20 #include <linux/types.h>
24 #include <sys/ioctl.h>
25 #include <linux/pci.h>
44 #define RORC_MAX_REVISION 4
57 #define DRORC_REG_NUM 32
105 #define I2C_DATA 0x000000FF // bits 7 ... 0
106 #define I2C_ADDRESS 0x0000FF00 // bits 15 ... 8
107 #define I2C_WRITE 0x00010000 // bit 16
108 #define I2C_DATA_VALID 0x10000000 // bit 28
109 #define I2C_READ_OPERATION_ACTIVE 0x20000000 // bit 29
110 #define I2C_WRITE_OPERATION_VALIDE 0x40000000 // bit 30
111 #define I2C_OPERATION_ACTIVE 0x80000000 // bit 31
120 #define DRORC_CMD_RESET_RORC 0x00000001 //bit 0
121 #define DRORC_CMD_RESET_CHAN 0x00000002 //bit 1
122 #define DRORC_CMD_CLEAR_RORC_ERROR 0x00000008 //bit 3
126 #define DRORC_CMD_RESET_DIU 0x00000001 //bit 0
127 #define DRORC_CMD_CLEAR_FIFOS 0x00000002 //bit 1
128 #define DRORC_CMD_CLEAR_RXFF 0x00000004 //bit 2
129 #define DRORC_CMD_CLEAR_TXFF 0x00000008 //bit 3
130 #define DRORC_CMD_CLEAR_ERROR 0x00000010 //bit 4
131 #define DRORC_CMD_CLEAR_COUNTERS 0x00000020 //bit 5
133 #define DRORC_CMD_JTAG_DOWN_ON 0x00000040 //bit 6
134 #define DRORC_CMD_JTAG_DOWN_OFF 0x00000080 //bit 7
135 #define DRORC_CMD_DATA_TX_ON_OFF 0x00000100 //bit 8
136 #define DRORC_CMD_DATA_RX_ON_OFF 0x00000200 //bit 9
137 #define DRORC_CMD_START_DG 0x00000400 //bit 10
138 #define DRORC_CMD_STOP_DG 0x00000800 //bit 11
139 #define DRORC_CMD_LOOPB_ON_OFF 0x00001000 //bit 12
140 #define DRORC_CMD_HLT_FLC_ON_OFF 0x20000000 //bit 29
141 #define DRORC_CMD_HLT_SPL_ON_OFF 0x40000000 //bit 30
147 #define DRORC_STAT_LINK_DOWN 0x00002000 //bit 13
148 #define DRORC_STAT_LINK_FULL 0x00004000 //bit 14
149 #define DRORC_STAT_CMD_NOT_EMPTY 0x00010000 //bit 16
151 #define DRORC_STAT_RXRBAR_NOT_SET 0x00020000 //bit 17
152 #define DRORC_STAT_RXAFF_EMPTY 0x00040000 //bit 18
153 #define DRORC_STAT_RXAFF_FULL 0x00080000 //bit 19
155 #define DRORC_STAT_TXRBAR_NOT_SET 0x00100000 //bit 20
156 #define DRORC_STAT_TXAFF_EMPTY 0x00200000 //bit 21
157 #define DRORC_STAT_TXAFF_FULL 0x00400000 //bit 22
159 #define DRORC_STAT_RXSTAT_NOT_EMPTY 0x00800000 //bit 23
160 #define DRORC_STAT_RXDAT_ALMOST_FULL 0x01000000 //bit 24
161 #define DRORC_STAT_RXDAT_NOT_EMPTY 0x02000000 //bit 25
163 #define DRORC_STAT_TXDAT_NOT_EMPTY 0x04000000 //bit 26
164 #define DRORC_STAT_TXDAT_ALMOST_FULL 0x08000000 //bit 27
166 #define DRORC_STAT_ERR_NOT_EMPTY 0x80000000 //bit 31
168 #define DRORC_STAT_ANY 0xffffffc0 //bits 31-6
174 #define DRORC_STAT_TEXT "0,0,0,0,0,0,\
175 JTAG download enabled,\
177 Data transfer (RDMA) enabled,\
178 Data receiver (WDMA) enabled,\
179 Data Generator started,0,\
180 Internal loop-back set,\
184 DDL command register not empty,\
185 Receive report base address not set,\
186 Receive address FIFO empty,\
187 Receive address FIFO full,\
188 Transmit report base address not set,\
189 Transmit address FIFO empty,\
190 Transmit address FIFO full,\
191 Receiver status FIFO not empty,\
192 Receive data FIFO almost full,\
193 Receive data FIFO not empty,\
194 Transmit data FIFO not empty,\
195 Transmit data FIFO almost full,\
197 HLT flow-control enabled,\
198 HLT splitter enabled,\
199 Error register is not empty"
201 #define DRORC_STAT_DEFAULT_TEXT "Reserved bit set"
209 #define PRORC_CMD_RESET_RORC 0x0110
210 #define PRORC_CMD_RESET_DIU 0x0210
211 #define PRORC_CMD_RESET_RORC_DIU 0x0310
212 #define PRORC_CMD_RESET_SIU 0x00F1
213 #define PRORC_CMD_CLEAR_FIFOS 0x0410
214 #define PRORC_CMD_CLEAR_FF 0x0810
215 #define PRORC_CMD_CLEAR_ERROR 0x1010
216 #define PRORC_CMD_CLEAR_COUNTERS 0x2010
217 #define PRORC_CMD_GET_STAT 0x020
218 #define PRORC_CMD_GET_ID 0x030
219 #define PRORC_CMD_PUSH_FF 0x040
220 #define PRORC_CMD_POP_FF 0x050
221 #define PRORC_CMD_PUT_READY_BASE 0x060
222 #define PRORC_CMD_DG_PARAM1 0x070
223 #define PRORC_CMD_DG_PARAM2 0x080
224 #define PRORC_CMD_DOWNL_DATA 0x090
225 #define PRORC_CMD_DOWNL_JTAG 0x190
226 #define PRORC_CMD_PARAM_RESET 0x0a0
227 #define PRORC_CMD_LOOPB_ON 0x1a0
228 #define PRORC_CMD_STOP_ERR_ON 0x2a0
229 #define PRORC_CMD_START_W_DMA 0x1b0
230 #define PRORC_CMD_STOP_W_DMA 0x0b0
231 #define PRORC_CMD_START_DG 0x3b0
232 #define PRORC_CMD_STOP_DG 0x2b0
233 #define PRORC_CMD_GET_IN_BYTES 0x0c0
234 #define PRORC_CMD_GET_OUT_BYTES 0x1c0
236 #define PRORC_PARAM_LOOPB 0x1
237 #define PRORC_PARAM_STOP_ERR 0x2
243 #define PRORC_NE_OMB1 0x0000000f
244 #define PRORC_NE_OMB2 0x000000f0
245 #define PRORC_NE_OMB3 0x00000f00
246 #define PRORC_NE_OMB4 0x0000f000
247 #define PRORC_NE_OUTMB 0x0000ffff
248 #define PRORC_NE_IMB1 0x000f0000
249 #define PRORC_NE_IMB2 0x00f00000
250 #define PRORC_NE_IMB3 0x0f000000
251 #define PRORC_NE_IMB4 0x70000000
252 #define PRORC_NE_INMB 0x7fff0000
258 #define PRORC_BIT_LINK_DOWN 0x80000000
259 #define PRORC_BIT_FF_EMPTY 0x40000000
260 #define PRORC_BIT_CMD_RDY1 0x04000000
261 #define PRORC_BIT_CMD_RDY2 0x02000000
262 #define PRORC_BIT_CMD_PROC 0x01000000
268 #define PRORC_STAT_LINK_DOWN 0x40000000 //bit 30
269 #define PRORC_STAT_LINK_FULL 0x20000000 //bit 29
270 #define PRORC_STAT_FIFO_NOT_EMPTY 0x10000000 //bit 28
271 #define PRORC_STAT_DC_NOT_EMPTY 0x08000000 //bit 27
272 #define PRORC_STAT_JTAG_NOT_EMPTY 0x04000000 //bit 26
273 #define PRORC_STAT_FED_NOT_EMPTY 0x02000000 //bit 25
274 #define PRORC_STAT_DIU_CMD_NOT_EMPTY 0x01000000 //bit 24
275 #define PRORC_STAT_DTSTW_NOT_EMPTY 0x00800000 //bit 23
276 #define PRORC_STAT_RFBAR_NOT_SET 0x00400000 //bit 22
277 #define PRORC_STAT_START_DATA_GEN 0x00200000 //bit 21
278 #define PRORC_STAT_LOOP_BACK 0x00100000 //bit 20
279 #define PRORC_STAT_STOP_ON_ERROR 0x00080000 //bit 19
280 #define PRORC_STAT_JTAG_DLOAD_ENABLE 0x00040000 //bit 18
281 #define PRORC_STAT_WAIT_DTSTW 0x00020000 //bit 17
282 #define PRORC_STAT_RDMA_RUNNING 0x00010000 //bit 16
283 #define PRORC_STAT_RDMA_SUSP_PCI 0x00008000 //bit 15
284 #define PRORC_STAT_RDMA_SUSP_LINK 0x00004000 //bit 14
285 #define PRORC_STAT_JTAG_REC_ENABLE 0x00002000 //bit 13
286 #define PRORC_STAT_WDMA_RUNNING 0x00001000 //bit 12
287 #define PRORC_STAT_WDMA_SUSP_PCI 0x00000800 //bit 11
288 #define PRORC_STAT_WDMA_SUSP_LINK 0x00000400 //bit 10
289 #define PRORC_STAT_FF_EMPTY 0x00000020 //bit 5
290 #define PRORC_STAT_FF_FULL 0x00000010 //bit 4
291 #define PRORC_STAT_FF_USEDW 0x0000000f //bits 3-0
292 #define PRORC_STAT_ANY 0x7ffffff0 //bits 30-4
298 #define PRORC_STAT_TEXT "0,0,0,0,\
302 W_DMA suspended because of the link (DC_EMPTY),\
303 W_DMA suspended because of the PCI (WRFULL),\
305 JTAG receive enabled,\
306 R_DMA_SUSPENDED because of the link (FEDF_FULL),\
307 R_DMA suspended because of the PCI (RDEMPTY),\
309 Waiting for DTSTW adfter R_DMA,\
310 JTAG download enabled,\
311 Stop on error is on,\
312 Internal loop-back set,\
313 Data Generator started,\
314 Ready FIFO base address not set,\
315 DTSTW register not empty,\
316 DIU command register not empty,\
318 JTAG FIFO not empty,\
320 Status FIFO not empty,\
325 #define PRORC_STAT_DEFAULT_TEXT "Reserved bit set"
331 #define PRORC_ERROR 0x80000000
332 #define PRORC_ERR_INV_COMM 0x40000000
333 #define PRORC_ERR_MISS_PARM 0x20000000
334 #define PRORC_ERR_FF_OVWR 0x04000000
335 #define PRORC_ERR_DTSTW_OVWR 0x02000000
336 #define PRORC_ERR_DIU_OVWR 0x01000000
337 #define PRORC_ERR_LINK_DOWN 0x00800000
338 #define PRORC_ERR_STAT_FF_FULL 0x00000008
339 #define PRORC_ERR_FED_FULL 0x00000004
340 #define PRORC_ERR_DC_FULL 0x00000002
341 #define PRORC_ERR_JTAG_FULL 0x00000001
344 #define MAX_WAIT 1000000
350 #define PRORC_DMA_WAIT 16
358 #define MAX_RETURN_CODE 15
359 #define MAX_RETURN_TEXT 32
361 #define RORC_STATUS_OK 0
362 #define RORC_STATUS_ERROR -1
363 #define RORC_INVALID_PARAM -2
365 #define RORC_LINK_NOT_ON -4
366 #define RORC_CMD_NOT_ALLOWED -8
367 #define RORC_NOT_ACCEPTED -16
368 #define RORC_NOT_ABLE -32
369 #define RORC_TIMEOUT -64
371 #define RORC_FF_FULL -128
372 #define RORC_FF_EMPTY -256
374 #define RORC_NOT_ENOUGH_REPLY -512
375 #define RORC_TOO_MANY_REPLY -1024
377 #define RORC_DATA_BLOCK_NOT_ARRIVED 0
378 #define RORC_NOT_END_OF_EVENT_ARRIVED 1
379 #define RORC_LAST_BLOCK_OF_EVENT_ARRIVED 2
385 #define RORC_RESET_FF 1
386 #define RORC_RESET_RORC 2
387 #define RORC_RESET_DIU 4
388 #define RORC_RESET_SIU 8
389 #define RORC_LINK_UP 16
390 #define RORC_RESET_FEE 32
391 #define RORC_RESET_FIFOS 64
392 #define RORC_RESET_ERROR 128
393 #define RORC_RESET_COUNTERS 256
395 #define RORC_RESET_ALL 0x000001FF //bits 8-0
401 #define RORC_DG_CONST 1
402 #define RORC_DG_ALTER 2
403 #define RORC_DG_FLY0 3
404 #define RORC_DG_FLY1 4
405 #define RORC_DG_INCR 5
406 #define RORC_DG_DECR 6
407 #define RORC_DG_RANDOM 7
409 #define RORC_DG_NO_RANDOM_LEN 0
410 #define RORC_DG_INFINIT_EVENT 0
416 #define TWO_TO_THE_18 262144.0
417 #define TWO_TO_THE_20 1048576.0
418 #define TWO_TO_THE_32 4294967296.0
419 #define RORC_CLOCK_18 0.009868950588
425 #define dRorcWriteReg(dev, reg_number, reg_value) \
426 *(*(dev)).reg[reg_number] = reg_value
428 #define dRorcReadReg(dev, reg_number) (*(*(dev)).reg[reg_number])
430 #define dRorcPushRxFreeFifo(dev, blockAddress, blockLength, readyFifoIndex) \
431 dRorcWriteReg (dev, C_RAFH, blockAddress); \
432 dRorcWriteReg (dev, C_RAFL, ((blockLength) << 8) | (readyFifoIndex))
434 #define dRorcPushTxFreeFifo(dev, blockAddress, blockLength, readyFifoIndex) \
435 dRorcWriteReg (dev, C_TAFH, blockAddress); \
436 dRorcWriteReg (dev, C_TAFL, ((blockLength) << 8) | (readyFifoIndex))
438 #define dRorcCheckLoopBack(dev) (dRorcReadReg(dev, C_CSR) & \
439 DRORC_CMD_LOOPB_ON_OFF)
440 #define dRorcChangeLoopBack(dev) dRorcWriteReg(dev, C_CSR, \
441 DRORC_CMD_LOOPB_ON_OFF)
442 #define dRorcCheckHltFlctl(dev) (dRorcReadReg(dev, C_CSR) & \
443 DRORC_CMD_HLT_FLC_ON_OFF)
444 #define dRorcChangeHltFlctl(dev) dRorcWriteReg(dev, C_CSR, \
445 DRORC_CMD_HLT_FLC_ON_OFF)
446 #define dRorcCheckHltSplit(dev) (dRorcReadReg(dev, C_CSR) & \
447 DRORC_CMD_HLT_SPL_ON_OFF)
448 #define dRorcChangeHltSplit(dev) dRorcWriteReg(dev, C_CSR, \
449 DRORC_CMD_HLT_SPL_ON_OFF)
450 #define dRorcCheckRxStatus(dev) (dRorcReadReg(dev, C_CSR) & \
451 DRORC_STAT_RXSTAT_NOT_EMPTY)
452 #define dRorcCheckTxStatus(dev) (dRorcReadReg(dev, C_CSR) & \
453 DRORC_STAT_TXSTAT_NOT_EMPTY)
454 #define dRorcCheckRxData(dev) (dRorcReadReg(dev, C_CSR) & \
455 DRORC_STAT_RXDAT_NOT_EMPTY)
456 #define dRorcCheckTxData(dev) (dRorcReadReg(dev, C_CSR) & \
457 DRORC_STAT_TXDAT_NOT_EMPTY)
458 #define dRorcReadRxDmaCount(dev) (dRorcReadReg(dev, C_RXDC) & 0xFFFFFF)
459 #define dRorcReadTxDmaCount(dev) (dRorcReadReg(dev, C_TXDC) & 0xFFFFFF)
461 #define I2C_ACTIVE(dev) (dRorcReadReg(dev, RHID) & I2C_OPERATION_ACTIVE)
465 #define pRorcWriteMb(dev, mb_number, mb_value) \
466 *(*(dev)).omb[mb_number] = mb_value
468 #define pRorcReadMb(dev, mb_number) (*(*(dev)).imb[mb_number])
470 #define pRorcReadRxDmaCount(dev) (*(*(dev)).mwtc)
471 #define pRorcReadTxDmaCount(dev) (*(*(dev)).mrtc)
473 #define pRorcPushOldFreeFifo(dev, blockAddress, blockLength, readyFifoIndex) \
474 while ((*(*(dev)).mbef & 0xffff) != 0); \
475 *(*(dev)).omb[3] = (blockLength); \
476 *(*(dev)).omb[2] = (blockAddress); \
477 *(*(dev)).omb[1] = ((readyFifoIndex) << 8) | PRORC_CMD_PUSH_FF
479 #define pRorcInitCmdProc(dev) (prorc_cmd_rdy = (pRorcReadMb(dev, 4) & PRORC_BIT_CMD_RDY1))
482 #define pRorcCheckMb(dev, mb_mask) (*(*(dev)).mbef & mb_mask)
484 #define NVRAM_BUSY_MEM(ptr_to_pci_mem) (*(ptr_to_pci_mem + 0x3F) & 0x80)
488 #define pRorc(dev) ((*(dev)).rorc_revision == PRORC)
490 #define rorcCheckLink(dev) \
492 ((pRorcReadMb(dev, 4) & PRORC_BIT_LINK_DOWN) ? RORC_LINK_NOT_ON \
495 ((dRorcReadReg(dev, C_CSR) & DRORC_STAT_LINK_DOWN) ? RORC_LINK_NOT_ON \
498 #define rorcCheckStatus(dev) \
500 pRorcCheckMb(dev, PRORC_NE_IMB1) : dRorcCheckRxStatus(dev))
502 #define rorcCheckCommandRegister(dev) \
504 pRorcCheckMb(dev, PRORC_NE_OMB1) \
506 dRorcReadReg(dev, C_CSR) & DRORC_STAT_CMD_NOT_EMPTY)
508 #define rorcPutCommandRegister(dev, com) \
510 (pRorcInitCmdProc(dev), pRorcWriteMb(dev, 1, com), pRorcWaitCmdProc(dev)) \
512 (dRorcWriteReg((dev), C_DCR, (com))))
514 #define rorcLoopBackOn(dev) rorcParamOn(dev, PRORC_PARAM_LOOPB)
516 #define rorcLoopBackOff(dev) rorcParamOff(dev);
518 #define rorcPushFreeFifo(dev, blockAddress, blockLength, readyFifoIndex) \
521 while ((*(*(dev)).mbef & 0xffff) != 0); \
522 *(*(dev)).omb[3] = (blockLength); \
523 *(*(dev)).omb[2] = (blockAddress); \
524 *(*(dev)).omb[1] = ((readyFifoIndex) << 8) | PRORC_CMD_PUSH_FF; \
528 dRorcPushRxFreeFifo(dev, blockAddress, blockLength, readyFifoIndex); \
531 #define rorcHasData(rf, index) \
532 (((rf)[index].status == -1) ? RORC_DATA_BLOCK_NOT_ARRIVED : \
533 (((rf)[index].status == 0) ? RORC_NOT_END_OF_EVENT_ARRIVED : \
534 RORC_LAST_BLOCK_OF_EVENT_ARRIVED))
536 #define rorcFFSize(fw) ((fw & 0xff000000) >> 18)
537 #define rorcFWVersMajor(fw) ((fw >> 20) & 0xf)
538 #define rorcFWVersMinor(fw) ((fw >> 13) & 0x7f)
548 volatile unsigned *p2pci;
550 unsigned short vendor;
551 unsigned short device;
553 unsigned base_address[6];
554 unsigned rom_address;
555 unsigned bus_speed_mode;
564 volatile unsigned *reg[DRORC_REG_NUM];
565 volatile unsigned *omb[5];
566 volatile unsigned *imb[5];
567 volatile unsigned *mwar;
568 volatile unsigned *mwtc;
569 volatile unsigned *mrar;
570 volatile unsigned *mrtc;
571 volatile unsigned *mbef;
572 volatile unsigned *intcsr;
573 volatile unsigned *mcsr;
574 long long int loop_per_usec;
575 long long int max_resp_time;
590 volatile unsigned int length;
591 volatile unsigned int status;
615 __u8
data[DDL_MAX_HW_ID];
633 char text[MAX_RETURN_TEXT];
640 extern volatile __u32 prorc_cmd_rdy;
641 extern volatile int interrupt_arrived;
648 void sprom_load_address_mem(
volatile char *ptr_to_pci_mem, __u8 address);
649 __u8 sprom_readB_mem(
volatile char *ptr_to_pci_mem, __u8 address);
650 int i2c_write_a_byte(
rorcHandle_t dev, __u8 address, __u8
data,
int timeout);
651 int i2c_read_a_byte(
rorcHandle_t dev, __u8 address, __u8 *
data,
int timeout);
653 void rorcBuildHwSerial(__u8
data[],
int rorc_rev,
int version_major,
654 int version_minor, __u8 c_pld[],
int numb_chan,
656 int rorcCheckOpen(
int minor,
unsigned int channel);
657 int rorcFind(
int revision,
int serial,
int *minor);
660 int *diu_version,
int max_dev);
661 int rorcQuickFind(
int *rorc_minor,
int *rorc_revision,
int *pci_speed,
662 int *rorc_serial,
int *rorc_fw_maj,
int *rorc_fw_min,
663 int *max_chan,
int *ch_pid0,
int *ch_pid1,
int max_dev);
669 int physmemOpen (
int *fd,
670 volatile unsigned long **user_addr,
671 unsigned long *phys_addr,
672 unsigned long *size_physmem);
673 int physmemCheck (
char *devnam,
674 unsigned long *phys_addr,
675 unsigned long *size_physmem);
676 int physmemClose (
int physmem_fd,
677 unsigned long *addr_user_physmem,
678 unsigned long phys_size_physmem);
691 int *readyFifoIndex);
694 int pRorcEmptyMb(
rorc_pci_dev_t *prorc,
int mb_number,
short print);
699 int cmajor,
int cminor,
int crelease);
700 char* rorcInterpretBusMode(
int bus_speed_mode);
701 char* rorcInterpretBusSpeed(
int bus_speed_mode);
702 char *rorcInterpretReturnCode(
int return_code);
703 void rorcInterpretStatus(
rorcHandle_t dev, __u32 status,
char* pref,
char* suff);
704 void rorcInterpretErrors(__u32 errors,
char* pref,
char* suff);
706 void rorcInterpretVersion(__u32 x);
708 void rorcInterpretFw(__u32 fw);
719 __u32 initEventNumber,
729 unsigned long readyFifoBaseAdress);
732 unsigned long bufferPhysAddress,
733 unsigned long bufferWordLength,
734 unsigned long returnPhysAddress);
737 unsigned long bufferPhysAddress,
738 unsigned long bufferWordLength,
739 unsigned long returnPhysAddress);