isp_sbus.c revision 1.40.2.5 1 /* $NetBSD: isp_sbus.c,v 1.40.2.5 2001/10/08 20:11:26 nathanw 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 static int isp_sbus_intr(void *);
78 static int
79 isp_sbus_rd_isr(struct ispsoftc *, u_int16_t *, u_int16_t *, u_int16_t *);
80 static u_int16_t isp_sbus_rd_reg(struct ispsoftc *, int);
81 static void isp_sbus_wr_reg (struct ispsoftc *, int, u_int16_t);
82 static int isp_sbus_mbxdma(struct ispsoftc *);
83 static int isp_sbus_dmasetup(struct ispsoftc *, XS_T *, ispreq_t *, u_int16_t *,
84 u_int16_t);
85 static void isp_sbus_dmateardown(struct ispsoftc *, XS_T *, u_int16_t);
86
87 #ifndef ISP_1000_RISC_CODE
88 #define ISP_1000_RISC_CODE NULL
89 #endif
90
91 static struct ispmdvec mdvec = {
92 isp_sbus_rd_isr,
93 isp_sbus_rd_reg,
94 isp_sbus_wr_reg,
95 isp_sbus_mbxdma,
96 isp_sbus_dmasetup,
97 isp_sbus_dmateardown,
98 NULL,
99 NULL,
100 NULL,
101 ISP_1000_RISC_CODE
102 };
103
104 struct isp_sbussoftc {
105 struct ispsoftc sbus_isp;
106 struct sbusdev sbus_sd;
107 sdparam sbus_dev;
108 bus_space_tag_t sbus_bustag;
109 bus_dma_tag_t sbus_dmatag;
110 bus_space_handle_t sbus_reg;
111 int sbus_node;
112 int sbus_pri;
113 struct ispmdvec sbus_mdvec;
114 bus_dmamap_t *sbus_dmamap;
115 bus_dmamap_t sbus_rquest_dmamap;
116 bus_dmamap_t sbus_result_dmamap;
117 int16_t sbus_poff[_NREG_BLKS];
118 };
119
120
121 static int isp_match(struct device *, struct cfdata *, void *);
122 static void isp_sbus_attach(struct device *, struct device *, void *);
123 struct cfattach isp_sbus_ca = {
124 sizeof (struct isp_sbussoftc), isp_match, isp_sbus_attach
125 };
126
127 static int
128 isp_match(struct device *parent, struct cfdata *cf, void *aux)
129 {
130 int rv;
131 #ifdef DEBUG
132 static int oneshot = 1;
133 #endif
134 struct sbus_attach_args *sa = aux;
135
136 rv = (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 ||
137 strcmp("PTI,ptisp", sa->sa_name) == 0 ||
138 strcmp("ptisp", sa->sa_name) == 0 ||
139 strcmp("SUNW,isp", sa->sa_name) == 0 ||
140 strcmp("QLGC,isp", sa->sa_name) == 0);
141 #ifdef DEBUG
142 if (rv && oneshot) {
143 oneshot = 0;
144 printf("Qlogic ISP Driver, NetBSD (sbus) Platform Version "
145 "%d.%d Core Version %d.%d\n",
146 ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR,
147 ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR);
148 }
149 #endif
150 return (rv);
151 }
152
153
154 static void
155 isp_sbus_attach(struct device *parent, struct device *self, void *aux)
156 {
157 int freq, ispburst, sbusburst;
158 struct sbus_attach_args *sa = aux;
159 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) self;
160 struct ispsoftc *isp = &sbc->sbus_isp;
161
162 printf(" for %s\n", sa->sa_name);
163
164 sbc->sbus_bustag = sa->sa_bustag;
165 sbc->sbus_dmatag = sa->sa_dmatag;
166 if (sa->sa_nintr != 0)
167 sbc->sbus_pri = sa->sa_pri;
168 sbc->sbus_mdvec = mdvec;
169
170 if (sa->sa_npromvaddrs != 0) {
171 sbc->sbus_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
172 } else {
173 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, sa->sa_offset,
174 sa->sa_size, BUS_SPACE_MAP_LINEAR, 0,
175 &sbc->sbus_reg) != 0) {
176 printf("%s: cannot map registers\n", self->dv_xname);
177 return;
178 }
179 }
180 sbc->sbus_node = sa->sa_node;
181
182 freq = PROM_getpropint(sa->sa_node, "clock-frequency", 0);
183 if (freq) {
184 /*
185 * Convert from HZ to MHz, rounding up.
186 */
187 freq = (freq + 500000)/1000000;
188 #if 0
189 printf("%s: %d MHz\n", self->dv_xname, freq);
190 #endif
191 }
192 sbc->sbus_mdvec.dv_clock = freq;
193
194 /*
195 * Now figure out what the proper burst sizes, etc., to use.
196 * Unfortunately, there is no ddi_dma_burstsizes here which
197 * walks up the tree finding the limiting burst size node (if
198 * any).
199 */
200 sbusburst = ((struct sbus_softc *)parent)->sc_burst;
201 if (sbusburst == 0)
202 sbusburst = SBUS_BURST_32 - 1;
203 ispburst = PROM_getpropint(sa->sa_node, "burst-sizes", -1);
204 if (ispburst == -1) {
205 ispburst = sbusburst;
206 }
207 ispburst &= sbusburst;
208 ispburst &= ~(1 << 7);
209 ispburst &= ~(1 << 6);
210 sbc->sbus_mdvec.dv_conf1 = 0;
211 if (ispburst & (1 << 5)) {
212 sbc->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_32;
213 } else if (ispburst & (1 << 4)) {
214 sbc->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_16;
215 } else if (ispburst & (1 << 3)) {
216 sbc->sbus_mdvec.dv_conf1 =
217 BIU_SBUS_CONF1_BURST8 | BIU_SBUS_CONF1_FIFO_8;
218 }
219 if (sbc->sbus_mdvec.dv_conf1) {
220 sbc->sbus_mdvec.dv_conf1 |= BIU_BURST_ENABLE;
221 }
222
223 /*
224 * Some early versions of the PTI SBus adapter
225 * would fail in trying to download (via poking)
226 * FW. We give up on them.
227 */
228 if (strcmp("PTI,ptisp", sa->sa_name) == 0 ||
229 strcmp("ptisp", sa->sa_name) == 0) {
230 sbc->sbus_mdvec.dv_ispfw = NULL;
231 }
232
233 isp->isp_mdvec = &sbc->sbus_mdvec;
234 isp->isp_bustype = ISP_BT_SBUS;
235 isp->isp_type = ISP_HA_SCSI_UNKNOWN;
236 isp->isp_param = &sbc->sbus_dev;
237 bzero(isp->isp_param, sizeof (sdparam));
238
239 sbc->sbus_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF;
240 sbc->sbus_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = SBUS_MBOX_REGS_OFF;
241 sbc->sbus_poff[SXP_BLOCK >> _BLK_REG_SHFT] = SBUS_SXP_REGS_OFF;
242 sbc->sbus_poff[RISC_BLOCK >> _BLK_REG_SHFT] = SBUS_RISC_REGS_OFF;
243 sbc->sbus_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF;
244
245 /* Establish interrupt channel */
246 bus_intr_establish(sbc->sbus_bustag, sbc->sbus_pri, IPL_BIO, 0,
247 isp_sbus_intr, sbc);
248 sbus_establish(&sbc->sbus_sd, &sbc->sbus_isp.isp_osinfo._dev);
249
250 /*
251 * Set up logging levels.
252 */
253 #ifdef ISP_LOGDEFAULT
254 isp->isp_dblev = ISP_LOGDEFAULT;
255 #else
256 isp->isp_dblev = ISP_LOGWARN|ISP_LOGERR;
257 if (bootverbose)
258 isp->isp_dblev |= ISP_LOGCONFIG|ISP_LOGINFO;
259 #ifdef SCSIDEBUG
260 isp->isp_dblev |= ISP_LOGDEBUG1|ISP_LOGDEBUG2;
261 #endif
262 #ifdef DEBUG
263 isp->isp_dblev |= ISP_LOGDEBUG0;
264 #endif
265 #endif
266
267 isp->isp_confopts = self->dv_cfdata->cf_flags;
268 isp->isp_role = ISP_DEFAULT_ROLES;
269
270 /*
271 * There's no tool on sparc to set NVRAM for ISPs, so ignore it.
272 */
273 isp->isp_confopts |= ISP_CFG_NONVRAM;
274 ISP_LOCK(isp);
275 isp->isp_osinfo.no_mbox_ints = 1;
276 isp_reset(isp);
277 if (isp->isp_state != ISP_RESETSTATE) {
278 ISP_UNLOCK(isp);
279 return;
280 }
281 ENABLE_INTS(isp);
282 isp_init(isp);
283 if (isp->isp_state != ISP_INITSTATE) {
284 isp_uninit(isp);
285 ISP_UNLOCK(isp);
286 return;
287 }
288
289 /*
290 * do generic attach.
291 */
292 ISP_UNLOCK(isp);
293 isp_attach(isp);
294 if (isp->isp_state != ISP_RUNSTATE) {
295 ISP_LOCK(isp);
296 isp_uninit(isp);
297 ISP_UNLOCK(isp);
298 }
299 }
300
301 static int
302 isp_sbus_intr(void *arg)
303 {
304 u_int16_t isr, sema, mbox;
305 struct ispsoftc *isp = arg;
306 struct isp_sbussoftc *sbc = arg;
307
308 bus_dmamap_sync(sbc->sbus_dmatag, sbc->sbus_result_dmamap, 0,
309 sbc->sbus_result_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
310 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
311 sbc->sbus_isp.isp_osinfo.onintstack = 1;
312 isp_intr(isp, isr, sema, mbox);
313 sbc->sbus_isp.isp_osinfo.onintstack = 0;
314 return (1);
315 } else {
316 return (0);
317 }
318 }
319
320 #define IspVirt2Off(a, x) \
321 (((struct isp_sbussoftc *)a)->sbus_poff[((x) & _BLK_REG_MASK) >> \
322 _BLK_REG_SHFT] + ((x) & 0xff))
323
324 #define BXR2(sbc, off) \
325 bus_space_read_2(sbc->sbus_bustag, sbc->sbus_reg, off)
326
327 static int
328 isp_sbus_rd_isr(struct ispsoftc *isp, u_int16_t *isrp,
329 u_int16_t *semap, u_int16_t *mbp)
330 {
331 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
332 u_int16_t isr, sema;
333
334 isr = BXR2(sbc, IspVirt2Off(isp, BIU_ISR));
335 sema = BXR2(sbc, IspVirt2Off(isp, BIU_SEMA));
336 isp_prt(isp, ISP_LOGDEBUG3, "ISR 0x%x SEMA 0x%x", isr, sema);
337 isr &= INT_PENDING_MASK(isp);
338 sema &= BIU_SEMA_LOCK;
339 if (isr == 0 && sema == 0) {
340 return (0);
341 }
342 *isrp = isr;
343 if ((*semap = sema) != 0) {
344 *mbp = BXR2(sbc, IspVirt2Off(isp, OUTMAILBOX0));
345 }
346 return (1);
347 }
348
349 static u_int16_t
350 isp_sbus_rd_reg(struct ispsoftc *isp, int regoff)
351 {
352 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
353 int offset = sbc->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
354 offset += (regoff & 0xff);
355 return (bus_space_read_2(sbc->sbus_bustag, sbc->sbus_reg, offset));
356 }
357
358 static void
359 isp_sbus_wr_reg(struct ispsoftc *isp, int regoff, u_int16_t val)
360 {
361 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
362 int offset = sbc->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
363 offset += (regoff & 0xff);
364 bus_space_write_2(sbc->sbus_bustag, sbc->sbus_reg, offset, val);
365 }
366
367 static int
368 isp_sbus_mbxdma(struct ispsoftc *isp)
369 {
370 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
371 bus_dma_tag_t dmatag = sbc->sbus_dmatag;
372 bus_dma_segment_t reqseg, rspseg;
373 int reqrs, rsprs, i, progress;
374 size_t n;
375 bus_size_t len;
376
377 if (isp->isp_rquest_dma)
378 return (0);
379
380 n = isp->isp_maxcmds * sizeof (XS_T *);
381 isp->isp_xflist = (XS_T **) malloc(n, M_DEVBUF, M_WAITOK);
382 if (isp->isp_xflist == NULL) {
383 isp_prt(isp, ISP_LOGERR, "cannot alloc xflist array");
384 return (1);
385 }
386 bzero(isp->isp_xflist, n);
387 n = sizeof (bus_dmamap_t) * isp->isp_maxcmds;
388 sbc->sbus_dmamap = (bus_dmamap_t *) malloc(n, M_DEVBUF, M_WAITOK);
389 if (sbc->sbus_dmamap == NULL) {
390 free(isp->isp_xflist, M_DEVBUF);
391 isp->isp_xflist = NULL;
392 isp_prt(isp, ISP_LOGERR, "cannot alloc dmamap array");
393 return (1);
394 }
395 for (i = 0; i < isp->isp_maxcmds; i++) {
396 /* Allocate a DMA handle */
397 if (bus_dmamap_create(dmatag, MAXPHYS, 1, MAXPHYS, 0,
398 BUS_DMA_NOWAIT, &sbc->sbus_dmamap[i]) != 0) {
399 isp_prt(isp, ISP_LOGERR, "cmd DMA maps create error");
400 break;
401 }
402 }
403 if (i < isp->isp_maxcmds) {
404 while (--i >= 0) {
405 bus_dmamap_destroy(dmatag, sbc->sbus_dmamap[i]);
406 }
407 free(isp->isp_xflist, M_DEVBUF);
408 free(sbc->sbus_dmamap, M_DEVBUF);
409 isp->isp_xflist = NULL;
410 sbc->sbus_dmamap = NULL;
411 return (1);
412 }
413
414 /*
415 * Allocate and map the request and response queues
416 */
417 progress = 0;
418 len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));
419 if (bus_dmamem_alloc(dmatag, len, 0, 0, &reqseg, 1, &reqrs,
420 BUS_DMA_NOWAIT)) {
421 goto dmafail;
422 }
423 progress++;
424 if (bus_dmamem_map(dmatag, &reqseg, reqrs, len,
425 (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
426 goto dmafail;
427 }
428 progress++;
429 if (bus_dmamap_create(dmatag, len, 1, len, 0, BUS_DMA_NOWAIT,
430 &sbc->sbus_rquest_dmamap) != 0) {
431 goto dmafail;
432 }
433 progress++;
434 if (bus_dmamap_load(dmatag, sbc->sbus_rquest_dmamap,
435 isp->isp_rquest, len, NULL, BUS_DMA_NOWAIT) != 0) {
436 goto dmafail;
437 }
438 progress++;
439 isp->isp_rquest_dma = sbc->sbus_rquest_dmamap->dm_segs[0].ds_addr;
440
441 len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp));
442 if (bus_dmamem_alloc(dmatag, len, 0, 0, &rspseg, 1, &rsprs,
443 BUS_DMA_NOWAIT)) {
444 goto dmafail;
445 }
446 progress++;
447 if (bus_dmamem_map(dmatag, &rspseg, rsprs, len,
448 (caddr_t *)&isp->isp_result, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
449 goto dmafail;
450 }
451 progress++;
452 if (bus_dmamap_create(dmatag, len, 1, len, 0, BUS_DMA_NOWAIT,
453 &sbc->sbus_result_dmamap) != 0) {
454 goto dmafail;
455 }
456 progress++;
457 if (bus_dmamap_load(dmatag, sbc->sbus_result_dmamap,
458 isp->isp_result, len, NULL, BUS_DMA_NOWAIT) != 0) {
459 goto dmafail;
460 }
461 isp->isp_result_dma = sbc->sbus_result_dmamap->dm_segs[0].ds_addr;
462
463 return (0);
464
465 dmafail:
466 isp_prt(isp, ISP_LOGERR, "Mailbox DMA Setup Failure");
467
468 if (progress >= 8) {
469 bus_dmamap_unload(dmatag, sbc->sbus_result_dmamap);
470 }
471 if (progress >= 7) {
472 bus_dmamap_destroy(dmatag, sbc->sbus_result_dmamap);
473 }
474 if (progress >= 6) {
475 bus_dmamem_unmap(dmatag,
476 isp->isp_result, ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)));
477 }
478 if (progress >= 5) {
479 bus_dmamem_free(dmatag, &rspseg, rsprs);
480 }
481
482 if (progress >= 4) {
483 bus_dmamap_unload(dmatag, sbc->sbus_rquest_dmamap);
484 }
485 if (progress >= 3) {
486 bus_dmamap_destroy(dmatag, sbc->sbus_rquest_dmamap);
487 }
488 if (progress >= 2) {
489 bus_dmamem_unmap(dmatag,
490 isp->isp_rquest, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
491 }
492 if (progress >= 1) {
493 bus_dmamem_free(dmatag, &reqseg, reqrs);
494 }
495
496 for (i = 0; i < isp->isp_maxcmds; i++) {
497 bus_dmamap_destroy(dmatag, sbc->sbus_dmamap[i]);
498 }
499 free(sbc->sbus_dmamap, M_DEVBUF);
500 free(isp->isp_xflist, M_DEVBUF);
501 isp->isp_xflist = NULL;
502 sbc->sbus_dmamap = NULL;
503 return (1);
504 }
505
506 /*
507 * Map a DMA request.
508 * We're guaranteed that rq->req_handle is a value from 1 to isp->isp_maxcmds.
509 */
510
511 static int
512 isp_sbus_dmasetup(struct ispsoftc *isp, XS_T *xs, ispreq_t *rq,
513 u_int16_t *iptrp, u_int16_t optr)
514 {
515 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
516 bus_dmamap_t dmap;
517 ispcontreq_t *crq;
518 int cansleep = (xs->xs_control & XS_CTL_NOSLEEP) == 0;
519 int in = (xs->xs_control & XS_CTL_DATA_IN) != 0;
520
521 if (xs->datalen == 0) {
522 rq->req_seg_count = 1;
523 goto mbxsync;
524 }
525
526 dmap = sbc->sbus_dmamap[isp_handle_index(rq->req_handle)];
527 if (dmap->dm_nsegs != 0) {
528 panic("%s: dma map already allocated\n", isp->isp_name);
529 /* NOTREACHED */
530 }
531 if (bus_dmamap_load(sbc->sbus_dmatag, dmap, xs->data, xs->datalen,
532 NULL, (cansleep ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT) |
533 BUS_DMA_STREAMING) != 0) {
534 XS_SETERR(xs, HBA_BOTCH);
535 return (CMD_COMPLETE);
536 }
537
538 bus_dmamap_sync(sbc->sbus_dmatag, dmap, 0, xs->datalen,
539 in? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
540
541 if (in) {
542 rq->req_flags |= REQFLAG_DATA_IN;
543 } else {
544 rq->req_flags |= REQFLAG_DATA_OUT;
545 }
546
547 if (XS_CDBLEN(xs) > 12) {
548 crq = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, *iptrp);
549 *iptrp = ISP_NXT_QENTRY(*iptrp, RQUEST_QUEUE_LEN(isp));
550 if (*iptrp == optr) {
551 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow++");
552 bus_dmamap_unload(sbc->sbus_dmatag, dmap);
553 XS_SETERR(xs, HBA_BOTCH);
554 return (CMD_EAGAIN);
555 }
556 rq->req_seg_count = 2;
557 rq->req_dataseg[0].ds_count = 0;
558 rq->req_dataseg[0].ds_base = 0;
559 bzero((void *)crq, sizeof (*crq));
560 crq->req_header.rqs_entry_count = 1;
561 crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
562 crq->req_dataseg[0].ds_count = xs->datalen;
563 crq->req_dataseg[0].ds_base = dmap->dm_segs[0].ds_addr;
564 ISP_SBUSIFY_ISPHDR(isp, &crq->req_header)
565 } else {
566 rq->req_dataseg[0].ds_count = xs->datalen;
567 rq->req_dataseg[0].ds_base = dmap->dm_segs[0].ds_addr;
568 rq->req_seg_count = 1;
569 }
570
571 mbxsync:
572 ISP_SWIZZLE_REQUEST(isp, rq);
573 bus_dmamap_sync(sbc->sbus_dmatag, sbc->sbus_rquest_dmamap, 0,
574 sbc->sbus_rquest_dmamap->dm_mapsize, BUS_DMASYNC_PREWRITE);
575 return (CMD_QUEUED);
576 }
577
578 static void
579 isp_sbus_dmateardown(struct ispsoftc *isp, XS_T *xs, u_int16_t handle)
580 {
581 struct isp_sbussoftc *sbc = (struct isp_sbussoftc *) isp;
582 bus_dmamap_t dmap;
583
584 dmap = sbc->sbus_dmamap[isp_handle_index(handle)];
585
586 if (dmap->dm_nsegs == 0) {
587 panic("%s: dma map not already allocated\n", isp->isp_name);
588 /* NOTREACHED */
589 }
590 bus_dmamap_sync(sbc->sbus_dmatag, dmap, 0,
591 xs->datalen, (xs->xs_control & XS_CTL_DATA_IN)?
592 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
593 bus_dmamap_unload(sbc->sbus_dmatag, dmap);
594 }
595