From patchwork Sun Dec 11 13:05:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Simchaev X-Patchwork-Id: 633455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2E9FC001B2 for ; Sun, 11 Dec 2022 13:05:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230299AbiLKNFc (ORCPT ); Sun, 11 Dec 2022 08:05:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbiLKNFZ (ORCPT ); Sun, 11 Dec 2022 08:05:25 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68349643C; Sun, 11 Dec 2022 05:05:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1670763924; x=1702299924; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=SWyM7wbZEyZVPXuv8kFl6aITesnHHHDe8q6cAolkwg8=; b=II+8m1pftt5nLQS8PSxzXfEu6c+8z5I5rhhzhfKsR2uDAxE7gvVwmrRu Ss2bs5fHE3wyDOgCwXfmtooMNsMpGLJd3IowpkQPHCipVPgYlRq+wL/5e XQ+ope9NXkbqvWRo6QH+dDV6VvrJvSIZWAOPzMJSMIRJ+IER3Jh7gjyx5 yKP+3y1RTMWz/bLRoM1qNvdhlaa30RBppY/NMYmz1NFV1FtpSOYx2EfLk 7iFq928h+cotALMzgNQTwBQMCxVTW+8n8Tl5muN1CoF61jFLxskmRr45a yPzUcDt1pf759WPvKRzDEiO5ly+rVP07/In101TZrogRK8l0xhk5Ds5ep w==; X-IronPort-AV: E=Sophos;i="5.96,236,1665417600"; d="scan'208";a="218373507" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2022 21:05:24 +0800 IronPort-SDR: 2HA5PcRhNW7Y6YwBFvLW70UvDP035VWCPGycvBFwhePrKpNW1d6B2xb00nBF/9rTzykeAdhjU9 o8lg6oR7BZ2cNJroJG2P8yh54KX3eqOlx8VDh6LY1rTVMsx9dZP6W9Xh1YVYrrcTcjLypCvsqI TmfsnRo6T0SbLCY8LwYmp/7106IMSBh+VBUYSE8afZx8IjakdWjZwi61eHS/YZLYTyhmgWGlLv ORj3QGUbsTPROP0eWULUoWFseDIwRwEQEGmcddC5w7/lbdPoQkTo5f3GfRBMPxbRsHsMS7CBT/ aXQ= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Dec 2022 04:23:50 -0800 IronPort-SDR: v/6xWXe4O2pFf1I6vNnRRyGvaWgAaQTAWAjn4t5CaGRpoqlLWfFjYDjkYBM54bD+KEIip9P75w sCh4HFsBX2ykWd3jNBlh/TNwn4wdhJhvSXsEwJiU3RjERsaXfnj9fM+IRPRs5ttgq0fHTz995e uU6CWvH9mm0O7koXVCtGuqQYOfJgLX/3uD8V8gMKlnyfgB5wO0vckoH6eaWW20dwxnDQhY+S37 piCkOaOfqqBlE2uV5HxX9TwKpy2dHns2wlcaTos/zZQThF5IpCpXXKBiUZIQv6NCBt/LnrFlmk 66o= WDCIronportException: Internal Received: from ilb001078.ad.shared (HELO ilb001078.sdcorp.global.sandisk.com) ([10.45.31.219]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Dec 2022 05:05:22 -0800 From: Arthur Simchaev To: martin.petersen@oracle.com Cc: beanhuo@micron.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Arthur Simchaev Subject: [PATCH v5 1/4] ufs: core: Remove redundant wb check Date: Sun, 11 Dec 2022 15:05:08 +0200 Message-Id: <1670763911-8695-2-git-send-email-Arthur.Simchaev@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> References: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We used to use the extended-feature field in the device descriptor, as an indication that the device supports ufs2.2 or later. Remove that as this check is specifically done few lines above. Reviewed-by: Bart Van Assche Reviewed-by: Bean Huo Signed-off-by: Arthur Simchaev Reviewed-by: Stanley Chu --- drivers/ufs/core/ufshcd.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 2dbe249..2e47c69 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -7608,10 +7608,6 @@ 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); From patchwork Sun Dec 11 13:05:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Simchaev X-Patchwork-Id: 633166 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74021C4332F for ; Sun, 11 Dec 2022 13:05:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230304AbiLKNFd (ORCPT ); Sun, 11 Dec 2022 08:05:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbiLKNF3 (ORCPT ); Sun, 11 Dec 2022 08:05:29 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 637FC7665; Sun, 11 Dec 2022 05:05:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1670763928; x=1702299928; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=hxKXO2yBuZAkpZohhnj1hmirpis+1mcmu51hWeoH3F4=; b=JWVmiF1Fnq6H868ROF0rIR9N56z0QhBrCG4jVs5iC8QNx1C30emj6mw5 8xwuJUakv09fF7zLzjJpwqKNxJLiI1/RTMSTdk1hQWPE6NkvFCiFecKXC Dvqrk3NdTJrylYO35zy1HLtrxnbXPsxW0G9Z2N4pPG21Xk5B6iFuezRp0 2Ub2KFAdmd8BUNYmIiR4j81KeR6H3DT+JeQIZnX2Xq6jvHJSle7QFMs+e Xc8uNQ+IyUf6xkUymmTpQeoxTT/ozkVuvCpoMDuH/KMM7YXaMnCvW91sE 9tBzF+FmHZnWV7kUFIqd9DIIRHuc9b0vfT8NR6uew0gAnhSOzP+Fdk6TJ A==; X-IronPort-AV: E=Sophos;i="5.96,236,1665417600"; d="scan'208";a="218373512" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2022 21:05:28 +0800 IronPort-SDR: xyO/QRTYLQgD8uyRZaQNOYgMGEDvhGLSdqT53wznt3IwDC/Sdzg5ZbkWdl2natW76tUdxnLcMa wbt3pAZANxyQ2HlOGjSWuFjh0UHgywH6zMVXZhaqzs3UeL9wIhIQbUyi9Y3orqORgIvb6O4zzG PCeSazoxNUyQGVmFTT4ye/rIQsmhmxywWwzRXm4ibANXIKPITLpqVPC6QDjpL33ZrE7nRsp2Ei HeT4+3vGdVF/NxDoms9gIhDMx/jAecQd2qh3p8keJziskxzX1rhwQbKtGbx5BWy+Cp48OX7YcU yso= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Dec 2022 04:23:54 -0800 IronPort-SDR: LZ/pc4pWCMD7Ue0sVyRonl9y/fBf2QxVRx+4gHBFlRsEEL+gUcXFzA41RJp3HZw89xrkqdfPGI b8bbQrBan2DaXCi3wZnOT60elxw9/LOmZN3NF+z33qPcOIA7LtVxDxu2UYA18LiWp+/hxpyUKJ 6mTplAdJGXgbQ4YXX/kE9cQEwcwGmReGvHWibX4CkEhAKUn0ir9KAGqvqbE8Oj9AM3ojdWkHsw 7jjPb1LZO4exCLtrHE0LhHssaL28BA0TxgqEs09cpBTapfMhYFNi6Hu92tnQwdIulpTDwVFbfp KYU= WDCIronportException: Internal Received: from ilb001078.ad.shared (HELO ilb001078.sdcorp.global.sandisk.com) ([10.45.31.219]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Dec 2022 05:05:26 -0800 From: Arthur Simchaev To: martin.petersen@oracle.com Cc: beanhuo@micron.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Arthur Simchaev Subject: [PATCH v5 2/4] ufs: core: Remove redundant desc_size variable from hba Date: Sun, 11 Dec 2022 15:05:09 +0200 Message-Id: <1670763911-8695-3-git-send-email-Arthur.Simchaev@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> References: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Always read the descriptor with QUERY_DESC_MAX_SIZE. According to the spec, the device returns the actual size Reviewed-by: Bean Huo Signed-off-by: Arthur Simchaev Reviewed-by: Bart Van Assche --- drivers/ufs/core/ufs_bsg.c | 6 +--- drivers/ufs/core/ufshcd-priv.h | 3 -- drivers/ufs/core/ufshcd.c | 72 ++++++++---------------------------------- drivers/ufs/core/ufshpb.c | 4 +-- include/ufs/ufs.h | 1 - include/ufs/ufshcd.h | 4 --- 6 files changed, 15 insertions(+), 75 deletions(-) diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c index b99e3f3..7eec38c 100644 --- a/drivers/ufs/core/ufs_bsg.c +++ b/drivers/ufs/core/ufs_bsg.c @@ -21,11 +21,7 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len, if (desc_size <= 0) return -EINVAL; - ufshcd_map_desc_id_to_length(hba, desc_id, desc_len); - if (!*desc_len) - return -EINVAL; - - *desc_len = min_t(int, *desc_len, desc_size); + *desc_len = min_t(int, QUERY_DESC_MAX_SIZE, desc_size); return 0; } diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index a9e8e1f..c52e2f3 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -70,9 +70,6 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, int ufshcd_hold(struct ufs_hba *hba, bool async); void ufshcd_release(struct ufs_hba *hba); -void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, - int *desc_length); - int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd); int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 2e47c69..bb032bc 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3369,37 +3369,6 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, } /** - * ufshcd_map_desc_id_to_length - map descriptor IDN to its length - * @hba: Pointer to adapter instance - * @desc_id: descriptor idn value - * @desc_len: mapped desc length (out) - */ -void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, - int *desc_len) -{ - if (desc_id >= QUERY_DESC_IDN_MAX || desc_id == QUERY_DESC_IDN_RFU_0 || - desc_id == QUERY_DESC_IDN_RFU_1) - *desc_len = 0; - else - *desc_len = hba->desc_size[desc_id]; -} -EXPORT_SYMBOL(ufshcd_map_desc_id_to_length); - -static void ufshcd_update_desc_length(struct ufs_hba *hba, - enum desc_idn desc_id, int desc_index, - unsigned char desc_len) -{ - if (hba->desc_size[desc_id] == QUERY_DESC_MAX_SIZE && - desc_id != QUERY_DESC_IDN_STRING && desc_index != UFS_RPMB_UNIT) - /* For UFS 3.1, the normal unit descriptor is 10 bytes larger - * than the RPMB unit, however, both descriptors share the same - * desc_idn, to cover both unit descriptors with one length, we - * choose the normal unit descriptor length by desc_index. - */ - hba->desc_size[desc_id] = desc_len; -} - -/** * ufshcd_read_desc_param - read the specified descriptor parameter * @hba: Pointer to adapter instance * @desc_id: descriptor idn value @@ -3419,20 +3388,13 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, { int ret; u8 *desc_buf; - int buff_len; + int buff_len = QUERY_DESC_MAX_SIZE; bool is_kmalloc = true; /* Safety check */ if (desc_id >= QUERY_DESC_IDN_MAX || !param_size) return -EINVAL; - /* Get the length of descriptor */ - ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len); - if (!buff_len) { - dev_err(hba->dev, "%s: Failed to get desc length\n", __func__); - return -EINVAL; - } - if (param_offset >= buff_len) { dev_err(hba->dev, "%s: Invalid offset 0x%x in descriptor IDN 0x%x, length 0x%x\n", __func__, param_offset, desc_id, buff_len); @@ -3470,7 +3432,6 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, /* Update descriptor length */ buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; - ufshcd_update_desc_length(hba, desc_id, desc_index, buff_len); if (is_kmalloc) { /* Make sure we don't copy more data than available */ @@ -4909,7 +4870,7 @@ static void ufshcd_setup_links(struct ufs_hba *hba, struct scsi_device *sdev) */ static void ufshcd_lu_init(struct ufs_hba *hba, struct scsi_device *sdev) { - int len = hba->desc_size[QUERY_DESC_IDN_UNIT]; + int len = QUERY_DESC_MAX_SIZE; u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); u8 lun_qdepth = hba->nutrs; u8 *desc_buf; @@ -7480,25 +7441,24 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba, static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba) { int ret; - int buff_len = hba->desc_size[QUERY_DESC_IDN_POWER]; u8 *desc_buf; u32 icc_level; - desc_buf = kmalloc(buff_len, GFP_KERNEL); + desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) return; ret = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_POWER, 0, 0, - desc_buf, buff_len); + desc_buf, QUERY_DESC_MAX_SIZE); if (ret) { dev_err(hba->dev, - "%s: Failed reading power descriptor.len = %d ret = %d", - __func__, buff_len, ret); + "%s: Failed reading power descriptor ret = %d", + __func__, ret); goto out; } icc_level = ufshcd_find_max_sup_active_icc_level(hba, desc_buf, - buff_len); + QUERY_DESC_MAX_SIZE); dev_dbg(hba->dev, "%s: setting icc_level 0x%x", __func__, icc_level); ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, @@ -7715,14 +7675,14 @@ static int ufs_get_device_desc(struct ufs_hba *hba) u8 *desc_buf; struct ufs_dev_info *dev_info = &hba->dev_info; - desc_buf = kmalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); + desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; goto out; } err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, - hba->desc_size[QUERY_DESC_IDN_DEVICE]); + QUERY_DESC_MAX_SIZE); if (err) { dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", __func__, err); @@ -7969,18 +7929,16 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) static int ufshcd_device_geo_params_init(struct ufs_hba *hba) { int err; - size_t buff_len; u8 *desc_buf; - buff_len = hba->desc_size[QUERY_DESC_IDN_GEOMETRY]; - desc_buf = kmalloc(buff_len, GFP_KERNEL); + desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; goto out; } err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_GEOMETRY, 0, 0, - desc_buf, buff_len); + desc_buf, QUERY_DESC_MAX_SIZE); if (err) { dev_err(hba->dev, "%s: Failed reading Geometry Desc. err = %d\n", __func__, err); @@ -7992,7 +7950,7 @@ static int ufshcd_device_geo_params_init(struct ufs_hba *hba) else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN] == 0) hba->dev_info.max_lu_supported = 8; - if (hba->desc_size[QUERY_DESC_IDN_GEOMETRY] >= + if (desc_buf[QUERY_DESC_LENGTH_OFFSET] >= GEOMETRY_DESC_PARAM_HPB_MAX_ACTIVE_REGS) ufshpb_get_geo_info(hba, desc_buf); @@ -8077,11 +8035,7 @@ static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba) static int ufshcd_device_params_init(struct ufs_hba *hba) { bool flag; - int ret, i; - - /* Init device descriptor sizes */ - for (i = 0; i < QUERY_DESC_IDN_MAX; i++) - hba->desc_size[i] = QUERY_DESC_MAX_SIZE; + int ret; /* Init UFS geometry descriptor related parameters */ ret = ufshcd_device_geo_params_init(hba); diff --git a/drivers/ufs/core/ufshpb.c b/drivers/ufs/core/ufshpb.c index be3fb24..19c9b5d 100644 --- a/drivers/ufs/core/ufshpb.c +++ b/drivers/ufs/core/ufshpb.c @@ -2382,12 +2382,10 @@ static int ufshpb_get_lu_info(struct ufs_hba *hba, int lun, { u16 max_active_rgns; u8 lu_enable; - int size; + int size = QUERY_DESC_MAX_SIZE; int ret; char desc_buf[QUERY_DESC_MAX_SIZE]; - ufshcd_map_desc_id_to_length(hba, QUERY_DESC_IDN_UNIT, &size); - ufshcd_rpm_get_sync(hba); ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_UNIT, lun, 0, diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index 1bba3fe..2fc7107 100644 --- a/include/ufs/ufs.h +++ b/include/ufs/ufs.h @@ -38,7 +38,6 @@ #define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F #define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID) #define UFS_UPIU_WLUN_ID (1 << 7) -#define UFS_RPMB_UNIT 0xC4 /* WriteBooster buffer is available only for the logical unit from 0 to 7 */ #define UFS_UPIU_MAX_WB_LUN_ID 8 diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 5cf81df..830abab 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -952,7 +952,6 @@ struct ufs_hba { bool is_urgent_bkops_lvl_checked; struct rw_semaphore clk_scaling_lock; - unsigned char desc_size[QUERY_DESC_IDN_MAX]; atomic_t scsi_block_reqs_cnt; struct device bsg_dev; @@ -1186,9 +1185,6 @@ void ufshcd_release(struct ufs_hba *hba); void ufshcd_clkgate_delay_set(struct device *dev, unsigned long value); -void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, - int *desc_length); - u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba); int ufshcd_get_vreg(struct device *dev, struct ufs_vreg *vreg); From patchwork Sun Dec 11 13:05:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Simchaev X-Patchwork-Id: 633454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CD55C4332F for ; Sun, 11 Dec 2022 13:05:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230313AbiLKNFu (ORCPT ); Sun, 11 Dec 2022 08:05:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbiLKNFc (ORCPT ); Sun, 11 Dec 2022 08:05:32 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C806643C; Sun, 11 Dec 2022 05:05:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1670763932; x=1702299932; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=lOhqg0Kj2b3Ceb+h0MzSJtC+pjsOicvAGo60FmKdVGU=; b=ddkI1w9QzAT6UmE8h8rjzN/Hvb9VsatILGAK2zLfIBskloBonsCq2dEY 6qh0qr4ilLLM0694+rsUvU/X6aetKV418WO1ajir+tduWNFjHJIZyRUII 1Eyt2cACjzz7Wt18A9JrLPLywOU0bB9OmQbkYQ+Z46/TLaO8/zK0YOaVK fhp4qS7542XVLEpobMaQANwDCWRuCr+ouQ6/0ITsb+2B4uXYSNxXorMd3 KuCcGaQXS8AMK+Nu5HY76zv3k+SsFC7L/claoDCGgrQo/q1TfQxtgfykq hbTDGnPM8Sl7qUCDKeSBIohPYFAindetpFvSxU+x4YJIkz9m/ybs5KSbS w==; X-IronPort-AV: E=Sophos;i="5.96,236,1665417600"; d="scan'208";a="218373517" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2022 21:05:32 +0800 IronPort-SDR: o0zBj+HN8/uru9NTHeYI2i80dM+swNp042xFEYiwIIkD9hFXlOzHy6rszglZY2FxrLfwZYxWgw 9nF2qTejwDD7n+eMY1nAbhLZexdSpSixmiHqA6WApSs5croSbLiBbB3Xch+2rEI9/Ho2/72le5 nx3d7B/WB6igQuQFAOuU2U+ddenHb4m4J955o/u5FE3Al7UVBWr/QOm2XEhUFuq78tOixN9yyN zvL2JmM1907TFovVZPoy7+P3YzDrilhertkQcNVGz9s3dNHyEXUto1srcyWD7KVsle8wnFM755 d8g= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Dec 2022 04:23:58 -0800 IronPort-SDR: r1LvllYZ4Wr/PWHUu/G+btmcckGzyClIzCTdRFhE3MUfvX7o1z5sKiISf7P4Um/tH2VSsfXpA0 rqbIvRNhbZBY97KNKExm7e+vbgJ29G54r+wI+NzDHralKOTasXnO7CYt9T+g0vaaCZVIIyC549 j/Kw8OGvTdv1LNQotE55twO9cwG8DWjeSs6wp2XLqAXzzGhh6lZcFxkaNDjgzC2HJTJa8DszG8 PHK5Sv6cap1C1e2Wys+YjsRUNLoNm19DEbJ7eH/lIl+isjVFyTk12tV7IvThdvx1vDtwsyDRih MFU= WDCIronportException: Internal Received: from ilb001078.ad.shared (HELO ilb001078.sdcorp.global.sandisk.com) ([10.45.31.219]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Dec 2022 05:05:30 -0800 From: Arthur Simchaev To: martin.petersen@oracle.com Cc: beanhuo@micron.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Arthur Simchaev Subject: [PATCH v5 3/4] ufs: core: Remove len parameter from ufshcd_set_active_icc_lvl Date: Sun, 11 Dec 2022 15:05:10 +0200 Message-Id: <1670763911-8695-4-git-send-email-Arthur.Simchaev@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> References: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org len argument is not used anymore in ufshcd_set_active_icc_lvl function. Reviewed-by: Bart Van Assche Reviewed-by: Bean Huo Signed-off-by: Arthur Simchaev --- drivers/ufs/core/ufshcd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index bb032bc..b6ef92d3 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -7394,12 +7394,11 @@ static u32 ufshcd_get_max_icc_level(int sup_curr_uA, u32 start_scan, * In case regulators are not initialized we'll return 0 * @hba: per-adapter instance * @desc_buf: power descriptor buffer to extract ICC levels from. - * @len: length of desc_buff * * Returns calculated ICC level */ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba, - const u8 *desc_buf, int len) + const u8 *desc_buf) { u32 icc_level = 0; @@ -7457,8 +7456,7 @@ static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba) goto out; } - icc_level = ufshcd_find_max_sup_active_icc_level(hba, desc_buf, - QUERY_DESC_MAX_SIZE); + icc_level = ufshcd_find_max_sup_active_icc_level(hba, desc_buf); dev_dbg(hba->dev, "%s: setting icc_level 0x%x", __func__, icc_level); ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, From patchwork Sun Dec 11 13:05:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Simchaev X-Patchwork-Id: 633165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BE20C4332F for ; Sun, 11 Dec 2022 13:05:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230311AbiLKNFw (ORCPT ); Sun, 11 Dec 2022 08:05:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbiLKNFt (ORCPT ); Sun, 11 Dec 2022 08:05:49 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FA20E0BC; Sun, 11 Dec 2022 05:05:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1670763936; x=1702299936; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=virbk6rhnfIZfWCJDUiMIpVN6qxlNGltOo4qipvPCg4=; b=krhbLUm7iVih87HtXsEhViw0nj2ZgwIzvYEwTgRR62wOjUQUqeGODsWS C07WsI/ewyV8YcSuNE1+cJZYqlooElgGjpmHadG4VUqwcJmH9ILdNfmDo bvMBhFblJj5XNWlRksU/0dzrdaNAPZrD2rwSkXBT24cOMxV4zpjlMZT6F ZwNlXrRC98hCmvHf8kIvklPmMZEt/Wi6W71Pm5EHFQa33MTtxSV+SOLtx v/LpyXN4yokduNKA79Ars5VKxvswRmcMyFrf4qtuR/vvIXaf/iR/0EGYR fnNbQZPfzcSpIx5DTPAnTqbJXzSqKCUxnY0h0U+p22TZRSADy6T2g6sAI w==; X-IronPort-AV: E=Sophos;i="5.96,236,1665417600"; d="scan'208";a="218373534" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2022 21:05:36 +0800 IronPort-SDR: Qdms07bEsYnc8iIAhuE29cgVdz20A9vPuewpeHUonXeSFjhFosaPzF0gyio+ehHwhw5Tr8w97l 8GLPrV5/tz0PFyjvAQyPGe7qziLntvQXWD8XJbpSwzWUSIjok5ssMiwEV5D+5u4RQi6Sex5Dp4 oMrkavTEKBydhLOuGMFssgeIa9XY0Po+KShWz0hHe4iWJlWiyEG/9Ye+uVnjYPe9lU02fQy+VE YWev4eGXOD6c+SyZpRLKZxXxYi7cmmZ4wEo/4w7kALcYAbXxzGqNyD5wjz4WI72u6Wc9jbiErQ ZKc= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Dec 2022 04:24:02 -0800 IronPort-SDR: CFUMjJwsfpiF5e1l0dQA7ZsNakqTfUOdKmtmfSMWGqOtsO5DxyIkRioWcmeC4RB5EwLDocTC0M Uxbt3/GzCcpMncSU3JSk2gc/cjyNit4rGJy9+Ge01y7I4/VqcqPGnT0k0JelbKVErsyBsSwLf7 iXNrxdFJr1FJdv3+W4u/K2ZfA+ZqK9Ye6uTr6blJVS33ByfaSM0XuSE5lKQchzKvOym28fh5ly 4rogVux9hirQHOD3lD1gClnj4CQNgZvcfXD1EehMkKgSJlSJaF6U7xH9hKDRiTaaPvxmlUmoDj QRg= WDCIronportException: Internal Received: from ilb001078.ad.shared (HELO ilb001078.sdcorp.global.sandisk.com) ([10.45.31.219]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Dec 2022 05:05:34 -0800 From: Arthur Simchaev To: martin.petersen@oracle.com Cc: beanhuo@micron.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Arthur Simchaev Subject: [PATCH v5 4/4] ufs: core: Remove ufshcd_map_desc_id_to_length function Date: Sun, 11 Dec 2022 15:05:11 +0200 Message-Id: <1670763911-8695-5-git-send-email-Arthur.Simchaev@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> References: <1670763911-8695-1-git-send-email-Arthur.Simchaev@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There shouldn't be any restriction of the descriptor size (not the descriptor id for that matter) up to QUERY_DESC_MAX_SIZE. According to the spec, the caller can use any descriptor size, and it is up to the device to return the actual size. Therefore there shouldn't be any sizes hardcoded in the kernel, nor any need to cache it, hence ufshcd_map_desc_id_to_length function is redundant. Always read the descriptors with QUERY_DESC_MAX_SIZE size. Reviewed-by: Bart Van Assche Reviewed-by: Bean Huo Suggested-by: Bean Huo Signed-off-by: Arthur Simchaev Reviewed-by: Bart Van Assche --- drivers/ufs/core/ufs_bsg.c | 1 - drivers/ufs/core/ufshcd.c | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c index 7eec38c..dc441ac 100644 --- a/drivers/ufs/core/ufs_bsg.c +++ b/drivers/ufs/core/ufs_bsg.c @@ -16,7 +16,6 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len, struct utp_upiu_query *qr) { int desc_size = be16_to_cpu(qr->length); - int desc_id = qr->idn; if (desc_size <= 0) return -EINVAL; diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index b6ef92d3..7f89626 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3395,12 +3395,6 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, if (desc_id >= QUERY_DESC_IDN_MAX || !param_size) return -EINVAL; - if (param_offset >= buff_len) { - dev_err(hba->dev, "%s: Invalid offset 0x%x in descriptor IDN 0x%x, length 0x%x\n", - __func__, param_offset, desc_id, buff_len); - return -EINVAL; - } - /* Check whether we need temp memory */ if (param_offset != 0 || param_size < buff_len) { desc_buf = kzalloc(buff_len, GFP_KERNEL); @@ -3413,15 +3407,23 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, /* Request for full descriptor */ ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, - desc_id, desc_index, 0, - desc_buf, &buff_len); - + desc_id, desc_index, 0, + desc_buf, &buff_len); if (ret) { dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d\n", __func__, desc_id, desc_index, param_offset, ret); goto out; } + /* Update descriptor length */ + buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; + + if (param_offset >= buff_len) { + dev_err(hba->dev, "%s: Invalid offset 0x%x in descriptor IDN 0x%x, length 0x%x\n", + __func__, param_offset, desc_id, buff_len); + return -EINVAL; + } + /* Sanity check */ if (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET] != desc_id) { dev_err(hba->dev, "%s: invalid desc_id %d in descriptor header\n", @@ -3430,9 +3432,6 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, goto out; } - /* Update descriptor length */ - buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; - if (is_kmalloc) { /* Make sure we don't copy more data than available */ if (param_offset >= buff_len)