[7/8] net/nfp: add support for VLAN insert V2 with NFD3

Message ID 20221128065359.12737-8-chaoyong.he@corigine.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series Add the features for nfp include VLAN strip, QinQ strip, VLAN insert |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Chaoyong He Nov. 28, 2022, 6:53 a.m. UTC
  From: Peng Zhang <peng.zhang@corigine.com>

The firmware support VLAN insert with the descriptor or the metadata.
So adding a NFP_NET_CFG_CTRL_RXVLAN_V2 bit to distinguish them. When
VLAN insert is set, sending the vlan information with the descriptor.
When VLAN insert V2 is set, sending it with the metadata.

Now NFP_NET_CFG_CTRL_L2SWITCH_LOCAL isn't used, so 0x1 << 23 is used
by NFP_NET_CFG_CTRL_RXVLAN_V2.

Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
 drivers/net/nfp/nfp_common.c |  9 ++++++---
 drivers/net/nfp/nfp_ctrl.h   |  2 +-
 drivers/net/nfp/nfp_rxtx.c   | 30 +++++++++++++++++++++++++++++-
 3 files changed, 36 insertions(+), 5 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index 9c740ee9b5..853eb4a3f7 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -195,7 +195,7 @@  nfp_net_log_device_information(const struct nfp_net_hw *hw)
 			NFD_CFG_MAJOR_VERSION_of(hw->ver),
 			NFD_CFG_MINOR_VERSION_of(hw->ver), hw->max_mtu);
 
-	PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", hw->cap,
+	PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", hw->cap,
 			hw->cap & NFP_NET_CFG_CTRL_PROMISC   ? "PROMISC "   : "",
 			hw->cap & NFP_NET_CFG_CTRL_L2BC      ? "L2BCFILT "  : "",
 			hw->cap & NFP_NET_CFG_CTRL_L2MC      ? "L2MCFILT "  : "",
@@ -204,6 +204,7 @@  nfp_net_log_device_information(const struct nfp_net_hw *hw)
 			hw->cap & NFP_NET_CFG_CTRL_RXVLAN    ? "RXVLAN "    : "",
 			hw->cap & NFP_NET_CFG_CTRL_TXVLAN    ? "TXVLAN "    : "",
 			hw->cap & NFP_NET_CFG_CTRL_RXVLAN_V2 ? "RXVLANv2 "  : "",
+			hw->cap & NFP_NET_CFG_CTRL_TXVLAN_V2 ? "TXVLANv2 "  : "",
 			hw->cap & NFP_NET_CFG_CTRL_RXQINQ    ? "RXQINQ "    : "",
 			hw->cap & NFP_NET_CFG_CTRL_SCATTER   ? "SCATTER "   : "",
 			hw->cap & NFP_NET_CFG_CTRL_GATHER    ? "GATHER "    : "",
@@ -418,7 +419,9 @@  nfp_check_offloads(struct rte_eth_dev *dev)
 	hw->mtu = dev->data->mtu;
 
 	if (txmode->offloads & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) {
-		if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
+		if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN_V2)
+			ctrl |= NFP_NET_CFG_CTRL_TXVLAN_V2;
+		else if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
 			ctrl |= NFP_NET_CFG_CTRL_TXVLAN;
 	}
 
@@ -775,7 +778,7 @@  nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 					     RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
 					     RTE_ETH_RX_OFFLOAD_TCP_CKSUM;
 
-	if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
+	if (hw->cap & (NFP_NET_CFG_CTRL_TXVLAN | NFP_NET_CFG_CTRL_TXVLAN_V2))
 		dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 
 	if (hw->cap & NFP_NET_CFG_CTRL_TXCSUM)
