3c6cd774192ddbd0ba2712e9f630ad9adb4cef9e
[safe/jmp/linux-2.6] / drivers / net / wireless / wl12xx / main.c
1 /*
2  * This file is part of wl12xx
3  *
4  * Copyright (C) 2008-2009 Nokia Corporation
5  *
6  * Contact: Kalle Valo <kalle.valo@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/interrupt.h>
26 #include <linux/firmware.h>
27 #include <linux/delay.h>
28 #include <linux/irq.h>
29 #include <linux/spi/spi.h>
30 #include <linux/crc32.h>
31 #include <linux/etherdevice.h>
32 #include <linux/spi/wl12xx.h>
33
34 #include "wl12xx.h"
35 #include "wl12xx_80211.h"
36 #include "reg.h"
37 #include "wl1251.h"
38 #include "spi.h"
39 #include "event.h"
40 #include "tx.h"
41 #include "rx.h"
42 #include "ps.h"
43 #include "init.h"
44 #include "debugfs.h"
45
46 static void wl12xx_disable_interrupts(struct wl12xx *wl)
47 {
48         disable_irq(wl->irq);
49 }
50
51 static void wl12xx_power_off(struct wl12xx *wl)
52 {
53         wl->set_power(false);
54 }
55
56 static void wl12xx_power_on(struct wl12xx *wl)
57 {
58         wl->set_power(true);
59 }
60
61 static irqreturn_t wl12xx_irq(int irq, void *cookie)
62 {
63         struct wl12xx *wl;
64
65         wl12xx_debug(DEBUG_IRQ, "IRQ");
66
67         wl = cookie;
68
69         schedule_work(&wl->irq_work);
70
71         return IRQ_HANDLED;
72 }
73
74 static int wl12xx_fetch_firmware(struct wl12xx *wl)
75 {
76         const struct firmware *fw;
77         int ret;
78
79         ret = request_firmware(&fw, wl->chip.fw_filename, &wl->spi->dev);
80
81         if (ret < 0) {
82                 wl12xx_error("could not get firmware: %d", ret);
83                 return ret;
84         }
85
86         if (fw->size % 4) {
87                 wl12xx_error("firmware size is not multiple of 32 bits: %zu",
88                              fw->size);
89                 ret = -EILSEQ;
90                 goto out;
91         }
92
93         wl->fw_len = fw->size;
94         wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
95
96         if (!wl->fw) {
97                 wl12xx_error("could not allocate memory for the firmware");
98                 ret = -ENOMEM;
99                 goto out;
100         }
101
102         memcpy(wl->fw, fw->data, wl->fw_len);
103
104         ret = 0;
105
106 out:
107         release_firmware(fw);
108
109         return ret;
110 }
111
112 static int wl12xx_fetch_nvs(struct wl12xx *wl)
113 {
114         const struct firmware *fw;
115         int ret;
116
117         ret = request_firmware(&fw, wl->chip.nvs_filename, &wl->spi->dev);
118
119         if (ret < 0) {
120                 wl12xx_error("could not get nvs file: %d", ret);
121                 return ret;
122         }
123
124         if (fw->size % 4) {
125                 wl12xx_error("nvs size is not multiple of 32 bits: %zu",
126                              fw->size);
127                 ret = -EILSEQ;
128                 goto out;
129         }
130
131         wl->nvs_len = fw->size;
132         wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
133
134         if (!wl->nvs) {
135                 wl12xx_error("could not allocate memory for the nvs file");
136                 ret = -ENOMEM;
137                 goto out;
138         }
139
140         memcpy(wl->nvs, fw->data, wl->nvs_len);
141
142         ret = 0;
143
144 out:
145         release_firmware(fw);
146
147         return ret;
148 }
149
150 static void wl12xx_fw_wakeup(struct wl12xx *wl)
151 {
152         u32 elp_reg;
153
154         elp_reg = ELPCTRL_WAKE_UP;
155         wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
156         elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
157
158         if (!(elp_reg & ELPCTRL_WLAN_READY)) {
159                 wl12xx_warning("WLAN not ready");
160                 elp_reg = ELPCTRL_WAKE_UP_WLAN_READY;
161                 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
162         }
163 }
164
165 static int wl12xx_chip_wakeup(struct wl12xx *wl)
166 {
167         int ret = 0;
168
169         wl12xx_power_on(wl);
170         msleep(wl->chip.power_on_sleep);
171         wl12xx_spi_reset(wl);
172         wl12xx_spi_init(wl);
173
174         /* We don't need a real memory partition here, because we only want
175          * to use the registers at this point. */
176         wl12xx_set_partition(wl,
177                              0x00000000,
178                              0x00000000,
179                              REGISTERS_BASE,
180                              REGISTERS_DOWN_SIZE);
181
182         /* ELP module wake up */
183         wl12xx_fw_wakeup(wl);
184
185         /* whal_FwCtrl_BootSm() */
186
187         /* 0. read chip id from CHIP_ID */
188         wl->chip.id = wl12xx_reg_read32(wl, CHIP_ID_B);
189
190         /* 1. check if chip id is valid */
191
192         switch (wl->chip.id) {
193         case CHIP_ID_1251_PG12:
194                 wl12xx_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
195                              wl->chip.id);
196
197                 wl1251_setup(wl);
198
199                 break;
200         case CHIP_ID_1271_PG10:
201         case CHIP_ID_1251_PG10:
202         case CHIP_ID_1251_PG11:
203         default:
204                 wl12xx_error("unsupported chip id: 0x%x", wl->chip.id);
205                 ret = -ENODEV;
206                 goto out;
207         }
208
209         if (wl->fw == NULL) {
210                 ret = wl12xx_fetch_firmware(wl);
211                 if (ret < 0)
212                         goto out;
213         }
214
215         /* No NVS from netlink, try to get it from the filesystem */
216         if (wl->nvs == NULL) {
217                 ret = wl12xx_fetch_nvs(wl);
218                 if (ret < 0)
219                         goto out;
220         }
221
222 out:
223         return ret;
224 }
225
226 static void wl12xx_filter_work(struct work_struct *work)
227 {
228         struct wl12xx *wl =
229                 container_of(work, struct wl12xx, filter_work);
230         int ret;
231
232         mutex_lock(&wl->mutex);
233
234         if (wl->state == WL12XX_STATE_OFF)
235                 goto out;
236
237         ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
238         if (ret < 0)
239                 goto out;
240
241 out:
242         mutex_unlock(&wl->mutex);
243 }
244
245 int wl12xx_plt_start(struct wl12xx *wl)
246 {
247         int ret;
248
249         wl12xx_notice("power up");
250
251         if (wl->state != WL12XX_STATE_OFF) {
252                 wl12xx_error("cannot go into PLT state because not "
253                              "in off state: %d", wl->state);
254                 return -EBUSY;
255         }
256
257         wl->state = WL12XX_STATE_PLT;
258
259         ret = wl12xx_chip_wakeup(wl);
260         if (ret < 0)
261                 return ret;
262
263         ret = wl->chip.op_boot(wl);
264         if (ret < 0)
265                 return ret;
266
267         wl12xx_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
268
269         ret = wl->chip.op_plt_init(wl);
270         if (ret < 0)
271                 return ret;
272
273         return 0;
274 }
275
276 int wl12xx_plt_stop(struct wl12xx *wl)
277 {
278         wl12xx_notice("power down");
279
280         if (wl->state != WL12XX_STATE_PLT) {
281                 wl12xx_error("cannot power down because not in PLT "
282                              "state: %d", wl->state);
283                 return -EBUSY;
284         }
285
286         wl12xx_disable_interrupts(wl);
287         wl12xx_power_off(wl);
288
289         wl->state = WL12XX_STATE_OFF;
290
291         return 0;
292 }
293
294
295 static int wl12xx_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
296 {
297         struct wl12xx *wl = hw->priv;
298
299         skb_queue_tail(&wl->tx_queue, skb);
300
301         schedule_work(&wl->tx_work);
302
303         /*
304          * The workqueue is slow to process the tx_queue and we need stop
305          * the queue here, otherwise the queue will get too long.
306          */
307         if (skb_queue_len(&wl->tx_queue) >= WL12XX_TX_QUEUE_MAX_LENGTH) {
308                 ieee80211_stop_queues(wl->hw);
309
310                 /*
311                  * FIXME: this is racy, the variable is not properly
312                  * protected. Maybe fix this by removing the stupid
313                  * variable altogether and checking the real queue state?
314                  */
315                 wl->tx_queue_stopped = true;
316         }
317
318         return NETDEV_TX_OK;
319 }
320
321 static int wl12xx_op_start(struct ieee80211_hw *hw)
322 {
323         struct wl12xx *wl = hw->priv;
324         int ret = 0;
325
326         wl12xx_debug(DEBUG_MAC80211, "mac80211 start");
327
328         mutex_lock(&wl->mutex);
329
330         if (wl->state != WL12XX_STATE_OFF) {
331                 wl12xx_error("cannot start because not in off state: %d",
332                              wl->state);
333                 ret = -EBUSY;
334                 goto out;
335         }
336
337         ret = wl12xx_chip_wakeup(wl);
338         if (ret < 0)
339                 return ret;
340
341         ret = wl->chip.op_boot(wl);
342         if (ret < 0)
343                 goto out;
344
345         ret = wl->chip.op_hw_init(wl);
346         if (ret < 0)
347                 goto out;
348
349         ret = wl12xx_acx_station_id(wl);
350         if (ret < 0)
351                 goto out;
352
353         wl->state = WL12XX_STATE_ON;
354
355         wl12xx_info("firmware booted (%s)", wl->chip.fw_ver);
356
357 out:
358         if (ret < 0)
359                 wl12xx_power_off(wl);
360
361         mutex_unlock(&wl->mutex);
362
363         return ret;
364 }
365
366 static void wl12xx_op_stop(struct ieee80211_hw *hw)
367 {
368         struct wl12xx *wl = hw->priv;
369
370         wl12xx_info("down");
371
372         wl12xx_debug(DEBUG_MAC80211, "mac80211 stop");
373
374         mutex_lock(&wl->mutex);
375
376         WARN_ON(wl->state != WL12XX_STATE_ON);
377
378         if (wl->scanning) {
379                 mutex_unlock(&wl->mutex);
380                 ieee80211_scan_completed(wl->hw, true);
381                 mutex_lock(&wl->mutex);
382                 wl->scanning = false;
383         }
384
385         wl->state = WL12XX_STATE_OFF;
386
387         wl12xx_disable_interrupts(wl);
388
389         mutex_unlock(&wl->mutex);
390
391         cancel_work_sync(&wl->irq_work);
392         cancel_work_sync(&wl->tx_work);
393         cancel_work_sync(&wl->filter_work);
394
395         mutex_lock(&wl->mutex);
396
397         /* let's notify MAC80211 about the remaining pending TX frames */
398         wl12xx_tx_flush(wl);
399
400         wl12xx_power_off(wl);
401
402         memset(wl->bssid, 0, ETH_ALEN);
403         wl->listen_int = 1;
404         wl->bss_type = MAX_BSS_TYPE;
405
406         wl->data_in_count = 0;
407         wl->rx_counter = 0;
408         wl->rx_handled = 0;
409         wl->rx_current_buffer = 0;
410         wl->rx_last_id = 0;
411         wl->next_tx_complete = 0;
412         wl->elp = false;
413         wl->psm = 0;
414         wl->tx_queue_stopped = false;
415         wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
416
417         wl12xx_debugfs_reset(wl);
418
419         mutex_unlock(&wl->mutex);
420 }
421
422 static int wl12xx_op_add_interface(struct ieee80211_hw *hw,
423                                    struct ieee80211_if_init_conf *conf)
424 {
425         struct wl12xx *wl = hw->priv;
426         DECLARE_MAC_BUF(mac);
427         int ret = 0;
428
429         wl12xx_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %s",
430                      conf->type, print_mac(mac, conf->mac_addr));
431
432         mutex_lock(&wl->mutex);
433
434         switch (conf->type) {
435         case NL80211_IFTYPE_STATION:
436                 wl->bss_type = BSS_TYPE_STA_BSS;
437                 break;
438         case NL80211_IFTYPE_ADHOC:
439                 wl->bss_type = BSS_TYPE_IBSS;
440                 break;
441         default:
442                 ret = -EOPNOTSUPP;
443                 goto out;
444         }
445
446         if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) {
447                 memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
448                 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
449                 ret = wl12xx_acx_station_id(wl);
450                 if (ret < 0)
451                         goto out;
452         }
453
454 out:
455         mutex_unlock(&wl->mutex);
456         return ret;
457 }
458
459 static void wl12xx_op_remove_interface(struct ieee80211_hw *hw,
460                                          struct ieee80211_if_init_conf *conf)
461 {
462         wl12xx_debug(DEBUG_MAC80211, "mac80211 remove interface");
463 }
464
465 static int wl12xx_build_null_data(struct wl12xx *wl)
466 {
467         struct wl12xx_null_data_template template;
468
469         if (!is_zero_ether_addr(wl->bssid)) {
470                 memcpy(template.header.da, wl->bssid, ETH_ALEN);
471                 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
472         } else {
473                 memset(template.header.da, 0xff, ETH_ALEN);
474                 memset(template.header.bssid, 0xff, ETH_ALEN);
475         }
476
477         memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
478         template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
479                                                 IEEE80211_STYPE_NULLFUNC);
480
481         return wl12xx_cmd_template_set(wl, CMD_NULL_DATA, &template,
482                                        sizeof(template));
483
484 }
485
486 static int wl12xx_build_ps_poll(struct wl12xx *wl, u16 aid)
487 {
488         struct wl12xx_ps_poll_template template;
489
490         memcpy(template.bssid, wl->bssid, ETH_ALEN);
491         memcpy(template.ta, wl->mac_addr, ETH_ALEN);
492         template.aid = aid;
493         template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
494
495         return wl12xx_cmd_template_set(wl, CMD_PS_POLL, &template,
496                                        sizeof(template));
497
498 }
499
500 static int wl12xx_op_config(struct ieee80211_hw *hw, u32 changed)
501 {
502         struct wl12xx *wl = hw->priv;
503         struct ieee80211_conf *conf = &hw->conf;
504         int channel, ret = 0;
505
506         channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
507
508         wl12xx_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
509                      channel,
510                      conf->flags & IEEE80211_CONF_PS ? "on" : "off",
511                      conf->power_level);
512
513         mutex_lock(&wl->mutex);
514
515         if (channel != wl->channel) {
516                 /* FIXME: use beacon interval provided by mac80211 */
517                 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
518                 if (ret < 0)
519                         goto out;
520
521                 wl->channel = channel;
522         }
523
524         ret = wl12xx_build_null_data(wl);
525         if (ret < 0)
526                 goto out;
527
528         if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
529                 wl12xx_info("psm enabled");
530
531                 wl->psm_requested = true;
532
533                 /*
534                  * We enter PSM only if we're already associated.
535                  * If we're not, we'll enter it when joining an SSID,
536                  * through the bss_info_changed() hook.
537                  */
538                 ret = wl12xx_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
539         } else if (!(conf->flags & IEEE80211_CONF_PS) &&
540                    wl->psm_requested) {
541                 wl12xx_info("psm disabled");
542
543                 wl->psm_requested = false;
544
545                 if (wl->psm)
546                         ret = wl12xx_ps_set_mode(wl, STATION_ACTIVE_MODE);
547         }
548
549         if (conf->power_level != wl->power_level) {
550                 ret = wl12xx_acx_tx_power(wl, conf->power_level);
551                 if (ret < 0)
552                         goto out;
553
554                 wl->power_level = conf->power_level;
555         }
556
557 out:
558         mutex_unlock(&wl->mutex);
559         return ret;
560 }
561
562 #define WL12XX_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
563                                   FIF_ALLMULTI | \
564                                   FIF_FCSFAIL | \
565                                   FIF_BCN_PRBRESP_PROMISC | \
566                                   FIF_CONTROL | \
567                                   FIF_OTHER_BSS)
568
569 static void wl12xx_op_configure_filter(struct ieee80211_hw *hw,
570                                        unsigned int changed,
571                                        unsigned int *total,
572                                        int mc_count,
573                                        struct dev_addr_list *mc_list)
574 {
575         struct wl12xx *wl = hw->priv;
576
577         wl12xx_debug(DEBUG_MAC80211, "mac80211 configure filter");
578
579         *total &= WL12XX_SUPPORTED_FILTERS;
580         changed &= WL12XX_SUPPORTED_FILTERS;
581
582         if (changed == 0)
583                 /* no filters which we support changed */
584                 return;
585
586         /* FIXME: wl->rx_config and wl->rx_filter are not protected */
587
588         wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
589         wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
590
591         if (*total & FIF_PROMISC_IN_BSS) {
592                 wl->rx_config |= CFG_BSSID_FILTER_EN;
593                 wl->rx_config |= CFG_RX_ALL_GOOD;
594         }
595         if (*total & FIF_ALLMULTI)
596                 /*
597                  * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
598                  * all multicast frames
599                  */
600                 wl->rx_config &= ~CFG_MC_FILTER_EN;
601         if (*total & FIF_FCSFAIL)
602                 wl->rx_filter |= CFG_RX_FCS_ERROR;
603         if (*total & FIF_BCN_PRBRESP_PROMISC) {
604                 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
605                 wl->rx_config &= ~CFG_SSID_FILTER_EN;
606         }
607         if (*total & FIF_CONTROL)
608                 wl->rx_filter |= CFG_RX_CTL_EN;
609         if (*total & FIF_OTHER_BSS)
610                 wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
611
612         /*
613          * FIXME: workqueues need to be properly cancelled on stop(), for
614          * now let's just disable changing the filter settings. They will
615          * be updated any on config().
616          */
617         /* schedule_work(&wl->filter_work); */
618 }
619
620 /* HW encryption */
621 static int wl12xx_set_key_type(struct wl12xx *wl,
622                                struct wl12xx_cmd_set_keys *key,
623                                enum set_key_cmd cmd,
624                                struct ieee80211_key_conf *mac80211_key,
625                                const u8 *addr)
626 {
627         switch (mac80211_key->alg) {
628         case ALG_WEP:
629                 if (is_broadcast_ether_addr(addr))
630                         key->key_type = KEY_WEP_DEFAULT;
631                 else
632                         key->key_type = KEY_WEP_ADDR;
633
634                 mac80211_key->hw_key_idx = mac80211_key->keyidx;
635                 break;
636         case ALG_TKIP:
637                 if (is_broadcast_ether_addr(addr))
638                         key->key_type = KEY_TKIP_MIC_GROUP;
639                 else
640                         key->key_type = KEY_TKIP_MIC_PAIRWISE;
641
642                 mac80211_key->hw_key_idx = mac80211_key->keyidx;
643                 break;
644         case ALG_CCMP:
645                 if (is_broadcast_ether_addr(addr))
646                         key->key_type = KEY_AES_GROUP;
647                 else
648                         key->key_type = KEY_AES_PAIRWISE;
649                 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
650                 break;
651         default:
652                 wl12xx_error("Unknown key algo 0x%x", mac80211_key->alg);
653                 return -EOPNOTSUPP;
654         }
655
656         return 0;
657 }
658
659 static int wl12xx_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
660                              struct ieee80211_vif *vif,
661                              struct ieee80211_sta *sta,
662                              struct ieee80211_key_conf *key)
663 {
664         struct wl12xx *wl = hw->priv;
665         struct wl12xx_cmd_set_keys *wl_cmd;
666         const u8 *addr;
667         int ret;
668
669         static const u8 bcast_addr[ETH_ALEN] =
670                 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
671
672         wl12xx_debug(DEBUG_MAC80211, "mac80211 set key");
673
674         wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
675         if (!wl_cmd) {
676                 ret = -ENOMEM;
677                 goto out;
678         }
679
680         addr = sta ? sta->addr : bcast_addr;
681
682         wl12xx_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
683         wl12xx_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
684         wl12xx_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
685                      key->alg, key->keyidx, key->keylen, key->flags);
686         wl12xx_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
687
688         if (is_zero_ether_addr(addr)) {
689                 /* We dont support TX only encryption */
690                 ret = -EOPNOTSUPP;
691                 goto out;
692         }
693
694         mutex_lock(&wl->mutex);
695
696         switch (cmd) {
697         case SET_KEY:
698                 wl_cmd->key_action = KEY_ADD_OR_REPLACE;
699                 break;
700         case DISABLE_KEY:
701                 wl_cmd->key_action = KEY_REMOVE;
702                 break;
703         default:
704                 wl12xx_error("Unsupported key cmd 0x%x", cmd);
705                 break;
706         }
707
708         ret = wl12xx_set_key_type(wl, wl_cmd, cmd, key, addr);
709         if (ret < 0) {
710                 wl12xx_error("Set KEY type failed");
711                 goto out_unlock;
712         }
713
714         if (wl_cmd->key_type != KEY_WEP_DEFAULT)
715                 memcpy(wl_cmd->addr, addr, ETH_ALEN);
716
717         if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
718             (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
719                 /*
720                  * We get the key in the following form:
721                  * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
722                  * but the target is expecting:
723                  * TKIP - RX MIC - TX MIC
724                  */
725                 memcpy(wl_cmd->key, key->key, 16);
726                 memcpy(wl_cmd->key + 16, key->key + 24, 8);
727                 memcpy(wl_cmd->key + 24, key->key + 16, 8);
728
729         } else {
730                 memcpy(wl_cmd->key, key->key, key->keylen);
731         }
732         wl_cmd->key_size = key->keylen;
733
734         wl_cmd->id = key->keyidx;
735         wl_cmd->ssid_profile = 0;
736
737         wl12xx_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
738
739         ret = wl12xx_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
740         if (ret < 0) {
741                 wl12xx_warning("could not set keys");
742                 goto out_unlock;
743         }
744
745 out_unlock:
746         mutex_unlock(&wl->mutex);
747
748 out:
749         kfree(wl_cmd);
750
751         return ret;
752 }
753
754 static int wl12xx_build_basic_rates(char *rates)
755 {
756         u8 index = 0;
757
758         rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
759         rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
760         rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
761         rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
762
763         return index;
764 }
765
766 static int wl12xx_build_extended_rates(char *rates)
767 {
768         u8 index = 0;
769
770         rates[index++] = IEEE80211_OFDM_RATE_6MB;
771         rates[index++] = IEEE80211_OFDM_RATE_9MB;
772         rates[index++] = IEEE80211_OFDM_RATE_12MB;
773         rates[index++] = IEEE80211_OFDM_RATE_18MB;
774         rates[index++] = IEEE80211_OFDM_RATE_24MB;
775         rates[index++] = IEEE80211_OFDM_RATE_36MB;
776         rates[index++] = IEEE80211_OFDM_RATE_48MB;
777         rates[index++] = IEEE80211_OFDM_RATE_54MB;
778
779         return index;
780 }
781
782
783 static int wl12xx_build_probe_req(struct wl12xx *wl, u8 *ssid, size_t ssid_len)
784 {
785         struct wl12xx_probe_req_template template;
786         struct wl12xx_ie_rates *rates;
787         char *ptr;
788         u16 size;
789
790         ptr = (char *)&template;
791         size = sizeof(struct ieee80211_header);
792
793         memset(template.header.da, 0xff, ETH_ALEN);
794         memset(template.header.bssid, 0xff, ETH_ALEN);
795         memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
796         template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
797
798         /* IEs */
799         /* SSID */
800         template.ssid.header.id = WLAN_EID_SSID;
801         template.ssid.header.len = ssid_len;
802         if (ssid_len && ssid)
803                 memcpy(template.ssid.ssid, ssid, ssid_len);
804         size += sizeof(struct wl12xx_ie_header) + ssid_len;
805         ptr += size;
806
807         /* Basic Rates */
808         rates = (struct wl12xx_ie_rates *)ptr;
809         rates->header.id = WLAN_EID_SUPP_RATES;
810         rates->header.len = wl12xx_build_basic_rates(rates->rates);
811         size += sizeof(struct wl12xx_ie_header) + rates->header.len;
812         ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
813
814         /* Extended rates */
815         rates = (struct wl12xx_ie_rates *)ptr;
816         rates->header.id = WLAN_EID_EXT_SUPP_RATES;
817         rates->header.len = wl12xx_build_extended_rates(rates->rates);
818         size += sizeof(struct wl12xx_ie_header) + rates->header.len;
819
820         wl12xx_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
821
822         return wl12xx_cmd_template_set(wl, CMD_PROBE_REQ, &template,
823                                       size);
824 }
825
826 static int wl12xx_hw_scan(struct wl12xx *wl, u8 *ssid, size_t len,
827                           u8 active_scan, u8 high_prio, u8 num_channels,
828                           u8 probe_requests)
829 {
830         struct wl12xx_cmd_trigger_scan_to *trigger = NULL;
831         struct cmd_scan *params = NULL;
832         int i, ret;
833         u16 scan_options = 0;
834
835         if (wl->scanning)
836                 return -EINVAL;
837
838         params = kzalloc(sizeof(*params), GFP_KERNEL);
839         if (!params)
840                 return -ENOMEM;
841
842         params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
843         params->params.rx_filter_options =
844                 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
845
846         /* High priority scan */
847         if (!active_scan)
848                 scan_options |= SCAN_PASSIVE;
849         if (high_prio)
850                 scan_options |= SCAN_PRIORITY_HIGH;
851         params->params.scan_options = scan_options;
852
853         params->params.num_channels = num_channels;
854         params->params.num_probe_requests = probe_requests;
855         params->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
856         params->params.tid_trigger = 0;
857
858         for (i = 0; i < num_channels; i++) {
859                 params->channels[i].min_duration = cpu_to_le32(30000);
860                 params->channels[i].max_duration = cpu_to_le32(60000);
861                 memset(&params->channels[i].bssid_lsb, 0xff, 4);
862                 memset(&params->channels[i].bssid_msb, 0xff, 2);
863                 params->channels[i].early_termination = 0;
864                 params->channels[i].tx_power_att = 0;
865                 params->channels[i].channel = i + 1;
866                 memset(params->channels[i].pad, 0, 3);
867         }
868
869         for (i = num_channels; i < SCAN_MAX_NUM_OF_CHANNELS; i++)
870                 memset(&params->channels[i], 0,
871                        sizeof(struct basic_scan_channel_parameters));
872
873         if (len && ssid) {
874                 params->params.ssid_len = len;
875                 memcpy(params->params.ssid, ssid, len);
876         } else {
877                 params->params.ssid_len = 0;
878                 memset(params->params.ssid, 0, 32);
879         }
880
881         ret = wl12xx_build_probe_req(wl, ssid, len);
882         if (ret < 0) {
883                 wl12xx_error("PROBE request template failed");
884                 goto out;
885         }
886
887         trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
888         if (!trigger)
889                 goto out;
890
891         trigger->timeout = 0;
892
893         ret = wl12xx_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
894                               sizeof(*trigger));
895         if (ret < 0) {
896                 wl12xx_error("trigger scan to failed for hw scan");
897                 goto out;
898         }
899
900         wl12xx_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
901
902         wl->scanning = true;
903
904         ret = wl12xx_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
905         if (ret < 0)
906                 wl12xx_error("SCAN failed");
907
908         wl12xx_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
909
910         if (params->header.status != CMD_STATUS_SUCCESS) {
911                 wl12xx_error("TEST command answer error: %d",
912                              params->header.status);
913                 wl->scanning = false;
914                 ret = -EIO;
915                 goto out;
916         }
917
918 out:
919         kfree(params);
920         return ret;
921
922 }
923
924 static int wl12xx_op_hw_scan(struct ieee80211_hw *hw,
925                              struct cfg80211_scan_request *req)
926 {
927         struct wl12xx *wl = hw->priv;
928         int ret;
929         u8 *ssid = NULL;
930         size_t ssid_len = 0;
931
932         wl12xx_debug(DEBUG_MAC80211, "mac80211 hw scan");
933
934         if (req->n_ssids) {
935                 ssid = req->ssids[0].ssid;
936                 ssid_len = req->ssids[0].ssid_len;
937         }
938
939         mutex_lock(&wl->mutex);
940         ret = wl12xx_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
941         mutex_unlock(&wl->mutex);
942
943         return ret;
944 }
945
946 static int wl12xx_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
947 {
948         struct wl12xx *wl = hw->priv;
949         int ret;
950
951         ret = wl12xx_acx_rts_threshold(wl, (u16) value);
952
953         if (ret < 0)
954                 wl12xx_warning("wl12xx_op_set_rts_threshold failed: %d", ret);
955
956         return ret;
957 }
958
959 static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw,
960                                        struct ieee80211_vif *vif,
961                                        struct ieee80211_bss_conf *bss_conf,
962                                        u32 changed)
963 {
964         enum wl12xx_cmd_ps_mode mode;
965         struct wl12xx *wl = hw->priv;
966         struct sk_buff *beacon;
967         int ret;
968
969         wl12xx_debug(DEBUG_MAC80211, "mac80211 bss info changed");
970
971         mutex_lock(&wl->mutex);
972
973         if (changed & BSS_CHANGED_ASSOC) {
974                 if (bss_conf->assoc) {
975                         wl->aid = bss_conf->aid;
976
977                         ret = wl12xx_build_ps_poll(wl, wl->aid);
978                         if (ret < 0)
979                                 goto out;
980
981                         ret = wl12xx_acx_aid(wl, wl->aid);
982                         if (ret < 0)
983                                 goto out;
984
985                         /* If we want to go in PSM but we're not there yet */
986                         if (wl->psm_requested && !wl->psm) {
987                                 mode = STATION_POWER_SAVE_MODE;
988                                 ret = wl12xx_ps_set_mode(wl, mode);
989                                 if (ret < 0)
990                                         goto out;
991                         }
992                 }
993         }
994         if (changed & BSS_CHANGED_ERP_SLOT) {
995                 if (bss_conf->use_short_slot)
996                         ret = wl12xx_acx_slot(wl, SLOT_TIME_SHORT);
997                 else
998                         ret = wl12xx_acx_slot(wl, SLOT_TIME_LONG);
999                 if (ret < 0) {
1000                         wl12xx_warning("Set slot time failed %d", ret);
1001                         goto out;
1002                 }
1003         }
1004
1005         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1006                 if (bss_conf->use_short_preamble)
1007                         wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
1008                 else
1009                         wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
1010         }
1011
1012         if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1013                 if (bss_conf->use_cts_prot)
1014                         ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_ENABLE);
1015                 else
1016                         ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1017                 if (ret < 0) {
1018                         wl12xx_warning("Set ctsprotect failed %d", ret);
1019                         goto out;
1020                 }
1021         }
1022
1023         if (changed & BSS_CHANGED_BSSID) {
1024                 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1025
1026                 ret = wl12xx_build_null_data(wl);
1027                 if (ret < 0)
1028                         goto out;
1029
1030                 if (wl->bss_type != BSS_TYPE_IBSS) {
1031                         ret = wl12xx_cmd_join(wl, wl->bss_type, 5, 100, 1);
1032                         if (ret < 0)
1033                                 goto out;
1034                 }
1035         }
1036
1037         if (changed & BSS_CHANGED_BEACON) {
1038                 beacon = ieee80211_beacon_get(hw, vif);
1039                 ret = wl12xx_cmd_template_set(wl, CMD_BEACON, beacon->data,
1040                                               beacon->len);
1041
1042                 if (ret < 0) {
1043                         dev_kfree_skb(beacon);
1044                         goto out;
1045                 }
1046
1047                 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
1048                                               beacon->len);
1049
1050                 dev_kfree_skb(beacon);
1051
1052                 if (ret < 0)
1053                         goto out;
1054
1055                 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
1056
1057                 if (ret < 0)
1058                         goto out;
1059         }
1060
1061 out:
1062         mutex_unlock(&wl->mutex);
1063 }
1064
1065
1066 /* can't be const, mac80211 writes to this */
1067 static struct ieee80211_rate wl12xx_rates[] = {
1068         { .bitrate = 10,
1069           .hw_value = 0x1,
1070           .hw_value_short = 0x1, },
1071         { .bitrate = 20,
1072           .hw_value = 0x2,
1073           .hw_value_short = 0x2,
1074           .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1075         { .bitrate = 55,
1076           .hw_value = 0x4,
1077           .hw_value_short = 0x4,
1078           .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1079         { .bitrate = 110,
1080           .hw_value = 0x20,
1081           .hw_value_short = 0x20,
1082           .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1083         { .bitrate = 60,
1084           .hw_value = 0x8,
1085           .hw_value_short = 0x8, },
1086         { .bitrate = 90,
1087           .hw_value = 0x10,
1088           .hw_value_short = 0x10, },
1089         { .bitrate = 120,
1090           .hw_value = 0x40,
1091           .hw_value_short = 0x40, },
1092         { .bitrate = 180,
1093           .hw_value = 0x80,
1094           .hw_value_short = 0x80, },
1095         { .bitrate = 240,
1096           .hw_value = 0x200,
1097           .hw_value_short = 0x200, },
1098         { .bitrate = 360,
1099          .hw_value = 0x400,
1100          .hw_value_short = 0x400, },
1101         { .bitrate = 480,
1102           .hw_value = 0x800,
1103           .hw_value_short = 0x800, },
1104         { .bitrate = 540,
1105           .hw_value = 0x1000,
1106           .hw_value_short = 0x1000, },
1107 };
1108
1109 /* can't be const, mac80211 writes to this */
1110 static struct ieee80211_channel wl12xx_channels[] = {
1111         { .hw_value = 1, .center_freq = 2412},
1112         { .hw_value = 2, .center_freq = 2417},
1113         { .hw_value = 3, .center_freq = 2422},
1114         { .hw_value = 4, .center_freq = 2427},
1115         { .hw_value = 5, .center_freq = 2432},
1116         { .hw_value = 6, .center_freq = 2437},
1117         { .hw_value = 7, .center_freq = 2442},
1118         { .hw_value = 8, .center_freq = 2447},
1119         { .hw_value = 9, .center_freq = 2452},
1120         { .hw_value = 10, .center_freq = 2457},
1121         { .hw_value = 11, .center_freq = 2462},
1122         { .hw_value = 12, .center_freq = 2467},
1123         { .hw_value = 13, .center_freq = 2472},
1124 };
1125
1126 /* can't be const, mac80211 writes to this */
1127 static struct ieee80211_supported_band wl12xx_band_2ghz = {
1128         .channels = wl12xx_channels,
1129         .n_channels = ARRAY_SIZE(wl12xx_channels),
1130         .bitrates = wl12xx_rates,
1131         .n_bitrates = ARRAY_SIZE(wl12xx_rates),
1132 };
1133
1134 static const struct ieee80211_ops wl12xx_ops = {
1135         .start = wl12xx_op_start,
1136         .stop = wl12xx_op_stop,
1137         .add_interface = wl12xx_op_add_interface,
1138         .remove_interface = wl12xx_op_remove_interface,
1139         .config = wl12xx_op_config,
1140         .configure_filter = wl12xx_op_configure_filter,
1141         .tx = wl12xx_op_tx,
1142         .set_key = wl12xx_op_set_key,
1143         .hw_scan = wl12xx_op_hw_scan,
1144         .bss_info_changed = wl12xx_op_bss_info_changed,
1145         .set_rts_threshold = wl12xx_op_set_rts_threshold,
1146 };
1147
1148 static int wl12xx_register_hw(struct wl12xx *wl)
1149 {
1150         int ret;
1151
1152         if (wl->mac80211_registered)
1153                 return 0;
1154
1155         SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1156
1157         ret = ieee80211_register_hw(wl->hw);
1158         if (ret < 0) {
1159                 wl12xx_error("unable to register mac80211 hw: %d", ret);
1160                 return ret;
1161         }
1162
1163         wl->mac80211_registered = true;
1164
1165         wl12xx_notice("loaded");
1166
1167         return 0;
1168 }
1169
1170 static int wl12xx_init_ieee80211(struct wl12xx *wl)
1171 {
1172         /* The tx descriptor buffer and the TKIP space */
1173         wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1174                 + WL12XX_TKIP_IV_SPACE;
1175
1176         /* unit us */
1177         /* FIXME: find a proper value */
1178         wl->hw->channel_change_time = 10000;
1179
1180         wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1181                 IEEE80211_HW_NOISE_DBM;
1182
1183         wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1184         wl->hw->wiphy->max_scan_ssids = 1;
1185         wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl12xx_band_2ghz;
1186
1187         SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1188
1189         return 0;
1190 }
1191
1192 #define WL12XX_DEFAULT_CHANNEL 1
1193 static int __devinit wl12xx_probe(struct spi_device *spi)
1194 {
1195         struct wl12xx_platform_data *pdata;
1196         struct ieee80211_hw *hw;
1197         struct wl12xx *wl;
1198         int ret, i;
1199         static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1200
1201         pdata = spi->dev.platform_data;
1202         if (!pdata) {
1203                 wl12xx_error("no platform data");
1204                 return -ENODEV;
1205         }
1206
1207         hw = ieee80211_alloc_hw(sizeof(*wl), &wl12xx_ops);
1208         if (!hw) {
1209                 wl12xx_error("could not alloc ieee80211_hw");
1210                 return -ENOMEM;
1211         }
1212
1213         wl = hw->priv;
1214         memset(wl, 0, sizeof(*wl));
1215
1216         wl->hw = hw;
1217         dev_set_drvdata(&spi->dev, wl);
1218         wl->spi = spi;
1219
1220         wl->data_in_count = 0;
1221
1222         skb_queue_head_init(&wl->tx_queue);
1223
1224         INIT_WORK(&wl->tx_work, wl12xx_tx_work);
1225         INIT_WORK(&wl->filter_work, wl12xx_filter_work);
1226         wl->channel = WL12XX_DEFAULT_CHANNEL;
1227         wl->scanning = false;
1228         wl->default_key = 0;
1229         wl->listen_int = 1;
1230         wl->rx_counter = 0;
1231         wl->rx_handled = 0;
1232         wl->rx_current_buffer = 0;
1233         wl->rx_last_id = 0;
1234         wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
1235         wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
1236         wl->elp = false;
1237         wl->psm = 0;
1238         wl->psm_requested = false;
1239         wl->tx_queue_stopped = false;
1240         wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
1241
1242         /* We use the default power on sleep time until we know which chip
1243          * we're using */
1244         wl->chip.power_on_sleep = WL12XX_DEFAULT_POWER_ON_SLEEP;
1245
1246         for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1247                 wl->tx_frames[i] = NULL;
1248
1249         wl->next_tx_complete = 0;
1250
1251         /*
1252          * In case our MAC address is not correctly set,
1253          * we use a random but Nokia MAC.
1254          */
1255         memcpy(wl->mac_addr, nokia_oui, 3);
1256         get_random_bytes(wl->mac_addr + 3, 3);
1257
1258         wl->state = WL12XX_STATE_OFF;
1259         mutex_init(&wl->mutex);
1260
1261         wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1262         wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1263
1264         wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1265         if (!wl->rx_descriptor) {
1266                 wl12xx_error("could not allocate memory for rx descriptor");
1267                 ret = -ENOMEM;
1268                 goto out_free;
1269         }
1270
1271         /* This is the only SPI value that we need to set here, the rest
1272          * comes from the board-peripherals file */
1273         spi->bits_per_word = 32;
1274
1275         ret = spi_setup(spi);
1276         if (ret < 0) {
1277                 wl12xx_error("spi_setup failed");
1278                 goto out_free;
1279         }
1280
1281         wl->set_power = pdata->set_power;
1282         if (!wl->set_power) {
1283                 wl12xx_error("set power function missing in platform data");
1284                 ret = -ENODEV;
1285                 goto out_free;
1286         }
1287
1288         wl->irq = spi->irq;
1289         if (wl->irq < 0) {
1290                 wl12xx_error("irq missing in platform data");
1291                 ret = -ENODEV;
1292                 goto out_free;
1293         }
1294
1295         ret = request_irq(wl->irq, wl12xx_irq, 0, DRIVER_NAME, wl);
1296         if (ret < 0) {
1297                 wl12xx_error("request_irq() failed: %d", ret);
1298                 goto out_free;
1299         }
1300
1301         set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
1302
1303         disable_irq(wl->irq);
1304
1305         ret = wl12xx_init_ieee80211(wl);
1306         if (ret)
1307                 goto out_irq;
1308
1309         ret = wl12xx_register_hw(wl);
1310         if (ret)
1311                 goto out_irq;
1312
1313         wl12xx_debugfs_init(wl);
1314
1315         wl12xx_notice("initialized");
1316
1317         return 0;
1318
1319  out_irq:
1320         free_irq(wl->irq, wl);
1321
1322  out_free:
1323         kfree(wl->rx_descriptor);
1324         wl->rx_descriptor = NULL;
1325
1326         ieee80211_free_hw(hw);
1327
1328         return ret;
1329 }
1330
1331 static int __devexit wl12xx_remove(struct spi_device *spi)
1332 {
1333         struct wl12xx *wl = dev_get_drvdata(&spi->dev);
1334
1335         ieee80211_unregister_hw(wl->hw);
1336
1337         wl12xx_debugfs_exit(wl);
1338
1339         free_irq(wl->irq, wl);
1340         kfree(wl->target_mem_map);
1341         kfree(wl->data_path);
1342         kfree(wl->fw);
1343         wl->fw = NULL;
1344         kfree(wl->nvs);
1345         wl->nvs = NULL;
1346
1347         kfree(wl->rx_descriptor);
1348         wl->rx_descriptor = NULL;
1349
1350         ieee80211_free_hw(wl->hw);
1351
1352         return 0;
1353 }
1354
1355
1356 static struct spi_driver wl12xx_spi_driver = {
1357         .driver = {
1358                 .name           = "wl12xx",
1359                 .bus            = &spi_bus_type,
1360                 .owner          = THIS_MODULE,
1361         },
1362
1363         .probe          = wl12xx_probe,
1364         .remove         = __devexit_p(wl12xx_remove),
1365 };
1366
1367 static int __init wl12xx_init(void)
1368 {
1369         int ret;
1370
1371         ret = spi_register_driver(&wl12xx_spi_driver);
1372         if (ret < 0) {
1373                 wl12xx_error("failed to register spi driver: %d", ret);
1374                 goto out;
1375         }
1376
1377 out:
1378         return ret;
1379 }
1380
1381 static void __exit wl12xx_exit(void)
1382 {
1383         spi_unregister_driver(&wl12xx_spi_driver);
1384
1385         wl12xx_notice("unloaded");
1386 }
1387
1388 module_init(wl12xx_init);
1389 module_exit(wl12xx_exit);
1390
1391 MODULE_LICENSE("GPL");
1392 MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>, "
1393                 "Luciano Coelho <luciano.coelho@nokia.com>");