nsp32.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * Workbit NinjaSCSI-32Bi/UDE PCI/CardBus SCSI Host Bus Adapter driver
  3. * Basic data header
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef _NSP32_H
  16. #define _NSP32_H
  17. //#define NSP32_DEBUG 9
  18. /*
  19. * VENDOR/DEVICE ID
  20. */
  21. #define PCI_VENDOR_ID_IODATA 0x10fc
  22. #define PCI_VENDOR_ID_WORKBIT 0x1145
  23. #define PCI_DEVICE_ID_NINJASCSI_32BI_CBSC_II 0x0005
  24. #define PCI_DEVICE_ID_NINJASCSI_32BI_KME 0xf007
  25. #define PCI_DEVICE_ID_NINJASCSI_32BI_WBT 0x8007
  26. #define PCI_DEVICE_ID_WORKBIT_STANDARD 0xf010
  27. #define PCI_DEVICE_ID_WORKBIT_DUALEDGE 0xf011
  28. #define PCI_DEVICE_ID_NINJASCSI_32BI_LOGITEC 0xf012
  29. #define PCI_DEVICE_ID_NINJASCSI_32BIB_LOGITEC 0xf013
  30. #define PCI_DEVICE_ID_NINJASCSI_32UDE_MELCO 0xf015
  31. #define PCI_DEVICE_ID_NINJASCSI_32UDE_MELCO_II 0x8009
  32. /*
  33. * MODEL
  34. */
  35. enum {
  36. MODEL_IODATA = 0,
  37. MODEL_KME = 1,
  38. MODEL_WORKBIT = 2,
  39. MODEL_LOGITEC = 3,
  40. MODEL_PCI_WORKBIT = 4,
  41. MODEL_PCI_LOGITEC = 5,
  42. MODEL_PCI_MELCO = 6,
  43. };
  44. static char * nsp32_model[] = {
  45. "I-O DATA CBSC-II CardBus card",
  46. "KME SCSI CardBus card",
  47. "Workbit duo SCSI CardBus card",
  48. "Logitec CardBus card with external ROM",
  49. "Workbit / I-O DATA PCI card",
  50. "Logitec PCI card with external ROM",
  51. "Melco CardBus/PCI card with external ROM",
  52. };
  53. /*
  54. * SCSI Generic Definitions
  55. */
  56. #define EXTENDED_SDTR_LEN 0x03
  57. /* Little Endian */
  58. typedef u32 u32_le;
  59. typedef u16 u16_le;
  60. /*
  61. * MACRO
  62. */
  63. #define BIT(x) (1UL << (x))
  64. /*
  65. * BASIC Definitions
  66. */
  67. #ifndef TRUE
  68. # define TRUE 1
  69. #endif
  70. #ifndef FALSE
  71. # define FALSE 0
  72. #endif
  73. #define ASSERT 1
  74. #define NEGATE 0
  75. /*******************/
  76. /* normal register */
  77. /*******************/
  78. /*
  79. * Don't access below register with Double Word:
  80. * +00, +04, +08, +0c, +64, +80, +84, +88, +90, +c4, +c8, +cc, +d0.
  81. */
  82. #define IRQ_CONTROL 0x00 /* BASE+00, W, W */
  83. #define IRQ_STATUS 0x00 /* BASE+00, W, R */
  84. # define IRQSTATUS_LATCHED_MSG BIT(0)
  85. # define IRQSTATUS_LATCHED_IO BIT(1)
  86. # define IRQSTATUS_LATCHED_CD BIT(2)
  87. # define IRQSTATUS_LATCHED_BUS_FREE BIT(3)
  88. # define IRQSTATUS_RESELECT_OCCUER BIT(4)
  89. # define IRQSTATUS_PHASE_CHANGE_IRQ BIT(5)
  90. # define IRQSTATUS_SCSIRESET_IRQ BIT(6)
  91. # define IRQSTATUS_TIMER_IRQ BIT(7)
  92. # define IRQSTATUS_FIFO_SHLD_IRQ BIT(8)
  93. # define IRQSTATUS_PCI_IRQ BIT(9)
  94. # define IRQSTATUS_BMCNTERR_IRQ BIT(10)
  95. # define IRQSTATUS_AUTOSCSI_IRQ BIT(11)
  96. # define PCI_IRQ_MASK BIT(12)
  97. # define TIMER_IRQ_MASK BIT(13)
  98. # define FIFO_IRQ_MASK BIT(14)
  99. # define SCSI_IRQ_MASK BIT(15)
  100. # define IRQ_CONTROL_ALL_IRQ_MASK (PCI_IRQ_MASK | \
  101. TIMER_IRQ_MASK | \
  102. FIFO_IRQ_MASK | \
  103. SCSI_IRQ_MASK )
  104. # define IRQSTATUS_ANY_IRQ (IRQSTATUS_RESELECT_OCCUER | \
  105. IRQSTATUS_PHASE_CHANGE_IRQ | \
  106. IRQSTATUS_SCSIRESET_IRQ | \
  107. IRQSTATUS_TIMER_IRQ | \
  108. IRQSTATUS_FIFO_SHLD_IRQ | \
  109. IRQSTATUS_PCI_IRQ | \
  110. IRQSTATUS_BMCNTERR_IRQ | \
  111. IRQSTATUS_AUTOSCSI_IRQ )
  112. #define TRANSFER_CONTROL 0x02 /* BASE+02, W, W */
  113. #define TRANSFER_STATUS 0x02 /* BASE+02, W, R */
  114. # define CB_MMIO_MODE BIT(0)
  115. # define CB_IO_MODE BIT(1)
  116. # define BM_TEST BIT(2)
  117. # define BM_TEST_DIR BIT(3)
  118. # define DUAL_EDGE_ENABLE BIT(4)
  119. # define NO_TRANSFER_TO_HOST BIT(5)
  120. # define TRANSFER_GO BIT(7)
  121. # define BLIEND_MODE BIT(8)
  122. # define BM_START BIT(9)
  123. # define ADVANCED_BM_WRITE BIT(10)
  124. # define BM_SINGLE_MODE BIT(11)
  125. # define FIFO_TRUE_FULL BIT(12)
  126. # define FIFO_TRUE_EMPTY BIT(13)
  127. # define ALL_COUNTER_CLR BIT(14)
  128. # define FIFOTEST BIT(15)
  129. #define INDEX_REG 0x04 /* BASE+04, Byte(R/W), Word(R) */
  130. #define TIMER_SET 0x06 /* BASE+06, W, R/W */
  131. # define TIMER_CNT_MASK (0xff)
  132. # define TIMER_STOP BIT(8)
  133. #define DATA_REG_LOW 0x08 /* BASE+08, LowW, R/W */
  134. #define DATA_REG_HI 0x0a /* BASE+0a, Hi-W, R/W */
  135. #define FIFO_REST_CNT 0x0c /* BASE+0c, W, R/W */
  136. # define FIFO_REST_MASK 0x1ff
  137. # define FIFO_EMPTY_SHLD_FLAG BIT(14)
  138. # define FIFO_FULL_SHLD_FLAG BIT(15)
  139. #define SREQ_SMPL_RATE 0x0f /* BASE+0f, B, R/W */
  140. # define SREQSMPLRATE_RATE0 BIT(0)
  141. # define SREQSMPLRATE_RATE1 BIT(1)
  142. # define SAMPLING_ENABLE BIT(2)
  143. # define SMPL_40M (0) /* 40MHz: 0-100ns/period */
  144. # define SMPL_20M (SREQSMPLRATE_RATE0) /* 20MHz: 100-200ns/period */
  145. # define SMPL_10M (SREQSMPLRATE_RATE1) /* 10Mhz: 200- ns/period */
  146. #define SCSI_BUS_CONTROL 0x10 /* BASE+10, B, R/W */
  147. # define BUSCTL_SEL BIT(0)
  148. # define BUSCTL_RST BIT(1)
  149. # define BUSCTL_DATAOUT_ENB BIT(2)
  150. # define BUSCTL_ATN BIT(3)
  151. # define BUSCTL_ACK BIT(4)
  152. # define BUSCTL_BSY BIT(5)
  153. # define AUTODIRECTION BIT(6)
  154. # define ACKENB BIT(7)
  155. #define CLR_COUNTER 0x12 /* BASE+12, B, W */
  156. # define ACK_COUNTER_CLR BIT(0)
  157. # define SREQ_COUNTER_CLR BIT(1)
  158. # define FIFO_HOST_POINTER_CLR BIT(2)
  159. # define FIFO_REST_COUNT_CLR BIT(3)
  160. # define BM_COUNTER_CLR BIT(4)
  161. # define SAVED_ACK_CLR BIT(5)
  162. # define CLRCOUNTER_ALLMASK (ACK_COUNTER_CLR | \
  163. SREQ_COUNTER_CLR | \
  164. FIFO_HOST_POINTER_CLR | \
  165. FIFO_REST_COUNT_CLR | \
  166. BM_COUNTER_CLR | \
  167. SAVED_ACK_CLR )
  168. #define SCSI_BUS_MONITOR 0x12 /* BASE+12, B, R */
  169. # define BUSMON_MSG BIT(0)
  170. # define BUSMON_IO BIT(1)
  171. # define BUSMON_CD BIT(2)
  172. # define BUSMON_BSY BIT(3)
  173. # define BUSMON_ACK BIT(4)
  174. # define BUSMON_REQ BIT(5)
  175. # define BUSMON_SEL BIT(6)
  176. # define BUSMON_ATN BIT(7)
  177. #define COMMAND_DATA 0x14 /* BASE+14, B, R/W */
  178. #define PARITY_CONTROL 0x16 /* BASE+16, B, W */
  179. # define PARITY_CHECK_ENABLE BIT(0)
  180. # define PARITY_ERROR_CLEAR BIT(1)
  181. #define PARITY_STATUS 0x16 /* BASE+16, B, R */
  182. //# define PARITY_CHECK_ENABLE BIT(0)
  183. # define PARITY_ERROR_NORMAL BIT(1)
  184. # define PARITY_ERROR_LSB BIT(1)
  185. # define PARITY_ERROR_MSB BIT(2)
  186. #define RESELECT_ID 0x18 /* BASE+18, B, R */
  187. #define COMMAND_CONTROL 0x18 /* BASE+18, W, W */
  188. # define CLEAR_CDB_FIFO_POINTER BIT(0)
  189. # define AUTO_COMMAND_PHASE BIT(1)
  190. # define AUTOSCSI_START BIT(2)
  191. # define AUTOSCSI_RESTART BIT(3)
  192. # define AUTO_PARAMETER BIT(4)
  193. # define AUTO_ATN BIT(5)
  194. # define AUTO_MSGIN_00_OR_04 BIT(6)
  195. # define AUTO_MSGIN_02 BIT(7)
  196. # define AUTO_MSGIN_03 BIT(8)
  197. #define SET_ARBIT 0x1a /* BASE+1a, B, W */
  198. # define ARBIT_GO BIT(0)
  199. # define ARBIT_CLEAR BIT(1)
  200. #define ARBIT_STATUS 0x1a /* BASE+1a, B, R */
  201. //# define ARBIT_GO BIT(0)
  202. # define ARBIT_WIN BIT(1)
  203. # define ARBIT_FAIL BIT(2)
  204. # define AUTO_PARAMETER_VALID BIT(3)
  205. # define SGT_VALID BIT(4)
  206. #define SYNC_REG 0x1c /* BASE+1c, B, R/W */
  207. #define ACK_WIDTH 0x1d /* BASE+1d, B, R/W */
  208. #define SCSI_DATA_WITH_ACK 0x20 /* BASE+20, B, R/W */
  209. #define SCSI_OUT_LATCH_TARGET_ID 0x22 /* BASE+22, B, W */
  210. #define SCSI_DATA_IN 0x22 /* BASE+22, B, R */
  211. #define SCAM_CONTROL 0x24 /* BASE+24, B, W */
  212. #define SCAM_STATUS 0x24 /* BASE+24, B, R */
  213. # define SCAM_MSG BIT(0)
  214. # define SCAM_IO BIT(1)
  215. # define SCAM_CD BIT(2)
  216. # define SCAM_BSY BIT(3)
  217. # define SCAM_SEL BIT(4)
  218. # define SCAM_XFEROK BIT(5)
  219. #define SCAM_DATA 0x26 /* BASE+26, B, R/W */
  220. # define SD0 BIT(0)
  221. # define SD1 BIT(1)
  222. # define SD2 BIT(2)
  223. # define SD3 BIT(3)
  224. # define SD4 BIT(4)
  225. # define SD5 BIT(5)
  226. # define SD6 BIT(6)
  227. # define SD7 BIT(7)
  228. #define SACK_CNT 0x28 /* BASE+28, DW, R/W */
  229. #define SREQ_CNT 0x2c /* BASE+2c, DW, R/W */
  230. #define FIFO_DATA_LOW 0x30 /* BASE+30, B/W/DW, R/W */
  231. #define FIFO_DATA_HIGH 0x32 /* BASE+32, B/W, R/W */
  232. #define BM_START_ADR 0x34 /* BASE+34, DW, R/W */
  233. #define BM_CNT 0x38 /* BASE+38, DW, R/W */
  234. # define BM_COUNT_MASK 0x0001ffffUL
  235. # define SGTEND BIT(31) /* Last SGT marker */
  236. #define SGT_ADR 0x3c /* BASE+3c, DW, R/W */
  237. #define WAIT_REG 0x40 /* Bi only */
  238. #define SCSI_EXECUTE_PHASE 0x40 /* BASE+40, W, R */
  239. # define COMMAND_PHASE BIT(0)
  240. # define DATA_IN_PHASE BIT(1)
  241. # define DATA_OUT_PHASE BIT(2)
  242. # define MSGOUT_PHASE BIT(3)
  243. # define STATUS_PHASE BIT(4)
  244. # define ILLEGAL_PHASE BIT(5)
  245. # define BUS_FREE_OCCUER BIT(6)
  246. # define MSG_IN_OCCUER BIT(7)
  247. # define MSG_OUT_OCCUER BIT(8)
  248. # define SELECTION_TIMEOUT BIT(9)
  249. # define MSGIN_00_VALID BIT(10)
  250. # define MSGIN_02_VALID BIT(11)
  251. # define MSGIN_03_VALID BIT(12)
  252. # define MSGIN_04_VALID BIT(13)
  253. # define AUTOSCSI_BUSY BIT(15)
  254. #define SCSI_CSB_IN 0x42 /* BASE+42, B, R */
  255. #define SCSI_MSG_OUT 0x44 /* BASE+44, DW, R/W */
  256. # define MSGOUT_COUNT_MASK (BIT(0)|BIT(1))
  257. # define MV_VALID BIT(7)
  258. #define SEL_TIME_OUT 0x48 /* BASE+48, W, R/W */
  259. #define SAVED_SACK_CNT 0x4c /* BASE+4c, DW, R */
  260. #define HTOSDATADELAY 0x50 /* BASE+50, B, R/W */
  261. #define STOHDATADELAY 0x54 /* BASE+54, B, R/W */
  262. #define ACKSUMCHECKRD 0x58 /* BASE+58, W, R */
  263. #define REQSUMCHECKRD 0x5c /* BASE+5c, W, R */
  264. /********************/
  265. /* indexed register */
  266. /********************/
  267. #define CLOCK_DIV 0x00 /* BASE+08, IDX+00, B, R/W */
  268. # define CLOCK_2 BIT(0) /* MCLK/2 */
  269. # define CLOCK_4 BIT(1) /* MCLK/4 */
  270. # define PCICLK BIT(7) /* PCICLK (33MHz) */
  271. #define TERM_PWR_CONTROL 0x01 /* BASE+08, IDX+01, B, R/W */
  272. # define BPWR BIT(0)
  273. # define SENSE BIT(1) /* Read Only */
  274. #define EXT_PORT_DDR 0x02 /* BASE+08, IDX+02, B, R/W */
  275. #define EXT_PORT 0x03 /* BASE+08, IDX+03, B, R/W */
  276. # define LED_ON (0)
  277. # define LED_OFF BIT(0)
  278. #define IRQ_SELECT 0x04 /* BASE+08, IDX+04, W, R/W */
  279. # define IRQSELECT_RESELECT_IRQ BIT(0)
  280. # define IRQSELECT_PHASE_CHANGE_IRQ BIT(1)
  281. # define IRQSELECT_SCSIRESET_IRQ BIT(2)
  282. # define IRQSELECT_TIMER_IRQ BIT(3)
  283. # define IRQSELECT_FIFO_SHLD_IRQ BIT(4)
  284. # define IRQSELECT_TARGET_ABORT_IRQ BIT(5)
  285. # define IRQSELECT_MASTER_ABORT_IRQ BIT(6)
  286. # define IRQSELECT_SERR_IRQ BIT(7)
  287. # define IRQSELECT_PERR_IRQ BIT(8)
  288. # define IRQSELECT_BMCNTERR_IRQ BIT(9)
  289. # define IRQSELECT_AUTO_SCSI_SEQ_IRQ BIT(10)
  290. #define OLD_SCSI_PHASE 0x05 /* BASE+08, IDX+05, B, R */
  291. # define OLD_MSG BIT(0)
  292. # define OLD_IO BIT(1)
  293. # define OLD_CD BIT(2)
  294. # define OLD_BUSY BIT(3)
  295. #define FIFO_FULL_SHLD_COUNT 0x06 /* BASE+08, IDX+06, B, R/W */
  296. #define FIFO_EMPTY_SHLD_COUNT 0x07 /* BASE+08, IDX+07, B, R/W */
  297. #define EXP_ROM_CONTROL 0x08 /* BASE+08, IDX+08, B, R/W */ /* external ROM control */
  298. # define ROM_WRITE_ENB BIT(0)
  299. # define IO_ACCESS_ENB BIT(1)
  300. # define ROM_ADR_CLEAR BIT(2)
  301. #define EXP_ROM_ADR 0x09 /* BASE+08, IDX+09, W, R/W */
  302. #define EXP_ROM_DATA 0x0a /* BASE+08, IDX+0a, B, R/W */
  303. #define CHIP_MODE 0x0b /* BASE+08, IDX+0b, B, R */ /* NinjaSCSI-32Bi only */
  304. # define OEM0 BIT(1) /* OEM select */ /* 00=I-O DATA, 01=KME, 10=Workbit, 11=Ext ROM */
  305. # define OEM1 BIT(2) /* OEM select */
  306. # define OPTB BIT(3) /* KME mode select */
  307. # define OPTC BIT(4) /* KME mode select */
  308. # define OPTD BIT(5) /* KME mode select */
  309. # define OPTE BIT(6) /* KME mode select */
  310. # define OPTF BIT(7) /* Power management */
  311. #define MISC_WR 0x0c /* BASE+08, IDX+0c, W, R/W */
  312. #define MISC_RD 0x0c
  313. # define SCSI_DIRECTION_DETECTOR_SELECT BIT(0)
  314. # define SCSI2_HOST_DIRECTION_VALID BIT(1) /* Read only */
  315. # define HOST2_SCSI_DIRECTION_VALID BIT(2) /* Read only */
  316. # define DELAYED_BMSTART BIT(3)
  317. # define MASTER_TERMINATION_SELECT BIT(4)
  318. # define BMREQ_NEGATE_TIMING_SEL BIT(5)
  319. # define AUTOSEL_TIMING_SEL BIT(6)
  320. # define MISC_MABORT_MASK BIT(7)
  321. # define BMSTOP_CHANGE2_NONDATA_PHASE BIT(8)
  322. #define BM_CYCLE 0x0d /* BASE+08, IDX+0d, B, R/W */
  323. # define BM_CYCLE0 BIT(0)
  324. # define BM_CYCLE1 BIT(1)
  325. # define BM_FRAME_ASSERT_TIMING BIT(2)
  326. # define BM_IRDY_ASSERT_TIMING BIT(3)
  327. # define BM_SINGLE_BUS_MASTER BIT(4)
  328. # define MEMRD_CMD0 BIT(5)
  329. # define SGT_AUTO_PARA_MEMED_CMD BIT(6)
  330. # define MEMRD_CMD1 BIT(7)
  331. #define SREQ_EDGH 0x0e /* BASE+08, IDX+0e, B, W */
  332. # define SREQ_EDGH_SELECT BIT(0)
  333. #define UP_CNT 0x0f /* BASE+08, IDX+0f, B, W */
  334. # define REQCNT_UP BIT(0)
  335. # define ACKCNT_UP BIT(1)
  336. # define BMADR_UP BIT(4)
  337. # define BMCNT_UP BIT(5)
  338. # define SGT_CNT_UP BIT(7)
  339. #define CFG_CMD_STR 0x10 /* BASE+08, IDX+10, W, R */
  340. #define CFG_LATE_CACHE 0x11 /* BASE+08, IDX+11, W, R/W */
  341. #define CFG_BASE_ADR_1 0x12 /* BASE+08, IDX+12, W, R */
  342. #define CFG_BASE_ADR_2 0x13 /* BASE+08, IDX+13, W, R */
  343. #define CFG_INLINE 0x14 /* BASE+08, IDX+14, W, R */
  344. #define SERIAL_ROM_CTL 0x15 /* BASE+08, IDX+15, B, R */
  345. # define SCL BIT(0)
  346. # define ENA BIT(1)
  347. # define SDA BIT(2)
  348. #define FIFO_HST_POINTER 0x16 /* BASE+08, IDX+16, B, R/W */
  349. #define SREQ_DELAY 0x17 /* BASE+08, IDX+17, B, R/W */
  350. #define SACK_DELAY 0x18 /* BASE+08, IDX+18, B, R/W */
  351. #define SREQ_NOISE_CANCEL 0x19 /* BASE+08, IDX+19, B, R/W */
  352. #define SDP_NOISE_CANCEL 0x1a /* BASE+08, IDX+1a, B, R/W */
  353. #define DELAY_TEST 0x1b /* BASE+08, IDX+1b, B, R/W */
  354. #define SD0_NOISE_CANCEL 0x20 /* BASE+08, IDX+20, B, R/W */
  355. #define SD1_NOISE_CANCEL 0x21 /* BASE+08, IDX+21, B, R/W */
  356. #define SD2_NOISE_CANCEL 0x22 /* BASE+08, IDX+22, B, R/W */
  357. #define SD3_NOISE_CANCEL 0x23 /* BASE+08, IDX+23, B, R/W */
  358. #define SD4_NOISE_CANCEL 0x24 /* BASE+08, IDX+24, B, R/W */
  359. #define SD5_NOISE_CANCEL 0x25 /* BASE+08, IDX+25, B, R/W */
  360. #define SD6_NOISE_CANCEL 0x26 /* BASE+08, IDX+26, B, R/W */
  361. #define SD7_NOISE_CANCEL 0x27 /* BASE+08, IDX+27, B, R/W */
  362. /*
  363. * Useful Bus Monitor status combinations.
  364. */
  365. #define BUSMON_BUS_FREE 0
  366. #define BUSMON_COMMAND ( BUSMON_BSY | BUSMON_CD | BUSMON_REQ )
  367. #define BUSMON_MESSAGE_IN ( BUSMON_BSY | BUSMON_MSG | BUSMON_IO | BUSMON_CD | BUSMON_REQ )
  368. #define BUSMON_MESSAGE_OUT ( BUSMON_BSY | BUSMON_MSG | BUSMON_CD | BUSMON_REQ )
  369. #define BUSMON_DATA_IN ( BUSMON_BSY | BUSMON_IO | BUSMON_REQ )
  370. #define BUSMON_DATA_OUT ( BUSMON_BSY | BUSMON_REQ )
  371. #define BUSMON_STATUS ( BUSMON_BSY | BUSMON_IO | BUSMON_CD | BUSMON_REQ )
  372. #define BUSMON_RESELECT ( BUSMON_IO | BUSMON_SEL)
  373. #define BUSMON_PHASE_MASK ( BUSMON_MSG | BUSMON_IO | BUSMON_CD | BUSMON_SEL)
  374. #define BUSPHASE_COMMAND ( BUSMON_COMMAND & BUSMON_PHASE_MASK )
  375. #define BUSPHASE_MESSAGE_IN ( BUSMON_MESSAGE_IN & BUSMON_PHASE_MASK )
  376. #define BUSPHASE_MESSAGE_OUT ( BUSMON_MESSAGE_OUT & BUSMON_PHASE_MASK )
  377. #define BUSPHASE_DATA_IN ( BUSMON_DATA_IN & BUSMON_PHASE_MASK )
  378. #define BUSPHASE_DATA_OUT ( BUSMON_DATA_OUT & BUSMON_PHASE_MASK )
  379. #define BUSPHASE_STATUS ( BUSMON_STATUS & BUSMON_PHASE_MASK )
  380. #define BUSPHASE_SELECT ( BUSMON_SEL | BUSMON_IO )
  381. /************************************************************************
  382. * structure for DMA/Scatter Gather list
  383. */
  384. #define NSP32_SG_SIZE SG_ALL
  385. typedef struct _nsp32_sgtable {
  386. /* values must be little endian */
  387. u32_le addr; /* transfer address */
  388. u32_le len; /* transfer length. BIT(31) is for SGT_END mark */
  389. } __attribute__ ((packed)) nsp32_sgtable;
  390. typedef struct _nsp32_sglun {
  391. nsp32_sgtable sgt[NSP32_SG_SIZE+1]; /* SG table */
  392. } __attribute__ ((packed)) nsp32_sglun;
  393. #define NSP32_SG_TABLE_SIZE (sizeof(nsp32_sgtable) * NSP32_SG_SIZE * MAX_TARGET * MAX_LUN)
  394. /* Auto parameter mode memory map. */
  395. /* All values must be little endian. */
  396. typedef struct _nsp32_autoparam {
  397. u8 cdb[4 * 0x10]; /* SCSI Command */
  398. u32_le msgout; /* outgoing messages */
  399. u8 syncreg; /* sync register value */
  400. u8 ackwidth; /* ack width register value */
  401. u8 target_id; /* target/host device id */
  402. u8 sample_reg; /* hazard killer sampling rate */
  403. u16_le command_control; /* command control register */
  404. u16_le transfer_control; /* transfer control register */
  405. u32_le sgt_pointer; /* SG table physical address for DMA */
  406. u32_le dummy[2];
  407. } __attribute__ ((packed)) nsp32_autoparam; /* must be packed struct */
  408. /*
  409. * host data structure
  410. */
  411. /* message in/out buffer */
  412. #define MSGOUTBUF_MAX 20
  413. #define MSGINBUF_MAX 20
  414. /* flag for trans_method */
  415. #define NSP32_TRANSFER_BUSMASTER BIT(0)
  416. #define NSP32_TRANSFER_MMIO BIT(1) /* Not supported yet */
  417. #define NSP32_TRANSFER_PIO BIT(2) /* Not supported yet */
  418. /*
  419. * structure for connected LUN dynamic data
  420. *
  421. * Note: Currently tagged queuing is disabled, each nsp32_lunt holds
  422. * one SCSI command and one state.
  423. */
  424. #define DISCPRIV_OK BIT(0) /* DISCPRIV Enable mode */
  425. #define MSGIN03 BIT(1) /* Auto Msg In 03 Flag */
  426. typedef struct _nsp32_lunt {
  427. struct scsi_cmnd *SCpnt; /* Current Handling struct scsi_cmnd */
  428. unsigned long save_datp; /* Save Data Pointer - saved position from initial address */
  429. int msgin03; /* auto msg in 03 flag */
  430. unsigned int sg_num; /* Total number of SG entries */
  431. int cur_entry; /* Current SG entry number */
  432. nsp32_sglun *sglun; /* sg table per lun */
  433. dma_addr_t sglun_paddr; /* sglun physical address */
  434. } nsp32_lunt;
  435. /*
  436. * SCSI TARGET/LUN definition
  437. */
  438. #define NSP32_HOST_SCSIID 7 /* SCSI initiator is everytime defined as 7 */
  439. #define MAX_TARGET 8
  440. #define MAX_LUN 8 /* XXX: In SPI3, max number of LUN is 64. */
  441. typedef struct _nsp32_sync_table {
  442. unsigned char period_num; /* period number */
  443. unsigned char ackwidth; /* ack width designated by period */
  444. unsigned char start_period; /* search range - start period */
  445. unsigned char end_period; /* search range - end period */
  446. unsigned char sample_rate; /* hazard killer parameter */
  447. } nsp32_sync_table;
  448. /*
  449. * structure for target device static data
  450. */
  451. /* flag for nsp32_target.sync_flag */
  452. #define SDTR_INITIATOR BIT(0) /* sending SDTR from initiator */
  453. #define SDTR_TARGET BIT(1) /* sending SDTR from target */
  454. #define SDTR_DONE BIT(2) /* exchanging SDTR has been processed */
  455. /* syncronous period value for nsp32_target.config_max */
  456. #define FAST5M 0x32
  457. #define FAST10M 0x19
  458. #define ULTRA20M 0x0c
  459. /* flag for nsp32_target.{sync_offset}, period */
  460. #define ASYNC_OFFSET 0 /* asynchronous transfer */
  461. #define SYNC_OFFSET 0xf /* synchronous transfer max offset */
  462. /* syncreg:
  463. bit:07 06 05 04 03 02 01 00
  464. ---PERIOD-- ---OFFSET-- */
  465. #define TO_SYNCREG(period, offset) (((period) & 0x0f) << 4 | ((offset) & 0x0f))
  466. typedef struct _nsp32_target {
  467. unsigned char syncreg; /* value for SYNCREG */
  468. unsigned char ackwidth; /* value for ACKWIDTH */
  469. unsigned char period; /* sync period (0-255) */
  470. unsigned char offset; /* sync offset (0-15) */
  471. int sync_flag; /* SDTR_*, 0 */
  472. int limit_entry; /* max speed limit entry designated
  473. by EEPROM configuration */
  474. unsigned char sample_reg; /* SREQ hazard killer register */
  475. } nsp32_target;
  476. typedef struct _nsp32_hw_data {
  477. int IrqNumber;
  478. int BaseAddress;
  479. int NumAddress;
  480. void __iomem *MmioAddress;
  481. #define NSP32_MMIO_OFFSET 0x0800
  482. unsigned long MmioLength;
  483. struct scsi_cmnd *CurrentSC;
  484. struct pci_dev *Pci;
  485. const struct pci_device_id *pci_devid;
  486. struct Scsi_Host *Host;
  487. spinlock_t Lock;
  488. char info_str[100];
  489. /* allocated memory region */
  490. nsp32_sglun *sg_list; /* sglist virtuxal address */
  491. dma_addr_t sg_paddr; /* physical address of hw_sg_table */
  492. nsp32_autoparam *autoparam; /* auto parameter transfer region */
  493. dma_addr_t auto_paddr; /* physical address of autoparam */
  494. int cur_entry; /* current sgt entry */
  495. /* target/LUN */
  496. nsp32_lunt *cur_lunt; /* Current connected LUN table */
  497. nsp32_lunt lunt[MAX_TARGET][MAX_LUN]; /* All LUN table */
  498. nsp32_target *cur_target; /* Current connected SCSI ID */
  499. nsp32_target target[MAX_TARGET]; /* SCSI ID */
  500. int cur_id; /* Current connected target ID */
  501. int cur_lun; /* Current connected target LUN */
  502. /* behavior setting parameters */
  503. int trans_method; /* transfer method flag */
  504. int resettime; /* Reset time */
  505. int clock; /* clock dividing flag */
  506. nsp32_sync_table *synct; /* sync_table determined by clock */
  507. int syncnum; /* the max number of synct element */
  508. /* message buffer */
  509. unsigned char msgoutbuf[MSGOUTBUF_MAX]; /* msgout buffer */
  510. char msgout_len; /* msgoutbuf length */
  511. unsigned char msginbuf [MSGINBUF_MAX]; /* megin buffer */
  512. char msgin_len; /* msginbuf length */
  513. } nsp32_hw_data;
  514. /*
  515. * TIME definition
  516. */
  517. #define RESET_HOLD_TIME 10000 /* reset time in us (SCSI-2 says the
  518. minimum is 25us) */
  519. #define SEL_TIMEOUT_TIME 10000 /* 250ms defined in SCSI specification
  520. (25.6us/1unit) */
  521. #define ARBIT_TIMEOUT_TIME 100 /* 100us */
  522. #define REQSACK_TIMEOUT_TIME 10000 /* max wait time for REQ/SACK assertion
  523. or negation, 10000us == 10ms */
  524. /**************************************************************************
  525. * Compatibility functions
  526. */
  527. /* for Kernel 2.4 */
  528. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
  529. # define scsi_register_host(template) scsi_register_module(MODULE_SCSI_HA, template)
  530. # define scsi_unregister_host(template) scsi_unregister_module(MODULE_SCSI_HA, template)
  531. # define scsi_host_put(host) scsi_unregister(host)
  532. # define pci_name(pci_dev) ((pci_dev)->slot_name)
  533. typedef void irqreturn_t;
  534. # define IRQ_NONE /* */
  535. # define IRQ_HANDLED /* */
  536. # define IRQ_RETVAL(x) /* */
  537. /* This is ad-hoc version of scsi_host_get_next() */
  538. static inline struct Scsi_Host *scsi_host_get_next(struct Scsi_Host *host)
  539. {
  540. if (host == NULL) {
  541. return scsi_hostlist;
  542. } else {
  543. return host->next;
  544. }
  545. }
  546. /* This is ad-hoc version of scsi_host_hn_get() */
  547. static inline struct Scsi_Host *scsi_host_hn_get(unsigned short hostno)
  548. {
  549. struct Scsi_Host *host;
  550. for (host = scsi_host_get_next(NULL); host != NULL;
  551. host = scsi_host_get_next(host)) {
  552. if (host->host_no == hostno) {
  553. break;
  554. }
  555. }
  556. return host;
  557. }
  558. #endif
  559. #endif /* _NSP32_H */
  560. /* end */