[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240228155957.408036-2-larysa.zaremba@intel.com>
Date: Wed, 28 Feb 2024 16:59:45 +0100
From: Larysa Zaremba <larysa.zaremba@...el.com>
To: intel-wired-lan@...ts.osuosl.org
Cc: Larysa Zaremba <larysa.zaremba@...el.com>,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
Mateusz Pacuszka <mateuszx.pacuszka@...el.com>,
Tony Nguyen <anthony.l.nguyen@...el.com>,
Lukasz Plachno <lukasz.plachno@...el.com>,
Jakub Buchocki <jakubx.buchocki@...el.com>,
Pawel Kaminski <pawel.kaminski@...el.com>,
Przemek Kitszel <przemyslaw.kitszel@...el.com>,
Michal Swiatkowski <michal.swiatkowski@...ux.intel.com>,
Mateusz Polchlopek <mateusz.polchlopek@...el.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Pawel Chmielewski <pawel.chmielewski@...el.com>,
Jesse Brandeburg <jesse.brandeburg@...el.com>
Subject: [PATCH iwl-net 1/5] ice: Add function to get VF from device struct
From: Mateusz Polchlopek <mateusz.polchlopek@...el.com>
Introduce a helper ice_get_vf_by_dev() to look up VF for a given struct
device.
Signed-off-by: Mateusz Polchlopek <mateusz.polchlopek@...el.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@...el.com>
Signed-off-by: Larysa Zaremba <larysa.zaremba@...el.com>
---
drivers/net/ethernet/intel/ice/ice_vf_lib.c | 30 +++++++++++++++++++++
drivers/net/ethernet/intel/ice/ice_vf_lib.h | 6 +++++
2 files changed, 36 insertions(+)
diff --git a/drivers/net/ethernet/intel/ice/ice_vf_lib.c b/drivers/net/ethernet/intel/ice/ice_vf_lib.c
index 2ffdae9a82df..21d22e3ad0ba 100644
--- a/drivers/net/ethernet/intel/ice/ice_vf_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_vf_lib.c
@@ -45,6 +45,36 @@ struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id)
return NULL;
}
+/**
+ * ice_get_vf_by_dev - Get pointer to VF by device
+ * @dev: the device structure
+ *
+ * Locate and return a pointer to the VF structure associated with a given
+ * device.
+ * Return: valid VF structure associated with the device, NULL if none exists
+ */
+struct ice_vf *ice_get_vf_by_dev(struct device *dev)
+{
+ struct pci_dev *vfdev;
+ struct pci_dev *pdev;
+ struct ice_pf *pf;
+ struct ice_vf *vf;
+ unsigned int bkt;
+
+ vfdev = container_of(dev, struct pci_dev, dev);
+ pdev = vfdev->physfn;
+ pf = pci_get_drvdata(pdev);
+
+ rcu_read_lock();
+ ice_for_each_vf_rcu(pf, bkt, vf) {
+ if (vf->vfdev == vfdev)
+ break;
+ }
+ rcu_read_unlock();
+
+ return vf;
+}
+
/**
* ice_release_vf - Release VF associated with a refcount
* @ref: the kref decremented to zero
diff --git a/drivers/net/ethernet/intel/ice/ice_vf_lib.h b/drivers/net/ethernet/intel/ice/ice_vf_lib.h
index 0cc9034065c5..48f4cdbd6d27 100644
--- a/drivers/net/ethernet/intel/ice/ice_vf_lib.h
+++ b/drivers/net/ethernet/intel/ice/ice_vf_lib.h
@@ -213,6 +213,7 @@ static inline u16 ice_vf_get_port_vlan_tpid(struct ice_vf *vf)
#ifdef CONFIG_PCI_IOV
struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id);
+struct ice_vf *ice_get_vf_by_dev(struct device *dev);
void ice_put_vf(struct ice_vf *vf);
bool ice_has_vfs(struct ice_pf *pf);
u16 ice_get_num_vfs(struct ice_pf *pf);
@@ -237,6 +238,11 @@ static inline struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id)
return NULL;
}
+static inline struct ice_vf *ice_get_vf_by_dev(struct device *dev)
+{
+ return NULL;
+}
+
static inline void ice_put_vf(struct ice_vf *vf)
{
}
--
2.43.0
Powered by blists - more mailing lists