From patchwork Tue Oct 29 03:10:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 11216903 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66DDB139A for ; Tue, 29 Oct 2019 03:11:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 428B820862 for ; Tue, 29 Oct 2019 03:11:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="HLfw6Q9r"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="IIBiRQ6u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731255AbfJ2DLN (ORCPT ); Mon, 28 Oct 2019 23:11:13 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:34410 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbfJ2DLN (ORCPT ); Mon, 28 Oct 2019 23:11:13 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 2F9E860D93; Tue, 29 Oct 2019 03:11:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318672; bh=2xBHrDTj1u+VhhE2a1dXWL7IhuWYHPntPetQAGcWQok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HLfw6Q9rDiOwEUPL0axBjoki51BQSdj/s3s77/Y3XpDI82h+b0/jY7cNl81IKyDUa 173EMe8hLM5gTkwEOawEH+OZ9hCmMkUyPVL8P+CWp33ftp6Kgc2Q8RzNMD3dX1l5+3 FniAegsHrlH+5Cup0WsL0696JxXcxR/tuIfUjqNU= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from pacamara-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 0686160D86; Tue, 29 Oct 2019 03:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318671; bh=2xBHrDTj1u+VhhE2a1dXWL7IhuWYHPntPetQAGcWQok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IIBiRQ6uP76D14CR+uaT6XxCGNCBGbJ4KkG83lwGfajunzYt1vljTUIw2+glU0c8O Wbvd61MGVbOAHH0IilBv0mQDjsVRZssLrHN1jHAQv4gcEBTbGA9YSKF1UOnUuelgXI s/HAFL9KADjVLhk0xHDQktNiNtQU5UEI/rgw6KkM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 0686160D86 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: "James E.J. Bottomley" , "Martin K. Petersen" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/5] scsi: Adjust DBD setting in mode sense for caching mode page per LLD Date: Mon, 28 Oct 2019 20:10:50 -0700 Message-Id: <1572318655-28772-2-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1572318655-28772-1-git-send-email-cang@codeaurora.org> References: <1572318655-28772-1-git-send-email-cang@codeaurora.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Host sends MODE_SENSE_10 with caching mode page, to check if the device supports the cache feature. UFS JEDEC standards require DBD field to be set to 1. This patch allows LLD to define the setting of DBD if required. Signed-off-by: Can Guo --- drivers/scsi/sd.c | 6 +++++- include/scsi/scsi_host.h | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index aab4ed8..6d8194f 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2629,6 +2629,7 @@ static int sd_try_rc16_first(struct scsi_device *sdp) { int len = 0, res; struct scsi_device *sdp = sdkp->device; + struct Scsi_Host *host = sdp->host; int dbd; int modepage; @@ -2660,7 +2661,10 @@ static int sd_try_rc16_first(struct scsi_device *sdp) dbd = 8; } else { modepage = 8; - dbd = 0; + if (host->set_dbd_for_caching) + dbd = 8; + else + dbd = 0; } /* cautiously ask */ diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 2c3f0c5..3900987 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -650,6 +650,12 @@ struct Scsi_Host { unsigned no_scsi2_lun_in_cdb:1; /* + * Set "DBD" field in mode_sense caching mode page in case it is + * mandatory by LLD standard. + */ + unsigned set_dbd_for_caching:1; + + /* * Optional work queue to be utilized by the transport */ char work_q_name[20]; From patchwork Tue Oct 29 03:10:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 11216905 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76938913 for ; Tue, 29 Oct 2019 03:11:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53E4020862 for ; Tue, 29 Oct 2019 03:11:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="dVX3pMj1"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="Ubq0m4LR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731307AbfJ2DLU (ORCPT ); Mon, 28 Oct 2019 23:11:20 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:34574 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731303AbfJ2DLT (ORCPT ); Mon, 28 Oct 2019 23:11:19 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7F22F60E08; Tue, 29 Oct 2019 03:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318678; bh=QOMM1JLfQuLl5xgLBg3JI116eBhJGK2de0nSqrGNU6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dVX3pMj15T7WqcTurLoipaP0G5+pAjClPFoe7bONEf3HjYjXauSTEJRbNjePOJgMo BwH6kt5+cH5H/F5ceCunjY7wuimhgXU3pKVG6DJ7CXrWWecpRdIDwD9XCR3LB8bj3V w7F7MjlHHrJ69beC1yF3ETRvMt7cT2UBIrZiM17E= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from pacamara-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 8E73260D8F; Tue, 29 Oct 2019 03:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318677; bh=QOMM1JLfQuLl5xgLBg3JI116eBhJGK2de0nSqrGNU6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ubq0m4LRLu+EDr4v9KDVDIEILFfcv2VsPxXA2get/pdgmaa5lqKb+IlEVrDuoJTXA RjTyf2DAWxXrI/CpvuoOmpzVrog3yvT6+Pk4TJnJsMUt9BfWquMgiFvNWAobjpcgCT VXmGJUoxOJaFTSDQCARS+B7oaOofbhH51PDj2oCM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8E73260D8F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Tomas Winkler , Subhash Jadavani , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/5] scsi: ufs: Set DBD setting in mode sense for caching mode page Date: Mon, 28 Oct 2019 20:10:51 -0700 Message-Id: <1572318655-28772-3-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1572318655-28772-1-git-send-email-cang@codeaurora.org> References: <1572318655-28772-1-git-send-email-cang@codeaurora.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Host sends MODE_SENSE_10 with caching mode page, to check if the device supports the cache feature. UFS standards requires DBD field to be set to 1. Some card vendors are more strict and check the DBD field, hence respond with CHECK_CONDITION (Sense key set to ILLEGAL_REQUEST and ASC set to INVALID FIELD IN CDB). As a result of the CHECK_CONDITION response, host assumes that the device doesn't support the cache feature and doesn't send SYNCHORONIZE_CACHE commands to flush the device cache. This can result in data corruption in case of sudden power down, when there is data stored in the device cache. This patch fixes the DBD field setting in case of caching mode page. Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index c28c144..101b4d0 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8329,6 +8329,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) host->max_channel = UFSHCD_MAX_CHANNEL; host->unique_id = host->host_no; host->max_cmd_len = UFS_CDB_SIZE; + host->set_dbd_for_caching = 1; hba->max_pwr_info.is_valid = false; From patchwork Tue Oct 29 03:10:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 11216907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 068F3913 for ; Tue, 29 Oct 2019 03:12:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6D6821479 for ; Tue, 29 Oct 2019 03:12:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="hhbJeLAU"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="Ff3B31zP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731380AbfJ2DMm (ORCPT ); Mon, 28 Oct 2019 23:12:42 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:35038 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726740AbfJ2DMm (ORCPT ); Mon, 28 Oct 2019 23:12:42 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id BBB8F60D97; Tue, 29 Oct 2019 03:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318761; bh=6TC+OuBMy0RodpaYAtahI7XYuucLX/4lHyCtAfJNH/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hhbJeLAUJliq0/zLkAdYhXLEPtoJg9JCz7HbA+p2TEwvZvKuUvLPdAybfTA0cE2ha DMT5JohPAjOKEdFvspOcXy+c8Y4jC/q/aJutg+eqxEVL+ys2uZYdGrshLpLcd34OZn yVNLozOa1WUfQvsxnS3qJXHE/4wYVQ+pdpgCP3aI= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from pacamara-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 123A660CDD; Tue, 29 Oct 2019 03:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318760; bh=6TC+OuBMy0RodpaYAtahI7XYuucLX/4lHyCtAfJNH/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ff3B31zPcPdPmXbhKymDEeiE0AEoBTj10pWFr4sFoEeMzMNuW1gusleKxooBqvS0V l9a3hv1uG8aVUJuuWzruuAfHtoXMthVpTMUiFEIR1ZKA5EcHIOlrbgHYWevcamG78D Hq4jAm0MVxdu5zZViCyjktPqL5UStGUNjjMRW6LE= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 123A660CDD Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Tomas Winkler , Subhash Jadavani , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 3/5] scsi: ufs: Release clock if DMA map fails Date: Mon, 28 Oct 2019 20:10:52 -0700 Message-Id: <1572318655-28772-4-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1572318655-28772-1-git-send-email-cang@codeaurora.org> References: <1572318655-28772-1-git-send-email-cang@codeaurora.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In queuecommand path, if DMA map fails, it bails out with clock held. In this case, release the clock to keep its usage paired. Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 101b4d0..6e9236a 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2480,6 +2480,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) if (err) { lrbp->cmd = NULL; clear_bit_unlock(tag, &hba->lrb_in_use); + ufshcd_release(hba); goto out; } /* Make sure descriptors are ready before ringing the doorbell */ From patchwork Tue Oct 29 03:10:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 11216909 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D56B8139A for ; Tue, 29 Oct 2019 03:13:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8CD621721 for ; Tue, 29 Oct 2019 03:13:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="aYRbNw7G"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="B4F25mVY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728254AbfJ2DNt (ORCPT ); Mon, 28 Oct 2019 23:13:49 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:35498 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbfJ2DNt (ORCPT ); Mon, 28 Oct 2019 23:13:49 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7C22660D90; Tue, 29 Oct 2019 03:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318827; bh=scuAnT5H3nEdJxrQRggDSKVMJUJJS7VQFEZmMK5pJLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aYRbNw7GzDyJVFZtUXqxXDE0d8H+D43Xe1rGb3Dm0Zaljoi/VGM0lRW2bUNLcW/3L RH/8n1zfsvq3krjFJDO8QqeZ/1VLtvutfnUAPOfxi8jB4yNnquY6nvCJR4uqOVvVSP keuummUd7dMFOojKby5vPXID6YbBtyFaRm/wD+go= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from pacamara-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id F312C60CDD; Tue, 29 Oct 2019 03:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318825; bh=scuAnT5H3nEdJxrQRggDSKVMJUJJS7VQFEZmMK5pJLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B4F25mVYUQFmzJrCitT2mqxz1WPlQ1YbFP3pylRCDNBa+0wx2zUwElifiq49HLxF6 cCkNXZelCLy5SiOgMKa61qewwq5FMLzfoXWkMr/RrGtYN4ZsgmQJ5by0edxjLRng05 M1WVHAEM+rh74dFlv2IdEKaG+6t8X3t7CsBdNOPQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org F312C60CDD Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Tomas Winkler , Subhash Jadavani , Allison Randal , Greg Kroah-Hartman , Thomas Gleixner , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 4/5] scsi: ufs: Do not clear the DL layer timers Date: Mon, 28 Oct 2019 20:10:53 -0700 Message-Id: <1572318655-28772-5-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1572318655-28772-1-git-send-email-cang@codeaurora.org> References: <1572318655-28772-1-git-send-email-cang@codeaurora.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org During power mode change, PACP_PWR_Req frame sends PAPowerModeUserData parameters (and they are considered valid by device if Flags[4] - UserDataValid bit is set in the same frame). Currently we don't set these PAPowerModeUserData parameters and hardware always sets UserDataValid bit which would clear all the DL layer timeout values of the peer device after the power mode change. This change sets the PAPowerModeUserData[0..5] to UniPro specification recommended default values, in addition we are also setting the relevant DME_LOCAL_* timer attributes as required by UFS HCI specification. Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 20 ++++++++++++++++++++ drivers/scsi/ufs/unipro.h | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6e9236a..34efa8a 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4084,6 +4084,26 @@ static int ufshcd_change_power_mode(struct ufs_hba *hba, ufshcd_dme_set(hba, UIC_ARG_MIB(PA_HSSERIES), pwr_mode->hs_rate); + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA0), + DL_FC0ProtectionTimeOutVal_Default); + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA1), + DL_TC0ReplayTimeOutVal_Default); + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA2), + DL_AFC0ReqTimeOutVal_Default); + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA3), + DL_FC1ProtectionTimeOutVal_Default); + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA4), + DL_TC1ReplayTimeOutVal_Default); + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA5), + DL_AFC1ReqTimeOutVal_Default); + + ufshcd_dme_set(hba, UIC_ARG_MIB(DME_LocalFC0ProtectionTimeOutVal), + DL_FC0ProtectionTimeOutVal_Default); + ufshcd_dme_set(hba, UIC_ARG_MIB(DME_LocalTC0ReplayTimeOutVal), + DL_TC0ReplayTimeOutVal_Default); + ufshcd_dme_set(hba, UIC_ARG_MIB(DME_LocalAFC0ReqTimeOutVal), + DL_AFC0ReqTimeOutVal_Default); + ret = ufshcd_uic_change_pwr_mode(hba, pwr_mode->pwr_rx << 4 | pwr_mode->pwr_tx); diff --git a/drivers/scsi/ufs/unipro.h b/drivers/scsi/ufs/unipro.h index f539f87..3dc4d8b 100644 --- a/drivers/scsi/ufs/unipro.h +++ b/drivers/scsi/ufs/unipro.h @@ -161,6 +161,17 @@ /* PHY Adapter Protocol Constants */ #define PA_MAXDATALANES 4 +#define DL_FC0ProtectionTimeOutVal_Default 8191 +#define DL_TC0ReplayTimeOutVal_Default 65535 +#define DL_AFC0ReqTimeOutVal_Default 32767 +#define DL_FC1ProtectionTimeOutVal_Default 8191 +#define DL_TC1ReplayTimeOutVal_Default 65535 +#define DL_AFC1ReqTimeOutVal_Default 32767 + +#define DME_LocalFC0ProtectionTimeOutVal 0xD041 +#define DME_LocalTC0ReplayTimeOutVal 0xD042 +#define DME_LocalAFC0ReqTimeOutVal 0xD043 + /* PA power modes */ enum { FAST_MODE = 1, From patchwork Tue Oct 29 03:10:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 11216911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6082D139A for ; Tue, 29 Oct 2019 03:13:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D65B21479 for ; Tue, 29 Oct 2019 03:13:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="Jr2stk+4"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="flcGcZBO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729945AbfJ2DNz (ORCPT ); Mon, 28 Oct 2019 23:13:55 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:35654 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbfJ2DNz (ORCPT ); Mon, 28 Oct 2019 23:13:55 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B9A1760DD3; Tue, 29 Oct 2019 03:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318833; bh=cwk+ckjYkrKQl/u2OYjJHGZKW5UmPXnaICWGpGNCLX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jr2stk+49qBQFkJ9EvKuvT+VSmgFw7K8P/IS1sFhu1C6bIvI4wT037PzfQYkg7XIG o3JBOR3b1ccTOtC7rTiw8GQui4rtCdWVv3OxQyR0wbpb8Kt7oqpJnA50ksn1x5vyZj UNdS5RGtUdMhq8tfeCojPzpMcY5lhtR5NdOLtKbk= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from pacamara-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 05F3D60D96; Tue, 29 Oct 2019 03:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1572318832; bh=cwk+ckjYkrKQl/u2OYjJHGZKW5UmPXnaICWGpGNCLX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=flcGcZBOsTX+xfvs1L5gdLjjsGjNEml75WVrHJUJC83Lt7JJiE0boXEqR9Nx0Vt5s 1tvuX1UjyOOCayLdSQyF7dIUXVDsEQV+zK9ThM8rDlSLfmhRwve7erGXqrgcdPswVQ SHSnkQI5/3ldgq9lxf3Yw2NC3J/B+MoxXDvx7TkU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 05F3D60D96 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Tomas Winkler , Subhash Jadavani , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 5/5] scsi: ufs: Do not free irq in suspend Date: Mon, 28 Oct 2019 20:10:54 -0700 Message-Id: <1572318655-28772-6-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1572318655-28772-1-git-send-email-cang@codeaurora.org> References: <1572318655-28772-1-git-send-email-cang@codeaurora.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If PM QoS is enabled and we set request type to PM_QOS_REQ_AFFINE_IRQ then freeing up the irq makes the free_irq() print out warning with call stack. We don't really need to free up irq during suspend, disabling it during suspend and reenabling it during resume should be good enough. Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 34efa8a..fb36a51 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -266,26 +266,18 @@ static inline bool ufshcd_valid_tag(struct ufs_hba *hba, int tag) return tag >= 0 && tag < hba->nutrs; } -static inline int ufshcd_enable_irq(struct ufs_hba *hba) +static inline void ufshcd_enable_irq(struct ufs_hba *hba) { - int ret = 0; - if (!hba->is_irq_enabled) { - ret = request_irq(hba->irq, ufshcd_intr, IRQF_SHARED, UFSHCD, - hba); - if (ret) - dev_err(hba->dev, "%s: request_irq failed, ret=%d\n", - __func__, ret); + enable_irq(hba->irq); hba->is_irq_enabled = true; } - - return ret; } static inline void ufshcd_disable_irq(struct ufs_hba *hba) { if (hba->is_irq_enabled) { - free_irq(hba->irq, hba); + disable_irq(hba->irq); hba->is_irq_enabled = false; } } @@ -7927,9 +7919,7 @@ static int ufshcd_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) goto out; /* enable the host irq as host controller would be active soon */ - ret = ufshcd_enable_irq(hba); - if (ret) - goto disable_irq_and_vops_clks; + ufshcd_enable_irq(hba); ret = ufshcd_vreg_set_hpm(hba); if (ret)