From patchwork Tue Mar 9 11:55:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 397144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 694D1C433E6 for ; Tue, 9 Mar 2021 11:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F8A665268 for ; Tue, 9 Mar 2021 11:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbhCILz2 (ORCPT ); Tue, 9 Mar 2021 06:55:28 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:59190 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbhCILzO (ORCPT ); Tue, 9 Mar 2021 06:55:14 -0500 Date: Tue, 09 Mar 2021 11:55:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=connolly.tech; s=protonmail; t=1615290911; bh=YQ/ejMQkQH4oouGuAIVVZajeoxvnPnnBuATeNAQthxE=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=hmWvAgqDAr+vM5Wmz4D00Ye4g/Lgn++N0kqhM4fXiDCNfVFhay/3GmuOxfRsZxhgv guPeF0ApZ+JjqhPnIWp4pCjduz+lta4yyAg45vDV9QP9x78PDbdkeUPzMxUGSSfnR5 vXXJjbN2vW4OzdSiYKHHSYyjZ4a3Q+jcnKyTfXLM= To: caleb@connolly.tech, Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" From: Caleb Connolly Cc: ejb@linux.ibm.com, stanley.chu@mediatek.com, cang@codeaurora.org, beanhuo@micron.com, jaegeuk@kernel.org, asutoshd@codeaurora.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig Reply-To: Caleb Connolly Subject: [PATCH v2 1/3] scsi: ufshcd: use a function to calculate versions Message-ID: <20210309115336.117206-2-caleb@connolly.tech> In-Reply-To: <20210309115336.117206-1-caleb@connolly.tech> References: <20210309115336.117206-1-caleb@connolly.tech> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Update the driver to use a function for referencing the UFS version. This replaces the UFSHCI_VERSION_xy macros, and supports comparisons where they did not. Suggested-by: Christoph Hellwig Signed-off-by: Caleb Connolly --- drivers/scsi/ufs/ufshcd.c | 64 +++++++++++++++++---------------------- drivers/scsi/ufs/ufshci.h | 17 ++++++----- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 77161750c9fb..a458c248e5ef 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -669,23 +669,12 @@ int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask, */ static inline u32 ufshcd_get_intr_mask(struct ufs_hba *hba) { - u32 intr_mask = 0; + if (hba->ufs_version == ufshci_version(1, 0)) + return INTERRUPT_MASK_ALL_VER_10; + if (hba->ufs_version <= ufshci_version(2, 0)) + return INTERRUPT_MASK_ALL_VER_11; - switch (hba->ufs_version) { - case UFSHCI_VERSION_10: - intr_mask = INTERRUPT_MASK_ALL_VER_10; - break; - case UFSHCI_VERSION_11: - case UFSHCI_VERSION_20: - intr_mask = INTERRUPT_MASK_ALL_VER_11; - break; - case UFSHCI_VERSION_21: - default: - intr_mask = INTERRUPT_MASK_ALL_VER_21; - break; - } - - return intr_mask; + return INTERRUPT_MASK_ALL_VER_21; } /** @@ -696,10 +685,22 @@ static inline u32 ufshcd_get_intr_mask(struct ufs_hba *hba) */ static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba) { + u32 ufshci_ver; + if (hba->quirks & UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION) - return ufshcd_vops_get_ufs_hci_version(hba); + ufshci_ver = ufshcd_vops_get_ufs_hci_version(hba); + else + ufshci_ver = ufshcd_readl(hba, REG_UFS_VERSION); - return ufshcd_readl(hba, REG_UFS_VERSION); + /* + * UFSHCI v1.x uses a different version scheme, in order + * to allow the use of comparisons with the ufshci_version + * function, we convert it to the same scheme as ufs 2.0+. + */ + if (ufshci_ver & 0x00010000) + return ufshci_version(1, ufshci_ver & 0x00000100); + + return ufshci_ver; } /** @@ -931,8 +932,7 @@ static inline bool ufshcd_is_hba_active(struct ufs_hba *hba) u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba) { /* HCI version 1.0 and 1.1 supports UniPro 1.41 */ - if ((hba->ufs_version == UFSHCI_VERSION_10) || - (hba->ufs_version == UFSHCI_VERSION_11)) + if (hba->ufs_version <= ufshci_version(1, 1)) return UFS_UNIPRO_VER_1_41; else return UFS_UNIPRO_VER_1_6; @@ -2335,7 +2335,7 @@ static void ufshcd_enable_intr(struct ufs_hba *hba, u32 intrs) { u32 set = ufshcd_readl(hba, REG_INTERRUPT_ENABLE); - if (hba->ufs_version == UFSHCI_VERSION_10) { + if (hba->ufs_version == ufshci_version(1, 0)) { u32 rw; rw = set & INTERRUPT_MASK_RW_VER_10; set = rw | ((set ^ intrs) & intrs); @@ -2355,7 +2355,7 @@ static void ufshcd_disable_intr(struct ufs_hba *hba, u32 intrs) { u32 set = ufshcd_readl(hba, REG_INTERRUPT_ENABLE); - if (hba->ufs_version == UFSHCI_VERSION_10) { + if (hba->ufs_version == ufshci_version(1, 0)) { u32 rw; rw = (set & INTERRUPT_MASK_RW_VER_10) & ~(intrs & INTERRUPT_MASK_RW_VER_10); @@ -2518,8 +2518,7 @@ static int ufshcd_compose_devman_upiu(struct ufs_hba *hba, u8 upiu_flags; int ret = 0; - if ((hba->ufs_version == UFSHCI_VERSION_10) || - (hba->ufs_version == UFSHCI_VERSION_11)) + if (hba->ufs_version <= ufshci_version(1, 1)) lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE; else lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; @@ -2546,8 +2545,7 @@ static int ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) u8 upiu_flags; int ret = 0; - if ((hba->ufs_version == UFSHCI_VERSION_10) || - (hba->ufs_version == UFSHCI_VERSION_11)) + if (hba->ufs_version <= ufshci_version(1, 1)) lrbp->command_type = UTP_CMD_TYPE_SCSI; else lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; @@ -6561,15 +6559,10 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, ufshcd_prepare_lrbp_crypto(NULL, lrbp); hba->dev_cmd.type = cmd_type; - switch (hba->ufs_version) { - case UFSHCI_VERSION_10: - case UFSHCI_VERSION_11: + if (hba->ufs_version <= ufshci_version(1, 1)) lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE; - break; - default: + else lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; - break; - } /* update the task tag in the request upiu */ req_upiu->header.dword_0 |= cpu_to_be32(tag); @@ -9298,10 +9291,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) /* Get UFS version supported by the controller */ hba->ufs_version = ufshcd_get_ufs_version(hba); - if ((hba->ufs_version != UFSHCI_VERSION_10) && - (hba->ufs_version != UFSHCI_VERSION_11) && - (hba->ufs_version != UFSHCI_VERSION_20) && - (hba->ufs_version != UFSHCI_VERSION_21)) + if (hba->ufs_version < UFSHCI_VER(1, 0)) dev_err(hba->dev, "invalid UFS version 0x%x\n", hba->ufs_version); diff --git a/drivers/scsi/ufs/ufshci.h b/drivers/scsi/ufs/ufshci.h index 6795e1f0e8f8..e1eb44bacbe4 100644 --- a/drivers/scsi/ufs/ufshci.h +++ b/drivers/scsi/ufs/ufshci.h @@ -74,13 +74,16 @@ enum { #define MINOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 0) #define MAJOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 16) -/* Controller UFSHCI version */ -enum { - UFSHCI_VERSION_10 = 0x00010000, /* 1.0 */ - UFSHCI_VERSION_11 = 0x00010100, /* 1.1 */ - UFSHCI_VERSION_20 = 0x00000200, /* 2.0 */ - UFSHCI_VERSION_21 = 0x00000210, /* 2.1 */ -}; +/* + * Controller UFSHCI version + * - 2.x and newer use the following scheme: + * major << 8 + minor << 4 + * - 1.x has been converted to match this in + * ufshcd_get_ufs_version() + */ +static inline u32 ufshci_version(u32 major, u32 minor) { + return (((major) << 8) + ((minor) << 4)); +} /* * HCDDID - Host Controller Identification Descriptor From patchwork Tue Mar 9 11:55:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 396450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C7A0C43381 for ; Tue, 9 Mar 2021 11:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A04665173 for ; Tue, 9 Mar 2021 11:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230198AbhCILz2 (ORCPT ); Tue, 9 Mar 2021 06:55:28 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:47948 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbhCILzS (ORCPT ); Tue, 9 Mar 2021 06:55:18 -0500 Date: Tue, 09 Mar 2021 11:55:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=connolly.tech; s=protonmail; t=1615290916; bh=VAaoHzPUuviXWZuHpXivJNsABEQ935p5HTpQ7ZaoB2w=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=qNXClnM7sU1Zna0Jl+6S/Fl/ZQzw22kdzuprFtmzzwtcj9PQWUev6tICt2R4yCBv7 UZjzcBlV88lGdVAj05iFQ9XHzMjYbrUC2724b1smet0oWqfbq/TGiTw6aUmlrz8A8L kehRn1eRykeuB9AiAHHSDDmcrS6ZbnBhWzDeXl4o= To: caleb@connolly.tech, Andy Gross , Bjorn Andersson , Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" From: Caleb Connolly Cc: ejb@linux.ibm.com, stanley.chu@mediatek.com, cang@codeaurora.org, beanhuo@micron.com, jaegeuk@kernel.org, asutoshd@codeaurora.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Reply-To: Caleb Connolly Subject: [PATCH v2 2/3] scsi: ufs: qcom: use ufshci_version function Message-ID: <20210309115336.117206-3-caleb@connolly.tech> In-Reply-To: <20210309115336.117206-1-caleb@connolly.tech> References: <20210309115336.117206-1-caleb@connolly.tech> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Replace the UFSHCI_VERSION_xy macros. Signed-off-by: Caleb Connolly --- drivers/scsi/ufs/ufs-qcom.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c index f97d7b0ae3b6..2d54dce0eeda 100644 --- a/drivers/scsi/ufs/ufs-qcom.c +++ b/drivers/scsi/ufs/ufs-qcom.c @@ -809,9 +809,9 @@ static u32 ufs_qcom_get_ufs_hci_version(struct ufs_hba *hba) struct ufs_qcom_host *host = ufshcd_get_variant(hba); if (host->hw_ver.major == 0x1) - return UFSHCI_VERSION_11; + return ufshci_version(1, 1); else - return UFSHCI_VERSION_20; + return ufshci_version(2, 0); } /** From patchwork Tue Mar 9 11:55:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 396449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5321DC433DB for ; Tue, 9 Mar 2021 11:56:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1588B6526C for ; Tue, 9 Mar 2021 11:56:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230341AbhCILz7 (ORCPT ); Tue, 9 Mar 2021 06:55:59 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:12862 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbhCILz2 (ORCPT ); Tue, 9 Mar 2021 06:55:28 -0500 Date: Tue, 09 Mar 2021 11:55:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=connolly.tech; s=protonmail; t=1615290926; bh=brHsaCtOjl6MivQM5JJde4HEiWC8nBnkoSck0wfdshI=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=GcC1guE+S6HRGRa9GM8U1AY983YwbssMHCAIU4NjzLIB/jIVr7XM5zmGplEEwdtD7 ZT+bNJ0la6y+cSxkCTicp4wnZ6GNESntpTBOYPeNYjtYK56u5A1CRH6rIQyWp3d8rS tp3BbZuzRRivLrUbe19GNyna6hitJiaBuPC3g1Fk= To: caleb@connolly.tech, Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" From: Caleb Connolly Cc: ejb@linux.ibm.com, stanley.chu@mediatek.com, cang@codeaurora.org, beanhuo@micron.com, jaegeuk@kernel.org, asutoshd@codeaurora.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Nitin Rawat Reply-To: Caleb Connolly Subject: [PATCH v2 3/3] scsi: ufshcd: remove version check Message-ID: <20210309115336.117206-4-caleb@connolly.tech> In-Reply-To: <20210309115336.117206-1-caleb@connolly.tech> References: <20210309115336.117206-1-caleb@connolly.tech> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This check is redundant as all UFS versions are currently supported. Signed-off-by: Nitin Rawat Signed-off-by: Caleb Connolly --- drivers/scsi/ufs/ufshcd.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a458c248e5ef..a6f317f0dc9b 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9291,10 +9291,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) /* Get UFS version supported by the controller */ hba->ufs_version = ufshcd_get_ufs_version(hba); - if (hba->ufs_version < UFSHCI_VER(1, 0)) - dev_err(hba->dev, "invalid UFS version 0x%x\n", - hba->ufs_version); - /* Get Interrupt bit mask per version */ hba->intr_mask = ufshcd_get_intr_mask(hba);