From patchwork Sat May 18 12:42:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13667649 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 19CB5C25B75 for ; Sat, 18 May 2024 12:45:10 +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=qwdkUiSgVwW9wIQVpuUkgQ3YGDyN1IBC6Xgv12rrf3Y=; b=YT/qQ8WX/B16ws 9afxGK1bMDYvXn56pdyOyjHk/z14RfvcDM7TLMe7nTNk8jvCf4antv1W4sL/jk3UD/NHYPkTjYsHf YyYlpfmWpeu2i+wYHbofRj4fUCR/+PDE5mCmFFo94Lce/WRD6tbK4eTDUrIqm4hRXt4QYcUNY/OZO NWg+5X8igueOKGJojcKTzosw/8iqCLK5ywgHjzMHSVvxD0Utqh6UA/eu664g6FNB5g0pF1D09IPx8 GzW4pLzRJIv6P7GqzeG0+Sn1M2IOhyPTvadNe+CGKMPp0vGwgvG++eJNGTWz5t3VY9QrJ4fdhslMu qJa/pI2F05SSH/PMjQUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8JQm-0000000A662-3MGU; Sat, 18 May 2024 12:44:56 +0000 Received: from lelv0142.ext.ti.com ([198.47.23.249]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8JPc-0000000A5J2-2IMd for linux-arm-kernel@lists.infradead.org; Sat, 18 May 2024 12:43:48 +0000 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IChdGU017302; Sat, 18 May 2024 07:43:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036219; bh=JwuJzNh8I8iVqcX/z+Q5XQWtzHIZzmIwva4vCStI6+U=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=L8mkyL21BhOgbyPfkReoRNFCZ/ow3iMSQzpYWoF7fH76tv/j0ggEbcup5QShbcvbL sPRs23XsLB2qY1JU6kchl6pU4Qw7vv7HhdbXS0aXyxzzo1hsM0fgAGRsI/2J8NU4Wn kUV72+hTdEYPBlGgBUGngVrqrjK54CyQ7rcGs15g= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IChd6e129545 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:43:39 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE115.ent.ti.com (157.170.170.26) 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:38 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE102.ent.ti.com (157.170.170.32) 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:39 -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 44ICgY9T041511; Sat, 18 May 2024 07:43:35 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 13/28] net: ethernet: ti: cpsw-proxy-client: add helper to create netdevs Date: Sat, 18 May 2024 18:12:19 +0530 Message-ID: <20240518124234.2671651-14-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_054345_015742_3051A2F3 X-CRM114-Status: GOOD ( 15.86 ) 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 "init_netdevs()" to initialize and register net-device for each Virtual Port. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 102 ++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 6926f65a4613..30d53a8e174e 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -25,6 +26,7 @@ #define MAX_RX_DESC 500 #define MAX_RX_FLOWS 1 +#define MIN_PACKET_SIZE ETH_ZLEN #define MAX_PACKET_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN) #define CHAN_NAME_LEN 128 @@ -1177,6 +1179,106 @@ static int vport_rx_poll(struct napi_struct *napi_rx, int budget) return num_rx; } +const struct ethtool_ops cpsw_proxy_client_ethtool_ops = { +}; + +static const struct net_device_ops cpsw_proxy_client_netdev_ops = { +}; + +static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) +{ + struct device *dev = proxy_priv->dev; + struct vport_netdev_priv *ndev_priv; + struct rx_dma_chan *rx_chn; + struct tx_dma_chan *tx_chn; + int ret = 0; + u32 i; + + vport->ndev = devm_alloc_etherdev_mqs(dev, sizeof(struct vport_netdev_priv), + vport->num_tx_chan, vport->num_rx_chan); + + if (!vport->ndev) { + dev_err(dev, "error allocating netdev for port %u\n", vport->port_id); + return -ENOMEM; + } + + ndev_priv = netdev_priv(vport->ndev); + ndev_priv->vport = vport; + SET_NETDEV_DEV(vport->ndev, dev); + + if (is_valid_ether_addr(vport->mac_addr)) + eth_hw_addr_set(vport->ndev, vport->mac_addr); + + vport->ndev->min_mtu = MIN_PACKET_SIZE; + vport->ndev->max_mtu = MAX_PACKET_SIZE; + vport->ndev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM; + vport->ndev->features = vport->ndev->hw_features; + vport->ndev->vlan_features |= NETIF_F_SG; + vport->ndev->netdev_ops = &cpsw_proxy_client_netdev_ops; + vport->ndev->ethtool_ops = &cpsw_proxy_client_ethtool_ops; + + ndev_priv->stats = netdev_alloc_pcpu_stats(struct vport_netdev_stats); + if (!ndev_priv->stats) + return -ENOMEM; + + ret = devm_add_action_or_reset(dev, (void(*)(void *))free_percpu, ndev_priv->stats); + if (ret) { + dev_err(dev, "failed to add free_percpu action, err: %d\n", ret); + return ret; + } + + for (i = 0; i < vport->num_tx_chan; i++) { + tx_chn = &vport->tx_chans[i]; + netif_napi_add_tx(vport->ndev, &tx_chn->napi_tx, vport_tx_poll); + } + + for (i = 0; i < vport->num_rx_chan; i++) { + rx_chn = &vport->rx_chans[i]; + netif_napi_add(vport->ndev, &rx_chn->napi_rx, vport_rx_poll); + } + + ret = register_netdev(vport->ndev); + if (ret) + dev_err(dev, "error registering net device, err: %d\n", ret); + + return ret; +} + +static void unreg_netdevs(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + if (vport->ndev) + unregister_netdev(vport->ndev); + } +} + +static int init_netdevs(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + int ret; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + ret = init_netdev(proxy_priv, vport); + if (ret) { + dev_err(proxy_priv->dev, "failed to initialize ndev for port %u\n", + vport->port_id); + goto err; + } + } + + return 0; + +err: + unreg_netdevs(proxy_priv); + return ret; +} + static int cpsw_proxy_client_probe(struct rpmsg_device *rpdev) { struct cpsw_proxy_priv *proxy_priv;