1 /***********************************************************************
2 ;* File Name : TMSCSIM.H *
3 ;* TEKRAM DC-390(T) PCI SCSI Bus Master Host Adapter *
5 ;***********************************************************************/
6 /* $Id: tmscsim.h,v 2.15.2.3 2000/11/17 20:52:27 garloff Exp $ */
11 #include <linux/types.h>
13 #define SCSI_IRQ_NONE 255
15 #define MAX_ADAPTER_NUM 4
16 #define MAX_SG_LIST_BUF 16 /* Not used */
18 #define MAX_SRB_CNT 50 /* Max number of started commands */
20 #define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */
23 ;-----------------------------------------------------------------------
25 ;-----------------------------------------------------------------------
31 struct dc390_srb *pNextSRB;
32 struct dc390_dcb *pSRBDCB;
33 struct scsi_cmnd *pcmd;
34 struct scatterlist *pSegmentList;
36 struct scatterlist Segmentx; /* make a one entry of S/G list table */
38 unsigned long SGBusAddr; /*;a segment starting address as seen by AM53C974A
39 in CPU endianness. We're only getting 32-bit bus
40 addresses by default */
41 unsigned long SGToBeXferLen; /*; to be xfer length */
42 unsigned long TotalXferredLen;
43 unsigned long SavedTotXLen;
44 unsigned long Saved_Ptr;
48 u8 SRBFlag; /*; b0-AutoReqSense,b6-Read,b7-write */
49 /*; b4-settimeout,b5-Residual valid */
65 //u8 IORBFlag; /*;81h-Reset, 2-retry */
70 ;-----------------------------------------------------------------------
71 ; Device Control Block
72 ;-----------------------------------------------------------------------
76 struct dc390_dcb *pNextDCB;
77 struct dc390_acb *pDCBACB;
80 struct dc390_srb *pGoingSRB;
81 struct dc390_srb *pGoingLast;
82 struct dc390_srb *pActiveSRB;
87 u8 TargetID; /*; SCSI Target ID (SCSI Only) */
88 u8 TargetLUN; /*; SCSI Log. Unit (SCSI Only) */
96 u8 SyncMode; /*; 0:async mode */
97 u8 NegoPeriod; /*;for nego. */
98 u8 SyncPeriod; /*;for reg. */
99 u8 SyncOffset; /*;for reg. and nego.(low nibble) */
104 ;-----------------------------------------------------------------------
105 ; Adapter Control Block
106 ;-----------------------------------------------------------------------
110 struct Scsi_Host *pScsiHost;
116 u8 AdapterIndex; /*; nth Adapter this driver */
124 struct dc390_dcb *pLinkDCB;
125 struct dc390_dcb *pLastDCB;
126 struct dc390_dcb *pDCBRunRobin;
128 struct dc390_dcb *pActiveDCB;
129 struct dc390_srb *pFreeSRB;
130 struct dc390_srb *pTmpSRB;
136 #if defined(USE_SPINLOCKS) && USE_SPINLOCKS > 1 && (defined(CONFIG_SMP) || DEBUG_SPINLOCKS > 0)
143 u8 Ignore_IRQ; /* Not used */
145 struct pci_dev *pdev;
153 struct dc390_srb TmpSRB;
154 struct dc390_srb SRB_array[MAX_SRB_CNT]; /* 50 SRBs */
158 /*;-----------------------------------------------------------------------*/
161 #define BIT31 0x80000000
162 #define BIT30 0x40000000
163 #define BIT29 0x20000000
164 #define BIT28 0x10000000
165 #define BIT27 0x08000000
166 #define BIT26 0x04000000
167 #define BIT25 0x02000000
168 #define BIT24 0x01000000
169 #define BIT23 0x00800000
170 #define BIT22 0x00400000
171 #define BIT21 0x00200000
172 #define BIT20 0x00100000
173 #define BIT19 0x00080000
174 #define BIT18 0x00040000
175 #define BIT17 0x00020000
176 #define BIT16 0x00010000
177 #define BIT15 0x00008000
178 #define BIT14 0x00004000
179 #define BIT13 0x00002000
180 #define BIT12 0x00001000
181 #define BIT11 0x00000800
182 #define BIT10 0x00000400
183 #define BIT9 0x00000200
184 #define BIT8 0x00000100
185 #define BIT7 0x00000080
186 #define BIT6 0x00000040
187 #define BIT5 0x00000020
188 #define BIT4 0x00000010
189 #define BIT3 0x00000008
190 #define BIT2 0x00000004
191 #define BIT1 0x00000002
192 #define BIT0 0x00000001
194 /*;---UnitCtrlFlag */
195 #define UNIT_ALLOCATED BIT0
196 #define UNIT_INFO_CHANGED BIT1
197 #define FORMATING_MEDIA BIT2
198 #define UNIT_RETRY BIT3
201 #define DASD_SUPPORT BIT0
202 #define SCSI_SUPPORT BIT1
203 #define ASPI_SUPPORT BIT2
205 /*;----SRBState machine definition */
207 #define SRB_WAIT BIT0
208 #define SRB_READY BIT1
209 #define SRB_MSGOUT BIT2 /*;arbitration+msg_out 1st byte*/
210 #define SRB_MSGIN BIT3
211 #define SRB_MSGIN_MULTI BIT4
212 #define SRB_COMMAND BIT5
213 #define SRB_START_ BIT6 /*;arbitration+msg_out+command_out*/
214 #define SRB_DISCONNECT BIT7
215 #define SRB_DATA_XFER BIT8
216 #define SRB_XFERPAD BIT9
217 #define SRB_STATUS BIT10
218 #define SRB_COMPLETED BIT11
219 #define SRB_ABORT_SENT BIT12
220 #define DO_SYNC_NEGO BIT13
221 #define SRB_UNEXPECT_RESEL BIT14
225 #define ABORTION BIT1
226 #define OVER_RUN BIT2
227 #define UNDER_RUN BIT3
228 #define PARITY_ERROR BIT4
229 #define SRB_ERROR BIT5
232 #define RESET_DEV BIT0
233 #define RESET_DETECT BIT1
234 #define RESET_DONE BIT2
237 #define ABORT_DEV_ BIT0
242 #define RESIDUAL_VALID BIT5
243 #define ENABLE_TIMER BIT4
244 #define RESET_DEV0 BIT2
245 #define ABORT_DEV BIT1
246 #define AUTO_REQSENSE BIT0
248 /*;---Adapter status */
249 #define H_STATUS_GOOD 0
250 #define H_SEL_TIMEOUT 0x11
251 #define H_OVER_UNDER_RUN 0x12
252 #define H_UNEXP_BUS_FREE 0x13
253 #define H_TARGET_PHASE_F 0x14
254 #define H_INVALID_CCB_OP 0x16
255 #define H_LINK_CCB_BAD 0x17
256 #define H_BAD_TARGET_DIR 0x18
257 #define H_DUPLICATE_CCB 0x19
258 #define H_BAD_CCB_OR_SG 0x1A
259 #define H_ABORT 0x0FF
261 /*; SCSI Status byte codes*/
262 /* The values defined in include/scsi/scsi.h, to be shifted << 1 */
264 #define SCSI_STAT_UNEXP_BUS_F 0xFD /*; Unexpect Bus Free */
265 #define SCSI_STAT_BUS_RST_DETECT 0xFE /*; Scsi Bus Reset detected */
266 #define SCSI_STAT_SEL_TIMEOUT 0xFF /*; Selection Time out */
269 #define RES_TARGET 0x000000FF /* Target State */
270 #define RES_TARGET_LNX STATUS_MASK /* Only official ... */
271 #define RES_ENDMSG 0x0000FF00 /* End Message */
272 #define RES_DID 0x00FF0000 /* DID_ codes */
273 #define RES_DRV 0xFF000000 /* DRIVER_ codes */
275 #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
276 #define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)<<1)
278 #define SET_RES_TARGET(who, tgt) do { who &= ~RES_TARGET; who |= (int)(tgt); } while (0)
279 #define SET_RES_TARGET_LNX(who, tgt) do { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; } while (0)
280 #define SET_RES_MSG(who, msg) do { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; } while (0)
281 #define SET_RES_DID(who, did) do { who &= ~RES_DID; who |= (int)(did) << 16; } while (0)
282 #define SET_RES_DRV(who, drv) do { who &= ~RES_DRV; who |= (int)(drv) << 24; } while (0)
285 #define SYNC_DISABLE 0
286 #define SYNC_ENABLE BIT0
287 #define SYNC_NEGO_DONE BIT1
288 #define WIDE_ENABLE BIT2 /* Not used ;-) */
289 #define WIDE_NEGO_DONE BIT3 /* Not used ;-) */
290 #define EN_TAG_QUEUEING BIT4
291 #define EN_ATN_STOP BIT5
293 #define SYNC_NEGO_OFFSET 15
295 /*;---SCSI bus phase*/
296 #define SCSI_DATA_OUT 0
297 #define SCSI_DATA_IN 1
298 #define SCSI_COMMAND 2
299 #define SCSI_STATUS_ 3
302 #define SCSI_MSG_OUT 6
303 #define SCSI_MSG_IN 7
305 /*;----SCSI MSG BYTE*/ /* see scsi/scsi.h */ /* One is missing ! */
306 #define ABORT_TAG 0x0d
312 dma_addr_t saved_dma_handle;
316 ;==========================================================
318 ;==========================================================
320 typedef struct _EEprom
328 #define REAL_EE_ADAPT_SCSI_ID 64
329 #define REAL_EE_MODE2 65
330 #define REAL_EE_DELAY 66
331 #define REAL_EE_TAG_CMD_NUM 67
333 #define EE_ADAPT_SCSI_ID 32
336 #define EE_TAG_CMD_NUM 35
340 /*; EE_MODE1 bits definition*/
341 #define PARITY_CHK_ BIT0
342 #define SYNC_NEGO_ BIT1
343 #define EN_DISCONNECT_ BIT2
344 #define SEND_START_ BIT3
345 #define TAG_QUEUEING_ BIT4
347 /*; EE_MODE2 bits definition*/
348 #define MORE2_DRV BIT0
349 #define GREATER_1G BIT1
350 #define RST_SCSI_BUS BIT2
351 #define ACTIVE_NEGATION BIT3
353 #define LUN_CHECK BIT5
357 #define EEPROM_READ 0x80
360 ;==========================================================
361 ; AMD 53C974 Registers bit Definition
362 ;==========================================================
365 ;====================
367 ;====================
370 /*; Command Reg.(+0CH) (rw) */
371 #define DMA_COMMAND BIT7
373 #define CLEAR_FIFO_CMD 1
374 #define RST_DEVICE_CMD 2
375 #define RST_SCSI_BUS_CMD 3
377 #define INFO_XFER_CMD 0x10
378 #define INITIATOR_CMD_CMPLTE 0x11
379 #define MSG_ACCEPTED_CMD 0x12
380 #define XFER_PAD_BYTE 0x18
381 #define SET_ATN_CMD 0x1A
382 #define RESET_ATN_CMD 0x1B
384 #define SEL_WO_ATN 0x41 /* currently not used */
385 #define SEL_W_ATN 0x42
386 #define SEL_W_ATN_STOP 0x43
387 #define SEL_W_ATN3 0x46
388 #define EN_SEL_RESEL 0x44
389 #define DIS_SEL_RESEL 0x45 /* currently not used */
390 #define RESEL 0x40 /* " */
391 #define RESEL_ATN3 0x47 /* " */
393 #define DATA_XFER_CMD INFO_XFER_CMD
396 /*; SCSI Status Reg.(+10H) (r) */
397 #define INTERRUPT BIT7
398 #define ILLEGAL_OP_ERR BIT6
399 #define PARITY_ERR BIT5
400 #define COUNT_2_ZERO BIT4
401 #define GROUP_CODE_VALID BIT3
402 #define SCSI_PHASE_MASK (BIT2+BIT1+BIT0)
403 /* BIT2: MSG phase; BIT1: C/D physe; BIT0: I/O phase */
405 /*; Interrupt Status Reg.(+14H) (r) */
406 #define SCSI_RESET BIT7
407 #define INVALID_CMD BIT6
408 #define DISCONNECTED BIT5
409 #define SERVICE_REQUEST BIT4
410 #define SUCCESSFUL_OP BIT3
411 #define RESELECTED BIT2
412 #define SEL_ATTENTION BIT1
413 #define SELECTED BIT0
415 /*; Internal State Reg.(+18H) (r) */
416 #define SYNC_OFFSET_FLAG BIT3
417 #define INTRN_STATE_MASK (BIT2+BIT1+BIT0)
418 /* 0x04: Sel. successful (w/o stop), 0x01: Sel. successful (w/ stop) */
420 /*; Clock Factor Reg.(+24H) (w) */
421 #define CLK_FREQ_40MHZ 0
422 #define CLK_FREQ_35MHZ (BIT2+BIT1+BIT0)
423 #define CLK_FREQ_30MHZ (BIT2+BIT1)
424 #define CLK_FREQ_25MHZ (BIT2+BIT0)
425 #define CLK_FREQ_20MHZ BIT2
426 #define CLK_FREQ_15MHZ (BIT1+BIT0)
427 #define CLK_FREQ_10MHZ BIT1
429 /*; Control Reg. 1(+20H) (rw) */
430 #define EXTENDED_TIMING BIT7
431 #define DIS_INT_ON_SCSI_RST BIT6
432 #define PARITY_ERR_REPO BIT4
433 #define SCSI_ID_ON_BUS (BIT2+BIT1+BIT0) /* host adapter ID */
435 /*; Control Reg. 2(+2CH) (rw) */
436 #define EN_FEATURE BIT6
437 #define EN_SCSI2_CMD BIT3
439 /*; Control Reg. 3(+30H) (rw) */
440 #define ID_MSG_CHECK BIT7
441 #define EN_QTAG_MSG BIT6
442 #define EN_GRP2_CMD BIT5
443 #define FAST_SCSI BIT4 /* ;10MB/SEC */
444 #define FAST_CLK BIT3 /* ;25 - 40 MHZ */
446 /*; Control Reg. 4(+34H) (rw) */
448 #define EATER_25NS BIT7
449 #define EATER_35NS BIT6
450 #define EATER_0NS (BIT7+BIT6)
451 #define REDUCED_POWER BIT5
452 #define CTRL4_RESERVED BIT4 /* must be 1 acc. to AM53C974.c */
453 #define NEGATE_REQACKDATA BIT2
454 #define NEGATE_REQACK BIT3
456 #define GLITCH_TO_NS(x) (((~x>>6 & 2) >> 1) | ((x>>6 & 1) << 1 ^ (x>>6 & 2)))
457 #define NS_TO_GLITCH(y) (((~y<<7) | ~((y<<6) ^ ((y<<5 & 1<<6) | ~0x40))) & 0xc0)
460 ;====================
462 ;====================
464 /*; DMA Command Reg.(+40H) (rw) */
465 #define READ_DIRECTION BIT7
466 #define WRITE_DIRECTION 0
467 #define EN_DMA_INT BIT6
468 #define EN_PAGE_INT BIT5 /* page transfer interrupt enable */
469 #define MAP_TO_MDL BIT4
470 #define DIAGNOSTIC BIT2
471 #define DMA_IDLE_CMD 0
472 #define DMA_BLAST_CMD BIT0
473 #define DMA_ABORT_CMD BIT1
474 #define DMA_START_CMD (BIT1+BIT0)
476 /*; DMA Status Reg.(+54H) (r) */
477 #define PCI_MS_ABORT BIT6
478 #define BLAST_COMPLETE BIT5
479 #define SCSI_INTERRUPT BIT4
480 #define DMA_XFER_DONE BIT3
481 #define DMA_XFER_ABORT BIT2
482 #define DMA_XFER_ERROR BIT1
483 #define POWER_DOWN BIT0
485 /*; DMA SCSI Bus and Ctrl.(+70H) */
486 #define EN_INT_ON_PCI_ABORT BIT25
487 #define WRT_ERASE_DMA_STAT BIT24
488 #define PW_DOWN_CTRL BIT21
489 #define SCSI_BUSY BIT20
492 #define SCSI_LINES 0x0003ffff
495 ;==========================================================
496 ; SCSI Chip register address offset
497 ;==========================================================
498 ;Registers are rw unless declared otherwise
500 #define CtcReg_Low 0x00 /* r curr. transfer count */
501 #define CtcReg_Mid 0x04 /* r */
502 #define CtcReg_High 0x38 /* r */
503 #define ScsiFifo 0x08
505 #define Scsi_Status 0x10 /* r */
506 #define INT_Status 0x14 /* r */
507 #define Sync_Period 0x18 /* w */
508 #define Sync_Offset 0x1C /* w */
509 #define Clk_Factor 0x24 /* w */
510 #define CtrlReg1 0x20
511 #define CtrlReg2 0x2C
512 #define CtrlReg3 0x30
513 #define CtrlReg4 0x34
515 #define DMA_XferCnt 0x44 /* rw starting transfer count (32 bit) */
516 #define DMA_XferAddr 0x48 /* rw starting physical address (32 bit) */
517 #define DMA_Wk_ByteCntr 0x4C /* r working byte counter */
518 #define DMA_Wk_AddrCntr 0x50 /* r working address counter */
519 #define DMA_Status 0x54 /* r */
520 #define DMA_MDL_Addr 0x58 /* rw starting MDL address */
521 #define DMA_Wk_MDL_Cntr 0x5C /* r working MDL counter */
522 #define DMA_ScsiBusCtrl 0x70 /* rw SCSI Bus, PCI/DMA Ctrl */
524 #define StcReg_Low CtcReg_Low /* w start transfer count */
525 #define StcReg_Mid CtcReg_Mid /* w */
526 #define StcReg_High CtcReg_High /* w */
527 #define Scsi_Dest_ID Scsi_Status /* w */
528 #define Scsi_TimeOut INT_Status /* w */
529 #define Intern_State Sync_Period /* r */
530 #define Current_Fifo Sync_Offset /* r Curr. FIFO / int. state */
533 #define DC390_read8(address) \
534 (inb (pACB->IOPortBase + (address)))
536 #define DC390_read8_(address, base) \
537 (inb ((u16)(base) + (address)))
539 #define DC390_read16(address) \
540 (inw (pACB->IOPortBase + (address)))
542 #define DC390_read32(address) \
543 (inl (pACB->IOPortBase + (address)))
545 #define DC390_write8(address,value) \
546 outb ((value), pACB->IOPortBase + (address))
548 #define DC390_write8_(address,value,base) \
549 outb ((value), (u16)(base) + (address))
551 #define DC390_write16(address,value) \
552 outw ((value), pACB->IOPortBase + (address))
554 #define DC390_write32(address,value) \
555 outl ((value), pACB->IOPortBase + (address))
558 #endif /* _TMSCSIM_H */