mscpvar.h revision 1.13 1 1.13 yamt /* $NetBSD: mscpvar.h,v 1.13 2005/10/15 17:29:25 yamt Exp $ */
2 1.1 ragge /*
3 1.1 ragge * Copyright (c) 1988 Regents of the University of California.
4 1.1 ragge * All rights reserved.
5 1.10 agc *
6 1.10 agc * This code is derived from software contributed to Berkeley by
7 1.10 agc * Chris Torek.
8 1.10 agc *
9 1.10 agc * Redistribution and use in source and binary forms, with or without
10 1.10 agc * modification, are permitted provided that the following conditions
11 1.10 agc * are met:
12 1.10 agc * 1. Redistributions of source code must retain the above copyright
13 1.10 agc * notice, this list of conditions and the following disclaimer.
14 1.10 agc * 2. Redistributions in binary form must reproduce the above copyright
15 1.10 agc * notice, this list of conditions and the following disclaimer in the
16 1.10 agc * documentation and/or other materials provided with the distribution.
17 1.10 agc * 3. Neither the name of the University nor the names of its contributors
18 1.10 agc * may be used to endorse or promote products derived from this software
19 1.10 agc * without specific prior written permission.
20 1.10 agc *
21 1.10 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.10 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.10 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.10 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.10 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.10 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.10 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.10 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.10 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.10 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.10 agc * SUCH DAMAGE.
32 1.10 agc *
33 1.10 agc * @(#)mscpvar.h 7.3 (Berkeley) 6/28/90
34 1.10 agc */
35 1.10 agc
36 1.10 agc /*
37 1.10 agc * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
38 1.1 ragge *
39 1.1 ragge * This code is derived from software contributed to Berkeley by
40 1.1 ragge * Chris Torek.
41 1.1 ragge *
42 1.1 ragge * Redistribution and use in source and binary forms, with or without
43 1.1 ragge * modification, are permitted provided that the following conditions
44 1.1 ragge * are met:
45 1.1 ragge * 1. Redistributions of source code must retain the above copyright
46 1.1 ragge * notice, this list of conditions and the following disclaimer.
47 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
48 1.1 ragge * notice, this list of conditions and the following disclaimer in the
49 1.1 ragge * documentation and/or other materials provided with the distribution.
50 1.1 ragge * 3. All advertising materials mentioning features or use of this software
51 1.1 ragge * must display the following acknowledgement:
52 1.1 ragge * This product includes software developed by the University of
53 1.1 ragge * California, Berkeley and its contributors.
54 1.1 ragge * 4. Neither the name of the University nor the names of its contributors
55 1.1 ragge * may be used to endorse or promote products derived from this software
56 1.1 ragge * without specific prior written permission.
57 1.1 ragge *
58 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.1 ragge * SUCH DAMAGE.
69 1.1 ragge *
70 1.1 ragge * @(#)mscpvar.h 7.3 (Berkeley) 6/28/90
71 1.1 ragge */
72 1.1 ragge
73 1.1 ragge /*
74 1.1 ragge * MSCP generic driver configuration
75 1.1 ragge */
76 1.1 ragge
77 1.1 ragge /*
78 1.1 ragge * Enabling MSCP_PARANOIA makes the response code perform various checks
79 1.1 ragge * on the hardware. (Right now it verifies only the buffer pointer in
80 1.1 ragge * mscp_cmdref.)
81 1.1 ragge *
82 1.1 ragge * Enabling AVOID_EMULEX_BUG selects an alternative method of identifying
83 1.1 ragge * transfers in progress, which gets around a rather peculiar bug in the
84 1.1 ragge * SC41/MS. Enabling MSCP_PARANOIA instead should work, but will cause
85 1.1 ragge * `extra' Unibus resets.
86 1.1 ragge *
87 1.1 ragge * Either of these flags can simply be included as an `options' line in
88 1.1 ragge * your configuration file.
89 1.1 ragge */
90 1.1 ragge
91 1.1 ragge /* #define MSCP_PARANOIA */
92 1.1 ragge /* #define AVOID_EMULEX_BUG */
93 1.1 ragge
94 1.1 ragge /*
95 1.1 ragge * Ring information, per ring (one each for commands and responses).
96 1.1 ragge */
97 1.1 ragge struct mscp_ri {
98 1.1 ragge int mri_size; /* ring size */
99 1.1 ragge int mri_next; /* next (expected|free) */
100 1.1 ragge long *mri_desc; /* base address of descriptors */
101 1.1 ragge struct mscp *mri_ring; /* base address of packets */
102 1.1 ragge };
103 1.1 ragge
104 1.7 ragge /*
105 1.7 ragge * Transfer info, one per command packet.
106 1.7 ragge */
107 1.7 ragge struct mscp_xi {
108 1.7 ragge bus_dmamap_t mxi_dmam; /* Allocated DMA map for this entry */
109 1.7 ragge struct buf * mxi_bp; /* Buffer used in this command */
110 1.7 ragge struct mscp * mxi_mp; /* Packet used in this command */
111 1.7 ragge int mxi_inuse;
112 1.7 ragge };
113 1.7 ragge
114 1.1 ragge struct mscp_ctlr {
115 1.1 ragge void (*mc_ctlrdone) /* controller operation complete */
116 1.11 perry (struct device *);
117 1.7 ragge void (*mc_go) /* device-specific start routine */
118 1.11 perry (struct device *, struct mscp_xi *);
119 1.1 ragge void (*mc_saerror) /* ctlr error handling */
120 1.11 perry (struct device *, int);
121 1.1 ragge };
122 1.1 ragge
123 1.2 ragge struct mscp_softc;
124 1.2 ragge
125 1.1 ragge struct mscp_device {
126 1.2 ragge void (*me_dgram) /* error datagram */
127 1.11 perry (struct device *, struct mscp *, struct mscp_softc *);
128 1.2 ragge void (*me_iodone) /* normal I/O is done */
129 1.11 perry (struct device *, struct buf *);
130 1.2 ragge int (*me_online) /* drive on line */
131 1.11 perry (struct device *, struct mscp *);
132 1.5 ragge int (*me_gotstatus) /* got unit status */
133 1.11 perry (struct device *, struct mscp *);
134 1.2 ragge void (*me_replace) /* replace done */
135 1.11 perry (struct device *, struct mscp *);
136 1.2 ragge int (*me_ioerr) /* read or write failed */
137 1.11 perry (struct device *, struct mscp *, struct buf *);
138 1.2 ragge void (*me_bb) /* B_BAD io done */
139 1.11 perry (struct device *, struct mscp *, struct buf *);
140 1.2 ragge void (*me_fillin) /* Fill in mscp info for this drive */
141 1.11 perry (struct buf *,struct mscp *);
142 1.2 ragge void (*me_cmddone) /* Non-data transfer operation is done */
143 1.11 perry (struct device *, struct mscp *);
144 1.1 ragge };
145 1.1 ragge
146 1.1 ragge /*
147 1.1 ragge * This struct is used when attaching a mscpbus.
148 1.1 ragge */
149 1.1 ragge struct mscp_attach_args {
150 1.1 ragge struct mscp_ctlr *ma_mc; /* Pointer to ctlr's mscp_ctlr */
151 1.1 ragge int ma_type; /* disk/tape bus type */
152 1.1 ragge struct mscp_pack *ma_uda; /* comm area virtual */
153 1.1 ragge struct mscp_softc **ma_softc; /* backpointer to bus softc */
154 1.7 ragge bus_dmamap_t ma_dmam; /* This comm area dma info */
155 1.7 ragge bus_dma_tag_t ma_dmat;
156 1.7 ragge bus_space_tag_t ma_iot;
157 1.7 ragge bus_space_handle_t ma_iph; /* initialisation and polling */
158 1.7 ragge bus_space_handle_t ma_sah; /* status & address (read part) */
159 1.7 ragge bus_space_handle_t ma_swh; /* status & address (write part) */
160 1.1 ragge short ma_ivec; /* Interrupt vector to use */
161 1.3 ragge char ma_ctlrnr; /* Phys ctlr nr */
162 1.3 ragge char ma_adapnr; /* Phys adapter nr */
163 1.1 ragge };
164 1.1 ragge #define MSCPBUS_DISK 001 /* Bus is used for disk mounts */
165 1.1 ragge #define MSCPBUS_TAPE 002 /* Bus is used for tape mounts */
166 1.5 ragge #define MSCPBUS_UDA 004 /* ctlr is disk on unibus/qbus */
167 1.5 ragge #define MSCPBUS_KDB 010 /* ctlr is disk on BI */
168 1.5 ragge #define MSCPBUS_KLE 020 /* ctlr is tape on unibus/qbus */
169 1.1 ragge
170 1.1 ragge /*
171 1.1 ragge * Used when going for child devices.
172 1.1 ragge */
173 1.1 ragge struct drive_attach_args {
174 1.1 ragge struct mscp *da_mp; /* this devices response struct */
175 1.2 ragge int da_typ; /* Parent of type */
176 1.1 ragge };
177 1.1 ragge
178 1.1 ragge /*
179 1.1 ragge * Return values from functions.
180 1.1 ragge * MSCP_RESTARTED is peculiar to I/O errors.
181 1.1 ragge */
182 1.1 ragge #define MSCP_DONE 0 /* all ok */
183 1.1 ragge #define MSCP_FAILED 1 /* no go */
184 1.1 ragge #define MSCP_RESTARTED 2 /* transfer restarted */
185 1.1 ragge
186 1.1 ragge /*
187 1.1 ragge * Per device information.
188 1.1 ragge *
189 1.1 ragge * mi_ip is a pointer to the inverting pointers (things that get `ui's
190 1.1 ragge * given unit numbers) FOR THIS CONTROLLER (NOT the whole set!).
191 1.1 ragge *
192 1.1 ragge * b_actf holds a queue of those transfers that were started but have
193 1.1 ragge * not yet finished. Other Unibus drivers do not need this as they hand
194 1.1 ragge * out requests one at a time. MSCP devices, however, take a slew of
195 1.1 ragge * requests and pick their own order to execute them. This means that
196 1.1 ragge * we have to have a place to move transfers that were given to the
197 1.1 ragge * controller, so we can tell those apart from those that have not yet
198 1.1 ragge * been handed out; b_actf is that place.
199 1.1 ragge */
200 1.1 ragge struct mscp_softc {
201 1.1 ragge struct device mi_dev; /* Autoconf stuff */
202 1.1 ragge struct mscp_ri mi_cmd; /* MSCP command ring info */
203 1.1 ragge struct mscp_ri mi_rsp; /* MSCP response ring info */
204 1.7 ragge bus_dma_tag_t mi_dmat;
205 1.7 ragge bus_dmamap_t mi_dmam;
206 1.7 ragge struct mscp_xi mi_xi[NCMD];
207 1.7 ragge int mi_mxiuse; /* Bitfield of inuse mxi packets */
208 1.1 ragge short mi_credits; /* transfer credits */
209 1.1 ragge char mi_wantcmd; /* waiting for command packet */
210 1.1 ragge char mi_wantcredits; /* waiting for transfer credits */
211 1.1 ragge struct mscp_ctlr *mi_mc; /* Pointer to parent's mscp_ctlr */
212 1.1 ragge struct mscp_device *mi_me; /* Pointer to child's mscp_device */
213 1.1 ragge struct device **mi_dp; /* array of backpointers */
214 1.2 ragge int mi_driveno; /* Max physical drive number found */
215 1.3 ragge char mi_ctlrnr; /* Phys ctlr nr */
216 1.3 ragge char mi_adapnr; /* Phys adapter nr */
217 1.1 ragge int mi_flags;
218 1.1 ragge struct mscp_pack *mi_uda; /* virtual address */
219 1.1 ragge int mi_type;
220 1.1 ragge short mi_ivec; /* Interrupt vector to use */
221 1.2 ragge short mi_ierr; /* Init err counter */
222 1.7 ragge bus_space_tag_t mi_iot;
223 1.7 ragge bus_space_handle_t mi_iph; /* initialisation and polling */
224 1.7 ragge bus_space_handle_t mi_sah; /* status & address (read part) */
225 1.7 ragge bus_space_handle_t mi_swh; /* status & address (write part) */
226 1.13 yamt struct bufq_state *mi_resq; /* While waiting for packets */
227 1.1 ragge };
228 1.1 ragge
229 1.1 ragge /* mi_flags */
230 1.5 ragge #define MSC_STARTPOLL 1
231 1.5 ragge #define MSC_INSTART 2
232 1.5 ragge #define MSC_IGNOREINTR 4
233 1.5 ragge #define MSC_READY 8
234 1.1 ragge
235 1.1 ragge /*
236 1.1 ragge * We have run out of credits when mi_credits is <= MSCP_MINCREDITS.
237 1.1 ragge * It is still possible to issue one command in this case, but it must
238 1.1 ragge * not be a data transfer. E.g., `get command status' or `abort command'
239 1.1 ragge * is legal, while `read' is not.
240 1.1 ragge */
241 1.1 ragge #define MSCP_MINCREDITS 1
242 1.1 ragge
243 1.1 ragge /*
244 1.1 ragge * Flags for mscp_getcp().
245 1.1 ragge */
246 1.1 ragge #define MSCP_WAIT 1
247 1.1 ragge #define MSCP_DONTWAIT 0
248 1.1 ragge
249 1.1 ragge /* get a command packet */
250 1.1 ragge
251 1.1 ragge /*
252 1.1 ragge * Unit flags
253 1.1 ragge */
254 1.1 ragge #define UNIT_ONLINE 0x01 /* drive is on line */
255 1.1 ragge #define UNIT_HAVESTATUS 0x02 /* got unit status */
256 1.1 ragge #define UNIT_REQUEUE 0x04 /* requeue after response */
257 1.1 ragge
258 1.1 ragge /*
259 1.1 ragge * Handle a command ring transition: wake up sleepers for command packets.
260 1.1 ragge * This is too simple to bother with a function call.
261 1.1 ragge */
262 1.1 ragge #define MSCP_DOCMD(mi) { \
263 1.1 ragge if ((mi)->mi_wantcmd) { \
264 1.1 ragge (mi)->mi_wantcmd = 0; \
265 1.1 ragge wakeup((caddr_t) &(mi)->mi_wantcmd); \
266 1.1 ragge } \
267 1.1 ragge }
268 1.1 ragge
269 1.1 ragge /* Prototypes */
270 1.11 perry struct mscp *mscp_getcp(struct mscp_softc *, int);
271 1.11 perry void mscp_printevent(struct mscp *);
272 1.11 perry void mscp_go(struct mscp_softc *, struct mscp *, int);
273 1.11 perry void mscp_requeue(struct mscp_softc *);
274 1.11 perry void mscp_dorsp(struct mscp_softc *);
275 1.12 ragge int mscp_decodeerror(const char *, struct mscp *, struct mscp_softc *);
276 1.11 perry int mscp_print(void *, const char *);
277 1.11 perry void mscp_hexdump(struct mscp *);
278 1.11 perry void mscp_strategy(struct buf *, struct device *);
279 1.11 perry void mscp_printtype(int, int);
280 1.11 perry int mscp_waitstep(struct mscp_softc *, int, int);
281 1.11 perry void mscp_dgo(struct mscp_softc *, struct mscp_xi *);
282 1.11 perry void mscp_intr(struct mscp_softc *);
283