ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / scsi / tmscsim.h
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
8 #ifndef _TMSCSIM_H
9 #define _TMSCSIM_H
10
11 #include <linux/types.h>
12 #include <linux/config.h>
13
14 #define SCSI_IRQ_NONE 255
15
16 #define MAX_ADAPTER_NUM         4
17 #define MAX_SG_LIST_BUF         16      /* Not used */
18 #define MAX_CMD_PER_LUN         32
19 #define MAX_CMD_QUEUE           MAX_CMD_PER_LUN+MAX_CMD_PER_LUN/2+1     
20 #define MAX_SCSI_ID             8
21 #define MAX_SRB_CNT             MAX_CMD_QUEUE+1 /* Max number of started commands */
22
23 #define SEL_TIMEOUT             153     /* 250 ms selection timeout (@ 40 MHz) */
24
25 #define END_SCAN                2
26
27 #define pci_dma_lo32(a)                 (a & 0xffffffff)
28
29 typedef u8              UCHAR;  /*  8 bits */
30 typedef u16             USHORT; /* 16 bits */
31 typedef u32             UINT;   /* 32 bits */
32 typedef unsigned long   ULONG;  /* 32/64 bits */
33
34 typedef UCHAR           *PUCHAR;
35 typedef USHORT          *PUSHORT;
36 typedef UINT            *PUINT;
37 typedef ULONG           *PULONG;
38 typedef Scsi_Host_Template      *PSHT;
39 typedef struct Scsi_Host        *PSH;
40 typedef Scsi_Device     *PSCSIDEV;
41 typedef Scsi_Cmnd       *PSCSICMD;
42 typedef void            *PVOID;
43 typedef struct scatterlist  *PSGL, SGL;
44
45
46 /*;-----------------------------------------------------------------------*/
47 typedef  struct  _SyncMsg
48 {
49 UCHAR           ExtendMsg;
50 UCHAR           ExtMsgLen;
51 UCHAR           SyncXferReq;
52 UCHAR           Period;
53 UCHAR           ReqOffset;
54 } SyncMsg;
55 /*;-----------------------------------------------------------------------*/
56 typedef  struct  _Capacity
57 {
58 ULONG           BlockCount;
59 ULONG           BlockLength;
60 } Capacity;
61 /*;-----------------------------------------------------------------------*/
62 typedef  struct  _SGentry
63 {
64 ULONG           SGXferDataPtr;
65 ULONG           SGXferDataLen;
66 } SGentry;
67
68 typedef  struct  _SGentry1
69 {
70 ULONG           SGXLen;
71 ULONG           SGXPtr;
72 } SGentry1, *PSGE;
73
74
75 /*
76 ;-----------------------------------------------------------------------
77 ; SCSI Request Block
78 ;-----------------------------------------------------------------------
79 */
80 struct  _SRB
81 {
82 //UCHAR         CmdBlock[12];
83
84 struct _SRB     *pNextSRB;
85 struct _DCB     *pSRBDCB;
86 PSCSICMD        pcmd;
87 PSGL            pSegmentList;
88
89 /* 0x10: */
90 SGL             Segmentx;       /* make a one entry of S/G list table */
91
92 /* 0x1c: */
93 ULONG           SGBusAddr;      /*;a segment starting address as seen by AM53C974A*/
94 ULONG           SGToBeXferLen;  /*; to be xfer length */
95 ULONG           TotalXferredLen;
96 ULONG           SavedTotXLen;
97 UINT            SRBState;
98
99 /* 0x30: */
100 UCHAR           SRBStatus;
101 UCHAR           SRBFlag;        /*; b0-AutoReqSense,b6-Read,b7-write */
102                                 /*; b4-settimeout,b5-Residual valid */
103 UCHAR           AdaptStatus;
104 UCHAR           TargetStatus;
105
106 UCHAR           ScsiPhase;
107 UCHAR           TagNumber;
108 UCHAR           SGIndex;
109 UCHAR           SGcount;
110
111 /* 0x38: */
112 UCHAR           MsgCnt;
113 UCHAR           EndMessage;
114 UCHAR           RetryCnt;
115 UCHAR           SavedSGCount;                   
116
117 ULONG           Saved_Ptr;
118
119 /* 0x40: */
120 UCHAR           MsgInBuf[6];
121 UCHAR           MsgOutBuf[6];
122
123 //UCHAR         IORBFlag;       /*;81h-Reset, 2-retry */
124 /* 0x4c: */
125 };
126
127
128 typedef  struct  _SRB    DC390_SRB, *PSRB;
129
130 /*
131 ;-----------------------------------------------------------------------
132 ; Device Control Block
133 ;-----------------------------------------------------------------------
134 */
135 struct  _DCB
136 {
137 struct _DCB     *pNextDCB;
138 struct _ACB     *pDCBACB;
139
140 /* Aborted Commands */
141 //PSCSICMD      AboIORBhead;
142 //PSCSICMD      AboIORBtail;
143 //ULONG         AboIORBcnt;
144
145 /* 0x08: */
146 /* Queued SRBs */
147 PSRB            pWaitingSRB;
148 PSRB            pWaitLast;
149 PSRB            pGoingSRB;
150 PSRB            pGoingLast;
151 PSRB            pActiveSRB;
152 UCHAR           WaitSRBCnt;     /* Not used */
153 UCHAR           GoingSRBCnt;
154
155 UCHAR           DevType;
156 UCHAR           MaxCommand;
157
158 /* 0x20: */
159 UINT            TagMask;
160
161 UCHAR           TargetID;       /*; SCSI Target ID  (SCSI Only) */
162 UCHAR           TargetLUN;      /*; SCSI Log.  Unit (SCSI Only) */
163 UCHAR           DevMode;
164 UCHAR           DCBFlag;
165
166 UCHAR           CtrlR1;
167 UCHAR           CtrlR3;
168 UCHAR           CtrlR4;
169 UCHAR           Inquiry7;
170
171 /* 0x2c: */
172 UCHAR           SyncMode;       /*; 0:async mode */
173 UCHAR           NegoPeriod;     /*;for nego. */
174 UCHAR           SyncPeriod;     /*;for reg. */
175 UCHAR           SyncOffset;     /*;for reg. and nego.(low nibble) */
176
177 /* 0x30:*/
178 //UCHAR         InqDataBuf[8];
179 //UCHAR         CapacityBuf[8];
180 ///* 0x40: */
181 };
182
183 typedef  struct  _DCB    DC390_DCB, *PDCB;
184 /*
185 ;-----------------------------------------------------------------------
186 ; Adapter Control Block
187 ;-----------------------------------------------------------------------
188 */
189 struct  _ACB
190 {
191 PSH             pScsiHost;
192 struct _ACB     *pNextACB;
193 USHORT          IOPortBase;
194 UCHAR           IRQLevel;
195 UCHAR           status;
196
197 UCHAR           SRBCount;
198 UCHAR           AdapterIndex;   /*; nth Adapter this driver */
199 UCHAR           DeviceCnt;
200 UCHAR           DCBCnt;
201
202 /* 0x10: */
203 UCHAR           TagMaxNum;
204 UCHAR           ACBFlag;
205 UCHAR           Gmode2;
206 UCHAR           scan_devices;
207
208 PDCB            pLinkDCB;
209 PDCB            pLastDCB;
210 PDCB            pDCBRunRobin;
211
212 PDCB            pActiveDCB;
213 PSRB            pFreeSRB;
214 PSRB            pTmpSRB;
215
216 /* 0x2c: */
217 ULONG           QueryCnt;
218 struct list_head        cmdq;
219
220 /* 0x38: */
221 UCHAR           msgin123[4];
222 UCHAR           DCBmap[MAX_SCSI_ID];
223 UCHAR           Connected;
224 UCHAR           pad;
225
226 /* 0x3c: */
227 #if defined(USE_SPINLOCKS) && USE_SPINLOCKS > 1 && (defined(CONFIG_SMP) || DEBUG_SPINLOCKS > 0)
228 spinlock_t      lock;
229 #endif
230 UCHAR           sel_timeout;
231 UCHAR           glitch_cfg;
232
233 UCHAR           MsgLen;
234 UCHAR           Ignore_IRQ;     /* Not used */
235
236 PDEVDECL1;                      /* Pointer to PCI cfg. space */
237 /* 0x4c/0x48: */
238 ULONG           Cmds;
239 UINT            SelLost;
240 UINT            SelConn;
241 UINT            CmdInQ;
242 UINT            CmdOutOfSRB;
243         
244 /* 0x60/0x5c: */
245 struct timer_list       Waiting_Timer;
246 /* 0x74/0x70: */
247 DC390_SRB       TmpSRB;
248 /* 0xd8/0xd4: */
249 DC390_SRB       SRB_array[MAX_SRB_CNT];         /* 50 SRBs */
250 /* 0xfb0/0xfac: */
251 };
252
253 typedef  struct  _ACB    DC390_ACB, *PACB;
254
255 /*;-----------------------------------------------------------------------*/
256
257
258 #define BIT31   0x80000000
259 #define BIT30   0x40000000
260 #define BIT29   0x20000000
261 #define BIT28   0x10000000
262 #define BIT27   0x08000000
263 #define BIT26   0x04000000
264 #define BIT25   0x02000000
265 #define BIT24   0x01000000
266 #define BIT23   0x00800000
267 #define BIT22   0x00400000
268 #define BIT21   0x00200000
269 #define BIT20   0x00100000
270 #define BIT19   0x00080000
271 #define BIT18   0x00040000
272 #define BIT17   0x00020000
273 #define BIT16   0x00010000
274 #define BIT15   0x00008000
275 #define BIT14   0x00004000
276 #define BIT13   0x00002000
277 #define BIT12   0x00001000
278 #define BIT11   0x00000800
279 #define BIT10   0x00000400
280 #define BIT9    0x00000200
281 #define BIT8    0x00000100
282 #define BIT7    0x00000080
283 #define BIT6    0x00000040
284 #define BIT5    0x00000020
285 #define BIT4    0x00000010
286 #define BIT3    0x00000008
287 #define BIT2    0x00000004
288 #define BIT1    0x00000002
289 #define BIT0    0x00000001
290
291 /*;---UnitCtrlFlag */
292 #define UNIT_ALLOCATED  BIT0
293 #define UNIT_INFO_CHANGED BIT1
294 #define FORMATING_MEDIA BIT2
295 #define UNIT_RETRY      BIT3
296
297 /*;---UnitFlags */
298 #define DASD_SUPPORT    BIT0
299 #define SCSI_SUPPORT    BIT1
300 #define ASPI_SUPPORT    BIT2
301
302 /*;----SRBState machine definition */
303 #define SRB_FREE        0
304 #define SRB_WAIT        BIT0
305 #define SRB_READY       BIT1
306 #define SRB_MSGOUT      BIT2    /*;arbitration+msg_out 1st byte*/
307 #define SRB_MSGIN       BIT3
308 #define SRB_MSGIN_MULTI BIT4
309 #define SRB_COMMAND     BIT5
310 #define SRB_START_      BIT6    /*;arbitration+msg_out+command_out*/
311 #define SRB_DISCONNECT  BIT7
312 #define SRB_DATA_XFER   BIT8
313 #define SRB_XFERPAD     BIT9
314 #define SRB_STATUS      BIT10
315 #define SRB_COMPLETED   BIT11
316 #define SRB_ABORT_SENT  BIT12
317 #define DO_SYNC_NEGO    BIT13
318 #define SRB_UNEXPECT_RESEL BIT14
319
320 /*;---SRBstatus */
321 #define SRB_OK          BIT0
322 #define ABORTION        BIT1
323 #define OVER_RUN        BIT2
324 #define UNDER_RUN       BIT3
325 #define PARITY_ERROR    BIT4
326 #define SRB_ERROR       BIT5
327
328 /*;---ACBFlag */
329 #define RESET_DEV       BIT0
330 #define RESET_DETECT    BIT1
331 #define RESET_DONE      BIT2
332
333 /*;---DCBFlag */
334 #define ABORT_DEV_      BIT0
335
336 /*;---SRBFlag */
337 #define DATAOUT         BIT7
338 #define DATAIN          BIT6
339 #define RESIDUAL_VALID  BIT5
340 #define ENABLE_TIMER    BIT4
341 #define RESET_DEV0      BIT2
342 #define ABORT_DEV       BIT1
343 #define AUTO_REQSENSE   BIT0
344
345 /*;---Adapter status */
346 #define H_STATUS_GOOD    0
347 #define H_SEL_TIMEOUT    0x11
348 #define H_OVER_UNDER_RUN 0x12
349 #define H_UNEXP_BUS_FREE 0x13
350 #define H_TARGET_PHASE_F 0x14
351 #define H_INVALID_CCB_OP 0x16
352 #define H_LINK_CCB_BAD   0x17
353 #define H_BAD_TARGET_DIR 0x18
354 #define H_DUPLICATE_CCB  0x19
355 #define H_BAD_CCB_OR_SG  0x1A
356 #define H_ABORT          0x0FF
357
358 /*; SCSI Status byte codes*/ 
359 /* The values defined in include/scsi/scsi.h, to be shifted << 1 */
360
361 #define SCSI_STAT_UNEXP_BUS_F   0xFD    /*;  Unexpect Bus Free */
362 #define SCSI_STAT_BUS_RST_DETECT 0xFE   /*;  Scsi Bus Reset detected */
363 #define SCSI_STAT_SEL_TIMEOUT   0xFF    /*;  Selection Time out */
364
365 /* cmd->result */
366 #define RES_TARGET              0x000000FF      /* Target State */
367 #define RES_TARGET_LNX          STATUS_MASK     /* Only official ... */
368 #define RES_ENDMSG              0x0000FF00      /* End Message */
369 #define RES_DID                 0x00FF0000      /* DID_ codes */
370 #define RES_DRV                 0xFF000000      /* DRIVER_ codes */
371
372 #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
373 #define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)<<1)
374
375 #define SET_RES_TARGET(who,tgt) { who &= ~RES_TARGET; who |= (int)(tgt); }
376 #define SET_RES_TARGET_LNX(who,tgt) { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; }
377 #define SET_RES_MSG(who,msg) { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; }
378 #define SET_RES_DID(who,did) { who &= ~RES_DID; who |= (int)(did) << 16; }
379 #define SET_RES_DRV(who,drv) { who &= ~RES_DRV; who |= (int)(drv) << 24; }
380
381 /*;---Sync_Mode */
382 #define SYNC_DISABLE    0
383 #define SYNC_ENABLE     BIT0
384 #define SYNC_NEGO_DONE  BIT1
385 #define WIDE_ENABLE     BIT2    /* Not used ;-) */
386 #define WIDE_NEGO_DONE  BIT3    /* Not used ;-) */
387 #define EN_TAG_QUEUEING BIT4
388 #define EN_ATN_STOP     BIT5
389
390 #define SYNC_NEGO_OFFSET 15
391
392 /*;---SCSI bus phase*/
393 #define SCSI_DATA_OUT   0
394 #define SCSI_DATA_IN    1
395 #define SCSI_COMMAND    2
396 #define SCSI_STATUS_    3
397 #define SCSI_NOP0       4
398 #define SCSI_NOP1       5
399 #define SCSI_MSG_OUT    6
400 #define SCSI_MSG_IN     7
401
402 /*;----SCSI MSG BYTE*/ /* see scsi/scsi.h */ /* One is missing ! */
403 #define ABORT_TAG       0x0d
404
405 /*
406  *      SISC query queue
407  */
408 typedef struct {
409         struct list_head        list;
410         dma_addr_t              saved_dma_handle;
411 } dc390_cmd_scp_t;
412
413 struct scsi_cmnd_list
414 {
415         char dummy[offsetof(struct scsi_cmnd, SCp)];
416         dc390_cmd_scp_t scp;
417 };
418
419 /*
420 **  Inquiry Data format
421 */
422
423 typedef struct  _SCSIInqData { /* INQUIRY */
424
425         UCHAR    DevType;               /* Periph Qualifier & Periph Dev Type*/
426         UCHAR    RMB_TypeMod;           /* rem media bit & Dev Type Modifier */
427         UCHAR    Vers;                  /* ISO, ECMA, & ANSI versions        */
428         UCHAR    RDF;                   /* AEN, TRMIOP, & response data format*/
429         UCHAR    AddLen;                /* length of additional data         */
430         UCHAR    Res1;                  /* reserved                          */
431         UCHAR    Res2;                  /* reserved                          */
432         UCHAR    Flags;                 /* RelADr,Wbus32,Wbus16,Sync,etc.    */
433         UCHAR    VendorID[8];           /* Vendor Identification             */
434         UCHAR    ProductID[16];         /* Product Identification            */
435         UCHAR    ProductRev[4];         /* Product Revision                  */
436
437
438 } SCSI_INQDATA, *PSCSI_INQDATA;
439
440
441 /*  Inquiry byte 0 masks */
442
443
444 #define SCSI_DEVTYPE        0x1F      /* Peripheral Device Type             */
445 #define SCSI_PERIPHQUAL     0xE0      /* Peripheral Qualifier               */
446 #define TYPE_NODEV          SCSI_DEVTYPE    /* Unknown or no device type    */
447
448
449 /*  Inquiry byte 1 mask */
450
451 #define SCSI_REMOVABLE_MEDIA  0x80    /* Removable Media bit (1=removable)  */
452
453
454 /*  Peripheral Device Type definitions */
455 /*  see include/scsi/scsi.h for the rest */
456
457 #ifndef TYPE_PRINTER
458 # define TYPE_PRINTER            0x02      /* Printer device               */
459 #endif
460 #ifndef TYPE_COMM
461 # define TYPE_COMM               0x09      /* Communications device        */
462 #endif
463
464 /*
465 ** Inquiry flag definitions (Inq data byte 7)
466 */
467
468 #define SCSI_INQ_RELADR       0x80    /* device supports relative addressing*/
469 #define SCSI_INQ_WBUS32       0x40    /* device supports 32 bit data xfers  */
470 #define SCSI_INQ_WBUS16       0x20    /* device supports 16 bit data xfers  */
471 #define SCSI_INQ_SYNC         0x10    /* device supports synchronous xfer   */
472 #define SCSI_INQ_LINKED       0x08    /* device supports linked commands    */
473 #define SCSI_INQ_CMDQUEUE     0x02    /* device supports command queueing   */
474 #define SCSI_INQ_SFTRE        0x01    /* device supports soft resets */
475
476
477 /*
478 ;==========================================================
479 ; EEPROM byte offset
480 ;==========================================================
481 */
482 typedef  struct  _EEprom
483 {
484 UCHAR   EE_MODE1;
485 UCHAR   EE_SPEED;
486 UCHAR   xx1;
487 UCHAR   xx2;
488 } EEprom, *PEEprom;
489
490 #define REAL_EE_ADAPT_SCSI_ID 64
491 #define REAL_EE_MODE2   65
492 #define REAL_EE_DELAY   66
493 #define REAL_EE_TAG_CMD_NUM     67
494
495 #define EE_ADAPT_SCSI_ID 32
496 #define EE_MODE2        33
497 #define EE_DELAY        34
498 #define EE_TAG_CMD_NUM  35
499
500 #define EE_LEN          40
501
502 /*; EE_MODE1 bits definition*/
503 #define PARITY_CHK_     BIT0
504 #define SYNC_NEGO_      BIT1
505 #define EN_DISCONNECT_  BIT2
506 #define SEND_START_     BIT3
507 #define TAG_QUEUEING_   BIT4
508
509 /*; EE_MODE2 bits definition*/
510 #define MORE2_DRV       BIT0
511 #define GREATER_1G      BIT1
512 #define RST_SCSI_BUS    BIT2
513 #define ACTIVE_NEGATION BIT3
514 #define NO_SEEK         BIT4
515 #define LUN_CHECK       BIT5
516
517 #define ENABLE_CE       1
518 #define DISABLE_CE      0
519 #define EEPROM_READ     0x80
520
521 /*
522 ;==========================================================
523 ;       AMD 53C974 Registers bit Definition
524 ;==========================================================
525 */
526 /*
527 ;====================
528 ; SCSI Register
529 ;====================
530 */
531
532 /*; Command Reg.(+0CH) (rw) */
533 #define DMA_COMMAND             BIT7
534 #define NOP_CMD                 0
535 #define CLEAR_FIFO_CMD          1
536 #define RST_DEVICE_CMD          2
537 #define RST_SCSI_BUS_CMD        3
538
539 #define INFO_XFER_CMD           0x10
540 #define INITIATOR_CMD_CMPLTE    0x11
541 #define MSG_ACCEPTED_CMD        0x12
542 #define XFER_PAD_BYTE           0x18
543 #define SET_ATN_CMD             0x1A
544 #define RESET_ATN_CMD           0x1B
545
546 #define SEL_WO_ATN              0x41    /* currently not used */
547 #define SEL_W_ATN               0x42
548 #define SEL_W_ATN_STOP          0x43
549 #define SEL_W_ATN3              0x46
550 #define EN_SEL_RESEL            0x44
551 #define DIS_SEL_RESEL           0x45    /* currently not used */
552 #define RESEL                   0x40    /* " */
553 #define RESEL_ATN3              0x47    /* " */
554
555 #define DATA_XFER_CMD           INFO_XFER_CMD
556
557
558 /*; SCSI Status Reg.(+10H) (r) */
559 #define INTERRUPT               BIT7
560 #define ILLEGAL_OP_ERR          BIT6
561 #define PARITY_ERR              BIT5
562 #define COUNT_2_ZERO            BIT4
563 #define GROUP_CODE_VALID        BIT3
564 #define SCSI_PHASE_MASK         (BIT2+BIT1+BIT0) 
565 /* BIT2: MSG phase; BIT1: C/D physe; BIT0: I/O phase */
566
567 /*; Interrupt Status Reg.(+14H) (r) */
568 #define SCSI_RESET              BIT7
569 #define INVALID_CMD             BIT6
570 #define DISCONNECTED            BIT5
571 #define SERVICE_REQUEST         BIT4
572 #define SUCCESSFUL_OP           BIT3
573 #define RESELECTED              BIT2
574 #define SEL_ATTENTION           BIT1
575 #define SELECTED                BIT0
576
577 /*; Internal State Reg.(+18H) (r) */
578 #define SYNC_OFFSET_FLAG        BIT3
579 #define INTRN_STATE_MASK        (BIT2+BIT1+BIT0)
580 /* 0x04: Sel. successful (w/o stop), 0x01: Sel. successful (w/ stop) */
581
582 /*; Clock Factor Reg.(+24H) (w) */
583 #define CLK_FREQ_40MHZ          0
584 #define CLK_FREQ_35MHZ          (BIT2+BIT1+BIT0)
585 #define CLK_FREQ_30MHZ          (BIT2+BIT1)
586 #define CLK_FREQ_25MHZ          (BIT2+BIT0)
587 #define CLK_FREQ_20MHZ          BIT2
588 #define CLK_FREQ_15MHZ          (BIT1+BIT0)
589 #define CLK_FREQ_10MHZ          BIT1
590
591 /*; Control Reg. 1(+20H) (rw) */
592 #define EXTENDED_TIMING         BIT7
593 #define DIS_INT_ON_SCSI_RST     BIT6
594 #define PARITY_ERR_REPO         BIT4
595 #define SCSI_ID_ON_BUS          (BIT2+BIT1+BIT0) /* host adapter ID */
596
597 /*; Control Reg. 2(+2CH) (rw) */
598 #define EN_FEATURE              BIT6
599 #define EN_SCSI2_CMD            BIT3
600
601 /*; Control Reg. 3(+30H) (rw) */
602 #define ID_MSG_CHECK            BIT7
603 #define EN_QTAG_MSG             BIT6
604 #define EN_GRP2_CMD             BIT5
605 #define FAST_SCSI               BIT4    /* ;10MB/SEC */
606 #define FAST_CLK                BIT3    /* ;25 - 40 MHZ */
607
608 /*; Control Reg. 4(+34H) (rw) */
609 #define EATER_12NS              0
610 #define EATER_25NS              BIT7
611 #define EATER_35NS              BIT6
612 #define EATER_0NS               (BIT7+BIT6)
613 #define REDUCED_POWER           BIT5
614 #define CTRL4_RESERVED          BIT4    /* must be 1 acc. to AM53C974.c */
615 #define NEGATE_REQACKDATA       BIT2
616 #define NEGATE_REQACK           BIT3
617
618 #define GLITCH_TO_NS(x) (((~x>>6 & 2) >> 1) | ((x>>6 & 1) << 1 ^ (x>>6 & 2)))
619 #define NS_TO_GLITCH(y) (((~y<<7) | ~((y<<6) ^ ((y<<5 & 1<<6) | ~0x40))) & 0xc0)
620
621 /*
622 ;====================
623 ; DMA Register
624 ;====================
625 */
626 /*; DMA Command Reg.(+40H) (rw) */
627 #define READ_DIRECTION          BIT7
628 #define WRITE_DIRECTION         0
629 #define EN_DMA_INT              BIT6
630 #define EN_PAGE_INT             BIT5    /* page transfer interrupt enable */
631 #define MAP_TO_MDL              BIT4
632 #define DIAGNOSTIC              BIT2
633 #define DMA_IDLE_CMD            0
634 #define DMA_BLAST_CMD           BIT0
635 #define DMA_ABORT_CMD           BIT1
636 #define DMA_START_CMD           (BIT1+BIT0)
637
638 /*; DMA Status Reg.(+54H) (r) */
639 #define PCI_MS_ABORT            BIT6
640 #define BLAST_COMPLETE          BIT5
641 #define SCSI_INTERRUPT          BIT4
642 #define DMA_XFER_DONE           BIT3
643 #define DMA_XFER_ABORT          BIT2
644 #define DMA_XFER_ERROR          BIT1
645 #define POWER_DOWN              BIT0
646
647 /*; DMA SCSI Bus and Ctrl.(+70H) */
648 #define EN_INT_ON_PCI_ABORT     BIT25
649 #define WRT_ERASE_DMA_STAT      BIT24
650 #define PW_DOWN_CTRL            BIT21
651 #define SCSI_BUSY               BIT20
652 #define SCLK                    BIT19
653 #define SCAM                    BIT18
654 #define SCSI_LINES              0x0003ffff
655
656 /*
657 ;==========================================================
658 ; SCSI Chip register address offset
659 ;==========================================================
660 ;Registers are rw unless declared otherwise 
661 */
662 #define CtcReg_Low      0x00    /* r    curr. transfer count */
663 #define CtcReg_Mid      0x04    /* r */
664 #define CtcReg_High     0x38    /* r */
665 #define ScsiFifo        0x08
666 #define ScsiCmd         0x0C
667 #define Scsi_Status     0x10    /* r */
668 #define INT_Status      0x14    /* r */
669 #define Sync_Period     0x18    /* w */
670 #define Sync_Offset     0x1C    /* w */
671 #define Clk_Factor      0x24    /* w */
672 #define CtrlReg1        0x20    
673 #define CtrlReg2        0x2C
674 #define CtrlReg3        0x30
675 #define CtrlReg4        0x34
676 #define DMA_Cmd         0x40
677 #define DMA_XferCnt     0x44    /* rw   starting transfer count (32 bit) */
678 #define DMA_XferAddr    0x48    /* rw   starting physical address (32 bit) */
679 #define DMA_Wk_ByteCntr 0x4C    /* r    working byte counter */
680 #define DMA_Wk_AddrCntr 0x50    /* r    working address counter */
681 #define DMA_Status      0x54    /* r */
682 #define DMA_MDL_Addr    0x58    /* rw   starting MDL address */
683 #define DMA_Wk_MDL_Cntr 0x5C    /* r    working MDL counter */
684 #define DMA_ScsiBusCtrl 0x70    /* rw   SCSI Bus, PCI/DMA Ctrl */
685
686 #define StcReg_Low      CtcReg_Low      /* w    start transfer count */
687 #define StcReg_Mid      CtcReg_Mid      /* w */
688 #define StcReg_High     CtcReg_High     /* w */
689 #define Scsi_Dest_ID    Scsi_Status     /* w */
690 #define Scsi_TimeOut    INT_Status      /* w */
691 #define Intern_State    Sync_Period     /* r */
692 #define Current_Fifo    Sync_Offset     /* r    Curr. FIFO / int. state */
693
694
695 #define DC390_read8(address)                    \
696         (inb (pACB->IOPortBase + (address)))
697
698 #define DC390_read8_(address, base)             \
699         (inb ((USHORT)(base) + (address)))
700
701 #define DC390_read16(address)                   \
702         (inw (pACB->IOPortBase + (address)))
703
704 #define DC390_read32(address)                   \
705         (inl (pACB->IOPortBase + (address)))
706
707 #define DC390_write8(address,value)             \
708         outb ((value), pACB->IOPortBase + (address))
709
710 #define DC390_write8_(address,value,base)       \
711         outb ((value), (USHORT)(base) + (address))
712
713 #define DC390_write16(address,value)            \
714         outw ((value), pACB->IOPortBase + (address))
715
716 #define DC390_write32(address,value)            \
717         outl ((value), pACB->IOPortBase + (address))
718
719
720 #endif /* _TMSCSIM_H */