event.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 "wl12xx.h"
  24. #include "debug.h"
  25. #include "reg.h"
  26. #include "io.h"
  27. #include "event.h"
  28. #include "ps.h"
  29. #include "scan.h"
  30. #include "wl12xx_80211.h"
  31. static void wl1271_event_rssi_trigger(struct wl1271 *wl,
  32. struct wl12xx_vif *wlvif,
  33. struct event_mailbox *mbox)
  34. {
  35. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  36. enum nl80211_cqm_rssi_threshold_event event;
  37. s8 metric = mbox->rssi_snr_trigger_metric[0];
  38. wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
  39. if (metric <= wlvif->rssi_thold)
  40. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  41. else
  42. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  43. if (event != wlvif->last_rssi_event)
  44. ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
  45. wlvif->last_rssi_event = event;
  46. }
  47. static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  48. {
  49. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  50. if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
  51. if (!wlvif->sta.ba_rx_bitmap)
  52. return;
  53. ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
  54. vif->bss_conf.bssid);
  55. } else {
  56. u8 hlid;
  57. struct wl1271_link *lnk;
  58. for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
  59. WL12XX_MAX_LINKS) {
  60. lnk = &wl->links[hlid];
  61. if (!lnk->ba_bitmap)
  62. continue;
  63. ieee80211_stop_rx_ba_session(vif,
  64. lnk->ba_bitmap,
  65. lnk->addr);
  66. }
  67. }
  68. }
  69. static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
  70. u8 enable)
  71. {
  72. struct ieee80211_vif *vif;
  73. struct wl12xx_vif *wlvif;
  74. if (enable) {
  75. /* disable dynamic PS when requested by the firmware */
  76. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  77. vif = wl12xx_wlvif_to_vif(wlvif);
  78. ieee80211_disable_dyn_ps(vif);
  79. }
  80. set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  81. } else {
  82. clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  83. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  84. vif = wl12xx_wlvif_to_vif(wlvif);
  85. ieee80211_enable_dyn_ps(vif);
  86. wl1271_recalc_rx_streaming(wl, wlvif);
  87. }
  88. }
  89. }
  90. static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
  91. {
  92. wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
  93. wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
  94. wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
  95. }
  96. static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
  97. {
  98. struct ieee80211_vif *vif;
  99. struct wl12xx_vif *wlvif;
  100. u32 vector;
  101. bool beacon_loss = false;
  102. bool disconnect_sta = false;
  103. unsigned long sta_bitmap = 0;
  104. wl1271_event_mbox_dump(mbox);
  105. vector = le32_to_cpu(mbox->events_vector);
  106. vector &= ~(le32_to_cpu(mbox->events_mask));
  107. wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
  108. if (vector & SCAN_COMPLETE_EVENT_ID) {
  109. wl1271_debug(DEBUG_EVENT, "status: 0x%x",
  110. mbox->scheduled_scan_status);
  111. wl1271_scan_stm(wl, wl->scan_vif);
  112. }
  113. if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
  114. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
  115. "(status 0x%0x)", mbox->scheduled_scan_status);
  116. wl1271_scan_sched_scan_results(wl);
  117. }
  118. if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
  119. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
  120. "(status 0x%0x)", mbox->scheduled_scan_status);
  121. if (wl->sched_scanning) {
  122. ieee80211_sched_scan_stopped(wl->hw);
  123. wl->sched_scanning = false;
  124. }
  125. }
  126. if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
  127. wl12xx_event_soft_gemini_sense(wl,
  128. mbox->soft_gemini_sense_info);
  129. /*
  130. * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
  131. * filtering) is enabled. Without PSM, the stack will receive all
  132. * beacons and can detect beacon loss by itself.
  133. *
  134. * As there's possibility that the driver disables PSM before receiving
  135. * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
  136. *
  137. */
  138. if (vector & BSS_LOSE_EVENT_ID) {
  139. /* TODO: check for multi-role */
  140. wl1271_info("Beacon loss detected.");
  141. /* indicate to the stack, that beacons have been lost */
  142. beacon_loss = true;
  143. }
  144. if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
  145. /* TODO: check actual multi-role support */
  146. wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
  147. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  148. wl1271_event_rssi_trigger(wl, wlvif, mbox);
  149. }
  150. }
  151. if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
  152. u8 role_id = mbox->role_id;
  153. wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
  154. "ba_allowed = 0x%x, role_id=%d",
  155. mbox->rx_ba_allowed, role_id);
  156. wl12xx_for_each_wlvif(wl, wlvif) {
  157. if (role_id != 0xff && role_id != wlvif->role_id)
  158. continue;
  159. wlvif->ba_allowed = !!mbox->rx_ba_allowed;
  160. if (!wlvif->ba_allowed)
  161. wl1271_stop_ba_event(wl, wlvif);
  162. }
  163. }
  164. if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
  165. wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
  166. "status = 0x%x",
  167. mbox->channel_switch_status);
  168. /*
  169. * That event uses for two cases:
  170. * 1) channel switch complete with status=0
  171. * 2) channel switch failed status=1
  172. */
  173. /* TODO: configure only the relevant vif */
  174. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  175. bool success;
  176. if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
  177. &wl->flags))
  178. continue;
  179. success = mbox->channel_switch_status ? false : true;
  180. vif = wl12xx_wlvif_to_vif(wlvif);
  181. ieee80211_chswitch_done(vif, success);
  182. }
  183. }
  184. if ((vector & DUMMY_PACKET_EVENT_ID)) {
  185. wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
  186. wl1271_tx_dummy_packet(wl);
  187. }
  188. /*
  189. * "TX retries exceeded" has a different meaning according to mode.
  190. * In AP mode the offending station is disconnected.
  191. */
  192. if (vector & MAX_TX_RETRY_EVENT_ID) {
  193. wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
  194. sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
  195. disconnect_sta = true;
  196. }
  197. if (vector & INACTIVE_STA_EVENT_ID) {
  198. wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
  199. sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
  200. disconnect_sta = true;
  201. }
  202. if (disconnect_sta) {
  203. u32 num_packets = wl->conf.tx.max_tx_retries;
  204. struct ieee80211_sta *sta;
  205. const u8 *addr;
  206. int h;
  207. for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
  208. bool found = false;
  209. /* find the ap vif connected to this sta */
  210. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  211. if (!test_bit(h, wlvif->ap.sta_hlid_map))
  212. continue;
  213. found = true;
  214. break;
  215. }
  216. if (!found)
  217. continue;
  218. vif = wl12xx_wlvif_to_vif(wlvif);
  219. addr = wl->links[h].addr;
  220. rcu_read_lock();
  221. sta = ieee80211_find_sta(vif, addr);
  222. if (sta) {
  223. wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
  224. ieee80211_report_low_ack(sta, num_packets);
  225. }
  226. rcu_read_unlock();
  227. }
  228. }
  229. if (beacon_loss)
  230. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  231. vif = wl12xx_wlvif_to_vif(wlvif);
  232. ieee80211_connection_loss(vif);
  233. }
  234. return 0;
  235. }
  236. int wl1271_event_unmask(struct wl1271 *wl)
  237. {
  238. int ret;
  239. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  240. if (ret < 0)
  241. return ret;
  242. return 0;
  243. }
  244. void wl1271_event_mbox_config(struct wl1271 *wl)
  245. {
  246. wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
  247. wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
  248. wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
  249. wl->mbox_ptr[0], wl->mbox_ptr[1]);
  250. }
  251. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  252. {
  253. struct event_mailbox mbox;
  254. int ret;
  255. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  256. if (mbox_num > 1)
  257. return -EINVAL;
  258. /* first we read the mbox descriptor */
  259. wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
  260. sizeof(struct event_mailbox), false);
  261. /* process the descriptor */
  262. ret = wl1271_event_process(wl, &mbox);
  263. if (ret < 0)
  264. return ret;
  265. /* then we let the firmware know it can go on...*/
  266. wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
  267. return 0;
  268. }