-
Notifications
You must be signed in to change notification settings - Fork 76
/
tx.c
1455 lines (1291 loc) · 40.3 KB
/
tx.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
/*
* Datapath implementation for XRadio drivers
*
* Copyright (c) 2013, XRadio
* Author: XRadio
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <net/mac80211.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include "xradio.h"
#include "wsm.h"
#include "bh.h"
#include "ap.h"
#include "sta.h"
#include "sdio.h"
#include "common.h"
#include "p2p.h"
#define B_RATE_INDEX 0 //11b rate for important short frames in 2.4G.
#define AG_RATE_INDEX 6 //11a/g rate for important short frames in 5G.
#define XRADIO_INVALID_RATE_ID (0xFF)
/* rate should fall quickly to avoid dropping frames by aps.
* Add by yangfh 2014-9-22 13:39:57
*/
#define HIGH_RATE_MAX_RETRY 7
#ifdef TES_P2P_0002_ROC_RESTART
#include <linux/time.h>
#endif
//for test yangfh
extern u32 tx_retrylimit;
extern u32 tx_over_limit;
extern u32 tx_lower_limit;
extern int retry_mis;
static const struct ieee80211_rate *
xradio_get_tx_rate(const struct xradio_common *hw_priv,
const struct ieee80211_tx_rate *rate);
/* ******************************************************************** */
/* TX policy cache implementation */
static void tx_policy_dump(struct tx_policy *policy)
{
txrx_printk(XRADIO_DBG_MSG, "[TX policy] "
"%.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X"
"%.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X"
"%.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X: %d\n",
policy->raw[0] & 0x0F, policy->raw[0] >> 4,
policy->raw[1] & 0x0F, policy->raw[1] >> 4,
policy->raw[2] & 0x0F, policy->raw[2] >> 4,
policy->raw[3] & 0x0F, policy->raw[3] >> 4,
policy->raw[4] & 0x0F, policy->raw[4] >> 4,
policy->raw[5] & 0x0F, policy->raw[5] >> 4,
policy->raw[6] & 0x0F, policy->raw[6] >> 4,
policy->raw[7] & 0x0F, policy->raw[7] >> 4,
policy->raw[8] & 0x0F, policy->raw[8] >> 4,
policy->raw[9] & 0x0F, policy->raw[9] >> 4,
policy->raw[10] & 0x0F, policy->raw[10] >> 4,
policy->raw[11] & 0x0F, policy->raw[11] >> 4,
policy->defined);
}
static void xradio_check_go_neg_conf_success(struct xradio_common *hw_priv,
u8 *action)
{
if (action[2] == 0x50 && action[3] == 0x6F && action[4] == 0x9A &&
action[5] == 0x09 && action[6] == 0x02) {
if(action[17] == 0) {
hw_priv->is_go_thru_go_neg = true;
}
else {
hw_priv->is_go_thru_go_neg = false;
}
}
}
static void xradio_check_prov_desc_req(struct xradio_common *hw_priv,
u8 *action)
{
if (action[2] == 0x50 && action[3] == 0x6F && action[4] == 0x9A &&
action[5] == 0x09 && action[6] == 0x07) {
hw_priv->is_go_thru_go_neg = false;
}
}
//modified by yangfh
static void tx_policy_build(const struct xradio_common *hw_priv,
/* [out] */ struct tx_policy *policy,
struct ieee80211_tx_rate *rates, size_t count)
{
int i, j;
struct ieee80211_rate * tmp_rate = NULL;
unsigned limit = hw_priv->short_frame_max_tx_count;
unsigned max_rates_cnt = count;
unsigned total = 0;
BUG_ON(rates[0].idx < 0);
memset(policy, 0, sizeof(*policy));
txrx_printk(XRADIO_DBG_NIY,"============================");
#if 0
//debug yangfh
for (i = 0; i < count; ++i) {
if(rates[i].idx>=0) {
tmp_rate = xradio_get_tx_rate(hw_priv, &rates[i]);
txrx_printk(XRADIO_DBG_NIY,"[TX policy] Org %d.%dMps=%d",
tmp_rate->bitrate/10, tmp_rate->bitrate%10, rates[i].count);
}
}
txrx_printk(XRADIO_DBG_NIY,"----------------------------");
#endif
/* minstrel is buggy a little bit, so distille
* incoming rates first.
*/
/* Sort rates in descending order. */
total = rates[0].count;
for (i = 1; i < count; ++i) {
if (rates[i].idx > rates[i-1].idx) {
rates[i].idx = rates[i-1].idx>0?(rates[i-1].idx-1):-1;
}
if (rates[i].idx < 0 || i>=limit) {
count = i;
break;
} else {
total += rates[i].count;
}
}
/* Add lowest rate to the end when 11a/n.
* Don't apply in 11b/g because p2p unsupport 1Mbps.
* TODO: it's better to do this in rate control of mac80211.
*/
if (((rates[0].flags & IEEE80211_TX_RC_MCS) ||
hw_priv->channel->band == NL80211_BAND_5GHZ) &&
count < max_rates_cnt && rates[count-1].idx != 0) {
rates[count].idx = 0;
rates[count].count = rates[0].count;
rates[count].flags = rates[0].flags;
total += rates[count].count;
count++;
}
/* adjust tx count to limit, rates should fall quickly
* and lower rates should be more retry, because reorder
* buffer of reciever will be timeout and clear probably.
*/
if (count < 2) {
rates[0].count = limit;
total = limit;
} else {
u8 end_retry = 0; //the retry should be add to last rate.
if (limit > HIGH_RATE_MAX_RETRY) {
end_retry = limit - HIGH_RATE_MAX_RETRY;
limit = HIGH_RATE_MAX_RETRY;
}
for (i = 0; (limit != total) && (i < 100); ++i) { //i<100 to avoid dead loop
j = i % count;
if(limit < total) {
total += (rates[j].count > 1? -1 : 0);
rates[j].count += (rates[j].count > 1? -1 : 0);
} else {
j = count - 1 - j;
if (rates[j].count > 0) {
total++;
rates[j].count++;
}
}
}
if (end_retry) {
rates[count-1].count += end_retry;
limit += end_retry;
}
}
/* Eliminate duplicates. */
total = rates[0].count;
for (i = 0, j = 1; j < count; ++j) {
if (rates[j].idx == rates[i].idx) {
rates[i].count += rates[j].count;
} else if (rates[j].idx > rates[i].idx) {
break;
} else {
++i;
if (i != j)
rates[i] = rates[j];
}
total += rates[j].count;
}
count = i + 1;
/* Re-fill policy trying to keep every requested rate and with
* respect to the global max tx retransmission count.
*/
if (limit < count)
limit = count;
if (total > limit) {
for (i = 0; i < count; ++i) {
int left = count - i - 1;
if (rates[i].count > limit - left)
rates[i].count = limit - left;
limit -= rates[i].count;
}
}
/* HACK!!! Device has problems (at least) switching from
* 54Mbps CTS to 1Mbps. This switch takes enormous amount
* of time (100-200 ms), leading to valuable throughput drop.
* As a workaround, additional g-rates are injected to the
* policy.
*/
if (count == 2 && !(rates[0].flags & IEEE80211_TX_RC_MCS) &&
rates[0].idx > 4 && rates[0].count > 2 &&
rates[1].idx < 2) {
/* ">> 1" is an equivalent of "/ 2", but faster */
int mid_rate = (rates[0].idx + 4) >> 1;
/* Decrease number of retries for the initial rate */
rates[0].count -= 2;
if (mid_rate != 4) {
/* Keep fallback rate at 1Mbps. */
rates[3] = rates[1];
/* Inject 1 transmission on lowest g-rate */
rates[2].idx = 4;
rates[2].count = 1;
rates[2].flags = rates[1].flags;
/* Inject 1 transmission on mid-rate */
rates[1].idx = mid_rate;
rates[1].count = 1;
/* Fallback to 1 Mbps is a really bad thing,
* so let's try to increase probability of
* successful transmission on the lowest g rate
* even more */
if (rates[0].count >= 3) {
--rates[0].count;
++rates[2].count;
}
/* Adjust amount of rates defined */
count += 2;
} else {
/* Keep fallback rate at 1Mbps. */
rates[2] = rates[1];
/* Inject 2 transmissions on lowest g-rate */
rates[1].idx = 4;
rates[1].count = 2;
/* Adjust amount of rates defined */
count += 1;
}
}
tmp_rate = (struct ieee80211_rate *)xradio_get_tx_rate(hw_priv, &rates[0]);
if(tmp_rate)
policy->defined = tmp_rate->hw_value + 1;
for (i = 0; i < count; ++i) {
register unsigned rateid, off, shift, retries;
tmp_rate = (struct ieee80211_rate *)xradio_get_tx_rate(hw_priv, &rates[i]);
if(tmp_rate) {
rateid = tmp_rate->hw_value;
} else {
break;
}
off = rateid >> 3; /* eq. rateid / 8 */
shift = (rateid & 0x07) << 2; /* eq. (rateid % 8) * 4 */
retries = rates[i].count;
if (unlikely(retries > 0x0F))
rates[i].count = retries = 0x0F;
policy->tbl[off] |= __cpu_to_le32(retries << shift);
policy->retry_count += retries;
txrx_printk(XRADIO_DBG_NIY,"[TX policy] %d.%dMps=%d",
tmp_rate->bitrate/10, tmp_rate->bitrate%10, retries);
}
txrx_printk(XRADIO_DBG_MSG, "[TX policy] Dst Policy (%d): " \
"%d:%d, %d:%d, %d:%d, %d:%d, %d:%d\n",
count,
rates[0].idx, rates[0].count,
rates[1].idx, rates[1].count,
rates[2].idx, rates[2].count,
rates[3].idx, rates[3].count,
rates[4].idx, rates[4].count);
}
static inline bool tx_policy_is_equal(const struct tx_policy *wanted,
const struct tx_policy *cached)
{
size_t count = wanted->defined >> 1;
if (wanted->defined > cached->defined)
return false;
if (count) {
if (memcmp(wanted->raw, cached->raw, count))
return false;
}
if (wanted->defined & 1) {
if ((wanted->raw[count] & 0x0F) != (cached->raw[count] & 0x0F))
return false;
}
return true;
}
static int tx_policy_find(struct tx_policy_cache *cache,
const struct tx_policy *wanted)
{
/* O(n) complexity. Not so good, but there's only 8 entries in
* the cache.
* Also lru helps to reduce search time. */
struct tx_policy_cache_entry *it;
/* Search for policy in "used" list */
list_for_each_entry(it, &cache->used, link) {
if (tx_policy_is_equal(wanted, &it->policy))
return it - cache->cache;
}
/* Then - in "free list" */
list_for_each_entry(it, &cache->free, link) {
if (tx_policy_is_equal(wanted, &it->policy))
return it - cache->cache;
}
return -1;
}
static inline void tx_policy_use(struct tx_policy_cache *cache,
struct tx_policy_cache_entry *entry)
{
++entry->policy.usage_count;
list_move(&entry->link, &cache->used);
}
static inline int tx_policy_release(struct tx_policy_cache *cache,
struct tx_policy_cache_entry *entry)
{
int ret = --entry->policy.usage_count;
if (!ret)
list_move(&entry->link, &cache->free);
return ret;
}
/* ******************************************************************** */
/* External TX policy cache API */
void tx_policy_init(struct xradio_common *hw_priv)
{
struct tx_policy_cache *cache = &hw_priv->tx_policy_cache;
int i;
memset(cache, 0, sizeof(*cache));
spin_lock_init(&cache->lock);
INIT_LIST_HEAD(&cache->used);
INIT_LIST_HEAD(&cache->free);
for (i = 0; i < TX_POLICY_CACHE_SIZE; ++i)
list_add(&cache->cache[i].link, &cache->free);
}
static int tx_policy_get(struct xradio_common *hw_priv,
struct ieee80211_tx_rate *rates,
u8 use_bg_rate, bool *renew)
{
int idx;
struct tx_policy_cache *cache = &hw_priv->tx_policy_cache;
struct tx_policy wanted;
if(use_bg_rate) {
u8 rate = (u8)(use_bg_rate & 0x3f);
u8 shitf = ((rate&0x7)<<2);
u8 off = (rate>>3);
memset(&wanted, 0, sizeof(wanted));
wanted.defined = rate + 1;
wanted.retry_count = (hw_priv->short_frame_max_tx_count&0xf);
wanted.tbl[off] = wanted.retry_count<<shitf;
txrx_printk(XRADIO_DBG_NIY, "[TX policy] robust rate=%d\n", rate);
} else
tx_policy_build(hw_priv, &wanted, rates, IEEE80211_TX_MAX_RATES);
spin_lock_bh(&cache->lock);
idx = tx_policy_find(cache, &wanted);
if (idx >= 0) {
txrx_printk(XRADIO_DBG_MSG, "[TX policy] Used TX policy: %d\n",
idx);
*renew = false;
} else {
struct tx_policy_cache_entry *entry;
if (WARN_ON_ONCE(list_empty(&cache->free))) {
spin_unlock_bh(&cache->lock);
txrx_printk(XRADIO_DBG_ERROR, "[TX policy] no policy cache\n");
return XRADIO_INVALID_RATE_ID;
}
/* If policy is not found create a new one
* using the oldest entry in "free" list */
*renew = true;
entry = list_entry(cache->free.prev,
struct tx_policy_cache_entry, link);
entry->policy = wanted;
idx = entry - cache->cache;
txrx_printk(XRADIO_DBG_MSG, "[TX policy] New TX policy: %d\n",
idx);
tx_policy_dump(&entry->policy);
}
tx_policy_use(cache, &cache->cache[idx]);
if (unlikely(list_empty(&cache->free))) {
/* Lock TX queues. */
txrx_printk(XRADIO_DBG_WARN, "[TX policy] policy cache used up\n");
xradio_tx_queues_lock(hw_priv);
}
spin_unlock_bh(&cache->lock);
return idx;
}
static void tx_policy_put(struct xradio_common *hw_priv, int idx)
{
int usage, locked;
struct tx_policy_cache *cache = &hw_priv->tx_policy_cache;
spin_lock_bh(&cache->lock);
locked = list_empty(&cache->free);
usage = tx_policy_release(cache, &cache->cache[idx]);
if (unlikely(locked) && !usage) {
/* Unlock TX queues. */
xradio_tx_queues_unlock(hw_priv);
}
spin_unlock_bh(&cache->lock);
}
/*
bool tx_policy_cache_full(struct xradio_common *hw_priv)
{
bool ret;
struct tx_policy_cache *cache = &hw_priv->tx_policy_cache;
spin_lock_bh(&cache->lock);
ret = list_empty(&cache->free);
spin_unlock_bh(&cache->lock);
return ret;
}
*/
extern u32 policy_upload;
extern u32 policy_num;
static int tx_policy_upload(struct xradio_common *hw_priv)
{
struct tx_policy_cache *cache = &hw_priv->tx_policy_cache;
int i;
struct wsm_set_tx_rate_retry_policy arg = {
.hdr = {
.numTxRatePolicies = 0,
}
};
int if_id = 0;
spin_lock_bh(&cache->lock);
/* Upload only modified entries. */
for (i = 0; i < TX_POLICY_CACHE_SIZE; ++i) {
struct tx_policy *src = &cache->cache[i].policy;
if (src->retry_count && !src->uploaded) {
struct wsm_set_tx_rate_retry_policy_policy *dst =
&arg.tbl[arg.hdr.numTxRatePolicies];
dst->policyIndex = i;
dst->shortRetryCount = hw_priv->short_frame_max_tx_count-1;
//only RTS need use longRetryCount, should be short_frame.
dst->longRetryCount = hw_priv->short_frame_max_tx_count-1;
/* BIT(2) - Terminate retries when Tx rate retry policy
* finishes.
* BIT(3) - Count initial frame transmission as part of
* rate retry counting but not as a retry
* attempt */
dst->policyFlags = BIT(2) | BIT(3);
memcpy(dst->rateCountIndices, src->tbl,
sizeof(dst->rateCountIndices));
src->uploaded = 1;
++arg.hdr.numTxRatePolicies;
}
}
spin_unlock_bh(&cache->lock);
atomic_set(&hw_priv->upload_count, 0);
txrx_printk(XRADIO_DBG_MSG, "[TX policy] Upload %d policies\n",
arg.hdr.numTxRatePolicies);
/*TODO: COMBO*/
return wsm_set_tx_rate_retry_policy(hw_priv, &arg, if_id);
}
void tx_policy_upload_work(struct work_struct *work)
{
struct xradio_common *hw_priv =
container_of(work, struct xradio_common, tx_policy_upload_work);
WARN_ON(tx_policy_upload(hw_priv));
wsm_unlock_tx(hw_priv);
}
/* ******************************************************************** */
/* xradio TX implementation */
struct xradio_txinfo {
struct sk_buff *skb;
unsigned queue;
struct ieee80211_tx_info *tx_info;
const struct ieee80211_rate *rate;
struct ieee80211_hdr *hdr;
size_t hdrlen;
const u8 *da;
struct xradio_sta_priv *sta_priv;
struct xradio_txpriv txpriv;
};
u32 xradio_rate_mask_to_wsm(struct xradio_common *hw_priv, u32 rates)
{
u32 ret = 0;
int i;
u32 n_bitrates =
hw_priv->hw->wiphy->bands[hw_priv->channel->band]->n_bitrates;
struct ieee80211_rate * bitrates =
hw_priv->hw->wiphy->bands[hw_priv->channel->band]->bitrates;
for (i = 0; i < n_bitrates; ++i) {
if (rates & BIT(i))
ret |= BIT(bitrates[i].hw_value);
}
return ret;
}
static const struct ieee80211_rate *
xradio_get_tx_rate(const struct xradio_common *hw_priv,
const struct ieee80211_tx_rate *rate)
{
if (rate->idx < 0)
return NULL;
if (rate->flags & IEEE80211_TX_RC_MCS)
return &hw_priv->mcs_rates[rate->idx];
return &hw_priv->hw->wiphy->bands[hw_priv->channel->band]->
bitrates[rate->idx];
}
inline static s8
xradio_get_rate_idx(const struct xradio_common *hw_priv, u8 flag, u16 hw_value)
{
s16 ret = (s16)hw_value;
if(flag & IEEE80211_TX_RC_MCS) { //11n
if(hw_value <= hw_priv->mcs_rates[7].hw_value &&
hw_value >= hw_priv->mcs_rates[0].hw_value)
ret -= hw_priv->mcs_rates[0].hw_value;
else
ret = -1;
} else { //11b/g
if(hw_value>5 && hw_value<hw_priv->mcs_rates[0].hw_value) {
ret -= hw_priv->hw->wiphy->bands[hw_priv->channel->band]->bitrates[0].hw_value;
if(hw_priv->hw->wiphy->bands[hw_priv->channel->band]->bitrates[0].hw_value<5) //11a
ret -= 2;
} else if(hw_value<4) {
ret -= hw_priv->hw->wiphy->bands[hw_priv->channel->band]->bitrates[0].hw_value;
} else {
ret = -1;
}
}
return (s8)ret;
}
static int
xradio_tx_h_calc_link_ids(struct xradio_vif *priv,
struct ieee80211_tx_control *control,
struct xradio_txinfo *t)
{
struct xradio_common *hw_priv = xrwl_vifpriv_to_hwpriv(priv);
if ((t->tx_info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
(hw_priv->roc_if_id == priv->if_id))
t->txpriv.offchannel_if_id = 2;
else
t->txpriv.offchannel_if_id = 0;
if (likely(control->sta && t->sta_priv->link_id))
t->txpriv.raw_link_id =
t->txpriv.link_id =
t->sta_priv->link_id;
else if (priv->mode != NL80211_IFTYPE_AP)
t->txpriv.raw_link_id =
t->txpriv.link_id = 0;
else if (is_multicast_ether_addr(t->da)) {
if (priv->enable_beacon) {
t->txpriv.raw_link_id = 0;
t->txpriv.link_id = priv->link_id_after_dtim;
} else {
t->txpriv.raw_link_id = 0;
t->txpriv.link_id = 0;
}
} else {
t->txpriv.link_id =
xradio_find_link_id(priv, t->da);
/* Do not assign valid link id for deauth/disassoc frame being
transmitted to an unassociated STA */
if (!(t->txpriv.link_id) &&
(ieee80211_is_deauth(t->hdr->frame_control) ||
ieee80211_is_disassoc(t->hdr->frame_control))) {
t->txpriv.link_id = 0;
} else {
if (!t->txpriv.link_id)
t->txpriv.link_id = xradio_alloc_link_id(priv, t->da);
if (!t->txpriv.link_id) {
txrx_printk(XRADIO_DBG_ERROR,
"%s: No more link IDs available.\n", __func__);
return -ENOENT;
}
}
t->txpriv.raw_link_id = t->txpriv.link_id;
}
if (t->txpriv.raw_link_id)
priv->link_id_db[t->txpriv.raw_link_id - 1].timestamp =
jiffies;
#if defined(CONFIG_XRADIO_USE_EXTENSIONS)
if (control->sta &&
(control->sta->uapsd_queues & BIT(t->queue)))
t->txpriv.link_id = priv->link_id_uapsd;
#endif /* CONFIG_XRADIO_USE_EXTENSIONS */
return 0;
}
static void
xradio_tx_h_pm(struct xradio_vif *priv,
struct xradio_txinfo *t)
{
if (unlikely(ieee80211_is_auth(t->hdr->frame_control))) {
u32 mask = ~BIT(t->txpriv.raw_link_id);
spin_lock_bh(&priv->ps_state_lock);
priv->sta_asleep_mask &= mask;
priv->pspoll_mask &= mask;
spin_unlock_bh(&priv->ps_state_lock);
}
}
static void
xradio_tx_h_calc_tid(struct xradio_vif *priv,
struct xradio_txinfo *t)
{
if (ieee80211_is_data_qos(t->hdr->frame_control)) {
u8 *qos = ieee80211_get_qos_ctl(t->hdr);
t->txpriv.tid = qos[0] & IEEE80211_QOS_CTL_TID_MASK;
} else if (ieee80211_is_data(t->hdr->frame_control)) {
t->txpriv.tid = 0;
}
}
/* IV/ICV injection. */
/* TODO: Quite unoptimal. It's better co modify mac80211
* to reserve space for IV */
static int
xradio_tx_h_crypt(struct xradio_vif *priv,
struct xradio_txinfo *t)
{
size_t iv_len;
size_t icv_len;
u8 *icv;
if (!t->tx_info->control.hw_key ||
!(t->hdr->frame_control &
__cpu_to_le32(IEEE80211_FCTL_PROTECTED)))
return 0;
iv_len = t->tx_info->control.hw_key->iv_len;
icv_len = t->tx_info->control.hw_key->icv_len;
if (t->tx_info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
icv_len += 8; /* MIC */
if (unlikely((skb_headroom(t->skb) + skb_tailroom(t->skb) <
iv_len + icv_len + WSM_TX_EXTRA_HEADROOM) ||
(skb_headroom(t->skb) <
iv_len + WSM_TX_EXTRA_HEADROOM))) {
dev_dbg(priv->hw_priv->pdev,
"no space allocated for crypto headers.\n"
"headroom: %d, tailroom: %d, "
"req_headroom: %d, req_tailroom: %d\n"
"Please fix it in xradio_get_skb().\n",
skb_headroom(t->skb), skb_tailroom(t->skb),
iv_len + WSM_TX_EXTRA_HEADROOM, icv_len);
return -ENOMEM;
} else if (unlikely(skb_tailroom(t->skb) < icv_len)) {
size_t offset = icv_len - skb_tailroom(t->skb);
u8 *p;
dev_dbg(priv->hw_priv->pdev,
"Slowpath: tailroom is not big enough. "
"Req: %d, got: %d.\n",
icv_len, skb_tailroom(t->skb));
p = skb_push(t->skb, offset);
memmove(p, &p[offset], t->skb->len - offset);
skb_trim(t->skb, t->skb->len - offset);
}
/* ccmp pkt from umac to driver,it has iv room,,so ccmp pkt do not add iv room */
if (t->tx_info->control.hw_key->cipher != WLAN_CIPHER_SUITE_CCMP){
u8 *newhdr;
newhdr = skb_push(t->skb, iv_len);
memmove(newhdr, newhdr + iv_len, t->hdrlen);
t->hdr = (struct ieee80211_hdr *) newhdr;
}
t->hdrlen += iv_len;
icv = skb_put(t->skb, icv_len);
return 0;
}
static int
xradio_tx_h_align(struct xradio_vif *priv, struct xradio_txinfo *t,
u8 *flags)
{
size_t offset = (size_t)t->skb->data & 3;
u8 *newhdr;//add by dingxh
if (!offset)
return 0;
if (skb_headroom(t->skb) < offset) {
txrx_printk(XRADIO_DBG_ERROR,
"Bug: no space allocated "
"for DMA alignment.\n"
"headroom: %d\n",
skb_headroom(t->skb));
return -ENOMEM;
}
//offset = 1or3 process add by dingxh
if (offset & 1) {
newhdr = skb_push(t->skb, offset);
memmove(newhdr, newhdr + offset, t->skb->len-offset);
skb_trim(t->skb, t->skb->len-offset);
t->hdr = (struct ieee80211_hdr *) newhdr;
return 0;
}
//add by dingxh
//offset=2 process
skb_push(t->skb, offset);
t->hdrlen += offset;
t->txpriv.offset += offset;
*flags |= WSM_TX_2BYTES_SHIFT;
return 0;
}
static int
xradio_tx_h_action(struct xradio_vif *priv, struct xradio_txinfo *t)
{
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)t->hdr;
if (ieee80211_is_action(t->hdr->frame_control) &&
mgmt->u.action.category == WLAN_CATEGORY_BACK)
return 1;
else
return 0;
}
/* Add WSM header */
static struct wsm_tx *
xradio_tx_h_wsm(struct xradio_vif *priv, struct xradio_txinfo *t)
{
struct wsm_tx *wsm;
struct xradio_common *hw_priv = xrwl_vifpriv_to_hwpriv(priv);
if (skb_headroom(t->skb) < sizeof(struct wsm_tx)) {
txrx_printk(XRADIO_DBG_ERROR,
"Bug: no space allocated "
"for WSM header.\n"
"headroom: %d\n",
skb_headroom(t->skb));
return NULL;
}
wsm = (struct wsm_tx *)skb_push(t->skb, sizeof(struct wsm_tx));
t->txpriv.offset += sizeof(struct wsm_tx);
memset(wsm, 0, sizeof(*wsm));
wsm->hdr.len = __cpu_to_le16(t->skb->len);
wsm->hdr.id = __cpu_to_le16(0x0004);
wsm->queueId = (t->txpriv.raw_link_id << 2) | wsm_queue_id_to_wsm(t->queue);
if (wsm->hdr.len > hw_priv->wsm_caps.sizeInpChBuf) {
txrx_printk(XRADIO_DBG_ERROR,"%s,msg length too big=%d\n",
__func__, wsm->hdr.len);
wsm = NULL;
}
return wsm;
}
/* BT Coex specific handling */
static void
xradio_tx_h_bt(struct xradio_vif *priv, struct xradio_txinfo *t, struct wsm_tx *wsm)
{
u8 priority = 0;
struct xradio_common *hw_priv = xrwl_vifpriv_to_hwpriv(priv);
if (!hw_priv->is_BT_Present)
return;
if (unlikely(ieee80211_is_nullfunc(t->hdr->frame_control)))
priority = WSM_EPTA_PRIORITY_MGT;
else if (ieee80211_is_data(t->hdr->frame_control)) {
/* Skip LLC SNAP header (+6) */
u8 *payload = &t->skb->data[t->hdrlen];
u16 *ethertype = (u16 *) &payload[6];
if (unlikely(*ethertype == __be16_to_cpu(ETH_P_PAE)))
priority = WSM_EPTA_PRIORITY_EAPOL;
} else if (unlikely(ieee80211_is_assoc_req(t->hdr->frame_control) ||
ieee80211_is_reassoc_req(t->hdr->frame_control))) {
struct ieee80211_mgmt *mgt_frame =
(struct ieee80211_mgmt *)t->hdr;
if (mgt_frame->u.assoc_req.listen_interval <
priv->listen_interval) {
txrx_printk(XRADIO_DBG_MSG,
"Modified Listen Interval to %d from %d\n",
priv->listen_interval,
mgt_frame->u.assoc_req.listen_interval);
/* Replace listen interval derieved from
* the one read from SDD */
mgt_frame->u.assoc_req.listen_interval =
priv->listen_interval;
}
}
if (likely(!priority)) {
if (ieee80211_is_action(t->hdr->frame_control))
priority = WSM_EPTA_PRIORITY_ACTION;
else if (ieee80211_is_mgmt(t->hdr->frame_control))
priority = WSM_EPTA_PRIORITY_MGT;
else if ((wsm->queueId == WSM_QUEUE_VOICE))
priority = WSM_EPTA_PRIORITY_VOICE;
else if ((wsm->queueId == WSM_QUEUE_VIDEO))
priority = WSM_EPTA_PRIORITY_VIDEO;
else
priority = WSM_EPTA_PRIORITY_DATA;
}
txrx_printk(XRADIO_DBG_MSG, "[TX] EPTA priority %d.\n",
priority);
wsm->flags |= priority << 1;
}
static int
xradio_tx_h_rate_policy(struct xradio_common *hw_priv, struct xradio_txinfo *t,
struct wsm_tx *wsm)
{
bool tx_policy_renew = false;
struct xradio_vif *priv =
xrwl_get_vif_from_ieee80211(t->tx_info->control.vif);
t->txpriv.rate_id = tx_policy_get(hw_priv,
t->tx_info->control.rates, t->txpriv.use_bg_rate,
&tx_policy_renew);
if (t->txpriv.rate_id == XRADIO_INVALID_RATE_ID)
return -EFAULT;
wsm->flags |= t->txpriv.rate_id << 4;
t->rate = xradio_get_tx_rate(hw_priv, &t->tx_info->control.rates[0]);
if (t->txpriv.use_bg_rate)
wsm->maxTxRate = (u8)(t->txpriv.use_bg_rate & 0x3f);
else
wsm->maxTxRate = t->rate->hw_value;
if (t->rate->flags & IEEE80211_TX_RC_MCS) {
if (priv->association_mode.greenfieldMode)
wsm->htTxParameters |=
__cpu_to_le32(WSM_HT_TX_GREENFIELD);
else
wsm->htTxParameters |=
__cpu_to_le32(WSM_HT_TX_MIXED);
}
if (tx_policy_renew) {
txrx_printk(XRADIO_DBG_MSG, "[TX] TX policy renew.\n");
/* It's not so optimal to stop TX queues every now and then.
* Maybe it's better to reimplement task scheduling with
* a counter. */
/* xradio_tx_queues_lock(priv); */
/* Definetly better. TODO. */
if (atomic_add_return(1, &hw_priv->upload_count) == 1) {
wsm_lock_tx_async(hw_priv);
if (queue_work(hw_priv->workqueue,
&hw_priv->tx_policy_upload_work) <= 0) {
atomic_set(&hw_priv->upload_count, 0);
wsm_unlock_tx(hw_priv);
}
}
}
return 0;
}
static bool
xradio_tx_h_pm_state(struct xradio_vif *priv, struct xradio_txinfo *t)
{
int was_buffered = 1;
if (t->txpriv.link_id == priv->link_id_after_dtim &&
!priv->buffered_multicasts) {
priv->buffered_multicasts = true;
if (priv->sta_asleep_mask)
queue_work(priv->hw_priv->workqueue,
&priv->multicast_start_work);
}
if (t->txpriv.raw_link_id && t->txpriv.tid < XRADIO_MAX_TID)
was_buffered = priv->link_id_db[t->txpriv.raw_link_id - 1]
.buffered[t->txpriv.tid]++;
return !was_buffered;
}
static void
xradio_tx_h_ba_stat(struct xradio_vif *priv,
struct xradio_txinfo *t)
{
struct xradio_common *hw_priv = priv->hw_priv;
if (priv->join_status != XRADIO_JOIN_STATUS_STA)
return;
if (!xradio_is_ht(&hw_priv->ht_oper))
return;
if (!priv->setbssparams_done)
return;
if (!ieee80211_is_data(t->hdr->frame_control))
return;
spin_lock_bh(&hw_priv->ba_lock);
hw_priv->ba_acc += t->skb->len - t->hdrlen;
if (!(hw_priv->ba_cnt_rx || hw_priv->ba_cnt)) {
mod_timer(&hw_priv->ba_timer,
jiffies + XRADIO_BLOCK_ACK_INTERVAL);
}
hw_priv->ba_cnt++;
spin_unlock_bh(&hw_priv->ba_lock);
}
static int
xradio_tx_h_skb_pad(struct xradio_common *priv,
struct wsm_tx *wsm,
struct sk_buff *skb)
{
size_t len = __le16_to_cpu(wsm->hdr.len);
size_t padded_len = sdio_align_len(priv, len);
if (WARN_ON(skb_padto(skb, padded_len) != 0)) {
return -EINVAL;
}
return 0;
}
void xradio_tx(struct ieee80211_hw *dev, struct ieee80211_tx_control *control, struct sk_buff *skb)
{
struct xradio_common *hw_priv = dev->priv;
struct xradio_txinfo t = {
.skb = skb,
.queue = skb_get_queue_mapping(skb),
.tx_info = IEEE80211_SKB_CB(skb),
.hdr = (struct ieee80211_hdr *)skb->data,
.txpriv.tid = XRADIO_MAX_TID,
.txpriv.rate_id = XRADIO_INVALID_RATE_ID,
.txpriv.use_bg_rate = 0,
};
struct ieee80211_sta *sta;
struct wsm_tx *wsm;
bool tid_update = 0;
u8 flags = 0;
int ret = 0;
struct xradio_vif *priv;
struct ieee80211_hdr *frame = (struct ieee80211_hdr *)skb->data;
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
if (!skb->data)
BUG_ON(1);
if (!(t.tx_info->control.vif)) {
ret = __LINE__;
goto drop;
}
priv = xrwl_get_vif_from_ieee80211(t.tx_info->control.vif);
if (!priv) {
ret = __LINE__;
goto drop;