2 * This file is part of wl1271
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 #include <linux/mutex.h>
29 #include <linux/completion.h>
30 #include <linux/spinlock.h>
31 #include <linux/list.h>
32 #include <linux/bitops.h>
33 #include <net/mac80211.h>
35 #include "wl1271_conf.h"
37 #define DRIVER_NAME "wl1271"
38 #define DRIVER_PREFIX DRIVER_NAME ": "
45 DEBUG_MAILBOX
= BIT(3),
46 DEBUG_TESTMODE
= BIT(4),
53 DEBUG_MAC80211
= BIT(11),
59 #define DEBUG_LEVEL (DEBUG_NONE)
61 #define DEBUG_DUMP_LIMIT 1024
63 #define wl1271_error(fmt, arg...) \
64 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
66 #define wl1271_warning(fmt, arg...) \
67 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
69 #define wl1271_notice(fmt, arg...) \
70 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
72 #define wl1271_info(fmt, arg...) \
73 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
75 #define wl1271_debug(level, fmt, arg...) \
77 if (level & DEBUG_LEVEL) \
78 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
81 #define wl1271_dump(level, prefix, buf, len) \
83 if (level & DEBUG_LEVEL) \
84 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
85 DUMP_PREFIX_OFFSET, 16, 1, \
87 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
91 #define wl1271_dump_ascii(level, prefix, buf, len) \
93 if (level & DEBUG_LEVEL) \
94 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
95 DUMP_PREFIX_OFFSET, 16, 1, \
97 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
101 #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
102 CFG_BSSID_FILTER_EN | \
105 #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
106 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
107 CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
108 CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
110 #define WL1271_FW_NAME "wl1271-fw.bin"
111 #define WL1271_NVS_NAME "wl1271-nvs.bin"
113 /* NVS data structure */
114 #define WL1271_NVS_SECTION_SIZE 468
116 #define WL1271_NVS_GENERAL_PARAMS_SIZE 57
117 #define WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED \
118 (WL1271_NVS_GENERAL_PARAMS_SIZE + 1)
119 #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE 17
120 #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED \
121 (WL1271_NVS_STAT_RADIO_PARAMS_SIZE + 1)
122 #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE 65
123 #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED \
124 (WL1271_NVS_DYN_RADIO_PARAMS_SIZE + 1)
125 #define WL1271_NVS_FEM_COUNT 2
126 #define WL1271_NVS_INI_SPARE_SIZE 124
128 struct wl1271_nvs_file
{
130 u8 nvs
[WL1271_NVS_SECTION_SIZE
];
133 u8 general_params
[WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED
];
134 u8 stat_radio_params
[WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED
];
135 u8 dyn_radio_params
[WL1271_NVS_FEM_COUNT
]
136 [WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED
];
137 u8 ini_spare
[WL1271_NVS_INI_SPARE_SIZE
];
138 } __attribute__ ((packed
));
141 * Enable/disable 802.11a support for WL1273
143 #undef WL1271_80211A_ENABLED
146 * FIXME: for the wl1271, a busy word count of 1 here will result in a more
147 * optimal SPI interface. There is some SPI bug however, causing RXS time outs
148 * with this mode occasionally on boot, so lets have three for now. A value of
149 * three should make sure, that the chipset will always be ready, though this
150 * will impact throughput and latencies slightly.
152 #define WL1271_BUSY_WORD_CNT 3
153 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
155 #define WL1271_ELP_HW_STATE_ASLEEP 0
156 #define WL1271_ELP_HW_STATE_IRQ 1
158 #define WL1271_DEFAULT_BEACON_INT 100
159 #define WL1271_DEFAULT_DTIM_PERIOD 1
161 #define ACX_TX_DESCRIPTORS 32
169 enum wl1271_partition_type
{
177 struct wl1271_partition
{
182 struct wl1271_partition_set
{
183 struct wl1271_partition mem
;
184 struct wl1271_partition reg
;
185 struct wl1271_partition mem2
;
186 struct wl1271_partition mem3
;
191 /* FIXME: I'm not sure about this structure name */
197 struct wl1271_stats
{
198 struct acx_statistics
*fw_stats
;
199 unsigned long fw_stats_update
;
201 unsigned int retry_count
;
202 unsigned int excessive_retries
;
205 struct wl1271_debugfs
{
206 struct dentry
*rootdir
;
207 struct dentry
*fw_statistics
;
209 struct dentry
*tx_internal_desc_overflow
;
211 struct dentry
*rx_out_of_mem
;
212 struct dentry
*rx_hdr_overflow
;
213 struct dentry
*rx_hw_stuck
;
214 struct dentry
*rx_dropped
;
215 struct dentry
*rx_fcs_err
;
216 struct dentry
*rx_xfr_hint_trig
;
217 struct dentry
*rx_path_reset
;
218 struct dentry
*rx_reset_counter
;
220 struct dentry
*dma_rx_requested
;
221 struct dentry
*dma_rx_errors
;
222 struct dentry
*dma_tx_requested
;
223 struct dentry
*dma_tx_errors
;
225 struct dentry
*isr_cmd_cmplt
;
226 struct dentry
*isr_fiqs
;
227 struct dentry
*isr_rx_headers
;
228 struct dentry
*isr_rx_mem_overflow
;
229 struct dentry
*isr_rx_rdys
;
230 struct dentry
*isr_irqs
;
231 struct dentry
*isr_tx_procs
;
232 struct dentry
*isr_decrypt_done
;
233 struct dentry
*isr_dma0_done
;
234 struct dentry
*isr_dma1_done
;
235 struct dentry
*isr_tx_exch_complete
;
236 struct dentry
*isr_commands
;
237 struct dentry
*isr_rx_procs
;
238 struct dentry
*isr_hw_pm_mode_changes
;
239 struct dentry
*isr_host_acknowledges
;
240 struct dentry
*isr_pci_pm
;
241 struct dentry
*isr_wakeups
;
242 struct dentry
*isr_low_rssi
;
244 struct dentry
*wep_addr_key_count
;
245 struct dentry
*wep_default_key_count
;
246 /* skipping wep.reserved */
247 struct dentry
*wep_key_not_found
;
248 struct dentry
*wep_decrypt_fail
;
249 struct dentry
*wep_packets
;
250 struct dentry
*wep_interrupt
;
252 struct dentry
*pwr_ps_enter
;
253 struct dentry
*pwr_elp_enter
;
254 struct dentry
*pwr_missing_bcns
;
255 struct dentry
*pwr_wake_on_host
;
256 struct dentry
*pwr_wake_on_timer_exp
;
257 struct dentry
*pwr_tx_with_ps
;
258 struct dentry
*pwr_tx_without_ps
;
259 struct dentry
*pwr_rcvd_beacons
;
260 struct dentry
*pwr_power_save_off
;
261 struct dentry
*pwr_enable_ps
;
262 struct dentry
*pwr_disable_ps
;
263 struct dentry
*pwr_fix_tsf_ps
;
264 /* skipping cont_miss_bcns_spread for now */
265 struct dentry
*pwr_rcvd_awake_beacons
;
267 struct dentry
*mic_rx_pkts
;
268 struct dentry
*mic_calc_failure
;
270 struct dentry
*aes_encrypt_fail
;
271 struct dentry
*aes_decrypt_fail
;
272 struct dentry
*aes_encrypt_packets
;
273 struct dentry
*aes_decrypt_packets
;
274 struct dentry
*aes_encrypt_interrupt
;
275 struct dentry
*aes_decrypt_interrupt
;
277 struct dentry
*event_heart_beat
;
278 struct dentry
*event_calibration
;
279 struct dentry
*event_rx_mismatch
;
280 struct dentry
*event_rx_mem_empty
;
281 struct dentry
*event_rx_pool
;
282 struct dentry
*event_oom_late
;
283 struct dentry
*event_phy_transmit_error
;
284 struct dentry
*event_tx_stuck
;
286 struct dentry
*ps_pspoll_timeouts
;
287 struct dentry
*ps_upsd_timeouts
;
288 struct dentry
*ps_upsd_max_sptime
;
289 struct dentry
*ps_upsd_max_apturn
;
290 struct dentry
*ps_pspoll_max_apturn
;
291 struct dentry
*ps_pspoll_utilization
;
292 struct dentry
*ps_upsd_utilization
;
294 struct dentry
*rxpipe_rx_prep_beacon_drop
;
295 struct dentry
*rxpipe_descr_host_int_trig_rx_data
;
296 struct dentry
*rxpipe_beacon_buffer_thres_host_int_trig_rx_data
;
297 struct dentry
*rxpipe_missed_beacon_host_int_trig_rx_data
;
298 struct dentry
*rxpipe_tx_xfr_host_int_trig_rx_data
;
300 struct dentry
*tx_queue_len
;
302 struct dentry
*retry_count
;
303 struct dentry
*excessive_retries
;
304 struct dentry
*gpio_power
;
307 #define NUM_TX_QUEUES 4
308 #define NUM_RX_PKT_DESC 8
310 /* FW status registers */
311 struct wl1271_fw_status
{
316 u8 tx_results_counter
;
317 __le32 rx_pkt_descs
[NUM_RX_PKT_DESC
];
318 __le32 tx_released_blks
[NUM_TX_QUEUES
];
321 } __attribute__ ((packed
));
323 struct wl1271_rx_mem_pool_addr
{
330 u8 ssid
[IW_ESSID_MAX_SIZE
+1];
338 struct ieee80211_hw
*hw
;
339 bool mac80211_registered
;
341 struct spi_device
*spi
;
343 void (*set_power
)(bool enable
);
348 enum wl1271_state state
;
351 #define WL1271_FLAG_STA_RATES_CHANGED (0)
352 #define WL1271_FLAG_STA_ASSOCIATED (1)
353 #define WL1271_FLAG_JOINED (2)
354 #define WL1271_FLAG_GPIO_POWER (3)
355 #define WL1271_FLAG_TX_QUEUE_STOPPED (4)
356 #define WL1271_FLAG_SCANNING (5)
357 #define WL1271_FLAG_IN_ELP (6)
358 #define WL1271_FLAG_PSM (7)
359 #define WL1271_FLAG_PSM_REQUESTED (8)
362 struct wl1271_partition_set part
;
364 struct wl1271_chip chip
;
371 struct wl1271_nvs_file
*nvs
;
374 u8 mac_addr
[ETH_ALEN
];
376 u8 ssid
[IW_ESSID_MAX_SIZE
+ 1];
380 struct wl1271_acx_mem_map
*target_mem_map
;
382 /* Accounting for allocated / available TX blocks on HW */
383 u32 tx_blocks_freed
[NUM_TX_QUEUES
];
384 u32 tx_blocks_available
;
387 /* Transmitted TX packets counter for chipset interface */
388 int tx_packets_count
;
390 /* Time-offset between host and chipset clocks */
393 /* Session counter for the chipset */
396 /* Frames scheduled for transmission, not handled yet */
397 struct sk_buff_head tx_queue
;
399 struct work_struct tx_work
;
401 /* Pending TX frames */
402 struct sk_buff
*tx_frames
[ACX_TX_DESCRIPTORS
];
404 /* Security sequence number counters */
405 u8 tx_security_last_seq
;
406 u16 tx_security_seq_16
;
407 u32 tx_security_seq_32
;
412 /* Rx memory pool address */
413 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr
;
415 /* The target interrupt mask */
416 struct work_struct irq_work
;
418 /* The mbox event mask */
421 /* Mailbox pointers */
424 /* Are we currently scanning */
425 struct wl1271_scan scan
;
427 /* Our association ID */
430 /* currently configured rate set */
435 /* The current band */
436 enum ieee80211_band band
;
438 /* Default key (for WEP) */
441 unsigned int rx_config
;
442 unsigned int rx_filter
;
444 struct completion
*elp_compl
;
445 struct delayed_work elp_work
;
447 /* retry counter for PSM entries */
453 struct wl1271_stats stats
;
454 struct wl1271_debugfs debugfs
;
458 u32 buffer_busyword
[WL1271_BUSY_WORD_CNT
];
460 struct wl1271_fw_status
*fw_status
;
461 struct wl1271_tx_hw_res_if
*tx_res_if
;
463 struct ieee80211_vif
*vif
;
465 /* Current chipset configuration */
466 struct conf_drv_settings conf
;
468 struct list_head list
;
471 int wl1271_plt_start(struct wl1271
*wl
);
472 int wl1271_plt_stop(struct wl1271
*wl
);
474 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
476 #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
478 #define WL1271_DEFAULT_POWER_LEVEL 0
480 #define WL1271_TX_QUEUE_MAX_LENGTH 20
482 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
483 on in case is has been shut down shortly before */
484 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
485 #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
487 static inline bool wl1271_11a_enabled(void)
489 /* FIXME: this could be determined based on the NVS-INI file */
490 #ifdef WL1271_80211A_ENABLED