1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
7 #define _HAL_COM_PHYCFG_C_
10 #include <rtw_debug.h>
12 #include <linux/kernel.h>
14 u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 Band, u8 RfPath,
15 u8 TxNum, enum RATE_SECTION RateSection)
17 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
20 if (RfPath > ODM_RF_PATH_D) {
21 DBG_871X("Invalid Rf Path %d in PHY_GetTxPowerByRateBase()\n", RfPath);
25 if (Band == BAND_ON_2_4G) {
26 switch (RateSection) {
28 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][0];
31 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][1];
34 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][2];
37 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][3];
40 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][4];
43 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][5];
45 case VHT_1SSMCS0_1SSMCS9:
46 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][6];
48 case VHT_2SSMCS0_2SSMCS9:
49 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][7];
51 case VHT_3SSMCS0_3SSMCS9:
52 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][8];
54 case VHT_4SSMCS0_4SSMCS9:
55 value = pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][9];
58 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
59 RateSection, RfPath, TxNum);
62 } else if (Band == BAND_ON_5G) {
63 switch (RateSection) {
65 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][0];
68 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][1];
71 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][2];
74 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][3];
77 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][4];
79 case VHT_1SSMCS0_1SSMCS9:
80 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][5];
82 case VHT_2SSMCS0_2SSMCS9:
83 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][6];
85 case VHT_3SSMCS0_3SSMCS9:
86 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][7];
88 case VHT_4SSMCS0_4SSMCS9:
89 value = pHalData->TxPwrByRateBase5G[RfPath][TxNum][8];
92 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
93 RateSection, RfPath, TxNum);
97 DBG_871X("Invalid Band %d in PHY_GetTxPowerByRateBase()\n", Band);
103 phy_SetTxPowerByRateBase(
104 struct adapter *Adapter,
107 enum RATE_SECTION RateSection,
112 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
114 if (RfPath > ODM_RF_PATH_D) {
115 DBG_871X("Invalid Rf Path %d in phy_SetTxPowerByRatBase()\n", RfPath);
119 if (Band == BAND_ON_2_4G) {
120 switch (RateSection) {
122 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][0] = Value;
125 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][1] = Value;
128 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][2] = Value;
131 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][3] = Value;
134 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][4] = Value;
137 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][5] = Value;
139 case VHT_1SSMCS0_1SSMCS9:
140 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][6] = Value;
142 case VHT_2SSMCS0_2SSMCS9:
143 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][7] = Value;
145 case VHT_3SSMCS0_3SSMCS9:
146 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][8] = Value;
148 case VHT_4SSMCS0_4SSMCS9:
149 pHalData->TxPwrByRateBase2_4G[RfPath][TxNum][9] = Value;
152 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n",
153 RateSection, RfPath, TxNum);
156 } else if (Band == BAND_ON_5G) {
157 switch (RateSection) {
159 pHalData->TxPwrByRateBase5G[RfPath][TxNum][0] = Value;
162 pHalData->TxPwrByRateBase5G[RfPath][TxNum][1] = Value;
165 pHalData->TxPwrByRateBase5G[RfPath][TxNum][2] = Value;
168 pHalData->TxPwrByRateBase5G[RfPath][TxNum][3] = Value;
171 pHalData->TxPwrByRateBase5G[RfPath][TxNum][4] = Value;
173 case VHT_1SSMCS0_1SSMCS9:
174 pHalData->TxPwrByRateBase5G[RfPath][TxNum][5] = Value;
176 case VHT_2SSMCS0_2SSMCS9:
177 pHalData->TxPwrByRateBase5G[RfPath][TxNum][6] = Value;
179 case VHT_3SSMCS0_3SSMCS9:
180 pHalData->TxPwrByRateBase5G[RfPath][TxNum][7] = Value;
182 case VHT_4SSMCS0_4SSMCS9:
183 pHalData->TxPwrByRateBase5G[RfPath][TxNum][8] = Value;
186 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n",
187 RateSection, RfPath, TxNum);
191 DBG_871X("Invalid Band %d in phy_SetTxPowerByRateBase()\n", Band);
195 phy_StoreTxPowerByRateBase(
196 struct adapter *padapter
201 /* DBG_871X("===>%s\n", __func__); */
203 for (path = ODM_RF_PATH_A; path <= ODM_RF_PATH_B; ++path) {
204 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_11M);
205 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, CCK, RF_1TX, base);
206 /* DBG_871X("Power index base of 2.4G path %d 1Tx CCK = > 0x%x\n", path, base); */
208 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_54M);
209 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, OFDM, RF_1TX, base);
210 /* DBG_871X("Power index base of 2.4G path %d 1Tx OFDM = > 0x%x\n", path, base); */
212 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_MCS7);
213 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, HT_MCS0_MCS7, RF_1TX, base);
214 /* DBG_871X("Power index base of 2.4G path %d 1Tx MCS0-7 = > 0x%x\n", path, base); */
216 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_2TX, MGN_MCS15);
217 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, HT_MCS8_MCS15, RF_2TX, base);
218 /* DBG_871X("Power index base of 2.4G path %d 2Tx MCS8-15 = > 0x%x\n", path, base); */
220 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_3TX, MGN_MCS23);
221 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, HT_MCS16_MCS23, RF_3TX, base);
222 /* DBG_871X("Power index base of 2.4G path %d 3Tx MCS16-23 = > 0x%x\n", path, base); */
224 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_1TX, MGN_VHT1SS_MCS7);
225 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, VHT_1SSMCS0_1SSMCS9, RF_1TX, base);
226 /* DBG_871X("Power index base of 2.4G path %d 1Tx VHT1SS = > 0x%x\n", path, base); */
228 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_2TX, MGN_VHT2SS_MCS7);
229 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, VHT_2SSMCS0_2SSMCS9, RF_2TX, base);
230 /* DBG_871X("Power index base of 2.4G path %d 2Tx VHT2SS = > 0x%x\n", path, base); */
232 base = PHY_GetTxPowerByRate(padapter, BAND_ON_2_4G, path, RF_3TX, MGN_VHT3SS_MCS7);
233 phy_SetTxPowerByRateBase(padapter, BAND_ON_2_4G, path, VHT_3SSMCS0_3SSMCS9, RF_3TX, base);
234 /* DBG_871X("Power index base of 2.4G path %d 3Tx VHT3SS = > 0x%x\n", path, base); */
236 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_1TX, MGN_54M);
237 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, OFDM, RF_1TX, base);
238 /* DBG_871X("Power index base of 5G path %d 1Tx OFDM = > 0x%x\n", path, base); */
240 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_1TX, MGN_MCS7);
241 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, HT_MCS0_MCS7, RF_1TX, base);
242 /* DBG_871X("Power index base of 5G path %d 1Tx MCS0~7 = > 0x%x\n", path, base); */
244 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_2TX, MGN_MCS15);
245 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, HT_MCS8_MCS15, RF_2TX, base);
246 /* DBG_871X("Power index base of 5G path %d 2Tx MCS8~15 = > 0x%x\n", path, base); */
248 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_3TX, MGN_MCS23);
249 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, HT_MCS16_MCS23, RF_3TX, base);
250 /* DBG_871X("Power index base of 5G path %d 3Tx MCS16~23 = > 0x%x\n", path, base); */
252 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_1TX, MGN_VHT1SS_MCS7);
253 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, VHT_1SSMCS0_1SSMCS9, RF_1TX, base);
254 /* DBG_871X("Power index base of 5G path %d 1Tx VHT1SS = > 0x%x\n", path, base); */
256 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_2TX, MGN_VHT2SS_MCS7);
257 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, VHT_2SSMCS0_2SSMCS9, RF_2TX, base);
258 /* DBG_871X("Power index base of 5G path %d 2Tx VHT2SS = > 0x%x\n", path, base); */
260 base = PHY_GetTxPowerByRate(padapter, BAND_ON_5G, path, RF_3TX, MGN_VHT2SS_MCS7);
261 phy_SetTxPowerByRateBase(padapter, BAND_ON_5G, path, VHT_3SSMCS0_3SSMCS9, RF_3TX, base);
262 /* DBG_871X("Power index base of 5G path %d 3Tx VHT3SS = > 0x%x\n", path, base); */
265 /* DBG_871X("<===%s\n", __func__); */
268 u8 PHY_GetRateSectionIndexOfTxPowerByRate(
269 struct adapter *padapter, u32 RegAddr, u32 BitMask
272 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
273 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
276 if (pDM_Odm->PhyRegPgVersion == 0) {
278 case rTxAGC_A_Rate18_06:
281 case rTxAGC_A_Rate54_24:
284 case rTxAGC_A_CCK1_Mcs32:
287 case rTxAGC_B_CCK11_A_CCK2_11:
288 if (BitMask == bMaskH3Bytes)
290 else if (BitMask == 0x000000ff)
294 case rTxAGC_A_Mcs03_Mcs00:
297 case rTxAGC_A_Mcs07_Mcs04:
300 case rTxAGC_A_Mcs11_Mcs08:
303 case rTxAGC_A_Mcs15_Mcs12:
306 case rTxAGC_B_Rate18_06:
309 case rTxAGC_B_Rate54_24:
312 case rTxAGC_B_CCK1_55_Mcs32:
315 case rTxAGC_B_Mcs03_Mcs00:
318 case rTxAGC_B_Mcs07_Mcs04:
321 case rTxAGC_B_Mcs11_Mcs08:
324 case rTxAGC_B_Mcs15_Mcs12:
328 DBG_871X("Invalid RegAddr 0x3%x in PHY_GetRateSectionIndexOfTxPowerByRate()", RegAddr);
337 PHY_GetRateValuesOfTxPowerByRate(
338 struct adapter *padapter,
350 case rTxAGC_A_Rate18_06:
351 case rTxAGC_B_Rate18_06:
352 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_6M);
353 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_9M);
354 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_12M);
355 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_18M);
356 for (i = 0; i < 4; ++i) {
357 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
358 ((Value >> (i * 8)) & 0xF));
363 case rTxAGC_A_Rate54_24:
364 case rTxAGC_B_Rate54_24:
365 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_24M);
366 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_36M);
367 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_48M);
368 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_54M);
369 for (i = 0; i < 4; ++i) {
370 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
371 ((Value >> (i * 8)) & 0xF));
376 case rTxAGC_A_CCK1_Mcs32:
377 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M);
378 PwrByRateVal[0] = (s8) ((((Value >> (8 + 4)) & 0xF)) * 10 +
379 ((Value >> 8) & 0xF));
383 case rTxAGC_B_CCK11_A_CCK2_11:
384 if (BitMask == 0xffffff00) {
385 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M);
386 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M);
387 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M);
388 for (i = 1; i < 4; ++i) {
389 PwrByRateVal[i - 1] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
390 ((Value >> (i * 8)) & 0xF));
393 } else if (BitMask == 0x000000ff) {
394 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M);
395 PwrByRateVal[0] = (s8) ((((Value >> 4) & 0xF)) * 10 + (Value & 0xF));
400 case rTxAGC_A_Mcs03_Mcs00:
401 case rTxAGC_B_Mcs03_Mcs00:
402 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS0);
403 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS1);
404 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS2);
405 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS3);
406 for (i = 0; i < 4; ++i) {
407 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
408 ((Value >> (i * 8)) & 0xF));
413 case rTxAGC_A_Mcs07_Mcs04:
414 case rTxAGC_B_Mcs07_Mcs04:
415 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS4);
416 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS5);
417 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS6);
418 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS7);
419 for (i = 0; i < 4; ++i) {
420 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
421 ((Value >> (i * 8)) & 0xF));
426 case rTxAGC_A_Mcs11_Mcs08:
427 case rTxAGC_B_Mcs11_Mcs08:
428 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS8);
429 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS9);
430 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS10);
431 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS11);
432 for (i = 0; i < 4; ++i) {
433 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
434 ((Value >> (i * 8)) & 0xF));
439 case rTxAGC_A_Mcs15_Mcs12:
440 case rTxAGC_B_Mcs15_Mcs12:
441 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS12);
442 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS13);
443 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS14);
444 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS15);
445 for (i = 0; i < 4; ++i) {
446 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
447 ((Value >> (i * 8)) & 0xF));
453 case rTxAGC_B_CCK1_55_Mcs32:
454 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M);
455 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M);
456 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M);
457 for (i = 1; i < 4; ++i) {
458 PwrByRateVal[i - 1] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
459 ((Value >> (i * 8)) & 0xF));
468 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M);
469 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M);
470 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M);
471 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M);
472 for (i = 0; i < 4; ++i) {
473 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
474 ((Value >> (i * 8)) & 0xF));
483 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_6M);
484 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_9M);
485 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_12M);
486 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_18M);
487 for (i = 0; i < 4; ++i) {
488 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
489 ((Value >> (i * 8)) & 0xF));
498 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_24M);
499 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_36M);
500 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_48M);
501 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_54M);
502 for (i = 0; i < 4; ++i) {
503 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
504 ((Value >> (i * 8)) & 0xF));
513 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS0);
514 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS1);
515 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS2);
516 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS3);
517 for (i = 0; i < 4; ++i) {
518 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
519 ((Value >> (i * 8)) & 0xF));
528 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS4);
529 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS5);
530 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS6);
531 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS7);
532 for (i = 0; i < 4; ++i) {
533 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
534 ((Value >> (i * 8)) & 0xF));
543 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS8);
544 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS9);
545 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS10);
546 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS11);
547 for (i = 0; i < 4; ++i) {
548 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
549 ((Value >> (i * 8)) & 0xF));
558 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS12);
559 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS13);
560 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS14);
561 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS15);
562 for (i = 0; i < 4; ++i) {
563 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
564 ((Value >> (i * 8)) & 0xF));
573 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS0);
574 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS1);
575 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS2);
576 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS3);
577 for (i = 0; i < 4; ++i) {
578 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
579 ((Value >> (i * 8)) & 0xF));
588 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS4);
589 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS5);
590 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS6);
591 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS7);
592 for (i = 0; i < 4; ++i) {
593 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
594 ((Value >> (i * 8)) & 0xF));
603 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS8);
604 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT1SS_MCS9);
605 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS0);
606 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS1);
607 for (i = 0; i < 4; ++i) {
608 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
609 ((Value >> (i * 8)) & 0xF));
618 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS2);
619 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS3);
620 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS4);
621 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS5);
622 for (i = 0; i < 4; ++i) {
623 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
624 ((Value >> (i * 8)) & 0xF));
633 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS6);
634 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS7);
635 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS8);
636 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS9);
637 for (i = 0; i < 4; ++i) {
638 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
639 ((Value >> (i * 8)) & 0xF));
648 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS16);
649 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS17);
650 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS18);
651 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS19);
652 for (i = 0; i < 4; ++i) {
653 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
654 ((Value >> (i * 8)) & 0xF));
663 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS20);
664 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS21);
665 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS22);
666 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS23);
667 for (i = 0; i < 4; ++i) {
668 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
669 ((Value >> (i * 8)) & 0xF));
678 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS0);
679 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS1);
680 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS2);
681 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS3);
682 for (i = 0; i < 4; ++i) {
683 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
684 ((Value >> (i * 8)) & 0xF));
693 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS4);
694 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS5);
695 RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS6);
696 RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS7);
697 for (i = 0; i < 4; ++i) {
698 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
699 ((Value >> (i * 8)) & 0xF));
708 RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS8);
709 RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_VHT3SS_MCS9);
710 for (i = 0; i < 2; ++i) {
711 PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 +
712 ((Value >> (i * 8)) & 0xF));
718 DBG_871X("Invalid RegAddr 0x%x in %s()\n", RegAddr, __func__);
723 static void PHY_StoreTxPowerByRateNew(
724 struct adapter *padapter,
733 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
734 u8 i = 0, rateIndex[4] = {0}, rateNum = 0;
735 s8 PwrByRateVal[4] = {0};
737 PHY_GetRateValuesOfTxPowerByRate(padapter, RegAddr, BitMask, Data, rateIndex, PwrByRateVal, &rateNum);
739 if (Band != BAND_ON_2_4G && Band != BAND_ON_5G) {
740 DBG_871X("Invalid Band %d\n", Band);
744 if (RfPath > ODM_RF_PATH_D) {
745 DBG_871X("Invalid RfPath %d\n", RfPath);
749 if (TxNum > ODM_RF_PATH_D) {
750 DBG_871X("Invalid TxNum %d\n", TxNum);
754 for (i = 0; i < rateNum; ++i) {
755 if (rateIndex[i] == PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS0) ||
756 rateIndex[i] == PHY_GetRateIndexOfTxPowerByRate(MGN_VHT2SS_MCS1))
759 pHalData->TxPwrByRateOffset[Band][RfPath][TxNum][rateIndex[i]] = PwrByRateVal[i];
763 static void PHY_StoreTxPowerByRateOld(
764 struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data
767 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
768 u8 index = PHY_GetRateSectionIndexOfTxPowerByRate(padapter, RegAddr, BitMask);
770 pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][index] = Data;
771 /* DBG_871X("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n", pHalData->pwrGroupCnt, */
772 /* pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0]); */
775 void PHY_InitTxPowerByRate(struct adapter *padapter)
777 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
778 u8 band, rfPath, TxNum, rate;
780 for (band = BAND_ON_2_4G; band <= BAND_ON_5G; ++band)
781 for (rfPath = 0; rfPath < TX_PWR_BY_RATE_NUM_RF; ++rfPath)
782 for (TxNum = 0; TxNum < TX_PWR_BY_RATE_NUM_RF; ++TxNum)
783 for (rate = 0; rate < TX_PWR_BY_RATE_NUM_RATE; ++rate)
784 pHalData->TxPwrByRateOffset[band][rfPath][TxNum][rate] = 0;
787 void PHY_StoreTxPowerByRate(
788 struct adapter *padapter,
797 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
798 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
800 if (pDM_Odm->PhyRegPgVersion > 0)
801 PHY_StoreTxPowerByRateNew(padapter, Band, RfPath, TxNum, RegAddr, BitMask, Data);
802 else if (pDM_Odm->PhyRegPgVersion == 0) {
803 PHY_StoreTxPowerByRateOld(padapter, RegAddr, BitMask, Data);
805 if (RegAddr == rTxAGC_A_Mcs15_Mcs12 && pHalData->rf_type == RF_1T1R)
806 pHalData->pwrGroupCnt++;
807 else if (RegAddr == rTxAGC_B_Mcs15_Mcs12 && pHalData->rf_type != RF_1T1R)
808 pHalData->pwrGroupCnt++;
810 DBG_871X("Invalid PHY_REG_PG.txt version %d\n", pDM_Odm->PhyRegPgVersion);
815 phy_ConvertTxPowerByRateInDbmToRelativeValues(
816 struct adapter *padapter
819 u8 base = 0, i = 0, value = 0, band = 0, path = 0, txNum = 0;
821 MGN_1M, MGN_2M, MGN_5_5M, MGN_11M
824 MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M
826 u8 mcs0_7Rates[8] = {
827 MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7
829 u8 mcs8_15Rates[8] = {
830 MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15
832 u8 mcs16_23Rates[8] = {
833 MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23
835 u8 vht1ssRates[10] = {
836 MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4,
837 MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9
839 u8 vht2ssRates[10] = {
840 MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4,
841 MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9
843 u8 vht3ssRates[10] = {
844 MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4,
845 MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9
848 /* DBG_871X("===>PHY_ConvertTxPowerByRateInDbmToRelativeValues()\n"); */
850 for (band = BAND_ON_2_4G; band <= BAND_ON_5G; ++band) {
851 for (path = ODM_RF_PATH_A; path <= ODM_RF_PATH_D; ++path) {
852 for (txNum = RF_1TX; txNum < RF_MAX_TX_NUM; ++txNum) {
854 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_11M);
855 for (i = 0; i < ARRAY_SIZE(cckRates); ++i) {
856 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, cckRates[i]);
857 PHY_SetTxPowerByRate(padapter, band, path, txNum, cckRates[i], value - base);
861 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_54M);
862 for (i = 0; i < sizeof(ofdmRates); ++i) {
863 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, ofdmRates[i]);
864 PHY_SetTxPowerByRate(padapter, band, path, txNum, ofdmRates[i], value - base);
868 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_MCS7);
869 for (i = 0; i < sizeof(mcs0_7Rates); ++i) {
870 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, mcs0_7Rates[i]);
871 PHY_SetTxPowerByRate(padapter, band, path, txNum, mcs0_7Rates[i], value - base);
875 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_MCS15);
876 for (i = 0; i < sizeof(mcs8_15Rates); ++i) {
877 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, mcs8_15Rates[i]);
878 PHY_SetTxPowerByRate(padapter, band, path, txNum, mcs8_15Rates[i], value - base);
882 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_MCS23);
883 for (i = 0; i < sizeof(mcs16_23Rates); ++i) {
884 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, mcs16_23Rates[i]);
885 PHY_SetTxPowerByRate(padapter, band, path, txNum, mcs16_23Rates[i], value - base);
889 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_VHT1SS_MCS7);
890 for (i = 0; i < sizeof(vht1ssRates); ++i) {
891 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, vht1ssRates[i]);
892 PHY_SetTxPowerByRate(padapter, band, path, txNum, vht1ssRates[i], value - base);
896 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_VHT2SS_MCS7);
897 for (i = 0; i < sizeof(vht2ssRates); ++i) {
898 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, vht2ssRates[i]);
899 PHY_SetTxPowerByRate(padapter, band, path, txNum, vht2ssRates[i], value - base);
903 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_VHT3SS_MCS7);
904 for (i = 0; i < sizeof(vht3ssRates); ++i) {
905 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, vht3ssRates[i]);
906 PHY_SetTxPowerByRate(padapter, band, path, txNum, vht3ssRates[i], value - base);
912 /* DBG_871X("<===PHY_ConvertTxPowerByRateInDbmToRelativeValues()\n"); */
916 * This function must be called if the value in the PHY_REG_PG.txt(or header)
917 * is exact dBm values
919 void PHY_TxPowerByRateConfiguration(struct adapter *padapter)
921 phy_StoreTxPowerByRateBase(padapter);
922 phy_ConvertTxPowerByRateInDbmToRelativeValues(padapter);
925 void PHY_SetTxPowerIndexByRateSection(
926 struct adapter *padapter, u8 RFPath, u8 Channel, u8 RateSection
929 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
931 if (RateSection == CCK) {
932 u8 cckRates[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M};
933 if (pHalData->CurrentBandType == BAND_ON_2_4G)
934 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
935 pHalData->CurrentChannelBW,
937 ARRAY_SIZE(cckRates));
939 } else if (RateSection == OFDM) {
940 u8 ofdmRates[] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
941 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
942 pHalData->CurrentChannelBW,
944 ARRAY_SIZE(ofdmRates));
946 } else if (RateSection == HT_MCS0_MCS7) {
947 u8 htRates1T[] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7};
948 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
949 pHalData->CurrentChannelBW,
951 ARRAY_SIZE(htRates1T));
953 } else if (RateSection == HT_MCS8_MCS15) {
954 u8 htRates2T[] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15};
955 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
956 pHalData->CurrentChannelBW,
958 ARRAY_SIZE(htRates2T));
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,
963 pHalData->CurrentChannelBW,
965 ARRAY_SIZE(htRates3T));
967 } else if (RateSection == HT_MCS24_MCS31) {
968 u8 htRates4T[] = {MGN_MCS24, MGN_MCS25, MGN_MCS26, MGN_MCS27, MGN_MCS28, MGN_MCS29, MGN_MCS30, MGN_MCS31};
969 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
970 pHalData->CurrentChannelBW,
972 ARRAY_SIZE(htRates4T));
974 } else if (RateSection == VHT_1SSMCS0_1SSMCS9) {
975 u8 vhtRates1T[] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4,
976 MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9};
977 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
978 pHalData->CurrentChannelBW,
980 ARRAY_SIZE(vhtRates1T));
982 } else if (RateSection == VHT_2SSMCS0_2SSMCS9) {
983 u8 vhtRates2T[] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4,
984 MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9};
986 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
987 pHalData->CurrentChannelBW,
989 ARRAY_SIZE(vhtRates2T));
990 } else if (RateSection == VHT_3SSMCS0_3SSMCS9) {
991 u8 vhtRates3T[] = {MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4,
992 MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9};
994 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
995 pHalData->CurrentChannelBW,
997 ARRAY_SIZE(vhtRates3T));
998 } else if (RateSection == VHT_4SSMCS0_4SSMCS9) {
999 u8 vhtRates4T[] = {MGN_VHT4SS_MCS0, MGN_VHT4SS_MCS1, MGN_VHT4SS_MCS2, MGN_VHT4SS_MCS3, MGN_VHT4SS_MCS4,
1000 MGN_VHT4SS_MCS5, MGN_VHT4SS_MCS6, MGN_VHT4SS_MCS7, MGN_VHT4SS_MCS8, MGN_VHT4SS_MCS9};
1002 PHY_SetTxPowerIndexByRateArray(padapter, RFPath,
1003 pHalData->CurrentChannelBW,
1004 Channel, vhtRates4T,
1005 ARRAY_SIZE(vhtRates4T));
1007 DBG_871X("Invalid RateSection %d in %s", RateSection, __func__);
1010 static bool phy_GetChnlIndex(u8 Channel, u8 *ChannelIdx)
1012 u8 channel5G[CHANNEL_MAX_NUMBER_5G] = {
1013 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 100, 102,
1014 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130,
1015 132, 134, 136, 138, 140, 142, 144, 149, 151, 153, 155, 157, 159, 161,
1016 163, 165, 167, 168, 169, 171, 173, 175, 177
1021 if (Channel <= 14) {
1023 *ChannelIdx = Channel-1;
1027 for (i = 0; i < ARRAY_SIZE(channel5G); ++i) {
1028 if (channel5G[i] == Channel) {
1038 u8 PHY_GetTxPowerIndexBase(
1039 struct adapter *padapter,
1042 enum CHANNEL_WIDTH BandWidth,
1047 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1048 u8 i = 0; /* default set to 1S */
1050 u8 chnlIdx = (Channel-1);
1052 if (HAL_IsLegalChannel(padapter, Channel) == false) {
1054 DBG_871X("Illegal channel!!\n");
1057 *bIn24G = phy_GetChnlIndex(Channel, &chnlIdx);
1059 /* DBG_871X("[%s] Channel Index: %d\n", (*bIn24G?"2.4G":"5G"), chnlIdx); */
1061 if (*bIn24G) { /* 3 ============================== 2.4 G ============================== */
1062 if (IS_CCK_RATE(Rate))
1063 txPower = pHalData->Index24G_CCK_Base[RFPath][chnlIdx];
1064 else if (MGN_6M <= Rate)
1065 txPower = pHalData->Index24G_BW40_Base[RFPath][chnlIdx];
1067 DBG_871X("PHY_GetTxPowerIndexBase: INVALID Rate.\n");
1069 /* DBG_871X("Base Tx power(RF-%c, Rate #%d, Channel Index %d) = 0x%X\n", */
1070 /* ((RFPath == 0)?'A':'B'), Rate, chnlIdx, txPower); */
1073 if ((MGN_6M <= Rate && Rate <= MGN_54M) && !IS_CCK_RATE(Rate)) {
1074 txPower += pHalData->OFDM_24G_Diff[RFPath][TX_1S];
1075 /* DBG_871X("+PowerDiff 2.4G (RF-%c): (OFDM-1T) = (%d)\n", ((RFPath == 0)?'A':'B'), pHalData->OFDM_24G_Diff[RFPath][TX_1S]); */
1077 if (BandWidth == CHANNEL_WIDTH_20) { /* BW20-1S, BW20-2S */
1078 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1079 txPower += pHalData->BW20_24G_Diff[RFPath][TX_1S];
1080 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1081 txPower += pHalData->BW20_24G_Diff[RFPath][TX_2S];
1082 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1083 txPower += pHalData->BW20_24G_Diff[RFPath][TX_3S];
1084 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1085 txPower += pHalData->BW20_24G_Diff[RFPath][TX_4S];
1087 /* 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'), */
1088 /* pHalData->BW20_24G_Diff[RFPath][TX_1S], pHalData->BW20_24G_Diff[RFPath][TX_2S], */
1089 /* pHalData->BW20_24G_Diff[RFPath][TX_3S], pHalData->BW20_24G_Diff[RFPath][TX_4S]); */
1090 } else if (BandWidth == CHANNEL_WIDTH_40) { /* BW40-1S, BW40-2S */
1091 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1092 txPower += pHalData->BW40_24G_Diff[RFPath][TX_1S];
1093 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1094 txPower += pHalData->BW40_24G_Diff[RFPath][TX_2S];
1095 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1096 txPower += pHalData->BW40_24G_Diff[RFPath][TX_3S];
1097 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1098 txPower += pHalData->BW40_24G_Diff[RFPath][TX_4S];
1100 /* 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'), */
1101 /* pHalData->BW40_24G_Diff[RFPath][TX_1S], pHalData->BW40_24G_Diff[RFPath][TX_2S], */
1102 /* pHalData->BW40_24G_Diff[RFPath][TX_3S], pHalData->BW40_24G_Diff[RFPath][TX_4S]); */
1104 /* Willis suggest adopt BW 40M power index while in BW 80 mode */
1105 else if (BandWidth == CHANNEL_WIDTH_80) {
1106 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1107 txPower += pHalData->BW40_24G_Diff[RFPath][TX_1S];
1108 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1109 txPower += pHalData->BW40_24G_Diff[RFPath][TX_2S];
1110 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1111 txPower += pHalData->BW40_24G_Diff[RFPath][TX_3S];
1112 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1113 txPower += pHalData->BW40_24G_Diff[RFPath][TX_4S];
1115 /* 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'), */
1116 /* pHalData->BW40_24G_Diff[RFPath][TX_1S], pHalData->BW40_24G_Diff[RFPath][TX_2S], */
1117 /* pHalData->BW40_24G_Diff[RFPath][TX_3S], pHalData->BW40_24G_Diff[RFPath][TX_4S]); */
1119 } else {/* 3 ============================== 5 G ============================== */
1121 txPower = pHalData->Index5G_BW40_Base[RFPath][chnlIdx];
1123 DBG_871X("===> mpt_ProQueryCalTxPower_Jaguar: INVALID Rate.\n");
1125 /* DBG_871X("Base Tx power(RF-%c, Rate #%d, Channel Index %d) = 0x%X\n", */
1126 /* ((RFPath == 0)?'A':'B'), Rate, chnlIdx, txPower); */
1129 if ((MGN_6M <= Rate && Rate <= MGN_54M) && !IS_CCK_RATE(Rate)) {
1130 txPower += pHalData->OFDM_5G_Diff[RFPath][TX_1S];
1131 /* DBG_871X("+PowerDiff 5G (RF-%c): (OFDM-1T) = (%d)\n", ((RFPath == 0)?'A':'B'), pHalData->OFDM_5G_Diff[RFPath][TX_1S]); */
1134 /* BW20-1S, BW20-2S */
1135 if (BandWidth == CHANNEL_WIDTH_20) {
1136 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1137 txPower += pHalData->BW20_5G_Diff[RFPath][TX_1S];
1138 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1139 txPower += pHalData->BW20_5G_Diff[RFPath][TX_2S];
1140 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1141 txPower += pHalData->BW20_5G_Diff[RFPath][TX_3S];
1142 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1143 txPower += pHalData->BW20_5G_Diff[RFPath][TX_4S];
1145 /* 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'), */
1146 /* pHalData->BW20_5G_Diff[RFPath][TX_1S], pHalData->BW20_5G_Diff[RFPath][TX_2S], */
1147 /* pHalData->BW20_5G_Diff[RFPath][TX_3S], pHalData->BW20_5G_Diff[RFPath][TX_4S]); */
1148 } else if (BandWidth == CHANNEL_WIDTH_40) { /* BW40-1S, BW40-2S */
1149 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1150 txPower += pHalData->BW40_5G_Diff[RFPath][TX_1S];
1151 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1152 txPower += pHalData->BW40_5G_Diff[RFPath][TX_2S];
1153 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1154 txPower += pHalData->BW40_5G_Diff[RFPath][TX_3S];
1155 if ((MGN_MCS24 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1156 txPower += pHalData->BW40_5G_Diff[RFPath][TX_4S];
1158 /* 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'), */
1159 /* pHalData->BW40_5G_Diff[RFPath][TX_1S], pHalData->BW40_5G_Diff[RFPath][TX_2S], */
1160 /* pHalData->BW40_5G_Diff[RFPath][TX_3S], pHalData->BW40_5G_Diff[RFPath][TX_4S]); */
1161 } else if (BandWidth == CHANNEL_WIDTH_80) { /* BW80-1S, BW80-2S */
1162 /* <20121220, Kordan> Get the index of array "Index5G_BW80_Base". */
1163 u8 channel5G_80M[CHANNEL_MAX_NUMBER_5G_80M] = {42, 58, 106, 122, 138, 155, 171};
1164 for (i = 0; i < ARRAY_SIZE(channel5G_80M); ++i)
1165 if (channel5G_80M[i] == Channel)
1168 txPower = pHalData->Index5G_BW80_Base[RFPath][chnlIdx];
1170 if ((MGN_MCS0 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT1SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1171 txPower += + pHalData->BW80_5G_Diff[RFPath][TX_1S];
1172 if ((MGN_MCS8 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT2SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1173 txPower += pHalData->BW80_5G_Diff[RFPath][TX_2S];
1174 if ((MGN_MCS16 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT3SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1175 txPower += pHalData->BW80_5G_Diff[RFPath][TX_3S];
1176 if ((MGN_MCS23 <= Rate && Rate <= MGN_MCS31) || (MGN_VHT4SS_MCS0 <= Rate && Rate <= MGN_VHT4SS_MCS9))
1177 txPower += pHalData->BW80_5G_Diff[RFPath][TX_4S];
1179 /* 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'), */
1180 /* pHalData->BW80_5G_Diff[RFPath][TX_1S], pHalData->BW80_5G_Diff[RFPath][TX_2S], */
1181 /* pHalData->BW80_5G_Diff[RFPath][TX_3S], pHalData->BW80_5G_Diff[RFPath][TX_4S]); */
1188 s8 PHY_GetTxPowerTrackingOffset(struct adapter *padapter, u8 RFPath, u8 Rate)
1190 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1191 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
1194 if (pDM_Odm->RFCalibrateInfo.TxPowerTrackControl == false)
1197 if ((Rate == MGN_1M) || (Rate == MGN_2M) || (Rate == MGN_5_5M) || (Rate == MGN_11M)) {
1198 offset = pDM_Odm->Remnant_CCKSwingIdx;
1199 /* DBG_871X("+Remnant_CCKSwingIdx = 0x%x\n", RFPath, Rate, pDM_Odm->Remnant_CCKSwingIdx); */
1201 offset = pDM_Odm->Remnant_OFDMSwingIdx[RFPath];
1202 /* DBG_871X("+Remanant_OFDMSwingIdx[RFPath %u][Rate 0x%x] = 0x%x\n", RFPath, Rate, pDM_Odm->Remnant_OFDMSwingIdx[RFPath]); */
1209 u8 PHY_GetRateIndexOfTxPowerByRate(u8 Rate)
1345 case MGN_VHT1SS_MCS0:
1348 case MGN_VHT1SS_MCS1:
1351 case MGN_VHT1SS_MCS2:
1354 case MGN_VHT1SS_MCS3:
1357 case MGN_VHT1SS_MCS4:
1360 case MGN_VHT1SS_MCS5:
1363 case MGN_VHT1SS_MCS6:
1366 case MGN_VHT1SS_MCS7:
1369 case MGN_VHT1SS_MCS8:
1372 case MGN_VHT1SS_MCS9:
1375 case MGN_VHT2SS_MCS0:
1378 case MGN_VHT2SS_MCS1:
1381 case MGN_VHT2SS_MCS2:
1384 case MGN_VHT2SS_MCS3:
1387 case MGN_VHT2SS_MCS4:
1390 case MGN_VHT2SS_MCS5:
1393 case MGN_VHT2SS_MCS6:
1396 case MGN_VHT2SS_MCS7:
1399 case MGN_VHT2SS_MCS8:
1402 case MGN_VHT2SS_MCS9:
1405 case MGN_VHT3SS_MCS0:
1408 case MGN_VHT3SS_MCS1:
1411 case MGN_VHT3SS_MCS2:
1414 case MGN_VHT3SS_MCS3:
1417 case MGN_VHT3SS_MCS4:
1420 case MGN_VHT3SS_MCS5:
1423 case MGN_VHT3SS_MCS6:
1426 case MGN_VHT3SS_MCS7:
1429 case MGN_VHT3SS_MCS8:
1432 case MGN_VHT3SS_MCS9:
1435 case MGN_VHT4SS_MCS0:
1438 case MGN_VHT4SS_MCS1:
1441 case MGN_VHT4SS_MCS2:
1444 case MGN_VHT4SS_MCS3:
1447 case MGN_VHT4SS_MCS4:
1450 case MGN_VHT4SS_MCS5:
1453 case MGN_VHT4SS_MCS6:
1456 case MGN_VHT4SS_MCS7:
1459 case MGN_VHT4SS_MCS8:
1462 case MGN_VHT4SS_MCS9:
1466 DBG_871X("Invalid rate 0x%x in %s\n", Rate, __func__);
1472 s8 PHY_GetTxPowerByRate(
1473 struct adapter *padapter, u8 Band, u8 RFPath, u8 TxNum, u8 Rate
1476 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1478 u8 rateIndex = PHY_GetRateIndexOfTxPowerByRate(Rate);
1480 if ((padapter->registrypriv.RegEnableTxPowerByRate == 2 && pHalData->EEPROMRegulatory == 2) ||
1481 padapter->registrypriv.RegEnableTxPowerByRate == 0)
1484 if (Band != BAND_ON_2_4G && Band != BAND_ON_5G) {
1485 DBG_871X("Invalid band %d in %s\n", Band, __func__);
1488 if (RFPath > ODM_RF_PATH_D) {
1489 DBG_871X("Invalid RfPath %d in %s\n", RFPath, __func__);
1492 if (TxNum >= RF_MAX_TX_NUM) {
1493 DBG_871X("Invalid TxNum %d in %s\n", TxNum, __func__);
1496 if (rateIndex >= TX_PWR_BY_RATE_NUM_RATE) {
1497 DBG_871X("Invalid RateIndex %d in %s\n", rateIndex, __func__);
1501 value = pHalData->TxPwrByRateOffset[Band][RFPath][TxNum][rateIndex];
1507 void PHY_SetTxPowerByRate(
1508 struct adapter *padapter,
1516 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1517 u8 rateIndex = PHY_GetRateIndexOfTxPowerByRate(Rate);
1519 if (Band != BAND_ON_2_4G && Band != BAND_ON_5G) {
1520 DBG_871X("Invalid band %d in %s\n", Band, __func__);
1523 if (RFPath > ODM_RF_PATH_D) {
1524 DBG_871X("Invalid RfPath %d in %s\n", RFPath, __func__);
1527 if (TxNum >= RF_MAX_TX_NUM) {
1528 DBG_871X("Invalid TxNum %d in %s\n", TxNum, __func__);
1531 if (rateIndex >= TX_PWR_BY_RATE_NUM_RATE) {
1532 DBG_871X("Invalid RateIndex %d in %s\n", rateIndex, __func__);
1536 pHalData->TxPwrByRateOffset[Band][RFPath][TxNum][rateIndex] = Value;
1539 void PHY_SetTxPowerLevelByPath(struct adapter *Adapter, u8 channel, u8 path)
1541 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1542 bool bIsIn24G = (pHalData->CurrentBandType == BAND_ON_2_4G);
1544 /* if (pMgntInfo->RegNByteAccess == 0) */
1547 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, CCK);
1549 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, OFDM);
1550 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, HT_MCS0_MCS7);
1552 if (pHalData->NumTotalRFPath >= 2)
1553 PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, HT_MCS8_MCS15);
1558 void PHY_SetTxPowerIndexByRateArray(
1559 struct adapter *padapter,
1561 enum CHANNEL_WIDTH BandWidth,
1570 for (i = 0; i < RateArraySize; ++i) {
1571 powerIndex = PHY_GetTxPowerIndex(padapter, RFPath, Rates[i], BandWidth, Channel);
1572 PHY_SetTxPowerIndex(padapter, powerIndex, RFPath, Rates[i]);
1576 static s8 phy_GetWorldWideLimit(s8 *LimitTable)
1578 s8 min = LimitTable[0];
1581 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
1582 if (LimitTable[i] < min)
1583 min = LimitTable[i];
1589 static s8 phy_GetChannelIndexOfTxPowerLimit(u8 Band, u8 Channel)
1591 s8 channelIndex = -1;
1592 u8 channel5G[CHANNEL_MAX_NUMBER_5G] = {
1593 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 100, 102,
1594 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130,
1595 132, 134, 136, 138, 140, 142, 144, 149, 151, 153, 155, 157, 159, 161,
1596 163, 165, 167, 168, 169, 171, 173, 175, 177
1599 if (Band == BAND_ON_2_4G)
1600 channelIndex = Channel - 1;
1601 else if (Band == BAND_ON_5G) {
1602 for (i = 0; i < ARRAY_SIZE(channel5G); ++i) {
1603 if (channel5G[i] == Channel)
1607 DBG_871X("Invalid Band %d in %s", Band, __func__);
1609 if (channelIndex == -1)
1610 DBG_871X("Invalid Channel %d of Band %d in %s", Channel, Band, __func__);
1612 return channelIndex;
1615 static s16 get_bandwidth_idx(const enum CHANNEL_WIDTH bandwidth)
1617 switch (bandwidth) {
1618 case CHANNEL_WIDTH_20:
1620 case CHANNEL_WIDTH_40:
1622 case CHANNEL_WIDTH_80:
1624 case CHANNEL_WIDTH_160:
1631 static s16 get_rate_sctn_idx(const u8 rate)
1634 case MGN_1M: case MGN_2M: case MGN_5_5M: case MGN_11M:
1636 case MGN_6M: case MGN_9M: case MGN_12M: case MGN_18M:
1637 case MGN_24M: case MGN_36M: case MGN_48M: case MGN_54M:
1639 case MGN_MCS0: case MGN_MCS1: case MGN_MCS2: case MGN_MCS3:
1640 case MGN_MCS4: case MGN_MCS5: case MGN_MCS6: case MGN_MCS7:
1642 case MGN_MCS8: case MGN_MCS9: case MGN_MCS10: case MGN_MCS11:
1643 case MGN_MCS12: case MGN_MCS13: case MGN_MCS14: case MGN_MCS15:
1645 case MGN_MCS16: case MGN_MCS17: case MGN_MCS18: case MGN_MCS19:
1646 case MGN_MCS20: case MGN_MCS21: case MGN_MCS22: case MGN_MCS23:
1648 case MGN_MCS24: case MGN_MCS25: case MGN_MCS26: case MGN_MCS27:
1649 case MGN_MCS28: case MGN_MCS29: case MGN_MCS30: case MGN_MCS31:
1651 case MGN_VHT1SS_MCS0: case MGN_VHT1SS_MCS1: case MGN_VHT1SS_MCS2:
1652 case MGN_VHT1SS_MCS3: case MGN_VHT1SS_MCS4: case MGN_VHT1SS_MCS5:
1653 case MGN_VHT1SS_MCS6: case MGN_VHT1SS_MCS7: case MGN_VHT1SS_MCS8:
1654 case MGN_VHT1SS_MCS9:
1656 case MGN_VHT2SS_MCS0: case MGN_VHT2SS_MCS1: case MGN_VHT2SS_MCS2:
1657 case MGN_VHT2SS_MCS3: case MGN_VHT2SS_MCS4: case MGN_VHT2SS_MCS5:
1658 case MGN_VHT2SS_MCS6: case MGN_VHT2SS_MCS7: case MGN_VHT2SS_MCS8:
1659 case MGN_VHT2SS_MCS9:
1661 case MGN_VHT3SS_MCS0: case MGN_VHT3SS_MCS1: case MGN_VHT3SS_MCS2:
1662 case MGN_VHT3SS_MCS3: case MGN_VHT3SS_MCS4: case MGN_VHT3SS_MCS5:
1663 case MGN_VHT3SS_MCS6: case MGN_VHT3SS_MCS7: case MGN_VHT3SS_MCS8:
1664 case MGN_VHT3SS_MCS9:
1666 case MGN_VHT4SS_MCS0: case MGN_VHT4SS_MCS1: case MGN_VHT4SS_MCS2:
1667 case MGN_VHT4SS_MCS3: case MGN_VHT4SS_MCS4: case MGN_VHT4SS_MCS5:
1668 case MGN_VHT4SS_MCS6: case MGN_VHT4SS_MCS7: case MGN_VHT4SS_MCS8:
1669 case MGN_VHT4SS_MCS9:
1672 DBG_871X("Wrong rate 0x%x\n", rate);
1677 s8 phy_get_tx_pwr_lmt(struct adapter *adapter, u32 reg_pwr_tbl_sel,
1678 enum BAND_TYPE band_type, enum CHANNEL_WIDTH bandwidth,
1679 u8 rf_path, u8 data_rate, u8 channel)
1682 s16 idx_regulation = -1;
1683 s16 idx_bandwidth = -1;
1684 s16 idx_rate_sctn = -1;
1685 s16 idx_channel = -1;
1686 s8 pwr_lmt = MAX_POWER_INDEX;
1687 struct hal_com_data *hal_data = GET_HAL_DATA(adapter);
1689 if (((adapter->registrypriv.RegEnableTxPowerLimit == 2) &&
1690 (hal_data->EEPROMRegulatory != 1)) ||
1691 (adapter->registrypriv.RegEnableTxPowerLimit == 0))
1692 return MAX_POWER_INDEX;
1694 switch (adapter->registrypriv.RegPwrTblSel) {
1696 idx_regulation = TXPWR_LMT_ETSI;
1699 idx_regulation = TXPWR_LMT_MKK;
1702 idx_regulation = TXPWR_LMT_FCC;
1705 idx_regulation = TXPWR_LMT_WW;
1708 idx_regulation = (band_type == BAND_ON_2_4G) ?
1709 hal_data->Regulation2_4G :
1710 hal_data->Regulation5G;
1714 /* DBG_871X("pMgntInfo->RegPwrTblSel %d, final regulation %d\n", */
1715 /* adapter->registrypriv.RegPwrTblSel, idx_regulation); */
1717 if (band_type == BAND_ON_2_4G)
1719 else if (band_type == BAND_ON_5G)
1722 idx_bandwidth = get_bandwidth_idx(bandwidth);
1723 idx_rate_sctn = get_rate_sctn_idx(data_rate);
1725 if (band_type == BAND_ON_5G && idx_rate_sctn == 0)
1726 DBG_871X("Wrong rate 0x%x: No CCK in 5G Band\n", DataRate);
1728 /* workaround for wrong index combination to obtain tx power limit, */
1729 /* OFDM only exists in BW 20M */
1730 /* CCK table will only be given in BW 20M */
1731 /* HT on 80M will reference to HT on 40M */
1732 if (idx_rate_sctn == 0 || idx_rate_sctn == 1)
1734 else if ((idx_rate_sctn == 2 || idx_rate_sctn == 3) &&
1735 (band_type == BAND_ON_5G) && (idx_bandwidth == 2))
1738 if (band_type == BAND_ON_2_4G || band_type == BAND_ON_5G)
1739 channel = phy_GetChannelIndexOfTxPowerLimit(band_type, channel);
1741 if (idx_band == -1 || idx_regulation == -1 || idx_bandwidth == -1 ||
1742 idx_rate_sctn == -1 || idx_channel == -1) {
1743 /* 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", */
1744 /* idx_band, idx_regulation, idx_bandwidth, rf_path, */
1745 /* idx_rate_sctn, channel); */
1747 return MAX_POWER_INDEX;
1750 if (band_type == BAND_ON_2_4G) {
1751 s8 limits[10] = {0}; u8 i = 0;
1752 for (i = 0; i < MAX_REGULATION_NUM; i++)
1753 limits[i] = hal_data->TxPwrLimit_2_4G[i]
1759 pwr_lmt = (idx_regulation == TXPWR_LMT_WW) ?
1760 phy_GetWorldWideLimit(limits) :
1761 hal_data->TxPwrLimit_2_4G[idx_regulation]
1767 } else if (band_type == BAND_ON_5G) {
1768 s8 limits[10] = {0}; u8 i = 0;
1769 for (i = 0; i < MAX_REGULATION_NUM; ++i)
1770 limits[i] = hal_data->TxPwrLimit_5G[i]
1776 pwr_lmt = (idx_regulation == TXPWR_LMT_WW) ?
1777 phy_GetWorldWideLimit(limits) :
1778 hal_data->TxPwrLimit_5G[idx_regulation]
1784 DBG_871X("No power limit table of the specified band\n");
1787 /* combine 5G VHT & HT rate */
1788 /* 5G 20M and 40M HT and VHT can cross reference */
1790 if (band_type == BAND_ON_5G && pwr_lmt == MAX_POWER_INDEX) {
1791 if (idx_bandwidth == 0 || idx_bandwidth == 1) {
1792 RT_TRACE(COMP_INIT, DBG_LOUD, ("No power limit table of the specified band %d, bandwidth %d, ratesection %d, rf path %d\n",
1793 idx_band, idx_bandwidth,
1794 idx_rate_sctn, rf_path));
1795 if (idx_rate_sctn == 2)
1796 pwr_lmt = hal_data->TxPwrLimit_5G[idx_regulation][idx_bandwidth][4][idx_channel][rf_path];
1797 else if (idx_rate_sctn == 4)
1798 pwr_lmt = hal_data->TxPwrLimit_5G[idx_regulation][idx_bandwidth][2][idx_channel][rf_path];
1799 else if (idx_rate_sctn == 3)
1800 pwr_lmt = hal_data->TxPwrLimit_5G[idx_regulation][idx_bandwidth][5][idx_channel][rf_path];
1801 else if (idx_rate_sctn == 5)
1802 pwr_lmt = hal_data->TxPwrLimit_5G[idx_regulation][idx_bandwidth][3][idx_channel][rf_path];
1807 /* DBG_871X("TxPwrLmt[Regulation %d][Band %d][BW %d][RFPath %d][Rate 0x%x][Chnl %d] = %d\n", */
1808 /* idx_regulation, hal_data->CurrentBandType, bandwidth, rf_path, data_rate, channel, pwr_lmt); */
1812 static void phy_CrossReferenceHTAndVHTTxPowerLimit(struct adapter *padapter)
1814 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1815 u8 regulation, bw, channel, rateSection;
1818 for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
1819 for (bw = 0; bw < MAX_5G_BANDWITH_NUM; ++bw) {
1820 for (channel = 0; channel < CHANNEL_MAX_NUMBER_5G; ++channel) {
1821 for (rateSection = 0; rateSection < MAX_RATE_SECTION_NUM; ++rateSection) {
1822 tempPwrLmt = pHalData->TxPwrLimit_5G[regulation][bw][rateSection][channel][ODM_RF_PATH_A];
1823 if (tempPwrLmt == MAX_POWER_INDEX) {
1824 u8 baseSection = 2, refSection = 6;
1825 if (bw == 0 || bw == 1) { /* 5G 20M 40M VHT and HT can cross reference */
1826 /* DBG_871X("No power limit table of the specified band %d, bandwidth %d, ratesection %d, channel %d, rf path %d\n", */
1827 /* 1, bw, rateSection, channel, ODM_RF_PATH_A); */
1828 if (rateSection >= 2 && rateSection <= 9) {
1829 if (rateSection == 2) {
1832 } else if (rateSection == 3) {
1835 } else if (rateSection == 4) {
1838 } else if (rateSection == 5) {
1841 } else if (rateSection == 6) {
1844 } else if (rateSection == 7) {
1847 } else if (rateSection == 8) {
1850 } else if (rateSection == 9) {
1854 pHalData->TxPwrLimit_5G[regulation][bw][baseSection][channel][ODM_RF_PATH_A] =
1855 pHalData->TxPwrLimit_5G[regulation][bw][refSection][channel][ODM_RF_PATH_A];
1858 /* DBG_871X("use other value %d", tempPwrLmt); */
1867 void PHY_ConvertTxPowerLimitToPowerIndex(struct adapter *Adapter)
1869 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1870 u8 BW40PwrBasedBm2_4G = 0x2E;
1871 u8 regulation, bw, channel, rateSection;
1872 s8 tempValue = 0, tempPwrLmt = 0;
1875 /* DBG_871X("=====> PHY_ConvertTxPowerLimitToPowerIndex()\n"); */
1877 phy_CrossReferenceHTAndVHTTxPowerLimit(Adapter);
1879 for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
1880 for (bw = 0; bw < MAX_2_4G_BANDWITH_NUM; ++bw) {
1881 for (channel = 0; channel < CHANNEL_MAX_NUMBER_2G; ++channel) {
1882 for (rateSection = 0; rateSection < MAX_RATE_SECTION_NUM; ++rateSection) {
1883 tempPwrLmt = pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][channel][ODM_RF_PATH_A];
1885 for (rfPath = ODM_RF_PATH_A; rfPath < MAX_RF_PATH_NUM; ++rfPath) {
1886 if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) {
1887 if (rateSection == 5) /* HT 4T */
1888 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_4TX, HT_MCS24_MCS31);
1889 else if (rateSection == 4) /* HT 3T */
1890 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_3TX, HT_MCS16_MCS23);
1891 else if (rateSection == 3) /* HT 2T */
1892 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_2TX, HT_MCS8_MCS15);
1893 else if (rateSection == 2) /* HT 1T */
1894 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_1TX, HT_MCS0_MCS7);
1895 else if (rateSection == 1) /* OFDM */
1896 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_1TX, OFDM);
1897 else if (rateSection == 0) /* CCK */
1898 BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, BAND_ON_2_4G, rfPath, RF_1TX, CCK);
1900 BW40PwrBasedBm2_4G = Adapter->registrypriv.RegPowerBase * 2;
1902 if (tempPwrLmt != MAX_POWER_INDEX) {
1903 tempValue = tempPwrLmt - BW40PwrBasedBm2_4G;
1904 pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][channel][rfPath] = tempValue;
1912 /* DBG_871X("<===== PHY_ConvertTxPowerLimitToPowerIndex()\n"); */
1915 void PHY_InitTxPowerLimit(struct adapter *Adapter)
1917 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1920 /* DBG_871X("=====> PHY_InitTxPowerLimit()!\n"); */
1922 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
1923 for (j = 0; j < MAX_2_4G_BANDWITH_NUM; ++j)
1924 for (k = 0; k < MAX_RATE_SECTION_NUM; ++k)
1925 for (m = 0; m < CHANNEL_MAX_NUMBER_2G; ++m)
1926 for (l = 0; l < MAX_RF_PATH_NUM; ++l)
1927 pHalData->TxPwrLimit_2_4G[i][j][k][m][l] = MAX_POWER_INDEX;
1930 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
1931 for (j = 0; j < MAX_5G_BANDWITH_NUM; ++j)
1932 for (k = 0; k < MAX_RATE_SECTION_NUM; ++k)
1933 for (m = 0; m < CHANNEL_MAX_NUMBER_5G; ++m)
1934 for (l = 0; l < MAX_RF_PATH_NUM; ++l)
1935 pHalData->TxPwrLimit_5G[i][j][k][m][l] = MAX_POWER_INDEX;
1938 /* DBG_871X("<===== PHY_InitTxPowerLimit()!\n"); */
1941 void PHY_SetTxPowerLimit(
1942 struct adapter *Adapter,
1952 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1953 u8 regulation = 0, bandwidth = 0, rateSection = 0, channel;
1954 s8 powerLimit = 0, prevPowerLimit, channelIndex;
1956 /* DBG_871X("Index of power limit table [band %s][regulation %s][bw %s][rate section %s][rf path %s][chnl %s][val %s]\n", */
1957 /* Band, Regulation, Bandwidth, RateSection, RfPath, Channel, PowerLimit); */
1959 if (!GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel) ||
1960 !GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit))
1961 DBG_871X("Illegal index of power limit table [chnl %s][val %s]\n", Channel, PowerLimit);
1963 powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit;
1965 if (eqNByte(Regulation, (u8 *)("FCC"), 3))
1967 else if (eqNByte(Regulation, (u8 *)("MKK"), 3))
1969 else if (eqNByte(Regulation, (u8 *)("ETSI"), 4))
1971 else if (eqNByte(Regulation, (u8 *)("WW13"), 4))
1974 if (eqNByte(RateSection, (u8 *)("CCK"), 3) && eqNByte(RfPath, (u8 *)("1T"), 2))
1976 else if (eqNByte(RateSection, (u8 *)("OFDM"), 4) && eqNByte(RfPath, (u8 *)("1T"), 2))
1978 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("1T"), 2))
1980 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("2T"), 2))
1982 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("3T"), 2))
1984 else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("4T"), 2))
1986 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("1T"), 2))
1988 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("2T"), 2))
1990 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("3T"), 2))
1992 else if (eqNByte(RateSection, (u8 *)("VHT"), 3) && eqNByte(RfPath, (u8 *)("4T"), 2))
1995 DBG_871X("Wrong rate section!\n");
2000 if (eqNByte(Bandwidth, (u8 *)("20M"), 3))
2002 else if (eqNByte(Bandwidth, (u8 *)("40M"), 3))
2004 else if (eqNByte(Bandwidth, (u8 *)("80M"), 3))
2006 else if (eqNByte(Bandwidth, (u8 *)("160M"), 4))
2009 if (eqNByte(Band, (u8 *)("2.4G"), 4)) {
2010 channelIndex = phy_GetChannelIndexOfTxPowerLimit(BAND_ON_2_4G, channel);
2012 if (channelIndex == -1)
2015 prevPowerLimit = pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A];
2017 if (powerLimit < prevPowerLimit)
2018 pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A] = powerLimit;
2020 /* DBG_871X("2.4G Band value : [regulation %d][bw %d][rate_section %d][chnl %d][val %d]\n", */
2021 /* regulation, bandwidth, rateSection, channelIndex, pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A]); */
2022 } else if (eqNByte(Band, (u8 *)("5G"), 2)) {
2023 channelIndex = phy_GetChannelIndexOfTxPowerLimit(BAND_ON_5G, channel);
2025 if (channelIndex == -1)
2028 prevPowerLimit = pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A];
2030 if (powerLimit < prevPowerLimit)
2031 pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A] = powerLimit;
2033 /* DBG_871X("5G Band value : [regulation %d][bw %d][rate_section %d][chnl %d][val %d]\n", */
2034 /* regulation, bandwidth, rateSection, channel, pHalData->TxPwrLimit_5G[regulation][bandwidth][rateSection][channelIndex][ODM_RF_PATH_A]); */
2036 DBG_871X("Cannot recognize the band info in %s\n", Band);
2041 u8 PHY_GetTxPowerIndex(
2042 struct adapter *padapter,
2045 enum CHANNEL_WIDTH BandWidth,
2049 return PHY_GetTxPowerIndex_8723B(padapter, RFPath, Rate, BandWidth, Channel);
2052 void PHY_SetTxPowerIndex(
2053 struct adapter *padapter, u32 PowerIndex, u8 RFPath, u8 Rate
2056 PHY_SetTxPowerIndex_8723B(padapter, PowerIndex, RFPath, Rate);
2059 void Hal_ChannelPlanToRegulation(struct adapter *Adapter, u16 ChannelPlan)
2061 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2062 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2063 pHalData->Regulation5G = TXPWR_LMT_WW;
2065 switch (ChannelPlan) {
2066 case RT_CHANNEL_DOMAIN_WORLD_NULL:
2067 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2069 case RT_CHANNEL_DOMAIN_ETSI1_NULL:
2070 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2072 case RT_CHANNEL_DOMAIN_FCC1_NULL:
2073 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2075 case RT_CHANNEL_DOMAIN_MKK1_NULL:
2076 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2078 case RT_CHANNEL_DOMAIN_ETSI2_NULL:
2079 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2081 case RT_CHANNEL_DOMAIN_FCC1_FCC1:
2082 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2083 pHalData->Regulation5G = TXPWR_LMT_FCC;
2085 case RT_CHANNEL_DOMAIN_WORLD_ETSI1:
2086 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2087 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2089 case RT_CHANNEL_DOMAIN_MKK1_MKK1:
2090 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2091 pHalData->Regulation5G = TXPWR_LMT_MKK;
2093 case RT_CHANNEL_DOMAIN_WORLD_KCC1:
2094 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2095 pHalData->Regulation5G = TXPWR_LMT_MKK;
2097 case RT_CHANNEL_DOMAIN_WORLD_FCC2:
2098 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2099 pHalData->Regulation5G = TXPWR_LMT_FCC;
2101 case RT_CHANNEL_DOMAIN_WORLD_FCC3:
2102 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2103 pHalData->Regulation5G = TXPWR_LMT_FCC;
2105 case RT_CHANNEL_DOMAIN_WORLD_FCC4:
2106 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2107 pHalData->Regulation5G = TXPWR_LMT_FCC;
2109 case RT_CHANNEL_DOMAIN_WORLD_FCC5:
2110 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2111 pHalData->Regulation5G = TXPWR_LMT_FCC;
2113 case RT_CHANNEL_DOMAIN_WORLD_FCC6:
2114 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2115 pHalData->Regulation5G = TXPWR_LMT_FCC;
2117 case RT_CHANNEL_DOMAIN_FCC1_FCC7:
2118 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2119 pHalData->Regulation5G = TXPWR_LMT_FCC;
2121 case RT_CHANNEL_DOMAIN_WORLD_ETSI2:
2122 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2123 pHalData->Regulation5G = TXPWR_LMT_FCC;
2125 case RT_CHANNEL_DOMAIN_WORLD_ETSI3:
2126 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2127 pHalData->Regulation5G = TXPWR_LMT_FCC;
2129 case RT_CHANNEL_DOMAIN_MKK1_MKK2:
2130 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2131 pHalData->Regulation5G = TXPWR_LMT_FCC;
2133 case RT_CHANNEL_DOMAIN_MKK1_MKK3:
2134 pHalData->Regulation2_4G = TXPWR_LMT_MKK;
2135 pHalData->Regulation5G = TXPWR_LMT_FCC;
2137 case RT_CHANNEL_DOMAIN_FCC1_NCC1:
2138 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2139 pHalData->Regulation5G = TXPWR_LMT_FCC;
2141 case RT_CHANNEL_DOMAIN_FCC1_NCC2:
2142 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2143 pHalData->Regulation5G = TXPWR_LMT_FCC;
2145 case RT_CHANNEL_DOMAIN_GLOBAL_NULL:
2146 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2147 pHalData->Regulation5G = TXPWR_LMT_WW;
2149 case RT_CHANNEL_DOMAIN_ETSI1_ETSI4:
2150 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2151 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2153 case RT_CHANNEL_DOMAIN_FCC1_FCC2:
2154 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2155 pHalData->Regulation5G = TXPWR_LMT_FCC;
2157 case RT_CHANNEL_DOMAIN_FCC1_NCC3:
2158 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2159 pHalData->Regulation5G = TXPWR_LMT_FCC;
2161 case RT_CHANNEL_DOMAIN_WORLD_ETSI5:
2162 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2163 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2165 case RT_CHANNEL_DOMAIN_FCC1_FCC8:
2166 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2167 pHalData->Regulation5G = TXPWR_LMT_FCC;
2169 case RT_CHANNEL_DOMAIN_WORLD_ETSI6:
2170 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2171 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2173 case RT_CHANNEL_DOMAIN_WORLD_ETSI7:
2174 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2175 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2177 case RT_CHANNEL_DOMAIN_WORLD_ETSI8:
2178 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2179 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2181 case RT_CHANNEL_DOMAIN_WORLD_ETSI9:
2182 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2183 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2185 case RT_CHANNEL_DOMAIN_WORLD_ETSI10:
2186 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2187 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2189 case RT_CHANNEL_DOMAIN_WORLD_ETSI11:
2190 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2191 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2193 case RT_CHANNEL_DOMAIN_FCC1_NCC4:
2194 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2195 pHalData->Regulation5G = TXPWR_LMT_FCC;
2197 case RT_CHANNEL_DOMAIN_WORLD_ETSI12:
2198 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2199 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2201 case RT_CHANNEL_DOMAIN_FCC1_FCC9:
2202 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2203 pHalData->Regulation5G = TXPWR_LMT_FCC;
2205 case RT_CHANNEL_DOMAIN_WORLD_ETSI13:
2206 pHalData->Regulation2_4G = TXPWR_LMT_ETSI;
2207 pHalData->Regulation5G = TXPWR_LMT_ETSI;
2209 case RT_CHANNEL_DOMAIN_FCC1_FCC10:
2210 pHalData->Regulation2_4G = TXPWR_LMT_FCC;
2211 pHalData->Regulation5G = TXPWR_LMT_FCC;
2213 case RT_CHANNEL_DOMAIN_REALTEK_DEFINE: /* Realtek Reserve */
2214 pHalData->Regulation2_4G = TXPWR_LMT_WW;
2215 pHalData->Regulation5G = TXPWR_LMT_WW;
2223 static char file_path_bs[PATH_MAX];
2225 #define GetLineFromBuffer(buffer) strsep(&buffer, "\n")
2227 int phy_ConfigMACWithParaFile(struct adapter *Adapter, char *pFileName)
2229 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2230 int rlen = 0, rtStatus = _FAIL;
2231 char *szLine, *ptmp;
2232 u32 u4bRegOffset, u4bRegValue, u4bMove;
2234 if (!(Adapter->registrypriv.load_phy_file & LOAD_MAC_PARA_FILE))
2237 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2239 if ((pHalData->mac_reg_len == 0) && (pHalData->mac_reg == NULL)) {
2240 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2242 if (rtw_is_file_readable(file_path_bs) == true) {
2243 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2245 rtStatus = _SUCCESS;
2246 pHalData->mac_reg = vzalloc(rlen);
2247 if (pHalData->mac_reg) {
2248 memcpy(pHalData->mac_reg, pHalData->para_file_buf, rlen);
2249 pHalData->mac_reg_len = rlen;
2251 DBG_871X("%s mac_reg alloc fail !\n", __func__);
2255 if ((pHalData->mac_reg_len != 0) && (pHalData->mac_reg != NULL)) {
2256 memcpy(pHalData->para_file_buf, pHalData->mac_reg, pHalData->mac_reg_len);
2257 rtStatus = _SUCCESS;
2259 DBG_871X("%s(): Critical Error !!!\n", __func__);
2262 if (rtStatus == _SUCCESS) {
2263 ptmp = pHalData->para_file_buf;
2264 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2265 if (!IsCommentString(szLine)) {
2266 /* Get 1st hex value as register offset */
2267 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2268 if (u4bRegOffset == 0xffff) /* Ending. */
2271 /* Get 2nd hex value as register value. */
2273 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove))
2274 rtw_write8(Adapter, u4bRegOffset, (u8)u4bRegValue);
2279 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2284 int phy_ConfigBBWithParaFile(
2285 struct adapter *Adapter, char *pFileName, u32 ConfigType
2288 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2289 int rlen = 0, rtStatus = _FAIL;
2290 char *szLine, *ptmp;
2291 u32 u4bRegOffset, u4bRegValue, u4bMove;
2293 u32 *pBufLen = NULL;
2295 if (!(Adapter->registrypriv.load_phy_file & LOAD_BB_PARA_FILE))
2298 switch (ConfigType) {
2299 case CONFIG_BB_PHY_REG:
2300 pBuf = pHalData->bb_phy_reg;
2301 pBufLen = &pHalData->bb_phy_reg_len;
2303 case CONFIG_BB_AGC_TAB:
2304 pBuf = pHalData->bb_agc_tab;
2305 pBufLen = &pHalData->bb_agc_tab_len;
2308 DBG_871X("Unknown ConfigType!! %d\r\n", ConfigType);
2312 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2314 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2315 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2317 if (rtw_is_file_readable(file_path_bs) == true) {
2318 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2320 rtStatus = _SUCCESS;
2321 pBuf = vzalloc(rlen);
2323 memcpy(pBuf, pHalData->para_file_buf, rlen);
2326 switch (ConfigType) {
2327 case CONFIG_BB_PHY_REG:
2328 pHalData->bb_phy_reg = pBuf;
2330 case CONFIG_BB_AGC_TAB:
2331 pHalData->bb_agc_tab = pBuf;
2335 DBG_871X("%s(): ConfigType %d alloc fail !\n", __func__, ConfigType);
2339 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2340 memcpy(pHalData->para_file_buf, pBuf, *pBufLen);
2341 rtStatus = _SUCCESS;
2343 DBG_871X("%s(): Critical Error !!!\n", __func__);
2346 if (rtStatus == _SUCCESS) {
2347 ptmp = pHalData->para_file_buf;
2348 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2349 if (!IsCommentString(szLine)) {
2350 /* Get 1st hex value as register offset. */
2351 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2352 if (u4bRegOffset == 0xffff) /* Ending. */
2354 else if (u4bRegOffset == 0xfe || u4bRegOffset == 0xffe)
2356 else if (u4bRegOffset == 0xfd)
2358 else if (u4bRegOffset == 0xfc)
2360 else if (u4bRegOffset == 0xfb)
2362 else if (u4bRegOffset == 0xfa)
2364 else if (u4bRegOffset == 0xf9)
2367 /* Get 2nd hex value as register value. */
2369 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2370 /* DBG_871X("[BB-ADDR]%03lX =%08lX\n", u4bRegOffset, u4bRegValue); */
2371 PHY_SetBBReg(Adapter, u4bRegOffset, bMaskDWord, u4bRegValue);
2373 if (u4bRegOffset == 0xa24)
2374 pHalData->odmpriv.RFCalibrateInfo.RegA24 = u4bRegValue;
2376 /* Add 1us delay between BB/RF register setting. */
2383 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2388 static void phy_DecryptBBPgParaFile(struct adapter *Adapter, char *buffer)
2393 char *BufOfLines, *ptmp;
2395 /* DBG_871X("=====>phy_DecryptBBPgParaFile()\n"); */
2396 /* 32 the ascii code of the first visable char, 126 the last one */
2397 for (i = 0; i < 95; ++i)
2398 map[i] = (u8) (94 - i);
2402 for (BufOfLines = GetLineFromBuffer(ptmp); BufOfLines != NULL; BufOfLines = GetLineFromBuffer(ptmp)) {
2403 /* DBG_871X("Encrypted Line: %s\n", BufOfLines); */
2405 for (j = 0; j < strlen(BufOfLines); ++j) {
2406 currentChar = BufOfLines[j];
2408 if (currentChar == '\0')
2411 currentChar -= (u8) ((((i + j) * 3) % 128));
2413 BufOfLines[j] = map[currentChar - 32] + 32;
2415 /* DBG_871X("Decrypted Line: %s\n", BufOfLines); */
2416 if (strlen(BufOfLines) != 0)
2418 BufOfLines[strlen(BufOfLines)] = '\n';
2422 static int phy_ParseBBPgParaFile(struct adapter *Adapter, char *buffer)
2424 int rtStatus = _SUCCESS;
2425 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2426 char *szLine, *ptmp;
2427 u32 u4bRegOffset, u4bRegMask, u4bRegValue;
2429 bool firstLine = true;
2431 u8 band = 0, rf_path = 0;
2433 /* DBG_871X("=====>phy_ParseBBPgParaFile()\n"); */
2435 if (Adapter->registrypriv.RegDecryptCustomFile == 1)
2436 phy_DecryptBBPgParaFile(Adapter, buffer);
2439 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2440 if (!IsCommentString(szLine)) {
2441 if (isAllSpaceOrTab(szLine, sizeof(*szLine)))
2444 /* Get header info (relative value or exact value) */
2446 if (eqNByte(szLine, (u8 *)("#[v1]"), 5)) {
2448 pHalData->odmpriv.PhyRegPgVersion = szLine[3] - '0';
2449 /* DBG_871X("This is a new format PHY_REG_PG.txt\n"); */
2450 } else if (eqNByte(szLine, (u8 *)("#[v0]"), 5)) {
2451 pHalData->odmpriv.PhyRegPgVersion = szLine[3] - '0';
2452 /* DBG_871X("This is a old format PHY_REG_PG.txt ok\n"); */
2454 DBG_871X("The format in PHY_REG_PG are invalid %s\n", szLine);
2458 if (eqNByte(szLine + 5, (u8 *)("[Exact]#"), 8)) {
2459 pHalData->odmpriv.PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE;
2460 /* DBG_871X("The values in PHY_REG_PG are exact values ok\n"); */
2463 } else if (eqNByte(szLine + 5, (u8 *)("[Relative]#"), 11)) {
2464 pHalData->odmpriv.PhyRegPgValueType = PHY_REG_PG_RELATIVE_VALUE;
2465 /* DBG_871X("The values in PHY_REG_PG are relative values ok\n"); */
2469 DBG_871X("The values in PHY_REG_PG are invalid %s\n", szLine);
2474 if (pHalData->odmpriv.PhyRegPgVersion == 0) {
2475 /* Get 1st hex value as register offset. */
2476 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2478 if (u4bRegOffset == 0xffff) /* Ending. */
2481 /* Get 2nd hex value as register mask. */
2482 if (GetHexValueFromString(szLine, &u4bRegMask, &u4bMove))
2487 if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_RELATIVE_VALUE) {
2488 /* Get 3rd hex value as register value. */
2489 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2490 PHY_StoreTxPowerByRate(Adapter, 0, 0, 1, u4bRegOffset, u4bRegMask, u4bRegValue);
2491 /* DBG_871X("[ADDR] %03X =%08X Mask =%08x\n", u4bRegOffset, u4bRegValue, u4bRegMask); */
2494 } else if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) {
2495 u32 combineValue = 0;
2496 u8 integer = 0, fraction = 0;
2498 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2506 combineValue |= (((integer / 10) << 4) + (integer % 10));
2507 /* DBG_871X(" %d", integer); */
2509 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2518 combineValue |= (((integer / 10) << 4) + (integer % 10));
2519 /* DBG_871X(" %d", integer); */
2521 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2530 combineValue |= (((integer / 10) << 4) + (integer % 10));
2531 /* DBG_871X(" %d", integer); */
2533 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2542 combineValue |= (((integer / 10) << 4) + (integer % 10));
2543 /* DBG_871X(" %d", integer); */
2544 PHY_StoreTxPowerByRate(Adapter, 0, 0, 1, u4bRegOffset, u4bRegMask, combineValue);
2546 /* DBG_871X("[ADDR] 0x%3x = 0x%4x\n", u4bRegOffset, combineValue); */
2549 } else if (pHalData->odmpriv.PhyRegPgVersion > 0) {
2552 if (eqNByte(szLine, "0xffff", 6))
2555 if (!eqNByte("#[END]#", szLine, 7)) {
2556 /* load the table label info */
2557 if (szLine[0] == '#') {
2559 if (eqNByte(szLine, "#[2.4G]", 7)) {
2560 band = BAND_ON_2_4G;
2562 } else if (eqNByte(szLine, "#[5G]", 5)) {
2566 DBG_871X("Invalid band %s in PHY_REG_PG.txt\n", szLine);
2570 rf_path = szLine[index] - 'A';
2571 /* DBG_871X(" Table label Band %d, RfPath %d\n", band, rf_path); */
2572 } else { /* load rows of tables */
2573 if (szLine[1] == '1')
2575 else if (szLine[1] == '2')
2577 else if (szLine[1] == '3')
2579 else if (szLine[1] == '4')
2582 DBG_871X("Invalid row in PHY_REG_PG.txt %c\n", szLine[1]);
2586 while (szLine[index] != ']')
2588 ++index;/* skip ] */
2590 /* Get 2nd hex value as register offset. */
2592 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove))
2597 /* Get 2nd hex value as register mask. */
2598 if (GetHexValueFromString(szLine, &u4bRegMask, &u4bMove))
2603 if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_RELATIVE_VALUE) {
2604 /* Get 3rd hex value as register value. */
2605 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2606 PHY_StoreTxPowerByRate(Adapter, band, rf_path, tx_num, u4bRegOffset, u4bRegMask, u4bRegValue);
2607 /* DBG_871X("[ADDR] %03X (tx_num %d) =%08X Mask =%08x\n", u4bRegOffset, tx_num, u4bRegValue, u4bRegMask); */
2610 } else if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) {
2611 u32 combineValue = 0;
2612 u8 integer = 0, fraction = 0;
2614 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2622 combineValue |= (((integer / 10) << 4) + (integer % 10));
2623 /* DBG_871X(" %d", integer); */
2625 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2634 combineValue |= (((integer / 10) << 4) + (integer % 10));
2635 /* DBG_871X(" %d", integer); */
2637 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2646 combineValue |= (((integer / 10) << 4) + (integer % 10));
2647 /* DBG_871X(" %d", integer); */
2649 if (GetFractionValueFromString(szLine, &integer, &fraction, &u4bMove))
2658 combineValue |= (((integer / 10) << 4) + (integer % 10));
2659 /* DBG_871X(" %d", integer); */
2660 PHY_StoreTxPowerByRate(Adapter, band, rf_path, tx_num, u4bRegOffset, u4bRegMask, combineValue);
2662 /* DBG_871X("[ADDR] 0x%3x (tx_num %d) = 0x%4x\n", u4bRegOffset, tx_num, combineValue); */
2669 /* DBG_871X("<=====phy_ParseBBPgParaFile()\n"); */
2673 int phy_ConfigBBWithPgParaFile(struct adapter *Adapter, char *pFileName)
2675 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2676 int rlen = 0, rtStatus = _FAIL;
2678 if (!(Adapter->registrypriv.load_phy_file & LOAD_BB_PG_PARA_FILE))
2681 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2683 if ((pHalData->bb_phy_reg_pg_len == 0) && (pHalData->bb_phy_reg_pg == NULL)) {
2684 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2686 if (rtw_is_file_readable(file_path_bs) == true) {
2687 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2689 rtStatus = _SUCCESS;
2690 pHalData->bb_phy_reg_pg = vzalloc(rlen);
2691 if (pHalData->bb_phy_reg_pg) {
2692 memcpy(pHalData->bb_phy_reg_pg, pHalData->para_file_buf, rlen);
2693 pHalData->bb_phy_reg_pg_len = rlen;
2695 DBG_871X("%s bb_phy_reg_pg alloc fail !\n", __func__);
2699 if ((pHalData->bb_phy_reg_pg_len != 0) && (pHalData->bb_phy_reg_pg != NULL)) {
2700 memcpy(pHalData->para_file_buf, pHalData->bb_phy_reg_pg, pHalData->bb_phy_reg_pg_len);
2701 rtStatus = _SUCCESS;
2703 DBG_871X("%s(): Critical Error !!!\n", __func__);
2706 if (rtStatus == _SUCCESS) {
2707 /* DBG_871X("phy_ConfigBBWithPgParaFile(): read %s ok\n", pFileName); */
2708 phy_ParseBBPgParaFile(Adapter, pHalData->para_file_buf);
2710 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2715 int PHY_ConfigRFWithParaFile(
2716 struct adapter *Adapter, char *pFileName, u8 eRFPath
2719 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2720 int rlen = 0, rtStatus = _FAIL;
2721 char *szLine, *ptmp;
2722 u32 u4bRegOffset, u4bRegValue, u4bMove;
2725 u32 *pBufLen = NULL;
2727 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_PARA_FILE))
2732 pBuf = pHalData->rf_radio_a;
2733 pBufLen = &pHalData->rf_radio_a_len;
2736 pBuf = pHalData->rf_radio_b;
2737 pBufLen = &pHalData->rf_radio_b_len;
2740 DBG_871X("Unknown RF path!! %d\r\n", eRFPath);
2744 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2746 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2747 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2749 if (rtw_is_file_readable(file_path_bs) == true) {
2750 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2752 rtStatus = _SUCCESS;
2753 pBuf = vzalloc(rlen);
2755 memcpy(pBuf, pHalData->para_file_buf, rlen);
2760 pHalData->rf_radio_a = pBuf;
2763 pHalData->rf_radio_b = pBuf;
2767 DBG_871X("%s(): eRFPath =%d alloc fail !\n", __func__, eRFPath);
2771 if ((pBufLen != NULL) && (*pBufLen == 0) && (pBuf == NULL)) {
2772 memcpy(pHalData->para_file_buf, pBuf, *pBufLen);
2773 rtStatus = _SUCCESS;
2775 DBG_871X("%s(): Critical Error !!!\n", __func__);
2778 if (rtStatus == _SUCCESS) {
2779 /* DBG_871X("%s(): read %s successfully\n", __func__, pFileName); */
2781 ptmp = pHalData->para_file_buf;
2782 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2783 if (!IsCommentString(szLine)) {
2784 /* Get 1st hex value as register offset. */
2785 if (GetHexValueFromString(szLine, &u4bRegOffset, &u4bMove)) {
2786 if (u4bRegOffset == 0xfe || u4bRegOffset == 0xffe) /* Deay specific ms. Only RF configuration require delay. */
2788 else if (u4bRegOffset == 0xfd) {
2790 for (i = 0; i < 100; i++)
2791 udelay(MAX_STALL_TIME);
2792 } else if (u4bRegOffset == 0xfc) {
2794 for (i = 0; i < 20; i++)
2795 udelay(MAX_STALL_TIME);
2796 } else if (u4bRegOffset == 0xfb)
2798 else if (u4bRegOffset == 0xfa)
2800 else if (u4bRegOffset == 0xf9)
2802 else if (u4bRegOffset == 0xffff)
2805 /* Get 2nd hex value as register value. */
2807 if (GetHexValueFromString(szLine, &u4bRegValue, &u4bMove)) {
2808 PHY_SetRFReg(Adapter, eRFPath, u4bRegOffset, bRFRegOffsetMask, u4bRegValue);
2810 /* Temp add, for frequency lock, if no delay, that may cause */
2811 /* frequency shift, ex: 2412MHz => 2417MHz */
2812 /* If frequency shift, the following action may works. */
2813 /* Fractional-N table in radio_a.txt */
2814 /* 0x2a 0x00001 channel 1 */
2815 /* 0x2b 0x00808 frequency divider. */
2824 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2829 static void initDeltaSwingIndexTables(
2830 struct adapter *Adapter,
2839 #define STR_EQUAL_5G(_band, _path, _sign, _rate, _chnl) \
2840 ((strcmp(Band, _band) == 0) && (strcmp(Path, _path) == 0) && (strcmp(Sign, _sign) == 0) &&\
2841 (strcmp(Rate, _rate) == 0) && (strcmp(Channel, _chnl) == 0)\
2843 #define STR_EQUAL_2G(_band, _path, _sign, _rate) \
2844 ((strcmp(Band, _band) == 0) && (strcmp(Path, _path) == 0) && (strcmp(Sign, _sign) == 0) &&\
2845 (strcmp(Rate, _rate) == 0)\
2848 #define STORE_SWING_TABLE(_array, _iteratedIdx) \
2849 for (token = strsep(&Data, delim); token != NULL; token = strsep(&Data, delim)) {\
2850 sscanf(token, "%d", &idx);\
2851 _array[_iteratedIdx++] = (u8)idx;\
2854 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2855 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
2856 PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
2862 /* DBG_871X("===>initDeltaSwingIndexTables(): Band: %s;\nPath: %s;\nSign: %s;\nChannel: %s;\nRate: %s;\n, Data: %s;\n", */
2863 /* Band, Path, Sign, Channel, Rate, Data); */
2865 if (STR_EQUAL_2G("2G", "A", "+", "CCK")) {
2866 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_P, j);
2867 } else if (STR_EQUAL_2G("2G", "A", "-", "CCK")) {
2868 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_N, j);
2869 } else if (STR_EQUAL_2G("2G", "B", "+", "CCK")) {
2870 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_P, j);
2871 } else if (STR_EQUAL_2G("2G", "B", "-", "CCK")) {
2872 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_N, j);
2873 } else if (STR_EQUAL_2G("2G", "A", "+", "ALL")) {
2874 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GA_P, j);
2875 } else if (STR_EQUAL_2G("2G", "A", "-", "ALL")) {
2876 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GA_N, j);
2877 } else if (STR_EQUAL_2G("2G", "B", "+", "ALL")) {
2878 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GB_P, j);
2879 } else if (STR_EQUAL_2G("2G", "B", "-", "ALL")) {
2880 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_2GB_N, j);
2881 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "0")) {
2882 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[0], j);
2883 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "0")) {
2884 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[0], j);
2885 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "0")) {
2886 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[0], j);
2887 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "0")) {
2888 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[0], j);
2889 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "1")) {
2890 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[1], j);
2891 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "1")) {
2892 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[1], j);
2893 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "1")) {
2894 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[1], j);
2895 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "1")) {
2896 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[1], j);
2897 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "2")) {
2898 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[2], j);
2899 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "2")) {
2900 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[2], j);
2901 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "2")) {
2902 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[2], j);
2903 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "2")) {
2904 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[2], j);
2905 } else if (STR_EQUAL_5G("5G", "A", "+", "ALL", "3")) {
2906 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[3], j);
2907 } else if (STR_EQUAL_5G("5G", "A", "-", "ALL", "3")) {
2908 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[3], j);
2909 } else if (STR_EQUAL_5G("5G", "B", "+", "ALL", "3")) {
2910 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[3], j);
2911 } else if (STR_EQUAL_5G("5G", "B", "-", "ALL", "3")) {
2912 STORE_SWING_TABLE(pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[3], j);
2914 DBG_871X("===>initDeltaSwingIndexTables(): The input is invalid!!\n");
2917 int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName)
2919 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2920 int rlen = 0, rtStatus = _FAIL;
2921 char *szLine, *ptmp;
2924 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_TRACK_PARA_FILE))
2927 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
2929 if ((pHalData->rf_tx_pwr_track_len == 0) && (pHalData->rf_tx_pwr_track == NULL)) {
2930 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
2932 if (rtw_is_file_readable(file_path_bs) == true) {
2933 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
2935 rtStatus = _SUCCESS;
2936 pHalData->rf_tx_pwr_track = vzalloc(rlen);
2937 if (pHalData->rf_tx_pwr_track) {
2938 memcpy(pHalData->rf_tx_pwr_track, pHalData->para_file_buf, rlen);
2939 pHalData->rf_tx_pwr_track_len = rlen;
2941 DBG_871X("%s rf_tx_pwr_track alloc fail !\n", __func__);
2945 if ((pHalData->rf_tx_pwr_track_len != 0) && (pHalData->rf_tx_pwr_track != NULL)) {
2946 memcpy(pHalData->para_file_buf, pHalData->rf_tx_pwr_track, pHalData->rf_tx_pwr_track_len);
2947 rtStatus = _SUCCESS;
2949 DBG_871X("%s(): Critical Error !!!\n", __func__);
2952 if (rtStatus == _SUCCESS) {
2953 /* DBG_871X("%s(): read %s successfully\n", __func__, pFileName); */
2955 ptmp = pHalData->para_file_buf;
2956 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
2957 if (!IsCommentString(szLine)) {
2958 char band[5] = "", path[5] = "", sign[5] = "";
2959 char chnl[5] = "", rate[10] = "";
2960 char data[300] = ""; /* 100 is too small */
2962 if (strlen(szLine) < 10 || szLine[0] != '[')
2965 strncpy(band, szLine+1, 2);
2966 strncpy(path, szLine+5, 1);
2967 strncpy(sign, szLine+8, 1);
2969 i = 10; /* szLine+10 */
2970 if (!ParseQualifiedString(szLine, &i, rate, '[', ']')) {
2971 /* DBG_871X("Fail to parse rate!\n"); */
2973 if (!ParseQualifiedString(szLine, &i, chnl, '[', ']')) {
2974 /* DBG_871X("Fail to parse channel group!\n"); */
2976 while (szLine[i] != '{' && i < strlen(szLine))
2978 if (!ParseQualifiedString(szLine, &i, data, '{', '}')) {
2979 /* DBG_871X("Fail to parse data!\n"); */
2982 initDeltaSwingIndexTables(Adapter, band, path, sign, chnl, rate, data);
2986 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
2991 static int phy_ParsePowerLimitTableFile(struct adapter *Adapter, char *buffer)
2993 u32 i = 0, forCnt = 0;
2994 u8 loadingStage = 0, limitValue = 0, fraction = 0;
2995 char *szLine, *ptmp;
2996 int rtStatus = _SUCCESS;
2997 char band[10], bandwidth[10], rateSection[10],
2998 regulation[TXPWR_LMT_MAX_REGULATION_NUM][10], rfPath[10], colNumBuf[10];
3001 DBG_871X("===>phy_ParsePowerLimitTableFile()\n");
3003 if (Adapter->registrypriv.RegDecryptCustomFile == 1)
3004 phy_DecryptBBPgParaFile(Adapter, buffer);
3007 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
3009 if (IsCommentString(szLine)) {
3013 if (loadingStage == 0) {
3014 for (forCnt = 0; forCnt < TXPWR_LMT_MAX_REGULATION_NUM; ++forCnt)
3015 memset((void *) regulation[forCnt], 0, 10);
3017 memset((void *) band, 0, 10);
3018 memset((void *) bandwidth, 0, 10);
3019 memset((void *) rateSection, 0, 10);
3020 memset((void *) rfPath, 0, 10);
3021 memset((void *) colNumBuf, 0, 10);
3023 if (szLine[0] != '#' || szLine[1] != '#')
3026 /* skip the space */
3028 while (szLine[i] == ' ' || szLine[i] == '\t')
3031 szLine[--i] = ' '; /* return the space in front of the regulation info */
3033 /* Parse the label of the table */
3034 if (!ParseQualifiedString(szLine, &i, band, ' ', ',')) {
3035 DBG_871X("Fail to parse band!\n");
3038 if (!ParseQualifiedString(szLine, &i, bandwidth, ' ', ',')) {
3039 DBG_871X("Fail to parse bandwidth!\n");
3042 if (!ParseQualifiedString(szLine, &i, rfPath, ' ', ',')) {
3043 DBG_871X("Fail to parse rf path!\n");
3046 if (!ParseQualifiedString(szLine, &i, rateSection, ' ', ',')) {
3047 DBG_871X("Fail to parse rate!\n");
3052 } else if (loadingStage == 1) {
3053 if (szLine[0] != '#' || szLine[1] != '#')
3056 /* skip the space */
3058 while (szLine[i] == ' ' || szLine[i] == '\t')
3061 if (!eqNByte((u8 *)(szLine + i), (u8 *)("START"), 5)) {
3062 DBG_871X("Lost \"## START\" label\n");
3067 } else if (loadingStage == 2) {
3068 if (szLine[0] != '#' || szLine[1] != '#')
3071 /* skip the space */
3073 while (szLine[i] == ' ' || szLine[i] == '\t')
3076 if (!ParseQualifiedString(szLine, &i, colNumBuf, '#', '#')) {
3077 DBG_871X("Fail to parse column number!\n");
3081 if (!GetU1ByteIntegerFromStringInDecimal(colNumBuf, &colNum))
3084 if (colNum > TXPWR_LMT_MAX_REGULATION_NUM) {
3086 "unvalid col number %d (greater than max %d)\n",
3087 colNum, TXPWR_LMT_MAX_REGULATION_NUM
3092 for (forCnt = 0; forCnt < colNum; ++forCnt) {
3093 u8 regulation_name_cnt = 0;
3095 /* skip the space */
3096 while (szLine[i] == ' ' || szLine[i] == '\t')
3099 while (szLine[i] != ' ' && szLine[i] != '\t' && szLine[i] != '\0')
3100 regulation[forCnt][regulation_name_cnt++] = szLine[i++];
3101 /* DBG_871X("regulation %s!\n", regulation[forCnt]); */
3103 if (regulation_name_cnt == 0) {
3104 DBG_871X("unvalid number of regulation!\n");
3110 } else if (loadingStage == 3) {
3111 char channel[10] = {0}, powerLimit[10] = {0};
3114 /* the table ends */
3115 if (szLine[0] == '#' && szLine[1] == '#') {
3117 while (szLine[i] == ' ' || szLine[i] == '\t')
3120 if (eqNByte((u8 *)(szLine + i), (u8 *)("END"), 3)) {
3124 DBG_871X("Wrong format\n");
3125 DBG_871X("<===== phy_ParsePowerLimitTableFile()\n");
3130 if ((szLine[0] != 'c' && szLine[0] != 'C') ||
3131 (szLine[1] != 'h' && szLine[1] != 'H')) {
3132 DBG_871X("Meet wrong channel => power limt pair\n");
3135 i = 2;/* move to the location behind 'h' */
3137 /* load the channel number */
3139 while (szLine[i] >= '0' && szLine[i] <= '9') {
3140 channel[cnt] = szLine[i];
3144 /* DBG_871X("chnl %s!\n", channel); */
3146 for (forCnt = 0; forCnt < colNum; ++forCnt) {
3147 /* skip the space between channel number and the power limit value */
3148 while (szLine[i] == ' ' || szLine[i] == '\t')
3151 /* load the power limit value */
3154 memset((void *) powerLimit, 0, 10);
3155 while ((szLine[i] >= '0' && szLine[i] <= '9') || szLine[i] == '.') {
3156 if (szLine[i] == '.') {
3157 if ((szLine[i+1] >= '0' && szLine[i+1] <= '9')) {
3158 fraction = szLine[i+1];
3161 DBG_871X("Wrong fraction in TXPWR_LMT.txt\n");
3168 powerLimit[cnt] = szLine[i];
3173 if (powerLimit[0] == '\0') {
3174 powerLimit[0] = '6';
3175 powerLimit[1] = '3';
3178 if (!GetU1ByteIntegerFromStringInDecimal(powerLimit, &limitValue))
3183 if (fraction == '5')
3186 /* the value is greater or equal to 100 */
3187 if (limitValue >= 100) {
3188 powerLimit[cnt++] = limitValue/100 + '0';
3191 if (limitValue >= 10) {
3192 powerLimit[cnt++] = limitValue/10 + '0';
3195 powerLimit[cnt++] = '0';
3197 powerLimit[cnt++] = limitValue + '0';
3198 } else if (limitValue >= 10) { /* the value is greater or equal to 10 */
3199 powerLimit[cnt++] = limitValue/10 + '0';
3201 powerLimit[cnt++] = limitValue + '0';
3203 /* the value is less than 10 */
3205 powerLimit[cnt++] = limitValue + '0';
3207 powerLimit[cnt] = '\0';
3210 /* DBG_871X("ch%s => %s\n", channel, powerLimit); */
3212 /* store the power limit value */
3213 PHY_SetTxPowerLimit(Adapter, (u8 *)regulation[forCnt], (u8 *)band,
3214 (u8 *)bandwidth, (u8 *)rateSection, (u8 *)rfPath, (u8 *)channel, (u8 *)powerLimit);
3218 DBG_871X("Abnormal loading stage in phy_ParsePowerLimitTableFile()!\n");
3224 DBG_871X("<===phy_ParsePowerLimitTableFile()\n");
3228 int PHY_ConfigRFWithPowerLimitTableParaFile(
3229 struct adapter *Adapter, char *pFileName
3232 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
3233 int rlen = 0, rtStatus = _FAIL;
3235 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_LMT_PARA_FILE))
3238 memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
3240 if ((pHalData->rf_tx_pwr_lmt_len == 0) && (pHalData->rf_tx_pwr_lmt == NULL)) {
3241 rtw_merge_string(file_path_bs, PATH_MAX, rtw_phy_file_path, pFileName);
3243 if (rtw_is_file_readable(file_path_bs) == true) {
3244 rlen = rtw_retrive_from_file(file_path_bs, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
3246 rtStatus = _SUCCESS;
3247 pHalData->rf_tx_pwr_lmt = vzalloc(rlen);
3248 if (pHalData->rf_tx_pwr_lmt) {
3249 memcpy(pHalData->rf_tx_pwr_lmt, pHalData->para_file_buf, rlen);
3250 pHalData->rf_tx_pwr_lmt_len = rlen;
3252 DBG_871X("%s rf_tx_pwr_lmt alloc fail !\n", __func__);
3256 if ((pHalData->rf_tx_pwr_lmt_len != 0) && (pHalData->rf_tx_pwr_lmt != NULL)) {
3257 memcpy(pHalData->para_file_buf, pHalData->rf_tx_pwr_lmt, pHalData->rf_tx_pwr_lmt_len);
3258 rtStatus = _SUCCESS;
3260 DBG_871X("%s(): Critical Error !!!\n", __func__);
3263 if (rtStatus == _SUCCESS) {
3264 /* DBG_871X("%s(): read %s ok\n", __func__, pFileName); */
3265 rtStatus = phy_ParsePowerLimitTableFile(Adapter, pHalData->para_file_buf);
3267 DBG_871X("%s(): No File %s, Load from HWImg Array!\n", __func__, pFileName);
3272 void phy_free_filebuf(struct adapter *padapter)
3274 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
3276 if (pHalData->mac_reg)
3277 vfree(pHalData->mac_reg);
3278 if (pHalData->bb_phy_reg)
3279 vfree(pHalData->bb_phy_reg);
3280 if (pHalData->bb_agc_tab)
3281 vfree(pHalData->bb_agc_tab);
3282 if (pHalData->bb_phy_reg_pg)
3283 vfree(pHalData->bb_phy_reg_pg);
3284 if (pHalData->bb_phy_reg_mp)
3285 vfree(pHalData->bb_phy_reg_mp);
3286 if (pHalData->rf_radio_a)
3287 vfree(pHalData->rf_radio_a);
3288 if (pHalData->rf_radio_b)
3289 vfree(pHalData->rf_radio_b);
3290 if (pHalData->rf_tx_pwr_track)
3291 vfree(pHalData->rf_tx_pwr_track);
3292 if (pHalData->rf_tx_pwr_lmt)
3293 vfree(pHalData->rf_tx_pwr_lmt);