[PATCH net-next v2 1/3] net: ethernet: ti: RPMsg based shared memory ethernet driver
From: Yojana Mallik
Date: Fri May 31 2024 - 02:40:57 EST
From: Ravi Gunasekaran <r-gunasekaran@xxxxxx>
TI's K3 SoCs comprises heterogeneous processors (Cortex A, Cortex R).
When the ethernet controller is completely managed by a core (Cortex R)
running a flavor of RTOS, in a non virtualized environment, network traffic
tunnelling between heterogeneous processors can be realized by means of
RPMsg based shared memory ethernet driver. With the shared memory used
for the data plane and the RPMsg end point channel used for control plane.
inter-core-virt-eth driver is modelled as a RPMsg based shared
memory ethernet driver for such an use case.
As a first step, register the inter-core-virt-eth as a RPMsg driver.
And introduce basic control messages for querying and responding.
Signed-off-by: Ravi Gunasekaran <r-gunasekaran@xxxxxx>
Signed-off-by: Yojana Mallik <y-mallik@xxxxxx>
---
drivers/net/ethernet/ti/Kconfig | 9 +++
drivers/net/ethernet/ti/Makefile | 1 +
drivers/net/ethernet/ti/icve_rpmsg_common.h | 47 +++++++++++
drivers/net/ethernet/ti/inter_core_virt_eth.c | 81 +++++++++++++++++++
drivers/net/ethernet/ti/inter_core_virt_eth.h | 27 +++++++
5 files changed, 165 insertions(+)
create mode 100644 drivers/net/ethernet/ti/icve_rpmsg_common.h
create mode 100644 drivers/net/ethernet/ti/inter_core_virt_eth.c
create mode 100644 drivers/net/ethernet/ti/inter_core_virt_eth.h
diff --git a/drivers/net/ethernet/ti/Kconfig b/drivers/net/ethernet/ti/Kconfig
index 1729eb0e0b41..4f00cb8fe9f1 100644
--- a/drivers/net/ethernet/ti/Kconfig
+++ b/drivers/net/ethernet/ti/Kconfig
@@ -145,6 +145,15 @@ config TI_AM65_CPSW_QOS
The EST scheduler runs on CPTS and the TAS/EST schedule is
updated in the Fetch RAM memory of the CPSW.
+config TI_K3_INTERCORE_VIRT_ETH
+ tristate "TI K3 Intercore Virtual Ethernet driver"
+ help
+ This driver provides intercore virtual ethernet driver
+ capability.Intercore Virtual Ethernet driver is modelled as
+ a RPMsg based shared memory ethernet driver for network traffic
+ tunnelling between heterogeneous processors Cortex A and Cortex R
+ used in TI's K3 SoCs.
+
config TI_KEYSTONE_NETCP
tristate "TI Keystone NETCP Core Support"
select TI_DAVINCI_MDIO
diff --git a/drivers/net/ethernet/ti/Makefile b/drivers/net/ethernet/ti/Makefile
index 6e086b4c0384..24b14ca73407 100644
--- a/drivers/net/ethernet/ti/Makefile
+++ b/drivers/net/ethernet/ti/Makefile
@@ -49,3 +49,4 @@ icssg-prueth-sr1-y := icssg/icssg_prueth_sr1.o \
icssg/icssg_stats.o \
icssg/icssg_ethtool.o
obj-$(CONFIG_TI_ICSS_IEP) += icssg/icss_iep.o
+obj-$(CONFIG_TI_K3_INTERCORE_VIRT_ETH) += inter_core_virt_eth.o
diff --git a/drivers/net/ethernet/ti/icve_rpmsg_common.h b/drivers/net/ethernet/ti/icve_rpmsg_common.h
new file mode 100644
index 000000000000..7cd157479d4d
--- /dev/null
+++ b/drivers/net/ethernet/ti/icve_rpmsg_common.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Texas Instruments K3 Inter Core Virtual Ethernet Driver common header
+ *
+ * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __ICVE_RPMSG_COMMON_H__
+#define __ICVE_RPMSG_COMMON_H__
+
+#include <linux/if_ether.h>
+
+enum icve_msg_type {
+ ICVE_REQUEST_MSG = 0,
+ ICVE_RESPONSE_MSG,
+ ICVE_NOTIFY_MSG,
+};
+
+struct request_message {
+ u32 type; /* Request Type */
+ u32 id; /* Request ID */
+} __packed;
+
+struct response_message {
+ u32 type; /* Response Type */
+ u32 id; /* Response ID */
+} __packed;
+
+struct notify_message {
+ u32 type; /* Notify Type */
+ u32 id; /* Notify ID */
+} __packed;
+
+struct message_header {
+ u32 src_id;
+ u32 msg_type; /* Do not use enum type, as enum size is compiler dependent */
+} __packed;
+
+struct message {
+ struct message_header msg_hdr;
+ union {
+ struct request_message req_msg;
+ struct response_message resp_msg;
+ struct notify_message notify_msg;
+ };
+} __packed;
+
+#endif /* __ICVE_RPMSG_COMMON_H__ */
diff --git a/drivers/net/ethernet/ti/inter_core_virt_eth.c b/drivers/net/ethernet/ti/inter_core_virt_eth.c
new file mode 100644
index 000000000000..bea822d2373a
--- /dev/null
+++ b/drivers/net/ethernet/ti/inter_core_virt_eth.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Texas Instruments K3 Inter Core Virtual Ethernet Driver
+ *
+ * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "inter_core_virt_eth.h"
+
+static int icve_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
+ void *priv, u32 src)
+{
+ struct icve_common *common = dev_get_drvdata(&rpdev->dev);
+ struct message *msg = (struct message *)data;
+ u32 msg_type = msg->msg_hdr.msg_type;
+ u32 rpmsg_type;
+
+ switch (msg_type) {
+ case ICVE_REQUEST_MSG:
+ rpmsg_type = msg->req_msg.type;
+ dev_dbg(common->dev, "Msg type = %d; RPMsg type = %d\n",
+ msg_type, rpmsg_type);
+ break;
+ case ICVE_RESPONSE_MSG:
+ rpmsg_type = msg->resp_msg.type;
+ dev_dbg(common->dev, "Msg type = %d; RPMsg type = %d\n",
+ msg_type, rpmsg_type);
+ break;
+ case ICVE_NOTIFY_MSG:
+ rpmsg_type = msg->notify_msg.type;
+ dev_dbg(common->dev, "Msg type = %d; RPMsg type = %d\n",
+ msg_type, rpmsg_type);
+ break;
+ default:
+ dev_err(common->dev, "Invalid msg type\n");
+ break;
+ }
+ return 0;
+}
+
+static int icve_rpmsg_probe(struct rpmsg_device *rpdev)
+{
+ struct device *dev = &rpdev->dev;
+ struct icve_common *common;
+
+ common = devm_kzalloc(&rpdev->dev, sizeof(*common), GFP_KERNEL);
+ if (!common)
+ return -ENOMEM;
+
+ dev_set_drvdata(dev, common);
+
+ common->port = devm_kzalloc(dev, sizeof(*common->port), GFP_KERNEL);
+ common->dev = dev;
+ common->rpdev = rpdev;
+
+ return 0;
+}
+
+static void icve_rpmsg_remove(struct rpmsg_device *rpdev)
+{
+ dev_info(&rpdev->dev, "icve rpmsg client driver is removed\n");
+}
+
+static struct rpmsg_device_id icve_rpmsg_id_table[] = {
+ { .name = "ti.icve" },
+ {},
+};
+MODULE_DEVICE_TABLE(rpmsg, icve_rpmsg_id_table);
+
+static struct rpmsg_driver icve_rpmsg_client = {
+ .drv.name = KBUILD_MODNAME,
+ .id_table = icve_rpmsg_id_table,
+ .probe = icve_rpmsg_probe,
+ .callback = icve_rpmsg_cb,
+ .remove = icve_rpmsg_remove,
+};
+module_rpmsg_driver(icve_rpmsg_client);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Siddharth Vadapalli <s-vadapalli@xxxxxx>");
+MODULE_AUTHOR("Ravi Gunasekaran <r-gunasekaran@xxxxxx");
+MODULE_DESCRIPTION("TI Inter Core Virtual Ethernet driver");
diff --git a/drivers/net/ethernet/ti/inter_core_virt_eth.h b/drivers/net/ethernet/ti/inter_core_virt_eth.h
new file mode 100644
index 000000000000..91a3aba96996
--- /dev/null
+++ b/drivers/net/ethernet/ti/inter_core_virt_eth.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Texas Instruments K3 Inter Core Virtual Ethernet Driver
+ *
+ * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __INTER_CORE_VIRT_ETH_H__
+#define __INTER_CORE_VIRT_ETH_H__
+
+#include <linux/etherdevice.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/rpmsg.h>
+#include "icve_rpmsg_common.h"
+
+struct icve_port {
+ struct icve_common *common;
+} __packed;
+
+struct icve_common {
+ struct rpmsg_device *rpdev;
+ struct icve_port *port;
+ struct device *dev;
+} __packed;
+
+#endif /* __INTER_CORE_VIRT_ETH_H__ */
--
2.40.1