rtw_mp.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125
  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. }
  976. void fill_txdesc_for_mp(PADAPTER padapter, struct tx_desc *ptxdesc)
  977. {
  978. struct mp_priv *pmp_priv = &padapter->mppriv;
  979. _rtw_memcpy(ptxdesc, &(pmp_priv->tx.desc), TXDESC_SIZE);
  980. }
  981. #if defined(CONFIG_RTL8192C) || defined(CONFIG_RTL8192D)
  982. void fill_tx_desc_8192cd(PADAPTER padapter)
  983. {
  984. struct mp_priv *pmp_priv = &padapter->mppriv;
  985. struct tx_desc *desc = &(pmp_priv->tx.desc);
  986. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  987. desc->txdw1 |= cpu_to_le32(BK); // don't aggregate(AMPDU)
  988. desc->txdw1 |= cpu_to_le32((pattrib->mac_id) & 0x1F); //CAM_ID(MAC_ID)
  989. desc->txdw1 |= cpu_to_le32((pattrib->qsel << QSEL_SHT) & 0x00001F00); // Queue Select, TID
  990. desc->txdw1 |= cpu_to_le32((pattrib->raid << Rate_ID_SHT) & 0x000F0000); // Rate Adaptive ID
  991. // offset 8
  992. // desc->txdw2 |= cpu_to_le32(AGG_BK);//AGG BK
  993. desc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0x0fff0000);
  994. desc->txdw4 |= cpu_to_le32(HW_SEQ_EN);
  995. desc->txdw4 |= cpu_to_le32(USERATE);
  996. desc->txdw4 |= cpu_to_le32(DISDATAFB);
  997. if( pmp_priv->preamble ){
  998. if (pmp_priv->rateidx <= MPT_RATE_54M)
  999. desc->txdw4 |= cpu_to_le32(DATA_SHORT); // CCK Short Preamble
  1000. }
  1001. if (pmp_priv->bandwidth == CHANNEL_WIDTH_40)
  1002. desc->txdw4 |= cpu_to_le32(DATA_BW);
  1003. // offset 20
  1004. desc->txdw5 |= cpu_to_le32(pmp_priv->rateidx & 0x0000001F);
  1005. if( pmp_priv->preamble ){
  1006. if (pmp_priv->rateidx > MPT_RATE_54M)
  1007. desc->txdw5 |= cpu_to_le32(SGI); // MCS Short Guard Interval
  1008. }
  1009. desc->txdw5 |= cpu_to_le32(0x0001FF00); // DATA/RTS Rate Fallback Limit
  1010. }
  1011. #endif
  1012. #if defined(CONFIG_RTL8188E)
  1013. void fill_tx_desc_8188e(PADAPTER padapter)
  1014. {
  1015. struct mp_priv *pmp_priv = &padapter->mppriv;
  1016. struct tx_desc *desc = &(pmp_priv->tx.desc);
  1017. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1018. u32 pkt_size = pattrib->last_txcmdsz;
  1019. s32 bmcast = IS_MCAST(pattrib->ra);
  1020. // offset 0
  1021. #if !defined(CONFIG_RTL8188E_SDIO)
  1022. desc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
  1023. desc->txdw0 |= cpu_to_le32(pkt_size & 0x0000FFFF); // packet size
  1024. desc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) & 0x00FF0000); //32 bytes for TX Desc
  1025. if (bmcast) desc->txdw0 |= cpu_to_le32(BMC); // broadcast packet
  1026. desc->txdw1 |= cpu_to_le32((0x01 << 26) & 0xff000000);
  1027. #endif
  1028. desc->txdw1 |= cpu_to_le32((pattrib->mac_id) & 0x3F); //CAM_ID(MAC_ID)
  1029. desc->txdw1 |= cpu_to_le32((pattrib->qsel << QSEL_SHT) & 0x00001F00); // Queue Select, TID
  1030. desc->txdw1 |= cpu_to_le32((pattrib->raid << RATE_ID_SHT) & 0x000F0000); // Rate Adaptive ID
  1031. // offset 8
  1032. // desc->txdw2 |= cpu_to_le32(AGG_BK);//AGG BK
  1033. desc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0x0fff0000);
  1034. desc->txdw4 |= cpu_to_le32(HW_SSN);
  1035. desc->txdw4 |= cpu_to_le32(USERATE);
  1036. desc->txdw4 |= cpu_to_le32(DISDATAFB);
  1037. if( pmp_priv->preamble ){
  1038. if (pmp_priv->rateidx <= MPT_RATE_54M)
  1039. desc->txdw4 |= cpu_to_le32(DATA_SHORT); // CCK Short Preamble
  1040. }
  1041. if (pmp_priv->bandwidth == CHANNEL_WIDTH_40)
  1042. desc->txdw4 |= cpu_to_le32(DATA_BW);
  1043. // offset 20
  1044. desc->txdw5 |= cpu_to_le32(pmp_priv->rateidx & 0x0000001F);
  1045. if( pmp_priv->preamble ){
  1046. if (pmp_priv->rateidx > MPT_RATE_54M)
  1047. desc->txdw5 |= cpu_to_le32(SGI); // MCS Short Guard Interval
  1048. }
  1049. desc->txdw5 |= cpu_to_le32(RTY_LMT_EN); // retry limit enable
  1050. desc->txdw5 |= cpu_to_le32(0x00180000); // DATA/RTS Rate Fallback Limit
  1051. }
  1052. #endif
  1053. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  1054. void fill_tx_desc_8812a(PADAPTER padapter)
  1055. {
  1056. struct mp_priv *pmp_priv = &padapter->mppriv;
  1057. //struct tx_desc *pDesc = &(pmp_priv->tx.desc);
  1058. u8 *pDesc = (u8 *)&(pmp_priv->tx.desc);
  1059. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1060. u32 pkt_size = pattrib->last_txcmdsz;
  1061. s32 bmcast = IS_MCAST(pattrib->ra);
  1062. u8 data_rate,pwr_status,offset;
  1063. SET_TX_DESC_FIRST_SEG_8812(pDesc, 1);
  1064. SET_TX_DESC_LAST_SEG_8812(pDesc, 1);
  1065. SET_TX_DESC_OWN_8812(pDesc, 1);
  1066. SET_TX_DESC_PKT_SIZE_8812(pDesc, pkt_size);
  1067. offset = TXDESC_SIZE + OFFSET_SZ;
  1068. SET_TX_DESC_OFFSET_8812(pDesc, offset);
  1069. SET_TX_DESC_PKT_OFFSET_8812(pDesc, 1);
  1070. if (bmcast) {
  1071. SET_TX_DESC_BMC_8812(pDesc, 1);
  1072. }
  1073. SET_TX_DESC_MACID_8812(pDesc, pattrib->mac_id);
  1074. SET_TX_DESC_RATE_ID_8812(pDesc, pattrib->raid);
  1075. //SET_TX_DESC_RATE_ID_8812(pDesc, RATEID_IDX_G);
  1076. SET_TX_DESC_QUEUE_SEL_8812(pDesc, pattrib->qsel);
  1077. //SET_TX_DESC_QUEUE_SEL_8812(pDesc, QSLT_MGNT);
  1078. if (!pattrib->qos_en) {
  1079. SET_TX_DESC_HWSEQ_EN_8812(pDesc, 1); // Hw set sequence number
  1080. } else {
  1081. SET_TX_DESC_SEQ_8812(pDesc, pattrib->seqnum);
  1082. }
  1083. SET_TX_DESC_DISABLE_FB_8812(pDesc, 1);
  1084. SET_TX_DESC_USE_RATE_8812(pDesc, 1);
  1085. SET_TX_DESC_TX_RATE_8812(pDesc, pmp_priv->rateidx);
  1086. }
  1087. #endif
  1088. #if defined(CONFIG_RTL8192E)
  1089. void fill_tx_desc_8192e(PADAPTER padapter)
  1090. {
  1091. struct mp_priv *pmp_priv = &padapter->mppriv;
  1092. struct tx_desc *desc = &(pmp_priv->tx.desc);
  1093. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1094. }
  1095. #endif
  1096. #if defined(CONFIG_RTL8723B)
  1097. void fill_tx_desc_8723b(PADAPTER padapter)
  1098. {
  1099. struct mp_priv *pmp_priv = &padapter->mppriv;
  1100. struct tx_desc *desc = &(pmp_priv->tx.desc);
  1101. struct pkt_attrib *pattrib = &(pmp_priv->tx.attrib);
  1102. PTXDESC_8723B ptxdesc;
  1103. ptxdesc->bk = 1;
  1104. ptxdesc->macid = pattrib->mac_id;
  1105. ptxdesc->qsel = pattrib->qsel;
  1106. ptxdesc->rate_id = pattrib->raid;
  1107. ptxdesc->seq = pattrib->seqnum;
  1108. ptxdesc->hwseq_sel = 2;
  1109. ptxdesc->userate = 1;
  1110. ptxdesc->disdatafb = 1;
  1111. if( pmp_priv->preamble ){
  1112. if (pmp_priv->rateidx <= MPT_RATE_54M)
  1113. ptxdesc->data_short = 1;
  1114. }
  1115. if (pmp_priv->bandwidth == CHANNEL_WIDTH_40)
  1116. ptxdesc->data_bw = 1;
  1117. ptxdesc->datarate = pmp_priv->rateidx;
  1118. ptxdesc->data_ratefb_lmt = 0x1F;
  1119. ptxdesc->rts_ratefb_lmt = 0xF;
  1120. }
  1121. #endif
  1122. void SetPacketTx(PADAPTER padapter)
  1123. {
  1124. u8 *ptr, *pkt_start, *pkt_end;
  1125. u32 pkt_size,offset;
  1126. struct tx_desc *desc;
  1127. struct rtw_ieee80211_hdr *hdr;
  1128. u8 payload;
  1129. s32 bmcast;
  1130. struct pkt_attrib *pattrib;
  1131. struct mp_priv *pmp_priv;
  1132. pmp_priv = &padapter->mppriv;
  1133. if (pmp_priv->tx.stop) return;
  1134. pmp_priv->tx.sended = 0;
  1135. pmp_priv->tx.stop = 0;
  1136. pmp_priv->tx_pktcount = 0;
  1137. //3 1. update_attrib()
  1138. pattrib = &pmp_priv->tx.attrib;
  1139. _rtw_memcpy(pattrib->src, padapter->eeprompriv.mac_addr, ETH_ALEN);
  1140. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  1141. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  1142. bmcast = IS_MCAST(pattrib->ra);
  1143. if (bmcast) {
  1144. pattrib->mac_id = 1;
  1145. pattrib->psta = rtw_get_bcmc_stainfo(padapter);
  1146. } else {
  1147. pattrib->mac_id = 0;
  1148. pattrib->psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
  1149. }
  1150. pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->pktlen;
  1151. //3 2. allocate xmit buffer
  1152. pkt_size = pattrib->last_txcmdsz;
  1153. if (pmp_priv->tx.pallocated_buf)
  1154. rtw_mfree(pmp_priv->tx.pallocated_buf, pmp_priv->tx.buf_size);
  1155. pmp_priv->tx.write_size = pkt_size;
  1156. pmp_priv->tx.buf_size = pkt_size + XMITBUF_ALIGN_SZ;
  1157. pmp_priv->tx.pallocated_buf = rtw_zmalloc(pmp_priv->tx.buf_size);
  1158. if (pmp_priv->tx.pallocated_buf == NULL) {
  1159. DBG_871X("%s: malloc(%d) fail!!\n", __func__, pmp_priv->tx.buf_size);
  1160. return;
  1161. }
  1162. pmp_priv->tx.buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pmp_priv->tx.pallocated_buf), XMITBUF_ALIGN_SZ);
  1163. ptr = pmp_priv->tx.buf;
  1164. desc = &(pmp_priv->tx.desc);
  1165. _rtw_memset(desc, 0, TXDESC_SIZE);
  1166. pkt_start = ptr;
  1167. pkt_end = pkt_start + pkt_size;
  1168. //3 3. init TX descriptor
  1169. #if defined(CONFIG_RTL8192C) || defined(CONFIG_RTL8192D)
  1170. if(IS_HARDWARE_TYPE_8192C(padapter) ||IS_HARDWARE_TYPE_8192D(padapter))
  1171. fill_tx_desc_8192cd(padapter);
  1172. #endif
  1173. #if defined(CONFIG_RTL8188E)
  1174. if(IS_HARDWARE_TYPE_8188E(padapter))
  1175. fill_tx_desc_8188e(padapter);
  1176. #endif
  1177. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  1178. if(IS_HARDWARE_TYPE_8812(padapter))
  1179. fill_tx_desc_8812a(padapter);
  1180. #endif
  1181. #if defined(CONFIG_RTL8192E)
  1182. if(IS_HARDWARE_TYPE_8188E(padapter))
  1183. fill_tx_desc_8192e(padapter);
  1184. #endif
  1185. #if defined(CONFIG_RTL8723B)
  1186. if(IS_HARDWARE_TYPE_8723B(padapter))
  1187. fill_tx_desc_8723b(padapter);
  1188. #endif
  1189. //3 4. make wlan header, make_wlanhdr()
  1190. hdr = (struct rtw_ieee80211_hdr *)pkt_start;
  1191. SetFrameSubType(&hdr->frame_ctl, pattrib->subtype);
  1192. _rtw_memcpy(hdr->addr1, pattrib->dst, ETH_ALEN); // DA
  1193. _rtw_memcpy(hdr->addr2, pattrib->src, ETH_ALEN); // SA
  1194. _rtw_memcpy(hdr->addr3, get_bssid(&padapter->mlmepriv), ETH_ALEN); // RA, BSSID
  1195. //3 5. make payload
  1196. ptr = pkt_start + pattrib->hdrlen;
  1197. switch (pmp_priv->tx.payload) {
  1198. case 0:
  1199. payload = 0x00;
  1200. break;
  1201. case 1:
  1202. payload = 0x5a;
  1203. break;
  1204. case 2:
  1205. payload = 0xa5;
  1206. break;
  1207. case 3:
  1208. payload = 0xff;
  1209. break;
  1210. default:
  1211. payload = 0x00;
  1212. break;
  1213. }
  1214. _rtw_memset(ptr, payload, pkt_end - ptr);
  1215. //3 6. start thread
  1216. #ifdef PLATFORM_LINUX
  1217. pmp_priv->tx.PktTxThread = kthread_run(mp_xmit_packet_thread, pmp_priv, "RTW_MP_THREAD");
  1218. if (IS_ERR(pmp_priv->tx.PktTxThread))
  1219. DBG_871X("Create PktTx Thread Fail !!!!!\n");
  1220. #endif
  1221. #ifdef PLATFORM_FREEBSD
  1222. {
  1223. struct proc *p;
  1224. struct thread *td;
  1225. pmp_priv->tx.PktTxThread = kproc_kthread_add(mp_xmit_packet_thread, pmp_priv,
  1226. &p, &td, RFHIGHPID, 0, "MPXmitThread", "MPXmitThread");
  1227. if (pmp_priv->tx.PktTxThread < 0)
  1228. DBG_871X("Create PktTx Thread Fail !!!!!\n");
  1229. }
  1230. #endif
  1231. }
  1232. void SetPacketRx(PADAPTER pAdapter, u8 bStartRx)
  1233. {
  1234. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1235. if(bStartRx)
  1236. {
  1237. // Accept CRC error and destination address
  1238. #if 1
  1239. //ndef CONFIG_RTL8723A
  1240. pHalData->ReceiveConfig = AAP | APM | AM | AB | APP_ICV | ADF | AMF | HTC_LOC_CTRL | APP_MIC | APP_PHYSTS;
  1241. pHalData->ReceiveConfig |= ACRC32;
  1242. rtw_write32(pAdapter, REG_RCR, pHalData->ReceiveConfig);
  1243. // Accept all data frames
  1244. rtw_write16(pAdapter, REG_RXFLTMAP2, 0xFFFF);
  1245. #else
  1246. rtw_write32(pAdapter, REG_RCR, 0x70000101);
  1247. #endif
  1248. }
  1249. else
  1250. {
  1251. rtw_write32(pAdapter, REG_RCR, 0);
  1252. }
  1253. }
  1254. void ResetPhyRxPktCount(PADAPTER pAdapter)
  1255. {
  1256. u32 i, phyrx_set = 0;
  1257. for (i = 0; i <= 0xF; i++) {
  1258. phyrx_set = 0;
  1259. phyrx_set |= _RXERR_RPT_SEL(i); //select
  1260. phyrx_set |= RXERR_RPT_RST; // set counter to zero
  1261. rtw_write32(pAdapter, REG_RXERR_RPT, phyrx_set);
  1262. }
  1263. }
  1264. static u32 GetPhyRxPktCounts(PADAPTER pAdapter, u32 selbit)
  1265. {
  1266. //selection
  1267. u32 phyrx_set = 0, count = 0;
  1268. phyrx_set = _RXERR_RPT_SEL(selbit & 0xF);
  1269. rtw_write32(pAdapter, REG_RXERR_RPT, phyrx_set);
  1270. //Read packet count
  1271. count = rtw_read32(pAdapter, REG_RXERR_RPT) & RXERR_COUNTER_MASK;
  1272. return count;
  1273. }
  1274. u32 GetPhyRxPktReceived(PADAPTER pAdapter)
  1275. {
  1276. u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
  1277. OFDM_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_OFDM_MPDU_OK);
  1278. CCK_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_CCK_MPDU_OK);
  1279. HT_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_HT_MPDU_OK);
  1280. return OFDM_cnt + CCK_cnt + HT_cnt;
  1281. }
  1282. u32 GetPhyRxPktCRC32Error(PADAPTER pAdapter)
  1283. {
  1284. u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
  1285. OFDM_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_OFDM_MPDU_FAIL);
  1286. CCK_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_CCK_MPDU_FAIL);
  1287. HT_cnt = GetPhyRxPktCounts(pAdapter, RXERR_TYPE_HT_MPDU_FAIL);
  1288. return OFDM_cnt + CCK_cnt + HT_cnt;
  1289. }
  1290. //reg 0x808[9:0]: FFT data x
  1291. //reg 0x808[22]: 0 --> 1 to get 1 FFT data y
  1292. //reg 0x8B4[15:0]: FFT data y report
  1293. static u32 rtw_GetPSDData(PADAPTER pAdapter, u32 point)
  1294. {
  1295. u32 psd_val=0;
  1296. #if defined(CONFIG_RTL8812A) //MP PSD for 8812A
  1297. u16 psd_reg = 0x910;
  1298. u16 psd_regL= 0xF44;
  1299. #else
  1300. u16 psd_reg = 0x808;
  1301. u16 psd_regL= 0x8B4;
  1302. #endif
  1303. psd_val = rtw_read32(pAdapter, psd_reg);
  1304. psd_val &= 0xFFBFFC00;
  1305. psd_val |= point;
  1306. rtw_write32(pAdapter, psd_reg, psd_val);
  1307. rtw_mdelay_os(1);
  1308. psd_val |= 0x00400000;
  1309. rtw_write32(pAdapter, psd_reg, psd_val);
  1310. rtw_mdelay_os(1);
  1311. psd_val = rtw_read32(pAdapter, psd_regL);
  1312. psd_val &= 0x0000FFFF;
  1313. return psd_val;
  1314. }
  1315. /*
  1316. * pts start_point_min stop_point_max
  1317. * 128 64 64 + 128 = 192
  1318. * 256 128 128 + 256 = 384
  1319. * 512 256 256 + 512 = 768
  1320. * 1024 512 512 + 1024 = 1536
  1321. *
  1322. */
  1323. u32 mp_query_psd(PADAPTER pAdapter, u8 *data)
  1324. {
  1325. u32 i, psd_pts=0, psd_start=0, psd_stop=0;
  1326. u32 psd_data=0;
  1327. #ifdef PLATFORM_LINUX
  1328. if (!netif_running(pAdapter->pnetdev)) {
  1329. RT_TRACE(_module_mp_, _drv_warning_, ("mp_query_psd: Fail! interface not opened!\n"));
  1330. return 0;
  1331. }
  1332. #endif
  1333. if (check_fwstate(&pAdapter->mlmepriv, WIFI_MP_STATE) == _FALSE) {
  1334. RT_TRACE(_module_mp_, _drv_warning_, ("mp_query_psd: Fail! not in MP mode!\n"));
  1335. return 0;
  1336. }
  1337. if (strlen(data) == 0) { //default value
  1338. psd_pts = 128;
  1339. psd_start = 64;
  1340. psd_stop = 128;
  1341. } else {
  1342. sscanf(data, "pts=%d,start=%d,stop=%d", &psd_pts, &psd_start, &psd_stop);
  1343. }
  1344. _rtw_memset(data, '\0', sizeof(data));
  1345. i = psd_start;
  1346. while (i < psd_stop)
  1347. {
  1348. if (i >= psd_pts) {
  1349. psd_data = rtw_GetPSDData(pAdapter, i-psd_pts);
  1350. } else {
  1351. psd_data = rtw_GetPSDData(pAdapter, i);
  1352. }
  1353. sprintf(data, "%s%x ", data, psd_data);
  1354. i++;
  1355. }
  1356. #ifdef CONFIG_LONG_DELAY_ISSUE
  1357. rtw_msleep_os(100);
  1358. #else
  1359. rtw_mdelay_os(100);
  1360. #endif
  1361. return strlen(data)+1;
  1362. }
  1363. void _rtw_mp_xmit_priv (struct xmit_priv *pxmitpriv)
  1364. {
  1365. int i,res;
  1366. _adapter *padapter = pxmitpriv->adapter;
  1367. struct xmit_frame *pxmitframe = (struct xmit_frame*) pxmitpriv->pxmit_frame_buf;
  1368. struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
  1369. u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  1370. u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
  1371. if(padapter->registrypriv.mp_mode ==0)
  1372. {
  1373. max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  1374. num_xmit_extbuf = NR_XMIT_EXTBUFF;
  1375. }
  1376. else
  1377. {
  1378. max_xmit_extbuf_size = 20000;
  1379. num_xmit_extbuf = 1;
  1380. }
  1381. pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
  1382. for(i=0; i<num_xmit_extbuf; i++)
  1383. {
  1384. rtw_os_xmit_resource_free(padapter, pxmitbuf,(max_xmit_extbuf_size + XMITBUF_ALIGN_SZ), _FALSE);
  1385. pxmitbuf++;
  1386. }
  1387. if(pxmitpriv->pallocated_xmit_extbuf) {
  1388. rtw_vmfree(pxmitpriv->pallocated_xmit_extbuf, num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
  1389. }
  1390. if(padapter->registrypriv.mp_mode ==0)
  1391. {
  1392. max_xmit_extbuf_size = 20000;
  1393. num_xmit_extbuf = 1;
  1394. }
  1395. else
  1396. {
  1397. max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  1398. num_xmit_extbuf = NR_XMIT_EXTBUFF;
  1399. }
  1400. // Init xmit extension buff
  1401. _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
  1402. pxmitpriv->pallocated_xmit_extbuf = rtw_zvmalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
  1403. if (pxmitpriv->pallocated_xmit_extbuf == NULL){
  1404. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("alloc xmit_extbuf fail!\n"));
  1405. res= _FAIL;
  1406. goto exit;
  1407. }
  1408. pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmit_extbuf), 4);
  1409. pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
  1410. for (i = 0; i < num_xmit_extbuf; i++)
  1411. {
  1412. _rtw_init_listhead(&pxmitbuf->list);
  1413. pxmitbuf->priv_data = NULL;
  1414. pxmitbuf->padapter = padapter;
  1415. pxmitbuf->buf_tag = XMITBUF_MGNT;
  1416. if((res=rtw_os_xmit_resource_alloc(padapter, pxmitbuf,max_xmit_extbuf_size + XMITBUF_ALIGN_SZ, _FALSE)) == _FAIL) {
  1417. res= _FAIL;
  1418. goto exit;
  1419. }
  1420. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1421. pxmitbuf->phead = pxmitbuf->pbuf;
  1422. pxmitbuf->pend = pxmitbuf->pbuf + max_xmit_extbuf_size;
  1423. pxmitbuf->len = 0;
  1424. pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
  1425. #endif
  1426. rtw_list_insert_tail(&pxmitbuf->list, &(pxmitpriv->free_xmit_extbuf_queue.queue));
  1427. #ifdef DBG_XMIT_BUF_EXT
  1428. pxmitbuf->no=i;
  1429. #endif
  1430. pxmitbuf++;
  1431. }
  1432. pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
  1433. exit:
  1434. ;
  1435. }
  1436. ULONG getPowerDiffByRate8188E(
  1437. IN PADAPTER pAdapter,
  1438. IN u1Byte CurrChannel,
  1439. IN ULONG RfPath
  1440. )
  1441. {
  1442. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1443. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1444. ULONG PwrGroup=0;
  1445. ULONG TxPower=0, Limit=0;
  1446. ULONG Pathmapping = (RfPath == ODM_RF_PATH_A?0:8);
  1447. switch(pHalData->EEPROMRegulatory)
  1448. {
  1449. case 0: // driver-defined maximum power offset for longer communication range
  1450. // refer to power by rate table
  1451. PwrGroup = 0;
  1452. Limit = 0xff;
  1453. break;
  1454. case 1: // Power-limit table-defined maximum power offset range
  1455. // choosed by min(power by rate, power limit).
  1456. {
  1457. if(pHalData->pwrGroupCnt == 1)
  1458. PwrGroup = 0;
  1459. if(pHalData->pwrGroupCnt >= 3)
  1460. {
  1461. if(CurrChannel <= 3)
  1462. PwrGroup = 0;
  1463. else if(CurrChannel >= 4 && CurrChannel <= 9)
  1464. PwrGroup = 1;
  1465. else if(CurrChannel > 9)
  1466. PwrGroup = 2;
  1467. if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
  1468. PwrGroup++;
  1469. else
  1470. PwrGroup+=4;
  1471. }
  1472. Limit = 0xff;
  1473. }
  1474. break;
  1475. case 2: // not support power offset by rate.
  1476. // don't increase any power diff
  1477. PwrGroup = 0;
  1478. Limit = 0;
  1479. break;
  1480. default:
  1481. PwrGroup = 0;
  1482. Limit = 0xff;
  1483. break;
  1484. }
  1485. {
  1486. switch(pMptCtx->MptRateIndex)
  1487. {
  1488. case MPT_RATE_1M:
  1489. case MPT_RATE_2M:
  1490. case MPT_RATE_55M:
  1491. case MPT_RATE_11M:
  1492. //CCK rates, don't add any tx power index.
  1493. //RT_DISP(FPHY, PHY_TXPWR,("CCK rates!\n"));
  1494. break;
  1495. case MPT_RATE_6M: //0xe00 [31:0] = 18M,12M,09M,06M
  1496. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff);
  1497. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 6M, TxPower = %d\n",
  1498. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1499. break;
  1500. case MPT_RATE_9M:
  1501. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff00)>>8);
  1502. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 9M, TxPower = %d\n",
  1503. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1504. break;
  1505. case MPT_RATE_12M:
  1506. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff0000)>>16);
  1507. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 12M, TxPower = %d\n",
  1508. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1509. break;
  1510. case MPT_RATE_18M:
  1511. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0+Pathmapping])&0xff000000)>>24);
  1512. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x, OFDM 24M, TxPower = %d\n",
  1513. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][0], TxPower));
  1514. break;
  1515. case MPT_RATE_24M: //0xe04[31:0] = 54M,48M,36M,24M
  1516. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff);
  1517. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 24M, TxPower = %d\n",
  1518. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1519. break;
  1520. case MPT_RATE_36M:
  1521. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff00)>>8);
  1522. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 36M, TxPower = %d\n",
  1523. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1524. break;
  1525. case MPT_RATE_48M:
  1526. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff0000)>>16);
  1527. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 48M, TxPower = %d\n",
  1528. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1529. break;
  1530. case MPT_RATE_54M:
  1531. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1+Pathmapping])&0xff000000)>>24);
  1532. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x, OFDM 54M, TxPower = %d\n",
  1533. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][1], TxPower));
  1534. break;
  1535. case MPT_RATE_MCS0: //0xe10[31:0]= MCS=03,02,01,00
  1536. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff);
  1537. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS0, TxPower = %d\n",
  1538. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1539. break;
  1540. case MPT_RATE_MCS1:
  1541. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff00)>>8);
  1542. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS1, TxPower = %d\n",
  1543. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1544. break;
  1545. case MPT_RATE_MCS2:
  1546. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff0000)>>16);
  1547. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS2, TxPower = %d\n",
  1548. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1549. break;
  1550. case MPT_RATE_MCS3:
  1551. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2+Pathmapping])&0xff000000)>>24);
  1552. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x, MCS3, TxPower = %d\n",
  1553. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][2], TxPower));
  1554. break;
  1555. case MPT_RATE_MCS4: //0xe14[31:0]= MCS=07,06,05,04
  1556. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff);
  1557. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS4, TxPower = %d\n",
  1558. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1559. break;
  1560. case MPT_RATE_MCS5:
  1561. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff00)>>8);
  1562. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS5, TxPower = %d\n",
  1563. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1564. break;
  1565. case MPT_RATE_MCS6:
  1566. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff0000)>>16);
  1567. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS6, TxPower = %d\n",
  1568. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1569. break;
  1570. case MPT_RATE_MCS7:
  1571. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3+Pathmapping])&0xff000000)>>24);
  1572. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x, MCS7, TxPower = %d\n",
  1573. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][3], TxPower));
  1574. break;
  1575. case MPT_RATE_MCS8: //0xe18[31:0]= MCS=11,10,09,08
  1576. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff);
  1577. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS8, TxPower = %d\n",
  1578. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1579. break;
  1580. case MPT_RATE_MCS9:
  1581. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff00)>>8);
  1582. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS9, TxPower = %d\n",
  1583. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1584. break;
  1585. case MPT_RATE_MCS10:
  1586. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff0000)>>16);
  1587. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS10, TxPower = %d\n",
  1588. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1589. break;
  1590. case MPT_RATE_MCS11:
  1591. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4+Pathmapping])&0xff000000)>>24);
  1592. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x, MCS11, TxPower = %d\n",
  1593. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][4], TxPower));
  1594. break;
  1595. case MPT_RATE_MCS12: //0xe1c[31:0]= MCS=15,14,13,12
  1596. TxPower += ((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff);
  1597. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS12, TxPower = %d\n",
  1598. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1599. break;
  1600. case MPT_RATE_MCS13:
  1601. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff00)>>8);
  1602. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS13, TxPower = %d\n",
  1603. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1604. break;
  1605. case MPT_RATE_MCS14:
  1606. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff0000)>>16);
  1607. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS14, TxPower = %d\n",
  1608. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1609. break;
  1610. case MPT_RATE_MCS15:
  1611. TxPower += (((pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5+Pathmapping])&0xff000000)>>24);
  1612. //RT_DISP(FPHY, PHY_TXPWR,("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x, MCS15, TxPower = %d\n",
  1613. // PwrGroup, pHalData->MCSTxPowerLevelOriginalOffset[PwrGroup][5], TxPower));
  1614. break;
  1615. default:
  1616. break;
  1617. }
  1618. }
  1619. if(TxPower > Limit)
  1620. TxPower = Limit;
  1621. return TxPower;
  1622. }
  1623. static ULONG
  1624. mpt_ProQueryCalTxPower_8188E(
  1625. IN PADAPTER pAdapter,
  1626. IN u1Byte RfPath
  1627. )
  1628. {
  1629. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1630. u1Byte TxCount=TX_1S, i = 0; //default set to 1S
  1631. //PMGNT_INFO pMgntInfo = &(pAdapter->MgntInfo);
  1632. ULONG TxPower = 1, PwrGroup=0, PowerDiffByRate=0;
  1633. ULONG TxPowerCCK = 1, TxPowerOFDM = 1, TxPowerBW20 = 1, TxPowerBW40 = 1 ;
  1634. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1635. u1Byte CurrChannel = pHalData->CurrentChannel;
  1636. u1Byte index = (CurrChannel -1);
  1637. u1Byte rf_path=(RfPath), rfPath;
  1638. u1Byte limit = 0, rate = 0;
  1639. if(HAL_IsLegalChannel(pAdapter, CurrChannel) == FALSE)
  1640. {
  1641. CurrChannel = 1;
  1642. }
  1643. if( pMptCtx->MptRateIndex >= MPT_RATE_1M &&
  1644. pMptCtx->MptRateIndex <= MPT_RATE_11M )
  1645. {
  1646. TxPower = pHalData->Index24G_CCK_Base[rf_path][index];
  1647. }
  1648. else if(pMptCtx->MptRateIndex >= MPT_RATE_6M &&
  1649. pMptCtx->MptRateIndex <= MPT_RATE_54M )
  1650. {
  1651. TxPower = pHalData->Index24G_BW40_Base[rf_path][index];
  1652. }
  1653. else if(pMptCtx->MptRateIndex >= MPT_RATE_MCS0 &&
  1654. pMptCtx->MptRateIndex <= MPT_RATE_MCS7 )
  1655. {
  1656. TxPower = pHalData->Index24G_BW40_Base[rf_path][index];
  1657. }
  1658. //RT_DISP(FPHY, PHY_TXPWR, ("HT40 rate(%d) Tx power(RF-%c) = 0x%x\n", pMptCtx->MptRateIndex, ((rf_path==0)?'A':'B'), TxPower));
  1659. if(pMptCtx->MptRateIndex >= MPT_RATE_6M &&
  1660. pMptCtx->MptRateIndex <= MPT_RATE_54M )
  1661. {
  1662. TxPower += pHalData->OFDM_24G_Diff[rf_path][TxCount];
  1663. ///RT_DISP(FPHY, PHY_TXPWR, ("+OFDM_PowerDiff(RF-%c) = 0x%x\n", ((rf_path==0)?'A':'B'),
  1664. // pHalData->OFDM_24G_Diff[rf_path][TxCount]));
  1665. }
  1666. if(pMptCtx->MptRateIndex >= MPT_RATE_MCS0)
  1667. {
  1668. if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
  1669. {
  1670. TxPower += pHalData->BW20_24G_Diff[rf_path][TxCount];
  1671. // RT_DISP(FPHY, PHY_TXPWR, ("+HT20_PowerDiff(RF-%c) = 0x%x\n", ((rf_path==0)?'A':'B'),
  1672. // pHalData->BW20_24G_Diff[rf_path][TxCount]));
  1673. }
  1674. }
  1675. #ifdef ENABLE_POWER_BY_RATE
  1676. PowerDiffByRate = getPowerDiffByRate8188E(pAdapter, CurrChannel, RfPath);
  1677. #else
  1678. PowerDiffByRate = 0;
  1679. #endif
  1680. //RT_DISP(FPHY, PHY_TXPWR, ("+PowerDiffByRate(RF-%c) = 0x%x\n", ((rf_path==0)?'A':'B'),
  1681. // PowerDiffByRate));
  1682. TxPower += PowerDiffByRate;
  1683. // RT_DISP(FPHY, PHY_TXPWR, ("Final TxPower(RF-%c) = %d(0x%x)\n", ((rf_path==0)?'A':'B'),
  1684. // TxPower, TxPower));
  1685. /*
  1686. if(TxPower > 0x3f)
  1687. TxPower = 0x3f;
  1688. */
  1689. // 2012/11/02 Awk: add power limit mechansim
  1690. if( pMptCtx->MptRateIndex >= MPT_RATE_1M &&
  1691. pMptCtx->MptRateIndex <= MPT_RATE_11M )
  1692. {
  1693. rate = MGN_1M;
  1694. }
  1695. else if(pMptCtx->MptRateIndex >= MPT_RATE_6M &&
  1696. pMptCtx->MptRateIndex <= MPT_RATE_54M )
  1697. {
  1698. rate = MGN_54M;
  1699. }
  1700. else if(pMptCtx->MptRateIndex >= MPT_RATE_MCS0 &&
  1701. pMptCtx->MptRateIndex <= MPT_RATE_MCS7 )
  1702. {
  1703. rate = MGN_MCS7;
  1704. }
  1705. #ifdef CONFIG_8192E
  1706. limit = PHY_GetPowerLimitValue(pAdapter, pMptCtx->RegTxPwrLimit,
  1707. pHalData->CurrentBandType,
  1708. pHalData->CurrentChannelBW,RfPath,
  1709. rate, CurrChannel);
  1710. #endif
  1711. TxPower = TxPower > limit ? limit : TxPower;
  1712. return TxPower;
  1713. }
  1714. ULONG mpt_ProQueryCalTxPower(
  1715. PADAPTER pAdapter,
  1716. u8 RfPath
  1717. )
  1718. {
  1719. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1720. ULONG TxPower = 1, PwrGroup=0, PowerDiffByRate=0;
  1721. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1722. u1Byte limit = 0, rate = 0;
  1723. rate=pMptCtx->MptRateIndex;
  1724. if ( IS_HARDWARE_TYPE_8188E(pAdapter) || IS_HARDWARE_TYPE_8192E(pAdapter) )//|| IS_HARDWARE_TYPE_8723B(pAdapter))
  1725. {
  1726. return mpt_ProQueryCalTxPower_8188E(pAdapter, RfPath);
  1727. }
  1728. else
  1729. {
  1730. #ifdef CONFIG_8812A
  1731. TxPower = PHY_GetTxPowerIndex_8812A(pAdapter, RfPath, rate,pHalData->CurrentChannelBW, pHalData->CurrentChannel);
  1732. #endif
  1733. return TxPower;
  1734. }
  1735. }
  1736. void Hal_ProSetCrystalCap (PADAPTER pAdapter , u32 CrystalCapVal)
  1737. {
  1738. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1739. CrystalCapVal = pHalData->CrystalCap & 0x3F;
  1740. if(IS_HARDWARE_TYPE_8192D(pAdapter))
  1741. {
  1742. PHY_SetBBReg(pAdapter, REG_AFE_XTAL_CTRL, 0xF0, CrystalCapVal & 0x0F);
  1743. PHY_SetBBReg(pAdapter, REG_AFE_PLL_CTRL, 0xF0000000, (CrystalCapVal & 0xF0) >> 4);
  1744. }
  1745. else if(IS_HARDWARE_TYPE_8188E(pAdapter))
  1746. {
  1747. // write 0x24[16:11] = 0x24[22:17] = CrystalCap
  1748. PHY_SetBBReg(pAdapter, REG_AFE_XTAL_CTRL, 0x7FF800, (CrystalCapVal | (CrystalCapVal << 6)));
  1749. }
  1750. else if(IS_HARDWARE_TYPE_8812(pAdapter))
  1751. {
  1752. // write 0x2C[30:25] = 0x2C[24:19] = CrystalCap
  1753. PHY_SetBBReg(pAdapter, REG_MAC_PHY_CTRL, 0x7FF80000, (CrystalCapVal | (CrystalCapVal << 6)));
  1754. }
  1755. else if(IS_HARDWARE_TYPE_8821(pAdapter) || IS_HARDWARE_TYPE_8192E(pAdapter))
  1756. {
  1757. // write 0x2C[23:18] = 0x2C[17:12] = CrystalCap
  1758. PHY_SetBBReg(pAdapter, REG_MAC_PHY_CTRL, 0xFFF000, (CrystalCapVal | (CrystalCapVal << 6)));
  1759. }
  1760. else
  1761. {
  1762. PHY_SetBBReg(pAdapter, 0x2c, 0xFFF000, (CrystalCapVal | (CrystalCapVal << 6)));
  1763. }
  1764. }
  1765. #endif