From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (unknown [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1CC59460AB; Fri, 17 Jan 2025 12:47:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5DFAC42E6C; Fri, 17 Jan 2025 12:45:30 +0100 (CET) Received: from smtpbg151.qq.com (smtpbg151.qq.com [18.169.211.239]) by mails.dpdk.org (Postfix) with ESMTP id 710F742E66 for ; Fri, 17 Jan 2025 12:45:27 +0100 (CET) X-QQ-mid: bizesmtp85t1737114323ts2afhxz X-QQ-Originating-IP: OTjQPa21whOGjBtxbD06A8NK3PxJFTQM3g5Difdi7PU= Received: from DSK-zaiyuwang.trustnetic.com ( [36.24.187.167]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 17 Jan 2025 19:45:21 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10234097010763673070 From: Zaiyu Wang To: dev@dpdk.org Cc: Zaiyu Wang , Jiawen Wu Subject: [PATCH v3 08/15] net/ngbe: add VLAN related ops for VF device Date: Fri, 17 Jan 2025 19:44:46 +0800 Message-Id: <20250117114455.15864-9-zaiyuwang@trustnetic.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20250117114455.15864-1-zaiyuwang@trustnetic.com> References: <20250109040227.1016-1-zaiyuwang@trustnetic.com> <20250117114455.15864-1-zaiyuwang@trustnetic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz5a-1 X-QQ-XMAILINFO: MHW60DEVusDnpS7m83inHy2CMSlwEzZgDJE0LNlNYJYk7z6zt5i/Lwc4 rOvIet8lqXM6KOo9yxpfwzCLGwACjYT7wGhhfwQ7BK2BWtqQU3hiYcmDYZ+rpZhVT3seLmx Z35b1kiJA9/dqHjAlb5S8kMvls2jxXGeNS4eJlthA8wu23E6pWwaVvYg/5ZpSvMTecT7hUc SUsmo2AzN112dyjimWVF7TtcQd7D+ygzhY+7oLAJSG4IEAeZXTwYuWRA0fEEvMVDO3wuBrh v63MQW2Jc4EapvSnUslqizOCboRueuWXeu9mktXlWTUHDJhFLJaGttFJgGLbKUFx7VC2ZvM G/65hXEzhlYhGQ8FDGU/VfW7B6hcC3liwdg9L4qwbHEtriyN0ZdzWFyFSgjZLjBBJ4XdNx6 Q9Zrvshbhzarb90QH4qUqFR50VSP2CNbEoJ8K7jkArqvOegGZiy2q1TohL555V4Iuk1lE2Q NVwyMJZAEWZm/Hj3S0jMvYmWKC7wdcqa3eapEz5mioVdW3qw7uvFyroeL256uajHl3sy/wT E4JbM4y6mSeMtL76s+UrlfDur077JBCRpPQczJOX5kKXd0zkn+hx0Bf2lllIUHltLTRuM8/ RTPXr94gHuOpKPuYwS0yWMTkGPOkFe/fB0k33o7KR8aNUZ1M0KnU4JVkVri8H7COxWvt2Xg NqWAnBMSAX6L1yjqln3yQFLe2KuX5nRqkvehsDPmMcrnmdOfNKcK4vXrpPTp0BU5Np26wP8 AfGmTngQEX3+SOeh8ytHhk4Y16vNDZRx9yccsPvCZDjOfaMQalE9rdHYkfDladHtscSi0CL yqp5SVNMmd0DnG8D088EvATdp8507mZwmjxjFQuKSvZQGK6LCXiVuQRb2aqNGwCQ9jYn8E7 3mPjUhM092DC07IOWvPUrBBOy0lPkahFvjvE3npx5nIHGgKoOoFMwUe71frw4mzmA8QlyEx eNlHwUOwS9wXB35QvNgfIe3XauU6oMP104wqbQaU6cgoS01yDO/XzzZcwxJ+UpzjK0dwb4X GdZqUWt4TxAStsYn/RGiWilB4q4KI= X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= X-QQ-RECHKSPAM: 0 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 Add support for VLAN filter, offload and strip set feature. Signed-off-by: Zaiyu Wang --- doc/guides/nics/features/ngbe_vf.ini | 1 + drivers/net/ngbe/base/ngbe_vf.c | 33 +++++++- drivers/net/ngbe/base/ngbe_vf.h | 2 + drivers/net/ngbe/ngbe_ethdev_vf.c | 112 +++++++++++++++++++++++++++ 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 ad123684c5..48f3bd73bb 100644 --- a/doc/guides/nics/features/ngbe_vf.ini +++ b/doc/guides/nics/features/ngbe_vf.ini @@ -11,6 +11,7 @@ LRO = Y TSO = Y Promiscuous mode = Y Allmulticast mode = 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 47fee7e14d..039f87423d 100644 --- a/drivers/net/ngbe/base/ngbe_vf.c +++ b/drivers/net/ngbe/base/ngbe_vf.c @@ -262,6 +262,36 @@ 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 @@ -441,10 +471,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 f664656c42..a6048807cc 100644 --- a/drivers/net/ngbe/ngbe_ethdev_vf.c +++ b/drivers/net/ngbe/ngbe_ethdev_vf.c @@ -18,6 +18,8 @@ #define NGBEVF_PMD_NAME "rte_ngbevf_pmd" /* PMD name */ 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); @@ -109,6 +111,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; @@ -152,6 +156,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) { @@ -383,6 +393,105 @@ 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, @@ -608,6 +717,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