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 4231FA00C5; Thu, 30 Dec 2021 07:11:48 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1D9A4426FA; Thu, 30 Dec 2021 07:10:03 +0100 (CET) Received: from VLXDG1SPAM1.ramaxel.com (email.unionmem.com [221.4.138.186]) by mails.dpdk.org (Postfix) with ESMTP id 5E1A2426E9 for ; Thu, 30 Dec 2021 07:09:59 +0100 (CET) Received: from V12DG1MBS01.ramaxel.local (v12dg1mbs01.ramaxel.local [172.26.18.31]) by VLXDG1SPAM1.ramaxel.com with ESMTPS id 1BU69DWj040086 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Dec 2021 14:09:15 +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; Thu, 30 Dec 2021 14:09:14 +0800 From: Yanling Song To: CC: , , , , , , Subject: [PATCH v6 19/26] net/spnic: support promiscuous and allmulticast Rx modes Date: Thu, 30 Dec 2021 14:08:57 +0800 Message-ID: <63761bd93b54c981da492f6566ad5925783aa343.1640838702.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: V12DG1MBS03.ramaxel.local (172.26.18.33) To V12DG1MBS01.ramaxel.local (172.26.18.31) X-DNSRBL: X-MAIL: VLXDG1SPAM1.ramaxel.com 1BU69DWj040086 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 654fc55b6c..b10b55f22c 100644 --- a/drivers/net/spnic/spnic_ethdev.c +++ b/drivers/net/spnic/spnic_ethdev.c @@ -1375,6 +1375,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. @@ -1811,6 +1961,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, @@ -1836,6 +1990,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.32.0