4 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <dev/isci/isci.h>
37 #include <sys/malloc.h>
39 #include <cam/cam_periph.h>
40 #include <cam/cam_xpt_periph.h>
42 #include <dev/isci/scil/sci_memory_descriptor_list.h>
43 #include <dev/isci/scil/sci_memory_descriptor_list_decorator.h>
45 #include <dev/isci/scil/scif_controller.h>
46 #include <dev/isci/scil/scif_library.h>
47 #include <dev/isci/scil/scif_io_request.h>
48 #include <dev/isci/scil/scif_task_request.h>
49 #include <dev/isci/scil/scif_remote_device.h>
50 #include <dev/isci/scil/scif_domain.h>
51 #include <dev/isci/scil/scif_user_callback.h>
52 #include <dev/isci/scil/scic_sgpio.h>
54 #include <dev/led/led.h>
56 void isci_action(struct cam_sim *sim, union ccb *ccb);
57 void isci_poll(struct cam_sim *sim);
59 #define ccb_sim_ptr sim_priv.entries[0].ptr
62 * @brief This user callback will inform the user that the controller has
63 * had a serious unexpected error. The user should not the error,
64 * disable interrupts, and wait for current ongoing processing to
65 * complete. Subsequently, the user should reset the controller.
67 * @param[in] controller This parameter specifies the controller that had
72 void scif_cb_controller_error(SCI_CONTROLLER_HANDLE_T controller,
73 SCI_CONTROLLER_ERROR error)
76 isci_log_message(0, "ISCI", "scif_cb_controller_error: 0x%x\n",
81 * @brief This user callback will inform the user that the controller has
82 * finished the start process.
84 * @param[in] controller This parameter specifies the controller that was
86 * @param[in] completion_status This parameter specifies the results of
87 * the start operation. SCI_SUCCESS indicates successful
92 void scif_cb_controller_start_complete(SCI_CONTROLLER_HANDLE_T controller,
93 SCI_STATUS completion_status)
96 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
97 sci_object_get_association(controller);
99 isci_controller->is_started = TRUE;
101 /* Set bits for all domains. We will clear them one-by-one once
102 * the domains complete discovery, or return error when calling
103 * scif_domain_discover. Once all bits are clear, we will register
104 * the controller with CAM.
106 isci_controller->initial_discovery_mask = (1 << SCI_MAX_DOMAINS) - 1;
108 for(index = 0; index < SCI_MAX_DOMAINS; index++) {
110 SCI_DOMAIN_HANDLE_T domain =
111 isci_controller->domain[index].sci_object;
113 status = scif_domain_discover(
115 scif_domain_get_suggested_discover_timeout(domain),
119 if (status != SCI_SUCCESS)
121 isci_controller_domain_discovery_complete(
122 isci_controller, &isci_controller->domain[index]);
128 * @brief This user callback will inform the user that the controller has
129 * finished the stop process. Note, after user calls
130 * scif_controller_stop(), before user receives this controller stop
131 * complete callback, user should not expect any callback from
132 * framework, such like scif_cb_domain_change_notification().
134 * @param[in] controller This parameter specifies the controller that was
136 * @param[in] completion_status This parameter specifies the results of
137 * the stop operation. SCI_SUCCESS indicates successful
142 void scif_cb_controller_stop_complete(SCI_CONTROLLER_HANDLE_T controller,
143 SCI_STATUS completion_status)
145 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
146 sci_object_get_association(controller);
148 isci_controller->is_started = FALSE;
152 isci_single_map(void *arg, bus_dma_segment_t *seg, int nseg, int error)
154 SCI_PHYSICAL_ADDRESS *phys_addr = arg;
156 *phys_addr = seg[0].ds_addr;
160 * @brief This method will be invoked to allocate memory dynamically.
162 * @param[in] controller This parameter represents the controller
163 * object for which to allocate memory.
164 * @param[out] mde This parameter represents the memory descriptor to
165 * be filled in by the user that will reference the newly
170 void scif_cb_controller_allocate_memory(SCI_CONTROLLER_HANDLE_T controller,
171 SCI_PHYSICAL_MEMORY_DESCRIPTOR_T *mde)
173 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
174 sci_object_get_association(controller);
177 * Note this routine is only used for buffers needed to translate
178 * SCSI UNMAP commands to ATA DSM commands for SATA disks.
180 * We first try to pull a buffer from the controller's pool, and only
181 * call contigmalloc if one isn't there.
183 if (!sci_pool_empty(isci_controller->unmap_buffer_pool)) {
184 sci_pool_get(isci_controller->unmap_buffer_pool,
185 mde->virtual_address);
187 mde->virtual_address = contigmalloc(PAGE_SIZE,
188 M_ISCI, M_NOWAIT, 0, BUS_SPACE_MAXADDR,
189 mde->constant_memory_alignment, 0);
191 if (mde->virtual_address != NULL)
192 bus_dmamap_load(isci_controller->buffer_dma_tag,
193 NULL, mde->virtual_address, PAGE_SIZE,
194 isci_single_map, &mde->physical_address,
199 * @brief This method will be invoked to allocate memory dynamically.
201 * @param[in] controller This parameter represents the controller
202 * object for which to allocate memory.
203 * @param[out] mde This parameter represents the memory descriptor to
204 * be filled in by the user that will reference the newly
209 void scif_cb_controller_free_memory(SCI_CONTROLLER_HANDLE_T controller,
210 SCI_PHYSICAL_MEMORY_DESCRIPTOR_T * mde)
212 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
213 sci_object_get_association(controller);
216 * Put the buffer back into the controller's buffer pool, rather
217 * than invoking configfree. This helps reduce chance we won't
218 * have buffers available when system is under memory pressure.
220 sci_pool_put(isci_controller->unmap_buffer_pool,
221 mde->virtual_address);
224 void isci_controller_construct(struct ISCI_CONTROLLER *controller,
225 struct isci_softc *isci)
227 SCI_CONTROLLER_HANDLE_T scif_controller_handle;
229 scif_library_allocate_controller(isci->sci_library_handle,
230 &scif_controller_handle);
232 scif_controller_construct(isci->sci_library_handle,
233 scif_controller_handle, NULL);
235 controller->isci = isci;
236 controller->scif_controller_handle = scif_controller_handle;
238 /* This allows us to later use
239 * sci_object_get_association(scif_controller_handle)
240 * inside of a callback routine to get our struct ISCI_CONTROLLER object
242 sci_object_set_association(scif_controller_handle, (void *)controller);
244 controller->is_started = FALSE;
245 controller->is_frozen = FALSE;
246 controller->release_queued_ccbs = FALSE;
247 controller->sim = NULL;
248 controller->initial_discovery_mask = 0;
250 sci_fast_list_init(&controller->pending_device_reset_list);
252 mtx_init(&controller->lock, "isci", NULL, MTX_DEF);
254 uint32_t domain_index;
256 for(domain_index = 0; domain_index < SCI_MAX_DOMAINS; domain_index++) {
257 isci_domain_construct( &controller->domain[domain_index],
258 domain_index, controller);
261 controller->timer_memory = malloc(
262 sizeof(struct ISCI_TIMER) * SCI_MAX_TIMERS, M_ISCI,
265 sci_pool_initialize(controller->timer_pool);
267 struct ISCI_TIMER *timer = (struct ISCI_TIMER *)
268 controller->timer_memory;
270 for ( int i = 0; i < SCI_MAX_TIMERS; i++ ) {
271 sci_pool_put(controller->timer_pool, timer++);
274 sci_pool_initialize(controller->unmap_buffer_pool);
277 static void isci_led_fault_func(void *priv, int onoff)
279 struct ISCI_PHY *phy = priv;
281 /* map onoff to the fault LED */
282 phy->led_fault = onoff;
283 scic_sgpio_update_led_state(phy->handle, 1 << phy->index,
284 phy->led_fault, phy->led_locate, 0);
287 static void isci_led_locate_func(void *priv, int onoff)
289 struct ISCI_PHY *phy = priv;
291 /* map onoff to the locate LED */
292 phy->led_locate = onoff;
293 scic_sgpio_update_led_state(phy->handle, 1 << phy->index,
294 phy->led_fault, phy->led_locate, 0);
297 SCI_STATUS isci_controller_initialize(struct ISCI_CONTROLLER *controller)
299 SCIC_USER_PARAMETERS_T scic_user_parameters;
300 SCI_CONTROLLER_HANDLE_T scic_controller_handle;
302 unsigned long tunable;
305 scic_controller_handle =
306 scif_controller_get_scic_handle(controller->scif_controller_handle);
308 if (controller->isci->oem_parameters_found == TRUE)
310 scic_oem_parameters_set(
311 scic_controller_handle,
312 &controller->oem_parameters,
313 (uint8_t)(controller->oem_parameters_version));
316 scic_user_parameters_get(scic_controller_handle, &scic_user_parameters);
318 if (TUNABLE_ULONG_FETCH("hw.isci.no_outbound_task_timeout", &tunable))
319 scic_user_parameters.sds1.no_outbound_task_timeout =
322 if (TUNABLE_ULONG_FETCH("hw.isci.ssp_max_occupancy_timeout", &tunable))
323 scic_user_parameters.sds1.ssp_max_occupancy_timeout =
326 if (TUNABLE_ULONG_FETCH("hw.isci.stp_max_occupancy_timeout", &tunable))
327 scic_user_parameters.sds1.stp_max_occupancy_timeout =
330 if (TUNABLE_ULONG_FETCH("hw.isci.ssp_inactivity_timeout", &tunable))
331 scic_user_parameters.sds1.ssp_inactivity_timeout =
334 if (TUNABLE_ULONG_FETCH("hw.isci.stp_inactivity_timeout", &tunable))
335 scic_user_parameters.sds1.stp_inactivity_timeout =
338 if (TUNABLE_ULONG_FETCH("hw.isci.max_speed_generation", &tunable))
339 for (i = 0; i < SCI_MAX_PHYS; i++)
340 scic_user_parameters.sds1.phys[i].max_speed_generation =
343 scic_user_parameters_set(scic_controller_handle, &scic_user_parameters);
345 /* Scheduler bug in SCU requires SCIL to reserve some task contexts as a
346 * a workaround - one per domain.
348 controller->queue_depth = SCI_MAX_IO_REQUESTS - SCI_MAX_DOMAINS;
350 if (TUNABLE_INT_FETCH("hw.isci.controller_queue_depth",
351 &controller->queue_depth)) {
352 controller->queue_depth = max(1, min(controller->queue_depth,
353 SCI_MAX_IO_REQUESTS - SCI_MAX_DOMAINS));
356 /* Reserve one request so that we can ensure we have one available TC
357 * to do internal device resets.
359 controller->sim_queue_depth = controller->queue_depth - 1;
361 /* Although we save one TC to do internal device resets, it is possible
362 * we could end up using several TCs for simultaneous device resets
363 * while at the same time having CAM fill our controller queue. To
364 * simulate this condition, and how our driver handles it, we can set
365 * this io_shortage parameter, which will tell CAM that we have a
366 * large queue depth than we really do.
368 uint32_t io_shortage = 0;
369 TUNABLE_INT_FETCH("hw.isci.io_shortage", &io_shortage);
370 controller->sim_queue_depth += io_shortage;
372 /* Attach to CAM using xpt_bus_register now, then immediately freeze
373 * the simq. It will get released later when initial domain discovery
376 controller->has_been_scanned = FALSE;
377 mtx_lock(&controller->lock);
378 isci_controller_attach_to_cam(controller);
379 xpt_freeze_simq(controller->sim, 1);
380 mtx_unlock(&controller->lock);
382 for (i = 0; i < SCI_MAX_PHYS; i++) {
383 controller->phys[i].handle = scic_controller_handle;
384 controller->phys[i].index = i;
387 controller->phys[i].led_fault = 0;
388 sprintf(led_name, "isci.bus%d.port%d.fault", controller->index, i);
389 controller->phys[i].cdev_fault = led_create(isci_led_fault_func,
390 &controller->phys[i], led_name);
393 controller->phys[i].led_locate = 0;
394 sprintf(led_name, "isci.bus%d.port%d.locate", controller->index, i);
395 controller->phys[i].cdev_locate = led_create(isci_led_locate_func,
396 &controller->phys[i], led_name);
399 return (scif_controller_initialize(controller->scif_controller_handle));
402 int isci_controller_allocate_memory(struct ISCI_CONTROLLER *controller)
405 device_t device = controller->isci->device;
406 uint32_t max_segment_size = isci_io_request_get_max_io_size();
408 struct ISCI_MEMORY *uncached_controller_memory =
409 &controller->uncached_controller_memory;
410 struct ISCI_MEMORY *cached_controller_memory =
411 &controller->cached_controller_memory;
412 struct ISCI_MEMORY *request_memory =
413 &controller->request_memory;
414 POINTER_UINT virtual_address;
415 bus_addr_t physical_address;
417 controller->mdl = sci_controller_get_memory_descriptor_list_handle(
418 controller->scif_controller_handle);
420 uncached_controller_memory->size = sci_mdl_decorator_get_memory_size(
421 controller->mdl, SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS);
423 error = isci_allocate_dma_buffer(device, uncached_controller_memory);
428 sci_mdl_decorator_assign_memory( controller->mdl,
429 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS,
430 uncached_controller_memory->virtual_address,
431 uncached_controller_memory->physical_address);
433 cached_controller_memory->size = sci_mdl_decorator_get_memory_size(
435 SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
438 error = isci_allocate_dma_buffer(device, cached_controller_memory);
443 sci_mdl_decorator_assign_memory(controller->mdl,
444 SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS,
445 cached_controller_memory->virtual_address,
446 cached_controller_memory->physical_address);
448 request_memory->size =
449 controller->queue_depth * isci_io_request_get_object_size();
451 error = isci_allocate_dma_buffer(device, request_memory);
456 /* For STP PIO testing, we want to ensure we can force multiple SGLs
457 * since this has been a problem area in SCIL. This tunable parameter
458 * will allow us to force DMA segments to a smaller size, ensuring
459 * that even if a physically contiguous buffer is attached to this
460 * I/O, the DMA subsystem will pass us multiple segments in our DMA
463 TUNABLE_INT_FETCH("hw.isci.max_segment_size", &max_segment_size);
465 /* Create DMA tag for our I/O requests. Then we can create DMA maps based off
466 * of this tag and store them in each of our ISCI_IO_REQUEST objects. This
467 * will enable better performance than creating the DMA maps everytime we get
470 status = bus_dma_tag_create(bus_get_dma_tag(device), 0x1, 0x0,
471 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL,
472 isci_io_request_get_max_io_size(),
473 SCI_MAX_SCATTER_GATHER_ELEMENTS, max_segment_size, 0, NULL, NULL,
474 &controller->buffer_dma_tag);
476 sci_pool_initialize(controller->request_pool);
478 virtual_address = request_memory->virtual_address;
479 physical_address = request_memory->physical_address;
481 for (int i = 0; i < controller->queue_depth; i++) {
482 struct ISCI_REQUEST *request =
483 (struct ISCI_REQUEST *)virtual_address;
485 isci_request_construct(request,
486 controller->scif_controller_handle,
487 controller->buffer_dma_tag, physical_address);
489 sci_pool_put(controller->request_pool, request);
491 virtual_address += isci_request_get_object_size();
492 physical_address += isci_request_get_object_size();
495 uint32_t remote_device_size = sizeof(struct ISCI_REMOTE_DEVICE) +
496 scif_remote_device_get_object_size();
498 controller->remote_device_memory = (uint8_t *) malloc(
499 remote_device_size * SCI_MAX_REMOTE_DEVICES, M_ISCI,
502 sci_pool_initialize(controller->remote_device_pool);
504 uint8_t *remote_device_memory_ptr = controller->remote_device_memory;
506 for (int i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
507 struct ISCI_REMOTE_DEVICE *remote_device =
508 (struct ISCI_REMOTE_DEVICE *)remote_device_memory_ptr;
510 controller->remote_device[i] = NULL;
511 remote_device->index = i;
512 remote_device->is_resetting = FALSE;
513 remote_device->frozen_lun_mask = 0;
514 sci_fast_list_element_init(remote_device,
515 &remote_device->pending_device_reset_element);
516 TAILQ_INIT(&remote_device->queued_ccbs);
517 remote_device->release_queued_ccb = FALSE;
518 remote_device->queued_ccb_in_progress = NULL;
521 * For the first SCI_MAX_DOMAINS device objects, do not put
522 * them in the pool, rather assign them to each domain. This
523 * ensures that any device attached directly to port "i" will
524 * always get CAM target id "i".
526 if (i < SCI_MAX_DOMAINS)
527 controller->domain[i].da_remote_device = remote_device;
529 sci_pool_put(controller->remote_device_pool,
531 remote_device_memory_ptr += remote_device_size;
537 void isci_controller_start(void *controller_handle)
539 struct ISCI_CONTROLLER *controller =
540 (struct ISCI_CONTROLLER *)controller_handle;
541 SCI_CONTROLLER_HANDLE_T scif_controller_handle =
542 controller->scif_controller_handle;
544 scif_controller_start(scif_controller_handle,
545 scif_controller_get_suggested_start_timeout(scif_controller_handle));
547 scic_controller_enable_interrupts(
548 scif_controller_get_scic_handle(controller->scif_controller_handle));
551 void isci_controller_domain_discovery_complete(
552 struct ISCI_CONTROLLER *isci_controller, struct ISCI_DOMAIN *isci_domain)
554 if (!isci_controller->has_been_scanned)
556 /* Controller has not been scanned yet. We'll clear
557 * the discovery bit for this domain, then check if all bits
558 * are now clear. That would indicate that all domains are
559 * done with discovery and we can then proceed with initial
563 isci_controller->initial_discovery_mask &=
564 ~(1 << isci_domain->index);
566 if (isci_controller->initial_discovery_mask == 0) {
567 struct isci_softc *driver = isci_controller->isci;
568 uint8_t next_index = isci_controller->index + 1;
570 isci_controller->has_been_scanned = TRUE;
572 /* Unfreeze simq to allow initial scan to proceed. */
573 xpt_release_simq(isci_controller->sim, TRUE);
575 #if __FreeBSD_version < 800000
576 /* When driver is loaded after boot, we need to
577 * explicitly rescan here for versions <8.0, because
578 * CAM only automatically scans new buses at boot
581 union ccb *ccb = xpt_alloc_ccb_nowait();
583 xpt_create_path(&ccb->ccb_h.path, NULL,
584 cam_sim_path(isci_controller->sim),
585 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
590 if (next_index < driver->controller_count) {
591 /* There are more controllers that need to
592 * start. So start the next one.
594 isci_controller_start(
595 &driver->controllers[next_index]);
599 /* All controllers have been started and completed discovery.
600 * Disestablish the config hook while will signal to the
601 * kernel during boot that it is safe to try to find and
602 * mount the root partition.
604 config_intrhook_disestablish(
605 &driver->config_hook);
611 int isci_controller_attach_to_cam(struct ISCI_CONTROLLER *controller)
613 struct isci_softc *isci = controller->isci;
614 device_t parent = device_get_parent(isci->device);
615 int unit = device_get_unit(isci->device);
616 struct cam_devq *isci_devq = cam_simq_alloc(controller->sim_queue_depth);
618 if(isci_devq == NULL) {
619 isci_log_message(0, "ISCI", "isci_devq is NULL \n");
623 controller->sim = cam_sim_alloc(isci_action, isci_poll, "isci",
624 controller, unit, &controller->lock, controller->sim_queue_depth,
625 controller->sim_queue_depth, isci_devq);
627 if(controller->sim == NULL) {
628 isci_log_message(0, "ISCI", "cam_sim_alloc... fails\n");
629 cam_simq_free(isci_devq);
633 if(xpt_bus_register(controller->sim, parent, controller->index)
635 isci_log_message(0, "ISCI", "xpt_bus_register...fails \n");
636 cam_sim_free(controller->sim, TRUE);
637 mtx_unlock(&controller->lock);
641 if(xpt_create_path(&controller->path, NULL,
642 cam_sim_path(controller->sim), CAM_TARGET_WILDCARD,
643 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
644 isci_log_message(0, "ISCI", "xpt_create_path....fails\n");
645 xpt_bus_deregister(cam_sim_path(controller->sim));
646 cam_sim_free(controller->sim, TRUE);
647 mtx_unlock(&controller->lock);
654 void isci_poll(struct cam_sim *sim)
656 struct ISCI_CONTROLLER *controller =
657 (struct ISCI_CONTROLLER *)cam_sim_softc(sim);
659 isci_interrupt_poll_handler(controller);
662 void isci_action(struct cam_sim *sim, union ccb *ccb)
664 struct ISCI_CONTROLLER *controller =
665 (struct ISCI_CONTROLLER *)cam_sim_softc(sim);
667 switch ( ccb->ccb_h.func_code ) {
670 struct ccb_pathinq *cpi = &ccb->cpi;
671 int bus = cam_sim_bus(sim);
672 ccb->ccb_h.ccb_sim_ptr = sim;
673 cpi->version_num = 1;
674 cpi->hba_inquiry = PI_TAG_ABLE;
675 cpi->target_sprt = 0;
676 cpi->hba_misc = PIM_NOBUSRESET | PIM_SEQSCAN |
678 cpi->hba_eng_cnt = 0;
679 cpi->max_target = SCI_MAX_REMOTE_DEVICES - 1;
680 cpi->max_lun = ISCI_MAX_LUN;
681 #if __FreeBSD_version >= 800102
682 cpi->maxio = isci_io_request_get_max_io_size();
684 cpi->unit_number = cam_sim_unit(sim);
686 cpi->initiator_id = SCI_MAX_REMOTE_DEVICES;
687 cpi->base_transfer_speed = 300000;
688 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
689 strncpy(cpi->hba_vid, "Intel Corp.", HBA_IDLEN);
690 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
691 cpi->transport = XPORT_SAS;
692 cpi->transport_version = 0;
693 cpi->protocol = PROTO_SCSI;
694 cpi->protocol_version = SCSI_REV_SPC2;
695 cpi->ccb_h.status = CAM_REQ_CMP;
699 case XPT_GET_TRAN_SETTINGS:
701 struct ccb_trans_settings *general_settings = &ccb->cts;
702 struct ccb_trans_settings_sas *sas_settings =
703 &general_settings->xport_specific.sas;
704 struct ccb_trans_settings_scsi *scsi_settings =
705 &general_settings->proto_specific.scsi;
706 struct ISCI_REMOTE_DEVICE *remote_device;
708 remote_device = controller->remote_device[ccb->ccb_h.target_id];
710 if (remote_device == NULL) {
711 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
712 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
713 ccb->ccb_h.status |= CAM_DEV_NOT_THERE;
718 general_settings->protocol = PROTO_SCSI;
719 general_settings->transport = XPORT_SAS;
720 general_settings->protocol_version = SCSI_REV_SPC2;
721 general_settings->transport_version = 0;
722 scsi_settings->valid = CTS_SCSI_VALID_TQ;
723 scsi_settings->flags = CTS_SCSI_FLAGS_TAG_ENB;
724 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
725 ccb->ccb_h.status |= CAM_REQ_CMP;
727 sas_settings->bitrate =
728 isci_remote_device_get_bitrate(remote_device);
730 if (sas_settings->bitrate != 0)
731 sas_settings->valid = CTS_SAS_VALID_SPEED;
737 isci_io_request_execute_scsi_io(ccb, controller);
739 #if __FreeBSD_version >= 900026
741 isci_io_request_execute_smp_io(ccb, controller);
744 case XPT_SET_TRAN_SETTINGS:
745 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
746 ccb->ccb_h.status |= CAM_REQ_CMP;
749 case XPT_CALC_GEOMETRY:
750 cam_calc_geometry(&ccb->ccg, /*extended*/1);
755 struct ISCI_REMOTE_DEVICE *remote_device =
756 controller->remote_device[ccb->ccb_h.target_id];
758 if (remote_device != NULL)
759 isci_remote_device_reset(remote_device, ccb);
761 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
762 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
763 ccb->ccb_h.status |= CAM_DEV_NOT_THERE;
769 ccb->ccb_h.status = CAM_REQ_CMP;
773 isci_log_message(0, "ISCI", "Unhandled func_code 0x%x\n",
774 ccb->ccb_h.func_code);
775 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
776 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
777 ccb->ccb_h.status |= CAM_REQ_INVALID;
784 * Unfortunately, SCIL doesn't cleanly handle retry conditions.
785 * CAM_REQUEUE_REQ works only when no one is using the pass(4) interface. So
786 * when SCIL denotes an I/O needs to be retried (typically because of mixing
787 * tagged/non-tagged ATA commands, or running out of NCQ slots), we queue
788 * these I/O internally. Once SCIL completes an I/O to this device, or we get
789 * a ready notification, we will retry the first I/O on the queue.
790 * Unfortunately, SCIL also doesn't cleanly handle starting the new I/O within
791 * the context of the completion handler, so we need to retry these I/O after
792 * the completion handler is done executing.
795 isci_controller_release_queued_ccbs(struct ISCI_CONTROLLER *controller)
797 struct ISCI_REMOTE_DEVICE *dev;
798 struct ccb_hdr *ccb_h;
801 KASSERT(mtx_owned(&controller->lock), ("controller lock not owned"));
803 controller->release_queued_ccbs = FALSE;
805 dev_idx < SCI_MAX_REMOTE_DEVICES;
808 dev = controller->remote_device[dev_idx];
810 dev->release_queued_ccb == TRUE &&
811 dev->queued_ccb_in_progress == NULL) {
812 dev->release_queued_ccb = FALSE;
813 ccb_h = TAILQ_FIRST(&dev->queued_ccbs);
818 isci_log_message(1, "ISCI", "release %p %x\n", ccb_h,
819 ((union ccb *)ccb_h)->csio.cdb_io.cdb_bytes[0]);
821 dev->queued_ccb_in_progress = (union ccb *)ccb_h;
822 isci_io_request_execute_scsi_io(
823 (union ccb *)ccb_h, controller);