Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1492446lqo; Sat, 18 May 2024 05:46:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVrlsnBr8JEI+L2UC70ZZSM/kJNbSwnwRafMoMtUN8D+UVm5F42TqiI2tWoZSyo1OMohwI5g36r3/BtW7pA+mVUu/qZSR+4822LIClhQ== X-Google-Smtp-Source: AGHT+IGA6dgeDQcPeGck4mPg7yQTNQxuLAjAVIu+xV2mreQMtvR22IfONxfMoVsm/EOySFY/GC4G X-Received: by 2002:a17:902:f70f:b0:1e3:e0ca:d8a3 with SMTP id d9443c01a7336-1ef43d2e22cmr279431795ad.6.1716036361699; Sat, 18 May 2024 05:46:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716036361; cv=pass; d=google.com; s=arc-20160816; b=rBP036N4d9uKS4b6x7y/wD2L0kBmGVHtQRgSmYRr8XsxcvK1PQCXqs23vu/n/yMnN+ bewy3dv3+Nat5LRrcFb53f2lBJsnS8tStg1snSU5hFBo13V1vRqrXuLEyax4dWZq1BlF +NKQzm4xm/yYIBzihON/Wft9xIuKZ280GFbifsgCii0x5XBmauY99LxmGkxBdJiVVGfz XT6dKBsl8dp8BnlCaYQljso4vLGgwnziaMePO5qfirT+mDzomjABz75/faYxRjaG91to LJVRBV5D503+qV0QGItSzZ+/yBRl6Ka+32D0ed6wpsWXuxrY7+Bg3Lqgb9EQtcL/U1Ny T1PQ== 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=X4OG+ZvQd9VrF6yQRJQsEZaaVWKIzPyaHgTp/GtXj38=; fh=o09Pg6xF7oDS6d546SEMTPTO411plfH6YfIeKl0U52o=; b=CQvcIMPdPuegtjbNKoYfPugO4hacPAwBbMuQSQ+JvThIG+IZQtESvmZIVv1PKu/I8W JNTdWylHAOjFvkqto3T0ipz//nqt3vA/7Q99r84uAstXhivyP5CQHTGz3Fd5KYlS5wPK BPkmvw/MkfwYXifviZ6PJvl18H6G68MDx2HlZqeNfSLxK22plEEGMo8qe8fXP7TpFNDB +ZvMxVgel0btphZDXIY5ESRcCsSgjHnBws4TzGYDvhx63+lwLumiie5uKAO54j8eUVd1 8Sow+FyTCaoWGfiUlfgwJVBLM5WlM3f869hfBEXQwdBq3mslwNLyMSQKnOHTBjv7uLFG a3TQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=AL78jLzy; 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-182856-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182856-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-1ef0c153584si198123005ad.481.2024.05.18.05.46.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 May 2024 05:46:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182856-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=AL78jLzy; 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-182856-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182856-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 A3140282859 for ; Sat, 18 May 2024 12:45:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87D4F6CDB7; Sat, 18 May 2024 12:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="AL78jLzy" 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 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: 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 "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; -- 2.40.1