1195972f6Sopenharmony_ciFrom 95aba99f41333ad430496eab2596bc8b489ae731 Mon Sep 17 00:00:00 2001
2195972f6Sopenharmony_ciFrom: Dirk Ziegelmeier <dirk@ziegelmeier.net>
3195972f6Sopenharmony_ciDate: Fri, 19 Oct 2018 22:30:17 +0200
4195972f6Sopenharmony_ciSubject: [PATCH] Implement task #11620: Add outgoing VLAN PCP support for
5195972f6Sopenharmony_ci Ethernet level QoS
6195972f6Sopenharmony_ci
7195972f6Sopenharmony_ciApply rebased patch from Timmy Brolin
8195972f6Sopenharmony_ci---
9195972f6Sopenharmony_ci src/core/tcp.c           | 29 ++++++++++++++++-------------
10195972f6Sopenharmony_ci src/core/tcp_in.c        |  3 +++
11195972f6Sopenharmony_ci src/include/lwip/netif.h | 22 ++++++++++++++--------
12195972f6Sopenharmony_ci src/include/lwip/opt.h   | 34 +++++++++++++++++++++++-----------
13195972f6Sopenharmony_ci src/netif/ethernet.c     | 12 ++++++++++--
14195972f6Sopenharmony_ci 5 files changed, 66 insertions(+), 34 deletions(-)
15195972f6Sopenharmony_ci
16195972f6Sopenharmony_cidiff --git a/src/core/tcp.c b/src/core/tcp.c
17195972f6Sopenharmony_ciindex ce03c8161..1f91d24ba 100644
18195972f6Sopenharmony_ci--- a/src/core/tcp.c
19195972f6Sopenharmony_ci+++ b/src/core/tcp.c
20195972f6Sopenharmony_ci@@ -892,6 +892,9 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
21195972f6Sopenharmony_ci   lpcb->ttl = pcb->ttl;
22195972f6Sopenharmony_ci   lpcb->tos = pcb->tos;
23195972f6Sopenharmony_ci
24195972f6Sopenharmony_ci+#if LWIP_VLAN_PCP
25195972f6Sopenharmony_ci+  lpcb->netif_hints.tci = pcb->netif_hints.tci;
26195972f6Sopenharmony_ci+#endif /* LWIP_VLAN_PCP */
27195972f6Sopenharmony_ci #if GAZELLE_TCP_REUSE_IPPORT
28195972f6Sopenharmony_ci   lpcb->connect_num = 0;
29195972f6Sopenharmony_ci   lpcb->next_same_port_pcb = NULL;
30195972f6Sopenharmony_ciindex 428a6f48d..d1fe067a4 100644
31195972f6Sopenharmony_ci--- a/src/core/tcp_in.c
32195972f6Sopenharmony_ci+++ b/src/core/tcp_in.c
33195972f6Sopenharmony_ci@@ -690,6 +690,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
34195972f6Sopenharmony_ci #if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
35195972f6Sopenharmony_ci     npcb->listener = pcb;
36195972f6Sopenharmony_ci #endif /* LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG */
37195972f6Sopenharmony_ci+#if LWIP_VLAN_PCP
38195972f6Sopenharmony_ci+    npcb->netif_hints.tci = pcb->netif_hints.tci;
39195972f6Sopenharmony_ci+#endif /* LWIP_VLAN_PCP */
40195972f6Sopenharmony_ci     /* inherit socket options */
41195972f6Sopenharmony_ci     npcb->so_options = pcb->so_options & SOF_INHERITED;
42195972f6Sopenharmony_ci     npcb->netif_idx = pcb->netif_idx;
43195972f6Sopenharmony_cidiff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h
44195972f6Sopenharmony_ciindex 9e2007a64..013a69b5a 100644
45195972f6Sopenharmony_ci--- a/src/include/lwip/netif.h
46195972f6Sopenharmony_ci+++ b/src/include/lwip/netif.h
47195972f6Sopenharmony_ci@@ -248,14 +248,20 @@ typedef u8_t netif_addr_idx_t;
48195972f6Sopenharmony_ci #define NETIF_ADDR_IDX_MAX 0x7F
49195972f6Sopenharmony_ci #endif
50195972f6Sopenharmony_ci 
51195972f6Sopenharmony_ci+#if LWIP_NETIF_HWADDRHINT || LWIP_VLAN_PCP
52195972f6Sopenharmony_ci+ #define LWIP_NETIF_USE_HINTS              1
53195972f6Sopenharmony_ci+ struct netif_hint {
54195972f6Sopenharmony_ci #if LWIP_NETIF_HWADDRHINT
55195972f6Sopenharmony_ci-#define LWIP_NETIF_USE_HINTS              1
56195972f6Sopenharmony_ci-struct netif_hint {
57195972f6Sopenharmony_ci-  netif_addr_idx_t addr_hint;
58195972f6Sopenharmony_ci-};
59195972f6Sopenharmony_ci-#else /* LWIP_NETIF_HWADDRHINT */
60195972f6Sopenharmony_ci-#define LWIP_NETIF_USE_HINTS              0
61195972f6Sopenharmony_ci-#endif /* LWIP_NETIF_HWADDRHINT */
62195972f6Sopenharmony_ci+   u8_t addr_hint;
63195972f6Sopenharmony_ci+#endif
64195972f6Sopenharmony_ci+#if LWIP_VLAN_PCP
65195972f6Sopenharmony_ci+  /** VLAN hader is set if this is >= 0 (but must be <= 0xFFFF) */
66195972f6Sopenharmony_ci+  s32_t tci;
67195972f6Sopenharmony_ci+#endif
68195972f6Sopenharmony_ci+ };
69195972f6Sopenharmony_ci+#else /* LWIP_NETIF_HWADDRHINT || LWIP_VLAN_PCP */
70195972f6Sopenharmony_ci+ #define LWIP_NETIF_USE_HINTS              0
71195972f6Sopenharmony_ci+#endif /* LWIP_NETIF_HWADDRHINT || LWIP_VLAN_PCP*/
72195972f6Sopenharmony_ci 
73195972f6Sopenharmony_ci /** Generic data structure used for all lwIP network interfaces.
74195972f6Sopenharmony_ci  *  The following fields should be filled in by the initialization
75195972f6Sopenharmony_ci #if LWIP_IPV6_AUTOCONFIG
76195972f6Sopenharmony_cidiff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
77195972f6Sopenharmony_ciindex 90fce4f05..fb4b10c8b 100644
78195972f6Sopenharmony_ci--- a/src/include/lwip/opt.h
79195972f6Sopenharmony_ci+++ b/src/include/lwip/opt.h
80195972f6Sopenharmony_ci@@ -677,6 +677,18 @@
81195972f6Sopenharmony_ci #define ETHARP_SUPPORT_VLAN             0
82195972f6Sopenharmony_ci #endif
83195972f6Sopenharmony_ci 
84195972f6Sopenharmony_ci+/**
85195972f6Sopenharmony_ci+ * LWIP_VLAN_PCP==1: Enable outgoing VLAN taggning of frames on a per-PCB basis
86195972f6Sopenharmony_ci+ * for QoS purposes. With this feature enabled, each PCB has a new variable: "tci".
87195972f6Sopenharmony_ci+ * (Tag Control Identifier). The TCI contains three fields: VID, CFI and PCP.
88195972f6Sopenharmony_ci+ * VID is the VLAN ID, which should be set to zero.
89195972f6Sopenharmony_ci+ * The "CFI" bit is used to enable or disable VLAN tags for the PCB.
90195972f6Sopenharmony_ci+ * PCP (Priority Code Point) is a 3 bit field used for Ethernet level QoS.
91195972f6Sopenharmony_ci+ */
92195972f6Sopenharmony_ci+#ifndef LWIP_VLAN_PCP
93195972f6Sopenharmony_ci+#define LWIP_VLAN_PCP                   0
94195972f6Sopenharmony_ci+#endif
95195972f6Sopenharmony_ci+
96195972f6Sopenharmony_ci /** LWIP_ETHERNET==1: enable ethernet support even though ARP might be disabled
97195972f6Sopenharmony_ci  */
98195972f6Sopenharmony_ci #if !defined LWIP_ETHERNET || defined __DOXYGEN__
99195972f6Sopenharmony_ci@@ -1548,13 +1560,13 @@
100195972f6Sopenharmony_ci  * link level header. The default is 14, the standard value for
101195972f6Sopenharmony_ci  * Ethernet.
102195972f6Sopenharmony_ci  */
103195972f6Sopenharmony_ci-#if !defined PBUF_LINK_HLEN || defined __DOXYGEN__
104195972f6Sopenharmony_ci-#if defined LWIP_HOOK_VLAN_SET && !defined __DOXYGEN__
105195972f6Sopenharmony_ci-#define PBUF_LINK_HLEN                  (18 + ETH_PAD_SIZE)
106195972f6Sopenharmony_ci-#else /* LWIP_HOOK_VLAN_SET */
107195972f6Sopenharmony_ci-#define PBUF_LINK_HLEN                  (14 + ETH_PAD_SIZE)
108195972f6Sopenharmony_ci-#endif /* LWIP_HOOK_VLAN_SET */
109195972f6Sopenharmony_ci-#endif
110195972f6Sopenharmony_ci+ #if !defined PBUF_LINK_HLEN || defined __DOXYGEN__
111195972f6Sopenharmony_ci+#if (defined LWIP_HOOK_VLAN_SET || LWIP_VLAN_PCP) && !defined __DOXYGEN__
112195972f6Sopenharmony_ci+ #define PBUF_LINK_HLEN                  (18 + ETH_PAD_SIZE)
113195972f6Sopenharmony_ci+#else /* LWIP_HOOK_VLAN_SET || LWIP_VLAN_PCP */
114195972f6Sopenharmony_ci+ #define PBUF_LINK_HLEN                  (14 + ETH_PAD_SIZE)
115195972f6Sopenharmony_ci+#endif /* LWIP_HOOK_VLAN_SET || LWIP_VLAN_PCP */
116195972f6Sopenharmony_ci+ #endif
117195972f6Sopenharmony_ci 
118195972f6Sopenharmony_ci /**
119195972f6Sopenharmony_ci  * PBUF_LINK_ENCAPSULATION_HLEN: the number of bytes that should be allocated
120195972f6Sopenharmony_cidiff --git a/src/netif/ethernet.c b/src/netif/ethernet.c
121195972f6Sopenharmony_ciindex dd171e280..9e367f8cc 100644
122195972f6Sopenharmony_ci--- a/src/netif/ethernet.c
123195972f6Sopenharmony_ci+++ b/src/netif/ethernet.c
124195972f6Sopenharmony_ci@@ -273,8 +273,16 @@ ethernet_output(struct netif * netif, struct pbuf * p,
125195972f6Sopenharmony_ci   struct eth_hdr *ethhdr;
126195972f6Sopenharmony_ci   u16_t eth_type_be = lwip_htons(eth_type);
127195972f6Sopenharmony_ci 
128195972f6Sopenharmony_ci-#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET)
129195972f6Sopenharmony_ci-  s32_t vlan_prio_vid = LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type);
130195972f6Sopenharmony_ci+#if ETHARP_SUPPORT_VLAN
131195972f6Sopenharmony_ci+  s32_t vlan_prio_vid;
132195972f6Sopenharmony_ci+#ifdef LWIP_HOOK_VLAN_SET
133195972f6Sopenharmony_ci+  vlan_prio_vid = LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type);
134195972f6Sopenharmony_ci+#elif LWIP_VLAN_PCP
135195972f6Sopenharmony_ci+  vlan_prio_vid = -1;
136195972f6Sopenharmony_ci+  if (netif->hints && (netif->hints->tci >= 0)) {
137195972f6Sopenharmony_ci+    vlan_prio_vid = (u16_t)netif->hints->tci;
138195972f6Sopenharmony_ci+  }
139195972f6Sopenharmony_ci+#endif
140195972f6Sopenharmony_ci   if (vlan_prio_vid >= 0) {
141195972f6Sopenharmony_ci     struct eth_vlan_hdr *vlanhdr;
142195972f6Sopenharmony_ci 
143195972f6Sopenharmony_ci
144