pcilynx.h 16 KB

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