DPDK patches and discussions
 help / color / mirror / Atom feed
From: <wanry@3snic.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@amd.com>, Renyong Wan <wanry@3snic.com>,
	Steven Song <steven.song@3snic.com>
Subject: [PATCH v3 30/32] net/sssnic: support VLAN offload and filter
Date: Fri, 1 Sep 2023 11:28:40 +0800	[thread overview]
Message-ID: <20230901032842.223547-31-wanry@3snic.com> (raw)
In-Reply-To: <20230901032842.223547-1-wanry@3snic.com>

From: Renyong Wan <wanry@3snic.com>

Signed-off-by: Steven Song <steven.song@3snic.com>
Signed-off-by: Renyong Wan <wanry@3snic.com>
---
 doc/guides/nics/features/sssnic.ini  |  2 +
 drivers/net/sssnic/base/sssnic_api.c | 34 +++++++++++
 drivers/net/sssnic/base/sssnic_api.h |  1 +
 drivers/net/sssnic/base/sssnic_cmd.h |  9 +++
 drivers/net/sssnic/sssnic_ethdev.c   | 87 ++++++++++++++++++++++++++++
 5 files changed, 133 insertions(+)

diff --git a/doc/guides/nics/features/sssnic.ini b/doc/guides/nics/features/sssnic.ini
index 9bf05cb968..f5738ac934 100644
--- a/doc/guides/nics/features/sssnic.ini
+++ b/doc/guides/nics/features/sssnic.ini
@@ -19,6 +19,8 @@ RSS hash             = Y
 RSS key update       = Y
 RSS reta update      = Y
 Inner RSS            = Y
+VLAN filter          = Y
+VLAN offload         = Y
 L3 checksum offload  = Y
 L4 checksum offload  = Y
 Inner L3 checksum    = Y
diff --git a/drivers/net/sssnic/base/sssnic_api.c b/drivers/net/sssnic/base/sssnic_api.c
index d91896cdd2..68c16c9c1e 100644
--- a/drivers/net/sssnic/base/sssnic_api.c
+++ b/drivers/net/sssnic/base/sssnic_api.c
@@ -1601,3 +1601,37 @@ sssnic_flow_ctrl_get(struct sssnic_hw *hw, bool *autoneg, bool *rx_en,
 
 	return 0;
 }
+
+int
+sssnic_vlan_filter_set(struct sssnic_hw *hw, uint16_t vid, bool add)
+{
+	int ret;
+	struct sssnic_vlan_filter_set_cmd cmd;
+	struct sssnic_msg msg;
+	uint32_t cmd_len;
+
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.function = SSSNIC_FUNC_IDX(hw);
+	cmd.add = add ? 1 : 0;
+	cmd.vid = vid;
+	cmd_len = sizeof(cmd);
+
+	sssnic_msg_init(&msg, (uint8_t *)&cmd, cmd_len,
+		SSSNIC_SET_PORT_VLAN_FILTER_CMD, SSSNIC_MPU_FUNC_IDX,
+		SSSNIC_LAN_MODULE, SSSNIC_MSG_TYPE_REQ);
+
+	ret = sssnic_mbox_send(hw, &msg, (uint8_t *)&cmd, &cmd_len, 0);
+	if (ret != 0) {
+		PMD_DRV_LOG(ERR, "Failed to send mbox message, ret=%d", ret);
+		return ret;
+	}
+
+	if (cmd_len == 0 || cmd.common.status != 0) {
+		PMD_DRV_LOG(ERR,
+			"Bad response to SSSNIC_SET_PORT_VLAN_FILTER_CMD, len=%u, status=%u",
+			cmd_len, cmd.common.status);
+		return -EIO;
+	}
+
+	return 0;
+}
diff --git a/drivers/net/sssnic/base/sssnic_api.h b/drivers/net/sssnic/base/sssnic_api.h
index 36544a5dc3..28b235dda2 100644
--- a/drivers/net/sssnic/base/sssnic_api.h
+++ b/drivers/net/sssnic/base/sssnic_api.h
@@ -469,5 +469,6 @@ int sssnic_flow_ctrl_set(struct sssnic_hw *hw, bool autoneg, bool rx_en,
 	bool tx_en);
 int sssnic_flow_ctrl_get(struct sssnic_hw *hw, bool *autoneg, bool *rx_en,
 	bool *tx_en);
+int sssnic_vlan_filter_set(struct sssnic_hw *hw, uint16_t vid, bool add);
 
 #endif /* _SSSNIC_API_H_ */
