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