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