DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net: add macro for VLAN header length
@ 2021-11-10 17:40 Ferruh Yigit
  2021-11-11  1:34 ` Wang, Haiyue
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Ferruh Yigit @ 2021-11-10 17:40 UTC (permalink / raw)
  To: Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy, Qi Zhang,
	Xiao Wang, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou, Beilei Xing,
	Jingjing Wu, Qiming Yang, Rosen Xu, Haiyue Wang, Jiawen Wu,
	Jian Wang, Maxime Coquelin, Chenbo Xia, Olivier Matz
  Cc: Ferruh Yigit, dev

Multiple drivers are defining macros for VLAN header length, to remove
the redundancy defining macro in the ether header.
And updated drivers to use the new macro.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 drivers/net/bnx2x/bnx2x_vfpf.c       | 2 +-
 drivers/net/bnx2x/bnx2x_vfpf.h       | 2 --
 drivers/net/cxgbe/cxgbe_compat.h     | 1 -
 drivers/net/cxgbe/sge.c              | 2 +-
 drivers/net/fm10k/fm10k.h            | 2 --
 drivers/net/fm10k/fm10k_ethdev.c     | 2 +-
 drivers/net/hinic/hinic_pmd_ethdev.h | 3 +--
 drivers/net/i40e/i40e_ethdev.h       | 4 +---
 drivers/net/iavf/iavf.h              | 3 +--
 drivers/net/ice/ice_dcf_ethdev.c     | 2 +-
 drivers/net/ice/ice_ethdev.h         | 4 +---
 drivers/net/ipn3ke/ipn3ke_ethdev.h   | 3 +--
 drivers/net/ixgbe/ixgbe_ethdev.c     | 4 ++--
 drivers/net/ixgbe/ixgbe_ethdev.h     | 1 -
 drivers/net/ixgbe/ixgbe_rxtx.c       | 4 ++--
 drivers/net/ngbe/ngbe_ethdev.c       | 2 +-
 drivers/net/ngbe/ngbe_ethdev.h       | 1 -
 drivers/net/ngbe/ngbe_rxtx.c         | 2 +-
 drivers/net/txgbe/txgbe_ethdev.c     | 2 +-
 drivers/net/txgbe/txgbe_ethdev.h     | 1 -
 drivers/net/txgbe/txgbe_ethdev_vf.c  | 2 +-
 drivers/net/txgbe/txgbe_rxtx.c       | 4 ++--
 examples/vhost/main.c                | 3 +--
 lib/net/rte_ether.h                  | 5 +++--
 24 files changed, 23 insertions(+), 38 deletions(-)

diff --git a/drivers/net/bnx2x/bnx2x_vfpf.c b/drivers/net/bnx2x/bnx2x_vfpf.c
index 0e8a92cd336e..945e3df84ff8 100644
--- a/drivers/net/bnx2x/bnx2x_vfpf.c
+++ b/drivers/net/bnx2x/bnx2x_vfpf.c
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
 
 	sc->old_bulletin = *bull;
 
diff --git a/drivers/net/bnx2x/bnx2x_vfpf.h b/drivers/net/bnx2x/bnx2x_vfpf.h
index 7aab8b101aaa..957734126687 100644
--- a/drivers/net/bnx2x/bnx2x_vfpf.h
+++ b/drivers/net/bnx2x/bnx2x_vfpf.h
@@ -10,8 +10,6 @@
 
 #include "ecore_sp.h"
 
-#define VLAN_HLEN 4
-
 struct vf_resource_query {
 	uint8_t num_rxqs;
 	uint8_t num_txqs;
diff --git a/drivers/net/cxgbe/cxgbe_compat.h b/drivers/net/cxgbe/cxgbe_compat.h
index 83ae1c2e5a83..8d3737fc6100 100644
--- a/drivers/net/cxgbe/cxgbe_compat.h
+++ b/drivers/net/cxgbe/cxgbe_compat.h
@@ -75,7 +75,6 @@ extern int cxgbe_mbox_logtype;
 #define CXGBE_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
 #define PTR_ALIGN(p, a) ((typeof(p))CXGBE_ALIGN((unsigned long)(p), (a)))
 
-#define VLAN_HLEN 4
 #define ETHER_ADDR_LEN 6
 
 #define rmb()     rte_rmb() /* dpdk rte provided rmb */
diff --git a/drivers/net/cxgbe/sge.c b/drivers/net/cxgbe/sge.c
index 9e464cb3da9f..f623f3e68420 100644
--- a/drivers/net/cxgbe/sge.c
+++ b/drivers/net/cxgbe/sge.c
@@ -72,7 +72,7 @@ static inline unsigned int fl_mtu_bufsize(struct adapter *adapter,
 {
 	struct sge *s = &adapter->sge;
 
-	return CXGBE_ALIGN(s->pktshift + RTE_ETHER_HDR_LEN + VLAN_HLEN + mtu,
+	return CXGBE_ALIGN(s->pktshift + RTE_ETHER_HDR_LEN + RTE_VLAN_HLEN + mtu,
 			   s->fl_align);
 }
 
diff --git a/drivers/net/fm10k/fm10k.h b/drivers/net/fm10k/fm10k.h
index b7522a47a80b..7cfa29faa85a 100644
--- a/drivers/net/fm10k/fm10k.h
+++ b/drivers/net/fm10k/fm10k.h
@@ -81,8 +81,6 @@
 	RTE_MIN(((txq)->nb_desc - 2), (txq)->free_thresh)
 #define FM10K_TX_RS_THRESH_DIV(txq)        ((txq)->nb_desc)
 
-#define FM10K_VLAN_TAG_SIZE 4
-
 /* Maximum number of MAC addresses per PF/VF */
 #define FM10K_MAX_MACADDR_NUM       64
 
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index c25c32314065..7c85a057466a 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -759,7 +759,7 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if ((dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
-				2 * FM10K_VLAN_TAG_SIZE) > buf_size ||
+				2 * RTE_VLAN_HLEN) > buf_size ||
 			rxq->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
 			uint32_t reg;
 			dev->data->scattered_rx = 1;
diff --git a/drivers/net/hinic/hinic_pmd_ethdev.h b/drivers/net/hinic/hinic_pmd_ethdev.h
index 8f1b3d58886f..5eca8b10b9e1 100644
--- a/drivers/net/hinic/hinic_pmd_ethdev.h
+++ b/drivers/net/hinic/hinic_pmd_ethdev.h
@@ -35,9 +35,8 @@
 #define HINIC_MAX_MTU_SIZE              9600
 #define HINIC_MIN_MTU_SIZE              256
 
-#define HINIC_VLAN_TAG_SIZE             4
 #define HINIC_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + HINIC_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 
 #define HINIC_MIN_FRAME_SIZE        (HINIC_MIN_MTU_SIZE + HINIC_ETH_OVERHEAD)
 #define HINIC_MAX_JUMBO_FRAME_SIZE  (HINIC_MAX_MTU_SIZE + HINIC_ETH_OVERHEAD)
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index d8042abbd9be..2d182f8000a6 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -27,8 +27,6 @@
  */
 #define I40E_GL_RXERR1_H(_i)	(0x00318004 + ((_i) * 8))
 
-#define I40E_VLAN_TAG_SIZE        4
-
 #define I40E_AQ_LEN               32
 #define I40E_AQ_BUF_SZ            4096
 /* Number of queues per TC should be one of 1, 2, 4, 8, 16, 32, 64 */
@@ -292,7 +290,7 @@ struct rte_flow {
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define I40E_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + I40E_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define I40E_ETH_MAX_LEN (RTE_ETHER_MTU + I40E_ETH_OVERHEAD)
 
 #define I40E_RXTX_BYTES_H_16_BIT(bytes) ((bytes) & ~I40E_48_BIT_MASK)
diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h
index f413dbed833a..0bb5698583ba 100644
--- a/drivers/net/iavf/iavf.h
+++ b/drivers/net/iavf/iavf.h
@@ -78,9 +78,8 @@
 /* The overhead from MTU to max frame size.
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
-#define IAVF_VLAN_TAG_SIZE               4
 #define IAVF_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + IAVF_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define IAVF_ETH_MAX_LEN (RTE_ETHER_MTU + IAVF_ETH_OVERHEAD)
 
 #define IAVF_32_BIT_WIDTH (CHAR_BIT * 4)
diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index d1e675764127..28f7f7fb72c4 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -81,7 +81,7 @@ ice_dcf_init_rxq(struct rte_eth_dev *dev, struct ice_rx_queue *rxq)
 
 	rxq->max_pkt_len = max_pkt_len;
 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
-	    (rxq->max_pkt_len + 2 * ICE_VLAN_TAG_SIZE) > buf_size) {
+	    (rxq->max_pkt_len + 2 * RTE_VLAN_HLEN) > buf_size) {
 		dev_data->scattered_rx = 1;
 	}
 	rxq->qrx_tail = hw->hw_addr + IAVF_QRX_TAIL1(rxq->queue_id);
diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index 3a5bb9bbc625..d66b29671f1f 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -14,8 +14,6 @@
 #include "base/ice_adminq_cmd.h"
 #include "base/ice_flow.h"
 
-#define ICE_VLAN_TAG_SIZE        4
-
 #define ICE_ADMINQ_LEN               32
 #define ICE_SBIOQ_LEN                32
 #define ICE_MAILBOXQ_LEN             32
@@ -136,7 +134,7 @@
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define ICE_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + ICE_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define ICE_ETH_MAX_LEN (RTE_ETHER_MTU + ICE_ETH_OVERHEAD)
 
 #define ICE_RXTX_BYTES_HIGH(bytes) ((bytes) & ~ICE_40_BIT_MASK)
diff --git a/drivers/net/ipn3ke/ipn3ke_ethdev.h b/drivers/net/ipn3ke/ipn3ke_ethdev.h
index ba3f8821e235..041f13d9c365 100644
--- a/drivers/net/ipn3ke/ipn3ke_ethdev.h
+++ b/drivers/net/ipn3ke/ipn3ke_ethdev.h
@@ -633,13 +633,12 @@ ipn3ke_tm_ops_get(struct rte_eth_dev *ethdev,
 #define IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_MASK \
 	IPN3KE_MASK(0x1, IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_SHIFT)
 
-#define IPN3KE_VLAN_TAG_SIZE    4
 /**
  * The overhead from MTU to max frame size.
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define IPN3KE_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + IPN3KE_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define IPN3KE_ETH_MAX_LEN (RTE_ETHER_MTU + IPN3KE_ETH_OVERHEAD)
 
 #define IPN3KE_MAC_FRAME_SIZE_MAX    9728
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 1911cf2fab05..fe61dba81d68 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -5173,7 +5173,7 @@ ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev->data->dev_started && !dev->data->scattered_rx &&
-	    frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
+	    frame_size + 2 * RTE_VLAN_HLEN >
 			dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
@@ -6341,7 +6341,7 @@ ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
+	    (max_frame + 2 * RTE_VLAN_HLEN >
 			dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 876b670f2682..83e8b5e56a6f 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -43,7 +43,6 @@
 #define IXGBE_NB_STAT_MAPPING_REGS  32
 #define IXGBE_EXTENDED_VLAN	  (uint32_t)(1 << 26) /* EXTENDED VLAN ENABLE */
 #define IXGBE_VFTA_SIZE 128
-#define IXGBE_VLAN_TAG_SIZE 4
 #define IXGBE_HKEY_MAX_INDEX 10
 #define IXGBE_MAX_RX_QUEUE_NUM	128
 #define IXGBE_MAX_INTR_QUEUE_NUM	15
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index cd259430461a..d7c80d424263 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5153,7 +5153,7 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev)
 				       IXGBE_SRRCTL_BSIZEPKT_SHIFT);
 
 		/* It adds dual VLAN length for supporting dual VLAN */
-		if (frame_size + 2 * IXGBE_VLAN_TAG_SIZE > buf_size)
+		if (frame_size + 2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
@@ -5729,7 +5729,7 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
 
 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
 		    /* It adds dual VLAN length for supporting dual VLAN */
-		    (frame_size + 2 * IXGBE_VLAN_TAG_SIZE) > buf_size) {
+		    (frame_size + 2 * RTE_VLAN_HLEN) > buf_size) {
 			if (!dev->data->scattered_rx)
 				PMD_INIT_LOG(DEBUG, "forcing scatter mode");
 			dev->data->scattered_rx = 1;
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 775789f59607..981592f7f495 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -2488,7 +2488,7 @@ ngbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (frame_size + 2 * NGBE_VLAN_TAG_SIZE >
+	    (frame_size + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/ngbe/ngbe_ethdev.h b/drivers/net/ngbe/ngbe_ethdev.h
index c68582e5aea5..bb96f6a5e7e0 100644
--- a/drivers/net/ngbe/ngbe_ethdev.h
+++ b/drivers/net/ngbe/ngbe_ethdev.h
@@ -19,7 +19,6 @@
 #define NGBE_FLAG_NEED_LINK_CONFIG  ((uint32_t)(1 << 4))
 
 #define NGBE_VFTA_SIZE 128
-#define NGBE_VLAN_TAG_SIZE 4
 #define NGBE_HKEY_MAX_INDEX 10
 /*Default value of Max Rx Queue*/
 #define NGBE_MAX_RX_QUEUE_NUM	8
diff --git a/drivers/net/ngbe/ngbe_rxtx.c b/drivers/net/ngbe/ngbe_rxtx.c
index 0feea92588a1..86a5ef5486ec 100644
--- a/drivers/net/ngbe/ngbe_rxtx.c
+++ b/drivers/net/ngbe/ngbe_rxtx.c
@@ -2951,7 +2951,7 @@ ngbe_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if (dev->data->mtu + NGBE_ETH_OVERHEAD +
-				2 * NGBE_VLAN_TAG_SIZE > buf_size)
+				2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index 04afc6134142..47d0e6ea40f2 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -3461,7 +3461,7 @@ txgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (frame_size + 2 * TXGBE_VLAN_TAG_SIZE >
+	    (frame_size + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/txgbe/txgbe_ethdev.h b/drivers/net/txgbe/txgbe_ethdev.h
index 8304b68292da..262dbb5e38ff 100644
--- a/drivers/net/txgbe/txgbe_ethdev.h
+++ b/drivers/net/txgbe/txgbe_ethdev.h
@@ -36,7 +36,6 @@
  * FreeBSD driver.
  */
 #define TXGBE_VFTA_SIZE 128
-#define TXGBE_VLAN_TAG_SIZE 4
 #define TXGBE_HKEY_MAX_INDEX 10
 /*Default value of Max Rx Queue*/
 #define TXGBE_MAX_RX_QUEUE_NUM	128
diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index 67ae69dec30a..c7c298ae2d02 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -1111,7 +1111,7 @@ txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (max_frame + 2 * TXGBE_VLAN_TAG_SIZE >
+	    (max_frame + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/txgbe/txgbe_rxtx.c b/drivers/net/txgbe/txgbe_rxtx.c
index 497af8d22d23..35b77cb271ba 100644
--- a/drivers/net/txgbe/txgbe_rxtx.c
+++ b/drivers/net/txgbe/txgbe_rxtx.c
@@ -4389,7 +4389,7 @@ txgbe_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if (dev->data->mtu + TXGBE_ETH_OVERHEAD +
-				2 * TXGBE_VLAN_TAG_SIZE > buf_size)
+				2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
@@ -4906,7 +4906,7 @@ txgbevf_dev_rx_init(struct rte_eth_dev *dev)
 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
 		    /* It adds dual VLAN length for supporting dual VLAN */
 		    (dev->data->mtu + TXGBE_ETH_OVERHEAD +
-				2 * TXGBE_VLAN_TAG_SIZE) > buf_size) {
+				2 * RTE_VLAN_HLEN) > buf_size) {
 			if (!dev->data->scattered_rx)
 				PMD_INIT_LOG(DEBUG, "forcing scatter mode");
 			dev->data->scattered_rx = 1;
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 8685dfd81b1d..d1d28cec5d3b 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -195,7 +195,6 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE * MAX_VHOST_DEVICE];
 
 #define MBUF_TABLE_DRAIN_TSC	((rte_get_tsc_hz() + US_PER_S - 1) \
 				 / US_PER_S * BURST_TX_DRAIN_US)
-#define VLAN_HLEN       4
 
 static inline int
 open_dma(const char *value)
@@ -1010,7 +1009,7 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	 * by minus length of vlan tag, so need restore
 	 * the packet length by plus it.
 	 */
-	*offset  = VLAN_HLEN;
+	*offset  = RTE_VLAN_HLEN;
 	*vlan_tag = vlan_tags[vdev->vid];
 
 	RTE_LOG_DP(DEBUG, VHOST_DATA,
diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index 1a0dbf0d607c..f079b888c9c7 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -35,9 +35,10 @@ extern "C" {
 	(RTE_ETHER_MAX_LEN - RTE_ETHER_HDR_LEN - \
 		RTE_ETHER_CRC_LEN) /**< Ethernet MTU. */
 
+#define RTE_VLAN_HLEN       4
+/** Maximum VLAN frame length, including CRC. */
 #define RTE_ETHER_MAX_VLAN_FRAME_LEN \
-	(RTE_ETHER_MAX_LEN + 4)
-	/**< Maximum VLAN frame length, including CRC. */
+	(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
 
 #define RTE_ETHER_MAX_JUMBO_FRAME_LEN \
 	0x3F00 /**< Maximum Jumbo frame length, including CRC. */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH] net: add macro for VLAN header length
  2021-11-10 17:40 [PATCH] net: add macro for VLAN header length Ferruh Yigit
@ 2021-11-11  1:34 ` Wang, Haiyue
  2021-11-12  2:36 ` Xu, Rosen
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Wang, Haiyue @ 2021-11-11  1:34 UTC (permalink / raw)
  To: Yigit, Ferruh, Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy,
	Zhang, Qi Z, Wang, Xiao W, Ziyang Xuan, Xiaoyun Wang,
	Guoyang Zhou, Xing, Beilei, Wu, Jingjing, Yang, Qiming, Xu,
	Rosen, Jiawen Wu, Jian Wang, Maxime Coquelin, Xia, Chenbo,
	Olivier Matz
  Cc: dev

> -----Original Message-----
> From: Yigit, Ferruh <ferruh.yigit@intel.com>
> Sent: Thursday, November 11, 2021 01:40
> To: Rasesh Mody <rmody@marvell.com>; Shahed Shaikh <shshaikh@marvell.com>; Rahul Lakkireddy
> <rahul.lakkireddy@chelsio.com>; Zhang, Qi Z <qi.z.zhang@intel.com>; Wang, Xiao W
> <xiao.w.wang@intel.com>; Ziyang Xuan <xuanziyang2@huawei.com>; Xiaoyun Wang
> <cloud.wangxiaoyun@huawei.com>; Guoyang Zhou <zhouguoyang@huawei.com>; Xing, Beilei
> <beilei.xing@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>; Yang, Qiming <qiming.yang@intel.com>;
> Xu, Rosen <rosen.xu@intel.com>; Wang, Haiyue <haiyue.wang@intel.com>; Jiawen Wu
> <jiawenwu@trustnetic.com>; Jian Wang <jianwang@trustnetic.com>; Maxime Coquelin
> <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>; Olivier Matz <olivier.matz@6wind.com>
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; dev@dpdk.org
> Subject: [PATCH] net: add macro for VLAN header length
> 
> Multiple drivers are defining macros for VLAN header length, to remove
> the redundancy defining macro in the ether header.
> And updated drivers to use the new macro.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
>  drivers/net/bnx2x/bnx2x_vfpf.c       | 2 +-
>  drivers/net/bnx2x/bnx2x_vfpf.h       | 2 --
>  drivers/net/cxgbe/cxgbe_compat.h     | 1 -
>  drivers/net/cxgbe/sge.c              | 2 +-
>  drivers/net/fm10k/fm10k.h            | 2 --
>  drivers/net/fm10k/fm10k_ethdev.c     | 2 +-
>  drivers/net/hinic/hinic_pmd_ethdev.h | 3 +--
>  drivers/net/i40e/i40e_ethdev.h       | 4 +---
>  drivers/net/iavf/iavf.h              | 3 +--
>  drivers/net/ice/ice_dcf_ethdev.c     | 2 +-
>  drivers/net/ice/ice_ethdev.h         | 4 +---
>  drivers/net/ipn3ke/ipn3ke_ethdev.h   | 3 +--


>  drivers/net/ixgbe/ixgbe_ethdev.c     | 4 ++--
>  drivers/net/ixgbe/ixgbe_ethdev.h     | 1 -
>  drivers/net/ixgbe/ixgbe_rxtx.c       | 4 ++--

Thanks for the cleanup work. ;-)

Acked-by: Haiyue Wang <haiyue.wang@intel.com>

>  drivers/net/ngbe/ngbe_ethdev.c       | 2 +-
>  drivers/net/ngbe/ngbe_ethdev.h       | 1 -
>  drivers/net/ngbe/ngbe_rxtx.c         | 2 +-
>  drivers/net/txgbe/txgbe_ethdev.c     | 2 +-
>  drivers/net/txgbe/txgbe_ethdev.h     | 1 -
>  drivers/net/txgbe/txgbe_ethdev_vf.c  | 2 +-
>  drivers/net/txgbe/txgbe_rxtx.c       | 4 ++--
>  examples/vhost/main.c                | 3 +--
>  lib/net/rte_ether.h                  | 5 +++--
>  24 files changed, 23 insertions(+), 38 deletions(-)
> 


> --
> 2.31.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH] net: add macro for VLAN header length
  2021-11-10 17:40 [PATCH] net: add macro for VLAN header length Ferruh Yigit
  2021-11-11  1:34 ` Wang, Haiyue
