From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C65EAA04A4; Sat, 18 Dec 2021 03:54:45 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29FB0426E5; Sat, 18 Dec 2021 03:52:45 +0100 (CET) Received: from VLXDG1SPAM1.ramaxel.com (email.ramaxel.com [221.4.138.186]) by mails.dpdk.org (Postfix) with ESMTP id C76A1426E7 for ; Sat, 18 Dec 2021 03:52:43 +0100 (CET) Received: from V12DG1MBS01.ramaxel.local (v12dg1mbs01.ramaxel.local [172.26.18.31]) by VLXDG1SPAM1.ramaxel.com with ESMTPS id 1BI2q27Q010347 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 Dec 2021 10:52:02 +0800 (GMT-8) (envelope-from songyl@ramaxel.com) Received: from localhost.localdomain (10.64.9.47) by V12DG1MBS01.ramaxel.local (172.26.18.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Sat, 18 Dec 2021 10:52:02 +0800 From: Yanling Song To: CC: , , , Subject: [PATCH v1 19/25] net/spnic: support promiscuous and allmulticast Rx modes Date: Sat, 18 Dec 2021 10:51:46 +0800 Message-ID: <056dc0cd7dbafa37d68a2887d5602f860fe44b7b.1639636621.git.songyl@ramaxel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.64.9.47] X-ClientProxiedBy: V12DG1MBS01.ramaxel.local (172.26.18.31) To V12DG1MBS01.ramaxel.local (172.26.18.31) X-DNSRBL: X-MAIL: VLXDG1SPAM1.ramaxel.com 1BI2q27Q010347 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This commit implements promiscuous_enable/disable() and allmulticast_enable/disable() to configure promiscuous or allmulticast Rx modes. Note: promiscuous rx mode is only supported by PF. Signed-off-by: Yanling Song --- drivers/net/spnic/spnic_ethdev.c | 156 +++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/drivers/net/spnic/spnic_ethdev.c b/drivers/net/spnic/spnic_ethdev.c index 7f6bd41c55..0b5ef15373 100644 --- a/drivers/net/spnic/spnic_ethdev.c +++ b/drivers/net/spnic/spnic_ethdev.c @@ -1394,6 +1394,156 @@ static int spnic_vlan_offload_set(struct rte_eth_dev *dev, int mask) return 0; } +/** + * Enable allmulticast mode. + * + * @param[in] dev + * Pointer to ethernet device structure. + * + * @retval zero: Success + * @retval non-zero: Failure + */ +static int spnic_dev_allmulticast_enable(struct rte_eth_dev *dev) +{ + struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev); + u32 rx_mode; + int err; + + err = spnic_mutex_lock(&nic_dev->rx_mode_mutex); + if (err) + return err; + + rx_mode = nic_dev->rx_mode | SPNIC_RX_MODE_MC_ALL; + + err = spnic_set_rx_mode(nic_dev->hwdev, rx_mode); + if (err) { + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + PMD_DRV_LOG(ERR, "Enable allmulticast failed, error: %d", err); + return err; + } + + nic_dev->rx_mode = rx_mode; + + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + + PMD_DRV_LOG(INFO, "Enable allmulticast succeed, nic_dev: %s, port_id: %d", + nic_dev->dev_name, dev->data->port_id); + return 0; +} + +/** + * Disable allmulticast mode. + * + * @param[in] dev + * Pointer to ethernet device structure. + * + * @retval zero: Success + * @retval non-zero: Failure + */ +static int spnic_dev_allmulticast_disable(struct rte_eth_dev *dev) +{ + struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev); + u32 rx_mode; + int err; + + err = spnic_mutex_lock(&nic_dev->rx_mode_mutex); + if (err) + return err; + + rx_mode = nic_dev->rx_mode & (~SPNIC_RX_MODE_MC_ALL); + + err = spnic_set_rx_mode(nic_dev->hwdev, rx_mode); + if (err) { + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + PMD_DRV_LOG(ERR, "Disable allmulticast failed, error: %d", err); + return err; + } + + nic_dev->rx_mode = rx_mode; + + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + + PMD_DRV_LOG(INFO, "Disable allmulticast succeed, nic_dev: %s, port_id: %d", + nic_dev->dev_name, dev->data->port_id); + return 0; +} + +/** + * Enable promiscuous mode. + * + * @param[in] dev + * Pointer to ethernet device structure. + * + * @retval zero: Success + * @retval non-zero: Failure + */ +static int spnic_dev_promiscuous_enable(struct rte_eth_dev *dev) +{ + struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev); + u32 rx_mode; + int err; + + err = spnic_mutex_lock(&nic_dev->rx_mode_mutex); + if (err) + return err; + + rx_mode = nic_dev->rx_mode | SPNIC_RX_MODE_PROMISC; + + err = spnic_set_rx_mode(nic_dev->hwdev, rx_mode); + if (err) { + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + PMD_DRV_LOG(ERR, "Enable promiscuous failed"); + return err; + } + + nic_dev->rx_mode = rx_mode; + + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + + PMD_DRV_LOG(INFO, "Enable promiscuous, nic_dev: %s, port_id: %d, promisc: %d", + nic_dev->dev_name, dev->data->port_id, + dev->data->promiscuous); + return 0; +} + +/** + * Disable promiscuous mode. + * + * @param[in] dev + * Pointer to ethernet device structure. + * + * @retval zero: Success + * @retval non-zero: Failure + */ +static int spnic_dev_promiscuous_disable(struct rte_eth_dev *dev) +{ + struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev); + u32 rx_mode; + int err; + + err = spnic_mutex_lock(&nic_dev->rx_mode_mutex); + if (err) + return err; + + rx_mode = nic_dev->rx_mode & (~SPNIC_RX_MODE_PROMISC); + + err = spnic_set_rx_mode(nic_dev->hwdev, rx_mode); + if (err) { + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + PMD_DRV_LOG(ERR, "Disable promiscuous failed"); + return err; + } + + nic_dev->rx_mode = rx_mode; + + (void)spnic_mutex_unlock(&nic_dev->rx_mode_mutex); + + PMD_DRV_LOG(INFO, "Disable promiscuous, nic_dev: %s, port_id: %d, promisc: %d", + nic_dev->dev_name, dev->data->port_id, + dev->data->promiscuous); + return 0; +} + /** * Update the RSS hash key and RSS hash type. @@ -1830,6 +1980,10 @@ static const struct eth_dev_ops spnic_pmd_ops = { .mtu_set = spnic_dev_set_mtu, .vlan_filter_set = spnic_vlan_filter_set, .vlan_offload_set = spnic_vlan_offload_set, + .allmulticast_enable = spnic_dev_allmulticast_enable, + .allmulticast_disable = spnic_dev_allmulticast_disable, + .promiscuous_enable = spnic_dev_promiscuous_enable, + .promiscuous_disable = spnic_dev_promiscuous_disable, .rss_hash_update = spnic_rss_hash_update, .rss_hash_conf_get = spnic_rss_conf_get, .reta_update = spnic_rss_reta_update, @@ -1855,6 +2009,8 @@ static const struct eth_dev_ops spnic_pmd_vf_ops = { .mtu_set = spnic_dev_set_mtu, .vlan_filter_set = spnic_vlan_filter_set, .vlan_offload_set = spnic_vlan_offload_set, + .allmulticast_enable = spnic_dev_allmulticast_enable, + .allmulticast_disable = spnic_dev_allmulticast_disable, .rss_hash_update = spnic_rss_hash_update, .rss_hash_conf_get = spnic_rss_conf_get, .reta_update = spnic_rss_reta_update, -- 2.27.0