Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3353667rdg; Tue, 17 Oct 2023 11:56:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSzlsND+k9s+xyCJPvLXvAK3Eze16e3oUpKywxIA98oVDDGKR4FDD1zaSDTAFeBifJABXS X-Received: by 2002:a05:6a00:180e:b0:6be:4df:2c9c with SMTP id y14-20020a056a00180e00b006be04df2c9cmr3468543pfa.28.1697568992602; Tue, 17 Oct 2023 11:56:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697568992; cv=pass; d=google.com; s=arc-20160816; b=bIKRr30O1f3tDgNA+WBdKAo/EzaV4ZNZ/ju68555eLSe4TrN3FbWZONkxDgvM34EDX Q56yS90zVRfoIYxpWrDB14GzkVpK9iVLrplDFceobhRYMZP73f+OUKP+hsEecV2TF6on jK0lN7STxwOEdX5Y8DwwOA4IbZn8sG0d62AQyDsXkn9CqipdTbE4QG0JqozCQhaHz71l SQnwtYybyhNzw/+dufDZyK4W7pYhqT/2nzlku0XZB638VK96dkMzMEceQiLxpMQ7WApw Vtfs+7WrBBCayCojv9flzwNKuKzaPjiBVP3h+gr9eYBGpA187Ms/fs2PzhtZQ7YSVcpE 5TPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to :content-transfer-encoding:content-disposition:references:message-id :subject:cc:to:from:date:dkim-signature; bh=QL6kFCzUjal1/ynwQzNM+b5aR+B6UvCRBtDpoTjVbLs=; fh=MmewaMNhjy0wyUtNJeH8nBqjIWc1L4AP7VNUo7VNk7M=; b=dSYk0+oJ62DyBzFCXwwNYtwBxdKsL0hj2HW+kyUwRZIiY6ZdET8YC+fmSZeGB+SrsD K4qMEYF4A9HmReVbbK7VoseLkMFmeghOAqxLdPcr4mjQBI8TDDELeB1kNtQnJ7z6PKzR +oUXrPoUNiv4N/ca88TW3YPlbZAimCyq0Ub7fGCzAK7XZg1QAWx9jAVYvrjDFSnpmQFa bUuvdtqpZLnZbosmp9Gad6pGUANY4eGuJ84vZzifIQFZvLEZ3VyFRPK+dkXN8NbtF7xX cRxR+fVTGt+VaUzGgHQscUtCA1qV9I96Isf4c7hTpJZgB+4rgw8HRsKdX3ZJYqMgsnJq TRQw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=svw63NjD; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j3-20020a056a00130300b0068a54e524d9si2255651pfu.150.2023.10.17.11.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 11:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=svw63NjD; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 220B38047840; Tue, 17 Oct 2023 11:56:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343887AbjJQS4S (ORCPT + 99 others); Tue, 17 Oct 2023 14:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232228AbjJQS4Q (ORCPT ); Tue, 17 Oct 2023 14:56:16 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2049.outbound.protection.outlook.com [40.107.7.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8C70C6; Tue, 17 Oct 2023 11:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ocKI9TJvIyUbJQzIlbWFZUmRRorogw8SNkaZo5DZywGN7OuTngXe5zzRYWvufRdLLiVvdkQdIWHtfK/E2mT2GrAyYWoesRnb2xzPRMKOqCRi7ZQEkqExAYl2/ErsRW29TZugzHV61lSQTXIj6jgCETF9p4iFjJd8hikY9YMGEgNRKX8EH8RSgbMeeNTEk4VMqQFuKhgulZPxyaT3FyABLUciEb4QD/I5WebZ3/yD4pgqN3xZhaRySaQiDqi+HuQJ5dx9JMA8fgb96XziLrDFDKTP+ub4YJNlaPNnOALs8qdyEFNNjLIwaNZMct0GJnpLLQrIzcUZVvpfXVeZT1OV6g== 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=QL6kFCzUjal1/ynwQzNM+b5aR+B6UvCRBtDpoTjVbLs=; b=LizPayy/W+kUOmVP3GfEL1QjmLBXRUwiGPzWkI9J60W5VRTqn79UnTRu0Y6gJfHkYZxXK8DtccIwSqkgDm9z37XGPw5oVmB9GmkoViL9Sor1+lACorl0LtKFuZDDMmfytYDYLVJ/OfeWjtLzVgGWXfaFhdYQFf/xzapGsMglRBbk3acBdZhb0Yk5PzcioG31pg3CqUSCDkV58KkTri7x/YRXIcQNUPTdmwLAjykbrkpRtMmDZ2nJISlWJpSRfGImHKfoluRwhETV9BwdhOmC2oUbISzovJbEeuv7wBiOspXS3TqNqmHnWBsNb/KawNQ8+vlH4vrXDoQlvxsBxHKziw== 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=QL6kFCzUjal1/ynwQzNM+b5aR+B6UvCRBtDpoTjVbLs=; b=svw63NjDosg8KZ0ftgMQg6aDJv1/WTIH17aRZMHdMB/iC8Ew2df0c9cv2a1IPa+jToBc7oZLQnGVH/yUEnjKw/Nt4mWZeI2SObMNHN7TtPMqL3P0Dsx6RUD2eudUfmJxIqxu/2EulEXv9lP7YwwscfqVVHQqKflnRvcw5WcTaxA= 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 DB9PR04MB9865.eurprd04.prod.outlook.com (2603:10a6:10:4f0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Tue, 17 Oct 2023 18:56:09 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::1774:e25f:f99:aca2]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::1774:e25f:f99:aca2%4]) with mapi id 15.20.6907.021; Tue, 17 Oct 2023 18:56:08 +0000 Date: Tue, 17 Oct 2023 14:55:57 -0400 From: Frank Li To: Manivannan Sadhasivam Cc: 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: Re: [PATCH v2 1/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-ID: References: <20230911220920.1817033-1-Frank.Li@nxp.com> <20230911220920.1817033-2-Frank.Li@nxp.com> <20231017183722.GB137137@thinkpad> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231017183722.GB137137@thinkpad> X-ClientProxiedBy: SJ0PR05CA0205.namprd05.prod.outlook.com (2603:10b6:a03:330::30) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|DB9PR04MB9865:EE_ X-MS-Office365-Filtering-Correlation-Id: 81b4e6fa-aacb-4637-d813-08dbcf42b8fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SzVdAfuvUeml4Y+GhE29F64KoAVIAbsLCkWCDpriRLZ/Ilsxmct+B+g6whKiH4QaxZXcQ18ofxN3ogp8yLCD1GqtZZ8nJAe0VQX1P7o0nSw7iPLSMOLZ6q51Ki3ooVsRXGMLymLNRuWvqj9L2Z1F0ZYaRcm/3FEu0ofFZLqxjs/GGC2WaNP+vu2vmBsvJIbtzw4baNJyS/RZ5co7Mg5vQ6aBLohhRPcQlWob1W9QfK/S2b1gYRMGdYhcafdzKDS+kbl4M+jM/h+Y9n9A2LZbfz8owdrcQU4Tv94uXKPgDgb8QTFqr34n4ptDKQG6ElW00sUGb+On1Bu+/Q7jpvta01d4feW2scjsyiYxM+n68OwTCc9BqJryNXZUWK2JttjBEvtrmiCpKEQAVEEvpeRwO02kA1SLCJk0sqfno/UACvBaS6cD5DuxjQ4QlBi1Co+dQw/hcxUzsMQgdaXOCHeWiEpZtfpcFjK/GHWdGxW6VHt6n+SHkdVaR5FgpJBzNDwXTVlwVgPnNyDmMKedjb7xi7qORTmn4pMWiimx25ZugdbdTfP56O4o56MOqGAnTq4AlIJ0AM8APafZnLZE3VlwpFKhbw5smV5diGjVJ0picdE= 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)(7916004)(366004)(346002)(39860400002)(136003)(396003)(376002)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(6666004)(38350700005)(5660300002)(86362001)(41300700001)(7416002)(2906002)(966005)(83380400001)(4326008)(66946007)(316002)(66556008)(66476007)(6916009)(38100700002)(6512007)(6486002)(8676002)(52116002)(9686003)(8936002)(6506007)(478600001)(33716001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NlVWczdrZ2lMZUgvakphczhqZ3QrUDlKL3VFYmlOcHRwcWZuck8xYkJ4dkxx?= =?utf-8?B?eWNSS0ZGdlFiTHRpcGx0dnBWNkd5YmE1U05SSDdxZHVhWjMwRThIalVaaWlv?= =?utf-8?B?MzRuU254aEdiQytkV1NvOTR3V1VDb1ZIRGYzaDJERVEzUkVwL29KOFVnV2Rx?= =?utf-8?B?ZHZlRHVmcDJDY2s3Z2x5RVZYQklMUXdXNXR2SG9qMGswZUNtM1NTUGljMzJq?= =?utf-8?B?dWdRdWV1Ykp0THBpVHpXRlY2bFJLZThFREhqemtneUt0elVjTEpBZXFOTHN1?= =?utf-8?B?dnZjY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L3krMHJoM01uWS9MUnJieHkxdXU0?= =?utf-8?Q?QHWA=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81b4e6fa-aacb-4637-d813-08dbcf42b8fa X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 18:56:08.4547 (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: xCLj5OnYBa+BvXi4CxoEFE41HL2xI53s9IdX0vLYAwCDIlBX6RUgVJiVxeCrltwxdwJaAHMfcMNIvU2QYQrw/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9865 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 17 Oct 2023 11:56:29 -0700 (PDT) On Wed, Oct 18, 2023 at 12:07:22AM +0530, Manivannan Sadhasivam wrote: > On Mon, Sep 11, 2023 at 06:09:16PM -0400, Frank Li wrote: > > 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 > > "Doorbell feature is implemented by mapping the EP's MSI interrupt controller > message address to a dedicated BAR in the EPC core. It is the responsibility > of the EPF driver to pass the actual message data to be written by the host to > the doorbell BAR region through its own logic." > > > 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. > > "Allocate platform specific doorbell IRQs to be used by the host to trigger > doorbells on EP." > > > + * > > + * @epc: the EPC device that need doorbell address and data from RC. > > EPC device for which the doorbell needs to be allocated > > > + * @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 > > s/num_msgs/num_db > > > + * > > + * 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; > > You mentioned 0 is a success. So if there is no callback, you want to return > success? > > > + > > + mutex_lock(&epc->lock); > > + ret = epc->ops->alloc_doorbell(epc, func_no, vfunc_no, num_msgs); > > Why can't you just call the generic function here and in other places instead of > implementing callbacks? I do not see a necessity for EPC specific callbacks. If > there is one, please specify. 1. Refer v1 your comments. https://lore.kernel.org/imx/20230906145227.GC5930@thinkpad/ 2. Maybe some ep controller have built-in doorbell support. Write to some address to trigger doorbell irq. Frank > > > + 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. > > Same as above. > > > + * @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); > > Same as suggested above. > > > + 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); > > Same as suggested above. > > > + > > + 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); > > + > > No need of this newline > > > + if (!epf) > > + return; > > + > > + if (epf->msg && desc->msi_index < epf->num_msgs) > > + epf->msg[desc->msi_index] = *msg; > > +} > > + > > + > > Remove extra newline > > > +/** > > + * 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 > > + * > > Same comment as for pci_epc_alloc_doorbell() > > > + * 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++) { > > You should iterate over msi_desc as below: > > msi_lock_descs(dev); > msi_for_each_desc(desc, dev, MSI_DESC_ALL) { > ... > } > msi_unlock_descs(dev); > > > + virq = msi_get_virq(dev, i); > > + if (i == 0) > > + epf->virq_base = virq; > > + > > + ret = request_irq(virq, pci_epf_generic_doorbell_handler, 0, > > request_irq(desc->irq, ...) > > > + 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; > > return ret; > > > +} > > +EXPORT_SYMBOL_GPL(pci_epc_generic_alloc_doorbell); > > + > > [...] > > > 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); > > kdoc missing. > > > }; > > > > /** > > @@ -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; > > num_db > > You also need to add kdoc for each new member. > > - Mani > > -- > மணிவண்ணன் சதாசிவம்