summaryrefslogtreecommitdiffstats
path: root/sys/i386/isa/bs/bsvar.h
blob: 6267c31a917c9b7ede877249bb282ba0842ad4fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/*	$NecBSD: bsvar.h,v 1.2 1997/10/31 17:43:41 honda Exp $	*/
/*	$NetBSD$	*/
/*
 * [NetBSD for NEC PC98 series]
 *  Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */
/*
 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA.  All rights reserved.
 */

#ifdef __FreeBSD__
#define	BS_INLINE	__inline
#else
#define	BS_INLINE	inline
#endif

/**************************************************
 *	CONTROL FLAGS  (cf_flags)
 *************************************************/
#define	BSC_FASTACK		0x01
#define	BSC_SMITSAT_DISEN	0x02
#define	BSC_CHIP_CLOCK(dvcfg)	(((dvcfg) >> 4) & 0x03)

#define	BS_SCSI_SYNC		DVF_SCSI_SYNC
#define	BS_SCSI_DISC		DVF_SCSI_DISC
#define	BS_SCSI_WAIT		DVF_SCSI_WAIT
#define	BS_SCSI_LINK		DVF_SCSI_LINK
#define	BS_SCSI_QTAG		DVF_SCSI_QTAG
#define	BS_SCSI_NOSAT		DVF_SCSI_SP0
#define	BS_SCSI_NOPARITY	DVF_SCSI_NOPARITY
#define	BS_SCSI_SAVESP		DVF_SCSI_SAVESP
#define	BS_SCSI_NOSMIT		DVF_SCSI_SP1
#define	BS_SCSI_PERIOD(XXX)	DVF_SCSI_PERIOD(XXX)
#define	BS_SCSI_OFFSET(XXX)	DVF_SCSI_OFFSET(XXX)
#define BS_SCSI_SYNCMASK	DVF_SCSI_SYNCMASK
#define	BS_SCSI_BITS		DVF_SCSI_BITS

#define	BS_SCSI_DEFCFG		(BS_SCSI_NOSAT | DVF_SCSI_DEFCFG)

#define	BS_SCSI_POSITIVE (BS_SCSI_SYNC | BS_SCSI_DISC | BS_SCSI_LINK)
#define	BS_SCSI_NEGATIVE (BS_SCSI_WAIT | BS_SCSI_NOSAT | BS_SCSI_NOPARITY |\
			  BS_SCSI_SAVESP | BS_SCSI_NOSMIT)
/*******************************************
 * CONFIG SECTION
 ******************************************/
/* Enable timeout watch dog */
#define	BS_DEFAULT_TIMEOUT_SECOND	16	/* default 16 sec */
#define	BS_SYNC_TIMEOUT			16
#define	BS_STARTUP_TIMEOUT		60
#define	BS_MOTOR_TIMEOUT		120
#define	BS_TIMEOUT_CHECK_INTERVAL	4	/* check each 4 sec */

/* If you use memory over 16M */
#ifdef	SCSI_BOUNCE_SIZE
#define	BS_BOUNCE_SIZE	SCSI_BOUNCE_SIZE
#else	/* !SCSI_BOUNCE_SIZE */
#define	BS_BOUNCE_SIZE	0
#endif	/* !SCSI_BOUNCE_SIZE */

/* debug */
#define	BS_STATICS		1
#define	BS_DIAG			1
#define	BS_DEBUG_ROUTINE	1
#define	BS_DEBUG		1
/* #define	SHOW_PORT	1 */

/**************************************************
 *	PARAMETER
 **************************************************/
#define	NTARGETS	8
#define	RETRIES		1	/* number of retries before giving up */
#define	HARDRETRIES	3
#define	XSMAX		4
#define	BSDMABUFSIZ	0x10000
#define BS_MAX_CCB	(XSMAX * (NTARGETS - 1))

#define	BSCMDSTART	0
#define	BSCMDRESTART	0x01
#define	BSCMDFORCE	0x02

#define	BS_TIMEOUT_INTERVAL	(hz * BS_TIMEOUT_CHECK_INTERVAL)

/**************************************************
 *	SCSI PHASE
 **************************************************/
enum scsi_phase {
	FREE = 0,
	HOSTQUEUE,
	DISCONNECTED,
	IOCOMPLETED,
	ATTENTIONASSERT,
	DISCONNECTASSERT,
	SELECTASSERT,
	SELECTED,
	RESELECTED,
	MSGIN,
	MSGOUT,
	STATUSIN,
	CMDPHASE,
	DATAPHASE,
	SATSEL,
	SATRESEL,
	SATSDP,
	SATCOMPSEQ,
	UNDEF,
};

