Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1492344lqo; Sat, 18 May 2024 05:45:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWto1Hm9jZTIQUWUbc2/5kRac752LTiY4vQaEBOmqQF+XfH6D4+IYWQSrC3xpHW22qcJGYyuS3NoR9eqnYXjr2Uwgu4X2YrRBmgaGLqtw== X-Google-Smtp-Source: AGHT+IGY2Fc71+LE2oJQPb+8npRoEGVgtrd/xqdJ1r4Dw4I5R+5MWwz9OeVDImVqgWRsSsIdk6CO X-Received: by 2002:a17:902:7608:b0:1e2:817b:460a with SMTP id d9443c01a7336-1ef43e293e4mr241463875ad.34.1716036345850; Sat, 18 May 2024 05:45:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716036345; cv=pass; d=google.com; s=arc-20160816; b=ULF8zyGm55X161ILQpJT7qdVtaCop0Yi/HAgEWJekVPIf93LusokvHjWZ2jc/ZikAS GqCMX2tPsKjrPAAiAQ7WGBlBjogyvNHTlDDzY49DHaa7pe278d5Dv20VSLaOQVuDmJ/I nnVOk6QTo+hFnbp9Pt81dbAqn4tud6QsLf6uUxksTi1KMYHmzfccxVb0keKvAJ7wXtWY 1kv0CBoEM7TsV08e6OAWabbfoXQ3MnNLXgUEmE1X5I1RHZl20AABdYOutCTd+85/Y781 PE7JJz1HrLY3VtMMeT4F8dgWQIepu6aOKvCp+ZUIhl1tJhPeTVd3jaxo8SMwEudQZRAk 9fhQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=520vVll/ZFOoW9AjksFfU8ARoVZ/aAksC0ZgDCAKvsQ=; fh=o09Pg6xF7oDS6d546SEMTPTO411plfH6YfIeKl0U52o=; b=q5OcNfOYMqm4H+lcuD+W1HMltFH377AHqkw7WFMWiks4UmBt6+NKhwg1PW5HWOATdf rgvWS1nETIM+YGMjYa1eA9DPJTyFVPCtz1gktDXSFTa/KSdTt3cmet5t0MHDudj0Bg9G 9iEYfcYkL2KVJ4Z5XTjnwdi5L7xglhZteVnG1wADNYK1F/qGvq5lKc0dpDQZzSZF73Jo 34yPOxsUg6VtBdJ5GjF4yJOQYN+Gu6jE8Ln3eN8qDJEcsG2i9FogvMZL98bceElzMsPQ 5pSglm59QA0h8ldaGicSWDH6ygF+2dJ11t651cwIbU+6UMdebSb6eiKXmcvUgfKQI51i R5tg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=K+kal9ku; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-182855-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c03ac04si57411145ad.404.2024.05.18.05.45.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 May 2024 05:45:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182855-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=K+kal9ku; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-182855-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 83DCA281FBD for ; Sat, 18 May 2024 12:45:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F0E56BFB0; Sat, 18 May 2024 12:43:33 +0000 (UTC) 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 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 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; -- 2.40.1