]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
i40e: Remove back pointer from i40e_hw structure
authorIvan Vecera <ivecera@redhat.com>
Wed, 27 Sep 2023 08:31:27 +0000 (10:31 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:35:55 +0000 (16:35 +0200)
[ Upstream commit 39ec612acf6d075809c38a7262d7ad09314762f3 ]

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 <ivecera@redhat.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Stable-dep-of: 6dbdd4de0362 ("e1000e: Workaround for sporadic MDI error on Meteor Lake systems")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/intel/i40e/i40e.h
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/intel/i40e/i40e_osdep.h
drivers/net/ethernet/intel/i40e/i40e_type.h

index 3cc0b87def3fa4f4c60e86fcfaf3bf2b020c5610..6f08c8fe653bd23c934a9c093347a71fa57b1eb2 100644 (file)
@@ -1322,4 +1322,15 @@ static inline u32 i40e_is_tc_mqprio_enabled(struct i40e_pf *pf)
        return pf->flags & I40E_FLAG_TC_MQPRIO;
 }
 
+/**
+ * i40e_hw_to_pf - get pf pointer from the hardware structure
+ * @hw: pointer to the device HW structure
+ **/
+static inline struct i40e_pf *i40e_hw_to_pf(struct i40e_hw *hw)
+{
+       return container_of(hw, struct i40e_pf, hw);
+}
+
+struct device *i40e_hw_to_dev(struct i40e_hw *hw);
+
 #endif /* _I40E_H_ */
index 8bfecf81d26f6e6531ec82e05bcd769e5576e828..17ab6a1c539719f8222d0722132495d7befd2a9a 100644 (file)
@@ -125,6 +125,17 @@ static void netdev_hw_addr_refcnt(struct i40e_mac_filter *f,
        }
 }
 
+/**
+ * i40e_hw_to_dev - get device pointer from the hardware structure
+ * @hw: pointer to the device HW structure
+ **/
+struct device *i40e_hw_to_dev(struct i40e_hw *hw)
+{
+       struct i40e_pf *pf = i40e_hw_to_pf(hw);
+
+       return &pf->pdev->dev;
+}
+
 /**
  * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  * @hw:   pointer to the HW structure
@@ -135,7 +146,7 @@ static void netdev_hw_addr_refcnt(struct i40e_mac_filter *f,
 int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
                            u64 size, u32 alignment)
 {
-       struct i40e_pf *pf = (struct i40e_pf *)hw->back;
+       struct i40e_pf *pf = i40e_hw_to_pf(hw);
 
        mem->size = ALIGN(size, alignment);
        mem->va = dma_alloc_coherent(&pf->pdev->dev, mem->size, &mem->pa,
@@ -153,7 +164,7 @@ int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  **/
 int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
 {
-       struct i40e_pf *pf = (struct i40e_pf *)hw->back;
+       struct i40e_pf *pf = i40e_hw_to_pf(hw);
 
        dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
        mem->va = NULL;
@@ -15653,10 +15664,10 @@ err_switch_setup:
  **/
 static inline void i40e_set_subsystem_device_id(struct i40e_hw *hw)
 {
-       struct pci_dev *pdev = ((struct i40e_pf *)hw->back)->pdev;
+       struct i40e_pf *pf = i40e_hw_to_pf(hw);
 
-       hw->subsystem_device_id = pdev->subsystem_device ?
-               pdev->subsystem_device :
+       hw->subsystem_device_id = pf->pdev->subsystem_device ?
+               pf->pdev->subsystem_device :
                (ushort)(rd32(hw, I40E_PFPCI_SUBSYSID) & USHRT_MAX);
 }
 
@@ -15726,7 +15737,6 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        set_bit(__I40E_DOWN, pf->state);
 
        hw = &pf->hw;
-       hw->back = pf;
 
        pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
                                I40E_MAX_CSR_SPACE);
index 2bd4de03dafa2b06d690b22e3ccecf4547175705..997569a4ad57be2cb8c6caffee59c13718371d0f 100644 (file)
  * actual OS primitives
  */
 
-#define hw_dbg(hw, S, A...)                                                    \
-do {                                                                           \
-       dev_dbg(&((struct i40e_pf *)hw->back)->pdev->dev, S, ##A);              \
-} while (0)
+struct i40e_hw;
+struct device *i40e_hw_to_dev(struct i40e_hw *hw);
+
+#define hw_dbg(hw, S, A...) dev_dbg(i40e_hw_to_dev(hw), S, ##A)
 
 #define wr32(a, reg, value)    writel((value), ((a)->hw_addr + (reg)))
 #define rd32(a, reg)           readl((a)->hw_addr + (reg))
index 232131bedc3e7983983324cfedbca193b641e730..658bc89132783a64982e03124aca13e2cf058e1e 100644 (file)
@@ -525,7 +525,6 @@ struct i40e_dcbx_config {
 /* Port hardware description */
 struct i40e_hw {
        u8 __iomem *hw_addr;
-       void *back;
 
        /* subsystem structs */
        struct i40e_phy_info phy;