]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pds_core: specify auxiliary_device to be created
authorShannon Nelson <shannon.nelson@amd.com>
Thu, 20 Mar 2025 19:44:08 +0000 (12:44 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Thu, 20 Mar 2025 23:03:29 +0000 (20:03 -0300)
In preparation for adding a new auxiliary_device for the PF,
make the vif type an argument to pdsc_auxbus_dev_add().  Pass in
the address of the padev pointer so that the caller can specify
where to save it and keep the mutex usage within the function.

Link: https://patch.msgid.link/r/20250320194412.67983-3-shannon.nelson@amd.com
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/net/ethernet/amd/pds_core/auxbus.c
drivers/net/ethernet/amd/pds_core/core.h
drivers/net/ethernet/amd/pds_core/devlink.c
drivers/net/ethernet/amd/pds_core/main.c

index 78fba368e797d7cfd86bf68a1fdf2041536e7613..563de9e7ce0a7d3a18d2f535a892ed685a88e1c2 100644 (file)
@@ -175,29 +175,32 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,
        return padev;
 }
 
-void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
+void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf,
+                        struct pds_auxiliary_dev **pd_ptr)
 {
        struct pds_auxiliary_dev *padev;
 
+       if (!*pd_ptr)
+               return;
+
        mutex_lock(&pf->config_lock);
 
-       padev = pf->vfs[cf->vf_id].padev;
-       if (padev) {
-               pds_client_unregister(pf, padev->client_id);
-               auxiliary_device_delete(&padev->aux_dev);
-               auxiliary_device_uninit(&padev->aux_dev);
-               padev->client_id = 0;
-       }
-       pf->vfs[cf->vf_id].padev = NULL;
+       padev = *pd_ptr;
+       pds_client_unregister(pf, padev->client_id);
+       auxiliary_device_delete(&padev->aux_dev);
+       auxiliary_device_uninit(&padev->aux_dev);
+       padev->client_id = 0;
+       *pd_ptr = NULL;
 
        mutex_unlock(&pf->config_lock);
 }
 
-int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
+int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf,
+                       enum pds_core_vif_types vt,
+                       struct pds_auxiliary_dev **pd_ptr)
 {
        struct pds_auxiliary_dev *padev;
        char devname[PDS_DEVNAME_LEN];
-       enum pds_core_vif_types vt;
        unsigned long mask;
        u16 vt_support;
        int client_id;
@@ -206,6 +209,9 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
        if (!cf)
                return -ENODEV;
 
+       if (vt >= PDS_DEV_TYPE_MAX)
+               return -EINVAL;
+
        mutex_lock(&pf->config_lock);
 
        mask = BIT_ULL(PDSC_S_FW_DEAD) |
@@ -217,17 +223,10 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
                goto out_unlock;
        }
 
-       /* We only support vDPA so far, so it is the only one to
-        * be verified that it is available in the Core device and
-        * enabled in the devlink param.  In the future this might
-        * become a loop for several VIF types.
-        */
-
        /* Verify that the type is supported and enabled.  It is not
         * an error if there is no auxbus device support for this
         * VF, it just means something else needs to happen with it.
         */
-       vt = PDS_DEV_TYPE_VDPA;
        vt_support = !!le16_to_cpu(pf->dev_ident.vif_types[vt]);
        if (!(vt_support &&
              pf->viftype_status[vt].supported &&
@@ -253,7 +252,7 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
                err = PTR_ERR(padev);
                goto out_unlock;
        }
-       pf->vfs[cf->vf_id].padev = padev;
+       *pd_ptr = padev;
 
 out_unlock:
        mutex_unlock(&pf->config_lock);
index 631a59cfdd7ee8b958870fe75bfd46bff5d91b07..f075e68c64dba49d6cf08809fcbe713c33fe4693 100644 (file)
@@ -303,8 +303,11 @@ void pdsc_health_thread(struct work_struct *work);
 int pdsc_register_notify(struct notifier_block *nb);
 void pdsc_unregister_notify(struct notifier_block *nb);
 void pdsc_notify(unsigned long event, void *data);
-int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf);
-void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf);
+int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf,
+                       enum pds_core_vif_types vt,
+                       struct pds_auxiliary_dev **pd_ptr);
+void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf,
+                        struct pds_auxiliary_dev **pd_ptr);
 
 void pdsc_process_adminq(struct pdsc_qcq *qcq);
 void pdsc_work_thread(struct work_struct *work);
index 4e2b92ddef6f990a741d6ab6368bed19f02399b1..c5c787df61a4ecb0caf03005a22f570a0e41ef16 100644 (file)
@@ -57,9 +57,10 @@ int pdsc_dl_enable_set(struct devlink *dl, u32 id,
                struct pdsc *vf = pdsc->vfs[vf_id].vf;
 
                if (ctx->val.vbool)
-                       err = pdsc_auxbus_dev_add(vf, pdsc);
+                       err = pdsc_auxbus_dev_add(vf, pdsc, vt_entry->vif_id,
+                                                 &pdsc->vfs[vf_id].padev);
                else
-                       pdsc_auxbus_dev_del(vf, pdsc);
+                       pdsc_auxbus_dev_del(vf, pdsc, &pdsc->vfs[vf_id].padev);
        }
 
        return err;
index 660268ff95623fbe9c86ee2078913c85a3579a5a..a3a68889137b63ff5addb6bef152f04411b47621 100644 (file)
@@ -190,7 +190,8 @@ static int pdsc_init_vf(struct pdsc *vf)
        devl_unlock(dl);
 
        pf->vfs[vf->vf_id].vf = vf;
-       err = pdsc_auxbus_dev_add(vf, pf);
+       err = pdsc_auxbus_dev_add(vf, pf, PDS_DEV_TYPE_VDPA,
+                                 &pf->vfs[vf->vf_id].padev);
        if (err) {
                devl_lock(dl);
                devl_unregister(dl);
@@ -417,7 +418,7 @@ static void pdsc_remove(struct pci_dev *pdev)
 
                pf = pdsc_get_pf_struct(pdsc->pdev);
                if (!IS_ERR(pf)) {
-                       pdsc_auxbus_dev_del(pdsc, pf);
+                       pdsc_auxbus_dev_del(pdsc, pf, &pf->vfs[pdsc->vf_id].padev);
                        pf->vfs[pdsc->vf_id].vf = NULL;
                }
        } else {
@@ -482,7 +483,8 @@ static void pdsc_reset_prepare(struct pci_dev *pdev)
 
                pf = pdsc_get_pf_struct(pdsc->pdev);
                if (!IS_ERR(pf))
-                       pdsc_auxbus_dev_del(pdsc, pf);
+                       pdsc_auxbus_dev_del(pdsc, pf,
+                                           &pf->vfs[pdsc->vf_id].padev);
        }
 
        pdsc_unmap_bars(pdsc);
@@ -527,7 +529,8 @@ static void pdsc_reset_done(struct pci_dev *pdev)
 
                pf = pdsc_get_pf_struct(pdsc->pdev);
                if (!IS_ERR(pf))
-                       pdsc_auxbus_dev_add(pdsc, pf);
+                       pdsc_auxbus_dev_add(pdsc, pf, PDS_DEV_TYPE_VDPA,
+                                           &pf->vfs[pdsc->vf_id].padev);
        }
 }