Repository navigation
Expand file tree
/
Copy pathif_owl.c
More file actions
executable file
·2150 lines (1713 loc) · 52.5 KB
/
Copy pathif_owl.c
File metadata and controls
executable file
·2150 lines (1713 loc) · 52.5 KB
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
/*
* Copyright (c) 2013 Qualcomm Atheros, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Qualcomm Atheros nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <adf_os_types.h>
#include <adf_os_dma.h>
#include <adf_os_timer.h>
#include <adf_os_lock.h>
#include <adf_os_io.h>
#include <adf_os_mem.h>
#include <adf_os_util.h>
#include <adf_os_stdtypes.h>
#include <adf_os_defer.h>
#include <adf_os_atomic.h>
#include <adf_nbuf.h>
#include <adf_net.h>
#include <adf_net_wcmd.h>
#include "if_llc.h"
#ifdef USE_HEADERLEN_RESV
#include <if_llc.h>
#endif
#include <ieee80211_var.h>
#include "if_athrate.h"
#include "if_athvar.h"
#include "ah_desc.h"
#include "ah_internal.h"
#define ath_tgt_free_skb adf_nbuf_free
#define OFDM_PLCP_BITS 22
#define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
#define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
#define L_STF 8
#define L_LTF 8
#define L_SIG 4
#define HT_SIG 8
#define HT_STF 4
#define HT_LTF(_ns) (4 * (_ns))
#define SYMBOL_TIME(_ns) ((_ns) << 2) // ns * 4 us
#define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) // ns * 3.6 us
static a_uint16_t bits_per_symbol[][2] = {
/* 20MHz 40MHz */
{ 26, 54 }, // 0: BPSK
{ 52, 108 }, // 1: QPSK 1/2
{ 78, 162 }, // 2: QPSK 3/4
{ 104, 216 }, // 3: 16-QAM 1/2
{ 156, 324 }, // 4: 16-QAM 3/4
{ 208, 432 }, // 5: 64-QAM 2/3
{ 234, 486 }, // 6: 64-QAM 3/4
{ 260, 540 }, // 7: 64-QAM 5/6
{ 52, 108 }, // 8: BPSK
{ 104, 216 }, // 9: QPSK 1/2
{ 156, 324 }, // 10: QPSK 3/4
{ 208, 432 }, // 11: 16-QAM 1/2
{ 312, 648 }, // 12: 16-QAM 3/4
{ 416, 864 }, // 13: 64-QAM 2/3
{ 468, 972 }, // 14: 64-QAM 3/4
{ 520, 1080 }, // 15: 64-QAM 5/6
};
void owltgt_tx_processq(struct ath_softc_tgt *sc, struct ath_txq *txq,
owl_txq_state_t txqstate);
static void ath_tgt_txqaddbuf(struct ath_softc_tgt *sc, struct ath_txq *txq,
struct ath_tx_buf *bf, struct ath_tx_desc *lastds);
void ath_rate_findrate_11n_Hardcoded(struct ath_softc_tgt *sc,
struct ath_rc_series series[]);
void ath_buf_set_rate_Hardcoded(struct ath_softc_tgt *sc,
struct ath_tx_buf *bf) ;
static a_int32_t ath_tgt_txbuf_setup(struct ath_softc_tgt *sc,
struct ath_tx_buf *bf, ath_data_hdr_t *dh);
static void ath_tx_freebuf(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
static void ath_tx_uc_comp(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
static void ath_update_stats(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
void adf_print_buf(adf_nbuf_t buf);
static void ath_tgt_tx_enqueue(struct ath_txq *txq, struct ath_atx_tid *tid);
void ath_tgt_tx_comp_aggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
struct ieee80211_frame *ATH_SKB_2_WH(adf_nbuf_t skb);
void ath_tgt_tx_send_normal(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
static void ath_tgt_tx_sched_normal(struct ath_softc_tgt *sc, ath_atx_tid_t *tid);
static void ath_tgt_tx_sched_aggr(struct ath_softc_tgt *sc, ath_atx_tid_t *tid);
extern a_int32_t ath_chainmask_sel_logic(void *);
static a_int32_t ath_get_pktlen(struct ath_tx_buf *bf, a_int32_t hdrlen);
static void ath_tgt_txq_schedule(struct ath_softc_tgt *sc, struct ath_txq *txq);
typedef void (*ath_ft_set_atype_t)(struct ath_softc_tgt *sc, struct ath_buf *bf);
static void
ath_tx_set_retry(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
static void
ath_bar_tx(struct ath_softc_tgt *sc, ath_atx_tid_t *tid, struct ath_tx_buf *bf);
static void
ath_tx_update_baw(ath_atx_tid_t *tid, int seqno);
static void
ath_tx_retry_subframe(struct ath_softc_tgt *sc, struct ath_tx_buf *bf,
ath_tx_bufhead *bf_q, struct ath_tx_buf **bar);
static void
ath_tx_comp_aggr_error(struct ath_softc_tgt *sc, struct ath_tx_buf *bf, ath_atx_tid_t *tid);
void ath_tx_addto_baw(ath_atx_tid_t *tid, struct ath_tx_buf *bf);
static inline void ath_tx_retry_unaggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
static void ath_tx_comp_unaggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
static void ath_update_aggr_stats(struct ath_softc_tgt *sc, struct ath_tx_desc *ds,
int nframes, int nbad);
static inline void ath_aggr_resume_tid(struct ath_softc_tgt *sc, ath_atx_tid_t *tid);
static void ath_tx_comp_cleanup(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
int ath_tgt_tx_add_to_aggr(struct ath_softc_tgt *sc,
struct ath_buf *bf,int datatype,
ath_atx_tid_t *tid, int is_burst);
int ath_tgt_tx_form_aggr(struct ath_softc_tgt *sc, ath_atx_tid_t *tid,
ath_tx_bufhead *bf_q);
struct ieee80211_frame *ATH_SKB_2_WH(adf_nbuf_t skb)
{
a_uint8_t *anbdata;
a_uint32_t anblen;
adf_nbuf_peek_header(skb, &anbdata, &anblen);
return((struct ieee80211_frame *)anbdata);
}
#undef adf_os_cpu_to_le16
static a_uint16_t adf_os_cpu_to_le16(a_uint16_t x)
{
return ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8));
}
static inline void
ath_aggr_resume_tid(struct ath_softc_tgt *sc, ath_atx_tid_t *tid)
{
struct ath_txq *txq;
txq = TID_TO_ACTXQ(tid->tidno);
tid->paused = 0;
if (asf_tailq_empty(&tid->buf_q))
return;
ath_tgt_tx_enqueue(txq, tid);
ath_tgt_txq_schedule(sc, txq);
}
static inline void
ath_aggr_pause_tid(struct ath_softc_tgt *sc, ath_atx_tid_t *tid)
{
tid->paused =1;
}
static a_uint32_t ath_pkt_duration(struct ath_softc_tgt *sc,
a_uint8_t rix, struct ath_tx_buf *bf,
a_int32_t width, a_int32_t half_gi)
{
const HAL_RATE_TABLE *rt = sc->sc_currates;
a_uint32_t nbits, nsymbits, duration, nsymbols;
a_uint8_t rc;
a_int32_t streams;
a_int32_t pktlen;
pktlen = bf->bf_isaggr ? bf->bf_al : bf->bf_pktlen;
rc = rt->info[rix].rateCode;
if (!IS_HT_RATE(rc))
return ath_hal_computetxtime(sc->sc_ah, rt, pktlen, rix,
bf->bf_shpream);
nbits = (pktlen << 3) + OFDM_PLCP_BITS;
nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
nsymbols = (nbits + nsymbits - 1) / nsymbits;
if (!half_gi)
duration = SYMBOL_TIME(nsymbols);
else
duration = SYMBOL_TIME_HALFGI(nsymbols);
streams = HT_RC_2_STREAMS(rc);
duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
return duration;
}
static void ath_dma_map(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
adf_nbuf_t skb = bf->bf_skb;
skb = adf_nbuf_queue_first(&bf->bf_skbhead);
adf_nbuf_map(sc->sc_dev, bf->bf_dmamap, skb, ADF_OS_DMA_TO_DEVICE);
}
static void ath_dma_unmap(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
adf_nbuf_queue_first(&bf->bf_skbhead);
adf_nbuf_unmap( sc->sc_dev, bf->bf_dmamap, ADF_OS_DMA_TO_DEVICE);
}
static void ath_filltxdesc(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
struct ath_tx_desc *ds0, *ds = bf->bf_desc;
struct ath_hal *ah = sc->sc_ah;
a_uint8_t i;
ds0 = ds;
adf_nbuf_dmamap_info(bf->bf_dmamap, &bf->bf_dmamap_info);
for (i = 0; i < bf->bf_dmamap_info.nsegs; i++, ds++) {
ds->ds_data = bf->bf_dmamap_info.dma_segs[i].paddr;
if (i == (bf->bf_dmamap_info.nsegs - 1)) {
ds->ds_link = 0;
bf->bf_lastds = ds;
} else
ds->ds_link = ATH_BUF_GET_DESC_PHY_ADDR_WITH_IDX(bf, i+1);
ah->ah_fillTxDesc(ds
, bf->bf_dmamap_info.dma_segs[i].len
, i == 0
, i == (bf->bf_dmamap_info.nsegs - 1)
, ds0);
}
}
static void ath_tx_tgt_setds(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
struct ath_tx_desc *ds = bf->bf_desc;
struct ath_hal *ah = sc->sc_ah;
switch (bf->bf_protmode) {
case IEEE80211_PROT_RTSCTS:
bf->bf_flags |= HAL_TXDESC_RTSENA;
break;
case IEEE80211_PROT_CTSONLY:
bf->bf_flags |= HAL_TXDESC_CTSENA;
break;
default:
break;
}
ah->ah_set11nTxDesc(ds
, bf->bf_pktlen
, bf->bf_atype
, 60
, bf->bf_keyix
, bf->bf_keytype
, bf->bf_flags | HAL_TXDESC_INTREQ);
ath_filltxdesc(sc, bf);
}
static struct ath_tx_buf *ath_buf_toggle(struct ath_softc_tgt *sc,
struct ath_tx_buf *bf,
a_uint8_t retry)
{
struct ath_tx_buf *tmp = NULL;
adf_nbuf_t buf = NULL;
adf_os_assert(sc->sc_txbuf_held != NULL);
tmp = sc->sc_txbuf_held;
if (retry) {
ath_dma_unmap(sc, bf);
adf_nbuf_queue_init(&tmp->bf_skbhead);
buf = adf_nbuf_queue_remove(&bf->bf_skbhead);
adf_os_assert(buf);
adf_nbuf_queue_add(&tmp->bf_skbhead, buf);
adf_os_assert(adf_nbuf_queue_len(&bf->bf_skbhead) == 0);
tmp->bf_next = bf->bf_next;
tmp->bf_endpt = bf->bf_endpt;
tmp->bf_tidno = bf->bf_tidno;
tmp->bf_skb = bf->bf_skb;
tmp->bf_node = bf->bf_node;
tmp->bf_isaggr = bf->bf_isaggr;
tmp->bf_flags = bf->bf_flags;
tmp->bf_state = bf->bf_state;
tmp->bf_retries = bf->bf_retries;
tmp->bf_comp = bf->bf_comp;
tmp->bf_nframes = bf->bf_nframes;
tmp->bf_cookie = bf->bf_cookie;
bf->bf_isaggr = 0;
bf->bf_next = NULL;
bf->bf_skb = NULL;
bf->bf_node = NULL;
bf->bf_flags = 0;
bf->bf_comp = NULL;
bf->bf_retries = 0;
bf->bf_nframes = 0;
ath_dma_map(sc, tmp);
ath_tx_tgt_setds(sc, tmp);
}
sc->sc_txbuf_held = bf;
return tmp;
}
static void ath_tgt_skb_free(struct ath_softc_tgt *sc,
adf_nbuf_queue_t *head,
HTC_ENDPOINT_ID endpt)
{
adf_nbuf_t tskb;
while (adf_nbuf_queue_len(head) != 0) {
tskb = adf_nbuf_queue_remove(head);
ath_free_tx_skb(sc->tgt_htc_handle,endpt,tskb);
}
}
static void ath_buf_comp(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
ath_dma_unmap(sc, bf);
ath_tgt_skb_free(sc, &bf->bf_skbhead,bf->bf_endpt);
bf->bf_skb = NULL;
bf->bf_node = NULL;
bf = ath_buf_toggle(sc, bf, 0);
if (bf != NULL) {
asf_tailq_insert_tail(&sc->sc_txbuf, bf, bf_list);
}
}
static void ath_buf_set_rate(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
struct ath_hal *ah = sc->sc_ah;
const HAL_RATE_TABLE *rt;
struct ath_tx_desc *ds = bf->bf_desc;
HAL_11N_RATE_SERIES series[4];
a_int32_t i, flags;
a_uint8_t rix, cix, rtsctsrate;
a_int32_t prot_mode = AH_FALSE;
rt = sc->sc_currates;
rix = bf->bf_rcs[0].rix;
flags = (bf->bf_flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA));
cix = rt->info[sc->sc_protrix].controlRate;
if (bf->bf_protmode != IEEE80211_PROT_NONE &&
(rt->info[rix].phy == IEEE80211_T_OFDM ||
rt->info[rix].phy == IEEE80211_T_HT) &&
(bf->bf_flags & HAL_TXDESC_NOACK) == 0) {
cix = rt->info[sc->sc_protrix].controlRate;
prot_mode = AH_TRUE;
} else {
if (ath_hal_getcapability(ah, HAL_CAP_HT) && (!bf->bf_ismcast))
flags = HAL_TXDESC_RTSENA;
for (i = 4; i--;) {
if (bf->bf_rcs[i].tries) {
cix = rt->info[bf->bf_rcs[i].rix].controlRate;
break;
}
}
}
adf_os_mem_set(series, 0, sizeof(HAL_11N_RATE_SERIES) * 4);
for (i = 0; i < 4; i++) {
if (!bf->bf_rcs[i].tries)
continue;
rix = bf->bf_rcs[i].rix;
series[i].Rate = rt->info[rix].rateCode |
(bf->bf_shpream ? rt->info[rix].shortPreamble : 0);
series[i].Tries = bf->bf_rcs[i].tries;
#ifdef MAGPIE_MERLIN
series[i].RateFlags = ((bf->bf_rcs[i].flags & ATH_RC_RTSCTS_FLAG) ?
HAL_RATESERIES_RTS_CTS : 0 ) |
((bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) ?
HAL_RATESERIES_2040 : 0 ) |
((bf->bf_rcs[i].flags & ATH_RC_HT40_SGI_FLAG) ?
HAL_RATESERIES_HALFGI : 0 ) |
((bf->bf_rcs[i].flags & ATH_RC_TX_STBC_FLAG) ?
HAL_RATESERIES_STBC: 0);
#else
series[i].RateFlags = ((bf->bf_rcs[i].flags & ATH_RC_RTSCTS_FLAG) ?
HAL_RATESERIES_RTS_CTS : 0 ) |
((bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) ?
HAL_RATESERIES_2040 : 0 ) |
((bf->bf_rcs[i].flags & ATH_RC_HT40_SGI_FLAG) ?
HAL_RATESERIES_HALFGI : 0 );
#endif
series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
(bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) != 0,
(bf->bf_rcs[i].flags & ATH_RC_HT40_SGI_FLAG));
series[i].ChSel = sc->sc_ic.ic_tx_chainmask;
if (prot_mode)
series[i].RateFlags |= HAL_RATESERIES_RTS_CTS;
if (bf->bf_rcs[i].flags & ATH_RC_DS_FLAG)
series[i].RateFlags |= HAL_RATESERIES_RTS_CTS;
}
rtsctsrate = rt->info[cix].rateCode |
(bf->bf_shpream ? rt->info[cix].shortPreamble : 0);
ah->ah_set11nRateScenario(ds, 1,
rtsctsrate,
series, 4,
flags);
}
static void ath_tgt_rate_findrate(struct ath_softc_tgt *sc,
struct ath_node_target *an,
a_int32_t shortPreamble,
size_t frameLen,
a_int32_t numTries,
a_int32_t numRates,
a_int32_t stepDnInc,
a_uint32_t rcflag,
struct ath_rc_series series[],
a_int32_t *isProbe)
{
ath_rate_findrate(sc, an, 1, frameLen, 10, 4, 1,
ATH_RC_PROBE_ALLOWED, series, isProbe);
}
static void owl_tgt_tid_init(struct ath_atx_tid *tid)
{
int i;
tid->seq_start = tid->seq_next = 0;
tid->baw_size = WME_MAX_BA;
tid->baw_head = tid->baw_tail = 0;
tid->paused = 0;
tid->flag = 0;
tid->sched = AH_FALSE;
asf_tailq_init(&tid->buf_q);
for (i = 0; i < ATH_TID_MAX_BUFS; i++) {
TX_BUF_BITMAP_CLR(tid->tx_buf_bitmap, i);
}
}
static void owl_tgt_tid_cleanup(struct ath_softc_tgt *sc,
struct ath_atx_tid *tid)
{
tid->incomp--;
if (tid->incomp) {
return;
}
tid->flag &= ~TID_CLEANUP_INPROGRES;
if (tid->flag & TID_REINITIALIZE) {
adf_os_print("TID REINIT DONE for tid %p\n", tid);
tid->flag &= ~TID_REINITIALIZE;
owl_tgt_tid_init(tid);
} else {
ath_aggr_resume_tid(sc, tid);
}
}
void owl_tgt_node_init(struct ath_node_target * an)
{
struct ath_atx_tid *tid;
int tidno;
for (tidno = 0, tid = &an->tid[tidno]; tidno < WME_NUM_TID;tidno++, tid++) {
tid->tidno = tidno;
tid->an = an;
if ( tid->flag & TID_CLEANUP_INPROGRES ) {
tid->flag |= TID_REINITIALIZE;
adf_os_print("tid[%p]->incomp is not 0: %d\n",
tid, tid->incomp);
} else {
owl_tgt_tid_init(tid);
}
}
}
void ath_tx_status_clear(struct ath_softc_tgt *sc)
{
int i;
for (i = 0; i < 2; i++) {
sc->tx_status[i].cnt = 0;
}
}
static WMI_TXSTATUS_EVENT *ath_tx_status_get(struct ath_softc_tgt *sc)
{
WMI_TXSTATUS_EVENT *txs = NULL;
int i;
for (i = 0; i < 2; i++) {
if (sc->tx_status[i].cnt < HTC_MAX_TX_STATUS) {
txs = &sc->tx_status[i];
break;
}
}
return txs;
}
void ath_tx_status_update(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
struct ath_tx_desc *ds = bf->bf_lastds;
WMI_TXSTATUS_EVENT *txs;
if (sc->sc_tx_draining)
return;
txs = ath_tx_status_get(sc);
if (txs == NULL)
return;
txs->txstatus[txs->cnt].ts_flags = 0;
txs->txstatus[txs->cnt].cookie = bf->bf_cookie;
txs->txstatus[txs->cnt].ts_rate = SM(bf->bf_endpt, ATH9K_HTC_TXSTAT_EPID);
if (ds->ds_txstat.ts_status & HAL_TXERR_FILT)
txs->txstatus[txs->cnt].ts_flags |= ATH9K_HTC_TXSTAT_FILT;
if (!(ds->ds_txstat.ts_status & HAL_TXERR_XRETRY) &&
!(ds->ds_txstat.ts_status & HAL_TXERR_FIFO) &&
!(ds->ds_txstat.ts_status & HAL_TXERR_TIMER_EXPIRED) &&
!(ds->ds_txstat.ts_status & HAL_TXERR_FILT))
txs->txstatus[txs->cnt].ts_flags |= ATH9K_HTC_TXSTAT_ACK;
ath_tx_status_update_rate(sc, bf->bf_rcs, ds->ds_txstat.ts_rate, txs);
txs->cnt++;
}
void ath_tx_status_update_aggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf,
struct ath_tx_desc *ds, struct ath_rc_series rcs[],
int txok)
{
WMI_TXSTATUS_EVENT *txs;
if (sc->sc_tx_draining)
return;
txs = ath_tx_status_get(sc);
if (txs == NULL)
return;
txs->txstatus[txs->cnt].cookie = bf->bf_cookie;
txs->txstatus[txs->cnt].ts_rate = SM(bf->bf_endpt, ATH9K_HTC_TXSTAT_EPID);
if (txok)
txs->txstatus[txs->cnt].ts_flags |= ATH9K_HTC_TXSTAT_ACK;
if (rcs)
ath_tx_status_update_rate(sc, rcs, ds->ds_txstat.ts_rate, txs);
txs->cnt++;
}
void ath_tx_status_send(struct ath_softc_tgt *sc)
{
int i;
if (sc->sc_tx_draining)
return;
for (i = 0; i < 2; i++) {
if (sc->tx_status[i].cnt) {
wmi_event(sc->tgt_wmi_handle, WMI_TXSTATUS_EVENTID,
&sc->tx_status[i], sizeof(WMI_TXSTATUS_EVENT));
/* FIXME: Handle failures. */
sc->tx_status[i].cnt = 0;
}
}
}
static void owltgt_tx_process_cabq(struct ath_softc_tgt *sc, struct ath_txq *txq)
{
struct ath_hal *ah = sc->sc_ah;
ah->ah_setInterrupts(ah, sc->sc_imask & ~HAL_INT_SWBA);
owltgt_tx_processq(sc, txq, OWL_TXQ_ACTIVE);
ah->ah_setInterrupts(ah, sc->sc_imask);
}
void owl_tgt_tx_tasklet(TQUEUE_ARG data)
{
struct ath_softc_tgt *sc = (struct ath_softc_tgt *)data;
a_int32_t i;
struct ath_txq *txq;
ath_tx_status_clear(sc);
for (i = 0; i < (HAL_NUM_TX_QUEUES - 6); i++) {
txq = ATH_TXQ(sc, i);
if (ATH_TXQ_SETUP(sc, i)) {
if (txq == sc->sc_cabq)
owltgt_tx_process_cabq(sc, txq);
else
owltgt_tx_processq(sc, txq, OWL_TXQ_ACTIVE);
}
}
ath_tx_status_send(sc);
}
void owltgt_tx_processq(struct ath_softc_tgt *sc, struct ath_txq *txq,
owl_txq_state_t txqstate)
{
struct ath_tx_buf *bf;
struct ath_tx_desc *ds;
struct ath_hal *ah = sc->sc_ah;
HAL_STATUS status;
for (;;) {
if (asf_tailq_empty(&txq->axq_q)) {
txq->axq_link = NULL;
txq->axq_linkbuf = NULL;
break;
}
bf = asf_tailq_first(&txq->axq_q);
ds = bf->bf_lastds;
status = ah->ah_procTxDesc(ah, ds);
if (status == HAL_EINPROGRESS) {
if (txqstate == OWL_TXQ_ACTIVE)
break;
else if (txqstate == OWL_TXQ_STOPPED) {
__stats(sc, tx_stopfiltered);
ds->ds_txstat.ts_flags = 0;
ds->ds_txstat.ts_status = HAL_OK;
} else {
ds->ds_txstat.ts_flags = HAL_TX_SW_FILTERED;
}
}
ATH_TXQ_REMOVE_HEAD(txq, bf, bf_list);
if ((asf_tailq_empty(&txq->axq_q))) {
__stats(sc, tx_qnull);
txq->axq_link = NULL;
txq->axq_linkbuf = NULL;
}
if (bf->bf_comp) {
bf->bf_comp(sc, bf);
} else {
ath_tx_status_update(sc, bf);
ath_buf_comp(sc, bf);
}
if (txqstate == OWL_TXQ_ACTIVE) {
ath_tgt_txq_schedule(sc, txq);
}
}
}
static struct ieee80211_frame* ATH_SKB2_WH(adf_nbuf_t skb)
{
a_uint8_t *anbdata;
a_uint32_t anblen;
adf_nbuf_peek_header(skb, &anbdata, &anblen);
return((struct ieee80211_frame *)anbdata);
}
void
ath_tgt_tid_drain(struct ath_softc_tgt *sc, struct ath_atx_tid *tid)
{
struct ath_tx_buf *bf;
while (!asf_tailq_empty(&tid->buf_q)) {
TAILQ_DEQ(&tid->buf_q, bf, bf_list);
ath_tx_freebuf(sc, bf);
}
tid->seq_next = tid->seq_start;
tid->baw_tail = tid->baw_head;
}
static void ath_tgt_tx_comp_normal(struct ath_softc_tgt *sc,
struct ath_tx_buf *bf)
{
struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
if (tid->flag & TID_CLEANUP_INPROGRES) {
owl_tgt_tid_cleanup(sc, tid);
}
if (bf->bf_node) {
ath_tx_uc_comp(sc, bf);
}
ath_tx_freebuf(sc, bf);
}
static struct ieee80211_node_target * ath_tgt_find_node(struct ath_softc_tgt *sc,
a_int32_t node_index)
{
struct ath_node_target *an;
struct ieee80211_node_target *ni;
if (node_index > TARGET_NODE_MAX)
return NULL;
an = &sc->sc_sta[node_index];
ni = &an->ni;
if (an->an_valid) {
if (ni->ni_vap == NULL) {
return NULL;
}
return ni;
}
return NULL;
}
static struct ath_tx_buf* ath_tx_buf_alloc(struct ath_softc_tgt *sc)
{
struct ath_tx_buf *bf = NULL;
bf = asf_tailq_first(&sc->sc_txbuf);
if (bf != NULL) {
adf_os_mem_set(&bf->bf_state, 0, sizeof(struct ath_buf_state));
asf_tailq_remove(&sc->sc_txbuf, bf, bf_list);
} else {
adf_os_assert(0);
}
return bf;
}
struct ath_tx_buf* ath_tgt_tx_prepare(struct ath_softc_tgt *sc,
adf_nbuf_t skb, ath_data_hdr_t *dh)
{
struct ath_tx_buf *bf;
struct ieee80211_node_target *ni;
struct ath_atx_tid *tid;
ni = ath_tgt_find_node(sc, dh->ni_index);
if (ni == NULL)
return NULL;
tid = ATH_AN_2_TID(ATH_NODE_TARGET(ni), dh->tidno);
if (tid->flag & TID_REINITIALIZE) {
adf_os_print("drop frame due to TID reinit\n");
return NULL;
}
bf = ath_tx_buf_alloc(sc);
if (!bf) {
__stats(sc, tx_nobufs);
return NULL;
}
bf->bf_tidno = dh->tidno;
bf->bf_txq = TID_TO_ACTXQ(bf->bf_tidno);
bf->bf_keytype = dh->keytype;
bf->bf_keyix = dh->keyix;
bf->bf_protmode = dh->flags & (IEEE80211_PROT_RTSCTS | IEEE80211_PROT_CTSONLY);
bf->bf_node = ni;
adf_nbuf_queue_add(&bf->bf_skbhead, skb);
skb = adf_nbuf_queue_first(&(bf->bf_skbhead));
if (adf_nbuf_queue_len(&(bf->bf_skbhead)) == 0) {
__stats(sc, tx_noskbs);
return NULL;
}
adf_os_assert(skb);
bf->bf_skb = skb;
ath_tgt_txbuf_setup(sc, bf, dh);
ath_dma_map(sc, bf);
ath_tx_tgt_setds(sc, bf);
return bf;
}
static void ath_tgt_tx_seqno_normal(struct ath_tx_buf *bf)
{
struct ieee80211_node_target *ni = bf->bf_node;
struct ath_node_target *an = ATH_NODE_TARGET(ni);
struct ieee80211_frame *wh = ATH_SKB_2_WH(bf->bf_skb);
struct ath_atx_tid *tid = ATH_AN_2_TID(an, bf->bf_tidno);
u_int8_t fragno = (wh->i_seq[0] & 0xf);
INCR(ni->ni_txseqmgmt, IEEE80211_SEQ_MAX);
bf->bf_seqno = (tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT);
*(u_int16_t *)wh->i_seq = adf_os_cpu_to_le16(bf->bf_seqno);
wh->i_seq[0] |= fragno;
if (!(wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG))
INCR(tid->seq_next, IEEE80211_SEQ_MAX);
}
static a_int32_t ath_key_setup(struct ieee80211_node_target *ni,
struct ath_tx_buf *bf)
{
struct ieee80211_frame *wh = ATH_SKB_2_WH(bf->bf_skb);
if (!(wh->i_fc[1] & IEEE80211_FC1_WEP)) {
bf->bf_keytype = HAL_KEY_TYPE_CLEAR;
bf->bf_keyix = HAL_TXKEYIX_INVALID;
return 0;
}
switch (bf->bf_keytype) {
case HAL_KEY_TYPE_WEP:
bf->bf_pktlen += IEEE80211_WEP_ICVLEN;
break;
case HAL_KEY_TYPE_AES:
bf->bf_pktlen += IEEE80211_WEP_MICLEN;
break;
case HAL_KEY_TYPE_TKIP:
bf->bf_pktlen += IEEE80211_WEP_ICVLEN;
break;
default:
break;
}
if (bf->bf_keytype == HAL_KEY_TYPE_AES ||
bf->bf_keytype == HAL_KEY_TYPE_TKIP)
ieee80211_tgt_crypto_encap(wh, ni, bf->bf_keytype);
return 0;
}
static void ath_tgt_txq_add_ucast(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
struct ath_hal *ah = sc->sc_ah;
struct ath_txq *txq;
volatile a_int32_t txe_val;
adf_os_assert(bf);
txq = bf->bf_txq;
ah->ah_procTxDesc(ah, bf->bf_lastds);
ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
if (txq->axq_link == NULL) {
ah->ah_setTxDP(ah, txq->axq_qnum, ATH_BUF_GET_DESC_PHY_ADDR(bf));
} else {
*txq->axq_link = ATH_BUF_GET_DESC_PHY_ADDR(bf);
txe_val = ioread32_mac(0x0840);
if (!(txe_val & (1<< txq->axq_qnum)))
ah->ah_setTxDP(ah, txq->axq_qnum, ATH_BUF_GET_DESC_PHY_ADDR(bf));
}
txq->axq_link = &bf->bf_lastds->ds_link;
ah->ah_startTxDma(ah, txq->axq_qnum);
}
static a_int32_t ath_tgt_txbuf_setup(struct ath_softc_tgt *sc,
struct ath_tx_buf *bf,
ath_data_hdr_t *dh)
{
struct ieee80211_frame *wh = ATH_SKB2_WH(bf->bf_skb);
a_int32_t retval;
a_uint32_t flags = adf_os_ntohl(dh->flags);
ath_tgt_tx_seqno_normal(bf);
bf->bf_txq_add = ath_tgt_txq_add_ucast;
bf->bf_hdrlen = ieee80211_anyhdrsize(wh);
bf->bf_pktlen = ath_get_pktlen(bf, bf->bf_hdrlen);
bf->bf_ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
if ((retval = ath_key_setup(bf->bf_node, bf)) < 0)
return retval;
if (flags & ATH_SHORT_PREAMBLE)
bf->bf_shpream = AH_TRUE;
else
bf->bf_shpream = AH_FALSE;
bf->bf_flags = HAL_TXDESC_CLRDMASK;
bf->bf_atype = HAL_PKT_TYPE_NORMAL;
return 0;
}
static a_int32_t
ath_get_pktlen(struct ath_tx_buf *bf, a_int32_t hdrlen)
{
adf_nbuf_t skb = bf->bf_skb;
a_int32_t pktlen;
skb = adf_nbuf_queue_first(&bf->bf_skbhead);
pktlen = adf_nbuf_len(skb);
pktlen -= (hdrlen & 3);
pktlen += IEEE80211_CRC_LEN;
return pktlen;
}
void
ath_tgt_tx_send_normal(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
struct ath_rc_series rcs[4];
struct ath_rc_series mrcs[4];
a_int32_t shortPreamble = 0;
a_int32_t isProbe = 0;
adf_os_mem_set(rcs, 0, sizeof(struct ath_rc_series)*4 );
adf_os_mem_set(mrcs, 0, sizeof(struct ath_rc_series)*4 );
if (!bf->bf_ismcast) {
ath_tgt_rate_findrate(sc, an, shortPreamble,
0, 0, 0, 0, 0,
rcs, &isProbe);
ath_hal_memcpy(bf->bf_rcs, rcs, sizeof(rcs));
} else {
struct ath_vap_target *avp;
avp = &sc->sc_vap[bf->vap_index];
mrcs[1].tries = mrcs[2].tries = mrcs[3].tries = 0;
mrcs[1].rix = mrcs[2].rix = mrcs[3].rix = 0;
mrcs[0].rix = ath_get_minrateidx(sc, avp);
mrcs[0].tries = 1;
mrcs[0].flags = 0;
ath_hal_memcpy(bf->bf_rcs, mrcs, sizeof(mrcs));
}
ath_buf_set_rate(sc, bf);
bf->bf_txq_add(sc, bf);
}
static void
ath_tx_freebuf(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
{
a_int32_t i ;
struct ath_tx_desc *bfd = NULL;
struct ath_hal *ah = sc->sc_ah;
for (bfd = bf->bf_desc, i = 0; i < bf->bf_dmamap_info.nsegs; bfd++, i++) {
ah->ah_clr11nAggr(bfd);
ah->ah_set11nBurstDuration(bfd, 0);
ah->ah_set11nVirtualMoreFrag(bfd, 0);
}