xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/dhd_flowring.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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  * Copyright (C) 2020, Broadcom.
10  *
11  *      Unless you and Broadcom execute a separate written software license
12  * agreement governing use of this software, this software is licensed to you
13  * under the terms of the GNU General Public License version 2 (the "GPL"),
14  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
15  * following added to such license:
16  *
17  *      As a special exception, the copyright holders of this software give you
18  * permission to link this software with independent modules, and to copy and
19  * distribute the resulting executable under terms of your choice, provided that
20  * you also meet, for each linked independent module, the terms and conditions of
21  * the license of that module.  An independent module is a module which is not
22  * derived from this software.  The special exception does not apply to any
23  * modifications of the software.
24  *
25  *
26  * <<Broadcom-WL-IPTag/Open:>>
27  *
28  * $Id$
29  */
30 
31 /** XXX Twiki: [PCIeFullDongleArchitecture] */
32 
33 /****************
34  * Common types *
35  */
36 
37 #ifndef _dhd_flowrings_h_
38 #define _dhd_flowrings_h_
39 
40 /* Max pkts held in a flow ring's backup queue */
41 #define FLOW_RING_QUEUE_THRESHOLD       (2048)
42 
43 /* Number of H2D common rings */
44 #define FLOW_RING_COMMON                BCMPCIE_H2D_COMMON_MSGRINGS
45 
46 #define FLOWID_INVALID                  (ID16_INVALID)
47 #define FLOWID_RESERVED                 (FLOW_RING_COMMON)
48 
49 #define FLOW_RING_STATUS_OPEN           0
50 #define FLOW_RING_STATUS_CREATE_PENDING	1
51 #define FLOW_RING_STATUS_CLOSED         2
52 #define FLOW_RING_STATUS_DELETE_PENDING 3
53 #define FLOW_RING_STATUS_FLUSH_PENDING  4
54 
55 #ifdef IDLE_TX_FLOW_MGMT
56 #define FLOW_RING_STATUS_SUSPENDED	5
57 #define FLOW_RING_STATUS_RESUME_PENDING	6
58 #endif /* IDLE_TX_FLOW_MGMT */
59 #define FLOW_RING_STATUS_STA_FREEING    7
60 
61 #if defined(DHD_HTPUT_TUNABLES)
62 #define HTPUT_FLOW_RING_PRIO		PRIO_8021D_BE
63 #define HTPUT_NUM_STA_FLOW_RINGS	1u
64 #define HTPUT_NUM_CLIENT_FLOW_RINGS	3u
65 #define HTPUT_TOTAL_FLOW_RINGS		(HTPUT_NUM_STA_FLOW_RINGS + HTPUT_NUM_CLIENT_FLOW_RINGS)
66 #define DHD_IS_FLOWID_HTPUT(pub, flowid) \
67 	((flowid >= (pub)->htput_flow_ring_start) && \
68 	(flowid < ((pub)->htput_flow_ring_start + HTPUT_TOTAL_FLOW_RINGS)))
69 #endif /* DHD_HTPUT_TUNABLES */
70 
71 #ifdef DHD_EFI
72 /*
73  * Each lbuf is of size 2048 bytes. But the last 112 bytes is occupied for lbuf header.
74  * Since lbuf is crucial data structure we want to avoid operations very close to lbuf.
75  * so providing a pad of 136 bytes. so lbuf and pad together is 248 bytes.
76  *
77  * So the maximum usable lbuf size is 1800 bytes.
78  *
79  * These 1800 bytes is utilized for below purposes.
80  *
81  * 1. FW operating in mode2 requires 98 bytes for extra headers
82  * like SNAP, PLCP etc. Whereas FW operating in mode4 requires 70 bytes.
83  * So in EFI DHD we will consider 98 bytes which fits for chips operating in both mode2 and mode4.
84  *
85  * 2. For TPUT tests in EFI user can request a maximum payload of 1500 bytes.
86  * To add ethernet header and TPUT header etc we are reserving 100bytes. So 1600 bytes are utilized
87  * for headers and payload.
88  *
89  * so 1698(98 + 1600) bytes by are consumed by 1 and 2.
90  * So we still have 112 bytes which can be utilized
91  * if FW needs buffer for more headers in future.
92  *
93  * --Update-- 13Jul2018 (above comments preserved for history)
94  * 3.  In case of 11ax chips more headroom is required, FW requires a min. of 1920 bytes for Rx
95  * buffers, or it will trap. Therefore bumping up the size to 1920 bytes. Which leaves
96  * only 16 bytes pad between data and lbuf header ! Further size increase may not be possible !!
97  */
98 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ	1920
99 #else
100 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ	2048
101 #endif /* DHD_EFI */
102 
103 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ_MAX 4096
104 
105 #define DHD_FLOWRING_TX_BIG_PKT_SIZE	(3700u)
106 
107 #define DHD_FLOW_PRIO_AC_MAP		0
108 #define DHD_FLOW_PRIO_TID_MAP		1
109 /* Flow ring prority map for lossless roaming */
110 #define DHD_FLOW_PRIO_LLR_MAP		2
111 
112 /* Hashing a MacAddress for lkup into a per interface flow hash table */
113 #define DHD_FLOWRING_HASH_SIZE    256
114 #define	DHD_FLOWRING_HASHINDEX(ea, prio) \
115 	       ((((uint8 *)(ea))[3] ^ ((uint8 *)(ea))[4] ^ ((uint8 *)(ea))[5] ^ ((uint8)(prio))) \
116 		% DHD_FLOWRING_HASH_SIZE)
117 
118 #define DHD_IF_ROLE(pub, idx)		(((if_flow_lkup_t *)(pub)->if_flow_lkup)[idx].role)
119 #define DHD_IF_ROLE_AP(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_AP)
120 #define DHD_IF_ROLE_STA(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_STA)
121 #define DHD_IF_ROLE_P2PGC(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_CLIENT)
122 #define DHD_IF_ROLE_P2PGO(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_GO)
123 #define DHD_IF_ROLE_WDS(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_WDS)
124 #define DHD_IF_ROLE_IBSS(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_IBSS)
125 #define DHD_IF_ROLE_NAN(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_NAN)
126 
127 #define DHD_IF_ROLE_GENERIC_STA(pub, idx) \
128 	(DHD_IF_ROLE_STA(pub, idx) || DHD_IF_ROLE_P2PGC(pub, idx) || DHD_IF_ROLE_WDS(pub, idx))
129 
130 #ifdef DHD_AWDL
131 #define DHD_IF_ROLE_AWDL(pub, idx)	(DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_AWDL)
132 #define DHD_IF_ROLE_MULTI_CLIENT(pub, idx) \
133 	(DHD_IF_ROLE_AP(pub, idx) || DHD_IF_ROLE_P2PGO(pub, idx) || DHD_IF_ROLE_AWDL(pub, idx) ||\
134 		DHD_IF_ROLE_NAN(pub, idx))
135 #else
136 #define DHD_IF_ROLE_MULTI_CLIENT(pub, idx) \
137 	(DHD_IF_ROLE_AP(pub, idx) || DHD_IF_ROLE_P2PGO(pub, idx) ||\
138 		DHD_IF_ROLE_NAN(pub, idx))
139 #endif /* DHD_AWDL */
140 
141 #define DHD_FLOW_RING(dhdp, flowid) \
142 	(flow_ring_node_t *)&(((flow_ring_node_t *)((dhdp)->flow_ring_table))[flowid])
143 
144 struct flow_queue;
145 
146 /* Flow Ring Queue Enqueue overflow callback */
147 typedef int (*flow_queue_cb_t)(struct flow_queue * queue, void * pkt);
148 
149 /**
150  * Each flow ring has an associated (tx flow controlled) queue. 802.3 packets are transferred
151  * between queue and ring. A packet from the host stack is first added to the queue, and in a later
152  * stage transferred to the flow ring. Packets in the queue are dhd owned, whereas packets in the
153  * flow ring are device owned.
154  */
155 typedef struct flow_queue {
156 	dll_t  list;                /* manage a flowring queue in a double linked list */
157 	void * head;                /* first packet in the queue */
158 	void * tail;                /* last packet in the queue */
159 	uint16 len;                 /* number of packets in the queue */
160 	uint16 max;                 /* maximum or min budget (used in cumm) */
161 	uint32 threshold;           /* parent's cummulative length threshold */
162 	void * clen_ptr;            /* parent's cummulative length counter */
163 	uint32 failures;            /* enqueue failures due to queue overflow */
164 	flow_queue_cb_t cb;         /* callback invoked on threshold crossing */
165 	uint32 l2threshold;         /* grandparent's (level 2) cummulative length threshold */
166 	void * l2clen_ptr;          /* grandparent's (level 2) cummulative length counter */
167 } flow_queue_t;
168 
169 #define DHD_FLOW_QUEUE_LEN(queue)       ((int)(queue)->len)
170 #define DHD_FLOW_QUEUE_MAX(queue)       ((int)(queue)->max)
171 #define DHD_FLOW_QUEUE_THRESHOLD(queue) ((int)(queue)->threshold)
172 #define DHD_FLOW_QUEUE_L2THRESHOLD(queue) ((int)(queue)->l2threshold)
173 #define DHD_FLOW_QUEUE_EMPTY(queue)     ((queue)->len == 0)
174 #define DHD_FLOW_QUEUE_FAILURES(queue)  ((queue)->failures)
175 
176 #define DHD_FLOW_QUEUE_AVAIL(queue)     ((int)((queue)->max - (queue)->len))
177 #define DHD_FLOW_QUEUE_FULL(queue)      ((queue)->len >= (queue)->max)
178 
179 #define DHD_FLOW_QUEUE_OVFL(queue, budget)  \
180 	(((queue)->len) > budget)
181 
182 #define DHD_FLOW_QUEUE_SET_MAX(queue, budget) \
183 	((queue)->max) = ((budget) - 1)
184 
185 /* Queue's cummulative threshold. */
186 #define DHD_FLOW_QUEUE_SET_THRESHOLD(queue, cumm_threshold) \
187 	((queue)->threshold) = ((cumm_threshold) - 1)
188 
189 /* Queue's cummulative length object accessor. */
190 #define DHD_FLOW_QUEUE_CLEN_PTR(queue)  ((queue)->clen_ptr)
191 
192 /* Set a queue's cumm_len point to a parent's cumm_ctr_t cummulative length */
193 #define DHD_FLOW_QUEUE_SET_CLEN(queue, parent_clen_ptr)  \
194 	((queue)->clen_ptr) = (void *)(parent_clen_ptr)
195 
196 /* Queue's level 2 cummulative threshold. */
197 #define DHD_FLOW_QUEUE_SET_L2THRESHOLD(queue, l2cumm_threshold) \
198 	((queue)->l2threshold) = ((l2cumm_threshold) - 1)
199 
200 /* Queue's level 2 cummulative length object accessor. */
201 #define DHD_FLOW_QUEUE_L2CLEN_PTR(queue)  ((queue)->l2clen_ptr)
202 
203 /* Set a queue's level 2 cumm_len point to a grandparent's cumm_ctr_t cummulative length */
204 #define DHD_FLOW_QUEUE_SET_L2CLEN(queue, grandparent_clen_ptr)  \
205 	((queue)->l2clen_ptr) = (void *)(grandparent_clen_ptr)
206 
207 #if defined(BCMDBG)
208 #define DHD_FLOWRING_TXSTATUS_CNT_UPDATE(bus, flowid, txstatus) \
209 		dhd_bus_flow_ring_cnt_update(bus, flowid, txstatus)
210 #else
211 #define DHD_FLOWRING_TXSTATUS_CNT_UPDATE(bus, flowid, txstatus)
212 #endif /* BCMDBG */
213 
214 /* Pkttag not compatible with PROP_TXSTATUS or WLFC */
215 typedef struct dhd_pkttag_fr {
216 	uint16  flowid;
217 	uint16  ifid;
218 } dhd_pkttag_fr_t;
219 
220 #define DHD_PKTTAG_SET_IFID(tag, idx)       ((tag)->ifid = (uint16)(idx))
221 #define DHD_PKTTAG_SET_PA(tag, pa)          ((tag)->physaddr = (pa))
222 #define DHD_PKTTAG_SET_PA_LEN(tag, palen)   ((tag)->pa_len = (palen))
223 #define DHD_PKTTAG_IFID(tag)                ((tag)->ifid)
224 #define DHD_PKTTAG_PA(tag)                  ((tag)->physaddr)
225 #define DHD_PKTTAG_PA_LEN(tag)              ((tag)->pa_len)
226 
227 /** each flow ring is dedicated to a tid/sa/da combination */
228 typedef struct flow_info {
229 	uint8		tid;
230 	uint8		ifindex;
231 	uchar		sa[ETHER_ADDR_LEN];
232 	uchar		da[ETHER_ADDR_LEN];
233 #if defined(BCMDBG)
234 	uint32		tx_status[DHD_MAX_TX_STATUS_MSGS];
235 #endif
236 #ifdef TX_STATUS_LATENCY_STATS
237 	/* total number of tx_status received on this flowid */
238 	uint64           num_tx_status;
239 	/* cumulative tx_status latency for this flowid */
240 	uint64          cum_tx_status_latency;
241 	/* num tx packets sent on this flowring */
242 	uint64		num_tx_pkts;
243 #endif /* TX_STATUS_LATENCY_STATS */
244 } flow_info_t;
245 
246 /** a flow ring is used for outbound (towards antenna) 802.3 packets */
247 typedef struct flow_ring_node {
248 	dll_t		list;  /* manage a constructed flowring in a dll, must be at first place */
249 	flow_queue_t	queue; /* queues packets before they enter the flow ring, flow control */
250 	bool		active;
251 	uint8		status;
252 	/*
253 	 * flowid: unique ID of a flow ring, which can either be unicast or broadcast/multicast. For
254 	 * unicast flow rings, the flow id accelerates ARM 802.3->802.11 header translation.
255 	 */
256 	uint16		flowid;
257 	flow_info_t	flow_info;
258 	void		*prot_info;
259 	void		*lock; /* lock for flowring access protection */
260 
261 #ifdef IDLE_TX_FLOW_MGMT
262 	uint64		last_active_ts; /* contains last active timestamp */
263 #endif /* IDLE_TX_FLOW_MGMT */
264 #ifdef DEVICE_TX_STUCK_DETECT
265 	/* Time stamp(msec) when last time a Tx packet completion is received on this flow ring */
266 	uint32		tx_cmpl;
267 	/*
268 	 * Holds the tx_cmpl which was read during the previous
269 	 * iteration of the stuck detection algo
270 	 */
271 	uint32		tx_cmpl_prev;
272 	/* counter to decide if this particlur flow is stuck or not */
273 	uint32		stuck_count;
274 #endif /* DEVICE_TX_STUCK_DETECT */
275 #ifdef DHD_HP2P
276 	bool	hp2p_ring;
277 #endif /* DHD_HP2P */
278 } flow_ring_node_t;
279 
280 typedef flow_ring_node_t flow_ring_table_t;
281 
282 typedef struct flow_hash_info {
283 	uint16			flowid;
284 	flow_info_t		flow_info;
285 	struct flow_hash_info	*next;
286 } flow_hash_info_t;
287 
288 typedef struct if_flow_lkup {
289 	bool		status;
290 	uint8		role; /* Interface role: STA/AP */
291 	flow_hash_info_t *fl_hash[DHD_FLOWRING_HASH_SIZE]; /* Lkup Hash table */
292 } if_flow_lkup_t;
293 
294 static INLINE flow_ring_node_t *
dhd_constlist_to_flowring(dll_t * item)295 dhd_constlist_to_flowring(dll_t *item)
296 {
297 	return ((flow_ring_node_t *)item);
298 }
299 
300 /* Exported API */
301 
302 /* Flow ring's queue management functions */
303 extern flow_ring_node_t * dhd_flow_ring_node(dhd_pub_t *dhdp, uint16 flowid);
304 extern flow_queue_t * dhd_flow_queue(dhd_pub_t *dhdp, uint16 flowid);
305 
306 extern void dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
307 extern void dhd_flow_queue_reinit(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
308 extern void dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb);
309 extern int  dhd_flow_queue_enqueue(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
310 extern int  dhd_flow_queue_enqueue_head(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
311 extern void * dhd_flow_queue_dequeue(dhd_pub_t *dhdp, flow_queue_t *queue);
312 extern void dhd_flow_queue_reinsert(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
313 
314 extern void dhd_flow_ring_config_thresholds(dhd_pub_t *dhdp, uint16 flowid,
315                           int queue_budget, int cumm_threshold, void *cumm_ctr,
316                           int l2cumm_threshold, void *l2cumm_ctr);
317 extern int  dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_h2d_rings);
318 
319 extern void dhd_flow_rings_deinit(dhd_pub_t *dhdp);
320 
321 extern int dhd_flowid_update(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio,
322                 void *pktbuf);
323 extern int dhd_flowid_debug_create(dhd_pub_t *dhdp, uint8 ifindex,
324 	uint8 prio, char *sa, char *da, uint16 *flowid);
325 extern int dhd_flowid_find_by_ifidx(dhd_pub_t *dhdp, uint8 ifidex, uint16 flowid);
326 
327 extern void dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid);
328 
329 extern void dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex);
330 extern void dhd_flow_rings_flush(dhd_pub_t *dhdp, uint8 ifindex);
331 
332 extern void dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex,
333                 char *addr);
334 
335 /* Handle Interface ADD, DEL operations */
336 extern void dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex,
337                 uint8 op, uint8 role);
338 
339 /* Handle a STA interface link status update */
340 extern int dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex,
341                 uint8 status);
342 extern int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set);
343 extern int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map);
344 extern uint32 dhd_active_tx_flowring_bkpq_len(dhd_pub_t *dhdp);
345 #ifdef DHD_AWDL
346 /* DHD handler for awdl peer op IOVAR */
347 extern void dhd_awdl_peer_op(dhd_pub_t *dhdp, uint8 ifindex,
348                 void *buf, uint32 buflen);
349 #endif /* DHD_AWDL */
350 extern uint8 dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex);
351 #endif /* _dhd_flowrings_h_ */
352