blob: bf245a87e80e85c4aff702b4722e79e3413f2c13 [file] [log] [blame]
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001/*
Kalle Valo80301cd2009-06-12 14:17:39 +03002 * This file is part of wl1251
Kalle Valo2f01a1f2009-04-29 23:33:31 +03003 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
Kalle Valo2f01a1f2009-04-29 23:33:31 +03007 * 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.
10 *
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.
15 *
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
19 * 02110-1301 USA
20 *
21 */
22
Kalle Valo80301cd2009-06-12 14:17:39 +030023#ifndef __WL1251_H__
24#define __WL1251_H__
Kalle Valo2f01a1f2009-04-29 23:33:31 +030025
26#include <linux/mutex.h>
27#include <linux/list.h>
28#include <linux/bitops.h>
29#include <net/mac80211.h>
30
Kalle Valo80301cd2009-06-12 14:17:39 +030031#define DRIVER_NAME "wl1251"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030032#define DRIVER_PREFIX DRIVER_NAME ": "
33
34enum {
35 DEBUG_NONE = 0,
36 DEBUG_IRQ = BIT(0),
37 DEBUG_SPI = BIT(1),
38 DEBUG_BOOT = BIT(2),
39 DEBUG_MAILBOX = BIT(3),
40 DEBUG_NETLINK = BIT(4),
41 DEBUG_EVENT = BIT(5),
42 DEBUG_TX = BIT(6),
43 DEBUG_RX = BIT(7),
44 DEBUG_SCAN = BIT(8),
45 DEBUG_CRYPT = BIT(9),
46 DEBUG_PSM = BIT(10),
47 DEBUG_MAC80211 = BIT(11),
48 DEBUG_CMD = BIT(12),
49 DEBUG_ACX = BIT(13),
50 DEBUG_ALL = ~0,
51};
52
53#define DEBUG_LEVEL (DEBUG_NONE)
54
55#define DEBUG_DUMP_LIMIT 1024
56
Kalle Valo80301cd2009-06-12 14:17:39 +030057#define wl1251_error(fmt, arg...) \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030058 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
59
Kalle Valo80301cd2009-06-12 14:17:39 +030060#define wl1251_warning(fmt, arg...) \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030061 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
62
Kalle Valo80301cd2009-06-12 14:17:39 +030063#define wl1251_notice(fmt, arg...) \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030064 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
65
Kalle Valo80301cd2009-06-12 14:17:39 +030066#define wl1251_info(fmt, arg...) \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030067 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
68
Kalle Valo80301cd2009-06-12 14:17:39 +030069#define wl1251_debug(level, fmt, arg...) \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030070 do { \
71 if (level & DEBUG_LEVEL) \
72 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
73 } while (0)
74
Kalle Valo80301cd2009-06-12 14:17:39 +030075#define wl1251_dump(level, prefix, buf, len) \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030076 do { \
77 if (level & DEBUG_LEVEL) \
78 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
79 DUMP_PREFIX_OFFSET, 16, 1, \
80 buf, \
81 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
82 0); \
83 } while (0)
84
Kalle Valo80301cd2009-06-12 14:17:39 +030085#define wl1251_dump_ascii(level, prefix, buf, len) \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030086 do { \
87 if (level & DEBUG_LEVEL) \
88 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
89 DUMP_PREFIX_OFFSET, 16, 1, \
90 buf, \
91 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
92 true); \
93 } while (0)
94
Kalle Valo80301cd2009-06-12 14:17:39 +030095#define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030096 CFG_BSSID_FILTER_EN)
97
Kalle Valo80301cd2009-06-12 14:17:39 +030098#define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
Kalle Valo2f01a1f2009-04-29 23:33:31 +030099 CFG_RX_MGMT_EN | \
100 CFG_RX_DATA_EN | \
101 CFG_RX_CTL_EN | \
102 CFG_RX_BCN_EN | \
103 CFG_RX_AUTH_EN | \
104 CFG_RX_ASSOC_EN)
105
Kalle Valo80301cd2009-06-12 14:17:39 +0300106#define WL1251_BUSY_WORD_LEN 8
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300107
108struct boot_attr {
109 u32 radio_type;
110 u8 mac_clock;
111 u8 arm_clock;
112 int firmware_debug;
113 u32 minor;
114 u32 major;
115 u32 bugfix;
116};
117
Kalle Valo80301cd2009-06-12 14:17:39 +0300118enum wl1251_state {
119 WL1251_STATE_OFF,
120 WL1251_STATE_ON,
121 WL1251_STATE_PLT,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300122};
123
Kalle Valo80301cd2009-06-12 14:17:39 +0300124enum wl1251_partition_type {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300125 PART_DOWN,
126 PART_WORK,
127 PART_DRPW,
128
129 PART_TABLE_LEN
130};
131
Jarkko Nikulaa0bbb582011-04-04 11:04:57 +0300132enum wl1251_station_mode {
133 STATION_ACTIVE_MODE,
134 STATION_POWER_SAVE_MODE,
135};
136
Kalle Valo80301cd2009-06-12 14:17:39 +0300137struct wl1251_partition {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300138 u32 size;
139 u32 start;
140};
141
Kalle Valo80301cd2009-06-12 14:17:39 +0300142struct wl1251_partition_set {
143 struct wl1251_partition mem;
144 struct wl1251_partition reg;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300145};
146
Kalle Valo80301cd2009-06-12 14:17:39 +0300147struct wl1251;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300148
Kalle Valo80301cd2009-06-12 14:17:39 +0300149struct wl1251_stats {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300150 struct acx_statistics *fw_stats;
151 unsigned long fw_stats_update;
152
153 unsigned int retry_count;
154 unsigned int excessive_retries;
155};
156
Kalle Valo80301cd2009-06-12 14:17:39 +0300157struct wl1251_debugfs {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300158 struct dentry *rootdir;
159 struct dentry *fw_statistics;
160
161 struct dentry *tx_internal_desc_overflow;
162
163 struct dentry *rx_out_of_mem;
164 struct dentry *rx_hdr_overflow;
165 struct dentry *rx_hw_stuck;
166 struct dentry *rx_dropped;
167 struct dentry *rx_fcs_err;
168 struct dentry *rx_xfr_hint_trig;
169 struct dentry *rx_path_reset;
170 struct dentry *rx_reset_counter;
171
172 struct dentry *dma_rx_requested;
173 struct dentry *dma_rx_errors;
174 struct dentry *dma_tx_requested;
175 struct dentry *dma_tx_errors;
176
177 struct dentry *isr_cmd_cmplt;
178 struct dentry *isr_fiqs;
179 struct dentry *isr_rx_headers;
180 struct dentry *isr_rx_mem_overflow;
181 struct dentry *isr_rx_rdys;
182 struct dentry *isr_irqs;
183 struct dentry *isr_tx_procs;
184 struct dentry *isr_decrypt_done;
185 struct dentry *isr_dma0_done;
186 struct dentry *isr_dma1_done;
187 struct dentry *isr_tx_exch_complete;
188 struct dentry *isr_commands;
189 struct dentry *isr_rx_procs;
190 struct dentry *isr_hw_pm_mode_changes;
191 struct dentry *isr_host_acknowledges;
192 struct dentry *isr_pci_pm;
193 struct dentry *isr_wakeups;
194 struct dentry *isr_low_rssi;
195
196 struct dentry *wep_addr_key_count;
197 struct dentry *wep_default_key_count;
198 /* skipping wep.reserved */
199 struct dentry *wep_key_not_found;
200 struct dentry *wep_decrypt_fail;
201 struct dentry *wep_packets;
202 struct dentry *wep_interrupt;
203
204 struct dentry *pwr_ps_enter;
205 struct dentry *pwr_elp_enter;
206 struct dentry *pwr_missing_bcns;
207 struct dentry *pwr_wake_on_host;
208 struct dentry *pwr_wake_on_timer_exp;
209 struct dentry *pwr_tx_with_ps;
210 struct dentry *pwr_tx_without_ps;
211 struct dentry *pwr_rcvd_beacons;
212 struct dentry *pwr_power_save_off;
213 struct dentry *pwr_enable_ps;
214 struct dentry *pwr_disable_ps;
215 struct dentry *pwr_fix_tsf_ps;
216 /* skipping cont_miss_bcns_spread for now */
217 struct dentry *pwr_rcvd_awake_beacons;
218
219 struct dentry *mic_rx_pkts;
220 struct dentry *mic_calc_failure;
221
222 struct dentry *aes_encrypt_fail;
223 struct dentry *aes_decrypt_fail;
224 struct dentry *aes_encrypt_packets;
225 struct dentry *aes_decrypt_packets;
226 struct dentry *aes_encrypt_interrupt;
227 struct dentry *aes_decrypt_interrupt;
228
229 struct dentry *event_heart_beat;
230 struct dentry *event_calibration;
231 struct dentry *event_rx_mismatch;
232 struct dentry *event_rx_mem_empty;
233 struct dentry *event_rx_pool;
234 struct dentry *event_oom_late;
235 struct dentry *event_phy_transmit_error;
236 struct dentry *event_tx_stuck;
237
238 struct dentry *ps_pspoll_timeouts;
239 struct dentry *ps_upsd_timeouts;
240 struct dentry *ps_upsd_max_sptime;
241 struct dentry *ps_upsd_max_apturn;
242 struct dentry *ps_pspoll_max_apturn;
243 struct dentry *ps_pspoll_utilization;
244 struct dentry *ps_upsd_utilization;
245
246 struct dentry *rxpipe_rx_prep_beacon_drop;
247 struct dentry *rxpipe_descr_host_int_trig_rx_data;
248 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
249 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
250 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
251
252 struct dentry *tx_queue_len;
Kalle Valob7339b12009-11-30 10:17:38 +0200253 struct dentry *tx_queue_status;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300254
255 struct dentry *retry_count;
256 struct dentry *excessive_retries;
257};
258
Bob Copeland08d9f5722009-08-07 13:33:11 +0300259struct wl1251_if_operations {
260 void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
261 void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
Grazvydas Ignotas3f9e7502010-03-11 17:44:57 +0200262 void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
263 void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
Grazvydas Ignotascb7bbc72010-11-04 00:13:47 +0200264 int (*power)(struct wl1251 *wl, bool enable);
Bob Copeland08d9f5722009-08-07 13:33:11 +0300265 void (*reset)(struct wl1251 *wl);
Bob Copelandb5ed9c12009-08-07 13:33:49 +0300266 void (*enable_irq)(struct wl1251 *wl);
267 void (*disable_irq)(struct wl1251 *wl);
Bob Copeland08d9f5722009-08-07 13:33:11 +0300268};
269
Kalle Valo80301cd2009-06-12 14:17:39 +0300270struct wl1251 {
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300271 struct ieee80211_hw *hw;
272 bool mac80211_registered;
273
Bob Copelandaf8c78e2009-08-07 13:33:34 +0300274 void *if_priv;
Bob Copeland8e639c02009-08-07 13:33:26 +0300275 const struct wl1251_if_operations *if_ops;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300276
277 void (*set_power)(bool enable);
278 int irq;
David-John Willisc95cf3d02009-11-17 18:50:09 +0200279 bool use_eeprom;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300280
Denis 'GNUtoo' Carikli9df86e22010-08-27 23:48:19 +0200281 spinlock_t wl_lock;
282
Kalle Valo80301cd2009-06-12 14:17:39 +0300283 enum wl1251_state state;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300284 struct mutex mutex;
285
286 int physical_mem_addr;
287 int physical_reg_addr;
288 int virtual_mem_addr;
289 int virtual_reg_addr;
290
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300291 int cmd_box_addr;
292 int event_box_addr;
293 struct boot_attr boot_attr;
294
295 u8 *fw;
296 size_t fw_len;
297 u8 *nvs;
298 size_t nvs_len;
299
300 u8 bssid[ETH_ALEN];
301 u8 mac_addr[ETH_ALEN];
302 u8 bss_type;
303 u8 listen_int;
304 int channel;
305
306 void *target_mem_map;
307 struct acx_data_path_params_resp *data_path;
308
309 /* Number of TX packets transferred to the FW, modulo 16 */
310 u32 data_in_count;
311
312 /* Frames scheduled for transmission, not handled yet */
313 struct sk_buff_head tx_queue;
314 bool tx_queue_stopped;
315
316 struct work_struct tx_work;
317 struct work_struct filter_work;
318
319 /* Pending TX frames */
320 struct sk_buff *tx_frames[16];
321
322 /*
323 * Index pointing to the next TX complete entry
324 * in the cyclic XT complete array we get from
325 * the FW.
326 */
327 u32 next_tx_complete;
328
329 /* FW Rx counter */
330 u32 rx_counter;
331
332 /* Rx frames handled */
333 u32 rx_handled;
334
335 /* Current double buffer */
336 u32 rx_current_buffer;
337 u32 rx_last_id;
338
339 /* The target interrupt mask */
340 u32 intr_mask;
341 struct work_struct irq_work;
342
343 /* The mbox event mask */
344 u32 event_mask;
345
346 /* Mailbox pointers */
347 u32 mbox_ptr[2];
348
349 /* Are we currently scanning */
350 bool scanning;
351
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300352 /* Default key (for WEP) */
353 u32 default_key;
354
355 unsigned int tx_mgmt_frm_rate;
356 unsigned int tx_mgmt_frm_mod;
357
358 unsigned int rx_config;
359 unsigned int rx_filter;
360
361 /* is firmware in elp mode */
362 bool elp;
363
Juuso Oikarinend5da79a2009-11-17 18:48:37 +0200364 struct delayed_work elp_work;
365
Jarkko Nikulaa0bbb582011-04-04 11:04:57 +0300366 enum wl1251_station_mode station_mode;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300367
368 /* PSM mode requested */
369 bool psm_requested;
370
Kalle Valoe2fd4612009-08-07 13:34:12 +0300371 u16 beacon_int;
372 u8 dtim_period;
373
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300374 /* in dBm */
375 int power_level;
376
David Gnedt8964e492011-01-30 20:11:00 +0100377 int rssi_thold;
378
Kalle Valo80301cd2009-06-12 14:17:39 +0300379 struct wl1251_stats stats;
380 struct wl1251_debugfs debugfs;
Kalle Valo1d3b8132009-06-12 14:14:28 +0300381
382 u32 buffer_32;
Kalle Valo56343a32009-06-12 14:14:47 +0300383 u32 buffer_cmd;
Kalle Valo80301cd2009-06-12 14:17:39 +0300384 u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
385 struct wl1251_rx_descriptor *rx_descriptor;
Kalle Valo0e71bb02009-08-07 13:33:57 +0300386
Juuso Oikarinen287f6f92009-11-17 18:48:23 +0200387 struct ieee80211_vif *vif;
388
Kalle Valo0e71bb02009-08-07 13:33:57 +0300389 u32 chip_id;
390 char fw_ver[21];
John W. Linville19434142010-07-28 15:23:30 -0400391
392 /* Most recently reported noise in dBm */
393 s8 noise;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300394};
395
Kalle Valo80301cd2009-06-12 14:17:39 +0300396int wl1251_plt_start(struct wl1251 *wl);
397int wl1251_plt_stop(struct wl1251 *wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300398
Bob Copeland8e639c02009-08-07 13:33:26 +0300399struct ieee80211_hw *wl1251_alloc_hw(void);
400int wl1251_free_hw(struct wl1251 *wl);
401int wl1251_init_ieee80211(struct wl1251 *wl);
Bob Copelandb5ed9c12009-08-07 13:33:49 +0300402void wl1251_enable_interrupts(struct wl1251 *wl);
403void wl1251_disable_interrupts(struct wl1251 *wl);
Bob Copeland8e639c02009-08-07 13:33:26 +0300404
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300405#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
406#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
407#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
408
Kalle Valo80301cd2009-06-12 14:17:39 +0300409#define WL1251_DEFAULT_POWER_LEVEL 20
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300410
Denis 'GNUtoo' Carikli9df86e22010-08-27 23:48:19 +0200411#define WL1251_TX_QUEUE_LOW_WATERMARK 10
412#define WL1251_TX_QUEUE_HIGH_WATERMARK 25
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300413
Kalle Valoe2fd4612009-08-07 13:34:12 +0300414#define WL1251_DEFAULT_BEACON_INT 100
415#define WL1251_DEFAULT_DTIM_PERIOD 1
416
Kalle Valo97802792009-08-07 13:34:27 +0300417#define WL1251_DEFAULT_CHANNEL 0
418
David Gnedtc3e334d2011-01-30 20:10:57 +0100419#define WL1251_DEFAULT_BET_CONSECUTIVE 10
420
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300421#define CHIP_ID_1251_PG10 (0x7010101)
422#define CHIP_ID_1251_PG11 (0x7020101)
423#define CHIP_ID_1251_PG12 (0x7030101)
424#define CHIP_ID_1271_PG10 (0x4030101)
Luciano Coelho27797d62009-06-12 14:15:33 +0300425#define CHIP_ID_1271_PG20 (0x4030111)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300426
Kalle Valo0e71bb02009-08-07 13:33:57 +0300427#define WL1251_FW_NAME "wl1251-fw.bin"
428#define WL1251_NVS_NAME "wl1251-nvs.bin"
429
Stefan Weile8a8b252011-01-02 15:12:42 +0100430#define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
Kalle Valo0e71bb02009-08-07 13:33:57 +0300431
432#define WL1251_PART_DOWN_MEM_START 0x0
433#define WL1251_PART_DOWN_MEM_SIZE 0x16800
434#define WL1251_PART_DOWN_REG_START REGISTERS_BASE
435#define WL1251_PART_DOWN_REG_SIZE REGISTERS_DOWN_SIZE
436
437#define WL1251_PART_WORK_MEM_START 0x28000
438#define WL1251_PART_WORK_MEM_SIZE 0x14000
439#define WL1251_PART_WORK_REG_START REGISTERS_BASE
440#define WL1251_PART_WORK_REG_SIZE REGISTERS_WORK_SIZE
441
David Gnedt8964e492011-01-30 20:11:00 +0100442#define WL1251_DEFAULT_LOW_RSSI_WEIGHT 10
443#define WL1251_DEFAULT_LOW_RSSI_DEPTH 10
444
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300445#endif