1 /* $NecBSD: bsvar.h,v 1.2 1997/10/31 17:43:41 honda Exp $ */
4 * [NetBSD for NEC PC98 series]
5 * Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
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 $
35 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA. All rights reserved.
39 #define BS_INLINE __inline
41 #define BS_INLINE inline
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)
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
65 #define BS_SCSI_DEFCFG (BS_SCSI_NOSAT | DVF_SCSI_DEFCFG)
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 /*******************************************
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 */
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 */
90 #define BS_DEBUG_ROUTINE 1
92 /* #define SHOW_PORT 1 */
94 /**************************************************
96 **************************************************/
98 #define RETRIES 1 /* number of retries before giving up */
101 #define BSDMABUFSIZ 0x10000
102 #define BS_MAX_CCB (XSMAX * (NTARGETS - 1))
105 #define BSCMDRESTART 0x01
106 #define BSCMDFORCE 0x02
108 #define BS_TIMEOUT_INTERVAL (hz * BS_TIMEOUT_CHECK_INTERVAL)
110 /**************************************************
112 **************************************************/
135 /**************************************************
136 * SCSI PHASE CONTROL MACRO
137 **************************************************/
138 #define BS_HOST_START \
140 bsc->sc_nexus = ti; \
143 #define BS_HOST_TERMINATE \
145 bsc->sc_selwait = NULL; \
146 bsc->sc_nexus = NULL; \
149 #define BS_SELECTION_START \
151 bsc->sc_selwait = ti; \
154 #define BS_SELECTION_TERMINATE \
156 bsc->sc_selwait = NULL; \
159 #define BS_SETUP_PHASE(PHASE) \
161 ti->ti_ophase = ti->ti_phase; \
162 ti->ti_phase = (PHASE); \
165 #define BS_SETUP_MSGPHASE(PHASE) \
167 bsc->sc_msgphase = (PHASE); \
170 #define BS_SETUP_SYNCSTATE(STATE) \
172 ti->ti_syncnow.state = (STATE); \
175 #define BS_SETUP_TARGSTATE(STATE) \
177 ti->ti_state = (STATE); \
180 #define BS_LOAD_SDP \
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; \
187 #define BS_RESTORE_SDP \
189 bsc->sc_p = ti->ti_scsp; \
192 #define BS_SAVE_SDP \
194 ti->ti_scsp = bsc->sc_p; \
197 /**************************************************
199 **************************************************/
202 u_int8_t msg[MAXMSGLEN];
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
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
244 #define BSERRORBITS "\020\014busy\013abnormal\012retry\011msgerr\010fatal\007seltimeout\006sense\005timeout\004statuserr\003parity\002cmderr\001dmaerr"
246 /* bsccb bsccb_flags & targ_info flags & cmd flags*/
247 #define BSREAD 0x0001
249 #define BSLINK 0x0004
250 #define BSERROROK 0x0008
251 #define BSSMIT 0x0010
252 #define BSDISC 0x1000
253 #define BSFORCEIOPOLL 0x2000
255 #define BSCASTAT 0x01000000
256 #define BSSENSECCB 0x02000000
257 #define BSQUEUED 0x04000000
258 #define BSALTBUF 0x08000000
259 #define BSITSDONE 0x10000000
260 #define BSNEXUS 0x20000000
262 #define BSCFLAGSMASK (0xffff)
265 TAILQ_ENTRY(bsccb) ccb_chain;
267 union ccb *ccb; /* upper drivers info */
271 u_int bsccb_flags; /* control flags */
273 int rcnt; /* retry counter of this ccb */
275 u_int error; /* recorded error */
277 /*****************************************
279 *****************************************/
280 u_int8_t *cmd; /* scsi cmd */
283 u_int8_t *data; /* scsi data */
286 u_int8_t msgout[MAXMSGLEN]; /* scsi msgout */
289 /*****************************************
291 *****************************************/
296 GENERIC_CCB_ASSERT(bs, bsccb)
300 /*0*/ TAILQ_ENTRY(targ_info) ti_tchain; /* targ_info link */
302 /*4*/ TAILQ_ENTRY(targ_info) ti_wchain; /* wait link */
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 */
308 /*14*/ struct bsccbtab ti_ctab, ti_bctab; /* ccb */
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 */
317 /*28*/ u_int ti_cfgflags; /* target cfg flags */
319 /*2c*/ u_int ti_flags; /* flags */
320 /*30*/ u_int ti_mflags; /* flags masks */
322 /*34*/ u_int ti_error; /* error flags */
323 /*38*/ u_int ti_herrcnt; /* hardware err retry counter */
325 /*****************************************
327 *****************************************/
328 /*3c*/ struct sc_p ti_scsp; /* saved scsi data pointer */
330 /*50*/ enum scsi_phase ti_phase; /* scsi phase */
331 /*54*/ enum scsi_phase ti_ophase; /* previous scsi phase */
333 /*58*/ u_int8_t ti_status; /* status in */
335 /*59*/ u_int8_t ti_msgin[MAXMSGLEN]; /* msgin buffer */
336 /*64*/ int ti_msginptr;
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 */
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) */
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;
353 /*7c*/ u_long sm_offset;
355 /*****************************************
357 *****************************************/
358 /*79*/ u_int8_t targ_type;
359 /*7a*/ u_int8_t targ_support;
361 /*****************************************
362 * generic scsi cmd buffer for this target
363 *****************************************/
364 /*7b*/ u_int8_t scsi_cmd[12];
365 struct scsi_sense_data sense;
368 TAILQ_HEAD(titab, targ_info);
372 /*****************************************
374 *****************************************/
375 OS_DEPEND_DEVICE_HEADER
377 OS_DEPEND_MISC_HEADER
379 /*****************************************
381 *****************************************/
382 struct targ_info *sc_ti[NTARGETS];
385 struct titab sc_sttab;
386 struct titab sc_titab;
388 /*****************************************
390 *****************************************/
391 struct targ_info *sc_nexus; /* current active nexus */
393 enum scsi_phase sc_msgphase; /* scsi phase pointed by msg */
395 struct targ_info *sc_selwait; /* selection assert */
397 u_int sc_dtgnum; /* disconnected target */
399 /*****************************************
400 * current scsi data pointer
401 *****************************************/
402 struct sc_p sc_p; /* scsi data pointer */
404 int sc_dmadir; /* dma direction */
406 int sm_tdatalen; /* smit data transfer bytes */
408 /*****************************************
410 *****************************************/
411 u_int sc_retry; /* max retry count */
413 #define BSDMATRANSFER 0x01
414 #define BSDMASTART 0x02
415 #define BSSMITSTART 0x04
416 #define BSUNDERRESET 0x08
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 */
427 #define BSC_TARG_CHECK 2
429 int sc_hstate; /* host state */
431 /*****************************************
433 *****************************************/
434 u_int sc_wc; /* weight count */
437 struct bsccb *sc_outccb;
439 /*****************************************
440 * wd33c93 chip depend section
441 *****************************************/
442 u_int sc_cfgflags; /* hardware cfg flags */
444 struct bshw *sc_hw; /* hw selection */
446 u_long sm_offset; /* smit buffer offset */
450 int sc_hwlock; /* hardware lock count */
452 int sc_iobase; /* iobase for FreeBSD */
453 u_int32_t sc_irq; /* irq */
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 */
461 /*****************************************
463 *****************************************/
464 #define BS_DVNAME_LEN 16
465 u_char sc_dvname[BS_DVNAME_LEN];
467 /*****************************************
469 *****************************************/
471 struct cam_path *path;
474 /*************************************************
476 *************************************************/
480 u_int select_miss_in_assert;
481 u_int select_miss_by_reselect;
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 */
494 #ifdef BS_DEBUG_ROUTINE
496 #define Debugger() panic("should call debugger here (bs.c)")
499 extern int bs_debug_flag;
500 #endif /* BS_DEBUG */
501 #endif /* BS_DEBUG_ROUTINE */
503 /*************************************************
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 *));
513 /*************************************************
515 *************************************************/
518 #define NOTARGET (-2)
519 #define HASERROR (-1)
521 /* XXX: use scsi_message.h */
524 #define ST_CHKCOND 0x02
527 #define ST_INTERGOOD 0x10
528 #define ST_INTERMET 0x14
529 #define ST_CONFLICT 0x18
530 #define ST_QUEFULL 0x28
534 #define MSG_COMP 0x00
535 #define MSG_EXTEND 0x01
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
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