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