1 From b5a0ff49504db5ebc55dcdfd53576741ad1ffb32 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Wed, 27 Sep 2023 10:31:27 +0200
4 Subject: i40e: Remove back pointer from i40e_hw structure
6 From: Ivan Vecera <ivecera@redhat.com>
8 [ Upstream commit 39ec612acf6d075809c38a7262d7ad09314762f3 ]
10 The .back field placed in i40e_hw is used to get pointer to i40e_pf
11 instance but it is not necessary as the i40e_hw is a part of i40e_pf
12 and containerof macro can be used to obtain the pointer to i40e_pf.
13 Remove .back field from i40e_hw structure, introduce i40e_hw_to_pf()
14 and i40e_hw_to_dev() helpers and use them.
16 Signed-off-by: Ivan Vecera <ivecera@redhat.com>
17 Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
18 Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
19 Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
20 Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel)
21 Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
22 Stable-dep-of: 6dbdd4de0362 ("e1000e: Workaround for sporadic MDI error on Meteor Lake systems")
23 Signed-off-by: Sasha Levin <sashal@kernel.org>
25 drivers/net/ethernet/intel/i40e/i40e.h | 11 ++++++++++
26 drivers/net/ethernet/intel/i40e/i40e_main.c | 22 ++++++++++++++------
27 drivers/net/ethernet/intel/i40e/i40e_osdep.h | 8 +++----
28 drivers/net/ethernet/intel/i40e/i40e_type.h | 1 -
29 4 files changed, 31 insertions(+), 11 deletions(-)
31 diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
32 index 3cc0b87def3fa..6f08c8fe653bd 100644
33 --- a/drivers/net/ethernet/intel/i40e/i40e.h
34 +++ b/drivers/net/ethernet/intel/i40e/i40e.h
35 @@ -1322,4 +1322,15 @@ static inline u32 i40e_is_tc_mqprio_enabled(struct i40e_pf *pf)
36 return pf->flags & I40E_FLAG_TC_MQPRIO;
40 + * i40e_hw_to_pf - get pf pointer from the hardware structure
41 + * @hw: pointer to the device HW structure
43 +static inline struct i40e_pf *i40e_hw_to_pf(struct i40e_hw *hw)
45 + return container_of(hw, struct i40e_pf, hw);
48 +struct device *i40e_hw_to_dev(struct i40e_hw *hw);
51 diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
52 index 8bfecf81d26f6..17ab6a1c53971 100644
53 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
54 +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
55 @@ -125,6 +125,17 @@ static void netdev_hw_addr_refcnt(struct i40e_mac_filter *f,
60 + * i40e_hw_to_dev - get device pointer from the hardware structure
61 + * @hw: pointer to the device HW structure
63 +struct device *i40e_hw_to_dev(struct i40e_hw *hw)
65 + struct i40e_pf *pf = i40e_hw_to_pf(hw);
67 + return &pf->pdev->dev;
71 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
72 * @hw: pointer to the HW structure
73 @@ -135,7 +146,7 @@ static void netdev_hw_addr_refcnt(struct i40e_mac_filter *f,
74 int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
75 u64 size, u32 alignment)
77 - struct i40e_pf *pf = (struct i40e_pf *)hw->back;
78 + struct i40e_pf *pf = i40e_hw_to_pf(hw);
80 mem->size = ALIGN(size, alignment);
81 mem->va = dma_alloc_coherent(&pf->pdev->dev, mem->size, &mem->pa,
82 @@ -153,7 +164,7 @@ int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
84 int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
86 - struct i40e_pf *pf = (struct i40e_pf *)hw->back;
87 + struct i40e_pf *pf = i40e_hw_to_pf(hw);
89 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
91 @@ -15653,10 +15664,10 @@ static int i40e_init_recovery_mode(struct i40e_pf *pf, struct i40e_hw *hw)
93 static inline void i40e_set_subsystem_device_id(struct i40e_hw *hw)
95 - struct pci_dev *pdev = ((struct i40e_pf *)hw->back)->pdev;
96 + struct i40e_pf *pf = i40e_hw_to_pf(hw);
98 - hw->subsystem_device_id = pdev->subsystem_device ?
99 - pdev->subsystem_device :
100 + hw->subsystem_device_id = pf->pdev->subsystem_device ?
101 + pf->pdev->subsystem_device :
102 (ushort)(rd32(hw, I40E_PFPCI_SUBSYSID) & USHRT_MAX);
105 @@ -15726,7 +15737,6 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
106 set_bit(__I40E_DOWN, pf->state);
111 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
113 diff --git a/drivers/net/ethernet/intel/i40e/i40e_osdep.h b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
114 index 2bd4de03dafa2..997569a4ad57b 100644
115 --- a/drivers/net/ethernet/intel/i40e/i40e_osdep.h
116 +++ b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
118 * actual OS primitives
121 -#define hw_dbg(hw, S, A...) \
123 - dev_dbg(&((struct i40e_pf *)hw->back)->pdev->dev, S, ##A); \
126 +struct device *i40e_hw_to_dev(struct i40e_hw *hw);
128 +#define hw_dbg(hw, S, A...) dev_dbg(i40e_hw_to_dev(hw), S, ##A)
130 #define wr32(a, reg, value) writel((value), ((a)->hw_addr + (reg)))
131 #define rd32(a, reg) readl((a)->hw_addr + (reg))
132 diff --git a/drivers/net/ethernet/intel/i40e/i40e_type.h b/drivers/net/ethernet/intel/i40e/i40e_type.h
133 index 232131bedc3e7..658bc89132783 100644
134 --- a/drivers/net/ethernet/intel/i40e/i40e_type.h
135 +++ b/drivers/net/ethernet/intel/i40e/i40e_type.h
136 @@ -525,7 +525,6 @@ struct i40e_dcbx_config {
137 /* Port hardware description */
142 /* subsystem structs */
143 struct i40e_phy_info phy;