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, metric,
  117. GFP_KERNEL);
  118. wlvif->last_rssi_event = event;
  119. }
  120. }
  121. EXPORT_SYMBOL_GPL(wlcore_event_rssi_trigger);
  122. static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  123. {
  124. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  125. if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
  126. u8 hlid = wlvif->sta.hlid;
  127. if (!wl->links[hlid].ba_bitmap)
  128. return;
  129. ieee80211_stop_rx_ba_session(vif, wl->links[hlid].ba_bitmap,
  130. vif->bss_conf.bssid);
  131. } else {
  132. u8 hlid;
  133. struct wl1271_link *lnk;
  134. for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
  135. wl->num_links) {
  136. lnk = &wl->links[hlid];
  137. if (!lnk->ba_bitmap)
  138. continue;
  139. ieee80211_stop_rx_ba_session(vif,
  140. lnk->ba_bitmap,
  141. lnk->addr);
  142. }
  143. }
  144. }
  145. void wlcore_event_soft_gemini_sense(struct wl1271 *wl, u8 enable)
  146. {
  147. struct wl12xx_vif *wlvif;
  148. if (enable) {
  149. set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  150. } else {
  151. clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  152. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  153. wl1271_recalc_rx_streaming(wl, wlvif);
  154. }
  155. }
  156. }
  157. EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense);
  158. void wlcore_event_sched_scan_completed(struct wl1271 *wl,
  159. u8 status)
  160. {
  161. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
  162. status);
  163. if (wl->sched_vif) {
  164. ieee80211_sched_scan_stopped(wl->hw);
  165. wl->sched_vif = NULL;
  166. }
  167. }
  168. EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed);
  169. void wlcore_event_ba_rx_constraint(struct wl1271 *wl,
  170. unsigned long roles_bitmap,
  171. unsigned long allowed_bitmap)
  172. {
  173. struct wl12xx_vif *wlvif;
  174. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx allowed=0x%lx",
  175. __func__, roles_bitmap, allowed_bitmap);
  176. wl12xx_for_each_wlvif(wl, wlvif) {
  177. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  178. !test_bit(wlvif->role_id , &roles_bitmap))
  179. continue;
  180. wlvif->ba_allowed = !!test_bit(wlvif->role_id,
  181. &allowed_bitmap);
  182. if (!wlvif->ba_allowed)
  183. wl1271_stop_ba_event(wl, wlvif);
  184. }
  185. }
  186. EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint);
  187. void wlcore_event_channel_switch(struct wl1271 *wl,
  188. unsigned long roles_bitmap,
  189. bool success)
  190. {
  191. struct wl12xx_vif *wlvif;
  192. struct ieee80211_vif *vif;
  193. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx success=%d",
  194. __func__, roles_bitmap, success);
  195. wl12xx_for_each_wlvif(wl, wlvif) {
  196. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  197. !test_bit(wlvif->role_id , &roles_bitmap))
  198. continue;
  199. if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
  200. &wlvif->flags))
  201. continue;
  202. vif = wl12xx_wlvif_to_vif(wlvif);
  203. if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
  204. ieee80211_chswitch_done(vif, success);
  205. cancel_delayed_work(&wlvif->channel_switch_work);
  206. } else {
  207. set_bit(WLVIF_FLAG_BEACON_DISABLED, &wlvif->flags);
  208. ieee80211_csa_finish(vif);
  209. }
  210. }
  211. }
  212. EXPORT_SYMBOL_GPL(wlcore_event_channel_switch);
  213. void wlcore_event_dummy_packet(struct wl1271 *wl)
  214. {
  215. if (wl->plt) {
  216. wl1271_info("Got DUMMY_PACKET event in PLT mode. FW bug, ignoring.");
  217. return;
  218. }
  219. wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
  220. wl1271_tx_dummy_packet(wl);
  221. }
  222. EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet);
  223. static void wlcore_disconnect_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  224. {
  225. u32 num_packets = wl->conf.tx.max_tx_retries;
  226. struct wl12xx_vif *wlvif;
  227. struct ieee80211_vif *vif;
  228. struct ieee80211_sta *sta;
  229. const u8 *addr;
  230. int h;
  231. for_each_set_bit(h, &sta_bitmap, wl->num_links) {
  232. bool found = false;
  233. /* find the ap vif connected to this sta */
  234. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  235. if (!test_bit(h, wlvif->ap.sta_hlid_map))
  236. continue;
  237. found = true;
  238. break;
  239. }
  240. if (!found)
  241. continue;
  242. vif = wl12xx_wlvif_to_vif(wlvif);
  243. addr = wl->links[h].addr;
  244. rcu_read_lock();
  245. sta = ieee80211_find_sta(vif, addr);
  246. if (sta) {
  247. wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
  248. ieee80211_report_low_ack(sta, num_packets);
  249. }
  250. rcu_read_unlock();
  251. }
  252. }
  253. void wlcore_event_max_tx_failure(struct wl1271 *wl, unsigned long sta_bitmap)
  254. {
  255. wl1271_debug(DEBUG_EVENT, "MAX_TX_FAILURE_EVENT_ID");
  256. wlcore_disconnect_sta(wl, sta_bitmap);
  257. }
  258. EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure);
  259. void wlcore_event_inactive_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  260. {
  261. wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
  262. wlcore_disconnect_sta(wl, sta_bitmap);
  263. }
  264. EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta);
  265. void wlcore_event_roc_complete(struct wl1271 *wl)
  266. {
  267. wl1271_debug(DEBUG_EVENT, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
  268. if (wl->roc_vif)
  269. ieee80211_ready_on_channel(wl->hw);
  270. }
  271. EXPORT_SYMBOL_GPL(wlcore_event_roc_complete);
  272. void wlcore_event_beacon_loss(struct wl1271 *wl, unsigned long roles_bitmap)
  273. {
  274. /*
  275. * We are HW_MONITOR device. On beacon loss - queue
  276. * connection loss work. Cancel it on REGAINED event.
  277. */
  278. struct wl12xx_vif *wlvif;
  279. struct ieee80211_vif *vif;
  280. int delay = wl->conf.conn.synch_fail_thold *
  281. wl->conf.conn.bss_lose_timeout;
  282. wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap);
  283. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  284. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  285. !test_bit(wlvif->role_id , &roles_bitmap))
  286. continue;
  287. vif = wl12xx_wlvif_to_vif(wlvif);
  288. /* don't attempt roaming in case of p2p */
  289. if (wlvif->p2p) {
  290. ieee80211_connection_loss(vif);
  291. continue;
  292. }
  293. /*
  294. * if the work is already queued, it should take place.
  295. * We don't want to delay the connection loss
  296. * indication any more.
  297. */
  298. ieee80211_queue_delayed_work(wl->hw,
  299. &wlvif->connection_loss_work,
  300. msecs_to_jiffies(delay));
  301. ieee80211_cqm_beacon_loss_notify(vif, GFP_KERNEL);
  302. }
  303. }
  304. EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss);
  305. int wl1271_event_unmask(struct wl1271 *wl)
  306. {
  307. int ret;
  308. wl1271_debug(DEBUG_EVENT, "unmasking event_mask 0x%x", wl->event_mask);
  309. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  310. if (ret < 0)
  311. return ret;
  312. return 0;
  313. }
  314. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  315. {
  316. int ret;
  317. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  318. if (mbox_num > 1)
  319. return -EINVAL;
  320. /* first we read the mbox descriptor */
  321. ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
  322. wl->mbox_size, false);
  323. if (ret < 0)
  324. return ret;
  325. /* process the descriptor */
  326. ret = wl->ops->process_mailbox_events(wl);
  327. if (ret < 0)
  328. return ret;
  329. /*
  330. * TODO: we just need this because one bit is in a different
  331. * place. Is there any better way?
  332. */
  333. ret = wl->ops->ack_event(wl);
  334. return ret;
  335. }