]> rtime.felk.cvut.cz Git - mcf548x/linux.git/blob - drivers/staging/brcm80211/include/dbus.h
Initial 2.6.37
[mcf548x/linux.git] / drivers / staging / brcm80211 / include / dbus.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 #ifndef __DBUS_H__
18 #define __DBUS_H__
19
20 #ifdef BCMDBG
21 #define DBUSERR(args)        do { if (net_ratelimit()) printf args; } while (0)
22 #define DBUSTRACE(args)
23 #define DBUSDBGLOCK(args)
24
25 #else
26 #define DBUSTRACE(args)
27 #define DBUSERR(args)
28 #define DBUSDBGLOCK(args)
29 #endif
30
31 enum {
32         DBUS_OK = 0,
33         DBUS_ERR = -200,
34         DBUS_ERR_TIMEOUT,
35         DBUS_ERR_DISCONNECT,
36         DBUS_ERR_NODEVICE,
37         DBUS_ERR_UNSUPPORTED,
38         DBUS_ERR_PENDING,
39         DBUS_ERR_NOMEM,
40         DBUS_ERR_TXFAIL,
41         DBUS_ERR_TXTIMEOUT,
42         DBUS_ERR_TXDROP,
43         DBUS_ERR_RXFAIL,
44         DBUS_ERR_RXDROP,
45         DBUS_ERR_TXCTLFAIL,
46         DBUS_ERR_RXCTLFAIL,
47         DBUS_ERR_REG_PARAM,
48         DBUS_STATUS_CANCELLED
49 };
50
51 #define ERR_CBMASK_TXFAIL               0x00000001
52 #define ERR_CBMASK_RXFAIL               0x00000002
53 #define ERR_CBMASK_ALL                  0xFFFFFFFF
54
55 #define DBUS_CBCTL_WRITE                0
56 #define DBUS_CBCTL_READ                 1
57
58 #define DBUS_TX_RETRY_LIMIT             3       /* retries for failed txirb */
59 #define DBUS_TX_TIMEOUT_INTERVAL        250     /* timeout for txirb complete, in ms */
60
61 #define DBUS_BUFFER_SIZE_TX     5000
62 #define DBUS_BUFFER_SIZE_RX     5000
63
64 #define DBUS_BUFFER_SIZE_TX_NOAGG       2048
65 #define DBUS_BUFFER_SIZE_RX_NOAGG       2048
66
67 /* DBUS types */
68 enum {
69         DBUS_USB,
70         DBUS_SDIO,
71         DBUS_SPI,
72         DBUS_UNKNOWN
73 };
74
75 enum dbus_state {
76         DBUS_STATE_DL_PENDING,
77         DBUS_STATE_DL_DONE,
78         DBUS_STATE_UP,
79         DBUS_STATE_DOWN,
80         DBUS_STATE_PNP_FWDL,
81         DBUS_STATE_DISCONNECT
82 };
83
84 enum dbus_pnp_state {
85         DBUS_PNP_DISCONNECT,
86         DBUS_PNP_SLEEP,
87         DBUS_PNP_RESUME
88 };
89
90 typedef enum _DEVICE_SPEED {
91         INVALID_SPEED = -1,
92         LOW_SPEED = 1,          /* USB 1.1: 1.5 Mbps */
93         FULL_SPEED,             /* USB 1.1: 12  Mbps */
94         HIGH_SPEED,             /* USB 2.0: 480 Mbps */
95         SUPER_SPEED,            /* USB 3.0: 4.8 Gbps */
96 } DEVICE_SPEED;
97
98 typedef struct {
99         int bustype;
100         int vid;
101         int pid;
102         int devid;
103         int chiprev;            /* chip revsion number */
104         int mtu;
105         int nchan;              /* Data Channels */
106 } dbus_attrib_t;
107
108 /* FIX: Account for errors related to DBUS;
109  * Let upper layer account for packets/bytes
110  */
111 typedef struct {
112         u32 rx_errors;
113         u32 tx_errors;
114         u32 rx_dropped;
115         u32 tx_dropped;
116 } dbus_stats_t;
117
118 /*
119  * Configurable BUS parameters
120  */
121 typedef struct {
122         bool rxctl_deferrespok;
123 } dbus_config_t;
124
125 struct dbus_callbacks;
126 struct exec_parms;
127
128 typedef void *(*probe_cb_t) (void *arg, const char *desc, u32 bustype,
129                              u32 hdrlen);
130 typedef void (*disconnect_cb_t) (void *arg);
131 typedef void *(*exec_cb_t) (struct exec_parms *args);
132
133 /* Client callbacks registered during dbus_attach() */
134 typedef struct dbus_callbacks {
135         void (*send_complete) (void *cbarg, void *info, int status);
136         void (*recv_buf) (void *cbarg, u8 *buf, int len);
137         void (*recv_pkt) (void *cbarg, void *pkt);
138         void (*txflowcontrol) (void *cbarg, bool onoff);
139         void (*errhandler) (void *cbarg, int err);
140         void (*ctl_complete) (void *cbarg, int type, int status);
141         void (*state_change) (void *cbarg, int state);
142         void *(*pktget) (void *cbarg, uint len, bool send);
143         void (*pktfree) (void *cbarg, void *p, bool send);
144 } dbus_callbacks_t;
145
146 struct dbus_pub;
147 struct bcmstrbuf;
148 struct dbus_irb;
149 struct dbus_irb_rx;
150 struct dbus_irb_tx;
151 struct dbus_intf_callbacks;
152
153 typedef struct {
154         void *(*attach) (struct dbus_pub *pub, void *cbarg,
155                          struct dbus_intf_callbacks *cbs);
156         void (*detach) (struct dbus_pub *pub, void *bus);
157
158         int (*up) (void *bus);
159         int (*down) (void *bus);
160         int (*send_irb) (void *bus, struct dbus_irb_tx *txirb);
161         int (*recv_irb) (void *bus, struct dbus_irb_rx *rxirb);
162         int (*cancel_irb) (void *bus, struct dbus_irb_tx *txirb);
163         int (*send_ctl) (void *bus, u8 *buf, int len);
164         int (*recv_ctl) (void *bus, u8 *buf, int len);
165         int (*get_stats) (void *bus, dbus_stats_t *stats);
166         int (*get_attrib) (void *bus, dbus_attrib_t *attrib);
167
168         int (*pnp) (void *bus, int event);
169         int (*remove) (void *bus);
170         int (*resume) (void *bus);
171         int (*suspend) (void *bus);
172         int (*stop) (void *bus);
173         int (*reset) (void *bus);
174
175         /* Access to bus buffers directly */
176         void *(*pktget) (void *bus, int len);
177         void (*pktfree) (void *bus, void *pkt);
178
179         int (*iovar_op) (void *bus, const char *name, void *params, int plen,
180                          void *arg, int len, bool set);
181         void (*dump) (void *bus, struct bcmstrbuf *strbuf);
182         int (*set_config) (void *bus, dbus_config_t *config);
183         int (*get_config) (void *bus, dbus_config_t *config);
184
185          bool(*device_exists) (void *bus);
186          bool(*dlneeded) (void *bus);
187         int (*dlstart) (void *bus, u8 *fw, int len);
188         int (*dlrun) (void *bus);
189          bool(*recv_needed) (void *bus);
190
191         void *(*exec_rxlock) (void *bus, exec_cb_t func,
192                               struct exec_parms *args);
193         void *(*exec_txlock) (void *bus, exec_cb_t func,
194                               struct exec_parms *args);
195
196         int (*tx_timer_init) (void *bus);
197         int (*tx_timer_start) (void *bus, uint timeout);
198         int (*tx_timer_stop) (void *bus);
199
200         int (*sched_dpc) (void *bus);
201         int (*lock) (void *bus);
202         int (*unlock) (void *bus);
203         int (*sched_probe_cb) (void *bus);
204
205         int (*shutdown) (void *bus);
206
207         int (*recv_stop) (void *bus);
208         int (*recv_resume) (void *bus);
209
210         /* Add from the bottom */
211 } dbus_intf_t;
212
213 typedef struct dbus_pub {
214         struct osl_info *osh;
215         dbus_stats_t stats;
216         dbus_attrib_t attrib;
217         enum dbus_state busstate;
218         DEVICE_SPEED device_speed;
219         int ntxq, nrxq, rxsize;
220         void *bus;
221         struct shared_info *sh;
222 } dbus_pub_t;
223
224 #define BUS_INFO(bus, type) (((type *) bus)->pub->bus)
225
226 /*
227  * Public Bus Function Interface
228  */
229 extern int dbus_register(int vid, int pid, probe_cb_t prcb,
230                          disconnect_cb_t discb, void *prarg, void *param1,
231                          void *param2);
232 extern int dbus_deregister(void);
233
234 extern const dbus_pub_t *dbus_attach(struct osl_info *osh, int rxsize, int nrxq,
235                                      int ntxq, void *cbarg,
236                                      dbus_callbacks_t *cbs,
237                                      struct shared_info *sh);
238 extern void dbus_detach(const dbus_pub_t *pub);
239
240 extern int dbus_up(const dbus_pub_t *pub);
241 extern int dbus_down(const dbus_pub_t *pub);
242 extern int dbus_stop(const dbus_pub_t *pub);
243 extern int dbus_shutdown(const dbus_pub_t *pub);
244 extern void dbus_flowctrl_rx(const dbus_pub_t *pub, bool on);
245
246 extern int dbus_send_buf(const dbus_pub_t *pub, u8 *buf, int len,
247                          void *info);
248 extern int dbus_send_pkt(const dbus_pub_t *pub, void *pkt, void *info);
249 extern int dbus_send_ctl(const dbus_pub_t *pub, u8 *buf, int len);
250 extern int dbus_recv_ctl(const dbus_pub_t *pub, u8 *buf, int len);
251
252 extern int dbus_get_stats(const dbus_pub_t *pub, dbus_stats_t *stats);
253 extern int dbus_get_attrib(const dbus_pub_t *pub, dbus_attrib_t *attrib);
254 extern int dbus_get_device_speed(const dbus_pub_t *pub);
255 extern int dbus_set_config(const dbus_pub_t *pub, dbus_config_t *config);
256 extern int dbus_get_config(const dbus_pub_t *pub, dbus_config_t *config);
257
258 extern void *dbus_pktget(const dbus_pub_t *pub, int len);
259 extern void dbus_pktfree(const dbus_pub_t *pub, void *pkt);
260
261 extern int dbus_set_errmask(const dbus_pub_t *pub, u32 mask);
262 extern int dbus_pnp_sleep(const dbus_pub_t *pub);
263 extern int dbus_pnp_resume(const dbus_pub_t *pub, int *fw_reload);
264 extern int dbus_pnp_disconnect(const dbus_pub_t *pub);
265
266 extern int dbus_iovar_op(const dbus_pub_t *pub, const char *name,
267                          void *params, int plen, void *arg, int len, bool set);
268 #ifdef BCMDBG
269 extern void dbus_hist_dump(const dbus_pub_t *pub, struct bcmstrbuf *b);
270 #endif                          /* BCMDBG */
271 /*
272  * Private Common Bus Interface
273  */
274
275 /* IO Request Block (IRB) */
276 typedef struct dbus_irb {
277         struct dbus_irb *next;  /* it's casted from dbus_irb_tx or dbus_irb_rx struct */
278 } dbus_irb_t;
279
280 typedef struct dbus_irb_rx {
281         struct dbus_irb irb;    /* Must be first */
282         u8 *buf;
283         int buf_len;
284         int actual_len;
285         void *pkt;
286         void *info;
287         void *arg;
288 } dbus_irb_rx_t;
289
290 typedef struct dbus_irb_tx {
291         struct dbus_irb irb;    /* Must be first */
292         u8 *buf;
293         int len;
294         void *pkt;
295         int retry_count;
296         void *info;
297         void *arg;
298 } dbus_irb_tx_t;
299
300 /* DBUS interface callbacks are different from user callbacks
301  * so, internally, different info can be passed to upper layer
302  */
303 typedef struct dbus_intf_callbacks {
304         void (*send_irb_timeout) (void *cbarg, dbus_irb_tx_t *txirb);
305         void (*send_irb_complete) (void *cbarg, dbus_irb_tx_t *txirb,
306                                    int status);
307         void (*recv_irb_complete) (void *cbarg, dbus_irb_rx_t *rxirb,
308                                    int status);
309         void (*errhandler) (void *cbarg, int err);
310         void (*ctl_complete) (void *cbarg, int type, int status);
311         void (*state_change) (void *cbarg, int state);
312          bool(*isr) (void *cbarg, bool *wantdpc);
313          bool(*dpc) (void *cbarg, bool bounded);
314         void (*watchdog) (void *cbarg);
315         void *(*pktget) (void *cbarg, uint len, bool send);
316         void (*pktfree) (void *cbarg, void *p, bool send);
317         struct dbus_irb *(*getirb) (void *cbarg, bool send);
318         void (*rxerr_indicate) (void *cbarg, bool on);
319 } dbus_intf_callbacks_t;
320
321 /*
322  * Porting: To support new bus, port these functions below
323  */
324
325 /*
326  * Bus specific Interface
327  * Implemented by dbus_usb.c/dbus_sdio.c
328  */
329 extern int dbus_bus_register(int vid, int pid, probe_cb_t prcb,
330                              disconnect_cb_t discb, void *prarg,
331                              dbus_intf_t **intf, void *param1, void *param2);
332 extern int dbus_bus_deregister(void);
333
334 /*
335  * Bus-specific and OS-specific Interface
336  * Implemented by dbus_usb_[linux/ndis].c/dbus_sdio_[linux/ndis].c
337  */
338 extern int dbus_bus_osl_register(int vid, int pid, probe_cb_t prcb,
339                                  disconnect_cb_t discb, void *prarg,
340                                  dbus_intf_t **intf, void *param1,
341                                  void *param2);
342 extern int dbus_bus_osl_deregister(void);
343
344 /*
345  * Bus-specific, OS-specific, HW-specific Interface
346  * Mainly for SDIO Host HW controller
347  */
348 extern int dbus_bus_osl_hw_register(int vid, int pid, probe_cb_t prcb,
349                                     disconnect_cb_t discb, void *prarg,
350                                     dbus_intf_t **intf);
351 extern int dbus_bus_osl_hw_deregister(void);
352
353 #endif                          /* __DBUS_H__ */