[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220208133425.1096-7-shameerali.kolothum.thodi@huawei.com>
Date: Tue, 8 Feb 2022 13:34:23 +0000
From: Shameer Kolothum <shameerali.kolothum.thodi@...wei.com>
To: <kvm@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-crypto@...r.kernel.org>
CC: <alex.williamson@...hat.com>, <jgg@...dia.com>,
<cohuck@...hat.com>, <mgurtovoy@...dia.com>, <yishaih@...dia.com>,
<linuxarm@...wei.com>, <liulongfang@...wei.com>,
<prime.zeng@...ilicon.com>, <jonathan.cameron@...wei.com>,
<wangzhou1@...ilicon.com>
Subject: [RFC v4 6/8] crypto: hisilicon/qm: Add helper to retrieve the PF qm data
Provides a new interface 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@...wei.com>
---
drivers/crypto/hisilicon/hpre/hpre_main.c | 6 ++++
drivers/crypto/hisilicon/qm.c | 38 +++++++++++++++++++++++
drivers/crypto/hisilicon/sec2/sec_main.c | 6 ++++
drivers/crypto/hisilicon/zip/zip_main.c | 6 ++++
include/linux/hisi_acc_qm.h | 6 ++++
5 files changed, 62 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);
+
static void hpre_register_debugfs(void)
{
if (!debugfs_initialized())
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index 8c29f9fba573..b2858a6f925a 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -5999,6 +5999,44 @@ void hisi_qm_put_dfx_access(struct hisi_qm *qm)
}
EXPORT_SYMBOL_GPL(hisi_qm_put_dfx_access);
+struct hisi_qm *hisi_qm_get_pf_qm(struct pci_dev *pdev)
+{
+ struct hisi_qm *pf_qm;
+ struct pci_driver *(*fn)(void) = NULL;
+
+ if (!pdev->is_virtfn)
+ return NULL;
+
+ switch (pdev->device) {
+ case PCI_DEVICE_ID_HUAWEI_SEC_VF:
+ fn = symbol_get(hisi_sec_get_pf_driver);
+ break;
+ case PCI_DEVICE_ID_HUAWEI_HPRE_VF:
+ fn = symbol_get(hisi_hpre_get_pf_driver);
+ break;
+ case PCI_DEVICE_ID_HUAWEI_ZIP_VF:
+ fn = symbol_get(hisi_zip_get_pf_driver);
+ break;
+ default:
+ return NULL;
+ }
+
+ if (!fn)
+ return NULL;
+
+ pf_qm = pci_iov_get_pf_drvdata(pdev, fn());
+
+ if (pdev->device == PCI_DEVICE_ID_HUAWEI_SEC_VF)
+ symbol_put(hisi_sec_get_pf_driver);
+ else if (pdev->device == PCI_DEVICE_ID_HUAWEI_HPRE_VF)
+ symbol_put(hisi_hpre_get_pf_driver);
+ else
+ symbol_put(hisi_zip_get_pf_driver);
+
+ return !IS_ERR(pf_qm) ? pf_qm : NULL;
+}
+EXPORT_SYMBOL_GPL(hisi_qm_get_pf_qm);
+
/**
* hisi_qm_pm_init() - Initialize qm runtime PM.
* @qm: pointer to accelerator device.
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/include/linux/hisi_acc_qm.h b/include/linux/hisi_acc_qm.h
index 8befb59c6fb3..6dbc5df2923b 100644
--- a/include/linux/hisi_acc_qm.h
+++ b/include/linux/hisi_acc_qm.h
@@ -476,4 +476,10 @@ 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 hisi_qm *hisi_qm_get_pf_qm(struct pci_dev *pdev);
+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
--
2.17.1
Powered by blists - more mailing lists