event.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. static void wl1271_event_rssi_trigger(struct wl1271 *wl,
  31. struct wl12xx_vif *wlvif,
  32. struct event_mailbox *mbox)
  33. {
  34. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  35. enum nl80211_cqm_rssi_threshold_event event;
  36. s8 metric = mbox->rssi_snr_trigger_metric[0];
  37. wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
  38. if (metric <= wlvif->rssi_thold)
  39. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  40. else
  41. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  42. if (event != wlvif->last_rssi_event)
  43. ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
  44. wlvif->last_rssi_event = event;
  45. }
  46. static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  47. {
  48. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  49. if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
  50. if (!wlvif->sta.ba_rx_bitmap)
  51. return;
  52. ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
  53. vif->bss_conf.bssid);
  54. } else {
  55. u8 hlid;
  56. struct wl1271_link *lnk;
  57. for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
  58. WL12XX_MAX_LINKS) {
  59. lnk = &wl->links[hlid];
  60. if (!lnk->ba_bitmap)
  61. continue;
  62. ieee80211_stop_rx_ba_session(vif,
  63. lnk->ba_bitmap,
  64. lnk->addr);
  65. }
  66. }
  67. }
  68. static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
  69. u8 enable)
  70. {
  71. struct wl12xx_vif *wlvif;
  72. if (enable) {
  73. set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  74. } else {
  75. clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  76. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  77. wl1271_recalc_rx_streaming(wl, wlvif);
  78. }
  79. }
  80. }
  81. static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
  82. {
  83. wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
  84. wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
  85. wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
  86. }
  87. static int wl1271_event_process(struct wl1271 *wl)
  88. {
  89. struct event_mailbox *mbox = wl->mbox;
  90. struct ieee80211_vif *vif;
  91. struct wl12xx_vif *wlvif;
  92. u32 vector;
  93. bool disconnect_sta = false;
  94. unsigned long sta_bitmap = 0;
  95. int ret;
  96. wl1271_event_mbox_dump(mbox);
  97. vector = le32_to_cpu(mbox->events_vector);
  98. vector &= ~(le32_to_cpu(mbox->events_mask));
  99. wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
  100. if (vector & SCAN_COMPLETE_EVENT_ID) {
  101. wl1271_debug(DEBUG_EVENT, "status: 0x%x",
  102. mbox->scheduled_scan_status);
  103. wl1271_scan_stm(wl, wl->scan_vif);
  104. }
  105. if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
  106. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
  107. "(status 0x%0x)", mbox->scheduled_scan_status);
  108. wl1271_scan_sched_scan_results(wl);
  109. }
  110. if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
  111. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
  112. "(status 0x%0x)", mbox->scheduled_scan_status);
  113. if (wl->sched_scanning) {
  114. ieee80211_sched_scan_stopped(wl->hw);
  115. wl->sched_scanning = false;
  116. }
  117. }
  118. if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
  119. wl12xx_event_soft_gemini_sense(wl,
  120. mbox->soft_gemini_sense_info);
  121. /*
  122. * We are HW_MONITOR device. On beacon loss - queue
  123. * connection loss work. Cancel it on REGAINED event.
  124. */
  125. if (vector & BSS_LOSE_EVENT_ID) {
  126. /* TODO: check for multi-role */
  127. int delay = wl->conf.conn.synch_fail_thold *
  128. wl->conf.conn.bss_lose_timeout;
  129. wl1271_info("Beacon loss detected.");
  130. /*
  131. * if the work is already queued, it should take place. We
  132. * don't want to delay the connection loss indication
  133. * any more.
  134. */
  135. ieee80211_queue_delayed_work(wl->hw, &wl->connection_loss_work,
  136. msecs_to_jiffies(delay));
  137. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  138. vif = wl12xx_wlvif_to_vif(wlvif);
  139. ieee80211_cqm_rssi_notify(
  140. vif,
  141. NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
  142. GFP_KERNEL);
  143. }
  144. }
  145. if (vector & REGAINED_BSS_EVENT_ID) {
  146. /* TODO: check for multi-role */
  147. wl1271_info("Beacon regained.");
  148. cancel_delayed_work(&wl->connection_loss_work);
  149. /* sanity check - we can't lose and gain the beacon together */
  150. WARN(vector & BSS_LOSE_EVENT_ID,
  151. "Concurrent beacon loss and gain from FW");
  152. }
  153. if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
  154. /* TODO: check actual multi-role support */
  155. wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
  156. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  157. wl1271_event_rssi_trigger(wl, wlvif, mbox);
  158. }
  159. }
  160. if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
  161. u8 role_id = mbox->role_id;
  162. wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
  163. "ba_allowed = 0x%x, role_id=%d",
  164. mbox->rx_ba_allowed, role_id);
  165. wl12xx_for_each_wlvif(wl, wlvif) {
  166. if (role_id != 0xff && role_id != wlvif->role_id)
  167. continue;
  168. wlvif->ba_allowed = !!mbox->rx_ba_allowed;
  169. if (!wlvif->ba_allowed)
  170. wl1271_stop_ba_event(wl, wlvif);
  171. }
  172. }
  173. if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
  174. wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
  175. "status = 0x%x",
  176. mbox->channel_switch_status);
  177. /*
  178. * That event uses for two cases:
  179. * 1) channel switch complete with status=0
  180. * 2) channel switch failed status=1
  181. */
  182. /* TODO: configure only the relevant vif */
  183. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  184. bool success;
  185. if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
  186. &wlvif->flags))
  187. continue;
  188. success = mbox->channel_switch_status ? false : true;
  189. vif = wl12xx_wlvif_to_vif(wlvif);
  190. ieee80211_chswitch_done(vif, success);
  191. }
  192. }
  193. if ((vector & DUMMY_PACKET_EVENT_ID)) {
  194. wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
  195. ret = wl1271_tx_dummy_packet(wl);
  196. if (ret < 0)
  197. return ret;
  198. }
  199. /*
  200. * "TX retries exceeded" has a different meaning according to mode.
  201. * In AP mode the offending station is disconnected.
  202. */
  203. if (vector & MAX_TX_RETRY_EVENT_ID) {
  204. wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
  205. sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
  206. disconnect_sta = true;
  207. }
  208. if (vector & INACTIVE_STA_EVENT_ID) {
  209. wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
  210. sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
  211. disconnect_sta = true;
  212. }
  213. if (disconnect_sta) {
  214. u32 num_packets = wl->conf.tx.max_tx_retries;
  215. struct ieee80211_sta *sta;
  216. const u8 *addr;
  217. int h;
  218. for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
  219. bool found = false;
  220. /* find the ap vif connected to this sta */
  221. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  222. if (!test_bit(h, wlvif->ap.sta_hlid_map))
  223. continue;
  224. found = true;
  225. break;
  226. }
  227. if (!found)
  228. continue;
  229. vif = wl12xx_wlvif_to_vif(wlvif);
  230. addr = wl->links[h].addr;
  231. rcu_read_lock();
  232. sta = ieee80211_find_sta(vif, addr);
  233. if (sta) {
  234. wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
  235. ieee80211_report_low_ack(sta, num_packets);
  236. }
  237. rcu_read_unlock();
  238. }
  239. }
  240. return 0;
  241. }
  242. int wl1271_event_unmask(struct wl1271 *wl)
  243. {
  244. int ret;
  245. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  246. if (ret < 0)
  247. return ret;
  248. return 0;
  249. }
  250. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  251. {
  252. int ret;
  253. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  254. if (mbox_num > 1)
  255. return -EINVAL;
  256. /* first we read the mbox descriptor */
  257. ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
  258. sizeof(*wl->mbox), false);
  259. if (ret < 0)
  260. return ret;
  261. /* process the descriptor */
  262. ret = wl1271_event_process(wl);
  263. if (ret < 0)
  264. return ret;
  265. /*
  266. * TODO: we just need this because one bit is in a different
  267. * place. Is there any better way?
  268. */
  269. ret = wl->ops->ack_event(wl);
  270. return ret;
  271. }