Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[sfrench/cifs-2.6.git] / drivers / staging / at76_usb / at76_usb.h
1 /*
2  * Copyright (c) 2002,2003 Oliver Kurth
3  *           (c) 2003,2004 Joerg Albert <joerg.albert@gmx.de>
4  *           (c) 2007 Guido Guenther <agx@sigxcpu.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This driver was based on information from the Sourceforge driver
12  * released and maintained by Atmel:
13  *
14  *  http://sourceforge.net/projects/atmelwlandriver/
15  *
16  * Although the code was completely re-written,
17  * it would have been impossible without Atmel's decision to
18  * release an Open Source driver (unfortunately the firmware was
19  * kept binary only). Thanks for that decision to Atmel!
20  */
21
22 #ifndef _AT76_USB_H
23 #define _AT76_USB_H
24
25 /* Board types */
26 enum board_type {
27         BOARD_503_ISL3861 = 1,
28         BOARD_503_ISL3863 = 2,
29         BOARD_503 = 3,
30         BOARD_503_ACC = 4,
31         BOARD_505 = 5,
32         BOARD_505_2958 = 6,
33         BOARD_505A = 7,
34         BOARD_505AMX = 8
35 };
36
37 /* our private ioctl's */
38 /* preamble length (0 - long, 1 - short, 2 - auto) */
39 #define AT76_SET_SHORT_PREAMBLE         (SIOCIWFIRSTPRIV + 0)
40 #define AT76_GET_SHORT_PREAMBLE         (SIOCIWFIRSTPRIV + 1)
41 /* which debug channels are enabled */
42 #define AT76_SET_DEBUG                  (SIOCIWFIRSTPRIV + 2)
43 #define AT76_GET_DEBUG                  (SIOCIWFIRSTPRIV + 3)
44 /* power save mode (incl. the Atmel proprietary smart save mode) */
45 #define AT76_SET_POWERSAVE_MODE         (SIOCIWFIRSTPRIV + 4)
46 #define AT76_GET_POWERSAVE_MODE         (SIOCIWFIRSTPRIV + 5)
47 /* min and max channel times for scan */
48 #define AT76_SET_SCAN_TIMES             (SIOCIWFIRSTPRIV + 6)
49 #define AT76_GET_SCAN_TIMES             (SIOCIWFIRSTPRIV + 7)
50 /* scan mode (0 - active, 1 - passive) */
51 #define AT76_SET_SCAN_MODE              (SIOCIWFIRSTPRIV + 8)
52 #define AT76_GET_SCAN_MODE              (SIOCIWFIRSTPRIV + 9)
53
54 #define CMD_STATUS_IDLE                         0x00
55 #define CMD_STATUS_COMPLETE                     0x01
56 #define CMD_STATUS_UNKNOWN                      0x02
57 #define CMD_STATUS_INVALID_PARAMETER            0x03
58 #define CMD_STATUS_FUNCTION_NOT_SUPPORTED       0x04
59 #define CMD_STATUS_TIME_OUT                     0x07
60 #define CMD_STATUS_IN_PROGRESS                  0x08
61 #define CMD_STATUS_HOST_FAILURE                 0xff
62 #define CMD_STATUS_SCAN_FAILED                  0xf0
63
64 /* answers to get op mode */
65 #define OPMODE_NONE                             0x00
66 #define OPMODE_NORMAL_NIC_WITH_FLASH            0x01
67 #define OPMODE_HW_CONFIG_MODE                   0x02
68 #define OPMODE_DFU_MODE_WITH_FLASH              0x03
69 #define OPMODE_NORMAL_NIC_WITHOUT_FLASH         0x04
70
71 #define CMD_SET_MIB             0x01
72 #define CMD_GET_MIB             0x02
73 #define CMD_SCAN                0x03
74 #define CMD_JOIN                0x04
75 #define CMD_START_IBSS          0x05
76 #define CMD_RADIO_ON            0x06
77 #define CMD_RADIO_OFF           0x07
78 #define CMD_STARTUP             0x0B
79
80 #define MIB_LOCAL               0x01
81 #define MIB_MAC_ADDR            0x02
82 #define MIB_MAC                 0x03
83 #define MIB_MAC_MGMT            0x05
84 #define MIB_MAC_WEP             0x06
85 #define MIB_PHY                 0x07
86 #define MIB_FW_VERSION          0x08
87 #define MIB_MDOMAIN             0x09
88
89 #define ADHOC_MODE              1
90 #define INFRASTRUCTURE_MODE     2
91
92 /* values for struct mib_local, field preamble_type */
93 #define PREAMBLE_TYPE_LONG      0
94 #define PREAMBLE_TYPE_SHORT     1
95 #define PREAMBLE_TYPE_AUTO      2
96
97 /* values for tx_rate */
98 #define TX_RATE_1MBIT           0
99 #define TX_RATE_2MBIT           1
100 #define TX_RATE_5_5MBIT         2
101 #define TX_RATE_11MBIT          3
102 #define TX_RATE_AUTO            4
103
104 /* power management modes */
105 #define AT76_PM_OFF             1
106 #define AT76_PM_ON              2
107 #define AT76_PM_SMART           3
108
109 struct hwcfg_r505 {
110         u8 cr39_values[14];
111         u8 reserved1[14];
112         u8 bb_cr[14];
113         u8 pidvid[4];
114         u8 mac_addr[ETH_ALEN];
115         u8 regulatory_domain;
116         u8 reserved2[14];
117         u8 cr15_values[14];
118         u8 reserved3[3];
119 } __attribute__((packed));
120
121 struct hwcfg_rfmd {
122         u8 cr20_values[14];
123         u8 cr21_values[14];
124         u8 bb_cr[14];
125         u8 pidvid[4];
126         u8 mac_addr[ETH_ALEN];
127         u8 regulatory_domain;
128         u8 low_power_values[14];
129         u8 normal_power_values[14];
130         u8 reserved1[3];
131 } __attribute__((packed));
132
133 struct hwcfg_intersil {
134         u8 mac_addr[ETH_ALEN];
135         u8 cr31_values[14];
136         u8 cr58_values[14];
137         u8 pidvid[4];
138         u8 regulatory_domain;
139         u8 reserved[1];
140 } __attribute__((packed));
141
142 union at76_hwcfg {
143         struct hwcfg_intersil i;
144         struct hwcfg_rfmd r3;
145         struct hwcfg_r505 r5;
146 };
147
148 #define WEP_SMALL_KEY_LEN       (40 / 8)
149 #define WEP_LARGE_KEY_LEN       (104 / 8)
150
151 struct at76_card_config {
152         u8 exclude_unencrypted;
153         u8 promiscuous_mode;
154         u8 short_retry_limit;
155         u8 encryption_type;
156         __le16 rts_threshold;
157         __le16 fragmentation_threshold; /* 256..2346 */
158         u8 basic_rate_set[4];
159         u8 auto_rate_fallback;  /* 0,1 */
160         u8 channel;
161         u8 privacy_invoked;
162         u8 wep_default_key_id;  /* 0..3 */
163         u8 current_ssid[32];
164         u8 wep_default_key_value[4][WEP_KEY_LEN];
165         u8 ssid_len;
166         u8 short_preamble;
167         __le16 beacon_period;
168 } __attribute__((packed));
169
170 struct at76_command {
171         u8 cmd;
172         u8 reserved;
173         __le16 size;
174         u8 data[0];
175 } __attribute__((packed));
176
177 /* Length of Atmel-specific Rx header before 802.11 frame */
178 #define AT76_RX_HDRLEN offsetof(struct at76_rx_buffer, packet)
179
180 struct at76_rx_buffer {
181         __le16 wlength;
182         u8 rx_rate;
183         u8 newbss;
184         u8 fragmentation;
185         u8 rssi;
186         u8 link_quality;
187         u8 noise_level;
188         __le32 rx_time;
189         u8 packet[IEEE80211_FRAME_LEN + IEEE80211_FCS_LEN];
190 } __attribute__((packed));
191
192 /* Length of Atmel-specific Tx header before 802.11 frame */
193 #define AT76_TX_HDRLEN offsetof(struct at76_tx_buffer, packet)
194
195 struct at76_tx_buffer {
196         __le16 wlength;
197         u8 tx_rate;
198         u8 padding;
199         u8 reserved[4];
200         u8 packet[IEEE80211_FRAME_LEN + IEEE80211_FCS_LEN];
201 } __attribute__((packed));
202
203 /* defines for scan_type below */
204 #define SCAN_TYPE_ACTIVE        0
205 #define SCAN_TYPE_PASSIVE       1
206
207 struct at76_req_scan {
208         u8 bssid[ETH_ALEN];
209         u8 essid[32];
210         u8 scan_type;
211         u8 channel;
212         __le16 probe_delay;
213         __le16 min_channel_time;
214         __le16 max_channel_time;
215         u8 essid_size;
216         u8 international_scan;
217 } __attribute__((packed));
218
219 struct at76_req_ibss {
220         u8 bssid[ETH_ALEN];
221         u8 essid[32];
222         u8 bss_type;
223         u8 channel;
224         u8 essid_size;
225         u8 reserved[3];
226 } __attribute__((packed));
227
228 struct at76_req_join {
229         u8 bssid[ETH_ALEN];
230         u8 essid[32];
231         u8 bss_type;
232         u8 channel;
233         __le16 timeout;
234         u8 essid_size;
235         u8 reserved;
236 } __attribute__((packed));
237
238 struct set_mib_buffer {
239         u8 type;
240         u8 size;
241         u8 index;
242         u8 reserved;
243         union {
244                 u8 byte;
245                 __le16 word;
246                 u8 addr[ETH_ALEN];
247         } data;
248 } __attribute__((packed));
249
250 struct mib_local {
251         u16 reserved0;
252         u8 beacon_enable;
253         u8 txautorate_fallback;
254         u8 reserved1;
255         u8 ssid_size;
256         u8 promiscuous_mode;
257         u16 reserved2;
258         u8 preamble_type;
259         u16 reserved3;
260 } __attribute__((packed));
261
262 struct mib_mac_addr {
263         u8 mac_addr[ETH_ALEN];
264         u8 res[2];              /* ??? */
265         u8 group_addr[4][ETH_ALEN];
266         u8 group_addr_status[4];
267 } __attribute__((packed));
268
269 struct mib_mac {
270         __le32 max_tx_msdu_lifetime;
271         __le32 max_rx_lifetime;
272         __le16 frag_threshold;
273         __le16 rts_threshold;
274         __le16 cwmin;
275         __le16 cwmax;
276         u8 short_retry_time;
277         u8 long_retry_time;
278         u8 scan_type;           /* active or passive */
279         u8 scan_channel;
280         __le16 probe_delay;     /* delay before ProbeReq in active scan, RO */
281         __le16 min_channel_time;
282         __le16 max_channel_time;
283         __le16 listen_interval;
284         u8 desired_ssid[32];
285         u8 desired_bssid[ETH_ALEN];
286         u8 desired_bsstype;     /* ad-hoc or infrastructure */
287         u8 reserved2;
288 } __attribute__((packed));
289
290 struct mib_mac_mgmt {
291         __le16 beacon_period;
292         __le16 CFP_max_duration;
293         __le16 medium_occupancy_limit;
294         __le16 station_id;      /* assoc id */
295         __le16 ATIM_window;
296         u8 CFP_mode;
297         u8 privacy_option_implemented;
298         u8 DTIM_period;
299         u8 CFP_period;
300         u8 current_bssid[ETH_ALEN];
301         u8 current_essid[32];
302         u8 current_bss_type;
303         u8 power_mgmt_mode;
304         /* rfmd and 505 */
305         u8 ibss_change;
306         u8 res;
307         u8 multi_domain_capability_implemented;
308         u8 multi_domain_capability_enabled;
309         u8 country_string[3];
310         u8 reserved[3];
311 } __attribute__((packed));
312
313 struct mib_mac_wep {
314         u8 privacy_invoked;     /* 0 disable encr., 1 enable encr */
315         u8 wep_default_key_id;
316         u8 wep_key_mapping_len;
317         u8 exclude_unencrypted;
318         __le32 wep_icv_error_count;
319         __le32 wep_excluded_count;
320         u8 wep_default_keyvalue[WEP_KEYS][WEP_KEY_LEN];
321         u8 encryption_level;    /* 1 for 40bit, 2 for 104bit encryption */
322 } __attribute__((packed));
323
324 struct mib_phy {
325         __le32 ed_threshold;
326
327         __le16 slot_time;
328         __le16 sifs_time;
329         __le16 preamble_length;
330         __le16 plcp_header_length;
331         __le16 mpdu_max_length;
332         __le16 cca_mode_supported;
333
334         u8 operation_rate_set[4];
335         u8 channel_id;
336         u8 current_cca_mode;
337         u8 phy_type;
338         u8 current_reg_domain;
339 } __attribute__((packed));
340
341 struct mib_fw_version {
342         u8 major;
343         u8 minor;
344         u8 patch;
345         u8 build;
346 } __attribute__((packed));
347
348 struct mib_mdomain {
349         u8 tx_powerlevel[14];
350         u8 channel_list[14];    /* 0 for invalid channels */
351 } __attribute__((packed));
352
353 struct at76_fw_header {
354         __le32 crc;             /* CRC32 of the whole image */
355         __le32 board_type;      /* firmware compatibility code */
356         u8 build;               /* firmware build number */
357         u8 patch;               /* firmware patch level */
358         u8 minor;               /* firmware minor version */
359         u8 major;               /* firmware major version */
360         __le32 str_offset;      /* offset of the copyright string */
361         __le32 int_fw_offset;   /* internal firmware image offset */
362         __le32 int_fw_len;      /* internal firmware image length */
363         __le32 ext_fw_offset;   /* external firmware image offset */
364         __le32 ext_fw_len;      /* external firmware image length */
365 } __attribute__((packed));
366
367 enum mac_state {
368         MAC_INIT,
369         MAC_SCANNING,
370         MAC_AUTH,
371         MAC_ASSOC,
372         MAC_JOINING,
373         MAC_CONNECTED,
374         MAC_OWN_IBSS
375 };
376
377 /* a description of a regulatory domain and the allowed channels */
378 struct reg_domain {
379         u16 code;
380         char const *name;
381         u32 channel_map;        /* if bit N is set, channel (N+1) is allowed */
382 };
383
384 /* how long do we keep a (I)BSS in the bss_list in jiffies
385    this should be long enough for the user to retrieve the table
386    (by iwlist ?) after the device started, because all entries from
387    other channels than the one the device locks on get removed, too */
388 #define BSS_LIST_TIMEOUT        (120 * HZ)
389 /* struct to store BSS info found during scan */
390 #define BSS_LIST_MAX_RATE_LEN   32      /* 32 rates should be enough ... */
391
392 struct bss_info {
393         struct list_head list;
394
395         u8 bssid[ETH_ALEN];     /* bssid */
396         u8 ssid[IW_ESSID_MAX_SIZE];     /* essid */
397         u8 ssid_len;            /* length of ssid above */
398         u8 channel;
399         u16 capa;               /* BSS capabilities */
400         u16 beacon_interval;    /* beacon interval, Kus (1024 microseconds) */
401         u8 rates[BSS_LIST_MAX_RATE_LEN];        /* supported rates in units of
402                                                    500 kbps, ORed with 0x80 for
403                                                    basic rates */
404         u8 rates_len;
405
406         /* quality of received beacon */
407         u8 rssi;
408         u8 link_qual;
409         u8 noise_level;
410
411         unsigned long last_rx;  /* time (jiffies) of last beacon received */
412 };
413
414 /* a rx data buffer to collect rx fragments */
415 struct rx_data_buf {
416         u8 sender[ETH_ALEN];    /* sender address */
417         u16 seqnr;              /* sequence number */
418         u16 fragnr;             /* last fragment received */
419         unsigned long last_rx;  /* jiffies of last rx */
420         struct sk_buff *skb;    /* == NULL if entry is free */
421 };
422
423 #define NR_RX_DATA_BUF          8
424
425 /* Data for one loaded firmware file */
426 struct fwentry {
427         const char *const fwname;
428         const struct firmware *fw;
429         int extfw_size;
430         int intfw_size;
431         /* pointer to loaded firmware, no need to free */
432         u8 *extfw;              /* external firmware, extfw_size bytes long */
433         u8 *intfw;              /* internal firmware, intfw_size bytes long */
434         enum board_type board_type;     /* board type */
435         struct mib_fw_version fw_version;
436         int loaded;             /* Loaded and parsed successfully */
437 };
438
439 struct at76_priv {
440         struct usb_device *udev;        /* USB device pointer */
441         struct net_device *netdev;      /* net device pointer */
442         struct net_device_stats stats;  /* net device stats */
443         struct iw_statistics wstats;    /* wireless stats */
444
445         struct sk_buff *rx_skb; /* skbuff for receiving data */
446         void *bulk_out_buffer;  /* buffer for sending data */
447
448         struct urb *tx_urb;     /* URB for sending data */
449         struct urb *rx_urb;     /* URB for receiving data */
450
451         unsigned int tx_pipe;   /* bulk out pipe */
452         unsigned int rx_pipe;   /* bulk in pipe */
453
454         struct mutex mtx;       /* locks this structure */
455
456         /* work queues */
457         struct work_struct work_assoc_done;
458         struct work_struct work_join;
459         struct work_struct work_new_bss;
460         struct work_struct work_start_scan;
461         struct work_struct work_set_promisc;
462         struct work_struct work_submit_rx;
463         struct delayed_work dwork_restart;
464         struct delayed_work dwork_get_scan;
465         struct delayed_work dwork_beacon;
466         struct delayed_work dwork_auth;
467         struct delayed_work dwork_assoc;
468
469         struct tasklet_struct rx_tasklet;
470
471         /* the WEP stuff */
472         int wep_enabled;        /* 1 if WEP is enabled */
473         int wep_key_id;         /* key id to be used */
474         u8 wep_keys[WEP_KEYS][WEP_KEY_LEN];     /* the four WEP keys,
475                                                    5 or 13 bytes are used */
476         u8 wep_keys_len[WEP_KEYS];      /* the length of the above keys */
477
478         int channel;
479         int iw_mode;
480         u8 bssid[ETH_ALEN];
481         u8 essid[IW_ESSID_MAX_SIZE];
482         int essid_size;
483         int radio_on;
484         int promisc;
485
486         int preamble_type;      /* 0 - long, 1 - short, 2 - auto */
487         int auth_mode;          /* authentication type: 0 open, 1 shared key */
488         int txrate;             /* 0,1,2,3 = 1,2,5.5,11 Mbps, 4 is auto */
489         int frag_threshold;     /* threshold for fragmentation of tx packets */
490         int rts_threshold;      /* threshold for RTS mechanism */
491         int short_retry_limit;
492
493         int scan_min_time;      /* scan min channel time */
494         int scan_max_time;      /* scan max channel time */
495         int scan_mode;          /* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */
496         int scan_need_any;      /* if set, need to scan for any ESSID */
497
498         /* the list we got from scanning */
499         spinlock_t bss_list_spinlock;   /* protects bss_list operations */
500         struct list_head bss_list;      /* list of BSS we got beacons from */
501         struct timer_list bss_list_timer;       /* timer to purge old entries
502                                                    from bss_list */
503         struct bss_info *curr_bss;      /* current BSS */
504         u16 assoc_id;           /* current association ID, if associated */
505
506         u8 wanted_bssid[ETH_ALEN];
507         int wanted_bssid_valid; /* != 0 if wanted_bssid is to be used */
508
509         /* some data for infrastructure mode only */
510         spinlock_t mgmt_spinlock;       /* this spinlock protects access to
511                                            next_mgmt_bulk */
512
513         struct at76_tx_buffer *next_mgmt_bulk;  /* pending management msg to
514                                                    send via bulk out */
515         enum mac_state mac_state;
516         enum {
517                 SCAN_IDLE,
518                 SCAN_IN_PROGRESS,
519                 SCAN_COMPLETED
520         } scan_state;
521         time_t last_scan;
522
523         int retries;            /* remaining retries in case of timeout when
524                                  * sending AuthReq or AssocReq */
525         u8 pm_mode;             /* power management mode */
526         u32 pm_period;          /* power management period in microseconds */
527
528         struct reg_domain const *domain;        /* reg domain description */
529
530         /* iwspy support */
531         spinlock_t spy_spinlock;
532         struct iw_spy_data spy_data;
533
534         struct iw_public_data wireless_data;
535
536         /* These fields contain HW config provided by the device (not all of
537          * these fields are used by all board types) */
538         u8 mac_addr[ETH_ALEN];
539         u8 regulatory_domain;
540
541         struct at76_card_config card_config;
542
543         /* store rx fragments until complete */
544         struct rx_data_buf rx_data[NR_RX_DATA_BUF];
545
546         enum board_type board_type;
547         struct mib_fw_version fw_version;
548
549         unsigned int device_unplugged:1;
550         unsigned int netdev_registered:1;
551         struct set_mib_buffer mib_buf;  /* global buffer for set_mib calls */
552
553         /* beacon counting */
554         int beacon_period;      /* period of mgmt beacons, Kus */
555         int beacons_received;
556         unsigned long beacons_last_qual;        /* time we restarted counting
557                                                    beacons */
558 };
559
560 struct at76_rx_radiotap {
561         struct ieee80211_radiotap_header rt_hdr;
562         __le64 rt_tsft;
563         u8 rt_flags;
564         u8 rt_rate;
565         s8 rt_signal;
566         s8 rt_noise;
567 };
568
569 #define AT76_RX_RADIOTAP_PRESENT                  \
570         ((1 << IEEE80211_RADIOTAP_TSFT)         | \
571         (1 << IEEE80211_RADIOTAP_FLAGS)         | \
572         (1 << IEEE80211_RADIOTAP_RATE)          | \
573         (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)  | \
574         (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
575
576 #define BEACON_MAX_DATA_LENGTH  1500
577
578 /* the maximum size of an AssocReq packet */
579 #define ASSOCREQ_MAX_SIZE \
580   (AT76_TX_HDRLEN + sizeof(struct ieee80211_assoc_request) + \
581    1 + 1 + IW_ESSID_MAX_SIZE + 1 + 1 + 4)
582
583 /* for shared secret auth, add the challenge text size */
584 #define AUTH_FRAME_SIZE (AT76_TX_HDRLEN + sizeof(struct ieee80211_auth))
585
586 /* Maximal number of AuthReq retries */
587 #define AUTH_RETRIES            3
588
589 /* Maximal number of AssocReq retries */
590 #define ASSOC_RETRIES           3
591
592 /* Beacon timeout in managed mode when we are connected */
593 #define BEACON_TIMEOUT          (10 * HZ)
594
595 /* Timeout for authentication response */
596 #define AUTH_TIMEOUT            (1 * HZ)
597
598 /* Timeout for association response */
599 #define ASSOC_TIMEOUT           (1 * HZ)
600
601 /* Polling interval when scan is running */
602 #define SCAN_POLL_INTERVAL      (HZ / 4)
603
604 /* Command completion timeout */
605 #define CMD_COMPLETION_TIMEOUT  (5 * HZ)
606
607 #define DEF_RTS_THRESHOLD       1536
608 #define DEF_FRAG_THRESHOLD      1536
609 #define DEF_SHORT_RETRY_LIMIT   8
610 #define DEF_CHANNEL             10
611 #define DEF_SCAN_MIN_TIME       10
612 #define DEF_SCAN_MAX_TIME       120
613
614 #define MAX_RTS_THRESHOLD       (MAX_FRAG_THRESHOLD + 1)
615
616 /* the max padding size for tx in bytes (see calc_padding) */
617 #define MAX_PADDING_SIZE        53
618
619 #endif                          /* _AT76_USB_H */