blob: 74544e11f69204827cd786cdfba59f54bc05a1e5 [file] [log] [blame]
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001/*
Kalle Valo80301cd2009-06-12 14:17:39 +03002 * This file is part of wl1251
Kalle Valo2f01a1f2009-04-29 23:33:31 +03003 *
4 * Copyright (C) 2008-2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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
24#include <linux/module.h>
25#include <linux/interrupt.h>
26#include <linux/firmware.h>
27#include <linux/delay.h>
28#include <linux/irq.h>
Kalle Valo2f01a1f2009-04-29 23:33:31 +030029#include <linux/crc32.h>
30#include <linux/etherdevice.h>
Kalle Valo2f01a1f2009-04-29 23:33:31 +030031
Kalle Valo13674112009-06-12 14:17:25 +030032#include "wl1251.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030033#include "wl12xx_80211.h"
34#include "reg.h"
Kalle Valoe6f0b5c2009-06-12 14:16:58 +030035#include "wl1251_ops.h"
Bob Copeland0764de62009-08-07 13:32:56 +030036#include "wl1251_io.h"
Bob Copeland8e639c02009-08-07 13:33:26 +030037#include "wl1251_cmd.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +030038#include "wl1251_event.h"
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +030039#include "wl1251_tx.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +030040#include "wl1251_rx.h"
41#include "wl1251_ps.h"
42#include "wl1251_init.h"
43#include "wl1251_debugfs.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030044
Kalle Valo80301cd2009-06-12 14:17:39 +030045static void wl1251_disable_interrupts(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030046{
47 disable_irq(wl->irq);
48}
49
Kalle Valo80301cd2009-06-12 14:17:39 +030050static void wl1251_power_off(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030051{
52 wl->set_power(false);
53}
54
Kalle Valo80301cd2009-06-12 14:17:39 +030055static void wl1251_power_on(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030056{
57 wl->set_power(true);
58}
59
Bob Copeland8e639c02009-08-07 13:33:26 +030060irqreturn_t wl1251_irq(int irq, void *cookie)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030061{
Kalle Valo80301cd2009-06-12 14:17:39 +030062 struct wl1251 *wl;
Kalle Valo2f01a1f2009-04-29 23:33:31 +030063
Kalle Valo80301cd2009-06-12 14:17:39 +030064 wl1251_debug(DEBUG_IRQ, "IRQ");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030065
66 wl = cookie;
67
68 schedule_work(&wl->irq_work);
69
70 return IRQ_HANDLED;
71}
72
Kalle Valo80301cd2009-06-12 14:17:39 +030073static int wl1251_fetch_firmware(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030074{
75 const struct firmware *fw;
Bob Copeland6c766f42009-08-07 13:33:04 +030076 struct device *dev = wiphy_dev(wl->hw->wiphy);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030077 int ret;
78
Bob Copeland6c766f42009-08-07 13:33:04 +030079 ret = request_firmware(&fw, wl->chip.fw_filename, dev);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030080
81 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +030082 wl1251_error("could not get firmware: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030083 return ret;
84 }
85
86 if (fw->size % 4) {
Kalle Valo80301cd2009-06-12 14:17:39 +030087 wl1251_error("firmware size is not multiple of 32 bits: %zu",
Kalle Valo2f01a1f2009-04-29 23:33:31 +030088 fw->size);
89 ret = -EILSEQ;
90 goto out;
91 }
92
93 wl->fw_len = fw->size;
94 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
95
96 if (!wl->fw) {
Kalle Valo80301cd2009-06-12 14:17:39 +030097 wl1251_error("could not allocate memory for the firmware");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030098 ret = -ENOMEM;
99 goto out;
100 }
101
102 memcpy(wl->fw, fw->data, wl->fw_len);
103
104 ret = 0;
105
106out:
107 release_firmware(fw);
108
109 return ret;
110}
111
Kalle Valo80301cd2009-06-12 14:17:39 +0300112static int wl1251_fetch_nvs(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300113{
114 const struct firmware *fw;
Bob Copeland6c766f42009-08-07 13:33:04 +0300115 struct device *dev = wiphy_dev(wl->hw->wiphy);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300116 int ret;
117
Bob Copeland6c766f42009-08-07 13:33:04 +0300118 ret = request_firmware(&fw, wl->chip.nvs_filename, dev);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300119
120 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300121 wl1251_error("could not get nvs file: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300122 return ret;
123 }
124
125 if (fw->size % 4) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300126 wl1251_error("nvs size is not multiple of 32 bits: %zu",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300127 fw->size);
128 ret = -EILSEQ;
129 goto out;
130 }
131
132 wl->nvs_len = fw->size;
133 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
134
135 if (!wl->nvs) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300136 wl1251_error("could not allocate memory for the nvs file");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300137 ret = -ENOMEM;
138 goto out;
139 }
140
141 memcpy(wl->nvs, fw->data, wl->nvs_len);
142
143 ret = 0;
144
145out:
146 release_firmware(fw);
147
148 return ret;
149}
150
Kalle Valo80301cd2009-06-12 14:17:39 +0300151static void wl1251_fw_wakeup(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300152{
153 u32 elp_reg;
154
155 elp_reg = ELPCTRL_WAKE_UP;
Kalle Valo80301cd2009-06-12 14:17:39 +0300156 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
157 elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300158
Kalle Valo05fac682009-06-12 14:17:47 +0300159 if (!(elp_reg & ELPCTRL_WLAN_READY))
Kalle Valo80301cd2009-06-12 14:17:39 +0300160 wl1251_warning("WLAN not ready");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300161}
162
Kalle Valo80301cd2009-06-12 14:17:39 +0300163static int wl1251_chip_wakeup(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300164{
165 int ret = 0;
166
Kalle Valo80301cd2009-06-12 14:17:39 +0300167 wl1251_power_on(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300168 msleep(wl->chip.power_on_sleep);
Bob Copeland08d9f5722009-08-07 13:33:11 +0300169 wl->if_ops->reset(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300170
171 /* We don't need a real memory partition here, because we only want
172 * to use the registers at this point. */
Kalle Valo80301cd2009-06-12 14:17:39 +0300173 wl1251_set_partition(wl,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300174 0x00000000,
175 0x00000000,
176 REGISTERS_BASE,
177 REGISTERS_DOWN_SIZE);
178
179 /* ELP module wake up */
Kalle Valo80301cd2009-06-12 14:17:39 +0300180 wl1251_fw_wakeup(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300181
182 /* whal_FwCtrl_BootSm() */
183
184 /* 0. read chip id from CHIP_ID */
Kalle Valo80301cd2009-06-12 14:17:39 +0300185 wl->chip.id = wl1251_reg_read32(wl, CHIP_ID_B);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300186
187 /* 1. check if chip id is valid */
188
189 switch (wl->chip.id) {
190 case CHIP_ID_1251_PG12:
Kalle Valo80301cd2009-06-12 14:17:39 +0300191 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300192 wl->chip.id);
193
194 wl1251_setup(wl);
195
196 break;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300197 case CHIP_ID_1251_PG10:
198 case CHIP_ID_1251_PG11:
199 default:
Kalle Valo80301cd2009-06-12 14:17:39 +0300200 wl1251_error("unsupported chip id: 0x%x", wl->chip.id);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300201 ret = -ENODEV;
202 goto out;
203 }
204
205 if (wl->fw == NULL) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300206 ret = wl1251_fetch_firmware(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300207 if (ret < 0)
208 goto out;
209 }
210
211 /* No NVS from netlink, try to get it from the filesystem */
212 if (wl->nvs == NULL) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300213 ret = wl1251_fetch_nvs(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300214 if (ret < 0)
215 goto out;
216 }
217
218out:
219 return ret;
220}
221
Kalle Valo80301cd2009-06-12 14:17:39 +0300222static void wl1251_filter_work(struct work_struct *work)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300223{
Kalle Valo80301cd2009-06-12 14:17:39 +0300224 struct wl1251 *wl =
225 container_of(work, struct wl1251, filter_work);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300226 int ret;
227
228 mutex_lock(&wl->mutex);
229
Kalle Valo80301cd2009-06-12 14:17:39 +0300230 if (wl->state == WL1251_STATE_OFF)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300231 goto out;
232
Kalle Valo80301cd2009-06-12 14:17:39 +0300233 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300234 if (ret < 0)
235 goto out;
236
Juuso Oikarinen77cc9e42009-06-12 14:16:52 +0300237 /* FIXME: replace the magic numbers with proper definitions */
238 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
Kalle Valoc5483b72009-06-12 14:16:32 +0300239 if (ret < 0)
240 goto out_sleep;
241
242out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +0300243 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300244
245out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300246 mutex_unlock(&wl->mutex);
247}
248
Kalle Valo80301cd2009-06-12 14:17:39 +0300249static int wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300250{
Kalle Valo80301cd2009-06-12 14:17:39 +0300251 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300252
253 skb_queue_tail(&wl->tx_queue, skb);
254
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300255 /*
256 * The chip specific setup must run before the first TX packet -
257 * before that, the tx_work will not be initialized!
258 */
259
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300260 schedule_work(&wl->tx_work);
261
262 /*
263 * The workqueue is slow to process the tx_queue and we need stop
264 * the queue here, otherwise the queue will get too long.
265 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300266 if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_MAX_LENGTH) {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300267 ieee80211_stop_queues(wl->hw);
268
269 /*
270 * FIXME: this is racy, the variable is not properly
271 * protected. Maybe fix this by removing the stupid
272 * variable altogether and checking the real queue state?
273 */
274 wl->tx_queue_stopped = true;
275 }
276
277 return NETDEV_TX_OK;
278}
279
Kalle Valo80301cd2009-06-12 14:17:39 +0300280static int wl1251_op_start(struct ieee80211_hw *hw)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300281{
Kalle Valo80301cd2009-06-12 14:17:39 +0300282 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300283 int ret = 0;
284
Kalle Valo80301cd2009-06-12 14:17:39 +0300285 wl1251_debug(DEBUG_MAC80211, "mac80211 start");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300286
287 mutex_lock(&wl->mutex);
288
Kalle Valo80301cd2009-06-12 14:17:39 +0300289 if (wl->state != WL1251_STATE_OFF) {
290 wl1251_error("cannot start because not in off state: %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300291 wl->state);
292 ret = -EBUSY;
293 goto out;
294 }
295
Kalle Valo80301cd2009-06-12 14:17:39 +0300296 ret = wl1251_chip_wakeup(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300297 if (ret < 0)
Jiri Slabyfe643412009-07-14 22:37:13 +0200298 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300299
300 ret = wl->chip.op_boot(wl);
301 if (ret < 0)
302 goto out;
303
304 ret = wl->chip.op_hw_init(wl);
305 if (ret < 0)
306 goto out;
307
Kalle Valo80301cd2009-06-12 14:17:39 +0300308 ret = wl1251_acx_station_id(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300309 if (ret < 0)
310 goto out;
311
Kalle Valo80301cd2009-06-12 14:17:39 +0300312 wl->state = WL1251_STATE_ON;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300313
Kalle Valo80301cd2009-06-12 14:17:39 +0300314 wl1251_info("firmware booted (%s)", wl->chip.fw_ver);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300315
316out:
317 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +0300318 wl1251_power_off(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300319
320 mutex_unlock(&wl->mutex);
321
322 return ret;
323}
324
Kalle Valo80301cd2009-06-12 14:17:39 +0300325static void wl1251_op_stop(struct ieee80211_hw *hw)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300326{
Kalle Valo80301cd2009-06-12 14:17:39 +0300327 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300328
Kalle Valo80301cd2009-06-12 14:17:39 +0300329 wl1251_info("down");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300330
Kalle Valo80301cd2009-06-12 14:17:39 +0300331 wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300332
333 mutex_lock(&wl->mutex);
334
Kalle Valo80301cd2009-06-12 14:17:39 +0300335 WARN_ON(wl->state != WL1251_STATE_ON);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300336
337 if (wl->scanning) {
338 mutex_unlock(&wl->mutex);
339 ieee80211_scan_completed(wl->hw, true);
340 mutex_lock(&wl->mutex);
341 wl->scanning = false;
342 }
343
Kalle Valo80301cd2009-06-12 14:17:39 +0300344 wl->state = WL1251_STATE_OFF;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300345
Kalle Valo80301cd2009-06-12 14:17:39 +0300346 wl1251_disable_interrupts(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300347
348 mutex_unlock(&wl->mutex);
349
350 cancel_work_sync(&wl->irq_work);
351 cancel_work_sync(&wl->tx_work);
352 cancel_work_sync(&wl->filter_work);
353
354 mutex_lock(&wl->mutex);
355
356 /* let's notify MAC80211 about the remaining pending TX frames */
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300357 wl->chip.op_tx_flush(wl);
Kalle Valo80301cd2009-06-12 14:17:39 +0300358 wl1251_power_off(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300359
360 memset(wl->bssid, 0, ETH_ALEN);
361 wl->listen_int = 1;
362 wl->bss_type = MAX_BSS_TYPE;
363
364 wl->data_in_count = 0;
365 wl->rx_counter = 0;
366 wl->rx_handled = 0;
367 wl->rx_current_buffer = 0;
368 wl->rx_last_id = 0;
369 wl->next_tx_complete = 0;
370 wl->elp = false;
371 wl->psm = 0;
372 wl->tx_queue_stopped = false;
Kalle Valo80301cd2009-06-12 14:17:39 +0300373 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300374
Kalle Valo80301cd2009-06-12 14:17:39 +0300375 wl1251_debugfs_reset(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300376
377 mutex_unlock(&wl->mutex);
378}
379
Kalle Valo80301cd2009-06-12 14:17:39 +0300380static int wl1251_op_add_interface(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300381 struct ieee80211_if_init_conf *conf)
382{
Kalle Valo80301cd2009-06-12 14:17:39 +0300383 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300384 int ret = 0;
385
Johannes Berge91d8332009-07-15 17:21:41 +0200386 wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
387 conf->type, conf->mac_addr);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300388
389 mutex_lock(&wl->mutex);
390
391 switch (conf->type) {
392 case NL80211_IFTYPE_STATION:
393 wl->bss_type = BSS_TYPE_STA_BSS;
394 break;
395 case NL80211_IFTYPE_ADHOC:
396 wl->bss_type = BSS_TYPE_IBSS;
397 break;
398 default:
399 ret = -EOPNOTSUPP;
400 goto out;
401 }
402
403 if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) {
404 memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
405 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
Kalle Valo80301cd2009-06-12 14:17:39 +0300406 ret = wl1251_acx_station_id(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300407 if (ret < 0)
408 goto out;
409 }
410
411out:
412 mutex_unlock(&wl->mutex);
413 return ret;
414}
415
Kalle Valo80301cd2009-06-12 14:17:39 +0300416static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300417 struct ieee80211_if_init_conf *conf)
418{
Kalle Valo80301cd2009-06-12 14:17:39 +0300419 wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300420}
421
Kalle Valo80301cd2009-06-12 14:17:39 +0300422static int wl1251_build_null_data(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300423{
424 struct wl12xx_null_data_template template;
425
426 if (!is_zero_ether_addr(wl->bssid)) {
427 memcpy(template.header.da, wl->bssid, ETH_ALEN);
428 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
429 } else {
430 memset(template.header.da, 0xff, ETH_ALEN);
431 memset(template.header.bssid, 0xff, ETH_ALEN);
432 }
433
434 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
435 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
436 IEEE80211_STYPE_NULLFUNC);
437
Kalle Valo80301cd2009-06-12 14:17:39 +0300438 return wl1251_cmd_template_set(wl, CMD_NULL_DATA, &template,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300439 sizeof(template));
440
441}
442
Kalle Valo80301cd2009-06-12 14:17:39 +0300443static int wl1251_build_ps_poll(struct wl1251 *wl, u16 aid)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300444{
445 struct wl12xx_ps_poll_template template;
446
447 memcpy(template.bssid, wl->bssid, ETH_ALEN);
448 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
449 template.aid = aid;
450 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
451
Kalle Valo80301cd2009-06-12 14:17:39 +0300452 return wl1251_cmd_template_set(wl, CMD_PS_POLL, &template,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300453 sizeof(template));
454
455}
456
Kalle Valo80301cd2009-06-12 14:17:39 +0300457static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300458{
Kalle Valo80301cd2009-06-12 14:17:39 +0300459 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300460 struct ieee80211_conf *conf = &hw->conf;
461 int channel, ret = 0;
462
463 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
464
Kalle Valo80301cd2009-06-12 14:17:39 +0300465 wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300466 channel,
467 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
468 conf->power_level);
469
470 mutex_lock(&wl->mutex);
471
Kalle Valo80301cd2009-06-12 14:17:39 +0300472 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300473 if (ret < 0)
474 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300475
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300476 if (channel != wl->channel) {
477 /* FIXME: use beacon interval provided by mac80211 */
Juuso Oikarinen77cc9e42009-06-12 14:16:52 +0300478 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300479 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300480 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300481
482 wl->channel = channel;
483 }
484
Kalle Valo80301cd2009-06-12 14:17:39 +0300485 ret = wl1251_build_null_data(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300486 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300487 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300488
489 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
Luciano Coelho47af3fe2009-06-12 14:17:53 +0300490 wl1251_debug(DEBUG_PSM, "psm enabled");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300491
492 wl->psm_requested = true;
493
494 /*
495 * We enter PSM only if we're already associated.
496 * If we're not, we'll enter it when joining an SSID,
497 * through the bss_info_changed() hook.
498 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300499 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300500 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
501 wl->psm_requested) {
Luciano Coelho47af3fe2009-06-12 14:17:53 +0300502 wl1251_debug(DEBUG_PSM, "psm disabled");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300503
504 wl->psm_requested = false;
505
506 if (wl->psm)
Kalle Valo80301cd2009-06-12 14:17:39 +0300507 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300508 }
509
510 if (conf->power_level != wl->power_level) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300511 ret = wl1251_acx_tx_power(wl, conf->power_level);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300512 if (ret < 0)
513 goto out;
514
515 wl->power_level = conf->power_level;
516 }
517
Kalle Valoc5483b72009-06-12 14:16:32 +0300518out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +0300519 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300520
521out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300522 mutex_unlock(&wl->mutex);
Kalle Valoc5483b72009-06-12 14:16:32 +0300523
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300524 return ret;
525}
526
Kalle Valo80301cd2009-06-12 14:17:39 +0300527#define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300528 FIF_ALLMULTI | \
529 FIF_FCSFAIL | \
530 FIF_BCN_PRBRESP_PROMISC | \
531 FIF_CONTROL | \
532 FIF_OTHER_BSS)
533
Kalle Valo80301cd2009-06-12 14:17:39 +0300534static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300535 unsigned int changed,
536 unsigned int *total,
537 int mc_count,
538 struct dev_addr_list *mc_list)
539{
Kalle Valo80301cd2009-06-12 14:17:39 +0300540 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300541
Kalle Valo80301cd2009-06-12 14:17:39 +0300542 wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300543
Kalle Valo80301cd2009-06-12 14:17:39 +0300544 *total &= WL1251_SUPPORTED_FILTERS;
545 changed &= WL1251_SUPPORTED_FILTERS;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300546
547 if (changed == 0)
548 /* no filters which we support changed */
549 return;
550
551 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
552
Kalle Valo80301cd2009-06-12 14:17:39 +0300553 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
554 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300555
556 if (*total & FIF_PROMISC_IN_BSS) {
557 wl->rx_config |= CFG_BSSID_FILTER_EN;
558 wl->rx_config |= CFG_RX_ALL_GOOD;
559 }
560 if (*total & FIF_ALLMULTI)
561 /*
562 * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
563 * all multicast frames
564 */
565 wl->rx_config &= ~CFG_MC_FILTER_EN;
566 if (*total & FIF_FCSFAIL)
567 wl->rx_filter |= CFG_RX_FCS_ERROR;
568 if (*total & FIF_BCN_PRBRESP_PROMISC) {
569 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
570 wl->rx_config &= ~CFG_SSID_FILTER_EN;
571 }
572 if (*total & FIF_CONTROL)
573 wl->rx_filter |= CFG_RX_CTL_EN;
574 if (*total & FIF_OTHER_BSS)
575 wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
576
577 /*
578 * FIXME: workqueues need to be properly cancelled on stop(), for
579 * now let's just disable changing the filter settings. They will
580 * be updated any on config().
581 */
582 /* schedule_work(&wl->filter_work); */
583}
584
585/* HW encryption */
Kalle Valo80301cd2009-06-12 14:17:39 +0300586static int wl1251_set_key_type(struct wl1251 *wl,
587 struct wl1251_cmd_set_keys *key,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300588 enum set_key_cmd cmd,
589 struct ieee80211_key_conf *mac80211_key,
590 const u8 *addr)
591{
592 switch (mac80211_key->alg) {
593 case ALG_WEP:
594 if (is_broadcast_ether_addr(addr))
595 key->key_type = KEY_WEP_DEFAULT;
596 else
597 key->key_type = KEY_WEP_ADDR;
598
599 mac80211_key->hw_key_idx = mac80211_key->keyidx;
600 break;
601 case ALG_TKIP:
602 if (is_broadcast_ether_addr(addr))
603 key->key_type = KEY_TKIP_MIC_GROUP;
604 else
605 key->key_type = KEY_TKIP_MIC_PAIRWISE;
606
607 mac80211_key->hw_key_idx = mac80211_key->keyidx;
608 break;
609 case ALG_CCMP:
610 if (is_broadcast_ether_addr(addr))
611 key->key_type = KEY_AES_GROUP;
612 else
613 key->key_type = KEY_AES_PAIRWISE;
614 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
615 break;
616 default:
Kalle Valo80301cd2009-06-12 14:17:39 +0300617 wl1251_error("Unknown key algo 0x%x", mac80211_key->alg);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300618 return -EOPNOTSUPP;
619 }
620
621 return 0;
622}
623
Kalle Valo80301cd2009-06-12 14:17:39 +0300624static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300625 struct ieee80211_vif *vif,
626 struct ieee80211_sta *sta,
627 struct ieee80211_key_conf *key)
628{
Kalle Valo80301cd2009-06-12 14:17:39 +0300629 struct wl1251 *wl = hw->priv;
630 struct wl1251_cmd_set_keys *wl_cmd;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300631 const u8 *addr;
632 int ret;
633
634 static const u8 bcast_addr[ETH_ALEN] =
635 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
636
Kalle Valo80301cd2009-06-12 14:17:39 +0300637 wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300638
Kalle Valoff258392009-06-12 14:14:19 +0300639 wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
640 if (!wl_cmd) {
641 ret = -ENOMEM;
642 goto out;
643 }
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300644
645 addr = sta ? sta->addr : bcast_addr;
646
Kalle Valo80301cd2009-06-12 14:17:39 +0300647 wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
648 wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
649 wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300650 key->alg, key->keyidx, key->keylen, key->flags);
Kalle Valo80301cd2009-06-12 14:17:39 +0300651 wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300652
Kalle Valoff258392009-06-12 14:14:19 +0300653 if (is_zero_ether_addr(addr)) {
654 /* We dont support TX only encryption */
655 ret = -EOPNOTSUPP;
656 goto out;
657 }
658
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300659 mutex_lock(&wl->mutex);
660
Kalle Valo80301cd2009-06-12 14:17:39 +0300661 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300662 if (ret < 0)
663 goto out_unlock;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300664
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300665 switch (cmd) {
666 case SET_KEY:
Kalle Valoff258392009-06-12 14:14:19 +0300667 wl_cmd->key_action = KEY_ADD_OR_REPLACE;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300668 break;
669 case DISABLE_KEY:
Kalle Valoff258392009-06-12 14:14:19 +0300670 wl_cmd->key_action = KEY_REMOVE;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300671 break;
672 default:
Kalle Valo80301cd2009-06-12 14:17:39 +0300673 wl1251_error("Unsupported key cmd 0x%x", cmd);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300674 break;
675 }
676
Kalle Valo80301cd2009-06-12 14:17:39 +0300677 ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300678 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300679 wl1251_error("Set KEY type failed");
Kalle Valoc5483b72009-06-12 14:16:32 +0300680 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300681 }
682
Kalle Valoff258392009-06-12 14:14:19 +0300683 if (wl_cmd->key_type != KEY_WEP_DEFAULT)
684 memcpy(wl_cmd->addr, addr, ETH_ALEN);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300685
Kalle Valoff258392009-06-12 14:14:19 +0300686 if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
687 (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300688 /*
689 * We get the key in the following form:
690 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
691 * but the target is expecting:
692 * TKIP - RX MIC - TX MIC
693 */
Kalle Valoff258392009-06-12 14:14:19 +0300694 memcpy(wl_cmd->key, key->key, 16);
695 memcpy(wl_cmd->key + 16, key->key + 24, 8);
696 memcpy(wl_cmd->key + 24, key->key + 16, 8);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300697
698 } else {
Kalle Valoff258392009-06-12 14:14:19 +0300699 memcpy(wl_cmd->key, key->key, key->keylen);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300700 }
Kalle Valoff258392009-06-12 14:14:19 +0300701 wl_cmd->key_size = key->keylen;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300702
Kalle Valoff258392009-06-12 14:14:19 +0300703 wl_cmd->id = key->keyidx;
704 wl_cmd->ssid_profile = 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300705
Kalle Valo80301cd2009-06-12 14:17:39 +0300706 wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300707
Kalle Valo80301cd2009-06-12 14:17:39 +0300708 ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
Kalle Valoff258392009-06-12 14:14:19 +0300709 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300710 wl1251_warning("could not set keys");
Kalle Valoc5483b72009-06-12 14:16:32 +0300711 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300712 }
713
Kalle Valoc5483b72009-06-12 14:16:32 +0300714out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +0300715 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300716
717out_unlock:
Kalle Valoff258392009-06-12 14:14:19 +0300718 mutex_unlock(&wl->mutex);
719
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300720out:
Kalle Valoff258392009-06-12 14:14:19 +0300721 kfree(wl_cmd);
722
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300723 return ret;
724}
725
Kalle Valo80301cd2009-06-12 14:17:39 +0300726static int wl1251_build_basic_rates(char *rates)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300727{
728 u8 index = 0;
729
730 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
731 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
732 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
733 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
734
735 return index;
736}
737
Kalle Valo80301cd2009-06-12 14:17:39 +0300738static int wl1251_build_extended_rates(char *rates)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300739{
740 u8 index = 0;
741
742 rates[index++] = IEEE80211_OFDM_RATE_6MB;
743 rates[index++] = IEEE80211_OFDM_RATE_9MB;
744 rates[index++] = IEEE80211_OFDM_RATE_12MB;
745 rates[index++] = IEEE80211_OFDM_RATE_18MB;
746 rates[index++] = IEEE80211_OFDM_RATE_24MB;
747 rates[index++] = IEEE80211_OFDM_RATE_36MB;
748 rates[index++] = IEEE80211_OFDM_RATE_48MB;
749 rates[index++] = IEEE80211_OFDM_RATE_54MB;
750
751 return index;
752}
753
754
Kalle Valo80301cd2009-06-12 14:17:39 +0300755static int wl1251_build_probe_req(struct wl1251 *wl, u8 *ssid, size_t ssid_len)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300756{
757 struct wl12xx_probe_req_template template;
758 struct wl12xx_ie_rates *rates;
759 char *ptr;
760 u16 size;
761
762 ptr = (char *)&template;
763 size = sizeof(struct ieee80211_header);
764
765 memset(template.header.da, 0xff, ETH_ALEN);
766 memset(template.header.bssid, 0xff, ETH_ALEN);
767 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
768 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
769
770 /* IEs */
771 /* SSID */
772 template.ssid.header.id = WLAN_EID_SSID;
773 template.ssid.header.len = ssid_len;
774 if (ssid_len && ssid)
775 memcpy(template.ssid.ssid, ssid, ssid_len);
776 size += sizeof(struct wl12xx_ie_header) + ssid_len;
777 ptr += size;
778
779 /* Basic Rates */
780 rates = (struct wl12xx_ie_rates *)ptr;
781 rates->header.id = WLAN_EID_SUPP_RATES;
Kalle Valo80301cd2009-06-12 14:17:39 +0300782 rates->header.len = wl1251_build_basic_rates(rates->rates);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300783 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
784 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
785
786 /* Extended rates */
787 rates = (struct wl12xx_ie_rates *)ptr;
788 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
Kalle Valo80301cd2009-06-12 14:17:39 +0300789 rates->header.len = wl1251_build_extended_rates(rates->rates);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300790 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
791
Kalle Valo80301cd2009-06-12 14:17:39 +0300792 wl1251_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300793
Kalle Valo80301cd2009-06-12 14:17:39 +0300794 return wl1251_cmd_template_set(wl, CMD_PROBE_REQ, &template,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300795 size);
796}
797
Kalle Valo80301cd2009-06-12 14:17:39 +0300798static int wl1251_hw_scan(struct wl1251 *wl, u8 *ssid, size_t len,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300799 u8 active_scan, u8 high_prio, u8 num_channels,
800 u8 probe_requests)
801{
Kalle Valo80301cd2009-06-12 14:17:39 +0300802 struct wl1251_cmd_trigger_scan_to *trigger = NULL;
Kalle Valoff258392009-06-12 14:14:19 +0300803 struct cmd_scan *params = NULL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300804 int i, ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300805 u16 scan_options = 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300806
807 if (wl->scanning)
808 return -EINVAL;
809
810 params = kzalloc(sizeof(*params), GFP_KERNEL);
811 if (!params)
812 return -ENOMEM;
813
814 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
815 params->params.rx_filter_options =
816 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
817
818 /* High priority scan */
819 if (!active_scan)
820 scan_options |= SCAN_PASSIVE;
821 if (high_prio)
822 scan_options |= SCAN_PRIORITY_HIGH;
823 params->params.scan_options = scan_options;
824
825 params->params.num_channels = num_channels;
826 params->params.num_probe_requests = probe_requests;
827 params->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
828 params->params.tid_trigger = 0;
829
830 for (i = 0; i < num_channels; i++) {
831 params->channels[i].min_duration = cpu_to_le32(30000);
832 params->channels[i].max_duration = cpu_to_le32(60000);
833 memset(&params->channels[i].bssid_lsb, 0xff, 4);
834 memset(&params->channels[i].bssid_msb, 0xff, 2);
835 params->channels[i].early_termination = 0;
836 params->channels[i].tx_power_att = 0;
837 params->channels[i].channel = i + 1;
838 memset(params->channels[i].pad, 0, 3);
839 }
840
841 for (i = num_channels; i < SCAN_MAX_NUM_OF_CHANNELS; i++)
842 memset(&params->channels[i], 0,
843 sizeof(struct basic_scan_channel_parameters));
844
845 if (len && ssid) {
846 params->params.ssid_len = len;
847 memcpy(params->params.ssid, ssid, len);
848 } else {
849 params->params.ssid_len = 0;
850 memset(params->params.ssid, 0, 32);
851 }
852
Kalle Valo80301cd2009-06-12 14:17:39 +0300853 ret = wl1251_build_probe_req(wl, ssid, len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300854 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300855 wl1251_error("PROBE request template failed");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300856 goto out;
857 }
858
Kalle Valoff258392009-06-12 14:14:19 +0300859 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
860 if (!trigger)
861 goto out;
862
863 trigger->timeout = 0;
864
Kalle Valo80301cd2009-06-12 14:17:39 +0300865 ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
Kalle Valoff258392009-06-12 14:14:19 +0300866 sizeof(*trigger));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300867 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300868 wl1251_error("trigger scan to failed for hw scan");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300869 goto out;
870 }
871
Kalle Valo80301cd2009-06-12 14:17:39 +0300872 wl1251_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300873
874 wl->scanning = true;
875
Kalle Valo80301cd2009-06-12 14:17:39 +0300876 ret = wl1251_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300877 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +0300878 wl1251_error("SCAN failed");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300879
Bob Copeland0764de62009-08-07 13:32:56 +0300880 wl1251_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300881
Kalle Valoff258392009-06-12 14:14:19 +0300882 if (params->header.status != CMD_STATUS_SUCCESS) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300883 wl1251_error("TEST command answer error: %d",
Kalle Valoff258392009-06-12 14:14:19 +0300884 params->header.status);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300885 wl->scanning = false;
886 ret = -EIO;
887 goto out;
888 }
889
890out:
891 kfree(params);
892 return ret;
893
894}
895
Kalle Valo80301cd2009-06-12 14:17:39 +0300896static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300897 struct cfg80211_scan_request *req)
898{
Kalle Valo80301cd2009-06-12 14:17:39 +0300899 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300900 int ret;
901 u8 *ssid = NULL;
902 size_t ssid_len = 0;
903
Kalle Valo80301cd2009-06-12 14:17:39 +0300904 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300905
906 if (req->n_ssids) {
907 ssid = req->ssids[0].ssid;
908 ssid_len = req->ssids[0].ssid_len;
909 }
910
911 mutex_lock(&wl->mutex);
Kalle Valoc5483b72009-06-12 14:16:32 +0300912
Kalle Valo80301cd2009-06-12 14:17:39 +0300913 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300914 if (ret < 0)
915 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300916
Kalle Valo80301cd2009-06-12 14:17:39 +0300917 ret = wl1251_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300918
Kalle Valo80301cd2009-06-12 14:17:39 +0300919 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300920
921out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300922 mutex_unlock(&wl->mutex);
923
924 return ret;
925}
926
Kalle Valo80301cd2009-06-12 14:17:39 +0300927static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300928{
Kalle Valo80301cd2009-06-12 14:17:39 +0300929 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300930 int ret;
931
Kalle Valocee4fd22009-06-12 14:16:20 +0300932 mutex_lock(&wl->mutex);
933
Kalle Valo80301cd2009-06-12 14:17:39 +0300934 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300935 if (ret < 0)
936 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300937
Kalle Valo80301cd2009-06-12 14:17:39 +0300938 ret = wl1251_acx_rts_threshold(wl, (u16) value);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300939 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +0300940 wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300941
Kalle Valo80301cd2009-06-12 14:17:39 +0300942 wl1251_ps_elp_sleep(wl);
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300943
Kalle Valoc5483b72009-06-12 14:16:32 +0300944out:
Kalle Valocee4fd22009-06-12 14:16:20 +0300945 mutex_unlock(&wl->mutex);
946
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300947 return ret;
948}
949
Kalle Valo80301cd2009-06-12 14:17:39 +0300950static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300951 struct ieee80211_vif *vif,
952 struct ieee80211_bss_conf *bss_conf,
953 u32 changed)
954{
Kalle Valo80301cd2009-06-12 14:17:39 +0300955 enum wl1251_cmd_ps_mode mode;
956 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300957 struct sk_buff *beacon;
958 int ret;
959
Kalle Valo80301cd2009-06-12 14:17:39 +0300960 wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300961
962 mutex_lock(&wl->mutex);
963
Kalle Valo80301cd2009-06-12 14:17:39 +0300964 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300965 if (ret < 0)
966 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300967
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300968 if (changed & BSS_CHANGED_ASSOC) {
969 if (bss_conf->assoc) {
970 wl->aid = bss_conf->aid;
971
Kalle Valo80301cd2009-06-12 14:17:39 +0300972 ret = wl1251_build_ps_poll(wl, wl->aid);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300973 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300974 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300975
Kalle Valo80301cd2009-06-12 14:17:39 +0300976 ret = wl1251_acx_aid(wl, wl->aid);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300977 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300978 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300979
980 /* If we want to go in PSM but we're not there yet */
981 if (wl->psm_requested && !wl->psm) {
982 mode = STATION_POWER_SAVE_MODE;
Kalle Valo80301cd2009-06-12 14:17:39 +0300983 ret = wl1251_ps_set_mode(wl, mode);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300984 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300985 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300986 }
987 }
988 }
989 if (changed & BSS_CHANGED_ERP_SLOT) {
990 if (bss_conf->use_short_slot)
Kalle Valo80301cd2009-06-12 14:17:39 +0300991 ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300992 else
Kalle Valo80301cd2009-06-12 14:17:39 +0300993 ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300994 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300995 wl1251_warning("Set slot time failed %d", ret);
Kalle Valoc5483b72009-06-12 14:16:32 +0300996 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300997 }
998 }
999
1000 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1001 if (bss_conf->use_short_preamble)
Kalle Valo80301cd2009-06-12 14:17:39 +03001002 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001003 else
Kalle Valo80301cd2009-06-12 14:17:39 +03001004 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001005 }
1006
1007 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1008 if (bss_conf->use_cts_prot)
Kalle Valo80301cd2009-06-12 14:17:39 +03001009 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001010 else
Kalle Valo80301cd2009-06-12 14:17:39 +03001011 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001012 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001013 wl1251_warning("Set ctsprotect failed %d", ret);
1014 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001015 }
1016 }
1017
1018 if (changed & BSS_CHANGED_BSSID) {
1019 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1020
Kalle Valo80301cd2009-06-12 14:17:39 +03001021 ret = wl1251_build_null_data(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001022 if (ret < 0)
1023 goto out;
1024
1025 if (wl->bss_type != BSS_TYPE_IBSS) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001026 ret = wl1251_cmd_join(wl, wl->bss_type, 5, 100, 1);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001027 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +03001028 goto out_sleep;
1029 wl1251_warning("Set ctsprotect failed %d", ret);
1030 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001031 }
1032 }
1033
1034 if (changed & BSS_CHANGED_BEACON) {
1035 beacon = ieee80211_beacon_get(hw, vif);
Kalle Valo80301cd2009-06-12 14:17:39 +03001036 ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001037 beacon->len);
1038
1039 if (ret < 0) {
1040 dev_kfree_skb(beacon);
1041 goto out;
1042 }
1043
Kalle Valo80301cd2009-06-12 14:17:39 +03001044 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001045 beacon->len);
1046
1047 dev_kfree_skb(beacon);
1048
1049 if (ret < 0)
1050 goto out;
1051
Juuso Oikarinen77cc9e42009-06-12 14:16:52 +03001052 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001053
1054 if (ret < 0)
1055 goto out;
1056 }
1057
Kalle Valoc5483b72009-06-12 14:16:32 +03001058out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +03001059 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +03001060
1061out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001062 mutex_unlock(&wl->mutex);
1063}
1064
1065
1066/* can't be const, mac80211 writes to this */
Kalle Valo80301cd2009-06-12 14:17:39 +03001067static struct ieee80211_rate wl1251_rates[] = {
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001068 { .bitrate = 10,
1069 .hw_value = 0x1,
1070 .hw_value_short = 0x1, },
1071 { .bitrate = 20,
1072 .hw_value = 0x2,
1073 .hw_value_short = 0x2,
1074 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1075 { .bitrate = 55,
1076 .hw_value = 0x4,
1077 .hw_value_short = 0x4,
1078 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1079 { .bitrate = 110,
1080 .hw_value = 0x20,
1081 .hw_value_short = 0x20,
1082 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1083 { .bitrate = 60,
1084 .hw_value = 0x8,
1085 .hw_value_short = 0x8, },
1086 { .bitrate = 90,
1087 .hw_value = 0x10,
1088 .hw_value_short = 0x10, },
1089 { .bitrate = 120,
1090 .hw_value = 0x40,
1091 .hw_value_short = 0x40, },
1092 { .bitrate = 180,
1093 .hw_value = 0x80,
1094 .hw_value_short = 0x80, },
1095 { .bitrate = 240,
1096 .hw_value = 0x200,
1097 .hw_value_short = 0x200, },
1098 { .bitrate = 360,
1099 .hw_value = 0x400,
1100 .hw_value_short = 0x400, },
1101 { .bitrate = 480,
1102 .hw_value = 0x800,
1103 .hw_value_short = 0x800, },
1104 { .bitrate = 540,
1105 .hw_value = 0x1000,
1106 .hw_value_short = 0x1000, },
1107};
1108
1109/* can't be const, mac80211 writes to this */
Kalle Valo80301cd2009-06-12 14:17:39 +03001110static struct ieee80211_channel wl1251_channels[] = {
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001111 { .hw_value = 1, .center_freq = 2412},
1112 { .hw_value = 2, .center_freq = 2417},
1113 { .hw_value = 3, .center_freq = 2422},
1114 { .hw_value = 4, .center_freq = 2427},
1115 { .hw_value = 5, .center_freq = 2432},
1116 { .hw_value = 6, .center_freq = 2437},
1117 { .hw_value = 7, .center_freq = 2442},
1118 { .hw_value = 8, .center_freq = 2447},
1119 { .hw_value = 9, .center_freq = 2452},
1120 { .hw_value = 10, .center_freq = 2457},
1121 { .hw_value = 11, .center_freq = 2462},
1122 { .hw_value = 12, .center_freq = 2467},
1123 { .hw_value = 13, .center_freq = 2472},
1124};
1125
1126/* can't be const, mac80211 writes to this */
Kalle Valo80301cd2009-06-12 14:17:39 +03001127static struct ieee80211_supported_band wl1251_band_2ghz = {
1128 .channels = wl1251_channels,
1129 .n_channels = ARRAY_SIZE(wl1251_channels),
1130 .bitrates = wl1251_rates,
1131 .n_bitrates = ARRAY_SIZE(wl1251_rates),
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001132};
1133
Kalle Valo80301cd2009-06-12 14:17:39 +03001134static const struct ieee80211_ops wl1251_ops = {
1135 .start = wl1251_op_start,
1136 .stop = wl1251_op_stop,
1137 .add_interface = wl1251_op_add_interface,
1138 .remove_interface = wl1251_op_remove_interface,
1139 .config = wl1251_op_config,
1140 .configure_filter = wl1251_op_configure_filter,
1141 .tx = wl1251_op_tx,
1142 .set_key = wl1251_op_set_key,
1143 .hw_scan = wl1251_op_hw_scan,
1144 .bss_info_changed = wl1251_op_bss_info_changed,
1145 .set_rts_threshold = wl1251_op_set_rts_threshold,
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001146};
1147
Kalle Valo80301cd2009-06-12 14:17:39 +03001148static int wl1251_register_hw(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001149{
1150 int ret;
1151
1152 if (wl->mac80211_registered)
1153 return 0;
1154
1155 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1156
1157 ret = ieee80211_register_hw(wl->hw);
1158 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001159 wl1251_error("unable to register mac80211 hw: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001160 return ret;
1161 }
1162
1163 wl->mac80211_registered = true;
1164
Kalle Valo80301cd2009-06-12 14:17:39 +03001165 wl1251_notice("loaded");
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001166
1167 return 0;
1168}
1169
Bob Copeland8e639c02009-08-07 13:33:26 +03001170int wl1251_init_ieee80211(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001171{
Bob Copeland8e639c02009-08-07 13:33:26 +03001172 int ret;
1173
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001174 /* The tx descriptor buffer and the TKIP space */
1175 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +03001176 + WL1251_TKIP_IV_SPACE;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001177
1178 /* unit us */
1179 /* FIXME: find a proper value */
1180 wl->hw->channel_change_time = 10000;
1181
1182 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1183 IEEE80211_HW_NOISE_DBM;
1184
1185 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1186 wl->hw->wiphy->max_scan_ssids = 1;
Kalle Valo80301cd2009-06-12 14:17:39 +03001187 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001188
Bob Copeland8e639c02009-08-07 13:33:26 +03001189 ret = wl1251_register_hw(wl);
1190 if (ret)
1191 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001192
Bob Copeland8e639c02009-08-07 13:33:26 +03001193 wl1251_debugfs_init(wl);
1194 wl1251_notice("initialized");
1195
1196 ret = 0;
1197
1198out:
1199 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001200}
1201
Kalle Valo80301cd2009-06-12 14:17:39 +03001202#define WL1251_DEFAULT_CHANNEL 1
Bob Copeland8e639c02009-08-07 13:33:26 +03001203struct ieee80211_hw *wl1251_alloc_hw(void)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001204{
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001205 struct ieee80211_hw *hw;
Kalle Valo80301cd2009-06-12 14:17:39 +03001206 struct wl1251 *wl;
Bob Copeland8e639c02009-08-07 13:33:26 +03001207 int i;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001208 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1209
Kalle Valo80301cd2009-06-12 14:17:39 +03001210 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001211 if (!hw) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001212 wl1251_error("could not alloc ieee80211_hw");
Bob Copeland8e639c02009-08-07 13:33:26 +03001213 return ERR_PTR(-ENOMEM);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001214 }
1215
1216 wl = hw->priv;
1217 memset(wl, 0, sizeof(*wl));
1218
1219 wl->hw = hw;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001220
1221 wl->data_in_count = 0;
1222
1223 skb_queue_head_init(&wl->tx_queue);
1224
Kalle Valo80301cd2009-06-12 14:17:39 +03001225 INIT_WORK(&wl->filter_work, wl1251_filter_work);
1226 wl->channel = WL1251_DEFAULT_CHANNEL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001227 wl->scanning = false;
1228 wl->default_key = 0;
1229 wl->listen_int = 1;
1230 wl->rx_counter = 0;
1231 wl->rx_handled = 0;
1232 wl->rx_current_buffer = 0;
1233 wl->rx_last_id = 0;
Kalle Valo80301cd2009-06-12 14:17:39 +03001234 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
1235 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001236 wl->elp = false;
1237 wl->psm = 0;
1238 wl->psm_requested = false;
1239 wl->tx_queue_stopped = false;
Kalle Valo80301cd2009-06-12 14:17:39 +03001240 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001241
1242 /* We use the default power on sleep time until we know which chip
1243 * we're using */
Kalle Valo80301cd2009-06-12 14:17:39 +03001244 wl->chip.power_on_sleep = WL1251_DEFAULT_POWER_ON_SLEEP;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001245
1246 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1247 wl->tx_frames[i] = NULL;
1248
1249 wl->next_tx_complete = 0;
1250
1251 /*
1252 * In case our MAC address is not correctly set,
1253 * we use a random but Nokia MAC.
1254 */
1255 memcpy(wl->mac_addr, nokia_oui, 3);
1256 get_random_bytes(wl->mac_addr + 3, 3);
1257
Kalle Valo80301cd2009-06-12 14:17:39 +03001258 wl->state = WL1251_STATE_OFF;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001259 mutex_init(&wl->mutex);
1260
1261 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1262 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1263
Kalle Valo47212132009-06-12 14:15:08 +03001264 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1265 if (!wl->rx_descriptor) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001266 wl1251_error("could not allocate memory for rx descriptor");
Bob Copeland8e639c02009-08-07 13:33:26 +03001267 ieee80211_free_hw(hw);
1268 return ERR_PTR(-ENOMEM);
Kalle Valo47212132009-06-12 14:15:08 +03001269 }
1270
Bob Copeland8e639c02009-08-07 13:33:26 +03001271 return hw;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001272}
1273
Bob Copeland8e639c02009-08-07 13:33:26 +03001274int wl1251_free_hw(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001275{
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001276 ieee80211_unregister_hw(wl->hw);
1277
Kalle Valo80301cd2009-06-12 14:17:39 +03001278 wl1251_debugfs_exit(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001279
1280 free_irq(wl->irq, wl);
1281 kfree(wl->target_mem_map);
1282 kfree(wl->data_path);
1283 kfree(wl->fw);
1284 wl->fw = NULL;
1285 kfree(wl->nvs);
1286 wl->nvs = NULL;
Kalle Valo47212132009-06-12 14:15:08 +03001287
1288 kfree(wl->rx_descriptor);
1289 wl->rx_descriptor = NULL;
1290
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001291 ieee80211_free_hw(wl->hw);
1292
1293 return 0;
1294}