in2000.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. * in2000.h - Linux device driver definitions for the
  3. * Always IN2000 ISA SCSI card.
  4. *
  5. * IMPORTANT: This file is for version 1.33 - 26/Aug/1998
  6. *
  7. * Copyright (c) 1996 John Shifflett, GeoLog Consulting
  8. * john@geolog.com
  9. * jshiffle@netcom.com
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. */
  22. #ifndef IN2000_H
  23. #define IN2000_H
  24. #include <asm/io.h>
  25. #define PROC_INTERFACE /* add code for /proc/scsi/in2000/xxx interface */
  26. #ifdef PROC_INTERFACE
  27. #define PROC_STATISTICS /* add code for keeping various real time stats */
  28. #endif
  29. #define SYNC_DEBUG /* extra info on sync negotiation printed */
  30. #define DEBUGGING_ON /* enable command-line debugging bitmask */
  31. #define DEBUG_DEFAULTS 0 /* default bitmask - change from command-line */
  32. #ifdef __i386__
  33. #define FAST_READ_IO /* No problems with these on my machine */
  34. #define FAST_WRITE_IO
  35. #endif
  36. #ifdef DEBUGGING_ON
  37. #define DB(f,a) if (hostdata->args & (f)) a;
  38. #define CHECK_NULL(p,s) /* if (!(p)) {printk("\n"); while (1) printk("NP:%s\r",(s));} */
  39. #else
  40. #define DB(f,a)
  41. #define CHECK_NULL(p,s)
  42. #endif
  43. #define uchar unsigned char
  44. #define read1_io(a) (inb(hostdata->io_base+(a)))
  45. #define read2_io(a) (inw(hostdata->io_base+(a)))
  46. #define write1_io(b,a) (outb((b),hostdata->io_base+(a)))
  47. #define write2_io(w,a) (outw((w),hostdata->io_base+(a)))
  48. #ifdef __i386__
  49. /* These inline assembly defines are derived from a patch
  50. * sent to me by Bill Earnest. He's done a lot of very
  51. * valuable thinking, testing, and coding during his effort
  52. * to squeeze more speed out of this driver. I really think
  53. * that we are doing IO at close to the maximum now with
  54. * the fifo. (And yes, insw uses 'edi' while outsw uses
  55. * 'esi'. Thanks Bill!)
  56. */
  57. #define FAST_READ2_IO() \
  58. ({ \
  59. int __dummy_1,__dummy_2; \
  60. __asm__ __volatile__ ("\n \
  61. cld \n \
  62. orl %%ecx, %%ecx \n \
  63. jz 1f \n \
  64. rep \n \
  65. insw (%%dx),%%es:(%%edi) \n \
  66. 1: " \
  67. : "=D" (sp) ,"=c" (__dummy_1) ,"=d" (__dummy_2) /* output */ \
  68. : "2" (f), "0" (sp), "1" (i) /* input */ \
  69. ); /* trashed */ \
  70. })
  71. #define FAST_WRITE2_IO() \
  72. ({ \
  73. int __dummy_1,__dummy_2; \
  74. __asm__ __volatile__ ("\n \
  75. cld \n \
  76. orl %%ecx, %%ecx \n \
  77. jz 1f \n \
  78. rep \n \
  79. outsw %%ds:(%%esi),(%%dx) \n \
  80. 1: " \
  81. : "=S" (sp) ,"=c" (__dummy_1) ,"=d" (__dummy_2)/* output */ \
  82. : "2" (f), "0" (sp), "1" (i) /* input */ \
  83. ); /* trashed */ \
  84. })
  85. #endif
  86. /* IN2000 io_port offsets */
  87. #define IO_WD_ASR 0x00 /* R - 3393 auxstat reg */
  88. #define ASR_INT 0x80
  89. #define ASR_LCI 0x40
  90. #define ASR_BSY 0x20
  91. #define ASR_CIP 0x10
  92. #define ASR_PE 0x02
  93. #define ASR_DBR 0x01
  94. #define IO_WD_ADDR 0x00 /* W - 3393 address reg */
  95. #define IO_WD_DATA 0x01 /* R/W - rest of 3393 regs */
  96. #define IO_FIFO 0x02 /* R/W - in2000 dual-port fifo (16 bits) */
  97. #define IN2000_FIFO_SIZE 2048 /* fifo capacity in bytes */
  98. #define IO_CARD_RESET 0x03 /* W - in2000 start master reset */
  99. #define IO_FIFO_COUNT 0x04 /* R - in2000 fifo counter */
  100. #define IO_FIFO_WRITE 0x05 /* W - clear fifo counter, start write */
  101. #define IO_FIFO_READ 0x07 /* W - start fifo read */
  102. #define IO_LED_OFF 0x08 /* W - turn off in2000 activity LED */
  103. #define IO_SWITCHES 0x08 /* R - read in2000 dip switch */
  104. #define SW_ADDR0 0x01 /* bit 0 = bit 0 of index to io addr */
  105. #define SW_ADDR1 0x02 /* bit 1 = bit 1 of index io addr */
  106. #define SW_DISINT 0x04 /* bit 2 true if ints disabled */
  107. #define SW_INT0 0x08 /* bit 3 = bit 0 of index to interrupt */
  108. #define SW_INT1 0x10 /* bit 4 = bit 1 of index to interrupt */
  109. #define SW_INT_SHIFT 3 /* shift right this amount to right justify int bits */
  110. #define SW_SYNC_DOS5 0x20 /* bit 5 used by Always BIOS */
  111. #define SW_FLOPPY 0x40 /* bit 6 true if floppy enabled */
  112. #define SW_BIT7 0x80 /* bit 7 hardwired true (ground) */
  113. #define IO_LED_ON 0x09 /* W - turn on in2000 activity LED */
  114. #define IO_HARDWARE 0x0a /* R - read in2000 hardware rev, stop reset */
  115. #define IO_INTR_MASK 0x0c /* W - in2000 interrupt mask reg */
  116. #define IMASK_WD 0x01 /* WD33c93 interrupt mask */
  117. #define IMASK_FIFO 0x02 /* FIFO interrupt mask */
  118. /* wd register names */
  119. #define WD_OWN_ID 0x00
  120. #define WD_CONTROL 0x01
  121. #define WD_TIMEOUT_PERIOD 0x02
  122. #define WD_CDB_1 0x03
  123. #define WD_CDB_2 0x04
  124. #define WD_CDB_3 0x05
  125. #define WD_CDB_4 0x06
  126. #define WD_CDB_5 0x07
  127. #define WD_CDB_6 0x08
  128. #define WD_CDB_7 0x09
  129. #define WD_CDB_8 0x0a
  130. #define WD_CDB_9 0x0b
  131. #define WD_CDB_10 0x0c
  132. #define WD_CDB_11 0x0d
  133. #define WD_CDB_12 0x0e
  134. #define WD_TARGET_LUN 0x0f
  135. #define WD_COMMAND_PHASE 0x10
  136. #define WD_SYNCHRONOUS_TRANSFER 0x11
  137. #define WD_TRANSFER_COUNT_MSB 0x12
  138. #define WD_TRANSFER_COUNT 0x13
  139. #define WD_TRANSFER_COUNT_LSB 0x14
  140. #define WD_DESTINATION_ID 0x15
  141. #define WD_SOURCE_ID 0x16
  142. #define WD_SCSI_STATUS 0x17
  143. #define WD_COMMAND 0x18
  144. #define WD_DATA 0x19
  145. #define WD_QUEUE_TAG 0x1a
  146. #define WD_AUXILIARY_STATUS 0x1f
  147. /* WD commands */
  148. #define WD_CMD_RESET 0x00
  149. #define WD_CMD_ABORT 0x01
  150. #define WD_CMD_ASSERT_ATN 0x02
  151. #define WD_CMD_NEGATE_ACK 0x03
  152. #define WD_CMD_DISCONNECT 0x04
  153. #define WD_CMD_RESELECT 0x05
  154. #define WD_CMD_SEL_ATN 0x06
  155. #define WD_CMD_SEL 0x07
  156. #define WD_CMD_SEL_ATN_XFER 0x08
  157. #define WD_CMD_SEL_XFER 0x09
  158. #define WD_CMD_RESEL_RECEIVE 0x0a
  159. #define WD_CMD_RESEL_SEND 0x0b
  160. #define WD_CMD_WAIT_SEL_RECEIVE 0x0c
  161. #define WD_CMD_TRANS_ADDR 0x18
  162. #define WD_CMD_TRANS_INFO 0x20
  163. #define WD_CMD_TRANSFER_PAD 0x21
  164. #define WD_CMD_SBT_MODE 0x80
  165. /* SCSI Bus Phases */
  166. #define PHS_DATA_OUT 0x00
  167. #define PHS_DATA_IN 0x01
  168. #define PHS_COMMAND 0x02
  169. #define PHS_STATUS 0x03
  170. #define PHS_MESS_OUT 0x06
  171. #define PHS_MESS_IN 0x07
  172. /* Command Status Register definitions */
  173. /* reset state interrupts */
  174. #define CSR_RESET 0x00
  175. #define CSR_RESET_AF 0x01
  176. /* successful completion interrupts */
  177. #define CSR_RESELECT 0x10
  178. #define CSR_SELECT 0x11
  179. #define CSR_SEL_XFER_DONE 0x16
  180. #define CSR_XFER_DONE 0x18
  181. /* paused or aborted interrupts */
  182. #define CSR_MSGIN 0x20
  183. #define CSR_SDP 0x21
  184. #define CSR_SEL_ABORT 0x22
  185. #define CSR_RESEL_ABORT 0x25
  186. #define CSR_RESEL_ABORT_AM 0x27
  187. #define CSR_ABORT 0x28
  188. /* terminated interrupts */
  189. #define CSR_INVALID 0x40
  190. #define CSR_UNEXP_DISC 0x41
  191. #define CSR_TIMEOUT 0x42
  192. #define CSR_PARITY 0x43
  193. #define CSR_PARITY_ATN 0x44
  194. #define CSR_BAD_STATUS 0x45
  195. #define CSR_UNEXP 0x48
  196. /* service required interrupts */
  197. #define CSR_RESEL 0x80
  198. #define CSR_RESEL_AM 0x81
  199. #define CSR_DISC 0x85
  200. #define CSR_SRV_REQ 0x88
  201. /* Own ID/CDB Size register */
  202. #define OWNID_EAF 0x08
  203. #define OWNID_EHP 0x10
  204. #define OWNID_RAF 0x20
  205. #define OWNID_FS_8 0x00
  206. #define OWNID_FS_12 0x40
  207. #define OWNID_FS_16 0x80
  208. /* Control register */
  209. #define CTRL_HSP 0x01
  210. #define CTRL_HA 0x02
  211. #define CTRL_IDI 0x04
  212. #define CTRL_EDI 0x08
  213. #define CTRL_HHP 0x10
  214. #define CTRL_POLLED 0x00
  215. #define CTRL_BURST 0x20
  216. #define CTRL_BUS 0x40
  217. #define CTRL_DMA 0x80
  218. /* Timeout Period register */
  219. #define TIMEOUT_PERIOD_VALUE 20 /* results in 200 ms. */
  220. /* Synchronous Transfer Register */
  221. #define STR_FSS 0x80
  222. /* Destination ID register */
  223. #define DSTID_DPD 0x40
  224. #define DATA_OUT_DIR 0
  225. #define DATA_IN_DIR 1
  226. #define DSTID_SCC 0x80
  227. /* Source ID register */
  228. #define SRCID_MASK 0x07
  229. #define SRCID_SIV 0x08
  230. #define SRCID_DSP 0x20
  231. #define SRCID_ES 0x40
  232. #define SRCID_ER 0x80
  233. #define ILLEGAL_STATUS_BYTE 0xff
  234. #define DEFAULT_SX_PER 500 /* (ns) fairly safe */
  235. #define DEFAULT_SX_OFF 0 /* aka async */
  236. #define OPTIMUM_SX_PER 252 /* (ns) best we can do (mult-of-4) */
  237. #define OPTIMUM_SX_OFF 12 /* size of in2000 fifo */
  238. struct sx_period {
  239. unsigned int period_ns;
  240. uchar reg_value;
  241. };
  242. struct IN2000_hostdata {
  243. struct Scsi_Host *next;
  244. uchar chip; /* what kind of wd33c93 chip? */
  245. uchar microcode; /* microcode rev if 'B' */
  246. unsigned short io_base; /* IO port base */
  247. unsigned int dip_switch; /* dip switch settings */
  248. unsigned int hrev; /* hardware revision of card */
  249. volatile uchar busy[8]; /* index = target, bit = lun */
  250. volatile Scsi_Cmnd *input_Q; /* commands waiting to be started */
  251. volatile Scsi_Cmnd *selecting; /* trying to select this command */
  252. volatile Scsi_Cmnd *connected; /* currently connected command */
  253. volatile Scsi_Cmnd *disconnected_Q;/* commands waiting for reconnect */
  254. uchar state; /* what we are currently doing */
  255. uchar fifo; /* what the FIFO is up to */
  256. uchar level2; /* extent to which Level-2 commands are used */
  257. uchar disconnect; /* disconnect/reselect policy */
  258. unsigned int args; /* set from command-line argument */
  259. uchar incoming_msg[8]; /* filled during message_in phase */
  260. int incoming_ptr; /* mainly used with EXTENDED messages */
  261. uchar outgoing_msg[8]; /* send this during next message_out */
  262. int outgoing_len; /* length of outgoing message */
  263. unsigned int default_sx_per; /* default transfer period for SCSI bus */
  264. uchar sync_xfer[8]; /* sync_xfer reg settings per target */
  265. uchar sync_stat[8]; /* status of sync negotiation per target */
  266. uchar sync_off; /* bit mask: don't use sync with these targets */
  267. #ifdef PROC_INTERFACE
  268. uchar proc; /* bit mask: what's in proc output */
  269. #ifdef PROC_STATISTICS
  270. unsigned long cmd_cnt[8]; /* # of commands issued per target */
  271. unsigned long int_cnt; /* # of interrupts serviced */
  272. unsigned long disc_allowed_cnt[8]; /* # of disconnects allowed per target */
  273. unsigned long disc_done_cnt[8]; /* # of disconnects done per target*/
  274. #endif
  275. #endif
  276. };
  277. /* defines for hostdata->chip */
  278. #define C_WD33C93 0
  279. #define C_WD33C93A 1
  280. #define C_WD33C93B 2
  281. #define C_UNKNOWN_CHIP 100
  282. /* defines for hostdata->state */
  283. #define S_UNCONNECTED 0
  284. #define S_SELECTING 1
  285. #define S_RUNNING_LEVEL2 2
  286. #define S_CONNECTED 3
  287. #define S_PRE_TMP_DISC 4
  288. #define S_PRE_CMP_DISC 5
  289. /* defines for hostdata->fifo */
  290. #define FI_FIFO_UNUSED 0
  291. #define FI_FIFO_READING 1
  292. #define FI_FIFO_WRITING 2
  293. /* defines for hostdata->level2 */
  294. /* NOTE: only the first 3 are trustworthy at this point -
  295. * having trouble when more than 1 device is reading/writing
  296. * at the same time...
  297. */
  298. #define L2_NONE 0 /* no combination commands - we get lots of ints */
  299. #define L2_SELECT 1 /* start with SEL_ATN_XFER, but never resume it */
  300. #define L2_BASIC 2 /* resume after STATUS ints & RDP messages */
  301. #define L2_DATA 3 /* resume after DATA_IN/OUT ints */
  302. #define L2_MOST 4 /* resume after anything except a RESELECT int */
  303. #define L2_RESELECT 5 /* resume after everything, including RESELECT ints */
  304. #define L2_ALL 6 /* always resume */
  305. /* defines for hostdata->disconnect */
  306. #define DIS_NEVER 0
  307. #define DIS_ADAPTIVE 1
  308. #define DIS_ALWAYS 2
  309. /* defines for hostdata->args */
  310. #define DB_TEST 1<<0
  311. #define DB_FIFO 1<<1
  312. #define DB_QUEUE_COMMAND 1<<2
  313. #define DB_EXECUTE 1<<3
  314. #define DB_INTR 1<<4
  315. #define DB_TRANSFER 1<<5
  316. #define DB_MASK 0x3f
  317. #define A_NO_SCSI_RESET 1<<15
  318. /* defines for hostdata->sync_xfer[] */
  319. #define SS_UNSET 0
  320. #define SS_FIRST 1
  321. #define SS_WAITING 2
  322. #define SS_SET 3
  323. /* defines for hostdata->proc */
  324. #define PR_VERSION 1<<0
  325. #define PR_INFO 1<<1
  326. #define PR_STATISTICS 1<<2
  327. #define PR_CONNECTED 1<<3
  328. #define PR_INPUTQ 1<<4
  329. #define PR_DISCQ 1<<5
  330. #define PR_TEST 1<<6
  331. #define PR_STOP 1<<7
  332. # include <linux/init.h>
  333. # include <linux/spinlock.h>
  334. # define in2000__INITFUNC(function) __initfunc(function)
  335. # define in2000__INIT __init
  336. # define in2000__INITDATA __initdata
  337. # define CLISPIN_LOCK(host,flags) spin_lock_irqsave(host->host_lock, flags)
  338. # define CLISPIN_UNLOCK(host,flags) spin_unlock_irqrestore(host->host_lock, \
  339. flags)
  340. static int in2000_detect(struct scsi_host_template *) in2000__INIT;
  341. static int in2000_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
  342. static int in2000_abort(Scsi_Cmnd *);
  343. static void in2000_setup(char *, int *) in2000__INIT;
  344. static int in2000_biosparam(struct scsi_device *, struct block_device *,
  345. sector_t, int *);
  346. static int in2000_bus_reset(Scsi_Cmnd *);
  347. #define IN2000_CAN_Q 16
  348. #define IN2000_SG SG_ALL
  349. #define IN2000_CPL 2
  350. #define IN2000_HOST_ID 7
  351. #endif /* IN2000_H */