From patchwork Sat May 18 12:42:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: s-vadapalli X-Patchwork-Id: 13667666 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 03A27C25B75 for ; Sat, 18 May 2024 13:48:04 +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=rBvLSB97QR8kKyIa+GajfexZFkXDww1uz6jV+IqVxIU=; b=HKyjRSc3cnKdiQ LvpoEguZQuo1dBol3/cO4qYR51k3pj/sN3BteVkEY72/19MZjuc35d3v5dDqZ9sexyZC19+BWeK6P 8V90umFtIYm3jIbcP1gHUG+Dluh3ToRYXHR8pFt1tWGw7PhWNdhfoNWJaRtloX3oA8Rlbv1pY67Ha v5XMNFaqWng6RnFWE/EDeK+g5V9YX7LVXBejLLk/yQLAZrxURwvmFNuYGErhTSEJ9xEkBIJXfyWBK yWu3EV5+8TNczM/iiY+aQL6RPupcEIPgbymPRrCklTaAgPJavSndaD7m7bdxlGwndDXB/tIkTIcXZ K98anlk5S07XXJSe23MQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s8KPh-0000000ACXr-1LRT; Sat, 18 May 2024 13:47:53 +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 1s8JQZ-0000000A5xq-2Dp6 for linux-arm-kernel@lists.infradead.org; Sat, 18 May 2024 12:44:45 +0000 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44ICidYo055082; Sat, 18 May 2024 07:44:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716036279; bh=PBa9dvCuZos4JKSfHsV95/NYkFboZosIZz2HTkKHaWw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XApwLL0oybS7ZqecH5qupDsbrgBdWwUfB3pXK/vJe3XX8LvdkoIXbtMlp29J0t6a0 8cDh5EIKqMf+IZDOOvwBqTMNVwahSkVkFA3Fvur5CPNzA7o3zeTW8QdoqkhZzzC/gL 7MHXuJLscNU/SKjRQtsbNELBsh8u6qY4vUclf84Q= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44ICidik018223 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 07:44:39 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE115.ent.ti.com (10.64.6.36) 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:44:38 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE102.ent.ti.com (10.64.6.23) 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:44:38 -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 44ICgY9g041511; Sat, 18 May 2024 07:44:34 -0500 From: Siddharth Vadapalli To: , , , , , , , CC: , , , , , , , Subject: [RFC PATCH net-next 26/28] net: ethernet: ti: cpsw-proxy-client: add ndo_set_rx_mode member Date: Sat, 18 May 2024 18:12:32 +0530 Message-ID: <20240518124234.2671651-27-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_054443_762116_A4C7D37C X-CRM114-Status: GOOD ( 15.61 ) 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 .ndo_set_rx_mode callback named "vport_set_rx_mode()". Syncing the Multicast Address list requires adding/deleting Multicast Addresses registered with EthFw. Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/cpsw-proxy-client.c | 131 ++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw-proxy-client.c b/drivers/net/ethernet/ti/cpsw-proxy-client.c index 9ede3e584a06..56311b019376 100644 --- a/drivers/net/ethernet/ti/cpsw-proxy-client.c +++ b/drivers/net/ethernet/ti/cpsw-proxy-client.c @@ -106,6 +106,9 @@ struct virtual_port { struct net_device *ndev; struct rx_dma_chan *rx_chans; struct tx_dma_chan *tx_chans; + struct netdev_hw_addr_list mcast_list; + struct workqueue_struct *vport_wq; + struct work_struct rx_mode_work; struct completion tdown_complete; struct notifier_block inetaddr_nb; enum virtual_port_type port_type; @@ -1428,6 +1431,59 @@ static void vport_rx_cleanup(void *data, dma_addr_t desc_dma) dev_kfree_skb_any(skb); } +static int vport_add_mcast(struct net_device *ndev, const u8 *addr) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct rx_dma_chan *rx_chn = &vport->rx_chans[0]; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_MCAST_FILTER_ADD; + req_p->token = vport->port_token; + req_p->vlan_id = ETHFW_DFLT_VLAN; + req_p->rx_flow_base = rx_chn->flow_base; + req_p->rx_flow_offset = rx_chn->flow_offset; + ether_addr_copy(req_p->mac_addr, 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 add mcast filter, err: %d\n", ret); + return -EIO; + } + + return 0; +} + +static int vport_del_mcast(struct net_device *ndev, const u8 *addr) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; + struct cpsw_proxy_req_params *req_p; + struct message resp_msg; + int ret; + + mutex_lock(&proxy_priv->req_params_mutex); + req_p = &proxy_priv->req_params; + req_p->request_type = ETHFW_MCAST_FILTER_DEL; + req_p->token = vport->port_token; + req_p->vlan_id = ETHFW_DFLT_VLAN; + ether_addr_copy(req_p->mac_addr, 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 delete mcast filter, err: %d\n", ret); + return -EIO; + } + + return 0; +} + static void vport_stop(struct virtual_port *vport) { struct cpsw_proxy_priv *proxy_priv = vport->proxy_priv; @@ -1466,6 +1522,9 @@ static void vport_stop(struct virtual_port *vport) napi_disable(&rx_chn->napi_rx); hrtimer_cancel(&rx_chn->rx_hrtimer); } + + if (vport->port_features & ETHFW_MCAST_FILTERING) + cancel_work_sync(&vport->rx_mode_work); } static int vport_open(struct virtual_port *vport, netdev_features_t features) @@ -1533,6 +1592,8 @@ static int vport_ndo_stop(struct net_device *ndev) netdev_err(ndev, "failed to deregister MAC for port %u\n", vport->port_id); + __dev_mc_unsync(ndev, vport_del_mcast); + __hw_addr_init(&vport->mcast_list); vport_stop(vport); dev_info(proxy_priv->dev, "stopped port %u on interface %s\n", @@ -1786,6 +1847,31 @@ static void vport_ndo_tx_timeout(struct net_device *ndev, unsigned int txqueue) } } +static void vport_set_rx_mode_work(struct work_struct *work) +{ + struct virtual_port *vport = container_of(work, struct virtual_port, rx_mode_work); + struct net_device *ndev; + + if (likely(vport->port_features & ETHFW_MCAST_FILTERING)) { + ndev = vport->ndev; + + netif_addr_lock_bh(ndev); + __hw_addr_sync(&vport->mcast_list, &ndev->mc, ndev->addr_len); + netif_addr_unlock_bh(ndev); + + __hw_addr_sync_dev(&vport->mcast_list, ndev, + vport_add_mcast, vport_del_mcast); + } +} + +static void vport_set_rx_mode(struct net_device *ndev) +{ + struct virtual_port *vport = vport_ndev_to_vport(ndev); + + if (vport->port_features & ETHFW_MCAST_FILTERING) + queue_work(vport->vport_wq, &vport->rx_mode_work); +} + static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_open = vport_ndo_open, .ndo_stop = vport_ndo_stop, @@ -1794,6 +1880,7 @@ static const struct net_device_ops cpsw_proxy_client_netdev_ops = { .ndo_tx_timeout = vport_ndo_tx_timeout, .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = eth_mac_addr, + .ndo_set_rx_mode = vport_set_rx_mode, }; static int init_netdev(struct cpsw_proxy_priv *proxy_priv, struct virtual_port *vport) @@ -1871,12 +1958,56 @@ static void unreg_netdevs(struct cpsw_proxy_priv *proxy_priv) } } +static void destroy_vport_wqs(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->vport_wq) + destroy_workqueue(vport->vport_wq); + } +} + +static int create_vport_wqs(struct cpsw_proxy_priv *proxy_priv) +{ + struct virtual_port *vport; + char wq_name[IFNAMSIZ]; + u32 i; + + for (i = 0; i < proxy_priv->num_virt_ports; i++) { + vport = &proxy_priv->virt_ports[i]; + if (!(vport->port_features & ETHFW_MCAST_FILTERING)) + continue; + + snprintf(wq_name, sizeof(wq_name), "vport_%d", vport->port_id); + __hw_addr_init(&vport->mcast_list); + INIT_WORK(&vport->rx_mode_work, vport_set_rx_mode_work); + vport->vport_wq = create_singlethread_workqueue(wq_name); + if (!vport->vport_wq) { + dev_err(proxy_priv->dev, "failed to create wq %s\n", wq_name); + goto err; + } + } + + return 0; + +err: + destroy_vport_wqs(proxy_priv); + return -ENOMEM; +} + static int init_netdevs(struct cpsw_proxy_priv *proxy_priv) { struct virtual_port *vport; int ret; u32 i; + ret = create_vport_wqs(proxy_priv); + if (ret) + return ret; + for (i = 0; i < proxy_priv->num_virt_ports; i++) { vport = &proxy_priv->virt_ports[i]; ret = init_netdev(proxy_priv, vport);