From patchwork Thu Dec 8 23:18:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asutosh Das X-Patchwork-Id: 31524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp472863wrr; Thu, 8 Dec 2022 15:20:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7n1jn5zy882UU7ej5pgP2wthqyorOoLaxEO6lJkY1MZxDoY8PSkWZqzk16eAPBmTBzq+ba X-Received: by 2002:a17:902:ebc2:b0:185:441e:58ae with SMTP id p2-20020a170902ebc200b00185441e58aemr3685174plg.17.1670541648539; Thu, 08 Dec 2022 15:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670541648; cv=none; d=google.com; s=arc-20160816; b=oxY+W5cMU3+xJHP14LZn/7ZMqay47mw+reswp5HfjU8fj5DWnfNUufgi4GdvAMo0Wk K6uHrAriegRtnw59rSq6WSBUfjMIZXzrlvb6yqU+VeACmGpy97VVnv6FFYb+7VEEiBNr 5WJ4GixJqVOl5RFzUS2ClfG8ciPKCL8maDVHvaZ9W4urzSshrZgFfAw9R3SMUr/iucTR smG6Z47fbNVQm6aZIGbVgr9lRSd8xPw0YtFQuM4rnuKPtF1SzkSKoXut4g7BDqjrDRZb AGhcK02EicwHjE8sECnHP4TnHFvzh7onSwFo+B0+bIvz+z4ny5jEZbvWmmQ1ZCZXtcde 4nSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ySeoHANVoUPzDPpnomiG5X9f91zkrUH1wy9mvylqHe0=; b=gSMeZX7CcTkqG30TH1BAHRzf/uKXQfxIdrYy8G1cwMnOo/SPg+wIXkQlQMkSq0cAOr 1THLDhJ5p3X8eZItk4WZLCblhgodooWhHU1AnawbGQpCE53WdkE71yj9yjCScHEcc091 SvoqpzRZPg2HAI6O/xJYuOD6VSnFgCEeBz+jQ7MeDq9PI8+xbhYZydqbeVIO7hOn61fI azPFOlD+RJrRJ/lyTnCpSanF+HEgf+nJZd72LHpQwnjHULw5pmMcfNzdSrB9wGNGyhrk K8i9Y9B5HNBKSy44kdIqEjzesLOSFOEXZUgzWJt1aXfBORP/VpFLYJ1hI/ue60F1Sv1L R5Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=qdMGqaYa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a170902e1d400b00188d6e1b831si22132052pla.298.2022.12.08.15.20.35; Thu, 08 Dec 2022 15:20:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=qdMGqaYa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbiLHXTA (ORCPT + 99 others); Thu, 8 Dec 2022 18:19:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbiLHXS7 (ORCPT ); Thu, 8 Dec 2022 18:18:59 -0500 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EC3879C92; Thu, 8 Dec 2022 15:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1670541538; x=1702077538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ySeoHANVoUPzDPpnomiG5X9f91zkrUH1wy9mvylqHe0=; b=qdMGqaYa49KbQPzdKWuntnelIbcoHUhQ9vWI6dfyWJm4We1HPCfxHlez 5vwG2oe4pSVxrEW7EjFLY0c4k4m9Lef1t1ZIs2Yuc2wjxJwp+Ea+PL+1M JfkzP+GCx4X3qfb8Mtacem3kKxUE7gYCJ3RS6GPHFUyT2eOU263hGHdf1 Y=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-01.qualcomm.com with ESMTP; 08 Dec 2022 15:18:54 -0800 X-QCInternal: smtphost Received: from unknown (HELO nasanex01a.na.qualcomm.com) ([10.52.223.231]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 15:18:54 -0800 Received: from asutoshd-linux1.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 8 Dec 2022 15:18:54 -0800 From: Asutosh Das To: , , CC: , , , , , , , , , Asutosh Das , , Alim Akhtar , "James E.J. Bottomley" , Matthias Brugger , Jinyoung Choi , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Subject: [PATCH v11 01/16] ufs: core: Optimize duplicate code to read extended feature Date: Thu, 8 Dec 2022 15:18:27 -0800 Message-ID: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751689879895088031?= X-GMAIL-MSGID: =?utf-8?q?1751689879895088031?= The code to parse the extended feature is duplicated twice in the ufs core. Replace the duplicated code with a function. Signed-off-by: Asutosh Das Reviewed-by: Bart Van Assche Reviewed-by: Manivannan Sadhasivam Reviewed-by: Stanley Chu --- drivers/ufs/core/ufshcd.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 2dbe249..6ea22b5 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -215,6 +215,17 @@ ufs_get_desired_pm_lvl_for_dev_link_state(enum ufs_dev_pwr_mode dev_state, return UFS_PM_LVL_0; } +static unsigned int ufs_get_ext_ufs_feature(struct ufs_hba *hba, + const u8 *desc_buf) +{ + if (hba->desc_size[QUERY_DESC_IDN_DEVICE] < + DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4) + return 0; + + return get_unaligned_be32(desc_buf + + DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP); +} + static const struct ufs_dev_quirk ufs_fixups[] = { /* UFS cards deviations table */ { .wmanufacturerid = UFS_VENDOR_MICRON, @@ -7608,13 +7619,7 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, const u8 *desc_buf) (hba->dev_quirks & UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES))) goto wb_disabled; - if (hba->desc_size[QUERY_DESC_IDN_DEVICE] < - DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4) - goto wb_disabled; - - ext_ufs_feature = get_unaligned_be32(desc_buf + - DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP); - + ext_ufs_feature = ufs_get_ext_ufs_feature(hba, desc_buf); if (!(ext_ufs_feature & UFS_DEV_WRITE_BOOSTER_SUP)) goto wb_disabled; @@ -7668,7 +7673,7 @@ static void ufshcd_temp_notif_probe(struct ufs_hba *hba, const u8 *desc_buf) if (!(hba->caps & UFSHCD_CAP_TEMP_NOTIF) || dev_info->wspecversion < 0x300) return; - ext_ufs_feature = get_unaligned_be32(desc_buf + DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP); + ext_ufs_feature = ufs_get_ext_ufs_feature(hba, desc_buf); if (ext_ufs_feature & UFS_DEV_LOW_TEMP_NOTIF) mask |= MASK_EE_TOO_LOW_TEMP;