wl1271_event.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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_spi.h"
  26. #include "wl1271_io.h"
  27. #include "wl1271_event.h"
  28. #include "wl1271_ps.h"
  29. #include "wl12xx_80211.h"
  30. static int wl1271_event_scan_complete(struct wl1271 *wl,
  31. struct event_mailbox *mbox)
  32. {
  33. int size = sizeof(struct wl12xx_probe_req_template);
  34. wl1271_debug(DEBUG_EVENT, "status: 0x%x",
  35. mbox->scheduled_scan_status);
  36. if (test_bit(WL1271_FLAG_SCANNING, &wl->flags)) {
  37. if (wl->scan.state == WL1271_SCAN_BAND_DUAL) {
  38. wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
  39. NULL, size);
  40. /* 2.4 GHz band scanned, scan 5 GHz band, pretend
  41. * to the wl1271_cmd_scan function that we are not
  42. * scanning as it checks that.
  43. */
  44. clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
  45. wl1271_cmd_scan(wl, wl->scan.ssid, wl->scan.ssid_len,
  46. wl->scan.active,
  47. wl->scan.high_prio,
  48. WL1271_SCAN_BAND_5_GHZ,
  49. wl->scan.probe_requests);
  50. } else {
  51. if (wl->scan.state == WL1271_SCAN_BAND_2_4_GHZ)
  52. wl1271_cmd_template_set(wl,
  53. CMD_TEMPL_CFG_PROBE_REQ_2_4,
  54. NULL, size);
  55. else
  56. wl1271_cmd_template_set(wl,
  57. CMD_TEMPL_CFG_PROBE_REQ_5,
  58. NULL, size);
  59. mutex_unlock(&wl->mutex);
  60. ieee80211_scan_completed(wl->hw, false);
  61. mutex_lock(&wl->mutex);
  62. clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
  63. }
  64. }
  65. return 0;
  66. }
  67. static int wl1271_event_ps_report(struct wl1271 *wl,
  68. struct event_mailbox *mbox,
  69. bool *beacon_loss)
  70. {
  71. int ret = 0;
  72. wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
  73. switch (mbox->ps_status) {
  74. case EVENT_ENTER_POWER_SAVE_FAIL:
  75. wl1271_debug(DEBUG_PSM, "PSM entry failed");
  76. if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
  77. /* remain in active mode */
  78. wl->psm_entry_retry = 0;
  79. break;
  80. }
  81. if (wl->psm_entry_retry < wl->conf.conn.psm_entry_retries) {
  82. wl->psm_entry_retry++;
  83. ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
  84. true);
  85. } else {
  86. wl1271_error("PSM entry failed, giving up.\n");
  87. /* FIXME: this may need to be reconsidered. for now it
  88. is not possible to indicate to the mac80211
  89. afterwards that PSM entry failed. To maximize
  90. functionality (receiving data and remaining
  91. associated) make sure that we are in sync with the
  92. AP in regard of PSM mode. */
  93. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
  94. false);
  95. wl->psm_entry_retry = 0;
  96. }
  97. break;
  98. case EVENT_ENTER_POWER_SAVE_SUCCESS:
  99. wl->psm_entry_retry = 0;
  100. /* enable beacon filtering */
  101. ret = wl1271_acx_beacon_filter_opt(wl, true);
  102. if (ret < 0)
  103. break;
  104. /* enable beacon early termination */
  105. ret = wl1271_acx_bet_enable(wl, true);
  106. if (ret < 0)
  107. break;
  108. /* go to extremely low power mode */
  109. wl1271_ps_elp_sleep(wl);
  110. if (ret < 0)
  111. break;
  112. break;
  113. case EVENT_EXIT_POWER_SAVE_FAIL:
  114. wl1271_debug(DEBUG_PSM, "PSM exit failed");
  115. if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
  116. wl->psm_entry_retry = 0;
  117. break;
  118. }
  119. /* make sure the firmware goes to active mode - the frame to
  120. be sent next will indicate to the AP, that we are active. */
  121. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
  122. false);
  123. break;
  124. case EVENT_EXIT_POWER_SAVE_SUCCESS:
  125. default:
  126. break;
  127. }
  128. return ret;
  129. }
  130. static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
  131. {
  132. wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
  133. wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
  134. wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
  135. }
  136. static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
  137. {
  138. int ret;
  139. u32 vector;
  140. bool beacon_loss = false;
  141. wl1271_event_mbox_dump(mbox);
  142. vector = le32_to_cpu(mbox->events_vector);
  143. vector &= ~(le32_to_cpu(mbox->events_mask));
  144. wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
  145. if (vector & SCAN_COMPLETE_EVENT_ID) {
  146. ret = wl1271_event_scan_complete(wl, mbox);
  147. if (ret < 0)
  148. return ret;
  149. }
  150. /*
  151. * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
  152. * filtering) is enabled. Without PSM, the stack will receive all
  153. * beacons and can detect beacon loss by itself.
  154. */
  155. if (vector & BSS_LOSE_EVENT_ID &&
  156. test_bit(WL1271_FLAG_PSM, &wl->flags)) {
  157. wl1271_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
  158. /* indicate to the stack, that beacons have been lost */
  159. beacon_loss = true;
  160. }
  161. if (vector & PS_REPORT_EVENT_ID) {
  162. wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
  163. ret = wl1271_event_ps_report(wl, mbox, &beacon_loss);
  164. if (ret < 0)
  165. return ret;
  166. }
  167. if (wl->vif && beacon_loss) {
  168. /* Obviously, it's dangerous to release the mutex while
  169. we are holding many of the variables in the wl struct.
  170. That's why it's done last in the function, and care must
  171. be taken that nothing more is done after this function
  172. returns. */
  173. mutex_unlock(&wl->mutex);
  174. ieee80211_beacon_loss(wl->vif);
  175. mutex_lock(&wl->mutex);
  176. }
  177. return 0;
  178. }
  179. int wl1271_event_unmask(struct wl1271 *wl)
  180. {
  181. int ret;
  182. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  183. if (ret < 0)
  184. return ret;
  185. return 0;
  186. }
  187. void wl1271_event_mbox_config(struct wl1271 *wl)
  188. {
  189. wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
  190. wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
  191. wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
  192. wl->mbox_ptr[0], wl->mbox_ptr[1]);
  193. }
  194. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  195. {
  196. struct event_mailbox mbox;
  197. int ret;
  198. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  199. if (mbox_num > 1)
  200. return -EINVAL;
  201. /* first we read the mbox descriptor */
  202. wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
  203. sizeof(struct event_mailbox), false);
  204. /* process the descriptor */
  205. ret = wl1271_event_process(wl, &mbox);
  206. if (ret < 0)
  207. return ret;
  208. /* then we let the firmware know it can go on...*/
  209. wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
  210. return 0;
  211. }