2 * This file is part of wl1271
4 * Copyright (C) 2008-2010 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/firmware.h>
26 #include <linux/delay.h>
27 #include <linux/spi/spi.h>
28 #include <linux/crc32.h>
29 #include <linux/etherdevice.h>
30 #include <linux/vmalloc.h>
31 #include <linux/inetdevice.h>
34 #include "wl12xx_80211.h"
35 #include "wl1271_reg.h"
36 #include "wl1271_spi.h"
37 #include "wl1271_io.h"
38 #include "wl1271_event.h"
39 #include "wl1271_tx.h"
40 #include "wl1271_rx.h"
41 #include "wl1271_ps.h"
42 #include "wl1271_init.h"
43 #include "wl1271_debugfs.h"
44 #include "wl1271_cmd.h"
45 #include "wl1271_boot.h"
46 #include "wl1271_testmode.h"
48 #define WL1271_BOOT_RETRIES 3
50 static struct conf_drv_settings default_conf
= {
52 .per_threshold
= 7500,
53 .max_scan_compensation_time
= 120000,
54 .nfs_sample_interval
= 400,
57 .probe_req_compensation
= 170,
58 .scan_window_compensation
= 50,
60 .beacon_miss_threshold
= 60,
61 .rate_adaptation_threshold
= CONF_HW_BIT_RATE_12MBPS
,
62 .rate_adaptation_snr
= 0
65 .rx_msdu_life_time
= 512000,
66 .packet_detection_threshold
= 0,
67 .ps_poll_timeout
= 15,
69 .rts_threshold
= 2347,
70 .rx_cca_threshold
= 0,
71 .irq_blk_threshold
= 0xFFFF,
72 .irq_pkt_threshold
= 0,
74 .queue_type
= CONF_RX_QUEUE_TYPE_LOW_PRIORITY
,
77 .tx_energy_detection
= 0,
79 .enabled_rates
= CONF_HW_BIT_RATE_1MBPS
|
80 CONF_HW_BIT_RATE_2MBPS
,
81 .short_retry_limit
= 10,
82 .long_retry_limit
= 10,
105 .aifsn
= CONF_TX_AIFS_PIFS
,
112 .aifsn
= CONF_TX_AIFS_PIFS
,
120 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
121 .tsid
= CONF_TX_AC_BE
,
122 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
123 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
128 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
129 .tsid
= CONF_TX_AC_BE
,
130 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
131 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
136 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
137 .tsid
= CONF_TX_AC_BE
,
138 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
139 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
144 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
145 .tsid
= CONF_TX_AC_BE
,
146 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
147 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
152 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
153 .tsid
= CONF_TX_AC_BE
,
154 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
155 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
160 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
161 .tsid
= CONF_TX_AC_BE
,
162 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
163 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
168 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
169 .tsid
= CONF_TX_AC_BE
,
170 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
171 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
175 .frag_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
,
176 .tx_compl_timeout
= 700,
177 .tx_compl_threshold
= 4
180 .wake_up_event
= CONF_WAKE_UP_EVENT_DTIM
,
181 .listen_interval
= 0,
182 .bcn_filt_mode
= CONF_BCN_FILT_MODE_ENABLED
,
183 .bcn_filt_ie_count
= 1,
186 .ie
= WLAN_EID_CHANNEL_SWITCH
,
187 .rule
= CONF_BCN_RULE_PASS_ON_APPEARANCE
,
190 .synch_fail_thold
= 10,
191 .bss_lose_timeout
= 100,
192 .beacon_rx_timeout
= 10000,
193 .broadcast_timeout
= 20000,
194 .rx_broadcast_in_ps
= 1,
195 .ps_poll_threshold
= 20,
196 .sig_trigger_count
= 2,
201 .metric
= CONF_TRIG_METRIC_RSSI_BEACON
,
202 .type
= CONF_TRIG_EVENT_TYPE_EDGE
,
203 .direction
= CONF_TRIG_EVENT_DIR_LOW
,
211 .metric
= CONF_TRIG_METRIC_RSSI_BEACON
,
212 .type
= CONF_TRIG_EVENT_TYPE_EDGE
,
213 .direction
= CONF_TRIG_EVENT_DIR_HIGH
,
220 .rssi_bcn_avg_weight
= 10,
221 .rssi_pkt_avg_weight
= 10,
222 .snr_bcn_avg_weight
= 10,
223 .snr_pkt_avg_weight
= 10
225 .bet_enable
= CONF_BET_MODE_ENABLE
,
226 .bet_max_consecutive
= 10,
227 .psm_entry_retries
= 3
239 .host_clk_settling_time
= 5000,
240 .host_fast_wakeup_support
= false
244 static LIST_HEAD(wl_list
);
246 static void wl1271_conf_init(struct wl1271
*wl
)
250 * This function applies the default configuration to the driver. This
251 * function is invoked upon driver load (spi probe.)
253 * The configuration is stored in a run-time structure in order to
254 * facilitate for run-time adjustment of any of the parameters. Making
255 * changes to the configuration structure will apply the new values on
256 * the next interface up (wl1271_op_start.)
259 /* apply driver default configuration */
260 memcpy(&wl
->conf
, &default_conf
, sizeof(default_conf
));
264 static int wl1271_plt_init(struct wl1271
*wl
)
266 struct conf_tx_ac_category
*conf_ac
;
267 struct conf_tx_tid
*conf_tid
;
270 ret
= wl1271_cmd_general_parms(wl
);
274 ret
= wl1271_cmd_radio_parms(wl
);
278 ret
= wl1271_init_templates_config(wl
);
282 ret
= wl1271_acx_init_mem_config(wl
);
286 /* PHY layer config */
287 ret
= wl1271_init_phy_config(wl
);
289 goto out_free_memmap
;
291 ret
= wl1271_acx_dco_itrim_params(wl
);
293 goto out_free_memmap
;
295 /* Initialize connection monitoring thresholds */
296 ret
= wl1271_acx_conn_monit_params(wl
);
298 goto out_free_memmap
;
300 /* Bluetooth WLAN coexistence */
301 ret
= wl1271_init_pta(wl
);
303 goto out_free_memmap
;
305 /* Energy detection */
306 ret
= wl1271_init_energy_detection(wl
);
308 goto out_free_memmap
;
310 /* Default fragmentation threshold */
311 ret
= wl1271_acx_frag_threshold(wl
);
313 goto out_free_memmap
;
315 /* Default TID configuration */
316 for (i
= 0; i
< wl
->conf
.tx
.tid_conf_count
; i
++) {
317 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
318 ret
= wl1271_acx_tid_cfg(wl
, conf_tid
->queue_id
,
319 conf_tid
->channel_type
,
322 conf_tid
->ack_policy
,
323 conf_tid
->apsd_conf
[0],
324 conf_tid
->apsd_conf
[1]);
326 goto out_free_memmap
;
329 /* Default AC configuration */
330 for (i
= 0; i
< wl
->conf
.tx
.ac_conf_count
; i
++) {
331 conf_ac
= &wl
->conf
.tx
.ac_conf
[i
];
332 ret
= wl1271_acx_ac_cfg(wl
, conf_ac
->ac
, conf_ac
->cw_min
,
333 conf_ac
->cw_max
, conf_ac
->aifsn
,
334 conf_ac
->tx_op_limit
);
336 goto out_free_memmap
;
339 /* Enable data path */
340 ret
= wl1271_cmd_data_path(wl
, 1);
342 goto out_free_memmap
;
344 /* Configure for CAM power saving (ie. always active) */
345 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
347 goto out_free_memmap
;
350 ret
= wl1271_acx_pm_config(wl
);
352 goto out_free_memmap
;
357 kfree(wl
->target_mem_map
);
358 wl
->target_mem_map
= NULL
;
363 static void wl1271_disable_interrupts(struct wl1271
*wl
)
365 disable_irq(wl
->irq
);
368 static void wl1271_power_off(struct wl1271
*wl
)
370 wl
->set_power(false);
371 clear_bit(WL1271_FLAG_GPIO_POWER
, &wl
->flags
);
374 static void wl1271_power_on(struct wl1271
*wl
)
377 set_bit(WL1271_FLAG_GPIO_POWER
, &wl
->flags
);
380 static void wl1271_fw_status(struct wl1271
*wl
,
381 struct wl1271_fw_status
*status
)
386 wl1271_read(wl
, FW_STATUS_ADDR
, status
, sizeof(*status
), false);
388 wl1271_debug(DEBUG_IRQ
, "intr: 0x%x (fw_rx_counter = %d, "
389 "drv_rx_counter = %d, tx_results_counter = %d)",
391 status
->fw_rx_counter
,
392 status
->drv_rx_counter
,
393 status
->tx_results_counter
);
395 /* update number of available TX blocks */
396 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
397 u32 cnt
= le32_to_cpu(status
->tx_released_blks
[i
]) -
398 wl
->tx_blocks_freed
[i
];
400 wl
->tx_blocks_freed
[i
] =
401 le32_to_cpu(status
->tx_released_blks
[i
]);
402 wl
->tx_blocks_available
+= cnt
;
406 /* if more blocks are available now, schedule some tx work */
407 if (total
&& !skb_queue_empty(&wl
->tx_queue
))
408 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
410 /* update the host-chipset time offset */
411 wl
->time_offset
= jiffies_to_usecs(jiffies
) -
412 le32_to_cpu(status
->fw_localtime
);
415 static void wl1271_irq_work(struct work_struct
*work
)
420 container_of(work
, struct wl1271
, irq_work
);
422 mutex_lock(&wl
->mutex
);
424 wl1271_debug(DEBUG_IRQ
, "IRQ work");
426 if (wl
->state
== WL1271_STATE_OFF
)
429 ret
= wl1271_ps_elp_wakeup(wl
, true);
433 wl1271_write32(wl
, ACX_REG_INTERRUPT_MASK
, WL1271_ACX_INTR_ALL
);
435 wl1271_fw_status(wl
, wl
->fw_status
);
436 intr
= le32_to_cpu(wl
->fw_status
->intr
);
438 wl1271_debug(DEBUG_IRQ
, "Zero interrupt received.");
442 intr
&= WL1271_INTR_MASK
;
444 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
445 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
446 wl1271_event_handle(wl
, 0);
449 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
450 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
451 wl1271_event_handle(wl
, 1);
454 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
455 wl1271_debug(DEBUG_IRQ
,
456 "WL1271_ACX_INTR_INIT_COMPLETE");
458 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
459 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
461 if (intr
& WL1271_ACX_INTR_DATA
) {
462 u8 tx_res_cnt
= wl
->fw_status
->tx_results_counter
-
463 wl
->tx_results_count
;
465 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
467 /* check for tx results */
469 wl1271_tx_complete(wl
, tx_res_cnt
);
471 wl1271_rx(wl
, wl
->fw_status
);
475 wl1271_write32(wl
, ACX_REG_INTERRUPT_MASK
,
476 WL1271_ACX_INTR_ALL
& ~(WL1271_INTR_MASK
));
477 wl1271_ps_elp_sleep(wl
);
480 mutex_unlock(&wl
->mutex
);
483 static int wl1271_fetch_firmware(struct wl1271
*wl
)
485 const struct firmware
*fw
;
488 ret
= request_firmware(&fw
, WL1271_FW_NAME
, &wl
->spi
->dev
);
491 wl1271_error("could not get firmware: %d", ret
);
496 wl1271_error("firmware size is not multiple of 32 bits: %zu",
502 wl
->fw_len
= fw
->size
;
503 wl
->fw
= vmalloc(wl
->fw_len
);
506 wl1271_error("could not allocate memory for the firmware");
511 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
516 release_firmware(fw
);
521 static int wl1271_update_mac_addr(struct wl1271
*wl
)
524 u8
*nvs_ptr
= (u8
*)wl
->nvs
->nvs
;
526 /* get mac address from the NVS */
527 wl
->mac_addr
[0] = nvs_ptr
[11];
528 wl
->mac_addr
[1] = nvs_ptr
[10];
529 wl
->mac_addr
[2] = nvs_ptr
[6];
530 wl
->mac_addr
[3] = nvs_ptr
[5];
531 wl
->mac_addr
[4] = nvs_ptr
[4];
532 wl
->mac_addr
[5] = nvs_ptr
[3];
534 /* FIXME: if it is a zero-address, we should bail out. Now, instead,
535 we randomize an address */
536 if (is_zero_ether_addr(wl
->mac_addr
)) {
537 static const u8 nokia_oui
[3] = {0x00, 0x1f, 0xdf};
538 memcpy(wl
->mac_addr
, nokia_oui
, 3);
539 get_random_bytes(wl
->mac_addr
+ 3, 3);
541 /* update this address to the NVS */
542 nvs_ptr
[11] = wl
->mac_addr
[0];
543 nvs_ptr
[10] = wl
->mac_addr
[1];
544 nvs_ptr
[6] = wl
->mac_addr
[2];
545 nvs_ptr
[5] = wl
->mac_addr
[3];
546 nvs_ptr
[4] = wl
->mac_addr
[4];
547 nvs_ptr
[3] = wl
->mac_addr
[5];
550 SET_IEEE80211_PERM_ADDR(wl
->hw
, wl
->mac_addr
);
555 static int wl1271_fetch_nvs(struct wl1271
*wl
)
557 const struct firmware
*fw
;
560 ret
= request_firmware(&fw
, WL1271_NVS_NAME
, &wl
->spi
->dev
);
563 wl1271_error("could not get nvs file: %d", ret
);
567 if (fw
->size
!= sizeof(struct wl1271_nvs_file
)) {
568 wl1271_error("nvs size is not as expected: %zu != %zu",
569 fw
->size
, sizeof(struct wl1271_nvs_file
));
574 wl
->nvs
= kmalloc(sizeof(struct wl1271_nvs_file
), GFP_KERNEL
);
577 wl1271_error("could not allocate memory for the nvs file");
582 memcpy(wl
->nvs
, fw
->data
, sizeof(struct wl1271_nvs_file
));
584 ret
= wl1271_update_mac_addr(wl
);
587 release_firmware(fw
);
592 static void wl1271_fw_wakeup(struct wl1271
*wl
)
596 elp_reg
= ELPCTRL_WAKE_UP
;
597 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, elp_reg
);
600 static int wl1271_setup(struct wl1271
*wl
)
602 wl
->fw_status
= kmalloc(sizeof(*wl
->fw_status
), GFP_KERNEL
);
606 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
607 if (!wl
->tx_res_if
) {
608 kfree(wl
->fw_status
);
612 INIT_WORK(&wl
->irq_work
, wl1271_irq_work
);
613 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
617 static int wl1271_chip_wakeup(struct wl1271
*wl
)
619 struct wl1271_partition_set partition
;
622 msleep(WL1271_PRE_POWER_ON_SLEEP
);
624 msleep(WL1271_POWER_ON_SLEEP
);
628 /* We don't need a real memory partition here, because we only want
629 * to use the registers at this point. */
630 memset(&partition
, 0, sizeof(partition
));
631 partition
.reg
.start
= REGISTERS_BASE
;
632 partition
.reg
.size
= REGISTERS_DOWN_SIZE
;
633 wl1271_set_partition(wl
, &partition
);
635 /* ELP module wake up */
636 wl1271_fw_wakeup(wl
);
638 /* whal_FwCtrl_BootSm() */
640 /* 0. read chip id from CHIP_ID */
641 wl
->chip
.id
= wl1271_read32(wl
, CHIP_ID_B
);
643 /* 1. check if chip id is valid */
645 switch (wl
->chip
.id
) {
646 case CHIP_ID_1271_PG10
:
647 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
650 ret
= wl1271_setup(wl
);
654 case CHIP_ID_1271_PG20
:
655 wl1271_debug(DEBUG_BOOT
, "chip id 0x%x (1271 PG20)",
658 ret
= wl1271_setup(wl
);
663 wl1271_warning("unsupported chip id: 0x%x", wl
->chip
.id
);
668 if (wl
->fw
== NULL
) {
669 ret
= wl1271_fetch_firmware(wl
);
674 /* No NVS from netlink, try to get it from the filesystem */
675 if (wl
->nvs
== NULL
) {
676 ret
= wl1271_fetch_nvs(wl
);
685 int wl1271_plt_start(struct wl1271
*wl
)
687 int retries
= WL1271_BOOT_RETRIES
;
690 mutex_lock(&wl
->mutex
);
692 wl1271_notice("power up");
694 if (wl
->state
!= WL1271_STATE_OFF
) {
695 wl1271_error("cannot go into PLT state because not "
696 "in off state: %d", wl
->state
);
703 ret
= wl1271_chip_wakeup(wl
);
707 ret
= wl1271_boot(wl
);
711 ret
= wl1271_plt_init(wl
);
715 wl
->state
= WL1271_STATE_PLT
;
716 wl1271_notice("firmware booted in PLT mode (%s)",
721 wl1271_disable_interrupts(wl
);
722 mutex_unlock(&wl
->mutex
);
723 /* Unlocking the mutex in the middle of handling is
724 inherently unsafe. In this case we deem it safe to do,
725 because we need to let any possibly pending IRQ out of
726 the system (and while we are WL1271_STATE_OFF the IRQ
727 work function will not do anything.) Also, any other
728 possible concurrent operations will fail due to the
729 current state, hence the wl1271 struct should be safe. */
730 cancel_work_sync(&wl
->irq_work
);
731 mutex_lock(&wl
->mutex
);
733 wl1271_power_off(wl
);
736 wl1271_error("firmware boot in PLT mode failed despite %d retries",
737 WL1271_BOOT_RETRIES
);
739 mutex_unlock(&wl
->mutex
);
744 int wl1271_plt_stop(struct wl1271
*wl
)
748 mutex_lock(&wl
->mutex
);
750 wl1271_notice("power down");
752 if (wl
->state
!= WL1271_STATE_PLT
) {
753 wl1271_error("cannot power down because not in PLT "
754 "state: %d", wl
->state
);
759 wl1271_disable_interrupts(wl
);
760 wl1271_power_off(wl
);
762 wl
->state
= WL1271_STATE_OFF
;
766 mutex_unlock(&wl
->mutex
);
772 static int wl1271_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
774 struct wl1271
*wl
= hw
->priv
;
775 struct ieee80211_conf
*conf
= &hw
->conf
;
776 struct ieee80211_tx_info
*txinfo
= IEEE80211_SKB_CB(skb
);
777 struct ieee80211_sta
*sta
= txinfo
->control
.sta
;
780 /* peek into the rates configured in the STA entry */
781 spin_lock_irqsave(&wl
->wl_lock
, flags
);
782 if (sta
&& sta
->supp_rates
[conf
->channel
->band
] != wl
->sta_rate_set
) {
783 wl
->sta_rate_set
= sta
->supp_rates
[conf
->channel
->band
];
784 set_bit(WL1271_FLAG_STA_RATES_CHANGED
, &wl
->flags
);
786 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
788 /* queue the packet */
789 skb_queue_tail(&wl
->tx_queue
, skb
);
792 * The chip specific setup must run before the first TX packet -
793 * before that, the tx_work will not be initialized!
796 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
799 * The workqueue is slow to process the tx_queue and we need stop
800 * the queue here, otherwise the queue will get too long.
802 if (skb_queue_len(&wl
->tx_queue
) >= WL1271_TX_QUEUE_MAX_LENGTH
) {
803 ieee80211_stop_queues(wl
->hw
);
806 * FIXME: this is racy, the variable is not properly
807 * protected. Maybe fix this by removing the stupid
808 * variable altogether and checking the real queue state?
810 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED
, &wl
->flags
);
816 static int wl1271_dev_notify(struct notifier_block
*me
, unsigned long what
,
819 struct net_device
*dev
;
820 struct wireless_dev
*wdev
;
822 struct ieee80211_hw
*hw
;
824 struct wl1271
*wl_temp
;
825 struct in_device
*idev
;
826 struct in_ifaddr
*ifa
= arg
;
829 /* FIXME: this ugly function should probably be implemented in the
830 * mac80211, and here should only be a simple callback handling actual
831 * setting of the filters. Now we need to dig up references to
832 * various structures to gain access to what we need.
833 * Also, because of this, there is no "initial" setting of the filter
834 * in "op_start", because we don't want to dig up struct net_device
835 * there - the filter will be set upon first change of the interface
838 dev
= ifa
->ifa_dev
->dev
;
840 wdev
= dev
->ieee80211_ptr
;
848 hw
= wiphy_priv(wiphy
);
852 /* Check that the interface is one supported by this driver. */
854 list_for_each_entry(wl
, &wl_list
, list
) {
861 /* Get the interface IP address for the device. "ifa" will become
863 - there is no IPV4 protocol address configured
864 - there are multiple (virtual) IPV4 addresses configured
865 When "ifa" is NULL, filtering will be disabled.
870 ifa
= idev
->ifa_list
;
872 if (ifa
&& ifa
->ifa_next
)
875 mutex_lock(&wl
->mutex
);
877 if (wl
->state
== WL1271_STATE_OFF
)
880 ret
= wl1271_ps_elp_wakeup(wl
, false);
884 ret
= wl1271_acx_arp_ip_filter(wl
, true,
885 (u8
*)&ifa
->ifa_address
,
888 ret
= wl1271_acx_arp_ip_filter(wl
, false, NULL
,
890 wl1271_ps_elp_sleep(wl
);
893 mutex_unlock(&wl
->mutex
);
898 static struct notifier_block wl1271_dev_notifier
= {
899 .notifier_call
= wl1271_dev_notify
,
903 static int wl1271_op_start(struct ieee80211_hw
*hw
)
905 struct wl1271
*wl
= hw
->priv
;
906 int retries
= WL1271_BOOT_RETRIES
;
909 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
911 mutex_lock(&wl
->mutex
);
913 if (wl
->state
!= WL1271_STATE_OFF
) {
914 wl1271_error("cannot start because not in off state: %d",
922 ret
= wl1271_chip_wakeup(wl
);
926 ret
= wl1271_boot(wl
);
930 ret
= wl1271_hw_init(wl
);
934 wl
->state
= WL1271_STATE_ON
;
935 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver
);
939 wl1271_disable_interrupts(wl
);
940 mutex_unlock(&wl
->mutex
);
941 /* Unlocking the mutex in the middle of handling is
942 inherently unsafe. In this case we deem it safe to do,
943 because we need to let any possibly pending IRQ out of
944 the system (and while we are WL1271_STATE_OFF the IRQ
945 work function will not do anything.) Also, any other
946 possible concurrent operations will fail due to the
947 current state, hence the wl1271 struct should be safe. */
948 cancel_work_sync(&wl
->irq_work
);
949 mutex_lock(&wl
->mutex
);
951 wl1271_power_off(wl
);
954 wl1271_error("firmware boot failed despite %d retries",
955 WL1271_BOOT_RETRIES
);
957 mutex_unlock(&wl
->mutex
);
960 list_add(&wl
->list
, &wl_list
);
961 register_inetaddr_notifier(&wl1271_dev_notifier
);
967 static void wl1271_op_stop(struct ieee80211_hw
*hw
)
969 struct wl1271
*wl
= hw
->priv
;
974 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
976 unregister_inetaddr_notifier(&wl1271_dev_notifier
);
979 mutex_lock(&wl
->mutex
);
981 WARN_ON(wl
->state
!= WL1271_STATE_ON
);
983 if (test_and_clear_bit(WL1271_FLAG_SCANNING
, &wl
->flags
)) {
984 mutex_unlock(&wl
->mutex
);
985 ieee80211_scan_completed(wl
->hw
, true);
986 mutex_lock(&wl
->mutex
);
989 wl
->state
= WL1271_STATE_OFF
;
991 wl1271_disable_interrupts(wl
);
993 mutex_unlock(&wl
->mutex
);
995 cancel_work_sync(&wl
->irq_work
);
996 cancel_work_sync(&wl
->tx_work
);
998 mutex_lock(&wl
->mutex
);
1000 /* let's notify MAC80211 about the remaining pending TX frames */
1001 wl1271_tx_flush(wl
);
1002 wl1271_power_off(wl
);
1004 memset(wl
->bssid
, 0, ETH_ALEN
);
1005 memset(wl
->ssid
, 0, IW_ESSID_MAX_SIZE
+ 1);
1007 wl
->bss_type
= MAX_BSS_TYPE
;
1008 wl
->band
= IEEE80211_BAND_2GHZ
;
1011 wl
->psm_entry_retry
= 0;
1012 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1013 wl
->tx_blocks_available
= 0;
1014 wl
->tx_results_count
= 0;
1015 wl
->tx_packets_count
= 0;
1016 wl
->tx_security_last_seq
= 0;
1017 wl
->tx_security_seq_16
= 0;
1018 wl
->tx_security_seq_32
= 0;
1019 wl
->time_offset
= 0;
1020 wl
->session_counter
= 0;
1021 wl
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
1022 wl
->sta_rate_set
= 0;
1025 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
1026 wl
->tx_blocks_freed
[i
] = 0;
1028 wl1271_debugfs_reset(wl
);
1029 mutex_unlock(&wl
->mutex
);
1032 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
1033 struct ieee80211_vif
*vif
)
1035 struct wl1271
*wl
= hw
->priv
;
1038 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
1039 vif
->type
, vif
->addr
);
1041 mutex_lock(&wl
->mutex
);
1049 switch (vif
->type
) {
1050 case NL80211_IFTYPE_STATION
:
1051 wl
->bss_type
= BSS_TYPE_STA_BSS
;
1053 case NL80211_IFTYPE_ADHOC
:
1054 wl
->bss_type
= BSS_TYPE_IBSS
;
1061 /* FIXME: what if conf->mac_addr changes? */
1064 mutex_unlock(&wl
->mutex
);
1068 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
1069 struct ieee80211_vif
*vif
)
1071 struct wl1271
*wl
= hw
->priv
;
1073 mutex_lock(&wl
->mutex
);
1074 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
1076 mutex_unlock(&wl
->mutex
);
1080 static int wl1271_op_config_interface(struct ieee80211_hw
*hw
,
1081 struct ieee80211_vif
*vif
,
1082 struct ieee80211_if_conf
*conf
)
1084 struct wl1271
*wl
= hw
->priv
;
1085 struct sk_buff
*beacon
;
1088 wl1271_debug(DEBUG_MAC80211
, "mac80211 config_interface bssid %pM",
1090 wl1271_dump_ascii(DEBUG_MAC80211
, "ssid: ", conf
->ssid
,
1093 mutex_lock(&wl
->mutex
);
1095 ret
= wl1271_ps_elp_wakeup(wl
, false);
1099 if (memcmp(wl
->bssid
, conf
->bssid
, ETH_ALEN
)) {
1100 wl1271_debug(DEBUG_MAC80211
, "bssid changed");
1102 memcpy(wl
->bssid
, conf
->bssid
, ETH_ALEN
);
1104 ret
= wl1271_cmd_join(wl
);
1108 ret
= wl1271_cmd_build_null_data(wl
);
1113 wl
->ssid_len
= conf
->ssid_len
;
1115 memcpy(wl
->ssid
, conf
->ssid
, wl
->ssid_len
);
1117 if (conf
->changed
& IEEE80211_IFCC_BEACON
) {
1118 beacon
= ieee80211_beacon_get(hw
, vif
);
1119 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
,
1120 beacon
->data
, beacon
->len
);
1123 dev_kfree_skb(beacon
);
1127 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PROBE_RESPONSE
,
1128 beacon
->data
, beacon
->len
);
1130 dev_kfree_skb(beacon
);
1137 wl1271_ps_elp_sleep(wl
);
1140 mutex_unlock(&wl
->mutex
);
1146 static int wl1271_join_channel(struct wl1271
*wl
, int channel
)
1149 /* we need to use a dummy BSSID for now */
1150 static const u8 dummy_bssid
[ETH_ALEN
] = { 0x0b, 0xad, 0xde,
1153 /* the dummy join is not required for ad-hoc */
1154 if (wl
->bss_type
== BSS_TYPE_IBSS
)
1157 /* disable mac filter, so we hear everything */
1158 wl
->rx_config
&= ~CFG_BSSID_FILTER_EN
;
1160 wl
->channel
= channel
;
1161 memcpy(wl
->bssid
, dummy_bssid
, ETH_ALEN
);
1163 ret
= wl1271_cmd_join(wl
);
1167 set_bit(WL1271_FLAG_JOINED
, &wl
->flags
);
1173 static int wl1271_unjoin_channel(struct wl1271
*wl
)
1177 /* to stop listening to a channel, we disconnect */
1178 ret
= wl1271_cmd_disconnect(wl
);
1182 clear_bit(WL1271_FLAG_JOINED
, &wl
->flags
);
1184 memset(wl
->bssid
, 0, ETH_ALEN
);
1185 wl
->rx_config
= WL1271_DEFAULT_RX_CONFIG
;
1191 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
1193 struct wl1271
*wl
= hw
->priv
;
1194 struct ieee80211_conf
*conf
= &hw
->conf
;
1195 int channel
, ret
= 0;
1197 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
1199 wl1271_debug(DEBUG_MAC80211
, "mac80211 config ch %d psm %s power %d %s",
1201 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
1203 conf
->flags
& IEEE80211_CONF_IDLE
? "idle" : "in use");
1205 mutex_lock(&wl
->mutex
);
1207 wl
->band
= conf
->channel
->band
;
1209 ret
= wl1271_ps_elp_wakeup(wl
, false);
1213 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1214 if (conf
->flags
& IEEE80211_CONF_IDLE
&&
1215 test_bit(WL1271_FLAG_JOINED
, &wl
->flags
))
1216 wl1271_unjoin_channel(wl
);
1217 else if (!(conf
->flags
& IEEE80211_CONF_IDLE
))
1218 wl1271_join_channel(wl
, channel
);
1220 if (conf
->flags
& IEEE80211_CONF_IDLE
) {
1221 wl
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
1222 wl
->sta_rate_set
= 0;
1223 wl1271_acx_rate_policies(wl
);
1227 /* if the channel changes while joined, join again */
1228 if (channel
!= wl
->channel
&&
1229 test_bit(WL1271_FLAG_JOINED
, &wl
->flags
)) {
1230 wl
->channel
= channel
;
1231 /* FIXME: maybe use CMD_CHANNEL_SWITCH for this? */
1232 ret
= wl1271_cmd_join(wl
);
1234 wl1271_warning("cmd join to update channel failed %d",
1237 wl
->channel
= channel
;
1239 if (conf
->flags
& IEEE80211_CONF_PS
&&
1240 !test_bit(WL1271_FLAG_PSM_REQUESTED
, &wl
->flags
)) {
1241 set_bit(WL1271_FLAG_PSM_REQUESTED
, &wl
->flags
);
1244 * We enter PSM only if we're already associated.
1245 * If we're not, we'll enter it when joining an SSID,
1246 * through the bss_info_changed() hook.
1248 if (test_bit(WL1271_FLAG_STA_ASSOCIATED
, &wl
->flags
)) {
1249 wl1271_info("psm enabled");
1250 ret
= wl1271_ps_set_mode(wl
, STATION_POWER_SAVE_MODE
,
1253 } else if (!(conf
->flags
& IEEE80211_CONF_PS
) &&
1254 test_bit(WL1271_FLAG_PSM_REQUESTED
, &wl
->flags
)) {
1255 wl1271_info("psm disabled");
1257 clear_bit(WL1271_FLAG_PSM_REQUESTED
, &wl
->flags
);
1259 if (test_bit(WL1271_FLAG_PSM
, &wl
->flags
))
1260 ret
= wl1271_ps_set_mode(wl
, STATION_ACTIVE_MODE
,
1264 if (conf
->power_level
!= wl
->power_level
) {
1265 ret
= wl1271_acx_tx_power(wl
, conf
->power_level
);
1269 wl
->power_level
= conf
->power_level
;
1273 wl1271_ps_elp_sleep(wl
);
1276 mutex_unlock(&wl
->mutex
);
1281 struct wl1271_filter_params
{
1284 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
1287 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
, int mc_count
,
1288 struct dev_addr_list
*mc_list
)
1290 struct wl1271_filter_params
*fp
;
1293 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
1295 wl1271_error("Out of memory setting filters.");
1299 /* update multicast filtering parameters */
1301 if (mc_count
> ACX_MC_ADDRESS_GROUP_MAX
) {
1303 fp
->enabled
= false;
1306 fp
->mc_list_length
= 0;
1307 for (i
= 0; i
< mc_count
; i
++) {
1308 if (mc_list
->da_addrlen
== ETH_ALEN
) {
1309 memcpy(fp
->mc_list
[fp
->mc_list_length
],
1310 mc_list
->da_addr
, ETH_ALEN
);
1311 fp
->mc_list_length
++;
1313 wl1271_warning("Unknown mc address length.");
1314 mc_list
= mc_list
->next
;
1317 return (u64
)(unsigned long)fp
;
1320 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
1323 FIF_BCN_PRBRESP_PROMISC | \
1327 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
1328 unsigned int changed
,
1329 unsigned int *total
, u64 multicast
)
1331 struct wl1271_filter_params
*fp
= (void *)(unsigned long)multicast
;
1332 struct wl1271
*wl
= hw
->priv
;
1335 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter");
1337 mutex_lock(&wl
->mutex
);
1339 if (wl
->state
== WL1271_STATE_OFF
)
1342 ret
= wl1271_ps_elp_wakeup(wl
, false);
1346 *total
&= WL1271_SUPPORTED_FILTERS
;
1347 changed
&= WL1271_SUPPORTED_FILTERS
;
1349 if (*total
& FIF_ALLMULTI
)
1350 ret
= wl1271_acx_group_address_tbl(wl
, false, NULL
, 0);
1352 ret
= wl1271_acx_group_address_tbl(wl
, fp
->enabled
,
1354 fp
->mc_list_length
);
1360 /* FIXME: We still need to set our filters properly */
1362 /* determine, whether supported filter values have changed */
1366 /* apply configured filters */
1367 ret
= wl1271_acx_rx_config(wl
, wl
->rx_config
, wl
->rx_filter
);
1372 wl1271_ps_elp_sleep(wl
);
1375 mutex_unlock(&wl
->mutex
);
1378 static int wl1271_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1379 struct ieee80211_vif
*vif
,
1380 struct ieee80211_sta
*sta
,
1381 struct ieee80211_key_conf
*key_conf
)
1383 struct wl1271
*wl
= hw
->priv
;
1390 static const u8 bcast_addr
[ETH_ALEN
] =
1391 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1393 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
1395 addr
= sta
? sta
->addr
: bcast_addr
;
1397 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x", cmd
);
1398 wl1271_dump(DEBUG_CRYPT
, "ADDR: ", addr
, ETH_ALEN
);
1399 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
1400 key_conf
->alg
, key_conf
->keyidx
,
1401 key_conf
->keylen
, key_conf
->flags
);
1402 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
1404 if (is_zero_ether_addr(addr
)) {
1405 /* We dont support TX only encryption */
1410 mutex_lock(&wl
->mutex
);
1412 ret
= wl1271_ps_elp_wakeup(wl
, false);
1416 switch (key_conf
->alg
) {
1420 key_conf
->hw_key_idx
= key_conf
->keyidx
;
1423 key_type
= KEY_TKIP
;
1425 key_conf
->hw_key_idx
= key_conf
->keyidx
;
1426 tx_seq_32
= wl
->tx_security_seq_32
;
1427 tx_seq_16
= wl
->tx_security_seq_16
;
1432 key_conf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1433 tx_seq_32
= wl
->tx_security_seq_32
;
1434 tx_seq_16
= wl
->tx_security_seq_16
;
1437 wl1271_error("Unknown key algo 0x%x", key_conf
->alg
);
1445 ret
= wl1271_cmd_set_key(wl
, KEY_ADD_OR_REPLACE
,
1446 key_conf
->keyidx
, key_type
,
1447 key_conf
->keylen
, key_conf
->key
,
1448 addr
, tx_seq_32
, tx_seq_16
);
1450 wl1271_error("Could not add or replace key");
1454 /* the default WEP key needs to be configured at least once */
1455 if (key_type
== KEY_WEP
) {
1456 ret
= wl1271_cmd_set_default_wep_key(wl
,
1464 /* The wl1271 does not allow to remove unicast keys - they
1465 will be cleared automatically on next CMD_JOIN. Ignore the
1466 request silently, as we dont want the mac80211 to emit
1467 an error message. */
1468 if (!is_broadcast_ether_addr(addr
))
1471 ret
= wl1271_cmd_set_key(wl
, KEY_REMOVE
,
1472 key_conf
->keyidx
, key_type
,
1473 key_conf
->keylen
, key_conf
->key
,
1476 wl1271_error("Could not remove key");
1482 wl1271_error("Unsupported key cmd 0x%x", cmd
);
1490 wl1271_ps_elp_sleep(wl
);
1493 mutex_unlock(&wl
->mutex
);
1499 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
1500 struct cfg80211_scan_request
*req
)
1502 struct wl1271
*wl
= hw
->priv
;
1507 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
1510 ssid
= req
->ssids
[0].ssid
;
1511 len
= req
->ssids
[0].ssid_len
;
1514 mutex_lock(&wl
->mutex
);
1516 ret
= wl1271_ps_elp_wakeup(wl
, false);
1520 if (wl1271_11a_enabled())
1521 ret
= wl1271_cmd_scan(hw
->priv
, ssid
, len
, 1, 0,
1522 WL1271_SCAN_BAND_DUAL
, 3);
1524 ret
= wl1271_cmd_scan(hw
->priv
, ssid
, len
, 1, 0,
1525 WL1271_SCAN_BAND_2_4_GHZ
, 3);
1527 wl1271_ps_elp_sleep(wl
);
1530 mutex_unlock(&wl
->mutex
);
1535 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1537 struct wl1271
*wl
= hw
->priv
;
1540 mutex_lock(&wl
->mutex
);
1542 ret
= wl1271_ps_elp_wakeup(wl
, false);
1546 ret
= wl1271_acx_rts_threshold(wl
, (u16
) value
);
1548 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret
);
1550 wl1271_ps_elp_sleep(wl
);
1553 mutex_unlock(&wl
->mutex
);
1558 static void wl1271_ssid_set(struct wl1271
*wl
, struct sk_buff
*beacon
)
1560 u8
*ptr
= beacon
->data
+
1561 offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
1563 /* find the location of the ssid in the beacon */
1564 while (ptr
< beacon
->data
+ beacon
->len
) {
1565 if (ptr
[0] == WLAN_EID_SSID
) {
1566 wl
->ssid_len
= ptr
[1];
1567 memcpy(wl
->ssid
, ptr
+2, wl
->ssid_len
);
1572 wl1271_error("ad-hoc beacon template has no SSID!\n");
1575 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
1576 struct ieee80211_vif
*vif
,
1577 struct ieee80211_bss_conf
*bss_conf
,
1580 enum wl1271_cmd_ps_mode mode
;
1581 struct wl1271
*wl
= hw
->priv
;
1582 bool do_join
= false;
1585 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info changed");
1587 mutex_lock(&wl
->mutex
);
1589 ret
= wl1271_ps_elp_wakeup(wl
, false);
1593 if (wl
->bss_type
== BSS_TYPE_IBSS
) {
1594 /* FIXME: This implements rudimentary ad-hoc support -
1595 proper templates are on the wish list and notification
1596 on when they change. This patch will update the templates
1597 on every call to this function. */
1598 struct sk_buff
*beacon
= ieee80211_beacon_get(hw
, vif
);
1601 struct ieee80211_hdr
*hdr
;
1603 wl1271_ssid_set(wl
, beacon
);
1604 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
,
1609 dev_kfree_skb(beacon
);
1613 hdr
= (struct ieee80211_hdr
*) beacon
->data
;
1614 hdr
->frame_control
= cpu_to_le16(
1615 IEEE80211_FTYPE_MGMT
|
1616 IEEE80211_STYPE_PROBE_RESP
);
1618 ret
= wl1271_cmd_template_set(wl
,
1619 CMD_TEMPL_PROBE_RESPONSE
,
1622 dev_kfree_skb(beacon
);
1626 /* Need to update the SSID (for filtering etc) */
1631 if ((changed
& BSS_CHANGED_BSSID
) &&
1633 * Now we know the correct bssid, so we send a new join command
1634 * and enable the BSSID filter
1636 memcmp(wl
->bssid
, bss_conf
->bssid
, ETH_ALEN
)) {
1637 wl
->rx_config
|= CFG_BSSID_FILTER_EN
;
1638 memcpy(wl
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1639 ret
= wl1271_cmd_build_null_data(wl
);
1641 wl1271_warning("cmd buld null data failed %d",
1646 /* Need to update the BSSID (for filtering etc) */
1650 if (changed
& BSS_CHANGED_ASSOC
) {
1651 if (bss_conf
->assoc
) {
1652 wl
->aid
= bss_conf
->aid
;
1653 set_bit(WL1271_FLAG_STA_ASSOCIATED
, &wl
->flags
);
1656 * with wl1271, we don't need to update the
1657 * beacon_int and dtim_period, because the firmware
1658 * updates it by itself when the first beacon is
1659 * received after a join.
1661 ret
= wl1271_cmd_build_ps_poll(wl
, wl
->aid
);
1665 ret
= wl1271_acx_aid(wl
, wl
->aid
);
1669 /* If we want to go in PSM but we're not there yet */
1670 if (test_bit(WL1271_FLAG_PSM_REQUESTED
, &wl
->flags
) &&
1671 !test_bit(WL1271_FLAG_PSM
, &wl
->flags
)) {
1672 mode
= STATION_POWER_SAVE_MODE
;
1673 ret
= wl1271_ps_set_mode(wl
, mode
, true);
1678 /* use defaults when not associated */
1679 clear_bit(WL1271_FLAG_STA_ASSOCIATED
, &wl
->flags
);
1685 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1686 if (bss_conf
->use_short_slot
)
1687 ret
= wl1271_acx_slot(wl
, SLOT_TIME_SHORT
);
1689 ret
= wl1271_acx_slot(wl
, SLOT_TIME_LONG
);
1691 wl1271_warning("Set slot time failed %d", ret
);
1696 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1697 if (bss_conf
->use_short_preamble
)
1698 wl1271_acx_set_preamble(wl
, ACX_PREAMBLE_SHORT
);
1700 wl1271_acx_set_preamble(wl
, ACX_PREAMBLE_LONG
);
1703 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1704 if (bss_conf
->use_cts_prot
)
1705 ret
= wl1271_acx_cts_protect(wl
, CTSPROTECT_ENABLE
);
1707 ret
= wl1271_acx_cts_protect(wl
, CTSPROTECT_DISABLE
);
1709 wl1271_warning("Set ctsprotect failed %d", ret
);
1715 ret
= wl1271_cmd_join(wl
);
1717 wl1271_warning("cmd join failed %d", ret
);
1720 set_bit(WL1271_FLAG_JOINED
, &wl
->flags
);
1724 wl1271_ps_elp_sleep(wl
);
1727 mutex_unlock(&wl
->mutex
);
1730 static int wl1271_op_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1731 const struct ieee80211_tx_queue_params
*params
)
1733 struct wl1271
*wl
= hw
->priv
;
1736 mutex_lock(&wl
->mutex
);
1738 wl1271_debug(DEBUG_MAC80211
, "mac80211 conf tx %d", queue
);
1740 ret
= wl1271_ps_elp_wakeup(wl
, false);
1744 ret
= wl1271_acx_ac_cfg(wl
, wl1271_tx_get_queue(queue
),
1745 params
->cw_min
, params
->cw_max
,
1746 params
->aifs
, params
->txop
);
1750 ret
= wl1271_acx_tid_cfg(wl
, wl1271_tx_get_queue(queue
),
1751 CONF_CHANNEL_TYPE_EDCF
,
1752 wl1271_tx_get_queue(queue
),
1753 CONF_PS_SCHEME_LEGACY_PSPOLL
,
1754 CONF_ACK_POLICY_LEGACY
, 0, 0);
1759 wl1271_ps_elp_sleep(wl
);
1762 mutex_unlock(&wl
->mutex
);
1768 /* can't be const, mac80211 writes to this */
1769 static struct ieee80211_rate wl1271_rates
[] = {
1771 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
1772 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
1774 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
1775 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
1776 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1778 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
1779 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
1780 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1782 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
1783 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
1784 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1786 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
1787 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
1789 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
1790 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
1792 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
1793 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
1795 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
1796 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
1798 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
1799 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
1801 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
1802 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
1804 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
1805 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
1807 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
1808 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
1811 /* can't be const, mac80211 writes to this */
1812 static struct ieee80211_channel wl1271_channels
[] = {
1813 { .hw_value
= 1, .center_freq
= 2412, .max_power
= 25 },
1814 { .hw_value
= 2, .center_freq
= 2417, .max_power
= 25 },
1815 { .hw_value
= 3, .center_freq
= 2422, .max_power
= 25 },
1816 { .hw_value
= 4, .center_freq
= 2427, .max_power
= 25 },
1817 { .hw_value
= 5, .center_freq
= 2432, .max_power
= 25 },
1818 { .hw_value
= 6, .center_freq
= 2437, .max_power
= 25 },
1819 { .hw_value
= 7, .center_freq
= 2442, .max_power
= 25 },
1820 { .hw_value
= 8, .center_freq
= 2447, .max_power
= 25 },
1821 { .hw_value
= 9, .center_freq
= 2452, .max_power
= 25 },
1822 { .hw_value
= 10, .center_freq
= 2457, .max_power
= 25 },
1823 { .hw_value
= 11, .center_freq
= 2462, .max_power
= 25 },
1824 { .hw_value
= 12, .center_freq
= 2467, .max_power
= 25 },
1825 { .hw_value
= 13, .center_freq
= 2472, .max_power
= 25 },
1828 /* can't be const, mac80211 writes to this */
1829 static struct ieee80211_supported_band wl1271_band_2ghz
= {
1830 .channels
= wl1271_channels
,
1831 .n_channels
= ARRAY_SIZE(wl1271_channels
),
1832 .bitrates
= wl1271_rates
,
1833 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
1836 /* 5 GHz data rates for WL1273 */
1837 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
1839 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
1840 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
1842 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
1843 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
1845 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
1846 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
1848 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
1849 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
1851 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
1852 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
1854 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
1855 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
1857 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
1858 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
1860 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
1861 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
1864 /* 5 GHz band channels for WL1273 */
1865 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
1866 { .hw_value
= 183, .center_freq
= 4915},
1867 { .hw_value
= 184, .center_freq
= 4920},
1868 { .hw_value
= 185, .center_freq
= 4925},
1869 { .hw_value
= 187, .center_freq
= 4935},
1870 { .hw_value
= 188, .center_freq
= 4940},
1871 { .hw_value
= 189, .center_freq
= 4945},
1872 { .hw_value
= 192, .center_freq
= 4960},
1873 { .hw_value
= 196, .center_freq
= 4980},
1874 { .hw_value
= 7, .center_freq
= 5035},
1875 { .hw_value
= 8, .center_freq
= 5040},
1876 { .hw_value
= 9, .center_freq
= 5045},
1877 { .hw_value
= 11, .center_freq
= 5055},
1878 { .hw_value
= 12, .center_freq
= 5060},
1879 { .hw_value
= 16, .center_freq
= 5080},
1880 { .hw_value
= 34, .center_freq
= 5170},
1881 { .hw_value
= 36, .center_freq
= 5180},
1882 { .hw_value
= 38, .center_freq
= 5190},
1883 { .hw_value
= 40, .center_freq
= 5200},
1884 { .hw_value
= 42, .center_freq
= 5210},
1885 { .hw_value
= 44, .center_freq
= 5220},
1886 { .hw_value
= 46, .center_freq
= 5230},
1887 { .hw_value
= 48, .center_freq
= 5240},
1888 { .hw_value
= 52, .center_freq
= 5260},
1889 { .hw_value
= 56, .center_freq
= 5280},
1890 { .hw_value
= 60, .center_freq
= 5300},
1891 { .hw_value
= 64, .center_freq
= 5320},
1892 { .hw_value
= 100, .center_freq
= 5500},
1893 { .hw_value
= 104, .center_freq
= 5520},
1894 { .hw_value
= 108, .center_freq
= 5540},
1895 { .hw_value
= 112, .center_freq
= 5560},
1896 { .hw_value
= 116, .center_freq
= 5580},
1897 { .hw_value
= 120, .center_freq
= 5600},
1898 { .hw_value
= 124, .center_freq
= 5620},
1899 { .hw_value
= 128, .center_freq
= 5640},
1900 { .hw_value
= 132, .center_freq
= 5660},
1901 { .hw_value
= 136, .center_freq
= 5680},
1902 { .hw_value
= 140, .center_freq
= 5700},
1903 { .hw_value
= 149, .center_freq
= 5745},
1904 { .hw_value
= 153, .center_freq
= 5765},
1905 { .hw_value
= 157, .center_freq
= 5785},
1906 { .hw_value
= 161, .center_freq
= 5805},
1907 { .hw_value
= 165, .center_freq
= 5825},
1911 static struct ieee80211_supported_band wl1271_band_5ghz
= {
1912 .channels
= wl1271_channels_5ghz
,
1913 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
1914 .bitrates
= wl1271_rates_5ghz
,
1915 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
1918 static const struct ieee80211_ops wl1271_ops
= {
1919 .start
= wl1271_op_start
,
1920 .stop
= wl1271_op_stop
,
1921 .add_interface
= wl1271_op_add_interface
,
1922 .remove_interface
= wl1271_op_remove_interface
,
1923 .config
= wl1271_op_config
,
1924 /* .config_interface = wl1271_op_config_interface, */
1925 .prepare_multicast
= wl1271_op_prepare_multicast
,
1926 .configure_filter
= wl1271_op_configure_filter
,
1928 .set_key
= wl1271_op_set_key
,
1929 .hw_scan
= wl1271_op_hw_scan
,
1930 .bss_info_changed
= wl1271_op_bss_info_changed
,
1931 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
1932 .conf_tx
= wl1271_op_conf_tx
,
1933 CFG80211_TESTMODE_CMD(wl1271_tm_cmd
)
1936 int wl1271_register_hw(struct wl1271
*wl
)
1940 if (wl
->mac80211_registered
)
1943 SET_IEEE80211_PERM_ADDR(wl
->hw
, wl
->mac_addr
);
1945 ret
= ieee80211_register_hw(wl
->hw
);
1947 wl1271_error("unable to register mac80211 hw: %d", ret
);
1951 wl
->mac80211_registered
= true;
1953 wl1271_notice("loaded");
1958 int wl1271_init_ieee80211(struct wl1271
*wl
)
1960 /* The tx descriptor buffer and the TKIP space. */
1961 wl
->hw
->extra_tx_headroom
= WL1271_TKIP_IV_SPACE
+
1962 sizeof(struct wl1271_tx_hw_descr
);
1965 /* FIXME: find a proper value */
1966 wl
->hw
->channel_change_time
= 10000;
1968 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
1969 IEEE80211_HW_NOISE_DBM
|
1970 IEEE80211_HW_BEACON_FILTER
|
1971 IEEE80211_HW_SUPPORTS_PS
;
1973 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1974 BIT(NL80211_IFTYPE_ADHOC
);
1975 wl
->hw
->wiphy
->max_scan_ssids
= 1;
1976 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &wl1271_band_2ghz
;
1978 if (wl1271_11a_enabled())
1979 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &wl1271_band_5ghz
;
1981 SET_IEEE80211_DEV(wl
->hw
, &wl
->spi
->dev
);
1986 #define WL1271_DEFAULT_CHANNEL 0
1988 struct ieee80211_hw
*wl1271_alloc_hw(void)
1990 struct ieee80211_hw
*hw
;
1994 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
1996 wl1271_error("could not alloc ieee80211_hw");
1997 return ERR_PTR(-ENOMEM
);
2001 memset(wl
, 0, sizeof(*wl
));
2003 INIT_LIST_HEAD(&wl
->list
);
2007 skb_queue_head_init(&wl
->tx_queue
);
2009 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
2010 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
2011 wl
->default_key
= 0;
2013 wl
->rx_config
= WL1271_DEFAULT_RX_CONFIG
;
2014 wl
->rx_filter
= WL1271_DEFAULT_RX_FILTER
;
2015 wl
->psm_entry_retry
= 0;
2016 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
2017 wl
->basic_rate_set
= CONF_TX_RATE_MASK_BASIC
;
2018 wl
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
2019 wl
->sta_rate_set
= 0;
2020 wl
->band
= IEEE80211_BAND_2GHZ
;
2024 for (i
= 0; i
< ACX_TX_DESCRIPTORS
; i
++)
2025 wl
->tx_frames
[i
] = NULL
;
2027 spin_lock_init(&wl
->wl_lock
);
2029 wl
->state
= WL1271_STATE_OFF
;
2030 mutex_init(&wl
->mutex
);
2032 /* Apply default driver configuration. */
2033 wl1271_conf_init(wl
);
2035 wl1271_debugfs_init(wl
);
2040 int wl1271_free_hw(struct wl1271
*wl
)
2042 ieee80211_unregister_hw(wl
->hw
);
2044 wl1271_debugfs_exit(wl
);
2046 kfree(wl
->target_mem_map
);
2052 kfree(wl
->fw_status
);
2053 kfree(wl
->tx_res_if
);
2055 ieee80211_free_hw(wl
->hw
);