2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
21 #define DBUSERR(args) do { if (net_ratelimit()) printf args; } while (0)
22 #define DBUSTRACE(args)
23 #define DBUSDBGLOCK(args)
26 #define DBUSTRACE(args)
28 #define DBUSDBGLOCK(args)
51 #define ERR_CBMASK_TXFAIL 0x00000001
52 #define ERR_CBMASK_RXFAIL 0x00000002
53 #define ERR_CBMASK_ALL 0xFFFFFFFF
55 #define DBUS_CBCTL_WRITE 0
56 #define DBUS_CBCTL_READ 1
58 #define DBUS_TX_RETRY_LIMIT 3 /* retries for failed txirb */
59 #define DBUS_TX_TIMEOUT_INTERVAL 250 /* timeout for txirb complete, in ms */
61 #define DBUS_BUFFER_SIZE_TX 5000
62 #define DBUS_BUFFER_SIZE_RX 5000
64 #define DBUS_BUFFER_SIZE_TX_NOAGG 2048
65 #define DBUS_BUFFER_SIZE_RX_NOAGG 2048
76 DBUS_STATE_DL_PENDING,
90 typedef enum _DEVICE_SPEED {
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 */
103 int chiprev; /* chip revsion number */
105 int nchan; /* Data Channels */
108 /* FIX: Account for errors related to DBUS;
109 * Let upper layer account for packets/bytes
119 * Configurable BUS parameters
122 bool rxctl_deferrespok;
125 struct dbus_callbacks;
128 typedef void *(*probe_cb_t) (void *arg, const char *desc, u32 bustype,
130 typedef void (*disconnect_cb_t) (void *arg);
131 typedef void *(*exec_cb_t) (struct exec_parms *args);
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);
151 struct dbus_intf_callbacks;
154 void *(*attach) (struct dbus_pub *pub, void *cbarg,
155 struct dbus_intf_callbacks *cbs);
156 void (*detach) (struct dbus_pub *pub, void *bus);
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);
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);
175 /* Access to bus buffers directly */
176 void *(*pktget) (void *bus, int len);
177 void (*pktfree) (void *bus, void *pkt);
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);
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);
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);
196 int (*tx_timer_init) (void *bus);
197 int (*tx_timer_start) (void *bus, uint timeout);
198 int (*tx_timer_stop) (void *bus);
200 int (*sched_dpc) (void *bus);
201 int (*lock) (void *bus);
202 int (*unlock) (void *bus);
203 int (*sched_probe_cb) (void *bus);
205 int (*shutdown) (void *bus);
207 int (*recv_stop) (void *bus);
208 int (*recv_resume) (void *bus);
210 /* Add from the bottom */
213 typedef struct dbus_pub {
214 struct osl_info *osh;
216 dbus_attrib_t attrib;
217 enum dbus_state busstate;
218 DEVICE_SPEED device_speed;
219 int ntxq, nrxq, rxsize;
221 struct shared_info *sh;
224 #define BUS_INFO(bus, type) (((type *) bus)->pub->bus)
227 * Public Bus Function Interface
229 extern int dbus_register(int vid, int pid, probe_cb_t prcb,
230 disconnect_cb_t discb, void *prarg, void *param1,
232 extern int dbus_deregister(void);
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);
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);
246 extern int dbus_send_buf(const dbus_pub_t *pub, u8 *buf, int len,
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);
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);
258 extern void *dbus_pktget(const dbus_pub_t *pub, int len);
259 extern void dbus_pktfree(const dbus_pub_t *pub, void *pkt);
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);
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);
269 extern void dbus_hist_dump(const dbus_pub_t *pub, struct bcmstrbuf *b);
272 * Private Common Bus Interface
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 */
280 typedef struct dbus_irb_rx {
281 struct dbus_irb irb; /* Must be first */
290 typedef struct dbus_irb_tx {
291 struct dbus_irb irb; /* Must be first */
300 /* DBUS interface callbacks are different from user callbacks
301 * so, internally, different info can be passed to upper layer
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,
307 void (*recv_irb_complete) (void *cbarg, dbus_irb_rx_t *rxirb,
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;
322 * Porting: To support new bus, port these functions below
326 * Bus specific Interface
327 * Implemented by dbus_usb.c/dbus_sdio.c
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);
335 * Bus-specific and OS-specific Interface
336 * Implemented by dbus_usb_[linux/ndis].c/dbus_sdio_[linux/ndis].c
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,
342 extern int dbus_bus_osl_deregister(void);
345 * Bus-specific, OS-specific, HW-specific Interface
346 * Mainly for SDIO Host HW controller
348 extern int dbus_bus_osl_hw_register(int vid, int pid, probe_cb_t prcb,
349 disconnect_cb_t discb, void *prarg,
351 extern int dbus_bus_osl_hw_deregister(void);
353 #endif /* __DBUS_H__ */