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