Skip to content

Commit f53d931

Browse files
emuslndavem330
authored andcommitted
pds_core: add initial VF device handling
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>
1 parent 65e0185 commit f53d931

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ struct pdsc_dev_bar {
3030
int res_index;
3131
};
3232

33+
struct pdsc_vf {
34+
struct pds_auxiliary_dev *padev;
35+
u16 index;
36+
__le16 vif_types[PDS_DEV_TYPE_MAX];
37+
};
38+
3339
struct pdsc_devinfo {
3440
u8 asic_type;
3541
u8 asic_rev;
@@ -147,6 +153,9 @@ struct pdsc {
147153
struct dentry *dentry;
148154
struct device *dev;
149155
struct pdsc_dev_bar bars[PDS_CORE_BARS_MAX];
156+
struct pdsc_vf *vfs;
157+
int num_vfs;
158+
int vf_id;
150159
int hw_index;
151160
int uid;
152161

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ MODULE_LICENSE("GPL");
1616
/* Supported devices */
1717
static const struct pci_device_id pdsc_id_table[] = {
1818
{ PCI_VDEVICE(PENSANDO, PCI_DEVICE_ID_PENSANDO_CORE_PF) },
19+
{ PCI_VDEVICE(PENSANDO, PCI_DEVICE_ID_PENSANDO_VDPA_VF) },
1920
{ 0, } /* end of table */
2021
};
2122
MODULE_DEVICE_TABLE(pci, pdsc_id_table);
@@ -132,9 +133,51 @@ void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num)
132133
(u64)page_num << PAGE_SHIFT, PAGE_SIZE);
133134
}
134135

136+
static int pdsc_sriov_configure(struct pci_dev *pdev, int num_vfs)
137+
{
138+
struct pdsc *pdsc = pci_get_drvdata(pdev);
139+
struct device *dev = pdsc->dev;
140+
int ret = 0;
141+
142+
if (num_vfs > 0) {
143+
pdsc->vfs = kcalloc(num_vfs, sizeof(struct pdsc_vf),
144+
GFP_KERNEL);
145+
if (!pdsc->vfs)
146+
return -ENOMEM;
147+
pdsc->num_vfs = num_vfs;
148+
149+
ret = pci_enable_sriov(pdev, num_vfs);
150+
if (ret) {
151+
dev_err(dev, "Cannot enable SRIOV: %pe\n",
152+
ERR_PTR(ret));
153+
goto no_vfs;
154+
}
155+
156+
return num_vfs;
157+
}
158+
159+
no_vfs:
160+
pci_disable_sriov(pdev);
161+
162+
kfree(pdsc->vfs);
163+
pdsc->vfs = NULL;
164+
pdsc->num_vfs = 0;
165+
166+
return ret;
167+
}
168+
135169
static int pdsc_init_vf(struct pdsc *vf)
136170
{
137-
return -1;
171+
struct devlink *dl;
172+
173+
vf->vf_id = pci_iov_vf_id(vf->pdev);
174+
175+
dl = priv_to_devlink(vf);
176+
devl_lock(dl);
177+
devl_register(dl);
178+
devl_unlock(dl);
179+
180+
return 0;
138181
}
139182

140183
static const struct devlink_health_reporter_ops pdsc_fw_reporter_ops = {
@@ -323,6 +366,8 @@ static void pdsc_remove(struct pci_dev *pdev)
323366
devl_unlock(dl);
324367

325368
if (!pdev->is_virtfn) {
369+
pdsc_sriov_configure(pdev, 0);
370+
326371
del_timer_sync(&pdsc->wdtimer);
327372
if (pdsc->wq)
328373
destroy_workqueue(pdsc->wq);
@@ -354,6 +399,7 @@ static struct pci_driver pdsc_driver = {
354399
.id_table = pdsc_id_table,
355400
.probe = pdsc_probe,
356401
.remove = pdsc_remove,
402+
.sriov_configure = pdsc_sriov_configure,
357403
};
358404

359405
static int __init pdsc_init_module(void)

0 commit comments

Comments
 (0)