-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdhd_wlfc.c
4770 lines (4059 loc) · 126 KB
/
dhd_wlfc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* DHD PROP_TXSTATUS Module.
*
* Copyright (C) 2022, Broadcom.
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed to you
* under the terms of the GNU General Public License version 2 (the "GPL"),
* available at http://www.broadcom.com/licenses/GPLv2.php, with the
* following added to such license:
*
* As a special exception, the copyright holders of this software give you
* permission to link this software with independent modules, and to copy and
* distribute the resulting executable under terms of your choice, provided that
* you also meet, for each linked independent module, the terms and conditions of
* the license of that module. An independent module is a module which is not
* derived from this software. The special exception does not apply to any
* modifications of the software.
*
*
* <<Broadcom-WL-IPTag/Open:>>
*
* $Id$
*
*/
/** XXX Twiki [PropTxStatus] */
#include <typedefs.h>
#include <osl.h>
#include <bcmutils.h>
#include <bcmendian.h>
#include <dngl_stats.h>
#include <dhd.h>
#include <dhd_bus.h>
#include <dhd_dbg.h>
#include <dhd_config.h>
#include <wl_android.h>
#ifdef PROP_TXSTATUS /* a form of flow control between host and dongle */
#include <wlfc_proto.h>
#include <dhd_wlfc.h>
#endif
#ifdef DHDTCPACK_SUPPRESS
#include <dhd_ip.h>
#endif /* DHDTCPACK_SUPPRESS */
/*
* wlfc naming and lock rules:
*
* 1. Private functions name like _dhd_wlfc_XXX, declared as static and avoid wlfc lock operation.
* 2. Public functions name like dhd_wlfc_XXX, use wlfc lock if needed.
* 3. Non-Proptxstatus module call public functions only and avoid wlfc lock operation.
*
*/
#if defined(DHD_WLFC_THREAD)
#define WLFC_THREAD_QUICK_RETRY_WAIT_MS 10 /* 10 msec */
#define WLFC_THREAD_RETRY_WAIT_MS 10000 /* 10 sec */
#endif /* defined (DHD_WLFC_THREAD) */
#ifdef PROP_TXSTATUS
#ifdef QMONITOR
#define DHD_WLFC_QMON_COMPLETE(entry) dhd_qmon_txcomplete(&entry->qmon)
#else
#define DHD_WLFC_QMON_COMPLETE(entry)
#endif /* QMONITOR */
/** reordering related */
#if defined(DHD_WLFC_THREAD)
static void
_dhd_wlfc_thread_wakeup(dhd_pub_t *dhdp)
{
#if defined(LINUX)
dhdp->wlfc_thread_go = TRUE;
wake_up_interruptible(&dhdp->wlfc_wqhead);
#endif /* LINUX */
}
#endif /* DHD_WLFC_THREAD */
static uint16
_dhd_wlfc_adjusted_seq(void* p, uint8 current_seq)
{
uint16 seq;
if (!p) {
return 0xffff;
}
seq = WL_TXSTATUS_GET_FREERUNCTR(DHD_PKTTAG_H2DTAG(PKTTAG(p)));
if (seq < current_seq) {
/* wrap around */
seq += 256;
}
return seq;
}
/**
* Enqueue a caller supplied packet on a caller supplied precedence queue, optionally reorder
* suppressed packets.
* @param[in] pq caller supplied packet queue to enqueue the packet on
* @param[in] prec precedence of the to-be-queued packet
* @param[in] p transmit packet to enqueue
* @param[in] qHead if TRUE, enqueue to head instead of tail. Used to maintain d11 seq order.
* @param[in] current_seq
* @param[in] reOrder reOrder on odd precedence (=suppress queue)
*/
static void
_dhd_wlfc_prec_enque(struct pktq *pq, int prec, void* p, bool qHead,
uint8 current_seq, bool reOrder)
{
struct pktq_prec *q;
uint16 seq, seq2;
void *p2, *p2_prev;
if (!p)
return;
ASSERT(prec >= 0 && prec < pq->num_prec);
ASSERT(PKTLINK(p) == NULL); /* queueing chains not allowed */
ASSERT(!pktq_full(pq));
ASSERT(!pktqprec_full(pq, prec));
q = &pq->q[prec];
if (q->head == NULL) {
/* empty queue */
q->head = p;
q->tail = p;
} else {
if (reOrder && (prec & 1)) {
seq = _dhd_wlfc_adjusted_seq(p, current_seq);
p2 = qHead ? q->head : q->tail;
seq2 = _dhd_wlfc_adjusted_seq(p2, current_seq);
if ((qHead &&((seq+1) > seq2)) || (!qHead && ((seq2+1) > seq))) {
/* need reorder */
p2 = q->head;
p2_prev = NULL;
seq2 = _dhd_wlfc_adjusted_seq(p2, current_seq);
while (seq > seq2) {
p2_prev = p2;
p2 = PKTLINK(p2);
if (!p2) {
break;
}
seq2 = _dhd_wlfc_adjusted_seq(p2, current_seq);
}
if (p2_prev == NULL) {
/* insert head */
PKTSETLINK(p, q->head);
q->head = p;
} else if (p2 == NULL) {
/* insert tail */
PKTSETLINK(p2_prev, p);
q->tail = p;
} else {
/* insert after p2_prev */
PKTSETLINK(p, PKTLINK(p2_prev));
PKTSETLINK(p2_prev, p);
}
goto exit;
}
}
if (qHead) {
PKTSETLINK(p, q->head);
q->head = p;
} else {
PKTSETLINK(q->tail, p);
q->tail = p;
}
}
exit:
q->n_pkts++;
pq->n_pkts_tot++;
if (pq->hi_prec < prec)
pq->hi_prec = (uint8)prec;
} /* _dhd_wlfc_prec_enque */
/**
* Create a place to store all packet pointers submitted to the firmware until a status comes back,
* suppress or otherwise.
*
* hang-er: noun, a contrivance on which things are hung, as a hook.
*/
/** @deprecated soon */
static void*
_dhd_wlfc_hanger_create(dhd_pub_t *dhd, int max_items)
{
int i;
wlfc_hanger_t* hanger;
/* allow only up to a specific size for now */
ASSERT(max_items == WLFC_HANGER_MAXITEMS);
if ((hanger = (wlfc_hanger_t*)DHD_OS_PREALLOC(dhd, DHD_PREALLOC_DHD_WLFC_HANGER,
WLFC_HANGER_SIZE(max_items))) == NULL) {
return NULL;
}
memset(hanger, 0, WLFC_HANGER_SIZE(max_items));
hanger->max_items = max_items;
for (i = 0; i < hanger->max_items; i++) {
hanger->items[i].state = WLFC_HANGER_ITEM_STATE_FREE;
}
return hanger;
}
/** @deprecated soon */
static int
_dhd_wlfc_hanger_delete(dhd_pub_t *dhd, void* hanger)
{
wlfc_hanger_t* h = (wlfc_hanger_t*)hanger;
if (h) {
DHD_OS_PREFREE(dhd, h, WLFC_HANGER_SIZE(h->max_items));
return BCME_OK;
}
return BCME_BADARG;
}
/** @deprecated soon */
static uint16
_dhd_wlfc_hanger_get_free_slot(void* hanger)
{
uint32 i;
wlfc_hanger_t* h = (wlfc_hanger_t*)hanger;
if (h) {
i = h->slot_pos + 1;
if (i == h->max_items) {
i = 0;
}
while (i != h->slot_pos) {
if (h->items[i].state == WLFC_HANGER_ITEM_STATE_FREE) {
h->slot_pos = i;
return (uint16)i;
}
i++;
if (i == h->max_items)
i = 0;
}
h->failed_slotfind++;
}
return WLFC_HANGER_MAXITEMS;
}
/** @deprecated soon */
static int
_dhd_wlfc_hanger_get_genbit(void* hanger, void* pkt, uint32 slot_id, int* gen)
{
int rc = BCME_OK;
wlfc_hanger_t* h = (wlfc_hanger_t*)hanger;
*gen = 0xff;
/* this packet was not pushed at the time it went to the firmware */
if (slot_id == WLFC_HANGER_MAXITEMS)
return BCME_NOTFOUND;
if (h) {
if (h->items[slot_id].state != WLFC_HANGER_ITEM_STATE_FREE) {
*gen = h->items[slot_id].gen;
}
else {
DHD_ERROR(("Error: %s():%d item not used\n",
__FUNCTION__, __LINE__));
rc = BCME_NOTFOUND;
}
} else {
rc = BCME_BADARG;
}
return rc;
}
/** @deprecated soon */
static int
_dhd_wlfc_hanger_pushpkt(void* hanger, void* pkt, uint32 slot_id)
{
int rc = BCME_OK;
wlfc_hanger_t* h = (wlfc_hanger_t*)hanger;
if (h && (slot_id < WLFC_HANGER_MAXITEMS)) {
if (h->items[slot_id].state == WLFC_HANGER_ITEM_STATE_FREE) {
h->items[slot_id].state = WLFC_HANGER_ITEM_STATE_INUSE;
h->items[slot_id].pkt = pkt;
h->items[slot_id].pkt_state = 0;
h->items[slot_id].pkt_txstatus = 0;
h->pushed++;
} else {
h->failed_to_push++;
rc = BCME_NOTFOUND;
}
} else {
rc = BCME_BADARG;
}
return rc;
}
/** @deprecated soon */
static int
_dhd_wlfc_hanger_poppkt(void* hanger, uint32 slot_id, void** pktout, bool remove_from_hanger)
{
int rc = BCME_OK;
wlfc_hanger_t* h = (wlfc_hanger_t*)hanger;
*pktout = NULL;
/* this packet was not pushed at the time it went to the firmware */
if (slot_id == WLFC_HANGER_MAXITEMS)
return BCME_NOTFOUND;
if (h) {
if (h->items[slot_id].state != WLFC_HANGER_ITEM_STATE_FREE) {
*pktout = h->items[slot_id].pkt;
if (remove_from_hanger) {
h->items[slot_id].state =
WLFC_HANGER_ITEM_STATE_FREE;
h->items[slot_id].pkt = NULL;
h->items[slot_id].gen = 0xff;
h->items[slot_id].identifier = 0;
h->popped++;
}
} else {
h->failed_to_pop++;
rc = BCME_NOTFOUND;
}
} else {
rc = BCME_BADARG;
}
return rc;
}
/** @deprecated soon */
static int
_dhd_wlfc_hanger_mark_suppressed(void* hanger, uint32 slot_id, uint8 gen)
{
int rc = BCME_OK;
wlfc_hanger_t* h = (wlfc_hanger_t*)hanger;
/* this packet was not pushed at the time it went to the firmware */
if (slot_id == WLFC_HANGER_MAXITEMS)
return BCME_NOTFOUND;
if (h) {
h->items[slot_id].gen = gen;
if (h->items[slot_id].state == WLFC_HANGER_ITEM_STATE_INUSE) {
h->items[slot_id].state = WLFC_HANGER_ITEM_STATE_INUSE_SUPPRESSED;
} else {
rc = BCME_BADARG;
}
} else {
rc = BCME_BADARG;
}
return rc;
}
/** remove reference of specific packet in hanger */
/** @deprecated soon */
static bool
_dhd_wlfc_hanger_remove_reference(wlfc_hanger_t* h, void* pkt)
{
int i;
if (!h || !pkt) {
return FALSE;
}
i = WL_TXSTATUS_GET_HSLOT(DHD_PKTTAG_H2DTAG(PKTTAG(pkt)));
if ((i < h->max_items) && (pkt == h->items[i].pkt)) {
if (h->items[i].state == WLFC_HANGER_ITEM_STATE_INUSE_SUPPRESSED) {
h->items[i].state = WLFC_HANGER_ITEM_STATE_FREE;
h->items[i].pkt = NULL;
h->items[i].gen = 0xff;
h->items[i].identifier = 0;
return TRUE;
} else {
DHD_ERROR(("Error: %s():%d item not suppressed\n",
__FUNCTION__, __LINE__));
}
}
return FALSE;
}
/** afq = At Firmware Queue, queue containing packets pending in the dongle */
static int
_dhd_wlfc_enque_afq(athost_wl_status_info_t* ctx, void *p)
{
wlfc_mac_descriptor_t* entry;
uint16 entry_idx = WL_TXSTATUS_GET_HSLOT(DHD_PKTTAG_H2DTAG(PKTTAG(p)));
uint8 prec = DHD_PKTTAG_FIFO(PKTTAG(p));
if (entry_idx < WLFC_MAC_DESC_TABLE_SIZE)
entry = &ctx->destination_entries.nodes[entry_idx];
else if (entry_idx < (WLFC_MAC_DESC_TABLE_SIZE + WLFC_MAX_IFNUM))
entry = &ctx->destination_entries.interfaces[entry_idx - WLFC_MAC_DESC_TABLE_SIZE];
else
entry = &ctx->destination_entries.other;
pktq_penq(&entry->afq, prec, p);
return BCME_OK;
}
/** afq = At Firmware Queue, queue containing packets pending in the dongle */
static int
_dhd_wlfc_deque_afq(athost_wl_status_info_t* ctx, uint16 hslot, uint8 hcnt, uint8 prec,
void **pktout)
{
wlfc_mac_descriptor_t *entry;
struct pktq *pq;
struct pktq_prec *q;
void *p, *b;
if (!ctx) {
DHD_ERROR(("%s: ctx(%p), pktout(%p)\n", __FUNCTION__, ctx, pktout));
return BCME_BADARG;
}
if (pktout) {
*pktout = NULL;
}
ASSERT(hslot < (WLFC_MAC_DESC_TABLE_SIZE + WLFC_MAX_IFNUM + 1));
if (hslot < WLFC_MAC_DESC_TABLE_SIZE)
entry = &ctx->destination_entries.nodes[hslot];
else if (hslot < (WLFC_MAC_DESC_TABLE_SIZE + WLFC_MAX_IFNUM))
entry = &ctx->destination_entries.interfaces[hslot - WLFC_MAC_DESC_TABLE_SIZE];
else
entry = &ctx->destination_entries.other;
pq = &entry->afq;
ASSERT(prec < pq->num_prec);
q = &pq->q[prec];
b = NULL;
p = q->head;
while (p && (hcnt != WL_TXSTATUS_GET_FREERUNCTR(DHD_PKTTAG_H2DTAG(PKTTAG(p)))))
{
b = p;
p = PKTLINK(p);
}
if (p == NULL) {
/* none is matched */
if (b) {
DHD_ERROR(("%s: can't find matching seq(%d)\n", __FUNCTION__, hcnt));
} else {
DHD_ERROR(("%s: queue is empty\n", __FUNCTION__));
}
return BCME_ERROR;
}
bcm_pkt_validate_chk(p, "_dhd_wlfc_deque_afq");
if (!b) {
/* head packet is matched */
if ((q->head = PKTLINK(p)) == NULL) {
q->tail = NULL;
}
} else {
/* middle packet is matched */
DHD_INFO(("%s: out of order, seq(%d), head_seq(%d)\n", __FUNCTION__, hcnt,
WL_TXSTATUS_GET_FREERUNCTR(DHD_PKTTAG_H2DTAG(PKTTAG(q->head)))));
ctx->stats.ooo_pkts[prec]++;
PKTSETLINK(b, PKTLINK(p));
if (PKTLINK(p) == NULL) {
q->tail = b;
}
}
q->n_pkts--;
pq->n_pkts_tot--;
#ifdef WL_TXQ_STALL
q->dequeue_count++;
#endif
PKTSETLINK(p, NULL);
if (pktout) {
*pktout = p;
}
return BCME_OK;
} /* _dhd_wlfc_deque_afq */
/**
* Flow control information piggy backs on packets, in the form of one or more TLVs. This function
* pushes one or more TLVs onto a packet that is going to be sent towards the dongle.
*
* @param[in] ctx
* @param[in/out] packet
* @param[in] tim_signal TRUE if parameter 'tim_bmp' is valid
* @param[in] tim_bmp
* @param[in] mac_handle
* @param[in] htodtag
* @param[in] htodseq d11 seqno for seqno reuse, only used if 'seq reuse' was agreed upon
* earlier between host and firmware.
* @param[in] skip_wlfc_hdr
*/
static int
_dhd_wlfc_pushheader(athost_wl_status_info_t* ctx, void** packet, bool tim_signal,
uint8 tim_bmp, uint8 mac_handle, uint32 htodtag, uint16 htodseq, bool skip_wlfc_hdr)
{
uint32 wl_pktinfo = 0;
uint8* wlh;
uint8 dataOffset = 0;
uint8 fillers;
uint8 tim_signal_len = 0;
dhd_pub_t *dhdp = (dhd_pub_t *)ctx->dhdp;
struct bdc_header *h;
void *p = *packet;
if (skip_wlfc_hdr)
goto push_bdc_hdr;
if (tim_signal) {
tim_signal_len = TLV_HDR_LEN + WLFC_CTL_VALUE_LEN_PENDING_TRAFFIC_BMP;
}
/* +2 is for Type[1] and Len[1] in TLV, plus TIM signal */
dataOffset = WLFC_CTL_VALUE_LEN_PKTTAG + TLV_HDR_LEN + tim_signal_len;
if (WLFC_GET_REUSESEQ(dhdp->wlfc_mode)) {
dataOffset += WLFC_CTL_VALUE_LEN_SEQ;
}
fillers = ROUNDUP(dataOffset, 4) - dataOffset;
dataOffset += fillers;
PKTPUSH(ctx->osh, p, dataOffset);
wlh = (uint8*) PKTDATA(ctx->osh, p);
wl_pktinfo = htol32(htodtag);
wlh[TLV_TAG_OFF] = WLFC_CTL_TYPE_PKTTAG;
wlh[TLV_LEN_OFF] = WLFC_CTL_VALUE_LEN_PKTTAG;
memcpy(&wlh[TLV_HDR_LEN] /* dst */, &wl_pktinfo, sizeof(uint32));
if (WLFC_GET_REUSESEQ(dhdp->wlfc_mode)) {
uint16 wl_seqinfo = htol16(htodseq);
wlh[TLV_LEN_OFF] += WLFC_CTL_VALUE_LEN_SEQ;
memcpy(&wlh[TLV_HDR_LEN + WLFC_CTL_VALUE_LEN_PKTTAG], &wl_seqinfo,
WLFC_CTL_VALUE_LEN_SEQ);
}
if (tim_signal_len) {
wlh[dataOffset - fillers - tim_signal_len ] =
WLFC_CTL_TYPE_PENDING_TRAFFIC_BMP;
wlh[dataOffset - fillers - tim_signal_len + 1] =
WLFC_CTL_VALUE_LEN_PENDING_TRAFFIC_BMP;
wlh[dataOffset - fillers - tim_signal_len + 2] = mac_handle;
wlh[dataOffset - fillers - tim_signal_len + 3] = tim_bmp;
}
if (fillers)
memset(&wlh[dataOffset - fillers], WLFC_CTL_TYPE_FILLER, fillers);
push_bdc_hdr:
PKTPUSH(ctx->osh, p, BDC_HEADER_LEN);
h = (struct bdc_header *)PKTDATA(ctx->osh, p);
h->flags = (BDC_PROTO_VER << BDC_FLAG_VER_SHIFT);
if (PKTSUMNEEDED(p))
h->flags |= BDC_FLAG_SUM_NEEDED;
#ifdef EXT_STA
/* save pkt encryption exemption info for dongle */
h->flags &= ~BDC_FLAG_EXEMPT;
h->flags |= (DHD_PKTTAG_EXEMPT(PKTTAG(p)) & BDC_FLAG_EXEMPT);
#endif /* EXT_STA */
h->priority = (PKTPRIO(p) & BDC_PRIORITY_MASK);
h->flags2 = 0;
h->dataOffset = dataOffset >> 2;
BDC_SET_IF_IDX(h, DHD_PKTTAG_IF(PKTTAG(p)));
*packet = p;
return BCME_OK;
} /* _dhd_wlfc_pushheader */
/**
* Removes (PULLs) flow control related headers from the caller supplied packet, is invoked eg
* when a packet is about to be freed.
*/
static int
_dhd_wlfc_pullheader(athost_wl_status_info_t* ctx, void* pktbuf)
{
struct bdc_header *h;
if (PKTLEN(ctx->osh, pktbuf) < BDC_HEADER_LEN) {
DHD_ERROR(("%s: rx data too short (%d < %d)\n", __FUNCTION__,
PKTLEN(ctx->osh, pktbuf), BDC_HEADER_LEN));
return BCME_ERROR;
}
h = (struct bdc_header *)PKTDATA(ctx->osh, pktbuf);
/* pull BDC header */
PKTPULL(ctx->osh, pktbuf, BDC_HEADER_LEN);
if (PKTLEN(ctx->osh, pktbuf) < (uint)(h->dataOffset << 2)) {
DHD_ERROR(("%s: rx data too short (%d < %d)\n", __FUNCTION__,
PKTLEN(ctx->osh, pktbuf), (h->dataOffset << 2)));
return BCME_ERROR;
}
/* pull wl-header */
PKTPULL(ctx->osh, pktbuf, (h->dataOffset << 2));
return BCME_OK;
}
/**
* @param[in/out] p packet
*/
static wlfc_mac_descriptor_t*
_dhd_wlfc_find_table_entry(athost_wl_status_info_t* ctx, void* p)
{
int i;
wlfc_mac_descriptor_t* table = ctx->destination_entries.nodes;
uint8 ifid = DHD_PKTTAG_IF(PKTTAG(p));
uint8* dstn = DHD_PKTTAG_DSTN(PKTTAG(p));
wlfc_mac_descriptor_t* entry = DHD_PKTTAG_ENTRY(PKTTAG(p));
int iftype = ctx->destination_entries.interfaces[ifid].iftype;
/* saved one exists, return it */
if (entry)
return entry;
/* Multicast destination, STA and P2P clients get the interface entry.
* STA/GC gets the Mac Entry for TDLS destinations, TDLS destinations
* have their own entry.
*/
if ((iftype == WLC_E_IF_ROLE_STA || ETHER_ISMULTI(dstn) ||
iftype == WLC_E_IF_ROLE_P2P_CLIENT) &&
(ctx->destination_entries.interfaces[ifid].occupied)) {
entry = &ctx->destination_entries.interfaces[ifid];
}
if (entry && ETHER_ISMULTI(dstn)) {
DHD_PKTTAG_SET_ENTRY(PKTTAG(p), entry);
return entry;
}
for (i = 0; i < WLFC_MAC_DESC_TABLE_SIZE; i++) {
if (table[i].occupied) {
if (table[i].interface_id == ifid) {
if (!memcmp(table[i].ea, dstn, ETHER_ADDR_LEN)) {
entry = &table[i];
break;
}
}
}
}
if (entry == NULL)
entry = &ctx->destination_entries.other;
DHD_PKTTAG_SET_ENTRY(PKTTAG(p), entry);
return entry;
} /* _dhd_wlfc_find_table_entry */
/**
* In case a packet must be dropped (because eg the queues are full), various tallies have to be
* be updated. Called from several other functions.
* @param[in] dhdp pointer to public DHD structure
* @param[in] prec precedence of the packet
* @param[in] p the packet to be dropped
* @param[in] bPktInQ TRUE if packet is part of a queue
*/
static int
_dhd_wlfc_prec_drop(dhd_pub_t *dhdp, int prec, void* p, bool bPktInQ)
{
athost_wl_status_info_t* ctx;
void *pout = NULL;
ASSERT(dhdp && p);
if (prec < 0 || prec >= WLFC_PSQ_PREC_COUNT) {
ASSERT(0);
return BCME_BADARG;
}
ctx = (athost_wl_status_info_t*)dhdp->wlfc_state;
if (!WLFC_GET_AFQ(dhdp->wlfc_mode) && (prec & 1)) {
/* suppressed queue, need pop from hanger */
_dhd_wlfc_hanger_poppkt(ctx->hanger, WL_TXSTATUS_GET_HSLOT(DHD_PKTTAG_H2DTAG
(PKTTAG(p))), &pout, TRUE);
ASSERT(p == pout);
}
if (!(prec & 1)) {
#ifdef DHDTCPACK_SUPPRESS
/* pkt in delayed q, so fake push BDC header for
* dhd_tcpack_check_xmit() and dhd_txcomplete().
*/
_dhd_wlfc_pushheader(ctx, &p, FALSE, 0, 0, 0, 0, TRUE);
/* This packet is about to be freed, so remove it from tcp_ack_info_tbl
* This must be one of...
* 1. A pkt already in delayQ is evicted by another pkt with higher precedence
* in _dhd_wlfc_prec_enq_with_drop()
* 2. A pkt could not be enqueued to delayQ because it is full,
* in _dhd_wlfc_enque_delayq().
* 3. A pkt could not be enqueued to delayQ because it is full,
* in _dhd_wlfc_rollback_packet_toq().
*/
if (dhd_tcpack_check_xmit(dhdp, p) == BCME_ERROR) {
DHD_ERROR(("%s %d: tcpack_suppress ERROR!!!"
" Stop using it\n",
__FUNCTION__, __LINE__));
dhd_tcpack_suppress_set(dhdp, TCPACK_SUP_OFF);
}
#endif /* DHDTCPACK_SUPPRESS */
}
if (bPktInQ) {
ctx->pkt_cnt_in_q[DHD_PKTTAG_IF(PKTTAG(p))][prec>>1]--;
ctx->pkt_cnt_per_ac[prec>>1]--;
ctx->pkt_cnt_in_psq--;
}
ctx->pkt_cnt_in_drv[DHD_PKTTAG_IF(PKTTAG(p))][DHD_PKTTAG_FIFO(PKTTAG(p))]--;
ctx->stats.pktout++;
ctx->stats.drop_pkts[prec]++;
dhd_txcomplete(dhdp, p, FALSE);
PKTFREE(ctx->osh, p, TRUE);
return 0;
} /* _dhd_wlfc_prec_drop */
/**
* Called when eg the host handed a new packet over to the driver, or when the dongle reported
* that a packet could currently not be transmitted (=suppressed). This function enqueues a transmit
* packet in the host driver to be (re)transmitted at a later opportunity.
* @param[in] dhdp pointer to public DHD structure
* @param[in] qHead When TRUE, queue packet at head instead of tail, to preserve d11 sequence
*/
static bool
_dhd_wlfc_prec_enq_with_drop(dhd_pub_t *dhdp, struct pktq *pq, void *pkt, int prec, bool qHead,
uint8 current_seq)
{
void *p = NULL;
int eprec = -1; /* precedence to evict from */
athost_wl_status_info_t* ctx;
ASSERT(dhdp && pq && pkt);
ASSERT(prec >= 0 && prec < pq->num_prec);
ctx = (athost_wl_status_info_t*)dhdp->wlfc_state;
/* Fast case, precedence queue is not full and we are also not
* exceeding total queue length
*/
if (!pktqprec_full(pq, prec) && !pktq_full(pq)) {
goto exit;
}
/* Determine precedence from which to evict packet, if any */
if (pktqprec_full(pq, prec)) {
eprec = prec;
} else if (pktq_full(pq)) {
p = pktq_peek_tail(pq, &eprec);
if (!p) {
DHD_ERROR(("Error: %s():%d\n", __FUNCTION__, __LINE__));
return FALSE;
}
if ((eprec > prec) || (eprec < 0)) {
if (!pktqprec_empty(pq, prec)) {
eprec = prec;
} else {
return FALSE;
}
}
}
/* Evict if needed */
if (eprec >= 0) {
/* Detect queueing to unconfigured precedence */
ASSERT(!pktqprec_empty(pq, eprec));
/* Evict all fragmented frames */
dhd_prec_drop_pkts(dhdp, pq, eprec, _dhd_wlfc_prec_drop);
}
exit:
/* Enqueue */
_dhd_wlfc_prec_enque(pq, prec, pkt, qHead, current_seq,
WLFC_GET_REORDERSUPP(dhdp->wlfc_mode));
ctx->pkt_cnt_in_q[DHD_PKTTAG_IF(PKTTAG(pkt))][prec>>1]++;
ctx->pkt_cnt_per_ac[prec>>1]++;
ctx->pkt_cnt_in_psq++;
return TRUE;
} /* _dhd_wlfc_prec_enq_with_drop */
/**
* Called during eg the 'committing' of a transmit packet from the OS layer to a lower layer, in
* the event that this 'commit' failed.
*/
static int
_dhd_wlfc_rollback_packet_toq(athost_wl_status_info_t* ctx,
void* p, ewlfc_packet_state_t pkt_type, uint32 hslot)
{
/*
* put the packet back to the head of queue
* - suppressed packet goes back to suppress sub-queue
* - pull out the header, if new or delayed packet
*
* Note: hslot is used only when header removal is done.
*/
wlfc_mac_descriptor_t* entry;
int rc = BCME_OK;
int prec, fifo_id;
entry = _dhd_wlfc_find_table_entry(ctx, p);
prec = DHD_PKTTAG_FIFO(PKTTAG(p));
fifo_id = prec << 1;
if (pkt_type == eWLFC_PKTTYPE_SUPPRESSED)
fifo_id += 1;
if (entry != NULL) {
/*
if this packet did not count against FIFO credit, it must have
taken a requested_credit from the firmware (for pspoll etc.)
*/
if ((prec != AC_COUNT) && !DHD_PKTTAG_CREDITCHECK(PKTTAG(p)))
entry->requested_credit++;
if (pkt_type == eWLFC_PKTTYPE_DELAYED) {
/* decrement sequence count */
WLFC_DECR_SEQCOUNT(entry, prec);
/* remove header first */
rc = _dhd_wlfc_pullheader(ctx, p);
if (rc != BCME_OK) {
DHD_ERROR(("Error: %s():%d\n", __FUNCTION__, __LINE__));
goto exit;
}
}
if (_dhd_wlfc_prec_enq_with_drop(ctx->dhdp, &entry->psq, p, fifo_id, TRUE,
WLFC_SEQCOUNT(entry, fifo_id>>1))
== FALSE) {
/* enque failed */
DHD_ERROR(("Error: %s():%d, fifo_id(%d)\n",
__FUNCTION__, __LINE__, fifo_id));
rc = BCME_ERROR;
}
} else {
DHD_ERROR(("Error: %s():%d\n", __FUNCTION__, __LINE__));
rc = BCME_ERROR;
}
exit:
if (rc != BCME_OK) {
ctx->stats.rollback_failed++;
_dhd_wlfc_prec_drop(ctx->dhdp, fifo_id, p, FALSE);
} else {
ctx->stats.rollback++;
}
return rc;
} /* _dhd_wlfc_rollback_packet_toq */
/** Returns TRUE if host OS -> DHD flow control is allowed on the caller supplied interface */
static bool
_dhd_wlfc_allow_fc(athost_wl_status_info_t* ctx, uint8 ifid)
{
int prec, ac_traffic = WLFC_NO_TRAFFIC;
for (prec = 0; prec < AC_COUNT; prec++) {
if (ctx->pkt_cnt_in_drv[ifid][prec] > 0) {
if (ac_traffic == WLFC_NO_TRAFFIC)
ac_traffic = prec + 1;
else if (ac_traffic != (prec + 1))
ac_traffic = WLFC_MULTI_TRAFFIC;
}
}
if (ac_traffic >= 1 && ac_traffic <= AC_COUNT) {
/* single AC (BE/BK/VI/VO) in queue */
if (ctx->allow_fc) {
return TRUE;
} else {
uint32 delta;
uint32 curr_t = OSL_SYSUPTIME();
if (ctx->fc_defer_timestamp == 0) {
/* first single ac scenario */
ctx->fc_defer_timestamp = curr_t;
return FALSE;
}
/* single AC duration, this handles wrap around, e.g. 1 - ~0 = 2. */
delta = curr_t - ctx->fc_defer_timestamp;
if (delta >= WLFC_FC_DEFER_PERIOD_MS) {
ctx->allow_fc = TRUE;
}
}
} else {
/* multiple ACs or BCMC in queue */
ctx->allow_fc = FALSE;
ctx->fc_defer_timestamp = 0;
}
return ctx->allow_fc;
} /* _dhd_wlfc_allow_fc */
/**
* Starts or stops the flow of transmit packets from the host OS towards the DHD, depending on
* low/high watermarks.
*/
static void
_dhd_wlfc_flow_control_check(athost_wl_status_info_t* ctx, struct pktq* pq, uint8 if_id)
{
dhd_pub_t *dhdp;
ASSERT(ctx);
dhdp = (dhd_pub_t *)ctx->dhdp;
ASSERT(dhdp);
if (if_id >= WLFC_MAX_IFNUM)
return;
if (dhdp->skip_fc && dhdp->skip_fc((void *)dhdp, if_id))
return;
if ((ctx->hostif_flow_state[if_id] == OFF) && !_dhd_wlfc_allow_fc(ctx, if_id))
return;
if ((pq->n_pkts_tot <= WLFC_FLOWCONTROL_LOWATER) && (ctx->hostif_flow_state[if_id] == ON)) {
/* start traffic */
ctx->hostif_flow_state[if_id] = OFF;
/*
WLFC_DBGMESG(("qlen:%02d, if:%02d, ->OFF, start traffic %s()\n",
pq->n_pkts_tot, if_id, __FUNCTION__));
*/
WLFC_DBGMESG(("F"));
dhd_txflowcontrol(dhdp, if_id, OFF);
ctx->toggle_host_if = 0;
}
if (pq->n_pkts_tot >= WLFC_FLOWCONTROL_HIWATER && ctx->hostif_flow_state[if_id] == OFF) {
/* stop traffic */
ctx->hostif_flow_state[if_id] = ON;
/*
WLFC_DBGMESG(("qlen:%02d, if:%02d, ->ON, stop traffic %s()\n",
pq->n_pkts_tot, if_id, __FUNCTION__));
*/
WLFC_DBGMESG(("N"));
dhd_txflowcontrol(dhdp, if_id, ON);
ctx->host_ifidx = if_id;
ctx->toggle_host_if = 1;
}
return;
} /* _dhd_wlfc_flow_control_check */
/** XXX: Warning: this function directly accesses bus-transmit function */
static int
_dhd_wlfc_send_signalonly_packet(athost_wl_status_info_t* ctx, wlfc_mac_descriptor_t* entry,
uint8 ta_bmp)
{
int rc = BCME_OK;
void* p = NULL;
int dummylen = ((dhd_pub_t *)ctx->dhdp)->hdrlen+ 16;
dhd_pub_t *dhdp = (dhd_pub_t *)ctx->dhdp;
if (dhdp->proptxstatus_txoff) {
rc = BCME_NORESOURCE;
return rc;
}