Re: [PATCH net-next 09/10] net: hns3: Add support of .sriov_configure in HNS3 driver

2018-05-16 Thread kbuild test robot
Hi Peng,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:
https://github.com/0day-ci/linux/commits/Salil-Mehta/Misc-Bug-Fixes-and-clean-ups-for-HNS3-Driver/20180516-211239
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:266:16: sparse: expression 
using sizeof(void)
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:266:16: sparse: expression 
using sizeof(void)
>> drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:1582:5: sparse: symbol 
>> 'hns3_pci_sriov_configure' was not declared. Should it be static?
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:2513:21: sparse: expression 
using sizeof(void)
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:2706:22: sparse: expression 
using sizeof(void)
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:2706:22: sparse: expression 
using sizeof(void)

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


Re: [PATCH net-next 09/10] net: hns3: Add support of .sriov_configure in HNS3 driver

2018-05-16 Thread kbuild test robot
Hi Peng,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:
https://github.com/0day-ci/linux/commits/Salil-Mehta/Misc-Bug-Fixes-and-clean-ups-for-HNS3-Driver/20180516-211239
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:266:16: sparse: expression 
using sizeof(void)
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:266:16: sparse: expression 
using sizeof(void)
>> drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:1582:5: sparse: symbol 
>> 'hns3_pci_sriov_configure' was not declared. Should it be static?
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:2513:21: sparse: expression 
using sizeof(void)
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:2706:22: sparse: expression 
using sizeof(void)
   drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:2706:22: sparse: expression 
using sizeof(void)

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


[PATCH net-next 09/10] net: hns3: Add support of .sriov_configure in HNS3 driver

2018-05-15 Thread Salil Mehta
From: Peng Li 

As HNS3 driver will enable SRIOV default and enable all VFs the
HW support, if PF and VF driver compiled to kernel, VF driver
will work on host default, it is not right.

This patch adds support for hns3_driver.sriov_configure to support
user configs the VF_num, and do not enable sriov default.

Signed-off-by: Peng Li 
Suggested-by: Zhou Wang 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 58 ++---
 1 file changed, 32 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index ac75b5d..e85ff38 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1511,29 +1511,6 @@ static bool hns3_is_phys_func(struct pci_dev *pdev)
return false;
 }
 
-static int get_num_req_vfs(struct pci_dev *pdev)
-{
-   /* a variable vf num will be supported later */
-   return pci_sriov_get_totalvfs(pdev);
-}
-
-static void hns3_enable_sriov(struct pci_dev *pdev)
-{
-   int num_req_vfs = get_num_req_vfs(pdev);
-   int ret;
-
-   /* Enable SRIOV */
-   if (!num_req_vfs)
-   return;
-
-   dev_info(>dev, "active VFs(%d) found, enabling SRIOV\n",
-num_req_vfs);
-
-   ret = pci_enable_sriov(pdev, num_req_vfs);
-   if (ret)
-   dev_err(>dev, "SRIOV enable failed %d\n", ret);
-}
-
 static void hns3_disable_sriov(struct pci_dev *pdev)
 {
/* If our VFs are assigned we cannot shut down SR-IOV
@@ -1578,9 +1555,6 @@ static int hns3_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 
hnae3_register_ae_dev(ae_dev);
 
-   if (hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV))
-   hns3_enable_sriov(pdev);
-
return 0;
 }
 
@@ -1597,11 +1571,43 @@ static void hns3_remove(struct pci_dev *pdev)
hnae3_unregister_ae_dev(ae_dev);
 }
 
+/**
+ * hns3_pci_sriov_configure
+ * @pdev: pointer to a pci_dev structure
+ * @num_vfs: number of VFs to allocate
+ *
+ * Enable or change the number of VFs. Called when the user updates the number
+ * of VFs in sysfs.
+ **/
+int hns3_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
+{
+   int ret;
+
+   if (!(hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV))) {
+   dev_warn(>dev, "Can not config SRIOV\n");
+   return -EINVAL;
+   }
+
+   if (num_vfs) {
+   ret = pci_enable_sriov(pdev, num_vfs);
+   if (ret)
+   dev_err(>dev, "SRIOV enable failed %d\n", ret);
+   } else if (!pci_vfs_assigned(pdev)) {
+   pci_disable_sriov(pdev);
+   } else {
+   dev_warn(>dev,
+"Unable to free VFs because some are assigned to 
VMs.\n");
+   }
+
+   return 0;
+}
+
 static struct pci_driver hns3_driver = {
.name = hns3_driver_name,
.id_table = hns3_pci_tbl,
.probe= hns3_probe,
.remove   = hns3_remove,
+   .sriov_configure = hns3_pci_sriov_configure,
 };
 
 /* set default feature to hns3 */
-- 
2.7.4




[PATCH net-next 09/10] net: hns3: Add support of .sriov_configure in HNS3 driver

2018-05-15 Thread Salil Mehta
From: Peng Li 

As HNS3 driver will enable SRIOV default and enable all VFs the
HW support, if PF and VF driver compiled to kernel, VF driver
will work on host default, it is not right.

This patch adds support for hns3_driver.sriov_configure to support
user configs the VF_num, and do not enable sriov default.

Signed-off-by: Peng Li 
Suggested-by: Zhou Wang 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 58 ++---
 1 file changed, 32 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index ac75b5d..e85ff38 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1511,29 +1511,6 @@ static bool hns3_is_phys_func(struct pci_dev *pdev)
return false;
 }
 
