2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/interrupt.h>
27 #include <linux/firmware.h>
28 #include <linux/delay.h>
29 #include <linux/irq.h>
30 #include <linux/spi/spi.h>
31 #include <linux/crc32.h>
32 #include <linux/etherdevice.h>
33 #include <linux/spi/wl12xx.h>
36 #include "wl12xx_80211.h"
37 #include "wl1271_reg.h"
38 #include "wl1271_spi.h"
39 #include "wl1271_event.h"
40 #include "wl1271_tx.h"
41 #include "wl1271_rx.h"
42 #include "wl1271_ps.h"
43 #include "wl1271_init.h"
44 #include "wl1271_debugfs.h"
45 #include "wl1271_cmd.h"
46 #include "wl1271_boot.h"
48 static int wl1271_plt_init(struct wl1271 *wl)
52 ret = wl1271_acx_init_mem_config(wl);
56 ret = wl1271_cmd_data_path(wl, wl->channel, 1);
63 static void wl1271_disable_interrupts(struct wl1271 *wl)
68 static void wl1271_power_off(struct wl1271 *wl)
73 static void wl1271_power_on(struct wl1271 *wl)
78 static void wl1271_fw_status(struct wl1271 *wl, struct wl1271_fw_status *status)
84 * FIXME: Reading the FW status directly from the registers seems to
85 * be the right thing to do, but it doesn't work. And in the
86 * reference driver, there is a workaround called
87 * USE_SDIO_24M_WORKAROUND, which reads the status from memory
88 * instead, so we do the same here.
91 wl1271_spi_mem_read(wl, STATUS_MEM_ADDRESS, status, sizeof(*status));
93 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
94 "drv_rx_counter = %d, tx_results_counter = %d)",
96 status->fw_rx_counter,
97 status->drv_rx_counter,
98 status->tx_results_counter);
100 /* update number of available TX blocks */
101 for (i = 0; i < NUM_TX_QUEUES; i++) {
102 u32 cnt = status->tx_released_blks[i] - wl->tx_blocks_freed[i];
103 wl->tx_blocks_freed[i] = status->tx_released_blks[i];
104 wl->tx_blocks_available += cnt;
108 /* if more blocks are available now, schedule some tx work */
109 if (total && !skb_queue_empty(&wl->tx_queue))
110 schedule_work(&wl->tx_work);
112 /* update the host-chipset time offset */
113 wl->time_offset = jiffies_to_usecs(jiffies) - status->fw_localtime;
116 #define WL1271_IRQ_MAX_LOOPS 10
117 static void wl1271_irq_work(struct work_struct *work)
119 u32 intr, ctr = WL1271_IRQ_MAX_LOOPS;
122 container_of(work, struct wl1271, irq_work);
124 mutex_lock(&wl->mutex);
126 wl1271_debug(DEBUG_IRQ, "IRQ work");
128 if (wl->state == WL1271_STATE_OFF)
131 ret = wl1271_ps_elp_wakeup(wl, true);
135 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
137 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
139 wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
143 intr &= WL1271_INTR_MASK;
146 wl1271_fw_status(wl, wl->fw_status);
149 if (intr & (WL1271_ACX_INTR_EVENT_A |
150 WL1271_ACX_INTR_EVENT_B)) {
151 wl1271_debug(DEBUG_IRQ,
152 "WL1271_ACX_INTR_EVENT (0x%x)", intr);
153 if (intr & WL1271_ACX_INTR_EVENT_A)
154 wl1271_event_handle(wl, 0);
156 wl1271_event_handle(wl, 1);
159 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
160 wl1271_debug(DEBUG_IRQ,
161 "WL1271_ACX_INTR_INIT_COMPLETE");
163 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
164 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
166 if (intr & WL1271_ACX_INTR_DATA) {
167 u8 tx_res_cnt = wl->fw_status->tx_results_counter -
168 wl->tx_results_count;
170 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
172 /* check for tx results */
174 wl1271_tx_complete(wl, tx_res_cnt);
176 wl1271_rx(wl, wl->fw_status);
179 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
180 intr &= WL1271_INTR_MASK;
181 } while (intr && --ctr);
184 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK,
185 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
186 wl1271_ps_elp_sleep(wl);
189 mutex_unlock(&wl->mutex);
192 static irqreturn_t wl1271_irq(int irq, void *cookie)
197 wl1271_debug(DEBUG_IRQ, "IRQ");
201 /* complete the ELP completion */
202 spin_lock_irqsave(&wl->wl_lock, flags);
204 complete(wl->elp_compl);
205 wl->elp_compl = NULL;
208 schedule_work(&wl->irq_work);
209 spin_unlock_irqrestore(&wl->wl_lock, flags);
214 static int wl1271_fetch_firmware(struct wl1271 *wl)
216 const struct firmware *fw;
219 ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev);
222 wl1271_error("could not get firmware: %d", ret);
227 wl1271_error("firmware size is not multiple of 32 bits: %zu",
233 wl->fw_len = fw->size;
234 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
237 wl1271_error("could not allocate memory for the firmware");
242 memcpy(wl->fw, fw->data, wl->fw_len);
247 release_firmware(fw);
252 static int wl1271_fetch_nvs(struct wl1271 *wl)
254 const struct firmware *fw;
257 ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev);
260 wl1271_error("could not get nvs file: %d", ret);
265 wl1271_error("nvs size is not multiple of 32 bits: %zu",
271 wl->nvs_len = fw->size;
272 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
275 wl1271_error("could not allocate memory for the nvs file");
280 memcpy(wl->nvs, fw->data, wl->nvs_len);
285 release_firmware(fw);
290 static void wl1271_fw_wakeup(struct wl1271 *wl)
294 elp_reg = ELPCTRL_WAKE_UP;
295 wl1271_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
298 static int wl1271_setup(struct wl1271 *wl)
300 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
304 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
305 if (!wl->tx_res_if) {
306 kfree(wl->fw_status);
310 INIT_WORK(&wl->irq_work, wl1271_irq_work);
311 INIT_WORK(&wl->tx_work, wl1271_tx_work);
315 static int wl1271_chip_wakeup(struct wl1271 *wl)
320 msleep(WL1271_POWER_ON_SLEEP);
321 wl1271_spi_reset(wl);
324 /* We don't need a real memory partition here, because we only want
325 * to use the registers at this point. */
326 wl1271_set_partition(wl,
330 REGISTERS_DOWN_SIZE);
332 /* ELP module wake up */
333 wl1271_fw_wakeup(wl);
335 /* whal_FwCtrl_BootSm() */
337 /* 0. read chip id from CHIP_ID */
338 wl->chip.id = wl1271_reg_read32(wl, CHIP_ID_B);
340 /* 1. check if chip id is valid */
342 switch (wl->chip.id) {
343 case CHIP_ID_1271_PG10:
344 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
347 ret = wl1271_setup(wl);
351 case CHIP_ID_1271_PG20:
352 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
355 ret = wl1271_setup(wl);
360 wl1271_error("unsupported chip id: 0x%x", wl->chip.id);
365 if (wl->fw == NULL) {
366 ret = wl1271_fetch_firmware(wl);
371 /* No NVS from netlink, try to get it from the filesystem */
372 if (wl->nvs == NULL) {
373 ret = wl1271_fetch_nvs(wl);
382 static void wl1271_filter_work(struct work_struct *work)
385 container_of(work, struct wl1271, filter_work);
388 mutex_lock(&wl->mutex);
390 if (wl->state == WL1271_STATE_OFF)
393 ret = wl1271_ps_elp_wakeup(wl, false);
397 /* FIXME: replace the magic numbers with proper definitions */
398 ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
403 wl1271_ps_elp_sleep(wl);
406 mutex_unlock(&wl->mutex);
409 int wl1271_plt_start(struct wl1271 *wl)
413 mutex_lock(&wl->mutex);
415 wl1271_notice("power up");
417 if (wl->state != WL1271_STATE_OFF) {
418 wl1271_error("cannot go into PLT state because not "
419 "in off state: %d", wl->state);
424 wl->state = WL1271_STATE_PLT;
426 ret = wl1271_chip_wakeup(wl);
430 ret = wl1271_boot(wl);
434 wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
436 ret = wl1271_plt_init(wl);
441 mutex_unlock(&wl->mutex);
446 int wl1271_plt_stop(struct wl1271 *wl)
450 mutex_lock(&wl->mutex);
452 wl1271_notice("power down");
454 if (wl->state != WL1271_STATE_PLT) {
455 wl1271_error("cannot power down because not in PLT "
456 "state: %d", wl->state);
461 wl1271_disable_interrupts(wl);
462 wl1271_power_off(wl);
464 wl->state = WL1271_STATE_OFF;
467 mutex_unlock(&wl->mutex);
473 static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
475 struct wl1271 *wl = hw->priv;
477 skb_queue_tail(&wl->tx_queue, skb);
480 * The chip specific setup must run before the first TX packet -
481 * before that, the tx_work will not be initialized!
484 schedule_work(&wl->tx_work);
487 * The workqueue is slow to process the tx_queue and we need stop
488 * the queue here, otherwise the queue will get too long.
490 if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) {
491 ieee80211_stop_queues(wl->hw);
494 * FIXME: this is racy, the variable is not properly
495 * protected. Maybe fix this by removing the stupid
496 * variable altogether and checking the real queue state?
498 wl->tx_queue_stopped = true;
504 static int wl1271_op_start(struct ieee80211_hw *hw)
506 struct wl1271 *wl = hw->priv;
509 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
511 mutex_lock(&wl->mutex);
513 if (wl->state != WL1271_STATE_OFF) {
514 wl1271_error("cannot start because not in off state: %d",
520 ret = wl1271_chip_wakeup(wl);
524 ret = wl1271_boot(wl);
528 ret = wl1271_hw_init(wl);
532 wl->state = WL1271_STATE_ON;
534 wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
538 wl1271_power_off(wl);
540 mutex_unlock(&wl->mutex);
545 static void wl1271_op_stop(struct ieee80211_hw *hw)
547 struct wl1271 *wl = hw->priv;
552 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
554 mutex_lock(&wl->mutex);
556 WARN_ON(wl->state != WL1271_STATE_ON);
559 mutex_unlock(&wl->mutex);
560 ieee80211_scan_completed(wl->hw, true);
561 mutex_lock(&wl->mutex);
562 wl->scanning = false;
565 wl->state = WL1271_STATE_OFF;
567 wl1271_disable_interrupts(wl);
569 mutex_unlock(&wl->mutex);
571 cancel_work_sync(&wl->irq_work);
572 cancel_work_sync(&wl->tx_work);
573 cancel_work_sync(&wl->filter_work);
575 mutex_lock(&wl->mutex);
577 /* let's notify MAC80211 about the remaining pending TX frames */
579 wl1271_power_off(wl);
581 memset(wl->bssid, 0, ETH_ALEN);
582 memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
585 wl->bss_type = MAX_BSS_TYPE;
590 wl->tx_queue_stopped = false;
591 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
592 wl->tx_blocks_available = 0;
593 wl->tx_results_count = 0;
594 wl->tx_packets_count = 0;
595 wl->tx_security_last_seq = 0;
596 wl->tx_security_seq_16 = 0;
597 wl->tx_security_seq_32 = 0;
599 wl->session_counter = 0;
600 for (i = 0; i < NUM_TX_QUEUES; i++)
601 wl->tx_blocks_freed[i] = 0;
603 wl1271_debugfs_reset(wl);
604 mutex_unlock(&wl->mutex);
607 static int wl1271_op_add_interface(struct ieee80211_hw *hw,
608 struct ieee80211_if_init_conf *conf)
610 struct wl1271 *wl = hw->priv;
613 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
614 conf->type, conf->mac_addr);
616 mutex_lock(&wl->mutex);
618 switch (conf->type) {
619 case NL80211_IFTYPE_STATION:
620 wl->bss_type = BSS_TYPE_STA_BSS;
622 case NL80211_IFTYPE_ADHOC:
623 wl->bss_type = BSS_TYPE_IBSS;
630 /* FIXME: what if conf->mac_addr changes? */
633 mutex_unlock(&wl->mutex);
637 static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
638 struct ieee80211_if_init_conf *conf)
640 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
644 static int wl1271_op_config_interface(struct ieee80211_hw *hw,
645 struct ieee80211_vif *vif,
646 struct ieee80211_if_conf *conf)
648 struct wl1271 *wl = hw->priv;
649 struct sk_buff *beacon;
652 wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %pM",
654 wl1271_dump_ascii(DEBUG_MAC80211, "ssid: ", conf->ssid,
657 mutex_lock(&wl->mutex);
659 ret = wl1271_ps_elp_wakeup(wl, false);
663 memcpy(wl->bssid, conf->bssid, ETH_ALEN);
665 ret = wl1271_cmd_build_null_data(wl);
669 wl->ssid_len = conf->ssid_len;
671 memcpy(wl->ssid, conf->ssid, wl->ssid_len);
673 if (wl->bss_type != BSS_TYPE_IBSS) {
674 /* FIXME: replace the magic numbers with proper definitions */
675 ret = wl1271_cmd_join(wl, wl->bss_type, 5, 100, 1);
680 if (conf->changed & IEEE80211_IFCC_BEACON) {
681 beacon = ieee80211_beacon_get(hw, vif);
682 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
683 beacon->data, beacon->len);
686 dev_kfree_skb(beacon);
690 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE,
691 beacon->data, beacon->len);
693 dev_kfree_skb(beacon);
698 /* FIXME: replace the magic numbers with proper definitions */
699 ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
706 wl1271_ps_elp_sleep(wl);
709 mutex_unlock(&wl->mutex);
715 static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
717 struct wl1271 *wl = hw->priv;
718 struct ieee80211_conf *conf = &hw->conf;
719 int channel, ret = 0;
721 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
723 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
725 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
728 mutex_lock(&wl->mutex);
730 ret = wl1271_ps_elp_wakeup(wl, false);
734 if (channel != wl->channel) {
735 u8 old_channel = wl->channel;
736 wl->channel = channel;
738 /* FIXME: use beacon interval provided by mac80211 */
739 ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
741 wl->channel = old_channel;
746 ret = wl1271_cmd_build_null_data(wl);
750 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
751 wl1271_info("psm enabled");
753 wl->psm_requested = true;
756 * We enter PSM only if we're already associated.
757 * If we're not, we'll enter it when joining an SSID,
758 * through the bss_info_changed() hook.
760 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
761 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
763 wl1271_info("psm disabled");
765 wl->psm_requested = false;
768 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE);
771 if (conf->power_level != wl->power_level) {
772 ret = wl1271_acx_tx_power(wl, conf->power_level);
776 wl->power_level = conf->power_level;
780 wl1271_ps_elp_sleep(wl);
783 mutex_unlock(&wl->mutex);
788 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
791 FIF_BCN_PRBRESP_PROMISC | \
795 static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
796 unsigned int changed,
797 unsigned int *total,u64 multicast)
799 struct wl1271 *wl = hw->priv;
801 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
803 *total &= WL1271_SUPPORTED_FILTERS;
804 changed &= WL1271_SUPPORTED_FILTERS;
809 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
810 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
811 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
814 * FIXME: workqueues need to be properly cancelled on stop(), for
815 * now let's just disable changing the filter settings. They will
816 * be updated any on config().
818 /* schedule_work(&wl->filter_work); */
821 static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
822 struct ieee80211_vif *vif,
823 struct ieee80211_sta *sta,
824 struct ieee80211_key_conf *key_conf)
826 struct wl1271 *wl = hw->priv;
833 static const u8 bcast_addr[ETH_ALEN] =
834 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
836 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
838 addr = sta ? sta->addr : bcast_addr;
840 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
841 wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
842 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
843 key_conf->alg, key_conf->keyidx,
844 key_conf->keylen, key_conf->flags);
845 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
847 if (is_zero_ether_addr(addr)) {
848 /* We dont support TX only encryption */
853 mutex_lock(&wl->mutex);
855 ret = wl1271_ps_elp_wakeup(wl, false);
859 switch (key_conf->alg) {
863 key_conf->hw_key_idx = key_conf->keyidx;
868 key_conf->hw_key_idx = key_conf->keyidx;
869 tx_seq_32 = wl->tx_security_seq_32;
870 tx_seq_16 = wl->tx_security_seq_16;
875 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
876 tx_seq_32 = wl->tx_security_seq_32;
877 tx_seq_16 = wl->tx_security_seq_16;
880 wl1271_error("Unknown key algo 0x%x", key_conf->alg);
888 ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
889 key_conf->keyidx, key_type,
890 key_conf->keylen, key_conf->key,
891 addr, tx_seq_32, tx_seq_16);
893 wl1271_error("Could not add or replace key");
899 ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
900 key_conf->keyidx, key_type,
901 key_conf->keylen, key_conf->key,
904 wl1271_error("Could not remove key");
910 wl1271_error("Unsupported key cmd 0x%x", cmd);
918 wl1271_ps_elp_sleep(wl);
921 mutex_unlock(&wl->mutex);
927 static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
928 struct cfg80211_scan_request *req)
930 struct wl1271 *wl = hw->priv;
935 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
938 ssid = req->ssids[0].ssid;
939 ssid_len = req->ssids[0].ssid_len;
942 mutex_lock(&wl->mutex);
944 ret = wl1271_ps_elp_wakeup(wl, false);
948 ret = wl1271_cmd_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
950 wl1271_ps_elp_sleep(wl);
953 mutex_unlock(&wl->mutex);
958 static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
960 struct wl1271 *wl = hw->priv;
963 mutex_lock(&wl->mutex);
965 ret = wl1271_ps_elp_wakeup(wl, false);
969 ret = wl1271_acx_rts_threshold(wl, (u16) value);
971 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
973 wl1271_ps_elp_sleep(wl);
976 mutex_unlock(&wl->mutex);
981 static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
982 struct ieee80211_vif *vif,
983 struct ieee80211_bss_conf *bss_conf,
986 enum wl1271_cmd_ps_mode mode;
987 struct wl1271 *wl = hw->priv;
990 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
992 mutex_lock(&wl->mutex);
994 ret = wl1271_ps_elp_wakeup(wl, false);
998 if (changed & BSS_CHANGED_ASSOC) {
999 if (bss_conf->assoc) {
1000 wl->aid = bss_conf->aid;
1002 ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
1006 ret = wl1271_acx_aid(wl, wl->aid);
1010 /* If we want to go in PSM but we're not there yet */
1011 if (wl->psm_requested && !wl->psm) {
1012 mode = STATION_POWER_SAVE_MODE;
1013 ret = wl1271_ps_set_mode(wl, mode);
1019 if (changed & BSS_CHANGED_ERP_SLOT) {
1020 if (bss_conf->use_short_slot)
1021 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
1023 ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
1025 wl1271_warning("Set slot time failed %d", ret);
1030 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1031 if (bss_conf->use_short_preamble)
1032 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
1034 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
1037 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1038 if (bss_conf->use_cts_prot)
1039 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
1041 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1043 wl1271_warning("Set ctsprotect failed %d", ret);
1049 wl1271_ps_elp_sleep(wl);
1052 mutex_unlock(&wl->mutex);
1056 /* can't be const, mac80211 writes to this */
1057 static struct ieee80211_rate wl1271_rates[] = {
1060 .hw_value_short = 0x1, },
1063 .hw_value_short = 0x2,
1064 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1067 .hw_value_short = 0x4,
1068 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1071 .hw_value_short = 0x20,
1072 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1075 .hw_value_short = 0x8, },
1078 .hw_value_short = 0x10, },
1081 .hw_value_short = 0x40, },
1084 .hw_value_short = 0x80, },
1087 .hw_value_short = 0x200, },
1090 .hw_value_short = 0x400, },
1093 .hw_value_short = 0x800, },
1096 .hw_value_short = 0x1000, },
1099 /* can't be const, mac80211 writes to this */
1100 static struct ieee80211_channel wl1271_channels[] = {
1101 { .hw_value = 1, .center_freq = 2412},
1102 { .hw_value = 2, .center_freq = 2417},
1103 { .hw_value = 3, .center_freq = 2422},
1104 { .hw_value = 4, .center_freq = 2427},
1105 { .hw_value = 5, .center_freq = 2432},
1106 { .hw_value = 6, .center_freq = 2437},
1107 { .hw_value = 7, .center_freq = 2442},
1108 { .hw_value = 8, .center_freq = 2447},
1109 { .hw_value = 9, .center_freq = 2452},
1110 { .hw_value = 10, .center_freq = 2457},
1111 { .hw_value = 11, .center_freq = 2462},
1112 { .hw_value = 12, .center_freq = 2467},
1113 { .hw_value = 13, .center_freq = 2472},
1116 /* can't be const, mac80211 writes to this */
1117 static struct ieee80211_supported_band wl1271_band_2ghz = {
1118 .channels = wl1271_channels,
1119 .n_channels = ARRAY_SIZE(wl1271_channels),
1120 .bitrates = wl1271_rates,
1121 .n_bitrates = ARRAY_SIZE(wl1271_rates),
1124 static const struct ieee80211_ops wl1271_ops = {
1125 .start = wl1271_op_start,
1126 .stop = wl1271_op_stop,
1127 .add_interface = wl1271_op_add_interface,
1128 .remove_interface = wl1271_op_remove_interface,
1129 .config = wl1271_op_config,
1130 /* .config_interface = wl1271_op_config_interface, */
1131 .configure_filter = wl1271_op_configure_filter,
1133 .set_key = wl1271_op_set_key,
1134 .hw_scan = wl1271_op_hw_scan,
1135 .bss_info_changed = wl1271_op_bss_info_changed,
1136 .set_rts_threshold = wl1271_op_set_rts_threshold,
1139 static int wl1271_register_hw(struct wl1271 *wl)
1143 if (wl->mac80211_registered)
1146 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1148 ret = ieee80211_register_hw(wl->hw);
1150 wl1271_error("unable to register mac80211 hw: %d", ret);
1154 wl->mac80211_registered = true;
1156 wl1271_notice("loaded");
1161 static int wl1271_init_ieee80211(struct wl1271 *wl)
1164 * The tx descriptor buffer and the TKIP space.
1166 * FIXME: add correct 1271 descriptor size
1168 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE;
1171 /* FIXME: find a proper value */
1172 wl->hw->channel_change_time = 10000;
1174 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1175 IEEE80211_HW_NOISE_DBM;
1177 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1178 wl->hw->wiphy->max_scan_ssids = 1;
1179 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
1181 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1186 static void wl1271_device_release(struct device *dev)
1191 static struct platform_device wl1271_device = {
1195 /* device model insists to have a release function */
1197 .release = wl1271_device_release,
1201 #define WL1271_DEFAULT_CHANNEL 0
1202 static int __devinit wl1271_probe(struct spi_device *spi)
1204 struct wl12xx_platform_data *pdata;
1205 struct ieee80211_hw *hw;
1208 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1210 pdata = spi->dev.platform_data;
1212 wl1271_error("no platform data");
1216 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
1218 wl1271_error("could not alloc ieee80211_hw");
1223 memset(wl, 0, sizeof(*wl));
1226 dev_set_drvdata(&spi->dev, wl);
1229 skb_queue_head_init(&wl->tx_queue);
1231 INIT_WORK(&wl->filter_work, wl1271_filter_work);
1232 wl->channel = WL1271_DEFAULT_CHANNEL;
1233 wl->scanning = false;
1234 wl->default_key = 0;
1237 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
1238 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
1241 wl->psm_requested = false;
1242 wl->tx_queue_stopped = false;
1243 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1245 /* We use the default power on sleep time until we know which chip
1247 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1248 wl->tx_frames[i] = NULL;
1250 spin_lock_init(&wl->wl_lock);
1253 * In case our MAC address is not correctly set,
1254 * we use a random but Nokia MAC.
1256 memcpy(wl->mac_addr, nokia_oui, 3);
1257 get_random_bytes(wl->mac_addr + 3, 3);
1259 wl->state = WL1271_STATE_OFF;
1260 mutex_init(&wl->mutex);
1262 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1263 if (!wl->rx_descriptor) {
1264 wl1271_error("could not allocate memory for rx descriptor");
1269 /* This is the only SPI value that we need to set here, the rest
1270 * comes from the board-peripherals file */
1271 spi->bits_per_word = 32;
1273 ret = spi_setup(spi);
1275 wl1271_error("spi_setup failed");
1279 wl->set_power = pdata->set_power;
1280 if (!wl->set_power) {
1281 wl1271_error("set power function missing in platform data");
1288 wl1271_error("irq missing in platform data");
1293 ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
1295 wl1271_error("request_irq() failed: %d", ret);
1299 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
1301 disable_irq(wl->irq);
1303 ret = platform_device_register(&wl1271_device);
1305 wl1271_error("couldn't register platform device");
1308 dev_set_drvdata(&wl1271_device.dev, wl);
1310 ret = wl1271_init_ieee80211(wl);
1314 ret = wl1271_register_hw(wl);
1318 wl1271_debugfs_init(wl);
1320 wl1271_notice("initialized");
1325 platform_device_unregister(&wl1271_device);
1328 free_irq(wl->irq, wl);
1331 kfree(wl->rx_descriptor);
1332 wl->rx_descriptor = NULL;
1334 ieee80211_free_hw(hw);
1339 static int __devexit wl1271_remove(struct spi_device *spi)
1341 struct wl1271 *wl = dev_get_drvdata(&spi->dev);
1343 ieee80211_unregister_hw(wl->hw);
1345 wl1271_debugfs_exit(wl);
1346 platform_device_unregister(&wl1271_device);
1347 free_irq(wl->irq, wl);
1348 kfree(wl->target_mem_map);
1354 kfree(wl->rx_descriptor);
1355 wl->rx_descriptor = NULL;
1357 kfree(wl->fw_status);
1358 kfree(wl->tx_res_if);
1360 ieee80211_free_hw(wl->hw);
1366 static struct spi_driver wl1271_spi_driver = {
1369 .bus = &spi_bus_type,
1370 .owner = THIS_MODULE,
1373 .probe = wl1271_probe,
1374 .remove = __devexit_p(wl1271_remove),
1377 static int __init wl1271_init(void)
1381 ret = spi_register_driver(&wl1271_spi_driver);
1383 wl1271_error("failed to register spi driver: %d", ret);
1391 static void __exit wl1271_exit(void)
1393 spi_unregister_driver(&wl1271_spi_driver);
1395 wl1271_notice("unloaded");
1398 module_init(wl1271_init);
1399 module_exit(wl1271_exit);
1401 MODULE_LICENSE("GPL");
1402 MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");