[11/32] net/ngbe: add device promiscuous and allmulticast mode

Message ID 20210908083758.312055-12-jiawenwu@trustnetic.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series net/ngbe: add many features |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jiawen Wu Sept. 8, 2021, 8:37 a.m. UTC
  Support to enable/disable promiscuous and allmulticast mode for a port.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 doc/guides/nics/features/ngbe.ini |  2 +
 doc/guides/nics/ngbe.rst          |  2 +
 drivers/net/ngbe/ngbe_ethdev.c    | 63 +++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+)
  

Patch

diff --git a/doc/guides/nics/features/ngbe.ini b/doc/guides/nics/features/ngbe.ini
index bdb06916e1..2f38f1e843 100644
--- a/doc/guides/nics/features/ngbe.ini
+++ b/doc/guides/nics/features/ngbe.ini
@@ -12,6 +12,8 @@  MTU update           = Y
 Jumbo frame          = Y
 Scattered Rx         = Y
 TSO                  = Y
+Promiscuous mode     = Y
+Allmulticast mode    = Y
 CRC offload          = P
 VLAN offload         = P
 QinQ offload         = P
diff --git a/doc/guides/nics/ngbe.rst b/doc/guides/nics/ngbe.rst
index 64c07e4741..8333fba9cd 100644
--- a/doc/guides/nics/ngbe.rst
+++ b/doc/guides/nics/ngbe.rst
@@ -15,6 +15,8 @@  Features
 - Checksum offload
 - VLAN/QinQ stripping and inserting
 - TSO offload
+- Promiscuous mode
+- Multicast mode
 - Port hardware statistics
 - Jumbo frames
 - Link state information
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 29f35d9e8d..ce71edd6d8 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -1674,6 +1674,65 @@  ngbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
 	return ngbe_dev_link_update_share(dev, wait_to_complete);
 }
 
+static int
+ngbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
+{
+	struct ngbe_hw *hw = ngbe_dev_hw(dev);
+	uint32_t fctrl;
+
+	fctrl = rd32(hw, NGBE_PSRCTL);
+	fctrl |= (NGBE_PSRCTL_UCP | NGBE_PSRCTL_MCP);
+	wr32(hw, NGBE_PSRCTL, fctrl);
+
+	return 0;
+}
+
+static int
+ngbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
+{
+	struct ngbe_hw *hw = ngbe_dev_hw(dev);
+	uint32_t fctrl;
+
+	fctrl = rd32(hw, NGBE_PSRCTL);
+	fctrl &= (~NGBE_PSRCTL_UCP);
+	if (dev->data->all_multicast == 1)
+		fctrl |= NGBE_PSRCTL_MCP;
+	else
+		fctrl &= (~NGBE_PSRCTL_MCP);
+	wr32(hw, NGBE_PSRCTL, fctrl);
+
+	return 0;
+}
+
+static int
+ngbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
+{
+	struct ngbe_hw *hw = ngbe_dev_hw(dev);
+	uint32_t fctrl;
+
+	fctrl = rd32(hw, NGBE_PSRCTL);
+	fctrl |= NGBE_PSRCTL_MCP;
+	wr32(hw, NGBE_PSRCTL, fctrl);
+
+	return 0;
+}
+
+static int
+ngbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
+{
+	struct ngbe_hw *hw = ngbe_dev_hw(dev);
+	uint32_t fctrl;
+
+	if (dev->data->promiscuous == 1)
+		return 0; /* must remain in all_multicast mode */
+
+	fctrl = rd32(hw, NGBE_PSRCTL);
+	fctrl &= (~NGBE_PSRCTL_MCP);
+	wr32(hw, NGBE_PSRCTL, fctrl);
+
+	return 0;
+}
+
 /**
  * It clears the interrupt causes and enables the interrupt.
  * It will be called once only during NIC initialized.
@@ -2109,6 +2168,10 @@  static const struct eth_dev_ops ngbe_eth_dev_ops = {
 	.dev_stop                   = ngbe_dev_stop,
 	.dev_close                  = ngbe_dev_close,
 	.dev_reset                  = ngbe_dev_reset,
+	.promiscuous_enable         = ngbe_dev_promiscuous_enable,
+	.promiscuous_disable        = ngbe_dev_promiscuous_disable,
+	.allmulticast_enable        = ngbe_dev_allmulticast_enable,
+	.allmulticast_disable       = ngbe_dev_allmulticast_disable,
 	.link_update                = ngbe_dev_link_update,
 	.stats_get                  = ngbe_dev_stats_get,
 	.xstats_get                 = ngbe_dev_xstats_get,