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>
35 #include <linux/inetdevice.h>
38 #include "wl12xx_80211.h"
39 #include "wl1271_reg.h"
40 #include "wl1271_spi.h"
41 #include "wl1271_event.h"
42 #include "wl1271_tx.h"
43 #include "wl1271_rx.h"
44 #include "wl1271_ps.h"
45 #include "wl1271_init.h"
46 #include "wl1271_debugfs.h"
47 #include "wl1271_cmd.h"
48 #include "wl1271_boot.h"
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
= 0xFFEF,
71 .irq_blk_threshold
= 0,
72 .irq_pkt_threshold
= USHORT_MAX
,
74 .queue_type
= CONF_RX_QUEUE_TYPE_LOW_PRIORITY
,
77 .tx_energy_detection
= 0,
79 .enabled_rates
= CONF_TX_RATE_MASK_UNSPECIFIED
,
80 .short_retry_limit
= 10,
81 .long_retry_limit
= 10,
104 .aifsn
= CONF_TX_AIFS_PIFS
,
111 .aifsn
= CONF_TX_AIFS_PIFS
,
119 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
120 .tsid
= CONF_TX_AC_BE
,
121 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
122 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
127 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
128 .tsid
= CONF_TX_AC_BE
,
129 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
130 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
135 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
136 .tsid
= CONF_TX_AC_BE
,
137 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
138 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
143 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
144 .tsid
= CONF_TX_AC_BE
,
145 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
146 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
151 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
152 .tsid
= CONF_TX_AC_BE
,
153 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
154 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
159 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
160 .tsid
= CONF_TX_AC_BE
,
161 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
162 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
167 .channel_type
= CONF_CHANNEL_TYPE_DCF
,
168 .tsid
= CONF_TX_AC_BE
,
169 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
170 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
174 .frag_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
,
175 .tx_compl_timeout
= 5,
176 .tx_compl_threshold
= 5
179 .wake_up_event
= CONF_WAKE_UP_EVENT_DTIM
,
180 .listen_interval
= 0,
181 .bcn_filt_mode
= CONF_BCN_FILT_MODE_ENABLED
,
182 .bcn_filt_ie_count
= 1,
185 .ie
= WLAN_EID_CHANNEL_SWITCH
,
186 .rule
= CONF_BCN_RULE_PASS_ON_APPEARANCE
,
189 .synch_fail_thold
= 5,
190 .bss_lose_timeout
= 100,
191 .beacon_rx_timeout
= 10000,
192 .broadcast_timeout
= 20000,
193 .rx_broadcast_in_ps
= 1,
194 .ps_poll_threshold
= 4,
195 .sig_trigger_count
= 2,
200 .metric
= CONF_TRIG_METRIC_RSSI_BEACON
,
201 .type
= CONF_TRIG_EVENT_TYPE_EDGE
,
202 .direction
= CONF_TRIG_EVENT_DIR_LOW
,
210 .metric
= CONF_TRIG_METRIC_RSSI_BEACON
,
211 .type
= CONF_TRIG_EVENT_TYPE_EDGE
,
212 .direction
= CONF_TRIG_EVENT_DIR_HIGH
,
219 .rssi_bcn_avg_weight
= 10,
220 .rssi_pkt_avg_weight
= 10,
221 .snr_bcn_avg_weight
= 10,
222 .snr_pkt_avg_weight
= 10
224 .bet_enable
= CONF_BET_MODE_ENABLE
,
225 .bet_max_consecutive
= 10,
226 .psm_entry_retries
= 3
234 0x18, 0x10, 0x05, 0xfb, 0xf0, 0xe8,
241 0x18, 0x10, 0x05, 0xf6, 0xf0, 0xe8,
248 0x18, 0x10, 0x05, 0xfb, 0xf0, 0xe8,
254 .ref_clk
= CONF_REF_CLK_38_4_E
,
256 .clk_valid_on_wakeup
= 0,
258 .single_dual_band
= CONF_SINGLE_BAND
,
259 .tx_bip_fem_autodetect
= 0,
260 .tx_bip_fem_manufacturer
= 1,
266 .rx_rssi_and_proc_compens
= {
267 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8,
268 0xfc, 0x00, 0x08, 0x10, 0xf0, 0xf8,
270 .rx_trace_loss_5
= { 0, 0, 0, 0, 0, 0, 0 },
271 .tx_trace_loss_5
= { 0, 0, 0, 0, 0, 0, 0 },
272 .rx_rssi_and_proc_compens_5
= {
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 .tx_ref_pd_voltage
= 0x24e,
277 .tx_ref_power
= 0x78,
279 .tx_rate_limits_normal
= {
280 0x1e, 0x1f, 0x22, 0x24, 0x28, 0x29 },
281 .tx_rate_limits_degraded
= {
282 0x1b, 0x1c, 0x1e, 0x20, 0x24, 0x25 },
283 .tx_channel_limits_11b
= {
284 0x22, 0x50, 0x50, 0x50, 0x50, 0x50,
285 0x50, 0x50, 0x50, 0x50, 0x22, 0x50,
287 .tx_channel_limits_ofdm
= {
288 0x20, 0x50, 0x50, 0x50, 0x50, 0x50,
289 0x50, 0x50, 0x50, 0x50, 0x20, 0x50,
291 .tx_pdv_rate_offsets
= {
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
294 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x27 },
295 .rx_fem_insertion_loss
= 0x14,
296 .tx_ref_pd_voltage_5
= {
297 0x0190, 0x01a4, 0x01c3, 0x01d8,
300 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 },
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
303 .tx_rate_limits_normal_5
= {
304 0x1b, 0x1e, 0x21, 0x23, 0x27, 0x00 },
305 .tx_rate_limits_degraded_5
= {
306 0x1b, 0x1e, 0x21, 0x23, 0x27, 0x00 },
307 .tx_channel_limits_ofdm_5
= {
308 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
309 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
310 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
311 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
313 .tx_pdv_rate_offsets_5
= {
314 0x01, 0x02, 0x02, 0x02, 0x02, 0x00 },
316 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 },
317 .rx_fem_insertion_loss_5
= {
318 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }
323 static LIST_HEAD(wl_list
);
325 static void wl1271_conf_init(struct wl1271
*wl
)
329 * This function applies the default configuration to the driver. This
330 * function is invoked upon driver load (spi probe.)
332 * The configuration is stored in a run-time structure in order to
333 * facilitate for run-time adjustment of any of the parameters. Making
334 * changes to the configuration structure will apply the new values on
335 * the next interface up (wl1271_op_start.)
338 /* apply driver default configuration */
339 memcpy(&wl
->conf
, &default_conf
, sizeof(default_conf
));
341 if (wl1271_11a_enabled())
342 wl
->conf
.init
.genparam
.single_dual_band
= CONF_DUAL_BAND
;
346 static int wl1271_plt_init(struct wl1271
*wl
)
350 ret
= wl1271_cmd_general_parms(wl
);
354 ret
= wl1271_cmd_radio_parms(wl
);
358 ret
= wl1271_acx_init_mem_config(wl
);
362 ret
= wl1271_cmd_data_path(wl
, wl
->channel
, 1);
369 static void wl1271_disable_interrupts(struct wl1271
*wl
)
371 disable_irq(wl
->irq
);
374 static void wl1271_power_off(struct wl1271
*wl
)
376 wl
->set_power(false);
379 static void wl1271_power_on(struct wl1271
*wl
)
384 static void wl1271_fw_status(struct wl1271
*wl
,
385 struct wl1271_fw_status
*status
)
390 wl1271_spi_read(wl
, FW_STATUS_ADDR
, status
,
391 sizeof(*status
), false);
393 wl1271_debug(DEBUG_IRQ
, "intr: 0x%x (fw_rx_counter = %d, "
394 "drv_rx_counter = %d, tx_results_counter = %d)",
396 status
->fw_rx_counter
,
397 status
->drv_rx_counter
,
398 status
->tx_results_counter
);
400 /* update number of available TX blocks */
401 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
402 u32 cnt
= le32_to_cpu(status
->tx_released_blks
[i
]) -
403 wl
->tx_blocks_freed
[i
];
405 wl
->tx_blocks_freed
[i
] =
406 le32_to_cpu(status
->tx_released_blks
[i
]);
407 wl
->tx_blocks_available
+= cnt
;
411 /* if more blocks are available now, schedule some tx work */
412 if (total
&& !skb_queue_empty(&wl
->tx_queue
))
413 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
415 /* update the host-chipset time offset */
416 wl
->time_offset
= jiffies_to_usecs(jiffies
) -
417 le32_to_cpu(status
->fw_localtime
);
420 static void wl1271_irq_work(struct work_struct
*work
)
425 container_of(work
, struct wl1271
, irq_work
);
427 mutex_lock(&wl
->mutex
);
429 wl1271_debug(DEBUG_IRQ
, "IRQ work");
431 if (wl
->state
== WL1271_STATE_OFF
)
434 ret
= wl1271_ps_elp_wakeup(wl
, true);
438 wl1271_spi_write32(wl
, ACX_REG_INTERRUPT_MASK
, WL1271_ACX_INTR_ALL
);
440 wl1271_fw_status(wl
, wl
->fw_status
);
441 intr
= le32_to_cpu(wl
->fw_status
->intr
);
443 wl1271_debug(DEBUG_IRQ
, "Zero interrupt received.");
447 intr
&= WL1271_INTR_MASK
;
449 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
450 bool do_ack
= (intr
& WL1271_ACX_INTR_EVENT_B
) ? false : true;
451 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
452 wl1271_event_handle(wl
, 0, do_ack
);
455 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
456 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
457 wl1271_event_handle(wl
, 1, true);
460 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
461 wl1271_debug(DEBUG_IRQ
,
462 "WL1271_ACX_INTR_INIT_COMPLETE");
464 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
465 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
467 if (intr
& WL1271_ACX_INTR_DATA
) {
468 u8 tx_res_cnt
= wl
->fw_status
->tx_results_counter
-
469 wl
->tx_results_count
;
471 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
473 /* check for tx results */
475 wl1271_tx_complete(wl
, tx_res_cnt
);
477 wl1271_rx(wl
, wl
->fw_status
);
481 wl1271_spi_write32(wl
, ACX_REG_INTERRUPT_MASK
,
482 WL1271_ACX_INTR_ALL
& ~(WL1271_INTR_MASK
));
483 wl1271_ps_elp_sleep(wl
);
486 mutex_unlock(&wl
->mutex
);
489 static irqreturn_t
wl1271_irq(int irq
, void *cookie
)
494 wl1271_debug(DEBUG_IRQ
, "IRQ");
498 /* complete the ELP completion */
499 spin_lock_irqsave(&wl
->wl_lock
, flags
);
501 complete(wl
->elp_compl
);
502 wl
->elp_compl
= NULL
;
505 ieee80211_queue_work(wl
->hw
, &wl
->irq_work
);
506 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
511 static int wl1271_fetch_firmware(struct wl1271
*wl
)
513 const struct firmware
*fw
;
516 ret
= request_firmware(&fw
, WL1271_FW_NAME
, &wl
->spi
->dev
);
519 wl1271_error("could not get firmware: %d", ret
);
524 wl1271_error("firmware size is not multiple of 32 bits: %zu",
530 wl
->fw_len
= fw
->size
;
531 wl
->fw
= vmalloc(wl
->fw_len
);
534 wl1271_error("could not allocate memory for the firmware");
539 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
544 release_firmware(fw
);
549 static int wl1271_fetch_nvs(struct wl1271
*wl
)
551 const struct firmware
*fw
;
554 ret
= request_firmware(&fw
, WL1271_NVS_NAME
, &wl
->spi
->dev
);
557 wl1271_error("could not get nvs file: %d", ret
);
562 wl1271_error("nvs size is not multiple of 32 bits: %zu",
568 wl
->nvs_len
= fw
->size
;
569 wl
->nvs
= kmalloc(wl
->nvs_len
, GFP_KERNEL
);
572 wl1271_error("could not allocate memory for the nvs file");
577 memcpy(wl
->nvs
, fw
->data
, wl
->nvs_len
);
582 release_firmware(fw
);
587 static void wl1271_fw_wakeup(struct wl1271
*wl
)
591 elp_reg
= ELPCTRL_WAKE_UP
;
592 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, elp_reg
);
595 static int wl1271_setup(struct wl1271
*wl
)
597 wl
->fw_status
= kmalloc(sizeof(*wl
->fw_status
), GFP_KERNEL
);
601 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
602 if (!wl
->tx_res_if
) {
603 kfree(wl
->fw_status
);
607 INIT_WORK(&wl
->irq_work
, wl1271_irq_work
);
608 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
612 static int wl1271_chip_wakeup(struct wl1271
*wl
)
614 struct wl1271_partition_set partition
;
618 msleep(WL1271_POWER_ON_SLEEP
);
619 wl1271_spi_reset(wl
);
622 /* We don't need a real memory partition here, because we only want
623 * to use the registers at this point. */
624 memset(&partition
, 0, sizeof(partition
));
625 partition
.reg
.start
= REGISTERS_BASE
;
626 partition
.reg
.size
= REGISTERS_DOWN_SIZE
;
627 wl1271_set_partition(wl
, &partition
);
629 /* ELP module wake up */
630 wl1271_fw_wakeup(wl
);
632 /* whal_FwCtrl_BootSm() */
634 /* 0. read chip id from CHIP_ID */
635 wl
->chip
.id
= wl1271_spi_read32(wl
, CHIP_ID_B
);
637 /* 1. check if chip id is valid */
639 switch (wl
->chip
.id
) {
640 case CHIP_ID_1271_PG10
:
641 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
644 ret
= wl1271_setup(wl
);
648 case CHIP_ID_1271_PG20
:
649 wl1271_debug(DEBUG_BOOT
, "chip id 0x%x (1271 PG20)",
652 ret
= wl1271_setup(wl
);
657 wl1271_error("unsupported chip id: 0x%x", wl
->chip
.id
);
662 if (wl
->fw
== NULL
) {
663 ret
= wl1271_fetch_firmware(wl
);
668 /* No NVS from netlink, try to get it from the filesystem */
669 if (wl
->nvs
== NULL
) {
670 ret
= wl1271_fetch_nvs(wl
);
678 wl1271_power_off(wl
);
684 int wl1271_plt_start(struct wl1271
*wl
)
688 mutex_lock(&wl
->mutex
);
690 wl1271_notice("power up");
692 if (wl
->state
!= WL1271_STATE_OFF
) {
693 wl1271_error("cannot go into PLT state because not "
694 "in off state: %d", wl
->state
);
699 wl
->state
= WL1271_STATE_PLT
;
701 ret
= wl1271_chip_wakeup(wl
);
705 ret
= wl1271_boot(wl
);
709 wl1271_notice("firmware booted in PLT mode (%s)", wl
->chip
.fw_ver
);
711 ret
= wl1271_plt_init(wl
);
713 goto out_irq_disable
;
715 /* Make sure power saving is disabled */
716 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
718 goto out_irq_disable
;
723 wl1271_disable_interrupts(wl
);
726 wl1271_power_off(wl
);
729 mutex_unlock(&wl
->mutex
);
734 int wl1271_plt_stop(struct wl1271
*wl
)
738 mutex_lock(&wl
->mutex
);
740 wl1271_notice("power down");
742 if (wl
->state
!= WL1271_STATE_PLT
) {
743 wl1271_error("cannot power down because not in PLT "
744 "state: %d", wl
->state
);
749 wl1271_disable_interrupts(wl
);
750 wl1271_power_off(wl
);
752 wl
->state
= WL1271_STATE_OFF
;
756 mutex_unlock(&wl
->mutex
);
762 static int wl1271_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
764 struct wl1271
*wl
= hw
->priv
;
766 skb_queue_tail(&wl
->tx_queue
, skb
);
769 * The chip specific setup must run before the first TX packet -
770 * before that, the tx_work will not be initialized!
773 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
776 * The workqueue is slow to process the tx_queue and we need stop
777 * the queue here, otherwise the queue will get too long.
779 if (skb_queue_len(&wl
->tx_queue
) >= WL1271_TX_QUEUE_MAX_LENGTH
) {
780 ieee80211_stop_queues(wl
->hw
);
783 * FIXME: this is racy, the variable is not properly
784 * protected. Maybe fix this by removing the stupid
785 * variable altogether and checking the real queue state?
787 wl
->tx_queue_stopped
= true;
793 static int wl1271_dev_notify(struct notifier_block
*me
, unsigned long what
,
796 struct net_device
*dev
;
797 struct wireless_dev
*wdev
;
799 struct ieee80211_hw
*hw
;
801 struct wl1271
*wl_temp
;
802 struct in_device
*idev
;
803 struct in_ifaddr
*ifa
= arg
;
806 /* FIXME: this ugly function should probably be implemented in the
807 * mac80211, and here should only be a simple callback handling actual
808 * setting of the filters. Now we need to dig up references to
809 * various structures to gain access to what we need.
810 * Also, because of this, there is no "initial" setting of the filter
811 * in "op_start", because we don't want to dig up struct net_device
812 * there - the filter will be set upon first change of the interface
815 dev
= ifa
->ifa_dev
->dev
;
817 wdev
= dev
->ieee80211_ptr
;
825 hw
= wiphy_priv(wiphy
);
829 /* Check that the interface is one supported by this driver. */
831 list_for_each_entry(wl
, &wl_list
, list
) {
838 /* Get the interface IP address for the device. "ifa" will become
840 - there is no IPV4 protocol address configured
841 - there are multiple (virtual) IPV4 addresses configured
842 When "ifa" is NULL, filtering will be disabled.
847 ifa
= idev
->ifa_list
;
849 if (ifa
&& ifa
->ifa_next
)
852 mutex_lock(&wl
->mutex
);
854 if (wl
->state
== WL1271_STATE_OFF
)
857 ret
= wl1271_ps_elp_wakeup(wl
, false);
861 ret
= wl1271_acx_arp_ip_filter(wl
, true,
862 (u8
*)&ifa
->ifa_address
,
865 ret
= wl1271_acx_arp_ip_filter(wl
, false, NULL
,
867 wl1271_ps_elp_sleep(wl
);
870 mutex_unlock(&wl
->mutex
);
875 static struct notifier_block wl1271_dev_notifier
= {
876 .notifier_call
= wl1271_dev_notify
,
880 static int wl1271_op_start(struct ieee80211_hw
*hw
)
882 struct wl1271
*wl
= hw
->priv
;
885 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
887 mutex_lock(&wl
->mutex
);
889 if (wl
->state
!= WL1271_STATE_OFF
) {
890 wl1271_error("cannot start because not in off state: %d",
896 ret
= wl1271_chip_wakeup(wl
);
900 ret
= wl1271_boot(wl
);
904 ret
= wl1271_hw_init(wl
);
906 goto out_irq_disable
;
908 wl
->state
= WL1271_STATE_ON
;
910 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver
);
915 wl1271_disable_interrupts(wl
);
918 wl1271_power_off(wl
);
921 mutex_unlock(&wl
->mutex
);
924 list_add(&wl
->list
, &wl_list
);
925 register_inetaddr_notifier(&wl1271_dev_notifier
);
931 static void wl1271_op_stop(struct ieee80211_hw
*hw
)
933 struct wl1271
*wl
= hw
->priv
;
938 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
940 unregister_inetaddr_notifier(&wl1271_dev_notifier
);
943 mutex_lock(&wl
->mutex
);
945 WARN_ON(wl
->state
!= WL1271_STATE_ON
);
948 mutex_unlock(&wl
->mutex
);
949 ieee80211_scan_completed(wl
->hw
, true);
950 mutex_lock(&wl
->mutex
);
951 wl
->scanning
= false;
954 wl
->state
= WL1271_STATE_OFF
;
956 wl1271_disable_interrupts(wl
);
958 mutex_unlock(&wl
->mutex
);
960 cancel_work_sync(&wl
->irq_work
);
961 cancel_work_sync(&wl
->tx_work
);
963 mutex_lock(&wl
->mutex
);
965 /* let's notify MAC80211 about the remaining pending TX frames */
967 wl1271_power_off(wl
);
969 memset(wl
->bssid
, 0, ETH_ALEN
);
970 memset(wl
->ssid
, 0, IW_ESSID_MAX_SIZE
+ 1);
972 wl
->bss_type
= MAX_BSS_TYPE
;
973 wl
->band
= IEEE80211_BAND_2GHZ
;
978 wl
->psm_entry_retry
= 0;
979 wl
->tx_queue_stopped
= false;
980 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
981 wl
->tx_blocks_available
= 0;
982 wl
->tx_results_count
= 0;
983 wl
->tx_packets_count
= 0;
984 wl
->tx_security_last_seq
= 0;
985 wl
->tx_security_seq_16
= 0;
986 wl
->tx_security_seq_32
= 0;
988 wl
->session_counter
= 0;
991 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
992 wl
->tx_blocks_freed
[i
] = 0;
994 wl1271_debugfs_reset(wl
);
995 mutex_unlock(&wl
->mutex
);
998 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
999 struct ieee80211_if_init_conf
*conf
)
1001 struct wl1271
*wl
= hw
->priv
;
1004 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
1005 conf
->type
, conf
->mac_addr
);
1007 mutex_lock(&wl
->mutex
);
1013 wl
->vif
= conf
->vif
;
1015 switch (conf
->type
) {
1016 case NL80211_IFTYPE_STATION
:
1017 wl
->bss_type
= BSS_TYPE_STA_BSS
;
1019 case NL80211_IFTYPE_ADHOC
:
1020 wl
->bss_type
= BSS_TYPE_IBSS
;
1027 /* FIXME: what if conf->mac_addr changes? */
1030 mutex_unlock(&wl
->mutex
);
1034 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
1035 struct ieee80211_if_init_conf
*conf
)
1037 struct wl1271
*wl
= hw
->priv
;
1039 mutex_lock(&wl
->mutex
);
1040 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
1042 mutex_unlock(&wl
->mutex
);
1046 static int wl1271_op_config_interface(struct ieee80211_hw
*hw
,
1047 struct ieee80211_vif
*vif
,
1048 struct ieee80211_if_conf
*conf
)
1050 struct wl1271
*wl
= hw
->priv
;
1051 struct sk_buff
*beacon
;
1054 wl1271_debug(DEBUG_MAC80211
, "mac80211 config_interface bssid %pM",
1056 wl1271_dump_ascii(DEBUG_MAC80211
, "ssid: ", conf
->ssid
,
1059 mutex_lock(&wl
->mutex
);
1061 ret
= wl1271_ps_elp_wakeup(wl
, false);
1065 if (memcmp(wl
->bssid
, conf
->bssid
, ETH_ALEN
)) {
1066 wl1271_debug(DEBUG_MAC80211
, "bssid changed");
1068 memcpy(wl
->bssid
, conf
->bssid
, ETH_ALEN
);
1070 ret
= wl1271_cmd_join(wl
);
1074 ret
= wl1271_cmd_build_null_data(wl
);
1079 wl
->ssid_len
= conf
->ssid_len
;
1081 memcpy(wl
->ssid
, conf
->ssid
, wl
->ssid_len
);
1083 if (conf
->changed
& IEEE80211_IFCC_BEACON
) {
1084 beacon
= ieee80211_beacon_get(hw
, vif
);
1085 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
,
1086 beacon
->data
, beacon
->len
);
1089 dev_kfree_skb(beacon
);
1093 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PROBE_RESPONSE
,
1094 beacon
->data
, beacon
->len
);
1096 dev_kfree_skb(beacon
);
1103 wl1271_ps_elp_sleep(wl
);
1106 mutex_unlock(&wl
->mutex
);
1112 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
1114 struct wl1271
*wl
= hw
->priv
;
1115 struct ieee80211_conf
*conf
= &hw
->conf
;
1116 int channel
, ret
= 0;
1118 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
1120 wl1271_debug(DEBUG_MAC80211
, "mac80211 config ch %d psm %s power %d",
1122 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
1125 mutex_lock(&wl
->mutex
);
1127 wl
->band
= conf
->channel
->band
;
1129 ret
= wl1271_ps_elp_wakeup(wl
, false);
1133 if (channel
!= wl
->channel
) {
1135 * We assume that the stack will configure the right channel
1136 * before associating, so we don't need to send a join
1137 * command here. We will join the right channel when the
1140 wl
->channel
= channel
;
1143 if (conf
->flags
& IEEE80211_CONF_PS
&& !wl
->psm_requested
) {
1144 wl1271_info("psm enabled");
1146 wl
->psm_requested
= true;
1149 * We enter PSM only if we're already associated.
1150 * If we're not, we'll enter it when joining an SSID,
1151 * through the bss_info_changed() hook.
1153 ret
= wl1271_ps_set_mode(wl
, STATION_POWER_SAVE_MODE
);
1154 } else if (!(conf
->flags
& IEEE80211_CONF_PS
) &&
1155 wl
->psm_requested
) {
1156 wl1271_info("psm disabled");
1158 wl
->psm_requested
= false;
1161 ret
= wl1271_ps_set_mode(wl
, STATION_ACTIVE_MODE
);
1164 if (conf
->power_level
!= wl
->power_level
) {
1165 ret
= wl1271_acx_tx_power(wl
, conf
->power_level
);
1169 wl
->power_level
= conf
->power_level
;
1173 wl1271_ps_elp_sleep(wl
);
1176 mutex_unlock(&wl
->mutex
);
1181 struct wl1271_filter_params
{
1184 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
1187 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
, int mc_count
,
1188 struct dev_addr_list
*mc_list
)
1190 struct wl1271_filter_params
*fp
;
1193 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
1195 wl1271_error("Out of memory setting filters.");
1199 /* update multicast filtering parameters */
1201 if (mc_count
> ACX_MC_ADDRESS_GROUP_MAX
) {
1203 fp
->enabled
= false;
1206 fp
->mc_list_length
= 0;
1207 for (i
= 0; i
< mc_count
; i
++) {
1208 if (mc_list
->da_addrlen
== ETH_ALEN
) {
1209 memcpy(fp
->mc_list
[fp
->mc_list_length
],
1210 mc_list
->da_addr
, ETH_ALEN
);
1211 fp
->mc_list_length
++;
1213 wl1271_warning("Unknown mc address length.");
1214 mc_list
= mc_list
->next
;
1217 return (u64
)(unsigned long)fp
;
1220 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
1223 FIF_BCN_PRBRESP_PROMISC | \
1227 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
1228 unsigned int changed
,
1229 unsigned int *total
, u64 multicast
)
1231 struct wl1271_filter_params
*fp
= (void *)(unsigned long)multicast
;
1232 struct wl1271
*wl
= hw
->priv
;
1235 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter");
1237 mutex_lock(&wl
->mutex
);
1239 if (wl
->state
== WL1271_STATE_OFF
)
1242 ret
= wl1271_ps_elp_wakeup(wl
, false);
1246 *total
&= WL1271_SUPPORTED_FILTERS
;
1247 changed
&= WL1271_SUPPORTED_FILTERS
;
1249 if (*total
& FIF_ALLMULTI
)
1250 ret
= wl1271_acx_group_address_tbl(wl
, false, NULL
, 0);
1252 ret
= wl1271_acx_group_address_tbl(wl
, fp
->enabled
,
1254 fp
->mc_list_length
);
1260 /* FIXME: We still need to set our filters properly */
1262 /* determine, whether supported filter values have changed */
1266 /* apply configured filters */
1267 ret
= wl1271_acx_rx_config(wl
, wl
->rx_config
, wl
->rx_filter
);
1272 wl1271_ps_elp_sleep(wl
);
1275 mutex_unlock(&wl
->mutex
);
1278 static int wl1271_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1279 struct ieee80211_vif
*vif
,
1280 struct ieee80211_sta
*sta
,
1281 struct ieee80211_key_conf
*key_conf
)
1283 struct wl1271
*wl
= hw
->priv
;
1290 static const u8 bcast_addr
[ETH_ALEN
] =
1291 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1293 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
1295 addr
= sta
? sta
->addr
: bcast_addr
;
1297 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x", cmd
);
1298 wl1271_dump(DEBUG_CRYPT
, "ADDR: ", addr
, ETH_ALEN
);
1299 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
1300 key_conf
->alg
, key_conf
->keyidx
,
1301 key_conf
->keylen
, key_conf
->flags
);
1302 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
1304 if (is_zero_ether_addr(addr
)) {
1305 /* We dont support TX only encryption */
1310 mutex_lock(&wl
->mutex
);
1312 ret
= wl1271_ps_elp_wakeup(wl
, false);
1316 switch (key_conf
->alg
) {
1320 key_conf
->hw_key_idx
= key_conf
->keyidx
;
1323 key_type
= KEY_TKIP
;
1325 key_conf
->hw_key_idx
= key_conf
->keyidx
;
1326 tx_seq_32
= wl
->tx_security_seq_32
;
1327 tx_seq_16
= wl
->tx_security_seq_16
;
1332 key_conf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1333 tx_seq_32
= wl
->tx_security_seq_32
;
1334 tx_seq_16
= wl
->tx_security_seq_16
;
1337 wl1271_error("Unknown key algo 0x%x", key_conf
->alg
);
1345 ret
= wl1271_cmd_set_key(wl
, KEY_ADD_OR_REPLACE
,
1346 key_conf
->keyidx
, key_type
,
1347 key_conf
->keylen
, key_conf
->key
,
1348 addr
, tx_seq_32
, tx_seq_16
);
1350 wl1271_error("Could not add or replace key");
1356 ret
= wl1271_cmd_set_key(wl
, KEY_REMOVE
,
1357 key_conf
->keyidx
, key_type
,
1358 key_conf
->keylen
, key_conf
->key
,
1361 wl1271_error("Could not remove key");
1367 wl1271_error("Unsupported key cmd 0x%x", cmd
);
1375 wl1271_ps_elp_sleep(wl
);
1378 mutex_unlock(&wl
->mutex
);
1384 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
1385 struct cfg80211_scan_request
*req
)
1387 struct wl1271
*wl
= hw
->priv
;
1392 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
1395 ssid
= req
->ssids
[0].ssid
;
1396 len
= req
->ssids
[0].ssid_len
;
1399 mutex_lock(&wl
->mutex
);
1401 ret
= wl1271_ps_elp_wakeup(wl
, false);
1405 if (wl1271_11a_enabled())
1406 ret
= wl1271_cmd_scan(hw
->priv
, ssid
, len
, 1, 0,
1407 WL1271_SCAN_BAND_DUAL
, 3);
1409 ret
= wl1271_cmd_scan(hw
->priv
, ssid
, len
, 1, 0,
1410 WL1271_SCAN_BAND_2_4_GHZ
, 3);
1412 wl1271_ps_elp_sleep(wl
);
1415 mutex_unlock(&wl
->mutex
);
1420 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1422 struct wl1271
*wl
= hw
->priv
;
1425 mutex_lock(&wl
->mutex
);
1427 ret
= wl1271_ps_elp_wakeup(wl
, false);
1431 ret
= wl1271_acx_rts_threshold(wl
, (u16
) value
);
1433 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret
);
1435 wl1271_ps_elp_sleep(wl
);
1438 mutex_unlock(&wl
->mutex
);
1443 static u32
wl1271_enabled_rates_get(struct wl1271
*wl
, u64 basic_rate_set
)
1445 struct ieee80211_supported_band
*band
;
1446 u32 enabled_rates
= 0;
1449 band
= wl
->hw
->wiphy
->bands
[wl
->band
];
1450 for (bit
= 0; bit
< band
->n_bitrates
; bit
++) {
1451 if (basic_rate_set
& 0x1)
1452 enabled_rates
|= band
->bitrates
[bit
].hw_value
;
1453 basic_rate_set
>>= 1;
1456 return enabled_rates
;
1459 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
1460 struct ieee80211_vif
*vif
,
1461 struct ieee80211_bss_conf
*bss_conf
,
1464 enum wl1271_cmd_ps_mode mode
;
1465 struct wl1271
*wl
= hw
->priv
;
1468 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info changed");
1470 mutex_lock(&wl
->mutex
);
1472 ret
= wl1271_ps_elp_wakeup(wl
, false);
1476 if (changed
& BSS_CHANGED_ASSOC
) {
1477 if (bss_conf
->assoc
) {
1478 wl
->aid
= bss_conf
->aid
;
1481 * with wl1271, we don't need to update the
1482 * beacon_int and dtim_period, because the firmware
1483 * updates it by itself when the first beacon is
1484 * received after a join.
1486 ret
= wl1271_cmd_build_ps_poll(wl
, wl
->aid
);
1490 ret
= wl1271_acx_aid(wl
, wl
->aid
);
1494 /* If we want to go in PSM but we're not there yet */
1495 if (wl
->psm_requested
&& !wl
->psm
) {
1496 mode
= STATION_POWER_SAVE_MODE
;
1497 ret
= wl1271_ps_set_mode(wl
, mode
);
1502 /* use defaults when not associated */
1503 wl
->basic_rate_set
= WL1271_DEFAULT_BASIC_RATE_SET
;
1509 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1510 if (bss_conf
->use_short_slot
)
1511 ret
= wl1271_acx_slot(wl
, SLOT_TIME_SHORT
);
1513 ret
= wl1271_acx_slot(wl
, SLOT_TIME_LONG
);
1515 wl1271_warning("Set slot time failed %d", ret
);
1520 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1521 if (bss_conf
->use_short_preamble
)
1522 wl1271_acx_set_preamble(wl
, ACX_PREAMBLE_SHORT
);
1524 wl1271_acx_set_preamble(wl
, ACX_PREAMBLE_LONG
);
1527 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1528 if (bss_conf
->use_cts_prot
)
1529 ret
= wl1271_acx_cts_protect(wl
, CTSPROTECT_ENABLE
);
1531 ret
= wl1271_acx_cts_protect(wl
, CTSPROTECT_DISABLE
);
1533 wl1271_warning("Set ctsprotect failed %d", ret
);
1538 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1539 wl
->basic_rate_set
= wl1271_enabled_rates_get(
1540 wl
, bss_conf
->basic_rates
);
1542 ret
= wl1271_acx_rate_policies(wl
, wl
->basic_rate_set
);
1544 wl1271_warning("Set rate policies failed %d", ret
);
1550 wl1271_ps_elp_sleep(wl
);
1553 mutex_unlock(&wl
->mutex
);
1557 /* can't be const, mac80211 writes to this */
1558 static struct ieee80211_rate wl1271_rates
[] = {
1560 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
1561 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
1563 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
1564 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
1565 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1567 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
1568 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
1569 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
1571 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
1572 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
1573 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
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 /* can't be const, mac80211 writes to this */
1601 static struct ieee80211_channel wl1271_channels
[] = {
1602 { .hw_value
= 1, .center_freq
= 2412},
1603 { .hw_value
= 2, .center_freq
= 2417},
1604 { .hw_value
= 3, .center_freq
= 2422},
1605 { .hw_value
= 4, .center_freq
= 2427},
1606 { .hw_value
= 5, .center_freq
= 2432},
1607 { .hw_value
= 6, .center_freq
= 2437},
1608 { .hw_value
= 7, .center_freq
= 2442},
1609 { .hw_value
= 8, .center_freq
= 2447},
1610 { .hw_value
= 9, .center_freq
= 2452},
1611 { .hw_value
= 10, .center_freq
= 2457},
1612 { .hw_value
= 11, .center_freq
= 2462},
1613 { .hw_value
= 12, .center_freq
= 2467},
1614 { .hw_value
= 13, .center_freq
= 2472},
1617 /* can't be const, mac80211 writes to this */
1618 static struct ieee80211_supported_band wl1271_band_2ghz
= {
1619 .channels
= wl1271_channels
,
1620 .n_channels
= ARRAY_SIZE(wl1271_channels
),
1621 .bitrates
= wl1271_rates
,
1622 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
1625 /* 5 GHz data rates for WL1273 */
1626 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
1628 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
1629 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
1631 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
1632 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
1634 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
1635 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
1637 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
1638 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
1640 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
1641 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
1643 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
1644 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
1646 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
1647 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
1649 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
1650 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
1653 /* 5 GHz band channels for WL1273 */
1654 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
1655 { .hw_value
= 183, .center_freq
= 4915},
1656 { .hw_value
= 184, .center_freq
= 4920},
1657 { .hw_value
= 185, .center_freq
= 4925},
1658 { .hw_value
= 187, .center_freq
= 4935},
1659 { .hw_value
= 188, .center_freq
= 4940},
1660 { .hw_value
= 189, .center_freq
= 4945},
1661 { .hw_value
= 192, .center_freq
= 4960},
1662 { .hw_value
= 196, .center_freq
= 4980},
1663 { .hw_value
= 7, .center_freq
= 5035},
1664 { .hw_value
= 8, .center_freq
= 5040},
1665 { .hw_value
= 9, .center_freq
= 5045},
1666 { .hw_value
= 11, .center_freq
= 5055},
1667 { .hw_value
= 12, .center_freq
= 5060},
1668 { .hw_value
= 16, .center_freq
= 5080},
1669 { .hw_value
= 34, .center_freq
= 5170},
1670 { .hw_value
= 36, .center_freq
= 5180},
1671 { .hw_value
= 38, .center_freq
= 5190},
1672 { .hw_value
= 40, .center_freq
= 5200},
1673 { .hw_value
= 42, .center_freq
= 5210},
1674 { .hw_value
= 44, .center_freq
= 5220},
1675 { .hw_value
= 46, .center_freq
= 5230},
1676 { .hw_value
= 48, .center_freq
= 5240},
1677 { .hw_value
= 52, .center_freq
= 5260},
1678 { .hw_value
= 56, .center_freq
= 5280},
1679 { .hw_value
= 60, .center_freq
= 5300},
1680 { .hw_value
= 64, .center_freq
= 5320},
1681 { .hw_value
= 100, .center_freq
= 5500},
1682 { .hw_value
= 104, .center_freq
= 5520},
1683 { .hw_value
= 108, .center_freq
= 5540},
1684 { .hw_value
= 112, .center_freq
= 5560},
1685 { .hw_value
= 116, .center_freq
= 5580},
1686 { .hw_value
= 120, .center_freq
= 5600},
1687 { .hw_value
= 124, .center_freq
= 5620},
1688 { .hw_value
= 128, .center_freq
= 5640},
1689 { .hw_value
= 132, .center_freq
= 5660},
1690 { .hw_value
= 136, .center_freq
= 5680},
1691 { .hw_value
= 140, .center_freq
= 5700},
1692 { .hw_value
= 149, .center_freq
= 5745},
1693 { .hw_value
= 153, .center_freq
= 5765},
1694 { .hw_value
= 157, .center_freq
= 5785},
1695 { .hw_value
= 161, .center_freq
= 5805},
1696 { .hw_value
= 165, .center_freq
= 5825},
1700 static struct ieee80211_supported_band wl1271_band_5ghz
= {
1701 .channels
= wl1271_channels_5ghz
,
1702 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
1703 .bitrates
= wl1271_rates_5ghz
,
1704 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
1707 static const struct ieee80211_ops wl1271_ops
= {
1708 .start
= wl1271_op_start
,
1709 .stop
= wl1271_op_stop
,
1710 .add_interface
= wl1271_op_add_interface
,
1711 .remove_interface
= wl1271_op_remove_interface
,
1712 .config
= wl1271_op_config
,
1713 /* .config_interface = wl1271_op_config_interface, */
1714 .prepare_multicast
= wl1271_op_prepare_multicast
,
1715 .configure_filter
= wl1271_op_configure_filter
,
1717 .set_key
= wl1271_op_set_key
,
1718 .hw_scan
= wl1271_op_hw_scan
,
1719 .bss_info_changed
= wl1271_op_bss_info_changed
,
1720 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
1723 static int wl1271_register_hw(struct wl1271
*wl
)
1727 if (wl
->mac80211_registered
)
1730 SET_IEEE80211_PERM_ADDR(wl
->hw
, wl
->mac_addr
);
1732 ret
= ieee80211_register_hw(wl
->hw
);
1734 wl1271_error("unable to register mac80211 hw: %d", ret
);
1738 wl
->mac80211_registered
= true;
1740 wl1271_notice("loaded");
1745 static int wl1271_init_ieee80211(struct wl1271
*wl
)
1747 /* The tx descriptor buffer and the TKIP space. */
1748 wl
->hw
->extra_tx_headroom
= WL1271_TKIP_IV_SPACE
+
1749 sizeof(struct wl1271_tx_hw_descr
);
1752 /* FIXME: find a proper value */
1753 wl
->hw
->channel_change_time
= 10000;
1755 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
1756 IEEE80211_HW_NOISE_DBM
|
1757 IEEE80211_HW_BEACON_FILTER
|
1758 IEEE80211_HW_SUPPORTS_PS
;
1760 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
1761 wl
->hw
->wiphy
->max_scan_ssids
= 1;
1762 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &wl1271_band_2ghz
;
1764 if (wl1271_11a_enabled())
1765 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &wl1271_band_5ghz
;
1767 SET_IEEE80211_DEV(wl
->hw
, &wl
->spi
->dev
);
1772 static void wl1271_device_release(struct device
*dev
)
1777 static struct platform_device wl1271_device
= {
1781 /* device model insists to have a release function */
1783 .release
= wl1271_device_release
,
1787 #define WL1271_DEFAULT_CHANNEL 0
1788 static int __devinit
wl1271_probe(struct spi_device
*spi
)
1790 struct wl12xx_platform_data
*pdata
;
1791 struct ieee80211_hw
*hw
;
1794 static const u8 nokia_oui
[3] = {0x00, 0x1f, 0xdf};
1796 pdata
= spi
->dev
.platform_data
;
1798 wl1271_error("no platform data");
1802 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
1804 wl1271_error("could not alloc ieee80211_hw");
1809 memset(wl
, 0, sizeof(*wl
));
1811 INIT_LIST_HEAD(&wl
->list
);
1814 dev_set_drvdata(&spi
->dev
, wl
);
1817 skb_queue_head_init(&wl
->tx_queue
);
1819 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
1820 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
1821 wl
->scanning
= false;
1822 wl
->default_key
= 0;
1824 wl
->rx_config
= WL1271_DEFAULT_RX_CONFIG
;
1825 wl
->rx_filter
= WL1271_DEFAULT_RX_FILTER
;
1828 wl
->psm_requested
= false;
1829 wl
->psm_entry_retry
= 0;
1830 wl
->tx_queue_stopped
= false;
1831 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1832 wl
->basic_rate_set
= WL1271_DEFAULT_BASIC_RATE_SET
;
1833 wl
->band
= IEEE80211_BAND_2GHZ
;
1837 for (i
= 0; i
< ACX_TX_DESCRIPTORS
; i
++)
1838 wl
->tx_frames
[i
] = NULL
;
1840 spin_lock_init(&wl
->wl_lock
);
1843 * In case our MAC address is not correctly set,
1844 * we use a random but Nokia MAC.
1846 memcpy(wl
->mac_addr
, nokia_oui
, 3);
1847 get_random_bytes(wl
->mac_addr
+ 3, 3);
1849 wl
->state
= WL1271_STATE_OFF
;
1850 mutex_init(&wl
->mutex
);
1852 /* This is the only SPI value that we need to set here, the rest
1853 * comes from the board-peripherals file */
1854 spi
->bits_per_word
= 32;
1856 ret
= spi_setup(spi
);
1858 wl1271_error("spi_setup failed");
1862 wl
->set_power
= pdata
->set_power
;
1863 if (!wl
->set_power
) {
1864 wl1271_error("set power function missing in platform data");
1871 wl1271_error("irq missing in platform data");
1876 ret
= request_irq(wl
->irq
, wl1271_irq
, 0, DRIVER_NAME
, wl
);
1878 wl1271_error("request_irq() failed: %d", ret
);
1882 set_irq_type(wl
->irq
, IRQ_TYPE_EDGE_RISING
);
1884 disable_irq(wl
->irq
);
1886 ret
= platform_device_register(&wl1271_device
);
1888 wl1271_error("couldn't register platform device");
1891 dev_set_drvdata(&wl1271_device
.dev
, wl
);
1893 /* Apply default driver configuration. */
1894 wl1271_conf_init(wl
);
1896 ret
= wl1271_init_ieee80211(wl
);
1900 ret
= wl1271_register_hw(wl
);
1904 wl1271_debugfs_init(wl
);
1906 wl1271_notice("initialized");
1911 platform_device_unregister(&wl1271_device
);
1914 free_irq(wl
->irq
, wl
);
1917 ieee80211_free_hw(hw
);
1922 static int __devexit
wl1271_remove(struct spi_device
*spi
)
1924 struct wl1271
*wl
= dev_get_drvdata(&spi
->dev
);
1926 ieee80211_unregister_hw(wl
->hw
);
1928 wl1271_debugfs_exit(wl
);
1929 platform_device_unregister(&wl1271_device
);
1930 free_irq(wl
->irq
, wl
);
1931 kfree(wl
->target_mem_map
);
1937 kfree(wl
->fw_status
);
1938 kfree(wl
->tx_res_if
);
1940 ieee80211_free_hw(wl
->hw
);
1946 static struct spi_driver wl1271_spi_driver
= {
1949 .bus
= &spi_bus_type
,
1950 .owner
= THIS_MODULE
,
1953 .probe
= wl1271_probe
,
1954 .remove
= __devexit_p(wl1271_remove
),
1957 static int __init
wl1271_init(void)
1961 ret
= spi_register_driver(&wl1271_spi_driver
);
1963 wl1271_error("failed to register spi driver: %d", ret
);
1971 static void __exit
wl1271_exit(void)
1973 spi_unregister_driver(&wl1271_spi_driver
);
1975 wl1271_notice("unloaded");
1978 module_init(wl1271_init
);
1979 module_exit(wl1271_exit
);
1981 MODULE_LICENSE("GPL");
1982 MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
1983 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
1984 MODULE_FIRMWARE(WL1271_FW_NAME
);