@ 2021-11-12  2:36 ` Xu, Rosen
  2021-11-12  6:09 ` Jiawen Wu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Xu, Rosen @ 2021-11-12  2:36 UTC (permalink / raw)
  To: Yigit, Ferruh, Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy,
	Zhang, Qi Z, Wang, Xiao W, Ziyang Xuan, Xiaoyun Wang,
	Guoyang Zhou, Xing, Beilei, Wu, Jingjing, Yang, Qiming, Wang,
	Haiyue, Jiawen Wu, Jian Wang, Maxime Coquelin, Xia, Chenbo,
	Olivier Matz
  Cc: dev

Hi,

> -----Original Message-----
> From: Yigit, Ferruh <ferruh.yigit@intel.com>
> Sent: Thursday, November 11, 2021 1:40
> To: Rasesh Mody <rmody@marvell.com>; Shahed Shaikh
> <shshaikh@marvell.com>; Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>;
> Zhang, Qi Z <qi.z.zhang@intel.com>; Wang, Xiao W
> <xiao.w.wang@intel.com>; Ziyang Xuan <xuanziyang2@huawei.com>;
> Xiaoyun Wang <cloud.wangxiaoyun@huawei.com>; Guoyang Zhou
> <zhouguoyang@huawei.com>; Xing, Beilei <beilei.xing@intel.com>; Wu,
> Jingjing <jingjing.wu@intel.com>; Yang, Qiming <qiming.yang@intel.com>; Xu,
> Rosen <rosen.xu@intel.com>; Wang, Haiyue <haiyue.wang@intel.com>;
> Jiawen Wu <jiawenwu@trustnetic.com>; Jian Wang
> <jianwang@trustnetic.com>; Maxime Coquelin
> <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>;
> Olivier Matz <olivier.matz@6wind.com>
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; dev@dpdk.org
> Subject: [PATCH] net: add macro for VLAN header length
> 
> Multiple drivers are defining macros for VLAN header length, to remove the
> redundancy defining macro in the ether header.
> And updated drivers to use the new macro.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
>  drivers/net/bnx2x/bnx2x_vfpf.c       | 2 +-
>  drivers/net/bnx2x/bnx2x_vfpf.h       | 2 --
>  drivers/net/cxgbe/cxgbe_compat.h     | 1 -
>  drivers/net/cxgbe/sge.c              | 2 +-
>  drivers/net/fm10k/fm10k.h            | 2 --
>  drivers/net/fm10k/fm10k_ethdev.c     | 2 +-
>  drivers/net/hinic/hinic_pmd_ethdev.h | 3 +--
>  drivers/net/i40e/i40e_ethdev.h       | 4 +---
>  drivers/net/iavf/iavf.h              | 3 +--
>  drivers/net/ice/ice_dcf_ethdev.c     | 2 +-
>  drivers/net/ice/ice_ethdev.h         | 4 +---
>  drivers/net/ipn3ke/ipn3ke_ethdev.h   | 3 +--

