StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rorc_lib.h
1 #ifndef _RORC_LIB_H_
2 #define _RORC_LIB_H_
3 
4 /*
5  ***************************************************
6  * rorc_lib.h
7  *
8  * Header file for library routines for ALICE RORC programs
9  *
10  * last updated: 24/04/2007
11  * written by: Peter Csato and Ervin Denes
12  ***************************************************
13  */
14 
15 #include <unistd.h>
16 #include <errno.h>
17 #include <stdio.h>
18 #include <fcntl.h>
19 #include <stdlib.h>
20 #include <linux/types.h>
21 //#include <sys/io.h>
22 #include <sys/mman.h>
23 //#include <asm/page.h>
24 #include <sys/ioctl.h>
25 #include <linux/pci.h>
26 
27 
28 
29 
30 
31 //#include "rorc.h"
32 //#include "rorc_aux.h"
33 //#include "rorc_date.h"
34 #include "ddl_def.h"
35 
36 
37 
38 
39 /*
40  * Defines ----------------------- D-RORC ----------------------------
41  */
42 
43 /* RORC's PCI revisions */
44 #define RORC_MAX_REVISION 4 /* revision 1: pRORC, 2: D-RORC with pluggable DIU
45  3: integrated D-RORC and DIU
46  4: second generation D-RORC
47  */
48 #define PRORC 1
49 #define DRORC 2
50 #define INTEG 3
51 #define DRORC2 4
52 
53 /*
54  * D-RORC REGISTERS
55  */
56 
57 #define DRORC_REG_NUM 32
58 
59 #define RCSR 0 /* RORC Control and Status register */
60 #define RERR 1 /* RORC Error register */
61 #define RFID 2 /* Firmware ID */
62 #define RHID 3 /* Hardware ID */
63 #define C_CSR 4 /* channel Control and Status register */
64 #define C_ERR 5 /* channel Error register */
65 #define C_DCR 6 /* channel DDL Command register */
66 #define C_DSR 7 /* channel DDL Status register */
67 #define C_DG1 8 /* channel Data Generator param 1 */
68 #define C_DG2 9 /* channel Data Generator param 2 */
69 #define C_DG3 10 /* channel Data Generator param 3 */
70 #define C_DG4 11 /* channel Data Generator param 4 */
71 #define C_DGS 12 /* channel Data Generator Status */
72 #define C_RRBAR 13 /* channel Receive Report Base Address */
73 #define C_RAFL 14 /* channel Receive Address FIFO Low */
74 #define C_RAFH 15 /* channel Receive Address FIFO High */
75 #define C_TRBAR 16 /* channel Transmit Report Base Address */
76 #define C_TAFL 17 /* channel Transmit Address FIFO Low */
77 #define C_TAFH 18 /* channel Transmit Address FIFO High */
78 #define RESERVED 19
79 #define C_RDR1 20 /* channel Receive Data Rate register 1 */
80 #define C_RDR2 21 /* channel Receive Data Rate register 2 */
81 #define C_RDR3 22 /* channel Receive Data Rate register 3 */
82 #define C_RDR4 23 /* channel Receive Data Rate register 4 */
83 #define C_TDR1 24 /* channel Transmit Data Rate register 1 */
84 #define C_TDR2 25 /* channel Transmit Data Rate register 2 */
85 #define C_TDR3 26 /* channel Transmit Data Rate register 3 */
86 #define C_TDR4 27 /* channel Transmit Data Rate register 4 */
87 #define C_RXDC 28 /* channel Receive DMA count register */
88 #define C_TXDC 29 /* channel Transmit DMA count register */
89 #define C_RXDA 30 /* channel Receive DMA address register */
90 #define C_TXDA 31 /* channel Transmit DMA address register */
91 
92 /* high addresses for 64 bit */
93 #define C_RAFX 32 /* Receive Address FIFO Extension register */
94 #define C_RRBX 33 /* Rx Report Base Address Extension register */
95 #define C_TAFX 34 /* Transmit Address FIFO Extension register */
96 #define C_TRBX 35 /* Tx Report Base Address Extension register */
97 #define C_RDAH 36 /* channel Receive DMA address register High*/
98 #define C_TDAH 37 /* channel Transmit DMA address register High*/
99 
100 
101 /*
102  * I2C bits (D-RORC HID register)
103  */
104 
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
112 
113 
114 /*
115  * D-RORC commands
116  */
117 
118 /* RCSR controls */
119 
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
123 
124 /* CCSR commands */
125 
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
132 
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
142 
143 /*
144  * CCSR status bits
145  */
146 
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
150 
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
154 
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
158 
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
162 
163 #define DRORC_STAT_TXDAT_NOT_EMPTY 0x04000000 //bit 26
164 #define DRORC_STAT_TXDAT_ALMOST_FULL 0x08000000 //bit 27
165 
166 #define DRORC_STAT_ERR_NOT_EMPTY 0x80000000 //bit 31
167 
168 #define DRORC_STAT_ANY 0xffffffc0 //bits 31-6
169 
170 /*
171  * CCSR status text
172  */
173 
174 #define DRORC_STAT_TEXT "0,0,0,0,0,0,\
175 JTAG download enabled,\
176 0,\
177 Data transfer (RDMA) enabled,\
178 Data receiver (WDMA) enabled,\
179 Data Generator started,0,\
180 Internal loop-back set,\
181 Link is down,\
182 Link is full,\
183 0,\
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,\
196 0,\
197 HLT flow-control enabled,\
198 HLT splitter enabled,\
199 Error register is not empty"
200 
201 #define DRORC_STAT_DEFAULT_TEXT "Reserved bit set"
202 
203 /*------------------- pRORC ----------------------------------*/
204 
205 /*
206  * pRORC commands
207  */
208 
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
235 
236 #define PRORC_PARAM_LOOPB 0x1
237 #define PRORC_PARAM_STOP_ERR 0x2
238 
239 /*
240  * Mailbox not empty bits
241  */
242 
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
253 
254 /*
255  * Control bits of IMB4 high byte
256  */
257 
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
263 
264 /*
265  * OCSR bits
266  */
267 
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
293 
294 /*
295  * OCSR status text
296  */
297 
298 #define PRORC_STAT_TEXT "0,0,0,0,\
299 Free FIFO full,\
300 Free FIFO empty,\
301 0,0,0,0,\
302 W_DMA suspended because of the link (DC_EMPTY),\
303 W_DMA suspended because of the PCI (WRFULL),\
304 W_DMA running,\
305 JTAG receive enabled,\
306 R_DMA_SUSPENDED because of the link (FEDF_FULL),\
307 R_DMA suspended because of the PCI (RDEMPTY),\
308 R_DMA running,\
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,\
317 FED FIFO not empty,\
318 JTAG FIFO not empty,\
319 DC FIFO not empty,\
320 Status FIFO not empty,\
321 Link is full,\
322 Link is down,\
323 0"
324 
325 #define PRORC_STAT_DEFAULT_TEXT "Reserved bit set"
326 
327 /*
328  * RSER bits
329  */
330 
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
342 
343 /* nvram constants */
344 #define MAX_WAIT 1000000
345 
346 /*
347  * DMA WAIT
348  */
349 
350 #define PRORC_DMA_WAIT 16
351 
352 /*-----------------------------------------------*/
353 
354 /*
355  * Return values
356  */
357 
358 #define MAX_RETURN_CODE 15
359 #define MAX_RETURN_TEXT 32
360 
361 #define RORC_STATUS_OK 0
362 #define RORC_STATUS_ERROR -1
363 #define RORC_INVALID_PARAM -2
364 
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
370 
371 #define RORC_FF_FULL -128
372 #define RORC_FF_EMPTY -256
373 
374 #define RORC_NOT_ENOUGH_REPLY -512
375 #define RORC_TOO_MANY_REPLY -1024
376 
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
380 
381 /*
382  * pRORC initialization and reset options
383  */
384 
385 #define RORC_RESET_FF 1 /* reset Free FIFOs */
386 #define RORC_RESET_RORC 2 /* reset RORC */
387 #define RORC_RESET_DIU 4 /* reset DIU */
388 #define RORC_RESET_SIU 8 /* reset SIU */
389 #define RORC_LINK_UP 16 /* init link */
390 #define RORC_RESET_FEE 32 /* reset Front-End */
391 #define RORC_RESET_FIFOS 64 /* reset RORC's FIFOS (not Free FIFO) */
392 #define RORC_RESET_ERROR 128 /* reset RORC's error register */
393 #define RORC_RESET_COUNTERS 256 /* reset RORC's event number counters */
394 
395 #define RORC_RESET_ALL 0x000001FF //bits 8-0
396 
397 /*
398  * Data Generator patterns
399  */
400 
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
408 
409 #define RORC_DG_NO_RANDOM_LEN 0
410 #define RORC_DG_INFINIT_EVENT 0
411 
412 /*
413  * pRORC clock time (1/(26.5625 MHz) = 3.764705882e-8 sec) * 2^18
414  */
415 
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
420 
421 /*
422  * Macros ------------------- D-RORC --------------------------------------
423  */
424 
425 #define dRorcWriteReg(dev, reg_number, reg_value) \
426  *(*(dev)).reg[reg_number] = reg_value
427 
428 #define dRorcReadReg(dev, reg_number) (*(*(dev)).reg[reg_number])
429 
430 #define dRorcPushRxFreeFifo(dev, blockAddress, blockLength, readyFifoIndex) \
431  dRorcWriteReg (dev, C_RAFH, blockAddress); \
432  dRorcWriteReg (dev, C_RAFL, ((blockLength) << 8) | (readyFifoIndex))
433 
434 #define dRorcPushTxFreeFifo(dev, blockAddress, blockLength, readyFifoIndex) \
435  dRorcWriteReg (dev, C_TAFH, blockAddress); \
436  dRorcWriteReg (dev, C_TAFL, ((blockLength) << 8) | (readyFifoIndex))
437 
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)
460 
461 #define I2C_ACTIVE(dev) (dRorcReadReg(dev, RHID) & I2C_OPERATION_ACTIVE)
462 
463 /*------------------------- pRORC ---------------------------------------*/
464 
465 #define pRorcWriteMb(dev, mb_number, mb_value) \
466  *(*(dev)).omb[mb_number] = mb_value
467 
468 #define pRorcReadMb(dev, mb_number) (*(*(dev)).imb[mb_number])
469 
470 #define pRorcReadRxDmaCount(dev) (*(*(dev)).mwtc)
471 #define pRorcReadTxDmaCount(dev) (*(*(dev)).mrtc)
472 
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
478 
479 #define pRorcInitCmdProc(dev) (prorc_cmd_rdy = (pRorcReadMb(dev, 4) & PRORC_BIT_CMD_RDY1))
480 
481 /* #define pRorcCheckMb(dev, mb_mask) ((*(*(dev)).mbef & mb_mask) == mb_mask) */
482 #define pRorcCheckMb(dev, mb_mask) (*(*(dev)).mbef & mb_mask)
483 
484 #define NVRAM_BUSY_MEM(ptr_to_pci_mem) (*(ptr_to_pci_mem + 0x3F) & 0x80)
485 
486 /*-----------------------------------------------------------------------*/
487 
488 #define pRorc(dev) ((*(dev)).rorc_revision == PRORC)
489 
490 #define rorcCheckLink(dev) \
491  (pRorc(dev) ? \
492  ((pRorcReadMb(dev, 4) & PRORC_BIT_LINK_DOWN) ? RORC_LINK_NOT_ON \
493  : RORC_STATUS_OK) \
494  : \
495  ((dRorcReadReg(dev, C_CSR) & DRORC_STAT_LINK_DOWN) ? RORC_LINK_NOT_ON \
496  : RORC_STATUS_OK))
497 
498 #define rorcCheckStatus(dev) \
499  (pRorc(dev) ? \
500  pRorcCheckMb(dev, PRORC_NE_IMB1) : dRorcCheckRxStatus(dev))
501 
502 #define rorcCheckCommandRegister(dev) \
503  (pRorc(dev) ? \
504  pRorcCheckMb(dev, PRORC_NE_OMB1) \
505  : \
506  dRorcReadReg(dev, C_CSR) & DRORC_STAT_CMD_NOT_EMPTY)
507 
508 #define rorcPutCommandRegister(dev, com) \
509  (pRorc(dev) ? \
510  (pRorcInitCmdProc(dev), pRorcWriteMb(dev, 1, com), pRorcWaitCmdProc(dev)) \
511  : \
512  (dRorcWriteReg((dev), C_DCR, (com))))
513 
514 #define rorcLoopBackOn(dev) rorcParamOn(dev, PRORC_PARAM_LOOPB)
515 
516 #define rorcLoopBackOff(dev) rorcParamOff(dev);
517 
518 #define rorcPushFreeFifo(dev, blockAddress, blockLength, readyFifoIndex) \
519  if (pRorc(dev)) \
520  { \
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; \
525  } \
526  else \
527  { \
528  dRorcPushRxFreeFifo(dev, blockAddress, blockLength, readyFifoIndex); \
529  }
530 
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))
535 
536 #define rorcFFSize(fw) ((fw & 0xff000000) >> 18) /* (x >> 24) * 64 */
537 #define rorcFWVersMajor(fw) ((fw >> 20) & 0xf)
538 #define rorcFWVersMinor(fw) ((fw >> 13) & 0x7f)
539 
540 /*
541  * Type defs ----------------------------------------------------
542  */
543 
544 typedef struct
545 {
546  int fd;
547  int minor;
548  volatile unsigned *p2pci;
549  unsigned shift;
550  unsigned short vendor;
551  unsigned short device;
552  unsigned irq;
553  unsigned base_address[6];
554  unsigned rom_address;
555  unsigned bus_speed_mode;
556  int rorc_revision;
557  int rorc_serial;
558  int diu_version;
559  int driver_major;
560  int driver_minor;
561  int driver_release;
562  int ddl_channel;
563  int fd_ch;
564  volatile unsigned *reg[DRORC_REG_NUM]; /* D-RORC reg addresses */
565  volatile unsigned *omb[5]; /* pRORC reg addresses */
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; /* loop/us for the given machine */
575  long long int max_resp_time; /* the corresponding max. time */
577 
580 
581 typedef struct
582 {
583  int minor;
584  int channel;
586 
587 
588 typedef struct
589 {
590  volatile unsigned int length;
591  volatile unsigned int status;
593 
594 typedef struct
595 {
596  __u32 ccsr;
597  __u32 cerr;
598  __u32 cdgs;
599 } rorcStatus_t;
600 
601 typedef struct
602 {
603  unsigned long gbc;
604  unsigned long mbc;
605  unsigned long gtc;
606  unsigned long lbc;
607  double lspeed;
608  double bytes;
609  double time;
610  double gspeed;
611 } rorcCounter_t;
612 
613 typedef struct
614 {
615  __u8 data[DDL_MAX_HW_ID];
616  int version;
617  int subversion;
618  int serial;
620 
621 typedef struct
622 {
623  char id_text[8];
624  int sn_pos; // serial number position
625  int ch_pos; // channel number position
626  int ver_pos; // hw version position
627  int ld_pos; // logical device position
628 } rorcId_t;
629 
630 typedef struct
631 {
632  int code;
633  char text[MAX_RETURN_TEXT];
634 } rorcReturn_t;
635 
636 /*
637  * Global variables ------------------------------------------------
638  */
639 
640 extern volatile __u32 prorc_cmd_rdy;
641 extern volatile int interrupt_arrived;
642 
643 
644 /*
645  * Prototypes ------------------------------------------------------
646  */
647 
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);
652 rorcHwSerial_t rorcSerial(rorcHandle_t handle);
653 void rorcBuildHwSerial(__u8 data[], int rorc_rev, int version_major,
654  int version_minor, __u8 c_pld[], int numb_chan,
655  int serial);
656 int rorcCheckOpen(int minor, unsigned int channel);
657 int rorcFind(int revision, int serial, int *minor);
658 int rorcFindAll(rorcHwSerial_t *hw, rorcHwSerial_t *diu_hw,
659  rorcChannelId_t *channel, int *rorc_revision,
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);
664 int rorcMapChannel(rorcDescriptor_t *prorc, int minor, int channel);
665 int rorcMap(rorcDescriptor_t *prorc, int minor);
666 int rorcOpenChannel(rorcDescriptor_t *prorc, int minor, int channel);
667 int rorcOpen(rorcDescriptor_t *prorc, int minor);
668 int rorcClose(rorcDescriptor_t *prorc);
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);
679 int rorcCheckVersion(rorc_pci_dev_t *dev);
680 void rorcReset(rorc_pci_dev_t *dev, int prorc_cmd);
681 int rorcEmptyDataFifos(rorc_pci_dev_t *dev, int empty_time);
682 int dRorcWaitRxStatusNotEmpty(rorc_pci_dev_t *dev);
683 int dRorcCheckRxFreeFifo(rorc_pci_dev_t *dev);
684 int dRorcCheckTxFreeFifo(rorc_pci_dev_t *dev);
685 int rorcCheckTxNotFinished(rorc_pci_dev_t *dev);
686 int rorcCheckFreeFifo(rorc_pci_dev_t *dev);
687 int rorcPopFreeFifo (rorc_pci_dev_t *dev,
688  int tx,
689  __u32 *blockAddress,
690  int *blockLength,
691  int *readyFifoIndex);
692 int pRorcWaitCmdProc(rorc_pci_dev_t *dev);
693 int pRorcWaitMbNotEmpty(rorc_pci_dev_t *dev, __u32 mbMask);
694 int pRorcEmptyMb(rorc_pci_dev_t *prorc, int mb_number, short print);
695 int dRorcEmptyRxStatus(rorc_pci_dev_t *prorc, short print);
696 int rorcReadRorcStatus(rorcHandle_t handle, rorcStatus_t *status);
697 char *rorcPrintStatus(rorcHandle_t handle, int prefix);
698 int rorcCheckDriver(rorcHandle_t dev, int crevision,
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);
705 __u32 rorcReadFw(rorcHandle_t handle);
706 void rorcInterpretVersion(__u32 x);
707 void rorcInterpretSerial(rorcHwSerial_t hw);
708 void rorcInterpretFw(__u32 fw);
709 int rorcReadCounters(rorcHandle_t dev, rorcCounter_t *counter, int inOrout);
710 int rorcReadRxDmaCount(rorcHandle_t dev);
711 int rorcReadTxDmaCount(rorcHandle_t dev);
712 int rorcParamOn(rorc_pci_dev_t *dev, int param);
713 int rorcParamOff(rorc_pci_dev_t *dev);
714 int rorcHltFlctlOn(rorc_pci_dev_t *dev);
715 int rorcHltFlctlOff(rorc_pci_dev_t *dev);
716 int rorcHltSplitOn(rorc_pci_dev_t *dev);
717 int rorcHltSplitOff(rorc_pci_dev_t *dev);
718 int rorcArmDataGenerator(rorc_pci_dev_t *dev,
719  __u32 initEventNumber,
720  __u32 initDataWord,
721  int dataPattern,
722  int eventLen,
723  int seed,
724  int *rounded_len);
725 int rorcStartDataGenerator(rorc_pci_dev_t *dev,
726  __u32 maxLoop);
727 int rorcStopDataGenerator(rorc_pci_dev_t *dev);
728 int rorcStartDataReceiver(rorc_pci_dev_t *dev,
729  unsigned long readyFifoBaseAdress);
730 int rorcStopDataReceiver(rorc_pci_dev_t *dev);
731 int rorcStartDownload(rorc_pci_dev_t *dev,
732  unsigned long bufferPhysAddress,
733  unsigned long bufferWordLength,
734  unsigned long returnPhysAddress);
735 int rorcStopDownload(rorc_pci_dev_t *dev);
736 int rorcStartJtag(rorc_pci_dev_t *dev,
737  unsigned long bufferPhysAddress,
738  unsigned long bufferWordLength,
739  unsigned long returnPhysAddress);
740 int rorcStopJtag(rorc_pci_dev_t *dev);
741 
742 
743 
744 
745 
746 #endif /* _RORC_LIB_H_ */