c020adbe2d0a0077482b3fd27b7a450a20bcd45a
[pandora-kernel.git] / drivers / net / wireless / wl1251 / wl1251.h
1 /*
2  * This file is part of wl1251
3  *
4  * Copyright (c) 1998-2007 Texas Instruments Incorporated
5  * Copyright (C) 2008-2009 Nokia Corporation
6  *
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.
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
23 #ifndef __WL1251_H__
24 #define __WL1251_H__
25
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>
31
32 #define DRIVER_NAME "wl1251"
33 #define DRIVER_PREFIX DRIVER_NAME ": "
34
35 enum {
36         DEBUG_NONE      = 0,
37         DEBUG_IRQ       = BIT(0),
38         DEBUG_SPI       = BIT(1),
39         DEBUG_BOOT      = BIT(2),
40         DEBUG_MAILBOX   = BIT(3),
41         DEBUG_NETLINK   = BIT(4),
42         DEBUG_EVENT     = BIT(5),
43         DEBUG_TX        = BIT(6),
44         DEBUG_RX        = BIT(7),
45         DEBUG_SCAN      = BIT(8),
46         DEBUG_CRYPT     = BIT(9),
47         DEBUG_PSM       = BIT(10),
48         DEBUG_MAC80211  = BIT(11),
49         DEBUG_CMD       = BIT(12),
50         DEBUG_ACX       = BIT(13),
51         DEBUG_ALL       = ~0,
52 };
53
54 #define DEBUG_LEVEL (DEBUG_NONE)
55
56 #define DEBUG_DUMP_LIMIT 1024
57
58 #define wl1251_error(fmt, arg...) \
59         printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
60
61 #define wl1251_warning(fmt, arg...) \
62         printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
63
64 #define wl1251_notice(fmt, arg...) \
65         printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
66
67 #define wl1251_info(fmt, arg...) \
68         printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
69
70 #define wl1251_debug(level, fmt, arg...) \
71         do { \
72                 if (level & DEBUG_LEVEL) \
73                         printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
74         } while (0)
75
76 #define wl1251_dump(level, prefix, buf, len)    \
77         do { \
78                 if (level & DEBUG_LEVEL) \
79                         print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
80                                        DUMP_PREFIX_OFFSET, 16, 1,       \
81                                        buf,                             \
82                                        min_t(size_t, len, DEBUG_DUMP_LIMIT), \
83                                        0);                              \
84         } while (0)
85
86 #define wl1251_dump_ascii(level, prefix, buf, len)      \
87         do { \
88                 if (level & DEBUG_LEVEL) \
89                         print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
90                                        DUMP_PREFIX_OFFSET, 16, 1,       \
91                                        buf,                             \
92                                        min_t(size_t, len, DEBUG_DUMP_LIMIT), \
93                                        true);                           \
94         } while (0)
95
96 #define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN |   \
97                                   CFG_BSSID_FILTER_EN)
98
99 #define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN |  \
100                                   CFG_RX_MGMT_EN |  \
101                                   CFG_RX_DATA_EN |  \
102                                   CFG_RX_CTL_EN |   \
103                                   CFG_RX_BCN_EN |   \
104                                   CFG_RX_AUTH_EN |  \
105                                   CFG_RX_ASSOC_EN)
106
107 #define WL1251_BUSY_WORD_LEN 8
108
109 struct boot_attr {
110         u32 radio_type;
111         u8 mac_clock;
112         u8 arm_clock;
113         int firmware_debug;
114         u32 minor;
115         u32 major;
116         u32 bugfix;
117 };
118
119 enum wl1251_state {
120         WL1251_STATE_OFF,
121         WL1251_STATE_ON,
122         WL1251_STATE_PLT,
123 };
124
125 enum wl1251_partition_type {
126         PART_DOWN,
127         PART_WORK,
128         PART_DRPW,
129
130         PART_TABLE_LEN
131 };
132
133 enum wl1251_station_mode {
134         STATION_ACTIVE_MODE,
135         STATION_POWER_SAVE_MODE,
136         STATION_IDLE,
137 };
138
139 struct wl1251_partition {
140         u32 size;
141         u32 start;
142 };
143
144 struct wl1251_partition_set {
145         struct wl1251_partition mem;
146         struct wl1251_partition reg;
147 };
148
149 struct wl1251;
150
151 struct wl1251_stats {
152         struct acx_statistics *fw_stats;
153         unsigned long fw_stats_update;
154
155         unsigned int retry_count;
156         unsigned int excessive_retries;
157 };
158
159 struct wl1251_debugfs {
160         struct dentry *rootdir;
161         struct dentry *fw_statistics;
162
163         struct dentry *tx_internal_desc_overflow;
164
165         struct dentry *rx_out_of_mem;
166         struct dentry *rx_hdr_overflow;
167         struct dentry *rx_hw_stuck;
168         struct dentry *rx_dropped;
169         struct dentry *rx_fcs_err;
170         struct dentry *rx_xfr_hint_trig;
171         struct dentry *rx_path_reset;
172         struct dentry *rx_reset_counter;
173
174         struct dentry *dma_rx_requested;
175         struct dentry *dma_rx_errors;
176         struct dentry *dma_tx_requested;
177         struct dentry *dma_tx_errors;
178
179         struct dentry *isr_cmd_cmplt;
180         struct dentry *isr_fiqs;
181         struct dentry *isr_rx_headers;
182         struct dentry *isr_rx_mem_overflow;
183         struct dentry *isr_rx_rdys;
184         struct dentry *isr_irqs;
185         struct dentry *isr_tx_procs;
186         struct dentry *isr_decrypt_done;
187         struct dentry *isr_dma0_done;
188         struct dentry *isr_dma1_done;
189         struct dentry *isr_tx_exch_complete;
190         struct dentry *isr_commands;
191         struct dentry *isr_rx_procs;
192         struct dentry *isr_hw_pm_mode_changes;
193         struct dentry *isr_host_acknowledges;
194         struct dentry *isr_pci_pm;
195         struct dentry *isr_wakeups;
196         struct dentry *isr_low_rssi;
197
198         struct dentry *wep_addr_key_count;
199         struct dentry *wep_default_key_count;
200         /* skipping wep.reserved */
201         struct dentry *wep_key_not_found;
202         struct dentry *wep_decrypt_fail;
203         struct dentry *wep_packets;
204         struct dentry *wep_interrupt;
205
206         struct dentry *pwr_ps_enter;
207         struct dentry *pwr_elp_enter;
208         struct dentry *pwr_missing_bcns;
209         struct dentry *pwr_wake_on_host;
210         struct dentry *pwr_wake_on_timer_exp;
211         struct dentry *pwr_tx_with_ps;
212         struct dentry *pwr_tx_without_ps;
213         struct dentry *pwr_rcvd_beacons;
214         struct dentry *pwr_power_save_off;
215         struct dentry *pwr_enable_ps;
216         struct dentry *pwr_disable_ps;
217         struct dentry *pwr_fix_tsf_ps;
218         /* skipping cont_miss_bcns_spread for now */
219         struct dentry *pwr_rcvd_awake_beacons;
220
221         struct dentry *mic_rx_pkts;
222         struct dentry *mic_calc_failure;
223
224         struct dentry *aes_encrypt_fail;
225         struct dentry *aes_decrypt_fail;
226         struct dentry *aes_encrypt_packets;
227         struct dentry *aes_decrypt_packets;
228         struct dentry *aes_encrypt_interrupt;
229         struct dentry *aes_decrypt_interrupt;
230
231         struct dentry *event_heart_beat;
232         struct dentry *event_calibration;
233         struct dentry *event_rx_mismatch;
234         struct dentry *event_rx_mem_empty;
235         struct dentry *event_rx_pool;
236         struct dentry *event_oom_late;
237         struct dentry *event_phy_transmit_error;
238         struct dentry *event_tx_stuck;
239
240         struct dentry *ps_pspoll_timeouts;
241         struct dentry *ps_upsd_timeouts;
242         struct dentry *ps_upsd_max_sptime;
243         struct dentry *ps_upsd_max_apturn;
244         struct dentry *ps_pspoll_max_apturn;
245         struct dentry *ps_pspoll_utilization;
246         struct dentry *ps_upsd_utilization;
247
248         struct dentry *rxpipe_rx_prep_beacon_drop;
249         struct dentry *rxpipe_descr_host_int_trig_rx_data;
250         struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
251         struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
252         struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
253
254         struct dentry *tx_queue_len;
255         struct dentry *tx_queue_status;
256
257         struct dentry *retry_count;
258         struct dentry *excessive_retries;
259
260         struct dentry *dump_nvs;
261         struct dentry *dump_full;
262 };
263
264 struct wl1251_if_operations {
265         void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
266         void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
267         void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
268         void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
269         int  (*power)(struct wl1251 *wl, bool enable);
270         void (*reset)(struct wl1251 *wl);
271         void (*enable_irq)(struct wl1251 *wl);
272         void (*disable_irq)(struct wl1251 *wl);
273 };
274
275 struct wl1251 {
276         struct ieee80211_hw *hw;
277         bool mac80211_registered;
278
279         void *if_priv;
280         const struct wl1251_if_operations *if_ops;
281
282         void (*set_power)(bool enable);
283         int irq;
284         bool use_eeprom;
285         bool dump_eeprom;
286
287         spinlock_t wl_lock;
288
289         enum wl1251_state state;
290         struct mutex mutex;
291
292         int physical_mem_addr;
293         int physical_reg_addr;
294         int virtual_mem_addr;
295         int virtual_reg_addr;
296
297         int cmd_box_addr;
298         int event_box_addr;
299         struct boot_attr boot_attr;
300
301         u8 *fw;
302         size_t fw_len;
303         u8 *nvs;
304         size_t nvs_len;
305
306         u8 bssid[ETH_ALEN];
307         u8 mac_addr[ETH_ALEN];
308         u8 bss_type;
309         u8 listen_int;
310         int channel;
311         bool monitor_present;
312
313         void *target_mem_map;
314         struct acx_data_path_params_resp *data_path;
315
316         /* Number of TX packets transferred to the FW, modulo 16 */
317         u32 data_in_count;
318
319         /* Frames scheduled for transmission, not handled yet */
320         struct sk_buff_head tx_queue;
321         bool tx_queue_stopped;
322
323         struct work_struct tx_work;
324
325         /* Pending TX frames */
326         struct sk_buff *tx_frames[16];
327
328         /*
329          * Index pointing to the next TX complete entry
330          * in the cyclic XT complete array we get from
331          * the FW.
332          */
333         u32 next_tx_complete;
334
335         /* FW Rx counter */
336         u32 rx_counter;
337
338         /* Rx frames handled */
339         u32 rx_handled;
340
341         /* Current double buffer */
342         u32 rx_current_buffer;
343         u32 rx_last_id;
344
345         /* The target interrupt mask */
346         u32 intr_mask;
347         struct work_struct irq_work;
348
349         /* The mbox event mask */
350         u32 event_mask;
351
352         /* Mailbox pointers */
353         u32 mbox_ptr[2];
354
355         /* Are we currently scanning */
356         bool scanning;
357
358         /* Default key (for WEP) */
359         u32 default_key;
360
361         unsigned int tx_mgmt_frm_rate;
362         unsigned int tx_mgmt_frm_mod;
363
364         unsigned int rx_config;
365         unsigned int rx_filter;
366
367         /* is firmware in elp mode */
368         bool elp;
369
370         struct delayed_work elp_work;
371
372         enum wl1251_station_mode station_mode;
373
374         /* PSM mode requested */
375         bool psm_requested;
376
377         u16 beacon_int;
378         u8 dtim_period;
379
380         /* in dBm */
381         int power_level;
382
383         int rssi_thold;
384
385         struct wl1251_stats stats;
386         struct wl1251_debugfs debugfs;
387
388         u32 buffer_32;
389         u32 buffer_cmd;
390         u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
391         struct wl1251_rx_descriptor *rx_descriptor;
392
393         struct ieee80211_vif *vif;
394
395         u32 chip_id;
396         char fw_ver[21];
397
398         /* Most recently reported noise in dBm */
399         s8 noise;
400
401         void *eeprom_dump;
402
403         /* PS hacks.. */
404         unsigned long ps_change_jiffies;
405         unsigned long last_io_jiffies;
406         struct delayed_work ps_work;
407         bool bss_lost;
408         bool ps_transitioning;
409 };
410
411 int wl1251_plt_start(struct wl1251 *wl);
412 int wl1251_plt_stop(struct wl1251 *wl);
413
414 struct ieee80211_hw *wl1251_alloc_hw(void);
415 int wl1251_free_hw(struct wl1251 *wl);
416 int wl1251_init_ieee80211(struct wl1251 *wl);
417 void wl1251_enable_interrupts(struct wl1251 *wl);
418 void wl1251_disable_interrupts(struct wl1251 *wl);
419 irqreturn_t wl1251_irq(int irq, void *cookie);
420
421 #define DEFAULT_HW_GEN_MODULATION_TYPE    CCK_LONG /* Long Preamble */
422 #define DEFAULT_HW_GEN_TX_RATE          RATE_2MBPS
423 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
424
425 #define WL1251_DEFAULT_POWER_LEVEL 20
426
427 #define WL1251_TX_QUEUE_LOW_WATERMARK  10
428 #define WL1251_TX_QUEUE_HIGH_WATERMARK 25
429
430 #define WL1251_DEFAULT_BEACON_INT 100
431 #define WL1251_DEFAULT_DTIM_PERIOD 1
432
433 #define WL1251_DEFAULT_CHANNEL 0
434
435 #define WL1251_DEFAULT_BET_CONSECUTIVE 10
436
437 #define CHIP_ID_1251_PG10                  (0x7010101)
438 #define CHIP_ID_1251_PG11                  (0x7020101)
439 #define CHIP_ID_1251_PG12                  (0x7030101)
440 #define CHIP_ID_1271_PG10                  (0x4030101)
441 #define CHIP_ID_1271_PG20                  (0x4030111)
442
443 #define WL1251_FW_NAME "wl1251-fw.bin"
444 #define WL1251_NVS_NAME "wl1251-nvs.bin"
445
446 #define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
447
448 #define WL1251_PART_DOWN_MEM_START      0x0
449 #define WL1251_PART_DOWN_MEM_SIZE       0x16800
450 #define WL1251_PART_DOWN_REG_START      REGISTERS_BASE
451 #define WL1251_PART_DOWN_REG_SIZE       REGISTERS_DOWN_SIZE
452
453 #define WL1251_PART_WORK_MEM_START      0x28000
454 #define WL1251_PART_WORK_MEM_SIZE       0x14000
455 #define WL1251_PART_WORK_REG_START      REGISTERS_BASE
456 #define WL1251_PART_WORK_REG_SIZE       REGISTERS_WORK_SIZE
457
458 #define WL1251_DEFAULT_LOW_RSSI_WEIGHT          10
459 #define WL1251_DEFAULT_LOW_RSSI_DEPTH           10
460
461 #endif