wl12xx: increase scan timeout to 30s
[linux-2.6-block.git] / drivers / net / wireless / wl12xx / wl12xx.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 __WL12XX_H__
26 #define __WL12XX_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 #include "conf.h"
36 #include "ini.h"
37 #include "event.h"
38
39 #define WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin"
40 #define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin"
41
42 #define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin"
43 #define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin"
44
45 #define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin"
46 #define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin"
47
48 /*
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().
52  */
53 #define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
54
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
58
59 #define WL1271_CIPHER_SUITE_GEM 0x00147201
60
61 #define WL1271_BUSY_WORD_CNT 1
62 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
63
64 #define WL1271_ELP_HW_STATE_ASLEEP 0
65 #define WL1271_ELP_HW_STATE_IRQ    1
66
67 #define WL1271_DEFAULT_BEACON_INT  100
68 #define WL1271_DEFAULT_DTIM_PERIOD 1
69
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
74
75 #define WL12XX_MAX_RATE_POLICIES 16
76
77 /* Defined by FW as 0. Will not be freed or allocated. */
78 #define WL12XX_SYSTEM_HLID         0
79
80 /*
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.
87  */
88 #define WL1271_PS_STA_MAX_PACKETS  2
89
90 #define WL1271_AP_BSS_INDEX        0
91 #define WL1271_AP_DEF_BEACON_EXP   20
92
93 #define ACX_TX_DESCRIPTORS         16
94
95 #define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
96
97 enum wl1271_state {
98         WL1271_STATE_OFF,
99         WL1271_STATE_ON,
100 };
101
102 enum wl12xx_fw_type {
103         WL12XX_FW_TYPE_NONE,
104         WL12XX_FW_TYPE_NORMAL,
105         WL12XX_FW_TYPE_MULTI,
106         WL12XX_FW_TYPE_PLT,
107 };
108
109 enum wl1271_partition_type {
110         PART_DOWN,
111         PART_WORK,
112         PART_DRPW,
113
114         PART_TABLE_LEN
115 };
116
117 struct wl1271_partition {
118         u32 size;
119         u32 start;
120 };
121
122 struct wl1271_partition_set {
123         struct wl1271_partition mem;
124         struct wl1271_partition reg;
125         struct wl1271_partition mem2;
126         struct wl1271_partition mem3;
127 };
128
129 struct wl1271;
130
131 enum {
132         FW_VER_CHIP,
133         FW_VER_IF_TYPE,
134         FW_VER_MAJOR,
135         FW_VER_SUBTYPE,
136         FW_VER_MINOR,
137
138         NUM_FW_VER
139 };
140
141 #define FW_VER_CHIP_WL127X 6
142 #define FW_VER_CHIP_WL128X 7
143
144 #define FW_VER_IF_TYPE_STA 1
145 #define FW_VER_IF_TYPE_AP  2
146
147 #define FW_VER_MINOR_1_SPARE_STA_MIN 58
148 #define FW_VER_MINOR_1_SPARE_AP_MIN  47
149
150 #define FW_VER_MINOR_FWLOG_STA_MIN 70
151
152 struct wl1271_chip {
153         u32 id;
154         char fw_ver_str[ETHTOOL_BUSINFO_LEN];
155         unsigned int fw_ver[NUM_FW_VER];
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 #define NUM_TX_QUEUES              4
167 #define NUM_RX_PKT_DESC            8
168
169 #define AP_MAX_STATIONS            8
170
171 /* FW status registers */
172 struct wl12xx_fw_status {
173         __le32 intr;
174         u8  fw_rx_counter;
175         u8  drv_rx_counter;
176         u8  reserved;
177         u8  tx_results_counter;
178         __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
179         __le32 fw_localtime;
180
181         /*
182          * A bitmap (where each bit represents a single HLID)
183          * to indicate if the station is in PS mode.
184          */
185         __le32 link_ps_bitmap;
186
187         /*
188          * A bitmap (where each bit represents a single HLID) to indicate
189          * if the station is in Fast mode
190          */
191         __le32 link_fast_bitmap;
192
193         /* Cumulative counter of total released mem blocks since FW-reset */
194         __le32 total_released_blks;
195
196         /* Size (in Memory Blocks) of TX pool */
197         __le32 tx_total;
198
199         /* Cumulative counter of released packets per AC */
200         u8 tx_released_pkts[NUM_TX_QUEUES];
201
202         /* Cumulative counter of freed packets per HLID */
203         u8 tx_lnk_free_pkts[WL12XX_MAX_LINKS];
204
205         /* Cumulative counter of released Voice memory blocks */
206         u8 tx_voice_released_blks;
207         u8 padding_1[3];
208         __le32 log_start_addr;
209 } __packed;
210
211 struct wl1271_rx_mem_pool_addr {
212         u32 addr;
213         u32 addr_extra;
214 };
215
216 #define WL1271_MAX_CHANNELS 64
217 struct wl1271_scan {
218         struct cfg80211_scan_request *req;
219         unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
220         bool failed;
221         u8 state;
222         u8 ssid[IEEE80211_MAX_SSID_LEN+1];
223         size_t ssid_len;
224 };
225
226 struct wl1271_if_operations {
227         void (*read)(struct device *child, int addr, void *buf, size_t len,
228                      bool fixed);
229         void (*write)(struct device *child, int addr, void *buf, size_t len,
230                      bool fixed);
231         void (*reset)(struct device *child);
232         void (*init)(struct device *child);
233         int (*power)(struct device *child, bool enable);
234         void (*set_block_size) (struct device *child, unsigned int blksz);
235 };
236
237 #define MAX_NUM_KEYS 14
238 #define MAX_KEY_SIZE 32
239
240 struct wl1271_ap_key {
241         u8 id;
242         u8 key_type;
243         u8 key_size;
244         u8 key[MAX_KEY_SIZE];
245         u8 hlid;
246         u32 tx_seq_32;
247         u16 tx_seq_16;
248 };
249
250 enum wl12xx_flags {
251         WL1271_FLAG_GPIO_POWER,
252         WL1271_FLAG_TX_QUEUE_STOPPED,
253         WL1271_FLAG_TX_PENDING,
254         WL1271_FLAG_IN_ELP,
255         WL1271_FLAG_ELP_REQUESTED,
256         WL1271_FLAG_IRQ_RUNNING,
257         WL1271_FLAG_FW_TX_BUSY,
258         WL1271_FLAG_DUMMY_PACKET_PENDING,
259         WL1271_FLAG_SUSPENDED,
260         WL1271_FLAG_PENDING_WORK,
261         WL1271_FLAG_SOFT_GEMINI,
262         WL1271_FLAG_RECOVERY_IN_PROGRESS,
263         WL1271_FLAG_VIF_CHANGE_IN_PROGRESS,
264         WL1271_FLAG_INTENDED_FW_RECOVERY,
265 };
266
267 enum wl12xx_vif_flags {
268         WLVIF_FLAG_INITIALIZED,
269         WLVIF_FLAG_STA_ASSOCIATED,
270         WLVIF_FLAG_STA_AUTHORIZED,
271         WLVIF_FLAG_IBSS_JOINED,
272         WLVIF_FLAG_AP_STARTED,
273         WLVIF_FLAG_IN_PS,
274         WLVIF_FLAG_STA_STATE_SENT,
275         WLVIF_FLAG_RX_STREAMING_STARTED,
276         WLVIF_FLAG_PSPOLL_FAILURE,
277         WLVIF_FLAG_CS_PROGRESS,
278         WLVIF_FLAG_AP_PROBE_RESP_SET,
279         WLVIF_FLAG_IN_USE,
280 };
281
282 struct wl1271_link {
283         /* AP-mode - TX queue per AC in link */
284         struct sk_buff_head tx_queue[NUM_TX_QUEUES];
285
286         /* accounting for allocated / freed packets in FW */
287         u8 allocated_pkts;
288         u8 prev_freed_pkts;
289
290         u8 addr[ETH_ALEN];
291
292         /* bitmap of TIDs where RX BA sessions are active for this link */
293         u8 ba_bitmap;
294 };
295
296 struct wl1271 {
297         struct ieee80211_hw *hw;
298         bool mac80211_registered;
299
300         struct device *dev;
301
302         void *if_priv;
303
304         struct wl1271_if_operations *if_ops;
305
306         void (*set_power)(bool enable);
307         int irq;
308         int ref_clock;
309
310         spinlock_t wl_lock;
311
312         enum wl1271_state state;
313         enum wl12xx_fw_type fw_type;
314         bool plt;
315         u8 last_vif_count;
316         struct mutex mutex;
317
318         unsigned long flags;
319
320         struct wl1271_partition_set part;
321
322         struct wl1271_chip chip;
323
324         int cmd_box_addr;
325         int event_box_addr;
326
327         u8 *fw;
328         size_t fw_len;
329         void *nvs;
330         size_t nvs_len;
331
332         s8 hw_pg_ver;
333
334         /* address read from the fuse ROM */
335         u32 fuse_oui_addr;
336         u32 fuse_nic_addr;
337
338         /* we have up to 2 MAC addresses */
339         struct mac_address addresses[2];
340         int channel;
341         u8 system_hlid;
342
343         unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
344         unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
345         unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
346         unsigned long rate_policies_map[
347                         BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
348
349         struct list_head wlvif_list;
350
351         u8 sta_count;
352         u8 ap_count;
353
354         struct wl1271_acx_mem_map *target_mem_map;
355
356         /* Accounting for allocated / available TX blocks on HW */
357         u32 tx_blocks_freed;
358         u32 tx_blocks_available;
359         u32 tx_allocated_blocks;
360         u32 tx_results_count;
361
362         /* amount of spare TX blocks to use */
363         u32 tx_spare_blocks;
364
365         /* Accounting for allocated / available Tx packets in HW */
366         u32 tx_pkts_freed[NUM_TX_QUEUES];
367         u32 tx_allocated_pkts[NUM_TX_QUEUES];
368
369         /* Transmitted TX packets counter for chipset interface */
370         u32 tx_packets_count;
371
372         /* Time-offset between host and chipset clocks */
373         s64 time_offset;
374
375         /* Frames scheduled for transmission, not handled yet */
376         int tx_queue_count[NUM_TX_QUEUES];
377         long stopped_queues_map;
378
379         /* Frames received, not handled yet by mac80211 */
380         struct sk_buff_head deferred_rx_queue;
381
382         /* Frames sent, not returned yet to mac80211 */
383         struct sk_buff_head deferred_tx_queue;
384
385         struct work_struct tx_work;
386         struct workqueue_struct *freezable_wq;
387
388         /* Pending TX frames */
389         unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)];
390         struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
391         int tx_frames_cnt;
392
393         /* FW Rx counter */
394         u32 rx_counter;
395
396         /* Rx memory pool address */
397         struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
398
399         /* Intermediate buffer, used for packet aggregation */
400         u8 *aggr_buf;
401
402         /* Reusable dummy packet template */
403         struct sk_buff *dummy_packet;
404
405         /* Network stack work  */
406         struct work_struct netstack_work;
407
408         /* FW log buffer */
409         u8 *fwlog;
410
411         /* Number of valid bytes in the FW log buffer */
412         ssize_t fwlog_size;
413
414         /* Sysfs FW log entry readers wait queue */
415         wait_queue_head_t fwlog_waitq;
416
417         /* Hardware recovery work */
418         struct work_struct recovery_work;
419
420         struct event_mailbox *mbox;
421
422         /* The mbox event mask */
423         u32 event_mask;
424
425         /* Mailbox pointers */
426         u32 mbox_ptr[2];
427
428         /* Are we currently scanning */
429         struct ieee80211_vif *scan_vif;
430         struct wl1271_scan scan;
431         struct delayed_work scan_complete_work;
432
433         bool sched_scanning;
434
435         /* The current band */
436         enum ieee80211_band band;
437
438         struct completion *elp_compl;
439         struct delayed_work elp_work;
440
441         /* in dBm */
442         int power_level;
443
444         struct wl1271_stats stats;
445
446         __le32 buffer_32;
447         u32 buffer_cmd;
448         u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
449
450         struct wl12xx_fw_status *fw_status;
451         struct wl1271_tx_hw_res_if *tx_res_if;
452
453         /* Current chipset configuration */
454         struct conf_drv_settings conf;
455
456         bool sg_enabled;
457
458         bool enable_11a;
459
460         /* Most recently reported noise in dBm */
461         s8 noise;
462
463         /* bands supported by this instance of wl12xx */
464         struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
465
466         int tcxo_clock;
467
468         /*
469          * wowlan trigger was configured during suspend.
470          * (currently, only "ANY" trigger is supported)
471          */
472         bool wow_enabled;
473         bool irq_wake_enabled;
474
475         /*
476          * AP-mode - links indexed by HLID. The global and broadcast links
477          * are always active.
478          */
479         struct wl1271_link links[WL12XX_MAX_LINKS];
480
481         /* AP-mode - a bitmap of links currently in PS mode according to FW */
482         u32 ap_fw_ps_map;
483
484         /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
485         unsigned long ap_ps_map;
486
487         /* Quirks of specific hardware revisions */
488         unsigned int quirks;
489
490         /* Platform limitations */
491         unsigned int platform_quirks;
492
493         /* number of currently active RX BA sessions */
494         int ba_rx_session_count;
495
496         /* AP-mode - number of currently connected stations */
497         int active_sta_count;
498
499         /* last wlvif we transmitted from */
500         struct wl12xx_vif *last_wlvif;
501
502         /* work to fire when Tx is stuck */
503         struct delayed_work tx_watchdog_work;
504 };
505
506 struct wl1271_station {
507         u8 hlid;
508 };
509
510 struct wl12xx_vif {
511         struct wl1271 *wl;
512         struct list_head list;
513         unsigned long flags;
514         u8 bss_type;
515         u8 p2p; /* we are using p2p role */
516         u8 role_id;
517
518         /* sta/ibss specific */
519         u8 dev_role_id;
520         u8 dev_hlid;
521
522         union {
523                 struct {
524                         u8 hlid;
525                         u8 ba_rx_bitmap;
526
527                         u8 basic_rate_idx;
528                         u8 ap_rate_idx;
529                         u8 p2p_rate_idx;
530
531                         bool qos;
532                 } sta;
533                 struct {
534                         u8 global_hlid;
535                         u8 bcast_hlid;
536
537                         /* HLIDs bitmap of associated stations */
538                         unsigned long sta_hlid_map[BITS_TO_LONGS(
539                                                         WL12XX_MAX_LINKS)];
540
541                         /* recoreded keys - set here before AP startup */
542                         struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
543
544                         u8 mgmt_rate_idx;
545                         u8 bcast_rate_idx;
546                         u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
547                 } ap;
548         };
549
550         /* the hlid of the last transmitted skb */
551         int last_tx_hlid;
552
553         unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
554
555         u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
556         u8 ssid_len;
557
558         /* The current band */
559         enum ieee80211_band band;
560         int channel;
561
562         u32 bitrate_masks[IEEE80211_NUM_BANDS];
563         u32 basic_rate_set;
564
565         /*
566          * currently configured rate set:
567          *      bits  0-15 - 802.11abg rates
568          *      bits 16-23 - 802.11n   MCS index mask
569          * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
570          */
571         u32 basic_rate;
572         u32 rate_set;
573
574         /* probe-req template for the current AP */
575         struct sk_buff *probereq;
576
577         /* Beaconing interval (needed for ad-hoc) */
578         u32 beacon_int;
579
580         /* Default key (for WEP) */
581         u32 default_key;
582
583         /* Our association ID */
584         u16 aid;
585
586         /* Session counter for the chipset */
587         int session_counter;
588
589         /* retry counter for PSM entries */
590         u8 psm_entry_retry;
591
592         /* in dBm */
593         int power_level;
594
595         int rssi_thold;
596         int last_rssi_event;
597
598         /* save the current encryption type for auto-arp config */
599         u8 encryption_type;
600         __be32 ip_addr;
601
602         /* RX BA constraint value */
603         bool ba_support;
604         bool ba_allowed;
605
606         /* Rx Streaming */
607         struct work_struct rx_streaming_enable_work;
608         struct work_struct rx_streaming_disable_work;
609         struct timer_list rx_streaming_timer;
610
611         /*
612          * This struct must be last!
613          * data that has to be saved acrossed reconfigs (e.g. recovery)
614          * should be declared in this struct.
615          */
616         struct {
617                 u8 persistent[0];
618                 /*
619                  * Security sequence number
620                  *     bits 0-15: lower 16 bits part of sequence number
621                  *     bits 16-47: higher 32 bits part of sequence number
622                  *     bits 48-63: not in use
623                  */
624                 u64 tx_security_seq;
625
626                 /* 8 bits of the last sequence number in use */
627                 u8 tx_security_last_seq_lsb;
628         };
629 };
630
631 static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
632 {
633         return (struct wl12xx_vif *)vif->drv_priv;
634 }
635
636 static inline
637 struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
638 {
639         return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
640 }
641
642 #define wl12xx_for_each_wlvif(wl, wlvif) \
643                 list_for_each_entry(wlvif, &wl->wlvif_list, list)
644
645 #define wl12xx_for_each_wlvif_continue(wl, wlvif) \
646                 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
647
648 #define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type)    \
649                 wl12xx_for_each_wlvif(wl, wlvif)                \
650                         if (wlvif->bss_type == _bss_type)
651
652 #define wl12xx_for_each_wlvif_sta(wl, wlvif)    \
653                 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
654
655 #define wl12xx_for_each_wlvif_ap(wl, wlvif)     \
656                 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
657
658 int wl1271_plt_start(struct wl1271 *wl);
659 int wl1271_plt_stop(struct wl1271 *wl);
660 int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
661 void wl12xx_queue_recovery_work(struct wl1271 *wl);
662 size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
663
664 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
665
666 #define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
667 #define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
668
669 #define WL1271_DEFAULT_POWER_LEVEL 0
670
671 #define WL1271_TX_QUEUE_LOW_WATERMARK  32
672 #define WL1271_TX_QUEUE_HIGH_WATERMARK 256
673
674 #define WL1271_DEFERRED_QUEUE_LIMIT    64
675
676 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
677    on in case is has been shut down shortly before */
678 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
679 #define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
680
681 /* Macros to handle wl1271.sta_rate_set */
682 #define HW_BG_RATES_MASK        0xffff
683 #define HW_HT_RATES_OFFSET      16
684
685 /* Quirks */
686
687 /* Each RX/TX transaction requires an end-of-transaction transfer */
688 #define WL12XX_QUIRK_END_OF_TRANSACTION         BIT(0)
689
690 /* wl127x and SPI don't support SDIO block size alignment */
691 #define WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT     BIT(2)
692
693 /* Older firmwares did not implement the FW logger over bus feature */
694 #define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED      BIT(4)
695
696 #define WL12XX_HW_BLOCK_SIZE    256
697
698 #endif