-static int get_num_req_vfs(struct pci_dev *pdev)
-{
-   /* a variable vf num will be supported later */
-   return pci_sriov_get_totalvfs(pdev);
-}
-
-static void hns3_enable_sriov(struct pci_dev *pdev)
-{
-   int num_req_vfs = get_num_req_vfs(pdev);
-   int ret;
-
-   /* Enable SRIOV */
-   if (!num_req_vfs)
-   return;
-
-   dev_info(>dev, "active VFs(%d) found, enabling SRIOV\n",
-num_req_vfs);
-
-   ret = pci_enable_sriov(pdev, num_req_vfs);
-   if (ret)
-   dev_err(>dev, "SRIOV enable failed %d\n", ret);
-}
-
 static void hns3_disable_sriov(struct pci_dev *pdev)
 {
/* If our VFs are assigned we cannot shut down SR-IOV
@@ -1578,9 +1555,6 @@ static int hns3_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 
hnae3_register_ae_dev(ae_dev);
 
-   if (hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV))
-   hns3_enable_sriov(pdev);
-
return 0;
 }
 
@@ -1597,11 +1571,43 @@ static void hns3_remove(struct pci_dev *pdev)
hnae3_unregister_ae_dev(ae_dev);
 }
 
+/**
+ * hns3_pci_sriov_configure
+ * @pdev: pointer to a pci_dev structure
+ * @num_vfs: number of VFs to allocate
+ *
+ * Enable or change the number of VFs. Called when the user updates the number
+ * of VFs in sysfs.
+ **/
+int hns3_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
+{
+   int ret;
+
+   if (!(hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV))) {
+   dev_warn(>dev, "Can not config SRIOV\n");
+   return -EINVAL;
+   }
+
+   if (num_vfs) {
+   ret = pci_enable_sriov(pdev, num_vfs);
+   if (ret)
+   dev_err(>dev, "SRIOV enable failed %d\n", ret);
+   } else if (!pci_vfs_assigned(pdev)) {
+   pci_disable_sriov(pdev);
+   } else {
+   dev_warn(>dev,
+"Unable to free VFs because some are assigned to 
VMs.\n");
+   }
+
+   return 0;
+}
+
 static struct pci_driver hns3_driver = {
.name = hns3_driver_name,
.id_table = hns3_pci_tbl,
.probe= hns3_probe,
.remove   = hns3_remove,
+   .sriov_configure = hns3_pci_sriov_configure,
 };
 
 /* set default feature to hns3 */
-- 
2.7.4