Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3874038pxb; Mon, 21 Feb 2022 07:24:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVlTkYP85u6hxa85Gf+PK9/ibXYpOc122G/H4tjWzBOtGofoCelXDrWwoTTARwmYhjZAOm X-Received: by 2002:a17:90b:1713:b0:1bc:3eca:627c with SMTP id ko19-20020a17090b171300b001bc3eca627cmr5130824pjb.144.1645457099324; Mon, 21 Feb 2022 07:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645457099; cv=none; d=google.com; s=arc-20160816; b=YhWloBncgko083bzkVTW09trdwQl/2NLfsItzgI02tZFtTzaDiINGrD+uLrh0kRyku 7OjyzB3uNf2oGMUnksZYLNfKRD8oRjK3rpYMG5w/mcZ7ohjVQibHrX5fBvnd5gHfhqEv R732zI9ymr0Xr/3zxykW3Mg0lHUUdtN6gmMCIaRdC7Rd1EthaV101QpnlQId5qMpJg79 lBbB4tDsxz1jke21fZ6HVoxGnH2h+BjgKZAo/GX3oBPxjV6Jep+ehfWn8q+GXNxlx8kx cUrD3rORcRViJUZBt0my+QdkI/1ttzAyUXCcp9COFFLU6GhrYccu5h2leGs9d6PMh6g9 DGKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=vlRrJbP4k0u6wCYIw46qMMA393R8bDk6JSYWRoziKHQ=; b=NX41nzHnHijTktdbtr8DOSXFisP/kWIoIK1aCIm+gZDuBVJmnoa3c8fMUnobqFRDsP zSnL/JSpmJZR5d+xtuGgz9CTOaAl/ra4osqtQ0zKcFyCmJ0MeZRl4fpoT8ymRFZc3OGT KGI2339L45kyIB/mu/KLFz5JeyMfolWNSPYJnASbUIzU8S7i2y3k0qYYCMnIKtFQBrxg ozwbO3V8Z1lXGSeLFsuKHHVUf8lPHowSPfeE2HM8nhSoFfUXTchoEcChGtQsn4SEkggL 5BUsWuwSW728CHuu3NbX4D5pKOe9BKQKSYe5fFxCXuAWt/ntG8R2rIlEcaGL3M96JiTL b7iQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m17si7086543pfk.367.2022.02.21.07.24.43; Mon, 21 Feb 2022 07:24:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356665AbiBULmm (ORCPT + 99 others); Mon, 21 Feb 2022 06:42:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356655AbiBULmY (ORCPT ); Mon, 21 Feb 2022 06:42:24 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97B3B1C121; Mon, 21 Feb 2022 03:41:57 -0800 (PST) Received: from fraeml702-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4K2Kyy3gkYz67wfW; Mon, 21 Feb 2022 19:37:14 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml702-chm.china.huawei.com (10.206.15.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.21; Mon, 21 Feb 2022 12:41:55 +0100 Received: from A2006125610.china.huawei.com (10.47.91.169) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 21 Feb 2022 11:41:49 +0000 From: Shameer Kolothum To: , , CC: , , , , , , , , , Subject: [PATCH v5 6/8] hisi_acc_vfio_pci: Add helper to retrieve the PF qm data Date: Mon, 21 Feb 2022 11:40:41 +0000 Message-ID: <20220221114043.2030-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20220221114043.2030-1-shameerali.kolothum.thodi@huawei.com> References: <20220221114043.2030-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.47.91.169] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); + 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 #include +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 -- 2.25.1