wl1271_event.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 "wl1271.h"
  24. #include "wl1271_reg.h"
  25. #include "wl1271_io.h"
  26. #include "wl1271_event.h"
  27. #include "wl1271_ps.h"
  28. #include "wl12xx_80211.h"
  29. void wl1271_pspoll_work(struct work_struct *work)
  30. {
  31. struct delayed_work *dwork;
  32. struct wl1271 *wl;
  33. dwork = container_of(work, struct delayed_work, work);
  34. wl = container_of(dwork, struct wl1271, pspoll_work);
  35. wl1271_debug(DEBUG_EVENT, "pspoll work");
  36. mutex_lock(&wl->mutex);
  37. if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags))
  38. goto out;
  39. if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
  40. goto out;
  41. /*
  42. * if we end up here, then we were in powersave when the pspoll
  43. * delivery failure occurred, and no-one changed state since, so
  44. * we should go back to powersave.
  45. */
  46. wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, true);
  47. out:
  48. mutex_unlock(&wl->mutex);
  49. };
  50. static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl)
  51. {
  52. int delay = wl->conf.conn.ps_poll_recovery_period;
  53. int ret;
  54. wl->ps_poll_failures++;
  55. if (wl->ps_poll_failures == 1)
  56. wl1271_info("AP with dysfunctional ps-poll, "
  57. "trying to work around it.");
  58. /* force active mode receive data from the AP */
  59. if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
  60. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, true);
  61. if (ret < 0)
  62. return;
  63. set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags);
  64. ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work,
  65. msecs_to_jiffies(delay));
  66. }
  67. /*
  68. * If already in active mode, lets we should be getting data from
  69. * the AP right away. If we enter PSM too fast after this, and data
  70. * remains on the AP, we will get another event like this, and we'll
  71. * go into active once more.
  72. */
  73. }
  74. static int wl1271_event_scan_complete(struct wl1271 *wl,
  75. struct event_mailbox *mbox)
  76. {
  77. wl1271_debug(DEBUG_EVENT, "status: 0x%x",
  78. mbox->scheduled_scan_status);
  79. if (test_bit(WL1271_FLAG_SCANNING, &wl->flags)) {
  80. if (wl->scan.state == WL1271_SCAN_BAND_DUAL) {
  81. /* 2.4 GHz band scanned, scan 5 GHz band, pretend
  82. * to the wl1271_cmd_scan function that we are not
  83. * scanning as it checks that.
  84. */
  85. clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
  86. /* FIXME: ie missing! */
  87. wl1271_cmd_scan(wl, wl->scan.ssid, wl->scan.ssid_len,
  88. wl->scan.req,
  89. wl->scan.active,
  90. wl->scan.high_prio,
  91. WL1271_SCAN_BAND_5_GHZ,
  92. wl->scan.probe_requests);
  93. } else {
  94. mutex_unlock(&wl->mutex);
  95. ieee80211_scan_completed(wl->hw, false);
  96. mutex_lock(&wl->mutex);
  97. clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
  98. }
  99. }
  100. return 0;
  101. }
  102. static int wl1271_event_ps_report(struct wl1271 *wl,
  103. struct event_mailbox *mbox,
  104. bool *beacon_loss)
  105. {
  106. int ret = 0;
  107. wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
  108. switch (mbox->ps_status) {
  109. case EVENT_ENTER_POWER_SAVE_FAIL:
  110. wl1271_debug(DEBUG_PSM, "PSM entry failed");
  111. if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
  112. /* remain in active mode */
  113. wl->psm_entry_retry = 0;
  114. break;
  115. }
  116. if (wl->psm_entry_retry < wl->conf.conn.psm_entry_retries) {
  117. wl->psm_entry_retry++;
  118. ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
  119. true);
  120. } else {
  121. wl1271_info("No ack to nullfunc from AP.");
  122. wl->psm_entry_retry = 0;
  123. *beacon_loss = true;
  124. }
  125. break;
  126. case EVENT_ENTER_POWER_SAVE_SUCCESS:
  127. wl->psm_entry_retry = 0;
  128. /* enable beacon filtering */
  129. ret = wl1271_acx_beacon_filter_opt(wl, true);
  130. if (ret < 0)
  131. break;
  132. /* enable beacon early termination */
  133. ret = wl1271_acx_bet_enable(wl, true);
  134. if (ret < 0)
  135. break;
  136. /* go to extremely low power mode */
  137. wl1271_ps_elp_sleep(wl);
  138. if (ret < 0)
  139. break;
  140. break;
  141. case EVENT_EXIT_POWER_SAVE_FAIL:
  142. wl1271_debug(DEBUG_PSM, "PSM exit failed");
  143. if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
  144. wl->psm_entry_retry = 0;
  145. break;
  146. }
  147. /* make sure the firmware goes to active mode - the frame to
  148. be sent next will indicate to the AP, that we are active. */
  149. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
  150. false);
  151. break;
  152. case EVENT_EXIT_POWER_SAVE_SUCCESS:
  153. default:
  154. break;
  155. }
  156. return ret;
  157. }
  158. static void wl1271_event_rssi_trigger(struct wl1271 *wl,
  159. struct event_mailbox *mbox)
  160. {
  161. enum nl80211_cqm_rssi_threshold_event event;
  162. s8 metric = mbox->rssi_snr_trigger_metric[0];
  163. wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
  164. if (metric <= wl->rssi_thold)
  165. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  166. else
  167. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  168. if (event != wl->last_rssi_event)
  169. ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL);
  170. wl->last_rssi_event = event;
  171. }
  172. static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
  173. {
  174. wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
  175. wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
  176. wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
  177. }
  178. static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
  179. {
  180. int ret;
  181. u32 vector;
  182. bool beacon_loss = false;
  183. wl1271_event_mbox_dump(mbox);
  184. vector = le32_to_cpu(mbox->events_vector);
  185. vector &= ~(le32_to_cpu(mbox->events_mask));
  186. wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
  187. if (vector & SCAN_COMPLETE_EVENT_ID) {
  188. ret = wl1271_event_scan_complete(wl, mbox);
  189. if (ret < 0)
  190. return ret;
  191. }
  192. /*
  193. * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
  194. * filtering) is enabled. Without PSM, the stack will receive all
  195. * beacons and can detect beacon loss by itself.
  196. *
  197. * As there's possibility that the driver disables PSM before receiving
  198. * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
  199. *
  200. */
  201. if (vector & BSS_LOSE_EVENT_ID) {
  202. wl1271_info("Beacon loss detected.");
  203. /* indicate to the stack, that beacons have been lost */
  204. beacon_loss = true;
  205. }
  206. if (vector & PS_REPORT_EVENT_ID) {
  207. wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
  208. ret = wl1271_event_ps_report(wl, mbox, &beacon_loss);
  209. if (ret < 0)
  210. return ret;
  211. }
  212. if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
  213. wl1271_event_pspoll_delivery_fail(wl);
  214. if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
  215. wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
  216. if (wl->vif)
  217. wl1271_event_rssi_trigger(wl, mbox);
  218. }
  219. if (wl->vif && beacon_loss)
  220. ieee80211_connection_loss(wl->vif);
  221. return 0;
  222. }
  223. int wl1271_event_unmask(struct wl1271 *wl)
  224. {
  225. int ret;
  226. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  227. if (ret < 0)
  228. return ret;
  229. return 0;
  230. }
  231. void wl1271_event_mbox_config(struct wl1271 *wl)
  232. {
  233. wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
  234. wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
  235. wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
  236. wl->mbox_ptr[0], wl->mbox_ptr[1]);
  237. }
  238. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  239. {
  240. struct event_mailbox mbox;
  241. int ret;
  242. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  243. if (mbox_num > 1)
  244. return -EINVAL;
  245. /* first we read the mbox descriptor */
  246. wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
  247. sizeof(struct event_mailbox), false);
  248. /* process the descriptor */
  249. ret = wl1271_event_process(wl, &mbox);
  250. if (ret < 0)
  251. return ret;
  252. /* then we let the firmware know it can go on...*/
  253. wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
  254. return 0;
  255. }