Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / staging / ath6kl / os / linux / include / ar6000_drv.h
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2004-2010 Atheros Communications Inc.
3 // All rights reserved.
4 //
5 // 
6 //
7 // Permission to use, copy, modify, and/or distribute this software for any
8 // purpose with or without fee is hereby granted, provided that the above
9 // copyright notice and this permission notice appear in all copies.
10 //
11 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 //
19 //
20 //
21 // Author(s): ="Atheros"
22 //------------------------------------------------------------------------------
23
24 #ifndef _AR6000_H_
25 #define _AR6000_H_
26
27 #include <linux/init.h>
28 #include <linux/sched.h>
29 #include <linux/spinlock.h>
30 #include <linux/if_ether.h>
31 #include <linux/etherdevice.h>
32 #include <net/iw_handler.h>
33 #include <linux/if_arp.h>
34 #include <linux/ip.h>
35 #include <linux/wireless.h>
36 #include <net/cfg80211.h>
37 #include <linux/module.h>
38 #include <asm/io.h>
39
40 #include <a_config.h>
41 #include <athdefs.h>
42 #include "a_osapi.h"
43 #include "htc_api.h"
44 #include "wmi.h"
45 #include "a_drv.h"
46 #include "bmi.h"
47 #include <ieee80211.h>
48 #include <ieee80211_ioctl.h>
49 #include <wlan_api.h>
50 #include <wmi_api.h>
51 #include "pkt_log.h"
52 #include "aggr_recv_api.h"
53 #include <host_version.h>
54 #include <linux/rtnetlink.h>
55 #include <linux/init.h>
56 #include <linux/moduleparam.h>
57 #include "ar6000_api.h"
58 #ifdef CONFIG_HOST_TCMD_SUPPORT
59 #include <testcmd.h>
60 #endif
61 #include <linux/firmware.h>
62
63 #include "targaddrs.h"
64 #include "dbglog_api.h"
65 #include "ar6000_diag.h"
66 #include "common_drv.h"
67 #include "roaming.h"
68 #include "hci_transport_api.h"
69 #define ATH_MODULE_NAME driver
70 #include "a_debug.h"
71 #include "hw/apb_map.h"
72 #include "hw/rtc_reg.h"
73 #include "hw/mbox_reg.h"
74 #include "gpio_reg.h"
75
76 #define  ATH_DEBUG_DBG_LOG       ATH_DEBUG_MAKE_MODULE_MASK(0)
77 #define  ATH_DEBUG_WLAN_CONNECT  ATH_DEBUG_MAKE_MODULE_MASK(1)
78 #define  ATH_DEBUG_WLAN_SCAN     ATH_DEBUG_MAKE_MODULE_MASK(2)
79 #define  ATH_DEBUG_WLAN_TX       ATH_DEBUG_MAKE_MODULE_MASK(3)
80 #define  ATH_DEBUG_WLAN_RX       ATH_DEBUG_MAKE_MODULE_MASK(4)
81 #define  ATH_DEBUG_HTC_RAW       ATH_DEBUG_MAKE_MODULE_MASK(5)
82 #define  ATH_DEBUG_HCI_BRIDGE    ATH_DEBUG_MAKE_MODULE_MASK(6)
83 #define  ATH_DEBUG_HCI_RECV      ATH_DEBUG_MAKE_MODULE_MASK(7)
84 #define  ATH_DEBUG_HCI_SEND      ATH_DEBUG_MAKE_MODULE_MASK(8)
85 #define  ATH_DEBUG_HCI_DUMP      ATH_DEBUG_MAKE_MODULE_MASK(9)
86
87 #ifndef  __dev_put
88 #define  __dev_put(dev) dev_put(dev)
89 #endif
90
91
92 #define USER_SAVEDKEYS_STAT_INIT     0
93 #define USER_SAVEDKEYS_STAT_RUN      1
94
95 // TODO this needs to move into the AR_SOFTC struct
96 struct USER_SAVEDKEYS {
97     struct ieee80211req_key   ucast_ik;
98     struct ieee80211req_key   bcast_ik;
99     CRYPTO_TYPE               keyType;
100     bool                    keyOk;
101 };
102
103 #define DBG_INFO        0x00000001
104 #define DBG_ERROR       0x00000002
105 #define DBG_WARNING     0x00000004
106 #define DBG_SDIO        0x00000008
107 #define DBG_HIF         0x00000010
108 #define DBG_HTC         0x00000020
109 #define DBG_WMI         0x00000040
110 #define DBG_WMI2        0x00000080
111 #define DBG_DRIVER      0x00000100
112
113 #define DBG_DEFAULTS    (DBG_ERROR|DBG_WARNING)
114
115
116 int ar6000_ReadRegDiag(struct hif_device *hifDevice, u32 *address, u32 *data);
117 int ar6000_WriteRegDiag(struct hif_device *hifDevice, u32 *address, u32 *data);
118
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122
123 #define MAX_AR6000                        1
124 #define AR6000_MAX_RX_BUFFERS             16
125 #define AR6000_BUFFER_SIZE                1664
126 #define AR6000_MAX_AMSDU_RX_BUFFERS       4
127 #define AR6000_AMSDU_REFILL_THRESHOLD     3
128 #define AR6000_AMSDU_BUFFER_SIZE          (WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH + 128)
129 #define AR6000_MAX_RX_MESSAGE_SIZE        (max(WMI_MAX_NORMAL_RX_DATA_FRAME_LENGTH,WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH))
130
131 #define AR6000_TX_TIMEOUT                 10
132 #define AR6000_ETH_ADDR_LEN               6
133 #define AR6000_MAX_ENDPOINTS              4
134 #define MAX_NODE_NUM                      15
135 /* MAX_HI_COOKIE_NUM are reserved for high priority traffic */
136 #define MAX_DEF_COOKIE_NUM                180
137 #define MAX_HI_COOKIE_NUM                 18 /* 10% of MAX_COOKIE_NUM */
138 #define MAX_COOKIE_NUM                    (MAX_DEF_COOKIE_NUM + MAX_HI_COOKIE_NUM)
139
140 /* MAX_DEFAULT_SEND_QUEUE_DEPTH is used to set the default queue depth for the
141  * WMM send queues.  If a queue exceeds this depth htc will query back to the
142  * OS specific layer by calling EpSendFull().  This gives the OS layer the
143  * opportunity to drop the packet if desired.  Therefore changing
144  * MAX_DEFAULT_SEND_QUEUE_DEPTH does not affect resource utilization but
145  * does impact the threshold used to identify if a packet should be
146  * dropped. */
147 #define MAX_DEFAULT_SEND_QUEUE_DEPTH      (MAX_DEF_COOKIE_NUM / WMM_NUM_AC)
148
149 #define AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT        1
150 #define AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT  1
151 #define A_DISCONNECT_TIMER_INTERVAL       10 * 1000
152 #define A_DEFAULT_LISTEN_INTERVAL         100
153 #define A_MAX_WOW_LISTEN_INTERVAL         1000
154
155 enum {
156     DRV_HB_CHALLENGE = 0,
157     APP_HB_CHALLENGE
158 };
159
160 enum {
161     WLAN_INIT_MODE_NONE = 0,
162     WLAN_INIT_MODE_USR,
163     WLAN_INIT_MODE_UDEV,
164     WLAN_INIT_MODE_DRV
165 };
166
167 /* Suspend - configuration */
168 enum {
169     WLAN_SUSPEND_CUT_PWR = 0,
170     WLAN_SUSPEND_DEEP_SLEEP,
171     WLAN_SUSPEND_WOW,
172     WLAN_SUSPEND_CUT_PWR_IF_BT_OFF
173 };
174
175 /* WiFi OFF - configuration */
176 enum {
177     WLAN_OFF_CUT_PWR = 0,
178     WLAN_OFF_DEEP_SLEEP,
179 };
180
181 /* WLAN low power state */
182 enum {
183     WLAN_POWER_STATE_ON = 0,
184     WLAN_POWER_STATE_CUT_PWR = 1,
185     WLAN_POWER_STATE_DEEP_SLEEP,
186     WLAN_POWER_STATE_WOW
187 };
188
189 /* WLAN WoW State */
190 enum {
191     WLAN_WOW_STATE_NONE = 0,
192     WLAN_WOW_STATE_SUSPENDED,
193     WLAN_WOW_STATE_SUSPENDING
194 };
195
196
197 typedef enum _AR6K_BIN_FILE {
198     AR6K_OTP_FILE,
199     AR6K_FIRMWARE_FILE,
200     AR6K_PATCH_FILE,
201     AR6K_BOARD_DATA_FILE,
202 } AR6K_BIN_FILE;
203
204 #ifdef SETUPHCI_ENABLED
205 #define SETUPHCI_DEFAULT           1
206 #else
207 #define SETUPHCI_DEFAULT           0
208 #endif /* SETUPHCI_ENABLED */
209
210 #ifdef SETUPBTDEV_ENABLED
211 #define SETUPBTDEV_DEFAULT         1
212 #else
213 #define SETUPBTDEV_DEFAULT         0
214 #endif /* SETUPBTDEV_ENABLED */
215
216 #ifdef ENABLEUARTPRINT_SET
217 #define ENABLEUARTPRINT_DEFAULT    1
218 #else
219 #define ENABLEUARTPRINT_DEFAULT    0
220 #endif /* ENABLEARTPRINT_SET */
221
222 #ifdef ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER
223 #define NOHIFSCATTERSUPPORT_DEFAULT    1
224 #else /* ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER */
225 #define NOHIFSCATTERSUPPORT_DEFAULT    0
226 #endif /* ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER */
227
228
229 #if defined(CONFIG_ATH6KL_ENABLE_COEXISTENCE)
230
231 #ifdef CONFIG_AR600x_BT_QCOM
232 #define ATH6KL_BT_DEV 1
233 #elif defined(CONFIG_AR600x_BT_CSR)
234 #define ATH6KL_BT_DEV 2
235 #else
236 #define ATH6KL_BT_DEV 3
237 #endif
238
239 #ifdef CONFIG_AR600x_DUAL_ANTENNA
240 #define ATH6KL_BT_ANTENNA 2
241 #else
242 #define ATH6KL_BT_ANTENNA 1
243 #endif
244
245 #endif /* CONFIG_ATH6KL_ENABLE_COEXISTENCE */
246
247 #ifdef AR600x_BT_AR3001
248 #define AR3KHCIBAUD_DEFAULT        3000000
249 #define HCIUARTSCALE_DEFAULT       1
250 #define HCIUARTSTEP_DEFAULT        8937
251 #else
252 #define AR3KHCIBAUD_DEFAULT        0
253 #define HCIUARTSCALE_DEFAULT       0
254 #define HCIUARTSTEP_DEFAULT        0
255 #endif /* AR600x_BT_AR3001 */
256
257 #define WLAN_INIT_MODE_DEFAULT     WLAN_INIT_MODE_DRV
258
259 #define AR6K_PATCH_DOWNLOAD_ADDRESS(_param, _ver) do { \
260     if ((_ver) == AR6003_REV1_VERSION) { \
261         (_param) = AR6003_REV1_PATCH_DOWNLOAD_ADDRESS; \
262     } else if ((_ver) == AR6003_REV2_VERSION) { \
263         (_param) = AR6003_REV2_PATCH_DOWNLOAD_ADDRESS; \
264     } else { \
265        AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \
266        A_ASSERT(0); \
267     } \
268 } while (0)
269
270 #define AR6K_DATA_DOWNLOAD_ADDRESS(_param, _ver) do { \
271     if ((_ver) == AR6003_REV1_VERSION) { \
272         (_param) = AR6003_REV1_DATA_DOWNLOAD_ADDRESS; \
273     } else if ((_ver) == AR6003_REV2_VERSION) { \
274         (_param) = AR6003_REV2_DATA_DOWNLOAD_ADDRESS; \
275     } else { \
276        AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \
277        A_ASSERT(0); \
278     } \
279 } while (0)
280
281 #define AR6K_DATASET_PATCH_ADDRESS(_param, _ver) do { \
282         if ((_ver) == AR6003_REV2_VERSION) { \
283                 (_param) = AR6003_REV2_DATASET_PATCH_ADDRESS; \
284         } else if ((_ver) == AR6003_REV3_VERSION) { \
285                 (_param) = AR6003_REV3_DATASET_PATCH_ADDRESS; \
286         } else { \
287         AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \
288         A_ASSERT(0); \
289         } \
290 } while (0)
291
292 #define AR6K_APP_LOAD_ADDRESS(_param, _ver) do { \
293         if ((_ver) == AR6003_REV2_VERSION) { \
294                 (_param) = AR6003_REV2_APP_LOAD_ADDRESS; \
295         } else if ((_ver) == AR6003_REV3_VERSION) { \
296                 (_param) = AR6003_REV3_APP_LOAD_ADDRESS; \
297         } else { \
298         AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \
299         A_ASSERT(0); \
300         } \
301 } while (0)
302
303 #define AR6K_APP_START_OVERRIDE_ADDRESS(_param, _ver) do { \
304         if ((_ver) == AR6003_REV2_VERSION) { \
305                 (_param) = AR6003_REV2_APP_START_OVERRIDE; \
306         } else if ((_ver) == AR6003_REV3_VERSION) { \
307                 (_param) = AR6003_REV3_APP_START_OVERRIDE; \
308         } else { \
309         AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \
310         A_ASSERT(0); \
311         } \
312 } while (0)
313
314 /* AR6003 1.0 definitions */
315 #define AR6003_REV1_VERSION                 0x300002ba
316 #define AR6003_REV1_DATA_DOWNLOAD_ADDRESS   AR6003_REV1_OTP_DATA_ADDRESS
317 #define AR6003_REV1_PATCH_DOWNLOAD_ADDRESS  0x57ea6c
318 #define AR6003_REV1_OTP_FILE                "ath6k/AR6003/hw1.0/otp.bin.z77"
319 #define AR6003_REV1_FIRMWARE_FILE           "ath6k/AR6003/hw1.0/athwlan.bin.z77"
320 #define AR6003_REV1_TCMD_FIRMWARE_FILE      "ath6k/AR6003/hw1.0/athtcmd_ram.bin"
321 #define AR6003_REV1_ART_FIRMWARE_FILE       "ath6k/AR6003/hw1.0/device.bin"
322 #define AR6003_REV1_PATCH_FILE              "ath6k/AR6003/hw1.0/data.patch.bin"
323 #define AR6003_REV1_EPPING_FIRMWARE_FILE    "ath6k/AR6003/hw1.0/endpointping.bin"
324 #ifdef CONFIG_AR600x_SD31_XXX
325 #define AR6003_REV1_BOARD_DATA_FILE         "ath6k/AR6003/hw1.0/bdata.SD31.bin"
326 #elif defined(CONFIG_AR600x_SD32_XXX)
327 #define AR6003_REV1_BOARD_DATA_FILE         "ath6k/AR6003/hw1.0/bdata.SD32.bin"
328 #elif defined(CONFIG_AR600x_WB31_XXX)
329 #define AR6003_REV1_BOARD_DATA_FILE         "ath6k/AR6003/hw1.0/bdata.WB31.bin"
330 #else
331 #define AR6003_REV1_BOARD_DATA_FILE         "ath6k/AR6003/hw1.0/bdata.CUSTOM.bin"
332 #endif /* Board Data File */
333
334 /* AR6003 2.0 definitions */
335 #define AR6003_REV2_VERSION                 0x30000384 
336 #define AR6003_REV2_DATA_DOWNLOAD_ADDRESS   AR6003_REV2_OTP_DATA_ADDRESS
337 #define AR6003_REV2_PATCH_DOWNLOAD_ADDRESS  0x57e910
338 #define AR6003_REV2_OTP_FILE                "ath6k/AR6003/hw2.0/otp.bin.z77"
339 #define AR6003_REV2_FIRMWARE_FILE           "ath6k/AR6003/hw2.0/athwlan.bin.z77"
340 #define AR6003_REV2_TCMD_FIRMWARE_FILE      "ath6k/AR6003/hw2.0/athtcmd_ram.bin"
341 #define AR6003_REV2_ART_FIRMWARE_FILE       "ath6k/AR6003/hw2.0/device.bin"
342 #define AR6003_REV2_PATCH_FILE              "ath6k/AR6003/hw2.0/data.patch.bin"
343 #define AR6003_REV2_EPPING_FIRMWARE_FILE    "ath6k/AR6003/hw2.0/endpointping.bin"
344 #ifdef CONFIG_AR600x_SD31_XXX
345 #define AR6003_REV2_BOARD_DATA_FILE         "ath6k/AR6003/hw2.0/bdata.SD31.bin"
346 #elif defined(CONFIG_AR600x_SD32_XXX)
347 #define AR6003_REV2_BOARD_DATA_FILE         "ath6k/AR6003/hw2.0/bdata.SD32.bin"
348 #elif defined(CONFIG_AR600x_WB31_XXX)
349 #define AR6003_REV2_BOARD_DATA_FILE         "ath6k/AR6003/hw2.0/bdata.WB31.bin"
350 #else
351 #define AR6003_REV2_BOARD_DATA_FILE         "ath6k/AR6003/hw2.0/bdata.CUSTOM.bin"
352 #endif /* Board Data File */
353
354 /* AR6003 3.0 definitions */
355 #define AR6003_REV3_VERSION                 0x30000582
356 #define AR6003_REV3_OTP_FILE                "ath6k/AR6003/hw2.1.1/otp.bin"
357 #define AR6003_REV3_FIRMWARE_FILE           "ath6k/AR6003/hw2.1.1/athwlan.bin"
358 #define AR6003_REV3_TCMD_FIRMWARE_FILE    "ath6k/AR6003/hw2.1.1/athtcmd_ram.bin"
359 #define AR6003_REV3_ART_FIRMWARE_FILE       "ath6k/AR6003/hw2.1.1/device.bin"
360 #define AR6003_REV3_PATCH_FILE            "ath6k/AR6003/hw2.1.1/data.patch.bin"
361 #define AR6003_REV3_EPPING_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/endpointping.bin"
362 #ifdef CONFIG_AR600x_SD31_XXX
363 #define AR6003_REV3_BOARD_DATA_FILE       "ath6k/AR6003/hw2.1.1/bdata.SD31.bin"
364 #elif defined(CONFIG_AR600x_SD32_XXX)
365 #define AR6003_REV3_BOARD_DATA_FILE        "ath6k/AR6003/hw2.1.1/bdata.SD32.bin"
366 #elif defined(CONFIG_AR600x_WB31_XXX)
367 #define AR6003_REV3_BOARD_DATA_FILE        "ath6k/AR6003/hw2.1.1/bdata.WB31.bin"
368 #else
369 #define AR6003_REV3_BOARD_DATA_FILE      "ath6k/AR6003/hw2.1.1/bdata.CUSTOM.bin"
370 #endif /* Board Data File */
371
372
373 /* Power states */
374 enum {
375     WLAN_PWR_CTRL_UP = 0,
376     WLAN_PWR_CTRL_CUT_PWR,
377     WLAN_PWR_CTRL_DEEP_SLEEP,
378     WLAN_PWR_CTRL_WOW,
379     WLAN_PWR_CTRL_DEEP_SLEEP_DISABLED
380 };
381
382 /* HTC RAW streams */
383 typedef enum _HTC_RAW_STREAM_ID {
384     HTC_RAW_STREAM_NOT_MAPPED = -1,
385     HTC_RAW_STREAM_0 = 0,
386     HTC_RAW_STREAM_1 = 1,
387     HTC_RAW_STREAM_2 = 2,
388     HTC_RAW_STREAM_3 = 3,
389     HTC_RAW_STREAM_NUM_MAX
390 } HTC_RAW_STREAM_ID;
391
392 #define RAW_HTC_READ_BUFFERS_NUM    4
393 #define RAW_HTC_WRITE_BUFFERS_NUM   4
394
395 #define HTC_RAW_BUFFER_SIZE  1664
396
397 typedef struct {
398     int currPtr;
399     int length;
400     unsigned char data[HTC_RAW_BUFFER_SIZE];
401     struct htc_packet    HTCPacket;
402 } raw_htc_buffer;
403
404 #ifdef CONFIG_HOST_TCMD_SUPPORT
405 /*
406  *  add TCMD_MODE besides wmi and bypasswmi
407  *  in TCMD_MODE, only few TCMD releated wmi commands
408  *  counld be hanlder
409  */
410 enum {
411     AR6000_WMI_MODE = 0,
412     AR6000_BYPASS_MODE,
413     AR6000_TCMD_MODE,
414     AR6000_WLAN_MODE
415 };
416 #endif /* CONFIG_HOST_TCMD_SUPPORT */
417
418 struct ar_wep_key {
419     u8 arKeyIndex;
420     u8 arKeyLen;
421     u8 arKey[64];
422 } ;
423
424 struct ar_key {
425     u8 key[WLAN_MAX_KEY_LEN];
426     u8 key_len;
427     u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
428     u8 seq_len;
429     u32 cipher;
430 };
431
432 enum {
433     SME_DISCONNECTED,
434     SME_CONNECTING,
435     SME_CONNECTED
436 };
437
438 struct ar_node_mapping {
439     u8 macAddress[6];
440     u8 epId;
441     u8 txPending;
442 };
443
444 struct ar_cookie {
445     unsigned long          arc_bp[2];    /* Must be first field */
446     struct htc_packet             HtcPkt;       /* HTC packet wrapper */
447     struct ar_cookie *arc_list_next;
448 };
449
450 struct ar_hb_chlng_resp {
451     A_TIMER                 timer;
452     u32 frequency;
453     u32 seqNum;
454     bool                  outstanding;
455     u8 missCnt;
456     u8 missThres;
457 };
458
459 /* Per STA data, used in AP mode */
460 /*TODO: All this should move to OS independent dir */
461
462 #define STA_PWR_MGMT_MASK 0x1
463 #define STA_PWR_MGMT_SHIFT 0x0
464 #define STA_PWR_MGMT_AWAKE 0x0
465 #define STA_PWR_MGMT_SLEEP 0x1
466
467 #define STA_SET_PWR_SLEEP(sta) (sta->flags |= (STA_PWR_MGMT_MASK << STA_PWR_MGMT_SHIFT))
468 #define STA_CLR_PWR_SLEEP(sta) (sta->flags &= ~(STA_PWR_MGMT_MASK << STA_PWR_MGMT_SHIFT))
469 #define STA_IS_PWR_SLEEP(sta) ((sta->flags >> STA_PWR_MGMT_SHIFT) & STA_PWR_MGMT_MASK)
470
471 #define STA_PS_POLLED_MASK 0x1
472 #define STA_PS_POLLED_SHIFT 0x1
473 #define STA_SET_PS_POLLED(sta) (sta->flags |= (STA_PS_POLLED_MASK << STA_PS_POLLED_SHIFT))
474 #define STA_CLR_PS_POLLED(sta) (sta->flags &= ~(STA_PS_POLLED_MASK << STA_PS_POLLED_SHIFT))
475 #define STA_IS_PS_POLLED(sta) (sta->flags & (STA_PS_POLLED_MASK << STA_PS_POLLED_SHIFT))
476
477 typedef struct {
478     u16 flags;
479     u8 mac[ATH_MAC_LEN];
480     u8 aid;
481     u8 keymgmt;
482     u8 ucipher;
483     u8 auth;
484     u8 wpa_ie[IEEE80211_MAX_IE];
485     A_NETBUF_QUEUE_T        psq;    /* power save q */
486     A_MUTEX_T               psqLock;
487 } sta_t;
488
489 typedef struct ar6_raw_htc {
490     HTC_ENDPOINT_ID         arRaw2EpMapping[HTC_RAW_STREAM_NUM_MAX];
491     HTC_RAW_STREAM_ID       arEp2RawMapping[ENDPOINT_MAX];
492     struct semaphore        raw_htc_read_sem[HTC_RAW_STREAM_NUM_MAX];
493     struct semaphore        raw_htc_write_sem[HTC_RAW_STREAM_NUM_MAX];
494     wait_queue_head_t       raw_htc_read_queue[HTC_RAW_STREAM_NUM_MAX];
495     wait_queue_head_t       raw_htc_write_queue[HTC_RAW_STREAM_NUM_MAX];
496     raw_htc_buffer          raw_htc_read_buffer[HTC_RAW_STREAM_NUM_MAX][RAW_HTC_READ_BUFFERS_NUM];
497     raw_htc_buffer          raw_htc_write_buffer[HTC_RAW_STREAM_NUM_MAX][RAW_HTC_WRITE_BUFFERS_NUM];
498     bool                  write_buffer_available[HTC_RAW_STREAM_NUM_MAX];
499     bool                  read_buffer_available[HTC_RAW_STREAM_NUM_MAX];
500 } AR_RAW_HTC_T;
501
502 struct ar6_softc {
503     struct net_device       *arNetDev;    /* net_device pointer */
504     void                    *arWmi;
505     int                     arTxPending[ENDPOINT_MAX];
506     int                     arTotalTxDataPending;
507     u8 arNumDataEndPts;
508     bool                  arWmiEnabled;
509     bool                  arWmiReady;
510     bool                  arConnected;
511     HTC_HANDLE              arHtcTarget;
512     void                    *arHifDevice;
513     spinlock_t              arLock;
514     struct semaphore        arSem;
515     int                     arSsidLen;
516     u_char                  arSsid[32];
517     u8 arNextMode;
518     u8 arNetworkType;
519     u8 arDot11AuthMode;
520     u8 arAuthMode;
521     u8 arPairwiseCrypto;
522     u8 arPairwiseCryptoLen;
523     u8 arGroupCrypto;
524     u8 arGroupCryptoLen;
525     u8 arDefTxKeyIndex;
526     struct ar_wep_key       arWepKeyList[WMI_MAX_KEY_INDEX + 1];
527     u8 arBssid[6];
528     u8 arReqBssid[6];
529     u16 arChannelHint;
530     u16 arBssChannel;
531     u16 arListenIntervalB;
532     u16 arListenIntervalT;
533     struct ar6000_version   arVersion;
534     u32 arTargetType;
535     s8 arRssi;
536     u8 arTxPwr;
537     bool                  arTxPwrSet;
538     s32 arBitRate;
539     struct net_device_stats arNetStats;
540     struct iw_statistics    arIwStats;
541     s8 arNumChannels;
542     u16 arChannelList[32];
543     u32 arRegCode;
544     bool                  statsUpdatePending;
545     TARGET_STATS            arTargetStats;
546     s8 arMaxRetries;
547     u8 arPhyCapability;
548 #ifdef CONFIG_HOST_TCMD_SUPPORT
549     u8 tcmdRxReport;
550     u32 tcmdRxTotalPkt;
551     s32 tcmdRxRssi;
552     u32 tcmdPm;
553     u32 arTargetMode;
554     u32 tcmdRxcrcErrPkt;
555     u32 tcmdRxsecErrPkt;
556     u16 tcmdRateCnt[TCMD_MAX_RATES];
557     u16 tcmdRateCntShortGuard[TCMD_MAX_RATES];
558 #endif
559     AR6000_WLAN_STATE       arWlanState;
560     struct ar_node_mapping  arNodeMap[MAX_NODE_NUM];
561     u8 arIbssPsEnable;
562     u8 arNodeNum;
563     u8 arNexEpId;
564     struct ar_cookie        *arCookieList;
565     u32 arCookieCount;
566     u32 arRateMask;
567     u8 arSkipScan;
568     u16 arBeaconInterval;
569     bool                  arConnectPending;
570     bool                  arWmmEnabled;
571     struct ar_hb_chlng_resp arHBChallengeResp;
572     u8 arKeepaliveConfigured;
573     u32 arMgmtFilter;
574     HTC_ENDPOINT_ID         arAc2EpMapping[WMM_NUM_AC];
575     bool                  arAcStreamActive[WMM_NUM_AC];
576     u8 arAcStreamPriMap[WMM_NUM_AC];
577     u8 arHiAcStreamActivePri;
578     u8 arEp2AcMapping[ENDPOINT_MAX];
579     HTC_ENDPOINT_ID         arControlEp;
580 #ifdef HTC_RAW_INTERFACE
581     AR_RAW_HTC_T            *arRawHtc;
582 #endif
583     bool                  arNetQueueStopped;
584     bool                  arRawIfInit;
585     int                     arDeviceIndex;
586     struct common_credit_state_info arCreditStateInfo;
587     bool                  arWMIControlEpFull;
588     bool                  dbgLogFetchInProgress;
589     u8                 log_buffer[DBGLOG_HOST_LOG_BUFFER_SIZE];
590     u32 log_cnt;
591     u32 dbglog_init_done;
592     u32 arConnectCtrlFlags;
593     s32 user_savedkeys_stat;
594     u32 user_key_ctrl;
595     struct USER_SAVEDKEYS   user_saved_keys;
596     USER_RSSI_THOLD rssi_map[12];
597     u8 arUserBssFilter;
598     u16 ap_profile_flag;    /* AP mode */
599     WMI_AP_ACL              g_acl;              /* AP mode */
600     sta_t                   sta_list[AP_MAX_NUM_STA]; /* AP mode */
601     u8 sta_list_index;     /* AP mode */
602     struct ieee80211req_key ap_mode_bkey;           /* AP mode */
603     A_NETBUF_QUEUE_T        mcastpsq;    /* power save q for Mcast frames */
604     A_MUTEX_T               mcastpsqLock;
605     bool                  DTIMExpired; /* flag to indicate DTIM expired */
606     u8 intra_bss;   /* enable/disable intra bss data forward */
607     void                    *aggr_cntxt;
608 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
609     void                    *hcidev_info;
610 #endif
611     WMI_AP_MODE_STAT        arAPStats;
612     u8 ap_hidden_ssid;
613     u8 ap_country_code[3];
614     u8 ap_wmode;
615     u8 ap_dtim_period;
616     u16 ap_beacon_interval;
617     u16 arRTS;
618     u16 arACS; /* AP mode - Auto Channel Selection */
619     struct htc_packet_queue        amsdu_rx_buffer_queue;
620     bool                  bIsDestroyProgress; /* flag to indicate ar6k destroy is in progress */
621     A_TIMER                 disconnect_timer;
622     u8 rxMetaVersion;
623 #ifdef WAPI_ENABLE
624     u8 arWapiEnable;
625 #endif
626         WMI_BTCOEX_CONFIG_EVENT arBtcoexConfig;
627         WMI_BTCOEX_STATS_EVENT  arBtcoexStats;
628     s32 (*exitCallback)(void *config);  /* generic callback at AR6K exit */
629     struct hif_device_os_device_info   osDevInfo;
630     struct wireless_dev *wdev;
631     struct cfg80211_scan_request    *scan_request;
632     struct ar_key   keys[WMI_MAX_KEY_INDEX + 1];
633     u32 smeState;
634     u16 arWlanPowerState;
635     bool                  arWlanOff;
636 #ifdef CONFIG_PM
637     u16 arWowState;
638     bool                  arBTOff;
639     bool                  arBTSharing;
640     u16 arSuspendConfig;
641     u16 arWlanOffConfig;
642     u16 arWow2Config;
643 #endif
644     u8 scan_triggered;
645     WMI_SCAN_PARAMS_CMD     scParams;
646 #define AR_MCAST_FILTER_MAC_ADDR_SIZE  4
647     u8 mcast_filters[MAC_MAX_FILTERS_PER_LIST][AR_MCAST_FILTER_MAC_ADDR_SIZE];
648     u8 bdaddr[6];
649     bool                  scanSpecificSsid;
650 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
651     void                    *arApDev;
652 #endif
653     u8 arAutoAuthStage;
654 };
655
656 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
657 struct ar_virtual_interface {
658     struct net_device       *arNetDev;    /* net_device pointer */
659     struct ar6_softc              *arDev;       /* ar device pointer */
660     struct net_device       *arStaNetDev; /* net_device pointer */
661 };
662 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
663
664 static inline void *ar6k_priv(struct net_device *dev)
665 {
666     return (wdev_priv(dev->ieee80211_ptr));
667 }
668
669 #define SET_HCI_BUS_TYPE(pHciDev, __bus, __type) do { \
670     (pHciDev)->bus = (__bus); \
671     (pHciDev)->dev_type = (__type); \
672 } while(0)
673
674 #define GET_INODE_FROM_FILEP(filp) \
675     (filp)->f_path.dentry->d_inode
676
677 #define arAc2EndpointID(ar,ac)          (ar)->arAc2EpMapping[(ac)]
678 #define arSetAc2EndpointIDMap(ar,ac,ep)  \
679 {  (ar)->arAc2EpMapping[(ac)] = (ep); \
680    (ar)->arEp2AcMapping[(ep)] = (ac); }
681 #define arEndpoint2Ac(ar,ep)           (ar)->arEp2AcMapping[(ep)]
682
683 #define arRawIfEnabled(ar) (ar)->arRawIfInit
684 #define arRawStream2EndpointID(ar,raw)          (ar)->arRawHtc->arRaw2EpMapping[(raw)]
685 #define arSetRawStream2EndpointIDMap(ar,raw,ep)  \
686 {  (ar)->arRawHtc->arRaw2EpMapping[(raw)] = (ep); \
687    (ar)->arRawHtc->arEp2RawMapping[(ep)] = (raw); }
688 #define arEndpoint2RawStreamID(ar,ep)           (ar)->arRawHtc->arEp2RawMapping[(ep)]
689
690 struct ar_giwscan_param {
691     char *current_ev;
692     char *end_buf;
693     u32 bytes_needed;
694     struct iw_request_info *info;
695 };
696
697 #define AR6000_STAT_INC(ar, stat)       (ar->arNetStats.stat++)
698
699 #define AR6000_SPIN_LOCK(lock, param)   do {                            \
700     if (irqs_disabled()) {                                              \
701         AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("IRQs disabled:AR6000_LOCK\n"));                 \
702     }                                                                   \
703     spin_lock_bh(lock);                                                 \
704 } while (0)
705
706 #define AR6000_SPIN_UNLOCK(lock, param) do {                            \
707     if (irqs_disabled()) {                                              \
708         AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("IRQs disabled: AR6000_UNLOCK\n"));              \
709     }                                                                   \
710     spin_unlock_bh(lock);                                               \
711 } while (0)
712
713 void ar6000_init_profile_info(struct ar6_softc *ar);
714 void ar6000_install_static_wep_keys(struct ar6_softc *ar);
715 int ar6000_init(struct net_device *dev);
716 int ar6000_dbglog_get_debug_logs(struct ar6_softc *ar);
717 void ar6000_TxDataCleanup(struct ar6_softc *ar);
718 int ar6000_acl_data_tx(struct sk_buff *skb, struct net_device *dev);
719 void ar6000_restart_endpoint(struct net_device *dev);
720 void ar6000_stop_endpoint(struct net_device *dev, bool keepprofile, bool getdbglogs);
721
722 #ifdef HTC_RAW_INTERFACE
723
724 #ifndef __user
725 #define __user
726 #endif
727
728 int ar6000_htc_raw_open(struct ar6_softc *ar);
729 int ar6000_htc_raw_close(struct ar6_softc *ar);
730 ssize_t ar6000_htc_raw_read(struct ar6_softc *ar,
731                             HTC_RAW_STREAM_ID StreamID,
732                             char __user *buffer, size_t count);
733 ssize_t ar6000_htc_raw_write(struct ar6_softc *ar,
734                              HTC_RAW_STREAM_ID StreamID,
735                              char __user *buffer, size_t count);
736
737 #endif /* HTC_RAW_INTERFACE */
738
739 /* AP mode */
740 /*TODO: These routines should be moved to a file that is common across OS */
741 sta_t *
742 ieee80211_find_conn(struct ar6_softc *ar, u8 *node_addr);
743
744 sta_t *
745 ieee80211_find_conn_for_aid(struct ar6_softc *ar, u8 aid);
746
747 u8 remove_sta(struct ar6_softc *ar, u8 *mac, u16 reason);
748
749 /* HCI support */
750
751 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
752 int ar6000_setup_hci(struct ar6_softc *ar);
753 void     ar6000_cleanup_hci(struct ar6_softc *ar);
754 void     ar6000_set_default_ar3kconfig(struct ar6_softc *ar, void *ar3kconfig);
755
756 /* HCI bridge testing */
757 int hci_test_send(struct ar6_softc *ar, struct sk_buff *skb);
758 #endif
759
760 ATH_DEBUG_DECLARE_EXTERN(htc);
761 ATH_DEBUG_DECLARE_EXTERN(wmi);
762 ATH_DEBUG_DECLARE_EXTERN(bmi);
763 ATH_DEBUG_DECLARE_EXTERN(hif);
764 ATH_DEBUG_DECLARE_EXTERN(wlan);
765 ATH_DEBUG_DECLARE_EXTERN(misc);
766
767 extern u8 bcast_mac[];
768 extern u8 null_mac[];
769
770 #ifdef __cplusplus
771 }
772 #endif
773
774 #endif /* _AR6000_H_ */