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 <asm/uaccess.h>
35 #include <asm/unaligned.h>
36 /* The kernel threading is sdio-specific */
37
38 #include <wlioctl.h>
39
40 /* Forward decls */
41 struct dhd_bus;
42 struct dhd_prot;
43 struct dhd_info;
44
45 /* The level of bus communication with the dongle */
46 enum dhd_bus_state {
47 DHD_BUS_DOWN, /* Not ready for frame transfers */
48 DHD_BUS_LOAD, /* Download access only (CPU reset) */
49 DHD_BUS_DATA /* Ready for frame transfers */
50 };
51
52 /* Common structure for module and instance linkage */
53 typedef struct dhd_pub {
54 /* Linkage ponters */
55 struct dhd_bus *bus; /* Bus module handle */
56 struct dhd_prot *prot; /* Protocol module handle */
57 struct dhd_info *info; /* Info module handle */
58
59 /* Internal dhd items */
60 bool up; /* Driver up/down (to OS) */
61 bool txoff; /* Transmit flow-controlled */
62 bool dongle_reset; /* true = DEVRESET put dongle into reset */
63 enum dhd_bus_state busstate;
64 uint hdrlen; /* Total DHD header length (proto + bus) */
65 uint maxctl; /* Max size rxctl request from proto to bus */
66 uint rxsz; /* Rx buffer size bus module should use */
67 u8 wme_dp; /* wme discard priority */
68
69 /* Dongle media info */
70 bool iswl; /* Dongle-resident driver is wl */
71 unsigned long drv_version; /* Version of dongle-resident driver */
72 u8 mac[ETH_ALEN]; /* MAC address obtained from dongle */
73 dngl_stats_t dstats; /* Stats for dongle-based data */
74
75 /* Additional stats for the bus level */
76 unsigned long tx_packets; /* Data packets sent to dongle */
77 unsigned long tx_multicast; /* Multicast data packets sent to dongle */
78 unsigned long tx_errors; /* Errors in sending data to dongle */
79 unsigned long tx_ctlpkts; /* Control packets sent to dongle */
80 unsigned long tx_ctlerrs; /* Errors sending control frames to dongle */
81 unsigned long rx_packets; /* Packets sent up the network interface */
82 unsigned long rx_multicast; /* Multicast packets sent up the network
83 interface */
84 unsigned long rx_errors; /* Errors processing rx data packets */
85 unsigned long rx_ctlpkts; /* Control frames processed from dongle */
86 unsigned long rx_ctlerrs; /* Errors in processing rx control frames */
87 unsigned long rx_dropped; /* Packets dropped locally (no memory) */
88 unsigned long rx_flushed; /* Packets flushed due to
89 unscheduled sendup thread */
90 unsigned long wd_dpc_sched; /* Number of times dhd dpc scheduled by
91 watchdog timer */
92
93 unsigned long rx_readahead_cnt; /* Number of packets where header read-ahead
94 was used. */
95 unsigned long tx_realloc; /* Number of tx packets we had to realloc for
96 headroom */
97 unsigned long fc_packets; /* Number of flow control pkts recvd */
98
99 /* Last error return */
100 int bcmerror;
101 uint tickcnt;
102
103 /* Last error from dongle */
104 int dongle_error;
105
106 /* Suspend disable flag flag */
107 int suspend_disable_flag; /* "1" to disable all extra powersaving
108 during suspend */
109 int in_suspend; /* flag set to 1 when early suspend called */
110 #ifdef PNO_SUPPORT
111 int pno_enable; /* pno status : "1" is pno enable */
112 #endif /* PNO_SUPPORT */
113 int dtim_skip; /* dtim skip , default 0 means wake each dtim */
114
115 /* Pkt filter defination */
116 char *pktfilter[100];
117 int pktfilter_count;
118
119 u8 country_code[WLC_CNTRY_BUF_SZ];
120 char eventmask[WL_EVENTING_MASK_LEN];
121
122 } dhd_pub_t;
123
124 #if defined(CONFIG_PM_SLEEP)
125
126 #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
127 #define _DHD_PM_RESUME_WAIT(a, b) do {\
128 int retry = 0; \
129 while (dhd_mmc_suspend && retry++ != b) { \
130 wait_event_timeout(a, false, HZ/100); \
131 } \
132 } while (0)
133 #define DHD_PM_RESUME_WAIT(a) _DHD_PM_RESUME_WAIT(a, 30)
134 #define DHD_PM_RESUME_WAIT_FOREVER(a) _DHD_PM_RESUME_WAIT(a, ~0)
135 #define DHD_PM_RESUME_RETURN_ERROR(a) \
136 do { if (dhd_mmc_suspend) return a; } while (0)
137 #define DHD_PM_RESUME_RETURN do { if (dhd_mmc_suspend) return; } while (0)
138
139 #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
140 #define SPINWAIT_SLEEP(a, exp, us) do { \
141 uint countdown = (us) + 9999; \
142 while ((exp) && (countdown >= 10000)) { \
143 wait_event_timeout(a, false, HZ/100); \
144 countdown -= 10000; \
145 } \
146 } while (0)
147
148 #else
149
150 #define DHD_PM_RESUME_WAIT_INIT(a)
151 #define DHD_PM_RESUME_WAIT(a)
152 #define DHD_PM_RESUME_WAIT_FOREVER(a)
153 #define DHD_PM_RESUME_RETURN_ERROR(a)
154 #define DHD_PM_RESUME_RETURN
155
156 #define DHD_SPINWAIT_SLEEP_INIT(a)
157 #define SPINWAIT_SLEEP(a, exp, us) do { \
158 uint countdown = (us) + 9; \
159 while ((exp) && (countdown >= 10)) { \
160 udelay(10); \
161 countdown -= 10; \
162 } \
163 } while (0)
164
165 #endif /* defined(CONFIG_PM_SLEEP) */
166 #define DHD_IF_VIF 0x01 /* Virtual IF (Hidden from user) */
167
MUTEX_LOCK_INIT(dhd_pub_t * dhdp)168 static inline void MUTEX_LOCK_INIT(dhd_pub_t *dhdp)
169 {
170 }
171
MUTEX_LOCK(dhd_pub_t * dhdp)172 static inline void MUTEX_LOCK(dhd_pub_t *dhdp)
173 {
174 }
175
MUTEX_UNLOCK(dhd_pub_t * dhdp)176 static inline void MUTEX_UNLOCK(dhd_pub_t *dhdp)
177 {
178 }
179
MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)180 static inline void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t *dhdp)
181 {
182 }
183
MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)184 static inline void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t *dhdp)
185 {
186 }
187
MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)188 static inline void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t *dhdp)
189 {
190 }
191
MUTEX_LOCK_WL_SCAN_SET_INIT(void)192 static inline void MUTEX_LOCK_WL_SCAN_SET_INIT(void)
193 {
194 }
195
MUTEX_LOCK_WL_SCAN_SET(void)196 static inline void MUTEX_LOCK_WL_SCAN_SET(void)
197 {
198 }
199
MUTEX_UNLOCK_WL_SCAN_SET(void)200 static inline void MUTEX_UNLOCK_WL_SCAN_SET(void)
201 {
202 }
203
204 typedef struct dhd_if_event {
205 u8 ifidx;
206 u8 action;
207 u8 flags;
208 u8 bssidx;
209 } dhd_if_event_t;
210
211 /*
212 * Exported from dhd OS modules (dhd_linux/dhd_ndis)
213 */
214
215 /* Indication from bus module regarding presence/insertion of dongle.
216 * Return dhd_pub_t pointer, used as handle to OS module in later calls.
217 * Returned structure should have bus and prot pointers filled in.
218 * bus_hdrlen specifies required headroom for bus module header.
219 */
220 extern dhd_pub_t *dhd_attach(struct dhd_bus *bus,
221 uint bus_hdrlen);
222 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
223
224 /* Indication from bus module regarding removal/absence of dongle */
225 extern void dhd_detach(dhd_pub_t *dhdp);
226
227 /* Indication from bus module to change flow-control state */
228 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
229
230 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q,
231 struct sk_buff *pkt, int prec);
232
233 /* Receive frame for delivery to OS. Callee disposes of rxp. */
234 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx,
235 struct sk_buff *rxp, int numpkt);
236
237 /* Return pointer to interface name */
238 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
239
240 /* Request scheduling of the bus dpc */
241 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
242
243 /* Notify tx completion */
244 extern void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success);
245
246 /* Query ioctl */
247 extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
248 uint len);
249
250 /* OS independent layer functions */
251 extern int dhd_os_proto_block(dhd_pub_t *pub);
252 extern int dhd_os_proto_unblock(dhd_pub_t *pub);
253 extern int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition,
254 bool *pending);
255 extern int dhd_os_ioctl_resp_wake(dhd_pub_t *pub);
256 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
257 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
258 extern void *dhd_os_open_image(char *filename);
259 extern int dhd_os_get_image_block(char *buf, int len, void *image);
260 extern void dhd_os_close_image(void *image);
261 extern void dhd_os_wd_timer(void *bus, uint wdtick);
262 extern void dhd_os_sdlock(dhd_pub_t *pub);
263 extern void dhd_os_sdunlock(dhd_pub_t *pub);
264 extern void dhd_os_sdlock_txq(dhd_pub_t *pub);
265 extern void dhd_os_sdunlock_txq(dhd_pub_t *pub);
266 extern void dhd_os_sdlock_rxq(dhd_pub_t *pub);
267 extern void dhd_os_sdunlock_rxq(dhd_pub_t *pub);
268 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t *pub);
269 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
270 extern int dhd_custom_get_mac_address(unsigned char *buf);
271 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t *pub);
272 extern void dhd_os_sdlock_eventq(dhd_pub_t *pub);
273 extern void dhd_os_sdunlock_eventq(dhd_pub_t *pub);
274 #ifdef DHD_DEBUG
275 extern int write_to_file(dhd_pub_t *dhd, u8 *buf, int size);
276 #endif /* DHD_DEBUG */
277 #if defined(OOB_INTR_ONLY)
278 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
279 #endif /* defined(OOB_INTR_ONLY) */
280 extern void dhd_os_sdtxlock(dhd_pub_t *pub);
281 extern void dhd_os_sdtxunlock(dhd_pub_t *pub);
282
283 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
284
285 typedef struct {
286 u32 limit; /* Expiration time (usec) */
287 u32 increment; /* Current expiration increment (usec) */
288 u32 elapsed; /* Current elapsed time (usec) */
289 u32 tick; /* O/S tick time (usec) */
290 } dhd_timeout_t;
291
292 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
293 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
294
295 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
296 extern u8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
297 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
298 wl_event_msg_t *, void **data_ptr);
299
300 extern void dhd_common_init(void);
301
302 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
303 char *name, u8 *mac_addr, u32 flags, u8 bssidx);
304 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
305
306 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char *name);
307 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
308
309 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
310 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, unsigned char * cp,
311 int len);
312
313 /* Send packet to dongle via data channel */
314 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pkt);
315
316 /* Send event to host */
317 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event,
318 void *data);
319 extern int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag);
320 extern uint dhd_bus_status(dhd_pub_t *dhdp);
321 extern int dhd_bus_start(dhd_pub_t *dhdp);
322
323 enum cust_gpio_modes {
324 WLAN_RESET_ON,
325 WLAN_RESET_OFF,
326 WLAN_POWER_ON,
327 WLAN_POWER_OFF
328 };
329 /*
330 * Insmod parameters for debug/test
331 */
332
333 /* Watchdog timer interval */
334 extern uint dhd_watchdog_ms;
335
336 #if defined(DHD_DEBUG)
337 /* Console output poll interval */
338 extern uint dhd_console_ms;
339 #endif /* defined(DHD_DEBUG) */
340
341 /* Use interrupts */
342 extern uint dhd_intr;
343
344 /* Use polling */
345 extern uint dhd_poll;
346
347 /* ARP offload agent mode */
348 extern uint dhd_arp_mode;
349
350 /* ARP offload enable */
351 extern uint dhd_arp_enable;
352
353 /* Pkt filte enable control */
354 extern uint dhd_pkt_filter_enable;
355
356 /* Pkt filter init setup */
357 extern uint dhd_pkt_filter_init;
358
359 /* Pkt filter mode control */
360 extern uint dhd_master_mode;
361
362 /* Roaming mode control */
363 extern uint dhd_roam;
364
365 /* Roaming mode control */
366 extern uint dhd_radio_up;
367
368 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
369 extern int dhd_idletime;
370 #define DHD_IDLETIME_TICKS 1
371
372 /* SDIO Drive Strength */
373 extern uint dhd_sdiod_drive_strength;
374
375 /* Override to force tx queueing all the time */
376 extern uint dhd_force_tx_queueing;
377
378 #ifdef SDTEST
379 /* Echo packet generator (SDIO), pkts/s */
380 extern uint dhd_pktgen;
381
382 /* Echo packet len (0 => sawtooth, max 1800) */
383 extern uint dhd_pktgen_len;
384 #define MAX_PKTGEN_LEN 1800
385 #endif
386
387 /* optionally set by a module_param_string() */
388 #define MOD_PARAM_PATHLEN 2048
389 extern char fw_path[MOD_PARAM_PATHLEN];
390 extern char nv_path[MOD_PARAM_PATHLEN];
391
392 /* For supporting multiple interfaces */
393 #define DHD_MAX_IFS 16
394 #define DHD_DEL_IF -0xe
395 #define DHD_BAD_IF -0xf
396
397 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool * lockvar);
398 extern void dhd_wait_event_wakeup(dhd_pub_t *dhd);
399
400 #endif /* _dhd_h_ */
401