forked from mareksuscak/asus-pce-n53-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmm_data.c
2964 lines (2430 loc) · 76.7 KB
/
cmm_data.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
/*
*************************************************************************
* Ralink Tech Inc.
* 5F., No.36, Taiyuan St., Jhubei City,
* Hsinchu County 302,
* Taiwan, R.O.C.
*
* (c) Copyright 2002-2010, Ralink Technology, Inc.
*
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
*************************************************************************/
#include "rt_config.h"
UCHAR SNAP_802_1H[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
UCHAR SNAP_BRIDGE_TUNNEL[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
UCHAR EAPOL[] = {0x88, 0x8e};
UCHAR TPID[] = {0x81, 0x00}; /* VLAN related */
UCHAR IPX[] = {0x81, 0x37};
UCHAR APPLE_TALK[] = {0x80, 0xf3};
UCHAR OfdmRateToRxwiMCS[12] = {
0, 0, 0, 0,
0, 1, 2, 3, /* OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 */
4, 5, 6, 7, /* OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 */
};
UCHAR RxwiMCSToOfdmRate[12] = {
RATE_6, RATE_9, RATE_12, RATE_18,
RATE_24, RATE_36, RATE_48, RATE_54, /* OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 */
4, 5, 6, 7, /* OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 */
};
UCHAR MapUserPriorityToAccessCategory[8] = {QID_AC_BE, QID_AC_BK, QID_AC_BK, QID_AC_BE, QID_AC_VI, QID_AC_VI, QID_AC_VO, QID_AC_VO};
/*
========================================================================
Routine Description:
API for MLME to transmit management frame to AP (BSS Mode)
or station (IBSS Mode)
Arguments:
pAd Pointer to our adapter
pData Pointer to the outgoing 802.11 frame
Length Size of outgoing management frame
Return Value:
NDIS_STATUS_FAILURE
NDIS_STATUS_PENDING
NDIS_STATUS_SUCCESS
IRQL = PASSIVE_LEVEL
IRQL = DISPATCH_LEVEL
Note:
========================================================================
*/
NDIS_STATUS MiniportMMRequest(
IN PRTMP_ADAPTER pAd,
IN UCHAR QueIdx,
IN PUCHAR pData,
IN UINT Length)
{
PNDIS_PACKET pPacket;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
ULONG FreeNum;
UINT8 TXWISize = pAd->chipCap.TXWISize;
UCHAR rtmpHwHdr[TXINFO_SIZE + pAd->chipCap.TXWISize]; /*RTMP_HW_HDR_LEN];*/
#ifdef RTMP_MAC_PCI
unsigned long IrqFlags = 0;
// UCHAR IrqState;
#endif /* RTMP_MAC_PCI */
BOOLEAN bUseDataQ = FALSE, FlgDataQForce = FALSE, FlgIsLocked = FALSE;
int retryCnt = 0;
ASSERT(Length <= MGMT_DMA_BUFFER_SIZE);
if ((QueIdx & MGMT_USE_QUEUE_FLAG) == MGMT_USE_QUEUE_FLAG)
{
bUseDataQ = TRUE;
QueIdx &= (~MGMT_USE_QUEUE_FLAG);
}
#ifdef RTMP_MAC_PCI
/* 2860C use Tx Ring*/
// IrqState = pAd->irq_disabled;
if (pAd->MACVersion == 0x28600100)
{
/* do not care about the version */
// QueIdx = (bUseDataQ ==TRUE ? QueIdx : 3);
// bUseDataQ = TRUE;
}
if (bUseDataQ)
{
RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
FlgIsLocked = TRUE;
retryCnt = MAX_DATAMM_RETRY;
}
#endif /* RTMP_MAC_PCI */
do
{
/* Reset is in progress, stop immediately*/
if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)||
!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)
)
{
Status = NDIS_STATUS_FAILURE;
break;
}
#ifdef CONFIG_STA_SUPPORT
#endif /* CONFIG_STA_SUPPORT */
/* Check Free priority queue*/
/* Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing.*/
#ifdef RTMP_MAC_PCI
if (bUseDataQ)
{
/* free Tx(QueIdx) resources*/
RTMPFreeTXDUponTxDmaDone(pAd, QueIdx);
FreeNum = GET_TXRING_FREENO(pAd, QueIdx);
}
else
#endif /* RTMP_MAC_PCI */
{
FreeNum = GET_MGMTRING_FREENO(pAd);
}
if ((FreeNum > 0))
{
/* We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870*/
NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWISize));
Status = RTMPAllocateNdisPacket(pAd, &pPacket, (PUCHAR)&rtmpHwHdr, (TXINFO_SIZE + TXWISize), pData, Length);
if (Status != NDIS_STATUS_SUCCESS)
{
DBGPRINT(RT_DEBUG_WARN, ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n"));
break;
}
/*pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;*/
/*pAd->CommonCfg.MlmeRate = RATE_2;*/
#ifdef RTMP_MAC_PCI
if (bUseDataQ)
{
/* Status = MlmeDataHardTransmit(pAd, QueIdx, pPacket); */
FlgDataQForce = TRUE;
retryCnt--;
}
#endif /* RTMP_MAC_PCI */
Status = MlmeHardTransmit(pAd, QueIdx, pPacket, FlgDataQForce, FlgIsLocked);
if (Status == NDIS_STATUS_SUCCESS)
retryCnt = 0;
else
RELEASE_NDIS_PACKET(pAd, pPacket, Status);
}
else
{
pAd->RalinkCounters.MgmtRingFullCount++;
#ifdef RTMP_MAC_PCI
if (bUseDataQ)
{
retryCnt--;
DBGPRINT(RT_DEBUG_TRACE, ("retryCnt %d\n", retryCnt));
if (retryCnt == 0)
{
DBGPRINT(RT_DEBUG_ERROR, ("Qidx(%d), not enough space in DataRing, MgmtRingFullCount=%ld!\n",
QueIdx, pAd->RalinkCounters.MgmtRingFullCount));
}
}
#endif /* RTMP_MAC_PCI */
DBGPRINT(RT_DEBUG_ERROR, ("Qidx(%d), not enough space in MgmtRing, MgmtRingFullCount=%ld!\n",
QueIdx, pAd->RalinkCounters.MgmtRingFullCount));
}
} while (retryCnt > 0);
#ifdef RTMP_MAC_PCI
if (bUseDataQ)
RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
#endif /* RTMP_MAC_PCI */
return Status;
}
/*
========================================================================
Routine Description:
Copy frame from waiting queue into relative ring buffer and set
appropriate ASIC register to kick hardware transmit function
Arguments:
pAd Pointer to our adapter
pBuffer Pointer to memory of outgoing frame
Length Size of outgoing management frame
Return Value:
NDIS_STATUS_FAILURE
NDIS_STATUS_PENDING
NDIS_STATUS_SUCCESS
IRQL = PASSIVE_LEVEL
IRQL = DISPATCH_LEVEL
Note:
========================================================================
*/
NDIS_STATUS MlmeHardTransmit(
IN PRTMP_ADAPTER pAd,
IN UCHAR QueIdx,
IN PNDIS_PACKET pPacket,
IN BOOLEAN FlgDataQForce,
IN BOOLEAN FlgIsLocked)
{
PACKET_INFO PacketInfo;
PUCHAR pSrcBufVA;
UINT SrcBufLen;
if ((pAd->Dot11_H.RDMode != RD_NORMAL_MODE)
#ifdef CARRIER_DETECTION_SUPPORT
#endif /* CARRIER_DETECTION_SUPPORT */
)
{
return NDIS_STATUS_FAILURE;
}
RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
if (pSrcBufVA == NULL)
return NDIS_STATUS_FAILURE;
{
#ifdef RTMP_MAC_PCI
if ((pAd->MACVersion == 0x28600100) || (FlgDataQForce == TRUE))
return MlmeHardTransmitTxRing(pAd,QueIdx,pPacket);
else
#endif /* RTMP_MAC_PCI */
return MlmeHardTransmitMgmtRing(pAd,QueIdx,pPacket);
}
}
NDIS_STATUS MlmeHardTransmitMgmtRing(
IN PRTMP_ADAPTER pAd,
IN UCHAR QueIdx,
IN PNDIS_PACKET pPacket)
{
PACKET_INFO PacketInfo;
PUCHAR pSrcBufVA;
UINT SrcBufLen;
PHEADER_802_11 pHeader_802_11;
BOOLEAN bAckRequired, bInsertTimestamp;
UCHAR MlmeRate;
PTXWI_STRUC pFirstTxWI;
MAC_TABLE_ENTRY *pMacEntry = NULL;
UCHAR PID;
UINT8 TXWISize = pAd->chipCap.TXWISize;
RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
/* Make sure MGMT ring resource won't be used by other threads*/
RTMP_SEM_LOCK(&pAd->MgmtRingLock);
if (pSrcBufVA == NULL)
{
/* The buffer shouldn't be NULL*/
RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
return NDIS_STATUS_FAILURE;
}
#ifdef CONFIG_STA_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
{
/* outgoing frame always wakeup PHY to prevent frame lost*/
if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
AsicForceWakeup(pAd, TRUE);
}
#endif /* CONFIG_STA_SUPPORT */
pFirstTxWI = (PTXWI_STRUC)(pSrcBufVA + TXINFO_SIZE);
pHeader_802_11 = (PHEADER_802_11) (pSrcBufVA + TXINFO_SIZE + TXWISize);
if (pHeader_802_11->Addr1[0] & 0x01)
{
MlmeRate = pAd->CommonCfg.BasicMlmeRate;
}
else
{
MlmeRate = pAd->CommonCfg.MlmeRate;
}
/* Verify Mlme rate for a / g bands.*/
if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) /* 11A band*/
MlmeRate = RATE_6;
if ((pHeader_802_11->FC.Type == BTYPE_DATA) &&
(pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL))
{
pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1);
}
#ifdef CONFIG_STA_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
{
/* Fixed W52 with Activity scan issue in ABG_MIXED and ABGN_MIXED mode.*/
if (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED
#ifdef DOT11_N_SUPPORT
|| pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED
#endif /* DOT11_N_SUPPORT */
)
{
if (pAd->LatchRfRegs.Channel > 14)
pAd->CommonCfg.MlmeTransmit.field.MODE = 1;
else
pAd->CommonCfg.MlmeTransmit.field.MODE = 0;
}
}
#endif /* CONFIG_STA_SUPPORT */
/* Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE)*/
/* Snice it's been set to 0 while on MgtMacHeaderInit*/
/* By the way this will cause frame to be send on PWR_SAVE failed.*/
#ifdef CONFIG_STA_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
{
if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
{
/* We are in scan progress, just let the PwrMgmt bit keep as it orginally should be.*/
}
else
#endif /* CONFIG_STA_SUPPORT */
pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE; /* (pAd->StaCfg.Psm == PWR_SAVE);*/
#ifdef CONFIG_STA_SUPPORT
}
#endif /* CONFIG_STA_SUPPORT */
#ifdef CONFIG_STA_SUPPORT
/* In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame*/
/* Data-Null packets alse pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD*/
/* if ((pHeader_802_11->FC.Type != BTYPE_DATA) && (pHeader_802_11->FC.Type != BTYPE_CNTL))*/
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
{
if ((pHeader_802_11->FC.SubType == SUBTYPE_ACTION) ||
((pHeader_802_11->FC.Type == BTYPE_DATA) &&
((pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL) ||
(pHeader_802_11->FC.SubType == SUBTYPE_NULL_FUNC))))
{
if (RtmpPktPmBitCheck(pAd) == TRUE)
pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
INFRA_ON(pAd) &&
RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
{
/* We are in scan progress, just let the PwrMgmt bit keep as it orginally should be. */
}
else
{
pHeader_802_11->FC.PwrMgmt = pAd->CommonCfg.bAPSDForcePowerSave;
}
}
}
#endif /* CONFIG_STA_SUPPORT */
bInsertTimestamp = FALSE;
if (pHeader_802_11->FC.Type == BTYPE_CNTL) /* must be PS-POLL*/
{
#ifdef CONFIG_STA_SUPPORT
/*Set PM bit in ps-poll, to fix WLK 1.2 PowerSaveMode_ext failure issue.*/
if ((pAd->OpMode == OPMODE_STA) && (pHeader_802_11->FC.SubType == SUBTYPE_PS_POLL))
{
pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
}
#endif /* CONFIG_STA_SUPPORT */
bAckRequired = FALSE;
}
else /* BTYPE_MGMT or BTYPE_DATA(must be NULL frame)*/
{
if (pHeader_802_11->Addr1[0] & 0x01) /* MULTICAST, BROADCAST*/
{
bAckRequired = FALSE;
pHeader_802_11->Duration = 0;
}
else
{
bAckRequired = TRUE;
pHeader_802_11->Duration = RTMPCalcDuration(pAd, MlmeRate, 14);
if ((pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP) && (pHeader_802_11->FC.Type == BTYPE_MGMT))
{
bInsertTimestamp = TRUE;
bAckRequired = FALSE; /* Disable ACK to prevent retry 0x1f for Probe Response*/
}
else if ((pHeader_802_11->FC.SubType == SUBTYPE_PROBE_REQ) && (pHeader_802_11->FC.Type == BTYPE_MGMT))
{
bAckRequired = FALSE; /* Disable ACK to prevent retry 0x1f for Probe Request*/
}
}
}
pHeader_802_11->Sequence = pAd->Sequence++;
if (pAd->Sequence >0xfff)
pAd->Sequence = 0;
/* Before radar detection done, mgmt frame can not be sent but probe req*/
/* Because we need to use probe req to trigger driver to send probe req in passive scan*/
if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ)
&& (pAd->CommonCfg.bIEEE80211H == 1)
&& (pAd->Dot11_H.RDMode != RD_NORMAL_MODE))
{
DBGPRINT(RT_DEBUG_ERROR,("MlmeHardTransmit --> radar detect not in normal mode !!!\n"));
/* if (!IrqState)*/
RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
return (NDIS_STATUS_FAILURE);
}
#ifdef RT_BIG_ENDIAN
RTMPFrameEndianChange(pAd, (PUCHAR)pHeader_802_11, DIR_WRITE, FALSE);
#endif
/* fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET*/
/* should always has only one physical buffer, and the whole frame size equals*/
/* to the first scatter buffer size*/
/*
Initialize TX Descriptor
For inter-frame gap, the number is for this frame and next frame
For MLME rate, we will fix as 2Mb to match other vendor's implement
*/
/*pAd->CommonCfg.MlmeTransmit.field.MODE = 1;*/
/*
management frame doesn't need encryption.
so use RESERVED_WCID no matter u are sending to specific wcid or not
*/
PID = PID_MGMT;
if (pMacEntry == NULL)
{
RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp, FALSE, bAckRequired, FALSE,
0, RESERVED_WCID, (SrcBufLen - TXINFO_SIZE - TXWISize), PID, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
}
else
{
/* dont use low rate to send QoS Null data frame */
RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE,
bInsertTimestamp, FALSE, bAckRequired, FALSE,
0, pMacEntry->Aid, (SrcBufLen - TXINFO_SIZE - TXWISize),
pMacEntry->MaxHTPhyMode.field.MCS, 0,
(UCHAR)pMacEntry->MaxHTPhyMode.field.MCS,
IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode);
}
#ifdef RT_BIG_ENDIAN
RTMPWIEndianChange(pAd, (PUCHAR)pFirstTxWI, TYPE_TXWI);
#endif
/* Now do hardware-depened kick out.*/
HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen);
/* Make sure to release MGMT ring resource*/
/* if (!IrqState)*/
RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
return NDIS_STATUS_SUCCESS;
}
/********************************************************************************
New DeQueue Procedures.
********************************************************************************/
#define DEQUEUE_LOCK(lock, bIntContext, IrqFlags) \
do{ \
if (bIntContext == FALSE) \
RTMP_IRQ_LOCK((lock), IrqFlags); \
}while(0)
#define DEQUEUE_UNLOCK(lock, bIntContext, IrqFlags) \
do{ \
if (bIntContext == FALSE) \
RTMP_IRQ_UNLOCK((lock), IrqFlags); \
}while(0)
/*
========================================================================
Tx Path design algorithm:
Basically, we divide the packets into four types, Broadcast/Multicast, 11N Rate(AMPDU, AMSDU, Normal), B/G Rate(ARALINK, Normal),
Specific Packet Type. Following show the classification rule and policy for each kinds of packets.
Classification Rule=>
Multicast: (*addr1 & 0x01) == 0x01
Specific : bDHCPFrame, bARPFrame, bEAPOLFrame, etc.
11N Rate : If peer support HT
(1).AMPDU -- If TXBA is negotiated.
(2).AMSDU -- If AMSDU is capable for both peer and ourself.
*). AMSDU can embedded in a AMPDU, but now we didn't support it.
(3).Normal -- Other packets which send as 11n rate.
B/G Rate : If peer is b/g only.
(1).ARALINK-- If both of peer/us supprot Ralink proprietary Aggregation and the TxRate is large than RATE_6
(2).Normal -- Other packets which send as b/g rate.
Fragment:
The packet must be unicast, NOT A-RALINK, NOT A-MSDU, NOT 11n, then can consider about fragment.
Classified Packet Handle Rule=>
Multicast:
No ACK, pTxBlk->bAckRequired = FALSE;
No WMM, pTxBlk->bWMM = FALSE;
No piggyback, pTxBlk->bPiggyBack = FALSE;
Force LowRate, pTxBlk->bForceLowRate = TRUE;
Specific : Basically, for specific packet, we should handle it specifically, but now all specific packets are use
the same policy to handle it.
Force LowRate, pTxBlk->bForceLowRate = TRUE;
11N Rate :
No piggyback, pTxBlk->bPiggyBack = FALSE;
(1).AMSDU
pTxBlk->bWMM = TRUE;
(2).AMPDU
pTxBlk->bWMM = TRUE;
(3).Normal
B/G Rate :
(1).ARALINK
(2).Normal
========================================================================
*/
static UCHAR TxPktClassification(
IN RTMP_ADAPTER *pAd,
IN PNDIS_PACKET pPacket)
{
UCHAR TxFrameType = TX_UNKOWN_FRAME;
UCHAR Wcid;
MAC_TABLE_ENTRY *pMacEntry = NULL;
#ifdef DOT11_N_SUPPORT
BOOLEAN bHTRate = FALSE;
#endif /* DOT11_N_SUPPORT */
Wcid = RTMP_GET_PACKET_WCID(pPacket);
if (Wcid == MCAST_WCID)
{ /* Handle for RA is Broadcast/Multicast Address.*/
return TX_MCAST_FRAME;
}
/* Handle for unicast packets*/
pMacEntry = &pAd->MacTab.Content[Wcid];
if (RTMP_GET_PACKET_LOWRATE(pPacket))
{ /* It's a specific packet need to force low rate, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame*/
TxFrameType = TX_LEGACY_FRAME;
}
#ifdef DOT11_N_SUPPORT
else if (IS_HT_RATE(pMacEntry))
{ /* it's a 11n capable packet*/
/* Depends on HTPhyMode to check if the peer support the HTRate transmission.*/
/* Currently didn't support A-MSDU embedded in A-MPDU*/
bHTRate = TRUE;
if (RTMP_GET_PACKET_MOREDATA(pPacket) || (pMacEntry->PsMode == PWR_SAVE))
TxFrameType = TX_LEGACY_FRAME;
#ifdef UAPSD_SUPPORT
else if (RTMP_GET_PACKET_EOSP(pPacket))
TxFrameType = TX_LEGACY_FRAME;
#endif /* UAPSD_SUPPORT */
else if((pMacEntry->TXBAbitmap & (1<<(RTMP_GET_PACKET_UP(pPacket)))) != 0)
return TX_AMPDU_FRAME;
else if(CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AMSDU_INUSED))
return TX_AMSDU_FRAME;
else
TxFrameType = TX_LEGACY_FRAME;
}
#endif /* DOT11_N_SUPPORT */
else
{ /* it's a legacy b/g packet.*/
if ((CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE) && pAd->CommonCfg.bAggregationCapable) &&
(RTMP_GET_PACKET_TXRATE(pPacket) >= RATE_6) &&
(!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))))
{ /* if peer support Ralink Aggregation, we use it.*/
TxFrameType = TX_RALINK_FRAME;
}
else
{
TxFrameType = TX_LEGACY_FRAME;
}
}
/* Currently, our fragment only support when a unicast packet send as NOT-ARALINK, NOT-AMSDU and NOT-AMPDU.*/
if ((RTMP_GET_PACKET_FRAGMENTS(pPacket) > 1)
&& (TxFrameType == TX_LEGACY_FRAME)
#ifdef DOT11_N_SUPPORT
&& ((pMacEntry->TXBAbitmap & (1<<(RTMP_GET_PACKET_UP(pPacket)))) == 0)
#endif /* DOT11_N_SUPPORT */
)
TxFrameType = TX_FRAG_FRAME;
return TxFrameType;
}
BOOLEAN RTMP_FillTxBlkInfo(
IN RTMP_ADAPTER *pAd,
IN TX_BLK *pTxBlk)
{
PACKET_INFO PacketInfo;
PNDIS_PACKET pPacket;
PMAC_TABLE_ENTRY pMacEntry = NULL;
pPacket = pTxBlk->pPacket;
RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen);
pTxBlk->Wcid = RTMP_GET_PACKET_WCID(pPacket);
pTxBlk->apidx = RTMP_GET_PACKET_IF(pPacket);
pTxBlk->UserPriority = RTMP_GET_PACKET_UP(pPacket);
pTxBlk->FrameGap = IFS_HTTXOP; /* ASIC determine Frame Gap*/
if (RTMP_GET_PACKET_CLEAR_EAP_FRAME(pTxBlk->pPacket))
TX_BLK_SET_FLAG(pTxBlk, fTX_bClearEAPFrame);
else
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bClearEAPFrame);
/* Default to clear this flag*/
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bForceNonQoS);
if (pTxBlk->Wcid == MCAST_WCID)
{
pTxBlk->pMacEntry = NULL;
{
#ifdef MCAST_RATE_SPECIFIC
PUCHAR pDA = GET_OS_PKT_DATAPTR(pPacket);
if (((*pDA & 0x01) == 0x01) && (*pDA != 0xff))
pTxBlk->pTransmit = &pAd->CommonCfg.MCastPhyMode;
else
#endif /* MCAST_RATE_SPECIFIC */
pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
}
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); /* AckRequired = FALSE, when broadcast packet in Adhoc mode.*/
/*TX_BLK_SET_FLAG(pTxBlk, fTX_bForceLowRate);*/
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAllowFrag);
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
if (RTMP_GET_PACKET_MOREDATA(pPacket))
{
TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
}
}
else
{
pTxBlk->pMacEntry = &pAd->MacTab.Content[pTxBlk->Wcid];
pTxBlk->pTransmit = &pTxBlk->pMacEntry->HTPhyMode;
pMacEntry = pTxBlk->pMacEntry;
/* For all unicast packets, need Ack unless the Ack Policy is not set as NORMAL_ACK.*/
if (pAd->CommonCfg.AckPolicy[pTxBlk->QueIdx] != NORMAL_ACK)
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired);
else
TX_BLK_SET_FLAG(pTxBlk, fTX_bAckRequired);
#ifdef CONFIG_STA_SUPPORT
#ifdef XLINK_SUPPORT
if ((pAd->OpMode == OPMODE_STA) &&
(ADHOC_ON(pAd)) /*&&
(RX_FILTER_TEST_FLAG(pAd, fRX_FILTER_ACCEPT_PROMISCUOUS))*/)
{
if(pAd->StaCfg.PSPXlink)
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired);
}
#endif /* XLINK_SUPPORT */
#endif /* CONFIG_STA_SUPPORT */
{
#ifdef CONFIG_STA_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
{
/* If support WMM, enable it.*/
if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))
TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM);
/* if (pAd->StaCfg.bAutoTxRateSwitch)*/
/* TX_BLK_SET_FLAG(pTxBlk, fTX_AutoRateSwitch);*/
}
#endif /* CONFIG_STA_SUPPORT */
}
if (pTxBlk->TxFrameType == TX_LEGACY_FRAME)
{
if ( (RTMP_GET_PACKET_LOWRATE(pPacket)) ||
((pAd->OpMode == OPMODE_AP) && (pMacEntry->MaxHTPhyMode.field.MODE == MODE_CCK) && (pMacEntry->MaxHTPhyMode.field.MCS == RATE_1)))
{ /* Specific packet, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame, need force low rate.*/
pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
#ifdef DOT11_N_SUPPORT
/* Modify the WMM bit for ICV issue. If we have a packet with EOSP field need to set as 1, how to handle it???*/
if (IS_HT_STA(pTxBlk->pMacEntry) &&
(CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RALINK_CHIPSET)) &&
((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RDG_CAPABLE)))
{
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
TX_BLK_SET_FLAG(pTxBlk, fTX_bForceNonQoS);
}
#endif /* DOT11_N_SUPPORT */
}
#ifdef DOT11_N_SUPPORT
if ( (IS_HT_RATE(pMacEntry) == FALSE) &&
(CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE)))
{ /* Currently piggy-back only support when peer is operate in b/g mode.*/
TX_BLK_SET_FLAG(pTxBlk, fTX_bPiggyBack);
}
#endif /* DOT11_N_SUPPORT */
if (RTMP_GET_PACKET_MOREDATA(pPacket))
{
TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
}
#ifdef UAPSD_SUPPORT
if (RTMP_GET_PACKET_EOSP(pPacket))
{
TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM_UAPSD_EOSP);
}
#endif /* UAPSD_SUPPORT */
}
else if (pTxBlk->TxFrameType == TX_FRAG_FRAME)
{
TX_BLK_SET_FLAG(pTxBlk, fTX_bAllowFrag);
}
pMacEntry->DebugTxCount++;
}
pAd->LastTxRate = (USHORT)pTxBlk->pTransmit->word;
return TRUE;
}
BOOLEAN CanDoAggregateTransmit(
IN RTMP_ADAPTER *pAd,
IN NDIS_PACKET *pPacket,
IN TX_BLK *pTxBlk)
{
int minLen = LENGTH_802_3;
/*DBGPRINT(RT_DEBUG_TRACE, ("Check if can do aggregation! TxFrameType=%d!\n", pTxBlk->TxFrameType));*/
if (RTMP_GET_PACKET_WCID(pPacket) == MCAST_WCID)
return FALSE;
if (RTMP_GET_PACKET_DHCP(pPacket) ||
RTMP_GET_PACKET_EAPOL(pPacket) ||
RTMP_GET_PACKET_WAI(pPacket))
return FALSE;
/* Make sure the first packet has non-zero-length data payload */
if (RTMP_GET_PACKET_VLAN(pPacket))
minLen += LENGTH_802_1Q; /* VLAN tag */
else if (RTMP_GET_PACKET_LLCSNAP(pPacket))
minLen += 8; /* SNAP hdr Len*/
if (minLen >= GET_OS_PKT_LEN(pPacket))
return FALSE;
if ((pTxBlk->TxFrameType == TX_AMSDU_FRAME) &&
((pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))> (RX_BUFFER_AGGRESIZE - 100)))
{ /* For AMSDU, allow the packets with total length < max-amsdu size*/
return FALSE;
}
if ((pTxBlk->TxFrameType == TX_RALINK_FRAME) &&
(pTxBlk->TxPacketList.Number == 2))
{ /* For RALINK-Aggregation, allow two frames in one batch.*/
return FALSE;
}
#ifdef CONFIG_STA_SUPPORT
if ((INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) /* must be unicast to AP*/
return TRUE;
else
#endif /* CONFIG_STA_SUPPORT */
return FALSE;
}
/*
========================================================================
Routine Description:
To do the enqueue operation and extract the first item of waiting
list. If a number of available shared memory segments could meet
the request of extracted item, the extracted item will be fragmented
into shared memory segments.
Arguments:
pAd Pointer to our adapter
pQueue Pointer to Waiting Queue
Return Value:
None
IRQL = DISPATCH_LEVEL
Note:
========================================================================
*/
VOID RTMPDeQueuePacket(
IN PRTMP_ADAPTER pAd,
IN BOOLEAN bIntContext,
IN UCHAR QIdx, /* BulkOutPipeId */
IN UCHAR Max_Tx_Packets)
{
PQUEUE_ENTRY pEntry = NULL;
PNDIS_PACKET pPacket;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
UCHAR Count=0;
PQUEUE_HEADER pQueue;
ULONG FreeNumber[NUM_OF_TX_RING];
UCHAR QueIdx, sQIdx, eQIdx;
unsigned long IrqFlags = 0;
BOOLEAN hasTxDesc = FALSE;
TX_BLK TxBlk;
TX_BLK *pTxBlk;
#ifdef DBG_DIAGNOSE
BOOLEAN firstRound;
RtmpDiagStruct *pDiagStruct = &pAd->DiagStruct;
#endif
if (QIdx == NUM_OF_TX_RING)
{
sQIdx = 0;
eQIdx = 3; /* 4 ACs, start from 0.*/
}
else
{
sQIdx = eQIdx = QIdx;
}
for (QueIdx=sQIdx; QueIdx <= eQIdx; QueIdx++)
{
Count=0;
RTMP_START_DEQUEUE(pAd, QueIdx, IrqFlags);
#ifdef DBG_DIAGNOSE
firstRound = ((QueIdx == 0) ? TRUE : FALSE);
#endif /* DBG_DIAGNOSE */
while (1)
{
if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS |
fRTMP_ADAPTER_RADIO_OFF |
fRTMP_ADAPTER_RESET_IN_PROGRESS |
fRTMP_ADAPTER_HALT_IN_PROGRESS |
fRTMP_ADAPTER_NIC_NOT_EXIST)))
)
{
RTMP_STOP_DEQUEUE(pAd, QueIdx, IrqFlags);
return;
}
if (Count >= Max_Tx_Packets)
break;
DEQUEUE_LOCK(&pAd->irq_lock, bIntContext, IrqFlags);
if (&pAd->TxSwQueue[QueIdx] == NULL)
{
#ifdef DBG_DIAGNOSE
if (firstRound == TRUE)
pDiagStruct->TxSWQueCnt[pDiagStruct->ArrayCurIdx][0]++;
#endif /* DBG_DIAGNOSE */
DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
break;
}
#ifdef RTMP_MAC_PCI
FreeNumber[QueIdx] = GET_TXRING_FREENO(pAd, QueIdx);
#ifdef DBG_DIAGNOSE
if (firstRound == TRUE)
{
UCHAR txDescNumLevel, txSwQNumLevel;
txDescNumLevel = (TX_RING_SIZE - FreeNumber[QueIdx]); /* Number of occupied hw desc.*/
txDescNumLevel = ((txDescNumLevel <=15) ? txDescNumLevel : 15);
pDiagStruct->TxDescCnt[pDiagStruct->ArrayCurIdx][txDescNumLevel]++;
txSwQNumLevel = ((pAd->TxSwQueue[QueIdx].Number <=7) ? pAd->TxSwQueue[QueIdx].Number : 8);
pDiagStruct->TxSWQueCnt[pDiagStruct->ArrayCurIdx][txSwQNumLevel]++;
firstRound = FALSE;
}
#endif /* DBG_DIAGNOSE */
if (FreeNumber[QueIdx] <= 5)
{
/* free Tx(QueIdx) resources*/
RTMPFreeTXDUponTxDmaDone(pAd, QueIdx);
FreeNumber[QueIdx] = GET_TXRING_FREENO(pAd, QueIdx);
}
#endif /* RTMP_MAC_PCI */
/* probe the Queue Head*/
pQueue = &pAd->TxSwQueue[QueIdx];
if ((pEntry = pQueue->Head) == NULL)
{
DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
break;
}
pTxBlk = &TxBlk;
NdisZeroMemory((PUCHAR)pTxBlk, sizeof(TX_BLK));
/*InitializeQueueHeader(&pTxBlk->TxPacketList); Didn't need it because we already memzero it.*/
pTxBlk->QueIdx = QueIdx;
#ifdef VENDOR_FEATURE1_SUPPORT
pTxBlk->HeaderBuf = (UCHAR *)pTxBlk->HeaderBuffer;
#endif /* VENDOR_FEATURE1_SUPPORT */
pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
/* Early check to make sure we have enoguh Tx Resource.*/
hasTxDesc = RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, FreeNumber[QueIdx], pPacket);
if (!hasTxDesc)
{
pAd->PrivateInfo.TxRingFullCnt++;
DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
break;
}
pTxBlk->TxFrameType = TxPktClassification(pAd, pPacket);
pEntry = RemoveHeadQueue(pQueue);
pTxBlk->TotalFrameNum++;
pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); /* The real fragment number maybe vary*/
pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket);
pTxBlk->pPacket = pPacket;
InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket));
if (pTxBlk->TxFrameType == TX_RALINK_FRAME || pTxBlk->TxFrameType == TX_AMSDU_FRAME)
{
// Enhance SW Aggregation Mechanism
if (NEED_QUEUE_BACK_FOR_AGG(pAd, QueIdx, FreeNumber[QueIdx], pTxBlk->TxFrameType))
{
InsertHeadQueue(pQueue, PACKET_TO_QUEUE_ENTRY(pPacket));
DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
break;
}
}
if (pTxBlk->TxFrameType == TX_RALINK_FRAME || pTxBlk->TxFrameType == TX_AMSDU_FRAME)
{
// Enhance SW Aggregation Mechanism