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 $
34 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA. All rights reserved.
38 #define BS_INLINE __inline
40 #define BS_INLINE inline
43 /**************************************************
44 * CONTROL FLAGS (cf_flags)
45 *************************************************/
46 #define BSC_FASTACK 0x01
47 #define BSC_SMITSAT_DISEN 0x02
48 #define BSC_CHIP_CLOCK(dvcfg) (((dvcfg) >> 4) & 0x03)
50 #define BS_SCSI_SYNC DVF_SCSI_SYNC
51 #define BS_SCSI_DISC DVF_SCSI_DISC
52 #define BS_SCSI_WAIT DVF_SCSI_WAIT
53 #define BS_SCSI_LINK DVF_SCSI_LINK
54 #define BS_SCSI_QTAG DVF_SCSI_QTAG
55 #define BS_SCSI_NOSAT DVF_SCSI_SP0
56 #define BS_SCSI_NOPARITY DVF_SCSI_NOPARITY
57 #define BS_SCSI_SAVESP DVF_SCSI_SAVESP
58 #define BS_SCSI_NOSMIT DVF_SCSI_SP1
59 #define BS_SCSI_PERIOD(XXX) DVF_SCSI_PERIOD(XXX)
60 #define BS_SCSI_OFFSET(XXX) DVF_SCSI_OFFSET(XXX)
61 #define BS_SCSI_SYNCMASK DVF_SCSI_SYNCMASK
62 #define BS_SCSI_BITS DVF_SCSI_BITS
64 #define BS_SCSI_DEFCFG (BS_SCSI_NOSAT | DVF_SCSI_DEFCFG)
66 #define BS_SCSI_POSITIVE (BS_SCSI_SYNC | BS_SCSI_DISC | BS_SCSI_LINK)
67 #define BS_SCSI_NEGATIVE (BS_SCSI_WAIT | BS_SCSI_NOSAT | BS_SCSI_NOPARITY |\
68 BS_SCSI_SAVESP | BS_SCSI_NOSMIT)
69 /*******************************************
71 ******************************************/
72 /* Enable timeout watch dog */
73 #define BS_DEFAULT_TIMEOUT_SECOND 16 /* default 16 sec */
74 #define BS_SYNC_TIMEOUT 16
75 #define BS_STARTUP_TIMEOUT 60
76 #define BS_MOTOR_TIMEOUT 120
77 #define BS_TIMEOUT_CHECK_INTERVAL 4 /* check each 4 sec */
79 /* If you use memory over 16M */
80 #ifdef SCSI_BOUNCE_SIZE
81 #define BS_BOUNCE_SIZE SCSI_BOUNCE_SIZE
82 #else /* !SCSI_BOUNCE_SIZE */
83 #define BS_BOUNCE_SIZE 0
84 #endif /* !SCSI_BOUNCE_SIZE */
89 #define BS_DEBUG_ROUTINE 1
91 /* #define SHOW_PORT 1 */
93 /**************************************************
95 **************************************************/
97 #define RETRIES 1 /* number of retries before giving up */
100 #define BSDMABUFSIZ 0x10000
101 #define BS_MAX_CCB (XSMAX * (NTARGETS - 1))
104 #define BSCMDRESTART 0x01
105 #define BSCMDFORCE 0x02
107 #define BS_TIMEOUT_INTERVAL (hz * BS_TIMEOUT_CHECK_INTERVAL)
109 /**************************************************
111 **************************************************/
134 /**************************************************
135 * SCSI PHASE CONTROL MACRO
136 **************************************************/
137 #define BS_HOST_START \
139 bsc->sc_nexus = ti; \
142 #define BS_HOST_TERMINATE \
144 bsc->sc_selwait = NULL; \
145 bsc->sc_nexus = NULL; \
148 #define BS_SELECTION_START \
150 bsc->sc_selwait = ti; \
153 #define BS_SELECTION_TERMINATE \
155 bsc->sc_selwait = NULL; \
158 #define BS_SETUP_PHASE(PHASE) \
160 ti->ti_ophase = ti->ti_phase; \
161 ti->ti_phase = (PHASE); \
164 #define BS_SETUP_MSGPHASE(PHASE) \
166 bsc->sc_msgphase = (PHASE); \
169 #define BS_SETUP_SYNCSTATE(STATE) \
171 ti->ti_syncnow.state = (STATE); \
174 #define BS_SETUP_TARGSTATE(STATE) \
176 ti->ti_state = (STATE); \
179 #define BS_LOAD_SDP \
181 bsc->sc_p.data = ti->ti_scsp.data; \
182 bsc->sc_p.datalen = ti->ti_scsp.datalen; \
183 bsc->sc_p.seglen = ti->ti_scsp.seglen; \
186 #define BS_RESTORE_SDP \
188 bsc->sc_p = ti->ti_scsp; \
191 #define BS_SAVE_SDP \
193 ti->ti_scsp = bsc->sc_p; \
196 /**************************************************
198 **************************************************/
201 u_int8_t msg[MAXMSGLEN];
211 #define BS_SYNCMSG_NULL 0x00
212 #define BS_SYNCMSG_ASSERT 0x01
213 #define BS_SYNCMSG_REJECT 0x02
214 #define BS_SYNCMSG_ACCEPT 0x03
215 #define BS_SYNCMSG_REQUESTED 0x04
229 /* targ_info error flags */
230 #define BSDMAABNORMAL 0x01
231 #define BSCMDABNORMAL 0x02
232 #define BSPARITY 0x04
233 #define BSSTATUSERROR 0x08
234 #define BSTIMEOUT 0x10
235 #define BSREQSENSE 0x20
236 #define BSSELTIMEOUT 0x40
237 #define BSFATALIO 0x80
238 #define BSMSGERROR 0x100
239 #define BSTRYRECOV 0x200
240 #define BSABNORMAL 0x400
241 #define BSTARGETBUSY 0x800
243 #define BSERRORBITS "\020\014busy\013abnormal\012retry\011msgerr\010fatal\007seltimeout\006sense\005timeout\004statuserr\003parity\002cmderr\001dmaerr"
245 /* bsccb bsccb_flags & targ_info flags & cmd flags*/
246 #define BSREAD 0x0001
248 #define BSLINK 0x0004
249 #define BSERROROK 0x0008
250 #define BSSMIT 0x0010
251 #define BSDISC 0x1000
252 #define BSFORCEIOPOLL 0x2000
254 #define BSCASTAT 0x01000000
255 #define BSSENSECCB 0x02000000
256 #define BSQUEUED 0x04000000
257 #define BSALTBUF 0x08000000
258 #define BSITSDONE 0x10000000
259 #define BSNEXUS 0x20000000
261 #define BSCFLAGSMASK (0xffff)
264 TAILQ_ENTRY(bsccb) ccb_chain;
266 union ccb *ccb; /* upper drivers info */
270 u_int bsccb_flags; /* control flags */
272 int rcnt; /* retry counter of this ccb */
274 u_int error; /* recorded error */
276 /*****************************************
278 *****************************************/
279 u_int8_t *cmd; /* scsi cmd */
282 u_int8_t *data; /* scsi data */
285 u_int8_t msgout[MAXMSGLEN]; /* scsi msgout */
288 /*****************************************
290 *****************************************/
295 GENERIC_CCB_ASSERT(bs, bsccb)
299 /*0*/ TAILQ_ENTRY(targ_info) ti_tchain; /* targ_info link */
301 /*4*/ TAILQ_ENTRY(targ_info) ti_wchain; /* wait link */
303 /*8*/ struct bs_softc *ti_bsc; /* our controller */
304 /*c*/ u_int ti_id; /* scsi id */
305 /*10*/ u_int ti_lun; /* current lun */
307 /*14*/ struct bsccbtab ti_ctab, ti_bctab; /* ccb */
309 #define BS_TARG_NULL 0
310 #define BS_TARG_CTRL 1
311 #define BS_TARG_START 2
312 #define BS_TARG_SYNCH 3
313 #define BS_TARG_RDY 4
314 /*24*/ int ti_state; /* target state */
316 /*28*/ u_int ti_cfgflags; /* target cfg flags */
318 /*2c*/ u_int ti_flags; /* flags */
319 /*30*/ u_int ti_mflags; /* flags masks */
321 /*34*/ u_int ti_error; /* error flags */
322 /*38*/ u_int ti_herrcnt; /* hardware err retry counter */
324 /*****************************************
326 *****************************************/
327 /*3c*/ struct sc_p ti_scsp; /* saved scsi data pointer */
329 /*50*/ enum scsi_phase ti_phase; /* scsi phase */
330 /*54*/ enum scsi_phase ti_ophase; /* previous scsi phase */
332 /*58*/ u_int8_t ti_status; /* status in */
334 /*59*/ u_int8_t ti_msgin[MAXMSGLEN]; /* msgin buffer */
335 /*64*/ int ti_msginptr;
337 /*68*/ u_int8_t ti_msgout; /* last msgout byte */
338 /*69*/ u_int8_t ti_emsgout; /* last msgout byte */
339 /*6c*/ u_int ti_omsgoutlen; /* for retry msgout */
341 /*70*/ struct syncdata ti_syncmax; /* synch data (scsi) */
342 /*72*/ struct syncdata ti_syncnow;
343 /*74*/ u_int8_t ti_sync; /* synch val (chip) */
345 /*****************************************
346 * bounce buffer & smit data pointer
347 *****************************************/
348 /*75*/ u_int8_t *bounce_phys;
349 /*76*/ u_int8_t *bounce_addr;
350 /*78*/ u_int bounce_size;
352 /*7c*/ u_long sm_offset;
354 /*****************************************
356 *****************************************/
357 /*79*/ u_int8_t targ_type;
358 /*7a*/ u_int8_t targ_support;
360 /*****************************************
361 * generic scsi cmd buffer for this target
362 *****************************************/
363 /*7b*/ u_int8_t scsi_cmd[12];
364 struct scsi_sense_data sense;
367 TAILQ_HEAD(titab, targ_info);
371 /*****************************************
373 *****************************************/
374 OS_DEPEND_DEVICE_HEADER
376 OS_DEPEND_MISC_HEADER
378 /*****************************************
380 *****************************************/
381 struct targ_info *sc_ti[NTARGETS];
384 struct titab sc_sttab;
385 struct titab sc_titab;
387 /*****************************************
389 *****************************************/
390 struct targ_info *sc_nexus; /* current active nexus */
392 enum scsi_phase sc_msgphase; /* scsi phase pointed by msg */
394 struct targ_info *sc_selwait; /* selection assert */
396 u_int sc_dtgnum; /* disconnected target */
398 /*****************************************
399 * current scsi data pointer
400 *****************************************/
401 struct sc_p sc_p; /* scsi data pointer */
403 int sc_dmadir; /* dma direction */
405 int sm_tdatalen; /* smit data transfer bytes */
407 /*****************************************
409 *****************************************/
410 u_int sc_retry; /* max retry count */
412 #define BSDMATRANSFER 0x01
413 #define BSDMASTART 0x02
414 #define BSSMITSTART 0x04
415 #define BSUNDERRESET 0x08
417 #define BSSTARTTIMEOUT 0x20
418 #define BSPOLLDONE 0x100
419 #define BSJOBDONE 0x200
420 #define BSBSMODE 0x400
421 #define BSINACTIVE 0x800
422 volatile int sc_flags; /* host flags */
426 #define BSC_TARG_CHECK 2
428 int sc_hstate; /* host state */
430 /*****************************************
432 *****************************************/
433 u_int sc_wc; /* weight count */
436 struct bsccb *sc_outccb;
438 /*****************************************
439 * wd33c93 chip depend section
440 *****************************************/
441 u_int sc_cfgflags; /* hardware cfg flags */
443 struct bshw *sc_hw; /* hw selection */
445 u_long sm_offset; /* smit buffer offset */
449 int sc_hwlock; /* hardware lock count */
451 int sc_iobase; /* iobase for FreeBSD */
452 u_int32_t sc_irq; /* irq */
454 u_int sc_dmachan; /* dma channel */
455 u_int8_t sc_busstat; /* scsi bus status register */
456 u_int8_t sc_hostid; /* host scsi id */
457 u_int8_t sc_cspeed; /* chip clock rate */
458 u_int8_t sc_membank; /* memory back (NEC) register */
460 /*****************************************
462 *****************************************/
463 #define BS_DVNAME_LEN 16
464 u_char sc_dvname[BS_DVNAME_LEN];
466 /*****************************************
468 *****************************************/
470 struct cam_path *path;
473 /*************************************************
475 *************************************************/
479 u_int select_miss_in_assert;
480 u_int select_miss_by_reselect;
488 extern struct bs_statics bs_statics[NTARGETS];
489 extern u_int bs_linkcmd_count[];
490 extern u_int bs_bounce_used[];
491 #endif /* BS_STATICS */
493 #ifdef BS_DEBUG_ROUTINE
495 #define Debugger() panic("should call debugger here (bs.c)")
498 extern int bs_debug_flag;
499 #endif /* BS_DEBUG */
500 #endif /* BS_DEBUG_ROUTINE */
502 /*************************************************
504 *************************************************/
505 int bs_scsi_cmd_internal __P((struct bsccb *, u_int));
506 struct bsccb *bscmddone __P((struct targ_info *));
507 int bscmdstart __P((struct targ_info *, int));
508 int bs_scsi_cmd_poll __P((struct targ_info *, struct bsccb *));
509 int bs_sequencer __P((struct bs_softc *));
510 void bs_poll_timeout __P((struct bs_softc *, char *));
512 /*************************************************
514 *************************************************/
517 #define NOTARGET (-2)
518 #define HASERROR (-1)
520 /* XXX: use scsi_message.h */
523 #define ST_CHKCOND 0x02
526 #define ST_INTERGOOD 0x10
527 #define ST_INTERMET 0x14
528 #define ST_CONFLICT 0x18
529 #define ST_QUEFULL 0x28
533 #define MSG_COMP 0x00
534 #define MSG_EXTEND 0x01
536 #define MKMSG_EXTEND(XLEN, XCODE) ((((u_int)(XLEN)) << NBBY) | ((u_int)(XCODE)))
537 #define MSG_EXTEND_MDPCODE 0x00
538 #define MSG_EXTEND_MDPLEN 0x05
539 #define MSG_EXTEND_SYNCHCODE 0x01
540 #define MSG_EXTEND_SYNCHLEN 0x03
541 #define MSG_EXTEND_WIDECODE 0x03
542 #define MSG_EXTEND_WIDELEN 0x02
544 #define MSG_SAVESP 0x02
545 #define MSG_RESTORESP 0x03
546 #define MSG_DISCON 0x04
547 #define MSG_I_ERROR 0x05
548 #define MSG_ABORT 0x06
549 #define MSG_REJECT 0x07
550 #define MSG_NOOP 0x08
551 #define MSG_PARITY 0x09
552 #define MSG_LCOMP 0x0a
553 #define MSG_LCOMP_F 0x0b
554 #define MSG_RESET 0x0c