From patchwork Mon Sep 11 22:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13380451 X-Patchwork-Delegate: manivannanece23@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63C92CA0EC3 for ; Tue, 12 Sep 2023 01:15:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233689AbjILBPY (ORCPT ); Mon, 11 Sep 2023 21:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbjILBPJ (ORCPT ); Mon, 11 Sep 2023 21:15:09 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on0602.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0c::602]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDA22174387; Mon, 11 Sep 2023 18:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hpMb7IX+7oA73X33ItmyizZ43fdwVOyJLgNjpD9prLE7PKTUI2yDnxoy2AcEyP80dkwNd6TE+nVQiNfkMZGyFAMRij395U45XYwY+hrJMlJXSDN1PeAkpJDPt813bAoGkBqIN2ZTHPcOPr/ydQjQ1K3y5RtA+mjcX1FJtSIlVVtqit/wjbWtqJVmED9ojU2TuRN5zaY0mAzBsxUaPXQgBl9kPHXMrCPD1kFlB/1txj/ZZurXDLwOZ9Cw+wQrn1ROFoOptZdHy5dczZvJTDgb1xB8eJeAewiSQxMX8H4A6xOo0xZNhgLz7vlseJ5gswdQfYI6BeKgu11zAdZspCvQrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=g+bjztS/6vJwT0O0RAzLFlqabXhUpXXiyiK6O/MCCdA=; b=KcPV/darBv8kD/G+b8NDEZaXkOgY7xHdxRR+NrsdYi7OUs8umVUSV4ookgt7BmH2oeg1fgIo55xnVcKaMuHoGHIU45P+vtlAB+yJ53629icQYbBNquR/hVeOZZLJAL8b4zj23pXamHilElO/axMfv9y/R0Ik0ubwb+VQUL/gQIjSrQ+K8iaxH5fFtwQP2HfhQvbB8icN8wT/AMH9LeoEpYf7UQ+lKnh9iwZ3BIUNNzd5ymYS36zpZJ90GBAq4WQWnfvm79alcvWacKkiq0zZwYXc6AIUC95+rDyM+Pll8YkyaqO9aGee0bMAyT2zmlhrtZrZ0KeuHRy7C0ARJFs1IQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g+bjztS/6vJwT0O0RAzLFlqabXhUpXXiyiK6O/MCCdA=; b=sTahCCtK5S+nZDllaajvvbsYPQg3PRMMqUZF6K+4exkhQcqRW6wNWq0z5IsyRFOqXm0TgZpCP8EWqVTcRcmWZcNk34J0lH3ROa0nSoauLRYM03SdQAKWGqSegyl18EutGI3iTDxRJ8o+EnTVoO0QRb/yEaixEldegvilZ4/rXs0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PAXPR04MB8125.eurprd04.prod.outlook.com (2603:10a6:102:1cc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Mon, 11 Sep 2023 22:09:48 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a%3]) with mapi id 15.20.6768.029; Mon, 11 Sep 2023 22:09:47 +0000 From: Frank Li To: manivannan.sadhasivam@linaro.org Cc: Frank.li@nxp.com, aisheng.dong@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, festevam@gmail.com, imx@lists.linux.dev, jdmason@kudzu.us, kernel@pengutronix.de, kishon@kernel.org, kw@linux.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, lpieralisi@kernel.org, maz@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org, tglx@linutronix.de Subject: [PATCH v2 1/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Date: Mon, 11 Sep 2023 18:09:16 -0400 Message-Id: <20230911220920.1817033-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230911220920.1817033-1-Frank.Li@nxp.com> References: <20230911220920.1817033-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR07CA0010.namprd07.prod.outlook.com (2603:10b6:a02:bc::23) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PAXPR04MB8125:EE_ X-MS-Office365-Filtering-Correlation-Id: defeff76-23ec-4301-9d8d-08dbb313cfef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lprMpiLy3lfhuL9aWimIP0hW31Rd7stM6KetKarLdtW8i7Ex/N5pM1o5/hh4c5hx0GQOjEn/A6cTfrUR3POD3jzeHRmtyJLJf2lMYxSaLRIth01USa16LKQ2lethX32lJfbmM4nP0+UGjn+VZRXJS1pD5dQNOYHkB16KBRswIdTYalSG9W9zS3ksEzNuy3yCe+0WloUjw1VkmvTc3nyKUvUOqzYBxDrjdBrhiX8EJjQzP5ErwytKMYEsJVS881KN1bBcDhDqg5Q0k6upAENOU4hM1AlrO7F/aE2GPS8XTOEelUpTWAoJxOuCqT3CgJ/lxhVJR6iU7QsAZUPAg3byAlCE9i9LLh6f+7ZH2NE54FzkzRm3K14f9NY58QTdwAvdTRPf5dQBKKQnQjyyViJKkexXXmYl6CYQxCjy2v3BjX7W68gDFK/cxtIw/hnAyDpw4VP19jFYi2wEYewC4cTaee1O6Y8CGzen+XssWojzHgrIS2+37PKAyBQHZuZPXv1FLGt+RkS8nJD4lzvnSPB/Bhu8/YMQlatnoHdv2cNqLltm6qX6PAHEgQThsRyvOEHKq5BMGK6y4c7Hi9qcrfj0G2Vnu2sCRr6yuGIp5mJGOLeBAX+lMffOsOjaWAr+KPP4 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(366004)(136003)(396003)(346002)(1800799009)(186009)(451199024)(6512007)(26005)(1076003)(86362001)(30864003)(2906002)(83380400001)(6486002)(2616005)(52116002)(6506007)(6666004)(7416002)(38350700002)(478600001)(38100700002)(36756003)(5660300002)(8676002)(8936002)(66476007)(66556008)(4326008)(6916009)(316002)(66946007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RHPr7vHg0qxX3txC6ASjwmwVtiJG9pff8fCyTdV6R/71sNPe7OSH7onXrvvV1zXtj4bVEYwQ5zYTrRRW+qQ58GAMbMxAgGajjD7WF5p20o4QPyLp0ImrtN6ZJ8bZGj14KpwSgvgYVPlnxYLqhPPwmoC4Sb/XXMTjVjO8irwj3XFamUUbIyrkqdpqLscbO2n87j9XKYN+KYzmPOnj+zojmQHi8FuxGquikSd3J1VwBaTcMxrpCUUykVPakmj01UqXjiaZ2xhNWJMdS3GgF9cFnPxVq1y8Vg8jj5q5vqopBQBaldHPJ4m8B+pzeWkw5dXqWKcHH8dCdDsL1Ba8/6YaMJHxFAyfIaB0p50NKoaAOndzpuaOWflp0mWvnVYS/pluh37hQeIX6hd+y1jbiPl853iE3OExZfrDSyUQhrys7zItFPs1s8kEuJvT8tveObN+eUbq+bJ7I4OuX7c38dy04dGhRMMlv1ROLa8LuCmx+z07TjYJmGkC8wTj0is63uKrbh9uFc5TkVJjNSRGLkCSZlNF2TW8EIo/WG/+LR6MXnteG6nEgtWxHmn2UaN1HMkAjNlZcRLV7OKBeukZZ2gHN8DnIZDsFU07cmURtMzjLEFnum9RJPc5FcRLRcq1qN6lrzMuT9qJiXYEM/CFod43H8AqETV55dLq+DqDAxkwHIXXqP8nRfVrzt2dX/FsMJblUk3iauLjmR18qA8uUpX4aL9HhTwl99EMEnzm6mfXQ3OfHXz/VzHsEH8HMb9WLHyjVXwqbhsgBqxJMMq1ZkgRWXzHqPCSTQ1FWeh/dZKQxp874wC14fvCOXrb/68Ko9c6qIBF99b836IXvvqEFwhqJ1pgS8gzjBhkBWJWWPF0L3s8avqcBDpuIDBmkoa92KkrG5L3jV5mnJaQPSlc71UzxxaJ4kOr2n9b1QTKx5wfLYrLz72cVUis1SAIKTHB8svERf4JYpg8INLZl2hqLHGcQzfLe09kJiwlJVp8tvcSyCEfiKSKi0YvnAiaKRIBCh9Som2y9epLNoyt9SYyWfYcksNMD+VaCbGnomiTMitsgm9YACLPGeaMSHeSv/r2OnjGEWlQohQmuaut3O/AJkLBRPNqLfYfzFyCxsqgACr14qcZLmkJw3jnlWpn8EgkY6jL6ST1sefvDcm5a/On4qk/zmHlezAi1+ydEtr79FjqF+Npq/z6u/MzmuFPKDprLqKQzpBhH6PV2TjNJUBkW9ntlqUovYx+O9tZxzZDWFYnzqyZ58Ml032W6Ysl6oGsiJMqMhP6fk8Vc2EcHOdJ/ySABeb9zd7fBW6Tjs8fctEbt/1YvRsyJ5W/BznqJbr4fsXV5jnrKoQLYfLvkET3sIP8DROS9J2sT5ZOTfSDIhsgBetlCRBSxM77kOVX7z8r5zRKjRWCaGm/q5/3IhYu6mGtOFM6JxptWfJvOItZQyCVEV9aBsZ5QFOgDoVezkjOJwwwsAK99oegzUzHU9IVwrotMT1jEtX/hUg/KzMidx4GovftQI0lNTOpgoqTBZlnw6XZkHkn5EZqjjcAZX1TYNySdfyj9JTi/x4PjjeM9UF5Di2274FNJkHH+5YK+eUQ3KtV X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: defeff76-23ec-4301-9d8d-08dbb313cfef X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2023 22:09:47.8851 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jRuUPpgkwk9/49haExCk5Z66DgNC8GcGERZpdDwm0JFvOsi605XaMGJhpy8x+RrYyoc6yyPhB3km+ta2RMLUtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8125 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This commit introduces a common method for sending messages from the Root Complex (RC) to the Endpoint (EP) by utilizing the platform MSI interrupt controller, such as ARM GIC, as an EP doorbell. Maps the memory assigned for the BAR region by the PCI host to the message address of the platform MSI interrupt controller in the PCI EP. As a result, when the PCI RC writes to the BAR region, it triggers an IRQ at the EP. This implementation serves as a common method for all endpoint function drivers. However, it currently supports only one EP physical function due to limitations in ARM MSI/IMS readiness. Signed-off-by: Frank Li --- drivers/pci/endpoint/pci-epc-core.c | 192 ++++++++++++++++++++++++++++ drivers/pci/endpoint/pci-epf-core.c | 44 +++++++ include/linux/pci-epc.h | 6 + include/linux/pci-epf.h | 7 + 4 files changed, 249 insertions(+) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 5a4a8b0be6262..d336a99c6a94f 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -783,6 +784,197 @@ void pci_epc_bme_notify(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_bme_notify); +/** + * pci_epc_alloc_doorbell() - alloc an address space to let RC trigger EP side IRQ by write data to + * the space. + * + * @epc: the EPC device that need doorbell address and data from RC. + * @func_no: the physical endpoint function number in the EPC device. + * @vfunc_no: the virtual endpoint function number in the physical function. + * @num_msgs: the total number of doorbell messages + * + * Return: 0 success, other is failure + */ +int pci_epc_alloc_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no, int num_msgs) +{ + int ret; + + if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) + return -EINVAL; + + if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no])) + return -EINVAL; + + if (!epc->ops->alloc_doorbell) + return 0; + + mutex_lock(&epc->lock); + ret = epc->ops->alloc_doorbell(epc, func_no, vfunc_no, num_msgs); + mutex_unlock(&epc->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epc_alloc_doorbell); + +/** + * pci_epc_free_doorbell() - free resource allocated by pci_epc_alloc_doorbell() + * + * @epc: the EPC device that need doorbell address and data from RC. + * @func_no: the physical endpoint function number in the EPC device. + * @vfunc_no: the virtual endpoint function number in the physical function. + * + * Return: 0 success, other is failure + */ +void pci_epc_free_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no) +{ + if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) + return; + + if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no])) + return; + + if (!epc->ops->free_doorbell) + return; + + mutex_lock(&epc->lock); + epc->ops->free_doorbell(epc, func_no, vfunc_no); + mutex_unlock(&epc->lock); +} +EXPORT_SYMBOL_GPL(pci_epc_free_doorbell); + +static irqreturn_t pci_epf_generic_doorbell_handler(int irq, void *data) +{ + struct pci_epf *epf = data; + + if (epf->event_ops && epf->event_ops->doorbell) + epf->event_ops->doorbell(epf, irq - epf->virq_base); + + return IRQ_HANDLED; +} + +static void pci_epc_generic_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc = NULL; + struct class_dev_iter iter; + struct pci_epf *epf; + struct device *dev; + + class_dev_iter_init(&iter, pci_epc_class, NULL, NULL); + while ((dev = class_dev_iter_next(&iter))) { + if (dev->parent != desc->dev) + continue; + + epc = to_pci_epc(dev); + + class_dev_iter_exit(&iter); + break; + } + + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + + if (!epf) + return; + + if (epf->msg && desc->msi_index < epf->num_msgs) + epf->msg[desc->msi_index] = *msg; +} + + +/** + * pci_epc_generic_alloc_doorbell() - Common help function. Allocate address space from MSI + * controller + * + * @epc: the EPC device that need doorbell address and data from RC. + * @func_no: the physical endpoint function number in the EPC device. + * @vfunc_no: the virtual endpoint function number in the physical function. + * @num_msgs: the total number of doorbell messages + * + * Remark: use this function only if EPC driver just register one EPC device. + * + * Return: 0 success, other is failure + */ +int pci_epc_generic_alloc_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no, int num_msgs) +{ + struct pci_epf *epf; + struct device *dev; + int virq, last; + int ret; + int i; + + if (IS_ERR_OR_NULL(epc)) + return -EINVAL; + + /* Currently only support one func and one vfunc for doorbell */ + if (func_no || vfunc_no) + return -EINVAL; + + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + if (!epf) + return -EINVAL; + + dev = epc->dev.parent; + ret = platform_msi_domain_alloc_irqs(dev, num_msgs, pci_epc_generic_write_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI\n"); + return -ENOMEM; + } + + last = -1; + for (i = 0; i < num_msgs; i++) { + virq = msi_get_virq(dev, i); + if (i == 0) + epf->virq_base = virq; + + ret = request_irq(virq, pci_epf_generic_doorbell_handler, 0, + kasprintf(GFP_KERNEL, "pci-epc-doorbell%d", i), epf); + + if (ret) { + dev_err(dev, "Failed to request doorbell\n"); + goto err_free_irq; + } + last = i; + } + + return 0; + +err_free_irq: + for (i = 0; i < last; i++) + kfree(free_irq(epf->virq_base + i, epf)); + platform_msi_domain_free_irqs(dev); + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(pci_epc_generic_alloc_doorbell); + +/** + * pci_epc_generic_free_doorbell() - Common help function. Free resource created by + * pci_epc_generic_alloc_doorbell() + * + * @epc: the EPC device that need doorbell address and data from RC. + * @func_no: the physical endpoint function number in the EPC device. + * @vfunc_no: the virtual endpoint function number in the physical function. + * @num_msgs: the total number of doorbell messages + */ +void pci_epc_generic_free_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no) +{ + struct pci_epf *epf; + int i; + + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + if (!epf) + return; + + for (i = 0; i < epf->num_msgs; i++) + kfree(free_irq(epf->virq_base + i, epf)); + + platform_msi_domain_free_irqs(epc->dev.parent); +} +EXPORT_SYMBOL_GPL(pci_epc_generic_free_doorbell); + /** * pci_epc_destroy() - destroy the EPC device * @epc: the EPC device that has to be destroyed diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 2c32de6679377..eab82c6b0119a 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -300,6 +301,49 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, } EXPORT_SYMBOL_GPL(pci_epf_alloc_space); +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_msgs) +{ + struct pci_epc *epc; + struct device *dev; + int ret; + + epc = epf->epc; + dev = &epc->dev; + + epf->msg = kcalloc(num_msgs, sizeof(struct msi_msg), GFP_KERNEL); + if (!epf->msg) + return -ENOMEM; + + epf->num_msgs = num_msgs; + + ret = pci_epc_alloc_doorbell(epc, epf->func_no, epf->vfunc_no, num_msgs); + if (ret) + goto err_free_mem; + + return ret; + +err_free_mem: + kfree(epf->msg); + epf->msg = NULL; + epf->num_msgs = 0; + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + struct pci_epc *epc; + + epc = epf->epc; + pci_epc_free_doorbell(epc, epf->func_no, epf->vfunc_no); + + kfree(epf->msg); + epf->msg = NULL; + epf->num_msgs = 0; +} +EXPORT_SYMBOL_GPL(pci_epf_free_doorbell); + static void pci_epf_remove_cfs(struct pci_epf_driver *driver) { struct config_group *group, *tmp; diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 5cb6940310729..605fb0debd6bc 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -88,6 +88,8 @@ struct pci_epc_ops { void (*stop)(struct pci_epc *epc); const struct pci_epc_features* (*get_features)(struct pci_epc *epc, u8 func_no, u8 vfunc_no); + int (*alloc_doorbell)(struct pci_epc *epc, u8 func_no, u8 vfunc_no, int num_msgs); + void (*free_doorbell)(struct pci_epc *epc, u8 func_no, u8 vfunc_no); struct module *owner; }; @@ -251,4 +253,8 @@ void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc, phys_addr_t *phys_addr, size_t size); void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr, void __iomem *virt_addr, size_t size); +int pci_epc_alloc_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no, int num_msgs); +void pci_epc_free_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no); +int pci_epc_generic_alloc_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no, int num_msgs); +void pci_epc_generic_free_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no); #endif /* __LINUX_PCI_EPC_H */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 3f44b6aec4770..485c146a5efe2 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -79,6 +79,7 @@ struct pci_epc_event_ops { int (*link_up)(struct pci_epf *epf); int (*link_down)(struct pci_epf *epf); int (*bme)(struct pci_epf *epf); + int (*doorbell)(struct pci_epf *epf, int index); }; /** @@ -180,6 +181,9 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct msi_msg *msg; + u16 num_msgs; + int virq_base; }; /** @@ -223,4 +227,7 @@ int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums); +void pci_epf_free_doorbell(struct pci_epf *epf); + #endif /* __LINUX_PCI_EPF_H */ From patchwork Mon Sep 11 22:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13380437 X-Patchwork-Delegate: manivannanece23@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 378DBCA0EC6 for ; Tue, 12 Sep 2023 00:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231349AbjILAqM (ORCPT ); Mon, 11 Sep 2023 20:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232043AbjILAqE (ORCPT ); Mon, 11 Sep 2023 20:46:04 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on060b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::60b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9AA8141923; Mon, 11 Sep 2023 17:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JM9T91Hk2Yy0wLB09pZdnPTd9iFpXDHoc24rfWyQ8tJKgTQL6aEO9b8qTWcqE1iIU29oI0eBWJZuvub3t16yRjp1JaZRfK6I9QzGU7UUFJT4d6Wd9cCTp0pnvCqVIDpuND22uWYhYmfnmqoclH/sq1eQxNq6pI24b6+gtfbBpssetXp43M6efkC6bmQ5w5aK/JOd1YFiNxRxpgN6eTmbW15kO0pSvFxavNOtlQ9zfK8UBSOwmK2L62IRuvUK2gTx2nNdMDlt+7N2jzxEc/5jRYSgAtSf5Jj88p7mV0mLS4jYSHMMjeb+x/HPx0pW2XWNbakuOI0AhsL8At4E5BkRgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4EhE1gap6D3kYZSQq/ASaMYmSkecBwLLo1zEPZt2hAI=; b=CWrHluc6fKzH68k4DRjjWfzn5kBQ5aWAILiCXFSHtkfqPEpK7Mdshwttgeb9MQrxnCS+ewgpzlXx3YVhUqUjlHKfaNxuI7D/ULgAYA5WbVcE0Eii/1yN/qm6whoxVwyrKBqhv7BTUINH4AmBWK+lyRzgJHkRgYM/d3gOlyjMjANe1EvAWSgsPS4cUGm7s7UoqldD4bo7RgL0e7jZcptgSUKyHcXzRBzvREKlrIj08jOqVXvnEBE0oUdCQov00e/UWquOQUOzHxICSpp4y3WfMSdYoKBNnbY0EFQP1khXTdT9++r2xCc1A59iWlvwroeWkXhXCAzJGHySX/VTirk52w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4EhE1gap6D3kYZSQq/ASaMYmSkecBwLLo1zEPZt2hAI=; b=SXQlHhfGySxEy+U7abpSFU/Yy1bwUQXigpBOy3Uy+oTM1c0WPukunK/J2d1h+lkMYBtFR4UYooxID3R6ibf7meU0wb3F5erP5/didx6ErVbWiatlq2A+wyP8NN7dfGRWg3q8Z6glB7/ws2mPedrjk3cIIfB4cFXz/hu4l8KM7ls= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PAXPR04MB8125.eurprd04.prod.outlook.com (2603:10a6:102:1cc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Mon, 11 Sep 2023 22:09:52 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a%3]) with mapi id 15.20.6768.029; Mon, 11 Sep 2023 22:09:52 +0000 From: Frank Li To: manivannan.sadhasivam@linaro.org Cc: Frank.li@nxp.com, aisheng.dong@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, festevam@gmail.com, imx@lists.linux.dev, jdmason@kudzu.us, kernel@pengutronix.de, kishon@kernel.org, kw@linux.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, lpieralisi@kernel.org, maz@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org, tglx@linutronix.de Subject: [PATCH v2 2/5] PCI: dwc: add doorbell support by use MSI controller Date: Mon, 11 Sep 2023 18:09:17 -0400 Message-Id: <20230911220920.1817033-3-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230911220920.1817033-1-Frank.Li@nxp.com> References: <20230911220920.1817033-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR07CA0010.namprd07.prod.outlook.com (2603:10b6:a02:bc::23) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PAXPR04MB8125:EE_ X-MS-Office365-Filtering-Correlation-Id: 132e49fa-d0a7-43f8-1fcf-08dbb313d2c9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Si/R84P0WKU4WEEhixSFHJEqa94WJUkEPAYKQSyWPPWVccxPc2G97kwIARoiDSHTlsVWJsjJRvk6VQVZrCpAs4rAYtWr+o5k5LqoofYFVt/2agpi1OofJCCGUvSAm6GkTC8gfnPmb4rNgVaI4PDEi/8VCbfhXNwHIdNgfC7B7BEAoK+CG5LnhX9j4YlDo9ryEJwCl+I6j9ogugTAO0tEVd5aQhAwWB6ReCI1Kpj5JOQiKYucILn5CzxnxGKlgMdOSC1jIUBWgWVG/rpaZSPwpuSGBigWDrvGLO6Ba4WA8jJICANOvf3fDpFNkbcp/3CE37APk/JVPgyt9L9R5SpEFruPkZjqN0XqNOm0CPfpIGz3KJbWol3hHJqAbbrL99E3CU9DSxFxx5t35Q9VTZXb+q627hIQVw+chfmi8MZ2mN/yH6yqLRgYlsN97t2pJdq5HaHEQ4BFAuUkZLZxtMkLGA5gIZ4G8OVtO1k9idHo6oVZ5hdIJYBL+dXdav44WoQR69vMnFtMTxFx94wzENMDLWFJOwqik7ZhMQ572gX5Le1fJ7mWgiF/RpwBoaoA4UJgj6I44KjA1KlmUdS44i+KkcrBmSXGdX2di6Tg0FnguzFO080hJZGa3R4iPWX18pe4 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(366004)(136003)(396003)(346002)(1800799009)(186009)(451199024)(6512007)(26005)(1076003)(86362001)(2906002)(83380400001)(6486002)(2616005)(52116002)(6506007)(6666004)(7416002)(38350700002)(478600001)(38100700002)(36756003)(5660300002)(8676002)(8936002)(66476007)(66556008)(4326008)(6916009)(316002)(66946007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RrNdvTxONOmEkXTSjRRVJ1pswjZ6mcc3kJTyhwlLIqafNei71LKqzhBiSobFh2fMDT11AaXtqYlSzU8Rza1Jc2925QD19qNPGRvl91S05gJmAKrWAZ0B3OpAsrO5HpRUUlcxfv0VNu4yCp+YnmmcS/DiNkCvXG8w8xj2BJuS+4Vwth1hSKjN+Kt5fJTduUwRvUfKEBeEbmqhAR/OhCKs0JwdhaeC45PfmFI+2eJSctSeOUC/uh667IZtBDSVNzdbyfTuZ99kqejrWHXzfS7SGCH8mgZ169kpdKrUJ/JXpgDG54URkGeuj7hAH1FigDwYEaPjNrQq3PX40B7gjlAkKycfRk36aUxLrtIW/4fsYcmuwCP5IJ45PrETBWs15lSLDn/x1KU8NJ/LimmnZQ7syqXtOuFvm0tnXOwz+eqqaCQ8JeI/WgDkBvLZtE1+oFe/yQtVYHPEZLxl9pJiZwrZiR63Xpuw+ZH8Nc6roMVCA11asIMvtJv2mlR1bj2H57dREBcPgDm1jWZH3N7DJ0FzZd9JipBvN9pz3EfHuOHfmdcF+xRUFV30tRABFdASMry2PJKiICkE62ptxEB0RxXGalJRkUKDdeGAiav37Nh7SqTR/uUzLei/iBBMQAykEOZEWDp7tgpA5jhqpWLk7yXWSwgcrRCk2wlL3L9y4AAplZ8oWgg9iUKqyiUuxnjKPIBeQyQ3zHDszDUCeS2WfW8kGSVCEg8/t/yem7B+f9rrpWfNqG1RFzwQEpzYsL9DWWNXVEGZaa1y7eT7ssZAfaoyHQ5YrMg2tKnxjntSwDDa/5jr6Cf1qWr9Dpfmgs+P0RCaQuhuaJlQpIR7SLqToc8UB7/L8aHMIN7p8EDzxBr+nLshjFj7tjGyA6H/kS2EAQZCUOoq32bCrDuiodCVDsx1JsIU6guT1TDBz/P1gavLTpMwc/OA2irKWArE87e3Zyjh9gK9OPaHbR69//fM9fFIAVZd1KiokDEnURahNfpOZ9uTCvWGus9J3lk5rTwFn8otDZlw5lzvK21RSD9hFPJFFM0WphwpfzEYSbhXwIMmmai2C17Xnu2/ac+EXoauVjl9+kPgBTKr6FJgEf01e+G046VL8gTKXW11Z4ElaGO3GRCS+MbLi/xQks0G/fo+6lkRy21mlNJ86ccw+4Y1fIQ8Basxr2N2Zj3S7a6SDmQ6NY05w7gxvbiy/VssMcSm3IdyWLbMTERDgyNiXzrjuvQ+VaWWoKaVv1sVJBUt5I2sH6SodHRuAY5EWeNrjLmPPJ7nkIE3v1p5/UDpYGxnCZ4ycyVqfKFzN7rJNO7KII/dFtkIjfXgY5mpZTGv5WT8Duh0w8apIUCFmo/BGDCCdn8RGUTo1cyArxRhtNIgwF6ZuCtPK4BjemAb8Ft5/C5zGCQ/4UknbgKa/VtQhqdEPxjZaVY+kvsZRCy2RMPlGkCEaHoiiieRO9ua6357ALARGg/Bjqbed2O3CMRr03AiU32TERjrx7ov2sSE1jo7B3Ko3wNEDrLdgMcwgbYQHa5ECThU1iTn4CPXBkCh2VQXc4FFYBSUy4U7iHPVVOi0g5HLJA1aLdHMakmlX6xn599Ffi/q X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 132e49fa-d0a7-43f8-1fcf-08dbb313d2c9 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2023 22:09:52.8026 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KMH0qVgSc6npN8FBytjjLhSMnBIQ2uFR7th6qglISl/+6FaGrK4P6C506/3NBkk4Yu9hl7G1IbfvFk2Da8fngQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8125 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Call pci_epc_generic_alloc_doorbell() to alloc an platform MSI address space.The Endpoint (EP) function drver can maps the memory assigned for the BAR region by the PCI host to the message address of the platform MSI interrupt controller in the PCI EP. As a result, when the PCI RC writes to the BAR region, it triggers an IRQ at the EP. Signed-off-by: Frank Li --- drivers/pci/controller/dwc/pcie-designware-ep.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index f9182f8d552f4..4f6be5f4ba18a 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -477,6 +477,8 @@ static const struct pci_epc_ops epc_ops = { .start = dw_pcie_ep_start, .stop = dw_pcie_ep_stop, .get_features = dw_pcie_ep_get_features, + .alloc_doorbell = pci_epc_generic_alloc_doorbell, + .free_doorbell = pci_epc_generic_free_doorbell, }; int dw_pcie_ep_raise_legacy_irq(struct dw_pcie_ep *ep, u8 func_no) From patchwork Mon Sep 11 22:09:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13380459 X-Patchwork-Delegate: manivannanece23@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 791C6CA0EC8 for ; Tue, 12 Sep 2023 01:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235487AbjILBab (ORCPT ); Mon, 11 Sep 2023 21:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235261AbjILBaU (ORCPT ); Mon, 11 Sep 2023 21:30:20 -0400 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on20630.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaf::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A737F184470; Mon, 11 Sep 2023 18:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vz7skDRsoECeM2FCmTjf6BK2RIt7V0fZgwsBE9MTcsFffMPoSZe944w3xdL/Pqf/PB4T0DoJd/K9mc2XUcC40gGv1el990H20vPWA8gO5y2Ya7gIEFCfAa4Wkmu8kK6AsKtIY/ues5iVUQ6fQdvTi8Tj5ysbAq0p/PvUfTTbp0122ZgXpyCR/5r4JWWHjHYGm5szO1LRkqa4Eri2R2aeuZKnTv7yBka3lEFk/2JuAHaginAeIxLRdnfyyfQDlNjMW68/8p99F1dz4s8LGt7s8p6hkC3iLDjCcfs88Sx08HQC5X0O9P6Rl0eSNWL6yuFVKvgeVTr7QXAVT2ho/n0NDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kn/xKL/kdfC5LoTDOItOlRfR7cNqoPTQczNOO7CdilI=; b=Az1Uvbkpp80eaA3vdi7facqSMq3zY8YQcPdyjo58jftCMQ+nybl28R0vj9Mz7V7qtnzheTnv7/ksY0iWalGbF8GFDjZEsZ0BICOTvjZzzJWUGVQtjG3n+EtPUfrAy2cTy7pF//YDV3VfEsAP5MHI3qhtWrza1cdmTjyy3gsaf9eyYcm4g8SFBK3AZXEh03ldZLX1NshQqtkJssL4HSMGb6qCcqYN2/kdnjfpQO3uquXS/jlzw5aQeLL465wR49m5wY3ybKnj9cnMlyfIWkx8hVAMQmFU9ZEmWxlCTKr4Ee9f3POsO/yz1ltbzh0w5DCHUdlQZPCbjqgB4HgRvFuDRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kn/xKL/kdfC5LoTDOItOlRfR7cNqoPTQczNOO7CdilI=; b=AAeWW+K5AJyMFKtZFf+ffnJjoLrakmseMR1DooNvvIxvODgHcjrAMjuJIZUh3O3RNSZ/Mm2lSG+6eRcijc5+FoV0kPBzX0+pQCOu9H37jiUIv8mZtaQUKtJMWItHaVaEtKe8yRAEYezr1iEaXPeXs0AVDYX2PwmofVA+gr31fSc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PAXPR04MB8125.eurprd04.prod.outlook.com (2603:10a6:102:1cc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Mon, 11 Sep 2023 22:09:57 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a%3]) with mapi id 15.20.6768.029; Mon, 11 Sep 2023 22:09:57 +0000 From: Frank Li To: manivannan.sadhasivam@linaro.org Cc: Frank.li@nxp.com, aisheng.dong@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, festevam@gmail.com, imx@lists.linux.dev, jdmason@kudzu.us, kernel@pengutronix.de, kishon@kernel.org, kw@linux.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, lpieralisi@kernel.org, maz@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org, tglx@linutronix.de Subject: [PATCH v2 3/5] PCI: endpoint: pci-epf-test: add doorbell test Date: Mon, 11 Sep 2023 18:09:18 -0400 Message-Id: <20230911220920.1817033-4-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230911220920.1817033-1-Frank.Li@nxp.com> References: <20230911220920.1817033-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR07CA0010.namprd07.prod.outlook.com (2603:10b6:a02:bc::23) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PAXPR04MB8125:EE_ X-MS-Office365-Filtering-Correlation-Id: 63d7a292-805c-4abe-b487-08dbb313d5b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KsSfjwz4koHw+bRPf0t8XgpnhFBhRnMoyM9mnZxRnju6k+CIVvIOoeYSBb5EX2gNoPOxcsXIPSTNy7WY4NPs0xG8iQQ0s6rXiiGxcte/wawQRooUB7UwIdHYgjEMg/c5U4T4ROutf6jHcobO8AGf8yyiUUcwd5zTL2SONkXoNQ06QhBJEyfKk1Vh+CvmD0lkPAgs6VZU5qH6DmRP3IZxpxG1cFuh3gFKo+tENYum8mlOe3hnBIe/pYdhAc5s0ZpNQuE9RCmOvYN54fXh2Xn4rVaw4M495TM8iTBhXfyA+zGS4k19+wUOak7iP6y3LoggVZm9XG7as8wWBcZsI66XcuCcmenuxXQcA/7txktC1AfNx5vmZq5B50BUckDvbA7sG/I9lqT886+jzGwJhiYRLo9/C+Msqj1lkXaj5FZByCRFg204524LzluI7ws6wC3pZkjDtvytfQX99VPzODFcGoQ4xf28rDRx5Qcg88SlTD89rWuT+AukZkOL16ydUkp5uhRxzImiaX5mna1Csguw7oIaxWyCwlqIGPvZZhqMRv80x/pT8FN+4d2RkrIMKTnz6E0BaN0roqTijxDXArY6SnJxRZOxHs8eXq1nz3QbD2VHUJuP+xATgl4/E3LqbCSX X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(366004)(136003)(396003)(346002)(1800799009)(186009)(451199024)(6512007)(26005)(1076003)(86362001)(2906002)(83380400001)(6486002)(2616005)(52116002)(6506007)(6666004)(7416002)(38350700002)(478600001)(38100700002)(36756003)(5660300002)(8676002)(8936002)(66476007)(66556008)(4326008)(6916009)(316002)(66946007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: T9LPQOR5e5E86dXLc4fzC1LjQYSC2G6E0piM8pAMxvdzxE2bdpgD6/i8+ZYal0aOeqbmUSi0DbKjsjTtJI+mblMM0UR97UXc/LjD7FD62J/5GHubjXHRFEfxBZwWx5oiLY8msxiA/J5i+wii+n+FvFE7X/Sd3z7S3hLvn3RYoonS/TgMtKR1NV94jlbAZv38EWj1IOc/KVL2x3tY6f2hJysxO0IB+8QT8PZBcy7HCPYBDIck5upGB9gih8aWC6A5oFBsvrXc3NL7NIv8L52+Lno/rxxqRrXiGNTeZ4BJFlFTFPM+IDTpGLzRO01nb20wfeJQBQwEKFxBStjmLWVd2K0ok3jlHUZeWTPeHK1/qOrVs1XzB17opyPAH+Jm4US3x/ImOzHb0w9EIUYU6HAhKBWesb3H4cv4bCbF6LXL7OPrTAphNqLycssofBNtNxvVEcRJaF/iwq6AVtQKC+ylfZjh9QeugY+LoQouJsH6xhra3w4bzEo1YGHVFF7bbn62HnDSXo7MStCsnow4cGxNzfgLRVewU18Gjsmag1iQ0yIO2eGSRN3p65jBBGCVKDrIVz/sFTuMpHZ1fwjP6et493cBA4sNMpI1hi71E4POqfMpcjQD/Lj1bj0FkE6Iwfs5Eh3j+r5+8OPRE0RbMV3J2LgrsZUPMFgqu2bA6gdEdPgh079sekujtF3bEuiN95F4oPH04SfPFbzHf8MPRyZOuRW5n0yIuE+n5wIE//GQy/ifactEYAcYYj/OlngJCYnedVHtdKQSdK8baUu5qZky/ot7BAcwEpV85e/1VpwDRe1zPtCYyFwRTZzT91wtPmxjYBc9xtus6e4YWhrwIPqtUPrEO0IAbxwsIIHagMrL24X5cqLoq0lKz4oKrDdWYWCH7DS3qcjmD2evvaR0t+PJFZQeoWj88yVF0yhrzgbS/pnNQlz95nH5LHsr7El2ZEyTfajLzfS29iY0Gt8tWQ/sUP2pRQ5fohuSmZK1tHxd1P4AfXBHRb8zvgyGNKhjMcDcvbkAsPo7+QAKdK8txJki1s34mlYfdehEc4F02x6bHVgnB/JkRQiGY1mnOiKd9X+QAg1otLZ/BuojaeVN5H75Uvjnz/T5DcU1+Fhnju5cqeBqL2/bkYB+Bkh+47m7bXmRmUJPo6iuKLQAYvzNd8lJ7qfff+RgKAfU6DV8hQIsie6mArzx7uULkoX/xc9IolWdtU1GcbgVNJZCBS5lLlq4EQ5EHBHCjJ2e6uYxaO/tuFYTht0S3gP1Bk2EimgJnzmgOqV4u7H64gJxk1t2Zubjuip7YHL4whSKtiJ/hAfIPMy86B/Ou76MZdj5f09zRDCS1JS+LvAjL5qlhYveEvMXhz4RVhAWYLEdqK9A8POGgQA63GjljY8/i/ssL6UH0j/4dxL7WN4RDrYmDR3T3SjgtqVJ+U7Go6Q78+MRiA55xguYcZYk2DPf0i9ZGqECxb7ZGbLDev/TMLx0FGOWhpK75CTs753GKGoX7/evP08yFU2SWG5xth2vIFdFjWeEOX4TpFNoI1T4gJITjDQVXPts2j9cYXfezZOwMFtC3WxZUwgLNz+SrvAnzWEnuBHTq7tx X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63d7a292-805c-4abe-b487-08dbb313d5b5 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2023 22:09:57.6113 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: T3HESZIgw61deJWHKoBqR37OdJOK0brf9/bETwqkTJYOTFg6/YEA/OT9jTkdu0vjosradiSm/q+O5kk/FCIfJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8125 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add three register: doorbell_bar, doorbell_addr, doorbell_data, doorbell_done. Call pci_epf_alloc_doorbell() all a doorbell address space. Root complex(RC) side driver can trigger pci-epc-test's doorbell callback handler by write doorbell_data to mapped doorbell_bar's address space. pci-epc-test will set doorbell_done in doorbell callback. Signed-off-by: Frank Li --- drivers/pci/endpoint/functions/pci-epf-test.c | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 1f0d2b84296a3..566549919b87b 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -39,17 +40,21 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) #define FLAG_USE_DMA BIT(0) #define TIMER_RESOLUTION 1 +#define MAGIC_VERSION_MASK GENMASK(7, 0) + static struct workqueue_struct *kpcitest_workqueue; struct pci_epf_test { void *reg[PCI_STD_NUM_BARS]; struct pci_epf *epf; enum pci_barno test_reg_bar; + enum pci_barno doorbell_bar; size_t msix_table_offset; struct delayed_work cmd_handler; struct dma_chan *dma_chan_tx; @@ -74,6 +79,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_addr; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -693,6 +701,8 @@ static void pci_epf_test_unbind(struct pci_epf *epf) struct pci_epf_bar *epf_bar; int bar; + pci_epf_free_doorbell(epf); + cancel_delayed_work(&epf_test->cmd_handler); pci_epf_test_clean_dma_chan(epf_test); for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { @@ -808,9 +818,22 @@ static int pci_epf_test_link_up(struct pci_epf *epf) return 0; } +static int pci_epf_test_doorbell(struct pci_epf *epf, int index) +{ + struct pci_epf_test *epf_test = epf_get_drvdata(epf); + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + pci_epf_test_raise_irq(epf_test, reg); + + return 0; +} + static const struct pci_epc_event_ops pci_epf_test_event_ops = { .core_init = pci_epf_test_core_init, .link_up = pci_epf_test_link_up, + .doorbell = pci_epf_test_doorbell, }; static int pci_epf_test_alloc_space(struct pci_epf *epf) @@ -859,7 +882,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) epf_bar = &epf->bar[bar]; add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; - if (bar == test_reg_bar) + if (bar == test_reg_bar || bar == epf_test->doorbell_bar) continue; if (!!(epc_features->reserved_bar & (1 << bar))) @@ -900,9 +923,14 @@ static int pci_epf_test_bind(struct pci_epf *epf) struct pci_epf_test *epf_test = epf_get_drvdata(epf); const struct pci_epc_features *epc_features; enum pci_barno test_reg_bar = BAR_0; + enum pci_barno doorbell_bar = NO_BAR; struct pci_epc *epc = epf->epc; bool linkup_notifier = false; bool core_init_notifier = false; + struct pci_epf_test_reg *reg; + struct msi_msg *msg; + u64 doorbell_addr; + u32 align; if (WARN_ON_ONCE(!epc)) return -EINVAL; @@ -923,10 +951,39 @@ static int pci_epf_test_bind(struct pci_epf *epf) epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; + align = epc_features->align; + align = align ? align : 128; + + ret = pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + msg = epf->msg; + doorbell_bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + if (doorbell_bar > 0) { + epf_test->doorbell_bar = doorbell_bar; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + epf->bar[doorbell_bar].phys_addr = round_down(doorbell_addr, align); + epf->bar[doorbell_bar].barno = doorbell_bar; + epf->bar[doorbell_bar].size = align; + } else { + pci_epf_free_doorbell(epf); + } + } + ret = pci_epf_test_alloc_space(epf); if (ret) return ret; + reg = epf_test->reg[test_reg_bar]; + reg->magic |= FIELD_PREP(MAGIC_VERSION_MASK, 0x1); + if (doorbell_bar > 0) { + reg->doorbell_addr = doorbell_addr & (align - 1); + reg->doorbell_data = msg->data; + reg->doorbell_bar = doorbell_bar; + } + if (!core_init_notifier) { ret = pci_epf_test_core_init(epf); if (ret) From patchwork Mon Sep 11 22:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13380477 X-Patchwork-Delegate: manivannanece23@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 781EBCA0ECB for ; Tue, 12 Sep 2023 01:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236029AbjILB5G (ORCPT ); Mon, 11 Sep 2023 21:57:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235461AbjILB4t (ORCPT ); Mon, 11 Sep 2023 21:56:49 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2047.outbound.protection.outlook.com [40.107.7.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A57FD18E070; Mon, 11 Sep 2023 18:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l/a4LdsjP1nC3UfbmZV6DReBouRjOkcEt5vvkuBMETUPMf8aL6wL5jCvkXpB71aWJGx7AxVFHh09o/ziRcI6aJlryI5Q9WJPNDOM6PlRiC63Cx7BrfuoKmGql0qjakYqyOt5WiBV6q8fG47/70qXDI4RMrK8a6cxB+EQHSocvxs9yNVQ0uCeDcIkVKIJDLtrhvRhPl+rGk5qpecFC6uzwEsGsxkkUFKgHQ9TzXweSI/ArBw9r8dFuWWfD1sFURT+MdKu0LMYsIlhOr3TTnVzPU5+d601VYsdwht/lBsBBNA1vDUbXgK70cvaKh5aSfsyMYgibMo/6+DkwzaRZOBFpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pawYnph2SHbrEHaYnXZY+4i/Sym/OYJTMb0F57YyL5U=; b=C3Q40CQkxYPAh8oELfmQnWTgWniOfR/xjAWYyID5B4YhwwBzKoenK2F/kK5RZVsqyeu/3imMxpZ+1T9HQEXy4sPlx16tgUlj3AsXcJhulnVTpzcFJMCE/fl+Lg13YQ7VWuubpQgqGm48m+y7/UpQikholygqlRa59CzGpN2SJXVlpLiFnpPK2cNBRk/qwYLrLom1oOTcwLCFWl6r6meNK+x1UdQKfsDy73DbK0+56jXCkbir+beOaVHOvsom4TD/iWW15Khcu4O+7LqyMWbNsX1N7pBN0E/7yhdylCiKdMIItsU4KYPsuUvS4v+TZZovmKh00sD4DFD7A8GDqWhSMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pawYnph2SHbrEHaYnXZY+4i/Sym/OYJTMb0F57YyL5U=; b=MU1Ihhggx4KY7TkbpWmdLa8s/7V1QVsZhVtuTsRnZRSLsVrzDUBCFbm8rhX2PddOJ591ezWNkSJCJqF8p1IAAJ+k6A/5dRLDU0+CnDa9nqLHC3WmCzhB5nuZf9M/OSamd/fDIBKPctpN4ka+vtBYrajqsj0whoB8Egupbbydkx0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PAXPR04MB8125.eurprd04.prod.outlook.com (2603:10a6:102:1cc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Mon, 11 Sep 2023 22:10:02 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a%3]) with mapi id 15.20.6768.029; Mon, 11 Sep 2023 22:10:02 +0000 From: Frank Li To: manivannan.sadhasivam@linaro.org Cc: Frank.li@nxp.com, aisheng.dong@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, festevam@gmail.com, imx@lists.linux.dev, jdmason@kudzu.us, kernel@pengutronix.de, kishon@kernel.org, kw@linux.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, lpieralisi@kernel.org, maz@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org, tglx@linutronix.de Subject: [PATCH v2 4/5] misc: pci_endpoint_test: Add doorbell test case Date: Mon, 11 Sep 2023 18:09:19 -0400 Message-Id: <20230911220920.1817033-5-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230911220920.1817033-1-Frank.Li@nxp.com> References: <20230911220920.1817033-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR07CA0010.namprd07.prod.outlook.com (2603:10b6:a02:bc::23) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PAXPR04MB8125:EE_ X-MS-Office365-Filtering-Correlation-Id: 36faf6f3-2e1a-4a65-fb7b-08dbb313d893 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rxI3Vti50fbk7fKFU2rppYOY7945uq/oB4MyyXrjgCM3czHqXP2UcNxaDkvOvhX/6LSg//7wfyqRyr1VYqAlXJfmwgFCKFMTyflLLxa4WT1a8btHqt0sw24u4gQy+Tck2a18cPirT5JBwfbjcgsrX8EAEZNGAqRNL9eJAhFq5LWa5E+f2m0JOrAOAeGiK8WC0k0A/GMX0rvnKfhZNGNFQxhHyek0Mh/7V28OR9QWxZIEzyC2yc2yGloqT5haCq12NF9lg/zzgGoMB2U+3QcbPhosd3zG99KF1LBQb22fcDKH3Wb0Tlba7kZsHaINhCiiXBqcuJWe1WUoQnq+FrmmgmQoNbXcW4c2LwGGFABAzto3h7w/cG3btAvJkRrcNFGc3/fbMTbbX3x8WvQHfkX2X9BcrExRg4zXgNIPEpHkkZr4O3l/JzlHU38aOdXfo1BJvHHGLFO4JQRZxjXIykIOCQkvMZQjUvJu0cxL1HB8L1XNl45qzzvR+zcxCqHIIBCzgeeh5PFWhYs2vi1PLnfyLUD7zjRoxKJkMkZlU1Pi2ucSMuo01VYiCbprMpNNw1UumtOYOzTCwh85nHr1Tt5e7JTZkEZe7J+2c84G+cIcU+lc0bLY3S/HvexTEXWf9wjm X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(366004)(136003)(396003)(346002)(1800799009)(186009)(451199024)(6512007)(26005)(1076003)(86362001)(2906002)(6486002)(2616005)(52116002)(6506007)(6666004)(7416002)(38350700002)(478600001)(38100700002)(36756003)(5660300002)(8676002)(8936002)(66476007)(66556008)(4326008)(6916009)(316002)(66946007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yxi+KdXfdghFQcabBU/ZI9LsPuWSwJWMt+PJfb3+PJsRWCETtfya6F8t73nyOYJwsjvwqi6sSvkEHP9AS9DMPjXRkxT+cB4+OEoa5QqseJoeD/9k9BoF60fe8auQlq6iV81ab3aFmRsBUKQxkcB5ST6J/eL9eZwYZ0MN/Qw4B42xt1gOZUIIk+h6dCmZJW27KThSSyLBO8vn0gV8tsvgtd6eH1gRA83nWXY9h8v5vYuJ8RKVirlNXOgb3HpQqSKnU5u69s7Dli6zJuo1MimOxSAnjzb+oF6v0HFpUsvxGoUwFVLWyzz5EodKnNbGAuLit2WVqMMsuBmIl/BzYlQQsh7/dalpdfgnxXGbQ1J6+D/OvNBGBdyK3VpGRcmEyeaKeM/sgjmAwvcaHwkcEyrac62xxMt+SgK3wPzSu8nz6BB901P1/2FSfRvPxmREf0PdP30LXuhJ2JcZjzupYzuLXPKSReJeiA3SXt9Skd3jJx0ZZ6mCTRqLCzbdQacQGfveci84Zhhmk+QhsHf0xqBk8/68IffyGOxV3fsfLIYFN4UuGmFYHGicmhBsXC+3FH0JZMz4tTntKY8IXynw6TWcqnQK5uwxm/VAy3KO008KmBgSoC5aVYmGW4yu7Zw7W+9ZBoRnpVJof0r2fdddty0x4niXsxa9C24x31hyiYFWZfz4RPrgwMXN2kNLjA65Ea2k9hYCTB/Q2K4fbbckrde0zbaOTB5eViWKNH97I7UIW2Is86Q7WuJZzoL3o9FQ/yh3YyUOlWl7ce/6k5BXVBU0v/ZElh2Py8/0raW03oRkKoauXnxFjEYgwLT3Odom2IDx+d20yFzq0Kk33azcw7za+HkrPc352CXhqFtCP9z0o5dmKt1A0bUcWdeO5IwVVk8mv5aDdwHQ7EmAbv82K1yJqoqCkM8y0NUBh7AbXIf3SK2ZpJyGZ/8EXMAfbID7YEmmv6Lh3vB4yZ3hLLIG+NBV8U3PjDeYPr28TJZ+8RPendFvLaz7Lq8bLIV7t1f1KTRLavLNubNt7HQgOcpg+iRC6GfNg2QnNelTkdoAaHfLvv5Y+4IWUy5LpWKS2JqQRu6ZZXtNY3i95fqhDxyt+sbfKUUccHtgsfN4u55okSGSw/GsYJr14aozTNie/tV4dwLtiP7yNuU/7oJls1XR01PrwIP5XgQsNDwWZopb1demvJfJftCe8qNLjSdhJcoexlJ69cky0CipgA1VUsPbMN2LrWrh3RQZP7A17TQsIqv2B2AxTu9VpYZPb9gKyD7NDYzod6uPmGrEWrMDNGvG1HqrIVdndIVlnTuLxbY42x1G0jP/lA6PRJx8V7oWg4FPtR5yKpxLkmUE4RqByIsBq5XV0d0i5+1km8b42XN9vfaxHBnnLLwFz2hmmpgz56UXplYn6PBsoADa1PFVX5KYRdbwqNjgb1Wn1HS8xWs/+V5zr56Uf2i/ovv9OOIkZ+6NbAhYfuTAWUPwW4cTKqo64m3im3uq954ka4GisI28ZbkZdRS6vqBLAi/7lhb6mKlXHmncH6RfnZFWWLbWRi37fu0DrGg0Mx9I1nQCkomxIqCbk5h0kLkA0RXBzG4jgV/7ohQ7 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36faf6f3-2e1a-4a65-fb7b-08dbb313d893 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2023 22:10:02.5036 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ETRiofgDtryzdrvW6eIJke6pBJScHa6INpxOByGPhOMiUKpRC9/QAdALBSgXNli1jaGcJEY7PFooNXUM/LYo+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8125 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Using bit 0..7 of magic as version number in pci_endpoint_test struct to support older driver versions. Save to 'version' field of struct pci_endpoint_test to prevent reading non-existent address. Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR, PCIE_ENDPOINT_TEST_DB_DATA. Write data from PCI_ENDPOINT_TEST_DB_DATA to address from PCI_ENDPOINT_TEST_DB_ADDR to trigger doorbell and wait for endpoint feedback. Signed-off-by: Frank Li --- drivers/misc/pci_endpoint_test.c | 48 ++++++++++++++++++++++++++++++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 49 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index ed4d0ef5e5c31..ed0b025132d17 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -33,6 +33,8 @@ #define IRQ_TYPE_MSIX 2 #define PCI_ENDPOINT_TEST_MAGIC 0x0 +#define PCI_MAGIC_VERSION_MASK GENMASK(7, 0) +#define PCI_ENDPOINT_TEST_V1 0x1 #define PCI_ENDPOINT_TEST_COMMAND 0x4 #define COMMAND_RAISE_LEGACY_IRQ BIT(0) @@ -52,6 +54,7 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) #define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10 @@ -66,7 +69,12 @@ #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28 #define PCI_ENDPOINT_TEST_FLAGS 0x2c +#define PCI_ENDPOINT_TEST_DB_BAR 0x30 +#define PCI_ENDPOINT_TEST_DB_ADDR 0x34 +#define PCI_ENDPOINT_TEST_DB_DATA 0x38 + #define FLAG_USE_DMA BIT(0) +#define FLAG_SUPPORT_DOORBELL BIT(1) #define PCI_DEVICE_ID_TI_AM654 0xb00c #define PCI_DEVICE_ID_TI_J7200 0xb00f @@ -102,6 +110,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR = -1, }; struct pci_endpoint_test { @@ -118,6 +127,7 @@ struct pci_endpoint_test { enum pci_barno test_reg_bar; size_t alignment; const char *name; + u8 version; }; struct pci_endpoint_test_data { @@ -713,6 +723,38 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, return false; } +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + enum pci_barno bar; + u32 data, status; + u32 addr; + + if (test->version < PCI_ENDPOINT_TEST_V1) + return false; + + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + if (bar == NO_BAR) + return false; + + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_ADDR); + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0); + pci_endpoint_test_bar_writel(test, bar, addr, data); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_SUCCESS) + return true; + + return false; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -760,6 +802,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, case PCITEST_CLEAR_IRQ: ret = pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret = pci_endpoint_test_doorbell(test); + break; } ret: @@ -887,6 +932,9 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, misc_device->parent = &pdev->dev; misc_device->fops = &pci_endpoint_test_fops; + test->version = FIELD_GET(PCI_MAGIC_VERSION_MASK, + pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_MAGIC)); + err = misc_register(misc_device); if (err) { dev_err(dev, "Failed to register device\n"); diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h index f9c1af8d141b4..479ca1aa3ae0b 100644 --- a/include/uapi/linux/pcitest.h +++ b/include/uapi/linux/pcitest.h @@ -20,6 +20,7 @@ #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int) #define PCITEST_GET_IRQTYPE _IO('P', 0x9) #define PCITEST_CLEAR_IRQ _IO('P', 0x10) +#define PCITEST_DOORBELL _IO('P', 0x11) #define PCITEST_FLAGS_USE_DMA 0x00000001 From patchwork Mon Sep 11 22:09:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13380480 X-Patchwork-Delegate: manivannanece23@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF907CA0EC3 for ; Tue, 12 Sep 2023 02:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237143AbjILCIU (ORCPT ); Mon, 11 Sep 2023 22:08:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235253AbjILBzb (ORCPT ); Mon, 11 Sep 2023 21:55:31 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2041.outbound.protection.outlook.com [40.107.21.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B9FF1B7EB2; Mon, 11 Sep 2023 18:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ys7D5ZsP6PsywLDbvxEZI8q4r/EG7vkiA6/7R+eBrzHBb/QJVmyzuKWkxilEHLQ/4mpE3gV2lYADQ4tksPCeJQKkohGiR4NQ4MpsPvEsVrxbvXWzRla+YLG4r2IqC2NvYmvtrdBhY8WvKEOz52f+vbDg9LqMdxTav8Johw0tFDXB1kXYmPnLMzG/o+RkntvqZf1LaxCxH1zKythzsru80x9oiyj+EVPw9jLQN044ETLB9I4EJW6qJwMKffeytDcRJ7KjoJo0KZki2Bysf2GGVtQJ4ZphZgUfBYhrYxxOw7OOw+/Ts1OPWJM4jz8Aw3ePYPi5OidtSzM0ZEp6hyOr+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=swA+Mv5Ko8rpGiwnsn9lzKn2XyQXSyIoXb5iBljgaCI=; b=cXPIG3VUN8tVkQT4/m11oYl/QLR39Sjq9kcRpbiXNJLMxYMTlgIOWJ1VWxRYyO4XuDdypvBhcRm3RL3vnrJSk/GoEZIdvBC+zNPdmoYvqXBEX8+nwQmea/hgQaLYNbMeAPEHkK5YVgTGLtnYeKoxQsJejthpzvOQAEmulVOVVIpC+5YpHFJkTAllp+4OghMBMltF5fefl9hT2A4q1kdQCOzv9ExA65L4CxnLCfbzh7B1hpHfCKmstgTmov6gUV08YBQ6LqYJvbVJHNJWRMnYDan2A/E5Or+5toVAQOJO9cfdTsB4qfsSPCcw/tkJ28XT3IFKVqmiB6F865IdE10uvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=swA+Mv5Ko8rpGiwnsn9lzKn2XyQXSyIoXb5iBljgaCI=; b=clebLMIRCDx3MxQJ8DwR/S3KbqXE+kueZCi/ZAfTMyW3t6YCDSDRVTeFQ4koVnXD9zQGWb5SCzw4rN1VzUKi0wAjIDmvu6kkK9eZpy8oaHJ+lxnA7p9aORHzHF0R3IC7n68vwokOtb4SoVu/G249epezxBUv0THyL5WC4wWA9zY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PAXPR04MB8125.eurprd04.prod.outlook.com (2603:10a6:102:1cc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Mon, 11 Sep 2023 22:10:07 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::aa90:117d:c1d0:346a%3]) with mapi id 15.20.6768.029; Mon, 11 Sep 2023 22:10:07 +0000 From: Frank Li To: manivannan.sadhasivam@linaro.org Cc: Frank.li@nxp.com, aisheng.dong@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, festevam@gmail.com, imx@lists.linux.dev, jdmason@kudzu.us, kernel@pengutronix.de, kishon@kernel.org, kw@linux.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, lpieralisi@kernel.org, maz@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org, tglx@linutronix.de Subject: [PATCH v2 5/5] tools: PCI: Add 'B' option for test doorbell Date: Mon, 11 Sep 2023 18:09:20 -0400 Message-Id: <20230911220920.1817033-6-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230911220920.1817033-1-Frank.Li@nxp.com> References: <20230911220920.1817033-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR07CA0010.namprd07.prod.outlook.com (2603:10b6:a02:bc::23) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PAXPR04MB8125:EE_ X-MS-Office365-Filtering-Correlation-Id: e66a8d84-6a46-43c7-904c-08dbb313db80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r2LdZ4NGK+EPRmiJGRz+eBPgr7ZJOC6Rm02C11ij6NlJhkp2sFTxySoNTpk/BMH5VQi/2RanHIz98WHQ8sOSHOWfnmOvGdK9GzEX5oZnigIqP9Cy56ZPV+cD53osdWsSx+uV0htOhPih+ts04LfeQNmv8pv/3i9qO5P6WLmHWvo9x/usf3ZDMbpA/f8dmiozXMhPOiIEQEXRYO5CEDvXWfRFmI+teywJvxuGbi7kGMbskrZm9g5hyQrWyArhMvnQQ61b8G3LlcUwU8rIV2rFHpLQpixbEL7D48hnWO68+30DrX8dsTdsTIGD9+CwfGhJ5YfsohavI/yixQHoTFzX/qq7DzAE/IJfY7gks2AK/ch8rgPSFwHTw4kPW3eU3aC+uZ8CYxpLIGsyCHs+nkT+DujHaKgdeaizvSUKxwvjbh2tUWysLC1Wv6VZQYwziGC5e4Kd66588M7cQYOeb1qNQJYutO0d/Uw+62Lyp63lAlRUDUgWb5oXTqiLH/jtVKuENVbrLn52E8fd91gPO2j689NxHmLbRzA+bpRGTML/W1TbJ7b1/L5WIaWSYjrJMueK43jA5gcPmmzjS8tksMvf4zZrrfT+2JqsuexiK/NiQg4mB8fwC+qlJnTvDgx2qzji X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(366004)(136003)(396003)(346002)(1800799009)(186009)(451199024)(6512007)(26005)(1076003)(86362001)(2906002)(83380400001)(6486002)(2616005)(52116002)(6506007)(6666004)(7416002)(38350700002)(478600001)(38100700002)(36756003)(5660300002)(8676002)(8936002)(66476007)(66556008)(4326008)(6916009)(316002)(66946007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XNqEVW8xHXXaA2vMQOdiUzBYMShA7HxIl5558OUEU/+tT8ExO2Uxaw9fKXn3/sRL7IdfaIZ5x9OfQn/pftf5AI/GHjFYEPgL/6ce4h6xYtu0c2angq/sgurBWBzRMEAS2mD7RPhmnrAsMDDkYjXGIlavvoScUsGDGmxNKTwYFxsRp5fCus6ufHVFEcsromlbb2MSXtWtk4K0omfe5DCZopn8yALXIZtQh6yJ27w3CIZ2/nVUUd1VCo4pFsG+TzzxvJwnDUvbZaOD3mr81b5E5qJwrttP5jT6leHq6K1IPUMRIxuCXmG5ENCiVmz1YEDsBKQGdwmMykA65mbJtPQ+EsSveXc33LPtcDuirVJ4q6/zUAlKPu5IIYgsccrFbqkHPc7GG1tZLGhDWWPxTQf/ErxsGwbGRMPjWVvC++d5EyP6kw5Eg7GbM0pLG2rHHLV3KrvfPFfYZq+Xan1KL7qVsJa9RjNqCpUtRFKs/rJ9V73b2lDZ7eJIxvzfTtKB9WjK8N9uWN2eWmZD6QgPuXrJ0i4gsFe7unn8nG64B0xCWYbeMtw/dfXbSqrB3Bh1t9bhwLkxRXmiINqqwqpUrGPSz1Km4X8z6x2X6J/AA5Y3MhjNFKrsfoOwvIrwysnq+o8luSSA7QoxXPKu1Mp0YqPO86O6JjkETE9aAOjxMSuQcYMx9CnHitsNUDvMHxSypCYWs4+u+Vkbv78gpPWtaGwr1Bh34nUCdRT1C2DfZPxTztw+vEh5mxZs2HGxzAoJigycJMcF/MJ9tuTOxPqSaPCWdtZjyKRqe/do1MjGMiXyAZall+6JsnU5Kodaem2DK+OM7XuKYG/jFfhTWdL+LwlSpqv7IPyZFKkmZbx0s5CK3qZynqcJEF+XXU9cBzd4SpnWGKN3If0Jv6KnHfbd2YPZ79eZ0RrnWOAtT/DMISlL1MrezJCsOysfMDGbK8SkKkMWtiNrbvZOsvxFKJwGzRKyfJABS/IaiC+yhcWuTTam40WKf5jfUd+PeTlR8hgxlXlJAXhBTVgMDBULmaaHV1AQDXxCD1LRe2tncmcZIO+1UZXU0GSKtXvdWjR8Vjcgk/QjobAqO9ZawBAjhHOqZs6BmbyZfu+YCGAbhqjclBFZx/L5Jm6VXAgKRwEIvKKQRTXDCE2WgwkHdNDlcjvcTBar9oQTDCZkfhWQsMVFubWJsJtZjpv657/pfbTLuehehKA2hf/4Nj4k6mOtBtvw0c2pBwhv4XsoelRvtDr2acP1N7DKGDGjgUpnNdFdR3tcey5kfnsl92G56B2/1Z04RmkzBTym9ctbBm4dbVzzpwu/Dw9xlAMbABxV6ilPwKueeUqk3nBmZUcJlg9mAbCmiPH0Nd3byrRWrQr02mhEGr1xKoje9HyXAQpHhN6eoeyEyuV6VEpGKAaDTJywI0Ufz6IFfk4PlhwEsBFYfzn3UwVWltUpHBigxGZbhEz7JtpdkUZzTqnPIf4HaFnC/dEuFpQzO0a2RP2jKCixoekAuceN71XOFV2VEl5b6iHV/vB9qeLvtjjyPk26tc6mtcMZ+PUxmY43Rv66BBD0Qbc9rfaQxjGSwFcwOBSxCSYN8BgPP+Ex X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e66a8d84-6a46-43c7-904c-08dbb313db80 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2023 22:10:07.3149 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: F6zgntwo0w6LJ86NUEJyaRQOnt4KlBm9G6tW39cGqBCbmb0pIhlf5Z7gSzeWQjBfwUE7atMgT+eOTiahrS8bfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8125 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add doorbell test support. Signed-off-by: Frank Li --- tools/pci/pcitest.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c index 441b542346354..215d0aa8a09fe 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -36,6 +36,7 @@ struct pci_test { bool copy; unsigned long size; bool use_dma; + bool doorbell; }; static int run_test(struct pci_test *test) @@ -149,6 +150,15 @@ static int run_test(struct pci_test *test) fprintf(stdout, "%s\n", result[ret]); } + if (test->doorbell) { + ret = ioctl(fd, PCITEST_DOORBELL, 0); + fprintf(stdout, "Push doorbell\t\t"); + if (ret < 0) + fprintf(stdout, "TEST FAILED\n"); + else + fprintf(stdout, "%s\n", result[ret]); + } + fflush(stdout); close(fd); return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ @@ -174,7 +184,7 @@ int main(int argc, char **argv) /* set default endpoint device */ test->device = "/dev/pci-endpoint-test.0"; - while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF) + while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF) switch (c) { case 'D': test->device = optarg; @@ -224,6 +234,9 @@ int main(int argc, char **argv) case 'd': test->use_dma = true; continue; + case 'B': + test->doorbell = true; + continue; case 'h': default: usage: @@ -243,6 +256,7 @@ int main(int argc, char **argv) "\t-w Write buffer test\n" "\t-c Copy buffer test\n" "\t-s Size of buffer {default: 100KB}\n" + "\t-B Doorbell test\n" "\t-h Print this help message\n", argv[0]); return -EINVAL;