mpt_netbsd.c revision 1.18.2.4 1 1.18.2.3 tls /* $NetBSD: mpt_netbsd.c,v 1.18.2.4 2017/12/03 11:37:03 jdolecek Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 2003 Wasabi Systems, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1 thorpej *
9 1.1 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1 thorpej * modification, are permitted provided that the following conditions
11 1.1 thorpej * are met:
12 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1 thorpej * documentation and/or other materials provided with the distribution.
17 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1 thorpej * must display the following acknowledgement:
19 1.1 thorpej * This product includes software developed for the NetBSD Project by
20 1.1 thorpej * Wasabi Systems, Inc.
21 1.1 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 thorpej * or promote products derived from this software without specific prior
23 1.1 thorpej * written permission.
24 1.1 thorpej *
25 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.1 thorpej */
37 1.1 thorpej
38 1.1 thorpej /*
39 1.1 thorpej * Copyright (c) 2000, 2001 by Greg Ansley
40 1.1 thorpej * Partially derived from Matt Jacob's ISP driver.
41 1.1 thorpej *
42 1.1 thorpej * Redistribution and use in source and binary forms, with or without
43 1.1 thorpej * modification, are permitted provided that the following conditions
44 1.1 thorpej * are met:
45 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
46 1.1 thorpej * notice immediately at the beginning of the file, without modification,
47 1.1 thorpej * this list of conditions, and the following disclaimer.
48 1.1 thorpej * 2. The name of the author may not be used to endorse or promote products
49 1.1 thorpej * derived from this software without specific prior written permission.
50 1.1 thorpej *
51 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
55 1.1 thorpej * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 1.1 thorpej * SUCH DAMAGE.
62 1.1 thorpej */
63 1.1 thorpej /*
64 1.1 thorpej * Additional Copyright (c) 2002 by Matthew Jacob under same license.
65 1.1 thorpej */
66 1.1 thorpej
67 1.1 thorpej /*
68 1.1 thorpej * mpt_netbsd.c:
69 1.1 thorpej *
70 1.1 thorpej * NetBSD-specific routines for LSI Fusion adapters. Includes some
71 1.1 thorpej * bus_dma glue, and SCSIPI glue.
72 1.1 thorpej *
73 1.1 thorpej * Adapted from the FreeBSD "mpt" driver by Jason R. Thorpe for
74 1.1 thorpej * Wasabi Systems, Inc.
75 1.12 tron *
76 1.12 tron * Additional contributions by Garrett D'Amore on behalf of TELES AG.
77 1.1 thorpej */
78 1.7 lukem
79 1.7 lukem #include <sys/cdefs.h>
80 1.18.2.3 tls __KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.18.2.4 2017/12/03 11:37:03 jdolecek Exp $");
81 1.1 thorpej
82 1.18.2.4 jdolecek #include "bio.h"
83 1.18.2.4 jdolecek
84 1.1 thorpej #include <dev/ic/mpt.h> /* pulls in all headers */
85 1.18.2.3 tls #include <sys/scsiio.h>
86 1.1 thorpej
87 1.18.2.4 jdolecek #if NBIO > 0
88 1.18.2.4 jdolecek #include <dev/biovar.h>
89 1.18.2.4 jdolecek #endif
90 1.18.2.4 jdolecek
91 1.1 thorpej static int mpt_poll(mpt_softc_t *, struct scsipi_xfer *, int);
92 1.1 thorpej static void mpt_timeout(void *);
93 1.18.2.3 tls static void mpt_restart(mpt_softc_t *, request_t *);
94 1.1 thorpej static void mpt_done(mpt_softc_t *, uint32_t);
95 1.18.2.3 tls static int mpt_drain_queue(mpt_softc_t *);
96 1.1 thorpej static void mpt_run_xfer(mpt_softc_t *, struct scsipi_xfer *);
97 1.1 thorpej static void mpt_set_xfer_mode(mpt_softc_t *, struct scsipi_xfer_mode *);
98 1.1 thorpej static void mpt_get_xfer_mode(mpt_softc_t *, struct scsipi_periph *);
99 1.1 thorpej static void mpt_ctlop(mpt_softc_t *, void *vmsg, uint32_t);
100 1.1 thorpej static void mpt_event_notify_reply(mpt_softc_t *, MSG_EVENT_NOTIFY_REPLY *);
101 1.18.2.3 tls static void mpt_bus_reset(mpt_softc_t *);
102 1.1 thorpej
103 1.1 thorpej static void mpt_scsipi_request(struct scsipi_channel *,
104 1.1 thorpej scsipi_adapter_req_t, void *);
105 1.1 thorpej static void mpt_minphys(struct buf *);
106 1.18.2.3 tls static int mpt_ioctl(struct scsipi_channel *, u_long, void *, int,
107 1.18.2.3 tls struct proc *);
108 1.18 martin
109 1.18.2.4 jdolecek #if NBIO > 0
110 1.18.2.4 jdolecek static bool mpt_is_raid(mpt_softc_t *);
111 1.18.2.4 jdolecek static int mpt_bio_ioctl(device_t, u_long, void *);
112 1.18.2.4 jdolecek static int mpt_bio_ioctl_inq(mpt_softc_t *, struct bioc_inq *);
113 1.18.2.4 jdolecek static int mpt_bio_ioctl_vol(mpt_softc_t *, struct bioc_vol *);
114 1.18.2.4 jdolecek static int mpt_bio_ioctl_disk(mpt_softc_t *, struct bioc_disk *);
115 1.18.2.4 jdolecek static int mpt_bio_ioctl_disk_novol(mpt_softc_t *, struct bioc_disk *);
116 1.18.2.4 jdolecek static int mpt_bio_ioctl_setstate(mpt_softc_t *, struct bioc_setstate *);
117 1.18.2.4 jdolecek #endif
118 1.18.2.4 jdolecek
119 1.1 thorpej void
120 1.1 thorpej mpt_scsipi_attach(mpt_softc_t *mpt)
121 1.1 thorpej {
122 1.1 thorpej struct scsipi_adapter *adapt = &mpt->sc_adapter;
123 1.1 thorpej struct scsipi_channel *chan = &mpt->sc_channel;
124 1.1 thorpej int maxq;
125 1.1 thorpej
126 1.1 thorpej mpt->bus = 0; /* XXX ?? */
127 1.1 thorpej
128 1.1 thorpej maxq = (mpt->mpt_global_credits < MPT_MAX_REQUESTS(mpt)) ?
129 1.1 thorpej mpt->mpt_global_credits : MPT_MAX_REQUESTS(mpt);
130 1.1 thorpej
131 1.1 thorpej /* Fill in the scsipi_adapter. */
132 1.1 thorpej memset(adapt, 0, sizeof(*adapt));
133 1.18 martin adapt->adapt_dev = mpt->sc_dev;
134 1.1 thorpej adapt->adapt_nchannels = 1;
135 1.17 mhitch adapt->adapt_openings = maxq - 2; /* Reserve 2 for driver use*/
136 1.17 mhitch adapt->adapt_max_periph = maxq - 2;
137 1.1 thorpej adapt->adapt_request = mpt_scsipi_request;
138 1.1 thorpej adapt->adapt_minphys = mpt_minphys;
139 1.18.2.3 tls adapt->adapt_ioctl = mpt_ioctl;
140 1.1 thorpej
141 1.1 thorpej /* Fill in the scsipi_channel. */
142 1.1 thorpej memset(chan, 0, sizeof(*chan));
143 1.1 thorpej chan->chan_adapter = adapt;
144 1.18.2.2 tls if (mpt->is_sas) {
145 1.18.2.2 tls chan->chan_bustype = &scsi_sas_bustype;
146 1.18.2.2 tls } else if (mpt->is_fc) {
147 1.18.2.2 tls chan->chan_bustype = &scsi_fc_bustype;
148 1.18.2.2 tls } else {
149 1.18.2.2 tls chan->chan_bustype = &scsi_bustype;
150 1.18.2.2 tls }
151 1.1 thorpej chan->chan_channel = 0;
152 1.1 thorpej chan->chan_flags = 0;
153 1.1 thorpej chan->chan_nluns = 8;
154 1.12 tron chan->chan_ntargets = mpt->mpt_max_devices;
155 1.12 tron chan->chan_id = mpt->mpt_ini_id;
156 1.1 thorpej
157 1.18.2.3 tls /*
158 1.18.2.3 tls * Save the output of the config so we can rescan the bus in case of
159 1.18.2.3 tls * errors
160 1.18.2.3 tls */
161 1.18.2.3 tls mpt->sc_scsibus_dv = config_found(mpt->sc_dev, &mpt->sc_channel,
162 1.18.2.3 tls scsiprint);
163 1.18.2.4 jdolecek
164 1.18.2.4 jdolecek #if NBIO > 0
165 1.18.2.4 jdolecek if (mpt_is_raid(mpt)) {
166 1.18.2.4 jdolecek if (bio_register(mpt->sc_dev, mpt_bio_ioctl) != 0)
167 1.18.2.4 jdolecek panic("%s: controller registration failed",
168 1.18.2.4 jdolecek device_xname(mpt->sc_dev));
169 1.18.2.4 jdolecek }
170 1.18.2.4 jdolecek #endif
171 1.1 thorpej }
172 1.1 thorpej
173 1.1 thorpej int
174 1.1 thorpej mpt_dma_mem_alloc(mpt_softc_t *mpt)
175 1.1 thorpej {
176 1.1 thorpej bus_dma_segment_t reply_seg, request_seg;
177 1.1 thorpej int reply_rseg, request_rseg;
178 1.1 thorpej bus_addr_t pptr, end;
179 1.11 christos char *vptr;
180 1.1 thorpej size_t len;
181 1.1 thorpej int error, i;
182 1.1 thorpej
183 1.1 thorpej /* Check if we have already allocated the reply memory. */
184 1.1 thorpej if (mpt->reply != NULL)
185 1.1 thorpej return (0);
186 1.1 thorpej
187 1.1 thorpej /*
188 1.1 thorpej * Allocate the request pool. This isn't really DMA'd memory,
189 1.1 thorpej * but it's a convenient place to do it.
190 1.1 thorpej */
191 1.1 thorpej len = sizeof(request_t) * MPT_MAX_REQUESTS(mpt);
192 1.1 thorpej mpt->request_pool = malloc(len, M_DEVBUF, M_WAITOK | M_ZERO);
193 1.1 thorpej if (mpt->request_pool == NULL) {
194 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to allocate request pool\n");
195 1.1 thorpej return (ENOMEM);
196 1.1 thorpej }
197 1.1 thorpej
198 1.1 thorpej /*
199 1.1 thorpej * Allocate DMA resources for reply buffers.
200 1.1 thorpej */
201 1.1 thorpej error = bus_dmamem_alloc(mpt->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0,
202 1.1 thorpej &reply_seg, 1, &reply_rseg, 0);
203 1.1 thorpej if (error) {
204 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to allocate reply area, error = %d\n",
205 1.14 cegger error);
206 1.1 thorpej goto fail_0;
207 1.1 thorpej }
208 1.1 thorpej
209 1.1 thorpej error = bus_dmamem_map(mpt->sc_dmat, &reply_seg, reply_rseg, PAGE_SIZE,
210 1.11 christos (void **) &mpt->reply, BUS_DMA_COHERENT/*XXX*/);
211 1.1 thorpej if (error) {
212 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to map reply area, error = %d\n",
213 1.14 cegger error);
214 1.1 thorpej goto fail_1;
215 1.1 thorpej }
216 1.1 thorpej
217 1.1 thorpej error = bus_dmamap_create(mpt->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE,
218 1.1 thorpej 0, 0, &mpt->reply_dmap);
219 1.1 thorpej if (error) {
220 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to create reply DMA map, error = %d\n",
221 1.14 cegger error);
222 1.1 thorpej goto fail_2;
223 1.1 thorpej }
224 1.1 thorpej
225 1.1 thorpej error = bus_dmamap_load(mpt->sc_dmat, mpt->reply_dmap, mpt->reply,
226 1.1 thorpej PAGE_SIZE, NULL, 0);
227 1.1 thorpej if (error) {
228 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to load reply DMA map, error = %d\n",
229 1.14 cegger error);
230 1.1 thorpej goto fail_3;
231 1.1 thorpej }
232 1.1 thorpej mpt->reply_phys = mpt->reply_dmap->dm_segs[0].ds_addr;
233 1.1 thorpej
234 1.1 thorpej /*
235 1.1 thorpej * Allocate DMA resources for request buffers.
236 1.1 thorpej */
237 1.1 thorpej error = bus_dmamem_alloc(mpt->sc_dmat, MPT_REQ_MEM_SIZE(mpt),
238 1.1 thorpej PAGE_SIZE, 0, &request_seg, 1, &request_rseg, 0);
239 1.1 thorpej if (error) {
240 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to allocate request area, "
241 1.14 cegger "error = %d\n", error);
242 1.1 thorpej goto fail_4;
243 1.1 thorpej }
244 1.1 thorpej
245 1.1 thorpej error = bus_dmamem_map(mpt->sc_dmat, &request_seg, request_rseg,
246 1.11 christos MPT_REQ_MEM_SIZE(mpt), (void **) &mpt->request, 0);
247 1.1 thorpej if (error) {
248 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to map request area, error = %d\n",
249 1.14 cegger error);
250 1.1 thorpej goto fail_5;
251 1.1 thorpej }
252 1.1 thorpej
253 1.1 thorpej error = bus_dmamap_create(mpt->sc_dmat, MPT_REQ_MEM_SIZE(mpt), 1,
254 1.1 thorpej MPT_REQ_MEM_SIZE(mpt), 0, 0, &mpt->request_dmap);
255 1.1 thorpej if (error) {
256 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to create request DMA map, "
257 1.14 cegger "error = %d\n", error);
258 1.1 thorpej goto fail_6;
259 1.1 thorpej }
260 1.1 thorpej
261 1.1 thorpej error = bus_dmamap_load(mpt->sc_dmat, mpt->request_dmap, mpt->request,
262 1.1 thorpej MPT_REQ_MEM_SIZE(mpt), NULL, 0);
263 1.1 thorpej if (error) {
264 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to load request DMA map, error = %d\n",
265 1.14 cegger error);
266 1.1 thorpej goto fail_7;
267 1.1 thorpej }
268 1.1 thorpej mpt->request_phys = mpt->request_dmap->dm_segs[0].ds_addr;
269 1.1 thorpej
270 1.1 thorpej pptr = mpt->request_phys;
271 1.11 christos vptr = (void *) mpt->request;
272 1.1 thorpej end = pptr + MPT_REQ_MEM_SIZE(mpt);
273 1.1 thorpej
274 1.1 thorpej for (i = 0; pptr < end; i++) {
275 1.1 thorpej request_t *req = &mpt->request_pool[i];
276 1.1 thorpej req->index = i;
277 1.1 thorpej
278 1.1 thorpej /* Store location of Request Data */
279 1.1 thorpej req->req_pbuf = pptr;
280 1.1 thorpej req->req_vbuf = vptr;
281 1.1 thorpej
282 1.1 thorpej pptr += MPT_REQUEST_AREA;
283 1.1 thorpej vptr += MPT_REQUEST_AREA;
284 1.1 thorpej
285 1.1 thorpej req->sense_pbuf = (pptr - MPT_SENSE_SIZE);
286 1.1 thorpej req->sense_vbuf = (vptr - MPT_SENSE_SIZE);
287 1.1 thorpej
288 1.18.2.1 tls error = bus_dmamap_create(mpt->sc_dmat,
289 1.18.2.1 tls MPT_SGL_MAX * PAGE_SIZE ,
290 1.18.2.1 tls MPT_SGL_MAX,
291 1.18.2.1 tls MPT_SGL_MAX * PAGE_SIZE,
292 1.18.2.1 tls 0, 0, &req->dmap);
293 1.1 thorpej if (error) {
294 1.18 martin aprint_error_dev(mpt->sc_dev, "unable to create req %d DMA map, "
295 1.14 cegger "error = %d\n", i, error);
296 1.1 thorpej goto fail_8;
297 1.1 thorpej }
298 1.1 thorpej }
299 1.1 thorpej
300 1.1 thorpej return (0);
301 1.1 thorpej
302 1.1 thorpej fail_8:
303 1.1 thorpej for (--i; i >= 0; i--) {
304 1.1 thorpej request_t *req = &mpt->request_pool[i];
305 1.3 thorpej if (req->dmap != NULL)
306 1.3 thorpej bus_dmamap_destroy(mpt->sc_dmat, req->dmap);
307 1.1 thorpej }
308 1.1 thorpej bus_dmamap_unload(mpt->sc_dmat, mpt->request_dmap);
309 1.1 thorpej fail_7:
310 1.1 thorpej bus_dmamap_destroy(mpt->sc_dmat, mpt->request_dmap);
311 1.1 thorpej fail_6:
312 1.11 christos bus_dmamem_unmap(mpt->sc_dmat, (void *)mpt->request, PAGE_SIZE);
313 1.1 thorpej fail_5:
314 1.1 thorpej bus_dmamem_free(mpt->sc_dmat, &request_seg, request_rseg);
315 1.1 thorpej fail_4:
316 1.1 thorpej bus_dmamap_unload(mpt->sc_dmat, mpt->reply_dmap);
317 1.1 thorpej fail_3:
318 1.1 thorpej bus_dmamap_destroy(mpt->sc_dmat, mpt->reply_dmap);
319 1.1 thorpej fail_2:
320 1.11 christos bus_dmamem_unmap(mpt->sc_dmat, (void *)mpt->reply, PAGE_SIZE);
321 1.1 thorpej fail_1:
322 1.1 thorpej bus_dmamem_free(mpt->sc_dmat, &reply_seg, reply_rseg);
323 1.1 thorpej fail_0:
324 1.1 thorpej free(mpt->request_pool, M_DEVBUF);
325 1.1 thorpej
326 1.1 thorpej mpt->reply = NULL;
327 1.1 thorpej mpt->request = NULL;
328 1.1 thorpej mpt->request_pool = NULL;
329 1.1 thorpej
330 1.1 thorpej return (error);
331 1.1 thorpej }
332 1.1 thorpej
333 1.1 thorpej int
334 1.1 thorpej mpt_intr(void *arg)
335 1.1 thorpej {
336 1.1 thorpej mpt_softc_t *mpt = arg;
337 1.1 thorpej int nrepl = 0;
338 1.1 thorpej
339 1.1 thorpej if ((mpt_read(mpt, MPT_OFFSET_INTR_STATUS) & MPT_INTR_REPLY_READY) == 0)
340 1.1 thorpej return (0);
341 1.1 thorpej
342 1.18.2.3 tls nrepl = mpt_drain_queue(mpt);
343 1.1 thorpej return (nrepl != 0);
344 1.1 thorpej }
345 1.1 thorpej
346 1.1 thorpej void
347 1.1 thorpej mpt_prt(mpt_softc_t *mpt, const char *fmt, ...)
348 1.1 thorpej {
349 1.1 thorpej va_list ap;
350 1.1 thorpej
351 1.18 martin printf("%s: ", device_xname(mpt->sc_dev));
352 1.1 thorpej va_start(ap, fmt);
353 1.1 thorpej vprintf(fmt, ap);
354 1.1 thorpej va_end(ap);
355 1.1 thorpej printf("\n");
356 1.1 thorpej }
357 1.1 thorpej
358 1.1 thorpej static int
359 1.1 thorpej mpt_poll(mpt_softc_t *mpt, struct scsipi_xfer *xs, int count)
360 1.1 thorpej {
361 1.1 thorpej
362 1.1 thorpej /* Timeouts are in msec, so we loop in 1000usec cycles */
363 1.1 thorpej while (count) {
364 1.1 thorpej mpt_intr(mpt);
365 1.1 thorpej if (xs->xs_status & XS_STS_DONE)
366 1.1 thorpej return (0);
367 1.1 thorpej delay(1000); /* only happens in boot, so ok */
368 1.1 thorpej count--;
369 1.1 thorpej }
370 1.1 thorpej return (1);
371 1.1 thorpej }
372 1.1 thorpej
373 1.1 thorpej static void
374 1.1 thorpej mpt_timeout(void *arg)
375 1.1 thorpej {
376 1.1 thorpej request_t *req = arg;
377 1.18.2.3 tls struct scsipi_xfer *xs;
378 1.18.2.3 tls struct scsipi_periph *periph;
379 1.18.2.3 tls mpt_softc_t *mpt;
380 1.18.2.3 tls uint32_t oseq;
381 1.18.2.3 tls int s, nrepl = 0;
382 1.18.2.3 tls
383 1.18.2.3 tls if (req->xfer == NULL) {
384 1.18.2.3 tls printf("mpt_timeout: NULL xfer for request index 0x%x, sequenc 0x%x\n",
385 1.18.2.3 tls req->index, req->sequence);
386 1.18.2.3 tls return;
387 1.18.2.3 tls }
388 1.18.2.3 tls xs = req->xfer;
389 1.18.2.3 tls periph = xs->xs_periph;
390 1.18.2.3 tls mpt = device_private(periph->periph_channel->chan_adapter->adapt_dev);
391 1.1 thorpej scsipi_printaddr(periph);
392 1.1 thorpej printf("command timeout\n");
393 1.1 thorpej
394 1.1 thorpej s = splbio();
395 1.1 thorpej
396 1.1 thorpej oseq = req->sequence;
397 1.1 thorpej mpt->timeouts++;
398 1.1 thorpej if (mpt_intr(mpt)) {
399 1.1 thorpej if (req->sequence != oseq) {
400 1.18.2.3 tls mpt->success++;
401 1.1 thorpej mpt_prt(mpt, "recovered from command timeout");
402 1.1 thorpej splx(s);
403 1.1 thorpej return;
404 1.1 thorpej }
405 1.1 thorpej }
406 1.18.2.3 tls
407 1.18.2.3 tls /*
408 1.18.2.3 tls * Ensure the IOC is really done giving us data since it appears it can
409 1.18.2.3 tls * sometimes fail to give us interrupts under heavy load.
410 1.18.2.3 tls */
411 1.18.2.3 tls nrepl = mpt_drain_queue(mpt);
412 1.18.2.3 tls if (nrepl ) {
413 1.18.2.3 tls mpt_prt(mpt, "mpt_timeout: recovered %d commands",nrepl);
414 1.18.2.3 tls }
415 1.18.2.3 tls
416 1.18.2.3 tls if (req->sequence != oseq) {
417 1.18.2.3 tls mpt->success++;
418 1.18.2.3 tls splx(s);
419 1.18.2.3 tls return;
420 1.18.2.3 tls }
421 1.18.2.3 tls
422 1.1 thorpej mpt_prt(mpt,
423 1.1 thorpej "timeout on request index = 0x%x, seq = 0x%08x",
424 1.1 thorpej req->index, req->sequence);
425 1.1 thorpej mpt_check_doorbell(mpt);
426 1.1 thorpej mpt_prt(mpt, "Status 0x%08x, Mask 0x%08x, Doorbell 0x%08x",
427 1.1 thorpej mpt_read(mpt, MPT_OFFSET_INTR_STATUS),
428 1.1 thorpej mpt_read(mpt, MPT_OFFSET_INTR_MASK),
429 1.1 thorpej mpt_read(mpt, MPT_OFFSET_DOORBELL));
430 1.1 thorpej mpt_prt(mpt, "request state: %s", mpt_req_state(req->debug));
431 1.1 thorpej if (mpt->verbose > 1)
432 1.1 thorpej mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req->req_vbuf);
433 1.1 thorpej
434 1.6 thorpej xs->error = XS_TIMEOUT;
435 1.18.2.3 tls splx(s);
436 1.18.2.3 tls mpt_restart(mpt, req);
437 1.18.2.3 tls }
438 1.18.2.3 tls
439 1.18.2.3 tls static void
440 1.18.2.3 tls mpt_restart(mpt_softc_t *mpt, request_t *req0)
441 1.18.2.3 tls {
442 1.18.2.3 tls int i, s, nreq;
443 1.18.2.3 tls request_t *req;
444 1.18.2.3 tls struct scsipi_xfer *xs;
445 1.18.2.3 tls
446 1.18.2.3 tls /* first, reset the IOC, leaving stopped so all requests are idle */
447 1.18.2.3 tls if (mpt_soft_reset(mpt) != MPT_OK) {
448 1.18.2.3 tls mpt_prt(mpt, "soft reset failed");
449 1.18.2.3 tls /*
450 1.18.2.3 tls * Don't try a hard reset since this mangles the PCI
451 1.18.2.3 tls * configuration registers.
452 1.18.2.3 tls */
453 1.18.2.3 tls return;
454 1.18.2.3 tls }
455 1.18.2.3 tls
456 1.18.2.3 tls /* Freeze the channel so scsipi doesn't queue more commands. */
457 1.18.2.3 tls scsipi_channel_freeze(&mpt->sc_channel, 1);
458 1.6 thorpej
459 1.18.2.3 tls /* Return all pending requests to scsipi and de-allocate them. */
460 1.18.2.3 tls s = splbio();
461 1.18.2.3 tls nreq = 0;
462 1.18.2.3 tls for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) {
463 1.18.2.3 tls req = &mpt->request_pool[i];
464 1.18.2.3 tls xs = req->xfer;
465 1.18.2.3 tls if (xs != NULL) {
466 1.18.2.3 tls if (xs->datalen != 0)
467 1.18.2.3 tls bus_dmamap_unload(mpt->sc_dmat, req->dmap);
468 1.18.2.3 tls req->xfer = NULL;
469 1.18.2.3 tls callout_stop(&xs->xs_callout);
470 1.18.2.3 tls if (req != req0) {
471 1.18.2.3 tls nreq++;
472 1.18.2.3 tls xs->error = XS_REQUEUE;
473 1.18.2.3 tls }
474 1.18.2.3 tls scsipi_done(xs);
475 1.18.2.3 tls /*
476 1.18.2.3 tls * Don't need to mpt_free_request() since mpt_init()
477 1.18.2.3 tls * below will free all requests anyway.
478 1.18.2.3 tls */
479 1.18.2.3 tls mpt_free_request(mpt, req);
480 1.18.2.3 tls }
481 1.18.2.3 tls }
482 1.1 thorpej splx(s);
483 1.18.2.3 tls if (nreq > 0)
484 1.18.2.3 tls mpt_prt(mpt, "re-queued %d requests", nreq);
485 1.18.2.3 tls
486 1.18.2.3 tls /* Re-initialize the IOC (which restarts it). */
487 1.18.2.3 tls if (mpt_init(mpt, MPT_DB_INIT_HOST) == 0)
488 1.18.2.3 tls mpt_prt(mpt, "restart succeeded");
489 1.18.2.3 tls /* else error message already printed */
490 1.18.2.3 tls
491 1.18.2.3 tls /* Thaw the channel, causing scsipi to re-queue the commands. */
492 1.18.2.3 tls scsipi_channel_thaw(&mpt->sc_channel, 1);
493 1.18.2.3 tls }
494 1.18.2.3 tls
495 1.18.2.3 tls static int
496 1.18.2.3 tls mpt_drain_queue(mpt_softc_t *mpt)
497 1.18.2.3 tls {
498 1.18.2.3 tls int nrepl = 0;
499 1.18.2.3 tls uint32_t reply;
500 1.18.2.3 tls
501 1.18.2.3 tls reply = mpt_pop_reply_queue(mpt);
502 1.18.2.3 tls while (reply != MPT_REPLY_EMPTY) {
503 1.18.2.3 tls nrepl++;
504 1.18.2.3 tls if (mpt->verbose > 1) {
505 1.18.2.3 tls if ((reply & MPT_CONTEXT_REPLY) != 0) {
506 1.18.2.3 tls /* Address reply; IOC has something to say */
507 1.18.2.3 tls mpt_print_reply(MPT_REPLY_PTOV(mpt, reply));
508 1.18.2.3 tls } else {
509 1.18.2.3 tls /* Context reply; all went well */
510 1.18.2.3 tls mpt_prt(mpt, "context %u reply OK", reply);
511 1.18.2.3 tls }
512 1.18.2.3 tls }
513 1.18.2.3 tls mpt_done(mpt, reply);
514 1.18.2.3 tls reply = mpt_pop_reply_queue(mpt);
515 1.18.2.3 tls }
516 1.18.2.3 tls return (nrepl);
517 1.1 thorpej }
518 1.1 thorpej
519 1.1 thorpej static void
520 1.1 thorpej mpt_done(mpt_softc_t *mpt, uint32_t reply)
521 1.1 thorpej {
522 1.6 thorpej struct scsipi_xfer *xs = NULL;
523 1.1 thorpej struct scsipi_periph *periph;
524 1.1 thorpej int index;
525 1.1 thorpej request_t *req;
526 1.1 thorpej MSG_REQUEST_HEADER *mpt_req;
527 1.1 thorpej MSG_SCSI_IO_REPLY *mpt_reply;
528 1.18.2.3 tls int restart = 0; /* nonzero if we need to restart the IOC*/
529 1.1 thorpej
530 1.1 thorpej if (__predict_true((reply & MPT_CONTEXT_REPLY) == 0)) {
531 1.1 thorpej /* context reply (ok) */
532 1.1 thorpej mpt_reply = NULL;
533 1.1 thorpej index = reply & MPT_CONTEXT_MASK;
534 1.1 thorpej } else {
535 1.1 thorpej /* address reply (error) */
536 1.1 thorpej
537 1.1 thorpej /* XXX BUS_DMASYNC_POSTREAD XXX */
538 1.1 thorpej mpt_reply = MPT_REPLY_PTOV(mpt, reply);
539 1.18.2.3 tls if (mpt_reply != NULL) {
540 1.18.2.3 tls if (mpt->verbose > 1) {
541 1.18.2.3 tls uint32_t *pReply = (uint32_t *) mpt_reply;
542 1.9 perry
543 1.18.2.3 tls mpt_prt(mpt, "Address Reply (index %u):",
544 1.18.2.3 tls le32toh(mpt_reply->MsgContext) & 0xffff);
545 1.18.2.3 tls mpt_prt(mpt, "%08x %08x %08x %08x", pReply[0],
546 1.18.2.3 tls pReply[1], pReply[2], pReply[3]);
547 1.18.2.3 tls mpt_prt(mpt, "%08x %08x %08x %08x", pReply[4],
548 1.18.2.3 tls pReply[5], pReply[6], pReply[7]);
549 1.18.2.3 tls mpt_prt(mpt, "%08x %08x %08x %08x", pReply[8],
550 1.18.2.3 tls pReply[9], pReply[10], pReply[11]);
551 1.18.2.3 tls }
552 1.18.2.3 tls index = le32toh(mpt_reply->MsgContext);
553 1.18.2.3 tls } else
554 1.18.2.3 tls index = reply & MPT_CONTEXT_MASK;
555 1.1 thorpej }
556 1.1 thorpej
557 1.1 thorpej /*
558 1.1 thorpej * Address reply with MessageContext high bit set.
559 1.1 thorpej * This is most likely a notify message, so we try
560 1.1 thorpej * to process it, then free it.
561 1.1 thorpej */
562 1.1 thorpej if (__predict_false((index & 0x80000000) != 0)) {
563 1.1 thorpej if (mpt_reply != NULL)
564 1.1 thorpej mpt_ctlop(mpt, mpt_reply, reply);
565 1.1 thorpej else
566 1.18.2.3 tls mpt_prt(mpt, "%s: index 0x%x, NULL reply", __func__,
567 1.18.2.3 tls index);
568 1.1 thorpej return;
569 1.1 thorpej }
570 1.1 thorpej
571 1.1 thorpej /* Did we end up with a valid index into the table? */
572 1.1 thorpej if (__predict_false(index < 0 || index >= MPT_MAX_REQUESTS(mpt))) {
573 1.18.2.3 tls mpt_prt(mpt, "%s: invalid index (0x%x) in reply", __func__,
574 1.18.2.3 tls index);
575 1.1 thorpej return;
576 1.1 thorpej }
577 1.1 thorpej
578 1.1 thorpej req = &mpt->request_pool[index];
579 1.1 thorpej
580 1.1 thorpej /* Make sure memory hasn't been trashed. */
581 1.1 thorpej if (__predict_false(req->index != index)) {
582 1.18.2.3 tls mpt_prt(mpt, "%s: corrupted request_t (0x%x)", __func__,
583 1.18.2.3 tls index);
584 1.1 thorpej return;
585 1.1 thorpej }
586 1.1 thorpej
587 1.2 thorpej MPT_SYNC_REQ(mpt, req, BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
588 1.1 thorpej mpt_req = req->req_vbuf;
589 1.1 thorpej
590 1.1 thorpej /* Short cut for task management replies; nothing more for us to do. */
591 1.1 thorpej if (__predict_false(mpt_req->Function == MPI_FUNCTION_SCSI_TASK_MGMT)) {
592 1.1 thorpej if (mpt->verbose > 1)
593 1.18.2.3 tls mpt_prt(mpt, "%s: TASK MGMT", __func__);
594 1.18.2.3 tls KASSERT(req == mpt->mngt_req);
595 1.18.2.3 tls mpt->mngt_req = NULL;
596 1.1 thorpej goto done;
597 1.1 thorpej }
598 1.1 thorpej
599 1.1 thorpej if (__predict_false(mpt_req->Function == MPI_FUNCTION_PORT_ENABLE))
600 1.1 thorpej goto done;
601 1.1 thorpej
602 1.1 thorpej /*
603 1.1 thorpej * At this point, it had better be a SCSI I/O command, but don't
604 1.1 thorpej * crash if it isn't.
605 1.1 thorpej */
606 1.1 thorpej if (__predict_false(mpt_req->Function !=
607 1.1 thorpej MPI_FUNCTION_SCSI_IO_REQUEST)) {
608 1.1 thorpej if (mpt->verbose > 1)
609 1.18.2.3 tls mpt_prt(mpt, "%s: unknown Function 0x%x (0x%x)",
610 1.18.2.3 tls __func__, mpt_req->Function, index);
611 1.1 thorpej goto done;
612 1.1 thorpej }
613 1.1 thorpej
614 1.1 thorpej /* Recover scsipi_xfer from the request structure. */
615 1.1 thorpej xs = req->xfer;
616 1.1 thorpej
617 1.1 thorpej /* Can't have a SCSI command without a scsipi_xfer. */
618 1.1 thorpej if (__predict_false(xs == NULL)) {
619 1.1 thorpej mpt_prt(mpt,
620 1.18.2.3 tls "%s: no scsipi_xfer, index = 0x%x, seq = 0x%08x", __func__,
621 1.1 thorpej req->index, req->sequence);
622 1.1 thorpej mpt_prt(mpt, "request state: %s", mpt_req_state(req->debug));
623 1.1 thorpej mpt_prt(mpt, "mpt_request:");
624 1.1 thorpej mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req->req_vbuf);
625 1.1 thorpej
626 1.1 thorpej if (mpt_reply != NULL) {
627 1.1 thorpej mpt_prt(mpt, "mpt_reply:");
628 1.1 thorpej mpt_print_reply(mpt_reply);
629 1.1 thorpej } else {
630 1.1 thorpej mpt_prt(mpt, "context reply: 0x%08x", reply);
631 1.1 thorpej }
632 1.1 thorpej goto done;
633 1.1 thorpej }
634 1.1 thorpej
635 1.1 thorpej callout_stop(&xs->xs_callout);
636 1.1 thorpej
637 1.1 thorpej periph = xs->xs_periph;
638 1.1 thorpej
639 1.1 thorpej /*
640 1.1 thorpej * If we were a data transfer, unload the map that described
641 1.1 thorpej * the data buffer.
642 1.1 thorpej */
643 1.1 thorpej if (__predict_true(xs->datalen != 0)) {
644 1.1 thorpej bus_dmamap_sync(mpt->sc_dmat, req->dmap, 0,
645 1.1 thorpej req->dmap->dm_mapsize,
646 1.1 thorpej (xs->xs_control & XS_CTL_DATA_IN) ? BUS_DMASYNC_POSTREAD
647 1.1 thorpej : BUS_DMASYNC_POSTWRITE);
648 1.1 thorpej bus_dmamap_unload(mpt->sc_dmat, req->dmap);
649 1.1 thorpej }
650 1.1 thorpej
651 1.1 thorpej if (__predict_true(mpt_reply == NULL)) {
652 1.1 thorpej /*
653 1.1 thorpej * Context reply; report that the command was
654 1.1 thorpej * successful!
655 1.1 thorpej *
656 1.1 thorpej * Also report the xfer mode, if necessary.
657 1.1 thorpej */
658 1.1 thorpej if (__predict_false(mpt->mpt_report_xfer_mode != 0)) {
659 1.1 thorpej if ((mpt->mpt_report_xfer_mode &
660 1.1 thorpej (1 << periph->periph_target)) != 0)
661 1.1 thorpej mpt_get_xfer_mode(mpt, periph);
662 1.1 thorpej }
663 1.1 thorpej xs->error = XS_NOERROR;
664 1.1 thorpej xs->status = SCSI_OK;
665 1.1 thorpej xs->resid = 0;
666 1.6 thorpej mpt_free_request(mpt, req);
667 1.1 thorpej scsipi_done(xs);
668 1.6 thorpej return;
669 1.1 thorpej }
670 1.1 thorpej
671 1.1 thorpej xs->status = mpt_reply->SCSIStatus;
672 1.18.2.3 tls switch (le16toh(mpt_reply->IOCStatus) & MPI_IOCSTATUS_MASK) {
673 1.1 thorpej case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:
674 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
675 1.18.2.3 tls mpt_prt(mpt, "%s: IOC overrun!", __func__);
676 1.1 thorpej break;
677 1.1 thorpej
678 1.1 thorpej case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:
679 1.1 thorpej /*
680 1.1 thorpej * Yikes! Tagged queue full comes through this path!
681 1.1 thorpej *
682 1.1 thorpej * So we'll change it to a status error and anything
683 1.1 thorpej * that returns status should probably be a status
684 1.1 thorpej * error as well.
685 1.1 thorpej */
686 1.15 chs xs->resid = xs->datalen - le32toh(mpt_reply->TransferCount);
687 1.1 thorpej if (mpt_reply->SCSIState &
688 1.1 thorpej MPI_SCSI_STATE_NO_SCSI_STATUS) {
689 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
690 1.1 thorpej break;
691 1.1 thorpej }
692 1.1 thorpej /* FALLTHROUGH */
693 1.1 thorpej case MPI_IOCSTATUS_SUCCESS:
694 1.1 thorpej case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR:
695 1.1 thorpej switch (xs->status) {
696 1.1 thorpej case SCSI_OK:
697 1.1 thorpej /* Report the xfer mode, if necessary. */
698 1.1 thorpej if ((mpt->mpt_report_xfer_mode &
699 1.1 thorpej (1 << periph->periph_target)) != 0)
700 1.1 thorpej mpt_get_xfer_mode(mpt, periph);
701 1.1 thorpej xs->resid = 0;
702 1.1 thorpej break;
703 1.1 thorpej
704 1.1 thorpej case SCSI_CHECK:
705 1.1 thorpej xs->error = XS_SENSE;
706 1.1 thorpej break;
707 1.1 thorpej
708 1.1 thorpej case SCSI_BUSY:
709 1.1 thorpej case SCSI_QUEUE_FULL:
710 1.1 thorpej xs->error = XS_BUSY;
711 1.1 thorpej break;
712 1.1 thorpej
713 1.1 thorpej default:
714 1.1 thorpej scsipi_printaddr(periph);
715 1.1 thorpej printf("invalid status code %d\n", xs->status);
716 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
717 1.1 thorpej break;
718 1.1 thorpej }
719 1.1 thorpej break;
720 1.1 thorpej
721 1.1 thorpej case MPI_IOCSTATUS_BUSY:
722 1.1 thorpej case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:
723 1.1 thorpej xs->error = XS_RESOURCE_SHORTAGE;
724 1.1 thorpej break;
725 1.1 thorpej
726 1.1 thorpej case MPI_IOCSTATUS_SCSI_INVALID_BUS:
727 1.1 thorpej case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:
728 1.1 thorpej case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
729 1.1 thorpej xs->error = XS_SELTIMEOUT;
730 1.1 thorpej break;
731 1.1 thorpej
732 1.1 thorpej case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
733 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
734 1.18.2.3 tls mpt_prt(mpt, "%s: IOC SCSI residual mismatch!", __func__);
735 1.18.2.3 tls restart = 1;
736 1.1 thorpej break;
737 1.1 thorpej
738 1.1 thorpej case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:
739 1.1 thorpej /* XXX What should we do here? */
740 1.18.2.3 tls mpt_prt(mpt, "%s: IOC SCSI task terminated!", __func__);
741 1.18.2.3 tls restart = 1;
742 1.1 thorpej break;
743 1.1 thorpej
744 1.1 thorpej case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
745 1.1 thorpej /* XXX */
746 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
747 1.18.2.3 tls mpt_prt(mpt, "%s: IOC SCSI task failed!", __func__);
748 1.18.2.3 tls restart = 1;
749 1.1 thorpej break;
750 1.1 thorpej
751 1.1 thorpej case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:
752 1.1 thorpej /* XXX */
753 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
754 1.18.2.3 tls mpt_prt(mpt, "%s: IOC task terminated!", __func__);
755 1.18.2.3 tls restart = 1;
756 1.1 thorpej break;
757 1.1 thorpej
758 1.1 thorpej case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:
759 1.1 thorpej /* XXX This is a bus-reset */
760 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
761 1.18.2.3 tls mpt_prt(mpt, "%s: IOC SCSI bus reset!", __func__);
762 1.18.2.3 tls restart = 1;
763 1.18.2.3 tls break;
764 1.18.2.3 tls
765 1.18.2.3 tls case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:
766 1.18.2.3 tls /*
767 1.18.2.3 tls * FreeBSD and Linux indicate this is a phase error between
768 1.18.2.3 tls * the IOC and the drive itself. When this happens, the IOC
769 1.18.2.3 tls * becomes unhappy and stops processing all transactions.
770 1.18.2.3 tls * Call mpt_timeout which knows how to get the IOC back
771 1.18.2.3 tls * on its feet.
772 1.18.2.3 tls */
773 1.18.2.3 tls mpt_prt(mpt, "%s: IOC indicates protocol error -- "
774 1.18.2.3 tls "recovering...", __func__);
775 1.18.2.3 tls xs->error = XS_TIMEOUT;
776 1.18.2.3 tls restart = 1;
777 1.18.2.3 tls
778 1.1 thorpej break;
779 1.1 thorpej
780 1.1 thorpej default:
781 1.1 thorpej /* XXX unrecognized HBA error */
782 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
783 1.18.2.3 tls mpt_prt(mpt, "%s: IOC returned unknown code: 0x%x", __func__,
784 1.18.2.3 tls le16toh(mpt_reply->IOCStatus));
785 1.18.2.3 tls restart = 1;
786 1.1 thorpej break;
787 1.1 thorpej }
788 1.9 perry
789 1.18.2.3 tls if (mpt_reply != NULL) {
790 1.18.2.3 tls if (mpt_reply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
791 1.18.2.3 tls memcpy(&xs->sense.scsi_sense, req->sense_vbuf,
792 1.18.2.3 tls sizeof(xs->sense.scsi_sense));
793 1.18.2.3 tls } else if (mpt_reply->SCSIState &
794 1.18.2.3 tls MPI_SCSI_STATE_AUTOSENSE_FAILED) {
795 1.18.2.3 tls /*
796 1.18.2.3 tls * This will cause the scsipi layer to issue
797 1.18.2.3 tls * a REQUEST SENSE.
798 1.18.2.3 tls */
799 1.18.2.3 tls if (xs->status == SCSI_CHECK)
800 1.18.2.3 tls xs->error = XS_BUSY;
801 1.18.2.3 tls }
802 1.1 thorpej }
803 1.1 thorpej
804 1.1 thorpej done:
805 1.18.2.3 tls if (mpt_reply != NULL && le16toh(mpt_reply->IOCStatus) &
806 1.18.2.3 tls MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
807 1.18.2.3 tls mpt_prt(mpt, "%s: IOC has error - logging...\n", __func__);
808 1.18.2.3 tls mpt_ctlop(mpt, mpt_reply, reply);
809 1.18.2.3 tls }
810 1.18.2.3 tls
811 1.18.2.3 tls /* If IOC done with this request, free it up. */
812 1.1 thorpej if (mpt_reply == NULL || (mpt_reply->MsgFlags & 0x80) == 0)
813 1.1 thorpej mpt_free_request(mpt, req);
814 1.1 thorpej
815 1.1 thorpej /* If address reply, give the buffer back to the IOC. */
816 1.1 thorpej if (mpt_reply != NULL)
817 1.1 thorpej mpt_free_reply(mpt, (reply << 1));
818 1.6 thorpej
819 1.6 thorpej if (xs != NULL)
820 1.6 thorpej scsipi_done(xs);
821 1.18.2.3 tls
822 1.18.2.3 tls if (restart) {
823 1.18.2.3 tls mpt_prt(mpt, "%s: IOC fatal error: restarting...", __func__);
824 1.18.2.3 tls mpt_restart(mpt, NULL);
825 1.18.2.3 tls }
826 1.1 thorpej }
827 1.1 thorpej
828 1.1 thorpej static void
829 1.1 thorpej mpt_run_xfer(mpt_softc_t *mpt, struct scsipi_xfer *xs)
830 1.1 thorpej {
831 1.1 thorpej struct scsipi_periph *periph = xs->xs_periph;
832 1.1 thorpej request_t *req;
833 1.1 thorpej MSG_SCSI_IO_REQUEST *mpt_req;
834 1.1 thorpej int error, s;
835 1.1 thorpej
836 1.1 thorpej s = splbio();
837 1.1 thorpej req = mpt_get_request(mpt);
838 1.1 thorpej if (__predict_false(req == NULL)) {
839 1.1 thorpej /* This should happen very infrequently. */
840 1.1 thorpej xs->error = XS_RESOURCE_SHORTAGE;
841 1.1 thorpej scsipi_done(xs);
842 1.1 thorpej splx(s);
843 1.1 thorpej return;
844 1.1 thorpej }
845 1.1 thorpej splx(s);
846 1.1 thorpej
847 1.1 thorpej /* Link the req and the scsipi_xfer. */
848 1.1 thorpej req->xfer = xs;
849 1.1 thorpej
850 1.1 thorpej /* Now we build the command for the IOC */
851 1.1 thorpej mpt_req = req->req_vbuf;
852 1.1 thorpej memset(mpt_req, 0, sizeof(*mpt_req));
853 1.1 thorpej
854 1.1 thorpej mpt_req->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
855 1.1 thorpej mpt_req->Bus = mpt->bus;
856 1.1 thorpej
857 1.1 thorpej mpt_req->SenseBufferLength =
858 1.1 thorpej (sizeof(xs->sense.scsi_sense) < MPT_SENSE_SIZE) ?
859 1.1 thorpej sizeof(xs->sense.scsi_sense) : MPT_SENSE_SIZE;
860 1.1 thorpej
861 1.1 thorpej /*
862 1.1 thorpej * We use the message context to find the request structure when
863 1.1 thorpej * we get the command completion interrupt from the IOC.
864 1.1 thorpej */
865 1.15 chs mpt_req->MsgContext = htole32(req->index);
866 1.1 thorpej
867 1.1 thorpej /* Which physical device to do the I/O on. */
868 1.1 thorpej mpt_req->TargetID = periph->periph_target;
869 1.1 thorpej mpt_req->LUN[1] = periph->periph_lun;
870 1.1 thorpej
871 1.1 thorpej /* Set the direction of the transfer. */
872 1.1 thorpej if (xs->xs_control & XS_CTL_DATA_IN)
873 1.1 thorpej mpt_req->Control = MPI_SCSIIO_CONTROL_READ;
874 1.1 thorpej else if (xs->xs_control & XS_CTL_DATA_OUT)
875 1.1 thorpej mpt_req->Control = MPI_SCSIIO_CONTROL_WRITE;
876 1.1 thorpej else
877 1.1 thorpej mpt_req->Control = MPI_SCSIIO_CONTROL_NODATATRANSFER;
878 1.1 thorpej
879 1.1 thorpej /* Set the queue behavior. */
880 1.12 tron if (__predict_true((!mpt->is_scsi) ||
881 1.1 thorpej (mpt->mpt_tag_enable &
882 1.1 thorpej (1 << periph->periph_target)))) {
883 1.1 thorpej switch (XS_CTL_TAGTYPE(xs)) {
884 1.1 thorpej case XS_CTL_HEAD_TAG:
885 1.1 thorpej mpt_req->Control |= MPI_SCSIIO_CONTROL_HEADOFQ;
886 1.1 thorpej break;
887 1.1 thorpej
888 1.1 thorpej #if 0 /* XXX */
889 1.1 thorpej case XS_CTL_ACA_TAG:
890 1.1 thorpej mpt_req->Control |= MPI_SCSIIO_CONTROL_ACAQ;
891 1.1 thorpej break;
892 1.1 thorpej #endif
893 1.1 thorpej
894 1.1 thorpej case XS_CTL_ORDERED_TAG:
895 1.1 thorpej mpt_req->Control |= MPI_SCSIIO_CONTROL_ORDEREDQ;
896 1.1 thorpej break;
897 1.1 thorpej
898 1.1 thorpej case XS_CTL_SIMPLE_TAG:
899 1.1 thorpej mpt_req->Control |= MPI_SCSIIO_CONTROL_SIMPLEQ;
900 1.1 thorpej break;
901 1.1 thorpej
902 1.1 thorpej default:
903 1.12 tron if (mpt->is_scsi)
904 1.12 tron mpt_req->Control |= MPI_SCSIIO_CONTROL_UNTAGGED;
905 1.12 tron else
906 1.1 thorpej mpt_req->Control |= MPI_SCSIIO_CONTROL_SIMPLEQ;
907 1.1 thorpej break;
908 1.1 thorpej }
909 1.1 thorpej } else
910 1.1 thorpej mpt_req->Control |= MPI_SCSIIO_CONTROL_UNTAGGED;
911 1.1 thorpej
912 1.12 tron if (__predict_false(mpt->is_scsi &&
913 1.1 thorpej (mpt->mpt_disc_enable &
914 1.1 thorpej (1 << periph->periph_target)) == 0))
915 1.1 thorpej mpt_req->Control |= MPI_SCSIIO_CONTROL_NO_DISCONNECT;
916 1.1 thorpej
917 1.15 chs mpt_req->Control = htole32(mpt_req->Control);
918 1.15 chs
919 1.1 thorpej /* Copy the SCSI command block into place. */
920 1.1 thorpej memcpy(mpt_req->CDB, xs->cmd, xs->cmdlen);
921 1.1 thorpej
922 1.1 thorpej mpt_req->CDBLength = xs->cmdlen;
923 1.15 chs mpt_req->DataLength = htole32(xs->datalen);
924 1.15 chs mpt_req->SenseBufferLowAddr = htole32(req->sense_pbuf);
925 1.1 thorpej
926 1.1 thorpej /*
927 1.1 thorpej * Map the DMA transfer.
928 1.1 thorpej */
929 1.1 thorpej if (xs->datalen) {
930 1.1 thorpej SGE_SIMPLE32 *se;
931 1.1 thorpej
932 1.1 thorpej error = bus_dmamap_load(mpt->sc_dmat, req->dmap, xs->data,
933 1.1 thorpej xs->datalen, NULL,
934 1.1 thorpej ((xs->xs_control & XS_CTL_NOSLEEP) ? BUS_DMA_NOWAIT
935 1.1 thorpej : BUS_DMA_WAITOK) |
936 1.1 thorpej BUS_DMA_STREAMING |
937 1.1 thorpej ((xs->xs_control & XS_CTL_DATA_IN) ? BUS_DMA_READ
938 1.1 thorpej : BUS_DMA_WRITE));
939 1.1 thorpej switch (error) {
940 1.1 thorpej case 0:
941 1.1 thorpej break;
942 1.1 thorpej
943 1.1 thorpej case ENOMEM:
944 1.1 thorpej case EAGAIN:
945 1.1 thorpej xs->error = XS_RESOURCE_SHORTAGE;
946 1.1 thorpej goto out_bad;
947 1.1 thorpej
948 1.1 thorpej default:
949 1.1 thorpej xs->error = XS_DRIVER_STUFFUP;
950 1.1 thorpej mpt_prt(mpt, "error %d loading DMA map", error);
951 1.1 thorpej out_bad:
952 1.1 thorpej s = splbio();
953 1.1 thorpej mpt_free_request(mpt, req);
954 1.1 thorpej scsipi_done(xs);
955 1.1 thorpej splx(s);
956 1.1 thorpej return;
957 1.1 thorpej }
958 1.1 thorpej
959 1.1 thorpej if (req->dmap->dm_nsegs > MPT_NSGL_FIRST(mpt)) {
960 1.1 thorpej int seg, i, nleft = req->dmap->dm_nsegs;
961 1.1 thorpej uint32_t flags;
962 1.1 thorpej SGE_CHAIN32 *ce;
963 1.1 thorpej
964 1.1 thorpej seg = 0;
965 1.1 thorpej flags = MPI_SGE_FLAGS_SIMPLE_ELEMENT;
966 1.1 thorpej if (xs->xs_control & XS_CTL_DATA_OUT)
967 1.1 thorpej flags |= MPI_SGE_FLAGS_HOST_TO_IOC;
968 1.1 thorpej
969 1.1 thorpej se = (SGE_SIMPLE32 *) &mpt_req->SGL;
970 1.1 thorpej for (i = 0; i < MPT_NSGL_FIRST(mpt) - 1;
971 1.1 thorpej i++, se++, seg++) {
972 1.1 thorpej uint32_t tf;
973 1.1 thorpej
974 1.1 thorpej memset(se, 0, sizeof(*se));
975 1.15 chs se->Address =
976 1.15 chs htole32(req->dmap->dm_segs[seg].ds_addr);
977 1.1 thorpej MPI_pSGE_SET_LENGTH(se,
978 1.1 thorpej req->dmap->dm_segs[seg].ds_len);
979 1.1 thorpej tf = flags;
980 1.1 thorpej if (i == MPT_NSGL_FIRST(mpt) - 2)
981 1.1 thorpej tf |= MPI_SGE_FLAGS_LAST_ELEMENT;
982 1.1 thorpej MPI_pSGE_SET_FLAGS(se, tf);
983 1.15 chs se->FlagsLength = htole32(se->FlagsLength);
984 1.1 thorpej nleft--;
985 1.1 thorpej }
986 1.1 thorpej
987 1.1 thorpej /*
988 1.1 thorpej * Tell the IOC where to find the first chain element.
989 1.1 thorpej */
990 1.1 thorpej mpt_req->ChainOffset =
991 1.1 thorpej ((char *)se - (char *)mpt_req) >> 2;
992 1.1 thorpej
993 1.1 thorpej /*
994 1.1 thorpej * Until we're finished with all segments...
995 1.1 thorpej */
996 1.1 thorpej while (nleft) {
997 1.1 thorpej int ntodo;
998 1.1 thorpej
999 1.1 thorpej /*
1000 1.1 thorpej * Construct the chain element that points to
1001 1.1 thorpej * the next segment.
1002 1.1 thorpej */
1003 1.1 thorpej ce = (SGE_CHAIN32 *) se++;
1004 1.1 thorpej if (nleft > MPT_NSGL(mpt)) {
1005 1.1 thorpej ntodo = MPT_NSGL(mpt) - 1;
1006 1.1 thorpej ce->NextChainOffset = (MPT_RQSL(mpt) -
1007 1.1 thorpej sizeof(SGE_SIMPLE32)) >> 2;
1008 1.15 chs ce->Length = htole16(MPT_NSGL(mpt)
1009 1.15 chs * sizeof(SGE_SIMPLE32));
1010 1.1 thorpej } else {
1011 1.1 thorpej ntodo = nleft;
1012 1.1 thorpej ce->NextChainOffset = 0;
1013 1.15 chs ce->Length = htole16(ntodo
1014 1.15 chs * sizeof(SGE_SIMPLE32));
1015 1.1 thorpej }
1016 1.15 chs ce->Address = htole32(req->req_pbuf +
1017 1.15 chs ((char *)se - (char *)mpt_req));
1018 1.1 thorpej ce->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT;
1019 1.1 thorpej for (i = 0; i < ntodo; i++, se++, seg++) {
1020 1.1 thorpej uint32_t tf;
1021 1.1 thorpej
1022 1.1 thorpej memset(se, 0, sizeof(*se));
1023 1.15 chs se->Address = htole32(
1024 1.15 chs req->dmap->dm_segs[seg].ds_addr);
1025 1.1 thorpej MPI_pSGE_SET_LENGTH(se,
1026 1.1 thorpej req->dmap->dm_segs[seg].ds_len);
1027 1.1 thorpej tf = flags;
1028 1.1 thorpej if (i == ntodo - 1) {
1029 1.1 thorpej tf |=
1030 1.1 thorpej MPI_SGE_FLAGS_LAST_ELEMENT;
1031 1.1 thorpej if (ce->NextChainOffset == 0) {
1032 1.1 thorpej tf |=
1033 1.1 thorpej MPI_SGE_FLAGS_END_OF_LIST |
1034 1.1 thorpej MPI_SGE_FLAGS_END_OF_BUFFER;
1035 1.1 thorpej }
1036 1.1 thorpej }
1037 1.1 thorpej MPI_pSGE_SET_FLAGS(se, tf);
1038 1.15 chs se->FlagsLength =
1039 1.15 chs htole32(se->FlagsLength);
1040 1.1 thorpej nleft--;
1041 1.1 thorpej }
1042 1.1 thorpej }
1043 1.1 thorpej bus_dmamap_sync(mpt->sc_dmat, req->dmap, 0,
1044 1.1 thorpej req->dmap->dm_mapsize,
1045 1.1 thorpej (xs->xs_control & XS_CTL_DATA_IN) ?
1046 1.1 thorpej BUS_DMASYNC_PREREAD
1047 1.1 thorpej : BUS_DMASYNC_PREWRITE);
1048 1.1 thorpej } else {
1049 1.1 thorpej int i;
1050 1.1 thorpej uint32_t flags;
1051 1.1 thorpej
1052 1.1 thorpej flags = MPI_SGE_FLAGS_SIMPLE_ELEMENT;
1053 1.1 thorpej if (xs->xs_control & XS_CTL_DATA_OUT)
1054 1.1 thorpej flags |= MPI_SGE_FLAGS_HOST_TO_IOC;
1055 1.1 thorpej
1056 1.1 thorpej /* Copy the segments into our SG list. */
1057 1.1 thorpej se = (SGE_SIMPLE32 *) &mpt_req->SGL;
1058 1.1 thorpej for (i = 0; i < req->dmap->dm_nsegs;
1059 1.1 thorpej i++, se++) {
1060 1.1 thorpej uint32_t tf;
1061 1.1 thorpej
1062 1.1 thorpej memset(se, 0, sizeof(*se));
1063 1.15 chs se->Address =
1064 1.15 chs htole32(req->dmap->dm_segs[i].ds_addr);
1065 1.1 thorpej MPI_pSGE_SET_LENGTH(se,
1066 1.1 thorpej req->dmap->dm_segs[i].ds_len);
1067 1.1 thorpej tf = flags;
1068 1.1 thorpej if (i == req->dmap->dm_nsegs - 1) {
1069 1.1 thorpej tf |=
1070 1.1 thorpej MPI_SGE_FLAGS_LAST_ELEMENT |
1071 1.1 thorpej MPI_SGE_FLAGS_END_OF_BUFFER |
1072 1.1 thorpej MPI_SGE_FLAGS_END_OF_LIST;
1073 1.1 thorpej }
1074 1.1 thorpej MPI_pSGE_SET_FLAGS(se, tf);
1075 1.15 chs se->FlagsLength = htole32(se->FlagsLength);
1076 1.1 thorpej }
1077 1.1 thorpej bus_dmamap_sync(mpt->sc_dmat, req->dmap, 0,
1078 1.1 thorpej req->dmap->dm_mapsize,
1079 1.1 thorpej (xs->xs_control & XS_CTL_DATA_IN) ?
1080 1.1 thorpej BUS_DMASYNC_PREREAD
1081 1.1 thorpej : BUS_DMASYNC_PREWRITE);
1082 1.1 thorpej }
1083 1.1 thorpej } else {
1084 1.1 thorpej /*
1085 1.1 thorpej * No data to transfer; just make a single simple SGL
1086 1.1 thorpej * with zero length.
1087 1.1 thorpej */
1088 1.1 thorpej SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) &mpt_req->SGL;
1089 1.1 thorpej memset(se, 0, sizeof(*se));
1090 1.1 thorpej MPI_pSGE_SET_FLAGS(se,
1091 1.1 thorpej (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
1092 1.1 thorpej MPI_SGE_FLAGS_SIMPLE_ELEMENT | MPI_SGE_FLAGS_END_OF_LIST));
1093 1.15 chs se->FlagsLength = htole32(se->FlagsLength);
1094 1.1 thorpej }
1095 1.1 thorpej
1096 1.1 thorpej if (mpt->verbose > 1)
1097 1.1 thorpej mpt_print_scsi_io_request(mpt_req);
1098 1.1 thorpej
1099 1.18.2.3 tls if (xs->timeout == 0) {
1100 1.18.2.3 tls mpt_prt(mpt, "mpt_run_xfer: no timeout specified for request: 0x%x\n",
1101 1.18.2.3 tls req->index);
1102 1.18.2.3 tls xs->timeout = 500;
1103 1.18.2.3 tls }
1104 1.18.2.3 tls
1105 1.1 thorpej s = splbio();
1106 1.1 thorpej if (__predict_true((xs->xs_control & XS_CTL_POLL) == 0))
1107 1.1 thorpej callout_reset(&xs->xs_callout,
1108 1.1 thorpej mstohz(xs->timeout), mpt_timeout, req);
1109 1.1 thorpej mpt_send_cmd(mpt, req);
1110 1.1 thorpej splx(s);
1111 1.1 thorpej
1112 1.1 thorpej if (__predict_true((xs->xs_control & XS_CTL_POLL) == 0))
1113 1.1 thorpej return;
1114 1.1 thorpej
1115 1.1 thorpej /*
1116 1.1 thorpej * If we can't use interrupts, poll on completion.
1117 1.1 thorpej */
1118 1.4 thorpej if (mpt_poll(mpt, xs, xs->timeout))
1119 1.1 thorpej mpt_timeout(req);
1120 1.1 thorpej }
1121 1.1 thorpej
1122 1.1 thorpej static void
1123 1.1 thorpej mpt_set_xfer_mode(mpt_softc_t *mpt, struct scsipi_xfer_mode *xm)
1124 1.1 thorpej {
1125 1.1 thorpej fCONFIG_PAGE_SCSI_DEVICE_1 tmp;
1126 1.1 thorpej
1127 1.1 thorpej /*
1128 1.1 thorpej * Always allow disconnect; we don't have a way to disable
1129 1.1 thorpej * it right now, in any case.
1130 1.1 thorpej */
1131 1.1 thorpej mpt->mpt_disc_enable |= (1 << xm->xm_target);
1132 1.1 thorpej
1133 1.1 thorpej if (xm->xm_mode & PERIPH_CAP_TQING)
1134 1.1 thorpej mpt->mpt_tag_enable |= (1 << xm->xm_target);
1135 1.1 thorpej else
1136 1.1 thorpej mpt->mpt_tag_enable &= ~(1 << xm->xm_target);
1137 1.1 thorpej
1138 1.17 mhitch if (mpt->is_scsi) {
1139 1.17 mhitch /*
1140 1.17 mhitch * SCSI transport settings only make any sense for
1141 1.17 mhitch * SCSI
1142 1.17 mhitch */
1143 1.17 mhitch
1144 1.17 mhitch tmp = mpt->mpt_dev_page1[xm->xm_target];
1145 1.1 thorpej
1146 1.17 mhitch /*
1147 1.17 mhitch * Set the wide/narrow parameter for the target.
1148 1.17 mhitch */
1149 1.17 mhitch if (xm->xm_mode & PERIPH_CAP_WIDE16)
1150 1.17 mhitch tmp.RequestedParameters |= MPI_SCSIDEVPAGE1_RP_WIDE;
1151 1.17 mhitch else
1152 1.17 mhitch tmp.RequestedParameters &= ~MPI_SCSIDEVPAGE1_RP_WIDE;
1153 1.1 thorpej
1154 1.17 mhitch /*
1155 1.17 mhitch * Set the synchronous parameters for the target.
1156 1.17 mhitch *
1157 1.17 mhitch * XXX If we request sync transfers, we just go ahead and
1158 1.17 mhitch * XXX request the maximum available. We need finer control
1159 1.17 mhitch * XXX in order to implement Domain Validation.
1160 1.17 mhitch */
1161 1.17 mhitch tmp.RequestedParameters &= ~(MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK |
1162 1.17 mhitch MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK |
1163 1.17 mhitch MPI_SCSIDEVPAGE1_RP_DT | MPI_SCSIDEVPAGE1_RP_QAS |
1164 1.17 mhitch MPI_SCSIDEVPAGE1_RP_IU);
1165 1.17 mhitch if (xm->xm_mode & PERIPH_CAP_SYNC) {
1166 1.17 mhitch int factor, offset, np;
1167 1.17 mhitch
1168 1.17 mhitch factor = (mpt->mpt_port_page0.Capabilities >> 8) & 0xff;
1169 1.17 mhitch offset = (mpt->mpt_port_page0.Capabilities >> 16) & 0xff;
1170 1.17 mhitch np = 0;
1171 1.17 mhitch if (factor < 0x9) {
1172 1.17 mhitch /* Ultra320 */
1173 1.17 mhitch np |= MPI_SCSIDEVPAGE1_RP_QAS | MPI_SCSIDEVPAGE1_RP_IU;
1174 1.17 mhitch }
1175 1.17 mhitch if (factor < 0xa) {
1176 1.17 mhitch /* at least Ultra160 */
1177 1.17 mhitch np |= MPI_SCSIDEVPAGE1_RP_DT;
1178 1.17 mhitch }
1179 1.17 mhitch np |= (factor << 8) | (offset << 16);
1180 1.17 mhitch tmp.RequestedParameters |= np;
1181 1.1 thorpej }
1182 1.17 mhitch
1183 1.17 mhitch host2mpt_config_page_scsi_device_1(&tmp);
1184 1.17 mhitch if (mpt_write_cfg_page(mpt, xm->xm_target, &tmp.Header)) {
1185 1.17 mhitch mpt_prt(mpt, "unable to write Device Page 1");
1186 1.17 mhitch return;
1187 1.1 thorpej }
1188 1.1 thorpej
1189 1.17 mhitch if (mpt_read_cfg_page(mpt, xm->xm_target, &tmp.Header)) {
1190 1.17 mhitch mpt_prt(mpt, "unable to read back Device Page 1");
1191 1.17 mhitch return;
1192 1.17 mhitch }
1193 1.1 thorpej
1194 1.17 mhitch mpt2host_config_page_scsi_device_1(&tmp);
1195 1.17 mhitch mpt->mpt_dev_page1[xm->xm_target] = tmp;
1196 1.17 mhitch if (mpt->verbose > 1) {
1197 1.17 mhitch mpt_prt(mpt,
1198 1.17 mhitch "SPI Target %d Page 1: RequestedParameters %x Config %x",
1199 1.17 mhitch xm->xm_target,
1200 1.17 mhitch mpt->mpt_dev_page1[xm->xm_target].RequestedParameters,
1201 1.17 mhitch mpt->mpt_dev_page1[xm->xm_target].Configuration);
1202 1.17 mhitch }
1203 1.1 thorpej }
1204 1.1 thorpej
1205 1.1 thorpej /*
1206 1.1 thorpej * Make a note that we should perform an async callback at the
1207 1.1 thorpej * end of the next successful command completion to report the
1208 1.1 thorpej * negotiated transfer mode.
1209 1.1 thorpej */
1210 1.1 thorpej mpt->mpt_report_xfer_mode |= (1 << xm->xm_target);
1211 1.1 thorpej }
1212 1.1 thorpej
1213 1.1 thorpej static void
1214 1.1 thorpej mpt_get_xfer_mode(mpt_softc_t *mpt, struct scsipi_periph *periph)
1215 1.1 thorpej {
1216 1.1 thorpej fCONFIG_PAGE_SCSI_DEVICE_0 tmp;
1217 1.1 thorpej struct scsipi_xfer_mode xm;
1218 1.1 thorpej int period, offset;
1219 1.1 thorpej
1220 1.1 thorpej tmp = mpt->mpt_dev_page0[periph->periph_target];
1221 1.15 chs host2mpt_config_page_scsi_device_0(&tmp);
1222 1.1 thorpej if (mpt_read_cfg_page(mpt, periph->periph_target, &tmp.Header)) {
1223 1.1 thorpej mpt_prt(mpt, "unable to read Device Page 0");
1224 1.1 thorpej return;
1225 1.1 thorpej }
1226 1.15 chs mpt2host_config_page_scsi_device_0(&tmp);
1227 1.1 thorpej
1228 1.1 thorpej if (mpt->verbose > 1) {
1229 1.1 thorpej mpt_prt(mpt,
1230 1.1 thorpej "SPI Tgt %d Page 0: NParms %x Information %x",
1231 1.1 thorpej periph->periph_target,
1232 1.1 thorpej tmp.NegotiatedParameters, tmp.Information);
1233 1.1 thorpej }
1234 1.1 thorpej
1235 1.1 thorpej xm.xm_target = periph->periph_target;
1236 1.1 thorpej xm.xm_mode = 0;
1237 1.1 thorpej
1238 1.1 thorpej if (tmp.NegotiatedParameters & MPI_SCSIDEVPAGE0_NP_WIDE)
1239 1.1 thorpej xm.xm_mode |= PERIPH_CAP_WIDE16;
1240 1.1 thorpej
1241 1.1 thorpej period = (tmp.NegotiatedParameters >> 8) & 0xff;
1242 1.1 thorpej offset = (tmp.NegotiatedParameters >> 16) & 0xff;
1243 1.1 thorpej if (offset) {
1244 1.1 thorpej xm.xm_period = period;
1245 1.1 thorpej xm.xm_offset = offset;
1246 1.1 thorpej xm.xm_mode |= PERIPH_CAP_SYNC;
1247 1.1 thorpej }
1248 1.1 thorpej
1249 1.1 thorpej /*
1250 1.1 thorpej * Tagged queueing is all controlled by us; there is no
1251 1.1 thorpej * other setting to query.
1252 1.1 thorpej */
1253 1.1 thorpej if (mpt->mpt_tag_enable & (1 << periph->periph_target))
1254 1.1 thorpej xm.xm_mode |= PERIPH_CAP_TQING;
1255 1.1 thorpej
1256 1.1 thorpej /*
1257 1.1 thorpej * We're going to deliver the async event, so clear the marker.
1258 1.1 thorpej */
1259 1.1 thorpej mpt->mpt_report_xfer_mode &= ~(1 << periph->periph_target);
1260 1.1 thorpej
1261 1.1 thorpej scsipi_async_event(&mpt->sc_channel, ASYNC_EVENT_XFER_MODE, &xm);
1262 1.1 thorpej }
1263 1.1 thorpej
1264 1.1 thorpej static void
1265 1.1 thorpej mpt_ctlop(mpt_softc_t *mpt, void *vmsg, uint32_t reply)
1266 1.1 thorpej {
1267 1.1 thorpej MSG_DEFAULT_REPLY *dmsg = vmsg;
1268 1.1 thorpej
1269 1.1 thorpej switch (dmsg->Function) {
1270 1.1 thorpej case MPI_FUNCTION_EVENT_NOTIFICATION:
1271 1.1 thorpej mpt_event_notify_reply(mpt, vmsg);
1272 1.1 thorpej mpt_free_reply(mpt, (reply << 1));
1273 1.1 thorpej break;
1274 1.1 thorpej
1275 1.1 thorpej case MPI_FUNCTION_EVENT_ACK:
1276 1.18.2.4 jdolecek {
1277 1.18.2.4 jdolecek MSG_EVENT_ACK_REPLY *msg = vmsg;
1278 1.18.2.4 jdolecek int index = le32toh(msg->MsgContext) & ~0x80000000;
1279 1.1 thorpej mpt_free_reply(mpt, (reply << 1));
1280 1.18.2.4 jdolecek if (index >= 0 && index < MPT_MAX_REQUESTS(mpt)) {
1281 1.18.2.4 jdolecek request_t *req = &mpt->request_pool[index];
1282 1.18.2.4 jdolecek mpt_free_request(mpt, req);
1283 1.18.2.4 jdolecek }
1284 1.1 thorpej break;
1285 1.18.2.4 jdolecek }
1286 1.1 thorpej
1287 1.1 thorpej case MPI_FUNCTION_PORT_ENABLE:
1288 1.1 thorpej {
1289 1.1 thorpej MSG_PORT_ENABLE_REPLY *msg = vmsg;
1290 1.15 chs int index = le32toh(msg->MsgContext) & ~0x80000000;
1291 1.1 thorpej if (mpt->verbose > 1)
1292 1.1 thorpej mpt_prt(mpt, "enable port reply index %d", index);
1293 1.1 thorpej if (index >= 0 && index < MPT_MAX_REQUESTS(mpt)) {
1294 1.1 thorpej request_t *req = &mpt->request_pool[index];
1295 1.1 thorpej req->debug = REQ_DONE;
1296 1.1 thorpej }
1297 1.1 thorpej mpt_free_reply(mpt, (reply << 1));
1298 1.1 thorpej break;
1299 1.1 thorpej }
1300 1.1 thorpej
1301 1.1 thorpej case MPI_FUNCTION_CONFIG:
1302 1.1 thorpej {
1303 1.1 thorpej MSG_CONFIG_REPLY *msg = vmsg;
1304 1.15 chs int index = le32toh(msg->MsgContext) & ~0x80000000;
1305 1.1 thorpej if (index >= 0 && index < MPT_MAX_REQUESTS(mpt)) {
1306 1.1 thorpej request_t *req = &mpt->request_pool[index];
1307 1.1 thorpej req->debug = REQ_DONE;
1308 1.1 thorpej req->sequence = reply;
1309 1.1 thorpej } else
1310 1.1 thorpej mpt_free_reply(mpt, (reply << 1));
1311 1.1 thorpej break;
1312 1.1 thorpej }
1313 1.1 thorpej
1314 1.1 thorpej default:
1315 1.1 thorpej mpt_prt(mpt, "unknown ctlop: 0x%x", dmsg->Function);
1316 1.1 thorpej }
1317 1.1 thorpej }
1318 1.1 thorpej
1319 1.1 thorpej static void
1320 1.1 thorpej mpt_event_notify_reply(mpt_softc_t *mpt, MSG_EVENT_NOTIFY_REPLY *msg)
1321 1.1 thorpej {
1322 1.1 thorpej
1323 1.15 chs switch (le32toh(msg->Event)) {
1324 1.1 thorpej case MPI_EVENT_LOG_DATA:
1325 1.1 thorpej {
1326 1.1 thorpej int i;
1327 1.1 thorpej
1328 1.1 thorpej /* Some error occurrerd that the Fusion wants logged. */
1329 1.1 thorpej mpt_prt(mpt, "EvtLogData: IOCLogInfo: 0x%08x", msg->IOCLogInfo);
1330 1.1 thorpej mpt_prt(mpt, "EvtLogData: Event Data:");
1331 1.1 thorpej for (i = 0; i < msg->EventDataLength; i++) {
1332 1.1 thorpej if ((i % 4) == 0)
1333 1.18 martin printf("%s:\t", device_xname(mpt->sc_dev));
1334 1.1 thorpej printf("0x%08x%c", msg->Data[i],
1335 1.1 thorpej ((i % 4) == 3) ? '\n' : ' ');
1336 1.1 thorpej }
1337 1.1 thorpej if ((i % 4) != 0)
1338 1.1 thorpej printf("\n");
1339 1.1 thorpej break;
1340 1.1 thorpej }
1341 1.1 thorpej
1342 1.1 thorpej case MPI_EVENT_UNIT_ATTENTION:
1343 1.1 thorpej mpt_prt(mpt, "Unit Attn: Bus 0x%02x Target 0x%02x",
1344 1.1 thorpej (msg->Data[0] >> 8) & 0xff, msg->Data[0] & 0xff);
1345 1.1 thorpej break;
1346 1.1 thorpej
1347 1.1 thorpej case MPI_EVENT_IOC_BUS_RESET:
1348 1.1 thorpej /* We generated a bus reset. */
1349 1.1 thorpej mpt_prt(mpt, "IOC Bus Reset Port %d",
1350 1.1 thorpej (msg->Data[0] >> 8) & 0xff);
1351 1.1 thorpej break;
1352 1.1 thorpej
1353 1.1 thorpej case MPI_EVENT_EXT_BUS_RESET:
1354 1.1 thorpej /* Someone else generated a bus reset. */
1355 1.1 thorpej mpt_prt(mpt, "External Bus Reset");
1356 1.1 thorpej /*
1357 1.1 thorpej * These replies don't return EventData like the MPI
1358 1.1 thorpej * spec says they do.
1359 1.1 thorpej */
1360 1.1 thorpej /* XXX Send an async event? */
1361 1.1 thorpej break;
1362 1.1 thorpej
1363 1.1 thorpej case MPI_EVENT_RESCAN:
1364 1.1 thorpej /*
1365 1.1 thorpej * In general, thise means a device has been added
1366 1.1 thorpej * to the loop.
1367 1.1 thorpej */
1368 1.1 thorpej mpt_prt(mpt, "Rescan Port %d", (msg->Data[0] >> 8) & 0xff);
1369 1.1 thorpej /* XXX Send an async event? */
1370 1.1 thorpej break;
1371 1.1 thorpej
1372 1.1 thorpej case MPI_EVENT_LINK_STATUS_CHANGE:
1373 1.1 thorpej mpt_prt(mpt, "Port %d: Link state %s",
1374 1.1 thorpej (msg->Data[1] >> 8) & 0xff,
1375 1.1 thorpej (msg->Data[0] & 0xff) == 0 ? "Failed" : "Active");
1376 1.1 thorpej break;
1377 1.1 thorpej
1378 1.1 thorpej case MPI_EVENT_LOOP_STATE_CHANGE:
1379 1.1 thorpej switch ((msg->Data[0] >> 16) & 0xff) {
1380 1.1 thorpej case 0x01:
1381 1.1 thorpej mpt_prt(mpt,
1382 1.1 thorpej "Port %d: FC Link Event: LIP(%02x,%02x) "
1383 1.1 thorpej "(Loop Initialization)",
1384 1.1 thorpej (msg->Data[1] >> 8) & 0xff,
1385 1.1 thorpej (msg->Data[0] >> 8) & 0xff,
1386 1.1 thorpej (msg->Data[0] ) & 0xff);
1387 1.1 thorpej switch ((msg->Data[0] >> 8) & 0xff) {
1388 1.1 thorpej case 0xf7:
1389 1.1 thorpej if ((msg->Data[0] & 0xff) == 0xf7)
1390 1.1 thorpej mpt_prt(mpt, "\tDevice needs AL_PA");
1391 1.1 thorpej else
1392 1.1 thorpej mpt_prt(mpt, "\tDevice %02x doesn't "
1393 1.1 thorpej "like FC performance",
1394 1.1 thorpej msg->Data[0] & 0xff);
1395 1.1 thorpej break;
1396 1.1 thorpej
1397 1.1 thorpej case 0xf8:
1398 1.1 thorpej if ((msg->Data[0] & 0xff) == 0xf7)
1399 1.1 thorpej mpt_prt(mpt, "\tDevice detected loop "
1400 1.1 thorpej "failure before acquiring AL_PA");
1401 1.1 thorpej else
1402 1.1 thorpej mpt_prt(mpt, "\tDevice %02x detected "
1403 1.1 thorpej "loop failure",
1404 1.1 thorpej msg->Data[0] & 0xff);
1405 1.1 thorpej break;
1406 1.1 thorpej
1407 1.1 thorpej default:
1408 1.1 thorpej mpt_prt(mpt, "\tDevice %02x requests that "
1409 1.1 thorpej "device %02x reset itself",
1410 1.1 thorpej msg->Data[0] & 0xff,
1411 1.1 thorpej (msg->Data[0] >> 8) & 0xff);
1412 1.1 thorpej break;
1413 1.1 thorpej }
1414 1.1 thorpej break;
1415 1.1 thorpej
1416 1.1 thorpej case 0x02:
1417 1.1 thorpej mpt_prt(mpt, "Port %d: FC Link Event: LPE(%02x,%02x) "
1418 1.1 thorpej "(Loop Port Enable)",
1419 1.1 thorpej (msg->Data[1] >> 8) & 0xff,
1420 1.1 thorpej (msg->Data[0] >> 8) & 0xff,
1421 1.1 thorpej (msg->Data[0] ) & 0xff);
1422 1.1 thorpej break;
1423 1.1 thorpej
1424 1.1 thorpej case 0x03:
1425 1.1 thorpej mpt_prt(mpt, "Port %d: FC Link Event: LPB(%02x,%02x) "
1426 1.1 thorpej "(Loop Port Bypass)",
1427 1.1 thorpej (msg->Data[1] >> 8) & 0xff,
1428 1.1 thorpej (msg->Data[0] >> 8) & 0xff,
1429 1.1 thorpej (msg->Data[0] ) & 0xff);
1430 1.1 thorpej break;
1431 1.1 thorpej
1432 1.1 thorpej default:
1433 1.1 thorpej mpt_prt(mpt, "Port %d: FC Link Event: "
1434 1.1 thorpej "Unknown event (%02x %02x %02x)",
1435 1.1 thorpej (msg->Data[1] >> 8) & 0xff,
1436 1.1 thorpej (msg->Data[0] >> 16) & 0xff,
1437 1.1 thorpej (msg->Data[0] >> 8) & 0xff,
1438 1.1 thorpej (msg->Data[0] ) & 0xff);
1439 1.1 thorpej break;
1440 1.1 thorpej }
1441 1.1 thorpej break;
1442 1.1 thorpej
1443 1.1 thorpej case MPI_EVENT_LOGOUT:
1444 1.1 thorpej mpt_prt(mpt, "Port %d: FC Logout: N_PortID: %02x",
1445 1.1 thorpej (msg->Data[1] >> 8) & 0xff, msg->Data[0]);
1446 1.1 thorpej break;
1447 1.1 thorpej
1448 1.1 thorpej case MPI_EVENT_EVENT_CHANGE:
1449 1.1 thorpej /*
1450 1.1 thorpej * This is just an acknowledgement of our
1451 1.1 thorpej * mpt_send_event_request().
1452 1.1 thorpej */
1453 1.1 thorpej break;
1454 1.1 thorpej
1455 1.12 tron case MPI_EVENT_SAS_PHY_LINK_STATUS:
1456 1.13 tron switch ((msg->Data[0] >> 12) & 0x0f) {
1457 1.12 tron case 0x00:
1458 1.12 tron mpt_prt(mpt, "Phy %d: Link Status Unknown",
1459 1.12 tron msg->Data[0] & 0xff);
1460 1.12 tron break;
1461 1.12 tron case 0x01:
1462 1.12 tron mpt_prt(mpt, "Phy %d: Link Disabled",
1463 1.12 tron msg->Data[0] & 0xff);
1464 1.12 tron break;
1465 1.12 tron case 0x02:
1466 1.12 tron mpt_prt(mpt, "Phy %d: Failed Speed Negotiation",
1467 1.12 tron msg->Data[0] & 0xff);
1468 1.12 tron break;
1469 1.12 tron case 0x03:
1470 1.12 tron mpt_prt(mpt, "Phy %d: SATA OOB Complete",
1471 1.12 tron msg->Data[0] & 0xff);
1472 1.12 tron break;
1473 1.12 tron case 0x08:
1474 1.12 tron mpt_prt(mpt, "Phy %d: Link Rate 1.5 Gbps",
1475 1.12 tron msg->Data[0] & 0xff);
1476 1.12 tron break;
1477 1.12 tron case 0x09:
1478 1.12 tron mpt_prt(mpt, "Phy %d: Link Rate 3.0 Gbps",
1479 1.12 tron msg->Data[0] & 0xff);
1480 1.12 tron break;
1481 1.13 tron default:
1482 1.12 tron mpt_prt(mpt, "Phy %d: SAS Phy Link Status Event: "
1483 1.12 tron "Unknown event (%0x)",
1484 1.12 tron msg->Data[0] & 0xff, (msg->Data[0] >> 8) & 0xff);
1485 1.12 tron }
1486 1.12 tron break;
1487 1.12 tron
1488 1.12 tron case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1489 1.12 tron case MPI_EVENT_SAS_DISCOVERY:
1490 1.12 tron /* ignore these events for now */
1491 1.12 tron break;
1492 1.12 tron
1493 1.17 mhitch case MPI_EVENT_QUEUE_FULL:
1494 1.17 mhitch /* This can get a little chatty */
1495 1.17 mhitch if (mpt->verbose > 0)
1496 1.17 mhitch mpt_prt(mpt, "Queue Full Event");
1497 1.17 mhitch break;
1498 1.17 mhitch
1499 1.1 thorpej default:
1500 1.1 thorpej mpt_prt(mpt, "Unknown async event: 0x%x", msg->Event);
1501 1.1 thorpej break;
1502 1.1 thorpej }
1503 1.9 perry
1504 1.1 thorpej if (msg->AckRequired) {
1505 1.1 thorpej MSG_EVENT_ACK *ackp;
1506 1.1 thorpej request_t *req;
1507 1.1 thorpej
1508 1.1 thorpej if ((req = mpt_get_request(mpt)) == NULL) {
1509 1.1 thorpej /* XXX XXX XXX XXXJRT */
1510 1.1 thorpej panic("mpt_event_notify_reply: unable to allocate "
1511 1.1 thorpej "request structure");
1512 1.1 thorpej }
1513 1.1 thorpej
1514 1.1 thorpej ackp = (MSG_EVENT_ACK *) req->req_vbuf;
1515 1.1 thorpej memset(ackp, 0, sizeof(*ackp));
1516 1.1 thorpej ackp->Function = MPI_FUNCTION_EVENT_ACK;
1517 1.1 thorpej ackp->Event = msg->Event;
1518 1.1 thorpej ackp->EventContext = msg->EventContext;
1519 1.15 chs ackp->MsgContext = htole32(req->index | 0x80000000);
1520 1.1 thorpej mpt_check_doorbell(mpt);
1521 1.1 thorpej mpt_send_cmd(mpt, req);
1522 1.1 thorpej }
1523 1.1 thorpej }
1524 1.1 thorpej
1525 1.18.2.3 tls static void
1526 1.18.2.3 tls mpt_bus_reset(mpt_softc_t *mpt)
1527 1.18.2.3 tls {
1528 1.18.2.3 tls request_t *req;
1529 1.18.2.3 tls MSG_SCSI_TASK_MGMT *mngt_req;
1530 1.18.2.3 tls int s;
1531 1.18.2.3 tls
1532 1.18.2.3 tls s = splbio();
1533 1.18.2.3 tls if (mpt->mngt_req) {
1534 1.18.2.3 tls /* request already queued; can't do more */
1535 1.18.2.3 tls splx(s);
1536 1.18.2.3 tls return;
1537 1.18.2.3 tls }
1538 1.18.2.3 tls req = mpt_get_request(mpt);
1539 1.18.2.3 tls if (__predict_false(req == NULL)) {
1540 1.18.2.3 tls mpt_prt(mpt, "no mngt request\n");
1541 1.18.2.3 tls splx(s);
1542 1.18.2.3 tls return;
1543 1.18.2.3 tls }
1544 1.18.2.3 tls mpt->mngt_req = req;
1545 1.18.2.3 tls splx(s);
1546 1.18.2.3 tls mngt_req = req->req_vbuf;
1547 1.18.2.3 tls memset(mngt_req, 0, sizeof(*mngt_req));
1548 1.18.2.3 tls mngt_req->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1549 1.18.2.3 tls mngt_req->Bus = mpt->bus;
1550 1.18.2.3 tls mngt_req->TargetID = 0;
1551 1.18.2.3 tls mngt_req->ChainOffset = 0;
1552 1.18.2.3 tls mngt_req->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
1553 1.18.2.3 tls mngt_req->Reserved1 = 0;
1554 1.18.2.3 tls mngt_req->MsgFlags =
1555 1.18.2.3 tls mpt->is_fc ? MPI_SCSITASKMGMT_MSGFLAGS_LIP_RESET_OPTION : 0;
1556 1.18.2.3 tls mngt_req->MsgContext = req->index;
1557 1.18.2.3 tls mngt_req->TaskMsgContext = 0;
1558 1.18.2.3 tls s = splbio();
1559 1.18.2.3 tls mpt_send_handshake_cmd(mpt, sizeof(*mngt_req), mngt_req);
1560 1.18.2.3 tls splx(s);
1561 1.18.2.3 tls }
1562 1.1 thorpej
1563 1.1 thorpej /*****************************************************************************
1564 1.1 thorpej * SCSI interface routines
1565 1.1 thorpej *****************************************************************************/
1566 1.1 thorpej
1567 1.1 thorpej static void
1568 1.1 thorpej mpt_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
1569 1.1 thorpej void *arg)
1570 1.1 thorpej {
1571 1.1 thorpej struct scsipi_adapter *adapt = chan->chan_adapter;
1572 1.18.2.3 tls mpt_softc_t *mpt = device_private(adapt->adapt_dev);
1573 1.1 thorpej
1574 1.1 thorpej switch (req) {
1575 1.1 thorpej case ADAPTER_REQ_RUN_XFER:
1576 1.1 thorpej mpt_run_xfer(mpt, (struct scsipi_xfer *) arg);
1577 1.1 thorpej return;
1578 1.1 thorpej
1579 1.1 thorpej case ADAPTER_REQ_GROW_RESOURCES:
1580 1.1 thorpej /* Not supported. */
1581 1.1 thorpej return;
1582 1.1 thorpej
1583 1.1 thorpej case ADAPTER_REQ_SET_XFER_MODE:
1584 1.1 thorpej mpt_set_xfer_mode(mpt, (struct scsipi_xfer_mode *) arg);
1585 1.1 thorpej return;
1586 1.1 thorpej }
1587 1.1 thorpej }
1588 1.1 thorpej
1589 1.1 thorpej static void
1590 1.1 thorpej mpt_minphys(struct buf *bp)
1591 1.1 thorpej {
1592 1.1 thorpej if (bp->b_bcount > MPT_MAX_XFER)
1593 1.1 thorpej bp->b_bcount = MPT_MAX_XFER;
1594 1.1 thorpej minphys(bp);
1595 1.1 thorpej }
1596 1.18.2.3 tls
1597 1.18.2.3 tls static int
1598 1.18.2.3 tls mpt_ioctl(struct scsipi_channel *chan, u_long cmd, void *arg,
1599 1.18.2.3 tls int flag, struct proc *p)
1600 1.18.2.3 tls {
1601 1.18.2.3 tls mpt_softc_t *mpt;
1602 1.18.2.3 tls int s;
1603 1.18.2.3 tls
1604 1.18.2.3 tls mpt = device_private(chan->chan_adapter->adapt_dev);
1605 1.18.2.3 tls switch (cmd) {
1606 1.18.2.3 tls case SCBUSIORESET:
1607 1.18.2.3 tls mpt_bus_reset(mpt);
1608 1.18.2.3 tls s = splbio();
1609 1.18.2.3 tls mpt_intr(mpt);
1610 1.18.2.3 tls splx(s);
1611 1.18.2.3 tls return(0);
1612 1.18.2.3 tls default:
1613 1.18.2.3 tls return (ENOTTY);
1614 1.18.2.3 tls }
1615 1.18.2.3 tls }
1616 1.18.2.4 jdolecek
1617 1.18.2.4 jdolecek #if NBIO > 0
1618 1.18.2.4 jdolecek static fCONFIG_PAGE_IOC_2 *
1619 1.18.2.4 jdolecek mpt_get_cfg_page_ioc2(mpt_softc_t *mpt)
1620 1.18.2.4 jdolecek {
1621 1.18.2.4 jdolecek fCONFIG_PAGE_HEADER hdr;
1622 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2 *ioc2;
1623 1.18.2.4 jdolecek int rv;
1624 1.18.2.4 jdolecek
1625 1.18.2.4 jdolecek rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC, 2, 0, &hdr);
1626 1.18.2.4 jdolecek if (rv)
1627 1.18.2.4 jdolecek return NULL;
1628 1.18.2.4 jdolecek
1629 1.18.2.4 jdolecek ioc2 = malloc(hdr.PageLength * 4, M_DEVBUF, M_WAITOK | M_ZERO);
1630 1.18.2.4 jdolecek if (ioc2 == NULL)
1631 1.18.2.4 jdolecek return NULL;
1632 1.18.2.4 jdolecek
1633 1.18.2.4 jdolecek memcpy(ioc2, &hdr, sizeof(hdr));
1634 1.18.2.4 jdolecek
1635 1.18.2.4 jdolecek rv = mpt_read_cfg_page(mpt, 0, &ioc2->Header);
1636 1.18.2.4 jdolecek if (rv)
1637 1.18.2.4 jdolecek goto fail;
1638 1.18.2.4 jdolecek mpt2host_config_page_ioc_2(ioc2);
1639 1.18.2.4 jdolecek
1640 1.18.2.4 jdolecek return ioc2;
1641 1.18.2.4 jdolecek
1642 1.18.2.4 jdolecek fail:
1643 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
1644 1.18.2.4 jdolecek return NULL;
1645 1.18.2.4 jdolecek }
1646 1.18.2.4 jdolecek
1647 1.18.2.4 jdolecek static fCONFIG_PAGE_IOC_3 *
1648 1.18.2.4 jdolecek mpt_get_cfg_page_ioc3(mpt_softc_t *mpt)
1649 1.18.2.4 jdolecek {
1650 1.18.2.4 jdolecek fCONFIG_PAGE_HEADER hdr;
1651 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_3 *ioc3;
1652 1.18.2.4 jdolecek int rv;
1653 1.18.2.4 jdolecek
1654 1.18.2.4 jdolecek rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC, 3, 0, &hdr);
1655 1.18.2.4 jdolecek if (rv)
1656 1.18.2.4 jdolecek return NULL;
1657 1.18.2.4 jdolecek
1658 1.18.2.4 jdolecek ioc3 = malloc(hdr.PageLength * 4, M_DEVBUF, M_WAITOK | M_ZERO);
1659 1.18.2.4 jdolecek if (ioc3 == NULL)
1660 1.18.2.4 jdolecek return NULL;
1661 1.18.2.4 jdolecek
1662 1.18.2.4 jdolecek memcpy(ioc3, &hdr, sizeof(hdr));
1663 1.18.2.4 jdolecek
1664 1.18.2.4 jdolecek rv = mpt_read_cfg_page(mpt, 0, &ioc3->Header);
1665 1.18.2.4 jdolecek if (rv)
1666 1.18.2.4 jdolecek goto fail;
1667 1.18.2.4 jdolecek
1668 1.18.2.4 jdolecek return ioc3;
1669 1.18.2.4 jdolecek
1670 1.18.2.4 jdolecek fail:
1671 1.18.2.4 jdolecek free(ioc3, M_DEVBUF);
1672 1.18.2.4 jdolecek return NULL;
1673 1.18.2.4 jdolecek }
1674 1.18.2.4 jdolecek
1675 1.18.2.4 jdolecek
1676 1.18.2.4 jdolecek static fCONFIG_PAGE_RAID_VOL_0 *
1677 1.18.2.4 jdolecek mpt_get_cfg_page_raid_vol0(mpt_softc_t *mpt, int address)
1678 1.18.2.4 jdolecek {
1679 1.18.2.4 jdolecek fCONFIG_PAGE_HEADER hdr;
1680 1.18.2.4 jdolecek fCONFIG_PAGE_RAID_VOL_0 *rvol0;
1681 1.18.2.4 jdolecek int rv;
1682 1.18.2.4 jdolecek
1683 1.18.2.4 jdolecek rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_RAID_VOLUME, 0,
1684 1.18.2.4 jdolecek address, &hdr);
1685 1.18.2.4 jdolecek if (rv)
1686 1.18.2.4 jdolecek return NULL;
1687 1.18.2.4 jdolecek
1688 1.18.2.4 jdolecek rvol0 = malloc(hdr.PageLength * 4, M_DEVBUF, M_WAITOK | M_ZERO);
1689 1.18.2.4 jdolecek if (rvol0 == NULL)
1690 1.18.2.4 jdolecek return NULL;
1691 1.18.2.4 jdolecek
1692 1.18.2.4 jdolecek memcpy(rvol0, &hdr, sizeof(hdr));
1693 1.18.2.4 jdolecek
1694 1.18.2.4 jdolecek rv = mpt_read_cfg_page(mpt, address, &rvol0->Header);
1695 1.18.2.4 jdolecek if (rv)
1696 1.18.2.4 jdolecek goto fail;
1697 1.18.2.4 jdolecek mpt2host_config_page_raid_vol_0(rvol0);
1698 1.18.2.4 jdolecek
1699 1.18.2.4 jdolecek return rvol0;
1700 1.18.2.4 jdolecek
1701 1.18.2.4 jdolecek fail:
1702 1.18.2.4 jdolecek free(rvol0, M_DEVBUF);
1703 1.18.2.4 jdolecek return NULL;
1704 1.18.2.4 jdolecek }
1705 1.18.2.4 jdolecek
1706 1.18.2.4 jdolecek static fCONFIG_PAGE_RAID_PHYS_DISK_0 *
1707 1.18.2.4 jdolecek mpt_get_cfg_page_raid_phys_disk0(mpt_softc_t *mpt, int address)
1708 1.18.2.4 jdolecek {
1709 1.18.2.4 jdolecek fCONFIG_PAGE_HEADER hdr;
1710 1.18.2.4 jdolecek fCONFIG_PAGE_RAID_PHYS_DISK_0 *physdisk0;
1711 1.18.2.4 jdolecek int rv;
1712 1.18.2.4 jdolecek
1713 1.18.2.4 jdolecek rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK, 0,
1714 1.18.2.4 jdolecek address, &hdr);
1715 1.18.2.4 jdolecek if (rv)
1716 1.18.2.4 jdolecek return NULL;
1717 1.18.2.4 jdolecek
1718 1.18.2.4 jdolecek physdisk0 = malloc(hdr.PageLength * 4, M_DEVBUF, M_WAITOK | M_ZERO);
1719 1.18.2.4 jdolecek if (physdisk0 == NULL)
1720 1.18.2.4 jdolecek return NULL;
1721 1.18.2.4 jdolecek
1722 1.18.2.4 jdolecek memcpy(physdisk0, &hdr, sizeof(hdr));
1723 1.18.2.4 jdolecek
1724 1.18.2.4 jdolecek rv = mpt_read_cfg_page(mpt, address, &physdisk0->Header);
1725 1.18.2.4 jdolecek if (rv)
1726 1.18.2.4 jdolecek goto fail;
1727 1.18.2.4 jdolecek mpt2host_config_page_raid_phys_disk_0(physdisk0);
1728 1.18.2.4 jdolecek
1729 1.18.2.4 jdolecek return physdisk0;
1730 1.18.2.4 jdolecek
1731 1.18.2.4 jdolecek fail:
1732 1.18.2.4 jdolecek free(physdisk0, M_DEVBUF);
1733 1.18.2.4 jdolecek return NULL;
1734 1.18.2.4 jdolecek }
1735 1.18.2.4 jdolecek
1736 1.18.2.4 jdolecek static bool
1737 1.18.2.4 jdolecek mpt_is_raid(mpt_softc_t *mpt)
1738 1.18.2.4 jdolecek {
1739 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2 *ioc2;
1740 1.18.2.4 jdolecek bool is_raid = false;
1741 1.18.2.4 jdolecek
1742 1.18.2.4 jdolecek ioc2 = mpt_get_cfg_page_ioc2(mpt);
1743 1.18.2.4 jdolecek if (ioc2 == NULL)
1744 1.18.2.4 jdolecek return false;
1745 1.18.2.4 jdolecek
1746 1.18.2.4 jdolecek if (ioc2->CapabilitiesFlags != 0xdeadbeef) {
1747 1.18.2.4 jdolecek is_raid = !!(ioc2->CapabilitiesFlags &
1748 1.18.2.4 jdolecek (MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT|
1749 1.18.2.4 jdolecek MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT|
1750 1.18.2.4 jdolecek MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT));
1751 1.18.2.4 jdolecek }
1752 1.18.2.4 jdolecek
1753 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
1754 1.18.2.4 jdolecek
1755 1.18.2.4 jdolecek return is_raid;
1756 1.18.2.4 jdolecek }
1757 1.18.2.4 jdolecek
1758 1.18.2.4 jdolecek static int
1759 1.18.2.4 jdolecek mpt_bio_ioctl(device_t dev, u_long cmd, void *addr)
1760 1.18.2.4 jdolecek {
1761 1.18.2.4 jdolecek mpt_softc_t *mpt = device_private(dev);
1762 1.18.2.4 jdolecek int error, s;
1763 1.18.2.4 jdolecek
1764 1.18.2.4 jdolecek KERNEL_LOCK(1, curlwp);
1765 1.18.2.4 jdolecek s = splbio();
1766 1.18.2.4 jdolecek
1767 1.18.2.4 jdolecek switch (cmd) {
1768 1.18.2.4 jdolecek case BIOCINQ:
1769 1.18.2.4 jdolecek error = mpt_bio_ioctl_inq(mpt, addr);
1770 1.18.2.4 jdolecek break;
1771 1.18.2.4 jdolecek case BIOCVOL:
1772 1.18.2.4 jdolecek error = mpt_bio_ioctl_vol(mpt, addr);
1773 1.18.2.4 jdolecek break;
1774 1.18.2.4 jdolecek case BIOCDISK_NOVOL:
1775 1.18.2.4 jdolecek error = mpt_bio_ioctl_disk_novol(mpt, addr);
1776 1.18.2.4 jdolecek break;
1777 1.18.2.4 jdolecek case BIOCDISK:
1778 1.18.2.4 jdolecek error = mpt_bio_ioctl_disk(mpt, addr);
1779 1.18.2.4 jdolecek break;
1780 1.18.2.4 jdolecek case BIOCSETSTATE:
1781 1.18.2.4 jdolecek error = mpt_bio_ioctl_setstate(mpt, addr);
1782 1.18.2.4 jdolecek break;
1783 1.18.2.4 jdolecek default:
1784 1.18.2.4 jdolecek error = EINVAL;
1785 1.18.2.4 jdolecek break;
1786 1.18.2.4 jdolecek }
1787 1.18.2.4 jdolecek
1788 1.18.2.4 jdolecek splx(s);
1789 1.18.2.4 jdolecek KERNEL_UNLOCK_ONE(curlwp);
1790 1.18.2.4 jdolecek
1791 1.18.2.4 jdolecek return error;
1792 1.18.2.4 jdolecek }
1793 1.18.2.4 jdolecek
1794 1.18.2.4 jdolecek static int
1795 1.18.2.4 jdolecek mpt_bio_ioctl_inq(mpt_softc_t *mpt, struct bioc_inq *bi)
1796 1.18.2.4 jdolecek {
1797 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2 *ioc2;
1798 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_3 *ioc3;
1799 1.18.2.4 jdolecek
1800 1.18.2.4 jdolecek ioc2 = mpt_get_cfg_page_ioc2(mpt);
1801 1.18.2.4 jdolecek if (ioc2 == NULL)
1802 1.18.2.4 jdolecek return EIO;
1803 1.18.2.4 jdolecek ioc3 = mpt_get_cfg_page_ioc3(mpt);
1804 1.18.2.4 jdolecek if (ioc3 == NULL) {
1805 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
1806 1.18.2.4 jdolecek return EIO;
1807 1.18.2.4 jdolecek }
1808 1.18.2.4 jdolecek
1809 1.18.2.4 jdolecek strlcpy(bi->bi_dev, device_xname(mpt->sc_dev), sizeof(bi->bi_dev));
1810 1.18.2.4 jdolecek bi->bi_novol = ioc2->NumActiveVolumes;
1811 1.18.2.4 jdolecek bi->bi_nodisk = ioc3->NumPhysDisks;
1812 1.18.2.4 jdolecek
1813 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
1814 1.18.2.4 jdolecek free(ioc3, M_DEVBUF);
1815 1.18.2.4 jdolecek
1816 1.18.2.4 jdolecek return 0;
1817 1.18.2.4 jdolecek }
1818 1.18.2.4 jdolecek
1819 1.18.2.4 jdolecek static int
1820 1.18.2.4 jdolecek mpt_bio_ioctl_vol(mpt_softc_t *mpt, struct bioc_vol *bv)
1821 1.18.2.4 jdolecek {
1822 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2 *ioc2 = NULL;
1823 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2_RAID_VOL *ioc2rvol;
1824 1.18.2.4 jdolecek fCONFIG_PAGE_RAID_VOL_0 *rvol0 = NULL;
1825 1.18.2.4 jdolecek struct scsipi_periph *periph;
1826 1.18.2.4 jdolecek struct scsipi_inquiry_data inqbuf;
1827 1.18.2.4 jdolecek char vendor[9], product[17], revision[5];
1828 1.18.2.4 jdolecek int address;
1829 1.18.2.4 jdolecek
1830 1.18.2.4 jdolecek ioc2 = mpt_get_cfg_page_ioc2(mpt);
1831 1.18.2.4 jdolecek if (ioc2 == NULL)
1832 1.18.2.4 jdolecek return EIO;
1833 1.18.2.4 jdolecek
1834 1.18.2.4 jdolecek if (bv->bv_volid < 0 || bv->bv_volid >= ioc2->NumActiveVolumes)
1835 1.18.2.4 jdolecek goto fail;
1836 1.18.2.4 jdolecek
1837 1.18.2.4 jdolecek ioc2rvol = &ioc2->RaidVolume[bv->bv_volid];
1838 1.18.2.4 jdolecek address = ioc2rvol->VolumeID | (ioc2rvol->VolumeBus << 8);
1839 1.18.2.4 jdolecek
1840 1.18.2.4 jdolecek rvol0 = mpt_get_cfg_page_raid_vol0(mpt, address);
1841 1.18.2.4 jdolecek if (rvol0 == NULL)
1842 1.18.2.4 jdolecek goto fail;
1843 1.18.2.4 jdolecek
1844 1.18.2.4 jdolecek bv->bv_dev[0] = '\0';
1845 1.18.2.4 jdolecek bv->bv_vendor[0] = '\0';
1846 1.18.2.4 jdolecek
1847 1.18.2.4 jdolecek periph = scsipi_lookup_periph(&mpt->sc_channel, ioc2rvol->VolumeBus, 0);
1848 1.18.2.4 jdolecek if (periph != NULL) {
1849 1.18.2.4 jdolecek if (periph->periph_dev != NULL) {
1850 1.18.2.4 jdolecek snprintf(bv->bv_dev, sizeof(bv->bv_dev), "%s",
1851 1.18.2.4 jdolecek device_xname(periph->periph_dev));
1852 1.18.2.4 jdolecek }
1853 1.18.2.4 jdolecek memset(&inqbuf, 0, sizeof(inqbuf));
1854 1.18.2.4 jdolecek if (scsipi_inquire(periph, &inqbuf,
1855 1.18.2.4 jdolecek XS_CTL_DISCOVERY | XS_CTL_SILENT) == 0) {
1856 1.18.2.4 jdolecek strnvisx(vendor, sizeof(vendor),
1857 1.18.2.4 jdolecek inqbuf.vendor, sizeof(inqbuf.vendor),
1858 1.18.2.4 jdolecek VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1859 1.18.2.4 jdolecek strnvisx(product, sizeof(product),
1860 1.18.2.4 jdolecek inqbuf.product, sizeof(inqbuf.product),
1861 1.18.2.4 jdolecek VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1862 1.18.2.4 jdolecek strnvisx(revision, sizeof(revision),
1863 1.18.2.4 jdolecek inqbuf.revision, sizeof(inqbuf.revision),
1864 1.18.2.4 jdolecek VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1865 1.18.2.4 jdolecek
1866 1.18.2.4 jdolecek snprintf(bv->bv_vendor, sizeof(bv->bv_vendor),
1867 1.18.2.4 jdolecek "%s %s %s", vendor, product, revision);
1868 1.18.2.4 jdolecek }
1869 1.18.2.4 jdolecek
1870 1.18.2.4 jdolecek snprintf(bv->bv_dev, sizeof(bv->bv_dev), "%s",
1871 1.18.2.4 jdolecek device_xname(periph->periph_dev));
1872 1.18.2.4 jdolecek }
1873 1.18.2.4 jdolecek bv->bv_nodisk = rvol0->NumPhysDisks;
1874 1.18.2.4 jdolecek bv->bv_size = (uint64_t)rvol0->MaxLBA * 512;
1875 1.18.2.4 jdolecek bv->bv_stripe_size = rvol0->StripeSize;
1876 1.18.2.4 jdolecek bv->bv_percent = -1;
1877 1.18.2.4 jdolecek bv->bv_seconds = 0;
1878 1.18.2.4 jdolecek
1879 1.18.2.4 jdolecek switch (rvol0->VolumeStatus.State) {
1880 1.18.2.4 jdolecek case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
1881 1.18.2.4 jdolecek bv->bv_status = BIOC_SVONLINE;
1882 1.18.2.4 jdolecek break;
1883 1.18.2.4 jdolecek case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
1884 1.18.2.4 jdolecek bv->bv_status = BIOC_SVDEGRADED;
1885 1.18.2.4 jdolecek break;
1886 1.18.2.4 jdolecek case MPI_RAIDVOL0_STATUS_STATE_FAILED:
1887 1.18.2.4 jdolecek bv->bv_status = BIOC_SVOFFLINE;
1888 1.18.2.4 jdolecek break;
1889 1.18.2.4 jdolecek default:
1890 1.18.2.4 jdolecek bv->bv_status = BIOC_SVINVALID;
1891 1.18.2.4 jdolecek break;
1892 1.18.2.4 jdolecek }
1893 1.18.2.4 jdolecek
1894 1.18.2.4 jdolecek switch (ioc2rvol->VolumeType) {
1895 1.18.2.4 jdolecek case MPI_RAID_VOL_TYPE_IS:
1896 1.18.2.4 jdolecek bv->bv_level = 0;
1897 1.18.2.4 jdolecek break;
1898 1.18.2.4 jdolecek case MPI_RAID_VOL_TYPE_IME:
1899 1.18.2.4 jdolecek case MPI_RAID_VOL_TYPE_IM:
1900 1.18.2.4 jdolecek bv->bv_level = 1;
1901 1.18.2.4 jdolecek break;
1902 1.18.2.4 jdolecek default:
1903 1.18.2.4 jdolecek bv->bv_level = -1;
1904 1.18.2.4 jdolecek break;
1905 1.18.2.4 jdolecek }
1906 1.18.2.4 jdolecek
1907 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
1908 1.18.2.4 jdolecek free(rvol0, M_DEVBUF);
1909 1.18.2.4 jdolecek
1910 1.18.2.4 jdolecek return 0;
1911 1.18.2.4 jdolecek
1912 1.18.2.4 jdolecek fail:
1913 1.18.2.4 jdolecek if (ioc2) free(ioc2, M_DEVBUF);
1914 1.18.2.4 jdolecek if (rvol0) free(rvol0, M_DEVBUF);
1915 1.18.2.4 jdolecek return EINVAL;
1916 1.18.2.4 jdolecek }
1917 1.18.2.4 jdolecek
1918 1.18.2.4 jdolecek static void
1919 1.18.2.4 jdolecek mpt_bio_ioctl_disk_common(mpt_softc_t *mpt, struct bioc_disk *bd,
1920 1.18.2.4 jdolecek int address)
1921 1.18.2.4 jdolecek {
1922 1.18.2.4 jdolecek fCONFIG_PAGE_RAID_PHYS_DISK_0 *phys = NULL;
1923 1.18.2.4 jdolecek char vendor_id[9], product_id[17], product_rev_level[5];
1924 1.18.2.4 jdolecek
1925 1.18.2.4 jdolecek phys = mpt_get_cfg_page_raid_phys_disk0(mpt, address);
1926 1.18.2.4 jdolecek if (phys == NULL)
1927 1.18.2.4 jdolecek return;
1928 1.18.2.4 jdolecek
1929 1.18.2.4 jdolecek strnvisx(vendor_id, sizeof(vendor_id),
1930 1.18.2.4 jdolecek phys->InquiryData.VendorID, sizeof(phys->InquiryData.VendorID),
1931 1.18.2.4 jdolecek VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1932 1.18.2.4 jdolecek strnvisx(product_id, sizeof(product_id),
1933 1.18.2.4 jdolecek phys->InquiryData.ProductID, sizeof(phys->InquiryData.ProductID),
1934 1.18.2.4 jdolecek VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1935 1.18.2.4 jdolecek strnvisx(product_rev_level, sizeof(product_rev_level),
1936 1.18.2.4 jdolecek phys->InquiryData.ProductRevLevel,
1937 1.18.2.4 jdolecek sizeof(phys->InquiryData.ProductRevLevel),
1938 1.18.2.4 jdolecek VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1939 1.18.2.4 jdolecek
1940 1.18.2.4 jdolecek snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s %s",
1941 1.18.2.4 jdolecek vendor_id, product_id, product_rev_level);
1942 1.18.2.4 jdolecek strlcpy(bd->bd_serial, phys->InquiryData.Info, sizeof(bd->bd_serial));
1943 1.18.2.4 jdolecek bd->bd_procdev[0] = '\0';
1944 1.18.2.4 jdolecek bd->bd_channel = phys->PhysDiskBus;
1945 1.18.2.4 jdolecek bd->bd_target = phys->PhysDiskID;
1946 1.18.2.4 jdolecek bd->bd_lun = 0;
1947 1.18.2.4 jdolecek bd->bd_size = (uint64_t)phys->MaxLBA * 512;
1948 1.18.2.4 jdolecek
1949 1.18.2.4 jdolecek switch (phys->PhysDiskStatus.State) {
1950 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_ONLINE:
1951 1.18.2.4 jdolecek bd->bd_status = BIOC_SDONLINE;
1952 1.18.2.4 jdolecek break;
1953 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_MISSING:
1954 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_FAILED:
1955 1.18.2.4 jdolecek bd->bd_status = BIOC_SDFAILED;
1956 1.18.2.4 jdolecek break;
1957 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED:
1958 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_FAILED_REQUESTED:
1959 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_OTHER_OFFLINE:
1960 1.18.2.4 jdolecek bd->bd_status = BIOC_SDOFFLINE;
1961 1.18.2.4 jdolecek break;
1962 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_INITIALIZING:
1963 1.18.2.4 jdolecek bd->bd_status = BIOC_SDSCRUB;
1964 1.18.2.4 jdolecek break;
1965 1.18.2.4 jdolecek case MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE:
1966 1.18.2.4 jdolecek default:
1967 1.18.2.4 jdolecek bd->bd_status = BIOC_SDINVALID;
1968 1.18.2.4 jdolecek break;
1969 1.18.2.4 jdolecek }
1970 1.18.2.4 jdolecek
1971 1.18.2.4 jdolecek free(phys, M_DEVBUF);
1972 1.18.2.4 jdolecek }
1973 1.18.2.4 jdolecek
1974 1.18.2.4 jdolecek static int
1975 1.18.2.4 jdolecek mpt_bio_ioctl_disk_novol(mpt_softc_t *mpt, struct bioc_disk *bd)
1976 1.18.2.4 jdolecek {
1977 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2 *ioc2 = NULL;
1978 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_3 *ioc3 = NULL;
1979 1.18.2.4 jdolecek fCONFIG_PAGE_RAID_VOL_0 *rvol0 = NULL;
1980 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2_RAID_VOL *ioc2rvol;
1981 1.18.2.4 jdolecek int address, v, d;
1982 1.18.2.4 jdolecek
1983 1.18.2.4 jdolecek ioc2 = mpt_get_cfg_page_ioc2(mpt);
1984 1.18.2.4 jdolecek if (ioc2 == NULL)
1985 1.18.2.4 jdolecek return EIO;
1986 1.18.2.4 jdolecek ioc3 = mpt_get_cfg_page_ioc3(mpt);
1987 1.18.2.4 jdolecek if (ioc3 == NULL) {
1988 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
1989 1.18.2.4 jdolecek return EIO;
1990 1.18.2.4 jdolecek }
1991 1.18.2.4 jdolecek
1992 1.18.2.4 jdolecek if (bd->bd_diskid < 0 || bd->bd_diskid >= ioc3->NumPhysDisks)
1993 1.18.2.4 jdolecek goto fail;
1994 1.18.2.4 jdolecek
1995 1.18.2.4 jdolecek address = ioc3->PhysDisk[bd->bd_diskid].PhysDiskNum;
1996 1.18.2.4 jdolecek
1997 1.18.2.4 jdolecek mpt_bio_ioctl_disk_common(mpt, bd, address);
1998 1.18.2.4 jdolecek
1999 1.18.2.4 jdolecek bd->bd_disknovol = true;
2000 1.18.2.4 jdolecek for (v = 0; bd->bd_disknovol && v < ioc2->NumActiveVolumes; v++) {
2001 1.18.2.4 jdolecek ioc2rvol = &ioc2->RaidVolume[v];
2002 1.18.2.4 jdolecek address = ioc2rvol->VolumeID | (ioc2rvol->VolumeBus << 8);
2003 1.18.2.4 jdolecek
2004 1.18.2.4 jdolecek rvol0 = mpt_get_cfg_page_raid_vol0(mpt, address);
2005 1.18.2.4 jdolecek if (rvol0 == NULL)
2006 1.18.2.4 jdolecek continue;
2007 1.18.2.4 jdolecek
2008 1.18.2.4 jdolecek for (d = 0; d < rvol0->NumPhysDisks; d++) {
2009 1.18.2.4 jdolecek if (rvol0->PhysDisk[d].PhysDiskNum ==
2010 1.18.2.4 jdolecek ioc3->PhysDisk[bd->bd_diskid].PhysDiskNum) {
2011 1.18.2.4 jdolecek bd->bd_disknovol = false;
2012 1.18.2.4 jdolecek bd->bd_volid = v;
2013 1.18.2.4 jdolecek break;
2014 1.18.2.4 jdolecek }
2015 1.18.2.4 jdolecek }
2016 1.18.2.4 jdolecek free(rvol0, M_DEVBUF);
2017 1.18.2.4 jdolecek }
2018 1.18.2.4 jdolecek
2019 1.18.2.4 jdolecek free(ioc3, M_DEVBUF);
2020 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
2021 1.18.2.4 jdolecek
2022 1.18.2.4 jdolecek return 0;
2023 1.18.2.4 jdolecek
2024 1.18.2.4 jdolecek fail:
2025 1.18.2.4 jdolecek if (ioc3) free(ioc3, M_DEVBUF);
2026 1.18.2.4 jdolecek if (ioc2) free(ioc2, M_DEVBUF);
2027 1.18.2.4 jdolecek return EINVAL;
2028 1.18.2.4 jdolecek }
2029 1.18.2.4 jdolecek
2030 1.18.2.4 jdolecek
2031 1.18.2.4 jdolecek static int
2032 1.18.2.4 jdolecek mpt_bio_ioctl_disk(mpt_softc_t *mpt, struct bioc_disk *bd)
2033 1.18.2.4 jdolecek {
2034 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2 *ioc2 = NULL;
2035 1.18.2.4 jdolecek fCONFIG_PAGE_RAID_VOL_0 *rvol0 = NULL;
2036 1.18.2.4 jdolecek fCONFIG_PAGE_IOC_2_RAID_VOL *ioc2rvol;
2037 1.18.2.4 jdolecek int address;
2038 1.18.2.4 jdolecek
2039 1.18.2.4 jdolecek ioc2 = mpt_get_cfg_page_ioc2(mpt);
2040 1.18.2.4 jdolecek if (ioc2 == NULL)
2041 1.18.2.4 jdolecek return EIO;
2042 1.18.2.4 jdolecek
2043 1.18.2.4 jdolecek if (bd->bd_volid < 0 || bd->bd_volid >= ioc2->NumActiveVolumes)
2044 1.18.2.4 jdolecek goto fail;
2045 1.18.2.4 jdolecek
2046 1.18.2.4 jdolecek ioc2rvol = &ioc2->RaidVolume[bd->bd_volid];
2047 1.18.2.4 jdolecek address = ioc2rvol->VolumeID | (ioc2rvol->VolumeBus << 8);
2048 1.18.2.4 jdolecek
2049 1.18.2.4 jdolecek rvol0 = mpt_get_cfg_page_raid_vol0(mpt, address);
2050 1.18.2.4 jdolecek if (rvol0 == NULL)
2051 1.18.2.4 jdolecek goto fail;
2052 1.18.2.4 jdolecek
2053 1.18.2.4 jdolecek if (bd->bd_diskid < 0 || bd->bd_diskid >= rvol0->NumPhysDisks)
2054 1.18.2.4 jdolecek goto fail;
2055 1.18.2.4 jdolecek
2056 1.18.2.4 jdolecek address = rvol0->PhysDisk[bd->bd_diskid].PhysDiskNum;
2057 1.18.2.4 jdolecek
2058 1.18.2.4 jdolecek mpt_bio_ioctl_disk_common(mpt, bd, address);
2059 1.18.2.4 jdolecek
2060 1.18.2.4 jdolecek free(ioc2, M_DEVBUF);
2061 1.18.2.4 jdolecek
2062 1.18.2.4 jdolecek return 0;
2063 1.18.2.4 jdolecek
2064 1.18.2.4 jdolecek fail:
2065 1.18.2.4 jdolecek if (ioc2) free(ioc2, M_DEVBUF);
2066 1.18.2.4 jdolecek return EINVAL;
2067 1.18.2.4 jdolecek }
2068 1.18.2.4 jdolecek
2069 1.18.2.4 jdolecek static int
2070 1.18.2.4 jdolecek mpt_bio_ioctl_setstate(mpt_softc_t *mpt, struct bioc_setstate *bs)
2071 1.18.2.4 jdolecek {
2072 1.18.2.4 jdolecek return ENOTTY;
2073 1.18.2.4 jdolecek }
2074 1.18.2.4 jdolecek #endif
2075 1.18.2.4 jdolecek
2076