event.c 8.0 KB

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