0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "ef100_sriov.h"
0013 #include "ef100_nic.h"
0014 #include "ef100_rep.h"
0015
0016 static int efx_ef100_pci_sriov_enable(struct efx_nic *efx, int num_vfs)
0017 {
0018 struct ef100_nic_data *nic_data = efx->nic_data;
0019 struct pci_dev *dev = efx->pci_dev;
0020 struct efx_rep *efv, *next;
0021 int rc, i;
0022
0023 efx->vf_count = num_vfs;
0024 rc = pci_enable_sriov(dev, num_vfs);
0025 if (rc)
0026 goto fail1;
0027
0028 if (!nic_data->grp_mae)
0029 return 0;
0030
0031 for (i = 0; i < num_vfs; i++) {
0032 rc = efx_ef100_vfrep_create(efx, i);
0033 if (rc)
0034 goto fail2;
0035 }
0036 return 0;
0037
0038 fail2:
0039 list_for_each_entry_safe(efv, next, &efx->vf_reps, list)
0040 efx_ef100_vfrep_destroy(efx, efv);
0041 pci_disable_sriov(dev);
0042 fail1:
0043 netif_err(efx, probe, efx->net_dev, "Failed to enable SRIOV VFs\n");
0044 efx->vf_count = 0;
0045 return rc;
0046 }
0047
0048 int efx_ef100_pci_sriov_disable(struct efx_nic *efx, bool force)
0049 {
0050 struct pci_dev *dev = efx->pci_dev;
0051 unsigned int vfs_assigned;
0052
0053 vfs_assigned = pci_vfs_assigned(dev);
0054 if (vfs_assigned && !force) {
0055 netif_info(efx, drv, efx->net_dev, "VFs are assigned to guests; "
0056 "please detach them before disabling SR-IOV\n");
0057 return -EBUSY;
0058 }
0059
0060 efx_ef100_fini_vfreps(efx);
0061 if (!vfs_assigned)
0062 pci_disable_sriov(dev);
0063 return 0;
0064 }
0065
0066 int efx_ef100_sriov_configure(struct efx_nic *efx, int num_vfs)
0067 {
0068 if (num_vfs == 0)
0069 return efx_ef100_pci_sriov_disable(efx, false);
0070 else
0071 return efx_ef100_pci_sriov_enable(efx, num_vfs);
0072 }