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: 13667650 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 3E56EC25B74 for ; Sat, 18 May 2024 12:45: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=yyz1zuY6UIbWavDAqRPXxG8z2vSVu7Xv32jUu+ozjwY=; b=wKW9lfFj2qfpJA yLyUNq+R4arz/Tgd1MYCEq0PacR7Hiv90p9V2rNw2MIFfoiWyEb81ZpYNBNX4Q2cHBeLWa+PSMZ4T wSSV5ZM4wDMbu1acSvoyoK0Plw6uXuqkwCwbykxm1FVpR2oPGe3/pyD+1AjVngSHHR6+Zoul65Rye EE4m23274/kSUaDYNmSeSnr/sF5BNyBVdoFCcKm52JbqnWKIN0bNUHaHTjO2ftFUpUzea0iDiH2+H PWgVJlBV7JYpxYWMslPJEZtb4UgSgVd4FfRbtngqoZ7d6R22ceyiLZwxs5pL8GsYvParCZNI/vL6t bbjxstq45B04SECaz4Vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8JQq-0000000A68V-1Awm; Sat, 18 May 2024 12:45:00 +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 1s8JPp-0000000A5SJ-2gAd for linux-arm-kernel@lists.infradead.org; Sat, 18 May 2024 12:44:03 +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 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> 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_054357_948814_EF0CC99F X-CRM114-Status: GOOD ( 15.74 ) 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 "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)