53c7,8xx.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:52k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * NCR 53c{7,8}0x0 driver, header file
  3.  *
  4.  * Sponsored by
  5.  *      iX Multiuser Multitasking Magazine
  6.  * Hannover, Germany
  7.  * hm@ix.de
  8.  *
  9.  * Copyright 1993, 1994, 1995 Drew Eckhardt
  10.  *      Visionary Computing 
  11.  *      (Unix and Linux consulting and custom programming)
  12.  *      drew@PoohSticks.ORG
  13.  * +1 (303) 786-7975
  14.  *
  15.  * TolerANT and SCSI SCRIPTS are registered trademarks of NCR Corporation.
  16.  * 
  17.  * PRE-ALPHA
  18.  *
  19.  * For more information, please consult 
  20.  *
  21.  * NCR 53C700/53C700-66
  22.  * SCSI I/O Processor
  23.  * Data Manual
  24.  *
  25.  * NCR 53C810
  26.  * PCI-SCSI I/O Processor 
  27.  * Data Manual
  28.  *
  29.  * NCR Microelectronics
  30.  * 1635 Aeroplaza Drive
  31.  * Colorado Springs, CO 80916
  32.  * +1 (719) 578-3400
  33.  *
  34.  * Toll free literature number
  35.  * +1 (800) 334-5454
  36.  *
  37.  */
  38. #ifndef NCR53c7x0_H
  39. #define NCR53c7x0_H
  40. #include <linux/version.h>
  41. /* 
  42.  * Prevent name space pollution in hosts.c, and only provide the 
  43.  * define we need to get the NCR53c7x0 driver into the host template
  44.  * array.
  45.  */
  46. #include <scsi/scsicam.h>
  47. extern int NCR53c7xx_abort(Scsi_Cmnd *);
  48. extern int NCR53c7xx_detect(Scsi_Host_Template *tpnt);
  49. extern int NCR53c7xx_queue_command(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
  50. extern int NCR53c7xx_reset(Scsi_Cmnd *, unsigned int);
  51. #ifdef MODULE
  52. extern int NCR53c7xx_release(struct Scsi_Host *);
  53. #else
  54. #define NCR53c7xx_release NULL
  55. #endif
  56. #define NCR53c7xx {
  57.           name:           "NCR53c{7,8}xx (rel 17)",
  58.   detect:         NCR53c7xx_detect,
  59.   queuecommand:   NCR53c7xx_queue_command,
  60.   abort:          NCR53c7xx_abort,
  61.   reset:          NCR53c7xx_reset,
  62.   bios_param:     scsicam_bios_param,
  63.   can_queue:      24,
  64.   this_id:        7,
  65.   sg_tablesize:   127,
  66.   cmd_per_lun:    3,
  67.   use_clustering: DISABLE_CLUSTERING} 
  68. #ifndef HOSTS_C
  69. /* Register addresses, ordered numerically */
  70. /* SCSI control 0 rw, default = 0xc0 */ 
  71. #define SCNTL0_REG  0x00
  72. #define SCNTL0_ARB1 0x80 /* 0 0 = simple arbitration */
  73. #define SCNTL0_ARB2 0x40 /* 1 1 = full arbitration */
  74. #define SCNTL0_STRT 0x20 /* Start Sequence */
  75. #define SCNTL0_WATN 0x10 /* Select with ATN */
  76. #define SCNTL0_EPC 0x08 /* Enable parity checking */
  77. /* Bit 2 is reserved on 800 series chips */
  78. #define SCNTL0_EPG_700 0x04 /* Enable parity generation */
  79. #define SCNTL0_AAP 0x02 /*  ATN/ on parity error */
  80. #define SCNTL0_TRG 0x01 /* Target mode */
  81. /* SCSI control 1 rw, default = 0x00 */
  82. #define SCNTL1_REG  0x01
  83. #define SCNTL1_EXC 0x80 /* Extra Clock Cycle of Data setup */
  84. #define SCNTL1_ADB 0x40 /*  contents of SODL on bus */
  85. #define SCNTL1_ESR_700 0x20 /* Enable SIOP response to selection 
  86.    and reselection */
  87. #define SCNTL1_DHP_800 0x20 /* Disable halt on parity error or ATN
  88.    target mode only */
  89. #define SCNTL1_CON 0x10 /* Connected */
  90. #define SCNTL1_RST 0x08 /* SCSI RST/ */
  91. #define SCNTL1_AESP 0x04 /* Force bad parity */
  92. #define SCNTL1_SND_700 0x02 /* Start SCSI send */
  93. #define SCNTL1_IARB_800 0x02 /* Immediate Arbitration, start
  94.    arbitration immediately after
  95.    busfree is detected */
  96. #define SCNTL1_RCV_700 0x01 /* Start SCSI receive */
  97. #define SCNTL1_SST_800 0x01 /* Start SCSI transfer */
  98. /* SCSI control 2 rw, */
  99. #define SCNTL2_REG_800 0x02
  100. #define SCNTL2_800_SDU 0x80 /* SCSI disconnect unexpected */
  101. /* SCSI control 3 rw */
  102. #define SCNTL3_REG_800  0x03
  103. #define SCNTL3_800_SCF_SHIFT 4
  104. #define SCNTL3_800_SCF_MASK 0x70
  105. #define SCNTL3_800_SCF2 0x40 /* Synchronous divisor */
  106. #define SCNTL3_800_SCF1 0x20 /* 0x00 = SCLK/3 */
  107. #define SCNTL3_800_SCF0 0x10 /* 0x10 = SCLK/1 */
  108. /* 0x20 = SCLK/1.5 
  109.    0x30 = SCLK/2 
  110.    0x40 = SCLK/3 */
  111.     
  112. #define SCNTL3_800_CCF_SHIFT 0
  113. #define SCNTL3_800_CCF_MASK 0x07
  114. #define SCNTL3_800_CCF2 0x04 /* 0x00 50.01 to 66 */
  115. #define SCNTL3_800_CCF1 0x02 /* 0x01 16.67 to 25 */
  116. #define SCNTL3_800_CCF0 0x01 /* 0x02 25.01 - 37.5 
  117.    0x03 37.51 - 50 
  118.    0x04 50.01 - 66 */
  119. /*  
  120.  * SCSI destination ID rw - the appropriate bit is set for the selected
  121.  * target ID.  This is written by the SCSI SCRIPTS processor.
  122.  * default = 0x00
  123.  */
  124. #define SDID_REG_700   0x02
  125. #define SDID_REG_800 0x06
  126. #define GP_REG_800 0x07 /* General purpose IO */
  127. #define GP_800_IO1 0x02
  128. #define GP_800_IO2 0x01
  129. /* SCSI interrupt enable rw, default = 0x00 */
  130. #define SIEN_REG_700 0x03
  131. #define SIEN0_REG_800 0x40
  132. #define SIEN_MA 0x80 /* Phase mismatch (ini) or ATN (tgt) */
  133. #define SIEN_FC 0x40 /* Function complete */
  134. #define SIEN_700_STO 0x20 /* Selection or reselection timeout */
  135. #define SIEN_800_SEL 0x20 /* Selected */
  136. #define SIEN_700_SEL 0x10 /* Selected or reselected */
  137. #define SIEN_800_RESEL 0x10 /* Reselected */
  138. #define SIEN_SGE 0x08 /* SCSI gross error */
  139. #define SIEN_UDC 0x04 /* Unexpected disconnect */
  140. #define SIEN_RST 0x02 /* SCSI RST/ received */
  141. #define SIEN_PAR 0x01 /* Parity error */
  142. /* 
  143.  * SCSI chip ID rw
  144.  * NCR53c700 : 
  145.  *  When arbitrating, the highest bit is used, when reselection or selection
  146.  *  occurs, the chip responds to all IDs for which a bit is set.
  147.  *  default = 0x00 
  148.  * NCR53c810 : 
  149.  * Uses bit mapping
  150.  */
  151. #define SCID_REG 0x04
  152. /* Bit 7 is reserved on 800 series chips */
  153. #define SCID_800_RRE 0x40 /* Enable response to reselection */
  154. #define SCID_800_SRE 0x20 /* Enable response to selection */
  155. /* Bits four and three are reserved on 800 series chips */
  156. #define SCID_800_ENC_MASK 0x07 /* Encoded SCSI ID */
  157. /* SCSI transfer rw, default = 0x00 */
  158. #define SXFER_REG 0x05
  159. #define SXFER_DHP 0x80 /* Disable halt on parity */
  160. #define SXFER_TP2 0x40 /* Transfer period msb */
  161. #define SXFER_TP1 0x20
  162. #define SXFER_TP0 0x10 /* lsb */
  163. #define SXFER_TP_MASK 0x70
  164. /* FIXME : SXFER_TP_SHIFT == 5 is right for '8xx chips */
  165. #define SXFER_TP_SHIFT 5
  166. #define SXFER_TP_4 0x00 /* Divisors */
  167. #define SXFER_TP_5 0x10<<1
  168. #define SXFER_TP_6 0x20<<1
  169. #define SXFER_TP_7 0x30<<1
  170. #define SXFER_TP_8 0x40<<1
  171. #define SXFER_TP_9 0x50<<1
  172. #define SXFER_TP_10 0x60<<1
  173. #define SXFER_TP_11 0x70<<1
  174. #define SXFER_MO3 0x08 /* Max offset msb */
  175. #define SXFER_MO2 0x04
  176. #define SXFER_MO1 0x02
  177. #define SXFER_MO0 0x01 /* lsb */
  178. #define SXFER_MO_MASK 0x0f
  179. #define SXFER_MO_SHIFT 0
  180. /* 
  181.  * SCSI output data latch rw
  182.  * The contents of this register are driven onto the SCSI bus when 
  183.  * the Assert Data Bus bit of the SCNTL1 register is set and 
  184.  * the CD, IO, and MSG bits of the SOCL register match the SCSI phase
  185.  */
  186. #define SODL_REG_700 0x06
  187. #define SODL_REG_800 0x54
  188. /* 
  189.  * SCSI output control latch rw, default = 0 
  190.  * Note that when the chip is being manually programmed as an initiator,
  191.  * the MSG, CD, and IO bits must be set correctly for the phase the target
  192.  * is driving the bus in.  Otherwise no data transfer will occur due to 
  193.  * phase mismatch.
  194.  */
  195. #define SBCL_REG 0x0b
  196. #define SBCL_REQ 0x80 /*  REQ */
  197. #define SBCL_ACK 0x40 /*  ACK */
  198. #define SBCL_BSY 0x20 /*  BSY */
  199. #define SBCL_SEL 0x10 /*  SEL */
  200. #define SBCL_ATN 0x08 /*  ATN */
  201. #define SBCL_MSG 0x04 /*  MSG */
  202. #define SBCL_CD 0x02 /*  C/D */
  203. #define SBCL_IO 0x01 /*  I/O */
  204. #define SBCL_PHASE_CMDOUT SBCL_CD
  205. #define SBCL_PHASE_DATAIN SBCL_IO
  206. #define SBCL_PHASE_DATAOUT 0
  207. #define SBCL_PHASE_MSGIN (SBCL_CD|SBCL_IO|SBCL_MSG)
  208. #define SBCL_PHASE_MSGOUT (SBCL_CD|SBCL_MSG)
  209. #define SBCL_PHASE_STATIN (SBCL_CD|SBCL_IO)
  210. #define SBCL_PHASE_MASK (SBCL_CD|SBCL_IO|SBCL_MSG)
  211. /* 
  212.  * SCSI first byte received latch ro 
  213.  * This register contains the first byte received during a block MOVE 
  214.  * SCSI SCRIPTS instruction, including
  215.  * 
  216.  * Initiator mode Target mode
  217.  * Message in Command
  218.  * Status Message out
  219.  * Data in Data out
  220.  *
  221.  * It also contains the selecting or reselecting device's ID and our 
  222.  * ID.
  223.  *
  224.  * Note that this is the register the various IF conditionals can 
  225.  * operate on.
  226.  */
  227. #define SFBR_REG 0x08
  228. /* 
  229.  * SCSI input data latch ro
  230.  * In initiator mode, data is latched into this register on the rising
  231.  * edge of REQ/. In target mode, data is latched on the rising edge of 
  232.  * ACK/
  233.  */
  234. #define SIDL_REG_700 0x09
  235. #define SIDL_REG_800 0x50
  236. /* 
  237.  * SCSI bus data lines ro 
  238.  * This register reflects the instantaneous status of the SCSI data 
  239.  * lines.  Note that SCNTL0 must be set to disable parity checking, 
  240.  * otherwise reading this register will latch new parity.
  241.  */
  242. #define SBDL_REG_700 0x0a
  243. #define SBDL_REG_800 0x58
  244. #define SSID_REG_800 0x0a
  245. #define SSID_800_VAL 0x80 /* Exactly two bits asserted at sel */
  246. #define SSID_800_ENCID_MASK 0x07 /* Device which performed operation */
  247. /* 
  248.  * SCSI bus control lines rw, 
  249.  * instantaneous readout of control lines 
  250.  */
  251. #define SOCL_REG 0x0b 
  252. #define SOCL_REQ 0x80 /*  REQ ro */
  253. #define SOCL_ACK 0x40 /*  ACK ro */
  254. #define SOCL_BSY 0x20 /*  BSY ro */
  255. #define SOCL_SEL 0x10 /*  SEL ro */
  256. #define SOCL_ATN 0x08 /*  ATN ro */
  257. #define SOCL_MSG 0x04 /*  MSG ro */
  258. #define SOCL_CD 0x02 /*  C/D ro */
  259. #define SOCL_IO 0x01 /*  I/O ro */
  260. /* 
  261.  * Synchronous SCSI Clock Control bits 
  262.  * 0 - set by DCNTL 
  263.  * 1 - SCLK / 1.0
  264.  * 2 - SCLK / 1.5
  265.  * 3 - SCLK / 2.0 
  266.  */
  267. #define SBCL_SSCF1 0x02 /* wo, -66 only */
  268. #define SBCL_SSCF0 0x01 /* wo, -66 only */
  269. #define SBCL_SSCF_MASK 0x03
  270. /* 
  271.  * XXX note : when reading the DSTAT and STAT registers to clear interrupts,
  272.  * insure that 10 clocks elapse between the two  
  273.  */
  274. /* DMA status ro */
  275. #define DSTAT_REG 0x0c
  276. #define DSTAT_DFE 0x80 /* DMA FIFO empty */
  277. #define DSTAT_800_MDPE 0x40 /* Master Data Parity Error */
  278. #define DSTAT_800_BF 0x20 /* Bus Fault */
  279. #define DSTAT_ABRT 0x10 /* Aborted - set on error */
  280. #define DSTAT_SSI 0x08 /* SCRIPTS single step interrupt */
  281. #define DSTAT_SIR 0x04 /* SCRIPTS interrupt received - 
  282.    set when INT instruction is 
  283.    executed */
  284. #define DSTAT_WTD 0x02 /* Watchdog timeout detected */
  285. #define DSTAT_OPC 0x01 /* Illegal instruction */
  286. #define DSTAT_800_IID 0x01 /* Same thing, different name */
  287. /* NCR53c800 moves this stuff into SIST0 */
  288. #define SSTAT0_REG 0x0d /* SCSI status 0 ro */
  289. #define SIST0_REG_800 0x42
  290. #define SSTAT0_MA 0x80 /* ini : phase mismatch,
  291.  * tgt : ATN/ asserted 
  292.  */
  293. #define SSTAT0_CMP 0x40 /* function complete */
  294. #define SSTAT0_700_STO 0x20 /* Selection or reselection timeout */
  295. #define SIST0_800_SEL 0x20 /* Selected */
  296. #define SSTAT0_700_SEL 0x10 /* Selected or reselected */
  297. #define SIST0_800_RSL 0x10 /* Reselected */
  298. #define SSTAT0_SGE 0x08 /* SCSI gross error */
  299. #define SSTAT0_UDC 0x04 /* Unexpected disconnect */
  300. #define SSTAT0_RST 0x02 /* SCSI RST/ received */
  301. #define SSTAT0_PAR 0x01 /* Parity error */
  302. /* And uses SSTAT0 for what was SSTAT1 */
  303. #define SSTAT1_REG 0x0e /* SCSI status 1 ro */
  304. #define SSTAT1_ILF 0x80 /* SIDL full */
  305. #define SSTAT1_ORF 0x40 /* SODR full */
  306. #define SSTAT1_OLF 0x20 /* SODL full */
  307. #define SSTAT1_AIP 0x10 /* Arbitration in progress */
  308. #define SSTAT1_LOA 0x08 /* Lost arbitration */
  309. #define SSTAT1_WOA 0x04 /* Won arbitration */
  310. #define SSTAT1_RST 0x02 /* Instant readout of RST/ */
  311. #define SSTAT1_SDP 0x01 /* Instant readout of SDP/ */
  312. #define SSTAT2_REG 0x0f /* SCSI status 2 ro */
  313. #define SSTAT2_FF3 0x80  /* number of bytes in synchronous */
  314. #define SSTAT2_FF2 0x40 /* data FIFO */
  315. #define SSTAT2_FF1 0x20
  316. #define SSTAT2_FF0 0x10
  317. #define SSTAT2_FF_MASK 0xf0
  318. #define SSTAT2_FF_SHIFT 4
  319. /* 
  320.  * Latched signals, latched on the leading edge of REQ/ for initiators,
  321.  * ACK/ for targets.
  322.  */
  323. #define SSTAT2_SDP 0x08 /* SDP */
  324. #define SSTAT2_MSG 0x04 /* MSG */
  325. #define SSTAT2_CD 0x02 /* C/D */
  326. #define SSTAT2_IO 0x01 /* I/O */
  327. #define SSTAT2_PHASE_CMDOUT SSTAT2_CD
  328. #define SSTAT2_PHASE_DATAIN SSTAT2_IO
  329. #define SSTAT2_PHASE_DATAOUT 0
  330. #define SSTAT2_PHASE_MSGIN (SSTAT2_CD|SSTAT2_IO|SSTAT2_MSG)
  331. #define SSTAT2_PHASE_MSGOUT (SSTAT2_CD|SSTAT2_MSG)
  332. #define SSTAT2_PHASE_STATIN (SSTAT2_CD|SSTAT2_IO)
  333. #define SSTAT2_PHASE_MASK (SSTAT2_CD|SSTAT2_IO|SSTAT2_MSG)
  334. /* NCR53c700-66 only */
  335. #define SCRATCHA_REG_00 0x10    /* through  0x13 Scratch A rw */
  336. /* NCR53c710 and higher */
  337. #define DSA_REG 0x10 /* DATA structure address */
  338. #define CTEST0_REG_700 0x14 /* Chip test 0 ro */
  339. #define CTEST0_REG_800 0x18 /* Chip test 0 rw, general purpose */
  340. /* 0x80 - 0x04 are reserved */
  341. #define CTEST0_700_RTRG 0x02 /* Real target mode */
  342. #define CTEST0_700_DDIR 0x01 /* Data direction, 1 = 
  343.  * SCSI bus to host, 0  =
  344.  * host to SCSI.
  345.  */
  346. #define CTEST1_REG_700 0x15 /* Chip test 1 ro */
  347. #define CTEST1_REG_800 0x19 /* Chip test 1 ro */
  348. #define CTEST1_FMT3 0x80 /* Identify which byte lanes are empty */
  349. #define CTEST1_FMT2 0x40  /* in the DMA FIFO */
  350. #define CTEST1_FMT1 0x20
  351. #define CTEST1_FMT0 0x10
  352. #define CTEST1_FFL3 0x08 /* Identify which bytes lanes are full */
  353. #define CTEST1_FFL2 0x04 /* in the DMA FIFO */
  354. #define CTEST1_FFL1 0x02
  355. #define CTEST1_FFL0 0x01
  356. #define CTEST2_REG_700 0x16 /* Chip test 2 ro */
  357. #define CTEST2_REG_800 0x1a /* Chip test 2 ro */
  358. #define CTEST2_800_DDIR 0x80 /* 1 = SCSI->host */
  359. #define CTEST2_800_SIGP 0x40 /* A copy of SIGP in ISTAT.
  360.    Reading this register clears */
  361. #define CTEST2_800_CIO 0x20 /* Configured as IO */.
  362. #define CTEST2_800_CM 0x10 /* Configured as memory */
  363. /* 0x80 - 0x40 are reserved on 700 series chips */
  364. #define CTEST2_700_SOFF 0x20 /* SCSI Offset Compare,
  365.  * As an initiator, this bit is 
  366.  * one when the synchronous offset
  367.  * is zero, as a target this bit 
  368.  * is one when the synchronous 
  369.  * offset is at the maximum
  370.  * defined in SXFER
  371.  */
  372. #define CTEST2_700_SFP 0x10 /* SCSI FIFO parity bit,
  373.  * reading CTEST3 unloads a byte
  374.  * from the FIFO and sets this
  375.  */
  376. #define CTEST2_700_DFP 0x08 /* DMA FIFO parity bit,
  377.  * reading CTEST6 unloads a byte
  378.  * from the FIFO and sets this
  379.  */
  380. #define CTEST2_TEOP 0x04 /* SCSI true end of process,
  381.  * indicates a totally finished
  382.  * transfer
  383.  */
  384. #define CTEST2_DREQ 0x02 /* Data request signal */
  385. /* 0x01 is reserved on 700 series chips */
  386. #define CTEST2_800_DACK 0x01
  387. /* 
  388.  * Chip test 3 ro 
  389.  * Unloads the bottom byte of the eight deep SCSI synchronous FIFO,
  390.  * check SSTAT2 FIFO full bits to determine size.  Note that a GROSS
  391.  * error results if a read is attempted on this register.  Also note 
  392.  * that 16 and 32 bit reads of this register will cause corruption.
  393.  */
  394. #define CTEST3_REG_700 0x17
  395. /*  Chip test 3 rw */
  396. #define CTEST3_REG_800 0x1b
  397. #define CTEST3_800_V3 0x80 /* Chip revision */
  398. #define CTEST3_800_V2 0x40
  399. #define CTEST3_800_V1 0x20
  400. #define CTEST3_800_V0 0x10
  401. #define CTEST3_800_FLF 0x08 /* Flush DMA FIFO */
  402. #define CTEST3_800_CLF 0x04 /* Clear DMA FIFO */
  403. #define CTEST3_800_FM 0x02 /* Fetch mode pin */
  404. /* bit 0 is reserved on 800 series chips */
  405. #define CTEST4_REG_700 0x18 /* Chip test 4 rw */
  406. #define CTEST4_REG_800 0x21 /* Chip test 4 rw */
  407. /* 0x80 is reserved on 700 series chips */
  408. #define CTEST4_800_BDIS 0x80 /* Burst mode disable */
  409. #define CTEST4_ZMOD 0x40 /* High impedance mode */
  410. #define CTEST4_SZM 0x20 /* SCSI bus high impedance */
  411. #define CTEST4_700_SLBE 0x10 /* SCSI loopback enabled */
  412. #define CTEST4_800_SRTM 0x10 /* Shadow Register Test Mode */
  413. #define CTEST4_700_SFWR 0x08 /* SCSI FIFO write enable, 
  414.  * redirects writes from SODL
  415.  * to the SCSI FIFO.
  416.  */
  417. #define CTEST4_800_MPEE 0x08 /* Enable parity checking
  418.    during master cycles on PCI
  419.    bus */
  420. /* 
  421.  * These bits send the contents of the CTEST6 register to the appropriate
  422.  * byte lane of the 32 bit DMA FIFO.  Normal operation is zero, otherwise 
  423.  * the high bit means the low two bits select the byte lane.
  424.  */
  425. #define CTEST4_FBL2 0x04
  426. #define CTEST4_FBL1 0x02
  427. #define CTEST4_FBL0 0x01
  428. #define CTEST4_FBL_MASK 0x07
  429. #define CTEST4_FBL_0 0x04 /* Select DMA FIFO byte lane 0 */
  430. #define CTEST4_FBL_1 0x05 /* Select DMA FIFO byte lane 1 */
  431. #define CTEST4_FBL_2 0x06 /* Select DMA FIFO byte lane 2 */
  432. #define CTEST4_FBL_3 0x07 /* Select DMA FIFO byte lane 3 */
  433. #define CTEST4_800_SAVE (CTEST4_800_BDIS)
  434. #define CTEST5_REG_700 0x19 /* Chip test 5 rw */
  435. #define CTEST5_REG_800 0x22 /* Chip test 5 rw */
  436. /* 
  437.  * Clock Address Incrementor.  When set, it increments the 
  438.  * DNAD register to the next bus size boundary.  It automatically 
  439.  * resets itself when the operation is complete.
  440.  */
  441. #define CTEST5_ADCK 0x80
  442. /*
  443.  * Clock Byte Counter.  When set, it decrements the DBC register to
  444.  * the next bus size boundary.
  445.  */
  446. #define CTEST5_BBCK 0x40
  447. /*
  448.  * Reset SCSI Offset.  Setting this bit to 1 clears the current offset
  449.  * pointer in the SCSI synchronous offset counter (SSTAT).  This bit
  450.  * is set to 1 if a SCSI Gross Error Condition occurs.  The offset should
  451.  * be cleared when a synchronous transfer fails.  When written, it is 
  452.  * automatically cleared after the SCSI synchronous offset counter is 
  453.  * reset.
  454.  */
  455. /* Bit 5 is reserved on 800 series chips */
  456. #define CTEST5_700_ROFF 0x20
  457. /* 
  458.  * Master Control for Set or Reset pulses. When 1, causes the low 
  459.  * four bits of register to set when set, 0 causes the low bits to
  460.  * clear when set.
  461.  */
  462. #define CTEST5_MASR  0x10
  463. #define CTEST5_DDIR 0x08 /* DMA direction */
  464. /*
  465.  * Bits 2-0 are reserved on 800 series chips
  466.  */
  467. #define CTEST5_700_EOP 0x04 /* End of process */
  468. #define CTEST5_700_DREQ 0x02 /* Data request */
  469. #define CTEST5_700_DACK 0x01 /* Data acknowledge */
  470. /* 
  471.  * Chip test 6 rw - writing to this register writes to the byte 
  472.  * lane in the DMA FIFO as determined by the FBL bits in the CTEST4
  473.  * register.
  474.  */
  475. #define CTEST6_REG_700 0x1a
  476. #define CTEST6_REG_800 0x23
  477. #define CTEST7_REG 0x1b /* Chip test 7 rw */
  478. /* 0x80 - 0x40 are reserved on NCR53c700 and NCR53c700-66 chips */
  479. #define CTEST7_10_CDIS 0x80 /* Cache burst disable */
  480. #define CTEST7_10_SC1 0x40 /* Snoop control bits */
  481. #define CTEST7_10_SC0 0x20
  482. #define CTEST7_10_SC_MASK 0x60
  483. /* 0x20 is reserved on the NCR53c700 */
  484. #define CTEST7_0060_FM 0x20 /* Fetch mode */
  485. #define CTEST7_STD 0x10 /* Selection timeout disable */
  486. #define CTEST7_DFP 0x08 /* DMA FIFO parity bit for CTEST6 */
  487. #define CTEST7_EVP 0x04 /* 1 = host bus even parity, 0 = odd */
  488. #define CTEST7_10_TT1 0x02 /* Transfer type */
  489. #define CTEST7_00_DC 0x02 /* Set to drive DC low during instruction 
  490.    fetch */
  491. #define CTEST7_DIFF 0x01 /* Differential mode */
  492. #define CTEST7_SAVE ( CTEST7_EVP | CTEST7_DIFF )
  493. #define TEMP_REG 0x1c /* through 0x1f Temporary stack rw */
  494. #define DFIFO_REG 0x20 /* DMA FIFO rw */
  495. /* 
  496.  * 0x80 is reserved on the NCR53c710, the CLF and FLF bits have been
  497.  * moved into the CTEST8 register.
  498.  */
  499. #define DFIFO_00_FLF 0x80 /* Flush DMA FIFO to memory */
  500. #define DFIFO_00_CLF 0x40 /* Clear DMA and SCSI FIFOs */
  501. #define DFIFO_BO6 0x40
  502. #define DFIFO_BO5 0x20
  503. #define DFIFO_BO4 0x10
  504. #define DFIFO_BO3 0x08
  505. #define DFIFO_BO2 0x04 
  506. #define DFIFO_BO1 0x02
  507. #define DFIFO_BO0 0x01
  508. #define DFIFO_10_BO_MASK 0x7f /* 7 bit counter */
  509. #define DFIFO_00_BO_MASK 0x3f /* 6 bit counter */
  510. /* 
  511.  * Interrupt status rw 
  512.  * Note that this is the only register which can be read while SCSI
  513.  * SCRIPTS are being executed.
  514.  */
  515. #define ISTAT_REG_700 0x21
  516. #define ISTAT_REG_800 0x14
  517. #define ISTAT_ABRT 0x80 /* Software abort, write 
  518.  *1 to abort, wait for interrupt. */
  519. /* 0x40 and 0x20 are reserved on NCR53c700 and NCR53c700-66 chips */
  520. #define ISTAT_10_SRST 0x40 /* software reset */
  521. #define ISTAT_10_SIGP 0x20 /* signal script */
  522. /* 0x10 is reserved on NCR53c700 series chips */
  523. #define ISTAT_800_SEM 0x10 /* semaphore */
  524. #define ISTAT_CON 0x08 /* 1 when connected */
  525. #define ISTAT_800_INTF 0x04 /* Interrupt on the fly */
  526. #define ISTAT_700_PRE 0x04 /* Pointer register empty.
  527.  * Set to 1 when DSPS and DSP
  528.  * registers are empty in pipeline
  529.  * mode, always set otherwise.
  530.  */
  531. #define ISTAT_SIP 0x02 /* SCSI interrupt pending from
  532.  * SCSI portion of SIOP see
  533.  * SSTAT0
  534.  */
  535. #define ISTAT_DIP 0x01 /* DMA interrupt pending 
  536.  * see DSTAT
  537.  */
  538. /* NCR53c700-66 and NCR53c710 only */
  539. #define CTEST8_REG 0x22 /* Chip test 8 rw */
  540. #define CTEST8_0066_EAS 0x80 /* Enable alternate SCSI clock,
  541.  * ie read from SCLK/ rather than CLK/
  542.  */
  543. #define CTEST8_0066_EFM 0x40 /* Enable fetch and master outputs */
  544. #define CTEST8_0066_GRP 0x20 /* Generate Receive Parity for 
  545.  * pass through.  This insures that 
  546.  * bad parity won't reach the host 
  547.  * bus.
  548.  */
  549. #define CTEST8_0066_TE 0x10 /* TolerANT enable.  Enable 
  550.  * active negation, should only
  551.  * be used for slow SCSI 
  552.  * non-differential.
  553.  */
  554. #define CTEST8_0066_HSC 0x08 /* Halt SCSI clock */
  555. #define CTEST8_0066_SRA 0x04 /* Shorten REQ/ACK filtering,
  556.  * must be set for fast SCSI-II
  557.  * speeds.
  558.  */
  559. #define CTEST8_0066_DAS 0x02 /* Disable automatic target/initiator
  560.  * switching.
  561.  */
  562. #define CTEST8_0066_LDE 0x01 /* Last disconnect enable.
  563.  * The status of pending 
  564.  * disconnect is maintained by
  565.  * the core, eliminating
  566.  * the possibility of missing a 
  567.  * selection or reselection
  568.  * while waiting to fetch a 
  569.  * WAIT DISCONNECT opcode.
  570.  */
  571. #define CTEST8_10_V3 0x80 /* Chip revision */
  572. #define CTEST8_10_V2 0x40
  573. #define CTEST8_10_V1 0x20
  574. #define CTEST8_10_V0 0x10
  575. #define CTEST8_10_V_MASK 0xf0
  576. #define CTEST8_10_FLF 0x08 /* Flush FIFOs */
  577. #define CTEST8_10_CLF 0x04 /* Clear FIFOs */
  578. #define CTEST8_10_FM 0x02 /* Fetch pin mode */
  579. #define CTEST8_10_SM 0x01 /* Snoop pin mode */
  580. /* 
  581.  * The CTEST9 register may be used to differentiate between a
  582.  * NCR53c700 and a NCR53c710.  
  583.  *
  584.  * Write 0xff to this register.
  585.  * Read it.
  586.  * If the contents are 0xff, it is a NCR53c700
  587.  * If the contents are 0x00, it is a NCR53c700-66 first revision
  588.  * If the contents are some other value, it is some other NCR53c700-66
  589.  */
  590. #define CTEST9_REG_00 0x23 /* Chip test 9 ro */
  591. #define LCRC_REG_10 0x23
  592. /*
  593.  * 0x24 through 0x27 are the DMA byte counter register.  Instructions
  594.  * write their high 8 bits into the DCMD register, the low 24 bits into
  595.  * the DBC register.
  596.  *
  597.  * Function is dependent on the command type being executed.
  598.  */
  599.  
  600. #define DBC_REG 0x24
  601. /* 
  602.  * For Block Move Instructions, DBC is a 24 bit quantity representing 
  603.  *     the number of bytes to transfer.
  604.  * For Transfer Control Instructions, DBC is bit fielded as follows : 
  605.  */
  606. /* Bits 20 - 23 should be clear */
  607. #define DBC_TCI_TRUE (1 << 19)  /* Jump when true */
  608. #define DBC_TCI_COMPARE_DATA (1 << 18) /* Compare data */
  609. #define DBC_TCI_COMPARE_PHASE (1 << 17) /* Compare phase with DCMD field */
  610. #define DBC_TCI_WAIT_FOR_VALID (1 << 16) /* Wait for REQ */
  611. /* Bits 8 - 15 are reserved on some implementations ? */
  612. #define DBC_TCI_MASK_MASK 0xff00  /* Mask for data compare */
  613. #define DBC_TCI_MASK_SHIFT 8
  614. #define DBC_TCI_DATA_MASK 0xff /* Data to be compared */ 
  615. #define DBC_TCI_DATA_SHIFT 0
  616. #define DBC_RWRI_IMMEDIATE_MASK 0xff00 /* Immediate data */
  617. #define DBC_RWRI_IMMEDIATE_SHIFT 8 /* Amount to shift */
  618. #define DBC_RWRI_ADDRESS_MASK 0x3f0000 /* Register address */
  619. #define DBC_RWRI_ADDRESS_SHIFT  16
  620. /*
  621.  * DMA command r/w
  622.  */
  623. #define DCMD_REG 0x27
  624. #define DCMD_TYPE_MASK 0xc0 /* Masks off type */
  625. #define DCMD_TYPE_BMI 0x00 /* Indicates a Block Move instruction */
  626. #define DCMD_BMI_IO 0x01 /* I/O, CD, and MSG bits selecting   */
  627. #define DCMD_BMI_CD 0x02 /* the phase for the block MOVE      */
  628. #define DCMD_BMI_MSG 0x04 /* instruction       */
  629. #define DCMD_BMI_OP_MASK 0x18 /* mask for opcode */
  630. #define DCMD_BMI_OP_MOVE_T 0x00 /* MOVE */
  631. #define DCMD_BMI_OP_MOVE_I 0x08 /* MOVE Initiator */
  632. #define DCMD_BMI_INDIRECT 0x20 /*  Indirect addressing */
  633. #define DCMD_TYPE_TCI 0x80 /* Indicates a Transfer Control 
  634.    instruction */
  635. #define DCMD_TCI_IO 0x01 /* I/O, CD, and MSG bits selecting   */
  636. #define DCMD_TCI_CD 0x02 /* the phase for the block MOVE      */
  637. #define DCMD_TCI_MSG 0x04 /* instruction       */
  638. #define DCMD_TCI_OP_MASK 0x38 /* mask for opcode */
  639. #define DCMD_TCI_OP_JUMP 0x00 /* JUMP */
  640. #define DCMD_TCI_OP_CALL 0x08 /* CALL */
  641. #define DCMD_TCI_OP_RETURN 0x10 /* RETURN */
  642. #define DCMD_TCI_OP_INT 0x18 /* INT */
  643. #define DCMD_TYPE_RWRI 0x40 /* Indicates I/O or register Read/Write
  644.    instruction */
  645. #define DCMD_RWRI_OPC_MASK 0x38 /* Opcode mask */
  646. #define DCMD_RWRI_OPC_WRITE 0x28 /* Write SFBR to register */
  647. #define DCMD_RWRI_OPC_READ 0x30 /* Read register to SFBR */
  648. #define DCMD_RWRI_OPC_MODIFY 0x38 /* Modify in place */
  649. #define DCMD_RWRI_OP_MASK 0x07
  650. #define DCMD_RWRI_OP_MOVE 0x00
  651. #define DCMD_RWRI_OP_SHL 0x01
  652. #define DCMD_RWRI_OP_OR 0x02
  653. #define DCMD_RWRI_OP_XOR 0x03
  654. #define DCMD_RWRI_OP_AND 0x04
  655. #define DCMD_RWRI_OP_SHR 0x05
  656. #define DCMD_RWRI_OP_ADD 0x06
  657. #define DCMD_RWRI_OP_ADDC 0x07
  658. #define DCMD_TYPE_MMI 0xc0 /* Indicates a Memory Move instruction 
  659.    (three words) */
  660. #define DNAD_REG 0x28 /* through 0x2b DMA next address for 
  661.    data */
  662. #define DSP_REG 0x2c /* through 0x2f DMA SCRIPTS pointer rw */
  663. #define DSPS_REG 0x30 /* through 0x33 DMA SCRIPTS pointer 
  664.    save rw */
  665. #define DMODE_REG_00 0x34  /* DMA mode rw */
  666. #define DMODE_00_BL1 0x80 /* Burst length bits */
  667. #define DMODE_00_BL0 0x40
  668. #define DMODE_BL_MASK 0xc0
  669. /* Burst lengths (800) */
  670. #define DMODE_BL_2 0x00 /* 2 transfer */
  671. #define DMODE_BL_4 0x40 /* 4 transfers */
  672. #define DMODE_BL_8 0x80 /* 8 transfers */
  673. #define DMODE_BL_16 0xc0 /* 16 transfers */
  674. #define DMODE_700_BW16 0x20 /* Host buswidth = 16 */
  675. #define DMODE_700_286 0x10 /* 286 mode */
  676. #define DMODE_700_IOM 0x08 /* Transfer to IO port */
  677. #define DMODE_700_FAM 0x04 /* Fixed address mode */
  678. #define DMODE_700_PIPE 0x02 /* Pipeline mode disables 
  679.  * automatic fetch / exec 
  680.  */
  681. #define DMODE_MAN 0x01 /* Manual start mode, 
  682.  * requires a 1 to be written
  683.  * to the start DMA bit in the DCNTL
  684.  * register to run scripts 
  685.  */
  686. #define DMODE_700_SAVE ( DMODE_00_BL_MASK | DMODE_00_BW16 | DMODE_00_286 )
  687. /* NCR53c800 series only */
  688. #define SCRATCHA_REG_800 0x34 /* through 0x37 Scratch A rw */
  689. /* NCR53c710 only */
  690. #define SCRATCB_REG_10 0x34 /* through 0x37 scratch B rw */
  691. #define DMODE_REG_10     0x38 /* DMA mode rw, NCR53c710 and newer */
  692. #define DMODE_800_SIOM 0x20 /* Source IO = 1 */
  693. #define DMODE_800_DIOM 0x10 /* Destination IO = 1 */
  694. #define DMODE_800_ERL 0x08 /* Enable Read Line */
  695. /* 35-38 are reserved on 700 and 700-66 series chips */
  696. #define DIEN_REG 0x39 /* DMA interrupt enable rw */
  697. /* 0x80, 0x40, and 0x20 are reserved on 700-series chips */
  698. #define DIEN_800_MDPE 0x40 /* Master data parity error */
  699. #define DIEN_800_BF 0x20 /* BUS fault */
  700. #define DIEN_ABRT 0x10 /* Enable aborted interrupt */
  701. #define DIEN_SSI 0x08 /* Enable single step interrupt */
  702. #define DIEN_SIR 0x04 /* Enable SCRIPTS INT command 
  703.  * interrupt
  704.  */
  705. /* 0x02 is reserved on 800 series chips */
  706. #define DIEN_700_WTD 0x02 /* Enable watchdog timeout interrupt */
  707. #define DIEN_700_OPC 0x01 /* Enable illegal instruction 
  708.  * interrupt 
  709.  */
  710. #define DIEN_800_IID 0x01 /*  Same meaning, different name */ 
  711. /*
  712.  * DMA watchdog timer rw
  713.  * set in 16 CLK input periods.
  714.  */
  715. #define DWT_REG 0x3a
  716. /* DMA control rw */
  717. #define DCNTL_REG 0x3b
  718. #define DCNTL_700_CF1 0x80 /* Clock divisor bits */
  719. #define DCNTL_700_CF0 0x40
  720. #define DCNTL_700_CF_MASK 0xc0
  721. /* Clock divisors     Divisor SCLK range (MHZ) */
  722. #define DCNTL_700_CF_2 0x00    /* 2.0    37.51-50.00 */
  723. #define DCNTL_700_CF_1_5 0x40 /* 1.5    25.01-37.50 */
  724. #define DCNTL_700_CF_1 0x80 /* 1.0     16.67-25.00 */
  725. #define DCNTL_700_CF_3 0xc0 /* 3.0    50.01-66.67 (53c700-66) */
  726. #define DCNTL_700_S16 0x20 /* Load scripts 16 bits at a time */
  727. #define DCNTL_SSM 0x10 /* Single step mode */
  728. #define DCNTL_700_LLM 0x08 /* Low level mode, can only be set 
  729.  * after selection */
  730. #define DCNTL_800_IRQM 0x08 /* Totem pole IRQ pin */
  731. #define DCNTL_STD 0x04 /* Start DMA / SCRIPTS */
  732. /* 0x02 is reserved */
  733. #define DCNTL_00_RST 0x01 /* Software reset, resets everything
  734.  * but 286 mode bit  in DMODE. On the
  735.  * NCR53c710, this bit moved to CTEST8
  736.  */
  737. #define DCNTL_10_COM 0x01 /* 700 software compatibility mode */
  738. #define DCNTL_700_SAVE ( DCNTL_CF_MASK | DCNTL_S16)
  739. /* NCR53c700-66 only */
  740. #define SCRATCHB_REG_00 0x3c /* through 0x3f scratch b rw */
  741. #define SCRATCHB_REG_800 0x5c /* through 0x5f scratch b rw */
  742. /* NCR53c710 only */
  743. #define ADDER_REG_10 0x3c /* Adder, NCR53c710 only */
  744. #define SIEN1_REG_800 0x41
  745. #define SIEN1_800_STO 0x04 /* selection/reselection timeout */
  746. #define SIEN1_800_GEN 0x02 /* general purpose timer */
  747. #define SIEN1_800_HTH 0x01 /* handshake to handshake */
  748. #define SIST1_REG_800 0x43
  749. #define SIST1_800_STO 0x04 /* selection/reselection timeout */
  750. #define SIST1_800_GEN 0x02 /* general purpose timer */
  751. #define SIST1_800_HTH 0x01 /* handshake to handshake */
  752. #define SLPAR_REG_800 0x44 /* Parity */
  753. #define MACNTL_REG_800 0x46 /* Memory access control */
  754. #define MACNTL_800_TYP3 0x80
  755. #define MACNTL_800_TYP2 0x40
  756. #define MACNTL_800_TYP1 0x20
  757. #define MACNTL_800_TYP0 0x10
  758. #define MACNTL_800_DWR 0x08
  759. #define MACNTL_800_DRD 0x04
  760. #define MACNTL_800_PSCPT 0x02
  761. #define MACNTL_800_SCPTS 0x01
  762. #define GPCNTL_REG_800 0x47 /* General Purpose Pin Control */
  763. /* Timeouts are expressed such that 0=off, 1=100us, doubling after that */
  764. #define STIME0_REG_800 0x48 /* SCSI Timer Register 0 */
  765. #define STIME0_800_HTH_MASK 0xf0 /* Handshake to Handshake timeout */
  766. #define STIME0_800_HTH_SHIFT 4
  767. #define STIME0_800_SEL_MASK 0x0f /* Selection timeout */
  768. #define STIME0_800_SEL_SHIFT 0
  769. #define STIME1_REG_800 0x49
  770. #define STIME1_800_GEN_MASK 0x0f /* General purpose timer */
  771. #define RESPID_REG_800 0x4a /* Response ID, bit fielded.  8
  772.    bits on narrow chips, 16 on WIDE */
  773. #define STEST0_REG_800 0x4c
  774. #define STEST0_800_SLT 0x08 /* Selection response logic test */
  775. #define STEST0_800_ART 0x04 /* Arbitration priority encoder test */
  776. #define STEST0_800_SOZ 0x02 /* Synchronous offset zero */
  777. #define STEST0_800_SOM 0x01 /* Synchronous offset maximum */
  778. #define STEST1_REG_800 0x4d
  779. #define STEST1_800_SCLK 0x80 /* Disable SCSI clock */
  780. #define STEST2_REG_800 0x4e
  781. #define STEST2_800_SCE 0x80 /* Enable SOCL/SODL */
  782. #define STEST2_800_ROF 0x40 /* Reset SCSI sync offset */
  783. #define STEST2_800_SLB 0x10 /* Enable SCSI loopback mode */
  784. #define STEST2_800_SZM 0x08 /* SCSI high impedance mode */
  785. #define STEST2_800_EXT 0x02 /* Extend REQ/ACK filter 30 to 60ns */
  786. #define STEST2_800_LOW 0x01 /* SCSI low level mode */
  787. #define STEST3_REG_800 0x4f  
  788. #define STEST3_800_TE 0x80 /* Enable active negation */
  789. #define STEST3_800_STR 0x40 /* SCSI FIFO test read */
  790. #define STEST3_800_HSC 0x20 /* Halt SCSI clock */
  791. #define STEST3_800_DSI 0x10 /* Disable single initiator response */
  792. #define STEST3_800_TTM 0x04 /* Time test mode */
  793. #define STEST3_800_CSF 0x02 /* Clear SCSI FIFO */
  794. #define STEST3_800_STW 0x01 /* SCSI FIFO test write */
  795. #define OPTION_PARITY  0x1 /* Enable parity checking */
  796. #define OPTION_TAGGED_QUEUE 0x2 /* Enable SCSI-II tagged queuing */
  797. #define OPTION_700 0x8 /* Always run NCR53c700 scripts */
  798. #define OPTION_INTFLY 0x10 /* Use INTFLY interrupts */
  799. #define OPTION_DEBUG_INTR 0x20 /* Debug interrupts */
  800. #define OPTION_DEBUG_INIT_ONLY 0x40 /* Run initialization code and 
  801.    simple test code, return
  802.    DID_NO_CONNECT if any SCSI
  803.    commands are attempted. */
  804. #define OPTION_DEBUG_READ_ONLY 0x80 /* Return DID_ERROR if any 
  805.    SCSI write is attempted */
  806. #define OPTION_DEBUG_TRACE 0x100 /* Animated trace mode, print 
  807.    each address and instruction 
  808.    executed to debug buffer. */
  809. #define OPTION_DEBUG_SINGLE 0x200 /* stop after executing one 
  810.    instruction */
  811. #define OPTION_SYNCHRONOUS 0x400 /* Enable sync SCSI.  */
  812. #define OPTION_MEMORY_MAPPED 0x800 /* NCR registers have valid 
  813.    memory mapping */
  814. #define OPTION_IO_MAPPED 0x1000  /* NCR registers have valid
  815.      I/O mapping */
  816. #define OPTION_DEBUG_PROBE_ONLY 0x2000  /* Probe only, don't even init */
  817. #define OPTION_DEBUG_TESTS_ONLY 0x4000  /* Probe, init, run selected tests */
  818. #define OPTION_DEBUG_TEST0 0x08000 /* Run test 0 */
  819. #define OPTION_DEBUG_TEST1 0x10000 /* Run test 1 */
  820. #define OPTION_DEBUG_TEST2 0x20000 /* Run test 2 */
  821. #define OPTION_DEBUG_DUMP 0x40000 /* Dump commands */
  822. #define OPTION_DEBUG_TARGET_LIMIT 0x80000 /* Only talk to target+luns specified */
  823. #define OPTION_DEBUG_NCOMMANDS_LIMIT 0x100000 /* Limit the number of commands */
  824. #define OPTION_DEBUG_SCRIPT 0x200000 /* Print when checkpoints are passed */
  825. #define OPTION_DEBUG_FIXUP 0x400000 /* print fixup values */
  826. #define OPTION_DEBUG_DSA 0x800000
  827. #define OPTION_DEBUG_CORRUPTION 0x1000000 /* Detect script corruption */
  828. #define OPTION_DEBUG_SDTR       0x2000000 /* Debug SDTR problem */
  829. #define OPTION_DEBUG_MISMATCH  0x4000000  /* Debug phase mismatches */
  830. #define OPTION_DISCONNECT 0x8000000 /* Allow disconnect */
  831. #define OPTION_DEBUG_DISCONNECT 0x10000000
  832. #define OPTION_ALWAYS_SYNCHRONOUS 0x20000000 /* Negotiate sync. transfers
  833.    on power up */
  834. #define OPTION_DEBUG_QUEUES 0x80000000
  835. #define OPTION_DEBUG_ALLOCATION 0x100000000LL
  836. #define OPTION_DEBUG_SYNCHRONOUS 0x200000000LL /* Sanity check SXFER and 
  837.    SCNTL3 registers */
  838. #define OPTION_NO_ASYNC 0x400000000LL /* Don't automagically send
  839.    SDTR for async transfers when
  840.    we haven't been told to do
  841.    a synchronous transfer. */
  842. #define OPTION_NO_PRINT_RACE 0x800000000LL /* Don't print message when
  843.    the reselect/WAIT DISCONNECT
  844.    race condition hits */
  845. #if !defined(PERM_OPTIONS)
  846. #define PERM_OPTIONS 0
  847. #endif
  848. struct NCR53c7x0_synchronous {
  849.     u32 select_indirect; /* Value used for indirect selection */
  850.     u32 script[8]; /* Size ?? Script used when target is 
  851. reselected */
  852.     unsigned char synchronous_want[5]; /* Per target desired SDTR */
  853. /* 
  854.  * Set_synchronous programs these, select_indirect and current settings after
  855.  * int_debug_should show a match.
  856.  */
  857.     unsigned char sxfer_sanity, scntl3_sanity;
  858. };
  859. #define CMD_FLAG_SDTR  1 /* Initiating synchronous 
  860.    transfer negotiation */
  861. #define CMD_FLAG_WDTR 2 /* Initiating wide transfer
  862.    negotiation */
  863. #define CMD_FLAG_DID_SDTR 4 /* did SDTR */
  864. #define CMD_FLAG_DID_WDTR 8 /* did WDTR */
  865. struct NCR53c7x0_table_indirect {
  866.     u32 count;
  867.     void *address;
  868. };
  869. enum ncr_event { 
  870.     EVENT_NONE = 0,
  871. /* 
  872.  * Order is IMPORTANT, since these must correspond to the event interrupts
  873.  * in 53c7,8xx.scr 
  874.  */
  875.     EVENT_ISSUE_QUEUE = 0x5000000, /* Command was added to issue queue */
  876.     EVENT_START_QUEUE, /* Command moved to start queue */
  877.     EVENT_SELECT, /* Command completed selection */
  878.     EVENT_DISCONNECT, /* Command disconnected */
  879.     EVENT_RESELECT, /* Command reselected */
  880.     EVENT_COMPLETE,         /* Command completed */
  881.     EVENT_IDLE,
  882.     EVENT_SELECT_FAILED,
  883.     EVENT_BEFORE_SELECT,
  884.     EVENT_RESELECT_FAILED
  885. };
  886. struct NCR53c7x0_event {
  887.     enum ncr_event event; /* What type of event */
  888.     unsigned char target;
  889.     unsigned char lun;
  890.     struct timeval time;
  891.     u32 *dsa; /* What's in the DSA register now (virt) */
  892. /* 
  893.  * A few things from that SCSI pid so we know what happened after 
  894.  * the Scsi_Cmnd structure in question may have disappeared.
  895.  */
  896.     unsigned long pid; /* The SCSI PID which caused this 
  897.    event */
  898.     unsigned char cmnd[12];
  899. };
  900. /*
  901.  * Things in the NCR53c7x0_cmd structure are split into two parts :
  902.  *
  903.  * 1.  A fixed portion, for things which are not accessed directly by static NCR
  904.  * code (ie, are referenced only by the Linux side of the driver,
  905.  * or only by dynamically generated code).  
  906.  *
  907.  * 2.  The DSA portion, for things which are accessed directly by static NCR
  908.  * code.
  909.  *
  910.  * This is a little ugly, but it 
  911.  * 1.  Avoids conflicts between the NCR code's picture of the structure, and 
  912.  *  Linux code's idea of what it looks like.
  913.  *
  914.  * 2.  Minimizes the pain in the Linux side of the code needed 
  915.  *  to calculate real dsa locations for things, etc.
  916.  * 
  917.  */
  918. struct NCR53c7x0_cmd {
  919.     void *real; /* Real, unaligned address for
  920.    free function */
  921.     void (* free)(void *, int); /* Command to deallocate; NULL
  922.    for structures allocated with
  923.    scsi_register, etc. */
  924.     Scsi_Cmnd *cmd; /* Associated Scsi_Cmnd 
  925.    structure, Scsi_Cmnd points
  926.    at NCR53c7x0_cmd using 
  927.    host_scribble structure */
  928.     int size; /* scsi_malloc'd size of this 
  929.    structure */
  930.     int flags; /* CMD_* flags */
  931. /*
  932.  * SDTR and WIDE messages are an either/or affair
  933.  * in this message, since we will go into message out and send
  934.  * _the whole mess_ without dropping out of message out to 
  935.  * let the target go into message in after sending the first 
  936.  * message.
  937.  */
  938.     unsigned char select[11]; /* Select message, includes
  939.    IDENTIFY
  940.    (optional) QUEUE TAG
  941.        (optional) SDTR or WDTR
  942.  */
  943.     volatile struct NCR53c7x0_cmd *next; /* Linux maintained lists (free,
  944.     running, eventually finished */
  945.       
  946.     u32 *data_transfer_start; /* Start of data transfer routines */
  947.     u32 *data_transfer_end; /* Address after end of data transfer o
  948.                             routines */
  949. /* 
  950.  * The following three fields were moved from the DSA proper to here
  951.  * since only dynamically generated NCR code refers to them, meaning
  952.  * we don't need dsa_* absolutes, and it is simpler to let the 
  953.  * host code refer to them directly.
  954.  */
  955. /* 
  956.  * HARD CODED : residual and saved_residual need to agree with the sizes
  957.  * used in NCR53c7,8xx.scr.  
  958.  * 
  959.  * FIXME: we want to consider the case where we have odd-length 
  960.  * scatter/gather buffers and a WIDE transfer, in which case 
  961.  * we'll need to use the CHAIN MOVE instruction.  Ick.
  962.  */
  963.     u32 residual[6]; /* Residual data transfer which
  964.    allows pointer code to work
  965.    right.
  966.                              [0-1] : Conditional call to 
  967.                               appropriate other transfer 
  968.                               routine.
  969.                              [2-3] : Residual block transfer
  970.                               instruction.
  971.                              [4-5] : Jump to instruction
  972.                               after splice.
  973.  */
  974.     u32 saved_residual[6];  /* Copy of old residual, so we 
  975.    can get another partial 
  976.    transfer and still recover 
  977.                           */
  978.          
  979.     u32 saved_data_pointer; /* Saved data pointer */
  980.     u32 dsa_next_addr;         /* _Address_ of dsa_next field  
  981.    in this dsa for RISCy 
  982.    style constant. */
  983.     u32 dsa_addr; /* Address of dsa; RISCy style
  984.    constant */
  985.     u32 dsa[0]; /* Variable length (depending
  986.    on host type, number of scatter /
  987.    gather buffers, etc).  */
  988. };
  989. struct NCR53c7x0_break {
  990.     u32 *address, old_instruction[2];
  991.     struct NCR53c7x0_break *next;
  992.     unsigned char old_size; /* Size of old instruction */
  993. };
  994. /* Indicates that the NCR is not executing code */
  995. #define STATE_HALTED 0
  996. /* 
  997.  * Indicates that the NCR is executing the wait for select / reselect 
  998.  * script.  Only used when running NCR53c700 compatible scripts, only 
  999.  * state during which an ABORT is _not_ considered an error condition.
  1000.  */
  1001. #define STATE_WAITING 1
  1002. /* Indicates that the NCR is executing other code. */
  1003. #define STATE_RUNNING 2
  1004. /* 
  1005.  * Indicates that the NCR was being aborted.
  1006.  */
  1007. #define STATE_ABORTING 3
  1008. /* Indicates that the NCR was successfully aborted. */
  1009. #define STATE_ABORTED 4
  1010. /* Indicates that the NCR has been disabled due to a fatal error */
  1011. #define STATE_DISABLED 5
  1012. /* 
  1013.  * Where knowledge of SCSI SCRIPT(tm) specified values are needed 
  1014.  * in an interrupt handler, an interrupt handler exists for each 
  1015.  * different SCSI script so we don't have name space problems.
  1016.  * 
  1017.  * Return values of these handlers are as follows : 
  1018.  */
  1019. #define SPECIFIC_INT_NOTHING  0 /* don't even restart */
  1020. #define SPECIFIC_INT_RESTART 1 /* restart at the next instruction */
  1021. #define SPECIFIC_INT_ABORT 2 /* recoverable error, abort cmd */
  1022. #define SPECIFIC_INT_PANIC 3 /* unrecoverable error, panic */
  1023. #define SPECIFIC_INT_DONE 4 /* normal command completion */
  1024. #define SPECIFIC_INT_BREAK 5 /* break point encountered */
  1025. struct NCR53c7x0_hostdata {
  1026.     int size; /* Size of entire Scsi_Host
  1027.    structure */
  1028.     int board; /* set to board type, useful if 
  1029.    we have host specific things,
  1030.    ie, a general purpose I/O 
  1031.    bit is being used to enable
  1032.    termination, etc. */
  1033.     int chip; /* set to chip type; 700-66 is
  1034.    700-66, rest are last three
  1035.    digits of part number */
  1036.     /*
  1037.      * PCI bus, device, function, only for NCR53c8x0 chips.
  1038.      * pci_valid indicates that the PCI configuration information
  1039.      * is valid, and we can twiddle MAX_LAT, etc. as recommended
  1040.      * for maximum performance in the NCR documentation.
  1041.      */
  1042.     unsigned char pci_bus, pci_device_fn;
  1043.     unsigned pci_valid:1;
  1044.     u32 *dsp; /* dsp to restart with after
  1045.    all stacked interrupts are
  1046.    handled. */
  1047.     unsigned dsp_changed:1; /* Has dsp changed within this
  1048.    set of stacked interrupts ? */
  1049.     unsigned char dstat; /* Most recent value of dstat */
  1050.     unsigned dstat_valid:1;
  1051.     unsigned expecting_iid:1; /* Expect IID interrupt */
  1052.     unsigned expecting_sto:1; /* Expect STO interrupt */
  1053.     
  1054.     /* 
  1055.      * The code stays cleaner if we use variables with function
  1056.      * pointers and offsets that are unique for the different
  1057.      * scripts rather than having a slew of switch(hostdata->chip) 
  1058.      * statements.
  1059.      * 
  1060.      * It also means that the #defines from the SCSI SCRIPTS(tm)
  1061.      * don't have to be visible outside of the script-specific
  1062.      * instructions, preventing name space pollution.
  1063.      */
  1064.     void (* init_fixup)(struct Scsi_Host *host);
  1065.     void (* init_save_regs)(struct Scsi_Host *host);
  1066.     void (* dsa_fixup)(struct NCR53c7x0_cmd *cmd);
  1067.     void (* soft_reset)(struct Scsi_Host *host);
  1068.     int (* run_tests)(struct Scsi_Host *host);
  1069.     /*
  1070.      * Called when DSTAT_SIR is set, indicating an interrupt generated
  1071.      * by the INT instruction, where values are unique for each SCSI
  1072.      * script.  Should return one of the SPEC_* values.
  1073.      */
  1074.     int (* dstat_sir_intr)(struct Scsi_Host *host, struct NCR53c7x0_cmd *cmd);
  1075.     int dsa_len; /* Size of DSA structure */
  1076.     /*
  1077.      * Location of DSA fields for the SCSI SCRIPT corresponding to this 
  1078.      * chip.  
  1079.      */
  1080.     s32 dsa_start;
  1081.     s32 dsa_end;
  1082.     s32 dsa_next;
  1083.     s32 dsa_prev;
  1084.     s32 dsa_cmnd;
  1085.     s32 dsa_select;
  1086.     s32 dsa_msgout;
  1087.     s32 dsa_cmdout;
  1088.     s32 dsa_dataout;
  1089.     s32 dsa_datain;
  1090.     s32 dsa_msgin;
  1091.     s32 dsa_msgout_other;
  1092.     s32 dsa_write_sync;
  1093.     s32 dsa_write_resume;
  1094.     s32 dsa_check_reselect;
  1095.     s32 dsa_status;
  1096.     s32 dsa_saved_pointer;
  1097.     s32 dsa_jump_dest;
  1098.     /* 
  1099.      * Important entry points that generic fixup code needs
  1100.      * to know about, fixed up.
  1101.      */
  1102.     s32 E_accept_message;
  1103.     s32 E_command_complete;
  1104.     s32 E_data_transfer;
  1105.     s32 E_dsa_code_template;
  1106.     s32 E_dsa_code_template_end;
  1107.     s32 E_end_data_transfer;
  1108.     s32 E_msg_in;
  1109.     s32 E_initiator_abort;
  1110.     s32 E_other_transfer;
  1111.     s32 E_other_in;
  1112.     s32 E_other_out;
  1113.     s32 E_target_abort;
  1114.     s32 E_debug_break;
  1115.     s32 E_reject_message;
  1116.     s32 E_respond_message;
  1117.     s32 E_select;
  1118.     s32 E_select_msgout;
  1119.     s32 E_test_0;
  1120.     s32 E_test_1;
  1121.     s32 E_test_2;
  1122.     s32 E_test_3;
  1123.     s32 E_dsa_zero;
  1124.     s32 E_cmdout_cmdout;
  1125.     s32 E_wait_reselect;
  1126.     s32 E_dsa_code_begin;
  1127.     long long options; /* Bitfielded set of options enabled */
  1128.     volatile u32 test_completed; /* Test completed */
  1129.     int test_running; /* Test currently running */
  1130.     s32 test_source;
  1131.     volatile s32 test_dest;
  1132.     volatile int state; /* state of driver, only used for 
  1133.    OPTION_700 */
  1134.     unsigned char  dmode; /* 
  1135.  * set to the address of the DMODE 
  1136.  * register for this chip.
  1137.  */
  1138.     unsigned char istat; /* 
  1139.                           * set to the address of the ISTAT 
  1140.                           * register for this chip.
  1141.                           */
  1142.   
  1143.     int scsi_clock; /* 
  1144.  * SCSI clock in HZ. 0 may be used 
  1145.  * for unknown, although this will
  1146.  * disable synchronous negotiation.
  1147.  */
  1148.     volatile int intrs; /* Number of interrupts */
  1149.     volatile int resets; /* Number of SCSI resets */
  1150.     unsigned char saved_dmode;
  1151.     unsigned char saved_ctest4;
  1152.     unsigned char saved_ctest7;
  1153.     unsigned char saved_dcntl;
  1154.     unsigned char saved_scntl3;
  1155.     unsigned char this_id_mask;
  1156.     /* Debugger information */
  1157.     struct NCR53c7x0_break *breakpoints, /* Linked list of all break points */
  1158. *breakpoint_current; /* Current breakpoint being stepped 
  1159.    through, NULL if we are running 
  1160.    normally. */
  1161. #ifdef NCR_DEBUG
  1162.     int debug_size; /* Size of debug buffer */
  1163.     volatile int debug_count; /* Current data count */
  1164.     volatile char *debug_buf; /* Output ring buffer */
  1165.     volatile char *debug_write; /* Current write pointer */
  1166.     volatile char *debug_read; /* Current read pointer */
  1167. #endif /* def NCR_DEBUG */
  1168.     /* XXX - primitive debugging junk, remove when working ? */
  1169.     int debug_print_limit; /* Number of commands to print
  1170.    out exhaustive debugging
  1171.    information for if 
  1172.    OPTION_DEBUG_DUMP is set */ 
  1173.     unsigned char debug_lun_limit[16]; /* If OPTION_DEBUG_TARGET_LIMIT
  1174.    set, puke if commands are sent
  1175.    to other target/lun combinations */
  1176.     int debug_count_limit; /* Number of commands to execute
  1177.    before puking to limit debugging 
  1178.    output */
  1179.     
  1180.     volatile unsigned idle:1; /* set to 1 if idle */
  1181.     /* 
  1182.      * Table of synchronous+wide transfer parameters set on a per-target
  1183.      * basis.
  1184.      */
  1185.     
  1186.     volatile struct NCR53c7x0_synchronous sync[16];
  1187.     volatile Scsi_Cmnd *issue_queue;
  1188. /* waiting to be issued by
  1189.    Linux driver */
  1190.     volatile struct NCR53c7x0_cmd *running_list;
  1191. /* commands running, maintained
  1192.    by Linux driver */
  1193.     volatile struct NCR53c7x0_cmd *curr; /* currently connected 
  1194.    nexus, ONLY valid for
  1195.    NCR53c700/NCR53c700-66
  1196.  */
  1197.     volatile struct NCR53c7x0_cmd *spare; /* pointer to spare,
  1198.                                  allocated at probe time,
  1199.                                  which we can use for 
  1200.    initialization */
  1201.     volatile struct NCR53c7x0_cmd *free;
  1202.     int max_cmd_size; /* Maximum size of NCR53c7x0_cmd
  1203.         based on number of 
  1204.    scatter/gather segments, etc.
  1205.    */
  1206.     volatile int num_cmds; /* Number of commands 
  1207.    allocated */
  1208.     volatile int extra_allocate;
  1209.     volatile unsigned char cmd_allocated[16]; /* Have we allocated commands
  1210.    for this target yet?  If not,
  1211.    do so ASAP */
  1212.     volatile unsigned char busy[16][8];      /* number of commands 
  1213.    executing on each target
  1214.                                */
  1215.     /* 
  1216.      * Eventually, I'll switch to a coroutine for calling 
  1217.      * cmd->done(cmd), etc. so that we can overlap interrupt
  1218.      * processing with this code for maximum performance.
  1219.      */
  1220.     
  1221.     volatile struct NCR53c7x0_cmd *finished_queue;
  1222.     /* Shared variables between SCRIPT and host driver */
  1223.     volatile u32 *schedule; /* Array of JUMPs to dsa_begin
  1224.    routines of various DSAs.  
  1225.    When not in use, replace
  1226.    with jump to next slot */
  1227.     volatile unsigned char msg_buf[16]; /* buffer for messages
  1228.    other than the command
  1229.    complete message */
  1230.     /* Per-target default synchronous and WIDE messages */
  1231.     volatile unsigned char synchronous_want[16][5];
  1232.     volatile unsigned char wide_want[16][4];
  1233.     /* Bit fielded set of targets we want to speak synchronously with */ 
  1234.     volatile u16 initiate_sdtr;
  1235.     /* Bit fielded set of targets we want to speak wide with */
  1236.     volatile u16 initiate_wdtr;
  1237.     /* Bit fielded list of targets we've talked to. */
  1238.     volatile u16 talked_to;
  1239.     /* Array of bit-fielded lun lists that we need to request_sense */
  1240.     volatile unsigned char request_sense[16];
  1241.     u32 addr_reconnect_dsa_head; /* RISCy style constant,
  1242.    address of following */
  1243.     volatile u32 reconnect_dsa_head;
  1244.     /* Data identifying nexus we are trying to match during reselection */
  1245.     volatile unsigned char reselected_identify; /* IDENTIFY message */
  1246.     volatile unsigned char reselected_tag; /* second byte of queue tag 
  1247.    message or 0 */
  1248.     /* These were static variables before we moved them */
  1249.     s32 NCR53c7xx_zero;
  1250.     s32 NCR53c7xx_sink;
  1251.     u32 NOP_insn;
  1252.     char NCR53c7xx_msg_reject;
  1253.     char NCR53c7xx_msg_abort;
  1254.     char NCR53c7xx_msg_nop;
  1255.     volatile int event_size, event_index;
  1256.     volatile struct NCR53c7x0_event *events;
  1257.     /* If we need to generate code to kill off the currently connected 
  1258.        command, this is where we do it. Should have a BMI instruction
  1259.        to source or sink the current data, followed by a JUMP
  1260.        to abort_connected */
  1261.     u32 *abort_script;
  1262.     int script_count; /* Size of script in words */
  1263.     u32 script[0]; /* Relocated SCSI script */
  1264. };
  1265. #define IRQ_NONE 255
  1266. #define DMA_NONE 255
  1267. #define IRQ_AUTO 254
  1268. #define DMA_AUTO 254
  1269. #define BOARD_GENERIC 0
  1270. #define NCR53c7x0_insn_size(insn)
  1271.     (((insn) & DCMD_TYPE_MASK) == DCMD_TYPE_MMI ? 3 : 2)
  1272.     
  1273. #define NCR53c7x0_local_declare()
  1274.     volatile unsigned char *NCR53c7x0_address_memory;
  1275.     unsigned int NCR53c7x0_address_io;
  1276.     int NCR53c7x0_memory_mapped
  1277. #define NCR53c7x0_local_setup(host)
  1278.     NCR53c7x0_address_memory = (void *) (host)->base;
  1279.     NCR53c7x0_address_io = (unsigned int) (host)->io_port;
  1280.     NCR53c7x0_memory_mapped = ((struct NCR53c7x0_hostdata *) 
  1281. host->hostdata)-> options & OPTION_MEMORY_MAPPED 
  1282. #define NCR53c7x0_read8(address) 
  1283.     (NCR53c7x0_memory_mapped ? 
  1284. (unsigned int)readb(NCR53c7x0_address_memory + (address)) :
  1285. inb(NCR53c7x0_address_io + (address)))
  1286. #define NCR53c7x0_read16(address) 
  1287.     (NCR53c7x0_memory_mapped ? 
  1288. (unsigned int)readw(NCR53c7x0_address_memory + (address)) :
  1289. inw(NCR53c7x0_address_io + (address)))
  1290. #define NCR53c7x0_read32(address) 
  1291.     (NCR53c7x0_memory_mapped ? 
  1292. (unsigned int) readl(NCR53c7x0_address_memory + (address)) : 
  1293. inl(NCR53c7x0_address_io + (address)))
  1294. #define NCR53c7x0_write8(address,value) 
  1295.     (NCR53c7x0_memory_mapped ? 
  1296.      ({writeb((value), NCR53c7x0_address_memory + (address)); mb();}) :
  1297. outb((value), NCR53c7x0_address_io + (address)))
  1298. #define NCR53c7x0_write16(address,value) 
  1299.     (NCR53c7x0_memory_mapped ? 
  1300.      ({writew((value), NCR53c7x0_address_memory + (address)); mb();}) :
  1301. outw((value), NCR53c7x0_address_io + (address)))
  1302. #define NCR53c7x0_write32(address,value) 
  1303.     (NCR53c7x0_memory_mapped ? 
  1304.      ({writel((value), NCR53c7x0_address_memory + (address)); mb();}) :
  1305. outl((value), NCR53c7x0_address_io + (address)))
  1306. /* Patch arbitrary 32 bit words in the script */
  1307. #define patch_abs_32(script, offset, symbol, value)
  1308.      for (i = 0; i < (sizeof (A_##symbol##_used) / sizeof 
  1309.          (u32)); ++i) {
  1310.     (script)[A_##symbol##_used[i] - (offset)] += (value);
  1311.     if (hostdata->options & OPTION_DEBUG_FIXUP) 
  1312.       printk("scsi%d : %s reference %d at 0x%x in %s is now 0x%xn",
  1313. host->host_no, #symbol, i, A_##symbol##_used[i] - 
  1314. (int)(offset), #script, (script)[A_##symbol##_used[i] -
  1315. (offset)]);
  1316.      }
  1317. /* Patch read/write instruction immediate field */
  1318. #define patch_abs_rwri_data(script, offset, symbol, value)
  1319.      for (i = 0; i < (sizeof (A_##symbol##_used) / sizeof 
  1320.          (u32)); ++i)
  1321.          (script)[A_##symbol##_used[i] - (offset)] =
  1322.      ((script)[A_##symbol##_used[i] - (offset)] & 
  1323.      ~DBC_RWRI_IMMEDIATE_MASK) | 
  1324.           (((value) << DBC_RWRI_IMMEDIATE_SHIFT) &
  1325.  DBC_RWRI_IMMEDIATE_MASK)
  1326. /* Patch transfer control instruction data field */
  1327. #define patch_abs_tci_data(script, offset, symbol, value)         
  1328.      for (i = 0; i < (sizeof (A_##symbol##_used) / sizeof 
  1329.          (u32)); ++i)
  1330.          (script)[A_##symbol##_used[i] - (offset)] =
  1331.      ((script)[A_##symbol##_used[i] - (offset)] & 
  1332.      ~DBC_TCI_DATA_MASK) | 
  1333.           (((value) << DBC_TCI_DATA_SHIFT) &
  1334.  DBC_TCI_DATA_MASK)
  1335. /* Patch field in dsa structure (assignment should be +=?) */
  1336. #define patch_dsa_32(dsa, symbol, word, value)
  1337. {
  1338. (dsa)[(hostdata->symbol - hostdata->dsa_start) / sizeof(u32)
  1339.     + (word)] = (value);
  1340. if (hostdata->options & OPTION_DEBUG_DSA)
  1341.     printk("scsi : dsa %s symbol %s(%d) word %d now 0x%xn",
  1342. #dsa, #symbol, hostdata->symbol, 
  1343. (word), (u32) le32_to_cpu(value));
  1344. }
  1345. /* Paranoid people could use panic() here. */
  1346. #define FATAL(host) shutdown((host));
  1347. #endif /* NCR53c7x0_C */
  1348. #endif /* NCR53c7x0_H */