Acked-by: Rosen Xu <rosen.xu@intel.com>

>  drivers/net/ixgbe/ixgbe_ethdev.c     | 4 ++--
>  drivers/net/ixgbe/ixgbe_ethdev.h     | 1 -
>  drivers/net/ixgbe/ixgbe_rxtx.c       | 4 ++--
>  drivers/net/ngbe/ngbe_ethdev.c       | 2 +-
>  drivers/net/ngbe/ngbe_ethdev.h       | 1 -
>  drivers/net/ngbe/ngbe_rxtx.c         | 2 +-
>  drivers/net/txgbe/txgbe_ethdev.c     | 2 +-
>  drivers/net/txgbe/txgbe_ethdev.h     | 1 -
>  drivers/net/txgbe/txgbe_ethdev_vf.c  | 2 +-
>  drivers/net/txgbe/txgbe_rxtx.c       | 4 ++--
>  examples/vhost/main.c                | 3 +--
>  lib/net/rte_ether.h                  | 5 +++--
>  24 files changed, 23 insertions(+), 38 deletions(-)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH] net: add macro for VLAN header length
  2021-11-10 17:40 [PATCH] net: add macro for VLAN header length Ferruh Yigit
  2021-11-11  1:34 ` Wang, Haiyue
  2021-11-12  2:36 ` Xu, Rosen
@ 2021-11-12  6:09 ` Jiawen Wu
  2021-11-16 23:14 ` Thomas Monjalon
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Jiawen Wu @ 2021-11-12  6:09 UTC (permalink / raw)
  To: 'Ferruh Yigit', 'Rasesh Mody',
	'Shahed Shaikh', 'Rahul Lakkireddy',
	'Qi Zhang', 'Xiao Wang', 'Ziyang Xuan',
	'Xiaoyun Wang', 'Guoyang Zhou',
	'Beilei Xing', 'Jingjing Wu',
	'Qiming Yang', 'Rosen Xu', 'Haiyue Wang',
	'Jian Wang', 'Maxime Coquelin',
	'Chenbo Xia', 'Olivier Matz'
  Cc: dev

On November 11, 2021 1:40 AM, Ferruh Yigit wrote:
> Multiple drivers are defining macros for VLAN header length, to remove the
> redundancy defining macro in the ether header.
> And updated drivers to use the new macro.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
>  drivers/net/bnx2x/bnx2x_vfpf.c       | 2 +-
>  drivers/net/bnx2x/bnx2x_vfpf.h       | 2 --
>  drivers/net/cxgbe/cxgbe_compat.h     | 1 -
>  drivers/net/cxgbe/sge.c              | 2 +-
>  drivers/net/fm10k/fm10k.h            | 2 --
>  drivers/net/fm10k/fm10k_ethdev.c     | 2 +-
>  drivers/net/hinic/hinic_pmd_ethdev.h | 3 +--
>  drivers/net/i40e/i40e_ethdev.h       | 4 +---
>  drivers/net/iavf/iavf.h              | 3 +--
>  drivers/net/ice/ice_dcf_ethdev.c     | 2 +-
>  drivers/net/ice/ice_ethdev.h         | 4 +---
>  drivers/net/ipn3ke/ipn3ke_ethdev.h   | 3 +--
>  drivers/net/ixgbe/ixgbe_ethdev.c     | 4 ++--
>  drivers/net/ixgbe/ixgbe_ethdev.h     | 1 -
>  drivers/net/ixgbe/ixgbe_rxtx.c       | 4 ++--
>  drivers/net/ngbe/ngbe_ethdev.c       | 2 +-
>  drivers/net/ngbe/ngbe_ethdev.h       | 1 -
>  drivers/net/ngbe/ngbe_rxtx.c         | 2 +-
>  drivers/net/txgbe/txgbe_ethdev.c     | 2 +-
>  drivers/net/txgbe/txgbe_ethdev.h     | 1 -
>  drivers/net/txgbe/txgbe_ethdev_vf.c  | 2 +-
>  drivers/net/txgbe/txgbe_rxtx.c       | 4 ++--

For txgbe/ngbe,

Acked-by: Jiawen Wu <jiawenwu@trustnetic.com>

>  examples/vhost/main.c                | 3 +--
>  lib/net/rte_ether.h                  | 5 +++--
>  24 files changed, 23 insertions(+), 38 deletions(-)




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] net: add macro for VLAN header length
  2021-11-10 17:40 [PATCH] net: add macro for VLAN header length Ferruh Yigit
                   ` (2 preceding siblings ...)
  2021-11-12  6:09 ` Jiawen Wu
@ 2021-11-16 23:14 ` Thomas Monjalon
  2021-11-17 10:00   ` Ferruh Yigit
  2021-11-17 18:08 ` [PATCH v2] " Ferruh Yigit
  2021-11-17 18:24 ` [PATCH v3] " Ferruh Yigit
  5 siblings, 1 reply; 11+ messages in thread
From: Thomas Monjalon @ 2021-11-16 23:14 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy, Qi Zhang,
	Xiao Wang, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou, Beilei Xing,
	Jingjing Wu, Qiming Yang, Rosen Xu, Haiyue Wang, Jiawen Wu,
	Jian Wang, Maxime Coquelin, Chenbo Xia, Olivier Matz, dev

10/11/2021 18:40, Ferruh Yigit:
> Multiple drivers are defining macros for VLAN header length, to remove
> the redundancy defining macro in the ether header.
> And updated drivers to use the new macro.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
[...]
> --- a/lib/net/rte_ether.h
> +++ b/lib/net/rte_ether.h
> +#define RTE_VLAN_HLEN       4

Please could you add a doxygen comment for this constant?

> +/** Maximum VLAN frame length, including CRC. */
>  #define RTE_ETHER_MAX_VLAN_FRAME_LEN \
> -	(RTE_ETHER_MAX_LEN + 4)
> -	/**< Maximum VLAN frame length, including CRC. */
> +	(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)

What about QinQ?



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] net: add macro for VLAN header length
  2021-11-16 23:14 ` Thomas Monjalon
@ 2021-11-17 10:00   ` Ferruh Yigit
  2021-11-17 10:02     ` Thomas Monjalon
  0 siblings, 1 reply; 11+ messages in thread
From: Ferruh Yigit @ 2021-11-17 10:00 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy, Qi Zhang,
	Xiao Wang, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou, Beilei Xing,
	Jingjing Wu, Qiming Yang, Rosen Xu, Haiyue Wang, Jiawen Wu,
	Jian Wang, Maxime Coquelin, Chenbo Xia, Olivier Matz, dev

On 11/16/2021 11:14 PM, Thomas Monjalon wrote:
> 10/11/2021 18:40, Ferruh Yigit:
>> Multiple drivers are defining macros for VLAN header length, to remove
>> the redundancy defining macro in the ether header.
>> And updated drivers to use the new macro.
>>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> [...]
>> --- a/lib/net/rte_ether.h
>> +++ b/lib/net/rte_ether.h
>> +#define RTE_VLAN_HLEN       4
> 
> Please could you add a doxygen comment for this constant?
> 

ack.

>> +/** Maximum VLAN frame length, including CRC. */
>>   #define RTE_ETHER_MAX_VLAN_FRAME_LEN \
>> -	(RTE_ETHER_MAX_LEN + 4)
>> -	/**< Maximum VLAN frame length, including CRC. */
>> +	(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
> 
> What about QinQ?
> 

I am just replacing hardcoded value with macro in this patch.
Changing 'RTE_ETHER_MAX_LEN' may have unexpected affect, and
may not be good thing to the at this stage.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] net: add macro for VLAN header length
  2021-11-17 10:00   ` Ferruh Yigit
