1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * @file Broadcom Dongle Host Driver (DHD), Flow ring specific code at top level
4 *
5 * Flow rings are transmit traffic (=propagating towards antenna) related entities
6 *
7 *
8 * Copyright (C) 1999-2019, Broadcom.
9 *
10 * Unless you and Broadcom execute a separate written software license
11 * agreement governing use of this software, this software is licensed to you
12 * under the terms of the GNU General Public License version 2 (the "GPL"),
13 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
14 * following added to such license:
15 *
16 * As a special exception, the copyright holders of this software give you
17 * permission to link this software with independent modules, and to copy and
18 * distribute the resulting executable under terms of your choice, provided that
19 * you also meet, for each linked independent module, the terms and conditions of
20 * the license of that module. An independent module is a module which is not
21 * derived from this software. The special exception does not apply to any
22 * modifications of the software.
23 *
24 * Notwithstanding the above, under no circumstances may you combine this
25 * software in any way with any other Broadcom software provided under a license
26 * other than the GPL, without Broadcom's express prior written consent.
27 *
28 *
29 * <<Broadcom-WL-IPTag/Open:>>
30 *
31 * $Id: dhd_flowring.c 808473 2019-03-07 07:35:30Z $
32 */
33
34 #include <typedefs.h>
35 #include <bcmutils.h>
36 #include <bcmendian.h>
37 #include <bcmdevs.h>
38
39 #include <ethernet.h>
40 #include <bcmevent.h>
41 #include <dngl_stats.h>
42
43 #include <dhd.h>
44
45 #include <dhd_flowring.h>
46 #include <dhd_bus.h>
47 #include <dhd_proto.h>
48 #include <dhd_dbg.h>
49 #include <802.1d.h>
50 #include <pcie_core.h>
51 #include <bcmmsgbuf.h>
52 #include <dhd_pcie.h>
53 #include <dhd_config.h>
54
55 static INLINE int dhd_flow_queue_throttle(flow_queue_t *queue);
56
57 static INLINE uint16 dhd_flowid_find(dhd_pub_t *dhdp, uint8 ifindex,
58 uint8 prio, char *sa, char *da);
59
60 static INLINE uint16 dhd_flowid_alloc(dhd_pub_t *dhdp, uint8 ifindex,
61 uint8 prio, char *sa, char *da);
62
63 static INLINE int dhd_flowid_lookup(dhd_pub_t *dhdp, uint8 ifindex,
64 uint8 prio, char *sa, char *da, uint16 *flowid);
65 int BCMFASTPATH dhd_flow_queue_overflow(flow_queue_t *queue, void *pkt);
66
67 #define FLOW_QUEUE_PKT_NEXT(p) PKTLINK(p)
68 #define FLOW_QUEUE_PKT_SETNEXT(p, x) PKTSETLINK((p), (x))
69
70 const uint8 prio2ac[8] = { 0, 1, 1, 0, 2, 2, 3, 3 };
71 const uint8 prio2tid[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
72
73 /** Queue overflow throttle. Return value: TRUE if throttle needs to be applied */
74 static INLINE int
dhd_flow_queue_throttle(flow_queue_t * queue)75 dhd_flow_queue_throttle(flow_queue_t *queue)
76 {
77 return DHD_FLOW_QUEUE_FULL(queue);
78 }
79
80 int BCMFASTPATH
dhd_flow_queue_overflow(flow_queue_t * queue,void * pkt)81 dhd_flow_queue_overflow(flow_queue_t *queue, void *pkt)
82 {
83 return BCME_NORESOURCE;
84 }
85
86 /** Returns flow ring given a flowid */
87 flow_ring_node_t *
dhd_flow_ring_node(dhd_pub_t * dhdp,uint16 flowid)88 dhd_flow_ring_node(dhd_pub_t *dhdp, uint16 flowid)
89 {
90 flow_ring_node_t * flow_ring_node;
91
92 ASSERT(dhdp != (dhd_pub_t*)NULL);
93 ASSERT(flowid < dhdp->num_flow_rings);
94 if (flowid >= dhdp->num_flow_rings) {
95 return NULL;
96 }
97
98 flow_ring_node = &(((flow_ring_node_t*)(dhdp->flow_ring_table))[flowid]);
99
100 ASSERT(flow_ring_node->flowid == flowid);
101 return flow_ring_node;
102 }
103
104 /** Returns 'backup' queue given a flowid */
105 flow_queue_t *
dhd_flow_queue(dhd_pub_t * dhdp,uint16 flowid)106 dhd_flow_queue(dhd_pub_t *dhdp, uint16 flowid)
107 {
108 flow_ring_node_t * flow_ring_node = NULL;
109
110 flow_ring_node = dhd_flow_ring_node(dhdp, flowid);
111 if (flow_ring_node)
112 return &flow_ring_node->queue;
113 else
114 return NULL;
115 }
116
117 /* Flow ring's queue management functions */
118
119 /** Reinitialize a flow ring's queue. */
120 void
dhd_flow_queue_reinit(dhd_pub_t * dhdp,flow_queue_t * queue,int max)121 dhd_flow_queue_reinit(dhd_pub_t *dhdp, flow_queue_t *queue, int max)
122 {
123 ASSERT((queue != NULL) && (max > 0));
124
125 queue->head = queue->tail = NULL;
126 queue->len = 0;
127
128 /* Set queue's threshold and queue's parent cummulative length counter */
129 ASSERT(max > 1);
130 DHD_FLOW_QUEUE_SET_MAX(queue, max);
131 DHD_FLOW_QUEUE_SET_THRESHOLD(queue, max);
132 DHD_FLOW_QUEUE_SET_CLEN(queue, &dhdp->cumm_ctr);
133 DHD_FLOW_QUEUE_SET_L2CLEN(queue, &dhdp->l2cumm_ctr);
134
135 queue->failures = 0U;
136 queue->cb = &dhd_flow_queue_overflow;
137 }
138
139 /** Initialize a flow ring's queue, called on driver initialization. */
140 void
dhd_flow_queue_init(dhd_pub_t * dhdp,flow_queue_t * queue,int max)141 dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max)
142 {
143 ASSERT((queue != NULL) && (max > 0));
144
145 dll_init(&queue->list);
146 dhd_flow_queue_reinit(dhdp, queue, max);
147 }
148
149 /** Register an enqueue overflow callback handler */
150 void
dhd_flow_queue_register(flow_queue_t * queue,flow_queue_cb_t cb)151 dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb)
152 {
153 ASSERT(queue != NULL);
154 queue->cb = cb;
155 }
156
157 /**
158 * Enqueue an 802.3 packet at the back of a flow ring's queue. From there, it will travel later on
159 * to the flow ring itself.
160 */
161 int BCMFASTPATH
dhd_flow_queue_enqueue(dhd_pub_t * dhdp,flow_queue_t * queue,void * pkt)162 dhd_flow_queue_enqueue(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt)
163 {
164 int ret = BCME_OK;
165
166 ASSERT(queue != NULL);
167
168 if (dhd_flow_queue_throttle(queue)) {
169 queue->failures++;
170 ret = (*queue->cb)(queue, pkt);
171 goto done;
172 }
173
174 if (queue->head) {
175 FLOW_QUEUE_PKT_SETNEXT(queue->tail, pkt);
176 } else {
177 queue->head = pkt;
178 }
179
180 FLOW_QUEUE_PKT_SETNEXT(pkt, NULL);
181
182 queue->tail = pkt; /* at tail */
183
184 queue->len++;
185 /* increment parent's cummulative length */
186 DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_CLEN_PTR(queue));
187 /* increment grandparent's cummulative length */
188 DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_L2CLEN_PTR(queue));
189
190 done:
191 return ret;
192 }
193
194 /** Dequeue an 802.3 packet from a flow ring's queue, from head (FIFO) */
195 void * BCMFASTPATH
dhd_flow_queue_dequeue(dhd_pub_t * dhdp,flow_queue_t * queue)196 dhd_flow_queue_dequeue(dhd_pub_t *dhdp, flow_queue_t *queue)
197 {
198 void * pkt;
199
200 ASSERT(queue != NULL);
201
202 pkt = queue->head; /* from head */
203
204 if (pkt == NULL) {
205 ASSERT((queue->len == 0) && (queue->tail == NULL));
206 goto done;
207 }
208
209 queue->head = FLOW_QUEUE_PKT_NEXT(pkt);
210 if (queue->head == NULL)
211 queue->tail = NULL;
212
213 queue->len--;
214 /* decrement parent's cummulative length */
215 DHD_CUMM_CTR_DECR(DHD_FLOW_QUEUE_CLEN_PTR(queue));
216 /* decrement grandparent's cummulative length */
217 DHD_CUMM_CTR_DECR(DHD_FLOW_QUEUE_L2CLEN_PTR(queue));
218
219 FLOW_QUEUE_PKT_SETNEXT(pkt, NULL); /* dettach packet from queue */
220
221 done:
222 return pkt;
223 }
224
225 /** Reinsert a dequeued 802.3 packet back at the head */
226 void BCMFASTPATH
dhd_flow_queue_reinsert(dhd_pub_t * dhdp,flow_queue_t * queue,void * pkt)227 dhd_flow_queue_reinsert(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt)
228 {
229 if (queue->head == NULL) {
230 queue->tail = pkt;
231 }
232
233 FLOW_QUEUE_PKT_SETNEXT(pkt, queue->head);
234 queue->head = pkt;
235 queue->len++;
236 /* increment parent's cummulative length */
237 DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_CLEN_PTR(queue));
238 /* increment grandparent's cummulative length */
239 DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_L2CLEN_PTR(queue));
240 }
241
242 /** Fetch the backup queue for a flowring, and assign flow control thresholds */
243 void
dhd_flow_ring_config_thresholds(dhd_pub_t * dhdp,uint16 flowid,int queue_budget,int cumm_threshold,void * cumm_ctr,int l2cumm_threshold,void * l2cumm_ctr)244 dhd_flow_ring_config_thresholds(dhd_pub_t *dhdp, uint16 flowid,
245 int queue_budget, int cumm_threshold, void *cumm_ctr,
246 int l2cumm_threshold, void *l2cumm_ctr)
247 {
248 flow_queue_t * queue = NULL;
249
250 ASSERT(dhdp != (dhd_pub_t*)NULL);
251 ASSERT(queue_budget > 1);
252 ASSERT(cumm_threshold > 1);
253 ASSERT(cumm_ctr != (void*)NULL);
254 ASSERT(l2cumm_threshold > 1);
255 ASSERT(l2cumm_ctr != (void*)NULL);
256
257 queue = dhd_flow_queue(dhdp, flowid);
258 if (queue) {
259 DHD_FLOW_QUEUE_SET_MAX(queue, queue_budget); /* Max queue length */
260
261 /* Set the queue's parent threshold and cummulative counter */
262 DHD_FLOW_QUEUE_SET_THRESHOLD(queue, cumm_threshold);
263 DHD_FLOW_QUEUE_SET_CLEN(queue, cumm_ctr);
264
265 /* Set the queue's grandparent threshold and cummulative counter */
266 DHD_FLOW_QUEUE_SET_L2THRESHOLD(queue, l2cumm_threshold);
267 DHD_FLOW_QUEUE_SET_L2CLEN(queue, l2cumm_ctr);
268 }
269 }
270
271 uint8
dhd_num_prio_supported_per_flow_ring(dhd_pub_t * dhdp)272 dhd_num_prio_supported_per_flow_ring(dhd_pub_t *dhdp)
273 {
274 uint8 prio_count = 0;
275 int i;
276 // Pick all elements one by one
277 for (i = 0; i < NUMPRIO; i++)
278 {
279 // Check if the picked element is already counted
280 int j;
281 for (j = 0; j < i; j++) {
282 if (dhdp->flow_prio_map[i] == dhdp->flow_prio_map[j]) {
283 break;
284 }
285 }
286 // If not counted earlier, then count it
287 if (i == j) {
288 prio_count++;
289 }
290 }
291
292 #ifdef DHD_LOSSLESS_ROAMING
293 /* For LLR, we are using flowring with prio 7 which is not considered
294 * in prio2ac array. But in __dhd_sendpkt, it is hardcoded hardcoded
295 * prio to PRIO_8021D_NC and send to dhd_flowid_update.
296 * So add 1 to prio_count.
297 */
298 prio_count++;
299 #endif /* DHD_LOSSLESS_ROAMING */
300
301 return prio_count;
302 }
303
304 uint8
dhd_get_max_multi_client_flow_rings(dhd_pub_t * dhdp)305 dhd_get_max_multi_client_flow_rings(dhd_pub_t *dhdp)
306 {
307 uint8 reserved_infra_sta_flow_rings = dhd_num_prio_supported_per_flow_ring(dhdp);
308 uint8 total_tx_flow_rings = dhdp->num_flow_rings - dhdp->bus->max_cmn_rings;
309 uint8 max_multi_client_flow_rings = total_tx_flow_rings - reserved_infra_sta_flow_rings;
310 return max_multi_client_flow_rings;
311 }
312
313 /** Initializes data structures of multiple flow rings */
314 int
dhd_flow_rings_init(dhd_pub_t * dhdp,uint32 num_flow_rings)315 dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings)
316 {
317 uint32 idx;
318 uint32 flow_ring_table_sz;
319 uint32 if_flow_lkup_sz = 0;
320 void * flowid_allocator;
321 flow_ring_table_t *flow_ring_table = NULL;
322 if_flow_lkup_t *if_flow_lkup = NULL;
323 void *lock = NULL;
324 void *list_lock = NULL;
325 unsigned long flags;
326
327 DHD_INFO(("%s\n", __FUNCTION__));
328
329 /* Construct a 16bit flowid allocator */
330 flowid_allocator = id16_map_init(dhdp->osh,
331 num_flow_rings - dhdp->bus->max_cmn_rings, FLOWID_RESERVED);
332 if (flowid_allocator == NULL) {
333 DHD_ERROR(("%s: flowid allocator init failure\n", __FUNCTION__));
334 return BCME_NOMEM;
335 }
336
337 /* Allocate a flow ring table, comprising of requested number of rings */
338 flow_ring_table_sz = (num_flow_rings * sizeof(flow_ring_node_t));
339 flow_ring_table = (flow_ring_table_t *)MALLOCZ(dhdp->osh, flow_ring_table_sz);
340 if (flow_ring_table == NULL) {
341 DHD_ERROR(("%s: flow ring table alloc failure\n", __FUNCTION__));
342 goto fail;
343 }
344
345 /* Initialize flow ring table state */
346 DHD_CUMM_CTR_INIT(&dhdp->cumm_ctr);
347 DHD_CUMM_CTR_INIT(&dhdp->l2cumm_ctr);
348 bzero((uchar *)flow_ring_table, flow_ring_table_sz);
349 for (idx = 0; idx < num_flow_rings; idx++) {
350 flow_ring_table[idx].status = FLOW_RING_STATUS_CLOSED;
351 flow_ring_table[idx].flowid = (uint16)idx;
352 flow_ring_table[idx].lock = dhd_os_spin_lock_init(dhdp->osh);
353 #ifdef IDLE_TX_FLOW_MGMT
354 flow_ring_table[idx].last_active_ts = OSL_SYSUPTIME();
355 #endif /* IDLE_TX_FLOW_MGMT */
356 if (flow_ring_table[idx].lock == NULL) {
357 DHD_ERROR(("%s: Failed to init spinlock for queue!\n", __FUNCTION__));
358 goto fail;
359 }
360
361 dll_init(&flow_ring_table[idx].list);
362
363 /* Initialize the per flow ring backup queue */
364 dhd_flow_queue_init(dhdp, &flow_ring_table[idx].queue,
365 dhdp->conf->flow_ring_queue_threshold);
366 }
367
368 /* Allocate per interface hash table (for fast lookup from interface to flow ring) */
369 if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS;
370 if_flow_lkup = (if_flow_lkup_t *)DHD_OS_PREALLOC(dhdp,
371 DHD_PREALLOC_IF_FLOW_LKUP, if_flow_lkup_sz);
372 if (if_flow_lkup == NULL) {
373 DHD_ERROR(("%s: if flow lkup alloc failure\n", __FUNCTION__));
374 goto fail;
375 }
376
377 /* Initialize per interface hash table */
378 for (idx = 0; idx < DHD_MAX_IFS; idx++) {
379 int hash_ix;
380 if_flow_lkup[idx].status = 0;
381 if_flow_lkup[idx].role = 0;
382 for (hash_ix = 0; hash_ix < DHD_FLOWRING_HASH_SIZE; hash_ix++)
383 if_flow_lkup[idx].fl_hash[hash_ix] = NULL;
384 }
385
386 lock = dhd_os_spin_lock_init(dhdp->osh);
387 if (lock == NULL)
388 goto fail;
389
390 list_lock = dhd_os_spin_lock_init(dhdp->osh);
391 if (list_lock == NULL)
392 goto lock_fail;
393
394 dhdp->flow_prio_map_type = DHD_FLOW_PRIO_AC_MAP;
395 bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
396
397 dhdp->max_multi_client_flow_rings = dhd_get_max_multi_client_flow_rings(dhdp);
398 dhdp->multi_client_flow_rings = 0U;
399
400 #ifdef DHD_LOSSLESS_ROAMING
401 dhdp->dequeue_prec_map = ALLPRIO;
402 #endif // endif
403 /* Now populate into dhd pub */
404 DHD_FLOWID_LOCK(lock, flags);
405 dhdp->num_flow_rings = num_flow_rings;
406 dhdp->flowid_allocator = (void *)flowid_allocator;
407 dhdp->flow_ring_table = (void *)flow_ring_table;
408 dhdp->if_flow_lkup = (void *)if_flow_lkup;
409 dhdp->flowid_lock = lock;
410 dhdp->flow_rings_inited = TRUE;
411 dhdp->flowring_list_lock = list_lock;
412 DHD_FLOWID_UNLOCK(lock, flags);
413
414 DHD_INFO(("%s done\n", __FUNCTION__));
415 return BCME_OK;
416
417 lock_fail:
418 /* deinit the spinlock */
419 dhd_os_spin_lock_deinit(dhdp->osh, lock);
420
421 fail:
422 /* Destruct the per interface flow lkup table */
423 if (if_flow_lkup != NULL) {
424 DHD_OS_PREFREE(dhdp, if_flow_lkup, if_flow_lkup_sz);
425 }
426 if (flow_ring_table != NULL) {
427 for (idx = 0; idx < num_flow_rings; idx++) {
428 if (flow_ring_table[idx].lock != NULL)
429 dhd_os_spin_lock_deinit(dhdp->osh, flow_ring_table[idx].lock);
430 }
431 MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz);
432 }
433 id16_map_fini(dhdp->osh, flowid_allocator);
434
435 return BCME_NOMEM;
436 }
437
438 /** Deinit Flow Ring specific data structures */
dhd_flow_rings_deinit(dhd_pub_t * dhdp)439 void dhd_flow_rings_deinit(dhd_pub_t *dhdp)
440 {
441 uint16 idx;
442 uint32 flow_ring_table_sz;
443 uint32 if_flow_lkup_sz;
444 flow_ring_table_t *flow_ring_table;
445 unsigned long flags;
446 void *lock;
447
448 DHD_INFO(("dhd_flow_rings_deinit\n"));
449
450 if (!(dhdp->flow_rings_inited)) {
451 DHD_ERROR(("dhd_flow_rings not initialized!\n"));
452 return;
453 }
454
455 if (dhdp->flow_ring_table != NULL) {
456
457 ASSERT(dhdp->num_flow_rings > 0);
458
459 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
460 flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
461 dhdp->flow_ring_table = NULL;
462 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
463 for (idx = 0; idx < dhdp->num_flow_rings; idx++) {
464 if (flow_ring_table[idx].active) {
465 dhd_bus_clean_flow_ring(dhdp->bus, &flow_ring_table[idx]);
466 }
467 ASSERT(DHD_FLOW_QUEUE_EMPTY(&flow_ring_table[idx].queue));
468
469 /* Deinit flow ring queue locks before destroying flow ring table */
470 if (flow_ring_table[idx].lock != NULL) {
471 dhd_os_spin_lock_deinit(dhdp->osh, flow_ring_table[idx].lock);
472 }
473 flow_ring_table[idx].lock = NULL;
474
475 }
476
477 /* Destruct the flow ring table */
478 flow_ring_table_sz = dhdp->num_flow_rings * sizeof(flow_ring_table_t);
479 MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz);
480 }
481
482 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
483
484 /* Destruct the per interface flow lkup table */
485 if (dhdp->if_flow_lkup != NULL) {
486 if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS;
487 bzero((uchar *)dhdp->if_flow_lkup, if_flow_lkup_sz);
488 DHD_OS_PREFREE(dhdp, dhdp->if_flow_lkup, if_flow_lkup_sz);
489 dhdp->if_flow_lkup = NULL;
490 }
491
492 /* Destruct the flowid allocator */
493 if (dhdp->flowid_allocator != NULL)
494 dhdp->flowid_allocator = id16_map_fini(dhdp->osh, dhdp->flowid_allocator);
495
496 dhdp->num_flow_rings = 0U;
497 bzero(dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
498
499 dhdp->max_multi_client_flow_rings = 0U;
500 dhdp->multi_client_flow_rings = 0U;
501
502 lock = dhdp->flowid_lock;
503 dhdp->flowid_lock = NULL;
504
505 if (lock) {
506 DHD_FLOWID_UNLOCK(lock, flags);
507 dhd_os_spin_lock_deinit(dhdp->osh, lock);
508 }
509
510 dhd_os_spin_lock_deinit(dhdp->osh, dhdp->flowring_list_lock);
511 dhdp->flowring_list_lock = NULL;
512
513 ASSERT(dhdp->if_flow_lkup == NULL);
514 ASSERT(dhdp->flowid_allocator == NULL);
515 ASSERT(dhdp->flow_ring_table == NULL);
516 dhdp->flow_rings_inited = FALSE;
517 }
518
519 /** Uses hash table to quickly map from ifindex to a flow ring 'role' (STA/AP) */
520 uint8
dhd_flow_rings_ifindex2role(dhd_pub_t * dhdp,uint8 ifindex)521 dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex)
522 {
523 if_flow_lkup_t *if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
524 ASSERT(if_flow_lkup);
525 return if_flow_lkup[ifindex].role;
526 }
527
528 #ifdef WLTDLS
is_tdls_destination(dhd_pub_t * dhdp,uint8 * da)529 bool is_tdls_destination(dhd_pub_t *dhdp, uint8 *da)
530 {
531 unsigned long flags;
532 tdls_peer_node_t *cur = NULL;
533
534 DHD_TDLS_LOCK(&dhdp->tdls_lock, flags);
535 cur = dhdp->peer_tbl.node;
536
537 while (cur != NULL) {
538 if (!memcmp(da, cur->addr, ETHER_ADDR_LEN)) {
539 DHD_TDLS_UNLOCK(&dhdp->tdls_lock, flags);
540 return TRUE;
541 }
542 cur = cur->next;
543 }
544 DHD_TDLS_UNLOCK(&dhdp->tdls_lock, flags);
545 return FALSE;
546 }
547 #endif /* WLTDLS */
548
549 /** Uses hash table to quickly map from ifindex+prio+da to a flow ring id */
550 static INLINE uint16
dhd_flowid_find(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da)551 dhd_flowid_find(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da)
552 {
553 int hash;
554 bool ismcast = FALSE;
555 flow_hash_info_t *cur;
556 if_flow_lkup_t *if_flow_lkup;
557 unsigned long flags;
558
559 ASSERT(ifindex < DHD_MAX_IFS);
560 if (ifindex >= DHD_MAX_IFS)
561 return FLOWID_INVALID;
562
563 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
564 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
565
566 ASSERT(if_flow_lkup);
567
568 if (DHD_IF_ROLE_GENERIC_STA(dhdp, ifindex)) {
569 #ifdef WLTDLS
570 if (dhdp->peer_tbl.tdls_peer_count && !(ETHER_ISMULTI(da)) &&
571 is_tdls_destination(dhdp, da)) {
572 hash = DHD_FLOWRING_HASHINDEX(da, prio);
573 cur = if_flow_lkup[ifindex].fl_hash[hash];
574 while (cur != NULL) {
575 if (!memcmp(cur->flow_info.da, da, ETHER_ADDR_LEN)) {
576 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
577 return cur->flowid;
578 }
579 cur = cur->next;
580 }
581 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
582 return FLOWID_INVALID;
583 }
584 #endif /* WLTDLS */
585 /* For STA non TDLS dest and WDS dest flow ring id is mapped based on prio only */
586 cur = if_flow_lkup[ifindex].fl_hash[prio];
587 if (cur) {
588 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
589 return cur->flowid;
590 }
591 } else {
592
593 if (ETHER_ISMULTI(da)) {
594 ismcast = TRUE;
595 hash = 0;
596 } else {
597 hash = DHD_FLOWRING_HASHINDEX(da, prio);
598 }
599
600 cur = if_flow_lkup[ifindex].fl_hash[hash];
601
602 while (cur) {
603 if ((ismcast && ETHER_ISMULTI(cur->flow_info.da)) ||
604 (!memcmp(cur->flow_info.da, da, ETHER_ADDR_LEN) &&
605 (cur->flow_info.tid == prio))) {
606 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
607 return cur->flowid;
608 }
609 cur = cur->next;
610 }
611 }
612 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
613
614 DHD_INFO(("%s: cannot find flowid\n", __FUNCTION__));
615 return FLOWID_INVALID;
616 } /* dhd_flowid_find */
617
618 /** Create unique Flow ID, called when a flow ring is created. */
619 static INLINE uint16
dhd_flowid_alloc(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da)620 dhd_flowid_alloc(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da)
621 {
622 flow_hash_info_t *fl_hash_node, *cur;
623 if_flow_lkup_t *if_flow_lkup;
624 int hash;
625 uint16 flowid;
626 unsigned long flags;
627
628 fl_hash_node = (flow_hash_info_t *) MALLOCZ(dhdp->osh, sizeof(flow_hash_info_t));
629 if (fl_hash_node == NULL) {
630 DHD_ERROR(("%s: flow_hash_info_t memory allocation failed \n", __FUNCTION__));
631 return FLOWID_INVALID;
632 }
633 memcpy(fl_hash_node->flow_info.da, da, sizeof(fl_hash_node->flow_info.da));
634
635 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
636 ASSERT(dhdp->flowid_allocator != NULL);
637 flowid = id16_map_alloc(dhdp->flowid_allocator);
638 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
639
640 if (flowid == FLOWID_INVALID) {
641 MFREE(dhdp->osh, fl_hash_node, sizeof(flow_hash_info_t));
642 DHD_ERROR_RLMT(("%s: cannot get free flowid \n", __FUNCTION__));
643 return FLOWID_INVALID;
644 }
645
646 fl_hash_node->flowid = flowid;
647 fl_hash_node->flow_info.tid = prio;
648 fl_hash_node->flow_info.ifindex = ifindex;
649 fl_hash_node->next = NULL;
650
651 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
652 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
653
654 if (DHD_IF_ROLE_GENERIC_STA(dhdp, ifindex)) {
655 /* For STA/GC non TDLS dest and WDS dest we allocate entry based on prio only */
656 #ifdef WLTDLS
657 if (dhdp->peer_tbl.tdls_peer_count &&
658 (is_tdls_destination(dhdp, da))) {
659 hash = DHD_FLOWRING_HASHINDEX(da, prio);
660 cur = if_flow_lkup[ifindex].fl_hash[hash];
661 if (cur) {
662 while (cur->next) {
663 cur = cur->next;
664 }
665 cur->next = fl_hash_node;
666 } else {
667 if_flow_lkup[ifindex].fl_hash[hash] = fl_hash_node;
668 }
669 } else
670 #endif /* WLTDLS */
671 if_flow_lkup[ifindex].fl_hash[prio] = fl_hash_node;
672 } else {
673
674 /* For bcast/mcast assign first slot in in interface */
675 hash = ETHER_ISMULTI(da) ? 0 : DHD_FLOWRING_HASHINDEX(da, prio);
676 cur = if_flow_lkup[ifindex].fl_hash[hash];
677 if (cur) {
678 while (cur->next) {
679 cur = cur->next;
680 }
681 cur->next = fl_hash_node;
682 } else
683 if_flow_lkup[ifindex].fl_hash[hash] = fl_hash_node;
684 }
685 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
686
687 DHD_INFO(("%s: allocated flowid %d\n", __FUNCTION__, fl_hash_node->flowid));
688
689 if (fl_hash_node->flowid >= dhdp->num_flow_rings) {
690 DHD_ERROR(("%s: flowid=%d num_flow_rings=%d ifindex=%d prio=%d role=%d\n",
691 __FUNCTION__, fl_hash_node->flowid, dhdp->num_flow_rings,
692 ifindex, prio, if_flow_lkup[ifindex].role));
693 dhd_prhex("da", (uchar *)da, ETHER_ADDR_LEN, DHD_ERROR_VAL);
694 dhd_prhex("sa", (uchar *)sa, ETHER_ADDR_LEN, DHD_ERROR_VAL);
695 return FLOWID_INVALID;
696 }
697
698 return fl_hash_node->flowid;
699 } /* dhd_flowid_alloc */
700
701 /** Get flow ring ID, if not present try to create one */
702 static INLINE int
dhd_flowid_lookup(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da,uint16 * flowid)703 dhd_flowid_lookup(dhd_pub_t *dhdp, uint8 ifindex,
704 uint8 prio, char *sa, char *da, uint16 *flowid)
705 {
706 uint16 id;
707 flow_ring_node_t *flow_ring_node;
708 flow_ring_table_t *flow_ring_table;
709 unsigned long flags;
710 int ret;
711
712 DHD_TRACE(("%s\n", __FUNCTION__));
713
714 if (!dhdp->flow_ring_table) {
715 return BCME_ERROR;
716 }
717
718 ASSERT(ifindex < DHD_MAX_IFS);
719 if (ifindex >= DHD_MAX_IFS)
720 return BCME_BADARG;
721
722 flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
723
724 id = dhd_flowid_find(dhdp, ifindex, prio, sa, da);
725
726 if (id == FLOWID_INVALID) {
727 bool if_role_multi_client;
728 if_flow_lkup_t *if_flow_lkup;
729 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
730
731 if (!if_flow_lkup[ifindex].status)
732 return BCME_ERROR;
733
734 /* check role for multi client case */
735 if_role_multi_client = DHD_IF_ROLE_MULTI_CLIENT(dhdp, ifindex);
736
737 /* Abort Flowring creation if multi client flowrings crossed the threshold */
738 #ifdef DHD_LIMIT_MULTI_CLIENT_FLOWRINGS
739 if (if_role_multi_client &&
740 (dhdp->multi_client_flow_rings >= dhdp->max_multi_client_flow_rings)) {
741 DHD_ERROR_RLMT(("%s: Max multi client flow rings reached: %d:%d\n",
742 __FUNCTION__, dhdp->multi_client_flow_rings,
743 dhdp->max_multi_client_flow_rings));
744 return BCME_ERROR;
745 }
746 #endif /* DHD_LIMIT_MULTI_CLIENT_FLOWRINGS */
747
748 /* Do not create Flowring if peer is not associated */
749 #if defined(PCIE_FULL_DONGLE)
750 if (if_role_multi_client && !ETHER_ISMULTI(da) &&
751 !dhd_sta_associated(dhdp, ifindex, (uint8 *)da)) {
752 DHD_ERROR_RLMT(("%s: Skip send pkt without peer addition\n", __FUNCTION__));
753 return BCME_ERROR;
754 }
755 #endif /* (linux || LINUX) && PCIE_FULL_DONGLE */
756
757 id = dhd_flowid_alloc(dhdp, ifindex, prio, sa, da);
758 if (id == FLOWID_INVALID) {
759 DHD_ERROR_RLMT(("%s: alloc flowid ifindex %u status %u\n",
760 __FUNCTION__, ifindex, if_flow_lkup[ifindex].status));
761 return BCME_ERROR;
762 }
763
764 ASSERT(id < dhdp->num_flow_rings);
765
766 /* Only after flowid alloc, increment multi_client_flow_rings */
767 if (if_role_multi_client) {
768 dhdp->multi_client_flow_rings++;
769 }
770
771 /* register this flowid in dhd_pub */
772 dhd_add_flowid(dhdp, ifindex, prio, da, id);
773
774 flow_ring_node = (flow_ring_node_t *) &flow_ring_table[id];
775
776 DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
777
778 /* Init Flow info */
779 memcpy(flow_ring_node->flow_info.sa, sa, sizeof(flow_ring_node->flow_info.sa));
780 memcpy(flow_ring_node->flow_info.da, da, sizeof(flow_ring_node->flow_info.da));
781 flow_ring_node->flow_info.tid = prio;
782 flow_ring_node->flow_info.ifindex = ifindex;
783 flow_ring_node->active = TRUE;
784 flow_ring_node->status = FLOW_RING_STATUS_CREATE_PENDING;
785
786 #ifdef TX_STATUS_LATENCY_STATS
787 flow_ring_node->flow_info.num_tx_status = 0;
788 flow_ring_node->flow_info.cum_tx_status_latency = 0;
789 flow_ring_node->flow_info.num_tx_pkts = 0;
790 #endif /* TX_STATUS_LATENCY_STATS */
791 DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
792
793 /* Create and inform device about the new flow */
794 if (dhd_bus_flow_ring_create_request(dhdp->bus, (void *)flow_ring_node)
795 != BCME_OK) {
796 DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
797 flow_ring_node->status = FLOW_RING_STATUS_CLOSED;
798 flow_ring_node->active = FALSE;
799 DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
800 DHD_ERROR(("%s: create error %d\n", __FUNCTION__, id));
801 return BCME_ERROR;
802 }
803
804 *flowid = id;
805 return BCME_OK;
806 } else {
807 /* if the Flow id was found in the hash */
808
809 if (id >= dhdp->num_flow_rings) {
810 DHD_ERROR(("%s: Invalid flow id : %u, num_flow_rings : %u\n",
811 __FUNCTION__, id, dhdp->num_flow_rings));
812 *flowid = FLOWID_INVALID;
813 ASSERT(0);
814 return BCME_ERROR;
815 }
816
817 flow_ring_node = (flow_ring_node_t *) &flow_ring_table[id];
818 DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
819
820 /*
821 * If the flow_ring_node is in Open State or Status pending state then
822 * we can return the Flow id to the caller.If the flow_ring_node is in
823 * FLOW_RING_STATUS_PENDING this means the creation is in progress and
824 * hence the packets should be queued.
825 *
826 * If the flow_ring_node is in FLOW_RING_STATUS_DELETE_PENDING Or
827 * FLOW_RING_STATUS_CLOSED, then we should return Error.
828 * Note that if the flowing is being deleted we would mark it as
829 * FLOW_RING_STATUS_DELETE_PENDING. Now before Dongle could respond and
830 * before we mark it as FLOW_RING_STATUS_CLOSED we could get tx packets.
831 * We should drop the packets in that case.
832 * The decission to return OK should NOT be based on 'active' variable, beause
833 * active is made TRUE when a flow_ring_node gets allocated and is made
834 * FALSE when the flow ring gets removed and does not reflect the True state
835 * of the Flow ring.
836 * In case if IDLE_TX_FLOW_MGMT is defined, we have to handle two more flowring
837 * states. If the flow_ring_node's status is FLOW_RING_STATUS_SUSPENDED, the flowid
838 * is to be returned and from dhd_bus_txdata, the flowring would be resumed again.
839 * The status FLOW_RING_STATUS_RESUME_PENDING, is equivalent to
840 * FLOW_RING_STATUS_CREATE_PENDING.
841 */
842 if (flow_ring_node->status == FLOW_RING_STATUS_DELETE_PENDING ||
843 flow_ring_node->status == FLOW_RING_STATUS_CLOSED) {
844 *flowid = FLOWID_INVALID;
845 ret = BCME_ERROR;
846 } else {
847 *flowid = id;
848 ret = BCME_OK;
849 }
850
851 DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
852 return ret;
853 } /* Flow Id found in the hash */
854 } /* dhd_flowid_lookup */
855
856 int
dhd_flowid_find_by_ifidx(dhd_pub_t * dhdp,uint8 ifindex,uint16 flowid)857 dhd_flowid_find_by_ifidx(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid)
858 {
859 int hashidx = 0;
860 bool found = FALSE;
861 flow_hash_info_t *cur;
862 if_flow_lkup_t *if_flow_lkup;
863 unsigned long flags;
864
865 if (!dhdp->flow_ring_table) {
866 DHD_ERROR(("%s : dhd->flow_ring_table is NULL\n", __FUNCTION__));
867 return BCME_ERROR;
868 }
869
870 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
871 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
872 for (hashidx = 0; hashidx < DHD_FLOWRING_HASH_SIZE; hashidx++) {
873 cur = if_flow_lkup[ifindex].fl_hash[hashidx];
874 if (cur) {
875 if (cur->flowid == flowid) {
876 found = TRUE;
877 }
878
879 while (!found && cur) {
880 if (cur->flowid == flowid) {
881 found = TRUE;
882 break;
883 }
884 cur = cur->next;
885 }
886
887 if (found) {
888 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
889 return BCME_OK;
890 }
891 }
892 }
893 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
894
895 return BCME_ERROR;
896 }
897
898 int
dhd_flowid_debug_create(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da,uint16 * flowid)899 dhd_flowid_debug_create(dhd_pub_t *dhdp, uint8 ifindex,
900 uint8 prio, char *sa, char *da, uint16 *flowid)
901 {
902 return dhd_flowid_lookup(dhdp, ifindex, prio, sa, da, flowid);
903 }
904
905 /**
906 * Assign existing or newly created flowid to an 802.3 packet. This flowid is later on used to
907 * select the flowring to send the packet to the dongle.
908 */
909 int BCMFASTPATH
dhd_flowid_update(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,void * pktbuf)910 dhd_flowid_update(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, void *pktbuf)
911 {
912 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
913 struct ether_header *eh = (struct ether_header *)pktdata;
914 uint16 flowid = 0;
915
916 ASSERT(ifindex < DHD_MAX_IFS);
917
918 if (ifindex >= DHD_MAX_IFS) {
919 return BCME_BADARG;
920 }
921
922 if (!dhdp->flowid_allocator) {
923 DHD_ERROR(("%s: Flow ring not intited yet \n", __FUNCTION__));
924 return BCME_ERROR;
925 }
926
927 if (dhd_flowid_lookup(dhdp, ifindex, prio, (char *)eh->ether_shost, (char *)eh->ether_dhost,
928 &flowid) != BCME_OK) {
929 return BCME_ERROR;
930 }
931
932 DHD_INFO(("%s: prio %d flowid %d\n", __FUNCTION__, prio, flowid));
933
934 /* Tag the packet with flowid */
935 DHD_PKT_SET_FLOWID(pktbuf, flowid);
936 return BCME_OK;
937 }
938
939 void
dhd_flowid_free(dhd_pub_t * dhdp,uint8 ifindex,uint16 flowid)940 dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid)
941 {
942 int hashix;
943 bool found = FALSE;
944 flow_hash_info_t *cur, *prev;
945 if_flow_lkup_t *if_flow_lkup;
946 unsigned long flags;
947 bool if_role_multi_client;
948
949 ASSERT(ifindex < DHD_MAX_IFS);
950 if (ifindex >= DHD_MAX_IFS)
951 return;
952
953 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
954 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
955
956 if_role_multi_client = DHD_IF_ROLE_MULTI_CLIENT(dhdp, ifindex);
957
958 for (hashix = 0; hashix < DHD_FLOWRING_HASH_SIZE; hashix++) {
959
960 cur = if_flow_lkup[ifindex].fl_hash[hashix];
961
962 if (cur) {
963 if (cur->flowid == flowid) {
964 found = TRUE;
965 }
966
967 prev = NULL;
968 while (!found && cur) {
969 if (cur->flowid == flowid) {
970 found = TRUE;
971 break;
972 }
973 prev = cur;
974 cur = cur->next;
975 }
976 if (found) {
977 if (!prev) {
978 if_flow_lkup[ifindex].fl_hash[hashix] = cur->next;
979 } else {
980 prev->next = cur->next;
981 }
982
983 /* Decrement multi_client_flow_rings */
984 if (if_role_multi_client) {
985 dhdp->multi_client_flow_rings--;
986 }
987
988 /* deregister flowid from dhd_pub. */
989 dhd_del_flowid(dhdp, ifindex, flowid);
990
991 id16_map_free(dhdp->flowid_allocator, flowid);
992 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
993 MFREE(dhdp->osh, cur, sizeof(flow_hash_info_t));
994
995 return;
996 }
997 }
998 }
999
1000 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1001 DHD_ERROR(("%s: could not free flow ring hash entry flowid %d\n",
1002 __FUNCTION__, flowid));
1003 } /* dhd_flowid_free */
1004
1005 /**
1006 * Delete all Flow rings associated with the given interface. Is called when eg the dongle
1007 * indicates that a wireless link has gone down.
1008 */
1009 void
dhd_flow_rings_delete(dhd_pub_t * dhdp,uint8 ifindex)1010 dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex)
1011 {
1012 uint32 id;
1013 flow_ring_table_t *flow_ring_table;
1014
1015 DHD_ERROR(("%s: ifindex %u\n", __FUNCTION__, ifindex));
1016
1017 ASSERT(ifindex < DHD_MAX_IFS);
1018 if (ifindex >= DHD_MAX_IFS)
1019 return;
1020
1021 if (!dhdp->flow_ring_table)
1022 return;
1023
1024 flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
1025 for (id = 0; id < dhdp->num_flow_rings; id++) {
1026 if (flow_ring_table[id].active &&
1027 (flow_ring_table[id].flow_info.ifindex == ifindex) &&
1028 (flow_ring_table[id].status == FLOW_RING_STATUS_OPEN)) {
1029 dhd_bus_flow_ring_delete_request(dhdp->bus,
1030 (void *) &flow_ring_table[id]);
1031 }
1032 }
1033 }
1034
1035 void
dhd_flow_rings_flush(dhd_pub_t * dhdp,uint8 ifindex)1036 dhd_flow_rings_flush(dhd_pub_t *dhdp, uint8 ifindex)
1037 {
1038 uint32 id;
1039 flow_ring_table_t *flow_ring_table;
1040
1041 DHD_INFO(("%s: ifindex %u\n", __FUNCTION__, ifindex));
1042
1043 ASSERT(ifindex < DHD_MAX_IFS);
1044 if (ifindex >= DHD_MAX_IFS)
1045 return;
1046
1047 if (!dhdp->flow_ring_table)
1048 return;
1049 flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
1050
1051 for (id = 0; id < dhdp->num_flow_rings; id++) {
1052 if (flow_ring_table[id].active &&
1053 (flow_ring_table[id].flow_info.ifindex == ifindex) &&
1054 (flow_ring_table[id].status == FLOW_RING_STATUS_OPEN)) {
1055 dhd_bus_flow_ring_flush_request(dhdp->bus,
1056 (void *) &flow_ring_table[id]);
1057 }
1058 }
1059 }
1060
1061 /** Delete flow ring(s) for given peer address. Related to AP/AWDL/TDLS functionality. */
1062 void
dhd_flow_rings_delete_for_peer(dhd_pub_t * dhdp,uint8 ifindex,char * addr)1063 dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex, char *addr)
1064 {
1065 uint32 id;
1066 flow_ring_table_t *flow_ring_table;
1067
1068 DHD_ERROR(("%s: ifindex %u\n", __FUNCTION__, ifindex));
1069
1070 ASSERT(ifindex < DHD_MAX_IFS);
1071 if (ifindex >= DHD_MAX_IFS)
1072 return;
1073
1074 if (!dhdp->flow_ring_table)
1075 return;
1076
1077 flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
1078 for (id = 0; id < dhdp->num_flow_rings; id++) {
1079 /*
1080 * Send flowring delete request even if flowring status is
1081 * FLOW_RING_STATUS_CREATE_PENDING, to handle cases where DISASSOC_IND
1082 * event comes ahead of flowring create response.
1083 * Otherwise the flowring will not be deleted later as there will not be any
1084 * DISASSOC_IND event. With this change, when create response event comes to DHD,
1085 * it will change the status to FLOW_RING_STATUS_OPEN and soon delete response
1086 * event will come, upon which DHD will delete the flowring.
1087 */
1088 if (flow_ring_table[id].active &&
1089 (flow_ring_table[id].flow_info.ifindex == ifindex) &&
1090 (!memcmp(flow_ring_table[id].flow_info.da, addr, ETHER_ADDR_LEN)) &&
1091 ((flow_ring_table[id].status == FLOW_RING_STATUS_OPEN) ||
1092 (flow_ring_table[id].status == FLOW_RING_STATUS_CREATE_PENDING))) {
1093 DHD_ERROR(("%s: deleting flowid %d\n",
1094 __FUNCTION__, flow_ring_table[id].flowid));
1095 dhd_bus_flow_ring_delete_request(dhdp->bus,
1096 (void *) &flow_ring_table[id]);
1097 }
1098 }
1099 }
1100
1101 /** Handles interface ADD, CHANGE, DEL indications from the dongle */
1102 void
dhd_update_interface_flow_info(dhd_pub_t * dhdp,uint8 ifindex,uint8 op,uint8 role)1103 dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex,
1104 uint8 op, uint8 role)
1105 {
1106 if_flow_lkup_t *if_flow_lkup;
1107 unsigned long flags;
1108
1109 ASSERT(ifindex < DHD_MAX_IFS);
1110 if (ifindex >= DHD_MAX_IFS)
1111 return;
1112
1113 DHD_INFO(("%s: ifindex %u op %u role is %u \n",
1114 __FUNCTION__, ifindex, op, role));
1115 if (!dhdp->flowid_allocator) {
1116 DHD_ERROR(("%s: Flow ring not intited yet \n", __FUNCTION__));
1117 return;
1118 }
1119
1120 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
1121 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
1122
1123 if (op == WLC_E_IF_ADD || op == WLC_E_IF_CHANGE) {
1124
1125 if_flow_lkup[ifindex].role = role;
1126
1127 if (role == WLC_E_IF_ROLE_WDS) {
1128 /**
1129 * WDS role does not send WLC_E_LINK event after interface is up.
1130 * So to create flowrings for WDS, make status as TRUE in WLC_E_IF itself.
1131 * same is true while making the status as FALSE.
1132 * TODO: Fix FW to send WLC_E_LINK for WDS role aswell. So that all the
1133 * interfaces are handled uniformly.
1134 */
1135 if_flow_lkup[ifindex].status = TRUE;
1136 DHD_INFO(("%s: Mcast Flow ring for ifindex %d role is %d \n",
1137 __FUNCTION__, ifindex, role));
1138 }
1139 } else if ((op == WLC_E_IF_DEL) && (role == WLC_E_IF_ROLE_WDS)) {
1140 if_flow_lkup[ifindex].status = FALSE;
1141 DHD_INFO(("%s: cleanup all Flow rings for ifindex %d role is %d \n",
1142 __FUNCTION__, ifindex, role));
1143 }
1144 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1145 }
1146
1147 /** Handles a STA 'link' indication from the dongle */
1148 int
dhd_update_interface_link_status(dhd_pub_t * dhdp,uint8 ifindex,uint8 status)1149 dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex, uint8 status)
1150 {
1151 if_flow_lkup_t *if_flow_lkup;
1152 unsigned long flags;
1153
1154 ASSERT(ifindex < DHD_MAX_IFS);
1155 if (ifindex >= DHD_MAX_IFS)
1156 return BCME_BADARG;
1157
1158 DHD_INFO(("%s: ifindex %d status %d\n", __FUNCTION__, ifindex, status));
1159
1160 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
1161 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
1162
1163 if (status) {
1164 if_flow_lkup[ifindex].status = TRUE;
1165 } else {
1166 if_flow_lkup[ifindex].status = FALSE;
1167 }
1168
1169 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1170
1171 return BCME_OK;
1172 }
1173
1174 /** Update flow priority mapping, called on IOVAR */
dhd_update_flow_prio_map(dhd_pub_t * dhdp,uint8 map)1175 int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map)
1176 {
1177 uint16 flowid;
1178 flow_ring_node_t *flow_ring_node;
1179
1180 if (map > DHD_FLOW_PRIO_LLR_MAP)
1181 return BCME_BADOPTION;
1182
1183 /* Check if we need to change prio map */
1184 if (map == dhdp->flow_prio_map_type)
1185 return BCME_OK;
1186
1187 /* If any ring is active we cannot change priority mapping for flow rings */
1188 for (flowid = 0; flowid < dhdp->num_flow_rings; flowid++) {
1189 flow_ring_node = DHD_FLOW_RING(dhdp, flowid);
1190 if (flow_ring_node->active)
1191 return BCME_EPERM;
1192 }
1193
1194 /* Inform firmware about new mapping type */
1195 if (BCME_OK != dhd_flow_prio_map(dhdp, &map, TRUE))
1196 return BCME_ERROR;
1197
1198 /* update internal structures */
1199 dhdp->flow_prio_map_type = map;
1200 if (dhdp->flow_prio_map_type == DHD_FLOW_PRIO_TID_MAP)
1201 bcopy(prio2tid, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
1202 else
1203 bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
1204
1205 dhdp->max_multi_client_flow_rings = dhd_get_max_multi_client_flow_rings(dhdp);
1206
1207 return BCME_OK;
1208 }
1209
1210 /** Inform firmware on updated flow priority mapping, called on IOVAR */
dhd_flow_prio_map(dhd_pub_t * dhd,uint8 * map,bool set)1211 int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set)
1212 {
1213 uint8 iovbuf[24];
1214 int len;
1215 if (!set) {
1216 memset(&iovbuf, 0, sizeof(iovbuf));
1217 len = bcm_mkiovar("bus:fl_prio_map", NULL, 0, (char*)iovbuf, sizeof(iovbuf));
1218 if (len == 0) {
1219 return BCME_BUFTOOSHORT;
1220 }
1221 if (dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0) < 0) {
1222 DHD_ERROR(("%s: failed to get fl_prio_map\n", __FUNCTION__));
1223 return BCME_ERROR;
1224 }
1225 *map = iovbuf[0];
1226 return BCME_OK;
1227 }
1228 len = bcm_mkiovar("bus:fl_prio_map", (char *)map, 4, (char*)iovbuf, sizeof(iovbuf));
1229 if (len == 0) {
1230 return BCME_BUFTOOSHORT;
1231 }
1232 if (dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, len, TRUE, 0) < 0) {
1233 DHD_ERROR(("%s: failed to set fl_prio_map \n",
1234 __FUNCTION__));
1235 return BCME_ERROR;
1236 }
1237 return BCME_OK;
1238 }
1239