1 #include <linux/config.h>
3 #define PCILYNX_DRIVER_NAME "pcilynx"
4 #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
10 #define PCILYNX_MAX_REGISTER 0xfff
11 #define PCILYNX_MAX_MEMORY 0xffff
13 #define PCI_DEVICE_ID_TI_PCILYNX 0x8000
14 #define MAX_PCILYNX_CARDS 4
15 #define LOCALRAM_SIZE 4096
17 #define NUM_ISORCV_PCL 4
18 #define MAX_ISORCV_SIZE 2048
19 #define ISORCV_PER_PAGE (PAGE_SIZE / MAX_ISORCV_SIZE)
20 #define ISORCV_PAGES (NUM_ISORCV_PCL / ISORCV_PER_PAGE)
22 #define CHANNEL_LOCALBUS 0
23 #define CHANNEL_ASYNC_RCV 1
24 #define CHANNEL_ISO_RCV 2
25 #define CHANNEL_ASYNC_SEND 3
26 #define CHANNEL_ISO_SEND 4
31 int id; /* sequential card number */
43 enum { clear, have_intr, have_aux_buf, have_pcl_mem,
44 have_1394_buffers, have_iomappings } state;
46 /* remapped memory spaces */
53 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
54 atomic_t aux_intr_seen;
55 wait_queue_head_t aux_intr_wait;
58 dma_addr_t mem_dma_buffer_dma;
59 struct semaphore mem_dma_mutex;
60 wait_queue_head_t mem_dma_intr_wait;
64 * use local RAM of LOCALRAM_SIZE bytes for PCLs, which allows for
65 * LOCALRAM_SIZE * 8 PCLs (each sized 128 bytes);
66 * the following is an allocation bitmap
68 u8 pcl_bmap[LOCALRAM_SIZE / 1024];
70 #ifndef CONFIG_IEEE1394_PCILYNX_LOCALRAM
71 /* point to PCLs memory area if needed */
73 dma_addr_t pcl_mem_dma;
76 /* PCLs for local mem / aux transfers */
79 /* IEEE-1394 part follows */
80 struct hpsb_host *host;
84 spinlock_t phy_reg_lock;
86 pcl_t rcv_pcl_start, rcv_pcl;
88 dma_addr_t rcv_page_dma;
91 struct lynx_send_data {
93 struct hpsb_packet *queue, *queue_last;
94 spinlock_t queue_lock;
95 dma_addr_t header_dma, data_dma;
100 pcl_t pcl[NUM_ISORCV_PCL];
101 u32 stat[NUM_ISORCV_PCL];
102 void *page[ISORCV_PAGES];
103 dma_addr_t page_dma[ISORCV_PAGES];
106 int next, last, used, running;
112 /* the per-file data structure for mem space access */
114 struct ti_lynx *lynx;
116 atomic_t aux_intr_last_seen;
117 /* enum values are the same as LBUS_ADDR_SEL_* values below */
118 enum { rom = 0x10000, aux = 0x20000, ram = 0 } type;
124 * Register read and write helper functions.
126 inline static void reg_write(const struct ti_lynx *lynx, int offset, u32 data)
128 writel(data, lynx->registers + offset);
131 inline static u32 reg_read(const struct ti_lynx *lynx, int offset)
133 return readl(lynx->registers + offset);
136 inline static void reg_set_bits(const struct ti_lynx *lynx, int offset,
139 reg_write(lynx, offset, (reg_read(lynx, offset) | mask));
142 inline static void reg_clear_bits(const struct ti_lynx *lynx, int offset,
145 reg_write(lynx, offset, (reg_read(lynx, offset) & ~mask));
150 /* chip register definitions follow */
152 #define PCI_LATENCY_CACHELINE 0x0c
154 #define MISC_CONTROL 0x40
155 #define MISC_CONTROL_SWRESET (1<<0)
157 #define PCI_INT_STATUS 0x48
158 #define PCI_INT_ENABLE 0x4c
159 /* status and enable have identical bit numbers */
160 #define PCI_INT_INT_PEND (1<<31)
161 #define PCI_INT_FORCED_INT (1<<30)
162 #define PCI_INT_SLV_ADR_PERR (1<<28)
163 #define PCI_INT_SLV_DAT_PERR (1<<27)
164 #define PCI_INT_MST_DAT_PERR (1<<26)
165 #define PCI_INT_MST_DEV_TIMEOUT (1<<25)
166 #define PCI_INT_INTERNAL_SLV_TIMEOUT (1<<23)
167 #define PCI_INT_AUX_TIMEOUT (1<<18)
168 #define PCI_INT_AUX_INT (1<<17)
169 #define PCI_INT_1394 (1<<16)
170 #define PCI_INT_DMA4_PCL (1<<9)
171 #define PCI_INT_DMA4_HLT (1<<8)
172 #define PCI_INT_DMA3_PCL (1<<7)
173 #define PCI_INT_DMA3_HLT (1<<6)
174 #define PCI_INT_DMA2_PCL (1<<5)
175 #define PCI_INT_DMA2_HLT (1<<4)
176 #define PCI_INT_DMA1_PCL (1<<3)
177 #define PCI_INT_DMA1_HLT (1<<2)
178 #define PCI_INT_DMA0_PCL (1<<1)
179 #define PCI_INT_DMA0_HLT (1<<0)
180 /* all DMA interrupts combined: */
181 #define PCI_INT_DMA_ALL 0x3ff
183 #define PCI_INT_DMA_HLT(chan) (1 << (chan * 2))
184 #define PCI_INT_DMA_PCL(chan) (1 << (chan * 2 + 1))
186 #define LBUS_ADDR 0xb4
187 #define LBUS_ADDR_SEL_RAM (0x0<<16)
188 #define LBUS_ADDR_SEL_ROM (0x1<<16)
189 #define LBUS_ADDR_SEL_AUX (0x2<<16)
190 #define LBUS_ADDR_SEL_ZV (0x3<<16)
192 #define GPIO_CTRL_A 0xb8
193 #define GPIO_CTRL_B 0xbc
194 #define GPIO_DATA_BASE 0xc0
196 #define DMA_BREG(base, chan) (base + chan * 0x20)
197 #define DMA_SREG(base, chan) (base + chan * 0x10)
199 #define DMA0_PREV_PCL 0x100
200 #define DMA1_PREV_PCL 0x120
201 #define DMA2_PREV_PCL 0x140
202 #define DMA3_PREV_PCL 0x160
203 #define DMA4_PREV_PCL 0x180
204 #define DMA_PREV_PCL(chan) (DMA_BREG(DMA0_PREV_PCL, chan))
206 #define DMA0_CURRENT_PCL 0x104
207 #define DMA1_CURRENT_PCL 0x124
208 #define DMA2_CURRENT_PCL 0x144
209 #define DMA3_CURRENT_PCL 0x164
210 #define DMA4_CURRENT_PCL 0x184
211 #define DMA_CURRENT_PCL(chan) (DMA_BREG(DMA0_CURRENT_PCL, chan))
213 #define DMA0_CHAN_STAT 0x10c
214 #define DMA1_CHAN_STAT 0x12c
215 #define DMA2_CHAN_STAT 0x14c
216 #define DMA3_CHAN_STAT 0x16c
217 #define DMA4_CHAN_STAT 0x18c
218 #define DMA_CHAN_STAT(chan) (DMA_BREG(DMA0_CHAN_STAT, chan))
219 /* CHAN_STATUS registers share bits */
220 #define DMA_CHAN_STAT_SELFID (1<<31)
221 #define DMA_CHAN_STAT_ISOPKT (1<<30)
222 #define DMA_CHAN_STAT_PCIERR (1<<29)
223 #define DMA_CHAN_STAT_PKTERR (1<<28)
224 #define DMA_CHAN_STAT_PKTCMPL (1<<27)
225 #define DMA_CHAN_STAT_SPECIALACK (1<<14)
228 #define DMA0_CHAN_CTRL 0x110
229 #define DMA1_CHAN_CTRL 0x130
230 #define DMA2_CHAN_CTRL 0x150
231 #define DMA3_CHAN_CTRL 0x170
232 #define DMA4_CHAN_CTRL 0x190
233 #define DMA_CHAN_CTRL(chan) (DMA_BREG(DMA0_CHAN_CTRL, chan))
234 /* CHAN_CTRL registers share bits */
235 #define DMA_CHAN_CTRL_ENABLE (1<<31)
236 #define DMA_CHAN_CTRL_BUSY (1<<30)
237 #define DMA_CHAN_CTRL_LINK (1<<29)
239 #define DMA0_READY 0x114
240 #define DMA1_READY 0x134
241 #define DMA2_READY 0x154
242 #define DMA3_READY 0x174
243 #define DMA4_READY 0x194
244 #define DMA_READY(chan) (DMA_BREG(DMA0_READY, chan))
246 #define DMA_GLOBAL_REGISTER 0x908
248 #define FIFO_SIZES 0xa00
250 #define FIFO_CONTROL 0xa10
251 #define GRF_FLUSH (1<<4)
252 #define ITF_FLUSH (1<<3)
253 #define ATF_FLUSH (1<<2)
255 #define FIFO_XMIT_THRESHOLD 0xa14
257 #define DMA0_WORD0_CMP_VALUE 0xb00
258 #define DMA1_WORD0_CMP_VALUE 0xb10
259 #define DMA2_WORD0_CMP_VALUE 0xb20
260 #define DMA3_WORD0_CMP_VALUE 0xb30
261 #define DMA4_WORD0_CMP_VALUE 0xb40
262 #define DMA_WORD0_CMP_VALUE(chan) (DMA_SREG(DMA0_WORD0_CMP_VALUE, chan))
264 #define DMA0_WORD0_CMP_ENABLE 0xb04
265 #define DMA1_WORD0_CMP_ENABLE 0xb14
266 #define DMA2_WORD0_CMP_ENABLE 0xb24
267 #define DMA3_WORD0_CMP_ENABLE 0xb34
268 #define DMA4_WORD0_CMP_ENABLE 0xb44
269 #define DMA_WORD0_CMP_ENABLE(chan) (DMA_SREG(DMA0_WORD0_CMP_ENABLE,chan))
271 #define DMA0_WORD1_CMP_VALUE 0xb08
272 #define DMA1_WORD1_CMP_VALUE 0xb18
273 #define DMA2_WORD1_CMP_VALUE 0xb28
274 #define DMA3_WORD1_CMP_VALUE 0xb38
275 #define DMA4_WORD1_CMP_VALUE 0xb48
276 #define DMA_WORD1_CMP_VALUE(chan) (DMA_SREG(DMA0_WORD1_CMP_VALUE, chan))
278 #define DMA0_WORD1_CMP_ENABLE 0xb0c
279 #define DMA1_WORD1_CMP_ENABLE 0xb1c
280 #define DMA2_WORD1_CMP_ENABLE 0xb2c
281 #define DMA3_WORD1_CMP_ENABLE 0xb3c
282 #define DMA4_WORD1_CMP_ENABLE 0xb4c
283 #define DMA_WORD1_CMP_ENABLE(chan) (DMA_SREG(DMA0_WORD1_CMP_ENABLE,chan))
284 /* word 1 compare enable flags */
285 #define DMA_WORD1_CMP_MATCH_OTHERBUS (1<<15)
286 #define DMA_WORD1_CMP_MATCH_BROADCAST (1<<14)
287 #define DMA_WORD1_CMP_MATCH_BUS_BCAST (1<<13)
288 #define DMA_WORD1_CMP_MATCH_NODE_BCAST (1<<12)
289 #define DMA_WORD1_CMP_MATCH_LOCAL (1<<11)
290 #define DMA_WORD1_CMP_ENABLE_SELF_ID (1<<10)
291 #define DMA_WORD1_CMP_ENABLE_MASTER (1<<8)
293 #define LINK_ID 0xf00
294 #define LINK_ID_BUS(id) (id<<22)
295 #define LINK_ID_NODE(id) (id<<16)
297 #define LINK_CONTROL 0xf04
298 #define LINK_CONTROL_BUSY (1<<29)
299 #define LINK_CONTROL_TX_ISO_EN (1<<26)
300 #define LINK_CONTROL_RX_ISO_EN (1<<25)
301 #define LINK_CONTROL_TX_ASYNC_EN (1<<24)
302 #define LINK_CONTROL_RX_ASYNC_EN (1<<23)
303 #define LINK_CONTROL_RESET_TX (1<<21)
304 #define LINK_CONTROL_RESET_RX (1<<20)
305 #define LINK_CONTROL_CYCMASTER (1<<11)
306 #define LINK_CONTROL_CYCSOURCE (1<<10)
307 #define LINK_CONTROL_CYCTIMEREN (1<<9)
308 #define LINK_CONTROL_RCV_CMP_VALID (1<<7)
309 #define LINK_CONTROL_SNOOP_ENABLE (1<<6)
311 #define CYCLE_TIMER 0xf08
313 #define LINK_PHY 0xf0c
314 #define LINK_PHY_READ (1<<31)
315 #define LINK_PHY_WRITE (1<<30)
316 #define LINK_PHY_ADDR(addr) (addr<<24)
317 #define LINK_PHY_WDATA(data) (data<<16)
318 #define LINK_PHY_RADDR(addr) (addr<<8)
321 #define LINK_INT_STATUS 0xf14
322 #define LINK_INT_ENABLE 0xf18
323 /* status and enable have identical bit numbers */
324 #define LINK_INT_LINK_INT (1<<31)
325 #define LINK_INT_PHY_TIMEOUT (1<<30)
326 #define LINK_INT_PHY_REG_RCVD (1<<29)
327 #define LINK_INT_PHY_BUSRESET (1<<28)
328 #define LINK_INT_TX_RDY (1<<26)
329 #define LINK_INT_RX_DATA_RDY (1<<25)
330 #define LINK_INT_ISO_STUCK (1<<20)
331 #define LINK_INT_ASYNC_STUCK (1<<19)
332 #define LINK_INT_SENT_REJECT (1<<17)
333 #define LINK_INT_HDR_ERR (1<<16)
334 #define LINK_INT_TX_INVALID_TC (1<<15)
335 #define LINK_INT_CYC_SECOND (1<<11)
336 #define LINK_INT_CYC_START (1<<10)
337 #define LINK_INT_CYC_DONE (1<<9)
338 #define LINK_INT_CYC_PENDING (1<<8)
339 #define LINK_INT_CYC_LOST (1<<7)
340 #define LINK_INT_CYC_ARB_FAILED (1<<6)
341 #define LINK_INT_GRF_OVERFLOW (1<<5)
342 #define LINK_INT_ITF_UNDERFLOW (1<<4)
343 #define LINK_INT_ATF_UNDERFLOW (1<<3)
344 #define LINK_INT_ISOARB_FAILED (1<<0)
347 #define PHY_VENDORID_TI 0x800028
348 #define PHY_PRODUCTID_TSB41LV03 0x000000
351 /* this is the physical layout of a PCL, its size is 128 bytes */
354 u32 async_error_next;
357 u32 remaining_transfer_count;
358 u32 next_data_buffer;
362 } buffer[13] __attribute__ ((packed));
363 } __attribute__ ((packed));
365 #include <linux/stddef.h>
366 #define pcloffs(MEMBER) (offsetof(struct ti_pcl, MEMBER))
369 #ifdef CONFIG_IEEE1394_PCILYNX_LOCALRAM
371 inline static void put_pcl(const struct ti_lynx *lynx, pcl_t pclid,
372 const struct ti_pcl *pcl)
375 u32 *in = (u32 *)pcl;
376 u32 *out = (u32 *)(lynx->local_ram + pclid * sizeof(struct ti_pcl));
378 for (i = 0; i < 32; i++, out++, in++) {
379 writel(cpu_to_le32(*in), out);
383 inline static void get_pcl(const struct ti_lynx *lynx, pcl_t pclid,
387 u32 *out = (u32 *)pcl;
388 u32 *in = (u32 *)(lynx->local_ram + pclid * sizeof(struct ti_pcl));
390 for (i = 0; i < 32; i++, out++, in++) {
391 *out = le32_to_cpu(readl(in));
395 inline static u32 pcl_bus(const struct ti_lynx *lynx, pcl_t pclid)
397 return pci_resource_start(lynx->dev, 1) + pclid * sizeof(struct ti_pcl);
400 #else /* CONFIG_IEEE1394_PCILYNX_LOCALRAM */
402 inline static void put_pcl(const struct ti_lynx *lynx, pcl_t pclid,
403 const struct ti_pcl *pcl)
405 memcpy_le32((u32 *)(lynx->pcl_mem + pclid * sizeof(struct ti_pcl)),
406 (u32 *)pcl, sizeof(struct ti_pcl));
409 inline static void get_pcl(const struct ti_lynx *lynx, pcl_t pclid,
412 memcpy_le32((u32 *)pcl,
413 (u32 *)(lynx->pcl_mem + pclid * sizeof(struct ti_pcl)),
414 sizeof(struct ti_pcl));
417 inline static u32 pcl_bus(const struct ti_lynx *lynx, pcl_t pclid)
419 return lynx->pcl_mem_dma + pclid * sizeof(struct ti_pcl);
422 #endif /* CONFIG_IEEE1394_PCILYNX_LOCALRAM */
425 #if defined (CONFIG_IEEE1394_PCILYNX_LOCALRAM) || defined (__BIG_ENDIAN)
426 typedef struct ti_pcl pcltmp_t;
428 inline static struct ti_pcl *edit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
431 get_pcl(lynx, pclid, tmp);
435 inline static void commit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
438 put_pcl(lynx, pclid, tmp);
442 typedef int pcltmp_t; /* just a dummy */
444 inline static struct ti_pcl *edit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
447 return lynx->pcl_mem + pclid * sizeof(struct ti_pcl);
450 inline static void commit_pcl(const struct ti_lynx *lynx, pcl_t pclid,
457 inline static void run_sub_pcl(const struct ti_lynx *lynx, pcl_t pclid, int idx,
460 reg_write(lynx, DMA0_CURRENT_PCL + dmachan * 0x20,
461 pcl_bus(lynx, pclid) + idx * 4);
462 reg_write(lynx, DMA0_CHAN_CTRL + dmachan * 0x20,
463 DMA_CHAN_CTRL_ENABLE | DMA_CHAN_CTRL_LINK);
466 inline static void run_pcl(const struct ti_lynx *lynx, pcl_t pclid, int dmachan)
468 run_sub_pcl(lynx, pclid, 0, dmachan);
471 #define PCL_NEXT_INVALID (1<<0)
473 /* transfer commands */
474 #define PCL_CMD_RCV (0x1<<24)
475 #define PCL_CMD_RCV_AND_UPDATE (0xa<<24)
476 #define PCL_CMD_XMT (0x2<<24)
477 #define PCL_CMD_UNFXMT (0xc<<24)
478 #define PCL_CMD_PCI_TO_LBUS (0x8<<24)
479 #define PCL_CMD_LBUS_TO_PCI (0x9<<24)
482 #define PCL_CMD_NOP (0x0<<24)
483 #define PCL_CMD_LOAD (0x3<<24)
484 #define PCL_CMD_STOREQ (0x4<<24)
485 #define PCL_CMD_STORED (0xb<<24)
486 #define PCL_CMD_STORE0 (0x5<<24)
487 #define PCL_CMD_STORE1 (0x6<<24)
488 #define PCL_CMD_COMPARE (0xe<<24)
489 #define PCL_CMD_SWAP_COMPARE (0xf<<24)
490 #define PCL_CMD_ADD (0xd<<24)
491 #define PCL_CMD_BRANCH (0x7<<24)
493 /* BRANCH condition codes */
494 #define PCL_COND_DMARDY_SET (0x1<<20)
495 #define PCL_COND_DMARDY_CLEAR (0x2<<20)
497 #define PCL_GEN_INTR (1<<19)
498 #define PCL_LAST_BUFF (1<<18)
499 #define PCL_LAST_CMD (PCL_LAST_BUFF)
500 #define PCL_WAITSTAT (1<<17)
501 #define PCL_BIGENDIAN (1<<16)
502 #define PCL_ISOMODE (1<<12)
505 #define _(x) (__constant_cpu_to_be32(x))
507 static quadlet_t lynx_csr_rom[] = {
508 /* bus info block offset (hex) */
509 _(0x04040000), /* info/CRC length, CRC 400 */
510 _(0x31333934), /* 1394 magic number 404 */
511 _(0xf064a000), /* misc. settings 408 */
512 _(0x08002850), /* vendor ID, chip ID high 40c */
513 _(0x0000ffff), /* chip ID low 410 */
515 _(0x00090000), /* directory length, CRC 414 */
516 _(0x03080028), /* vendor ID (Texas Instr.) 418 */
517 _(0x81000008), /* offset to textual ID 41c */
518 _(0x0c000200), /* node capabilities 420 */
519 _(0x8d00000e), /* offset to unique ID 424 */
520 _(0xc7000010), /* offset to module independent info 428 */
521 _(0x04000000), /* module hardware version 42c */
522 _(0x81000014), /* offset to textual ID 430 */
523 _(0x09000000), /* node hardware version 434 */
524 _(0x81000018), /* offset to textual ID 438 */
525 /* module vendor ID textual */
526 _(0x00070000), /* CRC length, CRC 43c */
527 _(0x00000000), /* 440 */
528 _(0x00000000), /* 444 */
529 _(0x54455841), /* "Texas Instruments" 448 */
530 _(0x5320494e), /* 44c */
531 _(0x53545255), /* 450 */
532 _(0x4d454e54), /* 454 */
533 _(0x53000000), /* 458 */
534 /* node unique ID leaf */
535 _(0x00020000), /* CRC length, CRC 45c */
536 _(0x08002850), /* vendor ID, chip ID high 460 */
537 _(0x0000ffff), /* chip ID low 464 */
538 /* module dependent info */
539 _(0x00050000), /* CRC length, CRC 468 */
540 _(0x81000012), /* offset to module textual ID 46c */
541 _(0x81000017), /* textual descriptor 470 */
542 _(0x39010000), /* SRAM size 474 */
543 _(0x3a010000), /* AUXRAM size 478 */
544 _(0x3b000000), /* AUX device 47c */
545 /* module textual ID */
546 _(0x00050000), /* CRC length, CRC 480 */
547 _(0x00000000), /* 484 */
548 _(0x00000000), /* 488 */
549 _(0x54534231), /* "TSB12LV21" 48c */
550 _(0x324c5632), /* 490 */
551 _(0x31000000), /* 494 */
553 _(0x00060000), /* CRC length, CRC 498 */
554 _(0x00000000), /* 49c */
555 _(0x00000000), /* 4a0 */
556 _(0x39383036), /* "9806000-0001" 4a4 */
557 _(0x3030302d), /* 4a8 */
558 _(0x30303031), /* 4ac */
559 _(0x20000001), /* 4b0 */
560 /* module hardware version textual */
561 _(0x00050000), /* CRC length, CRC 4b4 */
562 _(0x00000000), /* 4b8 */
563 _(0x00000000), /* 4bc */
564 _(0x5453424b), /* "TSBKPCITST" 4c0 */
565 _(0x50434954), /* 4c4 */
566 _(0x53540000), /* 4c8 */
567 /* node hardware version textual */
568 _(0x00050000), /* CRC length, CRC 4d0 */
569 _(0x00000000), /* 4d4 */
570 _(0x00000000), /* 4d8 */
571 _(0x54534232), /* "TSB21LV03" 4dc */
572 _(0x314c5630), /* 4e0 */
573 _(0x33000000) /* 4e4 */