PCI: Add DOE support for endpoint
Subsystems (3)
v2 cover PCI: Add DOE support for endpoint
This patch series introduces the framework for supporting the Data Object Exchange (DOE) feature for PCIe endpoint devices. Please refer to the documentation added in patch 4 for details on the feature and implementation architecture.
The implementation provides a common framework for all PCIe endpoint controllers, not specific to any particular SoC vendor.
This patch series is the non-RFC version of the RFC series at
https://lore.kernel.org/all/[email protected]/
The changes since v1 are documented in the respective patch description.
A new patch (patch 3) have been introduced in the series. This patch moves the burden of initializing and setting-up the DOE mailbox from controller driver to EPC core driver, avoiding the duplication of code across the controller drivers. This patch adds APIs to the EPC core driver, which simply needs to be called by the controller driver during probe/cleanup if it supports DOE capability.
Aksh Garg (4):
PCI/DOE: Move common definitions to the header file
PCI: endpoint: Add DOE mailbox support for endpoint functions
PCI: endpoint: Add API for DOE initialization and setup in EPC core
Documentation: PCI: Add documentation for DOE endpoint support
Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-endpoint-doe.rst | 318 ++++++++++ drivers/pci/doe.c | 11 - drivers/pci/endpoint/Kconfig | 14 + drivers/pci/endpoint/Makefile | 1 + drivers/pci/endpoint/pci-ep-doe.c | 552 ++++++++++++++++++ drivers/pci/endpoint/pci-epc-core.c | 71 +++ drivers/pci/pci.h | 47 ++ include/linux/pci-doe.h | 8 + include/linux/pci-epc.h | 24 + 10 files changed, 1036 insertions(+), 11 deletions(-) create mode 100644 Documentation/PCI/endpoint/pci-endpoint-doe.rst create mode 100644 drivers/pci/endpoint/pci-ep-doe.c
Signature · 1 line
2.34.1
PATCH v2 1/4 PCI/DOE: Move common definitions to the header file
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.
---
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/[email protected]/
drivers/pci/doe.c | 11 ----------- drivers/pci/pci.h | 9 +++++++++ include/linux/pci-doe.h | 3 +++ 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/pci/doe.c +0 -11
@@ -28,12 +28,6 @@#define PCI_DOE_TIMEOUT HZ#define PCI_DOE_POLL_INTERVAL (PCI_DOE_TIMEOUT / 128) -#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 }; -struct pci_doe_feature { -u16 vid; -u8 type; -}; -/** * struct pci_doe_task - represents a single query/response *
drivers/pci/pci.h +9 -0
@@ -681,6 +681,15 @@ struct pci_sriov {bool drivers_autoprobe;/* Auto probing of VFs by driver */ }; +/* 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);
include/linux/pci-doe.h +3 -0
@@ -19,6 +19,9 @@ struct pci_doe_mb;#define PCI_DOE_FEATURE_CMA 1#define PCI_DOE_FEATURE_SSESSION 2 +/* 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);
Signature · 1 line
2.34.1
PATCH v2 2/4 PCI: endpoint: Add DOE mailbox support for endpoint functions
In reply to Aksh GargDOE (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.
---
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 specially, 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
v1: https://lore.kernel.org/all/[email protected]/
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
drivers/pci/endpoint/Kconfig +14 -0
@@ -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. +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" endmenu
drivers/pci/endpoint/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) += pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) += pci-epc-core.o pci-epf-core.o\ pci-epc-mem.o functions/ obj-$(CONFIG_PCI_ENDPOINT_MSI_DOORBELL) += pci-ep-msi.o +obj-$(CONFIG_PCI_ENDPOINT_DOE) += pci-ep-doe.o
drivers/pci/endpoint/pci-ep-doe.c new file +552 -0
552 lines not on this page · raw message
drivers/pci/pci.h +38 -0
@@ -690,6 +690,12 @@ struct pci_doe_feature {u8 type; }; +struct pci_epc ; + +typedef void (*pci_ep_doe_complete_t )(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);
@@ -700,6 +706,38 @@ static inline void pci_doe_destroy(struct pci_dev *pdev) { }static inline void pci_doe_disconnected (struct pci_dev *pdev) { }#endif +#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_offset, +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 -EOPNOTSUPP ; } +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 cap_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);
include/linux/pci-doe.h +5 -0
@@ -22,6 +22,11 @@ struct pci_doe_mb;/* Max data object length is 2^18 dwords */ #define PCI_DOE_MAX_LENGTH (1 << 18) +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);
include/linux/pci-epc.h +3 -0
@@ -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 };/**
Signature · 1 line
2.34.1
PATCH v2 3/4 PCI: endpoint: Add API for DOE initialization and setup in EPC core
In reply to Aksh GargAdd 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.
---
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/p57x6jleaim5w7t2k3v7tioujnaxuovfpj5euop5ogefvw23se@y5fw3che5p5d/
drivers/pci/endpoint/pci-epc-core.c | 71 +++++++++++++++++++++++++++++ include/linux/pci-epc.h | 21 +++++++++ 2 files changed, 92 insertions(+)
drivers/pci/endpoint/pci-epc-core.c +71 -0
@@ -14,6 +14,8 @@#include <linux/pci-epf.h> #include <linux/pci-ep-cfs.h> +#include "../pci.h" +static const struct class pci_epc_class = { .name ="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); +/** +* 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 functions +* 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_features). +* +* RETURNS: 0 on success, -errno on failure +*/ +int pci_epc_doe_setup (struct pci_epc *epc) +{ +u16 cap_offset =0 ; +u8 func_no; +int ret; + +if (!epc || !epc->ops || !epc->ops->find_ext_capability) +return -EINVAL ; + +/* Initialize DOE framework for this controller */ + ret =pci_ep_doe_init (epc); +if (ret) +return ret; + +/* Discover DOE capabilities for all functions */ +for (func_no =0 ; func_no < epc->max_functions; func_no++) { +while ((cap_offset = epc->ops->find_ext_capability (epc, func_no,0 , + cap_offset, +PCI_EXT_CAP_ID_DOE ))) { +/* Register this DOE mailbox */ + ret =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 cleanup +* if DOE support is available (indicated by doe_capable in pci_epc_features). +* +* 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
include/linux/pci-epc.h +21 -0
@@ -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 function +* 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; };
@@ -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, u8 vfunc_no,void pci_epc_mem_unmap (struct pci_epc *epc,u8 func_no,u8 vfunc_no,struct pci_epc_map *map); +#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) {
Signature · 1 line
2.34.1
PATCH v2 4/4 Documentation: PCI: Add documentation for DOE endpoint support
In reply to Aksh GargDocument the architecture and implementation details for the Data Object Exchange (DOE) framework for PCIe Endpoint devices.
---
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/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
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
Documentation/PCI/endpoint/index.rst +1 -0
@@ -9,6 +9,7 @@ PCI Endpoint Framework pci-endpoint pci-endpoint-cfs + pci-endpoint-doe pci-test-function pci-test-howto pci-ntb-function
Documentation/PCI/endpoint/pci-endpoint-doe.rst new file +318 -0
318 lines not on this page · raw message
Signature · 1 line
2.34.1