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 } 55