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