From: Ivan Vecera <ivecera@redhat.com>
To: netdev@vger.kernel.org
Cc: poros@redhat.com, mschmidt@redhat.com,
jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com,
davem@davemloft.net, kuba@kernel.org, edumazet@google.com,
pabeni@redhat.com, intel-wired-lan@lists.osuosl.org,
linux-kernel@vger.kernel.org, przemyslaw.kitszel@intel.com
Subject: [PATCH net-next v2 1/9] i40e: Remove back pointer from i40e_hw structure
Date: Wed, 27 Sep 2023 10:31:27 +0200 [thread overview]
Message-ID: <20230927083135.3237206-2-ivecera@redhat.com> (raw)
In-Reply-To: <20230927083135.3237206-1-ivecera@redhat.com>
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>
---
drivers/net/ethernet/intel/i40e/i40e.h | 11 ++++++++++
drivers/net/ethernet/intel/i40e/i40e_main.c | 22 ++++++++++++++------
drivers/net/ethernet/intel/i40e/i40e_osdep.h | 8 +++----
drivers/net/ethernet/intel/i40e/i40e_type.h | 1 -
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
index 6e310a539467..7f79d5929be6 100644
--- a/drivers/net/ethernet/intel/i40e/i40e.h
+++ b/drivers/net/ethernet/intel/i40e/i40e.h
@@ -1321,4 +1321,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_ */
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 00ca2b88165c..c19d1b4cc32b 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -119,6 +119,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
@@ -129,7 +140,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,
@@ -147,7 +158,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;
@@ -15623,10 +15634,10 @@ static int i40e_init_recovery_mode(struct i40e_pf *pf, struct i40e_hw *hw)
**/
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);
}
@@ -15696,7 +15707,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);
diff --git a/drivers/net/ethernet/intel/i40e/i40e_osdep.h b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
index 2bd4de03dafa..997569a4ad57 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_osdep.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
@@ -18,10 +18,10 @@
* 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))
diff --git a/drivers/net/ethernet/intel/i40e/i40e_type.h b/drivers/net/ethernet/intel/i40e/i40e_type.h
index 232131bedc3e..658bc8913278 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_type.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_type.h
@@ -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;
--
2.41.0
next prev parent reply other threads:[~2023-09-27 8:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 8:31 [PATCH net-next v2 0/9] i40e: House-keeping and clean-up Ivan Vecera
2023-09-27 8:31 ` Ivan Vecera [this message]
2023-10-05 8:08 ` [Intel-wired-lan] [PATCH net-next v2 1/9] i40e: Remove back pointer from i40e_hw structure Pucha, HimasekharX Reddy
2023-09-27 8:31 ` [PATCH net-next v2 2/9] i40e: Move I40E_MASK macro to i40e_register.h Ivan Vecera
2023-10-05 8:10 ` [Intel-wired-lan] " Pucha, HimasekharX Reddy
2023-09-27 8:31 ` [PATCH net-next v2 3/9] i40e: Refactor I40E_MDIO_CLAUSE* macros Ivan Vecera
2023-10-05 8:12 ` [Intel-wired-lan] " Pucha, HimasekharX Reddy
2023-09-27 8:31 ` [PATCH net-next v2 4/9] virtchnl: Add header dependencies Ivan Vecera
2023-09-27 8:31 ` [PATCH net-next v2 5/9] i40e: Simplify memory allocation functions Ivan Vecera
2023-10-05 8:14 ` [Intel-wired-lan] " Pucha, HimasekharX Reddy
2023-09-27 8:31 ` [PATCH net-next v2 6/9] i40e: Move memory allocation structures to i40e_alloc.h Ivan Vecera
2023-10-05 8:16 ` [Intel-wired-lan] " Pucha, HimasekharX Reddy
2023-09-27 8:31 ` [PATCH net-next v2 7/9] i40e: Split i40e_osdep.h Ivan Vecera
2023-10-05 8:18 ` [Intel-wired-lan] " Pucha, HimasekharX Reddy
2023-09-27 8:31 ` [PATCH net-next v2 8/9] i40e: Remove circular header dependencies and fix headers Ivan Vecera
2023-10-05 8:22 ` [Intel-wired-lan] " Pucha, HimasekharX Reddy
2023-09-27 8:31 ` [PATCH net-next v2 9/9] i40e: Move DDP specific macros and structures to i40e_ddp.c Ivan Vecera
2023-10-05 8:23 ` [Intel-wired-lan] " Pucha, HimasekharX Reddy
2023-09-27 8:53 ` [PATCH net-next v2 0/9] i40e: House-keeping and clean-up Przemek Kitszel
2023-09-28 22:12 ` Jesse Brandeburg
2023-10-04 19:17 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230927083135.3237206-2-ivecera@redhat.com \
--to=ivecera@redhat.com \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jesse.brandeburg@intel.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=poros@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).