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