xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/include/dbus.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Dongle BUS interface Abstraction layer
3  *   target serial buses like USB, SDIO, SPI, etc.
4  *
5  * Copyright (C) 2020, Broadcom.
6  *
7  *      Unless you and Broadcom execute a separate written software license
8  * agreement governing use of this software, this software is licensed to you
9  * under the terms of the GNU General Public License version 2 (the "GPL"),
10  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11  * following added to such license:
12  *
13  *      As a special exception, the copyright holders of this software give you
14  * permission to link this software with independent modules, and to copy and
15  * distribute the resulting executable under terms of your choice, provided that
16  * you also meet, for each linked independent module, the terms and conditions of
17  * the license of that module.  An independent module is a module which is not
18  * derived from this software.  The special exception does not apply to any
19  * modifications of the software.
20  *
21  *
22  * <<Broadcom-WL-IPTag/Open:>>
23  */
24 
25 #ifndef __DBUS_H__
26 #define __DBUS_H__
27 
28 #include "typedefs.h"
29 #include <dhd_linux.h>
30 
31 extern uint dbus_msglevel;
32 #define DBUS_ERROR_VAL	0x0001
33 #define DBUS_TRACE_VAL	0x0002
34 #define DBUS_INFO_VAL	0x0004
35 
36 #if defined(DHD_DEBUG)
37 #define DBUSERR(args)		do {if (dbus_msglevel & DBUS_ERROR_VAL) printf args;} while (0)
38 #define DBUSTRACE(args)		do {if (dbus_msglevel & DBUS_TRACE_VAL) printf args;} while (0)
39 #define DBUSINFO(args)		do {if (dbus_msglevel & DBUS_INFO_VAL) printf args;} while (0)
40 #else /* defined(DHD_DEBUG) */
41 #define DBUSERR(args)
42 #define DBUSTRACE(args)
43 #define DBUSINFO(args)
44 #endif
45 
46 enum {
47 	DBUS_OK = 0,
48 	DBUS_ERR = -200,
49 	DBUS_ERR_TIMEOUT,
50 	DBUS_ERR_DISCONNECT,
51 	DBUS_ERR_NODEVICE,
52 	DBUS_ERR_UNSUPPORTED,
53 	DBUS_ERR_PENDING,
54 	DBUS_ERR_NOMEM,
55 	DBUS_ERR_TXFAIL,
56 	DBUS_ERR_TXTIMEOUT,
57 	DBUS_ERR_TXDROP,
58 	DBUS_ERR_RXFAIL,
59 	DBUS_ERR_RXDROP,
60 	DBUS_ERR_TXCTLFAIL,
61 	DBUS_ERR_RXCTLFAIL,
62 	DBUS_ERR_REG_PARAM,
63 	DBUS_STATUS_CANCELLED,
64 	DBUS_ERR_NVRAM,
65 	DBUS_JUMBO_NOMATCH,
66 	DBUS_JUMBO_BAD_FORMAT,
67 	DBUS_NVRAM_NONTXT,
68 	DBUS_ERR_RXZLP
69 };
70 
71 #define BCM_OTP_SIZE_43236  84	/* number of 16 bit values */
72 #define BCM_OTP_SW_RGN_43236	24  /* start offset of SW config region */
73 #define BCM_OTP_ADDR_43236 0x18000800 /* address of otp base */
74 
75 #define ERR_CBMASK_TXFAIL		0x00000001
76 #define ERR_CBMASK_RXFAIL		0x00000002
77 #define ERR_CBMASK_ALL			0xFFFFFFFF
78 
79 #define DBUS_CBCTL_WRITE			0
80 #define DBUS_CBCTL_READ				1
81 #if defined(INTR_EP_ENABLE)
82 #define DBUS_CBINTR_POLL			2
83 #endif /* defined(INTR_EP_ENABLE) */
84 
85 #define DBUS_TX_RETRY_LIMIT		3		/* retries for failed txirb */
86 #define DBUS_TX_TIMEOUT_INTERVAL	250		/* timeout for txirb complete, in ms */
87 
88 /*
89  * The max TCB/RCB data buffer size
90  * With USB RPC aggregation on,
91  *   rx buffer has to be a single big chunk memory due to dongle->host aggregation
92  *     Upper layer has to do byte copy to deaggregate the buffer to satisfy WL driver
93  *       one buffer per pkt requirement
94  *     Windows Vista may be able to use MDL to workaround this requirement
95  *   tx buffer has to copy over RPC buffer since they are managed in different domain
96  *     Without copy, DBUS and RPC has to break the encapsulation, which is not implemented
97  *     RPC aggregated buffer arrives as a chained buffers. bypte copy needs to traverse the chain
98  *     to form one continuous USB irb.
99  *   These buffer size must accomodate the MAX rpc agg size in both direction
100  *   #define BCM_RPC_TP_DNGL_AGG_MAX_BYTE
101  *   #define BCM_RPC_TP_HOST_AGG_MAX_BYTE
102  * Without USB RPC aggregation, these buffer size can be smaller like normal 2K
103  *  to fit max tcp pkt(ETH_MAX_DATA_SIZE) + d11/phy/rpc/overhead
104  *
105  * The number of buffer needed is upper layer dependent. e.g. rpc defines BCM_RPC_TP_DBUS_NTXQ
106  */
107 #define DBUS_BUFFER_SIZE_TX	32000
108 #define DBUS_BUFFER_SIZE_RX	24000
109 
110 #define DBUS_BUFFER_SIZE_TX_NOAGG	2048
111 #define DBUS_BUFFER_SIZE_RX_NOAGG	2048
112 
113 /** DBUS types */
114 enum {
115 	DBUS_USB,
116 	DBUS_SDIO,
117 	DBUS_SPI,
118 	DBUS_UNKNOWN
119 };
120 
121 enum dbus_state {
122 	DBUS_STATE_DL_PENDING,
123 	DBUS_STATE_DL_DONE,
124 	DBUS_STATE_UP,
125 	DBUS_STATE_DOWN,
126 	DBUS_STATE_PNP_FWDL,
127 	DBUS_STATE_DISCONNECT,
128 	DBUS_STATE_SLEEP,
129 	DBUS_STATE_DL_NEEDED
130 };
131 
132 enum dbus_pnp_state {
133 	DBUS_PNP_DISCONNECT,
134 	DBUS_PNP_SLEEP,
135 	DBUS_PNP_RESUME
136 };
137 
138 enum dbus_file {
139     DBUS_FIRMWARE,
140     DBUS_NVFILE
141 };
142 
143 typedef enum _DEVICE_SPEED {
144 	INVALID_SPEED = -1,
145 	LOW_SPEED     =  1,	/**< USB 1.1: 1.5 Mbps */
146 	FULL_SPEED,     	/**< USB 1.1: 12  Mbps */
147 	HIGH_SPEED,		/**< USB 2.0: 480 Mbps */
148 	SUPER_SPEED,		/**< USB 3.0: 4.8 Gbps */
149 } DEVICE_SPEED;
150 
151 typedef struct {
152 	int bustype;
153 	int vid;
154 	int pid;
155 	int devid;
156 	int chiprev; /**< chip revsion number */
157 	int mtu;
158 	int nchan; /**< Data Channels */
159 	int has_2nd_bulk_in_ep;
160 } dbus_attrib_t;
161 
162 /* FIX: Account for errors related to DBUS;
163  * Let upper layer account for packets/bytes
164  */
165 typedef struct {
166 	uint32 rx_errors;
167 	uint32 tx_errors;
168 	uint32 rx_dropped;
169 	uint32 tx_dropped;
170 } dbus_stats_t;
171 
172 /**
173  * Configurable BUS parameters
174  */
175 enum {
176 	DBUS_CONFIG_ID_RXCTL_DEFERRES = 1,
177 	DBUS_CONFIG_ID_AGGR_LIMIT,
178 	DBUS_CONFIG_ID_KEEPIF_ON_DEVRESET
179 };
180 
181 typedef struct {
182 	uint32 config_id;
183 	union {
184 		uint32 general_param;
185 		bool rxctl_deferrespok;
186 		struct {
187 			int maxrxsf;
188 			int maxrxsize;
189 			int maxtxsf;
190 			int maxtxsize;
191 		} aggr_param;
192 	};
193 } dbus_config_t;
194 
195 /**
196  * External Download Info
197  */
198 typedef struct dbus_extdl {
199 	uint8 *fw;
200 	int fwlen;
201 	uint8 *vars;
202 	int varslen;
203 } dbus_extdl_t;
204 
205 struct dbus_callbacks;
206 struct exec_parms;
207 
208 typedef void *(*probe_cb_t)(void *arg, const char *desc, uint32 bustype,
209 	uint16 bus_no, uint16 slot, uint32 hdrlen);
210 typedef void (*disconnect_cb_t)(void *arg);
211 typedef void *(*exec_cb_t)(struct exec_parms *args);
212 
213 /** Client callbacks registered during dbus_attach() */
214 typedef struct dbus_callbacks {
215 	void (*send_complete)(void *cbarg, void *info, int status);
216 	void (*recv_buf)(void *cbarg, uint8 *buf, int len);
217 	void (*recv_pkt)(void *cbarg, void *pkt);
218 	void (*txflowcontrol)(void *cbarg, bool onoff);
219 	void (*errhandler)(void *cbarg, int err);
220 	void (*ctl_complete)(void *cbarg, int type, int status);
221 	void (*state_change)(void *cbarg, int state);
222 	void *(*pktget)(void *cbarg, uint len, bool send);
223 	void (*pktfree)(void *cbarg, void *p, bool send);
224 } dbus_callbacks_t;
225 
226 struct dbus_pub;
227 struct bcmstrbuf;
228 struct dbus_irb;
229 struct dbus_irb_rx;
230 struct dbus_irb_tx;
231 struct dbus_intf_callbacks;
232 
233 typedef struct {
234 	void* (*attach)(struct dbus_pub *pub, void *cbarg, struct dbus_intf_callbacks *cbs);
235 	void (*detach)(struct dbus_pub *pub, void *bus);
236 
237 	int (*up)(void *bus);
238 	int (*down)(void *bus);
239 	int (*send_irb)(void *bus, struct dbus_irb_tx *txirb);
240 	int (*recv_irb)(void *bus, struct dbus_irb_rx *rxirb);
241 	int (*cancel_irb)(void *bus, struct dbus_irb_tx *txirb);
242 	int (*send_ctl)(void *bus, uint8 *buf, int len);
243 	int (*recv_ctl)(void *bus, uint8 *buf, int len);
244 	int (*get_stats)(void *bus, dbus_stats_t *stats);
245 	int (*get_attrib)(void *bus, dbus_attrib_t *attrib);
246 
247 	int (*pnp)(void *bus, int evnt);
248 	int (*remove)(void *bus);
249 	int (*resume)(void *bus);
250 	int (*suspend)(void *bus);
251 	int (*stop)(void *bus);
252 	int (*reset)(void *bus);
253 
254 	/* Access to bus buffers directly */
255 	void *(*pktget)(void *bus, int len);
256 	void (*pktfree)(void *bus, void *pkt);
257 
258 	int  (*iovar_op)(void *bus, const char *name, void *params, int plen, void *arg, int len,
259 		bool set);
260 	void (*dump)(void *bus, struct bcmstrbuf *strbuf);
261 	int  (*set_config)(void *bus, dbus_config_t *config);
262 	int  (*get_config)(void *bus, dbus_config_t *config);
263 
264 	bool (*device_exists)(void *bus);
265 	int (*dlneeded)(void *bus);
266 	int  (*dlstart)(void *bus, uint8 *fw, int len);
267 	int  (*dlrun)(void *bus);
268 	bool (*recv_needed)(void *bus);
269 
270 	void *(*exec_rxlock)(void *bus, exec_cb_t func, struct exec_parms *args);
271 	void *(*exec_txlock)(void *bus, exec_cb_t func, struct exec_parms *args);
272 
273 	int (*tx_timer_init)(void *bus);
274 	int (*tx_timer_start)(void *bus, uint timeout);
275 	int (*tx_timer_stop)(void *bus);
276 
277 	int (*sched_dpc)(void *bus);
278 	int (*lock)(void *bus);
279 	int (*unlock)(void *bus);
280 	int (*sched_probe_cb)(void *bus);
281 
282 	int (*shutdown)(void *bus);
283 
284 	int (*recv_stop)(void *bus);
285 	int (*recv_resume)(void *bus);
286 
287 	int (*recv_irb_from_ep)(void *bus, struct dbus_irb_rx *rxirb, uint ep_idx);
288 
289 	int (*readreg)(void *bus, uint32 regaddr, int datalen, uint32 *value);
290 
291 	/* Add from the bottom */
292 } dbus_intf_t;
293 
294 typedef struct dbus_pub {
295 	struct osl_info *osh;
296 	dbus_stats_t stats;
297 	dbus_attrib_t attrib;
298 	enum dbus_state busstate;
299 	DEVICE_SPEED device_speed;
300 	int ntxq, nrxq, rxsize;
301 	void *bus;
302 	struct shared_info *sh;
303 	void *dev_info;
304 } dbus_pub_t;
305 
306 #define BUS_INFO(bus, type) (((type *) bus)->pub->bus)
307 
308 #define	ALIGNED_LOCAL_VARIABLE(var, align)					\
309 	uint8	buffer[SDALIGN+64];						\
310 	uint8	*var = (uint8 *)(((uintptr)&buffer[0]) & ~(align-1)) + align;
311 
312 /*
313  * Public Bus Function Interface
314  */
315 
316 /*
317  * FIX: Is there better way to pass OS/Host handles to DBUS but still
318  *      maintain common interface for all OS??
319  * Under NDIS, param1 needs to be MiniportHandle
320  *  For NDIS60, param2 is WdfDevice
321  * Under Linux, param1 and param2 are NULL;
322  */
323 //extern int dbus_register(int vid, int pid, probe_cb_t prcb, disconnect_cb_t discb, void *prarg,
324 //	void *param1, void *param2);
325 //extern int dbus_deregister(void);
326 
327 //extern int dbus_download_firmware(dbus_pub_t *pub);
328 //extern int dbus_up(struct dhd_bus *pub);
329 extern int dbus_down(dbus_pub_t *pub);
330 //extern int dbus_stop(struct dhd_bus *pub);
331 extern int dbus_shutdown(dbus_pub_t *pub);
332 extern void dbus_flowctrl_rx(dbus_pub_t *pub, bool on);
333 
334 //extern int dbus_send_txdata(dbus_pub_t *dbus, void *pktbuf);
335 extern int dbus_send_buf(dbus_pub_t *pub, uint8 *buf, int len, void *info);
336 //extern int dbus_send_pkt(dbus_pub_t *pub, void *pkt, void *info);
337 //extern int dbus_send_ctl(struct dhd_bus *pub, uint8 *buf, int len);
338 //extern int dbus_recv_ctl(struct dhd_bus *pub, uint8 *buf, int len);
339 //extern int dbus_recv_bulk(dbus_pub_t *pub, uint32 ep_idx);
340 //extern int dbus_poll_intr(dbus_pub_t *pub);
341 extern int dbus_get_stats(dbus_pub_t *pub, dbus_stats_t *stats);
342 extern int dbus_get_device_speed(dbus_pub_t *pub);
343 extern int dbus_set_config(dbus_pub_t *pub, dbus_config_t *config);
344 extern int dbus_get_config(dbus_pub_t *pub, dbus_config_t *config);
345 extern void * dbus_get_devinfo(dbus_pub_t *pub);
346 
347 extern void *dbus_pktget(dbus_pub_t *pub, int len);
348 extern void dbus_pktfree(dbus_pub_t *pub, void* pkt);
349 
350 extern int dbus_set_errmask(dbus_pub_t *pub, uint32 mask);
351 extern int dbus_pnp_sleep(dbus_pub_t *pub);
352 extern int dbus_pnp_resume(dbus_pub_t *pub, int *fw_reload);
353 extern int dbus_pnp_disconnect(dbus_pub_t *pub);
354 
355 //extern int dbus_iovar_op(dbus_pub_t *pub, const char *name,
356 //	void *params, int plen, void *arg, int len, bool set);
357 #ifdef BCMDBG
358 extern void dbus_hist_dump(dbus_pub_t *pub, struct bcmstrbuf *b);
359 #endif /* BCMDBG */
360 
361 extern void *dhd_dbus_txq(const dbus_pub_t *pub);
362 extern uint dhd_dbus_hdrlen(const dbus_pub_t *pub);
363 
364 /*
365  * Private Common Bus Interface
366  */
367 
368 /** IO Request Block (IRB) */
369 typedef struct dbus_irb {
370 	struct dbus_irb *next;	/**< it's casted from dbus_irb_tx or dbus_irb_rx struct */
371 } dbus_irb_t;
372 
373 typedef struct dbus_irb_rx {
374 	struct dbus_irb irb; /* Must be first */
375 	uint8 *buf;
376 	int buf_len;
377 	int actual_len;
378 	void *pkt;
379 	void *info;
380 	void *arg;
381 } dbus_irb_rx_t;
382 
383 typedef struct dbus_irb_tx {
384 	struct dbus_irb irb; 	/** Must be first */
385 	uint8 *buf;		/** mutually exclusive with struct member 'pkt' */
386 	int len;		/** length of field 'buf' */
387 	void *pkt;		/** mutually exclusive with struct member 'buf' */
388 	int retry_count;
389 	void *info;
390 	void *arg;
391 	void *send_buf;		/**< linear  bufffer for LINUX when aggreagtion is enabled */
392 } dbus_irb_tx_t;
393 
394 /**
395  * DBUS interface callbacks are different from user callbacks
396  * so, internally, different info can be passed to upper layer
397  */
398 typedef struct dbus_intf_callbacks {
399 	void (*send_irb_timeout)(void *cbarg, dbus_irb_tx_t *txirb);
400 	void (*send_irb_complete)(void *cbarg, dbus_irb_tx_t *txirb, int status);
401 	void (*recv_irb_complete)(void *cbarg, dbus_irb_rx_t *rxirb, int status);
402 	void (*errhandler)(void *cbarg, int err);
403 	void (*ctl_complete)(void *cbarg, int type, int status);
404 	void (*state_change)(void *cbarg, int state);
405 	bool (*isr)(void *cbarg, bool *wantdpc);
406 	bool (*dpc)(void *cbarg, bool bounded);
407 	void (*watchdog)(void *cbarg);
408 	void *(*pktget)(void *cbarg, uint len, bool send);
409 	void (*pktfree)(void *cbarg, void *p, bool send);
410 	struct dbus_irb* (*getirb)(void *cbarg, bool send);
411 	void (*rxerr_indicate)(void *cbarg, bool on);
412 } dbus_intf_callbacks_t;
413 
414 /* callback functions */
415 typedef struct {
416 	/* probe the device */
417 	void *(*probe)(uint16 bus, uint16 slot, uint32 hdrlen);
418 	/* remove the device */
419 	void (*remove)(void *context);
420 	/* can we suspend now */
421 	int (*suspend)(void *context);
422 	/* resume from suspend */
423 	int (*resume)(void *context);
424 } dbus_driver_t;
425 
426 /*
427  * Porting: To support new bus, port these functions below
428  */
429 
430 /*
431  * Bus specific Interface
432  * Implemented by dbus_usb.c/dbus_sdio.c
433  */
434 extern int dbus_bus_register(dbus_driver_t *driver, dbus_intf_t **intf);
435 extern int dbus_bus_deregister(void);
436 extern void dbus_bus_fw_get(void *bus, uint8 **fw, int *fwlen, int *decomp);
437 
438 /*
439  * Bus-specific and OS-specific Interface
440  * Implemented by dbus_usb_[linux/ndis].c/dbus_sdio_[linux/ndis].c
441  */
442 extern int dbus_bus_osl_register(dbus_driver_t *driver, dbus_intf_t **intf);
443 extern int dbus_bus_osl_deregister(void);
444 
445 /*
446  * Bus-specific, OS-specific, HW-specific Interface
447  * Mainly for SDIO Host HW controller
448  */
449 extern int dbus_bus_osl_hw_register(int vid, int pid, probe_cb_t prcb, disconnect_cb_t discb,
450 	void *prarg, dbus_intf_t **intf);
451 extern int dbus_bus_osl_hw_deregister(void);
452 
453 extern uint usbdev_bulkin_eps(void);
454 #if defined(BCM_REQUEST_FW)
455 extern void *dbus_get_fw_nvfile(int devid, int chiprev, uint8 **fw, int *fwlen, int type,
456   uint16 boardtype, uint16 boardrev, char *path);
457 extern void dbus_release_fw_nvfile(void *firmware);
458 #endif  /* #if defined(BCM_REQUEST_FW) */
459 
460 #if defined(EHCI_FASTPATH_TX) || defined(EHCI_FASTPATH_RX)
461 /*
462  * Include file for the ECHI fastpath optimized USB
463  * Practically all the lines below have equivalent in some structures in other include (or even
464  * source) files This violates all kind of structure and layering, but cutting through layers is
465  * what the optimization is about. The definitions are NOT literally borrowed from any GPLd code;
466  * the file is intended to be GPL-clean
467  *
468  * Note that while some resemblance between this code and GPLd code in Linux might exist, it is
469  * due to the common sibling. See FreeBSD: head/sys/dev/usb/controller/ehci.h for the source of
470  * inspiration :-)
471  *
472  * The code assumes little endian throughout
473  */
474 
475 #if !defined(__linux__)
476 #error "EHCI fastpath is for Linux only."
477 #endif
478 
479 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
480 	/* Backward compatibility */
481 	typedef unsigned int gfp_t;
482 
483 	#define dma_pool pci_pool
484 	#define dma_pool_create(name, dev, size, align, alloc) \
485 		pci_pool_create(name, dev, size, align, alloc, GFP_DMA | GFP_ATOMIC)
486 	#define dma_pool_destroy(pool) pci_pool_destroy(pool)
487 	#define dma_pool_alloc(pool, flags, handle) pci_pool_alloc(pool, flags, handle)
488 	#define dma_pool_free(pool, vaddr, addr) pci_pool_free(pool, vaddr, addr)
489 
490 	#define dma_map_single(dev, addr, size, dir)	pci_map_single(dev, addr, size, dir)
491 	#define dma_unmap_single(dev, hnd, size, dir)	pci_unmap_single(dev, hnd, size, dir)
492 	#define DMA_FROM_DEVICE PCI_DMA_FROMDEVICE
493 	#define DMA_TO_DEVICE PCI_DMA_TODEVICE
494 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */
495 
496 /* Availability of these functions varies (when present, they have two arguments) */
497 #ifndef hc32_to_cpu
498 	#define hc32_to_cpu(x)	le32_to_cpu(x)
499 	#define cpu_to_hc32(x)	cpu_to_le32(x)
500 	typedef unsigned int __hc32;
501 #else
502 	#error Two-argument functions needed
503 #endif
504 
505 /* Private USB opcode base */
506 #define EHCI_FASTPATH		0x31
507 #define	EHCI_SET_EP_BYPASS	EHCI_FASTPATH
508 #define	EHCI_SET_BYPASS_CB	(EHCI_FASTPATH + 1)
509 #define	EHCI_SET_BYPASS_DEV	(EHCI_FASTPATH + 2)
510 #define	EHCI_DUMP_STATE		(EHCI_FASTPATH + 3)
511 #define	EHCI_SET_BYPASS_POOL	(EHCI_FASTPATH + 4)
512 #define	EHCI_CLR_EP_BYPASS	(EHCI_FASTPATH + 5)
513 
514 /*
515  * EHCI QTD structure (hardware and extension)
516  * NOTE that is does not need to (and does not) match its kernel counterpart
517  */
518 #define EHCI_QTD_NBUFFERS       5
519 #define EHCI_QTD_ALIGN  	32
520 #define EHCI_BULK_PACKET_SIZE	512
521 #define EHCI_QTD_XACTERR_MAX	32
522 
523 struct ehci_qtd {
524 	/* Hardware map */
525 	volatile uint32_t	qtd_next;
526 	volatile uint32_t	qtd_altnext;
527 	volatile uint32_t	qtd_status;
528 #define	EHCI_QTD_GET_BYTES(x)	(((x)>>16) & 0x7fff)
529 #define	EHCI_QTD_IOC            0x00008000
530 #define	EHCI_QTD_GET_CERR(x)	(((x)>>10) & 0x3)
531 #define EHCI_QTD_SET_CERR(x)    ((x) << 10)
532 #define	EHCI_QTD_GET_PID(x)	(((x)>>8) & 0x3)
533 #define EHCI_QTD_SET_PID(x)     ((x) <<  8)
534 #define EHCI_QTD_ACTIVE         0x80
535 #define EHCI_QTD_HALTED         0x40
536 #define EHCI_QTD_BUFERR         0x20
537 #define EHCI_QTD_BABBLE         0x10
538 #define EHCI_QTD_XACTERR        0x08
539 #define EHCI_QTD_MISSEDMICRO    0x04
540 	volatile uint32_t 	qtd_buffer[EHCI_QTD_NBUFFERS];
541 	volatile uint32_t 	qtd_buffer_hi[EHCI_QTD_NBUFFERS];
542 
543 	/* Implementation extension */
544 	dma_addr_t		qtd_self;		/**< own hardware address */
545 	struct ehci_qtd		*obj_next;		/**< software link to the next QTD */
546 	void			*rpc;			/**< pointer to the rpc buffer */
547 	size_t			length;			/**< length of the data in the buffer */
548 	void			*buff;			/**< pointer to the reassembly buffer */
549 	int			xacterrs;		/**< retry counter for qtd xact error */
550 } __attribute__ ((aligned(EHCI_QTD_ALIGN)));
551 
552 #define	EHCI_NULL	__constant_cpu_to_le32(1) /* HW null pointer shall be odd */
553 
554 #define SHORT_READ_Q(token) (EHCI_QTD_GET_BYTES(token) != 0 && EHCI_QTD_GET_PID(token) == 1)
555 
556 /**
557  * Queue Head
558  * NOTE This structure is slightly different from the one in the kernel; but needs to stay
559  * compatible.
560  */
561 struct ehci_qh {
562 	/* Hardware map */
563 	volatile uint32_t 	qh_link;
564 	volatile uint32_t 	qh_endp;
565 	volatile uint32_t 	qh_endphub;
566 	volatile uint32_t 	qh_curqtd;
567 
568 	/* QTD overlay */
569 	volatile uint32_t	ow_next;
570 	volatile uint32_t	ow_altnext;
571 	volatile uint32_t	ow_status;
572 	volatile uint32_t	ow_buffer [EHCI_QTD_NBUFFERS];
573 	volatile uint32_t	ow_buffer_hi [EHCI_QTD_NBUFFERS];
574 
575 	/* Extension (should match the kernel layout) */
576 	dma_addr_t		unused0;
577 	void 			*unused1;
578 	struct list_head	unused2;
579 	struct ehci_qtd		*dummy;
580 	struct ehci_qh		*unused3;
581 
582 	struct ehci_hcd		*unused4;
583 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
584 	struct kref		unused5;
585 	unsigned		unused6;
586 
587 	uint8_t			unused7;
588 
589 	/* periodic schedule info */
590 	uint8_t			unused8;
591 	uint8_t			unused9;
592 	uint8_t			unused10;
593 	uint16_t		unused11;
594 	uint16_t		unused12;
595 	uint16_t		unused13;
596 	struct usb_device	*unused14;
597 #else
598 	unsigned		unused5;
599 
600 	u8			unused6;
601 
602 	/* periodic schedule info */
603 	u8			unused7;
604 	u8			unused8;
605 	u8			unused9;
606 	unsigned short		unused10;
607 	unsigned short		unused11;
608 #define NO_FRAME ((unsigned short)~0)
609 #ifdef EHCI_QUIRK_FIX
610 	struct usb_device	*unused12;
611 #endif /* EHCI_QUIRK_FIX */
612 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
613 	struct ehci_qtd		*first_qtd;
614 		/* Link to the first QTD; this is an optimized equivalent of the qtd_list field */
615 		/* NOTE that ehci_qh in ehci.h shall reserve this word */
616 } __attribute__ ((aligned(EHCI_QTD_ALIGN)));
617 
618 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
619 /** The corresponding structure in the kernel is used to get the QH */
620 struct hcd_dev {	/* usb_device.hcpriv points to this */
621 	struct list_head	unused0;
622 	struct list_head	unused1;
623 
624 	/* array of QH pointers */
625 	void			*ep[32];
626 };
627 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
628 
629 int optimize_qtd_fill_with_rpc(const dbus_pub_t *pub,  int epn, struct ehci_qtd *qtd, void *rpc,
630 	int token, int len);
631 int optimize_qtd_fill_with_data(const dbus_pub_t *pub, int epn, struct ehci_qtd *qtd, void *data,
632 	int token, int len);
633 int optimize_submit_async(struct ehci_qtd *qtd, int epn);
634 void inline optimize_ehci_qtd_init(struct ehci_qtd *qtd, dma_addr_t dma);
635 struct ehci_qtd *optimize_ehci_qtd_alloc(gfp_t flags);
636 void optimize_ehci_qtd_free(struct ehci_qtd *qtd);
637 void optimize_submit_rx_request(const dbus_pub_t *pub, int epn, struct ehci_qtd *qtd_in, void *buf);
638 #endif /* EHCI_FASTPATH_TX || EHCI_FASTPATH_RX */
639 
640 void  dbus_flowctrl_tx(void *dbi, bool on);
641 #ifdef LINUX
642 struct device * dbus_get_dev(void);
643 #endif /* LINUX */
644 #endif /* __DBUS_H__ */
645