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