/**************************************************
 *	SCSI PHASE CONTROL MACRO
 **************************************************/
#define	BS_HOST_START					\
{							\
	bsc->sc_nexus = ti;				\
}

#define	BS_HOST_TERMINATE				\
{							\
	bsc->sc_selwait = NULL;				\
	bsc->sc_nexus = NULL;				\
}

#define	BS_SELECTION_START				\
{							\
	bsc->sc_selwait = ti;				\
}

#define	BS_SELECTION_TERMINATE				\
{							\
	bsc->sc_selwait = NULL;				\
}

#define	BS_SETUP_PHASE(PHASE)				\
{							\
	ti->ti_ophase = ti->ti_phase;			\
	ti->ti_phase = (PHASE);				\
}

#define	BS_SETUP_MSGPHASE(PHASE)			\
{							\
	bsc->sc_msgphase = (PHASE);			\
}

#define	BS_SETUP_SYNCSTATE(STATE)			\
{							\
	ti->ti_syncnow.state = (STATE);			\
}

#define	BS_SETUP_TARGSTATE(STATE)			\
{							\
	ti->ti_state = (STATE);				\
}

#define	BS_LOAD_SDP					\
{							\
	bsc->sc_p.data = ti->ti_scsp.data;		\
	bsc->sc_p.datalen = ti->ti_scsp.datalen;	\
	bsc->sc_p.seglen = ti->ti_scsp.seglen;		\
}

#define	BS_RESTORE_SDP					\
{							\
	bsc->sc_p = ti->ti_scsp;			\
}

#define	BS_SAVE_SDP					\
{							\
	ti->ti_scsp = bsc->sc_p;			\
}

/**************************************************
 * STRUCTURES
 **************************************************/
struct msgbase {
#define	MAXMSGLEN	8
	u_int8_t msg[MAXMSGLEN];
	u_int msglen;

	u_int flag;
};

struct syncdata {
	u_int8_t period;
	u_int8_t offset;

#define	BS_SYNCMSG_NULL		0x00
#define	BS_SYNCMSG_ASSERT	0x01
#define	BS_SYNCMSG_REJECT	0x02
#define	BS_SYNCMSG_ACCEPT	0x03
#define	BS_SYNCMSG_REQUESTED	0x04
	u_int state;
};

struct sc_p {
	u_int8_t *data;
	int datalen;

	u_int8_t *segaddr;
	int seglen;

	u_int8_t *bufp;
};

/* targ_info error flags */
#define	BSDMAABNORMAL	0x01
#define	BSCMDABNORMAL	0x02
#define	BSPARITY	0x04
#define	BSSTATUSERROR	0x08
#define	BSTIMEOUT	0x10
#define	BSREQSENSE	0x20
#define	BSSELTIMEOUT	0x40
#define	BSFATALIO	0x80
#define	BSMSGERROR	0x100
#define	BSTRYRECOV	0x200
#define	BSABNORMAL	0x400
#define	BSTARGETBUSY	0x800

#define	BSERRORBITS	"\020\014busy\013abnormal\012retry\011msgerr\010fatal\007seltimeout\006sense\005timeout\004statuserr\003parity\002cmderr\001dmaerr"

/* bsccb bsccb_flags & targ_info flags & cmd flags*/
#define	BSREAD		0x0001
#define	BSSAT		0x0002
#define	BSLINK		0x0004
#define	BSERROROK	0x0008
#define	BSSMIT		0x0010
#define	BSDISC		0x1000
#define	BSFORCEIOPOLL	0x2000

#define	BSCASTAT	0x01000000
#define	BSSENSECCB	0x02000000
#define	BSQUEUED	0x04000000
#define	BSALTBUF	0x08000000
#define	BSITSDONE	0x10000000
#define	BSNEXUS		0x20000000

#define	BSCFLAGSMASK	(0xffff)

struct bsccb {
	TAILQ_ENTRY(bsccb) ccb_chain;

	union ccb *ccb;			/* upper drivers info */

	u_int lun;			/* lun */

	u_int bsccb_flags;		/* control flags */

	int rcnt;			/* retry counter of this ccb */

	u_int error;			/* recorded error */

	/*****************************************
	 * scsi cmd & data
	 *****************************************/
	u_int8_t *cmd;			/* scsi cmd */
	int cmdlen;

	u_int8_t *data;			/* scsi data */
	int datalen;

