wl1251_event.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * This file is part of wl1251
  3. *
  4. * Copyright (c) 1998-2007 Texas Instruments Incorporated
  5. * Copyright (C) 2008 Nokia Corporation
  6. *
  7. * Contact: Kalle Valo <kalle.valo@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #include "wl1251.h"
  25. #include "wl1251_reg.h"
  26. #include "wl1251_io.h"
  27. #include "wl1251_event.h"
  28. #include "wl1251_ps.h"
  29. static int wl1251_event_scan_complete(struct wl1251 *wl,
  30. struct event_mailbox *mbox)
  31. {
  32. wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
  33. mbox->scheduled_scan_status,
  34. mbox->scheduled_scan_channels);
  35. if (wl->scanning) {
  36. mutex_unlock(&wl->mutex);
  37. ieee80211_scan_completed(wl->hw, false);
  38. mutex_lock(&wl->mutex);
  39. wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan completed");
  40. wl->scanning = false;
  41. }
  42. return 0;
  43. }
  44. static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
  45. {
  46. wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
  47. wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
  48. wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
  49. }
  50. static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
  51. {
  52. int ret;
  53. u32 vector;
  54. wl1251_event_mbox_dump(mbox);
  55. vector = mbox->events_vector & ~(mbox->events_mask);
  56. wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
  57. if (vector & SCAN_COMPLETE_EVENT_ID) {
  58. ret = wl1251_event_scan_complete(wl, mbox);
  59. if (ret < 0)
  60. return ret;
  61. }
  62. if (vector & BSS_LOSE_EVENT_ID) {
  63. wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
  64. if (wl->psm_requested && wl->psm) {
  65. ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
  66. if (ret < 0)
  67. return ret;
  68. }
  69. }
  70. if (vector & SYNCHRONIZATION_TIMEOUT_EVENT_ID && wl->psm) {
  71. wl1251_debug(DEBUG_EVENT, "SYNCHRONIZATION_TIMEOUT_EVENT");
  72. /* indicate to the stack, that beacons have been lost */
  73. ieee80211_beacon_loss(wl->vif);
  74. }
  75. if (vector & REGAINED_BSS_EVENT_ID) {
  76. if (wl->psm_requested) {
  77. ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
  78. if (ret < 0)
  79. return ret;
  80. }
  81. }
  82. return 0;
  83. }
  84. int wl1251_event_unmask(struct wl1251 *wl)
  85. {
  86. int ret;
  87. ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
  88. if (ret < 0)
  89. return ret;
  90. return 0;
  91. }
  92. void wl1251_event_mbox_config(struct wl1251 *wl)
  93. {
  94. wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
  95. wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
  96. wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
  97. wl->mbox_ptr[0], wl->mbox_ptr[1]);
  98. }
  99. int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
  100. {
  101. struct event_mailbox mbox;
  102. int ret;
  103. wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  104. if (mbox_num > 1)
  105. return -EINVAL;
  106. /* first we read the mbox descriptor */
  107. wl1251_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
  108. sizeof(struct event_mailbox));
  109. /* process the descriptor */
  110. ret = wl1251_event_process(wl, &mbox);
  111. if (ret < 0)
  112. return ret;
  113. /* then we let the firmware know it can go on...*/
  114. wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
  115. return 0;
  116. }