[NET_SCHED]: Fix endless loops caused by inaccurate qlen counters (part 1)
[hh.org.git] / drivers / scsi / tmscsim.h
blob9b66fa8d38d948129df809016c0e81deb87cc900
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 $ */
8 #ifndef _TMSCSIM_H
9 #define _TMSCSIM_H
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 */
17 #define MAX_SCSI_ID 8
18 #define MAX_SRB_CNT 50 /* Max number of started commands */
20 #define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */
22 #define pci_dma_lo32(a) (a & 0xffffffff)
24 typedef u8 UCHAR; /* 8 bits */
25 typedef u16 USHORT; /* 16 bits */
26 typedef u32 UINT; /* 32 bits */
27 typedef unsigned long ULONG; /* 32/64 bits */
31 ;-----------------------------------------------------------------------
32 ; SCSI Request Block
33 ;-----------------------------------------------------------------------
35 struct dc390_srb
37 //u8 CmdBlock[12];
39 struct dc390_srb *pNextSRB;
40 struct dc390_dcb *pSRBDCB;
41 struct scsi_cmnd *pcmd;
42 struct scatterlist *pSegmentList;
44 struct scatterlist Segmentx; /* make a one entry of S/G list table */
46 unsigned long SGBusAddr; /*;a segment starting address as seen by AM53C974A*/
47 unsigned long SGToBeXferLen; /*; to be xfer length */
48 unsigned long TotalXferredLen;
49 unsigned long SavedTotXLen;
50 unsigned long Saved_Ptr;
51 u32 SRBState;
53 u8 SRBStatus;
54 u8 SRBFlag; /*; b0-AutoReqSense,b6-Read,b7-write */
55 /*; b4-settimeout,b5-Residual valid */
56 u8 AdaptStatus;
57 u8 TargetStatus;
59 u8 ScsiPhase;
60 s8 TagNumber;
61 u8 SGIndex;
62 u8 SGcount;
64 u8 MsgCnt;
65 u8 EndMessage;
66 u8 SavedSGCount;
68 u8 MsgInBuf[6];
69 u8 MsgOutBuf[6];
71 //u8 IORBFlag; /*;81h-Reset, 2-retry */
76 ;-----------------------------------------------------------------------
77 ; Device Control Block
78 ;-----------------------------------------------------------------------
80 struct dc390_dcb
82 struct dc390_dcb *pNextDCB;
83 struct dc390_acb *pDCBACB;
85 /* Queued SRBs */
86 struct dc390_srb *pGoingSRB;
87 struct dc390_srb *pGoingLast;
88 struct dc390_srb *pActiveSRB;
89 u8 GoingSRBCnt;
91 u32 TagMask;
93 u8 TargetID; /*; SCSI Target ID (SCSI Only) */
94 u8 TargetLUN; /*; SCSI Log. Unit (SCSI Only) */
95 u8 DevMode;
96 u8 DCBFlag;
98 u8 CtrlR1;
99 u8 CtrlR3;
100 u8 CtrlR4;
102 u8 SyncMode; /*; 0:async mode */
103 u8 NegoPeriod; /*;for nego. */
104 u8 SyncPeriod; /*;for reg. */
105 u8 SyncOffset; /*;for reg. and nego.(low nibble) */
110 ;-----------------------------------------------------------------------
111 ; Adapter Control Block
112 ;-----------------------------------------------------------------------
114 struct dc390_acb
116 struct Scsi_Host *pScsiHost;
117 u16 IOPortBase;
118 u8 IRQLevel;
119 u8 status;
121 u8 SRBCount;
122 u8 AdapterIndex; /*; nth Adapter this driver */
123 u8 DCBCnt;
125 u8 TagMaxNum;
126 u8 ACBFlag;
127 u8 Gmode2;
128 u8 scan_devices;
130 struct dc390_dcb *pLinkDCB;
131 struct dc390_dcb *pLastDCB;
132 struct dc390_dcb *pDCBRunRobin;
134 struct dc390_dcb *pActiveDCB;
135 struct dc390_srb *pFreeSRB;
136 struct dc390_srb *pTmpSRB;
138 u8 msgin123[4];
139 u8 Connected;
140 u8 pad;
142 #if defined(USE_SPINLOCKS) && USE_SPINLOCKS > 1 && (defined(CONFIG_SMP) || DEBUG_SPINLOCKS > 0)
143 spinlock_t lock;
144 #endif
145 u8 sel_timeout;
146 u8 glitch_cfg;
148 u8 MsgLen;
149 u8 Ignore_IRQ; /* Not used */
151 struct pci_dev *pdev;
153 unsigned long Cmds;
154 u32 SelLost;
155 u32 SelConn;
156 u32 CmdInQ;
157 u32 CmdOutOfSRB;
159 struct dc390_srb TmpSRB;
160 struct dc390_srb SRB_array[MAX_SRB_CNT]; /* 50 SRBs */
164 /*;-----------------------------------------------------------------------*/
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
200 /*;---UnitCtrlFlag */
201 #define UNIT_ALLOCATED BIT0
202 #define UNIT_INFO_CHANGED BIT1
203 #define FORMATING_MEDIA BIT2
204 #define UNIT_RETRY BIT3
206 /*;---UnitFlags */
207 #define DASD_SUPPORT BIT0
208 #define SCSI_SUPPORT BIT1
209 #define ASPI_SUPPORT BIT2
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
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
237 /*;---ACBFlag */
238 #define RESET_DEV BIT0
239 #define RESET_DETECT BIT1
240 #define RESET_DONE BIT2
242 /*;---DCBFlag */
243 #define ABORT_DEV_ BIT0
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
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
267 /*; SCSI Status byte codes*/
268 /* The values defined in include/scsi/scsi.h, to be shifted << 1 */
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 */
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 */
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)
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)
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
299 #define SYNC_NEGO_OFFSET 15
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
311 /*;----SCSI MSG BYTE*/ /* see scsi/scsi.h */ /* One is missing ! */
312 #define ABORT_TAG 0x0d
315 * SISC query queue
317 typedef struct {
318 dma_addr_t saved_dma_handle;
319 } dc390_cmd_scp_t;
322 ;==========================================================
323 ; EEPROM byte offset
324 ;==========================================================
326 typedef struct _EEprom
328 u8 EE_MODE1;
329 u8 EE_SPEED;
330 u8 xx1;
331 u8 xx2;
332 } EEprom, *PEEprom;
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
339 #define EE_ADAPT_SCSI_ID 32
340 #define EE_MODE2 33
341 #define EE_DELAY 34
342 #define EE_TAG_CMD_NUM 35
344 #define EE_LEN 40
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
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
361 #define ENABLE_CE 1
362 #define DISABLE_CE 0
363 #define EEPROM_READ 0x80
366 ;==========================================================
367 ; AMD 53C974 Registers bit Definition
368 ;==========================================================
371 ;====================
372 ; SCSI Register
373 ;====================
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
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
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 /* " */
399 #define DATA_XFER_CMD INFO_XFER_CMD
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 */
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
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) */
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
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 */
441 /*; Control Reg. 2(+2CH) (rw) */
442 #define EN_FEATURE BIT6
443 #define EN_SCSI2_CMD BIT3
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 */
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
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)
466 ;====================
467 ; DMA Register
468 ;====================
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)
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
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
501 ;==========================================================
502 ; SCSI Chip register address offset
503 ;==========================================================
504 ;Registers are rw unless declared otherwise
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 */
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 */
539 #define DC390_read8(address) \
540 (inb (pACB->IOPortBase + (address)))
542 #define DC390_read8_(address, base) \
543 (inb ((u16)(base) + (address)))
545 #define DC390_read16(address) \
546 (inw (pACB->IOPortBase + (address)))
548 #define DC390_read32(address) \
549 (inl (pACB->IOPortBase + (address)))
551 #define DC390_write8(address,value) \
552 outb ((value), pACB->IOPortBase + (address))
554 #define DC390_write8_(address,value,base) \
555 outb ((value), (u16)(base) + (address))
557 #define DC390_write16(address,value) \
558 outw ((value), pACB->IOPortBase + (address))
560 #define DC390_write32(address,value) \
561 outl ((value), pACB->IOPortBase + (address))
564 #endif /* _TMSCSIM_H */