whci-hc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. * Wireless Host Controller (WHC) data structures.
  3. *
  4. * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #ifndef _WHCI_WHCI_HC_H
  21. #define _WHCI_WHCI_HC_H
  22. #include <linux/list.h>
  23. /**
  24. * WHCI_PAGE_SIZE - page size use by WHCI
  25. *
  26. * WHCI assumes that host system uses pages of 4096 octets.
  27. */
  28. #define WHCI_PAGE_SIZE 4096
  29. /**
  30. * QTD_MAX_TXFER_SIZE - max number of bytes to transfer with a single
  31. * qtd.
  32. *
  33. * This is 2^20 - 1.
  34. */
  35. #define QTD_MAX_XFER_SIZE 1048575
  36. /**
  37. * struct whc_qtd - Queue Element Transfer Descriptors (qTD)
  38. *
  39. * This describes the data for a bulk, control or interrupt transfer.
  40. *
  41. * [WHCI] section 3.2.4
  42. */
  43. struct whc_qtd {
  44. __le32 status; /*< remaining transfer len and transfer status */
  45. __le32 options;
  46. __le64 page_list_ptr; /*< physical pointer to data buffer page list*/
  47. __u8 setup[8]; /*< setup data for control transfers */
  48. } __attribute__((packed));
  49. #define QTD_STS_ACTIVE (1 << 31) /* enable execution of transaction */
  50. #define QTD_STS_HALTED (1 << 30) /* transfer halted */
  51. #define QTD_STS_DBE (1 << 29) /* data buffer error */
  52. #define QTD_STS_BABBLE (1 << 28) /* babble detected */
  53. #define QTD_STS_RCE (1 << 27) /* retry count exceeded */
  54. #define QTD_STS_LAST_PKT (1 << 26) /* set Last Packet Flag in WUSB header */
  55. #define QTD_STS_INACTIVE (1 << 25) /* queue set is marked inactive */
  56. #define QTD_STS_IALT_VALID (1 << 23) /* iAlt field is valid */
  57. #define QTD_STS_IALT(i) (QTD_STS_IALT_VALID | ((i) << 20)) /* iAlt field */
  58. #define QTD_STS_LEN(l) ((l) << 0) /* transfer length */
  59. #define QTD_STS_TO_LEN(s) ((s) & 0x000fffff)
  60. #define QTD_OPT_IOC (1 << 1) /* page_list_ptr points to buffer directly */
  61. #define QTD_OPT_SMALL (1 << 0) /* interrupt on complete */
  62. /**
  63. * struct whc_itd - Isochronous Queue Element Transfer Descriptors (iTD)
  64. *
  65. * This describes the data and other parameters for an isochronous
  66. * transfer.
  67. *
  68. * [WHCI] section 3.2.5
  69. */
  70. struct whc_itd {
  71. __le16 presentation_time; /*< presentation time for OUT transfers */
  72. __u8 num_segments; /*< number of data segments in segment list */
  73. __u8 status; /*< command execution status */
  74. __le32 options; /*< misc transfer options */
  75. __le64 page_list_ptr; /*< physical pointer to data buffer page list */
  76. __le64 seg_list_ptr; /*< physical pointer to segment list */
  77. } __attribute__((packed));
  78. #define ITD_STS_ACTIVE (1 << 7) /* enable execution of transaction */
  79. #define ITD_STS_DBE (1 << 5) /* data buffer error */
  80. #define ITD_STS_BABBLE (1 << 4) /* babble detected */
  81. #define ITD_STS_INACTIVE (1 << 1) /* queue set is marked inactive */
  82. #define ITD_OPT_IOC (1 << 1) /* interrupt on complete */
  83. #define ITD_OPT_SMALL (1 << 0) /* page_list_ptr points to buffer directly */
  84. /**
  85. * Page list entry.
  86. *
  87. * A TD's page list must contain sufficient page list entries for the
  88. * total data length in the TD.
  89. *
  90. * [WHCI] section 3.2.4.3
  91. */
  92. struct whc_page_list_entry {
  93. __le64 buf_ptr; /*< physical pointer to buffer */
  94. } __attribute__((packed));
  95. /**
  96. * struct whc_seg_list_entry - Segment list entry.
  97. *
  98. * Describes a portion of the data buffer described in the containing
  99. * qTD's page list.
  100. *
  101. * seg_ptr = qtd->page_list_ptr[qtd->seg_list_ptr[seg].idx].buf_ptr
  102. * + qtd->seg_list_ptr[seg].offset;
  103. *
  104. * Segments can't cross page boundries.
  105. *
  106. * [WHCI] section 3.2.5.5
  107. */
  108. struct whc_seg_list_entry {
  109. __le16 len; /*< segment length */
  110. __u8 idx; /*< index into page list */
  111. __u8 status; /*< segment status */
  112. __le16 offset; /*< 12 bit offset into page */
  113. } __attribute__((packed));
  114. /**
  115. * struct whc_qhead - endpoint and status information for a qset.
  116. *
  117. * [WHCI] section 3.2.6
  118. */
  119. struct whc_qhead {
  120. __le64 link; /*< next qset in list */
  121. __le32 info1;
  122. __le32 info2;
  123. __le32 info3;
  124. __le16 status;
  125. __le16 err_count; /*< transaction error count */
  126. __le32 cur_window;
  127. __le32 scratch[3]; /*< h/w scratch area */
  128. union {
  129. struct whc_qtd qtd;
  130. struct whc_itd itd;
  131. } overlay;
  132. } __attribute__((packed));
  133. #define QH_LINK_PTR_MASK (~0x03Full)
  134. #define QH_LINK_PTR(ptr) ((ptr) & QH_LINK_PTR_MASK)
  135. #define QH_LINK_IQS (1 << 4) /* isochronous queue set */
  136. #define QH_LINK_NTDS(n) (((n) - 1) << 1) /* number of TDs in queue set */
  137. #define QH_LINK_T (1 << 0) /* last queue set in periodic schedule list */
  138. #define QH_INFO1_EP(e) ((e) << 0) /* endpoint number */
  139. #define QH_INFO1_DIR_IN (1 << 4) /* IN transfer */
  140. #define QH_INFO1_DIR_OUT (0 << 4) /* OUT transfer */
  141. #define QH_INFO1_TR_TYPE_CTRL (0x0 << 5) /* control transfer */
  142. #define QH_INFO1_TR_TYPE_ISOC (0x1 << 5) /* isochronous transfer */
  143. #define QH_INFO1_TR_TYPE_BULK (0x2 << 5) /* bulk transfer */
  144. #define QH_INFO1_TR_TYPE_INT (0x3 << 5) /* interrupt */
  145. #define QH_INFO1_TR_TYPE_LP_INT (0x7 << 5) /* low power interrupt */
  146. #define QH_INFO1_DEV_INFO_IDX(i) ((i) << 8) /* index into device info buffer */
  147. #define QH_INFO1_SET_INACTIVE (1 << 15) /* set inactive after transfer */
  148. #define QH_INFO1_MAX_PKT_LEN(l) ((l) << 16) /* maximum packet length */
  149. #define QH_INFO2_BURST(b) ((b) << 0) /* maximum burst length */
  150. #define QH_INFO2_DBP(p) ((p) << 5) /* data burst policy (see [WUSB] table 5-7) */
  151. #define QH_INFO2_MAX_COUNT(c) ((c) << 8) /* max isoc/int pkts per zone */
  152. #define QH_INFO2_RQS (1 << 15) /* reactivate queue set */
  153. #define QH_INFO2_MAX_RETRY(r) ((r) << 16) /* maximum transaction retries */
  154. #define QH_INFO2_MAX_SEQ(s) ((s) << 20) /* maximum sequence number */
  155. #define QH_INFO3_MAX_DELAY(d) ((d) << 0) /* maximum stream delay in 125 us units (isoc only) */
  156. #define QH_INFO3_INTERVAL(i) ((i) << 16) /* segment interval in 125 us units (isoc only) */
  157. #define QH_INFO3_TX_RATE_53_3 (0 << 24)
  158. #define QH_INFO3_TX_RATE_80 (1 << 24)
  159. #define QH_INFO3_TX_RATE_106_7 (2 << 24)
  160. #define QH_INFO3_TX_RATE_160 (3 << 24)
  161. #define QH_INFO3_TX_RATE_200 (4 << 24)
  162. #define QH_INFO3_TX_RATE_320 (5 << 24)
  163. #define QH_INFO3_TX_RATE_400 (6 << 24)
  164. #define QH_INFO3_TX_RATE_480 (7 << 24)
  165. #define QH_INFO3_TX_PWR(p) ((p) << 29) /* transmit power (see [WUSB] section 5.2.1.2) */
  166. #define QH_STATUS_FLOW_CTRL (1 << 15)
  167. #define QH_STATUS_ICUR(i) ((i) << 5)
  168. #define QH_STATUS_TO_ICUR(s) (((s) >> 5) & 0x7)
  169. #define QH_STATUS_SEQ_MASK 0x1f
  170. /**
  171. * usb_pipe_to_qh_type - USB core pipe type to QH transfer type
  172. *
  173. * Returns the QH type field for a USB core pipe type.
  174. */
  175. static inline unsigned usb_pipe_to_qh_type(unsigned pipe)
  176. {
  177. static const unsigned type[] = {
  178. [PIPE_ISOCHRONOUS] = QH_INFO1_TR_TYPE_ISOC,
  179. [PIPE_INTERRUPT] = QH_INFO1_TR_TYPE_INT,
  180. [PIPE_CONTROL] = QH_INFO1_TR_TYPE_CTRL,
  181. [PIPE_BULK] = QH_INFO1_TR_TYPE_BULK,
  182. };
  183. return type[usb_pipetype(pipe)];
  184. }
  185. /**
  186. * Maxiumum number of TDs in a qset.
  187. */
  188. #define WHCI_QSET_TD_MAX 8
  189. /**
  190. * struct whc_qset - WUSB data transfers to a specific endpoint
  191. * @qh: the QHead of this qset
  192. * @qtd: up to 8 qTDs (for qsets for control, bulk and interrupt
  193. * transfers)
  194. * @itd: up to 8 iTDs (for qsets for isochronous transfers)
  195. * @qset_dma: DMA address for this qset
  196. * @whc: WHCI HC this qset is for
  197. * @ep: endpoint
  198. * @stds: list of sTDs queued to this qset
  199. * @ntds: number of qTDs queued (not necessarily the same as nTDs
  200. * field in the QH)
  201. * @td_start: index of the first qTD in the list
  202. * @td_end: index of next free qTD in the list (provided
  203. * ntds < WHCI_QSET_TD_MAX)
  204. *
  205. * Queue Sets (qsets) are added to the asynchronous schedule list
  206. * (ASL) or the periodic zone list (PZL).
  207. *
  208. * qsets may contain up to 8 TDs (either qTDs or iTDs as appropriate).
  209. * Each TD may refer to at most 1 MiB of data. If a single transfer
  210. * has > 8MiB of data, TDs can be reused as they are completed since
  211. * the TD list is used as a circular buffer. Similarly, several
  212. * (smaller) transfers may be queued in a qset.
  213. *
  214. * WHCI controllers may cache portions of the qsets in the ASL and
  215. * PZL, requiring the WHCD to inform the WHC that the lists have been
  216. * updated (fields changed or qsets inserted or removed). For safe
  217. * insertion and removal of qsets from the lists the schedule must be
  218. * stopped to avoid races in updating the QH link pointers.
  219. *
  220. * Since the HC is free to execute qsets in any order, all transfers
  221. * to an endpoint should use the same qset to ensure transfers are
  222. * executed in the order they're submitted.
  223. *
  224. * [WHCI] section 3.2.3
  225. */
  226. struct whc_qset {
  227. struct whc_qhead qh;
  228. union {
  229. struct whc_qtd qtd[WHCI_QSET_TD_MAX];
  230. struct whc_itd itd[WHCI_QSET_TD_MAX];
  231. };
  232. /* private data for WHCD */
  233. dma_addr_t qset_dma;
  234. struct whc *whc;
  235. struct usb_host_endpoint *ep;
  236. struct list_head stds;
  237. int ntds;
  238. int td_start;
  239. int td_end;
  240. struct list_head list_node;
  241. unsigned in_sw_list:1;
  242. unsigned in_hw_list:1;
  243. unsigned remove:1;
  244. struct urb *pause_after_urb;
  245. struct completion remove_complete;
  246. int max_burst;
  247. int max_seq;
  248. };
  249. static inline void whc_qset_set_link_ptr(u64 *ptr, u64 target)
  250. {
  251. if (target)
  252. *ptr = (*ptr & ~(QH_LINK_PTR_MASK | QH_LINK_T)) | QH_LINK_PTR(target);
  253. else
  254. *ptr = QH_LINK_T;
  255. }
  256. /**
  257. * struct di_buf_entry - Device Information (DI) buffer entry.
  258. *
  259. * There's one of these per connected device.
  260. */
  261. struct di_buf_entry {
  262. __le32 availability_info[8]; /*< MAS availability information, one MAS per bit */
  263. __le32 addr_sec_info; /*< addressing and security info */
  264. __le32 reserved[7];
  265. } __attribute__((packed));
  266. #define WHC_DI_SECURE (1 << 31)
  267. #define WHC_DI_DISABLE (1 << 30)
  268. #define WHC_DI_KEY_IDX(k) ((k) << 8)
  269. #define WHC_DI_KEY_IDX_MASK 0x0000ff00
  270. #define WHC_DI_DEV_ADDR(a) ((a) << 0)
  271. #define WHC_DI_DEV_ADDR_MASK 0x000000ff
  272. /**
  273. * struct dn_buf_entry - Device Notification (DN) buffer entry.
  274. *
  275. * [WHCI] section 3.2.8
  276. */
  277. struct dn_buf_entry {
  278. __u8 msg_size; /*< number of octets of valid DN data */
  279. __u8 reserved1;
  280. __u8 src_addr; /*< source address */
  281. __u8 status; /*< buffer entry status */
  282. __le32 tkid; /*< TKID for source device, valid if secure bit is set */
  283. __u8 dn_data[56]; /*< up to 56 octets of DN data */
  284. } __attribute__((packed));
  285. #define WHC_DN_STATUS_VALID (1 << 7) /* buffer entry is valid */
  286. #define WHC_DN_STATUS_SECURE (1 << 6) /* notification received using secure frame */
  287. #define WHC_N_DN_ENTRIES (4096 / sizeof(struct dn_buf_entry))
  288. /* The Add MMC IE WUSB Generic Command may take up to 256 bytes of
  289. data. [WHCI] section 2.4.7. */
  290. #define WHC_GEN_CMD_DATA_LEN 256
  291. /*
  292. * HC registers.
  293. *
  294. * [WHCI] section 2.4
  295. */
  296. #define WHCIVERSION 0x00
  297. #define WHCSPARAMS 0x04
  298. # define WHCSPARAMS_TO_N_MMC_IES(p) (((p) >> 16) & 0xff)
  299. # define WHCSPARAMS_TO_N_KEYS(p) (((p) >> 8) & 0xff)
  300. # define WHCSPARAMS_TO_N_DEVICES(p) (((p) >> 0) & 0x7f)
  301. #define WUSBCMD 0x08
  302. # define WUSBCMD_BCID(b) ((b) << 16)
  303. # define WUSBCMD_BCID_MASK (0xff << 16)
  304. # define WUSBCMD_ASYNC_QSET_RM (1 << 12)
  305. # define WUSBCMD_PERIODIC_QSET_RM (1 << 11)
  306. # define WUSBCMD_WUSBSI(s) ((s) << 8)
  307. # define WUSBCMD_WUSBSI_MASK (0x7 << 8)
  308. # define WUSBCMD_ASYNC_SYNCED_DB (1 << 7)
  309. # define WUSBCMD_PERIODIC_SYNCED_DB (1 << 6)
  310. # define WUSBCMD_ASYNC_UPDATED (1 << 5)
  311. # define WUSBCMD_PERIODIC_UPDATED (1 << 4)
  312. # define WUSBCMD_ASYNC_EN (1 << 3)
  313. # define WUSBCMD_PERIODIC_EN (1 << 2)
  314. # define WUSBCMD_WHCRESET (1 << 1)
  315. # define WUSBCMD_RUN (1 << 0)
  316. #define WUSBSTS 0x0c
  317. # define WUSBSTS_ASYNC_SCHED (1 << 15)
  318. # define WUSBSTS_PERIODIC_SCHED (1 << 14)
  319. # define WUSBSTS_DNTS_SCHED (1 << 13)
  320. # define WUSBSTS_HCHALTED (1 << 12)
  321. # define WUSBSTS_GEN_CMD_DONE (1 << 9)
  322. # define WUSBSTS_CHAN_TIME_ROLLOVER (1 << 8)
  323. # define WUSBSTS_DNTS_OVERFLOW (1 << 7)
  324. # define WUSBSTS_BPST_ADJUSTMENT_CHANGED (1 << 6)
  325. # define WUSBSTS_HOST_ERR (1 << 5)
  326. # define WUSBSTS_ASYNC_SCHED_SYNCED (1 << 4)
  327. # define WUSBSTS_PERIODIC_SCHED_SYNCED (1 << 3)
  328. # define WUSBSTS_DNTS_INT (1 << 2)
  329. # define WUSBSTS_ERR_INT (1 << 1)
  330. # define WUSBSTS_INT (1 << 0)
  331. # define WUSBSTS_INT_MASK 0x3ff
  332. #define WUSBINTR 0x10
  333. # define WUSBINTR_GEN_CMD_DONE (1 << 9)
  334. # define WUSBINTR_CHAN_TIME_ROLLOVER (1 << 8)
  335. # define WUSBINTR_DNTS_OVERFLOW (1 << 7)
  336. # define WUSBINTR_BPST_ADJUSTMENT_CHANGED (1 << 6)
  337. # define WUSBINTR_HOST_ERR (1 << 5)
  338. # define WUSBINTR_ASYNC_SCHED_SYNCED (1 << 4)
  339. # define WUSBINTR_PERIODIC_SCHED_SYNCED (1 << 3)
  340. # define WUSBINTR_DNTS_INT (1 << 2)
  341. # define WUSBINTR_ERR_INT (1 << 1)
  342. # define WUSBINTR_INT (1 << 0)
  343. # define WUSBINTR_ALL 0x3ff
  344. #define WUSBGENCMDSTS 0x14
  345. # define WUSBGENCMDSTS_ACTIVE (1 << 31)
  346. # define WUSBGENCMDSTS_ERROR (1 << 24)
  347. # define WUSBGENCMDSTS_IOC (1 << 23)
  348. # define WUSBGENCMDSTS_MMCIE_ADD 0x01
  349. # define WUSBGENCMDSTS_MMCIE_RM 0x02
  350. # define WUSBGENCMDSTS_SET_MAS 0x03
  351. # define WUSBGENCMDSTS_CHAN_STOP 0x04
  352. # define WUSBGENCMDSTS_RWP_EN 0x05
  353. #define WUSBGENCMDPARAMS 0x18
  354. #define WUSBGENADDR 0x20
  355. #define WUSBASYNCLISTADDR 0x28
  356. #define WUSBDNTSBUFADDR 0x30
  357. #define WUSBDEVICEINFOADDR 0x38
  358. #define WUSBSETSECKEYCMD 0x40
  359. # define WUSBSETSECKEYCMD_SET (1 << 31)
  360. # define WUSBSETSECKEYCMD_ERASE (1 << 30)
  361. # define WUSBSETSECKEYCMD_GTK (1 << 8)
  362. # define WUSBSETSECKEYCMD_IDX(i) ((i) << 0)
  363. #define WUSBTKID 0x44
  364. #define WUSBSECKEY 0x48
  365. #define WUSBPERIODICLISTBASE 0x58
  366. #define WUSBMASINDEX 0x60
  367. #define WUSBDNTSCTRL 0x64
  368. # define WUSBDNTSCTRL_ACTIVE (1 << 31)
  369. # define WUSBDNTSCTRL_INTERVAL(i) ((i) << 8)
  370. # define WUSBDNTSCTRL_SLOTS(s) ((s) << 0)
  371. #define WUSBTIME 0x68
  372. # define WUSBTIME_CHANNEL_TIME_MASK 0x00ffffff
  373. #define WUSBBPST 0x6c
  374. #define WUSBDIBUPDATED 0x70
  375. #endif /* #ifndef _WHCI_WHCI_HC_H */