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