1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #define _HAL_COM_PHYCFG_C_
17 #include <drv_types.h>
18 #include <rtw_debug.h>
21 u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 Band, u8 RfPath,
22 u8 TxNum, enum RATE_SECTION RateSection)
24 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
27 if (RfPath > ODM_RF_PATH_D) {
28 DBG_871X("Invalid Rf Path %d in PHY_GetTxPowerByRateBase()\n", RfPath);
32 if (Band == BAND_ON_2_4G) {
33 switch (RateSection) {
35 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][0];
38 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][1];
41 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][2];
44 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][3];
47 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][4];
50 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][5];
52 case VHT_1SSMCS0_1SSMCS9:
53 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][6];
55 case VHT_2SSMCS0_2SSMCS9:
56 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][7];
58 case VHT_3SSMCS0_3SSMCS9:
59 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][8];
61 case VHT_4SSMCS0_4SSMCS9:
62 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][9];
65 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
66 RateSection, RfPath, TxNum);
70 } else if (Band == BAND_ON_5G) {
71 switch (RateSection) {
73 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][0];
76 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][1];
79 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][2];
82 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][3];
85 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][4];
87 case VHT_1SSMCS0_1SSMCS9:
88 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][5];
90 case VHT_2SSMCS0_2SSMCS9:
91 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][6];
93 case VHT_3SSMCS0_3SSMCS9:
94 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][7];
96 case VHT_4SSMCS0_4SSMCS9:
97 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][8];
100 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
101 RateSection, RfPath, TxNum);
105 DBG_871X("Invalid Band %d in PHY_GetTxPowerByRateBase()\n", Band);
111 phy_SetTxPowerByRateBase(
112 struct adapter *Adapter,
115 enum RATE_SECTION RateSection,
120 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
122 if (RfPath > ODM_RF_PATH_D) {
123 DBG_871X("Invalid Rf Path %d in phy_SetTxPowerByRatBase()\n", RfPath);
127 if (Band == BAND_ON_2_4G) {
128 switch (RateSection) {
130 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][0] = Value;
133 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][1] = Value;
136 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][2] = Value;
139 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][3] = Value;
142 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][4] = Value;
145 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][5] = Value;
147 case VHT_1SSMCS0_1SSMCS9:
148 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][6] = Value;
150 case VHT_2SSMCS0_2SSMCS9:
151 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][7] = Value;
153 case VHT_3SSMCS0_3SSMCS9:
154 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][8] = Value;
156 case VHT_4SSMCS0_4SSMCS9:
157 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][9] = Value;
160 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n",
161 RateSection, RfPath, TxNum);
164 } else if (Band == BAND_ON_5G) {
165 switch (RateSection) {
167 pHalData->TxPwrByRateBase5G[RfPath][TxNum][0] = Value;
170 pHalData->TxPwrByRateBase5G[RfPath][TxNum][1] = Value;
173 pHalData->TxPwrByRateBase5G[RfPath][TxNum][2] = Value;
176 pHalData->TxPwrByRateBase5G[RfPath][TxNum][3] = Value;
179 pHalData->TxPwrByRateBase5G[RfPath][TxNum][4] = Value;
181 case VHT_1SSMCS0_1SSMCS9:
182 pHalData->TxPwrByRateBase5G[RfPath][TxNum][5] = Value;
184 case VHT_2SSMCS0_2SSMCS9:
185 pHalData->TxPwrByRateBase5G[RfPath][TxNum][6] = Value;
187 case VHT_3SSMCS0_3SSMCS9:
188 pHalData->TxPwrByRateBase5G[RfPath][TxNum][7] = Value;
190 case VHT_4SSMCS0_4SSMCS9:
191 pHalData->TxPwrByRateBase5G[RfPath][TxNum][8] = Value;
194 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n",
195 RateSection, RfPath, TxNum);
199 DBG_871X("Invalid Band %d in phy_SetTxPowerByRateBase()\n", Band);
203 phy_StoreTxPowerByRateBase(
204 struct adapter *padapter
209 /* DBG_871X("===>%s\n", __func__); */
211 for (path = ODM_RF_PATH_A; path <= ODM_RF_PATH_B; ++path) {
212 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_11M);
213 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, CCK, RF_1TX, base);
214 /* DBG_871X("Power index base of 2.4G path %d 1Tx CCK = > 0x%x\n", path, base); */
216 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_54M);
217 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, OFDM, RF_1TX, base);
218 /* DBG_871X("Power index base of 2.4G path %d 1Tx OFDM = > 0x%x\n", path, base); */
220 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_MCS7);
221 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, HT_MCS0_MCS7, RF_1TX, base);
222 /* DBG_871X("Power index base of 2.4G path %d 1Tx MCS0-7 = > 0x%x\n", path, base); */
224 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_2TX, MGN_MCS15);
225 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, HT_MCS8_MCS15, RF_2TX, base);
226 /* DBG_871X("Power index base of 2.4G path %d 2Tx MCS8-15 = > 0x%x\n", path, base); */
228 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_3TX, MGN_MCS23);
229 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, HT_MCS16_MCS23, RF_3TX, base);
230 /* DBG_871X("Power index base of 2.4G path %d 3Tx MCS16-23 = > 0x%x\n", path, base); */
232 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_VHT1SS_MCS7);
233 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, VHT_1SSMCS0_1SSMCS9, RF_1TX, base);
234 /* DBG_871X("Power index base of 2.4G path %d 1Tx VHT1SS = > 0x%x\n", path, base); */
236 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_2TX, MGN_VHT2SS_MCS7);
237 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, VHT_2SSMCS0_2SSMCS9, RF_2TX, base);
238 /* DBG_871X("Power index base of 2.4G path %d 2Tx VHT2SS = > 0x%x\n", path, base); */
240 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_3TX, MGN_VHT3SS_MCS7);
241 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, VHT_3SSMCS0_3SSMCS9, RF_3TX, base);
242 /* DBG_871X("Power index base of 2.4G path %d 3Tx VHT3SS = > 0x%x\n", path, base); */
244 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_1TX, MGN_54M);
245 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, OFDM, RF_1TX, base);
246 /* DBG_871X("Power index base of 5G path %d 1Tx OFDM = > 0x%x\n", path, base); */
248 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_1TX, MGN_MCS7);
249 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, HT_MCS0_MCS7, RF_1TX, base);
250 /* DBG_871X("Power index base of 5G path %d 1Tx MCS0~7 = > 0x%x\n", path, base); */
252 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_2TX, MGN_MCS15);
253 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, HT_MCS8_MCS15, RF_2TX, base);
254 /* DBG_871X("Power index base of 5G path %d 2Tx MCS8~15 = > 0x%x\n", path, base); */
256 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_3TX, MGN_MCS23);
257 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, HT_MCS16_MCS23, RF_3TX, base);
258 /* DBG_871X("Power index base of 5G path %d 3Tx MCS16~23 = > 0x%x\n", path, base); */
260 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_1TX, MGN_VHT1SS_MCS7);
261 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, VHT_1SSMCS0_1SSMCS9, RF_1TX, base);
262 /* DBG_871X("Power index base of 5G path %d 1Tx VHT1SS = > 0x%x\n", path, base); */
264 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_2TX, MGN_VHT2SS_MCS7);
265 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, VHT_2SSMCS0_2SSMCS9, RF_2TX, base);
266 /* DBG_871X("Power index base of 5G path %d 2Tx VHT2SS = > 0x%x\n", path, base); */
268 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_3TX, MGN_VHT2SS_MCS7);
269 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, VHT_3SSMCS0_3SSMCS9, RF_3TX, base);
270 /* DBG_871X("Power index base of 5G path %d 3Tx VHT3SS = > 0x%x\n", path, base); */
273 /* DBG_871X("<===%s\n", __func__); */
276 u8 PHY_GetRateSectionIndexOfTxPowerByRate(
277 struct adapter *padapter, u32 RegAddr, u32 BitMask
280 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
281 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
284 if (pDM_Odm->PhyRegPgVersion == 0) {
286 case rTxAGC_A_Rate18_06:
289 case rTxAGC_A_Rate54_24:
292 case rTxAGC_A_CCK1_Mcs32:
295 case rTxAGC_B_CCK11_A_CCK2_11:
296 if (BitMask == bMaskH3Bytes)
298 else if (BitMask == 0x000000ff)
302 case rTxAGC_A_Mcs03_Mcs00:
305 case rTxAGC_A_Mcs07_Mcs04:
308 case rTxAGC_A_Mcs11_Mcs08:
311 case rTxAGC_A_Mcs15_Mcs12:
314 case rTxAGC_B_Rate18_06:
317 case rTxAGC_B_Rate54_24:
320 case rTxAGC_B_CCK1_55_Mcs32:
323 case rTxAGC_B_Mcs03_Mcs00:
326 case rTxAGC_B_Mcs07_Mcs04:
329 case rTxAGC_B_Mcs11_Mcs08:
332 case rTxAGC_B_Mcs15_Mcs12:
336 DBG_871X("Invalid RegAddr 0x3%x in PHY_GetRateSectionIndexOfTxPowerByRate()", RegAddr);
345 PHY_GetRateValuesOfTxPowerByRate(
346 struct adapter *padapter,
358 case rTxAGC_A_Rate18_06:
359 case rTxAGC_B_Rate18_06:
360 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_6M);
361 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_9M);
362 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_12M);
363 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_18M);
364 for (i = 0; i < 4; ++i) {
365 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
366 ((Value >> (i * 8)) & 0xF));
371 case rTxAGC_A_Rate54_24:
372 case rTxAGC_B_Rate54_24:
373 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_24M);
374 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_36M);
375 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_48M);
376 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_54M);
377 for (i = 0; i < 4; ++i) {
378 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
379 ((Value >> (i * 8)) & 0xF));
384 case rTxAGC_A_CCK1_Mcs32:
385 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M);
386 PwrByRateVal[0] = (s8) ((((Value >> (8 + 4)) & 0xF)) * 10 +
387 ((Value >> 8) & 0xF));
391 case rTxAGC_B_CCK11_A_CCK2_11:
392 if (BitMask == 0xffffff00) {
393 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M);
394 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M);
395 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M);
396 for (i = 1; i < 4; ++i) {
397 PwrByRateVal[i - 1] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
398 ((Value >> (i * 8)) & 0xF));
401 } else if (BitMask == 0x000000ff) {
402 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M);
403 PwrByRateVal[0] = (s8) ((((Value >> 4) & 0xF)) * 10 + (Value & 0xF));
408 case rTxAGC_A_Mcs03_Mcs00:
409 case rTxAGC_B_Mcs03_Mcs00:
410 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS0);
411 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS1);
412 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS2);
413 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS3);
414 for (i = 0; i < 4; ++i) {
415 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
416 ((Value >> (i * 8)) & 0xF));
421 case rTxAGC_A_Mcs07_Mcs04:
422 case rTxAGC_B_Mcs07_Mcs04:
423 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS4);
424 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS5);
425 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS6);
426 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS7);
427 for (i = 0; i < 4; ++i) {
428 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
429 ((Value >> (i * 8)) & 0xF));
434 case rTxAGC_A_Mcs11_Mcs08:
435 case rTxAGC_B_Mcs11_Mcs08:
436 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS8);
437 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS9);
438 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS10);
439 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS11);
440 for (i = 0; i < 4; ++i) {
441 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
442 ((Value >> (i * 8)) & 0xF));
447 case rTxAGC_A_Mcs15_Mcs12:
448 case rTxAGC_B_Mcs15_Mcs12:
449 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS12);
450 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS13);
451 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS14);
452 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS15);
453 for (i = 0; i < 4; ++i) {
454 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
455 ((Value >> (i * 8)) & 0xF));
461 case rTxAGC_B_CCK1_55_Mcs32:
462 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M);
463 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M);
464 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M);
465 for (i = 1; i < 4; ++i) {
466 PwrByRateVal[i - 1] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
467 ((Value >> (i * 8)) & 0xF));
476 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M);
477 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M);
478 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M);
479 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M);
480 for (i = 0; i < 4; ++i) {
481 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
482 ((Value >> (i * 8)) & 0xF));
491 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_6M);
492 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_9M);
493 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_12M);
494 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_18M);
495 for (i = 0; i < 4; ++i) {
496 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
497 ((Value >> (i * 8)) & 0xF));
506 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_24M);
507 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_36M);
508 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_48M);
509 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_54M);
510 for (i = 0; i < 4; ++i) {
511 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
512 ((Value >> (i * 8)) & 0xF));
521 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS0);
522 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS1);
523 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS2);
524 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS3);
525 for (i = 0; i < 4; ++i) {
526 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
527 ((Value >> (i * 8)) & 0xF));
536 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS4);
537 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS5);
538 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS6);
539 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS7);
540 for (i = 0; i < 4; ++i) {
541 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
542 ((Value >> (i * 8)) & 0xF));
551 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS8);
552 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS9);
553 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS10);
554 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS11);
555 for (i = 0; i < 4; ++i) {
556 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
557 ((Value >> (i * 8)) & 0xF));
566 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS12);
567 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS13);
568 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS14);
569 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS15);
570 for (i = 0; i < 4; ++i) {
571 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
572 ((Value >> (i * 8)) & 0xF));
581 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS0);
582 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS1);
583 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS2);
584 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS3);
585 for (i = 0; i < 4; ++i) {
586 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
587 ((Value >> (i * 8)) & 0xF));
596 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS4);
597 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS5);
598 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS6);
599 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS7);
600 for (i = 0; i < 4; ++i) {
601 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
602 ((Value >> (i * 8)) & 0xF));
611 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS8);
612 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS9);
613 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS0);
614 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS1);
615 for (i = 0; i < 4; ++i) {
616 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
617 ((Value >> (i * 8)) & 0xF));
626 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS2);
627 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS3);
628 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS4);
629 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS5);
630 for (i = 0; i < 4; ++i) {
631 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
632 ((Value >> (i * 8)) & 0xF));
641 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS6);
642 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS7);
643 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS8);
644 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS9);
645 for (i = 0; i < 4; ++i) {
646 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
647 ((Value >> (i * 8)) & 0xF));
656 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS16);
657 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS17);
658 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS18);
659 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS19);
660 for (i = 0; i < 4; ++i) {
661 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
662 ((Value >> (i * 8)) & 0xF));
671 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS20);
672 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS21);
673 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS22);
674 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS23);
675 for (i = 0; i < 4; ++i) {
676 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
677 ((Value >> (i * 8)) & 0xF));
686 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS0);
687 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS1);
688 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS2);
689 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS3);
690 for (i = 0; i < 4; ++i) {
691 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
692 ((Value >> (i * 8)) & 0xF));
701 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS4);
702 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS5);
703 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS6);
704 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS7);
705 for (i = 0; i < 4; ++i) {
706 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
707 ((Value >> (i * 8)) & 0xF));
716 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS8);
717 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS9);
718 for (i = 0; i < 2; ++i) {
719 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
720 ((Value >> (i * 8)) & 0xF));
726 DBG_871X("Invalid RegAddr 0x%x in %s()\n", RegAddr, __func__);
731 static void PHY_StoreTxPowerByRateNew(
732 struct adapter *padapter,
741 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
742 u8 i = 0, rateIndex[4] = {0}, rateNum = 0;
743 s8 PwrByRateVal[4] = {0};
745 PHY_GetRateValuesOfTxPowerByRate(padapter, RegAddr, BitMask, Data, rateIndex, PwrByRateVal, &rateNum);
747 if (Band != BAND_ON_2_4G && Band != BAND_ON_5G) {
748 DBG_871X("Invalid Band %d\n", Band);
752 if (RfPath > ODM_RF_PATH_D) {
753 DBG_871X("Invalid RfPath %d\n", RfPath);
757 if (TxNum > ODM_RF_PATH_D) {
758 DBG_871X("Invalid TxNum %d\n", TxNum);
762 for (i = 0; i < rateNum; ++i) {
763 if (rateIndex[i] == PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS0) ||
764 rateIndex[i] == PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS1))
767 pHalData->TxPwrByRateOffset[Band][RfPath][TxNum][rateIndex[i]] = PwrByRateVal[i];
771 static void PHY_StoreTxPowerByRateOld(
772 struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data
775 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
776 u8 index = PHY_GetRateSectionIndexOfTxPowerByRate(padapter, RegAddr, BitMask);
778 pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][index] = Data;
779 /* DBG_871X("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n", pHalData->pwrGroupCnt, */
780 /* pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0]); */
783 void PHY_InitTxPowerByRate(struct adapter *padapter)
785 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
786 u8 band, rfPath, TxNum, rate;
788 for (band = BAND_ON_2_4G; band <= BAND_ON_5G; ++band)
789 for (rfPath = 0; rfPath < TX_PWR_BY_RATE_NUM_RF; ++rfPath)
790 for (TxNum = 0; TxNum < TX_PWR_BY_RATE_NUM_RF; ++TxNum)
791 for (rate = 0; rate < TX_PWR_BY_RATE_NUM_RATE; ++rate)
792 pHalData->TxPwrByRateOffset[band][rfPath][TxNum][rate] = 0;
795 void PHY_StoreTxPowerByRate(
796 struct adapter *padapter,
805 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
806 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
808 if (pDM_Odm->PhyRegPgVersion > 0)
809 PHY_StoreTxPowerByRateNew(padapter, Band, RfPath, TxNum, RegAddr, BitMask, Data);
810 else if (pDM_Odm->PhyRegPgVersion == 0) {
811 PHY_StoreTxPowerByRateOld(padapter, RegAddr, BitMask, Data);
813 if (RegAddr == rTxAGC_A_Mcs15_Mcs12 && pHalData->rf_type == RF_1T1R)
814 pHalData->pwrGroupCnt++;
815 else if (RegAddr == rTxAGC_B_Mcs15_Mcs12 && pHalData->rf_type != RF_1T1R)
816 pHalData->pwrGroupCnt++;
818 DBG_871X("Invalid PHY_REG_PG.txt version %d\n", pDM_Odm->PhyRegPgVersion);
823 phy_ConvertTxPowerByRateInDbmToRelativeValues(
824 struct adapter *padapter
827 u8 base = 0, i = 0, value = 0, band = 0, path = 0, txNum = 0;
829 MGN_1M, MGN_2M, MGN_5_5M, MGN_11M
832 MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M
834 u8 mcs0_7Rates[8] = {
835 MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7
837 u8 mcs8_15Rates[8] = {
838 MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15
840 u8 mcs16_23Rates[8] = {
841 MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23
843 u8 vht1ssRates[10] = {
844 MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4,
845 MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9
847 u8 vht2ssRates[10] = {
848 MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4,
849 MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9
851 u8 vht3ssRates[10] = {
852 MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4,
853 MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9
856 /* DBG_871X("===>PHY_ConvertTxPowerByRateInDbmToRelativeValues()\n"); */
858 for (band = BAND_ON_2_4G; band <= BAND_ON_5G; ++band) {
859 for (path = ODM_RF_PATH_A; path <= ODM_RF_PATH_D; ++path) {
860 for (txNum = RF_1TX; txNum < RF_MAX_TX_NUM; ++txNum) {
862 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_11M);
863 for (i = 0; i < sizeof(cckRates); ++i) {
864 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, cckRates[i]);
865 PHY_SetTxPowerByRate(padapter, band, path, txNum, cckRates[i], value - base);
869 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_54M);
870 for (i = 0; i < sizeof(ofdmRates); ++i) {
871 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, ofdmRates[i]);
872 PHY_SetTxPowerByRate(padapter, band, path, txNum, ofdmRates[i], value - base);
876 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_MCS7);
877 for (i = 0; i < sizeof(mcs0_7Rates); ++i) {
878 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, mcs0_7Rates[i]);
879 PHY_SetTxPowerByRate(padapter, band, path, txNum, mcs0_7Rates[i], value - base);
883 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_MCS15);
884 for (i = 0; i < sizeof(mcs8_15Rates); ++i) {
885 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, mcs8_15Rates[i]);
886 PHY_SetTxPowerByRate(padapter, band, path, txNum, mcs8_15Rates[i], value - base);
890 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_MCS23);
891 for (i = 0; i < sizeof(mcs16_23Rates); ++i) {
892 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, mcs16_23Rates[i]);
893 PHY_SetTxPowerByRate(padapter, band, path, txNum, mcs16_23Rates[i], value - base);
897 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_VHT1SS_MCS7);
898 for (i = 0; i < sizeof(vht1ssRates); ++i) {
899 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, vht1ssRates[i]);
900 PHY_SetTxPowerByRate(padapter, band, path, txNum, vht1ssRates[i], value - base);
904 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_VHT2SS_MCS7);
905 for (i = 0; i < sizeof(vht2ssRates); ++i) {
906 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, vht2ssRates[i]);
907 PHY_SetTxPowerByRate(padapter, band, path, txNum, vht2ssRates[i], value - base);
911 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_VHT3SS_MCS7);
912 for (i = 0; i < sizeof(vht3ssRates); ++i) {
913 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, vht3ssRates[i]);
914 PHY_SetTxPowerByRate(padapter, band, path, txNum, vht3ssRates[i], value - base);
920 /* DBG_871X("<===PHY_ConvertTxPowerByRateInDbmToRelativeValues()\n"); */
924 * This function must be called if the value in the PHY_REG_PG.txt(or header)
925 * is exact dBm values
927 void PHY_TxPowerByRateConfiguration(struct adapter *padapter)
929 phy_StoreTxPowerByRateBase(padapter);
930 phy_ConvertTxPowerByRateInDbmToRelativeValues(padapter);
933 void PHY_SetTxPowerIndexByRateSection(
934 struct adapter *padapter, u8 RFPath, u8 Channel, u8 RateSection
937 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
939 if (RateSection == CCK) {
940 u8 cckRates[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M};
941 if (pHalData->CurrentBandType == BAND_ON_2_4G)
942 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
943 cckRates, sizeof(cckRates)/sizeof(u8));
945 } else if (RateSection == OFDM) {
946 u8 ofdmRates[] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
947 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
948 ofdmRates, sizeof(ofdmRates)/sizeof(u8));
950 } else if (RateSection == HT_MCS0_MCS7) {
951 u8 htRates1T[] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7};
952 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
953 htRates1T, sizeof(htRates1T)/sizeof(u8));
955 } else if (RateSection == HT_MCS8_MCS15) {
956 u8 htRates2T[] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15};
957 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
958 htRates2T, sizeof(htRates2T)/sizeof(u8));
960 } else if (RateSection == HT_MCS16_MCS23) {
961 u8 htRates3T[] = {MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23};
962 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
963 htRates3T, sizeof(htRates3T)/sizeof(u8));
965 } else if (RateSection == HT_MCS24_MCS31) {
966 u8 htRates4T[] = {MGN_MCS24, MGN_MCS25, MGN_MCS26, MGN_MCS27, MGN_MCS28, MGN_MCS29, MGN_MCS30, MGN_MCS31};
967 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
968 htRates4T, sizeof(htRates4T)/sizeof(u8));
970 } else if (RateSection == VHT_1SSMCS0_1SSMCS9) {
971 u8 vhtRates1T[] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4,
972 MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9};
973 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
974 vhtRates1T, sizeof(vhtRates1T)/sizeof(u8));
976 } else if (RateSection == VHT_2SSMCS0_2SSMCS9) {
977 u8 vhtRates2T[] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4,
978 MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9};
980 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
981 vhtRates2T, sizeof(vhtRates2T)/sizeof(u8));
982 } else if (RateSection == VHT_3SSMCS0_3SSMCS9) {
983 u8 vhtRates3T[] = {MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4,
984 MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9};
986 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
987 vhtRates3T, sizeof(vhtRates3T)/sizeof(u8));
988 } else if (RateSection == VHT_4SSMCS0_4SSMCS9) {
989 u8 vhtRates4T[] = {MGN_VHT4SS_MCS0, MGN_VHT4SS_MCS1, MGN_VHT4SS_MCS2, MGN_VHT4SS_MCS3, MGN_VHT4SS_MCS4,
990 MGN_VHT4SS_MCS5, MGN_VHT4SS_MCS6, MGN_VHT4SS_MCS7, MGN_VHT4SS_MCS8, MGN_VHT4SS_MCS9};
992 PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel,
993 vhtRates4T, sizeof(vhtRates4T)/sizeof(u8));
995 DBG_871X("Invalid RateSection %d in %s", RateSection, __func__);
998 static bool phy_GetChnlIndex(u8 Channel, u8 *ChannelIdx)
1000 u8 channel5G[CHANNEL_MAX_NUMBER_5G] = {
1001 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 100, 102,
1002 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130,
1003 132, 134, 136, 138, 140, 142, 144, 149, 151, 153, 155, 157, 159, 161,
1004 163, 165, 167, 168, 169, 171, 173, 175, 177
1009 if (Channel <= 14) {
1011 *ChannelIdx = Channel-1;
1015 for (i = 0; i < sizeof(channel5G)/sizeof(u8); ++i) {
1016 if (channel5G[i] == Channel) {
1026 u8 PHY_GetTxPowerIndexBase(
1027 struct adapter *padapter,
1030 enum CHANNEL_WIDTH BandWidth,
1035 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1036 u8 i = 0; /* default set to 1S */
1038 u8 chnlIdx = (Channel-1);
1040 if (HAL_IsLegalChannel(padapter, Channel) == false) {
1042 DBG_871X("Illegal channel!!\n");
1045 *bIn24G = phy_GetChnlIndex(Channel, &chnlIdx);
1047 /* DBG_871X("[%s] Channel Index: %d\n", (*bIn24G?"2.4G":"5G"), chnlIdx); */
1049 if (*bIn24G) { /* 3 ============================== 2.4 G ============================== */
1050 if (IS_CCK_RATE(Rate))
1051 txPower = pHalData->Index24G_CCK_Base[RFPath][chnlIdx];
1052 else if (MGN_6M <= Rate)
1053 txPower = pHalData->Index24G_BW40_Base[RFPath][chnlIdx];
1055 DBG_871X("PHY_GetTxPowerIndexBase: INVALID Rate.\n");
1057 /* DBG_871X("Base Tx power(RF-%c, Rate #%d, Channel Index %d) = 0x%X\n", */
1058 /* ((RFPath == 0)?'A':'B'), Rate, chnlIdx, txPower); */
1061 if ((MGN_6M <= Rate && Rate <= MGN_54M) && !IS_CCK_RATE(Rate)) {
1062 txPower += pHalData->OFDM_24G_Diff[RFPath][TX_1S];
1063 /* DBG_871X("+PowerDiff 2.4G (RF-%c): (OFDM-1T) = (%d)\n", ((RFPath == 0)?'A':'B'), pHalData->OFDM_24G_Diff[RFPath][TX_1S]); */
1065 if (BandWidth == CHANNEL_WIDTH_20) { /* BW20-1S, BW20-2S */
1066 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1067 txPower += pHalData->BW20_24G_Diff[RFPath][TX_1S];
1068 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1069 txPower += pHalData->BW20_24G_Diff[RFPath][TX_2S];
1070 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1071 txPower += pHalData->BW20_24G_Diff[RFPath][TX_3S];
1072 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1073 txPower += pHalData->BW20_24G_Diff[RFPath][TX_4S];
1075 /* DBG_871X("+PowerDiff 2.4G (RF-%c): (BW20-1S, BW20-2S, BW20-3S, BW20-4S) = (%d, %d, %d, %d)\n", ((RFPath == 0)?'A':(RFPath == 1)?'B':(RFPath ==2)?'C':'D'), */
1076 /* pHalData->BW20_24G_Diff[RFPath][TX_1S], pHalData->BW20_24G_Diff[RFPath][TX_2S], */
1077 /* pHalData->BW20_24G_Diff[RFPath][TX_3S], pHalData->BW20_24G_Diff[RFPath][TX_4S]); */
1078 } else if (BandWidth == CHANNEL_WIDTH_40) { /* BW40-1S, BW40-2S */
1079 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1080 txPower += pHalData->BW40_24G_Diff[RFPath][TX_1S];
1081 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1082 txPower += pHalData->BW40_24G_Diff[RFPath][TX_2S];
1083 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1084 txPower += pHalData->BW40_24G_Diff[RFPath][TX_3S];
1085 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1086 txPower += pHalData->BW40_24G_Diff[RFPath][TX_4S];
1088 /* DBG_871X("+PowerDiff 2.4G (RF-%c): (BW40-1S, BW40-2S, BW40-3S, BW40-4S) = (%d, %d, %d, %d)\n", ((RFPath == 0)?'A':(RFPath == 1)?'B':(RFPath ==2)?'C':'D'), */
1089 /* pHalData->BW40_24G_Diff[RFPath][TX_1S], pHalData->BW40_24G_Diff[RFPath][TX_2S], */
1090 /* pHalData->BW40_24G_Diff[RFPath][TX_3S], pHalData->BW40_24G_Diff[RFPath][TX_4S]); */
1092 /* Willis suggest adopt BW 40M power index while in BW 80 mode */
1093 else if (BandWidth == CHANNEL_WIDTH_80) {
1094 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1095 txPower += pHalData->BW40_24G_Diff[RFPath][TX_1S];
1096 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1097 txPower += pHalData->BW40_24G_Diff[RFPath][TX_2S];
1098 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1099 txPower += pHalData->BW40_24G_Diff[RFPath][TX_3S];
1100 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1101 txPower += pHalData->BW40_24G_Diff[RFPath][TX_4S];
1103 /* DBG_871X("+PowerDiff 2.4G (RF-%c): (BW40-1S, BW40-2S, BW40-3S, BW40-4T) = (%d, %d, %d, %d) P.S. Current is in BW 80MHz\n", ((RFPath == 0)?'A':(RFPath == 1)?'B':(RFPath ==2)?'C':'D'), */
1104 /* pHalData->BW40_24G_Diff[RFPath][TX_1S], pHalData->BW40_24G_Diff[RFPath][TX_2S], */
1105 /* pHalData->BW40_24G_Diff[RFPath][TX_3S], pHalData->BW40_24G_Diff[RFPath][TX_4S]); */
1107 } else {/* 3 ============================== 5 G ============================== */
1109 txPower = pHalData->Index5G_BW40_Base[RFPath][chnlIdx];
1111 DBG_871X("===> mpt_ProQueryCalTxPower_Jaguar: INVALID Rate.\n");
1113 /* DBG_871X("Base Tx power(RF-%c, Rate #%d, Channel Index %d) = 0x%X\n", */
1114 /* ((RFPath == 0)?'A':'B'), Rate, chnlIdx, txPower); */
1117 if ((MGN_6M <= Rate && Rate <= MGN_54M) && !IS_CCK_RATE(Rate)) {
1118 txPower += pHalData->OFDM_5G_Diff[RFPath][TX_1S];
1119 /* DBG_871X("+PowerDiff 5G (RF-%c): (OFDM-1T) = (%d)\n", ((RFPath == 0)?'A':'B'), pHalData->OFDM_5G_Diff[RFPath][TX_1S]); */
1122 /* BW20-1S, BW20-2S */
1123 if (BandWidth == CHANNEL_WIDTH_20) {
1124 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1125 txPower += pHalData->BW20_5G_Diff[RFPath][TX_1S];
1126 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1127 txPower += pHalData->BW20_5G_Diff[RFPath][TX_2S];
1128 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1129 txPower += pHalData->BW20_5G_Diff[RFPath][TX_3S];
1130 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1131 txPower += pHalData->BW20_5G_Diff[RFPath][TX_4S];
1133 /* DBG_871X("+PowerDiff 5G (RF-%c): (BW20-1S, BW20-2S, BW20-3S, BW20-4S) = (%d, %d, %d, %d)\n", ((RFPath == 0)?'A':(RFPath == 1)?'B':(RFPath ==2)?'C':'D'), */
1134 /* pHalData->BW20_5G_Diff[RFPath][TX_1S], pHalData->BW20_5G_Diff[RFPath][TX_2S], */
1135 /* pHalData->BW20_5G_Diff[RFPath][TX_3S], pHalData->BW20_5G_Diff[RFPath][TX_4S]); */
1136 } else if (BandWidth == CHANNEL_WIDTH_40) { /* BW40-1S, BW40-2S */
1137 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1138 txPower += pHalData->BW40_5G_Diff[RFPath][TX_1S];
1139 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1140 txPower += pHalData->BW40_5G_Diff[RFPath][TX_2S];
1141 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1142 txPower += pHalData->BW40_5G_Diff[RFPath][TX_3S];
1143 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1144 txPower += pHalData->BW40_5G_Diff[RFPath][TX_4S];
1146 /* DBG_871X("+PowerDiff 5G(RF-%c): (BW40-1S, BW40-2S) = (%d, %d, %d, %d)\n", ((RFPath == 0)?'A':(RFPath == 1)?'B':(RFPath ==2)?'C':'D'), */
1147 /* pHalData->BW40_5G_Diff[RFPath][TX_1S], pHalData->BW40_5G_Diff[RFPath][TX_2S], */
1148 /* pHalData->BW40_5G_Diff[RFPath][TX_3S], pHalData->BW40_5G_Diff[RFPath][TX_4S]); */
1149 } else if (BandWidth == CHANNEL_WIDTH_80) { /* BW80-1S, BW80-2S */
1150 /* <20121220, Kordan> Get the index of array "Index5G_BW80_Base". */
1151 u8 channel5G_80M[CHANNEL_MAX_NUMBER_5G_80M] = {42, 58, 106, 122, 138, 155, 171};
1152 for (i = 0; i < sizeof(channel5G_80M)/sizeof(u8); ++i)
1153 if (channel5G_80M[i] == Channel)
1156 txPower = pHalData->Index5G_BW80_Base[RFPath][chnlIdx];
1158 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1159 txPower += + pHalData->BW80_5G_Diff[RFPath][TX_1S];
1160 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1161 txPower += pHalData->BW80_5G_Diff[RFPath][TX_2S];
1162 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1163 txPower += pHalData->BW80_5G_Diff[RFPath][TX_3S];
1164 if ((MGN_MCS23 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1165 txPower += pHalData->BW80_5G_Diff[RFPath][TX_4S];
1167 /* DBG_871X("+PowerDiff 5G(RF-%c): (BW80-1S, BW80-2S, BW80-3S, BW80-4S) = (%d, %d, %d, %d)\n", ((RFPath == 0)?'A':(RFPath == 1)?'B':(RFPath ==2)?'C':'D'), */
1168 /* pHalData->BW80_5G_Diff[RFPath][TX_1S], pHalData->BW80_5G_Diff[RFPath][TX_2S], */
1169 /* pHalData->BW80_5G_Diff[RFPath][TX_3S], pHalData->BW80_5G_Diff[RFPath][TX_4S]); */
1176 s8 PHY_GetTxPowerTrackingOffset(struct adapter *padapter, u8 RFPath, u8 Rate)
1178 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1179 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
1182 if (pDM_Odm->RFCalibrateInfo.TxPowerTrackControl == false)
1185 if ((Rate == MGN_1M) || (Rate == MGN_2M) || (Rate == MGN_5_5M) || (Rate == MGN_11M)) {
1186 offset = pDM_Odm->Remnant_CCKSwingIdx;
1187 /* DBG_871X("+Remnant_CCKSwingIdx = 0x%x\n", RFPath, Rate, pDM_Odm->Remnant_CCKSwingIdx); */
1189 offset = pDM_Odm->Remnant_OFDMSwingIdx[RFPath];
1190 /* DBG_871X("+Remanant_OFDMSwingIdx[RFPath %u][Rate 0x%x] = 0x%x\n", RFPath, Rate, pDM_Odm->Remnant_OFDMSwingIdx[RFPath]); */
1197 u8 PHY_GetRateIndexOfTxPowerByRate(u8 Rate)
1333 case MGN_VHT1SS_MCS0:
1336 case MGN_VHT1SS_MCS1:
1339 case MGN_VHT1SS_MCS2:
1342 case MGN_VHT1SS_MCS3:
1345 case MGN_VHT1SS_MCS4:
1348 case MGN_VHT1SS_MCS5:
1351 case MGN_VHT1SS_MCS6:
1354 case MGN_VHT1SS_MCS7:
1357 case MGN_VHT1SS_MCS8:
1360 case MGN_VHT1SS_MCS9:
1363 case MGN_VHT2SS_MCS0:
1366 case MGN_VHT2SS_MCS1:
1369 case MGN_VHT2SS_MCS2:
1372 case MGN_VHT2SS_MCS3:
1375 case MGN_VHT2SS_MCS4:
1378 case MGN_VHT2SS_MCS5:
1381 case MGN_VHT2SS_MCS6:
1384 case MGN_VHT2SS_MCS7:
1387 case MGN_VHT2SS_MCS8:
1390 case MGN_VHT2SS_MCS9:
1393 case MGN_VHT3SS_MCS0:
1396 case MGN_VHT3SS_MCS1:
1399 case MGN_VHT3SS_MCS2:
1402 case MGN_VHT3SS_MCS3:
1405 case MGN_VHT3SS_MCS4:
1408 case MGN_VHT3SS_MCS5:
1411 case MGN_VHT3SS_MCS6:
1414 case MGN_VHT3SS_MCS7:
1417 case MGN_VHT3SS_MCS8:
1420 case MGN_VHT3SS_MCS9:
1423 case MGN_VHT4SS_MCS0:
1426 case MGN_VHT4SS_MCS1:
1429 case MGN_VHT4SS_MCS2:
1432 case MGN_VHT4SS_MCS3:
1435 case MGN_VHT4SS_MCS4:
1438 case MGN_VHT4SS_MCS5:
1441 case MGN_VHT4SS_MCS6:
1444 case MGN_VHT4SS_MCS7:
1447 case MGN_VHT4SS_MCS8:
1450 case MGN_VHT4SS_MCS9:
1454 DBG_871X("Invalid rate 0x%x in %s\n", Rate, __func__);
1461 s8 PHY_GetTxPowerByRate(
1462 struct adapter *padapter, u8 Band, u8 RFPath, u8 TxNum, u8 Rate
1465 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1467 u8 rateIndex = PHY_GetRateIndexOfTxPowerByRate(Rate);
1469 if ((padapter->registrypriv.RegEnableTxPowerByRate == 2 && pHalData->EEPROMRegulatory == 2) ||
1470 padapter->registrypriv.RegEnableTxPowerByRate == 0)
1473 if (Band != BAND_ON_2_4G && Band != BAND_ON_5G) {
1474 DBG_871X("Invalid band %d in %s\n", Band, __func__);
1477 if (RFPath > ODM_RF_PATH_D) {
1478 DBG_871X("Invalid RfPath %d in %s\n", RFPath, __func__);
1481 if (TxNum >= RF_MAX_TX_NUM) {
1482 DBG_871X("Invalid TxNum %d in %s\n", TxNum, __func__);
1485 if (rateIndex >= TX_PWR_BY_RATE_NUM_RATE) {
1486 DBG_871X("Invalid RateIndex %d in %s\n", rateIndex, __func__);
1490 value = pHalData->TxPwrByRateOffset[Band][RFPath][TxNum][rateIndex];
1496 void PHY_SetTxPowerByRate(
1497 struct adapter *padapter,
1505 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1506 u8 rateIndex = PHY_GetRateIndexOfTxPowerByRate(Rate);
1508 if (Band != BAND_ON_2_4G && Band != BAND_ON_5G) {
1509 DBG_871X("Invalid band %d in %s\n", Band, __func__);
1512 if (RFPath > ODM_RF_PATH_D) {
1513 DBG_871X("Invalid RfPath %d in %s\n", RFPath, __func__);
1516 if (TxNum >= RF_MAX_TX_NUM) {
1517 DBG_871X("Invalid TxNum %d in %s\n", TxNum, __func__);
1520 if (rateIndex >= TX_PWR_BY_RATE_NUM_RATE) {
1521 DBG_871X("Invalid RateIndex %d in %s\n", rateIndex, __func__);
1525 pHalData->TxPwrByRateOffset[Band][RFPath][TxNum][rateIndex] = Value;
1528 void PHY_SetTxPowerLevelByPath(struct adapter *Adapter, u8 channel, u8 path)
1530 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1531 bool bIsIn24G = (pHalData->CurrentBandType == BAND_ON_2_4G);
1533 /* if (pMgntInfo->RegNByteAccess == 0) */
1536 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, CCK);
1538 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, OFDM);
1539 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, HT_MCS0_MCS7);
1541 if (pHalData->NumTotalRFPath >= 2)
1542 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, HT_MCS8_MCS15);
1547 void PHY_SetTxPowerIndexByRateArray(
1548 struct adapter *padapter,
1550 enum CHANNEL_WIDTH BandWidth,
1559 for (i = 0; i < RateArraySize; ++i) {
1560 powerIndex = PHY_GetTxPowerIndex(padapter, RFPath, Rates[i], BandWidth, Channel);
1561 PHY_SetTxPowerIndex(padapter, powerIndex, RFPath, Rates[i]);
1565 static s8 phy_GetWorldWideLimit(s8 *LimitTable)
1567 s8 min = LimitTable[0];
1570 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
1571 if (LimitTable[i] < min)
1572 min = LimitTable[i];
1578 static s8 phy_GetChannelIndexOfTxPowerLimit(u8 Band, u8 Channel)
1580 s8 channelIndex = -1;
1581 u8 channel5G[CHANNEL_MAX_NUMBER_5G] = {
1582 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 100, 102,
1583 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130,
1584 132, 134, 136, 138, 140, 142, 144, 149, 151, 153, 155, 157, 159, 161,
1585 163, 165, 167, 168, 169, 171, 173, 175, 177
1588 if (Band == BAND_ON_2_4G)
1589 channelIndex = Channel - 1;
1590 else if (Band == BAND_ON_5G) {
1591 for (i = 0; i < sizeof(channel5G)/sizeof(u8); ++i) {
1592 if (channel5G[i] == Channel)
1596 DBG_871X("Invalid Band %d in %s", Band, __func__);
1598 if (channelIndex == -1)
1599 DBG_871X("Invalid Channel %d of Band %d in %s", Channel, Band, __func__);
1601 return channelIndex;
1604 s8 PHY_GetTxPowerLimit(
1605 struct adapter *Adapter,
1607 enum BAND_TYPE Band,
1608 enum CHANNEL_WIDTH Bandwidth,
1614 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1615 s16 band = -1, regulation = -1, bandwidth = -1, rateSection = -1, channel = -1;
1616 s8 powerLimit = MAX_POWER_INDEX;
1618 if ((Adapter->registrypriv.RegEnableTxPowerLimit == 2 && pHalData->EEPROMRegulatory != 1) ||
1619 Adapter->registrypriv.RegEnableTxPowerLimit == 0)
1620 return MAX_POWER_INDEX;
1622 switch (Adapter->registrypriv.RegPwrTblSel) {
1624 regulation = TXPWR_LMT_ETSI;
1627 regulation = TXPWR_LMT_MKK;
1630 regulation = TXPWR_LMT_FCC;
1634 regulation = TXPWR_LMT_WW;
1638 regulation = (Band == BAND_ON_2_4G) ? pHalData->Regulation2_4G : pHalData->Regulation5G;
1642 /* DBG_871X("pMgntInfo->RegPwrTblSel %d, final regulation %d\n", Adapter->registrypriv.RegPwrTblSel, regulation); */
1645 if (Band == BAND_ON_2_4G)
1647 else if (Band == BAND_ON_5G)
1650 if (Bandwidth == CHANNEL_WIDTH_20)
1652 else if (Bandwidth == CHANNEL_WIDTH_40)
1654 else if (Bandwidth == CHANNEL_WIDTH_80)
1656 else if (Bandwidth == CHANNEL_WIDTH_160)
1660 case MGN_1M: case MGN_2M: case MGN_5_5M: case MGN_11M:
1664 case MGN_6M: case MGN_9M: case MGN_12M: case MGN_18M:
1665 case MGN_24M: case MGN_36M: case MGN_48M: case MGN_54M:
1669 case MGN_MCS0: case MGN_MCS1: case MGN_MCS2: case MGN_MCS3:
1670 case MGN_MCS4: case MGN_MCS5: case MGN_MCS6: case MGN_MCS7:
1674 case MGN_MCS8: case MGN_MCS9: case MGN_MCS10: case MGN_MCS11:
1675 case MGN_MCS12: case MGN_MCS13: case MGN_MCS14: case MGN_MCS15:
1679 case MGN_MCS16: case MGN_MCS17: case MGN_MCS18: case MGN_MCS19:
1680 case MGN_MCS20: case MGN_MCS21: case MGN_MCS22: case MGN_MCS23:
1684 case MGN_MCS24: case MGN_MCS25: case MGN_MCS26: case MGN_MCS27:
1685 case MGN_MCS28: case MGN_MCS29: case MGN_MCS30: case MGN_MCS31:
1689 case MGN_VHT1SS_MCS0: case MGN_VHT1SS_MCS1: case MGN_VHT1SS_MCS2:
1690 case MGN_VHT1SS_MCS3: case MGN_VHT1SS_MCS4: case MGN_VHT1SS_MCS5:
1691 case MGN_VHT1SS_MCS6: case MGN_VHT1SS_MCS7: case MGN_VHT1SS_MCS8:
1692 case MGN_VHT1SS_MCS9:
1696 case MGN_VHT2SS_MCS0: case MGN_VHT2SS_MCS1: case MGN_VHT2SS_MCS2:
1697 case MGN_VHT2SS_MCS3: case MGN_VHT2SS_MCS4: case MGN_VHT2SS_MCS5:
1698 case MGN_VHT2SS_MCS6: case MGN_VHT2SS_MCS7: case MGN_VHT2SS_MCS8:
1699 case MGN_VHT2SS_MCS9:
1703 case MGN_VHT3SS_MCS0: case MGN_VHT3SS_MCS1: case MGN_VHT3SS_MCS2:
1704 case MGN_VHT3SS_MCS3: case MGN_VHT3SS_MCS4: case MGN_VHT3SS_MCS5:
1705 case MGN_VHT3SS_MCS6: case MGN_VHT3SS_MCS7: case MGN_VHT3SS_MCS8:
1706 case MGN_VHT3SS_MCS9:
1710 case MGN_VHT4SS_MCS0: case MGN_VHT4SS_MCS1: case MGN_VHT4SS_MCS2:
1711 case MGN_VHT4SS_MCS3: case MGN_VHT4SS_MCS4: case MGN_VHT4SS_MCS5:
1712 case MGN_VHT4SS_MCS6: case MGN_VHT4SS_MCS7: case MGN_VHT4SS_MCS8:
1713 case MGN_VHT4SS_MCS9:
1718 DBG_871X("Wrong rate 0x%x\n", DataRate);
1722 if (Band == BAND_ON_5G && rateSection == 0)
1723 DBG_871X("Wrong rate 0x%x: No CCK in 5G Band\n", DataRate);
1725 /* workaround for wrong index combination to obtain tx power limit, */
1726 /* OFDM only exists in BW 20M */
1727 if (rateSection == 1)
1730 /* workaround for wrong index combination to obtain tx power limit, */
1731 /* CCK table will only be given in BW 20M */
1732 if (rateSection == 0)
1735 /* workaround for wrong indxe combination to obtain tx power limit, */
1736 /* HT on 80M will reference to HT on 40M */
1737 if ((rateSection == 2 || rateSection == 3) && Band == BAND_ON_5G && bandwidth == 2) {
1741 if (Band == BAND_ON_2_4G)
1742 channel = phy_GetChannelIndexOfTxPowerLimit(BAND_ON_2_4G, Channel);
1743 else if (Band == BAND_ON_5G)
1744 channel = phy_GetChannelIndexOfTxPowerLimit(BAND_ON_5G, Channel);
1745 else if (Band == BAND_ON_BOTH) {
1746 /* BAND_ON_BOTH don't care temporarily */
1749 if (band == -1 || regulation == -1 || bandwidth == -1 ||
1750 rateSection == -1 || channel == -1) {
1751 /* DBG_871X("Wrong index value to access power limit table [band %d][regulation %d][bandwidth %d][rf_path %d][rate_section %d][chnlGroup %d]\n", */
1752 /* band, regulation, bandwidth, RfPath, rateSection, channelGroup); */
1754 return MAX_POWER_INDEX;
1757 if (Band == BAND_ON_2_4G) {
1758 s8 limits[10] = {0}; u8 i = 0;
1759 for (i = 0; i < MAX_REGULATION_NUM; i++)
1760 limits[i] = pHalData->TxPwrLimit_2_4G[i][bandwidth][rateSection][channel][RfPath];
1762 powerLimit = (regulation == TXPWR_LMT_WW) ? phy_GetWorldWideLimit(limits) :
1763 pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channel][RfPath];
1765 } else if (Band == BAND_ON_5G) {
1766 s8 limits[10] = {0}; u8 i = 0;
1767 for (i = 0; i < MAX_REGULATION_NUM; ++i)
1768 limits[i] = pHalData->TxPwrLimit_5G[i][bandwidth][rateSection][channel][RfPath];
1770 powerLimit = (regulation == TXPWR_LMT_WW) ? phy_GetWorldWideLimit(limits) :
1771 pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channel][RfPath];
1773 DBG_871X("No power limit table of the specified band\n");
1775 /* combine 5G VHT & HT rate */
1776 /* 5G 20M and 40M HT and VHT can cross reference */
1778 if (Band == BAND_ON_5G && powerLimit == MAX_POWER_INDEX) {
1779 if (bandwidth == 0 || bandwidth == 1) {
1780 RT_TRACE(COMP_INIT, DBG_LOUD, ("No power limit table of the specified band %d, bandwidth %d, ratesection %d, rf path %d\n",
1781 band, bandwidth, rateSection, RfPath));
1782 if (rateSection == 2)
1783 powerLimit = pHalData->TxPwrLimit_5G[regulation]
1784 [bandwidth][4][channelGroup][RfPath];
1785 else if (rateSection == 4)
1786 powerLimit = pHalData->TxPwrLimit_5G[regulation]
1787 [bandwidth][2][channelGroup][RfPath];
1788 else if (rateSection == 3)
1789 powerLimit = pHalData->TxPwrLimit_5G[regulation]
1790 [bandwidth][5][channelGroup][RfPath];
1791 else if (rateSection == 5)
1792 powerLimit = pHalData->TxPwrLimit_5G[regulation]
1793 [bandwidth][3][channelGroup][RfPath];
1797 /* DBG_871X("TxPwrLmt[Regulation %d][Band %d][BW %d][RFPath %d][Rate 0x%x][Chnl %d] = %d\n", */
1798 /* regulation, pHalData->CurrentBandType, Bandwidth, RfPath, DataRate, Channel, powerLimit); */
1802 static void phy_CrossReferenceHTAndVHTTxPowerLimit(struct adapter *padapter)
1804 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1805 u8 regulation, bw, channel, rateSection;
1808 for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
1809 for (bw = 0; bw < MAX_5G_BANDWITH_NUM; ++bw) {
1810 for (channel = 0; channel < CHANNEL_MAX_NUMBER_5G; ++channel) {
1811 for (rateSection = 0; rateSection < MAX_RATE_SECTION_NUM; ++rateSection) {
1812 tempPwrLmt = pHalData->TxPwrLimit_5G[regulation][bw][rateSection][channel][ODM_RF_PATH_A];
1813 if (tempPwrLmt == MAX_POWER_INDEX) {
1814 u8 baseSection = 2, refSection = 6;
1815 if (bw == 0 || bw == 1) { /* 5G 20M 40M VHT and HT can cross reference */
1816 /* DBG_871X("No power limit table of the specified band %d, bandwidth %d, ratesection %d, channel %d, rf path %d\n", */
1817 /* 1, bw, rateSection, channel, ODM_RF_PATH_A); */
1818 if (rateSection >= 2 && rateSection <= 9) {
1819 if (rateSection == 2) {
1822 } else if (rateSection == 3) {
1825 } else if (rateSection == 4) {
1828 } else if (rateSection == 5) {
1831 } else if (rateSection == 6) {
1834 } else if (rateSection == 7) {
1837 } else if (rateSection == 8) {
1840 } else if (rateSection == 9) {
1844 pHalData->TxPwrLimit_5G[regulation][bw][baseSection][channel][ODM_RF_PATH_A] =
1845 pHalData->TxPwrLimit_5G[regulation][bw][refSection][channel][ODM_RF_PATH_A];
1848 /* DBG_871X("use other value %d", tempPwrLmt); */
1857 void PHY_ConvertTxPowerLimitToPowerIndex(struct adapter *Adapter)
1859 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1860 u8 BW40PwrBasedBm2_4G = 0x2E;
1861 u8 regulation, bw, channel, rateSection;
1862 s8 tempValue = 0, tempPwrLmt = 0;
1865 /* DBG_871X("=====> PHY_ConvertTxPowerLimitToPowerIndex()\n"); */
1867 phy_CrossReferenceHTAndVHTTxPowerLimit(Adapter);
1869 for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
1870 for (bw = 0; bw < MAX_2_4G_BANDWITH_NUM; ++bw) {
1871 for (channel = 0; channel < CHANNEL_MAX_NUMBER_2G; ++channel) {
1872 for (rateSection = 0; rateSection < MAX_RATE_SECTION_NUM; ++rateSection) {
1873 tempPwrLmt = pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][channel][ODM_RF_PATH_A];
1875 for (rfPath = ODM_RF_PATH_A; rfPath < MAX_RF_PATH_NUM; ++rfPath) {
1876 if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) {
1877 if (rateSection == 5) /* HT 4T */
1878 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_4TX, HT_MCS24_MCS31);
1879 else if (rateSection == 4) /* HT 3T */
1880 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_3TX, HT_MCS16_MCS23);
1881 else if (rateSection == 3) /* HT 2T */
1882 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_2TX, HT_MCS8_MCS15);
1883 else if (rateSection == 2) /* HT 1T */
1884 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_1TX, HT_MCS0_MCS7);
1885 else if (rateSection == 1) /* OFDM */
1886 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_1TX, OFDM);
1887 else if (rateSection == 0) /* CCK */
1888 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_1TX, CCK);
1890 BW40PwrBasedBm2_4G = Adapter->registrypriv.RegPowerBase * 2;
1892 if (tempPwrLmt != MAX_POWER_INDEX) {
1893 tempValue = tempPwrLmt - BW40PwrBasedBm2_4G;
1894 pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][channel][rfPath] = tempValue;
1902 /* DBG_871X("<===== PHY_ConvertTxPowerLimitToPowerIndex()\n"); */
1905 void PHY_InitTxPowerLimit(struct adapter *Adapter)
1907 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1910 /* DBG_871X("=====> PHY_InitTxPowerLimit()!\n"); */
1912 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
1913 for (j = 0; j < MAX_2_4G_BANDWITH_NUM; ++j)
1914 for (k = 0; k < MAX_RATE_SECTION_NUM; ++k)
1915 for (m = 0; m < CHANNEL_MAX_NUMBER_2G; ++m)
1916 for (l = 0; l < MAX_RF_PATH_NUM; ++l)
1917 pHalData->TxPwrLimit_2_4G[i][j][k][m][l] = MAX_POWER_INDEX;
1920 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
1921 for (j = 0; j < MAX_5G_BANDWITH_NUM; ++j)
1922 for (k = 0; k < MAX_RATE_SECTION_NUM; ++k)
1923 for (m = 0; m < CHANNEL_MAX_NUMBER_5G; ++m)
1924 for (l = 0; l < MAX_RF_PATH_NUM; ++l)
1925 pHalData->TxPwrLimit_5G[i][j][k][m][l] = MAX_POWER_INDEX;
1928 /* DBG_871X("<===== PHY_InitTxPowerLimit()!\n"); */
1931 void PHY_SetTxPowerLimit(
1932 struct adapter *Adapter,
1942 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1943 u8 regulation = 0, bandwidth = 0, rateSection = 0, channel;
1944 s8 powerLimit = 0, prevPowerLimit, channelIndex;
1946 /* DBG_871X("Index of power limit table [band %s][regulation %s][bw %s][rate section %s][rf path %s][chnl %s][val %s]\n", */
1947 /* Band, Regulation, Bandwidth, RateSection, RfPath, Channel, PowerLimit); */
1949 if (!GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel) ||
1950 !GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit))
1951 DBG_871X("Illegal index of power limit table [chnl %s][val %s]\n", Channel, PowerLimit);
1953 powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit;
1955 if (eqNByte(Regulation, (u8 *)("FCC"), 3))
1957 else if (eqNByte(Regulation, (u8 *)("MKK"), 3))
1959 else if (eqNByte(Regulation, (u8 *)("ETSI"), 4))
1961 else if (eqNByte(Regulation, (u8 *)("WW13"), 4))
1964 if (eqNByte(RateSection, (u8 *)("CCK"), 3) && eqNByte(RfPath, (u8 *)("1T"), 2))
1966 else if (eqNByte(RateSection, (u8 *)("OFDM"), 4) && eqNByte(RfPath, (u8 *)("1T"), 2))
1968 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("1T"), 2))
1970 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("2T"), 2))
1972 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("3T"), 2))
1974 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("4T"), 2))
1976 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("1T"), 2))
1978 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("2T"), 2))
1980 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("3T"), 2))
1982 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("4T"), 2))
1985 DBG_871X("Wrong rate section!\n");
1990 if (eqNByte(Bandwidth, (u8 *)("20M"), 3))
1992 else if (eqNByte(Bandwidth, (u8 *)("40M"), 3))
1994 else if (eqNByte(Bandwidth, (u8 *)("80M"), 3))
1996 else if (eqNByte(Bandwidth, (u8 *)("160M"), 4))
1999 if (eqNByte(Band, (u8 *)("2.4G"), 4)) {
2000 channelIndex = phy_GetChannelIndexOfTxPowerLimit(BAND_ON_2_4G, channel);
2002 if (channelIndex == -1)
2005 prevPowerLimit = pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A];
2007 if (powerLimit < prevPowerLimit)
2008 pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A] = powerLimit;
2010 /* DBG_871X("2.4G Band value : [regulation %d][bw %d][rate_section %d][chnl %d][val %d]\n", */
2011 /* regulation, bandwidth, rateSection, channelIndex, pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A]); */
2012 } else if (eqNByte(Band, (u8 *)("5G"), 2)) {
2013 channelIndex = phy_GetChannelIndexOfTxPowerLimit(BAND_ON_5G, channel);
2015 if (channelIndex == -1)
2018 prevPowerLimit = pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A];
2020 if (powerLimit < prevPowerLimit)
2021 pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A] = powerLimit;
2023 /* DBG_871X("5G Band value : [regulation %d][bw %d][rate_section %d][chnl %d][val %d]\n", */
2024 /* regulation, bandwidth, rateSection, channel, pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A]); */
2026 DBG_871X("Cannot recognize the band info in %s\n", Band);
2031 u8 PHY_GetTxPowerIndex(
2032 struct adapter *padapter,
2035 enum CHANNEL_WIDTH BandWidth,
2039 return PHY_GetTxPowerIndex_8723B(padapter, RFPath, Rate, BandWidth, Channel);
2042 void PHY_SetTxPowerIndex(
2043 struct adapter *padapter, u32 PowerIndex, u8 RFPath, u8 Rate
2046 PHY_SetTxPowerIndex_8723B(padapter, PowerIndex, RFPath, Rate);
2049 void Hal_ChannelPlanToRegulation(struct adapter *Adapter, u16 ChannelPlan)
2051 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2052 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2053 pHalData->Regulation5G = TXPWR_LMT_WW;
2055 switch (ChannelPlan) {
2056 case RT_CHANNEL_DOMAIN_WORLD_NULL:
2057 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2059 case RT_CHANNEL_DOMAIN_ETSI1_NULL:
2060 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2062 case RT_CHANNEL_DOMAIN_FCC1_NULL:
2063 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2065 case RT_CHANNEL_DOMAIN_MKK1_NULL:
2066 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2068 case RT_CHANNEL_DOMAIN_ETSI2_NULL:
2069 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2071 case RT_CHANNEL_DOMAIN_FCC1_FCC1:
2072 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2073 pHalData->Regulation5G = TXPWR_LMT_FCC;
2075 case RT_CHANNEL_DOMAIN_WORLD_ETSI1:
2076 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2077 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2079 case RT_CHANNEL_DOMAIN_MKK1_MKK1:
2080 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2081 pHalData->Regulation5G = TXPWR_LMT_MKK;
2083 case RT_CHANNEL_DOMAIN_WORLD_KCC1:
2084 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2085 pHalData->Regulation5G = TXPWR_LMT_MKK;
2087 case RT_CHANNEL_DOMAIN_WORLD_FCC2:
2088 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2089 pHalData->Regulation5G = TXPWR_LMT_FCC;
2091 case RT_CHANNEL_DOMAIN_WORLD_FCC3:
2092 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2093 pHalData->Regulation5G = TXPWR_LMT_FCC;
2095 case RT_CHANNEL_DOMAIN_WORLD_FCC4:
2096 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2097 pHalData->Regulation5G = TXPWR_LMT_FCC;
2099 case RT_CHANNEL_DOMAIN_WORLD_FCC5:
2100 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2101 pHalData->Regulation5G = TXPWR_LMT_FCC;
2103 case RT_CHANNEL_DOMAIN_WORLD_FCC6:
2104 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2105 pHalData->Regulation5G = TXPWR_LMT_FCC;
2107 case RT_CHANNEL_DOMAIN_FCC1_FCC7:
2108 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2109 pHalData->Regulation5G = TXPWR_LMT_FCC;
2111 case RT_CHANNEL_DOMAIN_WORLD_ETSI2:
2112 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2113 pHalData->Regulation5G = TXPWR_LMT_FCC;
2115 case RT_CHANNEL_DOMAIN_WORLD_ETSI3:
2116 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2117 pHalData->Regulation5G = TXPWR_LMT_FCC;
2119 case RT_CHANNEL_DOMAIN_MKK1_MKK2:
2120 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2121 pHalData->Regulation5G = TXPWR_LMT_FCC;
2123 case RT_CHANNEL_DOMAIN_MKK1_MKK3:
2124 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2125 pHalData->Regulation5G = TXPWR_LMT_FCC;
2127 case RT_CHANNEL_DOMAIN_FCC1_NCC1:
2128 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2129 pHalData->Regulation5G = TXPWR_LMT_FCC;
2131 case RT_CHANNEL_DOMAIN_FCC1_NCC2:
2132 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2133 pHalData->Regulation5G = TXPWR_LMT_FCC;
2135 case RT_CHANNEL_DOMAIN_GLOBAL_NULL:
2136 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2137 pHalData->Regulation5G = TXPWR_LMT_WW;
2139 case RT_CHANNEL_DOMAIN_ETSI1_ETSI4:
2140 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2141 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2143 case RT_CHANNEL_DOMAIN_FCC1_FCC2:
2144 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2145 pHalData->Regulation5G = TXPWR_LMT_FCC;
2147 case RT_CHANNEL_DOMAIN_FCC1_NCC3:
2148 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2149 pHalData->Regulation5G = TXPWR_LMT_FCC;
2151 case RT_CHANNEL_DOMAIN_WORLD_ETSI5:
2152 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2153 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2155 case RT_CHANNEL_DOMAIN_FCC1_FCC8:
2156 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2157 pHalData->Regulation5G = TXPWR_LMT_FCC;
2159 case RT_CHANNEL_DOMAIN_WORLD_ETSI6:
2160 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2161 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2163 case RT_CHANNEL_DOMAIN_WORLD_ETSI7:
2164 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2165 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2167 case RT_CHANNEL_DOMAIN_WORLD_ETSI8:
2168 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2169 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2171 case RT_CHANNEL_DOMAIN_WORLD_ETSI9:
2172 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2173 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2175 case RT_CHANNEL_DOMAIN_WORLD_ETSI10:
2176 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2177 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2179 case RT_CHANNEL_DOMAIN_WORLD_ETSI11:
2180 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2181 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2183 case RT_CHANNEL_DOMAIN_FCC1_NCC4:
2184 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2185 pHalData->Regulation5G = TXPWR_LMT_FCC;
2187 case RT_CHANNEL_DOMAIN_WORLD_ETSI12:
2188 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2189 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2191 case RT_CHANNEL_DOMAIN_FCC1_FCC9:
2192 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2193 pHalData->Regulation5G = TXPWR_LMT_FCC;
2195 case RT_CHANNEL_DOMAIN_WORLD_ETSI13:
2196 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2197 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2199 case RT_CHANNEL_DOMAIN_FCC1_FCC10:
2200 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2201 pHalData->Regulation5G = TXPWR_LMT_FCC;
2203 case RT_CHANNEL_DOMAIN_REALTEK_DEFINE: /* Realtek Reserve */
2204 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2205 pHalData->Regulation5G = TXPWR_LMT_WW;
2213 static char file_path_bs[PATH_MAX];
2215 #define GetLineFromBuffer(buffer) strsep(&buffer, "\n")
2217 int phy_ConfigMACWithParaFile(struct adapter *Adapter, char *pFileName)
2219 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2220 int rlen = 0, rtStatus = _FAIL;
2221 char *szLine, *ptmp;
2222 u32 u4bRegOffset, u4bRegValue, u4bMove;
2224 if (!(Adapter->registrypriv.load_phy_file & LOAD_MAC_PARA_FILE))
2227 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2229 if ((pHalData->mac_reg_len == 0) && (pHalData->mac_reg == NULL)) {
2230 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2232 if (rtw_is_file_readable(file_path_bs) == true) {
2233 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2235 rtStatus = _SUCCESS;
2236 pHalData->mac_reg = vzalloc(rlen);
2237 if (pHalData->mac_reg) {
2238 memcpy(pHalData->mac_reg, pHalData->para_file_buf, rlen);
2239 pHalData->mac_reg_len = rlen;
2241 DBG_871X("%s mac_reg alloc fail !\n", __func__);
2245 if ((pHalData->mac_reg_len != 0) && (pHalData->mac_reg != NULL)) {
2246 memcpy(pHalData->para_file_buf, pHalData->mac_reg, pHalData->mac_reg_len);
2247 rtStatus = _SUCCESS;
2249 DBG_871X("%s(): Critical Error !!!\n", __func__);
2252 if (rtStatus == _SUCCESS) {
2253 ptmp = pHalData->para_file_buf;
2254 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2255 if (!IsCommentString(szLine)) {
2256 /* Get 1st hex value as register offset */
2257 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2258 if (u4bRegOffset == 0xffff) /* Ending. */
2261 /* Get 2nd hex value as register value. */
2263 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove))
2264 rtw_write8(Adapter, u4bRegOffset, (u8)u4bRegValue);
2269 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2274 int phy_ConfigBBWithParaFile(
2275 struct adapter *Adapter, char *pFileName, u32 ConfigType
2278 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2279 int rlen = 0, rtStatus = _FAIL;
2280 char *szLine, *ptmp;
2281 u32 u4bRegOffset, u4bRegValue, u4bMove;
2283 u32 *pBufLen = NULL;
2285 if (!(Adapter->registrypriv.load_phy_file & LOAD_BB_PARA_FILE))
2288 switch (ConfigType) {
2289 case CONFIG_BB_PHY_REG:
2290 pBuf = pHalData->bb_phy_reg;
2291 pBufLen = &pHalData->bb_phy_reg_len;
2293 case CONFIG_BB_AGC_TAB:
2294 pBuf = pHalData->bb_agc_tab;
2295 pBufLen = &pHalData->bb_agc_tab_len;
2298 DBG_871X("Unknown ConfigType!! %d\r\n", ConfigType);
2302 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2304 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2305 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2307 if (rtw_is_file_readable(file_path_bs) == true) {
2308 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2310 rtStatus = _SUCCESS;
2311 pBuf = vzalloc(rlen);
2313 memcpy(pBuf, pHalData->para_file_buf, rlen);
2316 switch (ConfigType) {
2317 case CONFIG_BB_PHY_REG:
2318 pHalData->bb_phy_reg = pBuf;
2320 case CONFIG_BB_AGC_TAB:
2321 pHalData->bb_agc_tab = pBuf;
2325 DBG_871X("%s(): ConfigType %d alloc fail !\n", __func__, ConfigType);
2329 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2330 memcpy(pHalData->para_file_buf, pBuf, *pBufLen);
2331 rtStatus = _SUCCESS;
2333 DBG_871X("%s(): Critical Error !!!\n", __func__);
2336 if (rtStatus == _SUCCESS) {
2337 ptmp = pHalData->para_file_buf;
2338 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2339 if (!IsCommentString(szLine)) {
2340 /* Get 1st hex value as register offset. */
2341 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2342 if (u4bRegOffset == 0xffff) /* Ending. */
2344 else if (u4bRegOffset == 0xfe || u4bRegOffset == 0xffe)
2346 else if (u4bRegOffset == 0xfd)
2348 else if (u4bRegOffset == 0xfc)
2350 else if (u4bRegOffset == 0xfb)
2352 else if (u4bRegOffset == 0xfa)
2354 else if (u4bRegOffset == 0xf9)
2357 /* Get 2nd hex value as register value. */
2359 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2360 /* DBG_871X("[BB-ADDR]%03lX =%08lX\n", u4bRegOffset, u4bRegValue); */
2361 PHY_SetBBReg(Adapter, u4bRegOffset, bMaskDWord, u4bRegValue);
2363 if (u4bRegOffset == 0xa24)
2364 pHalData->odmpriv.RFCalibrateInfo.RegA24 = u4bRegValue;
2366 /* Add 1us delay between BB/RF register setting. */
2373 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2378 static void phy_DecryptBBPgParaFile(struct adapter *Adapter, char *buffer)
2383 char *BufOfLines, *ptmp;
2385 /* DBG_871X("=====>phy_DecryptBBPgParaFile()\n"); */
2386 /* 32 the ascii code of the first visable char, 126 the last one */
2387 for (i = 0; i < 95; ++i)
2388 map[i] = (u8) (94 - i);
2392 for (BufOfLines = GetLineFromBuffer(ptmp); BufOfLines != NULL; BufOfLines = GetLineFromBuffer(ptmp)) {
2393 /* DBG_871X("Encrypted Line: %s\n", BufOfLines); */
2395 for (j = 0; j < strlen(BufOfLines); ++j) {
2396 currentChar = BufOfLines[j];
2398 if (currentChar == '\0')
2401 currentChar -= (u8) ((((i + j) * 3) % 128));
2403 BufOfLines[j] = map[currentChar - 32] + 32;
2405 /* DBG_871X("Decrypted Line: %s\n", BufOfLines); */
2406 if (strlen(BufOfLines) != 0)
2408 BufOfLines[strlen(BufOfLines)] = '\n';
2412 static int phy_ParseBBPgParaFile(struct adapter *Adapter, char *buffer)
2414 int rtStatus = _SUCCESS;
2415 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2416 char *szLine, *ptmp;
2417 u32 u4bRegOffset, u4bRegMask, u4bRegValue;
2419 bool firstLine = true;
2421 u8 band = 0, rf_path = 0;
2423 /* DBG_871X("=====>phy_ParseBBPgParaFile()\n"); */
2425 if (Adapter->registrypriv.RegDecryptCustomFile == 1)
2426 phy_DecryptBBPgParaFile(Adapter, buffer);
2429 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2430 if (!IsCommentString(szLine)) {
2431 if (isAllSpaceOrTab(szLine, sizeof(*szLine)))
2434 /* Get header info (relative value or exact value) */
2436 if (eqNByte(szLine, (u8 *)("#[v1]"), 5)) {
2438 pHalData->odmpriv.PhyRegPgVersion = szLine[3] - '0';
2439 /* DBG_871X("This is a new format PHY_REG_PG.txt\n"); */
2440 } else if (eqNByte(szLine, (u8 *)("#[v0]"), 5)) {
2441 pHalData->odmpriv.PhyRegPgVersion = szLine[3] - '0';
2442 /* DBG_871X("This is a old format PHY_REG_PG.txt ok\n"); */
2444 DBG_871X("The format in PHY_REG_PG are invalid %s\n", szLine);
2448 if (eqNByte(szLine + 5, (u8 *)("[Exact]#"), 8)) {
2449 pHalData->odmpriv.PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE;
2450 /* DBG_871X("The values in PHY_REG_PG are exact values ok\n"); */
2453 } else if (eqNByte(szLine + 5, (u8 *)("[Relative]#"), 11)) {
2454 pHalData->odmpriv.PhyRegPgValueType = PHY_REG_PG_RELATIVE_VALUE;
2455 /* DBG_871X("The values in PHY_REG_PG are relative values ok\n"); */
2459 DBG_871X("The values in PHY_REG_PG are invalid %s\n", szLine);
2464 if (pHalData->odmpriv.PhyRegPgVersion == 0) {
2465 /* Get 1st hex value as register offset. */
2466 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2468 if (u4bRegOffset == 0xffff) /* Ending. */
2471 /* Get 2nd hex value as register mask. */
2472 if (GetHexValueFromString(szLine, &u4bRegMask, &u4bMove))
2477 if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_RELATIVE_VALUE) {
2478 /* Get 3rd hex value as register value. */
2479 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2480 PHY_StoreTxPowerByRate(Adapter, 0, 0, 1, u4bRegOffset, u4bRegMask, u4bRegValue);
2481 /* DBG_871X("[ADDR] %03X =%08X Mask =%08x\n", u4bRegOffset, u4bRegValue, u4bRegMask); */
2484 } else if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) {
2485 u32 combineValue = 0;
2486 u8 integer = 0, fraction = 0;
2488 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2496 combineValue |= (((integer / 10) << 4) + (integer % 10));
2497 /* DBG_871X(" %d", integer); */
2499 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2508 combineValue |= (((integer / 10) << 4) + (integer % 10));
2509 /* DBG_871X(" %d", integer); */
2511 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2520 combineValue |= (((integer / 10) << 4) + (integer % 10));
2521 /* DBG_871X(" %d", integer); */
2523 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2532 combineValue |= (((integer / 10) << 4) + (integer % 10));
2533 /* DBG_871X(" %d", integer); */
2534 PHY_StoreTxPowerByRate(Adapter, 0, 0, 1, u4bRegOffset, u4bRegMask, combineValue);
2536 /* DBG_871X("[ADDR] 0x%3x = 0x%4x\n", u4bRegOffset, combineValue); */
2539 } else if (pHalData->odmpriv.PhyRegPgVersion > 0) {
2542 if (eqNByte(szLine, "0xffff", 6))
2545 if (!eqNByte("#[END]#", szLine, 7)) {
2546 /* load the table label info */
2547 if (szLine[0] == '#') {
2549 if (eqNByte(szLine, "#[2.4G]", 7)) {
2550 band = BAND_ON_2_4G;
2552 } else if (eqNByte(szLine, "#[5G]", 5)) {
2556 DBG_871X("Invalid band %s in PHY_REG_PG.txt\n", szLine);
2560 rf_path = szLine[index] - 'A';
2561 /* DBG_871X(" Table label Band %d, RfPath %d\n", band, rf_path); */
2562 } else { /* load rows of tables */
2563 if (szLine[1] == '1')
2565 else if (szLine[1] == '2')
2567 else if (szLine[1] == '3')
2569 else if (szLine[1] == '4')
2572 DBG_871X("Invalid row in PHY_REG_PG.txt %c\n", szLine[1]);
2576 while (szLine[index] != ']')
2578 ++index;/* skip ] */
2580 /* Get 2nd hex value as register offset. */
2582 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove))
2587 /* Get 2nd hex value as register mask. */
2588 if (GetHexValueFromString(szLine, &u4bRegMask, &u4bMove))
2593 if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_RELATIVE_VALUE) {
2594 /* Get 3rd hex value as register value. */
2595 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2596 PHY_StoreTxPowerByRate(Adapter, band, rf_path, tx_num, u4bRegOffset, u4bRegMask, u4bRegValue);
2597 /* DBG_871X("[ADDR] %03X (tx_num %d) =%08X Mask =%08x\n", u4bRegOffset, tx_num, u4bRegValue, u4bRegMask); */
2600 } else if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) {
2601 u32 combineValue = 0;
2602 u8 integer = 0, fraction = 0;
2604 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2612 combineValue |= (((integer / 10) << 4) + (integer % 10));
2613 /* DBG_871X(" %d", integer); */
2615 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2624 combineValue |= (((integer / 10) << 4) + (integer % 10));
2625 /* DBG_871X(" %d", integer); */
2627 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2636 combineValue |= (((integer / 10) << 4) + (integer % 10));
2637 /* DBG_871X(" %d", integer); */
2639 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2648 combineValue |= (((integer / 10) << 4) + (integer % 10));
2649 /* DBG_871X(" %d", integer); */
2650 PHY_StoreTxPowerByRate(Adapter, band, rf_path, tx_num, u4bRegOffset, u4bRegMask, combineValue);
2652 /* DBG_871X("[ADDR] 0x%3x (tx_num %d) = 0x%4x\n", u4bRegOffset, tx_num, combineValue); */
2659 /* DBG_871X("<=====phy_ParseBBPgParaFile()\n"); */
2663 int phy_ConfigBBWithPgParaFile(struct adapter *Adapter, char *pFileName)
2665 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2666 int rlen = 0, rtStatus = _FAIL;
2668 if (!(Adapter->registrypriv.load_phy_file & LOAD_BB_PG_PARA_FILE))
2671 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2673 if ((pHalData->bb_phy_reg_pg_len == 0) && (pHalData->bb_phy_reg_pg == NULL)) {
2674 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2676 if (rtw_is_file_readable(file_path_bs) == true) {
2677 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2679 rtStatus = _SUCCESS;
2680 pHalData->bb_phy_reg_pg = vzalloc(rlen);
2681 if (pHalData->bb_phy_reg_pg) {
2682 memcpy(pHalData->bb_phy_reg_pg, pHalData->para_file_buf, rlen);
2683 pHalData->bb_phy_reg_pg_len = rlen;
2685 DBG_871X("%s bb_phy_reg_pg alloc fail !\n", __func__);
2689 if ((pHalData->bb_phy_reg_pg_len != 0) && (pHalData->bb_phy_reg_pg != NULL)) {
2690 memcpy(pHalData->para_file_buf, pHalData->bb_phy_reg_pg, pHalData->bb_phy_reg_pg_len);
2691 rtStatus = _SUCCESS;
2693 DBG_871X("%s(): Critical Error !!!\n", __func__);
2696 if (rtStatus == _SUCCESS) {
2697 /* DBG_871X("phy_ConfigBBWithPgParaFile(): read %s ok\n", pFileName); */
2698 phy_ParseBBPgParaFile(Adapter, pHalData->para_file_buf);
2700 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2705 int PHY_ConfigRFWithParaFile(
2706 struct adapter *Adapter, char *pFileName, u8 eRFPath
2709 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2710 int rlen = 0, rtStatus = _FAIL;
2711 char *szLine, *ptmp;
2712 u32 u4bRegOffset, u4bRegValue, u4bMove;
2715 u32 *pBufLen = NULL;
2717 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_PARA_FILE))
2722 pBuf = pHalData->rf_radio_a;
2723 pBufLen = &pHalData->rf_radio_a_len;
2726 pBuf = pHalData->rf_radio_b;
2727 pBufLen = &pHalData->rf_radio_b_len;
2730 DBG_871X("Unknown RF path!! %d\r\n", eRFPath);
2734 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2736 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2737 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2739 if (rtw_is_file_readable(file_path_bs) == true) {
2740 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2742 rtStatus = _SUCCESS;
2743 pBuf = vzalloc(rlen);
2745 memcpy(pBuf, pHalData->para_file_buf, rlen);
2750 pHalData->rf_radio_a = pBuf;
2753 pHalData->rf_radio_b = pBuf;
2757 DBG_871X("%s(): eRFPath =%d alloc fail !\n", __func__, eRFPath);
2761 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2762 memcpy(pHalData->para_file_buf, pBuf, *pBufLen);
2763 rtStatus = _SUCCESS;
2765 DBG_871X("%s(): Critical Error !!!\n", __func__);
2768 if (rtStatus == _SUCCESS) {
2769 /* DBG_871X("%s(): read %s successfully\n", __func__, pFileName); */
2771 ptmp = pHalData->para_file_buf;
2772 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2773 if (!IsCommentString(szLine)) {
2774 /* Get 1st hex value as register offset. */
2775 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2776 if (u4bRegOffset == 0xfe || u4bRegOffset == 0xffe) /* Deay specific ms. Only RF configuration require delay. */
2778 else if (u4bRegOffset == 0xfd) {
2780 for (i = 0; i < 100; i++)
2781 udelay(MAX_STALL_TIME);
2782 } else if (u4bRegOffset == 0xfc) {
2784 for (i = 0; i < 20; i++)
2785 udelay(MAX_STALL_TIME);
2786 } else if (u4bRegOffset == 0xfb)
2788 else if (u4bRegOffset == 0xfa)
2790 else if (u4bRegOffset == 0xf9)
2792 else if (u4bRegOffset == 0xffff)
2795 /* Get 2nd hex value as register value. */
2797 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2798 PHY_SetRFReg(Adapter, eRFPath, u4bRegOffset, bRFRegOffsetMask, u4bRegValue);
2800 /* Temp add, for frequency lock, if no delay, that may cause */
2801 /* frequency shift, ex: 2412MHz => 2417MHz */
2802 /* If frequency shift, the following action may works. */
2803 /* Fractional-N table in radio_a.txt */
2804 /* 0x2a 0x00001 channel 1 */
2805 /* 0x2b 0x00808 frequency divider. */
2814 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2819 static void initDeltaSwingIndexTables(
2820 struct adapter *Adapter,
2829 #define STR_EQUAL_5G(_band, _path, _sign, _rate, _chnl) \
2830 ((strcmp(Band, _band) == 0) && (strcmp(Path, _path) == 0) && (strcmp(Sign, _sign) == 0) &&\
2831 (strcmp(Rate, _rate) == 0) && (strcmp(Channel, _chnl) == 0)\
2833 #define STR_EQUAL_2G(_band, _path, _sign, _rate) \
2834 ((strcmp(Band, _band) == 0) && (strcmp(Path, _path) == 0) && (strcmp(Sign, _sign) == 0) &&\
2835 (strcmp(Rate, _rate) == 0)\
2838 #define STORE_SWING_TABLE(_array, _iteratedIdx) \
2839 for (token = strsep(&Data, delim); token != NULL; token = strsep(&Data, delim)) {\
2840 sscanf(token, "%d", &idx);\
2841 _array[_iteratedIdx++] = (u8)idx;\
2844 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2845 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
2846 PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
2852 /* DBG_871X("===>initDeltaSwingIndexTables(): Band: %s;\nPath: %s;\nSign: %s;\nChannel: %s;\nRate: %s;\n, Data: %s;\n", */
2853 /* Band, Path, Sign, Channel, Rate, Data); */
2855 if (STR_EQUAL_2G("2G", "A", "+", "CCK")) {
2856 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_P, j);
2857 } else if (STR_EQUAL_2G("2G", "A", "-", "CCK")) {
2858 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_N, j);
2859 } else if (STR_EQUAL_2G("2G", "B", "+", "CCK")) {
2860 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_P, j);
2861 } else if (STR_EQUAL_2G("2G", "B", "-", "CCK")) {
2862 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_N, j);
2863 } else if (STR_EQUAL_2G("2G", "A", "+", "ALL")) {
2864 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GA_P, j);
2865 } else if (STR_EQUAL_2G("2G", "A", "-", "ALL")) {
2866 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GA_N, j);
2867 } else if (STR_EQUAL_2G("2G", "B", "+", "ALL")) {
2868 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GB_P, j);
2869 } else if (STR_EQUAL_2G("2G", "B", "-", "ALL")) {
2870 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GB_N, j);
2871 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "0")) {
2872 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[0], j);
2873 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "0")) {
2874 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[0], j);
2875 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "0")) {
2876 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[0], j);
2877 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "0")) {
2878 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[0], j);
2879 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "1")) {
2880 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[1], j);
2881 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "1")) {
2882 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[1], j);
2883 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "1")) {
2884 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[1], j);
2885 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "1")) {
2886 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[1], j);
2887 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "2")) {
2888 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[2], j);
2889 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "2")) {
2890 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[2], j);
2891 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "2")) {
2892 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[2], j);
2893 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "2")) {
2894 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[2], j);
2895 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "3")) {
2896 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[3], j);
2897 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "3")) {
2898 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[3], j);
2899 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "3")) {
2900 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[3], j);
2901 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "3")) {
2902 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[3], j);
2904 DBG_871X("===>initDeltaSwingIndexTables(): The input is invalid!!\n");
2907 int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName)
2909 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2910 int rlen = 0, rtStatus = _FAIL;
2911 char *szLine, *ptmp;
2914 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_TRACK_PARA_FILE))
2917 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2919 if ((pHalData->rf_tx_pwr_track_len == 0) && (pHalData->rf_tx_pwr_track == NULL)) {
2920 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2922 if (rtw_is_file_readable(file_path_bs) == true) {
2923 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2925 rtStatus = _SUCCESS;
2926 pHalData->rf_tx_pwr_track = vzalloc(rlen);
2927 if (pHalData->rf_tx_pwr_track) {
2928 memcpy(pHalData->rf_tx_pwr_track, pHalData->para_file_buf, rlen);
2929 pHalData->rf_tx_pwr_track_len = rlen;
2931 DBG_871X("%s rf_tx_pwr_track alloc fail !\n", __func__);
2935 if ((pHalData->rf_tx_pwr_track_len != 0) && (pHalData->rf_tx_pwr_track != NULL)) {
2936 memcpy(pHalData->para_file_buf, pHalData->rf_tx_pwr_track, pHalData->rf_tx_pwr_track_len);
2937 rtStatus = _SUCCESS;
2939 DBG_871X("%s(): Critical Error !!!\n", __func__);
2942 if (rtStatus == _SUCCESS) {
2943 /* DBG_871X("%s(): read %s successfully\n", __func__, pFileName); */
2945 ptmp = pHalData->para_file_buf;
2946 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2947 if (!IsCommentString(szLine)) {
2948 char band[5] = "", path[5] = "", sign[5] = "";
2949 char chnl[5] = "", rate[10] = "";
2950 char data[300] = ""; /* 100 is too small */
2952 if (strlen(szLine) < 10 || szLine[0] != '[')
2955 strncpy(band, szLine+1, 2);
2956 strncpy(path, szLine+5, 1);
2957 strncpy(sign, szLine+8, 1);
2959 i = 10; /* szLine+10 */
2960 if (!ParseQualifiedString(szLine, &i, rate, '[', ']')) {
2961 /* DBG_871X("Fail to parse rate!\n"); */
2963 if (!ParseQualifiedString(szLine, &i, chnl, '[', ']')) {
2964 /* DBG_871X("Fail to parse channel group!\n"); */
2966 while (szLine[i] != '{' && i < strlen(szLine))
2968 if (!ParseQualifiedString(szLine, &i, data, '{', '}')) {
2969 /* DBG_871X("Fail to parse data!\n"); */
2972 initDeltaSwingIndexTables(Adapter, band, path, sign, chnl, rate, data);
2976 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2981 static int phy_ParsePowerLimitTableFile(struct adapter *Adapter, char *buffer)
2983 u32 i = 0, forCnt = 0;
2984 u8 loadingStage = 0, limitValue = 0, fraction = 0;
2985 char *szLine, *ptmp;
2986 int rtStatus = _SUCCESS;
2987 char band[10], bandwidth[10], rateSection[10],
2988 regulation[TXPWR_LMT_MAX_REGULATION_NUM][10], rfPath[10], colNumBuf[10];
2991 DBG_871X("===>phy_ParsePowerLimitTableFile()\n");
2993 if (Adapter->registrypriv.RegDecryptCustomFile == 1)
2994 phy_DecryptBBPgParaFile(Adapter, buffer);
2997 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2999 if (IsCommentString(szLine)) {
3003 if (loadingStage == 0) {
3004 for (forCnt = 0; forCnt < TXPWR_LMT_MAX_REGULATION_NUM; ++forCnt)
3005 memset((void *) regulation[forCnt], 0, 10);
3007 memset((void *) band, 0, 10);
3008 memset((void *) bandwidth, 0, 10);
3009 memset((void *) rateSection, 0, 10);
3010 memset((void *) rfPath, 0, 10);
3011 memset((void *) colNumBuf, 0, 10);
3013 if (szLine[0] != '#' || szLine[1] != '#')
3016 /* skip the space */
3018 while (szLine[i] == ' ' || szLine[i] == '\t')
3021 szLine[--i] = ' '; /* return the space in front of the regulation info */
3023 /* Parse the label of the table */
3024 if (!ParseQualifiedString(szLine, &i, band, ' ', ',')) {
3025 DBG_871X("Fail to parse band!\n");
3028 if (!ParseQualifiedString(szLine, &i, bandwidth, ' ', ',')) {
3029 DBG_871X("Fail to parse bandwidth!\n");
3032 if (!ParseQualifiedString(szLine, &i, rfPath, ' ', ',')) {
3033 DBG_871X("Fail to parse rf path!\n");
3036 if (!ParseQualifiedString(szLine, &i, rateSection, ' ', ',')) {
3037 DBG_871X("Fail to parse rate!\n");
3042 } else if (loadingStage == 1) {
3043 if (szLine[0] != '#' || szLine[1] != '#')
3046 /* skip the space */
3048 while (szLine[i] == ' ' || szLine[i] == '\t')
3051 if (!eqNByte((u8 *)(szLine + i), (u8 *)("START"), 5)) {
3052 DBG_871X("Lost \"## START\" label\n");
3057 } else if (loadingStage == 2) {
3058 if (szLine[0] != '#' || szLine[1] != '#')
3061 /* skip the space */
3063 while (szLine[i] == ' ' || szLine[i] == '\t')
3066 if (!ParseQualifiedString(szLine, &i, colNumBuf, '#', '#')) {
3067 DBG_871X("Fail to parse column number!\n");
3071 if (!GetU1ByteIntegerFromStringInDecimal(colNumBuf, &colNum))
3074 if (colNum > TXPWR_LMT_MAX_REGULATION_NUM) {
3076 "unvalid col number %d (greater than max %d)\n",
3077 colNum, TXPWR_LMT_MAX_REGULATION_NUM
3082 for (forCnt = 0; forCnt < colNum; ++forCnt) {
3083 u8 regulation_name_cnt = 0;
3085 /* skip the space */
3086 while (szLine[i] == ' ' || szLine[i] == '\t')
3089 while (szLine[i] != ' ' && szLine[i] != '\t' && szLine[i] != '\0')
3090 regulation[forCnt][regulation_name_cnt++] = szLine[i++];
3091 /* DBG_871X("regulation %s!\n", regulation[forCnt]); */
3093 if (regulation_name_cnt == 0) {
3094 DBG_871X("unvalid number of regulation!\n");
3100 } else if (loadingStage == 3) {
3101 char channel[10] = {0}, powerLimit[10] = {0};
3104 /* the table ends */
3105 if (szLine[0] == '#' && szLine[1] == '#') {
3107 while (szLine[i] == ' ' || szLine[i] == '\t')
3110 if (eqNByte((u8 *)(szLine + i), (u8 *)("END"), 3)) {
3114 DBG_871X("Wrong format\n");
3115 DBG_871X("<===== phy_ParsePowerLimitTableFile()\n");
3120 if ((szLine[0] != 'c' && szLine[0] != 'C') ||
3121 (szLine[1] != 'h' && szLine[1] != 'H')) {
3122 DBG_871X("Meet wrong channel => power limt pair\n");
3125 i = 2;/* move to the location behind 'h' */
3127 /* load the channel number */
3129 while (szLine[i] >= '0' && szLine[i] <= '9') {
3130 channel[cnt] = szLine[i];
3134 /* DBG_871X("chnl %s!\n", channel); */
3136 for (forCnt = 0; forCnt < colNum; ++forCnt) {
3137 /* skip the space between channel number and the power limit value */
3138 while (szLine[i] == ' ' || szLine[i] == '\t')
3141 /* load the power limit value */
3144 memset((void *) powerLimit, 0, 10);
3145 while ((szLine[i] >= '0' && szLine[i] <= '9') || szLine[i] == '.') {
3146 if (szLine[i] == '.') {
3147 if ((szLine[i+1] >= '0' && szLine[i+1] <= '9')) {
3148 fraction = szLine[i+1];
3151 DBG_871X("Wrong fraction in TXPWR_LMT.txt\n");
3158 powerLimit[cnt] = szLine[i];
3163 if (powerLimit[0] == '\0') {
3164 powerLimit[0] = '6';
3165 powerLimit[1] = '3';
3168 if (!GetU1ByteIntegerFromStringInDecimal(powerLimit, &limitValue))
3173 if (fraction == '5')
3176 /* the value is greater or equal to 100 */
3177 if (limitValue >= 100) {
3178 powerLimit[cnt++] = limitValue/100 + '0';
3181 if (limitValue >= 10) {
3182 powerLimit[cnt++] = limitValue/10 + '0';
3185 powerLimit[cnt++] = '0';
3187 powerLimit[cnt++] = limitValue + '0';
3188 } else if (limitValue >= 10) { /* the value is greater or equal to 10 */
3189 powerLimit[cnt++] = limitValue/10 + '0';
3191 powerLimit[cnt++] = limitValue + '0';
3193 /* the value is less than 10 */
3195 powerLimit[cnt++] = limitValue + '0';
3197 powerLimit[cnt] = '\0';
3200 /* DBG_871X("ch%s => %s\n", channel, powerLimit); */
3202 /* store the power limit value */
3203 PHY_SetTxPowerLimit(Adapter, (u8 *)regulation[forCnt], (u8 *)band,
3204 (u8 *)bandwidth, (u8 *)rateSection, (u8 *)rfPath, (u8 *)channel, (u8 *)powerLimit);
3208 DBG_871X("Abnormal loading stage in phy_ParsePowerLimitTableFile()!\n");
3214 DBG_871X("<===phy_ParsePowerLimitTableFile()\n");
3218 int PHY_ConfigRFWithPowerLimitTableParaFile(
3219 struct adapter *Adapter, char *pFileName
3222 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
3223 int rlen = 0, rtStatus = _FAIL;
3225 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_LMT_PARA_FILE))
3228 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
3230 if ((pHalData->rf_tx_pwr_lmt_len == 0) && (pHalData->rf_tx_pwr_lmt == NULL)) {
3231 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
3233 if (rtw_is_file_readable(file_path_bs) == true) {
3234 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
3236 rtStatus = _SUCCESS;
3237 pHalData->rf_tx_pwr_lmt = vzalloc(rlen);
3238 if (pHalData->rf_tx_pwr_lmt) {
3239 memcpy(pHalData->rf_tx_pwr_lmt, pHalData->para_file_buf, rlen);
3240 pHalData->rf_tx_pwr_lmt_len = rlen;
3242 DBG_871X("%s rf_tx_pwr_lmt alloc fail !\n", __func__);
3246 if ((pHalData->rf_tx_pwr_lmt_len != 0) && (pHalData->rf_tx_pwr_lmt != NULL)) {
3247 memcpy(pHalData->para_file_buf, pHalData->rf_tx_pwr_lmt, pHalData->rf_tx_pwr_lmt_len);
3248 rtStatus = _SUCCESS;
3250 DBG_871X("%s(): Critical Error !!!\n", __func__);
3253 if (rtStatus == _SUCCESS) {
3254 /* DBG_871X("%s(): read %s ok\n", __func__, pFileName); */
3255 rtStatus = phy_ParsePowerLimitTableFile(Adapter, pHalData->para_file_buf);
3257 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
3262 void phy_free_filebuf(struct adapter *padapter)
3264 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
3266 if (pHalData->mac_reg)
3267 vfree(pHalData->mac_reg);
3268 if (pHalData->bb_phy_reg)
3269 vfree(pHalData->bb_phy_reg);
3270 if (pHalData->bb_agc_tab)
3271 vfree(pHalData->bb_agc_tab);
3272 if (pHalData->bb_phy_reg_pg)
3273 vfree(pHalData->bb_phy_reg_pg);
3274 if (pHalData->bb_phy_reg_mp)
3275 vfree(pHalData->bb_phy_reg_mp);
3276 if (pHalData->rf_radio_a)
3277 vfree(pHalData->rf_radio_a);
3278 if (pHalData->rf_radio_b)
3279 vfree(pHalData->rf_radio_b);
3280 if (pHalData->rf_tx_pwr_track)
3281 vfree(pHalData->rf_tx_pwr_track);
3282 if (pHalData->rf_tx_pwr_lmt)
3283 vfree(pHalData->rf_tx_pwr_lmt);