isci_io_request.c revision 234106
1103285Sikob/*- 2122526Ssimokawa * BSD LICENSE 3122526Ssimokawa * 4103285Sikob * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 5103285Sikob * All rights reserved. 6103285Sikob * 7103285Sikob * Redistribution and use in source and binary forms, with or without 8103285Sikob * modification, are permitted provided that the following conditions 9103285Sikob * are met: 10103285Sikob * 11103285Sikob * * Redistributions of source code must retain the above copyright 12103285Sikob * notice, this list of conditions and the following disclaimer. 13103285Sikob * * Redistributions in binary form must reproduce the above copyright 14103285Sikob * notice, this list of conditions and the following disclaimer in 15103285Sikob * the documentation and/or other materials provided with the 16103285Sikob * distribution. 17103285Sikob * 18103285Sikob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19103285Sikob * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20103285Sikob * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21103285Sikob * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22103285Sikob * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23103285Sikob * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24103285Sikob * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25103285Sikob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26103285Sikob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27103285Sikob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28103285Sikob * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29103285Sikob */ 30103285Sikob 31103285Sikob#include <sys/cdefs.h> 32103285Sikob__FBSDID("$FreeBSD: head/sys/dev/isci/isci_io_request.c 234106 2012-04-10 16:33:19Z jimharris $"); 33103285Sikob 34103285Sikob#include <dev/isci/isci.h> 35103285Sikob 36103285Sikob#include <cam/scsi/scsi_all.h> 37103285Sikob#include <cam/scsi/scsi_message.h> 38103285Sikob 39103285Sikob#include <dev/isci/scil/intel_sas.h> 40103285Sikob 41103285Sikob#include <dev/isci/scil/sci_util.h> 42103285Sikob 43103285Sikob#include <dev/isci/scil/scif_io_request.h> 44103285Sikob#include <dev/isci/scil/scif_controller.h> 45117732Ssimokawa#include <dev/isci/scil/scif_remote_device.h> 46117126Sscottl#include <dev/isci/scil/scif_user_callback.h> 47117126Sscottl 48117732Ssimokawa#include <dev/isci/scil/scic_io_request.h> 49103285Sikob#include <dev/isci/scil/scic_user_callback.h> 50112136Ssimokawa 51112136Ssimokawa/** 52112136Ssimokawa * @brief This user callback will inform the user that an IO request has 53103285Sikob * completed. 54103285Sikob * 55103285Sikob * @param[in] controller This parameter specifies the controller on 56103285Sikob * which the IO request is completing. 57103285Sikob * @param[in] remote_device This parameter specifies the remote device on 58103285Sikob * which this request is completing. 59103285Sikob * @param[in] io_request This parameter specifies the IO request that has 60103285Sikob * completed. 61103285Sikob * @param[in] completion_status This parameter specifies the results of 62103285Sikob * the IO request operation. SCI_IO_SUCCESS indicates 63103285Sikob * successful completion. 64103285Sikob * 65103285Sikob * @return none 66103285Sikob */ 67113584Ssimokawavoid 68103285Sikobscif_cb_io_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller, 69120660Ssimokawa SCI_REMOTE_DEVICE_HANDLE_T remote_device, 70103285Sikob SCI_IO_REQUEST_HANDLE_T io_request, SCI_IO_STATUS completion_status) 71103285Sikob{ 72103285Sikob struct ISCI_IO_REQUEST *isci_request = 73103285Sikob (struct ISCI_IO_REQUEST *)sci_object_get_association(io_request); 74111615Ssimokawa 75121185Ssimokawa scif_controller_complete_io(scif_controller, remote_device, io_request); 76121185Ssimokawa isci_io_request_complete(scif_controller, remote_device, isci_request, 77121185Ssimokawa completion_status); 78121185Ssimokawa} 79121185Ssimokawa 80113584Ssimokawavoid 81113584Ssimokawaisci_io_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller, 82113584Ssimokawa SCI_REMOTE_DEVICE_HANDLE_T remote_device, 83103285Sikob struct ISCI_IO_REQUEST *isci_request, SCI_IO_STATUS completion_status) 84113584Ssimokawa{ 85111615Ssimokawa struct ISCI_CONTROLLER *isci_controller; 86111615Ssimokawa struct ISCI_REMOTE_DEVICE *isci_remote_device; 87111615Ssimokawa union ccb *ccb; 88111615Ssimokawa BOOL complete_ccb; 89111615Ssimokawa 90111615Ssimokawa complete_ccb = TRUE; 91111615Ssimokawa isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(scif_controller); 92120660Ssimokawa isci_remote_device = 93111615Ssimokawa (struct ISCI_REMOTE_DEVICE *) sci_object_get_association(remote_device); 94111615Ssimokawa 95111615Ssimokawa ccb = isci_request->ccb; 96103285Sikob 97120660Ssimokawa ccb->ccb_h.status &= ~CAM_STATUS_MASK; 98120660Ssimokawa 99120660Ssimokawa switch (completion_status) { 100120660Ssimokawa case SCI_IO_SUCCESS: 101103285Sikob case SCI_IO_SUCCESS_COMPLETE_BEFORE_START: 102103285Sikob#if __FreeBSD_version >= 900026 103120660Ssimokawa if (ccb->ccb_h.func_code == XPT_SMP_IO) { 104103285Sikob void *smp_response = 105103285Sikob scif_io_request_get_response_iu_address( 106120660Ssimokawa isci_request->sci_object); 107103285Sikob 108103285Sikob memcpy(ccb->smpio.smp_response, smp_response, 109111203Ssimokawa ccb->smpio.smp_response_len); 110103285Sikob } 111124251Ssimokawa#endif 112111199Ssimokawa ccb->ccb_h.status |= CAM_REQ_CMP; 113122387Ssimokawa break; 114122387Ssimokawa 115122387Ssimokawa case SCI_IO_SUCCESS_IO_DONE_EARLY: 116103285Sikob ccb->ccb_h.status |= CAM_REQ_CMP; 117103285Sikob ccb->csio.resid = ccb->csio.dxfer_len - 118103285Sikob scif_io_request_get_number_of_bytes_transferred( 119103285Sikob isci_request->sci_object); 120103285Sikob break; 121103285Sikob 122103285Sikob case SCI_IO_FAILURE_RESPONSE_VALID: 123103285Sikob { 124103285Sikob SCI_SSP_RESPONSE_IU_T * response_buffer; 125121792Ssimokawa uint32_t sense_length; 126122387Ssimokawa int error_code, sense_key, asc, ascq; 127122387Ssimokawa struct ccb_scsiio *csio = &ccb->csio; 128122387Ssimokawa 129122387Ssimokawa response_buffer = (SCI_SSP_RESPONSE_IU_T *) 130122387Ssimokawa scif_io_request_get_response_iu_address( 131103285Sikob isci_request->sci_object); 132122387Ssimokawa 133122387Ssimokawa sense_length = sci_ssp_get_sense_data_length( 134122387Ssimokawa response_buffer->sense_data_length); 135122387Ssimokawa 136122387Ssimokawa sense_length = MIN(csio->sense_len, sense_length); 137122387Ssimokawa 138103285Sikob memcpy(&csio->sense_data, response_buffer->data, sense_length); 139103285Sikob 140113584Ssimokawa csio->sense_resid = csio->sense_len - sense_length; 141113584Ssimokawa csio->scsi_status = response_buffer->status; 142113584Ssimokawa ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR; 143113584Ssimokawa ccb->ccb_h.status |= CAM_AUTOSNS_VALID; 144113584Ssimokawa scsi_extract_sense( &csio->sense_data, &error_code, &sense_key, 145113584Ssimokawa &asc, &ascq ); 146103285Sikob isci_log_message(1, "ISCI", 147103285Sikob "isci: bus=%x target=%x lun=%x cdb[0]=%x status=%x key=%x asc=%x ascq=%x\n", 148103285Sikob ccb->ccb_h.path_id, ccb->ccb_h.target_id, 149113584Ssimokawa ccb->ccb_h.target_lun, csio->cdb_io.cdb_bytes[0], 150120660Ssimokawa csio->scsi_status, sense_key, asc, ascq); 151113584Ssimokawa break; 152120660Ssimokawa } 153103285Sikob 154113584Ssimokawa case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: 155103285Sikob isci_remote_device_reset(isci_remote_device, NULL); 156103285Sikob 157113584Ssimokawa /* drop through */ 158103285Sikob case SCI_IO_FAILURE_TERMINATED: 159103285Sikob ccb->ccb_h.status |= CAM_REQ_TERMIO; 160113584Ssimokawa isci_log_message(1, "ISCI", 161103285Sikob "isci: bus=%x target=%x lun=%x cdb[0]=%x terminated\n", 162103285Sikob ccb->ccb_h.path_id, ccb->ccb_h.target_id, 163103285Sikob ccb->ccb_h.target_lun, ccb->csio.cdb_io.cdb_bytes[0]); 164114732Ssimokawa break; 165110336Ssimokawa 166103285Sikob case SCI_IO_FAILURE_INVALID_STATE: 167110336Ssimokawa case SCI_IO_FAILURE_INSUFFICIENT_RESOURCES: 168103285Sikob complete_ccb = FALSE; 169103285Sikob break; 170103285Sikob 171103285Sikob case SCI_IO_FAILURE_INVALID_REMOTE_DEVICE: 172103285Sikob ccb->ccb_h.status |= CAM_DEV_NOT_THERE; 173110336Ssimokawa break; 174114732Ssimokawa 175108503Ssimokawa case SCI_IO_FAILURE_NO_NCQ_TAG_AVAILABLE: 176108503Ssimokawa { 177120842Ssimokawa struct ccb_relsim ccb_relsim; 178121185Ssimokawa struct cam_path *path; 179121185Ssimokawa 180121185Ssimokawa xpt_create_path(&path, NULL, 181121185Ssimokawa cam_sim_path(isci_controller->sim), 182120842Ssimokawa isci_remote_device->index, 0); 183103285Sikob 184103285Sikob xpt_setup_ccb(&ccb_relsim.ccb_h, path, 5); 185113584Ssimokawa ccb_relsim.ccb_h.func_code = XPT_REL_SIMQ; 186113584Ssimokawa ccb_relsim.ccb_h.flags = CAM_DEV_QFREEZE; 187111615Ssimokawa ccb_relsim.release_flags = RELSIM_ADJUST_OPENINGS; 188113584Ssimokawa ccb_relsim.openings = 189103285Sikob scif_remote_device_get_max_queue_depth(remote_device); 190113584Ssimokawa xpt_action((union ccb *)&ccb_relsim); 191103285Sikob xpt_free_path(path); 192103285Sikob complete_ccb = FALSE; 193103285Sikob } 194103285Sikob break; 195103285Sikob 196103285Sikob case SCI_IO_FAILURE: 197103285Sikob case SCI_IO_FAILURE_REQUIRES_SCSI_ABORT: 198103285Sikob case SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL: 199121185Ssimokawa case SCI_IO_FAILURE_PROTOCOL_VIOLATION: 200103285Sikob case SCI_IO_FAILURE_INVALID_PARAMETER_VALUE: 201103285Sikob case SCI_IO_FAILURE_CONTROLLER_SPECIFIC_ERR: 202103285Sikob default: 203111615Ssimokawa isci_log_message(1, "ISCI", 204111615Ssimokawa "isci: bus=%x target=%x lun=%x cdb[0]=%x completion status=%x\n", 205111615Ssimokawa ccb->ccb_h.path_id, ccb->ccb_h.target_id, 206111615Ssimokawa ccb->ccb_h.target_lun, ccb->csio.cdb_io.cdb_bytes[0], 207113584Ssimokawa completion_status); 208113584Ssimokawa ccb->ccb_h.status |= CAM_REQ_CMP_ERR; 209103285Sikob break; 210103285Sikob } 211103285Sikob 212103285Sikob callout_stop(&isci_request->parent.timer); 213103285Sikob bus_dmamap_sync(isci_request->parent.dma_tag, 214111615Ssimokawa isci_request->parent.dma_map, 215103285Sikob BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); 216103285Sikob 217103285Sikob bus_dmamap_unload(isci_request->parent.dma_tag, 218122387Ssimokawa isci_request->parent.dma_map); 219124145Ssimokawa 220124145Ssimokawa isci_request->ccb = NULL; 221103285Sikob 222122387Ssimokawa sci_pool_put(isci_controller->request_pool, 223124169Ssimokawa (struct ISCI_REQUEST *)isci_request); 224124169Ssimokawa 225124169Ssimokawa if (complete_ccb) { 226121185Ssimokawa if (ccb->ccb_h.status != CAM_REQ_CMP) { 227124169Ssimokawa /* ccb will be completed with some type of non-success 228121185Ssimokawa * status. So temporarily freeze the queue until the 229124169Ssimokawa * upper layers can act on the status. The 230124169Ssimokawa * CAM_DEV_QFRZN flag will then release the queue 231124169Ssimokawa * after the status is acted upon. 232124169Ssimokawa */ 233124169Ssimokawa ccb->ccb_h.status |= CAM_DEV_QFRZN; 234124169Ssimokawa xpt_freeze_devq(ccb->ccb_h.path, 1); 235124169Ssimokawa } 236124169Ssimokawa 237124169Ssimokawa if (isci_remote_device->frozen_lun_mask != 0) { 238121185Ssimokawa isci_remote_device_release_device_queue(isci_remote_device); 239121185Ssimokawa } 240124169Ssimokawa 241124169Ssimokawa xpt_done(ccb); 242124169Ssimokawa 243124169Ssimokawa if (isci_controller->is_frozen == TRUE) { 244124169Ssimokawa isci_controller->is_frozen = FALSE; 245103285Sikob xpt_release_simq(isci_controller->sim, TRUE); 246108281Ssimokawa } 247103285Sikob } else { 248103285Sikob isci_remote_device_freeze_lun_queue(isci_remote_device, 249103285Sikob ccb->ccb_h.target_lun); 250103285Sikob 251111615Ssimokawa isci_log_message(1, "ISCI", "queue %p %x\n", ccb, 252111615Ssimokawa ccb->csio.cdb_io.cdb_bytes[0]); 253103285Sikob ccb->ccb_h.status |= CAM_SIM_QUEUED; 254103285Sikob TAILQ_INSERT_TAIL(&isci_remote_device->queued_ccbs, 255103285Sikob &ccb->ccb_h, sim_links.tqe); 256103285Sikob } 257103285Sikob} 258103285Sikob 259103285Sikob/** 260103285Sikob * @brief This callback method asks the user to provide the physical 261103285Sikob * address for the supplied virtual address when building an 262103285Sikob * io request object. 263103285Sikob * 264103285Sikob * @param[in] controller This parameter is the core controller object 265103285Sikob * handle. 266103285Sikob * @param[in] io_request This parameter is the io request object handle 267103285Sikob * for which the physical address is being requested. 268103285Sikob * @param[in] virtual_address This paramter is the virtual address which 269103285Sikob * is to be returned as a physical address. 270103285Sikob * @param[out] physical_address The physical address for the supplied virtual 271103285Sikob * address. 272103285Sikob * 273103285Sikob * @return None. 274103285Sikob */ 275103285Sikobvoid 276103285Sikobscic_cb_io_request_get_physical_address(SCI_CONTROLLER_HANDLE_T controller, 277103285Sikob SCI_IO_REQUEST_HANDLE_T io_request, void *virtual_address, 278103285Sikob SCI_PHYSICAL_ADDRESS *physical_address) 279103285Sikob{ 280103285Sikob SCI_IO_REQUEST_HANDLE_T scif_request = 281103285Sikob sci_object_get_association(io_request); 282103285Sikob struct ISCI_REQUEST *isci_request = 283103285Sikob sci_object_get_association(scif_request); 284103285Sikob 285103285Sikob if(isci_request != NULL) { 286103285Sikob /* isci_request is not NULL, meaning this is a request initiated 287103285Sikob * by CAM or the isci layer (i.e. device reset for I/O 288103285Sikob * timeout). Therefore we can calculate the physical address 289103285Sikob * based on the address we stored in the struct ISCI_REQUEST 290103285Sikob * object. 291103285Sikob */ 292103285Sikob *physical_address = isci_request->physical_address + 293103285Sikob (uintptr_t)virtual_address - 294103285Sikob (uintptr_t)isci_request; 295103285Sikob } else { 296103285Sikob /* isci_request is NULL, meaning this is a request generated 297103285Sikob * internally by SCIL (i.e. for SMP requests or NCQ error 298103285Sikob * recovery). Therefore we calculate the physical address 299103285Sikob * based on the controller's uncached controller memory buffer, 300103285Sikob * since we know that this is what SCIL uses for internal 301103285Sikob * framework requests. 302103285Sikob */ 303103285Sikob SCI_CONTROLLER_HANDLE_T scif_controller = 304103285Sikob (SCI_CONTROLLER_HANDLE_T) sci_object_get_association(controller); 305103285Sikob struct ISCI_CONTROLLER *isci_controller = 306103285Sikob (struct ISCI_CONTROLLER *)sci_object_get_association(scif_controller); 307103285Sikob U64 virt_addr_offset = (uintptr_t)virtual_address - 308103285Sikob (U64)isci_controller->uncached_controller_memory.virtual_address; 309103285Sikob 310103285Sikob *physical_address = 311103285Sikob isci_controller->uncached_controller_memory.physical_address 312103285Sikob + virt_addr_offset; 313103285Sikob } 314103285Sikob} 315103285Sikob 316103285Sikob/** 317103285Sikob * @brief This callback method asks the user to provide the address for 318103285Sikob * the command descriptor block (CDB) associated with this IO request. 319103285Sikob * 320103285Sikob * @param[in] scif_user_io_request This parameter points to the user's 321103285Sikob * IO request object. It is a cookie that allows the user to 322103285Sikob * provide the necessary information for this callback. 323103285Sikob * 324103285Sikob * @return This method returns the virtual address of the CDB. 325103285Sikob */ 326120660Ssimokawavoid * 327111615Ssimokawascif_cb_io_request_get_cdb_address(void * scif_user_io_request) 328111615Ssimokawa{ 329111615Ssimokawa struct ISCI_IO_REQUEST *isci_request = 330103285Sikob (struct ISCI_IO_REQUEST *)scif_user_io_request; 331103285Sikob 332103285Sikob return (isci_request->ccb->csio.cdb_io.cdb_bytes); 333103285Sikob} 334103285Sikob 335103285Sikob/** 336103285Sikob * @brief This callback method asks the user to provide the length of 337103285Sikob * the command descriptor block (CDB) associated with this IO request. 338103285Sikob * 339103285Sikob * @param[in] scif_user_io_request This parameter points to the user's 340103285Sikob * IO request object. It is a cookie that allows the user to 341103285Sikob * provide the necessary information for this callback. 342103285Sikob * 343103285Sikob * @return This method returns the length of the CDB. 344103285Sikob */ 345103285Sikobuint32_t 346103285Sikobscif_cb_io_request_get_cdb_length(void * scif_user_io_request) 347103285Sikob{ 348103285Sikob struct ISCI_IO_REQUEST *isci_request = 349108503Ssimokawa (struct ISCI_IO_REQUEST *)scif_user_io_request; 350108503Ssimokawa 351103285Sikob return (isci_request->ccb->csio.cdb_len); 352103285Sikob} 353103285Sikob 354103285Sikob/** 355103285Sikob * @brief This callback method asks the user to provide the Logical Unit (LUN) 356103285Sikob * associated with this IO request. 357103285Sikob * 358103285Sikob * @note The contents of the value returned from this callback are defined 359103285Sikob * by the protocol standard (e.g. T10 SAS specification). Please 360103285Sikob * refer to the transport command information unit description 361103285Sikob * in the associated standard. 362103285Sikob * 363103285Sikob * @param[in] scif_user_io_request This parameter points to the user's 364103285Sikob * IO request object. It is a cookie that allows the user to 365110184Ssimokawa * provide the necessary information for this callback. 366110184Ssimokawa * 367110184Ssimokawa * @return This method returns the LUN associated with this request. 368110184Ssimokawa */ 369110184Ssimokawauint32_t 370110184Ssimokawascif_cb_io_request_get_lun(void * scif_user_io_request) 371110184Ssimokawa{ 372110184Ssimokawa struct ISCI_IO_REQUEST *isci_request = 373110184Ssimokawa (struct ISCI_IO_REQUEST *)scif_user_io_request; 374110184Ssimokawa 375110184Ssimokawa return (isci_request->ccb->ccb_h.target_lun); 376110184Ssimokawa} 377110184Ssimokawa 378110184Ssimokawa/** 379110184Ssimokawa * @brief This callback method asks the user to provide the task attribute 380110184Ssimokawa * associated with this IO request. 381110184Ssimokawa * 382110184Ssimokawa * @note The contents of the value returned from this callback are defined 383110184Ssimokawa * by the protocol standard (e.g. T10 SAS specification). Please 384110184Ssimokawa * refer to the transport command information unit description 385110184Ssimokawa * in the associated standard. 386110184Ssimokawa * 387110184Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 388110184Ssimokawa * IO request object. It is a cookie that allows the user to 389110184Ssimokawa * provide the necessary information for this callback. 390110184Ssimokawa * 391110184Ssimokawa * @return This method returns the task attribute associated with this 392110184Ssimokawa * IO request. 393110184Ssimokawa */ 394110184Ssimokawauint32_t 395110184Ssimokawascif_cb_io_request_get_task_attribute(void * scif_user_io_request) 396110184Ssimokawa{ 397110184Ssimokawa struct ISCI_IO_REQUEST *isci_request = 398110184Ssimokawa (struct ISCI_IO_REQUEST *)scif_user_io_request; 399110184Ssimokawa uint32_t task_attribute; 400110184Ssimokawa 401110184Ssimokawa if((isci_request->ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0) 402110184Ssimokawa switch(isci_request->ccb->csio.tag_action) { 403110184Ssimokawa case MSG_HEAD_OF_Q_TAG: 404110184Ssimokawa task_attribute = SCI_SAS_HEAD_OF_QUEUE_ATTRIBUTE; 405110184Ssimokawa break; 406110184Ssimokawa 407110184Ssimokawa case MSG_ORDERED_Q_TAG: 408110184Ssimokawa task_attribute = SCI_SAS_ORDERED_ATTRIBUTE; 409110184Ssimokawa break; 410110184Ssimokawa 411110184Ssimokawa case MSG_ACA_TASK: 412110184Ssimokawa task_attribute = SCI_SAS_ACA_ATTRIBUTE; 413110184Ssimokawa break; 414110184Ssimokawa 415110184Ssimokawa default: 416110184Ssimokawa task_attribute = SCI_SAS_SIMPLE_ATTRIBUTE; 417121185Ssimokawa break; 418121185Ssimokawa } 419103285Sikob else 420108503Ssimokawa task_attribute = SCI_SAS_SIMPLE_ATTRIBUTE; 421108503Ssimokawa 422121185Ssimokawa return (task_attribute); 423121185Ssimokawa} 424121185Ssimokawa 425103285Sikob/** 426121185Ssimokawa * @brief This callback method asks the user to provide the command priority 427114069Ssimokawa * associated with this IO request. 428108503Ssimokawa * 429108503Ssimokawa * @note The contents of the value returned from this callback are defined 430108503Ssimokawa * by the protocol standard (e.g. T10 SAS specification). Please 431108503Ssimokawa * refer to the transport command information unit description 432108503Ssimokawa * in the associated standard. 433108503Ssimokawa * 434110839Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 435108642Ssimokawa * IO request object. It is a cookie that allows the user to 436108642Ssimokawa * provide the necessary information for this callback. 437108642Ssimokawa * 438108503Ssimokawa * @return This method returns the command priority associated with this 439108503Ssimokawa * IO request. 440108503Ssimokawa */ 441108503Ssimokawauint32_t 442110839Ssimokawascif_cb_io_request_get_command_priority(void * scif_user_io_request) 443121185Ssimokawa{ 444121185Ssimokawa return (0); 445121185Ssimokawa} 446121185Ssimokawa 447121185Ssimokawa/** 448110839Ssimokawa * @brief This method simply returns the virtual address associated 449110839Ssimokawa * with the scsi_io and byte_offset supplied parameters. 450121185Ssimokawa * 451121185Ssimokawa * @note This callback is not utilized in the fast path. The expectation 452121185Ssimokawa * is that this method is utilized for items such as SCSI to ATA 453121185Ssimokawa * translation for commands like INQUIRY, READ CAPACITY, etc. 454121185Ssimokawa * 455121185Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 456121185Ssimokawa * IO request object. It is a cookie that allows the user to 457121185Ssimokawa * provide the necessary information for this callback. 458121185Ssimokawa * @param[in] byte_offset This parameter specifies the offset into the data 459121185Ssimokawa * buffers pointed to by the SGL. The byte offset starts at 0 460121185Ssimokawa * and continues until the last byte pointed to be the last SGL 461121185Ssimokawa * element. 462103285Sikob * 463121185Ssimokawa * @return A virtual address pointer to the location specified by the 464121185Ssimokawa * parameters. 465121185Ssimokawa */ 466121185Ssimokawauint8_t * 467121185Ssimokawascif_cb_io_request_get_virtual_address_from_sgl(void * scif_user_io_request, 468121185Ssimokawa uint32_t byte_offset) 469121185Ssimokawa{ 470121185Ssimokawa struct ISCI_IO_REQUEST *isci_request = 471121185Ssimokawa (struct ISCI_IO_REQUEST *)scif_user_io_request; 472121185Ssimokawa 473121185Ssimokawa return (isci_request->ccb->csio.data_ptr + byte_offset); 474121185Ssimokawa} 475121185Ssimokawa 476121185Ssimokawa/** 477121185Ssimokawa * @brief This callback method asks the user to provide the number of 478121185Ssimokawa * bytes to be transfered as part of this request. 479121185Ssimokawa * 480121185Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 481121185Ssimokawa * IO request object. It is a cookie that allows the user to 482121185Ssimokawa * provide the necessary information for this callback. 483121185Ssimokawa * 484121185Ssimokawa * @return This method returns the number of payload data bytes to be 485121185Ssimokawa * transfered for this IO request. 486121185Ssimokawa */ 487121185Ssimokawauint32_t 488121185Ssimokawascif_cb_io_request_get_transfer_length(void * scif_user_io_request) 489108503Ssimokawa{ 490108503Ssimokawa struct ISCI_IO_REQUEST *isci_request = 491121185Ssimokawa (struct ISCI_IO_REQUEST *)scif_user_io_request; 492121185Ssimokawa 493108503Ssimokawa return (isci_request->ccb->csio.dxfer_len); 494108503Ssimokawa 495108503Ssimokawa} 496110839Ssimokawa 497110839Ssimokawa/** 498110839Ssimokawa * @brief This callback method asks the user to provide the data direction 499121185Ssimokawa * for this request. 500110839Ssimokawa * 501121185Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 502121185Ssimokawa * IO request object. It is a cookie that allows the user to 503121185Ssimokawa * provide the necessary information for this callback. 504121185Ssimokawa * 505121185Ssimokawa * @return This method returns the value of SCI_IO_REQUEST_DATA_OUT, 506121185Ssimokawa * SCI_IO_REQUEST_DATA_IN, or SCI_IO_REQUEST_NO_DATA. 507121185Ssimokawa */ 508121185SsimokawaSCI_IO_REQUEST_DATA_DIRECTION 509121185Ssimokawascif_cb_io_request_get_data_direction(void * scif_user_io_request) 510121185Ssimokawa{ 511121185Ssimokawa struct ISCI_IO_REQUEST *isci_request = 512121185Ssimokawa (struct ISCI_IO_REQUEST *)scif_user_io_request; 513121185Ssimokawa 514121185Ssimokawa switch (isci_request->ccb->ccb_h.flags & CAM_DIR_MASK) { 515121185Ssimokawa case CAM_DIR_IN: 516121185Ssimokawa return (SCI_IO_REQUEST_DATA_IN); 517121185Ssimokawa case CAM_DIR_OUT: 518121185Ssimokawa return (SCI_IO_REQUEST_DATA_OUT); 519119196Ssimokawa default: 520113584Ssimokawa return (SCI_IO_REQUEST_NO_DATA); 521121185Ssimokawa } 522121185Ssimokawa} 523121185Ssimokawa 524113584Ssimokawa/** 525113584Ssimokawa * @brief This callback method asks the user to provide the address 526113584Ssimokawa * to where the next Scatter-Gather Element is located. 527113584Ssimokawa * 528113584Ssimokawa * Details regarding usage: 529113584Ssimokawa * - Regarding the first SGE: the user should initialize an index, 530121185Ssimokawa * or a pointer, prior to construction of the request that will 531121185Ssimokawa * reference the very first scatter-gather element. This is 532121185Ssimokawa * important since this method is called for every scatter-gather 533113584Ssimokawa * element, including the first element. 534113584Ssimokawa * - Regarding the last SGE: the user should return NULL from this 535113584Ssimokawa * method when this method is called and the SGL has exhausted 536113584Ssimokawa * all elements. 537113584Ssimokawa * 538113584Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 539113584Ssimokawa * IO request object. It is a cookie that allows the user to 540113584Ssimokawa * provide the necessary information for this callback. 541113584Ssimokawa * @param[in] current_sge_address This parameter specifies the address for 542113584Ssimokawa * the current SGE (i.e. the one that has just processed). 543113584Ssimokawa * @param[out] next_sge An address specifying the location for the next scatter 544113584Ssimokawa * gather element to be processed. 545113584Ssimokawa * 546113584Ssimokawa * @return None. 547113584Ssimokawa */ 548113584Ssimokawavoid 549113584Ssimokawascif_cb_io_request_get_next_sge(void * scif_user_io_request, 550121185Ssimokawa void * current_sge_address, void ** next_sge) 551121185Ssimokawa{ 552113584Ssimokawa struct ISCI_IO_REQUEST *isci_request = 553113584Ssimokawa (struct ISCI_IO_REQUEST *)scif_user_io_request; 554113584Ssimokawa 555121185Ssimokawa if (isci_request->current_sge_index == isci_request->num_segments) 556108503Ssimokawa *next_sge = NULL; 557103285Sikob else { 558121185Ssimokawa bus_dma_segment_t *sge = 559121185Ssimokawa &isci_request->sge[isci_request->current_sge_index]; 560121185Ssimokawa 561121185Ssimokawa isci_request->current_sge_index++; 562121185Ssimokawa *next_sge = sge; 563121185Ssimokawa } 564121185Ssimokawa} 565121185Ssimokawa 566121185Ssimokawa/** 567121185Ssimokawa * @brief This callback method asks the user to provide the contents of the 568121185Ssimokawa * "address" field in the Scatter-Gather Element. 569121185Ssimokawa * 570121185Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 571121185Ssimokawa * IO request object. It is a cookie that allows the user to 572121185Ssimokawa * provide the necessary information for this callback. 573121185Ssimokawa * @param[in] sge_address This parameter specifies the address for the 574121185Ssimokawa * SGE from which to retrieve the address field. 575121185Ssimokawa * 576121185Ssimokawa * @return A physical address specifying the contents of the SGE's address 577121185Ssimokawa * field. 578121185Ssimokawa */ 579121185SsimokawaSCI_PHYSICAL_ADDRESS 580121185Ssimokawascif_cb_sge_get_address_field(void *scif_user_io_request, void *sge_address) 581121185Ssimokawa{ 582121185Ssimokawa bus_dma_segment_t *sge = (bus_dma_segment_t *)sge_address; 583121185Ssimokawa 584121185Ssimokawa return ((SCI_PHYSICAL_ADDRESS)sge->ds_addr); 585121185Ssimokawa} 586121185Ssimokawa 587121185Ssimokawa/** 588121185Ssimokawa * @brief This callback method asks the user to provide the contents of the 589121185Ssimokawa * "length" field in the Scatter-Gather Element. 590121185Ssimokawa * 591121185Ssimokawa * @param[in] scif_user_io_request This parameter points to the user's 592121185Ssimokawa * IO request object. It is a cookie that allows the user to 593121185Ssimokawa * provide the necessary information for this callback. 594121185Ssimokawa * @param[in] sge_address This parameter specifies the address for the 595121185Ssimokawa * SGE from which to retrieve the address field. 596121185Ssimokawa * 597121185Ssimokawa * @return This method returns the length field specified inside the SGE 598121185Ssimokawa * referenced by the sge_address parameter. 599121185Ssimokawa */ 600121185Ssimokawauint32_t 601121185Ssimokawascif_cb_sge_get_length_field(void *scif_user_io_request, void *sge_address) 602121185Ssimokawa{ 603121185Ssimokawa bus_dma_segment_t *sge = (bus_dma_segment_t *)sge_address; 604121185Ssimokawa 605121185Ssimokawa return ((uint32_t)sge->ds_len); 606121185Ssimokawa} 607121185Ssimokawa 608121185Ssimokawavoid 609121185Ssimokawaisci_request_construct(struct ISCI_REQUEST *request, 610121185Ssimokawa SCI_CONTROLLER_HANDLE_T scif_controller_handle, 611121185Ssimokawa bus_dma_tag_t io_buffer_dma_tag, bus_addr_t physical_address) 612121185Ssimokawa{ 613114069Ssimokawa 614103285Sikob request->controller_handle = scif_controller_handle; 615103285Sikob request->dma_tag = io_buffer_dma_tag; 616103285Sikob request->physical_address = physical_address; 617103285Sikob bus_dmamap_create(request->dma_tag, 0, &request->dma_map); 618103285Sikob callout_init(&request->timer, CALLOUT_MPSAFE); 619103285Sikob} 620114069Ssimokawa 621114069Ssimokawastatic void 622103285Sikobisci_io_request_construct(void *arg, bus_dma_segment_t *seg, int nseg, 623103285Sikob int error) 624103285Sikob{ 625114069Ssimokawa union ccb *ccb; 626114069Ssimokawa struct ISCI_IO_REQUEST *io_request = (struct ISCI_IO_REQUEST *)arg; 627114069Ssimokawa SCI_REMOTE_DEVICE_HANDLE_T *device = io_request->parent.remote_device_handle; 628114069Ssimokawa SCI_STATUS status; 629114069Ssimokawa 630114069Ssimokawa io_request->num_segments = nseg; 631114069Ssimokawa io_request->sge = seg; 632114223Ssimokawa ccb = io_request->ccb; 633114260Ssimokawa 634114223Ssimokawa /* XXX More cleanup is needed here */ 635114223Ssimokawa if ((nseg == 0) || (error != 0)) { 636114260Ssimokawa ccb->ccb_h.status = CAM_REQ_INVALID; 637114260Ssimokawa xpt_done(ccb); 638114069Ssimokawa return; 639114069Ssimokawa } 640114069Ssimokawa 641114069Ssimokawa status = scif_io_request_construct( 642114069Ssimokawa io_request->parent.controller_handle, 643114069Ssimokawa io_request->parent.remote_device_handle, 644114069Ssimokawa SCI_CONTROLLER_INVALID_IO_TAG, (void *)io_request, 645114069Ssimokawa (void *)((char*)io_request + sizeof(struct ISCI_IO_REQUEST)), 646114069Ssimokawa &io_request->sci_object); 647103285Sikob 648111615Ssimokawa if (status != SCI_SUCCESS) { 649103285Sikob isci_io_request_complete(io_request->parent.controller_handle, 650111615Ssimokawa device, io_request, (SCI_IO_STATUS)status); 651103285Sikob return; 652111615Ssimokawa } 653111615Ssimokawa 654111615Ssimokawa sci_object_set_association(io_request->sci_object, io_request); 655111615Ssimokawa 656122387Ssimokawa bus_dmamap_sync(io_request->parent.dma_tag, io_request->parent.dma_map, 657122387Ssimokawa BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 658122387Ssimokawa 659122387Ssimokawa status = (SCI_STATUS)scif_controller_start_io( 660122387Ssimokawa io_request->parent.controller_handle, device, 661122387Ssimokawa io_request->sci_object, SCI_CONTROLLER_INVALID_IO_TAG); 662122387Ssimokawa 663122387Ssimokawa if (status != SCI_SUCCESS) { 664122387Ssimokawa isci_io_request_complete(io_request->parent.controller_handle, 665122387Ssimokawa device, io_request, (SCI_IO_STATUS)status); 666122387Ssimokawa return; 667122387Ssimokawa } 668122387Ssimokawa 669122387Ssimokawa if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) 670122387Ssimokawa callout_reset(&io_request->parent.timer, ccb->ccb_h.timeout, 671122387Ssimokawa isci_io_request_timeout, io_request); 672122387Ssimokawa} 673122387Ssimokawa 674122387Ssimokawavoid 675122387Ssimokawaisci_io_request_execute_scsi_io(union ccb *ccb, 676122387Ssimokawa struct ISCI_CONTROLLER *controller) 677122387Ssimokawa{ 678114069Ssimokawa struct ccb_scsiio *csio = &ccb->csio; 679114069Ssimokawa target_id_t target_id = ccb->ccb_h.target_id; 680111615Ssimokawa struct ISCI_REQUEST *request; 681111615Ssimokawa struct ISCI_IO_REQUEST *io_request; 682111615Ssimokawa struct ISCI_REMOTE_DEVICE *device = 683111615Ssimokawa controller->remote_device[target_id]; 684111615Ssimokawa int error; 685103285Sikob 686103285Sikob if (device == NULL) { 687103285Sikob ccb->ccb_h.status &= ~CAM_SIM_QUEUED; 688111615Ssimokawa ccb->ccb_h.status &= ~CAM_STATUS_MASK; 689103285Sikob ccb->ccb_h.status |= CAM_DEV_NOT_THERE; 690111615Ssimokawa xpt_done(ccb); 691103285Sikob return; 692103285Sikob } 693103285Sikob 694103285Sikob if (sci_pool_empty(controller->request_pool)) { 695103285Sikob ccb->ccb_h.status &= ~CAM_SIM_QUEUED; 696103285Sikob ccb->ccb_h.status &= ~CAM_STATUS_MASK; 697103285Sikob ccb->ccb_h.status |= CAM_REQUEUE_REQ; 698103285Sikob xpt_freeze_simq(controller->sim, 1); 699121185Ssimokawa controller->is_frozen = TRUE; 700121185Ssimokawa xpt_done(ccb); 701111615Ssimokawa return; 702103285Sikob } 703121185Ssimokawa 704121185Ssimokawa ASSERT(device->is_resetting == FALSE); 705121185Ssimokawa 706103285Sikob sci_pool_get(controller->request_pool, request); 707103285Sikob io_request = (struct ISCI_IO_REQUEST *)request; 708103285Sikob 709111615Ssimokawa io_request->ccb = ccb; 710103285Sikob io_request->current_sge_index = 0; 711111615Ssimokawa io_request->parent.remote_device_handle = device->sci_object; 712111615Ssimokawa 713111615Ssimokawa if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) != 0) 714111615Ssimokawa panic("Unexpected CAM_SCATTER_VALID flag! flags = 0x%x\n", 715111615Ssimokawa ccb->ccb_h.flags); 716111615Ssimokawa 717111615Ssimokawa if ((ccb->ccb_h.flags & CAM_DATA_PHYS) != 0) 718103285Sikob panic("Unexpected CAM_DATA_PHYS flag! flags = 0x%x\n", 719110336Ssimokawa ccb->ccb_h.flags); 720103285Sikob 721113584Ssimokawa error = bus_dmamap_load(io_request->parent.dma_tag, 722111615Ssimokawa io_request->parent.dma_map, csio->data_ptr, csio->dxfer_len, 723103285Sikob isci_io_request_construct, io_request, 0x0); 724111615Ssimokawa 725111615Ssimokawa /* A resource shortage from BUSDMA will be automatically 726111615Ssimokawa * continued at a later point, pushing the CCB processing 727110336Ssimokawa * forward, which will in turn unfreeze the simq. 728110336Ssimokawa */ 729111615Ssimokawa if (error == EINPROGRESS) { 730110336Ssimokawa xpt_freeze_simq(controller->sim, 1); 731103285Sikob ccb->ccb_h.flags |= CAM_RELEASE_SIMQ; 732103285Sikob } 733103285Sikob} 734103285Sikob 735103285Sikobvoid 736103285Sikobisci_io_request_timeout(void *arg) 737103285Sikob{ 738103285Sikob struct ISCI_IO_REQUEST *request = (struct ISCI_IO_REQUEST *)arg; 739103285Sikob struct ISCI_REMOTE_DEVICE *remote_device = (struct ISCI_REMOTE_DEVICE *) 740111615Ssimokawa sci_object_get_association(request->parent.remote_device_handle); 741103285Sikob struct ISCI_CONTROLLER *controller = remote_device->domain->controller; 742111615Ssimokawa 743111615Ssimokawa mtx_lock(&controller->lock); 744103285Sikob isci_remote_device_reset(remote_device, NULL); 745111615Ssimokawa mtx_unlock(&controller->lock); 746103285Sikob} 747103285Sikob 748103285Sikob#if __FreeBSD_version >= 900026 749103285Sikob/** 750103285Sikob * @brief This callback method gets the size of and pointer to the buffer 751103285Sikob * (if any) containing the request buffer for an SMP request. 752103285Sikob * 753103285Sikob * @param[in] core_request This parameter specifies the SCI core's request 754103285Sikob * object associated with the SMP request. 755103285Sikob * @param[out] smp_request_buffer This parameter returns a pointer to the 756103285Sikob * payload portion of the SMP request - i.e. everything after 757103285Sikob * the SMP request header. 758103285Sikob * 759103285Sikob * @return Size of the request buffer in bytes. This does *not* include 760103285Sikob * the size of the SMP request header. 761113584Ssimokawa */ 762113584Ssimokawastatic uint32_t 763113584Ssimokawasmp_io_request_cb_get_request_buffer(SCI_IO_REQUEST_HANDLE_T core_request, 764113584Ssimokawa uint8_t ** smp_request_buffer) 765113584Ssimokawa{ 766113584Ssimokawa struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) 767113584Ssimokawa sci_object_get_association(sci_object_get_association(core_request)); 768113584Ssimokawa 769124145Ssimokawa *smp_request_buffer = isci_request->ccb->smpio.smp_request + 770124145Ssimokawa sizeof(SMP_REQUEST_HEADER_T); 771124145Ssimokawa 772124145Ssimokawa return (isci_request->ccb->smpio.smp_request_len - 773122387Ssimokawa sizeof(SMP_REQUEST_HEADER_T)); 774113584Ssimokawa} 775113584Ssimokawa 776113584Ssimokawa/** 777103285Sikob * @brief This callback method gets the SMP function for an SMP request. 778103285Sikob * 779103285Sikob * @param[in] core_request This parameter specifies the SCI core's request 780103285Sikob * object associated with the SMP request. 781103285Sikob * 782103285Sikob * @return SMP function for the SMP request. 783103285Sikob */ 784111199Ssimokawastatic uint8_t 785111199Ssimokawasmp_io_request_cb_get_function(SCI_IO_REQUEST_HANDLE_T core_request) 786103285Sikob{ 787122387Ssimokawa struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) 788122387Ssimokawa sci_object_get_association(sci_object_get_association(core_request)); 789122387Ssimokawa SMP_REQUEST_HEADER_T *header = 790122387Ssimokawa (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request; 791122387Ssimokawa 792122387Ssimokawa return (header->function); 793122387Ssimokawa} 794111615Ssimokawa 795111615Ssimokawa/** 796103285Sikob * @brief This callback method gets the SMP frame type for an SMP request. 797111615Ssimokawa * 798103285Sikob * @param[in] core_request This parameter specifies the SCI core's request 799103285Sikob * object associated with the SMP request. 800103285Sikob * 801110193Ssimokawa * @return SMP frame type for the SMP request. 802110193Ssimokawa */ 803110193Ssimokawastatic uint8_t 804121185Ssimokawasmp_io_request_cb_get_frame_type(SCI_IO_REQUEST_HANDLE_T core_request) 805103285Sikob{ 806110145Ssimokawa struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) 807121185Ssimokawa sci_object_get_association(sci_object_get_association(core_request)); 808103285Sikob SMP_REQUEST_HEADER_T *header = 809103285Sikob (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request; 810103285Sikob 811110193Ssimokawa return (header->smp_frame_type); 812103285Sikob} 813103285Sikob 814103285Sikob/** 815114069Ssimokawa * @brief This callback method gets the allocated response length for an SMP request. 816103285Sikob * 817114069Ssimokawa * @param[in] core_request This parameter specifies the SCI core's request 818114069Ssimokawa * object associated with the SMP request. 819103285Sikob * 820111615Ssimokawa * @return Allocated response length for the SMP request. 821103285Sikob */ 822103285Sikobstatic uint8_t 823103285Sikobsmp_io_request_cb_get_allocated_response_length( 824103285Sikob SCI_IO_REQUEST_HANDLE_T core_request) 825103285Sikob{ 826103285Sikob struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) 827103285Sikob sci_object_get_association(sci_object_get_association(core_request)); 828103285Sikob SMP_REQUEST_HEADER_T *header = 829103285Sikob (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request; 830103285Sikob 831103285Sikob return (header->allocated_response_length); 832103285Sikob} 833103285Sikob 834103285Sikobstatic SCI_STATUS 835103285Sikobisci_smp_request_construct(struct ISCI_IO_REQUEST *request) 836103285Sikob{ 837103285Sikob SCI_STATUS status; 838111615Ssimokawa SCIC_SMP_PASSTHRU_REQUEST_CALLBACKS_T callbacks; 839121185Ssimokawa 840121185Ssimokawa status = scif_request_construct(request->parent.controller_handle, 841103285Sikob request->parent.remote_device_handle, SCI_CONTROLLER_INVALID_IO_TAG, 842124145Ssimokawa (void *)request, 843124145Ssimokawa (void *)((char*)request + sizeof(struct ISCI_IO_REQUEST)), 844103285Sikob &request->sci_object); 845103285Sikob 846103285Sikob if (status == SCI_SUCCESS) { 847103285Sikob callbacks.scic_cb_smp_passthru_get_request = 848103285Sikob &smp_io_request_cb_get_request_buffer; 849113584Ssimokawa callbacks.scic_cb_smp_passthru_get_function = 850103285Sikob &smp_io_request_cb_get_function; 851103285Sikob callbacks.scic_cb_smp_passthru_get_frame_type = 852113584Ssimokawa &smp_io_request_cb_get_frame_type; 853103285Sikob callbacks.scic_cb_smp_passthru_get_allocated_response_length = 854103285Sikob &smp_io_request_cb_get_allocated_response_length; 855103285Sikob 856113584Ssimokawa /* create the smp passthrough part of the io request */ 857113584Ssimokawa status = scic_io_request_construct_smp_pass_through( 858113584Ssimokawa scif_io_request_get_scic_handle(request->sci_object), 859113584Ssimokawa &callbacks); 860103285Sikob } 861103285Sikob 862103285Sikob return (status); 863103285Sikob} 864113584Ssimokawa 865113584Ssimokawavoid 866113584Ssimokawaisci_io_request_execute_smp_io(union ccb *ccb, 867113584Ssimokawa struct ISCI_CONTROLLER *controller) 868113584Ssimokawa{ 869113584Ssimokawa SCI_STATUS status; 870113584Ssimokawa target_id_t target_id = ccb->ccb_h.target_id; 871113584Ssimokawa struct ISCI_REQUEST *request; 872113584Ssimokawa struct ISCI_IO_REQUEST *io_request; 873113584Ssimokawa SCI_REMOTE_DEVICE_HANDLE_T smp_device_handle; 874113584Ssimokawa struct ISCI_REMOTE_DEVICE *end_device = controller->remote_device[target_id]; 875113584Ssimokawa 876113584Ssimokawa /* SMP commands are sent to an end device, because SMP devices are not 877103285Sikob * exposed to the kernel. It is our responsibility to use this method 878114732Ssimokawa * to get the SMP device that contains the specified end device. If 879103285Sikob * the device is direct-attached, the handle will come back NULL, and 880114732Ssimokawa * we'll just fail the SMP_IO with DEV_NOT_THERE. 881114732Ssimokawa */ 882114732Ssimokawa scif_remote_device_get_containing_device(end_device->sci_object, 883114732Ssimokawa &smp_device_handle); 884114732Ssimokawa 885114732Ssimokawa if (smp_device_handle == NULL) { 886114732Ssimokawa ccb->ccb_h.status &= ~CAM_SIM_QUEUED; 887114732Ssimokawa ccb->ccb_h.status &= ~CAM_STATUS_MASK; 888114732Ssimokawa ccb->ccb_h.status |= CAM_DEV_NOT_THERE; 889114732Ssimokawa xpt_done(ccb); 890121185Ssimokawa return; 891121185Ssimokawa } 892121185Ssimokawa 893114732Ssimokawa if (sci_pool_empty(controller->request_pool)) { 894114732Ssimokawa ccb->ccb_h.status &= ~CAM_SIM_QUEUED; 895114732Ssimokawa ccb->ccb_h.status &= ~CAM_STATUS_MASK; 896114732Ssimokawa ccb->ccb_h.status |= CAM_REQUEUE_REQ; 897114732Ssimokawa xpt_freeze_simq(controller->sim, 1); 898114732Ssimokawa controller->is_frozen = TRUE; 899114732Ssimokawa xpt_done(ccb); 900114732Ssimokawa return; 901114732Ssimokawa } 902114732Ssimokawa 903114732Ssimokawa ASSERT(device->is_resetting == FALSE); 904114732Ssimokawa 905114732Ssimokawa sci_pool_get(controller->request_pool, request); 906114732Ssimokawa io_request = (struct ISCI_IO_REQUEST *)request; 907114732Ssimokawa 908114732Ssimokawa io_request->ccb = ccb; 909120660Ssimokawa io_request->parent.remote_device_handle = smp_device_handle; 910114732Ssimokawa 911114732Ssimokawa status = isci_smp_request_construct(io_request); 912114732Ssimokawa 913114732Ssimokawa if (status != SCI_SUCCESS) { 914114732Ssimokawa isci_io_request_complete(controller->scif_controller_handle, 915114732Ssimokawa smp_device_handle, io_request, (SCI_IO_STATUS)status); 916114732Ssimokawa return; 917114732Ssimokawa } 918114732Ssimokawa 919103285Sikob sci_object_set_association(io_request->sci_object, io_request); 920114732Ssimokawa 921114732Ssimokawa status = (SCI_STATUS) scif_controller_start_io( 922103285Sikob controller->scif_controller_handle, smp_device_handle, 923114732Ssimokawa io_request->sci_object, SCI_CONTROLLER_INVALID_IO_TAG); 924114732Ssimokawa 925103285Sikob if (status != SCI_SUCCESS) { 926114732Ssimokawa isci_io_request_complete(controller->scif_controller_handle, 927103285Sikob smp_device_handle, io_request, (SCI_IO_STATUS)status); 928114732Ssimokawa return; 929113584Ssimokawa } 930114732Ssimokawa 931114732Ssimokawa if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) 932114732Ssimokawa callout_reset(&io_request->parent.timer, ccb->ccb_h.timeout, 933114732Ssimokawa isci_io_request_timeout, request); 934114732Ssimokawa} 935114732Ssimokawa#endif 936114732Ssimokawa