blob: 671dc5af2e689330cdbafd3fe86cf757360e56c0 [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 | \
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_FW_NAME "wl1271-fw.bin"
108#define WL1271_NVS_NAME "wl1271-nvs.bin"
109
Juuso Oikarinen545f1da2009-10-08 21:56:23 +0300110/*
111 * FIXME: for the wl1271, a busy word count of 1 here will result in a more
112 * optimal SPI interface. There is some SPI bug however, causing RXS time outs
113 * with this mode occasionally on boot, so lets have two for now.
114 */
115#define WL1271_BUSY_WORD_CNT 2
116#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300117
118#define WL1271_ELP_HW_STATE_ASLEEP 0
119#define WL1271_ELP_HW_STATE_IRQ 1
120
121enum wl1271_state {
122 WL1271_STATE_OFF,
123 WL1271_STATE_ON,
124 WL1271_STATE_PLT,
125};
126
127enum wl1271_partition_type {
128 PART_DOWN,
129 PART_WORK,
130 PART_DRPW,
131
132 PART_TABLE_LEN
133};
134
135struct wl1271_partition {
136 u32 size;
137 u32 start;
138};
139
140struct wl1271_partition_set {
141 struct wl1271_partition mem;
142 struct wl1271_partition reg;
143};
144
145struct wl1271;
146
147/* FIXME: I'm not sure about this structure name */
148struct wl1271_chip {
149 u32 id;
150 char fw_ver[21];
151};
152
153struct wl1271_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
161struct wl1271_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
258 struct dentry *retry_count;
259 struct dentry *excessive_retries;
260};
261
262#define NUM_TX_QUEUES 4
263#define NUM_RX_PKT_DESC 8
264
265/* FW status registers */
266struct wl1271_fw_status {
267 u32 intr;
268 u8 fw_rx_counter;
269 u8 drv_rx_counter;
270 u8 reserved;
271 u8 tx_results_counter;
272 u32 rx_pkt_descs[NUM_RX_PKT_DESC];
273 u32 tx_released_blks[NUM_TX_QUEUES];
274 u32 fw_localtime;
275 u32 padding[2];
276} __attribute__ ((packed));
277
278struct wl1271_rx_mem_pool_addr {
279 u32 addr;
280 u32 addr_extra;
281};
282
283struct wl1271 {
284 struct ieee80211_hw *hw;
285 bool mac80211_registered;
286
287 struct spi_device *spi;
288
289 void (*set_power)(bool enable);
290 int irq;
291
292 spinlock_t wl_lock;
293
294 enum wl1271_state state;
295 struct mutex mutex;
296
297 int physical_mem_addr;
298 int physical_reg_addr;
299 int virtual_mem_addr;
300 int virtual_reg_addr;
301
302 struct wl1271_chip chip;
303
304 int cmd_box_addr;
305 int event_box_addr;
306
307 u8 *fw;
308 size_t fw_len;
309 u8 *nvs;
310 size_t nvs_len;
311
312 u8 bssid[ETH_ALEN];
313 u8 mac_addr[ETH_ALEN];
314 u8 bss_type;
315 u8 ssid[IW_ESSID_MAX_SIZE + 1];
316 u8 ssid_len;
317 u8 listen_int;
318 int channel;
319
320 struct wl1271_acx_mem_map *target_mem_map;
321
322 /* Accounting for allocated / available TX blocks on HW */
323 u32 tx_blocks_freed[NUM_TX_QUEUES];
324 u32 tx_blocks_available;
325 u8 tx_results_count;
326
327 /* Transmitted TX packets counter for chipset interface */
328 int tx_packets_count;
329
330 /* Time-offset between host and chipset clocks */
331 int time_offset;
332
333 /* Session counter for the chipset */
334 int session_counter;
335
336 /* Frames scheduled for transmission, not handled yet */
337 struct sk_buff_head tx_queue;
338 bool tx_queue_stopped;
339
340 struct work_struct tx_work;
341 struct work_struct filter_work;
342
343 /* Pending TX frames */
344 struct sk_buff *tx_frames[16];
345
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300346 /* Security sequence number counters */
347 u8 tx_security_last_seq;
348 u16 tx_security_seq_16;
349 u32 tx_security_seq_32;
350
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300351 /* FW Rx counter */
352 u32 rx_counter;
353
354 /* Rx memory pool address */
355 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
356
357 /* The target interrupt mask */
358 struct work_struct irq_work;
359
360 /* The mbox event mask */
361 u32 event_mask;
362
363 /* Mailbox pointers */
364 u32 mbox_ptr[2];
365
366 /* Are we currently scanning */
367 bool scanning;
368
369 /* Our association ID */
370 u16 aid;
371
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +0300372 /* The current band */
373 enum ieee80211_band band;
374
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300375 /* Default key (for WEP) */
376 u32 default_key;
377
378 unsigned int rx_config;
379 unsigned int rx_filter;
380
381 /* is firmware in elp mode */
382 bool elp;
383
384 struct completion *elp_compl;
Juuso Oikarinen37b70a82009-10-08 21:56:21 +0300385 struct delayed_work elp_work;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300386
387 /* we can be in psm, but not in elp, we have to differentiate */
388 bool psm;
389
390 /* PSM mode requested */
391 bool psm_requested;
392
393 /* in dBm */
394 int power_level;
395
396 struct wl1271_stats stats;
397 struct wl1271_debugfs debugfs;
398
399 u32 buffer_32;
400 u32 buffer_cmd;
Juuso Oikarinen545f1da2009-10-08 21:56:23 +0300401 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300402 struct wl1271_rx_descriptor *rx_descriptor;
403
404 struct wl1271_fw_status *fw_status;
405 struct wl1271_tx_hw_res_if *tx_res_if;
406};
407
408int wl1271_plt_start(struct wl1271 *wl);
409int wl1271_plt_stop(struct wl1271 *wl);
410
411#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
412
413#define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
414
415#define WL1271_DEFAULT_POWER_LEVEL 0
416
417#define WL1271_TX_QUEUE_MAX_LENGTH 20
418
419/* WL1271 needs a 200ms sleep after power on */
420#define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
421
422#endif