diff --git a/drivers/net/nfp/nfp_ctrl.h b/drivers/net/nfp/nfp_ctrl.h
index bffdd8345e..6e2601d174 100644
--- a/drivers/net/nfp/nfp_ctrl.h
+++ b/drivers/net/nfp/nfp_ctrl.h
@@ -103,7 +103,7 @@ 
 #define   NFP_NET_CFG_CTRL_MSIXAUTO       (0x1 << 20) /* MSI-X auto-masking */
 #define   NFP_NET_CFG_CTRL_TXRWB          (0x1 << 21) /* Write-back of TX ring*/
 #define   NFP_NET_CFG_CTRL_L2SWITCH       (0x1 << 22) /* L2 Switch */
-#define   NFP_NET_CFG_CTRL_L2SWITCH_LOCAL (0x1 << 23) /* Switch to local */
+#define   NFP_NET_CFG_CTRL_TXVLAN_V2      (0x1 << 23) /* Enable VLAN insert with metadata */
 #define   NFP_NET_CFG_CTRL_VXLAN          (0x1 << 24) /* Enable VXLAN */
 #define   NFP_NET_CFG_CTRL_NVGRE          (0x1 << 25) /* Enable NVGRE */
 #define   NFP_NET_CFG_CTRL_MSIX_TX_OFF    (0x1 << 26) /* Disable MSIX for TX */
diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c
index 200886111e..293769f240 100644
--- a/drivers/net/nfp/nfp_rxtx.c
+++ b/drivers/net/nfp/nfp_rxtx.c
@@ -833,6 +833,33 @@  nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
 	return 0;
 }
 
+/*
+ * nfp_net_nfd3_tx_vlan() - Set vlan info in the nfd3 tx desc
+ *
+ * If enable NFP_NET_CFG_CTRL_TXVLAN_V2
+ *	Vlan_info is stored in the meta and
+ *	is handled in the nfp_net_nfd3_set_meta_vlan
+ * else if enable NFP_NET_CFG_CTRL_TXVLAN
+ *	Vlan_info is stored in the tx_desc and
+ *	is handled in the nfp_net_nfd3_tx_vlan
+ */
+static void
+nfp_net_nfd3_tx_vlan(struct nfp_net_txq *txq,
+		struct nfp_net_nfd3_tx_desc *txd,
+		struct rte_mbuf *mb)
+{
+	struct nfp_net_hw *hw = txq->hw;
+
+	if ((hw->cap & NFP_NET_CFG_CTRL_TXVLAN_V2) != 0 ||
+		(hw->cap & NFP_NET_CFG_CTRL_TXVLAN) == 0)
+		return;
+
+	if ((mb->ol_flags & RTE_MBUF_F_TX_VLAN) != 0) {
+		txd->flags |= PCIE_DESC_TX_VLAN;
+		txd->vlan = mb->vlan_tci;
+	}
+}
+
 static void
 nfp_net_set_meta_vlan(struct nfp_net_meta_raw *meta_data,
 		struct rte_mbuf *pkt,
@@ -861,7 +888,7 @@  nfp_net_nfd3_set_meta_data(struct nfp_net_meta_raw *meta_data,
 	hw = txq->hw;
 
 	if ((pkt->ol_flags & RTE_MBUF_F_TX_VLAN) != 0 &&
-			(hw->ctrl & NFP_NET_CFG_CTRL_TXVLAN) != 0) {
+			(hw->ctrl & NFP_NET_CFG_CTRL_TXVLAN_V2) != 0) {
 		if (meta_data->length == 0)
 			meta_data->length = NFP_NET_META_HEADER_SIZE;
 		meta_data->length += NFP_NET_META_FIELD_SIZE;
@@ -960,6 +987,7 @@  nfp_net_nfd3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pk
 		txd.data_len = pkt->pkt_len;
 		nfp_net_nfd3_tx_tso(txq, &txd, pkt);
 		nfp_net_nfd3_tx_cksum(txq, &txd, pkt);
+		nfp_net_nfd3_tx_vlan(txq, &txd, pkt);
 
 		/*
 		 * mbuf data_len is the data in one segment and pkt_len data