wl1271_event.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_info("No ack to nullfunc from AP.");
  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_rssi_trigger(struct wl1271 *wl,
  114. struct event_mailbox *mbox)
  115. {
  116. enum nl80211_cqm_rssi_threshold_event event;
  117. s8 metric = mbox->rssi_snr_trigger_metric[0];
  118. wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
  119. if (metric <= wl->rssi_thold)
  120. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  121. else
  122. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  123. if (event != wl->last_rssi_event)
  124. ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL);
  125. wl->last_rssi_event = event;
  126. }
  127. static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
  128. {
  129. wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
  130. wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
  131. wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
  132. }
  133. static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
  134. {
  135. int ret;
  136. u32 vector;
  137. bool beacon_loss = false;
  138. wl1271_event_mbox_dump(mbox);
  139. vector = le32_to_cpu(mbox->events_vector);
  140. vector &= ~(le32_to_cpu(mbox->events_mask));
  141. wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
  142. if (vector & SCAN_COMPLETE_EVENT_ID) {
  143. ret = wl1271_event_scan_complete(wl, mbox);
  144. if (ret < 0)
  145. return ret;
  146. }
  147. /*
  148. * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
  149. * filtering) is enabled. Without PSM, the stack will receive all
  150. * beacons and can detect beacon loss by itself.
  151. *
  152. * As there's possibility that the driver disables PSM before receiving
  153. * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
  154. *
  155. */
  156. if (vector & BSS_LOSE_EVENT_ID) {
  157. wl1271_info("Beacon loss detected.");
  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 (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
  168. wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
  169. if (wl->vif)
  170. wl1271_event_rssi_trigger(wl, mbox);
  171. }
  172. if (wl->vif && beacon_loss)
  173. ieee80211_connection_loss(wl->vif);
  174. return 0;
  175. }
  176. int wl1271_event_unmask(struct wl1271 *wl)
  177. {
  178. int ret;
  179. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  180. if (ret < 0)
  181. return ret;
  182. return 0;
  183. }
  184. void wl1271_event_mbox_config(struct wl1271 *wl)
  185. {
  186. wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
  187. wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
  188. wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
  189. wl->mbox_ptr[0], wl->mbox_ptr[1]);
  190. }
  191. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  192. {
  193. struct event_mailbox mbox;
  194. int ret;
  195. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  196. if (mbox_num > 1)
  197. return -EINVAL;
  198. /* first we read the mbox descriptor */
  199. wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
  200. sizeof(struct event_mailbox), false);
  201. /* process the descriptor */
  202. ret = wl1271_event_process(wl, &mbox);
  203. if (ret < 0)
  204. return ret;
  205. /* then we let the firmware know it can go on...*/
  206. wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
  207. return 0;
  208. }