	u_int8_t msgout[MAXMSGLEN];	/* scsi msgout */
	u_int msgoutlen;

	/*****************************************
	 * timeout counter
	 *****************************************/
	int tc;
	int tcmax;
};

GENERIC_CCB_ASSERT(bs, bsccb)

/* target info */
struct targ_info {
/*0*/	TAILQ_ENTRY(targ_info) ti_tchain;	/* targ_info link */

/*4*/	TAILQ_ENTRY(targ_info) ti_wchain;	/* wait link */

/*8*/	struct bs_softc *ti_bsc;		/* our controller */
/*c*/	u_int ti_id;				/* scsi id */
/*10*/	u_int ti_lun;				/* current lun */

/*14*/	struct bsccbtab ti_ctab, ti_bctab;	/* ccb */

#define	BS_TARG_NULL	0
#define	BS_TARG_CTRL	1
#define	BS_TARG_START	2
#define	BS_TARG_SYNCH	3
#define BS_TARG_RDY	4
/*24*/	int ti_state;				/* target state */

/*28*/	u_int ti_cfgflags;			/* target cfg flags */

/*2c*/	u_int ti_flags;				/* flags */
/*30*/	u_int ti_mflags;			/* flags masks */

/*34*/	u_int ti_error;				/* error flags */
/*38*/	u_int ti_herrcnt;			/* hardware err retry counter */

	/*****************************************
	 * scsi phase data
	 *****************************************/
/*3c*/	struct sc_p ti_scsp;			/* saved scsi data pointer */

/*50*/	enum scsi_phase ti_phase;		/* scsi phase */
/*54*/	enum scsi_phase ti_ophase;		/* previous scsi phase */

/*58*/	u_int8_t ti_status;			/* status in */

/*59*/	u_int8_t ti_msgin[MAXMSGLEN];		/* msgin buffer */
/*64*/	int ti_msginptr;

/*68*/	u_int8_t ti_msgout;			/* last msgout byte */
/*69*/	u_int8_t ti_emsgout;			/* last msgout byte */
/*6c*/	u_int ti_omsgoutlen;			/* for retry msgout */

/*70*/	struct syncdata ti_syncmax;		/* synch data (scsi) */
/*72*/	struct syncdata ti_syncnow;
/*74*/	u_int8_t ti_sync;			/* synch val (chip) */

	/*****************************************
	 * bounce buffer & smit data pointer
	 *****************************************/
/*75*/	u_int8_t *bounce_phys;
/*76*/	u_int8_t *bounce_addr;
/*78*/	u_int bounce_size;

/*7c*/	u_long sm_offset;

	/*****************************************
	 * target inq data
	 *****************************************/
/*79*/	u_int8_t targ_type;
/*7a*/	u_int8_t targ_support;

	/*****************************************
	 * generic scsi cmd buffer for this target
	 *****************************************/
/*7b*/	u_int8_t scsi_cmd[12];
	struct scsi_sense_data sense;
};

TAILQ_HEAD(titab, targ_info);
struct bshw;

struct bs_softc {
	/*****************************************
	 * OS depend header
	 *****************************************/
	OS_DEPEND_DEVICE_HEADER

	OS_DEPEND_MISC_HEADER

	/*****************************************
	 * target link
	 *****************************************/
	struct targ_info *sc_ti[NTARGETS];
	u_int sc_openf;

	struct titab sc_sttab;
	struct titab sc_titab;

	/*****************************************
	 * current scsi phase
	 *****************************************/
	struct targ_info *sc_nexus;		/* current active nexus */

	enum scsi_phase sc_msgphase;		/* scsi phase pointed by msg */

	struct targ_info *sc_selwait;		/* selection assert */

	u_int sc_dtgnum;			/* disconnected target */

	/*****************************************
	 * current scsi data pointer
	 *****************************************/
	struct sc_p sc_p;			/* scsi data pointer */

	int sc_dmadir;				/* dma direction */

	int sm_tdatalen;			/* smit data transfer bytes */

	/*****************************************
	 * parameter
	 *****************************************/
	u_int sc_retry;				/* max retry count */

#define	BSDMATRANSFER	0x01
#define	BSDMASTART	0x02
#define	BSSMITSTART	0x04
#define	BSUNDERRESET	0x08
#define	BSRESET		0x10
#define	BSSTARTTIMEOUT	0x20
#define	BSPOLLDONE	0x100
#define	BSJOBDONE	0x200
#define	BSBSMODE	0x400
#define	BSINACTIVE	0x800
	volatile int sc_flags;			/* host flags */

#define	BSC_NULL	0
#define	BSC_BOOTUP	1
#define	BSC_TARG_CHECK	2
#define	BSC_RDY		3
	int sc_hstate;				/* host state */

