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),
57 DEBUG_FILTERS = BIT(15),
61 #define DEBUG_LEVEL (DEBUG_NONE)
63 #define DEBUG_DUMP_LIMIT 1024
65 #define wl1271_error(fmt, arg...) \
66 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
68 #define wl1271_warning(fmt, arg...) \
69 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
71 #define wl1271_notice(fmt, arg...) \
72 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
74 #define wl1271_info(fmt, arg...) \
75 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
77 #define wl1271_debug(level, fmt, arg...) \
79 if (level & DEBUG_LEVEL) \
80 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
83 #define wl1271_dump(level, prefix, buf, len) \
85 if (level & DEBUG_LEVEL) \
86 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
87 DUMP_PREFIX_OFFSET, 16, 1, \
89 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
93 #define wl1271_dump_ascii(level, prefix, buf, len) \
95 if (level & DEBUG_LEVEL) \
96 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
97 DUMP_PREFIX_OFFSET, 16, 1, \
99 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
103 #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
104 CFG_BSSID_FILTER_EN | \
107 #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
108 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
109 CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
110 CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
112 #define WL1271_FW_NAME "wl1271-fw.bin"
113 #define WL1271_NVS_NAME "wl1271-nvs.bin"
115 #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
116 #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
118 /* NVS data structure */
119 #define WL1271_NVS_SECTION_SIZE 468
121 #define WL1271_NVS_GENERAL_PARAMS_SIZE 57
122 #define WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED \
123 (WL1271_NVS_GENERAL_PARAMS_SIZE + 1)
124 #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE 17
125 #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED \
126 (WL1271_NVS_STAT_RADIO_PARAMS_SIZE + 1)
127 #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE 65
128 #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED \
129 (WL1271_NVS_DYN_RADIO_PARAMS_SIZE + 1)
130 #define WL1271_NVS_FEM_COUNT 2
131 #define WL1271_NVS_INI_SPARE_SIZE 124
133 struct wl1271_nvs_file {
135 u8 nvs[WL1271_NVS_SECTION_SIZE];
138 u8 general_params[WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED];
139 u8 stat_radio_params[WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED];
140 u8 dyn_radio_params[WL1271_NVS_FEM_COUNT]
141 [WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED];
142 u8 ini_spare[WL1271_NVS_INI_SPARE_SIZE];
143 } __attribute__ ((packed));
146 * Enable/disable 802.11a support for WL1273
148 #undef WL1271_80211A_ENABLED
151 * FIXME: for the wl1271, a busy word count of 1 here will result in a more
152 * optimal SPI interface. There is some SPI bug however, causing RXS time outs
153 * with this mode occasionally on boot, so lets have three for now. A value of
154 * three should make sure, that the chipset will always be ready, though this
155 * will impact throughput and latencies slightly.
157 #define WL1271_BUSY_WORD_CNT 3
158 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
160 #define WL1271_ELP_HW_STATE_ASLEEP 0
161 #define WL1271_ELP_HW_STATE_IRQ 1
163 #define WL1271_DEFAULT_BEACON_INT 100
164 #define WL1271_DEFAULT_DTIM_PERIOD 1
166 #define ACX_TX_DESCRIPTORS 32
174 enum wl1271_partition_type {
182 struct wl1271_partition {
187 struct wl1271_partition_set {
188 struct wl1271_partition mem;
189 struct wl1271_partition reg;
190 struct wl1271_partition mem2;
191 struct wl1271_partition mem3;
196 /* FIXME: I'm not sure about this structure name */
202 struct wl1271_stats {
203 struct acx_statistics *fw_stats;
204 unsigned long fw_stats_update;
206 unsigned int retry_count;
207 unsigned int excessive_retries;
210 struct wl1271_debugfs {
211 struct dentry *rootdir;
212 struct dentry *fw_statistics;
214 struct dentry *tx_internal_desc_overflow;
216 struct dentry *rx_out_of_mem;
217 struct dentry *rx_hdr_overflow;
218 struct dentry *rx_hw_stuck;
219 struct dentry *rx_dropped;
220 struct dentry *rx_fcs_err;
221 struct dentry *rx_xfr_hint_trig;
222 struct dentry *rx_path_reset;
223 struct dentry *rx_reset_counter;
225 struct dentry *dma_rx_requested;
226 struct dentry *dma_rx_errors;
227 struct dentry *dma_tx_requested;
228 struct dentry *dma_tx_errors;
230 struct dentry *isr_cmd_cmplt;
231 struct dentry *isr_fiqs;
232 struct dentry *isr_rx_headers;
233 struct dentry *isr_rx_mem_overflow;
234 struct dentry *isr_rx_rdys;
235 struct dentry *isr_irqs;
236 struct dentry *isr_tx_procs;
237 struct dentry *isr_decrypt_done;
238 struct dentry *isr_dma0_done;
239 struct dentry *isr_dma1_done;
240 struct dentry *isr_tx_exch_complete;
241 struct dentry *isr_commands;
242 struct dentry *isr_rx_procs;
243 struct dentry *isr_hw_pm_mode_changes;
244 struct dentry *isr_host_acknowledges;
245 struct dentry *isr_pci_pm;
246 struct dentry *isr_wakeups;
247 struct dentry *isr_low_rssi;
249 struct dentry *wep_addr_key_count;
250 struct dentry *wep_default_key_count;
251 /* skipping wep.reserved */
252 struct dentry *wep_key_not_found;
253 struct dentry *wep_decrypt_fail;
254 struct dentry *wep_packets;
255 struct dentry *wep_interrupt;
257 struct dentry *pwr_ps_enter;
258 struct dentry *pwr_elp_enter;
259 struct dentry *pwr_missing_bcns;
260 struct dentry *pwr_wake_on_host;
261 struct dentry *pwr_wake_on_timer_exp;
262 struct dentry *pwr_tx_with_ps;
263 struct dentry *pwr_tx_without_ps;
264 struct dentry *pwr_rcvd_beacons;
265 struct dentry *pwr_power_save_off;
266 struct dentry *pwr_enable_ps;
267 struct dentry *pwr_disable_ps;
268 struct dentry *pwr_fix_tsf_ps;
269 /* skipping cont_miss_bcns_spread for now */
270 struct dentry *pwr_rcvd_awake_beacons;
272 struct dentry *mic_rx_pkts;
273 struct dentry *mic_calc_failure;
275 struct dentry *aes_encrypt_fail;
276 struct dentry *aes_decrypt_fail;
277 struct dentry *aes_encrypt_packets;
278 struct dentry *aes_decrypt_packets;
279 struct dentry *aes_encrypt_interrupt;
280 struct dentry *aes_decrypt_interrupt;
282 struct dentry *event_heart_beat;
283 struct dentry *event_calibration;
284 struct dentry *event_rx_mismatch;
285 struct dentry *event_rx_mem_empty;
286 struct dentry *event_rx_pool;
287 struct dentry *event_oom_late;
288 struct dentry *event_phy_transmit_error;
289 struct dentry *event_tx_stuck;
291 struct dentry *ps_pspoll_timeouts;
292 struct dentry *ps_upsd_timeouts;
293 struct dentry *ps_upsd_max_sptime;
294 struct dentry *ps_upsd_max_apturn;
295 struct dentry *ps_pspoll_max_apturn;
296 struct dentry *ps_pspoll_utilization;
297 struct dentry *ps_upsd_utilization;
299 struct dentry *rxpipe_rx_prep_beacon_drop;
300 struct dentry *rxpipe_descr_host_int_trig_rx_data;
301 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
302 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
303 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
305 struct dentry *tx_queue_len;
307 struct dentry *retry_count;
308 struct dentry *excessive_retries;
309 struct dentry *gpio_power;
312 #define NUM_TX_QUEUES 4
313 #define NUM_RX_PKT_DESC 8
315 /* FW status registers */
316 struct wl1271_fw_status {
321 u8 tx_results_counter;
322 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
323 __le32 tx_released_blks[NUM_TX_QUEUES];
326 } __attribute__ ((packed));
328 struct wl1271_rx_mem_pool_addr {
335 u8 ssid[IW_ESSID_MAX_SIZE+1];
342 struct wl1271_if_operations {
343 void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
345 void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
347 void (*reset)(struct wl1271 *wl);
348 void (*init)(struct wl1271 *wl);
349 void (*power)(struct wl1271 *wl, bool enable);
350 struct device* (*dev)(struct wl1271 *wl);
351 void (*enable_irq)(struct wl1271 *wl);
352 void (*disable_irq)(struct wl1271 *wl);
356 struct platform_device *plat_dev;
357 struct ieee80211_hw *hw;
358 bool mac80211_registered;
362 struct wl1271_if_operations *if_ops;
364 void (*set_power)(bool enable);
369 enum wl1271_state state;
372 #define WL1271_FLAG_STA_RATES_CHANGED (0)
373 #define WL1271_FLAG_STA_ASSOCIATED (1)
374 #define WL1271_FLAG_JOINED (2)
375 #define WL1271_FLAG_GPIO_POWER (3)
376 #define WL1271_FLAG_TX_QUEUE_STOPPED (4)
377 #define WL1271_FLAG_SCANNING (5)
378 #define WL1271_FLAG_IN_ELP (6)
379 #define WL1271_FLAG_PSM (7)
380 #define WL1271_FLAG_PSM_REQUESTED (8)
381 #define WL1271_FLAG_IRQ_PENDING (9)
382 #define WL1271_FLAG_IRQ_RUNNING (10)
385 struct wl1271_partition_set part;
387 struct wl1271_chip chip;
394 struct wl1271_nvs_file *nvs;
397 u8 mac_addr[ETH_ALEN];
399 u8 ssid[IW_ESSID_MAX_SIZE + 1];
403 struct wl1271_acx_mem_map *target_mem_map;
405 /* Accounting for allocated / available TX blocks on HW */
406 u32 tx_blocks_freed[NUM_TX_QUEUES];
407 u32 tx_blocks_available;
408 u32 tx_results_count;
410 /* Transmitted TX packets counter for chipset interface */
411 u32 tx_packets_count;
413 /* Time-offset between host and chipset clocks */
416 /* Session counter for the chipset */
419 /* Frames scheduled for transmission, not handled yet */
420 struct sk_buff_head tx_queue;
422 struct work_struct tx_work;
424 /* Pending TX frames */
425 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
427 /* Security sequence number counters */
428 u8 tx_security_last_seq;
434 /* Rx memory pool address */
435 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
437 /* The target interrupt mask */
438 struct work_struct irq_work;
440 /* The mbox event mask */
443 /* Mailbox pointers */
446 /* Are we currently scanning */
447 struct wl1271_scan scan;
449 /* Our association ID */
452 /* currently configured rate set */
457 /* The current band */
458 enum ieee80211_band band;
460 /* Default key (for WEP) */
463 unsigned int filters;
464 unsigned int rx_config;
465 unsigned int rx_filter;
467 struct completion *elp_compl;
468 struct delayed_work elp_work;
470 /* retry counter for PSM entries */
476 struct wl1271_stats stats;
477 struct wl1271_debugfs debugfs;
481 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
483 struct wl1271_fw_status *fw_status;
484 struct wl1271_tx_hw_res_if *tx_res_if;
486 struct ieee80211_vif *vif;
488 /* Current chipset configuration */
489 struct conf_drv_settings conf;
493 struct list_head list;
496 int wl1271_plt_start(struct wl1271 *wl);
497 int wl1271_plt_stop(struct wl1271 *wl);
499 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
501 #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
503 #define WL1271_DEFAULT_POWER_LEVEL 0
505 #define WL1271_TX_QUEUE_LOW_WATERMARK 10
506 #define WL1271_TX_QUEUE_HIGH_WATERMARK 25
508 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
509 on in case is has been shut down shortly before */
510 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
511 #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
513 static inline bool wl1271_11a_enabled(void)
515 /* FIXME: this could be determined based on the NVS-INI file */
516 #ifdef WL1271_80211A_ENABLED