@ 2021-11-17 10:02     ` Thomas Monjalon
  2021-11-17 10:12       ` Ferruh Yigit
  0 siblings, 1 reply; 11+ messages in thread
From: Thomas Monjalon @ 2021-11-17 10:02 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy, Qi Zhang,
	Xiao Wang, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou, Beilei Xing,
	Jingjing Wu, Qiming Yang, Rosen Xu, Haiyue Wang, Jiawen Wu,
	Jian Wang, Maxime Coquelin, Chenbo Xia, Olivier Matz, dev

17/11/2021 11:00, Ferruh Yigit:
> On 11/16/2021 11:14 PM, Thomas Monjalon wrote:
> > 10/11/2021 18:40, Ferruh Yigit:
> >> Multiple drivers are defining macros for VLAN header length, to remove
> >> the redundancy defining macro in the ether header.
> >> And updated drivers to use the new macro.
> >>
> >> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > [...]
> >> --- a/lib/net/rte_ether.h
> >> +++ b/lib/net/rte_ether.h
> >> +#define RTE_VLAN_HLEN       4
> > 
> > Please could you add a doxygen comment for this constant?
> > 
> 
> ack.
> 
> >> +/** Maximum VLAN frame length, including CRC. */
> >>   #define RTE_ETHER_MAX_VLAN_FRAME_LEN \
> >> -	(RTE_ETHER_MAX_LEN + 4)
> >> -	/**< Maximum VLAN frame length, including CRC. */
> >> +	(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
> > 
> > What about QinQ?
> > 
> 
> I am just replacing hardcoded value with macro in this patch.
> Changing 'RTE_ETHER_MAX_LEN' may have unexpected affect, and
> may not be good thing to the at this stage.

Sure
But can we take this opportunity to note that this macro
does not take QinQ into account?
Just a comment update?

Same for RTE_VLAN_HLEN, it is only one VLAN.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] net: add macro for VLAN header length
  2021-11-17 10:02     ` Thomas Monjalon
@ 2021-11-17 10:12       ` Ferruh Yigit
  0 siblings, 0 replies; 11+ messages in thread
From: Ferruh Yigit @ 2021-11-17 10:12 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy, Qi Zhang,
	Xiao Wang, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou, Beilei Xing,
	Jingjing Wu, Qiming Yang, Rosen Xu, Haiyue Wang, Jiawen Wu,
	Jian Wang, Maxime Coquelin, Chenbo Xia, Olivier Matz, dev

On 11/17/2021 10:02 AM, Thomas Monjalon wrote:
> 17/11/2021 11:00, Ferruh Yigit:
>> On 11/16/2021 11:14 PM, Thomas Monjalon wrote:
>>> 10/11/2021 18:40, Ferruh Yigit:
>>>> Multiple drivers are defining macros for VLAN header length, to remove
>>>> the redundancy defining macro in the ether header.
>>>> And updated drivers to use the new macro.
>>>>
>>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>> [...]
>>>> --- a/lib/net/rte_ether.h
>>>> +++ b/lib/net/rte_ether.h
>>>> +#define RTE_VLAN_HLEN       4
>>>
>>> Please could you add a doxygen comment for this constant?
>>>
>>
>> ack.
>>
>>>> +/** Maximum VLAN frame length, including CRC. */
>>>>    #define RTE_ETHER_MAX_VLAN_FRAME_LEN \
>>>> -	(RTE_ETHER_MAX_LEN + 4)
>>>> -	/**< Maximum VLAN frame length, including CRC. */
>>>> +	(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
>>>
>>> What about QinQ?
>>>
>>
>> I am just replacing hardcoded value with macro in this patch.
>> Changing 'RTE_ETHER_MAX_LEN' may have unexpected affect, and
>> may not be good thing to the at this stage.
> 
> Sure
> But can we take this opportunity to note that this macro
> does not take QinQ into account?
> Just a comment update?
> 

Yep, a can put a brief note.

> Same for RTE_VLAN_HLEN, it is only one VLAN.
> 
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2] net: add macro for VLAN header length
  2021-11-10 17:40 [PATCH] net: add macro for VLAN header length Ferruh Yigit
                   ` (3 preceding siblings ...)
  2021-11-16 23:14 ` Thomas Monjalon
@ 2021-11-17 18:08 ` Ferruh Yigit
  2021-11-17 18:24 ` [PATCH v3] " Ferruh Yigit
  5 siblings, 0 replies; 11+ messages in thread
From: Ferruh Yigit @ 2021-11-17 18:08 UTC (permalink / raw)
  To: Rasesh Mody, Shahed Shaikh, Rahul Lakkireddy, Apeksha Gupta,
	Sachin Saxena, Qi Zhang, Xiao Wang, Ziyang Xuan, Xiaoyun Wang,
	Guoyang Zhou, Beilei Xing, Jingjing Wu, Qiming Yang, Rosen Xu,
	Haiyue Wang, Jiawen Wu, Jian Wang, Maxime Coquelin, Chenbo Xia,
	Olivier Matz
  Cc: Ferruh Yigit, dev

Multiple drivers are defining macros for VLAN header length, to remove
the redundancy defining macro in the ether header.
And updated drivers to use the new macro.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Haiyue Wang <haiyue.wang@intel.com>
Acked-by: Rosen Xu <rosen.xu@intel.com>
Acked-by: Jiawen Wu <jiawenwu@trustnetic.com>

---
v2:
* update new enetfec driver too
* Add doxygen comment to macro
---
 drivers/net/bnx2x/bnx2x_vfpf.c       | 2 +-
 drivers/net/bnx2x/bnx2x_vfpf.h       | 2 --
 drivers/net/cxgbe/cxgbe_compat.h     | 1 -
 drivers/net/cxgbe/sge.c              | 2 +-
 drivers/net/enetfec/enet_ethdev.h    | 1 -
 drivers/net/enetfec/enet_rxtx.c      | 4 ++--
 drivers/net/fm10k/fm10k.h            | 2 --
 drivers/net/fm10k/fm10k_ethdev.c     | 2 +-
 drivers/net/hinic/hinic_pmd_ethdev.h | 3 +--
 drivers/net/i40e/i40e_ethdev.h       | 4 +---
 drivers/net/iavf/iavf.h              | 3 +--
 drivers/net/ice/ice_dcf_ethdev.c     | 2 +-
 drivers/net/ice/ice_ethdev.h         | 4 +---
 drivers/net/ipn3ke/ipn3ke_ethdev.h   | 3 +--
 drivers/net/ixgbe/ixgbe_ethdev.c     | 4 ++--
 drivers/net/ixgbe/ixgbe_ethdev.h     | 1 -
 drivers/net/ixgbe/ixgbe_rxtx.c       | 4 ++--
 drivers/net/ngbe/ngbe_ethdev.c       | 2 +-
 drivers/net/ngbe/ngbe_ethdev.h       | 1 -
 drivers/net/ngbe/ngbe_rxtx.c         | 2 +-
 drivers/net/txgbe/txgbe_ethdev.c     | 2 +-
 drivers/net/txgbe/txgbe_ethdev.h     | 1 -
 drivers/net/txgbe/txgbe_ethdev_vf.c  | 2 +-
 drivers/net/txgbe/txgbe_rxtx.c       | 4 ++--
 examples/vhost/main.c                | 3 +--
 lib/net/rte_ether.h                  | 5 +++--
 26 files changed, 25 insertions(+), 41 deletions(-)

diff --git a/drivers/net/bnx2x/bnx2x_vfpf.c b/drivers/net/bnx2x/bnx2x_vfpf.c
index 0e8a92cd336e..945e3df84ff8 100644
--- a/drivers/net/bnx2x/bnx2x_vfpf.c
+++ b/drivers/net/bnx2x/bnx2x_vfpf.c
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
 
 	sc->old_bulletin = *bull;
 
diff --git a/drivers/net/bnx2x/bnx2x_vfpf.h b/drivers/net/bnx2x/bnx2x_vfpf.h
index 7aab8b101aaa..957734126687 100644
--- a/drivers/net/bnx2x/bnx2x_vfpf.h
+++ b/drivers/net/bnx2x/bnx2x_vfpf.h
@@ -10,8 +10,6 @@
 
 #include "ecore_sp.h"
 
