Merge branches 'pm-cpuidle', 'pm-opp' and 'pm-avs'
[cascardo/linux.git] / drivers / staging / ks7010 / ks_wlan.h
1 /*
2  *   Driver for KeyStream IEEE802.11 b/g wireless LAN cards.
3  *
4  *   Copyright (C) 2006-2008 KeyStream Corp.
5  *   Copyright (C) 2009 Renesas Technology Corp.
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License version 2 as
9  *   published by the Free Software Foundation.
10  */
11
12 #ifndef _KS_WLAN_H
13 #define _KS_WLAN_H
14
15 #define WPS
16
17 #include <linux/version.h>
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21
22 #include <linux/spinlock.h>     /* spinlock_t                                   */
23 #include <linux/sched.h>        /* wait_queue_head_t                            */
24 #include <linux/types.h>        /* pid_t                                        */
25 #include <linux/netdevice.h>    /* struct net_device_stats,  struct sk_buff     */
26 #include <linux/etherdevice.h>
27 #include <linux/wireless.h>
28 #include <asm/atomic.h> /* struct atmic_t                               */
29 #include <linux/timer.h>        /* struct timer_list */
30 #include <linux/string.h>
31 #include <linux/completion.h>   /* struct completion */
32 #include <linux/workqueue.h>
33
34 #include <asm/io.h>
35
36 #include "ks7010_sdio.h"
37
38 #ifdef KS_WLAN_DEBUG
39 #define DPRINTK(n, fmt, args...) \
40                  if (KS_WLAN_DEBUG>(n)) printk(KERN_NOTICE "%s: "fmt, __FUNCTION__, ## args)
41 #else
42 #define DPRINTK(n, fmt, args...)
43 #endif
44
45 struct ks_wlan_parameter {
46         uint8_t operation_mode; /* Operation Mode */
47         uint8_t channel;        /*  Channel */
48         uint8_t tx_rate;        /*  Transmit Rate */
49         struct {
50                 uint8_t size;
51                 uint8_t body[16];
52         } rate_set;
53         uint8_t bssid[ETH_ALEN];        /* BSSID */
54         struct {
55                 uint8_t size;
56                 uint8_t body[32 + 1];
57         } ssid; /*  SSID */
58         uint8_t preamble;       /*  Preamble */
59         uint8_t powermgt;       /*  PowerManagementMode */
60         uint32_t scan_type;     /*  AP List Scan Type */
61 #define BEACON_LOST_COUNT_MIN 0
62 #define BEACON_LOST_COUNT_MAX 65535
63         uint32_t beacon_lost_count;     /*  Beacon Lost Count */
64         uint32_t rts;   /*  RTS Threashold */
65         uint32_t fragment;      /*  Fragmentation Threashold */
66         uint32_t privacy_invoked;
67         uint32_t wep_index;
68         struct {
69                 uint8_t size;
70                 uint8_t val[13 * 2 + 1];
71         } wep_key[4];
72         uint16_t authenticate_type;
73         uint16_t phy_type;      /* 11b/11g/11bg mode type */
74         uint16_t cts_mode;      /* for 11g/11bg mode cts mode */
75         uint16_t phy_info_timer;        /* phy information timer */
76 };
77
78 enum {
79         DEVICE_STATE_OFF = 0,   /* this means hw_unavailable is != 0 */
80         DEVICE_STATE_PREBOOT,   /* we are in a pre-boot state (empty RAM) */
81         DEVICE_STATE_BOOT,      /* boot state (fw upload, run fw) */
82         DEVICE_STATE_PREINIT,   /* pre-init state */
83         DEVICE_STATE_INIT,      /* init state (restore MIB backup to device) */
84         DEVICE_STATE_READY,     /* driver&device are in operational state */
85         DEVICE_STATE_SLEEP      /* device in sleep mode */
86 };
87
88 /* SME flag */
89 #define SME_MODE_SET        (1<<0)
90 #define SME_RTS             (1<<1)
91 #define SME_FRAG            (1<<2)
92 #define SME_WEP_FLAG        (1<<3)
93 #define SME_WEP_INDEX       (1<<4)
94 #define SME_WEP_VAL1        (1<<5)
95 #define SME_WEP_VAL2        (1<<6)
96 #define SME_WEP_VAL3        (1<<7)
97 #define SME_WEP_VAL4        (1<<8)
98 #define SME_WEP_VAL_MASK    (SME_WEP_VAL1|SME_WEP_VAL2|SME_WEP_VAL3|SME_WEP_VAL4)
99 #define SME_RSN             (1<<9)
100 #define SME_RSN_MULTICAST   (1<<10)
101 #define SME_RSN_UNICAST     (1<<11)
102 #define SME_RSN_AUTH        (1<<12)
103
104 #define SME_AP_SCAN         (1<<13)
105 #define SME_MULTICAST       (1<<14)
106
107 /* SME Event */
108 enum {
109         SME_START,
110
111         SME_MULTICAST_REQUEST,
112         SME_MACADDRESS_SET_REQUEST,
113         SME_BSS_SCAN_REQUEST,
114         SME_SET_FLAG,
115         SME_SET_TXKEY,
116         SME_SET_KEY1,
117         SME_SET_KEY2,
118         SME_SET_KEY3,
119         SME_SET_KEY4,
120         SME_SET_PMK_TSC,
121         SME_SET_GMK1_TSC,
122         SME_SET_GMK2_TSC,
123         SME_SET_GMK3_TSC,
124         SME_SET_PMKSA,
125         SME_POW_MNGMT_REQUEST,
126         SME_PHY_INFO_REQUEST,
127         SME_MIC_FAILURE_REQUEST,
128         SME_GET_MAC_ADDRESS,
129         SME_GET_PRODUCT_VERSION,
130         SME_STOP_REQUEST,
131         SME_RTS_THRESHOLD_REQUEST,
132         SME_FRAGMENTATION_THRESHOLD_REQUEST,
133         SME_WEP_INDEX_REQUEST,
134         SME_WEP_KEY1_REQUEST,
135         SME_WEP_KEY2_REQUEST,
136         SME_WEP_KEY3_REQUEST,
137         SME_WEP_KEY4_REQUEST,
138         SME_WEP_FLAG_REQUEST,
139         SME_RSN_UCAST_REQUEST,
140         SME_RSN_MCAST_REQUEST,
141         SME_RSN_AUTH_REQUEST,
142         SME_RSN_ENABLED_REQUEST,
143         SME_RSN_MODE_REQUEST,
144 #ifdef WPS
145         SME_WPS_ENABLE_REQUEST,
146         SME_WPS_PROBE_REQUEST,
147 #endif
148         SME_SET_GAIN,
149         SME_GET_GAIN,
150         SME_SLEEP_REQUEST,
151         SME_SET_REGION,
152         SME_MODE_SET_REQUEST,
153         SME_START_REQUEST,
154         SME_GET_EEPROM_CKSUM,
155
156         SME_MIC_FAILURE_CONFIRM,
157         SME_START_CONFIRM,
158
159         SME_MULTICAST_CONFIRM,
160         SME_BSS_SCAN_CONFIRM,
161         SME_GET_CURRENT_AP,
162         SME_POW_MNGMT_CONFIRM,
163         SME_PHY_INFO_CONFIRM,
164         SME_STOP_CONFIRM,
165         SME_RTS_THRESHOLD_CONFIRM,
166         SME_FRAGMENTATION_THRESHOLD_CONFIRM,
167         SME_WEP_INDEX_CONFIRM,
168         SME_WEP_KEY1_CONFIRM,
169         SME_WEP_KEY2_CONFIRM,
170         SME_WEP_KEY3_CONFIRM,
171         SME_WEP_KEY4_CONFIRM,
172         SME_WEP_FLAG_CONFIRM,
173         SME_RSN_UCAST_CONFIRM,
174         SME_RSN_MCAST_CONFIRM,
175         SME_RSN_AUTH_CONFIRM,
176         SME_RSN_ENABLED_CONFIRM,
177         SME_RSN_MODE_CONFIRM,
178         SME_MODE_SET_CONFIRM,
179         SME_SLEEP_CONFIRM,
180
181         SME_RSN_SET_CONFIRM,
182         SME_WEP_SET_CONFIRM,
183         SME_TERMINATE,
184
185         SME_EVENT_SIZE  /* end */
186 };
187
188 /* SME Status */
189 enum {
190         SME_IDLE,
191         SME_SETUP,
192         SME_DISCONNECT,
193         SME_CONNECT
194 };
195
196 #define SME_EVENT_BUFF_SIZE     128
197
198 struct sme_info {
199         int sme_status;
200         int event_buff[SME_EVENT_BUFF_SIZE];
201         unsigned int qhead;
202         unsigned int qtail;
203 #ifdef KS_WLAN_DEBUG
204         /* for debug */
205         unsigned int max_event_count;
206 #endif
207         spinlock_t sme_spin;
208         unsigned long sme_flag;
209 };
210
211 struct hostt_t {
212         int buff[SME_EVENT_BUFF_SIZE];
213         unsigned int qhead;
214         unsigned int qtail;
215 };
216
217 #define RSN_IE_BODY_MAX 64
218 struct rsn_ie_t {
219         uint8_t id;     /* 0xdd = WPA or 0x30 = RSN */
220         uint8_t size;   /* max ? 255 ? */
221         uint8_t body[RSN_IE_BODY_MAX];
222 } __attribute__ ((packed));
223
224 #ifdef WPS
225 #define WPS_IE_BODY_MAX 255
226 struct wps_ie_t {
227         uint8_t id;     /* 221 'dd <len> 00 50 F2 04' */
228         uint8_t size;   /* max ? 255 ? */
229         uint8_t body[WPS_IE_BODY_MAX];
230 } __attribute__ ((packed));
231 #endif /* WPS */
232
233 struct local_ap_t {
234         uint8_t bssid[6];
235         uint8_t rssi;
236         uint8_t sq;
237         struct {
238                 uint8_t size;
239                 uint8_t body[32];
240                 uint8_t ssid_pad;
241         } ssid;
242         struct {
243                 uint8_t size;
244                 uint8_t body[16];
245                 uint8_t rate_pad;
246         } rate_set;
247         uint16_t capability;
248         uint8_t channel;
249         uint8_t noise;
250         struct rsn_ie_t wpa_ie;
251         struct rsn_ie_t rsn_ie;
252 #ifdef WPS
253         struct wps_ie_t wps_ie;
254 #endif /* WPS */
255 };
256
257 #define LOCAL_APLIST_MAX 31
258 #define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
259 struct local_aplist_t {
260         int size;
261         struct local_ap_t ap[LOCAL_APLIST_MAX + 1];
262 };
263
264 struct local_gain_t {
265         uint8_t TxMode;
266         uint8_t RxMode;
267         uint8_t TxGain;
268         uint8_t RxGain;
269 };
270
271 struct local_eeprom_sum_t {
272         uint8_t type;
273         uint8_t result;
274 };
275
276 enum {
277         EEPROM_OK,
278         EEPROM_CHECKSUM_NONE,
279         EEPROM_FW_NOT_SUPPORT,
280         EEPROM_NG,
281 };
282
283 /* Power Save Status */
284 enum {
285         PS_NONE,
286         PS_ACTIVE_SET,
287         PS_SAVE_SET,
288         PS_CONF_WAIT,
289         PS_SNOOZE,
290         PS_WAKEUP
291 };
292
293 struct power_save_status_t {
294         atomic_t status;        /* initialvalue 0 */
295         struct completion wakeup_wait;
296         atomic_t confirm_wait;
297         atomic_t snooze_guard;
298 };
299
300 struct sleep_status_t {
301         atomic_t status;        /* initialvalue 0 */
302         atomic_t doze_request;
303         atomic_t wakeup_request;
304 };
305
306 /* WPA */
307 struct scan_ext_t {
308         unsigned int flag;
309         char ssid[IW_ESSID_MAX_SIZE + 1];
310 };
311
312 enum {
313         CIPHER_NONE,
314         CIPHER_WEP40,
315         CIPHER_TKIP,
316         CIPHER_CCMP,
317         CIPHER_WEP104
318 };
319
320 #define CIPHER_ID_WPA_NONE    "\x00\x50\xf2\x00"
321 #define CIPHER_ID_WPA_WEP40   "\x00\x50\xf2\x01"
322 #define CIPHER_ID_WPA_TKIP    "\x00\x50\xf2\x02"
323 #define CIPHER_ID_WPA_CCMP    "\x00\x50\xf2\x04"
324 #define CIPHER_ID_WPA_WEP104  "\x00\x50\xf2\x05"
325
326 #define CIPHER_ID_WPA2_NONE   "\x00\x0f\xac\x00"
327 #define CIPHER_ID_WPA2_WEP40  "\x00\x0f\xac\x01"
328 #define CIPHER_ID_WPA2_TKIP   "\x00\x0f\xac\x02"
329 #define CIPHER_ID_WPA2_CCMP   "\x00\x0f\xac\x04"
330 #define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
331
332 #define CIPHER_ID_LEN    4
333
334 enum {
335         KEY_MGMT_802_1X,
336         KEY_MGMT_PSK,
337         KEY_MGMT_WPANONE,
338 };
339
340 #define KEY_MGMT_ID_WPA_NONE     "\x00\x50\xf2\x00"
341 #define KEY_MGMT_ID_WPA_1X       "\x00\x50\xf2\x01"
342 #define KEY_MGMT_ID_WPA_PSK      "\x00\x50\xf2\x02"
343 #define KEY_MGMT_ID_WPA_WPANONE  "\x00\x50\xf2\xff"
344
345 #define KEY_MGMT_ID_WPA2_NONE    "\x00\x0f\xac\x00"
346 #define KEY_MGMT_ID_WPA2_1X      "\x00\x0f\xac\x01"
347 #define KEY_MGMT_ID_WPA2_PSK     "\x00\x0f\xac\x02"
348 #define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
349
350 #define KEY_MGMT_ID_LEN  4
351
352 #define MIC_KEY_SIZE 8
353
354 struct wpa_key_t {
355         uint32_t ext_flags;     /* IW_ENCODE_EXT_xxx */
356         uint8_t tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
357         uint8_t rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
358         struct sockaddr addr;   /* ff:ff:ff:ff:ff:ff for broadcast/multicast
359                                  * (group) keys or unicast address for
360                                  * individual keys */
361         uint16_t alg;
362         uint16_t key_len;       /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
363         uint8_t key_val[IW_ENCODING_TOKEN_MAX];
364         uint8_t tx_mic_key[MIC_KEY_SIZE];
365         uint8_t rx_mic_key[MIC_KEY_SIZE];
366 };
367 #define WPA_KEY_INDEX_MAX 4
368 #define WPA_RX_SEQ_LEN 6
369
370 struct mic_failure_t {
371         uint16_t failure;       /* MIC Failure counter 0 or 1 or 2 */
372         uint16_t counter;       /* 1sec counter 0-60 */
373         uint32_t last_failure_time;
374         int stop;       /* stop flag */
375 };
376
377 struct wpa_status_t {
378         int wpa_enabled;
379         unsigned int rsn_enabled;
380         int version;
381         int pairwise_suite;     /* unicast cipher */
382         int group_suite;        /* multicast cipher */
383         int key_mgmt_suite;     /* authentication key management suite */
384         int auth_alg;
385         int txkey;
386         struct wpa_key_t key[WPA_KEY_INDEX_MAX];
387         struct scan_ext_t scan_ext;
388         struct mic_failure_t mic_failure;
389 };
390
391 #include <linux/list.h>
392 #define PMK_LIST_MAX 8
393 struct pmk_list_t {
394         uint16_t size;
395         struct list_head head;
396         struct pmk_t {
397                 struct list_head list;
398                 uint8_t bssid[ETH_ALEN];
399                 uint8_t pmkid[IW_PMKID_LEN];
400         } pmk[PMK_LIST_MAX];
401 };
402
403 #ifdef WPS
404 struct wps_status_t {
405         int wps_enabled;
406         int ielen;
407         uint8_t ie[255];
408 };
409 #endif /* WPS */
410
411 struct ks_wlan_private {
412
413         struct hw_info_t ks_wlan_hw;    /* hardware information */
414
415         struct net_device *net_dev;
416         int reg_net;    /* register_netdev */
417         struct net_device_stats nstats;
418         struct iw_statistics wstats;
419
420         struct completion confirm_wait;
421
422         /* trx device & sme */
423         struct tx_device tx_dev;
424         struct rx_device rx_dev;
425         struct sme_info sme_i;
426         u8 *rxp;
427         unsigned int rx_size;
428         struct tasklet_struct sme_task;
429         struct work_struct ks_wlan_wakeup_task;
430         int scan_ind_count;
431
432         unsigned char eth_addr[ETH_ALEN];
433
434         struct local_aplist_t aplist;
435         struct local_ap_t current_ap;
436         struct power_save_status_t psstatus;
437         struct sleep_status_t sleepstatus;
438         struct wpa_status_t wpa;
439         struct pmk_list_t pmklist;
440         /* wireless parameter */
441         struct ks_wlan_parameter reg;
442         uint8_t current_rate;
443
444         char nick[IW_ESSID_MAX_SIZE + 1];
445
446         spinlock_t multicast_spin;
447
448         spinlock_t dev_read_lock;
449         wait_queue_head_t devread_wait;
450
451         unsigned int need_commit;       /* for ioctl */
452
453         /* DeviceIoControl */
454         int device_open_status;
455         atomic_t event_count;
456         atomic_t rec_count;
457         int dev_count;
458 #define DEVICE_STOCK_COUNT 20
459         unsigned char *dev_data[DEVICE_STOCK_COUNT];
460         int dev_size[DEVICE_STOCK_COUNT];
461
462         /* ioctl : IOCTL_FIRMWARE_VERSION */
463         unsigned char firmware_version[128 + 1];
464         int version_size;
465
466         int mac_address_valid;  /* Mac Address Status */
467
468         int dev_state;
469
470         struct sk_buff *skb;
471         unsigned int cur_rx;    /* Index into the Rx buffer of next Rx pkt. */
472         /* spinlock_t lock; */
473 #define FORCE_DISCONNECT    0x80000000
474 #define CONNECT_STATUS_MASK 0x7FFFFFFF
475         uint32_t connect_status;        /* connect status */
476         int infra_status;       /* Infractructure status */
477
478         uint8_t data_buff[0x1000];
479
480         uint8_t scan_ssid_len;
481         uint8_t scan_ssid[IW_ESSID_MAX_SIZE + 1];
482         struct local_gain_t gain;
483 #ifdef WPS
484         struct net_device *l2_dev;
485         int l2_fd;
486         struct wps_status_t wps;
487 #endif /* WPS */
488         uint8_t sleep_mode;
489
490         uint8_t region;
491         struct local_eeprom_sum_t eeprom_sum;
492         uint8_t eeprom_checksum;
493
494         struct hostt_t hostt;
495
496         unsigned long last_doze;
497         unsigned long last_wakeup;
498
499         uint wakeup_count;      /* for detect wakeup loop */
500 };
501
502 extern int ks_wlan_net_start(struct net_device *dev);
503 extern int ks_wlan_net_stop(struct net_device *dev);
504
505 #endif /* _KS_WLAN_H */