Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / disk / i386 / bs / bsvar.h
1 /*      $NecBSD: bsvar.h,v 1.2 1997/10/31 17:43:41 honda Exp $  */
2 /*      $NetBSD$        */
3 /*
4  * [NetBSD for NEC PC98 series]
5  *  Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
6  *  All rights reserved.
7  * 
8  *  Redistribution and use in source and binary forms, with or without
9  *  modification, are permitted provided that the following conditions
10  *  are met:
11  *  1. Redistributions of source code must retain the above copyright
12  *     notice, this list of conditions and the following disclaimer.
13  *  2. Redistributions in binary form must reproduce the above copyright
14  *     notice, this list of conditions and the following disclaimer in the
15  *     documentation and/or other materials provided with the distribution.
16  *  3. The name of the author may not be used to endorse or promote products
17  *     derived from this software without specific prior written permission.
18  * 
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD: src/sys/i386/isa/bs/bsvar.h,v 1.6.6.1 2000/03/22 03:36:45 nyan Exp $
32  * $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsvar.h,v 1.2 2003/06/17 04:28:37 dillon Exp $
33  */
34 /*
35  * Copyright (c) 1994, 1995, 1996 Naofumi HONDA.  All rights reserved.
36  */
37
38 #ifdef __FreeBSD__
39 #define BS_INLINE       __inline
40 #else
41 #define BS_INLINE       inline
42 #endif
43
44 /**************************************************
45  *      CONTROL FLAGS  (cf_flags)
46  *************************************************/
47 #define BSC_FASTACK             0x01
48 #define BSC_SMITSAT_DISEN       0x02
49 #define BSC_CHIP_CLOCK(dvcfg)   (((dvcfg) >> 4) & 0x03)
50
51 #define BS_SCSI_SYNC            DVF_SCSI_SYNC
52 #define BS_SCSI_DISC            DVF_SCSI_DISC
53 #define BS_SCSI_WAIT            DVF_SCSI_WAIT
54 #define BS_SCSI_LINK            DVF_SCSI_LINK
55 #define BS_SCSI_QTAG            DVF_SCSI_QTAG
56 #define BS_SCSI_NOSAT           DVF_SCSI_SP0
57 #define BS_SCSI_NOPARITY        DVF_SCSI_NOPARITY
58 #define BS_SCSI_SAVESP          DVF_SCSI_SAVESP
59 #define BS_SCSI_NOSMIT          DVF_SCSI_SP1
60 #define BS_SCSI_PERIOD(XXX)     DVF_SCSI_PERIOD(XXX)
61 #define BS_SCSI_OFFSET(XXX)     DVF_SCSI_OFFSET(XXX)
62 #define BS_SCSI_SYNCMASK        DVF_SCSI_SYNCMASK
63 #define BS_SCSI_BITS            DVF_SCSI_BITS
64
65 #define BS_SCSI_DEFCFG          (BS_SCSI_NOSAT | DVF_SCSI_DEFCFG)
66
67 #define BS_SCSI_POSITIVE (BS_SCSI_SYNC | BS_SCSI_DISC | BS_SCSI_LINK)
68 #define BS_SCSI_NEGATIVE (BS_SCSI_WAIT | BS_SCSI_NOSAT | BS_SCSI_NOPARITY |\
69                           BS_SCSI_SAVESP | BS_SCSI_NOSMIT)
70 /*******************************************
71  * CONFIG SECTION
72  ******************************************/
73 /* Enable timeout watch dog */
74 #define BS_DEFAULT_TIMEOUT_SECOND       16      /* default 16 sec */
75 #define BS_SYNC_TIMEOUT                 16
76 #define BS_STARTUP_TIMEOUT              60
77 #define BS_MOTOR_TIMEOUT                120
78 #define BS_TIMEOUT_CHECK_INTERVAL       4       /* check each 4 sec */
79
80 /* If you use memory over 16M */
81 #ifdef  SCSI_BOUNCE_SIZE
82 #define BS_BOUNCE_SIZE  SCSI_BOUNCE_SIZE
83 #else   /* !SCSI_BOUNCE_SIZE */
84 #define BS_BOUNCE_SIZE  0
85 #endif  /* !SCSI_BOUNCE_SIZE */
86
87 /* debug */
88 #define BS_STATICS              1
89 #define BS_DIAG                 1
90 #define BS_DEBUG_ROUTINE        1
91 #define BS_DEBUG                1
92 /* #define      SHOW_PORT       1 */
93
94 /**************************************************
95  *      PARAMETER
96  **************************************************/
97 #define NTARGETS        8
98 #define RETRIES         1       /* number of retries before giving up */
99 #define HARDRETRIES     3
100 #define XSMAX           4
101 #define BSDMABUFSIZ     0x10000
102 #define BS_MAX_CCB      (XSMAX * (NTARGETS - 1))
103
104 #define BSCMDSTART      0
105 #define BSCMDRESTART    0x01
106 #define BSCMDFORCE      0x02
107
108 #define BS_TIMEOUT_INTERVAL     (hz * BS_TIMEOUT_CHECK_INTERVAL)
109
110 /**************************************************
111  *      SCSI PHASE
112  **************************************************/
113 enum scsi_phase {
114         FREE = 0,
115         HOSTQUEUE,
116         DISCONNECTED,
117         IOCOMPLETED,
118         ATTENTIONASSERT,
119         DISCONNECTASSERT,
120         SELECTASSERT,
121         SELECTED,
122         RESELECTED,
123         MSGIN,
124         MSGOUT,
125         STATUSIN,
126         CMDPHASE,
127         DATAPHASE,
128         SATSEL,
129         SATRESEL,
130         SATSDP,
131         SATCOMPSEQ,
132         UNDEF,
133 };
134
135 /**************************************************
136  *      SCSI PHASE CONTROL MACRO
137  **************************************************/
138 #define BS_HOST_START                                   \
139 {                                                       \
140         bsc->sc_nexus = ti;                             \
141 }
142
143 #define BS_HOST_TERMINATE                               \
144 {                                                       \
145         bsc->sc_selwait = NULL;                         \
146         bsc->sc_nexus = NULL;                           \
147 }
148
149 #define BS_SELECTION_START                              \
150 {                                                       \
151         bsc->sc_selwait = ti;                           \
152 }
153
154 #define BS_SELECTION_TERMINATE                          \
155 {                                                       \
156         bsc->sc_selwait = NULL;                         \
157 }
158
159 #define BS_SETUP_PHASE(PHASE)                           \
160 {                                                       \
161         ti->ti_ophase = ti->ti_phase;                   \
162         ti->ti_phase = (PHASE);                         \
163 }
164
165 #define BS_SETUP_MSGPHASE(PHASE)                        \
166 {                                                       \
167         bsc->sc_msgphase = (PHASE);                     \
168 }
169
170 #define BS_SETUP_SYNCSTATE(STATE)                       \
171 {                                                       \
172         ti->ti_syncnow.state = (STATE);                 \
173 }
174
175 #define BS_SETUP_TARGSTATE(STATE)                       \
176 {                                                       \
177         ti->ti_state = (STATE);                         \
178 }
179
180 #define BS_LOAD_SDP                                     \
181 {                                                       \
182         bsc->sc_p.data = ti->ti_scsp.data;              \
183         bsc->sc_p.datalen = ti->ti_scsp.datalen;        \
184         bsc->sc_p.seglen = ti->ti_scsp.seglen;          \
185 }
186
187 #define BS_RESTORE_SDP                                  \
188 {                                                       \
189         bsc->sc_p = ti->ti_scsp;                        \
190 }
191
192 #define BS_SAVE_SDP                                     \
193 {                                                       \
194         ti->ti_scsp = bsc->sc_p;                        \
195 }
196
197 /**************************************************
198  * STRUCTURES
199  **************************************************/
200 struct msgbase {
201 #define MAXMSGLEN       8
202         u_int8_t msg[MAXMSGLEN];
203         u_int msglen;
204
205         u_int flag;
206 };
207
208 struct syncdata {
209         u_int8_t period;
210         u_int8_t offset;
211
212 #define BS_SYNCMSG_NULL         0x00
213 #define BS_SYNCMSG_ASSERT       0x01
214 #define BS_SYNCMSG_REJECT       0x02
215 #define BS_SYNCMSG_ACCEPT       0x03
216 #define BS_SYNCMSG_REQUESTED    0x04
217         u_int state;
218 };
219
220 struct sc_p {
221         u_int8_t *data;
222         int datalen;
223
224         u_int8_t *segaddr;
225         int seglen;
226
227         u_int8_t *bufp;
228 };
229
230 /* targ_info error flags */
231 #define BSDMAABNORMAL   0x01
232 #define BSCMDABNORMAL   0x02
233 #define BSPARITY        0x04
234 #define BSSTATUSERROR   0x08
235 #define BSTIMEOUT       0x10
236 #define BSREQSENSE      0x20
237 #define BSSELTIMEOUT    0x40
238 #define BSFATALIO       0x80
239 #define BSMSGERROR      0x100
240 #define BSTRYRECOV      0x200
241 #define BSABNORMAL      0x400
242 #define BSTARGETBUSY    0x800
243
244 #define BSERRORBITS     "\020\014busy\013abnormal\012retry\011msgerr\010fatal\007seltimeout\006sense\005timeout\004statuserr\003parity\002cmderr\001dmaerr"
245
246 /* bsccb bsccb_flags & targ_info flags & cmd flags*/
247 #define BSREAD          0x0001
248 #define BSSAT           0x0002
249 #define BSLINK          0x0004
250 #define BSERROROK       0x0008
251 #define BSSMIT          0x0010
252 #define BSDISC          0x1000
253 #define BSFORCEIOPOLL   0x2000
254
255 #define BSCASTAT        0x01000000
256 #define BSSENSECCB      0x02000000
257 #define BSQUEUED        0x04000000
258 #define BSALTBUF        0x08000000
259 #define BSITSDONE       0x10000000
260 #define BSNEXUS         0x20000000
261
262 #define BSCFLAGSMASK    (0xffff)
263
264 struct bsccb {
265         TAILQ_ENTRY(bsccb) ccb_chain;
266
267         union ccb *ccb;                 /* upper drivers info */
268
269         u_int lun;                      /* lun */
270
271         u_int bsccb_flags;              /* control flags */
272
273         int rcnt;                       /* retry counter of this ccb */
274
275         u_int error;                    /* recorded error */
276
277         /*****************************************
278          * scsi cmd & data
279          *****************************************/
280         u_int8_t *cmd;                  /* scsi cmd */
281         int cmdlen;
282
283         u_int8_t *data;                 /* scsi data */
284         int datalen;
285
286         u_int8_t msgout[MAXMSGLEN];     /* scsi msgout */
287         u_int msgoutlen;
288
289         /*****************************************
290          * timeout counter
291          *****************************************/
292         int tc;
293         int tcmax;
294 };
295
296 GENERIC_CCB_ASSERT(bs, bsccb)
297
298 /* target info */
299 struct targ_info {
300 /*0*/   TAILQ_ENTRY(targ_info) ti_tchain;       /* targ_info link */
301
302 /*4*/   TAILQ_ENTRY(targ_info) ti_wchain;       /* wait link */
303
304 /*8*/   struct bs_softc *ti_bsc;                /* our controller */
305 /*c*/   u_int ti_id;                            /* scsi id */
306 /*10*/  u_int ti_lun;                           /* current lun */
307
308 /*14*/  struct bsccbtab ti_ctab, ti_bctab;      /* ccb */
309
310 #define BS_TARG_NULL    0
311 #define BS_TARG_CTRL    1
312 #define BS_TARG_START   2
313 #define BS_TARG_SYNCH   3
314 #define BS_TARG_RDY     4
315 /*24*/  int ti_state;                           /* target state */
316
317 /*28*/  u_int ti_cfgflags;                      /* target cfg flags */
318
319 /*2c*/  u_int ti_flags;                         /* flags */
320 /*30*/  u_int ti_mflags;                        /* flags masks */
321
322 /*34*/  u_int ti_error;                         /* error flags */
323 /*38*/  u_int ti_herrcnt;                       /* hardware err retry counter */
324
325         /*****************************************
326          * scsi phase data
327          *****************************************/
328 /*3c*/  struct sc_p ti_scsp;                    /* saved scsi data pointer */
329
330 /*50*/  enum scsi_phase ti_phase;               /* scsi phase */
331 /*54*/  enum scsi_phase ti_ophase;              /* previous scsi phase */
332
333 /*58*/  u_int8_t ti_status;                     /* status in */
334
335 /*59*/  u_int8_t ti_msgin[MAXMSGLEN];           /* msgin buffer */
336 /*64*/  int ti_msginptr;
337
338 /*68*/  u_int8_t ti_msgout;                     /* last msgout byte */
339 /*69*/  u_int8_t ti_emsgout;                    /* last msgout byte */
340 /*6c*/  u_int ti_omsgoutlen;                    /* for retry msgout */
341
342 /*70*/  struct syncdata ti_syncmax;             /* synch data (scsi) */
343 /*72*/  struct syncdata ti_syncnow;
344 /*74*/  u_int8_t ti_sync;                       /* synch val (chip) */
345
346         /*****************************************
347          * bounce buffer & smit data pointer
348          *****************************************/
349 /*75*/  u_int8_t *bounce_phys;
350 /*76*/  u_int8_t *bounce_addr;
351 /*78*/  u_int bounce_size;
352
353 /*7c*/  u_long sm_offset;
354
355         /*****************************************
356          * target inq data
357          *****************************************/
358 /*79*/  u_int8_t targ_type;
359 /*7a*/  u_int8_t targ_support;
360
361         /*****************************************
362          * generic scsi cmd buffer for this target
363          *****************************************/
364 /*7b*/  u_int8_t scsi_cmd[12];
365         struct scsi_sense_data sense;
366 };
367
368 TAILQ_HEAD(titab, targ_info);
369 struct bshw;
370
371 struct bs_softc {
372         /*****************************************
373          * OS depend header
374          *****************************************/
375         OS_DEPEND_DEVICE_HEADER
376
377         OS_DEPEND_MISC_HEADER
378
379         /*****************************************
380          * target link
381          *****************************************/
382         struct targ_info *sc_ti[NTARGETS];
383         u_int sc_openf;
384
385         struct titab sc_sttab;
386         struct titab sc_titab;
387
388         /*****************************************
389          * current scsi phase
390          *****************************************/
391         struct targ_info *sc_nexus;             /* current active nexus */
392
393         enum scsi_phase sc_msgphase;            /* scsi phase pointed by msg */
394
395         struct targ_info *sc_selwait;           /* selection assert */
396
397         u_int sc_dtgnum;                        /* disconnected target */
398
399         /*****************************************
400          * current scsi data pointer
401          *****************************************/
402         struct sc_p sc_p;                       /* scsi data pointer */
403
404         int sc_dmadir;                          /* dma direction */
405
406         int sm_tdatalen;                        /* smit data transfer bytes */
407
408         /*****************************************
409          * parameter
410          *****************************************/
411         u_int sc_retry;                         /* max retry count */
412
413 #define BSDMATRANSFER   0x01
414 #define BSDMASTART      0x02
415 #define BSSMITSTART     0x04
416 #define BSUNDERRESET    0x08
417 #define BSRESET         0x10
418 #define BSSTARTTIMEOUT  0x20
419 #define BSPOLLDONE      0x100
420 #define BSJOBDONE       0x200
421 #define BSBSMODE        0x400
422 #define BSINACTIVE      0x800
423         volatile int sc_flags;                  /* host flags */
424
425 #define BSC_NULL        0
426 #define BSC_BOOTUP      1
427 #define BSC_TARG_CHECK  2
428 #define BSC_RDY         3
429         int sc_hstate;                          /* host state */
430
431         /*****************************************
432          * polling misc
433          *****************************************/
434         u_int sc_wc;                            /* weight count */
435
436         int sc_poll;
437         struct bsccb *sc_outccb;
438
439         /*****************************************
440          * wd33c93 chip depend section
441          *****************************************/
442         u_int sc_cfgflags;                      /* hardware cfg flags */
443
444         struct bshw *sc_hw;                     /* hw selection */
445
446         u_long sm_offset;                       /* smit buffer offset */
447
448         u_int sc_RSTdelay;
449
450         int sc_hwlock;                          /* hardware lock count */
451
452         int sc_iobase;                          /* iobase for FreeBSD */
453         u_int32_t sc_irq;                       /* irq */
454
455         u_int sc_dmachan;                       /* dma channel */
456         u_int8_t sc_busstat;                    /* scsi bus status register */
457         u_int8_t sc_hostid;                     /* host scsi id */
458         u_int8_t sc_cspeed;                     /* chip clock rate */
459         u_int8_t sc_membank;                    /* memory back (NEC) register */
460
461         /*****************************************
462          * our name
463          *****************************************/
464 #define BS_DVNAME_LEN   16
465         u_char sc_dvname[BS_DVNAME_LEN];
466
467         /*****************************************
468          * CAM support
469          *****************************************/
470         struct          cam_sim  *sim;
471         struct          cam_path *path;
472 };
473
474 /*************************************************
475  * debug
476  *************************************************/
477 #ifdef  BS_STATICS
478 struct bs_statics {
479         u_int select;
480         u_int select_miss_in_assert;
481         u_int select_miss_by_reselect;
482         u_int select_miss;
483         u_int select_win;
484         u_int selected;
485         u_int disconnected;
486         u_int reselect;
487 };
488
489 extern struct bs_statics bs_statics[NTARGETS];
490 extern u_int bs_linkcmd_count[];
491 extern u_int bs_bounce_used[];
492 #endif  /* BS_STATICS */
493
494 #ifdef  BS_DEBUG_ROUTINE
495 #ifndef DDB
496 #define Debugger()      panic("should call debugger here (bs.c)")
497 #endif  /* DDB */
498 #ifdef  BS_DEBUG
499 extern int bs_debug_flag;
500 #endif /* BS_DEBUG */
501 #endif /* BS_DEBUG_ROUTINE */
502
503 /*************************************************
504  * Function declare
505  *************************************************/
506 int bs_scsi_cmd_internal __P((struct bsccb *, u_int));
507 struct bsccb *bscmddone __P((struct targ_info *));
508 int bscmdstart __P((struct targ_info *, int));
509 int bs_scsi_cmd_poll __P((struct targ_info *, struct bsccb *));
510 int bs_sequencer __P((struct bs_softc *));
511 void bs_poll_timeout __P((struct bs_softc *, char *));
512
513 /*************************************************
514  * XXX
515  *************************************************/
516 /* misc error */
517 #define COMPLETE        2
518 #define NOTARGET        (-2)
519 #define HASERROR        (-1)
520
521 /* XXX: use scsi_message.h */
522 /* status */
523 #define ST_GOOD         0x00
524 #define ST_CHKCOND      0x02
525 #define ST_MET          0x04
526 #define ST_BUSY         0x08
527 #define ST_INTERGOOD    0x10
528 #define ST_INTERMET     0x14
529 #define ST_CONFLICT     0x18
530 #define ST_QUEFULL      0x28
531 #define ST_UNK          0xff
532
533 /* message */
534 #define MSG_COMP        0x00
535 #define MSG_EXTEND      0x01
536
537 #define MKMSG_EXTEND(XLEN, XCODE) ((((u_int)(XLEN)) << NBBY) | ((u_int)(XCODE)))
538 #define MSG_EXTEND_MDPCODE      0x00
539 #define MSG_EXTEND_MDPLEN       0x05
540 #define MSG_EXTEND_SYNCHCODE    0x01
541 #define MSG_EXTEND_SYNCHLEN     0x03
542 #define MSG_EXTEND_WIDECODE     0x03
543 #define MSG_EXTEND_WIDELEN      0x02
544
545 #define MSG_SAVESP      0x02
546 #define MSG_RESTORESP   0x03
547 #define MSG_DISCON      0x04
548 #define MSG_I_ERROR     0x05
549 #define MSG_ABORT       0x06
550 #define MSG_REJECT      0x07
551 #define MSG_NOOP        0x08
552 #define MSG_PARITY      0x09
553 #define MSG_LCOMP       0x0a
554 #define MSG_LCOMP_F     0x0b
555 #define MSG_RESET       0x0c