Skip to content

Commit b699bdc

Browse files
emuslnjgunthorpe
authored andcommitted
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/[email protected] Reviewed-by: Leon Romanovsky <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Signed-off-by: Shannon Nelson <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent e8562da commit b699bdc

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

drivers/net/ethernet/amd/pds_core/auxbus.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,29 +175,32 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,
175175
return padev;
176176
}
177177

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)
179180
{
180181
struct pds_auxiliary_dev *padev;
181182

183+
if (!*pd_ptr)
184+
return;
185+
182186
mutex_lock(&pf->config_lock);
183187

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;
192194

193195
mutex_unlock(&pf->config_lock);
194196
}
195197

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)
197201
{
198202
struct pds_auxiliary_dev *padev;
199203
char devname[PDS_DEVNAME_LEN];
200-
enum pds_core_vif_types vt;
201204
unsigned long mask;
202205
u16 vt_support;
203206
int client_id;
@@ -206,6 +209,9 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
206209
if (!cf)
207210
return -ENODEV;
208211

212+
if (vt >= PDS_DEV_TYPE_MAX)
213+
return -EINVAL;
214+
209215
mutex_lock(&pf->config_lock);
210216

211217
mask = BIT_ULL(PDSC_S_FW_DEAD) |
@@ -217,17 +223,10 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
217223
goto out_unlock;
218224
}
219225

220-
/* We only support vDPA so far, so it is the only one to
221-
* be verified that it is available in the Core device and
222-
* enabled in the devlink param. In the future this might
223-
* become a loop for several VIF types.
224-
*/
225-
226226
/* Verify that the type is supported and enabled. It is not
227227
* an error if there is no auxbus device support for this
228228
* VF, it just means something else needs to happen with it.
229229
*/
230-
vt = PDS_DEV_TYPE_VDPA;
231230
vt_support = !!le16_to_cpu(pf->dev_ident.vif_types[vt]);
232231
if (!(vt_support &&
233232
pf->viftype_status[vt].supported &&
@@ -253,7 +252,7 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
253252
err = PTR_ERR(padev);
254253
goto out_unlock;
255254
}
256-
pf->vfs[cf->vf_id].padev = padev;
255+
*pd_ptr = padev;
257256

258257
out_unlock:
259258
mutex_unlock(&pf->config_lock);

drivers/net/ethernet/amd/pds_core/core.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,11 @@ void pdsc_health_thread(struct work_struct *work);
303303
int pdsc_register_notify(struct notifier_block *nb);
304304
void pdsc_unregister_notify(struct notifier_block *nb);
305305
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);
308311

309312
void pdsc_process_adminq(struct pdsc_qcq *qcq);
310313
void pdsc_work_thread(struct work_struct *work);

drivers/net/ethernet/amd/pds_core/devlink.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ int pdsc_dl_enable_set(struct devlink *dl, u32 id,
5757
struct pdsc *vf = pdsc->vfs[vf_id].vf;
5858

5959
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);
6162
else
62-
pdsc_auxbus_dev_del(vf, pdsc);
63+
pdsc_auxbus_dev_del(vf, pdsc, &pdsc->vfs[vf_id].padev);
6364
}
6465

6566
return err;

drivers/net/ethernet/amd/pds_core/main.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ static int pdsc_init_vf(struct pdsc *vf)
190190
devl_unlock(dl);
191191

192192
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);
194195
if (err) {
195196
devl_lock(dl);
196197
devl_unregister(dl);
@@ -417,7 +418,7 @@ static void pdsc_remove(struct pci_dev *pdev)
417418

418419
pf = pdsc_get_pf_struct(pdsc->pdev);
419420
if (!IS_ERR(pf)) {
420-
pdsc_auxbus_dev_del(pdsc, pf);
421+
pdsc_auxbus_dev_del(pdsc, pf, &pf->vfs[pdsc->vf_id].padev);
421422
pf->vfs[pdsc->vf_id].vf = NULL;
422423
}
423424
} else {
@@ -482,7 +483,8 @@ static void pdsc_reset_prepare(struct pci_dev *pdev)
482483

483484
pf = pdsc_get_pf_struct(pdsc->pdev);
484485
if (!IS_ERR(pf))
485-
pdsc_auxbus_dev_del(pdsc, pf);
486+
pdsc_auxbus_dev_del(pdsc, pf,
487+
&pf->vfs[pdsc->vf_id].padev);
486488
}
487489

488490
pdsc_unmap_bars(pdsc);
@@ -527,7 +529,8 @@ static void pdsc_reset_done(struct pci_dev *pdev)
527529

528530
pf = pdsc_get_pf_struct(pdsc->pdev);
529531
if (!IS_ERR(pf))
530-
pdsc_auxbus_dev_add(pdsc, pf);
532+
pdsc_auxbus_dev_add(pdsc, pf, PDS_DEV_TYPE_VDPA,
533+
&pf->vfs[pdsc->vf_id].padev);
531534
}
532535
}
533536

0 commit comments

Comments
 (0)