Skip to content

Commit 4bb6cdc

Browse files
Jeffrey Huangdavem330
authored andcommitted
bnxt_en: More robust SRIOV cleanup sequence.
Instead of always calling pci_sriov_disable() in remove_one(), the driver should detect whether VFs are currently assigned to the VMs. If the VFs are active in VMs, then it should not disable SRIOV as it is catastrophic to the VMs. Instead, it just leaves the VFs alone and continues to unload the PF. The user can then cleanup the VMs even after the PF driver has been unloaded. Signed-off-by: Jeffrey Huang <huangjw@broadcom.com> Signed-off-by: Michael Chan <mchan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 84e86b9 commit 4bb6cdc

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int bnxt_set_vf_attr(struct bnxt *bp, int num_vfs)
258258
return 0;
259259
}
260260

261-
static int bnxt_hwrm_func_vf_resource_free(struct bnxt *bp)
261+
static int bnxt_hwrm_func_vf_resource_free(struct bnxt *bp, int num_vfs)
262262
{
263263
int i, rc = 0;
264264
struct bnxt_pf_info *pf = &bp->pf;
@@ -267,7 +267,7 @@ static int bnxt_hwrm_func_vf_resource_free(struct bnxt *bp)
267267
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_RESC_FREE, -1, -1);
268268

269269
mutex_lock(&bp->hwrm_cmd_lock);
270-
for (i = pf->first_vf_id; i < pf->first_vf_id + pf->active_vfs; i++) {
270+
for (i = pf->first_vf_id; i < pf->first_vf_id + num_vfs; i++) {
271271
req.vf_id = cpu_to_le16(i);
272272
rc = _hwrm_send_message(bp, &req, sizeof(req),
273273
HWRM_CMD_TIMEOUT);
@@ -509,7 +509,7 @@ static int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs)
509509

510510
err_out2:
511511
/* Free the resources reserved for various VF's */
512-
bnxt_hwrm_func_vf_resource_free(bp);
512+
bnxt_hwrm_func_vf_resource_free(bp, *num_vfs);
513513

514514
err_out1:
515515
bnxt_free_vf_resources(bp);
@@ -519,13 +519,19 @@ static int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs)
519519

520520
void bnxt_sriov_disable(struct bnxt *bp)
521521
{
522-
if (!bp->pf.active_vfs)
523-
return;
522+
u16 num_vfs = pci_num_vf(bp->pdev);
524523

525-
pci_disable_sriov(bp->pdev);
524+
if (!num_vfs)
525+
return;
526526

527-
/* Free the resources reserved for various VF's */
528-
bnxt_hwrm_func_vf_resource_free(bp);
527+
if (pci_vfs_assigned(bp->pdev)) {
528+
netdev_warn(bp->dev, "Unable to free %d VFs because some are assigned to VMs.\n",
529+
num_vfs);
530+
} else {
531+
pci_disable_sriov(bp->pdev);
532+
/* Free the HW resources reserved for various VF's */
533+
bnxt_hwrm_func_vf_resource_free(bp, num_vfs);
534+
}
529535

530536
bnxt_free_vf_resources(bp);
531537

@@ -552,17 +558,25 @@ int bnxt_sriov_configure(struct pci_dev *pdev, int num_vfs)
552558
}
553559
bp->sriov_cfg = true;
554560
rtnl_unlock();
555-
if (!num_vfs) {
556-
bnxt_sriov_disable(bp);
557-
return 0;
561+
562+
if (pci_vfs_assigned(bp->pdev)) {
563+
netdev_warn(dev, "Unable to configure SRIOV since some VFs are assigned to VMs.\n");
564+
num_vfs = 0;
565+
goto sriov_cfg_exit;
558566
}
559567

560568
/* Check if enabled VFs is same as requested */
561-
if (num_vfs == bp->pf.active_vfs)
562-
return 0;
569+
if (num_vfs && num_vfs == bp->pf.active_vfs)
570+
goto sriov_cfg_exit;
571+
572+
/* if there are previous existing VFs, clean them up */
573+
bnxt_sriov_disable(bp);
574+
if (!num_vfs)
575+
goto sriov_cfg_exit;
563576

564577
bnxt_sriov_enable(bp, &num_vfs);
565578

579+
sriov_cfg_exit:
566580
bp->sriov_cfg = false;
567581
wake_up(&bp->sriov_cfg_wait);
568582

0 commit comments

Comments
 (0)