rtw_mp.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_MP_C_
  21. #include <drv_types.h>
  22. #ifdef PLATFORM_FREEBSD
  23. #include <sys/unistd.h> /* for RFHIGHPID */
  24. #endif
  25. #include "../hal/OUTSRC/odm_precomp.h"
  26. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  27. #include <rtw_bt_mp.h>
  28. #endif
  29. #ifdef CONFIG_MP_INCLUDED
  30. u32 read_macreg(_adapter *padapter, u32 addr, u32 sz)
  31. {
  32. u32 val = 0;
  33. switch(sz)
  34. {
  35. case 1:
  36. val = rtw_read8(padapter, addr);
  37. break;
  38. case 2:
  39. val = rtw_read16(padapter, addr);
  40. break;
  41. case 4:
  42. val = rtw_read32(padapter, addr);
  43. break;
  44. default:
  45. val = 0xffffffff;
  46. break;
  47. }
  48. return val;
  49. }
  50. void write_macreg(_adapter *padapter, u32 addr, u32 val, u32 sz)
  51. {
  52. switch(sz)
  53. {
  54. case 1:
  55. rtw_write8(padapter, addr, (u8)val);
  56. break;
  57. case 2:
  58. rtw_write16(padapter, addr, (u16)val);
  59. break;
  60. case 4:
  61. rtw_write32(padapter, addr, val);
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. u32 read_bbreg(_adapter *padapter, u32 addr, u32 bitmask)
  68. {
  69. return rtw_hal_read_bbreg(padapter, addr, bitmask);
  70. }
  71. void write_bbreg(_adapter *padapter, u32 addr, u32 bitmask, u32 val)
  72. {
  73. rtw_hal_write_bbreg(padapter, addr, bitmask, val);
  74. }
  75. u32 _read_rfreg(PADAPTER padapter, u8 rfpath, u32 addr, u32 bitmask)
  76. {
  77. return rtw_hal_read_rfreg(padapter, rfpath, addr, bitmask);
  78. }
  79. void _write_rfreg(PADAPTER padapter, u8 rfpath, u32 addr, u32 bitmask, u32 val)
  80. {
  81. rtw_hal_write_rfreg(padapter, rfpath, addr, bitmask, val);
  82. }
  83. u32 read_rfreg(PADAPTER padapter, u8 rfpath, u32 addr)
  84. {
  85. return _read_rfreg(padapter, rfpath, addr, bRFRegOffsetMask);
  86. }
  87. void write_rfreg(PADAPTER padapter, u8 rfpath, u32 addr, u32 val)
  88. {
  89. _write_rfreg(padapter, rfpath, addr, bRFRegOffsetMask, val);
  90. }
  91. static void _init_mp_priv_(struct mp_priv *pmp_priv)
  92. {
  93. WLAN_BSSID_EX *pnetwork;
  94. _rtw_memset(pmp_priv, 0, sizeof(struct mp_priv));
  95. pmp_priv->mode = MP_OFF;
  96. pmp_priv->channel = 1;
  97. pmp_priv->bandwidth = CHANNEL_WIDTH_20;
  98. pmp_priv->prime_channel_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  99. pmp_priv->rateidx = MPT_RATE_1M;
  100. pmp_priv->txpoweridx = 0x2A;
  101. pmp_priv->antenna_tx = ANTENNA_A;
  102. pmp_priv->antenna_rx = ANTENNA_AB;
  103. pmp_priv->check_mp_pkt = 0;
  104. pmp_priv->tx_pktcount = 0;
  105. pmp_priv->rx_pktcount = 0;
  106. pmp_priv->rx_crcerrpktcount = 0;
  107. pmp_priv->network_macaddr[0] = 0x00;
  108. pmp_priv->network_macaddr[1] = 0xE0;
  109. pmp_priv->network_macaddr[2] = 0x4C;
  110. pmp_priv->network_macaddr[3] = 0x87;
  111. pmp_priv->network_macaddr[4] = 0x66;
  112. pmp_priv->network_macaddr[5] = 0x55;
  113. pnetwork = &pmp_priv->mp_network.network;
  114. _rtw_memcpy(pnetwork->MacAddress, pmp_priv->network_macaddr, ETH_ALEN);
  115. pnetwork->Ssid.SsidLength = 8;
  116. _rtw_memcpy(pnetwork->Ssid.Ssid, "mp_871x", pnetwork->Ssid.SsidLength);
  117. }
  118. #ifdef PLATFORM_WINDOWS
  119. /*
  120. void mp_wi_callback(
  121. IN NDIS_WORK_ITEM* pwk_item,
  122. IN PVOID cntx
  123. )
  124. {
  125. _adapter* padapter =(_adapter *)cntx;
  126. struct mp_priv *pmppriv=&padapter->mppriv;
  127. struct mp_wi_cntx *pmp_wi_cntx=&pmppriv->wi_cntx;
  128. // Execute specified action.
  129. if(pmp_wi_cntx->curractfunc != NULL)
  130. {
  131. LARGE_INTEGER cur_time;
  132. ULONGLONG start_time, end_time;
  133. NdisGetCurrentSystemTime(&cur_time); // driver version
  134. start_time = cur_time.QuadPart/10; // The return value is in microsecond
  135. pmp_wi_cntx->curractfunc(padapter);
  136. NdisGetCurrentSystemTime(&cur_time); // driver version
  137. end_time = cur_time.QuadPart/10; // The return value is in microsecond
  138. RT_TRACE(_module_mp_, _drv_info_,
  139. ("WorkItemActType: %d, time spent: %I64d us\n",
  140. pmp_wi_cntx->param.act_type, (end_time-start_time)));
  141. }
  142. NdisAcquireSpinLock(&(pmp_wi_cntx->mp_wi_lock));
  143. pmp_wi_cntx->bmp_wi_progress= _FALSE;
  144. NdisReleaseSpinLock(&(pmp_wi_cntx->mp_wi_lock));
  145. if (pmp_wi_cntx->bmpdrv_unload)
  146. {
  147. NdisSetEvent(&(pmp_wi_cntx->mp_wi_evt));
  148. }
  149. }
  150. */
  151. static int init_mp_priv_by_os(struct mp_priv *pmp_priv)
  152. {
  153. struct mp_wi_cntx *pmp_wi_cntx;
  154. if (pmp_priv == NULL) return _FAIL;
  155. pmp_priv->rx_testcnt = 0;
  156. pmp_priv->rx_testcnt1 = 0;
  157. pmp_priv->rx_testcnt2 = 0;
  158. pmp_priv->tx_testcnt = 0;
  159. pmp_priv->tx_testcnt1 = 0;
  160. pmp_wi_cntx = &pmp_priv->wi_cntx
  161. pmp_wi_cntx->bmpdrv_unload = _FALSE;
  162. pmp_wi_cntx->bmp_wi_progress = _FALSE;
  163. pmp_wi_cntx->curractfunc = NULL;
  164. return _SUCCESS;
  165. }
  166. #endif
  167. #ifdef PLATFORM_LINUX
  168. static int init_mp_priv_by_os(struct mp_priv *pmp_priv)
  169. {
  170. int i, res;
  171. struct mp_xmit_frame *pmp_xmitframe;
  172. if (pmp_priv == NULL) return _FAIL;
  173. _rtw_init_queue(&pmp_priv->free_mp_xmitqueue);
  174. pmp_priv->pallocated_mp_xmitframe_buf = NULL;
  175. pmp_priv->pallocated_mp_xmitframe_buf = rtw_zmalloc(NR_MP_XMITFRAME * sizeof(struct mp_xmit_frame) + 4);
  176. if (pmp_priv->pallocated_mp_xmitframe_buf == NULL) {
  177. res = _FAIL;
  178. goto _exit_init_mp_priv;
  179. }
  180. pmp_priv->pmp_xmtframe_buf = pmp_priv->pallocated_mp_xmitframe_buf + 4 - ((SIZE_PTR) (pmp_priv->pallocated_mp_xmitframe_buf) & 3);
  181. pmp_xmitframe = (struct mp_xmit_frame*)pmp_priv->pmp_xmtframe_buf;
  182. for (i = 0; i < NR_MP_XMITFRAME; i++)
  183. {
  184. _rtw_init_listhead(&pmp_xmitframe->list);
  185. rtw_list_insert_tail(&pmp_xmitframe->list, &pmp_priv->free_mp_xmitqueue.queue);
  186. pmp_xmitframe->pkt = NULL;
  187. pmp_xmitframe->frame_tag = MP_FRAMETAG;
  188. pmp_xmitframe->padapter = pmp_priv->papdater;
  189. pmp_xmitframe++;
  190. }
  191. pmp_priv->free_mp_xmitframe_cnt = NR_MP_XMITFRAME;
  192. res = _SUCCESS;
  193. _exit_init_mp_priv:
  194. return res;
  195. }
  196. #endif
  197. static void mp_init_xmit_attrib(struct mp_tx *pmptx, PADAPTER padapter)
  198. {
  199. struct pkt_attrib *pattrib;
  200. struct tx_desc *desc;
  201. // init xmitframe attribute
  202. pattrib = &pmptx->attrib;
  203. _rtw_memset(pattrib, 0, sizeof(struct pkt_attrib));
  204. desc = &pmptx->desc;
  205. _rtw_memset(desc, 0, TXDESC_SIZE);
  206. pattrib->ether_type = 0x8712;
  207. //_rtw_memcpy(pattrib->src, padapter->eeprompriv.mac_addr, ETH_ALEN);
  208. // _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  209. _rtw_memset(pattrib->dst, 0xFF, ETH_ALEN);
  210. // pattrib->dhcp_pkt = 0;
  211. // pattrib->pktlen = 0;
  212. pattrib->ack_policy = 0;
  213. // pattrib->pkt_hdrlen = ETH_HLEN;
  214. pattrib->hdrlen = WLAN_HDR_A3_LEN;
  215. pattrib->subtype = WIFI_DATA;
  216. pattrib->priority = 0;
  217. pattrib->qsel = pattrib->priority;
  218. // do_queue_select(padapter, pattrib);
  219. pattrib->nr_frags = 1;
  220. pattrib->encrypt = 0;
  221. pattrib->bswenc = _FALSE;
  222. pattrib->qos_en = _FALSE;
  223. }
  224. s32 init_mp_priv(PADAPTER padapter)
  225. {
  226. struct mp_priv *pmppriv = &padapter->mppriv;
  227. _init_mp_priv_(pmppriv);
  228. pmppriv->papdater = padapter;
  229. pmppriv->tx.stop = 1;
  230. mp_init_xmit_attrib(&pmppriv->tx, padapter);
  231. switch (padapter->registrypriv.rf_config) {
  232. case RF_1T1R:
  233. pmppriv->antenna_tx = ANTENNA_A;
  234. pmppriv->antenna_rx = ANTENNA_A;
  235. break;
  236. case RF_1T2R:
  237. default:
  238. pmppriv->antenna_tx = ANTENNA_A;
  239. pmppriv->antenna_rx = ANTENNA_AB;
  240. break;
  241. case RF_2T2R:
  242. case RF_2T2R_GREEN:
  243. pmppriv->antenna_tx = ANTENNA_AB;
  244. pmppriv->antenna_rx = ANTENNA_AB;
  245. break;
  246. case RF_2T4R:
  247. pmppriv->antenna_tx = ANTENNA_AB;
  248. pmppriv->antenna_rx = ANTENNA_ABCD;
  249. break;
  250. }
  251. return _SUCCESS;
  252. }
  253. void free_mp_priv(struct mp_priv *pmp_priv)
  254. {
  255. if (pmp_priv->pallocated_mp_xmitframe_buf) {
  256. rtw_mfree(pmp_priv->pallocated_mp_xmitframe_buf, 0);
  257. pmp_priv->pallocated_mp_xmitframe_buf = NULL;
  258. }
  259. pmp_priv->pmp_xmtframe_buf = NULL;
  260. }
  261. static VOID PHY_IQCalibrate_default(
  262. IN PADAPTER pAdapter,
  263. IN BOOLEAN bReCovery
  264. )
  265. {
  266. DBG_871X("%s\n", __func__);
  267. }
  268. static VOID PHY_LCCalibrate_default(
  269. IN PADAPTER pAdapter
  270. )
  271. {
  272. DBG_871X("%s\n", __func__);
  273. }
  274. static VOID PHY_SetRFPathSwitch_default(
  275. IN PADAPTER pAdapter,
  276. IN BOOLEAN bMain
  277. )
  278. {
  279. DBG_871X("%s\n", __func__);
  280. }
  281. #if defined (CONFIG_RTL8192C) || defined (CONFIG_RTL8723A)
  282. #define PHY_IQCalibrate(a,b) rtl8192c_PHY_IQCalibrate(a,b)
  283. #define PHY_LCCalibrate(a) rtl8192c_PHY_LCCalibrate(a)
  284. //#define dm_CheckTXPowerTracking(a) rtl8192c_odm_CheckTXPowerTracking(a)
  285. #define PHY_SetRFPathSwitch(a,b) rtl8192c_PHY_SetRFPathSwitch(a,b)
  286. #endif
  287. #ifdef CONFIG_RTL8192D
  288. #define PHY_IQCalibrate(a,b) rtl8192d_PHY_IQCalibrate(a)
  289. #define PHY_LCCalibrate(a) rtl8192d_PHY_LCCalibrate(a)
  290. //#define dm_CheckTXPowerTracking(a) rtl8192d_odm_CheckTXPowerTracking(a)
  291. #define PHY_SetRFPathSwitch(a,b) rtl8192d_PHY_SetRFPathSwitch(a,b)
  292. #endif
  293. #ifdef CONFIG_RTL8188E
  294. #define PHY_IQCalibrate(a,b) PHY_IQCalibrate_8188E(a,b)
  295. #define PHY_LCCalibrate(a) PHY_LCCalibrate_8188E(&(GET_HAL_DATA(a)->odmpriv))
  296. #define PHY_SetRFPathSwitch(a,b) PHY_SetRFPathSwitch_8188E(a,b)
  297. #endif
  298. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  299. /*
  300. #define PHY_IQCalibrate(a,b) PHY_IQCalibrate_8812A(a,b)
  301. #define PHY_LCCalibrate(a) PHY_LCCalibrate_8812A(&(GET_HAL_DATA(a)->odmpriv))
  302. #define PHY_SetRFPathSwitch(a,b) PHY_SetRFPathSwitch_8812A(a,b)
  303. */
  304. #ifndef CONFIG_RTL8812A
  305. #define PHY_IQCalibrate_8812A
  306. #define PHY_LCCalibrate_8812A
  307. #define PHY_SetRFPathSwitch_8812A
  308. #endif
  309. #ifndef CONFIG_RTL8821A
  310. #define PHY_IQCalibrate_8821A
  311. #define PHY_LCCalibrate_8821A
  312. #define PHY_SetRFPathSwitch_8812A
  313. #endif
  314. #define PHY_IQCalibrate(_Adapter, b) \
  315. IS_HARDWARE_TYPE_8812(_Adapter) ? PHY_IQCalibrate_8812A(_Adapter, b) : \
  316. IS_HARDWARE_TYPE_8821(_Adapter) ? PHY_IQCalibrate_8821A(_Adapter, b) : \
  317. PHY_IQCalibrate_default(_Adapter, b)
  318. #define PHY_LCCalibrate(_Adapter) \
  319. IS_HARDWARE_TYPE_8812(_Adapter) ? PHY_LCCalibrate_8812A(&(GET_HAL_DATA(_Adapter)->odmpriv)) : \
  320. IS_HARDWARE_TYPE_8821(_Adapter) ? PHY_LCCalibrate_8821A(&(GET_HAL_DATA(_Adapter)->odmpriv)) : \
  321. PHY_LCCalibrate_default(_Adapter)
  322. #define PHY_SetRFPathSwitch(_Adapter, b) \
  323. (IS_HARDWARE_TYPE_JAGUAR(_Adapter)) ? PHY_SetRFPathSwitch_8812A(_Adapter, b) : \
  324. PHY_SetRFPathSwitch_default(_Adapter, b)
  325. #endif //#if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  326. #ifdef CONFIG_RTL8192E
  327. #define PHY_IQCalibrate(a,b) PHY_IQCalibrate_8192E(a,b)
  328. #define PHY_LCCalibrate(a) PHY_LCCalibrate_8192E(&(GET_HAL_DATA(a)->odmpriv))
  329. #define PHY_SetRFPathSwitch(a,b) PHY_SetRFPathSwitch_8192E(a,b)
  330. #endif //CONFIG_RTL8812A_8821A
  331. #ifdef CONFIG_RTL8723B
  332. #define PHY_IQCalibrate(a,b) PHY_IQCalibrate_8723B(a,b)
  333. #define PHY_LCCalibrate(a) PHY_LCCalibrate_8723B(a)
  334. #define PHY_SetRFPathSwitch(a,b) PHY_SetRFPathSwitch_8723B(a,b)
  335. #endif
  336. s32
  337. MPT_InitializeAdapter(
  338. IN PADAPTER pAdapter,
  339. IN u8 Channel
  340. )
  341. {
  342. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  343. s32 rtStatus = _SUCCESS;
  344. PMPT_CONTEXT pMptCtx = &pAdapter->mppriv.MptCtx;
  345. u32 ledsetting;
  346. struct mlme_priv *pmlmepriv = &pAdapter->mlmepriv;
  347. //-------------------------------------------------------------------------
  348. // HW Initialization for 8190 MPT.
  349. //-------------------------------------------------------------------------
  350. //-------------------------------------------------------------------------
  351. // SW Initialization for 8190 MP.
  352. //-------------------------------------------------------------------------
  353. pMptCtx->bMptDrvUnload = _FALSE;
  354. pMptCtx->bMassProdTest = _FALSE;
  355. pMptCtx->bMptIndexEven = _TRUE; //default gain index is -6.0db
  356. pMptCtx->h2cReqNum = 0x0;
  357. /* Init mpt event. */
  358. #if 0 // for Windows
  359. NdisInitializeEvent( &(pMptCtx->MptWorkItemEvent) );
  360. NdisAllocateSpinLock( &(pMptCtx->MptWorkItemSpinLock) );
  361. PlatformInitializeWorkItem(
  362. Adapter,
  363. &(pMptCtx->MptWorkItem),
  364. (RT_WORKITEM_CALL_BACK)MPT_WorkItemCallback,
  365. (PVOID)Adapter,
  366. "MptWorkItem");
  367. #endif
  368. //init for BT MP
  369. #if defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)
  370. pMptCtx->bMPh2c_timeout = _FALSE;
  371. pMptCtx->MptH2cRspEvent = _FALSE;
  372. pMptCtx->MptBtC2hEvent = _FALSE;
  373. _rtw_init_sema(&pMptCtx->MPh2c_Sema, 0);
  374. _init_timer( &pMptCtx->MPh2c_timeout_timer, pAdapter->pnetdev, MPh2c_timeout_handle, pAdapter );
  375. #endif
  376. pMptCtx->bMptWorkItemInProgress = _FALSE;
  377. pMptCtx->CurrMptAct = NULL;
  378. //-------------------------------------------------------------------------
  379. #if 1
  380. // Don't accept any packets
  381. rtw_write32(pAdapter, REG_RCR, 0);
  382. #else
  383. // Accept CRC error and destination address
  384. //pHalData->ReceiveConfig |= (RCR_ACRC32|RCR_AAP);
  385. //rtw_write32(pAdapter, REG_RCR, pHalData->ReceiveConfig);
  386. rtw_write32(pAdapter, REG_RCR, 0x70000101);
  387. #endif
  388. #if 0
  389. // If EEPROM or EFUSE is empty,we assign as RF 2T2R for MP.
  390. if (pHalData->AutoloadFailFlag == TRUE)
  391. {
  392. pHalData->RF_Type = RF_2T2R;
  393. }
  394. #endif
  395. //ledsetting = rtw_read32(pAdapter, REG_LEDCFG0);
  396. //rtw_write32(pAdapter, REG_LEDCFG0, ledsetting & ~LED0DIS);
  397. if(IS_HARDWARE_TYPE_8192DU(pAdapter))
  398. {
  399. rtw_write32(pAdapter, REG_LEDCFG0, 0x8888);
  400. }
  401. else
  402. {
  403. //rtw_write32(pAdapter, REG_LEDCFG0, 0x08080);
  404. ledsetting = rtw_read32(pAdapter, REG_LEDCFG0);
  405. #if defined (CONFIG_RTL8192C) || defined( CONFIG_RTL8192D )
  406. rtw_write32(pAdapter, REG_LEDCFG0, ledsetting & ~BIT(7));
  407. #endif
  408. }
  409. PHY_IQCalibrate(pAdapter, _FALSE);
  410. dm_CheckTXPowerTracking(&pHalData->odmpriv); //trigger thermal meter
  411. PHY_LCCalibrate(pAdapter);
  412. #ifdef CONFIG_PCI_HCI
  413. PHY_SetRFPathSwitch(pAdapter, 1/*pHalData->bDefaultAntenna*/); //Wifi default use Main
  414. #else
  415. #ifdef CONFIG_RTL8192C
  416. if (pHalData->BoardType == BOARD_MINICARD)
  417. PHY_SetRFPathSwitch(pAdapter, 1/*pHalData->bDefaultAntenna*/); //default use Main
  418. #endif
  419. #endif
  420. pMptCtx->backup0xc50 = (u1Byte)PHY_QueryBBReg(pAdapter, rOFDM0_XAAGCCore1, bMaskByte0);
  421. pMptCtx->backup0xc58 = (u1Byte)PHY_QueryBBReg(pAdapter, rOFDM0_XBAGCCore1, bMaskByte0);
  422. pMptCtx->backup0xc30 = (u1Byte)PHY_QueryBBReg(pAdapter, rOFDM0_RxDetector1, bMaskByte0);
  423. #ifdef CONFIG_RTL8188E
  424. pMptCtx->backup0x52_RF_A = (u1Byte)PHY_QueryRFReg(pAdapter, RF_PATH_A, RF_0x52, 0x000F0);
  425. pMptCtx->backup0x52_RF_B = (u1Byte)PHY_QueryRFReg(pAdapter, RF_PATH_A, RF_0x52, 0x000F0);
  426. #endif
  427. #ifdef CONFIG_RTL8723A
  428. rtl8723a_InitAntenna_Selection(pAdapter);
  429. #endif //CONFIG_RTL8723A
  430. #ifdef CONFIG_RTL8723B
  431. rtl8723b_InitAntenna_Selection(pAdapter);
  432. #endif //CONFIG_RTL8723B
  433. //set ant to wifi side in mp mode
  434. rtw_write16(pAdapter, 0x870, 0x300);
  435. rtw_write16(pAdapter, 0x860, 0x110);
  436. if (pAdapter->registrypriv.mp_mode == 1)
  437. pmlmepriv->fw_state = WIFI_MP_STATE;
  438. return rtStatus;
  439. }
  440. /*-----------------------------------------------------------------------------
  441. * Function: MPT_DeInitAdapter()
  442. *
  443. * Overview: Extra DeInitialization for Mass Production Test.
  444. *
  445. * Input: PADAPTER pAdapter
  446. *
  447. * Output: NONE
  448. *
  449. * Return: NONE
  450. *
  451. * Revised History:
  452. * When Who Remark
  453. * 05/08/2007 MHC Create Version 0.
  454. * 05/18/2007 MHC Add normal driver MPHalt code.
  455. *
  456. *---------------------------------------------------------------------------*/
  457. VOID
  458. MPT_DeInitAdapter(
  459. IN PADAPTER pAdapter
  460. )
  461. {
  462. PMPT_CONTEXT pMptCtx = &pAdapter->mppriv.MptCtx;
  463. pMptCtx->bMptDrvUnload = _TRUE;
  464. #if defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)
  465. _rtw_free_sema(&(pMptCtx->MPh2c_Sema));
  466. _cancel_timer_ex( &pMptCtx->MPh2c_timeout_timer);
  467. #endif
  468. #if 0 // for Windows
  469. PlatformFreeWorkItem( &(pMptCtx->MptWorkItem) );
  470. while(pMptCtx->bMptWorkItemInProgress)
  471. {
  472. if(NdisWaitEvent(&(pMptCtx->MptWorkItemEvent), 50))
  473. {
  474. break;
  475. }
  476. }
  477. NdisFreeSpinLock( &(pMptCtx->MptWorkItemSpinLock) );
  478. #endif
  479. }
  480. static u8 mpt_ProStartTest(PADAPTER padapter)
  481. {
  482. PMPT_CONTEXT pMptCtx = &padapter->mppriv.MptCtx;
  483. pMptCtx->bMassProdTest = _TRUE;
  484. pMptCtx->bStartContTx = _FALSE;
  485. pMptCtx->bCckContTx = _FALSE;
  486. pMptCtx->bOfdmContTx = _FALSE;
  487. pMptCtx->bSingleCarrier = _FALSE;
  488. pMptCtx->bCarrierSuppression = _FALSE;
  489. pMptCtx->bSingleTone = _FALSE;
  490. return _SUCCESS;
  491. }
  492. /*
  493. * General use
  494. */
  495. s32 SetPowerTracking(PADAPTER padapter, u8 enable)
  496. {
  497. Hal_SetPowerTracking( padapter, enable );
  498. return 0;
  499. }
  500. void GetPowerTracking(PADAPTER padapter, u8 *enable)
  501. {
  502. Hal_GetPowerTracking( padapter, enable );
  503. }
  504. static void disable_dm(PADAPTER padapter)
  505. {
  506. #ifndef CONFIG_RTL8723A
  507. u8 v8;
  508. #endif
  509. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  510. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  511. //3 1. disable firmware dynamic mechanism
  512. // disable Power Training, Rate Adaptive
  513. #ifdef CONFIG_RTL8723A
  514. SetBcnCtrlReg(padapter, 0, EN_BCN_FUNCTION);
  515. #else
  516. v8 = rtw_read8(padapter, REG_BCN_CTRL);
  517. v8 &= ~EN_BCN_FUNCTION;
  518. rtw_write8(padapter, REG_BCN_CTRL, v8);
  519. #endif
  520. //3 2. disable driver dynamic mechanism
  521. // disable Dynamic Initial Gain
  522. // disable High Power
  523. // disable Power Tracking
  524. Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, _FALSE);
  525. // enable APK, LCK and IQK but disable power tracking
  526. #if !(defined(CONFIG_RTL8188E) || defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)|| defined(CONFIG_RTL8192E))
  527. pdmpriv->TxPowerTrackControl = _FALSE;
  528. #endif
  529. Switch_DM_Func(padapter, DYNAMIC_RF_CALIBRATION, _TRUE);
  530. }
  531. //This function initializes the DUT to the MP test mode
  532. s32 mp_start_test(PADAPTER padapter)
  533. {
  534. WLAN_BSSID_EX bssid;
  535. struct sta_info *psta;
  536. u32 length;
  537. u8 val8;
  538. _irqL irqL;
  539. s32 res = _SUCCESS;
  540. struct mp_priv *pmppriv = &padapter->mppriv;
  541. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  542. struct wlan_network *tgt_network = &pmlmepriv->cur_network;
  543. padapter->registrypriv.mp_mode = 1;
  544. pmppriv->bSetTxPower=0; //for manually set tx power
  545. //3 disable dynamic mechanism
  546. disable_dm(padapter);
  547. #ifdef CONFIG_RTL8812A
  548. rtl8812_InitHalDm(padapter);
  549. #endif
  550. //3 0. update mp_priv
  551. if (padapter->registrypriv.rf_config == RF_MAX_TYPE) {
  552. // switch (phal->rf_type) {
  553. switch (GET_RF_TYPE(padapter)) {
  554. case RF_1T1R:
  555. pmppriv->antenna_tx = ANTENNA_A;
  556. pmppriv->antenna_rx = ANTENNA_A;
  557. break;
  558. case RF_1T2R:
  559. default:
  560. pmppriv->antenna_tx = ANTENNA_A;
  561. pmppriv->antenna_rx = ANTENNA_AB;
  562. break;
  563. case RF_2T2R:
  564. case RF_2T2R_GREEN:
  565. pmppriv->antenna_tx = ANTENNA_AB;
  566. pmppriv->antenna_rx = ANTENNA_AB;
  567. break;
  568. case RF_2T4R:
  569. pmppriv->antenna_tx = ANTENNA_AB;
  570. pmppriv->antenna_rx = ANTENNA_ABCD;
  571. break;
  572. }
  573. }
  574. mpt_ProStartTest(padapter);
  575. //3 1. initialize a new WLAN_BSSID_EX
  576. // _rtw_memset(&bssid, 0, sizeof(WLAN_BSSID_EX));
  577. _rtw_memcpy(bssid.MacAddress, pmppriv->network_macaddr, ETH_ALEN);
  578. bssid.Ssid.SsidLength = strlen("mp_pseudo_adhoc");
  579. _rtw_memcpy(bssid.Ssid.Ssid, (u8*)"mp_pseudo_adhoc", bssid.Ssid.SsidLength);
  580. bssid.InfrastructureMode = Ndis802_11IBSS;
  581. bssid.NetworkTypeInUse = Ndis802_11DS;
  582. bssid.IELength = 0;
  583. length = get_WLAN_BSSID_EX_sz(&bssid);
  584. if (length % 4)
  585. bssid.Length = ((length >> 2) + 1) << 2; //round up to multiple of 4 bytes.
  586. else
  587. bssid.Length = length;
  588. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  589. if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  590. goto end_of_mp_start_test;
  591. //init mp_start_test status
  592. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  593. rtw_disassoc_cmd(padapter, 500, _TRUE);
  594. rtw_indicate_disconnect(padapter);
  595. rtw_free_assoc_resources(padapter, 1);
  596. }
  597. pmppriv->prev_fw_state = get_fwstate(pmlmepriv);
  598. if (padapter->registrypriv.mp_mode == 1)
  599. pmlmepriv->fw_state = WIFI_MP_STATE;
  600. #if 0
  601. if (pmppriv->mode == _LOOPBOOK_MODE_) {
  602. set_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE); //append txdesc
  603. RT_TRACE(_module_mp_, _drv_notice_, ("+start mp in Lookback mode\n"));
  604. } else {
  605. RT_TRACE(_module_mp_, _drv_notice_, ("+start mp in normal mode\n"));
  606. }
  607. #endif
  608. set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
  609. //3 2. create a new psta for mp driver
  610. //clear psta in the cur_network, if any
  611. psta = rtw_get_stainfo(&padapter->stapriv, tgt_network->network.MacAddress);
  612. if (psta) rtw_free_stainfo(padapter, psta);
  613. psta = rtw_alloc_stainfo(&padapter->stapriv, bssid.MacAddress);
  614. if (psta == NULL) {
  615. RT_TRACE(_module_mp_, _drv_err_, ("mp_start_test: Can't alloc sta_info!\n"));
  616. pmlmepriv->fw_state = pmppriv->prev_fw_state;
  617. res = _FAIL;
  618. goto end_of_mp_start_test;
  619. }
  620. //3 3. join psudo AdHoc
  621. tgt_network->join_res = 1;
  622. tgt_network->aid = psta->aid = 1;
  623. _rtw_memcpy(&tgt_network->network, &bssid, length);
  624. rtw_indicate_connect(padapter);
  625. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  626. end_of_mp_start_test:
  627. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  628. if (res == _SUCCESS)
  629. {
  630. // set MSR to WIFI_FW_ADHOC_STATE
  631. #if !defined (CONFIG_RTL8712)
  632. val8 = rtw_read8(padapter, MSR) & 0xFC; // 0x0102
  633. val8 |= WIFI_FW_ADHOC_STATE;
  634. rtw_write8(padapter, MSR, val8); // Link in ad hoc network
  635. #endif
  636. #if defined (CONFIG_RTL8712)
  637. rtw_write8(padapter, MSR, 1); // Link in ad hoc network
  638. rtw_write8(padapter, RCR, 0); // RCR : disable all pkt, 0x10250048
  639. rtw_write8(padapter, RCR+2, 0x57); // RCR disable Check BSSID, 0x1025004a
  640. // disable RX filter map , mgt frames will put in RX FIFO 0
  641. rtw_write16(padapter, RXFLTMAP0, 0x0); // 0x10250116
  642. val8 = rtw_read8(padapter, EE_9346CR); // 0x1025000A
  643. if (!(val8 & _9356SEL))//boot from EFUSE
  644. efuse_change_max_size(padapter);
  645. #endif
  646. }
  647. return res;
  648. }
  649. //------------------------------------------------------------------------------
  650. //This function change the DUT from the MP test mode into normal mode
  651. void mp_stop_test(PADAPTER padapter)
  652. {
  653. struct mp_priv *pmppriv = &padapter->mppriv;
  654. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  655. struct wlan_network *tgt_network = &pmlmepriv->cur_network;
  656. struct sta_info *psta;
  657. _irqL irqL;
  658. if(pmppriv->mode==MP_ON)
  659. {
  660. pmppriv->bSetTxPower=0;
  661. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  662. if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _FALSE)
  663. goto end_of_mp_stop_test;
  664. //3 1. disconnect psudo AdHoc
  665. rtw_indicate_disconnect(padapter);
  666. //3 2. clear psta used in mp test mode.
  667. // rtw_free_assoc_resources(padapter, 1);
  668. psta = rtw_get_stainfo(&padapter->stapriv, tgt_network->network.MacAddress);
  669. if (psta) rtw_free_stainfo(padapter, psta);
  670. //3 3. return to normal state (default:station mode)
  671. pmlmepriv->fw_state = pmppriv->prev_fw_state; // WIFI_STATION_STATE;
  672. //flush the cur_network
  673. _rtw_memset(tgt_network, 0, sizeof(struct wlan_network));
  674. _clr_fwstate_(pmlmepriv, WIFI_MP_STATE);
  675. end_of_mp_stop_test:
  676. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  677. }
  678. }
  679. /*---------------------------hal\rtl8192c\MPT_Phy.c---------------------------*/
  680. #if 0
  681. //#ifdef CONFIG_USB_HCI
  682. static VOID mpt_AdjustRFRegByRateByChan92CU(PADAPTER pAdapter, u8 RateIdx, u8 Channel, u8 BandWidthID)
  683. {
  684. u8 eRFPath;
  685. u32 rfReg0x26;
  686. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  687. if (RateIdx < MPT_RATE_6M) { // CCK rate,for 88cu
  688. rfReg0x26 = 0xf400;
  689. }
  690. else if ((RateIdx >= MPT_RATE_6M) && (RateIdx <= MPT_RATE_54M)) {// OFDM rate,for 88cu
  691. if ((4 == Channel) || (8 == Channel) || (12 == Channel))
  692. rfReg0x26 = 0xf000;
  693. else if ((5 == Channel) || (7 == Channel) || (13 == Channel) || (14 == Channel))
  694. rfReg0x26 = 0xf400;
  695. else
  696. rfReg0x26 = 0x4f200;
  697. }
  698. else if ((RateIdx >= MPT_RATE_MCS0) && (RateIdx <= MPT_RATE_MCS15)) {// MCS 20M ,for 88cu // MCS40M rate,for 88cu
  699. if (CHANNEL_WIDTH_20 == BandWidthID) {
  700. if ((4 == Channel) || (8 == Channel))
  701. rfReg0x26 = 0xf000;
  702. else if ((5 == Channel) || (7 == Channel) || (13 == Channel) || (14 == Channel))
  703. rfReg0x26 = 0xf400;
  704. else
  705. rfReg0x26 = 0x4f200;
  706. }
  707. else{
  708. if ((4 == Channel) || (8 == Channel))
  709. rfReg0x26 = 0xf000;
  710. else if ((5 == Channel) || (7 == Channel))
  711. rfReg0x26 = 0xf400;
  712. else
  713. rfReg0x26 = 0x4f200;
  714. }
  715. }
  716. // RT_TRACE(COMP_CMD, DBG_LOUD, ("\n mpt_AdjustRFRegByRateByChan92CU():Chan:%d Rate=%d rfReg0x26:0x%08x\n",Channel, RateIdx,rfReg0x26));
  717. for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++) {
  718. write_rfreg(pAdapter, eRFPath, RF_SYN_G2, rfReg0x26);
  719. }
  720. }
  721. #endif
  722. /*-----------------------------------------------------------------------------
  723. * Function: mpt_SwitchRfSetting
  724. *
  725. * Overview: Change RF Setting when we siwthc channel/rate/BW for MP.
  726. *
  727. * Input: IN PADAPTER pAdapter
  728. *
  729. * Output: NONE
  730. *
  731. * Return: NONE
  732. *
  733. * Revised History:
  734. * When Who Remark
  735. * 01/08/2009 MHC Suggestion from SD3 Willis for 92S series.
  736. * 01/09/2009 MHC Add CCK modification for 40MHZ. Suggestion from SD3.
  737. *
  738. *---------------------------------------------------------------------------*/
  739. static void mpt_SwitchRfSetting(PADAPTER pAdapter)
  740. {
  741. Hal_mpt_SwitchRfSetting(pAdapter);
  742. }
  743. /*---------------------------hal\rtl8192c\MPT_Phy.c---------------------------*/
  744. /*---------------------------hal\rtl8192c\MPT_HelperFunc.c---------------------------*/
  745. static void MPT_CCKTxPowerAdjust(PADAPTER Adapter, BOOLEAN bInCH14)
  746. {
  747. Hal_MPT_CCKTxPowerAdjust(Adapter,bInCH14);
  748. }
  749. static void MPT_CCKTxPowerAdjustbyIndex(PADAPTER pAdapter, BOOLEAN beven)
  750. {
  751. Hal_MPT_CCKTxPowerAdjustbyIndex(pAdapter,beven);
  752. }
  753. /*---------------------------hal\rtl8192c\MPT_HelperFunc.c---------------------------*/
  754. /*
  755. * SetChannel
  756. * Description
  757. * Use H2C command to change channel,
  758. * not only modify rf register, but also other setting need to be done.
  759. */
  760. void SetChannel(PADAPTER pAdapter)
  761. {
  762. Hal_SetChannel(pAdapter);
  763. }
  764. /*
  765. * Notice
  766. * Switch bandwitdth may change center frequency(channel)
  767. */
  768. void SetBandwidth(PADAPTER pAdapter)
  769. {
  770. Hal_SetBandwidth(pAdapter);
  771. }
  772. static void SetCCKTxPower(PADAPTER pAdapter, u8 *TxPower)
  773. {
  774. Hal_SetCCKTxPower(pAdapter,TxPower);
  775. }
  776. static void SetOFDMTxPower(PADAPTER pAdapter, u8 *TxPower)
  777. {
  778. Hal_SetOFDMTxPower(pAdapter,TxPower);
  779. }
  780. void SetAntenna(PADAPTER pAdapter)
  781. {
  782. Hal_SetAntenna(pAdapter);
  783. }
  784. void SetAntennaPathPower(PADAPTER pAdapter)
  785. {
  786. Hal_SetAntennaPathPower(pAdapter);
  787. }
  788. int SetTxPower(PADAPTER pAdapter)
  789. {
  790. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  791. u1Byte CurrChannel;
  792. BOOLEAN bResult = _TRUE;
  793. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  794. u1Byte rf, TxPower[2];
  795. u8 u1TxPower = pAdapter->mppriv.txpoweridx;
  796. CurrChannel = pMptCtx->MptChannelToSw;
  797. if(HAL_IsLegalChannel(pAdapter, CurrChannel) == _FALSE)
  798. {
  799. DBG_871X("SetTxPower(): CurrentChannel:%d is not valid\n", CurrChannel);
  800. return _FALSE;
  801. }
  802. TxPower[ODM_RF_PATH_A] = (u1Byte)(u1TxPower&0xff);
  803. TxPower[ODM_RF_PATH_B] = (u1Byte)((u1TxPower&0xff00)>>8);
  804. DBG_871X("TxPower(A, B) = (0x%x, 0x%x)\n", TxPower[ODM_RF_PATH_A], TxPower[ODM_RF_PATH_B]);
  805. for(rf=0; rf<2; rf++)
  806. {
  807. if(TxPower[rf] > MAX_TX_PWR_INDEX_N_MODE) {
  808. DBG_871X("===> SetTxPower: The power index is too large.\n");
  809. return _FALSE;
  810. }
  811. pMptCtx->TxPwrLevel[rf] = TxPower[rf];
  812. }
  813. Hal_SetTxPower(pAdapter);
  814. return _TRUE;
  815. }
  816. void SetTxAGCOffset(PADAPTER pAdapter, u32 ulTxAGCOffset)
  817. {
  818. u32 TxAGCOffset_B, TxAGCOffset_C, TxAGCOffset_D,tmpAGC;
  819. TxAGCOffset_B = (ulTxAGCOffset&0x000000ff);
  820. TxAGCOffset_C = ((ulTxAGCOffset&0x0000ff00)>>8);
  821. TxAGCOffset_D = ((ulTxAGCOffset&0x00ff0000)>>16);
  822. tmpAGC = (TxAGCOffset_D<<8 | TxAGCOffset_C<<4 | TxAGCOffset_B);
  823. write_bbreg(pAdapter, rFPGA0_TxGainStage,
  824. (bXBTxAGC|bXCTxAGC|bXDTxAGC), tmpAGC);
  825. }
  826. void SetDataRate(PADAPTER pAdapter)
  827. {
  828. Hal_SetDataRate(pAdapter);
  829. }
  830. void MP_PHY_SetRFPathSwitch(PADAPTER pAdapter ,BOOLEAN bMain)
  831. {
  832. PHY_SetRFPathSwitch(pAdapter,bMain);
  833. }
  834. s32 SetThermalMeter(PADAPTER pAdapter, u8 target_ther)
  835. {
  836. return Hal_SetThermalMeter( pAdapter, target_ther);
  837. }
  838. static void TriggerRFThermalMeter(PADAPTER pAdapter)
  839. {
  840. Hal_TriggerRFThermalMeter(pAdapter);
  841. }
  842. static u8 ReadRFThermalMeter(PADAPTER pAdapter)
  843. {
  844. return Hal_ReadRFThermalMeter(pAdapter);
  845. }
  846. void GetThermalMeter(PADAPTER pAdapter, u8 *value)
  847. {
  848. Hal_GetThermalMeter(pAdapter,value);
  849. }
  850. void SetSingleCarrierTx(PADAPTER pAdapter, u8 bStart)
  851. {
  852. PhySetTxPowerLevel(pAdapter);
  853. Hal_SetSingleCarrierTx(pAdapter,bStart);
  854. }
  855. void SetSingleToneTx(PADAPTER pAdapter, u8 bStart)
  856. {
  857. PhySetTxPowerLevel(pAdapter);
  858. Hal_SetSingleToneTx(pAdapter,bStart);
  859. }
  860. void SetCarrierSuppressionTx(PADAPTER pAdapter, u8 bStart)
  861. {
  862. PhySetTxPowerLevel(pAdapter);
  863. Hal_SetCarrierSuppressionTx(pAdapter, bStart);
  864. }
  865. void SetCCKContinuousTx(PADAPTER pAdapter, u8 bStart)
  866. {
  867. PhySetTxPowerLevel(pAdapter);
  868. Hal_SetCCKContinuousTx(pAdapter,bStart);
  869. }
  870. void SetOFDMContinuousTx(PADAPTER pAdapter, u8 bStart)
  871. {
  872. PhySetTxPowerLevel(pAdapter);
  873. Hal_SetOFDMContinuousTx( pAdapter, bStart);
  874. }/* mpt_StartOfdmContTx */
  875. void SetContinuousTx(PADAPTER pAdapter, u8 bStart)
  876. {
  877. PhySetTxPowerLevel(pAdapter);
  878. Hal_SetContinuousTx(pAdapter,bStart);
  879. }
  880. void PhySetTxPowerLevel(PADAPTER pAdapter)
  881. {
  882. struct mp_priv *pmp_priv = &pAdapter->mppriv;
  883. if (pmp_priv->bSetTxPower==0) // for NO manually set power index
  884. {
  885. #ifdef CONFIG_RTL8188E
  886. PHY_SetTxPowerLevel8188E(pAdapter,pmp_priv->channel);
  887. #endif
  888. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  889. PHY_SetTxPowerLevel8812(pAdapter,pmp_priv->channel);
  890. #endif
  891. #if defined(CONFIG_RTL8192D)
  892. PHY_SetTxPowerLevel8192D(pAdapter,pmp_priv->channel);
  893. #endif
  894. #if defined(CONFIG_RTL8192C)
  895. PHY_SetTxPowerLevel8192C(pAdapter,pmp_priv->channel);
  896. #endif
  897. #if defined(CONFIG_RTL8192E)
  898. PHY_SetTxPowerLevel8192E(pAdapter,pmp_priv->channel);
  899. #endif
  900. #if defined(CONFIG_RTL8723B)
  901. PHY_SetTxPowerLevel8723B(pAdapter,pmp_priv->channel);
  902. #endif
  903. }
  904. }
  905. //------------------------------------------------------------------------------
  906. static void dump_mpframe(PADAPTER padapter, struct xmit_frame *pmpframe)
  907. {
  908. rtw_hal_mgnt_xmit(padapter, pmpframe);
  909. }
  910. static struct xmit_frame *alloc_mp_xmitframe(struct xmit_priv *pxmitpriv)
  911. {
  912. struct xmit_frame *pmpframe;
  913. struct xmit_buf *pxmitbuf;
  914. if ((pmpframe = rtw_alloc_xmitframe(pxmitpriv)) == NULL)
  915. {
  916. return NULL;
  917. }
  918. if ((pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv)) == NULL)
  919. {
  920. rtw_free_xmitframe(pxmitpriv, pmpframe);
  921. return NULL;
  922. }
  923. pmpframe->frame_tag = MP_FRAMETAG;
  924. pmpframe->pxmitbuf = pxmitbuf;
  925. pmpframe->buf_addr = pxmitbuf->pbuf;
  926. pxmitbuf->priv_data = pmpframe;
  927. return pmpframe;
  928. }
  929. static thread_return mp_xmit_packet_thread(thread_context context)
  930. {
  931. struct xmit_frame *pxmitframe;
  932. struct mp_tx *pmptx;
  933. struct mp_priv *pmp_priv;
  934. struct xmit_priv *pxmitpriv;
  935. PADAPTER padapter;
  936. pmp_priv = (struct mp_priv *)context;
  937. pmptx = &pmp_priv->tx;
  938. padapter = pmp_priv->papdater;
  939. pxmitpriv = &(padapter->xmitpriv);
  940. thread_enter("RTW_MP_THREAD");
  941. DBG_871X("%s:pkTx Start\n", __func__);
  942. while (1) {
  943. pxmitframe = alloc_mp_xmitframe(pxmitpriv);
  944. if (pxmitframe == NULL) {
  945. if (pmptx->stop ||
  946. padapter->bSurpriseRemoved ||
  947. padapter->bDriverStopped) {
  948. goto exit;
  949. }
  950. else {
  951. rtw_msleep_os(1);
  952. continue;
  953. }
  954. }
  955. _rtw_memcpy((u8 *)(pxmitframe->buf_addr+TXDESC_OFFSET), pmptx->buf, pmptx->write_size);
  956. _rtw_memcpy(&(pxmitframe->attrib), &(pmptx->attrib), sizeof(struct pkt_attrib));
  957. dump_mpframe(padapter, pxmitframe);
  958. pmptx->sended++;
  959. pmp_priv->tx_pktcount++;
  960. if (pmptx->stop ||
  961. padapter->bSurpriseRemoved ||
  962. padapter->bDriverStopped)
  963. goto exit;
  964. if ((pmptx->count != 0) &&
  965. (pmptx->count == pmptx->sended))
  966. goto exit;
  967. flush_signals_thread();
  968. }
  969. exit:
  970. //DBG_871X("%s:pkTx Exit\n", __func__);
  971. rtw_mfree(pmptx->pallocated_buf, pmptx->buf_size);
  972. pmptx->pallocated_buf = NULL;
  973. pmptx->stop = 1;
  974. thread_exit();
  975. #ifdef PLATFORM_LINUX
  976. return 0;
  977. #endif
  978. }
  979. void fill_txdesc_for_mp(PADAPTER padapter, struct tx_desc *ptxdesc)
  980. {
  981. struct mp_priv *pmp_priv = &padapter->mppriv;
  982. _rtw_memcpy(ptxdesc, &(pmp_priv->tx.desc), TXDESC_SIZE);
  983. }
  984. #if defined(CONFIG_RTL8192C) || defined(CONFIG_RTL8192D)
  985. void fill_tx_desc_8192cd(PADAPTER padapter)
  986. {
  987. struct mp_priv *pmp_priv = &padapter->mppriv;
  988. struct tx_desc *desc = &(pmp_priv->tx.desc);
  989. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  990. desc->txdw1 |= cpu_to_le32(BK); // don't aggregate(AMPDU)
  991. desc->txdw1 |= cpu_to_le32((pattrib->mac_id) & 0x1F); //CAM_ID(MAC_ID)
  992. desc->txdw1 |= cpu_to_le32((pattrib->qsel << QSEL_SHT) & 0x00001F00); // Queue Select, TID
  993. desc->txdw1 |= cpu_to_le32((pattrib->raid << Rate_ID_SHT) & 0x000F0000); // Rate Adaptive ID
  994. // offset 8
  995. // desc->txdw2 |= cpu_to_le32(AGG_BK);//AGG BK
  996. desc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0x0fff0000);
  997. desc->txdw4 |= cpu_to_le32(HW_SEQ_EN);
  998. desc->txdw4 |= cpu_to_le32(USERATE);
  999. desc->txdw4 |= cpu_to_le32(DISDATAFB);
  1000. if( pmp_priv->preamble ){
  1001. if (pmp_priv->rateidx <= MPT_RATE_54M)
  1002. desc->txdw4 |= cpu_to_le32(DATA_SHORT); // CCK Short Preamble
  1003. }
  1004. if (pmp_priv->bandwidth == CHANNEL_WIDTH_40)
  1005. desc->txdw4 |= cpu_to_le32(DATA_BW);
  1006. // offset 20
  1007. desc->txdw5 |= cpu_to_le32(pmp_priv->rateidx & 0x0000001F);
  1008. if( pmp_priv->preamble ){
  1009. if (pmp_priv->rateidx > MPT_RATE_54M)
  1010. desc->txdw5 |= cpu_to_le32(SGI); // MCS Short Guard Interval
  1011. }
  1012. desc->txdw5 |= cpu_to_le32(0x0001FF00); // DATA/RTS Rate Fallback Limit
  1013. }
  1014. #endif
  1015. #if defined(CONFIG_RTL8188E)
  1016. void fill_tx_desc_8188e(PADAPTER padapter)
  1017. {
  1018. struct mp_priv *pmp_priv = &padapter->mppriv;
  1019. struct tx_desc *desc = &(pmp_priv->tx.desc);
  1020. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1021. u32 pkt_size = pattrib->last_txcmdsz;
  1022. s32 bmcast = IS_MCAST(pattrib->ra);
  1023. // offset 0
  1024. #if !defined(CONFIG_RTL8188E_SDIO)
  1025. desc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
  1026. desc->txdw0 |= cpu_to_le32(pkt_size & 0x0000FFFF); // packet size
  1027. desc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) & 0x00FF0000); //32 bytes for TX Desc
  1028. if (bmcast) desc->txdw0 |= cpu_to_le32(BMC); // broadcast packet
  1029. desc->txdw1 |= cpu_to_le32((0x01 << 26) & 0xff000000);
  1030. #endif
  1031. desc->txdw1 |= cpu_to_le32((pattrib->mac_id) & 0x3F); //CAM_ID(MAC_ID)
  1032. desc->txdw1 |= cpu_to_le32((pattrib->qsel << QSEL_SHT) & 0x00001F00); // Queue Select, TID
  1033. desc->txdw1 |= cpu_to_le32((pattrib->raid << RATE_ID_SHT) & 0x000F0000); // Rate Adaptive ID
  1034. // offset 8
  1035. // desc->txdw2 |= cpu_to_le32(AGG_BK);//AGG BK
  1036. desc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0x0fff0000);
  1037. desc->txdw4 |= cpu_to_le32(HW_SSN);
  1038. desc->txdw4 |= cpu_to_le32(USERATE);
  1039. desc->txdw4 |= cpu_to_le32(DISDATAFB);
  1040. if( pmp_priv->preamble ){
  1041. if (pmp_priv->rateidx <= MPT_RATE_54M)
  1042. desc->txdw4 |= cpu_to_le32(DATA_SHORT); // CCK Short Preamble
  1043. }
  1044. if (pmp_priv->bandwidth == CHANNEL_WIDTH_40)
  1045. desc->txdw4 |= cpu_to_le32(DATA_BW);
  1046. // offset 20
  1047. desc->txdw5 |= cpu_to_le32(pmp_priv->rateidx & 0x0000001F);
  1048. if( pmp_priv->preamble ){
  1049. if (pmp_priv->rateidx > MPT_RATE_54M)
  1050. desc->txdw5 |= cpu_to_le32(SGI); // MCS Short Guard Interval
  1051. }
  1052. desc->txdw5 |= cpu_to_le32(RTY_LMT_EN); // retry limit enable
  1053. desc->txdw5 |= cpu_to_le32(0x00180000); // DATA/RTS Rate Fallback Limit
  1054. }
  1055. #endif
  1056. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  1057. void fill_tx_desc_8812a(PADAPTER padapter)
  1058. {
  1059. struct mp_priv *pmp_priv = &padapter->mppriv;
  1060. //struct tx_desc *pDesc = &(pmp_priv->tx.desc);
  1061. u8 *pDesc = (u8 *)&(pmp_priv->tx.desc);
  1062. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1063. u32 pkt_size = pattrib->last_txcmdsz;
  1064. s32 bmcast = IS_MCAST(pattrib->ra);
  1065. u8 data_rate,pwr_status,offset;
  1066. SET_TX_DESC_FIRST_SEG_8812(pDesc, 1);
  1067. SET_TX_DESC_LAST_SEG_8812(pDesc, 1);
  1068. SET_TX_DESC_OWN_8812(pDesc, 1);
  1069. SET_TX_DESC_PKT_SIZE_8812(pDesc, pkt_size);
  1070. offset = TXDESC_SIZE + OFFSET_SZ;
  1071. SET_TX_DESC_OFFSET_8812(pDesc, offset);
  1072. SET_TX_DESC_PKT_OFFSET_8812(pDesc, 1);
  1073. if (bmcast) {
  1074. SET_TX_DESC_BMC_8812(pDesc, 1);
  1075. }
  1076. SET_TX_DESC_MACID_8812(pDesc, pattrib->mac_id);
  1077. SET_TX_DESC_RATE_ID_8812(pDesc, pattrib->raid);
  1078. //SET_TX_DESC_RATE_ID_8812(pDesc, RATEID_IDX_G);
  1079. SET_TX_DESC_QUEUE_SEL_8812(pDesc, pattrib->qsel);
  1080. //SET_TX_DESC_QUEUE_SEL_8812(pDesc, QSLT_MGNT);
  1081. if (!pattrib->qos_en) {
  1082. SET_TX_DESC_HWSEQ_EN_8812(pDesc, 1); // Hw set sequence number
  1083. } else {
  1084. SET_TX_DESC_SEQ_8812(pDesc, pattrib->seqnum);
  1085. }
  1086. SET_TX_DESC_DISABLE_FB_8812(pDesc, 1);
  1087. SET_TX_DESC_USE_RATE_8812(pDesc, 1);
  1088. SET_TX_DESC_TX_RATE_8812(pDesc, pmp_priv->rateidx);
  1089. }
  1090. #endif
  1091. #if defined(CONFIG_RTL8192E)
  1092. void fill_tx_desc_8192e(PADAPTER padapter)
  1093. {
  1094. struct mp_priv *pmp_priv = &padapter->mppriv;
  1095. struct tx_desc *desc = &(pmp_priv->tx.desc);
  1096. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1097. }
  1098. #endif
  1099. #if defined(CONFIG_RTL8723B)
  1100. void fill_tx_desc_8723b(PADAPTER padapter)
  1101. {
  1102. struct mp_priv *pmp_priv = &padapter->mppriv;
  1103. struct tx_desc *desc = &(pmp_priv->tx.desc);
  1104. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1105. PTXDESC_8723B ptxdesc;
  1106. ptxdesc->bk = 1;
  1107. ptxdesc->macid = pattrib->mac_id;
  1108. ptxdesc->qsel = pattrib->qsel;
  1109. ptxdesc->rate_id = pattrib->raid;
  1110. ptxdesc->seq = pattrib->seqnum;
  1111. ptxdesc->hwseq_sel = 2;
  1112. ptxdesc->userate = 1;
  1113. ptxdesc->disdatafb = 1;
  1114. if( pmp_priv->preamble ){
  1115. if (pmp_priv->rateidx <= MPT_RATE_54M)
  1116. ptxdesc->data_short = 1;
  1117. }
  1118. if (pmp_priv->bandwidth == CHANNEL_WIDTH_40)
  1119. ptxdesc->data_bw = 1;
  1120. ptxdesc->datarate = pmp_priv->rateidx;
  1121. ptxdesc->data_ratefb_lmt = 0x1F;
  1122. ptxdesc->rts_ratefb_lmt = 0xF;
  1123. }
  1124. #endif
  1125. void SetPacketTx(PADAPTER padapter)
  1126. {
  1127. u8 *ptr, *pkt_start, *pkt_end;
  1128. u32 pkt_size,offset;
  1129. struct tx_desc *desc;
  1130. struct rtw_ieee80211_hdr *hdr;
  1131. u8 payload;
  1132. s32 bmcast;
  1133. struct pkt_attrib *pattrib;
  1134. struct mp_priv *pmp_priv;
  1135. pmp_priv = &padapter->mppriv;
  1136. if (pmp_priv->tx.stop) return;
  1137. pmp_priv->tx.sended = 0;
  1138. pmp_priv->tx.stop = 0;
  1139. pmp_priv->tx_pktcount = 0;
  1140. //3 1. update_attrib()
  1141. pattrib = &pmp_priv->tx.attrib;
  1142. _rtw_memcpy(pattrib->src, padapter->eeprompriv.mac_addr, ETH_ALEN);
  1143. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  1144. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  1145. bmcast = IS_MCAST(pattrib->ra);
  1146. if (bmcast) {
  1147. pattrib->mac_id = 1;
  1148. pattrib->psta = rtw_get_bcmc_stainfo(padapter);
  1149. } else {
  1150. pattrib->mac_id = 0;
  1151. pattrib->psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
  1152. }
  1153. pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->pktlen;
  1154. //3 2. allocate xmit buffer
  1155. pkt_size = pattrib->last_txcmdsz;
  1156. if (pmp_priv->tx.pallocated_buf)
  1157. rtw_mfree(pmp_priv->tx.pallocated_buf, pmp_priv->tx.buf_size);
  1158. pmp_priv->tx.write_size = pkt_size;
  1159. pmp_priv->tx.buf_size = pkt_size + XMITBUF_ALIGN_SZ;
  1160. pmp_priv->tx.pallocated_buf = rtw_zmalloc(pmp_priv->tx.buf_size);
  1161. if (pmp_priv->tx.pallocated_buf == NULL) {
  1162. DBG_871X("%s: malloc(%d) fail!!\n", __func__, pmp_priv->tx.buf_size);
  1163. return;
  1164. }
  1165. pmp_priv->tx.buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pmp_priv->tx.pallocated_buf), XMITBUF_ALIGN_SZ);
  1166. ptr = pmp_priv->tx.buf;
  1167. desc = &(pmp_priv->tx.desc);
  1168. _rtw_memset(desc, 0, TXDESC_SIZE);
  1169. pkt_start = ptr;
  1170. pkt_end = pkt_start + pkt_size;
  1171. //3 3. init TX descriptor
  1172. #if defined(CONFIG_RTL8192C) || defined(CONFIG_RTL8192D)
  1173. if(IS_HARDWARE_TYPE_8192C(padapter) ||IS_HARDWARE_TYPE_8192D(padapter))
  1174. fill_tx_desc_8192cd(padapter);
  1175. #endif
  1176. #if defined(CONFIG_RTL8188E)
  1177. if(IS_HARDWARE_TYPE_8188E(padapter))
  1178. fill_tx_desc_8188e(padapter);
  1179. #endif
  1180. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  1181. if(IS_HARDWARE_TYPE_8812(padapter))
  1182. fill_tx_desc_8812a(padapter);
  1183. #endif
  1184. #if defined(CONFIG_RTL8192E)
  1185. if(IS_HARDWARE_TYPE_8188E(padapter))
  1186. fill_tx_desc_8192e(padapter);
  1187. #endif
  1188. #if defined(CONFIG_RTL8723B)
  1189. if(IS_HARDWARE_TYPE_8723B(padapter))
  1190. fill_tx_desc_8723b(padapter);
  1191. #endif
  1192. //3 4. make wlan header, make_wlanhdr()
  1193. hdr = (struct rtw_ieee80211_hdr *)pkt_start;
  1194. SetFrameSubType(&hdr->frame_ctl, pattrib->subtype);
  1195. _rtw_memcpy(hdr->addr1, pattrib->dst, ETH_ALEN); // DA
  1196. _rtw_memcpy(hdr->addr2, pattrib->src, ETH_ALEN); // SA
  1197. _rtw_memcpy(hdr->addr3, get_bssid(&padapter->mlmepriv), ETH_ALEN); // RA, BSSID
  1198. //3 5. make payload
  1199. ptr = pkt_start + pattrib->hdrlen;
  1200. switch (pmp_priv->tx.payload) {
  1201. case 0:
  1202. payload = 0x00;
  1203. break;
  1204. case 1:
  1205. payload = 0x5a;
  1206. break;
  1207. case 2:
  1208. payload = 0xa5;
  1209. break;
  1210. case 3:
  1211. payload = 0xff;
  1212. break;
  1213. default:
  1214. payload = 0x00;
  1215. break;
  1216. }
  1217. _rtw_memset(ptr, payload, pkt_end - ptr);
  1218. //3 6. start thread
  1219. #ifdef PLATFORM_LINUX
  1220. pmp_priv->tx.PktTxThread = kthread_run(mp_xmit_packet_thread, pmp_priv, "RTW_MP_THREAD");
  1221. if (IS_ERR(pmp_priv->tx.PktTxThread))
  1222. DBG_871X("Create PktTx Thread Fail !!!!!\n");
  1223. #endif
  1224. #ifdef PLATFORM_FREEBSD
  1225. {
  1226. struct proc *p;
  1227. struct thread *td;
  1228. pmp_priv->tx.PktTxThread = kproc_kthread_add(mp_xmit_packet_thread, pmp_priv,
  1229. &p, &td, RFHIGHPID, 0, "MPXmitThread", "MPXmitThread");
  1230. if (pmp_priv->tx.PktTxThread < 0)
  1231. DBG_871X("Create PktTx Thread Fail !!!!!\n");
  1232. }
  1233. #endif
  1234. }
  1235. void SetPacketRx(PADAPTER pAdapter, u8 bStartRx)
  1236. {
  1237. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1238. if(bStartRx)
  1239. {
  1240. // Accept CRC error and destination address
  1241. #if 1
  1242. //ndef CONFIG_RTL8723A
  1243. pHalData->ReceiveConfig = AAP | APM | AM | AB | APP_ICV | ADF | AMF | HTC_LOC_CTRL | APP_MIC | APP_PHYSTS;
  1244. pHalData->ReceiveConfig |= ACRC32;
  1245. rtw_write32(pAdapter, REG_RCR, pHalData->ReceiveConfig);
  1246. // Accept all data frames
  1247. rtw_write16(pAdapter, REG_RXFLTMAP2, 0xFFFF);
  1248. #else
  1249. rtw_write32(pAdapter, REG_RCR, 0x70000101);
  1250. #endif
  1251. }
  1252. else
  1253. {
  1254. rtw_write32(pAdapter, REG_RCR, 0);
  1255. }
  1256. }
  1257. void ResetPhyRxPktCount(PADAPTER pAdapter)
  1258. {
  1259. u32 i, phyrx_set = 0;
  1260. for (i = 0; i <= 0xF; i++) {
  1261. phyrx_set = 0;
  1262. phyrx_set |= _RXERR_RPT_SEL(i); //select
  1263. phyrx_set |= RXERR_RPT_RST; // set counter to zero
  1264. rtw_write32(pAdapter, REG_RXERR_RPT, phyrx_set);
  1265. }
  1266. }
  1267. static u32 GetPhyRxPktCounts(PADAPTER pAdapter, u32 selbit)
  1268. {
  1269. //selection
  1270. u32 phyrx_set = 0, count = 0;
  1271. phyrx_set = _RXERR_RPT_SEL(selbit & 0xF);
  1272. rtw_write32(pAdapter, REG_RXERR_RPT, phyrx_set);
  1273. //Read packet count
  1274. count = rtw_read32(pAdapter, REG_RXERR_RPT) & RXERR_COUNTER_MASK;
  1275. return count;
  1276. }
  1277. u32 GetPhyRxPktReceived(PADAPTER pAdapter)
  1278. {
  1279. u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
  1280. OFDM_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_OFDM_MPDU_OK);
  1281. CCK_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_CCK_MPDU_OK);
  1282. HT_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_HT_MPDU_OK);
  1283. return OFDM_cnt + CCK_cnt + HT_cnt;
  1284. }
  1285. u32 GetPhyRxPktCRC32Error(PADAPTER pAdapter)
  1286. {
  1287. u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
  1288. OFDM_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_OFDM_MPDU_FAIL);
  1289. CCK_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_CCK_MPDU_FAIL);
  1290. HT_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_HT_MPDU_FAIL);
  1291. return OFDM_cnt + CCK_cnt + HT_cnt;
  1292. }
  1293. //reg 0x808[9:0]: FFT data x
  1294. //reg 0x808[22]: 0 --> 1 to get 1 FFT data y
  1295. //reg 0x8B4[15:0]: FFT data y report
  1296. static u32 rtw_GetPSDData(PADAPTER pAdapter, u32 point)
  1297. {
  1298. u32 psd_val=0;
  1299. #if defined(CONFIG_RTL8812A) //MP PSD for 8812A
  1300. u16 psd_reg = 0x910;
  1301. u16 psd_regL= 0xF44;
  1302. #else
  1303. u16 psd_reg = 0x808;
  1304. u16 psd_regL= 0x8B4;
  1305. #endif
  1306. psd_val = rtw_read32(pAdapter, psd_reg);
  1307. psd_val &= 0xFFBFFC00;
  1308. psd_val |= point;
  1309. rtw_write32(pAdapter, psd_reg, psd_val);
  1310. rtw_mdelay_os(1);
  1311. psd_val |= 0x00400000;
  1312. rtw_write32(pAdapter, psd_reg, psd_val);
  1313. rtw_mdelay_os(1);
  1314. psd_val = rtw_read32(pAdapter, psd_regL);
  1315. psd_val &= 0x0000FFFF;
  1316. return psd_val;
  1317. }
  1318. /*
  1319. * pts start_point_min stop_point_max
  1320. * 128 64 64 + 128 = 192
  1321. * 256 128 128 + 256 = 384
  1322. * 512 256 256 + 512 = 768
  1323. * 1024 512 512 + 1024 = 1536
  1324. *
  1325. */
  1326. u32 mp_query_psd(PADAPTER pAdapter, u8 *data)
  1327. {
  1328. u32 i, psd_pts=0, psd_start=0, psd_stop=0;
  1329. u32 psd_data=0;
  1330. #ifdef PLATFORM_LINUX
  1331. if (!netif_running(pAdapter->pnetdev)) {
  1332. RT_TRACE(_module_mp_, _drv_warning_, ("mp_query_psd: Fail! interface not opened!\n"));
  1333. return 0;
  1334. }
  1335. #endif
  1336. if (check_fwstate(&pAdapter->mlmepriv, WIFI_MP_STATE) == _FALSE) {
  1337. RT_TRACE(_module_mp_, _drv_warning_, ("mp_query_psd: Fail! not in MP mode!\n"));
  1338. return 0;
  1339. }
  1340. if (strlen(data) == 0) { //default value
  1341. psd_pts = 128;
  1342. psd_start = 64;
  1343. psd_stop = 128;
  1344. } else {
  1345. sscanf(data, "pts=%d,start=%d,stop=%d", &psd_pts, &psd_start, &psd_stop);
  1346. }
  1347. _rtw_memset(data, '\0', sizeof(data));
  1348. i = psd_start;
  1349. while (i < psd_stop)
  1350. {
  1351. if (i >= psd_pts) {
  1352. psd_data = rtw_GetPSDData(pAdapter, i-psd_pts);
  1353. } else {
  1354. psd_data = rtw_GetPSDData(pAdapter, i);
  1355. }
  1356. sprintf(data, "%s%x ", data, psd_data);
  1357. i++;
  1358. }
  1359. #ifdef CONFIG_LONG_DELAY_ISSUE
  1360. rtw_msleep_os(100);
  1361. #else
  1362. rtw_mdelay_os(100);
  1363. #endif
  1364. return strlen(data)+1;
  1365. }
  1366. void _rtw_mp_xmit_priv (struct xmit_priv *pxmitpriv)
  1367. {
  1368. int i,res;
  1369. _adapter *padapter = pxmitpriv->adapter;
  1370. struct xmit_frame *pxmitframe = (struct xmit_frame*) pxmitpriv->pxmit_frame_buf;
  1371. struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
  1372. u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  1373. u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
  1374. if(padapter->registrypriv.mp_mode ==0)
  1375. {
  1376. max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  1377. num_xmit_extbuf = NR_XMIT_EXTBUFF;
  1378. }
  1379. else
  1380. {
  1381. max_xmit_extbuf_size = 20000;
  1382. num_xmit_extbuf = 1;
  1383. }
  1384. pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
  1385. for(i=0; i<num_xmit_extbuf; i++)
  1386. {
  1387. rtw_os_xmit_resource_free(padapter, pxmitbuf,(max_xmit_extbuf_size + XMITBUF_ALIGN_SZ), _FALSE);
  1388. pxmitbuf++;
  1389. }
  1390. if(pxmitpriv->pallocated_xmit_extbuf) {
  1391. rtw_vmfree(pxmitpriv->pallocated_xmit_extbuf, num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
  1392. }
  1393. if(padapter->registrypriv.mp_mode ==0)
  1394. {
  1395. max_xmit_extbuf_size = 20000;
  1396. num_xmit_extbuf = 1;
  1397. }
  1398. else
  1399. {
  1400. max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  1401. num_xmit_extbuf = NR_XMIT_EXTBUFF;
  1402. }
  1403. // Init xmit extension buff
  1404. _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
  1405. pxmitpriv->pallocated_xmit_extbuf = rtw_zvmalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
  1406. if (pxmitpriv->pallocated_xmit_extbuf == NULL){
  1407. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("alloc xmit_extbuf fail!\n"));
  1408. res= _FAIL;
  1409. goto exit;
  1410. }
  1411. pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmit_extbuf), 4);
  1412. pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
  1413. for (i = 0; i < num_xmit_extbuf; i++)
  1414. {
  1415. _rtw_init_listhead(&pxmitbuf->list);
  1416. pxmitbuf->priv_data = NULL;
  1417. pxmitbuf->padapter = padapter;
  1418. pxmitbuf->buf_tag = XMITBUF_MGNT;
  1419. if((res=rtw_os_xmit_resource_alloc(padapter, pxmitbuf,max_xmit_extbuf_size + XMITBUF_ALIGN_SZ, _FALSE)) == _FAIL) {
  1420. res= _FAIL;
  1421. goto exit;
  1422. }
  1423. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1424. pxmitbuf->phead = pxmitbuf->pbuf;
  1425. pxmitbuf->pend = pxmitbuf->pbuf + max_xmit_extbuf_size;
  1426. pxmitbuf->len = 0;
  1427. pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
  1428. #endif
  1429. rtw_list_insert_tail(&pxmitbuf->list, &(pxmitpriv->free_xmit_extbuf_queue.queue));
  1430. #ifdef DBG_XMIT_BUF_EXT
  1431. pxmitbuf->no=i;
  1432. #endif
  1433. pxmitbuf++;
  1434. }
  1435. pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
  1436. exit:
  1437. ;
  1438. }
  1439. ULONG getPowerDiffByRate8188E(
  1440. IN PADAPTER pAdapter,
  1441. IN u1Byte CurrChannel,
  1442. IN ULONG RfPath
  1443. )
  1444. {
  1445. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1446. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1447. ULONG PwrGroup=0;
  1448. ULONG TxPower=0, Limit=0;
  1449. ULONG Pathmapping = (RfPath == ODM_RF_PATH_A?0:8);
  1450. switch(pHalData->EEPROMRegulatory)
  1451. {
  1452. case 0: // driver-defined maximum power offset for longer communication range
  1453. // refer to power by rate table
  1454. PwrGroup = 0;
  1455. Limit = 0xff;
  1456. break;
  1457. case 1: // Power-limit table-defined maximum power offset range
  1458. // choosed by min(power by rate, power limit).
  1459. {
  1460. if(pHalData->pwrGroupCnt == 1)
  1461. PwrGroup = 0;
  1462. if(pHalData->pwrGroupCnt >= 3)
  1463. {
  1464. if(CurrChannel <= 3)
  1465. PwrGroup = 0;
  1466. else if(CurrChannel >= 4 && CurrChannel <= 9)
  1467. PwrGroup = 1;
  1468. else if(CurrChannel > 9)
  1469. PwrGroup = 2;
  1470. if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
  1471. PwrGroup++;
  1472. else
  1473. PwrGroup+=4;
  1474. }
  1475. Limit = 0xff;
  1476. }
  1477. break;
  1478. case 2: // not support power offset by rate.
  1479. // don't increase any power diff
  1480. PwrGroup = 0;
  1481. Limit = 0;
  1482. break;
  1483. default:
  1484. PwrGroup = 0;
  1485. Limit = 0xff;
  1486. break;
  1487. }
  1488. {
  1489. switch(pMptCtx->MptRateIndex)
  1490. {
  1491. case MPT_RATE_1M:
  1492. case MPT_RATE_2M:
  1493. case MPT_RATE_55M:
  1494. case MPT_RATE_11M:
  1495. //CCK rates, don't add any tx power index.
  1496. //RT_DISP(FPHY, PHY_TXPWR,("CCK rates!\n"));
  1497. break;
  1498. case MPT_RATE_6M: //0xe00 [31:0] = 18M,12M,09M,06M
  1499. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff);
  1500. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 6M, TxPower = %d\n",
  1501. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1502. break;
  1503. case MPT_RATE_9M:
  1504. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff00)>>8);
  1505. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 9M, TxPower = %d\n",
  1506. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1507. break;
  1508. case MPT_RATE_12M:
  1509. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff0000)>>16);
  1510. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 12M, TxPower = %d\n",
  1511. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1512. break;
  1513. case MPT_RATE_18M:
  1514. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff000000)>>24);
  1515. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 24M, TxPower = %d\n",
  1516. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1517. break;
  1518. case MPT_RATE_24M: //0xe04[31:0] = 54M,48M,36M,24M
  1519. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff);
  1520. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 24M, TxPower = %d\n",
  1521. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1522. break;
  1523. case MPT_RATE_36M:
  1524. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff00)>>8);
  1525. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 36M, TxPower = %d\n",
  1526. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1527. break;
  1528. case MPT_RATE_48M:
  1529. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff0000)>>16);
  1530. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 48M, TxPower = %d\n",
  1531. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1532. break;
  1533. case MPT_RATE_54M:
  1534. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff000000)>>24);
  1535. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 54M, TxPower = %d\n",
  1536. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1537. break;
  1538. case MPT_RATE_MCS0: //0xe10[31:0]= MCS=03,02,01,00
  1539. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff);
  1540. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS0, TxPower = %d\n",
  1541. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1542. break;
  1543. case MPT_RATE_MCS1:
  1544. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff00)>>8);
  1545. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS1, TxPower = %d\n",
  1546. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1547. break;
  1548. case MPT_RATE_MCS2:
  1549. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff0000)>>16);
  1550. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS2, TxPower = %d\n",
  1551. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1552. break;
  1553. case MPT_RATE_MCS3:
  1554. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff000000)>>24);
  1555. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS3, TxPower = %d\n",
  1556. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1557. break;
  1558. case MPT_RATE_MCS4: //0xe14[31:0]= MCS=07,06,05,04
  1559. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff);
  1560. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS4, TxPower = %d\n",
  1561. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1562. break;
  1563. case MPT_RATE_MCS5:
  1564. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff00)>>8);
  1565. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS5, TxPower = %d\n",
  1566. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1567. break;
  1568. case MPT_RATE_MCS6:
  1569. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff0000)>>16);
  1570. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS6, TxPower = %d\n",
  1571. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1572. break;
  1573. case MPT_RATE_MCS7:
  1574. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff000000)>>24);
  1575. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS7, TxPower = %d\n",
  1576. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1577. break;
  1578. case MPT_RATE_MCS8: //0xe18[31:0]= MCS=11,10,09,08
  1579. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff);
  1580. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS8, TxPower = %d\n",
  1581. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1582. break;
  1583. case MPT_RATE_MCS9:
  1584. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff00)>>8);
  1585. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS9, TxPower = %d\n",
  1586. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1587. break;
  1588. case MPT_RATE_MCS10:
  1589. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff0000)>>16);
  1590. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS10, TxPower = %d\n",
  1591. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1592. break;
  1593. case MPT_RATE_MCS11:
  1594. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff000000)>>24);
  1595. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS11, TxPower = %d\n",
  1596. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1597. break;
  1598. case MPT_RATE_MCS12: //0xe1c[31:0]= MCS=15,14,13,12
  1599. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff);
  1600. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS12, TxPower = %d\n",
  1601. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1602. break;
  1603. case MPT_RATE_MCS13:
  1604. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff00)>>8);
  1605. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS13, TxPower = %d\n",
  1606. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1607. break;
  1608. case MPT_RATE_MCS14:
  1609. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff0000)>>16);
  1610. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS14, TxPower = %d\n",
  1611. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1612. break;
  1613. case MPT_RATE_MCS15:
  1614. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff000000)>>24);
  1615. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS15, TxPower = %d\n",
  1616. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1617. break;
  1618. default:
  1619. break;
  1620. }
  1621. }
  1622. if(TxPower > Limit)
  1623. TxPower = Limit;
  1624. return TxPower;
  1625. }
  1626. static ULONG
  1627. mpt_ProQueryCalTxPower_8188E(
  1628. IN PADAPTER pAdapter,
  1629. IN u1Byte RfPath
  1630. )
  1631. {
  1632. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1633. u1Byte TxCount=TX_1S, i = 0; //default set to 1S
  1634. //PMGNT_INFO pMgntInfo = &(pAdapter->MgntInfo);
  1635. ULONG TxPower = 1, PwrGroup=0, PowerDiffByRate=0;
  1636. ULONG TxPowerCCK = 1, TxPowerOFDM = 1, TxPowerBW20 = 1, TxPowerBW40 = 1 ;
  1637. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1638. u1Byte CurrChannel = pHalData->CurrentChannel;
  1639. u1Byte index = (CurrChannel -1);
  1640. u1Byte rf_path=(RfPath), rfPath;
  1641. u1Byte limit = 0, rate = 0;
  1642. if(HAL_IsLegalChannel(pAdapter, CurrChannel) == FALSE)
  1643. {
  1644. CurrChannel = 1;
  1645. }
  1646. if( pMptCtx->MptRateIndex >= MPT_RATE_1M &&
  1647. pMptCtx->MptRateIndex <= MPT_RATE_11M )
  1648. {
  1649. TxPower = pHalData->Index24G_CCK_Base[rf_path][index];
  1650. }
  1651. else if(pMptCtx->MptRateIndex >= MPT_RATE_6M &&
  1652. pMptCtx->MptRateIndex <= MPT_RATE_54M )
  1653. {
  1654. TxPower = pHalData->Index24G_BW40_Base[rf_path][index];
  1655. }
  1656. else if(pMptCtx->MptRateIndex >= MPT_RATE_MCS0 &&
  1657. pMptCtx->MptRateIndex <= MPT_RATE_MCS7 )
  1658. {
  1659. TxPower = pHalData->Index24G_BW40_Base[rf_path][index];
  1660. }
  1661. //RT_DISP(FPHY, PHY_TXPWR, ("HT40 rate(%d) Tx power(RF-%c) = 0x%x\n", pMptCtx->MptRateIndex, ((rf_path==0)?'A':'B'), TxPower));
  1662. if(pMptCtx->MptRateIndex >= MPT_RATE_6M &&
  1663. pMptCtx->MptRateIndex <= MPT_RATE_54M )
  1664. {
  1665. TxPower += pHalData->OFDM_24G_Diff[rf_path][TxCount];
  1666. ///RT_DISP(FPHY, PHY_TXPWR, ("+OFDM_PowerDiff(RF-%c) = 0x%x\n", ((rf_path==0)?'A':'B'),
  1667. // pHalData->OFDM_24G_Diff[rf_path][TxCount]));
  1668. }
  1669. if(pMptCtx->MptRateIndex >= MPT_RATE_MCS0)
  1670. {
  1671. if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
  1672. {
  1673. TxPower += pHalData->BW20_24G_Diff[rf_path][TxCount];
  1674. // RT_DISP(FPHY, PHY_TXPWR, ("+HT20_PowerDiff(RF-%c) = 0x%x\n", ((rf_path==0)?'A':'B'),
  1675. // pHalData->BW20_24G_Diff[rf_path][TxCount]));
  1676. }
  1677. }
  1678. #ifdef ENABLE_POWER_BY_RATE
  1679. PowerDiffByRate = getPowerDiffByRate8188E(pAdapter, CurrChannel, RfPath);
  1680. #else
  1681. PowerDiffByRate = 0;
  1682. #endif
  1683. //RT_DISP(FPHY, PHY_TXPWR, ("+PowerDiffByRate(RF-%c) = 0x%x\n", ((rf_path==0)?'A':'B'),
  1684. // PowerDiffByRate));
  1685. TxPower += PowerDiffByRate;
  1686. // RT_DISP(FPHY, PHY_TXPWR, ("Final TxPower(RF-%c) = %d(0x%x)\n", ((rf_path==0)?'A':'B'),
  1687. // TxPower, TxPower));
  1688. /*
  1689. if(TxPower > 0x3f)
  1690. TxPower = 0x3f;
  1691. */
  1692. // 2012/11/02 Awk: add power limit mechansim
  1693. if( pMptCtx->MptRateIndex >= MPT_RATE_1M &&
  1694. pMptCtx->MptRateIndex <= MPT_RATE_11M )
  1695. {
  1696. rate = MGN_1M;
  1697. }
  1698. else if(pMptCtx->MptRateIndex >= MPT_RATE_6M &&
  1699. pMptCtx->MptRateIndex <= MPT_RATE_54M )
  1700. {
  1701. rate = MGN_54M;
  1702. }
  1703. else if(pMptCtx->MptRateIndex >= MPT_RATE_MCS0 &&
  1704. pMptCtx->MptRateIndex <= MPT_RATE_MCS7 )
  1705. {
  1706. rate = MGN_MCS7;
  1707. }
  1708. #ifdef CONFIG_8192E
  1709. limit = PHY_GetPowerLimitValue(pAdapter, pMptCtx->RegTxPwrLimit,
  1710. pHalData->CurrentBandType,
  1711. pHalData->CurrentChannelBW,RfPath,
  1712. rate, CurrChannel);
  1713. #endif
  1714. TxPower = TxPower > limit ? limit : TxPower;
  1715. return TxPower;
  1716. }
  1717. ULONG mpt_ProQueryCalTxPower(
  1718. PADAPTER pAdapter,
  1719. u8 RfPath
  1720. )
  1721. {
  1722. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1723. ULONG TxPower = 1, PwrGroup=0, PowerDiffByRate=0;
  1724. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1725. u1Byte limit = 0, rate = 0;
  1726. rate=pMptCtx->MptRateIndex;
  1727. if ( IS_HARDWARE_TYPE_8188E(pAdapter) || IS_HARDWARE_TYPE_8192E(pAdapter) )//|| IS_HARDWARE_TYPE_8723B(pAdapter))
  1728. {
  1729. return mpt_ProQueryCalTxPower_8188E(pAdapter, RfPath);
  1730. }
  1731. else
  1732. {
  1733. #ifdef CONFIG_8812A
  1734. TxPower = PHY_GetTxPowerIndex_8812A(pAdapter, RfPath, rate,pHalData->CurrentChannelBW, pHalData->CurrentChannel);
  1735. #endif
  1736. return TxPower;
  1737. }
  1738. }
  1739. void Hal_ProSetCrystalCap (PADAPTER pAdapter , u32 CrystalCapVal)
  1740. {
  1741. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1742. CrystalCapVal = pHalData->CrystalCap & 0x3F;
  1743. if(IS_HARDWARE_TYPE_8192D(pAdapter))
  1744. {
  1745. PHY_SetBBReg(pAdapter, REG_AFE_XTAL_CTRL, 0xF0, CrystalCapVal & 0x0F);
  1746. PHY_SetBBReg(pAdapter, REG_AFE_PLL_CTRL, 0xF0000000, (CrystalCapVal & 0xF0) >> 4);
  1747. }
  1748. else if(IS_HARDWARE_TYPE_8188E(pAdapter))
  1749. {
  1750. // write 0x24[16:11] = 0x24[22:17] = CrystalCap
  1751. PHY_SetBBReg(pAdapter, REG_AFE_XTAL_CTRL, 0x7FF800, (CrystalCapVal | (CrystalCapVal << 6)));
  1752. }
  1753. else if(IS_HARDWARE_TYPE_8812(pAdapter))
  1754. {
  1755. // write 0x2C[30:25] = 0x2C[24:19] = CrystalCap
  1756. PHY_SetBBReg(pAdapter, REG_MAC_PHY_CTRL, 0x7FF80000, (CrystalCapVal | (CrystalCapVal << 6)));
  1757. }
  1758. else if(IS_HARDWARE_TYPE_8821(pAdapter) || IS_HARDWARE_TYPE_8192E(pAdapter))
  1759. {
  1760. // write 0x2C[23:18] = 0x2C[17:12] = CrystalCap
  1761. PHY_SetBBReg(pAdapter, REG_MAC_PHY_CTRL, 0xFFF000, (CrystalCapVal | (CrystalCapVal << 6)));
  1762. }
  1763. else
  1764. {
  1765. PHY_SetBBReg(pAdapter, 0x2c, 0xFFF000, (CrystalCapVal | (CrystalCapVal << 6)));
  1766. }
  1767. }
  1768. #endif