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: 13667659 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 0DD03C25B74 for ; Sat, 18 May 2024 13:47:49 +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=P2XKbvKwwV47/JHGFF9O4ZF8duXSHy9oeduHfT7yTbg=; b=1xpkJIHEwRQkK2 Bv8rNUADlpeRmAIMq59ICS1yukcnoxR9tmcJPH02L1Ee9HZsEN/zXvHMyCpMufa+yOMAKzd4yz2az IbnYHBw8jFpzXu8uHkF0in/kZJeycra0xn1n2gWyh9Hd/0/MiLKoiJ6+qZCirqcFB6+BsrmueAsa6 6I9O0r6Z+7BQC6XxNoY2uUrOH5AxfLbFOx9+81NKmyZV1SAWH0QzjkuyTP0oHYo+yAV3OpcPvv1C2 zLxNtr4TM5Twt7KW3b0ZGFeVnBwKudEzxStXk+PwurYUrKwadYLTi0ABq4V0h8ehygTIVekk/X8v8 upI7u0QMr9i+VdWrHNfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8KPc-0000000ACUc-160Q; Sat, 18 May 2024 13:47:48 +0000 Received: from fllv0015.ext.ti.com ([198.47.19.141]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8JPP-0000000A59h-2aSw for linux-arm-kernel@lists.infradead.org; Sat, 18 May 2024 12:43:35 +0000 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> 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_054332_009067_A2A8F205 X-CRM114-Status: GOOD ( 18.04 ) 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 "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;