Skip to content

Commit 63f77a7

Browse files
brettcreeleyawilliam
authored andcommitted
vfio/pds: register with the pds_core PF
The pds_core driver will supply adminq services, so find the PF and register with the DSC services. Use the following commands to enable a VF: echo 1 > /sys/bus/pci/drivers/pds_core/$PF_BDF/sriov_numvfs Signed-off-by: Brett Creeley <[email protected]> Signed-off-by: Shannon Nelson <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Shameer Kolothum <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent b021d05 commit 63f77a7

File tree

8 files changed

+105
-2
lines changed

8 files changed

+105
-2
lines changed

drivers/vfio/pci/pds/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
obj-$(CONFIG_PDS_VFIO_PCI) += pds-vfio-pci.o
55

66
pds-vfio-pci-y := \
7+
cmds.o \
78
pci_drv.o \
89
vfio_dev.o

drivers/vfio/pci/pds/cmds.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright(c) 2023 Advanced Micro Devices, Inc. */
3+
4+
#include <linux/io.h>
5+
#include <linux/types.h>
6+
7+
#include <linux/pds/pds_common.h>
8+
#include <linux/pds/pds_core_if.h>
9+
#include <linux/pds/pds_adminq.h>
10+
11+
#include "vfio_dev.h"
12+
#include "cmds.h"
13+
14+
int pds_vfio_register_client_cmd(struct pds_vfio_pci_device *pds_vfio)
15+
{
16+
struct pci_dev *pdev = pds_vfio_to_pci_dev(pds_vfio);
17+
char devname[PDS_DEVNAME_LEN];
18+
struct pdsc *pdsc;
19+
int ci;
20+
21+
snprintf(devname, sizeof(devname), "%s.%d-%u", PDS_VFIO_LM_DEV_NAME,
22+
pci_domain_nr(pdev->bus),
23+
PCI_DEVID(pdev->bus->number, pdev->devfn));
24+
25+
pdsc = pdsc_get_pf_struct(pdev);
26+
if (IS_ERR(pdsc))
27+
return PTR_ERR(pdsc);
28+
29+
ci = pds_client_register(pdsc, devname);
30+
if (ci < 0)
31+
return ci;
32+
33+
pds_vfio->client_id = ci;
34+
35+
return 0;
36+
}
37+
38+
void pds_vfio_unregister_client_cmd(struct pds_vfio_pci_device *pds_vfio)
39+
{
40+
struct pci_dev *pdev = pds_vfio_to_pci_dev(pds_vfio);
41+
struct pdsc *pdsc;
42+
int err;
43+
44+
pdsc = pdsc_get_pf_struct(pdev);
45+
if (IS_ERR(pdsc))
46+
return;
47+
48+
err = pds_client_unregister(pdsc, pds_vfio->client_id);
49+
if (err)
50+
dev_err(&pdev->dev, "unregister from DSC failed: %pe\n",
51+
ERR_PTR(err));
52+
53+
pds_vfio->client_id = 0;
54+
}

drivers/vfio/pci/pds/cmds.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright(c) 2023 Advanced Micro Devices, Inc. */
3+
4+
#ifndef _CMDS_H_
5+
#define _CMDS_H_
6+
7+
int pds_vfio_register_client_cmd(struct pds_vfio_pci_device *pds_vfio);
8+
void pds_vfio_unregister_client_cmd(struct pds_vfio_pci_device *pds_vfio);
9+
10+
#endif /* _CMDS_H_ */

drivers/vfio/pci/pds/pci_drv.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
#include <linux/types.h>
99
#include <linux/vfio.h>
1010

11+
#include <linux/pds/pds_common.h>
1112
#include <linux/pds/pds_core_if.h>
13+
#include <linux/pds/pds_adminq.h>
1214

1315
#include "vfio_dev.h"
16+
#include "pci_drv.h"
17+
#include "cmds.h"
1418

