tmscsim.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /***********************************************************************
  2. ;* File Name : TMSCSIM.H *
  3. ;* TEKRAM DC-390(T) PCI SCSI Bus Master Host Adapter *
  4. ;* Device Driver *
  5. ;***********************************************************************/
  6. /* $Id: tmscsim.h,v 2.15.2.3 2000/11/17 20:52:27 garloff Exp $ */
  7. #ifndef _TMSCSIM_H
  8. #define _TMSCSIM_H
  9. #include <linux/types.h>
  10. #define SCSI_IRQ_NONE 255
  11. #define MAX_ADAPTER_NUM 4
  12. #define MAX_SG_LIST_BUF 16 /* Not used */
  13. #define MAX_SCSI_ID 8
  14. #define MAX_SRB_CNT 50 /* Max number of started commands */
  15. #define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */
  16. /*
  17. ;-----------------------------------------------------------------------
  18. ; SCSI Request Block
  19. ;-----------------------------------------------------------------------
  20. */
  21. struct dc390_srb
  22. {
  23. //u8 CmdBlock[12];
  24. struct dc390_srb *pNextSRB;
  25. struct dc390_dcb *pSRBDCB;
  26. struct scsi_cmnd *pcmd;
  27. struct scatterlist *pSegmentList;
  28. struct scatterlist Segmentx; /* make a one entry of S/G list table */
  29. unsigned long SGBusAddr; /*;a segment starting address as seen by AM53C974A
  30. in CPU endianness. We're only getting 32-bit bus
  31. addresses by default */
  32. unsigned long SGToBeXferLen; /*; to be xfer length */
  33. unsigned long TotalXferredLen;
  34. unsigned long SavedTotXLen;
  35. unsigned long Saved_Ptr;
  36. u32 SRBState;
  37. u8 SRBStatus;
  38. u8 SRBFlag; /*; b0-AutoReqSense,b6-Read,b7-write */
  39. /*; b4-settimeout,b5-Residual valid */
  40. u8 AdaptStatus;
  41. u8 TargetStatus;
  42. u8 ScsiPhase;
  43. s8 TagNumber;
  44. u8 SGIndex;
  45. u8 SGcount;
  46. u8 MsgCnt;
  47. u8 EndMessage;
  48. u8 MsgInBuf[6];
  49. u8 MsgOutBuf[6];
  50. //u8 IORBFlag; /*;81h-Reset, 2-retry */
  51. };
  52. /*
  53. ;-----------------------------------------------------------------------
  54. ; Device Control Block
  55. ;-----------------------------------------------------------------------
  56. */
  57. struct dc390_dcb
  58. {
  59. struct dc390_dcb *pNextDCB;
  60. struct dc390_acb *pDCBACB;
  61. /* Queued SRBs */
  62. struct dc390_srb *pGoingSRB;
  63. struct dc390_srb *pGoingLast;
  64. struct dc390_srb *pActiveSRB;
  65. u8 GoingSRBCnt;
  66. u32 TagMask;
  67. u8 TargetID; /*; SCSI Target ID (SCSI Only) */
  68. u8 TargetLUN; /*; SCSI Log. Unit (SCSI Only) */
  69. u8 DevMode;
  70. u8 DCBFlag;
  71. u8 CtrlR1;
  72. u8 CtrlR3;
  73. u8 CtrlR4;
  74. u8 SyncMode; /*; 0:async mode */
  75. u8 NegoPeriod; /*;for nego. */
  76. u8 SyncPeriod; /*;for reg. */
  77. u8 SyncOffset; /*;for reg. and nego.(low nibble) */
  78. };
  79. /*
  80. ;-----------------------------------------------------------------------
  81. ; Adapter Control Block
  82. ;-----------------------------------------------------------------------
  83. */
  84. struct dc390_acb
  85. {
  86. struct Scsi_Host *pScsiHost;
  87. u16 IOPortBase;
  88. u8 IRQLevel;
  89. u8 status;
  90. u8 SRBCount;
  91. u8 AdapterIndex; /*; nth Adapter this driver */
  92. u8 DCBCnt;
  93. u8 TagMaxNum;
  94. u8 ACBFlag;
  95. u8 Gmode2;
  96. u8 scan_devices;
  97. struct dc390_dcb *pLinkDCB;
  98. struct dc390_dcb *pLastDCB;
  99. struct dc390_dcb *pDCBRunRobin;
  100. struct dc390_dcb *pActiveDCB;
  101. struct dc390_srb *pFreeSRB;
  102. struct dc390_srb *pTmpSRB;
  103. u8 msgin123[4];
  104. u8 Connected;
  105. u8 pad;
  106. #if defined(USE_SPINLOCKS) && USE_SPINLOCKS > 1 && (defined(CONFIG_SMP) || DEBUG_SPINLOCKS > 0)
  107. spinlock_t lock;
  108. #endif
  109. u8 sel_timeout;
  110. u8 glitch_cfg;
  111. u8 MsgLen;
  112. u8 Ignore_IRQ; /* Not used */
  113. struct pci_dev *pdev;
  114. unsigned long Cmds;
  115. u32 SelLost;
  116. u32 SelConn;
  117. u32 CmdInQ;
  118. u32 CmdOutOfSRB;
  119. struct dc390_srb TmpSRB;
  120. struct dc390_srb SRB_array[MAX_SRB_CNT]; /* 50 SRBs */
  121. };
  122. /*;-----------------------------------------------------------------------*/
  123. #define BIT31 0x80000000
  124. #define BIT30 0x40000000
  125. #define BIT29 0x20000000
  126. #define BIT28 0x10000000
  127. #define BIT27 0x08000000
  128. #define BIT26 0x04000000
  129. #define BIT25 0x02000000
  130. #define BIT24 0x01000000
  131. #define BIT23 0x00800000
  132. #define BIT22 0x00400000
  133. #define BIT21 0x00200000
  134. #define BIT20 0x00100000
  135. #define BIT19 0x00080000
  136. #define BIT18 0x00040000
  137. #define BIT17 0x00020000
  138. #define BIT16 0x00010000
  139. #define BIT15 0x00008000
  140. #define BIT14 0x00004000
  141. #define BIT13 0x00002000
  142. #define BIT12 0x00001000
  143. #define BIT11 0x00000800
  144. #define BIT10 0x00000400
  145. #define BIT9 0x00000200
  146. #define BIT8 0x00000100
  147. #define BIT7 0x00000080
  148. #define BIT6 0x00000040
  149. #define BIT5 0x00000020
  150. #define BIT4 0x00000010
  151. #define BIT3 0x00000008
  152. #define BIT2 0x00000004
  153. #define BIT1 0x00000002
  154. #define BIT0 0x00000001
  155. /*;---UnitCtrlFlag */
  156. #define UNIT_ALLOCATED BIT0
  157. #define UNIT_INFO_CHANGED BIT1
  158. #define FORMATING_MEDIA BIT2
  159. #define UNIT_RETRY BIT3
  160. /*;---UnitFlags */
  161. #define DASD_SUPPORT BIT0
  162. #define SCSI_SUPPORT BIT1
  163. #define ASPI_SUPPORT BIT2
  164. /*;----SRBState machine definition */
  165. #define SRB_FREE 0
  166. #define SRB_WAIT BIT0
  167. #define SRB_READY BIT1
  168. #define SRB_MSGOUT BIT2 /*;arbitration+msg_out 1st byte*/
  169. #define SRB_MSGIN BIT3
  170. #define SRB_MSGIN_MULTI BIT4
  171. #define SRB_COMMAND BIT5
  172. #define SRB_START_ BIT6 /*;arbitration+msg_out+command_out*/
  173. #define SRB_DISCONNECT BIT7
  174. #define SRB_DATA_XFER BIT8
  175. #define SRB_XFERPAD BIT9
  176. #define SRB_STATUS BIT10
  177. #define SRB_COMPLETED BIT11
  178. #define SRB_ABORT_SENT BIT12
  179. #define DO_SYNC_NEGO BIT13
  180. #define SRB_UNEXPECT_RESEL BIT14
  181. /*;---SRBstatus */
  182. #define SRB_OK BIT0
  183. #define ABORTION BIT1
  184. #define OVER_RUN BIT2
  185. #define UNDER_RUN BIT3
  186. #define PARITY_ERROR BIT4
  187. #define SRB_ERROR BIT5
  188. /*;---ACBFlag */
  189. #define RESET_DEV BIT0
  190. #define RESET_DETECT BIT1
  191. #define RESET_DONE BIT2
  192. /*;---DCBFlag */
  193. #define ABORT_DEV_ BIT0
  194. /*;---SRBFlag */
  195. #define DATAOUT BIT7
  196. #define DATAIN BIT6
  197. #define RESIDUAL_VALID BIT5
  198. #define ENABLE_TIMER BIT4
  199. #define RESET_DEV0 BIT2
  200. #define ABORT_DEV BIT1
  201. #define AUTO_REQSENSE BIT0
  202. /*;---Adapter status */
  203. #define H_STATUS_GOOD 0
  204. #define H_SEL_TIMEOUT 0x11
  205. #define H_OVER_UNDER_RUN 0x12
  206. #define H_UNEXP_BUS_FREE 0x13
  207. #define H_TARGET_PHASE_F 0x14
  208. #define H_INVALID_CCB_OP 0x16
  209. #define H_LINK_CCB_BAD 0x17
  210. #define H_BAD_TARGET_DIR 0x18
  211. #define H_DUPLICATE_CCB 0x19
  212. #define H_BAD_CCB_OR_SG 0x1A
  213. #define H_ABORT 0x0FF
  214. /* cmd->result */
  215. #define RES_TARGET 0x000000FF /* Target State */
  216. #define RES_TARGET_LNX STATUS_MASK /* Only official ... */
  217. #define RES_ENDMSG 0x0000FF00 /* End Message */
  218. #define RES_DID 0x00FF0000 /* DID_ codes */
  219. #define RES_DRV 0xFF000000 /* DRIVER_ codes */
  220. #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
  221. #define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
  222. #define SET_RES_TARGET(who, tgt) do { who &= ~RES_TARGET; who |= (int)(tgt); } while (0)
  223. #define SET_RES_TARGET_LNX(who, tgt) do { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; } while (0)
  224. #define SET_RES_MSG(who, msg) do { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; } while (0)
  225. #define SET_RES_DID(who, did) do { who &= ~RES_DID; who |= (int)(did) << 16; } while (0)
  226. #define SET_RES_DRV(who, drv) do { who &= ~RES_DRV; who |= (int)(drv) << 24; } while (0)
  227. /*;---Sync_Mode */
  228. #define SYNC_DISABLE 0
  229. #define SYNC_ENABLE BIT0
  230. #define SYNC_NEGO_DONE BIT1
  231. #define WIDE_ENABLE BIT2 /* Not used ;-) */
  232. #define WIDE_NEGO_DONE BIT3 /* Not used ;-) */
  233. #define EN_TAG_QUEUEING BIT4
  234. #define EN_ATN_STOP BIT5
  235. #define SYNC_NEGO_OFFSET 15
  236. /*;---SCSI bus phase*/
  237. #define SCSI_DATA_OUT 0
  238. #define SCSI_DATA_IN 1
  239. #define SCSI_COMMAND 2
  240. #define SCSI_STATUS_ 3
  241. #define SCSI_NOP0 4
  242. #define SCSI_NOP1 5
  243. #define SCSI_MSG_OUT 6
  244. #define SCSI_MSG_IN 7
  245. /*;----SCSI MSG BYTE*/ /* see scsi/scsi.h */ /* One is missing ! */
  246. #define ABORT_TAG 0x0d
  247. /*
  248. * SISC query queue
  249. */
  250. typedef struct {
  251. dma_addr_t saved_dma_handle;
  252. } dc390_cmd_scp_t;
  253. /*
  254. ;==========================================================
  255. ; EEPROM byte offset
  256. ;==========================================================
  257. */
  258. typedef struct _EEprom
  259. {
  260. u8 EE_MODE1;
  261. u8 EE_SPEED;
  262. u8 xx1;
  263. u8 xx2;
  264. } EEprom, *PEEprom;
  265. #define REAL_EE_ADAPT_SCSI_ID 64
  266. #define REAL_EE_MODE2 65
  267. #define REAL_EE_DELAY 66
  268. #define REAL_EE_TAG_CMD_NUM 67
  269. #define EE_ADAPT_SCSI_ID 32
  270. #define EE_MODE2 33
  271. #define EE_DELAY 34
  272. #define EE_TAG_CMD_NUM 35
  273. #define EE_LEN 40
  274. /*; EE_MODE1 bits definition*/
  275. #define PARITY_CHK_ BIT0
  276. #define SYNC_NEGO_ BIT1
  277. #define EN_DISCONNECT_ BIT2
  278. #define SEND_START_ BIT3
  279. #define TAG_QUEUEING_ BIT4
  280. /*; EE_MODE2 bits definition*/
  281. #define MORE2_DRV BIT0
  282. #define GREATER_1G BIT1
  283. #define RST_SCSI_BUS BIT2
  284. #define ACTIVE_NEGATION BIT3
  285. #define NO_SEEK BIT4
  286. #define LUN_CHECK BIT5
  287. #define ENABLE_CE 1
  288. #define DISABLE_CE 0
  289. #define EEPROM_READ 0x80
  290. /*
  291. ;==========================================================
  292. ; AMD 53C974 Registers bit Definition
  293. ;==========================================================
  294. */
  295. /*
  296. ;====================
  297. ; SCSI Register
  298. ;====================
  299. */
  300. /*; Command Reg.(+0CH) (rw) */
  301. #define DMA_COMMAND BIT7
  302. #define NOP_CMD 0
  303. #define CLEAR_FIFO_CMD 1
  304. #define RST_DEVICE_CMD 2
  305. #define RST_SCSI_BUS_CMD 3
  306. #define INFO_XFER_CMD 0x10
  307. #define INITIATOR_CMD_CMPLTE 0x11
  308. #define MSG_ACCEPTED_CMD 0x12
  309. #define XFER_PAD_BYTE 0x18
  310. #define SET_ATN_CMD 0x1A
  311. #define RESET_ATN_CMD 0x1B
  312. #define SEL_WO_ATN 0x41 /* currently not used */
  313. #define SEL_W_ATN 0x42
  314. #define SEL_W_ATN_STOP 0x43
  315. #define SEL_W_ATN3 0x46
  316. #define EN_SEL_RESEL 0x44
  317. #define DIS_SEL_RESEL 0x45 /* currently not used */
  318. #define RESEL 0x40 /* " */
  319. #define RESEL_ATN3 0x47 /* " */
  320. #define DATA_XFER_CMD INFO_XFER_CMD
  321. /*; SCSI Status Reg.(+10H) (r) */
  322. #define INTERRUPT BIT7
  323. #define ILLEGAL_OP_ERR BIT6
  324. #define PARITY_ERR BIT5
  325. #define COUNT_2_ZERO BIT4
  326. #define GROUP_CODE_VALID BIT3
  327. #define SCSI_PHASE_MASK (BIT2+BIT1+BIT0)
  328. /* BIT2: MSG phase; BIT1: C/D physe; BIT0: I/O phase */
  329. /*; Interrupt Status Reg.(+14H) (r) */
  330. #define SCSI_RESET BIT7
  331. #define INVALID_CMD BIT6
  332. #define DISCONNECTED BIT5
  333. #define SERVICE_REQUEST BIT4
  334. #define SUCCESSFUL_OP BIT3
  335. #define RESELECTED BIT2
  336. #define SEL_ATTENTION BIT1
  337. #define SELECTED BIT0
  338. /*; Internal State Reg.(+18H) (r) */
  339. #define SYNC_OFFSET_FLAG BIT3
  340. #define INTRN_STATE_MASK (BIT2+BIT1+BIT0)
  341. /* 0x04: Sel. successful (w/o stop), 0x01: Sel. successful (w/ stop) */
  342. /*; Clock Factor Reg.(+24H) (w) */
  343. #define CLK_FREQ_40MHZ 0
  344. #define CLK_FREQ_35MHZ (BIT2+BIT1+BIT0)
  345. #define CLK_FREQ_30MHZ (BIT2+BIT1)
  346. #define CLK_FREQ_25MHZ (BIT2+BIT0)
  347. #define CLK_FREQ_20MHZ BIT2
  348. #define CLK_FREQ_15MHZ (BIT1+BIT0)
  349. #define CLK_FREQ_10MHZ BIT1
  350. /*; Control Reg. 1(+20H) (rw) */
  351. #define EXTENDED_TIMING BIT7
  352. #define DIS_INT_ON_SCSI_RST BIT6
  353. #define PARITY_ERR_REPO BIT4
  354. #define SCSI_ID_ON_BUS (BIT2+BIT1+BIT0) /* host adapter ID */
  355. /*; Control Reg. 2(+2CH) (rw) */
  356. #define EN_FEATURE BIT6
  357. #define EN_SCSI2_CMD BIT3
  358. /*; Control Reg. 3(+30H) (rw) */
  359. #define ID_MSG_CHECK BIT7
  360. #define EN_QTAG_MSG BIT6
  361. #define EN_GRP2_CMD BIT5
  362. #define FAST_SCSI BIT4 /* ;10MB/SEC */
  363. #define FAST_CLK BIT3 /* ;25 - 40 MHZ */
  364. /*; Control Reg. 4(+34H) (rw) */
  365. #define EATER_12NS 0
  366. #define EATER_25NS BIT7
  367. #define EATER_35NS BIT6
  368. #define EATER_0NS (BIT7+BIT6)
  369. #define REDUCED_POWER BIT5
  370. #define CTRL4_RESERVED BIT4 /* must be 1 acc. to AM53C974.c */
  371. #define NEGATE_REQACKDATA BIT2
  372. #define NEGATE_REQACK BIT3
  373. #define GLITCH_TO_NS(x) (((~x>>6 & 2) >> 1) | ((x>>6 & 1) << 1 ^ (x>>6 & 2)))
  374. #define NS_TO_GLITCH(y) (((~y<<7) | ~((y<<6) ^ ((y<<5 & 1<<6) | ~0x40))) & 0xc0)
  375. /*
  376. ;====================
  377. ; DMA Register
  378. ;====================
  379. */
  380. /*; DMA Command Reg.(+40H) (rw) */
  381. #define READ_DIRECTION BIT7
  382. #define WRITE_DIRECTION 0
  383. #define EN_DMA_INT BIT6
  384. #define EN_PAGE_INT BIT5 /* page transfer interrupt enable */
  385. #define MAP_TO_MDL BIT4
  386. #define DIAGNOSTIC BIT2
  387. #define DMA_IDLE_CMD 0
  388. #define DMA_BLAST_CMD BIT0
  389. #define DMA_ABORT_CMD BIT1
  390. #define DMA_START_CMD (BIT1+BIT0)
  391. /*; DMA Status Reg.(+54H) (r) */
  392. #define PCI_MS_ABORT BIT6
  393. #define BLAST_COMPLETE BIT5
  394. #define SCSI_INTERRUPT BIT4
  395. #define DMA_XFER_DONE BIT3
  396. #define DMA_XFER_ABORT BIT2
  397. #define DMA_XFER_ERROR BIT1
  398. #define POWER_DOWN BIT0
  399. /*; DMA SCSI Bus and Ctrl.(+70H) */
  400. #define EN_INT_ON_PCI_ABORT BIT25
  401. #define WRT_ERASE_DMA_STAT BIT24
  402. #define PW_DOWN_CTRL BIT21
  403. #define SCSI_BUSY BIT20
  404. #define SCLK BIT19
  405. #define SCAM BIT18
  406. #define SCSI_LINES 0x0003ffff
  407. /*
  408. ;==========================================================
  409. ; SCSI Chip register address offset
  410. ;==========================================================
  411. ;Registers are rw unless declared otherwise
  412. */
  413. #define CtcReg_Low 0x00 /* r curr. transfer count */
  414. #define CtcReg_Mid 0x04 /* r */
  415. #define CtcReg_High 0x38 /* r */
  416. #define ScsiFifo 0x08
  417. #define ScsiCmd 0x0C
  418. #define Scsi_Status 0x10 /* r */
  419. #define INT_Status 0x14 /* r */
  420. #define Sync_Period 0x18 /* w */
  421. #define Sync_Offset 0x1C /* w */
  422. #define Clk_Factor 0x24 /* w */
  423. #define CtrlReg1 0x20
  424. #define CtrlReg2 0x2C
  425. #define CtrlReg3 0x30
  426. #define CtrlReg4 0x34
  427. #define DMA_Cmd 0x40
  428. #define DMA_XferCnt 0x44 /* rw starting transfer count (32 bit) */
  429. #define DMA_XferAddr 0x48 /* rw starting physical address (32 bit) */
  430. #define DMA_Wk_ByteCntr 0x4C /* r working byte counter */
  431. #define DMA_Wk_AddrCntr 0x50 /* r working address counter */
  432. #define DMA_Status 0x54 /* r */
  433. #define DMA_MDL_Addr 0x58 /* rw starting MDL address */
  434. #define DMA_Wk_MDL_Cntr 0x5C /* r working MDL counter */
  435. #define DMA_ScsiBusCtrl 0x70 /* rw SCSI Bus, PCI/DMA Ctrl */
  436. #define StcReg_Low CtcReg_Low /* w start transfer count */
  437. #define StcReg_Mid CtcReg_Mid /* w */
  438. #define StcReg_High CtcReg_High /* w */
  439. #define Scsi_Dest_ID Scsi_Status /* w */
  440. #define Scsi_TimeOut INT_Status /* w */
  441. #define Intern_State Sync_Period /* r */
  442. #define Current_Fifo Sync_Offset /* r Curr. FIFO / int. state */
  443. #define DC390_read8(address) \
  444. (inb (pACB->IOPortBase + (address)))
  445. #define DC390_read8_(address, base) \
  446. (inb ((u16)(base) + (address)))
  447. #define DC390_read16(address) \
  448. (inw (pACB->IOPortBase + (address)))
  449. #define DC390_read32(address) \
  450. (inl (pACB->IOPortBase + (address)))
  451. #define DC390_write8(address,value) \
  452. outb ((value), pACB->IOPortBase + (address))
  453. #define DC390_write8_(address,value,base) \
  454. outb ((value), (u16)(base) + (address))
  455. #define DC390_write16(address,value) \
  456. outw ((value), pACB->IOPortBase + (address))
  457. #define DC390_write32(address,value) \
  458. outl ((value), pACB->IOPortBase + (address))
  459. #endif /* _TMSCSIM_H */