	/*****************************************
	 * polling misc
	 *****************************************/
	u_int sc_wc;				/* weight count */

	int sc_poll;
	struct bsccb *sc_outccb;

	/*****************************************
	 * wd33c93 chip depend section
	 *****************************************/
	u_int sc_cfgflags;			/* hardware cfg flags */

	struct bshw *sc_hw;			/* hw selection */

	u_long sm_offset;			/* smit buffer offset */

	u_int sc_RSTdelay;

	int sc_hwlock;				/* hardware lock count */

	int sc_iobase;				/* iobase for FreeBSD */
	u_int32_t sc_irq;			/* irq */

	u_int sc_dmachan;			/* dma channel */
	u_int8_t sc_busstat;			/* scsi bus status register */
	u_int8_t sc_hostid;			/* host scsi id */
	u_int8_t sc_cspeed;			/* chip clock rate */
	u_int8_t sc_membank;			/* memory back (NEC) register */

	/*****************************************
	 * our name
	 *****************************************/
#define	BS_DVNAME_LEN	16
	u_char sc_dvname[BS_DVNAME_LEN];

	/*****************************************
	 * CAM support
	 *****************************************/
	struct		cam_sim  *sim;
	struct		cam_path *path;
};

/*************************************************
 * debug
 *************************************************/
#ifdef	BS_STATICS
struct bs_statics {
	u_int select;
	u_int select_miss_in_assert;
	u_int select_miss_by_reselect;
	u_int select_miss;
	u_int select_win;
	u_int selected;
	u_int disconnected;
	u_int reselect;
};

extern struct bs_statics bs_statics[NTARGETS];
extern u_int bs_linkcmd_count[];
extern u_int bs_bounce_used[];
#endif	/* BS_STATICS */

#ifdef	BS_DEBUG_ROUTINE
#ifndef	DDB
#define	Debugger()	panic("should call debugger here (bs.c)")
#endif	/* DDB */
#ifdef	BS_DEBUG
extern int bs_debug_flag;
#endif /* BS_DEBUG */
#endif /* BS_DEBUG_ROUTINE */

/*************************************************
 * Function declare
 *************************************************/
int bs_scsi_cmd_internal __P((struct bsccb *, u_int));
struct bsccb *bscmddone __P((struct targ_info *));
int bscmdstart __P((struct targ_info *, int));
int bs_scsi_cmd_poll __P((struct targ_info *, struct bsccb *));
int bs_sequencer __P((struct bs_softc *));
void bs_poll_timeout __P((struct bs_softc *, char *));

/*************************************************
 * XXX
 *************************************************/
/* misc error */
#define COMPLETE	2
#define NOTARGET	(-2)
#define	HASERROR	(-1)

/* XXX: use scsi_message.h */
/* status */
#define	ST_GOOD		0x00
#define	ST_CHKCOND	0x02
#define	ST_MET		0x04
#define	ST_BUSY		0x08
#define	ST_INTERGOOD	0x10
#define	ST_INTERMET	0x14
#define	ST_CONFLICT	0x18
#define	ST_QUEFULL	0x28
#define	ST_UNK		0xff

/* message */
#define	MSG_COMP	0x00
#define	MSG_EXTEND	0x01

#define	MKMSG_EXTEND(XLEN, XCODE) ((((u_int)(XLEN)) << NBBY) | ((u_int)(XCODE)))
#define	MSG_EXTEND_MDPCODE	0x00
#define	MSG_EXTEND_MDPLEN	0x05
#define	MSG_EXTEND_SYNCHCODE	0x01
#define	MSG_EXTEND_SYNCHLEN	0x03
#define	MSG_EXTEND_WIDECODE	0x03
#define	MSG_EXTEND_WIDELEN	0x02

#define	MSG_SAVESP	0x02
#define	MSG_RESTORESP	0x03
#define	MSG_DISCON	0x04
#define	MSG_I_ERROR	0x05
#define	MSG_ABORT	0x06
#define	MSG_REJECT	0x07
#define	MSG_NOOP	0x08
#define	MSG_PARITY	0x09
#define	MSG_LCOMP	0x0a
#define	MSG_LCOMP_F	0x0b
#define	MSG_RESET	0x0c
OpenPOWER on IntegriCloud