1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
8 #include "rtl819x_HT.h"
9 u8 MCS_FILTER_ALL[16] = {
10 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
11 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
14 u8 MCS_FILTER_1SS[16] = {
15 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
16 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
19 u16 MCS_DATA_RATE[2][2][77] = {
20 {{13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234,
21 260, 39, 78, 117, 234, 312, 351, 390, 52, 104, 156, 208, 312, 416,
22 468, 520, 0, 78, 104, 130, 117, 156, 195, 104, 130, 130, 156, 182,
23 182, 208, 156, 195, 195, 234, 273, 273, 312, 130, 156, 181, 156,
24 181, 208, 234, 208, 234, 260, 260, 286, 195, 234, 273, 234, 273,
25 312, 351, 312, 351, 390, 390, 429},
26 {14, 29, 43, 58, 87, 116, 130, 144, 29, 58, 87, 116, 173, 231, 260, 289,
27 43, 87, 130, 173, 260, 347, 390, 433, 58, 116, 173, 231, 347, 462, 520,
28 578, 0, 87, 116, 144, 130, 173, 217, 116, 144, 144, 173, 202, 202, 231,
29 173, 217, 217, 260, 303, 303, 347, 144, 173, 202, 173, 202, 231, 260,
30 231, 260, 289, 289, 318, 217, 260, 303, 260, 303, 347, 390, 347, 390,
32 {{27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486,
33 540, 81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648,
34 864, 972, 1080, 12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324,
35 378, 378, 432, 324, 405, 405, 486, 567, 567, 648, 270, 324, 378, 324,
36 378, 432, 486, 432, 486, 540, 540, 594, 405, 486, 567, 486, 567, 648,
37 729, 648, 729, 810, 810, 891},
38 {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540,
39 600, 90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720,
40 960, 1080, 1200, 13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360,
41 420, 420, 480, 360, 450, 450, 540, 630, 630, 720, 300, 360, 420, 360,
42 420, 480, 540, 480, 540, 600, 600, 660, 450, 540, 630, 540, 630, 720,
43 810, 720, 810, 900, 900, 990} }
46 static u8 UNKNOWN_BORADCOM[3] = {0x00, 0x14, 0xbf};
48 static u8 LINKSYSWRT330_LINKSYSWRT300_BROADCOM[3] = {0x00, 0x1a, 0x70};
50 static u8 LINKSYSWRT350_LINKSYSWRT150_BROADCOM[3] = {0x00, 0x1d, 0x7e};
52 static u8 BELKINF5D8233V1_RALINK[3] = {0x00, 0x17, 0x3f};
54 static u8 BELKINF5D82334V3_RALINK[3] = {0x00, 0x1c, 0xdf};
56 static u8 PCI_RALINK[3] = {0x00, 0x90, 0xcc};
58 static u8 EDIMAX_RALINK[3] = {0x00, 0x0e, 0x2e};
60 static u8 AIRLINK_RALINK[3] = {0x00, 0x18, 0x02};
62 static u8 DLINK_ATHEROS_1[3] = {0x00, 0x1c, 0xf0};
64 static u8 DLINK_ATHEROS_2[3] = {0x00, 0x21, 0x91};
66 static u8 CISCO_BROADCOM[3] = {0x00, 0x17, 0x94};
68 static u8 LINKSYS_MARVELL_4400N[3] = {0x00, 0x14, 0xa4};
70 void HTUpdateDefaultSetting(struct rtllib_device *ieee)
72 struct rt_hi_throughput *ht_info = ieee->ht_info;
74 ht_info->bRegShortGI20MHz = 1;
75 ht_info->bRegShortGI40MHz = 1;
77 ht_info->bRegBW40MHz = 1;
79 if (ht_info->bRegBW40MHz)
80 ht_info->bRegSuppCCK = 1;
82 ht_info->bRegSuppCCK = true;
84 ht_info->nAMSDU_MaxSize = 7935UL;
85 ht_info->bAMSDU_Support = 0;
87 ht_info->bAMPDUEnable = 1;
88 ht_info->AMPDU_Factor = 2;
89 ht_info->MPDU_Density = 0;
91 ht_info->self_mimo_ps = 3;
92 if (ht_info->self_mimo_ps == 2)
93 ht_info->self_mimo_ps = 3;
94 ieee->tx_dis_rate_fallback = 0;
95 ieee->tx_use_drv_assinged_rate = 0;
97 ieee->bTxEnableFwCalcDur = 1;
99 ht_info->reg_rt2rt_aggregation = 1;
101 ht_info->reg_rx_reorder_enable = 1;
102 ht_info->rx_reorder_win_size = 64;
103 ht_info->rx_reorder_pending_time = 30;
106 static u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate)
108 struct rt_hi_throughput *ht_info = ieee->ht_info;
110 u8 is40MHz = (ht_info->bCurBW40MHz) ? 1 : 0;
111 u8 isShortGI = (ht_info->bCurBW40MHz) ?
112 ((ht_info->bCurShortGI40MHz) ? 1 : 0) :
113 ((ht_info->bCurShortGI20MHz) ? 1 : 0);
114 return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate & 0x7f)];
117 u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate)
119 u16 CCKOFDMRate[12] = {0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18,
120 0x24, 0x30, 0x48, 0x60, 0x6c};
125 return CCKOFDMRate[nDataRate];
126 if (nDataRate >= 0x10 && nDataRate <= 0x1f) {
129 } else if (nDataRate >= 0x20 && nDataRate <= 0x2f) {
132 } else if (nDataRate >= 0x30 && nDataRate <= 0x3f) {
135 } else if (nDataRate >= 0x40 && nDataRate <= 0x4f) {
139 return MCS_DATA_RATE[is40MHz][isShortGI][nDataRate & 0xf];
142 bool IsHTHalfNmodeAPs(struct rtllib_device *ieee)
144 bool retValue = false;
145 struct rtllib_network *net = &ieee->current_network;
147 if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) ||
148 (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) ||
149 (memcmp(net->bssid, PCI_RALINK, 3) == 0) ||
150 (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) ||
151 (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) ||
152 (net->ralink_cap_exist))
154 else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) ||
155 !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) ||
156 !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) ||
157 (net->broadcom_cap_exist))
159 else if (net->bssht.bd_rt2rt_aggregation)
167 static void HTIOTPeerDetermine(struct rtllib_device *ieee)
169 struct rt_hi_throughput *ht_info = ieee->ht_info;
170 struct rtllib_network *net = &ieee->current_network;
172 if (net->bssht.bd_rt2rt_aggregation) {
173 ht_info->IOTPeer = HT_IOT_PEER_REALTEK;
174 if (net->bssht.rt2rt_ht_mode & RT_HT_CAP_USE_92SE)
175 ht_info->IOTPeer = HT_IOT_PEER_REALTEK_92SE;
176 if (net->bssht.rt2rt_ht_mode & RT_HT_CAP_USE_SOFTAP)
177 ht_info->IOTPeer = HT_IOT_PEER_92U_SOFTAP;
178 } else if (net->broadcom_cap_exist) {
179 ht_info->IOTPeer = HT_IOT_PEER_BROADCOM;
180 } else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) ||
181 !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) ||
182 !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)) {
183 ht_info->IOTPeer = HT_IOT_PEER_BROADCOM;
184 } else if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) ||
185 (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) ||
186 (memcmp(net->bssid, PCI_RALINK, 3) == 0) ||
187 (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) ||
188 (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) ||
189 net->ralink_cap_exist) {
190 ht_info->IOTPeer = HT_IOT_PEER_RALINK;
191 } else if ((net->atheros_cap_exist) ||
192 (memcmp(net->bssid, DLINK_ATHEROS_1, 3) == 0) ||
193 (memcmp(net->bssid, DLINK_ATHEROS_2, 3) == 0)) {
194 ht_info->IOTPeer = HT_IOT_PEER_ATHEROS;
195 } else if ((memcmp(net->bssid, CISCO_BROADCOM, 3) == 0) ||
196 net->cisco_cap_exist) {
197 ht_info->IOTPeer = HT_IOT_PEER_CISCO;
198 } else if ((memcmp(net->bssid, LINKSYS_MARVELL_4400N, 3) == 0) ||
199 net->marvell_cap_exist) {
200 ht_info->IOTPeer = HT_IOT_PEER_MARVELL;
201 } else if (net->airgo_cap_exist) {
202 ht_info->IOTPeer = HT_IOT_PEER_AIRGO;
204 ht_info->IOTPeer = HT_IOT_PEER_UNKNOWN;
207 netdev_dbg(ieee->dev, "IOTPEER: %x\n", ht_info->IOTPeer);
210 static u8 HTIOTActIsDisableMCS14(struct rtllib_device *ieee, u8 *PeerMacAddr)
215 static bool HTIOTActIsDisableMCS15(struct rtllib_device *ieee)
220 static bool HTIOTActIsDisableMCSTwoSpatialStream(struct rtllib_device *ieee)
225 static u8 HTIOTActIsDisableEDCATurbo(struct rtllib_device *ieee,
231 static u8 HTIOTActIsMgntUseCCK6M(struct rtllib_device *ieee,
232 struct rtllib_network *network)
236 if (ieee->ht_info->IOTPeer == HT_IOT_PEER_BROADCOM)
242 static u8 HTIOTActIsCCDFsync(struct rtllib_device *ieee)
246 if (ieee->ht_info->IOTPeer == HT_IOT_PEER_BROADCOM)
251 static void HTIOTActDetermineRaFunc(struct rtllib_device *ieee, bool bPeerRx2ss)
253 struct rt_hi_throughput *ht_info = ieee->ht_info;
255 ht_info->iot_ra_func &= HT_IOT_RAFUNC_DISABLE_ALL;
257 if (ht_info->IOTPeer == HT_IOT_PEER_RALINK && !bPeerRx2ss)
258 ht_info->iot_ra_func |= HT_IOT_RAFUNC_PEER_1R;
260 if (ht_info->iot_action & HT_IOT_ACT_AMSDU_ENABLE)
261 ht_info->iot_ra_func |= HT_IOT_RAFUNC_TX_AMSDU;
264 void HTResetIOTSetting(struct rt_hi_throughput *ht_info)
266 ht_info->iot_action = 0;
267 ht_info->IOTPeer = HT_IOT_PEER_UNKNOWN;
268 ht_info->iot_ra_func = 0;
271 void HTConstructCapabilityElement(struct rtllib_device *ieee, u8 *posHTCap,
272 u8 *len, u8 IsEncrypt, bool bAssoc)
274 struct rt_hi_throughput *pHT = ieee->ht_info;
275 struct ht_capab_ele *pCapELE = NULL;
277 if (!posHTCap || !pHT) {
278 netdev_warn(ieee->dev,
279 "%s(): posHTCap and ht_info are null\n", __func__);
282 memset(posHTCap, 0, *len);
284 if ((bAssoc) && (pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)) {
285 static const u8 EWC11NHTCap[] = { 0x00, 0x90, 0x4c, 0x33 };
287 memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap));
288 pCapELE = (struct ht_capab_ele *)&posHTCap[4];
291 pCapELE = (struct ht_capab_ele *)posHTCap;
295 pCapELE->AdvCoding = 0;
296 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
297 pCapELE->ChlWidth = 0;
299 pCapELE->ChlWidth = (pHT->bRegBW40MHz ? 1 : 0);
301 pCapELE->MimoPwrSave = pHT->self_mimo_ps;
302 pCapELE->GreenField = 0;
303 pCapELE->ShortGI20Mhz = 1;
304 pCapELE->ShortGI40Mhz = 1;
308 pCapELE->DelayBA = 0;
309 pCapELE->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0;
310 pCapELE->DssCCk = ((pHT->bRegBW40MHz) ? (pHT->bRegSuppCCK ? 1 : 0) : 0);
312 pCapELE->LSigTxopProtect = 0;
314 netdev_dbg(ieee->dev,
315 "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n",
316 pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk);
319 pCapELE->MPDUDensity = 7;
320 pCapELE->MaxRxAMPDUFactor = 2;
322 pCapELE->MaxRxAMPDUFactor = 3;
323 pCapELE->MPDUDensity = 0;
326 memcpy(pCapELE->MCS, ieee->reg_dot11ht_oper_rate_set, 16);
327 memset(&pCapELE->ExtHTCapInfo, 0, 2);
328 memset(pCapELE->TxBFCap, 0, 4);
333 if (pHT->iot_action & HT_IOT_ACT_DISABLE_MCS15)
334 pCapELE->MCS[1] &= 0x7f;
336 if (pHT->iot_action & HT_IOT_ACT_DISABLE_MCS14)
337 pCapELE->MCS[1] &= 0xbf;
339 if (pHT->iot_action & HT_IOT_ACT_DISABLE_ALL_2SS)
340 pCapELE->MCS[1] &= 0x00;
342 if (pHT->iot_action & HT_IOT_ACT_DISABLE_RX_40MHZ_SHORT_GI)
343 pCapELE->ShortGI40Mhz = 0;
345 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) {
346 pCapELE->ChlWidth = 0;
352 void HTConstructInfoElement(struct rtllib_device *ieee, u8 *posHTInfo,
353 u8 *len, u8 IsEncrypt)
355 struct rt_hi_throughput *pHT = ieee->ht_info;
356 struct ht_info_ele *pHTInfoEle = (struct ht_info_ele *)posHTInfo;
358 if (!posHTInfo || !pHTInfoEle) {
359 netdev_warn(ieee->dev,
360 "%s(): posHTInfo and pHTInfoEle are null\n",
365 memset(posHTInfo, 0, *len);
366 if ((ieee->iw_mode == IW_MODE_ADHOC) ||
367 (ieee->iw_mode == IW_MODE_MASTER)) {
368 pHTInfoEle->ControlChl = ieee->current_network.channel;
369 pHTInfoEle->ExtChlOffset = ((!pHT->bRegBW40MHz) ?
370 HT_EXTCHNL_OFFSET_NO_EXT :
371 (ieee->current_network.channel <= 6)
372 ? HT_EXTCHNL_OFFSET_UPPER :
373 HT_EXTCHNL_OFFSET_LOWER);
374 pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz;
375 pHTInfoEle->RIFS = 0;
376 pHTInfoEle->PSMPAccessOnly = 0;
377 pHTInfoEle->SrvIntGranularity = 0;
378 pHTInfoEle->OptMode = pHT->current_op_mode;
379 pHTInfoEle->NonGFDevPresent = 0;
380 pHTInfoEle->DualBeacon = 0;
381 pHTInfoEle->SecondaryBeacon = 0;
382 pHTInfoEle->LSigTxopProtectFull = 0;
383 pHTInfoEle->PcoActive = 0;
384 pHTInfoEle->PcoPhase = 0;
386 memset(pHTInfoEle->BasicMSC, 0, 16);
395 void HTConstructRT2RTAggElement(struct rtllib_device *ieee, u8 *posRT2RTAgg,
399 netdev_warn(ieee->dev, "%s(): posRT2RTAgg is null\n", __func__);
402 memset(posRT2RTAgg, 0, *len);
403 *posRT2RTAgg++ = 0x00;
404 *posRT2RTAgg++ = 0xe0;
405 *posRT2RTAgg++ = 0x4c;
406 *posRT2RTAgg++ = 0x02;
407 *posRT2RTAgg++ = 0x01;
411 if (ieee->bSupportRemoteWakeUp)
412 *posRT2RTAgg |= RT_HT_CAP_USE_WOW;
417 static u8 HT_PickMCSRate(struct rtllib_device *ieee, u8 *pOperateMCS)
422 netdev_warn(ieee->dev, "%s(): pOperateMCS is null\n", __func__);
426 switch (ieee->mode) {
430 for (i = 0; i <= 15; i++)
435 pOperateMCS[0] &= RATE_ADPT_1SS_MASK;
436 pOperateMCS[1] &= RATE_ADPT_2SS_MASK;
437 pOperateMCS[3] &= RATE_ADPT_MCS32_MASK;
446 u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
452 u8 availableMcsRate[16];
454 if (!pMCSRateSet || !pMCSFilter) {
455 netdev_warn(ieee->dev,
456 "%s(): pMCSRateSet and pMCSFilter are null\n",
460 for (i = 0; i < 16; i++)
461 availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i];
463 for (i = 0; i < 16; i++) {
464 if (availableMcsRate[i] != 0)
470 for (i = 0; i < 16; i++) {
471 if (availableMcsRate[i] != 0) {
472 bitMap = availableMcsRate[i];
473 for (j = 0; j < 8; j++) {
474 if ((bitMap % 2) != 0) {
475 if (HTMcsToDataRate(ieee, (8 * i + j)) >
476 HTMcsToDataRate(ieee, mcsRate))
483 return mcsRate | 0x80;
486 static u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS,
491 for (i = 0; i <= 15; i++)
492 pOperateMCS[i] = ieee->reg_dot11tx_ht_oper_rate_set[i] &
495 HT_PickMCSRate(ieee, pOperateMCS);
497 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
500 for (i = 2; i <= 15; i++)
506 void HTSetConnectBwMode(struct rtllib_device *ieee,
507 enum ht_channel_width bandwidth,
508 enum ht_extchnl_offset Offset);
510 void HTOnAssocRsp(struct rtllib_device *ieee)
512 struct rt_hi_throughput *ht_info = ieee->ht_info;
513 struct ht_capab_ele *pPeerHTCap = NULL;
514 struct ht_info_ele *pPeerHTInfo = NULL;
515 u16 nMaxAMSDUSize = 0;
516 u8 *pMcsFilter = NULL;
518 static const u8 EWC11NHTCap[] = { 0x00, 0x90, 0x4c, 0x33 };
519 static const u8 EWC11NHTInfo[] = { 0x00, 0x90, 0x4c, 0x34 };
521 if (!ht_info->bCurrentHTSupport) {
522 netdev_warn(ieee->dev, "%s(): HT_DISABLE\n", __func__);
525 netdev_dbg(ieee->dev, "%s(): HT_ENABLE\n", __func__);
527 if (!memcmp(ht_info->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap)))
528 pPeerHTCap = (struct ht_capab_ele *)(&ht_info->PeerHTCapBuf[4]);
530 pPeerHTCap = (struct ht_capab_ele *)(ht_info->PeerHTCapBuf);
532 if (!memcmp(ht_info->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
533 pPeerHTInfo = (struct ht_info_ele *)
534 (&ht_info->PeerHTInfoBuf[4]);
536 pPeerHTInfo = (struct ht_info_ele *)(ht_info->PeerHTInfoBuf);
539 print_hex_dump_bytes("%s: ", __func__, DUMP_PREFIX_NONE,
540 pPeerHTCap, sizeof(struct ht_capab_ele));
542 HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
543 (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
544 ht_info->cur_tx_bw40mhz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
547 ht_info->bCurShortGI20MHz = ((ht_info->bRegShortGI20MHz) ?
548 ((pPeerHTCap->ShortGI20Mhz == 1) ?
549 true : false) : false);
550 ht_info->bCurShortGI40MHz = ((ht_info->bRegShortGI40MHz) ?
551 ((pPeerHTCap->ShortGI40Mhz == 1) ?
552 true : false) : false);
554 ht_info->bCurSuppCCK = ((ht_info->bRegSuppCCK) ?
555 ((pPeerHTCap->DssCCk == 1) ? true :
558 ht_info->bCurrent_AMSDU_Support = ht_info->bAMSDU_Support;
560 nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize == 0) ? 3839 : 7935;
562 if (ht_info->nAMSDU_MaxSize > nMaxAMSDUSize)
563 ht_info->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize;
565 ht_info->nCurrent_AMSDU_MaxSize = ht_info->nAMSDU_MaxSize;
567 ht_info->bCurrentAMPDUEnable = ht_info->bAMPDUEnable;
568 if (ieee->rtllib_ap_sec_type &&
569 (ieee->rtllib_ap_sec_type(ieee) & (SEC_ALG_WEP | SEC_ALG_TKIP))) {
570 if ((ht_info->IOTPeer == HT_IOT_PEER_ATHEROS) ||
571 (ht_info->IOTPeer == HT_IOT_PEER_UNKNOWN))
572 ht_info->bCurrentAMPDUEnable = false;
575 if (!ht_info->reg_rt2rt_aggregation) {
576 if (ht_info->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor)
577 ht_info->CurrentAMPDUFactor =
578 pPeerHTCap->MaxRxAMPDUFactor;
580 ht_info->CurrentAMPDUFactor = ht_info->AMPDU_Factor;
583 if (ieee->current_network.bssht.bd_rt2rt_aggregation) {
584 if (ieee->pairwise_key_type != KEY_TYPE_NA)
585 ht_info->CurrentAMPDUFactor =
586 pPeerHTCap->MaxRxAMPDUFactor;
588 ht_info->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
590 ht_info->CurrentAMPDUFactor = min_t(u32, pPeerHTCap->MaxRxAMPDUFactor,
594 ht_info->current_mpdu_density = max_t(u8, ht_info->MPDU_Density,
595 pPeerHTCap->MPDUDensity);
596 if (ht_info->iot_action & HT_IOT_ACT_TX_USE_AMSDU_8K) {
597 ht_info->bCurrentAMPDUEnable = false;
598 ht_info->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE;
600 ht_info->cur_rx_reorder_enable = ht_info->reg_rx_reorder_enable;
602 if (pPeerHTCap->MCS[0] == 0)
603 pPeerHTCap->MCS[0] = 0xff;
605 HTIOTActDetermineRaFunc(ieee, ((pPeerHTCap->MCS[1]) != 0));
607 HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11ht_oper_rate_set);
609 ht_info->peer_mimo_ps = pPeerHTCap->MimoPwrSave;
610 if (ht_info->peer_mimo_ps == MIMO_PS_STATIC)
611 pMcsFilter = MCS_FILTER_1SS;
613 pMcsFilter = MCS_FILTER_ALL;
614 ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee,
615 ieee->dot11ht_oper_rate_set,
617 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
619 ht_info->current_op_mode = pPeerHTInfo->OptMode;
622 void HTInitializeHTInfo(struct rtllib_device *ieee)
624 struct rt_hi_throughput *ht_info = ieee->ht_info;
626 ht_info->bCurrentHTSupport = false;
628 ht_info->bCurBW40MHz = false;
629 ht_info->cur_tx_bw40mhz = false;
631 ht_info->bCurShortGI20MHz = false;
632 ht_info->bCurShortGI40MHz = false;
633 ht_info->forced_short_gi = false;
635 ht_info->bCurSuppCCK = true;
637 ht_info->bCurrent_AMSDU_Support = false;
638 ht_info->nCurrent_AMSDU_MaxSize = ht_info->nAMSDU_MaxSize;
639 ht_info->current_mpdu_density = ht_info->MPDU_Density;
640 ht_info->CurrentAMPDUFactor = ht_info->AMPDU_Factor;
642 memset((void *)(&ht_info->SelfHTCap), 0,
643 sizeof(ht_info->SelfHTCap));
644 memset((void *)(&ht_info->SelfHTInfo), 0,
645 sizeof(ht_info->SelfHTInfo));
646 memset((void *)(&ht_info->PeerHTCapBuf), 0,
647 sizeof(ht_info->PeerHTCapBuf));
648 memset((void *)(&ht_info->PeerHTInfoBuf), 0,
649 sizeof(ht_info->PeerHTInfoBuf));
651 ht_info->sw_bw_in_progress = false;
653 ht_info->ePeerHTSpecVer = HT_SPEC_VER_IEEE;
655 ht_info->current_rt2rt_aggregation = false;
656 ht_info->current_rt2rt_long_slot_time = false;
657 ht_info->RT2RT_HT_Mode = (enum rt_ht_capability)0;
659 ht_info->IOTPeer = 0;
660 ht_info->iot_action = 0;
661 ht_info->iot_ra_func = 0;
664 u8 *RegHTSuppRateSets = &ieee->reg_ht_supp_rate_set[0];
666 RegHTSuppRateSets[0] = 0xFF;
667 RegHTSuppRateSets[1] = 0xFF;
668 RegHTSuppRateSets[4] = 0x01;
672 void HTInitializeBssDesc(struct bss_ht *pBssHT)
674 pBssHT->bd_support_ht = false;
675 memset(pBssHT->bd_ht_cap_buf, 0, sizeof(pBssHT->bd_ht_cap_buf));
676 pBssHT->bd_ht_cap_len = 0;
677 memset(pBssHT->bd_ht_info_buf, 0, sizeof(pBssHT->bd_ht_info_buf));
678 pBssHT->bd_ht_info_len = 0;
680 pBssHT->bd_ht_spec_ver = HT_SPEC_VER_IEEE;
682 pBssHT->bd_rt2rt_aggregation = false;
683 pBssHT->bd_rt2rt_long_slot_time = false;
684 pBssHT->rt2rt_ht_mode = (enum rt_ht_capability)0;
687 void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
688 struct rtllib_network *pNetwork)
690 struct rt_hi_throughput *ht_info = ieee->ht_info;
693 /* unmark enable_ht flag here is the same reason why unmarked in
694 * function rtllib_softmac_new_net. WB 2008.09.10
696 if (pNetwork->bssht.bd_support_ht) {
697 ht_info->bCurrentHTSupport = true;
698 ht_info->ePeerHTSpecVer = pNetwork->bssht.bd_ht_spec_ver;
700 if (pNetwork->bssht.bd_ht_cap_len > 0 &&
701 pNetwork->bssht.bd_ht_cap_len <= sizeof(ht_info->PeerHTCapBuf))
702 memcpy(ht_info->PeerHTCapBuf,
703 pNetwork->bssht.bd_ht_cap_buf,
704 pNetwork->bssht.bd_ht_cap_len);
706 if (pNetwork->bssht.bd_ht_info_len > 0 &&
707 pNetwork->bssht.bd_ht_info_len <=
708 sizeof(ht_info->PeerHTInfoBuf))
709 memcpy(ht_info->PeerHTInfoBuf,
710 pNetwork->bssht.bd_ht_info_buf,
711 pNetwork->bssht.bd_ht_info_len);
713 if (ht_info->reg_rt2rt_aggregation) {
714 ht_info->current_rt2rt_aggregation =
715 pNetwork->bssht.bd_rt2rt_aggregation;
716 ht_info->current_rt2rt_long_slot_time =
717 pNetwork->bssht.bd_rt2rt_long_slot_time;
718 ht_info->RT2RT_HT_Mode = pNetwork->bssht.rt2rt_ht_mode;
720 ht_info->current_rt2rt_aggregation = false;
721 ht_info->current_rt2rt_long_slot_time = false;
722 ht_info->RT2RT_HT_Mode = (enum rt_ht_capability)0;
725 HTIOTPeerDetermine(ieee);
727 ht_info->iot_action = 0;
728 bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid);
730 ht_info->iot_action |= HT_IOT_ACT_DISABLE_MCS14;
732 bIOTAction = HTIOTActIsDisableMCS15(ieee);
734 ht_info->iot_action |= HT_IOT_ACT_DISABLE_MCS15;
736 bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee);
738 ht_info->iot_action |= HT_IOT_ACT_DISABLE_ALL_2SS;
740 bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid);
742 ht_info->iot_action |= HT_IOT_ACT_DISABLE_EDCA_TURBO;
744 bIOTAction = HTIOTActIsMgntUseCCK6M(ieee, pNetwork);
746 ht_info->iot_action |= HT_IOT_ACT_MGNT_USE_CCK_6M;
747 bIOTAction = HTIOTActIsCCDFsync(ieee);
749 ht_info->iot_action |= HT_IOT_ACT_CDD_FSYNC;
751 ht_info->bCurrentHTSupport = false;
752 ht_info->current_rt2rt_aggregation = false;
753 ht_info->current_rt2rt_long_slot_time = false;
754 ht_info->RT2RT_HT_Mode = (enum rt_ht_capability)0;
756 ht_info->iot_action = 0;
757 ht_info->iot_ra_func = 0;
761 void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
762 struct rtllib_network *pNetwork)
764 struct rt_hi_throughput *ht_info = ieee->ht_info;
765 struct ht_info_ele *pPeerHTInfo =
766 (struct ht_info_ele *)pNetwork->bssht.bd_ht_info_buf;
768 if (ht_info->bCurrentHTSupport) {
769 if (pNetwork->bssht.bd_ht_info_len != 0)
770 ht_info->current_op_mode = pPeerHTInfo->OptMode;
773 EXPORT_SYMBOL(HT_update_self_and_peer_setting);
775 void HTUseDefaultSetting(struct rtllib_device *ieee)
777 struct rt_hi_throughput *ht_info = ieee->ht_info;
779 if (ht_info->enable_ht) {
780 ht_info->bCurrentHTSupport = true;
781 ht_info->bCurSuppCCK = ht_info->bRegSuppCCK;
783 ht_info->bCurBW40MHz = ht_info->bRegBW40MHz;
784 ht_info->bCurShortGI20MHz = ht_info->bRegShortGI20MHz;
786 ht_info->bCurShortGI40MHz = ht_info->bRegShortGI40MHz;
788 if (ieee->iw_mode == IW_MODE_ADHOC)
789 ieee->current_network.qos_data.active =
790 ieee->current_network.qos_data.supported;
791 ht_info->bCurrent_AMSDU_Support = ht_info->bAMSDU_Support;
792 ht_info->nCurrent_AMSDU_MaxSize = ht_info->nAMSDU_MaxSize;
794 ht_info->bCurrentAMPDUEnable = ht_info->bAMPDUEnable;
795 ht_info->CurrentAMPDUFactor = ht_info->AMPDU_Factor;
797 ht_info->current_mpdu_density = ht_info->current_mpdu_density;
799 HTFilterMCSRate(ieee, ieee->reg_dot11tx_ht_oper_rate_set,
800 ieee->dot11ht_oper_rate_set);
801 ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee,
802 ieee->dot11ht_oper_rate_set,
804 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
807 ht_info->bCurrentHTSupport = false;
811 u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame)
813 if (ieee->ht_info->bCurrentHTSupport) {
814 if ((IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) {
815 netdev_dbg(ieee->dev, "HT CONTROL FILED EXIST!!\n");
822 static void HTSetConnectBwModeCallback(struct rtllib_device *ieee)
824 struct rt_hi_throughput *ht_info = ieee->ht_info;
826 if (ht_info->bCurBW40MHz) {
827 if (ht_info->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER)
828 ieee->set_chan(ieee->dev,
829 ieee->current_network.channel + 2);
830 else if (ht_info->CurSTAExtChnlOffset ==
831 HT_EXTCHNL_OFFSET_LOWER)
832 ieee->set_chan(ieee->dev,
833 ieee->current_network.channel - 2);
835 ieee->set_chan(ieee->dev,
836 ieee->current_network.channel);
838 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40,
839 ht_info->CurSTAExtChnlOffset);
841 ieee->set_chan(ieee->dev, ieee->current_network.channel);
842 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20,
843 HT_EXTCHNL_OFFSET_NO_EXT);
846 ht_info->sw_bw_in_progress = false;
849 void HTSetConnectBwMode(struct rtllib_device *ieee,
850 enum ht_channel_width bandwidth,
851 enum ht_extchnl_offset Offset)
853 struct rt_hi_throughput *ht_info = ieee->ht_info;
855 if (!ht_info->bRegBW40MHz)
858 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
859 bandwidth = HT_CHANNEL_WIDTH_20;
861 if (ht_info->sw_bw_in_progress) {
862 pr_info("%s: sw_bw_in_progress!!\n", __func__);
865 if (bandwidth == HT_CHANNEL_WIDTH_20_40) {
866 if (ieee->current_network.channel < 2 &&
867 Offset == HT_EXTCHNL_OFFSET_LOWER)
868 Offset = HT_EXTCHNL_OFFSET_NO_EXT;
869 if (Offset == HT_EXTCHNL_OFFSET_UPPER ||
870 Offset == HT_EXTCHNL_OFFSET_LOWER) {
871 ht_info->bCurBW40MHz = true;
872 ht_info->CurSTAExtChnlOffset = Offset;
874 ht_info->bCurBW40MHz = false;
875 ht_info->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
878 ht_info->bCurBW40MHz = false;
879 ht_info->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
882 netdev_dbg(ieee->dev, "%s():ht_info->bCurBW40MHz:%x\n", __func__,
883 ht_info->bCurBW40MHz);
885 ht_info->sw_bw_in_progress = true;
887 HTSetConnectBwModeCallback(ieee);