1519
#define PDS_VFIO_DRV_DESCRIPTION "AMD/Pensando VFIO Device Driver"
1620
#define PCI_VENDOR_ID_PENSANDO 0x1dd8
@@ -32,8 +36,17 @@ static int pds_vfio_pci_probe(struct pci_dev *pdev,
3236
if (err)
3337
goto out_put_vdev;
3438

39+
err = pds_vfio_register_client_cmd(pds_vfio);
40+
if (err) {
41+
dev_err(&pdev->dev, "failed to register as client: %pe\n",
42+
ERR_PTR(err));
43+
goto out_unregister_coredev;
44+
}
45+
3546
return 0;
3647

48+
out_unregister_coredev:
49+
vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev);
3750
out_put_vdev:
3851
vfio_put_device(&pds_vfio->vfio_coredev.vdev);
3952
return err;
@@ -43,6 +56,7 @@ static void pds_vfio_pci_remove(struct pci_dev *pdev)
4356
{
4457
struct pds_vfio_pci_device *pds_vfio = pds_vfio_pci_drvdata(pdev);
4558

59+
pds_vfio_unregister_client_cmd(pds_vfio);
4660
vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev);
4761
vfio_put_device(&pds_vfio->vfio_coredev.vdev);
4862
}

drivers/vfio/pci/pds/pci_drv.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright(c) 2023 Advanced Micro Devices, Inc. */
3+
4+
#ifndef _PCI_DRV_H
5+
#define _PCI_DRV_H
6+
7+
#include <linux/pci.h>
8+
9+
#endif /* _PCI_DRV_H */

drivers/vfio/pci/pds/vfio_dev.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
#include "vfio_dev.h"
88

9+
struct pci_dev *pds_vfio_to_pci_dev(struct pds_vfio_pci_device *pds_vfio)
10+
{
11+
return pds_vfio->vfio_coredev.pdev;
12+
}
13+
914
struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev)
1015
{
1116
struct vfio_pci_core_device *core_device = dev_get_drvdata(&pdev->dev);
@@ -20,7 +25,7 @@ static int pds_vfio_init_device(struct vfio_device *vdev)
2025
container_of(vdev, struct pds_vfio_pci_device,
2126
vfio_coredev.vdev);
2227
struct pci_dev *pdev = to_pci_dev(vdev->dev);
23-
int err, vf_id;
28+
int err, vf_id, pci_id;
2429

2530
vf_id = pci_iov_vf_id(pdev);
2631
if (vf_id < 0)
@@ -32,6 +37,12 @@ static int pds_vfio_init_device(struct vfio_device *vdev)
3237

3338
pds_vfio->vf_id = vf_id;
3439

40+
pci_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
41+
dev_dbg(&pdev->dev,
42+
"%s: PF %#04x VF %#04x vf_id %d domain %d pds_vfio %p\n",
43+
__func__, pci_dev_id(pdev->physfn), pci_id, vf_id,
44+
pci_domain_nr(pdev->bus), pds_vfio);
45+
3546
return 0;
3647
}
3748

drivers/vfio/pci/pds/vfio_dev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ struct pds_vfio_pci_device {
1111
struct vfio_pci_core_device vfio_coredev;
1212

1313
int vf_id;
14+
u16 client_id;
1415
};
1516

1617
const struct vfio_device_ops *pds_vfio_ops_info(void);
1718
struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev);
1819

20+
struct pci_dev *pds_vfio_to_pci_dev(struct pds_vfio_pci_device *pds_vfio);
21+
1922
#endif /* _VFIO_DEV_H_ */

include/linux/pds/pds_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ enum pds_core_vif_types {
3434

3535
#define PDS_DEV_TYPE_CORE_STR "Core"
3636
#define PDS_DEV_TYPE_VDPA_STR "vDPA"
37-
#define PDS_DEV_TYPE_VFIO_STR "VFio"
37+
#define PDS_DEV_TYPE_VFIO_STR "vfio"
3838
#define PDS_DEV_TYPE_ETH_STR "Eth"
3939
#define PDS_DEV_TYPE_RDMA_STR "RDMA"
4040
#define PDS_DEV_TYPE_LM_STR "LM"
4141

4242
#define PDS_VDPA_DEV_NAME PDS_CORE_DRV_NAME "." PDS_DEV_TYPE_VDPA_STR
43+
#define PDS_VFIO_LM_DEV_NAME PDS_CORE_DRV_NAME "." PDS_DEV_TYPE_LM_STR "." PDS_DEV_TYPE_VFIO_STR
4344

4445
struct pdsc;
4546

0 commit comments

Comments
 (0)