2 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <dev/isci/isci.h>
38 #include <cam/scsi/scsi_all.h>
39 #include <cam/scsi/scsi_message.h>
41 #include <dev/isci/scil/intel_sas.h>
43 #include <dev/isci/scil/sci_util.h>
45 #include <dev/isci/scil/scif_io_request.h>
46 #include <dev/isci/scil/scif_controller.h>
47 #include <dev/isci/scil/scif_remote_device.h>
48 #include <dev/isci/scil/scif_user_callback.h>
50 #include <dev/isci/scil/scic_io_request.h>
51 #include <dev/isci/scil/scic_user_callback.h>
54 * @brief This user callback will inform the user that an IO request has
57 * @param[in] controller This parameter specifies the controller on
58 * which the IO request is completing.
59 * @param[in] remote_device This parameter specifies the remote device on
60 * which this request is completing.
61 * @param[in] io_request This parameter specifies the IO request that has
63 * @param[in] completion_status This parameter specifies the results of
64 * the IO request operation. SCI_IO_SUCCESS indicates
65 * successful completion.
70 scif_cb_io_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller,
71 SCI_REMOTE_DEVICE_HANDLE_T remote_device,
72 SCI_IO_REQUEST_HANDLE_T io_request, SCI_IO_STATUS completion_status)
74 struct ISCI_IO_REQUEST *isci_request =
75 (struct ISCI_IO_REQUEST *)sci_object_get_association(io_request);
77 scif_controller_complete_io(scif_controller, remote_device, io_request);
78 isci_io_request_complete(scif_controller, remote_device, isci_request,
83 isci_io_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller,
84 SCI_REMOTE_DEVICE_HANDLE_T remote_device,
85 struct ISCI_IO_REQUEST *isci_request, SCI_IO_STATUS completion_status)
87 struct ISCI_CONTROLLER *isci_controller;
88 struct ISCI_REMOTE_DEVICE *isci_remote_device;
91 struct ccb_scsiio *csio;
94 isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(scif_controller);
96 (struct ISCI_REMOTE_DEVICE *) sci_object_get_association(remote_device);
98 ccb = isci_request->ccb;
100 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
102 switch (completion_status) {
104 case SCI_IO_SUCCESS_COMPLETE_BEFORE_START:
105 if (ccb->ccb_h.func_code == XPT_SMP_IO) {
107 scif_io_request_get_response_iu_address(
108 isci_request->sci_object);
110 memcpy(ccb->smpio.smp_response, smp_response,
111 ccb->smpio.smp_response_len);
113 ccb->ccb_h.status |= CAM_REQ_CMP;
116 case SCI_IO_SUCCESS_IO_DONE_EARLY:
117 ccb->ccb_h.status |= CAM_REQ_CMP;
118 ccb->csio.resid = ccb->csio.dxfer_len -
119 scif_io_request_get_number_of_bytes_transferred(
120 isci_request->sci_object);
123 case SCI_IO_FAILURE_RESPONSE_VALID:
125 SCI_SSP_RESPONSE_IU_T * response_buffer;
126 uint32_t sense_length;
127 int error_code, sense_key, asc, ascq;
129 response_buffer = (SCI_SSP_RESPONSE_IU_T *)
130 scif_io_request_get_response_iu_address(
131 isci_request->sci_object);
133 sense_length = sci_ssp_get_sense_data_length(
134 response_buffer->sense_data_length);
136 sense_length = MIN(csio->sense_len, sense_length);
138 memcpy(&csio->sense_data, response_buffer->data, sense_length);
140 csio->sense_resid = csio->sense_len - sense_length;
141 csio->scsi_status = response_buffer->status;
142 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
143 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
144 scsi_extract_sense( &csio->sense_data, &error_code, &sense_key,
146 isci_log_message(1, "ISCI",
147 "isci: bus=%x target=%x lun=%x cdb[0]=%x status=%x key=%x asc=%x ascq=%x\n",
148 ccb->ccb_h.path_id, ccb->ccb_h.target_id,
149 ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio),
150 csio->scsi_status, sense_key, asc, ascq);
154 case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
155 isci_remote_device_reset(isci_remote_device, NULL);
156 ccb->ccb_h.status |= CAM_REQ_TERMIO;
157 isci_log_message(0, "ISCI",
158 "isci: bus=%x target=%x lun=%x cdb[0]=%x remote device reset required\n",
159 ccb->ccb_h.path_id, ccb->ccb_h.target_id,
160 ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio));
163 case SCI_IO_FAILURE_TERMINATED:
164 ccb->ccb_h.status |= CAM_REQ_TERMIO;
165 isci_log_message(0, "ISCI",
166 "isci: bus=%x target=%x lun=%x cdb[0]=%x terminated\n",
167 ccb->ccb_h.path_id, ccb->ccb_h.target_id,
168 ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio));
171 case SCI_IO_FAILURE_INVALID_STATE:
172 case SCI_IO_FAILURE_INSUFFICIENT_RESOURCES:
173 complete_ccb = FALSE;
176 case SCI_IO_FAILURE_INVALID_REMOTE_DEVICE:
177 ccb->ccb_h.status |= CAM_DEV_NOT_THERE;
180 case SCI_IO_FAILURE_NO_NCQ_TAG_AVAILABLE:
182 struct ccb_relsim ccb_relsim;
183 struct cam_path *path;
185 xpt_create_path(&path, NULL,
186 cam_sim_path(isci_controller->sim),
187 isci_remote_device->index, 0);
189 memset(&ccb_relsim, 0, sizeof(ccb_relsim));
190 xpt_setup_ccb(&ccb_relsim.ccb_h, path, 5);
191 ccb_relsim.ccb_h.func_code = XPT_REL_SIMQ;
192 ccb_relsim.ccb_h.flags = CAM_DEV_QFREEZE;
193 ccb_relsim.release_flags = RELSIM_ADJUST_OPENINGS;
194 ccb_relsim.openings =
195 scif_remote_device_get_max_queue_depth(remote_device);
196 xpt_action((union ccb *)&ccb_relsim);
198 complete_ccb = FALSE;
203 case SCI_IO_FAILURE_REQUIRES_SCSI_ABORT:
204 case SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL:
205 case SCI_IO_FAILURE_PROTOCOL_VIOLATION:
206 case SCI_IO_FAILURE_INVALID_PARAMETER_VALUE:
207 case SCI_IO_FAILURE_CONTROLLER_SPECIFIC_ERR:
209 isci_log_message(1, "ISCI",
210 "isci: bus=%x target=%x lun=%x cdb[0]=%x completion status=%x\n",
211 ccb->ccb_h.path_id, ccb->ccb_h.target_id,
212 ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio),
214 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
218 callout_stop(&isci_request->parent.timer);
219 bus_dmamap_sync(isci_request->parent.dma_tag,
220 isci_request->parent.dma_map,
221 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
223 bus_dmamap_unload(isci_request->parent.dma_tag,
224 isci_request->parent.dma_map);
226 isci_request->ccb = NULL;
228 sci_pool_put(isci_controller->request_pool,
229 (struct ISCI_REQUEST *)isci_request);
232 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
233 /* ccb will be completed with some type of non-success
234 * status. So temporarily freeze the queue until the
235 * upper layers can act on the status. The
236 * CAM_DEV_QFRZN flag will then release the queue
237 * after the status is acted upon.
239 ccb->ccb_h.status |= CAM_DEV_QFRZN;
240 xpt_freeze_devq(ccb->ccb_h.path, 1);
243 if (ccb->ccb_h.status & CAM_SIM_QUEUED) {
245 KASSERT(ccb == isci_remote_device->queued_ccb_in_progress,
246 ("multiple internally queued ccbs in flight"));
248 TAILQ_REMOVE(&isci_remote_device->queued_ccbs,
249 &ccb->ccb_h, sim_links.tqe);
250 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
253 * This CCB that was in the queue was completed, so
254 * set the in_progress pointer to NULL denoting that
255 * we can retry another CCB from the queue. We only
256 * allow one CCB at a time from the queue to be
257 * in progress so that we can effectively maintain
260 isci_remote_device->queued_ccb_in_progress = NULL;
263 if (isci_remote_device->frozen_lun_mask != 0) {
264 isci_remote_device_release_device_queue(isci_remote_device);
269 if (isci_controller->is_frozen == TRUE) {
270 isci_controller->is_frozen = FALSE;
271 xpt_release_simq(isci_controller->sim, TRUE);
274 isci_remote_device_freeze_lun_queue(isci_remote_device,
275 ccb->ccb_h.target_lun);
277 if (ccb->ccb_h.status & CAM_SIM_QUEUED) {
279 KASSERT(ccb == isci_remote_device->queued_ccb_in_progress,
280 ("multiple internally queued ccbs in flight"));
283 * Do nothing, CCB is already on the device's queue.
284 * We leave it on the queue, to be retried again
285 * next time a CCB on this device completes, or we
286 * get a ready notification for this device.
288 isci_log_message(1, "ISCI", "already queued %p %x\n",
289 ccb, scsiio_cdb_ptr(csio));
291 isci_remote_device->queued_ccb_in_progress = NULL;
294 isci_log_message(1, "ISCI", "queue %p %x\n", ccb,
295 scsiio_cdb_ptr(csio));
296 ccb->ccb_h.status |= CAM_SIM_QUEUED;
298 TAILQ_INSERT_TAIL(&isci_remote_device->queued_ccbs,
299 &ccb->ccb_h, sim_links.tqe);
305 * @brief This callback method asks the user to provide the physical
306 * address for the supplied virtual address when building an
309 * @param[in] controller This parameter is the core controller object
311 * @param[in] io_request This parameter is the io request object handle
312 * for which the physical address is being requested.
313 * @param[in] virtual_address This parameter is the virtual address which
314 * is to be returned as a physical address.
315 * @param[out] physical_address The physical address for the supplied virtual
321 scic_cb_io_request_get_physical_address(SCI_CONTROLLER_HANDLE_T controller,
322 SCI_IO_REQUEST_HANDLE_T io_request, void *virtual_address,
323 SCI_PHYSICAL_ADDRESS *physical_address)
325 SCI_IO_REQUEST_HANDLE_T scif_request =
326 sci_object_get_association(io_request);
327 struct ISCI_REQUEST *isci_request =
328 sci_object_get_association(scif_request);
330 if(isci_request != NULL) {
331 /* isci_request is not NULL, meaning this is a request initiated
332 * by CAM or the isci layer (i.e. device reset for I/O
333 * timeout). Therefore we can calculate the physical address
334 * based on the address we stored in the struct ISCI_REQUEST
337 *physical_address = isci_request->physical_address +
338 (uintptr_t)virtual_address -
339 (uintptr_t)isci_request;
341 /* isci_request is NULL, meaning this is a request generated
342 * internally by SCIL (i.e. for SMP requests or NCQ error
343 * recovery). Therefore we calculate the physical address
344 * based on the controller's uncached controller memory buffer,
345 * since we know that this is what SCIL uses for internal
346 * framework requests.
348 SCI_CONTROLLER_HANDLE_T scif_controller =
349 (SCI_CONTROLLER_HANDLE_T) sci_object_get_association(controller);
350 struct ISCI_CONTROLLER *isci_controller =
351 (struct ISCI_CONTROLLER *)sci_object_get_association(scif_controller);
352 U64 virt_addr_offset = (uintptr_t)virtual_address -
353 (U64)isci_controller->uncached_controller_memory.virtual_address;
356 isci_controller->uncached_controller_memory.physical_address
362 * @brief This callback method asks the user to provide the address for
363 * the command descriptor block (CDB) associated with this IO request.
365 * @param[in] scif_user_io_request This parameter points to the user's
366 * IO request object. It is a cookie that allows the user to
367 * provide the necessary information for this callback.
369 * @return This method returns the virtual address of the CDB.
372 scif_cb_io_request_get_cdb_address(void * scif_user_io_request)
374 struct ISCI_IO_REQUEST *isci_request =
375 (struct ISCI_IO_REQUEST *)scif_user_io_request;
377 return (scsiio_cdb_ptr(&isci_request->ccb->csio));
381 * @brief This callback method asks the user to provide the length of
382 * the command descriptor block (CDB) associated with this IO request.
384 * @param[in] scif_user_io_request This parameter points to the user's
385 * IO request object. It is a cookie that allows the user to
386 * provide the necessary information for this callback.
388 * @return This method returns the length of the CDB.
391 scif_cb_io_request_get_cdb_length(void * scif_user_io_request)
393 struct ISCI_IO_REQUEST *isci_request =
394 (struct ISCI_IO_REQUEST *)scif_user_io_request;
396 return (isci_request->ccb->csio.cdb_len);
400 * @brief This callback method asks the user to provide the Logical Unit (LUN)
401 * associated with this IO request.
403 * @note The contents of the value returned from this callback are defined
404 * by the protocol standard (e.g. T10 SAS specification). Please
405 * refer to the transport command information unit description
406 * in the associated standard.
408 * @param[in] scif_user_io_request This parameter points to the user's
409 * IO request object. It is a cookie that allows the user to
410 * provide the necessary information for this callback.
412 * @return This method returns the LUN associated with this request.
415 scif_cb_io_request_get_lun(void * scif_user_io_request)
417 struct ISCI_IO_REQUEST *isci_request =
418 (struct ISCI_IO_REQUEST *)scif_user_io_request;
420 return (isci_request->ccb->ccb_h.target_lun);
424 * @brief This callback method asks the user to provide the task attribute
425 * associated with this IO request.
427 * @note The contents of the value returned from this callback are defined
428 * by the protocol standard (e.g. T10 SAS specification). Please
429 * refer to the transport command information unit description
430 * in the associated standard.
432 * @param[in] scif_user_io_request This parameter points to the user's
433 * IO request object. It is a cookie that allows the user to
434 * provide the necessary information for this callback.
436 * @return This method returns the task attribute associated with this
440 scif_cb_io_request_get_task_attribute(void * scif_user_io_request)
442 struct ISCI_IO_REQUEST *isci_request =
443 (struct ISCI_IO_REQUEST *)scif_user_io_request;
444 uint32_t task_attribute;
446 if((isci_request->ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0)
447 switch(isci_request->ccb->csio.tag_action) {
448 case MSG_HEAD_OF_Q_TAG:
449 task_attribute = SCI_SAS_HEAD_OF_QUEUE_ATTRIBUTE;
452 case MSG_ORDERED_Q_TAG:
453 task_attribute = SCI_SAS_ORDERED_ATTRIBUTE;
457 task_attribute = SCI_SAS_ACA_ATTRIBUTE;
461 task_attribute = SCI_SAS_SIMPLE_ATTRIBUTE;
465 task_attribute = SCI_SAS_SIMPLE_ATTRIBUTE;
467 return (task_attribute);
471 * @brief This callback method asks the user to provide the command priority
472 * associated with this IO request.
474 * @note The contents of the value returned from this callback are defined
475 * by the protocol standard (e.g. T10 SAS specification). Please
476 * refer to the transport command information unit description
477 * in the associated standard.
479 * @param[in] scif_user_io_request This parameter points to the user's
480 * IO request object. It is a cookie that allows the user to
481 * provide the necessary information for this callback.
483 * @return This method returns the command priority associated with this
487 scif_cb_io_request_get_command_priority(void * scif_user_io_request)
493 * @brief This method simply returns the virtual address associated
494 * with the scsi_io and byte_offset supplied parameters.
496 * @note This callback is not utilized in the fast path. The expectation
497 * is that this method is utilized for items such as SCSI to ATA
498 * translation for commands like INQUIRY, READ CAPACITY, etc.
500 * @param[in] scif_user_io_request This parameter points to the user's
501 * IO request object. It is a cookie that allows the user to
502 * provide the necessary information for this callback.
503 * @param[in] byte_offset This parameter specifies the offset into the data
504 * buffers pointed to by the SGL. The byte offset starts at 0
505 * and continues until the last byte pointed to be the last SGL
508 * @return A virtual address pointer to the location specified by the
512 scif_cb_io_request_get_virtual_address_from_sgl(void * scif_user_io_request,
513 uint32_t byte_offset)
515 struct ISCI_IO_REQUEST *isci_request;
519 isci_request = scif_user_io_request;
520 ccb = isci_request->ccb;
523 * This callback is only invoked for SCSI/ATA translation of
524 * PIO commands such as INQUIRY and READ_CAPACITY, to allow
525 * the driver to write the translated data directly into the
526 * data buffer. It is never invoked for READ/WRITE commands.
527 * The driver currently assumes only READ/WRITE commands will
530 * As a safeguard against future changes to unmapped commands,
531 * add an explicit panic here should the DATA_MASK != VADDR.
532 * Otherwise, we would return some garbage pointer back to the
533 * caller which would result in a panic or more subtle data
534 * corruption later on.
536 if ((ccb->ccb_h.flags & CAM_DATA_MASK) != CAM_DATA_VADDR)
537 panic("%s: requesting pointer into unmapped ccb", __func__);
539 return (ccb->csio.data_ptr + byte_offset);
543 * @brief This callback method asks the user to provide the number of
544 * bytes to be transferred as part of this request.
546 * @param[in] scif_user_io_request This parameter points to the user's
547 * IO request object. It is a cookie that allows the user to
548 * provide the necessary information for this callback.
550 * @return This method returns the number of payload data bytes to be
551 * transferred for this IO request.
554 scif_cb_io_request_get_transfer_length(void * scif_user_io_request)
556 struct ISCI_IO_REQUEST *isci_request =
557 (struct ISCI_IO_REQUEST *)scif_user_io_request;
559 return (isci_request->ccb->csio.dxfer_len);
564 * @brief This callback method asks the user to provide the data direction
567 * @param[in] scif_user_io_request This parameter points to the user's
568 * IO request object. It is a cookie that allows the user to
569 * provide the necessary information for this callback.
571 * @return This method returns the value of SCI_IO_REQUEST_DATA_OUT,
572 * SCI_IO_REQUEST_DATA_IN, or SCI_IO_REQUEST_NO_DATA.
574 SCI_IO_REQUEST_DATA_DIRECTION
575 scif_cb_io_request_get_data_direction(void * scif_user_io_request)
577 struct ISCI_IO_REQUEST *isci_request =
578 (struct ISCI_IO_REQUEST *)scif_user_io_request;
580 switch (isci_request->ccb->ccb_h.flags & CAM_DIR_MASK) {
582 return (SCI_IO_REQUEST_DATA_IN);
584 return (SCI_IO_REQUEST_DATA_OUT);
586 return (SCI_IO_REQUEST_NO_DATA);
591 * @brief This callback method asks the user to provide the address
592 * to where the next Scatter-Gather Element is located.
594 * Details regarding usage:
595 * - Regarding the first SGE: the user should initialize an index,
596 * or a pointer, prior to construction of the request that will
597 * reference the very first scatter-gather element. This is
598 * important since this method is called for every scatter-gather
599 * element, including the first element.
600 * - Regarding the last SGE: the user should return NULL from this
601 * method when this method is called and the SGL has exhausted
604 * @param[in] scif_user_io_request This parameter points to the user's
605 * IO request object. It is a cookie that allows the user to
606 * provide the necessary information for this callback.
607 * @param[in] current_sge_address This parameter specifies the address for
608 * the current SGE (i.e. the one that has just processed).
609 * @param[out] next_sge An address specifying the location for the next scatter
610 * gather element to be processed.
615 scif_cb_io_request_get_next_sge(void * scif_user_io_request,
616 void * current_sge_address, void ** next_sge)
618 struct ISCI_IO_REQUEST *isci_request =
619 (struct ISCI_IO_REQUEST *)scif_user_io_request;
621 if (isci_request->current_sge_index == isci_request->num_segments)
624 bus_dma_segment_t *sge =
625 &isci_request->sge[isci_request->current_sge_index];
627 isci_request->current_sge_index++;
633 * @brief This callback method asks the user to provide the contents of the
634 * "address" field in the Scatter-Gather Element.
636 * @param[in] scif_user_io_request This parameter points to the user's
637 * IO request object. It is a cookie that allows the user to
638 * provide the necessary information for this callback.
639 * @param[in] sge_address This parameter specifies the address for the
640 * SGE from which to retrieve the address field.
642 * @return A physical address specifying the contents of the SGE's address
646 scif_cb_sge_get_address_field(void *scif_user_io_request, void *sge_address)
648 bus_dma_segment_t *sge = (bus_dma_segment_t *)sge_address;
650 return ((SCI_PHYSICAL_ADDRESS)sge->ds_addr);
654 * @brief This callback method asks the user to provide the contents of the
655 * "length" field in the Scatter-Gather Element.
657 * @param[in] scif_user_io_request This parameter points to the user's
658 * IO request object. It is a cookie that allows the user to
659 * provide the necessary information for this callback.
660 * @param[in] sge_address This parameter specifies the address for the
661 * SGE from which to retrieve the address field.
663 * @return This method returns the length field specified inside the SGE
664 * referenced by the sge_address parameter.
667 scif_cb_sge_get_length_field(void *scif_user_io_request, void *sge_address)
669 bus_dma_segment_t *sge = (bus_dma_segment_t *)sge_address;
671 return ((uint32_t)sge->ds_len);
675 isci_request_construct(struct ISCI_REQUEST *request,
676 SCI_CONTROLLER_HANDLE_T scif_controller_handle,
677 bus_dma_tag_t io_buffer_dma_tag, bus_addr_t physical_address)
680 request->controller_handle = scif_controller_handle;
681 request->dma_tag = io_buffer_dma_tag;
682 request->physical_address = physical_address;
683 bus_dmamap_create(request->dma_tag, 0, &request->dma_map);
684 callout_init(&request->timer, 1);
688 isci_io_request_construct(void *arg, bus_dma_segment_t *seg, int nseg,
692 struct ISCI_IO_REQUEST *io_request = (struct ISCI_IO_REQUEST *)arg;
693 SCI_REMOTE_DEVICE_HANDLE_T *device = io_request->parent.remote_device_handle;
696 io_request->num_segments = nseg;
697 io_request->sge = seg;
698 ccb = io_request->ccb;
701 ccb->ccb_h.status = CAM_REQ_INVALID;
706 status = scif_io_request_construct(
707 io_request->parent.controller_handle,
708 io_request->parent.remote_device_handle,
709 SCI_CONTROLLER_INVALID_IO_TAG, (void *)io_request,
710 (void *)((char*)io_request + sizeof(struct ISCI_IO_REQUEST)),
711 &io_request->sci_object);
713 if (status != SCI_SUCCESS) {
714 isci_io_request_complete(io_request->parent.controller_handle,
715 device, io_request, (SCI_IO_STATUS)status);
719 sci_object_set_association(io_request->sci_object, io_request);
721 bus_dmamap_sync(io_request->parent.dma_tag, io_request->parent.dma_map,
722 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
724 status = (SCI_STATUS)scif_controller_start_io(
725 io_request->parent.controller_handle, device,
726 io_request->sci_object, SCI_CONTROLLER_INVALID_IO_TAG);
728 if (status != SCI_SUCCESS) {
729 isci_io_request_complete(io_request->parent.controller_handle,
730 device, io_request, (SCI_IO_STATUS)status);
734 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY)
735 callout_reset_sbt(&io_request->parent.timer,
736 SBT_1MS * ccb->ccb_h.timeout, 0, isci_io_request_timeout,
741 isci_io_request_execute_scsi_io(union ccb *ccb,
742 struct ISCI_CONTROLLER *controller)
744 target_id_t target_id = ccb->ccb_h.target_id;
745 struct ISCI_REQUEST *request;
746 struct ISCI_IO_REQUEST *io_request;
747 struct ISCI_REMOTE_DEVICE *device =
748 controller->remote_device[target_id];
751 if (device == NULL) {
752 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
753 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
754 ccb->ccb_h.status |= CAM_DEV_NOT_THERE;
759 if (sci_pool_empty(controller->request_pool)) {
760 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
761 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
762 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
763 xpt_freeze_simq(controller->sim, 1);
764 controller->is_frozen = TRUE;
769 ASSERT(device->is_resetting == FALSE);
771 sci_pool_get(controller->request_pool, request);
772 io_request = (struct ISCI_IO_REQUEST *)request;
774 io_request->ccb = ccb;
775 io_request->current_sge_index = 0;
776 io_request->parent.remote_device_handle = device->sci_object;
778 error = bus_dmamap_load_ccb(io_request->parent.dma_tag,
779 io_request->parent.dma_map, ccb,
780 isci_io_request_construct, io_request, 0x0);
781 /* A resource shortage from BUSDMA will be automatically
782 * continued at a later point, pushing the CCB processing
783 * forward, which will in turn unfreeze the simq.
785 if (error == EINPROGRESS) {
786 xpt_freeze_simq(controller->sim, 1);
787 ccb->ccb_h.flags |= CAM_RELEASE_SIMQ;
792 isci_io_request_timeout(void *arg)
794 struct ISCI_IO_REQUEST *request = (struct ISCI_IO_REQUEST *)arg;
795 struct ISCI_REMOTE_DEVICE *remote_device = (struct ISCI_REMOTE_DEVICE *)
796 sci_object_get_association(request->parent.remote_device_handle);
797 struct ISCI_CONTROLLER *controller = remote_device->domain->controller;
799 mtx_lock(&controller->lock);
800 isci_remote_device_reset(remote_device, NULL);
801 mtx_unlock(&controller->lock);
805 * @brief This callback method gets the size of and pointer to the buffer
806 * (if any) containing the request buffer for an SMP request.
808 * @param[in] core_request This parameter specifies the SCI core's request
809 * object associated with the SMP request.
810 * @param[out] smp_request_buffer This parameter returns a pointer to the
811 * payload portion of the SMP request - i.e. everything after
812 * the SMP request header.
814 * @return Size of the request buffer in bytes. This does *not* include
815 * the size of the SMP request header.
818 smp_io_request_cb_get_request_buffer(SCI_IO_REQUEST_HANDLE_T core_request,
819 uint8_t ** smp_request_buffer)
821 struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)
822 sci_object_get_association(sci_object_get_association(core_request));
824 *smp_request_buffer = isci_request->ccb->smpio.smp_request +
825 sizeof(SMP_REQUEST_HEADER_T);
827 return (isci_request->ccb->smpio.smp_request_len -
828 sizeof(SMP_REQUEST_HEADER_T));
832 * @brief This callback method gets the SMP function for an SMP request.
834 * @param[in] core_request This parameter specifies the SCI core's request
835 * object associated with the SMP request.
837 * @return SMP function for the SMP request.
840 smp_io_request_cb_get_function(SCI_IO_REQUEST_HANDLE_T core_request)
842 struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)
843 sci_object_get_association(sci_object_get_association(core_request));
844 SMP_REQUEST_HEADER_T *header =
845 (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request;
847 return (header->function);
851 * @brief This callback method gets the SMP frame type for an SMP request.
853 * @param[in] core_request This parameter specifies the SCI core's request
854 * object associated with the SMP request.
856 * @return SMP frame type for the SMP request.
859 smp_io_request_cb_get_frame_type(SCI_IO_REQUEST_HANDLE_T core_request)
861 struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)
862 sci_object_get_association(sci_object_get_association(core_request));
863 SMP_REQUEST_HEADER_T *header =
864 (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request;
866 return (header->smp_frame_type);
870 * @brief This callback method gets the allocated response length for an SMP request.
872 * @param[in] core_request This parameter specifies the SCI core's request
873 * object associated with the SMP request.
875 * @return Allocated response length for the SMP request.
878 smp_io_request_cb_get_allocated_response_length(
879 SCI_IO_REQUEST_HANDLE_T core_request)
881 struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)
882 sci_object_get_association(sci_object_get_association(core_request));
883 SMP_REQUEST_HEADER_T *header =
884 (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request;
886 return (header->allocated_response_length);
890 isci_smp_request_construct(struct ISCI_IO_REQUEST *request)
893 SCIC_SMP_PASSTHRU_REQUEST_CALLBACKS_T callbacks;
895 status = scif_request_construct(request->parent.controller_handle,
896 request->parent.remote_device_handle, SCI_CONTROLLER_INVALID_IO_TAG,
898 (void *)((char*)request + sizeof(struct ISCI_IO_REQUEST)),
899 &request->sci_object);
901 if (status == SCI_SUCCESS) {
902 callbacks.scic_cb_smp_passthru_get_request =
903 &smp_io_request_cb_get_request_buffer;
904 callbacks.scic_cb_smp_passthru_get_function =
905 &smp_io_request_cb_get_function;
906 callbacks.scic_cb_smp_passthru_get_frame_type =
907 &smp_io_request_cb_get_frame_type;
908 callbacks.scic_cb_smp_passthru_get_allocated_response_length =
909 &smp_io_request_cb_get_allocated_response_length;
911 /* create the smp passthrough part of the io request */
912 status = scic_io_request_construct_smp_pass_through(
913 scif_io_request_get_scic_handle(request->sci_object),
921 isci_io_request_execute_smp_io(union ccb *ccb,
922 struct ISCI_CONTROLLER *controller)
925 target_id_t target_id = ccb->ccb_h.target_id;
926 struct ISCI_REQUEST *request;
927 struct ISCI_IO_REQUEST *io_request;
928 SCI_REMOTE_DEVICE_HANDLE_T smp_device_handle;
929 struct ISCI_REMOTE_DEVICE *end_device = controller->remote_device[target_id];
931 /* SMP commands are sent to an end device, because SMP devices are not
932 * exposed to the kernel. It is our responsibility to use this method
933 * to get the SMP device that contains the specified end device. If
934 * the device is direct-attached, the handle will come back NULL, and
935 * we'll just fail the SMP_IO with DEV_NOT_THERE.
937 scif_remote_device_get_containing_device(end_device->sci_object,
940 if (smp_device_handle == NULL) {
941 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
942 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
943 ccb->ccb_h.status |= CAM_DEV_NOT_THERE;
948 if (sci_pool_empty(controller->request_pool)) {
949 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
950 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
951 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
952 xpt_freeze_simq(controller->sim, 1);
953 controller->is_frozen = TRUE;
958 ASSERT(device->is_resetting == FALSE);
960 sci_pool_get(controller->request_pool, request);
961 io_request = (struct ISCI_IO_REQUEST *)request;
963 io_request->ccb = ccb;
964 io_request->parent.remote_device_handle = smp_device_handle;
966 status = isci_smp_request_construct(io_request);
968 if (status != SCI_SUCCESS) {
969 isci_io_request_complete(controller->scif_controller_handle,
970 smp_device_handle, io_request, (SCI_IO_STATUS)status);
974 sci_object_set_association(io_request->sci_object, io_request);
976 status = (SCI_STATUS) scif_controller_start_io(
977 controller->scif_controller_handle, smp_device_handle,
978 io_request->sci_object, SCI_CONTROLLER_INVALID_IO_TAG);
980 if (status != SCI_SUCCESS) {
981 isci_io_request_complete(controller->scif_controller_handle,
982 smp_device_handle, io_request, (SCI_IO_STATUS)status);
986 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY)
987 callout_reset_sbt(&io_request->parent.timer,
988 SBT_1MS * ccb->ccb_h.timeout, 0, isci_io_request_timeout,