pds_core: add initial VF device handling
authorShannon Nelson <shannon.nelson@amd.com>
Wed, 19 Apr 2023 17:04:22 +0000 (10:04 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 21 Apr 2023 07:29:13 +0000 (08:29 +0100)
This is the initial VF PCI driver framework for the new
pds_vdpa VF device, which will work in conjunction with an
auxiliary_bus client of the pds_core driver.  This does the
very basics of registering for the new VF device, setting
up debugfs entries, and registering with devlink.

Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/amd/pds_core/core.h
drivers/net/ethernet/amd/pds_core/main.c

index ac0480d..1ec8784 100644 (file)
@@ -30,6 +30,12 @@ struct pdsc_dev_bar {
        int res_index;
 };
 
+struct pdsc_vf {
+       struct pds_auxiliary_dev *padev;
+       u16     index;
+       __le16  vif_types[PDS_DEV_TYPE_MAX];
+};
+
 struct pdsc_devinfo {
        u8 asic_type;
        u8 asic_rev;
@@ -147,6 +153,9 @@ struct pdsc {
        struct dentry *dentry;
        struct device *dev;
        struct pdsc_dev_bar bars[PDS_CORE_BARS_MAX];
+       struct pdsc_vf *vfs;
+       int num_vfs;
+       int vf_id;
        int hw_index;
        int uid;
 
index 54aaf21..511cb91 100644 (file)
@@ -16,6 +16,7 @@ MODULE_LICENSE("GPL");
 /* Supported devices */
 static const struct pci_device_id pdsc_id_table[] = {
        { PCI_VDEVICE(PENSANDO, PCI_DEVICE_ID_PENSANDO_CORE_PF) },
+       { PCI_VDEVICE(PENSANDO, PCI_DEVICE_ID_PENSANDO_VDPA_VF) },
        { 0, }  /* end of table */
 };
 MODULE_DEVICE_TABLE(pci, pdsc_id_table);
@@ -132,9 +133,51 @@ void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num)
                               (u64)page_num << PAGE_SHIFT, PAGE_SIZE);
 }
 
+static int pdsc_sriov_configure(struct pci_dev *pdev, int num_vfs)
+{
+       struct pdsc *pdsc = pci_get_drvdata(pdev);
+       struct device *dev = pdsc->dev;
+       int ret = 0;
+
+       if (num_vfs > 0) {
+               pdsc->vfs = kcalloc(num_vfs, sizeof(struct pdsc_vf),
+                                   GFP_KERNEL);
+               if (!pdsc->vfs)
+                       return -ENOMEM;
+               pdsc->num_vfs = num_vfs;
+
+               ret = pci_enable_sriov(pdev, num_vfs);
+               if (ret) {
+                       dev_err(dev, "Cannot enable SRIOV: %pe\n",
+                               ERR_PTR(ret));
+                       goto no_vfs;
+               }
+
+               return num_vfs;
+       }
+
+no_vfs:
+       pci_disable_sriov(pdev);
+
+       kfree(pdsc->vfs);
+       pdsc->vfs = NULL;
+       pdsc->num_vfs = 0;
+
+       return ret;
+}
+
 static int pdsc_init_vf(struct pdsc *vf)
 {
-       return -1;
+       struct devlink *dl;
+
+       vf->vf_id = pci_iov_vf_id(vf->pdev);
+
+       dl = priv_to_devlink(vf);
+       devl_lock(dl);
+       devl_register(dl);
+       devl_unlock(dl);
+
+       return 0;
 }
 
 static const struct devlink_health_reporter_ops pdsc_fw_reporter_ops = {
@@ -323,6 +366,8 @@ static void pdsc_remove(struct pci_dev *pdev)
        devl_unlock(dl);
 
        if (!pdev->is_virtfn) {
+               pdsc_sriov_configure(pdev, 0);
+
                del_timer_sync(&pdsc->wdtimer);
                if (pdsc->wq)
                        destroy_workqueue(pdsc->wq);
@@ -354,6 +399,7 @@ static struct pci_driver pdsc_driver = {
        .id_table = pdsc_id_table,
        .probe = pdsc_probe,
        .remove = pdsc_remove,
+       .sriov_configure = pdsc_sriov_configure,
 };
 
 static int __init pdsc_init_module(void)