icp.c revision 1.2.2.5 1 1.2.2.5 thorpej /* $NetBSD: icp.c,v 1.2.2.5 2003/01/03 17:07:40 thorpej Exp $ */
2 1.2.2.2 nathanw
3 1.2.2.2 nathanw /*-
4 1.2.2.2 nathanw * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.2.2.2 nathanw * All rights reserved.
6 1.2.2.2 nathanw *
7 1.2.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 nathanw * by Andrew Doran.
9 1.2.2.2 nathanw *
10 1.2.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.2.2.2 nathanw * are met:
13 1.2.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.2.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 nathanw * must display the following acknowledgement:
20 1.2.2.2 nathanw * This product includes software developed by the NetBSD
21 1.2.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.2.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.2.2.2 nathanw * from this software without specific prior written permission.
25 1.2.2.2 nathanw *
26 1.2.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 nathanw */
38 1.2.2.2 nathanw
39 1.2.2.2 nathanw /*
40 1.2.2.2 nathanw * Copyright (c) 1999, 2000 Niklas Hallqvist. All rights reserved.
41 1.2.2.2 nathanw *
42 1.2.2.2 nathanw * Redistribution and use in source and binary forms, with or without
43 1.2.2.2 nathanw * modification, are permitted provided that the following conditions
44 1.2.2.2 nathanw * are met:
45 1.2.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
46 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer.
47 1.2.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
48 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
49 1.2.2.2 nathanw * documentation and/or other materials provided with the distribution.
50 1.2.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
51 1.2.2.2 nathanw * must display the following acknowledgement:
52 1.2.2.2 nathanw * This product includes software developed by Niklas Hallqvist.
53 1.2.2.2 nathanw * 4. The name of the author may not be used to endorse or promote products
54 1.2.2.2 nathanw * derived from this software without specific prior written permission.
55 1.2.2.2 nathanw *
56 1.2.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 1.2.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 1.2.2.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 1.2.2.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 1.2.2.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 1.2.2.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 1.2.2.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 1.2.2.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 1.2.2.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 1.2.2.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 1.2.2.2 nathanw *
67 1.2.2.2 nathanw * from OpenBSD: gdt_common.c,v 1.12 2001/07/04 06:43:18 niklas Exp
68 1.2.2.2 nathanw */
69 1.2.2.2 nathanw
70 1.2.2.2 nathanw /*
71 1.2.2.2 nathanw * This driver would not have written if it was not for the hardware donations
72 1.2.2.2 nathanw * from both ICP-Vortex and ko.neT. I want to thank them for their support.
73 1.2.2.2 nathanw *
74 1.2.2.2 nathanw * Re-worked for NetBSD by Andrew Doran. Test hardware kindly supplied by
75 1.2.2.2 nathanw * Intel.
76 1.2.2.2 nathanw */
77 1.2.2.2 nathanw
78 1.2.2.2 nathanw #include <sys/cdefs.h>
79 1.2.2.5 thorpej __KERNEL_RCSID(0, "$NetBSD: icp.c,v 1.2.2.5 2003/01/03 17:07:40 thorpej Exp $");
80 1.2.2.2 nathanw
81 1.2.2.2 nathanw #include <sys/param.h>
82 1.2.2.2 nathanw #include <sys/systm.h>
83 1.2.2.2 nathanw #include <sys/kernel.h>
84 1.2.2.2 nathanw #include <sys/device.h>
85 1.2.2.2 nathanw #include <sys/queue.h>
86 1.2.2.2 nathanw #include <sys/proc.h>
87 1.2.2.2 nathanw #include <sys/buf.h>
88 1.2.2.2 nathanw #include <sys/endian.h>
89 1.2.2.2 nathanw #include <sys/malloc.h>
90 1.2.2.2 nathanw #include <sys/disk.h>
91 1.2.2.2 nathanw
92 1.2.2.2 nathanw #include <uvm/uvm_extern.h>
93 1.2.2.2 nathanw
94 1.2.2.2 nathanw #include <machine/bswap.h>
95 1.2.2.2 nathanw #include <machine/bus.h>
96 1.2.2.2 nathanw
97 1.2.2.2 nathanw #include <dev/pci/pcireg.h>
98 1.2.2.2 nathanw #include <dev/pci/pcivar.h>
99 1.2.2.2 nathanw #include <dev/pci/pcidevs.h>
100 1.2.2.2 nathanw
101 1.2.2.2 nathanw #include <dev/ic/icpreg.h>
102 1.2.2.2 nathanw #include <dev/ic/icpvar.h>
103 1.2.2.2 nathanw
104 1.2.2.2 nathanw int icp_async_event(struct icp_softc *, int);
105 1.2.2.2 nathanw void icp_ccb_submit(struct icp_softc *icp, struct icp_ccb *ic);
106 1.2.2.2 nathanw void icp_chain(struct icp_softc *);
107 1.2.2.2 nathanw int icp_print(void *, const char *);
108 1.2.2.2 nathanw int icp_submatch(struct device *, struct cfdata *, void *);
109 1.2.2.2 nathanw void icp_watchdog(void *);
110 1.2.2.2 nathanw
111 1.2.2.2 nathanw int
112 1.2.2.2 nathanw icp_init(struct icp_softc *icp, const char *intrstr)
113 1.2.2.2 nathanw {
114 1.2.2.2 nathanw struct icp_attach_args icpa;
115 1.2.2.2 nathanw struct icp_binfo binfo;
116 1.2.2.2 nathanw struct icp_ccb *ic;
117 1.2.2.2 nathanw u_int16_t cdev_cnt;
118 1.2.2.2 nathanw int i, j, state, feat, nsegs, rv, noscsi, nocache;
119 1.2.2.2 nathanw
120 1.2.2.4 nathanw state = 0;
121 1.2.2.2 nathanw noscsi = 0;
122 1.2.2.2 nathanw nocache = 0;
123 1.2.2.2 nathanw
124 1.2.2.2 nathanw if (intrstr != NULL)
125 1.2.2.2 nathanw printf("%s: interrupting at %s\n", icp->icp_dv.dv_xname,
126 1.2.2.2 nathanw intrstr);
127 1.2.2.2 nathanw
128 1.2.2.2 nathanw SIMPLEQ_INIT(&icp->icp_ccb_queue);
129 1.2.2.2 nathanw SIMPLEQ_INIT(&icp->icp_ccb_freelist);
130 1.2.2.2 nathanw callout_init(&icp->icp_wdog_callout);
131 1.2.2.2 nathanw
132 1.2.2.2 nathanw /*
133 1.2.2.2 nathanw * Allocate a scratch area.
134 1.2.2.2 nathanw */
135 1.2.2.2 nathanw if (bus_dmamap_create(icp->icp_dmat, ICP_SCRATCH_SIZE, 1,
136 1.2.2.2 nathanw ICP_SCRATCH_SIZE, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
137 1.2.2.2 nathanw &icp->icp_scr_dmamap) != 0) {
138 1.2.2.2 nathanw printf("%s: cannot create scratch dmamap\n",
139 1.2.2.2 nathanw icp->icp_dv.dv_xname);
140 1.2.2.2 nathanw return (1);
141 1.2.2.2 nathanw }
142 1.2.2.2 nathanw state++;
143 1.2.2.2 nathanw
144 1.2.2.2 nathanw if (bus_dmamem_alloc(icp->icp_dmat, ICP_SCRATCH_SIZE, PAGE_SIZE, 0,
145 1.2.2.2 nathanw icp->icp_scr_seg, 1, &nsegs, BUS_DMA_NOWAIT) != 0) {
146 1.2.2.2 nathanw printf("%s: cannot alloc scratch dmamem\n",
147 1.2.2.2 nathanw icp->icp_dv.dv_xname);
148 1.2.2.2 nathanw goto bail_out;
149 1.2.2.2 nathanw }
150 1.2.2.2 nathanw state++;
151 1.2.2.2 nathanw
152 1.2.2.2 nathanw if (bus_dmamem_map(icp->icp_dmat, icp->icp_scr_seg, nsegs,
153 1.2.2.2 nathanw ICP_SCRATCH_SIZE, &icp->icp_scr, 0)) {
154 1.2.2.2 nathanw printf("%s: cannot map scratch dmamem\n", icp->icp_dv.dv_xname);
155 1.2.2.2 nathanw goto bail_out;
156 1.2.2.2 nathanw }
157 1.2.2.2 nathanw state++;
158 1.2.2.2 nathanw
159 1.2.2.2 nathanw if (bus_dmamap_load(icp->icp_dmat, icp->icp_scr_dmamap, icp->icp_scr,
160 1.2.2.2 nathanw ICP_SCRATCH_SIZE, NULL, BUS_DMA_NOWAIT)) {
161 1.2.2.2 nathanw printf("%s: cannot load scratch dmamap\n", icp->icp_dv.dv_xname);
162 1.2.2.2 nathanw goto bail_out;
163 1.2.2.2 nathanw }
164 1.2.2.2 nathanw state++;
165 1.2.2.2 nathanw
166 1.2.2.2 nathanw /*
167 1.2.2.2 nathanw * Allocate and initialize the command control blocks.
168 1.2.2.2 nathanw */
169 1.2.2.2 nathanw ic = malloc(sizeof(*ic) * ICP_NCCBS, M_DEVBUF, M_NOWAIT | M_ZERO);
170 1.2.2.2 nathanw if ((icp->icp_ccbs = ic) == NULL) {
171 1.2.2.2 nathanw printf("%s: malloc() failed\n", icp->icp_dv.dv_xname);
172 1.2.2.2 nathanw goto bail_out;
173 1.2.2.2 nathanw }
174 1.2.2.2 nathanw state++;
175 1.2.2.2 nathanw
176 1.2.2.2 nathanw for (i = 0; i < ICP_NCCBS; i++, ic++) {
177 1.2.2.2 nathanw /*
178 1.2.2.2 nathanw * The first two command indexes have special meanings, so
179 1.2.2.2 nathanw * we can't use them.
180 1.2.2.2 nathanw */
181 1.2.2.2 nathanw ic->ic_ident = i + 2;
182 1.2.2.2 nathanw rv = bus_dmamap_create(icp->icp_dmat, ICP_MAX_XFER,
183 1.2.2.2 nathanw ICP_MAXSG, ICP_MAX_XFER, 0,
184 1.2.2.2 nathanw BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
185 1.2.2.2 nathanw &ic->ic_xfer_map);
186 1.2.2.2 nathanw if (rv != 0)
187 1.2.2.2 nathanw break;
188 1.2.2.2 nathanw icp->icp_nccbs++;
189 1.2.2.2 nathanw icp_ccb_free(icp, ic);
190 1.2.2.2 nathanw }
191 1.2.2.2 nathanw #ifdef DIAGNOSTIC
192 1.2.2.2 nathanw if (icp->icp_nccbs != ICP_NCCBS)
193 1.2.2.2 nathanw printf("%s: %d/%d CCBs usable\n", icp->icp_dv.dv_xname,
194 1.2.2.2 nathanw icp->icp_nccbs, ICP_NCCBS);
195 1.2.2.2 nathanw #endif
196 1.2.2.2 nathanw
197 1.2.2.2 nathanw /*
198 1.2.2.2 nathanw * Initalize the controller.
199 1.2.2.2 nathanw */
200 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_SCREENSERVICE, ICP_INIT, 0, 0, 0)) {
201 1.2.2.2 nathanw printf("%s: screen service init error %d\n",
202 1.2.2.2 nathanw icp->icp_dv.dv_xname, icp->icp_status);
203 1.2.2.2 nathanw goto bail_out;
204 1.2.2.2 nathanw }
205 1.2.2.2 nathanw
206 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_CACHESERVICE, ICP_INIT, ICP_LINUX_OS, 0, 0)) {
207 1.2.2.2 nathanw printf("%s: cache service init error %d\n",
208 1.2.2.2 nathanw icp->icp_dv.dv_xname, icp->icp_status);
209 1.2.2.2 nathanw goto bail_out;
210 1.2.2.2 nathanw }
211 1.2.2.2 nathanw
212 1.2.2.2 nathanw icp_cmd(icp, ICP_CACHESERVICE, ICP_UNFREEZE_IO, 0, 0, 0);
213 1.2.2.2 nathanw
214 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_CACHESERVICE, ICP_MOUNT, 0xffff, 1, 0)) {
215 1.2.2.2 nathanw printf("%s: cache service mount error %d\n",
216 1.2.2.2 nathanw icp->icp_dv.dv_xname, icp->icp_status);
217 1.2.2.2 nathanw goto bail_out;
218 1.2.2.2 nathanw }
219 1.2.2.2 nathanw
220 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_CACHESERVICE, ICP_INIT, ICP_LINUX_OS, 0, 0)) {
221 1.2.2.2 nathanw printf("%s: cache service post-mount init error %d\n",
222 1.2.2.2 nathanw icp->icp_dv.dv_xname, icp->icp_status);
223 1.2.2.2 nathanw goto bail_out;
224 1.2.2.2 nathanw }
225 1.2.2.2 nathanw cdev_cnt = (u_int16_t)icp->icp_info;
226 1.2.2.2 nathanw
227 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_SCSIRAWSERVICE, ICP_INIT, 0, 0, 0)) {
228 1.2.2.2 nathanw printf("%s: raw service init error %d\n",
229 1.2.2.2 nathanw icp->icp_dv.dv_xname, icp->icp_status);
230 1.2.2.2 nathanw goto bail_out;
231 1.2.2.2 nathanw }
232 1.2.2.2 nathanw
233 1.2.2.2 nathanw /*
234 1.2.2.2 nathanw * Set/get raw service features (scatter/gather).
235 1.2.2.2 nathanw */
236 1.2.2.2 nathanw feat = 0;
237 1.2.2.2 nathanw if (icp_cmd(icp, ICP_SCSIRAWSERVICE, ICP_SET_FEAT, ICP_SCATTER_GATHER,
238 1.2.2.2 nathanw 0, 0))
239 1.2.2.2 nathanw if (icp_cmd(icp, ICP_SCSIRAWSERVICE, ICP_GET_FEAT, 0, 0, 0))
240 1.2.2.2 nathanw feat = icp->icp_info;
241 1.2.2.2 nathanw
242 1.2.2.2 nathanw if ((feat & ICP_SCATTER_GATHER) == 0) {
243 1.2.2.2 nathanw #ifdef DIAGNOSTIC
244 1.2.2.2 nathanw printf("%s: scatter/gather not supported (raw service)\n",
245 1.2.2.2 nathanw icp->icp_dv.dv_xname);
246 1.2.2.2 nathanw #endif
247 1.2.2.2 nathanw noscsi = 1;
248 1.2.2.2 nathanw }
249 1.2.2.2 nathanw
250 1.2.2.2 nathanw /*
251 1.2.2.2 nathanw * Set/get cache service features (scatter/gather).
252 1.2.2.2 nathanw */
253 1.2.2.2 nathanw feat = 0;
254 1.2.2.2 nathanw if (icp_cmd(icp, ICP_CACHESERVICE, ICP_SET_FEAT, 0,
255 1.2.2.2 nathanw ICP_SCATTER_GATHER, 0))
256 1.2.2.2 nathanw if (icp_cmd(icp, ICP_CACHESERVICE, ICP_GET_FEAT, 0, 0, 0))
257 1.2.2.2 nathanw feat = icp->icp_info;
258 1.2.2.2 nathanw
259 1.2.2.2 nathanw if ((feat & ICP_SCATTER_GATHER) == 0) {
260 1.2.2.2 nathanw #ifdef DIAGNOSTIC
261 1.2.2.2 nathanw printf("%s: scatter/gather not supported (cache service)\n",
262 1.2.2.2 nathanw icp->icp_dv.dv_xname);
263 1.2.2.2 nathanw #endif
264 1.2.2.2 nathanw nocache = 1;
265 1.2.2.2 nathanw }
266 1.2.2.2 nathanw
267 1.2.2.2 nathanw /*
268 1.2.2.2 nathanw * Pull some information from the board and dump.
269 1.2.2.2 nathanw */
270 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_CACHESERVICE, ICP_IOCTL, ICP_BOARD_INFO,
271 1.2.2.2 nathanw ICP_INVALID_CHANNEL, sizeof(struct icp_binfo))) {
272 1.2.2.2 nathanw printf("%s: unable to retrive board info\n",
273 1.2.2.2 nathanw icp->icp_dv.dv_xname);
274 1.2.2.2 nathanw goto bail_out;
275 1.2.2.2 nathanw }
276 1.2.2.2 nathanw memcpy(&binfo, icp->icp_scr, sizeof(binfo));
277 1.2.2.2 nathanw
278 1.2.2.2 nathanw printf("%s: model <%s>, firmware <%s>, %d channel(s), %dMB memory\n",
279 1.2.2.2 nathanw icp->icp_dv.dv_xname, binfo.bi_type_string, binfo.bi_raid_string,
280 1.2.2.2 nathanw binfo.bi_chan_count, le32toh(binfo.bi_memsize) >> 20);
281 1.2.2.2 nathanw
282 1.2.2.2 nathanw /*
283 1.2.2.2 nathanw * Determine the number of devices, and number of openings per
284 1.2.2.2 nathanw * device.
285 1.2.2.2 nathanw */
286 1.2.2.2 nathanw if (!nocache) {
287 1.2.2.2 nathanw for (j = 0; j < cdev_cnt && j < ICP_MAX_HDRIVES; j++) {
288 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_CACHESERVICE, ICP_INFO, j, 0,
289 1.2.2.2 nathanw 0))
290 1.2.2.2 nathanw continue;
291 1.2.2.2 nathanw
292 1.2.2.2 nathanw icp->icp_cdr[j].cd_size = icp->icp_info;
293 1.2.2.2 nathanw icp->icp_ndevs++;
294 1.2.2.2 nathanw
295 1.2.2.2 nathanw if (icp_cmd(icp, ICP_CACHESERVICE, ICP_DEVTYPE, j, 0,
296 1.2.2.2 nathanw 0))
297 1.2.2.2 nathanw icp->icp_cdr[j].cd_type = icp->icp_info;
298 1.2.2.2 nathanw }
299 1.2.2.2 nathanw }
300 1.2.2.2 nathanw
301 1.2.2.2 nathanw if (!noscsi)
302 1.2.2.2 nathanw icp->icp_ndevs += binfo.bi_chan_count;
303 1.2.2.2 nathanw
304 1.2.2.2 nathanw if (icp->icp_ndevs != 0)
305 1.2.2.2 nathanw icp->icp_openings =
306 1.2.2.2 nathanw (icp->icp_nccbs - ICP_NCCB_RESERVE) / icp->icp_ndevs;
307 1.2.2.2 nathanw #ifdef ICP_DEBUG
308 1.2.2.2 nathanw printf("%s: %d openings per device\n", icp->icp_dv.dv_xname,
309 1.2.2.2 nathanw icp->icp_openings);
310 1.2.2.2 nathanw #endif
311 1.2.2.2 nathanw
312 1.2.2.2 nathanw /*
313 1.2.2.2 nathanw * Attach SCSI channels.
314 1.2.2.2 nathanw */
315 1.2.2.2 nathanw if (!noscsi) {
316 1.2.2.2 nathanw struct icp_ioc_version *iv;
317 1.2.2.2 nathanw struct icp_rawioc *ri;
318 1.2.2.2 nathanw struct icp_getch *gc;
319 1.2.2.2 nathanw
320 1.2.2.2 nathanw iv = (struct icp_ioc_version *)icp->icp_scr;
321 1.2.2.2 nathanw iv->iv_version = htole32(ICP_IOC_NEWEST);
322 1.2.2.2 nathanw iv->iv_listents = ICP_MAXBUS;
323 1.2.2.2 nathanw iv->iv_firstchan = 0;
324 1.2.2.2 nathanw iv->iv_lastchan = ICP_MAXBUS - 1;
325 1.2.2.2 nathanw iv->iv_listoffset = htole32(sizeof(*iv));
326 1.2.2.2 nathanw
327 1.2.2.2 nathanw if (icp_cmd(icp, ICP_CACHESERVICE, ICP_IOCTL,
328 1.2.2.2 nathanw ICP_IOCHAN_RAW_DESC, ICP_INVALID_CHANNEL,
329 1.2.2.2 nathanw sizeof(*iv) + ICP_MAXBUS * sizeof(*ri))) {
330 1.2.2.2 nathanw ri = (struct icp_rawioc *)(iv + 1);
331 1.2.2.2 nathanw for (j = 0; j < binfo.bi_chan_count; j++, ri++)
332 1.2.2.2 nathanw icp->icp_bus_id[j] = ri->ri_procid;
333 1.2.2.2 nathanw } else {
334 1.2.2.2 nathanw /*
335 1.2.2.2 nathanw * Fall back to the old method.
336 1.2.2.2 nathanw */
337 1.2.2.2 nathanw gc = (struct icp_getch *)icp->icp_scr;
338 1.2.2.2 nathanw
339 1.2.2.2 nathanw for (i = 0; j < binfo.bi_chan_count; j++) {
340 1.2.2.2 nathanw if (!icp_cmd(icp, ICP_CACHESERVICE, ICP_IOCTL,
341 1.2.2.2 nathanw ICP_SCSI_CHAN_CNT | ICP_L_CTRL_PATTERN,
342 1.2.2.2 nathanw ICP_IO_CHANNEL | ICP_INVALID_CHANNEL,
343 1.2.2.2 nathanw sizeof(*gc))) {
344 1.2.2.2 nathanw printf("%s: unable to get chan info",
345 1.2.2.2 nathanw icp->icp_dv.dv_xname);
346 1.2.2.2 nathanw goto bail_out;
347 1.2.2.2 nathanw }
348 1.2.2.2 nathanw icp->icp_bus_id[j] = gc->gc_scsiid;
349 1.2.2.2 nathanw }
350 1.2.2.2 nathanw }
351 1.2.2.2 nathanw
352 1.2.2.2 nathanw for (j = 0; j < binfo.bi_chan_count; j++) {
353 1.2.2.2 nathanw if (icp->icp_bus_id[j] > ICP_MAXID_FC)
354 1.2.2.2 nathanw icp->icp_bus_id[j] = ICP_MAXID_FC;
355 1.2.2.2 nathanw
356 1.2.2.2 nathanw icpa.icpa_unit = j + ICPA_UNIT_SCSI;
357 1.2.2.2 nathanw config_found_sm(&icp->icp_dv, &icpa, icp_print,
358 1.2.2.2 nathanw icp_submatch);
359 1.2.2.2 nathanw }
360 1.2.2.2 nathanw }
361 1.2.2.2 nathanw
362 1.2.2.2 nathanw /*
363 1.2.2.2 nathanw * Attach cache devices.
364 1.2.2.2 nathanw */
365 1.2.2.2 nathanw if (!nocache) {
366 1.2.2.2 nathanw for (j = 0; j < cdev_cnt && j < ICP_MAX_HDRIVES; j++) {
367 1.2.2.2 nathanw if (icp->icp_cdr[j].cd_size == 0)
368 1.2.2.2 nathanw continue;
369 1.2.2.2 nathanw
370 1.2.2.2 nathanw icpa.icpa_unit = j;
371 1.2.2.2 nathanw config_found_sm(&icp->icp_dv, &icpa, icp_print,
372 1.2.2.2 nathanw icp_submatch);
373 1.2.2.2 nathanw }
374 1.2.2.2 nathanw }
375 1.2.2.2 nathanw
376 1.2.2.2 nathanw /*
377 1.2.2.2 nathanw * Start the watchdog.
378 1.2.2.2 nathanw */
379 1.2.2.2 nathanw icp_watchdog(icp);
380 1.2.2.2 nathanw return (0);
381 1.2.2.2 nathanw
382 1.2.2.2 nathanw bail_out:
383 1.2.2.2 nathanw if (state > 4)
384 1.2.2.2 nathanw for (j = 0; j < i; j++)
385 1.2.2.2 nathanw bus_dmamap_destroy(icp->icp_dmat,
386 1.2.2.2 nathanw icp->icp_ccbs[j].ic_xfer_map);
387 1.2.2.2 nathanw if (state > 3)
388 1.2.2.2 nathanw free(icp->icp_ccbs, M_DEVBUF);
389 1.2.2.2 nathanw if (state > 2)
390 1.2.2.2 nathanw bus_dmamap_unload(icp->icp_dmat, icp->icp_scr_dmamap);
391 1.2.2.2 nathanw if (state > 1)
392 1.2.2.2 nathanw bus_dmamem_unmap(icp->icp_dmat, icp->icp_scr,
393 1.2.2.2 nathanw ICP_SCRATCH_SIZE);
394 1.2.2.2 nathanw if (state > 0)
395 1.2.2.2 nathanw bus_dmamem_free(icp->icp_dmat, icp->icp_scr_seg, nsegs);
396 1.2.2.2 nathanw bus_dmamap_destroy(icp->icp_dmat, icp->icp_scr_dmamap);
397 1.2.2.2 nathanw
398 1.2.2.2 nathanw return (1);
399 1.2.2.2 nathanw }
400 1.2.2.2 nathanw
401 1.2.2.2 nathanw void
402 1.2.2.2 nathanw icp_watchdog(void *cookie)
403 1.2.2.2 nathanw {
404 1.2.2.2 nathanw struct icp_softc *icp;
405 1.2.2.2 nathanw int s;
406 1.2.2.2 nathanw
407 1.2.2.2 nathanw icp = cookie;
408 1.2.2.2 nathanw
409 1.2.2.2 nathanw s = splbio();
410 1.2.2.2 nathanw icp_intr(icp);
411 1.2.2.2 nathanw if (! SIMPLEQ_EMPTY(&icp->icp_ccb_queue))
412 1.2.2.2 nathanw icp_ccb_enqueue(icp, NULL);
413 1.2.2.2 nathanw splx(s);
414 1.2.2.2 nathanw
415 1.2.2.2 nathanw callout_reset(&icp->icp_wdog_callout, hz * ICP_WATCHDOG_FREQ,
416 1.2.2.2 nathanw icp_watchdog, icp);
417 1.2.2.2 nathanw }
418 1.2.2.2 nathanw
419 1.2.2.2 nathanw int
420 1.2.2.2 nathanw icp_print(void *aux, const char *pnp)
421 1.2.2.2 nathanw {
422 1.2.2.2 nathanw struct icp_attach_args *icpa;
423 1.2.2.2 nathanw const char *str;
424 1.2.2.2 nathanw
425 1.2.2.2 nathanw icpa = (struct icp_attach_args *)aux;
426 1.2.2.2 nathanw
427 1.2.2.2 nathanw if (pnp != NULL) {
428 1.2.2.2 nathanw if (icpa->icpa_unit < ICPA_UNIT_SCSI)
429 1.2.2.2 nathanw str = "block device";
430 1.2.2.2 nathanw else
431 1.2.2.2 nathanw str = "SCSI channel";
432 1.2.2.5 thorpej aprint_normal("%s at %s", str, pnp);
433 1.2.2.2 nathanw }
434 1.2.2.5 thorpej aprint_normal(" unit %d", icpa->icpa_unit);
435 1.2.2.2 nathanw
436 1.2.2.2 nathanw return (UNCONF);
437 1.2.2.2 nathanw }
438 1.2.2.2 nathanw
439 1.2.2.2 nathanw int
440 1.2.2.2 nathanw icp_submatch(struct device *parent, struct cfdata *cf, void *aux)
441 1.2.2.2 nathanw {
442 1.2.2.2 nathanw struct icp_attach_args *icpa;
443 1.2.2.2 nathanw
444 1.2.2.2 nathanw icpa = (struct icp_attach_args *)aux;
445 1.2.2.2 nathanw
446 1.2.2.2 nathanw if (cf->icpacf_unit != ICPCF_UNIT_DEFAULT &&
447 1.2.2.2 nathanw cf->icpacf_unit != icpa->icpa_unit)
448 1.2.2.2 nathanw return (0);
449 1.2.2.2 nathanw
450 1.2.2.3 nathanw return (config_match(parent, cf, aux));
451 1.2.2.2 nathanw }
452 1.2.2.2 nathanw
453 1.2.2.2 nathanw int
454 1.2.2.2 nathanw icp_async_event(struct icp_softc *icp, int val)
455 1.2.2.2 nathanw {
456 1.2.2.2 nathanw
457 1.2.2.2 nathanw /* XXX */
458 1.2.2.2 nathanw return (1);
459 1.2.2.2 nathanw }
460 1.2.2.2 nathanw
461 1.2.2.2 nathanw int
462 1.2.2.2 nathanw icp_intr(void *cookie)
463 1.2.2.2 nathanw {
464 1.2.2.2 nathanw struct icp_softc *icp;
465 1.2.2.2 nathanw struct icp_intr_ctx ctx;
466 1.2.2.2 nathanw struct icp_ccb *ic;
467 1.2.2.2 nathanw
468 1.2.2.2 nathanw icp = cookie;
469 1.2.2.2 nathanw
470 1.2.2.2 nathanw ctx.istatus = (*icp->icp_get_status)(icp);
471 1.2.2.2 nathanw if (!ctx.istatus) {
472 1.2.2.2 nathanw icp->icp_status = ICP_S_NO_STATUS;
473 1.2.2.2 nathanw return (0);
474 1.2.2.2 nathanw }
475 1.2.2.2 nathanw
476 1.2.2.2 nathanw (*icp->icp_intr)(icp, &ctx);
477 1.2.2.2 nathanw
478 1.2.2.2 nathanw icp->icp_status = ctx.cmd_status;
479 1.2.2.2 nathanw icp->icp_info = ctx.info;
480 1.2.2.2 nathanw icp->icp_info2 = ctx.info2;
481 1.2.2.2 nathanw
482 1.2.2.2 nathanw switch (ctx.istatus) {
483 1.2.2.2 nathanw case ICP_ASYNCINDEX:
484 1.2.2.2 nathanw icp_async_event(icp, ctx.service);
485 1.2.2.2 nathanw return (1);
486 1.2.2.2 nathanw
487 1.2.2.2 nathanw case ICP_SPEZINDEX:
488 1.2.2.2 nathanw printf("%s: uninitialized or unknown service (%d/%d)\n",
489 1.2.2.2 nathanw icp->icp_dv.dv_xname, ctx.info, ctx.info2);
490 1.2.2.2 nathanw return (1);
491 1.2.2.2 nathanw }
492 1.2.2.2 nathanw
493 1.2.2.2 nathanw if ((ctx.istatus - 2) > icp->icp_nccbs)
494 1.2.2.2 nathanw panic("icp_intr: bad command index returned");
495 1.2.2.2 nathanw
496 1.2.2.2 nathanw ic = &icp->icp_ccbs[ctx.istatus - 2];
497 1.2.2.2 nathanw ic->ic_status = icp->icp_status;
498 1.2.2.2 nathanw
499 1.2.2.2 nathanw if ((ic->ic_flags & IC_ALLOCED) == 0)
500 1.2.2.2 nathanw panic("icp_intr: inactive CCB identified");
501 1.2.2.2 nathanw
502 1.2.2.2 nathanw switch (icp->icp_status) {
503 1.2.2.2 nathanw case ICP_S_BSY:
504 1.2.2.2 nathanw #ifdef ICP_DEBUG
505 1.2.2.2 nathanw printf("%s: ICP_S_BSY received\n", icp->icp_dv.dv_xname);
506 1.2.2.2 nathanw #endif
507 1.2.2.2 nathanw SIMPLEQ_INSERT_HEAD(&icp->icp_ccb_queue, ic, ic_chain);
508 1.2.2.2 nathanw break;
509 1.2.2.2 nathanw
510 1.2.2.2 nathanw default:
511 1.2.2.2 nathanw ic->ic_flags |= IC_COMPLETE;
512 1.2.2.2 nathanw
513 1.2.2.2 nathanw if ((ic->ic_flags & IC_WAITING) != 0)
514 1.2.2.2 nathanw wakeup(ic);
515 1.2.2.2 nathanw else if (ic->ic_intr != NULL)
516 1.2.2.2 nathanw (*ic->ic_intr)(ic);
517 1.2.2.2 nathanw
518 1.2.2.2 nathanw if (! SIMPLEQ_EMPTY(&icp->icp_ccb_queue))
519 1.2.2.2 nathanw icp_ccb_enqueue(icp, NULL);
520 1.2.2.2 nathanw
521 1.2.2.2 nathanw break;
522 1.2.2.2 nathanw }
523 1.2.2.2 nathanw
524 1.2.2.2 nathanw return (1);
525 1.2.2.2 nathanw }
526 1.2.2.2 nathanw
527 1.2.2.2 nathanw int
528 1.2.2.2 nathanw icp_cmd(struct icp_softc *icp, u_int8_t service, u_int16_t opcode,
529 1.2.2.2 nathanw u_int32_t arg1, u_int32_t arg2, u_int32_t arg3)
530 1.2.2.2 nathanw {
531 1.2.2.2 nathanw struct icp_ioctlcmd *icmd;
532 1.2.2.2 nathanw struct icp_cachecmd *cc;
533 1.2.2.2 nathanw struct icp_rawcmd *rc;
534 1.2.2.2 nathanw int retries, rv;
535 1.2.2.2 nathanw struct icp_ccb *ic;
536 1.2.2.2 nathanw
537 1.2.2.2 nathanw retries = ICP_RETRIES;
538 1.2.2.2 nathanw
539 1.2.2.2 nathanw do {
540 1.2.2.2 nathanw ic = icp_ccb_alloc(icp);
541 1.2.2.2 nathanw memset(&ic->ic_cmd, 0, sizeof(ic->ic_cmd));
542 1.2.2.2 nathanw ic->ic_cmd.cmd_opcode = htole16(opcode);
543 1.2.2.2 nathanw
544 1.2.2.2 nathanw switch (service) {
545 1.2.2.2 nathanw case ICP_CACHESERVICE:
546 1.2.2.2 nathanw if (opcode == ICP_IOCTL) {
547 1.2.2.2 nathanw icmd = &ic->ic_cmd.cmd_packet.ic;
548 1.2.2.2 nathanw icmd->ic_subfunc = htole16(arg1);
549 1.2.2.2 nathanw icmd->ic_channel = htole32(arg2);
550 1.2.2.2 nathanw icmd->ic_bufsize = htole32(arg3);
551 1.2.2.2 nathanw icmd->ic_addr =
552 1.2.2.2 nathanw htole32(icp->icp_scr_seg[0].ds_addr);
553 1.2.2.2 nathanw
554 1.2.2.2 nathanw bus_dmamap_sync(icp->icp_dmat,
555 1.2.2.2 nathanw icp->icp_scr_dmamap, 0, arg3,
556 1.2.2.2 nathanw BUS_DMASYNC_PREWRITE |
557 1.2.2.2 nathanw BUS_DMASYNC_PREREAD);
558 1.2.2.2 nathanw } else {
559 1.2.2.2 nathanw cc = &ic->ic_cmd.cmd_packet.cc;
560 1.2.2.2 nathanw cc->cc_deviceno = htole16(arg1);
561 1.2.2.2 nathanw cc->cc_blockno = htole32(arg2);
562 1.2.2.2 nathanw }
563 1.2.2.2 nathanw break;
564 1.2.2.2 nathanw
565 1.2.2.2 nathanw case ICP_SCSIRAWSERVICE:
566 1.2.2.2 nathanw rc = &ic->ic_cmd.cmd_packet.rc;
567 1.2.2.2 nathanw rc->rc_direction = htole32(arg1);
568 1.2.2.2 nathanw rc->rc_bus = arg2;
569 1.2.2.2 nathanw rc->rc_target = arg3;
570 1.2.2.2 nathanw rc->rc_lun = arg3 >> 8;
571 1.2.2.2 nathanw break;
572 1.2.2.2 nathanw }
573 1.2.2.2 nathanw
574 1.2.2.2 nathanw ic->ic_service = service;
575 1.2.2.2 nathanw ic->ic_cmdlen = sizeof(ic->ic_cmd);
576 1.2.2.2 nathanw rv = icp_ccb_poll(icp, ic, 10000);
577 1.2.2.2 nathanw
578 1.2.2.2 nathanw switch (service) {
579 1.2.2.2 nathanw case ICP_CACHESERVICE:
580 1.2.2.2 nathanw if (opcode == ICP_IOCTL) {
581 1.2.2.2 nathanw bus_dmamap_sync(icp->icp_dmat,
582 1.2.2.2 nathanw icp->icp_scr_dmamap, 0, arg3,
583 1.2.2.2 nathanw BUS_DMASYNC_POSTWRITE |
584 1.2.2.2 nathanw BUS_DMASYNC_POSTREAD);
585 1.2.2.2 nathanw }
586 1.2.2.2 nathanw break;
587 1.2.2.2 nathanw }
588 1.2.2.2 nathanw
589 1.2.2.2 nathanw icp_ccb_free(icp, ic);
590 1.2.2.2 nathanw } while (rv != 0 && --retries > 0);
591 1.2.2.2 nathanw
592 1.2.2.2 nathanw return (icp->icp_status == ICP_S_OK);
593 1.2.2.2 nathanw }
594 1.2.2.2 nathanw
595 1.2.2.2 nathanw struct icp_ccb *
596 1.2.2.2 nathanw icp_ccb_alloc(struct icp_softc *icp)
597 1.2.2.2 nathanw {
598 1.2.2.2 nathanw struct icp_ccb *ic;
599 1.2.2.2 nathanw int s;
600 1.2.2.2 nathanw
601 1.2.2.2 nathanw s = splbio();
602 1.2.2.2 nathanw ic = SIMPLEQ_FIRST(&icp->icp_ccb_freelist);
603 1.2.2.2 nathanw SIMPLEQ_REMOVE_HEAD(&icp->icp_ccb_freelist, ic_chain);
604 1.2.2.2 nathanw splx(s);
605 1.2.2.2 nathanw
606 1.2.2.2 nathanw ic->ic_flags = IC_ALLOCED;
607 1.2.2.2 nathanw return (ic);
608 1.2.2.2 nathanw }
609 1.2.2.2 nathanw
610 1.2.2.2 nathanw void
611 1.2.2.2 nathanw icp_ccb_free(struct icp_softc *icp, struct icp_ccb *ic)
612 1.2.2.2 nathanw {
613 1.2.2.2 nathanw int s;
614 1.2.2.2 nathanw
615 1.2.2.2 nathanw s = splbio();
616 1.2.2.2 nathanw ic->ic_flags = 0;
617 1.2.2.2 nathanw ic->ic_intr = NULL;
618 1.2.2.2 nathanw SIMPLEQ_INSERT_HEAD(&icp->icp_ccb_freelist, ic, ic_chain);
619 1.2.2.2 nathanw splx(s);
620 1.2.2.2 nathanw }
621 1.2.2.2 nathanw
622 1.2.2.2 nathanw void
623 1.2.2.2 nathanw icp_ccb_enqueue(struct icp_softc *icp, struct icp_ccb *ic)
624 1.2.2.2 nathanw {
625 1.2.2.2 nathanw int s;
626 1.2.2.2 nathanw
627 1.2.2.2 nathanw s = splbio();
628 1.2.2.2 nathanw
629 1.2.2.2 nathanw if (ic != NULL)
630 1.2.2.2 nathanw SIMPLEQ_INSERT_TAIL(&icp->icp_ccb_queue, ic, ic_chain);
631 1.2.2.2 nathanw
632 1.2.2.2 nathanw while ((ic = SIMPLEQ_FIRST(&icp->icp_ccb_queue)) != NULL) {
633 1.2.2.2 nathanw if ((*icp->icp_test_busy)(icp))
634 1.2.2.2 nathanw break;
635 1.2.2.2 nathanw icp_ccb_submit(icp, ic);
636 1.2.2.2 nathanw SIMPLEQ_REMOVE_HEAD(&icp->icp_ccb_queue, ic_chain);
637 1.2.2.2 nathanw }
638 1.2.2.2 nathanw
639 1.2.2.2 nathanw splx(s);
640 1.2.2.2 nathanw }
641 1.2.2.2 nathanw
642 1.2.2.2 nathanw int
643 1.2.2.2 nathanw icp_ccb_map(struct icp_softc *icp, struct icp_ccb *ic, void *data, int size,
644 1.2.2.2 nathanw int dir)
645 1.2.2.2 nathanw {
646 1.2.2.2 nathanw struct icp_sg *sg;
647 1.2.2.2 nathanw int nsegs, i, rv;
648 1.2.2.2 nathanw bus_dmamap_t xfer;
649 1.2.2.2 nathanw
650 1.2.2.2 nathanw xfer = ic->ic_xfer_map;
651 1.2.2.2 nathanw
652 1.2.2.2 nathanw rv = bus_dmamap_load(icp->icp_dmat, xfer, data, size, NULL,
653 1.2.2.2 nathanw BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
654 1.2.2.2 nathanw ((dir & IC_XFER_IN) ? BUS_DMA_READ : BUS_DMA_WRITE));
655 1.2.2.2 nathanw if (rv != 0)
656 1.2.2.2 nathanw return (rv);
657 1.2.2.2 nathanw
658 1.2.2.2 nathanw nsegs = xfer->dm_nsegs;
659 1.2.2.2 nathanw ic->ic_xfer_size = size;
660 1.2.2.2 nathanw ic->ic_nsgent = nsegs;
661 1.2.2.2 nathanw ic->ic_flags |= dir;
662 1.2.2.2 nathanw sg = ic->ic_sg;
663 1.2.2.2 nathanw
664 1.2.2.2 nathanw if (sg != NULL) {
665 1.2.2.2 nathanw for (i = 0; i < nsegs; i++, sg++) {
666 1.2.2.2 nathanw sg->sg_addr = htole32(xfer->dm_segs[i].ds_addr);
667 1.2.2.2 nathanw sg->sg_len = htole32(xfer->dm_segs[i].ds_len);
668 1.2.2.2 nathanw }
669 1.2.2.2 nathanw } else if (nsegs > 1)
670 1.2.2.3 nathanw panic("icp_ccb_map: no SG list specified, but nsegs > 1");
671 1.2.2.2 nathanw
672 1.2.2.2 nathanw if ((dir & IC_XFER_OUT) != 0)
673 1.2.2.2 nathanw i = BUS_DMASYNC_PREWRITE;
674 1.2.2.2 nathanw else /* if ((dir & IC_XFER_IN) != 0) */
675 1.2.2.2 nathanw i = BUS_DMASYNC_PREREAD;
676 1.2.2.2 nathanw
677 1.2.2.2 nathanw bus_dmamap_sync(icp->icp_dmat, xfer, 0, ic->ic_xfer_size, i);
678 1.2.2.2 nathanw return (0);
679 1.2.2.2 nathanw }
680 1.2.2.2 nathanw
681 1.2.2.2 nathanw void
682 1.2.2.2 nathanw icp_ccb_unmap(struct icp_softc *icp, struct icp_ccb *ic)
683 1.2.2.2 nathanw {
684 1.2.2.2 nathanw int i;
685 1.2.2.2 nathanw
686 1.2.2.2 nathanw if ((ic->ic_flags & IC_XFER_OUT) != 0)
687 1.2.2.2 nathanw i = BUS_DMASYNC_POSTWRITE;
688 1.2.2.2 nathanw else /* if ((ic->ic_flags & IC_XFER_IN) != 0) */
689 1.2.2.2 nathanw i = BUS_DMASYNC_POSTREAD;
690 1.2.2.2 nathanw
691 1.2.2.2 nathanw bus_dmamap_sync(icp->icp_dmat, ic->ic_xfer_map, 0, ic->ic_xfer_size, i);
692 1.2.2.2 nathanw bus_dmamap_unload(icp->icp_dmat, ic->ic_xfer_map);
693 1.2.2.2 nathanw }
694 1.2.2.2 nathanw
695 1.2.2.2 nathanw int
696 1.2.2.2 nathanw icp_ccb_poll(struct icp_softc *icp, struct icp_ccb *ic, int timo)
697 1.2.2.2 nathanw {
698 1.2.2.2 nathanw int rv;
699 1.2.2.2 nathanw
700 1.2.2.2 nathanw for (timo = ICP_BUSY_WAIT_MS * 100; timo != 0; timo--) {
701 1.2.2.2 nathanw if (!(*icp->icp_test_busy)(icp))
702 1.2.2.2 nathanw break;
703 1.2.2.2 nathanw DELAY(10);
704 1.2.2.2 nathanw }
705 1.2.2.2 nathanw if (timo == 0) {
706 1.2.2.2 nathanw printf("%s: submit: busy\n", icp->icp_dv.dv_xname);
707 1.2.2.2 nathanw return (EAGAIN);
708 1.2.2.2 nathanw }
709 1.2.2.2 nathanw
710 1.2.2.2 nathanw icp_ccb_submit(icp, ic);
711 1.2.2.2 nathanw
712 1.2.2.2 nathanw for (timo *= 10; timo != 0; timo--) {
713 1.2.2.2 nathanw DELAY(100);
714 1.2.2.2 nathanw icp_intr(icp);
715 1.2.2.2 nathanw if ((ic->ic_flags & IC_COMPLETE) != 0)
716 1.2.2.2 nathanw break;
717 1.2.2.2 nathanw }
718 1.2.2.2 nathanw
719 1.2.2.2 nathanw if (timo != 0) {
720 1.2.2.2 nathanw if (ic->ic_status != ICP_S_OK) {
721 1.2.2.2 nathanw #ifdef ICP_DEBUG
722 1.2.2.2 nathanw printf("%s: request failed; status=0x%04x\n",
723 1.2.2.2 nathanw icp->icp_dv.dv_xname, ic->ic_status);
724 1.2.2.2 nathanw #endif
725 1.2.2.2 nathanw rv = EIO;
726 1.2.2.2 nathanw } else
727 1.2.2.2 nathanw rv = 0;
728 1.2.2.2 nathanw } else {
729 1.2.2.2 nathanw printf("%s: command timed out\n", icp->icp_dv.dv_xname);
730 1.2.2.2 nathanw rv = EIO;
731 1.2.2.2 nathanw }
732 1.2.2.2 nathanw
733 1.2.2.2 nathanw while ((*icp->icp_test_busy)(icp) != 0)
734 1.2.2.2 nathanw DELAY(10);
735 1.2.2.2 nathanw
736 1.2.2.2 nathanw return (rv);
737 1.2.2.2 nathanw }
738 1.2.2.2 nathanw
739 1.2.2.2 nathanw int
740 1.2.2.2 nathanw icp_ccb_wait(struct icp_softc *icp, struct icp_ccb *ic, int timo)
741 1.2.2.2 nathanw {
742 1.2.2.2 nathanw int s, rv;
743 1.2.2.2 nathanw
744 1.2.2.2 nathanw ic->ic_flags |= IC_WAITING;
745 1.2.2.2 nathanw
746 1.2.2.2 nathanw s = splbio();
747 1.2.2.2 nathanw icp_ccb_enqueue(icp, ic);
748 1.2.2.2 nathanw if ((rv = tsleep(ic, PRIBIO, "icpwccb", mstohz(timo))) != 0) {
749 1.2.2.2 nathanw splx(s);
750 1.2.2.2 nathanw return (rv);
751 1.2.2.2 nathanw }
752 1.2.2.2 nathanw splx(s);
753 1.2.2.2 nathanw
754 1.2.2.2 nathanw if (ic->ic_status != ICP_S_OK) {
755 1.2.2.2 nathanw printf("%s: command failed; status=%x\n", icp->icp_dv.dv_xname,
756 1.2.2.2 nathanw ic->ic_status);
757 1.2.2.2 nathanw return (EIO);
758 1.2.2.2 nathanw }
759 1.2.2.2 nathanw
760 1.2.2.2 nathanw return (0);
761 1.2.2.2 nathanw }
762 1.2.2.2 nathanw
763 1.2.2.2 nathanw void
764 1.2.2.2 nathanw icp_ccb_submit(struct icp_softc *icp, struct icp_ccb *ic)
765 1.2.2.2 nathanw {
766 1.2.2.2 nathanw
767 1.2.2.2 nathanw ic->ic_cmdlen = (ic->ic_cmdlen + 3) & ~3;
768 1.2.2.2 nathanw
769 1.2.2.2 nathanw (*icp->icp_set_sema0)(icp);
770 1.2.2.2 nathanw DELAY(10);
771 1.2.2.2 nathanw
772 1.2.2.2 nathanw ic->ic_cmd.cmd_boardnode = htole32(ICP_LOCALBOARD);
773 1.2.2.2 nathanw ic->ic_cmd.cmd_cmdindex = htole32(ic->ic_ident);
774 1.2.2.2 nathanw
775 1.2.2.2 nathanw (*icp->icp_copy_cmd)(icp, ic);
776 1.2.2.2 nathanw (*icp->icp_release_event)(icp, ic);
777 1.2.2.2 nathanw }
778