Message ID | 20220221114043.2030-7-shameerali.kolothum.thodi@huawei.com (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | Herbert Xu |
Headers | show |
Series | vfio/hisilicon: add ACC live migration driver | expand |
On Mon, 21 Feb 2022 11:40:41 +0000 Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> wrote: > Provides a helper function to retrieve the PF QM data associated > with a ACC VF dev. This makes use of the pci_iov_get_pf_drvdata() > to get PF drvdata safely. Introduces helpers to retrieve the ACC > PF dev struct pci_driver pointers as this is an input into the > pci_iov_get_pf_drvdata(). > > Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> > --- > drivers/crypto/hisilicon/hpre/hpre_main.c | 6 ++++ > drivers/crypto/hisilicon/sec2/sec_main.c | 6 ++++ > drivers/crypto/hisilicon/zip/zip_main.c | 6 ++++ > drivers/vfio/pci/hisilicon/Kconfig | 7 +++++ > .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 30 +++++++++++++++++++ > include/linux/hisi_acc_qm.h | 5 ++++ > 6 files changed, 60 insertions(+) > > diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c > index ba4043447e53..80fb9ef8c571 100644 > --- a/drivers/crypto/hisilicon/hpre/hpre_main.c > +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c > @@ -1189,6 +1189,12 @@ static struct pci_driver hpre_pci_driver = { > .driver.pm = &hpre_pm_ops, > }; > > +struct pci_driver *hisi_hpre_get_pf_driver(void) > +{ > + return &hpre_pci_driver; > +} > +EXPORT_SYMBOL(hisi_hpre_get_pf_driver); Curious why none of these are _GPL symbols. Thanks, Alex
diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c index ba4043447e53..80fb9ef8c571 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_main.c +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c @@ -1189,6 +1189,12 @@ static struct pci_driver hpre_pci_driver = { .driver.pm = &hpre_pm_ops, }; +struct pci_driver *hisi_hpre_get_pf_driver(void) +{ + return &hpre_pci_driver; +} +EXPORT_SYMBOL(hisi_hpre_get_pf_driver); + static void hpre_register_debugfs(void) { if (!debugfs_initialized()) diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c index ab806fb481ac..d8fb5c2b3482 100644 --- a/drivers/crypto/hisilicon/sec2/sec_main.c +++ b/drivers/crypto/hisilicon/sec2/sec_main.c @@ -1087,6 +1087,12 @@ static struct pci_driver sec_pci_driver = { .driver.pm = &sec_pm_ops, }; +struct pci_driver *hisi_sec_get_pf_driver(void) +{ + return &sec_pci_driver; +} +EXPORT_SYMBOL(hisi_sec_get_pf_driver); + static void sec_register_debugfs(void) { if (!debugfs_initialized()) diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c index f4a517728385..b6ccc7e8f37e 100644 --- a/drivers/crypto/hisilicon/zip/zip_main.c +++ b/drivers/crypto/hisilicon/zip/zip_main.c @@ -1010,6 +1010,12 @@ static struct pci_driver hisi_zip_pci_driver = { .driver.pm = &hisi_zip_pm_ops, }; +struct pci_driver *hisi_zip_get_pf_driver(void) +{ + return &hisi_zip_pci_driver; +} +EXPORT_SYMBOL(hisi_zip_get_pf_driver); + static void hisi_zip_register_debugfs(void) { if (!debugfs_initialized()) diff --git a/drivers/vfio/pci/hisilicon/Kconfig b/drivers/vfio/pci/hisilicon/Kconfig index d5acaf74a878..02811364a7a7 100644 --- a/drivers/vfio/pci/hisilicon/Kconfig +++ b/drivers/vfio/pci/hisilicon/Kconfig @@ -2,6 +2,13 @@ config HISI_ACC_VFIO_PCI tristate "VFIO PCI support for HiSilicon ACC devices" depends on (ARM64 && VFIO_PCI_CORE) || (COMPILE_TEST && 64BIT) + depends on PCI && PCI_MSI + depends on UACCE || UACCE=n + depends on ACPI + select CRYPTO_DEV_HISI_QM + select CRYPTO_DEV_HISI_HPRE + select CRYPTO_DEV_HISI_SEC2 + select CRYPTO_DEV_HISI_ZIP help This provides generic PCI support for HiSilicon ACC devices using the VFIO framework. diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c index 585eb84684c9..9c87ab74bf7f 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -13,6 +13,36 @@ #include <linux/vfio.h> #include <linux/vfio_pci_core.h> +static struct hisi_qm *hisi_acc_get_pf_qm(struct pci_dev *pdev) +{ + struct hisi_qm *pf_qm; + struct pci_driver *pf_driver; + + if (!pdev->is_virtfn) + return NULL; + + switch (pdev->device) { + case PCI_DEVICE_ID_HUAWEI_SEC_VF: + pf_driver = hisi_sec_get_pf_driver(); + break; + case PCI_DEVICE_ID_HUAWEI_HPRE_VF: + pf_driver = hisi_hpre_get_pf_driver(); + break; + case PCI_DEVICE_ID_HUAWEI_ZIP_VF: + pf_driver = hisi_zip_get_pf_driver(); + break; + default: + return NULL; + } + + if (!pf_driver) + return NULL; + + pf_qm = pci_iov_get_pf_drvdata(pdev, pf_driver); + + return !IS_ERR(pf_qm) ? pf_qm : NULL; +} + static int hisi_acc_pci_rw_access_check(struct vfio_device *core_vdev, size_t count, loff_t *ppos, size_t *new_count) diff --git a/include/linux/hisi_acc_qm.h b/include/linux/hisi_acc_qm.h index 5eb1e87ccd70..393ef17d306e 100644 --- a/include/linux/hisi_acc_qm.h +++ b/include/linux/hisi_acc_qm.h @@ -477,4 +477,9 @@ void hisi_qm_pm_init(struct hisi_qm *qm); int hisi_qm_get_dfx_access(struct hisi_qm *qm); void hisi_qm_put_dfx_access(struct hisi_qm *qm); void hisi_qm_regs_dump(struct seq_file *s, struct debugfs_regset32 *regset); + +/* Used by VFIO ACC live migration driver */ +struct pci_driver *hisi_sec_get_pf_driver(void); +struct pci_driver *hisi_hpre_get_pf_driver(void); +struct pci_driver *hisi_zip_get_pf_driver(void); #endif
Provides a helper function to retrieve the PF QM data associated with a ACC VF dev. This makes use of the pci_iov_get_pf_drvdata() to get PF drvdata safely. Introduces helpers to retrieve the ACC PF dev struct pci_driver pointers as this is an input into the pci_iov_get_pf_drvdata(). Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> --- drivers/crypto/hisilicon/hpre/hpre_main.c | 6 ++++ drivers/crypto/hisilicon/sec2/sec_main.c | 6 ++++ drivers/crypto/hisilicon/zip/zip_main.c | 6 ++++ drivers/vfio/pci/hisilicon/Kconfig | 7 +++++ .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 30 +++++++++++++++++++ include/linux/hisi_acc_qm.h | 5 ++++ 6 files changed, 60 insertions(+)