hal_dm_acs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2014 - 2017 Realtek Corporation.
  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. *****************************************************************************/
  15. #include <drv_types.h>
  16. #include <hal_data.h>
  17. #if defined(CONFIG_RTW_ACS) || defined(CONFIG_BACKGROUND_NOISE_MONITOR)
  18. static void _rtw_bss_nums_count(_adapter *adapter, u8 *pbss_nums)
  19. {
  20. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  21. _queue *queue = &(pmlmepriv->scanned_queue);
  22. struct wlan_network *pnetwork = NULL;
  23. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  24. _list *plist, *phead;
  25. _irqL irqL;
  26. int chan_idx = -1;
  27. if (pbss_nums == NULL) {
  28. RTW_ERR("%s pbss_nums is null pointer\n", __func__);
  29. return;
  30. }
  31. _rtw_memset(pbss_nums, 0, MAX_CHANNEL_NUM);
  32. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  33. phead = get_list_head(queue);
  34. plist = get_next(phead);
  35. while (1) {
  36. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  37. break;
  38. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  39. if (!pnetwork)
  40. break;
  41. chan_idx = rtw_chset_search_ch(adapter_to_chset(adapter), pnetwork->network.Configuration.DSConfig);
  42. if ((chan_idx == -1) || (chan_idx >= MAX_CHANNEL_NUM)) {
  43. RTW_ERR("%s can't get chan_idx(CH:%d)\n",
  44. __func__, pnetwork->network.Configuration.DSConfig);
  45. chan_idx = 0;
  46. }
  47. /*if (pnetwork->network.Reserved[0] != BSS_TYPE_PROB_REQ)*/
  48. pbss_nums[chan_idx]++;
  49. plist = get_next(plist);
  50. }
  51. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  52. }
  53. u8 rtw_get_ch_num_by_idx(_adapter *adapter, u8 idx)
  54. {
  55. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  56. RT_CHANNEL_INFO *pch_set = rfctl->channel_set;
  57. u8 max_chan_nums = rfctl->max_chan_nums;
  58. if (idx >= max_chan_nums)
  59. return 0;
  60. return pch_set[idx].ChannelNum;
  61. }
  62. #endif /*defined(CONFIG_RTW_ACS) || defined(CONFIG_BACKGROUND_NOISE_MONITOR)*/
  63. #ifdef CONFIG_RTW_ACS
  64. void rtw_acs_version_dump(void *sel, _adapter *adapter)
  65. {
  66. _RTW_PRINT_SEL(sel, "RTK_ACS VER_%d\n", RTK_ACS_VERSION);
  67. }
  68. u8 rtw_phydm_clm_ratio(_adapter *adapter)
  69. {
  70. struct dm_struct *phydm = adapter_to_phydm(adapter);
  71. return phydm_cmn_info_query(phydm, (enum phydm_info_query) PHYDM_INFO_CLM_RATIO);
  72. }
  73. u8 rtw_phydm_nhm_ratio(_adapter *adapter)
  74. {
  75. struct dm_struct *phydm = adapter_to_phydm(adapter);
  76. return phydm_cmn_info_query(phydm, (enum phydm_info_query) PHYDM_INFO_NHM_RATIO);
  77. }
  78. void rtw_acs_reset(_adapter *adapter)
  79. {
  80. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  81. struct auto_chan_sel *pacs = &hal_data->acs;
  82. _rtw_memset(pacs, 0, sizeof(struct auto_chan_sel));
  83. #ifdef CONFIG_RTW_ACS_DBG
  84. rtw_acs_adv_reset(adapter);
  85. #endif /*CONFIG_RTW_ACS_DBG*/
  86. }
  87. #ifdef CONFIG_RTW_ACS_DBG
  88. u8 rtw_is_acs_igi_valid(_adapter *adapter)
  89. {
  90. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  91. struct auto_chan_sel *pacs = &hal_data->acs;
  92. if ((pacs->igi) && ((pacs->igi >= 0x1E) || (pacs->igi < 0x60)))
  93. return _TRUE;
  94. return _FALSE;
  95. }
  96. void rtw_acs_adv_setting(_adapter *adapter, RT_SCAN_TYPE scan_type, u16 scan_time, u8 igi, u8 bw)
  97. {
  98. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  99. struct auto_chan_sel *pacs = &hal_data->acs;
  100. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  101. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  102. pacs->scan_type = scan_type;
  103. pacs->scan_time = scan_time;
  104. pacs->igi = igi;
  105. pacs->bw = bw;
  106. RTW_INFO("[ACS] ADV setting - scan_type:%c, ch_ms:%d(ms), igi:0x%02x, bw:%d\n",
  107. pacs->scan_type ? 'A' : 'P', pacs->scan_time, pacs->igi, pacs->bw);
  108. }
  109. void rtw_acs_adv_reset(_adapter *adapter)
  110. {
  111. rtw_acs_adv_setting(adapter, SCAN_ACTIVE, 0, 0, 0);
  112. }
  113. #endif /*CONFIG_RTW_ACS_DBG*/
  114. void rtw_acs_trigger(_adapter *adapter, u16 scan_time_ms, u8 scan_chan, enum NHM_PID pid)
  115. {
  116. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  117. struct dm_struct *phydm = adapter_to_phydm(adapter);
  118. #if (RTK_ACS_VERSION == 3)
  119. struct clm_para_info clm_para;
  120. struct nhm_para_info nhm_para;
  121. struct env_trig_rpt trig_rpt;
  122. scan_time_ms -= 10;
  123. init_acs_clm(clm_para, scan_time_ms);
  124. if (pid == NHM_PID_IEEE_11K_HIGH)
  125. init_11K_high_nhm(nhm_para, scan_time_ms);
  126. else if (pid == NHM_PID_IEEE_11K_LOW)
  127. init_11K_low_nhm(nhm_para, scan_time_ms);
  128. else
  129. init_acs_nhm(nhm_para, scan_time_ms);
  130. hal_data->acs.trig_rst = phydm_env_mntr_trigger(phydm, &nhm_para, &clm_para, &trig_rpt);
  131. if (hal_data->acs.trig_rst == (NHM_SUCCESS | CLM_SUCCESS)) {
  132. hal_data->acs.trig_rpt.clm_rpt_stamp = trig_rpt.clm_rpt_stamp;
  133. hal_data->acs.trig_rpt.nhm_rpt_stamp = trig_rpt.nhm_rpt_stamp;
  134. /*RTW_INFO("[ACS] trigger success (rst = 0x%02x, clm_stamp:%d, nhm_stamp:%d)\n",
  135. hal_data->acs.trig_rst, hal_data->acs.trig_rpt.clm_rpt_stamp, hal_data->acs.trig_rpt.nhm_rpt_stamp);*/
  136. } else
  137. RTW_ERR("[ACS] trigger failed (rst = 0x%02x)\n", hal_data->acs.trig_rst);
  138. #else
  139. phydm_ccx_monitor_trigger(phydm, scan_time_ms);
  140. #endif
  141. hal_data->acs.trigger_ch = scan_chan;
  142. hal_data->acs.triggered = _TRUE;
  143. #ifdef CONFIG_RTW_ACS_DBG
  144. RTW_INFO("[ACS] Trigger CH:%d, Times:%d\n", hal_data->acs.trigger_ch, scan_time_ms);
  145. #endif
  146. }
  147. void rtw_acs_get_rst(_adapter *adapter)
  148. {
  149. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  150. struct dm_struct *phydm = adapter_to_phydm(adapter);
  151. int chan_idx = -1;
  152. u8 cur_chan = hal_data->acs.trigger_ch;
  153. if (cur_chan == 0)
  154. return;
  155. if (!hal_data->acs.triggered)
  156. return;
  157. chan_idx = rtw_chset_search_ch(adapter_to_chset(adapter), cur_chan);
  158. if ((chan_idx == -1) || (chan_idx >= MAX_CHANNEL_NUM)) {
  159. RTW_ERR("[ACS] %s can't get chan_idx(CH:%d)\n", __func__, cur_chan);
  160. return;
  161. }
  162. #if (RTK_ACS_VERSION == 3)
  163. if (!(hal_data->acs.trig_rst == (NHM_SUCCESS | CLM_SUCCESS))) {
  164. RTW_ERR("[ACS] get_rst return, due to acs trigger failed\n");
  165. return;
  166. }
  167. {
  168. struct env_mntr_rpt rpt = {0};
  169. u8 rst;
  170. rst = phydm_env_mntr_result(phydm, &rpt);
  171. if ((rst == (NHM_SUCCESS | CLM_SUCCESS)) &&
  172. (rpt.clm_rpt_stamp == hal_data->acs.trig_rpt.clm_rpt_stamp) &&
  173. (rpt.nhm_rpt_stamp == hal_data->acs.trig_rpt.nhm_rpt_stamp)){
  174. hal_data->acs.clm_ratio[chan_idx] = rpt.clm_ratio;
  175. hal_data->acs.nhm_ratio[chan_idx] = rpt.nhm_ratio;
  176. _rtw_memcpy(&hal_data->acs.nhm[chan_idx][0], rpt.nhm_result, NHM_RPT_NUM);
  177. /*RTW_INFO("[ACS] get_rst success (rst = 0x%02x, clm_stamp:%d:%d, nhm_stamp:%d:%d)\n",
  178. rst,
  179. hal_data->acs.trig_rpt.clm_rpt_stamp, rpt.clm_rpt_stamp,
  180. hal_data->acs.trig_rpt.nhm_rpt_stamp, rpt.nhm_rpt_stamp);*/
  181. } else {
  182. RTW_ERR("[ACS] get_rst failed (rst = 0x%02x, clm_stamp:%d:%d, nhm_stamp:%d:%d)\n",
  183. rst,
  184. hal_data->acs.trig_rpt.clm_rpt_stamp, rpt.clm_rpt_stamp,
  185. hal_data->acs.trig_rpt.nhm_rpt_stamp, rpt.nhm_rpt_stamp);
  186. }
  187. }
  188. #else
  189. phydm_ccx_monitor_result(phydm);
  190. hal_data->acs.clm_ratio[chan_idx] = rtw_phydm_clm_ratio(adapter);
  191. hal_data->acs.nhm_ratio[chan_idx] = rtw_phydm_nhm_ratio(adapter);
  192. #endif
  193. hal_data->acs.triggered = _FALSE;
  194. #ifdef CONFIG_RTW_ACS_DBG
  195. RTW_INFO("[ACS] Result CH:%d, CLM:%d NHM:%d\n",
  196. cur_chan, hal_data->acs.clm_ratio[chan_idx], hal_data->acs.nhm_ratio[chan_idx]);
  197. #endif
  198. }
  199. void _rtw_phydm_acs_select_best_chan(_adapter *adapter)
  200. {
  201. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  202. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  203. u8 ch_idx;
  204. u8 ch_idx_24g = 0xFF, ch_idx_5g = 0xFF;
  205. u8 min_itf_24g = 0xFF, min_itf_5g = 0xFF;
  206. u8 *pbss_nums = hal_data->acs.bss_nums;
  207. u8 *pclm_ratio = hal_data->acs.clm_ratio;
  208. u8 *pnhm_ratio = hal_data->acs.nhm_ratio;
  209. u8 *pinterference_time = hal_data->acs.interference_time;
  210. u8 max_chan_nums = rfctl->max_chan_nums;
  211. for (ch_idx = 0; ch_idx < max_chan_nums; ch_idx++) {
  212. if (pbss_nums[ch_idx])
  213. pinterference_time[ch_idx] = (pclm_ratio[ch_idx] / 2) + pnhm_ratio[ch_idx];
  214. else
  215. pinterference_time[ch_idx] = pclm_ratio[ch_idx] + pnhm_ratio[ch_idx];
  216. if (rtw_get_ch_num_by_idx(adapter, ch_idx) < 14) {
  217. if (pinterference_time[ch_idx] < min_itf_24g) {
  218. min_itf_24g = pinterference_time[ch_idx];
  219. ch_idx_24g = ch_idx;
  220. }
  221. } else {
  222. if (pinterference_time[ch_idx] < min_itf_5g) {
  223. min_itf_5g = pinterference_time[ch_idx];
  224. ch_idx_5g = ch_idx;
  225. }
  226. }
  227. }
  228. if (ch_idx_24g != 0xFF)
  229. hal_data->acs.best_chan_24g = rtw_get_ch_num_by_idx(adapter, ch_idx_24g);
  230. if (ch_idx_5g != 0xFF)
  231. hal_data->acs.best_chan_5g = rtw_get_ch_num_by_idx(adapter, ch_idx_5g);
  232. hal_data->acs.trigger_ch = 0;
  233. }
  234. void rtw_acs_info_dump(void *sel, _adapter *adapter)
  235. {
  236. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  237. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  238. u8 max_chan_nums = rfctl->max_chan_nums;
  239. u8 ch_idx, ch_num;
  240. _RTW_PRINT_SEL(sel, "========== ACS (VER-%d) ==========\n", RTK_ACS_VERSION);
  241. _RTW_PRINT_SEL(sel, "Best 24G Channel:%d\n", hal_data->acs.best_chan_24g);
  242. _RTW_PRINT_SEL(sel, "Best 5G Channel:%d\n\n", hal_data->acs.best_chan_5g);
  243. #ifdef CONFIG_RTW_ACS_DBG
  244. _RTW_PRINT_SEL(sel, "Advanced setting - scan_type:%c, ch_ms:%d(ms), igi:0x%02x, bw:%d\n",
  245. hal_data->acs.scan_type ? 'A' : 'P', hal_data->acs.scan_time, hal_data->acs.igi, hal_data->acs.bw);
  246. _RTW_PRINT_SEL(sel, "BW 20MHz\n");
  247. _RTW_PRINT_SEL(sel, "%5s %3s %3s %3s(%%) %3s(%%) %3s\n",
  248. "Index", "CH", "BSS", "CLM", "NHM", "ITF");
  249. for (ch_idx = 0; ch_idx < max_chan_nums; ch_idx++) {
  250. ch_num = rtw_get_ch_num_by_idx(adapter, ch_idx);
  251. _RTW_PRINT_SEL(sel, "%5d %3d %3d %6d %6d %3d\n",
  252. ch_idx, ch_num, hal_data->acs.bss_nums[ch_idx],
  253. hal_data->acs.clm_ratio[ch_idx],
  254. hal_data->acs.nhm_ratio[ch_idx],
  255. hal_data->acs.interference_time[ch_idx]);
  256. }
  257. #endif
  258. }
  259. void rtw_acs_select_best_chan(_adapter *adapter)
  260. {
  261. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  262. _rtw_bss_nums_count(adapter, hal_data->acs.bss_nums);
  263. _rtw_phydm_acs_select_best_chan(adapter);
  264. rtw_acs_info_dump(RTW_DBGDUMP, adapter);
  265. }
  266. void rtw_acs_start(_adapter *adapter)
  267. {
  268. rtw_acs_reset(adapter);
  269. if (GET_ACS_STATE(adapter) != ACS_ENABLE)
  270. SET_ACS_STATE(adapter, ACS_ENABLE);
  271. }
  272. void rtw_acs_stop(_adapter *adapter)
  273. {
  274. SET_ACS_STATE(adapter, ACS_DISABLE);
  275. }
  276. u8 rtw_acs_get_clm_ratio_by_ch_num(_adapter *adapter, u8 chan)
  277. {
  278. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  279. int chan_idx = -1;
  280. chan_idx = rtw_chset_search_ch(adapter_to_chset(adapter), chan);
  281. if ((chan_idx == -1) || (chan_idx >= MAX_CHANNEL_NUM)) {
  282. RTW_ERR("[ACS] Get CLM fail, can't get chan_idx(CH:%d)\n", chan);
  283. return 0;
  284. }
  285. return hal_data->acs.clm_ratio[chan_idx];
  286. }
  287. u8 rtw_acs_get_clm_ratio_by_ch_idx(_adapter *adapter, u8 ch_idx)
  288. {
  289. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  290. if (ch_idx >= MAX_CHANNEL_NUM) {
  291. RTW_ERR("%s [ACS] ch_idx(%d) is invalid\n", __func__, ch_idx);
  292. return 0;
  293. }
  294. return hal_data->acs.clm_ratio[ch_idx];
  295. }
  296. u8 rtw_acs_get_nhm_ratio_by_ch_num(_adapter *adapter, u8 chan)
  297. {
  298. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  299. int chan_idx = -1;
  300. chan_idx = rtw_chset_search_ch(adapter_to_chset(adapter), chan);
  301. if ((chan_idx == -1) || (chan_idx >= MAX_CHANNEL_NUM)) {
  302. RTW_ERR("[ACS] Get NHM fail, can't get chan_idx(CH:%d)\n", chan);
  303. return 0;
  304. }
  305. return hal_data->acs.nhm_ratio[chan_idx];
  306. }
  307. u8 rtw_acs_get_num_ratio_by_ch_idx(_adapter *adapter, u8 ch_idx)
  308. {
  309. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  310. if (ch_idx >= MAX_CHANNEL_NUM) {
  311. RTW_ERR("%s [ACS] ch_idx(%d) is invalid\n", __func__, ch_idx);
  312. return 0;
  313. }
  314. return hal_data->acs.nhm_ratio[ch_idx];
  315. }
  316. void rtw_acs_chan_info_dump(void *sel, _adapter *adapter)
  317. {
  318. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  319. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  320. u8 max_chan_nums = rfctl->max_chan_nums;
  321. u8 ch_idx, ch_num;
  322. u8 utilization;
  323. _RTW_PRINT_SEL(sel, "BW 20MHz\n");
  324. _RTW_PRINT_SEL(sel, "%5s %3s %7s(%%) %12s(%%) %11s(%%) %9s(%%) %8s(%%)\n",
  325. "Index", "CH", "Quality", "Availability", "Utilization",
  326. "WIFI Util", "Interference Util");
  327. for (ch_idx = 0; ch_idx < max_chan_nums; ch_idx++) {
  328. ch_num = rtw_get_ch_num_by_idx(adapter, ch_idx);
  329. utilization = hal_data->acs.clm_ratio[ch_idx] + hal_data->acs.nhm_ratio[ch_idx];
  330. _RTW_PRINT_SEL(sel, "%5d %3d %7d %12d %12d %12d %12d\n",
  331. ch_idx, ch_num,
  332. (100-hal_data->acs.interference_time[ch_idx]),
  333. (100-utilization),
  334. utilization,
  335. hal_data->acs.clm_ratio[ch_idx],
  336. hal_data->acs.nhm_ratio[ch_idx]);
  337. }
  338. }
  339. void rtw_acs_current_info_dump(void *sel, _adapter *adapter)
  340. {
  341. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  342. u8 ch, cen_ch, bw, offset;
  343. _RTW_PRINT_SEL(sel, "========== ACS (VER-%d) ==========\n", RTK_ACS_VERSION);
  344. ch = rtw_get_oper_ch(adapter);
  345. bw = rtw_get_oper_bw(adapter);
  346. offset = rtw_get_oper_choffset(adapter);
  347. _RTW_PRINT_SEL(sel, "Current Channel:%d\n", ch);
  348. if ((bw == CHANNEL_WIDTH_80) ||(bw == CHANNEL_WIDTH_40)) {
  349. cen_ch = rtw_get_center_ch(ch, bw, offset);
  350. _RTW_PRINT_SEL(sel, "Center Channel:%d\n", cen_ch);
  351. }
  352. _RTW_PRINT_SEL(sel, "Current BW %s\n", ch_width_str(bw));
  353. if (0)
  354. _RTW_PRINT_SEL(sel, "Current IGI 0x%02x\n", rtw_phydm_get_cur_igi(adapter));
  355. _RTW_PRINT_SEL(sel, "CLM:%d, NHM:%d\n\n",
  356. hal_data->acs.cur_ch_clm_ratio, hal_data->acs.cur_ch_nhm_ratio);
  357. }
  358. void rtw_acs_update_current_info(_adapter *adapter)
  359. {
  360. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  361. hal_data->acs.cur_ch_clm_ratio = rtw_phydm_clm_ratio(adapter);
  362. hal_data->acs.cur_ch_nhm_ratio = rtw_phydm_nhm_ratio(adapter);
  363. #ifdef CONFIG_RTW_ACS_DBG
  364. rtw_acs_current_info_dump(RTW_DBGDUMP, adapter);
  365. #endif
  366. }
  367. #endif /*CONFIG_RTW_ACS*/
  368. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  369. void rtw_noise_monitor_version_dump(void *sel, _adapter *adapter)
  370. {
  371. _RTW_PRINT_SEL(sel, "RTK_NOISE_MONITOR VER_%d\n", RTK_NOISE_MONITOR_VERSION);
  372. }
  373. void rtw_nm_enable(_adapter *adapter)
  374. {
  375. SET_NM_STATE(adapter, NM_ENABLE);
  376. }
  377. void rtw_nm_disable(_adapter *adapter)
  378. {
  379. SET_NM_STATE(adapter, NM_DISABLE);
  380. }
  381. void rtw_noise_info_dump(void *sel, _adapter *adapter)
  382. {
  383. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  384. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  385. u8 max_chan_nums = rfctl->max_chan_nums;
  386. u8 ch_idx, ch_num;
  387. _RTW_PRINT_SEL(sel, "========== NM (VER-%d) ==========\n", RTK_NOISE_MONITOR_VERSION);
  388. _RTW_PRINT_SEL(sel, "%5s %3s %3s %10s", "Index", "CH", "BSS", "Noise(dBm)\n");
  389. _rtw_bss_nums_count(adapter, hal_data->nm.bss_nums);
  390. for (ch_idx = 0; ch_idx < max_chan_nums; ch_idx++) {
  391. ch_num = rtw_get_ch_num_by_idx(adapter, ch_idx);
  392. _RTW_PRINT_SEL(sel, "%5d %3d %3d %10d\n",
  393. ch_idx, ch_num, hal_data->nm.bss_nums[ch_idx],
  394. hal_data->nm.noise[ch_idx]);
  395. }
  396. }
  397. void rtw_noise_measure(_adapter *adapter, u8 chan, u8 is_pause_dig, u8 igi_value, u32 max_time)
  398. {
  399. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  400. struct dm_struct *phydm = &hal_data->odmpriv;
  401. int chan_idx = -1;
  402. s16 noise = 0;
  403. #ifdef DBG_NOISE_MONITOR
  404. RTW_INFO("[NM] chan(%d)-PauseDIG:%s, IGIValue:0x%02x, max_time:%d (ms)\n",
  405. chan, (is_pause_dig) ? "Y" : "N", igi_value, max_time);
  406. #endif
  407. chan_idx = rtw_chset_search_ch(adapter_to_chset(adapter), chan);
  408. if ((chan_idx == -1) || (chan_idx >= MAX_CHANNEL_NUM)) {
  409. RTW_ERR("[NM] Get noise fail, can't get chan_idx(CH:%d)\n", chan);
  410. return;
  411. }
  412. noise = odm_inband_noise_monitor(phydm, is_pause_dig, igi_value, max_time); /*dBm*/
  413. hal_data->nm.noise[chan_idx] = noise;
  414. #ifdef DBG_NOISE_MONITOR
  415. RTW_INFO("[NM] %s chan_%d, noise = %d (dBm)\n", __func__, chan, hal_data->nm.noise[chan_idx]);
  416. RTW_INFO("[NM] noise_a = %d, noise_b = %d noise_all:%d\n",
  417. phydm->noise_level.noise[RF_PATH_A],
  418. phydm->noise_level.noise[RF_PATH_B],
  419. phydm->noise_level.noise_all);
  420. #endif /*DBG_NOISE_MONITOR*/
  421. }
  422. s16 rtw_noise_query_by_chan_num(_adapter *adapter, u8 chan)
  423. {
  424. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  425. s16 noise = 0;
  426. int chan_idx = -1;
  427. chan_idx = rtw_chset_search_ch(adapter_to_chset(adapter), chan);
  428. if ((chan_idx == -1) || (chan_idx >= MAX_CHANNEL_NUM)) {
  429. RTW_ERR("[NM] Get noise fail, can't get chan_idx(CH:%d)\n", chan);
  430. return noise;
  431. }
  432. noise = hal_data->nm.noise[chan_idx];
  433. #ifdef DBG_NOISE_MONITOR
  434. RTW_INFO("[NM] %s chan_%d, noise = %d (dBm)\n", __func__, chan, noise);
  435. #endif/*DBG_NOISE_MONITOR*/
  436. return noise;
  437. }
  438. s16 rtw_noise_query_by_chan_idx(_adapter *adapter, u8 ch_idx)
  439. {
  440. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  441. s16 noise = 0;
  442. if (ch_idx >= MAX_CHANNEL_NUM) {
  443. RTW_ERR("[NM] %s ch_idx(%d) is invalid\n", __func__, ch_idx);
  444. return noise;
  445. }
  446. noise = hal_data->nm.noise[ch_idx];
  447. #ifdef DBG_NOISE_MONITOR
  448. RTW_INFO("[NM] %s ch_idx %d, noise = %d (dBm)\n", __func__, ch_idx, noise);
  449. #endif/*DBG_NOISE_MONITOR*/
  450. return noise;
  451. }
  452. s16 rtw_noise_measure_curchan(_adapter *padapter)
  453. {
  454. s16 noise = 0;
  455. u8 igi_value = 0x1E;
  456. u32 max_time = 100;/* ms */
  457. u8 is_pause_dig = _TRUE;
  458. u8 cur_chan = rtw_get_oper_ch(padapter);
  459. if (rtw_linked_check(padapter) == _FALSE)
  460. return noise;
  461. rtw_ps_deny(padapter, PS_DENY_IOCTL);
  462. LeaveAllPowerSaveModeDirect(padapter);
  463. rtw_noise_measure(padapter, cur_chan, is_pause_dig, igi_value, max_time);
  464. noise = rtw_noise_query_by_chan_num(padapter, cur_chan);
  465. rtw_ps_deny_cancel(padapter, PS_DENY_IOCTL);
  466. return noise;
  467. }
  468. #endif /*CONFIG_BACKGROUND_NOISE_MONITOR*/