wl1271: Moved module basics to wl1271_spi.c
[deliverable/linux.git] / drivers / net / wireless / wl12xx / wl1271_main.c
1 /*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-2010 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/firmware.h>
26 #include <linux/delay.h>
27 #include <linux/spi/spi.h>
28 #include <linux/crc32.h>
29 #include <linux/etherdevice.h>
30 #include <linux/vmalloc.h>
31 #include <linux/inetdevice.h>
32
33 #include "wl1271.h"
34 #include "wl12xx_80211.h"
35 #include "wl1271_reg.h"
36 #include "wl1271_spi.h"
37 #include "wl1271_io.h"
38 #include "wl1271_event.h"
39 #include "wl1271_tx.h"
40 #include "wl1271_rx.h"
41 #include "wl1271_ps.h"
42 #include "wl1271_init.h"
43 #include "wl1271_debugfs.h"
44 #include "wl1271_cmd.h"
45 #include "wl1271_boot.h"
46 #include "wl1271_testmode.h"
47
48 #define WL1271_BOOT_RETRIES 3
49
50 static struct conf_drv_settings default_conf = {
51 .sg = {
52 .per_threshold = 7500,
53 .max_scan_compensation_time = 120000,
54 .nfs_sample_interval = 400,
55 .load_ratio = 50,
56 .auto_ps_mode = 0,
57 .probe_req_compensation = 170,
58 .scan_window_compensation = 50,
59 .antenna_config = 0,
60 .beacon_miss_threshold = 60,
61 .rate_adaptation_threshold = CONF_HW_BIT_RATE_12MBPS,
62 .rate_adaptation_snr = 0
63 },
64 .rx = {
65 .rx_msdu_life_time = 512000,
66 .packet_detection_threshold = 0,
67 .ps_poll_timeout = 15,
68 .upsd_timeout = 15,
69 .rts_threshold = 2347,
70 .rx_cca_threshold = 0,
71 .irq_blk_threshold = 0xFFFF,
72 .irq_pkt_threshold = 0,
73 .irq_timeout = 600,
74 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
75 },
76 .tx = {
77 .tx_energy_detection = 0,
78 .rc_conf = {
79 .enabled_rates = CONF_HW_BIT_RATE_1MBPS |
80 CONF_HW_BIT_RATE_2MBPS,
81 .short_retry_limit = 10,
82 .long_retry_limit = 10,
83 .aflags = 0
84 },
85 .ac_conf_count = 4,
86 .ac_conf = {
87 [0] = {
88 .ac = CONF_TX_AC_BE,
89 .cw_min = 15,
90 .cw_max = 63,
91 .aifsn = 3,
92 .tx_op_limit = 0,
93 },
94 [1] = {
95 .ac = CONF_TX_AC_BK,
96 .cw_min = 15,
97 .cw_max = 63,
98 .aifsn = 7,
99 .tx_op_limit = 0,
100 },
101 [2] = {
102 .ac = CONF_TX_AC_VI,
103 .cw_min = 15,
104 .cw_max = 63,
105 .aifsn = CONF_TX_AIFS_PIFS,
106 .tx_op_limit = 3008,
107 },
108 [3] = {
109 .ac = CONF_TX_AC_VO,
110 .cw_min = 15,
111 .cw_max = 63,
112 .aifsn = CONF_TX_AIFS_PIFS,
113 .tx_op_limit = 1504,
114 },
115 },
116 .tid_conf_count = 7,
117 .tid_conf = {
118 [0] = {
119 .queue_id = 0,
120 .channel_type = CONF_CHANNEL_TYPE_DCF,
121 .tsid = CONF_TX_AC_BE,
122 .ps_scheme = CONF_PS_SCHEME_LEGACY,
123 .ack_policy = CONF_ACK_POLICY_LEGACY,
124 .apsd_conf = {0, 0},
125 },
126 [1] = {
127 .queue_id = 1,
128 .channel_type = CONF_CHANNEL_TYPE_DCF,
129 .tsid = CONF_TX_AC_BE,
130 .ps_scheme = CONF_PS_SCHEME_LEGACY,
131 .ack_policy = CONF_ACK_POLICY_LEGACY,
132 .apsd_conf = {0, 0},
133 },
134 [2] = {
135 .queue_id = 2,
136 .channel_type = CONF_CHANNEL_TYPE_DCF,
137 .tsid = CONF_TX_AC_BE,
138 .ps_scheme = CONF_PS_SCHEME_LEGACY,
139 .ack_policy = CONF_ACK_POLICY_LEGACY,
140 .apsd_conf = {0, 0},
141 },
142 [3] = {
143 .queue_id = 3,
144 .channel_type = CONF_CHANNEL_TYPE_DCF,
145 .tsid = CONF_TX_AC_BE,
146 .ps_scheme = CONF_PS_SCHEME_LEGACY,
147 .ack_policy = CONF_ACK_POLICY_LEGACY,
148 .apsd_conf = {0, 0},
149 },
150 [4] = {
151 .queue_id = 4,
152 .channel_type = CONF_CHANNEL_TYPE_DCF,
153 .tsid = CONF_TX_AC_BE,
154 .ps_scheme = CONF_PS_SCHEME_LEGACY,
155 .ack_policy = CONF_ACK_POLICY_LEGACY,
156 .apsd_conf = {0, 0},
157 },
158 [5] = {
159 .queue_id = 5,
160 .channel_type = CONF_CHANNEL_TYPE_DCF,
161 .tsid = CONF_TX_AC_BE,
162 .ps_scheme = CONF_PS_SCHEME_LEGACY,
163 .ack_policy = CONF_ACK_POLICY_LEGACY,
164 .apsd_conf = {0, 0},
165 },
166 [6] = {
167 .queue_id = 6,
168 .channel_type = CONF_CHANNEL_TYPE_DCF,
169 .tsid = CONF_TX_AC_BE,
170 .ps_scheme = CONF_PS_SCHEME_LEGACY,
171 .ack_policy = CONF_ACK_POLICY_LEGACY,
172 .apsd_conf = {0, 0},
173 }
174 },
175 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
176 .tx_compl_timeout = 700,
177 .tx_compl_threshold = 4
178 },
179 .conn = {
180 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
181 .listen_interval = 0,
182 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
183 .bcn_filt_ie_count = 1,
184 .bcn_filt_ie = {
185 [0] = {
186 .ie = WLAN_EID_CHANNEL_SWITCH,
187 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
188 }
189 },
190 .synch_fail_thold = 10,
191 .bss_lose_timeout = 100,
192 .beacon_rx_timeout = 10000,
193 .broadcast_timeout = 20000,
194 .rx_broadcast_in_ps = 1,
195 .ps_poll_threshold = 20,
196 .sig_trigger_count = 2,
197 .sig_trigger = {
198 [0] = {
199 .threshold = -75,
200 .pacing = 500,
201 .metric = CONF_TRIG_METRIC_RSSI_BEACON,
202 .type = CONF_TRIG_EVENT_TYPE_EDGE,
203 .direction = CONF_TRIG_EVENT_DIR_LOW,
204 .hysteresis = 2,
205 .index = 0,
206 .enable = 1
207 },
208 [1] = {
209 .threshold = -75,
210 .pacing = 500,
211 .metric = CONF_TRIG_METRIC_RSSI_BEACON,
212 .type = CONF_TRIG_EVENT_TYPE_EDGE,
213 .direction = CONF_TRIG_EVENT_DIR_HIGH,
214 .hysteresis = 2,
215 .index = 1,
216 .enable = 1
217 }
218 },
219 .sig_weights = {
220 .rssi_bcn_avg_weight = 10,
221 .rssi_pkt_avg_weight = 10,
222 .snr_bcn_avg_weight = 10,
223 .snr_pkt_avg_weight = 10
224 },
225 .bet_enable = CONF_BET_MODE_ENABLE,
226 .bet_max_consecutive = 10,
227 .psm_entry_retries = 3
228 },
229 .init = {
230 .radioparam = {
231 .fem = 1,
232 }
233 },
234 .itrim = {
235 .enable = false,
236 .timeout = 50000,
237 },
238 .pm_config = {
239 .host_clk_settling_time = 5000,
240 .host_fast_wakeup_support = false
241 }
242 };
243
244 static LIST_HEAD(wl_list);
245
246 static void wl1271_conf_init(struct wl1271 *wl)
247 {
248
249 /*
250 * This function applies the default configuration to the driver. This
251 * function is invoked upon driver load (spi probe.)
252 *
253 * The configuration is stored in a run-time structure in order to
254 * facilitate for run-time adjustment of any of the parameters. Making
255 * changes to the configuration structure will apply the new values on
256 * the next interface up (wl1271_op_start.)
257 */
258
259 /* apply driver default configuration */
260 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
261 }
262
263
264 static int wl1271_plt_init(struct wl1271 *wl)
265 {
266 struct conf_tx_ac_category *conf_ac;
267 struct conf_tx_tid *conf_tid;
268 int ret, i;
269
270 ret = wl1271_cmd_general_parms(wl);
271 if (ret < 0)
272 return ret;
273
274 ret = wl1271_cmd_radio_parms(wl);
275 if (ret < 0)
276 return ret;
277
278 ret = wl1271_init_templates_config(wl);
279 if (ret < 0)
280 return ret;
281
282 ret = wl1271_acx_init_mem_config(wl);
283 if (ret < 0)
284 return ret;
285
286 /* PHY layer config */
287 ret = wl1271_init_phy_config(wl);
288 if (ret < 0)
289 goto out_free_memmap;
290
291 ret = wl1271_acx_dco_itrim_params(wl);
292 if (ret < 0)
293 goto out_free_memmap;
294
295 /* Initialize connection monitoring thresholds */
296 ret = wl1271_acx_conn_monit_params(wl);
297 if (ret < 0)
298 goto out_free_memmap;
299
300 /* Bluetooth WLAN coexistence */
301 ret = wl1271_init_pta(wl);
302 if (ret < 0)
303 goto out_free_memmap;
304
305 /* Energy detection */
306 ret = wl1271_init_energy_detection(wl);
307 if (ret < 0)
308 goto out_free_memmap;
309
310 /* Default fragmentation threshold */
311 ret = wl1271_acx_frag_threshold(wl);
312 if (ret < 0)
313 goto out_free_memmap;
314
315 /* Default TID configuration */
316 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
317 conf_tid = &wl->conf.tx.tid_conf[i];
318 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
319 conf_tid->channel_type,
320 conf_tid->tsid,
321 conf_tid->ps_scheme,
322 conf_tid->ack_policy,
323 conf_tid->apsd_conf[0],
324 conf_tid->apsd_conf[1]);
325 if (ret < 0)
326 goto out_free_memmap;
327 }
328
329 /* Default AC configuration */
330 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
331 conf_ac = &wl->conf.tx.ac_conf[i];
332 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
333 conf_ac->cw_max, conf_ac->aifsn,
334 conf_ac->tx_op_limit);
335 if (ret < 0)
336 goto out_free_memmap;
337 }
338
339 /* Enable data path */
340 ret = wl1271_cmd_data_path(wl, 1);
341 if (ret < 0)
342 goto out_free_memmap;
343
344 /* Configure for CAM power saving (ie. always active) */
345 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
346 if (ret < 0)
347 goto out_free_memmap;
348
349 /* configure PM */
350 ret = wl1271_acx_pm_config(wl);
351 if (ret < 0)
352 goto out_free_memmap;
353
354 return 0;
355
356 out_free_memmap:
357 kfree(wl->target_mem_map);
358 wl->target_mem_map = NULL;
359
360 return ret;
361 }
362
363 static void wl1271_disable_interrupts(struct wl1271 *wl)
364 {
365 disable_irq(wl->irq);
366 }
367
368 static void wl1271_power_off(struct wl1271 *wl)
369 {
370 wl->set_power(false);
371 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
372 }
373
374 static void wl1271_power_on(struct wl1271 *wl)
375 {
376 wl->set_power(true);
377 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
378 }
379
380 static void wl1271_fw_status(struct wl1271 *wl,
381 struct wl1271_fw_status *status)
382 {
383 u32 total = 0;
384 int i;
385
386 wl1271_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
387
388 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
389 "drv_rx_counter = %d, tx_results_counter = %d)",
390 status->intr,
391 status->fw_rx_counter,
392 status->drv_rx_counter,
393 status->tx_results_counter);
394
395 /* update number of available TX blocks */
396 for (i = 0; i < NUM_TX_QUEUES; i++) {
397 u32 cnt = le32_to_cpu(status->tx_released_blks[i]) -
398 wl->tx_blocks_freed[i];
399
400 wl->tx_blocks_freed[i] =
401 le32_to_cpu(status->tx_released_blks[i]);
402 wl->tx_blocks_available += cnt;
403 total += cnt;
404 }
405
406 /* if more blocks are available now, schedule some tx work */
407 if (total && !skb_queue_empty(&wl->tx_queue))
408 ieee80211_queue_work(wl->hw, &wl->tx_work);
409
410 /* update the host-chipset time offset */
411 wl->time_offset = jiffies_to_usecs(jiffies) -
412 le32_to_cpu(status->fw_localtime);
413 }
414
415 static void wl1271_irq_work(struct work_struct *work)
416 {
417 int ret;
418 u32 intr;
419 struct wl1271 *wl =
420 container_of(work, struct wl1271, irq_work);
421
422 mutex_lock(&wl->mutex);
423
424 wl1271_debug(DEBUG_IRQ, "IRQ work");
425
426 if (wl->state == WL1271_STATE_OFF)
427 goto out;
428
429 ret = wl1271_ps_elp_wakeup(wl, true);
430 if (ret < 0)
431 goto out;
432
433 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
434
435 wl1271_fw_status(wl, wl->fw_status);
436 intr = le32_to_cpu(wl->fw_status->intr);
437 if (!intr) {
438 wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
439 goto out_sleep;
440 }
441
442 intr &= WL1271_INTR_MASK;
443
444 if (intr & WL1271_ACX_INTR_EVENT_A) {
445 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
446 wl1271_event_handle(wl, 0);
447 }
448
449 if (intr & WL1271_ACX_INTR_EVENT_B) {
450 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
451 wl1271_event_handle(wl, 1);
452 }
453
454 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
455 wl1271_debug(DEBUG_IRQ,
456 "WL1271_ACX_INTR_INIT_COMPLETE");
457
458 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
459 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
460
461 if (intr & WL1271_ACX_INTR_DATA) {
462 u8 tx_res_cnt = wl->fw_status->tx_results_counter -
463 wl->tx_results_count;
464
465 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
466
467 /* check for tx results */
468 if (tx_res_cnt)
469 wl1271_tx_complete(wl, tx_res_cnt);
470
471 wl1271_rx(wl, wl->fw_status);
472 }
473
474 out_sleep:
475 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
476 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
477 wl1271_ps_elp_sleep(wl);
478
479 out:
480 mutex_unlock(&wl->mutex);
481 }
482
483 static int wl1271_fetch_firmware(struct wl1271 *wl)
484 {
485 const struct firmware *fw;
486 int ret;
487
488 ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev);
489
490 if (ret < 0) {
491 wl1271_error("could not get firmware: %d", ret);
492 return ret;
493 }
494
495 if (fw->size % 4) {
496 wl1271_error("firmware size is not multiple of 32 bits: %zu",
497 fw->size);
498 ret = -EILSEQ;
499 goto out;
500 }
501
502 wl->fw_len = fw->size;
503 wl->fw = vmalloc(wl->fw_len);
504
505 if (!wl->fw) {
506 wl1271_error("could not allocate memory for the firmware");
507 ret = -ENOMEM;
508 goto out;
509 }
510
511 memcpy(wl->fw, fw->data, wl->fw_len);
512
513 ret = 0;
514
515 out:
516 release_firmware(fw);
517
518 return ret;
519 }
520
521 static int wl1271_update_mac_addr(struct wl1271 *wl)
522 {
523 int ret = 0;
524 u8 *nvs_ptr = (u8 *)wl->nvs->nvs;
525
526 /* get mac address from the NVS */
527 wl->mac_addr[0] = nvs_ptr[11];
528 wl->mac_addr[1] = nvs_ptr[10];
529 wl->mac_addr[2] = nvs_ptr[6];
530 wl->mac_addr[3] = nvs_ptr[5];
531 wl->mac_addr[4] = nvs_ptr[4];
532 wl->mac_addr[5] = nvs_ptr[3];
533
534 /* FIXME: if it is a zero-address, we should bail out. Now, instead,
535 we randomize an address */
536 if (is_zero_ether_addr(wl->mac_addr)) {
537 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
538 memcpy(wl->mac_addr, nokia_oui, 3);
539 get_random_bytes(wl->mac_addr + 3, 3);
540
541 /* update this address to the NVS */
542 nvs_ptr[11] = wl->mac_addr[0];
543 nvs_ptr[10] = wl->mac_addr[1];
544 nvs_ptr[6] = wl->mac_addr[2];
545 nvs_ptr[5] = wl->mac_addr[3];
546 nvs_ptr[4] = wl->mac_addr[4];
547 nvs_ptr[3] = wl->mac_addr[5];
548 }
549
550 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
551
552 return ret;
553 }
554
555 static int wl1271_fetch_nvs(struct wl1271 *wl)
556 {
557 const struct firmware *fw;
558 int ret;
559
560 ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev);
561
562 if (ret < 0) {
563 wl1271_error("could not get nvs file: %d", ret);
564 return ret;
565 }
566
567 if (fw->size != sizeof(struct wl1271_nvs_file)) {
568 wl1271_error("nvs size is not as expected: %zu != %zu",
569 fw->size, sizeof(struct wl1271_nvs_file));
570 ret = -EILSEQ;
571 goto out;
572 }
573
574 wl->nvs = kmalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL);
575
576 if (!wl->nvs) {
577 wl1271_error("could not allocate memory for the nvs file");
578 ret = -ENOMEM;
579 goto out;
580 }
581
582 memcpy(wl->nvs, fw->data, sizeof(struct wl1271_nvs_file));
583
584 ret = wl1271_update_mac_addr(wl);
585
586 out:
587 release_firmware(fw);
588
589 return ret;
590 }
591
592 static void wl1271_fw_wakeup(struct wl1271 *wl)
593 {
594 u32 elp_reg;
595
596 elp_reg = ELPCTRL_WAKE_UP;
597 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
598 }
599
600 static int wl1271_setup(struct wl1271 *wl)
601 {
602 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
603 if (!wl->fw_status)
604 return -ENOMEM;
605
606 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
607 if (!wl->tx_res_if) {
608 kfree(wl->fw_status);
609 return -ENOMEM;
610 }
611
612 INIT_WORK(&wl->irq_work, wl1271_irq_work);
613 INIT_WORK(&wl->tx_work, wl1271_tx_work);
614 return 0;
615 }
616
617 static int wl1271_chip_wakeup(struct wl1271 *wl)
618 {
619 struct wl1271_partition_set partition;
620 int ret = 0;
621
622 msleep(WL1271_PRE_POWER_ON_SLEEP);
623 wl1271_power_on(wl);
624 msleep(WL1271_POWER_ON_SLEEP);
625 wl1271_io_reset(wl);
626 wl1271_io_init(wl);
627
628 /* We don't need a real memory partition here, because we only want
629 * to use the registers at this point. */
630 memset(&partition, 0, sizeof(partition));
631 partition.reg.start = REGISTERS_BASE;
632 partition.reg.size = REGISTERS_DOWN_SIZE;
633 wl1271_set_partition(wl, &partition);
634
635 /* ELP module wake up */
636 wl1271_fw_wakeup(wl);
637
638 /* whal_FwCtrl_BootSm() */
639
640 /* 0. read chip id from CHIP_ID */
641 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
642
643 /* 1. check if chip id is valid */
644
645 switch (wl->chip.id) {
646 case CHIP_ID_1271_PG10:
647 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
648 wl->chip.id);
649
650 ret = wl1271_setup(wl);
651 if (ret < 0)
652 goto out;
653 break;
654 case CHIP_ID_1271_PG20:
655 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
656 wl->chip.id);
657
658 ret = wl1271_setup(wl);
659 if (ret < 0)
660 goto out;
661 break;
662 default:
663 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
664 ret = -ENODEV;
665 goto out;
666 }
667
668 if (wl->fw == NULL) {
669 ret = wl1271_fetch_firmware(wl);
670 if (ret < 0)
671 goto out;
672 }
673
674 /* No NVS from netlink, try to get it from the filesystem */
675 if (wl->nvs == NULL) {
676 ret = wl1271_fetch_nvs(wl);
677 if (ret < 0)
678 goto out;
679 }
680
681 out:
682 return ret;
683 }
684
685 int wl1271_plt_start(struct wl1271 *wl)
686 {
687 int retries = WL1271_BOOT_RETRIES;
688 int ret;
689
690 mutex_lock(&wl->mutex);
691
692 wl1271_notice("power up");
693
694 if (wl->state != WL1271_STATE_OFF) {
695 wl1271_error("cannot go into PLT state because not "
696 "in off state: %d", wl->state);
697 ret = -EBUSY;
698 goto out;
699 }
700
701 while (retries) {
702 retries--;
703 ret = wl1271_chip_wakeup(wl);
704 if (ret < 0)
705 goto power_off;
706
707 ret = wl1271_boot(wl);
708 if (ret < 0)
709 goto power_off;
710
711 ret = wl1271_plt_init(wl);
712 if (ret < 0)
713 goto irq_disable;
714
715 wl->state = WL1271_STATE_PLT;
716 wl1271_notice("firmware booted in PLT mode (%s)",
717 wl->chip.fw_ver);
718 goto out;
719
720 irq_disable:
721 wl1271_disable_interrupts(wl);
722 mutex_unlock(&wl->mutex);
723 /* Unlocking the mutex in the middle of handling is
724 inherently unsafe. In this case we deem it safe to do,
725 because we need to let any possibly pending IRQ out of
726 the system (and while we are WL1271_STATE_OFF the IRQ
727 work function will not do anything.) Also, any other
728 possible concurrent operations will fail due to the
729 current state, hence the wl1271 struct should be safe. */
730 cancel_work_sync(&wl->irq_work);
731 mutex_lock(&wl->mutex);
732 power_off:
733 wl1271_power_off(wl);
734 }
735
736 wl1271_error("firmware boot in PLT mode failed despite %d retries",
737 WL1271_BOOT_RETRIES);
738 out:
739 mutex_unlock(&wl->mutex);
740
741 return ret;
742 }
743
744 int wl1271_plt_stop(struct wl1271 *wl)
745 {
746 int ret = 0;
747
748 mutex_lock(&wl->mutex);
749
750 wl1271_notice("power down");
751
752 if (wl->state != WL1271_STATE_PLT) {
753 wl1271_error("cannot power down because not in PLT "
754 "state: %d", wl->state);
755 ret = -EBUSY;
756 goto out;
757 }
758
759 wl1271_disable_interrupts(wl);
760 wl1271_power_off(wl);
761
762 wl->state = WL1271_STATE_OFF;
763 wl->rx_counter = 0;
764
765 out:
766 mutex_unlock(&wl->mutex);
767
768 return ret;
769 }
770
771
772 static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
773 {
774 struct wl1271 *wl = hw->priv;
775 struct ieee80211_conf *conf = &hw->conf;
776 struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
777 struct ieee80211_sta *sta = txinfo->control.sta;
778 unsigned long flags;
779
780 /* peek into the rates configured in the STA entry */
781 spin_lock_irqsave(&wl->wl_lock, flags);
782 if (sta && sta->supp_rates[conf->channel->band] != wl->sta_rate_set) {
783 wl->sta_rate_set = sta->supp_rates[conf->channel->band];
784 set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
785 }
786 spin_unlock_irqrestore(&wl->wl_lock, flags);
787
788 /* queue the packet */
789 skb_queue_tail(&wl->tx_queue, skb);
790
791 /*
792 * The chip specific setup must run before the first TX packet -
793 * before that, the tx_work will not be initialized!
794 */
795
796 ieee80211_queue_work(wl->hw, &wl->tx_work);
797
798 /*
799 * The workqueue is slow to process the tx_queue and we need stop
800 * the queue here, otherwise the queue will get too long.
801 */
802 if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) {
803 ieee80211_stop_queues(wl->hw);
804
805 /*
806 * FIXME: this is racy, the variable is not properly
807 * protected. Maybe fix this by removing the stupid
808 * variable altogether and checking the real queue state?
809 */
810 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
811 }
812
813 return NETDEV_TX_OK;
814 }
815
816 static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
817 void *arg)
818 {
819 struct net_device *dev;
820 struct wireless_dev *wdev;
821 struct wiphy *wiphy;
822 struct ieee80211_hw *hw;
823 struct wl1271 *wl;
824 struct wl1271 *wl_temp;
825 struct in_device *idev;
826 struct in_ifaddr *ifa = arg;
827 int ret = 0;
828
829 /* FIXME: this ugly function should probably be implemented in the
830 * mac80211, and here should only be a simple callback handling actual
831 * setting of the filters. Now we need to dig up references to
832 * various structures to gain access to what we need.
833 * Also, because of this, there is no "initial" setting of the filter
834 * in "op_start", because we don't want to dig up struct net_device
835 * there - the filter will be set upon first change of the interface
836 * IP address. */
837
838 dev = ifa->ifa_dev->dev;
839
840 wdev = dev->ieee80211_ptr;
841 if (wdev == NULL)
842 return NOTIFY_DONE;
843
844 wiphy = wdev->wiphy;
845 if (wiphy == NULL)
846 return NOTIFY_DONE;
847
848 hw = wiphy_priv(wiphy);
849 if (hw == NULL)
850 return NOTIFY_DONE;
851
852 /* Check that the interface is one supported by this driver. */
853 wl_temp = hw->priv;
854 list_for_each_entry(wl, &wl_list, list) {
855 if (wl == wl_temp)
856 break;
857 }
858 if (wl == NULL)
859 return NOTIFY_DONE;
860
861 /* Get the interface IP address for the device. "ifa" will become
862 NULL if:
863 - there is no IPV4 protocol address configured
864 - there are multiple (virtual) IPV4 addresses configured
865 When "ifa" is NULL, filtering will be disabled.
866 */
867 ifa = NULL;
868 idev = dev->ip_ptr;
869 if (idev)
870 ifa = idev->ifa_list;
871
872 if (ifa && ifa->ifa_next)
873 ifa = NULL;
874
875 mutex_lock(&wl->mutex);
876
877 if (wl->state == WL1271_STATE_OFF)
878 goto out;
879
880 ret = wl1271_ps_elp_wakeup(wl, false);
881 if (ret < 0)
882 goto out;
883 if (ifa)
884 ret = wl1271_acx_arp_ip_filter(wl, true,
885 (u8 *)&ifa->ifa_address,
886 ACX_IPV4_VERSION);
887 else
888 ret = wl1271_acx_arp_ip_filter(wl, false, NULL,
889 ACX_IPV4_VERSION);
890 wl1271_ps_elp_sleep(wl);
891
892 out:
893 mutex_unlock(&wl->mutex);
894
895 return NOTIFY_OK;
896 }
897
898 static struct notifier_block wl1271_dev_notifier = {
899 .notifier_call = wl1271_dev_notify,
900 };
901
902
903 static int wl1271_op_start(struct ieee80211_hw *hw)
904 {
905 struct wl1271 *wl = hw->priv;
906 int retries = WL1271_BOOT_RETRIES;
907 int ret = 0;
908
909 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
910
911 mutex_lock(&wl->mutex);
912
913 if (wl->state != WL1271_STATE_OFF) {
914 wl1271_error("cannot start because not in off state: %d",
915 wl->state);
916 ret = -EBUSY;
917 goto out;
918 }
919
920 while (retries) {
921 retries--;
922 ret = wl1271_chip_wakeup(wl);
923 if (ret < 0)
924 goto power_off;
925
926 ret = wl1271_boot(wl);
927 if (ret < 0)
928 goto power_off;
929
930 ret = wl1271_hw_init(wl);
931 if (ret < 0)
932 goto irq_disable;
933
934 wl->state = WL1271_STATE_ON;
935 wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
936 goto out;
937
938 irq_disable:
939 wl1271_disable_interrupts(wl);
940 mutex_unlock(&wl->mutex);
941 /* Unlocking the mutex in the middle of handling is
942 inherently unsafe. In this case we deem it safe to do,
943 because we need to let any possibly pending IRQ out of
944 the system (and while we are WL1271_STATE_OFF the IRQ
945 work function will not do anything.) Also, any other
946 possible concurrent operations will fail due to the
947 current state, hence the wl1271 struct should be safe. */
948 cancel_work_sync(&wl->irq_work);
949 mutex_lock(&wl->mutex);
950 power_off:
951 wl1271_power_off(wl);
952 }
953
954 wl1271_error("firmware boot failed despite %d retries",
955 WL1271_BOOT_RETRIES);
956 out:
957 mutex_unlock(&wl->mutex);
958
959 if (!ret) {
960 list_add(&wl->list, &wl_list);
961 register_inetaddr_notifier(&wl1271_dev_notifier);
962 }
963
964 return ret;
965 }
966
967 static void wl1271_op_stop(struct ieee80211_hw *hw)
968 {
969 struct wl1271 *wl = hw->priv;
970 int i;
971
972 wl1271_info("down");
973
974 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
975
976 unregister_inetaddr_notifier(&wl1271_dev_notifier);
977 list_del(&wl->list);
978
979 mutex_lock(&wl->mutex);
980
981 WARN_ON(wl->state != WL1271_STATE_ON);
982
983 if (test_and_clear_bit(WL1271_FLAG_SCANNING, &wl->flags)) {
984 mutex_unlock(&wl->mutex);
985 ieee80211_scan_completed(wl->hw, true);
986 mutex_lock(&wl->mutex);
987 }
988
989 wl->state = WL1271_STATE_OFF;
990
991 wl1271_disable_interrupts(wl);
992
993 mutex_unlock(&wl->mutex);
994
995 cancel_work_sync(&wl->irq_work);
996 cancel_work_sync(&wl->tx_work);
997
998 mutex_lock(&wl->mutex);
999
1000 /* let's notify MAC80211 about the remaining pending TX frames */
1001 wl1271_tx_flush(wl);
1002 wl1271_power_off(wl);
1003
1004 memset(wl->bssid, 0, ETH_ALEN);
1005 memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
1006 wl->ssid_len = 0;
1007 wl->bss_type = MAX_BSS_TYPE;
1008 wl->band = IEEE80211_BAND_2GHZ;
1009
1010 wl->rx_counter = 0;
1011 wl->psm_entry_retry = 0;
1012 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1013 wl->tx_blocks_available = 0;
1014 wl->tx_results_count = 0;
1015 wl->tx_packets_count = 0;
1016 wl->tx_security_last_seq = 0;
1017 wl->tx_security_seq_16 = 0;
1018 wl->tx_security_seq_32 = 0;
1019 wl->time_offset = 0;
1020 wl->session_counter = 0;
1021 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1022 wl->sta_rate_set = 0;
1023 wl->flags = 0;
1024
1025 for (i = 0; i < NUM_TX_QUEUES; i++)
1026 wl->tx_blocks_freed[i] = 0;
1027
1028 wl1271_debugfs_reset(wl);
1029 mutex_unlock(&wl->mutex);
1030 }
1031
1032 static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1033 struct ieee80211_vif *vif)
1034 {
1035 struct wl1271 *wl = hw->priv;
1036 int ret = 0;
1037
1038 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1039 vif->type, vif->addr);
1040
1041 mutex_lock(&wl->mutex);
1042 if (wl->vif) {
1043 ret = -EBUSY;
1044 goto out;
1045 }
1046
1047 wl->vif = vif;
1048
1049 switch (vif->type) {
1050 case NL80211_IFTYPE_STATION:
1051 wl->bss_type = BSS_TYPE_STA_BSS;
1052 break;
1053 case NL80211_IFTYPE_ADHOC:
1054 wl->bss_type = BSS_TYPE_IBSS;
1055 break;
1056 default:
1057 ret = -EOPNOTSUPP;
1058 goto out;
1059 }
1060
1061 /* FIXME: what if conf->mac_addr changes? */
1062
1063 out:
1064 mutex_unlock(&wl->mutex);
1065 return ret;
1066 }
1067
1068 static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
1069 struct ieee80211_vif *vif)
1070 {
1071 struct wl1271 *wl = hw->priv;
1072
1073 mutex_lock(&wl->mutex);
1074 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
1075 wl->vif = NULL;
1076 mutex_unlock(&wl->mutex);
1077 }
1078
1079 #if 0
1080 static int wl1271_op_config_interface(struct ieee80211_hw *hw,
1081 struct ieee80211_vif *vif,
1082 struct ieee80211_if_conf *conf)
1083 {
1084 struct wl1271 *wl = hw->priv;
1085 struct sk_buff *beacon;
1086 int ret;
1087
1088 wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %pM",
1089 conf->bssid);
1090 wl1271_dump_ascii(DEBUG_MAC80211, "ssid: ", conf->ssid,
1091 conf->ssid_len);
1092
1093 mutex_lock(&wl->mutex);
1094
1095 ret = wl1271_ps_elp_wakeup(wl, false);
1096 if (ret < 0)
1097 goto out;
1098
1099 if (memcmp(wl->bssid, conf->bssid, ETH_ALEN)) {
1100 wl1271_debug(DEBUG_MAC80211, "bssid changed");
1101
1102 memcpy(wl->bssid, conf->bssid, ETH_ALEN);
1103
1104 ret = wl1271_cmd_join(wl);
1105 if (ret < 0)
1106 goto out_sleep;
1107
1108 ret = wl1271_cmd_build_null_data(wl);
1109 if (ret < 0)
1110 goto out_sleep;
1111 }
1112
1113 wl->ssid_len = conf->ssid_len;
1114 if (wl->ssid_len)
1115 memcpy(wl->ssid, conf->ssid, wl->ssid_len);
1116
1117 if (conf->changed & IEEE80211_IFCC_BEACON) {
1118 beacon = ieee80211_beacon_get(hw, vif);
1119 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
1120 beacon->data, beacon->len);
1121
1122 if (ret < 0) {
1123 dev_kfree_skb(beacon);
1124 goto out_sleep;
1125 }
1126
1127 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE,
1128 beacon->data, beacon->len);
1129
1130 dev_kfree_skb(beacon);
1131
1132 if (ret < 0)
1133 goto out_sleep;
1134 }
1135
1136 out_sleep:
1137 wl1271_ps_elp_sleep(wl);
1138
1139 out:
1140 mutex_unlock(&wl->mutex);
1141
1142 return ret;
1143 }
1144 #endif
1145
1146 static int wl1271_join_channel(struct wl1271 *wl, int channel)
1147 {
1148 int ret = 0;
1149 /* we need to use a dummy BSSID for now */
1150 static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde,
1151 0xad, 0xbe, 0xef };
1152
1153 /* the dummy join is not required for ad-hoc */
1154 if (wl->bss_type == BSS_TYPE_IBSS)
1155 goto out;
1156
1157 /* disable mac filter, so we hear everything */
1158 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1159
1160 wl->channel = channel;
1161 memcpy(wl->bssid, dummy_bssid, ETH_ALEN);
1162
1163 ret = wl1271_cmd_join(wl);
1164 if (ret < 0)
1165 goto out;
1166
1167 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1168
1169 out:
1170 return ret;
1171 }
1172
1173 static int wl1271_unjoin_channel(struct wl1271 *wl)
1174 {
1175 int ret;
1176
1177 /* to stop listening to a channel, we disconnect */
1178 ret = wl1271_cmd_disconnect(wl);
1179 if (ret < 0)
1180 goto out;
1181
1182 clear_bit(WL1271_FLAG_JOINED, &wl->flags);
1183 wl->channel = 0;
1184 memset(wl->bssid, 0, ETH_ALEN);
1185 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
1186
1187 out:
1188 return ret;
1189 }
1190
1191 static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
1192 {
1193 struct wl1271 *wl = hw->priv;
1194 struct ieee80211_conf *conf = &hw->conf;
1195 int channel, ret = 0;
1196
1197 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
1198
1199 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s",
1200 channel,
1201 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
1202 conf->power_level,
1203 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use");
1204
1205 mutex_lock(&wl->mutex);
1206
1207 wl->band = conf->channel->band;
1208
1209 ret = wl1271_ps_elp_wakeup(wl, false);
1210 if (ret < 0)
1211 goto out;
1212
1213 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1214 if (conf->flags & IEEE80211_CONF_IDLE &&
1215 test_bit(WL1271_FLAG_JOINED, &wl->flags))
1216 wl1271_unjoin_channel(wl);
1217 else if (!(conf->flags & IEEE80211_CONF_IDLE))
1218 wl1271_join_channel(wl, channel);
1219
1220 if (conf->flags & IEEE80211_CONF_IDLE) {
1221 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1222 wl->sta_rate_set = 0;
1223 wl1271_acx_rate_policies(wl);
1224 }
1225 }
1226
1227 /* if the channel changes while joined, join again */
1228 if (channel != wl->channel &&
1229 test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
1230 wl->channel = channel;
1231 /* FIXME: maybe use CMD_CHANNEL_SWITCH for this? */
1232 ret = wl1271_cmd_join(wl);
1233 if (ret < 0)
1234 wl1271_warning("cmd join to update channel failed %d",
1235 ret);
1236 } else
1237 wl->channel = channel;
1238
1239 if (conf->flags & IEEE80211_CONF_PS &&
1240 !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
1241 set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
1242
1243 /*
1244 * We enter PSM only if we're already associated.
1245 * If we're not, we'll enter it when joining an SSID,
1246 * through the bss_info_changed() hook.
1247 */
1248 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
1249 wl1271_info("psm enabled");
1250 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
1251 true);
1252 }
1253 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
1254 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
1255 wl1271_info("psm disabled");
1256
1257 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
1258
1259 if (test_bit(WL1271_FLAG_PSM, &wl->flags))
1260 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
1261 true);
1262 }
1263
1264 if (conf->power_level != wl->power_level) {
1265 ret = wl1271_acx_tx_power(wl, conf->power_level);
1266 if (ret < 0)
1267 goto out_sleep;
1268
1269 wl->power_level = conf->power_level;
1270 }
1271
1272 out_sleep:
1273 wl1271_ps_elp_sleep(wl);
1274
1275 out:
1276 mutex_unlock(&wl->mutex);
1277
1278 return ret;
1279 }
1280
1281 struct wl1271_filter_params {
1282 bool enabled;
1283 int mc_list_length;
1284 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
1285 };
1286
1287 static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, int mc_count,
1288 struct dev_addr_list *mc_list)
1289 {
1290 struct wl1271_filter_params *fp;
1291 int i;
1292
1293 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
1294 if (!fp) {
1295 wl1271_error("Out of memory setting filters.");
1296 return 0;
1297 }
1298
1299 /* update multicast filtering parameters */
1300 fp->enabled = true;
1301 if (mc_count > ACX_MC_ADDRESS_GROUP_MAX) {
1302 mc_count = 0;
1303 fp->enabled = false;
1304 }
1305
1306 fp->mc_list_length = 0;
1307 for (i = 0; i < mc_count; i++) {
1308 if (mc_list->da_addrlen == ETH_ALEN) {
1309 memcpy(fp->mc_list[fp->mc_list_length],
1310 mc_list->da_addr, ETH_ALEN);
1311 fp->mc_list_length++;
1312 } else
1313 wl1271_warning("Unknown mc address length.");
1314 mc_list = mc_list->next;
1315 }
1316
1317 return (u64)(unsigned long)fp;
1318 }
1319
1320 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
1321 FIF_ALLMULTI | \
1322 FIF_FCSFAIL | \
1323 FIF_BCN_PRBRESP_PROMISC | \
1324 FIF_CONTROL | \
1325 FIF_OTHER_BSS)
1326
1327 static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
1328 unsigned int changed,
1329 unsigned int *total, u64 multicast)
1330 {
1331 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
1332 struct wl1271 *wl = hw->priv;
1333 int ret;
1334
1335 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
1336
1337 mutex_lock(&wl->mutex);
1338
1339 if (wl->state == WL1271_STATE_OFF)
1340 goto out;
1341
1342 ret = wl1271_ps_elp_wakeup(wl, false);
1343 if (ret < 0)
1344 goto out;
1345
1346 *total &= WL1271_SUPPORTED_FILTERS;
1347 changed &= WL1271_SUPPORTED_FILTERS;
1348
1349 if (*total & FIF_ALLMULTI)
1350 ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
1351 else if (fp)
1352 ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
1353 fp->mc_list,
1354 fp->mc_list_length);
1355 if (ret < 0)
1356 goto out_sleep;
1357
1358 kfree(fp);
1359
1360 /* FIXME: We still need to set our filters properly */
1361
1362 /* determine, whether supported filter values have changed */
1363 if (changed == 0)
1364 goto out_sleep;
1365
1366 /* apply configured filters */
1367 ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
1368 if (ret < 0)
1369 goto out_sleep;
1370
1371 out_sleep:
1372 wl1271_ps_elp_sleep(wl);
1373
1374 out:
1375 mutex_unlock(&wl->mutex);
1376 }
1377
1378 static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1379 struct ieee80211_vif *vif,
1380 struct ieee80211_sta *sta,
1381 struct ieee80211_key_conf *key_conf)
1382 {
1383 struct wl1271 *wl = hw->priv;
1384 const u8 *addr;
1385 int ret;
1386 u32 tx_seq_32 = 0;
1387 u16 tx_seq_16 = 0;
1388 u8 key_type;
1389
1390 static const u8 bcast_addr[ETH_ALEN] =
1391 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1392
1393 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
1394
1395 addr = sta ? sta->addr : bcast_addr;
1396
1397 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
1398 wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
1399 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
1400 key_conf->alg, key_conf->keyidx,
1401 key_conf->keylen, key_conf->flags);
1402 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
1403
1404 if (is_zero_ether_addr(addr)) {
1405 /* We dont support TX only encryption */
1406 ret = -EOPNOTSUPP;
1407 goto out;
1408 }
1409
1410 mutex_lock(&wl->mutex);
1411
1412 ret = wl1271_ps_elp_wakeup(wl, false);
1413 if (ret < 0)
1414 goto out_unlock;
1415
1416 switch (key_conf->alg) {
1417 case ALG_WEP:
1418 key_type = KEY_WEP;
1419
1420 key_conf->hw_key_idx = key_conf->keyidx;
1421 break;
1422 case ALG_TKIP:
1423 key_type = KEY_TKIP;
1424
1425 key_conf->hw_key_idx = key_conf->keyidx;
1426 tx_seq_32 = wl->tx_security_seq_32;
1427 tx_seq_16 = wl->tx_security_seq_16;
1428 break;
1429 case ALG_CCMP:
1430 key_type = KEY_AES;
1431
1432 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1433 tx_seq_32 = wl->tx_security_seq_32;
1434 tx_seq_16 = wl->tx_security_seq_16;
1435 break;
1436 default:
1437 wl1271_error("Unknown key algo 0x%x", key_conf->alg);
1438
1439 ret = -EOPNOTSUPP;
1440 goto out_sleep;
1441 }
1442
1443 switch (cmd) {
1444 case SET_KEY:
1445 ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
1446 key_conf->keyidx, key_type,
1447 key_conf->keylen, key_conf->key,
1448 addr, tx_seq_32, tx_seq_16);
1449 if (ret < 0) {
1450 wl1271_error("Could not add or replace key");
1451 goto out_sleep;
1452 }
1453
1454 /* the default WEP key needs to be configured at least once */
1455 if (key_type == KEY_WEP) {
1456 ret = wl1271_cmd_set_default_wep_key(wl,
1457 wl->default_key);
1458 if (ret < 0)
1459 goto out_sleep;
1460 }
1461 break;
1462
1463 case DISABLE_KEY:
1464 /* The wl1271 does not allow to remove unicast keys - they
1465 will be cleared automatically on next CMD_JOIN. Ignore the
1466 request silently, as we dont want the mac80211 to emit
1467 an error message. */
1468 if (!is_broadcast_ether_addr(addr))
1469 break;
1470
1471 ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
1472 key_conf->keyidx, key_type,
1473 key_conf->keylen, key_conf->key,
1474 addr, 0, 0);
1475 if (ret < 0) {
1476 wl1271_error("Could not remove key");
1477 goto out_sleep;
1478 }
1479 break;
1480
1481 default:
1482 wl1271_error("Unsupported key cmd 0x%x", cmd);
1483 ret = -EOPNOTSUPP;
1484 goto out_sleep;
1485
1486 break;
1487 }
1488
1489 out_sleep:
1490 wl1271_ps_elp_sleep(wl);
1491
1492 out_unlock:
1493 mutex_unlock(&wl->mutex);
1494
1495 out:
1496 return ret;
1497 }
1498
1499 static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
1500 struct cfg80211_scan_request *req)
1501 {
1502 struct wl1271 *wl = hw->priv;
1503 int ret;
1504 u8 *ssid = NULL;
1505 size_t len = 0;
1506
1507 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
1508
1509 if (req->n_ssids) {
1510 ssid = req->ssids[0].ssid;
1511 len = req->ssids[0].ssid_len;
1512 }
1513
1514 mutex_lock(&wl->mutex);
1515
1516 ret = wl1271_ps_elp_wakeup(wl, false);
1517 if (ret < 0)
1518 goto out;
1519
1520 if (wl1271_11a_enabled())
1521 ret = wl1271_cmd_scan(hw->priv, ssid, len, 1, 0,
1522 WL1271_SCAN_BAND_DUAL, 3);
1523 else
1524 ret = wl1271_cmd_scan(hw->priv, ssid, len, 1, 0,
1525 WL1271_SCAN_BAND_2_4_GHZ, 3);
1526
1527 wl1271_ps_elp_sleep(wl);
1528
1529 out:
1530 mutex_unlock(&wl->mutex);
1531
1532 return ret;
1533 }
1534
1535 static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1536 {
1537 struct wl1271 *wl = hw->priv;
1538 int ret;
1539
1540 mutex_lock(&wl->mutex);
1541
1542 ret = wl1271_ps_elp_wakeup(wl, false);
1543 if (ret < 0)
1544 goto out;
1545
1546 ret = wl1271_acx_rts_threshold(wl, (u16) value);
1547 if (ret < 0)
1548 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
1549
1550 wl1271_ps_elp_sleep(wl);
1551
1552 out:
1553 mutex_unlock(&wl->mutex);
1554
1555 return ret;
1556 }
1557
1558 static void wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *beacon)
1559 {
1560 u8 *ptr = beacon->data +
1561 offsetof(struct ieee80211_mgmt, u.beacon.variable);
1562
1563 /* find the location of the ssid in the beacon */
1564 while (ptr < beacon->data + beacon->len) {
1565 if (ptr[0] == WLAN_EID_SSID) {
1566 wl->ssid_len = ptr[1];
1567 memcpy(wl->ssid, ptr+2, wl->ssid_len);
1568 return;
1569 }
1570 ptr += ptr[1];
1571 }
1572 wl1271_error("ad-hoc beacon template has no SSID!\n");
1573 }
1574
1575 static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
1576 struct ieee80211_vif *vif,
1577 struct ieee80211_bss_conf *bss_conf,
1578 u32 changed)
1579 {
1580 enum wl1271_cmd_ps_mode mode;
1581 struct wl1271 *wl = hw->priv;
1582 bool do_join = false;
1583 int ret;
1584
1585 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
1586
1587 mutex_lock(&wl->mutex);
1588
1589 ret = wl1271_ps_elp_wakeup(wl, false);
1590 if (ret < 0)
1591 goto out;
1592
1593 if (wl->bss_type == BSS_TYPE_IBSS) {
1594 /* FIXME: This implements rudimentary ad-hoc support -
1595 proper templates are on the wish list and notification
1596 on when they change. This patch will update the templates
1597 on every call to this function. */
1598 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1599
1600 if (beacon) {
1601 struct ieee80211_hdr *hdr;
1602
1603 wl1271_ssid_set(wl, beacon);
1604 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
1605 beacon->data,
1606 beacon->len);
1607
1608 if (ret < 0) {
1609 dev_kfree_skb(beacon);
1610 goto out_sleep;
1611 }
1612
1613 hdr = (struct ieee80211_hdr *) beacon->data;
1614 hdr->frame_control = cpu_to_le16(
1615 IEEE80211_FTYPE_MGMT |
1616 IEEE80211_STYPE_PROBE_RESP);
1617
1618 ret = wl1271_cmd_template_set(wl,
1619 CMD_TEMPL_PROBE_RESPONSE,
1620 beacon->data,
1621 beacon->len);
1622 dev_kfree_skb(beacon);
1623 if (ret < 0)
1624 goto out_sleep;
1625
1626 /* Need to update the SSID (for filtering etc) */
1627 do_join = true;
1628 }
1629 }
1630
1631 if ((changed & BSS_CHANGED_BSSID) &&
1632 /*
1633 * Now we know the correct bssid, so we send a new join command
1634 * and enable the BSSID filter
1635 */
1636 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
1637 wl->rx_config |= CFG_BSSID_FILTER_EN;
1638 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1639 ret = wl1271_cmd_build_null_data(wl);
1640 if (ret < 0) {
1641 wl1271_warning("cmd buld null data failed %d",
1642 ret);
1643 goto out_sleep;
1644 }
1645
1646 /* Need to update the BSSID (for filtering etc) */
1647 do_join = true;
1648 }
1649
1650 if (changed & BSS_CHANGED_ASSOC) {
1651 if (bss_conf->assoc) {
1652 wl->aid = bss_conf->aid;
1653 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1654
1655 /*
1656 * with wl1271, we don't need to update the
1657 * beacon_int and dtim_period, because the firmware
1658 * updates it by itself when the first beacon is
1659 * received after a join.
1660 */
1661 ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
1662 if (ret < 0)
1663 goto out_sleep;
1664
1665 ret = wl1271_acx_aid(wl, wl->aid);
1666 if (ret < 0)
1667 goto out_sleep;
1668
1669 /* If we want to go in PSM but we're not there yet */
1670 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) &&
1671 !test_bit(WL1271_FLAG_PSM, &wl->flags)) {
1672 mode = STATION_POWER_SAVE_MODE;
1673 ret = wl1271_ps_set_mode(wl, mode, true);
1674 if (ret < 0)
1675 goto out_sleep;
1676 }
1677 } else {
1678 /* use defaults when not associated */
1679 clear_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1680 wl->aid = 0;
1681 }
1682
1683 }
1684
1685 if (changed & BSS_CHANGED_ERP_SLOT) {
1686 if (bss_conf->use_short_slot)
1687 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
1688 else
1689 ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
1690 if (ret < 0) {
1691 wl1271_warning("Set slot time failed %d", ret);
1692 goto out_sleep;
1693 }
1694 }
1695
1696 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1697 if (bss_conf->use_short_preamble)
1698 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
1699 else
1700 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
1701 }
1702
1703 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1704 if (bss_conf->use_cts_prot)
1705 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
1706 else
1707 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1708 if (ret < 0) {
1709 wl1271_warning("Set ctsprotect failed %d", ret);
1710 goto out_sleep;
1711 }
1712 }
1713
1714 if (do_join) {
1715 ret = wl1271_cmd_join(wl);
1716 if (ret < 0) {
1717 wl1271_warning("cmd join failed %d", ret);
1718 goto out_sleep;
1719 }
1720 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1721 }
1722
1723 out_sleep:
1724 wl1271_ps_elp_sleep(wl);
1725
1726 out:
1727 mutex_unlock(&wl->mutex);
1728 }
1729
1730 static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
1731 const struct ieee80211_tx_queue_params *params)
1732 {
1733 struct wl1271 *wl = hw->priv;
1734 int ret;
1735
1736 mutex_lock(&wl->mutex);
1737
1738 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
1739
1740 ret = wl1271_ps_elp_wakeup(wl, false);
1741 if (ret < 0)
1742 goto out;
1743
1744 ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue),
1745 params->cw_min, params->cw_max,
1746 params->aifs, params->txop);
1747 if (ret < 0)
1748 goto out_sleep;
1749
1750 ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue),
1751 CONF_CHANNEL_TYPE_EDCF,
1752 wl1271_tx_get_queue(queue),
1753 CONF_PS_SCHEME_LEGACY_PSPOLL,
1754 CONF_ACK_POLICY_LEGACY, 0, 0);
1755 if (ret < 0)
1756 goto out_sleep;
1757
1758 out_sleep:
1759 wl1271_ps_elp_sleep(wl);
1760
1761 out:
1762 mutex_unlock(&wl->mutex);
1763
1764 return ret;
1765 }
1766
1767
1768 /* can't be const, mac80211 writes to this */
1769 static struct ieee80211_rate wl1271_rates[] = {
1770 { .bitrate = 10,
1771 .hw_value = CONF_HW_BIT_RATE_1MBPS,
1772 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
1773 { .bitrate = 20,
1774 .hw_value = CONF_HW_BIT_RATE_2MBPS,
1775 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
1776 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1777 { .bitrate = 55,
1778 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
1779 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
1780 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1781 { .bitrate = 110,
1782 .hw_value = CONF_HW_BIT_RATE_11MBPS,
1783 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
1784 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1785 { .bitrate = 60,
1786 .hw_value = CONF_HW_BIT_RATE_6MBPS,
1787 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
1788 { .bitrate = 90,
1789 .hw_value = CONF_HW_BIT_RATE_9MBPS,
1790 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
1791 { .bitrate = 120,
1792 .hw_value = CONF_HW_BIT_RATE_12MBPS,
1793 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
1794 { .bitrate = 180,
1795 .hw_value = CONF_HW_BIT_RATE_18MBPS,
1796 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
1797 { .bitrate = 240,
1798 .hw_value = CONF_HW_BIT_RATE_24MBPS,
1799 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
1800 { .bitrate = 360,
1801 .hw_value = CONF_HW_BIT_RATE_36MBPS,
1802 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
1803 { .bitrate = 480,
1804 .hw_value = CONF_HW_BIT_RATE_48MBPS,
1805 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
1806 { .bitrate = 540,
1807 .hw_value = CONF_HW_BIT_RATE_54MBPS,
1808 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
1809 };
1810
1811 /* can't be const, mac80211 writes to this */
1812 static struct ieee80211_channel wl1271_channels[] = {
1813 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
1814 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
1815 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
1816 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
1817 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
1818 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
1819 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
1820 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
1821 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
1822 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
1823 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
1824 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
1825 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
1826 };
1827
1828 /* can't be const, mac80211 writes to this */
1829 static struct ieee80211_supported_band wl1271_band_2ghz = {
1830 .channels = wl1271_channels,
1831 .n_channels = ARRAY_SIZE(wl1271_channels),
1832 .bitrates = wl1271_rates,
1833 .n_bitrates = ARRAY_SIZE(wl1271_rates),
1834 };
1835
1836 /* 5 GHz data rates for WL1273 */
1837 static struct ieee80211_rate wl1271_rates_5ghz[] = {
1838 { .bitrate = 60,
1839 .hw_value = CONF_HW_BIT_RATE_6MBPS,
1840 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
1841 { .bitrate = 90,
1842 .hw_value = CONF_HW_BIT_RATE_9MBPS,
1843 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
1844 { .bitrate = 120,
1845 .hw_value = CONF_HW_BIT_RATE_12MBPS,
1846 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
1847 { .bitrate = 180,
1848 .hw_value = CONF_HW_BIT_RATE_18MBPS,
1849 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
1850 { .bitrate = 240,
1851 .hw_value = CONF_HW_BIT_RATE_24MBPS,
1852 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
1853 { .bitrate = 360,
1854 .hw_value = CONF_HW_BIT_RATE_36MBPS,
1855 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
1856 { .bitrate = 480,
1857 .hw_value = CONF_HW_BIT_RATE_48MBPS,
1858 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
1859 { .bitrate = 540,
1860 .hw_value = CONF_HW_BIT_RATE_54MBPS,
1861 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
1862 };
1863
1864 /* 5 GHz band channels for WL1273 */
1865 static struct ieee80211_channel wl1271_channels_5ghz[] = {
1866 { .hw_value = 183, .center_freq = 4915},
1867 { .hw_value = 184, .center_freq = 4920},
1868 { .hw_value = 185, .center_freq = 4925},
1869 { .hw_value = 187, .center_freq = 4935},
1870 { .hw_value = 188, .center_freq = 4940},
1871 { .hw_value = 189, .center_freq = 4945},
1872 { .hw_value = 192, .center_freq = 4960},
1873 { .hw_value = 196, .center_freq = 4980},
1874 { .hw_value = 7, .center_freq = 5035},
1875 { .hw_value = 8, .center_freq = 5040},
1876 { .hw_value = 9, .center_freq = 5045},
1877 { .hw_value = 11, .center_freq = 5055},
1878 { .hw_value = 12, .center_freq = 5060},
1879 { .hw_value = 16, .center_freq = 5080},
1880 { .hw_value = 34, .center_freq = 5170},
1881 { .hw_value = 36, .center_freq = 5180},
1882 { .hw_value = 38, .center_freq = 5190},
1883 { .hw_value = 40, .center_freq = 5200},
1884 { .hw_value = 42, .center_freq = 5210},
1885 { .hw_value = 44, .center_freq = 5220},
1886 { .hw_value = 46, .center_freq = 5230},
1887 { .hw_value = 48, .center_freq = 5240},
1888 { .hw_value = 52, .center_freq = 5260},
1889 { .hw_value = 56, .center_freq = 5280},
1890 { .hw_value = 60, .center_freq = 5300},
1891 { .hw_value = 64, .center_freq = 5320},
1892 { .hw_value = 100, .center_freq = 5500},
1893 { .hw_value = 104, .center_freq = 5520},
1894 { .hw_value = 108, .center_freq = 5540},
1895 { .hw_value = 112, .center_freq = 5560},
1896 { .hw_value = 116, .center_freq = 5580},
1897 { .hw_value = 120, .center_freq = 5600},
1898 { .hw_value = 124, .center_freq = 5620},
1899 { .hw_value = 128, .center_freq = 5640},
1900 { .hw_value = 132, .center_freq = 5660},
1901 { .hw_value = 136, .center_freq = 5680},
1902 { .hw_value = 140, .center_freq = 5700},
1903 { .hw_value = 149, .center_freq = 5745},
1904 { .hw_value = 153, .center_freq = 5765},
1905 { .hw_value = 157, .center_freq = 5785},
1906 { .hw_value = 161, .center_freq = 5805},
1907 { .hw_value = 165, .center_freq = 5825},
1908 };
1909
1910
1911 static struct ieee80211_supported_band wl1271_band_5ghz = {
1912 .channels = wl1271_channels_5ghz,
1913 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
1914 .bitrates = wl1271_rates_5ghz,
1915 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
1916 };
1917
1918 static const struct ieee80211_ops wl1271_ops = {
1919 .start = wl1271_op_start,
1920 .stop = wl1271_op_stop,
1921 .add_interface = wl1271_op_add_interface,
1922 .remove_interface = wl1271_op_remove_interface,
1923 .config = wl1271_op_config,
1924 /* .config_interface = wl1271_op_config_interface, */
1925 .prepare_multicast = wl1271_op_prepare_multicast,
1926 .configure_filter = wl1271_op_configure_filter,
1927 .tx = wl1271_op_tx,
1928 .set_key = wl1271_op_set_key,
1929 .hw_scan = wl1271_op_hw_scan,
1930 .bss_info_changed = wl1271_op_bss_info_changed,
1931 .set_rts_threshold = wl1271_op_set_rts_threshold,
1932 .conf_tx = wl1271_op_conf_tx,
1933 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
1934 };
1935
1936 int wl1271_register_hw(struct wl1271 *wl)
1937 {
1938 int ret;
1939
1940 if (wl->mac80211_registered)
1941 return 0;
1942
1943 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1944
1945 ret = ieee80211_register_hw(wl->hw);
1946 if (ret < 0) {
1947 wl1271_error("unable to register mac80211 hw: %d", ret);
1948 return ret;
1949 }
1950
1951 wl->mac80211_registered = true;
1952
1953 wl1271_notice("loaded");
1954
1955 return 0;
1956 }
1957
1958 int wl1271_init_ieee80211(struct wl1271 *wl)
1959 {
1960 /* The tx descriptor buffer and the TKIP space. */
1961 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
1962 sizeof(struct wl1271_tx_hw_descr);
1963
1964 /* unit us */
1965 /* FIXME: find a proper value */
1966 wl->hw->channel_change_time = 10000;
1967
1968 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1969 IEEE80211_HW_NOISE_DBM |
1970 IEEE80211_HW_BEACON_FILTER |
1971 IEEE80211_HW_SUPPORTS_PS;
1972
1973 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1974 BIT(NL80211_IFTYPE_ADHOC);
1975 wl->hw->wiphy->max_scan_ssids = 1;
1976 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
1977
1978 if (wl1271_11a_enabled())
1979 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
1980
1981 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1982
1983 return 0;
1984 }
1985
1986 #define WL1271_DEFAULT_CHANNEL 0
1987
1988 struct ieee80211_hw *wl1271_alloc_hw(void)
1989 {
1990 struct ieee80211_hw *hw;
1991 struct wl1271 *wl;
1992 int i;
1993
1994 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
1995 if (!hw) {
1996 wl1271_error("could not alloc ieee80211_hw");
1997 return ERR_PTR(-ENOMEM);
1998 }
1999
2000 wl = hw->priv;
2001 memset(wl, 0, sizeof(*wl));
2002
2003 INIT_LIST_HEAD(&wl->list);
2004
2005 wl->hw = hw;
2006
2007 skb_queue_head_init(&wl->tx_queue);
2008
2009 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
2010 wl->channel = WL1271_DEFAULT_CHANNEL;
2011 wl->default_key = 0;
2012 wl->rx_counter = 0;
2013 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
2014 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
2015 wl->psm_entry_retry = 0;
2016 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
2017 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
2018 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
2019 wl->sta_rate_set = 0;
2020 wl->band = IEEE80211_BAND_2GHZ;
2021 wl->vif = NULL;
2022 wl->flags = 0;
2023
2024 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
2025 wl->tx_frames[i] = NULL;
2026
2027 spin_lock_init(&wl->wl_lock);
2028
2029 wl->state = WL1271_STATE_OFF;
2030 mutex_init(&wl->mutex);
2031
2032 /* Apply default driver configuration. */
2033 wl1271_conf_init(wl);
2034
2035 wl1271_debugfs_init(wl);
2036
2037 return hw;
2038 }
2039
2040 int wl1271_free_hw(struct wl1271 *wl)
2041 {
2042 ieee80211_unregister_hw(wl->hw);
2043
2044 wl1271_debugfs_exit(wl);
2045
2046 kfree(wl->target_mem_map);
2047 vfree(wl->fw);
2048 wl->fw = NULL;
2049 kfree(wl->nvs);
2050 wl->nvs = NULL;
2051
2052 kfree(wl->fw_status);
2053 kfree(wl->tx_res_if);
2054
2055 ieee80211_free_hw(wl->hw);
2056
2057 return 0;
2058 }
This page took 0.075543 seconds and 6 git commands to generate.