xref: /dragonfly/sys/dev/raid/amr/amr_cam.c (revision 1ab20d67)
1 /*-
2  * Copyright (c) 2000 Michael Smith
3  * Copyright (c) 2000 BSDi
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * Copyright (c) 2002 Eric Moore
28  * Copyright (c) 2002 LSI Logic Corporation
29  * All rights reserved.
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  * 1. Redistributions of source code must retain the above copyright
35  *    notice, this list of conditions and the following disclaimer.
36  * 2. Redistributions in binary form must reproduce the above copyright
37  *    notice, this list of conditions and the following disclaimer in the
38  *    documentation and/or other materials provided with the distribution.
39  * 3. The party using or redistributing the source code and binary forms
40  *    agrees to the disclaimer below and the terms and conditions set forth
41  *    herein.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
44  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53  * SUCH DAMAGE.
54  *
55  *	$FreeBSD: src/sys/dev/amr/amr_cam.c,v 1.1.2.3 2002/11/11 13:19:10 emoore Exp $
56  *	$DragonFly: src/sys/dev/raid/amr/amr_cam.c,v 1.4 2004/03/15 03:05:05 dillon Exp $
57  */
58 
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/malloc.h>
62 #include <sys/kernel.h>
63 
64 #include "amr_compat.h"
65 #include <sys/bus.h>
66 #include <sys/conf.h>
67 #include <sys/devicestat.h>
68 #include <sys/disk.h>
69 #include <sys/stat.h>
70 
71 #include <bus/cam/cam.h>
72 #include <bus/cam/cam_ccb.h>
73 #include <bus/cam/cam_sim.h>
74 #include <bus/cam/cam_xpt.h>
75 #include <bus/cam/cam_xpt_sim.h>
76 #include <bus/cam/cam_debug.h>
77 #include <bus/cam/scsi/scsi_all.h>
78 #include <bus/cam/scsi/scsi_message.h>
79 
80 #include <machine/resource.h>
81 #include <machine/bus.h>
82 
83 #include "amrreg.h"
84 #include "amrvar.h"
85 
86 static void		amr_cam_action(struct cam_sim *sim, union ccb *ccb);
87 static void		amr_cam_poll(struct cam_sim *sim);
88 static void		amr_cam_complete(struct amr_command *ac);
89 static void		amr_cam_complete_extcdb(struct amr_command *ac);
90 
91 
92 /********************************************************************************
93  * Enqueue/dequeue functions
94  */
95 static __inline void
96 amr_enqueue_ccb(struct amr_softc *sc, union ccb *ccb)
97 {
98     int		s;
99 
100     s = splbio();
101     TAILQ_INSERT_TAIL(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
102     splx(s);
103 }
104 
105 static __inline void
106 amr_requeue_ccb(struct amr_softc *sc, union ccb *ccb)
107 {
108     int		s;
109 
110     s = splbio();
111     TAILQ_INSERT_HEAD(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
112     splx(s);
113 }
114 
115 static __inline union ccb *
116 amr_dequeue_ccb(struct amr_softc *sc)
117 {
118     union ccb	*ccb;
119     int		s;
120 
121     s = splbio();
122     if ((ccb = (union ccb *)TAILQ_FIRST(&sc->amr_cam_ccbq)) != NULL)
123 	TAILQ_REMOVE(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
124     splx(s);
125     return(ccb);
126 }
127 
128 /********************************************************************************
129  * Attach our 'real' SCSI channels to CAM
130  */
131 int
132 amr_cam_attach(struct amr_softc *sc)
133 {
134     struct cam_devq	*devq;
135     int			chn;
136 
137     /* initialise the ccb queue */
138     TAILQ_INIT(&sc->amr_cam_ccbq);
139 
140     /*
141      * Allocate a devq for all our channels combined.  This should
142      * allow for the maximum number of SCSI commands we will accept
143      * at one time.
144      */
145     if ((devq = cam_simq_alloc(AMR_MAX_SCSI_CMDS)) == NULL)
146 	return(ENOMEM);
147 
148     /*
149      * Iterate over our channels, registering them with CAM
150      */
151     for (chn = 0; chn < sc->amr_maxchan; chn++) {
152 
153 	/* allocate a sim */
154 	if ((sc->amr_cam_sim[chn] = cam_sim_alloc(amr_cam_action,
155 						  amr_cam_poll,
156 						  "amr",
157 						  sc,
158 						  device_get_unit(sc->amr_dev),
159 						  1,
160 						  AMR_MAX_SCSI_CMDS,
161 						  devq)) == NULL) {
162 	    device_printf(sc->amr_dev, "CAM SIM attach failed\n");
163 	    return(ENOMEM);
164 	}
165 
166 	/* register the bus ID so we can get it later */
167 	if (xpt_bus_register(sc->amr_cam_sim[chn], chn)) {
168 	    device_printf(sc->amr_dev, "CAM XPT bus registration failed\n");
169 	    return(ENXIO);
170 	}
171     }
172     cam_simq_release(devq);
173     /*
174      * XXX we should scan the config and work out which devices are actually
175      * protected.
176      */
177     return(0);
178 }
179 
180 /********************************************************************************
181  * Disconnect ourselves from CAM
182  */
183 void
184 amr_cam_detach(struct amr_softc *sc)
185 {
186     int		chn;
187 
188     /*
189      * If a sim was allocated for a channel, free it
190      */
191     for (chn = 0; chn < sc->amr_maxchan; chn++) {
192 	if (sc->amr_cam_sim[chn] != NULL) {
193 	    xpt_bus_deregister(cam_sim_path(sc->amr_cam_sim[chn]));
194 	    cam_sim_free(sc->amr_cam_sim[chn]);
195 	}
196     }
197 }
198 
199 /********************************************************************************
200  ********************************************************************************
201                                                         CAM passthrough interface
202  ********************************************************************************
203  ********************************************************************************/
204 
205 /********************************************************************************
206  * Handle a request for action from CAM
207  */
208 static void
209 amr_cam_action(struct cam_sim *sim, union ccb *ccb)
210 {
211     struct amr_softc	*sc = cam_sim_softc(sim);
212 
213     switch(ccb->ccb_h.func_code) {
214 
215     /*
216      * Perform SCSI I/O to a physical device.
217      */
218     case XPT_SCSI_IO:
219     {
220 	struct ccb_hdr		*ccbh = &ccb->ccb_h;
221 	struct ccb_scsiio	*csio = &ccb->csio;
222 
223 	/* Validate the CCB */
224 	ccbh->status = CAM_REQ_INPROG;
225 
226 	/* check the CDB length */
227 	if (csio->cdb_len > AMR_MAX_EXTCDB_LEN)
228 	    ccbh->status = CAM_REQ_CMP_ERR;
229 
230 	if ((csio->cdb_len > AMR_MAX_CDB_LEN) && (sc->support_ext_cdb == 0 ))
231 	    ccbh->status = CAM_REQ_CMP_ERR;
232 
233 	/* check that the CDB pointer is not to a physical address */
234 	if ((ccbh->flags & CAM_CDB_POINTER) && (ccbh->flags & CAM_CDB_PHYS))
235 	    ccbh->status = CAM_REQ_CMP_ERR;
236 
237 	/* if there is data transfer, it must be to/from a virtual address */
238 	if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
239 	    if (ccbh->flags & CAM_DATA_PHYS)		/* we can't map it */
240 		ccbh->status = CAM_REQ_CMP_ERR;
241 	    if (ccbh->flags & CAM_SCATTER_VALID)	/* we want to do the s/g setup */
242 		ccbh->status = CAM_REQ_CMP_ERR;
243 	}
244 
245 	/*
246 	 * If the command is to a LUN other than 0, fail it.
247 	 * This is probably incorrect, but during testing the firmware did not
248 	 * seem to respect the LUN field, and thus devices appear echoed.
249 	 */
250 	if (csio->ccb_h.target_lun != 0)
251 	    ccbh->status = CAM_REQ_CMP_ERR;
252 
253 	/* if we're happy with the request, queue it for attention */
254 	if (ccbh->status == CAM_REQ_INPROG) {
255 
256 	    /* save the channel number in the ccb */
257 	    csio->ccb_h.sim_priv.entries[0].field = cam_sim_bus(sim);
258 
259 	    amr_enqueue_ccb(sc, ccb);
260 	    amr_startio(sc);
261 	    return;
262 	}
263 	break;
264     }
265 
266     case XPT_CALC_GEOMETRY:
267     {
268 	struct    ccb_calc_geometry *ccg = &ccb->ccg;
269 	u_int32_t size_in_mb;
270 	u_int32_t secs_per_cylinder;
271 
272 	size_in_mb = ccg->volume_size / ((1024L * 1024L) / ccg->block_size);
273 
274 	if (size_in_mb > 1024) {
275 	    ccg->heads = 255;
276 	    ccg->secs_per_track = 63;
277 	} else {
278 	    ccg->heads = 64;
279 	    ccg->secs_per_track = 32;
280 	}
281 	secs_per_cylinder = ccg->heads * ccg->secs_per_track;
282 	ccg->cylinders = ccg->volume_size / secs_per_cylinder;
283 	ccb->ccb_h.status = CAM_REQ_CMP;
284 	break;
285     }
286 
287     /*
288      * Return path stats.  Some of these should probably be
289      * amended.
290      */
291     case XPT_PATH_INQ:
292     {
293 	struct ccb_pathinq      *cpi = & ccb->cpi;
294 
295 	debug(3, "XPT_PATH_INQ");
296 	cpi->version_num = 1;           /* XXX??? */
297 	cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
298 	cpi->target_sprt = 0;
299 	cpi->hba_misc = PIM_NOBUSRESET;
300 	cpi->hba_eng_cnt = 0;
301 	cpi->max_target = AMR_MAX_TARGETS;
302 	cpi->max_lun = 0 /* AMR_MAX_LUNS*/;
303 	cpi->initiator_id = 7;          /* XXX variable? */
304 	strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
305 	strncpy(cpi->hba_vid, "LSI", HBA_IDLEN);
306 	strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
307 	cpi->unit_number = cam_sim_unit(sim);
308 	cpi->bus_id = cam_sim_bus(sim);
309 	cpi->base_transfer_speed = 132 * 1024;  /* XXX get from controller? */
310 	cpi->ccb_h.status = CAM_REQ_CMP;
311 
312 	break;
313     }
314 
315     case XPT_RESET_BUS:
316     {
317 	struct ccb_pathinq	*cpi = & ccb->cpi;
318 
319 	debug(1, "XPT_RESET_BUS");
320 	cpi->ccb_h.status = CAM_REQ_CMP;
321 	break;
322     }
323 
324     case XPT_RESET_DEV:
325     {
326 	debug(1, "XPT_RESET_DEV");
327 	ccb->ccb_h.status = CAM_REQ_CMP;
328 	break;
329     }
330 
331     case XPT_GET_TRAN_SETTINGS:
332     {
333 	struct ccb_trans_settings	*cts;
334 
335 	debug(3, "XPT_GET_TRAN_SETTINGS");
336 
337 	cts = &(ccb->cts);
338 
339 	if ((cts->flags & CCB_TRANS_USER_SETTINGS) == 0) {
340 		ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
341 		break;
342         }
343 
344 	cts->flags = CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB;
345 	cts->bus_width = MSG_EXT_WDTR_BUS_32_BIT;
346 	cts->sync_period = 6;   /* 40MHz how wide is this bus? */
347 	cts->sync_offset = 31;  /* How to extract this from board? */
348 
349 	cts->valid = CCB_TRANS_SYNC_RATE_VALID
350 	    | CCB_TRANS_SYNC_OFFSET_VALID
351 	    | CCB_TRANS_BUS_WIDTH_VALID
352 	    | CCB_TRANS_DISC_VALID
353 	    | CCB_TRANS_TQ_VALID;
354 	ccb->ccb_h.status = CAM_REQ_CMP;
355 	break;
356     }
357 
358     case XPT_SET_TRAN_SETTINGS:
359 	debug(3, "XPT_SET_TRAN_SETTINGS");
360 	ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
361 	break;
362 
363 
364     /*
365      * Reject anything else as unsupported.
366      */
367     default:
368 	/* we can't do this */
369 	ccb->ccb_h.status = CAM_REQ_INVALID;
370 	break;
371     }
372     xpt_done(ccb);
373 }
374 
375 /********************************************************************************
376  * Convert a CAM CCB off the top of the CCB queue to a passthrough SCSI command.
377  */
378 int
379 amr_cam_command(struct amr_softc *sc, struct amr_command **acp)
380 {
381     struct amr_command		*ac;
382     struct amr_passthrough		*ap;
383     struct amr_ext_passthrough	*aep;
384     struct ccb_scsiio			*csio;
385     int				bus, target, error;
386 
387     error = 0;
388     ac = NULL;
389     ap = NULL;
390     aep = NULL;
391 
392     /* check to see if there is a ccb for us to work with */
393     if ((csio = (struct ccb_scsiio *)amr_dequeue_ccb(sc)) == NULL)
394 	goto out;
395 
396     /* get bus/target, XXX validate against protected devices? */
397     bus = csio->ccb_h.sim_priv.entries[0].field;
398     target = csio->ccb_h.target_id;
399 
400     /*
401      * Build a passthrough command.
402      */
403 
404     /* construct passthrough */
405     if (sc->support_ext_cdb ) {
406 	    if ((aep = malloc(sizeof(*aep), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
407 		error = ENOMEM;
408 		goto out;
409 	    }
410 	    aep->ap_timeout = 2;
411 	    aep->ap_ars = 1;
412 	    aep->ap_request_sense_length = 14;
413 	    aep->ap_islogical = 0;
414 	    aep->ap_channel = bus;
415 	    aep->ap_scsi_id = target;
416 	    aep->ap_logical_drive_no = csio->ccb_h.target_lun;
417 	    aep->ap_cdb_length = csio->cdb_len;
418 	    aep->ap_data_transfer_length = csio->dxfer_len;
419 	    if (csio->ccb_h.flags & CAM_CDB_POINTER) {
420 		bcopy(csio->cdb_io.cdb_ptr, aep->ap_cdb, csio->cdb_len);
421 	    } else {
422 		bcopy(csio->cdb_io.cdb_bytes, aep->ap_cdb, csio->cdb_len);
423 	    }
424 	    /* we leave the data s/g list and s/g count to the map routine later */
425 
426 	    debug(2, " COMMAND %x/%d+%d to %d:%d:%d", aep->ap_cdb[0], aep->ap_cdb_length, csio->dxfer_len,
427 		  aep->ap_channel, aep->ap_scsi_id, aep->ap_logical_drive_no);
428 
429     } else {
430 	    if ((ap = malloc(sizeof(*ap), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
431 		error = ENOMEM;
432 		goto out;
433 	    }
434 	    ap->ap_timeout = 0;
435 	    ap->ap_ars = 1;
436 	    ap->ap_request_sense_length = 14;
437 	    ap->ap_islogical = 0;
438 	    ap->ap_channel = bus;
439 	    ap->ap_scsi_id = target;
440 	    ap->ap_logical_drive_no = csio->ccb_h.target_lun;
441 	    ap->ap_cdb_length = csio->cdb_len;
442 	    ap->ap_data_transfer_length = csio->dxfer_len;
443 	    if (csio->ccb_h.flags & CAM_CDB_POINTER) {
444 		bcopy(csio->cdb_io.cdb_ptr, ap->ap_cdb, csio->cdb_len);
445 	    } else {
446 		bcopy(csio->cdb_io.cdb_bytes, ap->ap_cdb, csio->cdb_len);
447 	    }
448 	    /* we leave the data s/g list and s/g count to the map routine later */
449 
450 	    debug(2, " COMMAND %x/%d+%d to %d:%d:%d", ap->ap_cdb[0], ap->ap_cdb_length, csio->dxfer_len,
451 		  ap->ap_channel, ap->ap_scsi_id, ap->ap_logical_drive_no);
452     }
453 
454     /* construct command */
455     if ((ac = amr_alloccmd(sc)) == NULL) {
456 	error = ENOMEM;
457 	goto out;
458     }
459 
460     ac->ac_flags |= AMR_CMD_DATAOUT;
461 
462     ac->ac_ccb_data = csio->data_ptr;
463     ac->ac_ccb_length = csio->dxfer_len;
464     if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
465 	ac->ac_flags |= AMR_CMD_CCB_DATAIN;
466     if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
467 	ac->ac_flags |= AMR_CMD_CCB_DATAOUT;
468 
469     ac->ac_private = csio;
470     if ( sc->support_ext_cdb ) {
471 	    ac->ac_data = aep;
472 	    ac->ac_length = sizeof(*aep);
473 	    ac->ac_complete = amr_cam_complete_extcdb;
474 	    ac->ac_mailbox.mb_command = AMR_CMD_EXTPASS;
475     } else {
476 	    ac->ac_data = ap;
477 	    ac->ac_length = sizeof(*ap);
478 	    ac->ac_complete = amr_cam_complete;
479 	    ac->ac_mailbox.mb_command = AMR_CMD_PASS;
480     }
481 
482 out:
483     if (error != 0) {
484 	if (ac != NULL)
485 	    amr_releasecmd(ac);
486 	if (ap != NULL)
487 	    free(ap, M_DEVBUF);
488 	if (aep != NULL)
489 	    free(aep, M_DEVBUF);
490 	if (csio != NULL)			/* put it back and try again later */
491 	    amr_requeue_ccb(sc, (union ccb *)csio);
492     }
493     *acp = ac;
494     return(error);
495 }
496 
497 /********************************************************************************
498  * Check for interrupt status
499  */
500 static void
501 amr_cam_poll(struct cam_sim *sim)
502 {
503     amr_done(cam_sim_softc(sim));
504 }
505 
506  /********************************************************************************
507  * Handle completion of a command submitted via CAM.
508  */
509 static void
510 amr_cam_complete(struct amr_command *ac)
511 {
512     struct amr_passthrough      *ap = (struct amr_passthrough *)ac->ac_data;
513     struct ccb_scsiio           *csio = (struct ccb_scsiio *)ac->ac_private;
514     struct scsi_inquiry_data    *inq = (struct scsi_inquiry_data *)csio->data_ptr;
515 
516     /* XXX note that we're ignoring ac->ac_status - good idea? */
517 
518     debug(1, "status 0x%x  scsi_status 0x%x", ac->ac_status, ap->ap_scsi_status);
519 
520     /*
521      * Hide disks from CAM so that they're not picked up and treated as 'normal' disks.
522      *
523      * If the configuration provides a mechanism to mark a disk a "not managed", we
524      * could add handling for that to allow disks to be selectively visible.
525      */
526 
527     if ((ap->ap_cdb[0] == INQUIRY) && (SID_TYPE(inq) == T_DIRECT)) {
528 	bzero(csio->data_ptr, csio->dxfer_len);
529 	if (ap->ap_scsi_status == 0xf0) {
530 	    csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
531 	} else {
532 	    csio->ccb_h.status = CAM_DEV_NOT_THERE;
533 	}
534     } else {
535 
536 	/* handle passthrough SCSI status */
537 	switch(ap->ap_scsi_status) {
538 	case 0:				/* completed OK */
539 	    csio->ccb_h.status = CAM_REQ_CMP;
540 	    break;
541 
542 	case 0x02:
543 	    csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
544 	    csio->scsi_status = SCSI_STATUS_CHECK_COND;
545 	    bcopy(ap->ap_request_sense_area, &csio->sense_data, AMR_MAX_REQ_SENSE_LEN);
546 	    csio->sense_len = AMR_MAX_REQ_SENSE_LEN;
547 	    csio->ccb_h.status |= CAM_AUTOSNS_VALID;
548 	    break;
549 
550 	case 0x08:
551 	    csio->ccb_h.status = CAM_SCSI_BUSY;
552 	    break;
553 
554 	case 0xf0:
555 	case 0xf4:
556 	default:
557 	    csio->ccb_h.status = CAM_REQ_CMP_ERR;
558 	    break;
559 	}
560     }
561     free(ap, M_DEVBUF);
562     if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE)
563 	debug(2, "%*D\n", imin(csio->dxfer_len, 16), csio->data_ptr, " ");
564     xpt_done((union ccb *)csio);
565     amr_releasecmd(ac);
566 }
567 
568 /********************************************************************************
569  * Handle completion of a command submitted via CAM.
570  * Completion for extended cdb
571  */
572 static void
573 amr_cam_complete_extcdb(struct amr_command *ac)
574 {
575     struct amr_ext_passthrough      *aep = (struct amr_ext_passthrough *)ac->ac_data;
576     struct ccb_scsiio           *csio = (struct ccb_scsiio *)ac->ac_private;
577     struct scsi_inquiry_data    *inq = (struct scsi_inquiry_data *)csio->data_ptr;
578 
579     /* XXX note that we're ignoring ac->ac_status - good idea? */
580 
581     debug(1, "status 0x%x  scsi_status 0x%x", ac->ac_status, aep->ap_scsi_status);
582 
583     /*
584      * Hide disks from CAM so that they're not picked up and treated as 'normal' disks.
585      *
586      * If the configuration provides a mechanism to mark a disk a "not managed", we
587      * could add handling for that to allow disks to be selectively visible.
588      */
589 
590     if ((aep->ap_cdb[0] == INQUIRY) && (SID_TYPE(inq) == T_DIRECT)) {
591 	bzero(csio->data_ptr, csio->dxfer_len);
592 	if (aep->ap_scsi_status == 0xf0) {
593 	    csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
594 	} else {
595 	    csio->ccb_h.status = CAM_DEV_NOT_THERE;
596 	}
597     } else {
598 
599 	/* handle passthrough SCSI status */
600 	switch(aep->ap_scsi_status) {
601 	case 0:				/* completed OK */
602 	    csio->ccb_h.status = CAM_REQ_CMP;
603 	    break;
604 
605 	case 0x02:
606 	    csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
607 	    csio->scsi_status = SCSI_STATUS_CHECK_COND;
608 	    bcopy(aep->ap_request_sense_area, &csio->sense_data, AMR_MAX_REQ_SENSE_LEN);
609 	    csio->sense_len = AMR_MAX_REQ_SENSE_LEN;
610 	    csio->ccb_h.status |= CAM_AUTOSNS_VALID;
611 	    break;
612 
613 	case 0x08:
614 	    csio->ccb_h.status = CAM_SCSI_BUSY;
615 	    break;
616 
617 	case 0xf0:
618 	case 0xf4:
619 	default:
620 	    csio->ccb_h.status = CAM_REQ_CMP_ERR;
621 	    break;
622 	}
623     }
624     free(aep, M_DEVBUF);
625     if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE)
626 	debug(2, "%*D\n", imin(csio->dxfer_len, 16), csio->data_ptr, " ");
627     xpt_done((union ccb *)csio);
628     amr_releasecmd(ac);
629 }
630