wl1271_event.c 5.6 KB

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