2 * Copyright (c) 2004-05 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
31 * AMCC'S 3ware driver for 9000 series storage controllers.
33 * Author: Vinod Kashyap
38 * FreeBSD CAM related functions.
42 #include <dev/twa/tw_osl_includes.h>
45 #include <cam/cam_ccb.h>
46 #include <cam/cam_sim.h>
47 #include <cam/cam_xpt_sim.h>
48 #include <cam/cam_xpt_periph.h>
49 #include <cam/cam_debug.h>
50 #include <cam/cam_periph.h>
52 #include <cam/scsi/scsi_all.h>
53 #include <cam/scsi/scsi_message.h>
55 static TW_VOID twa_action(struct cam_sim *sim, union ccb *ccb);
56 static TW_VOID twa_poll(struct cam_sim *sim);
57 static TW_VOID twa_async(TW_VOID *callback_arg, TW_UINT32 code,
58 struct cam_path *path, TW_VOID *arg);
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;
80 struct ccb_setasync csa;
83 tw_osli_dbg_dprintf(3, sc, "entered");
86 * Create the device queue for our SIM.
88 if ((devq = cam_simq_alloc(TW_OSLI_MAX_NUM_IOS)) == NULL) {
89 tw_osli_printf(sc, "error = %d",
90 TW_CL_SEVERITY_ERROR_STRING,
91 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
93 "Failed to create SIM device queue",
99 * Create a SIM entry. Though we can support TW_OSLI_MAX_NUM_IOS
100 * simultaneous requests, we claim to be able to handle only
101 * (TW_OSLI_MAX_NUM_IOS - 1), so that we always have a request
102 * packet available to service ioctls.
104 tw_osli_dbg_dprintf(3, sc, "Calling cam_sim_alloc");
105 sc->sim = cam_sim_alloc(twa_action, twa_poll, "twa", sc,
106 device_get_unit(sc->bus_dev),
107 TW_OSLI_MAX_NUM_IOS - 1, 1, devq);
108 if (sc->sim == NULL) {
110 tw_osli_printf(sc, "error = %d",
111 TW_CL_SEVERITY_ERROR_STRING,
112 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
114 "Failed to create a SIM entry",
122 tw_osli_dbg_dprintf(3, sc, "Calling xpt_bus_register");
124 if (xpt_bus_register(sc->sim, 0) != CAM_SUCCESS) {
125 cam_sim_free(sc->sim, TRUE);
126 sc->sim = NULL; /* so cam_detach will not try to free it */
127 tw_osli_printf(sc, "error = %d",
128 TW_CL_SEVERITY_ERROR_STRING,
129 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
131 "Failed to register the bus",
136 tw_osli_dbg_dprintf(3, sc, "Calling xpt_create_path");
137 if (xpt_create_path(&sc->path, NULL,
138 cam_sim_path(sc->sim),
140 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
141 xpt_bus_deregister(cam_sim_path (sc->sim));
142 /* Passing TRUE to cam_sim_free will free the devq as well. */
143 cam_sim_free(sc->sim, TRUE);
144 tw_osli_printf(sc, "error = %d",
145 TW_CL_SEVERITY_ERROR_STRING,
146 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
148 "Failed to create path",
153 tw_osli_dbg_dprintf(3, sc, "Calling xpt_setup_ccb");
154 xpt_setup_ccb(&csa.ccb_h, sc->path, 5);
155 csa.ccb_h.func_code = XPT_SASYNC_CB;
156 csa.event_enable = AC_FOUND_DEVICE | AC_LOST_DEVICE;
157 csa.callback = twa_async;
158 csa.callback_arg = sc;
159 xpt_action((union ccb *)&csa);
162 tw_osli_dbg_dprintf(3, sc, "Calling tw_osli_request_bus_scan");
164 * Request a bus scan, so that CAM gets to know of
165 * the logical units that we control.
167 if ((error = tw_osli_request_bus_scan(sc)))
168 tw_osli_printf(sc, "error = %d",
169 TW_CL_SEVERITY_ERROR_STRING,
170 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
172 "Bus scan request to CAM failed",
175 tw_osli_dbg_dprintf(3, sc, "exiting");
182 * Function name: tw_osli_cam_detach
183 * Description: Detaches the driver from CAM.
185 * Input: sc -- ptr to OSL internal ctlr context
190 tw_osli_cam_detach(struct twa_softc *sc)
192 tw_osli_dbg_dprintf(3, sc, "entered");
196 xpt_free_path(sc->path);
198 xpt_bus_deregister(cam_sim_path(sc->sim));
199 /* Passing TRUE to cam_sim_free will free the devq as well. */
200 cam_sim_free(sc->sim, TRUE);
208 * Function name: tw_osli_execute_scsi
209 * Description: Build a fw cmd, based on a CAM style ccb, and
212 * Input: req -- ptr to OSL internal request context
213 * ccb -- ptr to CAM style ccb
215 * Return value: 0 -- success
219 tw_osli_execute_scsi(struct tw_osli_req_context *req, union ccb *ccb)
221 struct twa_softc *sc = req->ctlr;
222 struct tw_cl_req_packet *req_pkt;
223 struct tw_cl_scsi_req_packet *scsi_req;
224 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
225 struct ccb_scsiio *csio = &(ccb->csio);
228 tw_osli_dbg_dprintf(10, sc, "SCSI I/O request 0x%x",
229 csio->cdb_io.cdb_bytes[0]);
231 if (ccb_h->target_id >= TW_CL_MAX_NUM_UNITS) {
232 tw_osli_dbg_dprintf(3, sc, "Invalid target. PTL = %x %x %x",
233 ccb_h->path_id, ccb_h->target_id, ccb_h->target_lun);
234 ccb_h->status |= CAM_TID_INVALID;
238 if (ccb_h->target_lun >= TW_CL_MAX_NUM_LUNS) {
239 tw_osli_dbg_dprintf(3, sc, "Invalid lun. PTL = %x %x %x",
240 ccb_h->path_id, ccb_h->target_id, ccb_h->target_lun);
241 ccb_h->status |= CAM_LUN_INVALID;
246 if(ccb_h->flags & CAM_CDB_PHYS) {
247 tw_osli_printf(sc, "",
248 TW_CL_SEVERITY_ERROR_STRING,
249 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
251 "Physical CDB address!");
252 ccb_h->status = CAM_REQ_CMP_ERR;
258 * We are going to work on this request. Mark it as enqueued (though
259 * we don't actually queue it...)
261 ccb_h->status |= CAM_SIM_QUEUED;
263 if((ccb_h->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
264 if(ccb_h->flags & CAM_DIR_IN)
265 req->flags |= TW_OSLI_REQ_FLAGS_DATA_IN;
267 req->flags |= TW_OSLI_REQ_FLAGS_DATA_OUT;
270 /* Build the CL understood request packet for SCSI cmds. */
271 req_pkt = &req->req_pkt;
273 req_pkt->tw_osl_callback = tw_osl_complete_io;
274 scsi_req = &(req_pkt->gen_req_pkt.scsi_req);
275 scsi_req->unit = ccb_h->target_id;
276 scsi_req->lun = ccb_h->target_lun;
277 scsi_req->sense_len = 0;
278 scsi_req->sense_data = (TW_UINT8 *)(&csio->sense_data);
279 scsi_req->scsi_status = 0;
280 if(ccb_h->flags & CAM_CDB_POINTER)
281 scsi_req->cdb = csio->cdb_io.cdb_ptr;
283 scsi_req->cdb = csio->cdb_io.cdb_bytes;
284 scsi_req->cdb_len = csio->cdb_len;
286 if (!(ccb_h->flags & CAM_DATA_PHYS)) {
287 /* Virtual data addresses. Need to convert them... */
288 tw_osli_dbg_dprintf(3, sc,
289 "XPT_SCSI_IO: Single virtual address!");
290 if (!(ccb_h->flags & CAM_SCATTER_VALID)) {
291 if (csio->dxfer_len > TW_CL_MAX_IO_SIZE) {
292 tw_osli_printf(sc, "size = %d",
293 TW_CL_SEVERITY_ERROR_STRING,
294 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
298 ccb_h->status = CAM_REQ_TOO_BIG;
303 if ((req->length = csio->dxfer_len)) {
304 req->data = csio->data_ptr;
305 scsi_req->sgl_entries = 1;
308 tw_osli_printf(sc, "",
309 TW_CL_SEVERITY_ERROR_STRING,
310 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
312 "XPT_SCSI_IO: Got SGList");
313 ccb_h->status = CAM_REQ_CMP_ERR;
318 /* Data addresses are physical. */
319 tw_osli_printf(sc, "",
320 TW_CL_SEVERITY_ERROR_STRING,
321 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
323 "XPT_SCSI_IO: Physical data addresses");
324 ccb_h->status = CAM_REQ_CMP_ERR;
325 ccb_h->status |= CAM_RELEASE_SIMQ;
326 ccb_h->status &= ~CAM_SIM_QUEUED;
331 ccb_h->timeout_ch = timeout(twa_timeout, req,
332 (ccb_h->timeout * hz) / 1000);
334 * twa_map_load_data_callback will fill in the SGL,
335 * and submit the I/O.
337 error = tw_osli_map_request(req);
344 * Function name: twa_action
345 * Description: Driver entry point for CAM's use.
347 * Input: sim -- sim corresponding to the ctlr
348 * ccb -- ptr to CAM request
353 twa_action(struct cam_sim *sim, union ccb *ccb)
355 struct twa_softc *sc = (struct twa_softc *)cam_sim_softc(sim);
356 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
358 switch (ccb_h->func_code) {
359 case XPT_SCSI_IO: /* SCSI I/O */
361 struct tw_osli_req_context *req;
363 if ((sc->state & TW_OSLI_CTLR_STATE_SIMQ_FROZEN) ||
364 ((req = tw_osli_get_request(sc)) == NULL)) {
365 tw_osli_dbg_dprintf(2, sc,
366 "simq frozen/Cannot get request pkt.");
368 * Freeze the simq to maintain ccb ordering. The next
369 * ccb that gets completed will unfreeze the simq.
371 tw_osli_disallow_new_requests(sc);
372 ccb_h->status |= CAM_REQUEUE_REQ;
376 req->req_handle.osl_req_ctxt = req;
378 if (tw_osli_execute_scsi(req, ccb))
379 tw_osli_req_q_insert_tail(req, TW_OSLI_FREE_Q);
384 tw_osli_dbg_dprintf(2, sc, "Abort request.");
385 ccb_h->status = CAM_UA_ABORT;
390 tw_cl_create_event(&(sc->ctlr_handle), TW_CL_TRUE,
391 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
392 0x2108, 0x3, TW_CL_SEVERITY_INFO_STRING,
393 "Received Reset Bus request from CAM",
396 if (tw_cl_reset_ctlr(&sc->ctlr_handle)) {
397 tw_cl_create_event(&(sc->ctlr_handle), TW_CL_TRUE,
398 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
399 0x2109, 0x1, TW_CL_SEVERITY_ERROR_STRING,
400 "Failed to reset bus",
402 ccb_h->status = CAM_REQ_CMP_ERR;
405 ccb_h->status = CAM_REQ_CMP;
410 case XPT_SET_TRAN_SETTINGS:
411 tw_osli_dbg_dprintf(3, sc, "XPT_SET_TRAN_SETTINGS");
414 * This command is not supported, since it's very specific
415 * to SCSI, and we are doing ATA.
417 ccb_h->status = CAM_FUNC_NOTAVAIL;
421 case XPT_GET_TRAN_SETTINGS:
423 struct ccb_trans_settings *cts = &ccb->cts;
425 tw_osli_dbg_dprintf(3, sc, "XPT_GET_TRAN_SETTINGS");
426 cts->valid = (CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID);
427 cts->flags &= ~(CCB_TRANS_DISC_ENB | CCB_TRANS_TAG_ENB);
428 ccb_h->status = CAM_REQ_CMP;
433 case XPT_CALC_GEOMETRY:
434 tw_osli_dbg_dprintf(3, sc, "XPT_CALC_GEOMETRY");
435 cam_calc_geometry(&ccb->ccg, 1/* extended */);
439 case XPT_PATH_INQ: /* Path inquiry -- get twa properties */
441 struct ccb_pathinq *path_inq = &ccb->cpi;
443 tw_osli_dbg_dprintf(3, sc, "XPT_PATH_INQ request");
445 path_inq->version_num = 1;
446 path_inq->hba_inquiry = 0;
447 path_inq->target_sprt = 0;
448 path_inq->hba_misc = 0;
449 path_inq->hba_eng_cnt = 0;
450 path_inq->max_target = TW_CL_MAX_NUM_UNITS;
451 path_inq->max_lun = TW_CL_MAX_NUM_LUNS - 1;
452 path_inq->unit_number = cam_sim_unit(sim);
453 path_inq->bus_id = cam_sim_bus(sim);
454 path_inq->initiator_id = TW_CL_MAX_NUM_UNITS;
455 path_inq->base_transfer_speed = 100000;
456 strncpy(path_inq->sim_vid, "FreeBSD", SIM_IDLEN);
457 strncpy(path_inq->hba_vid, "3ware", HBA_IDLEN);
458 strncpy(path_inq->dev_name, cam_sim_name(sim), DEV_IDLEN);
459 ccb_h->status = CAM_REQ_CMP;
465 tw_osli_dbg_dprintf(3, sc, "func_code = %x", ccb_h->func_code);
466 ccb_h->status = CAM_REQ_INVALID;
475 * Function name: twa_poll
476 * Description: Driver entry point called when interrupts are not
479 * Input: sim -- sim corresponding to the controller
484 twa_poll(struct cam_sim *sim)
486 struct twa_softc *sc = (struct twa_softc *)(cam_sim_softc(sim));
488 tw_osli_dbg_dprintf(3, sc, "entering; sc = %p", sc);
490 * It's been observed that twa_poll can get called (from
491 * dashutdown --> xpt_polled_action) even when interrupts are
492 * active, in which case, the ISR might clear the interrupt,
493 * leaving the call to tw_cl_interrupt below, no way of determining
494 * that the response from firmware is ready, resulting in
495 * tw_cl_deferred_interrupt never getting called. To cover this case,
496 * we will make the call to tw_cl_deferred_interrupt not dependent
497 * on the return value from tw_cl_interrupt.
499 tw_cl_interrupt(&(sc->ctlr_handle));
500 tw_cl_deferred_interrupt(&(sc->ctlr_handle));
501 tw_osli_dbg_dprintf(3, sc, "exiting; sc = %p", sc);
507 * Function name: twa_async
508 * Description: Driver entry point for CAM to notify driver of special
509 * events. We don't use this for now.
511 * Input: callback_arg -- ptr to per ctlr structure
512 * code -- code associated with the event
516 * Return value: 0 -- success
520 twa_async(TW_VOID *callback_arg, TW_UINT32 code,
521 struct cam_path *path, TW_VOID *arg)
524 struct twa_softc *sc = (struct twa_softc *)callback_arg;
525 #endif /* TW_OSL_DEBUG */
527 tw_osli_dbg_dprintf(3, sc, "sc = %p, code = %x, path = %p, arg = %p",
528 sc, code, path, arg);
534 * Function name: twa_timeout
535 * Description: Driver entry point for being alerted on a request
538 * Input: arg -- ptr to timed out request
543 twa_timeout(TW_VOID *arg)
545 struct tw_osli_req_context *req =
546 (struct tw_osli_req_context *)arg;
548 tw_cl_create_event(&(req->ctlr->ctlr_handle), TW_CL_TRUE,
549 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
550 0x210B, 0x1, TW_CL_SEVERITY_ERROR_STRING,
551 "Request timed out!",
552 "request = %p", req);
553 tw_cl_reset_ctlr(&(req->ctlr->ctlr_handle));
559 * Function name: tw_osli_request_bus_scan
560 * Description: Requests CAM for a scan of the bus.
562 * Input: sc -- ptr to per ctlr structure
564 * Return value: 0 -- success
568 tw_osli_request_bus_scan(struct twa_softc *sc)
570 struct cam_path *path;
573 tw_osli_dbg_dprintf(3, sc, "entering");
575 /* If we get here before sc->sim is initialized, return an error. */
578 if ((ccb = malloc(sizeof(union ccb), M_TEMP, M_WAITOK)) == NULL)
580 bzero(ccb, sizeof(union ccb));
582 if (xpt_create_path(&path, xpt_periph, cam_sim_path(sc->sim),
583 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP)
586 xpt_setup_ccb(&ccb->ccb_h, path, 5);
587 ccb->ccb_h.func_code = XPT_SCAN_BUS;
588 ccb->ccb_h.cbfcnp = twa_bus_scan_cb;
589 ccb->crcn.flags = CAM_FLAG_NONE;
598 * Function name: twa_bus_scan_cb
599 * Description: Callback from CAM on a bus scan request.
601 * Input: periph -- we don't use this
602 * ccb -- bus scan request ccb that we sent to CAM
607 twa_bus_scan_cb(struct cam_periph *periph, union ccb *ccb)
609 tw_osli_dbg_printf(3, "entering");
611 if (ccb->ccb_h.status != CAM_REQ_CMP)
612 printf("cam_scan_callback: failure status = %x\n",
615 tw_osli_dbg_printf(3, "success");
617 xpt_free_path(ccb->ccb_h.path);
624 * Function name: tw_osli_allow_new_requests
625 * Description: Sets the appropriate status bits in a ccb such that,
626 * when the ccb is completed by a call to xpt_done,
627 * CAM knows that it's ok to unfreeze the flow of new
628 * requests to this controller, if the flow is frozen.
630 * Input: sc -- ptr to OSL internal ctlr context
631 * ccb -- ptr to CAM request
636 tw_osli_allow_new_requests(struct twa_softc *sc, TW_VOID *ccb)
638 ((union ccb *)(ccb))->ccb_h.status |= CAM_RELEASE_SIMQ;
639 sc->state &= ~TW_OSLI_CTLR_STATE_SIMQ_FROZEN;
645 * Function name: tw_osli_disallow_new_requests
646 * Description: Calls the appropriate CAM function, so as to freeze
647 * the flow of new requests from CAM to this controller.
649 * Input: sc -- ptr to OSL internal ctlr context
654 tw_osli_disallow_new_requests(struct twa_softc *sc)
657 xpt_freeze_simq(sc->sim, 1);
659 sc->state |= TW_OSLI_CTLR_STATE_SIMQ_FROZEN;
665 * Function name: tw_osl_ctlr_busy
666 * Description: CL calls this function on cmd queue full or otherwise,
667 * when it is too busy to accept new requests.
669 * Input: ctlr_handle -- ptr to controller handle
670 * req_handle -- ptr to request handle sent by OSL.
675 tw_osl_ctlr_busy(struct tw_cl_ctlr_handle *ctlr_handle,
676 struct tw_cl_req_handle *req_handle)
678 tw_osli_disallow_new_requests(ctlr_handle->osl_ctlr_ctxt);
684 * Function name: tw_osl_scan_bus
685 * Description: CL calls this function to request for a bus scan.
687 * Input: ctlr_handle -- ptr to controller handle
692 tw_osl_scan_bus(struct tw_cl_ctlr_handle *ctlr_handle)
694 struct twa_softc *sc = ctlr_handle->osl_ctlr_ctxt;
697 if ((error = tw_osli_request_bus_scan(sc)))
698 tw_osli_printf(sc, "error = %d",
699 TW_CL_SEVERITY_ERROR_STRING,
700 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
702 "Bus scan request to CAM failed",
709 * Function name: tw_osl_complete_io
710 * Description: Called to complete CAM scsi requests.
712 * Input: req_handle -- ptr to request handle
717 tw_osl_complete_io(struct tw_cl_req_handle *req_handle)
719 struct tw_osli_req_context *req = req_handle->osl_req_ctxt;
720 struct tw_cl_req_packet *req_pkt =
721 (struct tw_cl_req_packet *)(&req->req_pkt);
722 struct tw_cl_scsi_req_packet *scsi_req;
723 struct twa_softc *sc = req->ctlr;
724 union ccb *ccb = (union ccb *)(req->orig_req);
726 tw_osli_dbg_dprintf(10, sc, "entering");
728 if (req->state != TW_OSLI_REQ_STATE_BUSY)
729 tw_osli_printf(sc, "request = %p, status = %d",
730 TW_CL_SEVERITY_ERROR_STRING,
731 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
733 "Unposted command completed!!",
737 * Remove request from the busy queue. Just mark it complete.
738 * There's no need to move it into the complete queue as we are
739 * going to be done with it right now.
741 req->state = TW_OSLI_REQ_STATE_COMPLETE;
742 tw_osli_req_q_remove_item(req, TW_OSLI_BUSY_Q);
744 tw_osli_unmap_request(req);
746 untimeout(twa_timeout, req, ccb->ccb_h.timeout_ch);
747 if (req->error_code) {
748 /* This request never got submitted to the firmware. */
749 if (req->error_code == EBUSY) {
751 * Cmd queue is full, or the Common Layer is out of
752 * resources. The simq will already have been frozen
753 * by CL's call to tw_osl_ctlr_busy, and this will
754 * maintain ccb ordering. The next ccb that gets
755 * completed will unfreeze the simq.
757 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
759 else if (req->error_code == EFBIG)
760 ccb->ccb_h.status = CAM_REQ_TOO_BIG;
762 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
764 scsi_req = &(req_pkt->gen_req_pkt.scsi_req);
765 if (req_pkt->status == TW_CL_ERR_REQ_SUCCESS)
766 ccb->ccb_h.status = CAM_REQ_CMP;
768 if (req_pkt->status & TW_CL_ERR_REQ_INVALID_TARGET)
769 ccb->ccb_h.status |= CAM_TID_INVALID;
770 else if (req_pkt->status & TW_CL_ERR_REQ_INVALID_LUN)
771 ccb->ccb_h.status |= CAM_LUN_INVALID;
772 else if (req_pkt->status & TW_CL_ERR_REQ_SCSI_ERROR)
773 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
774 else if (req_pkt->status & TW_CL_ERR_REQ_BUS_RESET)
775 ccb->ccb_h.status |= CAM_SCSI_BUS_RESET;
777 * If none of the above errors occurred, simply
778 * mark completion error.
780 if (ccb->ccb_h.status == 0)
781 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
783 if (req_pkt->status & TW_CL_ERR_REQ_AUTO_SENSE_VALID) {
784 ccb->csio.sense_len = scsi_req->sense_len;
785 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
789 ccb->csio.scsi_status = scsi_req->scsi_status;
790 /* If simq is frozen, unfreeze it. */
791 if (sc->state & TW_OSLI_CTLR_STATE_SIMQ_FROZEN)
792 tw_osli_allow_new_requests(sc, (TW_VOID *)ccb);
795 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
797 if (! req->error_code)
798 /* twa_action will free the request otherwise */
799 tw_osli_req_q_insert_tail(req, TW_OSLI_FREE_Q);