[iwl-net,1/5] ice: Add function to get VF from device struct
Commit Message
From: Mateusz Polchlopek <mateusz.polchlopek@intel.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@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.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(+)
@@ -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
@@ -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)
{
}