From patchwork Fri May 29 16:40:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11579339 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 E9819159A for ; Fri, 29 May 2020 16:41:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D15222077D for ; Fri, 29 May 2020 16:41:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HoIxLHf8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbgE2QlV (ORCPT ); Fri, 29 May 2020 12:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725681AbgE2QlU (ORCPT ); Fri, 29 May 2020 12:41:20 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D99FC03E969; Fri, 29 May 2020 09:41:20 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x6so4341979wrm.13; Fri, 29 May 2020 09:41:20 -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=ToxnDwTC+zLUDCpLe2beVSUXwkocz2pi9wyRrspW0/8=; b=HoIxLHf8O/A/gsDWC0yRHWJkfeXO7e3wAh6JFzOM0mLP3PeIEF0juZRcMh77tgI+Gw +NR4CKYfTOlUOW3xGka7NZ2DaZPlQTsISWdOvcqu1qxQhSqywRf4jUbyeecrByVKvK61 SdcfJmJF4QGrWsyH+gMYNBo3E1wv5ezS3gylavLvohyLrNr++vja6l5bOOUt/2sQY8VV 0yguOxnG5FKON04rglh8odqc76DKiBJlKCbINDZBHQ6dHcsJUVRxz8y/gOdgwUjew7yA O/YxP/rDm7QmIZtnQ3IsfCZXWF86gsP9CQwy4CPLGKXAEQccS2ohktqJWFsGyUNFnZE2 6Ziw== 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=ToxnDwTC+zLUDCpLe2beVSUXwkocz2pi9wyRrspW0/8=; b=Oz5w2b07ryjZGb4mxX08sSl3EVol77d/7ZCVGlHjMCcSRXrOzNs3UEOrsPzGFTKrU6 M3fgOAwAYO946jHUrWYcSzyHi8u1t3G9JiDO89hGKi28qiLTRN9+XNL04gVgsxGn68lf QyXozmxjn7MEf451+jFJC10pym3eXno6qS2El5bSDFx3F+dCZq0hVITiZLo1Fwh4QEr/ xQpnBNHa7VYlcVqlUcVd3MzynZ38oifNJAc28DFZxH7S4HBEd2vXLHaCf2FX68vV0qOt d7Qt8LjYeGvdh6ly1LjCDQN3/0isdcXQqwMwAvB8ZJu/2R6KkIbgXItFWw90EVfrvPat fSTg== X-Gm-Message-State: AOAM5305xo9ayQdX0HeOxZ/VGYD45iTjZGOOkAX6Oz2uS2Un9tuP/jhB ThuO1sapq1QTiWZNuQ/zQoM= X-Google-Smtp-Source: ABdhPJznNCRcCL8HaTUB0QPQV3vTRZB8EEeOG6FjEYgYWLxOTgppWSsAKKdu2h9d4fOfPrUhRF9ytw== X-Received: by 2002:adf:f446:: with SMTP id f6mr9449779wrp.59.1590770479254; Fri, 29 May 2020 09:41:19 -0700 (PDT) Received: from ubuntu-laptop.micron.com ([165.225.203.62]) by smtp.gmail.com with ESMTPSA id z25sm17344wmf.10.2020.05.29.09.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 09:41:18 -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 1/4] scsi: ufs: remove max_t in ufs_get_device_desc Date: Fri, 29 May 2020 18:40:51 +0200 Message-Id: <20200529164054.27552-2-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529164054.27552-1-huobean@gmail.com> References: <20200529164054.27552-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 the UFS device, the maximum descriptor size is 255, max_t called in ufs_get_device_desc() is useless. Signed-off-by: Bart van Assche Signed-off-by: Bean Huo Acked-by: Avri Altman Reviewed-by: Stanley Chu --- drivers/scsi/ufs/ufshcd.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index aca50ed39844..f57acfbf9d60 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6876,14 +6876,11 @@ static void ufs_fixup_device_setup(struct ufs_hba *hba) static int ufs_get_device_desc(struct ufs_hba *hba) { int err; - size_t buff_len; u8 model_index; u8 *desc_buf; struct ufs_dev_info *dev_info = &hba->dev_info; - buff_len = max_t(size_t, hba->desc_size.dev_desc, - QUERY_DESC_MAX_SIZE + 1); - desc_buf = kmalloc(buff_len, GFP_KERNEL); + desc_buf = kmalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; goto out; From patchwork Fri May 29 16:40:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11579341 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 632381667 for ; Fri, 29 May 2020 16:41:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C14C207F9 for ; Fri, 29 May 2020 16:41:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="otkk4MsX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbgE2QlZ (ORCPT ); Fri, 29 May 2020 12:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbgE2QlY (ORCPT ); Fri, 29 May 2020 12:41:24 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4A09C03E969; Fri, 29 May 2020 09:41:23 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id n5so4365540wmd.0; Fri, 29 May 2020 09:41:23 -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=otkk4MsXwbEgxYlni9vpgpBPRIAntHOtPorh+J0eGp13/thYuSLfUUdghhYF0P7E9X VDnlU1MuxQHDMySdYU1seLQgPxCBcyyoLoGJn8bCiYWjrx65uUiQkyRTj0LnXnXN3Kgn L3R6ztT03NlbxThWiGzTyWIyiQj3c0UIBsbHUc1q6edasOdvWjKTxq4ZvnMHCaU624PK sK+rXBYIczjhZ9HQgZRi6XXl8fu4FXWUxgs20bvfxE2ye4okzsIh7Ceo3V5v41aSjcc2 YK9viiz07KTC7ZyAfE2L0YpRap4Wia2iz1gKtcsOTu4s5S/cpyw0GQBU+ZNScXn+cfFb rdUg== 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=st5Ubio9WeXCO7Pa7VJGH/gP1MLdaC/RYa2Lnt0GyQK0b6JcUUa/WRrkxj0wgNn3vM KjMiEz8s/FvwaQ/H5qE+ieyxjDq/E79OdIrzOP8vDuyq17P42OyfHzxjQzq2TqUnzpIL YvZFkQVzU6icmeUVlJDFLf1hueGZLi2CICMmgIQp7UA7fupYw4PTn6Lopp6mk5kwAnQD hHWrYFZ8sfux4zL/gAHN/xmhs5V9rLH+zBW9cqvFVh0jF98939nkN7F1PkSkRcJ+YehJ O3mGHD3PPaQy9ei1YnPtODCx6Kt3ExUpTrU4DW7oLxkeXSTqkwyCjJFRa2pWKCehOyKU Shlw== X-Gm-Message-State: AOAM530yYmhxNYRCzJ+VwDQHhzdUgZhyuunZRT26U1b38o93iyl7627A f5KYAiINMUWsNXetQg71nME= X-Google-Smtp-Source: ABdhPJzMksF1nB0PsUQ7/F3DR+ZE8clh+DwsW7xE2aan9WQIiEe0EQnezRPTcPi9gES2GmA1cwhyQQ== X-Received: by 2002:a7b:c7d8:: with SMTP id z24mr8966111wmk.28.1590770482610; Fri, 29 May 2020 09:41:22 -0700 (PDT) Received: from ubuntu-laptop.micron.com ([165.225.203.62]) by smtp.gmail.com with ESMTPSA id z25sm17344wmf.10.2020.05.29.09.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 09:41:22 -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/4] scsi: ufs: delete ufshcd_read_desc() Date: Fri, 29 May 2020 18:40:52 +0200 Message-Id: <20200529164054.27552-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529164054.27552-1-huobean@gmail.com> References: <20200529164054.27552-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 Fri May 29 16:40:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11579343 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 143F460D for ; Fri, 29 May 2020 16:41:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5C212145D for ; Fri, 29 May 2020 16:41:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DwjBX5yH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbgE2Ql2 (ORCPT ); Fri, 29 May 2020 12:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbgE2Ql1 (ORCPT ); Fri, 29 May 2020 12:41:27 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71D97C03E969; Fri, 29 May 2020 09:41:27 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id x13so4442737wrv.4; Fri, 29 May 2020 09:41:27 -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=9bVBT0aZbmB/hF7sO6Le8A1yrPasSowI+6xR4HW0gLs=; b=DwjBX5yH1nF7KeYejJEVqaYclmSn8n7+34nTc4XbKH8bS1wrBjP/O1SPXI7Fmg+G+C jLpKXK8Zg8r6wnxl3887ieF+JNiWFJP8gBVtjdF0drrteV8+yHh8aSejGRuCb4rIPOtS CnZVKHM0hPswvSDonCwpSDoUjeHbWym+yhnOO5SnUr3A6RQGUrIaL0gNlY37LOeZsXMO 1KdmlnJ4enjoMX9+D7t4z8WdwdCT+B4Jg/tjV/vXBV8yE7hfyWgv3o9T9+O87zLXVKzt h0IeHZ0F/yZxEWYuSzPr8Yt+zLQrFnm8Y0OesHsWZ/ofxz97Zbc2qvxGN6Re0LmDghBi 8poA== 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=9bVBT0aZbmB/hF7sO6Le8A1yrPasSowI+6xR4HW0gLs=; b=kWZciPfNSFmpVjnr7yLmUwRVy/7uxUpbzqZnMGezI4TQg/+lp6lMEE/OnUJR/ng7T5 /UY8SaWKVIPmQbFASxnA/FfuYxDTuAbs+oV2UJR3Jgadz7+T7wcDrd2wUVdHh5i1S24G AFAUEYBccahYTV43ACipSx6O3GA11qJQGHuap/+vu5TVTb79mEBsHF5qaFv+SUXggTle ESkL1NF58OpqIq/X//KrLezTQt6zfZyjgO5UEd7W1Z7WCvw5PUcOhLKzf7GsQGfLxZ8y iK9tzjljLGcjapRnoSbPeEzk5TnVLfvWB3/4QY26tXdanh0YNReUBoOepG52IvSNuq7+ ZR/w== X-Gm-Message-State: AOAM530hLaz6aHj0zD1nf+YhD+4P6oEJ0B9sFPMuENOsaaoPosQFr+hZ OD7hJmhQtD2g/o2V8tcRjqY= X-Google-Smtp-Source: ABdhPJyaGltRLGWAu0gIaBXvsmEu7oXsBCS41zFRaoi7AaJDbQ4/+MoDCSoMcGhM955uH1S3N6/MuQ== X-Received: by 2002:adf:dfcf:: with SMTP id q15mr9230752wrn.373.1590770486130; Fri, 29 May 2020 09:41:26 -0700 (PDT) Received: from ubuntu-laptop.micron.com ([165.225.203.62]) by smtp.gmail.com with ESMTPSA id z25sm17344wmf.10.2020.05.29.09.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 09:41:25 -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/4] scsi: ufs: cleanup ufs initialization path Date: Fri, 29 May 2020 18:40:53 +0200 Message-Id: <20200529164054.27552-4-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529164054.27552-1-huobean@gmail.com> References: <20200529164054.27552-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 | 165 +++++++------------------------------ drivers/scsi/ufs/ufshcd.h | 16 +--- 4 files changed, 36 insertions(+), 160 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 f7e8bfefe3d4..951e52babf65 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: + if (desc_id == QUERY_DESC_IDN_RFU_0 || desc_id == QUERY_DESC_IDN_RFU_1) *desc_len = 0; - break; - default: - *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,9 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, goto out; } + ufshcd_update_desc_length(hba, desc_id, + desc_buf[QUERY_DESC_LENGTH_OFFSET]); + /* Check wherher we will not copy more data, than available */ if (is_kmalloc && param_size > buff_len) param_size = buff_len; @@ -6665,7 +6600,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 +6718,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 +6812,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 +7040,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 +7142,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 Fri May 29 16:40:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11579345 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 8E2EA159A for ; Fri, 29 May 2020 16:41:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 762ED2077D for ; Fri, 29 May 2020 16:41:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bf+1ZHGR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbgE2Qlc (ORCPT ); Fri, 29 May 2020 12:41:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbgE2Qla (ORCPT ); Fri, 29 May 2020 12:41:30 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A26B5C03E969; Fri, 29 May 2020 09:41:30 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x14so4479585wrp.2; Fri, 29 May 2020 09:41:30 -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=NaB7VWR04f+B+3g+DA/Cuf8vF3CQZRXxRPnbwEDcUjg=; b=bf+1ZHGR8XG85nypZi034t9JRcYxpaf8XixZwpJlZCIJps3M2xax75YQ+QOXZpZLC9 7qd6O44tTa6xFoitSy+5umbWo0J+fnEX0h4XYfUa+mF7sxhh8wIIthZb25/Ojr6T4cNx 53svAawW4PvsGR7SnnCN1XDE3Jj5+SuimrKRKklKeIQ4WLWU1cUq4xHaTQejhcv/Qdfk 3iFx79kTI9b6PG7V069vDmalzkQjDvRat9KKyopPRX3FpuQt4+N+fx5fTz7iB+cKe8tX HLJpQdI8NE60GvjgF6nVLEf5rYtAjyzsTsI21YOvLVEp5Int/9k151X3hM5fTxtT9ryv JzEQ== 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=NaB7VWR04f+B+3g+DA/Cuf8vF3CQZRXxRPnbwEDcUjg=; b=d8DBdvm1w/OQxSwcSbKxuQUM7MUaQ8eVC3HlOY2KMqdP/nfqiDJnkLg5Qy/GNwfLwF AYFU3WMxUb7dwrfLs7XEaaQxbIa9nEMDa4d1l9CyCdwv3jq/QmCh5arfa9sx0swpjhl9 T7b4MvZ7hiZcEXlto1ut4pLNY6fBuUvvbImilJgJ+/Eqt/BsuiNVeJVldps5PJPi9XAN Scix94YTYfztz2R8LmUcQfi1N9Pg5lrynpqWyJ4mH6ltxyDOOHKSdx+oKzNO+FQLXBA9 WZTJf7PbclbijdTCFjLvT1C1vwbeLbfR35XK/3ETfN3TJQz0WcbVrRyJC7R45Vf0Visy /5wg== X-Gm-Message-State: AOAM532FQfF+1Gl+sxkOj9Rdz7KNc7hguW2YlCmOdTCPKHZ04u1OZqNG 5FsujbGI9SHyFS69xHB5Du0= X-Google-Smtp-Source: ABdhPJxhVthUTmCxFIOx6ZYGEra973usr+hG6fG86hZ+KectIAx+zR9bO8isvhfbCc2Gs34L+MbYPQ== X-Received: by 2002:adf:9544:: with SMTP id 62mr9124451wrs.32.1590770489450; Fri, 29 May 2020 09:41:29 -0700 (PDT) Received: from ubuntu-laptop.micron.com ([165.225.203.62]) by smtp.gmail.com with ESMTPSA id z25sm17344wmf.10.2020.05.29.09.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 09:41:29 -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/4] scsi: ufs: add compatibility with 3.1 UFS unit descriptor length Date: Fri, 29 May 2020 18:40:54 +0200 Message-Id: <20200529164054.27552-5-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529164054.27552-1-huobean@gmail.com> References: <20200529164054.27552-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 951e52babf65..3cdc585d0095 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; } @@ -3141,7 +3146,7 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, goto out; } - ufshcd_update_desc_length(hba, desc_id, + ufshcd_update_desc_length(hba, desc_id, desc_index, desc_buf[QUERY_DESC_LENGTH_OFFSET]); /* Check wherher we will not copy more data, than available */