2 * Copyright (c) 2004-07 Applied Micro Circuits Corporation.
3 * Copyright (c) 2004-05 Vinod Kashyap.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
27 * $FreeBSD: src/sys/dev/twa/tw_osl_cam.c,v 1.14 2010/06/09 21:40:38 delphij Exp $
31 * AMCC'S 3ware driver for 9000 series storage controllers.
33 * Author: Vinod Kashyap
34 * Modifications by: Adam Radford
35 * Modifications by: Manjunath Ranganathaiah
40 * FreeBSD CAM related functions.
44 #include <dev/raid/twa/tw_osl_includes.h>
46 #include <bus/cam/cam.h>
47 #include <bus/cam/cam_ccb.h>
48 #include <bus/cam/cam_sim.h>
49 #include <bus/cam/cam_xpt_sim.h>
50 #include <bus/cam/cam_debug.h>
51 #include <bus/cam/cam_periph.h>
52 #include <bus/cam/cam_xpt_periph.h>
54 #include <bus/cam/scsi/scsi_all.h>
55 #include <bus/cam/scsi/scsi_message.h>
57 static TW_VOID twa_action(struct cam_sim *sim, union ccb *ccb);
58 static TW_VOID twa_poll(struct cam_sim *sim);
59 static TW_VOID twa_timeout(TW_VOID *arg);
60 static TW_VOID twa_bus_scan_cb(struct cam_periph *periph, union ccb *ccb);
62 static TW_INT32 tw_osli_execute_scsi(struct tw_osli_req_context *req,
68 * Function name: tw_osli_cam_attach
69 * Description: Attaches the driver to CAM.
71 * Input: sc -- ptr to OSL internal ctlr context
73 * Return value: 0 -- success
77 tw_osli_cam_attach(struct twa_softc *sc)
79 struct cam_devq *devq;
81 tw_osli_dbg_dprintf(3, sc, "entered");
84 * Create the device queue for our SIM.
86 if ((devq = cam_simq_alloc(TW_OSLI_MAX_NUM_REQUESTS)) == NULL) {
87 tw_osli_printf(sc, "error = %d",
88 TW_CL_SEVERITY_ERROR_STRING,
89 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
91 "Failed to create SIM device queue",
97 * Create a SIM entry. Though we can support TW_OSLI_MAX_NUM_REQUESTS
98 * simultaneous requests, we claim to be able to handle only
99 * TW_OSLI_MAX_NUM_IOS (two less), so that we always have a request
100 * packet available to service ioctls and AENs.
102 tw_osli_dbg_dprintf(3, sc, "Calling cam_sim_alloc");
103 sc->sim = cam_sim_alloc(twa_action, twa_poll, "twa", sc,
104 device_get_unit(sc->bus_dev), sc->sim_lock,
105 TW_OSLI_MAX_NUM_IOS, 1, devq);
106 if (sc->sim == NULL) {
107 tw_osli_printf(sc, "error = %d",
108 TW_CL_SEVERITY_ERROR_STRING,
109 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
111 "Failed to create a SIM entry",
119 tw_osli_dbg_dprintf(3, sc, "Calling xpt_bus_register");
120 lockmgr(sc->sim_lock, LK_EXCLUSIVE);
121 if (xpt_bus_register(sc->sim, 0) != CAM_SUCCESS) {
122 cam_sim_free(sc->sim);
123 sc->sim = NULL; /* so cam_detach will not try to free it */
124 tw_osli_printf(sc, "error = %d",
125 TW_CL_SEVERITY_ERROR_STRING,
126 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
128 "Failed to register the bus",
130 lockmgr(sc->sim_lock, LK_RELEASE);
134 tw_osli_dbg_dprintf(3, sc, "Calling xpt_create_path");
135 if (xpt_create_path(&sc->path, NULL,
136 cam_sim_path(sc->sim),
138 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
139 xpt_bus_deregister(cam_sim_path (sc->sim));
140 /* Passing TRUE to cam_sim_free will free the devq as well. */
141 cam_sim_free(sc->sim);
142 tw_osli_printf(sc, "error = %d",
143 TW_CL_SEVERITY_ERROR_STRING,
144 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
146 "Failed to create path",
148 lockmgr(sc->sim_lock, LK_RELEASE);
151 lockmgr(sc->sim_lock, LK_RELEASE);
153 tw_osli_dbg_dprintf(3, sc, "exiting");
160 * Function name: tw_osli_cam_detach
161 * Description: Detaches the driver from CAM.
163 * Input: sc -- ptr to OSL internal ctlr context
168 tw_osli_cam_detach(struct twa_softc *sc)
170 tw_osli_dbg_dprintf(3, sc, "entered");
172 lockmgr(sc->sim_lock, LK_EXCLUSIVE);
175 xpt_free_path(sc->path);
177 xpt_bus_deregister(cam_sim_path(sc->sim));
178 /* Passing TRUE to cam_sim_free will free the devq as well. */
179 cam_sim_free(sc->sim);
181 /* It's ok have 1 hold count while destroying the mutex */
182 lockuninit(sc->sim_lock);
188 * Function name: tw_osli_execute_scsi
189 * Description: Build a fw cmd, based on a CAM style ccb, and
192 * Input: req -- ptr to OSL internal request context
193 * ccb -- ptr to CAM style ccb
195 * Return value: 0 -- success
199 tw_osli_execute_scsi(struct tw_osli_req_context *req, union ccb *ccb)
201 struct twa_softc *sc = req->ctlr;
202 struct tw_cl_req_packet *req_pkt;
203 struct tw_cl_scsi_req_packet *scsi_req;
204 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
205 struct ccb_scsiio *csio = &(ccb->csio);
208 tw_osli_dbg_dprintf(10, sc, "SCSI I/O request 0x%x",
209 csio->cdb_io.cdb_bytes[0]);
211 if (ccb_h->target_id >= TW_CL_MAX_NUM_UNITS) {
212 tw_osli_dbg_dprintf(3, sc, "Invalid target. PTL = %x %x %x",
213 ccb_h->path_id, ccb_h->target_id, ccb_h->target_lun);
214 ccb_h->status |= CAM_TID_INVALID;
218 if (ccb_h->target_lun >= TW_CL_MAX_NUM_LUNS) {
219 tw_osli_dbg_dprintf(3, sc, "Invalid lun. PTL = %x %x %x",
220 ccb_h->path_id, ccb_h->target_id, ccb_h->target_lun);
221 ccb_h->status |= CAM_LUN_INVALID;
226 if(ccb_h->flags & CAM_CDB_PHYS) {
227 tw_osli_printf(sc, "",
228 TW_CL_SEVERITY_ERROR_STRING,
229 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
231 "Physical CDB address!");
232 ccb_h->status = CAM_REQ_INVALID;
238 * We are going to work on this request. Mark it as enqueued (though
239 * we don't actually queue it...)
241 ccb_h->status |= CAM_SIM_QUEUED;
243 if((ccb_h->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
244 if(ccb_h->flags & CAM_DIR_IN)
245 req->flags |= TW_OSLI_REQ_FLAGS_DATA_IN;
247 req->flags |= TW_OSLI_REQ_FLAGS_DATA_OUT;
250 /* Build the CL understood request packet for SCSI cmds. */
251 req_pkt = &req->req_pkt;
253 req_pkt->tw_osl_callback = tw_osl_complete_io;
254 scsi_req = &(req_pkt->gen_req_pkt.scsi_req);
255 scsi_req->unit = ccb_h->target_id;
256 scsi_req->lun = ccb_h->target_lun;
257 scsi_req->sense_len = 0;
258 scsi_req->sense_data = (TW_UINT8 *)(&csio->sense_data);
259 scsi_req->scsi_status = 0;
260 if(ccb_h->flags & CAM_CDB_POINTER)
261 scsi_req->cdb = csio->cdb_io.cdb_ptr;
263 scsi_req->cdb = csio->cdb_io.cdb_bytes;
264 scsi_req->cdb_len = csio->cdb_len;
266 if (!(ccb_h->flags & CAM_DATA_PHYS)) {
267 /* Virtual data addresses. Need to convert them... */
268 tw_osli_dbg_dprintf(3, sc,
269 "XPT_SCSI_IO: Single virtual address!");
270 if (!(ccb_h->flags & CAM_SCATTER_VALID)) {
271 if (csio->dxfer_len > TW_CL_MAX_IO_SIZE) {
272 tw_osli_printf(sc, "size = %d",
273 TW_CL_SEVERITY_ERROR_STRING,
274 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
278 ccb_h->status = CAM_REQ_TOO_BIG;
283 if ((req->length = csio->dxfer_len)) {
284 req->data = csio->data_ptr;
285 scsi_req->sgl_entries = 1;
288 tw_osli_printf(sc, "",
289 TW_CL_SEVERITY_ERROR_STRING,
290 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
292 "XPT_SCSI_IO: Got SGList");
293 ccb_h->status = CAM_REQ_INVALID;
298 /* Data addresses are physical. */
299 tw_osli_printf(sc, "",
300 TW_CL_SEVERITY_ERROR_STRING,
301 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
303 "XPT_SCSI_IO: Physical data addresses");
304 ccb_h->status = CAM_REQ_INVALID;
305 ccb_h->status &= ~CAM_SIM_QUEUED;
310 callout_reset(&ccb->ccb_h.timeout_ch,
311 (ccb_h->timeout * hz) / 1000, twa_timeout, req);
313 * twa_map_load_data_callback will fill in the SGL,
314 * and submit the I/O.
316 error = tw_osli_map_request(req);
323 * Function name: twa_action
324 * Description: Driver entry point for CAM's use.
326 * Input: sim -- sim corresponding to the ctlr
327 * ccb -- ptr to CAM request
332 twa_action(struct cam_sim *sim, union ccb *ccb)
334 struct twa_softc *sc = (struct twa_softc *)cam_sim_softc(sim);
335 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
337 switch (ccb_h->func_code) {
338 case XPT_SCSI_IO: /* SCSI I/O */
340 struct tw_osli_req_context *req;
342 req = tw_osli_get_request(sc);
344 tw_osli_dbg_dprintf(2, sc, "Cannot get request pkt.");
346 * Freeze the simq to maintain ccb ordering. The next
347 * ccb that gets completed will unfreeze the simq.
349 ccb_h->status |= CAM_REQUEUE_REQ;
353 req->req_handle.osl_req_ctxt = req;
354 req->req_handle.is_io = TW_CL_TRUE;
356 if (tw_osli_execute_scsi(req, ccb))
357 tw_osli_req_q_insert_tail(req, TW_OSLI_FREE_Q);
362 tw_osli_dbg_dprintf(2, sc, "Abort request.");
363 ccb_h->status = CAM_UA_ABORT;
368 tw_cl_create_event(&(sc->ctlr_handle), TW_CL_TRUE,
369 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
370 0x2108, 0x3, TW_CL_SEVERITY_INFO_STRING,
371 "Received Reset Bus request from CAM",
374 lockmgr(sc->sim_lock, LK_RELEASE);
375 if (tw_cl_reset_ctlr(&sc->ctlr_handle)) {
376 tw_cl_create_event(&(sc->ctlr_handle), TW_CL_TRUE,
377 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
378 0x2109, 0x1, TW_CL_SEVERITY_ERROR_STRING,
379 "Failed to reset bus",
381 ccb_h->status = CAM_REQ_CMP_ERR;
384 ccb_h->status = CAM_REQ_CMP;
386 lockmgr(sc->sim_lock, LK_EXCLUSIVE);
390 case XPT_SET_TRAN_SETTINGS:
391 tw_osli_dbg_dprintf(3, sc, "XPT_SET_TRAN_SETTINGS");
394 * This command is not supported, since it's very specific
395 * to SCSI, and we are doing ATA.
397 ccb_h->status = CAM_FUNC_NOTAVAIL;
401 case XPT_GET_TRAN_SETTINGS:
403 struct ccb_trans_settings *cts = &ccb->cts;
404 struct ccb_trans_settings_scsi *scsi =
405 &cts->proto_specific.scsi;
406 struct ccb_trans_settings_spi *spi =
407 &cts->xport_specific.spi;
409 cts->protocol = PROTO_SCSI;
410 cts->protocol_version = SCSI_REV_2;
411 cts->transport = XPORT_SPI;
412 cts->transport_version = 2;
414 spi->valid = CTS_SPI_VALID_DISC;
415 spi->flags = CTS_SPI_FLAGS_DISC_ENB;
416 scsi->valid = CTS_SCSI_VALID_TQ;
417 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
418 tw_osli_dbg_dprintf(3, sc, "XPT_GET_TRAN_SETTINGS");
419 ccb_h->status = CAM_REQ_CMP;
424 case XPT_CALC_GEOMETRY:
425 tw_osli_dbg_dprintf(3, sc, "XPT_CALC_GEOMETRY");
426 cam_calc_geometry(&ccb->ccg, 1/* extended */);
430 case XPT_PATH_INQ: /* Path inquiry -- get twa properties */
432 struct ccb_pathinq *path_inq = &ccb->cpi;
434 tw_osli_dbg_dprintf(3, sc, "XPT_PATH_INQ request");
436 path_inq->version_num = 1;
437 path_inq->hba_inquiry = 0;
438 path_inq->target_sprt = 0;
439 path_inq->hba_misc = 0;
440 path_inq->hba_eng_cnt = 0;
441 path_inq->max_target = TW_CL_MAX_NUM_UNITS;
442 path_inq->max_lun = TW_CL_MAX_NUM_LUNS - 1;
443 path_inq->unit_number = cam_sim_unit(sim);
444 path_inq->bus_id = cam_sim_bus(sim);
445 path_inq->initiator_id = TW_CL_MAX_NUM_UNITS;
446 path_inq->base_transfer_speed = 100000;
447 strncpy(path_inq->sim_vid, "FreeBSD", SIM_IDLEN);
448 strncpy(path_inq->hba_vid, "3ware", HBA_IDLEN);
449 strncpy(path_inq->dev_name, cam_sim_name(sim), DEV_IDLEN);
450 path_inq->transport = XPORT_SPI;
451 path_inq->transport_version = 2;
452 path_inq->protocol = PROTO_SCSI;
453 path_inq->protocol_version = SCSI_REV_2;
454 ccb_h->status = CAM_REQ_CMP;
460 tw_osli_dbg_dprintf(3, sc, "func_code = %x", ccb_h->func_code);
461 ccb_h->status = CAM_REQ_INVALID;
470 * Function name: twa_poll
471 * Description: Driver entry point called when interrupts are not
474 * Input: sim -- sim corresponding to the controller
479 twa_poll(struct cam_sim *sim)
481 struct twa_softc *sc = (struct twa_softc *)(cam_sim_softc(sim));
483 tw_osli_dbg_dprintf(3, sc, "entering; sc = %p", sc);
484 tw_cl_interrupt(&(sc->ctlr_handle));
485 tw_osli_dbg_dprintf(3, sc, "exiting; sc = %p", sc);
491 * Function name: twa_timeout
492 * Description: Driver entry point for being alerted on a request
495 * Input: arg -- ptr to timed out request
500 twa_timeout(TW_VOID *arg)
502 struct tw_osli_req_context *req =
503 (struct tw_osli_req_context *)arg;
505 tw_cl_create_event(&(req->ctlr->ctlr_handle), TW_CL_TRUE,
506 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
507 0x210B, 0x1, TW_CL_SEVERITY_ERROR_STRING,
508 "Request timed out!",
509 "request = %p", req);
510 tw_cl_reset_ctlr(&(req->ctlr->ctlr_handle));
516 * Function name: tw_osli_request_bus_scan
517 * Description: Requests CAM for a scan of the bus.
519 * Input: sc -- ptr to per ctlr structure
521 * Return value: 0 -- success
525 tw_osli_request_bus_scan(struct twa_softc *sc)
529 tw_osli_dbg_dprintf(3, sc, "entering");
531 /* If we get here before sc->sim is initialized, return an error. */
534 if ((ccb = xpt_alloc_ccb()) == NULL)
536 lockmgr(sc->sim_lock, LK_EXCLUSIVE);
537 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(sc->sim),
538 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
540 lockmgr(sc->sim_lock, LK_RELEASE);
544 xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, 5/*priority (low)*/);
545 ccb->ccb_h.func_code = XPT_SCAN_BUS;
546 ccb->ccb_h.cbfcnp = twa_bus_scan_cb;
547 ccb->crcn.flags = CAM_FLAG_NONE;
550 lockmgr(sc->sim_lock, LK_RELEASE);
557 * Function name: twa_bus_scan_cb
558 * Description: Callback from CAM on a bus scan request.
560 * Input: periph -- we don't use this
561 * ccb -- bus scan request ccb that we sent to CAM
566 twa_bus_scan_cb(struct cam_periph *periph, union ccb *ccb)
568 tw_osli_dbg_printf(3, "entering");
570 if (ccb->ccb_h.status != CAM_REQ_CMP)
571 kprintf("cam_scan_callback: failure status = %x\n",
574 tw_osli_dbg_printf(3, "success");
576 xpt_free_path(ccb->ccb_h.path);
583 * Function name: tw_osli_disallow_new_requests
584 * Description: Calls the appropriate CAM function, so as to freeze
585 * the flow of new requests from CAM to this controller.
587 * Input: sc -- ptr to OSL internal ctlr context
588 * req_handle -- ptr to request handle sent by OSL.
593 tw_osli_disallow_new_requests(struct twa_softc *sc,
594 struct tw_cl_req_handle *req_handle)
596 /* Only freeze/release the simq for IOs */
597 if (req_handle->is_io) {
598 struct tw_osli_req_context *req = req_handle->osl_req_ctxt;
599 union ccb *ccb = (union ccb *)(req->orig_req);
601 xpt_freeze_simq(sc->sim, 1);
602 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
609 * Function name: tw_osl_ctlr_busy
610 * Description: CL calls this function on cmd queue full or otherwise,
611 * when it is too busy to accept new requests.
613 * Input: ctlr_handle -- ptr to controller handle
614 * req_handle -- ptr to request handle sent by OSL.
619 tw_osl_ctlr_busy(struct tw_cl_ctlr_handle *ctlr_handle,
620 struct tw_cl_req_handle *req_handle)
622 tw_osli_disallow_new_requests(ctlr_handle->osl_ctlr_ctxt, req_handle);
628 * Function name: tw_osl_scan_bus
629 * Description: CL calls this function to request for a bus scan.
631 * Input: ctlr_handle -- ptr to controller handle
636 tw_osl_scan_bus(struct tw_cl_ctlr_handle *ctlr_handle)
638 struct twa_softc *sc = ctlr_handle->osl_ctlr_ctxt;
641 if ((error = tw_osli_request_bus_scan(sc)))
642 tw_osli_printf(sc, "error = %d",
643 TW_CL_SEVERITY_ERROR_STRING,
644 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
646 "Bus scan request to CAM failed",
653 * Function name: tw_osl_complete_io
654 * Description: Called to complete CAM scsi requests.
656 * Input: req_handle -- ptr to request handle
661 tw_osl_complete_io(struct tw_cl_req_handle *req_handle)
663 struct tw_osli_req_context *req = req_handle->osl_req_ctxt;
664 struct tw_cl_req_packet *req_pkt =
665 (struct tw_cl_req_packet *)(&req->req_pkt);
666 struct tw_cl_scsi_req_packet *scsi_req;
667 struct twa_softc *sc = req->ctlr;
668 union ccb *ccb = (union ccb *)(req->orig_req);
670 tw_osli_dbg_dprintf(10, sc, "entering");
672 if (req->state != TW_OSLI_REQ_STATE_BUSY)
673 tw_osli_printf(sc, "request = %p, status = %d",
674 TW_CL_SEVERITY_ERROR_STRING,
675 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
677 "Unposted command completed!!",
681 * Remove request from the busy queue. Just mark it complete.
682 * There's no need to move it into the complete queue as we are
683 * going to be done with it right now.
685 req->state = TW_OSLI_REQ_STATE_COMPLETE;
686 tw_osli_req_q_remove_item(req, TW_OSLI_BUSY_Q);
688 tw_osli_unmap_request(req);
690 callout_stop(&ccb->ccb_h.timeout_ch);
691 if (req->error_code) {
692 /* This request never got submitted to the firmware. */
693 if (req->error_code == EBUSY) {
695 * Cmd queue is full, or the Common Layer is out of
696 * resources. The simq will already have been frozen.
697 * When this ccb gets completed will unfreeze the simq.
699 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
701 else if (req->error_code == EFBIG)
702 ccb->ccb_h.status = CAM_REQ_TOO_BIG;
704 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
706 scsi_req = &(req_pkt->gen_req_pkt.scsi_req);
707 if (req_pkt->status == TW_CL_ERR_REQ_SUCCESS)
708 ccb->ccb_h.status = CAM_REQ_CMP;
710 if (req_pkt->status & TW_CL_ERR_REQ_INVALID_TARGET)
711 ccb->ccb_h.status |= CAM_TID_INVALID;
712 else if (req_pkt->status & TW_CL_ERR_REQ_INVALID_LUN)
713 ccb->ccb_h.status |= CAM_LUN_INVALID;
714 else if (req_pkt->status & TW_CL_ERR_REQ_SCSI_ERROR)
715 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
716 else if (req_pkt->status & TW_CL_ERR_REQ_BUS_RESET)
717 ccb->ccb_h.status |= CAM_SCSI_BUS_RESET;
719 * If none of the above errors occurred, simply
720 * mark completion error.
722 if (ccb->ccb_h.status == 0)
723 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
725 if (req_pkt->status & TW_CL_ERR_REQ_AUTO_SENSE_VALID) {
726 ccb->csio.sense_len = scsi_req->sense_len;
727 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
731 ccb->csio.scsi_status = scsi_req->scsi_status;
734 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
735 lockmgr(sc->sim_lock, LK_EXCLUSIVE);
737 lockmgr(sc->sim_lock, LK_RELEASE);
738 if (! req->error_code)
739 /* twa_action will free the request otherwise */
740 tw_osli_req_q_insert_tail(req, TW_OSLI_FREE_Q);