blob: b2bc7b59d6451dd6189c7d599c277e56e8a650b6 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
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
38enum {
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 | \
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300100 CFG_BSSID_FILTER_EN | \
101 CFG_MC_FILTER_EN)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300102
103#define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
104 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
105 CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
106 CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
107
Juuso Oikarinend94cd292009-10-08 21:56:25 +0300108#define WL1271_DEFAULT_BASIC_RATE_SET (ACX_RATE_MASK_ALL)
109
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300110#define WL1271_FW_NAME "wl1271-fw.bin"
111#define WL1271_NVS_NAME "wl1271-nvs.bin"
112
Juuso Oikarinen545f1da2009-10-08 21:56:23 +0300113/*
114 * FIXME: for the wl1271, a busy word count of 1 here will result in a more
115 * optimal SPI interface. There is some SPI bug however, causing RXS time outs
116 * with this mode occasionally on boot, so lets have two for now.
117 */
118#define WL1271_BUSY_WORD_CNT 2
119#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300120
121#define WL1271_ELP_HW_STATE_ASLEEP 0
122#define WL1271_ELP_HW_STATE_IRQ 1
123
Juuso Oikarinend94cd292009-10-08 21:56:25 +0300124#define WL1271_DEFAULT_BEACON_INT 100
125#define WL1271_DEFAULT_DTIM_PERIOD 1
126
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300127#define ACX_TX_DESCRIPTORS 32
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +0300128
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300129enum wl1271_state {
130 WL1271_STATE_OFF,
131 WL1271_STATE_ON,
132 WL1271_STATE_PLT,
133};
134
135enum wl1271_partition_type {
136 PART_DOWN,
137 PART_WORK,
138 PART_DRPW,
139
140 PART_TABLE_LEN
141};
142
143struct wl1271_partition {
144 u32 size;
145 u32 start;
146};
147
148struct wl1271_partition_set {
149 struct wl1271_partition mem;
150 struct wl1271_partition reg;
Juuso Oikarinen451de972009-10-12 15:08:46 +0300151 struct wl1271_partition mem2;
152 struct wl1271_partition mem3;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300153};
154
155struct wl1271;
156
157/* FIXME: I'm not sure about this structure name */
158struct wl1271_chip {
159 u32 id;
160 char fw_ver[21];
161};
162
163struct wl1271_stats {
164 struct acx_statistics *fw_stats;
165 unsigned long fw_stats_update;
166
167 unsigned int retry_count;
168 unsigned int excessive_retries;
169};
170
171struct wl1271_debugfs {
172 struct dentry *rootdir;
173 struct dentry *fw_statistics;
174
175 struct dentry *tx_internal_desc_overflow;
176
177 struct dentry *rx_out_of_mem;
178 struct dentry *rx_hdr_overflow;
179 struct dentry *rx_hw_stuck;
180 struct dentry *rx_dropped;
181 struct dentry *rx_fcs_err;
182 struct dentry *rx_xfr_hint_trig;
183 struct dentry *rx_path_reset;
184 struct dentry *rx_reset_counter;
185
186 struct dentry *dma_rx_requested;
187 struct dentry *dma_rx_errors;
188 struct dentry *dma_tx_requested;
189 struct dentry *dma_tx_errors;
190
191 struct dentry *isr_cmd_cmplt;
192 struct dentry *isr_fiqs;
193 struct dentry *isr_rx_headers;
194 struct dentry *isr_rx_mem_overflow;
195 struct dentry *isr_rx_rdys;
196 struct dentry *isr_irqs;
197 struct dentry *isr_tx_procs;
198 struct dentry *isr_decrypt_done;
199 struct dentry *isr_dma0_done;
200 struct dentry *isr_dma1_done;
201 struct dentry *isr_tx_exch_complete;
202 struct dentry *isr_commands;
203 struct dentry *isr_rx_procs;
204 struct dentry *isr_hw_pm_mode_changes;
205 struct dentry *isr_host_acknowledges;
206 struct dentry *isr_pci_pm;
207 struct dentry *isr_wakeups;
208 struct dentry *isr_low_rssi;
209
210 struct dentry *wep_addr_key_count;
211 struct dentry *wep_default_key_count;
212 /* skipping wep.reserved */
213 struct dentry *wep_key_not_found;
214 struct dentry *wep_decrypt_fail;
215 struct dentry *wep_packets;
216 struct dentry *wep_interrupt;
217
218 struct dentry *pwr_ps_enter;
219 struct dentry *pwr_elp_enter;
220 struct dentry *pwr_missing_bcns;
221 struct dentry *pwr_wake_on_host;
222 struct dentry *pwr_wake_on_timer_exp;
223 struct dentry *pwr_tx_with_ps;
224 struct dentry *pwr_tx_without_ps;
225 struct dentry *pwr_rcvd_beacons;
226 struct dentry *pwr_power_save_off;
227 struct dentry *pwr_enable_ps;
228 struct dentry *pwr_disable_ps;
229 struct dentry *pwr_fix_tsf_ps;
230 /* skipping cont_miss_bcns_spread for now */
231 struct dentry *pwr_rcvd_awake_beacons;
232
233 struct dentry *mic_rx_pkts;
234 struct dentry *mic_calc_failure;
235
236 struct dentry *aes_encrypt_fail;
237 struct dentry *aes_decrypt_fail;
238 struct dentry *aes_encrypt_packets;
239 struct dentry *aes_decrypt_packets;
240 struct dentry *aes_encrypt_interrupt;
241 struct dentry *aes_decrypt_interrupt;
242
243 struct dentry *event_heart_beat;
244 struct dentry *event_calibration;
245 struct dentry *event_rx_mismatch;
246 struct dentry *event_rx_mem_empty;
247 struct dentry *event_rx_pool;
248 struct dentry *event_oom_late;
249 struct dentry *event_phy_transmit_error;
250 struct dentry *event_tx_stuck;
251
252 struct dentry *ps_pspoll_timeouts;
253 struct dentry *ps_upsd_timeouts;
254 struct dentry *ps_upsd_max_sptime;
255 struct dentry *ps_upsd_max_apturn;
256 struct dentry *ps_pspoll_max_apturn;
257 struct dentry *ps_pspoll_utilization;
258 struct dentry *ps_upsd_utilization;
259
260 struct dentry *rxpipe_rx_prep_beacon_drop;
261 struct dentry *rxpipe_descr_host_int_trig_rx_data;
262 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
263 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
264 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
265
266 struct dentry *tx_queue_len;
267
268 struct dentry *retry_count;
269 struct dentry *excessive_retries;
270};
271
272#define NUM_TX_QUEUES 4
273#define NUM_RX_PKT_DESC 8
274
275/* FW status registers */
276struct wl1271_fw_status {
277 u32 intr;
278 u8 fw_rx_counter;
279 u8 drv_rx_counter;
280 u8 reserved;
281 u8 tx_results_counter;
282 u32 rx_pkt_descs[NUM_RX_PKT_DESC];
283 u32 tx_released_blks[NUM_TX_QUEUES];
284 u32 fw_localtime;
285 u32 padding[2];
286} __attribute__ ((packed));
287
288struct wl1271_rx_mem_pool_addr {
289 u32 addr;
290 u32 addr_extra;
291};
292
293struct wl1271 {
294 struct ieee80211_hw *hw;
295 bool mac80211_registered;
296
297 struct spi_device *spi;
298
299 void (*set_power)(bool enable);
300 int irq;
301
302 spinlock_t wl_lock;
303
304 enum wl1271_state state;
305 struct mutex mutex;
306
Juuso Oikarinen451de972009-10-12 15:08:46 +0300307 struct wl1271_partition_set part;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300308
309 struct wl1271_chip chip;
310
311 int cmd_box_addr;
312 int event_box_addr;
313
314 u8 *fw;
315 size_t fw_len;
316 u8 *nvs;
317 size_t nvs_len;
318
319 u8 bssid[ETH_ALEN];
320 u8 mac_addr[ETH_ALEN];
321 u8 bss_type;
322 u8 ssid[IW_ESSID_MAX_SIZE + 1];
323 u8 ssid_len;
324 u8 listen_int;
325 int channel;
326
327 struct wl1271_acx_mem_map *target_mem_map;
328
329 /* Accounting for allocated / available TX blocks on HW */
330 u32 tx_blocks_freed[NUM_TX_QUEUES];
331 u32 tx_blocks_available;
332 u8 tx_results_count;
333
334 /* Transmitted TX packets counter for chipset interface */
335 int tx_packets_count;
336
337 /* Time-offset between host and chipset clocks */
338 int time_offset;
339
340 /* Session counter for the chipset */
341 int session_counter;
342
343 /* Frames scheduled for transmission, not handled yet */
344 struct sk_buff_head tx_queue;
345 bool tx_queue_stopped;
346
347 struct work_struct tx_work;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300348
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300349 struct work_struct filter_work;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300350 struct wl1271_filter_params *filter_params;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300351
352 /* Pending TX frames */
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +0300353 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300354
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300355 /* Security sequence number counters */
356 u8 tx_security_last_seq;
357 u16 tx_security_seq_16;
358 u32 tx_security_seq_32;
359
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300360 /* FW Rx counter */
361 u32 rx_counter;
362
363 /* Rx memory pool address */
364 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
365
366 /* The target interrupt mask */
367 struct work_struct irq_work;
368
369 /* The mbox event mask */
370 u32 event_mask;
371
372 /* Mailbox pointers */
373 u32 mbox_ptr[2];
374
375 /* Are we currently scanning */
376 bool scanning;
377
378 /* Our association ID */
379 u16 aid;
380
Juuso Oikarinend94cd292009-10-08 21:56:25 +0300381 /* Beacon parameters */
382 u16 beacon_int;
383 u8 dtim_period;
384
385 /* currently configured rate set */
386 u32 basic_rate_set;
387
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +0300388 /* The current band */
389 enum ieee80211_band band;
390
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300391 /* Default key (for WEP) */
392 u32 default_key;
393
394 unsigned int rx_config;
395 unsigned int rx_filter;
396
397 /* is firmware in elp mode */
398 bool elp;
399
400 struct completion *elp_compl;
Juuso Oikarinen37b70a82009-10-08 21:56:21 +0300401 struct delayed_work elp_work;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300402
403 /* we can be in psm, but not in elp, we have to differentiate */
404 bool psm;
405
406 /* PSM mode requested */
407 bool psm_requested;
408
409 /* in dBm */
410 int power_level;
411
412 struct wl1271_stats stats;
413 struct wl1271_debugfs debugfs;
414
415 u32 buffer_32;
416 u32 buffer_cmd;
Juuso Oikarinen545f1da2009-10-08 21:56:23 +0300417 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300418 struct wl1271_rx_descriptor *rx_descriptor;
419
420 struct wl1271_fw_status *fw_status;
421 struct wl1271_tx_hw_res_if *tx_res_if;
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300422
423 struct ieee80211_vif *vif;
Luciano Coelhod6e19d132009-10-12 15:08:43 +0300424
425 /* Used for a workaround to send disconnect before rejoining */
426 bool joined;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300427};
428
429int wl1271_plt_start(struct wl1271 *wl);
430int wl1271_plt_stop(struct wl1271 *wl);
431
432#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
433
434#define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
435
436#define WL1271_DEFAULT_POWER_LEVEL 0
437
438#define WL1271_TX_QUEUE_MAX_LENGTH 20
439
440/* WL1271 needs a 200ms sleep after power on */
441#define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
442
443#endif