-#define VLAN_HLEN 4
-
 struct vf_resource_query {
 	uint8_t num_rxqs;
 	uint8_t num_txqs;
diff --git a/drivers/net/cxgbe/cxgbe_compat.h b/drivers/net/cxgbe/cxgbe_compat.h
index 83ae1c2e5a83..8d3737fc6100 100644
--- a/drivers/net/cxgbe/cxgbe_compat.h
+++ b/drivers/net/cxgbe/cxgbe_compat.h
@@ -75,7 +75,6 @@ extern int cxgbe_mbox_logtype;
 #define CXGBE_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
 #define PTR_ALIGN(p, a) ((typeof(p))CXGBE_ALIGN((unsigned long)(p), (a)))
 
-#define VLAN_HLEN 4
 #define ETHER_ADDR_LEN 6
 
 #define rmb()     rte_rmb() /* dpdk rte provided rmb */
diff --git a/drivers/net/cxgbe/sge.c b/drivers/net/cxgbe/sge.c
index 9e464cb3da9f..f623f3e68420 100644
--- a/drivers/net/cxgbe/sge.c
+++ b/drivers/net/cxgbe/sge.c
@@ -72,7 +72,7 @@ static inline unsigned int fl_mtu_bufsize(struct adapter *adapter,
 {
 	struct sge *s = &adapter->sge;
 
-	return CXGBE_ALIGN(s->pktshift + RTE_ETHER_HDR_LEN + VLAN_HLEN + mtu,
+	return CXGBE_ALIGN(s->pktshift + RTE_ETHER_HDR_LEN + RTE_VLAN_HLEN + mtu,
 			   s->fl_align);
 }
 
diff --git a/drivers/net/enetfec/enet_ethdev.h b/drivers/net/enetfec/enet_ethdev.h
index 798b6eee05bd..573b0672cd65 100644
--- a/drivers/net/enetfec/enet_ethdev.h
+++ b/drivers/net/enetfec/enet_ethdev.h
@@ -10,7 +10,6 @@
 #define BD_LEN			49152
 #define ENETFEC_TX_FR_SIZE	2048
 #define ETH_HLEN		RTE_ETHER_HDR_LEN
-#define VLAN_HLEN		4
 
 /* full duplex */
 #define FULL_DUPLEX		0x00
diff --git a/drivers/net/enetfec/enet_rxtx.c b/drivers/net/enetfec/enet_rxtx.c
index eac5ccf69bb7..49b326315dde 100644
--- a/drivers/net/enetfec/enet_rxtx.c
+++ b/drivers/net/enetfec/enet_rxtx.c
@@ -111,9 +111,9 @@ enetfec_recv_pkts(void *rxq1, struct rte_mbuf **rx_pkts,
 			vlan_tag = rte_be_to_cpu_16(vlan_header->vlan_tci);
 
 			vlan_packet_rcvd = true;
-			memmove((uint8_t *)mbuf_data + VLAN_HLEN,
+			memmove((uint8_t *)mbuf_data + RTE_VLAN_HLEN,
 				data, RTE_ETHER_ADDR_LEN * 2);
-			rte_pktmbuf_adj(mbuf, VLAN_HLEN);
+			rte_pktmbuf_adj(mbuf, RTE_VLAN_HLEN);
 		}
 
 		if (rxq->fep->bufdesc_ex &&
diff --git a/drivers/net/fm10k/fm10k.h b/drivers/net/fm10k/fm10k.h
index b7522a47a80b..7cfa29faa85a 100644
--- a/drivers/net/fm10k/fm10k.h
+++ b/drivers/net/fm10k/fm10k.h
@@ -81,8 +81,6 @@
 	RTE_MIN(((txq)->nb_desc - 2), (txq)->free_thresh)
 #define FM10K_TX_RS_THRESH_DIV(txq)        ((txq)->nb_desc)
 
-#define FM10K_VLAN_TAG_SIZE 4
-
 /* Maximum number of MAC addresses per PF/VF */
 #define FM10K_MAX_MACADDR_NUM       64
 
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index c25c32314065..7c85a057466a 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -759,7 +759,7 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if ((dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
-				2 * FM10K_VLAN_TAG_SIZE) > buf_size ||
+				2 * RTE_VLAN_HLEN) > buf_size ||
 			rxq->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
 			uint32_t reg;
 			dev->data->scattered_rx = 1;
diff --git a/drivers/net/hinic/hinic_pmd_ethdev.h b/drivers/net/hinic/hinic_pmd_ethdev.h
index 8f1b3d58886f..5eca8b10b9e1 100644
--- a/drivers/net/hinic/hinic_pmd_ethdev.h
+++ b/drivers/net/hinic/hinic_pmd_ethdev.h
@@ -35,9 +35,8 @@
 #define HINIC_MAX_MTU_SIZE              9600
 #define HINIC_MIN_MTU_SIZE              256
 
-#define HINIC_VLAN_TAG_SIZE             4
 #define HINIC_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + HINIC_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 
 #define HINIC_MIN_FRAME_SIZE        (HINIC_MIN_MTU_SIZE + HINIC_ETH_OVERHEAD)
 #define HINIC_MAX_JUMBO_FRAME_SIZE  (HINIC_MAX_MTU_SIZE + HINIC_ETH_OVERHEAD)
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index d8042abbd9be..2d182f8000a6 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -27,8 +27,6 @@
  */
 #define I40E_GL_RXERR1_H(_i)	(0x00318004 + ((_i) * 8))
 
-#define I40E_VLAN_TAG_SIZE        4
-
 #define I40E_AQ_LEN               32
 #define I40E_AQ_BUF_SZ            4096
 /* Number of queues per TC should be one of 1, 2, 4, 8, 16, 32, 64 */
@@ -292,7 +290,7 @@ struct rte_flow {
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define I40E_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + I40E_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define I40E_ETH_MAX_LEN (RTE_ETHER_MTU + I40E_ETH_OVERHEAD)
 
 #define I40E_RXTX_BYTES_H_16_BIT(bytes) ((bytes) & ~I40E_48_BIT_MASK)
diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h
index f413dbed833a..0bb5698583ba 100644
--- a/drivers/net/iavf/iavf.h
+++ b/drivers/net/iavf/iavf.h
@@ -78,9 +78,8 @@
 /* The overhead from MTU to max frame size.
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
-#define IAVF_VLAN_TAG_SIZE               4
 #define IAVF_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + IAVF_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define IAVF_ETH_MAX_LEN (RTE_ETHER_MTU + IAVF_ETH_OVERHEAD)
 
 #define IAVF_32_BIT_WIDTH (CHAR_BIT * 4)
diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index d1e675764127..28f7f7fb72c4 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -81,7 +81,7 @@ ice_dcf_init_rxq(struct rte_eth_dev *dev, struct ice_rx_queue *rxq)
 
 	rxq->max_pkt_len = max_pkt_len;
 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
-	    (rxq->max_pkt_len + 2 * ICE_VLAN_TAG_SIZE) > buf_size) {
+	    (rxq->max_pkt_len + 2 * RTE_VLAN_HLEN) > buf_size) {
 		dev_data->scattered_rx = 1;
 	}
 	rxq->qrx_tail = hw->hw_addr + IAVF_QRX_TAIL1(rxq->queue_id);
diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index f8d0f0c6ee26..11f7eb435233 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -14,8 +14,6 @@
 #include "base/ice_adminq_cmd.h"
 #include "base/ice_flow.h"
 
-#define ICE_VLAN_TAG_SIZE        4
-
 #define ICE_ADMINQ_LEN               32
 #define ICE_SBIOQ_LEN                32
 #define ICE_MAILBOXQ_LEN             32
@@ -136,7 +134,7 @@
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define ICE_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + ICE_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define ICE_ETH_MAX_LEN (RTE_ETHER_MTU + ICE_ETH_OVERHEAD)
 
 #define ICE_RXTX_BYTES_HIGH(bytes) ((bytes) & ~ICE_40_BIT_MASK)
diff --git a/drivers/net/ipn3ke/ipn3ke_ethdev.h b/drivers/net/ipn3ke/ipn3ke_ethdev.h
index ba3f8821e235..041f13d9c365 100644
--- a/drivers/net/ipn3ke/ipn3ke_ethdev.h
+++ b/drivers/net/ipn3ke/ipn3ke_ethdev.h
@@ -633,13 +633,12 @@ ipn3ke_tm_ops_get(struct rte_eth_dev *ethdev,
 #define IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_MASK \
 	IPN3KE_MASK(0x1, IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_SHIFT)
 
-#define IPN3KE_VLAN_TAG_SIZE    4
 /**
  * The overhead from MTU to max frame size.
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define IPN3KE_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + IPN3KE_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define IPN3KE_ETH_MAX_LEN (RTE_ETHER_MTU + IPN3KE_ETH_OVERHEAD)
 
 #define IPN3KE_MAC_FRAME_SIZE_MAX    9728
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 1911cf2fab05..fe61dba81d68 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -5173,7 +5173,7 @@ ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev->data->dev_started && !dev->data->scattered_rx &&
-	    frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
+	    frame_size + 2 * RTE_VLAN_HLEN >
 			dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
@@ -6341,7 +6341,7 @@ ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
+	    (max_frame + 2 * RTE_VLAN_HLEN >
 			dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 876b670f2682..83e8b5e56a6f 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -43,7 +43,6 @@
 #define IXGBE_NB_STAT_MAPPING_REGS  32
 #define IXGBE_EXTENDED_VLAN	  (uint32_t)(1 << 26) /* EXTENDED VLAN ENABLE */
 #define IXGBE_VFTA_SIZE 128
-#define IXGBE_VLAN_TAG_SIZE 4
 #define IXGBE_HKEY_MAX_INDEX 10
 #define IXGBE_MAX_RX_QUEUE_NUM	128
 #define IXGBE_MAX_INTR_QUEUE_NUM	15
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index cd259430461a..d7c80d424263 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5153,7 +5153,7 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev)
 				       IXGBE_SRRCTL_BSIZEPKT_SHIFT);
 
 		/* It adds dual VLAN length for supporting dual VLAN */
-		if (frame_size + 2 * IXGBE_VLAN_TAG_SIZE > buf_size)
+		if (frame_size + 2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
@@ -5729,7 +5729,7 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
 
 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
 		    /* It adds dual VLAN length for supporting dual VLAN */
-		    (frame_size + 2 * IXGBE_VLAN_TAG_SIZE) > buf_size) {
+		    (frame_size + 2 * RTE_VLAN_HLEN) > buf_size) {
 			if (!dev->data->scattered_rx)
 				PMD_INIT_LOG(DEBUG, "forcing scatter mode");
 			dev->data->scattered_rx = 1;
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 775789f59607..981592f7f495 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -2488,7 +2488,7 @@ ngbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (frame_size + 2 * NGBE_VLAN_TAG_SIZE >
+	    (frame_size + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/ngbe/ngbe_ethdev.h b/drivers/net/ngbe/ngbe_ethdev.h
index c68582e5aea5..bb96f6a5e7e0 100644
--- a/drivers/net/ngbe/ngbe_ethdev.h
+++ b/drivers/net/ngbe/ngbe_ethdev.h
@@ -19,7 +19,6 @@
 #define NGBE_FLAG_NEED_LINK_CONFIG  ((uint32_t)(1 << 4))
 
 #define NGBE_VFTA_SIZE 128
-#define NGBE_VLAN_TAG_SIZE 4
 #define NGBE_HKEY_MAX_INDEX 10
 /*Default value of Max Rx Queue*/
 #define NGBE_MAX_RX_QUEUE_NUM	8
diff --git a/drivers/net/ngbe/ngbe_rxtx.c b/drivers/net/ngbe/ngbe_rxtx.c
index 0feea92588a1..86a5ef5486ec 100644
--- a/drivers/net/ngbe/ngbe_rxtx.c
+++ b/drivers/net/ngbe/ngbe_rxtx.c
@@ -2951,7 +2951,7 @@ ngbe_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if (dev->data->mtu + NGBE_ETH_OVERHEAD +
-				2 * NGBE_VLAN_TAG_SIZE > buf_size)
+				2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index 04afc6134142..47d0e6ea40f2 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -3461,7 +3461,7 @@ txgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (frame_size + 2 * TXGBE_VLAN_TAG_SIZE >
+	    (frame_size + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/txgbe/txgbe_ethdev.h b/drivers/net/txgbe/txgbe_ethdev.h
index 8304b68292da..262dbb5e38ff 100644
--- a/drivers/net/txgbe/txgbe_ethdev.h
+++ b/drivers/net/txgbe/txgbe_ethdev.h
@@ -36,7 +36,6 @@
  * FreeBSD driver.
  */
 #define TXGBE_VFTA_SIZE 128
-#define TXGBE_VLAN_TAG_SIZE 4
 #define TXGBE_HKEY_MAX_INDEX 10
 /*Default value of Max Rx Queue*/
 #define TXGBE_MAX_RX_QUEUE_NUM	128
diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index 67ae69dec30a..c7c298ae2d02 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -1111,7 +1111,7 @@ txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (max_frame + 2 * TXGBE_VLAN_TAG_SIZE >
+	    (max_frame + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/txgbe/txgbe_rxtx.c b/drivers/net/txgbe/txgbe_rxtx.c
index 497af8d22d23..35b77cb271ba 100644
--- a/drivers/net/txgbe/txgbe_rxtx.c
+++ b/drivers/net/txgbe/txgbe_rxtx.c
@@ -4389,7 +4389,7 @@ txgbe_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if (dev->data->mtu + TXGBE_ETH_OVERHEAD +
-				2 * TXGBE_VLAN_TAG_SIZE > buf_size)
+				2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
@@ -4906,7 +4906,7 @@ txgbevf_dev_rx_init(struct rte_eth_dev *dev)
 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
 		    /* It adds dual VLAN length for supporting dual VLAN */
 		    (dev->data->mtu + TXGBE_ETH_OVERHEAD +
-				2 * TXGBE_VLAN_TAG_SIZE) > buf_size) {
+				2 * RTE_VLAN_HLEN) > buf_size) {
 			if (!dev->data->scattered_rx)
 				PMD_INIT_LOG(DEBUG, "forcing scatter mode");
 			dev->data->scattered_rx = 1;
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 8bf61b32b669..33d023aa3973 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -195,7 +195,6 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE * MAX_VHOST_DEVICE];
 
 #define MBUF_TABLE_DRAIN_TSC	((rte_get_tsc_hz() + US_PER_S - 1) \
 				 / US_PER_S * BURST_TX_DRAIN_US)
-#define VLAN_HLEN       4
 
 static inline int
 open_dma(const char *value)
@@ -1015,7 +1014,7 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	 * by minus length of vlan tag, so need restore
 	 * the packet length by plus it.
 	 */
-	*offset  = VLAN_HLEN;
+	*offset  = RTE_VLAN_HLEN;
 	*vlan_tag = vlan_tags[vdev->vid];
 
 	RTE_LOG_DP(DEBUG, VHOST_DATA,
diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index 1a0dbf0d607c..3d9852d9e29a 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -35,9 +35,10 @@ extern "C" {
 	(RTE_ETHER_MAX_LEN - RTE_ETHER_HDR_LEN - \
 		RTE_ETHER_CRC_LEN) /**< Ethernet MTU. */
 
+#define RTE_VLAN_HLEN       4  /**< VLAN (IEEE 802.1Q) header length. */
+/** Maximum VLAN frame length (excluding QinQ), including CRC. */
 #define RTE_ETHER_MAX_VLAN_FRAME_LEN \
-	(RTE_ETHER_MAX_LEN + 4)
-	/**< Maximum VLAN frame length, including CRC. */
+	(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
 
 #define RTE_ETHER_MAX_JUMBO_FRAME_LEN \
 	0x3F00 /**< Maximum Jumbo frame length, including CRC. */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3] net: add macro for VLAN header length
  2021-11-10 17:40 [PATCH] net: add macro for VLAN header length Ferruh Yigit
                   ` (4 preceding siblings ...)
  2021-11-17 18:08 ` [PATCH v2] " Ferruh Yigit
@ 2021-11-17 18:24 ` Ferruh Yigit
  2021-11-17 18:54   ` Thomas Monjalon
  5 siblings, 1 reply; 11+ messages in thread
From: Ferruh Yigit @ 2021-11-17 18:24 UTC (permalink / raw)
  To: Chandubabu Namburu, Rasesh Mody, Shahed Shaikh, Ajit Khaparde,
	Somnath Kotur, Rahul Lakkireddy, Apeksha Gupta, Sachin Saxena,
	Qi Zhang, Xiao Wang, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou,
	Min Hu (Connor),
	Yisen Zhuang, Lijun Ou, Beilei Xing, Jingjing Wu, Qiming Yang,
	Rosen Xu, Haiyue Wang, Zyta Szpak, Liron Himi, Jiawen Wu,
	Jian Wang, Maxime Coquelin, Chenbo Xia, Olivier Matz
  Cc: Ferruh Yigit, dev

Multiple drivers are defining macros for VLAN header length, to remove
the redundancy defining macro in the ether header.
And updated drivers to use the new macro.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Haiyue Wang <haiyue.wang@intel.com>
Acked-by: Rosen Xu <rosen.xu@intel.com>
Acked-by: Jiawen Wu <jiawenwu@trustnetic.com>

---
v2:
* update new enetfec driver too
* Add doxygen comment to macro

v3:
*update more drivers: axgbe, bnxt, hns3, mvneta, mvpp2
---
 drivers/net/axgbe/axgbe_dev.c        | 2 +-
 drivers/net/axgbe/axgbe_ethdev.h     | 3 +--
 drivers/net/bnx2x/bnx2x_vfpf.c       | 2 +-
 drivers/net/bnx2x/bnx2x_vfpf.h       | 2 --
 drivers/net/bnxt/bnxt.h              | 5 ++---
 drivers/net/bnxt/bnxt_hwrm.c         | 2 +-
 drivers/net/cxgbe/cxgbe_compat.h     | 1 -
 drivers/net/cxgbe/sge.c              | 2 +-
 drivers/net/enetfec/enet_ethdev.h    | 1 -
 drivers/net/enetfec/enet_rxtx.c      | 4 ++--
 drivers/net/fm10k/fm10k.h            | 2 --
 drivers/net/fm10k/fm10k_ethdev.c     | 2 +-
 drivers/net/hinic/hinic_pmd_ethdev.h | 3 +--
 drivers/net/hns3/hns3_ethdev.h       | 3 +--
 drivers/net/i40e/i40e_ethdev.h       | 4 +---
 drivers/net/iavf/iavf.h              | 3 +--
 drivers/net/ice/ice_dcf_ethdev.c     | 2 +-
 drivers/net/ice/ice_ethdev.h         | 4 +---
 drivers/net/ipn3ke/ipn3ke_ethdev.h   | 3 +--
 drivers/net/ixgbe/ixgbe_ethdev.c     | 4 ++--
 drivers/net/ixgbe/ixgbe_ethdev.h     | 1 -
 drivers/net/ixgbe/ixgbe_rxtx.c       | 4 ++--
 drivers/net/mvneta/mvneta_ethdev.h   | 3 +--
 drivers/net/mvpp2/mrvl_ethdev.h      | 3 +--
 drivers/net/ngbe/ngbe_ethdev.c       | 2 +-
 drivers/net/ngbe/ngbe_ethdev.h       | 1 -
 drivers/net/ngbe/ngbe_rxtx.c         | 2 +-
 drivers/net/txgbe/txgbe_ethdev.c     | 2 +-
 drivers/net/txgbe/txgbe_ethdev.h     | 1 -
 drivers/net/txgbe/txgbe_ethdev_vf.c  | 2 +-
 drivers/net/txgbe/txgbe_rxtx.c       | 4 ++--
 examples/vhost/main.c                | 3 +--
 lib/net/rte_ether.h                  | 5 +++--
 33 files changed, 33 insertions(+), 54 deletions(-)

diff --git a/drivers/net/axgbe/axgbe_dev.c b/drivers/net/axgbe/axgbe_dev.c
index 3aaa2193272f..daeb3308f468 100644
--- a/drivers/net/axgbe/axgbe_dev.c
+++ b/drivers/net/axgbe/axgbe_dev.c
@@ -51,7 +51,7 @@ static int get_lastbit_set(int x)
 static inline unsigned int axgbe_get_max_frame(struct axgbe_port *pdata)
 {
 	return pdata->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
-		RTE_ETHER_CRC_LEN + VLAN_HLEN;
+		RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN;
 }
 
 /* query busy bit */
diff --git a/drivers/net/axgbe/axgbe_ethdev.h b/drivers/net/axgbe/axgbe_ethdev.h
index 0a3e1c59df1a..a207f2ae1bc5 100644
--- a/drivers/net/axgbe/axgbe_ethdev.h
+++ b/drivers/net/axgbe/axgbe_ethdev.h
@@ -12,11 +12,10 @@
 #include "rte_time.h"
 
 #define IRQ				0xff
-#define VLAN_HLEN			4
 
 #define AXGBE_TX_MAX_BUF_SIZE		(0x3fff & ~(64 - 1))
 #define AXGBE_RX_MAX_BUF_SIZE		(0x3fff & ~(64 - 1))
-#define AXGBE_RX_MIN_BUF_SIZE		(RTE_ETHER_MAX_LEN + VLAN_HLEN)
+#define AXGBE_RX_MIN_BUF_SIZE		(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
 #define AXGBE_MAX_MAC_ADDRS		32
 #define AXGBE_MAX_HASH_MAC_ADDRS	256
 
diff --git a/drivers/net/bnx2x/bnx2x_vfpf.c b/drivers/net/bnx2x/bnx2x_vfpf.c
index 0e8a92cd336e..945e3df84ff8 100644
--- a/drivers/net/bnx2x/bnx2x_vfpf.c
+++ b/drivers/net/bnx2x/bnx2x_vfpf.c
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
 
 	sc->old_bulletin = *bull;
 
diff --git a/drivers/net/bnx2x/bnx2x_vfpf.h b/drivers/net/bnx2x/bnx2x_vfpf.h
index 7aab8b101aaa..957734126687 100644
--- a/drivers/net/bnx2x/bnx2x_vfpf.h
+++ b/drivers/net/bnx2x/bnx2x_vfpf.h
@@ -10,8 +10,6 @@
 
 #include "ecore_sp.h"
 
-#define VLAN_HLEN 4
-
 struct vf_resource_query {
 	uint8_t num_rxqs;
 	uint8_t num_txqs;
diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index 04b994e5ec7a..234161053fc5 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -76,14 +76,13 @@
 	((bp)->pdev->id.subsystem_device_id == BROADCOM_DEV_957508_N2100)
 
 #define BNXT_MAX_MTU		9574
-#define VLAN_TAG_SIZE		4
 #define BNXT_NUM_VLANS		2
 #define BNXT_MAX_PKT_LEN	(BNXT_MAX_MTU + RTE_ETHER_HDR_LEN +\
 				 RTE_ETHER_CRC_LEN +\
-				 (BNXT_NUM_VLANS * VLAN_TAG_SIZE))
+				 (BNXT_NUM_VLANS * RTE_VLAN_HLEN))
 /* FW adds extra 4 bytes for FCS */
 #define BNXT_VNIC_MRU(mtu)\
-	((mtu) + RTE_ETHER_HDR_LEN + VLAN_TAG_SIZE * BNXT_NUM_VLANS)
+	((mtu) + RTE_ETHER_HDR_LEN + RTE_VLAN_HLEN * BNXT_NUM_VLANS)
 #define BNXT_VF_RSV_NUM_RSS_CTX	1
 #define BNXT_VF_RSV_NUM_L2_CTX	4
 /* TODO: For now, do not support VMDq/RFS on VFs. */
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 67ed807dad8f..6de3b92c4029 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -3557,7 +3557,7 @@ bnxt_fill_vf_func_cfg_req_old(struct bnxt *bp,
 			HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
 
 	req->admin_mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
-					  RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
+					  RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN *
 					  BNXT_NUM_VLANS);
 	req->mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
 	req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
diff --git a/drivers/net/cxgbe/cxgbe_compat.h b/drivers/net/cxgbe/cxgbe_compat.h
index 83ae1c2e5a83..8d3737fc6100 100644
--- a/drivers/net/cxgbe/cxgbe_compat.h
+++ b/drivers/net/cxgbe/cxgbe_compat.h
@@ -75,7 +75,6 @@ extern int cxgbe_mbox_logtype;
 #define CXGBE_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
 #define PTR_ALIGN(p, a) ((typeof(p))CXGBE_ALIGN((unsigned long)(p), (a)))
 
-#define VLAN_HLEN 4
 #define ETHER_ADDR_LEN 6
 
 #define rmb()     rte_rmb() /* dpdk rte provided rmb */
diff --git a/drivers/net/cxgbe/sge.c b/drivers/net/cxgbe/sge.c
index 9e464cb3da9f..f623f3e68420 100644
--- a/drivers/net/cxgbe/sge.c
+++ b/drivers/net/cxgbe/sge.c
@@ -72,7 +72,7 @@ static inline unsigned int fl_mtu_bufsize(struct adapter *adapter,
 {
 	struct sge *s = &adapter->sge;
 
-	return CXGBE_ALIGN(s->pktshift + RTE_ETHER_HDR_LEN + VLAN_HLEN + mtu,
+	return CXGBE_ALIGN(s->pktshift + RTE_ETHER_HDR_LEN + RTE_VLAN_HLEN + mtu,
 			   s->fl_align);
 }
 
diff --git a/drivers/net/enetfec/enet_ethdev.h b/drivers/net/enetfec/enet_ethdev.h
index 798b6eee05bd..573b0672cd65 100644
--- a/drivers/net/enetfec/enet_ethdev.h
+++ b/drivers/net/enetfec/enet_ethdev.h
@@ -10,7 +10,6 @@
 #define BD_LEN			49152
 #define ENETFEC_TX_FR_SIZE	2048
 #define ETH_HLEN		RTE_ETHER_HDR_LEN
-#define VLAN_HLEN		4
 
 /* full duplex */
 #define FULL_DUPLEX		0x00
diff --git a/drivers/net/enetfec/enet_rxtx.c b/drivers/net/enetfec/enet_rxtx.c
index eac5ccf69bb7..49b326315dde 100644
--- a/drivers/net/enetfec/enet_rxtx.c
+++ b/drivers/net/enetfec/enet_rxtx.c
@@ -111,9 +111,9 @@ enetfec_recv_pkts(void *rxq1, struct rte_mbuf **rx_pkts,
 			vlan_tag = rte_be_to_cpu_16(vlan_header->vlan_tci);
 
 			vlan_packet_rcvd = true;
-			memmove((uint8_t *)mbuf_data + VLAN_HLEN,
+			memmove((uint8_t *)mbuf_data + RTE_VLAN_HLEN,
 				data, RTE_ETHER_ADDR_LEN * 2);
-			rte_pktmbuf_adj(mbuf, VLAN_HLEN);
+			rte_pktmbuf_adj(mbuf, RTE_VLAN_HLEN);
 		}
 
 		if (rxq->fep->bufdesc_ex &&
diff --git a/drivers/net/fm10k/fm10k.h b/drivers/net/fm10k/fm10k.h
index b7522a47a80b..7cfa29faa85a 100644
--- a/drivers/net/fm10k/fm10k.h
+++ b/drivers/net/fm10k/fm10k.h
@@ -81,8 +81,6 @@
 	RTE_MIN(((txq)->nb_desc - 2), (txq)->free_thresh)
 #define FM10K_TX_RS_THRESH_DIV(txq)        ((txq)->nb_desc)
 
-#define FM10K_VLAN_TAG_SIZE 4
-
 /* Maximum number of MAC addresses per PF/VF */
 #define FM10K_MAX_MACADDR_NUM       64
 
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index c25c32314065..7c85a057466a 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -759,7 +759,7 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if ((dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
-				2 * FM10K_VLAN_TAG_SIZE) > buf_size ||
+				2 * RTE_VLAN_HLEN) > buf_size ||
 			rxq->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
 			uint32_t reg;
 			dev->data->scattered_rx = 1;
diff --git a/drivers/net/hinic/hinic_pmd_ethdev.h b/drivers/net/hinic/hinic_pmd_ethdev.h
index 8f1b3d58886f..5eca8b10b9e1 100644
--- a/drivers/net/hinic/hinic_pmd_ethdev.h
+++ b/drivers/net/hinic/hinic_pmd_ethdev.h
@@ -35,9 +35,8 @@
 #define HINIC_MAX_MTU_SIZE              9600
 #define HINIC_MIN_MTU_SIZE              256
 
-#define HINIC_VLAN_TAG_SIZE             4
 #define HINIC_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + HINIC_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 
 #define HINIC_MIN_FRAME_SIZE        (HINIC_MIN_MTU_SIZE + HINIC_ETH_OVERHEAD)
 #define HINIC_MAX_JUMBO_FRAME_SIZE  (HINIC_MAX_MTU_SIZE + HINIC_ETH_OVERHEAD)
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index 55518a913d8c..6d30125dccb2 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -62,7 +62,6 @@
 #define HNS3_MAX_NON_TSO_BD_PER_PKT	8
 #define HNS3_MAX_TSO_BD_PER_PKT		63
 #define HNS3_MAX_FRAME_LEN		9728
-#define HNS3_VLAN_TAG_SIZE		4
 #define HNS3_DEFAULT_RX_BUF_LEN		2048
 #define HNS3_MAX_BD_PAYLEN		(1024 * 1024 - 1)
 #define HNS3_MAX_TSO_HDR_SIZE		512
@@ -70,7 +69,7 @@
 #define HNS3_MAX_LRO_SIZE		64512
 
 #define HNS3_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + HNS3_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define HNS3_PKTLEN_TO_MTU(pktlen)	((pktlen) - HNS3_ETH_OVERHEAD)
 #define HNS3_MAX_MTU	(HNS3_MAX_FRAME_LEN - HNS3_ETH_OVERHEAD)
 #define HNS3_DEFAULT_MTU		1500UL
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index d8042abbd9be..2d182f8000a6 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -27,8 +27,6 @@
  */
 #define I40E_GL_RXERR1_H(_i)	(0x00318004 + ((_i) * 8))
 
-#define I40E_VLAN_TAG_SIZE        4
-
 #define I40E_AQ_LEN               32
 #define I40E_AQ_BUF_SZ            4096
 /* Number of queues per TC should be one of 1, 2, 4, 8, 16, 32, 64 */
@@ -292,7 +290,7 @@ struct rte_flow {
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define I40E_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + I40E_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define I40E_ETH_MAX_LEN (RTE_ETHER_MTU + I40E_ETH_OVERHEAD)
 
 #define I40E_RXTX_BYTES_H_16_BIT(bytes) ((bytes) & ~I40E_48_BIT_MASK)
diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h
index f413dbed833a..0bb5698583ba 100644
--- a/drivers/net/iavf/iavf.h
+++ b/drivers/net/iavf/iavf.h
@@ -78,9 +78,8 @@
 /* The overhead from MTU to max frame size.
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
-#define IAVF_VLAN_TAG_SIZE               4
 #define IAVF_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + IAVF_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define IAVF_ETH_MAX_LEN (RTE_ETHER_MTU + IAVF_ETH_OVERHEAD)
 
 #define IAVF_32_BIT_WIDTH (CHAR_BIT * 4)
diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index d1e675764127..28f7f7fb72c4 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -81,7 +81,7 @@ ice_dcf_init_rxq(struct rte_eth_dev *dev, struct ice_rx_queue *rxq)
 
 	rxq->max_pkt_len = max_pkt_len;
 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
-	    (rxq->max_pkt_len + 2 * ICE_VLAN_TAG_SIZE) > buf_size) {
+	    (rxq->max_pkt_len + 2 * RTE_VLAN_HLEN) > buf_size) {
 		dev_data->scattered_rx = 1;
 	}
 	rxq->qrx_tail = hw->hw_addr + IAVF_QRX_TAIL1(rxq->queue_id);
diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index f8d0f0c6ee26..11f7eb435233 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -14,8 +14,6 @@
 #include "base/ice_adminq_cmd.h"
 #include "base/ice_flow.h"
 
-#define ICE_VLAN_TAG_SIZE        4
-
 #define ICE_ADMINQ_LEN               32
 #define ICE_SBIOQ_LEN                32
 #define ICE_MAILBOXQ_LEN             32
@@ -136,7 +134,7 @@
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define ICE_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + ICE_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define ICE_ETH_MAX_LEN (RTE_ETHER_MTU + ICE_ETH_OVERHEAD)
 
 #define ICE_RXTX_BYTES_HIGH(bytes) ((bytes) & ~ICE_40_BIT_MASK)
diff --git a/drivers/net/ipn3ke/ipn3ke_ethdev.h b/drivers/net/ipn3ke/ipn3ke_ethdev.h
index ba3f8821e235..041f13d9c365 100644
--- a/drivers/net/ipn3ke/ipn3ke_ethdev.h
+++ b/drivers/net/ipn3ke/ipn3ke_ethdev.h
@@ -633,13 +633,12 @@ ipn3ke_tm_ops_get(struct rte_eth_dev *ethdev,
 #define IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_MASK \
 	IPN3KE_MASK(0x1, IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_SHIFT)
 
-#define IPN3KE_VLAN_TAG_SIZE    4
 /**
  * The overhead from MTU to max frame size.
  * Considering QinQ packet, the VLAN tag needs to be counted twice.
  */
 #define IPN3KE_ETH_OVERHEAD \
-	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + IPN3KE_VLAN_TAG_SIZE * 2)
+	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN * 2)
 #define IPN3KE_ETH_MAX_LEN (RTE_ETHER_MTU + IPN3KE_ETH_OVERHEAD)
 
 #define IPN3KE_MAC_FRAME_SIZE_MAX    9728
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 1911cf2fab05..fe61dba81d68 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -5173,7 +5173,7 @@ ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev->data->dev_started && !dev->data->scattered_rx &&
-	    frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
+	    frame_size + 2 * RTE_VLAN_HLEN >
 			dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
@@ -6341,7 +6341,7 @@ ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
+	    (max_frame + 2 * RTE_VLAN_HLEN >
 			dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 876b670f2682..83e8b5e56a6f 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -43,7 +43,6 @@
 #define IXGBE_NB_STAT_MAPPING_REGS  32
 #define IXGBE_EXTENDED_VLAN	  (uint32_t)(1 << 26) /* EXTENDED VLAN ENABLE */
 #define IXGBE_VFTA_SIZE 128
-#define IXGBE_VLAN_TAG_SIZE 4
 #define IXGBE_HKEY_MAX_INDEX 10
 #define IXGBE_MAX_RX_QUEUE_NUM	128
 #define IXGBE_MAX_INTR_QUEUE_NUM	15
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index cd259430461a..d7c80d424263 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5153,7 +5153,7 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev)
 				       IXGBE_SRRCTL_BSIZEPKT_SHIFT);
 
 		/* It adds dual VLAN length for supporting dual VLAN */
-		if (frame_size + 2 * IXGBE_VLAN_TAG_SIZE > buf_size)
+		if (frame_size + 2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
@@ -5729,7 +5729,7 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
 
 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
 		    /* It adds dual VLAN length for supporting dual VLAN */
-		    (frame_size + 2 * IXGBE_VLAN_TAG_SIZE) > buf_size) {
+		    (frame_size + 2 * RTE_VLAN_HLEN) > buf_size) {
 			if (!dev->data->scattered_rx)
 				PMD_INIT_LOG(DEBUG, "forcing scatter mode");
 			dev->data->scattered_rx = 1;
diff --git a/drivers/net/mvneta/mvneta_ethdev.h b/drivers/net/mvneta/mvneta_ethdev.h
index a43bd61eb1a5..9e711d8e5ae0 100644
--- a/drivers/net/mvneta/mvneta_ethdev.h
+++ b/drivers/net/mvneta/mvneta_ethdev.h
@@ -45,9 +45,8 @@
 /** Rx queue descriptors alignment in B */
 #define MRVL_NETA_RXD_ALIGN 32
 
-#define MRVL_NETA_VLAN_TAG_LEN	4
 #define MRVL_NETA_ETH_HDRS_LEN	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + \
-				MRVL_NETA_VLAN_TAG_LEN)
+				RTE_VLAN_HLEN)
 
 #define MRVL_NETA_HDRS_LEN		(MV_MH_SIZE + MRVL_NETA_ETH_HDRS_LEN)
 #define MRVL_NETA_MTU_TO_MRU(mtu)	((mtu) + MRVL_NETA_HDRS_LEN)
diff --git a/drivers/net/mvpp2/mrvl_ethdev.h b/drivers/net/mvpp2/mrvl_ethdev.h
index 426cf3354801..3b69a6ecd19d 100644
--- a/drivers/net/mvpp2/mrvl_ethdev.h
+++ b/drivers/net/mvpp2/mrvl_ethdev.h
@@ -72,9 +72,8 @@
 /** Minimum number of sent buffers to release from shadow queue to BM */
 #define MRVL_PP2_BUF_RELEASE_BURST_SIZE	64
 
-#define MRVL_PP2_VLAN_TAG_LEN	4
 #define MRVL_PP2_ETH_HDRS_LEN	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + \
-				(2 * MRVL_PP2_VLAN_TAG_LEN))
+				(2 * RTE_VLAN_HLEN))
 #define MRVL_PP2_HDRS_LEN		(MV_MH_SIZE + MRVL_PP2_ETH_HDRS_LEN)
 #define MRVL_PP2_MTU_TO_MRU(mtu)	((mtu) + MRVL_PP2_HDRS_LEN)
 #define MRVL_PP2_MRU_TO_MTU(mru)	((mru) - MRVL_PP2_HDRS_LEN)
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 775789f59607..981592f7f495 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -2488,7 +2488,7 @@ ngbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (frame_size + 2 * NGBE_VLAN_TAG_SIZE >
+	    (frame_size + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/ngbe/ngbe_ethdev.h b/drivers/net/ngbe/ngbe_ethdev.h
index c68582e5aea5..bb96f6a5e7e0 100644
--- a/drivers/net/ngbe/ngbe_ethdev.h
+++ b/drivers/net/ngbe/ngbe_ethdev.h
@@ -19,7 +19,6 @@
 #define NGBE_FLAG_NEED_LINK_CONFIG  ((uint32_t)(1 << 4))
 
 #define NGBE_VFTA_SIZE 128
-#define NGBE_VLAN_TAG_SIZE 4
 #define NGBE_HKEY_MAX_INDEX 10
 /*Default value of Max Rx Queue*/
 #define NGBE_MAX_RX_QUEUE_NUM	8
diff --git a/drivers/net/ngbe/ngbe_rxtx.c b/drivers/net/ngbe/ngbe_rxtx.c
index 0feea92588a1..86a5ef5486ec 100644
--- a/drivers/net/ngbe/ngbe_rxtx.c
+++ b/drivers/net/ngbe/ngbe_rxtx.c
@@ -2951,7 +2951,7 @@ ngbe_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if (dev->data->mtu + NGBE_ETH_OVERHEAD +
-				2 * NGBE_VLAN_TAG_SIZE > buf_size)
+				2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index 04afc6134142..47d0e6ea40f2 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -3461,7 +3461,7 @@ txgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (frame_size + 2 * TXGBE_VLAN_TAG_SIZE >
+	    (frame_size + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/txgbe/txgbe_ethdev.h b/drivers/net/txgbe/txgbe_ethdev.h
index 8304b68292da..262dbb5e38ff 100644
--- a/drivers/net/txgbe/txgbe_ethdev.h
+++ b/drivers/net/txgbe/txgbe_ethdev.h
@@ -36,7 +36,6 @@
  * FreeBSD driver.
  */
 #define TXGBE_VFTA_SIZE 128
-#define TXGBE_VLAN_TAG_SIZE 4
 #define TXGBE_HKEY_MAX_INDEX 10
 /*Default value of Max Rx Queue*/
 #define TXGBE_MAX_RX_QUEUE_NUM	128
diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index 67ae69dec30a..c7c298ae2d02 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -1111,7 +1111,7 @@ txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	 * scattered packets when this feature has not been enabled before.
 	 */
 	if (dev_data->dev_started && !dev_data->scattered_rx &&
-	    (max_frame + 2 * TXGBE_VLAN_TAG_SIZE >
+	    (max_frame + 2 * RTE_VLAN_HLEN >
 	     dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
 		PMD_INIT_LOG(ERR, "Stop port first.");
 		return -EINVAL;
diff --git a/drivers/net/txgbe/txgbe_rxtx.c b/drivers/net/txgbe/txgbe_rxtx.c
index 497af8d22d23..35b77cb271ba 100644
--- a/drivers/net/txgbe/txgbe_rxtx.c
+++ b/drivers/net/txgbe/txgbe_rxtx.c
@@ -4389,7 +4389,7 @@ txgbe_dev_rx_init(struct rte_eth_dev *dev)
 
 		/* It adds dual VLAN length for supporting dual VLAN */
 		if (dev->data->mtu + TXGBE_ETH_OVERHEAD +
-				2 * TXGBE_VLAN_TAG_SIZE > buf_size)
+				2 * RTE_VLAN_HLEN > buf_size)
 			dev->data->scattered_rx = 1;
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
 			rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
@@ -4906,7 +4906,7 @@ txgbevf_dev_rx_init(struct rte_eth_dev *dev)
 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
 		    /* It adds dual VLAN length for supporting dual VLAN */
 		    (dev->data->mtu + TXGBE_ETH_OVERHEAD +
-				2 * TXGBE_VLAN_TAG_SIZE) > buf_size) {
+				2 * RTE_VLAN_HLEN) > buf_size) {
 			if (!dev->data->scattered_rx)
 				PMD_INIT_LOG(DEBUG, "forcing scatter mode");
 			dev->data->scattered_rx = 1;
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 8bf61b32b669..33d023aa3973 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -195,7 +195,6 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE * MAX_VHOST_DEVICE];
 
 #define MBUF_TABLE_DRAIN_TSC	((rte_get_tsc_hz() + US_PER_S - 1) \
 				 / US_PER_S * BURST_TX_DRAIN_US)
-#define VLAN_HLEN       4
 
 static inline int
 open_dma(const char *value)
@@ -1015,7 +1014,7 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	 * by minus length of vlan tag, so need restore
 	 * the packet length by plus it.
 	 */
-	*offset  = VLAN_HLEN;
+	*offset  = RTE_VLAN_HLEN;
 	*vlan_tag = vlan_tags[vdev->vid];
 
 	RTE_LOG_DP(DEBUG, VHOST_DATA,
diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index 1a0dbf0d607c..3d9852d9e29a 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -35,9 +35,10 @@ extern "C" {
 	(RTE_ETHER_MAX_LEN - RTE_ETHER_HDR_LEN - \
 		RTE_ETHER_CRC_LEN) /**< Ethernet MTU. */
 
+#define RTE_VLAN_HLEN       4  /**< VLAN (IEEE 802.1Q) header length. */
+/** Maximum VLAN frame length (excluding QinQ), including CRC. */
 #define RTE_ETHER_MAX_VLAN_FRAME_LEN \
-	(RTE_ETHER_MAX_LEN + 4)
-	/**< Maximum VLAN frame length, including CRC. */
+	(RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
 
 #define RTE_ETHER_MAX_JUMBO_FRAME_LEN \
 	0x3F00 /**< Maximum Jumbo frame length, including CRC. */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3] net: add macro for VLAN header length
  2021-11-17 18:24 ` [PATCH v3] " Ferruh Yigit
@ 2021-11-17 18:54   ` Thomas Monjalon
  0 siblings, 0 replies; 11+ messages in thread
From: Thomas Monjalon @ 2021-11-17 18:54 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: Chandubabu Namburu, Rasesh Mody, Shahed Shaikh, Ajit Khaparde,
	Somnath Kotur, Rahul Lakkireddy, Apeksha Gupta, Sachin Saxena,
	Qi Zhang, Xiao Wang, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou,
	Min Hu (Connor),
	Yisen Zhuang, Lijun Ou, Beilei Xing, Jingjing Wu, Qiming Yang,
	Rosen Xu, Haiyue Wang, Zyta Szpak, Liron Himi, Jiawen Wu,
	Jian Wang, Maxime Coquelin, Chenbo Xia, Olivier Matz, dev

17/11/2021 19:24, Ferruh Yigit:
> Multiple drivers are defining macros for VLAN header length, to remove
> the redundancy defining macro in the ether header.
> And updated drivers to use the new macro.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Acked-by: Haiyue Wang <haiyue.wang@intel.com>
> Acked-by: Rosen Xu <rosen.xu@intel.com>
> Acked-by: Jiawen Wu <jiawenwu@trustnetic.com>

Applied, thanks.



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-11-17 18:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10 17:40 [PATCH] net: add macro for VLAN header length Ferruh Yigit
2021-11-11  1:34 ` Wang, Haiyue
2021-11-12  2:36 ` Xu, Rosen
2021-11-12  6:09 ` Jiawen Wu
2021-11-16 23:14 ` Thomas Monjalon
2021-11-17 10:00   ` Ferruh Yigit
2021-11-17 10:02     ` Thomas Monjalon
2021-11-17 10:12       ` Ferruh Yigit
2021-11-17 18:08 ` [PATCH v2] " Ferruh Yigit
2021-11-17 18:24 ` [PATCH v3] " Ferruh Yigit
2021-11-17 18:54   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).