wl1271_event.c 5.6 KB
Newer Older
L
Luciano Coelho 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * This file is part of wl1271
 *
 * Copyright (C) 2008-2009 Nokia Corporation
 *
 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include "wl1271.h"
#include "wl1271_reg.h"
T
Teemu Paasikivi 已提交
26
#include "wl1271_io.h"
L
Luciano Coelho 已提交
27 28
#include "wl1271_event.h"
#include "wl1271_ps.h"
29
#include "wl12xx_80211.h"
L
Luciano Coelho 已提交
30 31 32 33 34 35 36

static int wl1271_event_scan_complete(struct wl1271 *wl,
				      struct event_mailbox *mbox)
{
	wl1271_debug(DEBUG_EVENT, "status: 0x%x",
		     mbox->scheduled_scan_status);

37
	if (test_bit(WL1271_FLAG_SCANNING, &wl->flags)) {
38 39 40 41 42
		if (wl->scan.state == WL1271_SCAN_BAND_DUAL) {
			/* 2.4 GHz band scanned, scan 5 GHz band, pretend
			 * to the wl1271_cmd_scan function that we are not
			 * scanning as it checks that.
			 */
43
			clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
44
			/* FIXME: ie missing! */
45
			wl1271_cmd_scan(wl, wl->scan.ssid, wl->scan.ssid_len,
46
						NULL, 0,
47 48 49 50 51 52 53 54
						wl->scan.active,
						wl->scan.high_prio,
						WL1271_SCAN_BAND_5_GHZ,
						wl->scan.probe_requests);
		} else {
			mutex_unlock(&wl->mutex);
			ieee80211_scan_completed(wl->hw, false);
			mutex_lock(&wl->mutex);
55
			clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
56 57
		}
	}
L
Luciano Coelho 已提交
58 59 60
	return 0;
}

61 62 63 64 65 66 67 68 69 70
static int wl1271_event_ps_report(struct wl1271 *wl,
				  struct event_mailbox *mbox,
				  bool *beacon_loss)
{
	int ret = 0;

	wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);

	switch (mbox->ps_status) {
	case EVENT_ENTER_POWER_SAVE_FAIL:
J
Juuso Oikarinen 已提交
71 72
		wl1271_debug(DEBUG_PSM, "PSM entry failed");

73
		if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
J
Juuso Oikarinen 已提交
74
			/* remain in active mode */
75 76 77 78
			wl->psm_entry_retry = 0;
			break;
		}

79 80
		if (wl->psm_entry_retry < wl->conf.conn.psm_entry_retries) {
			wl->psm_entry_retry++;
J
Juuso Oikarinen 已提交
81 82
			ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
						 true);
83
		} else {
84
			wl1271_error("PSM entry failed, giving up.\n");
85
			wl->psm_entry_retry = 0;
86
			*beacon_loss = true;
87 88 89 90
		}
		break;
	case EVENT_ENTER_POWER_SAVE_SUCCESS:
		wl->psm_entry_retry = 0;
J
Juuso Oikarinen 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

		/* enable beacon filtering */
		ret = wl1271_acx_beacon_filter_opt(wl, true);
		if (ret < 0)
			break;

		/* enable beacon early termination */
		ret = wl1271_acx_bet_enable(wl, true);
		if (ret < 0)
			break;

		/* go to extremely low power mode */
		wl1271_ps_elp_sleep(wl);
		if (ret < 0)
			break;
106 107
		break;
	case EVENT_EXIT_POWER_SAVE_FAIL:
J
Juuso Oikarinen 已提交
108 109 110 111 112 113 114
		wl1271_debug(DEBUG_PSM, "PSM exit failed");

		if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
			wl->psm_entry_retry = 0;
			break;
		}

115 116
		/* make sure the firmware goes to active mode - the frame to
		   be sent next will indicate to the AP, that we are active. */
J
Juuso Oikarinen 已提交
117 118
		ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
					 false);
119 120 121 122 123 124 125 126 127
		break;
	case EVENT_EXIT_POWER_SAVE_SUCCESS:
	default:
		break;
	}

	return ret;
}

L
Luciano Coelho 已提交
128 129 130 131 132 133 134 135 136 137 138
static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
{
	wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
	wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
	wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
}

static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
{
	int ret;
	u32 vector;
139
	bool beacon_loss = false;
L
Luciano Coelho 已提交
140 141 142

	wl1271_event_mbox_dump(mbox);

L
Luciano Coelho 已提交
143 144
	vector = le32_to_cpu(mbox->events_vector);
	vector &= ~(le32_to_cpu(mbox->events_mask));
L
Luciano Coelho 已提交
145 146 147 148 149 150 151 152
	wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);

	if (vector & SCAN_COMPLETE_EVENT_ID) {
		ret = wl1271_event_scan_complete(wl, mbox);
		if (ret < 0)
			return ret;
	}

153 154 155 156
	/*
	 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
	 * filtering) is enabled. Without PSM, the stack will receive all
	 * beacons and can detect beacon loss by itself.
157 158 159 160
	 *
	 * As there's possibility that the driver disables PSM before receiving
	 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
	 *
161
	 */
162
	if (vector & BSS_LOSE_EVENT_ID) {
L
Luciano Coelho 已提交
163 164
		wl1271_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");

165
		/* indicate to the stack, that beacons have been lost */
166 167 168 169 170 171 172 173 174 175
		beacon_loss = true;
	}

	if (vector & PS_REPORT_EVENT_ID) {
		wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
		ret = wl1271_event_ps_report(wl, mbox, &beacon_loss);
		if (ret < 0)
			return ret;
	}

176 177
	if (wl->vif && beacon_loss)
		ieee80211_connection_loss(wl->vif);
L
Luciano Coelho 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

	return 0;
}

int wl1271_event_unmask(struct wl1271 *wl)
{
	int ret;

	ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
	if (ret < 0)
		return ret;

	return 0;
}

void wl1271_event_mbox_config(struct wl1271 *wl)
{
T
Teemu Paasikivi 已提交
195
	wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
L
Luciano Coelho 已提交
196 197 198 199 200 201
	wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);

	wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
		     wl->mbox_ptr[0], wl->mbox_ptr[1]);
}

202
int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
L
Luciano Coelho 已提交
203 204 205 206 207 208 209 210 211 212
{
	struct event_mailbox mbox;
	int ret;

	wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);

	if (mbox_num > 1)
		return -EINVAL;

	/* first we read the mbox descriptor */
T
Teemu Paasikivi 已提交
213 214
	wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
		    sizeof(struct event_mailbox), false);
L
Luciano Coelho 已提交
215 216 217 218 219 220 221

	/* process the descriptor */
	ret = wl1271_event_process(wl, &mbox);
	if (ret < 0)
		return ret;

	/* then we let the firmware know it can go on...*/
T
Teemu Paasikivi 已提交
222
	wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
L
Luciano Coelho 已提交
223 224 225

	return 0;
}