2 * This file is part of wl1251
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008-2009 Nokia Corporation
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include <linux/mutex.h>
27 #include <linux/list.h>
28 #include <linux/bitops.h>
29 #include <linux/interrupt.h>
30 #include <net/mac80211.h>
32 #define DRIVER_NAME "wl1251"
33 #define DRIVER_PREFIX DRIVER_NAME ": "
40 DEBUG_MAILBOX = BIT(3),
41 DEBUG_NETLINK = BIT(4),
48 DEBUG_MAC80211 = BIT(11),
54 #define DEBUG_LEVEL (DEBUG_NONE)
56 #define DEBUG_DUMP_LIMIT 1024
58 #define wl1251_error(fmt, arg...) \
59 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
61 #define wl1251_warning(fmt, arg...) \
62 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
64 #define wl1251_notice(fmt, arg...) \
65 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
67 #define wl1251_info(fmt, arg...) \
68 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
70 #define wl1251_debug(level, fmt, arg...) \
72 if (level & DEBUG_LEVEL) \
73 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
76 #define wl1251_dump(level, prefix, buf, len) \
78 if (level & DEBUG_LEVEL) \
79 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
80 DUMP_PREFIX_OFFSET, 16, 1, \
82 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
86 #define wl1251_dump_ascii(level, prefix, buf, len) \
88 if (level & DEBUG_LEVEL) \
89 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
90 DUMP_PREFIX_OFFSET, 16, 1, \
92 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
96 #define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
100 #define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
108 #define WL1251_BUSY_WORD_LEN 8
126 enum wl1251_partition_type {
134 enum wl1251_station_mode {
136 STATION_POWER_SAVE_MODE,
140 struct wl1251_partition {
145 struct wl1251_partition_set {
146 struct wl1251_partition mem;
147 struct wl1251_partition reg;
152 struct wl1251_stats {
153 struct acx_statistics *fw_stats;
154 unsigned long fw_stats_update;
156 unsigned int retry_count;
157 unsigned int excessive_retries;
160 struct wl1251_debugfs {
161 struct dentry *rootdir;
162 struct dentry *fw_statistics;
164 struct dentry *tx_internal_desc_overflow;
166 struct dentry *rx_out_of_mem;
167 struct dentry *rx_hdr_overflow;
168 struct dentry *rx_hw_stuck;
169 struct dentry *rx_dropped;
170 struct dentry *rx_fcs_err;
171 struct dentry *rx_xfr_hint_trig;
172 struct dentry *rx_path_reset;
173 struct dentry *rx_reset_counter;
175 struct dentry *dma_rx_requested;
176 struct dentry *dma_rx_errors;
177 struct dentry *dma_tx_requested;
178 struct dentry *dma_tx_errors;
180 struct dentry *isr_cmd_cmplt;
181 struct dentry *isr_fiqs;
182 struct dentry *isr_rx_headers;
183 struct dentry *isr_rx_mem_overflow;
184 struct dentry *isr_rx_rdys;
185 struct dentry *isr_irqs;
186 struct dentry *isr_tx_procs;
187 struct dentry *isr_decrypt_done;
188 struct dentry *isr_dma0_done;
189 struct dentry *isr_dma1_done;
190 struct dentry *isr_tx_exch_complete;
191 struct dentry *isr_commands;
192 struct dentry *isr_rx_procs;
193 struct dentry *isr_hw_pm_mode_changes;
194 struct dentry *isr_host_acknowledges;
195 struct dentry *isr_pci_pm;
196 struct dentry *isr_wakeups;
197 struct dentry *isr_low_rssi;
199 struct dentry *wep_addr_key_count;
200 struct dentry *wep_default_key_count;
201 /* skipping wep.reserved */
202 struct dentry *wep_key_not_found;
203 struct dentry *wep_decrypt_fail;
204 struct dentry *wep_packets;
205 struct dentry *wep_interrupt;
207 struct dentry *pwr_ps_enter;
208 struct dentry *pwr_elp_enter;
209 struct dentry *pwr_missing_bcns;
210 struct dentry *pwr_wake_on_host;
211 struct dentry *pwr_wake_on_timer_exp;
212 struct dentry *pwr_tx_with_ps;
213 struct dentry *pwr_tx_without_ps;
214 struct dentry *pwr_rcvd_beacons;
215 struct dentry *pwr_power_save_off;
216 struct dentry *pwr_enable_ps;
217 struct dentry *pwr_disable_ps;
218 struct dentry *pwr_fix_tsf_ps;
219 /* skipping cont_miss_bcns_spread for now */
220 struct dentry *pwr_rcvd_awake_beacons;
222 struct dentry *mic_rx_pkts;
223 struct dentry *mic_calc_failure;
225 struct dentry *aes_encrypt_fail;
226 struct dentry *aes_decrypt_fail;
227 struct dentry *aes_encrypt_packets;
228 struct dentry *aes_decrypt_packets;
229 struct dentry *aes_encrypt_interrupt;
230 struct dentry *aes_decrypt_interrupt;
232 struct dentry *event_heart_beat;
233 struct dentry *event_calibration;
234 struct dentry *event_rx_mismatch;
235 struct dentry *event_rx_mem_empty;
236 struct dentry *event_rx_pool;
237 struct dentry *event_oom_late;
238 struct dentry *event_phy_transmit_error;
239 struct dentry *event_tx_stuck;
241 struct dentry *ps_pspoll_timeouts;
242 struct dentry *ps_upsd_timeouts;
243 struct dentry *ps_upsd_max_sptime;
244 struct dentry *ps_upsd_max_apturn;
245 struct dentry *ps_pspoll_max_apturn;
246 struct dentry *ps_pspoll_utilization;
247 struct dentry *ps_upsd_utilization;
249 struct dentry *rxpipe_rx_prep_beacon_drop;
250 struct dentry *rxpipe_descr_host_int_trig_rx_data;
251 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
252 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
253 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
255 struct dentry *tx_queue_len;
256 struct dentry *tx_queue_status;
258 struct dentry *retry_count;
259 struct dentry *excessive_retries;
261 struct dentry *dump_nvs;
262 struct dentry *dump_full;
265 struct wl1251_if_operations {
266 void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
267 void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
268 void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
269 void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
270 int (*power)(struct wl1251 *wl, bool enable);
271 void (*reset)(struct wl1251 *wl);
272 void (*enable_irq)(struct wl1251 *wl);
273 void (*disable_irq)(struct wl1251 *wl);
277 struct ieee80211_hw *hw;
278 bool mac80211_registered;
281 const struct wl1251_if_operations *if_ops;
283 void (*set_power)(bool enable);
290 enum wl1251_state state;
293 int physical_mem_addr;
294 int physical_reg_addr;
295 int virtual_mem_addr;
296 int virtual_reg_addr;
300 struct boot_attr boot_attr;
308 u8 mac_addr[ETH_ALEN];
312 bool monitor_present;
315 void *target_mem_map;
316 struct acx_data_path_params_resp *data_path;
318 /* Number of TX packets transferred to the FW, modulo 16 */
321 /* Frames scheduled for transmission, not handled yet */
322 struct sk_buff_head tx_queue;
323 bool tx_queue_stopped;
325 struct work_struct tx_work;
327 /* Pending TX frames */
328 struct sk_buff *tx_frames[16];
331 * Index pointing to the next TX complete entry
332 * in the cyclic XT complete array we get from
335 u32 next_tx_complete;
340 /* Rx frames handled */
343 /* Current double buffer */
344 u32 rx_current_buffer;
347 /* The target interrupt mask */
349 struct work_struct irq_work;
351 /* The mbox event mask */
354 /* Mailbox pointers */
357 /* Are we currently scanning */
360 /* Default key (for WEP) */
363 unsigned int tx_mgmt_frm_rate;
364 unsigned int tx_mgmt_frm_mod;
366 unsigned int rx_config;
367 unsigned int rx_filter;
369 /* is firmware in elp mode */
372 struct delayed_work elp_work;
374 enum wl1251_station_mode station_mode;
376 /* PSM mode requested */
387 struct wl1251_stats stats;
388 struct wl1251_debugfs debugfs;
392 u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
393 struct wl1251_rx_descriptor *rx_descriptor;
395 struct ieee80211_vif *vif;
400 /* Most recently reported noise in dBm */
406 unsigned long ps_change_jiffies;
407 unsigned long last_io_jiffies;
408 struct delayed_work ps_work;
410 bool ps_transitioning;
413 int wl1251_plt_start(struct wl1251 *wl);
414 int wl1251_plt_stop(struct wl1251 *wl);
416 struct ieee80211_hw *wl1251_alloc_hw(void);
417 int wl1251_free_hw(struct wl1251 *wl);
418 int wl1251_init_ieee80211(struct wl1251 *wl);
419 void wl1251_enable_interrupts(struct wl1251 *wl);
420 void wl1251_disable_interrupts(struct wl1251 *wl);
421 irqreturn_t wl1251_irq(int irq, void *cookie);
423 #define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
424 #define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
425 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
427 #define WL1251_DEFAULT_POWER_LEVEL 20
429 #define WL1251_TX_QUEUE_LOW_WATERMARK 10
430 #define WL1251_TX_QUEUE_HIGH_WATERMARK 25
432 #define WL1251_DEFAULT_BEACON_INT 100
433 #define WL1251_DEFAULT_DTIM_PERIOD 1
435 #define WL1251_DEFAULT_CHANNEL 0
437 #define WL1251_DEFAULT_BET_CONSECUTIVE 10
439 #define CHIP_ID_1251_PG10 (0x7010101)
440 #define CHIP_ID_1251_PG11 (0x7020101)
441 #define CHIP_ID_1251_PG12 (0x7030101)
442 #define CHIP_ID_1271_PG10 (0x4030101)
443 #define CHIP_ID_1271_PG20 (0x4030111)
445 #define WL1251_FW_NAME "wl1251-fw.bin"
446 #define WL1251_NVS_NAME "wl1251-nvs.bin"
448 #define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
450 #define WL1251_PART_DOWN_MEM_START 0x0
451 #define WL1251_PART_DOWN_MEM_SIZE 0x16800
452 #define WL1251_PART_DOWN_REG_START REGISTERS_BASE
453 #define WL1251_PART_DOWN_REG_SIZE REGISTERS_DOWN_SIZE
455 #define WL1251_PART_WORK_MEM_START 0x28000
456 #define WL1251_PART_WORK_MEM_SIZE 0x14000
457 #define WL1251_PART_WORK_REG_START REGISTERS_BASE
458 #define WL1251_PART_WORK_REG_SIZE REGISTERS_WORK_SIZE
460 #define WL1251_DEFAULT_LOW_RSSI_WEIGHT 10
461 #define WL1251_DEFAULT_LOW_RSSI_DEPTH 10