dbus.h 19 KB

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