Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 1 | /* |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 2 | * This file is part of wl1251 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 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 | |
Kalle Valo | 1367411 | 2009-06-12 14:17:25 +0300 | [diff] [blame] | 25 | #include "wl1251.h" |
Kalle Valo | 29d904c | 2009-08-07 13:35:11 +0300 | [diff] [blame] | 26 | #include "wl1251_reg.h" |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 27 | #include "wl1251_io.h" |
Kalle Valo | ef2f8d4 | 2009-06-12 14:17:19 +0300 | [diff] [blame] | 28 | #include "wl1251_event.h" |
| 29 | #include "wl1251_ps.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 30 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 31 | static int wl1251_event_scan_complete(struct wl1251 *wl, |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 32 | struct event_mailbox *mbox) |
| 33 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 34 | wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 35 | mbox->scheduled_scan_status, |
| 36 | mbox->scheduled_scan_channels); |
| 37 | |
| 38 | if (wl->scanning) { |
| 39 | mutex_unlock(&wl->mutex); |
| 40 | ieee80211_scan_completed(wl->hw, false); |
| 41 | mutex_lock(&wl->mutex); |
Kalle Valo | 2789da9 | 2009-08-07 13:35:26 +0300 | [diff] [blame] | 42 | wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan completed"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 43 | wl->scanning = false; |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 49 | static void wl1251_event_mbox_dump(struct event_mailbox *mbox) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 50 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 51 | wl1251_debug(DEBUG_EVENT, "MBOX DUMP:"); |
| 52 | wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); |
| 53 | wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 54 | } |
| 55 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 56 | static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 57 | { |
| 58 | int ret; |
| 59 | u32 vector; |
| 60 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 61 | wl1251_event_mbox_dump(mbox); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 62 | |
| 63 | vector = mbox->events_vector & ~(mbox->events_mask); |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 64 | wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 65 | |
| 66 | if (vector & SCAN_COMPLETE_EVENT_ID) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 67 | ret = wl1251_event_scan_complete(wl, mbox); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 68 | if (ret < 0) |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | if (vector & BSS_LOSE_EVENT_ID) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 73 | wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 74 | |
| 75 | if (wl->psm_requested && wl->psm) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 76 | ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 77 | if (ret < 0) |
| 78 | return ret; |
| 79 | } |
| 80 | } |
| 81 | |
Juuso Oikarinen | 287f6f9 | 2009-11-17 18:48:23 +0200 | [diff] [blame] | 82 | if (vector & SYNCHRONIZATION_TIMEOUT_EVENT_ID && wl->psm) { |
| 83 | wl1251_debug(DEBUG_EVENT, "SYNCHRONIZATION_TIMEOUT_EVENT"); |
| 84 | |
| 85 | /* indicate to the stack, that beacons have been lost */ |
| 86 | ieee80211_beacon_loss(wl->vif); |
| 87 | } |
| 88 | |
Vidhya Govindan | 33d51fa | 2009-11-17 18:49:23 +0200 | [diff] [blame] | 89 | if (vector & REGAINED_BSS_EVENT_ID) { |
| 90 | if (wl->psm_requested) { |
| 91 | ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE); |
| 92 | if (ret < 0) |
| 93 | return ret; |
| 94 | } |
| 95 | } |
| 96 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 100 | int wl1251_event_unmask(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 101 | { |
| 102 | int ret; |
| 103 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 104 | ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 105 | if (ret < 0) |
| 106 | return ret; |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 111 | void wl1251_event_mbox_config(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 112 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 113 | wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 114 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); |
| 115 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 116 | wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 117 | wl->mbox_ptr[0], wl->mbox_ptr[1]); |
| 118 | } |
| 119 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 120 | int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 121 | { |
| 122 | struct event_mailbox mbox; |
| 123 | int ret; |
| 124 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 125 | wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 126 | |
| 127 | if (mbox_num > 1) |
| 128 | return -EINVAL; |
| 129 | |
| 130 | /* first we read the mbox descriptor */ |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 131 | wl1251_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox, |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 132 | sizeof(struct event_mailbox)); |
| 133 | |
| 134 | /* process the descriptor */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 135 | ret = wl1251_event_process(wl, &mbox); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 136 | if (ret < 0) |
| 137 | return ret; |
| 138 | |
| 139 | /* then we let the firmware know it can go on...*/ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 140 | wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 141 | |
| 142 | return 0; |
| 143 | } |