Merge branch 'vendor/GDB'
[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 /*-
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  * $FreeBSD: src/sys/dev/amr/amr_cam.c,v 1.28 2008/11/03 00:53:54 scottl Exp $
57  */
58
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/malloc.h>
62 #include <sys/kernel.h>
63 #include <sys/module.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 <bus/cam/cam.h>
71 #include <bus/cam/cam_ccb.h>
72 #include <bus/cam/cam_sim.h>
73 #include <bus/cam/cam_xpt.h>
74 #include <bus/cam/cam_xpt_sim.h>
75 #include <bus/cam/cam_debug.h>
76 #include <bus/cam/scsi/scsi_all.h>
77 #include <bus/cam/scsi/scsi_message.h>
78
79 #include <dev/raid/amr/amrreg.h>
80 #include <dev/raid/amr/amrvar.h>
81
82 static int      amr_cam_probe(device_t dev);
83 static int      amr_cam_attach(device_t dev);
84 static int      amr_cam_detach(device_t dev);
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 int      amr_cam_command(struct amr_softc *sc, struct amr_command **acp);
89
90 static devclass_t       amr_pass_devclass;
91
92 static device_method_t  amr_pass_methods[] = {
93         DEVMETHOD(device_probe,         amr_cam_probe),
94         DEVMETHOD(device_attach,        amr_cam_attach),
95         DEVMETHOD(device_detach,        amr_cam_detach),
96         { 0, 0 }
97 };
98
99 static driver_t amr_pass_driver = {
100         "amrp",
101         amr_pass_methods,
102         0
103 };
104
105 DRIVER_MODULE(amrp, amr, amr_pass_driver, amr_pass_devclass, NULL, NULL);
106 MODULE_DEPEND(amrp, cam, 1, 1, 1);
107
108 MALLOC_DEFINE(M_AMRCAM, "amrcam", "AMR CAM memory");
109
110 /***********************************************************************
111  * Enqueue/dequeue functions
112  */
113 static __inline void
114 amr_enqueue_ccb(struct amr_softc *sc, union ccb *ccb)
115 {
116
117         TAILQ_INSERT_TAIL(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
118 }
119
120 static __inline void
121 amr_requeue_ccb(struct amr_softc *sc, union ccb *ccb)
122 {
123
124         TAILQ_INSERT_HEAD(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
125 }
126
127 static __inline union ccb *
128 amr_dequeue_ccb(struct amr_softc *sc)
129 {
130         union ccb       *ccb;
131
132         if ((ccb = (union ccb *)TAILQ_FIRST(&sc->amr_cam_ccbq)) != NULL)
133                 TAILQ_REMOVE(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
134         return(ccb);
135 }
136
137 static int
138 amr_cam_probe(device_t dev)
139 {
140         return (0);
141 }
142
143 /********************************************************************************
144  * Attach our 'real' SCSI channels to CAM
145  */
146 static int
147 amr_cam_attach(device_t dev)
148 {
149         struct amr_softc *sc;
150         struct cam_devq *devq;
151         int chn, error;
152
153         sc = device_get_softc(dev);
154
155         /* initialise the ccb queue */
156         TAILQ_INIT(&sc->amr_cam_ccbq);
157
158         /*
159          * Allocate a devq for all our channels combined.  This should
160          * allow for the maximum number of SCSI commands we will accept
161          * at one time. Save the pointer in the softc so we can find it later
162          * during detach.
163          */
164         if ((devq = cam_simq_alloc(AMR_MAX_SCSI_CMDS)) == NULL)
165                 return(ENOMEM);
166         sc->amr_cam_devq = devq;
167
168         /*
169          * Iterate over our channels, registering them with CAM
170          */
171         for (chn = 0; chn < sc->amr_maxchan; chn++) {
172
173                 /* allocate a sim */
174                 if ((sc->amr_cam_sim[chn] = cam_sim_alloc(amr_cam_action,
175                     amr_cam_poll, "amr", sc, device_get_unit(sc->amr_dev),
176                     &sc->amr_list_lock, 1, AMR_MAX_SCSI_CMDS, devq)) == NULL) {
177                         cam_simq_release(devq);
178                         device_printf(sc->amr_dev, "CAM SIM attach failed\n");
179                         return(ENOMEM);
180                 }
181
182                 /* register the bus ID so we can get it later */
183                 lockmgr(&sc->amr_list_lock, LK_EXCLUSIVE);
184                 error = xpt_bus_register(sc->amr_cam_sim[chn], chn);
185                 lockmgr(&sc->amr_list_lock, LK_RELEASE);
186                 if (error) {
187                         device_printf(sc->amr_dev,
188                             "CAM XPT bus registration failed\n");
189                         return(ENXIO);
190                 }
191         }
192         /*
193          * XXX we should scan the config and work out which devices are
194          * actually protected.
195          */
196         sc->amr_cam_command = amr_cam_command;
197         return(0);
198 }
199
200 /********************************************************************************
201  * Disconnect ourselves from CAM
202  */
203 static int
204 amr_cam_detach(device_t dev)
205 {
206         struct amr_softc *sc;
207         int             chn;
208
209         sc = device_get_softc(dev);
210         lockmgr(&sc->amr_list_lock, LK_EXCLUSIVE);
211         for (chn = 0; chn < sc->amr_maxchan; chn++) {
212                 /*
213                  * If a sim was allocated for this channel, free it
214                  */
215                 if (sc->amr_cam_sim[chn] != NULL) {
216                         xpt_bus_deregister(cam_sim_path(sc->amr_cam_sim[chn]));
217                         cam_sim_free(sc->amr_cam_sim[chn]);
218                 }
219         }
220         lockmgr(&sc->amr_list_lock, LK_RELEASE);
221
222         /* Now free the devq */
223         if (sc->amr_cam_devq != NULL)
224                 cam_simq_release(sc->amr_cam_devq);
225
226         return (0);
227 }
228
229 /***********************************************************************
230  ***********************************************************************
231                         CAM passthrough interface
232  ***********************************************************************
233  ***********************************************************************/
234
235 /***********************************************************************
236  * Handle a request for action from CAM
237  */
238 static void
239 amr_cam_action(struct cam_sim *sim, union ccb *ccb)
240 {
241         struct amr_softc        *sc = cam_sim_softc(sim);
242
243         switch(ccb->ccb_h.func_code) {
244
245         /*
246          * Perform SCSI I/O to a physical device.
247          */
248         case XPT_SCSI_IO:
249         {
250                 struct ccb_hdr          *ccbh = &ccb->ccb_h;
251                 struct ccb_scsiio       *csio = &ccb->csio;
252
253                 /* Validate the CCB */
254                 ccbh->status = CAM_REQ_INPROG;
255
256                 /* check the CDB length */
257                 if (csio->cdb_len > AMR_MAX_EXTCDB_LEN)
258                         ccbh->status = CAM_REQ_INVALID;
259
260                 if ((csio->cdb_len > AMR_MAX_CDB_LEN) &&
261                     (sc->support_ext_cdb == 0))
262                         ccbh->status = CAM_REQ_INVALID;
263
264                 /* check that the CDB pointer is not to a physical address */
265                 if ((ccbh->flags & CAM_CDB_POINTER) &&
266                     (ccbh->flags & CAM_CDB_PHYS))
267                         ccbh->status = CAM_REQ_INVALID;
268                 /*
269                  * if there is data transfer, it must be to/from a virtual
270                  * address
271                  */
272                 if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
273                         if (ccbh->flags & CAM_DATA_PHYS)
274                                 /* we can't map it */
275                                 ccbh->status = CAM_REQ_INVALID;
276                         if (ccbh->flags & CAM_SCATTER_VALID)
277                                 /* we want to do the s/g setup */
278                                 ccbh->status = CAM_REQ_INVALID;
279                 }
280
281                 /*
282                  * If the command is to a LUN other than 0, fail it.
283                  * This is probably incorrect, but during testing the
284                  * firmware did not seem to respect the LUN field, and thus
285                  * devices appear echoed.
286                  */
287                 if (csio->ccb_h.target_lun != 0)
288                         ccbh->status = CAM_DEV_NOT_THERE;
289
290                 /* if we're happy with the request, queue it for attention */
291                 if (ccbh->status == CAM_REQ_INPROG) {
292
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                 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
326                 strncpy(cpi->hba_vid, "LSI", HBA_IDLEN);
327                 strncpy(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         /*
399          * Reject anything else as unsupported.
400          */
401         default:
402                 /* we can't do this */
403                 ccb->ccb_h.status = CAM_REQ_INVALID;
404                 break;
405         }
406
407         KKASSERT(lockstatus(&sc->amr_list_lock, curthread) != 0);
408         xpt_done(ccb);
409 }
410
411 /***********************************************************************
412  * Convert a CAM CCB off the top of the CCB queue to a passthrough SCSI
413  * command.
414  */
415 static int
416 amr_cam_command(struct amr_softc *sc, struct amr_command **acp)
417 {
418         struct amr_command              *ac;
419         struct amr_passthrough          *ap;
420         struct amr_ext_passthrough      *aep;
421         struct ccb_scsiio               *csio;
422         int                             bus, target, error;
423
424         error = 0;
425         ac = NULL;
426         ap = NULL;
427         aep = NULL;
428
429         /* check to see if there is a ccb for us to work with */
430         if ((csio = (struct ccb_scsiio *)amr_dequeue_ccb(sc)) == NULL)
431                 goto out;
432
433         /* get bus/target, XXX validate against protected devices? */
434         bus = csio->ccb_h.sim_priv.entries[0].field;
435         target = csio->ccb_h.target_id;
436
437         /*
438          * Build a passthrough command.
439          */
440
441         /* construct command */
442         if ((ac = amr_alloccmd(sc)) == NULL) {
443                 error = ENOMEM;
444                 goto out;
445         }
446
447         /* construct passthrough */
448         if (sc->support_ext_cdb ) {
449                 aep = &ac->ac_ccb->ccb_epthru;
450                 aep->ap_timeout = 2;
451                 aep->ap_ars = 1;
452                 aep->ap_request_sense_length = 14;
453                 aep->ap_islogical = 0;
454                 aep->ap_channel = bus;
455                 aep->ap_scsi_id = target;
456                 aep->ap_logical_drive_no = csio->ccb_h.target_lun;
457                 aep->ap_cdb_length = csio->cdb_len;
458                 aep->ap_data_transfer_length = csio->dxfer_len;
459                 if (csio->ccb_h.flags & CAM_CDB_POINTER) {
460                         bcopy(csio->cdb_io.cdb_ptr, aep->ap_cdb, csio->cdb_len);
461                 } else {
462                         bcopy(csio->cdb_io.cdb_bytes, aep->ap_cdb,
463                             csio->cdb_len);
464                 }
465                 /*
466                  * we leave the data s/g list and s/g count to the map routine
467                  * later
468                  */
469
470                 debug(2, " COMMAND %x/%d+%d to %d:%d:%d", aep->ap_cdb[0],
471                     aep->ap_cdb_length, csio->dxfer_len, aep->ap_channel,
472                     aep->ap_scsi_id, aep->ap_logical_drive_no);
473
474         } else {
475                 ap = &ac->ac_ccb->ccb_pthru;
476                 ap->ap_timeout = 0;
477                 ap->ap_ars = 1;
478                 ap->ap_request_sense_length = 14;
479                 ap->ap_islogical = 0;
480                 ap->ap_channel = bus;
481                 ap->ap_scsi_id = target;
482                 ap->ap_logical_drive_no = csio->ccb_h.target_lun;
483                 ap->ap_cdb_length = csio->cdb_len;
484                 ap->ap_data_transfer_length = csio->dxfer_len;
485                 if (csio->ccb_h.flags & CAM_CDB_POINTER) {
486                         bcopy(csio->cdb_io.cdb_ptr, ap->ap_cdb, csio->cdb_len);
487                 } else {
488                         bcopy(csio->cdb_io.cdb_bytes, ap->ap_cdb,
489                             csio->cdb_len);
490                 }
491                 /*
492                  * we leave the data s/g list and s/g count to the map routine
493                  * later
494                  */
495
496                 debug(2, " COMMAND %x/%d+%d to %d:%d:%d", ap->ap_cdb[0],
497                     ap->ap_cdb_length, csio->dxfer_len, ap->ap_channel,
498                     ap->ap_scsi_id, ap->ap_logical_drive_no);
499         }
500
501         ac->ac_flags |= AMR_CMD_CCB;
502
503         ac->ac_data = csio->data_ptr;
504         ac->ac_length = csio->dxfer_len;
505         if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
506                 ac->ac_flags |= AMR_CMD_DATAIN;
507         if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
508                 ac->ac_flags |= AMR_CMD_DATAOUT;
509
510         ac->ac_private = csio;
511         ac->ac_complete = amr_cam_complete;
512         if ( sc->support_ext_cdb ) {
513                 ac->ac_mailbox.mb_command = AMR_CMD_EXTPASS;
514         } else {
515                 ac->ac_mailbox.mb_command = AMR_CMD_PASS;
516         }
517
518 out:
519         if (error != 0) {
520                 if (ac != NULL)
521                         amr_releasecmd(ac);
522                 if (csio != NULL)
523                         /* put it back and try again later */
524                         amr_requeue_ccb(sc, (union ccb *)csio);
525         }
526         *acp = ac;
527         return(error);
528 }
529
530 /***********************************************************************
531  * Check for interrupt status
532  */
533 static void
534 amr_cam_poll(struct cam_sim *sim)
535 {
536
537         amr_done(cam_sim_softc(sim));
538 }
539
540  /**********************************************************************
541  * Handle completion of a command submitted via CAM.
542  */
543 static void
544 amr_cam_complete(struct amr_command *ac)
545 {
546         struct amr_passthrough          *ap;
547         struct amr_ext_passthrough      *aep;
548         struct ccb_scsiio               *csio;
549         struct scsi_inquiry_data        *inq;
550         int                             scsi_status, cdb0;
551
552         ap = &ac->ac_ccb->ccb_pthru;
553         aep = &ac->ac_ccb->ccb_epthru;
554         csio = (struct ccb_scsiio *)ac->ac_private;
555         inq = (struct scsi_inquiry_data *)csio->data_ptr;
556
557         if (ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS)
558                 scsi_status = aep->ap_scsi_status;
559         else
560                 scsi_status = ap->ap_scsi_status;
561         debug(1, "status 0x%x  AP scsi_status 0x%x", ac->ac_status,
562             scsi_status);
563
564         /* Make sure the status is sane */
565         if ((ac->ac_status != AMR_STATUS_SUCCESS) && (scsi_status == 0)) {
566                 csio->ccb_h.status = CAM_REQ_CMP_ERR;
567                 goto out;
568         }
569
570         /*
571          * Hide disks from CAM so that they're not picked up and treated as
572          * 'normal' disks.
573          *
574          * If the configuration provides a mechanism to mark a disk a "not
575          * managed", we could add handling for that to allow disks to be
576          * selectively visible.
577          */
578
579         /* handle passthrough SCSI status */
580         switch(scsi_status) {
581         case 0: /* completed OK */
582                 if (ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS)
583                         cdb0 = aep->ap_cdb[0];
584                 else
585                         cdb0 = ap->ap_cdb[0];
586                 if ((cdb0 == INQUIRY) && (SID_TYPE(inq) == T_DIRECT))
587                         inq->device = (inq->device & 0xe0) | T_NODEVICE;
588                 csio->ccb_h.status = CAM_REQ_CMP;
589                 break;
590
591         case 0x02:
592                 csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
593                 csio->scsi_status = SCSI_STATUS_CHECK_COND;
594                 if (ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS)
595                         bcopy(aep->ap_request_sense_area, &csio->sense_data,
596                             AMR_MAX_REQ_SENSE_LEN);
597                 else
598                         bcopy(ap->ap_request_sense_area, &csio->sense_data,
599                             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                 /*
612                  * Non-zero LUNs are already filtered, so there's no need
613                  * to return CAM_DEV_NOT_THERE.
614                  */
615                 csio->ccb_h.status = CAM_SEL_TIMEOUT;
616                 break;
617         }
618
619 out:
620         if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE)
621                 debug(2, "%*D\n", imin(csio->dxfer_len, 16), csio->data_ptr,
622                     " ");
623
624         lockmgr(&ac->ac_sc->amr_list_lock, LK_EXCLUSIVE);
625         xpt_done((union ccb *)csio);
626         amr_releasecmd(ac);
627         lockmgr(&ac->ac_sc->amr_list_lock, LK_RELEASE);
628 }