-
Notifications
You must be signed in to change notification settings - Fork 9
/
ecrnx_txq.c
executable file
·1504 lines (1320 loc) · 45.4 KB
/
ecrnx_txq.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
/**
******************************************************************************
*
* @file ecrnx_txq.c
*
* Copyright (C) ESWIN 2015-2020
*
******************************************************************************
*/
#include "ecrnx_defs.h"
#include "ecrnx_tx.h"
#include "ipc_host.h"
#include "ecrnx_events.h"
/******************************************************************************
* Utils functions
*****************************************************************************/
const int nx_tid_prio[NX_NB_TID_PER_STA] = {7, 6, 5, 4, 3, 0, 2, 1};
static inline int ecrnx_txq_sta_idx(struct ecrnx_sta *sta, u8 tid)
{
if (is_multicast_sta(sta->sta_idx))
return NX_FIRST_VIF_TXQ_IDX + sta->vif_idx;
else
return (sta->sta_idx * NX_NB_TXQ_PER_STA) + tid;
}
static inline int ecrnx_txq_vif_idx(struct ecrnx_vif *vif, u8 type)
{
return NX_FIRST_VIF_TXQ_IDX + master_vif_idx(vif) + (type * NX_VIRT_DEV_MAX);
}
struct ecrnx_txq *ecrnx_txq_sta_get(struct ecrnx_sta *sta, u8 tid,
struct ecrnx_hw * ecrnx_hw)
{
if (tid >= NX_NB_TXQ_PER_STA)
tid = 0;
return &ecrnx_hw->txq[ecrnx_txq_sta_idx(sta, tid)];
}
struct ecrnx_txq *ecrnx_txq_vif_get(struct ecrnx_vif *vif, u8 type)
{
if (type > NX_UNK_TXQ_TYPE)
type = NX_BCMC_TXQ_TYPE;
return &vif->ecrnx_hw->txq[ecrnx_txq_vif_idx(vif, type)];
}
static inline struct ecrnx_sta *ecrnx_txq_2_sta(struct ecrnx_txq *txq)
{
return txq->sta;
}
/******************************************************************************
* Init/Deinit functions
*****************************************************************************/
/**
* ecrnx_txq_init - Initialize a TX queue
*
* @txq: TX queue to be initialized
* @idx: TX queue index
* @status: TX queue initial status
* @hwq: Associated HW queue
* @ndev: Net device this queue belongs to
* (may be null for non netdev txq)
*
* Each queue is initialized with the credit of @NX_TXQ_INITIAL_CREDITS.
*/
static void ecrnx_txq_init(struct ecrnx_txq *txq, int idx, u8 status,
struct ecrnx_hwq *hwq, int tid,
struct ecrnx_sta *sta, struct net_device *ndev)
{
int i;
txq->idx = idx;
txq->status = status;
txq->credits = NX_TXQ_INITIAL_CREDITS;
txq->pkt_sent = 0;
skb_queue_head_init(&txq->sk_list);
txq->last_retry_skb = NULL;
txq->nb_retry = 0;
txq->hwq = hwq;
txq->sta = sta;
for (i = 0; i < CONFIG_USER_MAX ; i++)
txq->pkt_pushed[i] = 0;
txq->push_limit = 0;
txq->tid = tid;
#ifdef CONFIG_MAC80211_TXQ
txq->nb_ready_mac80211 = 0;
#endif
txq->ps_id = LEGACY_PS_ID;
if (idx < NX_FIRST_VIF_TXQ_IDX) {
int sta_idx = sta->sta_idx;
int tid = idx - (sta_idx * NX_NB_TXQ_PER_STA);
if (tid < NX_NB_TID_PER_STA)
txq->ndev_idx = NX_STA_NDEV_IDX(tid, sta_idx);
else
txq->ndev_idx = NDEV_NO_TXQ;
} else if (idx < NX_FIRST_UNK_TXQ_IDX) {
txq->ndev_idx = NX_BCMC_TXQ_NDEV_IDX;
} else {
txq->ndev_idx = NDEV_NO_TXQ;
}
txq->ndev = ndev;
#ifdef CONFIG_ECRNX_AMSDUS_TX
txq->amsdu = NULL;
txq->amsdu_len = 0;
#endif /* CONFIG_ECRNX_AMSDUS_TX */
}
/**
* ecrnx_txq_flush - Flush all buffers queued for a TXQ
*
* @ecrnx_hw: main driver data
* @txq: txq to flush
*/
void ecrnx_txq_drop_skb(struct ecrnx_txq *txq, struct sk_buff *skb, struct ecrnx_hw *ecrnx_hw, bool retry_packet)
{
struct ecrnx_sw_txhdr *sw_txhdr;
unsigned long queued_time = 0;
skb_unlink(skb, &txq->sk_list);
sw_txhdr = ((struct ecrnx_txhdr *)skb->data)->sw_hdr;
/* hwq->len doesn't count skb to retry */
queued_time = jiffies - sw_txhdr->jiffies;
trace_txq_drop_skb(skb, txq, queued_time);
#ifdef CONFIG_ECRNX_AMSDUS_TX
if (sw_txhdr->desc.host.packet_cnt > 1) {
struct ecrnx_amsdu_txhdr *amsdu_txhdr;
list_for_each_entry(amsdu_txhdr, &sw_txhdr->amsdu.hdrs, list) {
dev_kfree_skb_any(amsdu_txhdr->skb);
}
if (txq->amsdu == sw_txhdr)
txq->amsdu = NULL;
}
#endif
kmem_cache_free(ecrnx_hw->sw_txhdr_cache, sw_txhdr);
if (retry_packet) {
txq->nb_retry--;
if (txq->nb_retry == 0) {
WARN(skb != txq->last_retry_skb,
"last dropped retry buffer is not the expected one");
txq->last_retry_skb = NULL;
}
}
dev_kfree_skb_any(skb);
}
/**
* ecrnx_txq_flush - Flush all buffers queued for a TXQ
*
* @ecrnx_hw: main driver data
* @txq: txq to flush
*/
void ecrnx_txq_flush(struct ecrnx_hw *ecrnx_hw, struct ecrnx_txq *txq)
{
int i, pushed = 0;
while(!skb_queue_empty(&txq->sk_list)) {
ecrnx_txq_drop_skb(txq, skb_peek(&txq->sk_list), ecrnx_hw, txq->nb_retry);
}
for (i = 0; i < CONFIG_USER_MAX; i++) {
pushed += txq->pkt_pushed[i];
}
if (pushed)
dev_warn(ecrnx_hw->dev, "TXQ[%d]: %d skb still pushed to the FW",
txq->idx, pushed);
}
/**
* ecrnx_txq_deinit - De-initialize a TX queue
*
* @ecrnx_hw: Driver main data
* @txq: TX queue to be de-initialized
* Any buffer stuck in a queue will be freed.
*/
static void ecrnx_txq_deinit(struct ecrnx_hw *ecrnx_hw, struct ecrnx_txq *txq)
{
if (txq->idx == TXQ_INACTIVE)
return;
spin_lock_bh(&ecrnx_hw->tx_lock);
ecrnx_txq_del_from_hw_list(txq);
txq->idx = TXQ_INACTIVE;
spin_unlock_bh(&ecrnx_hw->tx_lock);
ecrnx_txq_flush(ecrnx_hw, txq);
}
/**
* ecrnx_txq_vif_init - Initialize all TXQ linked to a vif
*
* @ecrnx_hw: main driver data
* @ecrnx_vif: Pointer on VIF
* @status: Intial txq status
*
* Softmac : 1 VIF TXQ per HWQ
*
* Fullmac : 1 VIF TXQ for BC/MC
* 1 VIF TXQ for MGMT to unknown STA
*/
void ecrnx_txq_vif_init(struct ecrnx_hw *ecrnx_hw, struct ecrnx_vif *ecrnx_vif,
u8 status)
{
struct ecrnx_txq *txq;
int idx;
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_BCMC_TXQ_TYPE);
idx = ecrnx_txq_vif_idx(ecrnx_vif, NX_BCMC_TXQ_TYPE);
ecrnx_txq_init(txq, idx, status, &ecrnx_hw->hwq[ECRNX_HWQ_BE], 0,
&ecrnx_hw->sta_table[ecrnx_vif->ap.bcmc_index], ecrnx_vif->ndev);
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_UNK_TXQ_TYPE);
idx = ecrnx_txq_vif_idx(ecrnx_vif, NX_UNK_TXQ_TYPE);
ecrnx_txq_init(txq, idx, status, &ecrnx_hw->hwq[ECRNX_HWQ_VO], TID_MGT,
NULL, ecrnx_vif->ndev);
}
/**
* ecrnx_txq_vif_deinit - Deinitialize all TXQ linked to a vif
*
* @ecrnx_hw: main driver data
* @ecrnx_vif: Pointer on VIF
*/
void ecrnx_txq_vif_deinit(struct ecrnx_hw * ecrnx_hw, struct ecrnx_vif *ecrnx_vif)
{
struct ecrnx_txq *txq;
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_BCMC_TXQ_TYPE);
ecrnx_txq_deinit(ecrnx_hw, txq);
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_UNK_TXQ_TYPE);
ecrnx_txq_deinit(ecrnx_hw, txq);
}
/**
* ecrnx_txq_sta_init - Initialize TX queues for a STA
*
* @ecrnx_hw: Main driver data
* @ecrnx_sta: STA for which tx queues need to be initialized
* @status: Intial txq status
*
* This function initialize all the TXQ associated to a STA.
* Softmac : 1 TXQ per TID
*
* Fullmac : 1 TXQ per TID (limited to 8)
* 1 TXQ for MGMT
*/
void ecrnx_txq_sta_init(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *ecrnx_sta,
u8 status)
{
struct ecrnx_txq *txq;
int tid, idx;
struct ecrnx_vif *ecrnx_vif = ecrnx_hw->vif_table[ecrnx_sta->vif_idx];
idx = ecrnx_txq_sta_idx(ecrnx_sta, 0);
foreach_sta_txq(ecrnx_sta, txq, tid, ecrnx_hw) {
ecrnx_txq_init(txq, idx, status, &ecrnx_hw->hwq[ecrnx_tid2hwq[tid]], tid,
ecrnx_sta, ecrnx_vif->ndev);
txq->ps_id = ecrnx_sta->uapsd_tids & (1 << tid) ? UAPSD_ID : LEGACY_PS_ID;
idx++;
}
}
/**
* ecrnx_txq_sta_deinit - Deinitialize TX queues for a STA
*
* @ecrnx_hw: Main driver data
* @ecrnx_sta: STA for which tx queues need to be deinitialized
*/
void ecrnx_txq_sta_deinit(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *ecrnx_sta)
{
struct ecrnx_txq *txq;
int tid;
foreach_sta_txq(ecrnx_sta, txq, tid, ecrnx_hw) {
ecrnx_txq_deinit(ecrnx_hw, txq);
}
}
/**
* ecrnx_txq_unk_vif_init - Initialize TXQ for unknown STA linked to a vif
*
* @ecrnx_vif: Pointer on VIF
*/
void ecrnx_txq_unk_vif_init(struct ecrnx_vif *ecrnx_vif)
{
struct ecrnx_hw *ecrnx_hw = ecrnx_vif->ecrnx_hw;
struct ecrnx_txq *txq;
int idx;
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_UNK_TXQ_TYPE);
idx = ecrnx_txq_vif_idx(ecrnx_vif, NX_UNK_TXQ_TYPE);
ecrnx_txq_init(txq, idx, 0, &ecrnx_hw->hwq[ECRNX_HWQ_VO], TID_MGT, NULL, ecrnx_vif->ndev);
}
/**
* ecrnx_txq_tdls_vif_deinit - Deinitialize TXQ for unknown STA linked to a vif
*
* @ecrnx_vif: Pointer on VIF
*/
void ecrnx_txq_unk_vif_deinit(struct ecrnx_vif *ecrnx_vif)
{
struct ecrnx_txq *txq;
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_UNK_TXQ_TYPE);
ecrnx_txq_deinit(ecrnx_vif->ecrnx_hw, txq);
}
/**
* ecrnx_init_unk_txq - Initialize TX queue for the transmission on a offchannel
*
* @vif: Interface for which the queue has to be initialized
*
* NOTE: Offchannel txq is only active for the duration of the ROC
*/
void ecrnx_txq_offchan_init(struct ecrnx_vif *ecrnx_vif)
{
struct ecrnx_hw *ecrnx_hw = ecrnx_vif->ecrnx_hw;
struct ecrnx_txq *txq;
txq = &ecrnx_hw->txq[NX_OFF_CHAN_TXQ_IDX];
ecrnx_txq_init(txq, NX_OFF_CHAN_TXQ_IDX, ECRNX_TXQ_STOP_CHAN,
&ecrnx_hw->hwq[ECRNX_HWQ_VO], TID_MGT, NULL, ecrnx_vif->ndev);
}
/**
* ecrnx_deinit_offchan_txq - Deinitialize TX queue for offchannel
*
* @vif: Interface that manages the STA
*
* This function deintialize txq for one STA.
* Any buffer stuck in a queue will be freed.
*/
void ecrnx_txq_offchan_deinit(struct ecrnx_vif *ecrnx_vif)
{
struct ecrnx_txq *txq;
txq = &ecrnx_vif->ecrnx_hw->txq[NX_OFF_CHAN_TXQ_IDX];
ecrnx_txq_deinit(ecrnx_vif->ecrnx_hw, txq);
}
/**
* ecrnx_txq_tdls_vif_init - Initialize TXQ vif for TDLS
*
* @ecrnx_vif: Pointer on VIF
*/
void ecrnx_txq_tdls_vif_init(struct ecrnx_vif *ecrnx_vif)
{
struct ecrnx_hw *ecrnx_hw = ecrnx_vif->ecrnx_hw;
if (!(ecrnx_hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
return;
ecrnx_txq_unk_vif_init(ecrnx_vif);
}
/**
* ecrnx_txq_tdls_vif_deinit - Deinitialize TXQ vif for TDLS
*
* @ecrnx_vif: Pointer on VIF
*/
void ecrnx_txq_tdls_vif_deinit(struct ecrnx_vif *ecrnx_vif)
{
struct ecrnx_hw *ecrnx_hw = ecrnx_vif->ecrnx_hw;
if (!(ecrnx_hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
return;
ecrnx_txq_unk_vif_deinit(ecrnx_vif);
}
/**
* ecrnx_txq_drop_old_traffic - Drop pkt queued for too long in a TXQ
*
* @txq: TXQ to process
* @ecrnx_hw: Driver main data
* @skb_timeout: Max queue duration, in jiffies, for this queue
* @dropped: Updated to inidicate if at least one skb was dropped
*
* @return Whether there is still pkt queued in this queue.
*/
static bool ecrnx_txq_drop_old_traffic(struct ecrnx_txq *txq, struct ecrnx_hw *ecrnx_hw,
unsigned long skb_timeout, bool *dropped)
{
struct sk_buff *skb, *skb_next;
bool pkt_queued = false;
int retry_packet = txq->nb_retry;
if (txq->idx == TXQ_INACTIVE)
return false;
spin_lock(&ecrnx_hw->tx_lock);
skb_queue_walk_safe(&txq->sk_list, skb, skb_next) {
struct ecrnx_sw_txhdr *sw_txhdr;
if (retry_packet) {
// Don't drop retry packets
retry_packet--;
continue;
}
sw_txhdr = ((struct ecrnx_txhdr *)skb->data)->sw_hdr;
if (!time_after(jiffies, sw_txhdr->jiffies + skb_timeout)) {
pkt_queued = true;
break;
}
*dropped = true;
ecrnx_printk_warn("%s:skb:0x%08x,txq:0x%p, txq_idx:%d, ps_id:%d \n", __func__, skb, txq, txq->idx, txq->ps_id);
ecrnx_txq_drop_skb(txq, skb, ecrnx_hw, false);
if (txq->sta && txq->sta->ps.active) {
txq->sta->ps.pkt_ready[txq->ps_id]--;
if (txq->sta->ps.pkt_ready[txq->ps_id] == 0)
ecrnx_set_traffic_status(ecrnx_hw, txq->sta, false, txq->ps_id);
// drop packet during PS service period
if (txq->sta->ps.sp_cnt[txq->ps_id]) {
txq->sta->ps.sp_cnt[txq->ps_id] --;
if (txq->push_limit)
txq->push_limit--;
if (WARN(((txq->ps_id == UAPSD_ID) &&
(txq->sta->ps.sp_cnt[txq->ps_id] == 0)),
"Drop last packet of UAPSD service period")) {
// TODO: inform FW to end SP
}
}
trace_ps_drop(txq->sta);
}
}
if (skb_queue_empty(&txq->sk_list)) {
ecrnx_txq_del_from_hw_list(txq);
txq->pkt_sent = 0;
}
spin_unlock(&ecrnx_hw->tx_lock);
/* restart netdev queue if number no more queued buffer */
if (unlikely(txq->status & ECRNX_TXQ_NDEV_FLOW_CTRL) &&
skb_queue_empty(&txq->sk_list)) {
txq->status &= ~ECRNX_TXQ_NDEV_FLOW_CTRL;
netif_wake_subqueue(txq->ndev, txq->ndev_idx);
trace_txq_flowctrl_restart(txq);
}
return pkt_queued;
}
/**
* ecrnx_txq_drop_ap_vif_old_traffic - Drop pkt queued for too long in TXQs
* linked to an "AP" vif (AP, MESH, P2P_GO)
*
* @vif: Vif to process
* @return Whether there is still pkt queued in any TXQ.
*/
static bool ecrnx_txq_drop_ap_vif_old_traffic(struct ecrnx_vif *vif)
{
struct ecrnx_sta *sta;
unsigned long timeout = (vif->ap.bcn_interval * HZ * 3) >> 10;
bool pkt_queued = false;
bool pkt_dropped = false;
// Should never be needed but still check VIF queues
ecrnx_txq_drop_old_traffic(ecrnx_txq_vif_get(vif, NX_BCMC_TXQ_TYPE),
vif->ecrnx_hw, ECRNX_TXQ_MAX_QUEUE_JIFFIES, &pkt_dropped);
ecrnx_txq_drop_old_traffic(ecrnx_txq_vif_get(vif, NX_UNK_TXQ_TYPE),
vif->ecrnx_hw, ECRNX_TXQ_MAX_QUEUE_JIFFIES, &pkt_dropped);
list_for_each_entry(sta, &vif->ap.sta_list, list) {
struct ecrnx_txq *txq;
int tid;
foreach_sta_txq(sta, txq, tid, vif->ecrnx_hw) {
pkt_queued |= ecrnx_txq_drop_old_traffic(txq, vif->ecrnx_hw,
timeout * sta->listen_interval,
&pkt_dropped);
}
}
if (pkt_dropped) {
ecrnx_printk_warn("Dropped packet in BCMC/UNK queue. \n");
}
return pkt_queued;
}
/**
* ecrnx_txq_drop_sta_vif_old_traffic - Drop pkt queued for too long in TXQs
* linked to a "STA" vif. In theory this should not be required as there is no
* case where traffic can accumulate in a STA interface.
*
* @vif: Vif to process
* @return Whether there is still pkt queued in any TXQ.
*/
static bool ecrnx_txq_drop_sta_vif_old_traffic(struct ecrnx_vif *vif)
{
struct ecrnx_txq *txq;
bool pkt_queued = false, pkt_dropped = false;
int tid;
if (vif->tdls_status == TDLS_LINK_ACTIVE) {
txq = ecrnx_txq_vif_get(vif, NX_UNK_TXQ_TYPE);
pkt_queued |= ecrnx_txq_drop_old_traffic(txq, vif->ecrnx_hw,
ECRNX_TXQ_MAX_QUEUE_JIFFIES,
&pkt_dropped);
foreach_sta_txq(vif->sta.tdls_sta, txq, tid, vif->ecrnx_hw) {
pkt_queued |= ecrnx_txq_drop_old_traffic(txq, vif->ecrnx_hw,
ECRNX_TXQ_MAX_QUEUE_JIFFIES,
&pkt_dropped);
}
}
if (vif->sta.ap) {
foreach_sta_txq(vif->sta.ap, txq, tid, vif->ecrnx_hw) {
pkt_queued |= ecrnx_txq_drop_old_traffic(txq, vif->ecrnx_hw,
ECRNX_TXQ_MAX_QUEUE_JIFFIES,
&pkt_dropped);
}
}
if (pkt_dropped) {
ecrnx_printk_warn("Dropped packet in STA interface TXQs. \n");
}
return pkt_queued;
}
/**
* ecrnx_txq_cleanup_timer_cb - callack for TXQ cleaup timer
* Used to prevent pkt to accumulate in TXQ. The main use case is for AP
* interface with client in Power Save mode but just in case all TXQs are
* checked.
*
* @t: timer structure
*/
static void ecrnx_txq_cleanup_timer_cb(struct timer_list *t)
{
struct ecrnx_hw *ecrnx_hw = from_timer(ecrnx_hw, t, txq_cleanup);
struct ecrnx_vif *vif;
bool pkt_queue = false;
list_for_each_entry(vif, &ecrnx_hw->vifs, list) {
switch (ECRNX_VIF_TYPE(vif)) {
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_P2P_GO:
case NL80211_IFTYPE_MESH_POINT:
pkt_queue |= ecrnx_txq_drop_ap_vif_old_traffic(vif);
break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
pkt_queue |= ecrnx_txq_drop_sta_vif_old_traffic(vif);
break;
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_MONITOR:
default:
continue;
}
}
if (pkt_queue)
mod_timer(t, jiffies + ECRNX_TXQ_CLEANUP_INTERVAL);
}
/**
* ecrnx_txq_start_cleanup_timer - Start 'cleanup' timer if not started
*
* @ecrnx_hw: Driver main data
*/
void ecrnx_txq_start_cleanup_timer(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta)
{
if (sta && !is_multicast_sta(sta->sta_idx) &&
!timer_pending(&ecrnx_hw->txq_cleanup))
mod_timer(&ecrnx_hw->txq_cleanup, jiffies + ECRNX_TXQ_CLEANUP_INTERVAL);
}
/**
* ecrnx_txq_prepare - Global initialization of txq
*
* @ecrnx_hw: Driver main data
*/
void ecrnx_txq_prepare(struct ecrnx_hw *ecrnx_hw)
{
int i;
for (i = 0; i < NX_NB_TXQ; i++) {
ecrnx_hw->txq[i].idx = TXQ_INACTIVE;
}
timer_setup(&ecrnx_hw->txq_cleanup, ecrnx_txq_cleanup_timer_cb, 0);
}
/******************************************************************************
* Start/Stop functions
*****************************************************************************/
/**
* ecrnx_txq_add_to_hw_list - Add TX queue to a HW queue schedule list.
*
* @txq: TX queue to add
*
* Add the TX queue if not already present in the HW queue list.
* To be called with tx_lock hold
*/
void ecrnx_txq_add_to_hw_list(struct ecrnx_txq *txq)
{
if (!(txq->status & ECRNX_TXQ_IN_HWQ_LIST)) {
trace_txq_add_to_hw(txq);
txq->status |= ECRNX_TXQ_IN_HWQ_LIST;
list_add_tail(&txq->sched_list, &txq->hwq->list);
txq->hwq->need_processing = true;
}
}
/**
* ecrnx_txq_del_from_hw_list - Delete TX queue from a HW queue schedule list.
*
* @txq: TX queue to delete
*
* Remove the TX queue from the HW queue list if present.
* To be called with tx_lock hold
*/
void ecrnx_txq_del_from_hw_list(struct ecrnx_txq *txq)
{
if (txq->status & ECRNX_TXQ_IN_HWQ_LIST) {
trace_txq_del_from_hw(txq);
txq->status &= ~ECRNX_TXQ_IN_HWQ_LIST;
list_del(&txq->sched_list);
}
}
/**
* ecrnx_txq_skb_ready - Check if skb are available for the txq
*
* @txq: Pointer on txq
* @return True if there are buffer ready to be pushed on this txq,
* false otherwise
*/
static inline bool ecrnx_txq_skb_ready(struct ecrnx_txq *txq)
{
#ifdef CONFIG_MAC80211_TXQ
if (txq->nb_ready_mac80211 != NOT_MAC80211_TXQ)
return ((txq->nb_ready_mac80211 > 0) || !skb_queue_empty(&txq->sk_list));
else
#endif
return !skb_queue_empty(&txq->sk_list);
}
/**
* ecrnx_txq_start - Try to Start one TX queue
*
* @txq: TX queue to start
* @reason: reason why the TX queue is started (among ECRNX_TXQ_STOP_xxx)
*
* Re-start the TX queue for one reason.
* If after this the txq is no longer stopped and some buffers are ready,
* the TX queue is also added to HW queue list.
* To be called with tx_lock hold
*/
void ecrnx_txq_start(struct ecrnx_txq *txq, u16 reason)
{
BUG_ON(txq==NULL);
if (txq->idx != TXQ_INACTIVE && (txq->status & reason))
{
trace_txq_start(txq, reason);
txq->status &= ~reason;
if (!ecrnx_txq_is_stopped(txq) && ecrnx_txq_skb_ready(txq))
ecrnx_txq_add_to_hw_list(txq);
}
}
/**
* ecrnx_txq_stop - Stop one TX queue
*
* @txq: TX queue to stop
* @reason: reason why the TX queue is stopped (among ECRNX_TXQ_STOP_xxx)
*
* Stop the TX queue. It will remove the TX queue from HW queue list
* To be called with tx_lock hold
*/
void ecrnx_txq_stop(struct ecrnx_txq *txq, u16 reason)
{
BUG_ON(txq==NULL);
if (txq->idx != TXQ_INACTIVE)
{
trace_txq_stop(txq, reason);
txq->status |= reason;
ecrnx_txq_del_from_hw_list(txq);
}
}
/**
* ecrnx_txq_sta_start - Start all the TX queue linked to a STA
*
* @sta: STA whose TX queues must be re-started
* @reason: Reason why the TX queue are restarted (among ECRNX_TXQ_STOP_xxx)
* @ecrnx_hw: Driver main data
*
* This function will re-start all the TX queues of the STA for the reason
* specified. It can be :
* - ECRNX_TXQ_STOP_STA_PS: the STA is no longer in power save mode
* - ECRNX_TXQ_STOP_VIF_PS: the VIF is in power save mode (p2p absence)
* - ECRNX_TXQ_STOP_CHAN: the STA's VIF is now on the current active channel
*
* Any TX queue with buffer ready and not Stopped for other reasons, will be
* added to the HW queue list
* To be called with tx_lock hold
*/
void ecrnx_txq_sta_start(struct ecrnx_sta *ecrnx_sta, u16 reason,
struct ecrnx_hw *ecrnx_hw)
{
struct ecrnx_txq *txq;
int tid;
trace_txq_sta_start(ecrnx_sta->sta_idx);
ecrnx_printk_tx("%s-%d:ecrnx_txq_stop,reaosn:0x%x,sta:0x%08x,sta_index:0x%08x \n", __func__, __LINE__, reason, ecrnx_sta, ecrnx_sta->sta_idx);
foreach_sta_txq(ecrnx_sta, txq, tid, ecrnx_hw) {
ecrnx_txq_start(txq, reason);
if (txq->idx != TXQ_INACTIVE && !skb_queue_empty(&txq->sk_list))
{
ecrnx_hwq_process(ecrnx_hw, txq->hwq);
}
}
}
/**
* ecrnx_stop_sta_txq - Stop all the TX queue linked to a STA
*
* @sta: STA whose TX queues must be stopped
* @reason: Reason why the TX queue are stopped (among ECRNX_TX_STOP_xxx)
* @ecrnx_hw: Driver main data
*
* This function will stop all the TX queues of the STA for the reason
* specified. It can be :
* - ECRNX_TXQ_STOP_STA_PS: the STA is in power save mode
* - ECRNX_TXQ_STOP_VIF_PS: the VIF is in power save mode (p2p absence)
* - ECRNX_TXQ_STOP_CHAN: the STA's VIF is not on the current active channel
*
* Any TX queue present in a HW queue list will be removed from this list.
* To be called with tx_lock hold
*/
void ecrnx_txq_sta_stop(struct ecrnx_sta *ecrnx_sta, u16 reason,
struct ecrnx_hw *ecrnx_hw)
{
struct ecrnx_txq *txq;
int tid;
if (!ecrnx_sta)
return;
trace_txq_sta_stop(ecrnx_sta->sta_idx);
foreach_sta_txq(ecrnx_sta, txq, tid, ecrnx_hw) {
ecrnx_printk_tx("%s-%d:stop_reaosn:0x%x,sta:0x%08x,sta_index:0x%08x ,txq:0x%p,tid:%d \n", __func__, __LINE__, reason, ecrnx_sta, ecrnx_sta->sta_idx, txq, tid);
ecrnx_txq_stop(txq, reason);
}
}
void ecrnx_txq_tdls_sta_start(struct ecrnx_vif *ecrnx_vif, u16 reason,
struct ecrnx_hw *ecrnx_hw)
{
trace_txq_vif_start(ecrnx_vif->vif_index);
spin_lock_bh(&ecrnx_hw->tx_lock);
if (ecrnx_vif->sta.tdls_sta)
ecrnx_txq_sta_start(ecrnx_vif->sta.tdls_sta, reason, ecrnx_hw);
spin_unlock_bh(&ecrnx_hw->tx_lock);
}
void ecrnx_txq_tdls_sta_stop(struct ecrnx_vif *ecrnx_vif, u16 reason,
struct ecrnx_hw *ecrnx_hw)
{
trace_txq_vif_stop(ecrnx_vif->vif_index);
spin_lock_bh(&ecrnx_hw->tx_lock);
if (ecrnx_vif->sta.tdls_sta)
ecrnx_txq_sta_stop(ecrnx_vif->sta.tdls_sta, reason, ecrnx_hw);
spin_unlock_bh(&ecrnx_hw->tx_lock);
}
static inline
void ecrnx_txq_vif_for_each_sta(struct ecrnx_hw *ecrnx_hw, struct ecrnx_vif *ecrnx_vif,
void (*f)(struct ecrnx_sta *, u16, struct ecrnx_hw *),
u16 reason)
{
switch (ECRNX_VIF_TYPE(ecrnx_vif)) {
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
{
if (ecrnx_vif->tdls_status == TDLS_LINK_ACTIVE)
f(ecrnx_vif->sta.tdls_sta, reason, ecrnx_hw);
#ifdef CONFIG_ECRNX_P2P
if (!(ecrnx_vif->sta.ap == NULL))
#else
if (!WARN_ON(ecrnx_vif->sta.ap == NULL))
#endif
f(ecrnx_vif->sta.ap, reason, ecrnx_hw);
break;
}
case NL80211_IFTYPE_AP_VLAN:
{
ecrnx_vif = ecrnx_vif->ap_vlan.master;
struct ecrnx_sta *sta;
list_for_each_entry(sta, &ecrnx_vif->ap.sta_list, list) {
f(sta, reason, ecrnx_hw);
}
break;
}
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_MESH_POINT:
case NL80211_IFTYPE_P2P_GO:
{
struct ecrnx_sta *sta;
list_for_each_entry(sta, &ecrnx_vif->ap.sta_list, list) {
f(sta, reason, ecrnx_hw);
}
break;
}
default:
//BUG();
ecrnx_printk_err("%s %d\n", __func__,ECRNX_VIF_TYPE(ecrnx_vif));
break;
}
}
/**
* ecrnx_txq_vif_start - START TX queues of all STA associated to the vif
* and vif's TXQ
*
* @vif: Interface to start
* @reason: Start reason (ECRNX_TXQ_STOP_CHAN or ECRNX_TXQ_STOP_VIF_PS)
* @ecrnx_hw: Driver main data
*
* Iterate over all the STA associated to the vif and re-start them for the
* reason @reason
* Take tx_lock
*/
void ecrnx_txq_vif_start(struct ecrnx_vif *ecrnx_vif, u16 reason,
struct ecrnx_hw *ecrnx_hw)
{
struct ecrnx_txq *txq;
trace_txq_vif_start(ecrnx_vif->vif_index);
spin_lock_bh(&ecrnx_hw->tx_lock);
//Reject if monitor interface
if (ecrnx_vif->wdev.iftype == NL80211_IFTYPE_MONITOR)
goto end;
if (ecrnx_vif->roc_tdls && ecrnx_vif->sta.tdls_sta && ecrnx_vif->sta.tdls_sta->tdls.chsw_en) {
ecrnx_txq_sta_start(ecrnx_vif->sta.tdls_sta, reason, ecrnx_hw);
}
if (!ecrnx_vif->roc_tdls) {
ecrnx_txq_vif_for_each_sta(ecrnx_hw, ecrnx_vif, ecrnx_txq_sta_start, reason);
}
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_BCMC_TXQ_TYPE);
ecrnx_txq_start(txq, reason);
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_UNK_TXQ_TYPE);
ecrnx_txq_start(txq, reason);
end:
spin_unlock_bh(&ecrnx_hw->tx_lock);
}
/**
* ecrnx_txq_vif_stop - STOP TX queues of all STA associated to the vif
*
* @vif: Interface to stop
* @arg: Stop reason (ECRNX_TXQ_STOP_CHAN or ECRNX_TXQ_STOP_VIF_PS)
* @ecrnx_hw: Driver main data
*
* Iterate over all the STA associated to the vif and stop them for the
* reason ECRNX_TXQ_STOP_CHAN or ECRNX_TXQ_STOP_VIF_PS
* Take tx_lock
*/
void ecrnx_txq_vif_stop(struct ecrnx_vif *ecrnx_vif, u16 reason,
struct ecrnx_hw *ecrnx_hw)
{
struct ecrnx_txq *txq;
trace_txq_vif_stop(ecrnx_vif->vif_index);
spin_lock_bh(&ecrnx_hw->tx_lock);
//Reject if monitor interface
if (ecrnx_vif->wdev.iftype == NL80211_IFTYPE_MONITOR)
goto end;
ecrnx_txq_vif_for_each_sta(ecrnx_hw, ecrnx_vif, ecrnx_txq_sta_stop, reason);
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_BCMC_TXQ_TYPE);
ecrnx_txq_stop(txq, reason);
txq = ecrnx_txq_vif_get(ecrnx_vif, NX_UNK_TXQ_TYPE);
ecrnx_txq_stop(txq, reason);
end:
spin_unlock_bh(&ecrnx_hw->tx_lock);
}
/**
* ecrnx_start_offchan_txq - START TX queue for offchannel frame
*
* @ecrnx_hw: Driver main data
*/
void ecrnx_txq_offchan_start(struct ecrnx_hw *ecrnx_hw)
{
struct ecrnx_txq *txq;
txq = &ecrnx_hw->txq[NX_OFF_CHAN_TXQ_IDX];
spin_lock_bh(&ecrnx_hw->tx_lock);
ecrnx_txq_start(txq, ECRNX_TXQ_STOP_CHAN);
spin_unlock_bh(&ecrnx_hw->tx_lock);
ecrnx_printk_tx("%s-%d:ecrnx_txq_start,reaosn:0x%x \n", __func__, __LINE__, ECRNX_TXQ_STOP_CHAN);
}
/**
* ecrnx_switch_vif_sta_txq - Associate TXQ linked to a STA to a new vif
*
* @sta: STA whose txq must be switched
* @old_vif: Vif currently associated to the STA (may no longer be active)
* @new_vif: vif which should be associated to the STA for now on
*
* This function will switch the vif (i.e. the netdev) associated to all STA's
* TXQ. This is used when AP_VLAN interface are created.
* If one STA is associated to an AP_vlan vif, it will be moved from the master
* AP vif to the AP_vlan vif.
* If an AP_vlan vif is removed, then STA will be moved back to mastert AP vif.
*
*/
void ecrnx_txq_sta_switch_vif(struct ecrnx_sta *sta, struct ecrnx_vif *old_vif,
struct ecrnx_vif *new_vif)
{
struct ecrnx_hw *ecrnx_hw = new_vif->ecrnx_hw;
struct ecrnx_txq *txq;
int i;
/* start TXQ on the new interface, and update ndev field in txq */
if (!netif_carrier_ok(new_vif->ndev))
netif_carrier_on(new_vif->ndev);
txq = ecrnx_txq_sta_get(sta, 0, ecrnx_hw);
for (i = 0; i < NX_NB_TID_PER_STA; i++, txq++) {
txq->ndev = new_vif->ndev;
netif_wake_subqueue(txq->ndev, txq->ndev_idx);
}
}
/******************************************************************************
* TXQ queue/schedule functions
*****************************************************************************/
/**
* ecrnx_txq_queue_skb - Queue a buffer in a TX queue
*
* @skb: Buffer to queue
* @txq: TX Queue in which the buffer must be added
* @ecrnx_hw: Driver main data
* @retry: Should it be queued in the retry list
*
* @return: Retrun 1 if txq has been added to hwq list, 0 otherwise
*
* Add a buffer in the buffer list of the TX queue
* and add this TX queue in the HW queue list if the txq is not stopped.
* If this is a retry packet it is added after the last retry packet or at the
* beginning if there is no retry packet queued.
*
* If the STA is in PS mode and this is the first packet queued for this txq
* update TIM.
*
* To be called with tx_lock hold
*/
int ecrnx_txq_queue_skb(struct sk_buff *skb, struct ecrnx_txq *txq,
struct ecrnx_hw *ecrnx_hw, bool retry,
struct sk_buff *skb_prev)
{
if (unlikely(txq->sta && txq->sta->ps.active)) {
txq->sta->ps.pkt_ready[txq->ps_id]++;
trace_ps_queue(txq->sta);
if (txq->sta->ps.pkt_ready[txq->ps_id] == 1) {
ecrnx_set_traffic_status(ecrnx_hw, txq->sta, true, txq->ps_id);
}
}
if (!retry) {
/* add buffer in the sk_list */
if (skb_prev)
skb_append(skb_prev, skb, &txq->sk_list);
else