From nobody Thu Oct 2 20:28:25 2025 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D84E320380; Thu, 11 Sep 2025 11:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590628; cv=none; b=M39nvJp88MVyTZ1sndqv4ZZ084iDfPz/MLuvbVTllchm/XnSg4E9sldFctWbZ1ESY4ob8HBwNPSTalzocgeudoMMI+5gN9+vMCq7sevognrDCLRFma/djpi0WlicSmrmLwV62DSr89AhZujG6qq2ynQ3Ui5RWPRsUjCuoatMgIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590628; c=relaxed/simple; bh=3/IXwQYdzrb+8+Wl8ttL6K2OCageb+uA5sMyf5P3l0U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jp31rAAUHRkNfsve2+irSt+vPPd2z/wDye8F6GGMFqOkOoMHZ7SAt/nKM2y+PmrBldU4NKg3PaeryeKnaMfyD93TbDY+5clU5mVG/wc0CW3Ph4fsnjlHBr6W72yK8iB6YzQeW1VFuviLdCmPchpF6Jkj6G+CKnnTus/Wc+H7agg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=ped4xet8; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="ped4xet8" Received: from lelvem-sh02.itg.ti.com ([10.180.78.226]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BBaJqJ282478; Thu, 11 Sep 2025 06:36:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757590579; bh=oFCiZfEq7zIHjgLX3tsUwQj/pkDFixFCQPlJyAkDwDQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ped4xet8FJRNV2jYqgJzx9ZFhpf9i/K81xUgQrLIJOGw7ea0RnyIOl6D2o+C/gYH4 p+Bpxl5Bp8auJcC8guGuwDYGk/hHVeq+vu2BbHrdiaJa9qNxfIQllCbLYNgBC2FWWv DFkQPwHNdXJI0qe1oJTNLol/50IgoG2UPVK9FYMA= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelvem-sh02.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BBaJ7R1027159 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 06:36:19 -0500 Received: from DLEE215.ent.ti.com (157.170.170.118) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 06:36:18 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DLEE215.ent.ti.com (157.170.170.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 06:36:18 -0500 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BBaIJL1766152; Thu, 11 Sep 2025 06:36:18 -0500 Received: from localhost (danish-tpc.dhcp.ti.com [172.24.231.152]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 58BBaHiF007143; Thu, 11 Sep 2025 06:36:18 -0500 From: MD Danish Anwar To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , MD Danish Anwar , Mengyuan Lou , Lei Wei , Xin Guo , Michael Ellerman , Fan Gong , Lorenzo Bianconi , Parthiban Veerasooran , Lukas Bulwahn , Geert Uytterhoeven CC: , , , , Subject: [PATCH net-next v4 1/7] net: rpmsg-eth: Add Documentation for RPMSG-ETH Driver Date: Thu, 11 Sep 2025 17:06:06 +0530 Message-ID: <20250911113612.2598643-2-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911113612.2598643-1-danishanwar@ti.com> References: <20250911113612.2598643-1-danishanwar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Add documentation for the RPMSG Based Virtual Ethernet Driver (rpmsg-eth). The documentation describes the driver's architecture, shared memory layout, RPMSG communication protocol, and requirements for vendor firmware to interoperate with the driver. It details the use of a magic number for shared memory validation, outlines the information exchanged between the host and remote processor, and provides a how-to guide for vendors to implement compatible firmware. Signed-off-by: MD Danish Anwar --- .../device_drivers/ethernet/index.rst | 1 + .../device_drivers/ethernet/rpmsg_eth.rst | 424 ++++++++++++++++++ 2 files changed, 425 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/rpmsg_= eth.rst diff --git a/Documentation/networking/device_drivers/ethernet/index.rst b/D= ocumentation/networking/device_drivers/ethernet/index.rst index 0b0a3eef6aae..20513a595af1 100644 --- a/Documentation/networking/device_drivers/ethernet/index.rst +++ b/Documentation/networking/device_drivers/ethernet/index.rst @@ -51,6 +51,7 @@ Contents: netronome/nfp pensando/ionic qualcomm/ppe/ppe + rpmsg_eth smsc/smc9 stmicro/stmmac ti/cpsw diff --git a/Documentation/networking/device_drivers/ethernet/rpmsg_eth.rst= b/Documentation/networking/device_drivers/ethernet/rpmsg_eth.rst new file mode 100644 index 000000000000..7a9d94291de4 --- /dev/null +++ b/Documentation/networking/device_drivers/ethernet/rpmsg_eth.rst @@ -0,0 +1,424 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +RPMSG Based Virtual Ethernet Driver +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D + +The RPMSG Based Virtual Ethernet Driver provides a virtual Ethernet interf= ace for +communication between a host processor and a remote processor using the RP= MSG +framework. This driver enables Ethernet-like packet transmission and recep= tion +over shared memory, facilitating inter-core communication in systems with +heterogeneous processors. + +The driver is designed to work with the RPMSG framework, which is part of = the +Linux Remote Processor (remoteproc) subsystem. It uses shared memory for d= ata +exchange and supports features like multicast address management, dynamic = MAC +address assignment, and efficient packet processing using NAPI. + +This driver is generic and can be used by any vendor. Vendors can develop = their +own firmware for the remote processor to make it compatible with this driv= er. +The firmware must adhere to the shared memory layout, RPMSG communication +protocol, and data exchange requirements described in this documentation. + +Naming Convention +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Throughout this documentation and in the driver implementation, the follow= ing naming +convention is used to describe the direction of communication: + +- **Firmware**: The firmware / RTOS binary running on the remote core. Thi= s takes the primary role. +- **Driver**: The Linux driver running on the host core. This takes the se= condary role. + +This convention is important for understanding the data flow and the respo= nsibilities +of each side in the communication channel. + +Key Features +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +- Virtual Ethernet interface using RPMSG. +- Shared memory-based packet transmission and reception. +- Support for multicast address management. +- Dynamic MAC address assignment. +- NAPI (New API) support for efficient packet processing. +- State machine for managing interface states. +- Workqueue-based asynchronous operations. +- Support for notifications and responses from the firmware. + +Magic Number +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +A **magic number** is used in the shared memory layout to validate that the +memory region is correctly initialized and accessible by both driver and t= he +firmware. This value is a unique constant ``0xABCDABCD`` that is written to +specific locations (such as the head and tail structures) in the shared me= mory +by the firmware and checked by the driver during the handshake process. + +Purpose of the Magic Number +--------------------------- + +- **Validation:** Ensures that the shared memory region has been properly = set up + and is not corrupted or uninitialized. +- **Synchronization:** Both driver and firmware must agree on the magic nu= mber + value, which helps detect mismatches in memory layout or protocol versio= n. +- **Error Detection:** If the driver detects an incorrect magic number dur= ing + initialization or runtime, it can abort the handshake and report an erro= r, + preventing undefined behavior. + +Implementation Details +---------------------- + +- The magic number is defined as a macro in the driver source (e.g., + ``#define RPMSG_ETH_SHM_MAGIC_NUM 0xABCDABCD``). +- The firmware must write this value to the ``magic_num`` field of the hea= d and + tail structures in the shared memory region. +- During the handshake, the Linux driver reads these fields and compares t= hem to + the expected value. If any mismatch is detected, the driver will log an = error + and refuse to proceed. + +Example Usage in Shared Memory +------------------------------ + +.. code-block:: text + + Shared Memory Layout: + --------------------------- + | MAGIC_NUM (0xABCDABCD) | <-- rpmsg_eth_shm_head + | HEAD | + --------------------------- + | MAGIC_NUM (0xABCDABCD) | <-- rpmsg_eth_shm_tail + | TAIL | + --------------------------- + +The magic number must be present in both the head and tail structures for = the +handshake to succeed. + +Firmware developers must ensure that the correct magic number is written t= o the +appropriate locations in shared memory before the Linux driver attempts to +initialize the interface. + +Shared Memory Layout +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The RPMSG Based Virtual Ethernet Driver uses a shared memory region to exc= hange +data between driver and firmware. The shared memory is divided into transm= it +and receive regions, each with its own `head` and `tail` indices to track = the +buffer state. The base address of this shared memory is configured in the +device tree. See :ref:`Configuration ` for details. + +Shared Memory Parameters +------------------------ + +The following parameters are exchanged between the driver and the firmware= to +configure the shared memory layout: + +1. **num_pkt_bufs**: + + - The total number of packet buffers available in the shared memory. + - This determines the maximum number of packets that can be stored in t= he + shared memory at any given time. + +2. **buff_slot_size**: + + - The size of each buffer slot in the shared memory. + - This includes space for the packet length, metadata, and the actual p= acket + data. + +3. **tx_offset**: + + - The offset from the `base_addr` where the transmit buffers begin. + - This is used by driver to write packets for transmission. + +4. **rx_offset**: + + - The offset from the `base_addr` where the receive buffers begin. + - This is used by driver to read packets received from the firmware. + +Shared Memory Structure +----------------------- + +The shared memory layout is as follows: + +.. code-block:: text + + Shared Memory Layout: + --------------------------- + | MAGIC_NUM | rpmsg_eth_shm_head + | HEAD_IDX | + --------------------------- + | MAGIC_NUM | + | PKT_1_LEN | + | PKT_1 | + --------------------------- + | ... | + --------------------------- + | MAGIC_NUM | + | TAIL_IDX | rpmsg_eth_shm_tail + --------------------------- + +1. **MAGIC_NUM**: + + - A unique identifier used to validate the shared memory region. + - Ensures that the memory region is correctly initialized and accessibl= e. + +2. **HEAD Index**: + + - Tracks the start of the buffer for packet transmission or reception. + - Updated by the producer (Driver or firmware) after writing a packet. + +3. **TAIL Index**: + + - Tracks the end of the buffer for packet transmission or reception. + - Updated by the consumer (Driver or firmware) after reading a packet. + +4. **Packet Buffers**: + + - Each packet buffer contains: + + - **Packet Length**: A 4-byte field indicating the size of the packe= t. + - **Packet Data**: The actual Ethernet frame data. + +5. **Buffer Size**: + + - Each buffer has a fixed size defined by `RPMSG_ETH_BUFFER_SIZE`, which + includes space for the packet length and data. + +Buffer Management +----------------- + +- The driver and firmware use a circular buffer mechanism to manage the sh= ared + memory. +- The `head` and `tail` indices are used to determine the number of packets + available for processing: + + .. code-block:: c + + num_pkts =3D head - tail; + num_pkts =3D num_pkts >=3D 0 ? num_pkts : (num_pkts + max_buffers= ); + +- The producer writes packets to the buffer and increments the `head` inde= x. +- The consumer reads packets from the buffer and increments the `tail` ind= ex. + +RPMSG Communication +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The driver uses RPMSG channels to exchange control messages with the firmw= are. +These messages are used to manage the state of the Ethernet interface, +configure settings, notify events, and exchange runtime information. + +Information Exchanged Between RPMSG Channels +-------------------------------------------- + +1. **Requests from Driver to Firmware**: + + - `RPMSG_ETH_REQ_SHM_INFO`: Request shared memory information, such as + ``num_pkt_bufs``, ``buff_slot_size``, ``tx_offset``, and + ``rx_offset``. + - `RPMSG_ETH_REQ_SET_MAC_ADDR`: Set the MAC address of the Ethernet + interface. + - `RPMSG_ETH_REQ_ADD_MC_ADDR`: Add a multicast address to the firmware's + filter list. + - `RPMSG_ETH_REQ_DEL_MC_ADDR`: Remove a multicast address from firmware= 's + filter list. + +2. **Responses from Firmware to Driver**: + + - `RPMSG_ETH_RESP_SET_MAC_ADDR`: Acknowledge the MAC address configurat= ion. + - `RPMSG_ETH_RESP_ADD_MC_ADDR`: Acknowledge the addition of a multicast + address. + - `RPMSG_ETH_RESP_DEL_MC_ADDR`: Acknowledge the removal of a multicast + address. + - `RPMSG_ETH_RESP_SHM_INFO`: Respond with shared memory information suc= h as + ``num_pkt_bufs``, ``buff_slot_size``, ``tx_offset``, and + ``rx_offset``. + +3. **Notifications from Firmware to Driver**: + + - `RPMSG_ETH_NOTIFY_PORT_UP`: Notify that the Ethernet port is up and r= eady + for communication. + - `RPMSG_ETH_NOTIFY_PORT_DOWN`: Notify that the Ethernet port is down. + - `RPMSG_ETH_NOTIFY_REMOTE_READY`: Notify that the firmware is ready for + communication. + +4. **Runtime Information Exchanged**: + + - **Link State**: Notifications about link state changes (e.g., link up= or + link down). + - **Statistics**: Runtime statistics such as transmitted/received packe= ts, + errors, and dropped packets. + - **Error Notifications**: Notifications about errors like buffer overf= lows + or invalid packets. + - **Configuration Updates**: Notifications about changes in configurati= on, + such as updated MTU or VLAN settings. + +How-To Guide for Vendors +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This section provides a guide for vendors to develop firmware for the remo= te +processor that is compatible with the RPMSG Based Virtual Ethernet Driver. + +1. **Implement Shared Memory Layout**: + + - Allocate a shared memory region for packet transmission and reception. + - Initialize the `MAGIC_NUM`, `num_pkt_bufs`, `buff_slot_size`, `tx_off= set`, + and `rx_offset`. + +2. **Magic Number Requirements** + + - The firmware must write a unique magic number ``0xABCDABCD`` to the + `magic_num` field of both the head and tail structures in the shared + memory region. + - This magic number is used by the Linux driver to validate that the sh= ared + memory region is correctly initialized and accessible. + - If the driver detects an incorrect magic number during the handshake,= it + will abort initialization and report an error. + - Vendors must ensure the magic number matches the value expected by the + Linux driver, see the `RPMSG_ETH_SHM_MAGIC_NUM` macro in the driver + source. + +3. **Handle RPMSG Requests**: + + - Implement handlers for the following RPMSG requests: + + - `RPMSG_ETH_REQ_SHM_INFO` + - `RPMSG_ETH_REQ_SET_MAC_ADDR` + - `RPMSG_ETH_REQ_ADD_MC_ADDR` + - `RPMSG_ETH_REQ_DEL_MC_ADDR` + +4. **Send RPMSG Notifications**: + + - Notify the Driver about the state of the Ethernet interface using the + notifications described above. + +5. **Send Runtime Information**: + + - Implement mechanisms to send runtime information such as link state + changes, statistics, and error notifications. + +6. **Implement Packet Processing**: + + - Process packets in the shared memory transmit and receive buffers. + +7. **Test the Firmware**: + + - Use the RPMSG Based Virtual Ethernet Driver on the host to test packet + transmission and reception. + +.. _rpmsg_config: + +Configuration +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The driver relies on the device tree for configuration. The shared memory +region need to be specified in the remote processor device's "memory-regio= n". + +Example Device Tree Node +------------------------ +Here is an example of how the device tree node might look: + +.. code-block:: dts + + { + compatible =3D "shared-dma-pool"; + reg =3D ; + }; + + { + memory-region =3D <&>; + }; + +In this example, ```` is the remote processor device node, a= nd +```` is the shared memory region node. The remote processor +device references the shared memory region node using the ``memory-region`` +property. + +Vendors can create their own ```` and add it to their remo= te +processor device node i.e. ```` + +Driver Configuration +-------------------- + +Vendors need to configure the driver as well by adding a new entry of type +:c:type:`rpmsg_device_id` in the array ``rpmsg_eth_id_table``. + +The :c:type:`rpmsg_device_id` structure contains two members: + +* :c:member:`name` - a string that identifies the RPMsg device +* :c:member:`driver_data` - a pointer to a :c:type:`rpmsg_eth_data` struct= ure + +Overview of rpmsg_eth_data +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``rpmsg_eth_data`` structure is a vendor-specific configuration struct= ure +that provides customization options for the RPMsg Ethernet driver. + +.. code-block:: c + + /** + * struct rpmsg_eth_data - RPMSG ETH device data + * @shm_region_index: Shared memory region index + */ + struct rpmsg_eth_data { + u8 shm_region_index; + }; + +Currently, the structure contains a single field, but it is designed to be +extensible for future enhancements. + +The shm_region_index Field +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``shm_region_index`` field is an 8-bit unsigned integer within the +``rpmsg_eth_data`` structure that specifies which memory-region phandle to= use +from the device tree for the RPMsg Ethernet shared memory. + +This field is used in the ``rpmsg_eth_get_shm_info`` function to retrieve = the +correct shared memory region from the device tree using the +``of_parse_phandle`` function: + +.. code-block:: c + + rmem_np =3D of_parse_phandle(np, "memory-region", common->data.shm_reg= ion_index); + +The ``shm_region_index`` indicates which memory region to use when multiple +memory regions are defined in the remote processor device tree node. + +Example +~~~~~~~ + +The following example shows how to create a custom RPMsg device ID: + +.. code-block:: c + + static const struct rpmsg_eth_data my_rpmsg_eth_data =3D { + .shm_region_index =3D 2, + }; + + static struct rpmsg_device_id my_rpmsg_eth_id_table[] =3D { + { .name =3D "my.shm-eth", .driver_data =3D (kernel_ulong_t)&my_rpm= sg_eth_data }, + {}, + }; + +Limitations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +- The driver assumes a specific shared memory layout and may not work with= other + configurations. +- The driver currently supports only one transmit and one receive queue. +- The current implementation only supports Linux driver running on the "ho= st" + core as secondary and firmware running on the "remote" core as primary. = It + does not support Linux-to-Linux communication where Linux driver would r= un on + both ends. + +References +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +- :doc:`RPMSG Framework documentation ` +- :doc:`Network device documentation ` + +Authors +=3D=3D=3D=3D=3D=3D=3D + +- MD Danish Anwar --=20 2.34.1 From nobody Thu Oct 2 20:28:26 2025 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53E7031CA59; Thu, 11 Sep 2025 11:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590631; cv=none; b=k2cH49G4jV2KIaY1ulw0EWX6/QDfGyIGT0bC/RAjyGkTE4LeFgZcioc1kjAfATdX4PGbmLdAF5fXCxoqX4kQajjV2M+vZjj6j/xRQ/3gxnAYEanIKjQEuHd8sSgNSZ1pWEslA5wSV9m73fil5p/SBXGiFoyHrsGjiGKVyFhDHDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590631; c=relaxed/simple; bh=TrXBybeR0aNAqOiIxm/hrdvqvYTzcoh2b2KKxtgdUW8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hrlZtJOD0JvvBAiZOb7f34g2gU0KxK0F+krFmTWrWhrkVosWB1myQ31m6zTVghAKJ4QrAVV6IDdGEKnVtYUNbdzJOR2sZZkGBjA5P2CosTgoo1H00CIOL5DRhPs4VD6k8ggHlsw7W7vQf3rAgf+aqtgYFzeNPJa4oXJVFefyADg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=Cbk1IJ1c; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Cbk1IJ1c" Received: from fllvem-sh04.itg.ti.com ([10.64.41.54]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BBaMZm793642; Thu, 11 Sep 2025 06:36:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757590582; bh=UcKnqqQ3hc0qlaEnqWP7Zltl+WKjelR3FGrd2YAXgOA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Cbk1IJ1co2d8Q4NLcfNYir5p1PxSKISLAJFGi4rBwGwUX2fRs82OEUBvssG3XeVA5 vfcJism3z2SvDy5otimGLFEYGqbHT8KUr1oBYBDzevFVXGpBEKj2NAdb+QVpc6B56r 7X1/1vF62ixta12VCN0zGNovs7b3bq9ScKQsPotw= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllvem-sh04.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BBaMVI1908800 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 06:36:22 -0500 Received: from DFLE200.ent.ti.com (10.64.6.58) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 06:36:21 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DFLE200.ent.ti.com (10.64.6.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 06:36:21 -0500 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BBaLa42061818; Thu, 11 Sep 2025 06:36:21 -0500 Received: from localhost (danish-tpc.dhcp.ti.com [172.24.231.152]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 58BBaKEM007150; Thu, 11 Sep 2025 06:36:20 -0500 From: MD Danish Anwar To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , MD Danish Anwar , Mengyuan Lou , Lei Wei , Xin Guo , Michael Ellerman , Fan Gong , Lorenzo Bianconi , Parthiban Veerasooran , Lukas Bulwahn , Geert Uytterhoeven CC: , , , , Subject: [PATCH net-next v4 2/7] net: rpmsg-eth: Add basic rpmsg skeleton Date: Thu, 11 Sep 2025 17:06:07 +0530 Message-ID: <20250911113612.2598643-3-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911113612.2598643-1-danishanwar@ti.com> References: <20250911113612.2598643-1-danishanwar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Introduces a basic RPMSG Ethernet driver and add it's basic skeleton. Add support for creating virtual Ethernet devices over RPMSG channels, allowing user-space programs to send and receive messages using a standard Ethernet protocol. The driver includes message handling, probe, and remove functions, along with necessary data structures. Signed-off-by: MD Danish Anwar --- drivers/net/ethernet/Kconfig | 11 +++ drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/rpmsg_eth.c | 144 +++++++++++++++++++++++++++++++ drivers/net/ethernet/rpmsg_eth.h | 85 ++++++++++++++++++ 4 files changed, 241 insertions(+) create mode 100644 drivers/net/ethernet/rpmsg_eth.c create mode 100644 drivers/net/ethernet/rpmsg_eth.h diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig index f86d4557d8d7..7d00e02a2c8f 100644 --- a/drivers/net/ethernet/Kconfig +++ b/drivers/net/ethernet/Kconfig @@ -170,6 +170,17 @@ config OA_TC6 To know the implementation details, refer documentation in . =20 +config RPMSG_ETH + tristate "RPMsg Based Virtual Ethernet driver" + depends on RPMSG + depends on REMOTEPROC + help + This makes it possible for user-space programs to send and receive + rpmsg messages as a standard eth protocol. + + To compile this driver as a module, choose M here: the module will be + called rpmsg_eth. + source "drivers/net/ethernet/packetengines/Kconfig" source "drivers/net/ethernet/pasemi/Kconfig" source "drivers/net/ethernet/pensando/Kconfig" diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile index 67182339469a..aebd15993e3c 100644 --- a/drivers/net/ethernet/Makefile +++ b/drivers/net/ethernet/Makefile @@ -107,3 +107,4 @@ obj-$(CONFIG_NET_VENDOR_XIRCOM) +=3D xircom/ obj-$(CONFIG_NET_VENDOR_SYNOPSYS) +=3D synopsys/ obj-$(CONFIG_NET_VENDOR_PENSANDO) +=3D pensando/ obj-$(CONFIG_OA_TC6) +=3D oa_tc6.o +obj-$(CONFIG_RPMSG_ETH) +=3D rpmsg_eth.o diff --git a/drivers/net/ethernet/rpmsg_eth.c b/drivers/net/ethernet/rpmsg_= eth.c new file mode 100644 index 000000000000..7224fbc89646 --- /dev/null +++ b/drivers/net/ethernet/rpmsg_eth.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +/* RPMsg Based Virtual Ethernet Driver + * + * Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com/ + */ + +#include +#include +#include +#include + +#include "rpmsg_eth.h" + +static int rpmsg_eth_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int = len, + void *priv, u32 src) +{ + struct rpmsg_eth_common *common =3D dev_get_drvdata(&rpdev->dev); + struct message *msg =3D (struct message *)data; + u32 msg_type =3D msg->msg_hdr.msg_type; + int ret =3D 0; + + switch (msg_type) { + case RPMSG_ETH_REQUEST_MSG: + case RPMSG_ETH_RESPONSE_MSG: + case RPMSG_ETH_NOTIFY_MSG: + dev_dbg(common->dev, "Msg type =3D %d, Src Id =3D %d\n", + msg_type, msg->msg_hdr.src_id); + break; + default: + dev_err(common->dev, "Invalid msg type\n"); + ret =3D -EINVAL; + break; + } + return ret; +} + +/** + * rpmsg_eth_get_shm_info - Retrieve shared memory region for RPMsg Ethern= et + * @common: Pointer to rpmsg_eth_common structure + * + * This function locates and maps the reserved memory region for the RPMsg + * Ethernet device by traversing the device tree hierarchy. It first ident= ifies + * the associated remote processor (rproc), then locates the "rpmsg-eth" c= hild + * node within the rproc's device tree node, and finally retrieves the + * "memory-region" phandle that points to the reserved memory region. + * Once found, the shared memory region is mapped into the + * kernel's virtual address space using devm_ioremap() + * + * Return: 0 on success, negative error code on failure. + */ +static int rpmsg_eth_get_shm_info(struct rpmsg_eth_common *common) +{ + struct device_node *np, *rmem_np; + struct reserved_mem *rmem; + struct rproc *rproc; + + /* Get the remote processor associated with this device */ + rproc =3D rproc_get_by_child(&common->rpdev->dev); + if (!rproc) { + dev_err(common->dev, "rpmsg eth device not child of rproc\n"); + return -EINVAL; + } + + /* Get the device node from rproc or its parent */ + np =3D rproc->dev.of_node ?: (rproc->dev.parent ? rproc->dev.parent->of_n= ode : NULL); + if (!np) { + dev_err(common->dev, "Cannot find rproc device node\n"); + return -ENODEV; + } + + /* Parse the memory-region phandle */ + rmem_np =3D of_parse_phandle(np, "memory-region", common->data.shm_region= _index); + of_node_put(np); + if (!rmem_np) { + dev_err(common->dev, "Cannot find shared memory region\n"); + return -EINVAL; + } + + /* Lookup the reserved memory region */ + rmem =3D of_reserved_mem_lookup(rmem_np); + of_node_put(rmem_np); + if (!rmem) + return -EINVAL; + + common->port->shm =3D devm_ioremap(common->dev, rmem->base, rmem->size); + if (IS_ERR(common->port->shm)) + return PTR_ERR(common->port->shm); + + common->port->buf_size =3D rmem->size; + + return 0; +} + +static int rpmsg_eth_probe(struct rpmsg_device *rpdev) +{ + struct device *dev =3D &rpdev->dev; + struct rpmsg_eth_common *common; + int ret =3D 0; + + common =3D devm_kzalloc(&rpdev->dev, sizeof(*common), GFP_KERNEL); + if (!common) + return -ENOMEM; + + dev_set_drvdata(dev, common); + + common->port =3D devm_kzalloc(dev, sizeof(*common->port), GFP_KERNEL); + common->dev =3D dev; + common->rpdev =3D rpdev; + common->data =3D *(const struct rpmsg_eth_data *)rpdev->id.driver_data; + + ret =3D rpmsg_eth_get_shm_info(common); + if (ret) + return ret; + + return 0; +} + +static void rpmsg_eth_remove(struct rpmsg_device *rpdev) +{ + dev_dbg(&rpdev->dev, "rpmsg-eth client driver is removed\n"); +} + +static const struct rpmsg_eth_data ti_rpmsg_eth_data =3D { + .shm_region_index =3D 2, +}; + +static struct rpmsg_device_id rpmsg_eth_id_table[] =3D { + { .name =3D "ti.shm-eth", .driver_data =3D (kernel_ulong_t)&ti_rpmsg_eth_= data }, + {}, +}; +MODULE_DEVICE_TABLE(rpmsg, rpmsg_eth_id_table); + +static struct rpmsg_driver rpmsg_eth_rpmsg_client =3D { + .drv.name =3D KBUILD_MODNAME, + .id_table =3D rpmsg_eth_id_table, + .probe =3D rpmsg_eth_probe, + .callback =3D rpmsg_eth_rpmsg_cb, + .remove =3D rpmsg_eth_remove, +}; +module_rpmsg_driver(rpmsg_eth_rpmsg_client); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("MD Danish Anwar "); +MODULE_DESCRIPTION("RPMsg Based Virtual Ethernet driver"); diff --git a/drivers/net/ethernet/rpmsg_eth.h b/drivers/net/ethernet/rpmsg_= eth.h new file mode 100644 index 000000000000..0d6f96f755eb --- /dev/null +++ b/drivers/net/ethernet/rpmsg_eth.h @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: GPL-2.0 + * RPMsg Based Virtual Ethernet Driver common header + * + * Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com/ + */ + +#ifndef __RPMSG_ETH_H__ +#define __RPMSG_ETH_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RPMSG_ETH_SHM_MAGIC_NUM 0xABCDABCD + +enum rpmsg_eth_msg_type { + RPMSG_ETH_REQUEST_MSG =3D 0, + RPMSG_ETH_RESPONSE_MSG, + RPMSG_ETH_NOTIFY_MSG, +}; + +/** + * struct message_header - message header structure for RPMSG Ethernet + * @src_id: Source endpoint ID + * @msg_type: Message type + */ +struct message_header { + u32 src_id; + u32 msg_type; +} __packed; + +/** + * struct message - RPMSG Ethernet message structure + * + * @msg_hdr: Message header contains source and destination endpoint and + * the type of message + * + * This structure is used to send and receive messages between the RPMSG + * Ethernet ports. + */ +struct message { + struct message_header msg_hdr; +} __packed; + +/** + * struct rpmsg_eth_data - RPMSG ETH device data + * @shm_region_index: Shared memory region index + */ +struct rpmsg_eth_data { + u8 shm_region_index; +}; + +/** + * struct rpmsg_eth_common - common structure for RPMSG Ethernet + * @rpdev: RPMSG device + * @port: Ethernet port + * @dev: Device + * @data: Vendor specific data + */ +struct rpmsg_eth_common { + struct rpmsg_device *rpdev; + struct rpmsg_eth_port *port; + struct device *dev; + struct rpmsg_eth_data data; +}; + +/** + * struct rpmsg_eth_port - Ethernet port structure for RPMSG Ethernet + * @common: Pointer to the common RPMSG Ethernet structure + * @shm: Shared memory region mapping + * @buf_size: Size (in bytes) of the shared memory buffer for this port + */ +struct rpmsg_eth_port { + struct rpmsg_eth_common *common; + void __iomem *shm; + phys_addr_t buf_size; +}; + +#endif /* __RPMSG_ETH_H__ */ --=20 2.34.1 From nobody Thu Oct 2 20:28:26 2025 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 228C032143C; Thu, 11 Sep 2025 11:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590632; cv=none; b=Ad4ucOWhq2yQR0+PNWsSve+jK1eSk1ms0wDCepHOrbrj5j4hCkVnwY/cYb2KRB6dvmq17RUSe/0stxhOcGP6wMoDDQntWx2yaTB0OFX5Lc6TfsW4o03jlsaiWdU6CH0U8GvDAdm1QkJ20dp2i1010ZlmQDZvJRgICkGn3JYqpEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590632; c=relaxed/simple; bh=a3f2zeOJzYbHwQToT1Zuhyx4X92Aem1weoPQccIKi78=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E5GhmYdcat18bXrjRP+IjSWCsAOgiBTIxqMSQgmuZw+vkRJYjj62SCKw2PoFh9j1krwT8YdzNWWpgcBJ57IrAczyYOATIBgT6Yll+qHJP1A3lGPE8aRwKTlQmD6Bfld0ZfYprDfq8pPsVYRUcPaT5YGHalCAbKeaudUd7myVGb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=Mb6br4lb; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Mb6br4lb" Received: from lelvem-sh01.itg.ti.com ([10.180.77.71]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BBaOwo793646; Thu, 11 Sep 2025 06:36:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757590584; bh=PNo4lWUuO2P45UXHR+xPsllMY5/OiVnXKiKAYC2w5AQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Mb6br4lbBOkHghOAofy/gnRZFpqbsBxXWsy0fXEdMBgPgtTilVurQAwTVtnIQqX63 yILcSB9WTGtKmRsudHICPi2Y+adVaSxYLxlsBwSCgyxH7931v5AN1xQffBNwpv/u+c FOeS0MOcxbxWEJiZ4trFpsY0u/l2AWHSf8YRZDKI= Received: from DFLE102.ent.ti.com (dfle102.ent.ti.com [10.64.6.23]) by lelvem-sh01.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BBaO8V464598 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 06:36:24 -0500 Received: from DFLE214.ent.ti.com (10.64.6.72) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 06:36:24 -0500 Received: from fllvem-mr07.itg.ti.com (10.64.41.89) by DFLE214.ent.ti.com (10.64.6.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 06:36:24 -0500 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by fllvem-mr07.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BBaNLt1068560; Thu, 11 Sep 2025 06:36:23 -0500 Received: from localhost (danish-tpc.dhcp.ti.com [172.24.231.152]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 58BBaMQn007156; Thu, 11 Sep 2025 06:36:23 -0500 From: MD Danish Anwar To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , MD Danish Anwar , Mengyuan Lou , Lei Wei , Xin Guo , Michael Ellerman , Fan Gong , Lorenzo Bianconi , Parthiban Veerasooran , Lukas Bulwahn , Geert Uytterhoeven CC: , , , , Subject: [PATCH net-next v4 3/7] net: rpmsg-eth: Register device as netdev Date: Thu, 11 Sep 2025 17:06:08 +0530 Message-ID: <20250911113612.2598643-4-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911113612.2598643-1-danishanwar@ti.com> References: <20250911113612.2598643-1-danishanwar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Register the rpmsg-eth device as a netdev and enhance the rpmsg callback function to handle shared memory for tx and rx buffers. Introduce structures for shared memory layout, including head, buffer, and tail indices. Add initialization for the netdev, including setting up MAC address, MTU, and netdev operations. Allocate memory for tx and rx buffers and map shared memory regions. Update the probe function to initialize the netdev and set the device state. Add necessary headers, constants, and enums for shared memory and state management. Define shared memory layout and buffer structures for efficient data handling. Implement helper macros for accessing private data and shared memory buffers. Ensure proper error handling during memory allocation and device registration. Signed-off-by: MD Danish Anwar --- drivers/net/ethernet/rpmsg_eth.c | 132 ++++++++++++++++++++- drivers/net/ethernet/rpmsg_eth.h | 195 +++++++++++++++++++++++++++++++ 2 files changed, 325 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/rpmsg_eth.c b/drivers/net/ethernet/rpmsg_= eth.c index 7224fbc89646..f599318633ea 100644 --- a/drivers/net/ethernet/rpmsg_eth.c +++ b/drivers/net/ethernet/rpmsg_eth.c @@ -11,20 +11,101 @@ =20 #include "rpmsg_eth.h" =20 +/** + * rpmsg_eth_validate_handshake - Validate handshake parameters from remote + * @port: Pointer to rpmsg_eth_port structure + * @shm_info: Pointer to shared memory info received from remote + * + * Checks buffer size, magic numbers, and TX/RX offsets in the handshake + * response to ensure they match expected values and are within valid rang= es. + * + * Return: 0 on success, -EINVAL on validation failure. + */ +static int rpmsg_eth_validate_handshake(struct rpmsg_eth_port *port, + struct rpmsg_eth_shm *shm_info) +{ + u32 tx_head_magic_num, tx_tail_magic_num; + u32 rx_head_magic_num, rx_tail_magic_num; + + if (shm_info->buff_slot_size !=3D RPMSG_ETH_BUFFER_SIZE) { + dev_err(port->common->dev, "Buffer configuration mismatch in handshake: = expected_buf_size=3D%zu, received_buf_size=3D%d\n", + RPMSG_ETH_BUFFER_SIZE, + shm_info->buff_slot_size); + return -EINVAL; + } + + if (shm_info->tx_offset >=3D port->buf_size || + shm_info->rx_offset >=3D port->buf_size) { + dev_err(port->common->dev, "TX/RX offset out of range in handshake: tx_o= ffset=3D0x%x, rx_offset=3D0x%x, size=3D0x%llx\n", + shm_info->tx_offset, + shm_info->rx_offset, + port->buf_size); + return -EINVAL; + } + + tx_head_magic_num =3D readl(port->shm + shm_info->tx_offset + + HEAD_MAGIC_NUM_OFFSET); + rx_head_magic_num =3D readl(port->shm + shm_info->rx_offset + + HEAD_MAGIC_NUM_OFFSET); + tx_tail_magic_num =3D readl(port->shm + shm_info->tx_offset + + TAIL_MAGIC_NUM_OFFSET(shm_info->num_pkt_bufs)); + rx_tail_magic_num =3D readl(port->shm + shm_info->rx_offset + + TAIL_MAGIC_NUM_OFFSET(shm_info->num_pkt_bufs)); + + if (tx_head_magic_num !=3D RPMSG_ETH_SHM_MAGIC_NUM || + rx_head_magic_num !=3D RPMSG_ETH_SHM_MAGIC_NUM || + tx_tail_magic_num !=3D RPMSG_ETH_SHM_MAGIC_NUM || + rx_tail_magic_num !=3D RPMSG_ETH_SHM_MAGIC_NUM) { + dev_err(port->common->dev, "Magic number mismatch in handshake at head/t= ail\n"); + return -EINVAL; + } + + return 0; +} + static int rpmsg_eth_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int = len, void *priv, u32 src) { struct rpmsg_eth_common *common =3D dev_get_drvdata(&rpdev->dev); struct message *msg =3D (struct message *)data; + struct rpmsg_eth_port *port =3D common->port; u32 msg_type =3D msg->msg_hdr.msg_type; + u32 rpmsg_type; int ret =3D 0; =20 switch (msg_type) { case RPMSG_ETH_REQUEST_MSG: + rpmsg_type =3D msg->req_msg.type; + dev_dbg(common->dev, "Msg type =3D %d, RPMsg type =3D %d, Src Id =3D %d,= Msg Id =3D %d\n", + msg_type, rpmsg_type, msg->msg_hdr.src_id, msg->req_msg.id); + break; case RPMSG_ETH_RESPONSE_MSG: + rpmsg_type =3D msg->resp_msg.type; + dev_dbg(common->dev, "Msg type =3D %d, RPMsg type =3D %d, Src Id =3D %d,= Msg Id =3D %d\n", + msg_type, rpmsg_type, msg->msg_hdr.src_id, msg->resp_msg.id); + switch (rpmsg_type) { + case RPMSG_ETH_RESP_SHM_INFO: + /* Handshake validation */ + ret =3D rpmsg_eth_validate_handshake(port, &msg->resp_msg.shm_info); + if (ret) { + dev_err(common->dev, "RPMSG handshake failed %d\n", ret); + return ret; + } + + /* Retrieve Tx and Rx shared memory info from msg */ + port->tx_offset =3D msg->resp_msg.shm_info.tx_offset; + port->rx_offset =3D msg->resp_msg.shm_info.rx_offset; + port->tx_max_buffers =3D + msg->resp_msg.shm_info.num_pkt_bufs; + port->rx_max_buffers =3D + msg->resp_msg.shm_info.num_pkt_bufs; + break; + } + break; case RPMSG_ETH_NOTIFY_MSG: - dev_dbg(common->dev, "Msg type =3D %d, Src Id =3D %d\n", - msg_type, msg->msg_hdr.src_id); + rpmsg_type =3D msg->notify_msg.type; + dev_dbg(common->dev, "Msg type =3D %d, RPMsg type =3D %d, Src Id =3D %d,= Msg Id =3D %d\n", + msg_type, rpmsg_type, msg->msg_hdr.src_id, msg->notify_msg.id); break; default: dev_err(common->dev, "Invalid msg type\n"); @@ -91,6 +172,47 @@ static int rpmsg_eth_get_shm_info(struct rpmsg_eth_comm= on *common) return 0; } =20 +static int rpmsg_eth_init_ndev(struct rpmsg_eth_common *common) +{ + struct device *dev =3D &common->rpdev->dev; + struct rpmsg_eth_ndev_priv *ndev_priv; + struct rpmsg_eth_port *port; + static u32 port_id; + int err =3D 0; + + port =3D common->port; + port->common =3D common; + port->port_id =3D port_id++; + + port->ndev =3D devm_alloc_etherdev_mqs(common->dev, sizeof(*ndev_priv), + RPMSG_ETH_MAX_TX_QUEUES, + RPMSG_ETH_MAX_RX_QUEUES); + + if (!port->ndev) { + dev_err(dev, "error allocating net_device\n"); + return -ENOMEM; + } + + ndev_priv =3D netdev_priv(port->ndev); + ndev_priv->port =3D port; + SET_NETDEV_DEV(port->ndev, dev); + + port->ndev->min_mtu =3D RPMSG_ETH_MIN_PACKET_SIZE; + port->ndev->max_mtu =3D RPMSG_ETH_MAX_MTU; + + if (!is_valid_ether_addr(port->ndev->dev_addr)) { + eth_hw_addr_random(port->ndev); + dev_dbg(dev, "Using random MAC address %pM\n", port->ndev->dev_addr); + } + + netif_carrier_off(port->ndev); + err =3D register_netdev(port->ndev); + if (err) + dev_err(dev, "error registering rpmsg_eth net device %d\n", err); + + return err; +} + static int rpmsg_eth_probe(struct rpmsg_device *rpdev) { struct device *dev =3D &rpdev->dev; @@ -107,11 +229,17 @@ static int rpmsg_eth_probe(struct rpmsg_device *rpdev) common->dev =3D dev; common->rpdev =3D rpdev; common->data =3D *(const struct rpmsg_eth_data *)rpdev->id.driver_data; + common->state =3D RPMSG_ETH_STATE_PROBE; =20 ret =3D rpmsg_eth_get_shm_info(common); if (ret) return ret; =20 + /* Register the network device */ + ret =3D rpmsg_eth_init_ndev(common); + if (ret) + return ret; + return 0; } =20 diff --git a/drivers/net/ethernet/rpmsg_eth.h b/drivers/net/ethernet/rpmsg_= eth.h index 0d6f96f755eb..0a0695e857df 100644 --- a/drivers/net/ethernet/rpmsg_eth.h +++ b/drivers/net/ethernet/rpmsg_eth.h @@ -18,6 +18,35 @@ #include =20 #define RPMSG_ETH_SHM_MAGIC_NUM 0xABCDABCD +#define RPMSG_ETH_MIN_PACKET_SIZE ETH_ZLEN +#define RPMSG_ETH_PACKET_BUFFER_SIZE 1540 +#define RPMSG_ETH_MAX_MTU \ + (RPMSG_ETH_PACKET_BUFFER_SIZE - (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN)) + +#define RPMSG_ETH_MAX_TX_QUEUES 1 +#define RPMSG_ETH_MAX_RX_QUEUES 1 +#define PKT_LEN_SIZE_TYPE sizeof(u32) +#define MAGIC_NUM_SIZE_TYPE sizeof(u32) + +/* 4 bytes to hold packet length and RPMSG_ETH_PACKET_BUFFER_SIZE to hold = packet */ +#define RPMSG_ETH_BUFFER_SIZE \ + (RPMSG_ETH_PACKET_BUFFER_SIZE + PKT_LEN_SIZE_TYPE + MAGIC_NUM_SIZE_TYPE) + +#define RX_POLL_TIMEOUT_JIFFIES usecs_to_jiffies(1000) +#define RX_POLL_JIFFIES (jiffies + RX_POLL_TIMEOUT_JIFFIES) +#define STATE_MACHINE_TIME_JIFFIES msecs_to_jiffies(100) +#define RPMSG_ETH_REQ_TIMEOUT_JIFFIES msecs_to_jiffies(100) + +#define HEAD_MAGIC_NUM_OFFSET 0x0 +#define HEAD_IDX_OFFSET (HEAD_MAGIC_NUM_OFFSET + MAGIC_NUM_SIZE_TYPE) +#define PKT_START_OFFSET(n) \ + ((HEAD_IDX_OFFSET + MAGIC_NUM_SIZE_TYPE) + ((n) * RPMSG_ETH_BUFFER_SIZE)) +#define TAIL_MAGIC_NUM_OFFSET(n) PKT_START_OFFSET((n)) +#define TAIL_IDX_OFFSET(n) (TAIL_MAGIC_NUM_OFFSET((n)) + MAGIC_NUM_SIZE_TY= PE) + +#define rpmsg_eth_ndev_to_priv(ndev) ((struct rpmsg_eth_ndev_priv *)netdev= _priv(ndev)) +#define rpmsg_eth_ndev_to_port(ndev) (rpmsg_eth_ndev_to_priv(ndev)->port) +#define rpmsg_eth_ndev_to_common(ndev) (rpmsg_eth_ndev_to_port(ndev)->comm= on) =20 enum rpmsg_eth_msg_type { RPMSG_ETH_REQUEST_MSG =3D 0, @@ -25,6 +54,87 @@ enum rpmsg_eth_msg_type { RPMSG_ETH_NOTIFY_MSG, }; =20 +enum rpmsg_eth_rpmsg_type { + /* Request types */ + RPMSG_ETH_REQ_SHM_INFO =3D 0, + RPMSG_ETH_REQ_SET_MAC_ADDR, + + /* Response types */ + RPMSG_ETH_RESP_SHM_INFO, + RPMSG_ETH_RESP_SET_MAC_ADDR, + + /* Notification types */ + RPMSG_ETH_NOTIFY_PORT_UP, + RPMSG_ETH_NOTIFY_PORT_DOWN, + RPMSG_ETH_NOTIFY_PORT_READY, + RPMSG_ETH_NOTIFY_REMOTE_READY, +}; + +/** + * struct rpmsg_eth_shm - Shared memory layout for RPMsg Ethernet + * @num_pkt_bufs: Number of packet buffers available in the shared memory + * @buff_slot_size: Size of each buffer slot in bytes + * @tx_offset: Offset for the transmit buffer region within the shared mem= ory + * @rx_offset: Offset for the receive buffer region within the shared memo= ry + * + * This structure defines the layout of the shared memory used for + * communication between the host and the remote processor in an RPMsg + * Ethernet driver. It specifies the configuration and memory offsets + * required for transmitting and receiving Ethernet packets. + */ +struct rpmsg_eth_shm { + u32 num_pkt_bufs; + u32 buff_slot_size; + u32 tx_offset; + u32 rx_offset; +} __packed; + +/** + * struct rpmsg_eth_mac_addr - MAC address information for RPMSG Ethernet + * @addr: MAC address + */ +struct rpmsg_eth_mac_addr { + char addr[ETH_ALEN]; +} __packed; + +/** + * struct request_message - request message structure for RPMSG Ethernet + * @type: Request Type + * @id: Request ID + * @mac_addr: MAC address (if request type is MAC address related) + */ +struct request_message { + u32 type; + u32 id; + union { + struct rpmsg_eth_mac_addr mac_addr; + }; +} __packed; + +/** + * struct response_message - response message structure for RPMSG Ethernet + * @type: Response Type + * @id: Response ID + * @shm_info: rpmsg shared memory info + */ +struct response_message { + u32 type; + u32 id; + union { + struct rpmsg_eth_shm shm_info; + }; +} __packed; + +/** + * struct notify_message - notification message structure for RPMSG Ethern= et + * @type: Notify Type + * @id: Notify ID + */ +struct notify_message { + u32 type; + u32 id; +} __packed; + /** * struct message_header - message header structure for RPMSG Ethernet * @src_id: Source endpoint ID @@ -40,12 +150,20 @@ struct message_header { * * @msg_hdr: Message header contains source and destination endpoint and * the type of message + * @req_msg: Request message structure contains the request type and ID + * @resp_msg: Response message structure contains the response type and ID + * @notify_msg: Notification message structure contains the notify type an= d ID * * This structure is used to send and receive messages between the RPMSG * Ethernet ports. */ struct message { struct message_header msg_hdr; + union { + struct request_message req_msg; + struct response_message resp_msg; + struct notify_message notify_msg; + }; } __packed; =20 /** @@ -56,30 +174,107 @@ struct rpmsg_eth_data { u8 shm_region_index; }; =20 +/* Shared Memory Layout + * + * --------------------------- ***************** + * | MAGIC_NUM | rpmsg_eth_shm_head + * | HEAD_IDX | + * --------------------------- ***************** + * | MAGIC_NUM | + * | PKT_1_LEN | + * | PKT_1 | + * --------------------------- + * | MAGIC_NUM | + * | PKT_2_LEN | rpmsg_eth_shm_buf + * | PKT_2 | + * --------------------------- + * | . | + * | . | + * --------------------------- + * | MAGIC_NUM | + * | PKT_N_LEN | + * | PKT_N | + * --------------------------- **************** + * | MAGIC_NUM | rpmsg_eth_shm_tail + * | TAIL_IDX | + * --------------------------- **************** + */ + +enum rpmsg_eth_state { + RPMSG_ETH_STATE_PROBE, + RPMSG_ETH_STATE_OPEN, + RPMSG_ETH_STATE_CLOSE, + RPMSG_ETH_STATE_READY, + RPMSG_ETH_STATE_RUNNING, + +}; + /** * struct rpmsg_eth_common - common structure for RPMSG Ethernet * @rpdev: RPMSG device + * @send_msg: Send message + * @recv_msg: Receive message * @port: Ethernet port * @dev: Device * @data: Vendor specific data + * @state: Interface state + * @state_work: Delayed work for state machine */ struct rpmsg_eth_common { struct rpmsg_device *rpdev; + /** @send_msg_lock: Lock for sending RPMSG */ + spinlock_t send_msg_lock; + /** @recv_msg_lock: Lock for receiving RPMSG */ + spinlock_t recv_msg_lock; + struct message send_msg; + struct message recv_msg; struct rpmsg_eth_port *port; struct device *dev; struct rpmsg_eth_data data; + enum rpmsg_eth_state state; + /** @state_lock: Lock for changing interface state */ + struct mutex state_lock; + struct delayed_work state_work; +}; + +/** + * struct rpmsg_eth_ndev_priv - private structure for RPMSG Ethernet net d= evice + * @port: Ethernet port + * @dev: Device + */ +struct rpmsg_eth_ndev_priv { + struct rpmsg_eth_port *port; + struct device *dev; }; =20 /** * struct rpmsg_eth_port - Ethernet port structure for RPMSG Ethernet * @common: Pointer to the common RPMSG Ethernet structure * @shm: Shared memory region mapping + * @tx_offset: Offset for TX region in shared memory + * @rx_offset: Offset for RX region in shared memory * @buf_size: Size (in bytes) of the shared memory buffer for this port + * @rx_timer: Timer for rx polling + * @rx_napi: NAPI structure for rx polling + * @local_mac_addr: Local MAC address + * @ndev: Network device + * @tx_max_buffers: Maximum number of tx buffers + * @rx_max_buffers: Maximum number of rx buffers + * @port_id: Port ID */ struct rpmsg_eth_port { struct rpmsg_eth_common *common; void __iomem *shm; + u32 tx_offset; + u32 rx_offset; phys_addr_t buf_size; + struct timer_list rx_timer; + struct napi_struct rx_napi; + u8 local_mac_addr[ETH_ALEN]; + struct net_device *ndev; + u32 tx_max_buffers; + u32 rx_max_buffers; + u32 port_id; }; =20 #endif /* __RPMSG_ETH_H__ */ --=20 2.34.1 From nobody Thu Oct 2 20:28:26 2025 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82EC432038B; Thu, 11 Sep 2025 11:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590627; cv=none; b=A0yB8W/7WgqWbEjvYRDGWl9aFcOGx6lpQO3I5MnQbNZW9ZFaOcH3DAUNGwuZPSP+TZoQCMXiuv/SMD96u7KL2DsSzpjS0RQuAawhF8jcNHxq5iiQDgd1G3XHjiv79FOfjpdokHIBaZRmK3RNGP8D7R95yl8OfhWfjqFvncpgYsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590627; c=relaxed/simple; bh=3JuQddPCunUMjQrT6vQYeUt75KQpUx3lNt2KEVfeukw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kAK3B7vJyJLPAMHiG/QLjjaof+QAGYLriDIl+e4FG+VtpqYw8fXsOTqO+EwouzSIcHiuGRX29zX2pS+bcGegnnMXSxQoo2544kUmrfLix5uNfy+WdJ6kRNJwzabNtRJ80mgoObeBxW2ECzXFtYmWwm+EK9iKSUh1M8Xchh+lvQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=GrpcF4J3; arc=none smtp.client-ip=198.47.19.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="GrpcF4J3" Received: from fllvem-sh04.itg.ti.com ([10.64.41.54]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BBaR7J735480; Thu, 11 Sep 2025 06:36:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757590587; bh=TM6mT9th3rVCAn81L1mGY3S50wIg3OwdQwzQAAB5wWs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=GrpcF4J3GXqL6HKj3ZXdFxclmYLZ0treeZYcL4W0Frg1Bywkp1mLF8JfvfHh9d5bY 06iXriz6+wmEXrNs75rzPibf6qZT8+AWFVg/WFGgK55GUm+Fe+2yufO5G82KuVGnDg kVVVUqH7s5zT9ef3I5d9UxabSPlOtZra58PxH1IA= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by fllvem-sh04.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BBaQfO1908833 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 06:36:26 -0500 Received: from DLEE203.ent.ti.com (157.170.170.78) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 06:36:25 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DLEE203.ent.ti.com (157.170.170.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 06:36:26 -0500 Received: from fllv0122.itg.ti.com (fllv0122.itg.ti.com [10.247.120.72]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BBaPkY2062025; Thu, 11 Sep 2025 06:36:26 -0500 Received: from localhost (danish-tpc.dhcp.ti.com [172.24.231.152]) by fllv0122.itg.ti.com (8.14.7/8.14.7) with ESMTP id 58BBaPlT032075; Thu, 11 Sep 2025 06:36:25 -0500 From: MD Danish Anwar To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , MD Danish Anwar , Mengyuan Lou , Lei Wei , Xin Guo , Michael Ellerman , Fan Gong , Lorenzo Bianconi , Parthiban Veerasooran , Lukas Bulwahn , Geert Uytterhoeven CC: , , , , Subject: [PATCH net-next v4 4/7] net: rpmsg-eth: Add netdev ops Date: Thu, 11 Sep 2025 17:06:09 +0530 Message-ID: <20250911113612.2598643-5-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911113612.2598643-1-danishanwar@ti.com> References: <20250911113612.2598643-1-danishanwar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Add netdev ops for rpmsg-eth driver. This patch introduces the netdev operations for the rpmsg-eth driver, enabling the driver to interact with the Linux networking stack. The following functionalities are implemented: 1. `ndo_open` and `ndo_stop`: - Handles the initialization and cleanup of the network device during open and stop operations. - Manages the state transitions of the rpmsg-eth driver. 2. `ndo_start_xmit`: - Implements the transmit functionality by copying data from the skb to the shared memory buffer and updating the head index. 3. `ndo_set_mac_address`: - Allows setting the MAC address of the network device and sends the updated MAC address to the remote processor. 4. RX Path: - Adds a timer-based mechanism to poll for received packets in shared memory. - Implements NAPI-based packet processing to handle received packets efficiently. 5. State Machine: - Introduces a state machine to manage the driver's state transitions, such as PROBE, OPEN, READY, and RUNNING. 6. Initialization: - Adds necessary initialization for locks, timers, and work structures. - Registers the network device and sets up NAPI and RX timer. 7. Cleanup: - Ensures proper cleanup of resources during driver removal, including NAPI and timers. This patch enhances the rpmsg-eth driver to function as a fully operational network device in the Linux kernel. Signed-off-by: MD Danish Anwar --- drivers/net/ethernet/rpmsg_eth.c | 318 +++++++++++++++++++++++++++++++ drivers/net/ethernet/rpmsg_eth.h | 2 + 2 files changed, 320 insertions(+) diff --git a/drivers/net/ethernet/rpmsg_eth.c b/drivers/net/ethernet/rpmsg_= eth.c index f599318633ea..43196e1d7eeb 100644 --- a/drivers/net/ethernet/rpmsg_eth.c +++ b/drivers/net/ethernet/rpmsg_eth.c @@ -63,6 +63,108 @@ static int rpmsg_eth_validate_handshake(struct rpmsg_et= h_port *port, return 0; } =20 +static int create_request(struct rpmsg_eth_common *common, + enum rpmsg_eth_rpmsg_type rpmsg_type) +{ + struct message *msg =3D &common->send_msg; + + msg->msg_hdr.src_id =3D common->port->port_id; + msg->req_msg.type =3D rpmsg_type; + + switch (rpmsg_type) { + case RPMSG_ETH_REQ_SHM_INFO: + msg->msg_hdr.msg_type =3D RPMSG_ETH_REQUEST_MSG; + break; + case RPMSG_ETH_REQ_SET_MAC_ADDR: + msg->msg_hdr.msg_type =3D RPMSG_ETH_REQUEST_MSG; + ether_addr_copy(msg->req_msg.mac_addr.addr, + common->port->ndev->dev_addr); + break; + case RPMSG_ETH_NOTIFY_PORT_UP: + case RPMSG_ETH_NOTIFY_PORT_DOWN: + msg->msg_hdr.msg_type =3D RPMSG_ETH_NOTIFY_MSG; + break; + default: + dev_err(common->dev, "Invalid RPMSG request\n"); + return -EINVAL; + } + return 0; +} + +static int rpmsg_eth_create_send_request(struct rpmsg_eth_common *common, + enum rpmsg_eth_rpmsg_type rpmsg_type, + bool wait) +{ + unsigned long flags; + int ret; + + if (wait) + reinit_completion(&common->sync_msg); + + spin_lock_irqsave(&common->send_msg_lock, flags); + ret =3D create_request(common, rpmsg_type); + if (ret) + goto release_lock; + + ret =3D rpmsg_send(common->rpdev->ept, (void *)(&common->send_msg), + sizeof(common->send_msg)); + if (ret) { + dev_err(common->dev, "Failed to send RPMSG message\n"); + goto release_lock; + } + + spin_unlock_irqrestore(&common->send_msg_lock, flags); + if (wait) { + ret =3D wait_for_completion_timeout(&common->sync_msg, + RPMSG_ETH_REQ_TIMEOUT_JIFFIES); + + if (!ret) { + dev_err(common->dev, "Failed to receive response within %ld jiffies\n", + RPMSG_ETH_REQ_TIMEOUT_JIFFIES); + return -ETIMEDOUT; + } + ret =3D 0; + } + return ret; +release_lock: + spin_unlock_irqrestore(&common->send_msg_lock, flags); + return ret; +} + +static void rpmsg_eth_state_machine(struct work_struct *work) +{ + struct delayed_work *dwork =3D to_delayed_work(work); + struct rpmsg_eth_common *common; + struct rpmsg_eth_port *port; + int ret; + + common =3D container_of(dwork, struct rpmsg_eth_common, state_work); + port =3D common->port; + + mutex_lock(&common->state_lock); + + switch (common->state) { + case RPMSG_ETH_STATE_PROBE: + break; + case RPMSG_ETH_STATE_OPEN: + rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_SHM_INFO, false); + break; + case RPMSG_ETH_STATE_CLOSE: + break; + case RPMSG_ETH_STATE_READY: + ret =3D rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_SET_MAC_ADDR= , false); + if (!ret) { + napi_enable(&port->rx_napi); + netif_carrier_on(port->ndev); + mod_timer(&port->rx_timer, RX_POLL_TIMEOUT_JIFFIES); + } + break; + case RPMSG_ETH_STATE_RUNNING: + break; + } + mutex_unlock(&common->state_lock); +} + static int rpmsg_eth_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int = len, void *priv, u32 src) { @@ -99,6 +201,17 @@ static int rpmsg_eth_rpmsg_cb(struct rpmsg_device *rpde= v, void *data, int len, msg->resp_msg.shm_info.num_pkt_bufs; port->rx_max_buffers =3D msg->resp_msg.shm_info.num_pkt_bufs; + + mutex_lock(&common->state_lock); + common->state =3D RPMSG_ETH_STATE_READY; + mutex_unlock(&common->state_lock); + + mod_delayed_work(system_wq, + &common->state_work, + STATE_MACHINE_TIME_JIFFIES); + + break; + case RPMSG_ETH_RESP_SET_MAC_ADDR: break; } break; @@ -106,6 +219,20 @@ static int rpmsg_eth_rpmsg_cb(struct rpmsg_device *rpd= ev, void *data, int len, rpmsg_type =3D msg->notify_msg.type; dev_dbg(common->dev, "Msg type =3D %d, RPMsg type =3D %d, Src Id =3D %d,= Msg Id =3D %d\n", msg_type, rpmsg_type, msg->msg_hdr.src_id, msg->notify_msg.id); + switch (rpmsg_type) { + case RPMSG_ETH_NOTIFY_REMOTE_READY: + mutex_lock(&common->state_lock); + common->state =3D RPMSG_ETH_STATE_RUNNING; + mutex_unlock(&common->state_lock); + + mod_delayed_work(system_wq, + &common->state_work, + STATE_MACHINE_TIME_JIFFIES); + break; + case RPMSG_ETH_NOTIFY_PORT_UP: + case RPMSG_ETH_NOTIFY_PORT_DOWN: + break; + } break; default: dev_err(common->dev, "Invalid msg type\n"); @@ -172,6 +299,181 @@ static int rpmsg_eth_get_shm_info(struct rpmsg_eth_co= mmon *common) return 0; } =20 +static void rpmsg_eth_rx_timer(struct timer_list *timer) +{ + struct rpmsg_eth_port *port =3D timer_container_of(port, timer, rx_timer); + struct napi_struct *napi; + int num_pkts =3D 0; + u32 head, tail; + + head =3D readl(port->shm + port->rx_offset + HEAD_IDX_OFFSET); + tail =3D readl(port->shm + port->rx_offset + + TAIL_IDX_OFFSET(port->rx_max_buffers)); + + num_pkts =3D tail - head; + num_pkts =3D num_pkts >=3D 0 ? num_pkts : + (num_pkts + port->rx_max_buffers); + + napi =3D &port->rx_napi; + if (num_pkts && likely(napi_schedule_prep(napi))) + __napi_schedule(napi); + else + mod_timer(&port->rx_timer, RX_POLL_JIFFIES); +} + +static int rpmsg_eth_rx_packets(struct napi_struct *napi, int budget) +{ + struct rpmsg_eth_port *port =3D container_of(napi, struct rpmsg_eth_port,= rx_napi); + u32 count, process_pkts; + struct sk_buff *skb; + u32 head, tail; + int num_pkts; + u32 pkt_len; + + head =3D readl(port->shm + port->rx_offset + HEAD_IDX_OFFSET); + tail =3D readl(port->shm + port->rx_offset + + TAIL_IDX_OFFSET(port->rx_max_buffers)); + + num_pkts =3D head - tail; + + num_pkts =3D num_pkts >=3D 0 ? num_pkts : + (num_pkts + port->rx_max_buffers); + process_pkts =3D min(num_pkts, budget); + count =3D 0; + while (count < process_pkts) { + memcpy_fromio((void *)&pkt_len, + port->shm + port->rx_offset + MAGIC_NUM_SIZE_TYPE + + PKT_START_OFFSET((tail + count) % port->rx_max_buffers), + PKT_LEN_SIZE_TYPE); + /* Start building the skb */ + skb =3D napi_alloc_skb(napi, pkt_len); + if (!skb) { + port->ndev->stats.rx_dropped++; + goto rx_dropped; + } + + skb->dev =3D port->ndev; + skb_put(skb, pkt_len); + memcpy_fromio((void *)skb->data, + port->shm + port->rx_offset + PKT_LEN_SIZE_TYPE + + MAGIC_NUM_SIZE_TYPE + + PKT_START_OFFSET((tail + count) % port->rx_max_buffers), + pkt_len); + + skb->protocol =3D eth_type_trans(skb, port->ndev); + + /* Push skb into network stack */ + napi_gro_receive(napi, skb); + + count++; + port->ndev->stats.rx_packets++; + port->ndev->stats.rx_bytes +=3D skb->len; + } + +rx_dropped: + + if (num_pkts) { + writel((tail + count) % port->rx_max_buffers, + port->shm + port->rx_offset + + TAIL_IDX_OFFSET(port->rx_max_buffers)); + + if (num_pkts < budget && napi_complete_done(napi, count)) + mod_timer(&port->rx_timer, RX_POLL_TIMEOUT_JIFFIES); + } + + return count; +} + +static int rpmsg_eth_ndo_open(struct net_device *ndev) +{ + struct rpmsg_eth_common *common =3D rpmsg_eth_ndev_to_common(ndev); + + mutex_lock(&common->state_lock); + common->state =3D RPMSG_ETH_STATE_OPEN; + mutex_unlock(&common->state_lock); + mod_delayed_work(system_wq, &common->state_work, msecs_to_jiffies(100)); + + return 0; +} + +static int rpmsg_eth_ndo_stop(struct net_device *ndev) +{ + struct rpmsg_eth_common *common =3D rpmsg_eth_ndev_to_common(ndev); + struct rpmsg_eth_port *port =3D rpmsg_eth_ndev_to_port(ndev); + + mutex_lock(&common->state_lock); + common->state =3D RPMSG_ETH_STATE_CLOSE; + mutex_unlock(&common->state_lock); + + netif_carrier_off(port->ndev); + + cancel_delayed_work_sync(&common->state_work); + timer_delete_sync(&port->rx_timer); + napi_disable(&port->rx_napi); + + return 0; +} + +static netdev_tx_t rpmsg_eth_start_xmit(struct sk_buff *skb, struct net_de= vice *ndev) +{ + struct rpmsg_eth_port *port =3D rpmsg_eth_ndev_to_port(ndev); + u32 head, tail; + int num_pkts; + u32 len; + + len =3D skb_headlen(skb); + head =3D readl(port->shm + port->tx_offset + HEAD_IDX_OFFSET); + tail =3D readl(port->shm + port->tx_offset + + TAIL_IDX_OFFSET(port->tx_max_buffers)); + + /* If the buffer queue is full, then drop packet */ + num_pkts =3D head - tail; + num_pkts =3D num_pkts >=3D 0 ? num_pkts : + (num_pkts + port->tx_max_buffers); + + if ((num_pkts + 1) =3D=3D port->tx_max_buffers) { + netdev_warn(ndev, "Tx buffer full %d\n", num_pkts); + goto ring_full; + } + /* Copy length */ + memcpy_toio(port->shm + port->tx_offset + PKT_START_OFFSET(head) + MAGIC_= NUM_SIZE_TYPE, + (void *)&len, PKT_LEN_SIZE_TYPE); + /* Copy data to shared mem */ + memcpy_toio(port->shm + port->tx_offset + PKT_START_OFFSET(head) + MAGIC_= NUM_SIZE_TYPE + + PKT_LEN_SIZE_TYPE, (void *)skb->data, len); + writel((head + 1) % port->tx_max_buffers, + port->shm + port->tx_offset + HEAD_IDX_OFFSET); + + ndev->stats.tx_packets++; + ndev->stats.tx_bytes +=3D skb->len; + + dev_consume_skb_any(skb); + return NETDEV_TX_OK; + +ring_full: + return NETDEV_TX_BUSY; +} + +static int rpmsg_eth_set_mac_address(struct net_device *ndev, void *addr) +{ + struct rpmsg_eth_common *common =3D rpmsg_eth_ndev_to_common(ndev); + int ret; + + ret =3D eth_mac_addr(ndev, addr); + + if (ret < 0) + return ret; + + return rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_SET_MAC_ADDR, = false); +} + +static const struct net_device_ops rpmsg_eth_netdev_ops =3D { + .ndo_open =3D rpmsg_eth_ndo_open, + .ndo_stop =3D rpmsg_eth_ndo_stop, + .ndo_start_xmit =3D rpmsg_eth_start_xmit, + .ndo_set_mac_address =3D rpmsg_eth_set_mac_address, +}; + static int rpmsg_eth_init_ndev(struct rpmsg_eth_common *common) { struct device *dev =3D &common->rpdev->dev; @@ -195,6 +497,7 @@ static int rpmsg_eth_init_ndev(struct rpmsg_eth_common = *common) =20 ndev_priv =3D netdev_priv(port->ndev); ndev_priv->port =3D port; + port->ndev->netdev_ops =3D &rpmsg_eth_netdev_ops; SET_NETDEV_DEV(port->ndev, dev); =20 port->ndev->min_mtu =3D RPMSG_ETH_MIN_PACKET_SIZE; @@ -206,6 +509,8 @@ static int rpmsg_eth_init_ndev(struct rpmsg_eth_common = *common) } =20 netif_carrier_off(port->ndev); + netif_napi_add(port->ndev, &port->rx_napi, rpmsg_eth_rx_packets); + timer_setup(&port->rx_timer, rpmsg_eth_rx_timer, 0); err =3D register_netdev(port->ndev); if (err) dev_err(dev, "error registering rpmsg_eth net device %d\n", err); @@ -235,6 +540,12 @@ static int rpmsg_eth_probe(struct rpmsg_device *rpdev) if (ret) return ret; =20 + spin_lock_init(&common->send_msg_lock); + spin_lock_init(&common->recv_msg_lock); + mutex_init(&common->state_lock); + INIT_DELAYED_WORK(&common->state_work, rpmsg_eth_state_machine); + init_completion(&common->sync_msg); + /* Register the network device */ ret =3D rpmsg_eth_init_ndev(common); if (ret) @@ -245,6 +556,13 @@ static int rpmsg_eth_probe(struct rpmsg_device *rpdev) =20 static void rpmsg_eth_remove(struct rpmsg_device *rpdev) { + struct rpmsg_eth_common *common =3D dev_get_drvdata(&rpdev->dev); + struct rpmsg_eth_port *port =3D common->port; + + netif_napi_del(&port->rx_napi); + timer_delete_sync(&port->rx_timer); + unregister_netdev(port->ndev); + dev_dbg(&rpdev->dev, "rpmsg-eth client driver is removed\n"); } =20 diff --git a/drivers/net/ethernet/rpmsg_eth.h b/drivers/net/ethernet/rpmsg_= eth.h index 0a0695e857df..80fa07be1678 100644 --- a/drivers/net/ethernet/rpmsg_eth.h +++ b/drivers/net/ethernet/rpmsg_eth.h @@ -219,6 +219,7 @@ enum rpmsg_eth_state { * @data: Vendor specific data * @state: Interface state * @state_work: Delayed work for state machine + * @sync_msg: Completion for synchronous message */ struct rpmsg_eth_common { struct rpmsg_device *rpdev; @@ -235,6 +236,7 @@ struct rpmsg_eth_common { /** @state_lock: Lock for changing interface state */ struct mutex state_lock; struct delayed_work state_work; + struct completion sync_msg; }; =20 /** --=20 2.34.1 From nobody Thu Oct 2 20:28:26 2025 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63FB931CA65; Thu, 11 Sep 2025 11:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590926; cv=none; b=amIGTXHWBKVopL8+6/Uj6rgLpA6wcrUiJjeEOLFcQOx1DQUfr7s6kLUDFB17wJ1QsAxf2+dkeuxDBrEwHhajKIUwMF7q9ohEI3YZhWnCmoQGLoAeLZaROqAvkfQ1ctOvOlrwunPmcSdNPIW9HqDXvmiJinaFjl9cgcOX5Hv24xQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590926; c=relaxed/simple; bh=JQQi36eZE14yH3jRBYl6UW9XA0A2eEGQafkfVENT8Ac=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=grYFFn9bvHLQjA6EX4ME36y5+LKTtt8DkHyAPkIax4fGjhz9Gu7VR3+SRRUQD4LV9VSkl6qgwFI4EiEYuz+XKt4oxDyBcLwEJpZ/69gbBH6pXc/drmPAv+tnBIIatxrZlsOjdI0LEREMA2k2R1+oRBPBGl9PnxQS3OBUo1qbgnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=i5JGUhxZ; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="i5JGUhxZ" Received: from lelvem-sh01.itg.ti.com ([10.180.77.71]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BBaSPF282600; Thu, 11 Sep 2025 06:36:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757590588; bh=MvLpwpR2k8oWPS7J/omjOonARgnQ/9NgXe245RoEZPI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=i5JGUhxZAtlepksxmLTonKbL9ibKpoQc9n3ck1pQSbI+fWfUeepdUQ9DoYwDw876U 8Ef/8ztmGSbAcSisQMNAXipQL4VMXUKSuBrh633GqFusOsqg8p5gIFxn81e2bFbIcj cbZKFivyWQmOaRmgz8rAvH2F651YJVZk6rUzMvTk= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelvem-sh01.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BBaSVT464628 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 06:36:28 -0500 Received: from DFLE211.ent.ti.com (10.64.6.69) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 06:36:28 -0500 Received: from fllvem-mr07.itg.ti.com (10.64.41.89) by DFLE211.ent.ti.com (10.64.6.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 06:36:28 -0500 Received: from fllv0122.itg.ti.com (fllv0122.itg.ti.com [10.247.120.72]) by fllvem-mr07.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BBaSwp1068579; Thu, 11 Sep 2025 06:36:28 -0500 Received: from localhost (danish-tpc.dhcp.ti.com [172.24.231.152]) by fllv0122.itg.ti.com (8.14.7/8.14.7) with ESMTP id 58BBaR4d032081; Thu, 11 Sep 2025 06:36:27 -0500 From: MD Danish Anwar To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , MD Danish Anwar , Mengyuan Lou , Lei Wei , Xin Guo , Michael Ellerman , Fan Gong , Lorenzo Bianconi , Parthiban Veerasooran , Lukas Bulwahn , Geert Uytterhoeven CC: , , , , Subject: [PATCH net-next v4 5/7] net: rpmsg-eth: Add support for multicast filtering Date: Thu, 11 Sep 2025 17:06:10 +0530 Message-ID: <20250911113612.2598643-6-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911113612.2598643-1-danishanwar@ti.com> References: <20250911113612.2598643-1-danishanwar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Add support for multicast filtering for RPMSG ETH driver. Implement the ndo_set_rx_mode callback as icve_set_rx_mode() API. rx_mode_workqueue is initialized in rpmsg_eth_probe() and queued in rpmsg_eth_set_rx_mode(). Signed-off-by: MD Danish Anwar --- drivers/net/ethernet/rpmsg_eth.c | 63 ++++++++++++++++++++++++++++++++ drivers/net/ethernet/rpmsg_eth.h | 12 ++++++ 2 files changed, 75 insertions(+) diff --git a/drivers/net/ethernet/rpmsg_eth.c b/drivers/net/ethernet/rpmsg_= eth.c index 43196e1d7eeb..cde19d924b89 100644 --- a/drivers/net/ethernet/rpmsg_eth.c +++ b/drivers/net/ethernet/rpmsg_eth.c @@ -80,6 +80,11 @@ static int create_request(struct rpmsg_eth_common *commo= n, ether_addr_copy(msg->req_msg.mac_addr.addr, common->port->ndev->dev_addr); break; + case RPMSG_ETH_REQ_ADD_MC_ADDR: + case RPMSG_ETH_REQ_DEL_MC_ADDR: + ether_addr_copy(msg->req_msg.mac_addr.addr, + common->mcast_addr); + break; case RPMSG_ETH_NOTIFY_PORT_UP: case RPMSG_ETH_NOTIFY_PORT_DOWN: msg->msg_hdr.msg_type =3D RPMSG_ETH_NOTIFY_MSG; @@ -131,6 +136,22 @@ static int rpmsg_eth_create_send_request(struct rpmsg_= eth_common *common, return ret; } =20 +static int rpmsg_eth_add_mc_addr(struct net_device *ndev, const u8 *addr) +{ + struct rpmsg_eth_common *common =3D rpmsg_eth_ndev_to_common(ndev); + + ether_addr_copy(common->mcast_addr, addr); + return rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_ADD_MC_ADDR, t= rue); +} + +static int rpmsg_eth_del_mc_addr(struct net_device *ndev, const u8 *addr) +{ + struct rpmsg_eth_common *common =3D rpmsg_eth_ndev_to_common(ndev); + + ether_addr_copy(common->mcast_addr, addr); + return rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_DEL_MC_ADDR, t= rue); +} + static void rpmsg_eth_state_machine(struct work_struct *work) { struct delayed_work *dwork =3D to_delayed_work(work); @@ -213,6 +234,10 @@ static int rpmsg_eth_rpmsg_cb(struct rpmsg_device *rpd= ev, void *data, int len, break; case RPMSG_ETH_RESP_SET_MAC_ADDR: break; + case RPMSG_ETH_RESP_ADD_MC_ADDR: + case RPMSG_ETH_RESP_DEL_MC_ADDR: + complete(&common->sync_msg); + break; } break; case RPMSG_ETH_NOTIFY_MSG: @@ -407,10 +432,15 @@ static int rpmsg_eth_ndo_stop(struct net_device *ndev) =20 netif_carrier_off(port->ndev); =20 + __dev_mc_unsync(ndev, rpmsg_eth_del_mc_addr); + __hw_addr_init(&common->mc_list); + cancel_delayed_work_sync(&common->state_work); timer_delete_sync(&port->rx_timer); napi_disable(&port->rx_napi); =20 + cancel_work_sync(&common->rx_mode_work); + return 0; } =20 @@ -467,10 +497,35 @@ static int rpmsg_eth_set_mac_address(struct net_devic= e *ndev, void *addr) return rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_SET_MAC_ADDR, = false); } =20 +static void rpmsg_eth_ndo_set_rx_mode_work(struct work_struct *work) +{ + struct rpmsg_eth_common *common; + struct net_device *ndev; + + common =3D container_of(work, struct rpmsg_eth_common, rx_mode_work); + ndev =3D common->port->ndev; + + /* make a mc list copy */ + netif_addr_lock_bh(ndev); + __hw_addr_sync(&common->mc_list, &ndev->mc, ndev->addr_len); + netif_addr_unlock_bh(ndev); + + __hw_addr_sync_dev(&common->mc_list, ndev, rpmsg_eth_add_mc_addr, + rpmsg_eth_del_mc_addr); +} + +static void rpmsg_eth_set_rx_mode(struct net_device *ndev) +{ + struct rpmsg_eth_common *common =3D rpmsg_eth_ndev_to_common(ndev); + + queue_work(common->cmd_wq, &common->rx_mode_work); +} + static const struct net_device_ops rpmsg_eth_netdev_ops =3D { .ndo_open =3D rpmsg_eth_ndo_open, .ndo_stop =3D rpmsg_eth_ndo_stop, .ndo_start_xmit =3D rpmsg_eth_start_xmit, + .ndo_set_rx_mode =3D rpmsg_eth_set_rx_mode, .ndo_set_mac_address =3D rpmsg_eth_set_mac_address, }; =20 @@ -546,6 +601,13 @@ static int rpmsg_eth_probe(struct rpmsg_device *rpdev) INIT_DELAYED_WORK(&common->state_work, rpmsg_eth_state_machine); init_completion(&common->sync_msg); =20 + __hw_addr_init(&common->mc_list); + INIT_WORK(&common->rx_mode_work, rpmsg_eth_ndo_set_rx_mode_work); + common->cmd_wq =3D create_singlethread_workqueue("rpmsg_eth_rx_work"); + if (!common->cmd_wq) { + dev_err(dev, "Failure requesting workqueue\n"); + return -ENOMEM; + } /* Register the network device */ ret =3D rpmsg_eth_init_ndev(common); if (ret) @@ -562,6 +624,7 @@ static void rpmsg_eth_remove(struct rpmsg_device *rpdev) netif_napi_del(&port->rx_napi); timer_delete_sync(&port->rx_timer); unregister_netdev(port->ndev); + destroy_workqueue(common->cmd_wq); =20 dev_dbg(&rpdev->dev, "rpmsg-eth client driver is removed\n"); } diff --git a/drivers/net/ethernet/rpmsg_eth.h b/drivers/net/ethernet/rpmsg_= eth.h index 80fa07be1678..d6112cb9269a 100644 --- a/drivers/net/ethernet/rpmsg_eth.h +++ b/drivers/net/ethernet/rpmsg_eth.h @@ -58,10 +58,14 @@ enum rpmsg_eth_rpmsg_type { /* Request types */ RPMSG_ETH_REQ_SHM_INFO =3D 0, RPMSG_ETH_REQ_SET_MAC_ADDR, + RPMSG_ETH_REQ_ADD_MC_ADDR, + RPMSG_ETH_REQ_DEL_MC_ADDR, =20 /* Response types */ RPMSG_ETH_RESP_SHM_INFO, RPMSG_ETH_RESP_SET_MAC_ADDR, + RPMSG_ETH_RESP_ADD_MC_ADDR, + RPMSG_ETH_RESP_DEL_MC_ADDR, =20 /* Notification types */ RPMSG_ETH_NOTIFY_PORT_UP, @@ -220,6 +224,10 @@ enum rpmsg_eth_state { * @state: Interface state * @state_work: Delayed work for state machine * @sync_msg: Completion for synchronous message + * @rx_mode_work: Work structure for rx mode + * @cmd_wq: Workqueue for commands + * @mc_list: List of multicast addresses + * @mcast_addr: Multicast address filter */ struct rpmsg_eth_common { struct rpmsg_device *rpdev; @@ -237,6 +245,10 @@ struct rpmsg_eth_common { struct mutex state_lock; struct delayed_work state_work; struct completion sync_msg; + struct work_struct rx_mode_work; + struct workqueue_struct *cmd_wq; + struct netdev_hw_addr_list mc_list; + u8 mcast_addr[ETH_ALEN]; }; =20 /** --=20 2.34.1 From nobody Thu Oct 2 20:28:26 2025 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AACEF321456; Thu, 11 Sep 2025 11:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590631; cv=none; b=pYIXerUg4XVfONQPlwFDrT0+N6Br6Bj73LkuceC83iWqBHh3SGOdvzRpA+oc5ssFulUjoBQLSywRMDiRzWdgie1jgp6LrEPtM5LZWN6rKkUy0UklAKqtbJfrF01f5hTJteM8Ys6Uyc59Y1jmXPK6uQGHD9JkvboXG78bjqtUziY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590631; c=relaxed/simple; bh=f19zsr4kaltVZz4tiXmXoetEm2f2Hxlavoo5DtHjrPM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r52JFribMlw0SdS/T1b3i1IBV2/tmG9GV8bXWDD1KGc1Fz+juPJgw3OaNfS5huEiWgtCQ/9QO5MY/pvWdYGjoBXr8rcGXccSeJtLrEj8mEzeK/nz0CFDHJht7oy4+Ub1wAFqzg9zT12tDkDn+7jMH7EzEdekP9al4oRfxRjFofw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=hOfDKkMm; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="hOfDKkMm" Received: from lelvem-sh02.itg.ti.com ([10.180.78.226]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BBaUED793666; Thu, 11 Sep 2025 06:36:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757590590; bh=78saqbBV7l7amg+T7GZYrtVBXo8ffvbG+RF5wZUGKuQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=hOfDKkMmxr580oGsCMt4qLsxC/JdOJSSOH6HAXjmH4wLKLlMk/EhVPMVUgwjQAovq Ju1gdfKhxfgyemDxuACApHGu8RoKrW/C/8qTj0UqA4oUdIXZ3NuEEyg5jKr5m312wl RSpA7jo9VlnvcIQfC8En1GqcVEJZs7PAuF+2BLD8= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelvem-sh02.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BBaURW1027202 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 06:36:30 -0500 Received: from DLEE211.ent.ti.com (157.170.170.113) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 06:36:30 -0500 Received: from fllvem-mr08.itg.ti.com (10.64.41.88) by DLEE211.ent.ti.com (157.170.170.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 06:36:30 -0500 Received: from fllv0122.itg.ti.com (fllv0122.itg.ti.com [10.247.120.72]) by fllvem-mr08.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BBaUha1015163; Thu, 11 Sep 2025 06:36:30 -0500 Received: from localhost (danish-tpc.dhcp.ti.com [172.24.231.152]) by fllv0122.itg.ti.com (8.14.7/8.14.7) with ESMTP id 58BBaTgj032087; Thu, 11 Sep 2025 06:36:29 -0500 From: MD Danish Anwar To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , MD Danish Anwar , Mengyuan Lou , Lei Wei , Xin Guo , Michael Ellerman , Fan Gong , Lorenzo Bianconi , Parthiban Veerasooran , Lukas Bulwahn , Geert Uytterhoeven CC: , , , , Subject: [PATCH net-next v4 6/7] MAINTAINERS: Add entry for RPMSG Ethernet driver Date: Thu, 11 Sep 2025 17:06:11 +0530 Message-ID: <20250911113612.2598643-7-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911113612.2598643-1-danishanwar@ti.com> References: <20250911113612.2598643-1-danishanwar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Add an entry to MAINTAINERS file for the rpmsg_eth driver with appropriate maintainer information and mailing list. Signed-off-by: MD Danish Anwar --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index e3907f0c1243..9fd0f6a602d0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22001,6 +22001,12 @@ L: linux-remoteproc@vger.kernel.org S: Maintained F: drivers/tty/rpmsg_tty.c =20 +RPMSG ETHERNET DRIVER +M: MD Danish Anwar +L: netdev@vger.kernel.org +S: Maintained +F: drivers/net/ethernet/rpmsg_eth* + RTASE ETHERNET DRIVER M: Justin Lai M: Larry Chiu --=20 2.34.1 From nobody Thu Oct 2 20:28:26 2025 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 540AF321442; Thu, 11 Sep 2025 11:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590631; cv=none; b=bmAsKvTNjm7bELpuPflnDZJXTJ5PGArfI8S4tiAlGVYBOD3am5pRHFqH08fWlWWsRuQkh83jDhmhD/CXw5dHLTtawKokTiZtg8TYDCiZUeFWqbZ28SykzPtxXOoHEZicZg7dJOBuQhQohg+5pfSvyDHMFrMbsbJMxP0N4CYF8xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757590631; c=relaxed/simple; bh=uCqh6weCbxxwSYUyrSLOci8g9ps7pnde7H7nW1y6vTI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LEZPSdLHHa+q08l2rKx0PbgdNx1yuuAMIfl59R4y2Y4zfPkrBFIyFRfWIY/2D+jtnEe88EXmiHN4mIqEN+HgtRqBLhODA+N6MQs+AyViPiOmGgKtkEX34/GEPdRPKfc+RYEacOS5u/6Nokb0yY+CfZxLFj7TqXqI/DDoHK2uyGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=csaVuRTW; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="csaVuRTW" Received: from lelvem-sh02.itg.ti.com ([10.180.78.226]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BBaWZ0793678; Thu, 11 Sep 2025 06:36:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757590592; bh=zRsIr23BIzgLzTmL8Py68DcXdNh7zzWEy6t51VP+4LQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=csaVuRTWANMjTWvJzA+8pI34HZcinEHvdvvHBq/vPXeimK0ExgheZbJ59jgLUQuha CiSgL0fBWumCz/N0hclO5oyHkHipU4+gqZC5cgeJuk3jMJGiR0oN9QHoK8dorJQzvA NaVcgiwywP8HPeQLU/wowrmJrcrZwOnNtUEDo8R8= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by lelvem-sh02.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BBaWPC1027214 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 06:36:32 -0500 Received: from DLEE200.ent.ti.com (157.170.170.75) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 06:36:32 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DLEE200.ent.ti.com (157.170.170.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 06:36:32 -0500 Received: from fllv0122.itg.ti.com (fllv0122.itg.ti.com [10.247.120.72]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BBaWWU1766328; Thu, 11 Sep 2025 06:36:32 -0500 Received: from localhost (danish-tpc.dhcp.ti.com [172.24.231.152]) by fllv0122.itg.ti.com (8.14.7/8.14.7) with ESMTP id 58BBaVFh032092; Thu, 11 Sep 2025 06:36:31 -0500 From: MD Danish Anwar To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , MD Danish Anwar , Mengyuan Lou , Lei Wei , Xin Guo , Michael Ellerman , Fan Gong , Lorenzo Bianconi , Parthiban Veerasooran , Lukas Bulwahn , Geert Uytterhoeven CC: , , , , Subject: [PATCH net-next v4 7/7] arch: arm64: dts: k3-am64*: Add shared memory region Date: Thu, 11 Sep 2025 17:06:12 +0530 Message-ID: <20250911113612.2598643-8-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911113612.2598643-1-danishanwar@ti.com> References: <20250911113612.2598643-1-danishanwar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Reserve a shared memory region for rpmsg eth communication and add it to the remote proc device `main_r5fss0_core0`. Signed-off-by: MD Danish Anwar --- arch/arm64/boot/dts/ti/k3-am642-evm.dts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/ti/k3-am642-evm.dts b/arch/arm64/boot/dts/= ti/k3-am642-evm.dts index e01866372293..6e8e2c39146b 100644 --- a/arch/arm64/boot/dts/ti/k3-am642-evm.dts +++ b/arch/arm64/boot/dts/ti/k3-am642-evm.dts @@ -61,7 +61,13 @@ main_r5fss0_core0_dma_memory_region: r5f-dma-memory@a000= 0000 { =20 main_r5fss0_core0_memory_region: r5f-memory@a0100000 { compatible =3D "shared-dma-pool"; - reg =3D <0x00 0xa0100000 0x00 0xf00000>; + reg =3D <0x00 0xa0100000 0x00 0x300000>; + no-map; + }; + + main_r5fss0_core0_memory_region_shm: r5f-shm-memory@a0400000 { + compatible =3D "shared-dma-pool"; + reg =3D <0x00 0xa0400000 0x00 0xc00000>; no-map; }; =20 @@ -767,7 +773,8 @@ mbox_m4_0: mbox-m4-0 { &main_r5fss0_core0 { mboxes =3D <&mailbox0_cluster2 &mbox_main_r5fss0_core0>; memory-region =3D <&main_r5fss0_core0_dma_memory_region>, - <&main_r5fss0_core0_memory_region>; + <&main_r5fss0_core0_memory_region>, + <&main_r5fss0_core0_memory_region_shm>; }; =20 &main_r5fss0_core1 { --=20 2.34.1