wl12xx: change blocksize alignment quirk to negative
[linux-2.6/libata-dev.git] / drivers / net / wireless / wl12xx / wl12xx.h
blobe58e801f7aea9f90c0bc419caf93a4abd930bc4c
1 /*
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
21 * 02110-1301 USA
25 #ifndef __WL12XX_H__
26 #define __WL12XX_H__
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>
35 #include "conf.h"
36 #include "ini.h"
39 * FW versions support BA 11n
40 * versions marks x.x.x.50-60.x
42 #define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50
43 #define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60
45 #define WL127X_FW_NAME "ti-connectivity/wl127x-fw-3.bin"
46 #define WL128X_FW_NAME "ti-connectivity/wl128x-fw-3.bin"
49 * wl127x and wl128x are using the same NVS file name. However, the
50 * ini parameters between them are different. The driver validates
51 * the correct NVS size in wl1271_boot_upload_nvs().
53 #define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
55 #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
56 #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
57 #define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
59 #define WL1271_CIPHER_SUITE_GEM 0x00147201
61 #define WL1271_BUSY_WORD_CNT 1
62 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
64 #define WL1271_ELP_HW_STATE_ASLEEP 0
65 #define WL1271_ELP_HW_STATE_IRQ 1
67 #define WL1271_DEFAULT_BEACON_INT 100
68 #define WL1271_DEFAULT_DTIM_PERIOD 1
70 #define WL12XX_MAX_ROLES 4
71 #define WL12XX_MAX_LINKS 12
72 #define WL12XX_INVALID_ROLE_ID 0xff
73 #define WL12XX_INVALID_LINK_ID 0xff
75 #define WL12XX_MAX_RATE_POLICIES 16
77 /* Defined by FW as 0. Will not be freed or allocated. */
78 #define WL12XX_SYSTEM_HLID 0
81 * When in AP-mode, we allow (at least) this number of packets
82 * to be transmitted to FW for a STA in PS-mode. Only when packets are
83 * present in the FW buffers it will wake the sleeping STA. We want to put
84 * enough packets for the driver to transmit all of its buffered data before
85 * the STA goes to sleep again. But we don't want to take too much memory
86 * as it might hurt the throughput of active STAs.
88 #define WL1271_PS_STA_MAX_PACKETS 2
90 #define WL1271_AP_BSS_INDEX 0
91 #define WL1271_AP_DEF_BEACON_EXP 20
93 #define ACX_TX_DESCRIPTORS 16
95 #define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
97 enum wl1271_state {
98 WL1271_STATE_OFF,
99 WL1271_STATE_ON,
100 WL1271_STATE_PLT,
103 enum wl1271_partition_type {
104 PART_DOWN,
105 PART_WORK,
106 PART_DRPW,
108 PART_TABLE_LEN
111 struct wl1271_partition {
112 u32 size;
113 u32 start;
116 struct wl1271_partition_set {
117 struct wl1271_partition mem;
118 struct wl1271_partition reg;
119 struct wl1271_partition mem2;
120 struct wl1271_partition mem3;
123 struct wl1271;
125 enum {
126 FW_VER_CHIP,
127 FW_VER_IF_TYPE,
128 FW_VER_MAJOR,
129 FW_VER_SUBTYPE,
130 FW_VER_MINOR,
132 NUM_FW_VER
135 #define FW_VER_CHIP_WL127X 6
136 #define FW_VER_CHIP_WL128X 7
138 #define FW_VER_IF_TYPE_STA 1
139 #define FW_VER_IF_TYPE_AP 2
141 #define FW_VER_MINOR_1_SPARE_STA_MIN 58
142 #define FW_VER_MINOR_1_SPARE_AP_MIN 47
144 #define FW_VER_MINOR_FWLOG_STA_MIN 70
146 struct wl1271_chip {
147 u32 id;
148 char fw_ver_str[ETHTOOL_BUSINFO_LEN];
149 unsigned int fw_ver[NUM_FW_VER];
152 struct wl1271_stats {
153 struct acx_statistics *fw_stats;
154 unsigned long fw_stats_update;
156 unsigned int retry_count;
157 unsigned int excessive_retries;
160 #define NUM_TX_QUEUES 4
161 #define NUM_RX_PKT_DESC 8
163 #define AP_MAX_STATIONS 8
165 /* FW status registers */
166 struct wl12xx_fw_status {
167 __le32 intr;
168 u8 fw_rx_counter;
169 u8 drv_rx_counter;
170 u8 reserved;
171 u8 tx_results_counter;
172 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
173 __le32 fw_localtime;
176 * A bitmap (where each bit represents a single HLID)
177 * to indicate if the station is in PS mode.
179 __le32 link_ps_bitmap;
182 * A bitmap (where each bit represents a single HLID) to indicate
183 * if the station is in Fast mode
185 __le32 link_fast_bitmap;
187 /* Cumulative counter of total released mem blocks since FW-reset */
188 __le32 total_released_blks;
190 /* Size (in Memory Blocks) of TX pool */
191 __le32 tx_total;
193 /* Cumulative counter of released packets per AC */
194 u8 tx_released_pkts[NUM_TX_QUEUES];
196 /* Cumulative counter of freed packets per HLID */
197 u8 tx_lnk_free_pkts[WL12XX_MAX_LINKS];
199 /* Cumulative counter of released Voice memory blocks */
200 u8 tx_voice_released_blks;
201 u8 padding_1[3];
202 __le32 log_start_addr;
203 } __packed;
205 struct wl1271_rx_mem_pool_addr {
206 u32 addr;
207 u32 addr_extra;
210 #define WL1271_MAX_CHANNELS 64
211 struct wl1271_scan {
212 struct cfg80211_scan_request *req;
213 unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
214 bool failed;
215 u8 state;
216 u8 ssid[IEEE80211_MAX_SSID_LEN+1];
217 size_t ssid_len;
220 struct wl1271_if_operations {
221 void (*read)(struct device *child, int addr, void *buf, size_t len,
222 bool fixed);
223 void (*write)(struct device *child, int addr, void *buf, size_t len,
224 bool fixed);
225 void (*reset)(struct device *child);
226 void (*init)(struct device *child);
227 int (*power)(struct device *child, bool enable);
228 void (*set_block_size) (struct device *child, unsigned int blksz);
231 #define MAX_NUM_KEYS 14
232 #define MAX_KEY_SIZE 32
234 struct wl1271_ap_key {
235 u8 id;
236 u8 key_type;
237 u8 key_size;
238 u8 key[MAX_KEY_SIZE];
239 u8 hlid;
240 u32 tx_seq_32;
241 u16 tx_seq_16;
244 enum wl12xx_flags {
245 WL1271_FLAG_GPIO_POWER,
246 WL1271_FLAG_TX_QUEUE_STOPPED,
247 WL1271_FLAG_TX_PENDING,
248 WL1271_FLAG_IN_ELP,
249 WL1271_FLAG_ELP_REQUESTED,
250 WL1271_FLAG_IRQ_RUNNING,
251 WL1271_FLAG_IDLE,
252 WL1271_FLAG_FW_TX_BUSY,
253 WL1271_FLAG_DUMMY_PACKET_PENDING,
254 WL1271_FLAG_SUSPENDED,
255 WL1271_FLAG_PENDING_WORK,
256 WL1271_FLAG_SOFT_GEMINI,
257 WL1271_FLAG_RECOVERY_IN_PROGRESS,
260 enum wl12xx_vif_flags {
261 WLVIF_FLAG_INITIALIZED,
262 WLVIF_FLAG_STA_ASSOCIATED,
263 WLVIF_FLAG_IBSS_JOINED,
264 WLVIF_FLAG_AP_STARTED,
265 WLVIF_FLAG_PSM,
266 WLVIF_FLAG_PSM_REQUESTED,
267 WLVIF_FLAG_STA_STATE_SENT,
268 WLVIF_FLAG_RX_STREAMING_STARTED,
269 WLVIF_FLAG_PSPOLL_FAILURE,
270 WLVIF_FLAG_CS_PROGRESS,
273 struct wl1271_link {
274 /* AP-mode - TX queue per AC in link */
275 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
277 /* accounting for allocated / freed packets in FW */
278 u8 allocated_pkts;
279 u8 prev_freed_pkts;
281 u8 addr[ETH_ALEN];
283 /* bitmap of TIDs where RX BA sessions are active for this link */
284 u8 ba_bitmap;
287 struct wl1271 {
288 struct ieee80211_hw *hw;
289 bool mac80211_registered;
291 struct device *dev;
293 void *if_priv;
295 struct wl1271_if_operations *if_ops;
297 void (*set_power)(bool enable);
298 int irq;
299 int ref_clock;
301 spinlock_t wl_lock;
303 enum wl1271_state state;
304 struct mutex mutex;
306 unsigned long flags;
308 struct wl1271_partition_set part;
310 struct wl1271_chip chip;
312 int cmd_box_addr;
313 int event_box_addr;
315 u8 *fw;
316 size_t fw_len;
317 void *nvs;
318 size_t nvs_len;
320 s8 hw_pg_ver;
322 u8 mac_addr[ETH_ALEN];
323 int channel;
324 u8 system_hlid;
326 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
327 unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
328 unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
329 unsigned long rate_policies_map[
330 BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
332 struct list_head wlvif_list;
334 u8 sta_count;
335 u8 ap_count;
337 struct wl1271_acx_mem_map *target_mem_map;
339 /* Accounting for allocated / available TX blocks on HW */
340 u32 tx_blocks_freed;
341 u32 tx_blocks_available;
342 u32 tx_allocated_blocks;
343 u32 tx_results_count;
345 /* amount of spare TX blocks to use */
346 u32 tx_spare_blocks;
348 /* Accounting for allocated / available Tx packets in HW */
349 u32 tx_pkts_freed[NUM_TX_QUEUES];
350 u32 tx_allocated_pkts[NUM_TX_QUEUES];
352 /* Transmitted TX packets counter for chipset interface */
353 u32 tx_packets_count;
355 /* Time-offset between host and chipset clocks */
356 s64 time_offset;
358 /* Frames scheduled for transmission, not handled yet */
359 int tx_queue_count[NUM_TX_QUEUES];
360 long stopped_queues_map;
362 /* Frames received, not handled yet by mac80211 */
363 struct sk_buff_head deferred_rx_queue;
365 /* Frames sent, not returned yet to mac80211 */
366 struct sk_buff_head deferred_tx_queue;
368 struct work_struct tx_work;
369 struct workqueue_struct *freezable_wq;
371 /* Pending TX frames */
372 unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)];
373 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
374 int tx_frames_cnt;
376 /* FW Rx counter */
377 u32 rx_counter;
379 /* Rx memory pool address */
380 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
382 /* Intermediate buffer, used for packet aggregation */
383 u8 *aggr_buf;
385 /* Reusable dummy packet template */
386 struct sk_buff *dummy_packet;
388 /* Network stack work */
389 struct work_struct netstack_work;
391 /* FW log buffer */
392 u8 *fwlog;
394 /* Number of valid bytes in the FW log buffer */
395 ssize_t fwlog_size;
397 /* Sysfs FW log entry readers wait queue */
398 wait_queue_head_t fwlog_waitq;
400 /* Hardware recovery work */
401 struct work_struct recovery_work;
403 /* The mbox event mask */
404 u32 event_mask;
406 /* Mailbox pointers */
407 u32 mbox_ptr[2];
409 /* Are we currently scanning */
410 struct ieee80211_vif *scan_vif;
411 struct wl1271_scan scan;
412 struct delayed_work scan_complete_work;
414 bool sched_scanning;
416 /* The current band */
417 enum ieee80211_band band;
419 struct completion *elp_compl;
420 struct delayed_work elp_work;
422 /* in dBm */
423 int power_level;
425 struct wl1271_stats stats;
427 __le32 buffer_32;
428 u32 buffer_cmd;
429 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
431 struct wl12xx_fw_status *fw_status;
432 struct wl1271_tx_hw_res_if *tx_res_if;
434 struct ieee80211_vif *vif;
436 /* Current chipset configuration */
437 struct conf_drv_settings conf;
439 bool sg_enabled;
441 bool enable_11a;
443 struct list_head list;
445 /* Most recently reported noise in dBm */
446 s8 noise;
448 /* bands supported by this instance of wl12xx */
449 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
451 int tcxo_clock;
454 * wowlan trigger was configured during suspend.
455 * (currently, only "ANY" trigger is supported)
457 bool wow_enabled;
458 bool irq_wake_enabled;
461 * AP-mode - links indexed by HLID. The global and broadcast links
462 * are always active.
464 struct wl1271_link links[WL12XX_MAX_LINKS];
466 /* AP-mode - a bitmap of links currently in PS mode according to FW */
467 u32 ap_fw_ps_map;
469 /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
470 unsigned long ap_ps_map;
472 /* Quirks of specific hardware revisions */
473 unsigned int quirks;
475 /* Platform limitations */
476 unsigned int platform_quirks;
478 /* number of currently active RX BA sessions */
479 int ba_rx_session_count;
481 /* AP-mode - number of currently connected stations */
482 int active_sta_count;
484 /* last wlvif we transmitted from */
485 struct wl12xx_vif *last_wlvif;
488 struct wl1271_station {
489 u8 hlid;
492 struct wl12xx_vif {
493 struct wl1271 *wl;
494 struct list_head list;
495 unsigned long flags;
496 u8 bss_type;
497 u8 p2p; /* we are using p2p role */
498 u8 role_id;
500 /* sta/ibss specific */
501 u8 dev_role_id;
502 u8 dev_hlid;
504 union {
505 struct {
506 u8 hlid;
507 u8 ba_rx_bitmap;
509 u8 basic_rate_idx;
510 u8 ap_rate_idx;
511 u8 p2p_rate_idx;
512 } sta;
513 struct {
514 u8 global_hlid;
515 u8 bcast_hlid;
517 /* HLIDs bitmap of associated stations */
518 unsigned long sta_hlid_map[BITS_TO_LONGS(
519 WL12XX_MAX_LINKS)];
521 /* recoreded keys - set here before AP startup */
522 struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
524 u8 mgmt_rate_idx;
525 u8 bcast_rate_idx;
526 u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
527 } ap;
530 /* the hlid of the last transmitted skb */
531 int last_tx_hlid;
533 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
535 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
536 u8 ssid_len;
538 /* The current band */
539 enum ieee80211_band band;
540 int channel;
542 u32 bitrate_masks[IEEE80211_NUM_BANDS];
543 u32 basic_rate_set;
546 * currently configured rate set:
547 * bits 0-15 - 802.11abg rates
548 * bits 16-23 - 802.11n MCS index mask
549 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
551 u32 basic_rate;
552 u32 rate_set;
554 /* probe-req template for the current AP */
555 struct sk_buff *probereq;
557 /* Beaconing interval (needed for ad-hoc) */
558 u32 beacon_int;
560 /* Default key (for WEP) */
561 u32 default_key;
563 /* Our association ID */
564 u16 aid;
566 /* Session counter for the chipset */
567 int session_counter;
569 struct completion *ps_compl;
570 struct delayed_work pspoll_work;
572 /* counter for ps-poll delivery failures */
573 int ps_poll_failures;
575 /* retry counter for PSM entries */
576 u8 psm_entry_retry;
578 /* in dBm */
579 int power_level;
581 int rssi_thold;
582 int last_rssi_event;
584 /* RX BA constraint value */
585 bool ba_support;
586 bool ba_allowed;
588 /* Rx Streaming */
589 struct work_struct rx_streaming_enable_work;
590 struct work_struct rx_streaming_disable_work;
591 struct timer_list rx_streaming_timer;
594 * This struct must be last!
595 * data that has to be saved acrossed reconfigs (e.g. recovery)
596 * should be declared in this struct.
598 struct {
599 u8 persistent[0];
601 * Security sequence number
602 * bits 0-15: lower 16 bits part of sequence number
603 * bits 16-47: higher 32 bits part of sequence number
604 * bits 48-63: not in use
606 u64 tx_security_seq;
608 /* 8 bits of the last sequence number in use */
609 u8 tx_security_last_seq_lsb;
613 static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
615 return (struct wl12xx_vif *)vif->drv_priv;
618 static inline
619 struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
621 return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
624 #define wl12xx_for_each_wlvif(wl, wlvif) \
625 list_for_each_entry(wlvif, &wl->wlvif_list, list)
627 #define wl12xx_for_each_wlvif_continue(wl, wlvif) \
628 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
630 #define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type) \
631 wl12xx_for_each_wlvif(wl, wlvif) \
632 if (wlvif->bss_type == _bss_type)
634 #define wl12xx_for_each_wlvif_sta(wl, wlvif) \
635 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
637 #define wl12xx_for_each_wlvif_ap(wl, wlvif) \
638 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
640 int wl1271_plt_start(struct wl1271 *wl);
641 int wl1271_plt_stop(struct wl1271 *wl);
642 int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
643 void wl12xx_queue_recovery_work(struct wl1271 *wl);
644 size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
646 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
648 #define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
649 #define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
651 #define WL1271_DEFAULT_POWER_LEVEL 0
653 #define WL1271_TX_QUEUE_LOW_WATERMARK 32
654 #define WL1271_TX_QUEUE_HIGH_WATERMARK 256
656 #define WL1271_DEFERRED_QUEUE_LIMIT 64
658 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
659 on in case is has been shut down shortly before */
660 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
661 #define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
663 /* Macros to handle wl1271.sta_rate_set */
664 #define HW_BG_RATES_MASK 0xffff
665 #define HW_HT_RATES_OFFSET 16
667 /* Quirks */
669 /* Each RX/TX transaction requires an end-of-transaction transfer */
670 #define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0)
672 /* wl127x and SPI don't support SDIO block size alignment */
673 #define WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT BIT(2)
675 /* Older firmwares did not implement the FW logger over bus feature */
676 #define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4)
678 #define WL12XX_HW_BLOCK_SIZE 256
680 #endif