From: Zaiyu Wang <zaiyuwang@trustnetic.com>
To: dev@dpdk.org
Cc: Zaiyu Wang <zaiyuwang@trustnetic.com>,
Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [PATCH 08/15] net/ngbe: add vlan related ops for VF device
Date: Thu, 9 Jan 2025 12:02:18 +0800 [thread overview]
Message-ID: <20250109040227.1016-9-zaiyuwang@trustnetic.com> (raw)
In-Reply-To: <20250109040227.1016-1-zaiyuwang@trustnetic.com>
Add support for VLAN filter, offload and strip set feature.
Signed-off-by: Zaiyu Wang <zaiyuwang@trustnetic.com>
---
doc/guides/nics/features/ngbe_vf.ini | 1 +
drivers/net/ngbe/base/ngbe_vf.c | 32 +++++++-
drivers/net/ngbe/base/ngbe_vf.h | 2 +
drivers/net/ngbe/ngbe_ethdev_vf.c | 113 +++++++++++++++++++++++++++
4 files changed, 147 insertions(+), 1 deletion(-)
diff --git a/doc/guides/nics/features/ngbe_vf.ini b/doc/guides/nics/features/ngbe_vf.ini
index 024d161c5e..e365f85e47 100644
--- a/doc/guides/nics/features/ngbe_vf.ini
+++ b/doc/guides/nics/features/ngbe_vf.ini
@@ -12,6 +12,7 @@ Jumbo frame = Y
Scattered Rx = Y
LRO = Y
TSO = Y
+VLAN filter = Y
CRC offload = P
VLAN offload = P
QinQ offload = P
diff --git a/drivers/net/ngbe/base/ngbe_vf.c b/drivers/net/ngbe/base/ngbe_vf.c
index 18bb8d263f..d50806876f 100644
--- a/drivers/net/ngbe/base/ngbe_vf.c
+++ b/drivers/net/ngbe/base/ngbe_vf.c
@@ -261,6 +261,35 @@ s32 ngbevf_update_xcast_mode(struct ngbe_hw *hw, int xcast_mode)
return 0;
}
+/**
+ * ngbe_set_vfta_vf - Set/Unset vlan filter table address
+ * @hw: pointer to the HW structure
+ * @vlan: 12 bit VLAN ID
+ * @vind: unused by VF drivers
+ * @vlan_on: if true then set bit, else clear bit
+ * @vlvf_bypass: boolean flag indicating updating default pool is okay
+ *
+ * Turn on/off specified VLAN in the VLAN filter table.
+ **/
+s32 ngbe_set_vfta_vf(struct ngbe_hw *hw, u32 vlan, u32 vind,
+ bool vlan_on, bool vlvf_bypass)
+{
+ u32 msgbuf[2];
+ s32 ret_val;
+ UNREFERENCED_PARAMETER(vind, vlvf_bypass);
+
+ msgbuf[0] = NGBE_VF_SET_VLAN;
+ msgbuf[1] = vlan;
+ /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
+ msgbuf[0] |= vlan_on << NGBE_VT_MSGINFO_SHIFT;
+
+ ret_val = ngbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
+ if (!ret_val && (msgbuf[0] & NGBE_VT_MSGTYPE_ACK))
+ return 0;
+
+ return ret_val | (msgbuf[0] & NGBE_VT_MSGTYPE_NACK);
+}
+
/**
* ngbe_get_mac_addr_vf - Read device MAC address
* @hw: pointer to the HW structure
@@ -440,10 +469,11 @@ s32 ngbe_init_ops_vf(struct ngbe_hw *hw)
mac->get_mac_addr = ngbe_get_mac_addr_vf;
mac->negotiate_api_version = ngbevf_negotiate_api_version;
- /* RAR, Multicast */
+ /* RAR, Multicast, VLAN */
mac->set_rar = ngbe_set_rar_vf;
mac->set_uc_addr = ngbevf_set_uc_addr_vf;
mac->update_xcast_mode = ngbevf_update_xcast_mode;
+ mac->set_vfta = ngbe_set_vfta_vf;
mac->set_rlpml = ngbevf_rlpml_set_vf;
mac->max_tx_queues = 1;
diff --git a/drivers/net/ngbe/base/ngbe_vf.h b/drivers/net/ngbe/base/ngbe_vf.h
index 3f328a0221..596f41dcb0 100644
--- a/drivers/net/ngbe/base/ngbe_vf.h
+++ b/drivers/net/ngbe/base/ngbe_vf.h
@@ -21,6 +21,8 @@ s32 ngbe_set_rar_vf(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
u32 enable_addr);
s32 ngbevf_set_uc_addr_vf(struct ngbe_hw *hw, u32 index, u8 *addr);
s32 ngbevf_update_xcast_mode(struct ngbe_hw *hw, int xcast_mode);
+s32 ngbe_set_vfta_vf(struct ngbe_hw *hw, u32 vlan, u32 vind,
+ bool vlan_on, bool vlvf_bypass);
s32 ngbevf_rlpml_set_vf(struct ngbe_hw *hw, u16 max_size);
int ngbevf_negotiate_api_version(struct ngbe_hw *hw, int api);
int ngbevf_get_queues(struct ngbe_hw *hw, unsigned int *num_tcs,
diff --git a/drivers/net/ngbe/ngbe_ethdev_vf.c b/drivers/net/ngbe/ngbe_ethdev_vf.c
index 1970bfcd05..193e29d0c1 100644
--- a/drivers/net/ngbe/ngbe_ethdev_vf.c
+++ b/drivers/net/ngbe/ngbe_ethdev_vf.c
@@ -20,6 +20,8 @@
static int ngbevf_dev_info_get(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info);
static int ngbevf_dev_close(struct rte_eth_dev *dev);
+static int ngbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
+static void ngbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
static int ngbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
static int ngbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
static void ngbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
@@ -111,6 +113,8 @@ eth_ngbevf_dev_init(struct rte_eth_dev *eth_dev)
uint32_t tc, tcs;
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
struct ngbe_hw *hw = ngbe_dev_hw(eth_dev);
+ struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(eth_dev);
+ struct ngbe_hwstrip *hwstrip = NGBE_DEV_HWSTRIP(eth_dev);
struct rte_ether_addr *perm_addr =
(struct rte_ether_addr *)hw->mac.perm_addr;
@@ -154,6 +158,12 @@ eth_ngbevf_dev_init(struct rte_eth_dev *eth_dev)
ngbe_map_device_id(hw);
hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
+ /* initialize the vfta */
+ memset(shadow_vfta, 0, sizeof(*shadow_vfta));
+
+ /* initialize the hw strip bitmap*/
+ memset(hwstrip, 0, sizeof(*hwstrip));
+
/* Initialize the shared code (base driver) */
err = ngbe_init_shared_code(hw);
if (err != 0) {
@@ -386,6 +396,106 @@ ngbevf_dev_close(struct rte_eth_dev *dev)
return 0;
}
+static void ngbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
+{
+ struct ngbe_hw *hw = ngbe_dev_hw(dev);
+ struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
+ int i = 0, j = 0, vfta = 0, mask = 1;
+
+ for (i = 0; i < NGBE_VFTA_SIZE; i++) {
+ vfta = shadow_vfta->vfta[i];
+ if (vfta) {
+ mask = 1;
+ for (j = 0; j < 32; j++) {
+ if (vfta & mask)
+ hw->mac.set_vfta(hw, (i << 5) + j, 0,
+ on, false);
+ mask <<= 1;
+ }
+ }
+ }
+}
+
+static int
+ngbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
+{
+ struct ngbe_hw *hw = ngbe_dev_hw(dev);
+ struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
+ uint32_t vid_idx = 0;
+ uint32_t vid_bit = 0;
+ int ret = 0;
+
+ PMD_INIT_FUNC_TRACE();
+
+ /* vind is not used in VF driver, set to 0, check ngbe_set_vfta_vf */
+ ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
+ if (ret) {
+ PMD_INIT_LOG(ERR, "Unable to set VF vlan");
+ return ret;
+ }
+ vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
+ vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
+
+ /* Save what we set and restore it after device reset */
+ if (on)
+ shadow_vfta->vfta[vid_idx] |= vid_bit;
+ else
+ shadow_vfta->vfta[vid_idx] &= ~vid_bit;
+
+ return 0;
+}
+
+static void
+ngbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
+{
+ struct ngbe_hw *hw = ngbe_dev_hw(dev);
+ uint32_t ctrl;
+
+ PMD_INIT_FUNC_TRACE();
+
+ if (queue >= hw->mac.max_rx_queues)
+ return;
+
+ ctrl = rd32(hw, NGBE_RXCFG(queue));
+ if (on)
+ ctrl |= NGBE_RXCFG_VLAN;
+ else
+ ctrl &= ~NGBE_RXCFG_VLAN;
+ wr32(hw, NGBE_RXCFG(queue), ctrl);
+
+ ngbe_vlan_hw_strip_bitmap_set(dev, queue, on);
+}
+
+static int
+ngbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
+{
+ struct ngbe_rx_queue *rxq;
+ uint16_t i;
+ int on = 0;
+
+ /* VF function only support hw strip feature, others are not support */
+ if (mask & RTE_ETH_VLAN_STRIP_MASK) {
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
+ rxq = dev->data->rx_queues[i];
+ on = !!(rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
+ ngbevf_vlan_strip_queue_set(dev, i, on);
+ }
+ }
+
+ return 0;
+}
+
+static int
+ngbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
+{
+ ngbe_config_vlan_strip_on_all_queues(dev, mask);
+
+ ngbevf_vlan_offload_config(dev, mask);
+
+ return 0;
+}
+
+
static int
ngbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
__rte_unused uint32_t index,
@@ -611,6 +721,9 @@ static const struct eth_dev_ops ngbevf_eth_dev_ops = {
.allmulticast_disable = ngbevf_dev_allmulticast_disable,
.dev_infos_get = ngbevf_dev_info_get,
.mtu_set = ngbevf_dev_set_mtu,
+ .vlan_filter_set = ngbevf_vlan_filter_set,
+ .vlan_strip_queue_set = ngbevf_vlan_strip_queue_set,
+ .vlan_offload_set = ngbevf_vlan_offload_set,
.mac_addr_add = ngbevf_add_mac_addr,
.mac_addr_remove = ngbevf_remove_mac_addr,
.mac_addr_set = ngbevf_set_default_mac_addr,
--
2.21.0.windows.1
next prev parent reply other threads:[~2025-01-09 4:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 4:02 [PATCH 00/15] net/ngbe: add VF driver support Zaiyu Wang
2025-01-09 4:02 ` [PATCH 01/15] net/ngbe: add ethdev probe and remove for VF device Zaiyu Wang
2025-01-09 4:02 ` [PATCH 02/15] net/ngbe: add support for PF-VF mailbox interface Zaiyu Wang
2025-01-09 4:02 ` [PATCH 03/15] net/ngbe: add hardware configuration code for VF device Zaiyu Wang
2025-01-09 4:02 ` [PATCH 04/15] net/ngbe: add promiscuous and allmulticast ops " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 05/15] net/ngbe: add set MTU " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 06/15] net/ngbe: add add/remove/set mac addr " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 07/15] net/ngbe: add datapath init code " Zaiyu Wang
2025-01-09 4:02 ` Zaiyu Wang [this message]
2025-01-09 4:02 ` [PATCH 09/15] net/ngbe: add interrupt support " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 10/15] net/ngbe: add link update ops " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 11/15] net/ngbe: add stats and xstats " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 12/15] net/ngbe: add start/stop/reset/close " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 13/15] net/ngbe: add multicast MAC filter " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 14/15] net/ngbe: add dump registers " Zaiyu Wang
2025-01-09 4:02 ` [PATCH 15/15] net/ngbe: add some ops which PF has implemented Zaiyu Wang
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=20250109040227.1016-9-zaiyuwang@trustnetic.com \
--to=zaiyuwang@trustnetic.com \
--cc=dev@dpdk.org \
--cc=jiawenwu@trustnetic.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).