i40e: enable extant VFs
authorMitch Williams <mitch.a.williams@intel.com>
Thu, 13 Feb 2014 11:48:47 +0000 (03:48 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Feb 2014 22:27:29 +0000 (17:27 -0500)
If VFs are present when the driver loads, then set up some resources
so they can function.

Change-ID: I485916a811609a9990ce663d06dc645f625b07ff
Signed-off-by: Mitch Williams <mitch.a.williams@intel.com>
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Tested-by: Sibai Li <sibai.li@intel.com>
Signed-off-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h

index 21d46f4bb214f60ba8fcb0112967457515e03035..897452d72d71cb73c44ea0ebcd2f974ef63bc5ca 100644 (file)
@@ -8076,6 +8076,16 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
                wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
                i40e_flush(hw);
+
+               if (pci_num_vf(pdev)) {
+                       dev_info(&pdev->dev,
+                                "Active VFs found, allocating resources.\n");
+                       err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
+                       if (err)
+                               dev_info(&pdev->dev,
+                                        "Error %d allocating resources for existing VFs\n",
+                                        err);
+               }
        }
 
        pfs_found++;
index 052be06b91aa8e8d3428c4a03afd29300e22a973..9074f63a2447512db98858025ca93006849aaca1 100644 (file)
@@ -840,7 +840,7 @@ void i40e_free_vfs(struct i40e_pf *pf)
  *
  * allocate vf resources
  **/
-static int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
+int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
 {
        struct i40e_vf *vfs;
        int i, ret = 0;
@@ -848,14 +848,16 @@ static int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
        /* Disable interrupt 0 so we don't try to handle the VFLR. */
        i40e_irq_dynamic_disable_icr0(pf);
 
-       ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
-       if (ret) {
-               dev_err(&pf->pdev->dev,
-                       "pci_enable_sriov failed with error %d!\n", ret);
-               pf->num_alloc_vfs = 0;
-               goto err_iov;
+       /* Check to see if we're just allocating resources for extant VFs */
+       if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
+               ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
+               if (ret) {
+                       dev_err(&pf->pdev->dev,
+                               "Failed to enable SR-IOV, error %d.\n", ret);
+                       pf->num_alloc_vfs = 0;
+                       goto err_iov;
+               }
        }
-
        /* allocate memory */
        vfs = kzalloc(num_alloc_vfs * sizeof(struct i40e_vf), GFP_KERNEL);
        if (!vfs) {
index cc1feee36e12b69e0ffaa300a4aa8509ba97bd4b..bedf0ba21d74ba612b730eb3bced390d5b59ac94 100644 (file)
@@ -102,6 +102,7 @@ struct i40e_vf {
 
 void i40e_free_vfs(struct i40e_pf *pf);
 int i40e_pci_sriov_configure(struct pci_dev *dev, int num_vfs);
+int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs);
 int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
                           u32 v_retval, u8 *msg, u16 msglen);
 int i40e_vc_process_vflr_event(struct i40e_pf *pf);