From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3D33646027; Thu, 9 Jan 2025 05:04:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9A2B140DDC; Thu, 9 Jan 2025 05:03:49 +0100 (CET) Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by mails.dpdk.org (Postfix) with ESMTP id 6AB3040DD5 for ; Thu, 9 Jan 2025 05:03:47 +0100 (CET) X-QQ-mid: bizesmtp84t1736395423tbe14mn0 X-QQ-Originating-IP: MHv3+mHcweW3c8Q5O9ow7gj68Fyf5WH93CZtGdDcVig= Received: from DSK-zaiyuwang.trustnetic.com ( [218.72.126.41]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 09 Jan 2025 12:03:41 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15578004468079634510 From: Zaiyu Wang To: dev@dpdk.org Cc: Zaiyu Wang , Jiawen Wu Subject: [PATCH 08/15] net/ngbe: add vlan related ops for VF device Date: Thu, 9 Jan 2025 12:02:18 +0800 Message-Id: <20250109040227.1016-9-zaiyuwang@trustnetic.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20250109040227.1016-1-zaiyuwang@trustnetic.com> References: <20250109040227.1016-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: N+zv///MAAEkKcxHIT476SlYiL0sG6BiM7VtRcQEkCd3KJf/WyXTPxvp HGs/4zIlkFe/Fw1asTcT4yokGsNmmB4VEshPj0gZuxMcqWpbkLdafIMzRkxdtNmRQj5ranf P35Ys8kl5/ijzG65y4Q7V7xbdm/o0C1mIbyYJjaWom/AP6SMEyF8Xug3C7DDvPWdDDu/3AH BxH0zSmfyqJuFHUs7ys8nugyjSYehP8VlQVaxv4x3+Ie2eQZo4uI6sdqCIvJhPrOaFMXibi KkI1svJpSbvmL3QLn2uvYHTbXLB99UsCEDyGetFG5feGqCaQuyMNjrjxoCW7qPRmZkgswuy AA3mcrY697R6oNW4BDJLEzjXv5+jAsl674ahqgMygUIrou8DzmvkQc1WwnS/65s4kNucY1r 6f2zwqB3KUhPS0qpyZ1P03628692ZPX46FuuxYHMGqqrFCRyrUdQzNf3OKIMffvbYemLZMM 5RkYNSQTkavBsXxelLmQ6Jj3WFkibIMuf7tossN219FOVt+BV50jtc2QIK6VMtWrsfIYQeh 2xTYCpz7owM8BXul45CdYz677SYAr51ZmlEoA4upU5OdG4wfx4sPgy4X8CxGkgJXb1C5tw6 7bAIoyqz1HaOgQF+mrpEZPydxWX1IficGPUjxM/FwTP1G60sToFt9mJmMGc8gwZJ82kqPrQ jvqtyqikEQeL069gmYMbyckBDSg3zgyhsv4v70w2b54u2rrXNvxxQjf6P31ToSh0T3lKcc2 pfTs57LjlAHNytejly0iOOUcDfY5l81i1ELa+200A14c7pBXiE5fxcJcMC3S1vlDvcRsoxq SZHEnsrXsxJdu79W7jgeoZbnSDu6xoIAo5gI/mOB1nR7yKrK3pT+q/TRDm4KbkMGEJ7xRit Me5QMb6FNEMalt5j7fk3oG5WmcY3Q4hxBIZ4gS13Ydjk7bz2lcoNVDLhB0pRr/LtA9pvOS3 iIUIJdGyWTwl3K+JfkVLph2TKAHiaAph7rjyrB0wckDIw2cnni/JC73TPhpquVT2b13sq7R 7x7/Du5zrPK3tTYxUM X-QQ-XMRINFO: Nq+8W0+stu50PRdwbJxPCL0= 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 | 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