2 * This file is part of wl12xx
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Kalle Valo <kalle.valo@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/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>
35 #include "wl12xx_80211.h"
46 static void wl12xx_disable_interrupts(struct wl12xx *wl)
51 static void wl12xx_power_off(struct wl12xx *wl)
56 static void wl12xx_power_on(struct wl12xx *wl)
61 static irqreturn_t wl12xx_irq(int irq, void *cookie)
65 wl12xx_debug(DEBUG_IRQ, "IRQ");
69 schedule_work(&wl->irq_work);
74 static int wl12xx_fetch_firmware(struct wl12xx *wl)
76 const struct firmware *fw;
79 ret = request_firmware(&fw, wl->chip.fw_filename, &wl->spi->dev);
82 wl12xx_error("could not get firmware: %d", ret);
87 wl12xx_error("firmware size is not multiple of 32 bits: %zu",
93 wl->fw_len = fw->size;
94 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
97 wl12xx_error("could not allocate memory for the firmware");
102 memcpy(wl->fw, fw->data, wl->fw_len);
107 release_firmware(fw);
112 static int wl12xx_fetch_nvs(struct wl12xx *wl)
114 const struct firmware *fw;
117 ret = request_firmware(&fw, wl->chip.nvs_filename, &wl->spi->dev);
120 wl12xx_error("could not get nvs file: %d", ret);
125 wl12xx_error("nvs size is not multiple of 32 bits: %zu",
131 wl->nvs_len = fw->size;
132 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
135 wl12xx_error("could not allocate memory for the nvs file");
140 memcpy(wl->nvs, fw->data, wl->nvs_len);
145 release_firmware(fw);
150 static void wl12xx_fw_wakeup(struct wl12xx *wl)
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);
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);
165 static int wl12xx_chip_wakeup(struct wl12xx *wl)
170 msleep(wl->chip.power_on_sleep);
171 wl12xx_spi_reset(wl);
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,
180 REGISTERS_DOWN_SIZE);
182 /* ELP module wake up */
183 wl12xx_fw_wakeup(wl);
185 /* whal_FwCtrl_BootSm() */
187 /* 0. read chip id from CHIP_ID */
188 wl->chip.id = wl12xx_reg_read32(wl, CHIP_ID_B);
190 /* 1. check if chip id is valid */
192 switch (wl->chip.id) {
193 case CHIP_ID_1251_PG12:
194 wl12xx_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
200 case CHIP_ID_1271_PG10:
201 case CHIP_ID_1251_PG10:
202 case CHIP_ID_1251_PG11:
204 wl12xx_error("unsupported chip id: 0x%x", wl->chip.id);
209 if (wl->fw == NULL) {
210 ret = wl12xx_fetch_firmware(wl);
215 /* No NVS from netlink, try to get it from the filesystem */
216 if (wl->nvs == NULL) {
217 ret = wl12xx_fetch_nvs(wl);
226 static void wl12xx_filter_work(struct work_struct *work)
229 container_of(work, struct wl12xx, filter_work);
232 mutex_lock(&wl->mutex);
234 if (wl->state == WL12XX_STATE_OFF)
237 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
242 mutex_unlock(&wl->mutex);
245 int wl12xx_plt_start(struct wl12xx *wl)
249 wl12xx_notice("power up");
251 if (wl->state != WL12XX_STATE_OFF) {
252 wl12xx_error("cannot go into PLT state because not "
253 "in off state: %d", wl->state);
257 wl->state = WL12XX_STATE_PLT;
259 ret = wl12xx_chip_wakeup(wl);
263 ret = wl->chip.op_boot(wl);
267 wl12xx_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
269 ret = wl->chip.op_plt_init(wl);
276 int wl12xx_plt_stop(struct wl12xx *wl)
278 wl12xx_notice("power down");
280 if (wl->state != WL12XX_STATE_PLT) {
281 wl12xx_error("cannot power down because not in PLT "
282 "state: %d", wl->state);
286 wl12xx_disable_interrupts(wl);
287 wl12xx_power_off(wl);
289 wl->state = WL12XX_STATE_OFF;
295 static int wl12xx_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
297 struct wl12xx *wl = hw->priv;
299 skb_queue_tail(&wl->tx_queue, skb);
301 schedule_work(&wl->tx_work);
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.
307 if (skb_queue_len(&wl->tx_queue) >= WL12XX_TX_QUEUE_MAX_LENGTH) {
308 ieee80211_stop_queues(wl->hw);
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?
315 wl->tx_queue_stopped = true;
321 static int wl12xx_op_start(struct ieee80211_hw *hw)
323 struct wl12xx *wl = hw->priv;
326 wl12xx_debug(DEBUG_MAC80211, "mac80211 start");
328 mutex_lock(&wl->mutex);
330 if (wl->state != WL12XX_STATE_OFF) {
331 wl12xx_error("cannot start because not in off state: %d",
337 ret = wl12xx_chip_wakeup(wl);
341 ret = wl->chip.op_boot(wl);
345 ret = wl->chip.op_hw_init(wl);
349 ret = wl12xx_acx_station_id(wl);
353 wl->state = WL12XX_STATE_ON;
355 wl12xx_info("firmware booted (%s)", wl->chip.fw_ver);
359 wl12xx_power_off(wl);
361 mutex_unlock(&wl->mutex);
366 static void wl12xx_op_stop(struct ieee80211_hw *hw)
368 struct wl12xx *wl = hw->priv;
372 wl12xx_debug(DEBUG_MAC80211, "mac80211 stop");
374 mutex_lock(&wl->mutex);
376 WARN_ON(wl->state != WL12XX_STATE_ON);
379 mutex_unlock(&wl->mutex);
380 ieee80211_scan_completed(wl->hw, true);
381 mutex_lock(&wl->mutex);
382 wl->scanning = false;
385 wl->state = WL12XX_STATE_OFF;
387 wl12xx_disable_interrupts(wl);
389 mutex_unlock(&wl->mutex);
391 cancel_work_sync(&wl->irq_work);
392 cancel_work_sync(&wl->tx_work);
393 cancel_work_sync(&wl->filter_work);
395 mutex_lock(&wl->mutex);
397 /* let's notify MAC80211 about the remaining pending TX frames */
400 wl12xx_power_off(wl);
402 memset(wl->bssid, 0, ETH_ALEN);
404 wl->bss_type = MAX_BSS_TYPE;
406 wl->data_in_count = 0;
409 wl->rx_current_buffer = 0;
411 wl->next_tx_complete = 0;
414 wl->tx_queue_stopped = false;
415 wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
417 wl12xx_debugfs_reset(wl);
419 mutex_unlock(&wl->mutex);
422 static int wl12xx_op_add_interface(struct ieee80211_hw *hw,
423 struct ieee80211_if_init_conf *conf)
425 struct wl12xx *wl = hw->priv;
426 DECLARE_MAC_BUF(mac);
429 wl12xx_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %s",
430 conf->type, print_mac(mac, conf->mac_addr));
432 mutex_lock(&wl->mutex);
434 switch (conf->type) {
435 case NL80211_IFTYPE_STATION:
436 wl->bss_type = BSS_TYPE_STA_BSS;
438 case NL80211_IFTYPE_ADHOC:
439 wl->bss_type = BSS_TYPE_IBSS;
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);
455 mutex_unlock(&wl->mutex);
459 static void wl12xx_op_remove_interface(struct ieee80211_hw *hw,
460 struct ieee80211_if_init_conf *conf)
462 wl12xx_debug(DEBUG_MAC80211, "mac80211 remove interface");
465 static int wl12xx_build_null_data(struct wl12xx *wl)
467 struct wl12xx_null_data_template template;
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);
473 memset(template.header.da, 0xff, ETH_ALEN);
474 memset(template.header.bssid, 0xff, ETH_ALEN);
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);
481 return wl12xx_cmd_template_set(wl, CMD_NULL_DATA, &template,
486 static int wl12xx_build_ps_poll(struct wl12xx *wl, u16 aid)
488 struct wl12xx_ps_poll_template template;
490 memcpy(template.bssid, wl->bssid, ETH_ALEN);
491 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
493 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
495 return wl12xx_cmd_template_set(wl, CMD_PS_POLL, &template,
500 static int wl12xx_op_config(struct ieee80211_hw *hw, u32 changed)
502 struct wl12xx *wl = hw->priv;
503 struct ieee80211_conf *conf = &hw->conf;
504 int channel, ret = 0;
506 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
508 wl12xx_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
510 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
513 mutex_lock(&wl->mutex);
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);
521 wl->channel = channel;
524 ret = wl12xx_build_null_data(wl);
528 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
529 wl12xx_info("psm enabled");
531 wl->psm_requested = true;
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.
538 ret = wl12xx_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
539 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
541 wl12xx_info("psm disabled");
543 wl->psm_requested = false;
546 ret = wl12xx_ps_set_mode(wl, STATION_ACTIVE_MODE);
549 if (conf->power_level != wl->power_level) {
550 ret = wl12xx_acx_tx_power(wl, conf->power_level);
554 wl->power_level = conf->power_level;
558 mutex_unlock(&wl->mutex);
562 #define WL12XX_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
565 FIF_BCN_PRBRESP_PROMISC | \
569 static void wl12xx_op_configure_filter(struct ieee80211_hw *hw,
570 unsigned int changed,
573 struct dev_addr_list *mc_list)
575 struct wl12xx *wl = hw->priv;
577 wl12xx_debug(DEBUG_MAC80211, "mac80211 configure filter");
579 *total &= WL12XX_SUPPORTED_FILTERS;
580 changed &= WL12XX_SUPPORTED_FILTERS;
583 /* no filters which we support changed */
586 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
588 wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
589 wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
591 if (*total & FIF_PROMISC_IN_BSS) {
592 wl->rx_config |= CFG_BSSID_FILTER_EN;
593 wl->rx_config |= CFG_RX_ALL_GOOD;
595 if (*total & FIF_ALLMULTI)
597 * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
598 * all multicast frames
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;
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;
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().
617 /* schedule_work(&wl->filter_work); */
621 static int wl12xx_set_key_type(struct wl12xx *wl, struct acx_set_key *key,
622 enum set_key_cmd cmd,
623 struct ieee80211_key_conf *mac80211_key,
626 switch (mac80211_key->alg) {
628 if (is_broadcast_ether_addr(addr))
629 key->key_type = KEY_WEP_DEFAULT;
631 key->key_type = KEY_WEP_ADDR;
633 mac80211_key->hw_key_idx = mac80211_key->keyidx;
636 if (is_broadcast_ether_addr(addr))
637 key->key_type = KEY_TKIP_MIC_GROUP;
639 key->key_type = KEY_TKIP_MIC_PAIRWISE;
641 mac80211_key->hw_key_idx = mac80211_key->keyidx;
644 if (is_broadcast_ether_addr(addr))
645 key->key_type = KEY_AES_GROUP;
647 key->key_type = KEY_AES_PAIRWISE;
648 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
651 wl12xx_error("Unknown key algo 0x%x", mac80211_key->alg);
658 static int wl12xx_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
659 struct ieee80211_vif *vif,
660 struct ieee80211_sta *sta,
661 struct ieee80211_key_conf *key)
663 struct wl12xx *wl = hw->priv;
664 struct acx_set_key wl_key;
668 static const u8 bcast_addr[ETH_ALEN] =
669 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
671 wl12xx_debug(DEBUG_MAC80211, "mac80211 set key");
673 memset(&wl_key, 0, sizeof(wl_key));
675 addr = sta ? sta->addr : bcast_addr;
677 wl12xx_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
678 wl12xx_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
679 wl12xx_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
680 key->alg, key->keyidx, key->keylen, key->flags);
681 wl12xx_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
683 mutex_lock(&wl->mutex);
687 wl_key.key_action = KEY_ADD_OR_REPLACE;
690 wl_key.key_action = KEY_REMOVE;
693 wl12xx_error("Unsupported key cmd 0x%x", cmd);
697 ret = wl12xx_set_key_type(wl, &wl_key, cmd, key, addr);
699 wl12xx_error("Set KEY type failed");
703 if (wl_key.key_type != KEY_WEP_DEFAULT)
704 memcpy(wl_key.addr, addr, ETH_ALEN);
706 if ((wl_key.key_type == KEY_TKIP_MIC_GROUP) ||
707 (wl_key.key_type == KEY_TKIP_MIC_PAIRWISE)) {
709 * We get the key in the following form:
710 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
711 * but the target is expecting:
712 * TKIP - RX MIC - TX MIC
714 memcpy(wl_key.key, key->key, 16);
715 memcpy(wl_key.key + 16, key->key + 24, 8);
716 memcpy(wl_key.key + 24, key->key + 16, 8);
719 memcpy(wl_key.key, key->key, key->keylen);
721 wl_key.key_size = key->keylen;
723 wl_key.id = key->keyidx;
724 wl_key.ssid_profile = 0;
726 wl12xx_dump(DEBUG_CRYPT, "TARGET KEY: ", &wl_key, sizeof(wl_key));
728 if (wl12xx_cmd_send(wl, CMD_SET_KEYS, &wl_key, sizeof(wl_key)) < 0) {
729 wl12xx_error("Set KEY failed");
735 mutex_unlock(&wl->mutex);
739 static int wl12xx_build_basic_rates(char *rates)
743 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
744 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
745 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
746 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
751 static int wl12xx_build_extended_rates(char *rates)
755 rates[index++] = IEEE80211_OFDM_RATE_6MB;
756 rates[index++] = IEEE80211_OFDM_RATE_9MB;
757 rates[index++] = IEEE80211_OFDM_RATE_12MB;
758 rates[index++] = IEEE80211_OFDM_RATE_18MB;
759 rates[index++] = IEEE80211_OFDM_RATE_24MB;
760 rates[index++] = IEEE80211_OFDM_RATE_36MB;
761 rates[index++] = IEEE80211_OFDM_RATE_48MB;
762 rates[index++] = IEEE80211_OFDM_RATE_54MB;
768 static int wl12xx_build_probe_req(struct wl12xx *wl, u8 *ssid, size_t ssid_len)
770 struct wl12xx_probe_req_template template;
771 struct wl12xx_ie_rates *rates;
775 ptr = (char *)&template;
776 size = sizeof(struct ieee80211_header);
778 memset(template.header.da, 0xff, ETH_ALEN);
779 memset(template.header.bssid, 0xff, ETH_ALEN);
780 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
781 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
785 template.ssid.header.id = WLAN_EID_SSID;
786 template.ssid.header.len = ssid_len;
787 if (ssid_len && ssid)
788 memcpy(template.ssid.ssid, ssid, ssid_len);
789 size += sizeof(struct wl12xx_ie_header) + ssid_len;
793 rates = (struct wl12xx_ie_rates *)ptr;
794 rates->header.id = WLAN_EID_SUPP_RATES;
795 rates->header.len = wl12xx_build_basic_rates(rates->rates);
796 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
797 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
800 rates = (struct wl12xx_ie_rates *)ptr;
801 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
802 rates->header.len = wl12xx_build_extended_rates(rates->rates);
803 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
805 wl12xx_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
807 return wl12xx_cmd_template_set(wl, CMD_PROBE_REQ, &template,
811 static int wl12xx_hw_scan(struct wl12xx *wl, u8 *ssid, size_t len,
812 u8 active_scan, u8 high_prio, u8 num_channels,
817 u16 scan_options = 0;
818 struct cmd_scan *params;
819 struct wl12xx_command *cmd_answer;
824 params = kzalloc(sizeof(*params), GFP_KERNEL);
828 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
829 params->params.rx_filter_options =
830 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
832 /* High priority scan */
834 scan_options |= SCAN_PASSIVE;
836 scan_options |= SCAN_PRIORITY_HIGH;
837 params->params.scan_options = scan_options;
839 params->params.num_channels = num_channels;
840 params->params.num_probe_requests = probe_requests;
841 params->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
842 params->params.tid_trigger = 0;
844 for (i = 0; i < num_channels; i++) {
845 params->channels[i].min_duration = cpu_to_le32(30000);
846 params->channels[i].max_duration = cpu_to_le32(60000);
847 memset(¶ms->channels[i].bssid_lsb, 0xff, 4);
848 memset(¶ms->channels[i].bssid_msb, 0xff, 2);
849 params->channels[i].early_termination = 0;
850 params->channels[i].tx_power_att = 0;
851 params->channels[i].channel = i + 1;
852 memset(params->channels[i].pad, 0, 3);
855 for (i = num_channels; i < SCAN_MAX_NUM_OF_CHANNELS; i++)
856 memset(¶ms->channels[i], 0,
857 sizeof(struct basic_scan_channel_parameters));
860 params->params.ssid_len = len;
861 memcpy(params->params.ssid, ssid, len);
863 params->params.ssid_len = 0;
864 memset(params->params.ssid, 0, 32);
867 ret = wl12xx_build_probe_req(wl, ssid, len);
869 wl12xx_error("PROBE request template failed");
873 ret = wl12xx_cmd_send(wl, CMD_TRIGGER_SCAN_TO, &split_scan,
876 wl12xx_error("Split SCAN failed");
880 wl12xx_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
884 ret = wl12xx_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
886 wl12xx_error("SCAN failed");
888 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
890 cmd_answer = (struct wl12xx_command *) params;
891 if (cmd_answer->status != CMD_STATUS_SUCCESS) {
892 wl12xx_error("TEST command answer error: %d",
894 wl->scanning = false;
905 static int wl12xx_op_hw_scan(struct ieee80211_hw *hw,
906 struct cfg80211_scan_request *req)
908 struct wl12xx *wl = hw->priv;
913 wl12xx_debug(DEBUG_MAC80211, "mac80211 hw scan");
916 ssid = req->ssids[0].ssid;
917 ssid_len = req->ssids[0].ssid_len;
920 mutex_lock(&wl->mutex);
921 ret = wl12xx_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
922 mutex_unlock(&wl->mutex);
927 static int wl12xx_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
929 struct wl12xx *wl = hw->priv;
932 ret = wl12xx_acx_rts_threshold(wl, (u16) value);
935 wl12xx_warning("wl12xx_op_set_rts_threshold failed: %d", ret);
940 static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw,
941 struct ieee80211_vif *vif,
942 struct ieee80211_bss_conf *bss_conf,
945 enum acx_ps_mode mode;
946 struct wl12xx *wl = hw->priv;
947 struct sk_buff *beacon;
950 wl12xx_debug(DEBUG_MAC80211, "mac80211 bss info changed");
952 mutex_lock(&wl->mutex);
954 if (changed & BSS_CHANGED_ASSOC) {
955 if (bss_conf->assoc) {
956 wl->aid = bss_conf->aid;
958 ret = wl12xx_build_ps_poll(wl, wl->aid);
962 ret = wl12xx_acx_aid(wl, wl->aid);
966 /* If we want to go in PSM but we're not there yet */
967 if (wl->psm_requested && !wl->psm) {
968 mode = STATION_POWER_SAVE_MODE;
969 ret = wl12xx_ps_set_mode(wl, mode);
975 if (changed & BSS_CHANGED_ERP_SLOT) {
976 if (bss_conf->use_short_slot)
977 ret = wl12xx_acx_slot(wl, SLOT_TIME_SHORT);
979 ret = wl12xx_acx_slot(wl, SLOT_TIME_LONG);
981 wl12xx_warning("Set slot time failed %d", ret);
986 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
987 if (bss_conf->use_short_preamble)
988 wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
990 wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
993 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
994 if (bss_conf->use_cts_prot)
995 ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_ENABLE);
997 ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_DISABLE);
999 wl12xx_warning("Set ctsprotect failed %d", ret);
1004 if (changed & BSS_CHANGED_BSSID) {
1005 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1007 ret = wl12xx_build_null_data(wl);
1011 if (wl->bss_type != BSS_TYPE_IBSS) {
1012 ret = wl12xx_cmd_join(wl, wl->bss_type, 5, 100, 1);
1018 if (changed & BSS_CHANGED_BEACON) {
1019 beacon = ieee80211_beacon_get(hw, vif);
1020 ret = wl12xx_cmd_template_set(wl, CMD_BEACON, beacon->data,
1024 dev_kfree_skb(beacon);
1028 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
1031 dev_kfree_skb(beacon);
1036 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
1043 mutex_unlock(&wl->mutex);
1047 /* can't be const, mac80211 writes to this */
1048 static struct ieee80211_rate wl12xx_rates[] = {
1051 .hw_value_short = 0x1, },
1054 .hw_value_short = 0x2,
1055 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1058 .hw_value_short = 0x4,
1059 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1062 .hw_value_short = 0x20,
1063 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1066 .hw_value_short = 0x8, },
1069 .hw_value_short = 0x10, },
1072 .hw_value_short = 0x40, },
1075 .hw_value_short = 0x80, },
1078 .hw_value_short = 0x200, },
1081 .hw_value_short = 0x400, },
1084 .hw_value_short = 0x800, },
1087 .hw_value_short = 0x1000, },
1090 /* can't be const, mac80211 writes to this */
1091 static struct ieee80211_channel wl12xx_channels[] = {
1092 { .hw_value = 1, .center_freq = 2412},
1093 { .hw_value = 2, .center_freq = 2417},
1094 { .hw_value = 3, .center_freq = 2422},
1095 { .hw_value = 4, .center_freq = 2427},
1096 { .hw_value = 5, .center_freq = 2432},
1097 { .hw_value = 6, .center_freq = 2437},
1098 { .hw_value = 7, .center_freq = 2442},
1099 { .hw_value = 8, .center_freq = 2447},
1100 { .hw_value = 9, .center_freq = 2452},
1101 { .hw_value = 10, .center_freq = 2457},
1102 { .hw_value = 11, .center_freq = 2462},
1103 { .hw_value = 12, .center_freq = 2467},
1104 { .hw_value = 13, .center_freq = 2472},
1107 /* can't be const, mac80211 writes to this */
1108 static struct ieee80211_supported_band wl12xx_band_2ghz = {
1109 .channels = wl12xx_channels,
1110 .n_channels = ARRAY_SIZE(wl12xx_channels),
1111 .bitrates = wl12xx_rates,
1112 .n_bitrates = ARRAY_SIZE(wl12xx_rates),
1115 static const struct ieee80211_ops wl12xx_ops = {
1116 .start = wl12xx_op_start,
1117 .stop = wl12xx_op_stop,
1118 .add_interface = wl12xx_op_add_interface,
1119 .remove_interface = wl12xx_op_remove_interface,
1120 .config = wl12xx_op_config,
1121 .configure_filter = wl12xx_op_configure_filter,
1123 .set_key = wl12xx_op_set_key,
1124 .hw_scan = wl12xx_op_hw_scan,
1125 .bss_info_changed = wl12xx_op_bss_info_changed,
1126 .set_rts_threshold = wl12xx_op_set_rts_threshold,
1129 static int wl12xx_register_hw(struct wl12xx *wl)
1133 if (wl->mac80211_registered)
1136 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1138 ret = ieee80211_register_hw(wl->hw);
1140 wl12xx_error("unable to register mac80211 hw: %d", ret);
1144 wl->mac80211_registered = true;
1146 wl12xx_notice("loaded");
1151 static int wl12xx_init_ieee80211(struct wl12xx *wl)
1153 /* The tx descriptor buffer and the TKIP space */
1154 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1155 + WL12XX_TKIP_IV_SPACE;
1158 /* FIXME: find a proper value */
1159 wl->hw->channel_change_time = 10000;
1161 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1162 IEEE80211_HW_NOISE_DBM;
1164 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1165 wl->hw->wiphy->max_scan_ssids = 1;
1166 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl12xx_band_2ghz;
1168 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1173 #define WL12XX_DEFAULT_CHANNEL 1
1174 static int __devinit wl12xx_probe(struct spi_device *spi)
1176 struct wl12xx_platform_data *pdata;
1177 struct ieee80211_hw *hw;
1180 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1182 pdata = spi->dev.platform_data;
1184 wl12xx_error("no platform data");
1188 hw = ieee80211_alloc_hw(sizeof(*wl), &wl12xx_ops);
1190 wl12xx_error("could not alloc ieee80211_hw");
1195 memset(wl, 0, sizeof(*wl));
1198 dev_set_drvdata(&spi->dev, wl);
1201 wl->data_in_count = 0;
1203 skb_queue_head_init(&wl->tx_queue);
1205 INIT_WORK(&wl->tx_work, wl12xx_tx_work);
1206 INIT_WORK(&wl->filter_work, wl12xx_filter_work);
1207 wl->channel = WL12XX_DEFAULT_CHANNEL;
1208 wl->scanning = false;
1209 wl->default_key = 0;
1213 wl->rx_current_buffer = 0;
1215 wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
1216 wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
1219 wl->psm_requested = false;
1220 wl->tx_queue_stopped = false;
1221 wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
1223 /* We use the default power on sleep time until we know which chip
1225 wl->chip.power_on_sleep = WL12XX_DEFAULT_POWER_ON_SLEEP;
1227 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1228 wl->tx_frames[i] = NULL;
1230 wl->next_tx_complete = 0;
1233 * In case our MAC address is not correctly set,
1234 * we use a random but Nokia MAC.
1236 memcpy(wl->mac_addr, nokia_oui, 3);
1237 get_random_bytes(wl->mac_addr + 3, 3);
1239 wl->state = WL12XX_STATE_OFF;
1240 mutex_init(&wl->mutex);
1242 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1243 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1245 /* This is the only SPI value that we need to set here, the rest
1246 * comes from the board-peripherals file */
1247 spi->bits_per_word = 32;
1249 ret = spi_setup(spi);
1251 wl12xx_error("spi_setup failed");
1255 wl->set_power = pdata->set_power;
1256 if (!wl->set_power) {
1257 wl12xx_error("set power function missing in platform data");
1263 wl12xx_error("irq missing in platform data");
1267 ret = request_irq(wl->irq, wl12xx_irq, 0, DRIVER_NAME, wl);
1269 wl12xx_error("request_irq() failed: %d", ret);
1273 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
1275 disable_irq(wl->irq);
1277 ret = wl12xx_init_ieee80211(wl);
1281 ret = wl12xx_register_hw(wl);
1285 wl12xx_debugfs_init(wl);
1287 wl12xx_notice("initialized");
1292 free_irq(wl->irq, wl);
1295 ieee80211_free_hw(hw);
1300 static int __devexit wl12xx_remove(struct spi_device *spi)
1302 struct wl12xx *wl = dev_get_drvdata(&spi->dev);
1304 ieee80211_unregister_hw(wl->hw);
1306 wl12xx_debugfs_exit(wl);
1308 free_irq(wl->irq, wl);
1309 kfree(wl->target_mem_map);
1310 kfree(wl->data_path);
1315 ieee80211_free_hw(wl->hw);
1321 static struct spi_driver wl12xx_spi_driver = {
1324 .bus = &spi_bus_type,
1325 .owner = THIS_MODULE,
1328 .probe = wl12xx_probe,
1329 .remove = __devexit_p(wl12xx_remove),
1332 static int __init wl12xx_init(void)
1336 ret = spi_register_driver(&wl12xx_spi_driver);
1338 wl12xx_error("failed to register spi driver: %d", ret);
1346 static void __exit wl12xx_exit(void)
1348 spi_unregister_driver(&wl12xx_spi_driver);
1350 wl12xx_notice("unloaded");
1353 module_init(wl12xx_init);
1354 module_exit(wl12xx_exit);
1356 MODULE_LICENSE("GPL");
1357 MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>, "
1358 "Luciano Coelho <luciano.coelho@nokia.com>");