1 /*
2 * @file Header file describing the flow rings DHD interfaces.
3 *
4 * Flow rings are transmit traffic (=propagating towards antenna) related entities.
5 *
6 * Provides type definitions and function prototypes used to create, delete and manage flow rings at
7 * high level.
8 *
9 * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
10 *
11 * Copyright (C) 1999-2017, Broadcom Corporation
12 *
13 * Unless you and Broadcom execute a separate written software license
14 * agreement governing use of this software, this software is licensed to you
15 * under the terms of the GNU General Public License version 2 (the "GPL"),
16 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
17 * following added to such license:
18 *
19 * As a special exception, the copyright holders of this software give you
20 * permission to link this software with independent modules, and to copy and
21 * distribute the resulting executable under terms of your choice, provided that
22 * you also meet, for each linked independent module, the terms and conditions of
23 * the license of that module. An independent module is a module which is not
24 * derived from this software. The special exception does not apply to any
25 * modifications of the software.
26 *
27 * Notwithstanding the above, under no circumstances may you combine this
28 * software in any way with any other Broadcom software provided under a license
29 * other than the GPL, without Broadcom's express prior written consent.
30 *
31 *
32 * <<Broadcom-WL-IPTag/Open:>>
33 *
34 * $Id: dhd_flowring.h 697690 2017-05-04 14:16:18Z $
35 */
36
37 /****************
38 * Common types *
39 */
40
41 #ifndef _dhd_flowrings_h_
42 #define _dhd_flowrings_h_
43
44 /* Max pkts held in a flow ring's backup queue */
45 #define FLOW_RING_QUEUE_THRESHOLD (2048)
46
47 /* Number of H2D common rings */
48 #define FLOW_RING_COMMON BCMPCIE_H2D_COMMON_MSGRINGS
49
50 #define FLOWID_INVALID (ID16_INVALID)
51 #define FLOWID_RESERVED (FLOW_RING_COMMON)
52
53 #define FLOW_RING_STATUS_OPEN 0
54 #define FLOW_RING_STATUS_CREATE_PENDING 1
55 #define FLOW_RING_STATUS_CLOSED 2
56 #define FLOW_RING_STATUS_DELETE_PENDING 3
57 #define FLOW_RING_STATUS_FLUSH_PENDING 4
58
59 #ifdef IDLE_TX_FLOW_MGMT
60 #define FLOW_RING_STATUS_SUSPENDED 5
61 #define FLOW_RING_STATUS_RESUME_PENDING 6
62 #endif /* IDLE_TX_FLOW_MGMT */
63 #define FLOW_RING_STATUS_STA_FREEING 7
64
65 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ 2048
66 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ_MAX 4096
67
68 #define DHD_FLOW_PRIO_AC_MAP 0
69 #define DHD_FLOW_PRIO_TID_MAP 1
70 /* Flow ring prority map for lossless roaming */
71 #define DHD_FLOW_PRIO_LLR_MAP 2
72
73 /* Hashing a MacAddress for lkup into a per interface flow hash table */
74 #define DHD_FLOWRING_HASH_SIZE 256
75 #define DHD_FLOWRING_HASHINDEX(ea, prio) \
76 ((((uint8 *)(ea))[3] ^ ((uint8 *)(ea))[4] ^ ((uint8 *)(ea))[5] ^ ((uint8)(prio))) \
77 % DHD_FLOWRING_HASH_SIZE)
78
79 #define DHD_IF_ROLE(pub, idx) (((if_flow_lkup_t *)(pub)->if_flow_lkup)[idx].role)
80 #define DHD_IF_ROLE_AP(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_AP)
81 #define DHD_IF_ROLE_STA(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_STA)
82 #define DHD_IF_ROLE_P2PGC(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_CLIENT)
83 #define DHD_IF_ROLE_P2PGO(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_GO)
84 #define DHD_IF_ROLE_WDS(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_WDS)
85 #define DHD_IF_ROLE_IBSS(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_IBSS)
86 #ifdef WL_NAN
87 #define DHD_IF_ROLE_NAN(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_NAN)
88 #else
89 #define DHD_IF_ROLE_NAN(pub, idx) (FALSE)
90 #endif /* WL_NAN */
91 #define DHD_IF_ROLE_AWDL(pub, idx) (FALSE)
92
93 #define DHD_IF_ROLE_GENERIC_STA(pub, idx) \
94 (DHD_IF_ROLE_STA(pub, idx) || DHD_IF_ROLE_P2PGC(pub, idx) || DHD_IF_ROLE_WDS(pub, idx))
95
96 #define DHD_IF_ROLE_MULTI_CLIENT(pub, idx) \
97 (DHD_IF_ROLE_AP(pub, idx) || DHD_IF_ROLE_P2PGO(pub, idx) || DHD_IF_ROLE_AWDL(pub, idx) ||\
98 DHD_IF_ROLE_NAN(pub, idx))
99
100 #define DHD_FLOW_RING(dhdp, flowid) \
101 (flow_ring_node_t *)&(((flow_ring_node_t *)((dhdp)->flow_ring_table))[flowid])
102
103 struct flow_queue;
104
105 /* Flow Ring Queue Enqueue overflow callback */
106 typedef int (*flow_queue_cb_t)(struct flow_queue * queue, void * pkt);
107
108 /**
109 * Each flow ring has an associated (tx flow controlled) queue. 802.3 packets are transferred
110 * between queue and ring. A packet from the host stack is first added to the queue, and in a later
111 * stage transferred to the flow ring. Packets in the queue are dhd owned, whereas packets in the
112 * flow ring are device owned.
113 */
114 typedef struct flow_queue {
115 dll_t list; /* manage a flowring queue in a double linked list */
116 void * head; /* first packet in the queue */
117 void * tail; /* last packet in the queue */
118 uint16 len; /* number of packets in the queue */
119 uint16 max; /* maximum or min budget (used in cumm) */
120 uint32 threshold; /* parent's cummulative length threshold */
121 void * clen_ptr; /* parent's cummulative length counter */
122 uint32 failures; /* enqueue failures due to queue overflow */
123 flow_queue_cb_t cb; /* callback invoked on threshold crossing */
124 uint32 l2threshold; /* grandparent's (level 2) cummulative length threshold */
125 void * l2clen_ptr; /* grandparent's (level 2) cummulative length counter */
126 } flow_queue_t;
127
128 #define DHD_FLOW_QUEUE_LEN(queue) ((int)(queue)->len)
129 #define DHD_FLOW_QUEUE_MAX(queue) ((int)(queue)->max)
130 #define DHD_FLOW_QUEUE_THRESHOLD(queue) ((int)(queue)->threshold)
131 #define DHD_FLOW_QUEUE_L2THRESHOLD(queue) ((int)(queue)->l2threshold)
132 #define DHD_FLOW_QUEUE_EMPTY(queue) ((queue)->len == 0)
133 #define DHD_FLOW_QUEUE_FAILURES(queue) ((queue)->failures)
134
135 #define DHD_FLOW_QUEUE_AVAIL(queue) ((int)((queue)->max - (queue)->len))
136 #define DHD_FLOW_QUEUE_FULL(queue) ((queue)->len >= (queue)->max)
137
138 #define DHD_FLOW_QUEUE_OVFL(queue, budget) \
139 (((queue)->len) > budget)
140
141 #define DHD_FLOW_QUEUE_SET_MAX(queue, budget) \
142 ((queue)->max) = ((budget) - 1)
143
144 /* Queue's cummulative threshold. */
145 #define DHD_FLOW_QUEUE_SET_THRESHOLD(queue, cumm_threshold) \
146 ((queue)->threshold) = ((cumm_threshold) - 1)
147
148 /* Queue's cummulative length object accessor. */
149 #define DHD_FLOW_QUEUE_CLEN_PTR(queue) ((queue)->clen_ptr)
150
151 /* Set a queue's cumm_len point to a parent's cumm_ctr_t cummulative length */
152 #define DHD_FLOW_QUEUE_SET_CLEN(queue, parent_clen_ptr) \
153 ((queue)->clen_ptr) = (void *)(parent_clen_ptr)
154
155 /* Queue's level 2 cummulative threshold. */
156 #define DHD_FLOW_QUEUE_SET_L2THRESHOLD(queue, l2cumm_threshold) \
157 ((queue)->l2threshold) = ((l2cumm_threshold) - 1)
158
159 /* Queue's level 2 cummulative length object accessor. */
160 #define DHD_FLOW_QUEUE_L2CLEN_PTR(queue) ((queue)->l2clen_ptr)
161
162 /* Set a queue's level 2 cumm_len point to a grandparent's cumm_ctr_t cummulative length */
163 #define DHD_FLOW_QUEUE_SET_L2CLEN(queue, grandparent_clen_ptr) \
164 ((queue)->l2clen_ptr) = (void *)(grandparent_clen_ptr)
165
166 #define DHD_FLOWRING_TXSTATUS_CNT_UPDATE(bus, flowid, txstatus)
167
168 /* Pkttag not compatible with PROP_TXSTATUS or WLFC */
169 typedef struct dhd_pkttag_fr {
170 uint16 flowid;
171 uint16 ifid;
172 #ifdef DHD_LB_TXC
173 int dataoff;
174 dmaaddr_t physaddr;
175 uint32 pa_len;
176 #endif /* DHD_LB_TXC */
177 } dhd_pkttag_fr_t;
178
179 #define DHD_PKTTAG_SET_IFID(tag, idx) ((tag)->ifid = (uint16)(idx))
180 #define DHD_PKTTAG_SET_PA(tag, pa) ((tag)->physaddr = (pa))
181 #define DHD_PKTTAG_SET_PA_LEN(tag, palen) ((tag)->pa_len = (palen))
182 #define DHD_PKTTAG_IFID(tag) ((tag)->ifid)
183 #define DHD_PKTTAG_PA(tag) ((tag)->physaddr)
184 #define DHD_PKTTAG_PA_LEN(tag) ((tag)->pa_len)
185
186 /** each flow ring is dedicated to a tid/sa/da combination */
187 typedef struct flow_info {
188 uint8 tid;
189 uint8 ifindex;
190 uchar sa[ETHER_ADDR_LEN];
191 uchar da[ETHER_ADDR_LEN];
192 #ifdef TX_STATUS_LATENCY_STATS
193 /* total number of tx_status received on this flowid */
194 uint64 num_tx_status;
195 /* cumulative tx_status latency for this flowid */
196 uint64 cum_tx_status_latency;
197 /* num tx packets sent on this flowring */
198 uint64 num_tx_pkts;
199 #endif /* TX_STATUS_LATENCY_STATS */
200 } flow_info_t;
201
202 /** a flow ring is used for outbound (towards antenna) 802.3 packets */
203 typedef struct flow_ring_node {
204 dll_t list; /* manage a constructed flowring in a dll, must be at first place */
205 flow_queue_t queue; /* queues packets before they enter the flow ring, flow control */
206 bool active;
207 uint8 status;
208 /*
209 * flowid: unique ID of a flow ring, which can either be unicast or broadcast/multicast. For
210 * unicast flow rings, the flow id accelerates ARM 802.3->802.11 header translation.
211 */
212 uint16 flowid;
213 flow_info_t flow_info;
214 void *prot_info;
215 void *lock; /* lock for flowring access protection */
216
217 #ifdef IDLE_TX_FLOW_MGMT
218 uint64 last_active_ts; /* contains last active timestamp */
219 #endif /* IDLE_TX_FLOW_MGMT */
220 #ifdef DHD_HP2P
221 bool hp2p_ring;
222 #endif /* DHD_HP2P */
223 } flow_ring_node_t;
224
225 typedef flow_ring_node_t flow_ring_table_t;
226
227 typedef struct flow_hash_info {
228 uint16 flowid;
229 flow_info_t flow_info;
230 struct flow_hash_info *next;
231 } flow_hash_info_t;
232
233 typedef struct if_flow_lkup {
234 bool status;
235 uint8 role; /* Interface role: STA/AP */
236 flow_hash_info_t *fl_hash[DHD_FLOWRING_HASH_SIZE]; /* Lkup Hash table */
237 } if_flow_lkup_t;
238
239 static INLINE flow_ring_node_t *
dhd_constlist_to_flowring(dll_t * item)240 dhd_constlist_to_flowring(dll_t *item)
241 {
242 return ((flow_ring_node_t *)item);
243 }
244
245 /* Exported API */
246
247 /* Flow ring's queue management functions */
248 extern flow_ring_node_t * dhd_flow_ring_node(dhd_pub_t *dhdp, uint16 flowid);
249 extern flow_queue_t * dhd_flow_queue(dhd_pub_t *dhdp, uint16 flowid);
250
251 extern void dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
252 extern void dhd_flow_queue_reinit(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
253 extern void dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb);
254 extern int dhd_flow_queue_enqueue(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
255 extern void * dhd_flow_queue_dequeue(dhd_pub_t *dhdp, flow_queue_t *queue);
256 extern void dhd_flow_queue_reinsert(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
257
258 extern void dhd_flow_ring_config_thresholds(dhd_pub_t *dhdp, uint16 flowid,
259 int queue_budget, int cumm_threshold, void *cumm_ctr,
260 int l2cumm_threshold, void *l2cumm_ctr);
261 extern int dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings);
262
263 extern void dhd_flow_rings_deinit(dhd_pub_t *dhdp);
264
265 extern int dhd_flowid_update(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio,
266 void *pktbuf);
267 extern int dhd_flowid_debug_create(dhd_pub_t *dhdp, uint8 ifindex,
268 uint8 prio, char *sa, char *da, uint16 *flowid);
269 extern int dhd_flowid_find_by_ifidx(dhd_pub_t *dhdp, uint8 ifidex, uint16 flowid);
270
271 extern void dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid);
272
273 extern void dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex);
274 extern void dhd_flow_rings_flush(dhd_pub_t *dhdp, uint8 ifindex);
275
276 extern void dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex,
277 char *addr);
278
279 /* Handle Interface ADD, DEL operations */
280 extern void dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex,
281 uint8 op, uint8 role);
282
283 /* Handle a STA interface link status update */
284 extern int dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex,
285 uint8 status);
286 extern int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set);
287 extern int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map);
288
289 extern uint8 dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex);
290 #endif /* _dhd_flowrings_h_ */
291