netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Damien Riégel" <damien.riegel@silabs.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Silicon Labs Kernel Team <linux-devel@silabs.com>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [RFC net-next 01/15] net: cpc: add base skeleton driver
Date: Sun, 11 May 2025 21:27:34 -0400	[thread overview]
Message-ID: <20250512012748.79749-2-damien.riegel@silabs.com> (raw)
In-Reply-To: <20250512012748.79749-1-damien.riegel@silabs.com>

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.

Signed-off-by: Damien Riégel <damien.riegel@silabs.com>
---
 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

diff --git a/MAINTAINERS b/MAINTAINERS
index 00e94bec401..8256ec0ff8a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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 <damien.riegel@silabs.com>
+R:	Silicon Labs Kernel Team <linux-devel@silabs.com>
+S:	Supported
+F:	drivers/net/cpc/*
+
 SILICON LABS WIRELESS DRIVERS (for WFxxx series)
 M:	Jérôme Pouiller <jerome.pouiller@silabs.com>
 S:	Supported
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 1fd5acdc73c..d78ca2f4de5 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -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"
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 13743d0e83b..19878d11c62 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -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
diff --git a/drivers/net/cpc/Kconfig b/drivers/net/cpc/Kconfig
new file mode 100644
index 00000000000..f31b6837b49
--- /dev/null
+++ b/drivers/net/cpc/Kconfig
@@ -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.
diff --git a/drivers/net/cpc/Makefile b/drivers/net/cpc/Makefile
new file mode 100644
index 00000000000..1ce7415f305
--- /dev/null
+++ b/drivers/net/cpc/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+cpc-y := interface.o main.o
+
+obj-$(CONFIG_CPC)	+= cpc.o
diff --git a/drivers/net/cpc/interface.c b/drivers/net/cpc/interface.c
new file mode 100644
index 00000000000..4fdc78a0868
--- /dev/null
+++ b/drivers/net/cpc/interface.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025, Silicon Laboratories, Inc.
+ */
+
+#include <linux/module.h>
+
+#include "interface.h"
+
+#define to_cpc_interface(d) container_of(d, struct cpc_interface, dev)
+
+static DEFINE_IDA(cpc_ida);
+
+/**
+ * cpc_intf_release() - Actual release of interface.
+ * @dev: Device embedded in struct cpc_interface
+ *
+ * This function should not be called directly, users are expected to use cpc_interface_put()
+ * instead. This function will be called when the last reference to the CPC device is released.
+ */
+static void cpc_intf_release(struct device *dev)
+{
+	struct cpc_interface *intf = to_cpc_interface(dev);
+
+	ida_free(&cpc_ida, intf->index);
+	kfree(intf);
+}
+
+/**
+ * cpc_interface_alloc() - Allocate memory for new CPC interface.
+ *
+ * @parent: Parent device.
+ * @ops: Callbacks for this device.
+ * @priv: Pointer to private structure associated with this device.
+ *
+ * Context: Process context as allocations are done with @GFP_KERNEL flag
+ *
+ * Return: allocated CPC interface or %NULL.
+ */
+struct cpc_interface *cpc_interface_alloc(struct device *parent,
+					  const struct cpc_interface_ops *ops,
+					  void *priv)
+{
+	struct cpc_interface *intf;
+
+	intf = kzalloc(sizeof(*intf), GFP_KERNEL);
+	if (!intf)
+		return NULL;
+
+	intf->index = ida_alloc(&cpc_ida, GFP_KERNEL);
+	if (intf->index < 0) {
+		kfree(intf);
+		return NULL;
+	}
+
+	intf->ops = ops;
+
+	intf->dev.parent = parent;
+	intf->dev.release = cpc_intf_release;
+
+	device_initialize(&intf->dev);
+
+	dev_set_name(&intf->dev, "cpc%d", intf->index);
+	dev_set_drvdata(&intf->dev, priv);
+
+	return intf;
+}
+
+/**
+ * cpc_interface_register() - Register CPC interface.
+ * @intf: CPC device to register.
+ *
+ * Context: Process context.
+ *
+ * Return: 0 if successful, otherwise a negative error code.
+ */
+int cpc_interface_register(struct cpc_interface *intf)
+{
+	int err;
+
+	err = device_add(&intf->dev);
+	if (err)
+		return err;
+
+	return 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);
+}
diff --git a/drivers/net/cpc/interface.h b/drivers/net/cpc/interface.h
new file mode 100644
index 00000000000..797f70119a8
--- /dev/null
+++ b/drivers/net/cpc/interface.h
@@ -0,0 +1,88 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025, Silicon Laboratories, Inc.
+ */
+
+#ifndef __CPC_INTERFACE_H
+#define __CPC_INTERFACE_H
+
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/skbuff.h>
+
+struct cpc_interface;
+struct cpc_interface_ops;
+
+/**
+ * struct cpc_interface - Representation of a CPC interface.
+ * @dev: Device structure for bookkeeping..
+ * @ops: Callbacks for this device.
+ * @index: Device index.
+ */
+struct cpc_interface {
+	struct device dev;
+
+	const struct cpc_interface_ops *ops;
+
+	int index;
+};
+
+/**
+ * struct cpc_interface_ops - Callbacks from CPC core to physical bus driver.
+ * @wake_tx: Called by CPC core to wake up the transmit task of that interface.
+ * @csum: Callback to calculate checksum over the payload.
+ *
+ * This structure contains various callbacks that the bus (SDIO, SPI) driver must implement.
+ */
+struct cpc_interface_ops {
+	int (*wake_tx)(struct cpc_interface *intf);
+	void (*csum)(struct sk_buff *skb);
+};
+
+struct cpc_interface *cpc_interface_alloc(struct device *parent,
+					  const struct cpc_interface_ops *ops,
+					  void *priv);
+
+int cpc_interface_register(struct cpc_interface *intf);
+void cpc_interface_unregister(struct cpc_interface *intf);
+
+/**
+ * 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;
+}
+
+/**
+ * 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.
+ * @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);
+}
+
+#endif
diff --git a/drivers/net/cpc/main.c b/drivers/net/cpc/main.c
new file mode 100644
index 00000000000..ba9ab1ccf63
--- /dev/null
+++ b/drivers/net/cpc/main.c
@@ -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 <damien.riegel@silabs.com>");
+MODULE_LICENSE("GPL");
-- 
2.49.0


  reply	other threads:[~2025-05-12  1:28 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12  1:27 [RFC net-next 00/15] Add support for Silicon Labs CPC Damien Riégel
2025-05-12  1:27 ` Damien Riégel [this message]
2025-05-12  2:13   ` [RFC net-next 01/15] net: cpc: add base skeleton driver Andrew Lunn
2025-05-12  1:27 ` [RFC net-next 02/15] net: cpc: add endpoint infrastructure Damien Riégel
2025-05-12  2:28   ` Andrew Lunn
2025-05-12  1:27 ` [RFC net-next 03/15] net: cpc: introduce CPC driver and bus Damien Riégel
2025-05-12  1:27 ` [RFC net-next 04/15] net: cpc: add protocol header structure and API Damien Riégel
2025-05-12  2:41   ` Andrew Lunn
2025-05-12  1:27 ` [RFC net-next 05/15] net: cpc: implement basic transmit path Damien Riégel
2025-05-12  1:27 ` [RFC net-next 06/15] net: cpc: implement basic receive path Damien Riégel
2025-05-12  1:27 ` [RFC net-next 07/15] net: cpc: implement sequencing and ack Damien Riégel
2025-05-12  1:27 ` [RFC net-next 08/15] net: cpc: add support for connecting endpoints Damien Riégel
2025-05-12  1:27 ` [RFC net-next 09/15] net: cpc: add support for RST frames Damien Riégel
2025-05-12  1:27 ` [RFC net-next 10/15] net: cpc: make disconnect blocking Damien Riégel
2025-05-12  1:27 ` [RFC net-next 11/15] net: cpc: add system endpoint Damien Riégel
2025-05-12  1:27 ` [RFC net-next 12/15] net: cpc: create system endpoint with a new interface Damien Riégel
2025-05-12  1:27 ` [RFC net-next 13/15] dt-bindings: net: cpc: add silabs,cpc-spi.yaml Damien Riégel
2025-05-14 21:38   ` Rob Herring
2025-05-12  1:27 ` [RFC net-next 14/15] net: cpc: add SPI interface driver Damien Riégel
2025-05-12  2:47   ` Andrew Lunn
2025-05-12  1:27 ` [RFC net-next 15/15] net: cpc: add Bluetooth HCI driver Damien Riégel
2025-05-12 17:07 ` [RFC net-next 00/15] Add support for Silicon Labs CPC Andrew Lunn
2025-05-13 21:15   ` Damien Riégel
2025-05-13 21:53     ` Andrew Lunn
2025-05-14 22:52       ` Damien Riégel
2025-05-15  7:49         ` Greg Kroah-Hartman
2025-05-15 15:00           ` Damien Riégel
2025-05-16  7:51             ` Greg Kroah-Hartman
2025-05-16 16:25               ` Damien Riégel
2025-05-18 15:23                 ` Andrew Lunn
2025-05-20  1:21                   ` Damien Riégel
2025-05-20 13:04                     ` Andrew Lunn
2025-05-22  2:46                       ` Alex Elder
2025-05-22  2:46                   ` Alex Elder
2025-05-22 18:11                     ` Andrew Lunn
2025-05-22  2:46         ` Alex Elder
2025-05-23 19:49           ` Damien Riégel
2025-05-23 20:06             ` Andrew Lunn
2025-05-23 20:38               ` Damien Riégel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250512012748.79749-2-damien.riegel@silabs.com \
    --to=damien.riegel@silabs.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-devel@silabs.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).