xref: /netbsd-src/sys/arch/amiga/dev/siopvar.h (revision 2e9df72ec394f443f02e2e3b5922bfdfe348dab9)
1 /*	$NetBSD: siopvar.h,v 1.29 2022/04/07 19:33:37 andvar Exp $	*/
2 
3 /*
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Van Jacobson of Lawrence Berkeley Laboratory.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)siopvar.h	7.1 (Berkeley) 5/8/90
35  */
36 #ifndef _SIOPVAR_H_
37 #define _SIOPVAR_H_
38 
39 /*
40  * The largest single request will be MAXPHYS bytes which will require
41  * at most MAXPHYS/PAGE_SIZE+1 chain elements to describe, i.e. if none of
42  * the buffer pages are physically contiguous (MAXPHYS/PAGE_SIZE) and the
43  * buffer is not page aligned (+1).
44  */
45 #define	DMAMAXIO	(MAXPHYS/PAGE_SIZE+1)
46 
47 /*
48  * Data Structure for SCRIPTS program
49  */
50 struct siop_ds {
51 	long	scsi_addr;		/* SCSI ID & sync */
52 	long	idlen;			/* Identify message */
53 	char	*idbuf;
54 	long	cmdlen;			/* SCSI command */
55 	char	*cmdbuf;
56 	long	stslen;			/* Status */
57 	char	*stsbuf;
58 	long	msglen;			/* Message */
59 	char	*msgbuf;
60 	long	msginlen;		/* Message in */
61 	char	*msginbuf;
62 	long	extmsglen;		/* Extended message in */
63 	char	*extmsgbuf;
64 	long	synmsglen;		/* Sync transfer request */
65 	char	*synmsgbuf;
66 	struct {
67 		long datalen;
68 		char *databuf;
69 	} chain[DMAMAXIO];
70 };
71 
72 /*
73  * ACB. Holds additional information for each SCSI command Comments: We
74  * need a separate scsi command block because we may need to overwrite it
75  * with a request sense command.  Basically, we refrain from fiddling with
76  * the scsi_xfer struct (except do the expected updating of return values).
77  * We'll generally update: xs->{flags,resid,error,sense,status} and
78  * occasionally xs->retries.
79  */
80 struct siop_acb {
81 	TAILQ_ENTRY(siop_acb) chain;
82 	struct scsipi_xfer *xs;	/* SCSI xfer ctrl block from above */
83 	int		flags;	/* Status */
84 #define ACB_FREE	0x00
85 #define ACB_ACTIVE	0x01
86 #define ACB_DONE	0x04
87 	struct scsipi_generic cmd;  /* SCSI command block */
88 	struct siop_ds ds;
89 	void	*iob_buf;
90 	u_long	iob_curbuf;
91 	u_long	iob_len, iob_curlen;
92 	u_char	msgout[6];
93 	u_char	msg[6];
94 	u_char	stat[1];
95 	u_char	status;
96 	u_char	dummy[2];
97 	int	 clen;
98 	char	*daddr;		/* Saved data pointer */
99 	int	 dleft;		/* Residue */
100 };
101 
102 /*
103  * Some info about each (possible) target on the SCSI bus.  This should
104  * probably have been a "per target+lunit" structure, but we'll leave it at
105  * this for now.  Is there a way to reliably hook it up to sc->fordriver??
106  */
107 struct siop_tinfo {
108 	int	cmds;		/* #commands processed */
109 	int	dconns;		/* #disconnects */
110 	int	touts;		/* #timeouts */
111 	int	perrs;		/* #parity errors */
112 	ushort	lubusy;		/* What local units/subr. are busy? */
113 	u_char  flags;
114 	u_char  period;		/* Period suggestion */
115 	u_char  offset;		/* Offset suggestion */
116 };
117 
118 struct	siop_softc {
119 	device_t sc_dev;
120 	struct	isr sc_isr;
121 	void	*sc_siop_si;
122 
123 	u_char	sc_istat;
124 	u_char	sc_dstat;
125 #ifndef ARCH_720
126 	u_char	sc_sstat0;
127 #endif
128 	u_char	sc_sstat1;
129 #ifdef ARCH_720
130 	u_short	sc_sist;
131 #endif
132 	u_long	sc_intcode;
133 	struct	scsipi_adapter sc_adapter;
134 	struct	scsipi_channel sc_channel;
135 	u_long	sc_scriptspa;		/* physical address of scripts */
136 	siop_regmap_p	sc_siopp;	/* the SIOP */
137 	u_long	sc_active;		/* number of active I/O's */
138 
139 	/* Lists of command blocks */
140 	TAILQ_HEAD(acb_list, siop_acb) free_list,
141 				       ready_list,
142 				       nexus_list;
143 
144 	struct siop_acb *sc_nexus;	/* current command */
145 #define SIOP_NACB 16
146 	struct siop_acb *sc_acb;	/* the real command blocks */
147 #ifndef ARCH_720
148 	struct siop_tinfo sc_tinfo[8];
149 #else
150 	struct siop_tinfo sc_tinfo[16];
151 #endif
152 
153 	u_short	sc_clock_freq;
154 	u_char	sc_dcntl;
155 	u_char	sc_ctest7;
156 	u_short	sc_tcp[4];
157 	u_char	sc_flags;
158 	u_char	sc_dien;
159 	u_char	sc_minsync;
160 #ifndef ARCH_720
161 	u_char	sc_sien;
162 #else
163 	u_short	sc_sien;
164 #endif
165 	/* one for each target */
166 	struct syncpar {
167 		u_char state;
168 		u_char sxfer;
169 #ifndef ARCH_720
170 		u_char sbcl;
171 #else
172 		u_char scntl3;
173 #endif
174 	} sc_sync[16];
175 };
176 
177 /* sc_flags */
178 #define	SIOP_INTSOFF	0x80	/* Interrupts turned off */
179 #define	SIOP_INTDEFER	0x40	/* Level 6 interrupt has been deferred */
180 #define	SIOP_ALIVE	0x01	/* controller initialized */
181 #define SIOP_SELECTED	0x04	/* bus is in selected state. Needed for
182 				   correct abort procedure. */
183 
184 /* negotiation states */
185 #define NEG_WIDE	0	/* Negotiate wide transfers */
186 #define	NEG_WAITW	1	/* Waiting for wide negotiation response */
187 #define NEG_SYNC	2	/* Negotiate synch transfers */
188 #define	NEG_WAITS	3	/* Waiting for synch negoation response */
189 #define NEG_DONE	4	/* Wide and/or sync negotiation done */
190 
191 #define	MSG_CMD_COMPLETE	0x00
192 #define MSG_EXT_MESSAGE		0x01
193 #define	MSG_SAVE_DATA_PTR	0x02
194 #define	MSG_RESTORE_PTR		0x03
195 #define	MSG_DISCONNECT		0x04
196 #define	MSG_INIT_DETECT_ERROR	0x05
197 #define	MSG_ABORT		0x06
198 #define	MSG_REJECT		0x07
199 #define	MSG_NOOP		0x08
200 #define	MSG_PARITY_ERROR	0x09
201 #define	MSG_BUS_DEVICE_RESET	0x0C
202 #define	MSG_IDENTIFY		0x80
203 #define	MSG_IDENTIFY_DR		0xc0	/* (disconnect/reconnect allowed) */
204 #define	MSG_SYNC_REQ		0x01
205 #define	MSG_WIDE_REQ		0x03
206 
207 #define	STS_CHECKCOND	0x02	/* Check Condition (ie., read sense) */
208 #define	STS_CONDMET	0x04	/* Condition Met (ie., search worked) */
209 #define	STS_BUSY	0x08
210 #define	STS_INTERMED	0x10	/* Intermediate status sent */
211 #define	STS_EXT		0x80	/* Extended status valid */
212 
213 #ifdef ARCH_720
214 void siopng_minphys(struct buf *bp);
215 void siopng_scsipi_request(struct scsipi_channel *,
216 			scsipi_adapter_req_t, void *);
217 void siopnginitialize(struct siop_softc *);
218 void siopngintr(struct siop_softc *);
219 void siopng_dump_registers(struct siop_softc *);
220 #ifdef DEBUG
221 void siopng_dump(struct siop_softc *);
222 #endif
223 
224 #else
225 
226 void siop_minphys(struct buf *bp);
227 void siop_scsipi_request(struct scsipi_channel *,
228 			scsipi_adapter_req_t, void *);
229 void siopinitialize(struct siop_softc *);
230 void siopintr(struct siop_softc *);
231 void siop_dump_registers(struct siop_softc *);
232 #ifdef DEBUG
233 void siop_dump(struct siop_softc *);
234 #endif
235 #endif
236 
237 #endif /* _SIOPVAR_H */
238