Add support for Silicon Labs CPC
Subsystems (3)
cover Add support for Silicon Labs CPC
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Some of the devices support several protocols in one chipset, and the main raison d'etre for CPC is to facilicate the co-existence of these protocols by providing each radio stack a dedicated communication channel over a shared physical link, such as SPI or SDIO.
These separate communication channels are called endpoints and the protocol provides:
- reliability by retransmitting unacknowledged packets. This is not part of the current patchset
- ordered delivery
- resource management, by avoiding sending packets to the radio co-processor if it doesn't have the room for receiving them
The current patchset showcases a full example with Bluetooth over SPI. In the future, other buses should be supported, as well as other radio protocols.
For the RFC, I've bundled everything together in a big module to avoid submitting patches to different subsystems, but I expect to get comments about that and the final version of these series will probably be split into two or three modules. Please let me know if it makes sense or not:
- net/cpc for the core implementation of the protocol
- drivers/bluetooth/ for the bluetooth endpoint
- optionally, the SPI driver could be separated from the main module and moved to drivers/spi
I've tried to split the patchset in digestible atomic commits but as we're introducing a new protocol the first 12 commits are all needed to get it to work. The SPI and Bluetooth driver are more standalone and illustrates how new bus or radio protocols would be added in the future.
[1] https://www.silabs.com/wireless/gecko-series-2
[2] https://www.silabs.com/wireless
Damien Riégel (15):
net: cpc: add base skeleton driver
net: cpc: add endpoint infrastructure
net: cpc: introduce CPC driver and bus
net: cpc: add protocol header structure and API
net: cpc: implement basic transmit path
net: cpc: implement basic receive path
net: cpc: implement sequencing and ack
net: cpc: add support for connecting endpoints
net: cpc: add support for RST frames
net: cpc: make disconnect blocking
net: cpc: add system endpoint
net: cpc: create system endpoint with a new interface
dt-bindings: net: cpc: add silabs,cpc-spi.yaml
net: cpc: add SPI interface driver
net: cpc: add Bluetooth HCI driver
.../bindings/net/silabs,cpc-spi.yaml | 54 ++ MAINTAINERS | 6 + drivers/net/Kconfig | 2 + drivers/net/Makefile | 1 + drivers/net/cpc/Kconfig | 16 + drivers/net/cpc/Makefile | 5 + drivers/net/cpc/ble.c | 147 +++++ drivers/net/cpc/ble.h | 14 + drivers/net/cpc/cpc.h | 204 +++++++ drivers/net/cpc/endpoint.c | 333 +++++++++++ drivers/net/cpc/header.c | 237 ++++++++ drivers/net/cpc/header.h | 83 +++ drivers/net/cpc/interface.c | 308 ++++++++++ drivers/net/cpc/interface.h | 117 ++++ drivers/net/cpc/main.c | 163 ++++++ drivers/net/cpc/protocol.c | 309 ++++++++++ drivers/net/cpc/protocol.h | 27 + drivers/net/cpc/spi.c | 550 ++++++++++++++++++ drivers/net/cpc/spi.h | 12 + drivers/net/cpc/system.c | 432 ++++++++++++++ drivers/net/cpc/system.h | 14 + 21 files changed, 3034 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/silabs,cpc-spi.yaml create mode 100644 drivers/net/cpc/Kconfig create mode 100644 drivers/net/cpc/Makefile create mode 100644 drivers/net/cpc/ble.c create mode 100644 drivers/net/cpc/ble.h create mode 100644 drivers/net/cpc/cpc.h create mode 100644 drivers/net/cpc/endpoint.c create mode 100644 drivers/net/cpc/header.c create mode 100644 drivers/net/cpc/header.h create mode 100644 drivers/net/cpc/interface.c create mode 100644 drivers/net/cpc/interface.h create mode 100644 drivers/net/cpc/main.c create mode 100644 drivers/net/cpc/protocol.c create mode 100644 drivers/net/cpc/protocol.h create mode 100644 drivers/net/cpc/spi.c create mode 100644 drivers/net/cpc/spi.h create mode 100644 drivers/net/cpc/system.c create mode 100644 drivers/net/cpc/system.h
Signature · 1 line
2.49.0
RFC 1/15 net: cpc: add base skeleton driver
This commit prepares the addition of a CPC driver. CPC, standing for Co-Processor Communication, enables users to have multiple stack protocols over a shared physical link using multiple endpoints.
This patch adds the basic infrastructure for the new module, and introduces a new structure cpc_interface. The goal of this structure is to abstract a physical link like an SPI device, a SDIO function, or a UART for instance.
--- MAINTAINERS | 6 +++ drivers/net/Kconfig | 2 + drivers/net/Makefile | 1 + drivers/net/cpc/Kconfig | 15 ++++++ drivers/net/cpc/Makefile | 5 ++ drivers/net/cpc/interface.c | 98 +++++++++++++++++++++++++++++++++++++ drivers/net/cpc/interface.h | 88 +++++++++++++++++++++++++++++++++ drivers/net/cpc/main.c | 21 ++++++++ 8 files changed, 236 insertions(+) create mode 100644 drivers/net/cpc/Kconfig create mode 100644 drivers/net/cpc/Makefile create mode 100644 drivers/net/cpc/interface.c create mode 100644 drivers/net/cpc/interface.h create mode 100644 drivers/net/cpc/main.c
MAINTAINERS +6 -0
@@ -21731,6 +21731,12 @@ S: Maintained F: drivers/input/touchscreen/silead.c F: drivers/platform/x86/touchscreen_dmi.c +SILICON LABS CPC DRIVERS +M: Damien Riégel <[email protected]> +R: Silicon Labs Kernel Team <[email protected]> +S: Supported +F: drivers/net/cpc/* + SILICON LABS WIRELESS DRIVERS (for WFxxx series) M: Jérôme Pouiller <[email protected]> S: Supported
drivers/net/Kconfig +2 -0
@@ -508,6 +508,8 @@ source "drivers/atm/Kconfig" source "drivers/net/caif/Kconfig" +source "drivers/net/cpc/Kconfig" + source "drivers/net/dsa/Kconfig" source "drivers/net/ethernet/Kconfig"
drivers/net/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_MHI_NET) += mhi_net.o obj-$(CONFIG_ARCNET) += arcnet/ obj-$(CONFIG_CAIF) += caif/ obj-$(CONFIG_CAN) += can/ +obj-$(CONFIG_CPC) += cpc/ ifdef CONFIG_NET_DSA obj-y += dsa/ endif
drivers/net/cpc/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +menuconfig CPC + tristate "Silicon Labs Co-Processor Communication (CPC) Protocol" + depends on NET + help + Provide support for the CPC protocol to Silicon Labs EFR32 devices. + + CPC provides a way to multiplex data channels over a shared physical + link. These data channels can carry Bluetooth, Wi-Fi, or any arbitrary + data. Depending on the part and the firmware, the set of available + channels may differ. + + Say Y here to compile support for CPC into the kernel or say M to + compile as a module.
drivers/net/cpc/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +cpc-y := interface.o main.o + +obj-$(CONFIG_CPC) += cpc.o
drivers/net/cpc/interface.c new file +98 -0
98 lines not on this page · raw message
drivers/net/cpc/interface.h new file +88 -0
88 lines not on this page · raw message
drivers/net/cpc/main.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025, Silicon Laboratories, Inc. +*/ + +#include <linux/module.h> + +static int __init cpc_init (void ) +{ +return 0 ; +} +module_init (cpc_init); + +static void __exit cpc_exit(void) +{ +} +module_exit (cpc_exit); + +MODULE_DESCRIPTION ("Silicon Labs CPC Protocol" ); +MODULE_AUTHOR ("Damien Riégel <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
2.49.0
Re: [RFC net-next 01/15] net: cpc: add base skeleton driver
Quoted 7 lines
drivers/net/cpc/interface.c new file +7
-0+/** +* cpc_interface_register() - Register CPC interface. +* @intf: CPC device to register. +* +* Context: Process context. +* +* Return: 0 if successful, otherwise a negative error code.
drivers/net/cpc/interface.c line 85
Quoted 10 lines
drivers/net/cpc/interface.c new file +10
-0+*/ +int cpc_interface_register (struct cpc_interface *intf) +{ +int err; + + err =device_add (&intf->dev); +if (err) +return err; + +return 0 ;
I guess this will change in a later patch, but maybe not. This should just be
return device_add(&intf->dev);
drivers/net/cpc/interface.c line 98
Quoted 13 lines
drivers/net/cpc/interface.c new file +13
-0+} + +/** +* cpc_interface_unregister() - Unregister a CPC interface. +* @intf: CPC device to unregister. +* +* Context: Process context. +*/ +void cpc_interface_unregister (struct cpc_interface *intf) +{ +device_del (&intf->dev); +cpc_interface_put (intf); +}
It seems odd that unregister is not a mirror of register?
drivers/net/cpc/interface.h line 61
Quoted 12 lines
drivers/net/cpc/interface.h new file +12
-0+/** +* cpc_interface_get() - Get a reference to interface and return its pointer. +* @intf: Interface to get. +* +* Return: Interface pointer with its reference counter incremented, or %NULL. +*/ +static inline struct cpc_interface *cpc_interface_get (struct cpc_interface *intf) +{ +if (!intf || !get_device (&intf->dev)) +return NULL ; +return intf; +}
What is the use case for passing in NULL?
Quoted 15 lines
drivers/net/cpc/interface.h new file +15
-0+ +/** +* cpc_interface_put() - Release reference to an interface. +* @intf: CPC interface +* +* Context: Process context. +*/ +static inline void cpc_interface_put (struct cpc_interface *intf) +{ +if (intf) +put_device (&intf->dev); +} + +/** +* cpc_interface_get_priv() - Get driver data associated with this interface.
drivers/net/cpc/interface.h line 86
Quoted 10 lines
drivers/net/cpc/interface.h new file +10
-0+* @intf: Interface pointer. +* +* Return: Driver data, set at allocation via cpc_interface_alloc(). +*/ +static inline void *cpc_interface_get_priv (struct cpc_interface *intf) +{ +if (!intf) +return NULL ; +return dev_get_drvdata (&intf->dev); +}
What is the use case for passing in NULL?
To me, this is hiding bugs. It seems better to let the kernel opp so you find out where you lost your intf.
Andrew
RFC 2/15 net: cpc: add endpoint infrastructure
In reply to Damien RiégelNetwork stacks using CPC are isolated from each other and their communication channels are called endpoints. Within a CPC interface, endpoints must have a unique Endpoint ID, which will be used to address messages to that specific endpoint in a latter changeset.
Endpoints are part of an interface, this is represented in the device model by endpoints being children of interface, and the interface ensuring uniqueness of the endpoint ID when a new one is added.
--- drivers/net/cpc/Makefile | 2 +- drivers/net/cpc/cpc.h | 101 ++++++++++++++++++++++ drivers/net/cpc/endpoint.c | 166 ++++++++++++++++++++++++++++++++++++ drivers/net/cpc/interface.c | 58 +++++++++++++ drivers/net/cpc/interface.h | 11 +++ 5 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 drivers/net/cpc/cpc.h create mode 100644 drivers/net/cpc/endpoint.c
drivers/net/cpc/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -cpc-y := interface.o main.o +cpc-y := endpoint.o interface.o main.o obj-$(CONFIG_CPC) += cpc.o
drivers/net/cpc/cpc.h new file +101 -0
101 lines not on this page · raw message
drivers/net/cpc/endpoint.c new file +166 -0
166 lines not on this page · raw message
drivers/net/cpc/interface.c +58 -0
82 lines not on this page · raw message
drivers/net/cpc/interface.h +11 -0
@@ -17,15 +17,24 @@ struct cpc_interface_ops;/** * struct cpc_interface - Representation of a CPC interface. * @dev: Device structure for bookkeeping.. +* @add_lock: Lock to serialize addition of new endpoints. * @ops: Callbacks for this device. * @index: Device index. +* @lock: Protect access to endpoint list. +* @eps: List of endpoints managed by this device. */ struct cpc_interface {struct device dev; +/* Prevent concurrent addition of new devices */ +struct mutex add_lock; +const struct cpc_interface_ops *ops;int index; + +struct mutex lock;/* Protect eps from concurrent access. */ +struct list_head eps; };/**
@@ -47,6 +56,8 @@ struct cpc_interface *cpc_interface_alloc(struct device *parent,int cpc_interface_register (struct cpc_interface *intf);void cpc_interface_unregister (struct cpc_interface *intf); +struct cpc_endpoint *cpc_interface_get_endpoint (struct cpc_interface *intf,u8 ep_id); +/** * cpc_interface_get() - Get a reference to interface and return its pointer. * @intf: Interface to get.
Signature · 1 line
2.49.0
Re: [RFC net-next 02/15] net: cpc: add endpoint infrastructure
Quoted 12 lines
drivers/net/cpc/endpoint.c new file +12
-0+/** +* cpc_endpoint_register() - Register an endpoint. +* @ep: Endpoint to register. +* +* Companion function of cpc_endpoint_alloc(). This function adds the endpoint, making it usable by +* CPC drivers. As this ensures that endpoint ID is unique within a CPC interface and then adds the +* endpoint, the lock interface is held to prevent concurrent additions. +* +* Context: Lock "add_lock" of endpoint's interface. +* +* Return: 0 on success, negative errno otherwise. +*/
drivers/net/cpc/endpoint.c line 116
Quoted 10 lines
drivers/net/cpc/endpoint.c new file +10
-0+int cpc_endpoint_register (struct cpc_endpoint *ep) +{ +int err; + +if (!ep || !ep->intf) +return -EINVAL ; + +mutex_lock (&ep->intf->add_lock); + err =__cpc_endpoint_register (ep); +mutex_unlock (&ep->intf->add_lock);
What exactly is add_lock protecting?
drivers/net/cpc/endpoint.c line 166
Quoted 5 lines
drivers/net/cpc/endpoint.c new file +5
-0+void cpc_endpoint_unregister (struct cpc_endpoint *ep) +{ +device_del (&ep->dev); +put_device (&ep->dev); +}
Register needs a lock, but unregister does not?
Quoted 9 lines
drivers/net/cpc/interface.c +9
-0+/** +* cpc_interface_get_endpoint() - get endpoint registered in CPC device with this id +* @intf: CPC device to probe +* @ep_id: endpoint ID that's being looked for +* +* Context: This function locks device's endpoint list. +* +* Return: a struct cpc_endpoint pointer or NULL if not found. +*/
drivers/net/cpc/interface.c int cpc_interface_register(struct cpc_interface *intf) · line 156
Quoted 10 lines
drivers/net/cpc/interface.c +10
-0+struct cpc_endpoint *cpc_interface_get_endpoint (struct cpc_interface *intf,u8 ep_id) +{ +struct cpc_endpoint *ep; + +mutex_lock (&intf->lock); + ep =__cpc_interface_get_endpoint (intf, ep_id); +mutex_unlock (&intf->lock); + +return ep; +}
cpc_interface_get_endpoint() but no cpc_interface_put_endpoint() ? Is this not taking a reference on the end point? Maybe this should not be called _get_.
Andrew
RFC 3/15 net: cpc: introduce CPC driver and bus
In reply to Damien RiégelEndpoints by itself are useless if there are no drivers to use them. This commit adds the final bit of infrastructure for CPC module: a new bus type and its associated driver.
As a very basic matching mechanism, the bus will match an endpoint with its driver if driver's name (driver.name attribute) matches endpoint's name.
--- drivers/net/cpc/cpc.h | 39 +++++++++++++++++++++++ drivers/net/cpc/endpoint.c | 1 + drivers/net/cpc/main.c | 65 +++++++++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 1 deletion(-)
drivers/net/cpc/cpc.h +39 -0
@@ -15,6 +15,8 @@ struct cpc_driver;struct cpc_interface ;struct cpc_endpoint ; +extern const struct bus_type cpc_bus; +/** * struct cpc_endpoint - Representation of CPC endpointl * @dev: Driver model representation of the device.
@@ -98,4 +100,41 @@ static inline void cpc_endpoint_set_drvdata(struct cpc_endpoint *ep, void *data) dev_set_drvdata(&ep->dev, data); } +/*---------------------------------------------------------------------------*/ + +/** +* struct cpc_driver - CPC endpoint driver. +* @driver: Internal driver for the device driver model. +* @probe: Binds this driver to the endpoint. +* @remove: Unbinds this driver from the endpoint. +* +* This represents a device driver that uses an endpoint to communicate with a remote application at +* the other side of the CPC interface. The way to communicate with the remote is abstracted by the +* interface, and drivers don't have to care if other endpoints are present or not. +*/ +struct cpc_driver { +struct device_driver driver; + +int (*probe)(struct cpc_endpoint *ep); +void (*remove)(struct cpc_endpoint *ep); +}; + +int __cpc_driver_register (struct cpc_driver *cpc_drv,struct module *owner); +void cpc_driver_unregister (struct cpc_driver *cpc_drv); + +/* Convenience macro with THIS_MODULE */ +#define cpc_driver_register (driver) \ + __cpc_driver_register(driver, THIS_MODULE) + +/** +* cpc_driver_from_drv - Upcast from a device driver. +* @drv: Reference to a device driver. +* +* @return: Reference to the cpc driver. +*/ +static inline struct cpc_driver *cpc_driver_from_drv (const struct device_driver *drv) +{ + return container_of(drv, struct cpc_driver, driver); +} +#endif
drivers/net/cpc/endpoint.c +1 -0
@@ -48,6 +48,7 @@ struct cpc_endpoint *cpc_endpoint_alloc(struct cpc_interface *intf, u8 id) ep->id = id; ep->dev.parent = &intf->dev; + ep->dev.bus = &cpc_bus; ep->dev.release = cpc_ep_release;device_initialize (&ep->dev);
drivers/net/cpc/main.c +64 -1
80 lines not on this page · raw message
Signature · 1 line
2.49.0
RFC 4/15 net: cpc: add protocol header structure and API
In reply to Damien RiégelCPC frames are composed of a header and optionally a payload. There are three main frame types currently supported:
- DATA for transmitting payload or regular control frames (like ACKs, that don't have payload associated with them)
- SYN for connection sequence
- RST for disconnection and errors
Add structure and functions to operate on this header. They will be leveraged in a future commit where the protocol is actually implemented.
--- drivers/net/cpc/Makefile | 2 +- drivers/net/cpc/header.c | 237 +++++++++++++++++++++++++++++++++++++++ drivers/net/cpc/header.h | 83 ++++++++++++++ 3 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 drivers/net/cpc/header.c create mode 100644 drivers/net/cpc/header.h
drivers/net/cpc/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -cpc-y := endpoint.o interface.o main.o +cpc-y := endpoint.o header.o interface.o main.o obj-$(CONFIG_CPC) += cpc.o
drivers/net/cpc/header.c new file +237 -0
237 lines not on this page · raw message
drivers/net/cpc/header.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [RFC net-next 04/15] net: cpc: add protocol header structure and API
Quoted 5 lines
drivers/net/cpc/header.h new file +5
-0+struct cpc_header { +u8 ctrl; +u8 ep_id; +u8 recv_wnd; +u8 seq;
drivers/net/cpc/header.h line 60
Quoted 10 lines
drivers/net/cpc/header.h new file +10
-0+u8 ack; +union { +u8 extension[3 ]; +struct __packed { +__le16 mtu; +u8 reserved; + } syn; +struct __packed { +__le16 payload_len; +u8 reserved;
These two le16 are unaligned for no good reason. Put the reserved byte first, then the u16. Once you have done that, you might be able to throw away all the __packed because it is then all naturally aligned.
Andrew
RFC 5/15 net: cpc: implement basic transmit path
In reply to Damien RiégelImplement a very basic transmission path for endpoints. Transmitting involves the following flow:
- user call cpc_endpoint_write() with the SKB they wish to send
- a CPC header is prepared and prepended to the frame
- SKB is pushed to endpoint's holding queue (*)
- SKB is dequeued from endpoint's holding queue and moved to interface's transmit queue (*)
- interface is woken up by invoking its wake_tx() callback
- interface work task is now responsible for dequeueing and transmitting that SKB when it's convenient for it to do so.
(*) Endpoint's holding queue currently serves no purpose but it will
when other protocol features are implemented.
--- drivers/net/cpc/Makefile | 2 +- drivers/net/cpc/cpc.h | 15 +++++++++ drivers/net/cpc/endpoint.c | 33 +++++++++++++++++++ drivers/net/cpc/interface.c | 40 +++++++++++++++++++++++ drivers/net/cpc/interface.h | 7 +++++ drivers/net/cpc/main.c | 50 +++++++++++++++++++++++++++++ drivers/net/cpc/protocol.c | 63 +++++++++++++++++++++++++++++++++++++ drivers/net/cpc/protocol.h | 19 +++++++++++ 8 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 drivers/net/cpc/protocol.c create mode 100644 drivers/net/cpc/protocol.h
drivers/net/cpc/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -cpc-y := endpoint.o header.o interface.o main.o +cpc-y := endpoint.o header.o interface.o main.o protocol.o obj-$(CONFIG_CPC) += cpc.o
drivers/net/cpc/cpc.h +15 -0
@@ -7,6 +7,7 @@#define __CPC_H#include <linux/device.h> +#include <linux/skbuff.h> #include <linux/types.h> #define CPC_ENDPOINT_NAME_MAX_LEN 128
@@ -24,6 +25,8 @@ extern const struct bus_type cpc_bus;* @id: Endpoint id, uniquely identifies an endpoint within a CPC device. * @intf: Pointer to CPC device this endpoint belongs to. * @list_node: list_head member for linking in a CPC device. +* @holding_queue: Contains frames that were not pushed to the transport layer +* due to having insufficient space in the transmit window. * * Each endpoint can send and receive data without consideration of the other endpoints sharing the * same physical link.
@@ -36,6 +39,8 @@ struct cpc_endpoint {struct cpc_interface *intf;struct list_head list_node; + +struct sk_buff_head holding_queue; };struct cpc_endpoint *cpc_endpoint_alloc (struct cpc_interface *intf,u8 id);
@@ -44,6 +49,8 @@ struct cpc_endpoint *cpc_endpoint_new(struct cpc_interface *intf, u8 id, const cvoid cpc_endpoint_unregister (struct cpc_endpoint *ep); +int cpc_endpoint_write (struct cpc_endpoint *ep,struct sk_buff *skb); +/** * cpc_endpoint_from_dev() - Upcast from a device pointer. * @dev: Reference to a device.
@@ -137,4 +144,12 @@ static inline struct cpc_driver *cpc_driver_from_drv(const struct device_driver return container_of(drv, struct cpc_driver, driver); } +/*---------------------------------------------------------------------------*/ + +struct sk_buff *cpc_skb_alloc (size_t payload_len,gfp_t priority); +void cpc_skb_set_ctx (struct sk_buff *skb, +void (*destructor)(struct sk_buff *skb), +void *ctx); +void *cpc_skb_get_ctx (struct sk_buff *skb); +#endif
drivers/net/cpc/endpoint.c +33 -0
@@ -6,7 +6,9 @@#include <linux/string.h> #include "cpc.h" +#include "header.h" #include "interface.h" +#include "protocol.h" /** * cpc_ep_release() - Actual release of the CPC endpoint.
@@ -18,6 +20,8 @@ static void cpc_ep_release(struct device *dev) {struct cpc_endpoint *ep =cpc_endpoint_from_dev (dev); +skb_queue_purge (&ep->holding_queue); +cpc_interface_put (ep->intf);kfree (ep); }
@@ -51,6 +55,8 @@ struct cpc_endpoint *cpc_endpoint_alloc(struct cpc_interface *intf, u8 id) ep->dev.bus = &cpc_bus; ep->dev.release = cpc_ep_release; +skb_queue_head_init (&ep->holding_queue); +device_initialize (&ep->dev);return ep;
@@ -165,3 +171,30 @@ void cpc_endpoint_unregister(struct cpc_endpoint *ep)device_del (&ep->dev);put_device (&ep->dev); } + +/** +* cpc_endpoint_write - Write a DATA frame. +* @ep: Endpoint handle. +* @skb: Frame to send. +* +* @return: 0 on success, otherwise a negative error code. +*/ +int cpc_endpoint_write (struct cpc_endpoint *ep,struct sk_buff *skb) +{ +struct cpc_header hdr; +int err; + +if (ep->intf->ops->csum) + ep->intf->ops->csum (skb); + +memset (&hdr,0 ,sizeof (hdr)); + hdr.ctrl =cpc_header_get_ctrl (CPC_FRAME_TYPE_DATA , true); + hdr.ep_id = ep->id; + hdr.recv_wnd =CPC_HEADER_MAX_RX_WINDOW ; + hdr.seq =0 ; + hdr.dat.payload_len = skb->len; + + err =__cpc_protocol_write (ep, &hdr, skb); + +return err; +}
drivers/net/cpc/interface.c +40 -0
@@ -58,6 +58,8 @@ struct cpc_interface *cpc_interface_alloc(struct device *parent,mutex_init (&intf->lock);INIT_LIST_HEAD (&intf->eps); +skb_queue_head_init (&intf->tx_queue); + intf->ops = ops; intf->dev.parent = parent;
@@ -154,3 +156,41 @@ struct cpc_endpoint *cpc_interface_get_endpoint(struct cpc_interface *intf, u8 ereturn ep; } + +/** +* cpc_interface_send_frame() - Queue a socket buffer for transmission. +* @intf: Interface to send SKB over. +* @ops: SKB to send. +* +* Queue SKB in interface's transmit queue and signal the interface. Interface is expected to use +* cpc_interface_dequeue() to get the next SKB to transmit. +*/ +void cpc_interface_send_frame (struct cpc_interface *intf,struct sk_buff *skb) +{ +skb_queue_tail (&intf->tx_queue, skb); + intf->ops->wake_tx (intf); +} + +/** +* cpc_interface_dequeue() - Get the next SKB that was queued for transmission. +* @intf: Interface. +* +* Get an SKB that was previously queued by cpc_interface_send_frame(). +* +* Return: An SKB, or %NULL if queue was empty. +*/ +struct sk_buff *cpc_interface_dequeue (struct cpc_interface *intf) +{ +return skb_dequeue (&intf->tx_queue); +} + +/** +* cpc_interface_tx_queue_empty() - Check if transmit queue is empty. +* @intf: Interface. +* +* Return: True if transmit queue is empty, false otherwise. +*/ +bool cpc_interface_tx_queue_empty (struct cpc_interface *intf) +{ +return skb_queue_empty_lockless (&intf->tx_queue); +}
drivers/net/cpc/interface.h +7 -0
@@ -22,6 +22,7 @@ struct cpc_interface_ops;* @index: Device index. * @lock: Protect access to endpoint list. * @eps: List of endpoints managed by this device. +* @tx_queue: Transmit queue to be consumed by the interface. */ struct cpc_interface {struct device dev;
@@ -35,6 +36,8 @@ struct cpc_interface {struct mutex lock;/* Protect eps from concurrent access. */ struct list_head eps; + +struct sk_buff_head tx_queue; };/**
@@ -58,6 +61,10 @@ void cpc_interface_unregister(struct cpc_interface *intf);struct cpc_endpoint *cpc_interface_get_endpoint (struct cpc_interface *intf,u8 ep_id); +void cpc_interface_send_frame (struct cpc_interface *intf,struct sk_buff *skb); +struct sk_buff *cpc_interface_dequeue (struct cpc_interface *intf); +bool cpc_interface_tx_queue_empty (struct cpc_interface *intf); +/** * cpc_interface_get() - Get a reference to interface and return its pointer. * @intf: Interface to get.
drivers/net/cpc/main.c +50 -0
56 lines not on this page · raw message
drivers/net/cpc/protocol.c new file +63 -0
63 lines not on this page · raw message
drivers/net/cpc/protocol.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025, Silicon Laboratories, Inc. +*/ + +#ifndef CPC_PROTOCOL_H +#define CPC_PROTOCOL_H + +#include <linux/skbuff.h> +#include <linux/timer.h> +#include <linux/types.h> +#include <linux/workqueue.h> + +struct cpc_endpoint ; +struct cpc_header ; + +int __cpc_protocol_write (struct cpc_endpoint *ep,struct cpc_header *hdr,struct sk_buff *skb); + +#endif
Signature · 1 line
2.49.0
RFC 6/15 net: cpc: implement basic receive path
In reply to Damien RiégelImplement a very basic receive path. When a new frame is available, interfaces are expected to call cpc_interface_receive_frame(). This frame will be handled in a high-priority workqueue and dispatched to the endpoint it targets, if available.
Endpoints should set an RX callback with cpc_endpoint_set_ops() in order to be notified when a new frame arrives. This callback should be short, long operations should be dispatched or the main reception task will be blocked until that processing finishes.
--- drivers/net/cpc/cpc.h | 9 ++++++ drivers/net/cpc/endpoint.c | 11 +++++++ drivers/net/cpc/interface.c | 59 +++++++++++++++++++++++++++++++++++++ drivers/net/cpc/interface.h | 8 +++++ drivers/net/cpc/protocol.c | 15 ++++++++++ drivers/net/cpc/protocol.h | 2 ++ 6 files changed, 104 insertions(+)
drivers/net/cpc/cpc.h +9 -0
@@ -18,6 +18,13 @@ struct cpc_endpoint;extern const struct bus_type cpc_bus; +/** struct cpc_endpoint_ops - Endpoint's callbacks. +* @rx: Data availability is provided with a skb owned by the driver. +*/ +struct cpc_endpoint_ops { +void (*rx)(struct cpc_endpoint *ep,struct sk_buff *skb); +}; +/** * struct cpc_endpoint - Representation of CPC endpointl * @dev: Driver model representation of the device.
@@ -39,6 +46,7 @@ struct cpc_endpoint {struct cpc_interface *intf;struct list_head list_node; +struct cpc_endpoint_ops *ops;struct sk_buff_head holding_queue; };
@@ -50,6 +58,7 @@ struct cpc_endpoint *cpc_endpoint_new(struct cpc_interface *intf, u8 id, const cvoid cpc_endpoint_unregister (struct cpc_endpoint *ep);int cpc_endpoint_write (struct cpc_endpoint *ep,struct sk_buff *skb); +void cpc_endpoint_set_ops (struct cpc_endpoint *ep,struct cpc_endpoint_ops *ops);/** * cpc_endpoint_from_dev() - Upcast from a device pointer.
drivers/net/cpc/endpoint.c +11 -0
@@ -172,6 +172,17 @@ void cpc_endpoint_unregister(struct cpc_endpoint *ep)put_device (&ep->dev); } +/** +* cpc_endpoint_set_ops() - Set callbacks for this endpoint. +* @ep: Endpoint +* @ops: New callbacks to set. If already set, override pre-existing value. +*/ +void cpc_endpoint_set_ops (struct cpc_endpoint *ep,struct cpc_endpoint_ops *ops) +{ +if (ep) + ep->ops = ops; +} +/** * cpc_endpoint_write - Write a DATA frame. * @ep: Endpoint handle.
drivers/net/cpc/interface.c +59 -0
93 lines not on this page · raw message
drivers/net/cpc/interface.h +8 -0
@@ -22,6 +22,9 @@ struct cpc_interface_ops;* @index: Device index. * @lock: Protect access to endpoint list. * @eps: List of endpoints managed by this device. +* @workq: Interface-specific work queue. +* @rx_work: work struct for processing received frames +* @rx_queue: list of sk_buff that were received * @tx_queue: Transmit queue to be consumed by the interface. */ struct cpc_interface {
@@ -37,6 +40,10 @@ struct cpc_interface {struct mutex lock;/* Protect eps from concurrent access. */ struct list_head eps; +struct workqueue_struct *workq; +struct work_struct rx_work; +struct sk_buff_head rx_queue; +struct sk_buff_head tx_queue; };
@@ -61,6 +68,7 @@ void cpc_interface_unregister(struct cpc_interface *intf);struct cpc_endpoint *cpc_interface_get_endpoint (struct cpc_interface *intf,u8 ep_id); +void cpc_interface_receive_frame (struct cpc_interface *intf,struct sk_buff *skb);void cpc_interface_send_frame (struct cpc_interface *intf,struct sk_buff *skb);struct sk_buff *cpc_interface_dequeue (struct cpc_interface *intf);bool cpc_interface_tx_queue_empty (struct cpc_interface *intf);
drivers/net/cpc/protocol.c +15 -0
@@ -39,6 +39,21 @@ static void __cpc_protocol_process_pending_tx_frames(struct cpc_endpoint *ep) } } +void cpc_protocol_on_data (struct cpc_endpoint *ep,struct sk_buff *skb) +{ +if (skb->len >CPC_HEADER_SIZE ) { +/* Strip header. */ +skb_pull (skb,CPC_HEADER_SIZE ); + +if (ep->ops && ep->ops->rx) + ep->ops->rx (ep, skb); +else +kfree_skb (skb); + }else { +kfree_skb (skb); + } +} +/** * __cpc_protocol_write() - Write a frame. * @ep: Endpoint handle.
drivers/net/cpc/protocol.h +2 -0
@@ -16,4 +16,6 @@ struct cpc_header;int __cpc_protocol_write (struct cpc_endpoint *ep,struct cpc_header *hdr,struct sk_buff *skb); +void cpc_protocol_on_data (struct cpc_endpoint *ep,struct sk_buff *skb); +#endif
Signature · 1 line
2.49.0
RFC 7/15 net: cpc: implement sequencing and ack
In reply to Damien RiégelCPC frames are sequenced and must be acked by the remote. If not acked in a timely manner, they should be retransmitted but that feature is not part of this commit.
Another key feature is that peers advertise how many frames they can receive. As the remote is usually a microcontroller with limited memory, this serves as a way to throttle the host and prevent it from sending frames that the microcontroller is not yet able to receive. This is where endpoint's holding_queue becomes useful and serves as storage for frames that endpoint is ready to send but that the remote is not yet able to receive.
--- drivers/net/cpc/cpc.h | 26 +++++++++ drivers/net/cpc/endpoint.c | 24 ++++++++- drivers/net/cpc/protocol.c | 108 ++++++++++++++++++++++++++++++++++++- 3 files changed, 156 insertions(+), 2 deletions(-)
drivers/net/cpc/cpc.h +26 -0
@@ -18,6 +18,27 @@ struct cpc_endpoint;extern const struct bus_type cpc_bus; +/** +* struct cpc_endpoint_tcb - endpoint's transmission control block +* @lock: synchronize tcb access +* @send_wnd: send window, maximum number of frames that the remote can accept +* TX frames should have a sequence in the range +* [send_una; send_una + send_wnd]. +* @send_nxt: send next, the next sequence number that will be used for transmission +* @send_una: send unacknowledged, the oldest unacknowledged sequence number +* @ack: current acknowledge number +* @seq: current sequence number +* @mtu: maximum transmission unit +*/ +struct cpc_endpoint_tcb { +struct mutex lock;/* Synchronize access to all other attributes. */ +u8 send_wnd; +u8 send_nxt; +u8 send_una; +u8 ack; +u8 seq; +}; +/** struct cpc_endpoint_ops - Endpoint's callbacks. * @rx: Data availability is provided with a skb owned by the driver. */
@@ -32,6 +53,8 @@ struct cpc_endpoint_ops {* @id: Endpoint id, uniquely identifies an endpoint within a CPC device. * @intf: Pointer to CPC device this endpoint belongs to. * @list_node: list_head member for linking in a CPC device. +* @tcb: Transmission control block. +* @pending_ack_queue: Contain frames pending on an acknowledge. * @holding_queue: Contains frames that were not pushed to the transport layer * due to having insufficient space in the transmit window. *
@@ -48,6 +71,9 @@ struct cpc_endpoint {struct list_head list_node;struct cpc_endpoint_ops *ops; +struct cpc_endpoint_tcb tcb; + +struct sk_buff_head pending_ack_queue;struct sk_buff_head holding_queue; };
drivers/net/cpc/endpoint.c +23 -1
@@ -20,12 +20,26 @@ static void cpc_ep_release(struct device *dev) {struct cpc_endpoint *ep =cpc_endpoint_from_dev (dev); +skb_queue_purge (&ep->pending_ack_queue);skb_queue_purge (&ep->holding_queue);cpc_interface_put (ep->intf);kfree (ep); } +/** +* cpc_endpoint_tcb_reset() - Reset endpoint's TCB to initial values. +* @ep: endpoint pointer +*/ +static void cpc_endpoint_tcb_reset (struct cpc_endpoint *ep) +{ + ep->tcb.seq = ep->id; + ep->tcb.ack =0 ; + ep->tcb.send_nxt = ep->id; + ep->tcb.send_una = ep->id; + ep->tcb.send_wnd =1 ; +} +/** * cpc_endpoint_alloc() - Allocate memory for new CPC endpoint. * @intf: CPC interface owning this endpoint.
@@ -55,6 +69,10 @@ struct cpc_endpoint *cpc_endpoint_alloc(struct cpc_interface *intf, u8 id) ep->dev.bus = &cpc_bus; ep->dev.release = cpc_ep_release; +mutex_init (&ep->tcb.lock); +cpc_endpoint_tcb_reset (ep); + +skb_queue_head_init (&ep->pending_ack_queue);skb_queue_head_init (&ep->holding_queue);device_initialize (&ep->dev);
@@ -195,6 +213,8 @@ int cpc_endpoint_write(struct cpc_endpoint *ep, struct sk_buff *skb)struct cpc_header hdr;int err; +mutex_lock (&ep->tcb.lock); +if (ep->intf->ops->csum) ep->intf->ops->csum (skb);
@@ -202,10 +222,12 @@ int cpc_endpoint_write(struct cpc_endpoint *ep, struct sk_buff *skb) hdr.ctrl =cpc_header_get_ctrl (CPC_FRAME_TYPE_DATA , true); hdr.ep_id = ep->id; hdr.recv_wnd =CPC_HEADER_MAX_RX_WINDOW ; - hdr.seq =0 ; + hdr.seq = ep->tcb.seq; hdr.dat.payload_len = skb->len; err =__cpc_protocol_write (ep, &hdr, skb); +mutex_unlock (&ep->tcb.lock); +return err; }
drivers/net/cpc/protocol.c +107 -1
145 lines not on this page · raw message
Signature · 1 line
2.49.0
RFC 8/15 net: cpc: add support for connecting endpoints
In reply to Damien RiégelEndpoints must be connected before transmitting. This is achieved using a three-way handshake in which each peer advertises the maximum payload size it can receive. Once again, this constraint comes from the remote microcontroller, which can have tight limit on the payload size it can handle.
--- drivers/net/cpc/cpc.h | 12 +++++ drivers/net/cpc/endpoint.c | 75 ++++++++++++++++++++++++++++ drivers/net/cpc/interface.c | 29 +++++++++++ drivers/net/cpc/interface.h | 3 ++ drivers/net/cpc/protocol.c | 97 ++++++++++++++++++++++++++++++++++++- drivers/net/cpc/protocol.h | 4 ++ 6 files changed, 219 insertions(+), 1 deletion(-)
drivers/net/cpc/cpc.h +12 -0
@@ -18,6 +18,11 @@ struct cpc_endpoint;extern const struct bus_type cpc_bus; +/* CPC endpoint flags */ +enum { +CPC_ENDPOINT_UP ,/* Connection is established with remote counterpart. */ +}; +/** * struct cpc_endpoint_tcb - endpoint's transmission control block * @lock: synchronize tcb access
@@ -37,6 +42,7 @@ struct cpc_endpoint_tcb {u8 send_una;u8 ack;u8 seq; +u16 mtu; };/** struct cpc_endpoint_ops - Endpoint's callbacks.
@@ -54,6 +60,8 @@ struct cpc_endpoint_ops {* @intf: Pointer to CPC device this endpoint belongs to. * @list_node: list_head member for linking in a CPC device. * @tcb: Transmission control block. +* @conn: Completion structure for connection. +* @flags: Endpoint state flags. * @pending_ack_queue: Contain frames pending on an acknowledge. * @holding_queue: Contains frames that were not pushed to the transport layer * due to having insufficient space in the transmit window.
@@ -72,6 +80,8 @@ struct cpc_endpoint {struct cpc_endpoint_ops *ops;struct cpc_endpoint_tcb tcb; +struct completion conn; +unsigned long flags;struct sk_buff_head pending_ack_queue;struct sk_buff_head holding_queue;
@@ -83,6 +93,8 @@ struct cpc_endpoint *cpc_endpoint_new(struct cpc_interface *intf, u8 id, const cvoid cpc_endpoint_unregister (struct cpc_endpoint *ep); +int cpc_endpoint_connect (struct cpc_endpoint *ep); +void cpc_endpoint_disconnect (struct cpc_endpoint *ep);int cpc_endpoint_write (struct cpc_endpoint *ep,struct sk_buff *skb);void cpc_endpoint_set_ops (struct cpc_endpoint *ep,struct cpc_endpoint_ops *ops);
drivers/net/cpc/endpoint.c +75 -0
109 lines not on this page · raw message
drivers/net/cpc/interface.c +29 -0
@@ -36,6 +36,9 @@ static void cpc_interface_rx_work(struct work_struct *work)case CPC_FRAME_TYPE_DATA :cpc_protocol_on_data (ep, skb);break ; +case CPC_FRAME_TYPE_SYN : +cpc_protocol_on_syn (ep, skb); +break ;default :kfree_skb (skb); }
@@ -203,6 +206,32 @@ struct cpc_endpoint *cpc_interface_get_endpoint(struct cpc_interface *intf, u8 ereturn ep; } +/** +* cpc_interface_add_rx_endpoint() - Set an endpoint as being available for receiving frames. +* @ep: Endpoint. +*/ +void cpc_interface_add_rx_endpoint (struct cpc_endpoint *ep) +{ +struct cpc_interface *intf = ep->intf; + +mutex_lock (&intf->lock); +list_add_tail (&ep->list_node, &intf->eps); +mutex_unlock (&intf->lock); +} + +/** +* cpc_interface_remove_rx_endpoint() - Unet an endpoint as being available for receiving frames. +* @ep: Endpoint. +*/ +void cpc_interface_remove_rx_endpoint (struct cpc_endpoint *ep) +{ +struct cpc_interface *intf = ep->intf; + +mutex_lock (&intf->lock); +list_del (&ep->list_node); +mutex_unlock (&intf->lock); +} +/** * cpc_interface_receive_frame - queue a received frame for processing * @intf: pointer to the CPC device
drivers/net/cpc/interface.h +3 -0
@@ -68,6 +68,9 @@ void cpc_interface_unregister(struct cpc_interface *intf);struct cpc_endpoint *cpc_interface_get_endpoint (struct cpc_interface *intf,u8 ep_id); +void cpc_interface_add_rx_endpoint (struct cpc_endpoint *ep); +void cpc_interface_remove_rx_endpoint (struct cpc_endpoint *ep); +void cpc_interface_receive_frame (struct cpc_interface *intf,struct sk_buff *skb);void cpc_interface_send_frame (struct cpc_interface *intf,struct sk_buff *skb);struct sk_buff *cpc_interface_dequeue (struct cpc_interface *intf);
drivers/net/cpc/protocol.c +96 -1
121 lines not on this page · raw message
drivers/net/cpc/protocol.h +4 -0
@@ -13,9 +13,13 @@struct cpc_endpoint ;struct cpc_header ; +struct cpc_interface ;int __cpc_protocol_write (struct cpc_endpoint *ep,struct cpc_header *hdr,struct sk_buff *skb);void cpc_protocol_on_data (struct cpc_endpoint *ep,struct sk_buff *skb); +void cpc_protocol_on_syn (struct cpc_endpoint *ep,struct sk_buff *skb); + +int cpc_protocol_send_syn (struct cpc_endpoint *ep);#endif
Signature · 1 line
2.49.0
RFC 9/15 net: cpc: add support for RST frames
In reply to Damien RiégelReset frames are used to either disconnect an endpoint or to signal that a frame is targeting an endpoint that is not connected.
--- drivers/net/cpc/cpc.h | 1 + drivers/net/cpc/endpoint.c | 16 ++++++++++++---- drivers/net/cpc/interface.c | 9 ++++++++- drivers/net/cpc/protocol.c | 32 +++++++++++++++++++++++++++++++- drivers/net/cpc/protocol.h | 2 ++ 5 files changed, 54 insertions(+), 6 deletions(-)
drivers/net/cpc/cpc.h +1 -0
@@ -94,6 +94,7 @@ struct cpc_endpoint *cpc_endpoint_new(struct cpc_interface *intf, u8 id, const cvoid cpc_endpoint_unregister (struct cpc_endpoint *ep);int cpc_endpoint_connect (struct cpc_endpoint *ep); +void __cpc_endpoint_disconnect (struct cpc_endpoint *ep,bool send_rst);void cpc_endpoint_disconnect (struct cpc_endpoint *ep);int cpc_endpoint_write (struct cpc_endpoint *ep,struct sk_buff *skb);void cpc_endpoint_set_ops (struct cpc_endpoint *ep,struct cpc_endpoint_ops *ops);
drivers/net/cpc/endpoint.c +12 -4
@@ -253,6 +253,17 @@ int cpc_endpoint_connect(struct cpc_endpoint *ep)return err; } +void __cpc_endpoint_disconnect (struct cpc_endpoint *ep,bool send_rst) +{ +if (!test_and_clear_bit (CPC_ENDPOINT_UP , &ep->flags)) +return ; + +cpc_interface_remove_rx_endpoint (ep); + +if (send_rst) +cpc_protocol_send_rst (ep->intf, ep->id); +} +/** * cpc_endpoint_disconnect - Disconnect endpoint from remote. * @ep: Endpoint handle.
@@ -264,10 +275,7 @@ int cpc_endpoint_connect(struct cpc_endpoint *ep)*/ void cpc_endpoint_disconnect (struct cpc_endpoint *ep) { -if (!test_and_clear_bit (CPC_ENDPOINT_UP , &ep->flags)) -return ; - -cpc_interface_remove_rx_endpoint (ep); +__cpc_endpoint_disconnect (ep, true); }/**
drivers/net/cpc/interface.c +8 -1
@@ -28,6 +28,10 @@ static void cpc_interface_rx_work(struct work_struct *work) ep =cpc_interface_get_endpoint (intf, ep_id);if (!ep) { +if (type !=CPC_FRAME_TYPE_RST ) { +dev_dbg (&intf->dev,"ep%u not allocated (%d)\n" , ep_id, type); +cpc_protocol_send_rst (intf, ep_id); + }kfree_skb (skb);continue ; }
@@ -39,8 +43,11 @@ static void cpc_interface_rx_work(struct work_struct *work)case CPC_FRAME_TYPE_SYN :cpc_protocol_on_syn (ep, skb);break ; -default : +case CPC_FRAME_TYPE_RST : +dev_dbg (&ep->dev,"reset\n" );kfree_skb (skb); +cpc_protocol_on_rst (ep); +break ; }cpc_endpoint_put (ep);
drivers/net/cpc/protocol.c +31 -1
@@ -60,6 +60,28 @@ static void __cpc_protocol_send_ack(struct cpc_endpoint *ep)cpc_interface_send_frame (ep->intf, skb); } +/** +* cpc_protocol_send_rst - send a RST frame +* @intf: interface pointer +* @ep_id: endpoint id +*/ +void cpc_protocol_send_rst (struct cpc_interface *intf,u8 ep_id) +{ +struct cpc_header hdr = { + .ctrl =cpc_header_get_ctrl (CPC_FRAME_TYPE_RST , false), + .ep_id = ep_id, + }; +struct sk_buff *skb; + + skb =cpc_skb_alloc (0 ,GFP_KERNEL ); +if (!skb) +return ; + +memcpy (skb_push (skb,sizeof (hdr)), &hdr,sizeof (hdr)); + +cpc_interface_send_frame (intf, skb); +} +static void cpc_protocol_on_tx_complete (struct sk_buff *skb) {struct cpc_endpoint *ep =cpc_skb_get_ctx (skb);
@@ -228,8 +250,11 @@ void cpc_protocol_on_syn(struct cpc_endpoint *ep, struct sk_buff *skb) {mutex_lock (&ep->tcb.lock); -if (!__cpc_protocol_is_syn_ack_valid (ep, skb)) +if (!__cpc_protocol_is_syn_ack_valid (ep, skb)) { +cpc_protocol_send_rst (ep->intf, ep->id); + goto out; + } __cpc_protocol_receive_ack(ep, cpc_header_get_recv_wnd(skb->data),
@@ -253,6 +278,11 @@ void cpc_protocol_on_syn(struct cpc_endpoint *ep, struct sk_buff *skb)kfree_skb (skb); } +void cpc_protocol_on_rst (struct cpc_endpoint *ep) +{ +__cpc_endpoint_disconnect (ep, false); +} +/** * __cpc_protocol_write() - Write a frame. * @ep: Endpoint handle.
drivers/net/cpc/protocol.h +2 -0
@@ -19,7 +19,9 @@ int __cpc_protocol_write(struct cpc_endpoint *ep, struct cpc_header *hdr, structvoid cpc_protocol_on_data (struct cpc_endpoint *ep,struct sk_buff *skb);void cpc_protocol_on_syn (struct cpc_endpoint *ep,struct sk_buff *skb); +void cpc_protocol_on_rst (struct cpc_endpoint *ep); +void cpc_protocol_send_rst (struct cpc_interface *intf,u8 ep_id);int cpc_protocol_send_syn (struct cpc_endpoint *ep);#endif
Signature · 1 line
2.49.0
RFC 10/15 net: cpc: make disconnect blocking
In reply to Damien RiégelIn order to make life easier for consumer drivers, make cpc_endpoint_disconnect() blocking. Once the call returns, it guarantees that endpoint's rx callback won't be called anymore, making driver's teardown simpler to implement.
--- drivers/net/cpc/cpc.h | 1 + drivers/net/cpc/endpoint.c | 19 ++++++++++++++++++- drivers/net/cpc/interface.c | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-)
drivers/net/cpc/cpc.h +1 -0
@@ -21,6 +21,7 @@ extern const struct bus_type cpc_bus;/* CPC endpoint flags */ enum {CPC_ENDPOINT_UP ,/* Connection is established with remote counterpart. */ +CPC_ENDPOINT_RECEIVING ,/* Interface RX work is processing a frame for this endpoint. */ };/**
drivers/net/cpc/endpoint.c +18 -1
@@ -260,8 +260,25 @@ void __cpc_endpoint_disconnect(struct cpc_endpoint *ep, bool send_rst)cpc_interface_remove_rx_endpoint (ep); -if (send_rst) +if (send_rst) { +/* +* It makes sense to wait on the RECEIVING bit only when send_rst is true as this +* means the operation was initiated by the user and can happen concurrently with +* the RX work function. If a RST is received from the remote and +* __cpc_endpoint_disconnect from the RX work function, then it's safe to assume +* that this frame won't trigger a call to ep->ops->rx function. +*/ +int err; + + err =wait_on_bit_timeout (&ep->flags, +CPC_ENDPOINT_RECEIVING , +TASK_INTERRUPTIBLE , +msecs_to_jiffies (1000 )); +if (!err) +dev_warn (&ep->dev,"Timeout when disconnecting.\n" ); +cpc_protocol_send_rst (ep->intf, ep->id); + } }/**
drivers/net/cpc/interface.c +4 -0
@@ -36,6 +36,8 @@ static void cpc_interface_rx_work(struct work_struct *work)continue ; } +set_bit (CPC_ENDPOINT_RECEIVING , &ep->flags); +switch (type) {case CPC_FRAME_TYPE_DATA :cpc_protocol_on_data (ep, skb);
@@ -50,6 +52,8 @@ static void cpc_interface_rx_work(struct work_struct *work)break ; } +clear_and_wake_up_bit (CPC_ENDPOINT_RECEIVING , &ep->flags); +cpc_endpoint_put (ep); } }
Signature · 1 line
2.49.0
RFC 11/15 net: cpc: add system endpoint
In reply to Damien RiégelThe system endpoint is the main endpoint and is guaranteed to be present in every CPC-enabled device. It is used to communicate device capabilities.
One of the key element of the system endpoint is that it will send a notification when an endpoint is opened on the microcontroller. When such notification is received by the host, a new endpoint will be registered.
As registering a new endpoint can be a long operation, as in the end it calls device_add(), system's endpoint processing of RX frames is dispatched in its own work function.
--- drivers/net/cpc/Makefile | 2 +- drivers/net/cpc/main.c | 8 + drivers/net/cpc/system.c | 432 +++++++++++++++++++++++++++++++++++++++ drivers/net/cpc/system.h | 14 ++ 4 files changed, 455 insertions(+), 1 deletion(-) create mode 100644 drivers/net/cpc/system.c create mode 100644 drivers/net/cpc/system.h
drivers/net/cpc/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -cpc-y := endpoint.o header.o interface.o main.o protocol.o +cpc-y := endpoint.o header.o interface.o main.o protocol.o system.o obj-$(CONFIG_CPC) += cpc.o
drivers/net/cpc/main.c +8 -0
@@ -8,6 +8,7 @@#include "cpc.h" #include "header.h" +#include "system.h" /** * cpc_skb_alloc() - Allocate an skb with a specific headroom for CPC headers.
@@ -118,6 +119,12 @@ static int __init cpc_init(void)int err; err =bus_register (&cpc_bus); +if (err) +return err; + + err =cpc_system_drv_register (); +if (err) +bus_unregister (&cpc_bus);return err; }
@@ -125,6 +132,7 @@ module_init(cpc_init); static void __exit cpc_exit(void) { +cpc_system_drv_unregister ();bus_unregister (&cpc_bus); }module_exit (cpc_exit);
drivers/net/cpc/system.c new file +432 -0
432 lines not on this page · raw message
drivers/net/cpc/system.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025, Silicon Laboratories, Inc. +*/ + +#ifndef __CPC_SYSTEM_H +#define __CPC_SYSTEM_H + +#define CPC_SYSTEM_ENDPOINT_NAME "system" + +int cpc_system_drv_register (void ); +void cpc_system_drv_unregister (void ); + +#endif
Signature · 1 line
2.49.0
RFC 12/15 net: cpc: create system endpoint with a new interface
In reply to Damien RiégelWithout a system endpoint, no new endpoints will ever be created on an interface, so as part of the registration of a new interface, create the system endpoint attached to it.
--- drivers/net/cpc/interface.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/net/cpc/interface.c +13 -0
@@ -9,6 +9,7 @@#include "header.h" #include "interface.h" #include "protocol.h" +#include "system.h" #define to_cpc_interface (d) container_of(d, struct cpc_interface, dev)
@@ -143,13 +144,25 @@ struct cpc_interface *cpc_interface_alloc(struct device *parent,*/ int cpc_interface_register (struct cpc_interface *intf) { +struct cpc_endpoint *system_ep;int err; err =device_add (&intf->dev);if (err)return err; + system_ep =cpc_endpoint_new (intf,0 ,CPC_SYSTEM_ENDPOINT_NAME ); +if (!system_ep) { + err = -ENOMEM ; + goto unregister_intf; + } +return 0 ; + +unregister_intf: +cpc_interface_unregister (intf); + +return err; }static int cpc_intf_unregister_ep (struct device *dev,void *null)
Signature · 1 line
2.49.0
RFC 13/15 dt-bindings: net: cpc: add silabs,cpc-spi.yaml
In reply to Damien RiégelDocument device tree bindings for Silicon Labs CPC over a SPI bus. This device requires both a chip select and an interrupt line to be able to work.
--- .../bindings/net/silabs,cpc-spi.yaml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/silabs,cpc-spi.yaml
Documentation/devicetree/bindings/net/silabs,cpc-spi.yaml new file +54 -0
@@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2024 Silicon Labs Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/silabs,cpc-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SPI driver for CPC + +maintainers: + - Damien Riégel <[email protected]> + +description: | + This binding is for the implementation of CPC protocol over SPI. The protocol + consists of a chain of header+payload frames. The interrupt is used by the + device to signal it has a frame to transmit, but also between headers and + payloads to signal that it is ready to receive payload. + +properties: + compatible: + enum: + - silabs,cpc-spi + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - interrupt + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + cpcspi@0 { + compatible = "silabs,cpc-spi"; + reg = <0>; + spi-max-frequency = <1000000>; + interrupt-parent = <&gpio>; + interrupts = <23 IRQ_TYPE_EDGE_FALLING>; + }; + };
Signature · 1 line
2.49.0
Rob Herring
maintainerRe: [RFC net-next 13/15] dt-bindings: net: cpc: add silabs,cpc-spi.yaml
Quoted 3 lines · Damien Riégel
Document device tree bindings for Silicon Labs CPC over a SPI bus. This device requires both a chip select and an interrupt line to be able to work.
What's CPC? Never defined here.
Bindings are for devices, not a SPI protocol. What if the device needs reset or power or ??? before you can talk to it. Maybe it's a situation where that will never matter, but you've got to spell it out here.
Quoted 16 lines
Signed-off-by Damien Riégel <[email protected]>--- .../bindings/net/silabs,cpc-spi.yaml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/silabs,cpc-spi.yamlDocumentation/devicetree/bindings/net/silabs,cpc-spi.yaml new file +3
-0@@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2024 Silicon Labs Inc. +%YAML 1.2
Documentation/devicetree/bindings/net/silabs,cpc-spi.yaml line 13
Quoted 10 lines
Documentation/devicetree/bindings/net/silabs,cpc-spi.yaml new file +10
-0+--- +$id: http://devicetree.org/schemas/net/silabs,cpc-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SPI driver for CPC + +maintainers: + - Damien Riégel <[email protected]> + +description: |
Don't need '|'
Quoted 44 lines
Documentation/devicetree/bindings/net/silabs,cpc-spi.yaml new file +41
-0+ This binding is for the implementation of CPC protocol over SPI. The protocol + consists of a chain of header+payload frames. The interrupt is used by the + device to signal it has a frame to transmit, but also between headers and + payloads to signal that it is ready to receive payload. + +properties: + compatible: + enum: + - silabs,cpc-spi + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - interrupt + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + cpcspi@0 { + compatible = "silabs,cpc-spi"; + reg = <0>; + spi-max-frequency = <1000000>; + interrupt-parent = <&gpio>; + interrupts = <23 IRQ_TYPE_EDGE_FALLING>; + }; + };Signature · 1 line
2.49.0
RFC 14/15 net: cpc: add SPI interface driver
In reply to Damien RiégelThis adds support for CPC over SPI. CPC uses a full-duplex protocol. Each frame transmission/reception is split into two parts:
- read and/or write header + header checksum
- read and/or write payload + payload checksum
Header frames are always 10 bytes (8 bytes of header and 2 bytes of checksum). The header contains the size of the payload to receive (size to transmit is already known). As the SPI device also has some processing to do when it receives a header, the SPI driver must wait for the interrupt line to be asserted before clocking the payload.
The SPI device always expects the chip select to be asserted and deasserted after a header, even if there are no payloads to transmit. This is used to keep headers transmission synchronized between host and device. As some controllers don't support doing that if there is nothing to transmit, a null byte is transmitted in that case and it will be ignored by the device.
If there are payloads, the driver will clock the maximum length of the two payloads.
--- drivers/net/cpc/Kconfig | 3 +- drivers/net/cpc/Makefile | 2 +- drivers/net/cpc/main.c | 8 + drivers/net/cpc/spi.c | 550 +++++++++++++++++++++++++++++++++++++++ drivers/net/cpc/spi.h | 12 + 5 files changed, 573 insertions(+), 2 deletions(-) create mode 100644 drivers/net/cpc/spi.c create mode 100644 drivers/net/cpc/spi.h
drivers/net/cpc/Kconfig +2 -1
@@ -2,7 +2,8 @@ menuconfig CPC tristate "Silicon Labs Co-Processor Communication (CPC) Protocol" - depends on NET + depends on NET && SPI + select CRC_ITU_T help Provide support for the CPC protocol to Silicon Labs EFR32 devices.
drivers/net/cpc/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -cpc-y := endpoint.o header.o interface.o main.o protocol.o system.o +cpc-y := endpoint.o header.o interface.o main.o protocol.o spi.o system.o obj-$(CONFIG_CPC) += cpc.o
drivers/net/cpc/main.c +8 -0
@@ -8,6 +8,7 @@#include "cpc.h" #include "header.h" +#include "spi.h" #include "system.h" /**
@@ -126,12 +127,19 @@ static int __init cpc_init(void)if (err)bus_unregister (&cpc_bus); + err =cpc_spi_register_driver (); +if (err) { +cpc_system_drv_unregister (); +bus_unregister (&cpc_bus); + } +return err; }module_init (cpc_init); static void __exit cpc_exit(void) { +cpc_spi_unregister_driver ();cpc_system_drv_unregister ();bus_unregister (&cpc_bus); }
drivers/net/cpc/spi.c new file +550 -0
550 lines not on this page · raw message
drivers/net/cpc/spi.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025, Silicon Laboratories, Inc. +*/ + +#ifndef __CPC_SPI_H +#define __CPC_SPI_H + +int cpc_spi_register_driver (void ); +void cpc_spi_unregister_driver (void ); + +#endif
Signature · 1 line
2.49.0
Re: [RFC net-next 14/15] net: cpc: add SPI interface driver
Quoted 614 lines · Damien Riégel
This adds support for CPC over SPI. CPC uses a full-duplex protocol. Each frame transmission/reception is split into two parts:
- read and/or write header + header checksum
- read and/or write payload + payload checksumHeader frames are always 10 bytes (8 bytes of header and 2 bytes of checksum). The header contains the size of the payload to receive (size to transmit is already known). As the SPI device also has some processing to do when it receives a header, the SPI driver must wait for the interrupt line to be asserted before clocking the payload.
The SPI device always expects the chip select to be asserted and deasserted after a header, even if there are no payloads to transmit. This is used to keep headers transmission synchronized between host and device. As some controllers don't support doing that if there is nothing to transmit, a null byte is transmitted in that case and it will be ignored by the device.
If there are payloads, the driver will clock the maximum length of the two payloads.
Signed-off-by Damien Riégel <[email protected]>--- drivers/net/cpc/Kconfig | 3 +- drivers/net/cpc/Makefile | 2 +- drivers/net/cpc/main.c | 8 + drivers/net/cpc/spi.c | 550 +++++++++++++++++++++++++++++++++++++++ drivers/net/cpc/spi.h | 12 + 5 files changed, 573 insertions(+), 2 deletions(-) create mode 100644 drivers/net/cpc/spi.c create mode 100644 drivers/net/cpc/spi.hdrivers/net/cpc/Kconfig +2
-1@@ -2,7 +2,8 @@ menuconfig CPC tristate "Silicon Labs Co-Processor Communication (CPC) Protocol" - depends on NET + depends on NET && SPI + select CRC_ITU_T help Provide support for the CPC protocol to Silicon Labs EFR32 devices.drivers/net/cpc/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -cpc-y := endpoint.o header.o interface.o main.o protocol.o system.o +cpc-y := endpoint.o header.o interface.o main.o protocol.o spi.o system.o obj-$(CONFIG_CPC) += cpc.odrivers/net/cpc/main.c +8
-0@@ -8,6 +8,7 @@#include "cpc.h" #include "header.h" +#include "spi.h" #include "system.h" /** @@ -126,12 +127,19 @@ static int __init cpc_init(void)if (err)bus_unregister (&cpc_bus); + err =cpc_spi_register_driver (); +if (err) { +cpc_system_drv_unregister (); +bus_unregister (&cpc_bus); + } +return err; }module_init (cpc_init); static void __exit cpc_exit(void) { +cpc_spi_unregister_driver ();cpc_system_drv_unregister ();bus_unregister (&cpc_bus); }drivers/net/cpc/spi.c new file +519
-0@@ -0,0 +1,550 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025, Silicon Laboratories, Inc. +*/ + +#include <linux/atomic.h> +#include <linux/crc-itu-t.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/interrupt.h> +#include <linux/kthread.h> +#include <linux/minmax.h> +#include <linux/of.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spi/spi.h> +#include <linux/unaligned.h> +#include <linux/wait.h> + +#include "cpc.h" +#include "header.h" +#include "interface.h" +#include "spi.h" + +#define CPC_SPI_CSUM_SIZE 2 +#define CPC_SPI_INTERRUPT_MAX_WAIT_MS 1000 +#define CPC_SPI_MAX_PAYLOAD_SIZE 4096 + +struct cpc_spi { +struct spi_device *spi; +struct cpc_interface *intf; + +struct task_struct *task; +wait_queue_head_t event_queue; + +struct sk_buff *tx_skb; +u8 tx_csum[CPC_SPI_CSUM_SIZE ]; + +atomic_t event_cond; +struct sk_buff *rx_skb; +unsigned int rx_len; +u8 rx_header[CPC_HEADER_SIZE +CPC_SPI_CSUM_SIZE ]; +}; + +static bool buffer_is_zeroes (const u8 *buffer,size_t length) +{ +for (size_t i =0 ; i < length; i++) { +if (buffer[i] !=0 ) +return false; + } + +return true; +} + +static u16 cpc_spi_csum (const u8 *buffer,size_t length) +{ +return crc_itu_t (0 , buffer, length); +} + +static int cpc_spi_do_xfer_header (struct cpc_spi *ctx) +{ +struct spi_transfer xfer_header = { + .rx_buf = ctx->rx_header, + .len =CPC_HEADER_SIZE , + .speed_hz = ctx->spi->max_speed_hz, + }; +struct spi_transfer xfer_csum = { + .rx_buf = &ctx->rx_header[CPC_HEADER_SIZE ], + .len =sizeof (ctx->tx_csum), + .speed_hz = ctx->spi->max_speed_hz, + }; +enum cpc_frame_type type; +struct spi_message msg; +size_t payload_len =0 ; +struct sk_buff *skb; +u16 rx_csum; +u16 csum; +int ret; + +if (ctx->tx_skb) { +u16 tx_hdr_csum =cpc_spi_csum (ctx->tx_skb->data,CPC_HEADER_SIZE ); + +put_unaligned_le16 (tx_hdr_csum, ctx->tx_csum); + + xfer_header.tx_buf = ctx->tx_skb->data; + xfer_csum.tx_buf = ctx->tx_csum; + } + +spi_message_init (&msg); +spi_message_add_tail (&xfer_header, &msg); +spi_message_add_tail (&xfer_csum, &msg); + + ret =spi_sync (ctx->spi, &msg); +if (ret) +return ret; + +if (ctx->tx_skb) { +if (skb_headlen (ctx->tx_skb) ==CPC_HEADER_SIZE ) { +kfree_skb (ctx->tx_skb); + ctx->tx_skb =NULL ; + }else { +skb_pull (ctx->tx_skb,CPC_HEADER_SIZE ); + } + } + +if (buffer_is_zeroes (ctx->rx_header,CPC_HEADER_SIZE )) +return 0 ; + + rx_csum =get_unaligned_le16 (&ctx->rx_header[CPC_HEADER_SIZE ]); + csum =cpc_spi_csum (ctx->rx_header,CPC_HEADER_SIZE ); + +if (rx_csum != csum || !cpc_header_get_type (ctx->rx_header, &type)) { +/* +* If the header checksum is invalid, its length can't be trusted, receive +* the maximum payload length to recover from that situation. If the frame +* type cannot be extracted from the header, use same recovery mechanism. +*/ + ctx->rx_len =CPC_SPI_MAX_PAYLOAD_SIZE ; + +return 0 ; + } + +if (type ==CPC_FRAME_TYPE_DATA ) + payload_len =cpc_header_get_payload_len (ctx->rx_header) + +sizeof (ctx->tx_csum); + + skb =cpc_skb_alloc (payload_len,GFP_KERNEL ); +if (!skb) { +/* +* Failed to allocate memory to receive the payload. Driver must clock in +* these bytes even if there is no room, to keep the sender in sync. +*/ + ctx->rx_len = payload_len; + +return 0 ; + } + +memcpy (skb_push (skb,CPC_HEADER_SIZE ), ctx->rx_header,CPC_HEADER_SIZE ); + +if (payload_len) { + ctx->rx_skb = skb; + ctx->rx_len = payload_len; + }else { +cpc_interface_receive_frame (ctx->intf, skb); + } + +return 0 ; +} + +static int cpc_spi_do_xfer_notch (struct cpc_spi *ctx) +{ +struct spi_transfer xfer = { + .tx_buf = ctx->tx_csum, + .len =1 , + .speed_hz = ctx->spi->max_speed_hz, + }; +struct spi_message msg; + + ctx->tx_csum[0 ] =0 ; + +spi_message_init (&msg); +spi_message_add_tail (&xfer, &msg); + +return spi_sync (ctx->spi, &msg); +} + +static int cpc_spi_do_xfer_payload (struct cpc_spi *ctx) +{ +struct spi_transfer shared_xfer = { + .speed_hz = ctx->spi->max_speed_hz, + .rx_buf =NULL , + .tx_buf =NULL , + }; +struct spi_transfer pad_xfer1 = { + .speed_hz = ctx->spi->max_speed_hz, + .rx_buf =NULL , + .tx_buf =NULL , + }; +struct spi_transfer pad_xfer2 = { + .speed_hz = ctx->spi->max_speed_hz, + .rx_buf =NULL , + .tx_buf =NULL , + }; +unsigned int rx_len = ctx->rx_len; +unsigned int tx_data_len; +struct spi_message msg; +int ret; + +spi_message_init (&msg); +spi_message_add_tail (&shared_xfer, &msg); + +/* +* This can happen if header checksum was invalid. In that case, protocol +* mandates to be ready to receive the maximum number of bytes that the +* device is capable to send, in order to be sure its TX queue is flushed. +*/ +if (!ctx->rx_skb && rx_len) { + shared_xfer.rx_buf =kmalloc (rx_len,GFP_KERNEL ); +if (!shared_xfer.rx_buf) +return -ENOMEM ; + + shared_xfer.len = rx_len; + } + +if (ctx->rx_skb && !ctx->tx_skb) { + shared_xfer.rx_buf =skb_put (ctx->rx_skb, rx_len); + shared_xfer.len = rx_len; + } + +if (ctx->tx_skb) { +u16 csum = ctx->tx_skb->csum; + +put_unaligned_le16 (csum, ctx->tx_csum); + + tx_data_len = ctx->tx_skb->len; + + shared_xfer.tx_buf = ctx->tx_skb->data; + shared_xfer.len = tx_data_len; + +if (!ctx->rx_skb) { + pad_xfer1.tx_buf = ctx->tx_csum; + pad_xfer1.len =sizeof (ctx->tx_csum); + +spi_message_add_tail (&pad_xfer1, &msg); + } + } + +if (ctx->rx_skb && ctx->tx_skb) { +unsigned int shared_len; +unsigned int pad_len; + + shared_len =min (rx_len, tx_data_len); + pad_len =max (rx_len, tx_data_len) - shared_len; + + shared_xfer.rx_buf =skb_put (ctx->rx_skb, shared_len); + shared_xfer.len = shared_len; + +if (rx_len < tx_data_len) { +/* +* |------- RX BUFFER + RX CSUM ------| +* |------------------- TX BUFFER ------------|---- TX CSUM ----| +* +* | SHARED | +* | PAD 1 | +* | PAD 2 | +*/ + pad_xfer1.rx_buf =NULL ; + pad_xfer1.tx_buf = ctx->tx_skb->data + shared_len; + pad_xfer1.len = pad_len; + + pad_xfer2.rx_buf =NULL ; + pad_xfer2.tx_buf = ctx->tx_csum; + pad_xfer2.len =sizeof (ctx->tx_csum); + +spi_message_add_tail (&pad_xfer1, &msg); +spi_message_add_tail (&pad_xfer2, &msg); + }else if (rx_len == tx_data_len) { +/* +* |------------- RX BUFFER + RX CSUM ---------| +* |------------------- TX BUFFER -------------|---- TX CSUM ---| +* +* | SHARED | +* | PAD 1 | +*/ + pad_xfer1.rx_buf =NULL ; + pad_xfer1.tx_buf = ctx->tx_csum; + pad_xfer1.len =sizeof (ctx->tx_csum); + +spi_message_add_tail (&pad_xfer1, &msg); + }else if (rx_len == tx_data_len +1 ) { +/* +* |----------------- RX BUFFER + RX CSUM ----------------| +* |------------------- TX BUFFER -------------|---- TX CSUM ---| +* +* | SHARED | +* | PAD 1 | +* | PAD 2 | +*/ + pad_xfer1.tx_buf = ctx->tx_csum; + pad_xfer1.rx_buf =skb_put (ctx->rx_skb,1 ); + pad_xfer1.len =1 ; + + pad_xfer2.tx_buf = &ctx->tx_csum[1 ]; + pad_xfer2.rx_buf =NULL ; + pad_xfer2.len =1 ; + +spi_message_add_tail (&pad_xfer1, &msg); +spi_message_add_tail (&pad_xfer2, &msg); + }else { +/* +* |----------------------------- RX BUFFER + RX CSUM -------------------| +* |------------------- TX BUFFER -------------|---- TX CSUM ---| +* +* | SHARED | +* | PAD 1 | +* | PAD 2 | +*/ + pad_xfer1.tx_buf = ctx->tx_csum; + pad_xfer1.rx_buf =skb_put (ctx->rx_skb,sizeof (ctx->tx_csum)); + pad_xfer1.len =sizeof (ctx->tx_csum); + + pad_xfer2.tx_buf =NULL ; + pad_xfer2.rx_buf =skb_put (ctx->rx_skb, pad_len -sizeof (ctx->tx_csum)); + pad_xfer2.len = pad_len -sizeof (ctx->tx_csum); + +spi_message_add_tail (&pad_xfer1, &msg); +spi_message_add_tail (&pad_xfer2, &msg); + } + } + + ret =spi_sync (ctx->spi, &msg); + +if (ctx->tx_skb) { +kfree_skb (ctx->tx_skb); + ctx->tx_skb =NULL ; + } + +if (ctx->rx_skb) { +unsigned char *csum_ptr; +u16 expected_csum; +u16 csum; + +if (ret) { +kfree_skb (ctx->rx_skb); + goto exit; + } + + csum_ptr =skb_tail_pointer (ctx->rx_skb) -sizeof (csum); + csum =get_unaligned_le16 (csum_ptr); + + expected_csum =cpc_spi_csum (ctx->rx_skb->data +CPC_HEADER_SIZE , + ctx->rx_len -sizeof (csum)); + +if (csum == expected_csum) { +skb_trim (ctx->rx_skb, ctx->rx_skb->len -sizeof (csum)); + +cpc_interface_receive_frame (ctx->intf, ctx->rx_skb); + }else { +kfree_skb (ctx->rx_skb); + } + } + +exit: + ctx->rx_skb =NULL ; + ctx->rx_len =0 ; + +return ret; +} + +static int cpc_spi_do_xfer_thread (void *data) +{ +struct cpc_spi *ctx = data; +bool xfer_idle = true; +int ret; + +while (!kthread_should_stop ()) { +if (xfer_idle) { + ret =wait_event_interruptible (ctx->event_queue, + (!cpc_interface_tx_queue_empty (ctx->intf) || +atomic_read (&ctx->event_cond) ==1 || +kthread_should_stop ())); + +if (ret) +continue ; + +if (kthread_should_stop ()) +return 0 ; + +if (!ctx->tx_skb) + ctx->tx_skb =cpc_interface_dequeue (ctx->intf); + +/* +* Reset thread event right before transmission to prevent interrupts that +* happened while the thread was already awake to wake up the thread again, +* as the event is going to be handled by this iteration. +*/ +atomic_set (&ctx->event_cond,0 ); + + ret =cpc_spi_do_xfer_header (ctx); +if (!ret) + xfer_idle = false; + }else { + ret =wait_event_timeout (ctx->event_queue, + (atomic_read (&ctx->event_cond) ==1 || +kthread_should_stop ()), +msecs_to_jiffies (CPC_SPI_INTERRUPT_MAX_WAIT_MS )); +if (ret ==0 ) { +dev_err_once (&ctx->spi->dev,"device didn't assert interrupt in a timely manner\n" ); +continue ; + } + +atomic_set (&ctx->event_cond,0 ); + +if (!ctx->tx_skb && !ctx->rx_skb) + ret =cpc_spi_do_xfer_notch (ctx); +else + ret =cpc_spi_do_xfer_payload (ctx); + +if (!ret) + xfer_idle = true; + } + } + +return 0 ; +} + +static irqreturn_t cpc_spi_irq_handler (int irq,void *data) +{ +struct cpc_spi *ctx = data; + +atomic_set (&ctx->event_cond,1 ); +wake_up (&ctx->event_queue); + +return IRQ_HANDLED ; +} + +static int cpc_spi_ops_wake_tx (struct cpc_interface *intf) +{ +struct cpc_spi *ctx =cpc_interface_get_priv (intf); + +wake_up_interruptible (&ctx->event_queue); + +return 0 ; +} + +static void cpc_spi_ops_csum (struct sk_buff *skb) +{ + skb->csum =cpc_spi_csum (skb->data, skb->len); +} + +static const struct cpc_interface_ops spi_intf_cpc_ops = { + .wake_tx = cpc_spi_ops_wake_tx, + .csum = cpc_spi_ops_csum, +}; + +static int cpc_spi_probe (struct spi_device *spi) +{ +struct cpc_interface *intf; +struct cpc_spi *ctx; +int err; + +if (!spi->irq) { +dev_err (&spi->dev,"cannot function without IRQ, please provide one\n" ); +return -EINVAL ; + } + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return -ENOMEM ; + + intf =cpc_interface_alloc (&spi->dev, &spi_intf_cpc_ops, ctx); +if (IS_ERR (intf)) { +kfree (ctx); + +return PTR_ERR (intf); + } + +spi_set_drvdata (spi, ctx); + + ctx->spi = spi; + ctx->intf = intf; + + ctx->tx_skb =NULL ; + +atomic_set (&ctx->event_cond,0 ); + ctx->rx_skb =NULL ; + +init_waitqueue_head (&ctx->event_queue); + + err =cpc_interface_register (intf); +if (err) + goto put_interface; + + err =request_irq (spi->irq, cpc_spi_irq_handler,IRQF_TRIGGER_FALLING , +dev_name (&spi->dev), ctx); +if (err) + goto unregister_interface; + + ctx->task =kthread_run (cpc_spi_do_xfer_thread, ctx,"%s" , +dev_name (&spi->dev)); +if (IS_ERR (ctx->task)) { + err =PTR_ERR (ctx->task); + goto free_irq; + } + +return 0 ; + +free_irq: +free_irq (spi->irq, ctx); + +unregister_interface: +cpc_interface_unregister (intf); + +put_interface: +cpc_interface_put (intf); + +kfree (ctx); + +return err; +} + +static void cpc_spi_remove (struct spi_device *spi) +{ +struct cpc_spi *ctx =spi_get_drvdata (spi); +struct cpc_interface *intf = ctx->intf; + +kthread_stop (ctx->task); +free_irq (spi->irq, ctx); +cpc_interface_unregister (intf); +kfree (ctx); +} + +static const struct of_device_id cpc_dt_ids[] = { + { .compatible ="silabs,cpc-spi" }, + {}, +}; +MODULE_DEVICE_TABLE (of, cpc_dt_ids); + +static const struct spi_device_id cpc_spi_ids[] = {
drivers/net/cpc/spi.c line 529
Quoted 10 lines
drivers/net/cpc/spi.c new file +10
-0+ { .name = "cpc-spi" }, + {}, +}; +MODULE_DEVICE_TABLE (spi, cpc_spi_ids); + +static struct spi_driver cpc_spi_driver = { + .driver = { + .name ="cpc-spi" , + .of_match_table = cpc_dt_ids, + },
Quoting an earlier patch:
Quoted 3 lines
As a very basic matching mechanism, the bus will match an endpoint with its driver if driver's name (driver.name attribute) matches endpoint's name.
Don't you want silabs in the name, so you can tell it from some other vendors SPI bus?
Andrew
kernel test robot
build botRe: [RFC net-next 14/15] net: cpc: add SPI interface driver
In reply to Damien Riégelkernel test robot noticed the following build warnings:
Hi Damien,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on robh/for-next]
[also build test WARNING on net/main linus/master v6.15-rc6 next-20250509] [cannot apply to net-next/main]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Damien-Ri-gel/net-cpc-add-base-skeleton-driver/20250512-093831 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/20250512012748.79749-15-damien.riegel%40silabs.com patch subject: [RFC net-next 14/15] net: cpc: add SPI interface driver config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20250512/[email protected]/config) compiler: sh4-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250512/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/net/cpc/spi.c:519:35: warning: 'cpc_spi_ids' defined but not used [-Wunused-const-variable=]
519 | static const struct spi_device_id cpc_spi_ids[] = {
| ^~~~~~~~~~~vim +/cpc_spi_ids +519 drivers/net/cpc/spi.c
518
> 519 static const struct spi_device_id cpc_spi_ids[] = { 520 { .name = "cpc-spi" },
521 {},
522 };
523 MODULE_DEVICE_TABLE(spi, cpc_spi_ids);
524
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC 15/15 net: cpc: add Bluetooth HCI driver
In reply to Damien RiégelAdd support for Bluetooth HCI driver. As most of the protocol is already handled by the remote endpoint, this driver is just doing some glue to plug into CPC.
--- drivers/net/cpc/Kconfig | 2 +- drivers/net/cpc/Makefile | 2 +- drivers/net/cpc/ble.c | 147 +++++++++++++++++++++++++++++++++++++++ drivers/net/cpc/ble.h | 14 ++++ drivers/net/cpc/main.c | 23 ++++-- 5 files changed, 181 insertions(+), 7 deletions(-) create mode 100644 drivers/net/cpc/ble.c create mode 100644 drivers/net/cpc/ble.h
drivers/net/cpc/Kconfig +1 -1
@@ -2,7 +2,7 @@ menuconfig CPC tristate "Silicon Labs Co-Processor Communication (CPC) Protocol" - depends on NET && SPI + depends on NET && SPI && BT select CRC_ITU_T help Provide support for the CPC protocol to Silicon Labs EFR32 devices.
drivers/net/cpc/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -cpc-y := endpoint.o header.o interface.o main.o protocol.o spi.o system.o +cpc-y := ble.o endpoint.o header.o interface.o main.o protocol.o spi.o system.o obj-$(CONFIG_CPC) += cpc.o
drivers/net/cpc/ble.c new file +147 -0
147 lines not on this page · raw message
drivers/net/cpc/ble.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025, Silicon Laboratories, Inc. +*/ + +#ifndef __CPC_BLE_H +#define __CPC_BLE_H + +#define CPC_BLUETOOTH_ENDPOINT_NAME "silabs,cpc-ble" + +int cpc_ble_drv_register (void ); +void cpc_ble_drv_unregister (void ); + +#endif
drivers/net/cpc/main.c +18 -5
@@ -7,6 +7,7 @@#include <linux/module.h> #include "cpc.h" +#include "ble.h" #include "header.h" #include "spi.h" #include "system.h"
@@ -125,13 +126,24 @@ static int __init cpc_init(void) err =cpc_system_drv_register ();if (err) -bus_unregister (&cpc_bus); + goto unregister_bus; + + err =cpc_ble_drv_register (); +if (err) + goto unregister_system_driver; err =cpc_spi_register_driver (); -if (err) { -cpc_system_drv_unregister (); -bus_unregister (&cpc_bus); - } +if (err) + goto unregister_ble_driver; + +return 0 ; + +unregister_ble_driver: +cpc_ble_drv_unregister (); +unregister_system_driver: +cpc_system_drv_unregister (); +unregister_bus: +bus_unregister (&cpc_bus);return err; }
@@ -140,6 +152,7 @@ module_init(cpc_init); static void __exit cpc_exit(void) {cpc_spi_unregister_driver (); +cpc_ble_drv_unregister ();cpc_system_drv_unregister ();bus_unregister (&cpc_bus); }
Signature · 1 line
2.49.0
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
The core of Greybus is already in the kernel, with some more bits being in staging. I don't know it too well, but at first glance it looks very similar. We should not duplicate that.
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Why should we add a vendor implementation when we already appear to have something which does most of what is needed?
Andrew
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.
https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.
https://www.ti.com/product/CC2674R10
TI has a similar device.
And maybe there are others?
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
And maybe a dumb question... How do transfers get out of order over SPI and SDIO? If you look at the Open Alliance TC6 specification for Ethernet over SPI, it does not have any issues with ordering.
Andrew
Quoted 63 lines · Andrew Lunn
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.https://www.ti.com/product/CC2674R10
TI has a similar device.And maybe there are others?
Quoted 8 lines
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
I get the sentiment that we don't want every single vendor to push their own protocols that are ever so slightly different. To be honest, I don't know if Greybus can be extended for that use case, or if it's something they are interested in supporting. I've subscribed to greybus-dev so hopefully my email will get through this time (previous one is pending approval).
Unfortunately, we're deep down the CPC road, especially on the firmware side. Blame on me for not sending the RFC sooner and getting feedback earlier, but if we have to massively change our course of action we need some degree of confidence that this is a viable alternative for achieving high-throughput for WiFi over SDIO. I would really value any input from the Greybus folks on this.
Quoted 3 lines
And maybe a dumb question... How do transfers get out of order over SPI and SDIO? If you look at the Open Alliance TC6 specification for Ethernet over SPI, it does not have any issues with ordering.
Sorry I wasn't very clear about that. Of course packets are sent in order but several packets can be sent at once before being acknowledged and we might detect CRC errors on one of these packets. CPC takes care of only delivering valid packets, and packets that come after the one with CRC error won't be delivered to upper layer until the faulty one is retransmitted.
I took a look at the specification you mentioned and they completely delegate that to upper layers:
When transmit or receive frame bit errors are detected on the SPI, the retry of frames is performed by higher protocol layers that are beyond the scope of this specification. [1]
Our goal was to be agnostic of stacks on top of CPC and reliably transmit frames. To give a bit of context, CPC was originally derived from HDLC, which features detecting sequence gaps and retransmission. On top of that, we've now added the mechanism I mentioned in previous emails that throttle the host when the RCP is not ready to receive and process frames on an endpoint.
[1] https://opensig.org/wp-content/uploads/2023/12/OPEN_Alliance_10BASET1x_MAC-PHY_Serial_Interface_V1.1.pdf (Section 7.3.1)
Quoted 80 lines · Damien Riégel
Quoted 63 lines · Andrew Lunn
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.https://www.ti.com/product/CC2674R10
TI has a similar device.And maybe there are others?
Quoted 8 lines
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
I get the sentiment that we don't want every single vendor to push their own protocols that are ever so slightly different. To be honest, I don't know if Greybus can be extended for that use case, or if it's something they are interested in supporting. I've subscribed to greybus-dev so hopefully my email will get through this time (previous one is pending approval).
Quoted 6 lines
Unfortunately, we're deep down the CPC road, especially on the firmware side. Blame on me for not sending the RFC sooner and getting feedback earlier, but if we have to massively change our course of action we need some degree of confidence that this is a viable alternative for achieving high-throughput for WiFi over SDIO. I would really value any input from the Greybus folks on this.
So what you are looking for is a standard way to "tunnel" SDIO over some other physical transport, right? If so, then yes, please use Greybus as that is exactly what it was designed for.
If there is a throughput issue with the sdio implementation on Greybus, we can address it by fixing up the code to go faster, I don't recall there ever being any real benchmarking happening for that protocol in the past as the physical layer that we were using for Greybus at the time (MIPI) was very fast, the bottleneck was usually either the host controller we were using for Greybus, OR on the firmware side in the device itself (i.e. turning Greybus packets into SDIO commands, as SDIO was pretty slow.)
thanks,
greg k-h
Quoted 88 lines · Greg Kroah-Hartman
Quoted 80 lines · Damien Riégel
Quoted 63 lines · Andrew Lunn
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.https://www.ti.com/product/CC2674R10
TI has a similar device.And maybe there are others?
Quoted 8 lines
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
I get the sentiment that we don't want every single vendor to push their own protocols that are ever so slightly different. To be honest, I don't know if Greybus can be extended for that use case, or if it's something they are interested in supporting. I've subscribed to greybus-dev so hopefully my email will get through this time (previous one is pending approval).
Quoted 6 lines
Unfortunately, we're deep down the CPC road, especially on the firmware side. Blame on me for not sending the RFC sooner and getting feedback earlier, but if we have to massively change our course of action we need some degree of confidence that this is a viable alternative for achieving high-throughput for WiFi over SDIO. I would really value any input from the Greybus folks on this.
Quoted 3 lines
So what you are looking for is a standard way to "tunnel" SDIO over some other physical transport, right? If so, then yes, please use Greybus as that is exactly what it was designed for.
No, we want to use SDIO as physical transport. To use the Greybus terminology, our MCUs would act as modules with a single interface, and that interface would have "radio" bundles for each of the supported stack.
So we want to expose our radio stacks in Linux and Greybus doesn't define protocols for that, so that's kind of uncharted territories and we were wondering if Greybus would be the right tool for that. I hope the situation is a bit clearer now.
Quoted 98 lines · Damien Riégel
Quoted 88 lines · Greg Kroah-Hartman
Quoted 80 lines · Damien Riégel
Quoted 63 lines · Andrew Lunn
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.https://www.ti.com/product/CC2674R10
TI has a similar device.And maybe there are others?
Quoted 8 lines
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
I get the sentiment that we don't want every single vendor to push their own protocols that are ever so slightly different. To be honest, I don't know if Greybus can be extended for that use case, or if it's something they are interested in supporting. I've subscribed to greybus-dev so hopefully my email will get through this time (previous one is pending approval).
Quoted 6 lines
Unfortunately, we're deep down the CPC road, especially on the firmware side. Blame on me for not sending the RFC sooner and getting feedback earlier, but if we have to massively change our course of action we need some degree of confidence that this is a viable alternative for achieving high-throughput for WiFi over SDIO. I would really value any input from the Greybus folks on this.
Quoted 3 lines
So what you are looking for is a standard way to "tunnel" SDIO over some other physical transport, right? If so, then yes, please use Greybus as that is exactly what it was designed for.
No, we want to use SDIO as physical transport. To use the Greybus terminology, our MCUs would act as modules with a single interface, and that interface would have "radio" bundles for each of the supported stack.
Quoted 4 lines
So we want to expose our radio stacks in Linux and Greybus doesn't define protocols for that, so that's kind of uncharted territories and we were wondering if Greybus would be the right tool for that. I hope the situation is a bit clearer now.
Yes, greybus does not expose a "wifi" protocol as that is way too device specific, sorry.
So this just would be like any other normal SDIO wifi device then, shouldn't be anything special, right?
thanks,
greg k-h
Quoted 104 lines · Greg Kroah-Hartman
Quoted 98 lines · Damien Riégel
Quoted 88 lines · Greg Kroah-Hartman
Quoted 80 lines · Damien Riégel
Quoted 63 lines · Andrew Lunn
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.https://www.ti.com/product/CC2674R10
TI has a similar device.And maybe there are others?
Quoted 8 lines
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
I get the sentiment that we don't want every single vendor to push their own protocols that are ever so slightly different. To be honest, I don't know if Greybus can be extended for that use case, or if it's something they are interested in supporting. I've subscribed to greybus-dev so hopefully my email will get through this time (previous one is pending approval).
Quoted 6 lines
Unfortunately, we're deep down the CPC road, especially on the firmware side. Blame on me for not sending the RFC sooner and getting feedback earlier, but if we have to massively change our course of action we need some degree of confidence that this is a viable alternative for achieving high-throughput for WiFi over SDIO. I would really value any input from the Greybus folks on this.
Quoted 3 lines
So what you are looking for is a standard way to "tunnel" SDIO over some other physical transport, right? If so, then yes, please use Greybus as that is exactly what it was designed for.
No, we want to use SDIO as physical transport. To use the Greybus terminology, our MCUs would act as modules with a single interface, and that interface would have "radio" bundles for each of the supported stack.
Quoted 4 lines
So we want to expose our radio stacks in Linux and Greybus doesn't define protocols for that, so that's kind of uncharted territories and we were wondering if Greybus would be the right tool for that. I hope the situation is a bit clearer now.
Quoted 5 lines
Yes, greybus does not expose a "wifi" protocol as that is way too device specific, sorry.
So this just would be like any other normal SDIO wifi device then, shouldn't be anything special, right?
Wifi is just one of the radio stacks that can be present but there can be other radio stacks running on the same device and sharing the same physical transport, like Bluetooth, Zigbee, or OpenThread. The goal of CPC (our custom protocol) is to multiplex all these protocols over the same physical bus.
I think Andrew pulled Greybus in the discussion because there is some overlap between Greybus and CPC:
- Greybus has bundles and CPorts, CPC only has "endpoints", which would be the equivalent of a bundle with a single cport
- discoverability of Greybus bundles/CPC endpoints by the host
- multiple bundles/endpoints might coexist in the same module/CPC-enabled device
- bundles/endpoints are independent from each other and each has its own dedicated driver
Greybus goes a step further and specs some protocols like GPIO or UART. CPC doesn't spec what goes over endpoints because it's geared towards radio applications and as you said, it's very device/stack specific. Once an endpoint is connected, CPC just passes a bidirectionnal stream of data between the two ends, which are free to do whatever they want with it. A good example of that is the bluetooth driver that's part of this RFC [1]. I hope my explanations make sense.
Quoted 10 lines
I think Andrew pulled Greybus in the discussion because there is some overlap between Greybus and CPC:
- Greybus has bundles and CPorts, CPC only has "endpoints", which would be the equivalent of a bundle with a single cport
- discoverability of Greybus bundles/CPC endpoints by the host
- multiple bundles/endpoints might coexist in the same module/CPC-enabled device
- bundles/endpoints are independent from each other and each has its own dedicated driver
Quoted 3 lines
Greybus goes a step further and specs some protocols like GPIO or UART. CPC doesn't spec what goes over endpoints because it's geared towards radio applications and as you said, it's very device/stack specific.
Is it device specific? Look at your Bluetooth implementation. I don't see anything device specific in it. That should work for any of the vendors of similar chips to yours.
For 802.15.4, Linux defines:
struct ieee802154_ops {
struct module *owner;
int (*start)(struct ieee802154_hw *hw);
void (*stop)(struct ieee802154_hw *hw);
int (*xmit_sync)(struct ieee802154_hw *hw,
struct sk_buff *skb);
int (*xmit_async)(struct ieee802154_hw *hw,
struct sk_buff *skb);
int (*ed)(struct ieee802154_hw *hw, u8 *level);
int (*set_channel)(struct ieee802154_hw *hw, u8 page,
u8 channel);
int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
struct ieee802154_hw_addr_filt *filt,
unsigned long changed);
int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm);
int (*set_lbt)(struct ieee802154_hw *hw, bool on);
int (*set_cca_mode)(struct ieee802154_hw *hw,
const struct wpan_phy_cca *cca);
int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm);
int (*set_csma_params)(struct ieee802154_hw *hw,
u8 min_be, u8 max_be, u8 retries);
int (*set_frame_retries)(struct ieee802154_hw *hw,
s8 retries);
int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
const bool on);
};Many of these are optional, but this gives an abstract representation of a device, which is should be possible to turn into a protocol talked over a transport bus like SPI or SDIO.
This also comes back to my point of there being at least four vendors of devices like yours. Linux does not want four or more implementations of this, each 90% the same, just a different way of converting this structure of operations into messages over a transport bus.
You have to define the protocol. Mainline needs that so when the next vendor comes along, we can point at your protocol and say that is how it has to be implemented in Mainline. Make your firmware on the SoC understand it. You have the advantage that you are here first, you get to define that protocol, but you do need to clearly define it.
You have listed how your implementation is similar to Greybus. You say what is not so great is streaming, i.e. the bulk data transfer needed to implement xmit_sync() and xmit_async() above. Greybus is too much RPC based. RPCs are actually what you want for most of the operations listed above, but i agree for data, in order to keep the transport fully loaded, you want double buffering. However, that appears to be possible with the current Greybus code.
gb_operation_unidirectional_timeout() says:
* Note that successful send of a unidirectional operation does not imply that
* the request as actually reached the remote end of the connection. */
So long as you are doing your memory management correctly, i don't see why you cannot implement double buffering in the transport driver.
I also don't see why you cannot extend the Greybus upper API and add a true gb_operation_unidirectional_async() call.
You also said that lots of small transfers are inefficient, and you wanted to combine small high level messages into one big transport layer message. This is something you frequently see with USB Ethernet dongles. The Ethernet driver puts a number of small Ethernet packets into one USB URB. The USB layer itself has no idea this is going on. I don't see why the same cannot be done here, greybus itself does not need to be aware of the packet consolidation.
Andrew
Quoted 11 lines · Andrew Lunn
This also comes back to my point of there being at least four vendors of devices like yours. Linux does not want four or more implementations of this, each 90% the same, just a different way of converting this structure of operations into messages over a transport bus.
You have to define the protocol. Mainline needs that so when the next vendor comes along, we can point at your protocol and say that is how it has to be implemented in Mainline. Make your firmware on the SoC understand it. You have the advantage that you are here first, you get to define that protocol, but you do need to clearly define it.
I understand that this is the preferred way and I'll push internally for going that direction. That being said, Greybus seems to offer the capability to have a custom driver for a given PID/VID, if a module doesn't implement a Greybus-standardized protocol. Would a custom Greybus driver for, just as an example, our Wifi stack be an acceptable option?
Quoted 14 lines
You have listed how your implementation is similar to Greybus. You say what is not so great is streaming, i.e. the bulk data transfer needed to implement
xmit_sync()andxmit_async()above. Greybus is too much RPC based. RPCs are actually what you want for most of the operations listed above, but i agree for data, in order to keep the transport fully loaded, you want double buffering. However, that appears to be possible with the current Greybus code.
gb_operation_unidirectional_timeout()says:* Note that successful send of a unidirectional operation does not imply that
* the request as actually reached the remote end of the connection. */
Quoted 5 lines
So long as you are doing your memory management correctly, i don't see why you cannot implement double buffering in the transport driver.
I also don't see why you cannot extend the Greybus upper API and add a true
gb_operation_unidirectional_async()call.
Just because touching a well established subsystem is scary, but I understand that we're allowed to make changes that make sense.
Quoted 7 lines
You also said that lots of small transfers are inefficient, and you wanted to combine small high level messages into one big transport layer message. This is something you frequently see with USB Ethernet dongles. The Ethernet driver puts a number of small Ethernet packets into one USB URB. The USB layer itself has no idea this is going on. I don't see why the same cannot be done here, greybus itself does not need to be aware of the packet consolidation.
Yeah, so in this design, CPC would really be limited to the transport bus (SPI for now), to do packet consolidation and managing RCP available buffers. I think at this point, the next step is to come up with a proof of concept of Greybus over CPC and see if that works or not.
Let me add that I sincerely appreciate that you took the time to review this RFC and provided an upstream-compatible alternative to what we proposed, so thank you for that.
Damien
Quoted 13 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
This also comes back to my point of there being at least four vendors of devices like yours. Linux does not want four or more implementations of this, each 90% the same, just a different way of converting this structure of operations into messages over a transport bus.
You have to define the protocol. Mainline needs that so when the next vendor comes along, we can point at your protocol and say that is how it has to be implemented in Mainline. Make your firmware on the SoC understand it. You have the advantage that you are here first, you get to define that protocol, but you do need to clearly define it.
Quoted 6 lines
I understand that this is the preferred way and I'll push internally for going that direction. That being said, Greybus seems to offer the capability to have a custom driver for a given PID/VID, if a module doesn't implement a Greybus-standardized protocol. Would a custom Greybus driver for, just as an example, our Wifi stack be an acceptable option?
It is not clear to me why a custom driver would be needed. You need to implement a Linux WiFi driver. That API is well defined, although you might only need a subset. What do you need in addition to that?
Quoted 8 lines
Quoted 5 lines
So long as you are doing your memory management correctly, i don't see why you cannot implement double buffering in the transport driver.
I also don't see why you cannot extend the Greybus upper API and add a true
gb_operation_unidirectional_async()call.Just because touching a well established subsystem is scary, but I understand that we're allowed to make changes that make sense.
There are developers here to help review such changes. And extending existing Linux subsystems is how Linux has become the dominant OS. You are getting it for free, building on the work of others, so it is not too unreasonable to contribute a little bit back by making it even better.
Quoted 9 lines
Quoted 8 lines
You also said that lots of small transfers are inefficient, and you wanted to combine small high level messages into one big transport layer message. This is something you frequently see with USB Ethernet dongles. The Ethernet driver puts a number of small Ethernet packets into one USB URB. The USB layer itself has no idea this is going on. I don't see why the same cannot be done here, greybus itself does not need to be aware of the packet consolidation.
Quoted 4 lines
Yeah, so in this design, CPC would really be limited to the transport bus (SPI for now), to do packet consolidation and managing RCP available buffers. I think at this point, the next step is to come up with a proof of concept of Greybus over CPC and see if that works or not.
You need to keep the lower level generic. I would not expect anything Silabs specific in how you transport Greybus over SPI or SDIO. As part of gb_operation_unidirectional_async() you need to think about flow control, you need some generic mechanism to indicate receive buffer availability in the device, and when to pause a while to let the device catch up, but there is no reason TI, Microchip, Nordic, etc should not be able to use the same encapsulation scheme.
Andrew
Quoted 21 lines · Andrew Lunn
Quoted 13 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
This also comes back to my point of there being at least four vendors of devices like yours. Linux does not want four or more implementations of this, each 90% the same, just a different way of converting this structure of operations into messages over a transport bus.
You have to define the protocol. Mainline needs that so when the next vendor comes along, we can point at your protocol and say that is how it has to be implemented in Mainline. Make your firmware on the SoC understand it. You have the advantage that you are here first, you get to define that protocol, but you do need to clearly define it.
Quoted 6 lines
I understand that this is the preferred way and I'll push internally for going that direction. That being said, Greybus seems to offer the capability to have a custom driver for a given PID/VID, if a module doesn't implement a Greybus-standardized protocol. Would a custom Greybus driver for, just as an example, our Wifi stack be an acceptable option?
Quoted 3 lines
It is not clear to me why a custom driver would be needed. You need to implement a Linux WiFi driver. That API is well defined, although you might only need a subset. What do you need in addition to that?
This "custom driver" is needed for CPC too, right? You need some way to translate what's happening in the kernel into directions sent over your transport to the hardware on the other side.
Don't worry about proposing changes to Greybus. But please do it incrementally, and share what you would like to do, so people can help steer you in the most promising direction.
-Alex
Quoted 38 lines
Quoted 8 lines
Quoted 5 lines
So long as you are doing your memory management correctly, i don't see why you cannot implement double buffering in the transport driver.
I also don't see why you cannot extend the Greybus upper API and add a true
gb_operation_unidirectional_async()call.Just because touching a well established subsystem is scary, but I understand that we're allowed to make changes that make sense.
There are developers here to help review such changes. And extending existing Linux subsystems is how Linux has become the dominant OS. You are getting it for free, building on the work of others, so it is not too unreasonable to contribute a little bit back by making it even better.
Quoted 9 lines
Quoted 8 lines
You also said that lots of small transfers are inefficient, and you wanted to combine small high level messages into one big transport layer message. This is something you frequently see with USB Ethernet dongles. The Ethernet driver puts a number of small Ethernet packets into one USB URB. The USB layer itself has no idea this is going on. I don't see why the same cannot be done here, greybus itself does not need to be aware of the packet consolidation.
Quoted 4 lines
Yeah, so in this design, CPC would really be limited to the transport bus (SPI for now), to do packet consolidation and managing RCP available buffers. I think at this point, the next step is to come up with a proof of concept of Greybus over CPC and see if that works or not.
You need to keep the lower level generic. I would not expect anything Silabs specific in how you transport Greybus over SPI or SDIO. As part of
gb_operation_unidirectional_async()you need to think about flow control, you need some generic mechanism to indicate receive buffer availability in the device, and when to pause a while to let the device catch up, but there is no reason TI, Microchip, Nordic, etc should not be able to use the same encapsulation scheme.Andrew
Quoted 47 lines · Andrew Lunn
Quoted 10 lines
I think Andrew pulled Greybus in the discussion because there is some overlap between Greybus and CPC:
- Greybus has bundles and CPorts, CPC only has "endpoints", which would be the equivalent of a bundle with a single cport
- discoverability of Greybus bundles/CPC endpoints by the host
- multiple bundles/endpoints might coexist in the same module/CPC-enabled device
- bundles/endpoints are independent from each other and each has its own dedicated driverQuoted 3 lines
Greybus goes a step further and specs some protocols like GPIO or UART. CPC doesn't spec what goes over endpoints because it's geared towards radio applications and as you said, it's very device/stack specific.
Is it device specific? Look at your Bluetooth implementation. I don't see anything device specific in it. That should work for any of the vendors of similar chips to yours.
For 802.15.4, Linux defines:
struct ieee802154_ops { struct module *owner; int (*start)(struct ieee802154_hw *hw); void (*stop)(struct ieee802154_hw *hw); int (*xmit_sync)(struct ieee802154_hw *hw, struct sk_buff *skb); int (*xmit_async)(struct ieee802154_hw *hw, struct sk_buff *skb); int (*ed)(struct ieee802154_hw *hw, u8 *level); int (*set_channel)(struct ieee802154_hw *hw, u8 page, u8 channel); int (*set_hw_addr_filt)(struct ieee802154_hw *hw, struct ieee802154_hw_addr_filt *filt, unsigned long changed); int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm); int (*set_lbt)(struct ieee802154_hw *hw, bool on); int (*set_cca_mode)(struct ieee802154_hw *hw, const struct wpan_phy_cca *cca); int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm); int (*set_csma_params)(struct ieee802154_hw *hw, u8 min_be, u8 max_be, u8 retries); int (*set_frame_retries)(struct ieee802154_hw *hw, s8 retries); int (*set_promiscuous_mode)(struct ieee802154_hw *hw, const bool on); };
Quoted 3 lines
Many of these are optional, but this gives an abstract representation of a device, which is should be possible to turn into a protocol talked over a transport bus like SPI or SDIO.
This is essentially how Greybus does things. It sets up drivers on the Linux side that translate callback functions into Greybus operations that get performed on target hardware on the remote module.
Quoted 11 lines
This also comes back to my point of there being at least four vendors of devices like yours. Linux does not want four or more implementations of this, each 90% the same, just a different way of converting this structure of operations into messages over a transport bus.
You have to define the protocol. Mainline needs that so when the next vendor comes along, we can point at your protocol and say that is how it has to be implemented in Mainline. Make your firmware on the SoC understand it. You have the advantage that you are here first, you get to define that protocol, but you do need to clearly define it.
I agree with all of this.
Quoted 9 lines
You have listed how your implementation is similar to Greybus. You say what is not so great is streaming, i.e. the bulk data transfer needed to implement
xmit_sync()andxmit_async()above. Greybus is too much RPC based. RPCs are actually what you want for most of the operations listed above, but i agree for data, in order to keep the transport fully loaded, you want double buffering. However, that appears to be possible with the current Greybus code.
gb_operation_unidirectional_timeout()says:
Yes, these are request messages that don't require a response. The acknowledgement is about when the host *sent it*, not when it got received. They're rarely used but I could see them being used this way. Still, you might be limited to 255 or so in-flight messages.
-Alex
Quoted 19 lines
* Note that successful send of a unidirectional operation does not imply that
* the request as actually reached the remote end of the connection. */So long as you are doing your memory management correctly, i don't see why you cannot implement double buffering in the transport driver.
I also don't see why you cannot extend the Greybus upper API and add a true
gb_operation_unidirectional_async()call.You also said that lots of small transfers are inefficient, and you wanted to combine small high level messages into one big transport layer message. This is something you frequently see with USB Ethernet dongles. The Ethernet driver puts a number of small Ethernet packets into one USB URB. The USB layer itself has no idea this is going on. I don't see why the same cannot be done here, greybus itself does not need to be aware of the packet consolidation.
Andrew
Quoted 8 lines
Quoted 8 lines
You have listed how your implementation is similar to Greybus. You say what is not so great is streaming, i.e. the bulk data transfer needed to implement
xmit_sync()andxmit_async()above. Greybus is too much RPC based. RPCs are actually what you want for most of the operations listed above, but i agree for data, in order to keep the transport fully loaded, you want double buffering. However, that appears to be possible with the current Greybus code.
Quoted 7 lines
Quoted 1 line
gb_operation_unidirectional_timeout()says:Yes, these are request messages that don't require a response. The acknowledgement is about when the host *sent it*, not when it got received. They're rarely used but I could see them being used this way. Still, you might be limited to 255 or so in-flight messages.
I don't actually see how you can have multiple messages in-flight, but maybe i'm missing something. It appears that upper layers pass the message down and then block on a completion. The signalling of that completion only happens when the message is on the wire. So it is all synchronous. In order to have multiple messages in-flight, the lower layer would have to copy the message, signal the completion, and then send the copy whenever the transport was free.
The network stack is however async by nature. The ndo_start_xmit call passes an skbuf. The data in the skbuf is setup for DMA transfer, and then ndo_start_xmit returns. Later, when the DMA has completed, the driver calls dev_kfree_skb() to say it has finished with the skb.
Ideally we want a similar async mechanism, which is why i suggested gb_operation_unidirectional_async(). Pass a message to Greybus, none blocking, and have a callback for when the message has hit the wire and the skb can be friend. The low level can then keep a list of skb's so it can quickly do back to back transfers over the transport to keep it busy.
Andrew
Quoted 73 lines · Damien Riégel
Quoted 63 lines · Andrew Lunn
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.https://www.ti.com/product/CC2674R10
TI has a similar device.And maybe there are others?
Quoted 8 lines
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
Quoted 6 lines
I get the sentiment that we don't want every single vendor to push their own protocols that are ever so slightly different. To be honest, I don't know if Greybus can be extended for that use case, or if it's something they are interested in supporting. I've subscribed to greybus-dev so hopefully my email will get through this time (previous one is pending approval).
Greybus was designed for a particular platform, but the intention was to make it extensible. It can be extended with new protocols, and I don't think anyone is opposed to that.
Quoted 6 lines
Unfortunately, we're deep down the CPC road, especially on the firmware side. Blame on me for not sending the RFC sooner and getting feedback earlier, but if we have to massively change our course of action we need some degree of confidence that this is a viable alternative for achieving high-throughput for WiFi over SDIO. I would really value any input from the Greybus folks on this.
I kind of assumed this. I'm sure Andrew's message was not that welcome for that reason, but he's right about trying to agree on something in common if possible. If Greybus can solve all your problems, the maintainers will support the code being modified to support what's needed.
(To be clear, I don't assume Greybus will solve all your problems. For example, UniPro provides a reliable transport, so that's what Greybus currently expects.)
I have no input on your throughput question at the moment.
-Alex
Quoted 26 lines
Quoted 3 lines
And maybe a dumb question... How do transfers get out of order over SPI and SDIO? If you look at the Open Alliance TC6 specification for Ethernet over SPI, it does not have any issues with ordering.
Sorry I wasn't very clear about that. Of course packets are sent in order but several packets can be sent at once before being acknowledged and we might detect CRC errors on one of these packets. CPC takes care of only delivering valid packets, and packets that come after the one with CRC error won't be delivered to upper layer until the faulty one is retransmitted.
I took a look at the specification you mentioned and they completely delegate that to upper layers:
When transmit or receive frame bit errors are detected on the SPI, the retry of frames is performed by higher protocol layers that are beyond the scope of this specification. [1]
Our goal was to be agnostic of stacks on top of CPC and reliably transmit frames. To give a bit of context, CPC was originally derived from HDLC, which features detecting sequence gaps and retransmission. On top of that, we've now added the mechanism I mentioned in previous emails that throttle the host when the RCP is not ready to receive and process frames on an endpoint.
[1] https://opensig.org/wp-content/uploads/2023/12/OPEN_Alliance_10BASET1x_MAC-PHY_Serial_Interface_V1.1.pdf (Section 7.3.1)
Quoted 98 lines · Alex Elder
Quoted 73 lines · Damien Riégel
Quoted 63 lines · Andrew Lunn
Quoted 22 lines · Damien Riégel
Quoted 11 lines · Andrew Lunn
Quoted 7 lines · Damien Riégel
Hi,
This patchset brings initial support for Silicon Labs CPC protocol, standing for Co-Processor Communication. This protocol is used by the EFR32 Series [1]. These devices offer a variety for radio protocols, such as Bluetooth, Z-Wave, Zigbee [2].
Before we get too deep into the details of the patches, please could you do a compare/contrast to Greybus.
Thank you for the prompt feedback on the RFC. We took a look at Greybus in the past and it didn't seem to fit our needs. One of the main use case that drove the development of CPC was to support WiFi (in coexistence with other radio stacks) over SDIO, and get the maximum throughput possible. We concluded that to achieve this we would need packet aggregation, as sending one frame at a time over SDIO is wasteful, and managing Radio Co-Processor available buffers, as sending frames that the RCP is not able to process would degrade performance.
Quoted 10 lines
Greybus don't seem to offer these capabilities. It seems to be more geared towards implementing RPC, where the host would send a command, and then wait for the device to execute it and to respond. For Greybus' protocols that implement some "streaming" features like audio or video capture, the data streams go to an I2S or CSI interface, but it doesn't seem to go through a CPort. So it seems to act as a backbone to connect CPorts together, but high-throughput transfers happen on other types of links. CPC is more about moving data over a physical link, guaranteeing ordered delivery and avoiding unnecessary transmissions if remote doesn't have the resources, it's much lower level than Greybus.
As is said, i don't know Greybus too well. I hope its Maintainers can comment on this.
Quoted 5 lines
Quoted 4 lines
Also, this patch adds Bluetooth, you talk about Z-Wave and Zigbee. But the EFR32 is a general purpose SoC, with I2C, SPI, PWM, UART. Greybus has support for these, although the code is current in staging. But for staging code, it is actually pretty good.
Quoted 7 lines
I agree with you that the EFR32 is a general purpose SoC and exposing all available peripherals would be great, but most customers buy it as an RCP module with one or more radio stacks enabled, and that's the situation we're trying to address. Maybe I introduced a framework with custom bus, drivers and endpoints where it was unnecessary, the goal is not to be super generic but only to support coexistence of our radio stacks.
This leads to my next problem.
https://www.nordicsemi.com/-/media/Software-and-other-downloads/Product-Briefs/nRF5340-SoC-PB.pdf
Nordic Semiconductor has what appears to be a similar device.https://www.microchip.com/en-us/products/wireless-connectivity/bluetooth-low-energy/microcontrollers
Microchip has a similar device as well.https://www.ti.com/product/CC2674R10
TI has a similar device.And maybe there are others?
Quoted 8 lines
Are we going to get a Silabs CPC, a Nordic CPC, a Microchip CPC, a TI CPC, and an ACME CPC?
How do we end up with one implementation?
Maybe Greybus does not currently support your streaming use case too well, but it is at least vendor neutral. Can it be extended for streaming?
Quoted 6 lines
I get the sentiment that we don't want every single vendor to push their own protocols that are ever so slightly different. To be honest, I don't know if Greybus can be extended for that use case, or if it's something they are interested in supporting. I've subscribed to greybus-dev so hopefully my email will get through this time (previous one is pending approval).
Greybus was designed for a particular platform, but the intention was to make it extensible. It can be extended with new protocols, and I don't think anyone is opposed to that.
Quoted 6 lines
Unfortunately, we're deep down the CPC road, especially on the firmware side. Blame on me for not sending the RFC sooner and getting feedback earlier, but if we have to massively change our course of action we need some degree of confidence that this is a viable alternative for achieving high-throughput for WiFi over SDIO. I would really value any input from the Greybus folks on this.
I kind of assumed this. I'm sure Andrew's message was not that welcome for that reason, but he's right about trying to agree on something in common if possible. If Greybus can solve all your problems, the maintainers will support the code being modified to support what's needed.
Quoted 3 lines
(To be clear, I don't assume Greybus will solve all your problems. For example, UniPro provides a reliable transport, so that's what Greybus currently expects.)
I don't really know about UniPro and I'm learning about it as the discussion goes, but one of the point listed on Wikipedia is "reliability - data errors detected and correctable via retransmission"
This is where CPC could come in, probably with a different name and a reduced scope, as a way to implement reliable transmission over UART, SPI, SDIO, by ensuring data errors are detected and packets retransmitted if necessary, and be limited to that.
What's missing for us in Greybus, as discussed in a subthread, is asynchronous operations to fit better with the network stack, but I think that could easily be added.
Quoted 8 lines
I don't really know about UniPro and I'm learning about it as the discussion goes, but one of the point listed on Wikipedia is "reliability - data errors detected and correctable via retransmission"
This is where CPC could come in, probably with a different name and a reduced scope, as a way to implement reliable transmission over UART, SPI, SDIO, by ensuring data errors are detected and packets retransmitted if necessary, and be limited to that.
You mentioned HDLC in the past. What is interesting is that HDLC is actually used in Greybus:
https://elixir.bootlin.com/linux/v6.15-rc7/source/drivers/greybus/gb-beagleplay.c#L581
I've no idea if its just for framing, or if there is also retries on errors, S-frames with flow and error control etc. There might be code you can reuse here.
Andrew
Quoted 9 lines · Andrew Lunn
Quoted 8 lines
I don't really know about UniPro and I'm learning about it as the discussion goes, but one of the point listed on Wikipedia is "reliability - data errors detected and correctable via retransmission"
This is where CPC could come in, probably with a different name and a reduced scope, as a way to implement reliable transmission over UART, SPI, SDIO, by ensuring data errors are detected and packets retransmitted if necessary, and be limited to that.
Quoted 8 lines
You mentioned HDLC in the past. What is interesting is that HDLC is actually used in Greybus:
https://elixir.bootlin.com/linux/v6.15-rc7/source/drivers/greybus/gb-beagleplay.c*L581
I've no idea if its just for framing, or if there is also retries on errors, S-frames with flow and error control etc. There might be code you can reuse here.
Yeah I've seen it when looking at Greybus, from what I could see it's only framing. There is a CRC check though, frames received that don't pass that check are not passed to Greybus layer.
Another aspect we would like to support is buffer management. In our implementation, each endpoint has its dedicated pool of RX buffers and the number of available buffers is advertised to the remote, so the Linux driver can delay transmission of packets if endpoints are out of RX buffers.
We decide to implement that mostly because that would get us the best throughtput possible. Sending a packet to an endpoint that doesn't have room for it means the packet will be dropped and we have to wait for a retransmission to occur, which degrades performance.