Index: head/sys/dev/isci/isci.h =================================================================== --- head/sys/dev/isci/isci.h (revision 358486) +++ head/sys/dev/isci/isci.h (revision 358487) @@ -1,354 +1,352 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * BSD LICENSE * * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _ISCI_H #define _ISCI_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define DEVICE2SOFTC(dev) ((struct isci_softc *) device_get_softc(dev)) #define DEVICE_TIMEOUT 1000 #define SCI_MAX_TIMERS 32 #define ISCI_NUM_PCI_BARS 2 #define ISCI_MAX_LUN 8 /* This device cannot DMA across a 4GB boundary */ #define ISCI_DMA_BOUNDARY ((bus_addr_t)((uint64_t)1 << 32)) MALLOC_DECLARE(M_ISCI); struct ISCI_TIMER { struct callout callout; SCI_TIMER_CALLBACK_T callback; void *cookie; BOOL is_started; }; struct ISCI_REMOTE_DEVICE { uint32_t index; struct ISCI_DOMAIN *domain; SCI_REMOTE_DEVICE_HANDLE_T sci_object; BOOL is_resetting; uint32_t frozen_lun_mask; SCI_FAST_LIST_ELEMENT_T pending_device_reset_element; /* * This queue maintains CCBs that have been returned with * SCI_IO_FAILURE_INVALID_STATE from the SCI layer. These CCBs * need to be retried, but we cannot return CAM_REQUEUE_REQ because * this status gets passed all the way back up to users of the pass(4) * interface and breaks things like smartctl. So instead, we queue * these CCBs internally. */ TAILQ_HEAD(,ccb_hdr) queued_ccbs; /* * Marker denoting this remote device needs its first queued ccb to * be retried. */ BOOL release_queued_ccb; /* * Points to a CCB in the queue that is currently being processed by * SCIL. This allows us to keep in flight CCBs in the queue so as to * maintain ordering (i.e. in case we retry an I/O and then find out * it needs to be retried again - it just keeps its same place in the * queue. */ union ccb * queued_ccb_in_progress; }; struct ISCI_DOMAIN { struct ISCI_CONTROLLER *controller; SCI_DOMAIN_HANDLE_T sci_object; uint8_t index; struct ISCI_REMOTE_DEVICE *da_remote_device; }; struct ISCI_MEMORY { bus_addr_t physical_address; bus_dma_tag_t dma_tag; bus_dmamap_t dma_map; POINTER_UINT virtual_address; uint32_t size; int error; }; struct ISCI_INTERRUPT_INFO { SCIC_CONTROLLER_HANDLER_METHODS_T *handlers; void *interrupt_target_handle; struct resource *res; int rid; void *tag; }; struct ISCI_PHY { struct cdev *cdev_fault; struct cdev *cdev_locate; SCI_CONTROLLER_HANDLE_T handle; int index; int led_fault; int led_locate; }; struct ISCI_CONTROLLER { struct isci_softc *isci; uint8_t index; SCI_CONTROLLER_HANDLE_T scif_controller_handle; struct ISCI_DOMAIN domain[SCI_MAX_DOMAINS]; BOOL is_started; BOOL has_been_scanned; uint32_t initial_discovery_mask; BOOL is_frozen; BOOL release_queued_ccbs; BOOL fail_on_task_timeout; uint8_t *remote_device_memory; struct ISCI_MEMORY cached_controller_memory; struct ISCI_MEMORY uncached_controller_memory; struct ISCI_MEMORY request_memory; bus_dma_tag_t buffer_dma_tag; struct mtx lock; struct cam_sim *sim; struct cam_path *path; struct ISCI_REMOTE_DEVICE *remote_device[SCI_MAX_REMOTE_DEVICES]; void *timer_memory; SCIC_OEM_PARAMETERS_T oem_parameters; uint32_t oem_parameters_version; uint32_t queue_depth; uint32_t sim_queue_depth; SCI_FAST_LIST_T pending_device_reset_list; struct ISCI_PHY phys[SCI_MAX_PHYS]; SCI_MEMORY_DESCRIPTOR_LIST_HANDLE_T mdl; SCI_POOL_CREATE(remote_device_pool, struct ISCI_REMOTE_DEVICE *, SCI_MAX_REMOTE_DEVICES); SCI_POOL_CREATE(request_pool, struct ISCI_REQUEST *, SCI_MAX_IO_REQUESTS); SCI_POOL_CREATE(timer_pool, struct ISCI_TIMER *, SCI_MAX_TIMERS); SCI_POOL_CREATE(unmap_buffer_pool, void *, SCI_MAX_REMOTE_DEVICES); }; struct ISCI_REQUEST { SCI_CONTROLLER_HANDLE_T controller_handle; SCI_REMOTE_DEVICE_HANDLE_T remote_device_handle; bus_dma_tag_t dma_tag; bus_dmamap_t dma_map; SCI_PHYSICAL_ADDRESS physical_address; struct callout timer; }; struct ISCI_IO_REQUEST { struct ISCI_REQUEST parent; SCI_IO_REQUEST_HANDLE_T sci_object; union ccb *ccb; uint32_t num_segments; uint32_t current_sge_index; bus_dma_segment_t *sge; }; struct ISCI_TASK_REQUEST { struct ISCI_REQUEST parent; struct scsi_sense_data sense_data; SCI_TASK_REQUEST_HANDLE_T sci_object; union ccb *ccb; }; struct ISCI_PCI_BAR { bus_space_tag_t bus_tag; bus_space_handle_t bus_handle; int resource_id; struct resource *resource; }; /* * One of these per allocated PCI device. */ struct isci_softc { struct ISCI_PCI_BAR pci_bar[ISCI_NUM_PCI_BARS]; struct ISCI_CONTROLLER controllers[SCI_MAX_CONTROLLERS]; SCI_LIBRARY_HANDLE_T sci_library_handle; void * sci_library_memory; SCIC_CONTROLLER_HANDLER_METHODS_T handlers[4]; struct ISCI_INTERRUPT_INFO interrupt_info[4]; uint32_t controller_count; uint32_t num_interrupts; uint32_t coalesce_number; uint32_t coalesce_timeout; device_t device; SCI_PCI_COMMON_HEADER_T pci_common_header; BOOL oem_parameters_found; struct intr_config_hook config_hook; }; int isci_allocate_resources(device_t device); int isci_allocate_dma_buffer(device_t device, struct ISCI_CONTROLLER *lock, struct ISCI_MEMORY *memory); void isci_remote_device_reset(struct ISCI_REMOTE_DEVICE *remote_device, union ccb *ccb); /** * Returns the negotiated link rate (in KB/s) for the associated * remote device. Used to fill out bitrate field for GET_TRANS_SETTINGS. * Will match the negotiated link rate for the lowest numbered local phy * in the port/domain containing this remote device. */ uint32_t isci_remote_device_get_bitrate( struct ISCI_REMOTE_DEVICE *remote_device); void isci_remote_device_freeze_lun_queue( struct ISCI_REMOTE_DEVICE *remote_device, lun_id_t lun); void isci_remote_device_release_lun_queue( struct ISCI_REMOTE_DEVICE *remote_device, lun_id_t lun); void isci_remote_device_release_device_queue( struct ISCI_REMOTE_DEVICE * remote_device); void isci_request_construct(struct ISCI_REQUEST *request, SCI_CONTROLLER_HANDLE_T scif_controller_handle, bus_dma_tag_t io_buffer_dma_tag, bus_addr_t physical_address); #define isci_io_request_get_max_io_size() \ ((SCI_MAX_SCATTER_GATHER_ELEMENTS - 1) * PAGE_SIZE) #define isci_task_request_get_object_size() \ (sizeof(struct ISCI_TASK_REQUEST) + scif_task_request_get_object_size()) #define isci_io_request_get_object_size() \ (sizeof(struct ISCI_IO_REQUEST) + scif_io_request_get_object_size()) #define isci_request_get_object_size() \ max( \ isci_task_request_get_object_size(), \ isci_io_request_get_object_size() \ ) void isci_io_request_execute_scsi_io(union ccb *ccb, struct ISCI_CONTROLLER *controller); -#if __FreeBSD_version >= 900026 void isci_io_request_execute_smp_io( union ccb *ccb, struct ISCI_CONTROLLER *controller); -#endif void isci_io_request_timeout(void *); void isci_get_oem_parameters(struct isci_softc *isci); void isci_io_request_complete( SCI_CONTROLLER_HANDLE_T scif_controller, SCI_REMOTE_DEVICE_HANDLE_T remote_device, struct ISCI_IO_REQUEST * isci_request, SCI_IO_STATUS completion_status); void isci_task_request_complete( SCI_CONTROLLER_HANDLE_T scif_controller, SCI_REMOTE_DEVICE_HANDLE_T remote_device, SCI_TASK_REQUEST_HANDLE_T io_request, SCI_TASK_STATUS completion_status); void isci_sysctl_initialize(struct isci_softc *isci); void isci_controller_construct(struct ISCI_CONTROLLER *controller, struct isci_softc *isci); SCI_STATUS isci_controller_initialize(struct ISCI_CONTROLLER *controller); int isci_controller_allocate_memory(struct ISCI_CONTROLLER *controller); void isci_controller_domain_discovery_complete( struct ISCI_CONTROLLER *isci_controller, struct ISCI_DOMAIN *isci_domain); int isci_controller_attach_to_cam(struct ISCI_CONTROLLER *controller); void isci_controller_start(void *controller); void isci_controller_release_queued_ccbs(struct ISCI_CONTROLLER *controller); void isci_domain_construct(struct ISCI_DOMAIN *domain, uint32_t domain_index, struct ISCI_CONTROLLER *controller); void isci_interrupt_setup(struct isci_softc *isci); void isci_interrupt_poll_handler(struct ISCI_CONTROLLER *controller); void isci_log_message(uint32_t verbosity, char *log_message_prefix, char *log_message, ...); extern uint32_t g_isci_debug_level; #endif /* #ifndef _ISCI_H */ Index: head/sys/dev/isci/isci_controller.c =================================================================== --- head/sys/dev/isci/isci_controller.c (revision 358486) +++ head/sys/dev/isci/isci_controller.c (revision 358487) @@ -1,843 +1,824 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * BSD LICENSE * * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void isci_action(struct cam_sim *sim, union ccb *ccb); void isci_poll(struct cam_sim *sim); #define ccb_sim_ptr sim_priv.entries[0].ptr /** * @brief This user callback will inform the user that the controller has * had a serious unexpected error. The user should not the error, * disable interrupts, and wait for current ongoing processing to * complete. Subsequently, the user should reset the controller. * * @param[in] controller This parameter specifies the controller that had * an error. * * @return none */ void scif_cb_controller_error(SCI_CONTROLLER_HANDLE_T controller, SCI_CONTROLLER_ERROR error) { isci_log_message(0, "ISCI", "scif_cb_controller_error: 0x%x\n", error); } /** * @brief This user callback will inform the user that the controller has * finished the start process. * * @param[in] controller This parameter specifies the controller that was * started. * @param[in] completion_status This parameter specifies the results of * the start operation. SCI_SUCCESS indicates successful * completion. * * @return none */ void scif_cb_controller_start_complete(SCI_CONTROLLER_HANDLE_T controller, SCI_STATUS completion_status) { uint32_t index; struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(controller); isci_controller->is_started = TRUE; /* Set bits for all domains. We will clear them one-by-one once * the domains complete discovery, or return error when calling * scif_domain_discover. Once all bits are clear, we will register * the controller with CAM. */ isci_controller->initial_discovery_mask = (1 << SCI_MAX_DOMAINS) - 1; for(index = 0; index < SCI_MAX_DOMAINS; index++) { SCI_STATUS status; SCI_DOMAIN_HANDLE_T domain = isci_controller->domain[index].sci_object; status = scif_domain_discover( domain, scif_domain_get_suggested_discover_timeout(domain), DEVICE_TIMEOUT ); if (status != SCI_SUCCESS) { isci_controller_domain_discovery_complete( isci_controller, &isci_controller->domain[index]); } } } /** * @brief This user callback will inform the user that the controller has * finished the stop process. Note, after user calls * scif_controller_stop(), before user receives this controller stop * complete callback, user should not expect any callback from * framework, such like scif_cb_domain_change_notification(). * * @param[in] controller This parameter specifies the controller that was * stopped. * @param[in] completion_status This parameter specifies the results of * the stop operation. SCI_SUCCESS indicates successful * completion. * * @return none */ void scif_cb_controller_stop_complete(SCI_CONTROLLER_HANDLE_T controller, SCI_STATUS completion_status) { struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(controller); isci_controller->is_started = FALSE; } static void isci_single_map(void *arg, bus_dma_segment_t *seg, int nseg, int error) { SCI_PHYSICAL_ADDRESS *phys_addr = arg; *phys_addr = seg[0].ds_addr; } /** * @brief This method will be invoked to allocate memory dynamically. * * @param[in] controller This parameter represents the controller * object for which to allocate memory. * @param[out] mde This parameter represents the memory descriptor to * be filled in by the user that will reference the newly * allocated memory. * * @return none */ void scif_cb_controller_allocate_memory(SCI_CONTROLLER_HANDLE_T controller, SCI_PHYSICAL_MEMORY_DESCRIPTOR_T *mde) { struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(controller); /* * Note this routine is only used for buffers needed to translate * SCSI UNMAP commands to ATA DSM commands for SATA disks. * * We first try to pull a buffer from the controller's pool, and only * call contigmalloc if one isn't there. */ if (!sci_pool_empty(isci_controller->unmap_buffer_pool)) { sci_pool_get(isci_controller->unmap_buffer_pool, mde->virtual_address); } else mde->virtual_address = contigmalloc(PAGE_SIZE, M_ISCI, M_NOWAIT, 0, BUS_SPACE_MAXADDR, mde->constant_memory_alignment, 0); if (mde->virtual_address != NULL) bus_dmamap_load(isci_controller->buffer_dma_tag, NULL, mde->virtual_address, PAGE_SIZE, isci_single_map, &mde->physical_address, BUS_DMA_NOWAIT); } /** * @brief This method will be invoked to allocate memory dynamically. * * @param[in] controller This parameter represents the controller * object for which to allocate memory. * @param[out] mde This parameter represents the memory descriptor to * be filled in by the user that will reference the newly * allocated memory. * * @return none */ void scif_cb_controller_free_memory(SCI_CONTROLLER_HANDLE_T controller, SCI_PHYSICAL_MEMORY_DESCRIPTOR_T * mde) { struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(controller); /* * Put the buffer back into the controller's buffer pool, rather * than invoking configfree. This helps reduce chance we won't * have buffers available when system is under memory pressure. */ sci_pool_put(isci_controller->unmap_buffer_pool, mde->virtual_address); } void isci_controller_construct(struct ISCI_CONTROLLER *controller, struct isci_softc *isci) { SCI_CONTROLLER_HANDLE_T scif_controller_handle; scif_library_allocate_controller(isci->sci_library_handle, &scif_controller_handle); scif_controller_construct(isci->sci_library_handle, scif_controller_handle, NULL); controller->isci = isci; controller->scif_controller_handle = scif_controller_handle; /* This allows us to later use * sci_object_get_association(scif_controller_handle) * inside of a callback routine to get our struct ISCI_CONTROLLER object */ sci_object_set_association(scif_controller_handle, (void *)controller); controller->is_started = FALSE; controller->is_frozen = FALSE; controller->release_queued_ccbs = FALSE; controller->sim = NULL; controller->initial_discovery_mask = 0; sci_fast_list_init(&controller->pending_device_reset_list); mtx_init(&controller->lock, "isci", NULL, MTX_DEF); uint32_t domain_index; for(domain_index = 0; domain_index < SCI_MAX_DOMAINS; domain_index++) { isci_domain_construct( &controller->domain[domain_index], domain_index, controller); } controller->timer_memory = malloc( sizeof(struct ISCI_TIMER) * SCI_MAX_TIMERS, M_ISCI, M_NOWAIT | M_ZERO); sci_pool_initialize(controller->timer_pool); struct ISCI_TIMER *timer = (struct ISCI_TIMER *) controller->timer_memory; for ( int i = 0; i < SCI_MAX_TIMERS; i++ ) { sci_pool_put(controller->timer_pool, timer++); } sci_pool_initialize(controller->unmap_buffer_pool); } static void isci_led_fault_func(void *priv, int onoff) { struct ISCI_PHY *phy = priv; /* map onoff to the fault LED */ phy->led_fault = onoff; scic_sgpio_update_led_state(phy->handle, 1 << phy->index, phy->led_fault, phy->led_locate, 0); } static void isci_led_locate_func(void *priv, int onoff) { struct ISCI_PHY *phy = priv; /* map onoff to the locate LED */ phy->led_locate = onoff; scic_sgpio_update_led_state(phy->handle, 1 << phy->index, phy->led_fault, phy->led_locate, 0); } SCI_STATUS isci_controller_initialize(struct ISCI_CONTROLLER *controller) { SCIC_USER_PARAMETERS_T scic_user_parameters; SCI_CONTROLLER_HANDLE_T scic_controller_handle; char led_name[64]; unsigned long tunable; uint32_t io_shortage; uint32_t fail_on_timeout; int i; scic_controller_handle = scif_controller_get_scic_handle(controller->scif_controller_handle); if (controller->isci->oem_parameters_found == TRUE) { scic_oem_parameters_set( scic_controller_handle, &controller->oem_parameters, (uint8_t)(controller->oem_parameters_version)); } scic_user_parameters_get(scic_controller_handle, &scic_user_parameters); if (TUNABLE_ULONG_FETCH("hw.isci.no_outbound_task_timeout", &tunable)) scic_user_parameters.sds1.no_outbound_task_timeout = (uint8_t)tunable; if (TUNABLE_ULONG_FETCH("hw.isci.ssp_max_occupancy_timeout", &tunable)) scic_user_parameters.sds1.ssp_max_occupancy_timeout = (uint16_t)tunable; if (TUNABLE_ULONG_FETCH("hw.isci.stp_max_occupancy_timeout", &tunable)) scic_user_parameters.sds1.stp_max_occupancy_timeout = (uint16_t)tunable; if (TUNABLE_ULONG_FETCH("hw.isci.ssp_inactivity_timeout", &tunable)) scic_user_parameters.sds1.ssp_inactivity_timeout = (uint16_t)tunable; if (TUNABLE_ULONG_FETCH("hw.isci.stp_inactivity_timeout", &tunable)) scic_user_parameters.sds1.stp_inactivity_timeout = (uint16_t)tunable; if (TUNABLE_ULONG_FETCH("hw.isci.max_speed_generation", &tunable)) for (i = 0; i < SCI_MAX_PHYS; i++) scic_user_parameters.sds1.phys[i].max_speed_generation = (uint8_t)tunable; scic_user_parameters_set(scic_controller_handle, &scic_user_parameters); /* Scheduler bug in SCU requires SCIL to reserve some task contexts as a * a workaround - one per domain. */ controller->queue_depth = SCI_MAX_IO_REQUESTS - SCI_MAX_DOMAINS; if (TUNABLE_INT_FETCH("hw.isci.controller_queue_depth", &controller->queue_depth)) { controller->queue_depth = max(1, min(controller->queue_depth, SCI_MAX_IO_REQUESTS - SCI_MAX_DOMAINS)); } /* Reserve one request so that we can ensure we have one available TC * to do internal device resets. */ controller->sim_queue_depth = controller->queue_depth - 1; /* Although we save one TC to do internal device resets, it is possible * we could end up using several TCs for simultaneous device resets * while at the same time having CAM fill our controller queue. To * simulate this condition, and how our driver handles it, we can set * this io_shortage parameter, which will tell CAM that we have a * large queue depth than we really do. */ io_shortage = 0; TUNABLE_INT_FETCH("hw.isci.io_shortage", &io_shortage); controller->sim_queue_depth += io_shortage; fail_on_timeout = 1; TUNABLE_INT_FETCH("hw.isci.fail_on_task_timeout", &fail_on_timeout); controller->fail_on_task_timeout = fail_on_timeout; /* Attach to CAM using xpt_bus_register now, then immediately freeze * the simq. It will get released later when initial domain discovery * is complete. */ controller->has_been_scanned = FALSE; mtx_lock(&controller->lock); isci_controller_attach_to_cam(controller); xpt_freeze_simq(controller->sim, 1); mtx_unlock(&controller->lock); for (i = 0; i < SCI_MAX_PHYS; i++) { controller->phys[i].handle = scic_controller_handle; controller->phys[i].index = i; /* fault */ controller->phys[i].led_fault = 0; sprintf(led_name, "isci.bus%d.port%d.fault", controller->index, i); controller->phys[i].cdev_fault = led_create(isci_led_fault_func, &controller->phys[i], led_name); /* locate */ controller->phys[i].led_locate = 0; sprintf(led_name, "isci.bus%d.port%d.locate", controller->index, i); controller->phys[i].cdev_locate = led_create(isci_led_locate_func, &controller->phys[i], led_name); } return (scif_controller_initialize(controller->scif_controller_handle)); } int isci_controller_allocate_memory(struct ISCI_CONTROLLER *controller) { int error; device_t device = controller->isci->device; uint32_t max_segment_size = isci_io_request_get_max_io_size(); uint32_t status = 0; struct ISCI_MEMORY *uncached_controller_memory = &controller->uncached_controller_memory; struct ISCI_MEMORY *cached_controller_memory = &controller->cached_controller_memory; struct ISCI_MEMORY *request_memory = &controller->request_memory; POINTER_UINT virtual_address; bus_addr_t physical_address; controller->mdl = sci_controller_get_memory_descriptor_list_handle( controller->scif_controller_handle); uncached_controller_memory->size = sci_mdl_decorator_get_memory_size( controller->mdl, SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS); error = isci_allocate_dma_buffer(device, controller, uncached_controller_memory); if (error != 0) return (error); sci_mdl_decorator_assign_memory( controller->mdl, SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS, uncached_controller_memory->virtual_address, uncached_controller_memory->physical_address); cached_controller_memory->size = sci_mdl_decorator_get_memory_size( controller->mdl, SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS ); error = isci_allocate_dma_buffer(device, controller, cached_controller_memory); if (error != 0) return (error); sci_mdl_decorator_assign_memory(controller->mdl, SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS, cached_controller_memory->virtual_address, cached_controller_memory->physical_address); request_memory->size = controller->queue_depth * isci_io_request_get_object_size(); error = isci_allocate_dma_buffer(device, controller, request_memory); if (error != 0) return (error); /* For STP PIO testing, we want to ensure we can force multiple SGLs * since this has been a problem area in SCIL. This tunable parameter * will allow us to force DMA segments to a smaller size, ensuring * that even if a physically contiguous buffer is attached to this * I/O, the DMA subsystem will pass us multiple segments in our DMA * load callback. */ TUNABLE_INT_FETCH("hw.isci.max_segment_size", &max_segment_size); /* Create DMA tag for our I/O requests. Then we can create DMA maps based off * of this tag and store them in each of our ISCI_IO_REQUEST objects. This * will enable better performance than creating the DMA maps every time we get * an I/O. */ status = bus_dma_tag_create(bus_get_dma_tag(device), 0x1, ISCI_DMA_BOUNDARY, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, isci_io_request_get_max_io_size(), SCI_MAX_SCATTER_GATHER_ELEMENTS, max_segment_size, 0, busdma_lock_mutex, &controller->lock, &controller->buffer_dma_tag); sci_pool_initialize(controller->request_pool); virtual_address = request_memory->virtual_address; physical_address = request_memory->physical_address; for (int i = 0; i < controller->queue_depth; i++) { struct ISCI_REQUEST *request = (struct ISCI_REQUEST *)virtual_address; isci_request_construct(request, controller->scif_controller_handle, controller->buffer_dma_tag, physical_address); sci_pool_put(controller->request_pool, request); virtual_address += isci_request_get_object_size(); physical_address += isci_request_get_object_size(); } uint32_t remote_device_size = sizeof(struct ISCI_REMOTE_DEVICE) + scif_remote_device_get_object_size(); controller->remote_device_memory = (uint8_t *) malloc( remote_device_size * SCI_MAX_REMOTE_DEVICES, M_ISCI, M_NOWAIT | M_ZERO); sci_pool_initialize(controller->remote_device_pool); uint8_t *remote_device_memory_ptr = controller->remote_device_memory; for (int i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { struct ISCI_REMOTE_DEVICE *remote_device = (struct ISCI_REMOTE_DEVICE *)remote_device_memory_ptr; controller->remote_device[i] = NULL; remote_device->index = i; remote_device->is_resetting = FALSE; remote_device->frozen_lun_mask = 0; sci_fast_list_element_init(remote_device, &remote_device->pending_device_reset_element); TAILQ_INIT(&remote_device->queued_ccbs); remote_device->release_queued_ccb = FALSE; remote_device->queued_ccb_in_progress = NULL; /* * For the first SCI_MAX_DOMAINS device objects, do not put * them in the pool, rather assign them to each domain. This * ensures that any device attached directly to port "i" will * always get CAM target id "i". */ if (i < SCI_MAX_DOMAINS) controller->domain[i].da_remote_device = remote_device; else sci_pool_put(controller->remote_device_pool, remote_device); remote_device_memory_ptr += remote_device_size; } return (0); } void isci_controller_start(void *controller_handle) { struct ISCI_CONTROLLER *controller = (struct ISCI_CONTROLLER *)controller_handle; SCI_CONTROLLER_HANDLE_T scif_controller_handle = controller->scif_controller_handle; scif_controller_start(scif_controller_handle, scif_controller_get_suggested_start_timeout(scif_controller_handle)); scic_controller_enable_interrupts( scif_controller_get_scic_handle(controller->scif_controller_handle)); } void isci_controller_domain_discovery_complete( struct ISCI_CONTROLLER *isci_controller, struct ISCI_DOMAIN *isci_domain) { if (!isci_controller->has_been_scanned) { /* Controller has not been scanned yet. We'll clear * the discovery bit for this domain, then check if all bits * are now clear. That would indicate that all domains are * done with discovery and we can then proceed with initial * scan. */ isci_controller->initial_discovery_mask &= ~(1 << isci_domain->index); if (isci_controller->initial_discovery_mask == 0) { struct isci_softc *driver = isci_controller->isci; uint8_t next_index = isci_controller->index + 1; isci_controller->has_been_scanned = TRUE; /* Unfreeze simq to allow initial scan to proceed. */ xpt_release_simq(isci_controller->sim, TRUE); -#if __FreeBSD_version < 800000 - /* When driver is loaded after boot, we need to - * explicitly rescan here for versions <8.0, because - * CAM only automatically scans new buses at boot - * time. - */ - union ccb *ccb = xpt_alloc_ccb_nowait(); - - xpt_create_path(&ccb->ccb_h.path, NULL, - cam_sim_path(isci_controller->sim), - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - xpt_rescan(ccb); -#endif - if (next_index < driver->controller_count) { /* There are more controllers that need to * start. So start the next one. */ isci_controller_start( &driver->controllers[next_index]); } else { /* All controllers have been started and completed discovery. * Disestablish the config hook while will signal to the * kernel during boot that it is safe to try to find and * mount the root partition. */ config_intrhook_disestablish( &driver->config_hook); } } } } int isci_controller_attach_to_cam(struct ISCI_CONTROLLER *controller) { struct isci_softc *isci = controller->isci; device_t parent = device_get_parent(isci->device); int unit = device_get_unit(isci->device); struct cam_devq *isci_devq = cam_simq_alloc(controller->sim_queue_depth); if(isci_devq == NULL) { isci_log_message(0, "ISCI", "isci_devq is NULL \n"); return (-1); } controller->sim = cam_sim_alloc(isci_action, isci_poll, "isci", controller, unit, &controller->lock, controller->sim_queue_depth, controller->sim_queue_depth, isci_devq); if(controller->sim == NULL) { isci_log_message(0, "ISCI", "cam_sim_alloc... fails\n"); cam_simq_free(isci_devq); return (-1); } if(xpt_bus_register(controller->sim, parent, controller->index) != CAM_SUCCESS) { isci_log_message(0, "ISCI", "xpt_bus_register...fails \n"); cam_sim_free(controller->sim, TRUE); mtx_unlock(&controller->lock); return (-1); } if(xpt_create_path(&controller->path, NULL, cam_sim_path(controller->sim), CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { isci_log_message(0, "ISCI", "xpt_create_path....fails\n"); xpt_bus_deregister(cam_sim_path(controller->sim)); cam_sim_free(controller->sim, TRUE); mtx_unlock(&controller->lock); return (-1); } return (0); } void isci_poll(struct cam_sim *sim) { struct ISCI_CONTROLLER *controller = (struct ISCI_CONTROLLER *)cam_sim_softc(sim); isci_interrupt_poll_handler(controller); } void isci_action(struct cam_sim *sim, union ccb *ccb) { struct ISCI_CONTROLLER *controller = (struct ISCI_CONTROLLER *)cam_sim_softc(sim); switch ( ccb->ccb_h.func_code ) { case XPT_PATH_INQ: { struct ccb_pathinq *cpi = &ccb->cpi; int bus = cam_sim_bus(sim); ccb->ccb_h.ccb_sim_ptr = sim; cpi->version_num = 1; cpi->hba_inquiry = PI_TAG_ABLE; cpi->target_sprt = 0; cpi->hba_misc = PIM_NOBUSRESET | PIM_SEQSCAN | PIM_UNMAPPED; cpi->hba_eng_cnt = 0; cpi->max_target = SCI_MAX_REMOTE_DEVICES - 1; cpi->max_lun = ISCI_MAX_LUN; -#if __FreeBSD_version >= 800102 cpi->maxio = isci_io_request_get_max_io_size(); -#endif cpi->unit_number = cam_sim_unit(sim); cpi->bus_id = bus; cpi->initiator_id = SCI_MAX_REMOTE_DEVICES; cpi->base_transfer_speed = 300000; strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); strlcpy(cpi->hba_vid, "Intel Corp.", HBA_IDLEN); strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); cpi->transport = XPORT_SAS; cpi->transport_version = 0; cpi->protocol = PROTO_SCSI; cpi->protocol_version = SCSI_REV_SPC2; cpi->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); } break; case XPT_GET_TRAN_SETTINGS: { struct ccb_trans_settings *general_settings = &ccb->cts; struct ccb_trans_settings_sas *sas_settings = &general_settings->xport_specific.sas; struct ccb_trans_settings_scsi *scsi_settings = &general_settings->proto_specific.scsi; struct ISCI_REMOTE_DEVICE *remote_device; remote_device = controller->remote_device[ccb->ccb_h.target_id]; if (remote_device == NULL) { ccb->ccb_h.status &= ~CAM_SIM_QUEUED; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_DEV_NOT_THERE; xpt_done(ccb); break; } general_settings->protocol = PROTO_SCSI; general_settings->transport = XPORT_SAS; general_settings->protocol_version = SCSI_REV_SPC2; general_settings->transport_version = 0; scsi_settings->valid = CTS_SCSI_VALID_TQ; scsi_settings->flags = CTS_SCSI_FLAGS_TAG_ENB; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_REQ_CMP; sas_settings->bitrate = isci_remote_device_get_bitrate(remote_device); if (sas_settings->bitrate != 0) sas_settings->valid = CTS_SAS_VALID_SPEED; xpt_done(ccb); } break; case XPT_SCSI_IO: if (ccb->ccb_h.flags & CAM_CDB_PHYS) { ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); break; } isci_io_request_execute_scsi_io(ccb, controller); break; -#if __FreeBSD_version >= 900026 case XPT_SMP_IO: isci_io_request_execute_smp_io(ccb, controller); break; -#endif case XPT_SET_TRAN_SETTINGS: ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_REQ_CMP; xpt_done(ccb); break; case XPT_CALC_GEOMETRY: cam_calc_geometry(&ccb->ccg, /*extended*/1); xpt_done(ccb); break; case XPT_RESET_DEV: { struct ISCI_REMOTE_DEVICE *remote_device = controller->remote_device[ccb->ccb_h.target_id]; if (remote_device != NULL) isci_remote_device_reset(remote_device, ccb); else { ccb->ccb_h.status &= ~CAM_SIM_QUEUED; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_DEV_NOT_THERE; xpt_done(ccb); } } break; case XPT_RESET_BUS: ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); break; default: isci_log_message(0, "ISCI", "Unhandled func_code 0x%x\n", ccb->ccb_h.func_code); ccb->ccb_h.status &= ~CAM_SIM_QUEUED; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_REQ_INVALID; xpt_done(ccb); break; } } /* * Unfortunately, SCIL doesn't cleanly handle retry conditions. * CAM_REQUEUE_REQ works only when no one is using the pass(4) interface. So * when SCIL denotes an I/O needs to be retried (typically because of mixing * tagged/non-tagged ATA commands, or running out of NCQ slots), we queue * these I/O internally. Once SCIL completes an I/O to this device, or we get * a ready notification, we will retry the first I/O on the queue. * Unfortunately, SCIL also doesn't cleanly handle starting the new I/O within * the context of the completion handler, so we need to retry these I/O after * the completion handler is done executing. */ void isci_controller_release_queued_ccbs(struct ISCI_CONTROLLER *controller) { struct ISCI_REMOTE_DEVICE *dev; struct ccb_hdr *ccb_h; uint8_t *ptr; int dev_idx; KASSERT(mtx_owned(&controller->lock), ("controller lock not owned")); controller->release_queued_ccbs = FALSE; for (dev_idx = 0; dev_idx < SCI_MAX_REMOTE_DEVICES; dev_idx++) { dev = controller->remote_device[dev_idx]; if (dev != NULL && dev->release_queued_ccb == TRUE && dev->queued_ccb_in_progress == NULL) { dev->release_queued_ccb = FALSE; ccb_h = TAILQ_FIRST(&dev->queued_ccbs); if (ccb_h == NULL) continue; ptr = scsiio_cdb_ptr(&((union ccb *)ccb_h)->csio); isci_log_message(1, "ISCI", "release %p %x\n", ccb_h, *ptr); dev->queued_ccb_in_progress = (union ccb *)ccb_h; isci_io_request_execute_scsi_io( (union ccb *)ccb_h, controller); } } } Index: head/sys/dev/isci/isci_io_request.c =================================================================== --- head/sys/dev/isci/isci_io_request.c (revision 358486) +++ head/sys/dev/isci/isci_io_request.c (revision 358487) @@ -1,993 +1,989 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * BSD LICENSE * * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include /** * @brief This user callback will inform the user that an IO request has * completed. * * @param[in] controller This parameter specifies the controller on * which the IO request is completing. * @param[in] remote_device This parameter specifies the remote device on * which this request is completing. * @param[in] io_request This parameter specifies the IO request that has * completed. * @param[in] completion_status This parameter specifies the results of * the IO request operation. SCI_IO_SUCCESS indicates * successful completion. * * @return none */ void scif_cb_io_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller, SCI_REMOTE_DEVICE_HANDLE_T remote_device, SCI_IO_REQUEST_HANDLE_T io_request, SCI_IO_STATUS completion_status) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)sci_object_get_association(io_request); scif_controller_complete_io(scif_controller, remote_device, io_request); isci_io_request_complete(scif_controller, remote_device, isci_request, completion_status); } void isci_io_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller, SCI_REMOTE_DEVICE_HANDLE_T remote_device, struct ISCI_IO_REQUEST *isci_request, SCI_IO_STATUS completion_status) { struct ISCI_CONTROLLER *isci_controller; struct ISCI_REMOTE_DEVICE *isci_remote_device; union ccb *ccb; BOOL complete_ccb; struct ccb_scsiio *csio; complete_ccb = TRUE; isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(scif_controller); isci_remote_device = (struct ISCI_REMOTE_DEVICE *) sci_object_get_association(remote_device); ccb = isci_request->ccb; csio = &ccb->csio; ccb->ccb_h.status &= ~CAM_STATUS_MASK; switch (completion_status) { case SCI_IO_SUCCESS: case SCI_IO_SUCCESS_COMPLETE_BEFORE_START: -#if __FreeBSD_version >= 900026 if (ccb->ccb_h.func_code == XPT_SMP_IO) { void *smp_response = scif_io_request_get_response_iu_address( isci_request->sci_object); memcpy(ccb->smpio.smp_response, smp_response, ccb->smpio.smp_response_len); } -#endif ccb->ccb_h.status |= CAM_REQ_CMP; break; case SCI_IO_SUCCESS_IO_DONE_EARLY: ccb->ccb_h.status |= CAM_REQ_CMP; ccb->csio.resid = ccb->csio.dxfer_len - scif_io_request_get_number_of_bytes_transferred( isci_request->sci_object); break; case SCI_IO_FAILURE_RESPONSE_VALID: { SCI_SSP_RESPONSE_IU_T * response_buffer; uint32_t sense_length; int error_code, sense_key, asc, ascq; response_buffer = (SCI_SSP_RESPONSE_IU_T *) scif_io_request_get_response_iu_address( isci_request->sci_object); sense_length = sci_ssp_get_sense_data_length( response_buffer->sense_data_length); sense_length = MIN(csio->sense_len, sense_length); memcpy(&csio->sense_data, response_buffer->data, sense_length); csio->sense_resid = csio->sense_len - sense_length; csio->scsi_status = response_buffer->status; ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR; ccb->ccb_h.status |= CAM_AUTOSNS_VALID; scsi_extract_sense( &csio->sense_data, &error_code, &sense_key, &asc, &ascq ); isci_log_message(1, "ISCI", "isci: bus=%x target=%x lun=%x cdb[0]=%x status=%x key=%x asc=%x ascq=%x\n", ccb->ccb_h.path_id, ccb->ccb_h.target_id, ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio), csio->scsi_status, sense_key, asc, ascq); break; } case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: isci_remote_device_reset(isci_remote_device, NULL); ccb->ccb_h.status |= CAM_REQ_TERMIO; isci_log_message(0, "ISCI", "isci: bus=%x target=%x lun=%x cdb[0]=%x remote device reset required\n", ccb->ccb_h.path_id, ccb->ccb_h.target_id, ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio)); break; case SCI_IO_FAILURE_TERMINATED: ccb->ccb_h.status |= CAM_REQ_TERMIO; isci_log_message(0, "ISCI", "isci: bus=%x target=%x lun=%x cdb[0]=%x terminated\n", ccb->ccb_h.path_id, ccb->ccb_h.target_id, ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio)); break; case SCI_IO_FAILURE_INVALID_STATE: case SCI_IO_FAILURE_INSUFFICIENT_RESOURCES: complete_ccb = FALSE; break; case SCI_IO_FAILURE_INVALID_REMOTE_DEVICE: ccb->ccb_h.status |= CAM_DEV_NOT_THERE; break; case SCI_IO_FAILURE_NO_NCQ_TAG_AVAILABLE: { struct ccb_relsim ccb_relsim; struct cam_path *path; xpt_create_path(&path, NULL, cam_sim_path(isci_controller->sim), isci_remote_device->index, 0); xpt_setup_ccb(&ccb_relsim.ccb_h, path, 5); ccb_relsim.ccb_h.func_code = XPT_REL_SIMQ; ccb_relsim.ccb_h.flags = CAM_DEV_QFREEZE; ccb_relsim.release_flags = RELSIM_ADJUST_OPENINGS; ccb_relsim.openings = scif_remote_device_get_max_queue_depth(remote_device); xpt_action((union ccb *)&ccb_relsim); xpt_free_path(path); complete_ccb = FALSE; } break; case SCI_IO_FAILURE: case SCI_IO_FAILURE_REQUIRES_SCSI_ABORT: case SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL: case SCI_IO_FAILURE_PROTOCOL_VIOLATION: case SCI_IO_FAILURE_INVALID_PARAMETER_VALUE: case SCI_IO_FAILURE_CONTROLLER_SPECIFIC_ERR: default: isci_log_message(1, "ISCI", "isci: bus=%x target=%x lun=%x cdb[0]=%x completion status=%x\n", ccb->ccb_h.path_id, ccb->ccb_h.target_id, ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio), completion_status); ccb->ccb_h.status |= CAM_REQ_CMP_ERR; break; } callout_stop(&isci_request->parent.timer); bus_dmamap_sync(isci_request->parent.dma_tag, isci_request->parent.dma_map, BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); bus_dmamap_unload(isci_request->parent.dma_tag, isci_request->parent.dma_map); isci_request->ccb = NULL; sci_pool_put(isci_controller->request_pool, (struct ISCI_REQUEST *)isci_request); if (complete_ccb) { if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { /* ccb will be completed with some type of non-success * status. So temporarily freeze the queue until the * upper layers can act on the status. The * CAM_DEV_QFRZN flag will then release the queue * after the status is acted upon. */ ccb->ccb_h.status |= CAM_DEV_QFRZN; xpt_freeze_devq(ccb->ccb_h.path, 1); } if (ccb->ccb_h.status & CAM_SIM_QUEUED) { KASSERT(ccb == isci_remote_device->queued_ccb_in_progress, ("multiple internally queued ccbs in flight")); TAILQ_REMOVE(&isci_remote_device->queued_ccbs, &ccb->ccb_h, sim_links.tqe); ccb->ccb_h.status &= ~CAM_SIM_QUEUED; /* * This CCB that was in the queue was completed, so * set the in_progress pointer to NULL denoting that * we can retry another CCB from the queue. We only * allow one CCB at a time from the queue to be * in progress so that we can effectively maintain * ordering. */ isci_remote_device->queued_ccb_in_progress = NULL; } if (isci_remote_device->frozen_lun_mask != 0) { isci_remote_device_release_device_queue(isci_remote_device); } xpt_done(ccb); if (isci_controller->is_frozen == TRUE) { isci_controller->is_frozen = FALSE; xpt_release_simq(isci_controller->sim, TRUE); } } else { isci_remote_device_freeze_lun_queue(isci_remote_device, ccb->ccb_h.target_lun); if (ccb->ccb_h.status & CAM_SIM_QUEUED) { KASSERT(ccb == isci_remote_device->queued_ccb_in_progress, ("multiple internally queued ccbs in flight")); /* * Do nothing, CCB is already on the device's queue. * We leave it on the queue, to be retried again * next time a CCB on this device completes, or we * get a ready notification for this device. */ isci_log_message(1, "ISCI", "already queued %p %x\n", ccb, scsiio_cdb_ptr(csio)); isci_remote_device->queued_ccb_in_progress = NULL; } else { isci_log_message(1, "ISCI", "queue %p %x\n", ccb, scsiio_cdb_ptr(csio)); ccb->ccb_h.status |= CAM_SIM_QUEUED; TAILQ_INSERT_TAIL(&isci_remote_device->queued_ccbs, &ccb->ccb_h, sim_links.tqe); } } } /** * @brief This callback method asks the user to provide the physical * address for the supplied virtual address when building an * io request object. * * @param[in] controller This parameter is the core controller object * handle. * @param[in] io_request This parameter is the io request object handle * for which the physical address is being requested. * @param[in] virtual_address This parameter is the virtual address which * is to be returned as a physical address. * @param[out] physical_address The physical address for the supplied virtual * address. * * @return None. */ void scic_cb_io_request_get_physical_address(SCI_CONTROLLER_HANDLE_T controller, SCI_IO_REQUEST_HANDLE_T io_request, void *virtual_address, SCI_PHYSICAL_ADDRESS *physical_address) { SCI_IO_REQUEST_HANDLE_T scif_request = sci_object_get_association(io_request); struct ISCI_REQUEST *isci_request = sci_object_get_association(scif_request); if(isci_request != NULL) { /* isci_request is not NULL, meaning this is a request initiated * by CAM or the isci layer (i.e. device reset for I/O * timeout). Therefore we can calculate the physical address * based on the address we stored in the struct ISCI_REQUEST * object. */ *physical_address = isci_request->physical_address + (uintptr_t)virtual_address - (uintptr_t)isci_request; } else { /* isci_request is NULL, meaning this is a request generated * internally by SCIL (i.e. for SMP requests or NCQ error * recovery). Therefore we calculate the physical address * based on the controller's uncached controller memory buffer, * since we know that this is what SCIL uses for internal * framework requests. */ SCI_CONTROLLER_HANDLE_T scif_controller = (SCI_CONTROLLER_HANDLE_T) sci_object_get_association(controller); struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)sci_object_get_association(scif_controller); U64 virt_addr_offset = (uintptr_t)virtual_address - (U64)isci_controller->uncached_controller_memory.virtual_address; *physical_address = isci_controller->uncached_controller_memory.physical_address + virt_addr_offset; } } /** * @brief This callback method asks the user to provide the address for * the command descriptor block (CDB) associated with this IO request. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * * @return This method returns the virtual address of the CDB. */ void * scif_cb_io_request_get_cdb_address(void * scif_user_io_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)scif_user_io_request; return (scsiio_cdb_ptr(&isci_request->ccb->csio)); } /** * @brief This callback method asks the user to provide the length of * the command descriptor block (CDB) associated with this IO request. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * * @return This method returns the length of the CDB. */ uint32_t scif_cb_io_request_get_cdb_length(void * scif_user_io_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)scif_user_io_request; return (isci_request->ccb->csio.cdb_len); } /** * @brief This callback method asks the user to provide the Logical Unit (LUN) * associated with this IO request. * * @note The contents of the value returned from this callback are defined * by the protocol standard (e.g. T10 SAS specification). Please * refer to the transport command information unit description * in the associated standard. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * * @return This method returns the LUN associated with this request. */ uint32_t scif_cb_io_request_get_lun(void * scif_user_io_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)scif_user_io_request; return (isci_request->ccb->ccb_h.target_lun); } /** * @brief This callback method asks the user to provide the task attribute * associated with this IO request. * * @note The contents of the value returned from this callback are defined * by the protocol standard (e.g. T10 SAS specification). Please * refer to the transport command information unit description * in the associated standard. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * * @return This method returns the task attribute associated with this * IO request. */ uint32_t scif_cb_io_request_get_task_attribute(void * scif_user_io_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)scif_user_io_request; uint32_t task_attribute; if((isci_request->ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0) switch(isci_request->ccb->csio.tag_action) { case MSG_HEAD_OF_Q_TAG: task_attribute = SCI_SAS_HEAD_OF_QUEUE_ATTRIBUTE; break; case MSG_ORDERED_Q_TAG: task_attribute = SCI_SAS_ORDERED_ATTRIBUTE; break; case MSG_ACA_TASK: task_attribute = SCI_SAS_ACA_ATTRIBUTE; break; default: task_attribute = SCI_SAS_SIMPLE_ATTRIBUTE; break; } else task_attribute = SCI_SAS_SIMPLE_ATTRIBUTE; return (task_attribute); } /** * @brief This callback method asks the user to provide the command priority * associated with this IO request. * * @note The contents of the value returned from this callback are defined * by the protocol standard (e.g. T10 SAS specification). Please * refer to the transport command information unit description * in the associated standard. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * * @return This method returns the command priority associated with this * IO request. */ uint32_t scif_cb_io_request_get_command_priority(void * scif_user_io_request) { return (0); } /** * @brief This method simply returns the virtual address associated * with the scsi_io and byte_offset supplied parameters. * * @note This callback is not utilized in the fast path. The expectation * is that this method is utilized for items such as SCSI to ATA * translation for commands like INQUIRY, READ CAPACITY, etc. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * @param[in] byte_offset This parameter specifies the offset into the data * buffers pointed to by the SGL. The byte offset starts at 0 * and continues until the last byte pointed to be the last SGL * element. * * @return A virtual address pointer to the location specified by the * parameters. */ uint8_t * scif_cb_io_request_get_virtual_address_from_sgl(void * scif_user_io_request, uint32_t byte_offset) { struct ISCI_IO_REQUEST *isci_request; union ccb *ccb; isci_request = scif_user_io_request; ccb = isci_request->ccb; /* * This callback is only invoked for SCSI/ATA translation of * PIO commands such as INQUIRY and READ_CAPACITY, to allow * the driver to write the translated data directly into the * data buffer. It is never invoked for READ/WRITE commands. * The driver currently assumes only READ/WRITE commands will * be unmapped. * * As a safeguard against future changes to unmapped commands, * add an explicit panic here should the DATA_MASK != VADDR. * Otherwise, we would return some garbage pointer back to the * caller which would result in a panic or more subtle data * corruption later on. */ if ((ccb->ccb_h.flags & CAM_DATA_MASK) != CAM_DATA_VADDR) panic("%s: requesting pointer into unmapped ccb", __func__); return (ccb->csio.data_ptr + byte_offset); } /** * @brief This callback method asks the user to provide the number of * bytes to be transferred as part of this request. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * * @return This method returns the number of payload data bytes to be * transferred for this IO request. */ uint32_t scif_cb_io_request_get_transfer_length(void * scif_user_io_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)scif_user_io_request; return (isci_request->ccb->csio.dxfer_len); } /** * @brief This callback method asks the user to provide the data direction * for this request. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * * @return This method returns the value of SCI_IO_REQUEST_DATA_OUT, * SCI_IO_REQUEST_DATA_IN, or SCI_IO_REQUEST_NO_DATA. */ SCI_IO_REQUEST_DATA_DIRECTION scif_cb_io_request_get_data_direction(void * scif_user_io_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)scif_user_io_request; switch (isci_request->ccb->ccb_h.flags & CAM_DIR_MASK) { case CAM_DIR_IN: return (SCI_IO_REQUEST_DATA_IN); case CAM_DIR_OUT: return (SCI_IO_REQUEST_DATA_OUT); default: return (SCI_IO_REQUEST_NO_DATA); } } /** * @brief This callback method asks the user to provide the address * to where the next Scatter-Gather Element is located. * * Details regarding usage: * - Regarding the first SGE: the user should initialize an index, * or a pointer, prior to construction of the request that will * reference the very first scatter-gather element. This is * important since this method is called for every scatter-gather * element, including the first element. * - Regarding the last SGE: the user should return NULL from this * method when this method is called and the SGL has exhausted * all elements. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * @param[in] current_sge_address This parameter specifies the address for * the current SGE (i.e. the one that has just processed). * @param[out] next_sge An address specifying the location for the next scatter * gather element to be processed. * * @return None. */ void scif_cb_io_request_get_next_sge(void * scif_user_io_request, void * current_sge_address, void ** next_sge) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *)scif_user_io_request; if (isci_request->current_sge_index == isci_request->num_segments) *next_sge = NULL; else { bus_dma_segment_t *sge = &isci_request->sge[isci_request->current_sge_index]; isci_request->current_sge_index++; *next_sge = sge; } } /** * @brief This callback method asks the user to provide the contents of the * "address" field in the Scatter-Gather Element. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * @param[in] sge_address This parameter specifies the address for the * SGE from which to retrieve the address field. * * @return A physical address specifying the contents of the SGE's address * field. */ SCI_PHYSICAL_ADDRESS scif_cb_sge_get_address_field(void *scif_user_io_request, void *sge_address) { bus_dma_segment_t *sge = (bus_dma_segment_t *)sge_address; return ((SCI_PHYSICAL_ADDRESS)sge->ds_addr); } /** * @brief This callback method asks the user to provide the contents of the * "length" field in the Scatter-Gather Element. * * @param[in] scif_user_io_request This parameter points to the user's * IO request object. It is a cookie that allows the user to * provide the necessary information for this callback. * @param[in] sge_address This parameter specifies the address for the * SGE from which to retrieve the address field. * * @return This method returns the length field specified inside the SGE * referenced by the sge_address parameter. */ uint32_t scif_cb_sge_get_length_field(void *scif_user_io_request, void *sge_address) { bus_dma_segment_t *sge = (bus_dma_segment_t *)sge_address; return ((uint32_t)sge->ds_len); } void isci_request_construct(struct ISCI_REQUEST *request, SCI_CONTROLLER_HANDLE_T scif_controller_handle, bus_dma_tag_t io_buffer_dma_tag, bus_addr_t physical_address) { request->controller_handle = scif_controller_handle; request->dma_tag = io_buffer_dma_tag; request->physical_address = physical_address; bus_dmamap_create(request->dma_tag, 0, &request->dma_map); callout_init(&request->timer, 1); } static void isci_io_request_construct(void *arg, bus_dma_segment_t *seg, int nseg, int error) { union ccb *ccb; struct ISCI_IO_REQUEST *io_request = (struct ISCI_IO_REQUEST *)arg; SCI_REMOTE_DEVICE_HANDLE_T *device = io_request->parent.remote_device_handle; SCI_STATUS status; io_request->num_segments = nseg; io_request->sge = seg; ccb = io_request->ccb; if (error != 0) { ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); return; } status = scif_io_request_construct( io_request->parent.controller_handle, io_request->parent.remote_device_handle, SCI_CONTROLLER_INVALID_IO_TAG, (void *)io_request, (void *)((char*)io_request + sizeof(struct ISCI_IO_REQUEST)), &io_request->sci_object); if (status != SCI_SUCCESS) { isci_io_request_complete(io_request->parent.controller_handle, device, io_request, (SCI_IO_STATUS)status); return; } sci_object_set_association(io_request->sci_object, io_request); bus_dmamap_sync(io_request->parent.dma_tag, io_request->parent.dma_map, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); status = (SCI_STATUS)scif_controller_start_io( io_request->parent.controller_handle, device, io_request->sci_object, SCI_CONTROLLER_INVALID_IO_TAG); if (status != SCI_SUCCESS) { isci_io_request_complete(io_request->parent.controller_handle, device, io_request, (SCI_IO_STATUS)status); return; } if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) callout_reset_sbt(&io_request->parent.timer, SBT_1MS * ccb->ccb_h.timeout, 0, isci_io_request_timeout, io_request, 0); } void isci_io_request_execute_scsi_io(union ccb *ccb, struct ISCI_CONTROLLER *controller) { target_id_t target_id = ccb->ccb_h.target_id; struct ISCI_REQUEST *request; struct ISCI_IO_REQUEST *io_request; struct ISCI_REMOTE_DEVICE *device = controller->remote_device[target_id]; int error; if (device == NULL) { ccb->ccb_h.status &= ~CAM_SIM_QUEUED; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_DEV_NOT_THERE; xpt_done(ccb); return; } if (sci_pool_empty(controller->request_pool)) { ccb->ccb_h.status &= ~CAM_SIM_QUEUED; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_REQUEUE_REQ; xpt_freeze_simq(controller->sim, 1); controller->is_frozen = TRUE; xpt_done(ccb); return; } ASSERT(device->is_resetting == FALSE); sci_pool_get(controller->request_pool, request); io_request = (struct ISCI_IO_REQUEST *)request; io_request->ccb = ccb; io_request->current_sge_index = 0; io_request->parent.remote_device_handle = device->sci_object; error = bus_dmamap_load_ccb(io_request->parent.dma_tag, io_request->parent.dma_map, ccb, isci_io_request_construct, io_request, 0x0); /* A resource shortage from BUSDMA will be automatically * continued at a later point, pushing the CCB processing * forward, which will in turn unfreeze the simq. */ if (error == EINPROGRESS) { xpt_freeze_simq(controller->sim, 1); ccb->ccb_h.flags |= CAM_RELEASE_SIMQ; } } void isci_io_request_timeout(void *arg) { struct ISCI_IO_REQUEST *request = (struct ISCI_IO_REQUEST *)arg; struct ISCI_REMOTE_DEVICE *remote_device = (struct ISCI_REMOTE_DEVICE *) sci_object_get_association(request->parent.remote_device_handle); struct ISCI_CONTROLLER *controller = remote_device->domain->controller; mtx_lock(&controller->lock); isci_remote_device_reset(remote_device, NULL); mtx_unlock(&controller->lock); } -#if __FreeBSD_version >= 900026 /** * @brief This callback method gets the size of and pointer to the buffer * (if any) containing the request buffer for an SMP request. * * @param[in] core_request This parameter specifies the SCI core's request * object associated with the SMP request. * @param[out] smp_request_buffer This parameter returns a pointer to the * payload portion of the SMP request - i.e. everything after * the SMP request header. * * @return Size of the request buffer in bytes. This does *not* include * the size of the SMP request header. */ static uint32_t smp_io_request_cb_get_request_buffer(SCI_IO_REQUEST_HANDLE_T core_request, uint8_t ** smp_request_buffer) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) sci_object_get_association(sci_object_get_association(core_request)); *smp_request_buffer = isci_request->ccb->smpio.smp_request + sizeof(SMP_REQUEST_HEADER_T); return (isci_request->ccb->smpio.smp_request_len - sizeof(SMP_REQUEST_HEADER_T)); } /** * @brief This callback method gets the SMP function for an SMP request. * * @param[in] core_request This parameter specifies the SCI core's request * object associated with the SMP request. * * @return SMP function for the SMP request. */ static uint8_t smp_io_request_cb_get_function(SCI_IO_REQUEST_HANDLE_T core_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) sci_object_get_association(sci_object_get_association(core_request)); SMP_REQUEST_HEADER_T *header = (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request; return (header->function); } /** * @brief This callback method gets the SMP frame type for an SMP request. * * @param[in] core_request This parameter specifies the SCI core's request * object associated with the SMP request. * * @return SMP frame type for the SMP request. */ static uint8_t smp_io_request_cb_get_frame_type(SCI_IO_REQUEST_HANDLE_T core_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) sci_object_get_association(sci_object_get_association(core_request)); SMP_REQUEST_HEADER_T *header = (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request; return (header->smp_frame_type); } /** * @brief This callback method gets the allocated response length for an SMP request. * * @param[in] core_request This parameter specifies the SCI core's request * object associated with the SMP request. * * @return Allocated response length for the SMP request. */ static uint8_t smp_io_request_cb_get_allocated_response_length( SCI_IO_REQUEST_HANDLE_T core_request) { struct ISCI_IO_REQUEST *isci_request = (struct ISCI_IO_REQUEST *) sci_object_get_association(sci_object_get_association(core_request)); SMP_REQUEST_HEADER_T *header = (SMP_REQUEST_HEADER_T *)isci_request->ccb->smpio.smp_request; return (header->allocated_response_length); } static SCI_STATUS isci_smp_request_construct(struct ISCI_IO_REQUEST *request) { SCI_STATUS status; SCIC_SMP_PASSTHRU_REQUEST_CALLBACKS_T callbacks; status = scif_request_construct(request->parent.controller_handle, request->parent.remote_device_handle, SCI_CONTROLLER_INVALID_IO_TAG, (void *)request, (void *)((char*)request + sizeof(struct ISCI_IO_REQUEST)), &request->sci_object); if (status == SCI_SUCCESS) { callbacks.scic_cb_smp_passthru_get_request = &smp_io_request_cb_get_request_buffer; callbacks.scic_cb_smp_passthru_get_function = &smp_io_request_cb_get_function; callbacks.scic_cb_smp_passthru_get_frame_type = &smp_io_request_cb_get_frame_type; callbacks.scic_cb_smp_passthru_get_allocated_response_length = &smp_io_request_cb_get_allocated_response_length; /* create the smp passthrough part of the io request */ status = scic_io_request_construct_smp_pass_through( scif_io_request_get_scic_handle(request->sci_object), &callbacks); } return (status); } void isci_io_request_execute_smp_io(union ccb *ccb, struct ISCI_CONTROLLER *controller) { SCI_STATUS status; target_id_t target_id = ccb->ccb_h.target_id; struct ISCI_REQUEST *request; struct ISCI_IO_REQUEST *io_request; SCI_REMOTE_DEVICE_HANDLE_T smp_device_handle; struct ISCI_REMOTE_DEVICE *end_device = controller->remote_device[target_id]; /* SMP commands are sent to an end device, because SMP devices are not * exposed to the kernel. It is our responsibility to use this method * to get the SMP device that contains the specified end device. If * the device is direct-attached, the handle will come back NULL, and * we'll just fail the SMP_IO with DEV_NOT_THERE. */ scif_remote_device_get_containing_device(end_device->sci_object, &smp_device_handle); if (smp_device_handle == NULL) { ccb->ccb_h.status &= ~CAM_SIM_QUEUED; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_DEV_NOT_THERE; xpt_done(ccb); return; } if (sci_pool_empty(controller->request_pool)) { ccb->ccb_h.status &= ~CAM_SIM_QUEUED; ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= CAM_REQUEUE_REQ; xpt_freeze_simq(controller->sim, 1); controller->is_frozen = TRUE; xpt_done(ccb); return; } ASSERT(device->is_resetting == FALSE); sci_pool_get(controller->request_pool, request); io_request = (struct ISCI_IO_REQUEST *)request; io_request->ccb = ccb; io_request->parent.remote_device_handle = smp_device_handle; status = isci_smp_request_construct(io_request); if (status != SCI_SUCCESS) { isci_io_request_complete(controller->scif_controller_handle, smp_device_handle, io_request, (SCI_IO_STATUS)status); return; } sci_object_set_association(io_request->sci_object, io_request); status = (SCI_STATUS) scif_controller_start_io( controller->scif_controller_handle, smp_device_handle, io_request->sci_object, SCI_CONTROLLER_INVALID_IO_TAG); if (status != SCI_SUCCESS) { isci_io_request_complete(controller->scif_controller_handle, smp_device_handle, io_request, (SCI_IO_STATUS)status); return; } if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) callout_reset_sbt(&io_request->parent.timer, SBT_1MS * ccb->ccb_h.timeout, 0, isci_io_request_timeout, request, 0); } -#endif