hal_intf.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 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 _HAL_INTF_C_
  21. #include <drv_types.h>
  22. void rtw_hal_chip_configure(_adapter *padapter)
  23. {
  24. if(padapter->HalFunc.intf_chip_configure)
  25. padapter->HalFunc.intf_chip_configure(padapter);
  26. }
  27. void rtw_hal_read_chip_info(_adapter *padapter)
  28. {
  29. if(padapter->HalFunc.read_adapter_info)
  30. padapter->HalFunc.read_adapter_info(padapter);
  31. }
  32. void rtw_hal_read_chip_version(_adapter *padapter)
  33. {
  34. if(padapter->HalFunc.read_chip_version)
  35. padapter->HalFunc.read_chip_version(padapter);
  36. }
  37. void rtw_hal_def_value_init(_adapter *padapter)
  38. {
  39. if(padapter->HalFunc.init_default_value)
  40. padapter->HalFunc.init_default_value(padapter);
  41. }
  42. void rtw_hal_free_data(_adapter *padapter)
  43. {
  44. if(padapter->HalFunc.free_hal_data)
  45. padapter->HalFunc.free_hal_data(padapter);
  46. }
  47. void rtw_hal_dm_init(_adapter *padapter)
  48. {
  49. if(padapter->HalFunc.dm_init)
  50. padapter->HalFunc.dm_init(padapter);
  51. }
  52. void rtw_hal_dm_deinit(_adapter *padapter)
  53. {
  54. // cancel dm timer
  55. if(padapter->HalFunc.dm_deinit)
  56. padapter->HalFunc.dm_deinit(padapter);
  57. }
  58. void rtw_hal_sw_led_init(_adapter *padapter)
  59. {
  60. if(padapter->HalFunc.InitSwLeds)
  61. padapter->HalFunc.InitSwLeds(padapter);
  62. }
  63. void rtw_hal_sw_led_deinit(_adapter *padapter)
  64. {
  65. if(padapter->HalFunc.DeInitSwLeds)
  66. padapter->HalFunc.DeInitSwLeds(padapter);
  67. }
  68. u32 rtw_hal_power_on(_adapter *padapter)
  69. {
  70. if(padapter->HalFunc.hal_power_on)
  71. return padapter->HalFunc.hal_power_on(padapter);
  72. return _FAIL;
  73. }
  74. uint rtw_hal_init(_adapter *padapter)
  75. {
  76. uint status = _SUCCESS;
  77. #ifdef CONFIG_DUALMAC_CONCURRENT
  78. if(padapter->hw_init_completed == _TRUE)
  79. {
  80. DBG_871X("rtw_hal_init: hw_init_completed == _TRUE\n");
  81. return status;
  82. }
  83. // before init mac0, driver must init mac1 first to avoid usb rx error.
  84. if((padapter->pbuddy_adapter != NULL) && (padapter->DualMacConcurrent == _TRUE)
  85. && (padapter->adapter_type == PRIMARY_ADAPTER))
  86. {
  87. if(padapter->pbuddy_adapter->hw_init_completed == _TRUE)
  88. {
  89. DBG_871X("rtw_hal_init: pbuddy_adapter hw_init_completed == _TRUE\n");
  90. }
  91. else
  92. {
  93. status = padapter->HalFunc.hal_init(padapter->pbuddy_adapter);
  94. if(status == _SUCCESS){
  95. padapter->pbuddy_adapter->hw_init_completed = _TRUE;
  96. }
  97. else{
  98. padapter->pbuddy_adapter->hw_init_completed = _FALSE;
  99. RT_TRACE(_module_hal_init_c_,_drv_err_,("rtw_hal_init: hal__init fail(pbuddy_adapter)\n"));
  100. DBG_871X("rtw_hal_init: hal__init fail(pbuddy_adapter)\n");
  101. return status;
  102. }
  103. }
  104. }
  105. #endif
  106. padapter->hw_init_completed=_FALSE;
  107. status = padapter->HalFunc.hal_init(padapter);
  108. if(status == _SUCCESS){
  109. padapter->hw_init_completed = _TRUE;
  110. if (padapter->registrypriv.notch_filter == 1)
  111. rtw_hal_notch_filter(padapter, 1);
  112. rtw_hal_reset_security_engine(padapter);
  113. rtw_led_control(padapter, LED_CTL_POWER_ON);
  114. }
  115. else{
  116. padapter->hw_init_completed = _FALSE;
  117. DBG_871X("rtw_hal_init: hal__init fail\n");
  118. }
  119. RT_TRACE(_module_hal_init_c_,_drv_err_,("-rtl871x_hal_init:status=0x%x\n",status));
  120. return status;
  121. }
  122. uint rtw_hal_deinit(_adapter *padapter)
  123. {
  124. uint status = _SUCCESS;
  125. _func_enter_;
  126. status = padapter->HalFunc.hal_deinit(padapter);
  127. if(status == _SUCCESS){
  128. rtw_led_control(padapter, LED_CTL_POWER_OFF);
  129. padapter->hw_init_completed = _FALSE;
  130. }
  131. else
  132. {
  133. DBG_871X("\n rtw_hal_deinit: hal_init fail\n");
  134. }
  135. _func_exit_;
  136. return status;
  137. }
  138. void rtw_hal_set_hwreg(_adapter *padapter, u8 variable, u8 *val)
  139. {
  140. if (padapter->HalFunc.SetHwRegHandler)
  141. padapter->HalFunc.SetHwRegHandler(padapter, variable, val);
  142. }
  143. void rtw_hal_get_hwreg(_adapter *padapter, u8 variable, u8 *val)
  144. {
  145. if (padapter->HalFunc.GetHwRegHandler)
  146. padapter->HalFunc.GetHwRegHandler(padapter, variable, val);
  147. }
  148. u8 rtw_hal_set_def_var(_adapter *padapter, HAL_DEF_VARIABLE eVariable, PVOID pValue)
  149. {
  150. if(padapter->HalFunc.SetHalDefVarHandler)
  151. return padapter->HalFunc.SetHalDefVarHandler(padapter,eVariable,pValue);
  152. return _FAIL;
  153. }
  154. u8 rtw_hal_get_def_var(_adapter *padapter, HAL_DEF_VARIABLE eVariable, PVOID pValue)
  155. {
  156. if(padapter->HalFunc.GetHalDefVarHandler)
  157. return padapter->HalFunc.GetHalDefVarHandler(padapter,eVariable,pValue);
  158. return _FAIL;
  159. }
  160. void rtw_hal_set_odm_var(_adapter *padapter, HAL_ODM_VARIABLE eVariable, PVOID pValue1,BOOLEAN bSet)
  161. {
  162. if(padapter->HalFunc.SetHalODMVarHandler)
  163. padapter->HalFunc.SetHalODMVarHandler(padapter,eVariable,pValue1,bSet);
  164. }
  165. void rtw_hal_get_odm_var(_adapter *padapter, HAL_ODM_VARIABLE eVariable, PVOID pValue1,BOOLEAN bSet)
  166. {
  167. if(padapter->HalFunc.GetHalODMVarHandler)
  168. padapter->HalFunc.GetHalODMVarHandler(padapter,eVariable,pValue1,bSet);
  169. }
  170. void rtw_hal_enable_interrupt(_adapter *padapter)
  171. {
  172. if (padapter->HalFunc.enable_interrupt)
  173. padapter->HalFunc.enable_interrupt(padapter);
  174. else
  175. DBG_871X("%s: HalFunc.enable_interrupt is NULL!\n", __FUNCTION__);
  176. }
  177. void rtw_hal_disable_interrupt(_adapter *padapter)
  178. {
  179. if (padapter->HalFunc.disable_interrupt)
  180. padapter->HalFunc.disable_interrupt(padapter);
  181. else
  182. DBG_871X("%s: HalFunc.disable_interrupt is NULL!\n", __FUNCTION__);
  183. }
  184. u32 rtw_hal_inirp_init(_adapter *padapter)
  185. {
  186. u32 rst = _FAIL;
  187. if(padapter->HalFunc.inirp_init)
  188. rst = padapter->HalFunc.inirp_init(padapter);
  189. else
  190. DBG_871X(" %s HalFunc.inirp_init is NULL!!!\n",__FUNCTION__);
  191. return rst;
  192. }
  193. u32 rtw_hal_inirp_deinit(_adapter *padapter)
  194. {
  195. if(padapter->HalFunc.inirp_deinit)
  196. return padapter->HalFunc.inirp_deinit(padapter);
  197. return _FAIL;
  198. }
  199. u8 rtw_hal_intf_ps_func(_adapter *padapter,HAL_INTF_PS_FUNC efunc_id, u8* val)
  200. {
  201. if(padapter->HalFunc.interface_ps_func)
  202. return padapter->HalFunc.interface_ps_func(padapter,efunc_id,val);
  203. return _FAIL;
  204. }
  205. s32 rtw_hal_xmitframe_enqueue(_adapter *padapter, struct xmit_frame *pxmitframe)
  206. {
  207. if(padapter->HalFunc.hal_xmitframe_enqueue)
  208. return padapter->HalFunc.hal_xmitframe_enqueue(padapter, pxmitframe);
  209. return _FALSE;
  210. }
  211. s32 rtw_hal_xmit(_adapter *padapter, struct xmit_frame *pxmitframe)
  212. {
  213. if(padapter->HalFunc.hal_xmit)
  214. return padapter->HalFunc.hal_xmit(padapter, pxmitframe);
  215. return _FALSE;
  216. }
  217. s32 rtw_hal_mgnt_xmit(_adapter *padapter, struct xmit_frame *pmgntframe)
  218. {
  219. s32 ret = _FAIL;
  220. update_mgntframe_attrib_addr(padapter, pmgntframe);
  221. if(padapter->HalFunc.mgnt_xmit)
  222. ret = padapter->HalFunc.mgnt_xmit(padapter, pmgntframe);
  223. return ret;
  224. }
  225. s32 rtw_hal_init_xmit_priv(_adapter *padapter)
  226. {
  227. if(padapter->HalFunc.init_xmit_priv != NULL)
  228. return padapter->HalFunc.init_xmit_priv(padapter);
  229. return _FAIL;
  230. }
  231. void rtw_hal_free_xmit_priv(_adapter *padapter)
  232. {
  233. if(padapter->HalFunc.free_xmit_priv != NULL)
  234. padapter->HalFunc.free_xmit_priv(padapter);
  235. }
  236. s32 rtw_hal_init_recv_priv(_adapter *padapter)
  237. {
  238. if(padapter->HalFunc.init_recv_priv)
  239. return padapter->HalFunc.init_recv_priv(padapter);
  240. return _FAIL;
  241. }
  242. void rtw_hal_free_recv_priv(_adapter *padapter)
  243. {
  244. if(padapter->HalFunc.free_recv_priv)
  245. padapter->HalFunc.free_recv_priv(padapter);
  246. }
  247. void rtw_hal_update_ra_mask(struct sta_info *psta, u8 rssi_level)
  248. {
  249. _adapter *padapter;
  250. struct mlme_priv *pmlmepriv;
  251. if(!psta)
  252. return;
  253. padapter = psta->padapter;
  254. pmlmepriv = &(padapter->mlmepriv);
  255. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  256. {
  257. add_RATid(padapter, psta, rssi_level);
  258. }
  259. else
  260. {
  261. if(padapter->HalFunc.UpdateRAMaskHandler)
  262. padapter->HalFunc.UpdateRAMaskHandler(padapter, psta->mac_id, rssi_level);
  263. }
  264. }
  265. void rtw_hal_add_ra_tid(_adapter *padapter, u32 bitmap, u8* arg, u8 rssi_level)
  266. {
  267. if(padapter->HalFunc.Add_RateATid)
  268. padapter->HalFunc.Add_RateATid(padapter, bitmap, arg, rssi_level);
  269. }
  270. #ifdef CONFIG_CONCURRENT_MODE
  271. void rtw_hal_clone_data(_adapter *dst_padapter, _adapter *src_padapter)
  272. {
  273. if(dst_padapter->HalFunc.clone_haldata)
  274. dst_padapter->HalFunc.clone_haldata(dst_padapter, src_padapter);
  275. }
  276. #endif
  277. /* Start specifical interface thread */
  278. void rtw_hal_start_thread(_adapter *padapter)
  279. {
  280. if(padapter->HalFunc.run_thread)
  281. padapter->HalFunc.run_thread(padapter);
  282. }
  283. /* Start specifical interface thread */
  284. void rtw_hal_stop_thread(_adapter *padapter)
  285. {
  286. if(padapter->HalFunc.cancel_thread)
  287. padapter->HalFunc.cancel_thread(padapter);
  288. }
  289. u32 rtw_hal_read_bbreg(_adapter *padapter, u32 RegAddr, u32 BitMask)
  290. {
  291. u32 data = 0;
  292. if(padapter->HalFunc.read_bbreg)
  293. data = padapter->HalFunc.read_bbreg(padapter, RegAddr, BitMask);
  294. return data;
  295. }
  296. void rtw_hal_write_bbreg(_adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data)
  297. {
  298. if(padapter->HalFunc.write_bbreg)
  299. padapter->HalFunc.write_bbreg(padapter, RegAddr, BitMask, Data);
  300. }
  301. u32 rtw_hal_read_rfreg(_adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask)
  302. {
  303. u32 data = 0;
  304. if( padapter->HalFunc.read_rfreg)
  305. data = padapter->HalFunc.read_rfreg(padapter, eRFPath, RegAddr, BitMask);
  306. return data;
  307. }
  308. void rtw_hal_write_rfreg(_adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
  309. {
  310. if(padapter->HalFunc.write_rfreg)
  311. padapter->HalFunc.write_rfreg(padapter, eRFPath, RegAddr, BitMask, Data);
  312. }
  313. s32 rtw_hal_interrupt_handler(_adapter *padapter)
  314. {
  315. if(padapter->HalFunc.interrupt_handler)
  316. return padapter->HalFunc.interrupt_handler(padapter);
  317. return _FAIL;
  318. }
  319. void rtw_hal_set_bwmode(_adapter *padapter, CHANNEL_WIDTH Bandwidth, u8 Offset)
  320. {
  321. if(padapter->HalFunc.set_bwmode_handler)
  322. padapter->HalFunc.set_bwmode_handler(padapter, Bandwidth, Offset);
  323. }
  324. void rtw_hal_set_chan(_adapter *padapter, u8 channel)
  325. {
  326. if(padapter->HalFunc.set_channel_handler)
  327. padapter->HalFunc.set_channel_handler(padapter, channel);
  328. }
  329. void rtw_hal_set_chnl_bw(_adapter *padapter, u8 channel, CHANNEL_WIDTH Bandwidth, u8 Offset40, u8 Offset80)
  330. {
  331. if(padapter->HalFunc.set_chnl_bw_handler)
  332. padapter->HalFunc.set_chnl_bw_handler(padapter, channel, Bandwidth, Offset40, Offset80);
  333. }
  334. void rtw_hal_dm_watchdog(_adapter *padapter)
  335. {
  336. #if defined(CONFIG_CONCURRENT_MODE)
  337. if (padapter->adapter_type != PRIMARY_ADAPTER)
  338. return;
  339. #endif
  340. if(padapter->HalFunc.hal_dm_watchdog)
  341. padapter->HalFunc.hal_dm_watchdog(padapter);
  342. }
  343. void rtw_hal_bcn_related_reg_setting(_adapter *padapter)
  344. {
  345. if(padapter->HalFunc.SetBeaconRelatedRegistersHandler)
  346. padapter->HalFunc.SetBeaconRelatedRegistersHandler(padapter);
  347. }
  348. #ifdef CONFIG_ANTENNA_DIVERSITY
  349. u8 rtw_hal_antdiv_before_linked(_adapter *padapter)
  350. {
  351. if(padapter->HalFunc.AntDivBeforeLinkHandler)
  352. return padapter->HalFunc.AntDivBeforeLinkHandler(padapter);
  353. return _FALSE;
  354. }
  355. void rtw_hal_antdiv_rssi_compared(_adapter *padapter, WLAN_BSSID_EX *dst, WLAN_BSSID_EX *src)
  356. {
  357. if(padapter->HalFunc.AntDivCompareHandler)
  358. padapter->HalFunc.AntDivCompareHandler(padapter, dst, src);
  359. }
  360. #endif
  361. #ifdef CONFIG_HOSTAPD_MLME
  362. s32 rtw_hal_hostap_mgnt_xmit_entry(_adapter *padapter, _pkt *pkt)
  363. {
  364. if(padapter->HalFunc.hostap_mgnt_xmit_entry)
  365. return padapter->HalFunc.hostap_mgnt_xmit_entry(padapter, pkt);
  366. return _FAIL;
  367. }
  368. #endif //CONFIG_HOSTAPD_MLME
  369. #ifdef DBG_CONFIG_ERROR_DETECT
  370. void rtw_hal_sreset_init(_adapter *padapter)
  371. {
  372. if(padapter->HalFunc.sreset_init_value)
  373. padapter->HalFunc.sreset_init_value(padapter);
  374. }
  375. void rtw_hal_sreset_reset(_adapter *padapter)
  376. {
  377. padapter = GET_PRIMARY_ADAPTER(padapter);
  378. if(padapter->HalFunc.silentreset)
  379. padapter->HalFunc.silentreset(padapter);
  380. }
  381. void rtw_hal_sreset_reset_value(_adapter *padapter)
  382. {
  383. if(padapter->HalFunc.sreset_reset_value)
  384. padapter->HalFunc.sreset_reset_value(padapter);
  385. }
  386. void rtw_hal_sreset_xmit_status_check(_adapter *padapter)
  387. {
  388. #ifdef CONFIG_CONCURRENT_MODE
  389. if (padapter->adapter_type != PRIMARY_ADAPTER)
  390. return;
  391. #endif
  392. if(padapter->HalFunc.sreset_xmit_status_check)
  393. padapter->HalFunc.sreset_xmit_status_check(padapter);
  394. }
  395. void rtw_hal_sreset_linked_status_check(_adapter *padapter)
  396. {
  397. if(padapter->HalFunc.sreset_linked_status_check)
  398. padapter->HalFunc.sreset_linked_status_check(padapter);
  399. }
  400. u8 rtw_hal_sreset_get_wifi_status(_adapter *padapter)
  401. {
  402. u8 status = 0;
  403. if(padapter->HalFunc.sreset_get_wifi_status)
  404. status = padapter->HalFunc.sreset_get_wifi_status(padapter);
  405. return status;
  406. }
  407. bool rtw_hal_sreset_inprogress(_adapter *padapter)
  408. {
  409. bool inprogress = _FALSE;
  410. padapter = GET_PRIMARY_ADAPTER(padapter);
  411. if(padapter->HalFunc.sreset_inprogress)
  412. inprogress = padapter->HalFunc.sreset_inprogress(padapter);
  413. return inprogress;
  414. }
  415. #endif //DBG_CONFIG_ERROR_DETECT
  416. #ifdef CONFIG_IOL
  417. int rtw_hal_iol_cmd(ADAPTER *adapter, struct xmit_frame *xmit_frame, u32 max_wating_ms, u32 bndy_cnt)
  418. {
  419. if(adapter->HalFunc.IOL_exec_cmds_sync)
  420. return adapter->HalFunc.IOL_exec_cmds_sync(adapter, xmit_frame, max_wating_ms,bndy_cnt);
  421. return _FAIL;
  422. }
  423. #endif
  424. #ifdef CONFIG_XMIT_THREAD_MODE
  425. s32 rtw_hal_xmit_thread_handler(_adapter *padapter)
  426. {
  427. if(padapter->HalFunc.xmit_thread_handler)
  428. return padapter->HalFunc.xmit_thread_handler(padapter);
  429. return _FAIL;
  430. }
  431. #endif
  432. void rtw_hal_notch_filter(_adapter *adapter, bool enable)
  433. {
  434. if(adapter->HalFunc.hal_notch_filter)
  435. adapter->HalFunc.hal_notch_filter(adapter,enable);
  436. }
  437. void rtw_hal_reset_security_engine(_adapter * adapter)
  438. {
  439. if(adapter->HalFunc.hal_reset_security_engine)
  440. adapter->HalFunc.hal_reset_security_engine(adapter);
  441. }
  442. s32 rtw_hal_c2h_handler(_adapter *adapter, struct c2h_evt_hdr *c2h_evt)
  443. {
  444. s32 ret = _FAIL;
  445. if (adapter->HalFunc.c2h_handler)
  446. ret = adapter->HalFunc.c2h_handler(adapter, c2h_evt);
  447. return ret;
  448. }
  449. c2h_id_filter rtw_hal_c2h_id_filter_ccx(_adapter *adapter)
  450. {
  451. return adapter->HalFunc.c2h_id_filter_ccx;
  452. }