]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/brcm80211/brcmfmac/dhd.h
eca67322e049615fadd46704ea5cd8f5700d9a9b
[mv-sheeva.git] / drivers / staging / brcm80211 / brcmfmac / dhd.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 /****************
18  * Common types *
19  */
20
21 #ifndef _dhd_h_
22 #define _dhd_h_
23
24 #include <linux/sched.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/skbuff.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/random.h>
32 #include <linux/spinlock.h>
33 #include <linux/ethtool.h>
34 #include <linux/suspend.h>
35 #include <asm/uaccess.h>
36 #include <asm/unaligned.h>
37 #include "bcmdefs.h"
38 /* The kernel threading is sdio-specific */
39 #include "bcmwifi.h"
40 #include "proto/bcmeth.h"
41 #include "proto/bcmevent.h"
42
43 /* Forward decls */
44 struct dhd_bus;
45 struct dhd_prot;
46 struct dhd_info;
47
48 #define WLC_UP                                  2
49 #define WLC_SET_PROMISC                         10
50 #define WLC_GET_RATE                            12
51 #define WLC_GET_INFRA                           19
52 #define WLC_SET_INFRA                           20
53 #define WLC_GET_AUTH                            21
54 #define WLC_SET_AUTH                            22
55 #define WLC_GET_BSSID                           23
56 #define WLC_GET_SSID                            25
57 #define WLC_SET_SSID                            26
58 #define WLC_GET_CHANNEL                         29
59 #define WLC_GET_SRL                             31
60 #define WLC_GET_LRL                             33
61 #define WLC_GET_RADIO                           37
62 #define WLC_SET_RADIO                           38
63 #define WLC_GET_PHYTYPE                         39
64 #define WLC_SET_KEY                             45
65 #define WLC_SET_PASSIVE_SCAN                    49
66 #define WLC_SCAN                                50
67 #define WLC_SCAN_RESULTS                        51
68 #define WLC_DISASSOC                            52
69 #define WLC_REASSOC                             53
70 #define WLC_SET_ROAM_TRIGGER                    55
71 #define WLC_SET_ROAM_DELTA                      57
72 #define WLC_GET_DTIMPRD                         77
73 #define WLC_SET_COUNTRY                         84
74 #define WLC_GET_PM                              85
75 #define WLC_SET_PM                              86
76 #define WLC_GET_AP                              117
77 #define WLC_SET_AP                              118
78 #define WLC_GET_RSSI                            127
79 #define WLC_GET_WSEC                            133
80 #define WLC_SET_WSEC                            134
81 #define WLC_GET_PHY_NOISE                       135
82 #define WLC_GET_BSS_INFO                        136
83 #define WLC_SET_SCAN_CHANNEL_TIME               185
84 #define WLC_SET_SCAN_UNASSOC_TIME               187
85 #define WLC_SCB_DEAUTHENTICATE_FOR_REASON       201
86 #define WLC_GET_VALID_CHANNELS                  217
87 #define WLC_GET_KEY_PRIMARY                     235
88 #define WLC_SET_KEY_PRIMARY                     236
89 #define WLC_SET_SCAN_PASSIVE_TIME               258
90 #define WLC_GET_VAR                             262     /* get value of named variable */
91 #define WLC_SET_VAR                             263     /* set named variable to value */
92
93 /* phy types (returned by WLC_GET_PHYTPE) */
94 #define WLC_PHY_TYPE_A          0
95 #define WLC_PHY_TYPE_B          1
96 #define WLC_PHY_TYPE_G          2
97 #define WLC_PHY_TYPE_N          4
98 #define WLC_PHY_TYPE_LP         5
99 #define WLC_PHY_TYPE_SSN        6
100 #define WLC_PHY_TYPE_HT         7
101 #define WLC_PHY_TYPE_LCN        8
102 #define WLC_PHY_TYPE_NULL       0xf
103
104 #define WL_PKT_FILTER_FIXED_LEN           offsetof(wl_pkt_filter_t, u)
105 #define WL_PKT_FILTER_PATTERN_FIXED_LEN   offsetof(wl_pkt_filter_pattern_t, mask_and_pattern)
106
107 #define WL_EVENTING_MASK_LEN    16
108
109 #define TOE_TX_CSUM_OL          0x00000001
110 #define TOE_RX_CSUM_OL          0x00000002
111
112 /* maximum channels returned by the get valid channels iovar */
113 #define WL_NUMCHANNELS          64
114
115 #define WL_BSS_INFO_VERSION     108     /* current ver of wl_bss_info struct */
116
117 /* size of wl_scan_params not including variable length array */
118 #define WL_SCAN_PARAMS_FIXED_SIZE 64
119
120 /* masks for channel and ssid count */
121 #define WL_SCAN_PARAMS_COUNT_MASK 0x0000ffff
122 #define WL_SCAN_PARAMS_NSSID_SHIFT 16
123
124 #define WL_SCAN_ACTION_START      1
125 #define WL_SCAN_ACTION_CONTINUE   2
126 #define WL_SCAN_ACTION_ABORT      3
127
128 #define ISCAN_REQ_VERSION 1
129
130 /* wl_iscan_results status values */
131 #define WL_SCAN_RESULTS_SUCCESS 0
132 #define WL_SCAN_RESULTS_PARTIAL 1
133 #define WL_SCAN_RESULTS_PENDING 2
134 #define WL_SCAN_RESULTS_ABORTED 3
135 #define WL_SCAN_RESULTS_NO_MEM  4
136
137 #define MAX_CCA_CHANNELS 38     /* Max number of 20 Mhz wide channels */
138 #define MAX_CCA_SECS     60     /* CCA keeps this many seconds history */
139
140 #define IBSS_MED        15      /* Mediom in-bss congestion percentage */
141 #define IBSS_HI         25      /* Hi in-bss congestion percentage */
142 #define OBSS_MED        12
143 #define OBSS_HI         25
144 #define INTERFER_MED    5
145 #define INTERFER_HI     10
146
147 #define  CCA_FLAG_2G_ONLY               0x01    /* Return a channel from 2.4 Ghz band */
148 #define  CCA_FLAG_5G_ONLY               0x02    /* Return a channel from 2.4 Ghz band */
149 #define  CCA_FLAG_IGNORE_DURATION       0x04    /* Ignore dwell time for each channel */
150 #define  CCA_FLAGS_PREFER_1_6_11        0x10
151 #define  CCA_FLAG_IGNORE_INTERFER       0x20    /* do not exlude channel based on interfer level */
152
153 #define CCA_ERRNO_BAND          1       /* After filtering for band pref, no choices left */
154 #define CCA_ERRNO_DURATION      2       /* After filtering for duration, no choices left */
155 #define CCA_ERRNO_PREF_CHAN     3       /* After filtering for chan pref, no choices left */
156 #define CCA_ERRNO_INTERFER      4       /* After filtering for interference, no choices left */
157 #define CCA_ERRNO_TOO_FEW       5       /* Only 1 channel was input */
158
159 #define WL_NUM_RPI_BINS         8
160 #define WL_RM_TYPE_BASIC        1
161 #define WL_RM_TYPE_CCA          2
162 #define WL_RM_TYPE_RPI          3
163
164 #define WL_RM_FLAG_PARALLEL     (1<<0)
165
166 #define WL_RM_FLAG_LATE         (1<<1)
167 #define WL_RM_FLAG_INCAPABLE    (1<<2)
168 #define WL_RM_FLAG_REFUSED      (1<<3)
169
170 #define WL_SOFT_KEY     (1 << 0)        /* Indicates this key is using soft encrypt */
171 #define WL_PRIMARY_KEY  (1 << 1)        /* Indicates this key is the primary (ie tx) key */
172 #define WL_KF_RES_4     (1 << 4)        /* Reserved for backward compat */
173 #define WL_KF_RES_5     (1 << 5)        /* Reserved for backward compat */
174 #define WL_IBSS_PEER_GROUP_KEY  (1 << 6)        /* Indicates a group key for a IBSS PEER */
175
176 #define WLC_IOCTL_SMLEN                 256     /* "small" length ioctl buffer required */
177 #define WLC_IOCTL_MEDLEN                1536    /* "med" length ioctl buffer required */
178 #define WLC_IOCTL_MAXLEN        8192
179
180 #define DHD_IF_VIF      0x01    /* Virtual IF (Hidden from user) */
181
182 /* optionally set by a module_param_string() */
183 #define MOD_PARAM_PATHLEN       2048
184
185 /* For supporting multiple interfaces */
186 #define DHD_MAX_IFS     16
187 #define DHD_DEL_IF      -0xe
188 #define DHD_BAD_IF      -0xf
189
190 #define DOT11_BSSTYPE_ANY                       2
191 #define DOT11_MAX_DEFAULT_KEYS  4
192
193 enum cust_gpio_modes {
194         WLAN_RESET_ON,
195         WLAN_RESET_OFF,
196         WLAN_POWER_ON,
197         WLAN_POWER_OFF
198 };
199
200 /* The level of bus communication with the dongle */
201 enum dhd_bus_state {
202         DHD_BUS_DOWN,           /* Not ready for frame transfers */
203         DHD_BUS_LOAD,           /* Download access only (CPU reset) */
204         DHD_BUS_DATA            /* Ready for frame transfers */
205 };
206
207 /* Pattern matching filter. Specifies an offset within received packets to
208  * start matching, the pattern to match, the size of the pattern, and a bitmask
209  * that indicates which bits within the pattern should be matched.
210  */
211 typedef struct wl_pkt_filter_pattern {
212         u32 offset;             /* Offset within received packet to start pattern matching.
213                                  * Offset '0' is the first byte of the ethernet header.
214                                  */
215         u32 size_bytes; /* Size of the pattern.  Bitmask must be the same size. */
216         u8 mask_and_pattern[1]; /* Variable length mask and pattern data.  mask starts
217                                          * at offset 0.  Pattern immediately follows mask.
218                                          */
219 } wl_pkt_filter_pattern_t;
220
221 /* IOVAR "pkt_filter_add" parameter. Used to install packet filters. */
222 typedef struct wl_pkt_filter {
223         u32 id;         /* Unique filter id, specified by app. */
224         u32 type;               /* Filter type (WL_PKT_FILTER_TYPE_xxx). */
225         u32 negate_match;       /* Negate the result of filter matches */
226         union {                 /* Filter definitions */
227                 wl_pkt_filter_pattern_t pattern;        /* Pattern matching filter */
228         } u;
229 } wl_pkt_filter_t;
230
231 /* IOVAR "pkt_filter_enable" parameter. */
232 typedef struct wl_pkt_filter_enable {
233         u32 id;         /* Unique filter id */
234         u32 enable;             /* Enable/disable bool */
235 } wl_pkt_filter_enable_t;
236
237 /* BSS info structure
238  * Applications MUST CHECK ie_offset field and length field to access IEs and
239  * next bss_info structure in a vector (in wl_scan_results_t)
240  */
241 typedef struct wl_bss_info {
242         u32 version;            /* version field */
243         u32 length;             /* byte length of data in this record,
244                                  * starting at version and including IEs
245                                  */
246         u8 BSSID[ETH_ALEN];
247         u16 beacon_period;      /* units are Kusec */
248         u16 capability; /* Capability information */
249         u8 SSID_len;
250         u8 SSID[32];
251         struct {
252                 uint count;     /* # rates in this set */
253                 u8 rates[16];   /* rates in 500kbps units w/hi bit set if basic */
254         } rateset;              /* supported rates */
255         chanspec_t chanspec;    /* chanspec for bss */
256         u16 atim_window;        /* units are Kusec */
257         u8 dtim_period; /* DTIM period */
258         s16 RSSI;               /* receive signal strength (in dBm) */
259         s8 phy_noise;           /* noise (in dBm) */
260
261         u8 n_cap;               /* BSS is 802.11N Capable */
262         u32 nbss_cap;   /* 802.11N BSS Capabilities (based on HT_CAP_*) */
263         u8 ctl_ch;              /* 802.11N BSS control channel number */
264         u32 reserved32[1];      /* Reserved for expansion of BSS properties */
265         u8 flags;               /* flags */
266         u8 reserved[3]; /* Reserved for expansion of BSS properties */
267         u8 basic_mcs[MCSSET_LEN];       /* 802.11N BSS required MCS set */
268
269         u16 ie_offset;  /* offset at which IEs start, from beginning */
270         u32 ie_length;  /* byte length of Information Elements */
271         s16 SNR;                /* average SNR of during frame reception */
272         /* Add new fields here */
273         /* variable length Information Elements */
274 } wl_bss_info_t;
275
276 typedef struct wlc_ssid {
277         u32 SSID_len;
278         unsigned char SSID[32];
279 } wlc_ssid_t;
280
281 typedef struct wl_scan_params {
282         wlc_ssid_t ssid;        /* default: {0, ""} */
283         u8 bssid[ETH_ALEN];     /* default: bcast */
284         s8 bss_type;            /* default: any,
285                                  * DOT11_BSSTYPE_ANY/INFRASTRUCTURE/INDEPENDENT
286                                  */
287         u8 scan_type;   /* flags, 0 use default */
288         s32 nprobes;            /* -1 use default, number of probes per channel */
289         s32 active_time;        /* -1 use default, dwell time per channel for
290                                  * active scanning
291                                  */
292         s32 passive_time;       /* -1 use default, dwell time per channel
293                                  * for passive scanning
294                                  */
295         s32 home_time;  /* -1 use default, dwell time for the home channel
296                                  * between channel scans
297                                  */
298         s32 channel_num;        /* count of channels and ssids that follow
299                                  *
300                                  * low half is count of channels in channel_list, 0
301                                  * means default (use all available channels)
302                                  *
303                                  * high half is entries in wlc_ssid_t array that
304                                  * follows channel_list, aligned for s32 (4 bytes)
305                                  * meaning an odd channel count implies a 2-byte pad
306                                  * between end of channel_list and first ssid
307                                  *
308                                  * if ssid count is zero, single ssid in the fixed
309                                  * parameter portion is assumed, otherwise ssid in
310                                  * the fixed portion is ignored
311                                  */
312         u16 channel_list[1];    /* list of chanspecs */
313 } wl_scan_params_t;
314
315 /* incremental scan struct */
316 typedef struct wl_iscan_params {
317         u32 version;
318         u16 action;
319         u16 scan_duration;
320         wl_scan_params_t params;
321 } wl_iscan_params_t;
322
323 /* 3 fields + size of wl_scan_params, not including variable length array */
324 #define WL_ISCAN_PARAMS_FIXED_SIZE (offsetof(wl_iscan_params_t, params) + sizeof(wlc_ssid_t))
325
326 typedef struct wl_scan_results {
327         u32 buflen;
328         u32 version;
329         u32 count;
330         wl_bss_info_t bss_info[1];
331 } wl_scan_results_t;
332
333 typedef struct wl_rateset_args {
334         u32 count;              /* # rates in this set */
335         u8 rates[WL_NUMRATES];  /* rates in 500kbps units w/hi bit set if basic */
336         u8 mcs[MCSSET_LEN];     /* supported mcs index bit map */
337 } wl_rateset_args_t;
338
339 /* u32 list */
340 typedef struct wl_u32_list {
341         /* in - # of elements, out - # of entries */
342         u32 count;
343         /* variable length u32 list */
344         u32 element[1];
345 } wl_u32_list_t;
346
347 /* used for association with a specific BSSID and chanspec list */
348 typedef struct wl_assoc_params {
349         u8 bssid[ETH_ALEN];     /* 00:00:00:00:00:00: broadcast scan */
350         s32 chanspec_num;       /* 0: all available channels,
351                                  * otherwise count of chanspecs in chanspec_list
352                                  */
353         chanspec_t chanspec_list[1];    /* list of chanspecs */
354 } wl_assoc_params_t;
355 #define WL_ASSOC_PARAMS_FIXED_SIZE      (sizeof(wl_assoc_params_t) - sizeof(chanspec_t))
356
357 /* used for reassociation/roam to a specific BSSID and channel */
358 typedef wl_assoc_params_t wl_reassoc_params_t;
359 #define WL_REASSOC_PARAMS_FIXED_SIZE    WL_ASSOC_PARAMS_FIXED_SIZE
360
361 /* used for join with or without a specific bssid and channel list */
362 typedef struct wl_join_params {
363         wlc_ssid_t ssid;
364         wl_assoc_params_t params;       /* optional field, but it must include the fixed portion
365                                          * of the wl_assoc_params_t struct when it does present.
366                                          */
367 } wl_join_params_t;
368 #define WL_JOIN_PARAMS_FIXED_SIZE       (sizeof(wl_join_params_t) - sizeof(chanspec_t))
369
370 /* size of wl_scan_results not including variable length array */
371 #define WL_SCAN_RESULTS_FIXED_SIZE (sizeof(wl_scan_results_t) - sizeof(wl_bss_info_t))
372
373 /* incremental scan results struct */
374 typedef struct wl_iscan_results {
375         u32 status;
376         wl_scan_results_t results;
377 } wl_iscan_results_t;
378
379 /* size of wl_iscan_results not including variable length array */
380 #define WL_ISCAN_RESULTS_FIXED_SIZE \
381         (WL_SCAN_RESULTS_FIXED_SIZE + offsetof(wl_iscan_results_t, results))
382
383 typedef struct {
384         u32 duration;   /* millisecs spent sampling this channel */
385         u32 congest_ibss;       /* millisecs in our bss (presumably this traffic will */
386         /*  move if cur bss moves channels) */
387         u32 congest_obss;       /* traffic not in our bss */
388         u32 interference;       /* millisecs detecting a non 802.11 interferer. */
389         u32 timestamp;  /* second timestamp */
390 } cca_congest_t;
391
392 typedef struct {
393         chanspec_t chanspec;    /* Which channel? */
394         u8 num_secs;            /* How many secs worth of data */
395         cca_congest_t secs[1];  /* Data */
396 } cca_congest_channel_req_t;
397
398 typedef struct wl_country {
399         char country_abbrev[WLC_CNTRY_BUF_SZ];  /* nul-terminated country code used in
400                                                  * the Country IE
401                                                  */
402         s32 rev;                /* revision specifier for ccode
403                                  * on set, -1 indicates unspecified.
404                                  * on get, rev >= 0
405                                  */
406         char ccode[WLC_CNTRY_BUF_SZ];   /* nul-terminated built-in country code.
407                                          * variable length, but fixed size in
408                                          * struct allows simple allocation for
409                                          * expected country strings <= 3 chars.
410                                          */
411 } wl_country_t;
412
413 typedef struct wl_channels_in_country {
414         u32 buflen;
415         u32 band;
416         char country_abbrev[WLC_CNTRY_BUF_SZ];
417         u32 count;
418         u32 channel[1];
419 } wl_channels_in_country_t;
420
421 typedef struct wl_country_list {
422         u32 buflen;
423         u32 band_set;
424         u32 band;
425         u32 count;
426         char country_abbrev[1];
427 } wl_country_list_t;
428
429 typedef struct wl_rm_req_elt {
430         s8 type;
431         s8 flags;
432         chanspec_t chanspec;
433         u32 token;              /* token for this measurement */
434         u32 tsf_h;              /* TSF high 32-bits of Measurement start time */
435         u32 tsf_l;              /* TSF low 32-bits */
436         u32 dur;                /* TUs */
437 } wl_rm_req_elt_t;
438
439 typedef struct wl_rm_req {
440         u32 token;              /* overall measurement set token */
441         u32 count;              /* number of measurement requests */
442         void *cb;               /* completion callback function: may be NULL */
443         void *cb_arg;           /* arg to completion callback function */
444         wl_rm_req_elt_t req[1]; /* variable length block of requests */
445 } wl_rm_req_t;
446 #define WL_RM_REQ_FIXED_LEN     offsetof(wl_rm_req_t, req)
447
448 typedef struct wl_rm_rep_elt {
449         s8 type;
450         s8 flags;
451         chanspec_t chanspec;
452         u32 token;              /* token for this measurement */
453         u32 tsf_h;              /* TSF high 32-bits of Measurement start time */
454         u32 tsf_l;              /* TSF low 32-bits */
455         u32 dur;                /* TUs */
456         u32 len;                /* byte length of data block */
457         u8 data[1];             /* variable length data block */
458 } wl_rm_rep_elt_t;
459 #define WL_RM_REP_ELT_FIXED_LEN 24      /* length excluding data block */
460
461 #define WL_RPI_REP_BIN_NUM 8
462 typedef struct wl_rm_rpi_rep {
463         u8 rpi[WL_RPI_REP_BIN_NUM];
464         s8 rpi_max[WL_RPI_REP_BIN_NUM];
465 } wl_rm_rpi_rep_t;
466
467 typedef struct wl_rm_rep {
468         u32 token;              /* overall measurement set token */
469         u32 len;                /* length of measurement report block */
470         wl_rm_rep_elt_t rep[1]; /* variable length block of reports */
471 } wl_rm_rep_t;
472 #define WL_RM_REP_FIXED_LEN     8
473
474 typedef struct wl_wsec_key {
475         u32 index;              /* key index */
476         u32 len;                /* key length */
477         u8 data[WLAN_MAX_KEY_LEN];      /* key data */
478         u32 pad_1[18];
479         u32 algo;               /* CRYPTO_ALGO_AES_CCM, CRYPTO_ALGO_WEP128, etc */
480         u32 flags;              /* misc flags */
481         u32 pad_2[2];
482         int pad_3;
483         int iv_initialized;     /* has IV been initialized already? */
484         int pad_4;
485         /* Rx IV */
486         struct {
487                 u32 hi; /* upper 32 bits of IV */
488                 u16 lo; /* lower 16 bits of IV */
489         } rxiv;
490         u32 pad_5[2];
491         u8 ea[ETH_ALEN];        /* per station */
492 } wl_wsec_key_t;
493
494 /* Used to get specific STA parameters */
495 typedef struct {
496         u32 val;
497         u8 ea[ETH_ALEN];
498 } scb_val_t;
499
500 /* channel encoding */
501 typedef struct channel_info {
502         int hw_channel;
503         int target_channel;
504         int scan_channel;
505 } channel_info_t;
506
507 /* Linux network driver ioctl encoding */
508 typedef struct wl_ioctl {
509         uint cmd;               /* common ioctl definition */
510         void *buf;              /* pointer to user buffer */
511         uint len;               /* length of user buffer */
512         u8 set;         /* get or set request (optional) */
513         uint used;              /* bytes read or written (optional) */
514         uint needed;            /* bytes needed (optional) */
515 } wl_ioctl_t;
516
517 /* Common structure for module and instance linkage */
518 typedef struct dhd_pub {
519         /* Linkage ponters */
520         struct dhd_bus *bus;    /* Bus module handle */
521         struct dhd_prot *prot;  /* Protocol module handle */
522         struct dhd_info *info;  /* Info module handle */
523
524         /* Internal dhd items */
525         bool up;                /* Driver up/down (to OS) */
526         bool txoff;             /* Transmit flow-controlled */
527         bool dongle_reset;      /* true = DEVRESET put dongle into reset */
528         enum dhd_bus_state busstate;
529         uint hdrlen;            /* Total DHD header length (proto + bus) */
530         uint maxctl;            /* Max size rxctl request from proto to bus */
531         uint rxsz;              /* Rx buffer size bus module should use */
532         u8 wme_dp;              /* wme discard priority */
533
534         /* Dongle media info */
535         bool iswl;              /* Dongle-resident driver is wl */
536         unsigned long drv_version;      /* Version of dongle-resident driver */
537         u8 mac[ETH_ALEN];                       /* MAC address obtained from dongle */
538         dngl_stats_t dstats;            /* Stats for dongle-based data */
539
540         /* Additional stats for the bus level */
541         unsigned long tx_packets;       /* Data packets sent to dongle */
542         unsigned long tx_multicast;     /* Multicast data packets sent to dongle */
543         unsigned long tx_errors;        /* Errors in sending data to dongle */
544         unsigned long tx_ctlpkts;       /* Control packets sent to dongle */
545         unsigned long tx_ctlerrs;       /* Errors sending control frames to dongle */
546         unsigned long rx_packets;       /* Packets sent up the network interface */
547         unsigned long rx_multicast;     /* Multicast packets sent up the network
548                                          interface */
549         unsigned long rx_errors;        /* Errors processing rx data packets */
550         unsigned long rx_ctlpkts;       /* Control frames processed from dongle */
551         unsigned long rx_ctlerrs;       /* Errors in processing rx control frames */
552         unsigned long rx_dropped;       /* Packets dropped locally (no memory) */
553         unsigned long rx_flushed;       /* Packets flushed due to
554                                 unscheduled sendup thread */
555         unsigned long wd_dpc_sched;     /* Number of times dhd dpc scheduled by
556                                          watchdog timer */
557
558         unsigned long rx_readahead_cnt; /* Number of packets where header read-ahead
559                                          was used. */
560         unsigned long tx_realloc;       /* Number of tx packets we had to realloc for
561                                          headroom */
562         unsigned long fc_packets;       /* Number of flow control pkts recvd */
563
564         /* Last error return */
565         int bcmerror;
566         uint tickcnt;
567
568         /* Last error from dongle */
569         int dongle_error;
570
571         /* Suspend disable flag  flag */
572         int suspend_disable_flag;       /* "1" to disable all extra powersaving
573                                          during suspend */
574         int in_suspend;         /* flag set to 1 when early suspend called */
575 #ifdef PNO_SUPPORT
576         int pno_enable;         /* pno status : "1" is pno enable */
577 #endif                          /* PNO_SUPPORT */
578         int dtim_skip;          /* dtim skip , default 0 means wake each dtim */
579
580         /* Pkt filter defination */
581         char *pktfilter[100];
582         int pktfilter_count;
583
584         u8 country_code[WLC_CNTRY_BUF_SZ];
585         char eventmask[WL_EVENTING_MASK_LEN];
586
587 } dhd_pub_t;
588
589 typedef struct dhd_if_event {
590         u8 ifidx;
591         u8 action;
592         u8 flags;
593         u8 bssidx;
594 } dhd_if_event_t;
595
596 typedef struct {
597         u32 limit;              /* Expiration time (usec) */
598         u32 increment;  /* Current expiration increment (usec) */
599         u32 elapsed;            /* Current elapsed time (usec) */
600         u32 tick;               /* O/S tick time (usec) */
601 } dhd_timeout_t;
602
603 #if defined(CONFIG_PM_SLEEP)
604 extern atomic_t dhd_mmc_suspend;
605 #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
606 #define _DHD_PM_RESUME_WAIT(a, b) do { \
607                 int retry = 0; \
608                 while (atomic_read(&dhd_mmc_suspend) && retry++ != b) { \
609                         wait_event_timeout(a, false, HZ/100); \
610                 } \
611         }       while (0)
612 #define DHD_PM_RESUME_WAIT(a)   _DHD_PM_RESUME_WAIT(a, 30)
613 #define DHD_PM_RESUME_WAIT_FOREVER(a)   _DHD_PM_RESUME_WAIT(a, ~0)
614 #define DHD_PM_RESUME_RETURN_ERROR(a)   \
615         do { if (atomic_read(&dhd_mmc_suspend)) return a; } while (0)
616 #define DHD_PM_RESUME_RETURN    do { \
617         if (atomic_read(&dhd_mmc_suspend)) \
618                 return; \
619         } while (0)
620
621 #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
622 #define SPINWAIT_SLEEP(a, exp, us) do { \
623                 uint countdown = (us) + 9999; \
624                 while ((exp) && (countdown >= 10000)) { \
625                         wait_event_timeout(a, false, HZ/100); \
626                         countdown -= 10000; \
627                 } \
628         } while (0)
629
630 #else
631
632 #define DHD_PM_RESUME_WAIT_INIT(a)
633 #define DHD_PM_RESUME_WAIT(a)
634 #define DHD_PM_RESUME_WAIT_FOREVER(a)
635 #define DHD_PM_RESUME_RETURN_ERROR(a)
636 #define DHD_PM_RESUME_RETURN
637
638 #define DHD_SPINWAIT_SLEEP_INIT(a)
639 #define SPINWAIT_SLEEP(a, exp, us)  do { \
640                 uint countdown = (us) + 9; \
641                 while ((exp) && (countdown >= 10)) { \
642                         udelay(10);  \
643                         countdown -= 10;  \
644                 } \
645         } while (0)
646
647 #endif  /* defined(CONFIG_PM_SLEEP) */
648
649 /*
650  * Insmod parameters for debug/test
651  */
652
653 /* Watchdog timer interval */
654 extern uint dhd_watchdog_ms;
655
656 #if defined(DHD_DEBUG)
657 /* Console output poll interval */
658 extern uint dhd_console_ms;
659 #endif                          /* defined(DHD_DEBUG) */
660
661 /* Use interrupts */
662 extern uint dhd_intr;
663
664 /* Use polling */
665 extern uint dhd_poll;
666
667 /* ARP offload agent mode */
668 extern uint dhd_arp_mode;
669
670 /* ARP offload enable */
671 extern uint dhd_arp_enable;
672
673 /* Pkt filte enable control */
674 extern uint dhd_pkt_filter_enable;
675
676 /*  Pkt filter init setup */
677 extern uint dhd_pkt_filter_init;
678
679 /* Pkt filter mode control */
680 extern uint dhd_master_mode;
681
682 /* Roaming mode control */
683 extern uint dhd_roam;
684
685 /* Roaming mode control */
686 extern uint dhd_radio_up;
687
688 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
689 extern int dhd_idletime;
690 #define DHD_IDLETIME_TICKS 1
691
692 /* SDIO Drive Strength */
693 extern uint dhd_sdiod_drive_strength;
694
695 /* Override to force tx queueing all the time */
696 extern uint dhd_force_tx_queueing;
697
698 #ifdef SDTEST
699 /* Echo packet generator (SDIO), pkts/s */
700 extern uint dhd_pktgen;
701
702 /* Echo packet len (0 => sawtooth, max 1800) */
703 extern uint dhd_pktgen_len;
704 #define MAX_PKTGEN_LEN 1800
705 #endif
706
707 extern char fw_path[MOD_PARAM_PATHLEN];
708 extern char nv_path[MOD_PARAM_PATHLEN];
709
710 extern u32 g_assert_type;
711
712 static inline void MUTEX_LOCK_INIT(dhd_pub_t *dhdp)
713 {
714 }
715
716 static inline void MUTEX_LOCK(dhd_pub_t *dhdp)
717 {
718 }
719
720 static inline void MUTEX_UNLOCK(dhd_pub_t *dhdp)
721 {
722 }
723
724 static inline void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t *dhdp)
725 {
726 }
727
728 static inline void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t *dhdp)
729 {
730 }
731
732 static inline void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t *dhdp)
733 {
734 }
735
736 static inline void MUTEX_LOCK_WL_SCAN_SET_INIT(void)
737 {
738 }
739
740 static inline void MUTEX_LOCK_WL_SCAN_SET(void)
741 {
742 }
743
744 static inline void MUTEX_UNLOCK_WL_SCAN_SET(void)
745 {
746 }
747
748 /*
749  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
750  */
751
752 /* Indication from bus module regarding presence/insertion of dongle.
753  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
754  * Returned structure should have bus and prot pointers filled in.
755  * bus_hdrlen specifies required headroom for bus module header.
756  */
757 extern dhd_pub_t *dhd_attach(struct dhd_bus *bus,
758                                 uint bus_hdrlen);
759 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
760
761 /* Indication from bus module regarding removal/absence of dongle */
762 extern void dhd_detach(dhd_pub_t *dhdp);
763
764 /* Indication from bus module to change flow-control state */
765 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
766
767 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q,
768                          struct sk_buff *pkt, int prec);
769
770 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
771 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx,
772                          struct sk_buff *rxp, int numpkt);
773
774 /* Return pointer to interface name */
775 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
776
777 /* Request scheduling of the bus dpc */
778 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
779
780 /* Notify tx completion */
781 extern void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success);
782
783 /* Query ioctl */
784 extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
785                               uint len);
786
787 /* OS independent layer functions */
788 extern int dhd_os_proto_block(dhd_pub_t *pub);
789 extern int dhd_os_proto_unblock(dhd_pub_t *pub);
790 extern int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition,
791                                   bool *pending);
792 extern int dhd_os_ioctl_resp_wake(dhd_pub_t *pub);
793 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
794 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
795 extern void *dhd_os_open_image(char *filename);
796 extern int dhd_os_get_image_block(char *buf, int len, void *image);
797 extern void dhd_os_close_image(void *image);
798 extern void dhd_os_wd_timer(void *bus, uint wdtick);
799 extern void dhd_os_sdlock(dhd_pub_t *pub);
800 extern void dhd_os_sdunlock(dhd_pub_t *pub);
801 extern void dhd_os_sdlock_txq(dhd_pub_t *pub);
802 extern void dhd_os_sdunlock_txq(dhd_pub_t *pub);
803 extern void dhd_os_sdlock_rxq(dhd_pub_t *pub);
804 extern void dhd_os_sdunlock_rxq(dhd_pub_t *pub);
805 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t *pub);
806 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
807 extern int dhd_custom_get_mac_address(unsigned char *buf);
808 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t *pub);
809 extern void dhd_os_sdlock_eventq(dhd_pub_t *pub);
810 extern void dhd_os_sdunlock_eventq(dhd_pub_t *pub);
811 #ifdef DHD_DEBUG
812 extern int write_to_file(dhd_pub_t *dhd, u8 *buf, int size);
813 #endif                          /* DHD_DEBUG */
814 #if defined(OOB_INTR_ONLY)
815 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
816 #endif                          /* defined(OOB_INTR_ONLY) */
817 extern void dhd_os_sdtxlock(dhd_pub_t *pub);
818 extern void dhd_os_sdtxunlock(dhd_pub_t *pub);
819
820 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
821
822 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
823 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
824
825 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
826 extern u8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
827 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
828                          wl_event_msg_t *, void **data_ptr);
829
830 extern void dhd_common_init(void);
831
832 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
833                       char *name, u8 *mac_addr, u32 flags, u8 bssidx);
834 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
835
836 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char *name);
837 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
838
839 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
840 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, unsigned char * cp,
841                            int len);
842
843 /* Send packet to dongle via data channel */
844 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pkt);
845
846 /* Send event to host */
847 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event,
848                              void *data);
849 extern int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag);
850 extern uint dhd_bus_status(dhd_pub_t *dhdp);
851 extern int dhd_bus_start(dhd_pub_t *dhdp);
852
853 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool * lockvar);
854 extern void dhd_wait_event_wakeup(dhd_pub_t *dhd);
855
856 #ifdef BCMDBG
857 #define ASSERT(exp) \
858           do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
859 extern void osl_assert(char *exp, char *file, int line);
860 #else
861 #define ASSERT(exp)     do {} while (0)
862 #endif  /* defined(BCMDBG) */
863
864 /* Linux network driver ioctl encoding */
865 typedef struct dhd_ioctl {
866         uint cmd;               /* common ioctl definition */
867         void *buf;              /* pointer to user buffer */
868         uint len;               /* length of user buffer */
869         bool set;               /* get or set request (optional) */
870         uint used;              /* bytes read or written (optional) */
871         uint needed;            /* bytes needed (optional) */
872         uint driver;            /* to identify target driver */
873 } dhd_ioctl_t;
874
875 /* per-driver magic numbers */
876 #define DHD_IOCTL_MAGIC         0x00444944
877
878 /* bump this number if you change the ioctl interface */
879 #define DHD_IOCTL_VERSION       1
880
881 #define DHD_IOCTL_MAXLEN        8192    /* max length ioctl buffer required */
882 #define DHD_IOCTL_SMLEN 256     /* "small" length ioctl buffer required */
883
884 /* common ioctl definitions */
885 #define DHD_GET_MAGIC                           0
886 #define DHD_GET_VERSION                         1
887 #define DHD_GET_VAR                             2
888 #define DHD_SET_VAR                             3
889
890 /* message levels */
891 #define DHD_ERROR_VAL   0x0001
892 #define DHD_TRACE_VAL   0x0002
893 #define DHD_INFO_VAL    0x0004
894 #define DHD_DATA_VAL    0x0008
895 #define DHD_CTL_VAL     0x0010
896 #define DHD_TIMER_VAL   0x0020
897 #define DHD_HDRS_VAL    0x0040
898 #define DHD_BYTES_VAL   0x0080
899 #define DHD_INTR_VAL    0x0100
900 #define DHD_LOG_VAL     0x0200
901 #define DHD_GLOM_VAL    0x0400
902 #define DHD_EVENT_VAL   0x0800
903 #define DHD_BTA_VAL     0x1000
904 #define DHD_ISCAN_VAL 0x2000
905
906 #ifdef SDTEST
907 /* For pktgen iovar */
908 typedef struct dhd_pktgen {
909         uint version;           /* To allow structure change tracking */
910         uint freq;              /* Max ticks between tx/rx attempts */
911         uint count;             /* Test packets to send/rcv each attempt */
912         uint print;             /* Print counts every <print> attempts */
913         uint total;             /* Total packets (or bursts) */
914         uint minlen;            /* Minimum length of packets to send */
915         uint maxlen;            /* Maximum length of packets to send */
916         uint numsent;           /* Count of test packets sent */
917         uint numrcvd;           /* Count of test packets received */
918         uint numfail;           /* Count of test send failures */
919         uint mode;              /* Test mode (type of test packets) */
920         uint stop;              /* Stop after this many tx failures */
921 } dhd_pktgen_t;
922
923 /* Version in case structure changes */
924 #define DHD_PKTGEN_VERSION 2
925
926 /* Type of test packets to use */
927 #define DHD_PKTGEN_ECHO         1       /* Send echo requests */
928 #define DHD_PKTGEN_SEND         2       /* Send discard packets */
929 #define DHD_PKTGEN_RXBURST      3       /* Request dongle send N packets */
930 #define DHD_PKTGEN_RECV         4       /* Continuous rx from continuous
931                                          tx dongle */
932 #endif                          /* SDTEST */
933
934 /* Enter idle immediately (no timeout) */
935 #define DHD_IDLE_IMMEDIATE      (-1)
936
937 /* Values for idleclock iovar: other values are the sd_divisor to use
938          when idle */
939 #define DHD_IDLE_ACTIVE 0       /* Do not request any SD clock change
940                                  when idle */
941 #define DHD_IDLE_STOP   (-1)    /* Request SD clock be stopped
942                                  (and use SD1 mode) */
943
944 #endif                          /* _dhd_h_ */