From nobody Wed Apr 1 22:13:35 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013005.outbound.protection.outlook.com [40.93.201.5]) (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 CA086391834; Wed, 1 Apr 2026 07:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028642; cv=fail; b=KXC9XTAMnOJOJBk/7GuM/2h2M6tgFbk4kNxs4ndBwZaqsswC9nNT7PPZafXCJYDzkMTK7BLx3mVcxt6hveOUjxX1shpOY5aE4VAUonFGwGF0/OuT102zw7+KW+5QxqpnH+BjN2ZJyDMnP5Gq4Ry0aykGg5NYnsuZB4IArFSWN/8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028642; c=relaxed/simple; bh=jNZAfKqhOMlUoJpOlWiJScp28OaPyI2i78phpqAhsRM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uwQfAmDiImyN2lFshmttcRwzMYmOtMG9noHHTGOc9C6zzwzZq+QHXtGw/kkUpfFRdCyNcbLkjZlIcpB8+s1AHFTwpq43NbRrGje9xEnSpZADhJqmaUF6UT1A+CjaF2e2z7rkGgdQ12cc7C0eM2gzOhleSYcERMw5fxcV+3g9tkM= 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=C7uA3xbG; arc=fail smtp.client-ip=40.93.201.5 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="C7uA3xbG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mpKuFoTTlzomWiDl2ESic474u5ZvlmuYHLEJs93v4hBMI1xe7wULiYvbltqqZuQ0+uopLumAbs+ktdKSZw97XutLeAaWHBpGFUQ39mWsDtGUoAMcK/5SrnCg5Q5M0aOEYyiVsf4nPhztmyCwXw3lGEpJPGrKpfwTHPTndHc/EbsnPGauInUFKqoqmwGmvWhv5f2sxOHL3pM/ZAexgBwM6fJvSdw5clPZMuDy3rSzKkimxIcgSHIqa5BNVRM0YjjY5S2neq6NR1/vsZnFXDdXkQM3r73MJT1xPX1TY/xsZO42xMyhamiqnj6sTtJXwJsIHBbdCIs2qzx20hvfdqtn9g== 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=/8OEV205hOziypl1nmJRGmEg0Pk/aozqrUUWMUkOv9w=; b=CwLwHV3zhKwNjYZrOn44wgZiYb8VEvtwF7aR9CdGk97KxE50ouUJnZdml+tx6XlJJ3/zWYHiSqA4/Kf0qbqaLUqGDhYInMMNeoRd0glXLEbHQ+DESrOgDUdcBET2ptw9oGOceZJWxqQnu32gHeSd46shxmP13KjDv8XITuANLQ1lijO8PmuNERCpONWyTd9tvc7Gtz1tF5cPYz9DB5W+Cjo5hr7sa3uzG0ulX5RewIFlZ4J54VeGNiwABeuMrtMxchhczd+9U7NSBIkeXBc/ZvnzCGI8uielTIuPRpCJ8OjNVcrmrieC/VFrVsLuz6YgPpbi2O+aRSHKLqmpOdlg7w== 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=/8OEV205hOziypl1nmJRGmEg0Pk/aozqrUUWMUkOv9w=; b=C7uA3xbGLzUG5rmqVIlCvVyhVm7Dwi5QYsU8hvovXaeVsrDg2UYXeeyiqwMCkdn+5iI6+WvM7e5SD6d5aWuCbHEphzimgFXKk9ka1vAbfoFdnWdtFWYvo3sfZ0LsB6PMgvUAh/x+nEfMVE3cyifQn1JKp/wJ03Iu6Jq/mxW8E0o= Received: from BL1P223CA0012.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::17) by MW5PR10MB5826.namprd10.prod.outlook.com (2603:10b6:303:19b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.15; Wed, 1 Apr 2026 07:30:37 +0000 Received: from BL02EPF00021F68.namprd02.prod.outlook.com (2603:10b6:208:2c4:cafe::2b) by BL1P223CA0012.outlook.office365.com (2603:10b6:208:2c4::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9745.30 via Frontend Transport; Wed, 1 Apr 2026 07:30:31 +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 BL02EPF00021F68.mail.protection.outlook.com (10.167.249.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.17 via Frontend Transport; Wed, 1 Apr 2026 07:30:36 +0000 Received: from DFLE211.ent.ti.com (10.64.6.69) 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.20; Wed, 1 Apr 2026 02:30:33 -0500 Received: from DFLE207.ent.ti.com (10.64.6.65) by DFLE211.ent.ti.com (10.64.6.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Apr 2026 02:30:33 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) 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.20 via Frontend Transport; Wed, 1 Apr 2026 02:30:33 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [172.24.231.225]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 6317UN3Q3832504; Wed, 1 Apr 2026 02:30:28 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v2 1/4] PCI/DOE: Move common definitions to the header file Date: Wed, 1 Apr 2026 13:00:19 +0530 Message-ID: <20260401073022.215805-2-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260401073022.215805-1-a-garg7@ti.com> References: <20260401073022.215805-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: BL02EPF00021F68:EE_|MW5PR10MB5826:EE_ X-MS-Office365-Filtering-Correlation-Id: d8bf949e-ab45-4752-5275-08de8fc09115 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|1800799024|36860700016|921020|56012099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: QnYsR+k0hTGagduKICOj88AEPCVtSkNg/6NyjjoF5tKaneWlhHVYIpM0jpHlEByCD3sBaYpMe4QgKcbkGzgNMZ3PRxQ8zXvGfb3DqhxgAHseY1u7Y83Ez3Zv+2IhF48wOFzsP2vpg2XZ8qDa91+d7AQ3VYo8CkqIx0UV/dzulpOZc0DIa+88MTtXklUdTrzqHMBQYNXvIMXvEgT3k4LLSFPtHNZV/JdGRJgi82N/oN8iZGwGMuKF747nVSvoonzI26myoZnvAfYzrPq0jf6IFagsHmmTpKbwCEEj3hBtVjuVy/16bOy2/K23OMULUO/uBzJRQ2JGqImE0OL0v6tD3rT2ok4RFF+7kzztMEDZIhP9QfN6Q+36YaWw6NzsdAIGz/ht1gDXJozZOdPyoZGkQ2nXVZ7a8eD+zHtojQijJzlk/3KB7saUPJymzvdbc8EynItjIakvzACEm8QbaFktdijwidzWUMJZd22Dl614HodGR8QBeNDgIiRsfqw1O+E+bJTKP6uOZ4U6PkPIVbtonjQFoOrQ2VpdPMgJvmMZa+yXAEQoPoY5WIe7s2RE/y5Ly2JxPHXuoVBJxrLvvYOT0Z08HBW5e9lY1WB3a5lwYdn9Uf4kIWOOnwMEBUZtNSqzIas9oAHKoYIYF60cYskGx8VznAE6eKT73jRU39t864gXklx5cJzCaJrO1k5TKq+zaSAXwYWQL24WQKyqoz1PYmV+XUQOExw3yrlSmrnLh+rVkDTpx0Fc9E2ctdiU6yjtKqpzgTTM6v9tSn1ypVEu2hNvB8Tci629FRNG3tP+q319RitiE1PyNQphsGB9uIoo 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)(376014)(7416014)(82310400026)(1800799024)(36860700016)(921020)(56012099003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aS6LAhxRx53RNyPfSfj+XoB83Xfcz4CHv8JocbC0PRB2AufYftbtlMB08V/X5fwljFheIh0NBkYYAbKQ/iRLho4e9S5cCnkteGEjavBpwfMRG6jOnb08K9EOy6/KVZwFwV11H8B0wadVr0H9uzH9D4XzhrkA9lhTH8BbCROqNMpjEpBTZpyqpAtDDiBywRFeDM0xzwQgzdPZe0Lp8GwsFryreepb2kAvv/MISBrZBnvCmaYLiavwyqBLuNm9iM7YQMQXvtNskqeowZ91YNqvxyzu3uYHGBp/r7gl406p+x7RPjir98ejNgIQtqBgCuHcgoOWvel4fFxGJI6HS/0aTSVusV/sWJI5aAE0tVe2swgTPSmRZmhV/SRwWPeoH6eoYNvAId06MHTsP0iAY54+hAPMcCqRB0Ifi/yVbkjLqsFZnvwjv5mbA0JLspNMMhF/ X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2026 07:30:36.2531 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8bf949e-ab45-4752-5275-08de8fc09115 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: BL02EPF00021F68.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR10MB5826 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 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. 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 13d998fbacce..66b7ec80f46f 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -681,6 +681,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 Wed Apr 1 22:13:35 2026 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012007.outbound.protection.outlook.com [40.107.200.7]) (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 73313396D2B; Wed, 1 Apr 2026 07:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.7 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028653; cv=fail; b=CYvWHWksJ1AwkVkVvMYgMVSjFaI6srjE6CYkWUAxm6o7DYmfcrzuZjc1NjbJgvaLlZly+LDpH2qX6l/4NQP9SlLEoOuT5eeR//yjpk1hEbSIaCmQvkWY4s6ckDY7GbBE4LBPPg4oNRzDU6fc74C67K57/1EGAkwq3zVScC0zEz8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028653; c=relaxed/simple; bh=0HzB0n+arXL6t2KuYiD02CH4uf6wtzDS9DQSFddQSTA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MCweKctwRoKNvxLfinN5BVEB6OBOuQB2VA53HdxhIMD1kDFIqXTz1I4suM68mGaYgcttcULrj8Ux8e1D1ci/gaCBf9Wn7kKKqjiOw4Goyy4MUsUW1B8d+b+/nkxkYzackUcIIvNAlQoErwQM7LK80ILp3+VZTuRSu6aUCmcHCgc= 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=nf8Jj+m4; arc=fail smtp.client-ip=40.107.200.7 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="nf8Jj+m4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ar8+4gOY2XR1JDvzBMg6LT8DfJYcEb37r14/SLHsjWDPhzRpkYuE7ssEGoeQFV3KMfliyvRfJBel2IDqUDHnQFNwDF+HiqXHq7Q11PSUc0XkdOeUDV+3X87JTJdZnOxcgvwLFA5y4/2HTmbUQ8m0G8sx19Bwmk59/49SRmAPGSVMe+bfm/ZAlxUbSAX19A9SmyMw4PZveJoXCp//iKqMNvCxWbwyInCb7PfEXzoWbWAUD/QhHB+ufayH3tJ6MYlDtLABS2SOBudRIbPh7SGzn+P+4W4ys5qFe3kCEuNNrdhW1aVIuQXKP3hAr30Mw4Pi1UK7osiC+AkDpvkGhiFiWQ== 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=bFcn9Vxo4lGgPt20VnXBB3wQ1onkpxIBV9SkXwzmenU=; b=nSymMRcc4aoRMdecx5eW4KGZU0y8c1FLsXuUT2pAhjg8ENfLQU6hxrE7JVY7NRev7hHR42kSNmU6RjnMU/4F2LJ7LmNrlmrfihtufKbVWnpJtRKb+NwijUr3cmBLCdKLlx0PknJpThxZq5YeCbdwhY5a+lHbq3Zm0kDLdlSJkNRCZp389yoiJSF+yhL7uqFozfeM9fZ39JPArVoUko6HQ8Cnqin7kClD5Z5021pdEytaA7nuY6ARiAoQkBtq7g40Vq6YxUSQ5Mf9KhB3ydFDqlvUQNrbq6g6xey/G7XPsQPXN7dnfkk8hvNsjm9Ryxx8TQ4aKgrKLR4q4XbAnWyK1Q== 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=bFcn9Vxo4lGgPt20VnXBB3wQ1onkpxIBV9SkXwzmenU=; b=nf8Jj+m4tudURpDDr0tjXGwtvE8H6w6ckmAGP/QpAnF+7z0ZlhyFNE7yE7AtCbRIUMDmUFWieC7MHPOKzntf9c3o2vL/vlgZAy5f/7lBEvBwrrJSKTu4Vrphd5/EGlEgdCHHn1vpB3yxMxJcwM4qglw3IBUs2XlL/O0UgqZ369g= Received: from BYAPR03CA0031.namprd03.prod.outlook.com (2603:10b6:a02:a8::44) by BY5PR10MB4243.namprd10.prod.outlook.com (2603:10b6:a03:210::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.16; Wed, 1 Apr 2026 07:30:48 +0000 Received: from SJ5PEPF000001E8.namprd05.prod.outlook.com (2603:10b6:a02:a8:cafe::c6) by BYAPR03CA0031.outlook.office365.com (2603:10b6:a02:a8::44) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9745.29 via Frontend Transport; Wed, 1 Apr 2026 07:30:48 +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 SJ5PEPF000001E8.mail.protection.outlook.com (10.167.242.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.17 via Frontend Transport; Wed, 1 Apr 2026 07:30:47 +0000 Received: from DFLE210.ent.ti.com (10.64.6.68) 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.20; Wed, 1 Apr 2026 02:30:38 -0500 Received: from DFLE211.ent.ti.com (10.64.6.69) by DFLE210.ent.ti.com (10.64.6.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Apr 2026 02:30:38 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DFLE211.ent.ti.com (10.64.6.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Wed, 1 Apr 2026 02:30:38 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [172.24.231.225]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 6317UN3R3832504; Wed, 1 Apr 2026 02:30:33 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v2 2/4] PCI: endpoint: Add DOE mailbox support for endpoint functions Date: Wed, 1 Apr 2026 13:00:20 +0530 Message-ID: <20260401073022.215805-3-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260401073022.215805-1-a-garg7@ti.com> References: <20260401073022.215805-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: SJ5PEPF000001E8:EE_|BY5PR10MB4243:EE_ X-MS-Office365-Filtering-Correlation-Id: e40a16df-e489-4d3a-cb60-08de8fc09791 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|36860700016|376014|82310400026|1800799024|921020|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: Y3BiW5GWzA9bWJaMGObVAcGe1uyjGa655pXwVOyLt1E5lni1fNQdcEe4o146bHSPhmzTJ1N5te7N1ffWy5zeD2E7NsFNywHSLwvO4+Mjg0VTLMOnYuJNaYZSQn1+ngcVLb01OzL1nMVezV4JpP8zSbl307bJR1+17GG6l3XC1i3BG4X6fJmWa4icEy3i+srTtPaPG/TBLkHm/GLs8N0kZEAMSmTfyg/ibzK91ozaoRG3cYNY6l2/DTCUknfgOt9/8vRCUOTqdUwXul3z3uGC0+8bNZi90fj6iV5x2of6sLTunTW51Ij4SEbWzr4inQ4DLMPSmBC0dLQdF2NfeTlnEvLVceFPQtVYd7jBHuBSfQctulsmriere6jIdIKhJBR5PH9vzlvXmCEGOxoZsH4v7oF9PP0fdTcwxedAp7H+lUrkl4vRfDeP7yiek/rZu0yggkp0jlUhbvDYugxWeeRF2/+P7Jib8On5F4W33WieEfRf30RATxmq0x3yXkQwRjS0xnx+V0VzapKnpp5RaoOW01O+9mT/eoZIsqNj+U5PTFvWLuYYLAGMlRm93xv9dKhTMI73ygob3AvRS3WMg4vvISZ1NkjddoANOP/LYMtzS2zGyw87mdhAr7ZrbHyKq/VZcIV7Q7TDL28R0t33jv7lKTW4ecply4eSO9JdkqDRKVT+hIa44/Xi57xkgrdl1qLFRO0xJViW2KNi1pVmR+bzr0PSJcNjQmy59lT0Cp1mdKH2WW+wTAJQU1qL2Nc95kJkTtRpoDAVL1/nRNFAjZSV2g== 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)(7416014)(36860700016)(376014)(82310400026)(1800799024)(921020)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D+/1HxQ3EKaOkMaUvxlsnRg7A1pRA3G0keca2hUiGkTYX58mO+ie86iI810cW0T0I+yDLeTSy5cXbI6v5gmoqU/SERFVAgHdmOTFLFThzuX2Lt2bkyauuI2naM/aEPo2Osv5oBg7g6gWE0MkLXrFDPAJFTIk5nSfj1UYd7t1KFAf8oElD3hCr/w7WwOYDhG88D580/lM1VV63PWHY4tIEnvJTRdJz5pglJSuziydOTw7afQo/SmrRZJF4rz2a0c6M/dDIVnprwH/JcSdpjxlEVXE+fPTZdDmV95aPT71J/rVx4vG1rX4YHAgh+YW2usl5DKfKrZLbMjUyV/w9SHot058ER3pxu4n2+/1v2gwco09ecW90GO+p2C7moLq6nIroBeeO9YWIZkDeINibaIVzbmo6meGNvRyxgXvp+1ZeXXGDY8ywSNQibXAZPwpeXF7 X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2026 07:30:47.1221 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e40a16df-e489-4d3a-cb60-08de8fc09791 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: SJ5PEPF000001E8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4243 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 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=20 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 | 552 ++++++++++++++++++++++++++++++ drivers/pci/pci.h | 38 ++ include/linux/pci-doe.h | 5 + include/linux/pci-epc.h | 3 + 6 files changed, 613 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..ded0290b15ed --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-doe.c @@ -0,0 +1,552 @@ +// 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 through an API. The API is invoked by t= he + * controller driver during initialization if DOE support is available. + * + * 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->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). The pro= tocol + * handler 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, const 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 through an API, invoked by the controller + * driver during controller cleanup to free all DOE resources, + * if DOE support is available. + */ +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 66b7ec80f46f..456e0717dd54 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -690,6 +690,12 @@ struct pci_doe_feature { u8 type; }; =20 +struct pci_epc; + +typedef void (*pci_ep_doe_complete_t)(u8 func_no, u16 cap_offset, int stat= us, + 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); @@ -700,6 +706,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, const 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, + const 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 c021c7af175f..cfe74585be4c 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 Wed Apr 1 22:13:35 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011056.outbound.protection.outlook.com [40.93.194.56]) (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 09288398904; Wed, 1 Apr 2026 07:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028656; cv=fail; b=FC0lkeSXW8U6BIoZ8cFO8Fa14q+baOQFrDj78sdQFa80IDifd18VJ2TOLQMboBFhZ8Lxark75hR1KcYObvuyoScmaUkspYGCiWhJLQWHpIAPfL/eRD3w0da3q2hoW+pyeEgk/a6e9z246cdZNqPfEmJzqHuUzOkuhL533imijlU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028656; c=relaxed/simple; bh=qaGRda44yb7zWAtrGphW2mY1sqlvMrXAAeYvF4T2S7Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DipoBRcT9BTbtnFTb5sT/OWScfPwGgVTE4zM8RIEBCVveO9/+Mdfsy31zSURXLOMbNQjc2JYrOf1Ds5bfr87w0Qf/4vaKeX/MghjZIHUhnj8XRhDP/pGtCVXF/UJCDzk3Os6gpyRd/qNXoL1+/z6T7y6eNiB4oU45BNe6guv+8w= 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=cqh+fBLI; arc=fail smtp.client-ip=40.93.194.56 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="cqh+fBLI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DKKAiO33B9rSJWSdQhT8l88jrc7N33ZJEocIUEwQgC5eujkybyAKVPCXSBh+Y5a0QxDniGsnrNxGHpTPTTY0xqZX+vU63VuKrmnb1aqShmfbsW1VgHYMcEiFYo3NyGdRHE9tzheQ/2Utvd8664yy4I2DOGvTV05SjpgIvq9KFhqQh/rXGLYCqKlyfdt9tLEM9OnIhAx1C4V01xRKWq7J21IQTcucUUQsBMX+T7Ffc84tpsG4exKP8qe2uGzdo/de7huxo81/S34EVk0/jbPT1V1LSU6Yio3RSs3oe/Kjjsi6+du24JeULcFU0lzJVFETRsm6NvJaeUvhzAp2LpwBww== 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=p+2nVL+oNEhLJODV/d5g6MEA/ciHlVTCNd0iT3/WNeQ=; b=uHrHqiRPSFCk9YqtDbnaAUeaHcDr/z3zfQ8hRO/YRkM0Nkjpzy/aV1eIZOhorZCb0Y3CALfdy2ZTKIclcd1l4xgcuRcUwMONHK0C5gvHMGrVyUt2Q/1+dIcrCLGaASJ8mWAgaVFRt8oJMOsQtybc+Dsq/qLKeq8gG8OUPVBz8q+CiOKocnAT4dhK7TyJQYNzrDS7ZxM5B7vjr4V4c5S+rXP2VsWSbX8Z7Wm91bNvQp+dnuZsyg6AWzkqjTNeg69ZFVrb7mxe3mvUo+CkgCDpXQCsByelEryssOndYGUGH3Rk6C7urUeE1ohZW5KjL+FIzW/cBeuDdWUEq8/nMBFJ4w== 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=p+2nVL+oNEhLJODV/d5g6MEA/ciHlVTCNd0iT3/WNeQ=; b=cqh+fBLI3lwEG3mawvx+RtFPUIZFcH9xV8c6rtzAkrOAvL5CSwWdcWRsO5g6jIbcHtkrbngQfix5y33vsd3Rp7/lpPsnKj4o4KwamDcgr3El0lK5cA+/jp2CPKrfzePatGc+nIzBU2xsbi80+Eg8/yMrE+ErE3b6fFukRvCJJ5s= Received: from BL1P223CA0001.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::6) by SJ0PR10MB5663.namprd10.prod.outlook.com (2603:10b6:a03:3db::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.28; Wed, 1 Apr 2026 07:30:50 +0000 Received: from BL02EPF00021F68.namprd02.prod.outlook.com (2603:10b6:208:2c4:cafe::23) by BL1P223CA0001.outlook.office365.com (2603:10b6:208:2c4::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9745.30 via Frontend Transport; Wed, 1 Apr 2026 07:30:52 +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 BL02EPF00021F68.mail.protection.outlook.com (10.167.249.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.17 via Frontend Transport; Wed, 1 Apr 2026 07:30:47 +0000 Received: from DFLE207.ent.ti.com (10.64.6.65) 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.20; Wed, 1 Apr 2026 02:30:43 -0500 Received: from DFLE205.ent.ti.com (10.64.6.63) 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.20; Wed, 1 Apr 2026 02:30:42 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DFLE205.ent.ti.com (10.64.6.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Wed, 1 Apr 2026 02:30:42 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [172.24.231.225]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 6317UN3S3832504; Wed, 1 Apr 2026 02:30:38 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v2 3/4] PCI: endpoint: Add API for DOE initialization and setup in EPC core Date: Wed, 1 Apr 2026 13:00:21 +0530 Message-ID: <20260401073022.215805-4-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260401073022.215805-1-a-garg7@ti.com> References: <20260401073022.215805-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: BL02EPF00021F68:EE_|SJ0PR10MB5663:EE_ X-MS-Office365-Filtering-Correlation-Id: ff52b391-d837-4e75-77a0-08de8fc097fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700016|82310400026|1800799024|921020|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: d7qWoi4qjfygrTUtlRMgyRW0QDv7rNt+sM/KqzqEajxg93a8Ai4c7Mu8bXy6P9PpbkLeWpjXYFv+K2t2t7V3obntYutgsGFYueY4TafFFSVhm+FWA7bi67MrVce8R6+PCr2nHgbnoVQlWgdk89jId+PAVcGtpPCWlc7GbAdEI7kioH+276Ka/bmBBjKuWovwOnAyaKABpI9rLmPDZncVd+vokdaOwDHMt86phIDpm/NQlc4nFmpmoT4nzLGdzPLmUovQ/x56/4PwQJ9/f3LNYIwXEPQ3cgLvUJnghIJv4Jc3MKwRukW4dp6n9InLdyyegiajd4+wc+xDuDmz+fOhdbqmFuVGh57C92LSxCKH5uOcSECxCOcccQPs9UZQzLhU5B2BgzuY19d62rWHmwzH8wWxnUK+FrqjGxafmw8z3N4P/jZdwmu598MCGE3/1iw/l5PrAT0P3SWAhHOKXzcPjBca5TeJuirRfHkrglJsnaWnT4aPjIxq0oS/IqubP8Q/OhzSiWEWFT4NTwfuqhV72FTWz7bPgVyZsmlG79S+y5+rHrH99py/5l6giuOFvYl6XMt4CeTfrecB2cfBBvY0MLSZkydS6RaeU/kgnX88MWRu9lqL+GiO+26HBcvE8vM1w0tpIi93rd/kLCBoqPf2UTxwRxhGjnWvZJAT6F4jlgYK2bpdCU+Kav2FdEdhINzwI1mS8UziWJpvl1Ov7pE4r2AkMRD26PQCMTC6oXx7b04Fk5CjknIcZSkDtGCIwX1kzMpWGqWvYbhdc/PQvC/skOjlrx/ebLkoV1aEbgfZYrsFYOUHNV3gCg0Bzzd0afS0 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)(7416014)(376014)(36860700016)(82310400026)(1800799024)(921020)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xlsUEPXZS7o3gmQ+21Zmpc3il7VohY29DugOeE1u19YspzMXPbwfizG9D8bmjqKIBqFrWSGGDidEN67cthcYm6f7xpIHZ36oAiMceAR+hsKI5p2tXrDeQmlwU37PtDmWCFGm7+biXcb0ndTQ3tFjMeN7NdWg2Iz3nc5WS64ql4lP5cnc2UIyrUQuYCe8AgApiqUVXgLKvE9x91x1oYVKDbyJL+kt38VxRvCGuxM7rDR7IAyMkhJB7Ima6QjWIuKZaH4Va4AE996gFl9FJ/evz8tnaJvM6mJoYd0sg+0EDA4XjJkCGFTcxm91jGP0t1hmSHoZFEiD4bkicdw030sT36PnV4ja6dvIsiRLuinxCnqpwMCQvaWdWsnFsXoU9nlsLBTugRPO6xm4jxHhmalKR/tSpIdP7SCFwqTN1lHPE3vPzNbzAis3QpKqVd8rnJ3E X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2026 07:30:47.8566 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff52b391-d837-4e75-77a0-08de8fc097fe 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: BL02EPF00021F68.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5663 Content-Type: text/plain; charset="utf-8" Add pci_epc_setup_doe() API in EPC core driver to initialize and setup the DOE framework for an endpoint controller. The API discovers the DOE capabilities (extended capability ID 0x2E), and registers each discovered DOE mailbox for all the functions in the endpoint controller. This API should be invoked by the controller driver during probe based on the doe_capable feature. Add pci_epc_destroy_doe() API in EPC core driver for cleanup of DOE resources, which should be invoked by the controller driver during controller cleanup based on the doe_capable feature. Co-developed-by: Siddharth Vadapalli Signed-off-by: Siddharth Vadapalli Signed-off-by: Aksh Garg --- Changes since v1: - New patch added to v2 (not in v1) 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 | 71 +++++++++++++++++++++++++++++ include/linux/pci-epc.h | 21 +++++++++ 2 files changed, 92 insertions(+) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci= -epc-core.c index e546b3dbb240..14f77dd0877b 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", }; @@ -547,6 +549,75 @@ void pci_epc_mem_unmap(struct pci_epc *epc, u8 func_no= , u8 vfunc_no, } EXPORT_SYMBOL_GPL(pci_epc_mem_unmap); =20 +/** + * pci_epc_doe_setup() - Setup and discover 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. + * + * This API should be called by the controller driver during initialization + * if DOE support is available (indicated by doe_capable in pci_epc_featur= es). + * + * RETURNS: 0 on success, -errno on failure + */ +int pci_epc_doe_setup(struct pci_epc *epc) +{ + u16 cap_offset =3D 0; + u8 func_no; + int ret; + + if (!epc || !epc->ops || !epc->ops->find_ext_capability) + return -EINVAL; + + /* Initialize DOE framework for this controller */ + ret =3D pci_ep_doe_init(epc); + if (ret) + return ret; + + /* 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_err(&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; +} +EXPORT_SYMBOL_GPL(pci_epc_doe_setup); + +/** + * pci_epc_doe_destroy() - Destroy and cleanup DOE mailboxes + * @epc: the EPC device on which DOE mailboxes has to be destroyed + * + * Destroy all DOE mailboxes registered on this endpoint controller and + * free associated resources. + * + * This API should be called by the controller driver during controller cl= eanup + * if DOE support is available (indicated by doe_capable in pci_epc_featur= es). + * + * RETURNS: 0 on success, -errno on failure + */ +int pci_epc_doe_destroy(struct pci_epc *epc) +{ + if (!epc) + return -EINVAL; + + pci_ep_doe_destroy(epc); + dev_dbg(&epc->dev, "DOE mailboxes destroyed\n"); + return 0; +} +EXPORT_SYMBOL_GPL(pci_epc_doe_destroy); + /** * pci_epc_clear_bar() - reset the BAR * @epc: the EPC device for which the BAR has to be cleared diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index cfe74585be4c..07fa41a8e466 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 @@ -236,6 +240,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 */ @@ -246,6 +251,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; }; @@ -334,6 +340,21 @@ int pci_epc_mem_map(struct pci_epc *epc, u8 func_no, u= 8 vfunc_no, void pci_epc_mem_unmap(struct pci_epc *epc, u8 func_no, u8 vfunc_no, struct pci_epc_map *map); =20 +#ifdef CONFIG_PCI_ENDPOINT_DOE +int pci_epc_doe_setup(struct pci_epc *epc); +int pci_epc_doe_destroy(struct pci_epc *epc); +#else +static inline int pci_epc_doe_setup(struct pci_epc *epc) +{ + return -EOPNOTSUPP; +} + +static inline int pci_epc_doe_destroy(struct pci_epc *epc) +{ + return -EOPNOTSUPP; +} +#endif + #else static inline void pci_epc_init_notify(struct pci_epc *epc) { --=20 2.34.1 From nobody Wed Apr 1 22:13:35 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010026.outbound.protection.outlook.com [52.101.201.26]) (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 B44D5397E9E; Wed, 1 Apr 2026 07:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.26 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028655; cv=fail; b=b4EnU8rvRxwcwSJNRn0HyhgueU2UraJj/IInVyxWG7Qt3lZ1ekT4+wpqZxMO1J63Ywg15k/jBDavPgxfS5CELZJOhE4U9hoZYJmqzSxMP/mD+Jkk7WJidKdM1HyJwpewrrwgFAADoRQZq9dzX25qZs6YSNAY4uJ0QDeOwLl7JII= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028655; c=relaxed/simple; bh=n3mSuPTxG7RpZyPt2jFJiYIKdb+tlzjKhmB04SSGMSI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cc7Ywqk4L7aCEUZENijKGdcXFzI9WRGuvnL7q6HsZK7wtu/MUUZOeZdF3FzffNxGH5sRabGtlbIxa4UIBgec5euq1SRoLY6IABWXCyDTUBucj5LimivIVom2jogOaJTQQmiAJHdO/OcojAMC4r35M+//BDPNAr6TzQ9s/pvH+4w= 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=FrNRs5CK; arc=fail smtp.client-ip=52.101.201.26 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="FrNRs5CK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rW7sq83J6La+HXYzrHURVSxjwTcxh5oDtr6r/sf4J+DsFTryDPubSN+lZbE5BMzZFE50G7ZwLDU8d1oFl6AHZUckQ4UADS8Px5rSx/Zse/dgF5rzx5xPPwESIw3DWW5uN610He8N6Ubc0u9YEv7rGj7kGxohPF/zjwhjftrZS14eM74GjDDqjOlfSWlVEV4zakec4J970iWIfrkT6ft1A5DK9yq4rYZX4eDWvlzlJnlS29KgXtFr43YYFGy/i5hxXrRVvklbEwy21/i8tGNevak+MlOJB6H0ZhDhSqpiVPSu+LXliwsoqflO3AOH46m92QTJgzgKTm+e4IoKu0SvVA== 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=JjpNCIGW+5eeZlYd0i8dzEEOmb+0Z81fHNYsUKvTnZQ=; b=YBFi8tOH5+jOl4IZNvnetZH8VkgyHdNzt+5odRUL/zi8ZbszqHAJUaY2B0M5PeXv48zTzDLf6I26TVS0WEIEGZOTz0DtZWgNdHePNp73raA9GqD2JD35JxIN/A7Z5RbbEp9bKNEqEDQTvcef+G9IRn1ownc+nK3l3/JLZ7u4HFDwMDyJB2vFW6aXlYYon8lUrRTIsQNuetdErxUJ0x94rS/tiTu3eF4llUb2Hd/QjgoDvkzjX/t+owPrhI3i68U/2cFZwOt2g2jtdow+whtIz+oAGzD+gt/+EXmB4E8ISHXCjM+ezHjOMVdo7ZdK2VzJ7zpjkmXR2KHPTPpRQPmsdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.23.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=JjpNCIGW+5eeZlYd0i8dzEEOmb+0Z81fHNYsUKvTnZQ=; b=FrNRs5CKIQCipiE4VSmxUgvj6Y4/xmSuzK08pA/PH64jO1iDpeWt3TbU6H2LH2j5MixQC/arIQvIIhFtfMifhIovL/63fx4JpIf0tSESFxRvv3OrfEMThOASDk+4jJAFhB8/zIoQnhDTddu648lryKuQMV9dOwyPVt93GxMAtV0= Received: from BYAPR02CA0063.namprd02.prod.outlook.com (2603:10b6:a03:54::40) by DS0PR10MB6078.namprd10.prod.outlook.com (2603:10b6:8:ca::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.28; Wed, 1 Apr 2026 07:30:49 +0000 Received: from CO1PEPF000075F1.namprd03.prod.outlook.com (2603:10b6:a03:54:cafe::19) by BYAPR02CA0063.outlook.office365.com (2603:10b6:a03:54::40) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9745.29 via Frontend Transport; Wed, 1 Apr 2026 07:30:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.23.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.23.194 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.23.194; helo=lewvzet200.ext.ti.com; pr=C Received: from lewvzet200.ext.ti.com (198.47.23.194) by CO1PEPF000075F1.mail.protection.outlook.com (10.167.249.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.21 via Frontend Transport; Wed, 1 Apr 2026 07:30:49 +0000 Received: from DLEE207.ent.ti.com (157.170.170.95) by lewvzet200.ext.ti.com (10.4.14.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Apr 2026 02:30:47 -0500 Received: from DLEE202.ent.ti.com (157.170.170.77) by DLEE207.ent.ti.com (157.170.170.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Apr 2026 02:30:47 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DLEE202.ent.ti.com (157.170.170.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Wed, 1 Apr 2026 02:30:47 -0500 Received: from a0507033-hp.dhcp.ti.com (a0507033-hp.dhcp.ti.com [172.24.231.225]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 6317UN3T3832504; Wed, 1 Apr 2026 02:30:43 -0500 From: Aksh Garg To: , , , , , , , , , , CC: , , , , , Subject: [PATCH v2 4/4] Documentation: PCI: Add documentation for DOE endpoint support Date: Wed, 1 Apr 2026 13:00:22 +0530 Message-ID: <20260401073022.215805-5-a-garg7@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260401073022.215805-1-a-garg7@ti.com> References: <20260401073022.215805-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: CO1PEPF000075F1:EE_|DS0PR10MB6078:EE_ X-MS-Office365-Filtering-Correlation-Id: 00aa032d-c486-4fcc-8aed-08de8fc098c9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700016|376014|7416014|921020|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: iKosfNV6v/7y1xUkJwPTOMa3ke3l6mPrbEwBsePXuoS3OL+UeqzY+1cJR9VxyOTnoEe6SqGmWCTGDDZzwB0U4YDuX1o7rKGjiejIT5CA0PTW7RRqIRR0Kaqwk27s+CZ6u6Mk+FDLNncuoNR2jU90iPmF+/Nisxp9v46DGqIC3pnOX5Wh2LJ9Yw++cL0CswD/7u+5foxN7v5FgeFYkE48ne1tgaJw57wWaT/MFlpGJ+lFw/UiLGQfC1Lq+TFdQIMobYs8VbqYoX0G76bAb7L8zKa0gUhdOXQK80FpYxC3vY2SmjBydrclnel69F8kXd3MbsvocVYFflK32v3e91dqgH+G00nlUEr/ahYdld4XkV6/RU+cdp6mQ3t0wTmrTi23hSXa1FAheF3ZUAba5dILipdAfWxEG+nW56k1XYQVjgog3n/wBAQE322KCaFFideRA0RKPmp0Jm2YCEwxY7NrskZO24lm/sNYOWPH4USJvDt9CSJ0So0R2c1Vify3PXZB19CQwPWZStVpRoe6NaIN9a7vmxpEZqGbbfsFyhH0uic/4TBTNj3/Tf2AZxG3z1K0wuXoPG727O49gqRx37hLZpxylUtGBxMx9QUHRBc4/SLOR4V6saZ69N1fqoaOfPgqPfY/gApDufFV78q7gkfa/d0sCjry1LTY+vonvDkjSvGEHEx7oBNrNm0V1k9EmAY7iRGL4aIynFIE5k+n9w90Ghn6IEx4jh7ySGGtqrbwG1HPsKzyKwzW5PJfl3hf96gxVP755Adyc4iOMbAg5l+hEjgTsGivn6gveYyhVEYUvBQcZTxTn61Q3KdvyPlri8naWW90iPNDi55/PPgDF/6OPg== X-Forefront-Antispam-Report: CIP:198.47.23.194;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:lewvzet200.ext.ti.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700016)(376014)(7416014)(921020)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: REHBLYleCkFi//ho229oNCJl9tNWh02h64jvoIb2lTZpTkCkeT4czfmH5qSUrKS34Kbjrw1+OrcLz+NudbqIuRFaes6OMAjD/acdmjEiIWUn6gQqfMEgts58a9Yq/Lfai1ftaAIFUupFARS84Dobw9aD31ER1Az7azVKO+2pxoR8fYdmmvvRB48Jgo3eX+Ht3Ch+pMDQzvW2s6noh8rFyn88n+85D11ZhAmTTmqOfJqhkzS6vhX4/rxsgjMSUHpOmPUkFi2q2LUDMlzA0UswbS06u6oAgduQKOStdzJMpbiru0C7oziTE2gDI5XCo89ESFNpCuU0WfjvUymZJYAz4HcCtF8rFGSAkJUjh2F4rGU1GrwKNM5LHQQZip3rsha7XdxT0qduvsTxkT8wYp0yXE/rEW5LeLxS0Q3Fzk3kZs6WXEN1JfP3ED3sMXqpNK/8 X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2026 07:30:49.1758 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00aa032d-c486-4fcc-8aed-08de8fc098c9 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.194];Helo=[lewvzet200.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075F1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6078 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 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 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 | 318 ++++++++++++++++++ 2 files changed, 319 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..03b7a69516f3 --- /dev/null +++ b/Documentation/PCI/endpoint/pci-endpoint-doe.rst @@ -0,0 +1,318 @@ +.. 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 Status = 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 256KB (2\ :sup:`18` = dwords). + +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 provides the ``pci_epc_doe_setup(epc)`` API for centralized D= OE +mailbox discovery and registration. The controller driver calls this API d= uring +its probe sequence if DOE is supported. + +This API performs the following steps: + +1. Calls ``pci_ep_doe_init(epc)``, which initializes the xarray data struc= ture + (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. Discovers 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 ma= ilbox. + +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 provides the ``pci_epc_doe_destroy(epc)`` API for centralized= DOE +cleanup. The controller driver calls this API during its remove sequence +if DOE is supported. + +This API calls ``pci_ep_doe_destroy(epc)``, which destroys all 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)(u8 func_no, +u16 cap_offset, int status, u16 vendor, u8 type, void *response_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 function number, capability offset (to identify = the mailbox), +status code indicating the result of request processing, vendor ID and typ= e 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