Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1545658pxb; Tue, 8 Feb 2022 21:49:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqXUpRWjROBr9tV+/OQz96r/Rj65OG7F5BLcRy/AuFLuvn3zdq/hLG0MJpaOvXrBs5gvbl X-Received: by 2002:a17:902:ab11:: with SMTP id ik17mr693657plb.9.1644385757884; Tue, 08 Feb 2022 21:49:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644385757; cv=none; d=google.com; s=arc-20160816; b=XJcXrzEVTRnOS2FOTMLmgxcv7a7rxKb+wnDcUsBgw176p2XT5+kZyf8YoAycZtaUah Ja+sBOymmjWdVMDfN/Q2wPAiqIzNsWC+KyB2ZUz2uCbGt8E7PauBRqDmimTd4+CssjDp fWawApT2cXOvS09Z9T7hSaILMBP+Ah/O7N/JCWY0Ek+tlfUKvhrcygl11Wm2ksuYHYTO 5yjrMzUEsNpZjAhKFAlDBAhGIbelcHT6zWcxHYnTgOomgFPs6PM4hbh5SKYSUObNjMnN 98P7ZtycgmamEaAVz7jcKFWomFoHwIKJGm80AShUHExJbGp4xZ49JmV86tl7n16ulIU8 OAlw== 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=lFJqnwUNqC7ECmzpIDOt+E3D67UDUf8DqXpfYFArh7U=; b=wteLOC9BjzdZY41LMBwEbY2h2pTVXtRkFdbsm9RTmtuXMtoXJnJFVz0VMK33qZIfAo 6y2qrHhxR5vO1zU4wjOL3nVEMqBdGC6+Maw/C1XvkC4WV6US96iccM3DXaXTWJ5JptOt m/9DQJXxByiPgTGYaKThZ2M3tBILt+MGSgdSM5Q21xlPSpC+tsISxqrDA/8QKXUtfY3S 3SNYvlkm6bJpUjXk9T2lqtF5lPr+8YwYbiD/BplWStFnWPpP6JBpK9Sy4nDHMziRaQxS 4pObvtVjiXRVxbEJW0ozZO7EF9OmoaYJqCC4+KhG86JC3phu3JUKvdrKjgRp/ALOPtpK LH2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o10si13240872plk.368.2022.02.08.21.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 21:49:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3A25BE00ED50; Tue, 8 Feb 2022 21:44:21 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354305AbiBHNgy (ORCPT + 99 others); Tue, 8 Feb 2022 08:36:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbiBHNgv (ORCPT ); Tue, 8 Feb 2022 08:36:51 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F9FC03FEDA; Tue, 8 Feb 2022 05:36:51 -0800 (PST) Received: from fraeml735-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4JtP7942wcz685QH; Tue, 8 Feb 2022 21:31:49 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml735-chm.china.huawei.com (10.206.15.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 8 Feb 2022 14:36:49 +0100 Received: from A2006125610.china.huawei.com (10.202.227.178) 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; Tue, 8 Feb 2022 13:36:42 +0000 From: Shameer Kolothum To: , , CC: , , , , , , , , , Subject: [RFC v4 6/8] crypto: hisilicon/qm: Add helper to retrieve the PF qm data Date: Tue, 8 Feb 2022 13:34:23 +0000 Message-ID: <20220208133425.1096-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20220208133425.1096-1-shameerali.kolothum.thodi@huawei.com> References: <20220208133425.1096-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.202.227.178] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-crypto@vger.kernel.org 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 --- 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