ohci1394.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  2. * ohci1394.h - driver for OHCI 1394 boards
  3. * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>
  4. * Gord Peters <GordPeters@smarttech.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #ifndef _OHCI1394_H
  21. #define _OHCI1394_H
  22. #include "ieee1394_types.h"
  23. #include <asm/io.h>
  24. #define OHCI1394_DRIVER_NAME "ohci1394"
  25. #define OHCI1394_MAX_AT_REQ_RETRIES 0x2
  26. #define OHCI1394_MAX_AT_RESP_RETRIES 0x2
  27. #define OHCI1394_MAX_PHYS_RESP_RETRIES 0x8
  28. #define OHCI1394_MAX_SELF_ID_ERRORS 16
  29. #define AR_REQ_NUM_DESC 4 /* number of AR req descriptors */
  30. #define AR_REQ_BUF_SIZE PAGE_SIZE /* size of AR req buffers */
  31. #define AR_REQ_SPLIT_BUF_SIZE PAGE_SIZE /* split packet buffer */
  32. #define AR_RESP_NUM_DESC 4 /* number of AR resp descriptors */
  33. #define AR_RESP_BUF_SIZE PAGE_SIZE /* size of AR resp buffers */
  34. #define AR_RESP_SPLIT_BUF_SIZE PAGE_SIZE /* split packet buffer */
  35. #define IR_NUM_DESC 16 /* number of IR descriptors */
  36. #define IR_BUF_SIZE PAGE_SIZE /* 4096 bytes/buffer */
  37. #define IR_SPLIT_BUF_SIZE PAGE_SIZE /* split packet buffer */
  38. #define IT_NUM_DESC 16 /* number of IT descriptors */
  39. #define AT_REQ_NUM_DESC 32 /* number of AT req descriptors */
  40. #define AT_RESP_NUM_DESC 32 /* number of AT resp descriptors */
  41. #define OHCI_LOOP_COUNT 100 /* Number of loops for reg read waits */
  42. #define OHCI_CONFIG_ROM_LEN 1024 /* Length of the mapped configrom space */
  43. #define OHCI1394_SI_DMA_BUF_SIZE 8192 /* length of the selfid buffer */
  44. /* PCI configuration space addresses */
  45. #define OHCI1394_PCI_HCI_Control 0x40
  46. struct dma_cmd {
  47. u32 control;
  48. u32 address;
  49. u32 branchAddress;
  50. u32 status;
  51. };
  52. /*
  53. * FIXME:
  54. * It is important that a single at_dma_prg does not cross a page boundary
  55. * The proper way to do it would be to do the check dynamically as the
  56. * programs are inserted into the AT fifo.
  57. */
  58. struct at_dma_prg {
  59. struct dma_cmd begin;
  60. quadlet_t data[4];
  61. struct dma_cmd end;
  62. quadlet_t pad[4]; /* FIXME: quick hack for memory alignment */
  63. };
  64. /* identify whether a DMA context is asynchronous or isochronous */
  65. enum context_type { DMA_CTX_ASYNC_REQ, DMA_CTX_ASYNC_RESP, DMA_CTX_ISO };
  66. /* DMA receive context */
  67. struct dma_rcv_ctx {
  68. struct ti_ohci *ohci;
  69. enum context_type type;
  70. int ctx;
  71. unsigned int num_desc;
  72. unsigned int buf_size;
  73. unsigned int split_buf_size;
  74. /* dma block descriptors */
  75. struct dma_cmd **prg_cpu;
  76. dma_addr_t *prg_bus;
  77. struct pci_pool *prg_pool;
  78. /* dma buffers */
  79. quadlet_t **buf_cpu;
  80. dma_addr_t *buf_bus;
  81. unsigned int buf_ind;
  82. unsigned int buf_offset;
  83. quadlet_t *spb;
  84. spinlock_t lock;
  85. struct tasklet_struct task;
  86. int ctrlClear;
  87. int ctrlSet;
  88. int cmdPtr;
  89. int ctxtMatch;
  90. };
  91. /* DMA transmit context */
  92. struct dma_trm_ctx {
  93. struct ti_ohci *ohci;
  94. enum context_type type;
  95. int ctx;
  96. unsigned int num_desc;
  97. /* dma block descriptors */
  98. struct at_dma_prg **prg_cpu;
  99. dma_addr_t *prg_bus;
  100. struct pci_pool *prg_pool;
  101. unsigned int prg_ind;
  102. unsigned int sent_ind;
  103. int free_prgs;
  104. quadlet_t *branchAddrPtr;
  105. /* list of packets inserted in the AT FIFO */
  106. struct list_head fifo_list;
  107. /* list of pending packets to be inserted in the AT FIFO */
  108. struct list_head pending_list;
  109. spinlock_t lock;
  110. struct tasklet_struct task;
  111. int ctrlClear;
  112. int ctrlSet;
  113. int cmdPtr;
  114. };
  115. struct ohci1394_iso_tasklet {
  116. struct tasklet_struct tasklet;
  117. struct list_head link;
  118. int context;
  119. enum { OHCI_ISO_TRANSMIT, OHCI_ISO_RECEIVE,
  120. OHCI_ISO_MULTICHANNEL_RECEIVE } type;
  121. };
  122. struct ti_ohci {
  123. struct pci_dev *dev;
  124. enum {
  125. OHCI_INIT_ALLOC_HOST,
  126. OHCI_INIT_HAVE_MEM_REGION,
  127. OHCI_INIT_HAVE_IOMAPPING,
  128. OHCI_INIT_HAVE_CONFIG_ROM_BUFFER,
  129. OHCI_INIT_HAVE_SELFID_BUFFER,
  130. OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE,
  131. OHCI_INIT_HAVE_IRQ,
  132. OHCI_INIT_DONE,
  133. } init_state;
  134. /* remapped memory spaces */
  135. void __iomem *registers;
  136. /* dma buffer for self-id packets */
  137. quadlet_t *selfid_buf_cpu;
  138. dma_addr_t selfid_buf_bus;
  139. /* buffer for csr config rom */
  140. quadlet_t *csr_config_rom_cpu;
  141. dma_addr_t csr_config_rom_bus;
  142. int csr_config_rom_length;
  143. unsigned int max_packet_size;
  144. /* async receive */
  145. struct dma_rcv_ctx ar_resp_context;
  146. struct dma_rcv_ctx ar_req_context;
  147. /* async transmit */
  148. struct dma_trm_ctx at_resp_context;
  149. struct dma_trm_ctx at_req_context;
  150. /* iso receive */
  151. int nb_iso_rcv_ctx;
  152. unsigned long ir_ctx_usage; /* use test_and_set_bit() for atomicity */
  153. unsigned long ir_multichannel_used; /* ditto */
  154. spinlock_t IR_channel_lock;
  155. /* iso transmit */
  156. int nb_iso_xmit_ctx;
  157. unsigned long it_ctx_usage; /* use test_and_set_bit() for atomicity */
  158. u64 ISO_channel_usage;
  159. /* IEEE-1394 part follows */
  160. struct hpsb_host *host;
  161. int phyid, isroot;
  162. spinlock_t phy_reg_lock;
  163. spinlock_t event_lock;
  164. int self_id_errors;
  165. /* Tasklets for iso receive and transmit, used by video1394
  166. * and dv1394 */
  167. struct list_head iso_tasklet_list;
  168. spinlock_t iso_tasklet_list_lock;
  169. /* Swap the selfid buffer? */
  170. unsigned int selfid_swap:1;
  171. /* Some Apple chipset seem to swap incoming headers for us */
  172. unsigned int no_swap_incoming:1;
  173. /* Force extra paranoia checking on bus-reset handling */
  174. unsigned int check_busreset:1;
  175. };
  176. static inline int cross_bound(unsigned long addr, unsigned int size)
  177. {
  178. if (size == 0)
  179. return 0;
  180. if (size > PAGE_SIZE)
  181. return 1;
  182. if (addr >> PAGE_SHIFT != (addr + size - 1) >> PAGE_SHIFT)
  183. return 1;
  184. return 0;
  185. }
  186. /*
  187. * Register read and write helper functions.
  188. */
  189. static inline void reg_write(const struct ti_ohci *ohci, int offset, u32 data)
  190. {
  191. writel(data, ohci->registers + offset);
  192. }
  193. static inline u32 reg_read(const struct ti_ohci *ohci, int offset)
  194. {
  195. return readl(ohci->registers + offset);
  196. }
  197. /* 2 KiloBytes of register space */
  198. #define OHCI1394_REGISTER_SIZE 0x800
  199. /* Offsets relative to context bases defined below */
  200. #define OHCI1394_ContextControlSet 0x000
  201. #define OHCI1394_ContextControlClear 0x004
  202. #define OHCI1394_ContextCommandPtr 0x00C
  203. /* register map */
  204. #define OHCI1394_Version 0x000
  205. #define OHCI1394_GUID_ROM 0x004
  206. #define OHCI1394_ATRetries 0x008
  207. #define OHCI1394_CSRData 0x00C
  208. #define OHCI1394_CSRCompareData 0x010
  209. #define OHCI1394_CSRControl 0x014
  210. #define OHCI1394_ConfigROMhdr 0x018
  211. #define OHCI1394_BusID 0x01C
  212. #define OHCI1394_BusOptions 0x020
  213. #define OHCI1394_GUIDHi 0x024
  214. #define OHCI1394_GUIDLo 0x028
  215. #define OHCI1394_ConfigROMmap 0x034
  216. #define OHCI1394_PostedWriteAddressLo 0x038
  217. #define OHCI1394_PostedWriteAddressHi 0x03C
  218. #define OHCI1394_VendorID 0x040
  219. #define OHCI1394_HCControlSet 0x050
  220. #define OHCI1394_HCControlClear 0x054
  221. #define OHCI1394_HCControl_noByteSwap 0x40000000
  222. #define OHCI1394_HCControl_programPhyEnable 0x00800000
  223. #define OHCI1394_HCControl_aPhyEnhanceEnable 0x00400000
  224. #define OHCI1394_HCControl_LPS 0x00080000
  225. #define OHCI1394_HCControl_postedWriteEnable 0x00040000
  226. #define OHCI1394_HCControl_linkEnable 0x00020000
  227. #define OHCI1394_HCControl_softReset 0x00010000
  228. #define OHCI1394_SelfIDBuffer 0x064
  229. #define OHCI1394_SelfIDCount 0x068
  230. #define OHCI1394_IRMultiChanMaskHiSet 0x070
  231. #define OHCI1394_IRMultiChanMaskHiClear 0x074
  232. #define OHCI1394_IRMultiChanMaskLoSet 0x078
  233. #define OHCI1394_IRMultiChanMaskLoClear 0x07C
  234. #define OHCI1394_IntEventSet 0x080
  235. #define OHCI1394_IntEventClear 0x084
  236. #define OHCI1394_IntMaskSet 0x088
  237. #define OHCI1394_IntMaskClear 0x08C
  238. #define OHCI1394_IsoXmitIntEventSet 0x090
  239. #define OHCI1394_IsoXmitIntEventClear 0x094
  240. #define OHCI1394_IsoXmitIntMaskSet 0x098
  241. #define OHCI1394_IsoXmitIntMaskClear 0x09C
  242. #define OHCI1394_IsoRecvIntEventSet 0x0A0
  243. #define OHCI1394_IsoRecvIntEventClear 0x0A4
  244. #define OHCI1394_IsoRecvIntMaskSet 0x0A8
  245. #define OHCI1394_IsoRecvIntMaskClear 0x0AC
  246. #define OHCI1394_InitialBandwidthAvailable 0x0B0
  247. #define OHCI1394_InitialChannelsAvailableHi 0x0B4
  248. #define OHCI1394_InitialChannelsAvailableLo 0x0B8
  249. #define OHCI1394_FairnessControl 0x0DC
  250. #define OHCI1394_LinkControlSet 0x0E0
  251. #define OHCI1394_LinkControlClear 0x0E4
  252. #define OHCI1394_LinkControl_RcvSelfID 0x00000200
  253. #define OHCI1394_LinkControl_RcvPhyPkt 0x00000400
  254. #define OHCI1394_LinkControl_CycleTimerEnable 0x00100000
  255. #define OHCI1394_LinkControl_CycleMaster 0x00200000
  256. #define OHCI1394_LinkControl_CycleSource 0x00400000
  257. #define OHCI1394_NodeID 0x0E8
  258. #define OHCI1394_PhyControl 0x0EC
  259. #define OHCI1394_IsochronousCycleTimer 0x0F0
  260. #define OHCI1394_AsReqFilterHiSet 0x100
  261. #define OHCI1394_AsReqFilterHiClear 0x104
  262. #define OHCI1394_AsReqFilterLoSet 0x108
  263. #define OHCI1394_AsReqFilterLoClear 0x10C
  264. #define OHCI1394_PhyReqFilterHiSet 0x110
  265. #define OHCI1394_PhyReqFilterHiClear 0x114
  266. #define OHCI1394_PhyReqFilterLoSet 0x118
  267. #define OHCI1394_PhyReqFilterLoClear 0x11C
  268. #define OHCI1394_PhyUpperBound 0x120
  269. #define OHCI1394_AsReqTrContextBase 0x180
  270. #define OHCI1394_AsReqTrContextControlSet 0x180
  271. #define OHCI1394_AsReqTrContextControlClear 0x184
  272. #define OHCI1394_AsReqTrCommandPtr 0x18C
  273. #define OHCI1394_AsRspTrContextBase 0x1A0
  274. #define OHCI1394_AsRspTrContextControlSet 0x1A0
  275. #define OHCI1394_AsRspTrContextControlClear 0x1A4
  276. #define OHCI1394_AsRspTrCommandPtr 0x1AC
  277. #define OHCI1394_AsReqRcvContextBase 0x1C0
  278. #define OHCI1394_AsReqRcvContextControlSet 0x1C0
  279. #define OHCI1394_AsReqRcvContextControlClear 0x1C4
  280. #define OHCI1394_AsReqRcvCommandPtr 0x1CC
  281. #define OHCI1394_AsRspRcvContextBase 0x1E0
  282. #define OHCI1394_AsRspRcvContextControlSet 0x1E0
  283. #define OHCI1394_AsRspRcvContextControlClear 0x1E4
  284. #define OHCI1394_AsRspRcvCommandPtr 0x1EC
  285. /* Isochronous transmit registers */
  286. /* Add (16 * n) for context n */
  287. #define OHCI1394_IsoXmitContextBase 0x200
  288. #define OHCI1394_IsoXmitContextControlSet 0x200
  289. #define OHCI1394_IsoXmitContextControlClear 0x204
  290. #define OHCI1394_IsoXmitCommandPtr 0x20C
  291. /* Isochronous receive registers */
  292. /* Add (32 * n) for context n */
  293. #define OHCI1394_IsoRcvContextBase 0x400
  294. #define OHCI1394_IsoRcvContextControlSet 0x400
  295. #define OHCI1394_IsoRcvContextControlClear 0x404
  296. #define OHCI1394_IsoRcvCommandPtr 0x40C
  297. #define OHCI1394_IsoRcvContextMatch 0x410
  298. /* Interrupts Mask/Events */
  299. #define OHCI1394_reqTxComplete 0x00000001
  300. #define OHCI1394_respTxComplete 0x00000002
  301. #define OHCI1394_ARRQ 0x00000004
  302. #define OHCI1394_ARRS 0x00000008
  303. #define OHCI1394_RQPkt 0x00000010
  304. #define OHCI1394_RSPkt 0x00000020
  305. #define OHCI1394_isochTx 0x00000040
  306. #define OHCI1394_isochRx 0x00000080
  307. #define OHCI1394_postedWriteErr 0x00000100
  308. #define OHCI1394_lockRespErr 0x00000200
  309. #define OHCI1394_selfIDComplete 0x00010000
  310. #define OHCI1394_busReset 0x00020000
  311. #define OHCI1394_phy 0x00080000
  312. #define OHCI1394_cycleSynch 0x00100000
  313. #define OHCI1394_cycle64Seconds 0x00200000
  314. #define OHCI1394_cycleLost 0x00400000
  315. #define OHCI1394_cycleInconsistent 0x00800000
  316. #define OHCI1394_unrecoverableError 0x01000000
  317. #define OHCI1394_cycleTooLong 0x02000000
  318. #define OHCI1394_phyRegRcvd 0x04000000
  319. #define OHCI1394_masterIntEnable 0x80000000
  320. /* DMA Control flags */
  321. #define DMA_CTL_OUTPUT_MORE 0x00000000
  322. #define DMA_CTL_OUTPUT_LAST 0x10000000
  323. #define DMA_CTL_INPUT_MORE 0x20000000
  324. #define DMA_CTL_INPUT_LAST 0x30000000
  325. #define DMA_CTL_UPDATE 0x08000000
  326. #define DMA_CTL_IMMEDIATE 0x02000000
  327. #define DMA_CTL_IRQ 0x00300000
  328. #define DMA_CTL_BRANCH 0x000c0000
  329. #define DMA_CTL_WAIT 0x00030000
  330. /* OHCI evt_* error types, table 3-2 of the OHCI 1.1 spec. */
  331. #define EVT_NO_STATUS 0x0 /* No event status */
  332. #define EVT_RESERVED_A 0x1 /* Reserved, not used !!! */
  333. #define EVT_LONG_PACKET 0x2 /* The revc data was longer than the buf */
  334. #define EVT_MISSING_ACK 0x3 /* A subaction gap was detected before an ack
  335. arrived, or recv'd ack had a parity error */
  336. #define EVT_UNDERRUN 0x4 /* Underrun on corresponding FIFO, packet
  337. truncated */
  338. #define EVT_OVERRUN 0x5 /* A recv FIFO overflowed on reception of ISO
  339. packet */
  340. #define EVT_DESCRIPTOR_READ 0x6 /* An unrecoverable error occurred while host was
  341. reading a descriptor block */
  342. #define EVT_DATA_READ 0x7 /* An error occurred while host controller was
  343. attempting to read from host memory in the data
  344. stage of descriptor processing */
  345. #define EVT_DATA_WRITE 0x8 /* An error occurred while host controller was
  346. attempting to write either during the data stage
  347. of descriptor processing, or when processing a single
  348. 16-bit host memory write */
  349. #define EVT_BUS_RESET 0x9 /* Identifies a PHY packet in the recv buffer as
  350. being a synthesized bus reset packet */
  351. #define EVT_TIMEOUT 0xa /* Indicates that the asynchronous transmit response
  352. packet expired and was not transmitted, or that an
  353. IT DMA context experienced a skip processing overflow */
  354. #define EVT_TCODE_ERR 0xb /* A bad tCode is associated with this packet.
  355. The packet was flushed */
  356. #define EVT_RESERVED_B 0xc /* Reserved, not used !!! */
  357. #define EVT_RESERVED_C 0xd /* Reserved, not used !!! */
  358. #define EVT_UNKNOWN 0xe /* An error condition has occurred that cannot be
  359. represented by any other event codes defined herein. */
  360. #define EVT_FLUSHED 0xf /* Send by the link side of output FIFO when asynchronous
  361. packets are being flushed due to a bus reset. */
  362. #define OHCI1394_TCODE_PHY 0xE
  363. /* Node offset map (phys DMA area, posted write area).
  364. * The value of OHCI1394_PHYS_UPPER_BOUND_PROGRAMMED may be modified but must
  365. * be lower than OHCI1394_MIDDLE_ADDRESS_SPACE.
  366. * OHCI1394_PHYS_UPPER_BOUND_FIXED and OHCI1394_MIDDLE_ADDRESS_SPACE are
  367. * constants given by the OHCI spec.
  368. */
  369. #define OHCI1394_PHYS_UPPER_BOUND_FIXED 0x000100000000ULL /* 4 GB */
  370. #define OHCI1394_PHYS_UPPER_BOUND_PROGRAMMED 0x010000000000ULL /* 1 TB */
  371. #define OHCI1394_MIDDLE_ADDRESS_SPACE 0xffff00000000ULL
  372. void ohci1394_init_iso_tasklet(struct ohci1394_iso_tasklet *tasklet,
  373. int type,
  374. void (*func)(unsigned long),
  375. unsigned long data);
  376. int ohci1394_register_iso_tasklet(struct ti_ohci *ohci,
  377. struct ohci1394_iso_tasklet *tasklet);
  378. void ohci1394_unregister_iso_tasklet(struct ti_ohci *ohci,
  379. struct ohci1394_iso_tasklet *tasklet);
  380. int ohci1394_stop_context(struct ti_ohci *ohci, int reg, char *msg);
  381. struct ti_ohci *ohci1394_get_struct(int card_num);
  382. #endif