Commit | Line | Data |
---|---|---|
f5fc0f86 LC |
1 | /* |
2 | * This file is part of wl1271 | |
3 | * | |
4 | * Copyright (C) 2008-2009 Nokia Corporation | |
5 | * | |
6 | * Contact: Luciano Coelho <luciano.coelho@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/platform_device.h> | |
26 | #include <linux/interrupt.h> | |
27 | #include <linux/firmware.h> | |
28 | #include <linux/delay.h> | |
29 | #include <linux/irq.h> | |
30 | #include <linux/spi/spi.h> | |
31 | #include <linux/crc32.h> | |
32 | #include <linux/etherdevice.h> | |
1fba4974 | 33 | #include <linux/vmalloc.h> |
f5fc0f86 LC |
34 | #include <linux/spi/wl12xx.h> |
35 | ||
36 | #include "wl1271.h" | |
37 | #include "wl12xx_80211.h" | |
38 | #include "wl1271_reg.h" | |
39 | #include "wl1271_spi.h" | |
40 | #include "wl1271_event.h" | |
41 | #include "wl1271_tx.h" | |
42 | #include "wl1271_rx.h" | |
43 | #include "wl1271_ps.h" | |
44 | #include "wl1271_init.h" | |
45 | #include "wl1271_debugfs.h" | |
46 | #include "wl1271_cmd.h" | |
47 | #include "wl1271_boot.h" | |
48 | ||
49 | static int wl1271_plt_init(struct wl1271 *wl) | |
50 | { | |
51 | int ret; | |
52 | ||
53 | ret = wl1271_acx_init_mem_config(wl); | |
54 | if (ret < 0) | |
55 | return ret; | |
56 | ||
57 | ret = wl1271_cmd_data_path(wl, wl->channel, 1); | |
58 | if (ret < 0) | |
59 | return ret; | |
60 | ||
61 | return 0; | |
62 | } | |
63 | ||
64 | static void wl1271_disable_interrupts(struct wl1271 *wl) | |
65 | { | |
66 | disable_irq(wl->irq); | |
67 | } | |
68 | ||
69 | static void wl1271_power_off(struct wl1271 *wl) | |
70 | { | |
71 | wl->set_power(false); | |
72 | } | |
73 | ||
74 | static void wl1271_power_on(struct wl1271 *wl) | |
75 | { | |
76 | wl->set_power(true); | |
77 | } | |
78 | ||
c15f63bf JO |
79 | static void wl1271_fw_status(struct wl1271 *wl, |
80 | struct wl1271_fw_status *status) | |
f5fc0f86 LC |
81 | { |
82 | u32 total = 0; | |
83 | int i; | |
84 | ||
74621417 JO |
85 | wl1271_spi_read(wl, FW_STATUS_ADDR, status, |
86 | sizeof(*status), false); | |
f5fc0f86 LC |
87 | |
88 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " | |
89 | "drv_rx_counter = %d, tx_results_counter = %d)", | |
90 | status->intr, | |
91 | status->fw_rx_counter, | |
92 | status->drv_rx_counter, | |
93 | status->tx_results_counter); | |
94 | ||
95 | /* update number of available TX blocks */ | |
96 | for (i = 0; i < NUM_TX_QUEUES; i++) { | |
97 | u32 cnt = status->tx_released_blks[i] - wl->tx_blocks_freed[i]; | |
98 | wl->tx_blocks_freed[i] = status->tx_released_blks[i]; | |
99 | wl->tx_blocks_available += cnt; | |
100 | total += cnt; | |
101 | } | |
102 | ||
103 | /* if more blocks are available now, schedule some tx work */ | |
104 | if (total && !skb_queue_empty(&wl->tx_queue)) | |
a64b07e8 | 105 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
f5fc0f86 LC |
106 | |
107 | /* update the host-chipset time offset */ | |
108 | wl->time_offset = jiffies_to_usecs(jiffies) - status->fw_localtime; | |
109 | } | |
110 | ||
f5fc0f86 LC |
111 | static void wl1271_irq_work(struct work_struct *work) |
112 | { | |
f5fc0f86 | 113 | int ret; |
c15f63bf | 114 | u32 intr; |
f5fc0f86 LC |
115 | struct wl1271 *wl = |
116 | container_of(work, struct wl1271, irq_work); | |
117 | ||
118 | mutex_lock(&wl->mutex); | |
119 | ||
120 | wl1271_debug(DEBUG_IRQ, "IRQ work"); | |
121 | ||
122 | if (wl->state == WL1271_STATE_OFF) | |
123 | goto out; | |
124 | ||
125 | ret = wl1271_ps_elp_wakeup(wl, true); | |
126 | if (ret < 0) | |
127 | goto out; | |
128 | ||
74621417 | 129 | wl1271_spi_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL); |
f5fc0f86 | 130 | |
c15f63bf JO |
131 | wl1271_fw_status(wl, wl->fw_status); |
132 | intr = wl->fw_status->intr; | |
f5fc0f86 LC |
133 | if (!intr) { |
134 | wl1271_debug(DEBUG_IRQ, "Zero interrupt received."); | |
135 | goto out_sleep; | |
136 | } | |
137 | ||
138 | intr &= WL1271_INTR_MASK; | |
139 | ||
c15f63bf JO |
140 | if (intr & (WL1271_ACX_INTR_EVENT_A | |
141 | WL1271_ACX_INTR_EVENT_B)) { | |
142 | wl1271_debug(DEBUG_IRQ, | |
143 | "WL1271_ACX_INTR_EVENT (0x%x)", intr); | |
144 | if (intr & WL1271_ACX_INTR_EVENT_A) | |
145 | wl1271_event_handle(wl, 0); | |
146 | else | |
147 | wl1271_event_handle(wl, 1); | |
148 | } | |
f5fc0f86 | 149 | |
c15f63bf JO |
150 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) |
151 | wl1271_debug(DEBUG_IRQ, | |
152 | "WL1271_ACX_INTR_INIT_COMPLETE"); | |
f5fc0f86 | 153 | |
c15f63bf JO |
154 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) |
155 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); | |
f5fc0f86 | 156 | |
c15f63bf JO |
157 | if (intr & WL1271_ACX_INTR_DATA) { |
158 | u8 tx_res_cnt = wl->fw_status->tx_results_counter - | |
159 | wl->tx_results_count; | |
f5fc0f86 | 160 | |
c15f63bf | 161 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); |
f5fc0f86 | 162 | |
c15f63bf JO |
163 | /* check for tx results */ |
164 | if (tx_res_cnt) | |
165 | wl1271_tx_complete(wl, tx_res_cnt); | |
f5fc0f86 | 166 | |
c15f63bf JO |
167 | wl1271_rx(wl, wl->fw_status); |
168 | } | |
f5fc0f86 LC |
169 | |
170 | out_sleep: | |
74621417 | 171 | wl1271_spi_write32(wl, ACX_REG_INTERRUPT_MASK, |
73d0a13c | 172 | WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); |
f5fc0f86 LC |
173 | wl1271_ps_elp_sleep(wl); |
174 | ||
175 | out: | |
176 | mutex_unlock(&wl->mutex); | |
177 | } | |
178 | ||
179 | static irqreturn_t wl1271_irq(int irq, void *cookie) | |
180 | { | |
181 | struct wl1271 *wl; | |
182 | unsigned long flags; | |
183 | ||
184 | wl1271_debug(DEBUG_IRQ, "IRQ"); | |
185 | ||
186 | wl = cookie; | |
187 | ||
188 | /* complete the ELP completion */ | |
189 | spin_lock_irqsave(&wl->wl_lock, flags); | |
190 | if (wl->elp_compl) { | |
191 | complete(wl->elp_compl); | |
192 | wl->elp_compl = NULL; | |
193 | } | |
194 | ||
a64b07e8 | 195 | ieee80211_queue_work(wl->hw, &wl->irq_work); |
f5fc0f86 LC |
196 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
197 | ||
198 | return IRQ_HANDLED; | |
199 | } | |
200 | ||
201 | static int wl1271_fetch_firmware(struct wl1271 *wl) | |
202 | { | |
203 | const struct firmware *fw; | |
204 | int ret; | |
205 | ||
206 | ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev); | |
207 | ||
208 | if (ret < 0) { | |
209 | wl1271_error("could not get firmware: %d", ret); | |
210 | return ret; | |
211 | } | |
212 | ||
213 | if (fw->size % 4) { | |
214 | wl1271_error("firmware size is not multiple of 32 bits: %zu", | |
215 | fw->size); | |
216 | ret = -EILSEQ; | |
217 | goto out; | |
218 | } | |
219 | ||
220 | wl->fw_len = fw->size; | |
1fba4974 | 221 | wl->fw = vmalloc(wl->fw_len); |
f5fc0f86 LC |
222 | |
223 | if (!wl->fw) { | |
224 | wl1271_error("could not allocate memory for the firmware"); | |
225 | ret = -ENOMEM; | |
226 | goto out; | |
227 | } | |
228 | ||
229 | memcpy(wl->fw, fw->data, wl->fw_len); | |
230 | ||
231 | ret = 0; | |
232 | ||
233 | out: | |
234 | release_firmware(fw); | |
235 | ||
236 | return ret; | |
237 | } | |
238 | ||
239 | static int wl1271_fetch_nvs(struct wl1271 *wl) | |
240 | { | |
241 | const struct firmware *fw; | |
242 | int ret; | |
243 | ||
244 | ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev); | |
245 | ||
246 | if (ret < 0) { | |
247 | wl1271_error("could not get nvs file: %d", ret); | |
248 | return ret; | |
249 | } | |
250 | ||
251 | if (fw->size % 4) { | |
252 | wl1271_error("nvs size is not multiple of 32 bits: %zu", | |
253 | fw->size); | |
254 | ret = -EILSEQ; | |
255 | goto out; | |
256 | } | |
257 | ||
258 | wl->nvs_len = fw->size; | |
259 | wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL); | |
260 | ||
261 | if (!wl->nvs) { | |
262 | wl1271_error("could not allocate memory for the nvs file"); | |
263 | ret = -ENOMEM; | |
264 | goto out; | |
265 | } | |
266 | ||
267 | memcpy(wl->nvs, fw->data, wl->nvs_len); | |
268 | ||
269 | ret = 0; | |
270 | ||
271 | out: | |
272 | release_firmware(fw); | |
273 | ||
274 | return ret; | |
275 | } | |
276 | ||
277 | static void wl1271_fw_wakeup(struct wl1271 *wl) | |
278 | { | |
279 | u32 elp_reg; | |
280 | ||
281 | elp_reg = ELPCTRL_WAKE_UP; | |
74621417 | 282 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); |
f5fc0f86 LC |
283 | } |
284 | ||
285 | static int wl1271_setup(struct wl1271 *wl) | |
286 | { | |
287 | wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL); | |
288 | if (!wl->fw_status) | |
289 | return -ENOMEM; | |
290 | ||
291 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); | |
292 | if (!wl->tx_res_if) { | |
293 | kfree(wl->fw_status); | |
294 | return -ENOMEM; | |
295 | } | |
296 | ||
297 | INIT_WORK(&wl->irq_work, wl1271_irq_work); | |
298 | INIT_WORK(&wl->tx_work, wl1271_tx_work); | |
299 | return 0; | |
300 | } | |
301 | ||
302 | static int wl1271_chip_wakeup(struct wl1271 *wl) | |
303 | { | |
451de97a | 304 | struct wl1271_partition_set partition; |
f5fc0f86 LC |
305 | int ret = 0; |
306 | ||
307 | wl1271_power_on(wl); | |
308 | msleep(WL1271_POWER_ON_SLEEP); | |
309 | wl1271_spi_reset(wl); | |
310 | wl1271_spi_init(wl); | |
311 | ||
312 | /* We don't need a real memory partition here, because we only want | |
313 | * to use the registers at this point. */ | |
451de97a JO |
314 | memset(&partition, 0, sizeof(partition)); |
315 | partition.reg.start = REGISTERS_BASE; | |
316 | partition.reg.size = REGISTERS_DOWN_SIZE; | |
317 | wl1271_set_partition(wl, &partition); | |
f5fc0f86 LC |
318 | |
319 | /* ELP module wake up */ | |
320 | wl1271_fw_wakeup(wl); | |
321 | ||
322 | /* whal_FwCtrl_BootSm() */ | |
323 | ||
324 | /* 0. read chip id from CHIP_ID */ | |
74621417 | 325 | wl->chip.id = wl1271_spi_read32(wl, CHIP_ID_B); |
f5fc0f86 LC |
326 | |
327 | /* 1. check if chip id is valid */ | |
328 | ||
329 | switch (wl->chip.id) { | |
330 | case CHIP_ID_1271_PG10: | |
331 | wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", | |
332 | wl->chip.id); | |
333 | ||
334 | ret = wl1271_setup(wl); | |
335 | if (ret < 0) | |
336 | goto out; | |
337 | break; | |
338 | case CHIP_ID_1271_PG20: | |
339 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", | |
340 | wl->chip.id); | |
341 | ||
342 | ret = wl1271_setup(wl); | |
343 | if (ret < 0) | |
344 | goto out; | |
345 | break; | |
346 | default: | |
347 | wl1271_error("unsupported chip id: 0x%x", wl->chip.id); | |
348 | ret = -ENODEV; | |
349 | goto out; | |
350 | } | |
351 | ||
352 | if (wl->fw == NULL) { | |
353 | ret = wl1271_fetch_firmware(wl); | |
354 | if (ret < 0) | |
355 | goto out; | |
356 | } | |
357 | ||
358 | /* No NVS from netlink, try to get it from the filesystem */ | |
359 | if (wl->nvs == NULL) { | |
360 | ret = wl1271_fetch_nvs(wl); | |
361 | if (ret < 0) | |
362 | goto out; | |
363 | } | |
364 | ||
365 | out: | |
366 | return ret; | |
367 | } | |
368 | ||
c87dec9f JO |
369 | struct wl1271_filter_params { |
370 | unsigned int filters; | |
371 | unsigned int changed; | |
372 | int mc_list_length; | |
373 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; | |
374 | }; | |
375 | ||
376 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ | |
377 | FIF_ALLMULTI | \ | |
378 | FIF_FCSFAIL | \ | |
379 | FIF_BCN_PRBRESP_PROMISC | \ | |
380 | FIF_CONTROL | \ | |
381 | FIF_OTHER_BSS) | |
382 | ||
f5fc0f86 LC |
383 | static void wl1271_filter_work(struct work_struct *work) |
384 | { | |
385 | struct wl1271 *wl = | |
386 | container_of(work, struct wl1271, filter_work); | |
c87dec9f JO |
387 | struct wl1271_filter_params *fp; |
388 | unsigned long flags; | |
389 | bool enabled = true; | |
f5fc0f86 LC |
390 | int ret; |
391 | ||
c87dec9f JO |
392 | /* first, get the filter parameters */ |
393 | spin_lock_irqsave(&wl->wl_lock, flags); | |
394 | fp = wl->filter_params; | |
395 | wl->filter_params = NULL; | |
396 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
397 | ||
398 | if (!fp) | |
399 | return; | |
400 | ||
401 | /* then, lock the mutex without risk of lock-up */ | |
f5fc0f86 LC |
402 | mutex_lock(&wl->mutex); |
403 | ||
404 | if (wl->state == WL1271_STATE_OFF) | |
405 | goto out; | |
406 | ||
407 | ret = wl1271_ps_elp_wakeup(wl, false); | |
408 | if (ret < 0) | |
409 | goto out; | |
410 | ||
c87dec9f JO |
411 | /* configure the mc filter regardless of the changed flags */ |
412 | if (fp->filters & FIF_ALLMULTI) | |
413 | enabled = false; | |
414 | ||
415 | ret = wl1271_acx_group_address_tbl(wl, enabled, | |
416 | fp->mc_list, fp->mc_list_length); | |
417 | if (ret < 0) | |
418 | goto out_sleep; | |
419 | ||
420 | /* determine, whether supported filter values have changed */ | |
421 | if (fp->changed == 0) | |
422 | goto out; | |
423 | ||
424 | /* apply configured filters */ | |
0535d9f4 | 425 | ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter); |
f5fc0f86 LC |
426 | if (ret < 0) |
427 | goto out_sleep; | |
428 | ||
429 | out_sleep: | |
430 | wl1271_ps_elp_sleep(wl); | |
431 | ||
432 | out: | |
433 | mutex_unlock(&wl->mutex); | |
c87dec9f | 434 | kfree(fp); |
f5fc0f86 LC |
435 | } |
436 | ||
437 | int wl1271_plt_start(struct wl1271 *wl) | |
438 | { | |
439 | int ret; | |
440 | ||
441 | mutex_lock(&wl->mutex); | |
442 | ||
443 | wl1271_notice("power up"); | |
444 | ||
445 | if (wl->state != WL1271_STATE_OFF) { | |
446 | wl1271_error("cannot go into PLT state because not " | |
447 | "in off state: %d", wl->state); | |
448 | ret = -EBUSY; | |
449 | goto out; | |
450 | } | |
451 | ||
452 | wl->state = WL1271_STATE_PLT; | |
453 | ||
454 | ret = wl1271_chip_wakeup(wl); | |
455 | if (ret < 0) | |
456 | goto out; | |
457 | ||
458 | ret = wl1271_boot(wl); | |
459 | if (ret < 0) | |
460 | goto out; | |
461 | ||
462 | wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver); | |
463 | ||
464 | ret = wl1271_plt_init(wl); | |
465 | if (ret < 0) | |
466 | goto out; | |
467 | ||
468 | out: | |
469 | mutex_unlock(&wl->mutex); | |
470 | ||
471 | return ret; | |
472 | } | |
473 | ||
474 | int wl1271_plt_stop(struct wl1271 *wl) | |
475 | { | |
476 | int ret = 0; | |
477 | ||
478 | mutex_lock(&wl->mutex); | |
479 | ||
480 | wl1271_notice("power down"); | |
481 | ||
482 | if (wl->state != WL1271_STATE_PLT) { | |
483 | wl1271_error("cannot power down because not in PLT " | |
484 | "state: %d", wl->state); | |
485 | ret = -EBUSY; | |
486 | goto out; | |
487 | } | |
488 | ||
489 | wl1271_disable_interrupts(wl); | |
490 | wl1271_power_off(wl); | |
491 | ||
492 | wl->state = WL1271_STATE_OFF; | |
493 | ||
494 | out: | |
495 | mutex_unlock(&wl->mutex); | |
496 | ||
497 | return ret; | |
498 | } | |
499 | ||
500 | ||
501 | static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | |
502 | { | |
503 | struct wl1271 *wl = hw->priv; | |
504 | ||
505 | skb_queue_tail(&wl->tx_queue, skb); | |
506 | ||
507 | /* | |
508 | * The chip specific setup must run before the first TX packet - | |
509 | * before that, the tx_work will not be initialized! | |
510 | */ | |
511 | ||
a64b07e8 | 512 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
f5fc0f86 LC |
513 | |
514 | /* | |
515 | * The workqueue is slow to process the tx_queue and we need stop | |
516 | * the queue here, otherwise the queue will get too long. | |
517 | */ | |
518 | if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) { | |
519 | ieee80211_stop_queues(wl->hw); | |
520 | ||
521 | /* | |
522 | * FIXME: this is racy, the variable is not properly | |
523 | * protected. Maybe fix this by removing the stupid | |
524 | * variable altogether and checking the real queue state? | |
525 | */ | |
526 | wl->tx_queue_stopped = true; | |
527 | } | |
528 | ||
529 | return NETDEV_TX_OK; | |
530 | } | |
531 | ||
532 | static int wl1271_op_start(struct ieee80211_hw *hw) | |
533 | { | |
534 | struct wl1271 *wl = hw->priv; | |
535 | int ret = 0; | |
536 | ||
537 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); | |
538 | ||
539 | mutex_lock(&wl->mutex); | |
540 | ||
541 | if (wl->state != WL1271_STATE_OFF) { | |
542 | wl1271_error("cannot start because not in off state: %d", | |
543 | wl->state); | |
544 | ret = -EBUSY; | |
545 | goto out; | |
546 | } | |
547 | ||
548 | ret = wl1271_chip_wakeup(wl); | |
549 | if (ret < 0) | |
550 | goto out; | |
551 | ||
552 | ret = wl1271_boot(wl); | |
553 | if (ret < 0) | |
554 | goto out; | |
555 | ||
556 | ret = wl1271_hw_init(wl); | |
557 | if (ret < 0) | |
558 | goto out; | |
559 | ||
560 | wl->state = WL1271_STATE_ON; | |
561 | ||
562 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver); | |
563 | ||
564 | out: | |
565 | if (ret < 0) | |
566 | wl1271_power_off(wl); | |
567 | ||
568 | mutex_unlock(&wl->mutex); | |
569 | ||
570 | return ret; | |
571 | } | |
572 | ||
573 | static void wl1271_op_stop(struct ieee80211_hw *hw) | |
574 | { | |
575 | struct wl1271 *wl = hw->priv; | |
c87dec9f | 576 | unsigned long flags; |
f5fc0f86 LC |
577 | int i; |
578 | ||
579 | wl1271_info("down"); | |
580 | ||
581 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); | |
582 | ||
c87dec9f JO |
583 | /* complete/cancel ongoing work */ |
584 | cancel_work_sync(&wl->filter_work); | |
585 | spin_lock_irqsave(&wl->wl_lock, flags); | |
586 | kfree(wl->filter_params); | |
587 | wl->filter_params = NULL; | |
588 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
589 | ||
f5fc0f86 LC |
590 | mutex_lock(&wl->mutex); |
591 | ||
592 | WARN_ON(wl->state != WL1271_STATE_ON); | |
593 | ||
594 | if (wl->scanning) { | |
595 | mutex_unlock(&wl->mutex); | |
596 | ieee80211_scan_completed(wl->hw, true); | |
597 | mutex_lock(&wl->mutex); | |
598 | wl->scanning = false; | |
599 | } | |
600 | ||
601 | wl->state = WL1271_STATE_OFF; | |
602 | ||
603 | wl1271_disable_interrupts(wl); | |
604 | ||
605 | mutex_unlock(&wl->mutex); | |
606 | ||
607 | cancel_work_sync(&wl->irq_work); | |
608 | cancel_work_sync(&wl->tx_work); | |
609 | cancel_work_sync(&wl->filter_work); | |
610 | ||
611 | mutex_lock(&wl->mutex); | |
612 | ||
613 | /* let's notify MAC80211 about the remaining pending TX frames */ | |
614 | wl1271_tx_flush(wl); | |
615 | wl1271_power_off(wl); | |
616 | ||
617 | memset(wl->bssid, 0, ETH_ALEN); | |
618 | memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1); | |
619 | wl->ssid_len = 0; | |
620 | wl->listen_int = 1; | |
621 | wl->bss_type = MAX_BSS_TYPE; | |
8a5a37a6 | 622 | wl->band = IEEE80211_BAND_2GHZ; |
f5fc0f86 LC |
623 | |
624 | wl->rx_counter = 0; | |
625 | wl->elp = false; | |
626 | wl->psm = 0; | |
627 | wl->tx_queue_stopped = false; | |
628 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; | |
629 | wl->tx_blocks_available = 0; | |
630 | wl->tx_results_count = 0; | |
631 | wl->tx_packets_count = 0; | |
ac4e4ce5 JO |
632 | wl->tx_security_last_seq = 0; |
633 | wl->tx_security_seq_16 = 0; | |
634 | wl->tx_security_seq_32 = 0; | |
f5fc0f86 LC |
635 | wl->time_offset = 0; |
636 | wl->session_counter = 0; | |
d6e19d13 LC |
637 | wl->joined = false; |
638 | ||
f5fc0f86 LC |
639 | for (i = 0; i < NUM_TX_QUEUES; i++) |
640 | wl->tx_blocks_freed[i] = 0; | |
641 | ||
642 | wl1271_debugfs_reset(wl); | |
643 | mutex_unlock(&wl->mutex); | |
644 | } | |
645 | ||
646 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, | |
647 | struct ieee80211_if_init_conf *conf) | |
648 | { | |
649 | struct wl1271 *wl = hw->priv; | |
f5fc0f86 LC |
650 | int ret = 0; |
651 | ||
e5539bcb JL |
652 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", |
653 | conf->type, conf->mac_addr); | |
f5fc0f86 LC |
654 | |
655 | mutex_lock(&wl->mutex); | |
b771eee5 JO |
656 | if (wl->vif) { |
657 | ret = -EBUSY; | |
658 | goto out; | |
659 | } | |
660 | ||
661 | wl->vif = conf->vif; | |
f5fc0f86 LC |
662 | |
663 | switch (conf->type) { | |
664 | case NL80211_IFTYPE_STATION: | |
665 | wl->bss_type = BSS_TYPE_STA_BSS; | |
666 | break; | |
667 | case NL80211_IFTYPE_ADHOC: | |
668 | wl->bss_type = BSS_TYPE_IBSS; | |
669 | break; | |
670 | default: | |
671 | ret = -EOPNOTSUPP; | |
672 | goto out; | |
673 | } | |
674 | ||
675 | /* FIXME: what if conf->mac_addr changes? */ | |
676 | ||
677 | out: | |
678 | mutex_unlock(&wl->mutex); | |
679 | return ret; | |
680 | } | |
681 | ||
682 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, | |
683 | struct ieee80211_if_init_conf *conf) | |
684 | { | |
b771eee5 JO |
685 | struct wl1271 *wl = hw->priv; |
686 | ||
687 | mutex_lock(&wl->mutex); | |
f5fc0f86 | 688 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); |
b771eee5 JO |
689 | wl->vif = NULL; |
690 | mutex_unlock(&wl->mutex); | |
f5fc0f86 LC |
691 | } |
692 | ||
693 | #if 0 | |
694 | static int wl1271_op_config_interface(struct ieee80211_hw *hw, | |
695 | struct ieee80211_vif *vif, | |
696 | struct ieee80211_if_conf *conf) | |
697 | { | |
698 | struct wl1271 *wl = hw->priv; | |
699 | struct sk_buff *beacon; | |
f5fc0f86 LC |
700 | int ret; |
701 | ||
3264690b DM |
702 | wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %pM", |
703 | conf->bssid); | |
f5fc0f86 LC |
704 | wl1271_dump_ascii(DEBUG_MAC80211, "ssid: ", conf->ssid, |
705 | conf->ssid_len); | |
706 | ||
707 | mutex_lock(&wl->mutex); | |
708 | ||
709 | ret = wl1271_ps_elp_wakeup(wl, false); | |
710 | if (ret < 0) | |
711 | goto out; | |
712 | ||
713 | memcpy(wl->bssid, conf->bssid, ETH_ALEN); | |
714 | ||
715 | ret = wl1271_cmd_build_null_data(wl); | |
716 | if (ret < 0) | |
717 | goto out_sleep; | |
718 | ||
719 | wl->ssid_len = conf->ssid_len; | |
720 | if (wl->ssid_len) | |
721 | memcpy(wl->ssid, conf->ssid, wl->ssid_len); | |
722 | ||
723 | if (wl->bss_type != BSS_TYPE_IBSS) { | |
d94cd297 | 724 | ret = wl1271_cmd_join(wl); |
f5fc0f86 LC |
725 | if (ret < 0) |
726 | goto out_sleep; | |
727 | } | |
728 | ||
729 | if (conf->changed & IEEE80211_IFCC_BEACON) { | |
730 | beacon = ieee80211_beacon_get(hw, vif); | |
731 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, | |
732 | beacon->data, beacon->len); | |
733 | ||
734 | if (ret < 0) { | |
735 | dev_kfree_skb(beacon); | |
736 | goto out_sleep; | |
737 | } | |
738 | ||
739 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, | |
740 | beacon->data, beacon->len); | |
741 | ||
742 | dev_kfree_skb(beacon); | |
743 | ||
744 | if (ret < 0) | |
745 | goto out_sleep; | |
746 | ||
d94cd297 | 747 | ret = wl1271_cmd_join(wl); |
f5fc0f86 LC |
748 | |
749 | if (ret < 0) | |
750 | goto out_sleep; | |
751 | } | |
752 | ||
753 | out_sleep: | |
754 | wl1271_ps_elp_sleep(wl); | |
755 | ||
756 | out: | |
757 | mutex_unlock(&wl->mutex); | |
758 | ||
759 | return ret; | |
760 | } | |
761 | #endif | |
762 | ||
763 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) | |
764 | { | |
765 | struct wl1271 *wl = hw->priv; | |
766 | struct ieee80211_conf *conf = &hw->conf; | |
767 | int channel, ret = 0; | |
768 | ||
769 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); | |
770 | ||
771 | wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d", | |
772 | channel, | |
773 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", | |
774 | conf->power_level); | |
775 | ||
776 | mutex_lock(&wl->mutex); | |
777 | ||
8a5a37a6 JO |
778 | wl->band = conf->channel->band; |
779 | ||
f5fc0f86 LC |
780 | ret = wl1271_ps_elp_wakeup(wl, false); |
781 | if (ret < 0) | |
782 | goto out; | |
783 | ||
784 | if (channel != wl->channel) { | |
785 | u8 old_channel = wl->channel; | |
786 | wl->channel = channel; | |
787 | ||
d94cd297 | 788 | ret = wl1271_cmd_join(wl); |
f5fc0f86 LC |
789 | if (ret < 0) { |
790 | wl->channel = old_channel; | |
791 | goto out_sleep; | |
792 | } | |
793 | } | |
794 | ||
795 | ret = wl1271_cmd_build_null_data(wl); | |
796 | if (ret < 0) | |
797 | goto out_sleep; | |
798 | ||
799 | if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) { | |
800 | wl1271_info("psm enabled"); | |
801 | ||
802 | wl->psm_requested = true; | |
803 | ||
804 | /* | |
805 | * We enter PSM only if we're already associated. | |
806 | * If we're not, we'll enter it when joining an SSID, | |
807 | * through the bss_info_changed() hook. | |
808 | */ | |
809 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE); | |
810 | } else if (!(conf->flags & IEEE80211_CONF_PS) && | |
811 | wl->psm_requested) { | |
812 | wl1271_info("psm disabled"); | |
813 | ||
814 | wl->psm_requested = false; | |
815 | ||
816 | if (wl->psm) | |
817 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE); | |
818 | } | |
819 | ||
820 | if (conf->power_level != wl->power_level) { | |
821 | ret = wl1271_acx_tx_power(wl, conf->power_level); | |
822 | if (ret < 0) | |
823 | goto out; | |
824 | ||
825 | wl->power_level = conf->power_level; | |
826 | } | |
827 | ||
828 | out_sleep: | |
829 | wl1271_ps_elp_sleep(wl); | |
830 | ||
831 | out: | |
832 | mutex_unlock(&wl->mutex); | |
833 | ||
834 | return ret; | |
835 | } | |
836 | ||
c87dec9f JO |
837 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, int mc_count, |
838 | struct dev_addr_list *mc_list) | |
839 | { | |
840 | struct wl1271 *wl = hw->priv; | |
841 | struct wl1271_filter_params *fp; | |
842 | unsigned long flags; | |
843 | int i; | |
844 | ||
845 | /* | |
846 | * FIXME: we should return a hash that will be passed to | |
847 | * configure_filter() instead of saving everything in the context. | |
848 | */ | |
849 | ||
850 | fp = kzalloc(sizeof(*fp), GFP_KERNEL); | |
851 | if (!fp) { | |
852 | wl1271_error("Out of memory setting filters."); | |
853 | return 0; | |
854 | } | |
855 | ||
856 | /* update multicast filtering parameters */ | |
857 | if (mc_count > ACX_MC_ADDRESS_GROUP_MAX) { | |
858 | mc_count = 0; | |
859 | fp->filters |= FIF_ALLMULTI; | |
860 | } | |
861 | ||
862 | fp->mc_list_length = 0; | |
863 | for (i = 0; i < mc_count; i++) { | |
864 | if (mc_list->da_addrlen == ETH_ALEN) { | |
865 | memcpy(fp->mc_list[fp->mc_list_length], | |
866 | mc_list->da_addr, ETH_ALEN); | |
867 | fp->mc_list_length++; | |
868 | } else | |
869 | wl1271_warning("Unknown mc address length."); | |
870 | } | |
871 | ||
0535d9f4 LC |
872 | /* FIXME: We still need to set our filters properly */ |
873 | ||
c87dec9f JO |
874 | spin_lock_irqsave(&wl->wl_lock, flags); |
875 | kfree(wl->filter_params); | |
876 | wl->filter_params = fp; | |
877 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
878 | ||
879 | return 1; | |
880 | } | |
f5fc0f86 LC |
881 | |
882 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, | |
883 | unsigned int changed, | |
c87dec9f | 884 | unsigned int *total, u64 multicast) |
f5fc0f86 LC |
885 | { |
886 | struct wl1271 *wl = hw->priv; | |
887 | ||
888 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter"); | |
889 | ||
890 | *total &= WL1271_SUPPORTED_FILTERS; | |
891 | changed &= WL1271_SUPPORTED_FILTERS; | |
892 | ||
c87dec9f | 893 | if (!multicast) |
f5fc0f86 LC |
894 | return; |
895 | ||
f5fc0f86 | 896 | /* |
c87dec9f JO |
897 | * FIXME: for now we are still using a workqueue for filter |
898 | * configuration, but with the new mac80211, this is not needed, | |
899 | * since configure_filter can now sleep. We now have | |
900 | * prepare_multicast, which needs to be atomic instead. | |
f5fc0f86 | 901 | */ |
c87dec9f JO |
902 | |
903 | /* store current filter config */ | |
904 | wl->filter_params->filters = *total; | |
905 | wl->filter_params->changed = changed; | |
906 | ||
907 | ieee80211_queue_work(wl->hw, &wl->filter_work); | |
f5fc0f86 LC |
908 | } |
909 | ||
910 | static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | |
911 | struct ieee80211_vif *vif, | |
912 | struct ieee80211_sta *sta, | |
913 | struct ieee80211_key_conf *key_conf) | |
914 | { | |
915 | struct wl1271 *wl = hw->priv; | |
916 | const u8 *addr; | |
917 | int ret; | |
ac4e4ce5 JO |
918 | u32 tx_seq_32 = 0; |
919 | u16 tx_seq_16 = 0; | |
f5fc0f86 LC |
920 | u8 key_type; |
921 | ||
922 | static const u8 bcast_addr[ETH_ALEN] = | |
923 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
924 | ||
925 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); | |
926 | ||
927 | addr = sta ? sta->addr : bcast_addr; | |
928 | ||
929 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd); | |
930 | wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN); | |
931 | wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x", | |
932 | key_conf->alg, key_conf->keyidx, | |
933 | key_conf->keylen, key_conf->flags); | |
934 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); | |
935 | ||
936 | if (is_zero_ether_addr(addr)) { | |
937 | /* We dont support TX only encryption */ | |
938 | ret = -EOPNOTSUPP; | |
939 | goto out; | |
940 | } | |
941 | ||
942 | mutex_lock(&wl->mutex); | |
943 | ||
944 | ret = wl1271_ps_elp_wakeup(wl, false); | |
945 | if (ret < 0) | |
946 | goto out_unlock; | |
947 | ||
948 | switch (key_conf->alg) { | |
949 | case ALG_WEP: | |
950 | key_type = KEY_WEP; | |
951 | ||
952 | key_conf->hw_key_idx = key_conf->keyidx; | |
953 | break; | |
954 | case ALG_TKIP: | |
955 | key_type = KEY_TKIP; | |
956 | ||
957 | key_conf->hw_key_idx = key_conf->keyidx; | |
ac4e4ce5 JO |
958 | tx_seq_32 = wl->tx_security_seq_32; |
959 | tx_seq_16 = wl->tx_security_seq_16; | |
f5fc0f86 LC |
960 | break; |
961 | case ALG_CCMP: | |
962 | key_type = KEY_AES; | |
963 | ||
964 | key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
ac4e4ce5 JO |
965 | tx_seq_32 = wl->tx_security_seq_32; |
966 | tx_seq_16 = wl->tx_security_seq_16; | |
f5fc0f86 LC |
967 | break; |
968 | default: | |
969 | wl1271_error("Unknown key algo 0x%x", key_conf->alg); | |
970 | ||
971 | ret = -EOPNOTSUPP; | |
972 | goto out_sleep; | |
973 | } | |
974 | ||
975 | switch (cmd) { | |
976 | case SET_KEY: | |
977 | ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE, | |
978 | key_conf->keyidx, key_type, | |
979 | key_conf->keylen, key_conf->key, | |
ac4e4ce5 | 980 | addr, tx_seq_32, tx_seq_16); |
f5fc0f86 LC |
981 | if (ret < 0) { |
982 | wl1271_error("Could not add or replace key"); | |
983 | goto out_sleep; | |
984 | } | |
985 | break; | |
986 | ||
987 | case DISABLE_KEY: | |
988 | ret = wl1271_cmd_set_key(wl, KEY_REMOVE, | |
989 | key_conf->keyidx, key_type, | |
990 | key_conf->keylen, key_conf->key, | |
ac4e4ce5 | 991 | addr, 0, 0); |
f5fc0f86 LC |
992 | if (ret < 0) { |
993 | wl1271_error("Could not remove key"); | |
994 | goto out_sleep; | |
995 | } | |
996 | break; | |
997 | ||
998 | default: | |
999 | wl1271_error("Unsupported key cmd 0x%x", cmd); | |
1000 | ret = -EOPNOTSUPP; | |
1001 | goto out_sleep; | |
1002 | ||
1003 | break; | |
1004 | } | |
1005 | ||
1006 | out_sleep: | |
1007 | wl1271_ps_elp_sleep(wl); | |
1008 | ||
1009 | out_unlock: | |
1010 | mutex_unlock(&wl->mutex); | |
1011 | ||
1012 | out: | |
1013 | return ret; | |
1014 | } | |
1015 | ||
1016 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, | |
1017 | struct cfg80211_scan_request *req) | |
1018 | { | |
1019 | struct wl1271 *wl = hw->priv; | |
1020 | int ret; | |
1021 | u8 *ssid = NULL; | |
1022 | size_t ssid_len = 0; | |
1023 | ||
1024 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); | |
1025 | ||
1026 | if (req->n_ssids) { | |
1027 | ssid = req->ssids[0].ssid; | |
1028 | ssid_len = req->ssids[0].ssid_len; | |
1029 | } | |
1030 | ||
1031 | mutex_lock(&wl->mutex); | |
1032 | ||
1033 | ret = wl1271_ps_elp_wakeup(wl, false); | |
1034 | if (ret < 0) | |
1035 | goto out; | |
1036 | ||
1037 | ret = wl1271_cmd_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3); | |
1038 | ||
1039 | wl1271_ps_elp_sleep(wl); | |
1040 | ||
1041 | out: | |
1042 | mutex_unlock(&wl->mutex); | |
1043 | ||
1044 | return ret; | |
1045 | } | |
1046 | ||
1047 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
1048 | { | |
1049 | struct wl1271 *wl = hw->priv; | |
1050 | int ret; | |
1051 | ||
1052 | mutex_lock(&wl->mutex); | |
1053 | ||
1054 | ret = wl1271_ps_elp_wakeup(wl, false); | |
1055 | if (ret < 0) | |
1056 | goto out; | |
1057 | ||
1058 | ret = wl1271_acx_rts_threshold(wl, (u16) value); | |
1059 | if (ret < 0) | |
1060 | wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret); | |
1061 | ||
1062 | wl1271_ps_elp_sleep(wl); | |
1063 | ||
1064 | out: | |
1065 | mutex_unlock(&wl->mutex); | |
1066 | ||
1067 | return ret; | |
1068 | } | |
1069 | ||
8a5a37a6 JO |
1070 | static u32 wl1271_enabled_rates_get(struct wl1271 *wl, u64 basic_rate_set) |
1071 | { | |
1072 | struct ieee80211_supported_band *band; | |
1073 | u32 enabled_rates = 0; | |
1074 | int bit; | |
1075 | ||
1076 | band = wl->hw->wiphy->bands[wl->band]; | |
1077 | for (bit = 0; bit < band->n_bitrates; bit++) { | |
1078 | if (basic_rate_set & 0x1) | |
1079 | enabled_rates |= band->bitrates[bit].hw_value; | |
1080 | basic_rate_set >>= 1; | |
1081 | } | |
1082 | ||
1083 | return enabled_rates; | |
1084 | } | |
1085 | ||
f5fc0f86 LC |
1086 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, |
1087 | struct ieee80211_vif *vif, | |
1088 | struct ieee80211_bss_conf *bss_conf, | |
1089 | u32 changed) | |
1090 | { | |
1091 | enum wl1271_cmd_ps_mode mode; | |
1092 | struct wl1271 *wl = hw->priv; | |
1093 | int ret; | |
1094 | ||
1095 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed"); | |
1096 | ||
1097 | mutex_lock(&wl->mutex); | |
1098 | ||
1099 | ret = wl1271_ps_elp_wakeup(wl, false); | |
1100 | if (ret < 0) | |
1101 | goto out; | |
1102 | ||
1103 | if (changed & BSS_CHANGED_ASSOC) { | |
1104 | if (bss_conf->assoc) { | |
d94cd297 JO |
1105 | wl->beacon_int = bss_conf->beacon_int; |
1106 | wl->dtim_period = bss_conf->dtim_period; | |
f5fc0f86 LC |
1107 | wl->aid = bss_conf->aid; |
1108 | ||
d94cd297 JO |
1109 | ret = wl1271_cmd_join(wl); |
1110 | if (ret < 0) { | |
1111 | wl1271_warning("Association configuration " | |
1112 | "failed %d", ret); | |
1113 | goto out_sleep; | |
1114 | } | |
1115 | ||
f5fc0f86 LC |
1116 | ret = wl1271_cmd_build_ps_poll(wl, wl->aid); |
1117 | if (ret < 0) | |
1118 | goto out_sleep; | |
1119 | ||
1120 | ret = wl1271_acx_aid(wl, wl->aid); | |
1121 | if (ret < 0) | |
1122 | goto out_sleep; | |
1123 | ||
1124 | /* If we want to go in PSM but we're not there yet */ | |
1125 | if (wl->psm_requested && !wl->psm) { | |
1126 | mode = STATION_POWER_SAVE_MODE; | |
1127 | ret = wl1271_ps_set_mode(wl, mode); | |
1128 | if (ret < 0) | |
1129 | goto out_sleep; | |
1130 | } | |
d94cd297 JO |
1131 | } else { |
1132 | /* use defaults when not associated */ | |
1133 | wl->beacon_int = WL1271_DEFAULT_BEACON_INT; | |
1134 | wl->dtim_period = WL1271_DEFAULT_DTIM_PERIOD; | |
1135 | wl->basic_rate_set = WL1271_DEFAULT_BASIC_RATE_SET; | |
1136 | wl->aid = 0; | |
f5fc0f86 | 1137 | } |
d94cd297 | 1138 | |
f5fc0f86 | 1139 | } |
8a5a37a6 | 1140 | |
f5fc0f86 LC |
1141 | if (changed & BSS_CHANGED_ERP_SLOT) { |
1142 | if (bss_conf->use_short_slot) | |
1143 | ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT); | |
1144 | else | |
1145 | ret = wl1271_acx_slot(wl, SLOT_TIME_LONG); | |
1146 | if (ret < 0) { | |
1147 | wl1271_warning("Set slot time failed %d", ret); | |
1148 | goto out_sleep; | |
1149 | } | |
1150 | } | |
1151 | ||
1152 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
1153 | if (bss_conf->use_short_preamble) | |
1154 | wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT); | |
1155 | else | |
1156 | wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG); | |
1157 | } | |
1158 | ||
1159 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
1160 | if (bss_conf->use_cts_prot) | |
1161 | ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE); | |
1162 | else | |
1163 | ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE); | |
1164 | if (ret < 0) { | |
1165 | wl1271_warning("Set ctsprotect failed %d", ret); | |
1166 | goto out_sleep; | |
1167 | } | |
1168 | } | |
1169 | ||
8a5a37a6 | 1170 | if (changed & BSS_CHANGED_BASIC_RATES) { |
d94cd297 | 1171 | wl->basic_rate_set = wl1271_enabled_rates_get( |
8a5a37a6 | 1172 | wl, bss_conf->basic_rates); |
d94cd297 JO |
1173 | ret = wl1271_acx_rate_policies(wl, wl->basic_rate_set); |
1174 | ||
8a5a37a6 JO |
1175 | if (ret < 0) { |
1176 | wl1271_warning("Set rate policies failed %d", ret); | |
1177 | goto out_sleep; | |
1178 | } | |
d94cd297 JO |
1179 | ret = wl1271_cmd_join(wl); |
1180 | if (ret < 0) { | |
1181 | wl1271_warning("Join with new basic rate " | |
1182 | "set failed %d", ret); | |
1183 | goto out_sleep; | |
1184 | } | |
8a5a37a6 JO |
1185 | } |
1186 | ||
f5fc0f86 LC |
1187 | out_sleep: |
1188 | wl1271_ps_elp_sleep(wl); | |
1189 | ||
1190 | out: | |
1191 | mutex_unlock(&wl->mutex); | |
1192 | } | |
1193 | ||
1194 | ||
1195 | /* can't be const, mac80211 writes to this */ | |
1196 | static struct ieee80211_rate wl1271_rates[] = { | |
1197 | { .bitrate = 10, | |
1198 | .hw_value = 0x1, | |
1199 | .hw_value_short = 0x1, }, | |
1200 | { .bitrate = 20, | |
1201 | .hw_value = 0x2, | |
1202 | .hw_value_short = 0x2, | |
1203 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
1204 | { .bitrate = 55, | |
1205 | .hw_value = 0x4, | |
1206 | .hw_value_short = 0x4, | |
1207 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
1208 | { .bitrate = 110, | |
1209 | .hw_value = 0x20, | |
1210 | .hw_value_short = 0x20, | |
1211 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
1212 | { .bitrate = 60, | |
1213 | .hw_value = 0x8, | |
1214 | .hw_value_short = 0x8, }, | |
1215 | { .bitrate = 90, | |
1216 | .hw_value = 0x10, | |
1217 | .hw_value_short = 0x10, }, | |
1218 | { .bitrate = 120, | |
1219 | .hw_value = 0x40, | |
1220 | .hw_value_short = 0x40, }, | |
1221 | { .bitrate = 180, | |
1222 | .hw_value = 0x80, | |
1223 | .hw_value_short = 0x80, }, | |
1224 | { .bitrate = 240, | |
1225 | .hw_value = 0x200, | |
1226 | .hw_value_short = 0x200, }, | |
1227 | { .bitrate = 360, | |
1228 | .hw_value = 0x400, | |
1229 | .hw_value_short = 0x400, }, | |
1230 | { .bitrate = 480, | |
1231 | .hw_value = 0x800, | |
1232 | .hw_value_short = 0x800, }, | |
1233 | { .bitrate = 540, | |
1234 | .hw_value = 0x1000, | |
1235 | .hw_value_short = 0x1000, }, | |
1236 | }; | |
1237 | ||
1238 | /* can't be const, mac80211 writes to this */ | |
1239 | static struct ieee80211_channel wl1271_channels[] = { | |
1240 | { .hw_value = 1, .center_freq = 2412}, | |
1241 | { .hw_value = 2, .center_freq = 2417}, | |
1242 | { .hw_value = 3, .center_freq = 2422}, | |
1243 | { .hw_value = 4, .center_freq = 2427}, | |
1244 | { .hw_value = 5, .center_freq = 2432}, | |
1245 | { .hw_value = 6, .center_freq = 2437}, | |
1246 | { .hw_value = 7, .center_freq = 2442}, | |
1247 | { .hw_value = 8, .center_freq = 2447}, | |
1248 | { .hw_value = 9, .center_freq = 2452}, | |
1249 | { .hw_value = 10, .center_freq = 2457}, | |
1250 | { .hw_value = 11, .center_freq = 2462}, | |
1251 | { .hw_value = 12, .center_freq = 2467}, | |
1252 | { .hw_value = 13, .center_freq = 2472}, | |
1253 | }; | |
1254 | ||
1255 | /* can't be const, mac80211 writes to this */ | |
1256 | static struct ieee80211_supported_band wl1271_band_2ghz = { | |
1257 | .channels = wl1271_channels, | |
1258 | .n_channels = ARRAY_SIZE(wl1271_channels), | |
1259 | .bitrates = wl1271_rates, | |
1260 | .n_bitrates = ARRAY_SIZE(wl1271_rates), | |
1261 | }; | |
1262 | ||
1263 | static const struct ieee80211_ops wl1271_ops = { | |
1264 | .start = wl1271_op_start, | |
1265 | .stop = wl1271_op_stop, | |
1266 | .add_interface = wl1271_op_add_interface, | |
1267 | .remove_interface = wl1271_op_remove_interface, | |
1268 | .config = wl1271_op_config, | |
1269 | /* .config_interface = wl1271_op_config_interface, */ | |
c87dec9f | 1270 | .prepare_multicast = wl1271_op_prepare_multicast, |
f5fc0f86 LC |
1271 | .configure_filter = wl1271_op_configure_filter, |
1272 | .tx = wl1271_op_tx, | |
1273 | .set_key = wl1271_op_set_key, | |
1274 | .hw_scan = wl1271_op_hw_scan, | |
1275 | .bss_info_changed = wl1271_op_bss_info_changed, | |
1276 | .set_rts_threshold = wl1271_op_set_rts_threshold, | |
1277 | }; | |
1278 | ||
1279 | static int wl1271_register_hw(struct wl1271 *wl) | |
1280 | { | |
1281 | int ret; | |
1282 | ||
1283 | if (wl->mac80211_registered) | |
1284 | return 0; | |
1285 | ||
1286 | SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr); | |
1287 | ||
1288 | ret = ieee80211_register_hw(wl->hw); | |
1289 | if (ret < 0) { | |
1290 | wl1271_error("unable to register mac80211 hw: %d", ret); | |
1291 | return ret; | |
1292 | } | |
1293 | ||
1294 | wl->mac80211_registered = true; | |
1295 | ||
1296 | wl1271_notice("loaded"); | |
1297 | ||
1298 | return 0; | |
1299 | } | |
1300 | ||
1301 | static int wl1271_init_ieee80211(struct wl1271 *wl) | |
1302 | { | |
1e2b7976 JO |
1303 | /* The tx descriptor buffer and the TKIP space. */ |
1304 | wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE + | |
1305 | sizeof(struct wl1271_tx_hw_descr); | |
f5fc0f86 LC |
1306 | |
1307 | /* unit us */ | |
1308 | /* FIXME: find a proper value */ | |
1309 | wl->hw->channel_change_time = 10000; | |
1310 | ||
1311 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | | |
1922167b JO |
1312 | IEEE80211_HW_NOISE_DBM | |
1313 | IEEE80211_HW_BEACON_FILTER; | |
f5fc0f86 LC |
1314 | |
1315 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); | |
1316 | wl->hw->wiphy->max_scan_ssids = 1; | |
1317 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz; | |
1318 | ||
1319 | SET_IEEE80211_DEV(wl->hw, &wl->spi->dev); | |
1320 | ||
1321 | return 0; | |
1322 | } | |
1323 | ||
1324 | static void wl1271_device_release(struct device *dev) | |
1325 | { | |
1326 | ||
1327 | } | |
1328 | ||
1329 | static struct platform_device wl1271_device = { | |
1330 | .name = "wl1271", | |
1331 | .id = -1, | |
1332 | ||
1333 | /* device model insists to have a release function */ | |
1334 | .dev = { | |
1335 | .release = wl1271_device_release, | |
1336 | }, | |
1337 | }; | |
1338 | ||
1339 | #define WL1271_DEFAULT_CHANNEL 0 | |
1340 | static int __devinit wl1271_probe(struct spi_device *spi) | |
1341 | { | |
1342 | struct wl12xx_platform_data *pdata; | |
1343 | struct ieee80211_hw *hw; | |
1344 | struct wl1271 *wl; | |
1345 | int ret, i; | |
1346 | static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; | |
1347 | ||
1348 | pdata = spi->dev.platform_data; | |
1349 | if (!pdata) { | |
1350 | wl1271_error("no platform data"); | |
1351 | return -ENODEV; | |
1352 | } | |
1353 | ||
1354 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); | |
1355 | if (!hw) { | |
1356 | wl1271_error("could not alloc ieee80211_hw"); | |
1357 | return -ENOMEM; | |
1358 | } | |
1359 | ||
1360 | wl = hw->priv; | |
1361 | memset(wl, 0, sizeof(*wl)); | |
1362 | ||
1363 | wl->hw = hw; | |
1364 | dev_set_drvdata(&spi->dev, wl); | |
1365 | wl->spi = spi; | |
1366 | ||
1367 | skb_queue_head_init(&wl->tx_queue); | |
1368 | ||
1369 | INIT_WORK(&wl->filter_work, wl1271_filter_work); | |
37b70a81 | 1370 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); |
f5fc0f86 LC |
1371 | wl->channel = WL1271_DEFAULT_CHANNEL; |
1372 | wl->scanning = false; | |
1373 | wl->default_key = 0; | |
1374 | wl->listen_int = 1; | |
1375 | wl->rx_counter = 0; | |
1376 | wl->rx_config = WL1271_DEFAULT_RX_CONFIG; | |
1377 | wl->rx_filter = WL1271_DEFAULT_RX_FILTER; | |
1378 | wl->elp = false; | |
1379 | wl->psm = 0; | |
1380 | wl->psm_requested = false; | |
1381 | wl->tx_queue_stopped = false; | |
1382 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; | |
d94cd297 JO |
1383 | wl->beacon_int = WL1271_DEFAULT_BEACON_INT; |
1384 | wl->dtim_period = WL1271_DEFAULT_DTIM_PERIOD; | |
1385 | wl->basic_rate_set = WL1271_DEFAULT_BASIC_RATE_SET; | |
8a5a37a6 | 1386 | wl->band = IEEE80211_BAND_2GHZ; |
b771eee5 | 1387 | wl->vif = NULL; |
d6e19d13 | 1388 | wl->joined = false; |
f5fc0f86 | 1389 | |
be7078c2 | 1390 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
f5fc0f86 LC |
1391 | wl->tx_frames[i] = NULL; |
1392 | ||
1393 | spin_lock_init(&wl->wl_lock); | |
1394 | ||
1395 | /* | |
1396 | * In case our MAC address is not correctly set, | |
1397 | * we use a random but Nokia MAC. | |
1398 | */ | |
1399 | memcpy(wl->mac_addr, nokia_oui, 3); | |
1400 | get_random_bytes(wl->mac_addr + 3, 3); | |
1401 | ||
1402 | wl->state = WL1271_STATE_OFF; | |
1403 | mutex_init(&wl->mutex); | |
1404 | ||
1405 | wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL); | |
1406 | if (!wl->rx_descriptor) { | |
1407 | wl1271_error("could not allocate memory for rx descriptor"); | |
1408 | ret = -ENOMEM; | |
1409 | goto out_free; | |
1410 | } | |
1411 | ||
1412 | /* This is the only SPI value that we need to set here, the rest | |
1413 | * comes from the board-peripherals file */ | |
1414 | spi->bits_per_word = 32; | |
1415 | ||
1416 | ret = spi_setup(spi); | |
1417 | if (ret < 0) { | |
1418 | wl1271_error("spi_setup failed"); | |
1419 | goto out_free; | |
1420 | } | |
1421 | ||
1422 | wl->set_power = pdata->set_power; | |
1423 | if (!wl->set_power) { | |
1424 | wl1271_error("set power function missing in platform data"); | |
1425 | ret = -ENODEV; | |
1426 | goto out_free; | |
1427 | } | |
1428 | ||
1429 | wl->irq = spi->irq; | |
1430 | if (wl->irq < 0) { | |
1431 | wl1271_error("irq missing in platform data"); | |
1432 | ret = -ENODEV; | |
1433 | goto out_free; | |
1434 | } | |
1435 | ||
1436 | ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl); | |
1437 | if (ret < 0) { | |
1438 | wl1271_error("request_irq() failed: %d", ret); | |
1439 | goto out_free; | |
1440 | } | |
1441 | ||
1442 | set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING); | |
1443 | ||
1444 | disable_irq(wl->irq); | |
1445 | ||
1446 | ret = platform_device_register(&wl1271_device); | |
1447 | if (ret) { | |
1448 | wl1271_error("couldn't register platform device"); | |
1449 | goto out_irq; | |
1450 | } | |
1451 | dev_set_drvdata(&wl1271_device.dev, wl); | |
1452 | ||
1453 | ret = wl1271_init_ieee80211(wl); | |
1454 | if (ret) | |
1455 | goto out_platform; | |
1456 | ||
1457 | ret = wl1271_register_hw(wl); | |
1458 | if (ret) | |
1459 | goto out_platform; | |
1460 | ||
1461 | wl1271_debugfs_init(wl); | |
1462 | ||
1463 | wl1271_notice("initialized"); | |
1464 | ||
1465 | return 0; | |
1466 | ||
1467 | out_platform: | |
1468 | platform_device_unregister(&wl1271_device); | |
1469 | ||
1470 | out_irq: | |
1471 | free_irq(wl->irq, wl); | |
1472 | ||
1473 | out_free: | |
1474 | kfree(wl->rx_descriptor); | |
1475 | wl->rx_descriptor = NULL; | |
1476 | ||
1477 | ieee80211_free_hw(hw); | |
1478 | ||
1479 | return ret; | |
1480 | } | |
1481 | ||
1482 | static int __devexit wl1271_remove(struct spi_device *spi) | |
1483 | { | |
1484 | struct wl1271 *wl = dev_get_drvdata(&spi->dev); | |
1485 | ||
1486 | ieee80211_unregister_hw(wl->hw); | |
1487 | ||
1488 | wl1271_debugfs_exit(wl); | |
1489 | platform_device_unregister(&wl1271_device); | |
1490 | free_irq(wl->irq, wl); | |
1491 | kfree(wl->target_mem_map); | |
1fba4974 | 1492 | vfree(wl->fw); |
f5fc0f86 LC |
1493 | wl->fw = NULL; |
1494 | kfree(wl->nvs); | |
1495 | wl->nvs = NULL; | |
1496 | ||
1497 | kfree(wl->rx_descriptor); | |
1498 | wl->rx_descriptor = NULL; | |
1499 | ||
1500 | kfree(wl->fw_status); | |
1501 | kfree(wl->tx_res_if); | |
1502 | ||
1503 | ieee80211_free_hw(wl->hw); | |
1504 | ||
1505 | return 0; | |
1506 | } | |
1507 | ||
1508 | ||
1509 | static struct spi_driver wl1271_spi_driver = { | |
1510 | .driver = { | |
1511 | .name = "wl1271", | |
1512 | .bus = &spi_bus_type, | |
1513 | .owner = THIS_MODULE, | |
1514 | }, | |
1515 | ||
1516 | .probe = wl1271_probe, | |
1517 | .remove = __devexit_p(wl1271_remove), | |
1518 | }; | |
1519 | ||
1520 | static int __init wl1271_init(void) | |
1521 | { | |
1522 | int ret; | |
1523 | ||
1524 | ret = spi_register_driver(&wl1271_spi_driver); | |
1525 | if (ret < 0) { | |
1526 | wl1271_error("failed to register spi driver: %d", ret); | |
1527 | goto out; | |
1528 | } | |
1529 | ||
1530 | out: | |
1531 | return ret; | |
1532 | } | |
1533 | ||
1534 | static void __exit wl1271_exit(void) | |
1535 | { | |
1536 | spi_unregister_driver(&wl1271_spi_driver); | |
1537 | ||
1538 | wl1271_notice("unloaded"); | |
1539 | } | |
1540 | ||
1541 | module_init(wl1271_init); | |
1542 | module_exit(wl1271_exit); | |
1543 | ||
1544 | MODULE_LICENSE("GPL"); | |
1545 | MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>"); | |
2f018725 | 1546 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |