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