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