Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pds_core: specify auxiliary_device to be created

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>

authored by

Shannon Nelson and committed by
Jason Gunthorpe
b699bdc7 e8562da8

+33 -27
+18 -19
drivers/net/ethernet/amd/pds_core/auxbus.c
··· 175 175 return padev; 176 176 } 177 177 178 - void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf) 178 + void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf, 179 + struct pds_auxiliary_dev **pd_ptr) 179 180 { 180 181 struct pds_auxiliary_dev *padev; 181 182 183 + if (!*pd_ptr) 184 + return; 185 + 182 186 mutex_lock(&pf->config_lock); 183 187 184 - padev = pf->vfs[cf->vf_id].padev; 185 - if (padev) { 186 - pds_client_unregister(pf, padev->client_id); 187 - auxiliary_device_delete(&padev->aux_dev); 188 - auxiliary_device_uninit(&padev->aux_dev); 189 - padev->client_id = 0; 190 - } 191 - pf->vfs[cf->vf_id].padev = NULL; 188 + padev = *pd_ptr; 189 + pds_client_unregister(pf, padev->client_id); 190 + auxiliary_device_delete(&padev->aux_dev); 191 + auxiliary_device_uninit(&padev->aux_dev); 192 + padev->client_id = 0; 193 + *pd_ptr = NULL; 192 194 193 195 mutex_unlock(&pf->config_lock); 194 196 } 195 197 196 - int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf) 198 + int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf, 199 + enum pds_core_vif_types vt, 200 + struct pds_auxiliary_dev **pd_ptr) 197 201 { 198 202 struct pds_auxiliary_dev *padev; 199 203 char devname[PDS_DEVNAME_LEN]; 200 - enum pds_core_vif_types vt; 201 204 unsigned long mask; 202 205 u16 vt_support; 203 206 int client_id; ··· 208 205 209 206 if (!cf) 210 207 return -ENODEV; 208 + 209 + if (vt >= PDS_DEV_TYPE_MAX) 210 + return -EINVAL; 211 211 212 212 mutex_lock(&pf->config_lock); 213 213 ··· 223 217 goto out_unlock; 224 218 } 225 219 226 - /* We only support vDPA so far, so it is the only one to 227 - * be verified that it is available in the Core device and 228 - * enabled in the devlink param. In the future this might 229 - * become a loop for several VIF types. 230 - */ 231 - 232 220 /* Verify that the type is supported and enabled. It is not 233 221 * an error if there is no auxbus device support for this 234 222 * VF, it just means something else needs to happen with it. 235 223 */ 236 - vt = PDS_DEV_TYPE_VDPA; 237 224 vt_support = !!le16_to_cpu(pf->dev_ident.vif_types[vt]); 238 225 if (!(vt_support && 239 226 pf->viftype_status[vt].supported && ··· 252 253 err = PTR_ERR(padev); 253 254 goto out_unlock; 254 255 } 255 - pf->vfs[cf->vf_id].padev = padev; 256 + *pd_ptr = padev; 256 257 257 258 out_unlock: 258 259 mutex_unlock(&pf->config_lock);
+5 -2
drivers/net/ethernet/amd/pds_core/core.h
··· 303 303 int pdsc_register_notify(struct notifier_block *nb); 304 304 void pdsc_unregister_notify(struct notifier_block *nb); 305 305 void pdsc_notify(unsigned long event, void *data); 306 - int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf); 307 - void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf); 306 + int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf, 307 + enum pds_core_vif_types vt, 308 + struct pds_auxiliary_dev **pd_ptr); 309 + void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf, 310 + struct pds_auxiliary_dev **pd_ptr); 308 311 309 312 void pdsc_process_adminq(struct pdsc_qcq *qcq); 310 313 void pdsc_work_thread(struct work_struct *work);
+3 -2
drivers/net/ethernet/amd/pds_core/devlink.c
··· 57 57 struct pdsc *vf = pdsc->vfs[vf_id].vf; 58 58 59 59 if (ctx->val.vbool) 60 - err = pdsc_auxbus_dev_add(vf, pdsc); 60 + err = pdsc_auxbus_dev_add(vf, pdsc, vt_entry->vif_id, 61 + &pdsc->vfs[vf_id].padev); 61 62 else 62 - pdsc_auxbus_dev_del(vf, pdsc); 63 + pdsc_auxbus_dev_del(vf, pdsc, &pdsc->vfs[vf_id].padev); 63 64 } 64 65 65 66 return err;
+7 -4
drivers/net/ethernet/amd/pds_core/main.c
··· 190 190 devl_unlock(dl); 191 191 192 192 pf->vfs[vf->vf_id].vf = vf; 193 - err = pdsc_auxbus_dev_add(vf, pf); 193 + err = pdsc_auxbus_dev_add(vf, pf, PDS_DEV_TYPE_VDPA, 194 + &pf->vfs[vf->vf_id].padev); 194 195 if (err) { 195 196 devl_lock(dl); 196 197 devl_unregister(dl); ··· 418 417 419 418 pf = pdsc_get_pf_struct(pdsc->pdev); 420 419 if (!IS_ERR(pf)) { 421 - pdsc_auxbus_dev_del(pdsc, pf); 420 + pdsc_auxbus_dev_del(pdsc, pf, &pf->vfs[pdsc->vf_id].padev); 422 421 pf->vfs[pdsc->vf_id].vf = NULL; 423 422 } 424 423 } else { ··· 483 482 484 483 pf = pdsc_get_pf_struct(pdsc->pdev); 485 484 if (!IS_ERR(pf)) 486 - pdsc_auxbus_dev_del(pdsc, pf); 485 + pdsc_auxbus_dev_del(pdsc, pf, 486 + &pf->vfs[pdsc->vf_id].padev); 487 487 } 488 488 489 489 pdsc_unmap_bars(pdsc); ··· 529 527 530 528 pf = pdsc_get_pf_struct(pdsc->pdev); 531 529 if (!IS_ERR(pf)) 532 - pdsc_auxbus_dev_add(pdsc, pf); 530 + pdsc_auxbus_dev_add(pdsc, pf, PDS_DEV_TYPE_VDPA, 531 + &pf->vfs[pdsc->vf_id].padev); 533 532 } 534 533 } 535 534