From patchwork Wed Feb 29 06:41:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Yaraganavi X-Patchwork-Id: 6995 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 20DDF23EB0 for ; Wed, 29 Feb 2012 06:44:28 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id DD1DBA180D6 for ; Wed, 29 Feb 2012 06:44:27 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so2747544iag.11 for ; Tue, 28 Feb 2012 22:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:x-forwarded-to:x-forwarded-for:delivered-to :received-spf:received-spf:dkim-signature:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=dCRQQyDvo4PdjqIeptNNdNNTPyhAYAV1nYkxBKXKrKo=; b=o6iM+lKdywnVwEhMmHsBNPIhWOsKhQayJndhLMTFK/w3ycXpyH5nEqv+8theJyxztE nzzmCVI3CQuCLobaFlBlCJk04RAJRk4UON3eN4SubTWwoT701TyjeOJLWZWLt/4fxxjJ FSn6zNBjvx18hL+EYMr3Ds3WUcGMWpoCoj1nA= MIME-Version: 1.0 Received: by 10.50.170.41 with SMTP id aj9mr20827250igc.0.1330497867688; Tue, 28 Feb 2012 22:44:27 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.11.10 with SMTP id r10csp25894ibr; Tue, 28 Feb 2012 22:44:27 -0800 (PST) Received: by 10.68.129.162 with SMTP id nx2mr2077098pbb.94.1330497866787; Tue, 28 Feb 2012 22:44:26 -0800 (PST) Received: from mail-pw0-f50.google.com (mail-pw0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id h9si6754753pbb.226.2012.02.28.22.44.23 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 28 Feb 2012 22:44:26 -0800 (PST) Received-SPF: pass (google.com: domain of santoshsy@gmail.com designates 209.85.160.50 as permitted sender) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of santoshsy@gmail.com designates 209.85.160.50 as permitted sender) smtp.mail=santoshsy@gmail.com; dkim=pass header.i=@gmail.com Received: by pbcwz7 with SMTP id wz7so2907053pbc.37 for ; Tue, 28 Feb 2012 22:44:23 -0800 (PST) Received-SPF: pass (google.com: domain of santoshsy@gmail.com designates 10.68.130.69 as permitted sender) client-ip=10.68.130.69; Received: from mr.google.com ([10.68.130.69]) by 10.68.130.69 with SMTP id oc5mr2800345pbb.5.1330497863796 (num_hops = 1); Tue, 28 Feb 2012 22:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=dCRQQyDvo4PdjqIeptNNdNNTPyhAYAV1nYkxBKXKrKo=; b=iLeseWacYaJJYp+StvWRxQw5kAwxy0ekfEaQ5tT3eyUw+8/Gr6/QdTURKf4CN9eNnv ARWXv4YbinUc5D0zNIKnNjF75IxuvmoM79bhHTmjYUbSqtz1737ayYSdPQLlQ1FnAP8c CS19DrHpeKP77yxjzyC6J9QMODEzZJLyR//hU= Received: by 10.68.130.69 with SMTP id oc5mr2351077pbb.5.1330497863743; Tue, 28 Feb 2012 22:44:23 -0800 (PST) Received: from girishks ([115.113.119.130]) by mx.google.com with ESMTPS id 3sm17830262pbx.66.2012.02.28.22.44.16 (version=SSLv3 cipher=OTHER); Tue, 28 Feb 2012 22:44:22 -0800 (PST) From: Santosh Y To: James.Bottomley@hansenpartnership.com Cc: linux-scsi@vger.kernel.org, patches@linaro.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, arnd.bergmann@linaro.org, saugata.das@linaro.org, dsaxena@linaro.org, stephen.doel@linaro.org, venkat@linaro.org, ilho215.lee@samsung.com, nala.la@samsung.com, girish.shivananjappa@linaro.org, vishak.g@samsung.com, k.rajesh@samsung.com, yejin.moon@samsung.com, sreekumar.c@samsung.com, vinholikatti@gmail.com, linkinjeon@gmail.com, michaelc@cs.wisc.edu, Santosh Yaraganavi Subject: [PATCH v3 3/5] [SCSI] ufshcd: UFSHCI error handling Date: Wed, 29 Feb 2012 12:11:52 +0530 Message-Id: <1330497714-26504-4-git-send-email-santoshsy@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1330497714-26504-1-git-send-email-santoshsy@gmail.com> References: <1330497714-26504-1-git-send-email-santoshsy@gmail.com> X-Gm-Message-State: ALoCoQmqPO4W+md0kh2umylDisMsau36oE3Iwv2vIek93yv1As2bM3WJDuMp6FV28F2aPOORxFzX From: Santosh Yaraganavi UFSHCI error handling includes support for: - UFS host controller errors - System bus errors - Unipro errors Signed-off-by: Santosh Yaraganavi Signed-off-by: Vinayak Holikatti Reviewed-by: Arnd Bergmann Reviewed-by: Vishak G Reviewed-by: Girish K S Reviewed-by: Namjae Jeon --- v2 -> v3: - use shost_priv() instead of accessing hostdata directly. v1 -> v2: - ufshcd_do_reset(): change return value to SUCCESS/FAILED, since the function can also be called from UFSHCD registered SCSI midlayer error handling routines. Ex: .eh_host_reset_handler which expects return value SUCCESS/FAILED - ufshcd_do_reset(): aquire spin_lock_irqsave only for instructions which share common data structure. drivers/scsi/ufs/ufshcd.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 97 insertions(+), 0 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 43b9c62..fa2fa96 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -138,6 +138,8 @@ struct uic_command { * @ufshcd_state: UFSHCD states * @int_enable_mask: Interrupt Mask Bits * @uic_workq: Work queue for UIC completion handling + * @feh_workq: Work queue for fatal controller error handling + * @errors: HBA errors */ struct ufs_hba { void __iomem *mmio_base; @@ -171,6 +173,10 @@ struct ufs_hba { /* Work Queues */ struct work_struct uic_workq; + struct work_struct feh_workq; + + /* HBA Errors */ + u32 errors; }; /** @@ -893,6 +899,9 @@ static int ufshcd_make_hba_operational(struct ufs_hba *hba) /* Configure interrupt aggregation */ ufshcd_config_int_aggr(hba, INT_AGGR_CONFIG); + if (hba->ufshcd_state == UFSHCD_STATE_RESET) + scsi_unblock_requests(hba->host); + hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; scsi_scan_host(hba->host); out: @@ -994,6 +1003,51 @@ static int ufshcd_initialize_hba(struct ufs_hba *hba) } /** + * ufshcd_do_reset - reset the host controller + * @hba: per adapter instance + * + * Returns SUCCESS/FAILED + */ +static int ufshcd_do_reset(struct ufs_hba *hba) +{ + struct ufshcd_lrb *lrbp; + unsigned long flags; + int tag; + + /* block commands from midlayer */ + scsi_block_requests(hba->host); + + spin_lock_irqsave(hba->host->host_lock, flags); + hba->ufshcd_state = UFSHCD_STATE_RESET; + + /* send controller to reset state */ + ufshcd_hba_stop(hba); + spin_unlock_irqrestore(hba->host->host_lock, flags); + + /* abort outstanding commands */ + for (tag = 0; tag < hba->nutrs; tag++) { + if (test_bit(tag, &hba->outstanding_reqs)) { + lrbp = &hba->lrb[tag]; + scsi_dma_unmap(lrbp->cmd); + lrbp->cmd->result = DID_RESET << 16; + lrbp->cmd->scsi_done(lrbp->cmd); + lrbp->cmd = NULL; + } + } + + /* clear outstanding request bit maps */ + hba->outstanding_reqs = 0; + + /* start the initialization process */ + if (ufshcd_initialize_hba(hba)) { + dev_err(&hba->pdev->dev, + "Reset: Controller initialization failed\n"); + return FAILED; + } + return SUCCESS; +} + +/** * ufshcd_slave_alloc - handle initial SCSI device configurations * @sdev: pointer to SCSI device * @@ -1240,12 +1294,54 @@ static void ufshcd_uic_cc_handler (struct work_struct *work) } /** + * ufshcd_fatal_err_handler - handle fatal errors + * @hba: per adapter instance + */ +static void ufshcd_fatal_err_handler(struct work_struct *work) +{ + struct ufs_hba *hba; + hba = container_of(work, struct ufs_hba, feh_workq); + + /* check if reset is already in progress */ + if (hba->ufshcd_state != UFSHCD_STATE_RESET) + ufshcd_do_reset(hba); +} + +/** + * ufshcd_err_handler - Check for fatal errors + * @work: pointer to a work queue structure + */ +static void ufshcd_err_handler(struct ufs_hba *hba) +{ + u32 reg; + + if (hba->errors & INT_FATAL_ERRORS) + goto fatal_eh; + + if (hba->errors & UIC_ERROR) { + + reg = readl(hba->mmio_base + + REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER); + if (reg & UIC_DATA_LINK_LAYER_ERROR_PA_INIT) + goto fatal_eh; + } + return; +fatal_eh: + hba->ufshcd_state = UFSHCD_STATE_ERROR; + schedule_work(&hba->feh_workq); +} + +/** * ufshcd_sl_intr - Interrupt service routine * @hba: per adapter instance * @intr_status: contains interrupts generated by the controller */ static void ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status) { + hba->errors = UFSHCD_ERROR_MASK & intr_status; + if (hba->errors) + ufshcd_err_handler(hba); + if (intr_status & UIC_COMMAND_COMPL) schedule_work(&hba->uic_workq); @@ -1492,6 +1588,7 @@ ufshcd_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Initialize work queues */ INIT_WORK(&hba->uic_workq, ufshcd_uic_cc_handler); + INIT_WORK(&hba->feh_workq, ufshcd_fatal_err_handler); /* IRQ registration */ err = request_irq(pdev->irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);