wl1271: Moved module basics to wl1271_spi.c
[deliverable/linux.git] / drivers / net / wireless / wl12xx / wl1271_main.c
CommitLineData
f5fc0f86
LC
1/*
2 * This file is part of wl1271
3 *
8bf29b0e 4 * Copyright (C) 2008-2010 Nokia Corporation
f5fc0f86
LC
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>
f5fc0f86
LC
25#include <linux/firmware.h>
26#include <linux/delay.h>
f5fc0f86
LC
27#include <linux/spi/spi.h>
28#include <linux/crc32.h>
29#include <linux/etherdevice.h>
1fba4974 30#include <linux/vmalloc.h>
01c09162 31#include <linux/inetdevice.h>
f5fc0f86
LC
32
33#include "wl1271.h"
34#include "wl12xx_80211.h"
35#include "wl1271_reg.h"
36#include "wl1271_spi.h"
7b048c52 37#include "wl1271_io.h"
f5fc0f86
LC
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"
c8c90873 46#include "wl1271_testmode.h"
f5fc0f86 47
9ccd9217
JO
48#define WL1271_BOOT_RETRIES 3
49
8a08048a
JO
50static 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,
3ed8f2c6
LC
70 .rx_cca_threshold = 0,
71 .irq_blk_threshold = 0xFFFF,
72 .irq_pkt_threshold = 0,
73 .irq_timeout = 600,
8a08048a
JO
74 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
75 },
76 .tx = {
77 .tx_energy_detection = 0,
78 .rc_conf = {
ec078d94
JO
79 .enabled_rates = CONF_HW_BIT_RATE_1MBPS |
80 CONF_HW_BIT_RATE_2MBPS,
8a08048a
JO
81 .short_retry_limit = 10,
82 .long_retry_limit = 10,
83 .aflags = 0
45b531a8 84 },
8a08048a
JO
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,
45b531a8 93 },
8a08048a
JO
94 [1] = {
95 .ac = CONF_TX_AC_BK,
96 .cw_min = 15,
97 .cw_max = 63,
98 .aifsn = 7,
99 .tx_op_limit = 0,
45b531a8 100 },
8a08048a
JO
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,
45b531a8 114 },
51f2be24 115 },
8a08048a
JO
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},
51f2be24 133 },
8a08048a
JO
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},
51f2be24 141 },
8a08048a
JO
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,
3ed8f2c6
LC
176 .tx_compl_timeout = 700,
177 .tx_compl_threshold = 4
8a08048a
JO
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,
51f2be24 188 }
47fab7d5 189 },
3ed8f2c6 190 .synch_fail_thold = 10,
8a08048a
JO
191 .bss_lose_timeout = 100,
192 .beacon_rx_timeout = 10000,
193 .broadcast_timeout = 20000,
194 .rx_broadcast_in_ps = 1,
3ed8f2c6 195 .ps_poll_threshold = 20,
8a08048a
JO
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
47fab7d5 207 },
8a08048a
JO
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
11f70f97
JO
224 },
225 .bet_enable = CONF_BET_MODE_ENABLE,
84502563 226 .bet_max_consecutive = 10,
19ad0715 227 .psm_entry_retries = 3
8a08048a
JO
228 },
229 .init = {
8a08048a 230 .radioparam = {
152ee6e0 231 .fem = 1,
2b60100b 232 }
6e92b416
LC
233 },
234 .itrim = {
235 .enable = false,
236 .timeout = 50000,
38ad2d87
JO
237 },
238 .pm_config = {
239 .host_clk_settling_time = 5000,
240 .host_fast_wakeup_support = false
8a08048a
JO
241 }
242};
243
01c09162
JO
244static LIST_HEAD(wl_list);
245
8a08048a
JO
246static void wl1271_conf_init(struct wl1271 *wl)
247{
2b60100b
JO
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 */
8a08048a 260 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
2b60100b
JO
261}
262
263
f5fc0f86
LC
264static int wl1271_plt_init(struct wl1271 *wl)
265{
12419cce
LC
266 struct conf_tx_ac_category *conf_ac;
267 struct conf_tx_tid *conf_tid;
268 int ret, i;
f5fc0f86 269
98b5dd5d 270 ret = wl1271_cmd_general_parms(wl);
4a90406b 271 if (ret < 0)
cc7defa3
LC
272 return ret;
273
98b5dd5d 274 ret = wl1271_cmd_radio_parms(wl);
4a90406b 275 if (ret < 0)
cc7defa3
LC
276 return ret;
277
12419cce
LC
278 ret = wl1271_init_templates_config(wl);
279 if (ret < 0)
280 return ret;
281
f5fc0f86
LC
282 ret = wl1271_acx_init_mem_config(wl);
283 if (ret < 0)
284 return ret;
285
12419cce
LC
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 */
94210897 340 ret = wl1271_cmd_data_path(wl, 1);
f5fc0f86 341 if (ret < 0)
12419cce
LC
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;
f5fc0f86
LC
353
354 return 0;
12419cce
LC
355
356 out_free_memmap:
357 kfree(wl->target_mem_map);
358 wl->target_mem_map = NULL;
359
360 return ret;
f5fc0f86
LC
361}
362
363static void wl1271_disable_interrupts(struct wl1271 *wl)
364{
365 disable_irq(wl->irq);
366}
367
368static void wl1271_power_off(struct wl1271 *wl)
369{
370 wl->set_power(false);
71449f8d 371 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
f5fc0f86
LC
372}
373
374static void wl1271_power_on(struct wl1271 *wl)
375{
376 wl->set_power(true);
71449f8d 377 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
f5fc0f86
LC
378}
379
c15f63bf
JO
380static void wl1271_fw_status(struct wl1271 *wl,
381 struct wl1271_fw_status *status)
f5fc0f86
LC
382{
383 u32 total = 0;
384 int i;
385
7b048c52 386 wl1271_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
f5fc0f86
LC
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++) {
d0f63b20
LC
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]);
f5fc0f86
LC
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))
a64b07e8 408 ieee80211_queue_work(wl->hw, &wl->tx_work);
f5fc0f86
LC
409
410 /* update the host-chipset time offset */
d0f63b20
LC
411 wl->time_offset = jiffies_to_usecs(jiffies) -
412 le32_to_cpu(status->fw_localtime);
f5fc0f86
LC
413}
414
f5fc0f86
LC
415static void wl1271_irq_work(struct work_struct *work)
416{
f5fc0f86 417 int ret;
c15f63bf 418 u32 intr;
f5fc0f86
LC
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
7b048c52 433 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
f5fc0f86 434
c15f63bf 435 wl1271_fw_status(wl, wl->fw_status);
d0f63b20 436 intr = le32_to_cpu(wl->fw_status->intr);
f5fc0f86
LC
437 if (!intr) {
438 wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
439 goto out_sleep;
440 }
441
442 intr &= WL1271_INTR_MASK;
443
1fd2794f 444 if (intr & WL1271_ACX_INTR_EVENT_A) {
1fd2794f 445 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
13f2dc52 446 wl1271_event_handle(wl, 0);
1fd2794f
JO
447 }
448
449 if (intr & WL1271_ACX_INTR_EVENT_B) {
450 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
13f2dc52 451 wl1271_event_handle(wl, 1);
c15f63bf 452 }
f5fc0f86 453
c15f63bf
JO
454 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
455 wl1271_debug(DEBUG_IRQ,
456 "WL1271_ACX_INTR_INIT_COMPLETE");
f5fc0f86 457
c15f63bf
JO
458 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
459 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
f5fc0f86 460
c15f63bf
JO
461 if (intr & WL1271_ACX_INTR_DATA) {
462 u8 tx_res_cnt = wl->fw_status->tx_results_counter -
463 wl->tx_results_count;
f5fc0f86 464
c15f63bf 465 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
f5fc0f86 466
c15f63bf
JO
467 /* check for tx results */
468 if (tx_res_cnt)
469 wl1271_tx_complete(wl, tx_res_cnt);
f5fc0f86 470
c15f63bf
JO
471 wl1271_rx(wl, wl->fw_status);
472 }
f5fc0f86
LC
473
474out_sleep:
7b048c52
TP
475 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
476 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
f5fc0f86
LC
477 wl1271_ps_elp_sleep(wl);
478
479out:
480 mutex_unlock(&wl->mutex);
481}
482
f5fc0f86
LC
483static 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;
1fba4974 503 wl->fw = vmalloc(wl->fw_len);
f5fc0f86
LC
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
515out:
516 release_firmware(fw);
517
518 return ret;
519}
520
7b21b6f8
JO
521static 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);
e2e77b5f
JO
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];
7b21b6f8
JO
548 }
549
550 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
551
552 return ret;
553}
554
f5fc0f86
LC
555static 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
152ee6e0
JO
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));
f5fc0f86
LC
570 ret = -EILSEQ;
571 goto out;
572 }
573
152ee6e0 574 wl->nvs = kmalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL);
f5fc0f86
LC
575
576 if (!wl->nvs) {
577 wl1271_error("could not allocate memory for the nvs file");
578 ret = -ENOMEM;
579 goto out;
580 }
581
152ee6e0 582 memcpy(wl->nvs, fw->data, sizeof(struct wl1271_nvs_file));
f5fc0f86 583
7b21b6f8 584 ret = wl1271_update_mac_addr(wl);
f5fc0f86
LC
585
586out:
587 release_firmware(fw);
588
589 return ret;
590}
591
592static void wl1271_fw_wakeup(struct wl1271 *wl)
593{
594 u32 elp_reg;
595
596 elp_reg = ELPCTRL_WAKE_UP;
74621417 597 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
f5fc0f86
LC
598}
599
600static 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
617static int wl1271_chip_wakeup(struct wl1271 *wl)
618{
451de97a 619 struct wl1271_partition_set partition;
f5fc0f86
LC
620 int ret = 0;
621
01ac17ec 622 msleep(WL1271_PRE_POWER_ON_SLEEP);
f5fc0f86
LC
623 wl1271_power_on(wl);
624 msleep(WL1271_POWER_ON_SLEEP);
9b280722
TP
625 wl1271_io_reset(wl);
626 wl1271_io_init(wl);
f5fc0f86
LC
627
628 /* We don't need a real memory partition here, because we only want
629 * to use the registers at this point. */
451de97a
JO
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);
f5fc0f86
LC
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 */
7b048c52 641 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
f5fc0f86
LC
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)
9ccd9217 652 goto out;
f5fc0f86
LC
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)
9ccd9217 660 goto out;
f5fc0f86
LC
661 break;
662 default:
9ccd9217 663 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
f5fc0f86 664 ret = -ENODEV;
9ccd9217 665 goto out;
f5fc0f86
LC
666 }
667
668 if (wl->fw == NULL) {
669 ret = wl1271_fetch_firmware(wl);
670 if (ret < 0)
9ccd9217 671 goto out;
f5fc0f86
LC
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)
9ccd9217 678 goto out;
f5fc0f86
LC
679 }
680
681out:
682 return ret;
683}
684
f5fc0f86
LC
685int wl1271_plt_start(struct wl1271 *wl)
686{
9ccd9217 687 int retries = WL1271_BOOT_RETRIES;
f5fc0f86
LC
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
9ccd9217
JO
701 while (retries) {
702 retries--;
703 ret = wl1271_chip_wakeup(wl);
704 if (ret < 0)
705 goto power_off;
f5fc0f86 706
9ccd9217
JO
707 ret = wl1271_boot(wl);
708 if (ret < 0)
709 goto power_off;
eb5b28d0 710
9ccd9217
JO
711 ret = wl1271_plt_init(wl);
712 if (ret < 0)
713 goto irq_disable;
bd5ea18f 714
9ccd9217
JO
715 wl->state = WL1271_STATE_PLT;
716 wl1271_notice("firmware booted in PLT mode (%s)",
717 wl->chip.fw_ver);
718 goto out;
eb5b28d0 719
9ccd9217
JO
720irq_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);
732power_off:
733 wl1271_power_off(wl);
734 }
f5fc0f86 735
9ccd9217
JO
736 wl1271_error("firmware boot in PLT mode failed despite %d retries",
737 WL1271_BOOT_RETRIES);
f5fc0f86
LC
738out:
739 mutex_unlock(&wl->mutex);
740
741 return ret;
742}
743
744int 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;
bd5ea18f 763 wl->rx_counter = 0;
f5fc0f86
LC
764
765out:
766 mutex_unlock(&wl->mutex);
767
768 return ret;
769}
770
771
772static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
773{
774 struct wl1271 *wl = hw->priv;
830fb67b
JO
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;
f5fc0f86 779
830fb67b
JO
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 */
f5fc0f86
LC
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
a64b07e8 796 ieee80211_queue_work(wl->hw, &wl->tx_work);
f5fc0f86
LC
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 */
71449f8d 810 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
f5fc0f86
LC
811 }
812
813 return NETDEV_TX_OK;
814}
815
01c09162
JO
816static 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)
17d7265c 842 return NOTIFY_DONE;
01c09162
JO
843
844 wiphy = wdev->wiphy;
845 if (wiphy == NULL)
17d7265c 846 return NOTIFY_DONE;
01c09162
JO
847
848 hw = wiphy_priv(wiphy);
849 if (hw == NULL)
17d7265c 850 return NOTIFY_DONE;
01c09162
JO
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)
17d7265c 859 return NOTIFY_DONE;
01c09162
JO
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
892out:
893 mutex_unlock(&wl->mutex);
894
17d7265c 895 return NOTIFY_OK;
01c09162
JO
896}
897
898static struct notifier_block wl1271_dev_notifier = {
899 .notifier_call = wl1271_dev_notify,
900};
901
902
f5fc0f86
LC
903static int wl1271_op_start(struct ieee80211_hw *hw)
904{
905 struct wl1271 *wl = hw->priv;
9ccd9217 906 int retries = WL1271_BOOT_RETRIES;
f5fc0f86
LC
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
9ccd9217
JO
920 while (retries) {
921 retries--;
922 ret = wl1271_chip_wakeup(wl);
923 if (ret < 0)
924 goto power_off;
f5fc0f86 925
9ccd9217
JO
926 ret = wl1271_boot(wl);
927 if (ret < 0)
928 goto power_off;
f5fc0f86 929
9ccd9217
JO
930 ret = wl1271_hw_init(wl);
931 if (ret < 0)
932 goto irq_disable;
f5fc0f86 933
9ccd9217
JO
934 wl->state = WL1271_STATE_ON;
935 wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
936 goto out;
eb5b28d0 937
9ccd9217
JO
938irq_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);
950power_off:
951 wl1271_power_off(wl);
952 }
eb5b28d0 953
9ccd9217
JO
954 wl1271_error("firmware boot failed despite %d retries",
955 WL1271_BOOT_RETRIES);
eb5b28d0 956out:
f5fc0f86
LC
957 mutex_unlock(&wl->mutex);
958
01c09162
JO
959 if (!ret) {
960 list_add(&wl->list, &wl_list);
961 register_inetaddr_notifier(&wl1271_dev_notifier);
962 }
963
f5fc0f86
LC
964 return ret;
965}
966
967static 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
01c09162
JO
976 unregister_inetaddr_notifier(&wl1271_dev_notifier);
977 list_del(&wl->list);
978
f5fc0f86
LC
979 mutex_lock(&wl->mutex);
980
981 WARN_ON(wl->state != WL1271_STATE_ON);
982
71449f8d 983 if (test_and_clear_bit(WL1271_FLAG_SCANNING, &wl->flags)) {
f5fc0f86
LC
984 mutex_unlock(&wl->mutex);
985 ieee80211_scan_completed(wl->hw, true);
986 mutex_lock(&wl->mutex);
f5fc0f86
LC
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);
f5fc0f86
LC
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;
f5fc0f86 1007 wl->bss_type = MAX_BSS_TYPE;
8a5a37a6 1008 wl->band = IEEE80211_BAND_2GHZ;
f5fc0f86
LC
1009
1010 wl->rx_counter = 0;
19ad0715 1011 wl->psm_entry_retry = 0;
f5fc0f86
LC
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;
ac4e4ce5
JO
1016 wl->tx_security_last_seq = 0;
1017 wl->tx_security_seq_16 = 0;
1018 wl->tx_security_seq_32 = 0;
f5fc0f86
LC
1019 wl->time_offset = 0;
1020 wl->session_counter = 0;
830fb67b
JO
1021 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1022 wl->sta_rate_set = 0;
1023 wl->flags = 0;
d6e19d13 1024
f5fc0f86
LC
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
1032static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1ed32e4f 1033 struct ieee80211_vif *vif)
f5fc0f86
LC
1034{
1035 struct wl1271 *wl = hw->priv;
f5fc0f86
LC
1036 int ret = 0;
1037
e5539bcb 1038 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1ed32e4f 1039 vif->type, vif->addr);
f5fc0f86
LC
1040
1041 mutex_lock(&wl->mutex);
b771eee5
JO
1042 if (wl->vif) {
1043 ret = -EBUSY;
1044 goto out;
1045 }
1046
1ed32e4f 1047 wl->vif = vif;
f5fc0f86 1048
1ed32e4f 1049 switch (vif->type) {
f5fc0f86
LC
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
1063out:
1064 mutex_unlock(&wl->mutex);
1065 return ret;
1066}
1067
1068static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
1ed32e4f 1069 struct ieee80211_vif *vif)
f5fc0f86 1070{
b771eee5
JO
1071 struct wl1271 *wl = hw->priv;
1072
1073 mutex_lock(&wl->mutex);
f5fc0f86 1074 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
b771eee5
JO
1075 wl->vif = NULL;
1076 mutex_unlock(&wl->mutex);
f5fc0f86
LC
1077}
1078
1079#if 0
1080static 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;
f5fc0f86
LC
1086 int ret;
1087
3264690b
DM
1088 wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %pM",
1089 conf->bssid);
f5fc0f86
LC
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
ae751bab
LC
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;
f5fc0f86 1107
c6317a54
JO
1108 ret = wl1271_cmd_build_null_data(wl);
1109 if (ret < 0)
1110 goto out_sleep;
1111 }
f5fc0f86
LC
1112
1113 wl->ssid_len = conf->ssid_len;
1114 if (wl->ssid_len)
1115 memcpy(wl->ssid, conf->ssid, wl->ssid_len);
1116
f5fc0f86
LC
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
f5fc0f86
LC
1132 if (ret < 0)
1133 goto out_sleep;
1134 }
1135
1136out_sleep:
1137 wl1271_ps_elp_sleep(wl);
1138
1139out:
1140 mutex_unlock(&wl->mutex);
1141
1142 return ret;
1143}
1144#endif
1145
c7f43e45
LC
1146static int wl1271_join_channel(struct wl1271 *wl, int channel)
1147{
e0d8bbf0 1148 int ret = 0;
c7f43e45
LC
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
e0d8bbf0
JO
1153 /* the dummy join is not required for ad-hoc */
1154 if (wl->bss_type == BSS_TYPE_IBSS)
1155 goto out;
1156
c7f43e45
LC
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
71449f8d 1167 set_bit(WL1271_FLAG_JOINED, &wl->flags);
c7f43e45
LC
1168
1169out:
1170 return ret;
1171}
1172
1173static 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
71449f8d 1182 clear_bit(WL1271_FLAG_JOINED, &wl->flags);
c7f43e45
LC
1183 wl->channel = 0;
1184 memset(wl->bssid, 0, ETH_ALEN);
1185 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
1186
1187out:
1188 return ret;
1189}
1190
f5fc0f86
LC
1191static 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
c7f43e45 1199 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s",
f5fc0f86
LC
1200 channel,
1201 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
c7f43e45
LC
1202 conf->power_level,
1203 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use");
f5fc0f86
LC
1204
1205 mutex_lock(&wl->mutex);
1206
8a5a37a6
JO
1207 wl->band = conf->channel->band;
1208
f5fc0f86
LC
1209 ret = wl1271_ps_elp_wakeup(wl, false);
1210 if (ret < 0)
1211 goto out;
1212
c7f43e45 1213 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
71449f8d
JO
1214 if (conf->flags & IEEE80211_CONF_IDLE &&
1215 test_bit(WL1271_FLAG_JOINED, &wl->flags))
c7f43e45 1216 wl1271_unjoin_channel(wl);
8f648c00 1217 else if (!(conf->flags & IEEE80211_CONF_IDLE))
c7f43e45 1218 wl1271_join_channel(wl, channel);
a6fe2313
JO
1219
1220 if (conf->flags & IEEE80211_CONF_IDLE) {
830fb67b
JO
1221 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1222 wl->sta_rate_set = 0;
1223 wl1271_acx_rate_policies(wl);
a6fe2313 1224 }
f5fc0f86
LC
1225 }
1226
c7f43e45 1227 /* if the channel changes while joined, join again */
ddb01a5b
JO
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;
c7f43e45 1238
71449f8d
JO
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);
f5fc0f86
LC
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 */
830fb67b 1248 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
af5e084b 1249 wl1271_info("psm enabled");
d8c42c0c
JO
1250 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
1251 true);
af5e084b 1252 }
f5fc0f86 1253 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
71449f8d 1254 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
f5fc0f86
LC
1255 wl1271_info("psm disabled");
1256
71449f8d 1257 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
f5fc0f86 1258
71449f8d 1259 if (test_bit(WL1271_FLAG_PSM, &wl->flags))
d8c42c0c
JO
1260 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
1261 true);
f5fc0f86
LC
1262 }
1263
1264 if (conf->power_level != wl->power_level) {
1265 ret = wl1271_acx_tx_power(wl, conf->power_level);
1266 if (ret < 0)
c6317a54 1267 goto out_sleep;
f5fc0f86
LC
1268
1269 wl->power_level = conf->power_level;
1270 }
1271
1272out_sleep:
1273 wl1271_ps_elp_sleep(wl);
1274
1275out:
1276 mutex_unlock(&wl->mutex);
1277
1278 return ret;
1279}
1280
b54853f1
JO
1281struct wl1271_filter_params {
1282 bool enabled;
1283 int mc_list_length;
1284 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
1285};
1286
c87dec9f
JO
1287static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, int mc_count,
1288 struct dev_addr_list *mc_list)
1289{
c87dec9f 1290 struct wl1271_filter_params *fp;
c87dec9f
JO
1291 int i;
1292
74441130 1293 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
c87dec9f
JO
1294 if (!fp) {
1295 wl1271_error("Out of memory setting filters.");
1296 return 0;
1297 }
1298
1299 /* update multicast filtering parameters */
b54853f1 1300 fp->enabled = true;
c87dec9f
JO
1301 if (mc_count > ACX_MC_ADDRESS_GROUP_MAX) {
1302 mc_count = 0;
b54853f1 1303 fp->enabled = false;
c87dec9f
JO
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.");
74441130 1314 mc_list = mc_list->next;
c87dec9f
JO
1315 }
1316
b54853f1 1317 return (u64)(unsigned long)fp;
c87dec9f 1318}
f5fc0f86 1319
b54853f1
JO
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
f5fc0f86
LC
1327static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
1328 unsigned int changed,
c87dec9f 1329 unsigned int *total, u64 multicast)
f5fc0f86 1330{
b54853f1 1331 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
f5fc0f86 1332 struct wl1271 *wl = hw->priv;
b54853f1 1333 int ret;
f5fc0f86
LC
1334
1335 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
1336
b54853f1
JO
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
f5fc0f86
LC
1346 *total &= WL1271_SUPPORTED_FILTERS;
1347 changed &= WL1271_SUPPORTED_FILTERS;
1348
b54853f1
JO
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;
f5fc0f86 1357
b54853f1
JO
1358 kfree(fp);
1359
1360 /* FIXME: We still need to set our filters properly */
c87dec9f 1361
b54853f1
JO
1362 /* determine, whether supported filter values have changed */
1363 if (changed == 0)
1364 goto out_sleep;
c87dec9f 1365
b54853f1
JO
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
1371out_sleep:
1372 wl1271_ps_elp_sleep(wl);
1373
1374out:
1375 mutex_unlock(&wl->mutex);
f5fc0f86
LC
1376}
1377
1378static 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;
ac4e4ce5
JO
1386 u32 tx_seq_32 = 0;
1387 u16 tx_seq_16 = 0;
f5fc0f86
LC
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;
ac4e4ce5
JO
1426 tx_seq_32 = wl->tx_security_seq_32;
1427 tx_seq_16 = wl->tx_security_seq_16;
f5fc0f86
LC
1428 break;
1429 case ALG_CCMP:
1430 key_type = KEY_AES;
1431
1432 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
ac4e4ce5
JO
1433 tx_seq_32 = wl->tx_security_seq_32;
1434 tx_seq_16 = wl->tx_security_seq_16;
f5fc0f86
LC
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,
ac4e4ce5 1448 addr, tx_seq_32, tx_seq_16);
f5fc0f86
LC
1449 if (ret < 0) {
1450 wl1271_error("Could not add or replace key");
1451 goto out_sleep;
1452 }
ee444cf0
JO
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 }
f5fc0f86
LC
1461 break;
1462
1463 case DISABLE_KEY:
fddc7dd7
JO
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
f5fc0f86
LC
1471 ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
1472 key_conf->keyidx, key_type,
1473 key_conf->keylen, key_conf->key,
ac4e4ce5 1474 addr, 0, 0);
f5fc0f86
LC
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
1489out_sleep:
1490 wl1271_ps_elp_sleep(wl);
1491
1492out_unlock:
1493 mutex_unlock(&wl->mutex);
1494
1495out:
1496 return ret;
1497}
1498
1499static 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;
abb0b3bf 1505 size_t len = 0;
f5fc0f86
LC
1506
1507 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
1508
1509 if (req->n_ssids) {
1510 ssid = req->ssids[0].ssid;
abb0b3bf 1511 len = req->ssids[0].ssid_len;
f5fc0f86
LC
1512 }
1513
1514 mutex_lock(&wl->mutex);
1515
1516 ret = wl1271_ps_elp_wakeup(wl, false);
1517 if (ret < 0)
1518 goto out;
1519
abb0b3bf
TP
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);
f5fc0f86
LC
1526
1527 wl1271_ps_elp_sleep(wl);
1528
1529out:
1530 mutex_unlock(&wl->mutex);
1531
1532 return ret;
1533}
1534
1535static 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
1552out:
1553 mutex_unlock(&wl->mutex);
1554
1555 return ret;
1556}
1557
30240fc7
JO
1558static 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
f5fc0f86
LC
1575static 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;
8bf29b0e 1582 bool do_join = false;
f5fc0f86
LC
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
e0d8bbf0
JO
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
30240fc7 1597 on every call to this function. */
e0d8bbf0
JO
1598 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1599
1600 if (beacon) {
1601 struct ieee80211_hdr *hdr;
30240fc7
JO
1602
1603 wl1271_ssid_set(wl, beacon);
e0d8bbf0
JO
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;
8bf29b0e
JO
1625
1626 /* Need to update the SSID (for filtering etc) */
1627 do_join = true;
e0d8bbf0
JO
1628 }
1629 }
1630
30240fc7
JO
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
8bf29b0e
JO
1646 /* Need to update the BSSID (for filtering etc) */
1647 do_join = true;
30240fc7
JO
1648 }
1649
f5fc0f86
LC
1650 if (changed & BSS_CHANGED_ASSOC) {
1651 if (bss_conf->assoc) {
1652 wl->aid = bss_conf->aid;
830fb67b 1653 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
f5fc0f86 1654
ae751bab
LC
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 */
f5fc0f86
LC
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 */
71449f8d
JO
1670 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) &&
1671 !test_bit(WL1271_FLAG_PSM, &wl->flags)) {
f5fc0f86 1672 mode = STATION_POWER_SAVE_MODE;
d8c42c0c 1673 ret = wl1271_ps_set_mode(wl, mode, true);
f5fc0f86
LC
1674 if (ret < 0)
1675 goto out_sleep;
1676 }
d94cd297
JO
1677 } else {
1678 /* use defaults when not associated */
830fb67b 1679 clear_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
d94cd297 1680 wl->aid = 0;
f5fc0f86 1681 }
d94cd297 1682
f5fc0f86 1683 }
8a5a37a6 1684
f5fc0f86
LC
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
8bf29b0e
JO
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
f5fc0f86
LC
1723out_sleep:
1724 wl1271_ps_elp_sleep(wl);
1725
1726out:
1727 mutex_unlock(&wl->mutex);
1728}
1729
c6999d83
KV
1730static 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
c82c1dde
KV
1740 ret = wl1271_ps_elp_wakeup(wl, false);
1741 if (ret < 0)
1742 goto out;
1743
c6999d83
KV
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)
c82c1dde 1748 goto out_sleep;
c6999d83
KV
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)
c82c1dde
KV
1756 goto out_sleep;
1757
1758out_sleep:
1759 wl1271_ps_elp_sleep(wl);
c6999d83
KV
1760
1761out:
1762 mutex_unlock(&wl->mutex);
1763
1764 return ret;
1765}
1766
f5fc0f86
LC
1767
1768/* can't be const, mac80211 writes to this */
1769static struct ieee80211_rate wl1271_rates[] = {
1770 { .bitrate = 10,
2b60100b
JO
1771 .hw_value = CONF_HW_BIT_RATE_1MBPS,
1772 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
f5fc0f86 1773 { .bitrate = 20,
2b60100b
JO
1774 .hw_value = CONF_HW_BIT_RATE_2MBPS,
1775 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
f5fc0f86
LC
1776 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1777 { .bitrate = 55,
2b60100b
JO
1778 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
1779 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
f5fc0f86
LC
1780 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1781 { .bitrate = 110,
2b60100b
JO
1782 .hw_value = CONF_HW_BIT_RATE_11MBPS,
1783 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
f5fc0f86
LC
1784 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1785 { .bitrate = 60,
2b60100b
JO
1786 .hw_value = CONF_HW_BIT_RATE_6MBPS,
1787 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
f5fc0f86 1788 { .bitrate = 90,
2b60100b
JO
1789 .hw_value = CONF_HW_BIT_RATE_9MBPS,
1790 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
f5fc0f86 1791 { .bitrate = 120,
2b60100b
JO
1792 .hw_value = CONF_HW_BIT_RATE_12MBPS,
1793 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
f5fc0f86 1794 { .bitrate = 180,
2b60100b
JO
1795 .hw_value = CONF_HW_BIT_RATE_18MBPS,
1796 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
f5fc0f86 1797 { .bitrate = 240,
2b60100b
JO
1798 .hw_value = CONF_HW_BIT_RATE_24MBPS,
1799 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
f5fc0f86 1800 { .bitrate = 360,
2b60100b
JO
1801 .hw_value = CONF_HW_BIT_RATE_36MBPS,
1802 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
f5fc0f86 1803 { .bitrate = 480,
2b60100b
JO
1804 .hw_value = CONF_HW_BIT_RATE_48MBPS,
1805 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
f5fc0f86 1806 { .bitrate = 540,
2b60100b
JO
1807 .hw_value = CONF_HW_BIT_RATE_54MBPS,
1808 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
f5fc0f86
LC
1809};
1810
1811/* can't be const, mac80211 writes to this */
1812static struct ieee80211_channel wl1271_channels[] = {
a2d0e3f1
LC
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 },
f5fc0f86
LC
1826};
1827
1828/* can't be const, mac80211 writes to this */
1829static 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
1ebec3d7
TP
1836/* 5 GHz data rates for WL1273 */
1837static 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 */
1865static 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
1911static 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
f5fc0f86
LC
1918static 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, */
c87dec9f 1925 .prepare_multicast = wl1271_op_prepare_multicast,
f5fc0f86
LC
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,
c6999d83 1932 .conf_tx = wl1271_op_conf_tx,
c8c90873 1933 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
f5fc0f86
LC
1934};
1935
2d5e82b8 1936int wl1271_register_hw(struct wl1271 *wl)
f5fc0f86
LC
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
2d5e82b8 1958int wl1271_init_ieee80211(struct wl1271 *wl)
f5fc0f86 1959{
1e2b7976
JO
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);
f5fc0f86
LC
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 |
1922167b 1969 IEEE80211_HW_NOISE_DBM |
03442a33
JO
1970 IEEE80211_HW_BEACON_FILTER |
1971 IEEE80211_HW_SUPPORTS_PS;
f5fc0f86 1972
e0d8bbf0
JO
1973 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1974 BIT(NL80211_IFTYPE_ADHOC);
f5fc0f86
LC
1975 wl->hw->wiphy->max_scan_ssids = 1;
1976 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
1977
1ebec3d7
TP
1978 if (wl1271_11a_enabled())
1979 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
1980
f5fc0f86
LC
1981 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1982
1983 return 0;
1984}
1985
f5fc0f86 1986#define WL1271_DEFAULT_CHANNEL 0
c332a4b8 1987
2d5e82b8 1988struct ieee80211_hw *wl1271_alloc_hw(void)
f5fc0f86 1989{
f5fc0f86
LC
1990 struct ieee80211_hw *hw;
1991 struct wl1271 *wl;
c332a4b8 1992 int i;
f5fc0f86
LC
1993
1994 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
1995 if (!hw) {
1996 wl1271_error("could not alloc ieee80211_hw");
c332a4b8 1997 return ERR_PTR(-ENOMEM);
f5fc0f86
LC
1998 }
1999
2000 wl = hw->priv;
2001 memset(wl, 0, sizeof(*wl));
2002
01c09162
JO
2003 INIT_LIST_HEAD(&wl->list);
2004
f5fc0f86 2005 wl->hw = hw;
f5fc0f86
LC
2006
2007 skb_queue_head_init(&wl->tx_queue);
2008
37b70a81 2009 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
f5fc0f86 2010 wl->channel = WL1271_DEFAULT_CHANNEL;
f5fc0f86 2011 wl->default_key = 0;
f5fc0f86
LC
2012 wl->rx_counter = 0;
2013 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
2014 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
19ad0715 2015 wl->psm_entry_retry = 0;
f5fc0f86 2016 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
a6fe2313 2017 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
830fb67b
JO
2018 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
2019 wl->sta_rate_set = 0;
8a5a37a6 2020 wl->band = IEEE80211_BAND_2GHZ;
b771eee5 2021 wl->vif = NULL;
830fb67b 2022 wl->flags = 0;
f5fc0f86 2023
be7078c2 2024 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
f5fc0f86
LC
2025 wl->tx_frames[i] = NULL;
2026
2027 spin_lock_init(&wl->wl_lock);
2028
f5fc0f86
LC
2029 wl->state = WL1271_STATE_OFF;
2030 mutex_init(&wl->mutex);
2031
c332a4b8
TP
2032 /* Apply default driver configuration. */
2033 wl1271_conf_init(wl);
2034
2d5e82b8
TP
2035 wl1271_debugfs_init(wl);
2036
c332a4b8
TP
2037 return hw;
2038}
2039
2040int 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.213202 seconds and 5 git commands to generate.