Skip to content

Commit 39ec612

Browse files
Ivan Veceraanguy11
authored andcommitted
i40e: Remove back pointer from i40e_hw structure
The .back field placed in i40e_hw is used to get pointer to i40e_pf instance but it is not necessary as the i40e_hw is a part of i40e_pf and containerof macro can be used to obtain the pointer to i40e_pf. Remove .back field from i40e_hw structure, introduce i40e_hw_to_pf() and i40e_hw_to_dev() helpers and use them. Signed-off-by: Ivan Vecera <[email protected]> Reviewed-by: Przemek Kitszel <[email protected]> Reviewed-by: Jesse Brandeburg <[email protected]> Reviewed-by: Aleksandr Loktionov <[email protected]> Tested-by: Pucha Himasekhar Reddy <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent 49e7265 commit 39ec612

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

drivers/net/ethernet/intel/i40e/i40e.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,4 +1321,15 @@ static inline u32 i40e_is_tc_mqprio_enabled(struct i40e_pf *pf)
13211321
return pf->flags & I40E_FLAG_TC_MQPRIO;
13221322
}
13231323

1324+
/**
1325+
* i40e_hw_to_pf - get pf pointer from the hardware structure
1326+
* @hw: pointer to the device HW structure
1327+
**/
1328+
static inline struct i40e_pf *i40e_hw_to_pf(struct i40e_hw *hw)
1329+
{
1330+
return container_of(hw, struct i40e_pf, hw);
1331+
}
1332+
1333+
struct device *i40e_hw_to_dev(struct i40e_hw *hw);
1334+
13241335
#endif /* _I40E_H_ */

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ static void netdev_hw_addr_refcnt(struct i40e_mac_filter *f,
119119
}
120120
}
121121

122+
/**
123+
* i40e_hw_to_dev - get device pointer from the hardware structure
124+
* @hw: pointer to the device HW structure
125+
**/
126+
struct device *i40e_hw_to_dev(struct i40e_hw *hw)
127+
{
128+
struct i40e_pf *pf = i40e_hw_to_pf(hw);
129+
130+
return &pf->pdev->dev;
131+
}
132+
122133
/**
123134
* i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
124135
* @hw: pointer to the HW structure
@@ -129,7 +140,7 @@ static void netdev_hw_addr_refcnt(struct i40e_mac_filter *f,
129140
int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
130141
u64 size, u32 alignment)
131142
{
132-
struct i40e_pf *pf = (struct i40e_pf *)hw->back;
143+
struct i40e_pf *pf = i40e_hw_to_pf(hw);
133144

134145
mem->size = ALIGN(size, alignment);
135146
mem->va = dma_alloc_coherent(&pf->pdev->dev, mem->size, &mem->pa,
@@ -147,7 +158,7 @@ int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
147158
**/
148159
int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
149160
{
150-
struct i40e_pf *pf = (struct i40e_pf *)hw->back;
161+
struct i40e_pf *pf = i40e_hw_to_pf(hw);
151162

152163
dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
153164
mem->va = NULL;
@@ -15619,10 +15630,10 @@ static int i40e_init_recovery_mode(struct i40e_pf *pf, struct i40e_hw *hw)
1561915630
**/
1562015631
static inline void i40e_set_subsystem_device_id(struct i40e_hw *hw)
1562115632
{
15622-
struct pci_dev *pdev = ((struct i40e_pf *)hw->back)->pdev;
15633+
struct i40e_pf *pf = i40e_hw_to_pf(hw);
1562315634

15624-
hw->subsystem_device_id = pdev->subsystem_device ?
15625-
pdev->subsystem_device :
15635+
hw->subsystem_device_id = pf->pdev->subsystem_device ?
15636+
pf->pdev->subsystem_device :
1562615637
(ushort)(rd32(hw, I40E_PFPCI_SUBSYSID) & USHRT_MAX);
1562715638
}
1562815639

@@ -15692,7 +15703,6 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1569215703
set_bit(__I40E_DOWN, pf->state);
1569315704

1569415705
hw = &pf->hw;
15695-
hw->back = pf;
1569615706

1569715707
pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
1569815708
I40E_MAX_CSR_SPACE);

drivers/net/ethernet/intel/i40e/i40e_osdep.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
* actual OS primitives
1919
*/
2020

21-
#define hw_dbg(hw, S, A...) \
22-
do { \
23-
dev_dbg(&((struct i40e_pf *)hw->back)->pdev->dev, S, ##A); \
24-
} while (0)
21+
struct i40e_hw;
22+
struct device *i40e_hw_to_dev(struct i40e_hw *hw);
23+
24+
#define hw_dbg(hw, S, A...) dev_dbg(i40e_hw_to_dev(hw), S, ##A)
2525

2626
#define wr32(a, reg, value) writel((value), ((a)->hw_addr + (reg)))
2727
#define rd32(a, reg) readl((a)->hw_addr + (reg))

drivers/net/ethernet/intel/i40e/i40e_type.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ struct i40e_dcbx_config {
525525
/* Port hardware description */
526526
struct i40e_hw {
527527
u8 __iomem *hw_addr;
528-
void *back;
529528

530529
/* subsystem structs */
531530
struct i40e_phy_info phy;

0 commit comments

Comments
 (0)