Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1021845ybl; Fri, 10 Jan 2020 10:39:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwCQt89vXYaEOiw3t6zU3mXZTQPkUgPKIEQODNyk2f8+Vobr4RCxM+B5aRNORN3IMKWTMRG X-Received: by 2002:aca:1011:: with SMTP id 17mr3404313oiq.72.1578681555390; Fri, 10 Jan 2020 10:39:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578681555; cv=none; d=google.com; s=arc-20160816; b=dKCCvdE1uG0ufe+hQ8ptO30oqVS6YT7/6YJX1nVP++PxoILi5bKeAzLbCc4lbzHvMr 4v4uY5Gdug5MDjJ6AdJsMOTVMdLUSWvKpcn9fn5mMoS/zqURxdsPK77KWHT/KQd+kcCN GIifM73L7BvOYuGYl0veogksG1dp1V7UQbYY9Lqk/jCrhtarZLktT2KD/e/OL0FJH/VD M8Yl2dceioLoo19M3QHZ55kusGgssFjAk0/1hPbiMVGMA5ohGP7RAK5LpWsL4bfOhP5i 1eDRvJxILMk2a6JnIkSgoEcLv1HCv/+rtKlg1tSG1MsyWPEYxNZYn4TmDIB43qkHLKEm +WuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=RXhuYHUQf7uxSiQZxx/MA7iyUWDN3SLdWOsQTulC9S4=; b=QgFperc8VOsGQSZINuoz4uBA/oyGPVve8jQ08CAqg3P0ud84IfL54rK7eiENks3Mxc W8xhiXCZ7bR4KHL/FO2K9QccHqi2e7p+8nVG1aatuHNwee2cFVdhtnZPH49fOXsMo7tB cZLJwxJpvGs69q06dL57ymeludEWSLYN6ZuvgChRYTCoWYdwGrG8lghgJoS+OINi8OVr hVJPIHbClU/aKwNjMPNSQOrAbnCqr8pfVsno4UX9oAtwAjvscnHnVh6pUG2QxVzn5/H1 1YTF+lJDqzq1h//DJSFB3ToIiQoQn1LsVsH6B3RSt+6iJpDf3riffr1B2pDFAQYXNhEn Txng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=R78av0Pm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21si2257645oth.174.2020.01.10.10.39.02; Fri, 10 Jan 2020 10:39:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=R78av0Pm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728753AbgAJSgt (ORCPT + 99 others); Fri, 10 Jan 2020 13:36:49 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44561 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728400AbgAJSgn (ORCPT ); Fri, 10 Jan 2020 13:36:43 -0500 Received: by mail-wr1-f66.google.com with SMTP id q10so2737286wrm.11; Fri, 10 Jan 2020 10:36:42 -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=RXhuYHUQf7uxSiQZxx/MA7iyUWDN3SLdWOsQTulC9S4=; b=R78av0PmtrxwhPQn2freZodrqi4x65lDTTlih37Z0jcQ8hPvAioH1eZ/r99mnr6wLV 4r9njGiWAZwDJA7zcALfNLY+BsHrmDSnYnzbo08/yyD+v04hIUCSPzMfH0Ow9Jlz65/8 yrv74QVM8b0n1ilQH/VtWc7j9ct2SKfqd61KIerozpse/2WwBFbeuVHv7LI7DE0B4tQj ImDwcx2GQ+CAGsfR6fimdhwLSe9Yc8P/+oc5pPO9S8Nw1Xwjy9v/YK0TyAeu1MZgL8Bu OgxHEpYr9gFkcouKjJWuiUTAedWrpVEsb3rvpCOLxrk9ANF4KGpiT52rAMuJqB0vcE7v CR/w== 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=RXhuYHUQf7uxSiQZxx/MA7iyUWDN3SLdWOsQTulC9S4=; b=fxsnCvezMYBtVRfoCyXEOFnIC+uWWbs5Rk/lxnII1mCdYINEuoGmvvqI0pMuFvKudo 7/2S/Mm4Qn2a0TFtW9NcqW5v52onlAVwyTzEjEaZCl4beoxEr332Vp6iqDn5gkJVTB/7 66STTd5AVNJHdjNgjt6Fe/uPyhPM+uWxQOjmlfjyV3aDRfo9UDDs0S0GeDxnFkAb+pRz Gcs1XaJhw/U9negHKqB4UoEKlk/7JyHrvZHbb/avbza7G9gVVTWWwA1YcW2oyqLVT6Ac dP3DRF1m9HQftlI3gv/dudQwRwBlWqxjLNMPDxsLV1lKZs8mz3I/etJc2OE0hd6tYvSR ihxA== X-Gm-Message-State: APjAAAX1SHbmnjL82f55Uk9bIx13uq0Ug1X9pkaqJDRLrPM4C+nTktt/ J2AHTCB8j2GB8m2SdZGi6u8= X-Received: by 2002:adf:fd43:: with SMTP id h3mr4747926wrs.169.1578681401414; Fri, 10 Jan 2020 10:36:41 -0800 (PST) Received: from localhost.localdomain (ip5f5bee3c.dynamic.kabel-deutschland.de. [95.91.238.60]) by smtp.gmail.com with ESMTPSA id x11sm3182825wre.68.2020.01.10.10.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 10:36:40 -0800 (PST) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, pedrom.sousa@synopsys.com, 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 2/3] scsi: ufs: initialize max_lu_supported while booting Date: Fri, 10 Jan 2020 19:36:05 +0100 Message-Id: <20200110183606.10102-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200110183606.10102-1-huobean@gmail.com> References: <20200110183606.10102-1-huobean@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bean Huo This patch is to add a new function ufshcd_init_device_param() for initialization of UFS device related parameters which are used by driver. In this version patch, there is only dev_info.max_lu_supported being initialized. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshcd.c | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 1b97f2dc0b63..a297fe55e36a 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3158,6 +3158,11 @@ 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); } +static int ufshcd_read_geometry_desc(struct ufs_hba *hba, u8 *buf, u32 size) +{ + return ufshcd_read_desc(hba, QUERY_DESC_IDN_GEOMETRY, 0, buf, size); +} + /** * struct uc_string_id - unicode string * @@ -6827,6 +6832,37 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) hba->req_abort_count = 0; } +static int ufshcd_init_device_param(struct ufs_hba *hba) +{ + int err; + size_t buff_len; + u8 *desc_buf; + + buff_len = QUERY_DESC_MAX_SIZE; + desc_buf = kmalloc(buff_len, GFP_KERNEL); + if (!desc_buf) { + err = -ENOMEM; + goto out; + } + + err = ufshcd_read_geometry_desc(hba, desc_buf, + hba->desc_size.geom_desc); + 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 void ufshcd_init_desc_sizes(struct ufs_hba *hba) { int err; @@ -7016,13 +7052,22 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) /* * If we are in error handling context or in power management callbacks - * context, no need to scan the host + * context, no need to scan the host and to reinitialize the parameters */ 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)); + /* Init parameters according to UFS relevant descriptors */ + ret = ufshcd_init_device_param(hba); + if (ret) { + dev_err(hba->dev, + "%s: Init of device param failed. err = %d\n", + __func__, ret); + goto out; + } + 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; -- 2.17.1