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 75922460C1; Mon, 20 Jan 2025 10:44:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D289740653; Mon, 20 Jan 2025 10:44:00 +0100 (CET) Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by mails.dpdk.org (Postfix) with ESMTP id 5B27740653 for ; Mon, 20 Jan 2025 10:43:55 +0100 (CET) X-QQ-mid: bizesmtp86t1737366231tn3bapha X-QQ-Originating-IP: K48LZOb+K5AD3p1E8us7sbnx+lnGOC7u+fwRna/4H88= Received: from DSK-zaiyuwang.trustnetic.com ( [115.197.136.137]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 20 Jan 2025 17:43:50 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10778060894216654419 From: Zaiyu Wang To: dev@dpdk.org Cc: Zaiyu Wang , Jiawen Wu Subject: [PATCH v4 08/15] net/ngbe: add VLAN related ops for VF device Date: Mon, 20 Jan 2025 17:42:34 +0800 Message-Id: <20250120094242.1844-9-zaiyuwang@trustnetic.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20250120094242.1844-1-zaiyuwang@trustnetic.com> References: <20250109040227.1016-1-zaiyuwang@trustnetic.com> <20250120094242.1844-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+v2p8NjVRtQ2VwH3U2bzzqihmqguvNE/a0eQilcwCGNLrsTgBZI5fa2 MS4v+ht5ASJuUOBAYvTQAZAFjBmf+W2grYPIgLQZvS/NRq4GUVL3JCKtWkcQHd3AjspjgC1 nqn8ievczZuVpMlgcyGK8Kx6I42qalR5n1lMQs3EEaHGQyA1CKV2FrAuh5WoxiynyN8xcU1 oLuMFK2/QgPIi07BzAAmPlmbaWQ65Kw/ecf66wdRujulLnDdAPQRzChMRzMEVgFwJ+I8SRX beuvhgv30puWiI4jhS/JYlSdhfcq+LwzeQ/Dbt/zCx1QJcJZTmea1G7oDMB9LvvNg664dvA y2/DmJu9YALrikSumiDo8c3tevYnNj3WysMaxq9ss9xnelkYX/8sno7my1C0ocwqYNnAIxp 3laQugQw3QybmVv/8Vstl6QkEApcjGIdiKiQnlat+wWCxM/F5OOUG9efPsKPyuDnJUDWi8N 51DX2LmgD6jFtdGsm49vv4q5PY67+rWAoEf9MdbxwG87EToNI4jTXePUv6MgC5dXkgg/KHz 3foLZMvHOAHbOeV3x/7Ra9C95CfWltwzXVfFbgrshho95R1/rt+Cdk7PI1LTEu8hu12FqBu Szj0iC+SypxXPAdD3wjH+dyhYgRhY0i8FbytkcYJQlr2KGj03mM40vi0X7dJNm8Vqy+BxoQ uUya8rI+pGbZ51poYOPz7Nyf0Rkj15bM2aa/an++LmrzZ/eKJyo3f9DQXDPaslNqlanRpVq qpIqy3cIX755jKbJhGzQLV2qNoVHN2vaxYEbTm4oPd87SZ3fEZjR5BWOb1wMNmm4i5/wwbm CVr7ubL+JuCgg7FP/CrCm4jbTbhRzKvvJxXb6t3vbr7ZpCM5M24W1KDzefx+4OKcM3H9Ko3 CTHujkR97+rKbxPQ6W9oGHxrzrsYpUgo7Z5orM5+2FPLjOwaQl5xkmKIXsvH5J7qNu0ggPu BLnxJyLTDRn00yfh2erq+yh77IT/nR7yh2Ch0yMOsj+oB5Be2T+14L5ZB88GvVBy036JGxZ HlpaoBrRwSC9SeO2RNwfuj/hNX/3k= X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= 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 97d8547cdf..441bf3bded 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