2 * This file is part of wl1271
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
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>
38 #define DRIVER_NAME "wl1271"
39 #define DRIVER_PREFIX DRIVER_NAME ": "
46 DEBUG_MAILBOX = BIT(3),
47 DEBUG_TESTMODE = BIT(4),
54 DEBUG_MAC80211 = BIT(11),
58 DEBUG_FILTERS = BIT(15),
59 DEBUG_ADHOC = BIT(16),
63 #define DEBUG_LEVEL (DEBUG_NONE)
65 #define DEBUG_DUMP_LIMIT 1024
67 #define wl1271_error(fmt, arg...) \
68 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
70 #define wl1271_warning(fmt, arg...) \
71 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
73 #define wl1271_notice(fmt, arg...) \
74 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
76 #define wl1271_info(fmt, arg...) \
77 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
79 #define wl1271_debug(level, fmt, arg...) \
81 if (level & DEBUG_LEVEL) \
82 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
85 #define wl1271_dump(level, prefix, buf, len) \
87 if (level & DEBUG_LEVEL) \
88 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
89 DUMP_PREFIX_OFFSET, 16, 1, \
91 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
95 #define wl1271_dump_ascii(level, prefix, buf, len) \
97 if (level & DEBUG_LEVEL) \
98 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
99 DUMP_PREFIX_OFFSET, 16, 1, \
101 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
105 #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
106 CFG_BSSID_FILTER_EN | \
109 #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
110 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
111 CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
112 CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
114 #define WL1271_FW_NAME "wl1271-fw.bin"
115 #define WL1271_NVS_NAME "wl1271-nvs.bin"
117 #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
118 #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
120 #define WL1271_CIPHER_SUITE_GEM 0x00147201
122 #define WL1271_BUSY_WORD_CNT 1
123 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
125 #define WL1271_ELP_HW_STATE_ASLEEP 0
126 #define WL1271_ELP_HW_STATE_IRQ 1
128 #define WL1271_DEFAULT_BEACON_INT 100
129 #define WL1271_DEFAULT_DTIM_PERIOD 1
131 #define ACX_TX_DESCRIPTORS 32
133 #define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
141 enum wl1271_partition_type {
149 struct wl1271_partition {
154 struct wl1271_partition_set {
155 struct wl1271_partition mem;
156 struct wl1271_partition reg;
157 struct wl1271_partition mem2;
158 struct wl1271_partition mem3;
163 /* FIXME: I'm not sure about this structure name */
169 struct wl1271_stats {
170 struct acx_statistics *fw_stats;
171 unsigned long fw_stats_update;
173 unsigned int retry_count;
174 unsigned int excessive_retries;
177 #define NUM_TX_QUEUES 4
178 #define NUM_RX_PKT_DESC 8
180 /* FW status registers */
181 struct wl1271_fw_status {
186 u8 tx_results_counter;
187 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
188 __le32 tx_released_blks[NUM_TX_QUEUES];
193 struct wl1271_rx_mem_pool_addr {
199 struct cfg80211_scan_request *req;
203 u8 ssid[IW_ESSID_MAX_SIZE+1];
207 struct wl1271_if_operations {
208 void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
210 void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
212 void (*reset)(struct wl1271 *wl);
213 void (*init)(struct wl1271 *wl);
214 int (*power)(struct wl1271 *wl, bool enable);
215 struct device* (*dev)(struct wl1271 *wl);
216 void (*enable_irq)(struct wl1271 *wl);
217 void (*disable_irq)(struct wl1271 *wl);
221 struct platform_device *plat_dev;
222 struct ieee80211_hw *hw;
223 bool mac80211_registered;
227 struct wl1271_if_operations *if_ops;
229 void (*set_power)(bool enable);
235 enum wl1271_state state;
238 #define WL1271_FLAG_STA_RATES_CHANGED (0)
239 #define WL1271_FLAG_STA_ASSOCIATED (1)
240 #define WL1271_FLAG_JOINED (2)
241 #define WL1271_FLAG_GPIO_POWER (3)
242 #define WL1271_FLAG_TX_QUEUE_STOPPED (4)
243 #define WL1271_FLAG_IN_ELP (5)
244 #define WL1271_FLAG_PSM (6)
245 #define WL1271_FLAG_PSM_REQUESTED (7)
246 #define WL1271_FLAG_IRQ_PENDING (8)
247 #define WL1271_FLAG_IRQ_RUNNING (9)
248 #define WL1271_FLAG_IDLE (10)
249 #define WL1271_FLAG_IDLE_REQUESTED (11)
250 #define WL1271_FLAG_PSPOLL_FAILURE (12)
251 #define WL1271_FLAG_STA_STATE_SENT (13)
252 #define WL1271_FLAG_FW_TX_BUSY (14)
255 struct wl1271_partition_set part;
257 struct wl1271_chip chip;
264 struct wl1271_nvs_file *nvs;
270 u8 mac_addr[ETH_ALEN];
273 u8 ssid[IW_ESSID_MAX_SIZE + 1];
277 struct wl1271_acx_mem_map *target_mem_map;
279 /* Accounting for allocated / available TX blocks on HW */
280 u32 tx_blocks_freed[NUM_TX_QUEUES];
281 u32 tx_blocks_available;
282 u32 tx_results_count;
284 /* Transmitted TX packets counter for chipset interface */
285 u32 tx_packets_count;
287 /* Time-offset between host and chipset clocks */
290 /* Session counter for the chipset */
293 /* Frames scheduled for transmission, not handled yet */
294 struct sk_buff_head tx_queue;
296 struct work_struct tx_work;
298 /* Pending TX frames */
299 unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)];
300 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
303 /* Security sequence number counters */
304 u8 tx_security_last_seq;
310 /* Rx memory pool address */
311 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
313 /* Intermediate buffer, used for packet aggregation */
316 /* The target interrupt mask */
317 struct work_struct irq_work;
319 /* Hardware recovery work */
320 struct work_struct recovery_work;
322 /* The mbox event mask */
325 /* Mailbox pointers */
328 /* Are we currently scanning */
329 struct wl1271_scan scan;
330 struct delayed_work scan_complete_work;
332 /* probe-req template for the current AP */
333 struct sk_buff *probereq;
335 /* Our association ID */
339 * currently configured rate set:
340 * bits 0-15 - 802.11abg rates
341 * bits 16-23 - 802.11n MCS index mask
342 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
349 /* The current band */
350 enum ieee80211_band band;
352 /* Beaconing interval (needed for ad-hoc) */
355 /* Default key (for WEP) */
358 unsigned int filters;
359 unsigned int rx_config;
360 unsigned int rx_filter;
362 struct completion *elp_compl;
363 struct delayed_work elp_work;
364 struct delayed_work pspoll_work;
366 /* counter for ps-poll delivery failures */
367 int ps_poll_failures;
369 /* retry counter for PSM entries */
378 struct wl1271_stats stats;
379 struct dentry *rootdir;
383 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
385 struct wl1271_fw_status *fw_status;
386 struct wl1271_tx_hw_res_if *tx_res_if;
388 struct ieee80211_vif *vif;
390 /* Current chipset configuration */
391 struct conf_drv_settings conf;
397 struct list_head list;
399 /* Most recently reported noise in dBm */
403 int wl1271_plt_start(struct wl1271 *wl);
404 int wl1271_plt_stop(struct wl1271 *wl);
406 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
408 #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
410 #define WL1271_DEFAULT_POWER_LEVEL 0
412 #define WL1271_TX_QUEUE_LOW_WATERMARK 10
413 #define WL1271_TX_QUEUE_HIGH_WATERMARK 25
415 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
416 on in case is has been shut down shortly before */
417 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
418 #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
420 /* Macros to handle wl1271.sta_rate_set */
421 #define HW_BG_RATES_MASK 0xffff
422 #define HW_HT_RATES_OFFSET 16