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/vmalloc.h>
34 #include <linux/spi/wl12xx.h>
37 #include "wl12xx_80211.h"
38 #include "wl1271_reg.h"
39 #include "wl1271_spi.h"
40 #include "wl1271_event.h"
41 #include "wl1271_tx.h"
42 #include "wl1271_rx.h"
43 #include "wl1271_ps.h"
44 #include "wl1271_init.h"
45 #include "wl1271_debugfs.h"
46 #include "wl1271_cmd.h"
47 #include "wl1271_boot.h"
49 static struct conf_drv_settings default_conf
= {
51 .per_threshold
= 7500,
52 .max_scan_compensation_time
= 120000,
53 .nfs_sample_interval
= 400,
56 .probe_req_compensation
= 170,
57 .scan_window_compensation
= 50,
59 .beacon_miss_threshold
= 60,
60 .rate_adaptation_threshold
= CONF_HW_BIT_RATE_12MBPS
,
61 .rate_adaptation_snr
= 0
64 .rx_msdu_life_time
= 512000,
65 .packet_detection_threshold
= 0,
66 .ps_poll_timeout
= 15,
68 .rts_threshold
= 2347,
69 .rx_cca_threshold
= 0xFFEF,
70 .irq_blk_threshold
= 0,
71 .irq_pkt_threshold
= USHORT_MAX
,
73 .queue_type
= CONF_RX_QUEUE_TYPE_LOW_PRIORITY
,
76 .tx_energy_detection
= 0,
78 .enabled_rates
= CONF_TX_RATE_MASK_UNSPECIFIED
,
79 .short_retry_limit
= 10,
80 .long_retry_limit
= 10,
103 .aifsn
= CONF_TX_AIFS_PIFS
,
110 .aifsn
= CONF_TX_AIFS_PIFS
,
118 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
119 .tsid
= CONF_TX_AC_BE
,
120 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
121 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
126 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
127 .tsid
= CONF_TX_AC_BE
,
128 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
129 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
134 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
135 .tsid
= CONF_TX_AC_BE
,
136 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
137 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
142 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
143 .tsid
= CONF_TX_AC_BE
,
144 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
145 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
150 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
151 .tsid
= CONF_TX_AC_BE
,
152 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
153 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
158 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
159 .tsid
= CONF_TX_AC_BE
,
160 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
161 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
166 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
167 .tsid
= CONF_TX_AC_BE
,
168 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
169 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
173 .frag_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
,
174 .tx_compl_timeout
= 5,
175 .tx_compl_threshold
= 5
178 .wake_up_event
= CONF_WAKE_UP_EVENT_DTIM
,
179 .listen_interval
= 0,
180 .bcn_filt_mode
= CONF_BCN_FILT_MODE_ENABLED
,
181 .bcn_filt_ie_count
= 1,
184 .ie
= WLAN_EID_CHANNEL_SWITCH
,
185 .rule
= CONF_BCN_RULE_PASS_ON_APPEARANCE
,
188 .synch_fail_thold
= 5,
189 .bss_lose_timeout
= 100,
190 .beacon_rx_timeout
= 10000,
191 .broadcast_timeout
= 20000,
192 .rx_broadcast_in_ps
= 1,
193 .ps_poll_threshold
= 4,
194 .sig_trigger_count
= 2,
199 .metric
= CONF_TRIG_METRIC_RSSI_BEACON
,
200 .type
= CONF_TRIG_EVENT_TYPE_EDGE
,
201 .direction
= CONF_TRIG_EVENT_DIR_LOW
,
209 .metric
= CONF_TRIG_METRIC_RSSI_BEACON
,
210 .type
= CONF_TRIG_EVENT_TYPE_EDGE
,
211 .direction
= CONF_TRIG_EVENT_DIR_HIGH
,
218 .rssi_bcn_avg_weight
= 10,
219 .rssi_pkt_avg_weight
= 10,
220 .snr_bcn_avg_weight
= 10,
221 .snr_pkt_avg_weight
= 10
223 .bet_enable
= CONF_BET_MODE_ENABLE
,
224 .bet_max_consecutive
= 100
232 0x18, 0x10, 0x05, 0xfb, 0xf0, 0xe8,
239 0x18, 0x10, 0x05, 0xf6, 0xf0, 0xe8,
246 0x18, 0x10, 0x05, 0xfb, 0xf0, 0xe8,
253 * FIXME: The correct value CONF_REF_CLK_38_4_E
254 * causes the firmware to crash on boot.
255 * The value 5 apparently is an
256 * unnoficial XTAL configuration of the
257 * same frequency, which appears to work.
261 .clk_valid_on_wakeup
= 0,
263 .single_dual_band
= CONF_SINGLE_BAND
,
264 .tx_bip_fem_autodetect
= 0,
265 .tx_bip_fem_manufacturer
= 1,
271 .rx_rssi_and_proc_compens
= {
272 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8,
273 0xfc, 0x00, 0x08, 0x10, 0xf0, 0xf8,
275 .rx_trace_loss_5
= { 0, 0, 0, 0, 0, 0, 0 },
276 .tx_trace_loss_5
= { 0, 0, 0, 0, 0, 0, 0 },
277 .rx_rssi_and_proc_compens_5
= {
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281 .tx_ref_pd_voltage
= 0x24e,
282 .tx_ref_power
= 0x78,
284 .tx_rate_limits_normal
= {
285 0x1e, 0x1f, 0x22, 0x24, 0x28, 0x29 },
286 .tx_rate_limits_degraded
= {
287 0x1b, 0x1c, 0x1e, 0x20, 0x24, 0x25 },
288 .tx_channel_limits_11b
= {
289 0x22, 0x50, 0x50, 0x50, 0x50, 0x50,
290 0x50, 0x50, 0x50, 0x50, 0x22, 0x50,
292 .tx_channel_limits_ofdm
= {
293 0x20, 0x50, 0x50, 0x50, 0x50, 0x50,
294 0x50, 0x50, 0x50, 0x50, 0x20, 0x50,
296 .tx_pdv_rate_offsets
= {
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
299 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x27 },
300 .rx_fem_insertion_loss
= 0x14,
301 .tx_ref_pd_voltage_5
= {
302 0x0190, 0x01a4, 0x01c3, 0x01d8,
305 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 },
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
308 .tx_rate_limits_normal_5
= {
309 0x1b, 0x1e, 0x21, 0x23, 0x27, 0x00 },
310 .tx_rate_limits_degraded_5
= {
311 0x1b, 0x1e, 0x21, 0x23, 0x27, 0x00 },
312 .tx_channel_limits_ofdm_5
= {
313 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
314 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
315 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
316 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
318 .tx_pdv_rate_offsets_5
= {
319 0x01, 0x02, 0x02, 0x02, 0x02, 0x00 },
321 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 },
322 .rx_fem_insertion_loss_5
= {
323 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }
328 static void wl1271_conf_init(struct wl1271
*wl
)
332 * This function applies the default configuration to the driver. This
333 * function is invoked upon driver load (spi probe.)
335 * The configuration is stored in a run-time structure in order to
336 * facilitate for run-time adjustment of any of the parameters. Making
337 * changes to the configuration structure will apply the new values on
338 * the next interface up (wl1271_op_start.)
341 /* apply driver default configuration */
342 memcpy(&wl
->conf
, &default_conf
, sizeof(default_conf
));
344 if (wl1271_11a_enabled())
345 wl
->conf
.init
.genparam
.single_dual_band
= CONF_DUAL_BAND
;
349 static int wl1271_plt_init(struct wl1271
*wl
)
353 ret
= wl1271_acx_init_mem_config(wl
);
357 ret
= wl1271_cmd_data_path(wl
, wl
->channel
, 1);
364 static void wl1271_disable_interrupts(struct wl1271
*wl
)
366 disable_irq(wl
->irq
);
369 static void wl1271_power_off(struct wl1271
*wl
)
371 wl
->set_power(false);
374 static void wl1271_power_on(struct wl1271
*wl
)
379 static void wl1271_fw_status(struct wl1271
*wl
,
380 struct wl1271_fw_status
*status
)
385 wl1271_spi_read(wl
, FW_STATUS_ADDR
, status
,
386 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
= status
->tx_released_blks
[i
] - wl
->tx_blocks_freed
[i
];
398 wl
->tx_blocks_freed
[i
] = status
->tx_released_blks
[i
];
399 wl
->tx_blocks_available
+= cnt
;
403 /* if more blocks are available now, schedule some tx work */
404 if (total
&& !skb_queue_empty(&wl
->tx_queue
))
405 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
407 /* update the host-chipset time offset */
408 wl
->time_offset
= jiffies_to_usecs(jiffies
) - status
->fw_localtime
;
411 static void wl1271_irq_work(struct work_struct
*work
)
416 container_of(work
, struct wl1271
, irq_work
);
418 mutex_lock(&wl
->mutex
);
420 wl1271_debug(DEBUG_IRQ
, "IRQ work");
422 if (wl
->state
== WL1271_STATE_OFF
)
425 ret
= wl1271_ps_elp_wakeup(wl
, true);
429 wl1271_spi_write32(wl
, ACX_REG_INTERRUPT_MASK
, WL1271_ACX_INTR_ALL
);
431 wl1271_fw_status(wl
, wl
->fw_status
);
432 intr
= wl
->fw_status
->intr
;
434 wl1271_debug(DEBUG_IRQ
, "Zero interrupt received.");
438 intr
&= WL1271_INTR_MASK
;
440 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
441 bool do_ack
= (intr
& WL1271_ACX_INTR_EVENT_B
) ? false : true;
442 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
443 wl1271_event_handle(wl
, 0, do_ack
);
446 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
447 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
448 wl1271_event_handle(wl
, 1, true);
451 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
452 wl1271_debug(DEBUG_IRQ
,
453 "WL1271_ACX_INTR_INIT_COMPLETE");
455 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
456 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
458 if (intr
& WL1271_ACX_INTR_DATA
) {
459 u8 tx_res_cnt
= wl
->fw_status
->tx_results_counter
-
460 wl
->tx_results_count
;
462 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
464 /* check for tx results */
466 wl1271_tx_complete(wl
, tx_res_cnt
);
468 wl1271_rx(wl
, wl
->fw_status
);
472 wl1271_spi_write32(wl
, ACX_REG_INTERRUPT_MASK
,
473 WL1271_ACX_INTR_ALL
& ~(WL1271_INTR_MASK
));
474 wl1271_ps_elp_sleep(wl
);
477 mutex_unlock(&wl
->mutex
);
480 static irqreturn_t
wl1271_irq(int irq
, void *cookie
)
485 wl1271_debug(DEBUG_IRQ
, "IRQ");
489 /* complete the ELP completion */
490 spin_lock_irqsave(&wl
->wl_lock
, flags
);
492 complete(wl
->elp_compl
);
493 wl
->elp_compl
= NULL
;
496 ieee80211_queue_work(wl
->hw
, &wl
->irq_work
);
497 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
502 static int wl1271_fetch_firmware(struct wl1271
*wl
)
504 const struct firmware
*fw
;
507 ret
= request_firmware(&fw
, WL1271_FW_NAME
, &wl
->spi
->dev
);
510 wl1271_error("could not get firmware: %d", ret
);
515 wl1271_error("firmware size is not multiple of 32 bits: %zu",
521 wl
->fw_len
= fw
->size
;
522 wl
->fw
= vmalloc(wl
->fw_len
);
525 wl1271_error("could not allocate memory for the firmware");
530 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
535 release_firmware(fw
);
540 static int wl1271_fetch_nvs(struct wl1271
*wl
)
542 const struct firmware
*fw
;
545 ret
= request_firmware(&fw
, WL1271_NVS_NAME
, &wl
->spi
->dev
);
548 wl1271_error("could not get nvs file: %d", ret
);
553 wl1271_error("nvs size is not multiple of 32 bits: %zu",
559 wl
->nvs_len
= fw
->size
;
560 wl
->nvs
= kmalloc(wl
->nvs_len
, GFP_KERNEL
);
563 wl1271_error("could not allocate memory for the nvs file");
568 memcpy(wl
->nvs
, fw
->data
, wl
->nvs_len
);
573 release_firmware(fw
);
578 static void wl1271_fw_wakeup(struct wl1271
*wl
)
582 elp_reg
= ELPCTRL_WAKE_UP
;
583 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, elp_reg
);
586 static int wl1271_setup(struct wl1271
*wl
)
588 wl
->fw_status
= kmalloc(sizeof(*wl
->fw_status
), GFP_KERNEL
);
592 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
593 if (!wl
->tx_res_if
) {
594 kfree(wl
->fw_status
);
598 INIT_WORK(&wl
->irq_work
, wl1271_irq_work
);
599 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
603 static int wl1271_chip_wakeup(struct wl1271
*wl
)
605 struct wl1271_partition_set partition
;
609 msleep(WL1271_POWER_ON_SLEEP
);
610 wl1271_spi_reset(wl
);
613 /* We don't need a real memory partition here, because we only want
614 * to use the registers at this point. */
615 memset(&partition
, 0, sizeof(partition
));
616 partition
.reg
.start
= REGISTERS_BASE
;
617 partition
.reg
.size
= REGISTERS_DOWN_SIZE
;
618 wl1271_set_partition(wl
, &partition
);
620 /* ELP module wake up */
621 wl1271_fw_wakeup(wl
);
623 /* whal_FwCtrl_BootSm() */
625 /* 0. read chip id from CHIP_ID */
626 wl
->chip
.id
= wl1271_spi_read32(wl
, CHIP_ID_B
);
628 /* 1. check if chip id is valid */
630 switch (wl
->chip
.id
) {
631 case CHIP_ID_1271_PG10
:
632 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
635 ret
= wl1271_setup(wl
);
639 case CHIP_ID_1271_PG20
:
640 wl1271_debug(DEBUG_BOOT
, "chip id 0x%x (1271 PG20)",
643 ret
= wl1271_setup(wl
);
648 wl1271_error("unsupported chip id: 0x%x", wl
->chip
.id
);
653 if (wl
->fw
== NULL
) {
654 ret
= wl1271_fetch_firmware(wl
);
659 /* No NVS from netlink, try to get it from the filesystem */
660 if (wl
->nvs
== NULL
) {
661 ret
= wl1271_fetch_nvs(wl
);
669 wl1271_power_off(wl
);
675 struct wl1271_filter_params
{
676 unsigned int filters
;
677 unsigned int changed
;
679 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
682 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
685 FIF_BCN_PRBRESP_PROMISC | \
689 static void wl1271_filter_work(struct work_struct
*work
)
692 container_of(work
, struct wl1271
, filter_work
);
693 struct wl1271_filter_params
*fp
;
698 /* first, get the filter parameters */
699 spin_lock_irqsave(&wl
->wl_lock
, flags
);
700 fp
= wl
->filter_params
;
701 wl
->filter_params
= NULL
;
702 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
707 /* then, lock the mutex without risk of lock-up */
708 mutex_lock(&wl
->mutex
);
710 if (wl
->state
== WL1271_STATE_OFF
)
713 ret
= wl1271_ps_elp_wakeup(wl
, false);
717 /* configure the mc filter regardless of the changed flags */
718 if (fp
->filters
& FIF_ALLMULTI
)
721 ret
= wl1271_acx_group_address_tbl(wl
, enabled
,
722 fp
->mc_list
, fp
->mc_list_length
);
726 /* determine, whether supported filter values have changed */
727 if (fp
->changed
== 0)
730 /* apply configured filters */
731 ret
= wl1271_acx_rx_config(wl
, wl
->rx_config
, wl
->rx_filter
);
736 wl1271_ps_elp_sleep(wl
);
739 mutex_unlock(&wl
->mutex
);
743 int wl1271_plt_start(struct wl1271
*wl
)
747 mutex_lock(&wl
->mutex
);
749 wl1271_notice("power up");
751 if (wl
->state
!= WL1271_STATE_OFF
) {
752 wl1271_error("cannot go into PLT state because not "
753 "in off state: %d", wl
->state
);
758 wl
->state
= WL1271_STATE_PLT
;
760 ret
= wl1271_chip_wakeup(wl
);
764 ret
= wl1271_boot(wl
);
768 wl1271_notice("firmware booted in PLT mode (%s)", wl
->chip
.fw_ver
);
770 ret
= wl1271_plt_init(wl
);
772 goto out_irq_disable
;
777 wl1271_disable_interrupts(wl
);
780 wl1271_power_off(wl
);
783 mutex_unlock(&wl
->mutex
);
788 int wl1271_plt_stop(struct wl1271
*wl
)
792 mutex_lock(&wl
->mutex
);
794 wl1271_notice("power down");
796 if (wl
->state
!= WL1271_STATE_PLT
) {
797 wl1271_error("cannot power down because not in PLT "
798 "state: %d", wl
->state
);
803 wl1271_disable_interrupts(wl
);
804 wl1271_power_off(wl
);
806 wl
->state
= WL1271_STATE_OFF
;
809 mutex_unlock(&wl
->mutex
);
815 static int wl1271_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
817 struct wl1271
*wl
= hw
->priv
;
819 skb_queue_tail(&wl
->tx_queue
, skb
);
822 * The chip specific setup must run before the first TX packet -
823 * before that, the tx_work will not be initialized!
826 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
829 * The workqueue is slow to process the tx_queue and we need stop
830 * the queue here, otherwise the queue will get too long.
832 if (skb_queue_len(&wl
->tx_queue
) >= WL1271_TX_QUEUE_MAX_LENGTH
) {
833 ieee80211_stop_queues(wl
->hw
);
836 * FIXME: this is racy, the variable is not properly
837 * protected. Maybe fix this by removing the stupid
838 * variable altogether and checking the real queue state?
840 wl
->tx_queue_stopped
= true;
846 static int wl1271_op_start(struct ieee80211_hw
*hw
)
848 struct wl1271
*wl
= hw
->priv
;
851 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
853 mutex_lock(&wl
->mutex
);
855 if (wl
->state
!= WL1271_STATE_OFF
) {
856 wl1271_error("cannot start because not in off state: %d",
862 ret
= wl1271_chip_wakeup(wl
);
866 ret
= wl1271_boot(wl
);
870 ret
= wl1271_hw_init(wl
);
872 goto out_irq_disable
;
874 wl
->state
= WL1271_STATE_ON
;
876 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver
);
881 wl1271_disable_interrupts(wl
);
884 wl1271_power_off(wl
);
887 mutex_unlock(&wl
->mutex
);
892 static void wl1271_op_stop(struct ieee80211_hw
*hw
)
894 struct wl1271
*wl
= hw
->priv
;
900 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
902 /* complete/cancel ongoing work */
903 cancel_work_sync(&wl
->filter_work
);
904 spin_lock_irqsave(&wl
->wl_lock
, flags
);
905 kfree(wl
->filter_params
);
906 wl
->filter_params
= NULL
;
907 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
909 mutex_lock(&wl
->mutex
);
911 WARN_ON(wl
->state
!= WL1271_STATE_ON
);
914 mutex_unlock(&wl
->mutex
);
915 ieee80211_scan_completed(wl
->hw
, true);
916 mutex_lock(&wl
->mutex
);
917 wl
->scanning
= false;
920 wl
->state
= WL1271_STATE_OFF
;
922 wl1271_disable_interrupts(wl
);
924 mutex_unlock(&wl
->mutex
);
926 cancel_work_sync(&wl
->irq_work
);
927 cancel_work_sync(&wl
->tx_work
);
928 cancel_work_sync(&wl
->filter_work
);
930 mutex_lock(&wl
->mutex
);
932 /* let's notify MAC80211 about the remaining pending TX frames */
934 wl1271_power_off(wl
);
936 memset(wl
->bssid
, 0, ETH_ALEN
);
937 memset(wl
->ssid
, 0, IW_ESSID_MAX_SIZE
+ 1);
939 wl
->bss_type
= MAX_BSS_TYPE
;
940 wl
->band
= IEEE80211_BAND_2GHZ
;
945 wl
->tx_queue_stopped
= false;
946 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
947 wl
->tx_blocks_available
= 0;
948 wl
->tx_results_count
= 0;
949 wl
->tx_packets_count
= 0;
950 wl
->tx_security_last_seq
= 0;
951 wl
->tx_security_seq_16
= 0;
952 wl
->tx_security_seq_32
= 0;
954 wl
->session_counter
= 0;
957 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
958 wl
->tx_blocks_freed
[i
] = 0;
960 wl1271_debugfs_reset(wl
);
961 mutex_unlock(&wl
->mutex
);
964 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
965 struct ieee80211_if_init_conf
*conf
)
967 struct wl1271
*wl
= hw
->priv
;
970 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
971 conf
->type
, conf
->mac_addr
);
973 mutex_lock(&wl
->mutex
);
981 switch (conf
->type
) {
982 case NL80211_IFTYPE_STATION
:
983 wl
->bss_type
= BSS_TYPE_STA_BSS
;
985 case NL80211_IFTYPE_ADHOC
:
986 wl
->bss_type
= BSS_TYPE_IBSS
;
993 /* FIXME: what if conf->mac_addr changes? */
996 mutex_unlock(&wl
->mutex
);
1000 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
1001 struct ieee80211_if_init_conf
*conf
)
1003 struct wl1271
*wl
= hw
->priv
;
1005 mutex_lock(&wl
->mutex
);
1006 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
1008 mutex_unlock(&wl
->mutex
);
1012 static int wl1271_op_config_interface(struct ieee80211_hw
*hw
,
1013 struct ieee80211_vif
*vif
,
1014 struct ieee80211_if_conf
*conf
)
1016 struct wl1271
*wl
= hw
->priv
;
1017 struct sk_buff
*beacon
;
1020 wl1271_debug(DEBUG_MAC80211
, "mac80211 config_interface bssid %pM",
1022 wl1271_dump_ascii(DEBUG_MAC80211
, "ssid: ", conf
->ssid
,
1025 mutex_lock(&wl
->mutex
);
1027 ret
= wl1271_ps_elp_wakeup(wl
, false);
1031 if (memcmp(wl
->bssid
, conf
->bssid
, ETH_ALEN
)) {
1032 wl1271_debug(DEBUG_MAC80211
, "bssid changed");
1034 memcpy(wl
->bssid
, conf
->bssid
, ETH_ALEN
);
1036 ret
= wl1271_cmd_join(wl
);
1041 ret
= wl1271_cmd_build_null_data(wl
);
1045 wl
->ssid_len
= conf
->ssid_len
;
1047 memcpy(wl
->ssid
, conf
->ssid
, wl
->ssid_len
);
1049 if (conf
->changed
& IEEE80211_IFCC_BEACON
) {
1050 beacon
= ieee80211_beacon_get(hw
, vif
);
1051 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
,
1052 beacon
->data
, beacon
->len
);
1055 dev_kfree_skb(beacon
);
1059 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PROBE_RESPONSE
,
1060 beacon
->data
, beacon
->len
);
1062 dev_kfree_skb(beacon
);
1069 wl1271_ps_elp_sleep(wl
);
1072 mutex_unlock(&wl
->mutex
);
1078 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
1080 struct wl1271
*wl
= hw
->priv
;
1081 struct ieee80211_conf
*conf
= &hw
->conf
;
1082 int channel
, ret
= 0;
1084 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
1086 wl1271_debug(DEBUG_MAC80211
, "mac80211 config ch %d psm %s power %d",
1088 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
1091 mutex_lock(&wl
->mutex
);
1093 wl
->band
= conf
->channel
->band
;
1095 ret
= wl1271_ps_elp_wakeup(wl
, false);
1099 if (channel
!= wl
->channel
) {
1101 * We assume that the stack will configure the right channel
1102 * before associating, so we don't need to send a join
1103 * command here. We will join the right channel when the
1106 wl
->channel
= channel
;
1109 ret
= wl1271_cmd_build_null_data(wl
);
1113 if (conf
->flags
& IEEE80211_CONF_PS
&& !wl
->psm_requested
) {
1114 wl1271_info("psm enabled");
1116 wl
->psm_requested
= true;
1119 * We enter PSM only if we're already associated.
1120 * If we're not, we'll enter it when joining an SSID,
1121 * through the bss_info_changed() hook.
1123 ret
= wl1271_ps_set_mode(wl
, STATION_POWER_SAVE_MODE
);
1124 } else if (!(conf
->flags
& IEEE80211_CONF_PS
) &&
1125 wl
->psm_requested
) {
1126 wl1271_info("psm disabled");
1128 wl
->psm_requested
= false;
1131 ret
= wl1271_ps_set_mode(wl
, STATION_ACTIVE_MODE
);
1134 if (conf
->power_level
!= wl
->power_level
) {
1135 ret
= wl1271_acx_tx_power(wl
, conf
->power_level
);
1139 wl
->power_level
= conf
->power_level
;
1143 wl1271_ps_elp_sleep(wl
);
1146 mutex_unlock(&wl
->mutex
);
1151 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
, int mc_count
,
1152 struct dev_addr_list
*mc_list
)
1154 struct wl1271
*wl
= hw
->priv
;
1155 struct wl1271_filter_params
*fp
;
1156 unsigned long flags
;
1160 * FIXME: we should return a hash that will be passed to
1161 * configure_filter() instead of saving everything in the context.
1164 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
1166 wl1271_error("Out of memory setting filters.");
1170 /* update multicast filtering parameters */
1171 if (mc_count
> ACX_MC_ADDRESS_GROUP_MAX
) {
1173 fp
->filters
|= FIF_ALLMULTI
;
1176 fp
->mc_list_length
= 0;
1177 for (i
= 0; i
< mc_count
; i
++) {
1178 if (mc_list
->da_addrlen
== ETH_ALEN
) {
1179 memcpy(fp
->mc_list
[fp
->mc_list_length
],
1180 mc_list
->da_addr
, ETH_ALEN
);
1181 fp
->mc_list_length
++;
1183 wl1271_warning("Unknown mc address length.");
1184 mc_list
= mc_list
->next
;
1187 /* FIXME: We still need to set our filters properly */
1189 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1190 kfree(wl
->filter_params
);
1191 wl
->filter_params
= fp
;
1192 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1197 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
1198 unsigned int changed
,
1199 unsigned int *total
, u64 multicast
)
1201 struct wl1271
*wl
= hw
->priv
;
1203 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter");
1205 *total
&= WL1271_SUPPORTED_FILTERS
;
1206 changed
&= WL1271_SUPPORTED_FILTERS
;
1212 * FIXME: for now we are still using a workqueue for filter
1213 * configuration, but with the new mac80211, this is not needed,
1214 * since configure_filter can now sleep. We now have
1215 * prepare_multicast, which needs to be atomic instead.
1218 /* store current filter config */
1219 wl
->filter_params
->filters
= *total
;
1220 wl
->filter_params
->changed
= changed
;
1222 ieee80211_queue_work(wl
->hw
, &wl
->filter_work
);
1225 static int wl1271_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1226 struct ieee80211_vif
*vif
,
1227 struct ieee80211_sta
*sta
,
1228 struct ieee80211_key_conf
*key_conf
)
1230 struct wl1271
*wl
= hw
->priv
;
1237 static const u8 bcast_addr
[ETH_ALEN
] =
1238 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1240 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
1242 addr
= sta
? sta
->addr
: bcast_addr
;
1244 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x", cmd
);
1245 wl1271_dump(DEBUG_CRYPT
, "ADDR: ", addr
, ETH_ALEN
);
1246 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
1247 key_conf
->alg
, key_conf
->keyidx
,
1248 key_conf
->keylen
, key_conf
->flags
);
1249 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
1251 if (is_zero_ether_addr(addr
)) {
1252 /* We dont support TX only encryption */
1257 mutex_lock(&wl
->mutex
);
1259 ret
= wl1271_ps_elp_wakeup(wl
, false);
1263 switch (key_conf
->alg
) {
1267 key_conf
->hw_key_idx
= key_conf
->keyidx
;
1270 key_type
= KEY_TKIP
;
1272 key_conf
->hw_key_idx
= key_conf
->keyidx
;
1273 tx_seq_32
= wl
->tx_security_seq_32
;
1274 tx_seq_16
= wl
->tx_security_seq_16
;
1279 key_conf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1280 tx_seq_32
= wl
->tx_security_seq_32
;
1281 tx_seq_16
= wl
->tx_security_seq_16
;
1284 wl1271_error("Unknown key algo 0x%x", key_conf
->alg
);
1292 ret
= wl1271_cmd_set_key(wl
, KEY_ADD_OR_REPLACE
,
1293 key_conf
->keyidx
, key_type
,
1294 key_conf
->keylen
, key_conf
->key
,
1295 addr
, tx_seq_32
, tx_seq_16
);
1297 wl1271_error("Could not add or replace key");
1303 ret
= wl1271_cmd_set_key(wl
, KEY_REMOVE
,
1304 key_conf
->keyidx
, key_type
,
1305 key_conf
->keylen
, key_conf
->key
,
1308 wl1271_error("Could not remove key");
1314 wl1271_error("Unsupported key cmd 0x%x", cmd
);
1322 wl1271_ps_elp_sleep(wl
);
1325 mutex_unlock(&wl
->mutex
);
1331 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
1332 struct cfg80211_scan_request
*req
)
1334 struct wl1271
*wl
= hw
->priv
;
1339 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
1342 ssid
= req
->ssids
[0].ssid
;
1343 len
= req
->ssids
[0].ssid_len
;
1346 mutex_lock(&wl
->mutex
);
1348 ret
= wl1271_ps_elp_wakeup(wl
, false);
1352 if (wl1271_11a_enabled())
1353 ret
= wl1271_cmd_scan(hw
->priv
, ssid
, len
, 1, 0,
1354 WL1271_SCAN_BAND_DUAL
, 3);
1356 ret
= wl1271_cmd_scan(hw
->priv
, ssid
, len
, 1, 0,
1357 WL1271_SCAN_BAND_2_4_GHZ
, 3);
1359 wl1271_ps_elp_sleep(wl
);
1362 mutex_unlock(&wl
->mutex
);
1367 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1369 struct wl1271
*wl
= hw
->priv
;
1372 mutex_lock(&wl
->mutex
);
1374 ret
= wl1271_ps_elp_wakeup(wl
, false);
1378 ret
= wl1271_acx_rts_threshold(wl
, (u16
) value
);
1380 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret
);
1382 wl1271_ps_elp_sleep(wl
);
1385 mutex_unlock(&wl
->mutex
);
1390 static u32
wl1271_enabled_rates_get(struct wl1271
*wl
, u64 basic_rate_set
)
1392 struct ieee80211_supported_band
*band
;
1393 u32 enabled_rates
= 0;
1396 band
= wl
->hw
->wiphy
->bands
[wl
->band
];
1397 for (bit
= 0; bit
< band
->n_bitrates
; bit
++) {
1398 if (basic_rate_set
& 0x1)
1399 enabled_rates
|= band
->bitrates
[bit
].hw_value
;
1400 basic_rate_set
>>= 1;
1403 return enabled_rates
;
1406 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
1407 struct ieee80211_vif
*vif
,
1408 struct ieee80211_bss_conf
*bss_conf
,
1411 enum wl1271_cmd_ps_mode mode
;
1412 struct wl1271
*wl
= hw
->priv
;
1415 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info changed");
1417 mutex_lock(&wl
->mutex
);
1419 ret
= wl1271_ps_elp_wakeup(wl
, false);
1423 if (changed
& BSS_CHANGED_ASSOC
) {
1424 if (bss_conf
->assoc
) {
1425 wl
->aid
= bss_conf
->aid
;
1428 * with wl1271, we don't need to update the
1429 * beacon_int and dtim_period, because the firmware
1430 * updates it by itself when the first beacon is
1431 * received after a join.
1433 ret
= wl1271_cmd_build_ps_poll(wl
, wl
->aid
);
1437 ret
= wl1271_acx_aid(wl
, wl
->aid
);
1441 /* If we want to go in PSM but we're not there yet */
1442 if (wl
->psm_requested
&& !wl
->psm
) {
1443 mode
= STATION_POWER_SAVE_MODE
;
1444 ret
= wl1271_ps_set_mode(wl
, mode
);
1449 /* use defaults when not associated */
1450 wl
->basic_rate_set
= WL1271_DEFAULT_BASIC_RATE_SET
;
1456 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1457 if (bss_conf
->use_short_slot
)
1458 ret
= wl1271_acx_slot(wl
, SLOT_TIME_SHORT
);
1460 ret
= wl1271_acx_slot(wl
, SLOT_TIME_LONG
);
1462 wl1271_warning("Set slot time failed %d", ret
);
1467 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1468 if (bss_conf
->use_short_preamble
)
1469 wl1271_acx_set_preamble(wl
, ACX_PREAMBLE_SHORT
);
1471 wl1271_acx_set_preamble(wl
, ACX_PREAMBLE_LONG
);
1474 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1475 if (bss_conf
->use_cts_prot
)
1476 ret
= wl1271_acx_cts_protect(wl
, CTSPROTECT_ENABLE
);
1478 ret
= wl1271_acx_cts_protect(wl
, CTSPROTECT_DISABLE
);
1480 wl1271_warning("Set ctsprotect failed %d", ret
);
1485 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1486 wl
->basic_rate_set
= wl1271_enabled_rates_get(
1487 wl
, bss_conf
->basic_rates
);
1489 ret
= wl1271_acx_rate_policies(wl
, wl
->basic_rate_set
);
1491 wl1271_warning("Set rate policies failed %d", ret
);
1497 wl1271_ps_elp_sleep(wl
);
1500 mutex_unlock(&wl
->mutex
);
1504 /* can't be const, mac80211 writes to this */
1505 static struct ieee80211_rate wl1271_rates
[] = {
1507 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
1508 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
1510 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
1511 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
1512 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1514 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
1515 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
1516 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1518 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
1519 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
1520 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1522 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
1523 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
1525 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
1526 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
1528 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
1529 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
1531 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
1532 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
1534 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
1535 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
1537 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
1538 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
1540 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
1541 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
1543 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
1544 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
1547 /* can't be const, mac80211 writes to this */
1548 static struct ieee80211_channel wl1271_channels
[] = {
1549 { .hw_value
= 1, .center_freq
= 2412},
1550 { .hw_value
= 2, .center_freq
= 2417},
1551 { .hw_value
= 3, .center_freq
= 2422},
1552 { .hw_value
= 4, .center_freq
= 2427},
1553 { .hw_value
= 5, .center_freq
= 2432},
1554 { .hw_value
= 6, .center_freq
= 2437},
1555 { .hw_value
= 7, .center_freq
= 2442},
1556 { .hw_value
= 8, .center_freq
= 2447},
1557 { .hw_value
= 9, .center_freq
= 2452},
1558 { .hw_value
= 10, .center_freq
= 2457},
1559 { .hw_value
= 11, .center_freq
= 2462},
1560 { .hw_value
= 12, .center_freq
= 2467},
1561 { .hw_value
= 13, .center_freq
= 2472},
1564 /* can't be const, mac80211 writes to this */
1565 static struct ieee80211_supported_band wl1271_band_2ghz
= {
1566 .channels
= wl1271_channels
,
1567 .n_channels
= ARRAY_SIZE(wl1271_channels
),
1568 .bitrates
= wl1271_rates
,
1569 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
1572 /* 5 GHz data rates for WL1273 */
1573 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
1575 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
1576 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
1578 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
1579 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
1581 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
1582 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
1584 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
1585 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
1587 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
1588 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
1590 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
1591 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
1593 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
1594 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
1596 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
1597 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
1600 /* 5 GHz band channels for WL1273 */
1601 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
1602 { .hw_value
= 183, .center_freq
= 4915},
1603 { .hw_value
= 184, .center_freq
= 4920},
1604 { .hw_value
= 185, .center_freq
= 4925},
1605 { .hw_value
= 187, .center_freq
= 4935},
1606 { .hw_value
= 188, .center_freq
= 4940},
1607 { .hw_value
= 189, .center_freq
= 4945},
1608 { .hw_value
= 192, .center_freq
= 4960},
1609 { .hw_value
= 196, .center_freq
= 4980},
1610 { .hw_value
= 7, .center_freq
= 5035},
1611 { .hw_value
= 8, .center_freq
= 5040},
1612 { .hw_value
= 9, .center_freq
= 5045},
1613 { .hw_value
= 11, .center_freq
= 5055},
1614 { .hw_value
= 12, .center_freq
= 5060},
1615 { .hw_value
= 16, .center_freq
= 5080},
1616 { .hw_value
= 34, .center_freq
= 5170},
1617 { .hw_value
= 36, .center_freq
= 5180},
1618 { .hw_value
= 38, .center_freq
= 5190},
1619 { .hw_value
= 40, .center_freq
= 5200},
1620 { .hw_value
= 42, .center_freq
= 5210},
1621 { .hw_value
= 44, .center_freq
= 5220},
1622 { .hw_value
= 46, .center_freq
= 5230},
1623 { .hw_value
= 48, .center_freq
= 5240},
1624 { .hw_value
= 52, .center_freq
= 5260},
1625 { .hw_value
= 56, .center_freq
= 5280},
1626 { .hw_value
= 60, .center_freq
= 5300},
1627 { .hw_value
= 64, .center_freq
= 5320},
1628 { .hw_value
= 100, .center_freq
= 5500},
1629 { .hw_value
= 104, .center_freq
= 5520},
1630 { .hw_value
= 108, .center_freq
= 5540},
1631 { .hw_value
= 112, .center_freq
= 5560},
1632 { .hw_value
= 116, .center_freq
= 5580},
1633 { .hw_value
= 120, .center_freq
= 5600},
1634 { .hw_value
= 124, .center_freq
= 5620},
1635 { .hw_value
= 128, .center_freq
= 5640},
1636 { .hw_value
= 132, .center_freq
= 5660},
1637 { .hw_value
= 136, .center_freq
= 5680},
1638 { .hw_value
= 140, .center_freq
= 5700},
1639 { .hw_value
= 149, .center_freq
= 5745},
1640 { .hw_value
= 153, .center_freq
= 5765},
1641 { .hw_value
= 157, .center_freq
= 5785},
1642 { .hw_value
= 161, .center_freq
= 5805},
1643 { .hw_value
= 165, .center_freq
= 5825},
1647 static struct ieee80211_supported_band wl1271_band_5ghz
= {
1648 .channels
= wl1271_channels_5ghz
,
1649 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
1650 .bitrates
= wl1271_rates_5ghz
,
1651 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
1654 static const struct ieee80211_ops wl1271_ops
= {
1655 .start
= wl1271_op_start
,
1656 .stop
= wl1271_op_stop
,
1657 .add_interface
= wl1271_op_add_interface
,
1658 .remove_interface
= wl1271_op_remove_interface
,
1659 .config
= wl1271_op_config
,
1660 /* .config_interface = wl1271_op_config_interface, */
1661 .prepare_multicast
= wl1271_op_prepare_multicast
,
1662 .configure_filter
= wl1271_op_configure_filter
,
1664 .set_key
= wl1271_op_set_key
,
1665 .hw_scan
= wl1271_op_hw_scan
,
1666 .bss_info_changed
= wl1271_op_bss_info_changed
,
1667 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
1670 static int wl1271_register_hw(struct wl1271
*wl
)
1674 if (wl
->mac80211_registered
)
1677 SET_IEEE80211_PERM_ADDR(wl
->hw
, wl
->mac_addr
);
1679 ret
= ieee80211_register_hw(wl
->hw
);
1681 wl1271_error("unable to register mac80211 hw: %d", ret
);
1685 wl
->mac80211_registered
= true;
1687 wl1271_notice("loaded");
1692 static int wl1271_init_ieee80211(struct wl1271
*wl
)
1694 /* The tx descriptor buffer and the TKIP space. */
1695 wl
->hw
->extra_tx_headroom
= WL1271_TKIP_IV_SPACE
+
1696 sizeof(struct wl1271_tx_hw_descr
);
1699 /* FIXME: find a proper value */
1700 wl
->hw
->channel_change_time
= 10000;
1702 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
1703 IEEE80211_HW_NOISE_DBM
|
1704 IEEE80211_HW_BEACON_FILTER
;
1706 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
1707 wl
->hw
->wiphy
->max_scan_ssids
= 1;
1708 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &wl1271_band_2ghz
;
1710 if (wl1271_11a_enabled())
1711 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &wl1271_band_5ghz
;
1713 SET_IEEE80211_DEV(wl
->hw
, &wl
->spi
->dev
);
1718 static void wl1271_device_release(struct device
*dev
)
1723 static struct platform_device wl1271_device
= {
1727 /* device model insists to have a release function */
1729 .release
= wl1271_device_release
,
1733 #define WL1271_DEFAULT_CHANNEL 0
1734 static int __devinit
wl1271_probe(struct spi_device
*spi
)
1736 struct wl12xx_platform_data
*pdata
;
1737 struct ieee80211_hw
*hw
;
1740 static const u8 nokia_oui
[3] = {0x00, 0x1f, 0xdf};
1742 pdata
= spi
->dev
.platform_data
;
1744 wl1271_error("no platform data");
1748 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
1750 wl1271_error("could not alloc ieee80211_hw");
1755 memset(wl
, 0, sizeof(*wl
));
1758 dev_set_drvdata(&spi
->dev
, wl
);
1761 skb_queue_head_init(&wl
->tx_queue
);
1763 INIT_WORK(&wl
->filter_work
, wl1271_filter_work
);
1764 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
1765 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
1766 wl
->scanning
= false;
1767 wl
->default_key
= 0;
1769 wl
->rx_config
= WL1271_DEFAULT_RX_CONFIG
;
1770 wl
->rx_filter
= WL1271_DEFAULT_RX_FILTER
;
1773 wl
->psm_requested
= false;
1774 wl
->tx_queue_stopped
= false;
1775 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1776 wl
->basic_rate_set
= WL1271_DEFAULT_BASIC_RATE_SET
;
1777 wl
->band
= IEEE80211_BAND_2GHZ
;
1781 for (i
= 0; i
< ACX_TX_DESCRIPTORS
; i
++)
1782 wl
->tx_frames
[i
] = NULL
;
1784 spin_lock_init(&wl
->wl_lock
);
1787 * In case our MAC address is not correctly set,
1788 * we use a random but Nokia MAC.
1790 memcpy(wl
->mac_addr
, nokia_oui
, 3);
1791 get_random_bytes(wl
->mac_addr
+ 3, 3);
1793 wl
->state
= WL1271_STATE_OFF
;
1794 mutex_init(&wl
->mutex
);
1796 wl
->rx_descriptor
= kmalloc(sizeof(*wl
->rx_descriptor
), GFP_KERNEL
);
1797 if (!wl
->rx_descriptor
) {
1798 wl1271_error("could not allocate memory for rx descriptor");
1803 /* This is the only SPI value that we need to set here, the rest
1804 * comes from the board-peripherals file */
1805 spi
->bits_per_word
= 32;
1807 ret
= spi_setup(spi
);
1809 wl1271_error("spi_setup failed");
1813 wl
->set_power
= pdata
->set_power
;
1814 if (!wl
->set_power
) {
1815 wl1271_error("set power function missing in platform data");
1822 wl1271_error("irq missing in platform data");
1827 ret
= request_irq(wl
->irq
, wl1271_irq
, 0, DRIVER_NAME
, wl
);
1829 wl1271_error("request_irq() failed: %d", ret
);
1833 set_irq_type(wl
->irq
, IRQ_TYPE_EDGE_RISING
);
1835 disable_irq(wl
->irq
);
1837 ret
= platform_device_register(&wl1271_device
);
1839 wl1271_error("couldn't register platform device");
1842 dev_set_drvdata(&wl1271_device
.dev
, wl
);
1844 /* Apply default driver configuration. */
1845 wl1271_conf_init(wl
);
1847 ret
= wl1271_init_ieee80211(wl
);
1851 ret
= wl1271_register_hw(wl
);
1855 wl1271_debugfs_init(wl
);
1857 wl1271_notice("initialized");
1862 platform_device_unregister(&wl1271_device
);
1865 free_irq(wl
->irq
, wl
);
1868 kfree(wl
->rx_descriptor
);
1869 wl
->rx_descriptor
= NULL
;
1871 ieee80211_free_hw(hw
);
1876 static int __devexit
wl1271_remove(struct spi_device
*spi
)
1878 struct wl1271
*wl
= dev_get_drvdata(&spi
->dev
);
1880 ieee80211_unregister_hw(wl
->hw
);
1882 wl1271_debugfs_exit(wl
);
1883 platform_device_unregister(&wl1271_device
);
1884 free_irq(wl
->irq
, wl
);
1885 kfree(wl
->target_mem_map
);
1891 kfree(wl
->rx_descriptor
);
1892 wl
->rx_descriptor
= NULL
;
1894 kfree(wl
->fw_status
);
1895 kfree(wl
->tx_res_if
);
1897 ieee80211_free_hw(wl
->hw
);
1903 static struct spi_driver wl1271_spi_driver
= {
1906 .bus
= &spi_bus_type
,
1907 .owner
= THIS_MODULE
,
1910 .probe
= wl1271_probe
,
1911 .remove
= __devexit_p(wl1271_remove
),
1914 static int __init
wl1271_init(void)
1918 ret
= spi_register_driver(&wl1271_spi_driver
);
1920 wl1271_error("failed to register spi driver: %d", ret
);
1928 static void __exit
wl1271_exit(void)
1930 spi_unregister_driver(&wl1271_spi_driver
);
1932 wl1271_notice("unloaded");
1935 module_init(wl1271_init
);
1936 module_exit(wl1271_exit
);
1938 MODULE_LICENSE("GPL");
1939 MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
1940 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");