Skip to contentSkip to conversation

iavf: Add helper function to go from pci_dev to adapter

PATCH New Karen Sornek 2 participants 2 messages Sep 15, 2021 – Oct 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iavf: Add helper function to go from pci_dev to adapter

Add helper function to go from pci_dev to adapter to make work simple - to go from a pci_dev to the adapter structure and make netdev assigment instead of having to go to the net_device then the adapter.

---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 24 +++++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +17 -7
index 80437ef26..39620fe6c 100644
@@ -51,6 +51,15 @@ MODULE_LICENSE("GPL v2");
 static const struct net_device_ops iavf_netdev_ops;
 struct workqueue_struct *iavf_wq;
 
+/**
+ * iavf_pdev_to_adapter - go from pci_dev to adapter
+ * @pdev: pci_dev pointer
+ */
+static struct iavf_adapter *iavf_pdev_to_adapter(struct pci_dev *pdev)
+{
+	return netdev_priv(pci_get_drvdata(pdev));
+}
+
 /**
  * iavf_allocate_dma_mem_d - OS specific memory alloc for shared code
  * @hw:   pointer to the HW structure
@@ -3725,8 +3734,8 @@ out:
  **/
 static void iavf_shutdown(struct pci_dev *pdev)
 {
-	struct net_device *netdev = pci_get_drvdata(pdev);
-	struct iavf_adapter *adapter = netdev_priv(netdev);
+	struct iavf_adapter *adapter = iavf_pdev_to_adapter(pdev);
+	struct net_device *netdev = adapter->netdev;
 
 	netif_device_detach(netdev);
 
@@ -3911,10 +3920,11 @@ static int __maybe_unused iavf_suspend(struct device *dev_d)
 static int __maybe_unused iavf_resume(struct device *dev_d)
 {
 	struct pci_dev *pdev = to_pci_dev(dev_d);
-	struct net_device *netdev = pci_get_drvdata(pdev);
-	struct iavf_adapter *adapter = netdev_priv(netdev);
+	struct iavf_adapter *adapter;
 	u32 err;
 
+	adapter = iavf_pdev_to_adapter(pdev);
+
 	pci_set_master(pdev);
 
 	rtnl_lock();
@@ -3933,7 +3943,7 @@ static int __maybe_unused iavf_resume(struct device *dev_d)
 
 	queue_work(iavf_wq, &adapter->reset_task);
 
-	netif_device_attach(netdev);
+	netif_device_attach(adapter->netdev);
 
 	return err;
 }
@@ -3949,8 +3959,8 @@ static int __maybe_unused iavf_resume(struct device *dev_d)
  **/
 static void iavf_remove(struct pci_dev *pdev)
 {
-	struct net_device *netdev = pci_get_drvdata(pdev);
-	struct iavf_adapter *adapter = netdev_priv(netdev);
+	struct iavf_adapter *adapter = iavf_pdev_to_adapter(pdev);
+	struct net_device *netdev = adapter->netdev;
 	struct iavf_fdir_fltr *fdir, *fdirtmp;
 	struct iavf_vlan_filter *vlf, *vlftmp;
 	struct iavf_adv_rss *rss, *rsstmp;
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/1 iavf: Add helper function to go from pci_dev to adapter

Quoted 26 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Karen Sornek
Sent: ?roda, 15 wrze?nia 2021 08:41
To: intel-wired-lan at lists.osuosl.org
Cc: Sornek, Karen <[email protected]>
Subject: [Intel-wired-lan] [PATCH net-next v1] iavf: Add helper function to go from pci_dev to adapter

Add helper function to go from pci_dev to adapter to make work simple - to go from a pci_dev to the adapter structure and make netdev assigment instead of having to go to the net_device then the adapter.

---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 24 +++++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -0
index 80437ef26..39620fe6c 100644

drivers/net/ethernet/intel/iavf/iavf_main.c MODULE_LICENSE("GPL v2"); static const struct · line 52

Quoted 2 lines
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -0
@@ -51,6 +51,15 @@ MODULE_LICENSE("GPL v2");  static const struct
 net_device_ops iavf_netdev_ops;  struct workqueue_struct *iavf_wq;