blob: abe157a174c7a4b3087c42c25ce4a047573c9f1f [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}
Bob Copelandaf8c78e2009-08-07 13:33:34 +030072EXPORT_SYMBOL_GPL(wl1251_irq);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030073
Kalle Valo80301cd2009-06-12 14:17:39 +030074static int wl1251_fetch_firmware(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030075{
76 const struct firmware *fw;
Bob Copeland6c766f42009-08-07 13:33:04 +030077 struct device *dev = wiphy_dev(wl->hw->wiphy);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030078 int ret;
79
Bob Copeland6c766f42009-08-07 13:33:04 +030080 ret = request_firmware(&fw, wl->chip.fw_filename, dev);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030081
82 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +030083 wl1251_error("could not get firmware: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030084 return ret;
85 }
86
87 if (fw->size % 4) {
Kalle Valo80301cd2009-06-12 14:17:39 +030088 wl1251_error("firmware size is not multiple of 32 bits: %zu",
Kalle Valo2f01a1f2009-04-29 23:33:31 +030089 fw->size);
90 ret = -EILSEQ;
91 goto out;
92 }
93
94 wl->fw_len = fw->size;
95 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
96
97 if (!wl->fw) {
Kalle Valo80301cd2009-06-12 14:17:39 +030098 wl1251_error("could not allocate memory for the firmware");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030099 ret = -ENOMEM;
100 goto out;
101 }
102
103 memcpy(wl->fw, fw->data, wl->fw_len);
104
105 ret = 0;
106
107out:
108 release_firmware(fw);
109
110 return ret;
111}
112
Kalle Valo80301cd2009-06-12 14:17:39 +0300113static int wl1251_fetch_nvs(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300114{
115 const struct firmware *fw;
Bob Copeland6c766f42009-08-07 13:33:04 +0300116 struct device *dev = wiphy_dev(wl->hw->wiphy);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300117 int ret;
118
Bob Copeland6c766f42009-08-07 13:33:04 +0300119 ret = request_firmware(&fw, wl->chip.nvs_filename, dev);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300120
121 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300122 wl1251_error("could not get nvs file: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300123 return ret;
124 }
125
126 if (fw->size % 4) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300127 wl1251_error("nvs size is not multiple of 32 bits: %zu",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300128 fw->size);
129 ret = -EILSEQ;
130 goto out;
131 }
132
133 wl->nvs_len = fw->size;
134 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
135
136 if (!wl->nvs) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300137 wl1251_error("could not allocate memory for the nvs file");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300138 ret = -ENOMEM;
139 goto out;
140 }
141
142 memcpy(wl->nvs, fw->data, wl->nvs_len);
143
144 ret = 0;
145
146out:
147 release_firmware(fw);
148
149 return ret;
150}
151
Kalle Valo80301cd2009-06-12 14:17:39 +0300152static void wl1251_fw_wakeup(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300153{
154 u32 elp_reg;
155
156 elp_reg = ELPCTRL_WAKE_UP;
Kalle Valo80301cd2009-06-12 14:17:39 +0300157 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
158 elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300159
Kalle Valo05fac682009-06-12 14:17:47 +0300160 if (!(elp_reg & ELPCTRL_WLAN_READY))
Kalle Valo80301cd2009-06-12 14:17:39 +0300161 wl1251_warning("WLAN not ready");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300162}
163
Kalle Valo80301cd2009-06-12 14:17:39 +0300164static int wl1251_chip_wakeup(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300165{
166 int ret = 0;
167
Kalle Valo80301cd2009-06-12 14:17:39 +0300168 wl1251_power_on(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300169 msleep(wl->chip.power_on_sleep);
Bob Copeland08d9f5722009-08-07 13:33:11 +0300170 wl->if_ops->reset(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300171
172 /* We don't need a real memory partition here, because we only want
173 * to use the registers at this point. */
Kalle Valo80301cd2009-06-12 14:17:39 +0300174 wl1251_set_partition(wl,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300175 0x00000000,
176 0x00000000,
177 REGISTERS_BASE,
178 REGISTERS_DOWN_SIZE);
179
180 /* ELP module wake up */
Kalle Valo80301cd2009-06-12 14:17:39 +0300181 wl1251_fw_wakeup(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300182
183 /* whal_FwCtrl_BootSm() */
184
185 /* 0. read chip id from CHIP_ID */
Kalle Valo80301cd2009-06-12 14:17:39 +0300186 wl->chip.id = wl1251_reg_read32(wl, CHIP_ID_B);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300187
188 /* 1. check if chip id is valid */
189
190 switch (wl->chip.id) {
191 case CHIP_ID_1251_PG12:
Kalle Valo80301cd2009-06-12 14:17:39 +0300192 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300193 wl->chip.id);
194
195 wl1251_setup(wl);
196
197 break;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300198 case CHIP_ID_1251_PG10:
199 case CHIP_ID_1251_PG11:
200 default:
Kalle Valo80301cd2009-06-12 14:17:39 +0300201 wl1251_error("unsupported chip id: 0x%x", wl->chip.id);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300202 ret = -ENODEV;
203 goto out;
204 }
205
206 if (wl->fw == NULL) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300207 ret = wl1251_fetch_firmware(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300208 if (ret < 0)
209 goto out;
210 }
211
212 /* No NVS from netlink, try to get it from the filesystem */
213 if (wl->nvs == NULL) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300214 ret = wl1251_fetch_nvs(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300215 if (ret < 0)
216 goto out;
217 }
218
219out:
220 return ret;
221}
222
Kalle Valo80301cd2009-06-12 14:17:39 +0300223static void wl1251_filter_work(struct work_struct *work)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300224{
Kalle Valo80301cd2009-06-12 14:17:39 +0300225 struct wl1251 *wl =
226 container_of(work, struct wl1251, filter_work);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300227 int ret;
228
229 mutex_lock(&wl->mutex);
230
Kalle Valo80301cd2009-06-12 14:17:39 +0300231 if (wl->state == WL1251_STATE_OFF)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300232 goto out;
233
Kalle Valo80301cd2009-06-12 14:17:39 +0300234 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300235 if (ret < 0)
236 goto out;
237
Juuso Oikarinen77cc9e42009-06-12 14:16:52 +0300238 /* FIXME: replace the magic numbers with proper definitions */
239 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
Kalle Valoc5483b72009-06-12 14:16:32 +0300240 if (ret < 0)
241 goto out_sleep;
242
243out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +0300244 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300245
246out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300247 mutex_unlock(&wl->mutex);
248}
249
Kalle Valo80301cd2009-06-12 14:17:39 +0300250static int wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300251{
Kalle Valo80301cd2009-06-12 14:17:39 +0300252 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300253
254 skb_queue_tail(&wl->tx_queue, skb);
255
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300256 /*
257 * The chip specific setup must run before the first TX packet -
258 * before that, the tx_work will not be initialized!
259 */
260
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300261 schedule_work(&wl->tx_work);
262
263 /*
264 * The workqueue is slow to process the tx_queue and we need stop
265 * the queue here, otherwise the queue will get too long.
266 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300267 if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_MAX_LENGTH) {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300268 ieee80211_stop_queues(wl->hw);
269
270 /*
271 * FIXME: this is racy, the variable is not properly
272 * protected. Maybe fix this by removing the stupid
273 * variable altogether and checking the real queue state?
274 */
275 wl->tx_queue_stopped = true;
276 }
277
278 return NETDEV_TX_OK;
279}
280
Kalle Valo80301cd2009-06-12 14:17:39 +0300281static int wl1251_op_start(struct ieee80211_hw *hw)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300282{
Kalle Valo80301cd2009-06-12 14:17:39 +0300283 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300284 int ret = 0;
285
Kalle Valo80301cd2009-06-12 14:17:39 +0300286 wl1251_debug(DEBUG_MAC80211, "mac80211 start");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300287
288 mutex_lock(&wl->mutex);
289
Kalle Valo80301cd2009-06-12 14:17:39 +0300290 if (wl->state != WL1251_STATE_OFF) {
291 wl1251_error("cannot start because not in off state: %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300292 wl->state);
293 ret = -EBUSY;
294 goto out;
295 }
296
Kalle Valo80301cd2009-06-12 14:17:39 +0300297 ret = wl1251_chip_wakeup(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300298 if (ret < 0)
Jiri Slabyfe643412009-07-14 22:37:13 +0200299 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300300
301 ret = wl->chip.op_boot(wl);
302 if (ret < 0)
303 goto out;
304
305 ret = wl->chip.op_hw_init(wl);
306 if (ret < 0)
307 goto out;
308
Kalle Valo80301cd2009-06-12 14:17:39 +0300309 ret = wl1251_acx_station_id(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300310 if (ret < 0)
311 goto out;
312
Kalle Valo80301cd2009-06-12 14:17:39 +0300313 wl->state = WL1251_STATE_ON;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300314
Kalle Valo80301cd2009-06-12 14:17:39 +0300315 wl1251_info("firmware booted (%s)", wl->chip.fw_ver);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300316
317out:
318 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +0300319 wl1251_power_off(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300320
321 mutex_unlock(&wl->mutex);
322
323 return ret;
324}
325
Kalle Valo80301cd2009-06-12 14:17:39 +0300326static void wl1251_op_stop(struct ieee80211_hw *hw)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300327{
Kalle Valo80301cd2009-06-12 14:17:39 +0300328 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300329
Kalle Valo80301cd2009-06-12 14:17:39 +0300330 wl1251_info("down");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300331
Kalle Valo80301cd2009-06-12 14:17:39 +0300332 wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300333
334 mutex_lock(&wl->mutex);
335
Kalle Valo80301cd2009-06-12 14:17:39 +0300336 WARN_ON(wl->state != WL1251_STATE_ON);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300337
338 if (wl->scanning) {
339 mutex_unlock(&wl->mutex);
340 ieee80211_scan_completed(wl->hw, true);
341 mutex_lock(&wl->mutex);
342 wl->scanning = false;
343 }
344
Kalle Valo80301cd2009-06-12 14:17:39 +0300345 wl->state = WL1251_STATE_OFF;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300346
Kalle Valo80301cd2009-06-12 14:17:39 +0300347 wl1251_disable_interrupts(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300348
349 mutex_unlock(&wl->mutex);
350
351 cancel_work_sync(&wl->irq_work);
352 cancel_work_sync(&wl->tx_work);
353 cancel_work_sync(&wl->filter_work);
354
355 mutex_lock(&wl->mutex);
356
357 /* let's notify MAC80211 about the remaining pending TX frames */
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300358 wl->chip.op_tx_flush(wl);
Kalle Valo80301cd2009-06-12 14:17:39 +0300359 wl1251_power_off(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300360
361 memset(wl->bssid, 0, ETH_ALEN);
362 wl->listen_int = 1;
363 wl->bss_type = MAX_BSS_TYPE;
364
365 wl->data_in_count = 0;
366 wl->rx_counter = 0;
367 wl->rx_handled = 0;
368 wl->rx_current_buffer = 0;
369 wl->rx_last_id = 0;
370 wl->next_tx_complete = 0;
371 wl->elp = false;
372 wl->psm = 0;
373 wl->tx_queue_stopped = false;
Kalle Valo80301cd2009-06-12 14:17:39 +0300374 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300375
Kalle Valo80301cd2009-06-12 14:17:39 +0300376 wl1251_debugfs_reset(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300377
378 mutex_unlock(&wl->mutex);
379}
380
Kalle Valo80301cd2009-06-12 14:17:39 +0300381static int wl1251_op_add_interface(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300382 struct ieee80211_if_init_conf *conf)
383{
Kalle Valo80301cd2009-06-12 14:17:39 +0300384 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300385 int ret = 0;
386
Johannes Berge91d8332009-07-15 17:21:41 +0200387 wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
388 conf->type, conf->mac_addr);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300389
390 mutex_lock(&wl->mutex);
391
392 switch (conf->type) {
393 case NL80211_IFTYPE_STATION:
394 wl->bss_type = BSS_TYPE_STA_BSS;
395 break;
396 case NL80211_IFTYPE_ADHOC:
397 wl->bss_type = BSS_TYPE_IBSS;
398 break;
399 default:
400 ret = -EOPNOTSUPP;
401 goto out;
402 }
403
404 if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) {
405 memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
406 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
Kalle Valo80301cd2009-06-12 14:17:39 +0300407 ret = wl1251_acx_station_id(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300408 if (ret < 0)
409 goto out;
410 }
411
412out:
413 mutex_unlock(&wl->mutex);
414 return ret;
415}
416
Kalle Valo80301cd2009-06-12 14:17:39 +0300417static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300418 struct ieee80211_if_init_conf *conf)
419{
Kalle Valo80301cd2009-06-12 14:17:39 +0300420 wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300421}
422
Kalle Valo80301cd2009-06-12 14:17:39 +0300423static int wl1251_build_null_data(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300424{
425 struct wl12xx_null_data_template template;
426
427 if (!is_zero_ether_addr(wl->bssid)) {
428 memcpy(template.header.da, wl->bssid, ETH_ALEN);
429 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
430 } else {
431 memset(template.header.da, 0xff, ETH_ALEN);
432 memset(template.header.bssid, 0xff, ETH_ALEN);
433 }
434
435 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
436 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
437 IEEE80211_STYPE_NULLFUNC);
438
Kalle Valo80301cd2009-06-12 14:17:39 +0300439 return wl1251_cmd_template_set(wl, CMD_NULL_DATA, &template,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300440 sizeof(template));
441
442}
443
Kalle Valo80301cd2009-06-12 14:17:39 +0300444static int wl1251_build_ps_poll(struct wl1251 *wl, u16 aid)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300445{
446 struct wl12xx_ps_poll_template template;
447
448 memcpy(template.bssid, wl->bssid, ETH_ALEN);
449 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
450 template.aid = aid;
451 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
452
Kalle Valo80301cd2009-06-12 14:17:39 +0300453 return wl1251_cmd_template_set(wl, CMD_PS_POLL, &template,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300454 sizeof(template));
455
456}
457
Kalle Valo80301cd2009-06-12 14:17:39 +0300458static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300459{
Kalle Valo80301cd2009-06-12 14:17:39 +0300460 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300461 struct ieee80211_conf *conf = &hw->conf;
462 int channel, ret = 0;
463
464 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
465
Kalle Valo80301cd2009-06-12 14:17:39 +0300466 wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300467 channel,
468 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
469 conf->power_level);
470
471 mutex_lock(&wl->mutex);
472
Kalle Valo80301cd2009-06-12 14:17:39 +0300473 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300474 if (ret < 0)
475 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300476
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300477 if (channel != wl->channel) {
478 /* FIXME: use beacon interval provided by mac80211 */
Juuso Oikarinen77cc9e42009-06-12 14:16:52 +0300479 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300480 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300481 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300482
483 wl->channel = channel;
484 }
485
Kalle Valo80301cd2009-06-12 14:17:39 +0300486 ret = wl1251_build_null_data(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300487 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300488 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300489
490 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
Luciano Coelho47af3fe2009-06-12 14:17:53 +0300491 wl1251_debug(DEBUG_PSM, "psm enabled");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300492
493 wl->psm_requested = true;
494
495 /*
496 * We enter PSM only if we're already associated.
497 * If we're not, we'll enter it when joining an SSID,
498 * through the bss_info_changed() hook.
499 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300500 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300501 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
502 wl->psm_requested) {
Luciano Coelho47af3fe2009-06-12 14:17:53 +0300503 wl1251_debug(DEBUG_PSM, "psm disabled");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300504
505 wl->psm_requested = false;
506
507 if (wl->psm)
Kalle Valo80301cd2009-06-12 14:17:39 +0300508 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300509 }
510
511 if (conf->power_level != wl->power_level) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300512 ret = wl1251_acx_tx_power(wl, conf->power_level);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300513 if (ret < 0)
514 goto out;
515
516 wl->power_level = conf->power_level;
517 }
518
Kalle Valoc5483b72009-06-12 14:16:32 +0300519out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +0300520 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300521
522out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300523 mutex_unlock(&wl->mutex);
Kalle Valoc5483b72009-06-12 14:16:32 +0300524
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300525 return ret;
526}
527
Kalle Valo80301cd2009-06-12 14:17:39 +0300528#define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300529 FIF_ALLMULTI | \
530 FIF_FCSFAIL | \
531 FIF_BCN_PRBRESP_PROMISC | \
532 FIF_CONTROL | \
533 FIF_OTHER_BSS)
534
Kalle Valo80301cd2009-06-12 14:17:39 +0300535static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300536 unsigned int changed,
537 unsigned int *total,
538 int mc_count,
539 struct dev_addr_list *mc_list)
540{
Kalle Valo80301cd2009-06-12 14:17:39 +0300541 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300542
Kalle Valo80301cd2009-06-12 14:17:39 +0300543 wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300544
Kalle Valo80301cd2009-06-12 14:17:39 +0300545 *total &= WL1251_SUPPORTED_FILTERS;
546 changed &= WL1251_SUPPORTED_FILTERS;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300547
548 if (changed == 0)
549 /* no filters which we support changed */
550 return;
551
552 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
553
Kalle Valo80301cd2009-06-12 14:17:39 +0300554 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
555 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300556
557 if (*total & FIF_PROMISC_IN_BSS) {
558 wl->rx_config |= CFG_BSSID_FILTER_EN;
559 wl->rx_config |= CFG_RX_ALL_GOOD;
560 }
561 if (*total & FIF_ALLMULTI)
562 /*
563 * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
564 * all multicast frames
565 */
566 wl->rx_config &= ~CFG_MC_FILTER_EN;
567 if (*total & FIF_FCSFAIL)
568 wl->rx_filter |= CFG_RX_FCS_ERROR;
569 if (*total & FIF_BCN_PRBRESP_PROMISC) {
570 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
571 wl->rx_config &= ~CFG_SSID_FILTER_EN;
572 }
573 if (*total & FIF_CONTROL)
574 wl->rx_filter |= CFG_RX_CTL_EN;
575 if (*total & FIF_OTHER_BSS)
576 wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
577
578 /*
579 * FIXME: workqueues need to be properly cancelled on stop(), for
580 * now let's just disable changing the filter settings. They will
581 * be updated any on config().
582 */
583 /* schedule_work(&wl->filter_work); */
584}
585
586/* HW encryption */
Kalle Valo80301cd2009-06-12 14:17:39 +0300587static int wl1251_set_key_type(struct wl1251 *wl,
588 struct wl1251_cmd_set_keys *key,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300589 enum set_key_cmd cmd,
590 struct ieee80211_key_conf *mac80211_key,
591 const u8 *addr)
592{
593 switch (mac80211_key->alg) {
594 case ALG_WEP:
595 if (is_broadcast_ether_addr(addr))
596 key->key_type = KEY_WEP_DEFAULT;
597 else
598 key->key_type = KEY_WEP_ADDR;
599
600 mac80211_key->hw_key_idx = mac80211_key->keyidx;
601 break;
602 case ALG_TKIP:
603 if (is_broadcast_ether_addr(addr))
604 key->key_type = KEY_TKIP_MIC_GROUP;
605 else
606 key->key_type = KEY_TKIP_MIC_PAIRWISE;
607
608 mac80211_key->hw_key_idx = mac80211_key->keyidx;
609 break;
610 case ALG_CCMP:
611 if (is_broadcast_ether_addr(addr))
612 key->key_type = KEY_AES_GROUP;
613 else
614 key->key_type = KEY_AES_PAIRWISE;
615 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
616 break;
617 default:
Kalle Valo80301cd2009-06-12 14:17:39 +0300618 wl1251_error("Unknown key algo 0x%x", mac80211_key->alg);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300619 return -EOPNOTSUPP;
620 }
621
622 return 0;
623}
624
Kalle Valo80301cd2009-06-12 14:17:39 +0300625static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300626 struct ieee80211_vif *vif,
627 struct ieee80211_sta *sta,
628 struct ieee80211_key_conf *key)
629{
Kalle Valo80301cd2009-06-12 14:17:39 +0300630 struct wl1251 *wl = hw->priv;
631 struct wl1251_cmd_set_keys *wl_cmd;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300632 const u8 *addr;
633 int ret;
634
635 static const u8 bcast_addr[ETH_ALEN] =
636 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
637
Kalle Valo80301cd2009-06-12 14:17:39 +0300638 wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300639
Kalle Valoff258392009-06-12 14:14:19 +0300640 wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
641 if (!wl_cmd) {
642 ret = -ENOMEM;
643 goto out;
644 }
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300645
646 addr = sta ? sta->addr : bcast_addr;
647
Kalle Valo80301cd2009-06-12 14:17:39 +0300648 wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
649 wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
650 wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300651 key->alg, key->keyidx, key->keylen, key->flags);
Kalle Valo80301cd2009-06-12 14:17:39 +0300652 wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300653
Kalle Valoff258392009-06-12 14:14:19 +0300654 if (is_zero_ether_addr(addr)) {
655 /* We dont support TX only encryption */
656 ret = -EOPNOTSUPP;
657 goto out;
658 }
659
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300660 mutex_lock(&wl->mutex);
661
Kalle Valo80301cd2009-06-12 14:17:39 +0300662 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300663 if (ret < 0)
664 goto out_unlock;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300665
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300666 switch (cmd) {
667 case SET_KEY:
Kalle Valoff258392009-06-12 14:14:19 +0300668 wl_cmd->key_action = KEY_ADD_OR_REPLACE;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300669 break;
670 case DISABLE_KEY:
Kalle Valoff258392009-06-12 14:14:19 +0300671 wl_cmd->key_action = KEY_REMOVE;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300672 break;
673 default:
Kalle Valo80301cd2009-06-12 14:17:39 +0300674 wl1251_error("Unsupported key cmd 0x%x", cmd);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300675 break;
676 }
677
Kalle Valo80301cd2009-06-12 14:17:39 +0300678 ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300679 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300680 wl1251_error("Set KEY type failed");
Kalle Valoc5483b72009-06-12 14:16:32 +0300681 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300682 }
683
Kalle Valoff258392009-06-12 14:14:19 +0300684 if (wl_cmd->key_type != KEY_WEP_DEFAULT)
685 memcpy(wl_cmd->addr, addr, ETH_ALEN);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300686
Kalle Valoff258392009-06-12 14:14:19 +0300687 if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
688 (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300689 /*
690 * We get the key in the following form:
691 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
692 * but the target is expecting:
693 * TKIP - RX MIC - TX MIC
694 */
Kalle Valoff258392009-06-12 14:14:19 +0300695 memcpy(wl_cmd->key, key->key, 16);
696 memcpy(wl_cmd->key + 16, key->key + 24, 8);
697 memcpy(wl_cmd->key + 24, key->key + 16, 8);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300698
699 } else {
Kalle Valoff258392009-06-12 14:14:19 +0300700 memcpy(wl_cmd->key, key->key, key->keylen);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300701 }
Kalle Valoff258392009-06-12 14:14:19 +0300702 wl_cmd->key_size = key->keylen;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300703
Kalle Valoff258392009-06-12 14:14:19 +0300704 wl_cmd->id = key->keyidx;
705 wl_cmd->ssid_profile = 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300706
Kalle Valo80301cd2009-06-12 14:17:39 +0300707 wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300708
Kalle Valo80301cd2009-06-12 14:17:39 +0300709 ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
Kalle Valoff258392009-06-12 14:14:19 +0300710 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300711 wl1251_warning("could not set keys");
Kalle Valoc5483b72009-06-12 14:16:32 +0300712 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300713 }
714
Kalle Valoc5483b72009-06-12 14:16:32 +0300715out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +0300716 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300717
718out_unlock:
Kalle Valoff258392009-06-12 14:14:19 +0300719 mutex_unlock(&wl->mutex);
720
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300721out:
Kalle Valoff258392009-06-12 14:14:19 +0300722 kfree(wl_cmd);
723
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300724 return ret;
725}
726
Kalle Valo80301cd2009-06-12 14:17:39 +0300727static int wl1251_build_basic_rates(char *rates)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300728{
729 u8 index = 0;
730
731 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
732 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
733 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
734 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
735
736 return index;
737}
738
Kalle Valo80301cd2009-06-12 14:17:39 +0300739static int wl1251_build_extended_rates(char *rates)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300740{
741 u8 index = 0;
742
743 rates[index++] = IEEE80211_OFDM_RATE_6MB;
744 rates[index++] = IEEE80211_OFDM_RATE_9MB;
745 rates[index++] = IEEE80211_OFDM_RATE_12MB;
746 rates[index++] = IEEE80211_OFDM_RATE_18MB;
747 rates[index++] = IEEE80211_OFDM_RATE_24MB;
748 rates[index++] = IEEE80211_OFDM_RATE_36MB;
749 rates[index++] = IEEE80211_OFDM_RATE_48MB;
750 rates[index++] = IEEE80211_OFDM_RATE_54MB;
751
752 return index;
753}
754
755
Kalle Valo80301cd2009-06-12 14:17:39 +0300756static int wl1251_build_probe_req(struct wl1251 *wl, u8 *ssid, size_t ssid_len)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300757{
758 struct wl12xx_probe_req_template template;
759 struct wl12xx_ie_rates *rates;
760 char *ptr;
761 u16 size;
762
763 ptr = (char *)&template;
764 size = sizeof(struct ieee80211_header);
765
766 memset(template.header.da, 0xff, ETH_ALEN);
767 memset(template.header.bssid, 0xff, ETH_ALEN);
768 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
769 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
770
771 /* IEs */
772 /* SSID */
773 template.ssid.header.id = WLAN_EID_SSID;
774 template.ssid.header.len = ssid_len;
775 if (ssid_len && ssid)
776 memcpy(template.ssid.ssid, ssid, ssid_len);
777 size += sizeof(struct wl12xx_ie_header) + ssid_len;
778 ptr += size;
779
780 /* Basic Rates */
781 rates = (struct wl12xx_ie_rates *)ptr;
782 rates->header.id = WLAN_EID_SUPP_RATES;
Kalle Valo80301cd2009-06-12 14:17:39 +0300783 rates->header.len = wl1251_build_basic_rates(rates->rates);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300784 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
785 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
786
787 /* Extended rates */
788 rates = (struct wl12xx_ie_rates *)ptr;
789 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
Kalle Valo80301cd2009-06-12 14:17:39 +0300790 rates->header.len = wl1251_build_extended_rates(rates->rates);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300791 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
792
Kalle Valo80301cd2009-06-12 14:17:39 +0300793 wl1251_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300794
Kalle Valo80301cd2009-06-12 14:17:39 +0300795 return wl1251_cmd_template_set(wl, CMD_PROBE_REQ, &template,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300796 size);
797}
798
Kalle Valo80301cd2009-06-12 14:17:39 +0300799static int wl1251_hw_scan(struct wl1251 *wl, u8 *ssid, size_t len,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300800 u8 active_scan, u8 high_prio, u8 num_channels,
801 u8 probe_requests)
802{
Kalle Valo80301cd2009-06-12 14:17:39 +0300803 struct wl1251_cmd_trigger_scan_to *trigger = NULL;
Kalle Valoff258392009-06-12 14:14:19 +0300804 struct cmd_scan *params = NULL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300805 int i, ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300806 u16 scan_options = 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300807
808 if (wl->scanning)
809 return -EINVAL;
810
811 params = kzalloc(sizeof(*params), GFP_KERNEL);
812 if (!params)
813 return -ENOMEM;
814
815 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
816 params->params.rx_filter_options =
817 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
818
819 /* High priority scan */
820 if (!active_scan)
821 scan_options |= SCAN_PASSIVE;
822 if (high_prio)
823 scan_options |= SCAN_PRIORITY_HIGH;
824 params->params.scan_options = scan_options;
825
826 params->params.num_channels = num_channels;
827 params->params.num_probe_requests = probe_requests;
828 params->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
829 params->params.tid_trigger = 0;
830
831 for (i = 0; i < num_channels; i++) {
832 params->channels[i].min_duration = cpu_to_le32(30000);
833 params->channels[i].max_duration = cpu_to_le32(60000);
834 memset(&params->channels[i].bssid_lsb, 0xff, 4);
835 memset(&params->channels[i].bssid_msb, 0xff, 2);
836 params->channels[i].early_termination = 0;
837 params->channels[i].tx_power_att = 0;
838 params->channels[i].channel = i + 1;
839 memset(params->channels[i].pad, 0, 3);
840 }
841
842 for (i = num_channels; i < SCAN_MAX_NUM_OF_CHANNELS; i++)
843 memset(&params->channels[i], 0,
844 sizeof(struct basic_scan_channel_parameters));
845
846 if (len && ssid) {
847 params->params.ssid_len = len;
848 memcpy(params->params.ssid, ssid, len);
849 } else {
850 params->params.ssid_len = 0;
851 memset(params->params.ssid, 0, 32);
852 }
853
Kalle Valo80301cd2009-06-12 14:17:39 +0300854 ret = wl1251_build_probe_req(wl, ssid, len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300855 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300856 wl1251_error("PROBE request template failed");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300857 goto out;
858 }
859
Kalle Valoff258392009-06-12 14:14:19 +0300860 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
861 if (!trigger)
862 goto out;
863
864 trigger->timeout = 0;
865
Kalle Valo80301cd2009-06-12 14:17:39 +0300866 ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
Kalle Valoff258392009-06-12 14:14:19 +0300867 sizeof(*trigger));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300868 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300869 wl1251_error("trigger scan to failed for hw scan");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300870 goto out;
871 }
872
Kalle Valo80301cd2009-06-12 14:17:39 +0300873 wl1251_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300874
875 wl->scanning = true;
876
Kalle Valo80301cd2009-06-12 14:17:39 +0300877 ret = wl1251_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300878 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +0300879 wl1251_error("SCAN failed");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300880
Bob Copeland0764de62009-08-07 13:32:56 +0300881 wl1251_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300882
Kalle Valoff258392009-06-12 14:14:19 +0300883 if (params->header.status != CMD_STATUS_SUCCESS) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300884 wl1251_error("TEST command answer error: %d",
Kalle Valoff258392009-06-12 14:14:19 +0300885 params->header.status);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300886 wl->scanning = false;
887 ret = -EIO;
888 goto out;
889 }
890
891out:
892 kfree(params);
893 return ret;
894
895}
896
Kalle Valo80301cd2009-06-12 14:17:39 +0300897static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300898 struct cfg80211_scan_request *req)
899{
Kalle Valo80301cd2009-06-12 14:17:39 +0300900 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300901 int ret;
902 u8 *ssid = NULL;
903 size_t ssid_len = 0;
904
Kalle Valo80301cd2009-06-12 14:17:39 +0300905 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300906
907 if (req->n_ssids) {
908 ssid = req->ssids[0].ssid;
909 ssid_len = req->ssids[0].ssid_len;
910 }
911
912 mutex_lock(&wl->mutex);
Kalle Valoc5483b72009-06-12 14:16:32 +0300913
Kalle Valo80301cd2009-06-12 14:17:39 +0300914 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300915 if (ret < 0)
916 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300917
Kalle Valo80301cd2009-06-12 14:17:39 +0300918 ret = wl1251_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300919
Kalle Valo80301cd2009-06-12 14:17:39 +0300920 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300921
922out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300923 mutex_unlock(&wl->mutex);
924
925 return ret;
926}
927
Kalle Valo80301cd2009-06-12 14:17:39 +0300928static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300929{
Kalle Valo80301cd2009-06-12 14:17:39 +0300930 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300931 int ret;
932
Kalle Valocee4fd22009-06-12 14:16:20 +0300933 mutex_lock(&wl->mutex);
934
Kalle Valo80301cd2009-06-12 14:17:39 +0300935 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300936 if (ret < 0)
937 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300938
Kalle Valo80301cd2009-06-12 14:17:39 +0300939 ret = wl1251_acx_rts_threshold(wl, (u16) value);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300940 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +0300941 wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300942
Kalle Valo80301cd2009-06-12 14:17:39 +0300943 wl1251_ps_elp_sleep(wl);
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300944
Kalle Valoc5483b72009-06-12 14:16:32 +0300945out:
Kalle Valocee4fd22009-06-12 14:16:20 +0300946 mutex_unlock(&wl->mutex);
947
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300948 return ret;
949}
950
Kalle Valo80301cd2009-06-12 14:17:39 +0300951static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300952 struct ieee80211_vif *vif,
953 struct ieee80211_bss_conf *bss_conf,
954 u32 changed)
955{
Kalle Valo80301cd2009-06-12 14:17:39 +0300956 enum wl1251_cmd_ps_mode mode;
957 struct wl1251 *wl = hw->priv;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300958 struct sk_buff *beacon;
959 int ret;
960
Kalle Valo80301cd2009-06-12 14:17:39 +0300961 wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300962
963 mutex_lock(&wl->mutex);
964
Kalle Valo80301cd2009-06-12 14:17:39 +0300965 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300966 if (ret < 0)
967 goto out;
Kalle Valo01d9cfb2009-06-12 14:16:26 +0300968
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300969 if (changed & BSS_CHANGED_ASSOC) {
970 if (bss_conf->assoc) {
971 wl->aid = bss_conf->aid;
972
Kalle Valo80301cd2009-06-12 14:17:39 +0300973 ret = wl1251_build_ps_poll(wl, wl->aid);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300974 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300975 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300976
Kalle Valo80301cd2009-06-12 14:17:39 +0300977 ret = wl1251_acx_aid(wl, wl->aid);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300978 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300979 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300980
981 /* If we want to go in PSM but we're not there yet */
982 if (wl->psm_requested && !wl->psm) {
983 mode = STATION_POWER_SAVE_MODE;
Kalle Valo80301cd2009-06-12 14:17:39 +0300984 ret = wl1251_ps_set_mode(wl, mode);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300985 if (ret < 0)
Kalle Valoc5483b72009-06-12 14:16:32 +0300986 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300987 }
988 }
989 }
990 if (changed & BSS_CHANGED_ERP_SLOT) {
991 if (bss_conf->use_short_slot)
Kalle Valo80301cd2009-06-12 14:17:39 +0300992 ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300993 else
Kalle Valo80301cd2009-06-12 14:17:39 +0300994 ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300995 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300996 wl1251_warning("Set slot time failed %d", ret);
Kalle Valoc5483b72009-06-12 14:16:32 +0300997 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300998 }
999 }
1000
1001 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1002 if (bss_conf->use_short_preamble)
Kalle Valo80301cd2009-06-12 14:17:39 +03001003 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001004 else
Kalle Valo80301cd2009-06-12 14:17:39 +03001005 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001006 }
1007
1008 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1009 if (bss_conf->use_cts_prot)
Kalle Valo80301cd2009-06-12 14:17:39 +03001010 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001011 else
Kalle Valo80301cd2009-06-12 14:17:39 +03001012 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001013 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001014 wl1251_warning("Set ctsprotect failed %d", ret);
1015 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001016 }
1017 }
1018
1019 if (changed & BSS_CHANGED_BSSID) {
1020 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1021
Kalle Valo80301cd2009-06-12 14:17:39 +03001022 ret = wl1251_build_null_data(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001023 if (ret < 0)
1024 goto out;
1025
1026 if (wl->bss_type != BSS_TYPE_IBSS) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001027 ret = wl1251_cmd_join(wl, wl->bss_type, 5, 100, 1);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001028 if (ret < 0)
Kalle Valo80301cd2009-06-12 14:17:39 +03001029 goto out_sleep;
1030 wl1251_warning("Set ctsprotect failed %d", ret);
1031 goto out_sleep;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001032 }
1033 }
1034
1035 if (changed & BSS_CHANGED_BEACON) {
1036 beacon = ieee80211_beacon_get(hw, vif);
Kalle Valo80301cd2009-06-12 14:17:39 +03001037 ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001038 beacon->len);
1039
1040 if (ret < 0) {
1041 dev_kfree_skb(beacon);
1042 goto out;
1043 }
1044
Kalle Valo80301cd2009-06-12 14:17:39 +03001045 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001046 beacon->len);
1047
1048 dev_kfree_skb(beacon);
1049
1050 if (ret < 0)
1051 goto out;
1052
Juuso Oikarinen77cc9e42009-06-12 14:16:52 +03001053 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001054
1055 if (ret < 0)
1056 goto out;
1057 }
1058
Kalle Valoc5483b72009-06-12 14:16:32 +03001059out_sleep:
Kalle Valo80301cd2009-06-12 14:17:39 +03001060 wl1251_ps_elp_sleep(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +03001061
1062out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001063 mutex_unlock(&wl->mutex);
1064}
1065
1066
1067/* can't be const, mac80211 writes to this */
Kalle Valo80301cd2009-06-12 14:17:39 +03001068static struct ieee80211_rate wl1251_rates[] = {
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001069 { .bitrate = 10,
1070 .hw_value = 0x1,
1071 .hw_value_short = 0x1, },
1072 { .bitrate = 20,
1073 .hw_value = 0x2,
1074 .hw_value_short = 0x2,
1075 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1076 { .bitrate = 55,
1077 .hw_value = 0x4,
1078 .hw_value_short = 0x4,
1079 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1080 { .bitrate = 110,
1081 .hw_value = 0x20,
1082 .hw_value_short = 0x20,
1083 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1084 { .bitrate = 60,
1085 .hw_value = 0x8,
1086 .hw_value_short = 0x8, },
1087 { .bitrate = 90,
1088 .hw_value = 0x10,
1089 .hw_value_short = 0x10, },
1090 { .bitrate = 120,
1091 .hw_value = 0x40,
1092 .hw_value_short = 0x40, },
1093 { .bitrate = 180,
1094 .hw_value = 0x80,
1095 .hw_value_short = 0x80, },
1096 { .bitrate = 240,
1097 .hw_value = 0x200,
1098 .hw_value_short = 0x200, },
1099 { .bitrate = 360,
1100 .hw_value = 0x400,
1101 .hw_value_short = 0x400, },
1102 { .bitrate = 480,
1103 .hw_value = 0x800,
1104 .hw_value_short = 0x800, },
1105 { .bitrate = 540,
1106 .hw_value = 0x1000,
1107 .hw_value_short = 0x1000, },
1108};
1109
1110/* can't be const, mac80211 writes to this */
Kalle Valo80301cd2009-06-12 14:17:39 +03001111static struct ieee80211_channel wl1251_channels[] = {
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001112 { .hw_value = 1, .center_freq = 2412},
1113 { .hw_value = 2, .center_freq = 2417},
1114 { .hw_value = 3, .center_freq = 2422},
1115 { .hw_value = 4, .center_freq = 2427},
1116 { .hw_value = 5, .center_freq = 2432},
1117 { .hw_value = 6, .center_freq = 2437},
1118 { .hw_value = 7, .center_freq = 2442},
1119 { .hw_value = 8, .center_freq = 2447},
1120 { .hw_value = 9, .center_freq = 2452},
1121 { .hw_value = 10, .center_freq = 2457},
1122 { .hw_value = 11, .center_freq = 2462},
1123 { .hw_value = 12, .center_freq = 2467},
1124 { .hw_value = 13, .center_freq = 2472},
1125};
1126
1127/* can't be const, mac80211 writes to this */
Kalle Valo80301cd2009-06-12 14:17:39 +03001128static struct ieee80211_supported_band wl1251_band_2ghz = {
1129 .channels = wl1251_channels,
1130 .n_channels = ARRAY_SIZE(wl1251_channels),
1131 .bitrates = wl1251_rates,
1132 .n_bitrates = ARRAY_SIZE(wl1251_rates),
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001133};
1134
Kalle Valo80301cd2009-06-12 14:17:39 +03001135static const struct ieee80211_ops wl1251_ops = {
1136 .start = wl1251_op_start,
1137 .stop = wl1251_op_stop,
1138 .add_interface = wl1251_op_add_interface,
1139 .remove_interface = wl1251_op_remove_interface,
1140 .config = wl1251_op_config,
1141 .configure_filter = wl1251_op_configure_filter,
1142 .tx = wl1251_op_tx,
1143 .set_key = wl1251_op_set_key,
1144 .hw_scan = wl1251_op_hw_scan,
1145 .bss_info_changed = wl1251_op_bss_info_changed,
1146 .set_rts_threshold = wl1251_op_set_rts_threshold,
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001147};
1148
Kalle Valo80301cd2009-06-12 14:17:39 +03001149static int wl1251_register_hw(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001150{
1151 int ret;
1152
1153 if (wl->mac80211_registered)
1154 return 0;
1155
1156 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1157
1158 ret = ieee80211_register_hw(wl->hw);
1159 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001160 wl1251_error("unable to register mac80211 hw: %d", ret);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001161 return ret;
1162 }
1163
1164 wl->mac80211_registered = true;
1165
Kalle Valo80301cd2009-06-12 14:17:39 +03001166 wl1251_notice("loaded");
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001167
1168 return 0;
1169}
1170
Bob Copeland8e639c02009-08-07 13:33:26 +03001171int wl1251_init_ieee80211(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001172{
Bob Copeland8e639c02009-08-07 13:33:26 +03001173 int ret;
1174
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001175 /* The tx descriptor buffer and the TKIP space */
1176 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +03001177 + WL1251_TKIP_IV_SPACE;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001178
1179 /* unit us */
1180 /* FIXME: find a proper value */
1181 wl->hw->channel_change_time = 10000;
1182
1183 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1184 IEEE80211_HW_NOISE_DBM;
1185
1186 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1187 wl->hw->wiphy->max_scan_ssids = 1;
Kalle Valo80301cd2009-06-12 14:17:39 +03001188 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001189
Bob Copeland8e639c02009-08-07 13:33:26 +03001190 ret = wl1251_register_hw(wl);
1191 if (ret)
1192 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001193
Bob Copeland8e639c02009-08-07 13:33:26 +03001194 wl1251_debugfs_init(wl);
1195 wl1251_notice("initialized");
1196
1197 ret = 0;
1198
1199out:
1200 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001201}
Bob Copelandaf8c78e2009-08-07 13:33:34 +03001202EXPORT_SYMBOL_GPL(wl1251_init_ieee80211);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001203
Kalle Valo80301cd2009-06-12 14:17:39 +03001204#define WL1251_DEFAULT_CHANNEL 1
Bob Copeland8e639c02009-08-07 13:33:26 +03001205struct ieee80211_hw *wl1251_alloc_hw(void)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001206{
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001207 struct ieee80211_hw *hw;
Kalle Valo80301cd2009-06-12 14:17:39 +03001208 struct wl1251 *wl;
Bob Copeland8e639c02009-08-07 13:33:26 +03001209 int i;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001210 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1211
Kalle Valo80301cd2009-06-12 14:17:39 +03001212 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001213 if (!hw) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001214 wl1251_error("could not alloc ieee80211_hw");
Bob Copeland8e639c02009-08-07 13:33:26 +03001215 return ERR_PTR(-ENOMEM);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001216 }
1217
1218 wl = hw->priv;
1219 memset(wl, 0, sizeof(*wl));
1220
1221 wl->hw = hw;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001222
1223 wl->data_in_count = 0;
1224
1225 skb_queue_head_init(&wl->tx_queue);
1226
Kalle Valo80301cd2009-06-12 14:17:39 +03001227 INIT_WORK(&wl->filter_work, wl1251_filter_work);
1228 wl->channel = WL1251_DEFAULT_CHANNEL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001229 wl->scanning = false;
1230 wl->default_key = 0;
1231 wl->listen_int = 1;
1232 wl->rx_counter = 0;
1233 wl->rx_handled = 0;
1234 wl->rx_current_buffer = 0;
1235 wl->rx_last_id = 0;
Kalle Valo80301cd2009-06-12 14:17:39 +03001236 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
1237 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001238 wl->elp = false;
1239 wl->psm = 0;
1240 wl->psm_requested = false;
1241 wl->tx_queue_stopped = false;
Kalle Valo80301cd2009-06-12 14:17:39 +03001242 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001243
1244 /* We use the default power on sleep time until we know which chip
1245 * we're using */
Kalle Valo80301cd2009-06-12 14:17:39 +03001246 wl->chip.power_on_sleep = WL1251_DEFAULT_POWER_ON_SLEEP;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001247
1248 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1249 wl->tx_frames[i] = NULL;
1250
1251 wl->next_tx_complete = 0;
1252
1253 /*
1254 * In case our MAC address is not correctly set,
1255 * we use a random but Nokia MAC.
1256 */
1257 memcpy(wl->mac_addr, nokia_oui, 3);
1258 get_random_bytes(wl->mac_addr + 3, 3);
1259
Kalle Valo80301cd2009-06-12 14:17:39 +03001260 wl->state = WL1251_STATE_OFF;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001261 mutex_init(&wl->mutex);
1262
1263 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1264 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1265
Kalle Valo47212132009-06-12 14:15:08 +03001266 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1267 if (!wl->rx_descriptor) {
Kalle Valo80301cd2009-06-12 14:17:39 +03001268 wl1251_error("could not allocate memory for rx descriptor");
Bob Copeland8e639c02009-08-07 13:33:26 +03001269 ieee80211_free_hw(hw);
1270 return ERR_PTR(-ENOMEM);
Kalle Valo47212132009-06-12 14:15:08 +03001271 }
1272
Bob Copeland8e639c02009-08-07 13:33:26 +03001273 return hw;
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001274}
Bob Copelandaf8c78e2009-08-07 13:33:34 +03001275EXPORT_SYMBOL_GPL(wl1251_alloc_hw);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001276
Bob Copeland8e639c02009-08-07 13:33:26 +03001277int wl1251_free_hw(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001278{
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001279 ieee80211_unregister_hw(wl->hw);
1280
Kalle Valo80301cd2009-06-12 14:17:39 +03001281 wl1251_debugfs_exit(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001282
1283 free_irq(wl->irq, wl);
1284 kfree(wl->target_mem_map);
1285 kfree(wl->data_path);
1286 kfree(wl->fw);
1287 wl->fw = NULL;
1288 kfree(wl->nvs);
1289 wl->nvs = NULL;
Kalle Valo47212132009-06-12 14:15:08 +03001290
1291 kfree(wl->rx_descriptor);
1292 wl->rx_descriptor = NULL;
1293
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001294 ieee80211_free_hw(wl->hw);
1295
1296 return 0;
1297}
Bob Copelandaf8c78e2009-08-07 13:33:34 +03001298EXPORT_SYMBOL_GPL(wl1251_free_hw);
1299
1300MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core");
1301MODULE_LICENSE("GPL");
1302MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>");
1303MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");