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