Merge branch 'stable-3.2' into pandora-3.2
[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_MC_FILTER_EN |    \
98                                   CFG_BSSID_FILTER_EN)
99
100 #define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN |  \
101                                   CFG_RX_MGMT_EN |  \
102                                   CFG_RX_DATA_EN |  \
103                                   CFG_RX_CTL_EN |   \
104                                   CFG_RX_BCN_EN |   \
105                                   CFG_RX_AUTH_EN |  \
106                                   CFG_RX_ASSOC_EN)
107
108 #define WL1251_BUSY_WORD_LEN 8
109
110 struct boot_attr {
111         u32 radio_type;
112         u8 mac_clock;
113         u8 arm_clock;
114         int firmware_debug;
115         u32 minor;
116         u32 major;
117         u32 bugfix;
118 };
119
120 enum wl1251_state {
121         WL1251_STATE_OFF,
122         WL1251_STATE_ON,
123         WL1251_STATE_PLT,
124 };
125
126 enum wl1251_partition_type {
127         PART_DOWN,
128         PART_WORK,
129         PART_DRPW,
130
131         PART_TABLE_LEN
132 };
133
134 enum wl1251_station_mode {
135         STATION_ACTIVE_MODE,
136         STATION_POWER_SAVE_MODE,
137         STATION_IDLE,
138 };
139
140 struct wl1251_partition {
141         u32 size;
142         u32 start;
143 };
144
145 struct wl1251_partition_set {
146         struct wl1251_partition mem;
147         struct wl1251_partition reg;
148 };
149
150 struct wl1251;
151
152 struct wl1251_stats {
153         struct acx_statistics *fw_stats;
154         unsigned long fw_stats_update;
155
156         unsigned int retry_count;
157         unsigned int excessive_retries;
158 };
159
160 struct wl1251_debugfs {
161         struct dentry *rootdir;
162         struct dentry *fw_statistics;
163
164         struct dentry *tx_internal_desc_overflow;
165
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;
174
175         struct dentry *dma_rx_requested;
176         struct dentry *dma_rx_errors;
177         struct dentry *dma_tx_requested;
178         struct dentry *dma_tx_errors;
179
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;
198
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;
206
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;
221
222         struct dentry *mic_rx_pkts;
223         struct dentry *mic_calc_failure;
224
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;
231
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;
240
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;
248
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;
254
255         struct dentry *tx_queue_len;
256         struct dentry *tx_queue_status;
257
258         struct dentry *retry_count;
259         struct dentry *excessive_retries;
260
261         struct dentry *dump_nvs;
262         struct dentry *dump_full;
263 };
264
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);
274 };
275
276 struct wl1251 {
277         struct ieee80211_hw *hw;
278         bool mac80211_registered;
279
280         void *if_priv;
281         const struct wl1251_if_operations *if_ops;
282
283         void (*set_power)(bool enable);
284         int irq;
285         bool use_eeprom;
286         bool dump_eeprom;
287         bool long_doze_mode;
288         bool long_doze_mode_set;
289
290         spinlock_t wl_lock;
291
292         enum wl1251_state state;
293         struct mutex mutex;
294
295         int physical_mem_addr;
296         int physical_reg_addr;
297         int virtual_mem_addr;
298         int virtual_reg_addr;
299
300         int cmd_box_addr;
301         int event_box_addr;
302         struct boot_attr boot_attr;
303
304         u8 *fw;
305         size_t fw_len;
306         u8 *nvs;
307         size_t nvs_len;
308
309         u8 bssid[ETH_ALEN];
310         u8 mac_addr[ETH_ALEN];
311         u8 bss_type;
312         u8 listen_int;
313         int channel;
314         bool monitor_present;
315         bool joined;
316
317         void *target_mem_map;
318         struct acx_data_path_params_resp *data_path;
319
320         /* Number of TX packets transferred to the FW, modulo 16 */
321         u32 data_in_count;
322
323         /* Frames scheduled for transmission, not handled yet */
324         struct sk_buff_head tx_queue;
325         bool tx_queue_stopped;
326
327         struct work_struct tx_work;
328
329         /* Pending TX frames */
330         struct sk_buff *tx_frames[16];
331
332         /*
333          * Index pointing to the next TX complete entry
334          * in the cyclic XT complete array we get from
335          * the FW.
336          */
337         u32 next_tx_complete;
338
339         /* FW Rx counter */
340         u32 rx_counter;
341
342         /* Rx frames handled */
343         u32 rx_handled;
344
345         /* Current double buffer */
346         u32 rx_current_buffer;
347         u32 rx_last_id;
348
349         /* The target interrupt mask */
350         u32 intr_mask;
351         struct work_struct irq_work;
352
353         /* The mbox event mask */
354         u32 event_mask;
355
356         /* Mailbox pointers */
357         u32 mbox_ptr[2];
358
359         /* Are we currently scanning */
360         bool scanning;
361
362         /* Default key (for WEP) */
363         u32 default_key;
364
365         unsigned int tx_mgmt_frm_rate;
366         unsigned int tx_mgmt_frm_mod;
367
368         unsigned int rx_config;
369         unsigned int rx_filter;
370
371         /* is firmware in elp mode */
372         bool elp;
373
374         struct delayed_work elp_work;
375
376         enum wl1251_station_mode station_mode;
377
378         /* PSM mode requested */
379         bool psm_requested;
380
381         u16 beacon_int;
382         u8 dtim_period;
383
384         /* in dBm */
385         int power_level;
386
387         int rssi_thold;
388
389         struct wl1251_stats stats;
390         struct wl1251_debugfs debugfs;
391
392         u32 buffer_32;
393         u32 buffer_cmd;
394         u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
395         struct wl1251_rx_descriptor *rx_descriptor;
396
397         struct ieee80211_vif *vif;
398
399         u32 chip_id;
400         char fw_ver[21];
401
402         /* Most recently reported noise in dBm */
403         s8 noise;
404
405         void *eeprom_dump;
406
407         /* PS hacks.. */
408         unsigned long ps_change_jiffies;
409         /* when we had PS "unfriendly" event like sync loss */
410         unsigned long last_no_ps_jiffies[2];
411         struct delayed_work ps_work;
412         bool bss_lost;
413         bool ps_transitioning;
414
415         /* rate accounting */
416         u32 ps_rate_threshold;
417         unsigned long rate_jiffies;
418         u32 rate_counter;
419         u32 rate;
420 };
421
422 int wl1251_plt_start(struct wl1251 *wl);
423 int wl1251_plt_stop(struct wl1251 *wl);
424
425 struct ieee80211_hw *wl1251_alloc_hw(void);
426 int wl1251_free_hw(struct wl1251 *wl);
427 int wl1251_init_ieee80211(struct wl1251 *wl);
428 void wl1251_enable_interrupts(struct wl1251 *wl);
429 void wl1251_disable_interrupts(struct wl1251 *wl);
430 irqreturn_t wl1251_irq(int irq, void *cookie);
431
432 static inline void wl1251_no_ps_event(struct wl1251 *wl)
433 {
434         wl->last_no_ps_jiffies[0] = wl->last_no_ps_jiffies[1];
435         wl->last_no_ps_jiffies[1] = jiffies;
436 }
437
438 static inline void wl1251_update_rate(struct wl1251 *wl, u32 length)
439 {
440         bool in_psm, rate_above_eq;
441         unsigned long diff;
442
443         diff = jiffies - wl->rate_jiffies;
444         if (diff >= msecs_to_jiffies(2000)) {
445                 wl->rate_jiffies = jiffies;
446                 wl->rate = wl->rate_counter = 0;
447         }
448         else if (diff >= msecs_to_jiffies(1000)) {
449                 wl->rate_jiffies += msecs_to_jiffies(1000);
450                 wl->rate = wl->rate_counter;
451                 wl->rate_counter = 0;
452         }
453         wl->rate_counter += length;
454
455         in_psm = wl->station_mode == STATION_POWER_SAVE_MODE;
456         rate_above_eq = wl->rate >= wl->ps_rate_threshold;
457         if (in_psm == rate_above_eq)
458                 ieee80211_queue_delayed_work(wl->hw, &wl->ps_work, 0);
459 }
460
461 #define DEFAULT_HW_GEN_MODULATION_TYPE    CCK_LONG /* Long Preamble */
462 #define DEFAULT_HW_GEN_TX_RATE          RATE_2MBPS
463 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
464
465 #define WL1251_DEFAULT_POWER_LEVEL 20
466
467 #define WL1251_TX_QUEUE_LOW_WATERMARK  10
468 #define WL1251_TX_QUEUE_HIGH_WATERMARK 25
469
470 #define WL1251_DEFAULT_BEACON_INT 100
471 #define WL1251_DEFAULT_DTIM_PERIOD 1
472
473 #define WL1251_DEFAULT_CHANNEL 0
474
475 #define WL1251_DEFAULT_BET_CONSECUTIVE 10
476
477 #define CHIP_ID_1251_PG10                  (0x7010101)
478 #define CHIP_ID_1251_PG11                  (0x7020101)
479 #define CHIP_ID_1251_PG12                  (0x7030101)
480 #define CHIP_ID_1271_PG10                  (0x4030101)
481 #define CHIP_ID_1271_PG20                  (0x4030111)
482
483 #define WL1251_FW_NAME "wl1251-fw.bin"
484 #define WL1251_NVS_NAME "wl1251-nvs.bin"
485
486 #define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
487
488 #define WL1251_PART_DOWN_MEM_START      0x0
489 #define WL1251_PART_DOWN_MEM_SIZE       0x16800
490 #define WL1251_PART_DOWN_REG_START      REGISTERS_BASE
491 #define WL1251_PART_DOWN_REG_SIZE       REGISTERS_DOWN_SIZE
492
493 #define WL1251_PART_WORK_MEM_START      0x28000
494 #define WL1251_PART_WORK_MEM_SIZE       0x14000
495 #define WL1251_PART_WORK_REG_START      REGISTERS_BASE
496 #define WL1251_PART_WORK_REG_SIZE       REGISTERS_WORK_SIZE
497
498 #define WL1251_DEFAULT_LOW_RSSI_WEIGHT          10
499 #define WL1251_DEFAULT_LOW_RSSI_DEPTH           10
500
501 #endif