uha.c revision 1.7 1 1.7 mycroft /* $NetBSD: uha.c,v 1.7 1997/03/29 02:32:31 mycroft Exp $ */
2 1.1 mycroft
3 1.1 mycroft #undef UHADEBUG
4 1.1 mycroft #ifdef DDB
5 1.1 mycroft #define integrate
6 1.1 mycroft #else
7 1.1 mycroft #define integrate static inline
8 1.1 mycroft #endif
9 1.1 mycroft
10 1.1 mycroft /*
11 1.7 mycroft * Copyright (c) 1994, 1996, 1997 Charles M. Hannum. All rights reserved.
12 1.1 mycroft *
13 1.1 mycroft * Redistribution and use in source and binary forms, with or without
14 1.1 mycroft * modification, are permitted provided that the following conditions
15 1.1 mycroft * are met:
16 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
17 1.1 mycroft * notice, this list of conditions and the following disclaimer.
18 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
19 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
20 1.1 mycroft * documentation and/or other materials provided with the distribution.
21 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
22 1.1 mycroft * must display the following acknowledgement:
23 1.1 mycroft * This product includes software developed by Charles M. Hannum.
24 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
25 1.1 mycroft * derived from this software without specific prior written permission.
26 1.1 mycroft *
27 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 1.1 mycroft */
38 1.1 mycroft
39 1.1 mycroft /*
40 1.1 mycroft * Ported for use with the UltraStor 14f by Gary Close (gclose (at) wvnvms.wvnet.edu)
41 1.1 mycroft * Slight fixes to timeouts to run with the 34F
42 1.1 mycroft * Thanks to Julian Elischer for advice and help with this port.
43 1.1 mycroft *
44 1.1 mycroft * Originally written by Julian Elischer (julian (at) tfs.com)
45 1.1 mycroft * for TRW Financial Systems for use under the MACH(2.5) operating system.
46 1.1 mycroft *
47 1.1 mycroft * TRW Financial Systems, in accordance with their agreement with Carnegie
48 1.1 mycroft * Mellon University, makes this software available to CMU to distribute
49 1.1 mycroft * or use in any manner that they see fit as long as this message is kept with
50 1.1 mycroft * the software. For this reason TFS also grants any other persons or
51 1.1 mycroft * organisations permission to use or modify this software.
52 1.1 mycroft *
53 1.1 mycroft * TFS supplies this software to be publicly redistributed
54 1.1 mycroft * on the understanding that TFS is not responsible for the correct
55 1.1 mycroft * functioning of this software in any circumstances.
56 1.1 mycroft *
57 1.1 mycroft * commenced: Sun Sep 27 18:14:01 PDT 1992
58 1.1 mycroft * slight mod to make work with 34F as well: Wed Jun 2 18:05:48 WST 1993
59 1.1 mycroft */
60 1.1 mycroft
61 1.1 mycroft #include <sys/types.h>
62 1.1 mycroft #include <sys/param.h>
63 1.1 mycroft #include <sys/systm.h>
64 1.1 mycroft #include <sys/kernel.h>
65 1.1 mycroft #include <sys/errno.h>
66 1.1 mycroft #include <sys/ioctl.h>
67 1.1 mycroft #include <sys/device.h>
68 1.1 mycroft #include <sys/malloc.h>
69 1.1 mycroft #include <sys/buf.h>
70 1.1 mycroft #include <sys/proc.h>
71 1.1 mycroft #include <sys/user.h>
72 1.1 mycroft
73 1.1 mycroft #include <machine/bus.h>
74 1.1 mycroft #include <machine/intr.h>
75 1.1 mycroft
76 1.1 mycroft #include <scsi/scsi_all.h>
77 1.1 mycroft #include <scsi/scsiconf.h>
78 1.1 mycroft
79 1.1 mycroft #include <dev/ic/uhareg.h>
80 1.1 mycroft #include <dev/ic/uhavar.h>
81 1.1 mycroft
82 1.1 mycroft #ifndef DDB
83 1.5 jonathan #define Debugger() panic("should call debugger here (uha.c)")
84 1.1 mycroft #endif /* ! DDB */
85 1.1 mycroft
86 1.1 mycroft #define KVTOPHYS(x) vtophys(x)
87 1.1 mycroft
88 1.4 mycroft integrate void uha_reset_mscp __P((struct uha_softc *, struct uha_mscp *));
89 1.1 mycroft void uha_free_mscp __P((struct uha_softc *, struct uha_mscp *));
90 1.4 mycroft integrate void uha_init_mscp __P((struct uha_softc *, struct uha_mscp *));
91 1.1 mycroft struct uha_mscp *uha_get_mscp __P((struct uha_softc *, int));
92 1.1 mycroft void uhaminphys __P((struct buf *));
93 1.1 mycroft int uha_scsi_cmd __P((struct scsi_xfer *));
94 1.1 mycroft
95 1.1 mycroft struct scsi_adapter uha_switch = {
96 1.1 mycroft uha_scsi_cmd,
97 1.1 mycroft uhaminphys,
98 1.1 mycroft 0,
99 1.1 mycroft 0,
100 1.1 mycroft };
101 1.1 mycroft
102 1.1 mycroft /* the below structure is so we have a default dev struct for out link struct */
103 1.1 mycroft struct scsi_device uha_dev = {
104 1.1 mycroft NULL, /* Use default error handler */
105 1.1 mycroft NULL, /* have a queue, served by this */
106 1.1 mycroft NULL, /* have no async handler */
107 1.1 mycroft NULL, /* Use default 'done' routine */
108 1.1 mycroft };
109 1.1 mycroft
110 1.1 mycroft struct cfdriver uha_cd = {
111 1.1 mycroft NULL, "uha", DV_DULL
112 1.1 mycroft };
113 1.1 mycroft
114 1.1 mycroft #define UHA_ABORT_TIMEOUT 2000 /* time to wait for abort (mSec) */
115 1.1 mycroft
116 1.1 mycroft /*
117 1.1 mycroft * Attach all the sub-devices we can find
118 1.1 mycroft */
119 1.1 mycroft void
120 1.7 mycroft uha_attach(sc, upd)
121 1.1 mycroft struct uha_softc *sc;
122 1.7 mycroft struct uha_probe_data *upd;
123 1.1 mycroft {
124 1.1 mycroft
125 1.1 mycroft (sc->init)(sc);
126 1.1 mycroft TAILQ_INIT(&sc->sc_free_mscp);
127 1.1 mycroft
128 1.1 mycroft /*
129 1.1 mycroft * fill in the prototype scsi_link.
130 1.1 mycroft */
131 1.1 mycroft sc->sc_link.channel = SCSI_CHANNEL_ONLY_ONE;
132 1.1 mycroft sc->sc_link.adapter_softc = sc;
133 1.7 mycroft sc->sc_link.adapter_target = upd->sc_scsi_dev;
134 1.1 mycroft sc->sc_link.adapter = &uha_switch;
135 1.1 mycroft sc->sc_link.device = &uha_dev;
136 1.1 mycroft sc->sc_link.openings = 2;
137 1.6 thorpej sc->sc_link.max_target = 7;
138 1.1 mycroft
139 1.1 mycroft /*
140 1.1 mycroft * ask the adapter what subunits are present
141 1.1 mycroft */
142 1.1 mycroft config_found(&sc->sc_dev, &sc->sc_link, scsiprint);
143 1.1 mycroft }
144 1.1 mycroft
145 1.1 mycroft integrate void
146 1.1 mycroft uha_reset_mscp(sc, mscp)
147 1.1 mycroft struct uha_softc *sc;
148 1.1 mycroft struct uha_mscp *mscp;
149 1.1 mycroft {
150 1.1 mycroft
151 1.1 mycroft mscp->flags = 0;
152 1.1 mycroft }
153 1.1 mycroft
154 1.1 mycroft /*
155 1.1 mycroft * A mscp (and hence a mbx-out) is put onto the free list.
156 1.1 mycroft */
157 1.1 mycroft void
158 1.1 mycroft uha_free_mscp(sc, mscp)
159 1.1 mycroft struct uha_softc *sc;
160 1.1 mycroft struct uha_mscp *mscp;
161 1.1 mycroft {
162 1.1 mycroft int s;
163 1.1 mycroft
164 1.1 mycroft s = splbio();
165 1.1 mycroft
166 1.1 mycroft uha_reset_mscp(sc, mscp);
167 1.1 mycroft TAILQ_INSERT_HEAD(&sc->sc_free_mscp, mscp, chain);
168 1.1 mycroft
169 1.1 mycroft /*
170 1.1 mycroft * If there were none, wake anybody waiting for one to come free,
171 1.1 mycroft * starting with queued entries.
172 1.1 mycroft */
173 1.1 mycroft if (mscp->chain.tqe_next == 0)
174 1.1 mycroft wakeup(&sc->sc_free_mscp);
175 1.1 mycroft
176 1.1 mycroft splx(s);
177 1.1 mycroft }
178 1.1 mycroft
179 1.1 mycroft integrate void
180 1.1 mycroft uha_init_mscp(sc, mscp)
181 1.1 mycroft struct uha_softc *sc;
182 1.1 mycroft struct uha_mscp *mscp;
183 1.1 mycroft {
184 1.1 mycroft int hashnum;
185 1.1 mycroft
186 1.1 mycroft bzero(mscp, sizeof(struct uha_mscp));
187 1.1 mycroft /*
188 1.1 mycroft * put in the phystokv hash table
189 1.1 mycroft * Never gets taken out.
190 1.1 mycroft */
191 1.1 mycroft mscp->hashkey = KVTOPHYS(mscp);
192 1.1 mycroft hashnum = MSCP_HASH(mscp->hashkey);
193 1.1 mycroft mscp->nexthash = sc->sc_mscphash[hashnum];
194 1.1 mycroft sc->sc_mscphash[hashnum] = mscp;
195 1.1 mycroft uha_reset_mscp(sc, mscp);
196 1.1 mycroft }
197 1.1 mycroft
198 1.1 mycroft /*
199 1.1 mycroft * Get a free mscp
200 1.1 mycroft *
201 1.1 mycroft * If there are none, see if we can allocate a new one. If so, put it in the
202 1.1 mycroft * hash table too otherwise either return an error or sleep.
203 1.1 mycroft */
204 1.1 mycroft struct uha_mscp *
205 1.1 mycroft uha_get_mscp(sc, flags)
206 1.1 mycroft struct uha_softc *sc;
207 1.1 mycroft int flags;
208 1.1 mycroft {
209 1.1 mycroft struct uha_mscp *mscp;
210 1.1 mycroft int s;
211 1.1 mycroft
212 1.1 mycroft s = splbio();
213 1.1 mycroft
214 1.1 mycroft /*
215 1.1 mycroft * If we can and have to, sleep waiting for one to come free
216 1.1 mycroft * but only if we can't allocate a new one
217 1.1 mycroft */
218 1.1 mycroft for (;;) {
219 1.1 mycroft mscp = sc->sc_free_mscp.tqh_first;
220 1.1 mycroft if (mscp) {
221 1.1 mycroft TAILQ_REMOVE(&sc->sc_free_mscp, mscp, chain);
222 1.1 mycroft break;
223 1.1 mycroft }
224 1.1 mycroft if (sc->sc_nummscps < UHA_MSCP_MAX) {
225 1.1 mycroft mscp = (struct uha_mscp *) malloc(sizeof(struct uha_mscp),
226 1.1 mycroft M_TEMP, M_NOWAIT);
227 1.1 mycroft if (!mscp) {
228 1.3 christos printf("%s: can't malloc mscp\n",
229 1.1 mycroft sc->sc_dev.dv_xname);
230 1.1 mycroft goto out;
231 1.1 mycroft }
232 1.1 mycroft uha_init_mscp(sc, mscp);
233 1.1 mycroft sc->sc_nummscps++;
234 1.1 mycroft break;
235 1.1 mycroft }
236 1.1 mycroft if ((flags & SCSI_NOSLEEP) != 0)
237 1.1 mycroft goto out;
238 1.1 mycroft tsleep(&sc->sc_free_mscp, PRIBIO, "uhamsc", 0);
239 1.1 mycroft }
240 1.1 mycroft
241 1.1 mycroft mscp->flags |= MSCP_ALLOC;
242 1.1 mycroft
243 1.1 mycroft out:
244 1.1 mycroft splx(s);
245 1.1 mycroft return (mscp);
246 1.1 mycroft }
247 1.1 mycroft
248 1.1 mycroft /*
249 1.1 mycroft * given a physical address, find the mscp that it corresponds to.
250 1.1 mycroft */
251 1.1 mycroft struct uha_mscp *
252 1.1 mycroft uha_mscp_phys_kv(sc, mscp_phys)
253 1.1 mycroft struct uha_softc *sc;
254 1.1 mycroft u_long mscp_phys;
255 1.1 mycroft {
256 1.1 mycroft int hashnum = MSCP_HASH(mscp_phys);
257 1.1 mycroft struct uha_mscp *mscp = sc->sc_mscphash[hashnum];
258 1.1 mycroft
259 1.1 mycroft while (mscp) {
260 1.1 mycroft if (mscp->hashkey == mscp_phys)
261 1.1 mycroft break;
262 1.1 mycroft mscp = mscp->nexthash;
263 1.1 mycroft }
264 1.1 mycroft return (mscp);
265 1.1 mycroft }
266 1.1 mycroft
267 1.1 mycroft /*
268 1.1 mycroft * We have a mscp which has been processed by the adaptor, now we look to see
269 1.1 mycroft * how the operation went.
270 1.1 mycroft */
271 1.1 mycroft void
272 1.1 mycroft uha_done(sc, mscp)
273 1.1 mycroft struct uha_softc *sc;
274 1.1 mycroft struct uha_mscp *mscp;
275 1.1 mycroft {
276 1.1 mycroft struct scsi_sense_data *s1, *s2;
277 1.1 mycroft struct scsi_xfer *xs = mscp->xs;
278 1.1 mycroft
279 1.1 mycroft SC_DEBUG(xs->sc_link, SDEV_DB2, ("uha_done\n"));
280 1.1 mycroft /*
281 1.1 mycroft * Otherwise, put the results of the operation
282 1.1 mycroft * into the xfer and call whoever started it
283 1.1 mycroft */
284 1.1 mycroft if ((mscp->flags & MSCP_ALLOC) == 0) {
285 1.3 christos printf("%s: exiting ccb not allocated!\n", sc->sc_dev.dv_xname);
286 1.1 mycroft Debugger();
287 1.1 mycroft return;
288 1.1 mycroft }
289 1.1 mycroft if (xs->error == XS_NOERROR) {
290 1.1 mycroft if (mscp->host_stat != UHA_NO_ERR) {
291 1.1 mycroft switch (mscp->host_stat) {
292 1.1 mycroft case UHA_SBUS_TIMEOUT: /* No response */
293 1.1 mycroft xs->error = XS_SELTIMEOUT;
294 1.1 mycroft break;
295 1.1 mycroft default: /* Other scsi protocol messes */
296 1.3 christos printf("%s: host_stat %x\n",
297 1.1 mycroft sc->sc_dev.dv_xname, mscp->host_stat);
298 1.1 mycroft xs->error = XS_DRIVER_STUFFUP;
299 1.1 mycroft }
300 1.1 mycroft } else if (mscp->target_stat != SCSI_OK) {
301 1.1 mycroft switch (mscp->target_stat) {
302 1.1 mycroft case SCSI_CHECK:
303 1.1 mycroft s1 = &mscp->mscp_sense;
304 1.1 mycroft s2 = &xs->sense;
305 1.1 mycroft *s2 = *s1;
306 1.1 mycroft xs->error = XS_SENSE;
307 1.1 mycroft break;
308 1.1 mycroft case SCSI_BUSY:
309 1.1 mycroft xs->error = XS_BUSY;
310 1.1 mycroft break;
311 1.1 mycroft default:
312 1.3 christos printf("%s: target_stat %x\n",
313 1.1 mycroft sc->sc_dev.dv_xname, mscp->target_stat);
314 1.1 mycroft xs->error = XS_DRIVER_STUFFUP;
315 1.1 mycroft }
316 1.1 mycroft } else
317 1.1 mycroft xs->resid = 0;
318 1.1 mycroft }
319 1.1 mycroft uha_free_mscp(sc, mscp);
320 1.1 mycroft xs->flags |= ITSDONE;
321 1.1 mycroft scsi_done(xs);
322 1.1 mycroft }
323 1.1 mycroft
324 1.1 mycroft void
325 1.1 mycroft uhaminphys(bp)
326 1.1 mycroft struct buf *bp;
327 1.1 mycroft {
328 1.1 mycroft
329 1.1 mycroft if (bp->b_bcount > ((UHA_NSEG - 1) << PGSHIFT))
330 1.1 mycroft bp->b_bcount = ((UHA_NSEG - 1) << PGSHIFT);
331 1.1 mycroft minphys(bp);
332 1.1 mycroft }
333 1.1 mycroft
334 1.1 mycroft /*
335 1.1 mycroft * start a scsi operation given the command and the data address. Also
336 1.1 mycroft * needs the unit, target and lu.
337 1.1 mycroft */
338 1.1 mycroft int
339 1.1 mycroft uha_scsi_cmd(xs)
340 1.1 mycroft struct scsi_xfer *xs;
341 1.1 mycroft {
342 1.1 mycroft struct scsi_link *sc_link = xs->sc_link;
343 1.1 mycroft struct uha_softc *sc = sc_link->adapter_softc;
344 1.1 mycroft struct uha_mscp *mscp;
345 1.1 mycroft struct uha_dma_seg *sg;
346 1.1 mycroft int seg; /* scatter gather seg being worked on */
347 1.1 mycroft u_long thiskv, thisphys, nextphys;
348 1.1 mycroft int bytes_this_seg, bytes_this_page, datalen, flags;
349 1.1 mycroft int s;
350 1.1 mycroft
351 1.1 mycroft SC_DEBUG(sc_link, SDEV_DB2, ("uha_scsi_cmd\n"));
352 1.1 mycroft /*
353 1.1 mycroft * get a mscp (mbox-out) to use. If the transfer
354 1.1 mycroft * is from a buf (possibly from interrupt time)
355 1.1 mycroft * then we can't allow it to sleep
356 1.1 mycroft */
357 1.1 mycroft flags = xs->flags;
358 1.1 mycroft if ((mscp = uha_get_mscp(sc, flags)) == NULL) {
359 1.1 mycroft xs->error = XS_DRIVER_STUFFUP;
360 1.1 mycroft return (TRY_AGAIN_LATER);
361 1.1 mycroft }
362 1.1 mycroft mscp->xs = xs;
363 1.1 mycroft mscp->timeout = xs->timeout;
364 1.1 mycroft
365 1.1 mycroft /*
366 1.1 mycroft * Put all the arguments for the xfer in the mscp
367 1.1 mycroft */
368 1.1 mycroft if (flags & SCSI_RESET) {
369 1.1 mycroft mscp->opcode = UHA_SDR;
370 1.1 mycroft mscp->ca = 0x01;
371 1.1 mycroft } else {
372 1.1 mycroft mscp->opcode = UHA_TSP;
373 1.1 mycroft /* XXX Not for tapes. */
374 1.1 mycroft mscp->ca = 0x01;
375 1.1 mycroft bcopy(xs->cmd, &mscp->scsi_cmd, mscp->scsi_cmd_length);
376 1.1 mycroft }
377 1.1 mycroft mscp->xdir = UHA_SDET;
378 1.1 mycroft mscp->dcn = 0x00;
379 1.1 mycroft mscp->chan = 0x00;
380 1.1 mycroft mscp->target = sc_link->target;
381 1.1 mycroft mscp->lun = sc_link->lun;
382 1.1 mycroft mscp->scsi_cmd_length = xs->cmdlen;
383 1.1 mycroft mscp->sense_ptr = KVTOPHYS(&mscp->mscp_sense);
384 1.1 mycroft mscp->req_sense_length = sizeof(mscp->mscp_sense);
385 1.1 mycroft mscp->host_stat = 0x00;
386 1.1 mycroft mscp->target_stat = 0x00;
387 1.1 mycroft
388 1.1 mycroft if (xs->datalen) {
389 1.1 mycroft sg = mscp->uha_dma;
390 1.1 mycroft seg = 0;
391 1.1 mycroft #ifdef TFS
392 1.1 mycroft if (flags & SCSI_DATA_UIO) {
393 1.2 christos struct iovec *iovp;
394 1.1 mycroft iovp = ((struct uio *) xs->data)->uio_iov;
395 1.1 mycroft datalen = ((struct uio *) xs->data)->uio_iovcnt;
396 1.1 mycroft xs->datalen = 0;
397 1.1 mycroft while (datalen && seg < UHA_NSEG) {
398 1.1 mycroft sg->seg_addr = (physaddr)iovp->iov_base;
399 1.1 mycroft sg->seg_len = iovp->iov_len;
400 1.1 mycroft xs->datalen += iovp->iov_len;
401 1.1 mycroft SC_DEBUGN(sc_link, SDEV_DB4, ("(0x%x@0x%x)",
402 1.1 mycroft iovp->iov_len, iovp->iov_base));
403 1.1 mycroft sg++;
404 1.1 mycroft iovp++;
405 1.1 mycroft seg++;
406 1.1 mycroft datalen--;
407 1.1 mycroft }
408 1.1 mycroft } else
409 1.1 mycroft #endif /*TFS */
410 1.1 mycroft {
411 1.1 mycroft /*
412 1.1 mycroft * Set up the scatter gather block
413 1.1 mycroft */
414 1.1 mycroft SC_DEBUG(sc_link, SDEV_DB4,
415 1.1 mycroft ("%d @0x%x:- ", xs->datalen, xs->data));
416 1.1 mycroft datalen = xs->datalen;
417 1.1 mycroft thiskv = (int) xs->data;
418 1.1 mycroft thisphys = KVTOPHYS(thiskv);
419 1.1 mycroft
420 1.1 mycroft while (datalen && seg < UHA_NSEG) {
421 1.1 mycroft bytes_this_seg = 0;
422 1.1 mycroft
423 1.1 mycroft /* put in the base address */
424 1.1 mycroft sg->seg_addr = thisphys;
425 1.1 mycroft
426 1.1 mycroft SC_DEBUGN(sc_link, SDEV_DB4, ("0x%x", thisphys));
427 1.1 mycroft
428 1.1 mycroft /* do it at least once */
429 1.1 mycroft nextphys = thisphys;
430 1.1 mycroft while (datalen && thisphys == nextphys) {
431 1.1 mycroft /*
432 1.1 mycroft * This page is contiguous (physically)
433 1.1 mycroft * with the the last, just extend the
434 1.1 mycroft * length
435 1.1 mycroft */
436 1.1 mycroft /* how far to the end of the page */
437 1.1 mycroft nextphys = (thisphys & ~PGOFSET) + NBPG;
438 1.1 mycroft bytes_this_page = nextphys - thisphys;
439 1.1 mycroft /**** or the data ****/
440 1.1 mycroft bytes_this_page = min(bytes_this_page,
441 1.1 mycroft datalen);
442 1.1 mycroft bytes_this_seg += bytes_this_page;
443 1.1 mycroft datalen -= bytes_this_page;
444 1.1 mycroft
445 1.1 mycroft /* get more ready for the next page */
446 1.1 mycroft thiskv = (thiskv & ~PGOFSET) + NBPG;
447 1.1 mycroft if (datalen)
448 1.1 mycroft thisphys = KVTOPHYS(thiskv);
449 1.1 mycroft }
450 1.1 mycroft /*
451 1.1 mycroft * next page isn't contiguous, finish the seg
452 1.1 mycroft */
453 1.1 mycroft SC_DEBUGN(sc_link, SDEV_DB4,
454 1.1 mycroft ("(0x%x)", bytes_this_seg));
455 1.1 mycroft sg->seg_len = bytes_this_seg;
456 1.1 mycroft sg++;
457 1.1 mycroft seg++;
458 1.1 mycroft }
459 1.1 mycroft }
460 1.1 mycroft /* end of iov/kv decision */
461 1.1 mycroft SC_DEBUGN(sc_link, SDEV_DB4, ("\n"));
462 1.1 mycroft if (datalen) {
463 1.1 mycroft /*
464 1.1 mycroft * there's still data, must have run out of segs!
465 1.1 mycroft */
466 1.3 christos printf("%s: uha_scsi_cmd, more than %d dma segs\n",
467 1.1 mycroft sc->sc_dev.dv_xname, UHA_NSEG);
468 1.1 mycroft goto bad;
469 1.1 mycroft }
470 1.1 mycroft mscp->data_addr = KVTOPHYS(mscp->uha_dma);
471 1.1 mycroft mscp->data_length = xs->datalen;
472 1.1 mycroft mscp->sgth = 0x01;
473 1.1 mycroft mscp->sg_num = seg;
474 1.1 mycroft } else { /* No data xfer, use non S/G values */
475 1.1 mycroft mscp->data_addr = (physaddr)0;
476 1.1 mycroft mscp->data_length = 0;
477 1.1 mycroft mscp->sgth = 0x00;
478 1.1 mycroft mscp->sg_num = 0;
479 1.1 mycroft }
480 1.1 mycroft mscp->link_id = 0;
481 1.1 mycroft mscp->link_addr = (physaddr)0;
482 1.1 mycroft
483 1.1 mycroft s = splbio();
484 1.1 mycroft (sc->start_mbox)(sc, mscp);
485 1.1 mycroft splx(s);
486 1.1 mycroft
487 1.1 mycroft /*
488 1.1 mycroft * Usually return SUCCESSFULLY QUEUED
489 1.1 mycroft */
490 1.1 mycroft if ((flags & SCSI_POLL) == 0)
491 1.1 mycroft return (SUCCESSFULLY_QUEUED);
492 1.1 mycroft
493 1.1 mycroft /*
494 1.1 mycroft * If we can't use interrupts, poll on completion
495 1.1 mycroft */
496 1.1 mycroft if ((sc->poll)(sc, xs, mscp->timeout)) {
497 1.1 mycroft uha_timeout(mscp);
498 1.1 mycroft if ((sc->poll)(sc, xs, mscp->timeout))
499 1.1 mycroft uha_timeout(mscp);
500 1.1 mycroft }
501 1.1 mycroft return (COMPLETE);
502 1.1 mycroft
503 1.1 mycroft bad:
504 1.1 mycroft xs->error = XS_DRIVER_STUFFUP;
505 1.1 mycroft uha_free_mscp(sc, mscp);
506 1.1 mycroft return (COMPLETE);
507 1.1 mycroft }
508 1.1 mycroft
509 1.1 mycroft void
510 1.1 mycroft uha_timeout(arg)
511 1.1 mycroft void *arg;
512 1.1 mycroft {
513 1.1 mycroft struct uha_mscp *mscp = arg;
514 1.1 mycroft struct scsi_xfer *xs = mscp->xs;
515 1.1 mycroft struct scsi_link *sc_link = xs->sc_link;
516 1.1 mycroft struct uha_softc *sc = sc_link->adapter_softc;
517 1.1 mycroft int s;
518 1.1 mycroft
519 1.1 mycroft sc_print_addr(sc_link);
520 1.3 christos printf("timed out");
521 1.1 mycroft
522 1.1 mycroft s = splbio();
523 1.1 mycroft
524 1.1 mycroft if (mscp->flags & MSCP_ABORT) {
525 1.1 mycroft /* abort timed out */
526 1.3 christos printf(" AGAIN\n");
527 1.1 mycroft /* XXX Must reset! */
528 1.1 mycroft } else {
529 1.1 mycroft /* abort the operation that has timed out */
530 1.3 christos printf("\n");
531 1.1 mycroft mscp->xs->error = XS_TIMEOUT;
532 1.1 mycroft mscp->timeout = UHA_ABORT_TIMEOUT;
533 1.1 mycroft mscp->flags |= MSCP_ABORT;
534 1.1 mycroft (sc->start_mbox)(sc, mscp);
535 1.1 mycroft }
536 1.1 mycroft
537 1.1 mycroft splx(s);
538 1.1 mycroft }
539