[v7,1/2] lib/net: fix parsing of VLAN metadata

Message ID PA4PR83MB052613CD2BA15A7EDD8B20FC97512@PA4PR83MB0526.EURPRD83.prod.outlook.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v7,1/2] lib/net: fix parsing of VLAN metadata |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Alan Elder Feb. 19, 2024, 9:31 a.m. UTC
  Add common macros for extracting parts of VLAN tag.

Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
Cc: sthemmin@microsoft.com
Cc: stable@dpdk.org

Signed-off-by: Alan Elder <alan.elder@microsoft.com>
---
v7:
* Split patches for lib and driver

v6:
* Line length can be 100 - un-split lines

v5:
* Move the VLAN parsing macros to rte_ether.h

v4:
* Make consistent with FreeBSD code

---
 .mailmap            |  1 +
 lib/net/rte_ether.h | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

-- 
2.25.1
  

Comments

Ferruh Yigit Feb. 19, 2024, 11:12 a.m. UTC | #1
On 2/19/2024 9:31 AM, Alan Elder wrote:
> Add common macros for extracting parts of VLAN tag.
> 
> Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Alan Elder <alan.elder@microsoft.com>
>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
  
Ferruh Yigit Feb. 19, 2024, 11:14 a.m. UTC | #2
On 2/19/2024 11:12 AM, Ferruh Yigit wrote:
> On 2/19/2024 9:31 AM, Alan Elder wrote:
>> Add common macros for extracting parts of VLAN tag.
>>
>> Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Alan Elder <alan.elder@microsoft.com>
>>
> 
> Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
>

Series applied to dpdk-next-net/main, thanks.


Updated patch title as below while merging:
net: add helper macros for VLAN metadata parsing


Also kept fixes and stable tag, although patch itself is not fix, to
request backporting the patch and highlight the reason of the request.
  

Patch

diff --git a/.mailmap b/.mailmap
index de339562f4..08fce0c472 100644
--- a/.mailmap
+++ b/.mailmap
@@ -33,6 +33,7 @@  Alain Leon <xerebz@gmail.com>
 Alan Brady <alan.brady@intel.com>
 Alan Carew <alan.carew@intel.com>
 Alan Dewar <alan.dewar@att.com> <adewar@brocade.com>
+Alan Elder <alan.elder@microsoft.com>
 Alan Liu <zaoxingliu@gmail.com>
 Alan Winkowski <walan@marvell.com>
 Alejandro Lucero <alejandro.lucero@netronome.com>
diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index ce073ea818..75285bdd12 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -46,6 +46,20 @@  extern "C" {
 
 #define RTE_ETHER_MIN_MTU 68 /**< Minimum MTU for IPv4 packets, see RFC 791. */
 
+/* VLAN header fields */
+#define RTE_VLAN_DEI_SHIFT	12
+#define RTE_VLAN_PRI_SHIFT	13
+#define RTE_VLAN_PRI_MASK	0xe000 /* Priority Code Point */
+#define RTE_VLAN_DEI_MASK	0x1000 /* Drop Eligible Indicator */
+#define RTE_VLAN_ID_MASK	0x0fff /* VLAN Identifier */
+
+#define RTE_VLAN_TCI_ID(vlan_tci)	((vlan_tci) & RTE_VLAN_ID_MASK)
+#define RTE_VLAN_TCI_PRI(vlan_tci)	(((vlan_tci) & RTE_VLAN_PRI_MASK) >> RTE_VLAN_PRI_SHIFT)
+#define RTE_VLAN_TCI_DEI(vlan_tci)	(((vlan_tci) & RTE_VLAN_DEI_MASK) >> RTE_VLAN_DEI_SHIFT)
+#define RTE_VLAN_TCI_MAKE(id, pri, dei)	((id) |					\
+					 ((pri) << RTE_VLAN_PRI_SHIFT) |	\
+					 ((dei) << RTE_VLAN_DEI_SHIFT))
+
 /**
  * Ethernet address:
  * A universally administered address is uniquely assigned to a device by its