event.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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, struct event_mailbox *mbox)
  89. {
  90. struct ieee80211_vif *vif;
  91. struct wl12xx_vif *wlvif;
  92. u32 vector;
  93. bool beacon_loss = false;
  94. bool disconnect_sta = false;
  95. unsigned long sta_bitmap = 0;
  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. * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
  123. * filtering) is enabled. Without PSM, the stack will receive all
  124. * beacons and can detect beacon loss by itself.
  125. *
  126. * As there's possibility that the driver disables PSM before receiving
  127. * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
  128. *
  129. */
  130. if (vector & BSS_LOSE_EVENT_ID) {
  131. /* TODO: check for multi-role */
  132. wl1271_info("Beacon loss detected.");
  133. /* indicate to the stack, that beacons have been lost */
  134. beacon_loss = true;
  135. }
  136. if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
  137. /* TODO: check actual multi-role support */
  138. wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
  139. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  140. wl1271_event_rssi_trigger(wl, wlvif, mbox);
  141. }
  142. }
  143. if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
  144. u8 role_id = mbox->role_id;
  145. wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
  146. "ba_allowed = 0x%x, role_id=%d",
  147. mbox->rx_ba_allowed, role_id);
  148. wl12xx_for_each_wlvif(wl, wlvif) {
  149. if (role_id != 0xff && role_id != wlvif->role_id)
  150. continue;
  151. wlvif->ba_allowed = !!mbox->rx_ba_allowed;
  152. if (!wlvif->ba_allowed)
  153. wl1271_stop_ba_event(wl, wlvif);
  154. }
  155. }
  156. if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
  157. wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
  158. "status = 0x%x",
  159. mbox->channel_switch_status);
  160. /*
  161. * That event uses for two cases:
  162. * 1) channel switch complete with status=0
  163. * 2) channel switch failed status=1
  164. */
  165. /* TODO: configure only the relevant vif */
  166. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  167. bool success;
  168. if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
  169. &wl->flags))
  170. continue;
  171. success = mbox->channel_switch_status ? false : true;
  172. vif = wl12xx_wlvif_to_vif(wlvif);
  173. ieee80211_chswitch_done(vif, success);
  174. }
  175. }
  176. if ((vector & DUMMY_PACKET_EVENT_ID)) {
  177. wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
  178. wl1271_tx_dummy_packet(wl);
  179. }
  180. /*
  181. * "TX retries exceeded" has a different meaning according to mode.
  182. * In AP mode the offending station is disconnected.
  183. */
  184. if (vector & MAX_TX_RETRY_EVENT_ID) {
  185. wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
  186. sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
  187. disconnect_sta = true;
  188. }
  189. if (vector & INACTIVE_STA_EVENT_ID) {
  190. wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
  191. sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
  192. disconnect_sta = true;
  193. }
  194. if (disconnect_sta) {
  195. u32 num_packets = wl->conf.tx.max_tx_retries;
  196. struct ieee80211_sta *sta;
  197. const u8 *addr;
  198. int h;
  199. for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
  200. bool found = false;
  201. /* find the ap vif connected to this sta */
  202. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  203. if (!test_bit(h, wlvif->ap.sta_hlid_map))
  204. continue;
  205. found = true;
  206. break;
  207. }
  208. if (!found)
  209. continue;
  210. vif = wl12xx_wlvif_to_vif(wlvif);
  211. addr = wl->links[h].addr;
  212. rcu_read_lock();
  213. sta = ieee80211_find_sta(vif, addr);
  214. if (sta) {
  215. wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
  216. ieee80211_report_low_ack(sta, num_packets);
  217. }
  218. rcu_read_unlock();
  219. }
  220. }
  221. if (beacon_loss)
  222. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  223. vif = wl12xx_wlvif_to_vif(wlvif);
  224. ieee80211_connection_loss(vif);
  225. }
  226. return 0;
  227. }
  228. int wl1271_event_unmask(struct wl1271 *wl)
  229. {
  230. int ret;
  231. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  232. if (ret < 0)
  233. return ret;
  234. return 0;
  235. }
  236. void wl1271_event_mbox_config(struct wl1271 *wl)
  237. {
  238. wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
  239. wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
  240. wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
  241. wl->mbox_ptr[0], wl->mbox_ptr[1]);
  242. }
  243. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  244. {
  245. struct event_mailbox mbox;
  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], &mbox,
  252. sizeof(struct event_mailbox), false);
  253. /* process the descriptor */
  254. ret = wl1271_event_process(wl, &mbox);
  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. }