From patchwork Sat May 18 12:42:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667609 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 C0EB04501C; Sat, 18 May 2024 12:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036198; cv=none; b=lno5wbcGbb1MpOqvTjkyErJcDFX7LUwGJZ3h5ko1akghdjnV1zmzAcqspQC0mOe2eYOVzbLsjX8k7WccAxERFDgWaHTkQxc7vz9lsf6aZ7f7gheQF9G+8n7akPtAjkxUN3DpjPv3iqAzpa59uncs9fwmPTES0ctmD6fcu3CcHcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036198; c=relaxed/simple; bh=Koe1sNrTYjSZCLuUcQozRg8Jzt4dLoVCuqgb/Y44CoI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X6GdKNlVb7BYNQVFCfpL8r+wPBIR7nTCV6EnRGWNXIoqjztirArCadzQoJJaw/B78IWf3tq9sEG6Mh7TGMN7zfem6mjvYewgA22H5R6/Mi8V/QlhuDLyUnWWFXi3FlVhOybkc922LMfUFiBk7ZqoRgX8Rl52lZvrb3fZo1Z3t3w= 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=kwxAuE8x; arc=none smtp.client-ip=198.47.19.141 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="kwxAuE8x" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgi82002707; Sat, 18 May 2024 07:42:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036164; bh=HErwNj3FkwqS+RMt1FiDnjhDBqOllwZh3tB5aqDrELw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=kwxAuE8xfN+7xRaYrs2/AEkk3tRY/NXvAHHzKxgumDdYginJ4lNPIj9F76RhQsQFc b8jcT5viEvTCyC7wwioIWcgPFt+Q6aBu14FpOxIP92ARA96wKJyCFFwHMmCFX48rIS nVPnA4kMQHYxGpBLOFce0Oofkro8G1bXLSzmDe0k= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICgivo129113 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:42:44 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:42:43 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:42:44 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9H041511; Sat, 18 May 2024 07:42:39 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 01/28] docs: networking: ti: add driver doc for CPSW Proxy Client Date: Sat, 18 May 2024 18:12:07 +0530 Message-ID: <20240518124234.2671651-2-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The CPSW Proxy Client driver interfaces with Ethernet Switch Firmware on a remote core to enable Ethernet functionality for applications running on Linux. The Ethernet Switch Firmware (EthFw) is in control of the CPSW Ethernet Switch on the SoC and acts as the Server, offering services to Clients running on various cores. Signed-off-by: Siddharth Vadapalli --- .../ethernet/ti/cpsw_proxy_client.rst | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/ti/cpsw_proxy_client.rst diff --git a/Documentation/networking/device_drivers/ethernet/ti/cpsw_proxy_client.rst b/Documentation/networking/device_drivers/ethernet/ti/cpsw_proxy_client.rst new file mode 100644 index 000000000000..46bff67b3446 --- /dev/null +++ b/Documentation/networking/device_drivers/ethernet/ti/cpsw_proxy_client.rst @@ -0,0 +1,182 @@ +.. SPDX-License-Identifier: GPL-2.0-only or MIT + +========================================== +Texas Instruments CPSW Proxy Client driver +========================================== + +Introduction +============ + +The CPSW (Common Platform Switch) Ethernet Switch on TI's K3 SoCs provides +Ethernet functionality. There may be multiple instances of CPSW on a single +SoC. The term "CPSWnG" is used to indicate the number of MAC Ports supported +by a specific instance of CPSW. CPSWnG indicates that the peripheral has +(n-1) MAC Ports and 1 Host Port. Examples of existing instances are: +CPSW2G => 1 MAC Port and 1 Host Port +CPSW3G => 2 MAC Ports and 1 Host Port +CPSW5G => 4 MAC Ports and 1 Host Port +CPSW9G => 8 MAC Ports and 1 Host Port + +The presence of 2 or more MAC Ports implies that Hardware Switching can +be enabled between the MAC Ports if required. + +The "am65-cpsw-nuss.c" driver in Linux at: +drivers/net/ethernet/ti/am65-cpsw-nuss.c +provides Ethernet functionality for applications on Linux. +It also handles both the control-path and data-path, namely: +Control => Configuration of the CPSW Peripheral +Data => Configuration of the DMA Channels to transmit/receive data + +The aforementioned configuration supports use-cases where all applications +which require Ethernet functionality are only running on Linux. + +However, there are use-cases where applications running on different +Operating Systems across multiple cores on the SoC require Ethernet +functionality. Such use-cases can be supported by implementing a +Client-Server model to share the data-path among Clients while the Server +owns the control-path. + +On TI's K3 SoCs (J721E, J7200 and J784S4 in particular), the Ethernet Switch +Firmware (EthFw) running on the MAIN R5F core acts as the Server and +configures the CPSWnG instance (CPSW5G on J7200 and CPSW9G on J721E, J784S4) +of the CPSW Ethernet Switch on the SoC. The Clients running on various cores +communicate with EthFw via RPMsg (Remote Processor Messaging) to request +resource allocation details during initialization, followed by requesting +EthFw to enable features supported by CPSW based on the features required +by the applications running on the respective cores. + +EthFw handles requests from the Clients and evaluates them before configuring +CPSW based on the request. Since no Client is actually in control of CPSW and +only requests EthFw for configuring CPSW, EthFw acts as the proxy for the +Clients. Thus, the Linux Client which interfaces with EthFw is named: +CPSW Proxy Client + +The data-path for the CPSW Proxy Client driver remains identical to the +"am65-cpsw-nuss.c" driver which happens to be DMA. It is only the control-path +that is different. + +Client-Server discovery occurs over the RPMsg-Bus. EthFw announces its +RPMsg Endpoint name over the RPMsg-Bus. The CPSW Proxy Client driver +registers itself with the Linux RPMsg framework to be probed for the same +Endpoint name. Following probe, the Linux Client driver begins communicating +with EthFw and queries details of the resources available for the Linux Client. + +Terminology +=========== + +Virtual Port + A Virtual Port refers to the Software View of an Ethernet MAC Port. + There are two types of Virtual Ports: + 1. Virtual MAC Only Port + 2. Virtual Switch Port + +Virtual MAC Only Port + A Virtual MAC only Port refers to a dedicated physical MAC Port for + a Client. This corresponds to MAC Mode of operation in Ethernet + Terminology. All traffic sent to or received from the Physical + MAC Port is that of the Client to which the Virtual MAC Only Port + has been allocated. + +Virtual Switch Port + A Virtual Switch Port refers to a group of physical MAC ports with + Switching enabled across them. This implies that any traffic sent + to the Port from a Client could potentially exit a Physical MAC + Port along with the traffic from other Clients. Similarly, the traffic + received on the Port by a Client could have potentially ingressed + on a Physical MAC Port along with the traffic meant for other Clients. + While the ALE (Address Lookup Engine) handles segregating the traffic, + and the CPSW Ethernet Switch places traffic on dedicated RX DMA Flows + meant for a single Client, it is worth noting that the bandwidths + of the Physical MAC Port are shared by Clients when traffic is sent to + or received from a Virtual Switch Port. + +Network Interface + The user-visible interface in Linux userspace exposed to applications + that serves as the entry/exit point for traffic to/from the Virtual + Ports. A single network interface (ethX) maps to either a Virtual + MAC Only Port or a Virtual Switch Port. + +C2S + RPMsg source is Client and destination is Server. + +S2C + RPMsg source is Server and destination is Client. + +Initialization Sequence +======================= + +The sequence of message exchanges between the Client driver and EthFw starting +from the driver probe and ending with the interfaces being brought up is as +follows: +1. C2S ETHFW_VIRT_PORT_INFO requesting details of Virtual Ports available + for the Linux Client. +2. S2C response containing requested details +3. C2S ETHFW_VIRT_PORT_ATTACH request for each Virtual Port allocated during + step 2. +4. S2C response containing details of the MTU Size, number of Tx DMA Channels + and RX DMA Flows for the specified Virtual Port. The *Features* associated + with the Virtual Port are also shared such as Multicast Filtering capability. +5. C2S ETHFW_ALLOC_RX request for each RX DMA Flow for a Virtual Port. +6. S2C response containing details of the RX PSI-L Thread ID, Flow base and + Flow offset. +7. C2S ETHFW_ALLOC_TX request for each TX DMA Channel for a Virtual Port. +8. S2C response containing details of the TX PSI-L Thread ID. +9. C2S ETHFW_ALLOC_MAC request for each Virtual Port. +10. S2C response containing the MAC Address corresponding to the Virtual Port. +11. C2S ETHFW_MAC_REGISTER request for each Virtual Port with the MAC Address + allocated in step 10. This is necessary to steer packets that ingress on + the MAC Ports of CPSW onto the RX DMA Flow for the Virtual Port in order + to allow the Client to receive the packets. +12. S2C response indicating status of request. +13. C2S ETHFW_IPv4_REGISTER request *only* for Virtual Switch Port interface. + The IPv4 address assigned to the "ethX" network interface in Linux + corresponding to the Virtual Switch Port interface has to be registered + with EthFw. This is due to the reason that all Broadcast requests including + ARP requests received by the MAC Ports corresponding to the Virtual Switch + Port are consumed solely be EthFw. Such traffic is sent to Clients by + alternate methods. Therefore EthFw needs to know the IPv4 address for the + "ethX" network interface in Linux in order to automatically respond to + ARP requests, thereby enabling Unicast communication. +14. S2C response indicating status of request. +15. C2S ETHFW_MCAST_FILTER_ADD request to register the Multicast Addresses + associated with the network interface corresponding to the Virtual Port + which has the Multicast Filtering capability. +16. S2C response indicating status of request. +17. C2S ETHFW_MCAST_FILTER_DEL request to deregister the Multicast Addresses + associated with the network interface corresponding to the Virtual Port + which has the Multicast Filtering capability. +18. S2C response indicating status of request. + +Shutdown Sequence +================= + +The sequence of message exchanges between the Client driver and EthFw on module +removal are as follows: +1. C2S ETHFW_MAC_DEREGISTER request to deregister the MAC Address for each + Virtual Port. +2. S2C response indicating status of request. +3. C2S ETHFW_MCAST_FILTER_DEL request to deregister the Multicast Addresses + associated with the network interface corresponding to the Virtual Port + which has the Multicast Filtering capability. +4. S2C response indicating status of request. +5. C2S ETHFW_FREE_MAC request to release the MAC Address allocated to each + Virtual Port. +6. S2C response indicating status of request. +7. C2S ETHFW_FREE_TX request to release the TX DMA Channel for each TX Channel + for every Virtual Port. +8. S2C response indicating status of request. +9. C2S ETHFW_FREE_RX request to release the RX DMA Flow for each RX Channel + for every Virtual Port. +10. S2C response indicating status of request. +11. C2S ETHFW_VIRT_PORT_DETACH request to release each Virtual Port. +12. S2C response indicating status of request. + +Features Supported +================== + +The set of features supported in addition to providing basic Ethernet +Functionality are: +1. Multicast Filtering +2. Determining Link Status of the network interface corresponding to the + Virtual MAC Only port via ethtool. +3. Interrupt Pacing/Coalescing From patchwork Sat May 18 12:42:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667608 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 B724245014; Sat, 18 May 2024 12:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036198; cv=none; b=FTVY0nm2sbYarI8MlS19iOYYMOSxV270Zq1YrRN+Te2R8wTwbpiglXJMtjEt1u83PO5PcaPHhMgKkshVl/uHT9/TljYi+fTJFstcdsvvCZJGAF9tYtbftGjs7NOgV7OddZf59FEMP2JlF6QWhGE4WtIkDBCVgu5smzMgnlxsV5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036198; c=relaxed/simple; bh=DEiNmpaVe3g+0xYtypFrg2vqcEb12rAGEvLjdXjUnjw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ljto0o4ovEUudQFRa8Bwr9lPni5G5Og1P8lpHzrPIbYcqdSVt74MzQqLONM7IWAWaT35mLApdv5u+ACMkSq437/jX61U3rQjc+s+kO0pSYygYyu2FJ4tabRzVsvk/A/BbZO9jw2I5BSKBz0IcritlvIw7C7M+b+coCns6KeHIE4= 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=jm4ei7Tz; arc=none smtp.client-ip=198.47.23.248 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="jm4ei7Tz" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgmw8110041; Sat, 18 May 2024 07:42:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036168; bh=UovvYxLe8eCCdaaAFq+U+PihUBOQSK8yJAiea02CXrg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=jm4ei7Tz9gUDGDH8692Bz759toPMOy4crOZBXbe0SB6Qd29HNEIu5uYRtcHGBm3Db FxLHIPMTzKgy38dYE2qPeBmoGnPbvpkMwJCbdo+83fLQmgJ6R5rbnVkLxN6H1P6zIR 5TMwF9FbzsKqAnMC3oLR4nZ8iQaBDxwElESiG6+M= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICgmRt017010 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:42:48 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) 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.23; Sat, 18 May 2024 07:42:48 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:42:48 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9I041511; Sat, 18 May 2024 07:42:44 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 02/28] net: ethernet: ti: add RPMsg structures for Ethernet Switch Firmware Date: Sat, 18 May 2024 18:12:08 +0530 Message-ID: <20240518124234.2671651-3-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The Ethernet Switch Firmware (EthFw) running on the remote MAIN R5 core is capable of configuring the CPSWnG instance of TI's CPSW Ethernet Switch on various TI SoCs such as J721E, J7200 and J784S4. EthFw is in complete control of CPSWnG and acts as a server which allocates and provides the resources to clients on different cores. All communication between EthFw and the clients occurs via RPMsg. Define the message structures used to communicate with EthFw. This shall enable the Linux Client to avail the services provided by EthFw. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/ethfw_abi.h | 370 ++++++++++++++++++++++++++++ 1 file changed, 370 insertions(+) create mode 100644 drivers/net/ethernet/ti/ethfw_abi.h diff --git a/drivers/net/ethernet/ti/ethfw_abi.h b/drivers/net/ethernet/ti/ethfw_abi.h new file mode 100644 index 000000000000..a857e920445b --- /dev/null +++ b/drivers/net/ethernet/ti/ethfw_abi.h @@ -0,0 +1,370 @@ +/* SPDX-License-Identifier: GPL-2.0-only or MIT */ +/* Texas Instruments Ethernet Switch Firmware (EthFw) ABIs + * + * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/ + * + */ + +#ifndef __ETHFW_ABI_H_ +#define __ETHFW_ABI_H_ + +/* Name of the RPMsg Endpoint announced by EthFw on the RPMsg-Bus */ +#define ETHFW_SERVICE_EP_NAME "ti.ethfw.ethdevice" + +/* Response status set by EthFw on the Success of a Request */ +#define ETHFW_RES_OK (0) + +/* Response status set by EthFw notifying the Client to retry a Request */ +#define ETHFW_RES_TRY_AGAIN (-1) + +/* Default VLAN ID for a Virtual Port */ +#define ETHFW_DFLT_VLAN 0xFFFF + +/* EthFw TX Checksum Offload Capability */ +#define ETHFW_TX_CSUM_OFFLOAD BIT(0) + +/* EthFw Multicast Filtering Capability */ +#define ETHFW_MCAST_FILTERING BIT(3) + +/* Token corresponding to the Linux CPSW Proxy Client assigned by EthFw */ +#define ETHFW_LINUX_CLIENT_TOKEN 3 + +/* Default token used by Virtual Port to communicate with EthFw */ +#define ETHFW_TOKEN_NONE 0xFFFFFFFF + +/* MAC Address length in octets */ +#define ETHFW_MACADDRLEN 6 + +/* IPV4 Address length in octets */ +#define ETHFW_IPV4ADDRLEN 4 + +/* Types of request messages sent to EthFw from CPSW Proxy Client */ +enum request_msg_type { + /* Request details of Virtual Ports allocated to the Client. + * Two types of Virtual Ports exist: + * 1. MAC Only Port: + * The Physical MAC Port corresponding to this type of Virtual + * Port does not belong to the group of MAC Ports which Switch + * traffic among themselves. The Physical MAC Port is dedicated + * solely to the Client which has been allocated this type of + * Virtual Port. + * + * 2. Switch Port: + * The Physical MAC Port corresponding to this type of Virtual + * Port belongs to the group of MAC Ports which Switch traffic + * among themselves. The Physical MAC Port is shared with other + * Clients in terms of the traffic that is sent out of or received + * on this port. + * + * EthFw responds to this request by providing a bitmask of the + * Virtual Port IDs for each type of Virtual Port allocated to + * the Client. + */ + ETHFW_VIRT_PORT_INFO, + + /* Request usage of a Virtual Port that has been allocated to the + * Client. + * + * EthFw responds with details of the supported MTU size, the number + * of TX DMA Channels and the number of RX DMA Flows for the specified + * Virtual Port. + */ + ETHFW_VIRT_PORT_ATTACH, + + /* Request disuse of a Virtual Port that was in use prior to the + * generation of this request. + */ + ETHFW_VIRT_PORT_DETACH, + + /* Request for allocation of a TX DMA Channel for a Virtual Port. + * Client can request as many TX DMA Channels as have been allocated + * by EthFw for the specified Virtual Port. + * + * EthFw responds with the TX PSI-L Thread ID corresponding to + * the TX DMA Channel for the Virtual Port to transmit traffic + * to CPSW. + */ + ETHFW_ALLOC_TX, + + /* Request for allocation of an RX DMA Flow for a Virtual Port. + * Client can request as many RX DMA Flows as have been allocated + * by EthFw for the specified Virtual Port. + * + * EthFw responds with the RX PSI-L Thread ID, the base of the RX + * Flow index and the offset from the base of the allocated RX Flow + * index. The RX Flow/Channel is used to receive traffic from CPSW. + */ + ETHFW_ALLOC_RX, + + /* Request for allocation of the MAC Address for a Virtual Port. + * + * EthFw responds with the MAC Address corresponding to the + * specified Virtual Port. + */ + ETHFW_ALLOC_MAC, + + /* Request for release of a TX DMA Channel that had been allocated + * to the specified Virtual Port. + */ + ETHFW_FREE_TX, + + /* Request for release of an RX DMA Flow that had been allocated to + * the specified Virtual Port. + */ + ETHFW_FREE_RX, + + /* Request for release of the MAC Address that had been allocated to + * the specified Virtual Port. + */ + ETHFW_FREE_MAC, + + /* Request for usage of the specified MAC Address for the traffic + * sent or received on the Virtual Port for which the MAC Address + * has been allocated. + */ + ETHFW_MAC_REGISTER, + + /* Request for disuse of the specified MAC Address for the traffic + * sent or received on the Virtual Port for which the MAC Address + * had been allocated. + */ + ETHFW_MAC_DEREGISTER, + + /* Request for setting the default RX DMA Flow for a Virtual Port. */ + ETHFW_SET_DEFAULT_RX_FLOW, + + /* Request for deleting the default RX DMA Flow for a Virtual Port. */ + ETHFW_DEL_DEFAULT_RX_FLOW, + + /* Request for registering the IPv4 Address of the Network Interface + * in Linux corresponding to the specified Virtual Port. + */ + ETHFW_IPv4_REGISTER, + + /* Request for deregistering the IPv4 Address of the Network Interface + * in Linux corresponding to the specified Virtual Port that had been + * registered prior to this request. + */ + ETHFW_IPv4_DEREGISTER, + + /* Request for joining a Multicast Address group */ + ETHFW_MCAST_FILTER_ADD, + + /* Request for leaving a Multicast Address group */ + ETHFW_MCAST_FILTER_DEL, + + /* Request to get link status */ + ETHFW_VIRT_PORT_LINK_STATUS, +}; + +enum notify_msg_type { + ETHFW_NOTIFYCLIENT_FWINFO, + ETHFW_NOTIFYCLIENT_HWPUSH, + ETHFW_NOTIFYCLIENT_HWERROR, + ETHFW_NOTIFYCLIENT_RECOVERED, + ETHFW_NOTIFYCLIENT_CUSTOM, + ETHFW_NOTIFYCLIENT_LAST, +}; + +enum ethfw_status { + ETHFW_INIT, + ETHFW_RECOVERY, + ETHFW_DEINIT, +}; + +enum message_type { + ETHFW_MSG_REQUEST, + ETHFW_MSG_NOTIFY, + ETHFW_MSG_RESPONSE, +}; + +struct message_header { + u32 token; + u32 client_id; + u32 msg_type; +} __packed; + +struct message { + struct message_header msg_hdr; + u32 message_data[120]; +} __packed; + +struct request_message_header { + struct message_header msg_hdr; + u32 request_type; + u32 request_id; +} __packed; + +struct response_message_header { + struct message_header msg_hdr; + u32 response_type; /* Same as request_type */ + u32 response_id; + int response_status; +} __packed; + +struct notify_message_header { + struct message_header msg_hdr; + u32 notify_type; +} __packed; + +struct common_response_message { + struct response_message_header response_msg_hdr; +} __packed; + +struct common_request_message { + struct request_message_header request_msg_hdr; +} __packed; + +struct common_notify_message { + struct notify_message_header notify_msg_hdr; +} __packed; + +struct virt_port_info_response { + struct response_message_header response_msg_hdr; + /* Port mask denoting absolute virtual switch ports allocated */ + u32 switch_port_mask; + /* Port mask denoting absolute virtual MAC ports allocated */ + u32 mac_port_mask; +} __packed; + +struct attach_request { + struct request_message_header request_msg_hdr; + /* Virtual port which needs core attach */ + u32 virt_port; +} __packed; + +struct attach_response { + struct response_message_header response_msg_hdr; + /* MTU of RX packet */ + u32 rx_mtu; + /* MTU of TX packet */ + u32 tx_mtu; + /* Feature bitmask */ + u32 features; + /* Number of TX DMA Channels available for the virtual port */ + u32 num_tx_chan; + /* Number of RX DMA Flows available for the virtual port */ + u32 num_rx_flow; +} __packed; + +struct rx_flow_alloc_request { + struct request_message_header request_msg_hdr; + /* Relative index of RX flow among available num_rx_flow flows */ + u32 rx_flow_idx; +} __packed; + +struct rx_flow_alloc_response { + struct response_message_header response_msg_hdr; + /* Allocated RX flow index base */ + u32 rx_flow_idx_base; + /* Allocated flow index offset */ + u32 rx_flow_idx_offset; + /* RX PSIL Peer source thread id */ + u32 rx_psil_src_id; +} __packed; + +struct tx_thread_alloc_request { + struct request_message_header request_msg_hdr; + /* Relative index of TX channel among available num_tx_chan channels */ + u32 tx_chan_idx; +} __packed; + +struct tx_thread_alloc_response { + struct response_message_header response_msg_hdr; + /* TX PSIL peer destination thread id which should be paired with the TX UDMA channel */ + u32 tx_psil_dest_id; +} __packed; + +struct mac_alloc_response { + struct response_message_header response_msg_hdr; + /* Allocated MAC address */ + u8 mac_addr[ETHFW_MACADDRLEN]; +} __packed; + +struct rx_flow_release_request { + struct request_message_header request_msg_hdr; + /* RX flow index base */ + u32 rx_flow_idx_base; + /* RX flow index offset */ + u32 rx_flow_idx_offset; +} __packed; + +struct tx_thread_release_request { + struct request_message_header request_msg_hdr; + /* TX PSIL Peer destination thread id to be freed */ + u32 tx_psil_dest_id; +} __packed; + +struct mac_release_request { + struct request_message_header request_msg_hdr; + /* MAC address to be freed */ + u8 mac_addr[ETHFW_MACADDRLEN]; +} __packed; + +struct mac_register_deregister_request { + struct request_message_header request_msg_hdr; + /* MAC address which needs to be registered/deregistered */ + u8 mac_addr[ETHFW_MACADDRLEN]; + /* RX flow index Base */ + u32 rx_flow_idx_base; + /* RX flow index offset */ + u32 rx_flow_idx_offset; +} __packed; + +struct ipv4_register_request { + struct request_message_header request_msg_hdr; + /* IPv4 Address */ + u8 ipv4_addr[ETHFW_IPV4ADDRLEN]; + /* MAC address associated with the IP address which should be added to + * the ARP table + */ + u8 mac_addr[ETHFW_MACADDRLEN]; +} __packed; + +struct ipv4_deregister_request { + struct request_message_header request_msg_hdr; + /* IPv4 Address */ + u8 ipv4_addr[ETHFW_IPV4ADDRLEN]; +} __packed; + +struct default_rx_flow_register_request { + struct request_message_header request_msg_hdr; + /* RX flow index Base */ + u32 rx_flow_idx_base; + /* RX flow index offset */ + u32 rx_flow_idx_offset; +} __packed; + +struct port_link_status_response { + struct response_message_header response_msg_hdr; + /* Link status of the port */ + bool link_up; + /* Link speed */ + u32 speed; + /* Duplex mode */ + u32 duplex; +} __packed; + +struct add_multicast_request { + struct request_message_header request_msg_hdr; + /* Multicast MAC address to be added */ + u8 mac_addr[ETHFW_MACADDRLEN]; + /* VLAN id */ + u16 vlan_id; + /* RX flow index from which the MAC_address association will be added. + * It's applicable only for _exclusive multicast traffic_ + */ + u32 rx_flow_idx_base; + /* RX flow index offset */ + u32 rx_flow_idx_offset; +} __packed; + +struct del_multicast_request { + struct request_message_header request_msg_hdr; + /* Multicast MAC address to be added */ + u8 mac_addr[ETHFW_MACADDRLEN]; + /* VLAN id */ + u16 vlan_id; +} __packed; + +#endif /* __ETHFW_ABI_H_ */ From patchwork Sat May 18 12:42:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667607 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (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 A534312E63; Sat, 18 May 2024 12:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036187; cv=none; b=UX+fGi7MbgH8QKwAirgFRHEXdBIWhokUdiRH8JgwqisxKPWV3UAJ29baaVN32U3Q9eTajhntWM6VL5Gp7jUdzpCuv1J1pVfXEWGE9ElFClaRsWdPjNM3RgruqYjbGuOiZZs4ERNAYY4i9tzbSk8CygsLdICNdP0hRM5UD55gwKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036187; c=relaxed/simple; bh=a1RrRoPKgUMeAZVvSxfDJQCbTiG+xNKv0jTAwceXp/s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XpL61eGgVsJtq0Yn+eWgdAFVJ3sWJClLQCXCMlEM1XUmAdG6PFZFBb1aYymvxMRPeo5U/c5IvV5dYiz8c+ffN1+dB/VWNb1Gj/xhMHkFPOPzWIWim9RQq5cNI9IDr48+09498NNb8oRQBvUkIrBP6y14p7oWSNuPaL/tmx2RNWw= 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=NVN7ZSZy; arc=none smtp.client-ip=198.47.23.249 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="NVN7ZSZy" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgr45017243; Sat, 18 May 2024 07:42:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036173; bh=4YVnM9yhpbr1F1sysYDYzoQYJXO4G2Ig3wn60U5nDX0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=NVN7ZSZy1L/XG9ILEj3nf/hfI74IbVwXDPwM9ik5J8/gNopf1fGo4RRf0w3Gq+k0B Gk3Olp3Mc6E8gBtHkwb4z328znEIERSWLHnp5SCdRBMvf14+ftSOUO1ukcblivK3Oj hDFOowVdsvv2RU+yBnMsBlOm/1PPr9t3pwHok9w0= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICgrow003903 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:42:53 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:42:53 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:42:53 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9J041511; Sat, 18 May 2024 07:42:49 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 03/28] net: ethernet: ti: introduce the CPSW Proxy Client Date: Sat, 18 May 2024 18:12:09 +0530 Message-ID: <20240518124234.2671651-4-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The CPSW Proxy Client driver in Linux communicates with Ethernet Switch Firmware (EthFw) running on a remote core via RPMsg. EthFw announces its RPMsg Endpoint over the RPMsg-Bus notifying its presence to all Clients. Register the CPSW Proxy Client driver with the RPMsg framework. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/Kconfig | 14 +++++ drivers/net/ethernet/ti/Makefile | 3 + drivers/net/ethernet/ti/cpsw-proxy-client.c | 70 +++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 drivers/net/ethernet/ti/cpsw-proxy-client.c diff --git a/drivers/net/ethernet/ti/Kconfig b/drivers/net/ethernet/ti/Kconfig index 1729eb0e0b41..ffbfd625625d 100644 --- a/drivers/net/ethernet/ti/Kconfig +++ b/drivers/net/ethernet/ti/Kconfig @@ -79,6 +79,20 @@ config TI_CPSW_SWITCHDEV To compile this driver as a module, choose M here: the module will be called cpsw_new. +config TI_CPSW_PROXY_CLIENT + tristate "TI CPSW Proxy Client" + depends on ARCH_K3 && OF && TI_K3_UDMA_GLUE_LAYER + help + This driver supports Ethernet functionality for CPSWnG + Ethernet Subsystem which is configured by Ethernet Switch + Firmware (EthFw). + + The Ethernet Switch Firmware acts as a proxy to the Linux + Client driver by performing all the necessary configuration + of the CPSW Peripheral while enabling network data transfer + to/from the Linux Client to CPSW over the allocated TX DMA + Channels and RX DMA Flows. + config TI_CPTS tristate "TI Common Platform Time Sync (CPTS) Support" depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || COMPILE_TEST diff --git a/drivers/net/ethernet/ti/Makefile b/drivers/net/ethernet/ti/Makefile index 6e086b4c0384..229b828f099e 100644 --- a/drivers/net/ethernet/ti/Makefile +++ b/drivers/net/ethernet/ti/Makefile @@ -7,6 +7,9 @@ obj-$(CONFIG_TI_CPSW) += cpsw-common.o obj-$(CONFIG_TI_DAVINCI_EMAC) += cpsw-common.o obj-$(CONFIG_TI_CPSW_SWITCHDEV) += cpsw-common.o +obj-$(CONFIG_TI_CPSW_PROXY_CLIENT) += ti-cpsw-proxy-client.o +ti-cpsw-proxy-client-y := cpsw-proxy-client.o + obj-$(CONFIG_TLAN) += tlan.o obj-$(CONFIG_TI_DAVINCI_EMAC) += ti_davinci_emac.o ti_davinci_emac-y := davinci_emac.o davinci_cpdma.o diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c new file mode 100644 index 000000000000..91d3338b3788 --- /dev/null +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-only or MIT +/* Texas Instruments CPSW Proxy Client Driver + * + * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/ + * + */ + +#include +#include +#include + +#include "ethfw_abi.h" + +struct cpsw_proxy_priv { + struct rpmsg_device *rpdev; + struct device *dev; +}; + +static int cpsw_proxy_client_cb(struct rpmsg_device *rpdev, void *data, + int len, void *priv, u32 src) +{ + struct device *dev = &rpdev->dev; + + dev_dbg(dev, "callback invoked\n"); + + return 0; +} + +static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) +{ + struct cpsw_proxy_priv *proxy_priv; + + proxy_priv = devm_kzalloc(&rpdev->dev, sizeof(struct cpsw_proxy_priv), GFP_KERNEL); + if (!proxy_priv) + return -ENOMEM; + + proxy_priv->rpdev = rpdev; + proxy_priv->dev = &rpdev->dev; + dev_dbg(proxy_priv->dev, "driver probed\n"); + + return 0; +} + +static void cpsw_proxy_client_remove(struct rpmsg_device *rpdev) +{ + struct device *dev = &rpdev->dev; + + dev_dbg(dev, "driver removed\n"); +} + +static struct rpmsg_device_id cpsw_proxy_client_id_table[] = { + { + .name = ETHFW_SERVICE_EP_NAME, + }, + {}, +}; +MODULE_DEVICE_TABLE(rpmsg, cpsw_proxy_client_id_table); + +static struct rpmsg_driver cpsw_proxy_client_driver = { + .drv.name = KBUILD_MODNAME, + .id_table = cpsw_proxy_client_id_table, + .probe = cpsw_proxy_client_probe, + .callback = cpsw_proxy_client_cb, + .remove = cpsw_proxy_client_remove, +}; +module_rpmsg_driver(cpsw_proxy_client_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("CPSW Proxy Client Driver"); +MODULE_AUTHOR("Siddharth Vadapalli "); From patchwork Sat May 18 12:42:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667612 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 A880055769; Sat, 18 May 2024 12:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036205; cv=none; b=YdQrJmj38KZNBPmFFLrvs2imM3Z/Z7yoeBd6IY3sLuyIp7zHv5dPRJWqwip5GXlj8KocmlgA0hsKOro1H9VAH+yV1mb628EBHV4oYqEqmvcCxV8UFJJrtxqdeLOqdMjSMkgmploHX/G8GUwBSAM8nI2sONuew8m9FphqGrlWfE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036205; c=relaxed/simple; bh=WakF8jtak+0vhjK2bTssbvGciBkwho7oY9NxlB6Dk4I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PmayRKrJ2ZpOgbGdeeEqzOK10Q9J+U9RLAk2x/QSI0bXdZ95tx7aY1qdMExN4ghGoAh1EG5anGeGcwKnRwaJpqlkPuE9iNNV6BdcOXZDgh1LANcXxPBBBvq/HDvtP0O7JLJ5SioeCZM/NRopUuNTbfnNGM7IOFWbPGt9E2V3orI= 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=BuVbKCln; arc=none smtp.client-ip=198.47.19.142 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="BuVbKCln" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgwI7054945; Sat, 18 May 2024 07:42:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036178; bh=7W1O2S0BwQFiS8C4UlqWrhgt+Eb2BDTC/PMCiQH9kFM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=BuVbKClnYEFrQc+h+7tH2watQFyB6h9lJayLTQ2YRplfIRgnfSzPFHxj/7caPwJ0H DT/LkpCGiEwfIaET38ypLFiPGLvHcIM/AV8Bxuj//OEAHjPfreilxLxrFL4Pb3/V2Z CJ/4VNRcdYWcNPDCKUMBqN5yeba1XF7M4Hfl4Jvg= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICgwvZ129183 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:42:58 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) 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.23; Sat, 18 May 2024 07:42:57 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:42:57 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9K041511; Sat, 18 May 2024 07:42:53 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 04/28] net: ethernet: ti: cpsw-proxy-client: add support for creating requests Date: Sat, 18 May 2024 18:12:10 +0530 Message-ID: <20240518124234.2671651-5-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The CPSW Proxy Client driver exchanges various types of requests with EthFw to achieve desired functionality. Add a function to create request messages that can be sent to EthFw over RPMsg-Bus, given the type of the request message and additional parameters required to form the message. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 140 ++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 91d3338b3788..3533f4ce1e3f 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -5,12 +5,29 @@ * */ +#include #include #include #include #include "ethfw_abi.h" +struct cpsw_proxy_req_params { + struct message req_msg; /* Request message to be filled */ + u32 token; + u32 client_id; + u32 request_id; + u32 request_type; + u32 rx_tx_idx; /* RX or TX Channel index */ + u32 rx_flow_base; /* RX DMA Flow base */ + u32 rx_flow_offset; /* RX DMA Flow offset */ + u32 tx_thread_id; /* PSI-L Thread ID of TX Channel */ + u32 port_id; /* Virtual Port ID */ + u16 vlan_id; + u8 mac_addr[ETH_ALEN]; + u8 ipv4_addr[ETHFW_IPV4ADDRLEN]; +}; + struct cpsw_proxy_priv { struct rpmsg_device *rpdev; struct device *dev; @@ -26,6 +43,129 @@ static int cpsw_proxy_client_cb(struct rpmsg_device *rpdev, void *data, return 0; } +static int create_request_message(struct cpsw_proxy_req_params *req_params) +{ + struct mac_register_deregister_request *mac_reg_dereg_req; + struct ipv4_deregister_request *ipv4_dereg_req; + struct common_request_message *common_req_msg; + struct tx_thread_release_request *tx_free_req; + struct tx_thread_alloc_request *tx_alloc_req; + struct add_multicast_request *mcast_add_req; + struct del_multicast_request *mcast_del_req; + struct rx_flow_release_request *rx_free_req; + struct ipv4_register_request *ipv4_reg_req; + struct request_message_header *req_msg_hdr; + struct rx_flow_alloc_request *rx_alloc_req; + struct message *msg = &req_params->req_msg; + struct mac_release_request *mac_free_req; + struct attach_request *attach_req; + u32 req_type; + + /* Set message header fields */ + msg->msg_hdr.token = req_params->token; + msg->msg_hdr.client_id = req_params->client_id; + msg->msg_hdr.msg_type = ETHFW_MSG_REQUEST; + + req_type = req_params->request_type; + + switch (req_type) { + case ETHFW_ALLOC_RX: + rx_alloc_req = (struct rx_flow_alloc_request *)msg; + req_msg_hdr = &rx_alloc_req->request_msg_hdr; + rx_alloc_req->rx_flow_idx = req_params->rx_tx_idx; + break; + + case ETHFW_ALLOC_TX: + tx_alloc_req = (struct tx_thread_alloc_request *)msg; + req_msg_hdr = &tx_alloc_req->request_msg_hdr; + tx_alloc_req->tx_chan_idx = req_params->rx_tx_idx; + break; + + case ETHFW_VIRT_PORT_ATTACH: + attach_req = (struct attach_request *)msg; + req_msg_hdr = &attach_req->request_msg_hdr; + attach_req->virt_port = req_params->port_id; + break; + + case ETHFW_FREE_MAC: + mac_free_req = (struct mac_release_request *)msg; + req_msg_hdr = &mac_free_req->request_msg_hdr; + ether_addr_copy(mac_free_req->mac_addr, req_params->mac_addr); + break; + + case ETHFW_FREE_RX: + rx_free_req = (struct rx_flow_release_request *)msg; + req_msg_hdr = &rx_free_req->request_msg_hdr; + rx_free_req->rx_flow_idx_base = req_params->rx_flow_base; + rx_free_req->rx_flow_idx_offset = req_params->rx_flow_offset; + break; + + case ETHFW_FREE_TX: + tx_free_req = (struct tx_thread_release_request *)msg; + req_msg_hdr = &tx_free_req->request_msg_hdr; + tx_free_req->tx_psil_dest_id = req_params->tx_thread_id; + break; + + case ETHFW_IPv4_DEREGISTER: + ipv4_dereg_req = (struct ipv4_deregister_request *)msg; + req_msg_hdr = &ipv4_dereg_req->request_msg_hdr; + memcpy(&ipv4_dereg_req->ipv4_addr, req_params->ipv4_addr, + ETHFW_IPV4ADDRLEN); + break; + + case ETHFW_IPv4_REGISTER: + ipv4_reg_req = (struct ipv4_register_request *)msg; + req_msg_hdr = &ipv4_reg_req->request_msg_hdr; + memcpy(&ipv4_reg_req->ipv4_addr, req_params->ipv4_addr, + ETHFW_IPV4ADDRLEN); + ether_addr_copy(ipv4_reg_req->mac_addr, + req_params->mac_addr); + break; + + case ETHFW_MAC_DEREGISTER: + case ETHFW_MAC_REGISTER: + mac_reg_dereg_req = (struct mac_register_deregister_request *)msg; + req_msg_hdr = &mac_reg_dereg_req->request_msg_hdr; + ether_addr_copy(mac_reg_dereg_req->mac_addr, + req_params->mac_addr); + mac_reg_dereg_req->rx_flow_idx_base = req_params->rx_flow_base; + mac_reg_dereg_req->rx_flow_idx_offset = req_params->rx_flow_offset; + break; + + case ETHFW_MCAST_FILTER_ADD: + mcast_add_req = (struct add_multicast_request *)msg; + req_msg_hdr = &mcast_add_req->request_msg_hdr; + ether_addr_copy(mcast_add_req->mac_addr, req_params->mac_addr); + mcast_add_req->vlan_id = req_params->vlan_id; + mcast_add_req->rx_flow_idx_base = req_params->rx_flow_base; + mcast_add_req->rx_flow_idx_offset = req_params->rx_flow_offset; + break; + + case ETHFW_MCAST_FILTER_DEL: + mcast_del_req = (struct del_multicast_request *)msg; + req_msg_hdr = &mcast_del_req->request_msg_hdr; + ether_addr_copy(mcast_del_req->mac_addr, req_params->mac_addr); + mcast_del_req->vlan_id = req_params->vlan_id; + break; + + case ETHFW_ALLOC_MAC: + case ETHFW_VIRT_PORT_DETACH: + case ETHFW_VIRT_PORT_INFO: + common_req_msg = (struct common_request_message *)msg; + req_msg_hdr = &common_req_msg->request_msg_hdr; + break; + + default: + return -EOPNOTSUPP; + } + + /* Set request message header fields */ + req_msg_hdr->request_id = req_params->request_id; + req_msg_hdr->request_type = req_params->request_type; + + return 0; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667611 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 AC2F945BE3; Sat, 18 May 2024 12:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036202; cv=none; b=LXTaMajYsofvfKriuiHXxPeT0ITeE4wmnB+8RjrNO+qMtGdU9qmwG8cVzabi4JTuZudE9YMJB3XpZq3uzczWXbU0jz9vhvcRry3zpsHWX402RDRWGQMK/jKtNi3q/jUwUpU3pENBBqCRhgpAjmrP1eeIcX4yJkkRwOGd6DSGNAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036202; c=relaxed/simple; bh=4gljx4eIYU2HWXd7cv80y4hDjxq0FtnAm5MHqUBitOE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FDBcuxso24UPHx17+KHQgiD+pQs/guRYqJcweBEDOP4V64arq/N4f//57xB+G9+CDSqXtXL5hIrQVVwPwaAc1Kj8XfYxuvIIen+CvBxHYc2DzGZwNXK4fwhODV/C5wWS4cLjlBctwZm7TLc0RY/PfgGf/jEKphiy29wfFSvOBFg= 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=tY6V2iu/; arc=none smtp.client-ip=198.47.23.248 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="tY6V2iu/" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICh24Z110064; Sat, 18 May 2024 07:43:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036182; bh=pwsEoFlTYu9+D4B/5o/60VHvS9uGtvdc6Hi7yXMznp8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tY6V2iu/EDwPj0nVEsIeZdPPd6MvjjVGGJsg7KSLZ9sXL5f37GVOCzmoJ92Ckk/1z qY3bvG+qZ90Zc1SHF5eILN13EIeekOmy+p5NdDm7OgtBMh8SyXVAMcuw6eFght5Mx4 EtVbNtVyfVqsg6XXkkAKZ7Uuwwueq7NnBCrPSM8g= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICh26n129305 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:02 -0500 Received: from DFLE107.ent.ti.com (10.64.6.28) 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.23; Sat, 18 May 2024 07:43:02 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:02 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9L041511; Sat, 18 May 2024 07:42:58 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 05/28] net: ethernet: ti: cpsw-proxy-client: enable message exchange with EthFw Date: Sat, 18 May 2024 18:12:11 +0530 Message-ID: <20240518124234.2671651-6-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add a new function which sends RPMsg requests to EthFw and shares the response for the request. The RPMsg callback function copies the response it receives from EthFw to the driver's private member, thereby allowing the response to be shared with the newly added function which sends the request. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 112 +++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 3533f4ce1e3f..70b8cfe67921 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -12,6 +12,8 @@ #include "ethfw_abi.h" +#define ETHFW_RESPONSE_TIMEOUT_MS 500 + struct cpsw_proxy_req_params { struct message req_msg; /* Request message to be filled */ u32 token; @@ -31,16 +33,50 @@ struct cpsw_proxy_req_params { struct cpsw_proxy_priv { struct rpmsg_device *rpdev; struct device *dev; + struct cpsw_proxy_req_params req_params; + struct message resp_msg; + struct completion wait_for_response; + int resp_msg_len; }; static int cpsw_proxy_client_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src) { + struct cpsw_proxy_priv *proxy_priv = dev_get_drvdata(&rpdev->dev); + struct response_message_header *resp_msg_hdr; + struct message *msg = (struct message *)data; + struct cpsw_proxy_req_params *req_params; struct device *dev = &rpdev->dev; + u32 msg_type, resp_id; dev_dbg(dev, "callback invoked\n"); + msg_type = msg->msg_hdr.msg_type; + switch (msg_type) { + case ETHFW_MSG_RESPONSE: + resp_msg_hdr = (struct response_message_header *)msg; + resp_id = resp_msg_hdr->response_id; + req_params = &proxy_priv->req_params; - return 0; + if (unlikely(resp_id == req_params->request_id - 1)) { + dev_info(dev, "ignoring late response for request: %u\n", + resp_id); + return 0; + } else if (unlikely(resp_id != req_params->request_id)) { + dev_err(dev, "expected response id: %u but received %u\n", + req_params->request_id, resp_id); + return -EINVAL; + } + + /* Share response */ + memcpy(&proxy_priv->resp_msg, msg, len); + proxy_priv->resp_msg_len = len; + complete(&proxy_priv->wait_for_response); + return 0; + + default: + dev_err(dev, "unsupported message received from EthFw\n"); + return -EOPNOTSUPP; + } } static int create_request_message(struct cpsw_proxy_req_params *req_params) @@ -166,6 +202,79 @@ static int create_request_message(struct cpsw_proxy_req_params *req_params) return 0; } +/* Send a request to EthFw and receive the response for request. + * Since the response is received by the callback function, it is + * copied to "resp_msg" member of "struct cpsw_proxy_priv" to + * allow sharing it with the following function. + * + * The request parameters within proxy_priv are expected to be set + * correctly by the caller. The caller is also expected to acquire + * lock before invoking this function, since requests and responses + * to/from EthFw are serialized. + */ +static int send_request_get_response(struct cpsw_proxy_priv *proxy_priv, + struct message *response) +{ + struct cpsw_proxy_req_params *req_params = &proxy_priv->req_params; + struct message *send_msg = &req_params->req_msg; + struct rpmsg_device *rpdev = proxy_priv->rpdev; + struct response_message_header *resp_msg_hdr; + struct device *dev = proxy_priv->dev; + unsigned long timeout; + u32 resp_status; + bool retry = 0; + int ret; + + ret = create_request_message(req_params); + if (ret) { + dev_err(dev, "failed to create request %d\n", ret); + goto err; + } + + /* Send request and wait for callback function to acknowledge + * receiving the response. + */ + reinit_completion(&proxy_priv->wait_for_response); + ret = rpmsg_send(rpdev->ept, (void *)(send_msg), + sizeof(struct message)); + if (ret) { + dev_err(dev, "failed to send rpmsg\n"); + goto err; + } + timeout = msecs_to_jiffies(ETHFW_RESPONSE_TIMEOUT_MS); + ret = wait_for_completion_timeout(&proxy_priv->wait_for_response, + timeout); + if (!ret) { + dev_err(dev, "response timedout\n"); + ret = -ETIMEDOUT; + goto err; + } + ret = 0; + + /* Store response shared by callback function */ + memcpy(response, &proxy_priv->resp_msg, proxy_priv->resp_msg_len); + resp_msg_hdr = (struct response_message_header *)response; + resp_status = resp_msg_hdr->response_status; + + if (unlikely(resp_status != ETHFW_RES_OK)) { + if (resp_status == ETHFW_RES_TRY_AGAIN) { + dev_info(dev, "resending request\n"); + ret = -EAGAIN; + retry = 1; + } else { + dev_err(dev, "bad response status: %d\n", resp_status); + ret = -EIO; + } + } + +err: + req_params->request_id++; + if (retry) + ret = send_request_get_response(proxy_priv, response); + + return ret; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; @@ -176,6 +285,7 @@ static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) proxy_priv->rpdev = rpdev; proxy_priv->dev = &rpdev->dev; + dev_set_drvdata(proxy_priv->dev, proxy_priv); dev_dbg(proxy_priv->dev, "driver probed\n"); return 0; From patchwork Sat May 18 12:42:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667610 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 461FA3BBE3; Sat, 18 May 2024 12:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036200; cv=none; b=sZwWM+96fcRqFxm1w2GFnv2y7jE4EUzk834mnEBmMeJnTbYaGRuwdbuWXB5OoGTLWsZf4eL0uU+6C08zRpbSKsOXTpLrtn3zj97XemGyJJaA/5gd6HMm+o384KwODRDLYyFjTeiW4Hq9P3EPO2+IDldDJPR4AAkKW2sBjUS2Boc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036200; c=relaxed/simple; bh=BX65I4hCBY8znLybw93RUD7npF1xBbqeKvfk+x/ftRQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HiRR0bEznybILGw+/TWEbSeo4WS/Lf8CAuob0TTFoneGv7LRusS76POBmTOIN2eay7FwwA3ZUrEKU0vPAVr+PMU6gaVXxS6U5xg7vR/cmWtv1gtdUiUlQHyH6MYLdl4M6IaV6IpoHdulhBfV0UIBAZmBSYaEeLX4sda24Ic7j/I= 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=mTAdO6AE; arc=none smtp.client-ip=198.47.23.248 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="mTAdO6AE" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICh7UH110072; Sat, 18 May 2024 07:43:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036187; bh=GzbWPgN25doQLrvoohmHb3qEO5wj31NYefx2WCnThbE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=mTAdO6AEQ2X6QJpHVLNvdhUnNHarZvzJB1Ma7BjZAESkzuQBNqrJdGXbFsOSvpF5p zKqra/ufKI8noIjiJOm40MvcjzSMoYFicL55NJdT9sTXAhxWTx6OYsdXmWTnoz9eRt B05Os9C35r2BdMvhaXzGf0W4wsuKkqFOoVhhKTdE= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICh7qX129339 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:07 -0500 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:06 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:06 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9M041511; Sat, 18 May 2024 07:43:02 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 06/28] net: ethernet: ti: cpsw-proxy-client: add helper to get virtual port info Date: Sat, 18 May 2024 18:12:12 +0530 Message-ID: <20240518124234.2671651-7-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the helper function "get_virtual_port_info()" to send the ETHFW_VIRT_PORT_INFO request and store details of virtual port allocation. The details include type of virtual port, the virtual port ID and the token identifying the virtual port. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 75 +++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 70b8cfe67921..262fbf59ac72 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -14,6 +14,11 @@ #define ETHFW_RESPONSE_TIMEOUT_MS 500 +enum virtual_port_type { + VIRT_SWITCH_PORT, + VIRT_MAC_ONLY_PORT, +}; + struct cpsw_proxy_req_params { struct message req_msg; /* Request message to be filled */ u32 token; @@ -30,13 +35,26 @@ struct cpsw_proxy_req_params { u8 ipv4_addr[ETHFW_IPV4ADDRLEN]; }; +struct virtual_port { + struct cpsw_proxy_priv *proxy_priv; + enum virtual_port_type port_type; + u32 port_id; +}; + struct cpsw_proxy_priv { struct rpmsg_device *rpdev; struct device *dev; + struct virtual_port *virt_ports; struct cpsw_proxy_req_params req_params; + struct mutex req_params_mutex; /* Request params mutex */ struct message resp_msg; struct completion wait_for_response; int resp_msg_len; + u32 vswitch_ports; /* Bitmask of Virtual Switch Port IDs */ + u32 vmac_ports /* Bitmask of Virtual MAC Only Port IDs */; + u32 num_switch_ports; + u32 num_mac_ports; + u32 num_virt_ports; }; static int cpsw_proxy_client_cb(struct rpmsg_device *rpdev, void *data, @@ -275,6 +293,63 @@ static int send_request_get_response(struct cpsw_proxy_priv *proxy_priv, return ret; } +static int get_virtual_port_info(struct cpsw_proxy_priv *proxy_priv) +{ + struct virt_port_info_response *vpi_resp; + struct cpsw_proxy_req_params *req_p; + struct virtual_port *vport; + struct message resp_msg; + unsigned int vp_id, i; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_VIRT_PORT_INFO; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + + if (ret) { + dev_err(proxy_priv->dev, "failed to get virtual port info\n"); + return ret; + } + + vpi_resp = (struct virt_port_info_response *)&resp_msg; + proxy_priv->vswitch_ports = vpi_resp->switch_port_mask; + proxy_priv->vmac_ports = vpi_resp->mac_port_mask; + /* Number of 1s set in vswitch_ports is the count of switch ports */ + proxy_priv->num_switch_ports = hweight32(proxy_priv->vswitch_ports); + proxy_priv->num_virt_ports = proxy_priv->num_switch_ports; + /* Number of 1s set in vmac_ports is the count of mac ports */ + proxy_priv->num_mac_ports = hweight32(proxy_priv->vmac_ports); + proxy_priv->num_virt_ports += proxy_priv->num_mac_ports; + + proxy_priv->virt_ports = devm_kcalloc(proxy_priv->dev, + proxy_priv->num_virt_ports, + sizeof(*proxy_priv->virt_ports), + GFP_KERNEL); + + vp_id = 0; + for (i = 0; i < proxy_priv->num_switch_ports; i++) { + vport = &proxy_priv->virt_ports[vp_id]; + vport->proxy_priv = proxy_priv; + vport->port_type = VIRT_SWITCH_PORT; + /* Port ID is derived from the bit set in the bitmask */ + vport->port_id = fns(proxy_priv->vswitch_ports, i); + vp_id++; + } + + for (i = 0; i < proxy_priv->num_mac_ports; i++) { + vport = &proxy_priv->virt_ports[vp_id]; + vport->proxy_priv = proxy_priv; + vport->port_type = VIRT_MAC_ONLY_PORT; + /* Port ID is derived from the bit set in the bitmask */ + vport->port_id = fns(proxy_priv->vmac_ports, i); + vp_id++; + } + + return 0; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667613 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 7F4F2604B3; Sat, 18 May 2024 12:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036207; cv=none; b=Q7CgWt0Wu3JC2jXObGmlwt0XFlIpxaHWfYXlPMyeQASgNA9OafodDNNoJStN44q0p29P5xuRKg9XpidMRfNcIJBnZPXsVmnFmk70tvCitEMCVLzS9bUxyvUFS6yTOJ7eKQNECGHiuiC4c4b8F2pifsDkaK9in0uK5nxxZjHFoHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036207; c=relaxed/simple; bh=DSow4JVM3Wc+nMlDPSHNLhUp0GWyFpMgBLlgLiWErLA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CjM6O3Nd1eWG1Myhi1rjnnC6mexECxKzqRJpXE7BLwgn5NetWYOptVFODxOz0IwjAQLJ4mrrnnL+T+Fh7wdWIsc16RMyMYg5LiZ42cNFQ+lyttf5cWZBk4B7QY2WM7jS6Xs7TaegrTfFxnNvbiGNDXi3Pw+hIzfOuNWza00N//I= 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=BVoN369O; arc=none smtp.client-ip=198.47.19.142 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="BVoN369O" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChBWO054960; Sat, 18 May 2024 07:43:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036191; bh=msXRCMz8oqQ3jcF0j+F0nb50w6sdf+t+D/WHZUaXasU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=BVoN369OF6MYQmWlCDzJJCH6BjxlN2uW2/XHv4gCXcZEhx48lBRNxf4AEBQcNCeMJ vL6ionP0iBpzfgXiPpANMcZe/Y+8LPHY4wv7Vhf1C6Ge7/ZgRPEubiMdQ7DeWl+fCS oODBs8EVhvFYDIbOzJf2UR3DtUXYeaMu2nHcBI7s= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChBpW129379 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:11 -0500 Received: from DFLE110.ent.ti.com (10.64.6.31) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:11 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:11 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9N041511; Sat, 18 May 2024 07:43:07 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 07/28] net: ethernet: ti: cpsw-proxy-client: add helper to attach virtual ports Date: Sat, 18 May 2024 18:12:13 +0530 Message-ID: <20240518124234.2671651-8-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the helper function "attach_virtual_ports()" to send the ETHFW_ATTACH_VIRT_PORT request for each virtual port and store details of features corresponding to the virtual port, the number of TX DMA Channels allocated to the virtual port and the number of RX DMA Channels allocated to the virtual port. If attaching any of the virtual ports fails, detach all previously attached virtual ports. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 90 +++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 262fbf59ac72..691b36bc3715 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -35,10 +35,26 @@ struct cpsw_proxy_req_params { u8 ipv4_addr[ETHFW_IPV4ADDRLEN]; }; +struct rx_dma_chan { + struct virtual_port *vport; + u32 rel_chan_idx; +}; + +struct tx_dma_chan { + struct virtual_port *vport; + u32 rel_chan_idx; +}; + struct virtual_port { struct cpsw_proxy_priv *proxy_priv; + struct rx_dma_chan *rx_chans; + struct tx_dma_chan *tx_chans; enum virtual_port_type port_type; u32 port_id; + u32 port_token; + u32 port_features; + u32 num_rx_chan; + u32 num_tx_chan; }; struct cpsw_proxy_priv { @@ -350,6 +366,80 @@ static int get_virtual_port_info(struct cpsw_proxy_priv *proxy_priv) return 0; } +static int attach_virtual_ports(struct cpsw_proxy_priv *proxy_priv) +{ + struct cpsw_proxy_req_params *req_p; + struct attach_response *att_resp; + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + struct virtual_port *vport; + struct message resp_msg; + unsigned int i, j; + u32 port_id; + int ret; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + port_id = vport->port_id; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->port_id = port_id; + req_p->request_type = ETHFW_VIRT_PORT_ATTACH; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + + if (ret) { + dev_err(proxy_priv->dev, "attaching virtual port failed\n"); + goto err; + } + + att_resp = (struct attach_response *)&resp_msg; + vport->port_token = att_resp->response_msg_hdr.msg_hdr.token; + vport->port_features = att_resp->features; + vport->num_tx_chan = att_resp->num_tx_chan; + vport->num_rx_chan = att_resp->num_rx_flow; + + vport->rx_chans = devm_kcalloc(proxy_priv->dev, + vport->num_rx_chan, + sizeof(*vport->rx_chans), + GFP_KERNEL); + for (j = 0; j < vport->num_rx_chan; j++) { + rx_chn = &vport->rx_chans[j]; + rx_chn->vport = vport; + rx_chn->rel_chan_idx = j; + } + + vport->tx_chans = devm_kcalloc(proxy_priv->dev, + vport->num_tx_chan, + sizeof(*vport->tx_chans), + GFP_KERNEL); + for (j = 0; j < vport->num_tx_chan; j++) { + tx_chn = &vport->tx_chans[j]; + tx_chn->vport = vport; + tx_chn->rel_chan_idx = j; + } + } + + return 0; + +err: + /* Detach virtual ports which were successfully attached */ + while (i--) { + vport = &proxy_priv->virt_ports[i]; + port_id = vport->port_id; + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_VIRT_PORT_DETACH; + req_p->token = vport->port_token; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) + dev_err(proxy_priv->dev, "detaching virtual port %u failed\n", port_id); + } + return -EIO; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667614 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 825BA6BFAA; Sat, 18 May 2024 12:43:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036212; cv=none; b=nKIU/MfTIMlZpfA9lNWPc70Ovt4E1QlVxCZU5lbjxvDlyib4t8frCFmbdTeNaCBw/8+nTYeSQgh1yF+qSlSy+wKL51LnhblQh620a1JpEcSuDqIvuPJ9lIbWvGSbtF9PSW0yaaKMRdar8HEz19TtUUAuKNMb9fCjsInDlL8Qe/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036212; c=relaxed/simple; bh=Jw4P8bVK9c/AccL9Hj+9pVXPKjs7iZ+nzu6OlcqM2iw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dYLydIL4RijsMVWeraZoKvtomyLcZUOn0xJV1InpSVPX7fK4YHSUN/gsn9K3fHOK79r2y3xvWSVwT5pT4ZNauuw/+lEeL+sK05obEH5B/ZZw89JVKa/Z/2dWl6OwON8MyjJh7+BJJribsnLovA9BGwfK/l4htKBuJ+FTAcPqgT8= 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=K+kal9ku; arc=none smtp.client-ip=198.47.19.142 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="K+kal9ku" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChGiU054968; Sat, 18 May 2024 07:43:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036196; bh=520vVll/ZFOoW9AjksFfU8ARoVZ/aAksC0ZgDCAKvsQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=K+kal9kuyL7dqvtYhLglioTDuaXqSUb2D0aq/uPAD6rJfl65QnJ8+LN39k6CpMiH3 AO0ngQ8WL9r4hsKGfartCIMXCfSvrw0LvR1pNxB/LGQ+EGoWysR/HZNH391entYFAM lGr33E4eNwVYlrlcHfF37oLwh7N1JSzLjnJJ97KA= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChGGR129426 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:16 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:16 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:16 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9O041511; Sat, 18 May 2024 07:43:12 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 08/28] net: ethernet: ti: cpsw-proxy-client: add helpers to alloc/free resources Date: Sat, 18 May 2024 18:12:14 +0530 Message-ID: <20240518124234.2671651-9-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "allocate_port_resources()" to request EthFw to allocate TX and RX DMA Channels and MAC Address for each Virtual Port which has been allocated to the Client. If allocating any of the resources fails, release all resources which were allocated earlier through the "free_port_resources()" function. During the process of freeing resources, if any request fails, avoid attempting to release other resources. This is due to the assumption that EthFw is non-functional and all further requests to free resources will most likely fail. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 165 ++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 691b36bc3715..b057cf4b7bea 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -38,11 +38,17 @@ struct cpsw_proxy_req_params { struct rx_dma_chan { struct virtual_port *vport; u32 rel_chan_idx; + u32 flow_base; + u32 flow_offset; + u32 thread_id; + bool in_use; }; struct tx_dma_chan { struct virtual_port *vport; u32 rel_chan_idx; + u32 thread_id; + bool in_use; }; struct virtual_port { @@ -55,6 +61,8 @@ struct virtual_port { u32 port_features; u32 num_rx_chan; u32 num_tx_chan; + u8 mac_addr[ETH_ALEN]; + bool mac_in_use; }; struct cpsw_proxy_priv { @@ -440,6 +448,163 @@ static int attach_virtual_ports(struct cpsw_proxy_priv *proxy_priv) return -EIO; } +static void free_port_resources(struct cpsw_proxy_priv *proxy_priv) +{ + struct cpsw_proxy_req_params *req_p; + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + struct virtual_port *vport; + struct message resp_msg; + u32 port_id, i, j; + int ret; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + port_id = vport->port_id; + + /* Free allocated MAC */ + if (vport->mac_in_use) { + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_FREE_MAC; + req_p->token = vport->port_token; + ether_addr_copy(req_p->mac_addr, vport->mac_addr); + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) { + dev_err(proxy_priv->dev, + "failed to free MAC Address for port %u err: %d\n", + port_id, ret); + return; + } + } + + /* Free TX DMA Channels */ + for (j = 0; j < vport->num_tx_chan; j++) { + tx_chn = &vport->tx_chans[j]; + if (!tx_chn->in_use) + continue; + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_FREE_TX; + req_p->token = vport->port_token; + req_p->tx_thread_id = tx_chn->thread_id; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) { + dev_err(proxy_priv->dev, + "failed to free TX Channel for port %u err: %d\n", + port_id, ret); + return; + } + } + + /* Free RX DMA Channels */ + for (j = 0; j < vport->num_rx_chan; j++) { + rx_chn = &vport->rx_chans[j]; + if (!rx_chn->in_use) + continue; + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_FREE_RX; + req_p->token = vport->port_token; + req_p->rx_flow_base = rx_chn->flow_base; + req_p->rx_flow_offset = rx_chn->flow_offset; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) { + dev_err(proxy_priv->dev, + "failed to free RX Channel for port %u err: %d\n", + port_id, ret); + return; + } + } + } +} + +static int allocate_port_resources(struct cpsw_proxy_priv *proxy_priv) +{ + struct tx_thread_alloc_response *tta_resp; + struct rx_flow_alloc_response *rfa_resp; + struct cpsw_proxy_req_params *req_p; + struct mac_alloc_response *ma_resp; + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + struct virtual_port *vport; + struct message resp_msg; + u32 port_id, i, j; + int ret; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + port_id = vport->port_id; + + /* Request RX DMA Flow allocation */ + for (j = 0; j < vport->num_rx_chan; j++) { + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_ALLOC_RX; + req_p->token = vport->port_token; + req_p->rx_tx_idx = j; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) { + dev_err(proxy_priv->dev, "RX Alloc for port %u failed\n", port_id); + goto err; + } + + rfa_resp = (struct rx_flow_alloc_response *)&resp_msg; + rx_chn = &vport->rx_chans[j]; + rx_chn->flow_base = rfa_resp->rx_flow_idx_base; + rx_chn->flow_offset = rfa_resp->rx_flow_idx_offset; + rx_chn->thread_id = rfa_resp->rx_psil_src_id; + rx_chn->in_use = 1; + } + + /* Request TX DMA Channel allocation */ + for (j = 0; j < vport->num_tx_chan; j++) { + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_ALLOC_TX; + req_p->token = vport->port_token; + req_p->rx_tx_idx = j; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) { + dev_err(proxy_priv->dev, "TX Alloc for port %u failed\n", port_id); + goto err; + } + + tta_resp = (struct tx_thread_alloc_response *)&resp_msg; + tx_chn = &vport->tx_chans[j]; + tx_chn->thread_id = tta_resp->tx_psil_dest_id; + tx_chn->in_use = 1; + } + + /* Request MAC allocation */ + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_ALLOC_MAC; + req_p->token = vport->port_token; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) { + dev_err(proxy_priv->dev, "MAC Alloc for port %u failed\n", port_id); + goto err; + } + + ma_resp = (struct mac_alloc_response *)&resp_msg; + ether_addr_copy(vport->mac_addr, ma_resp->mac_addr); + vport->mac_in_use = 1; + } + + return 0; + +err: + free_port_resources(proxy_priv); + return -EIO; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667615 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 0CF3C6CDA6; Sat, 18 May 2024 12:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036222; cv=none; b=p4/2arIdrwk64fKS+0gpaaplQpPeQDAq0OvGGH6GEno/8MopvAUs5oYHqSjwQdbwTBJ6rWCMvKstBDdagEDIy6ze4rvmC3rxpLOZaeGiWBE8bKq6HmRcvfxy0irm0iw7skt+xc8o4y49SBB/JpA3fGYMrjisVWB2qWtYRFzQO2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036222; c=relaxed/simple; bh=gIyVwz0Wcg0LkmdC28gikWPE100JFMVOaly/w6xEQOY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bX5slzN6EPu1rzOZwQwxilH3va8iqrpURiIPmGXS6BXwQ3UELV+veJE5+9x19ywlC4hQ/tGllXAXF0JH9nuhEglj/SgGgkcxsv24FpcJLf07loB+x4SaTDuZC2ASgapyL5Jt7KeerRxXayHp3ZFSiFIVD+4J67FMjaZbj87Y9QI= 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=AL78jLzy; arc=none smtp.client-ip=198.47.19.141 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="AL78jLzy" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChLLq002777; Sat, 18 May 2024 07:43:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036201; bh=X4OG+ZvQd9VrF6yQRJQsEZaaVWKIzPyaHgTp/GtXj38=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=AL78jLzyitLh7oyJmklgJCxhd4015R4pvSE2xNdc+rbrwqLYI/gORKTAniovoX+zj y2txWgDV6T3U3av6IUllFUOuRtxZ9c4oqb1z9SNuYy5lAUxwmOU7FUlkemvuFRo2MX x+yz5zJr2PXO5i/ANVhnkicr8EQkdwTpTLm30n2U= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChLJb129471 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:21 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:20 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:20 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9P041511; Sat, 18 May 2024 07:43:16 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 09/28] net: ethernet: ti: cpsw-proxy-client: add helper to init TX DMA Channels Date: Sat, 18 May 2024 18:12:15 +0530 Message-ID: <20240518124234.2671651-10-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the "init_tx_chans()" function to initialize the TX DMA Channels. With the knowledge of the PSI-L Thread IDs allocated to the Client for each Virtual Port, the TX DMA Channels can be setup using the DMA APIs. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 115 ++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index b057cf4b7bea..efb44ff04b6a 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -9,11 +9,20 @@ #include #include #include +#include #include "ethfw_abi.h" +#include "k3-cppi-desc-pool.h" #define ETHFW_RESPONSE_TIMEOUT_MS 500 +#define PS_DATA_SIZE 16 +#define SW_DATA_SIZE 16 + +#define MAX_TX_DESC 500 + +#define CHAN_NAME_LEN 128 + enum virtual_port_type { VIRT_SWITCH_PORT, VIRT_MAC_ONLY_PORT, @@ -46,8 +55,14 @@ struct rx_dma_chan { struct tx_dma_chan { struct virtual_port *vport; + struct device *dev; + struct k3_cppi_desc_pool *desc_pool; + struct k3_udma_glue_tx_channel *tx_chan; u32 rel_chan_idx; u32 thread_id; + u32 num_descs; + unsigned int irq; + char tx_chan_name[CHAN_NAME_LEN]; bool in_use; }; @@ -68,6 +83,7 @@ struct virtual_port { struct cpsw_proxy_priv { struct rpmsg_device *rpdev; struct device *dev; + struct device_node *dma_node; struct virtual_port *virt_ports; struct cpsw_proxy_req_params req_params; struct mutex req_params_mutex; /* Request params mutex */ @@ -79,6 +95,7 @@ struct cpsw_proxy_priv { u32 num_switch_ports; u32 num_mac_ports; u32 num_virt_ports; + u32 num_active_tx_chans; }; static int cpsw_proxy_client_cb(struct rpmsg_device *rpdev, void *data, @@ -605,6 +622,104 @@ static int allocate_port_resources(struct cpsw_proxy_priv *proxy_priv) return -EIO; } +static void free_tx_chns(void *data) +{ + struct cpsw_proxy_priv *proxy_priv = data; + struct tx_dma_chan *tx_chn; + struct virtual_port *vport; + u32 i, j; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + for (j = 0; j < vport->num_tx_chan; j++) { + tx_chn = &vport->tx_chans[j]; + + if (!IS_ERR_OR_NULL(tx_chn->desc_pool)) + k3_cppi_desc_pool_destroy(tx_chn->desc_pool); + + if (!IS_ERR_OR_NULL(tx_chn->tx_chan)) + k3_udma_glue_release_tx_chn(tx_chn->tx_chan); + + memset(tx_chn, 0, sizeof(*tx_chn)); + } + } +} + +static int init_tx_chans(struct cpsw_proxy_priv *proxy_priv) +{ + u32 max_desc_num = ALIGN(MAX_TX_DESC, MAX_SKB_FRAGS); + struct k3_udma_glue_tx_channel_cfg tx_cfg = { 0 }; + struct device *dev = proxy_priv->dev; + u32 hdesc_size, tx_chn_num, i, j; + char tx_chn_name[CHAN_NAME_LEN]; + struct k3_ring_cfg ring_cfg = { + .elm_size = K3_RINGACC_RING_ELSIZE_8, + .mode = K3_RINGACC_RING_MODE_RING, + .flags = 0 + }; + struct tx_dma_chan *tx_chn; + struct virtual_port *vport; + int ret = 0, ret1; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + + for (j = 0; j < vport->num_tx_chan; j++) { + tx_chn = &vport->tx_chans[j]; + + tx_chn_num = proxy_priv->num_active_tx_chans++; + snprintf(tx_chn_name, sizeof(tx_chn_name), "tx%u-virt-port-%u", + tx_chn_num, vport->port_id); + strscpy(tx_chn->tx_chan_name, tx_chn_name, sizeof(tx_chn->tx_chan_name)); + + hdesc_size = cppi5_hdesc_calc_size(true, PS_DATA_SIZE, SW_DATA_SIZE); + + tx_cfg.swdata_size = SW_DATA_SIZE; + tx_cfg.tx_cfg = ring_cfg; + tx_cfg.txcq_cfg = ring_cfg; + tx_cfg.tx_cfg.size = max_desc_num; + tx_cfg.txcq_cfg.size = max_desc_num; + + tx_chn->dev = dev; + tx_chn->num_descs = max_desc_num; + tx_chn->desc_pool = k3_cppi_desc_pool_create_name(dev, + tx_chn->num_descs, + hdesc_size, + tx_chn_name); + if (IS_ERR(tx_chn->desc_pool)) { + ret = PTR_ERR(tx_chn->desc_pool); + dev_err(dev, "failed to create tx pool %d\n", ret); + goto err; + } + + tx_chn->tx_chan = + k3_udma_glue_request_tx_chn_for_thread_id(dev, &tx_cfg, + proxy_priv->dma_node, + tx_chn->thread_id); + if (IS_ERR(tx_chn->tx_chan)) { + ret = PTR_ERR(tx_chn->tx_chan); + dev_err(dev, "Failed to request tx dma channel %d\n", ret); + goto err; + } + + tx_chn->irq = k3_udma_glue_tx_get_irq(tx_chn->tx_chan); + if (tx_chn->irq <= 0) { + dev_err(dev, "Failed to get tx dma irq %d\n", tx_chn->irq); + ret = -ENXIO; + } + } + } + +err: + ret1 = devm_add_action(dev, free_tx_chns, proxy_priv); + if (ret1) { + dev_err(dev, "failed to add free_tx_chns action %d", ret1); + return ret1; + } + + return ret; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667616 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 E41E96CDAB; Sat, 18 May 2024 12:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036223; cv=none; b=djjklaSpfK2GOx3ShGcUwNxA7QXqA7Mo4MjQMBTuGDbDF4TN6tEnrQqIhBRfz8upjQZukGLa6z8LRCVy5L4khf7A9YZu99ZzGsAyZlJ4LGBJbGNGYTmV/rpNMPE1EZOJOAcxUStfaxcePWAZU5N796I7ovjRbtOPt14bqyuDAVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036223; c=relaxed/simple; bh=ONWwtb/E5rDMX5BawuZhOKVUHmz5hGEN7uIBo5U6++c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rfPEHuuQ3Y+xCrqciiWCqV+ePvFaW3G9H+hqkh4rSG51+s+cPuiP/IZ01ptT6rHEN0TvB9eJNaznEUxc8un/GjhUA05mjNDUsnv9jSc6vO0F3MfIz+rqsQOZpzNj0NoQDQ6Hyw7ZYMQ7H6EKPBdlA8it5I9S/aQaqUEiHYFHV7o= 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=STbMyYOs; arc=none smtp.client-ip=198.47.19.141 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="STbMyYOs" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChPl6002785; Sat, 18 May 2024 07:43:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036205; bh=0GrwBlSU/Vcks+HbbBXVZ6OE94NII5ICaCjwmTrIL4Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=STbMyYOsqOucYTiFz+Bcl+qpGizPVtHQUzuXBJG+CQoNEEEh7l3Wx+VGjYCyZ1xNL 8I4LSpgJLohdCWh6d0/up686qtusvvYlZQ33HOJIVIbdpq3yQ/UbXf/r1B/3YEcC0T m7IZez6l6IJGuFpmQvTBkth1zzHQpWbxBc9uJW7w= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChP6R017301 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:25 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) 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.23; Sat, 18 May 2024 07:43:25 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:25 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9Q041511; Sat, 18 May 2024 07:43:21 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 10/28] net: ethernet: ti: cpsw-proxy-client: add helper to init RX DMA Channels Date: Sat, 18 May 2024 18:12:16 +0530 Message-ID: <20240518124234.2671651-11-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the "init_rx_chans()" function to initialize the RX DMA Channels. With the knowledge of the PSI-L Thread ID for the RX Channel along with the details of the RX Flow Base and RX Flow Offset, the RX DMA Flow on the RX Channel can be setup using the DMA APIs. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 128 ++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index efb44ff04b6a..16e8e585adce 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -20,6 +20,8 @@ #define SW_DATA_SIZE 16 #define MAX_TX_DESC 500 +#define MAX_RX_DESC 500 +#define MAX_RX_FLOWS 1 #define CHAN_NAME_LEN 128 @@ -46,10 +48,16 @@ struct cpsw_proxy_req_params { struct rx_dma_chan { struct virtual_port *vport; + struct device *dev; + struct k3_cppi_desc_pool *desc_pool; + struct k3_udma_glue_rx_channel *rx_chan; u32 rel_chan_idx; u32 flow_base; u32 flow_offset; u32 thread_id; + u32 num_descs; + unsigned int irq; + char rx_chan_name[CHAN_NAME_LEN]; bool in_use; }; @@ -96,6 +104,7 @@ struct cpsw_proxy_priv { u32 num_mac_ports; u32 num_virt_ports; u32 num_active_tx_chans; + u32 num_active_rx_chans; }; static int cpsw_proxy_client_cb(struct rpmsg_device *rpdev, void *data, @@ -720,6 +729,125 @@ static int init_tx_chans(struct cpsw_proxy_priv *proxy_priv) return ret; } +static void free_rx_chns(void *data) +{ + struct cpsw_proxy_priv *proxy_priv = data; + struct rx_dma_chan *rx_chn; + struct virtual_port *vport; + u32 i, j; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + + for (j = 0; j < vport->num_rx_chan; j++) { + rx_chn = &vport->rx_chans[j]; + + if (!IS_ERR_OR_NULL(rx_chn->desc_pool)) + k3_cppi_desc_pool_destroy(rx_chn->desc_pool); + + if (!IS_ERR_OR_NULL(rx_chn->rx_chan)) + k3_udma_glue_release_rx_chn(rx_chn->rx_chan); + } + } +} + +static int init_rx_chans(struct cpsw_proxy_priv *proxy_priv) +{ + struct k3_udma_glue_rx_channel_cfg rx_cfg = {0}; + struct device *dev = proxy_priv->dev; + u32 hdesc_size, rx_chn_num, i, j; + u32 max_desc_num = MAX_RX_DESC; + char rx_chn_name[CHAN_NAME_LEN]; + struct rx_dma_chan *rx_chn; + struct virtual_port *vport; + struct k3_ring_cfg rxring_cfg = { + .elm_size = K3_RINGACC_RING_ELSIZE_8, + .mode = K3_RINGACC_RING_MODE_MESSAGE, + .flags = 0, + }; + struct k3_ring_cfg fdqring_cfg = { + .elm_size = K3_RINGACC_RING_ELSIZE_8, + .mode = K3_RINGACC_RING_MODE_MESSAGE, + .flags = 0, + }; + struct k3_udma_glue_rx_flow_cfg rx_flow_cfg = { + .rx_cfg = rxring_cfg, + .rxfdq_cfg = fdqring_cfg, + .ring_rxq_id = K3_RINGACC_RING_ID_ANY, + .ring_rxfdq0_id = K3_RINGACC_RING_ID_ANY, + .src_tag_lo_sel = K3_UDMA_GLUE_SRC_TAG_LO_USE_REMOTE_SRC_TAG, + }; + int ret = 0, ret1; + + hdesc_size = cppi5_hdesc_calc_size(true, PS_DATA_SIZE, SW_DATA_SIZE); + + rx_cfg.swdata_size = SW_DATA_SIZE; + rx_cfg.flow_id_num = MAX_RX_FLOWS; + rx_cfg.remote = true; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + + for (j = 0; j < vport->num_rx_chan; j++) { + rx_chn = &vport->rx_chans[j]; + + rx_chn_num = proxy_priv->num_active_rx_chans++; + snprintf(rx_chn_name, sizeof(rx_chn_name), "rx%u-virt-port-%u", rx_chn_num, + vport->port_id); + strscpy(rx_chn->rx_chan_name, rx_chn_name, sizeof(rx_chn->rx_chan_name)); + + rx_cfg.flow_id_base = rx_chn->flow_base + rx_chn->flow_offset; + + /* init all flows */ + rx_chn->dev = dev; + rx_chn->num_descs = max_desc_num; + rx_chn->desc_pool = k3_cppi_desc_pool_create_name(dev, + rx_chn->num_descs, + hdesc_size, + rx_chn_name); + if (IS_ERR(rx_chn->desc_pool)) { + ret = PTR_ERR(rx_chn->desc_pool); + dev_err(dev, "Failed to create rx pool %d\n", ret); + goto err; + } + + rx_chn->rx_chan = + k3_udma_glue_request_remote_rx_chn_for_thread_id(dev, &rx_cfg, + proxy_priv->dma_node, + rx_chn->thread_id); + if (IS_ERR(rx_chn->rx_chan)) { + ret = PTR_ERR(rx_chn->rx_chan); + dev_err(dev, "Failed to request rx dma channel %d\n", ret); + goto err; + } + + rx_flow_cfg.rx_cfg.size = max_desc_num; + rx_flow_cfg.rxfdq_cfg.size = max_desc_num; + ret = k3_udma_glue_rx_flow_init(rx_chn->rx_chan, + 0, &rx_flow_cfg); + if (ret) { + dev_err(dev, "Failed to init rx flow %d\n", ret); + goto err; + } + + rx_chn->irq = k3_udma_glue_rx_get_irq(rx_chn->rx_chan, 0); + if (rx_chn->irq <= 0) { + ret = -ENXIO; + dev_err(dev, "Failed to get rx dma irq %d\n", rx_chn->irq); + } + } + } + +err: + ret1 = devm_add_action(dev, free_rx_chns, proxy_priv); + if (ret1) { + dev_err(dev, "failed to add free_rx_chns action %d", ret1); + return ret1; + } + + return ret; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667617 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 A9FDF6E5E8; Sat, 18 May 2024 12:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036227; cv=none; b=KgsT3q28jioqUKxZi68TC138cehqSHWK/vZbbx7wjp00MaZYyL6HW5uJ3Dbxbbs+nOeyhYFx5VLbrTNFpmP8Ml9VcIVkHznn70CJbTBAegVR+dXJWR1z5HJGuCWjF285vfVGttTzYHaNZW8WlyKgQ+mXPhfFoIH1R0J4KZ4Q3G8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036227; c=relaxed/simple; bh=7jnXzgN1DYVWeRy7s3XSSsPtDdBRVBcKsoIA0Bx5U5c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TGfdnFh6qiUjyJ41I009JU9qgilSQpySLzWU3YynCHtfiSDLV0NSNh5q57vJzl2EhiLYaylmd9cva3wizSxgOHjzMhHJ3z/NOh5OVRLoqvrNOjT2tyxVwVEoxOegNYfOmlebQh0mZFCsqbZdaKXouP1fIGRvm4vcmmzAB7x+3K0= 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=tLVR9OHX; arc=none smtp.client-ip=198.47.23.248 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="tLVR9OHX" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChUrw110100; Sat, 18 May 2024 07:43:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036210; bh=MsofboICpT4F+D2umTdZQcxmXGgAuWnH2iVGw4gZnhQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tLVR9OHXuhS7L3Ct+TQNsfrSXKN0rRnW6cy3Q16jZ1wPb6t5LwJY4xbyHT+Qqqqnd sB4dg5qB8PoRUYV3R4B6OAucHv40FjdDqs51PC1pcMX8OM8/a0nIYnEaAn9RK+16Do EVQK+Ui4rz53Q0Jv2XQ2PQFNNL+yA4LqXfatgfXA= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChUPm051425 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:30 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:29 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:29 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9R041511; Sat, 18 May 2024 07:43:25 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 11/28] net: ethernet: ti: cpsw-proxy-client: add NAPI TX polling function Date: Sat, 18 May 2024 18:12:17 +0530 Message-ID: <20240518124234.2671651-12-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the "vport_tx_poll()" function to be registered as the NAPI TX polling function via "netif_napi_add_tx()". Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 140 ++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 16e8e585adce..cf99d8b6c1ec 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -66,6 +66,7 @@ struct tx_dma_chan { struct device *dev; struct k3_cppi_desc_pool *desc_pool; struct k3_udma_glue_tx_channel *tx_chan; + struct napi_struct napi_tx; u32 rel_chan_idx; u32 thread_id; u32 num_descs; @@ -74,11 +75,26 @@ struct tx_dma_chan { bool in_use; }; +struct vport_netdev_stats { + u64 tx_packets; + u64 tx_bytes; + u64 rx_packets; + u64 rx_bytes; + struct u64_stats_sync syncp; +}; + +struct vport_netdev_priv { + struct vport_netdev_stats __percpu *stats; + struct virtual_port *vport; +}; + struct virtual_port { struct cpsw_proxy_priv *proxy_priv; struct rx_dma_chan *rx_chans; struct tx_dma_chan *tx_chans; + struct completion tdown_complete; enum virtual_port_type port_type; + atomic_t tdown_cnt; u32 port_id; u32 port_token; u32 port_features; @@ -672,6 +688,7 @@ static int init_tx_chans(struct cpsw_proxy_priv *proxy_priv) for (i = 0; i < proxy_priv->num_virt_ports; i++) { vport = &proxy_priv->virt_ports[i]; + init_completion(&vport->tdown_complete); for (j = 0; j < vport->num_tx_chan; j++) { tx_chn = &vport->tx_chans[j]; @@ -848,6 +865,129 @@ static int init_rx_chans(struct cpsw_proxy_priv *proxy_priv) return ret; } +static void vport_xmit_free(struct tx_dma_chan *tx_chn, struct device *dev, + struct cppi5_host_desc_t *desc) +{ + struct cppi5_host_desc_t *first_desc, *next_desc; + dma_addr_t buf_dma, next_desc_dma; + u32 buf_dma_len; + + first_desc = desc; + next_desc = first_desc; + + cppi5_hdesc_get_obuf(first_desc, &buf_dma, &buf_dma_len); + + dma_unmap_single(dev, buf_dma, buf_dma_len, + DMA_TO_DEVICE); + + next_desc_dma = cppi5_hdesc_get_next_hbdesc(first_desc); + while (next_desc_dma) { + next_desc = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, + next_desc_dma); + cppi5_hdesc_get_obuf(next_desc, &buf_dma, &buf_dma_len); + + dma_unmap_page(dev, buf_dma, buf_dma_len, + DMA_TO_DEVICE); + + next_desc_dma = cppi5_hdesc_get_next_hbdesc(next_desc); + + k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc); + } + + k3_cppi_desc_pool_free(tx_chn->desc_pool, first_desc); +} + +static int tx_compl_packets(struct virtual_port *vport, unsigned int tx_chan_idx, + unsigned int budget, bool *tdown) +{ + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct device *dev = proxy_priv->dev; + struct cppi5_host_desc_t *desc_tx; + struct netdev_queue *netif_txq; + unsigned int total_bytes = 0; + struct tx_dma_chan *tx_chn; + struct net_device *ndev; + struct sk_buff *skb; + dma_addr_t desc_dma; + int res, num_tx = 0; + void **swdata; + + tx_chn = &vport->tx_chans[tx_chan_idx]; + + while (budget--) { + struct vport_netdev_priv *ndev_priv; + struct vport_netdev_stats *stats; + + res = k3_udma_glue_pop_tx_chn(tx_chn->tx_chan, &desc_dma); + if (res == -ENODATA) + break; + + if (desc_dma & 0x1) { + if (atomic_dec_and_test(&vport->tdown_cnt)) + complete(&vport->tdown_complete); + *tdown = true; + break; + } + + desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, + desc_dma); + swdata = cppi5_hdesc_get_swdata(desc_tx); + skb = *(swdata); + vport_xmit_free(tx_chn, dev, desc_tx); + + ndev = skb->dev; + + ndev_priv = netdev_priv(ndev); + stats = this_cpu_ptr(ndev_priv->stats); + u64_stats_update_begin(&stats->syncp); + stats->tx_packets++; + stats->tx_bytes += skb->len; + u64_stats_update_end(&stats->syncp); + + total_bytes += skb->len; + napi_consume_skb(skb, budget); + num_tx++; + } + + if (!num_tx) + return 0; + + netif_txq = netdev_get_tx_queue(ndev, tx_chan_idx); + netdev_tx_completed_queue(netif_txq, num_tx, total_bytes); + + if (netif_tx_queue_stopped(netif_txq)) { + __netif_tx_lock(netif_txq, smp_processor_id()); + if (netif_running(ndev) && + (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >= + MAX_SKB_FRAGS)) + netif_tx_wake_queue(netif_txq); + + __netif_tx_unlock(netif_txq); + } + + return num_tx; +} + +static int vport_tx_poll(struct napi_struct *napi_tx, int budget) +{ + struct tx_dma_chan *tx_chn = container_of(napi_tx, struct tx_dma_chan, + napi_tx); + struct virtual_port *vport = tx_chn->vport; + bool tdown = false; + int num_tx; + + /* process every unprocessed channel */ + num_tx = tx_compl_packets(vport, tx_chn->rel_chan_idx, budget, &tdown); + + if (num_tx >= budget) + return budget; + + if (napi_complete_done(napi_tx, num_tx)) + enable_irq(tx_chn->irq); + + return 0; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667618 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 BD4F76EB5D; Sat, 18 May 2024 12:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036229; cv=none; b=h1i7vIx+7snP+VsaoqqOzI7VoJ878sEcN/DBPm7aLFS++BK7sYjB+6j2/zhfYmF+ExcGpJOsZl7Ncvd2jmwb7totknOwJSXxk+plyl8cf0Lz/dNlbOsqahJge95ZRD4xVExcCVsln7OTOpXqgkJ36pGGIBHY8qSfyF3R0wXbK48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036229; c=relaxed/simple; bh=G1p3WYla4GtP7wFX84DnEU4P/oP2uoStviRxIClBfdI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y6xGeootPlyKy7y0G7LG/D0XFSOClKISkhOl2KAhpure7Y4vfafqQsQK+uwq/YfEEORjoHSizxhtvVdnjARVl6GNuz/nOwyQbu7X9e4uNcWq3yP2fnQP406tpzC6eZ3tguMsjeuMZTi9btxLzSjKHzjiy+z5zZqVBukLwX43f6U= 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=qN6or/0K; arc=none smtp.client-ip=198.47.19.142 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="qN6or/0K" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChYvl054987; Sat, 18 May 2024 07:43:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036215; bh=VPQuJU0oxohYz+O/nfKaLrIBOkh0o0tWyD1UPoA6Aqs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=qN6or/0K7l8Gfl26Q87faFDCnjGM8uwmhjMqW4LDsBEfOBeGPjugBdR7a6WerQgui Tdbd3+VZ19qqCofO4e4JMQLNsJ9p0QfJoJ6JiGd48M/K1HVJyWj6XYIwTGESG+F961 LJ4PSdnqEVX6AmJIfd2CJj6gBaC2XgCBXsSQynWY= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChYuG004213 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:34 -0500 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:34 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:34 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9S041511; Sat, 18 May 2024 07:43:30 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 12/28] net: ethernet: ti: cpsw-proxy-client: add NAPI RX polling function Date: Sat, 18 May 2024 18:12:18 +0530 Message-ID: <20240518124234.2671651-13-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the "vport_rx_poll()" function to be registered as the NAPI RX polling function via "netif_napi_add()". Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 189 ++++++++++++++++++++ 1 file changed, 189 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index cf99d8b6c1ec..6926f65a4613 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -6,7 +6,9 @@ */ #include +#include #include +#include #include #include #include @@ -23,6 +25,8 @@ #define MAX_RX_DESC 500 #define MAX_RX_FLOWS 1 +#define MAX_PACKET_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN) + #define CHAN_NAME_LEN 128 enum virtual_port_type { @@ -51,6 +55,7 @@ struct rx_dma_chan { struct device *dev; struct k3_cppi_desc_pool *desc_pool; struct k3_udma_glue_rx_channel *rx_chan; + struct napi_struct napi_rx; u32 rel_chan_idx; u32 flow_base; u32 flow_offset; @@ -90,6 +95,7 @@ struct vport_netdev_priv { struct virtual_port { struct cpsw_proxy_priv *proxy_priv; + struct net_device *ndev; struct rx_dma_chan *rx_chans; struct tx_dma_chan *tx_chans; struct completion tdown_complete; @@ -988,6 +994,189 @@ static int vport_tx_poll(struct napi_struct *napi_tx, int budget) return 0; } +/* RX psdata[2] word format - checksum information */ +#define RX_PSD_CSUM_ERR BIT(16) +#define RX_PSD_IS_FRAGMENT BIT(17) +#define RX_PSD_IPV6_VALID BIT(19) +#define RX_PSD_IPV4_VALID BIT(20) + +static void vport_rx_csum(struct sk_buff *skb, u32 csum_info) +{ + /* HW can verify IPv4/IPv6 TCP/UDP packets checksum + * csum information provides in psdata[2] word: + * RX_PSD_CSUM_ERR bit - indicates csum error + * RX_PSD_IPV6_VALID and CPSW_RX_PSD_IPV4_VALID + * bits - indicates IPv4/IPv6 packet + * RX_PSD_IS_FRAGMENT bit - indicates fragmented packet + * RX_PSD_CSUM_ADD has value 0xFFFF for non fragmented packets + * or csum value for fragmented packets if !RX_PSD_CSUM_ERR + */ + skb_checksum_none_assert(skb); + + if (unlikely(!(skb->dev->features & NETIF_F_RXCSUM))) + return; + + if ((csum_info & (RX_PSD_IPV6_VALID | + RX_PSD_IPV4_VALID)) && + !(csum_info & RX_PSD_CSUM_ERR)) { + /* csum for fragmented packets is unsupported */ + if (!(csum_info & RX_PSD_IS_FRAGMENT)) + skb->ip_summed = CHECKSUM_UNNECESSARY; + } +} + +static int vport_rx_push(struct virtual_port *vport, struct sk_buff *skb, + u32 rx_chan_idx) +{ + struct rx_dma_chan *rx_chn = &vport->rx_chans[rx_chan_idx]; + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct device *dev = proxy_priv->dev; + struct cppi5_host_desc_t *desc_rx; + u32 pkt_len = skb_tailroom(skb); + dma_addr_t desc_dma; + dma_addr_t buf_dma; + void *swdata; + + desc_rx = k3_cppi_desc_pool_alloc(rx_chn->desc_pool); + if (!desc_rx) { + dev_err(dev, "Failed to allocate RXFDQ descriptor\n"); + return -ENOMEM; + } + desc_dma = k3_cppi_desc_pool_virt2dma(rx_chn->desc_pool, desc_rx); + + buf_dma = dma_map_single(dev, skb->data, pkt_len, DMA_FROM_DEVICE); + if (unlikely(dma_mapping_error(dev, buf_dma))) { + k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); + dev_err(dev, "Failed to map rx skb buffer\n"); + return -EINVAL; + } + + cppi5_hdesc_init(desc_rx, CPPI5_INFO0_HDESC_EPIB_PRESENT, + PS_DATA_SIZE); + cppi5_hdesc_attach_buf(desc_rx, 0, 0, buf_dma, skb_tailroom(skb)); + swdata = cppi5_hdesc_get_swdata(desc_rx); + *((void **)swdata) = skb; + + return k3_udma_glue_push_rx_chn(rx_chn->rx_chan, 0, desc_rx, desc_dma); +} + +static int vport_rx_packets(struct virtual_port *vport, u32 rx_chan_idx) +{ + struct rx_dma_chan *rx_chn = &vport->rx_chans[rx_chan_idx]; + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + u32 buf_dma_len, pkt_len, port_id = 0, csum_info; + struct device *dev = proxy_priv->dev; + struct vport_netdev_priv *ndev_priv; + struct cppi5_host_desc_t *desc_rx; + struct vport_netdev_stats *stats; + struct sk_buff *skb, *new_skb; + dma_addr_t desc_dma, buf_dma; + struct net_device *ndev; + u32 flow_idx = 0; + void **swdata; + int ret = 0; + u32 *psdata; + + ret = k3_udma_glue_pop_rx_chn(rx_chn->rx_chan, flow_idx, &desc_dma); + if (ret) { + if (ret != -ENODATA) + dev_err(dev, "RX: pop chn fail %d\n", ret); + return ret; + } + + if (desc_dma & 0x1) { + dev_dbg(dev, "%s RX tdown flow: %u\n", __func__, flow_idx); + return 0; + } + + desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma); + dev_dbg(dev, "%s flow_idx: %u desc %pad\n", + __func__, flow_idx, &desc_dma); + + swdata = cppi5_hdesc_get_swdata(desc_rx); + skb = *swdata; + cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len); + pkt_len = cppi5_hdesc_get_pktlen(desc_rx); + cppi5_desc_get_tags_ids(&desc_rx->hdr, &port_id, NULL); + /* read port for dbg */ + dev_dbg(dev, "%s rx port_id:%d\n", __func__, port_id); + ndev = vport->ndev; + skb->dev = ndev; + + psdata = cppi5_hdesc_get_psdata(desc_rx); + csum_info = psdata[2]; + dev_dbg(dev, "%s rx csum_info:%#x\n", __func__, csum_info); + + dma_unmap_single(dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE); + + k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); + + if (unlikely(!netif_running(skb->dev))) { + dev_kfree_skb_any(skb); + return -ENODEV; + } + + new_skb = netdev_alloc_skb_ip_align(ndev, MAX_PACKET_SIZE); + if (new_skb) { + skb_put(skb, pkt_len); + skb->protocol = eth_type_trans(skb, ndev); + vport_rx_csum(skb, csum_info); + napi_gro_receive(&rx_chn->napi_rx, skb); + + ndev_priv = netdev_priv(ndev); + stats = this_cpu_ptr(ndev_priv->stats); + + u64_stats_update_begin(&stats->syncp); + stats->rx_packets++; + stats->rx_bytes += pkt_len; + u64_stats_update_end(&stats->syncp); + kmemleak_not_leak(new_skb); + } else { + ndev->stats.rx_dropped++; + new_skb = skb; + } + + if (netif_dormant(ndev)) { + dev_kfree_skb_any(new_skb); + ndev->stats.rx_dropped++; + return -ENODEV; + } + + ret = vport_rx_push(vport, new_skb, rx_chn->rel_chan_idx); + if (WARN_ON(ret < 0)) { + dev_kfree_skb_any(new_skb); + ndev->stats.rx_errors++; + ndev->stats.rx_dropped++; + } + + return ret; +} + +static int vport_rx_poll(struct napi_struct *napi_rx, int budget) +{ + struct rx_dma_chan *rx_chn = container_of(napi_rx, struct rx_dma_chan, + napi_rx); + struct virtual_port *vport = rx_chn->vport; + int num_rx = 0; + int cur_budget; + int ret; + + /* process every flow */ + cur_budget = budget; + + while (cur_budget--) { + ret = vport_rx_packets(vport, rx_chn->rel_chan_idx); + if (ret) + break; + num_rx++; + } + + if (num_rx < budget && napi_complete_done(napi_rx, num_rx)) + enable_irq(rx_chn->irq); + + return num_rx; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667619 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (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 BB64C71B5C; Sat, 18 May 2024 12:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036235; cv=none; b=At6NX0Je3PbVW5shpDko3jvM9xrug64wQ6PTWpT6+tqsNJDK0lMLUqCBP/rm8+rs7CR6I1iCGT+xU7Rh6EMhwb2lbdPRNQHLEZBbcb0fcQuRWYZ+3Sv0JY826XN/bSW8WOzGZ30sR4QUXvfXWX0lbsQEg/uykoy8kJrtwhGltds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036235; c=relaxed/simple; bh=NFlMcR2OvOGa5KH83GGrhf/DAKBykXJk9Yz4ChOs2/0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q/MSZNwWn5zJJt4HLcRqFjdI6pm5a+1qvkNxYApvYLxADWeiudV0LdiG/dpUrBDjDqV9yI9JIKVVvaJUMeKOB2sSf5Daeu+j42tcn1m2ybw3E6G3WSGaxk/hjP5zeYXa6G4Y1xQ7ZVah+Vt5ILik7Aov0oUn0E94UdcZJjvaje0= 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=L8mkyL21; arc=none smtp.client-ip=198.47.23.249 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="L8mkyL21" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChdGU017302; Sat, 18 May 2024 07:43:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036219; bh=JwuJzNh8I8iVqcX/z+Q5XQWtzHIZzmIwva4vCStI6+U=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=L8mkyL21BhOgbyPfkReoRNFCZ/ow3iMSQzpYWoF7fH76tv/j0ggEbcup5QShbcvbL sPRs23XsLB2qY1JU6kchl6pU4Qw7vv7HhdbXS0aXyxzzo1hsM0fgAGRsI/2J8NU4Wn kUV72+hTdEYPBlGgBUGngVrqrjK54CyQ7rcGs15g= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChd6e129545 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:39 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:38 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:39 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9T041511; Sat, 18 May 2024 07:43:35 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 13/28] net: ethernet: ti: cpsw-proxy-client: add helper to create netdevs Date: Sat, 18 May 2024 18:12:19 +0530 Message-ID: <20240518124234.2671651-14-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "init_netdevs()" to initialize and register net-device for each Virtual Port. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 102 ++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 6926f65a4613..30d53a8e174e 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -25,6 +26,7 @@ #define MAX_RX_DESC 500 #define MAX_RX_FLOWS 1 +#define MIN_PACKET_SIZE ETH_ZLEN #define MAX_PACKET_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN) #define CHAN_NAME_LEN 128 @@ -1177,6 +1179,106 @@ static int vport_rx_poll(struct napi_struct *napi_rx, int budget) return num_rx; } +const struct ethtool_ops cpsw_proxy_client_ethtool_ops = { +}; + +static const struct net_device_ops cpsw_proxy_client_netdev_ops = { +}; + +static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) +{ + struct device *dev = proxy_priv->dev; + struct vport_netdev_priv *ndev_priv; + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + int ret = 0; + u32 i; + + vport->ndev = devm_alloc_etherdev_mqs(dev, sizeof(struct vport_netdev_priv), + vport->num_tx_chan, vport->num_rx_chan); + + if (!vport->ndev) { + dev_err(dev, "error allocating netdev for port %u\n", vport->port_id); + return -ENOMEM; + } + + ndev_priv = netdev_priv(vport->ndev); + ndev_priv->vport = vport; + SET_NETDEV_DEV(vport->ndev, dev); + + if (is_valid_ether_addr(vport->mac_addr)) + eth_hw_addr_set(vport->ndev, vport->mac_addr); + + vport->ndev->min_mtu = MIN_PACKET_SIZE; + vport->ndev->max_mtu = MAX_PACKET_SIZE; + vport->ndev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM; + vport->ndev->features = vport->ndev->hw_features; + vport->ndev->vlan_features |= NETIF_F_SG; + vport->ndev->netdev_ops = &cpsw_proxy_client_netdev_ops; + vport->ndev->ethtool_ops = &cpsw_proxy_client_ethtool_ops; + + ndev_priv->stats = netdev_alloc_pcpu_stats(struct vport_netdev_stats); + if (!ndev_priv->stats) + return -ENOMEM; + + ret = devm_add_action_or_reset(dev, (void(*)(void *))free_percpu, ndev_priv->stats); + if (ret) { + dev_err(dev, "failed to add free_percpu action, err: %d\n", ret); + return ret; + } + + for (i = 0; i < vport->num_tx_chan; i++) { + tx_chn = &vport->tx_chans[i]; + netif_napi_add_tx(vport->ndev, &tx_chn->napi_tx, vport_tx_poll); + } + + for (i = 0; i < vport->num_rx_chan; i++) { + rx_chn = &vport->rx_chans[i]; + netif_napi_add(vport->ndev, &rx_chn->napi_rx, vport_rx_poll); + } + + ret = register_netdev(vport->ndev); + if (ret) + dev_err(dev, "error registering net device, err: %d\n", ret); + + return ret; +} + +static void unreg_netdevs(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + if (vport->ndev) + unregister_netdev(vport->ndev); + } +} + +static int init_netdevs(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + int ret; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + ret = init_netdev(proxy_priv, vport); + if (ret) { + dev_err(proxy_priv->dev, "failed to initialize ndev for port %u\n", + vport->port_id); + goto err; + } + } + + return 0; + +err: + unreg_netdevs(proxy_priv); + return ret; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667620 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 E551673176; Sat, 18 May 2024 12:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036238; cv=none; b=WpbTA19N+Q+L4YMMpAKXx3sJmoTn5uBB5tRvpPuybDmzPiUjAFQUfv1xDU03+B5NI3E2VqtCcDO/L/2c1HulSsB1qGj0AxvLxv9Be0EUsl0KvkV75f4EGwhHGWSPYPmBQoGmJwVpI7JfKc3zVrBTWOWRMI+Zc/csevl/ip+sP2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036238; c=relaxed/simple; bh=5h6ODGkc0sX5ceDWUsNUPY8nudq5cP9FauIbQ+umf0k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TcTbaG+fNGF86RhJKDqfF+XSKWjs2E5vUH92g5Zr5fC+nIm438ubT9lAy7ELfE9mHeNRdlwJTwxcyJkIlAdGXE6kc57Kmnj6KqH9uylf/XnAeNL18a74kuQWrg5xbUBHp2Apa9dNN3jVefJBkGY5Pp60BteD+t6hxN0aZ6NxrFs= 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=tW7Ip1tl; arc=none smtp.client-ip=198.47.19.141 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="tW7Ip1tl" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChi4S002817; Sat, 18 May 2024 07:43:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036224; bh=LcRO+fF6vZiIuvVdbUfzVYscZs4/NXqdS1YbI7UC3Lg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tW7Ip1tlUcJWBx3LDawPmKULqGHjQ7qwrg2CKQ/IAEccO545q8q6onOvGKPZIZzHH EXKMMHot2ThfXjNJmUMgCX94rjjnbpI1UnQ1mR+inu+oVTLhNGgulkci55clNlzeY5 grcicOF44olGLvRF3d+Dt6GBNV9vVQaHM5fGtHZU= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChhdO004255 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:43 -0500 Received: from DFLE110.ent.ti.com (10.64.6.31) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:43 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:43 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9U041511; Sat, 18 May 2024 07:43:39 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 14/28] net: ethernet: ti: cpsw-proxy-client: add and register dma irq handlers Date: Sat, 18 May 2024 18:12:20 +0530 Message-ID: <20240518124234.2671651-15-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "register_dma_irq_handlers()" to register the TX and RX DMA Interrupt handlers for all the TX and RX DMA Channels for every Virtual Port. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 60 +++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 30d53a8e174e..b0f0e5db3a74 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1279,6 +1279,66 @@ static int init_netdevs(struct cpsw_proxy_priv *proxy_priv) return ret; } +static irqreturn_t tx_irq_handler(int irq, void *dev_id) +{ + struct tx_dma_chan *tx_chn = dev_id; + + disable_irq_nosync(irq); + napi_schedule(&tx_chn->napi_tx); + + return IRQ_HANDLED; +} + +static irqreturn_t rx_irq_handler(int irq, void *dev_id) +{ + struct rx_dma_chan *rx_chn = dev_id; + + disable_irq_nosync(irq); + napi_schedule(&rx_chn->napi_rx); + + return IRQ_HANDLED; +} + +static int register_dma_irq_handlers(struct cpsw_proxy_priv *proxy_priv) +{ + struct device *dev = proxy_priv->dev; + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + struct virtual_port *vport; + u32 i, j; + int ret; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + + for (j = 0; j < vport->num_tx_chan; j++) { + tx_chn = &vport->tx_chans[j]; + + ret = devm_request_irq(dev, tx_chn->irq, tx_irq_handler, + IRQF_TRIGGER_HIGH, tx_chn->tx_chan_name, tx_chn); + if (ret) { + dev_err(dev, "failed to request tx irq: %u, err: %d\n", + tx_chn->irq, ret); + return ret; + } + } + + for (j = 0; j < vport->num_rx_chan; j++) { + rx_chn = &vport->rx_chans[j]; + + ret = devm_request_irq(dev, rx_chn->irq, rx_irq_handler, + IRQF_TRIGGER_HIGH, rx_chn->rx_chan_name, rx_chn); + if (ret) { + dev_err(dev, "failed to request rx irq: %u, err: %d\n", + rx_chn->irq, ret); + return ret; + } + } + } + + return 0; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667621 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 1CAD374413; Sat, 18 May 2024 12:44:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036244; cv=none; b=KMCxzmZCnaaWFLRTf2wqLs7Ce8VniOQZLuquhFFiNFnHYTMGnjpxmuPTwHHYFM3bd5gaVXDhvrNwcGngsEcMhnlt1nbE5r9PgRQmSryFmwi6jP9MkmTKiAHMxpS7VzxWp+/XWkec/Ei0keo2E1IqSjQgVHyZTjYCRoOuWzkNJA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036244; c=relaxed/simple; bh=Vs6W+4IyjuzyntTqW7+e4tPXckOiXjLwmk+wB+VF1lo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=saPxK3VIqJdJ7lTYH0hAqKyaqSuaka6Tm7aNWehNdSGGXAJr1dzo8t0PiFywygk97UqRdS+Y8H7R5saYDR4ylRLG7yUH6seFszmjQw/s51wuoUG6g+GtonG1l6l8om+YNxEF8k9iyUfX8qwrHC6AldBzywg0pzscE8wTW8IWtsU= 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=VCcRArI4; arc=none smtp.client-ip=198.47.23.248 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="VCcRArI4" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChmPf110122; Sat, 18 May 2024 07:43:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036228; bh=qnXuvbGQhwcRpTOr7Phi9+6sH5BnBoym9ZcoMo85CaE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=VCcRArI4/y8pRxu4DKMyqC1EfCjmqENnT/Eq6QMiH7NYOEG4qRNj8Ym9ron9RlPm4 wOp+xVr6NyC5jvZSxs6DT2WMd5M9Z+D8vgsd/NKTnBuWyJJDX8YvB93pY2ZnLK97FZ E3rIHubDpMCo3iiE9XOpVwlYczsBxSMZBvzK0fgE= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChmCT129590 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:48 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:48 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:43:48 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9V041511; Sat, 18 May 2024 07:43:44 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 15/28] net: ethernet: ti: cpsw-proxy-client: add helpers to (de)register MAC Date: Sat, 18 May 2024 18:12:21 +0530 Message-ID: <20240518124234.2671651-16-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add functions "register_mac()" and "deregister_mac()" to register and deregister MAC Address of the network interface corresponding to the Virtual Port with EthFw. Registering the MAC Address with EthFw is necessary to receive unicast traffic directed to the MAC Address. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index b0f0e5db3a74..7af4a89a1847 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1182,6 +1182,53 @@ static int vport_rx_poll(struct napi_struct *napi_rx, int budget) const struct ethtool_ops cpsw_proxy_client_ethtool_ops = { }; +static int register_mac(struct virtual_port *vport) +{ + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct rx_dma_chan *rx_chn = &vport->rx_chans[0]; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + /* Register MAC Address only for RX DMA Channel 0 */ + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_MAC_REGISTER; + req_p->token = vport->port_token; + req_p->rx_flow_base = rx_chn->flow_base; + req_p->rx_flow_offset = rx_chn->flow_offset; + ether_addr_copy(req_p->mac_addr, vport->mac_addr); + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) + dev_err(proxy_priv->dev, "failed to register MAC Address\n"); + + return ret; +} + +static int deregister_mac(struct virtual_port *vport) +{ + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct rx_dma_chan *rx_chn = &vport->rx_chans[0]; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_MAC_DEREGISTER; + req_p->token = vport->port_token; + req_p->rx_flow_base = rx_chn->flow_base; + req_p->rx_flow_offset = rx_chn->flow_offset; + ether_addr_copy(req_p->mac_addr, vport->mac_addr); + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) + dev_err(proxy_priv->dev, "failed to deregister MAC Address\n"); + + return ret; +} + static const struct net_device_ops cpsw_proxy_client_netdev_ops = { }; From patchwork Sat May 18 12:42:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667622 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 1B66847F41; Sat, 18 May 2024 12:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036249; cv=none; b=eAd6rGPku3OqG6HnFadRZMhFVbXqDwQ8302NMYHV/c1oySFYPlQqYRFkmeicMBv11ymrL2KVrWUcjiajIcgeaz3QWZmyVB9s7SSfc428CmOBBjx8eabCBKkM/7ggwXNts4ImaYpmm2nrhylQL3MoFUrJRua420AJ0EUDVEeovJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036249; c=relaxed/simple; bh=xdwj5vF7j12BQeU6xoxU2CMmSC1eDsIBw2vHSiP6cpM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SV15rNsWOBNJVuDvy/1+1RxalfJs7KJYx3aMPIHESD1O8YYOWaQxpDhoTvMU940R3lDzM9+ZTFpZM1wC6uaHLtn8l2aBj+JHdxn0hBBzMPlfAMvpyJsX32v0OtVXVM/KV+l2sSfzoPfNNbuzxlcZeKeCevyA1kmIirhlcHd57xQ= 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=fzmKhZD8; arc=none smtp.client-ip=198.47.19.142 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="fzmKhZD8" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChrOQ055013; Sat, 18 May 2024 07:43:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036233; bh=qil1v3zl/pPDcdHjVC1LhrqtUF1vIpFvRXXcumK5U6Y=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=fzmKhZD82TIDbTU+w8b1mZ5xX/OfeEfwkvCK9bbJaj8ksLiZJAKeMsO/9yy7OIfQa 4DyiduW09fmR0cooEERY6ZJFthwtPDCvyKYrI04qgiGxzSztly8qCwBrDb5+vjjs7X HLnR7cxD7BnRpWUf9JGfGtU6xCuQnuvyyytQgZyY= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChrtP129623 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:53 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:52 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) 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.23 via Frontend Transport; Sat, 18 May 2024 07:43:52 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9W041511; Sat, 18 May 2024 07:43:48 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 16/28] net: ethernet: ti: cpsw-proxy-client: implement and register ndo_open Date: Sat, 18 May 2024 18:12:22 +0530 Message-ID: <20240518124234.2671651-17-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "vport_ndo_open()" and register it as the driver's .ndo_open callback. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 161 ++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 7af4a89a1847..e643ffb9455a 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -131,6 +131,11 @@ struct cpsw_proxy_priv { u32 num_active_rx_chans; }; +#define vport_netdev_to_priv(ndev) \ + ((struct vport_netdev_priv *)netdev_priv(ndev)) +#define vport_ndev_to_vport(ndev) \ + (vport_netdev_to_priv(ndev)->vport) + static int cpsw_proxy_client_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src) { @@ -1229,7 +1234,163 @@ static int deregister_mac(struct virtual_port *vport) return ret; } +static void vport_tx_cleanup(void *data, dma_addr_t desc_dma) +{ + struct tx_dma_chan *tx_chn = data; + struct cppi5_host_desc_t *desc_tx; + struct sk_buff *skb; + void **swdata; + + desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma); + swdata = cppi5_hdesc_get_swdata(desc_tx); + skb = *(swdata); + vport_xmit_free(tx_chn, tx_chn->dev, desc_tx); + + dev_kfree_skb_any(skb); +} + +static void vport_rx_cleanup(void *data, dma_addr_t desc_dma) +{ + struct rx_dma_chan *rx_chn = data; + struct cppi5_host_desc_t *desc_rx; + struct sk_buff *skb; + dma_addr_t buf_dma; + u32 buf_dma_len; + void **swdata; + + desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma); + swdata = cppi5_hdesc_get_swdata(desc_rx); + skb = *swdata; + cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len); + + dma_unmap_single(rx_chn->dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE); + k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); + + dev_kfree_skb_any(skb); +} + +static void vport_stop(struct virtual_port *vport) +{ + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + int i; + + /* shutdown tx channels */ + atomic_set(&vport->tdown_cnt, vport->num_tx_chan); + /* ensure new tdown_cnt value is visible */ + smp_mb__after_atomic(); + reinit_completion(&vport->tdown_complete); + + for (i = 0; i < vport->num_tx_chan; i++) + k3_udma_glue_tdown_tx_chn(vport->tx_chans[i].tx_chan, false); + + i = wait_for_completion_timeout(&vport->tdown_complete, msecs_to_jiffies(1000)); + if (!i) + dev_err(proxy_priv->dev, "tx teardown timeout\n"); + + for (i = 0; i < vport->num_tx_chan; i++) { + tx_chn = &vport->tx_chans[i]; + k3_udma_glue_reset_tx_chn(tx_chn->tx_chan, tx_chn, vport_tx_cleanup); + k3_udma_glue_disable_tx_chn(tx_chn->tx_chan); + napi_disable(&tx_chn->napi_tx); + } + + for (i = 0; i < vport->num_rx_chan; i++) { + rx_chn = &vport->rx_chans[i]; + k3_udma_glue_rx_flow_disable(rx_chn->rx_chan, 0); + /* Need some delay to process RX ring before reset */ + msleep(100); + k3_udma_glue_reset_rx_chn(rx_chn->rx_chan, 0, rx_chn, vport_rx_cleanup, + false); + napi_disable(&rx_chn->napi_rx); + } +} + +static int vport_open(struct virtual_port *vport, netdev_features_t features) +{ + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + struct sk_buff *skb; + u32 i, j; + int ret; + + for (i = 0; i < vport->num_rx_chan; i++) { + rx_chn = &vport->rx_chans[i]; + + for (j = 0; j < rx_chn->num_descs; j++) { + skb = __netdev_alloc_skb_ip_align(NULL, MAX_PACKET_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + ret = vport_rx_push(vport, skb, i); + if (ret < 0) { + netdev_err(vport->ndev, + "cannot submit skb to rx channel\n"); + kfree_skb(skb); + return ret; + } + kmemleak_not_leak(skb); + } + + ret = k3_udma_glue_rx_flow_enable(rx_chn->rx_chan, 0); + if (ret) + return ret; + } + + for (i = 0; i < vport->num_tx_chan; i++) { + tx_chn = &vport->tx_chans[i]; + ret = k3_udma_glue_enable_tx_chn(tx_chn->tx_chan); + if (ret) + return ret; + napi_enable(&tx_chn->napi_tx); + } + + for (i = 0; i < vport->num_rx_chan; i++) { + rx_chn = &vport->rx_chans[i]; + napi_enable(&rx_chn->napi_rx); + } + + return 0; +} + +static int vport_ndo_open(struct net_device *ndev) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + int ret; + u32 i; + + ret = netif_set_real_num_tx_queues(ndev, vport->num_tx_chan); + if (ret) + return ret; + + for (i = 0; i < vport->num_tx_chan; i++) + netdev_tx_reset_queue(netdev_get_tx_queue(ndev, i)); + + ret = vport_open(vport, ndev->features); + if (ret) + return ret; + + ret = register_mac(vport); + if (ret) { + netdev_err(ndev, "failed to register MAC for port: %u\n", + vport->port_id); + vport_stop(vport); + return -EIO; + } + + netif_tx_wake_all_queues(ndev); + netif_carrier_on(ndev); + + dev_info(proxy_priv->dev, "started port %u on interface %s\n", + vport->port_id, ndev->name); + + return 0; +} + static const struct net_device_ops cpsw_proxy_client_netdev_ops = { + .ndo_open = vport_ndo_open, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) From patchwork Sat May 18 12:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667628 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 2F0DE77108; Sat, 18 May 2024 12:44:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036283; cv=none; b=kLL0KfiGviBrMQomZYu71+hR+ylflYPxvd+xcF6OVqkoC0yI1UWPiajYA+gZKVsdVqeHpbD4x8uzHxNYUNCHzB+1IWKyONqNN/YRfLn6/tjbvJ1sS3DbJtiOR6KzN9KE8pK/nJrhtUuqYalp471Nv8UniQgRtraqqeXhy6RvPsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036283; c=relaxed/simple; bh=VLC56HNR23jTHjwxpkGsykAqr5GIFETK1IINEPmsABY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GtAYjjd8otQc9/Y/wX4JJdZCoGp1xBlwO1OP5Q4WEOKsjHNK2zOTw2nRtrfnT/qN00ntunfNXEQ5/pfOUCNSZgD/EUdh3hvpwDRPdFUi43diT64fG2/631z6fhjjmLTm8HHZM2CRD5/uxHQ/zYVarO1a9AdNZ/hNCHwbgMTV32Q= 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=c/XjHcJS; arc=none smtp.client-ip=198.47.19.142 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="c/XjHcJS" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChvhJ055020; Sat, 18 May 2024 07:43:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036237; bh=hJFQNo2lpYUFCMV7UOYccAwKmzAIdF5qSN5A6Wrlods=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=c/XjHcJS0R5fwjSfuZHMpxmVko6CwH0yaiOQOvIlB5oxLKvbh+xtXN4WqQH/t4nmJ h2uuy+Mo4jnUr9zXseNAGmV6Ht4yyrr2Ou+XcJfYvZUz037SkC45rm4GlYv/W8tmTG BZue67Zu2k4UYZkCFe9icMzUpm471OviKO32HdI8= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChviD051598 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:57 -0500 Received: from DLEE105.ent.ti.com (157.170.170.35) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:43:57 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) 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.23 via Frontend Transport; Sat, 18 May 2024 07:43:57 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9X041511; Sat, 18 May 2024 07:43:53 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 17/28] net: ethernet: ti: cpsw-proxy-client: implement and register ndo_stop Date: Sat, 18 May 2024 18:12:23 +0530 Message-ID: <20240518124234.2671651-18-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "vport_ndo_stop()" and register it as the driver's .ndo_stop callback. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index e643ffb9455a..646eab90832c 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1354,6 +1354,28 @@ static int vport_open(struct virtual_port *vport, netdev_features_t features) return 0; } +static int vport_ndo_stop(struct net_device *ndev) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + int ret; + + netif_tx_stop_all_queues(ndev); + netif_carrier_off(ndev); + + ret = deregister_mac(vport); + if (ret) + netdev_err(ndev, "failed to deregister MAC for port %u\n", + vport->port_id); + + vport_stop(vport); + + dev_info(proxy_priv->dev, "stopped port %u on interface %s\n", + vport->port_id, ndev->name); + + return 0; +} + static int vport_ndo_open(struct net_device *ndev) { struct virtual_port *vport = vport_ndev_to_vport(ndev); @@ -1391,6 +1413,7 @@ static int vport_ndo_open(struct net_device *ndev) static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_open = vport_ndo_open, + .ndo_stop = vport_ndo_stop, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) From patchwork Sat May 18 12:42:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667623 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 597EF2BD18; Sat, 18 May 2024 12:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036270; cv=none; b=ZjiA11eCxsfUACA7fYYflrzF4r6/ZvEKtG60cHl6ejFpkbkt9t34ECi+Q2tugKmibppME8FbpEl+DT0u0jUJPRXfy9RJTLgPfgjdy4MWxp4uqPz7Lp3PAazRhyL+P/kWF1j4rjXwLWNN0mdu0606k/Lg61VmepELB/ENC9foo0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036270; c=relaxed/simple; bh=9SoVvIRSrJk77rcTUkgJ+es7gE0GmGp5ZO6Mg6yDizU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UE7eI4SdkdLDMniEU/OtL/t3P0ORElKH49SXpuVS+lLLcIUZs6e24oWefJJzYqHkpq5n+hw5vQx4MGWWtLiMVJz3fBrRd+7KJqReWXD13al+eXzWDYwkr9E4fzDgitrK9cPI001257KnpYbBQ/P0xmKnSN13Jpt+GeEqbCm1Qac= 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=lEB4SdzD; arc=none smtp.client-ip=198.47.23.248 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="lEB4SdzD" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICi23w110141; Sat, 18 May 2024 07:44:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036242; bh=l8Tg5nTpOb8jjPX4ecgYTeUqBjWYnttismzv9xPhAh0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=lEB4SdzDa9aamUcov4y/zj1F0x/X2/F6pZy/Q+Rsopc6PXlsfFf+LNOnybVveiaBe qCs9egCZktnZTVnO71egclmdMdqYyn0yyXhCuXJ2ARGmNNt3LXG+9cWE9xD3V0ZIHe dy7yU1uDdiatMTQ31qTFum3pOhOLInc1+RUBiWDk= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICi2HK129758 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:02 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:02 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) 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.23 via Frontend Transport; Sat, 18 May 2024 07:44:02 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9Y041511; Sat, 18 May 2024 07:43:57 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 18/28] net: ethernet: ti: cpsw-proxy-client: implement and register ndo_start_xmit Date: Sat, 18 May 2024 18:12:24 +0530 Message-ID: <20240518124234.2671651-19-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "vport_ndo_xmit()" and register it as the driver's .ndo_start_xmit callback. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 152 ++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 646eab90832c..7cbe1d4b5112 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1411,9 +1411,161 @@ static int vport_ndo_open(struct net_device *ndev) return 0; } +static netdev_tx_t vport_ndo_xmit(struct sk_buff *skb, struct net_device *ndev) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cppi5_host_desc_t *first_desc, *next_desc, *cur_desc; + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct device *dev = proxy_priv->dev; + struct netdev_queue *netif_txq; + dma_addr_t desc_dma, buf_dma; + struct tx_dma_chan *tx_chn; + void **swdata; + int ret, i, q; + u32 pkt_len; + u32 *psdata; + + /* padding enabled in hw */ + pkt_len = skb_headlen(skb); + + /* Get Queue / TX DMA Channel for the SKB */ + q = skb_get_queue_mapping(skb); + tx_chn = &vport->tx_chans[q]; + netif_txq = netdev_get_tx_queue(ndev, q); + + /* Map the linear buffer */ + buf_dma = dma_map_single(dev, skb->data, pkt_len, + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(dev, buf_dma))) { + dev_err(dev, "Failed to map tx skb buffer\n"); + ndev->stats.tx_errors++; + goto drop_free_skb; + } + + first_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool); + if (!first_desc) { + dev_dbg(dev, "Failed to allocate descriptor\n"); + dma_unmap_single(dev, buf_dma, pkt_len, DMA_TO_DEVICE); + goto busy_stop_q; + } + + cppi5_hdesc_init(first_desc, CPPI5_INFO0_HDESC_EPIB_PRESENT, + PS_DATA_SIZE); + cppi5_desc_set_pktids(&first_desc->hdr, 0, 0x3FFF); + cppi5_hdesc_set_pkttype(first_desc, 0x7); + /* target port has to be 0 */ + cppi5_desc_set_tags_ids(&first_desc->hdr, 0, vport->port_type); + + cppi5_hdesc_attach_buf(first_desc, buf_dma, pkt_len, buf_dma, pkt_len); + swdata = cppi5_hdesc_get_swdata(first_desc); + *(swdata) = skb; + psdata = cppi5_hdesc_get_psdata(first_desc); + + /* HW csum offload if enabled */ + psdata[2] = 0; + if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { + unsigned int cs_start, cs_offset; + + cs_start = skb_transport_offset(skb); + cs_offset = cs_start + skb->csum_offset; + /* HW numerates bytes starting from 1 */ + psdata[2] = ((cs_offset + 1) << 24) | + ((cs_start + 1) << 16) | (skb->len - cs_start); + dev_dbg(dev, "%s tx psdata:%#x\n", __func__, psdata[2]); + } + + if (!skb_is_nonlinear(skb)) + goto done_tx; + + dev_dbg(dev, "fragmented SKB\n"); + + /* Handle the case where skb is fragmented in pages */ + cur_desc = first_desc; + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { + skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; + u32 frag_size = skb_frag_size(frag); + + next_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool); + if (!next_desc) { + dev_err(dev, "Failed to allocate descriptor\n"); + goto busy_free_descs; + } + + buf_dma = skb_frag_dma_map(dev, frag, 0, frag_size, + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(dev, buf_dma))) { + dev_err(dev, "Failed to map tx skb page\n"); + k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc); + ndev->stats.tx_errors++; + goto drop_free_descs; + } + + cppi5_hdesc_reset_hbdesc(next_desc); + cppi5_hdesc_attach_buf(next_desc, + buf_dma, frag_size, buf_dma, frag_size); + + desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, + next_desc); + cppi5_hdesc_link_hbdesc(cur_desc, desc_dma); + + pkt_len += frag_size; + cur_desc = next_desc; + } + WARN_ON(pkt_len != skb->len); + +done_tx: + skb_tx_timestamp(skb); + + /* report bql before sending packet */ + dev_dbg(dev, "push 0 %d Bytes\n", pkt_len); + + netdev_tx_sent_queue(netif_txq, pkt_len); + + cppi5_hdesc_set_pktlen(first_desc, pkt_len); + desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, first_desc); + ret = k3_udma_glue_push_tx_chn(tx_chn->tx_chan, first_desc, desc_dma); + if (ret) { + dev_err(dev, "can't push desc %d\n", ret); + /* inform bql */ + netdev_tx_completed_queue(netif_txq, 1, pkt_len); + ndev->stats.tx_errors++; + goto drop_free_descs; + } + + if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) < MAX_SKB_FRAGS) { + netif_tx_stop_queue(netif_txq); + /* Barrier, so that stop_queue visible to other cpus */ + smp_mb__after_atomic(); + dev_dbg(dev, "netif_tx_stop_queue %d\n", q); + + /* re-check for smp */ + if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >= + MAX_SKB_FRAGS) { + netif_tx_wake_queue(netif_txq); + dev_dbg(dev, "netif_tx_wake_queue %d\n", q); + } + } + + return NETDEV_TX_OK; + +drop_free_descs: + vport_xmit_free(tx_chn, dev, first_desc); +drop_free_skb: + ndev->stats.tx_dropped++; + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + +busy_free_descs: + vport_xmit_free(tx_chn, dev, first_desc); +busy_stop_q: + netif_tx_stop_queue(netif_txq); + return NETDEV_TX_BUSY; +} + static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_open = vport_ndo_open, .ndo_stop = vport_ndo_stop, + .ndo_start_xmit = vport_ndo_xmit, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) From patchwork Sat May 18 12:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667624 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 86BEC4E1B3; Sat, 18 May 2024 12:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036273; cv=none; b=ibQ5MfKvZZ5WWPh51rUCWGsfi4sbUSnGaZkeZHmLOSgL6J5ePSsaVqCFykAl9bk7YgcpZvDC1z5yDHUpOIAi83Bp29UEQLkvuv7QyWvzuTGbz0AwtgUSt6CUwFdEj5k0sAD1xsPfRABgyuybr4p8gBjBHez4p/mm7JeB91a8KkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036273; c=relaxed/simple; bh=rPAEvAm+p/u2nLjjrVskxSKkBnJOn5mvraIDQIwPdNk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mb8qtEL9m+WshATSzmNQKFkxZWUddEhXV1m3u9vA6JzpDkxSc9bAhb6S3ifHJsnzUkuvnAZc8bY7AKsiqvO8koE2+ncunppKCVaSzIg+JW1OM/tGW0F5AmjVEVNd2Zxx2QPgNLGqGkYHUkwdnN4nh858xvf8dKAmP1rXWdEotIA= 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=EXKhI5PA; arc=none smtp.client-ip=198.47.19.141 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="EXKhI5PA" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICi6ud002848; Sat, 18 May 2024 07:44:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036246; bh=MNJFVc6G40L2FZxmk2pnAhflXSN9ugTwXZFFV792Umg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=EXKhI5PA+wgkTcwJxwjHmG4ovXaf5ApqyP9176P/w5RARIJwVsQe01bT/n3jFStn+ Cq+Q4i12OdYKaJfH5ZX5cKS3OmvPTdiDUHEWsVqOQI9iNpPHVpMWF2qEBvnwKGMq+n n7d8Fm4Bc/BII7njX22HcNmCAKZEiUgqdL2/+BPI= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICi6Jp051768 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:06 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:06 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:06 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9Z041511; Sat, 18 May 2024 07:44:02 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 19/28] net: ethernet: ti: cpsw-proxy-client: implement and register ndo_get_stats64 Date: Sat, 18 May 2024 18:12:25 +0530 Message-ID: <20240518124234.2671651-20-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "vport_ndo_get_stats()" and register it as the driver's .ndo_get_stats64 callback. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 7cbe1d4b5112..6886557aa2a1 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1562,10 +1562,45 @@ static netdev_tx_t vport_ndo_xmit(struct sk_buff *skb, struct net_device *ndev) return NETDEV_TX_BUSY; } +static void vport_ndo_get_stats(struct net_device *ndev, + struct rtnl_link_stats64 *stats) +{ + struct vport_netdev_priv *ndev_priv = netdev_priv(ndev); + unsigned int start; + int cpu; + + for_each_possible_cpu(cpu) { + struct vport_netdev_stats *cpu_stats; + u64 rx_packets; + u64 rx_bytes; + u64 tx_packets; + u64 tx_bytes; + + cpu_stats = per_cpu_ptr(ndev_priv->stats, cpu); + do { + start = u64_stats_fetch_begin(&cpu_stats->syncp); + rx_packets = cpu_stats->rx_packets; + rx_bytes = cpu_stats->rx_bytes; + tx_packets = cpu_stats->tx_packets; + tx_bytes = cpu_stats->tx_bytes; + } while (u64_stats_fetch_retry(&cpu_stats->syncp, start)); + + stats->rx_packets += rx_packets; + stats->rx_bytes += rx_bytes; + stats->tx_packets += tx_packets; + stats->tx_bytes += tx_bytes; + } + + stats->rx_errors = ndev->stats.rx_errors; + stats->rx_dropped = ndev->stats.rx_dropped; + stats->tx_dropped = ndev->stats.tx_dropped; +} + static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_open = vport_ndo_open, .ndo_stop = vport_ndo_stop, .ndo_start_xmit = vport_ndo_xmit, + .ndo_get_stats64 = vport_ndo_get_stats, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) From patchwork Sat May 18 12:42:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667625 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 350922BD18; Sat, 18 May 2024 12:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036275; cv=none; b=APU9NDSOxQvcH15bkiuNpBlgwgiH9tZnZT2+sUK18eQLqmYUiqZurQSzzGjjozUXQptj9Ksc09XntKyniTy0wnQzSazgfnBt8P6yFbllO7hklhIbD+Y5Dd27gx3x4FcDnxnhm5pp+W4D12cmUntoHkZ074mbKlfqrx0b8/G/YV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036275; c=relaxed/simple; bh=trHlkmVueSpzbMIM48Qj2NuKuHblG4sExkmhZdZ/kaI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g56QhodFpfkbw6RUxJAQH0LINVplluOVbHahO5IYELapQ/RsIrGswieQbYW+dKX2sSadUMpRpyLBFCBkUtsXzq0UdTMufGkICNPHsoaEzkwxZt+nS9gO89zU4Q8eyGgbIpZHQjkjFKBJH+pQAm2lFU5xzeQHKqb7TzgtQgB7ztk= 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=tZTfMiNS; arc=none smtp.client-ip=198.47.19.142 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="tZTfMiNS" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICiBSc055039; Sat, 18 May 2024 07:44:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036251; bh=fbRzf+uBA4zF2HTBz3dtEjKx1tnV87uTG84AC6BwYCA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tZTfMiNSk6dmT3/UD6ncrA53raA4xsXFNJiKHUUvltsfsAnfm3HR1Op0QmPdYRsHM NLDf4tmz7nOkZH8paPGU1Rvs3+lmBtUx32wWchCz6ohXmc8AVVUpa1ShR+QuJx4Lx9 SgprH31adR8ciUvP2giEay0jZGAee8ft0oQtIka4= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICiBDK017753 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:11 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:11 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:11 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9a041511; Sat, 18 May 2024 07:44:07 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 20/28] net: ethernet: ti: cpsw-proxy-client: implement and register ndo_tx_timeout Date: Sat, 18 May 2024 18:12:26 +0530 Message-ID: <20240518124234.2671651-21-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the function "vport_ndo_tx_timeout()" and register it as the driver's .ndo_tx_timeout callback. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 6886557aa2a1..92a014e83c6c 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1596,11 +1596,37 @@ static void vport_ndo_get_stats(struct net_device *ndev, stats->tx_dropped = ndev->stats.tx_dropped; } +static void vport_ndo_tx_timeout(struct net_device *ndev, unsigned int txqueue) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct netdev_queue *netif_txq; + struct tx_dma_chan *tx_chn; + unsigned long trans_start; + + /* process every txq */ + netif_txq = netdev_get_tx_queue(ndev, txqueue); + tx_chn = &vport->tx_chans[txqueue]; + trans_start = READ_ONCE(netif_txq->trans_start); + + netdev_err(ndev, "txq:%d DRV_XOFF: %d tmo: %u dql_avail:%d free_desc:%zu\n", + txqueue, netif_tx_queue_stopped(netif_txq), + jiffies_to_msecs(jiffies - trans_start), + dql_avail(&netif_txq->dql), + k3_cppi_desc_pool_avail(tx_chn->desc_pool)); + + if (netif_tx_queue_stopped(netif_txq)) { + /* try to recover if it was stopped by driver */ + txq_trans_update(netif_txq); + netif_tx_wake_queue(netif_txq); + } +} + static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_open = vport_ndo_open, .ndo_stop = vport_ndo_stop, .ndo_start_xmit = vport_ndo_xmit, .ndo_get_stats64 = vport_ndo_get_stats, + .ndo_tx_timeout = vport_ndo_tx_timeout, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) From patchwork Sat May 18 12:42:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667626 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 F0F0576049; Sat, 18 May 2024 12:44:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036277; cv=none; b=crgMTlgOufKc4qBzeBLRNJUVQz/wHmhTb1sBaRmf/tv6jJxbQ0Mur20GA42Evbvpa7HUNiXQtNZbuUdfqlkoArmVMAE5+kXWbX4JSX3MqueeYvtSCLIDUTHFV5NrSsE3umS2F1/cX9sMc2sPg0MfdrBXbqPuiarxgCArecnANpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036277; c=relaxed/simple; bh=nU0E2Hu4Vd6tBUu/2Y2ZBPL4LsgszqmUvt7C5YBjkHs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ujWv+ld5id8LjIXxMKy7wW6DPjPj2Hm53zpegKm02Bmkx0/iAORJJRzsygHmsSDy8n9VOqIN7bCiHJbBUdvcNQwPc8ss3iqL0Q2JiBuZ17pUbr1yYXEWlTN9J5P4kxqH2kKQVXD+mG02tlxF+fycc326C3ir21ATcCcsboqJdnQ= 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=CmexDeL3; arc=none smtp.client-ip=198.47.23.248 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="CmexDeL3" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICiG14110164; Sat, 18 May 2024 07:44:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036256; bh=ORTd8VgUuVAq8aYkX1Htufqln1Jye9rbO8cQmwKmnTU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=CmexDeL3dMGrX7cXKw77q1CXfpX2mOC0uO1O/+6jw/J33ORtKgbdUjeBHPiYXjWRv VkSgOGVYeBA1HHKXPePJia/lRCvtzz5AcXFSBsOJgjUa5PeU4llSm3Ccr4GYJcpAqS kjuCBW+x2AcE6ZRIfddc6aa/2rvWxvbpZQvtvA28= Received: from DLEE110.ent.ti.com (dlee110.ent.ti.com [157.170.170.21]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICiG4i017802 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:16 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:15 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:15 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9b041511; Sat, 18 May 2024 07:44:11 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 21/28] net: ethernet: ti: cpsw-proxy-client: register ndo_validate/ndo_set_mac_addr Date: Sat, 18 May 2024 18:12:27 +0530 Message-ID: <20240518124234.2671651-22-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Register "eth_validate_addr()" as the .ndo_validate_addr callback. Register "eth_mac_addr()" as the .ndo_set_mac_address callback. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 92a014e83c6c..be42b02c3894 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1627,6 +1627,8 @@ static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_start_xmit = vport_ndo_xmit, .ndo_get_stats64 = vport_ndo_get_stats, .ndo_tx_timeout = vport_ndo_tx_timeout, + .ndo_validate_addr = eth_validate_addr, + .ndo_set_mac_address = eth_mac_addr, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) From patchwork Sat May 18 12:42:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667627 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (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 EEF55770FA; Sat, 18 May 2024 12:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036281; cv=none; b=qQfgq1od/sQ+qujdaPmAY0RkoqpikRRB6Ry7oONVlBOEVWtTywjbFfYK0f9AC+gOUQq/5/dqAcZ7LM7LBR02cV4Vc4ahtufilTuVrIMVgaUSGU7g7rb/ezUWckHSdrp8URepgoQPqUXTwwdWp7+s70zpfH74FN0Ebs+AE6ybyW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036281; c=relaxed/simple; bh=TkZ8YCzGf3L4/woShJhNStGq6ph3UlMnPIzsSyhl65U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LLxtHjJwS/u923/lxbDxiYARoWKwzXdoXNqxCBBrk6nBVK7Apj6qLyuSMi0e1mDNjSTQ2Hakv99CubinPJin/6qCarBjnL0Kt57yBqs3VbGyRiLSCR8p+eZbkcYdd+Jk3HJtMZJQb7X6l8jCobffrR9g63+82rfQ/9EoNu2jjl8= 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=fexKLyd8; arc=none smtp.client-ip=198.47.23.249 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="fexKLyd8" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICiK5o017356; Sat, 18 May 2024 07:44:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036260; bh=bhrgTDMVzI0dP8d/KQcIUJP6wdPok2F5QjLOlXwW5rY=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=fexKLyd8OlzpsoOiCIHCWanAWn6FgEqgJxW9JEEkeDcJbDPxC7oMezMsQt4DoUe2M za+kMTvGs69pY1hUWwdwgvWDkykQ5rkjFX5HxjniZVIIHlih+qVSFb4vfZtceLmFsS sK9nu5OtJ9APr88pxlv4bhQ+IXeRgwZy1cUYHXSU= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICiKAF130101 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:20 -0500 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:20 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:20 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9c041511; Sat, 18 May 2024 07:44:16 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 22/28] net: ethernet: ti: cpsw-proxy-client: implement .get_link ethtool op Date: Sat, 18 May 2024 18:12:28 +0530 Message-ID: <20240518124234.2671651-23-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the "vport_get_link()" function and register it as the driver's .get_link ethtool_ops callback. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index be42b02c3894..450fc183eaac 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -284,6 +284,7 @@ static int create_request_message(struct cpsw_proxy_req_params *req_params) case ETHFW_ALLOC_MAC: case ETHFW_VIRT_PORT_DETACH: case ETHFW_VIRT_PORT_INFO: + case ETHFW_VIRT_PORT_LINK_STATUS: common_req_msg = (struct common_request_message *)msg; req_msg_hdr = &common_req_msg->request_msg_hdr; break; @@ -1184,7 +1185,38 @@ static int vport_rx_poll(struct napi_struct *napi_rx, int budget) return num_rx; } +static u32 vport_get_link(struct net_device *ndev) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct port_link_status_response *pls_resp; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + bool link_up; + int ret; + + if (vport->port_type != VIRT_MAC_ONLY_PORT) + return ethtool_op_get_link(ndev); + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_VIRT_PORT_LINK_STATUS; + req_p->token = vport->port_token; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) { + netdev_err(ndev, "failed to get link status\n"); + /* Assume that link is down if status is unknown */ + return 0; + } + pls_resp = (struct port_link_status_response *)&resp_msg; + link_up = pls_resp->link_up; + + return link_up; +} + const struct ethtool_ops cpsw_proxy_client_ethtool_ops = { + .get_link = vport_get_link, }; static int register_mac(struct virtual_port *vport) From patchwork Sat May 18 12:42:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667629 X-Patchwork-Delegate: kuba@kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 23DE777118; Sat, 18 May 2024 12:44:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036284; cv=none; b=B0e8ZtkwBsXyKQypze4rIxRfd2cNJp65o4h6TTK8YAau1JXxViLoJ+MxPSgBbHSxstyIMlZW40l1HSnMkQg6YqPIDUq2NNxlOIbqXBf5h1b0YxIq3mTBIhqCogdfpJsjVq7gXMC51HYtXl4G75aL/ZuIGWXqNITY7xsUP74MWdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036284; c=relaxed/simple; bh=9ikqwUURIJXjmOX0YEggmPaxUl5VbN4VNsrVNZ2xog0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NY3XN1LZR0PMrf1nPYApuchJo6AkXyvZQtDmAshdYPg2hheAJyECMW2aN/p7x5pFZUt9PpvRHAasjyGFuQXfusUOThDIWA9qeO2KDx1vyrHdd+ADAZHA3ENB5i/vsp5dC5/38tUbZ3UVc6qvmDZQyuAPuBL+cvGUGhyqiD/Yftk= 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=oy4bA/9i; arc=none smtp.client-ip=198.47.23.248 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="oy4bA/9i" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICiPge110184; Sat, 18 May 2024 07:44:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036265; bh=lP4vcrz4edMAL+hEj61bfOYsm3giMknUDGXG+pKdxIQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=oy4bA/9irURetstA9Fc5yO+3I4DC1KGhldjpzWdHlZ+6kWzxUjtNQD6XeLlzLCkup 0XhKmadGTcBioI/dBHjnZaUPwJ9uCE/byMKJ5B+AzytVc0CnRwG57KU4vyxCgDNCzu Aeygm4F0CQmsKNv7kCXRdmeTARvh+sN8dk7HimgY= Received: from DLEE102.ent.ti.com (dlee102.ent.ti.com [157.170.170.32]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICiPNs052100 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:25 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:25 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:25 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9d041511; Sat, 18 May 2024 07:44:20 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 23/28] net: ethernet: ti: cpsw-proxy-client: add sw tx/rx irq coalescing Date: Sat, 18 May 2024 18:12:29 +0530 Message-ID: <20240518124234.2671651-24-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add coalescing support for the interrupts corresponding to the TX and RX DMA Channels using hrtimer. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 57 +++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 450fc183eaac..408c9f78c059 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -58,13 +58,16 @@ struct rx_dma_chan { struct k3_cppi_desc_pool *desc_pool; struct k3_udma_glue_rx_channel *rx_chan; struct napi_struct napi_rx; + struct hrtimer rx_hrtimer; u32 rel_chan_idx; u32 flow_base; u32 flow_offset; u32 thread_id; u32 num_descs; unsigned int irq; + unsigned long rx_pace_timeout; char rx_chan_name[CHAN_NAME_LEN]; + bool rx_irq_disabled; bool in_use; }; @@ -74,10 +77,12 @@ struct tx_dma_chan { struct k3_cppi_desc_pool *desc_pool; struct k3_udma_glue_tx_channel *tx_chan; struct napi_struct napi_tx; + struct hrtimer tx_hrtimer; u32 rel_chan_idx; u32 thread_id; u32 num_descs; unsigned int irq; + unsigned long tx_pace_timeout; char tx_chan_name[CHAN_NAME_LEN]; bool in_use; }; @@ -996,8 +1001,15 @@ static int vport_tx_poll(struct napi_struct *napi_tx, int budget) if (num_tx >= budget) return budget; - if (napi_complete_done(napi_tx, num_tx)) - enable_irq(tx_chn->irq); + if (napi_complete_done(napi_tx, num_tx)) { + if (unlikely(tx_chn->tx_pace_timeout && !tdown)) { + hrtimer_start(&tx_chn->tx_hrtimer, + ns_to_ktime(tx_chn->tx_pace_timeout), + HRTIMER_MODE_REL_PINNED); + } else { + enable_irq(tx_chn->irq); + } + } return 0; } @@ -1179,12 +1191,38 @@ static int vport_rx_poll(struct napi_struct *napi_rx, int budget) num_rx++; } - if (num_rx < budget && napi_complete_done(napi_rx, num_rx)) - enable_irq(rx_chn->irq); + if (num_rx < budget && napi_complete_done(napi_rx, num_rx)) { + if (rx_chn->rx_irq_disabled) { + rx_chn->rx_irq_disabled = false; + if (unlikely(rx_chn->rx_pace_timeout)) { + hrtimer_start(&rx_chn->rx_hrtimer, + ns_to_ktime(rx_chn->rx_pace_timeout), + HRTIMER_MODE_REL_PINNED); + } else { + enable_irq(rx_chn->irq); + } + } + } return num_rx; } +static enum hrtimer_restart vport_tx_timer_cb(struct hrtimer *timer) +{ + struct tx_dma_chan *tx_chn = container_of(timer, struct tx_dma_chan, tx_hrtimer); + + enable_irq(tx_chn->irq); + return HRTIMER_NORESTART; +} + +static enum hrtimer_restart vport_rx_timer_cb(struct hrtimer *timer) +{ + struct rx_dma_chan *rx_chn = container_of(timer, struct rx_dma_chan, rx_hrtimer); + + enable_irq(rx_chn->irq); + return HRTIMER_NORESTART; +} + static u32 vport_get_link(struct net_device *ndev) { struct virtual_port *vport = vport_ndev_to_vport(ndev); @@ -1326,6 +1364,7 @@ static void vport_stop(struct virtual_port *vport) k3_udma_glue_reset_tx_chn(tx_chn->tx_chan, tx_chn, vport_tx_cleanup); k3_udma_glue_disable_tx_chn(tx_chn->tx_chan); napi_disable(&tx_chn->napi_tx); + hrtimer_cancel(&tx_chn->tx_hrtimer); } for (i = 0; i < vport->num_rx_chan; i++) { @@ -1336,6 +1375,7 @@ static void vport_stop(struct virtual_port *vport) k3_udma_glue_reset_rx_chn(rx_chn->rx_chan, 0, rx_chn, vport_rx_cleanup, false); napi_disable(&rx_chn->napi_rx); + hrtimer_cancel(&rx_chn->rx_hrtimer); } } @@ -1381,6 +1421,10 @@ static int vport_open(struct virtual_port *vport, netdev_features_t features) for (i = 0; i < vport->num_rx_chan; i++) { rx_chn = &vport->rx_chans[i]; napi_enable(&rx_chn->napi_rx); + if (rx_chn->rx_irq_disabled) { + rx_chn->rx_irq_disabled = false; + enable_irq(rx_chn->irq); + } } return 0; @@ -1708,11 +1752,15 @@ static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port * for (i = 0; i < vport->num_tx_chan; i++) { tx_chn = &vport->tx_chans[i]; netif_napi_add_tx(vport->ndev, &tx_chn->napi_tx, vport_tx_poll); + hrtimer_init(&tx_chn->tx_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); + tx_chn->tx_hrtimer.function = &vport_tx_timer_cb; } for (i = 0; i < vport->num_rx_chan; i++) { rx_chn = &vport->rx_chans[i]; netif_napi_add(vport->ndev, &rx_chn->napi_rx, vport_rx_poll); + hrtimer_init(&rx_chn->rx_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); + rx_chn->rx_hrtimer.function = &vport_rx_timer_cb; } ret = register_netdev(vport->ndev); @@ -1771,6 +1819,7 @@ static irqreturn_t rx_irq_handler(int irq, void *dev_id) { struct rx_dma_chan *rx_chn = dev_id; + rx_chn->rx_irq_disabled = true; disable_irq_nosync(irq); napi_schedule(&rx_chn->napi_rx); From patchwork Sat May 18 12:42:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667630 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 12B0C78C70; Sat, 18 May 2024 12:44:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036286; cv=none; b=U81eGauAy7tyaOrT7WtPorWYYkPMs17h4fZidPo2QtnvZg1dli1qFwNzTIT4oWXbIIHQQAsy7zg7UNLoJ9+3SZcM4uDFT0Zq90FsAbCC1i64+jlVj9dG/AXeE2hVU/pBBR5M/jL+exAYzSQdmZRKHKo1rEj2PL3G5ADgS3O9Z+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036286; c=relaxed/simple; bh=i5Rd3pPxPnww42sxf22pzP0ZZOno9q5S9lWTpp/rxM4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A1OSDdEpg2pEOgJCzZpD6vtraF1QsZIzL81tPsa7h1WMlDnwbr8glj0kpMRebjVBbDUAr3DX2wWcNOYzNj6rWOFuBh6B9ufZdOYmeSys0u0dOsf6mnr/+8ikKa5Y8It2lUx/VBLhedrv8riU4QqLtZO8+m99+hlwvkEW+qci0l8= 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=jMB/r8r2; arc=none smtp.client-ip=198.47.19.141 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="jMB/r8r2" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICiTgX002883; Sat, 18 May 2024 07:44:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036269; bh=QVXXevX2p35Tc0MKEUXQO7615FHZ3IeMDwxKByj5l54=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=jMB/r8r2dtWaVBFxKclXHnSN+aMzyXYmIohPK275YdeF5dMkBqKxpTQ+93MTFqr5w SYJ6wUJyvtNr/53azwxvkvOEaBHhEtwpqhNMLWcrgFWN7aRC0q2FMd6YmfQo/CNFPG 6nOzjQnKwwlEVunXsNfMBFyyquDlihffub5KiDSI= Received: from DLEE110.ent.ti.com (dlee110.ent.ti.com [157.170.170.21]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICiTQH130389 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:29 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:29 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:29 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9e041511; Sat, 18 May 2024 07:44:25 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 24/28] net: ethernet: ti: cpsw-proxy-client: export coalescing support Date: Sat, 18 May 2024 18:12:30 +0530 Message-ID: <20240518124234.2671651-25-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Export coalescing support via ethtool ops. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 86 +++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 408c9f78c059..b42be0d389b8 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -1253,8 +1253,94 @@ static u32 vport_get_link(struct net_device *ndev) return link_up; } +static int vport_get_coal(struct net_device *ndev, struct ethtool_coalesce *coal, + struct kernel_ethtool_coalesce *kernel_coal, + struct netlink_ext_ack *extack) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + + coal->tx_coalesce_usecs = vport->tx_chans[0].tx_pace_timeout / 1000; + coal->rx_coalesce_usecs = vport->rx_chans[0].rx_pace_timeout / 1000; + return 0; +} + +static int vport_set_coal(struct net_device *ndev, struct ethtool_coalesce *coal, + struct kernel_ethtool_coalesce *kernel_coal, + struct netlink_ext_ack *extack) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct device *dev = proxy_priv->dev; + u32 i; + + if (coal->tx_coalesce_usecs && coal->tx_coalesce_usecs < 20) { + dev_err(dev, "TX coalesce must be at least 20 usecs. Defaulting to 20 usecs\n"); + coal->tx_coalesce_usecs = 20; + } + + if (coal->rx_coalesce_usecs && coal->rx_coalesce_usecs < 20) { + dev_err(dev, "RX coalesce must be at least 20 usecs. Defaulting to 20 usecs\n"); + coal->rx_coalesce_usecs = 20; + } + + /* Since it is possible to set pacing values per TX and RX queue, if per queue value is + * not specified, apply it to all available TX and RX queues. + */ + + for (i = 0; i < vport->num_tx_chan; i++) + vport->tx_chans[i].tx_pace_timeout = coal->tx_coalesce_usecs * 1000; + + for (i = 0; i < vport->num_rx_chan; i++) + vport->rx_chans[i].rx_pace_timeout = coal->rx_coalesce_usecs * 1000; + + return 0; +} + +static int vport_get_per_q_coal(struct net_device *ndev, u32 q, + struct ethtool_coalesce *coal) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + + if (q >= vport->num_tx_chan || q >= vport->num_rx_chan) + return -EINVAL; + + coal->tx_coalesce_usecs = vport->tx_chans[q].tx_pace_timeout / 1000; + coal->rx_coalesce_usecs = vport->rx_chans[q].rx_pace_timeout / 1000; + + return 0; +} + +static int vport_set_per_q_coal(struct net_device *ndev, u32 q, + struct ethtool_coalesce *coal) +{ struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct device *dev = vport->proxy_priv->dev; + + if (q >= vport->num_tx_chan || q >= vport->num_rx_chan) + return -EINVAL; + + if (coal->tx_coalesce_usecs && coal->tx_coalesce_usecs < 20) { + dev_err(dev, "TX coalesce must be at least 20 usecs. Defaulting to 20 usecs\n"); + coal->tx_coalesce_usecs = 20; + } + + if (coal->rx_coalesce_usecs && coal->rx_coalesce_usecs < 20) { + dev_err(dev, "RX coalesce must be at least 20 usecs. Defaulting to 20 usecs\n"); + coal->rx_coalesce_usecs = 20; + } + + vport->tx_chans[q].tx_pace_timeout = coal->tx_coalesce_usecs * 1000; + vport->rx_chans[q].rx_pace_timeout = coal->rx_coalesce_usecs * 1000; + + return 0; +} + const struct ethtool_ops cpsw_proxy_client_ethtool_ops = { .get_link = vport_get_link, + .supported_coalesce_params = ETHTOOL_COALESCE_USECS, + .get_coalesce = vport_get_coal, + .set_coalesce = vport_set_coal, + .get_per_queue_coalesce = vport_get_per_q_coal, + .set_per_queue_coalesce = vport_set_per_q_coal, }; static int register_mac(struct virtual_port *vport) From patchwork Sat May 18 12:42:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667631 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 96C0A78C90; Sat, 18 May 2024 12:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036288; cv=none; b=I+PBPip7LOcGA7GJ8dPvVlDj7YRrHHnIEJHIAiMO/K7EZpNe7MHiveS/NBGhZZSiOghVuE2PDehOG005yzgE1V38Bkke8mLfXc1E8kyErvJ16O/rYrzIno+ntZnn7yRsLrqDBQyPd8MBZdJvXQM79NnFyBdSCdY7+pVUnoTw26M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036288; c=relaxed/simple; bh=JeL3kwHWA27IQ2xJNUr2/T733iTEUzbEQ8JMyAkCjw8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H+UXLwJpgoQFT/REp8UocdPAzP6bd00QWlDvt8mEC8Ix3z6WErwt4DF5iDoydcxWozchJI0SP+RVVPiaHeRd9/bGvjN0JMjbkB5ZhqVMMwPduZOI2ZnMzFet5NVKtCQ64fQsGTwZqjNhp1x4CTlGey+pT7NHS83+fScEy3358bM= 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=PUDyOwSh; arc=none smtp.client-ip=198.47.19.142 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="PUDyOwSh" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICiYIA055074; Sat, 18 May 2024 07:44:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036274; bh=0ukhBT1ImvjnHFh3BaA3f4C26i8afBnuBDClD1lDvQc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=PUDyOwShCQFYYmfFIrHVZtG2mkkAWFSWPitVmTUF4wTB5oefF8sv8BC714Jfr53jF pxMtCd/+n4eDD7gvW9XURjsBkLFwyGQ0H4IeeqRDadCKJtQJG2INNbTSmB/B2No1kK fntnmtnEEQP6QWhZieVsMMM1ZZi8kNFakbILRKOU= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICiYl9005092 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:34 -0500 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:34 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) 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.23 via Frontend Transport; Sat, 18 May 2024 07:44:34 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9f041511; Sat, 18 May 2024 07:44:30 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 25/28] net: ethernet: ti: cpsw-proxy-client: add helpers to (de)register IPv4 Date: Sat, 18 May 2024 18:12:31 +0530 Message-ID: <20240518124234.2671651-26-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add functions "register_ipv4()" and "deregister_ipv4()" to register and deregister IPv4 Address of the network interface corresponding to the Virtual Switch Port with EthFw. Registering the IPv4 Address with EthFw is necessary in the case of the Virtual Switch Port. This is because all Broadcast packets received on any of the Switch Ports are consumed by EthFw. This includes the ARP request for the IPv4 Address of the network interface corresponding to the Virtual Switch Port as well. Thus, registering the IPv4 Address with EthFw results in EthFw responding to the ARP request thereby enabling subsequent Unicast communication with the network interface corresponding to the Virtual Switch Port. Add a notifier block to register/deregister the IPv4 address with EthFw corresponding to interface state changes as well as IPv4 Address changes. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 121 ++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index b42be0d389b8..9ede3e584a06 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,7 @@ struct virtual_port { struct rx_dma_chan *rx_chans; struct tx_dma_chan *tx_chans; struct completion tdown_complete; + struct notifier_block inetaddr_nb; enum virtual_port_type port_type; atomic_t tdown_cnt; u32 port_id; @@ -113,6 +115,7 @@ struct virtual_port { u32 port_features; u32 num_rx_chan; u32 num_tx_chan; + u8 ipv4_addr[ETHFW_IPV4ADDRLEN]; u8 mac_addr[ETH_ALEN]; bool mac_in_use; }; @@ -1952,6 +1955,124 @@ static int register_dma_irq_handlers(struct cpsw_proxy_priv *proxy_priv) return 0; } +static int register_ipv4(struct virtual_port *vport) +{ + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct device *dev = proxy_priv->dev; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_IPv4_REGISTER; + memcpy(req_p->ipv4_addr, vport->ipv4_addr, ETHFW_IPV4ADDRLEN); + ether_addr_copy(req_p->mac_addr, vport->mac_addr); + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + + if (ret) { + dev_err(dev, "failed to register IPv4 Address err: %d\n", ret); + return -EIO; + } + + return 0; +} + +static int deregister_ipv4(struct virtual_port *vport) +{ + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct device *dev = proxy_priv->dev; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_IPv4_DEREGISTER; + memcpy(req_p->ipv4_addr, vport->ipv4_addr, ETHFW_IPV4ADDRLEN); + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + + if (ret) { + dev_err(dev, "failed to deregister IPv4 Address err: %d\n", ret); + return -EIO; + } + + return 0; +} + +static bool cpsw_proxy_client_check(const struct net_device *ndev) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + + return ndev->netdev_ops == &cpsw_proxy_client_netdev_ops && + vport->port_type == VIRT_SWITCH_PORT; +} + +static int cpsw_proxy_client_inetaddr(struct notifier_block *unused, + unsigned long event, void *ptr) +{ + struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; + struct virtual_port *vport; + struct net_device *ndev; + int ret = 0; + + ndev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; + if (!ndev) + return NOTIFY_DONE; + + if (!cpsw_proxy_client_check(ndev)) + return NOTIFY_DONE; + + vport = vport_ndev_to_vport(ndev); + memcpy(vport->ipv4_addr, &ifa->ifa_address, ETHFW_IPV4ADDRLEN); + + switch (event) { + case NETDEV_UP: + case NETDEV_CHANGEADDR: + ret = register_ipv4(vport); + if (ret) + netdev_err(ndev, "IPv4 register failed: %d\n", ret); + break; + + case NETDEV_DOWN: + case NETDEV_PRE_CHANGEADDR: + ret = deregister_ipv4(vport); + if (ret) + netdev_err(ndev, "IPv4 deregister failed: %d\n", ret); + break; + } + + return notifier_from_errno(ret); +} + +static void unregister_notifiers(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + if (vport->port_type == VIRT_SWITCH_PORT) + unregister_inetaddr_notifier(&vport->inetaddr_nb); + } +} + +static void register_notifiers(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + if (vport->port_type == VIRT_SWITCH_PORT) { + vport->inetaddr_nb.notifier_call = cpsw_proxy_client_inetaddr; + register_inetaddr_notifier(&vport->inetaddr_nb); + } + } +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; From patchwork Sat May 18 12:42:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667632 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 0CCE67CF16; Sat, 18 May 2024 12:44:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036294; cv=none; b=bVIp86pT7ebaYonPkTPSx62yek/WsoL65mg8tGJr7Fg1v0D62TRe0L6iMDZ9u/Bd9euW0dDgn194ZmrILZLsFv/b1ShGnv75TP4YBAv85+qxGT105JVsxoDfFdllpy1NVxgJLk6Chynaqsuq+gBqXIyikNlJ49srpnefSSy/28I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036294; c=relaxed/simple; bh=Cr1Hx/59i5Pd0utl/xEQlO3tb13qU2CGqkR40CyfqrU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cHTzpcZ3OB5sp0CvrAJkYbI/8CI3w+sCFXjSq0B8WPod7X02QpkNTn35hma82KmrWvGpWC+7Rt07R4irM2Lur4tdSvzEBEiVYPYFjI/5W3zggx+jI9EFYq5o6+uaad4FN9g2ZXmdtV2cq29PYq4jVYyC7E1Nhz4juDLsQQCG5Cc= 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=XApwLL0o; arc=none smtp.client-ip=198.47.19.142 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="XApwLL0o" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICidYo055082; Sat, 18 May 2024 07:44:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036279; bh=PBa9dvCuZos4JKSfHsV95/NYkFboZosIZz2HTkKHaWw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XApwLL0oybS7ZqecH5qupDsbrgBdWwUfB3pXK/vJe3XX8LvdkoIXbtMlp29J0t6a0 8cDh5EIKqMf+IZDOOvwBqTMNVwahSkVkFA3Fvur5CPNzA7o3zeTW8QdoqkhZzzC/gL 7MHXuJLscNU/SKjRQtsbNELBsh8u6qY4vUclf84Q= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICidik018223 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:39 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:38 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) 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.23 via Frontend Transport; Sat, 18 May 2024 07:44:38 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9g041511; Sat, 18 May 2024 07:44:34 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 26/28] net: ethernet: ti: cpsw-proxy-client: add ndo_set_rx_mode member Date: Sat, 18 May 2024 18:12:32 +0530 Message-ID: <20240518124234.2671651-27-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the .ndo_set_rx_mode callback named "vport_set_rx_mode()". Syncing the Multicast Address list requires adding/deleting Multicast Addresses registered with EthFw. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 131 ++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 9ede3e584a06..56311b019376 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -106,6 +106,9 @@ struct virtual_port { struct net_device *ndev; struct rx_dma_chan *rx_chans; struct tx_dma_chan *tx_chans; + struct netdev_hw_addr_list mcast_list; + struct workqueue_struct *vport_wq; + struct work_struct rx_mode_work; struct completion tdown_complete; struct notifier_block inetaddr_nb; enum virtual_port_type port_type; @@ -1428,6 +1431,59 @@ static void vport_rx_cleanup(void *data, dma_addr_t desc_dma) dev_kfree_skb_any(skb); } +static int vport_add_mcast(struct net_device *ndev, const u8 *addr) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct rx_dma_chan *rx_chn = &vport->rx_chans[0]; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_MCAST_FILTER_ADD; + req_p->token = vport->port_token; + req_p->vlan_id = ETHFW_DFLT_VLAN; + req_p->rx_flow_base = rx_chn->flow_base; + req_p->rx_flow_offset = rx_chn->flow_offset; + ether_addr_copy(req_p->mac_addr, addr); + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + + if (ret) { + dev_err(proxy_priv->dev, "failed to add mcast filter, err: %d\n", ret); + return -EIO; + } + + return 0; +} + +static int vport_del_mcast(struct net_device *ndev, const u8 *addr) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_MCAST_FILTER_DEL; + req_p->token = vport->port_token; + req_p->vlan_id = ETHFW_DFLT_VLAN; + ether_addr_copy(req_p->mac_addr, addr); + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + + if (ret) { + dev_err(proxy_priv->dev, "failed to delete mcast filter, err: %d\n", ret); + return -EIO; + } + + return 0; +} + static void vport_stop(struct virtual_port *vport) { struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; @@ -1466,6 +1522,9 @@ static void vport_stop(struct virtual_port *vport) napi_disable(&rx_chn->napi_rx); hrtimer_cancel(&rx_chn->rx_hrtimer); } + + if (vport->port_features & ETHFW_MCAST_FILTERING) + cancel_work_sync(&vport->rx_mode_work); } static int vport_open(struct virtual_port *vport, netdev_features_t features) @@ -1533,6 +1592,8 @@ static int vport_ndo_stop(struct net_device *ndev) netdev_err(ndev, "failed to deregister MAC for port %u\n", vport->port_id); + __dev_mc_unsync(ndev, vport_del_mcast); + __hw_addr_init(&vport->mcast_list); vport_stop(vport); dev_info(proxy_priv->dev, "stopped port %u on interface %s\n", @@ -1786,6 +1847,31 @@ static void vport_ndo_tx_timeout(struct net_device *ndev, unsigned int txqueue) } } +static void vport_set_rx_mode_work(struct work_struct *work) +{ + struct virtual_port *vport = container_of(work, struct virtual_port, rx_mode_work); + struct net_device *ndev; + + if (likely(vport->port_features & ETHFW_MCAST_FILTERING)) { + ndev = vport->ndev; + + netif_addr_lock_bh(ndev); + __hw_addr_sync(&vport->mcast_list, &ndev->mc, ndev->addr_len); + netif_addr_unlock_bh(ndev); + + __hw_addr_sync_dev(&vport->mcast_list, ndev, + vport_add_mcast, vport_del_mcast); + } +} + +static void vport_set_rx_mode(struct net_device *ndev) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + + if (vport->port_features & ETHFW_MCAST_FILTERING) + queue_work(vport->vport_wq, &vport->rx_mode_work); +} + static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_open = vport_ndo_open, .ndo_stop = vport_ndo_stop, @@ -1794,6 +1880,7 @@ static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_tx_timeout = vport_ndo_tx_timeout, .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = eth_mac_addr, + .ndo_set_rx_mode = vport_set_rx_mode, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) @@ -1871,12 +1958,56 @@ static void unreg_netdevs(struct cpsw_proxy_priv *proxy_priv) } } +static void destroy_vport_wqs(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + if (vport->vport_wq) + destroy_workqueue(vport->vport_wq); + } +} + +static int create_vport_wqs(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + char wq_name[IFNAMSIZ]; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + if (!(vport->port_features & ETHFW_MCAST_FILTERING)) + continue; + + snprintf(wq_name, sizeof(wq_name), "vport_%d", vport->port_id); + __hw_addr_init(&vport->mcast_list); + INIT_WORK(&vport->rx_mode_work, vport_set_rx_mode_work); + vport->vport_wq = create_singlethread_workqueue(wq_name); + if (!vport->vport_wq) { + dev_err(proxy_priv->dev, "failed to create wq %s\n", wq_name); + goto err; + } + } + + return 0; + +err: + destroy_vport_wqs(proxy_priv); + return -ENOMEM; +} + static int init_netdevs(struct cpsw_proxy_priv *proxy_priv) { struct virtual_port *vport; int ret; u32 i; + ret = create_vport_wqs(proxy_priv); + if (ret) + return ret; + for (i = 0; i < proxy_priv->num_virt_ports; i++) { vport = &proxy_priv->virt_ports[i]; ret = init_netdev(proxy_priv, vport); From patchwork Sat May 18 12:42:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667633 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 208B47D3EC; Sat, 18 May 2024 12:44:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036296; cv=none; b=tfIgHLvYFr4leaDvHP2/T/7u3XLItdQxQ4Q5dzEjP0AFB0HRwGzNUub9gclD7iDHxhGvmn3I5yAqsDK2Q2mmqM8qb/iH9crBOfQhomht/KxaW0JmxgKvQkOwwAPfP4JcQhhxKzkPsdLjKa0gfmXRNwcnx3BrZtbr6rd+v60B1qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036296; c=relaxed/simple; bh=rhZhZefae0cACIc1qoO4sSovAhZuNhhVUznYmRvSPBM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q8wOvrer/hYcbSbaUj2lDB79Nz7BhhoL8aNVe3jFk7FMSIRXUL0zl588MjKscWqk3nUxONy7YcEr5YmpYw3Al/bk7UR+hCRJU/CQtrCB+N4qpecwi3N+cnlMt2vLJZpNRfzEMtAZpKulwY/X21Vb3sKYJzCNHPmguYmklnPXPQE= 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=ByCjHYP+; arc=none smtp.client-ip=198.47.19.142 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="ByCjHYP+" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICii3d055090; Sat, 18 May 2024 07:44:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036284; bh=gd1CjXaEXO/rtJ2evrOBvHAAqqCDyXL/UmbLLmBB14E=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ByCjHYP+PB07MHKGquA8vnYjE04cA+G93Mc87eFvhoHPd+51/1AReXp032LxL10X7 rR4ZUGsyPI3dcQ/Tmw38tfd9a6yPCxndOeBTzGQ6h5ItH+L3USN7+47v+t07kVJ+jA 1Lkj4qY5xcX9cYx0K30qgVdFteSLFLKlJAcAeoaY= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICiiT1130472 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:44 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 07:44:43 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:43 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9h041511; Sat, 18 May 2024 07:44:39 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 27/28] net: ethernet: ti: cpsw-proxy-client: add helper to detach virtual ports Date: Sat, 18 May 2024 18:12:33 +0530 Message-ID: <20240518124234.2671651-28-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add the helper function "detach_virtual_ports()" to release all resources held by the virtual ports and send the ETHFW_VIRT_PORT_DETACH request for each virtual port. This notifies EthFw that the virtual ports are unused. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 56311b019376..90be8bb0e37d 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -672,6 +672,29 @@ static int allocate_port_resources(struct cpsw_proxy_priv *proxy_priv) return -EIO; } +static void detach_virtual_ports(struct cpsw_proxy_priv *proxy_priv) +{ + struct cpsw_proxy_req_params *req_p; + struct virtual_port *vport; + struct message resp_msg; + u32 port_id, i; + int ret; + + free_port_resources(proxy_priv); + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + port_id = vport->port_id; + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_VIRT_PORT_DETACH; + req_p->token = vport->port_token; + ret = send_request_get_response(proxy_priv, &resp_msg); + mutex_unlock(&proxy_priv->req_params_mutex); + if (ret) + dev_err(proxy_priv->dev, "detaching virtual port %u failed\n", port_id); + } +} + static void free_tx_chns(void *data) { struct cpsw_proxy_priv *proxy_priv = data; From patchwork Sat May 18 12:42:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667634 X-Patchwork-Delegate: kuba@kernel.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 1FB8B7CF16; Sat, 18 May 2024 12:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036302; cv=none; b=tiWOeikWht4q/gfg7qzx6l/N8F62700a3xMUnu7BcIhFMdbVaKdx18LLbH3LI0vz9CAN8Irf5BLlCZI31GdL7cORYHFtQLVzpTyR5vDniaMGIjKJOHYrikAxsXtliiymC35kYqVCvfJ+2OlvMCvuhpqmkkCNxL0Rf8/wTmTeOCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716036302; c=relaxed/simple; bh=hynyAfgRm5q+1IANofou/nprgd/BjuI4O4e6YgviSjA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R80z6oHbPI5QcxZIspZG6fL9+o5OwG+W4W6/YVpOdBPCxbM+3pY4KAj7xjALVG0PqeMuJhYJIXv5vxcafv2Xztd52VYSSj3S2tD6/OFY0tvVEaKUYIN3jNefI3MT+wbDT2iAOkP/8j3JLQGCtU0dT8IHX8UKlIgppW8fQHi0PBU= 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=dthQdYTY; arc=none smtp.client-ip=198.47.19.142 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="dthQdYTY" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICimra055098; Sat, 18 May 2024 07:44:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036288; bh=VPaREiRTmandW1VVNogQssPNjYrkxOVaQwGJoi1ZkHI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=dthQdYTYKEVD3XytPwLMxYFpI0/p2qDVk/gPrr+k4aUKGMBysbuvG7bki2vAzEaCk MXkiXxWtBGnbo7EuaO+4xQM9Wd0z1zNnwL7JXxhXPyl2WXU6qXq7R0fOVNyqUCeaJB URShu77GUbuGADkhaU5/RULKbY7Fv+b3uNpyx3nw= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICimT0018265 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:48 -0500 Received: from DLEE101.ent.ti.com (157.170.170.31) 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.23; Sat, 18 May 2024 07:44:48 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE101.ent.ti.com (157.170.170.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 07:44:48 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44ICgY9i041511; Sat, 18 May 2024 07:44:44 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 28/28] net: ethernet: ti: cpsw-proxy-client: enable client driver functionality Date: Sat, 18 May 2024 18:12:34 +0530 Message-ID: <20240518124234.2671651-29-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240518124234.2671651-1-s-vadapalli@ti.com> References: <20240518124234.2671651-1-s-vadapalli@ti.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use the helpers added so far to enable the client driver functionality. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 82 +++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 90be8bb0e37d..3eccde764c17 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -2227,9 +2228,33 @@ static void register_notifiers(struct cpsw_proxy_priv *proxy_priv) } } +static void show_info(struct cpsw_proxy_priv *proxy_priv) +{ + struct device *dev = proxy_priv->dev; + struct virtual_port *vport; + u32 i; + + dev_info(dev, "%u Virtual Switch Port(s), %u Virtual MAC Only Port(s)\n", + proxy_priv->num_switch_ports, proxy_priv->num_mac_ports); + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + + if (vport->port_type == VIRT_SWITCH_PORT) + dev_info(dev, "Virt Port: %u, Type: Switch Port, Iface: %s, Num TX: %u, Num RX: %u, Token: %u\n", + vport->port_id, vport->ndev->name, vport->num_tx_chan, + vport->num_rx_chan, vport->port_token); + else + dev_info(dev, "Virt Port: %u, Type: MAC Port, Iface: %s, Num TX: %u, Num RX: %u, Token: %u\n", + vport->port_id, vport->ndev->name, vport->num_tx_chan, + vport->num_rx_chan, vport->port_token); + } +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv; + int ret; proxy_priv = devm_kzalloc(&rpdev->dev, sizeof(struct cpsw_proxy_priv), GFP_KERNEL); if (!proxy_priv) @@ -2237,22 +2262,79 @@ static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) proxy_priv->rpdev = rpdev; proxy_priv->dev = &rpdev->dev; + proxy_priv->dma_node = of_find_compatible_node(NULL, NULL, + (const char *)rpdev->id.driver_data); dev_set_drvdata(proxy_priv->dev, proxy_priv); dev_dbg(proxy_priv->dev, "driver probed\n"); + proxy_priv->req_params.token = ETHFW_TOKEN_NONE; + proxy_priv->req_params.client_id = ETHFW_LINUX_CLIENT_TOKEN; + mutex_init(&proxy_priv->req_params_mutex); + init_completion(&proxy_priv->wait_for_response); + + ret = get_virtual_port_info(proxy_priv); + if (ret) + return -EIO; + + ret = attach_virtual_ports(proxy_priv); + if (ret) + return -EIO; + + ret = allocate_port_resources(proxy_priv); + if (ret) + goto err_attach; + + ret = dma_coerce_mask_and_coherent(proxy_priv->dev, DMA_BIT_MASK(48)); + if (ret) { + dev_err(proxy_priv->dev, "error setting dma mask: %d\n", ret); + goto err_attach; + } + + ret = init_tx_chans(proxy_priv); + if (ret) + goto err_attach; + + ret = init_rx_chans(proxy_priv); + if (ret) + goto err_attach; + + ret = init_netdevs(proxy_priv); + if (ret) + goto err_attach; + + ret = register_dma_irq_handlers(proxy_priv); + if (ret) + goto err_netdevs; + + register_notifiers(proxy_priv); + show_info(proxy_priv); + return 0; + +err_netdevs: + unreg_netdevs(proxy_priv); +err_attach: + detach_virtual_ports(proxy_priv); + return ret; } static void cpsw_proxy_client_remove(struct rpmsg_device *rpdev) { + struct cpsw_proxy_priv *proxy_priv; struct device *dev = &rpdev->dev; dev_dbg(dev, "driver removed\n"); + proxy_priv = dev_get_drvdata(&rpdev->dev); + unregister_notifiers(proxy_priv); + unreg_netdevs(proxy_priv); + destroy_vport_wqs(proxy_priv); + detach_virtual_ports(proxy_priv); } static struct rpmsg_device_id cpsw_proxy_client_id_table[] = { { .name = ETHFW_SERVICE_EP_NAME, + .driver_data = (kernel_ulong_t)"ti,j721e-navss-main-udmap", }, {}, };