From nobody Sun May 24 19:33:54 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011002.outbound.protection.outlook.com [52.101.52.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 647FE3911C6; Fri, 22 May 2026 05:24:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427497; cv=fail; b=UZ/aI/BGaxuoOvdIkeyzRhuXMVjOh8NM7j1q2nI6BlVWAafWocsXYq/F/LBBNyvxZ8sTSPL5AgOqxu/4hrKZ9QTqcxnPbq9zzHTTR+uejvWr4oGDaGIrNrlOKrdBBpDzG+/PcoIkPHItqAHp+22YqiLMw25Mh/6bVM1jumyqPMM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427497; c=relaxed/simple; bh=rV+SL64WSibZCJuuv3r8Jss6QrFDZsPhRNVgqHO+Z8s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hzOsuTui/CYXN7hXYjXgsaEzTn0eUltzrUujrchL+KNv/0ECiYhZuL6ovkGv+ip2N6Y58JQXgoYi35ZEhLFHPQI/QwaYpZMF9yoIdRwmPgoIQ0OuhIrGE+r779LlmwRNHjNU68TW/nNv1G+fQTn/bLcbLcPfglPcJAj7o2XSSi8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=JSRtHAbC; arc=fail smtp.client-ip=52.101.52.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="JSRtHAbC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fThYTNR8XISNthXebaREtYtIBwQLPtC4jDoKcAl4Y651yg0Hhzani5ZqbYHPeyjpVcuKuKNeicdwYMdgS380E3xubeaTHFzPo3au7IMhh9cN4by/jmgKty4NWsdzzoVN4hpnVaQ6fHRXuDcviVQIjCFMMCVIPWLgrB2LjjGBmPw8084hhfwpi9nIK8g2UgF9Y+csPZS2GrRaHvCVUzCPtllguOlPPVB821XOL2yyTh4wHvqziv3fp9UjCmPKQ/7RcARvivDwGQGF2W18BYOSOqn94S2Zvt+6ifL0eaRJj84SWK8zz7k1SqrCYpsGjMnGJa9cyy1sGhe8FGON6T9gaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=SXIorvbTV1fc4KMOa02FLgl7HQom8FsxP0CttsJECtg=; b=ghwN8Cwa8fz4zR7zPvf3xBHTqyXkCU2s1EWkAAP2oyAME7yMuoa/ISgaljTsrYgNlmPMG7NHL4cP+AVVmKZW6KBfs6MSB8mvf4yrCOeBaWroacFk38BWb2F5/M4K7s4tnG3xbMnUJiGrSmQtOhG6rTegIRN1SrX/4576IQ/I5tMX+tm++DTkhZDiYGEWgHwWZVaRfH0m2pYKF7IMGNRhUZ3LIBnoviRVwnsxIr2Kr3cD+YWsnRmqFZjDBMEh9BykPJDFu8PG40CUiNef3cSfZ2W8j+O2v0I/D/27l+KNgQveyNL9unc9hA1YTtBujRMO0FvyZ5WXHZcx4IVX2b4K9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.21.195) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SXIorvbTV1fc4KMOa02FLgl7HQom8FsxP0CttsJECtg=; b=JSRtHAbCsx4KLdpAawwbvqgJhXIi+jsyAZWA3sLaBujIXsSEDyP3rqRzcxpfaIwBl+a1MH+hRe39GgMB0xraf1OAADnOZ9bOk90XvGK6WL6ljA7qnloWMOBvNrPigigm7m2gLBzkc/cumMJZkntu+zAC/Cu7soBCFxECrf6EApk= Received: from SJ0PR13CA0229.namprd13.prod.outlook.com (2603:10b6:a03:2c1::24) by CH3PR10MB6858.namprd10.prod.outlook.com (2603:10b6:610:152::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.17; Fri, 22 May 2026 05:24:50 +0000 Received: from MWH0EPF000A6731.namprd04.prod.outlook.com (2603:10b6:a03:2c1:cafe::7a) by SJ0PR13CA0229.outlook.office365.com (2603:10b6:a03:2c1::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Fri, 22 May 2026 05:24:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.21.195) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.21.195 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.21.195; helo=flwvzet201.ext.ti.com; pr=C Received: from flwvzet201.ext.ti.com (198.47.21.195) by MWH0EPF000A6731.mail.protection.outlook.com (10.167.249.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Fri, 22 May 2026 05:24:48 +0000 Received: from DFLE212.ent.ti.com (10.64.6.70) by flwvzet201.ext.ti.com (10.248.192.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:24:45 -0500 Received: from DFLE204.ent.ti.com (10.64.6.62) by DFLE212.ent.ti.com (10.64.6.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:24:45 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DFLE204.ent.ti.com (10.64.6.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37 via Frontend Transport; Fri, 22 May 2026 00:24:45 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [10.24.68.129]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 64M5OZpW1350956; Fri, 22 May 2026 00:24:40 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v4 1/4] PCI/DOE: Move common definitions to the header file Date: Fri, 22 May 2026 10:54:31 +0530 Message-ID: <20260522052434.802034-2-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260522052434.802034-1-a-garg7@ti.com> References: <20260522052434.802034-1-a-garg7@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A6731:EE_|CH3PR10MB6858:EE_ X-MS-Office365-Filtering-Correlation-Id: bdedb1e2-5306-4020-a993-08deb7c27111 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|7416014|376014|18002099003|22082099003|56012099003|921020; X-Microsoft-Antispam-Message-Info: l3nJmt+iYy/VWFVhZJ6F3VTR51CZf5HsFataHcH5PyCIGZTaLHEtk59Xqs9P4EDaK1mUdR4ADRfJikhBk/peENirO7q6mTyptaJvdnalh1HXz+/zO6kOS86PRw/Yq8NCoi678JIY6mqXVe5Ka/mTHBSL5kVMcuqez4Yd2yCz/MDPwqJ6K3Lqooa6TkF1EdUmimCcYM9e2nsOuXqEcaMysKscgqk0CA/fgwjaOLg8oiEea+RuVKCFV2mD2ovINjyo/RObkrjcbsm7vK2dsGI6u8sRXHxZl52Ph1H9g5Oby6hnaxpSYJ/rIwJKcPYD8MClN8CUA/3xMeUxRx8JqzI68tnmDGGg3OJtkPSe+Q9JcSqj0E17nVdCtfSnV4eR+ytix/0MNyxLsb1Ch6jyt7nTa0bCuvmu7NjgLKbGcRIlm/BW8aT5Rst0fpXtx2NdXDnarbvZUL4AbeAZq8qfUDSDafdkI1ZBfsRUAKtQXYnLgIhDhy4vvZ0+fNG4k5FwbHSOu6lZrK3CTQgaOvQP3wd6jvJQXJT38oIutempqF9yd6hHxlFlCIugdbNTSvx7C7WIX+yXkE6SrB0gb5pNSBSdgi1D++elruxWhajOovyscYvnUUnENY1cqPO9hFti8BKHauR6eXeFYUS7n46fr+5s/0KbURaXBwZbtSiklzfBJP+D+2wbpI4h+H17ecKJqK4r9fZ7KsyP/cNxxb3QMgQeoR0Tbr/h30DJz6JFl5SEzjPk65VL+lAwGCXVX1f/M89fEE2OPlHHDNPHAAt6vUF7rg8VbTJb24yqkhKXnnEzrYc= X-Forefront-Antispam-Report: CIP:198.47.21.195;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:flwvzet201.ext.ti.com;PTR:ErrorRetry;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700016)(7416014)(376014)(18002099003)(22082099003)(56012099003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SzX6PwM41fO8KlIx+VPgTDYOASLnO2FprBSAhzUjm50oUvhO/SsaixC6DTkF3PmtbS0fDif1WkLoJ33GPzzfTCZIqN4Eu7sdks6cy4gwvGmPPwspb3ED9kZPq+PTZRI5AVsySRyKR3Ex7E7JQUPW6TLvq0SXExffjJMzJ26eQLjuvEOrCnE38rhO+oByLUv/FPevrG5ZEnCu+q0m17UfqIXQyM0ng2Kr/CXe3ZI9xRYlkQb/m44pzQhEx2KYe6hbVjdrjRhCTnQ+t77FMGaooZxlMn1O3iEen1Y7qSNdGZleGlTWAMRWkf2aU3oPsQbw2YE0JAVdVOFeLjHthfjy6v1XT5J7iHS4W5qd+udHjp2v1cPRFbcWpTz+qBzSmA9uvdI+C/rOgXXxixuS74R95NUiMycBCzq/ssg6uHSrEjYsqdujIsx9EwQ1h57Eyk5A X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2026 05:24:48.0316 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bdedb1e2-5306-4020-a993-08deb7c27111 X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.21.195];Helo=[flwvzet201.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A6731.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB6858 Content-Type: text/plain; charset="utf-8" Move common macros and structures from drivers/pci/doe.c to drivers/pci/pci.h to allow reuse across root complex and endpoint DOE implementations. PCI_DOE_MAX_LENGTH macro can be used outside the PCI core as well, hence move the macro to include/linux/pci-doe.h. These changes prepare the groundwork for the DOE endpoint implementation that will reuse these common definitions. Co-developed-by: Siddharth Vadapalli Signed-off-by: Siddharth Vadapalli Signed-off-by: Aksh Garg --- Changes from v3 to v4: - None. Changes from v2 to v3: - Rebased on 7.1-rc1. Changes since v1: - Moved the common macros that need not be visible outside the PCI core to drivers/pci/pci.h instead to include/linux/pci-doe.h as suggested by Lukas Wunner - Removed the redundant empty inlines guarded with CONFIG_PCI_DOE in include/linux/pci-doe.h. v3: https://lore.kernel.org/all/20260427051725.223704-2-a-garg7@ti.com/ v2: https://lore.kernel.org/all/20260401073022.215805-2-a-garg7@ti.com/ v1: https://lore.kernel.org/all/20260213123603.420941-3-a-garg7@ti.com/ drivers/pci/doe.c | 11 ----------- drivers/pci/pci.h | 9 +++++++++ include/linux/pci-doe.h | 3 +++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c index 7b41da4ec11a..e8d9e95644b3 100644 --- a/drivers/pci/doe.c +++ b/drivers/pci/doe.c @@ -28,12 +28,6 @@ #define PCI_DOE_TIMEOUT HZ #define PCI_DOE_POLL_INTERVAL (PCI_DOE_TIMEOUT / 128) =20 -#define PCI_DOE_FLAG_CANCEL 0 -#define PCI_DOE_FLAG_DEAD 1 - -/* Max data object length is 2^18 dwords */ -#define PCI_DOE_MAX_LENGTH (1 << 18) - /** * struct pci_doe_mb - State for a single DOE mailbox * @@ -63,11 +57,6 @@ struct pci_doe_mb { #endif }; =20 -struct pci_doe_feature { - u16 vid; - u8 type; -}; - /** * struct pci_doe_task - represents a single query/response * diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 4a14f88e543a..5844deee2b5f 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -683,6 +683,15 @@ struct pci_sriov { bool drivers_autoprobe; /* Auto probing of VFs by driver */ }; =20 +/* DOE Mailbox state flags */ +#define PCI_DOE_FLAG_CANCEL 0 +#define PCI_DOE_FLAG_DEAD 1 + +struct pci_doe_feature { + u16 vid; + u8 type; +}; + #ifdef CONFIG_PCI_DOE void pci_doe_init(struct pci_dev *pdev); void pci_doe_destroy(struct pci_dev *pdev); diff --git a/include/linux/pci-doe.h b/include/linux/pci-doe.h index bd4346a7c4e7..abb9b7ae8029 100644 --- a/include/linux/pci-doe.h +++ b/include/linux/pci-doe.h @@ -19,6 +19,9 @@ struct pci_doe_mb; #define PCI_DOE_FEATURE_CMA 1 #define PCI_DOE_FEATURE_SSESSION 2 =20 +/* Max data object length is 2^18 dwords */ +#define PCI_DOE_MAX_LENGTH (1 << 18) + struct pci_doe_mb *pci_find_doe_mailbox(struct pci_dev *pdev, u16 vendor, u8 type); =20 --=20 2.34.1 From nobody Sun May 24 19:33:54 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010047.outbound.protection.outlook.com [52.101.61.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81880392812; Fri, 22 May 2026 05:24:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427498; cv=fail; b=utvGrfkjj0JZX1Yf3uo1pE8YmIJxS8WCVhclBpzv96Spdd2JSbQgzZvt+ux3gH+GyVAig/nc1+CSaQmU1vL8XdjyTsPfEXHriUGSOsyYGpjzT3cuCzlCv8iiRDssIOUbIyjfzIerSfaS78k2XW2K2z7VsaBtOi3DJLqHgDsbUMo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427498; c=relaxed/simple; bh=hcFLrxR5zHtLTCa6pA0Ueue2GhmLjomLTrpk9Mc4P28=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EkiiXz6mmS+rY8Upg0c29H9/kRq49TTkc2QJjDvNkxze13+kHwMpnJVbyh9hYtCD5/AnhzrKFZBHnotbOK8cgoBXNqG8ACcljM6xt866DaHylfZLy/autPgxGLUQrJH41hqDzdO+Ac7YhhRywJEA5jLf/vl2QUY/VYQKIh2sYCc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=R99aV/1D; arc=fail smtp.client-ip=52.101.61.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="R99aV/1D" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L86NJCuGloOEzNodOoczwyiT20K0CO8RSpzufrIN1PMdB5kYvjWMMxnu7/pEkBV0n9Pj/y3lGYV4ubdwYXL0bREmrx11F4LeWIXd4ReeyECLi+M8izhkcrX2rhkO7PmYEUJVETAfFoqzpTtlrxR938Lju3QpVyvs+Vajthxs6PwyPEFYRYPuxzY+LBmq+onQdXCBCXv9wFJcgJdHiqlpOIXfXhaEN3CeBQZ7OS/Kuz4LvGi6ttE+O36CeIzQ8RZpc9Y9tstBXBHaLtm27agC8bRUrUFSus1aMseDQHB8eeG9kQxmkD/e7xqycOlx0c4NFhCcVgHEKbFXZRES2NUkJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=4OfFZaDmFP+wPPHOXQOCdQhbAM0HP7zm/XBqtqag1fo=; b=ZRfAbSfo6trt0dhD+mB28ihX77ReoPTyWFWYpO/zhmL3eCL6gxKbpp2GWzVHHSOI0vlVSumCkYZzCrhSxj8Y2UYWN/AUA/IALFaU4eIL4o8uvXaAf4SL9KLB6Xcjq3l4xAuNdcSRqe7/GnWjqE9xW9Dq03PkOzFr1ia9JX+fSO+Iep8atD/bNs/3BmNE7El0YmPtoMq9kE3kzSFTGweDG5IikS32lR+IvfXwpIYBV07/vOriE43X7maztpdfsthnCMsL0EA6pFFVnO/e9yKLG+CIY7xk0nxbGt+92MnrfquWhY0lk8DYaendYS3Ql7bQ9QhK9M6bF2yoESgex+7OhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.23.195) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4OfFZaDmFP+wPPHOXQOCdQhbAM0HP7zm/XBqtqag1fo=; b=R99aV/1DjkBAIqcdJ0Q+XqNryDJ1h0F8+8HI/u0vrXo3BIV/m+oPOqgmQR6IU5Wc5CY7J97VsGuyupQO51Yv/bU4KNCOgKarHSJb4f2x7PQGynf17YPoXopZ0ca5+hP2ZrdhX4Q35NSBVUwFpu0rg9zKPUm5c6QWBPr2YcZNpUQ= Received: from DS1P223CA0012.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:453::15) by LV3PR10MB7868.namprd10.prod.outlook.com (2603:10b6:408:1b4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.17; Fri, 22 May 2026 05:24:51 +0000 Received: from DS1PEPF0001709D.namprd05.prod.outlook.com (2603:10b6:8:453:cafe::66) by DS1P223CA0012.outlook.office365.com (2603:10b6:8:453::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.17 via Frontend Transport; Fri, 22 May 2026 05:24:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.23.195) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.23.195 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.23.195; helo=lewvzet201.ext.ti.com; pr=C Received: from lewvzet201.ext.ti.com (198.47.23.195) by DS1PEPF0001709D.mail.protection.outlook.com (10.167.18.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Fri, 22 May 2026 05:24:51 +0000 Received: from DLEE210.ent.ti.com (157.170.170.112) by lewvzet201.ext.ti.com (10.4.14.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:24:50 -0500 Received: from DLEE211.ent.ti.com (157.170.170.113) by DLEE210.ent.ti.com (157.170.170.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:24:50 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DLEE211.ent.ti.com (157.170.170.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37 via Frontend Transport; Fri, 22 May 2026 00:24:50 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [10.24.68.129]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 64M5OZpX1350956; Fri, 22 May 2026 00:24:46 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v4 2/4] PCI: endpoint: Add DOE mailbox support for endpoint functions Date: Fri, 22 May 2026 10:54:32 +0530 Message-ID: <20260522052434.802034-3-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260522052434.802034-1-a-garg7@ti.com> References: <20260522052434.802034-1-a-garg7@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709D:EE_|LV3PR10MB7868:EE_ X-MS-Office365-Filtering-Correlation-Id: 89160a9b-4a7f-4647-fad4-08deb7c272dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|7416014|376014|82310400026|1800799024|18002099003|921020|56012099003|6133799003|22082099003|3023799007|5023799004; X-Microsoft-Antispam-Message-Info: ldowc4MeJEaSN2izpDdh3BTEwKldHXX/AGyro5ePP7Mk8rpCqBCHePJZU3UeI8lPKM0f+4Ul42As2GJclfqvza2ysH7IP4BOZKSOYpLApFvhtUFgVdOcle5i9g/h5RBBaV9nS3vXz4txtVxQVS2b0MXVvaTBiLlvl5gjSilOgXSzVzRyDhl+HmH4VfpaBaS367TIw2ityW7HppDELqeoBOQ/CByq6FmoeHOEeSsXJa/lUelD9jUKKVsF0G3IIDD+uIVf2afGtsTkPTPuCQOz9OL2rLrSY4rNG/TQn6gFH8YZ/bW3uA+wMYEETB2O5HKxUJRIGIxSg888AUMYMg23GShYt6smDxvNM/LyXaAoOcbmJD681ozUzZsxpgUrfzb815DSFuh2l9HEXrnJiyFtP1GIxj22H33NbItT/fwKoKOfiAEQKTUa40iZ4G/JDlJ0fixw5cngUu85hufbWeewSyAIRLTltwm/xWIofRUWILYI9kJNaka/NCmZmL2gHDmkh3NnobRqQWR68SBZE13mNuNPuajiPuQPkza0Wkea3WOkwZvBGNNtpHrnXbLQOZVdtY/iTmu98ycnVJXSNi8OPG+GzX9BrWXfsZirNP+0EMt3aXIxOIe+oFGkEv2/gOChS8vqzHFY9WrCLwwB7ck+DvaOcuea7wCZwdWq03CelZA0HjjquDPUjY59rBU6l8wWvxyvWgIhB0DgvvPwgyWp70HOUF17ecDASFr/GsgWseI= X-Forefront-Antispam-Report: CIP:198.47.23.195;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:lewvzet201.ext.ti.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(7416014)(376014)(82310400026)(1800799024)(18002099003)(921020)(56012099003)(6133799003)(22082099003)(3023799007)(5023799004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yro7tviwm2MQJp3u5HfqfZ9RazqO3YR/t6EiVyRDO+NXiwBwYwbImDBvyuT0ya7m3aS4cGjHoroZcGVkLXaxLBDxaO0+V/1rgfPz87foSc0rlOiekXUJlvuQTUFH0UGV/UNnwzLUGhmEfF2Iwqi6QLqA/kHiV5LXM3Sdp7i8RW3Kc3qOA6PkCk/4168j2aKqmiipQyLs6IaGb1oMk5z9MkNYcH7bW+jyvy0+aM9G3gPhMKdkWfwKENjOgeWkwd4OzzkPpo7AljM0LdXXNik/ZB3/bFk52u3dhnGhz6bN/9FqaCTQE3Goe4O5qkkInKUTbc/Qd5bhVyzIVwumFNhNznMjdm0t/82tJ0DMciRErpa7RAuK4Qjqc8WKMOWYNGnn7fFL3faxbT25wzNqwBdDk9LI273rgfvHG1/D6xaiMsupH/7BJFrYk+/uM/IYrdfD X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2026 05:24:51.0823 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89160a9b-4a7f-4647-fad4-08deb7c272dc X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.23.195];Helo=[lewvzet201.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001709D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR10MB7868 Content-Type: text/plain; charset="utf-8" DOE (Data Object Exchange) is a standard PCIe extended capability feature introduced in the Data Object Exchange (DOE) ECN for PCIe r5.0. It provides a communication mechanism primarily used for implementing PCIe security features such as device authentication, and secure link establishment. Think of DOE as a sophisticated mailbox system built into PCIe. The root complex can send structured requests to the endpoint device through DOE mailboxes, and the endpoint device responds with appropriate data. Add the DOE support for PCIe endpoint devices, enabling endpoint functions to process the DOE requests from the host. The implementation provides framework APIs for EPC core driver and controller drivers to register mailboxes, and request processing with workqueues ensuring sequential handling per mailbox, and parallel handling across mailboxes. The Discovery protocol is handled internally by the DOE core. This implementation complements the existing DOE implementation for root complex in drivers/pci/doe.c. Co-developed-by: Siddharth Vadapalli Signed-off-by: Siddharth Vadapalli Signed-off-by: Aksh Garg --- Changes from v3 to v4: - Used 'Returns' instead of 'RETURNS' in the function docstrings to comply with kernel-doc format, as suggested by Manivannan Sadhasivam. - In pci_ep_doe_process_request(), changed the type of request buffer from "const void *" to "void *", as the ownership is transferred to DOE-EP framework, which is responsible to free the buffer. - Added "struct pci_epc *epc" to typedef "pci_ep_doe_complete_t", to be used by the EPC driver. Changes from v2 to v3: - Rebased on 7.1-rc1. Changes since v1: - Moved the DOE-EP core file to drivers/pci/endpoint/pci-ep-doe.c, and corresponding Kconfig and Makefile to match the existing naming scheme, as suggested by Niklas Cassel. - Renamed the config from PCI_DOE_EP to PCI_ENDPOINT_DOE - Moved the function declarations that need not be visible outside the PCI core to drivers/pci/pci.h instead to include/linux/pci-doe.h as suggested by Lukas Wunner - Converted from synchronous to asynchronous request processing: * Removed wait_for_completion() from pci_ep_doe_process_request() * Function returns immediately after queuing to workqueue, hence removed private data for completion in the task structure * Added completion callback as an additional argument to pci_ep_doe_process_request(), which takes the response and status parameters as arguments (along with other required arguments), hence removed task_status in the task structure * Created a typedef pci_ep_doe_complete_t for completion callback * Removed the pci_ep_doe_task_complete() function, as it would not be required anymore with these changes * Moved from INIT_WORK_ONSTACK() to INIT_WORK(), to initialize the work on heap instead of stack * signal_task_complete() now invokes the completion callback, once the protocol handler completes its task - Changed from dynamic xarray-based protocol registration to static array: * Removed the register/unregister protocol APIs * Replaced the dynamic xarray with static array of struct pci_doe_protocol * Added discovery protocol to static array, instead of treating it specia= lly, hence removed the special handling for Discovery protocol in doe_ep_task_work() * Updated pci_ep_doe_handle_discovery() and pci_ep_doe_find_protocol() accordingly. - Memory Management: * DOE core frees request buffer in signal_task_complete() or during error handling * pci_ep_doe_process_request() defines response_pl and response_pl_sz as NULL and 0 respectively, whose pointer is passed to the protocol handler, hence removed the arguments void **response, size_t *response_= sz to this function. - Task structure refactoring: * Response buffer: void **response_pl to void *response_pl * Response size: size_t *response_pl_sz to size_t response_pl_sz * Changed the completion callback to type pci_ep_doe_complete_t * Removed void *private and int task_status - Updated documentation comments of the functions according to the changes v3: https://lore.kernel.org/all/20260427051725.223704-3-a-garg7@ti.com/ v2: https://lore.kernel.org/all/20260401073022.215805-3-a-garg7@ti.com/ v1: https://lore.kernel.org/all/20260213123603.420941-4-a-garg7@ti.com/ drivers/pci/endpoint/Kconfig | 14 + drivers/pci/endpoint/Makefile | 1 + drivers/pci/endpoint/pci-ep-doe.c | 553 ++++++++++++++++++++++++++++++ drivers/pci/pci.h | 39 +++ include/linux/pci-doe.h | 5 + include/linux/pci-epc.h | 3 + 6 files changed, 615 insertions(+) create mode 100644 drivers/pci/endpoint/pci-ep-doe.c diff --git a/drivers/pci/endpoint/Kconfig b/drivers/pci/endpoint/Kconfig index 8dad291be8b8..15ae16aaa58f 100644 --- a/drivers/pci/endpoint/Kconfig +++ b/drivers/pci/endpoint/Kconfig @@ -36,6 +36,20 @@ config PCI_ENDPOINT_MSI_DOORBELL doorbell. The RC can trigger doorbell in EP by writing data to a dedicated BAR, which the EP maps to the controller's message address. =20 +config PCI_ENDPOINT_DOE + bool "PCI Endpoint Data Object Exchange (DOE) support" + depends on PCI_ENDPOINT + help + This enables support for Data Object Exchange (DOE) protocol + on PCI Endpoint controllers. It provides a communication + mechanism through mailboxes, primarily used for PCIe security + features. + + Say Y here if you want be able to communicate using PCIe DOE + mailboxes. + + If unsure, say N. + source "drivers/pci/endpoint/functions/Kconfig" =20 endmenu diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index b4869d52053a..1fa176b6792b 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -7,3 +7,4 @@ obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) +=3D pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) +=3D pci-epc-core.o pci-epf-core.o\ pci-epc-mem.o functions/ obj-$(CONFIG_PCI_ENDPOINT_MSI_DOORBELL) +=3D pci-ep-msi.o +obj-$(CONFIG_PCI_ENDPOINT_DOE) +=3D pci-ep-doe.o diff --git a/drivers/pci/endpoint/pci-ep-doe.c b/drivers/pci/endpoint/pci-e= p-doe.c new file mode 100644 index 000000000000..63a5c1b8753a --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-doe.c @@ -0,0 +1,553 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Data Object Exchange for PCIe Endpoint + * PCIe r7.0, sec 6.30 DOE + * + * Copyright (C) 2026 Texas Instruments Incorporated - https://www.ti.com + * Aksh Garg + * Siddharth Vadapalli + */ + +#define dev_fmt(fmt) "DOE EP: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../pci.h" + +/* Forward declaration of discovery protocol handler */ +static int pci_ep_doe_handle_discovery(const void *request, size_t request= _sz, + void **response, size_t *response_sz); + +/** + * struct pci_doe_protocol - DOE protocol handler entry + * @vid: Vendor ID + * @type: Protocol type + * @handler: Handler function pointer + */ +struct pci_doe_protocol { + u16 vid; + u8 type; + pci_doe_protocol_handler_t handler; +}; + +/** + * struct pci_ep_doe_mb - State for a single DOE mailbox on EP + * + * This state is used to manage a single DOE mailbox capability on the + * endpoint side. + * + * @epc: PCI endpoint controller this mailbox belongs to + * @func_no: Physical function number of the function this mailbox belongs= to + * @cap_offset: Capability offset + * @work_queue: Queue of work items + * @flags: Bit array of PCI_DOE_FLAG_* flags + */ +struct pci_ep_doe_mb { + struct pci_epc *epc; + u8 func_no; + u16 cap_offset; + struct workqueue_struct *work_queue; + unsigned long flags; +}; + +/** + * struct pci_ep_doe_task - Represents a single DOE request/response task + * + * @feat: DOE feature (vendor ID and type) + * @request_pl: Request payload + * @request_pl_sz: Size of request payload in bytes + * @response_pl: Response buffer + * @response_pl_sz: Size of response buffer in bytes + * @complete: Completion callback + * @work: Work structure for workqueue + * @doe_mb: DOE mailbox handling this task + */ +struct pci_ep_doe_task { + struct pci_doe_feature feat; + const void *request_pl; + size_t request_pl_sz; + void *response_pl; + size_t response_pl_sz; + pci_ep_doe_complete_t complete; + + /* Initialized by pci_ep_doe_submit_task() */ + struct work_struct work; + struct pci_ep_doe_mb *doe_mb; +}; + +/* + * Global registry of protocol handlers. + * When a new DOE protocol, library is added, add an entry to this array. + */ +static const struct pci_doe_protocol pci_doe_protocols[] =3D { + { + .vid =3D PCI_VENDOR_ID_PCI_SIG, + .type =3D PCI_DOE_FEATURE_DISCOVERY, + .handler =3D pci_ep_doe_handle_discovery, + }, +}; + +/* + * Combines function number and capability offset into a unique lookup key + * for storing/retrieving DOE mailboxes in an xarray. + */ +#define PCI_DOE_MB_KEY(func, offset) \ + (((unsigned long)(func) << 16) | (offset)) +#define PCI_DOE_PROTOCOL_COUNT ARRAY_SIZE(pci_doe_protocols) + +/** + * pci_ep_doe_init() - Initialize the DOE framework for a controller in EP= mode + * @epc: PCI endpoint controller + * + * Initialize the DOE framework data structures. This only initializes + * the xarray that will hold the mailboxes. + * + * Returns: 0 on success, -errno on failure + */ +int pci_ep_doe_init(struct pci_epc *epc) +{ + if (!epc) + return -EINVAL; + + xa_init(&epc->doe_mbs); + return 0; +} +EXPORT_SYMBOL_GPL(pci_ep_doe_init); + +/** + * pci_ep_doe_add_mailbox() - Add a DOE mailbox for a physical function + * @epc: PCI endpoint controller + * @func_no: Physical function number + * @cap_offset: Offset of the DOE capability + * + * Create and register a DOE mailbox for the specified physical function + * and capability offset. + * + * EPC core driver calls this for each DOE capability discovered in the co= nfig + * space of each endpoint function if DOE support is available for the EPC. + * + * Returns: 0 on success, -errno on failure + */ +int pci_ep_doe_add_mailbox(struct pci_epc *epc, u8 func_no, u16 cap_offset) +{ + struct pci_ep_doe_mb *doe_mb; + unsigned long key; + int ret; + + if (!epc) + return -EINVAL; + + doe_mb =3D kzalloc_obj(*doe_mb, GFP_KERNEL); + if (!doe_mb) + return -ENOMEM; + + doe_mb->epc =3D epc; + doe_mb->func_no =3D func_no; + doe_mb->cap_offset =3D cap_offset; + + doe_mb->work_queue =3D alloc_ordered_workqueue("pci_ep_doe[%s:pf%d:offset= %x]", 0, + dev_name(&epc->dev), + func_no, cap_offset); + if (!doe_mb->work_queue) { + dev_err(epc->dev.parent, + "[pf%d:offset%x] failed to allocate work queue\n", + func_no, cap_offset); + ret =3D -ENOMEM; + goto err_free; + } + + /* Add to xarray with composite key */ + key =3D PCI_DOE_MB_KEY(func_no, cap_offset); + ret =3D xa_insert(&epc->doe_mbs, key, doe_mb, GFP_KERNEL); + if (ret) { + dev_err(epc->dev.parent, + "[pf%d:offset%x] failed to insert mailbox: %d\n", + func_no, cap_offset, ret); + goto err_destroy; + } + + dev_dbg(epc->dev.parent, + "DOE mailbox added: pf%d offset 0x%x\n", + func_no, cap_offset); + + return 0; + +err_destroy: + destroy_workqueue(doe_mb->work_queue); +err_free: + kfree(doe_mb); + return ret; +} +EXPORT_SYMBOL_GPL(pci_ep_doe_add_mailbox); + +/** + * pci_ep_doe_cancel_tasks() - Cancel all pending tasks + * @doe_mb: DOE mailbox + * + * Cancel all pending tasks in the mailbox. Mark the mailbox as dead + * so no new tasks can be submitted. + */ +static void pci_ep_doe_cancel_tasks(struct pci_ep_doe_mb *doe_mb) +{ + if (!doe_mb) + return; + + /* Mark the mailbox as dead */ + set_bit(PCI_DOE_FLAG_DEAD, &doe_mb->flags); + + /* Stop all pending work items from starting */ + set_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags); +} + +/** + * pci_ep_doe_get_mailbox() - Get DOE mailbox by function and offset + * @epc: PCI endpoint controller + * @func_no: Physical function number + * @cap_offset: Offset of the DOE capability + * + * Internal helper to look up a DOE mailbox by its function number and + * capability offset. + * + * Returns: Pointer to the mailbox or NULL if not found + */ +static struct pci_ep_doe_mb *pci_ep_doe_get_mailbox(struct pci_epc *epc, + u8 func_no, u16 cap_offset) +{ + unsigned long key; + + if (!epc) + return NULL; + + key =3D PCI_DOE_MB_KEY(func_no, cap_offset); + return xa_load(&epc->doe_mbs, key); +} + +/** + * pci_ep_doe_find_protocol() - Find protocol handler in static array + * @vendor: Vendor ID + * @type: Protocol type + * + * Look up a protocol handler in the static protocol array by matching ven= dor ID + * and protocol type. + * + * Returns: Handler function pointer or NULL if not found + */ +static pci_doe_protocol_handler_t pci_ep_doe_find_protocol(u16 vendor, u8 = type) +{ + int i; + + /* Search static protocol array */ + for (i =3D 0; i < PCI_DOE_PROTOCOL_COUNT; i++) { + if (pci_doe_protocols[i].vid =3D=3D vendor && + pci_doe_protocols[i].type =3D=3D type) + return pci_doe_protocols[i].handler; + } + + return NULL; +} + +/** + * pci_ep_doe_handle_discovery() - Handle Discovery protocol request + * @request: Request payload + * @request_sz: Request size + * @response: Output pointer for response buffer + * @response_sz: Output pointer for response size + * + * Handle the DOE Discovery protocol. The request contains an index specif= ying + * which protocol to query. This function creates a response containing the + * vendor ID and protocol type for the requested index, along with the next + * index value for further discovery: + * + * - next_index =3D 0: Signals this is the last protocol supported + * - next_index =3D n (non-zero): Signals more protocols available, + * query index n next + * + * Returns: 0 on success, -errno on failure + */ +static int pci_ep_doe_handle_discovery(const void *request, size_t request= _sz, + void **response, size_t *response_sz) +{ + struct pci_doe_protocol protocol; + u8 requested_index, next_index; + u32 *response_pl; + u32 request_pl; + u16 vendor; + u8 type; + + if (request_sz !=3D sizeof(u32)) + return -EINVAL; + + request_pl =3D *(u32 *)request; + requested_index =3D FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_REQ_3_INDEX, reque= st_pl); + + if (requested_index >=3D PCI_DOE_PROTOCOL_COUNT) + return -EINVAL; + + /* Get protocol from array at requested_index */ + protocol =3D pci_doe_protocols[requested_index]; + vendor =3D protocol.vid; + type =3D protocol.type; + + /* Calculate next index */ + next_index =3D (requested_index + 1 < PCI_DOE_PROTOCOL_COUNT) ? requested= _index + 1 : 0; + + response_pl =3D kzalloc_obj(*response_pl, GFP_KERNEL); + if (!response_pl) + return -ENOMEM; + + /* Build response */ + *response_pl =3D FIELD_PREP(PCI_DOE_DATA_OBJECT_DISC_RSP_3_VID, vendor) | + FIELD_PREP(PCI_DOE_DATA_OBJECT_DISC_RSP_3_TYPE, type) | + FIELD_PREP(PCI_DOE_DATA_OBJECT_DISC_RSP_3_NEXT_INDEX, next_index); + + *response =3D response_pl; + *response_sz =3D sizeof(*response_pl); + + return 0; +} + +static void signal_task_complete(struct pci_ep_doe_task *task, int status) +{ + kfree(task->request_pl); + task->complete(task->doe_mb->epc, task->doe_mb->func_no, + task->doe_mb->cap_offset, status, + task->feat.vid, task->feat.type, + task->response_pl, task->response_pl_sz); + kfree(task); +} + +/** + * doe_ep_task_work() - Work function for processing DOE EP tasks + * @work: Work structure + * + * Process a DOE request by calling the appropriate protocol handler. + */ +static void doe_ep_task_work(struct work_struct *work) +{ + struct pci_ep_doe_task *task =3D container_of(work, struct pci_ep_doe_tas= k, + work); + struct pci_ep_doe_mb *doe_mb =3D task->doe_mb; + pci_doe_protocol_handler_t handler; + int rc; + + if (test_bit(PCI_DOE_FLAG_DEAD, &doe_mb->flags)) { + signal_task_complete(task, -EIO); + return; + } + + /* Check if request was aborted */ + if (test_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags)) { + signal_task_complete(task, -ECANCELED); + return; + } + + /* Find protocol handler in the array */ + handler =3D pci_ep_doe_find_protocol(task->feat.vid, task->feat.type); + if (!handler) { + dev_warn(doe_mb->epc->dev.parent, + "[%d:%x] Unsupported protocol VID=3D%04x TYPE=3D%02x\n", + doe_mb->func_no, doe_mb->cap_offset, + task->feat.vid, task->feat.type); + signal_task_complete(task, -EOPNOTSUPP); + return; + } + + /* Call protocol handler */ + rc =3D handler(task->request_pl, task->request_pl_sz, + &task->response_pl, &task->response_pl_sz); + + signal_task_complete(task, rc); +} + +/** + * pci_ep_doe_submit_task() - Submit a task to be processed + * @doe_mb: DOE mailbox + * @task: Task to submit + * + * Submit a DOE task to the workqueue for asynchronous processing. + * + * Returns: 0 on success, -errno on failure + */ +static int pci_ep_doe_submit_task(struct pci_ep_doe_mb *doe_mb, + struct pci_ep_doe_task *task) +{ + if (test_bit(PCI_DOE_FLAG_DEAD, &doe_mb->flags)) + return -EIO; + + task->doe_mb =3D doe_mb; + INIT_WORK(&task->work, doe_ep_task_work); + queue_work(doe_mb->work_queue, &task->work); + return 0; +} + +/** + * pci_ep_doe_process_request() - Process DOE request on endpoint + * @epc: PCI endpoint controller + * @func_no: Physical function number + * @cap_offset: DOE capability offset + * @vendor: Vendor ID from request header + * @type: Protocol type from request header + * @request: Request payload in CPU-native format + * @request_sz: Size of request payload (bytes) + * @complete: Callback to invoke upon completion + * + * Asynchronously process a DOE request received on the endpoint. The requ= est + * payload should not include the DOE header (vendor/type/length). Ownersh= ip + * of the request buffer is transferred to DOE EP core, which frees the bu= ffer + * either on error or after the completion callback fires. The protocol ha= ndler + * will allocate the response buffer, which the caller (controller driver)= must + * free after use. + * + * This function returns immediately after queuing the request. The comple= tion + * callback will be invoked asynchronously from workqueue context once the + * request is processed. The callback receives the function number and cap= ability + * offset to identify the mailbox, along with a status code (0 on success,= -errno + * on failure), and other required arguments. + * + * As per DOE specification, a mailbox processes one request at a time. + * Therefore, this function will never be called concurrently for the same + * mailbox by different callers. + * + * The caller is responsible for the conversion of the received DOE request + * with le32_to_cpu() before calling this function. + * Similarly, it is responsible for converting the response payload with + * cpu_to_le32() before sending it back over the DOE mailbox. + * + * The caller is also responsible for ensuring that the request size + * is within the limits defined by PCI_DOE_MAX_LENGTH. + * + * Returns: 0 if the request was successfully queued, -errno on failure + */ +int pci_ep_doe_process_request(struct pci_epc *epc, u8 func_no, u16 cap_of= fset, + u16 vendor, u8 type, void *request, size_t request_sz, + pci_ep_doe_complete_t complete) +{ + struct pci_ep_doe_mb *doe_mb; + struct pci_ep_doe_task *task; + int rc; + + doe_mb =3D pci_ep_doe_get_mailbox(epc, func_no, cap_offset); + if (!doe_mb) { + kfree(request); + return -ENODEV; + } + + task =3D kzalloc_obj(*task, GFP_KERNEL); + if (!task) { + kfree(request); + return -ENOMEM; + } + + task->feat.vid =3D vendor; + task->feat.type =3D type; + task->request_pl =3D request; + task->request_pl_sz =3D request_sz; + task->response_pl =3D NULL; + task->response_pl_sz =3D 0; + task->complete =3D complete; + + rc =3D pci_ep_doe_submit_task(doe_mb, task); + if (rc) { + kfree(request); + kfree(task); + return rc; + } + + return 0; +} +EXPORT_SYMBOL_GPL(pci_ep_doe_process_request); + +/** + * pci_ep_doe_abort() - Abort DOE operations on a mailbox + * @epc: PCI endpoint controller + * @func_no: Physical function number + * @cap_offset: DOE capability offset + * + * Abort all queued and wait for in-flight DOE operations to complete for = the + * specified mailbox. This function is called by the EP controller driver + * when the RC sets the ABORT bit in the DOE Control register. + * + * The function will: + * + * - Set CANCEL flag to prevent new requests in the queue from starting + * - Wait for the currently executing handler to complete (cannot interrup= t) + * - Flush the workqueue to wait for all requests to be handled appropriat= ely + * - Clear CANCEL flag to prepare for new requests + * + * Returns: 0 on success, -errno on failure + */ +int pci_ep_doe_abort(struct pci_epc *epc, u8 func_no, u16 cap_offset) +{ + struct pci_ep_doe_mb *doe_mb; + + if (!epc) + return -EINVAL; + + doe_mb =3D pci_ep_doe_get_mailbox(epc, func_no, cap_offset); + if (!doe_mb) + return -ENODEV; + + /* Set CANCEL flag - worker will abort queued requests */ + set_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags); + flush_workqueue(doe_mb->work_queue); + + /* Clear CANCEL flag - mailbox ready for new requests */ + clear_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags); + + dev_dbg(epc->dev.parent, + "DOE mailbox aborted: PF%d offset 0x%x\n", + func_no, cap_offset); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_ep_doe_abort); + +/** + * pci_ep_doe_destroy_mb() - Destroy a single DOE mailbox + * @doe_mb: DOE mailbox to destroy + * + * Internal function to destroy a mailbox and free its resources. + */ +static void pci_ep_doe_destroy_mb(struct pci_ep_doe_mb *doe_mb) +{ + if (!doe_mb) + return; + + pci_ep_doe_cancel_tasks(doe_mb); + + if (doe_mb->work_queue) + destroy_workqueue(doe_mb->work_queue); + + kfree(doe_mb); +} + +/** + * pci_ep_doe_destroy() - Destroy all DOE mailboxes + * @epc: PCI endpoint controller + * + * Destroy all DOE mailboxes and free associated resources. + * + * The EPC core driver calls this to free all DOE resources, + * if DOE support is available for the EPC. + */ +void pci_ep_doe_destroy(struct pci_epc *epc) +{ + struct pci_ep_doe_mb *doe_mb; + unsigned long index; + + if (!epc) + return; + + xa_for_each(&epc->doe_mbs, index, doe_mb) + pci_ep_doe_destroy_mb(doe_mb); + + xa_destroy(&epc->doe_mbs); +} +EXPORT_SYMBOL_GPL(pci_ep_doe_destroy); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 5844deee2b5f..c4a0e25625e3 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -692,6 +692,13 @@ struct pci_doe_feature { u8 type; }; =20 +struct pci_epc; + +typedef void (*pci_ep_doe_complete_t)(struct pci_epc *epc, u8 func_no, + u16 cap_offset, int status, + u16 vendor, u8 type, + void *response_pl, size_t response_pl_sz); + #ifdef CONFIG_PCI_DOE void pci_doe_init(struct pci_dev *pdev); void pci_doe_destroy(struct pci_dev *pdev); @@ -702,6 +709,38 @@ static inline void pci_doe_destroy(struct pci_dev *pde= v) { } static inline void pci_doe_disconnected(struct pci_dev *pdev) { } #endif =20 +#ifdef CONFIG_PCI_ENDPOINT_DOE +int pci_ep_doe_init(struct pci_epc *epc); +int pci_ep_doe_add_mailbox(struct pci_epc *epc, u8 func_no, u16 cap_offset= ); +int pci_ep_doe_process_request(struct pci_epc *epc, u8 func_no, u16 cap_of= fset, + u16 vendor, u8 type, void *request, + size_t request_sz, pci_ep_doe_complete_t complete); +int pci_ep_doe_abort(struct pci_epc *epc, u8 func_no, u16 cap_offset); +void pci_ep_doe_destroy(struct pci_epc *epc); +#else +static inline int pci_ep_doe_init(struct pci_epc *epc) { return -EOPNOTSUP= P; } +static inline int pci_ep_doe_add_mailbox(struct pci_epc *epc, u8 func_no, + u16 cap_offset) +{ + return -EOPNOTSUPP; +} + +static inline int pci_ep_doe_process_request(struct pci_epc *epc, u8 func_= no, + u16 cap_offset, u16 vendor, u8 type, + void *request, size_t request_sz, + pci_ep_doe_complete_t complete) +{ + return -EOPNOTSUPP; +} + +static inline int pci_ep_doe_abort(struct pci_epc *epc, u8 func_no, u16 ca= p_offset) +{ + return -EOPNOTSUPP; +} + +static inline void pci_ep_doe_destroy(struct pci_epc *epc) { } +#endif + #ifdef CONFIG_PCI_NPEM void pci_npem_create(struct pci_dev *dev); void pci_npem_remove(struct pci_dev *dev); diff --git a/include/linux/pci-doe.h b/include/linux/pci-doe.h index abb9b7ae8029..c46e42f3ce78 100644 --- a/include/linux/pci-doe.h +++ b/include/linux/pci-doe.h @@ -22,6 +22,11 @@ struct pci_doe_mb; /* Max data object length is 2^18 dwords */ #define PCI_DOE_MAX_LENGTH (1 << 18) =20 +typedef int (*pci_doe_protocol_handler_t)(const void *request, + size_t request_sz, + void **response, + size_t *response_sz); + struct pci_doe_mb *pci_find_doe_mailbox(struct pci_dev *pdev, u16 vendor, u8 type); =20 diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 1eca1264815b..dd26294c8175 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -182,6 +182,9 @@ struct pci_epc { unsigned long function_num_map; int domain_nr; bool init_complete; +#ifdef CONFIG_PCI_ENDPOINT_DOE + struct xarray doe_mbs; +#endif }; =20 /** --=20 2.34.1 From nobody Sun May 24 19:33:54 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013068.outbound.protection.outlook.com [40.107.201.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BED7C3939B9; Fri, 22 May 2026 05:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427501; cv=fail; b=At/0ENB/Z/Ger5B5rnwcRsugG+eaiJy0eLt/VrTdxjIy/6Hsfua/KeLQ9YZQYKHiYImqKbyxCxeIUEl8O7Cs9czpfk1q9WUl+xdeRBL2qz79HiU7EhFIu5gEyFQ9ppbSkr7T/Fk2aDjklksQuozZxFB1fl9BAqaSFXnOZ/KZQiM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427501; c=relaxed/simple; bh=+cj1g5UvSh5IJmShtzrX9BynXGEYmm6qi56yuyyV9Qg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AhdI34O8QMVJT/OY3Wnv5YMTZ8oWelsMbjg7ClwyxVCS6zHe4+05R25NlxtKWKbJsS2s6x0pICA3yeNOWl48AQyqi42Yjerdr4+MXHpvy6RP0xxEJjDKmZ8QaWe23m2q5NiBJufdf6gDU7yjPuXauolUPJHPgeCE5DVfQRSqN4Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=aLpHA9GZ; arc=fail smtp.client-ip=40.107.201.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="aLpHA9GZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KNYuhTMl0dyVl4YQO7KSWSbnWjJKX0u3ANemgSWUR9tfH2B9ZYRKaZfHP+FgkoxCB/pIb4DyKDo2W+PCrPbWnZWZqqD+17LkThTO1bU1px6AMnUAYapBq1QjWYkvDKNlC+56+Z0iTWAdCImkpHDcmMz8Vlo//LEF27FEC6UfJBoHH4THRQTwJrjY2jSfs/bUfqU5AlqiJCvSlXfVP02XY7LN5jLkuKdq0woYJdPJdGOmFXfXSCnRvhFSwNGIDcRnjF7jEJjDAH8gYWCMbt/czTtd1oGTVPuTcksSWSTvXw/bDhHlSKTZQZT6j1XGB74SZFJzPHfOnYX7cmzahm3CFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=WN4DrYikmuZNlC6Gk0i+kSIthM58oE/Z6lQ3GB+gflU=; b=Mf+MawdgqKaR5O/+JPDwUHUchGccr/5ajbR8is4GHRm4gy9NM0RZwzQJJmQrHFi09vuBFb3QJZZnwRGtERUxkJk2wU64RvczmpG6/xQXIPBNERGrnq67czt5WTctTLcoKxVBh21oQ/QsrU3P/Fh//oXBJy25UQAMqR5TW7o9jSbJ14mfcrBI5j90q5CoNinZnvicb4SJP8eYI9daCh4FD9EAI7FtQUrE+mJzUiQnlddBBLQ5RET/3rOYVuNl0S4+G7YCRbsCri5UZLR7eCCkKNg9ytoiJqNPp7XxRsKclEwNeBbWHKXo7tOPmSm7/tTqxSuKu/NPURiJn8yPlvfdYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.21.194) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WN4DrYikmuZNlC6Gk0i+kSIthM58oE/Z6lQ3GB+gflU=; b=aLpHA9GZi07ix1mhiXG2CBjO+68RiX8IzRgK6DGPq76dRjF8KW8RJkERznRnlm5K2LafhLrwcFu+zCVFFrdX5XIzjBfPqVi37xpRj8iqHgtuMNYU5pQNDUFo3jTDLsOYAfycCcbewbdcyeT/dkgPatZC/tibI/ZUgJbSZNym4pE= Received: from CH0PR03CA0285.namprd03.prod.outlook.com (2603:10b6:610:e6::20) by MN2PR10MB4400.namprd10.prod.outlook.com (2603:10b6:208:198::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.17; Fri, 22 May 2026 05:24:57 +0000 Received: from DS2PEPF00003445.namprd04.prod.outlook.com (2603:10b6:610:e6:cafe::91) by CH0PR03CA0285.outlook.office365.com (2603:10b6:610:e6::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.17 via Frontend Transport; Fri, 22 May 2026 05:24:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.21.194) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.21.194 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.21.194; helo=flwvzet200.ext.ti.com; pr=C Received: from flwvzet200.ext.ti.com (198.47.21.194) by DS2PEPF00003445.mail.protection.outlook.com (10.167.17.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Fri, 22 May 2026 05:24:55 +0000 Received: from DFLE207.ent.ti.com (10.64.6.65) by flwvzet200.ext.ti.com (10.248.192.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:24:55 -0500 Received: from DFLE203.ent.ti.com (10.64.6.61) by DFLE207.ent.ti.com (10.64.6.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:24:55 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DFLE203.ent.ti.com (10.64.6.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37 via Frontend Transport; Fri, 22 May 2026 00:24:55 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [10.24.68.129]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 64M5OZpY1350956; Fri, 22 May 2026 00:24:50 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v4 3/4] PCI: endpoint: Add support for DOE initialization and setup in EPC core Date: Fri, 22 May 2026 10:54:33 +0530 Message-ID: <20260522052434.802034-4-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260522052434.802034-1-a-garg7@ti.com> References: <20260522052434.802034-1-a-garg7@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003445:EE_|MN2PR10MB4400:EE_ X-MS-Office365-Filtering-Correlation-Id: 3377759a-ca0f-480d-5e19-08deb7c275c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|82310400026|376014|7416014|1800799024|921020|18002099003|56012099003|22082099003|5023799004|6133799003; X-Microsoft-Antispam-Message-Info: fp0xe8681MXLvMA7iRaglZr/DmbZPdbjJ+tPbvepdI9cY/PlP1bXTSXGSAX9EZFuXhX6KSUbNH5r8VabLuCzFeCK2NiCl1mLOhIEWJbbrGG7XwGM4QC8noEFjpvpJHEuSFj8UNjquXq4lgjfASDeyS1uUQvC0CS6vqLmyS247iM4OIKmHOm9IuCrN/03IhsJmkPygCVEiXSlv6Bv9HKDAoyr7R1+eWbdQV+QjtJp4/oi4nQ+u5NNssv5FaxfB3x0mAsnJX0MMIOgRaxKc2I2sEmbi0ig93SHVc3BScnDR3i03ENyGEetJspDbj9sqEwicFDdcdW5e8FKihmF8sza87GtYCuXp+ywTLaIz66rJCfLl8gLpBBOC/HvC9qkvOUI1aw30KpENsV0zMVIMLtmDeCkXjGNInK1m1G+tqVTU7rzYbbeYiAFPpwR2WzYhU7GgBrTBYcC622An6coDZf1Epy9L7RMQQpWoRKKORWrhSb+TBckhf0x5XpGNeV8gwFK3Crq4glH6GtoDjz1RBEIDcMdDXPU+w3GLqJJR5dK7Mg/HQAYs8z9h7/0hgCxdd1ulEbXJEqCc03EatgIFVDN4IWMTYm4xh2cwbEGZx0NT0Uc7hgIIP3Jo4xOZnD5rTQIF9OTAR16pP1HouyYUu3m5k0JogaKKBQU4b9oR9+GaDW9UnHCJtQ9tFAd1Ueo9wWlKMoOIozc4GNTujf8VSZbvhU4a3bvR2ZhpdYES1XmIxfSgdn6WEChHIi+ZL/Q3BVqRRAOoCQmfcKUswHCsA4+QOngXWgeAmpFnSUypz3vjlQ= X-Forefront-Antispam-Report: CIP:198.47.21.194;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:flwvzet200.ext.ti.com;PTR:ErrorRetry;CAT:NONE;SFS:(13230040)(36860700016)(82310400026)(376014)(7416014)(1800799024)(921020)(18002099003)(56012099003)(22082099003)(5023799004)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4FsXalaSOOgwZ/SgT4THSvDq5bQ9U+QAk8JgwMyw/hGd8t70W7lfzAfHTWXOhac1KJf7vFrPLkB2O1JKsH6iFkMsOodD32sRieSiG47Kbtq4opKGVfu87UFCruj6hHUPKECIo55m9kmVuqDFfugd0Fk0LqkAqGoNXNzKSw77f845nuWE8ePgS8RtlXdhUtlB9cG6c4Q7Vel1mH5L17JDQobrWNFiVyVjengMfOAaiQ1MT2dQsWpfQyRib2c47TKWOBOw8vGaH8HnamaZIFMx+qOSp7iCc3Lt29Vyk3TV7Lx8rioKBXjEIAqDz4gwcgwchXlK5N+ZhwOYheBWWilVZhuFDQXexn/0WWU9YKCZVl3YW5PD/OwdZqno/p+7/3++Nh0vaQ3a6AT/6W4h1GcLkQ5Ny4OLzH9PEledJyPTPI0aUXyUlCkury5crXwwAttA X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2026 05:24:55.9477 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3377759a-ca0f-480d-5e19-08deb7c275c3 X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.21.194];Helo=[flwvzet200.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003445.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4400 Content-Type: text/plain; charset="utf-8" Add pci_epc_init_capabilities() in EPC core driver to initialize and setup the capabilities supported by the EPC driver. This calls pci_epc_doe_setup() to setup the DOE framework for an endpoint controller, which discovers the DOE capabilities (extended capability ID 0x2E), and registers each discovered DOE mailbox for all the functions in the endpoint controller. Add pci_epc_deinit_capabilities() in EPC core driver for cleanup of the resources used by the capabilities of the EPC driver. This calls pci_ep_doe_destroy() to destroy all DOE mailboxes and free associated resources. Co-developed-by: Siddharth Vadapalli Signed-off-by: Siddharth Vadapalli Signed-off-by: Aksh Garg --- Changes from v3 to v4: - Call DOE setup and destroy APIs directly within the EPC core, instead of relying on the EPC drivers to call them individually. EPC drivers do not need to explicitly handle DOE setup, rather the EPC core manages this transparently. (Suggested by Manivannan Sadhasivam). - Removed pci_epc_doe_destroy() API, which was just calling pci_ep_doe_dest= roy(). Instead, called pci_ep_doe_destroy() directly during cleanup. - Called pci_ep_doe_init() before the "!epc->ops->find_ext_capability" chec= k, because if doe-capable=3D1 and find_ext_capability() op is undefined, this would not initialize the epc->doe_mbs xarray. However during cleanup, the check "!epc->ops->find_ext_capability" would be unnecessary, and it will try to destroy the epc->doe_mbs xarray even when it was not initialized. Changes from v2 to v3: - Rebased on 7.1-rc1. Changes since v1: - New patch added to v2 (not present in v1) v3: https://lore.kernel.org/all/20260427051725.223704-4-a-garg7@ti.com/ v2: https://lore.kernel.org/all/20260401073022.215805-4-a-garg7@ti.com/ This patch is introduced based on the feedback provided by Manivannan Sadhasivam at [1]. [1]: https://lore.kernel.org/all/p57x6jleaim5w7t2k3v7tioujnaxuovfpj5euop5og= efvw23se@y5fw3che5p5d/ drivers/pci/endpoint/pci-epc-core.c | 92 +++++++++++++++++++++++++++++ include/linux/pci-epc.h | 6 ++ 2 files changed, 98 insertions(+) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci= -epc-core.c index 6c3c58185fc5..af7889b541c0 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -14,6 +14,8 @@ #include #include =20 +#include "../pci.h" + static const struct class pci_epc_class =3D { .name =3D "pci_epc", }; @@ -842,6 +844,71 @@ void pci_epc_linkdown(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_linkdown); =20 +/** + * pci_epc_doe_setup() - Discover and setup DOE mailboxes for all functions + * @epc: the EPC device on which DOE mailboxes has to be setup + * + * Discover DOE (Data Object Exchange) capabilities for all physical funct= ions + * in the endpoint controller and register DOE mailboxes. + * + * Returns: 0 on success, -errno on failure + */ +static int pci_epc_doe_setup(struct pci_epc *epc) +{ + u16 cap_offset =3D 0; + u8 func_no; + int ret; + + if (!epc->ops || !epc->ops->find_ext_capability) + return -EINVAL; + + /* Discover DOE capabilities for all functions */ + for (func_no =3D 0; func_no < epc->max_functions; func_no++) { + while ((cap_offset =3D epc->ops->find_ext_capability(epc, func_no, 0, + cap_offset, + PCI_EXT_CAP_ID_DOE))) { + /* Register this DOE mailbox */ + ret =3D pci_ep_doe_add_mailbox(epc, func_no, cap_offset); + if (ret) { + dev_warn(&epc->dev, + "[pf%d:offset %x] failed to add DOE mailbox\n", + func_no, cap_offset); + } + } + } + + dev_dbg(&epc->dev, "DOE mailboxes setup complete\n"); + return 0; +} + +/** + * pci_epc_init_capabilities() - Initialize EPC capabilities + * @epc: the EPC device whose capabilities need to be initialized + * + * Invoke to initialize capabilities supported by the EPC device. + */ +static void pci_epc_init_capabilities(struct pci_epc *epc) +{ + const struct pci_epc_features *epc_features; + int ret; + + epc_features =3D pci_epc_get_features(epc, 0, 0); + if (!epc_features) + return; + + if (IS_ENABLED(CONFIG_PCI_ENDPOINT_DOE) && epc_features->doe_capable) { + ret =3D pci_ep_doe_init(epc); + if (ret) { + dev_warn(&epc->dev, "DOE initialization failed: %d\n", ret); + return; + } + + ret =3D pci_epc_doe_setup(epc); + if (ret) + dev_warn(&epc->dev, "DOE setup failed: %d\n", ret); + } +} + /** * pci_epc_init_notify() - Notify the EPF device that EPC device initializ= ation * is completed. @@ -857,6 +924,8 @@ void pci_epc_init_notify(struct pci_epc *epc) if (IS_ERR_OR_NULL(epc)) return; =20 + pci_epc_init_capabilities(epc); + mutex_lock(&epc->list_lock); list_for_each_entry(epf, &epc->pci_epf, list) { mutex_lock(&epf->lock); @@ -890,6 +959,27 @@ void pci_epc_notify_pending_init(struct pci_epc *epc, = struct pci_epf *epf) } EXPORT_SYMBOL_GPL(pci_epc_notify_pending_init); =20 +/** + * pci_epc_deinit_capabilities() - Cleanup EPC capabilities + * @epc: the EPC device whose capabilities need to be cleaned up + * + * Invoke to cleanup capabilities supported by the EPC device, + * and free the associated resources. + */ +static void pci_epc_deinit_capabilities(struct pci_epc *epc) +{ + const struct pci_epc_features *epc_features; + + epc_features =3D pci_epc_get_features(epc, 0, 0); + if (!epc_features) + return; + + if (IS_ENABLED(CONFIG_PCI_ENDPOINT_DOE) && epc_features->doe_capable) { + pci_ep_doe_destroy(epc); + dev_dbg(&epc->dev, "DOE mailboxes destroyed\n"); + } +} + /** * pci_epc_deinit_notify() - Notify the EPF device about EPC deinitializat= ion * @epc: the EPC device whose deinitialization is completed @@ -903,6 +993,8 @@ void pci_epc_deinit_notify(struct pci_epc *epc) if (IS_ERR_OR_NULL(epc)) return; =20 + pci_epc_deinit_capabilities(epc); + mutex_lock(&epc->list_lock); list_for_each_entry(epf, &epc->pci_epf, list) { mutex_lock(&epf->lock); diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index dd26294c8175..11474e337db3 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -84,6 +84,8 @@ struct pci_epc_map { * @start: ops to start the PCI link * @stop: ops to stop the PCI link * @get_features: ops to get the features supported by the EPC + * @find_ext_capability: ops to find extended capability offset for a func= tion + * in endpoint controller * @owner: the module owner containing the ops */ struct pci_epc_ops { @@ -115,6 +117,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); + u16 (*find_ext_capability)(struct pci_epc *epc, u8 func_no, + u8 vfunc_no, u16 start, u8 cap); struct module *owner; }; =20 @@ -270,6 +274,7 @@ struct pci_epc_bar_desc { * @msi_capable: indicate if the endpoint function has MSI capability * @msix_capable: indicate if the endpoint function has MSI-X capability * @intx_capable: indicate if the endpoint can raise INTx interrupts + * @doe_capable: indicate if the endpoint function has DOE capability * @bar: array specifying the hardware description for each BAR * @align: alignment size required for BAR buffer allocation */ @@ -280,6 +285,7 @@ struct pci_epc_features { unsigned int msi_capable : 1; unsigned int msix_capable : 1; unsigned int intx_capable : 1; + unsigned int doe_capable : 1; struct pci_epc_bar_desc bar[PCI_STD_NUM_BARS]; size_t align; }; --=20 2.34.1 From nobody Sun May 24 19:33:54 2026 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012036.outbound.protection.outlook.com [52.101.53.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D1E5357CEA; Fri, 22 May 2026 05:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427505; cv=fail; b=Ipwu0JuO0aFNnmKVVVilOdoxqGD46UgKRxCDojY1jbWLID2mFsj1lKNwEmgALir7VRtJwsCZ5PXvdjWL/ZPqJqOG5WGvIfOeM0pgnknpY3FIKiEttWNPc8s/X1rPahvFIY0wTetUJYqLZWvyCtgm+0Rlg59IAeCnca2sOTyp9j0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779427505; c=relaxed/simple; bh=bNDH87uKqhlra0aM9eBTx5sxuIDHSfkul9ZYOasJdPI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nCvXtbrMvThGN3XYaqLvGWIfgj7e7R9Apsh5UA3A5tbcXv0i7NBJcd7URRsl6QtlCI2YUtsibZnUZwsBcUavetKTwpnefyCAn7QCZWTejvE2SnkQJjn0GfRdVF+WYbPwwXk3K721CaRg2KPAWJHCAILlagexRxOjNK3udbxAsss= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=arW0kGeD; arc=fail smtp.client-ip=52.101.53.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="arW0kGeD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GHJfTyLeGYAFP4awmshKPk0yxQTr2hmWlUY5MNlU97VYLgPRjHtyb4AEffo7wfVCS1qEXWl4o3lf0KHWDk/LySV41nq5UjZtvmPqWeHIGN6PV5XsNJyLjhlgS5yLx7WxC6riS4gpUWg09rhxnB/qm3fKzQRqZAPsdWixkPHfAHlfN0H/DPIkCKpni9hP3KWebRVV1qczOwAJZn1mU7jRKyxWCtDbd2Vez2JnuvEwrsP8dPlr3hipK9rBPMrEdduxig2V6BHxEEaaG0dz0hcR8aOeKd06v4HUN6cO2OgyQPumx8x6HxfhnNtIxqFwzA9dvqqVl1TcLxLlL8ICCnpVjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=lmnpbHzEfzLC6rOdSJXSxBF+aZyp7hruqktBOY5EicI=; b=Wn2khuKmd7RRgpYe903TDZt7E50amb5R9t3ZdrLqVBghHWc+g7RBkrtoroUnr+1pAy9A7mj8x5zb7gD65/D/FpDCh8E/L3h3rts1aX5v4g1gIyEHmGXxOT79JYUBF5MH3ssLrrYHsrZ2OorLuFdX5mOuyb13aSOE4Z8my5qx/tiF/BSWrseC9f0G8Fro7WPoTFCPcVwsIAdybo417iCNoo3pPUJN8idubRz+s1S0DWbVbU7gF4VnFJdueB811QFHY2NqxPqR9WWAawbe690zyqeREXpEwbFceK16zfKJ4++WFfgHR2mwYBcGRwHLkq8AqA2xgU+XW8WvT/BWJzNJLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.23.195) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lmnpbHzEfzLC6rOdSJXSxBF+aZyp7hruqktBOY5EicI=; b=arW0kGeDIDZDOgfEfr4+/Tsq2fiNSRZwJlH2SbM2oJrXjwzmO502PeIHNnoqfvT5EFb49FYEPM6Zx2sjtEil+5F7Z2KvEuWe//eJKlt9qjvl4XxPGGlpoLj8PKpr7Yb5ro+DKEd84P48TanUjGPiMvc9ZvR3Or112D6wNPkz4sI= Received: from DM6PR06CA0084.namprd06.prod.outlook.com (2603:10b6:5:336::17) by DS4PPF3689F8B17.namprd10.prod.outlook.com (2603:10b6:f:fc00::d12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9913.11; Fri, 22 May 2026 05:25:01 +0000 Received: from DS1PEPF0001709B.namprd05.prod.outlook.com (2603:10b6:5:336:cafe::db) by DM6PR06CA0084.outlook.office365.com (2603:10b6:5:336::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.17 via Frontend Transport; Fri, 22 May 2026 05:25:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.23.195) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.23.195 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.23.195; helo=lewvzet201.ext.ti.com; pr=C Received: from lewvzet201.ext.ti.com (198.47.23.195) by DS1PEPF0001709B.mail.protection.outlook.com (10.167.18.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Fri, 22 May 2026 05:25:00 +0000 Received: from DLEE212.ent.ti.com (157.170.170.114) by lewvzet201.ext.ti.com (10.4.14.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:25:00 -0500 Received: from DLEE210.ent.ti.com (157.170.170.112) by DLEE212.ent.ti.com (157.170.170.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 22 May 2026 00:25:00 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DLEE210.ent.ti.com (157.170.170.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37 via Frontend Transport; Fri, 22 May 2026 00:25:00 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [10.24.68.129]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 64M5OZpZ1350956; Fri, 22 May 2026 00:24:55 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v4 4/4] Documentation: PCI: Add documentation for DOE endpoint support Date: Fri, 22 May 2026 10:54:34 +0530 Message-ID: <20260522052434.802034-5-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260522052434.802034-1-a-garg7@ti.com> References: <20260522052434.802034-1-a-garg7@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709B:EE_|DS4PPF3689F8B17:EE_ X-MS-Office365-Filtering-Correlation-Id: cc9ba8b6-ae7b-43fb-1a99-08deb7c278b8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700016|82310400026|376014|3023799007|921020|56012099003|22082099003|18002099003|5023799004|6133799003; X-Microsoft-Antispam-Message-Info: PyNcKfkmV7u3Lh0r5Z04TxO6+QBk2bWyCShTXMloNz0awIylR1xjk3bSfLJANsitHlID9VSA0vBapyUqPYz5GDPJaEohNvdJiK1L5pT3TSN/i9PbUOlDJ9FqInrm813rpZmnyoQ4z3LanYH20Fj+RHEqONZmDyV5ZNG+KThtZulYoj2ze/RGpKUX4N1PVtZAKP47MdFLrKxByKDO3wDtKmleqSdQ/QOkYCULztetZRkhzKtIM15mvXY+OUcacgEMdvpadY9yFXdwOx1fndY4Fx2RW8mhE0trtbo4vseQrjeNRM37q6lV7Po2NtS3P5cjh+Eohjhr/W+6pE5JcmtzNm1FhNd7AbTwMrBt5UKNFVhbGgH3jeFNBsDEAyCPTggv7Jx5redt6yq9JcOuPYfME+jz/81iRVHNNEMh6ffL7mqBFQRrMUbFivrFHvx1fjoaTdXb6z4WI1xxwdh7llgnlvr1wiobomn+aCGd2onsSwwvyOCPmIxXnYNsesYjywOAcOBlK7AIW5/I2SOHu79TdPafJlSvSlm1jGELdYXGx9SOTWTH2QOZ/JbBdWaBVLscZ5R64xQ6c+16lQE4u7uCsjzvEY1sF2XZKXAX71F5+LoW3+3oo9S7XWY7QwHi3jB/QWhnbF0P1gnrlRDdEeKe+CIBfAViEFJiugeVfyb0yD3LfJVr1MpDRBvG/45IjvqGVAGvlDhuw3L9DaVBpTiwjESYIXXlfjgkIx+L2bkkHG5gnQaDOi6hKTaeKokxZo/hnLOKoZRUEmIZc4ijDFl6Rg== X-Forefront-Antispam-Report: CIP:198.47.23.195;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:lewvzet201.ext.ti.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700016)(82310400026)(376014)(3023799007)(921020)(56012099003)(22082099003)(18002099003)(5023799004)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hQcS5Nb4mz3v6eTUP6VZ5IyDRVV1mVoGNlkiwRkT67Jyw6oX/W5aQZAN8LkVAq6Cu+ZGad3Mcrs+/5YCiuVVtYywAWwCdTThXY5GaWb8mC9Nq4xOUS+ACCkB/3ZQIIMV4wdcntYc1KDfzl/nhY9JBb9DdxS/CuvVEGZEqraw8f8/yo68xRqCnkioHjHgztF0MHW6jjmV61aD4mr/6iW4mMkqsAczl/RsV5E40GORxU+nqU5eVHZotDN++JO+Y5YBQZTPke8L4YyxBATdebtYt99f4EawNdXSLuWT7JKOLo9k9dyXUkXF5vqqYrFfvezxzGPvgxFjPDSFaDPd6kGCuEYeRMjYCoJTGv4nxPfVYbjt8g1+sDV5YgTl7Fz4G+A+YFP6RxUT649L0Z2mKRsaTHs9GzAiZp6LOBBkPovjR15wjNhxqhy0H8xqucn1ulkV X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2026 05:25:00.9065 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc9ba8b6-ae7b-43fb-1a99-08deb7c278b8 X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.23.195];Helo=[lewvzet201.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001709B.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS4PPF3689F8B17 Document the architecture and implementation details for the Data Object Exchange (DOE) framework for PCIe Endpoint devices. Co-developed-by: Siddharth Vadapalli Signed-off-by: Siddharth Vadapalli Signed-off-by: Aksh Garg --- Changes from v3 to v4: - Updated the maximum size of the DOE object from 256KB to 1MB, as per PCIe spec. - Updated the DOE setup and cleanup sections. Changes from v2 to v3: - Rebased on 7.1-rc1. Changes since v1: - Squashed the patches [1] and [2], and moved the documentation file to Documentation/PCI/endpoint/pci-endpoint-doe.rst to match the existing naming scheme, as suggested by Niklas Cassel - Updated the documentation as per the design and implementaion changes made to previous patches in this series: * Updated for static protocol array instead of dynamic registration * Documented asynchronous callback model * Updated request/response flow with new callback signature * Updated memory ownership: DOE core frees request, driver frees response * Updated initialization and cleanup sections for new APIs v3: https://lore.kernel.org/all/20260427051725.223704-5-a-garg7@ti.com/ v2: https://lore.kernel.org/all/20260401073022.215805-5-a-garg7@ti.com/ v1: [1] https://lore.kernel.org/all/20260213123603.420941-2-a-garg7@ti.com/ [2] https://lore.kernel.org/all/20260213123603.420941-5-a-garg7@ti.com/ Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-endpoint-doe.rst | 329 ++++++++++++++++++ 2 files changed, 330 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-endpoint-doe.rst diff --git a/Documentation/PCI/endpoint/index.rst b/Documentation/PCI/endpo= int/index.rst index dd1f62e731c9..7c03d5abd2ef 100644 --- a/Documentation/PCI/endpoint/index.rst +++ b/Documentation/PCI/endpoint/index.rst @@ -9,6 +9,7 @@ PCI Endpoint Framework =20 pci-endpoint pci-endpoint-cfs + pci-endpoint-doe pci-test-function pci-test-howto pci-ntb-function diff --git a/Documentation/PCI/endpoint/pci-endpoint-doe.rst b/Documentatio= n/PCI/endpoint/pci-endpoint-doe.rst new file mode 100644 index 000000000000..a424a0a3add6 --- /dev/null +++ b/Documentation/PCI/endpoint/pci-endpoint-doe.rst @@ -0,0 +1,329 @@ +.. SPDX-License-Identifier: GPL-2.0-only OR MIT + +.. include:: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Data Object Exchange (DOE) for PCIe Endpoint +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:Copyright: |copy| 2026 Texas Instruments Incorporated +:Author: Aksh Garg +:Co-Author: Siddharth Vadapalli + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D + +DOE (Data Object Exchange) is a standard PCIe extended capability feature +introduced in the Data Object Exchange (DOE) ECN for PCIe r5.0. It is an o= ptional +mechanism for system firmware/software running on root complex (host) to p= erform +:ref:`data object ` exchanges with an endpoint function.= Each +data object is uniquely identified by the Vendor ID of the vendor publishi= ng the +data object definition and a Data Object Type value assigned by that vendo= r. + +Think of DOE as a sophisticated mailbox system built into PCIe. The root c= omplex +can send structured requests to the endpoint device through DOE mailboxes,= and +the endpoint device responds with appropriate data. DOE mailboxes are impl= emented +as PCIe Extended Capabilities in endpoint devices, allowing multiple mailb= oxes +per function, each potentially supporting different data object protocols. + +The DOE support for root complex devices has already been implemented in +``drivers/pci/doe.c``. + +How DOE Works +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The DOE mailbox operates through a simple request-response model: + +1. **Host sends request**: The root complex writes a data object (vendor I= D, type, + and payload) to the DOE write mailbox register (one DWORD at a time) of= the + endpoint function's config space and sets the GO bit in the DOE Control= register + to indicate that a request is ready for processing. +2. **Endpoint processes**: The endpoint function reads the request from DO= E write + mailbox register, sets the BUSY bit in the DOE Status register, identif= ies the + protocol of the data object, and executes the appropriate handler. +3. **Endpoint responds**: The endpoint function writes the response data o= bject to the + DOE read mailbox register (one DWORD at a time), and sets the READY bit= in the DOE + Status register to indicate that the response is ready. If an error occ= urs during + request processing (such as unsupported protocol or handler failure), t= he endpoint + sets the ERROR bit in the DOE Status register instead of the READY bit. +4. **Host reads response**: The root complex retrieves the response data f= rom the DOE read + mailbox register once the READY bit is set in the DOE Status register, = and then writes + any value to this register to indicate a successful read. If the ERROR = bit was set, + the root complex discards the response and performs error handling as n= eeded. + +Each mailbox operates independently and can handle one transaction at a ti= me. The +DOE specification supports data objects of size up to 1MB (2\ :sup:`18` dw= ords). + +For complete DOE capability details, refer to `PCI Express Base Specificat= ion Revision 7.0, +Section 6.30 - Data Object Exchange (DOE)`. + +Key Terminologies +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. _data-object-term: + +**Data Object** + A structured, vendor-defined, or standard-defined message exchanged betw= een + root complex and endpoint function via DOE capability registers in confi= guration + space of the function. + +**Mailbox** + A DOE capability on the endpoint device, where each physical function ca= n have + multiple mailboxes. + +**Protocol** + A specific type of DOE communication data object identified by a Vendor = ID and Type. + +**Handler** + A function that processes DOE requests of a specific protocol and genera= tes responses. + +Architecture of DOE Implementation for Endpoint +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. code-block:: text + + +------------------+ + | | + | Root Complex | + | | + +--------^---------+ + | + | Config space access + | over PCIe link + | + +----------v-----------+ + | | + | PCIe Controller | + | as Endpoint | + | | + | +-----------------+ | + | | DOE Mailbox | | + | +-------^---------+ | + +----------|-----------+ + +-----------|---------------------------------------------------------= ------+ + | | +-----------------= ---+ | + | +---------v--------+ Allocate | +--------------= + | | + | | |-------------------------------->| Request = | | | + | | EP Controller | +--->| Buffer = | | | + | | Driver | Free | | +--------------= + | | + | | |--------------------------+ | | = | | + | +--------^---------+ | | | = | | + | | | | | = | | + | | | | | = | | + | | pci_ep_doe_process_request() | | | = | | + | | | | | = | | + | +--------v---------+ Free | | | = | | + | | |----------------------------+ | DDR = | | + | | DOE EP Core |<----+ | | = | | + | | (doe-ep.c) | | Discovery | | = | | + | | |-----+ Protocol Handler | | = | | + | +--------^---------+ | | = | | + | | | | = | | + | | protocol_handler() | | = | | + | | | | = | | + | +--------v---------+ | | = | | + | | | | | +--------------= + | | + | | Protocol Handler | +----->| Response = | | | + | | Module |-------------------------------->| Buffer = | | | + | | (CMA/SPDM/Other) | Allocate | +--------------= + | | + | | | | = | | + | +------------------+ | = | | + | +-----------------= ---+ | + +---------------------------------------------------------------------= ------+ + +Initialization and Cleanup +-------------------------- + +**Framework Initialization and DOE Setup** + +The EPC core automatically initializes and sets up DOE mailboxes through t= he +``pci_epc_init_capabilities()`` internal function, which is invoked during +``pci_epc_init_notify()`` when the controller driver calls this API. +Controller drivers do not need to explicitly handle DOE initialization, +rather the EPC core manages this transparently. + +DOE initialization only occurs when the EPC driver reports DOE capability +through the ``doe_capable`` flag in its ``pci_epc_features``. + +This internal function performs the following steps: + +1. Calls ``pci_ep_doe_init(epc)`` to initialize the xarray data structure + (a resizable array data structure defined in linux) named ``doe_mbs`` t= hat + stores metadata of DOE mailboxes for the controller in ``struct pci_epc= ``. +2. Calls ``pci_epc_doe_setup(epc)`` to discover all DOE capabilities in the + endpoint function's configuration space for each function. For each + discovered DOE capability, calls ``pci_ep_doe_add_mailbox(epc, func_no, + cap_offset)`` to register the mailbox. + +Each DOE mailbox structure created by ``pci_ep_doe_add_mailbox()`` gets an +ordered workqueue allocated for processing DOE requests sequentially for t= hat +mailbox, enabling concurrent request handling across different mailboxes. = Each +mailbox is uniquely identified by the combination of physical function num= ber +and capability offset for that controller. + +**Cleanup** + +The EPC core automatically cleans up DOE mailboxes through the +``pci_epc_deinit_capabilities()`` internal function, which is invoked duri= ng +``pci_epc_deinit_notify()`` when the controller driver calls this API. +Controller drivers do not need to explicitly handle DOE cleanup, rather +the EPC core manages this transparently. + +DOE cleanup only occurs when the EPC device reported DOE capability +through the ``doe_capable`` flag in its ``pci_epc_features``. + +This internal function calls ``pci_ep_doe_destroy(epc)``, which destroys a= ll +registered mailboxes, cancels any pending tasks, flushes and destroys the +workqueues, and frees all memory allocated to the mailboxes. + +Protocol Handler Support +------------------------ + +Protocol implementations (such as CMA, SPDM, or vendor-specific protocols)= are +supported through a static array of protocol handlers. + +When a new DOE protocol library is introduced, its handler function is add= ed to +the static ``pci_doe_protocols`` array in ``drivers/pci/endpoint/pci-ep-do= e.c``. +The discovery protocol (VID =3D 0x0001 (PCI-SIG vendor ID), Type =3D 0x00 = (discovery +protocol)) is included in this static array and handled internally by the +DOE EP core. + +Request Handling +---------------- + +The complete flow of a DOE request from the root complex to the response: + +**Step 1: Root Complex =E2=86=92 EP Controller Driver** + +The root complex writes a DOE request (Vendor ID, Type, and Payload) to the +DOE write mailbox register in the endpoint function's configuration space = and sets +the GO bit in the DOE Control register, indicating that the request is rea= dy for +processing. + +**Step 2: EP Controller Driver =E2=86=92 DOE EP Core** + +The controller driver reads the request header to determine the data object +length. Based on this length field, it allocates a request buffer in memory +(DDR) of the appropriate size. The driver then reads the complete request +payload from the DOE write mailbox register and converts the data from +little-endian format (the format followed in the PCIe transactions over the +link) to CPU-native format using ``le32_to_cpu()``. The driver defines a +completion callback function with signature ``void (*complete)(struct pci_= epc *epc, +u8 func_no, u16 cap_offset, int status, u16 vendor, u8 type, void *respons= e_pl, +size_t response_pl_sz)`` to be invoked when the request processing complet= es. +The driver then calls ``pci_ep_doe_process_request(epc, func_no, cap_offse= t, +vendor, type, request, request_sz, complete)`` to hand off the request to = the +DOE EP core. This function returns immediately after queuing the work +(without blocking), and the driver sets the BUSY bit in the DOE Status reg= ister. + +**Step 3: DOE EP Core Processing** + +The DOE EP core creates a task structure and submits it to the mailbox's o= rdered +workqueue. This ensures that requests for each mailbox are processed +sequentially, one at a time, as required by the DOE specification. It look= s up +the protocol handler based on the Vendor ID and Type from the request head= er, +and executes the handler function. + +**Step 4: Protocol Handler Execution** + +The workqueue executes the task by calling the registered protocol handler: +``handler(request, request_sz, &response, &response_sz)``. The handler pro= cesses +the request, allocates a response buffer in memory (DDR), builds the respo= nse +data, and returns the response pointer and size. For the discovery protoco= l, +the DOE EP core handles this directly without invoking an external handler. + +**Step 5: DOE EP Core =E2=86=92 EP Controller Driver** + +After the protocol handler completes, the DOE EP core frees the request bu= ffer, +and invokes the completion callback provided by the controller driver asyn= chronously. +The callback receives the struct pci_epc, function number, capability offs= et (to +identify the mailbox), status code indicating the result of request proces= sing, +vendor ID and type of the data object, the response buffer, and its size. + +**Step 6: EP Controller Driver =E2=86=92 Root Complex** + +The controller driver converts the response from CPU-native format to +little-endian format using ``cpu_to_le32()``, writes the response to DOE r= ead +mailbox register, and sets the READY bit in the DOE Status register. The r= oot +complex then reads the response from the read mailbox register. Finally, t= he controller +driver frees the response buffer (which the handler allocated). + +Asynchronous Request Processing +------------------------------- + +The DOE-EP framework implements asynchronous request processing because an +endpoint function can have multiple instances of DOE mailboxes, and reques= ts may +be interleaved across these mailboxes. Request processing of one mailbox s= hould +not result in blocking request processing of other mailboxes. Hence, reque= sts +on each mailbox need to be handled in parallel for optimization. + +For the EP controller driver to handle requests on multiple mailboxes in +parallel, ``pci_ep_doe_process_request()`` must be asynchronous. The funct= ion +returns immediately after submitting the request to the mailbox's workqueu= e, +without waiting for the request to complete. A completion callback provide= d by +the controller driver is invoked asynchronously when request processing +finishes. This asynchronous design enables concurrent processing of reques= ts +across different mailboxes. + +Abort Handling +-------------- + +The DOE specification allows the root complex to abort ongoing DOE operati= ons +by setting the ABORT bit in the DOE Control register. + +**Trigger** + +When the root complex sets the ABORT bit, the EP controller driver detects= this +condition (typically in an interrupt handler or register polling routine).= The +action taken depends on the timing of the abort: + +- **ABORT during request transfer**: If the ABORT bit is set while the roo= t complex + is still transferring the request to the mailbox registers, the controll= er driver + discards the request and no call to ``pci_ep_doe_abort()`` is needed. + +- **ABORT after request submission**: If the ABORT bit is set after the re= quest + has been fully received and submitted to the DOE EP core via + ``pci_ep_doe_process_request()``, the controller driver must call + ``pci_ep_doe_abort(epc, func_no, cap_offset)`` for the affected mailbox = to + perform abort sequence in the DOE EP core. + +**Abort Sequence** + +The abort function performs the following actions: + +1. Sets the CANCEL flag on the mailbox to prevent queued requests from sta= rting +2. Flushes the workqueue to wait for any currently executing handler to co= mplete + (handlers cannot be interrupted mid-execution) +3. Clears the CANCEL flag to allow the mailbox to accept new requests + +Queued requests that have not started execution will be aborted with an er= ror +status. The currently executing request will complete normally, and the co= ntroller +will reject the response if it arrives after the abort sequence has been t= riggered. + +.. note:: + Independent of when the ABORT bit is triggered, the controller driver m= ust + clear the ERROR, BUSY, and READY bits in the DOE Status register after + completing the abort operation to reset the mailbox to an idle state. + +Error Handling +-------------- + +Errors can occur during DOE request processing for various reasons, such as +unsupported protocols, handler failures, or memory allocation failures. + +**Error Detection** + +When an error occurs during DOE request processing, the DOE EP core propag= ates this error +back to the controller driver either through the ``pci_ep_doe_process_requ= est()`` return value, +or the status code passed to the completion callback. + +**Error Response** + +When the controller driver receives an error code, it sets the ERROR bit i= n the DOE Status +register instead of writing a response to the read mailbox register, and f= rees the buffers. + +API Reference +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: drivers/pci/endpoint/pci-ep-doe.c + :export: --=20 2.34.1