diff --git a/drivers/net/sssnic/base/sssnic_cmd.h b/drivers/net/sssnic/base/sssnic_cmd.h
index d2054fad5a..3e70d0e223 100644
--- a/drivers/net/sssnic/base/sssnic_cmd.h
+++ b/drivers/net/sssnic/base/sssnic_cmd.h
@@ -425,4 +425,13 @@ struct sssnic_flow_ctrl_cmd {
 	uint8_t resvd1[5];
 };
 
+struct sssnic_vlan_filter_set_cmd {
+	struct sssnic_cmd_common common;
+	uint16_t function;
+	uint8_t add;
+	uint8_t resvd0;
+	uint16_t vid;
+	uint16_t resvd1;
+};
+
 #endif /* _SSSNIC_CMD_H_ */
diff --git a/drivers/net/sssnic/sssnic_ethdev.c b/drivers/net/sssnic/sssnic_ethdev.c
index 8999693027..8a1ccff70b 100644
--- a/drivers/net/sssnic/sssnic_ethdev.c
+++ b/drivers/net/sssnic/sssnic_ethdev.c
@@ -16,6 +16,7 @@
 #include "sssnic_ethdev_rss.h"
 
 static int sssnic_ethdev_init(struct rte_eth_dev *ethdev);
+static void sssnic_ethdev_vlan_filter_clean(struct rte_eth_dev *ethdev);
 
 static int
 sssnic_ethdev_infos_get(struct rte_eth_dev *ethdev,
@@ -340,6 +341,7 @@ sssnic_ethdev_release(struct rte_eth_dev *ethdev)
 {
 	struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev);
 
+	sssnic_ethdev_vlan_filter_clean(ethdev);
 	sssnic_ethdev_link_intr_disable(ethdev);
 	sssnic_ethdev_tx_queue_all_release(ethdev);
 	sssnic_ethdev_rx_queue_all_release(ethdev);
@@ -821,6 +823,89 @@ sssnic_ethdev_flow_ctrl_get(struct rte_eth_dev *ethdev,
 	return 0;
 }
 
+static int
+sssnic_ethdev_vlan_offload_set(struct rte_eth_dev *ethdev, int mask)
+{
+	struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev);
+	struct rte_eth_conf *dev_conf = &ethdev->data->dev_conf;
+	uint8_t vlan_strip_en;
+	uint32_t vlan_filter_en;
+	int ret;
+
+	if (mask & RTE_ETH_VLAN_STRIP_MASK) {
+		if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
+			vlan_strip_en = 1;
+		else
+			vlan_strip_en = 0;
+
+		ret = sssnic_vlan_strip_enable_set(hw, vlan_strip_en);
+		if (ret != 0) {
+			PMD_DRV_LOG(ERR, "Failed to %s vlan strip offload",
+				vlan_strip_en ? "enable" : "disable");
+			return ret;
+		}
+	}
+
+	if (mask & RTE_ETH_VLAN_FILTER_MASK) {
+		if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
+			vlan_filter_en = 1;
+		else
+			vlan_filter_en = 0;
+
+		ret = sssnic_vlan_filter_enable_set(hw, vlan_filter_en);
+		if (ret != 0) {
+			PMD_DRV_LOG(ERR, "Failed to %s vlan filter offload",
+				vlan_filter_en ? "enable" : "disable");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int
+sssnic_ethdev_vlan_filter_get(struct rte_eth_dev *ethdev, uint16_t vlan_id)
+{
+	struct rte_vlan_filter_conf *vfc = &ethdev->data->vlan_filter_conf;
+	int vidx = vlan_id / 64;
+	int vbit = vlan_id % 64;
+
+	return !!(vfc->ids[vidx] & RTE_BIT64(vbit));
+}
+
+static int
+sssnic_ethdev_vlan_filter_set(struct rte_eth_dev *ethdev, uint16_t vlan_id,
+	int on)
+{
+	struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev);
+	int ret;
+
+	if (sssnic_ethdev_vlan_filter_get(ethdev, vlan_id) == !!on)
+		return 0;
+
+	ret = sssnic_vlan_filter_set(hw, vlan_id, !!on);
+	if (ret) {
+		PMD_DRV_LOG(ERR,
+			"Failed to %s VLAN filter, vlan_id: %u, port: %u",
+			on ? "add" : "remove", vlan_id, ethdev->data->port_id);
+		return ret;
+	}
+
+	PMD_DRV_LOG(DEBUG, "%s VLAN %u filter to port %u",
+		on ? "Added" : "Removed", vlan_id, ethdev->data->port_id);
+
+	return 0;
+}
+
+static void
+sssnic_ethdev_vlan_filter_clean(struct rte_eth_dev *ethdev)
+{
+	uint16_t vlan_id;
+
+	for (vlan_id = 0; vlan_id <= RTE_ETHER_MAX_VLAN_ID; vlan_id++)
+		sssnic_ethdev_vlan_filter_set(ethdev, vlan_id, 0);
+}
+
 static const struct eth_dev_ops sssnic_ethdev_ops = {
 	.dev_start = sssnic_ethdev_start,
 	.dev_stop = sssnic_ethdev_stop,
@@ -864,6 +949,8 @@ static const struct eth_dev_ops sssnic_ethdev_ops = {
 	.fw_version_get = sssnic_ethdev_fw_version_get,
 	.flow_ctrl_set = sssnic_ethdev_flow_ctrl_set,
 	.flow_ctrl_get = sssnic_ethdev_flow_ctrl_get,
+	.vlan_offload_set = sssnic_ethdev_vlan_offload_set,
+	.vlan_filter_set = sssnic_ethdev_vlan_filter_set,
 };
 
 static int
-- 
2.27.0


  parent reply	other threads:[~2023-09-01  3:32 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01  3:28 [PATCH v3 00/32] Introduce sssnic PMD for 3SNIC's 9x0 serials Ethernet adapters wanry
2023-09-01  3:28 ` [PATCH v3 01/32] net/sssnic: add build and doc infrastructure wanry
2023-09-01  3:28 ` [PATCH v3 02/32] net/sssnic: add log type and log macros wanry
2023-09-01  3:28 ` [PATCH v3 03/32] net/sssnic: support probe and remove wanry
2023-09-01  3:28 ` [PATCH v3 04/32] net/sssnic: initialize hardware base wanry
2023-09-01  3:28 ` [PATCH v3 05/32] net/sssnic: add event queue wanry
2023-09-01  3:28 ` [PATCH v3 06/32] net/sssnic/base: add message definition and utility wanry
2023-09-01  3:28 ` [PATCH v3 07/32] net/sssnic/base: add mailbox support wanry
2023-09-01  3:28 ` [PATCH v3 08/32] net/sssnic/base: add work queue wanry
2023-09-01  3:28 ` [PATCH v3 09/32] net/sssnic/base: add control queue wanry
2023-09-01  3:28 ` [PATCH v3 10/32] net/sssnic: add dev configure and infos get wanry
2023-09-01  3:28 ` [PATCH v3 11/32] net/sssnic: add dev MAC ops wanry
2023-09-01  3:28 ` [PATCH v3 12/32] net/sssnic: support dev link status wanry
2023-09-01  3:28 ` [PATCH v3 13/32] net/sssnic: support link status event wanry
2023-09-01  3:28 ` [PATCH v3 14/32] net/sssnic: support Rx queue setup and release wanry
2023-09-01  3:28 ` [PATCH v3 15/32] net/sssnic: support Tx " wanry
2023-09-01  3:28 ` [PATCH v3 16/32] net/sssnic: support Rx queue start and stop wanry
2023-09-01  3:28 ` [PATCH v3 17/32] net/sssnic: support Tx " wanry
2023-09-01  3:28 ` [PATCH v3 18/32] net/sssnic: add Rx interrupt support wanry
2023-09-01  3:28 ` [PATCH v3 19/32] net/sssnic: support dev start and stop wanry
2023-09-01  3:28 ` [PATCH v3 20/32] net/sssnic: support dev close and reset wanry
2023-09-01  3:28 ` [PATCH v3 21/32] net/sssnic: add allmulticast and promiscuous ops wanry
2023-09-01  3:28 ` [PATCH v3 22/32] net/sssnic: add basic and extended stats ops wanry
2023-09-01  3:28 ` [PATCH v3 23/32] net/sssnic: support Rx packet burst wanry
2023-09-01  3:28 ` [PATCH v3 24/32] net/sssnic: support Tx " wanry
2023-09-01  3:28 ` [PATCH v3 25/32] net/sssnic: add RSS support wanry
2023-09-01  3:28 ` [PATCH v3 26/32] net/sssnic: support dev MTU set wanry
2023-09-01  3:28 ` [PATCH v3 27/32] net/sssnic: support dev queue info get wanry
2023-09-01  3:28 ` [PATCH v3 28/32] net/sssnic: support dev firmware version get wanry
2023-09-01  3:28 ` [PATCH v3 29/32] net/sssnic: add dev flow control ops wanry
2023-09-01  3:28 ` wanry [this message]
2023-09-01  3:28 ` [PATCH v3 31/32] net/sssnic: add generic flow ops wanry
2023-09-01  3:28 ` [PATCH v3 32/32] net/sssnic: add VF dev support wanry

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=20230901032842.223547-31-wanry@3snic.com \
    --to=wanry@3snic.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=steven.song@3snic.com \
    /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).