From patchwork Sun May 31 15:08:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11580677 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 1713690 for ; Sun, 31 May 2020 15:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F06E020801 for ; Sun, 31 May 2020 15:08:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M/A4dMsd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728234AbgEaPIt (ORCPT ); Sun, 31 May 2020 11:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728207AbgEaPIr (ORCPT ); Sun, 31 May 2020 11:08:47 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEDB0C05BD43; Sun, 31 May 2020 08:08:46 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id a2so6766728ejb.10; Sun, 31 May 2020 08:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/iVfVdmH13jpJlRd9mjv8JKjfCbbit0p7BrDulSQioM=; b=M/A4dMsdA7oB6kxYWqouN9nahc4JHTXW0VazjPUHZBSHVyQL+y+Vjmv5vxlctK3mJY dnlxbqLkCXmOwropflL3WBpglEKKxmo0PC6WAcTXPJaM/ulC0IGc9gRDQZMTtTLsSmhL y/wQI9uNmKwqXsCCMz4Nlzv3J4F3O7uTlVqU44mD+0s4NmwX5sjcS5nBaJkBN9a4vBrJ TRSaKPuFLcYfc55eCm/iJAKkqFB7UtxgJZuzd4OwuO5XcAPOtLvi9PLkclgTnm5JCNjJ OXaAanLwMgp7ncaEN4jGeiIEVAcf+VgrsqgGF8B9S9uWSxQhMrHbrFo4jMZGRhtiklVs +SlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/iVfVdmH13jpJlRd9mjv8JKjfCbbit0p7BrDulSQioM=; b=ACXLWvj80TTpX6ZtCsV4nIxeyKAnPcEOlafghtmFMmXsFU3t1DMvufXq5ioesdS7KY vjtAzwuSwpV9RmnPjmQ9+ahxxyNkC0QdcysSF4S+R23Eq8evqn92y8u0Gb7aZKxWOofs ICStbp4tcar/QCcKe0Y4bbjoS26SwrSw4k8lGqNh6Tz4aGbXNyNfTbYp8mqALB5KW9YN MqHsQgG3hPyuoJgmbfM1aM/f2S41d7vNES/OlN36bjM3eUDpbUHX0L8QuWx4rR0lNzRi HchgTaE+HcmK20ApjImh2w1qnuL/+oXoCS2C7V27o+gzu8Nc1kxmERyGdZtdrrM59l9v IOBw== X-Gm-Message-State: AOAM530/MbBSbJZ4hqLVQdt0Kaq4vVHYU9CcZKA2elCfHELWTASDLjgE ugI7Bdz1cjB+UYOa18MwGNg= X-Google-Smtp-Source: ABdhPJwj5bRavswqPW99VjIlO003CrdkKjCdgvvYy8Dvx07Hn7dV1wRJeUJZkMl/GOfFG4jBKeaBlg== X-Received: by 2002:a17:906:264a:: with SMTP id i10mr2617046ejc.210.1590937725546; Sun, 31 May 2020 08:08:45 -0700 (PDT) Received: from localhost.localdomain (ip5f5bfcfd.dynamic.kabel-deutschland.de. [95.91.252.253]) by smtp.gmail.com with ESMTPSA id a62sm9564928edf.38.2020.05.31.08.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 May 2020 08:08:45 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/5] scsi: ufs: delete ufshcd_read_desc() Date: Sun, 31 May 2020 17:08:28 +0200 Message-Id: <20200531150831.9946-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200531150831.9946-1-huobean@gmail.com> References: <20200531150831.9946-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo Delete ufshcd_read_desc(). Instead, let caller directly call ufshcd_read_desc_param(). Signed-off-by: Bean Huo Reviewed-by: Avri Altman Reviewed-by: Bart van Assche Reviewed-by: Stanley Chu --- drivers/scsi/ufs/ufshcd.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index f57acfbf9d60..f7e8bfefe3d4 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3221,16 +3221,6 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, return ret; } -static inline int ufshcd_read_desc(struct ufs_hba *hba, - enum desc_idn desc_id, - int desc_index, - void *buf, - u32 size) -{ - return ufshcd_read_desc_param(hba, desc_id, desc_index, 0, buf, size); -} - - /** * struct uc_string_id - unicode string * @@ -3278,9 +3268,8 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, if (!uc_str) return -ENOMEM; - ret = ufshcd_read_desc(hba, QUERY_DESC_IDN_STRING, - desc_index, uc_str, - QUERY_DESC_MAX_SIZE); + ret = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_STRING, desc_index, 0, + (u8 *)uc_str, QUERY_DESC_MAX_SIZE); if (ret < 0) { dev_err(hba->dev, "Reading String Desc failed after %d retries. err = %d\n", QUERY_REQ_RETRIES, ret); @@ -6684,8 +6673,8 @@ static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba) if (!desc_buf) return; - ret = ufshcd_read_desc(hba, QUERY_DESC_IDN_POWER, 0, - desc_buf, buff_len); + ret = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_POWER, 0, 0, + desc_buf, buff_len); if (ret) { dev_err(hba->dev, "%s: Failed reading power descriptor.len = %d ret = %d", @@ -6886,8 +6875,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba) goto out; } - err = ufshcd_read_desc(hba, QUERY_DESC_IDN_DEVICE, 0, desc_buf, - hba->desc_size.dev_desc); + err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, + hba->desc_size.dev_desc); if (err) { dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", __func__, err); @@ -7168,8 +7157,8 @@ static int ufshcd_device_geo_params_init(struct ufs_hba *hba) goto out; } - err = ufshcd_read_desc(hba, QUERY_DESC_IDN_GEOMETRY, 0, - desc_buf, buff_len); + err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_GEOMETRY, 0, 0, + desc_buf, buff_len); if (err) { dev_err(hba->dev, "%s: Failed reading Geometry Desc. err = %d\n", __func__, err); From patchwork Sun May 31 15:08:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11580683 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 3C02C739 for ; Sun, 31 May 2020 15:09:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22C07207C4 for ; Sun, 31 May 2020 15:09:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q/nmFo7C" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728318AbgEaPJG (ORCPT ); Sun, 31 May 2020 11:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728228AbgEaPIs (ORCPT ); Sun, 31 May 2020 11:08:48 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA469C061A0E; Sun, 31 May 2020 08:08:47 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id c35so5361633edf.5; Sun, 31 May 2020 08:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r8r5svcWyImZ6w7QoO3hY5ggCN6NWRqtw0VlABPCcR8=; b=q/nmFo7CUpwfne018Nypvy5mSG+2CnTbbEqtMuHqK6OVR43W1EdoXTh7a6zQ1JrFOM x3DdCWFfLx0NfP3kDyVIqh5XYLTm13+0mvGpas32T2MsTFXs1KWkBdG1kd1LWwexCkfK nUxFtYuBRDWYj3jKWDVFN5sv+QScuc2fc9X/cE6YdNH38GY7yDie9gi3+ykZIN1AFteI HMimIvkeMDlH6mMslVBZeXWDMJvLRFEW2+WqI3lhqfvQCvBniTCjsZ5qfPuEYfvzqCeJ 0wrOFFdgv8qVxplqzOXHsNwRhdCBWM7dLSLi5zthu6AwC/dyL0za8P33cGM4RcgMQ69V 6jeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r8r5svcWyImZ6w7QoO3hY5ggCN6NWRqtw0VlABPCcR8=; b=Zb9ulma2N7iuE9waIPNTUBtMnAyxOp9+938HVzS1lANmllGxO2wJYmfoFf8/ekxI6G mwPJ8u3grojI/pKKxmLGXt0bSbE6HBIe+QufAugfCi8dEv7IqGC991w2lPu4xXVwiqUM OFQSEd7Fj7il56/liKhm4E0rKxK0i2R4AJtuaSFc9q+KhpDc2ujgQbOt92kRsLgYgRAv W3jbcfM/K6PTTPbCkEn4/ugxZASyV4ZcTofr3ptUGqf1XlWo7StczJfMMuYUE+WO8yBl HMy6pi0VsyEynK+OM/KM7LmCnIlrpwVEJPz9PlYPMkh95XolnPxqkbPYH8ipk3wXwuB3 JEbQ== X-Gm-Message-State: AOAM533JGkYeF+99leS2olsGy2MKXXRJ3UCBJqPNuMyRNPDohnPZvfaa sofMRts5ckBldC8bj1uko4U= X-Google-Smtp-Source: ABdhPJwPp/0rbwWDA74IuEo4/S5AWdiSYnpFEIw8E9n9aVzwavto22sZhP8NUGmZlYy7C1guSNxO8w== X-Received: by 2002:a50:f052:: with SMTP id u18mr17198321edl.16.1590937726497; Sun, 31 May 2020 08:08:46 -0700 (PDT) Received: from localhost.localdomain (ip5f5bfcfd.dynamic.kabel-deutschland.de. [95.91.252.253]) by smtp.gmail.com with ESMTPSA id a62sm9564928edf.38.2020.05.31.08.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 May 2020 08:08:46 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/5] scsi: ufs: fix potential access NULL pointer while memcpy Date: Sun, 31 May 2020 17:08:29 +0200 Message-Id: <20200531150831.9946-4-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200531150831.9946-1-huobean@gmail.com> References: <20200531150831.9946-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo If param_offset is not 0, the memcpy length shouldn't be the true descriptor length. Fixes: a4b0e8a4e92b ("scsi: ufs: Factor out ufshcd_read_desc_param") Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index f7e8bfefe3d4..bc52a0e89cd3 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3211,7 +3211,7 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, /* Check wherher we will not copy more data, than available */ if (is_kmalloc && param_size > buff_len) - param_size = buff_len; + param_size = buff_len - param_offset; if (is_kmalloc) memcpy(param_read_buf, &desc_buf[param_offset], param_size); From patchwork Sun May 31 15:08:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11580679 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 DBACD739 for ; Sun, 31 May 2020 15:09:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B47C020723 for ; Sun, 31 May 2020 15:09:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R7D3L74e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728283AbgEaPI5 (ORCPT ); Sun, 31 May 2020 11:08:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728244AbgEaPIu (ORCPT ); Sun, 31 May 2020 11:08:50 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00A9DC05BD43; Sun, 31 May 2020 08:08:49 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id e12so121609eds.2; Sun, 31 May 2020 08:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FUV3upzTpDsnWlGYv+J5UrYZ5jbXrNtSp19U2s7r7w4=; b=R7D3L74elew7Nu+7bgp5ssYh1YpTmLKF+GHWai7snZxzkhgd0vkTFjG0WDKkgQLXhX PfdsB/BgQzEIRKJEVprNfh3seNN4MG7Y6t/rBZ1QVzvbnkYQfFoufbbhqHvbv5dwLscv khf4p8DZOrTYJDURnHHJpYBAGUCAe9Lak8z3mOSRGf/7Ys+GqTPJyHTutUeEPxLTgRJ4 nhtXVsRziGduKCwZzmN0p9GZU7DSZPvIPj75p31c3t0eazFCrsB2Q4ZXHvJ9764AeYYb Z5x76NH+LLsssY+YK5SfPCGDujOzFMlS/n9jxEaas6lTTS9sqboAnvdiWj9ojb3IZGcO /Urw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FUV3upzTpDsnWlGYv+J5UrYZ5jbXrNtSp19U2s7r7w4=; b=aD13Fuhn070/KnIG6c+EWVchN8dwDBjSPnoH82jRknRlYKT5kB8nspQQv2TBVwDdzo X+1noQqoLmdOkngdvPw2NppYsWuhLOxo7osvkJwZxjCZ4BYIuty4KyVHWaTk8ZwbNFPs lg0x2nd6mZOlcwocICSHVsrsJFEQmBLVjVF2Ks96ZMjxnN+FmKLlmLpl6+t4fEtD5B0o nSByAb3dxvuO+B/agrJOblchRNQfUXRHfMy+WvmiMZ0Sq6GUzBm4BUCm+IZOl/iWHKYb kpOyZ2yoSjgNeMFGiNxPb8zBn+EL5qsAgMCI0Z34yI8AxcCdRkSFi90XsuvazZtRkqfO vmDg== X-Gm-Message-State: AOAM532g6OftfRaZC3/ianBnPRz81y2u2CUPWKaZqBou/2G1HQvSDZvY 0OAKCou3rMbYsc9PSLfVvig= X-Google-Smtp-Source: ABdhPJwdBxMv6bIxBE7TZMLpz4FazVURqLlQgum/QVTMoAmma0JiM/myj+2k6Opc2mriL9IsReiBOQ== X-Received: by 2002:aa7:d613:: with SMTP id c19mr4762428edr.321.1590937727675; Sun, 31 May 2020 08:08:47 -0700 (PDT) Received: from localhost.localdomain (ip5f5bfcfd.dynamic.kabel-deutschland.de. [95.91.252.253]) by smtp.gmail.com with ESMTPSA id a62sm9564928edf.38.2020.05.31.08.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 May 2020 08:08:47 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/5] scsi: ufs: cleanup ufs initialization path Date: Sun, 31 May 2020 17:08:30 +0200 Message-Id: <20200531150831.9946-5-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200531150831.9946-1-huobean@gmail.com> References: <20200531150831.9946-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo At UFS initialization stage, to get the length of the descriptor, ufshcd_read_desc_length() being called 6 times. Instead, we will capture the descriptor size the first time we'll read it. Delete unnecessary redundant code, remove ufshcd_read_desc_length(), ufshcd_init_desc_sizes(), and boost UFS initialization. Signed-off-by: Bean Huo Reviewed-by: Bart van Assche Reviewed-by: Stanley Chu --- drivers/scsi/ufs/ufs.h | 10 --- drivers/scsi/ufs/ufs_bsg.c | 5 +- drivers/scsi/ufs/ufshcd.c | 168 ++++++++----------------------------- drivers/scsi/ufs/ufshcd.h | 16 +--- 4 files changed, 38 insertions(+), 161 deletions(-) diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index fadba3a3bbcd..6548ef102eb9 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -200,16 +200,6 @@ enum desc_header_offset { QUERY_DESC_DESC_TYPE_OFFSET = 0x01, }; -enum ufs_desc_def_size { - QUERY_DESC_DEVICE_DEF_SIZE = 0x59, - QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90, - QUERY_DESC_UNIT_DEF_SIZE = 0x2D, - QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06, - QUERY_DESC_GEOMETRY_DEF_SIZE = 0x48, - QUERY_DESC_POWER_DEF_SIZE = 0x62, - QUERY_DESC_HEALTH_DEF_SIZE = 0x25, -}; - /* Unit descriptor parameters offsets in bytes*/ enum unit_desc_param { UNIT_DESC_PARAM_LEN = 0x0, diff --git a/drivers/scsi/ufs/ufs_bsg.c b/drivers/scsi/ufs/ufs_bsg.c index 53dd87628cbe..27f54615ee84 100644 --- a/drivers/scsi/ufs/ufs_bsg.c +++ b/drivers/scsi/ufs/ufs_bsg.c @@ -11,13 +11,12 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len, { int desc_size = be16_to_cpu(qr->length); int desc_id = qr->idn; - int ret; if (desc_size <= 0) return -EINVAL; - ret = ufshcd_map_desc_id_to_length(hba, desc_id, desc_len); - if (ret || !*desc_len) + 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); diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index bc52a0e89cd3..45d1fef982a9 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3052,95 +3052,32 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, return err; } -/** - * ufshcd_read_desc_length - read the specified descriptor length from header - * @hba: Pointer to adapter instance - * @desc_id: descriptor idn value - * @desc_index: descriptor index - * @desc_length: pointer to variable to read the length of descriptor - * - * Return 0 in case of success, non-zero otherwise - */ -static int ufshcd_read_desc_length(struct ufs_hba *hba, - enum desc_idn desc_id, - int desc_index, - int *desc_length) -{ - int ret; - u8 header[QUERY_DESC_HDR_SIZE]; - int header_len = QUERY_DESC_HDR_SIZE; - - if (desc_id >= QUERY_DESC_IDN_MAX) - return -EINVAL; - - ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, - desc_id, desc_index, 0, header, - &header_len); - - if (ret) { - dev_err(hba->dev, "%s: Failed to get descriptor header id %d", - __func__, desc_id); - return ret; - } else if (desc_id != header[QUERY_DESC_DESC_TYPE_OFFSET]) { - dev_warn(hba->dev, "%s: descriptor header id %d and desc_id %d mismatch", - __func__, header[QUERY_DESC_DESC_TYPE_OFFSET], - desc_id); - ret = -EINVAL; - } - - *desc_length = header[QUERY_DESC_LENGTH_OFFSET]; - return ret; - -} - /** * 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) - * - * Return 0 in case of success, non-zero otherwise */ -int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, - enum desc_idn desc_id, int *desc_len) +void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, + int *desc_len) { - switch (desc_id) { - case QUERY_DESC_IDN_DEVICE: - *desc_len = hba->desc_size.dev_desc; - break; - case QUERY_DESC_IDN_POWER: - *desc_len = hba->desc_size.pwr_desc; - break; - case QUERY_DESC_IDN_GEOMETRY: - *desc_len = hba->desc_size.geom_desc; - break; - case QUERY_DESC_IDN_CONFIGURATION: - *desc_len = hba->desc_size.conf_desc; - break; - case QUERY_DESC_IDN_UNIT: - *desc_len = hba->desc_size.unit_desc; - break; - case QUERY_DESC_IDN_INTERCONNECT: - *desc_len = hba->desc_size.interc_desc; - break; - case QUERY_DESC_IDN_STRING: - *desc_len = QUERY_DESC_MAX_SIZE; - break; - case QUERY_DESC_IDN_HEALTH: - *desc_len = hba->desc_size.hlth_desc; - break; - case QUERY_DESC_IDN_RFU_0: - case QUERY_DESC_IDN_RFU_1: - *desc_len = 0; - break; - default: + if (desc_id >= QUERY_DESC_IDN_MAX || desc_id == QUERY_DESC_IDN_RFU_0 || + desc_id == QUERY_DESC_IDN_RFU_1) *desc_len = 0; - return -EINVAL; - } - return 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, + unsigned char desc_len) +{ + if (hba->desc_size[desc_id] == QUERY_DESC_MAX_SIZE && + desc_id != QUERY_DESC_IDN_STRING) + hba->desc_size[desc_id] = desc_len; +} + /** * ufshcd_read_desc_param - read the specified descriptor parameter * @hba: Pointer to adapter instance @@ -3168,16 +3105,11 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, if (desc_id >= QUERY_DESC_IDN_MAX || !param_size) return -EINVAL; - /* Get the max length of descriptor from structure filled up at probe - * time. - */ - ret = ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len); - - /* Sanity checks */ - if (ret || !buff_len) { - dev_err(hba->dev, "%s: Failed to get full descriptor length", - __func__); - return ret; + /* 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", __func__); + return -EINVAL; } /* Check whether we need temp memory */ @@ -3209,6 +3141,10 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, goto out; } + /* Update descriptor length */ + buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; + ufshcd_update_desc_length(hba, desc_id, buff_len); + /* Check wherher we will not copy more data, than available */ if (is_kmalloc && param_size > buff_len) param_size = buff_len - param_offset; @@ -6665,7 +6601,7 @@ 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.pwr_desc; + int buff_len = hba->desc_size[QUERY_DESC_IDN_POWER]; u8 *desc_buf; u32 icc_level; @@ -6783,7 +6719,8 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf) if (!ufshcd_is_wb_allowed(hba)) return; - if (hba->desc_size.dev_desc < DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4) + if (hba->desc_size[QUERY_DESC_IDN_DEVICE] < + DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4) goto wb_disabled; hba->dev_info.d_ext_ufs_feature_sup = @@ -6876,7 +6813,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba) } err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, - hba->desc_size.dev_desc); + hba->desc_size[QUERY_DESC_IDN_DEVICE]); if (err) { dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", __func__, err); @@ -7104,53 +7041,13 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) hba->req_abort_count = 0; } -static void ufshcd_init_desc_sizes(struct ufs_hba *hba) -{ - int err; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_DEVICE, 0, - &hba->desc_size.dev_desc); - if (err) - hba->desc_size.dev_desc = QUERY_DESC_DEVICE_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_POWER, 0, - &hba->desc_size.pwr_desc); - if (err) - hba->desc_size.pwr_desc = QUERY_DESC_POWER_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_INTERCONNECT, 0, - &hba->desc_size.interc_desc); - if (err) - hba->desc_size.interc_desc = QUERY_DESC_INTERCONNECT_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_CONFIGURATION, 0, - &hba->desc_size.conf_desc); - if (err) - hba->desc_size.conf_desc = QUERY_DESC_CONFIGURATION_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_UNIT, 0, - &hba->desc_size.unit_desc); - if (err) - hba->desc_size.unit_desc = QUERY_DESC_UNIT_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_GEOMETRY, 0, - &hba->desc_size.geom_desc); - if (err) - hba->desc_size.geom_desc = QUERY_DESC_GEOMETRY_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_HEALTH, 0, - &hba->desc_size.hlth_desc); - if (err) - hba->desc_size.hlth_desc = QUERY_DESC_HEALTH_DEF_SIZE; -} - 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.geom_desc; + buff_len = hba->desc_size[QUERY_DESC_IDN_GEOMETRY]; desc_buf = kmalloc(buff_len, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; @@ -7246,13 +7143,14 @@ 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; + int ret, i; /* Clear any previous UFS device information */ memset(&hba->dev_info, 0, sizeof(hba->dev_info)); - /* Init check for device descriptor sizes */ - ufshcd_init_desc_sizes(hba); + /* Init device descriptor sizes */ + for (i = 0; i < QUERY_DESC_IDN_MAX; i++) + hba->desc_size[i] = QUERY_DESC_MAX_SIZE; /* Init UFS geometry descriptor related parameters */ ret = ufshcd_device_geo_params_init(hba); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index e3dfb48e669e..5ea090d82ddc 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -236,16 +236,6 @@ struct ufs_dev_cmd { struct ufs_query query; }; -struct ufs_desc_size { - int dev_desc; - int pwr_desc; - int geom_desc; - int interc_desc; - int unit_desc; - int conf_desc; - int hlth_desc; -}; - /** * struct ufs_clk_info - UFS clock related info * @list: list headed by hba->clk_list_head @@ -738,7 +728,7 @@ struct ufs_hba { bool is_urgent_bkops_lvl_checked; struct rw_semaphore clk_scaling_lock; - struct ufs_desc_size desc_size; + unsigned char desc_size[QUERY_DESC_IDN_MAX]; atomic_t scsi_block_reqs_cnt; struct device bsg_dev; @@ -975,8 +965,8 @@ 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); -int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, - int *desc_length); +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); From patchwork Sun May 31 15:08:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11580681 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 C045090 for ; Sun, 31 May 2020 15:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A464520723 for ; Sun, 31 May 2020 15:09:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uPKWmbqu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728272AbgEaPI4 (ORCPT ); Sun, 31 May 2020 11:08:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728252AbgEaPIu (ORCPT ); Sun, 31 May 2020 11:08:50 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08455C061A0E; Sun, 31 May 2020 08:08:50 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id z5so6826523ejb.3; Sun, 31 May 2020 08:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MEIjMYiUChbqFAFH7gikTnN2cVqo8tkhFxOw2OxjyaU=; b=uPKWmbquwWYeY5eW/cl9nAqdXzw/jh5U6svQPC4aapN5yV+zz9gi2aSPkFDSdngsqj qOS7wLyjCgd6tmm+o9JvjlEmadKDLNrK+R3+HtAh99a54pRSXn/iFb5sQmWme+LryTKJ GoKFIr5sNIfhChDRObuRtjT9SDL2/bQzDSmk8mMpgpfc0KXfJI26mIDlVfJC9nCSGpoB oJv+PuIceaRe/zSxkkEoZdXM/TKECYQBd+fwB97pPumDBniN7si8TM/uF5QWogGvtk7l qseS4dx91NabCA8ohoJTyOv9NRtgw8u4UWIAhBWkk9G30gz7I9LhKPZpIYg3mdUk+yA7 YogA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MEIjMYiUChbqFAFH7gikTnN2cVqo8tkhFxOw2OxjyaU=; b=myuU4pqUXHRV+qpwHuhla5Kfalujt99yMHqaDuihh/Zx/mb7HjybnCNyC2qn2VYf2e isk+6Sd36uN6KrQ+D/8nRBXsMb4srI4iDEeTA7CCXm6S27YS1HYQZdH6x/nJxWJeKcyx j1NsuNiQ3HDhrvD+DcGm9jddMjeYbJfPAbeggPdVQ21bfMHSkgweOWvwNW2jAW4WanIO HabPZik0zIgTZCChDSz5Ue9QvrrqDSWp7qM0CixQ020t+MKVSYvdF0FvjRSEDjkGoHpz yOFHhQKCO2XG7UclfBJIccLWmcV85ITLIBMQHVasSq/W7Lu/1n+Xc3rGDYh6aJ0Er0qT 5oCA== X-Gm-Message-State: AOAM5325j+2gP0cLbYIRJgniNL78rb+vPOGtBZTQ4TUwJwXh0Sj5kkY1 6uO7e1vL69jUv55OZTuO/tY= X-Google-Smtp-Source: ABdhPJwl6uguCs5YC7SshKNrvK5ot6uJOWR0R080eVq1DZdYCsj15GQLxNw1iENyVsAo+Qjmn0pwQQ== X-Received: by 2002:a17:906:6686:: with SMTP id z6mr10337247ejo.258.1590937728748; Sun, 31 May 2020 08:08:48 -0700 (PDT) Received: from localhost.localdomain (ip5f5bfcfd.dynamic.kabel-deutschland.de. [95.91.252.253]) by smtp.gmail.com with ESMTPSA id a62sm9564928edf.38.2020.05.31.08.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 May 2020 08:08:48 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/5] scsi: ufs: add compatibility with 3.1 UFS unit descriptor length Date: Sun, 31 May 2020 17:08:31 +0200 Message-Id: <20200531150831.9946-6-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200531150831.9946-1-huobean@gmail.com> References: <20200531150831.9946-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo 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. Signed-off-by: Bean Huo Reviewed-by: Avri Altman --- drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufshcd.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index 6548ef102eb9..332ae09e6238 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -63,6 +63,7 @@ #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/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 45d1fef982a9..a64718bfe2bc 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3070,11 +3070,16 @@ void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn 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, + 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_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; } @@ -3143,7 +3148,7 @@ 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, buff_len); + ufshcd_update_desc_length(hba, desc_id, desc_index, buff_len); /* Check wherher we will not copy more data, than available */ if (is_kmalloc && param_size > buff_len)