event.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include "wlcore.h"
  24. #include "debug.h"
  25. #include "io.h"
  26. #include "event.h"
  27. #include "ps.h"
  28. #include "scan.h"
  29. #include "wl12xx_80211.h"
  30. #include "hw_ops.h"
  31. #define WL18XX_LOGGER_SDIO_BUFF_MAX (0x1020)
  32. #define WL18XX_DATA_RAM_BASE_ADDRESS (0x20000000)
  33. #define WL18XX_LOGGER_SDIO_BUFF_ADDR (0x40159c)
  34. #define WL18XX_LOGGER_BUFF_OFFSET (sizeof(struct fw_logger_information))
  35. #define WL18XX_LOGGER_READ_POINT_OFFSET (12)
  36. int wlcore_event_fw_logger(struct wl1271 *wl)
  37. {
  38. int ret;
  39. struct fw_logger_information fw_log;
  40. u8 *buffer;
  41. u32 internal_fw_addrbase = WL18XX_DATA_RAM_BASE_ADDRESS;
  42. u32 addr = WL18XX_LOGGER_SDIO_BUFF_ADDR;
  43. u32 end_buff_addr = WL18XX_LOGGER_SDIO_BUFF_ADDR +
  44. WL18XX_LOGGER_BUFF_OFFSET;
  45. u32 available_len;
  46. u32 actual_len;
  47. u32 clear_addr;
  48. size_t len;
  49. u32 start_loc;
  50. buffer = kzalloc(WL18XX_LOGGER_SDIO_BUFF_MAX, GFP_KERNEL);
  51. if (!buffer) {
  52. wl1271_error("Fail to allocate fw logger memory");
  53. fw_log.actual_buff_size = cpu_to_le32(0);
  54. goto out;
  55. }
  56. ret = wlcore_read(wl, addr, buffer, WL18XX_LOGGER_SDIO_BUFF_MAX,
  57. false);
  58. if (ret < 0) {
  59. wl1271_error("Fail to read logger buffer, error_id = %d",
  60. ret);
  61. fw_log.actual_buff_size = cpu_to_le32(0);
  62. goto free_out;
  63. }
  64. memcpy(&fw_log, buffer, sizeof(fw_log));
  65. if (le32_to_cpu(fw_log.actual_buff_size) == 0)
  66. goto free_out;
  67. actual_len = le32_to_cpu(fw_log.actual_buff_size);
  68. start_loc = (le32_to_cpu(fw_log.buff_read_ptr) -
  69. internal_fw_addrbase) - addr;
  70. end_buff_addr += le32_to_cpu(fw_log.max_buff_size);
  71. available_len = end_buff_addr -
  72. (le32_to_cpu(fw_log.buff_read_ptr) -
  73. internal_fw_addrbase);
  74. actual_len = min(actual_len, available_len);
  75. len = actual_len;
  76. wl12xx_copy_fwlog(wl, &buffer[start_loc], len);
  77. clear_addr = addr + start_loc + le32_to_cpu(fw_log.actual_buff_size) +
  78. internal_fw_addrbase;
  79. len = le32_to_cpu(fw_log.actual_buff_size) - len;
  80. if (len) {
  81. wl12xx_copy_fwlog(wl,
  82. &buffer[WL18XX_LOGGER_BUFF_OFFSET],
  83. len);
  84. clear_addr = addr + WL18XX_LOGGER_BUFF_OFFSET + len +
  85. internal_fw_addrbase;
  86. }
  87. /* double check that clear address and write pointer are the same */
  88. if (clear_addr != le32_to_cpu(fw_log.buff_write_ptr)) {
  89. wl1271_error("Calculate of clear addr Clear = %x, write = %x",
  90. clear_addr, le32_to_cpu(fw_log.buff_write_ptr));
  91. }
  92. /* indicate FW about Clear buffer */
  93. ret = wlcore_write32(wl, addr + WL18XX_LOGGER_READ_POINT_OFFSET,
  94. fw_log.buff_write_ptr);
  95. free_out:
  96. kfree(buffer);
  97. out:
  98. return le32_to_cpu(fw_log.actual_buff_size);
  99. }
  100. EXPORT_SYMBOL_GPL(wlcore_event_fw_logger);
  101. void wlcore_event_rssi_trigger(struct wl1271 *wl, s8 *metric_arr)
  102. {
  103. struct wl12xx_vif *wlvif;
  104. struct ieee80211_vif *vif;
  105. enum nl80211_cqm_rssi_threshold_event event;
  106. s8 metric = metric_arr[0];
  107. wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
  108. /* TODO: check actual multi-role support */
  109. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  110. if (metric <= wlvif->rssi_thold)
  111. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  112. else
  113. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  114. vif = wl12xx_wlvif_to_vif(wlvif);
  115. if (event != wlvif->last_rssi_event)
  116. ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
  117. wlvif->last_rssi_event = event;
  118. }
  119. }
  120. EXPORT_SYMBOL_GPL(wlcore_event_rssi_trigger);
  121. static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  122. {
  123. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  124. if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
  125. u8 hlid = wlvif->sta.hlid;
  126. if (!wl->links[hlid].ba_bitmap)
  127. return;
  128. ieee80211_stop_rx_ba_session(vif, wl->links[hlid].ba_bitmap,
  129. vif->bss_conf.bssid);
  130. } else {
  131. u8 hlid;
  132. struct wl1271_link *lnk;
  133. for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
  134. wl->num_links) {
  135. lnk = &wl->links[hlid];
  136. if (!lnk->ba_bitmap)
  137. continue;
  138. ieee80211_stop_rx_ba_session(vif,
  139. lnk->ba_bitmap,
  140. lnk->addr);
  141. }
  142. }
  143. }
  144. void wlcore_event_soft_gemini_sense(struct wl1271 *wl, u8 enable)
  145. {
  146. struct wl12xx_vif *wlvif;
  147. if (enable) {
  148. set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  149. } else {
  150. clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  151. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  152. wl1271_recalc_rx_streaming(wl, wlvif);
  153. }
  154. }
  155. }
  156. EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense);
  157. void wlcore_event_sched_scan_completed(struct wl1271 *wl,
  158. u8 status)
  159. {
  160. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
  161. status);
  162. if (wl->sched_vif) {
  163. ieee80211_sched_scan_stopped(wl->hw);
  164. wl->sched_vif = NULL;
  165. }
  166. }
  167. EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed);
  168. void wlcore_event_ba_rx_constraint(struct wl1271 *wl,
  169. unsigned long roles_bitmap,
  170. unsigned long allowed_bitmap)
  171. {
  172. struct wl12xx_vif *wlvif;
  173. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx allowed=0x%lx",
  174. __func__, roles_bitmap, allowed_bitmap);
  175. wl12xx_for_each_wlvif(wl, wlvif) {
  176. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  177. !test_bit(wlvif->role_id , &roles_bitmap))
  178. continue;
  179. wlvif->ba_allowed = !!test_bit(wlvif->role_id,
  180. &allowed_bitmap);
  181. if (!wlvif->ba_allowed)
  182. wl1271_stop_ba_event(wl, wlvif);
  183. }
  184. }
  185. EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint);
  186. void wlcore_event_channel_switch(struct wl1271 *wl,
  187. unsigned long roles_bitmap,
  188. bool success)
  189. {
  190. struct wl12xx_vif *wlvif;
  191. struct ieee80211_vif *vif;
  192. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx success=%d",
  193. __func__, roles_bitmap, success);
  194. wl12xx_for_each_wlvif(wl, wlvif) {
  195. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  196. !test_bit(wlvif->role_id , &roles_bitmap))
  197. continue;
  198. if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
  199. &wlvif->flags))
  200. continue;
  201. vif = wl12xx_wlvif_to_vif(wlvif);
  202. if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
  203. ieee80211_chswitch_done(vif, success);
  204. cancel_delayed_work(&wlvif->channel_switch_work);
  205. } else {
  206. set_bit(WLVIF_FLAG_BEACON_DISABLED, &wlvif->flags);
  207. ieee80211_csa_finish(vif);
  208. }
  209. }
  210. }
  211. EXPORT_SYMBOL_GPL(wlcore_event_channel_switch);
  212. void wlcore_event_dummy_packet(struct wl1271 *wl)
  213. {
  214. if (wl->plt) {
  215. wl1271_info("Got DUMMY_PACKET event in PLT mode. FW bug, ignoring.");
  216. return;
  217. }
  218. wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
  219. wl1271_tx_dummy_packet(wl);
  220. }
  221. EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet);
  222. static void wlcore_disconnect_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  223. {
  224. u32 num_packets = wl->conf.tx.max_tx_retries;
  225. struct wl12xx_vif *wlvif;
  226. struct ieee80211_vif *vif;
  227. struct ieee80211_sta *sta;
  228. const u8 *addr;
  229. int h;
  230. for_each_set_bit(h, &sta_bitmap, wl->num_links) {
  231. bool found = false;
  232. /* find the ap vif connected to this sta */
  233. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  234. if (!test_bit(h, wlvif->ap.sta_hlid_map))
  235. continue;
  236. found = true;
  237. break;
  238. }
  239. if (!found)
  240. continue;
  241. vif = wl12xx_wlvif_to_vif(wlvif);
  242. addr = wl->links[h].addr;
  243. rcu_read_lock();
  244. sta = ieee80211_find_sta(vif, addr);
  245. if (sta) {
  246. wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
  247. ieee80211_report_low_ack(sta, num_packets);
  248. }
  249. rcu_read_unlock();
  250. }
  251. }
  252. void wlcore_event_max_tx_failure(struct wl1271 *wl, unsigned long sta_bitmap)
  253. {
  254. wl1271_debug(DEBUG_EVENT, "MAX_TX_FAILURE_EVENT_ID");
  255. wlcore_disconnect_sta(wl, sta_bitmap);
  256. }
  257. EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure);
  258. void wlcore_event_inactive_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  259. {
  260. wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
  261. wlcore_disconnect_sta(wl, sta_bitmap);
  262. }
  263. EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta);
  264. void wlcore_event_roc_complete(struct wl1271 *wl)
  265. {
  266. wl1271_debug(DEBUG_EVENT, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
  267. if (wl->roc_vif)
  268. ieee80211_ready_on_channel(wl->hw);
  269. }
  270. EXPORT_SYMBOL_GPL(wlcore_event_roc_complete);
  271. void wlcore_event_beacon_loss(struct wl1271 *wl, unsigned long roles_bitmap)
  272. {
  273. /*
  274. * We are HW_MONITOR device. On beacon loss - queue
  275. * connection loss work. Cancel it on REGAINED event.
  276. */
  277. struct wl12xx_vif *wlvif;
  278. struct ieee80211_vif *vif;
  279. int delay = wl->conf.conn.synch_fail_thold *
  280. wl->conf.conn.bss_lose_timeout;
  281. wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap);
  282. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  283. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  284. !test_bit(wlvif->role_id , &roles_bitmap))
  285. continue;
  286. vif = wl12xx_wlvif_to_vif(wlvif);
  287. /* don't attempt roaming in case of p2p */
  288. if (wlvif->p2p) {
  289. ieee80211_connection_loss(vif);
  290. continue;
  291. }
  292. /*
  293. * if the work is already queued, it should take place.
  294. * We don't want to delay the connection loss
  295. * indication any more.
  296. */
  297. ieee80211_queue_delayed_work(wl->hw,
  298. &wlvif->connection_loss_work,
  299. msecs_to_jiffies(delay));
  300. ieee80211_cqm_beacon_loss_notify(vif, GFP_KERNEL);
  301. }
  302. }
  303. EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss);
  304. int wl1271_event_unmask(struct wl1271 *wl)
  305. {
  306. int ret;
  307. wl1271_debug(DEBUG_EVENT, "unmasking event_mask 0x%x", wl->event_mask);
  308. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  309. if (ret < 0)
  310. return ret;
  311. return 0;
  312. }
  313. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  314. {
  315. int ret;
  316. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  317. if (mbox_num > 1)
  318. return -EINVAL;
  319. /* first we read the mbox descriptor */
  320. ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
  321. wl->mbox_size, false);
  322. if (ret < 0)
  323. return ret;
  324. /* process the descriptor */
  325. ret = wl->ops->process_mailbox_events(wl);
  326. if (ret < 0)
  327. return ret;
  328. /*
  329. * TODO: we just need this because one bit is in a different
  330. * place. Is there any better way?
  331. */
  332. ret = wl->ops->ack_event(wl);
  333. return ret;
  334. }