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