DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yanling Song <songyl@ramaxel.com>
To: <dev@dpdk.org>
Cc: <songyl@ramaxel.com>, <yanling.song@linux.dev>,
	<yanggan@ramaxel.com>, <xuyun@ramaxel.com>,
	<ferruh.yigit@intel.com>
Subject: [PATCH v4 19/25] net/spnic: support promiscuous and allmulticast Rx modes
Date: Sat, 25 Dec 2021 19:29:07 +0800	[thread overview]
Message-ID: <db1216b66d8704d639b44b3d23320173a9294019.1640426040.git.songyl@ramaxel.com> (raw)
In-Reply-To: <cover.1640426040.git.songyl@ramaxel.com>

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 <songyl@ramaxel.com>
---
 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 5b1c67c90f..a3baa8c481 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


  parent reply	other threads:[~2021-12-25 11:31 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-25 11:28 [PATCH v4 00/25] Net/SPNIC: support SPNIC into DPDK 22.03 Yanling Song
2021-12-25 11:28 ` [PATCH v4 01/25] drivers/net: introduce a new PMD driver Yanling Song
2021-12-25 11:28 ` [PATCH v4 02/25] net/spnic: initialize the HW interface Yanling Song
2021-12-28  2:10   ` lihuisong (C)
2021-12-29 11:49     ` Yanling Song
2021-12-25 11:28 ` [PATCH v4 03/25] net/spnic: add mbox message channel Yanling Song
2021-12-25 11:28 ` [PATCH v4 04/25] net/spnic: introduce event queue Yanling Song
2021-12-25 11:28 ` [PATCH v4 05/25] net/spnic: add mgmt module Yanling Song
2021-12-25 11:28 ` [PATCH v4 06/25] net/spnic: add cmdq and work queue Yanling Song
2021-12-25 11:28 ` [PATCH v4 07/25] net/spnic: add interface handling cmdq message Yanling Song
2021-12-25 11:28 ` [PATCH v4 08/25] net/spnic: add hardware info initialization Yanling Song
2021-12-25 11:28 ` [PATCH v4 09/25] net/spnic: support MAC and link event handling Yanling Song
2021-12-25 11:28 ` [PATCH v4 10/25] net/spnic: add function info initialization Yanling Song
2021-12-25 11:28 ` [PATCH v4 11/25] net/spnic: add queue pairs context initialization Yanling Song
2021-12-25 11:29 ` [PATCH v4 12/25] net/spnic: support mbuf handling of Tx/Rx Yanling Song
2021-12-25 11:29 ` [PATCH v4 13/25] net/spnic: support Rx congfiguration Yanling Song
2021-12-25 11:29 ` [PATCH v4 14/25] net/spnic: add port/vport enable Yanling Song
2021-12-25 11:29 ` [PATCH v4 15/25] net/spnic: support IO packets handling Yanling Song
2021-12-25 11:29 ` [PATCH v4 16/25] net/spnic: add device configure/version/info Yanling Song
2021-12-25 11:29 ` [PATCH v4 17/25] net/spnic: support RSS configuration update and get Yanling Song
2021-12-25 11:29 ` [PATCH v4 18/25] net/spnic: support VLAN filtering and offloading Yanling Song
2021-12-25 11:29 ` Yanling Song [this message]
2021-12-25 11:29 ` [PATCH v4 20/25] net/spnic: support flow control Yanling Song
2021-12-25 11:29 ` [PATCH v4 21/25] net/spnic: support getting Tx/Rx queues info Yanling Song
2021-12-25 11:29 ` [PATCH v4 22/25] net/spnic: net/spnic: support xstats statistics Yanling Song
2021-12-25 11:29 ` [PATCH v4 23/25] net/spnic: support VFIO interrupt Yanling Song
2021-12-25 11:29 ` [PATCH v4 24/25] net/spnic: support Tx/Rx queue start/stop Yanling Song
2021-12-25 11:29 ` [PATCH v4 25/25] net/spnic: add doc infrastructure Yanling Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db1216b66d8704d639b44b3d23320173a9294019.1640426040.git.songyl@ramaxel.com \
    --to=songyl@ramaxel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=xuyun@ramaxel.com \
    --cc=yanggan@ramaxel.com \
    --cc=yanling.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).