From patchwork Sun Jan 19 00:13: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: 11340353 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 ABCEC138D for ; Sun, 19 Jan 2020 00:14:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A0272467C for ; Sun, 19 Jan 2020 00:14:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iW7zEuSY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727121AbgASAOB (ORCPT ); Sat, 18 Jan 2020 19:14:01 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39182 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727012AbgASAOB (ORCPT ); Sat, 18 Jan 2020 19:14:01 -0500 Received: by mail-wm1-f68.google.com with SMTP id 20so11160523wmj.4; Sat, 18 Jan 2020 16:14: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=sELIAc9JYznk8gLukGl5sh9ks34HnlMIU1NIlCV4wTE=; b=iW7zEuSYXDcEN+aUn69no6y2/t2qEqG9s+uaKRUQD46IoxNzuGFgHN42ldtJYynCOA Zd25bcAcApbUAw/X+z/RjlTe3MJQg+ww+lNOBXZnGjm9RUXwOGfDqth68LygsxIS3y6I 7936Jf6am0ix7igdQDhcVTZlC0Or20mSDXuGtW21PQ6lh51cgxmDy0f7S6J1cOVo9R8v Obh6IoH/Hd2TEaRsCDcn/b2ayLW8Q9fhRrepcc0NoU6b/wy2qy7uYeCk6f8D9/XIZLfE j/19KzQVXAmMH8nRaG6t+oCiU2H5Dc3+Rsht9NzZcAc0fPdVVaTD3MfrDeN9zZfz9vyJ Pu3Q== 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=sELIAc9JYznk8gLukGl5sh9ks34HnlMIU1NIlCV4wTE=; b=t6eo3X9O6oUROf/nH0eeMnzT0xWkrXh6zYnst+zw1OIsgMtKcD4LN+CzP/o9v2L4IE 6qMTovGFiEEdKsL/yUOjfM+C6WGBQMLAATAZEBFfu623V9hAunjzxrc2TL3oeorMW+KB aq2c0+hkf/Zpuw4LpjB6ZEMVK+u+7Ym5jr25MWSiH3k11wm9kYv1Os9EOE39rU7uV6tA /IvDrpvz+ysbc3f+5whDzhrjGtYfIjMG4eDusPpIRDlw+7yrreI1rlibt8ZqqrIUxr3E SqEaE447uQ+4xmmb/H9e43jsDtWdcde7DkTpcSVbtQ0aGPvoBYThc+S4Rx99b+v53JgM Rv4g== X-Gm-Message-State: APjAAAX+OR6Iy/bOpwhgkowMatdjBi5Yk2dsAPSddA+VZVBxSP5OSyJF zxC8CbyXJbCxZpUsxJLB86I= X-Google-Smtp-Source: APXvYqxlD6y7Bt3F2MMMyeEUc+W/AKLH/NgaL57LWyBzSnFZRtGox1dpnD68RGayahUnrZC+sXEw/w== X-Received: by 2002:a7b:c1d8:: with SMTP id a24mr11801469wmj.130.1579392839387; Sat, 18 Jan 2020 16:13:59 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:13:58 -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 v3 1/8] scsi: ufs: Fix ufshcd_probe_hba() reture value in case ufshcd_scsi_add_wlus() fails Date: Sun, 19 Jan 2020 01:13:20 +0100 Message-Id: <20200119001327.29155-2-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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 Signed-off-by: Bean Huo Signed-off-by: Alim Akhtar Reviewed-by: Alim Akhtar Reviewed-by: Stanley Chu --- 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 Sun Jan 19 00:13:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11340355 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 E9E1613BD for ; Sun, 19 Jan 2020 00:14:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B553224683 for ; Sun, 19 Jan 2020 00:14:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S7WwZirw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727665AbgASAOE (ORCPT ); Sat, 18 Jan 2020 19:14:04 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46872 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727012AbgASAOD (ORCPT ); Sat, 18 Jan 2020 19:14:03 -0500 Received: by mail-wr1-f68.google.com with SMTP id z7so25997670wrl.13; Sat, 18 Jan 2020 16:14:02 -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=SARs+g+pzoFpyO/cPbfGxV51BTmvZwh/HNcIT1QsL0c=; b=S7WwZirw8AdKD+sBYWyUiJm+6g3IXSGmWjzYQBrR/lt3A4sPP7rXgYFFV5+4leTmTq VOyHsaRXVhT4JcOcMTvGIU5Fhd+JOPuG0JMDqY0wqhifQEzHBiXeU9ULgJuP75pcmN5N Z7U65pOPRPTvJF5m/12sFpUmVi0qWsUyFSrgHpB74SS7qYEr1qg6KB2jduiR56MQFWle D/OS4oqgnskV/e0qYKh8TkQpgzarjfcWpmi4nb7IIEq+thEEHy9A2csc2aTVnExfoZMd DK7EK3hOPmDxZFWSuxgNyrUvNUceQTDBVcNw/rc8WqKNYBCdst9uceH/drPZoqmnCIMI pbNg== 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=SARs+g+pzoFpyO/cPbfGxV51BTmvZwh/HNcIT1QsL0c=; b=ABIdQtFxLSLkRRxrUCPDid+nqP9v6XQzW36N4lBVl+fAnZ5BFKlSbopu3XIuQYUDqC Knu5D8FyWbKUjhhJNo4t5lS3T4yzVdo5U8J4A8qns9uHE1/p+DTDSJ5DBs5eILZKmrjX BxxeP2lTjn9Ot2AQ1gsouxWYdnhHWS3apNpSG16XEHLrd98ibpGgrYjaagDrMqvW/9wt sG3j13PQp+eu7EgYAGY3v3EXTHxNj8yXlONRQ0bWCGbZgDjJqpLKwP0jNJERvhlNdJBD DITdX/cGCfBMPSrF6SwvtngmtcfZXsxQUJCIC4QFiamwswNNZMdvD3AZ3iOqeX8K86Mt zwpQ== X-Gm-Message-State: APjAAAV7V1UXwxEEMnZXmHMdjsNzrUnIQIra5M1IK8qhDFoHrz0Ij23O ZGKbYejwY+HIXr1xw2pVrFY= X-Google-Smtp-Source: APXvYqyq44bQBa9i3Hx5VgLkai6azPzfEZfyAg9zIivcb8SrKIPpr84HOaOHIOP1e/B8zLv/TMlIig== X-Received: by 2002:a5d:68c5:: with SMTP id p5mr10264878wrw.193.1579392841955; Sat, 18 Jan 2020 16:14:01 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:14:01 -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 v3 2/8] scsi: ufs: Delete struct ufs_dev_desc Date: Sun, 19 Jan 2020 01:13:21 +0100 Message-Id: <20200119001327.29155-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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 Signed-off-by: Bean Huo Reviewed-by: Alim Akhtar Reviewed-by: Stanley Chu --- drivers/scsi/ufs/ufs-mediatek.c | 7 ++--- drivers/scsi/ufs/ufs-qcom.c | 6 ++--- 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, 38 insertions(+), 49 deletions(-) diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c index 8d999c0e60fe..f8dd992b6f3a 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..9c6a182b3ed9 100644 --- a/drivers/scsi/ufs/ufs-qcom.c +++ b/drivers/scsi/ufs/ufs-qcom.c @@ -949,12 +949,12 @@ 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; + struct ufs_dev_info *dev_info = hba->dev_info; - if (hba->dev_quirks & UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME) + if (dev_info->dev_quirks & UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME) err = ufs_qcom_quirk_host_pa_saveconfigtime(hba); return err; 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 Sun Jan 19 00:13:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11340359 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 3F8D117EA for ; Sun, 19 Jan 2020 00:14:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 14C42246AF for ; Sun, 19 Jan 2020 00:14:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DBtEdIhY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728712AbgASAOG (ORCPT ); Sat, 18 Jan 2020 19:14:06 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38035 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728708AbgASAOF (ORCPT ); Sat, 18 Jan 2020 19:14:05 -0500 Received: by mail-wm1-f66.google.com with SMTP id u2so11145034wmc.3; Sat, 18 Jan 2020 16:14:04 -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=41ycnJotq3f2f3WoDrFXzRvGRmTy6PCXJzUIUZ0WMkw=; b=DBtEdIhYcglB3fGG9i+O216N4PbLiOWChz8+RsqhYBn35FrB9caSccBauRGN9CL3Cq sYpH1RJTtbZS1OdEH3iRD12Qu1GK0EpMmmNbUUB5Hrpcitu+ZVJ4p8lMB4jKbyhrzHUJ 8xg5lDZgI+/LIwAQ992h6GlTscFZFzr8FEEuNNhHu6RV59eg8llaqm1a5V6WBhs9AH3U fVTXWDzLXn1BljMxSjHyQxq+6TG/LY10WY1uYO/yXD6VALrvJmBBQ1NcBljBiqw+wEcR dc4qcdzNsGe5H+Zt6WyGZF//hYbjuym8N9tz6vw568CNtWGx/9PZrSlgYuk/K12A3RgX W9tg== 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=41ycnJotq3f2f3WoDrFXzRvGRmTy6PCXJzUIUZ0WMkw=; b=ByLH9xIL5fEq/eURWH1sVrdbQCdYNVCmaBFNXb4AW9/K0kA5hY1dfuS+Wg0LaFHfl2 dPtHPU1bfQGMUUqD3eSnWsnlI2w7D7Fd0Oovwm9FS2wa6FvCxgyw4JJAcGzXPhveiOtQ XUFQcJB2iKi2tJamkPoA3IoXzJURHAmKEDMpWmKy3kjTf8lE/olcI50CfGpFMBLaBl00 az566y9eLayfg89bq52De7q1PNppHRWi4sb9r1CYMuwxhw/5mUuK9cYGRr23izMTryBm arDiGuTVpM6wJFY7dDGtErP/+NcsOBVslywEq/FgEUXo2zH+qVJW0hIyVsiULS+5F0BY iQVA== X-Gm-Message-State: APjAAAXd1qY5F4Vt5qC+oj3IfE3QoR1reDzkeg1bHgvhNKyc112+BJZw u60ktAMqBTCx7MHsaLfXn74= X-Google-Smtp-Source: APXvYqyX/+jQ6xdYzSNmH1biMdfMfAp2pdkJOU/pdLReTHjL8Egz9a+ohYqqELi9mL8mm45JQ/JRVA== X-Received: by 2002:a05:600c:d5:: with SMTP id u21mr11807092wmm.85.1579392844256; Sat, 18 Jan 2020 16:14:04 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:14:03 -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 v3 3/8] scsi: ufs: Split ufshcd_probe_hba() based on its called flow Date: Sun, 19 Jan 2020 01:13:22 +0100 Message-Id: <20200119001327.29155-4-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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_init_params(). 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 --- 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..54c127ef360b 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_init_params(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_init_params(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 Sun Jan 19 00:13:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11340357 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 D1112138D for ; Sun, 19 Jan 2020 00:14:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AFF6524683 for ; Sun, 19 Jan 2020 00:14:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B2/FrWN5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728843AbgASAOJ (ORCPT ); Sat, 18 Jan 2020 19:14:09 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38201 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728811AbgASAOJ (ORCPT ); Sat, 18 Jan 2020 19:14:09 -0500 Received: by mail-wr1-f68.google.com with SMTP id y17so26065247wrh.5; Sat, 18 Jan 2020 16:14:07 -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=MRb5bXAWMY+l9HME4BWEKQK1eCgQVNeKGRrRGFvy7Iw=; b=B2/FrWN5PiQe/aTA5s7VuSedpHC2t/ZqQdcAwrd0ExqpHwthaMB9cq+df6CU+2tQXl iSKy9v5cJb/LkghYrXOZfyzrHsFH+VbKpRKnxYPVU2cJmdsnmRVnQHrT2aEgG2lCeMXh GfOGgYVOUrP881eKZcTOzGHFU/cDaNGwF4J/3662OuScc3v3lC8fMJPOO7a1ggydqhg1 SUqR7fT6krqRh0W9sUiNH5H1I0FxMjQkZIgPPSWYLjvtFl9UkfPaYtjoRFvXfzeLqKA8 ZXJm5Jwq/UMFrBUoHEwAywqnZJVZWffyLm2po+OKDne+T50m/BQdlZy/tQmQW1NVJWwY HIcw== 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=MRb5bXAWMY+l9HME4BWEKQK1eCgQVNeKGRrRGFvy7Iw=; b=HX3G2afWsP8TbNB5NMvDj4sf8IpGVmlRI+8C0fw0Ce8muKFkjQtj3GMmjmAiePCJaw kzDgj9uSB6EE8gILKKUs1ysbVTEgut9Z/g85ub37Z6mewnLPDH7r5jDzo9tuCMDSfTd5 rm5OfYdilLajzo7N6MDQfuArCTjRSTiFuqrWCbZRAkz7+y283zNG1dBFarma2NZrF8qV mKOx+5IUNS8CSGPahO0gY4uHPMF2FbXQTjrhjQnK218/ZKkxcAYmgHCrJWmZev0EXTAE BVXFeIP/yqSFNtznD+Kk26jOoCpEY1vAiefY411noxcwSY08dQKGFU+9Iw6H68s+lcTl QEEQ== X-Gm-Message-State: APjAAAXPJt/+Q5gOYb/GuknxydT+kNNoEL7XvbwQPZtLWLTNMGugKN8Z IUZw8NM/KrMQ7OqSBUvv2iE= X-Google-Smtp-Source: APXvYqx1p0C2LUh20OSMagkpn12NTrQfI/tEv9uchn0D3d1IwZoDmcLMN6qcNLwqb7PMrb2fHmyoyA== X-Received: by 2002:a5d:4481:: with SMTP id j1mr10609347wrq.348.1579392847120; Sat, 18 Jan 2020 16:14:07 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:14:06 -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 v3 4/8] scsi: ufs: move ufshcd_get_max_pwr_mode() to ufs_init_params() Date: Sun, 19 Jan 2020 01:13:23 +0100 Message-Id: <20200119001327.29155-5-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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_init_params(). Signed-off-by: Bean Huo Reviewed-by: Stanley Chu --- 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 54c127ef360b..925b31dc3110 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6959,6 +6959,11 @@ static int ufshcd_init_params(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 Sun Jan 19 00:13:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11340367 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 86544138D for ; Sun, 19 Jan 2020 00:14:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65B0F24683 for ; Sun, 19 Jan 2020 00:14:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uRX+7+jO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728909AbgASAON (ORCPT ); Sat, 18 Jan 2020 19:14:13 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52230 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727083AbgASAOM (ORCPT ); Sat, 18 Jan 2020 19:14:12 -0500 Received: by mail-wm1-f65.google.com with SMTP id p9so10913973wmc.2; Sat, 18 Jan 2020 16:14:11 -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=KQ+N4tgHIW2CTZZWICt6xNlWKRm3ezXQOgqUFuWPieE=; b=uRX+7+jO4sXPlkwbL6xZSMH/7riWE2GcLPUQNsega5krOcmjImsTlWLmdfKgm/9rWy BdXalv3nvsMsqM+xrH1il+d0v/l40kfUj5jHBd2L+slrW8avXfdN5n0qbWnLZYJv+6gz cUcloJFvBcVws8HIpGbL/5Y8fQ6YGdki/2jNASvbBu4DKW77/p5EnPuYwQWMe7LxGTwt PgOgJWa/tdbRiFMVOcVpxIqS91ZkOQWnlj6a1WzHBdgdGne+RPF8SFDBPbq4Rvrl7dRT 71COKy/Wrh/QfCBGU8FtOzofSYBkdADftIlb7wxP55CDSWkZ+lel3a3nZvWtVfmf/vtW jhLg== 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=KQ+N4tgHIW2CTZZWICt6xNlWKRm3ezXQOgqUFuWPieE=; b=FZ/AEukMzxwvhXi2daFGROx1Cwl3s0VoIGg5hgcW/9gwlvz8Oz6Prgh3zhy2GzHMCA 4mLJKiMsgOw4gk98kR3BnpkCtahIp7ubf71acUyUEWId2TAKFYD+6CRl/ASFaPSdJyW0 iRHzmf0PDg+v5DoThNxw8vczJEazbElWaEs0p+77rpxrbaa3HWV05ClhbRYRRAWMmC+q 17lgVWAkb/aN3zIeaVRpVMqv6YvkbTNuq0DVSXwBr29XKGhK2lrx/buf7fH/mbjpX9Nk 9lokKp0H8qFc+tYFEEkVJ2GVb4ICe+uOkzQKG1zqXmyPltU5vX9xRr7usTXj5W9gPSca CTxA== X-Gm-Message-State: APjAAAV7qXIdlbinPZXg9SuPqtG4skO5Nv4yyWvCm4Zx3BpXOOGKXGiB XdbMVnj8ZILx8GZ1BNXPW+c= X-Google-Smtp-Source: APXvYqzfQDxYFCAa2L7hVt9VbCi+P6vVJ7ErpDnBuDrE+db9/o0pi3qQvwRXwRhaaoLffxMDQu72BA== X-Received: by 2002:a05:600c:2406:: with SMTP id 6mr11812175wmp.30.1579392850818; Sat, 18 Jan 2020 16:14:10 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:14:10 -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 v3 5/8] scsi: ufs: Inline two functions into their callers Date: Sun, 19 Jan 2020 01:13:24 +0100 Message-Id: <20200119001327.29155-6-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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. Signed-off-by: Bean Huo Reviewed-by: Alim Akhtar --- 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 925b31dc3110..5f3b0ad5135a 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 Sun Jan 19 00:13:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11340361 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 1446013BD for ; Sun, 19 Jan 2020 00:14:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6C7624683 for ; Sun, 19 Jan 2020 00:14:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fb/I1AUO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729009AbgASAOP (ORCPT ); Sat, 18 Jan 2020 19:14:15 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51410 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728901AbgASAOO (ORCPT ); Sat, 18 Jan 2020 19:14:14 -0500 Received: by mail-wm1-f67.google.com with SMTP id d73so10892868wmd.1; Sat, 18 Jan 2020 16:14:13 -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=ugnjhMRTmnK+PtKom+FYsDk92nymRWFHwav/7Qa5gLg=; b=fb/I1AUO9WZ+sdrn1r9HSCuC3R4I3ezam0h3JleUYJACLuGWZ1tdZfA5gAfKviiP0Z HS8qM1r6zT+B/jWR5VJYIPCSi493opNtjZRuGDg4hwxi5fcuMLYJnXyHYOFTE5ViFK0Q QHybKJJc45aVFTdfBhE+yAtK8I9mKrl2hLeDif+Ae5nhKiBMSfZE+SwdjaeA5+eoIXja K4UxFp4ULvpgy+4bHNElNTZ70lQdDdfsNEHASiuLdTRXBid1awWV0DVYIXl3F41mlH2L NQQOsRl2623Udvzc2iAXa7hkI+IlLxG+t2pFLAaQzwaKBifseUBUiIT2BmOVkJ9PmlN5 JzGw== 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=ugnjhMRTmnK+PtKom+FYsDk92nymRWFHwav/7Qa5gLg=; b=laJH/2SHm6GE2GmArH948iXWn28kBe26ghRIPR5nyA9VfU0wlBHloWmYdey/tqp2Ly ENRAlL5p3r2yG5SWQjXeTL3D6RGMZPjAWeifayJMALtBHJI2zA4ODCmeZalofCHE0GFi Y+ApOEGWenElEAt4GhN/SmSyPfAWEVTkXwbSlvdGqL6D2jez3hj6HpWyqrNMb22ApTGe VZWEdow8Q/5ufuGzJuVe00wRLcLnCCF9YeCBzLPr1PfY0iOdmzxaxQvm2S6XGV6q1VGF AhESTfgvgBSlhklTlgWbgo5djEcVYzfmbFWmtFF8ytyOImHJfzpAprDUNQSRAhG/uq+Z X5og== X-Gm-Message-State: APjAAAVSp+8IMDPhH2WpXGPFGvz1yzimSEq2FyxTuCsismStPIwH4sfj +IPtxEQuB+pfJ9qL+RtmH8o= X-Google-Smtp-Source: APXvYqxUpkePkh24N2/Hepls/OnjrInhFI2HLhcjkT7bkk7t+M+FK7ghnFSMXJwvThrcwbOtpCntIA== X-Received: by 2002:a1c:3187:: with SMTP id x129mr12358687wmx.91.1579392852886; Sat, 18 Jan 2020 16:14:12 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:14:12 -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 v3 6/8] scsi: ufs: Delete is_init_prefetch from struct ufs_hba Date: Sun, 19 Jan 2020 01:13:25 +0100 Message-Id: <20200119001327.29155-7-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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 --- 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 5f3b0ad5135a..4f8fcbb5f92e 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 Sun Jan 19 00:13:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11340365 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 584B4138D for ; Sun, 19 Jan 2020 00:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3671E246A0 for ; Sun, 19 Jan 2020 00:14:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rBW0+V0t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729043AbgASAOS (ORCPT ); Sat, 18 Jan 2020 19:14:18 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39197 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729014AbgASAOR (ORCPT ); Sat, 18 Jan 2020 19:14:17 -0500 Received: by mail-wm1-f65.google.com with SMTP id 20so11160769wmj.4; Sat, 18 Jan 2020 16:14:15 -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=9q6DalID/6nJXKb+L/ud3IZ3fY2HNeLSUvnbsc/zVY4=; b=rBW0+V0t5FCD1BIk7j5dGm5ZUkGljoiF5+I7ac+RYDBAlOtKZIN5QPUD1BfDMcQzFP 4Xumgkg6qbzFIk8gLGyzMG62wQSfcoU+viB9ciztzbq10/OV81h64q7Cz+UVdoAtXC5w pBPdeV633bRnhdmv6B88DAp0lk/S0GwR/l31BkW7V0Qt2gc9DhhiVsYo1Mf8gLMyXvak FA1tVtR+E/OY1iDuVqBhW99RvfFYRFvtH1rxXneaAwlEugQ2b2YdxM+gIdv04om/eHHj TkmlE8Ide0lmZ/J83K7tYlT5EPrNm400ssJxlHFqi6LuGtiA2CuQU3cbqO9Wu/Vd5KDM TtpQ== 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=9q6DalID/6nJXKb+L/ud3IZ3fY2HNeLSUvnbsc/zVY4=; b=tuDP/eNyO1b2qSR5BXeXBn2iw+J64UNBX2JhixgvKkYxLgb3CftSN+joZ5DfV2oq7B /uFT6MbW3cRAyiftHAvGS2FJqAtzzxqqZo3XJSCpGvR3DkuaC8c4y/q1L6CeGXd7ezsg P2lV0Ta/zfQbeVn5V80NqwY+I5ebQ6MOIh7UIb9SpSFYE3l77DF+nAwUomxCQR6uU0b6 2zwZx7HSDoY3OdUACTLr4uHnRpRST/OoyhWjyqYALkZFE4pt155fKWgsZbhnop76iugy 6jSIbmcu+LwYsP6USPn52ZIt2kwiLzVogbiWFHwE6Bm2E/aqL5y3gx4JOFGeCfRk28+s mh4g== X-Gm-Message-State: APjAAAU6/BplXzG4HhuLs2UpR48i4qPfYBa2SgxeJpkHITWH6wcLwdWa KrB5steL1IW9OmOCac7OHeI= X-Google-Smtp-Source: APXvYqy9BKWJ1epovLCQLXGM0AHNn5Pby7OpTpwIW/BY+A6+38viCy+Yyd9irIE0xi1/iiudcL9rsg== X-Received: by 2002:a1c:6a07:: with SMTP id f7mr11651706wmc.171.1579392855132; Sat, 18 Jan 2020 16:14:15 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:14:14 -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 v3 7/8] scsi: ufs: Add max_lu_supported in struct ufs_dev_info Date: Sun, 19 Jan 2020 01:13:26 +0100 Message-Id: <20200119001327.29155-8-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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_init_device_geo_params() for initialization of UFS device geometry descriptor related parameters. Reviewed-by: Asutosh Das Signed-off-by: Bean Huo Reviewed-by: Alim Akhtar --- 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 4f8fcbb5f92e..dd10558f4d01 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_init_device_geo_params(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_init_params(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_init_device_geo_params(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_init_params(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 Sun Jan 19 00:13:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11340363 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 C358D13BD for ; Sun, 19 Jan 2020 00:14:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98664246B1 for ; Sun, 19 Jan 2020 00:14:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ifVChtVX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729052AbgASAOU (ORCPT ); Sat, 18 Jan 2020 19:14:20 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36606 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729028AbgASAOT (ORCPT ); Sat, 18 Jan 2020 19:14:19 -0500 Received: by mail-wr1-f66.google.com with SMTP id z3so26066135wru.3; Sat, 18 Jan 2020 16:14:18 -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=JcxadZK131d3CCycqq881Qc4UK7AcKsZZt6NwsgpxHk=; b=ifVChtVXpP+xBlUVu5XoyB70HfTtAuMqusG0xmzFTa1OPurEPYaVhOzIv8gKX0Yri0 ejGzgu00Hl4+2lVv+NQms8/70vnhrNYgsg0qGALHdjK7XwaRvAH+52jxbhp+ryQeHRmH Q64Il+GPgjnof37sq0J8a3mGfXCv0IYXOsxus8OhvM6N0kiKewD0eTpDSGchs9T53Q0b 7YoY7Krn06UTb5kwwvNEfxqrlJg8ws6bkXW2fqmqB+/hTRlbZ5I+44AnJOGuMuLPchXj KXR2FErUgYyInhUZTJrNoAu67kjsfrVIOHbh66OCRySJijfg1RDzJCpxmbsrHXlC1IMR ESZQ== 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=JcxadZK131d3CCycqq881Qc4UK7AcKsZZt6NwsgpxHk=; b=HLQHfMAbSQtgdCCVK9u9p3zGZZIC180IoKVz8UzCs2Z5OAxwn+P7EUlEuqI2qZc/7c 4wQ3UQRPB8V/+5M6aB3AGr78dgHZNWJ0KR4YbaM1/iUH60s1fD1nwC5FYVtN17AsHE9n TqozBBT3slihyGwS55hglYTwh4O06ztsIh3ppBTh9dEcmlNmvtIKKe8Z9a9OTbAvL1+S zN6GN3/AxW7ZLQlu68j32xMDvFaFwmLvc00d6aFG9Rw+P/KfIO802qHLcNGrJ22j4Llu 1a67J45jmW9D3pbT9P3Jfr4elfTYtdFbVs7N3K946zR/rmvaZ+n9vs8E8+iJYTG3yJ7B OqXA== X-Gm-Message-State: APjAAAUjLptHe3n6fpGsF+FlsHAxlQkNrUqvArMOqZlG4H+FQevqTjQH ioM6sY4D0s+IU94GiLDT2chePY1J X-Google-Smtp-Source: APXvYqyZAtKZNrooDp4z+ENSIc9Q2g4g5qH9RKG229vCI4YFDrzwwzYb42W/mQIfVw2yN4A0ln8BNw== X-Received: by 2002:adf:ef0b:: with SMTP id e11mr11117619wro.128.1579392857675; Sat, 18 Jan 2020 16:14:17 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id i8sm42177432wro.47.2020.01.18.16.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:14:17 -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 v3 8/8] scsi: ufs: Use UFS device indicated maximum LU number Date: Sun, 19 Jan 2020 01:13:27 +0100 Message-Id: <20200119001327.29155-9-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119001327.29155-1-huobean@gmail.com> References: <20200119001327.29155-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 Signed-off-by: Bean Huo Reviewed-by: Alim Akhtar --- 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 dd10558f4d01..bf714221455e 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,