From patchwork Mon Jan 20 13:08:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342153 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 9BF9992A for ; Mon, 20 Jan 2020 13:09:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A49B22464 for ; Mon, 20 Jan 2020 13:09:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eUjG3+sc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726901AbgATNJ2 (ORCPT ); Mon, 20 Jan 2020 08:09:28 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33091 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726876AbgATNJ2 (ORCPT ); Mon, 20 Jan 2020 08:09:28 -0500 Received: by mail-wm1-f67.google.com with SMTP id d139so14726654wmd.0; Mon, 20 Jan 2020 05:09:27 -0800 (PST) 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=nfRc8qQhIj3SkQPDN7l7ruKxb1Lhpkv0HXJIJCsM07A=; b=eUjG3+sc7ERm3Es8wJRe+/7lo+gswYModoGJULMSR3hlyY+Ij3Em7ZY2/9ndsukfuN tf3XgP16sZO8Wt6eoaqIKS3TNPZUW5PN/SrFSPiR8tmDd5JyyVNl7LSVhvdMRVGYZVfQ t1mLoAWnVJ6F5eu2MBocx2Txxj70QeBjXCRLa13Ei1/29uri219MqWPaUas1xcX/2WpZ 3ymr13bWKywazH1hlYAxFj0ZVgWpKBg7Jya4aAUvsprTgjdnSWI2+G/C7IydigXOTobS R2SJxTStqTZqjmCwz4aHAAsKOPa7Zm66lfeZqOkLw7qKLp37D6VTliK/nmBaQ2Xo5nAz vZSA== 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=nfRc8qQhIj3SkQPDN7l7ruKxb1Lhpkv0HXJIJCsM07A=; b=eNJ1hwYSv2Ldk/h7lYVQEymbudarFQYQRHmTMfhHsjlMJNo79WBrfzTjyhrt0/qmTR bOIZEwA2mFecYlDwFsc4Jnbx9rgXNPK4F0nlWyrNLy36a9CcV9sXRCDyL8CfHbzTHFp/ WNZD2xf/zaRTh2UA+CRQuVG6St6o7Ud5jOBXP2GLbLqEROJd1HrGgkgxMOqVqe3U1Gl5 6q+j0hvhH+4/VybBsLJIndvLiS3bfvTvD/xp7AXCs4Eo39uX2StpfvCCAhk5B7RTV5MQ tEhA9CcmmvrOmlbFij9RpwWgb6SeZSmWrPo77Gi/C501h5qRBQ0riuLH7PM+t5FbXe1i 12fA== X-Gm-Message-State: APjAAAWjdUCLBl1rLMW3Y+jXirVPmCN6rlR4BEQKVTPWPp5iE+zTPDAG eaoHZsKZ9+Neeb+UJXZOYZU= X-Google-Smtp-Source: APXvYqxm1eE4NCJQZ/6cZ/MJBwzv04zShUzVRAD22LmRwCnKVqCk7lhkUGEY6FIdYGMZeipLOCFlPg== X-Received: by 2002:a7b:c450:: with SMTP id l16mr17988259wmi.166.1579525766782; Mon, 20 Jan 2020 05:09:26 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:09:26 -0800 (PST) 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/8] scsi: ufs: Fix ufshcd_probe_hba() reture value in case ufshcd_scsi_add_wlus() fails Date: Mon, 20 Jan 2020 14:08:13 +0100 Message-Id: <20200120130820.1737-2-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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 A non-zero error value likely being returned by ufshcd_scsi_add_wlus() in case of failure of adding the WLs, but ufshcd_probe_hba() doesn't use this value, and doesn't report this failure to upper caller. This patch is to fix this issue. Fixes: 2a8fa600445c ("ufs: manually add well known logical units") Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar Reviewed-by: Stanley Chu Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshcd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index bea036ab189a..9a9085a7bcc5 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7032,7 +7032,8 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) ufshcd_init_icc_levels(hba); /* Add required well known logical units to scsi mid layer */ - if (ufshcd_scsi_add_wlus(hba)) + ret = ufshcd_scsi_add_wlus(hba); + if (ret) goto out; /* Initialize devfreq after UFS device is detected */ From patchwork Mon Jan 20 13:08:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342155 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 AC005921 for ; Mon, 20 Jan 2020 13:09:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74E2422314 for ; Mon, 20 Jan 2020 13:09:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aAVJFFl7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728767AbgATNJh (ORCPT ); Mon, 20 Jan 2020 08:09:37 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:56087 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgATNJg (ORCPT ); Mon, 20 Jan 2020 08:09:36 -0500 Received: by mail-wm1-f68.google.com with SMTP id q9so14414096wmj.5; Mon, 20 Jan 2020 05:09:34 -0800 (PST) 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=1bT3vENVZeYpp+haao00mI36dnBC8eHxtO2LeOFswtI=; b=aAVJFFl7ZELS5PIjvPDZtyNlr0izcvY5VVefRz0mpoo7eZDb3mFy1F94t3Jh+lWtku gAKe9srJCghI2cXO4yWFMPWfbIyfM5LZNEX0k49BPl3CtumP3B8B4IuTMBgam0IUsvpr zv3qgnd083jNVEFFWHlHsfPjJZLH9gYlfzFE16CGXkdsH7OfFBMuURuov7Z7IilZf2g2 cVXr8fQlvEIyHXAvl2QF2D8oXAP0HlPNR8P3ztx4RELRkv6wGSXsvNW7qMIq9P2NBkQ3 fk5AKx2XozIiL8bZh8KT7KBElQjK0OeuYwQnT3SD39oOEM6nxjyGFY6xhq0/4p0CZFst LXoQ== 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=1bT3vENVZeYpp+haao00mI36dnBC8eHxtO2LeOFswtI=; b=J40tcdI8ggevvZUbk/2BeIbheGTGyy7+DRFu4OpbaMklWmSy/l13qmNM7bdqaoyETI AEZvyJxdgpCYn1O8TuzE6tHrTrTERiAqvC+nyjLEDjRFissXokdkxWJslSLqmheRhJR5 MLI7G3VLVAa8lpeeRUdMHRrIQqUem+nv7rLnwXcSbi+DFuIbRVpzezXa3v3LF8LVUa7q zQd9MxBzZIST0HUU6IwS+1gbrCFBwmmn0F/oP0sokXHW8B9XeJJM7RFOtbpv7arluFsi ANfrS1Mh/dEA/2L6rVNE3D12IXGot9UGJWq/6jVbleK6POAYZeLke04jBCF19MSlYxG5 7erQ== X-Gm-Message-State: APjAAAVzaSWivwoCboW3dw9PToT7LjLKGstnGAHC+JhSseNKXvMikMqK AcZkxzLVvjWEd/GWnsXKB+w= X-Google-Smtp-Source: APXvYqxmGKMcFu8t8gw01m2HD90Q0vucQqmelZpqAYrYAIpzXeB9laO/B9FMW0gF+z/YtBdqN2P8WQ== X-Received: by 2002:a7b:cfc9:: with SMTP id f9mr18710947wmm.1.1579525773583; Mon, 20 Jan 2020 05:09:33 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:09:33 -0800 (PST) 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/8] scsi: ufs: Delete struct ufs_dev_desc Date: Mon, 20 Jan 2020 14:08:14 +0100 Message-Id: <20200120130820.1737-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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 In consideration of UFS host driver uses parameters of struct ufs_dev_desc, move its parameters to struct ufs_dev_info, delete struct ufs_dev_desc. Reviewed-by: Bart Van Assche Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar Reviewed-by: Stanley Chu Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufs-mediatek.c | 7 ++--- drivers/scsi/ufs/ufs-qcom.c | 3 +-- drivers/scsi/ufs/ufs.h | 11 +------- drivers/scsi/ufs/ufs_quirks.h | 9 ++++--- drivers/scsi/ufs/ufshcd.c | 47 +++++++++++++++------------------ drivers/scsi/ufs/ufshcd.h | 7 +++-- 6 files changed, 36 insertions(+), 48 deletions(-) diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c index 8d999c0e60fe..514a9b85fe0a 100644 --- a/drivers/scsi/ufs/ufs-mediatek.c +++ b/drivers/scsi/ufs/ufs-mediatek.c @@ -406,10 +406,11 @@ static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) return 0; } -static int ufs_mtk_apply_dev_quirks(struct ufs_hba *hba, - struct ufs_dev_desc *card) +static int ufs_mtk_apply_dev_quirks(struct ufs_hba *hba) { - if (card->wmanufacturerid == UFS_VENDOR_SAMSUNG) + struct ufs_dev_info *dev_info = &hba->dev_info; + + if (dev_info->wmanufacturerid == UFS_VENDOR_SAMSUNG) ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TACTIVATE), 6); return 0; diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c index ebb5c66e069f..c69c29a1ceb9 100644 --- a/drivers/scsi/ufs/ufs-qcom.c +++ b/drivers/scsi/ufs/ufs-qcom.c @@ -949,8 +949,7 @@ static int ufs_qcom_quirk_host_pa_saveconfigtime(struct ufs_hba *hba) return err; } -static int ufs_qcom_apply_dev_quirks(struct ufs_hba *hba, - struct ufs_dev_desc *card) +static int ufs_qcom_apply_dev_quirks(struct ufs_hba *hba) { int err = 0; diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index c89f21698629..fcc9b4d4e56f 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -530,17 +530,8 @@ struct ufs_dev_info { bool f_power_on_wp_en; /* Keeps information if any of the LU is power on write protected */ bool is_lu_power_on_wp; -}; - -#define MAX_MODEL_LEN 16 -/** - * ufs_dev_desc - ufs device details from the device descriptor - * - * @wmanufacturerid: card details - * @model: card model - */ -struct ufs_dev_desc { u16 wmanufacturerid; + /*UFS device Product Name */ u8 *model; }; diff --git a/drivers/scsi/ufs/ufs_quirks.h b/drivers/scsi/ufs/ufs_quirks.h index fe6cad9b2a0d..d0ab147f98d3 100644 --- a/drivers/scsi/ufs/ufs_quirks.h +++ b/drivers/scsi/ufs/ufs_quirks.h @@ -22,16 +22,17 @@ * @quirk: device quirk */ struct ufs_dev_fix { - struct ufs_dev_desc card; + u16 wmanufacturerid; + u8 *model; unsigned int quirk; }; -#define END_FIX { { 0 }, 0 } +#define END_FIX { } /* add specific device quirk */ #define UFS_FIX(_vendor, _model, _quirk) { \ - .card.wmanufacturerid = (_vendor),\ - .card.model = (_model), \ + .wmanufacturerid = (_vendor),\ + .model = (_model), \ .quirk = (_quirk), \ } diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 9a9085a7bcc5..58ef45b80cb0 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6583,16 +6583,13 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) return ret; } -static int ufs_get_device_desc(struct ufs_hba *hba, - struct ufs_dev_desc *dev_desc) +static int ufs_get_device_desc(struct ufs_hba *hba) { int err; size_t buff_len; u8 model_index; u8 *desc_buf; - - if (!dev_desc) - return -EINVAL; + 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); @@ -6613,12 +6610,12 @@ static int ufs_get_device_desc(struct ufs_hba *hba, * getting vendor (manufacturerID) and Bank Index in big endian * format */ - dev_desc->wmanufacturerid = desc_buf[DEVICE_DESC_PARAM_MANF_ID] << 8 | + dev_info->wmanufacturerid = desc_buf[DEVICE_DESC_PARAM_MANF_ID] << 8 | desc_buf[DEVICE_DESC_PARAM_MANF_ID + 1]; model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME]; err = ufshcd_read_string_desc(hba, model_index, - &dev_desc->model, SD_ASCII_STD); + &dev_info->model, SD_ASCII_STD); if (err < 0) { dev_err(hba->dev, "%s: Failed reading Product Name. err = %d\n", __func__, err); @@ -6636,23 +6633,25 @@ static int ufs_get_device_desc(struct ufs_hba *hba, return err; } -static void ufs_put_device_desc(struct ufs_dev_desc *dev_desc) +static void ufs_put_device_desc(struct ufs_hba *hba) { - kfree(dev_desc->model); - dev_desc->model = NULL; + struct ufs_dev_info *dev_info = &hba->dev_info; + + kfree(dev_info->model); + dev_info->model = NULL; } -static void ufs_fixup_device_setup(struct ufs_hba *hba, - struct ufs_dev_desc *dev_desc) +static void ufs_fixup_device_setup(struct ufs_hba *hba) { struct ufs_dev_fix *f; + struct ufs_dev_info *dev_info = &hba->dev_info; for (f = ufs_fixups; f->quirk; f++) { - if ((f->card.wmanufacturerid == dev_desc->wmanufacturerid || - f->card.wmanufacturerid == UFS_ANY_VENDOR) && - ((dev_desc->model && - STR_PRFX_EQUAL(f->card.model, dev_desc->model)) || - !strcmp(f->card.model, UFS_ANY_MODEL))) + if ((f->wmanufacturerid == dev_info->wmanufacturerid || + f->wmanufacturerid == UFS_ANY_VENDOR) && + ((dev_info->model && + STR_PRFX_EQUAL(f->model, dev_info->model)) || + !strcmp(f->model, UFS_ANY_MODEL))) hba->dev_quirks |= f->quirk; } } @@ -6804,8 +6803,7 @@ static int ufshcd_quirk_tune_host_pa_tactivate(struct ufs_hba *hba) return ret; } -static void ufshcd_tune_unipro_params(struct ufs_hba *hba, - struct ufs_dev_desc *card) +static void ufshcd_tune_unipro_params(struct ufs_hba *hba) { if (ufshcd_is_unipro_pa_params_tuning_req(hba)) { ufshcd_tune_pa_tactivate(hba); @@ -6819,7 +6817,7 @@ static void ufshcd_tune_unipro_params(struct ufs_hba *hba, if (hba->dev_quirks & UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE) ufshcd_quirk_tune_host_pa_tactivate(hba); - ufshcd_vops_apply_dev_quirks(hba, card); + ufshcd_vops_apply_dev_quirks(hba); } static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) @@ -6945,7 +6943,6 @@ static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba) */ static int ufshcd_probe_hba(struct ufs_hba *hba) { - struct ufs_dev_desc card = {0}; int ret; ktime_t start = ktime_get(); @@ -6974,16 +6971,15 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) /* Init check for device descriptor sizes */ ufshcd_init_desc_sizes(hba); - ret = ufs_get_device_desc(hba, &card); + ret = ufs_get_device_desc(hba); if (ret) { dev_err(hba->dev, "%s: Failed getting device info. err = %d\n", __func__, ret); goto out; } - ufs_fixup_device_setup(hba, &card); - ufshcd_tune_unipro_params(hba, &card); - ufs_put_device_desc(&card); + ufs_fixup_device_setup(hba); + ufshcd_tune_unipro_params(hba); /* UFS device is also active now */ ufshcd_set_ufs_dev_active(hba); @@ -7544,6 +7540,7 @@ static void ufshcd_hba_exit(struct ufs_hba *hba) ufshcd_setup_clocks(hba, false); ufshcd_setup_hba_vreg(hba, false); hba->is_powered = false; + ufs_put_device_desc(hba); } } diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index b1a1c65be8b1..32b6714f25a5 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -320,7 +320,7 @@ struct ufs_hba_variant_ops { void (*setup_task_mgmt)(struct ufs_hba *, int, u8); void (*hibern8_notify)(struct ufs_hba *, enum uic_cmd_dme, enum ufs_notify_change_status); - int (*apply_dev_quirks)(struct ufs_hba *, struct ufs_dev_desc *); + int (*apply_dev_quirks)(struct ufs_hba *hba); int (*suspend)(struct ufs_hba *, enum ufs_pm_op); int (*resume)(struct ufs_hba *, enum ufs_pm_op); void (*dbg_register_dump)(struct ufs_hba *hba); @@ -1054,11 +1054,10 @@ static inline void ufshcd_vops_hibern8_notify(struct ufs_hba *hba, return hba->vops->hibern8_notify(hba, cmd, status); } -static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba, - struct ufs_dev_desc *card) +static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba) { if (hba->vops && hba->vops->apply_dev_quirks) - return hba->vops->apply_dev_quirks(hba, card); + return hba->vops->apply_dev_quirks(hba); return 0; } From patchwork Mon Jan 20 13:08:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342157 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 CF0CA921 for ; Mon, 20 Jan 2020 13:09:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A43FE22525 for ; Mon, 20 Jan 2020 13:09:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tS06I7iy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728682AbgATNJm (ORCPT ); Mon, 20 Jan 2020 08:09:42 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46996 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgATNJm (ORCPT ); Mon, 20 Jan 2020 08:09:42 -0500 Received: by mail-wr1-f67.google.com with SMTP id z7so29446560wrl.13; Mon, 20 Jan 2020 05:09:39 -0800 (PST) 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=K7g3P4yjPnhMysBSNyjqYu6e8DmKZkt9WUC8TTFZsfs=; b=tS06I7iyTauar6DBTAglZqtZljnUJsGfNM+Jb80ZNZFV7rv1LOgDwyQCHxOzMh/Ip6 qktk0Ngjb5yeFoAIgYVgfYto7NlKmykVQL9jLvCEo+NKl5Ogq98GmEhUcNDF3mr1kQtF p0JRlDfr0sZ+bIEmS/Me0lmQlncpGx02+yNO0DPmXEJMGtJ0FlMjECGLC1bKRynjqrDK APpmsn5t616xy0NkpzBVkftX2yMEHq6Lkvk6+0J1glI5rV93OfsiaRhTeY4VwyTB4HyL Gdjeb2obWCvIwEPiU0B3wVUeyB6aSygf8Xv/bNBEU8wycqz2oVxjybXNRuoh6EOTDhCR oq+g== 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=K7g3P4yjPnhMysBSNyjqYu6e8DmKZkt9WUC8TTFZsfs=; b=TeBqevcpzYWSCE0P86uSJr7ws6LCRuv3EDybjDrn/sK/CL8WFQJsdpHXZ86/pwJH0P GvNd5n3fmYKQShWR2JPbQitlH2vllhgaovmtgxYaga8BRXpP0+T0jRQs8hfXYXvOxRkj bJnfhtDzBvLMjZUzAxgc1e0AN+impE4+noPZaTtFPHr3HdvEqKdXtDf8b3AA9ly/9Qx8 q1Y8x9IuxhGIjqqAhyD4l4QeoieeL/zW3ljooyZgvnscePRApe59no5oyf/n1V0nNMxf qUlN+21ISsCRuq9DoVgm5ImnKnrVjs7o1GFOhfHDSC4x0mDjG0GcJEM8FWH/DmiI2kjT 2hCw== X-Gm-Message-State: APjAAAXqWBQf5+Bw2LRCObkeCV1sBf3B0PT5IRmFVwepIuQFyRUNQqDK gyc4/8kc+2Is7uyfEzIZOYA= X-Google-Smtp-Source: APXvYqxvtfzUzZCY/SpEIz78AfM+PauSHUfWGMylBkvml23/t1+EnzIMRZS+ZQBuDi6+NXi0UiFFDg== X-Received: by 2002:a5d:4687:: with SMTP id u7mr17576545wrq.176.1579525778813; Mon, 20 Jan 2020 05:09:38 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:09:38 -0800 (PST) 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/8] scsi: ufs: Split ufshcd_probe_hba() based on its called flow Date: Mon, 20 Jan 2020 14:08:15 +0100 Message-Id: <20200120130820.1737-4-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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 This patch has two major non-functionality changes: 1. Take scanning host if-statement out from ufshcd_probe_hba(), and move into a new added function ufshcd_add_lus(). In this new function ufshcd_add_lus(), the main functionalitis include: ICC initialization, add well-known LUs, devfreq initialization, UFS bsg probe and scsi host scan. The reason for this change is that these functionalities only being called during booting stage flow ufshcd_init()->ufshcd_async_scan(). In the processes of error handling and power management ufshcd_suspend(), ufshcd_resume(), ufshcd_probe_hba() being called, but these functionalitis above metioned are not hit. 2. Move context of initialization of parameters associated with the UFS device to a new added function ufshcd_device_params_init(). The reason of this change is that all of these parameters are used by driver, but only need to be initialized once when booting. Combine them into an integral function, make them easier maintain. Signed-off-by: Bean Huo Reviewed-by: Asutosh Das --- drivers/scsi/ufs/ufshcd.c | 167 +++++++++++++++++++++++--------------- 1 file changed, 101 insertions(+), 66 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 58ef45b80cb0..935b50861864 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -246,7 +246,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba); static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd); static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag); static void ufshcd_hba_exit(struct ufs_hba *hba); -static int ufshcd_probe_hba(struct ufs_hba *hba); +static int ufshcd_probe_hba(struct ufs_hba *hba, bool async); static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on, bool skip_ref_clk); static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on); @@ -6307,7 +6307,7 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba) goto out; /* Establish the link again and restore the device */ - err = ufshcd_probe_hba(hba); + err = ufshcd_probe_hba(hba, false); if (!err && (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL)) err = -EIO; @@ -6935,13 +6935,83 @@ static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba) return err; } +static int ufshcd_device_params_init(struct ufs_hba *hba) +{ + bool flag; + int ret; + + /* Init check for device descriptor sizes */ + ufshcd_init_desc_sizes(hba); + + /* Check and apply UFS device quirks */ + ret = ufs_get_device_desc(hba); + if (ret) { + dev_err(hba->dev, "%s: Failed getting device info. err = %d\n", + __func__, ret); + goto out; + } + + ufs_fixup_device_setup(hba); + + /* Clear any previous UFS device information */ + memset(&hba->dev_info, 0, sizeof(hba->dev_info)); + if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG, + QUERY_FLAG_IDN_PWR_ON_WPE, &flag)) + hba->dev_info.f_power_on_wp_en = flag; + +out: + return ret; +} + +/** + * ufshcd_add_lus - probe and add UFS logical units + * @hba: per-adapter instance + */ +static int ufshcd_add_lus(struct ufs_hba *hba) +{ + int ret; + + if (!hba->is_init_prefetch) + ufshcd_init_icc_levels(hba); + + /* Add required well known logical units to scsi mid layer */ + ret = ufshcd_scsi_add_wlus(hba); + if (ret) + goto out; + + /* Initialize devfreq after UFS device is detected */ + if (ufshcd_is_clkscaling_supported(hba)) { + memcpy(&hba->clk_scaling.saved_pwr_info.info, + &hba->pwr_info, + sizeof(struct ufs_pa_layer_attr)); + hba->clk_scaling.saved_pwr_info.is_valid = true; + if (!hba->devfreq) { + ret = ufshcd_devfreq_init(hba); + if (ret) + goto out; + } + + hba->clk_scaling.is_allowed = true; + } + + ufs_bsg_probe(hba); + scsi_scan_host(hba->host); + pm_runtime_put_sync(hba->dev); + + if (!hba->is_init_prefetch) + hba->is_init_prefetch = true; +out: + return ret; +} + /** * ufshcd_probe_hba - probe hba to detect device and initialize * @hba: per-adapter instance + * @async: asynchronous execution or not * * Execute link-startup and verify device initialization */ -static int ufshcd_probe_hba(struct ufs_hba *hba) +static int ufshcd_probe_hba(struct ufs_hba *hba, bool async) { int ret; ktime_t start = ktime_get(); @@ -6960,25 +7030,26 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) /* UniPro link is active now */ ufshcd_set_link_active(hba); + /* Verify device initialization by sending NOP OUT UPIU */ ret = ufshcd_verify_dev_init(hba); if (ret) goto out; + /* Initiate UFS initialization, and waiting until completion */ ret = ufshcd_complete_dev_init(hba); if (ret) goto out; - /* Init check for device descriptor sizes */ - ufshcd_init_desc_sizes(hba); - - ret = ufs_get_device_desc(hba); - if (ret) { - dev_err(hba->dev, "%s: Failed getting device info. err = %d\n", - __func__, ret); - goto out; + /* + * Initialize UFS device parameters used by driver, these + * parameters are associated with UFS descriptors. + */ + if (async) { + ret = ufshcd_device_params_init(hba); + if (ret) + goto out; } - ufs_fixup_device_setup(hba); ufshcd_tune_unipro_params(hba); /* UFS device is also active now */ @@ -7011,60 +7082,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) /* Enable Auto-Hibernate if configured */ ufshcd_auto_hibern8_enable(hba); - /* - * If we are in error handling context or in power management callbacks - * context, no need to scan the host - */ - if (!ufshcd_eh_in_progress(hba) && !hba->pm_op_in_progress) { - bool flag; - - /* clear any previous UFS device information */ - memset(&hba->dev_info, 0, sizeof(hba->dev_info)); - if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG, - QUERY_FLAG_IDN_PWR_ON_WPE, &flag)) - hba->dev_info.f_power_on_wp_en = flag; - - if (!hba->is_init_prefetch) - ufshcd_init_icc_levels(hba); - - /* Add required well known logical units to scsi mid layer */ - ret = ufshcd_scsi_add_wlus(hba); - if (ret) - goto out; - - /* Initialize devfreq after UFS device is detected */ - if (ufshcd_is_clkscaling_supported(hba)) { - memcpy(&hba->clk_scaling.saved_pwr_info.info, - &hba->pwr_info, - sizeof(struct ufs_pa_layer_attr)); - hba->clk_scaling.saved_pwr_info.is_valid = true; - if (!hba->devfreq) { - ret = ufshcd_devfreq_init(hba); - if (ret) - goto out; - } - hba->clk_scaling.is_allowed = true; - } - - ufs_bsg_probe(hba); - - scsi_scan_host(hba->host); - pm_runtime_put_sync(hba->dev); - } - - if (!hba->is_init_prefetch) - hba->is_init_prefetch = true; - out: - /* - * If we failed to initialize the device or the device is not - * present, turn off the power/clocks etc. - */ - if (ret && !ufshcd_eh_in_progress(hba) && !hba->pm_op_in_progress) { - pm_runtime_put_sync(hba->dev); - ufshcd_exit_clk_scaling(hba); - ufshcd_hba_exit(hba); - } trace_ufshcd_init(dev_name(hba->dev), ret, ktime_to_us(ktime_sub(ktime_get(), start)), @@ -7080,8 +7098,25 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) static void ufshcd_async_scan(void *data, async_cookie_t cookie) { struct ufs_hba *hba = (struct ufs_hba *)data; + int ret; - ufshcd_probe_hba(hba); + /* Initialize hba, detect and initialize UFS device */ + ret = ufshcd_probe_hba(hba, true); + if (ret) + goto out; + + /* Probe and add UFS logical units */ + ret = ufshcd_add_lus(hba); +out: + /* + * If we failed to initialize the device or the device is not + * present, turn off the power/clocks etc. + */ + if (ret) { + pm_runtime_put_sync(hba->dev); + ufshcd_exit_clk_scaling(hba); + ufshcd_hba_exit(hba); + } } static const struct attribute_group *ufshcd_driver_groups[] = { From patchwork Mon Jan 20 13:08:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342159 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 98D46921 for ; Mon, 20 Jan 2020 13:09:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 76D2022527 for ; Mon, 20 Jan 2020 13:09:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hOX7AWby" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728587AbgATNJq (ORCPT ); Mon, 20 Jan 2020 08:09:46 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36785 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgATNJp (ORCPT ); Mon, 20 Jan 2020 08:09:45 -0500 Received: by mail-wr1-f68.google.com with SMTP id z3so29523347wru.3; Mon, 20 Jan 2020 05:09:44 -0800 (PST) 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=0nfogaZM2dNL7CJVNT5K6skef+A5vufAFs1oVF/aB60=; b=hOX7AWbyIAm8dos332hRD1BCIr8emfGDM3Z50AZGqgs0WJi6vfOTza9cctYVTXhX/E gjdPlMUHM1fM0CGjyW3L9Pj61b2HnfPoiKrtzA8sp7qees56oYKnZ8TElrIhgMDE+cGv 7qxo8gZbcqugFS//1mB6fcpy0fk62IQJJcuJmvpCPC6l02qEjFWpb3W2q/FeUK+8CzKN zLsidXl8ub3PNgUIojdbAuCiCmBh8ShS6KxXqE8azAwRo2hvSTvT4rgStvl8pmi9E+bB v+1eCN5V+6DKE+Mdf/DN1KUvydELvqYOY3ES/aCZ5MKTkxDkHAxM7CCNP6pDUijiI0oK eqpw== 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=0nfogaZM2dNL7CJVNT5K6skef+A5vufAFs1oVF/aB60=; b=fhbzXHuwKzD28wsgeXgXtYW/kkXKOLCHm4E1DK4tCQJSinfba8cpjuFl2YlMh8b0Fr iogyj4/awQHZf+PcYY3CrTEnV3V1lm8x9NsoNsH5640GmMSCj+WeqegZSZWCTb3t+XIx OJZEvAiPls+pShJ1odOeL206VUIAwh79SjivlkQphTi9lO/a+hny8GDQStaX1d37hlrC 9qFUKLoDg2vVT0c0s5nH4nYmgY7ATyMI9wlSxTj15OLaWOvkIhz74lqbno7Jbt+lFll6 xejnQCGTdbF6QrCJWKOSHIeYihh1LYcEMEXb89vMeIbQjMN1uMfje2Lu77JT2E35IqUL lfnQ== X-Gm-Message-State: APjAAAVcvN1swWWR0boYP5mU9RjLd22Yj3Qi6QtROc9fPvnvrE61bUOH bkyB2vMPffxt2PkxiJr84Qg= X-Google-Smtp-Source: APXvYqwQu61/jfEBPX1pApD1AvgjEKGFspoBGXvW4gOm62cY1uR6+/MzTJ7kO39Hmr69/VrjSG7WqA== X-Received: by 2002:a5d:448c:: with SMTP id j12mr17820821wrq.125.1579525783483; Mon, 20 Jan 2020 05:09:43 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:09:43 -0800 (PST) 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/8] scsi: ufs: Move ufshcd_get_max_pwr_mode() to ufshcd_device_params_init() Date: Mon, 20 Jan 2020 14:08:16 +0100 Message-Id: <20200120130820.1737-5-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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 ufshcd_get_max_pwr_mode() only need to be called once while booting, take it out from ufshcd_probe_hba() and inline into ufshcd_device_params_init(). Reviewed-by: Stanley Chu Signed-off-by: Bean Huo Reviewed-by: Asutosh Das --- drivers/scsi/ufs/ufshcd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 935b50861864..5dfe760f2786 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6959,6 +6959,11 @@ static int ufshcd_device_params_init(struct ufs_hba *hba) QUERY_FLAG_IDN_PWR_ON_WPE, &flag)) hba->dev_info.f_power_on_wp_en = flag; + /* Probe maximum power mode co-supported by both UFS host and device */ + if (ufshcd_get_max_pwr_mode(hba)) + dev_err(hba->dev, + "%s: Failed getting max supported power mode\n", + __func__); out: return ret; } @@ -7057,11 +7062,8 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool async) ufshcd_force_reset_auto_bkops(hba); hba->wlun_dev_clr_ua = true; - if (ufshcd_get_max_pwr_mode(hba)) { - dev_err(hba->dev, - "%s: Failed getting max supported power mode\n", - __func__); - } else { + /* Gear up to HS gear if supported */ + if (hba->max_pwr_info.is_valid) { /* * Set the right value to bRefClkFreq before attempting to * switch to HS gears. From patchwork Mon Jan 20 13:08:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342161 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 754A692A for ; Mon, 20 Jan 2020 13:09:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5320A22464 for ; Mon, 20 Jan 2020 13:09:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KEpR7IBa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728835AbgATNJw (ORCPT ); Mon, 20 Jan 2020 08:09:52 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35450 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgATNJw (ORCPT ); Mon, 20 Jan 2020 08:09:52 -0500 Received: by mail-wr1-f68.google.com with SMTP id g17so29471035wro.2; Mon, 20 Jan 2020 05:09:51 -0800 (PST) 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=/3xFRKoJ9mK9crMSN19CDem50p2shDlmdkEhOU+c0tI=; b=KEpR7IBaaatng20qXd0/G9/SujrmK4kv3BcyhpbGINjOPUOCsTiJ+hO42+JPH68g+z NCalyaeCyVnOjWtIz8l+F5UNeF0KlbbWDKk2t6GGiF0pbhhHW5J1lHyAKtxDl8wS4Uz8 eBiI1JGYJ0wwk5J4cS7LvVvGPMwxqsUCI95dpVAKLaFAPYBxz654Vn8XOwfAvvGrdGuq SIuwkniMUgAOF43majTmje8zGIaGbzpdE90CnvKyJNzh+GLDpBqQCagFdXnNjT+El239 4pKf59FH2dm3tsj+cac233JKH9BzL4NdHyPPXfVKGYhOiBpJpj5zrG7UxCez479mb+eC vmbQ== 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=/3xFRKoJ9mK9crMSN19CDem50p2shDlmdkEhOU+c0tI=; b=Q9DIgBuZq4Cnl2ZxBKD80MIgDvvOr5pDmFIq757L2Lf+hn7bgz1BDc1LoR0NdhB6fJ d2FC5JuULkAMuX1cIxcv1Bb8QdkUzzyVJXN989Dw+ZZdGJdmkB7vDeES2AHLoOhY1+XF nC4SeNL8Hx0dN7DMp7vHTZp4T1vZJlRwn9In05lGtpZ+yD72OtEnBWID+hYfqs47GYsJ nh4o9mA4crcCyEeUXmx/k/zNIAk5d936z2M2PhN3/NdAZNOA+IvSkFbZdcAq0+5z7wjc 06hsCHyWPFMcRVZANjdh2M4s+mMXX9imlbvDXupqV9/ZMBrYoIjPTtq+7/1Phf7s+SvO EtgQ== X-Gm-Message-State: APjAAAVR91OIIxyzpBwkny6Uhnfm6x5QC9xdtVKK4z39TWB+IsQj9i8c KtajAy0P0PVlyvRsjwzfyhQ= X-Google-Smtp-Source: APXvYqwnABy9fYgHh+NbPDAbrxy+R7YiJzxS1mB9B9LHjKk6cB/sI+2pMGOW2qv2xluFRmgVyJMJ/Q== X-Received: by 2002:adf:df0e:: with SMTP id y14mr17429525wrl.377.1579525790516; Mon, 20 Jan 2020 05:09:50 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:09:49 -0800 (PST) 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/8] scsi: ufs: Inline two functions into their callers Date: Mon, 20 Jan 2020 14:08:17 +0100 Message-Id: <20200120130820.1737-6-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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_power_desc() and ufshcd_read_device_desc(), directly inline ufshcd_read_desc() into its callers. Reviewed-by: Alim Akhtar Signed-off-by: Bean Huo Reviewed-by: Asutosh Das Reviewed-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 5dfe760f2786..3d3289bb3cad 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3146,17 +3146,6 @@ static inline int ufshcd_read_desc(struct ufs_hba *hba, return ufshcd_read_desc_param(hba, desc_id, desc_index, 0, buf, size); } -static inline int ufshcd_read_power_desc(struct ufs_hba *hba, - u8 *buf, - u32 size) -{ - return ufshcd_read_desc(hba, QUERY_DESC_IDN_POWER, 0, buf, size); -} - -static int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size) -{ - return ufshcd_read_desc(hba, QUERY_DESC_IDN_DEVICE, 0, buf, size); -} /** * struct uc_string_id - unicode string @@ -6493,7 +6482,8 @@ static void ufshcd_init_icc_levels(struct ufs_hba *hba) if (!desc_buf) return; - ret = ufshcd_read_power_desc(hba, desc_buf, buff_len); + ret = ufshcd_read_desc(hba, QUERY_DESC_IDN_POWER, 0, + desc_buf, buff_len); if (ret) { dev_err(hba->dev, "%s: Failed reading power descriptor.len = %d ret = %d", @@ -6599,7 +6589,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba) goto out; } - err = ufshcd_read_device_desc(hba, desc_buf, hba->desc_size.dev_desc); + err = ufshcd_read_desc(hba, QUERY_DESC_IDN_DEVICE, 0, desc_buf, + hba->desc_size.dev_desc); if (err) { dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", __func__, err); From patchwork Mon Jan 20 13:08:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342163 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 9B8B417EA for ; Mon, 20 Jan 2020 13:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 794FB22525 for ; Mon, 20 Jan 2020 13:10:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q+WRM1cN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728928AbgATNJ5 (ORCPT ); Mon, 20 Jan 2020 08:09:57 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33132 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgATNJ4 (ORCPT ); Mon, 20 Jan 2020 08:09:56 -0500 Received: by mail-wm1-f68.google.com with SMTP id d139so14727544wmd.0; Mon, 20 Jan 2020 05:09:55 -0800 (PST) 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=KLk7bHERzQdcb090yx1OHmdrZSniwsUQ3lMJ7bG4zOU=; b=q+WRM1cNNX8plyLJyEIHEtqIatyviQ9EQrnHDElmsDIC1F+XNpE6E2WwEt27/Vvj3O x36sO0NKYlHnUj6+PDrgX0BbtaUO/tD0dvyr75fFPqwROa6qctwj819PDJEDR1YJFM0N rCotVg0grb4LDXBI8BooI3tcjDbY7c2HwYO58cRGDTaGLcLpS0xehQbn+GIMJo5wOIlS x4FjnTVVXZtrba6b3DAMk31/B/e76BdQv/6Q5b2Ro9Auit5YIhX8YLv6/7PjqcLyQXhE e75nhJqTfUrkPryBkk9uraUZpSh3K8bSFS1FVKMl3ehXR8SpkK3yHSibCW04O51vVrqL 0icQ== 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=KLk7bHERzQdcb090yx1OHmdrZSniwsUQ3lMJ7bG4zOU=; b=VPuM8RmkNwIheoxR5JI/so0r7YcoelMYKuqHDgis2alRDL+Kx6GS4t2awsTrOOhdgX MUQSHFHgx7j+AieAZaK6UhCeBwJs9n181N0ecScpoJIEI16E5iMMXNiTf9d7sceauEYP NzIB7AchTJpj1hFstqb++yuBlJpzz/COylpdcFxqHu0oWj+MGeAhnFxBRp2R4VloNUBT cHlGKyFEnCQ7PQKkPROnck0V1DOdx5+5NxRodzxis7wZ+4Em4TjjB9Qp299va2GZdZDm LCvOwijRwmNE4OBB7ZaLluaP2dfE8mFzLgCFDAxCfnkZH3gE0maqzKJxP9oaIRiOPR/g nLHA== X-Gm-Message-State: APjAAAWGWegAJlRsPK/xG4BA168BKsX+R/BHQ/iXquNDeW2wQuaaT0KB axGNWk2edTy7AC+kiBLbVJg= X-Google-Smtp-Source: APXvYqwJh+sTAe00agX8D+AMFKZ0eukqYvg4n2kk/KOsxwe9dqrJtrKmnKzEB/1Tts9WLBKKBEwRGA== X-Received: by 2002:a05:600c:224d:: with SMTP id a13mr19048454wmm.70.1579525794561; Mon, 20 Jan 2020 05:09:54 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:09:54 -0800 (PST) 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 6/8] scsi: ufs: Delete is_init_prefetch from struct ufs_hba Date: Mon, 20 Jan 2020 14:08:18 +0100 Message-Id: <20200120130820.1737-7-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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 Without variable is_init_prefetch, the current logic can guarantee ufshcd_init_icc_levels() will execute only once, delete it now. Signed-off-by: Bean Huo Reviewed-by: Asutosh Das Reviewed-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 5 +---- drivers/scsi/ufs/ufshcd.h | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 3d3289bb3cad..0c859f239d1c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6967,8 +6967,7 @@ static int ufshcd_add_lus(struct ufs_hba *hba) { int ret; - if (!hba->is_init_prefetch) - ufshcd_init_icc_levels(hba); + ufshcd_init_icc_levels(hba); /* Add required well known logical units to scsi mid layer */ ret = ufshcd_scsi_add_wlus(hba); @@ -6994,8 +6993,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba) scsi_scan_host(hba->host); pm_runtime_put_sync(hba->dev); - if (!hba->is_init_prefetch) - hba->is_init_prefetch = true; out: return ret; } diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 32b6714f25a5..5c65d9fdeb14 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -501,7 +501,6 @@ struct ufs_stats { * @intr_mask: Interrupt Mask Bits * @ee_ctrl_mask: Exception event control mask * @is_powered: flag to check if HBA is powered - * @is_init_prefetch: flag to check if data was pre-fetched in initialization * @init_prefetch_data: data pre-fetched during initialization * @eh_work: Worker to handle UFS errors that require s/w attention * @eeh_work: Worker to handle exception events @@ -652,7 +651,6 @@ struct ufs_hba { u32 intr_mask; u16 ee_ctrl_mask; bool is_powered; - bool is_init_prefetch; struct ufs_init_prefetch init_prefetch_data; /* Work Queues */ From patchwork Mon Jan 20 13:08:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342165 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 957C892A for ; Mon, 20 Jan 2020 13:10:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72F6F2253D for ; Mon, 20 Jan 2020 13:10:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h/PYAoVb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728992AbgATNKC (ORCPT ); Mon, 20 Jan 2020 08:10:02 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36811 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgATNKB (ORCPT ); Mon, 20 Jan 2020 08:10:01 -0500 Received: by mail-wr1-f67.google.com with SMTP id z3so29524397wru.3; Mon, 20 Jan 2020 05:10:00 -0800 (PST) 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=pVtO//JnmpJEbBOinshMosCxkhLujL8jfc98AaizHQs=; b=h/PYAoVbPVkUylg7wmqeOlfd98AFbSFhV8pn/QBmjZRAP2c5WQDX7WbrVW2/bo5VzG XGWHBOuGuAHfvLIxyfKTmnJ8MFDkCoApK8woVBMu+09RlVkAbGMXApJtekJLTMBOgHli d2THVSje3krzlyXSE/wZ1mUnb3wRc1fnKW8O7KVT3uoYt9ML2hkHKGi8ble1NAl8VK3d +KzwFYIVNJGE6za30vHJ/TG75AD5P2fCfhzLsqoPunRIZrg6+kPSRPwrCkDO/0tgM+Of ON3ElLa5CixH8NhYZLP9JisBAFxw89U3X9rYQRj2QCeWSVag9qOgmVaQ5SnIUs+rWaxm S6wA== 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=pVtO//JnmpJEbBOinshMosCxkhLujL8jfc98AaizHQs=; b=lsK0F9nm10nbI8pbGJMQ+H843YBravaYSiPVrKTtnIYh2UnE7G79xofIqXWAkmGJ6H 8S4+2Z6++U0IlsBfGcKY8NA5HDGl6BvJHGZdtFh5l5I7TT4IDgN+yJ6QH0eB9uakrvLC RGvFB+tuy275/N+jfRDr8VD/xPQWpOMS329H9XZXg9tooIs+NUKh1sKLo2T8uCM3Dw8u ksDJNPh6ZwI402lB8vU6Z59NdY2gRUrYDZX7vmfRLUCvm1n71cecJsS7xl3bCYF9Z3g2 uZAzHRWCTxcpqVvNezH2ENhppaYJqHlMMn9EcBz4XWSxI7+TSw0rWsjmU2dIieR/Py0k yU3A== X-Gm-Message-State: APjAAAWITaKFniaYRXroZ2qaAG0GLhSoJnnC16MnNiRILRRZ5zEsWZWa llHNdCzhJ2yyVRWyDFpSm8Q= X-Google-Smtp-Source: APXvYqwr4VIDu6lmmNzjy8SSwl7QxKRgCEDKwrloWmxrg3BuKTubmHg8Y2Zjjp3SWHBOttVU6efOjw== X-Received: by 2002:a5d:4c8c:: with SMTP id z12mr17981235wrs.222.1579525799650; Mon, 20 Jan 2020 05:09:59 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:09:59 -0800 (PST) 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 7/8] scsi: ufs: Add max_lu_supported in struct ufs_dev_info Date: Mon, 20 Jan 2020 14:08:19 +0100 Message-Id: <20200120130820.1737-8-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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 Add one new parameter max_lu_supported in struct ufs_dev_info, which will be used to express exactly how many general LUs being supported by UFS device, and initialize it during booting stage. This patch also adds a new function ufshcd_device_geo_params_init() for initialization of UFS device geometry descriptor related parameters. Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufs.h | 2 ++ drivers/scsi/ufs/ufshcd.c | 41 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index fcc9b4d4e56f..c982bcc94662 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -530,6 +530,8 @@ struct ufs_dev_info { bool f_power_on_wp_en; /* Keeps information if any of the LU is power on write protected */ bool is_lu_power_on_wp; + /* Maximum number of general LU supported by the UFS device */ + u8 max_lu_supported; u16 wmanufacturerid; /*UFS device Product Name */ u8 *model; diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 0c859f239d1c..1d2812ad8742 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6858,6 +6858,37 @@ static void ufshcd_init_desc_sizes(struct ufs_hba *hba) 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; + desc_buf = kmalloc(buff_len, GFP_KERNEL); + if (!desc_buf) { + err = -ENOMEM; + goto out; + } + + err = ufshcd_read_desc(hba, QUERY_DESC_IDN_GEOMETRY, 0, + desc_buf, buff_len); + if (err) { + dev_err(hba->dev, "%s: Failed reading Geometry Desc. err = %d\n", + __func__, err); + goto out; + } + + if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN] == 1) + hba->dev_info.max_lu_supported = 32; + else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN] == 0) + hba->dev_info.max_lu_supported = 8; + +out: + kfree(desc_buf); + return err; +} + static struct ufs_ref_clk ufs_ref_clk_freqs[] = { {19200000, REF_CLK_FREQ_19_2_MHZ}, {26000000, REF_CLK_FREQ_26_MHZ}, @@ -6931,9 +6962,17 @@ static int ufshcd_device_params_init(struct ufs_hba *hba) bool flag; int ret; + /* 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 UFS geometry descriptor related parameters */ + ret = ufshcd_device_geo_params_init(hba); + if (ret) + goto out; + /* Check and apply UFS device quirks */ ret = ufs_get_device_desc(hba); if (ret) { @@ -6944,8 +6983,6 @@ static int ufshcd_device_params_init(struct ufs_hba *hba) ufs_fixup_device_setup(hba); - /* Clear any previous UFS device information */ - memset(&hba->dev_info, 0, sizeof(hba->dev_info)); if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG, QUERY_FLAG_IDN_PWR_ON_WPE, &flag)) hba->dev_info.f_power_on_wp_en = flag; From patchwork Mon Jan 20 13:08:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11342167 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 E8450921 for ; Mon, 20 Jan 2020 13:10:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC6A422525 for ; Mon, 20 Jan 2020 13:10:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pACO54zR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728901AbgATNKK (ORCPT ); Mon, 20 Jan 2020 08:10:10 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40598 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgATNKK (ORCPT ); Mon, 20 Jan 2020 08:10:10 -0500 Received: by mail-wm1-f66.google.com with SMTP id t14so14618076wmi.5; Mon, 20 Jan 2020 05:10:09 -0800 (PST) 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=ygaQ/46D8dGQ52VSi/XMDPuo6obEX8tZiKmv9YWb3M4=; b=pACO54zR5xoMJzdsrylDNfbu+eXZKS2kWL9dsFO9X+u04NOGXS6afl5nSE0mb/GmGp QzEWMQJvUSzfZ8hTl+8W759mk+KdF7c89eQQXAohBYwTxUtTYEc/b0Bzw455P/letpcD ROgkrVFrYOjevFTw2TT6IsRl+dlg+dprBqitnZKuxucoo0BW8LqHi04yXPigBpkTLnm5 b3gOlVIBI1PgX/hyNmkyBuNgRS61YYUjQbIgVl3RkUYGiHffazKD3lhfKJJcQ4BDhx6c biJ6ywfLjmcUAttSMDyzu7vM2BH9PHpxRISUJBSoTxouEsyYaUEnHa9t/gQZn4jkH7x+ sXIw== 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=ygaQ/46D8dGQ52VSi/XMDPuo6obEX8tZiKmv9YWb3M4=; b=flzW8aFpXfvPdRPUqEOrc1urPmwAARhfeiwmXxvNDtyso/nJlTBePHKwd9LHdLVDIZ Jhkdnar3s5U02c6NIcfTvgDHJMssBhUFhoZLTwqrILeuCqmHBs5HAuUOmDAkkI6viwns YT2bUxcHa2H+Ywsj2ru8xMzNUQVfh+xQfQEgx/T9EMhbnwd8pCsBNbJNrbVhAgazDz7D DOPo39Le6PPyvVGgzLdxbkL6UcpzAv9K8/iRVe5xyRjoip0/0MJqd0xdigx+ebCD2Bqg joEZYT/BpwoNQyY6CnHT/FLcaudxwxLAm9fPzZXgXEgNlC8FBehekLEXoeCLFjizSF4Z RTPQ== X-Gm-Message-State: APjAAAV2OP2QCfmUhI1lcnY9roV4B7jcHO2Dm/a0A51ZxSUFacC/rgeY ToJHp5Hy3QmUVgKj6B9x6Gk= X-Google-Smtp-Source: APXvYqxG4Tmf7UOO1mQ7QRQblVPm30R3woYtQQZNUjBsyjLOufLsSuaR0E8AE8K5I2RQBW3+ise1Ew== X-Received: by 2002:a1c:49c2:: with SMTP id w185mr18277857wma.138.1579525808359; Mon, 20 Jan 2020 05:10:08 -0800 (PST) Received: from ubuntu-G3.micron.com ([165.225.86.138]) by smtp.gmail.com with ESMTPSA id p18sm23065386wmb.8.2020.01.20.05.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 05:10:07 -0800 (PST) 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 8/8] scsi: ufs: Use UFS device indicated maximum LU number Date: Mon, 20 Jan 2020 14:08:20 +0100 Message-Id: <20200120130820.1737-9-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120130820.1737-1-huobean@gmail.com> References: <20200120130820.1737-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 According to Jedec standard UFS 3.0 and UFS 2.1 Spec, Maximum number of logical units supported by the UFS device is indicated by parameter bMaxNumberLU in Geometry Descriptor. This patch is to delete current hard code macro definition of UFS_UPIU_MAX_GENERAL_LUN, and switch to use device indicated number instead. Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufs-sysfs.c | 2 +- drivers/scsi/ufs/ufs.h | 12 +++++++++--- drivers/scsi/ufs/ufshcd.c | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 720be3f64be7..dbdf8b01abed 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -713,7 +713,7 @@ static ssize_t _pname##_show(struct device *dev, \ struct scsi_device *sdev = to_scsi_device(dev); \ struct ufs_hba *hba = shost_priv(sdev->host); \ u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); \ - if (!ufs_is_valid_unit_desc_lun(lun)) \ + if (!ufs_is_valid_unit_desc_lun(&hba->dev_info, lun)) \ return -EINVAL; \ return ufs_sysfs_read_desc_param(hba, QUERY_DESC_IDN_##_duname, \ lun, _duname##_DESC_PARAM##_puname, buf, _size); \ diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index c982bcc94662..dde2eb02f76f 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -63,7 +63,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_UPIU_MAX_GENERAL_LUN 8 /* Well known logical unit id in LUN field of UPIU */ enum { @@ -539,12 +538,19 @@ struct ufs_dev_info { /** * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor + * @dev_info: pointer of instance of struct ufs_dev_info * @lun: LU number to check * @return: true if the lun has a matching unit descriptor, false otherwise */ -static inline bool ufs_is_valid_unit_desc_lun(u8 lun) +static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, + u8 lun) { - return lun == UFS_UPIU_RPMB_WLUN || (lun < UFS_UPIU_MAX_GENERAL_LUN); + if (!dev_info || !dev_info->max_lu_supported) { + pr_err("Max General LU supported by UFS isn't initilized\n"); + return false; + } + + return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported); } #endif /* End of Header */ diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 1d2812ad8742..d7f2465447e0 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3270,7 +3270,7 @@ static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba, * Unit descriptors are only available for general purpose LUs (LUN id * from 0 to 7) and RPMB Well known LU. */ - if (!ufs_is_valid_unit_desc_lun(lun)) + if (!ufs_is_valid_unit_desc_lun(&hba->dev_info, lun)) return -EOPNOTSUPP; return ufshcd_read_desc_param(hba, QUERY_DESC_IDN_UNIT, lun, @@ -4525,7 +4525,7 @@ static int ufshcd_get_lu_wp(struct ufs_hba *hba, * protected so skip reading bLUWriteProtect parameter for * it. For other W-LUs, UNIT DESCRIPTOR is not available. */ - else if (lun >= UFS_UPIU_MAX_GENERAL_LUN) + else if (lun >= hba->dev_info.max_lu_supported) ret = -ENOTSUPP; else ret = ufshcd_read_unit_desc_param(hba,