Add ar6000 wireless driver.
[kernel.git] / drivers / ar6000 / ar6000 / ar6000_drv.h
1 /*
2  *
3  * Copyright (c) 2004-2007 Atheros Communications Inc.
4  * All rights reserved.
5  *
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  *  Software distributed under the License is distributed on an "AS
12  *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13  *  implied. See the License for the specific language governing
14  *  rights and limitations under the License.
15  *
16  *
17  *
18  */
19
20 #ifndef _AR6000_H_
21 #define _AR6000_H_
22
23 #include <linux/version.h>
24
25
26 #include <generated/autoconf.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/spinlock.h>
30 #include <linux/skbuff.h>
31 #include <linux/if_ether.h>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
34 #include <net/iw_handler.h>
35 #include <linux/if_arp.h>
36 #include <linux/ip.h>
37 #include <linux/semaphore.h>
38 #include <linux/wireless.h>
39 #include <linux/module.h>
40 #include <linux/sched.h>
41 #include <asm/io.h>
42
43 #include <a_config.h>
44 #include <athdefs.h>
45 #include "a_types.h"
46 #include "a_osapi.h"
47 #include "htc_api.h"
48 #include "wmi.h"
49 #include "a_drv.h"
50 #include "bmi.h"
51 #include <ieee80211.h>
52 #include <ieee80211_ioctl.h>
53 #include <wlan_api.h>
54 #include <wmi_api.h>
55 #include "gpio_api.h"
56 #include "gpio.h"
57 #include <host_version.h>
58 #include <linux/rtnetlink.h>
59 #include <linux/init.h>
60 #include <linux/moduleparam.h>
61 #include "AR6Khwreg.h"
62 #include "ar6000_api.h"
63 #ifdef CONFIG_HOST_TCMD_SUPPORT
64 #include <testcmd.h>
65 #endif
66
67 #include "targaddrs.h"
68 #include "dbglog_api.h"
69 #include "ar6000_diag.h"
70 #include "common_drv.h"
71
72 #ifndef  __dev_put
73 #define  __dev_put(dev) dev_put(dev)
74 #endif
75
76 #ifdef USER_KEYS
77
78 #define USER_SAVEDKEYS_STAT_INIT     0
79 #define USER_SAVEDKEYS_STAT_RUN      1
80
81 // TODO this needs to move into the AR_SOFTC struct
82 struct USER_SAVEDKEYS {
83     struct ieee80211req_key   ucast_ik;
84     struct ieee80211req_key   bcast_ik;
85     CRYPTO_TYPE               keyType;
86     A_BOOL                    keyOk;
87 };
88 #endif
89
90 #define DBG_INFO                0x00000001
91 #define DBG_ERROR               0x00000002
92 #define DBG_WARNING             0x00000004
93 #define DBG_SDIO                0x00000008
94 #define DBG_HIF                 0x00000010
95 #define DBG_HTC                 0x00000020
96 #define DBG_WMI                 0x00000040
97 #define DBG_WMI2                0x00000080
98 #define DBG_DRIVER              0x00000100
99
100 #define DBG_DEFAULTS    (DBG_ERROR|DBG_WARNING)
101
102
103 #ifdef DEBUG
104 #define AR_DEBUG_PRINTF(args...)        if (debugdriver) A_PRINTF(args);
105 #define AR_DEBUG2_PRINTF(args...)        if (debugdriver >= 2) A_PRINTF(args);
106 extern int debugdriver;
107 #else
108 #define AR_DEBUG_PRINTF(args...)
109 #define AR_DEBUG2_PRINTF(args...)
110 #endif
111
112 A_STATUS ar6000_ReadRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data);
113 A_STATUS ar6000_WriteRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data);
114
115 #ifdef __cplusplus
116 extern "C" {
117 #endif
118
119 #define MAX_AR6000                        1
120 #define AR6000_MAX_RX_BUFFERS             16
121 #define AR6000_BUFFER_SIZE                1664
122 #define AR6000_TX_TIMEOUT                 10
123 #define AR6000_ETH_ADDR_LEN               6
124 #define AR6000_MAX_ENDPOINTS              4
125 #define MAX_NODE_NUM                      15
126 #define MAX_COOKIE_NUM                    150
127 #define AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT        1
128 #define AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT  1
129
130 enum {
131     DRV_HB_CHALLENGE = 0,
132     APP_HB_CHALLENGE
133 };
134
135 /* HTC RAW streams */
136 typedef enum _HTC_RAW_STREAM_ID {
137     HTC_RAW_STREAM_NOT_MAPPED = -1,
138     HTC_RAW_STREAM_0 = 0,
139     HTC_RAW_STREAM_1 = 1,
140     HTC_RAW_STREAM_2 = 2,
141     HTC_RAW_STREAM_3 = 3,
142     HTC_RAW_STREAM_NUM_MAX
143 } HTC_RAW_STREAM_ID;
144
145 #define RAW_HTC_READ_BUFFERS_NUM    4
146 #define RAW_HTC_WRITE_BUFFERS_NUM   4
147
148 typedef struct {
149     int currPtr;
150     int length;
151     unsigned char data[AR6000_BUFFER_SIZE];
152     HTC_PACKET    HTCPacket;
153 } raw_htc_buffer;
154
155 #ifdef CONFIG_HOST_TCMD_SUPPORT
156 /*
157  *  add TCMD_MODE besides wmi and bypasswmi
158  *  in TCMD_MODE, only few TCMD releated wmi commands
159  *  counld be hanlder
160  */
161 enum {
162     AR6000_WMI_MODE = 0,
163     AR6000_BYPASS_MODE,
164     AR6000_TCMD_MODE,
165     AR6000_WLAN_MODE
166 };
167 #endif /* CONFIG_HOST_TCMD_SUPPORT */
168
169 struct ar_wep_key {
170     A_UINT8                 arKeyIndex;
171     A_UINT8                 arKeyLen;
172     A_UINT8                 arKey[64];
173 } ;
174
175 struct ar_node_mapping {
176     A_UINT8                 macAddress[6];
177     A_UINT8                 epId;
178     A_UINT8                 txPending;
179 };
180
181 struct ar_cookie {
182     A_UINT32               arc_bp[2];    /* Must be first field */
183     HTC_PACKET             HtcPkt;       /* HTC packet wrapper */
184     struct ar_cookie *arc_list_next;
185 };
186
187 struct ar_hb_chlng_resp {
188     A_TIMER                 timer;
189     A_UINT32                frequency;
190     A_UINT32                seqNum;
191     A_BOOL                  outstanding;
192     A_UINT8                 missCnt;
193     A_UINT8                 missThres;
194 };
195
196 typedef struct ar6_softc {
197     struct net_device       *arNetDev;    /* net_device pointer */
198     void                    *arWmi;
199     int                     arTxPending[WMI_PRI_MAX_COUNT];
200     int                     arTotalTxDataPending;
201     A_UINT8                 arNumDataEndPts;
202     A_BOOL                  arWmiEnabled;
203     A_BOOL                  arWmiReady;
204     A_BOOL                  arConnected;
205     A_BOOL                  arRadioSwitch;
206     HTC_HANDLE              arHtcTarget;
207     void                    *arHifDevice;
208     spinlock_t              arLock;
209     struct semaphore        arSem;
210     int                     arRxBuffers[WMI_PRI_MAX_COUNT];
211     int                     arSsidLen;
212     u_char                  arSsid[32];
213     A_UINT8                 arNetworkType;
214     A_UINT8                 arDot11AuthMode;
215     A_UINT8                 arAuthMode;
216     A_UINT8                 arPairwiseCrypto;
217     A_UINT8                 arPairwiseCryptoLen;
218     A_UINT8                 arGroupCrypto;
219     A_UINT8                 arGroupCryptoLen;
220     A_UINT8                 arDefTxKeyIndex;
221     struct ar_wep_key       arWepKeyList[WMI_MAX_KEY_INDEX + 1];
222     A_UINT8                 arBssid[6];
223     A_UINT8                 arReqBssid[6];
224     A_UINT16                arChannelHint;
225     A_UINT16                arBssChannel;
226     A_UINT16                arListenInterval;
227     struct ar6000_version   arVersion;
228     A_UINT32                arTargetType;
229     A_INT8                  arRssi;
230     A_UINT8                 arTxPwr;
231     A_BOOL                  arTxPwrSet;
232     A_INT32                 arBitRate;
233     struct net_device_stats arNetStats;
234     struct iw_statistics        arIwStats;
235     A_INT8                  arNumChannels;
236     A_UINT16                arChannelList[32];
237     A_UINT32                arRegCode;
238     A_BOOL                  statsUpdatePending;
239     TARGET_STATS            arTargetStats;
240     A_INT8                  arMaxRetries;
241     A_UINT8                 arPhyCapability;
242 #ifdef CONFIG_HOST_TCMD_SUPPORT
243     A_UINT8                 tcmdRxReport;
244     A_UINT32                tcmdRxTotalPkt;
245     A_INT32                 tcmdRxRssi;
246     A_UINT32                tcmdPm;
247    A_UINT32                 arTargetMode;
248 #endif
249     AR6000_WLAN_STATE       arWlanState;
250     struct ar_node_mapping  arNodeMap[MAX_NODE_NUM];
251     A_UINT8                 arIbssPsEnable;
252     A_UINT8                 arNodeNum;
253     A_UINT8                 arNexEpId;
254     struct ar_cookie        *arCookieList;
255     A_UINT16                arRateMask;
256     A_UINT8                 arSkipScan;
257     A_UINT16                arBeaconInterval;
258     A_BOOL                  arConnectPending;
259     A_BOOL                  arWmmEnabled;
260     struct ar_hb_chlng_resp arHBChallengeResp;
261     A_UINT8                 arKeepaliveConfigured;
262     A_UINT32                arMgmtFilter;
263     HTC_ENDPOINT_ID         arWmi2EpMapping[WMI_PRI_MAX_COUNT];
264     WMI_PRI_STREAM_ID       arEp2WmiMapping[ENDPOINT_MAX];
265 #ifdef HTC_RAW_INTERFACE
266     HTC_ENDPOINT_ID         arRaw2EpMapping[HTC_RAW_STREAM_NUM_MAX];
267     HTC_RAW_STREAM_ID       arEp2RawMapping[ENDPOINT_MAX];
268     struct semaphore        raw_htc_read_sem[HTC_RAW_STREAM_NUM_MAX];
269     struct semaphore        raw_htc_write_sem[HTC_RAW_STREAM_NUM_MAX];
270     wait_queue_head_t       raw_htc_read_queue[HTC_RAW_STREAM_NUM_MAX];
271     wait_queue_head_t       raw_htc_write_queue[HTC_RAW_STREAM_NUM_MAX];
272     raw_htc_buffer          *raw_htc_read_buffer[HTC_RAW_STREAM_NUM_MAX][RAW_HTC_READ_BUFFERS_NUM];
273     raw_htc_buffer          *raw_htc_write_buffer[HTC_RAW_STREAM_NUM_MAX][RAW_HTC_WRITE_BUFFERS_NUM];
274     A_BOOL                  write_buffer_available[HTC_RAW_STREAM_NUM_MAX];
275     A_BOOL                  read_buffer_available[HTC_RAW_STREAM_NUM_MAX];
276 #endif
277     A_BOOL                  arRawIfInit;
278     int                     arDeviceIndex;
279     COMMON_CREDIT_STATE_INFO arCreditStateInfo;
280     A_BOOL                  arWMIControlEpFull;
281     A_BOOL                  dbgLogFetchInProgress;
282     A_UCHAR                 log_buffer[DBGLOG_HOST_LOG_BUFFER_SIZE];
283     A_UINT32                log_cnt;
284     A_UINT32                dbglog_init_done;
285     A_UINT32                arConnectCtrlFlags;
286         A_UINT32                scan_complete;
287 #ifdef USER_KEYS
288     A_INT32                 user_savedkeys_stat;
289     A_UINT32                user_key_ctrl;
290     struct USER_SAVEDKEYS   user_saved_keys;
291 #endif
292 } AR_SOFTC_T;
293
294
295 #define arWMIStream2EndpointID(ar,wmi)          (ar)->arWmi2EpMapping[(wmi)]
296 #define arSetWMIStream2EndpointIDMap(ar,wmi,ep)  \
297 {  (ar)->arWmi2EpMapping[(wmi)] = (ep); \
298    (ar)->arEp2WmiMapping[(ep)] = (wmi); }
299 #define arEndpoint2WMIStreamID(ar,ep)           (ar)->arEp2WmiMapping[(ep)]
300
301 #define arRawIfEnabled(ar) (ar)->arRawIfInit
302 #define arRawStream2EndpointID(ar,raw)          (ar)->arRaw2EpMapping[(raw)]
303 #define arSetRawStream2EndpointIDMap(ar,raw,ep)  \
304 {  (ar)->arRaw2EpMapping[(raw)] = (ep); \
305    (ar)->arEp2RawMapping[(ep)] = (raw); }
306 #define arEndpoint2RawStreamID(ar,ep)           (ar)->arEp2RawMapping[(ep)]
307
308 struct ar_giwscan_param {
309     char    *current_ev;
310     char    *end_buf;
311     A_BOOL  firstPass;
312 };
313
314 #define AR6000_STAT_INC(ar, stat)       (ar->arNetStats.stat++)
315
316 #define AR6000_SPIN_LOCK(lock, param)   do {                            \
317     if (irqs_disabled()) {                                              \
318         AR_DEBUG_PRINTF("IRQs disabled:AR6000_LOCK\n");                 \
319     }                                                                   \
320     spin_lock_bh(lock);                                                 \
321 } while (0)
322
323 #define AR6000_SPIN_UNLOCK(lock, param) do {                            \
324     if (irqs_disabled()) {                                              \
325         AR_DEBUG_PRINTF("IRQs disabled: AR6000_UNLOCK\n");              \
326     }                                                                   \
327     spin_unlock_bh(lock);                                               \
328 } while (0)
329
330 int ar6000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
331 int ar6000_ioctl_dispatcher(struct net_device *dev, struct ifreq *rq, int cmd);
332 void ar6000_ioctl_iwsetup(struct iw_handler_def *def);
333 void ar6000_gpio_init(void);
334 void ar6000_init_profile_info(AR_SOFTC_T *ar);
335 void ar6000_install_static_wep_keys(AR_SOFTC_T *ar);
336 int ar6000_init(struct net_device *dev);
337 int ar6000_dbglog_get_debug_logs(AR_SOFTC_T *ar);
338 A_STATUS ar6000_SetHTCBlockSize(AR_SOFTC_T *ar);
339
340 #ifdef HTC_RAW_INTERFACE
341
342 #ifndef __user
343 #define __user
344 #endif
345
346 int ar6000_htc_raw_open(AR_SOFTC_T *ar);
347 int ar6000_htc_raw_close(AR_SOFTC_T *ar);
348 ssize_t ar6000_htc_raw_read(AR_SOFTC_T *ar,
349                             HTC_RAW_STREAM_ID StreamID,
350                             char __user *buffer, size_t count);
351 ssize_t ar6000_htc_raw_write(AR_SOFTC_T *ar,
352                              HTC_RAW_STREAM_ID StreamID,
353                              char __user *buffer, size_t count);
354
355 #endif /* HTC_RAW_INTERFACE */
356
357 #ifdef __cplusplus
358 }
359 #endif
360
361 #endif /* _AR6000_H_ */