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

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 <brett.creeley@amd.com>
Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20230807205755.29579-5-brett.creeley@amd.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Brett Creeley and committed by
Alex Williamson
63f77a71 b021d05e

+105 -2
+1
drivers/vfio/pci/pds/Makefile
··· 4 4 obj-$(CONFIG_PDS_VFIO_PCI) += pds-vfio-pci.o 5 5 6 6 pds-vfio-pci-y := \ 7 + cmds.o \ 7 8 pci_drv.o \ 8 9 vfio_dev.o
+54
drivers/vfio/pci/pds/cmds.c
··· 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 + }
+10
drivers/vfio/pci/pds/cmds.h
··· 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_ */
+14
drivers/vfio/pci/pds/pci_drv.c
··· 8 8 #include <linux/types.h> 9 9 #include <linux/vfio.h> 10 10 11 + #include <linux/pds/pds_common.h> 11 12 #include <linux/pds/pds_core_if.h> 13 + #include <linux/pds/pds_adminq.h> 12 14 13 15 #include "vfio_dev.h" 16 + #include "pci_drv.h" 17 + #include "cmds.h" 14 18 15 19 #define PDS_VFIO_DRV_DESCRIPTION "AMD/Pensando VFIO Device Driver" 16 20 #define PCI_VENDOR_ID_PENSANDO 0x1dd8 ··· 36 32 if (err) 37 33 goto out_put_vdev; 38 34 35 + err = pds_vfio_register_client_cmd(pds_vfio); 36 + if (err) { 37 + dev_err(&pdev->dev, "failed to register as client: %pe\n", 38 + ERR_PTR(err)); 39 + goto out_unregister_coredev; 40 + } 41 + 39 42 return 0; 40 43 44 + out_unregister_coredev: 45 + vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev); 41 46 out_put_vdev: 42 47 vfio_put_device(&pds_vfio->vfio_coredev.vdev); 43 48 return err; ··· 56 43 { 57 44 struct pds_vfio_pci_device *pds_vfio = pds_vfio_pci_drvdata(pdev); 58 45 46 + pds_vfio_unregister_client_cmd(pds_vfio); 59 47 vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev); 60 48 vfio_put_device(&pds_vfio->vfio_coredev.vdev); 61 49 }
+9
drivers/vfio/pci/pds/pci_drv.h
··· 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 */
+12 -1
drivers/vfio/pci/pds/vfio_dev.c
··· 6 6 7 7 #include "vfio_dev.h" 8 8 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 + 9 14 struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev) 10 15 { 11 16 struct vfio_pci_core_device *core_device = dev_get_drvdata(&pdev->dev); ··· 25 20 container_of(vdev, struct pds_vfio_pci_device, 26 21 vfio_coredev.vdev); 27 22 struct pci_dev *pdev = to_pci_dev(vdev->dev); 28 - int err, vf_id; 23 + int err, vf_id, pci_id; 29 24 30 25 vf_id = pci_iov_vf_id(pdev); 31 26 if (vf_id < 0) ··· 36 31 return err; 37 32 38 33 pds_vfio->vf_id = vf_id; 34 + 35 + pci_id = PCI_DEVID(pdev->bus->number, pdev->devfn); 36 + dev_dbg(&pdev->dev, 37 + "%s: PF %#04x VF %#04x vf_id %d domain %d pds_vfio %p\n", 38 + __func__, pci_dev_id(pdev->physfn), pci_id, vf_id, 39 + pci_domain_nr(pdev->bus), pds_vfio); 39 40 40 41 return 0; 41 42 }
+3
drivers/vfio/pci/pds/vfio_dev.h
··· 11 11 struct vfio_pci_core_device vfio_coredev; 12 12 13 13 int vf_id; 14 + u16 client_id; 14 15 }; 15 16 16 17 const struct vfio_device_ops *pds_vfio_ops_info(void); 17 18 struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev); 19 + 20 + struct pci_dev *pds_vfio_to_pci_dev(struct pds_vfio_pci_device *pds_vfio); 18 21 19 22 #endif /* _VFIO_DEV_H_ */
+2 -1
include/linux/pds/pds_common.h
··· 34 34 35 35 #define PDS_DEV_TYPE_CORE_STR "Core" 36 36 #define PDS_DEV_TYPE_VDPA_STR "vDPA" 37 - #define PDS_DEV_TYPE_VFIO_STR "VFio" 37 + #define PDS_DEV_TYPE_VFIO_STR "vfio" 38 38 #define PDS_DEV_TYPE_ETH_STR "Eth" 39 39 #define PDS_DEV_TYPE_RDMA_STR "RDMA" 40 40 #define PDS_DEV_TYPE_LM_STR "LM" 41 41 42 42 #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 43 44 44 45 struct pdsc; 45 46