From owner-svn-src-stable-7@FreeBSD.ORG Mon Aug 27 15:54:52 2012 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 442141065673; Mon, 27 Aug 2012 15:54:52 +0000 (UTC) (envelope-from jimharris@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2CA188FC08; Mon, 27 Aug 2012 15:54:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q7RFsqE6020424; Mon, 27 Aug 2012 15:54:52 GMT (envelope-from jimharris@svn.freebsd.org) Received: (from jimharris@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q7RFspac020415; Mon, 27 Aug 2012 15:54:51 GMT (envelope-from jimharris@svn.freebsd.org) Message-Id: <201208271554.q7RFspac020415@svn.freebsd.org> From: Jim Harris Date: Mon, 27 Aug 2012 15:54:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r239736 - in stable/7/sys/dev/isci: . scil X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Aug 2012 15:54:52 -0000 Author: jimharris Date: Mon Aug 27 15:54:51 2012 New Revision: 239736 URL: http://svn.freebsd.org/changeset/base/239736 Log: MFC r239545, r239665: Fix/add support for SCSI UNMAP to ATA DSM translation. (Note: scsi_da does not support BIO_DELETE->SCSI_UNMAP on this stable branch, but I am MFC'ing the changes to keep a consistent driver across all stable releases.) This addresses kernel panic observed when sending SCSI UNMAP commands to SATA disks attached to isci(4). 1) Flesh out callback routines to allocate/free buffers needed for translating SCSI UNMAP data to ATA DSM data. 2) Add controller-level pool for storing buffers previously allocated for UNMAP translation, to lessen chance of no buffer available under memory pressure. 3) Ensure driver properly handles case where buffer pool is empty and contigmalloc returns NULL. 4) Clear freeze bit in isci_remote_device_release_lun_queue() before calling xpt_release_devq to ensure that any ccbs which immediately start during the call to xpt_release_devq() see an accurate picture of the frozen_lun_mask. This code path is extensively exercised when tagged read/write commands mix with non-tagged DSM commands. Sponsored by: Intel Modified: stable/7/sys/dev/isci/isci.c stable/7/sys/dev/isci/isci.h stable/7/sys/dev/isci/isci_controller.c stable/7/sys/dev/isci/isci_remote_device.c stable/7/sys/dev/isci/scil/sati_unmap.c stable/7/sys/dev/isci/scil/scif_sas_sati_binding.h stable/7/sys/dev/isci/scil/scif_sas_stp_io_request.c Directory Properties: stable/7/sys/ (props changed) Modified: stable/7/sys/dev/isci/isci.c ============================================================================== --- stable/7/sys/dev/isci/isci.c Mon Aug 27 15:52:09 2012 (r239735) +++ stable/7/sys/dev/isci/isci.c Mon Aug 27 15:54:51 2012 (r239736) @@ -185,6 +185,7 @@ isci_detach(device_t device) for (i = 0; i < isci->controller_count; i++) { struct ISCI_CONTROLLER *controller = &isci->controllers[i]; SCI_STATUS status; + void *unmap_buffer; if (controller->scif_controller_handle != NULL) { scic_controller_disable_interrupts( @@ -218,6 +219,13 @@ isci_detach(device_t device) if (controller->remote_device_memory != NULL) free(controller->remote_device_memory, M_ISCI); + + while (1) { + sci_pool_get(controller->unmap_buffer_pool, unmap_buffer); + if (unmap_buffer == NULL) + break; + contigfree(unmap_buffer, PAGE_SIZE, M_ISCI); + } } /* The SCIF controllers have been stopped, so we can now Modified: stable/7/sys/dev/isci/isci.h ============================================================================== --- stable/7/sys/dev/isci/isci.h Mon Aug 27 15:52:09 2012 (r239735) +++ stable/7/sys/dev/isci/isci.h Mon Aug 27 15:54:51 2012 (r239736) @@ -175,6 +175,7 @@ struct ISCI_CONTROLLER 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 Modified: stable/7/sys/dev/isci/isci_controller.c ============================================================================== --- stable/7/sys/dev/isci/isci_controller.c Mon Aug 27 15:52:09 2012 (r239735) +++ stable/7/sys/dev/isci/isci_controller.c Mon Aug 27 15:54:51 2012 (r239736) @@ -145,6 +145,14 @@ void scif_cb_controller_stop_complete(SC 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. * @@ -159,7 +167,29 @@ void scif_cb_controller_stop_complete(SC 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); } /** @@ -176,7 +206,16 @@ void scif_cb_controller_allocate_memory( 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, @@ -228,6 +267,8 @@ void isci_controller_construct(struct IS for ( int i = 0; i < SCI_MAX_TIMERS; i++ ) { sci_pool_put(controller->timer_pool, timer++); } + + sci_pool_initialize(controller->unmap_buffer_pool); } SCI_STATUS isci_controller_initialize(struct ISCI_CONTROLLER *controller) Modified: stable/7/sys/dev/isci/isci_remote_device.c ============================================================================== --- stable/7/sys/dev/isci/isci_remote_device.c Mon Aug 27 15:52:09 2012 (r239735) +++ stable/7/sys/dev/isci/isci_remote_device.c Mon Aug 27 15:54:51 2012 (r239736) @@ -278,12 +278,12 @@ isci_remote_device_release_lun_queue(str if (remote_device->frozen_lun_mask & (1 << lun)) { struct cam_path *path; + remote_device->frozen_lun_mask &= ~(1 << lun); xpt_create_path(&path, xpt_periph, cam_sim_path(remote_device->domain->controller->sim), remote_device->index, lun); xpt_release_devq(path, 1, TRUE); xpt_free_path(path); - remote_device->frozen_lun_mask &= ~(1 << lun); } } Modified: stable/7/sys/dev/isci/scil/sati_unmap.c ============================================================================== --- stable/7/sys/dev/isci/scil/sati_unmap.c Mon Aug 27 15:52:09 2012 (r239735) +++ stable/7/sys/dev/isci/scil/sati_unmap.c Mon Aug 27 15:54:51 2012 (r239736) @@ -335,8 +335,8 @@ SATI_STATUS sati_unmap_initial_processin sati_scsi_sense_data_construct( sequence, scsi_io, - SCSI_STATUS_CHECK_CONDITION, - SCSI_SENSE_ABORTED_COMMAND, + SCSI_STATUS_BUSY, + SCSI_SENSE_NO_SENSE, SCSI_ASC_NO_ADDITIONAL_SENSE, SCSI_ASCQ_NO_ADDITIONAL_SENSE ); Modified: stable/7/sys/dev/isci/scil/scif_sas_sati_binding.h ============================================================================== --- stable/7/sys/dev/isci/scil/scif_sas_sati_binding.h Mon Aug 27 15:52:09 2012 (r239735) +++ stable/7/sys/dev/isci/scil/scif_sas_sati_binding.h Mon Aug 27 15:54:51 2012 (r239736) @@ -183,22 +183,16 @@ extern "C" { { \ SCIF_SAS_REQUEST_T* fw_request = (SCIF_SAS_REQUEST_T*)scsi_io; \ SCI_PHYSICAL_MEMORY_DESCRIPTOR_T mde; \ - SCI_PHYSICAL_ADDRESS phys_addr; \ mde.virtual_address = NULL; \ - sci_cb_make_physical_address(mde.physical_address, 0, 0); \ sci_base_mde_construct( \ &mde, 4, length, SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS \ ); \ scif_cb_controller_allocate_memory( \ fw_request->device->domain->controller, &mde \ ); \ - scic_cb_io_request_get_physical_address(fw_request->device->domain->controller, \ - NULL, \ - mde.virtual_address, \ - &phys_addr); \ *(virt_address) = mde.virtual_address; \ - *(phys_address_low) = sci_cb_physical_address_lower(phys_addr); \ - *(phys_address_high) = sci_cb_physical_address_upper(phys_addr); \ + *(phys_address_low) = sci_cb_physical_address_lower(mde.physical_address); \ + *(phys_address_high) = sci_cb_physical_address_upper(mde.physical_address); \ } #define sati_cb_free_dma_buffer(scsi_io, virt_address) \ @@ -206,7 +200,6 @@ extern "C" { SCIF_SAS_REQUEST_T* fw_request = (SCIF_SAS_REQUEST_T*)scsi_io; \ SCI_PHYSICAL_MEMORY_DESCRIPTOR_T mde; \ mde.virtual_address = virt_address; \ - sci_cb_make_physical_address(mde.physical_address, 0, 0); \ sci_base_mde_construct( \ &mde, 4, 0, SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS \ ); \ Modified: stable/7/sys/dev/isci/scil/scif_sas_stp_io_request.c ============================================================================== --- stable/7/sys/dev/isci/scil/scif_sas_stp_io_request.c Mon Aug 27 15:52:09 2012 (r239735) +++ stable/7/sys/dev/isci/scil/scif_sas_stp_io_request.c Mon Aug 27 15:54:51 2012 (r239736) @@ -171,6 +171,8 @@ SCI_STATUS scif_sas_stp_io_request_const ); } + sati_sequence_terminate(&fw_io->parent.stp.sequence, fw_io, fw_io); + return SCI_SUCCESS; } /**