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