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 D9FB6460A7; Fri, 17 Jan 2025 11:46:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2D35342D89; Fri, 17 Jan 2025 11:43:40 +0100 (CET) Received: from smtpbgjp3.qq.com (smtpbgjp3.qq.com [54.92.39.34]) by mails.dpdk.org (Postfix) with ESMTP id A3C6742D7B for ; Fri, 17 Jan 2025 11:43:36 +0100 (CET) X-QQ-mid: bizesmtpsz8t1737110612tq3o9i7 X-QQ-Originating-IP: gMRJiHWrBc8tfQdkKqagQZQgRtdNsulLer8mmGSmLX8= Received: from DSK-zaiyuwang.trustnetic.com ( [36.24.187.167]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 17 Jan 2025 18:43:31 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15278663110055015663 From: Zaiyu Wang To: dev@dpdk.org Cc: Zaiyu Wang , Jiawen Wu Subject: [PATCH v2 08/15] net/ngbe: add VLAN related ops for VF device Date: Fri, 17 Jan 2025 18:41:07 +0800 Message-Id: <20250117104115.16528-9-zaiyuwang@trustnetic.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20250117104115.16528-1-zaiyuwang@trustnetic.com> References: <20250109040227.1016-1-zaiyuwang@trustnetic.com> <20250117104115.16528-1-zaiyuwang@trustnetic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz5a-1 X-QQ-XMAILINFO: NuZeK9IboVofFkInc6eAbU4dcXTa0JOpPfHfEUcicGrWdZMPGCZOenUv kg8XnO63tvkUa+NL3esUOIrSCdpNXCJIHSTYIBnxxd2IgvvH+/FFfNm/r9CsoHUWB6hWjfb m4elSLGCu0VdWqO7nCm22jak/Od/aijtGyRCfkmbvtm7fou77b9C6jmtO6egOQNaWiDHfhQ xYj91yP9b3ZY42TlxMN1LQLmnnI+iDFq+2nl6qbOHrggFpcyv4lLiJRf7SNQvxMrceGKS/v 385af1goudXqktYCGgLu3+g9gH2W8BGeJbCZVdbSSboFurxw7I12eEbGJSg38Uzvc+kQUX6 9T2p7Nc+77Sh7695Y1wqVacbTT9e3sy0nEnzkoOKICWxJOQ32mDTeh2LB7Yfu8GrIY4euEZ 5AAknI3FvPpU3rX1yRZ4RXDd4CTuWsyRM6vB738abhzeAYpw9PCqNl+RySDsqztywWPc/CK LknY+Hi8b5awdZkfekqywz+P27QLH43Z5Y8hLOBQ+7u+y2Mt3AjcbT28DVk0QDJTW/aE1kv GjOX3y7grZR5FrzdpwFE/XC81TT4ZjWNszeZhE85tq6c7CBXSx2g/lbafUpUriiJMC+AJpE HsT0A6Sh0WJuS0AhBjfo2OBQu57zqujdiSr0YMfqR+8ZDrr6iAPNLLG8ifL3EtH2u4BNkGx +IbVZW/ao0V3kneql9rqSqEv4SSfo/KN/KemuUsNhupN6mwvJFRGGl4hVAJOSPAaexkDQCi jcKu8UxhM76DNdbpKuIQPXsmR/NqLn1Vd8DcRQn6B41zyFg4j4928jPJm/eN/C0Ku1sNTsS d/ZJz3nZX3p5Mb5WDWK7Mn3VVvFoa68zApxuA2dTB7iXatlSeojUktpwUGX1OGT11feoPqB ml3+G2Wp63lYfjJZdfzlA/lSG64yAIBuiakh+nfP2JnaSQ6ukoqALXKqqwv1A5+rFyQtWea SDu1MjnExrk7Kh4otD6Rhy3FJ/XmDrnvYy9T5rl4m3lzOcAVWs7SGWpub2owBJctGF50JIY r9Conen4hLXdOdHnvS X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= 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