wl1271: Update join usage
[safe/jmp/linux-2.6] / drivers / net / wireless / wl12xx / wl1271.h
1 /*
2  * This file is part of wl1271
3  *
4  * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5  * Copyright (C) 2008-2009 Nokia Corporation
6  *
7  * Contact: Luciano Coelho <luciano.coelho@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 __WL1271_H__
26 #define __WL1271_H__
27
28 #include <linux/mutex.h>
29 #include <linux/completion.h>
30 #include <linux/spinlock.h>
31 #include <linux/list.h>
32 #include <linux/bitops.h>
33 #include <net/mac80211.h>
34
35 #define DRIVER_NAME "wl1271"
36 #define DRIVER_PREFIX DRIVER_NAME ": "
37
38 enum {
39         DEBUG_NONE      = 0,
40         DEBUG_IRQ       = BIT(0),
41         DEBUG_SPI       = BIT(1),
42         DEBUG_BOOT      = BIT(2),
43         DEBUG_MAILBOX   = BIT(3),
44         DEBUG_NETLINK   = BIT(4),
45         DEBUG_EVENT     = BIT(5),
46         DEBUG_TX        = BIT(6),
47         DEBUG_RX        = BIT(7),
48         DEBUG_SCAN      = BIT(8),
49         DEBUG_CRYPT     = BIT(9),
50         DEBUG_PSM       = BIT(10),
51         DEBUG_MAC80211  = BIT(11),
52         DEBUG_CMD       = BIT(12),
53         DEBUG_ACX       = BIT(13),
54         DEBUG_ALL       = ~0,
55 };
56
57 #define DEBUG_LEVEL (DEBUG_NONE)
58
59 #define DEBUG_DUMP_LIMIT 1024
60
61 #define wl1271_error(fmt, arg...) \
62         printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
63
64 #define wl1271_warning(fmt, arg...) \
65         printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
66
67 #define wl1271_notice(fmt, arg...) \
68         printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
69
70 #define wl1271_info(fmt, arg...) \
71         printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
72
73 #define wl1271_debug(level, fmt, arg...) \
74         do { \
75                 if (level & DEBUG_LEVEL) \
76                         printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
77         } while (0)
78
79 #define wl1271_dump(level, prefix, buf, len)    \
80         do { \
81                 if (level & DEBUG_LEVEL) \
82                         print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
83                                        DUMP_PREFIX_OFFSET, 16, 1,       \
84                                        buf,                             \
85                                        min_t(size_t, len, DEBUG_DUMP_LIMIT), \
86                                        0);                              \
87         } while (0)
88
89 #define wl1271_dump_ascii(level, prefix, buf, len)      \
90         do { \
91                 if (level & DEBUG_LEVEL) \
92                         print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
93                                        DUMP_PREFIX_OFFSET, 16, 1,       \
94                                        buf,                             \
95                                        min_t(size_t, len, DEBUG_DUMP_LIMIT), \
96                                        true);                           \
97         } while (0)
98
99 #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN |   \
100                                   CFG_BSSID_FILTER_EN)
101
102 #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN |  \
103                                   CFG_RX_MGMT_EN | CFG_RX_DATA_EN |   \
104                                   CFG_RX_CTL_EN | CFG_RX_BCN_EN |     \
105                                   CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
106
107 #define WL1271_DEFAULT_BASIC_RATE_SET (ACX_RATE_MASK_ALL)
108
109 #define WL1271_FW_NAME "wl1271-fw.bin"
110 #define WL1271_NVS_NAME "wl1271-nvs.bin"
111
112 /*
113  * FIXME: for the wl1271, a busy word count of 1 here will result in a more
114  * optimal SPI interface. There is some SPI bug however, causing RXS time outs
115  * with this mode occasionally on boot, so lets have two for now.
116  */
117 #define WL1271_BUSY_WORD_CNT 2
118 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
119
120 #define WL1271_ELP_HW_STATE_ASLEEP 0
121 #define WL1271_ELP_HW_STATE_IRQ    1
122
123 #define WL1271_DEFAULT_BEACON_INT  100
124 #define WL1271_DEFAULT_DTIM_PERIOD 1
125
126 enum wl1271_state {
127         WL1271_STATE_OFF,
128         WL1271_STATE_ON,
129         WL1271_STATE_PLT,
130 };
131
132 enum wl1271_partition_type {
133         PART_DOWN,
134         PART_WORK,
135         PART_DRPW,
136
137         PART_TABLE_LEN
138 };
139
140 struct wl1271_partition {
141         u32 size;
142         u32 start;
143 };
144
145 struct wl1271_partition_set {
146         struct wl1271_partition mem;
147         struct wl1271_partition reg;
148 };
149
150 struct wl1271;
151
152 /* FIXME: I'm not sure about this structure name */
153 struct wl1271_chip {
154         u32 id;
155         char fw_ver[21];
156 };
157
158 struct wl1271_stats {
159         struct acx_statistics *fw_stats;
160         unsigned long fw_stats_update;
161
162         unsigned int retry_count;
163         unsigned int excessive_retries;
164 };
165
166 struct wl1271_debugfs {
167         struct dentry *rootdir;
168         struct dentry *fw_statistics;
169
170         struct dentry *tx_internal_desc_overflow;
171
172         struct dentry *rx_out_of_mem;
173         struct dentry *rx_hdr_overflow;
174         struct dentry *rx_hw_stuck;
175         struct dentry *rx_dropped;
176         struct dentry *rx_fcs_err;
177         struct dentry *rx_xfr_hint_trig;
178         struct dentry *rx_path_reset;
179         struct dentry *rx_reset_counter;
180
181         struct dentry *dma_rx_requested;
182         struct dentry *dma_rx_errors;
183         struct dentry *dma_tx_requested;
184         struct dentry *dma_tx_errors;
185
186         struct dentry *isr_cmd_cmplt;
187         struct dentry *isr_fiqs;
188         struct dentry *isr_rx_headers;
189         struct dentry *isr_rx_mem_overflow;
190         struct dentry *isr_rx_rdys;
191         struct dentry *isr_irqs;
192         struct dentry *isr_tx_procs;
193         struct dentry *isr_decrypt_done;
194         struct dentry *isr_dma0_done;
195         struct dentry *isr_dma1_done;
196         struct dentry *isr_tx_exch_complete;
197         struct dentry *isr_commands;
198         struct dentry *isr_rx_procs;
199         struct dentry *isr_hw_pm_mode_changes;
200         struct dentry *isr_host_acknowledges;
201         struct dentry *isr_pci_pm;
202         struct dentry *isr_wakeups;
203         struct dentry *isr_low_rssi;
204
205         struct dentry *wep_addr_key_count;
206         struct dentry *wep_default_key_count;
207         /* skipping wep.reserved */
208         struct dentry *wep_key_not_found;
209         struct dentry *wep_decrypt_fail;
210         struct dentry *wep_packets;
211         struct dentry *wep_interrupt;
212
213         struct dentry *pwr_ps_enter;
214         struct dentry *pwr_elp_enter;
215         struct dentry *pwr_missing_bcns;
216         struct dentry *pwr_wake_on_host;
217         struct dentry *pwr_wake_on_timer_exp;
218         struct dentry *pwr_tx_with_ps;
219         struct dentry *pwr_tx_without_ps;
220         struct dentry *pwr_rcvd_beacons;
221         struct dentry *pwr_power_save_off;
222         struct dentry *pwr_enable_ps;
223         struct dentry *pwr_disable_ps;
224         struct dentry *pwr_fix_tsf_ps;
225         /* skipping cont_miss_bcns_spread for now */
226         struct dentry *pwr_rcvd_awake_beacons;
227
228         struct dentry *mic_rx_pkts;
229         struct dentry *mic_calc_failure;
230
231         struct dentry *aes_encrypt_fail;
232         struct dentry *aes_decrypt_fail;
233         struct dentry *aes_encrypt_packets;
234         struct dentry *aes_decrypt_packets;
235         struct dentry *aes_encrypt_interrupt;
236         struct dentry *aes_decrypt_interrupt;
237
238         struct dentry *event_heart_beat;
239         struct dentry *event_calibration;
240         struct dentry *event_rx_mismatch;
241         struct dentry *event_rx_mem_empty;
242         struct dentry *event_rx_pool;
243         struct dentry *event_oom_late;
244         struct dentry *event_phy_transmit_error;
245         struct dentry *event_tx_stuck;
246
247         struct dentry *ps_pspoll_timeouts;
248         struct dentry *ps_upsd_timeouts;
249         struct dentry *ps_upsd_max_sptime;
250         struct dentry *ps_upsd_max_apturn;
251         struct dentry *ps_pspoll_max_apturn;
252         struct dentry *ps_pspoll_utilization;
253         struct dentry *ps_upsd_utilization;
254
255         struct dentry *rxpipe_rx_prep_beacon_drop;
256         struct dentry *rxpipe_descr_host_int_trig_rx_data;
257         struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
258         struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
259         struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
260
261         struct dentry *tx_queue_len;
262
263         struct dentry *retry_count;
264         struct dentry *excessive_retries;
265 };
266
267 #define NUM_TX_QUEUES              4
268 #define NUM_RX_PKT_DESC            8
269
270 /* FW status registers */
271 struct wl1271_fw_status {
272         u32 intr;
273         u8  fw_rx_counter;
274         u8  drv_rx_counter;
275         u8  reserved;
276         u8  tx_results_counter;
277         u32 rx_pkt_descs[NUM_RX_PKT_DESC];
278         u32 tx_released_blks[NUM_TX_QUEUES];
279         u32 fw_localtime;
280         u32 padding[2];
281 } __attribute__ ((packed));
282
283 struct wl1271_rx_mem_pool_addr {
284         u32 addr;
285         u32 addr_extra;
286 };
287
288 struct wl1271 {
289         struct ieee80211_hw *hw;
290         bool mac80211_registered;
291
292         struct spi_device *spi;
293
294         void (*set_power)(bool enable);
295         int irq;
296
297         spinlock_t wl_lock;
298
299         enum wl1271_state state;
300         struct mutex mutex;
301
302         int physical_mem_addr;
303         int physical_reg_addr;
304         int virtual_mem_addr;
305         int virtual_reg_addr;
306
307         struct wl1271_chip chip;
308
309         int cmd_box_addr;
310         int event_box_addr;
311
312         u8 *fw;
313         size_t fw_len;
314         u8 *nvs;
315         size_t nvs_len;
316
317         u8 bssid[ETH_ALEN];
318         u8 mac_addr[ETH_ALEN];
319         u8 bss_type;
320         u8 ssid[IW_ESSID_MAX_SIZE + 1];
321         u8 ssid_len;
322         u8 listen_int;
323         int channel;
324
325         struct wl1271_acx_mem_map *target_mem_map;
326
327         /* Accounting for allocated / available TX blocks on HW */
328         u32 tx_blocks_freed[NUM_TX_QUEUES];
329         u32 tx_blocks_available;
330         u8 tx_results_count;
331
332         /* Transmitted TX packets counter for chipset interface */
333         int tx_packets_count;
334
335         /* Time-offset between host and chipset clocks */
336         int time_offset;
337
338         /* Session counter for the chipset */
339         int session_counter;
340
341         /* Frames scheduled for transmission, not handled yet */
342         struct sk_buff_head tx_queue;
343         bool tx_queue_stopped;
344
345         struct work_struct tx_work;
346         struct work_struct filter_work;
347
348         /* Pending TX frames */
349         struct sk_buff *tx_frames[16];
350
351         /* Security sequence number counters */
352         u8 tx_security_last_seq;
353         u16 tx_security_seq_16;
354         u32 tx_security_seq_32;
355
356         /* FW Rx counter */
357         u32 rx_counter;
358
359         /* Rx memory pool address */
360         struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
361
362         /* The target interrupt mask */
363         struct work_struct irq_work;
364
365         /* The mbox event mask */
366         u32 event_mask;
367
368         /* Mailbox pointers */
369         u32 mbox_ptr[2];
370
371         /* Are we currently scanning */
372         bool scanning;
373
374         /* Our association ID */
375         u16 aid;
376
377         /* Beacon parameters */
378         u16 beacon_int;
379         u8 dtim_period;
380
381         /* currently configured rate set */
382         u32 basic_rate_set;
383
384         /* The current band */
385         enum ieee80211_band band;
386
387         /* Default key (for WEP) */
388         u32 default_key;
389
390         unsigned int rx_config;
391         unsigned int rx_filter;
392
393         /* is firmware in elp mode */
394         bool elp;
395
396         struct completion *elp_compl;
397         struct delayed_work elp_work;
398
399         /* we can be in psm, but not in elp, we have to differentiate */
400         bool psm;
401
402         /* PSM mode requested */
403         bool psm_requested;
404
405         /* in dBm */
406         int power_level;
407
408         struct wl1271_stats stats;
409         struct wl1271_debugfs debugfs;
410
411         u32 buffer_32;
412         u32 buffer_cmd;
413         u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
414         struct wl1271_rx_descriptor *rx_descriptor;
415
416         struct wl1271_fw_status *fw_status;
417         struct wl1271_tx_hw_res_if *tx_res_if;
418 };
419
420 int wl1271_plt_start(struct wl1271 *wl);
421 int wl1271_plt_stop(struct wl1271 *wl);
422
423 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
424
425 #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
426
427 #define WL1271_DEFAULT_POWER_LEVEL 0
428
429 #define WL1271_TX_QUEUE_MAX_LENGTH 20
430
431 /* WL1271 needs a 200ms sleep after power on */
432 #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
433
434 #endif