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: 13667643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C69ECC25B74 for ; Sat, 18 May 2024 12:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xm7GhFJ7CZjPvRaRUTkWJWuTm3dwG2EJ8MpwHEt+Pms=; b=qykGnAEfR7OMyL sB6vyuwdWM0xEZxfc2kbY2p0Ys7oq2qxaeUPBInAFmiKfA8UQ5/bpGJ6gXI3gi1XWLKKS5IxDcGer N+1kzwB6qfB7pV6Mq8t+TE34lAp8M9Mh/Ob75LlpwIJaqBQqif4qVVmKQY6ivNS71nwGFYpeAcn0r r/dRQC7rC7x3E7R8lDK+WI82+qE4wHXxaUt9e/Q06c1FSAVCWpoCZYkfaj30tXhGtk7KEmKWq+YD0 xlcFBK+QEuwhb7CzPOkQNqfrqiO3DYRN1Vd+31olur9onhB9Z27VVvUGfpP7DQUGfsjrpqbu5aF5G Nx1D8PCDhOoNX10/tQJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8JPt-0000000A5Ug-396t; Sat, 18 May 2024 12:44:01 +0000 Received: from fllv0016.ext.ti.com ([198.47.19.142]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8JPF-0000000A50a-0Mbm for linux-arm-kernel@lists.infradead.org; Sat, 18 May 2024 12:43:24 +0000 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> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240518_054321_353125_4D3D9BFF X-CRM114-Status: GOOD ( 16.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;