isp_sbus.c revision 1.14.2.4 1 /* $NetBSD: isp_sbus.c,v 1.14.2.4 2001/03/12 13:31:23 bouyer Exp $ */
2 /*
3 * This driver, which is contained in NetBSD in the files:
4 *
5 * sys/dev/ic/isp.c
6 * sys/dev/ic/isp_inline.h
7 * sys/dev/ic/isp_netbsd.c
8 * sys/dev/ic/isp_netbsd.h
9 * sys/dev/ic/isp_target.c
10 * sys/dev/ic/isp_target.h
11 * sys/dev/ic/isp_tpublic.h
12 * sys/dev/ic/ispmbox.h
13 * sys/dev/ic/ispreg.h
14 * sys/dev/ic/ispvar.h
15 * sys/microcode/isp/asm_sbus.h
16 * sys/microcode/isp/asm_1040.h
17 * sys/microcode/isp/asm_1080.h
18 * sys/microcode/isp/asm_12160.h
19 * sys/microcode/isp/asm_2100.h
20 * sys/microcode/isp/asm_2200.h
21 * sys/pci/isp_pci.c
22 * sys/sbus/isp_sbus.c
23 *
24 * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
25 * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
26 * Linux versions. This tends to be an interesting maintenance problem.
27 *
28 * Please coordinate with Matthew Jacob on changes you wish to make here.
29 */
30 /*
31 * SBus specific probe and attach routines for Qlogic ISP SCSI adapters.
32 *
33 * Copyright (c) 1997, 2001 by Matthew Jacob
34 * NASA AMES Research Center
35 * All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice immediately at the beginning of the file, without modification,
42 * this list of conditions, and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
51 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 */
60
61 #include <sys/param.h>
62 #include <sys/systm.h>
63 #include <sys/device.h>
64 #include <sys/kernel.h>
65 #include <sys/malloc.h>
66 #include <sys/queue.h>
67
68 #include <machine/bus.h>
69 #include <machine/intr.h>
70 #include <machine/autoconf.h>
71
72 #include <dev/ic/isp_netbsd.h>
73 #include <dev/microcode/isp/asm_sbus.h>
74 #include <dev/sbus/sbusvar.h>
75 #include <sys/reboot.h>
76
77 /*
78 * Gross! But there's no way around this until sparc64 iommu.c is fixed.
79 */
80 #if _MACHINE == sparc64
81 #define LMAP_FLAGS BUS_DMA_NOWAIT|BUS_DMA_COHERENT
82 #else
83 #define LMAP_FLAGS BUS_DMA_NOWAIT
84 #endif
85
86 static int isp_sbus_intr __P((void *));
87 static u_int16_t isp_sbus_rd_reg __P((struct ispsoftc *, int));
88 static void isp_sbus_wr_reg __P((struct ispsoftc *, int, u_int16_t));
89 static int isp_sbus_mbxdma __P((struct ispsoftc *));
90 static int isp_sbus_dmasetup __P((struct ispsoftc *, struct scsipi_xfer *,
91 ispreq_t *, u_int16_t *, u_int16_t));
92 static void isp_sbus_dmateardown __P((struct ispsoftc *, struct scsipi_xfer *,
93 u_int32_t));
94
95 #ifndef ISP_1000_RISC_CODE
96 #define ISP_1000_RISC_CODE NULL
97 #endif
98
99 static struct ispmdvec mdvec = {
100 isp_sbus_rd_reg,
101 isp_sbus_wr_reg,
102 isp_sbus_mbxdma,
103 isp_sbus_dmasetup,
104 isp_sbus_dmateardown,
105 NULL,
106 NULL,
107 NULL,
108 ISP_1000_RISC_CODE
109 };
110
111 struct isp_sbussoftc {
112 struct ispsoftc sbus_isp;
113 struct sbusdev sbus_sd;
114 sdparam sbus_dev;
115 bus_space_tag_t sbus_bustag;
116 bus_dma_tag_t sbus_dmatag;
117 bus_space_handle_t sbus_reg;
118 int sbus_node;
119 int sbus_pri;
120 struct ispmdvec sbus_mdvec;
121 bus_dmamap_t *sbus_dmamap;
122 bus_dmamap_t sbus_rquest_dmamap;
123 bus_dmamap_t sbus_result_dmamap;
124 int16_t sbus_poff[_NREG_BLKS];
125 };
126
127
128 static int isp_match __P((struct device *, struct cfdata *, void *));
129 static void isp_sbus_attach __P((struct device *, struct device *, void *));
130 struct cfattach isp_sbus_ca = {
131 sizeof (struct isp_sbussoftc), isp_match, isp_sbus_attach
132 };
133
134 static int
135 isp_match(parent, cf, aux)
136 struct device *parent;
137 struct cfdata *cf;
138 void *aux;
139 {
140 int rv;
141 #ifdef DEBUG
142 static int oneshot = 1;
143 #endif
144 struct sbus_attach_args *sa = aux;
145
146 rv = (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 ||
147 strcmp("PTI,ptisp", sa->sa_name) == 0 ||
148 strcmp("ptisp", sa->sa_name) == 0 ||
149 strcmp("SUNW,isp", sa->sa_name) == 0 ||
150 strcmp("QLGC,isp", sa->sa_name) == 0);
151 #ifdef DEBUG
152 if (rv && oneshot) {
153 oneshot = 0;
154 printf("Qlogic ISP Driver, NetBSD (sbus) Platform Version "
155 "%d.%d Core Version %d.%d\n",
156 ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR,
157 ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR);
158 }
159 #endif
160 return (rv);
161 }
162
163
164 static void
165 isp_sbus_attach(parent, self, aux)
166 struct device *parent, *self;
167 void *aux;
168 {
169 int freq, ispburst, sbusburst;
170 struct sbus_attach_args *sa = aux;
171 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) self;
172 struct ispsoftc *isp = &sbc->sbus_isp;
173
174 printf(" for %s\n", sa->sa_name);
175
176 sbc->sbus_bustag = sa->sa_bustag;
177 sbc->sbus_dmatag = sa->sa_dmatag;
178 if (sa->sa_nintr != 0)
179 sbc->sbus_pri = sa->sa_pri;
180 sbc->sbus_mdvec = mdvec;
181
182 if (sa->sa_npromvaddrs != 0) {
183 sbc->sbus_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
184 } else {
185 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, sa->sa_offset,
186 sa->sa_size, BUS_SPACE_MAP_LINEAR, 0,
187 &sbc->sbus_reg) != 0) {
188 printf("%s: cannot map registers\n", self->dv_xname);
189 return;
190 }
191 }
192 sbc->sbus_node = sa->sa_node;
193
194 freq = getpropint(sa->sa_node, "clock-frequency", 0);
195 if (freq) {
196 /*
197 * Convert from HZ to MHz, rounding up.
198 */
199 freq = (freq + 500000)/1000000;
200 #if 0
201 printf("%s: %d MHz\n", self->dv_xname, freq);
202 #endif
203 }
204 sbc->sbus_mdvec.dv_clock = freq;
205
206 /*
207 * Now figure out what the proper burst sizes, etc., to use.
208 * Unfortunately, there is no ddi_dma_burstsizes here which
209 * walks up the tree finding the limiting burst size node (if
210 * any).
211 */
212 sbusburst = ((struct sbus_softc *)parent)->sc_burst;
213 if (sbusburst == 0)
214 sbusburst = SBUS_BURST_32 - 1;
215 ispburst = getpropint(sa->sa_node, "burst-sizes", -1);
216 if (ispburst == -1) {
217 ispburst = sbusburst;
218 }
219 ispburst &= sbusburst;
220 ispburst &= ~(1 << 7);
221 ispburst &= ~(1 << 6);
222 sbc->sbus_mdvec.dv_conf1 = 0;
223 if (ispburst & (1 << 5)) {
224 sbc->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_32;
225 } else if (ispburst & (1 << 4)) {
226 sbc->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_16;
227 } else if (ispburst & (1 << 3)) {
228 sbc->sbus_mdvec.dv_conf1 =
229 BIU_SBUS_CONF1_BURST8 | BIU_SBUS_CONF1_FIFO_8;
230 }
231 if (sbc->sbus_mdvec.dv_conf1) {
232 sbc->sbus_mdvec.dv_conf1 |= BIU_BURST_ENABLE;
233 }
234
235 /*
236 * Some early versions of the PTI SBus adapter
237 * would fail in trying to download (via poking)
238 * FW. We give up on them.
239 */
240 if (strcmp("PTI,ptisp", sa->sa_name) == 0 ||
241 strcmp("ptisp", sa->sa_name) == 0) {
242 sbc->sbus_mdvec.dv_ispfw = NULL;
243 }
244
245 isp->isp_mdvec = &sbc->sbus_mdvec;
246 isp->isp_bustype = ISP_BT_SBUS;
247 isp->isp_type = ISP_HA_SCSI_UNKNOWN;
248 isp->isp_param = &sbc->sbus_dev;
249 bzero(isp->isp_param, sizeof (sdparam));
250
251 sbc->sbus_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF;
252 sbc->sbus_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = SBUS_MBOX_REGS_OFF;
253 sbc->sbus_poff[SXP_BLOCK >> _BLK_REG_SHFT] = SBUS_SXP_REGS_OFF;
254 sbc->sbus_poff[RISC_BLOCK >> _BLK_REG_SHFT] = SBUS_RISC_REGS_OFF;
255 sbc->sbus_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF;
256
257 /* Establish interrupt channel */
258 bus_intr_establish(sbc->sbus_bustag, sbc->sbus_pri, IPL_BIO, 0,
259 isp_sbus_intr, sbc);
260 sbus_establish(&sbc->sbus_sd, &sbc->sbus_isp.isp_osinfo._dev);
261
262 /*
263 * Set up logging levels.
264 */
265 #ifdef ISP_LOGDEFAULT
266 isp->isp_dblev = ISP_LOGDEFAULT;
267 #else
268 isp->isp_dblev = ISP_LOGWARN|ISP_LOGERR;
269 if (bootverbose)
270 isp->isp_dblev |= ISP_LOGCONFIG|ISP_LOGINFO;
271 #ifdef SCSIDEBUG
272 isp->isp_dblev |= ISP_LOGDEBUG1|ISP_LOGDEBUG2;
273 #endif
274 #ifdef DEBUG
275 isp->isp_dblev |= ISP_LOGDEBUG0;
276 #endif
277 #endif
278
279 isp->isp_confopts = self->dv_cfdata->cf_flags;
280 isp->isp_role = ISP_DEFAULT_ROLES;
281
282 /*
283 * There's no tool on sparc to set NVRAM for ISPs, so ignore it.
284 */
285 isp->isp_confopts |= ISP_CFG_NONVRAM;
286 ISP_LOCK(isp);
287 isp->isp_osinfo.no_mbox_ints = 1;
288 isp_reset(isp);
289 if (isp->isp_state != ISP_RESETSTATE) {
290 ISP_UNLOCK(isp);
291 return;
292 }
293 ENABLE_INTS(isp);
294 isp_init(isp);
295 if (isp->isp_state != ISP_INITSTATE) {
296 isp_uninit(isp);
297 ISP_UNLOCK(isp);
298 return;
299 }
300
301 /*
302 * do generic attach.
303 */
304 ISP_UNLOCK(isp);
305 isp_attach(isp);
306 if (isp->isp_state != ISP_RUNSTATE) {
307 ISP_LOCK(isp);
308 isp_uninit(isp);
309 ISP_UNLOCK(isp);
310 }
311 }
312
313 static int
314 isp_sbus_intr(arg)
315 void *arg;
316 {
317 int rv;
318 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *)arg;
319 bus_dmamap_sync(sbc->sbus_dmatag, sbc->sbus_result_dmamap, 0,
320 sbc->sbus_result_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
321 sbc->sbus_isp.isp_osinfo.onintstack = 1;
322 rv = isp_intr(arg);
323 sbc->sbus_isp.isp_osinfo.onintstack = 0;
324 return (rv);
325 }
326
327 static u_int16_t
328 isp_sbus_rd_reg(isp, regoff)
329 struct ispsoftc *isp;
330 int regoff;
331 {
332 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
333 int offset = sbc->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
334 offset += (regoff & 0xff);
335 return (bus_space_read_2(sbc->sbus_bustag, sbc->sbus_reg, offset));
336 }
337
338 static void
339 isp_sbus_wr_reg(isp, regoff, val)
340 struct ispsoftc *isp;
341 int regoff;
342 u_int16_t val;
343 {
344 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
345 int offset = sbc->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
346 offset += (regoff & 0xff);
347 bus_space_write_2(sbc->sbus_bustag, sbc->sbus_reg, offset, val);
348 }
349
350 static int
351 isp_sbus_mbxdma(isp)
352 struct ispsoftc *isp;
353 {
354 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
355 bus_dma_tag_t dmatag = sbc->sbus_dmatag;
356 bus_dma_segment_t reqseg, rspseg;
357 int reqrs, rsprs, i, progress;
358 size_t n;
359 bus_size_t len;
360
361 if (isp->isp_rquest_dma)
362 return (0);
363
364 n = sizeof (XS_T **) * isp->isp_maxcmds;
365 isp->isp_xflist = (XS_T **) malloc(n, M_DEVBUF, M_WAITOK);
366 if (isp->isp_xflist == NULL) {
367 isp_prt(isp, ISP_LOGERR, "cannot alloc xflist array");
368 return (1);
369 }
370 bzero(isp->isp_xflist, n);
371 n = sizeof (bus_dmamap_t) * isp->isp_maxcmds;
372 sbc->sbus_dmamap = (bus_dmamap_t *) malloc(n, M_DEVBUF, M_WAITOK);
373 if (sbc->sbus_dmamap == NULL) {
374 free(isp->isp_xflist, M_DEVBUF);
375 isp->isp_xflist = NULL;
376 isp_prt(isp, ISP_LOGERR, "cannot alloc dmamap array");
377 return (1);
378 }
379 for (i = 0; i < isp->isp_maxcmds; i++) {
380 /* Allocate a DMA handle */
381 if (bus_dmamap_create(dmatag, MAXPHYS, 1, MAXPHYS, 0,
382 BUS_DMA_NOWAIT, &sbc->sbus_dmamap[i]) != 0) {
383 isp_prt(isp, ISP_LOGERR, "cmd DMA maps create error");
384 break;
385 }
386 }
387 if (i < isp->isp_maxcmds) {
388 while (--i >= 0) {
389 bus_dmamap_destroy(dmatag, sbc->sbus_dmamap[i]);
390 }
391 free(isp->isp_xflist, M_DEVBUF);
392 free(sbc->sbus_dmamap, M_DEVBUF);
393 isp->isp_xflist = NULL;
394 sbc->sbus_dmamap = NULL;
395 return (1);
396 }
397
398 /*
399 * Allocate and map the request and response queues
400 */
401 progress = 0;
402 len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));
403 if (bus_dmamap_create(dmatag, len, 1, len, 0, BUS_DMA_NOWAIT,
404 &sbc->sbus_rquest_dmamap) != 0) {
405 goto dmafail;
406 }
407 progress++;
408 if (bus_dmamem_alloc(dmatag, len, 0, 0, &reqseg, 1, &reqrs,
409 BUS_DMA_NOWAIT)) {
410 goto dmafail;
411 }
412 isp->isp_rquest_dma = sbc->sbus_rquest_dmamap->dm_segs[0].ds_addr;
413 progress++;
414 if (bus_dmamem_map(dmatag, &reqseg, reqrs, len,
415 (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
416 goto dmafail;
417 }
418 progress++;
419 if (bus_dmamap_load(dmatag, sbc->sbus_rquest_dmamap,
420 isp->isp_rquest, len, NULL, LMAP_FLAGS) != 0) {
421 goto dmafail;
422 }
423 progress++;
424
425 len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp));
426 if (bus_dmamap_create(dmatag, len, 1, len, 0, BUS_DMA_NOWAIT,
427 &sbc->sbus_result_dmamap) != 0) {
428 goto dmafail;
429 }
430 progress++;
431 if (bus_dmamem_alloc(dmatag, len, 0, 0, &rspseg, 1, &rsprs,
432 BUS_DMA_NOWAIT)) {
433 goto dmafail;
434 }
435 isp->isp_result_dma = sbc->sbus_result_dmamap->dm_segs[0].ds_addr;
436 progress++;
437 if (bus_dmamem_map(dmatag, &rspseg, rsprs, len,
438 (caddr_t *)&isp->isp_result, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
439 goto dmafail;
440 }
441 progress++;
442 if (bus_dmamap_load(dmatag, sbc->sbus_result_dmamap,
443 isp->isp_result, len, NULL, LMAP_FLAGS) != 0) {
444 goto dmafail;
445 }
446 progress++;
447 return (0);
448
449 dmafail:
450 isp_prt(isp, ISP_LOGERR, "Mailbox DMA Setup Failure");
451
452 if (progress >= 8) {
453 bus_dmamap_unload(dmatag, sbc->sbus_result_dmamap);
454 }
455 if (progress >= 7) {
456 bus_dmamem_unmap(dmatag,
457 isp->isp_result, ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)));
458 }
459 if (progress >= 6) {
460 bus_dmamem_free(dmatag, &rspseg, rsprs);
461 }
462 if (progress >= 5) {
463 bus_dmamap_destroy(dmatag, sbc->sbus_result_dmamap);
464 }
465
466 if (progress >= 4) {
467 bus_dmamap_unload(dmatag, sbc->sbus_rquest_dmamap);
468 }
469 if (progress >= 3) {
470 bus_dmamem_unmap(dmatag,
471 isp->isp_rquest, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
472
473 }
474 if (progress >= 2) {
475 bus_dmamem_free(dmatag, &reqseg, reqrs);
476 }
477 if (progress >= 1) {
478 bus_dmamap_destroy(dmatag, sbc->sbus_rquest_dmamap);
479 }
480
481 for (i = 0; i < isp->isp_maxcmds; i++) {
482 bus_dmamap_destroy(dmatag, sbc->sbus_dmamap[i]);
483 }
484 free(sbc->sbus_dmamap, M_DEVBUF);
485 free(isp->isp_xflist, M_DEVBUF);
486 isp->isp_xflist = NULL;
487 sbc->sbus_dmamap = NULL;
488 return (1);
489 }
490
491 /*
492 * Map a DMA request.
493 * We're guaranteed that rq->req_handle is a value from 1 to isp->isp_maxcmds.
494 */
495
496 static int
497 isp_sbus_dmasetup(isp, xs, rq, iptrp, optr)
498 struct ispsoftc *isp;
499 struct scsipi_xfer *xs;
500 ispreq_t *rq;
501 u_int16_t *iptrp;
502 u_int16_t optr;
503 {
504 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
505 bus_dmamap_t dmap;
506 ispcontreq_t *crq;
507 int cansleep = (xs->xs_control & XS_CTL_NOSLEEP) == 0;
508 int in = (xs->xs_control & XS_CTL_DATA_IN) != 0;
509
510 if (xs->datalen == 0) {
511 rq->req_seg_count = 1;
512 goto mbxsync;
513 }
514
515 dmap = sbc->sbus_dmamap[isp_handle_index(rq->req_handle)];
516 if (dmap->dm_nsegs != 0) {
517 panic("%s: dma map already allocated\n", isp->isp_name);
518 /* NOTREACHED */
519 }
520 if (bus_dmamap_load(sbc->sbus_dmatag, dmap, xs->data, xs->datalen,
521 NULL, (cansleep ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT) |
522 BUS_DMA_STREAMING) != 0) {
523 XS_SETERR(xs, HBA_BOTCH);
524 return (CMD_COMPLETE);
525 }
526
527 bus_dmamap_sync(sbc->sbus_dmatag, dmap, 0, xs->datalen,
528 in? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
529
530 if (in) {
531 rq->req_flags |= REQFLAG_DATA_IN;
532 } else {
533 rq->req_flags |= REQFLAG_DATA_OUT;
534 }
535
536 if (XS_CDBLEN(xs) > 12) {
537 crq = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, *iptrp);
538 *iptrp = ISP_NXT_QENTRY(*iptrp, RQUEST_QUEUE_LEN(isp));
539 if (*iptrp == optr) {
540 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow++");
541 bus_dmamap_unload(sbc->sbus_dmatag, dmap);
542 XS_SETERR(xs, HBA_BOTCH);
543 return (CMD_EAGAIN);
544 }
545 rq->req_seg_count = 2;
546 rq->req_dataseg[0].ds_count = 0;
547 rq->req_dataseg[0].ds_base = 0;
548 bzero((void *)crq, sizeof (*crq));
549 crq->req_header.rqs_entry_count = 1;
550 crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
551 crq->req_dataseg[0].ds_count = xs->datalen;
552 crq->req_dataseg[0].ds_base = dmap->dm_segs[0].ds_addr;
553 ISP_SBUSIFY_ISPHDR(isp, &crq->req_header)
554 } else {
555 rq->req_dataseg[0].ds_count = xs->datalen;
556 rq->req_dataseg[0].ds_base = dmap->dm_segs[0].ds_addr;
557 rq->req_seg_count = 1;
558 }
559
560 mbxsync:
561 ISP_SWIZZLE_REQUEST(isp, rq);
562 bus_dmamap_sync(sbc->sbus_dmatag, sbc->sbus_rquest_dmamap, 0,
563 sbc->sbus_rquest_dmamap->dm_mapsize, BUS_DMASYNC_PREWRITE);
564 return (CMD_QUEUED);
565 }
566
567 static void
568 isp_sbus_dmateardown(isp, xs, handle)
569 struct ispsoftc *isp;
570 struct scsipi_xfer *xs;
571 u_int32_t handle;
572 {
573 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
574 bus_dmamap_t dmap;
575
576 dmap = sbc->sbus_dmamap[isp_handle_index(handle)];
577
578 if (dmap->dm_nsegs == 0) {
579 panic("%s: dma map not already allocated\n", isp->isp_name);
580 /* NOTREACHED */
581 }
582 bus_dmamap_sync(sbc->sbus_dmatag, dmap, 0,
583 xs->datalen, (xs->xs_control & XS_CTL_DATA_IN)?
584 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
585 bus_dmamap_unload(sbc->sbus_dmatag, dmap);
586 }
587