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