Skip to content

Commit 31642d2

Browse files
pkitszeldavem330
authored andcommitted
ice: store VF's pci_dev ptr in ice_vf
Extend struct ice_vf by vfdev. Calculation of vfdev falls more nicely into ice_create_vf_entries(). Caching of vfdev enables simplification of ice_restore_all_vfs_msi_state(). Reviewed-by: Jesse Brandeburg <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Signed-off-by: Przemek Kitszel <[email protected]> Co-developed-by: Mateusz Polchlopek <[email protected]> Signed-off-by: Mateusz Polchlopek <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9dffb97 commit 31642d2

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5541,7 +5541,7 @@ static void ice_pci_err_resume(struct pci_dev *pdev)
55415541
return;
55425542
}
55435543

5544-
ice_restore_all_vfs_msi_state(pdev);
5544+
ice_restore_all_vfs_msi_state(pf);
55455545

55465546
ice_do_reset(pf, ICE_RESET_PFR);
55475547
ice_service_task_restart(pf);

drivers/net/ethernet/intel/ice/ice_sriov.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -789,14 +789,19 @@ static const struct ice_vf_ops ice_sriov_vf_ops = {
789789
*/
790790
static int ice_create_vf_entries(struct ice_pf *pf, u16 num_vfs)
791791
{
792+
struct pci_dev *pdev = pf->pdev;
792793
struct ice_vfs *vfs = &pf->vfs;
794+
struct pci_dev *vfdev = NULL;
793795
struct ice_vf *vf;
794-
u16 vf_id;
795-
int err;
796+
u16 vf_pdev_id;
797+
int err, pos;
796798

797799
lockdep_assert_held(&vfs->table_lock);
798800

799-
for (vf_id = 0; vf_id < num_vfs; vf_id++) {
801+
pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
802+
pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_pdev_id);
803+
804+
for (u16 vf_id = 0; vf_id < num_vfs; vf_id++) {
800805
vf = kzalloc(sizeof(*vf), GFP_KERNEL);
801806
if (!vf) {
802807
err = -ENOMEM;
@@ -812,11 +817,23 @@ static int ice_create_vf_entries(struct ice_pf *pf, u16 num_vfs)
812817

813818
ice_initialize_vf_entry(vf);
814819

820+
do {
821+
vfdev = pci_get_device(pdev->vendor, vf_pdev_id, vfdev);
822+
} while (vfdev && vfdev->physfn != pdev);
823+
vf->vfdev = vfdev;
815824
vf->vf_sw_id = pf->first_sw;
816825

826+
pci_dev_get(vfdev);
827+
817828
hash_add_rcu(vfs->table, &vf->entry, vf_id);
818829
}
819830

831+
/* Decrement of refcount done by pci_get_device() inside the loop does
832+
* not touch the last iteration's vfdev, so it has to be done manually
833+
* to balance pci_dev_get() added within the loop.
834+
*/
835+
pci_dev_put(vfdev);
836+
820837
return 0;
821838

822839
err_free_entries:
@@ -1709,31 +1726,16 @@ void ice_print_vfs_mdd_events(struct ice_pf *pf)
17091726

17101727
/**
17111728
* ice_restore_all_vfs_msi_state - restore VF MSI state after PF FLR
1712-
* @pdev: pointer to a pci_dev structure
1729+
* @pf: pointer to the PF structure
17131730
*
17141731
* Called when recovering from a PF FLR to restore interrupt capability to
17151732
* the VFs.
17161733
*/
1717-
void ice_restore_all_vfs_msi_state(struct pci_dev *pdev)
1734+
void ice_restore_all_vfs_msi_state(struct ice_pf *pf)
17181735
{
1719-
u16 vf_id;
1720-
int pos;
1721-
1722-
if (!pci_num_vf(pdev))
1723-
return;
1736+
struct ice_vf *vf;
1737+
u32 bkt;
17241738

1725-
pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
1726-
if (pos) {
1727-
struct pci_dev *vfdev;
1728-
1729-
pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID,
1730-
&vf_id);
1731-
vfdev = pci_get_device(pdev->vendor, vf_id, NULL);
1732-
while (vfdev) {
1733-
if (vfdev->is_virtfn && vfdev->physfn == pdev)
1734-
pci_restore_msi_state(vfdev);
1735-
vfdev = pci_get_device(pdev->vendor, vf_id,
1736-
vfdev);
1737-
}
1738-
}
1739+
ice_for_each_vf(pf, bkt, vf)
1740+
pci_restore_msi_state(vf->vfdev);
17391741
}

drivers/net/ethernet/intel/ice/ice_sriov.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int
3333
ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
3434

3535
void ice_free_vfs(struct ice_pf *pf);
36-
void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
36+
void ice_restore_all_vfs_msi_state(struct ice_pf *pf);
3737

3838
int
3939
ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
@@ -67,7 +67,7 @@ static inline
6767
void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
6868
static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
6969
static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
70-
static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
70+
static inline void ice_restore_all_vfs_msi_state(struct ice_pf *pf) { }
7171

7272
static inline int
7373
ice_sriov_configure(struct pci_dev __always_unused *pdev,

drivers/net/ethernet/intel/ice/ice_vf_lib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static void ice_release_vf(struct kref *ref)
5656
{
5757
struct ice_vf *vf = container_of(ref, struct ice_vf, refcnt);
5858

59+
pci_dev_put(vf->vfdev);
60+
5961
vf->vf_ops->free(vf);
6062
}
6163

drivers/net/ethernet/intel/ice/ice_vf_lib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct ice_vf {
8282
struct rcu_head rcu;
8383
struct kref refcnt;
8484
struct ice_pf *pf;
85-
85+
struct pci_dev *vfdev;
8686
/* Used during virtchnl message handling and NDO ops against the VF
8787
* that will trigger a VFR
8888
*/

0 commit comments

Comments
 (0)