sfas.c revision 1.3.2.4 1 1.3.2.4 jdolecek /* $NetBSD: sfas.c,v 1.3.2.4 2002/06/23 17:33:57 jdolecek Exp $ */
2 1.3.2.2 thorpej
3 1.3.2.2 thorpej /*
4 1.3.2.2 thorpej * Copyright (c) 1995 Scott Stevens
5 1.3.2.2 thorpej * Copyright (c) 1995 Daniel Widenfalk
6 1.3.2.2 thorpej * Copyright (c) 1994 Christian E. Hopps
7 1.3.2.2 thorpej * Copyright (c) 1990 The Regents of the University of California.
8 1.3.2.2 thorpej * All rights reserved.
9 1.3.2.2 thorpej *
10 1.3.2.2 thorpej * This code is derived from software contributed to Berkeley by
11 1.3.2.2 thorpej * Van Jacobson of Lawrence Berkeley Laboratory.
12 1.3.2.2 thorpej *
13 1.3.2.2 thorpej * Redistribution and use in source and binary forms, with or without
14 1.3.2.2 thorpej * modification, are permitted provided that the following conditions
15 1.3.2.2 thorpej * are met:
16 1.3.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
17 1.3.2.2 thorpej * notice, this list of conditions and the following disclaimer.
18 1.3.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
19 1.3.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
20 1.3.2.2 thorpej * documentation and/or other materials provided with the distribution.
21 1.3.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
22 1.3.2.2 thorpej * must display the following acknowledgement:
23 1.3.2.2 thorpej * This product includes software developed by the University of
24 1.3.2.2 thorpej * California, Berkeley and its contributors.
25 1.3.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
26 1.3.2.2 thorpej * may be used to endorse or promote products derived from this software
27 1.3.2.2 thorpej * without specific prior written permission.
28 1.3.2.2 thorpej *
29 1.3.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 1.3.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 1.3.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.3.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 1.3.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 1.3.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 1.3.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 1.3.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 1.3.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 1.3.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 1.3.2.2 thorpej * SUCH DAMAGE.
40 1.3.2.2 thorpej *
41 1.3.2.2 thorpej * @(#)scsi.c 7.5 (Berkeley) 5/4/91
42 1.3.2.2 thorpej */
43 1.3.2.2 thorpej
44 1.3.2.2 thorpej /*
45 1.3.2.2 thorpej * Emulex FAS216 scsi adaptor driver
46 1.3.2.2 thorpej */
47 1.3.2.2 thorpej
48 1.3.2.2 thorpej /*
49 1.3.2.2 thorpej * Modified for NetBSD/arm32 by Scott Stevens
50 1.3.2.2 thorpej */
51 1.3.2.2 thorpej
52 1.3.2.2 thorpej #include <sys/param.h>
53 1.3.2.2 thorpej #include <sys/systm.h>
54 1.3.2.2 thorpej #include <sys/device.h>
55 1.3.2.2 thorpej #include <sys/buf.h>
56 1.3.2.2 thorpej #include <sys/proc.h>
57 1.3.2.2 thorpej
58 1.3.2.2 thorpej #include <dev/scsipi/scsi_all.h>
59 1.3.2.2 thorpej #include <dev/scsipi/scsipi_all.h>
60 1.3.2.2 thorpej #include <dev/scsipi/scsiconf.h>
61 1.3.2.2 thorpej
62 1.3.2.2 thorpej #include <uvm/uvm_extern.h>
63 1.3.2.2 thorpej
64 1.3.2.2 thorpej #include <machine/pmap.h>
65 1.3.2.2 thorpej #include <machine/cpu.h>
66 1.3.2.2 thorpej #include <machine/io.h>
67 1.3.2.2 thorpej #include <machine/intr.h>
68 1.3.2.2 thorpej #include <arm/arm32/katelib.h>
69 1.3.2.2 thorpej #include <acorn32/podulebus/podulebus.h>
70 1.3.2.2 thorpej #include <acorn32/podulebus/sfasreg.h>
71 1.3.2.2 thorpej #include <acorn32/podulebus/sfasvar.h>
72 1.3.2.2 thorpej
73 1.3.2.2 thorpej void sfasinitialize __P((struct sfas_softc *));
74 1.3.2.2 thorpej void sfas_minphys __P((struct buf *bp));
75 1.3.2.2 thorpej void sfas_scsi_request __P((struct scsipi_channel *,
76 1.3.2.2 thorpej scsipi_adapter_req_t, void *));
77 1.3.2.2 thorpej void sfas_donextcmd __P((struct sfas_softc *dev, struct sfas_pending *pendp));
78 1.3.2.2 thorpej void sfas_scsidone __P((struct sfas_softc *dev, struct scsipi_xfer *xs,
79 1.3.2.2 thorpej int stat));
80 1.3.2.2 thorpej void sfasintr __P((struct sfas_softc *dev));
81 1.3.2.2 thorpej void sfasiwait __P((struct sfas_softc *dev));
82 1.3.2.2 thorpej void sfas_ixfer __P((struct sfas_softc *dev, int polling));
83 1.3.2.2 thorpej void sfasreset __P((struct sfas_softc *dev, int how));
84 1.3.2.2 thorpej int sfasselect __P((struct sfas_softc *dev, struct sfas_pending *pendp,
85 1.3.2.2 thorpej unsigned char *cbuf, int clen,
86 1.3.2.2 thorpej unsigned char *buf, int len, int mode));
87 1.3.2.2 thorpej void sfasicmd __P((struct sfas_softc *dev, struct sfas_pending *pendp));
88 1.3.2.2 thorpej void sfasgo __P((struct sfas_softc *dev, struct sfas_pending *pendp));
89 1.3.2.2 thorpej
90 1.3.2.2 thorpej /*
91 1.3.2.2 thorpej * Initialize these to make 'em patchable. Defaults to enable sync and discon.
92 1.3.2.2 thorpej */
93 1.3.2.2 thorpej u_char sfas_inhibit_sync[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
94 1.3.2.2 thorpej u_char sfas_inhibit_disc[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
95 1.3.2.2 thorpej
96 1.3.2.2 thorpej #define DEBUG
97 1.3.2.2 thorpej #ifdef DEBUG
98 1.3.2.2 thorpej #define QPRINTF(a) if (sfas_debug > 1) printf a
99 1.3.2.2 thorpej int sfas_debug = 2;
100 1.3.2.2 thorpej #else
101 1.3.2.2 thorpej #define QPRINTF
102 1.3.2.2 thorpej #endif
103 1.3.2.2 thorpej
104 1.3.2.2 thorpej /*
105 1.3.2.2 thorpej * default minphys routine for sfas based controllers
106 1.3.2.2 thorpej */
107 1.3.2.2 thorpej void
108 1.3.2.2 thorpej sfas_minphys(bp)
109 1.3.2.2 thorpej struct buf *bp;
110 1.3.2.2 thorpej {
111 1.3.2.2 thorpej
112 1.3.2.2 thorpej /*
113 1.3.2.2 thorpej * No max transfer at this level.
114 1.3.2.2 thorpej */
115 1.3.2.2 thorpej minphys(bp);
116 1.3.2.2 thorpej }
117 1.3.2.2 thorpej
118 1.3.2.2 thorpej /*
119 1.3.2.2 thorpej * Initialize the nexus structs.
120 1.3.2.2 thorpej */
121 1.3.2.2 thorpej void
122 1.3.2.2 thorpej sfas_init_nexus(dev, nexus)
123 1.3.2.2 thorpej struct sfas_softc *dev;
124 1.3.2.2 thorpej struct nexus *nexus;
125 1.3.2.2 thorpej {
126 1.3.2.2 thorpej bzero(nexus, sizeof(struct nexus));
127 1.3.2.2 thorpej
128 1.3.2.2 thorpej nexus->state = SFAS_NS_IDLE;
129 1.3.2.2 thorpej nexus->period = 200;
130 1.3.2.2 thorpej nexus->offset = 0;
131 1.3.2.2 thorpej nexus->syncper = 5;
132 1.3.2.2 thorpej nexus->syncoff = 0;
133 1.3.2.2 thorpej nexus->config3 = dev->sc_config3 & ~SFAS_CFG3_FASTSCSI;
134 1.3.2.2 thorpej }
135 1.3.2.2 thorpej
136 1.3.2.2 thorpej void
137 1.3.2.2 thorpej sfasinitialize(dev)
138 1.3.2.2 thorpej struct sfas_softc *dev;
139 1.3.2.2 thorpej {
140 1.3.2.2 thorpej u_int *pte;
141 1.3.2.2 thorpej int i;
142 1.3.2.2 thorpej
143 1.3.2.2 thorpej dev->sc_led_status = 0;
144 1.3.2.2 thorpej
145 1.3.2.2 thorpej TAILQ_INIT(&dev->sc_xs_pending);
146 1.3.2.2 thorpej TAILQ_INIT(&dev->sc_xs_free);
147 1.3.2.2 thorpej
148 1.3.2.2 thorpej /*
149 1.3.2.2 thorpej * Initialize the sfas_pending structs and link them into the free list. We
150 1.3.2.2 thorpej * have to set vm_link_data.pages to 0 or the vm FIX won't work.
151 1.3.2.2 thorpej */
152 1.3.2.2 thorpej for(i=0; i<MAXPENDING; i++) {
153 1.3.2.2 thorpej TAILQ_INSERT_TAIL(&dev->sc_xs_free, &dev->sc_xs_store[i],
154 1.3.2.2 thorpej link);
155 1.3.2.2 thorpej }
156 1.3.2.2 thorpej
157 1.3.2.2 thorpej /*
158 1.3.2.2 thorpej * Calculate the correct clock conversion factor 2 <= factor <= 8, i.e. set
159 1.3.2.2 thorpej * the factor to clock_freq / 5 (int).
160 1.3.2.2 thorpej */
161 1.3.2.2 thorpej if (dev->sc_clock_freq <= 10)
162 1.3.2.2 thorpej dev->sc_clock_conv_fact = 2;
163 1.3.2.2 thorpej if (dev->sc_clock_freq <= 40)
164 1.3.2.2 thorpej dev->sc_clock_conv_fact = 2+((dev->sc_clock_freq-10)/5);
165 1.3.2.2 thorpej else
166 1.3.2.2 thorpej panic("sfasinitialize: Clock frequence too high");
167 1.3.2.2 thorpej
168 1.3.2.2 thorpej /* Setup and save the basic configuration registers */
169 1.3.2.2 thorpej dev->sc_config1 = (dev->sc_host_id & SFAS_CFG1_BUS_ID_MASK);
170 1.3.2.2 thorpej dev->sc_config2 = SFAS_CFG2_FEATURES_ENABLE;
171 1.3.2.2 thorpej dev->sc_config3 = (dev->sc_clock_freq > 25 ? SFAS_CFG3_FASTCLK : 0);
172 1.3.2.2 thorpej
173 1.3.2.2 thorpej /* Precalculate timeout value and clock period. */
174 1.3.2.2 thorpej /* Ekkk ... floating point in the kernel !!!! */
175 1.3.2.2 thorpej /* dev->sc_timeout_val = 1+dev->sc_timeout*dev->sc_clock_freq/
176 1.3.2.2 thorpej (7.682*dev->sc_clock_conv_fact);*/
177 1.3.2.2 thorpej dev->sc_timeout_val = 1+dev->sc_timeout*dev->sc_clock_freq/
178 1.3.2.2 thorpej ((7682*dev->sc_clock_conv_fact)/1000);
179 1.3.2.2 thorpej dev->sc_clock_period = 1000/dev->sc_clock_freq;
180 1.3.2.2 thorpej
181 1.3.2.2 thorpej sfasreset(dev, 1 | 2); /* Reset Chip and Bus */
182 1.3.2.2 thorpej
183 1.3.2.2 thorpej dev->sc_units_disconnected = 0;
184 1.3.2.2 thorpej dev->sc_msg_in_len = 0;
185 1.3.2.2 thorpej dev->sc_msg_out_len = 0;
186 1.3.2.2 thorpej
187 1.3.2.2 thorpej dev->sc_flags = 0;
188 1.3.2.2 thorpej
189 1.3.2.2 thorpej for(i=0; i<8; i++)
190 1.3.2.2 thorpej sfas_init_nexus(dev, &dev->sc_nexus[i]);
191 1.3.2.2 thorpej
192 1.3.2.2 thorpej if (dev->sc_ixfer == NULL)
193 1.3.2.2 thorpej dev->sc_ixfer = sfas_ixfer;
194 1.3.2.2 thorpej
195 1.3.2.2 thorpej /*
196 1.3.2.2 thorpej * Setup bump buffer.
197 1.3.2.2 thorpej */
198 1.3.2.2 thorpej dev->sc_bump_va = (u_char *)uvm_km_zalloc(kernel_map, dev->sc_bump_sz);
199 1.3.2.2 thorpej (void) pmap_extract(pmap_kernel(), (vaddr_t)dev->sc_bump_va,
200 1.3.2.2 thorpej (paddr_t *)&dev->sc_bump_pa);
201 1.3.2.2 thorpej
202 1.3.2.2 thorpej /*
203 1.3.2.2 thorpej * Setup pages to noncachable, that way we don't have to flush the cache
204 1.3.2.2 thorpej * every time we need "bumped" transfer.
205 1.3.2.2 thorpej */
206 1.3.2.4 jdolecek pte = vtopte((vaddr_t) dev->sc_bump_va);
207 1.3.2.4 jdolecek *pte &= ~(L2_C | L2_B);
208 1.3.2.2 thorpej cpu_tlb_flushD();
209 1.3.2.3 jdolecek cpu_dcache_wbinv_range((vm_offset_t)dev->sc_bump_va, NBPG);
210 1.3.2.2 thorpej
211 1.3.2.2 thorpej printf(" dmabuf V0x%08x P0x%08x", (u_int)dev->sc_bump_va, (u_int)dev->sc_bump_pa);
212 1.3.2.2 thorpej }
213 1.3.2.2 thorpej
214 1.3.2.2 thorpej
215 1.3.2.2 thorpej /*
216 1.3.2.2 thorpej * used by specific sfas controller
217 1.3.2.2 thorpej */
218 1.3.2.2 thorpej void
219 1.3.2.2 thorpej sfas_scsi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
220 1.3.2.2 thorpej void *arg)
221 1.3.2.2 thorpej {
222 1.3.2.2 thorpej struct scsipi_xfer *xs;
223 1.3.2.2 thorpej struct sfas_softc *dev = (void *)chan->chan_adapter->adapt_dev;
224 1.3.2.2 thorpej struct scsipi_periph *periph;
225 1.3.2.2 thorpej struct sfas_pending *pendp;
226 1.3.2.2 thorpej int flags, s, target;
227 1.3.2.2 thorpej
228 1.3.2.2 thorpej switch (req) {
229 1.3.2.2 thorpej case ADAPTER_REQ_RUN_XFER:
230 1.3.2.2 thorpej xs = arg;
231 1.3.2.2 thorpej periph = xs->xs_periph;
232 1.3.2.2 thorpej flags = xs->xs_control;
233 1.3.2.2 thorpej target = periph->periph_target;
234 1.3.2.2 thorpej
235 1.3.2.2 thorpej if (flags & XS_CTL_DATA_UIO)
236 1.3.2.2 thorpej panic("sfas: scsi data uio requested");
237 1.3.2.2 thorpej
238 1.3.2.2 thorpej if ((flags & XS_CTL_POLL) && (dev->sc_flags & SFAS_ACTIVE))
239 1.3.2.2 thorpej panic("sfas_scsicmd: busy");
240 1.3.2.2 thorpej
241 1.3.2.2 thorpej /* Get hold of a sfas_pending block. */
242 1.3.2.2 thorpej s = splbio();
243 1.3.2.2 thorpej pendp = dev->sc_xs_free.tqh_first;
244 1.3.2.2 thorpej if (pendp == NULL) {
245 1.3.2.2 thorpej xs->error = XS_RESOURCE_SHORTAGE;
246 1.3.2.2 thorpej scsipi_done(xs);
247 1.3.2.2 thorpej splx(s);
248 1.3.2.2 thorpej return;
249 1.3.2.2 thorpej }
250 1.3.2.2 thorpej TAILQ_REMOVE(&dev->sc_xs_free, pendp, link);
251 1.3.2.2 thorpej pendp->xs = xs;
252 1.3.2.2 thorpej splx(s);
253 1.3.2.2 thorpej
254 1.3.2.2 thorpej
255 1.3.2.2 thorpej /* If the chip if busy OR the unit is busy, we have to wait for out turn. */
256 1.3.2.2 thorpej if ((dev->sc_flags & SFAS_ACTIVE) ||
257 1.3.2.2 thorpej (dev->sc_nexus[target].flags & SFAS_NF_UNIT_BUSY)) {
258 1.3.2.2 thorpej s = splbio();
259 1.3.2.2 thorpej TAILQ_INSERT_TAIL(&dev->sc_xs_pending, pendp, link);
260 1.3.2.2 thorpej splx(s);
261 1.3.2.2 thorpej } else
262 1.3.2.2 thorpej sfas_donextcmd(dev, pendp);
263 1.3.2.2 thorpej
264 1.3.2.2 thorpej return;
265 1.3.2.2 thorpej
266 1.3.2.2 thorpej case ADAPTER_REQ_GROW_RESOURCES:
267 1.3.2.2 thorpej case ADAPTER_REQ_SET_XFER_MODE:
268 1.3.2.2 thorpej /* XXX Not supported. */
269 1.3.2.2 thorpej return;
270 1.3.2.2 thorpej }
271 1.3.2.2 thorpej }
272 1.3.2.2 thorpej
273 1.3.2.2 thorpej /*
274 1.3.2.2 thorpej * Actually select the unit, whereby the whole scsi-process is started.
275 1.3.2.2 thorpej */
276 1.3.2.2 thorpej void
277 1.3.2.2 thorpej sfas_donextcmd(dev, pendp)
278 1.3.2.2 thorpej struct sfas_softc *dev;
279 1.3.2.2 thorpej struct sfas_pending *pendp;
280 1.3.2.2 thorpej {
281 1.3.2.2 thorpej int s;
282 1.3.2.2 thorpej
283 1.3.2.2 thorpej /*
284 1.3.2.2 thorpej * Special case for scsi unit reset. I think this is waterproof. We first
285 1.3.2.2 thorpej * select the unit during splbio. We then cycle through the generated
286 1.3.2.2 thorpej * interrupts until the interrupt routine signals that the unit has
287 1.3.2.2 thorpej * acknowledged the reset. After that we have to wait a reset to select
288 1.3.2.2 thorpej * delay before anything else can happend.
289 1.3.2.2 thorpej */
290 1.3.2.2 thorpej if (pendp->xs->xs_control & XS_CTL_RESET) {
291 1.3.2.2 thorpej struct nexus *nexus;
292 1.3.2.2 thorpej
293 1.3.2.2 thorpej s = splbio();
294 1.3.2.2 thorpej while(!sfasselect(dev, pendp, 0, 0, 0, 0, SFAS_SELECT_K)) {
295 1.3.2.2 thorpej splx(s);
296 1.3.2.2 thorpej delay(10);
297 1.3.2.2 thorpej s = splbio();
298 1.3.2.2 thorpej }
299 1.3.2.2 thorpej
300 1.3.2.2 thorpej nexus = dev->sc_cur_nexus;
301 1.3.2.2 thorpej while(nexus->flags & SFAS_NF_UNIT_BUSY) {
302 1.3.2.2 thorpej sfasiwait(dev);
303 1.3.2.2 thorpej sfasintr(dev);
304 1.3.2.2 thorpej }
305 1.3.2.2 thorpej
306 1.3.2.2 thorpej nexus->flags |= SFAS_NF_UNIT_BUSY;
307 1.3.2.2 thorpej splx(s);
308 1.3.2.2 thorpej
309 1.3.2.2 thorpej sfasreset(dev, 0);
310 1.3.2.2 thorpej
311 1.3.2.2 thorpej s = splbio();
312 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_UNIT_BUSY;
313 1.3.2.2 thorpej splx(s);
314 1.3.2.2 thorpej }
315 1.3.2.2 thorpej
316 1.3.2.2 thorpej /*
317 1.3.2.2 thorpej * If we are polling, go to splbio and perform the command, else we poke
318 1.3.2.2 thorpej * the scsi-bus via sfasgo to get the interrupt machine going.
319 1.3.2.2 thorpej */
320 1.3.2.2 thorpej if (pendp->xs->xs_control & XS_CTL_POLL) {
321 1.3.2.2 thorpej s = splbio();
322 1.3.2.2 thorpej sfasicmd(dev, pendp);
323 1.3.2.2 thorpej TAILQ_INSERT_TAIL(&dev->sc_xs_free, pendp, link);
324 1.3.2.2 thorpej splx(s);
325 1.3.2.2 thorpej } else {
326 1.3.2.2 thorpej sfasgo(dev, pendp);
327 1.3.2.2 thorpej }
328 1.3.2.2 thorpej }
329 1.3.2.2 thorpej
330 1.3.2.2 thorpej void
331 1.3.2.2 thorpej sfas_scsidone(dev, xs, stat)
332 1.3.2.2 thorpej struct sfas_softc *dev;
333 1.3.2.2 thorpej struct scsipi_xfer *xs;
334 1.3.2.2 thorpej int stat;
335 1.3.2.2 thorpej {
336 1.3.2.2 thorpej struct sfas_pending *pendp;
337 1.3.2.2 thorpej int s;
338 1.3.2.2 thorpej
339 1.3.2.2 thorpej xs->status = stat;
340 1.3.2.2 thorpej
341 1.3.2.2 thorpej if (stat == 0)
342 1.3.2.2 thorpej xs->resid = 0;
343 1.3.2.2 thorpej else {
344 1.3.2.2 thorpej switch(stat) {
345 1.3.2.2 thorpej case SCSI_CHECK:
346 1.3.2.2 thorpej case SCSI_BUSY:
347 1.3.2.2 thorpej xs->error = XS_BUSY;
348 1.3.2.2 thorpej break;
349 1.3.2.2 thorpej case -1:
350 1.3.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
351 1.3.2.2 thorpej QPRINTF(("sfas_scsicmd() bad %x\n", stat));
352 1.3.2.2 thorpej break;
353 1.3.2.2 thorpej default:
354 1.3.2.2 thorpej xs->error = XS_TIMEOUT;
355 1.3.2.2 thorpej break;
356 1.3.2.2 thorpej }
357 1.3.2.2 thorpej }
358 1.3.2.2 thorpej
359 1.3.2.2 thorpej /* Steal the next command from the queue so that one unit can't hog the bus. */
360 1.3.2.2 thorpej s = splbio();
361 1.3.2.2 thorpej pendp = dev->sc_xs_pending.tqh_first;
362 1.3.2.2 thorpej while(pendp) {
363 1.3.2.2 thorpej if (!(dev->sc_nexus[pendp->xs->xs_periph->periph_target].flags &
364 1.3.2.2 thorpej SFAS_NF_UNIT_BUSY))
365 1.3.2.2 thorpej break;
366 1.3.2.2 thorpej pendp = pendp->link.tqe_next;
367 1.3.2.2 thorpej }
368 1.3.2.2 thorpej
369 1.3.2.2 thorpej if (pendp != NULL) {
370 1.3.2.2 thorpej TAILQ_REMOVE(&dev->sc_xs_pending, pendp, link);
371 1.3.2.2 thorpej }
372 1.3.2.2 thorpej
373 1.3.2.2 thorpej splx(s);
374 1.3.2.2 thorpej scsipi_done(xs);
375 1.3.2.2 thorpej
376 1.3.2.2 thorpej if (pendp)
377 1.3.2.2 thorpej sfas_donextcmd(dev, pendp);
378 1.3.2.2 thorpej }
379 1.3.2.2 thorpej
380 1.3.2.2 thorpej /*
381 1.3.2.2 thorpej * There are two kinds of reset:
382 1.3.2.2 thorpej * 1) CHIP-bus reset. This also implies a SCSI-bus reset.
383 1.3.2.2 thorpej * 2) SCSI-bus reset.
384 1.3.2.2 thorpej * After the appropriate resets have been performed we wait a reset to select
385 1.3.2.2 thorpej * delay time.
386 1.3.2.2 thorpej */
387 1.3.2.2 thorpej void
388 1.3.2.2 thorpej sfasreset(dev, how)
389 1.3.2.2 thorpej struct sfas_softc *dev;
390 1.3.2.2 thorpej int how;
391 1.3.2.2 thorpej {
392 1.3.2.2 thorpej sfas_regmap_p rp;
393 1.3.2.2 thorpej int i, s;
394 1.3.2.2 thorpej
395 1.3.2.2 thorpej rp = dev->sc_fas;
396 1.3.2.2 thorpej
397 1.3.2.2 thorpej if (how & 1) {
398 1.3.2.2 thorpej for(i=0; i<8; i++)
399 1.3.2.2 thorpej sfas_init_nexus(dev, &dev->sc_nexus[i]);
400 1.3.2.2 thorpej
401 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_RESET_CHIP;
402 1.3.2.2 thorpej delay(1);
403 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_NOP;
404 1.3.2.2 thorpej
405 1.3.2.2 thorpej *rp->sfas_config1 = dev->sc_config1;
406 1.3.2.2 thorpej *rp->sfas_config2 = dev->sc_config2;
407 1.3.2.2 thorpej *rp->sfas_config3 = dev->sc_config3;
408 1.3.2.2 thorpej *rp->sfas_timeout = dev->sc_timeout_val;
409 1.3.2.2 thorpej *rp->sfas_clkconv = dev->sc_clock_conv_fact &
410 1.3.2.2 thorpej SFAS_CLOCK_CONVERSION_MASK;
411 1.3.2.2 thorpej }
412 1.3.2.2 thorpej
413 1.3.2.2 thorpej if (how & 2) {
414 1.3.2.2 thorpej for(i=0; i<8; i++)
415 1.3.2.2 thorpej sfas_init_nexus(dev, &dev->sc_nexus[i]);
416 1.3.2.2 thorpej
417 1.3.2.2 thorpej s = splbio();
418 1.3.2.2 thorpej
419 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_RESET_SCSI_BUS;
420 1.3.2.2 thorpej delay(100);
421 1.3.2.2 thorpej
422 1.3.2.2 thorpej /* Skip interrupt generated by RESET_SCSI_BUS */
423 1.3.2.2 thorpej while(*rp->sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
424 1.3.2.2 thorpej dev->sc_status = *rp->sfas_status;
425 1.3.2.2 thorpej dev->sc_interrupt = *rp->sfas_interrupt;
426 1.3.2.2 thorpej
427 1.3.2.2 thorpej delay(100);
428 1.3.2.2 thorpej }
429 1.3.2.2 thorpej
430 1.3.2.2 thorpej dev->sc_status = *rp->sfas_status;
431 1.3.2.2 thorpej dev->sc_interrupt = *rp->sfas_interrupt;
432 1.3.2.2 thorpej
433 1.3.2.2 thorpej splx(s);
434 1.3.2.2 thorpej }
435 1.3.2.2 thorpej
436 1.3.2.2 thorpej if (dev->sc_config_flags & SFAS_SLOW_START)
437 1.3.2.2 thorpej delay(4*250000); /* RESET to SELECT DELAY*4 for slow devices */
438 1.3.2.2 thorpej else
439 1.3.2.2 thorpej delay(250000); /* RESET to SELECT DELAY */
440 1.3.2.2 thorpej }
441 1.3.2.2 thorpej
442 1.3.2.2 thorpej /*
443 1.3.2.2 thorpej * Save active data pointers to the nexus block currently active.
444 1.3.2.2 thorpej */
445 1.3.2.2 thorpej void
446 1.3.2.2 thorpej sfas_save_pointers(dev)
447 1.3.2.2 thorpej struct sfas_softc *dev;
448 1.3.2.2 thorpej {
449 1.3.2.2 thorpej struct nexus *nx;
450 1.3.2.2 thorpej
451 1.3.2.2 thorpej nx = dev->sc_cur_nexus;
452 1.3.2.2 thorpej if (nx) {
453 1.3.2.2 thorpej nx->cur_link = dev->sc_cur_link;
454 1.3.2.2 thorpej nx->max_link = dev->sc_max_link;
455 1.3.2.2 thorpej nx->buf = dev->sc_buf;
456 1.3.2.2 thorpej nx->len = dev->sc_len;
457 1.3.2.2 thorpej nx->dma_len = dev->sc_dma_len;
458 1.3.2.2 thorpej nx->dma_buf = dev->sc_dma_buf;
459 1.3.2.2 thorpej nx->dma_blk_flg = dev->sc_dma_blk_flg;
460 1.3.2.2 thorpej nx->dma_blk_len = dev->sc_dma_blk_len;
461 1.3.2.2 thorpej nx->dma_blk_ptr = dev->sc_dma_blk_ptr;
462 1.3.2.2 thorpej }
463 1.3.2.2 thorpej }
464 1.3.2.2 thorpej
465 1.3.2.2 thorpej /*
466 1.3.2.2 thorpej * Restore data pointers from the currently active nexus block.
467 1.3.2.2 thorpej */
468 1.3.2.2 thorpej void
469 1.3.2.2 thorpej sfas_restore_pointers(dev)
470 1.3.2.2 thorpej struct sfas_softc *dev;
471 1.3.2.2 thorpej {
472 1.3.2.2 thorpej struct nexus *nx;
473 1.3.2.2 thorpej
474 1.3.2.2 thorpej nx = dev->sc_cur_nexus;
475 1.3.2.2 thorpej if (nx) {
476 1.3.2.2 thorpej dev->sc_cur_link = nx->cur_link;
477 1.3.2.2 thorpej dev->sc_max_link = nx->max_link;
478 1.3.2.2 thorpej dev->sc_buf = nx->buf;
479 1.3.2.2 thorpej dev->sc_len = nx->len;
480 1.3.2.2 thorpej dev->sc_dma_len = nx->dma_len;
481 1.3.2.2 thorpej dev->sc_dma_buf = nx->dma_buf;
482 1.3.2.2 thorpej dev->sc_dma_blk_flg = nx->dma_blk_flg;
483 1.3.2.2 thorpej dev->sc_dma_blk_len = nx->dma_blk_len;
484 1.3.2.2 thorpej dev->sc_dma_blk_ptr = nx->dma_blk_ptr;
485 1.3.2.2 thorpej dev->sc_chain = nx->dma;
486 1.3.2.2 thorpej dev->sc_unit = (nx->lun_unit & 0x0F);
487 1.3.2.2 thorpej dev->sc_lun = (nx->lun_unit & 0xF0) >> 4;
488 1.3.2.2 thorpej }
489 1.3.2.2 thorpej }
490 1.3.2.2 thorpej
491 1.3.2.2 thorpej /*
492 1.3.2.2 thorpej * sfasiwait is used during interrupt and polled IO to wait for an event from
493 1.3.2.2 thorpej * the FAS chip. This function MUST NOT BE CALLED without interrupt disabled.
494 1.3.2.2 thorpej */
495 1.3.2.2 thorpej void
496 1.3.2.2 thorpej sfasiwait(dev)
497 1.3.2.2 thorpej struct sfas_softc *dev;
498 1.3.2.2 thorpej {
499 1.3.2.2 thorpej sfas_regmap_p rp;
500 1.3.2.2 thorpej
501 1.3.2.2 thorpej /*
502 1.3.2.2 thorpej * If SFAS_DONT_WAIT is set, we have already grabbed the interrupt info
503 1.3.2.2 thorpej * elsewhere. So we don't have to wait for it.
504 1.3.2.2 thorpej */
505 1.3.2.2 thorpej if (dev->sc_flags & SFAS_DONT_WAIT) {
506 1.3.2.2 thorpej dev->sc_flags &= ~SFAS_DONT_WAIT;
507 1.3.2.2 thorpej return;
508 1.3.2.2 thorpej }
509 1.3.2.2 thorpej
510 1.3.2.2 thorpej rp = dev->sc_fas;
511 1.3.2.2 thorpej
512 1.3.2.2 thorpej /* Wait for FAS chip to signal an interrupt. */
513 1.3.2.2 thorpej while(!(*rp->sfas_status & SFAS_STAT_INTERRUPT_PENDING))
514 1.3.2.2 thorpej delay(1);
515 1.3.2.2 thorpej
516 1.3.2.2 thorpej /* Grab interrupt info from chip. */
517 1.3.2.2 thorpej dev->sc_status = *rp->sfas_status;
518 1.3.2.2 thorpej dev->sc_interrupt = *rp->sfas_interrupt;
519 1.3.2.2 thorpej if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
520 1.3.2.2 thorpej dev->sc_resel[0] = *rp->sfas_fifo;
521 1.3.2.2 thorpej dev->sc_resel[1] = *rp->sfas_fifo;
522 1.3.2.2 thorpej }
523 1.3.2.2 thorpej }
524 1.3.2.2 thorpej
525 1.3.2.2 thorpej /*
526 1.3.2.2 thorpej * Transfer info to/from device. sfas_ixfer uses polled IO+sfasiwait so the
527 1.3.2.2 thorpej * rules that apply to sfasiwait also applies here.
528 1.3.2.2 thorpej */
529 1.3.2.2 thorpej void
530 1.3.2.2 thorpej sfas_ixfer(dev, polling)
531 1.3.2.2 thorpej struct sfas_softc *dev;
532 1.3.2.2 thorpej int polling;
533 1.3.2.2 thorpej {
534 1.3.2.2 thorpej sfas_regmap_p rp;
535 1.3.2.2 thorpej u_char *buf;
536 1.3.2.2 thorpej int len, mode, phase;
537 1.3.2.2 thorpej
538 1.3.2.2 thorpej rp = dev->sc_fas;
539 1.3.2.2 thorpej buf = dev->sc_buf;
540 1.3.2.2 thorpej len = dev->sc_len;
541 1.3.2.2 thorpej
542 1.3.2.2 thorpej /*
543 1.3.2.2 thorpej * Decode the scsi phase to determine whether we are reading or writing.
544 1.3.2.2 thorpej * mode == 1 => READ, mode == 0 => WRITE
545 1.3.2.2 thorpej */
546 1.3.2.2 thorpej phase = dev->sc_status & SFAS_STAT_PHASE_MASK;
547 1.3.2.2 thorpej mode = (phase == SFAS_PHASE_DATA_IN);
548 1.3.2.2 thorpej
549 1.3.2.2 thorpej while(len && ((dev->sc_status & SFAS_STAT_PHASE_MASK) == phase))
550 1.3.2.2 thorpej if (mode) {
551 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_TRANSFER_INFO;
552 1.3.2.2 thorpej
553 1.3.2.2 thorpej sfasiwait(dev);
554 1.3.2.2 thorpej
555 1.3.2.2 thorpej *buf++ = *rp->sfas_fifo;
556 1.3.2.2 thorpej len--;
557 1.3.2.2 thorpej } else {
558 1.3.2.2 thorpej len--;
559 1.3.2.2 thorpej *rp->sfas_fifo = *buf++;
560 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_TRANSFER_INFO;
561 1.3.2.2 thorpej
562 1.3.2.2 thorpej sfasiwait(dev);
563 1.3.2.2 thorpej }
564 1.3.2.2 thorpej
565 1.3.2.2 thorpej /* Update buffer pointers to reflect the sent/received data. */
566 1.3.2.2 thorpej dev->sc_buf = buf;
567 1.3.2.2 thorpej dev->sc_len = len;
568 1.3.2.2 thorpej
569 1.3.2.2 thorpej /*
570 1.3.2.2 thorpej * Since the last sfasiwait will be a phase-change, we can't wait for it
571 1.3.2.2 thorpej * again later, so we have to signal that.
572 1.3.2.2 thorpej * Since this may be called from an interrupt initiated routine then we
573 1.3.2.2 thorpej * must call sfasintr again to avoid losing an interrupt. Phew!
574 1.3.2.2 thorpej */
575 1.3.2.2 thorpej if(polling)
576 1.3.2.2 thorpej dev->sc_flags |= SFAS_DONT_WAIT;
577 1.3.2.2 thorpej else
578 1.3.2.2 thorpej sfasintr(dev);
579 1.3.2.2 thorpej }
580 1.3.2.2 thorpej
581 1.3.2.2 thorpej /*
582 1.3.2.2 thorpej * Build a Synchronous Data Transfer Request message
583 1.3.2.2 thorpej */
584 1.3.2.2 thorpej void
585 1.3.2.2 thorpej sfas_build_sdtrm(dev, period, offset)
586 1.3.2.2 thorpej struct sfas_softc *dev;
587 1.3.2.2 thorpej int period;
588 1.3.2.2 thorpej int offset;
589 1.3.2.2 thorpej {
590 1.3.2.2 thorpej dev->sc_msg_out[0] = 0x01;
591 1.3.2.2 thorpej dev->sc_msg_out[1] = 0x03;
592 1.3.2.2 thorpej dev->sc_msg_out[2] = 0x01;
593 1.3.2.2 thorpej dev->sc_msg_out[3] = period/4;
594 1.3.2.2 thorpej dev->sc_msg_out[4] = offset;
595 1.3.2.2 thorpej dev->sc_msg_out_len= 5;
596 1.3.2.2 thorpej }
597 1.3.2.2 thorpej
598 1.3.2.2 thorpej /*
599 1.3.2.2 thorpej * Arbitate the scsi bus and select the unit
600 1.3.2.2 thorpej */
601 1.3.2.2 thorpej int
602 1.3.2.2 thorpej sfas_select_unit(dev, target)
603 1.3.2.2 thorpej struct sfas_softc *dev;
604 1.3.2.2 thorpej short target;
605 1.3.2.2 thorpej {
606 1.3.2.2 thorpej sfas_regmap_p rp;
607 1.3.2.2 thorpej struct nexus *nexus;
608 1.3.2.2 thorpej int s, retcode, i;
609 1.3.2.2 thorpej u_char cmd;
610 1.3.2.2 thorpej
611 1.3.2.2 thorpej s = splbio(); /* Do this at splbio so that we won't be disturbed. */
612 1.3.2.2 thorpej
613 1.3.2.2 thorpej retcode = 0;
614 1.3.2.2 thorpej
615 1.3.2.2 thorpej nexus = &dev->sc_nexus[target];
616 1.3.2.2 thorpej
617 1.3.2.2 thorpej /*
618 1.3.2.2 thorpej * Check if the chip is busy. If not the we mark it as so and hope that nobody
619 1.3.2.2 thorpej * reselects us until we have grabbed the bus.
620 1.3.2.2 thorpej */
621 1.3.2.2 thorpej if (!(dev->sc_flags & SFAS_ACTIVE) && !dev->sc_sel_nexus) {
622 1.3.2.2 thorpej dev->sc_flags |= SFAS_ACTIVE;
623 1.3.2.2 thorpej
624 1.3.2.2 thorpej rp = dev->sc_fas;
625 1.3.2.2 thorpej
626 1.3.2.2 thorpej *rp->sfas_syncper = nexus->syncper;
627 1.3.2.2 thorpej *rp->sfas_syncoff = nexus->syncoff;
628 1.3.2.2 thorpej *rp->sfas_config3 = nexus->config3;
629 1.3.2.2 thorpej
630 1.3.2.2 thorpej *rp->sfas_config1 = dev->sc_config1;
631 1.3.2.2 thorpej *rp->sfas_timeout = dev->sc_timeout_val;
632 1.3.2.2 thorpej *rp->sfas_dest_id = target;
633 1.3.2.2 thorpej
634 1.3.2.2 thorpej /* If nobody has stolen the bus, we can send a select command to the chip. */
635 1.3.2.2 thorpej if (!(*rp->sfas_status & SFAS_STAT_INTERRUPT_PENDING)) {
636 1.3.2.2 thorpej *rp->sfas_fifo = nexus->ID;
637 1.3.2.2 thorpej if ((nexus->flags & (SFAS_NF_DO_SDTR | SFAS_NF_RESET))
638 1.3.2.2 thorpej || (dev->sc_msg_out_len != 0))
639 1.3.2.2 thorpej cmd = SFAS_CMD_SEL_ATN_STOP;
640 1.3.2.2 thorpej else {
641 1.3.2.2 thorpej for(i=0; i<nexus->clen; i++)
642 1.3.2.2 thorpej *rp->sfas_fifo = nexus->cbuf[i];
643 1.3.2.2 thorpej
644 1.3.2.2 thorpej cmd = SFAS_CMD_SEL_ATN;
645 1.3.2.2 thorpej }
646 1.3.2.2 thorpej
647 1.3.2.2 thorpej dev->sc_sel_nexus = nexus;
648 1.3.2.2 thorpej
649 1.3.2.2 thorpej *rp->sfas_command = cmd;
650 1.3.2.2 thorpej retcode = 1;
651 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_RETRY_SELECT;
652 1.3.2.2 thorpej } else
653 1.3.2.2 thorpej nexus->flags |= SFAS_NF_RETRY_SELECT;
654 1.3.2.2 thorpej } else
655 1.3.2.2 thorpej nexus->flags |= SFAS_NF_RETRY_SELECT;
656 1.3.2.2 thorpej
657 1.3.2.2 thorpej splx(s);
658 1.3.2.2 thorpej return(retcode);
659 1.3.2.2 thorpej }
660 1.3.2.2 thorpej
661 1.3.2.2 thorpej /*
662 1.3.2.2 thorpej * Grab the nexus if available else return 0.
663 1.3.2.2 thorpej */
664 1.3.2.2 thorpej struct nexus *
665 1.3.2.2 thorpej sfas_arbitate_target(dev, target)
666 1.3.2.2 thorpej struct sfas_softc *dev;
667 1.3.2.2 thorpej int target;
668 1.3.2.2 thorpej {
669 1.3.2.2 thorpej struct nexus *nexus;
670 1.3.2.2 thorpej int s;
671 1.3.2.2 thorpej
672 1.3.2.2 thorpej /*
673 1.3.2.2 thorpej * This is realy simple. Raise interrupt level to splbio. Grab the nexus and
674 1.3.2.2 thorpej * leave.
675 1.3.2.2 thorpej */
676 1.3.2.2 thorpej nexus = &dev->sc_nexus[target];
677 1.3.2.2 thorpej
678 1.3.2.2 thorpej s = splbio();
679 1.3.2.2 thorpej
680 1.3.2.2 thorpej if (nexus->flags & SFAS_NF_UNIT_BUSY)
681 1.3.2.2 thorpej nexus = 0;
682 1.3.2.2 thorpej else
683 1.3.2.2 thorpej nexus->flags |= SFAS_NF_UNIT_BUSY;
684 1.3.2.2 thorpej
685 1.3.2.2 thorpej splx(s);
686 1.3.2.2 thorpej return(nexus);
687 1.3.2.2 thorpej }
688 1.3.2.2 thorpej
689 1.3.2.2 thorpej /*
690 1.3.2.2 thorpej * Setup a nexus for use. Initializes command, buffer pointers and dma chain.
691 1.3.2.2 thorpej */
692 1.3.2.2 thorpej void
693 1.3.2.2 thorpej sfas_setup_nexus(dev, nexus, pendp, cbuf, clen, buf, len, mode)
694 1.3.2.2 thorpej struct sfas_softc *dev;
695 1.3.2.2 thorpej struct nexus *nexus;
696 1.3.2.2 thorpej struct sfas_pending *pendp;
697 1.3.2.2 thorpej unsigned char *cbuf;
698 1.3.2.2 thorpej int clen;
699 1.3.2.2 thorpej unsigned char *buf;
700 1.3.2.2 thorpej int len;
701 1.3.2.2 thorpej int mode;
702 1.3.2.2 thorpej {
703 1.3.2.2 thorpej char sync, target, lun;
704 1.3.2.2 thorpej
705 1.3.2.2 thorpej target = pendp->xs->xs_periph->periph_target;
706 1.3.2.2 thorpej lun = pendp->xs->xs_periph->periph_lun;
707 1.3.2.2 thorpej
708 1.3.2.2 thorpej /*
709 1.3.2.2 thorpej * Adopt mode to reflect the config flags.
710 1.3.2.2 thorpej * If we can't use DMA we can't use synch transfer. Also check the
711 1.3.2.2 thorpej * sfas_inhibit_xxx[target] flags.
712 1.3.2.2 thorpej */
713 1.3.2.2 thorpej if ((dev->sc_config_flags & (SFAS_NO_SYNCH | SFAS_NO_DMA)) ||
714 1.3.2.2 thorpej sfas_inhibit_sync[(int)target])
715 1.3.2.2 thorpej mode &= ~SFAS_SELECT_S;
716 1.3.2.2 thorpej
717 1.3.2.2 thorpej if ((dev->sc_config_flags & SFAS_NO_RESELECT) ||
718 1.3.2.2 thorpej sfas_inhibit_disc[(int)target])
719 1.3.2.2 thorpej mode &= ~SFAS_SELECT_R;
720 1.3.2.2 thorpej
721 1.3.2.2 thorpej nexus->xs = pendp->xs;
722 1.3.2.2 thorpej
723 1.3.2.2 thorpej /* Setup the nexus struct. */
724 1.3.2.2 thorpej nexus->ID = ((mode & SFAS_SELECT_R) ? 0xC0 : 0x80) | lun;
725 1.3.2.2 thorpej nexus->clen = clen;
726 1.3.2.2 thorpej bcopy(cbuf, nexus->cbuf, nexus->clen);
727 1.3.2.2 thorpej nexus->cbuf[1] |= lun << 5; /* Fix the lun bits */
728 1.3.2.2 thorpej nexus->cur_link = 0;
729 1.3.2.2 thorpej nexus->dma_len = 0;
730 1.3.2.2 thorpej nexus->dma_buf = 0;
731 1.3.2.2 thorpej nexus->dma_blk_len = 0;
732 1.3.2.2 thorpej nexus->dma_blk_ptr = 0;
733 1.3.2.2 thorpej nexus->len = len;
734 1.3.2.2 thorpej nexus->buf = buf;
735 1.3.2.2 thorpej nexus->lun_unit = (lun << 4) | target;
736 1.3.2.2 thorpej nexus->state = SFAS_NS_SELECTED;
737 1.3.2.2 thorpej
738 1.3.2.2 thorpej /* We must keep these flags. All else must be zero. */
739 1.3.2.2 thorpej nexus->flags &= SFAS_NF_UNIT_BUSY
740 1.3.2.2 thorpej | SFAS_NF_SYNC_TESTED | SFAS_NF_SELECT_ME;
741 1.3.2.2 thorpej
742 1.3.2.2 thorpej if (mode & SFAS_SELECT_I)
743 1.3.2.2 thorpej nexus->flags |= SFAS_NF_IMMEDIATE;
744 1.3.2.2 thorpej if (mode & SFAS_SELECT_K)
745 1.3.2.2 thorpej nexus->flags |= SFAS_NF_RESET;
746 1.3.2.2 thorpej
747 1.3.2.2 thorpej sync = ((mode & SFAS_SELECT_S) ? 1 : 0);
748 1.3.2.2 thorpej
749 1.3.2.2 thorpej /* We can't use sync during polled IO. */
750 1.3.2.2 thorpej if (sync && (mode & SFAS_SELECT_I))
751 1.3.2.2 thorpej sync = 0;
752 1.3.2.2 thorpej
753 1.3.2.2 thorpej if (!sync &&
754 1.3.2.2 thorpej ((nexus->flags & SFAS_NF_SYNC_TESTED) && (nexus->offset != 0))) {
755 1.3.2.2 thorpej /*
756 1.3.2.2 thorpej * If the scsi unit is set to synch transfer and we don't want
757 1.3.2.2 thorpej * that, we have to renegotiate.
758 1.3.2.2 thorpej */
759 1.3.2.2 thorpej
760 1.3.2.2 thorpej nexus->flags |= SFAS_NF_DO_SDTR;
761 1.3.2.2 thorpej nexus->period = 200;
762 1.3.2.2 thorpej nexus->offset = 0;
763 1.3.2.2 thorpej } else if (sync && !(nexus->flags & SFAS_NF_SYNC_TESTED)) {
764 1.3.2.2 thorpej /*
765 1.3.2.2 thorpej * If the scsi unit is not set to synch transfer and we want
766 1.3.2.2 thorpej * that, we have to negotiate. This should realy base the
767 1.3.2.2 thorpej * period on the clock frequence rather than just check if
768 1.3.2.2 thorpej * >25Mhz
769 1.3.2.2 thorpej */
770 1.3.2.2 thorpej
771 1.3.2.2 thorpej nexus->flags |= SFAS_NF_DO_SDTR;
772 1.3.2.2 thorpej nexus->period = ((dev->sc_clock_freq>25) ? 100 : 200);
773 1.3.2.2 thorpej nexus->offset = 8;
774 1.3.2.2 thorpej
775 1.3.2.2 thorpej /* If the user has a long cable, we want to limit the period */
776 1.3.2.2 thorpej if ((nexus->period == 100) &&
777 1.3.2.2 thorpej (dev->sc_config_flags & SFAS_SLOW_CABLE))
778 1.3.2.2 thorpej nexus->period = 200;
779 1.3.2.2 thorpej }
780 1.3.2.2 thorpej
781 1.3.2.2 thorpej /*
782 1.3.2.2 thorpej * Fake a dma-block for polled IO. This way we can use the same code to handle
783 1.3.2.2 thorpej * reselection. Much nicer this way.
784 1.3.2.2 thorpej */
785 1.3.2.2 thorpej if ((mode & SFAS_SELECT_I) || (dev->sc_config_flags & SFAS_NO_DMA)) {
786 1.3.2.2 thorpej nexus->dma[0].ptr = (vm_offset_t)buf;
787 1.3.2.2 thorpej nexus->dma[0].len = len;
788 1.3.2.2 thorpej nexus->dma[0].flg = SFAS_CHAIN_PRG;
789 1.3.2.2 thorpej nexus->max_link = 1;
790 1.3.2.2 thorpej } else {
791 1.3.2.2 thorpej nexus->max_link = dev->sc_build_dma_chain(dev, nexus->dma,
792 1.3.2.2 thorpej buf, len);
793 1.3.2.2 thorpej }
794 1.3.2.2 thorpej
795 1.3.2.2 thorpej /* Flush the caches. */
796 1.3.2.2 thorpej
797 1.3.2.2 thorpej if (len && !(mode & SFAS_SELECT_I))
798 1.3.2.3 jdolecek cpu_dcache_wbinv_range((vm_offset_t)buf, len);
799 1.3.2.2 thorpej }
800 1.3.2.2 thorpej
801 1.3.2.2 thorpej int
802 1.3.2.2 thorpej sfasselect(dev, pendp, cbuf, clen, buf, len, mode)
803 1.3.2.2 thorpej struct sfas_softc *dev;
804 1.3.2.2 thorpej struct sfas_pending *pendp;
805 1.3.2.2 thorpej unsigned char *cbuf;
806 1.3.2.2 thorpej int clen;
807 1.3.2.2 thorpej unsigned char *buf;
808 1.3.2.2 thorpej int len;
809 1.3.2.2 thorpej int mode;
810 1.3.2.2 thorpej {
811 1.3.2.2 thorpej struct nexus *nexus;
812 1.3.2.2 thorpej
813 1.3.2.2 thorpej /* Get the nexus struct. */
814 1.3.2.2 thorpej nexus = sfas_arbitate_target(dev, pendp->xs->xs_periph->periph_target);
815 1.3.2.2 thorpej if (nexus == NULL)
816 1.3.2.2 thorpej return(0);
817 1.3.2.2 thorpej
818 1.3.2.2 thorpej /* Setup the nexus struct. */
819 1.3.2.2 thorpej sfas_setup_nexus(dev, nexus, pendp, cbuf, clen, buf, len, mode);
820 1.3.2.2 thorpej
821 1.3.2.2 thorpej /* Post it to the interrupt machine. */
822 1.3.2.2 thorpej sfas_select_unit(dev, pendp->xs->xs_periph->periph_target);
823 1.3.2.2 thorpej
824 1.3.2.2 thorpej return(1);
825 1.3.2.2 thorpej }
826 1.3.2.2 thorpej
827 1.3.2.2 thorpej void
828 1.3.2.2 thorpej sfasgo(dev, pendp)
829 1.3.2.2 thorpej struct sfas_softc *dev;
830 1.3.2.2 thorpej struct sfas_pending *pendp;
831 1.3.2.2 thorpej {
832 1.3.2.2 thorpej int s;
833 1.3.2.2 thorpej char *buf;
834 1.3.2.2 thorpej
835 1.3.2.2 thorpej buf = pendp->xs->data;
836 1.3.2.2 thorpej
837 1.3.2.2 thorpej if (sfasselect(dev, pendp, (char *)pendp->xs->cmd, pendp->xs->cmdlen,
838 1.3.2.2 thorpej buf, pendp->xs->datalen, SFAS_SELECT_RS)) {
839 1.3.2.2 thorpej /*
840 1.3.2.2 thorpej * We got the command going so the sfas_pending struct is now
841 1.3.2.2 thorpej * free to reuse.
842 1.3.2.2 thorpej */
843 1.3.2.2 thorpej
844 1.3.2.2 thorpej s = splbio();
845 1.3.2.2 thorpej TAILQ_INSERT_TAIL(&dev->sc_xs_free, pendp, link);
846 1.3.2.2 thorpej splx(s);
847 1.3.2.2 thorpej } else {
848 1.3.2.2 thorpej /*
849 1.3.2.2 thorpej * We couldn't make the command fly so we have to wait. The
850 1.3.2.2 thorpej * struct MUST be inserted at the head to keep the order of
851 1.3.2.2 thorpej * the commands.
852 1.3.2.2 thorpej */
853 1.3.2.2 thorpej
854 1.3.2.2 thorpej s = splbio();
855 1.3.2.2 thorpej TAILQ_INSERT_HEAD(&dev->sc_xs_pending, pendp, link);
856 1.3.2.2 thorpej splx(s);
857 1.3.2.2 thorpej }
858 1.3.2.2 thorpej
859 1.3.2.2 thorpej return;
860 1.3.2.2 thorpej }
861 1.3.2.2 thorpej
862 1.3.2.2 thorpej /*
863 1.3.2.2 thorpej * Part one of the interrupt machine. Error checks and reselection test.
864 1.3.2.2 thorpej * We don't know if we have an active nexus here!
865 1.3.2.2 thorpej */
866 1.3.2.2 thorpej int
867 1.3.2.2 thorpej sfas_pretests(dev, rp)
868 1.3.2.2 thorpej struct sfas_softc *dev;
869 1.3.2.2 thorpej sfas_regmap_p rp;
870 1.3.2.2 thorpej {
871 1.3.2.2 thorpej struct nexus *nexus;
872 1.3.2.2 thorpej int i, s;
873 1.3.2.2 thorpej
874 1.3.2.2 thorpej if (dev->sc_interrupt & SFAS_INT_SCSI_RESET_DETECTED) {
875 1.3.2.2 thorpej /*
876 1.3.2.2 thorpej * Cleanup and notify user. Lets hope that this is all we
877 1.3.2.2 thorpej * have to do
878 1.3.2.2 thorpej */
879 1.3.2.2 thorpej
880 1.3.2.2 thorpej for(i=0; i<8; i++) {
881 1.3.2.2 thorpej if (dev->sc_nexus[i].xs)
882 1.3.2.2 thorpej sfas_scsidone(dev, dev->sc_nexus[i].xs, -2);
883 1.3.2.2 thorpej
884 1.3.2.2 thorpej sfas_init_nexus(dev, &dev->sc_nexus[i]);
885 1.3.2.2 thorpej }
886 1.3.2.2 thorpej printf("sfasintr: SCSI-RESET detected!");
887 1.3.2.2 thorpej return(-1);
888 1.3.2.2 thorpej }
889 1.3.2.2 thorpej
890 1.3.2.2 thorpej if (dev->sc_interrupt & SFAS_INT_ILLEGAL_COMMAND) {
891 1.3.2.2 thorpej /* Something went terrible wrong! Dump some data and panic! */
892 1.3.2.2 thorpej
893 1.3.2.2 thorpej printf("FIFO:");
894 1.3.2.2 thorpej while(*rp->sfas_fifo_flags & SFAS_FIFO_COUNT_MASK)
895 1.3.2.2 thorpej printf(" %x", *rp->sfas_fifo);
896 1.3.2.2 thorpej printf("\n");
897 1.3.2.2 thorpej
898 1.3.2.2 thorpej printf("CMD: %x\n", *rp->sfas_command);
899 1.3.2.2 thorpej panic("sfasintr: ILLEGAL COMMAND!");
900 1.3.2.2 thorpej }
901 1.3.2.2 thorpej
902 1.3.2.2 thorpej if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
903 1.3.2.2 thorpej /* We were reselected. Set the chip as busy */
904 1.3.2.2 thorpej
905 1.3.2.2 thorpej s = splbio();
906 1.3.2.2 thorpej dev->sc_flags |= SFAS_ACTIVE;
907 1.3.2.2 thorpej if (dev->sc_sel_nexus) {
908 1.3.2.2 thorpej dev->sc_sel_nexus->flags |= SFAS_NF_SELECT_ME;
909 1.3.2.2 thorpej dev->sc_sel_nexus = 0;
910 1.3.2.2 thorpej }
911 1.3.2.2 thorpej splx(s);
912 1.3.2.2 thorpej
913 1.3.2.2 thorpej if (dev->sc_units_disconnected) {
914 1.3.2.2 thorpej /* Find out who reselected us. */
915 1.3.2.2 thorpej
916 1.3.2.2 thorpej dev->sc_resel[0] &= ~(1<<dev->sc_host_id);
917 1.3.2.2 thorpej
918 1.3.2.2 thorpej for(i=0; i<8; i++)
919 1.3.2.2 thorpej if (dev->sc_resel[0] & (1<<i))
920 1.3.2.2 thorpej break;
921 1.3.2.2 thorpej
922 1.3.2.2 thorpej if (i == 8)
923 1.3.2.2 thorpej panic("Illegal reselection!");
924 1.3.2.2 thorpej
925 1.3.2.2 thorpej if (dev->sc_nexus[i].state == SFAS_NS_DISCONNECTED) {
926 1.3.2.2 thorpej /*
927 1.3.2.2 thorpej * This unit had disconnected, so we reconnect
928 1.3.2.2 thorpej * it.
929 1.3.2.2 thorpej */
930 1.3.2.2 thorpej
931 1.3.2.2 thorpej dev->sc_cur_nexus = &dev->sc_nexus[i];
932 1.3.2.2 thorpej nexus = dev->sc_cur_nexus;
933 1.3.2.2 thorpej
934 1.3.2.2 thorpej *rp->sfas_syncper = nexus->syncper;
935 1.3.2.2 thorpej *rp->sfas_syncoff = nexus->syncoff;
936 1.3.2.2 thorpej *rp->sfas_config3 = nexus->config3;
937 1.3.2.2 thorpej
938 1.3.2.2 thorpej *rp->sfas_dest_id = i & 7;
939 1.3.2.2 thorpej
940 1.3.2.2 thorpej dev->sc_units_disconnected--;
941 1.3.2.2 thorpej dev->sc_msg_in_len= 0;
942 1.3.2.2 thorpej
943 1.3.2.2 thorpej /* Restore active pointers. */
944 1.3.2.2 thorpej sfas_restore_pointers(dev);
945 1.3.2.2 thorpej
946 1.3.2.2 thorpej nexus->state = SFAS_NS_RESELECTED;
947 1.3.2.2 thorpej
948 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_MESSAGE_ACCEPTED;
949 1.3.2.2 thorpej
950 1.3.2.2 thorpej return(1);
951 1.3.2.2 thorpej }
952 1.3.2.2 thorpej }
953 1.3.2.2 thorpej
954 1.3.2.2 thorpej /* Somehow we got an illegal reselection. Dump and panic. */
955 1.3.2.2 thorpej printf("sfasintr: resel[0] %x resel[1] %x disconnected %d\n",
956 1.3.2.2 thorpej dev->sc_resel[0], dev->sc_resel[1],
957 1.3.2.2 thorpej dev->sc_units_disconnected);
958 1.3.2.2 thorpej panic("sfasintr: Unexpected reselection!");
959 1.3.2.2 thorpej }
960 1.3.2.2 thorpej
961 1.3.2.2 thorpej return(0);
962 1.3.2.2 thorpej }
963 1.3.2.2 thorpej
964 1.3.2.2 thorpej /*
965 1.3.2.2 thorpej * Part two of the interrupt machine. Handle disconnection and post command
966 1.3.2.2 thorpej * processing. We know that we have an active nexus here.
967 1.3.2.2 thorpej */
968 1.3.2.2 thorpej int
969 1.3.2.2 thorpej sfas_midaction(dev, rp, nexus)
970 1.3.2.2 thorpej struct sfas_softc *dev;
971 1.3.2.2 thorpej sfas_regmap_p rp;
972 1.3.2.2 thorpej struct nexus *nexus;
973 1.3.2.2 thorpej {
974 1.3.2.2 thorpej int i, left, len, s;
975 1.3.2.2 thorpej u_char status, msg;
976 1.3.2.2 thorpej
977 1.3.2.2 thorpej if (dev->sc_interrupt & SFAS_INT_DISCONNECT) {
978 1.3.2.2 thorpej s = splbio();
979 1.3.2.2 thorpej dev->sc_cur_nexus = 0;
980 1.3.2.2 thorpej
981 1.3.2.2 thorpej /* Mark chip as busy and clean up the chip FIFO. */
982 1.3.2.2 thorpej dev->sc_flags &= ~SFAS_ACTIVE;
983 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_FLUSH_FIFO;
984 1.3.2.2 thorpej
985 1.3.2.2 thorpej /* Let the nexus state reflect what we have to do. */
986 1.3.2.2 thorpej switch(nexus->state) {
987 1.3.2.2 thorpej case SFAS_NS_SELECTED:
988 1.3.2.2 thorpej dev->sc_sel_nexus = 0;
989 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_SELECT_ME;
990 1.3.2.2 thorpej
991 1.3.2.2 thorpej /*
992 1.3.2.2 thorpej * We were trying to select the unit. Probably no unit
993 1.3.2.2 thorpej * at this ID.
994 1.3.2.2 thorpej */
995 1.3.2.2 thorpej nexus->xs->resid = dev->sc_len;
996 1.3.2.2 thorpej
997 1.3.2.2 thorpej nexus->status = -2;
998 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_UNIT_BUSY;
999 1.3.2.2 thorpej nexus->state = SFAS_NS_FINISHED;
1000 1.3.2.2 thorpej break;
1001 1.3.2.2 thorpej
1002 1.3.2.2 thorpej case SFAS_NS_DONE:
1003 1.3.2.2 thorpej /* All done. */
1004 1.3.2.2 thorpej nexus->xs->resid = dev->sc_len;
1005 1.3.2.2 thorpej
1006 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_UNIT_BUSY;
1007 1.3.2.2 thorpej nexus->state = SFAS_NS_FINISHED;
1008 1.3.2.2 thorpej dev->sc_led(dev, 0);
1009 1.3.2.2 thorpej break;
1010 1.3.2.2 thorpej
1011 1.3.2.2 thorpej case SFAS_NS_DISCONNECTING:
1012 1.3.2.2 thorpej /*
1013 1.3.2.2 thorpej * We have received a DISCONNECT message, so we are
1014 1.3.2.2 thorpej * doing a normal disconnection.
1015 1.3.2.2 thorpej */
1016 1.3.2.2 thorpej nexus->state = SFAS_NS_DISCONNECTED;
1017 1.3.2.2 thorpej
1018 1.3.2.2 thorpej dev->sc_units_disconnected++;
1019 1.3.2.2 thorpej break;
1020 1.3.2.2 thorpej
1021 1.3.2.2 thorpej case SFAS_NS_RESET:
1022 1.3.2.2 thorpej /*
1023 1.3.2.2 thorpej * We were reseting this SCSI-unit. Clean up the
1024 1.3.2.2 thorpej * nexus struct.
1025 1.3.2.2 thorpej */
1026 1.3.2.2 thorpej dev->sc_led(dev, 0);
1027 1.3.2.2 thorpej sfas_init_nexus(dev, nexus);
1028 1.3.2.2 thorpej break;
1029 1.3.2.2 thorpej
1030 1.3.2.2 thorpej default:
1031 1.3.2.2 thorpej /*
1032 1.3.2.2 thorpej * Unexpected disconnection! Cleanup and exit. This
1033 1.3.2.2 thorpej * shouldn't cause any problems.
1034 1.3.2.2 thorpej */
1035 1.3.2.2 thorpej printf("sfasintr: Unexpected disconnection\n");
1036 1.3.2.2 thorpej printf("sfasintr: u %x s %d p %d f %x c %x\n",
1037 1.3.2.2 thorpej nexus->lun_unit, nexus->state,
1038 1.3.2.2 thorpej dev->sc_status & SFAS_STAT_PHASE_MASK,
1039 1.3.2.2 thorpej nexus->flags, nexus->cbuf[0]);
1040 1.3.2.2 thorpej
1041 1.3.2.2 thorpej nexus->xs->resid = dev->sc_len;
1042 1.3.2.2 thorpej
1043 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_UNIT_BUSY;
1044 1.3.2.2 thorpej nexus->state = SFAS_NS_FINISHED;
1045 1.3.2.2 thorpej nexus->status = -3;
1046 1.3.2.2 thorpej
1047 1.3.2.2 thorpej dev->sc_led(dev, 0);
1048 1.3.2.2 thorpej break;
1049 1.3.2.2 thorpej }
1050 1.3.2.2 thorpej
1051 1.3.2.2 thorpej /*
1052 1.3.2.2 thorpej * If we have disconnected units, we MUST enable reselection
1053 1.3.2.2 thorpej * within 250ms.
1054 1.3.2.2 thorpej */
1055 1.3.2.2 thorpej if (dev->sc_units_disconnected &&
1056 1.3.2.2 thorpej !(dev->sc_flags & SFAS_ACTIVE))
1057 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_ENABLE_RESEL;
1058 1.3.2.2 thorpej
1059 1.3.2.2 thorpej splx(s);
1060 1.3.2.2 thorpej
1061 1.3.2.2 thorpej /* Select the first pre-initialized nexus we find. */
1062 1.3.2.2 thorpej for(i=0; i<8; i++)
1063 1.3.2.2 thorpej if (dev->sc_nexus[i].flags & (SFAS_NF_SELECT_ME | SFAS_NF_RETRY_SELECT))
1064 1.3.2.2 thorpej if (sfas_select_unit(dev, i) == 2)
1065 1.3.2.2 thorpej break;
1066 1.3.2.2 thorpej
1067 1.3.2.2 thorpej /* We are done with this nexus! */
1068 1.3.2.2 thorpej if (nexus->state == SFAS_NS_FINISHED)
1069 1.3.2.2 thorpej sfas_scsidone(dev, nexus->xs, nexus->status);
1070 1.3.2.2 thorpej
1071 1.3.2.2 thorpej return(1);
1072 1.3.2.2 thorpej }
1073 1.3.2.2 thorpej
1074 1.3.2.2 thorpej switch(nexus->state) {
1075 1.3.2.2 thorpej case SFAS_NS_SELECTED:
1076 1.3.2.2 thorpej dev->sc_cur_nexus = nexus;
1077 1.3.2.2 thorpej dev->sc_sel_nexus = 0;
1078 1.3.2.2 thorpej
1079 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_SELECT_ME;
1080 1.3.2.2 thorpej
1081 1.3.2.2 thorpej /*
1082 1.3.2.2 thorpej * We have selected a unit. Setup chip, restore pointers and
1083 1.3.2.2 thorpej * light the led.
1084 1.3.2.2 thorpej */
1085 1.3.2.2 thorpej *rp->sfas_syncper = nexus->syncper;
1086 1.3.2.2 thorpej *rp->sfas_syncoff = nexus->syncoff;
1087 1.3.2.2 thorpej *rp->sfas_config3 = nexus->config3;
1088 1.3.2.2 thorpej
1089 1.3.2.2 thorpej sfas_restore_pointers(dev);
1090 1.3.2.2 thorpej
1091 1.3.2.2 thorpej nexus->status = 0xFF;
1092 1.3.2.2 thorpej dev->sc_msg_in[0] = 0xFF;
1093 1.3.2.2 thorpej dev->sc_msg_in_len= 0;
1094 1.3.2.2 thorpej
1095 1.3.2.2 thorpej dev->sc_led(dev, 1);
1096 1.3.2.2 thorpej
1097 1.3.2.2 thorpej break;
1098 1.3.2.2 thorpej
1099 1.3.2.2 thorpej case SFAS_NS_DATA_IN:
1100 1.3.2.2 thorpej case SFAS_NS_DATA_OUT:
1101 1.3.2.2 thorpej /* We have transfered data. */
1102 1.3.2.2 thorpej if (dev->sc_dma_len)
1103 1.3.2.2 thorpej if (dev->sc_cur_link < dev->sc_max_link) {
1104 1.3.2.2 thorpej /*
1105 1.3.2.2 thorpej * Clean up dma and at the same time get how
1106 1.3.2.2 thorpej * many bytes that were NOT transfered.
1107 1.3.2.2 thorpej */
1108 1.3.2.2 thorpej left = dev->sc_setup_dma(dev, 0, 0, SFAS_DMA_CLEAR);
1109 1.3.2.2 thorpej len = dev->sc_dma_len;
1110 1.3.2.2 thorpej
1111 1.3.2.2 thorpej if (nexus->state == SFAS_NS_DATA_IN) {
1112 1.3.2.2 thorpej /*
1113 1.3.2.2 thorpej * If we were bumping we may have had an odd length
1114 1.3.2.2 thorpej * which means that there may be bytes left in the
1115 1.3.2.2 thorpej * fifo. We also need to move the data from the
1116 1.3.2.2 thorpej * bump buffer to the actual memory.
1117 1.3.2.2 thorpej */
1118 1.3.2.2 thorpej if (dev->sc_dma_buf == dev->sc_bump_pa)
1119 1.3.2.2 thorpej {
1120 1.3.2.2 thorpej while((*rp->sfas_fifo_flags&SFAS_FIFO_COUNT_MASK)
1121 1.3.2.2 thorpej && left)
1122 1.3.2.2 thorpej dev->sc_bump_va[len-(left--)] = *rp->sfas_fifo;
1123 1.3.2.2 thorpej
1124 1.3.2.2 thorpej bcopy(dev->sc_bump_va, dev->sc_buf, len-left);
1125 1.3.2.2 thorpej }
1126 1.3.2.2 thorpej } else {
1127 1.3.2.2 thorpej /* Count any unsent bytes and flush them. */
1128 1.3.2.2 thorpej left+= *rp->sfas_fifo_flags & SFAS_FIFO_COUNT_MASK;
1129 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_FLUSH_FIFO;
1130 1.3.2.2 thorpej }
1131 1.3.2.2 thorpej
1132 1.3.2.2 thorpej /*
1133 1.3.2.2 thorpej * Update pointers/length to reflect the transfered
1134 1.3.2.2 thorpej * data.
1135 1.3.2.2 thorpej */
1136 1.3.2.2 thorpej dev->sc_len -= len-left;
1137 1.3.2.2 thorpej dev->sc_buf += len-left;
1138 1.3.2.2 thorpej
1139 1.3.2.2 thorpej dev->sc_dma_buf += len-left;
1140 1.3.2.2 thorpej dev->sc_dma_len = left;
1141 1.3.2.2 thorpej
1142 1.3.2.2 thorpej dev->sc_dma_blk_ptr += len-left;
1143 1.3.2.2 thorpej dev->sc_dma_blk_len -= len-left;
1144 1.3.2.2 thorpej
1145 1.3.2.2 thorpej /*
1146 1.3.2.2 thorpej * If it was the end of a dma block, we select the
1147 1.3.2.2 thorpej * next to begin with.
1148 1.3.2.2 thorpej */
1149 1.3.2.2 thorpej if (!dev->sc_dma_blk_len)
1150 1.3.2.2 thorpej dev->sc_cur_link++;
1151 1.3.2.2 thorpej }
1152 1.3.2.2 thorpej break;
1153 1.3.2.2 thorpej
1154 1.3.2.2 thorpej case SFAS_NS_STATUS:
1155 1.3.2.2 thorpej /*
1156 1.3.2.2 thorpej * If we were not sensing, grab the status byte. If we were
1157 1.3.2.2 thorpej * sensing and we got a bad status, let the user know.
1158 1.3.2.2 thorpej */
1159 1.3.2.2 thorpej
1160 1.3.2.2 thorpej status = *rp->sfas_fifo;
1161 1.3.2.2 thorpej msg = *rp->sfas_fifo;
1162 1.3.2.2 thorpej
1163 1.3.2.2 thorpej nexus->status = status;
1164 1.3.2.2 thorpej if (status != 0)
1165 1.3.2.2 thorpej nexus->status = -1;
1166 1.3.2.2 thorpej
1167 1.3.2.2 thorpej /*
1168 1.3.2.2 thorpej * Preload the command complete message. Handeled in
1169 1.3.2.2 thorpej * sfas_postaction.
1170 1.3.2.2 thorpej */
1171 1.3.2.2 thorpej dev->sc_msg_in[0] = msg;
1172 1.3.2.2 thorpej dev->sc_msg_in_len = 1;
1173 1.3.2.2 thorpej nexus->flags |= SFAS_NF_HAS_MSG;
1174 1.3.2.2 thorpej break;
1175 1.3.2.2 thorpej
1176 1.3.2.2 thorpej default:
1177 1.3.2.2 thorpej break;
1178 1.3.2.2 thorpej }
1179 1.3.2.2 thorpej
1180 1.3.2.2 thorpej return(0);
1181 1.3.2.2 thorpej }
1182 1.3.2.2 thorpej
1183 1.3.2.2 thorpej /*
1184 1.3.2.2 thorpej * Part three of the interrupt machine. Handle phase changes (and repeated
1185 1.3.2.2 thorpej * phase passes). We know that we have an active nexus here.
1186 1.3.2.2 thorpej */
1187 1.3.2.2 thorpej int
1188 1.3.2.2 thorpej sfas_postaction(dev, rp, nexus)
1189 1.3.2.2 thorpej struct sfas_softc *dev;
1190 1.3.2.2 thorpej sfas_regmap_p rp;
1191 1.3.2.2 thorpej struct nexus *nexus;
1192 1.3.2.2 thorpej {
1193 1.3.2.2 thorpej int i, len;
1194 1.3.2.2 thorpej u_char cmd;
1195 1.3.2.2 thorpej short offset, period;
1196 1.3.2.2 thorpej
1197 1.3.2.2 thorpej cmd = 0;
1198 1.3.2.2 thorpej
1199 1.3.2.2 thorpej switch(dev->sc_status & SFAS_STAT_PHASE_MASK) {
1200 1.3.2.2 thorpej case SFAS_PHASE_DATA_OUT:
1201 1.3.2.2 thorpej case SFAS_PHASE_DATA_IN:
1202 1.3.2.2 thorpej if ((dev->sc_status & SFAS_STAT_PHASE_MASK) ==
1203 1.3.2.2 thorpej SFAS_PHASE_DATA_OUT)
1204 1.3.2.2 thorpej nexus->state = SFAS_NS_DATA_OUT;
1205 1.3.2.2 thorpej else
1206 1.3.2.2 thorpej nexus->state = SFAS_NS_DATA_IN;
1207 1.3.2.2 thorpej
1208 1.3.2.2 thorpej /* Make DMA ready to accept new data. Load active pointers
1209 1.3.2.2 thorpej * from the DMA block. */
1210 1.3.2.2 thorpej dev->sc_setup_dma(dev, 0, 0, SFAS_DMA_CLEAR);
1211 1.3.2.2 thorpej if (dev->sc_cur_link < dev->sc_max_link) {
1212 1.3.2.2 thorpej if (!dev->sc_dma_blk_len) {
1213 1.3.2.2 thorpej dev->sc_dma_blk_ptr = dev->sc_chain[dev->sc_cur_link].ptr;
1214 1.3.2.2 thorpej dev->sc_dma_blk_len = dev->sc_chain[dev->sc_cur_link].len;
1215 1.3.2.2 thorpej dev->sc_dma_blk_flg = dev->sc_chain[dev->sc_cur_link].flg;
1216 1.3.2.2 thorpej }
1217 1.3.2.2 thorpej
1218 1.3.2.2 thorpej /* We should use polled IO here. */
1219 1.3.2.2 thorpej if (dev->sc_dma_blk_flg == SFAS_CHAIN_PRG) {
1220 1.3.2.2 thorpej dev->sc_ixfer(dev, nexus->xs->xs_control & XS_CTL_POLL);
1221 1.3.2.2 thorpej dev->sc_cur_link++;
1222 1.3.2.2 thorpej dev->sc_dma_len = 0;
1223 1.3.2.2 thorpej break;
1224 1.3.2.2 thorpej }
1225 1.3.2.2 thorpej else if (dev->sc_dma_blk_flg == SFAS_CHAIN_BUMP)
1226 1.3.2.2 thorpej len = dev->sc_dma_blk_len;
1227 1.3.2.2 thorpej else
1228 1.3.2.2 thorpej len = dev->sc_need_bump(dev, dev->sc_dma_blk_ptr,
1229 1.3.2.2 thorpej dev->sc_dma_blk_len);
1230 1.3.2.2 thorpej
1231 1.3.2.2 thorpej /*
1232 1.3.2.2 thorpej * If len != 0 we must bump the data, else we just DMA it
1233 1.3.2.2 thorpej * straight into memory.
1234 1.3.2.2 thorpej */
1235 1.3.2.2 thorpej if (len) {
1236 1.3.2.2 thorpej dev->sc_dma_buf = dev->sc_bump_pa;
1237 1.3.2.2 thorpej dev->sc_dma_len = len;
1238 1.3.2.2 thorpej
1239 1.3.2.2 thorpej if (nexus->state == SFAS_NS_DATA_OUT)
1240 1.3.2.2 thorpej bcopy(dev->sc_buf, dev->sc_bump_va, dev->sc_dma_len);
1241 1.3.2.2 thorpej } else {
1242 1.3.2.2 thorpej dev->sc_dma_buf = dev->sc_dma_blk_ptr;
1243 1.3.2.2 thorpej dev->sc_dma_len = dev->sc_dma_blk_len;
1244 1.3.2.2 thorpej }
1245 1.3.2.2 thorpej
1246 1.3.2.2 thorpej /* Load DMA with adress and length of transfer. */
1247 1.3.2.2 thorpej dev->sc_setup_dma(dev, dev->sc_dma_buf, dev->sc_dma_len,
1248 1.3.2.2 thorpej ((nexus->state == SFAS_NS_DATA_OUT) ?
1249 1.3.2.2 thorpej SFAS_DMA_WRITE : SFAS_DMA_READ));
1250 1.3.2.2 thorpej
1251 1.3.2.2 thorpej /* printf("Using DMA !!!!\n");*/
1252 1.3.2.2 thorpej cmd = SFAS_CMD_TRANSFER_INFO | SFAS_CMD_DMA;
1253 1.3.2.2 thorpej } else {
1254 1.3.2.2 thorpej /*
1255 1.3.2.2 thorpej * Hmmm, the unit wants more info than we have or has
1256 1.3.2.2 thorpej * more than we want. Let the chip handle that.
1257 1.3.2.2 thorpej */
1258 1.3.2.2 thorpej
1259 1.3.2.2 thorpej *rp->sfas_tc_low = 0; /* was 256 but this does not make sense */
1260 1.3.2.2 thorpej *rp->sfas_tc_mid = 1;
1261 1.3.2.2 thorpej *rp->sfas_tc_high = 0;
1262 1.3.2.2 thorpej cmd = SFAS_CMD_TRANSFER_PAD;
1263 1.3.2.2 thorpej }
1264 1.3.2.2 thorpej break;
1265 1.3.2.2 thorpej
1266 1.3.2.2 thorpej case SFAS_PHASE_COMMAND:
1267 1.3.2.2 thorpej /* The scsi unit wants the command, send it. */
1268 1.3.2.2 thorpej nexus->state = SFAS_NS_SVC;
1269 1.3.2.2 thorpej
1270 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_FLUSH_FIFO;
1271 1.3.2.2 thorpej for(i=0; i<5; i++);
1272 1.3.2.2 thorpej
1273 1.3.2.2 thorpej for(i=0; i<nexus->clen; i++)
1274 1.3.2.2 thorpej *rp->sfas_fifo = nexus->cbuf[i];
1275 1.3.2.2 thorpej cmd = SFAS_CMD_TRANSFER_INFO;
1276 1.3.2.2 thorpej break;
1277 1.3.2.2 thorpej
1278 1.3.2.2 thorpej case SFAS_PHASE_STATUS:
1279 1.3.2.2 thorpej /*
1280 1.3.2.2 thorpej * We've got status phase. Request status and command
1281 1.3.2.2 thorpej * complete message.
1282 1.3.2.2 thorpej */
1283 1.3.2.2 thorpej nexus->state = SFAS_NS_STATUS;
1284 1.3.2.2 thorpej cmd = SFAS_CMD_COMMAND_COMPLETE;
1285 1.3.2.2 thorpej break;
1286 1.3.2.2 thorpej
1287 1.3.2.2 thorpej case SFAS_PHASE_MESSAGE_OUT:
1288 1.3.2.2 thorpej /*
1289 1.3.2.2 thorpej * Either the scsi unit wants us to send a message or we have
1290 1.3.2.2 thorpej * asked for it by seting the ATN bit.
1291 1.3.2.2 thorpej */
1292 1.3.2.2 thorpej nexus->state = SFAS_NS_MSG_OUT;
1293 1.3.2.2 thorpej
1294 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_FLUSH_FIFO;
1295 1.3.2.2 thorpej
1296 1.3.2.2 thorpej if (nexus->flags & SFAS_NF_DO_SDTR) {
1297 1.3.2.2 thorpej /* Send a Synchronous Data Transfer Request. */
1298 1.3.2.2 thorpej
1299 1.3.2.2 thorpej sfas_build_sdtrm(dev, nexus->period, nexus->offset);
1300 1.3.2.2 thorpej nexus->flags |= SFAS_NF_SDTR_SENT;
1301 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_DO_SDTR;
1302 1.3.2.2 thorpej } else if (nexus->flags & SFAS_NF_RESET) {
1303 1.3.2.2 thorpej /* Send a reset scsi unit message. */
1304 1.3.2.2 thorpej
1305 1.3.2.2 thorpej dev->sc_msg_out[0] = 0x0C;
1306 1.3.2.2 thorpej dev->sc_msg_out_len = 1;
1307 1.3.2.2 thorpej nexus->state = SFAS_NS_RESET;
1308 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_RESET;
1309 1.3.2.2 thorpej } else if (dev->sc_msg_out_len == 0) {
1310 1.3.2.2 thorpej /* Don't know what to send so we send a NOP message. */
1311 1.3.2.2 thorpej
1312 1.3.2.2 thorpej dev->sc_msg_out[0] = 0x08;
1313 1.3.2.2 thorpej dev->sc_msg_out_len = 1;
1314 1.3.2.2 thorpej }
1315 1.3.2.2 thorpej
1316 1.3.2.2 thorpej cmd = SFAS_CMD_TRANSFER_INFO;
1317 1.3.2.2 thorpej
1318 1.3.2.2 thorpej for(i=0; i<dev->sc_msg_out_len; i++)
1319 1.3.2.2 thorpej *rp->sfas_fifo = dev->sc_msg_out[i];
1320 1.3.2.2 thorpej dev->sc_msg_out_len = 0;
1321 1.3.2.2 thorpej
1322 1.3.2.2 thorpej break;
1323 1.3.2.2 thorpej
1324 1.3.2.2 thorpej case SFAS_PHASE_MESSAGE_IN:
1325 1.3.2.2 thorpej /* Receive a message from the scsi unit. */
1326 1.3.2.2 thorpej nexus->state = SFAS_NS_MSG_IN;
1327 1.3.2.2 thorpej
1328 1.3.2.2 thorpej while(!(nexus->flags & SFAS_NF_HAS_MSG)) {
1329 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_TRANSFER_INFO;
1330 1.3.2.2 thorpej sfasiwait(dev);
1331 1.3.2.2 thorpej
1332 1.3.2.2 thorpej dev->sc_msg_in[dev->sc_msg_in_len++] = *rp->sfas_fifo;
1333 1.3.2.2 thorpej
1334 1.3.2.2 thorpej /* Check if we got all the bytes in the message. */
1335 1.3.2.2 thorpej if (dev->sc_msg_in[0] >= 0x80) ;
1336 1.3.2.2 thorpej else if (dev->sc_msg_in[0] >= 0x30) ;
1337 1.3.2.2 thorpej else if (((dev->sc_msg_in[0] >= 0x20) &&
1338 1.3.2.2 thorpej (dev->sc_msg_in_len == 2)) ||
1339 1.3.2.2 thorpej ((dev->sc_msg_in[0] != 0x01) &&
1340 1.3.2.2 thorpej (dev->sc_msg_in_len == 1))) {
1341 1.3.2.2 thorpej nexus->flags |= SFAS_NF_HAS_MSG;
1342 1.3.2.2 thorpej break;
1343 1.3.2.2 thorpej } else {
1344 1.3.2.2 thorpej if (dev->sc_msg_in_len >= 2)
1345 1.3.2.2 thorpej if ((dev->sc_msg_in[1]+2) == dev->sc_msg_in_len) {
1346 1.3.2.2 thorpej nexus->flags |= SFAS_NF_HAS_MSG;
1347 1.3.2.2 thorpej break;
1348 1.3.2.2 thorpej }
1349 1.3.2.2 thorpej }
1350 1.3.2.2 thorpej
1351 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_MESSAGE_ACCEPTED;
1352 1.3.2.2 thorpej sfasiwait(dev);
1353 1.3.2.2 thorpej
1354 1.3.2.2 thorpej if ((dev->sc_status & SFAS_STAT_PHASE_MASK) !=
1355 1.3.2.2 thorpej SFAS_PHASE_MESSAGE_IN)
1356 1.3.2.2 thorpej break;
1357 1.3.2.2 thorpej }
1358 1.3.2.2 thorpej
1359 1.3.2.2 thorpej cmd = SFAS_CMD_MESSAGE_ACCEPTED;
1360 1.3.2.2 thorpej if (nexus->flags & SFAS_NF_HAS_MSG) {
1361 1.3.2.2 thorpej /* We have a message. Decode it. */
1362 1.3.2.2 thorpej
1363 1.3.2.2 thorpej switch(dev->sc_msg_in[0]) {
1364 1.3.2.2 thorpej case 0x00: /* COMMAND COMPLETE */
1365 1.3.2.2 thorpej nexus->state = SFAS_NS_DONE;
1366 1.3.2.2 thorpej break;
1367 1.3.2.2 thorpej case 0x04: /* DISCONNECT */
1368 1.3.2.2 thorpej nexus->state = SFAS_NS_DISCONNECTING;
1369 1.3.2.2 thorpej break;
1370 1.3.2.2 thorpej case 0x02: /* SAVE DATA POINTER */
1371 1.3.2.2 thorpej sfas_save_pointers(dev);
1372 1.3.2.2 thorpej break;
1373 1.3.2.2 thorpej case 0x03: /* RESTORE DATA POINTERS */
1374 1.3.2.2 thorpej sfas_restore_pointers(dev);
1375 1.3.2.2 thorpej break;
1376 1.3.2.2 thorpej case 0x07: /* MESSAGE REJECT */
1377 1.3.2.2 thorpej /*
1378 1.3.2.2 thorpej * If we had sent a SDTR and we got a message
1379 1.3.2.2 thorpej * reject, the scsi docs say that we must go
1380 1.3.2.2 thorpej * to async transfer.
1381 1.3.2.2 thorpej */
1382 1.3.2.2 thorpej if (nexus->flags & SFAS_NF_SDTR_SENT) {
1383 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_SDTR_SENT;
1384 1.3.2.2 thorpej
1385 1.3.2.2 thorpej nexus->config3 &= ~SFAS_CFG3_FASTSCSI;
1386 1.3.2.2 thorpej nexus->syncper = 5;
1387 1.3.2.2 thorpej nexus->syncoff = 0;
1388 1.3.2.2 thorpej
1389 1.3.2.2 thorpej *rp->sfas_syncper = nexus->syncper;
1390 1.3.2.2 thorpej *rp->sfas_syncoff = nexus->syncoff;
1391 1.3.2.2 thorpej *rp->sfas_config3 = nexus->config3;
1392 1.3.2.2 thorpej } else
1393 1.3.2.2 thorpej /*
1394 1.3.2.2 thorpej * Something was rejected but we don't know
1395 1.3.2.2 thorpej * what! PANIC!
1396 1.3.2.2 thorpej */
1397 1.3.2.2 thorpej panic("sfasintr: Unknown message rejected!");
1398 1.3.2.2 thorpej break;
1399 1.3.2.2 thorpej case 0x08: /* MO OPERATION */
1400 1.3.2.2 thorpej break;
1401 1.3.2.2 thorpej case 0x01: /* EXTENDED MESSAGE */
1402 1.3.2.2 thorpej switch(dev->sc_msg_in[2]) {
1403 1.3.2.2 thorpej case 0x01:/* SYNC. DATA TRANSFER REQUEST */
1404 1.3.2.2 thorpej /* Decode the SDTR message. */
1405 1.3.2.2 thorpej period = 4*dev->sc_msg_in[3];
1406 1.3.2.2 thorpej offset = dev->sc_msg_in[4];
1407 1.3.2.2 thorpej
1408 1.3.2.2 thorpej /*
1409 1.3.2.2 thorpej * Make sure that the specs are within
1410 1.3.2.2 thorpej * chip limits. Note that if we
1411 1.3.2.2 thorpej * initiated the negotiation the specs
1412 1.3.2.2 thorpej * WILL be withing chip limits. If it
1413 1.3.2.2 thorpej * was the scsi unit that initiated
1414 1.3.2.2 thorpej * the negotiation, the specs may be
1415 1.3.2.2 thorpej * to high.
1416 1.3.2.2 thorpej */
1417 1.3.2.2 thorpej if (offset > 16)
1418 1.3.2.2 thorpej offset = 16;
1419 1.3.2.2 thorpej if ((period < 200) &&
1420 1.3.2.2 thorpej (dev->sc_clock_freq <= 25))
1421 1.3.2.2 thorpej period = 200;
1422 1.3.2.2 thorpej
1423 1.3.2.2 thorpej if (offset == 0)
1424 1.3.2.2 thorpej period = 5*dev->sc_clock_period;
1425 1.3.2.2 thorpej
1426 1.3.2.2 thorpej nexus->syncper = period/
1427 1.3.2.2 thorpej dev->sc_clock_period;
1428 1.3.2.2 thorpej nexus->syncoff = offset;
1429 1.3.2.2 thorpej
1430 1.3.2.2 thorpej if (period < 200)
1431 1.3.2.2 thorpej nexus->config3 |= SFAS_CFG3_FASTSCSI;
1432 1.3.2.2 thorpej else
1433 1.3.2.2 thorpej nexus->config3 &=~SFAS_CFG3_FASTSCSI;
1434 1.3.2.2 thorpej
1435 1.3.2.2 thorpej nexus->flags |= SFAS_NF_SYNC_TESTED;
1436 1.3.2.2 thorpej
1437 1.3.2.2 thorpej *rp->sfas_syncper = nexus->syncper;
1438 1.3.2.2 thorpej *rp->sfas_syncoff = nexus->syncoff;
1439 1.3.2.2 thorpej *rp->sfas_config3 = nexus->config3;
1440 1.3.2.2 thorpej
1441 1.3.2.2 thorpej /*
1442 1.3.2.2 thorpej * Hmmm, it seems that the scsi unit
1443 1.3.2.2 thorpej * initiated sync negotiation, so lets
1444 1.3.2.2 thorpej * reply acording to scsi-2 standard.
1445 1.3.2.2 thorpej */
1446 1.3.2.2 thorpej if (!(nexus->flags& SFAS_NF_SDTR_SENT))
1447 1.3.2.2 thorpej {
1448 1.3.2.2 thorpej if ((dev->sc_config_flags &
1449 1.3.2.2 thorpej SFAS_NO_SYNCH) ||
1450 1.3.2.2 thorpej (dev->sc_config_flags &
1451 1.3.2.2 thorpej SFAS_NO_DMA) ||
1452 1.3.2.2 thorpej sfas_inhibit_sync[
1453 1.3.2.2 thorpej nexus->lun_unit & 7]) {
1454 1.3.2.2 thorpej period = 200;
1455 1.3.2.2 thorpej offset = 0;
1456 1.3.2.2 thorpej }
1457 1.3.2.2 thorpej
1458 1.3.2.2 thorpej nexus->offset = offset;
1459 1.3.2.2 thorpej nexus->period = period;
1460 1.3.2.2 thorpej nexus->flags |= SFAS_NF_DO_SDTR;
1461 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_SET_ATN;
1462 1.3.2.2 thorpej }
1463 1.3.2.2 thorpej
1464 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_SDTR_SENT;
1465 1.3.2.2 thorpej break;
1466 1.3.2.2 thorpej
1467 1.3.2.2 thorpej case 0x00: /* MODIFY DATA POINTERS */
1468 1.3.2.2 thorpej case 0x02: /* EXTENDED IDENTIFY (SCSI-1) */
1469 1.3.2.2 thorpej case 0x03: /* WIDE DATA TRANSFER REQUEST */
1470 1.3.2.2 thorpej default:
1471 1.3.2.2 thorpej /* Reject any unhandeled messages. */
1472 1.3.2.2 thorpej
1473 1.3.2.2 thorpej dev->sc_msg_out[0] = 0x07;
1474 1.3.2.2 thorpej dev->sc_msg_out_len = 1;
1475 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_SET_ATN;
1476 1.3.2.2 thorpej cmd = SFAS_CMD_MESSAGE_ACCEPTED;
1477 1.3.2.2 thorpej break;
1478 1.3.2.2 thorpej }
1479 1.3.2.2 thorpej break;
1480 1.3.2.2 thorpej
1481 1.3.2.2 thorpej default:
1482 1.3.2.2 thorpej /* Reject any unhandeled messages. */
1483 1.3.2.2 thorpej
1484 1.3.2.2 thorpej dev->sc_msg_out[0] = 0x07;
1485 1.3.2.2 thorpej dev->sc_msg_out_len = 1;
1486 1.3.2.2 thorpej *rp->sfas_command = SFAS_CMD_SET_ATN;
1487 1.3.2.2 thorpej cmd = SFAS_CMD_MESSAGE_ACCEPTED;
1488 1.3.2.2 thorpej break;
1489 1.3.2.2 thorpej }
1490 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_HAS_MSG;
1491 1.3.2.2 thorpej dev->sc_msg_in_len = 0;
1492 1.3.2.2 thorpej }
1493 1.3.2.2 thorpej break;
1494 1.3.2.2 thorpej default:
1495 1.3.2.2 thorpej printf("SFASINTR: UNKNOWN PHASE! phase: %d\n",
1496 1.3.2.2 thorpej dev->sc_status & SFAS_STAT_PHASE_MASK);
1497 1.3.2.2 thorpej dev->sc_led(dev, 0);
1498 1.3.2.2 thorpej sfas_scsidone(dev, nexus->xs, -4);
1499 1.3.2.2 thorpej
1500 1.3.2.2 thorpej return(-1);
1501 1.3.2.2 thorpej }
1502 1.3.2.2 thorpej
1503 1.3.2.2 thorpej if (cmd)
1504 1.3.2.2 thorpej *rp->sfas_command = cmd;
1505 1.3.2.2 thorpej
1506 1.3.2.2 thorpej return(0);
1507 1.3.2.2 thorpej }
1508 1.3.2.2 thorpej
1509 1.3.2.2 thorpej /*
1510 1.3.2.2 thorpej * Stub for interrupt machine.
1511 1.3.2.2 thorpej */
1512 1.3.2.2 thorpej void
1513 1.3.2.2 thorpej sfasintr(dev)
1514 1.3.2.2 thorpej struct sfas_softc *dev;
1515 1.3.2.2 thorpej {
1516 1.3.2.2 thorpej sfas_regmap_p rp;
1517 1.3.2.2 thorpej struct nexus *nexus;
1518 1.3.2.2 thorpej
1519 1.3.2.2 thorpej rp = dev->sc_fas;
1520 1.3.2.2 thorpej
1521 1.3.2.2 thorpej if (!sfas_pretests(dev, rp)) {
1522 1.3.2.2 thorpej
1523 1.3.2.2 thorpej nexus = dev->sc_cur_nexus;
1524 1.3.2.2 thorpej if (nexus == NULL)
1525 1.3.2.2 thorpej nexus = dev->sc_sel_nexus;
1526 1.3.2.2 thorpej
1527 1.3.2.2 thorpej if (nexus)
1528 1.3.2.2 thorpej if (!sfas_midaction(dev, rp, nexus))
1529 1.3.2.2 thorpej sfas_postaction(dev, rp, nexus);
1530 1.3.2.2 thorpej }
1531 1.3.2.2 thorpej }
1532 1.3.2.2 thorpej
1533 1.3.2.2 thorpej /*
1534 1.3.2.2 thorpej * sfasicmd is used to perform IO when we can't use interrupts. sfasicmd
1535 1.3.2.2 thorpej * emulates the normal environment by waiting for the chip and calling
1536 1.3.2.2 thorpej * sfasintr.
1537 1.3.2.2 thorpej */
1538 1.3.2.2 thorpej void
1539 1.3.2.2 thorpej sfasicmd(dev, pendp)
1540 1.3.2.2 thorpej struct sfas_softc *dev;
1541 1.3.2.2 thorpej struct sfas_pending *pendp;
1542 1.3.2.2 thorpej {
1543 1.3.2.2 thorpej sfas_regmap_p rp;
1544 1.3.2.2 thorpej struct nexus *nexus;
1545 1.3.2.2 thorpej
1546 1.3.2.2 thorpej nexus = &dev->sc_nexus[pendp->xs->xs_periph->periph_target];
1547 1.3.2.2 thorpej rp = dev->sc_fas;
1548 1.3.2.2 thorpej
1549 1.3.2.2 thorpej if (!sfasselect(dev, pendp, (char *)pendp->xs->cmd, pendp->xs->cmdlen,
1550 1.3.2.2 thorpej (char *)pendp->xs->data, pendp->xs->datalen,
1551 1.3.2.2 thorpej SFAS_SELECT_I))
1552 1.3.2.2 thorpej panic("sfasicmd: Couldn't select unit");
1553 1.3.2.2 thorpej
1554 1.3.2.2 thorpej while(nexus->state != SFAS_NS_FINISHED) {
1555 1.3.2.2 thorpej sfasiwait(dev);
1556 1.3.2.2 thorpej sfasintr(dev);
1557 1.3.2.2 thorpej }
1558 1.3.2.2 thorpej
1559 1.3.2.2 thorpej nexus->flags &= ~SFAS_NF_SYNC_TESTED;
1560 1.3.2.2 thorpej }
1561 1.3.2.2 thorpej
1562 1.3.2.2 thorpej
1563 1.3.2.2 thorpej #ifdef SFAS_DEBUG
1564 1.3.2.2 thorpej
1565 1.3.2.2 thorpej void
1566 1.3.2.2 thorpej dump_nexus(nexus)
1567 1.3.2.2 thorpej struct nexus *nexus;
1568 1.3.2.2 thorpej {
1569 1.3.2.2 thorpej int loop;
1570 1.3.2.2 thorpej
1571 1.3.2.2 thorpej printf("nexus=%08x\n", (u_int)nexus);
1572 1.3.2.2 thorpej printf("scsi_fer=%08x\n", (u_int)nexus->xs);
1573 1.3.2.2 thorpej printf("ID=%02x\n", nexus->ID);
1574 1.3.2.2 thorpej printf("clen=%02x\n", nexus->clen);
1575 1.3.2.2 thorpej printf("cbuf=");
1576 1.3.2.2 thorpej for (loop = 0; loop< 14; ++loop)
1577 1.3.2.2 thorpej printf(" %02x\n", nexus->cbuf[loop]);
1578 1.3.2.2 thorpej printf("\n");
1579 1.3.2.2 thorpej printf("dma:\n");
1580 1.3.2.2 thorpej for (loop = 0; loop < MAXCHAIN; ++loop)
1581 1.3.2.2 thorpej printf("dma_chain: %08x %04x %04x\n", nexus->dma[loop].ptr,
1582 1.3.2.2 thorpej nexus->dma[loop].len, nexus->dma[loop].flg);
1583 1.3.2.2 thorpej printf("\n");
1584 1.3.2.2 thorpej
1585 1.3.2.2 thorpej printf("max_link=%d\n", nexus->max_link);
1586 1.3.2.2 thorpej printf("cur_link=%d\n", nexus->cur_link);
1587 1.3.2.2 thorpej
1588 1.3.2.2 thorpej printf("buf=%08x\n", (u_int)nexus->buf);
1589 1.3.2.2 thorpej printf("len=%08x\n", nexus->len);
1590 1.3.2.2 thorpej printf("dma_buf=%08x\n", (u_int)nexus->dma_buf);
1591 1.3.2.2 thorpej printf("dma_len=%08x\n", nexus->dma_len);
1592 1.3.2.2 thorpej printf("dma_blk_ptr=%08x\n", (u_int)nexus->dma_blk_ptr);
1593 1.3.2.2 thorpej printf("dma_blk_len=%08x\n", nexus->dma_blk_len);
1594 1.3.2.2 thorpej printf("dma_blk_flag=%08x\n", nexus->dma_blk_flg);
1595 1.3.2.2 thorpej printf("state=%02x\n", nexus->state);
1596 1.3.2.2 thorpej printf("flags=%04x\n", nexus->flags);
1597 1.3.2.2 thorpej printf("period=%d\n", nexus->period);
1598 1.3.2.2 thorpej printf("offset=%d\n", nexus->offset);
1599 1.3.2.2 thorpej printf("syncper=%d\n", nexus->syncper);
1600 1.3.2.2 thorpej printf("syncoff=%d\n", nexus->syncoff);
1601 1.3.2.2 thorpej printf("config3=%02x\n", nexus->config3);
1602 1.3.2.2 thorpej printf("lun_unit=%d\n", nexus->lun_unit);
1603 1.3.2.2 thorpej printf("status=%02x\n", nexus->status);
1604 1.3.2.2 thorpej printf("\n");
1605 1.3.2.2 thorpej }
1606 1.3.2.2 thorpej
1607 1.3.2.2 thorpej void
1608 1.3.2.2 thorpej dump_nexii(sc)
1609 1.3.2.2 thorpej struct sfas_softc *sc;
1610 1.3.2.2 thorpej {
1611 1.3.2.2 thorpej int loop;
1612 1.3.2.2 thorpej
1613 1.3.2.2 thorpej for (loop = 0; loop < 8; ++loop) {
1614 1.3.2.2 thorpej dump_nexus(&sc->sc_nexus[loop]);
1615 1.3.2.2 thorpej }
1616 1.3.2.2 thorpej }
1617 1.3.2.2 thorpej
1618 1.3.2.2 thorpej void
1619 1.3.2.2 thorpej dump_sfassoftc(sc)
1620 1.3.2.2 thorpej struct sfas_softc *sc;
1621 1.3.2.2 thorpej {
1622 1.3.2.2 thorpej printf("sfassoftc @ 0x%08x\n", (u_int)sc);
1623 1.3.2.2 thorpej printf("clock_freq = %d\n", sc->sc_clock_freq);
1624 1.3.2.2 thorpej printf("timeout = %d\n", sc->sc_timeout);
1625 1.3.2.2 thorpej printf("host_id = %d\n", sc->sc_host_id);
1626 1.3.2.2 thorpej printf("config_flags = 0x%08x\n", sc->sc_config_flags);
1627 1.3.2.2 thorpej printf("led_status = %d\n", sc->sc_led_status);
1628 1.3.2.2 thorpej
1629 1.3.2.2 thorpej dump_nexii(sc);
1630 1.3.2.2 thorpej printf("cur_nexus = 0x%08x\n", (u_int)sc->sc_cur_nexus);
1631 1.3.2.2 thorpej printf("sel_nexus = 0x%08x\n", (u_int)sc->sc_sel_nexus);
1632 1.3.2.2 thorpej printf("\n");
1633 1.3.2.2 thorpej }
1634 1.3.2.2 thorpej
1635 1.3.2.2 thorpej #endif /* SFAS_DEBUG */
1636