osiopvar.h revision 1.1.2.3 1 1.1.2.3 nathanw /* $NetBSD: osiopvar.h,v 1.1.2.3 2002/01/08 00:30:03 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*
4 1.1.2.2 nathanw * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
5 1.1.2.2 nathanw *
6 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
7 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
8 1.1.2.2 nathanw * are met:
9 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
11 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
14 1.1.2.2 nathanw * 3. The name of the author may not be used to endorse or promote products
15 1.1.2.2 nathanw * derived from this software without specific prior written permission.
16 1.1.2.2 nathanw *
17 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1.2.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1.2.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1.2.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1.2.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1.2.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1.2.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1.2.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1.2.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1.2.2 nathanw */
28 1.1.2.2 nathanw
29 1.1.2.2 nathanw /*
30 1.1.2.2 nathanw * Copyright (c) 1990 The Regents of the University of California.
31 1.1.2.2 nathanw * All rights reserved.
32 1.1.2.2 nathanw *
33 1.1.2.2 nathanw * This code is derived from software contributed to Berkeley by
34 1.1.2.2 nathanw * Van Jacobson of Lawrence Berkeley Laboratory.
35 1.1.2.2 nathanw *
36 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
37 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
38 1.1.2.2 nathanw * are met:
39 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
40 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
41 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
42 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
43 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
44 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
45 1.1.2.2 nathanw * must display the following acknowledgement:
46 1.1.2.2 nathanw * This product includes software developed by the University of
47 1.1.2.2 nathanw * California, Berkeley and its contributors.
48 1.1.2.2 nathanw * 4. Neither the name of the University nor the names of its contributors
49 1.1.2.2 nathanw * may be used to endorse or promote products derived from this software
50 1.1.2.2 nathanw * without specific prior written permission.
51 1.1.2.2 nathanw *
52 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 1.1.2.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1.2.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.1.2.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 1.1.2.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1.2.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1.2.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1.2.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1.2.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.1.2.2 nathanw * SUCH DAMAGE.
63 1.1.2.2 nathanw *
64 1.1.2.2 nathanw * @(#)siopvar.h 7.1 (Berkeley) 5/8/90
65 1.1.2.2 nathanw */
66 1.1.2.2 nathanw
67 1.1.2.2 nathanw #define osiop_read_1(sc, reg) \
68 1.1.2.2 nathanw bus_space_read_1((sc)->sc_bst, (sc)->sc_reg, reg)
69 1.1.2.2 nathanw #define osiop_write_1(sc, reg, val) \
70 1.1.2.2 nathanw bus_space_write_1((sc)->sc_bst, (sc)->sc_reg, reg, val)
71 1.1.2.2 nathanw
72 1.1.2.2 nathanw #define osiop_read_4(sc, reg) \
73 1.1.2.2 nathanw bus_space_read_4((sc)->sc_bst, (sc)->sc_reg, reg)
74 1.1.2.2 nathanw #define osiop_write_4(sc, reg, val) \
75 1.1.2.2 nathanw bus_space_write_4((sc)->sc_bst, (sc)->sc_reg, reg, val)
76 1.1.2.2 nathanw
77 1.1.2.2 nathanw /*
78 1.1.2.2 nathanw * The largest single request will be MAXPHYS bytes which will require
79 1.1.2.2 nathanw * at most MAXPHYS/NBPG+1 chain elements to describe, i.e. if none of
80 1.1.2.2 nathanw * the buffer pages are physically contiguous (MAXPHYS/NBPG) and the
81 1.1.2.2 nathanw * buffer is not page aligned (+1).
82 1.1.2.2 nathanw */
83 1.1.2.2 nathanw /* XXX This should be (MAXPHYS / NBPG + 1), but hardcoded in script */
84 1.1.2.2 nathanw #define OSIOP_NSG (16 + 1)
85 1.1.2.2 nathanw #if MAXPHYS > (PAGE_SIZE * (OSIOP_NSG - 1))
86 1.1.2.2 nathanw #define OSIOP_MAX_XFER (PAGE_SIZE * (OSIOP_NSG - 1))
87 1.1.2.2 nathanw #else
88 1.1.2.2 nathanw #define OSIOP_MAX_XFER MAXPHYS
89 1.1.2.2 nathanw #endif
90 1.1.2.2 nathanw
91 1.1.2.2 nathanw #define OSIOP_NTGT 8
92 1.1.2.2 nathanw #define OSIOP_NACB 32 /* XXX (PAGE_SIZE / sizeof(osiop_ds)) is better? */
93 1.1.2.2 nathanw
94 1.1.2.2 nathanw /*
95 1.1.2.2 nathanw * Data Structure for SCRIPTS program
96 1.1.2.2 nathanw */
97 1.1.2.2 nathanw typedef struct buf_table {
98 1.1.2.2 nathanw u_int32_t count;
99 1.1.2.2 nathanw u_int32_t addr;
100 1.1.2.2 nathanw } buf_table_t;
101 1.1.2.2 nathanw
102 1.1.2.2 nathanw struct osiop_ds {
103 1.1.2.2 nathanw u_int32_t scsi_addr; /* SCSI ID & sync */
104 1.1.2.2 nathanw u_int32_t pad1;
105 1.1.2.2 nathanw buf_table_t id; /* Identify message */
106 1.1.2.2 nathanw buf_table_t cmd; /* SCSI command */
107 1.1.2.2 nathanw buf_table_t status; /* Status */
108 1.1.2.2 nathanw buf_table_t msg; /* Message */
109 1.1.2.2 nathanw buf_table_t msgin; /* Message in */
110 1.1.2.2 nathanw buf_table_t extmsg; /* Extended message in */
111 1.1.2.2 nathanw buf_table_t synmsg; /* Sync transfer request */
112 1.1.2.2 nathanw buf_table_t data[OSIOP_NSG]; /* DMA S/G buffers */
113 1.1.2.2 nathanw
114 1.1.2.2 nathanw u_int8_t msgout[8];
115 1.1.2.2 nathanw u_int8_t msgbuf[8];
116 1.1.2.2 nathanw u_int8_t stat[8];
117 1.1.2.2 nathanw } __attribute__((__packed__));
118 1.1.2.2 nathanw
119 1.1.2.2 nathanw /* status can hold the SCSI_* status values, and 2 additionnal values: */
120 1.1.2.2 nathanw #define SCSI_OSIOP_NOCHECK 0xfe /* don't check the scsi status */
121 1.1.2.2 nathanw #define SCSI_OSIOP_NOSTATUS 0xff /* device didn't report status */
122 1.1.2.2 nathanw
123 1.1.2.2 nathanw #define MSG_INVALID 0xff /* dummy value for message buffer */
124 1.1.2.2 nathanw
125 1.1.2.2 nathanw #define OSIOP_DSOFF(x) offsetof(struct osiop_ds, x)
126 1.1.2.2 nathanw #define OSIOP_DSIDOFF OSIOP_DSOFF(msgout[0])
127 1.1.2.2 nathanw #define OSIOP_DSMSGOFF OSIOP_DSOFF(msgbuf[0])
128 1.1.2.2 nathanw #define OSIOP_DSMSGINOFF OSIOP_DSOFF(msgbuf[1])
129 1.1.2.2 nathanw #define OSIOP_DSEXTMSGOFF OSIOP_DSOFF(msgbuf[2])
130 1.1.2.2 nathanw #define OSIOP_DSSYNMSGOFF OSIOP_DSOFF(msgbuf[3])
131 1.1.2.2 nathanw #define OSIOP_DSSTATOFF OSIOP_DSOFF(stat[0])
132 1.1.2.2 nathanw
133 1.1.2.2 nathanw /*
134 1.1.2.2 nathanw * ACB. Holds additional information for each SCSI command Comments:
135 1.1.2.2 nathanw * Basicly, we refrain from fiddling with the scsi_xfer struct
136 1.1.2.2 nathanw * (except do the expected updating of return values).
137 1.1.2.2 nathanw * We'll generally update: xs->{flags,resid,error,status} and
138 1.1.2.2 nathanw * occasionally xs->retries.
139 1.1.2.2 nathanw */
140 1.1.2.2 nathanw struct osiop_acb {
141 1.1.2.2 nathanw TAILQ_ENTRY(osiop_acb) chain;
142 1.1.2.2 nathanw struct scsipi_xfer *xs; /* SCSI xfer ctrl block from upper layer */
143 1.1.2.2 nathanw struct osiop_softc *sc; /* points back to our adapter */
144 1.1.2.2 nathanw
145 1.1.2.2 nathanw bus_dmamap_t cmddma; /* DMA map for SCSI command */
146 1.1.2.2 nathanw bus_dmamap_t datadma; /* DMA map for data transfer */
147 1.1.2.2 nathanw
148 1.1.2.2 nathanw struct osiop_ds *ds; /* data structure for this acb */
149 1.1.2.2 nathanw bus_size_t dsoffset; /* offset of data structure for this acb */
150 1.1.2.2 nathanw
151 1.1.2.2 nathanw bus_size_t cmdlen; /* command length */
152 1.1.2.2 nathanw bus_size_t datalen; /* transfer data length */
153 1.1.2.2 nathanw #ifdef OSIOP_DEBUG
154 1.1.2.2 nathanw void *data; /* transfer data buffer ptr */
155 1.1.2.2 nathanw #endif
156 1.1.2.2 nathanw
157 1.1.2.2 nathanw bus_addr_t curaddr; /* current transfer data buffer */
158 1.1.2.2 nathanw bus_size_t curlen; /* current transfer data length */
159 1.1.2.2 nathanw
160 1.1.2.2 nathanw int status; /* status of this acb */
161 1.1.2.2 nathanw /* status defs */
162 1.1.2.2 nathanw #define ACB_S_FREE 0 /* cmd slot is free */
163 1.1.2.2 nathanw #define ACB_S_READY 1 /* cmd slot is waiting for processing */
164 1.1.2.2 nathanw #define ACB_S_ACTIVE 2 /* cmd slot is being processed */
165 1.1.2.2 nathanw #define ACB_S_DONE 3 /* cmd slot has been processed */
166 1.1.2.2 nathanw
167 1.1.2.2 nathanw int flags; /* cmd slot flags */
168 1.1.2.2 nathanw #define ACB_F_TIMEOUT 0x01 /* command timeout */
169 1.1.2.2 nathanw
170 1.1.2.2 nathanw u_int8_t intstat; /* buffer to save sc_flags on disconnect */
171 1.1.2.2 nathanw };
172 1.1.2.2 nathanw
173 1.1.2.2 nathanw /*
174 1.1.2.2 nathanw * Some info about each (possible) target on the SCSI bus. This should
175 1.1.2.2 nathanw * probably have been a "per target+lunit" structure, but we'll leave it at
176 1.1.2.2 nathanw * this for now. Is there a way to reliably hook it up to sc->fordriver??
177 1.1.2.2 nathanw */
178 1.1.2.2 nathanw struct osiop_tinfo {
179 1.1.2.2 nathanw int cmds; /* number of commands processed */
180 1.1.2.2 nathanw int dconns; /* number of disconnects */
181 1.1.2.2 nathanw int touts; /* number of timeouts */
182 1.1.2.2 nathanw int perrs; /* number of parity errors */
183 1.1.2.3 nathanw int lubusy; /* What local units/subr. are busy? */
184 1.1.2.3 nathanw int period; /* Period suggestion */
185 1.1.2.3 nathanw int offset; /* Offset suggestion */
186 1.1.2.3 nathanw int flags; /* misc flags per each target */
187 1.1.2.2 nathanw #define TI_NOSYNC 0x01 /* disable sync xfer on this target */
188 1.1.2.2 nathanw #define TI_NODISC 0x02 /* disable disconnect on this target */
189 1.1.2.3 nathanw int state; /* negotiation state */
190 1.1.2.3 nathanw u_int8_t sxfer; /* value for SXFER reg */
191 1.1.2.3 nathanw u_int8_t sbcl; /* value for SBCL reg */
192 1.1.2.2 nathanw } tinfo_t;
193 1.1.2.2 nathanw
194 1.1.2.2 nathanw struct osiop_softc {
195 1.1.2.2 nathanw struct device sc_dev;
196 1.1.2.2 nathanw
197 1.1.2.2 nathanw bus_space_tag_t sc_bst; /* bus space tag */
198 1.1.2.2 nathanw bus_space_handle_t sc_reg; /* register I/O handle */
199 1.1.2.2 nathanw
200 1.1.2.2 nathanw bus_dma_tag_t sc_dmat; /* bus dma tag */
201 1.1.2.2 nathanw bus_dmamap_t sc_scrdma; /* script dma map */
202 1.1.2.2 nathanw bus_dmamap_t sc_dsdma; /* script data dma map */
203 1.1.2.2 nathanw
204 1.1.2.2 nathanw u_int32_t *sc_script; /* ptr to script memory */
205 1.1.2.2 nathanw struct osiop_ds *sc_ds; /* ptr to data structure memory */
206 1.1.2.2 nathanw
207 1.1.2.2 nathanw int sc_id; /* adapter SCSI id */
208 1.1.2.2 nathanw int sc_active; /* number of active I/O's */
209 1.1.2.2 nathanw
210 1.1.2.2 nathanw struct osiop_acb *sc_nexus; /* current command */
211 1.1.2.2 nathanw struct osiop_acb *sc_acb; /* the real command blocks */
212 1.1.2.2 nathanw
213 1.1.2.2 nathanw /* Lists of command blocks */
214 1.1.2.2 nathanw TAILQ_HEAD(acb_list, osiop_acb) free_list,
215 1.1.2.2 nathanw ready_list,
216 1.1.2.2 nathanw nexus_list;
217 1.1.2.2 nathanw
218 1.1.2.2 nathanw struct scsipi_adapter sc_adapter;
219 1.1.2.2 nathanw struct scsipi_channel sc_channel;
220 1.1.2.2 nathanw
221 1.1.2.2 nathanw struct osiop_tinfo sc_tinfo[OSIOP_NTGT];
222 1.1.2.2 nathanw
223 1.1.2.2 nathanw int sc_clock_freq;
224 1.1.2.2 nathanw int sc_tcp[4];
225 1.1.2.2 nathanw int sc_flags;
226 1.1.2.2 nathanw #define OSIOP_INTSOFF 0x80 /* Interrupts turned off */
227 1.1.2.2 nathanw #define OSIOP_INTDEFER 0x40 /* MD interrupt has been deferred */
228 1.1.2.2 nathanw #define OSIOP_NODMA 0x02 /* No DMA transfer */
229 1.1.2.2 nathanw #define OSIOP_ALIVE 0x01 /* controller initialized */
230 1.1.2.2 nathanw
231 1.1.2.2 nathanw int sc_cfflags; /* copy of config flags */
232 1.1.2.2 nathanw
233 1.1.2.3 nathanw int sc_minsync;
234 1.1.2.2 nathanw
235 1.1.2.2 nathanw u_int8_t sc_dstat;
236 1.1.2.2 nathanw u_int8_t sc_sstat0;
237 1.1.2.2 nathanw u_int8_t sc_sstat1;
238 1.1.2.2 nathanw u_int8_t sc_istat;
239 1.1.2.2 nathanw u_int8_t sc_dcntl;
240 1.1.2.2 nathanw u_int8_t sc_ctest7;
241 1.1.2.2 nathanw u_int8_t sc_sien;
242 1.1.2.2 nathanw u_int8_t sc_dien;
243 1.1.2.2 nathanw };
244 1.1.2.2 nathanw
245 1.1.2.2 nathanw /* negotiation states */
246 1.1.2.2 nathanw #define NEG_INIT 0 /* Initial negotiate state */
247 1.1.2.3 nathanw #define NEG_SYNC NEG_INIT /* Negotiate synch transfers */
248 1.1.2.3 nathanw #define NEG_WAITS 1 /* Waiting for synch negoation response */
249 1.1.2.3 nathanw #define NEG_DONE 2 /* Wide and/or sync negotation done */
250 1.1.2.2 nathanw
251 1.1.2.2 nathanw void osiop_attach(struct osiop_softc *);
252 1.1.2.2 nathanw void osiop_intr(struct osiop_softc *);
253