pcilynx.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. #ifndef __PCILYNX_H__
  2. #define __PCILYNX_H__
  3. #define PCILYNX_DRIVER_NAME "pcilynx"
  4. #define PCILYNX_MAJOR 177
  5. #define PCILYNX_MINOR_AUX_START 0
  6. #define PCILYNX_MINOR_ROM_START 16
  7. #define PCILYNX_MINOR_RAM_START 32
  8. #define PCILYNX_MAX_REGISTER 0xfff
  9. #define PCILYNX_MAX_MEMORY 0xffff
  10. #define PCI_DEVICE_ID_TI_PCILYNX 0x8000
  11. #define MAX_PCILYNX_CARDS 4
  12. #define LOCALRAM_SIZE 4096
  13. #define NUM_ISORCV_PCL 4
  14. #define MAX_ISORCV_SIZE 2048
  15. #define ISORCV_PER_PAGE (PAGE_SIZE / MAX_ISORCV_SIZE)
  16. #define ISORCV_PAGES (NUM_ISORCV_PCL / ISORCV_PER_PAGE)
  17. #define CHANNEL_LOCALBUS 0
  18. #define CHANNEL_ASYNC_RCV 1
  19. #define CHANNEL_ISO_RCV 2
  20. #define CHANNEL_ASYNC_SEND 3
  21. #define CHANNEL_ISO_SEND 4
  22. #define PCILYNX_CONFIG_ROM_LENGTH 1024
  23. typedef int pcl_t;
  24. struct ti_lynx {
  25. int id; /* sequential card number */
  26. spinlock_t lock;
  27. struct pci_dev *dev;
  28. struct {
  29. unsigned reg_1394a:1;
  30. u32 vendor;
  31. u32 product;
  32. } phyic;
  33. enum { clear, have_intr, have_aux_buf, have_pcl_mem,
  34. have_1394_buffers, have_iomappings, is_host } state;
  35. /* remapped memory spaces */
  36. void __iomem *registers;
  37. void __iomem *local_rom;
  38. void __iomem *local_ram;
  39. void __iomem *aux_port;
  40. quadlet_t bus_info_block[5];
  41. /*
  42. * use local RAM of LOCALRAM_SIZE bytes for PCLs, which allows for
  43. * LOCALRAM_SIZE * 8 PCLs (each sized 128 bytes);
  44. * the following is an allocation bitmap
  45. */
  46. u8 pcl_bmap[LOCALRAM_SIZE / 1024];
  47. /* point to PCLs memory area if needed */
  48. void *pcl_mem;
  49. dma_addr_t pcl_mem_dma;
  50. /* PCLs for local mem / aux transfers */
  51. pcl_t dmem_pcl;
  52. /* IEEE-1394 part follows */
  53. struct hpsb_host *host;
  54. int phyid, isroot;
  55. int selfid_size;
  56. int phy_reg0;
  57. spinlock_t phy_reg_lock;
  58. pcl_t rcv_pcl_start, rcv_pcl;
  59. void *rcv_page;
  60. dma_addr_t rcv_page_dma;
  61. int rcv_active;
  62. struct lynx_send_data {
  63. pcl_t pcl_start, pcl;
  64. struct list_head queue;
  65. struct list_head pcl_queue; /* this queue contains at most one packet */
  66. spinlock_t queue_lock;
  67. dma_addr_t header_dma, data_dma;
  68. int channel;
  69. } async, iso_send;
  70. struct {
  71. pcl_t pcl[NUM_ISORCV_PCL];
  72. u32 stat[NUM_ISORCV_PCL];
  73. void *page[ISORCV_PAGES];
  74. dma_addr_t page_dma[ISORCV_PAGES];
  75. pcl_t pcl_start;
  76. int chan_count;
  77. int next, last, used, running;
  78. struct tasklet_struct tq;
  79. spinlock_t lock;
  80. } iso_rcv;
  81. u32 i2c_driven_state; /* the state we currently drive the Serial EEPROM Control register */
  82. };
  83. /* the per-file data structure for mem space access */
  84. struct memdata {
  85. struct ti_lynx *lynx;
  86. int cid;
  87. atomic_t aux_intr_last_seen;
  88. /* enum values are the same as LBUS_ADDR_SEL_* values below */
  89. enum { rom = 0x10000, aux = 0x20000, ram = 0 } type;
  90. };
  91. /*
  92. * Register read and write helper functions.
  93. */
  94. static inline void reg_write(const struct ti_lynx *lynx, int offset, u32 data)
  95. {
  96. writel(data, lynx->registers + offset);
  97. }
  98. static inline u32 reg_read(const struct ti_lynx *lynx, int offset)
  99. {
  100. return readl(lynx->registers + offset);
  101. }
  102. static inline void reg_set_bits(const struct ti_lynx *lynx, int offset,
  103. u32 mask)
  104. {
  105. reg_write(lynx, offset, (reg_read(lynx, offset) | mask));
  106. }
  107. static inline void reg_clear_bits(const struct ti_lynx *lynx, int offset,
  108. u32 mask)
  109. {
  110. reg_write(lynx, offset, (reg_read(lynx, offset) & ~mask));
  111. }
  112. /* chip register definitions follow */
  113. #define PCI_LATENCY_CACHELINE 0x0c
  114. #define MISC_CONTROL 0x40
  115. #define MISC_CONTROL_SWRESET (1<<0)
  116. #define SERIAL_EEPROM_CONTROL 0x44
  117. #define PCI_INT_STATUS 0x48
  118. #define PCI_INT_ENABLE 0x4c
  119. /* status and enable have identical bit numbers */
  120. #define PCI_INT_INT_PEND (1<<31)
  121. #define PCI_INT_FORCED_INT (1<<30)
  122. #define PCI_INT_SLV_ADR_PERR (1<<28)
  123. #define PCI_INT_SLV_DAT_PERR (1<<27)
  124. #define PCI_INT_MST_DAT_PERR (1<<26)
  125. #define PCI_INT_MST_DEV_TIMEOUT (1<<25)
  126. #define PCI_INT_INTERNAL_SLV_TIMEOUT (1<<23)
  127. #define PCI_INT_AUX_TIMEOUT (1<<18)
  128. #define PCI_INT_AUX_INT (1<<17)
  129. #define PCI_INT_1394 (1<<16)
  130. #define PCI_INT_DMA4_PCL (1<<9)
  131. #define PCI_INT_DMA4_HLT (1<<8)
  132. #define PCI_INT_DMA3_PCL (1<<7)
  133. #define PCI_INT_DMA3_HLT (1<<6)
  134. #define PCI_INT_DMA2_PCL (1<<5)
  135. #define PCI_INT_DMA2_HLT (1<<4)
  136. #define PCI_INT_DMA1_PCL (1<<3)
  137. #define PCI_INT_DMA1_HLT (1<<2)
  138. #define PCI_INT_DMA0_PCL (1<<1)
  139. #define PCI_INT_DMA0_HLT (1<<0)
  140. /* all DMA interrupts combined: */
  141. #define PCI_INT_DMA_ALL 0x3ff
  142. #define PCI_INT_DMA_HLT(chan) (1 << (chan * 2))
  143. #define PCI_INT_DMA_PCL(chan) (1 << (chan * 2 + 1))
  144. #define LBUS_ADDR 0xb4
  145. #define LBUS_ADDR_SEL_RAM (0x0<<16)
  146. #define LBUS_ADDR_SEL_ROM (0x1<<16)
  147. #define LBUS_ADDR_SEL_AUX (0x2<<16)
  148. #define LBUS_ADDR_SEL_ZV (0x3<<16)
  149. #define GPIO_CTRL_A 0xb8
  150. #define GPIO_CTRL_B 0xbc
  151. #define GPIO_DATA_BASE 0xc0
  152. #define DMA_BREG(base, chan) (base + chan * 0x20)
  153. #define DMA_SREG(base, chan) (base + chan * 0x10)
  154. #define DMA0_PREV_PCL 0x100
  155. #define DMA1_PREV_PCL 0x120
  156. #define DMA2_PREV_PCL 0x140
  157. #define DMA3_PREV_PCL 0x160
  158. #define DMA4_PREV_PCL 0x180
  159. #define DMA_PREV_PCL(chan) (DMA_BREG(DMA0_PREV_PCL, chan))
  160. #define DMA0_CURRENT_PCL 0x104
  161. #define DMA1_CURRENT_PCL 0x124
  162. #define DMA2_CURRENT_PCL 0x144
  163. #define DMA3_CURRENT_PCL 0x164
  164. #define DMA4_CURRENT_PCL 0x184
  165. #define DMA_CURRENT_PCL(chan) (DMA_BREG(DMA0_CURRENT_PCL, chan))
  166. #define DMA0_CHAN_STAT 0x10c
  167. #define DMA1_CHAN_STAT 0x12c
  168. #define DMA2_CHAN_STAT 0x14c
  169. #define DMA3_CHAN_STAT 0x16c
  170. #define DMA4_CHAN_STAT 0x18c
  171. #define DMA_CHAN_STAT(chan) (DMA_BREG(DMA0_CHAN_STAT, chan))
  172. /* CHAN_STATUS registers share bits */
  173. #define DMA_CHAN_STAT_SELFID (1<<31)
  174. #define DMA_CHAN_STAT_ISOPKT (1<<30)
  175. #define DMA_CHAN_STAT_PCIERR (1<<29)
  176. #define DMA_CHAN_STAT_PKTERR (1<<28)
  177. #define DMA_CHAN_STAT_PKTCMPL (1<<27)
  178. #define DMA_CHAN_STAT_SPECIALACK (1<<14)
  179. #define DMA0_CHAN_CTRL 0x110
  180. #define DMA1_CHAN_CTRL 0x130
  181. #define DMA2_CHAN_CTRL 0x150
  182. #define DMA3_CHAN_CTRL 0x170
  183. #define DMA4_CHAN_CTRL 0x190
  184. #define DMA_CHAN_CTRL(chan) (DMA_BREG(DMA0_CHAN_CTRL, chan))
  185. /* CHAN_CTRL registers share bits */
  186. #define DMA_CHAN_CTRL_ENABLE (1<<31)
  187. #define DMA_CHAN_CTRL_BUSY (1<<30)
  188. #define DMA_CHAN_CTRL_LINK (1<<29)
  189. #define DMA0_READY 0x114
  190. #define DMA1_READY 0x134
  191. #define DMA2_READY 0x154
  192. #define DMA3_READY 0x174
  193. #define DMA4_READY 0x194
  194. #define DMA_READY(chan) (DMA_BREG(DMA0_READY, chan))
  195. #define DMA_GLOBAL_REGISTER 0x908
  196. #define FIFO_SIZES 0xa00
  197. #define FIFO_CONTROL 0xa10
  198. #define FIFO_CONTROL_GRF_FLUSH (1<<4)
  199. #define FIFO_CONTROL_ITF_FLUSH (1<<3)
  200. #define FIFO_CONTROL_ATF_FLUSH (1<<2)
  201. #define FIFO_XMIT_THRESHOLD 0xa14
  202. #define DMA0_WORD0_CMP_VALUE 0xb00
  203. #define DMA1_WORD0_CMP_VALUE 0xb10
  204. #define DMA2_WORD0_CMP_VALUE 0xb20
  205. #define DMA3_WORD0_CMP_VALUE 0xb30
  206. #define DMA4_WORD0_CMP_VALUE 0xb40
  207. #define DMA_WORD0_CMP_VALUE(chan) (DMA_SREG(DMA0_WORD0_CMP_VALUE, chan))
  208. #define DMA0_WORD0_CMP_ENABLE 0xb04
  209. #define DMA1_WORD0_CMP_ENABLE 0xb14
  210. #define DMA2_WORD0_CMP_ENABLE 0xb24
  211. #define DMA3_WORD0_CMP_ENABLE 0xb34
  212. #define DMA4_WORD0_CMP_ENABLE 0xb44
  213. #define DMA_WORD0_CMP_ENABLE(chan) (DMA_SREG(DMA0_WORD0_CMP_ENABLE,chan))
  214. #define DMA0_WORD1_CMP_VALUE 0xb08
  215. #define DMA1_WORD1_CMP_VALUE 0xb18
  216. #define DMA2_WORD1_CMP_VALUE 0xb28
  217. #define DMA3_WORD1_CMP_VALUE 0xb38
  218. #define DMA4_WORD1_CMP_VALUE 0xb48
  219. #define DMA_WORD1_CMP_VALUE(chan) (DMA_SREG(DMA0_WORD1_CMP_VALUE, chan))
  220. #define DMA0_WORD1_CMP_ENABLE 0xb0c
  221. #define DMA1_WORD1_CMP_ENABLE 0xb1c
  222. #define DMA2_WORD1_CMP_ENABLE 0xb2c
  223. #define DMA3_WORD1_CMP_ENABLE 0xb3c
  224. #define DMA4_WORD1_CMP_ENABLE 0xb4c
  225. #define DMA_WORD1_CMP_ENABLE(chan) (DMA_SREG(DMA0_WORD1_CMP_ENABLE,chan))
  226. /* word 1 compare enable flags */
  227. #define DMA_WORD1_CMP_MATCH_OTHERBUS (1<<15)
  228. #define DMA_WORD1_CMP_MATCH_BROADCAST (1<<14)
  229. #define DMA_WORD1_CMP_MATCH_BUS_BCAST (1<<13)
  230. #define DMA_WORD1_CMP_MATCH_LOCAL_NODE (1<<12)
  231. #define DMA_WORD1_CMP_MATCH_EXACT (1<<11)
  232. #define DMA_WORD1_CMP_ENABLE_SELF_ID (1<<10)
  233. #define DMA_WORD1_CMP_ENABLE_MASTER (1<<8)
  234. #define LINK_ID 0xf00
  235. #define LINK_ID_BUS(id) (id<<22)
  236. #define LINK_ID_NODE(id) (id<<16)
  237. #define LINK_CONTROL 0xf04
  238. #define LINK_CONTROL_BUSY (1<<29)
  239. #define LINK_CONTROL_TX_ISO_EN (1<<26)
  240. #define LINK_CONTROL_RX_ISO_EN (1<<25)
  241. #define LINK_CONTROL_TX_ASYNC_EN (1<<24)
  242. #define LINK_CONTROL_RX_ASYNC_EN (1<<23)
  243. #define LINK_CONTROL_RESET_TX (1<<21)
  244. #define LINK_CONTROL_RESET_RX (1<<20)
  245. #define LINK_CONTROL_CYCMASTER (1<<11)
  246. #define LINK_CONTROL_CYCSOURCE (1<<10)
  247. #define LINK_CONTROL_CYCTIMEREN (1<<9)
  248. #define LINK_CONTROL_RCV_CMP_VALID (1<<7)
  249. #define LINK_CONTROL_SNOOP_ENABLE (1<<6)
  250. #define CYCLE_TIMER 0xf08
  251. #define LINK_PHY 0xf0c
  252. #define LINK_PHY_READ (1<<31)
  253. #define LINK_PHY_WRITE (1<<30)
  254. #define LINK_PHY_ADDR(addr) (addr<<24)
  255. #define LINK_PHY_WDATA(data) (data<<16)
  256. #define LINK_PHY_RADDR(addr) (addr<<8)
  257. #define LINK_INT_STATUS 0xf14
  258. #define LINK_INT_ENABLE 0xf18
  259. /* status and enable have identical bit numbers */
  260. #define LINK_INT_LINK_INT (1<<31)
  261. #define LINK_INT_PHY_TIMEOUT (1<<30)
  262. #define LINK_INT_PHY_REG_RCVD (1<<29)
  263. #define LINK_INT_PHY_BUSRESET (1<<28)
  264. #define LINK_INT_TX_RDY (1<<26)
  265. #define LINK_INT_RX_DATA_RDY (1<<25)
  266. #define LINK_INT_ISO_STUCK (1<<20)
  267. #define LINK_INT_ASYNC_STUCK (1<<19)
  268. #define LINK_INT_SENT_REJECT (1<<17)
  269. #define LINK_INT_HDR_ERR (1<<16)
  270. #define LINK_INT_TX_INVALID_TC (1<<15)
  271. #define LINK_INT_CYC_SECOND (1<<11)
  272. #define LINK_INT_CYC_START (1<<10)
  273. #define LINK_INT_CYC_DONE (1<<9)
  274. #define LINK_INT_CYC_PENDING (1<<8)
  275. #define LINK_INT_CYC_LOST (1<<7)
  276. #define LINK_INT_CYC_ARB_FAILED (1<<6)
  277. #define LINK_INT_GRF_OVERFLOW (1<<5)
  278. #define LINK_INT_ITF_UNDERFLOW (1<<4)
  279. #define LINK_INT_ATF_UNDERFLOW (1<<3)
  280. #define LINK_INT_ISOARB_FAILED (1<<0)
  281. /* PHY specifics */
  282. #define PHY_VENDORID_TI 0x800028
  283. #define PHY_PRODUCTID_TSB41LV03 0x000000
  284. /* this is the physical layout of a PCL, its size is 128 bytes */
  285. struct ti_pcl {
  286. u32 next;
  287. u32 async_error_next;
  288. u32 user_data;
  289. u32 pcl_status;
  290. u32 remaining_transfer_count;
  291. u32 next_data_buffer;
  292. struct {
  293. u32 control;
  294. u32 pointer;
  295. } buffer[13] __attribute__ ((packed));
  296. } __attribute__ ((packed));
  297. #include <linux/stddef.h>
  298. #define pcloffs(MEMBER) (offsetof(struct ti_pcl, MEMBER))
  299. static inline void put_pcl(const struct ti_lynx *lynx, pcl_t pclid,
  300. const struct ti_pcl *pcl)
  301. {
  302. memcpy_le32((u32 *)(lynx->pcl_mem + pclid * sizeof(struct ti_pcl)),
  303. (u32 *)pcl, sizeof(struct ti_pcl));
  304. }
  305. static inline void get_pcl(const struct ti_lynx *lynx, pcl_t pclid,
  306. struct ti_pcl *pcl)
  307. {
  308. memcpy_le32((u32 *)pcl,
  309. (u32 *)(lynx->pcl_mem + pclid * sizeof(struct ti_pcl)),
  310. sizeof(struct ti_pcl));
  311. }
  312. static inline u32 pcl_bus(const struct ti_lynx *lynx, pcl_t pclid)
  313. {
  314. return lynx->pcl_mem_dma + pclid * sizeof(struct ti_pcl);
  315. }
  316. #if defined (__BIG_ENDIAN)
  317. typedef struct ti_pcl pcltmp_t;
  318. static inline struct ti_pcl *edit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
  319. pcltmp_t *tmp)
  320. {
  321. get_pcl(lynx, pclid, tmp);
  322. return tmp;
  323. }
  324. static inline void commit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
  325. pcltmp_t *tmp)
  326. {
  327. put_pcl(lynx, pclid, tmp);
  328. }
  329. #else
  330. typedef int pcltmp_t; /* just a dummy */
  331. static inline struct ti_pcl *edit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
  332. pcltmp_t *tmp)
  333. {
  334. return lynx->pcl_mem + pclid * sizeof(struct ti_pcl);
  335. }
  336. static inline void commit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
  337. pcltmp_t *tmp)
  338. {
  339. }
  340. #endif
  341. static inline void run_sub_pcl(const struct ti_lynx *lynx, pcl_t pclid, int idx,
  342. int dmachan)
  343. {
  344. reg_write(lynx, DMA0_CURRENT_PCL + dmachan * 0x20,
  345. pcl_bus(lynx, pclid) + idx * 4);
  346. reg_write(lynx, DMA0_CHAN_CTRL + dmachan * 0x20,
  347. DMA_CHAN_CTRL_ENABLE | DMA_CHAN_CTRL_LINK);
  348. }
  349. static inline void run_pcl(const struct ti_lynx *lynx, pcl_t pclid, int dmachan)
  350. {
  351. run_sub_pcl(lynx, pclid, 0, dmachan);
  352. }
  353. #define PCL_NEXT_INVALID (1<<0)
  354. /* transfer commands */
  355. #define PCL_CMD_RCV (0x1<<24)
  356. #define PCL_CMD_RCV_AND_UPDATE (0xa<<24)
  357. #define PCL_CMD_XMT (0x2<<24)
  358. #define PCL_CMD_UNFXMT (0xc<<24)
  359. #define PCL_CMD_PCI_TO_LBUS (0x8<<24)
  360. #define PCL_CMD_LBUS_TO_PCI (0x9<<24)
  361. /* aux commands */
  362. #define PCL_CMD_NOP (0x0<<24)
  363. #define PCL_CMD_LOAD (0x3<<24)
  364. #define PCL_CMD_STOREQ (0x4<<24)
  365. #define PCL_CMD_STORED (0xb<<24)
  366. #define PCL_CMD_STORE0 (0x5<<24)
  367. #define PCL_CMD_STORE1 (0x6<<24)
  368. #define PCL_CMD_COMPARE (0xe<<24)
  369. #define PCL_CMD_SWAP_COMPARE (0xf<<24)
  370. #define PCL_CMD_ADD (0xd<<24)
  371. #define PCL_CMD_BRANCH (0x7<<24)
  372. /* BRANCH condition codes */
  373. #define PCL_COND_DMARDY_SET (0x1<<20)
  374. #define PCL_COND_DMARDY_CLEAR (0x2<<20)
  375. #define PCL_GEN_INTR (1<<19)
  376. #define PCL_LAST_BUFF (1<<18)
  377. #define PCL_LAST_CMD (PCL_LAST_BUFF)
  378. #define PCL_WAITSTAT (1<<17)
  379. #define PCL_BIGENDIAN (1<<16)
  380. #define PCL_ISOMODE (1<<12)
  381. #endif