Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp935375rwb; Thu, 1 Dec 2022 10:07:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5PnX464jxSpPW9rMneasKtdW8Kb/mXOVWdyY/DVs/2necsym1UqIesgn/WsR28JyRPc+1L X-Received: by 2002:a17:906:2352:b0:7ad:a030:487e with SMTP id m18-20020a170906235200b007ada030487emr58475711eja.508.1669918057575; Thu, 01 Dec 2022 10:07:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669918057; cv=none; d=google.com; s=arc-20160816; b=GD40vO0pN/TZE/QpFTphcL2FSfiZPr+9TbxulS5zURpTCNV/yGj9kZUfDrVhF3pYVm Oz6FyfUgv0MsvvAvnYHyWYiLFZllUZkYA1kPu0+V3NYiAtw+GxFRx4CQSs6MQE0oyGz3 JvBEJZapK29ewkrWxtY1KuV+Kt6mqDO3+8dmVTqHG27F0TYwECUpPikqWF2uby8xOwEQ VKB24UBxnDwe3+4lHgyGq2sOrBSdATAq8iFbsKV7enneFRYWz48NIhf3eXgrtkc/Xpfd mD6JF5N0hD1SK5IPjmpRRrg0f2SRmeGWPGzSUDAjVmAhrxLECoYPJd1wNHS5611LI78X NLbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i+a+h42fy9GjOTea32LS7GN+oEWTDG5o4oBP56ao/Mw=; b=OnpCLBpv2j4YbcPQBQ0zbNFKUPwjeiRkywGhTq4fMrMsEu8aV1MMtOQhcMKPxVp1/6 aUaEQ0bBP3fxC7kh4492Cs8vwp3Y/FyyL7y/2pGqTLKLXBgkl0iabu6ZPpHEJ7Smj5/B Ni1yafRODhkbybv2QHqDB3vWcJi3z2rEOFz9oj5QTKbHyA9sUvTgbsaSkGluQ4smm2qe IUTowiKZyDwfKgxzhwHqeZOhnRPjp5026U6cB4jC5KSkQGzb2lN6XDNb2ixIpvkPusqo 2eZoXD+0eS/4IkQbnV9r9QuPbssgYeMxGYgWADjRVLTiTn9itcqENxHUFw3rrMrpq5K5 X7JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AX4O85AL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs31-20020a1709072d1f00b0078e1d1d6005si5196269ejc.23.2022.12.01.10.07.16; Thu, 01 Dec 2022 10:07:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AX4O85AL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbiLARsA (ORCPT + 83 others); Thu, 1 Dec 2022 12:48:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230354AbiLARrL (ORCPT ); Thu, 1 Dec 2022 12:47:11 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9537EBB022 for ; Thu, 1 Dec 2022 09:45:51 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id 136so2295699pga.1 for ; Thu, 01 Dec 2022 09:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i+a+h42fy9GjOTea32LS7GN+oEWTDG5o4oBP56ao/Mw=; b=AX4O85ALoJesLtLqBEOg/DhUkKKW3meVzBnuog7JrhO/MhGJLQp9AMhmcA10OMeMjI Unv28eUYRvrOj2Zz25LNnYU0ZbvfT40/O7M4PxhOVZTm7/Gk3VTA8/E1i4k4HpdCnD7U UbmJ675Zdls+aoS87D7gKCDK5bgnyKL6i2v6wTlTeJYfGWVtJs59psQrwMw+7Cdbsq4g koXjyn82aCADRUU6CAo+QdJ64YSa5X0u9MVXyVcJktKSY8I3CbotELyrtVHYv+JOduy6 eWld9PvRjbMKxAuqJlB2ly0Giee8PVaVbEqvqsXfD21mczNFNsa6Apu9jRPlJzHV2hE1 /7Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i+a+h42fy9GjOTea32LS7GN+oEWTDG5o4oBP56ao/Mw=; b=lVBL5k4hbYblU4CwHyZQM28+aruLmyMX1Cq+E4/7WQ91SIWWazNi6bDD7CxU83Bd/X /es6cDFzKiCzV82xK5Ps/PtG5GMwp6zJGE6pm2Ljmzjc6wXMVng4e6ftOPgH25jAGJnD dsjFovSFkGMPUhQMvaDF2R1bEikdumd9vA7L/wgDbcetz070WS28FkNCRwZGJqbT9oxi awcmHMk8aB5PvK7jNAtUgAZCxHli4s/dJ83gY/bhEgiiYveil/1JQiHPzNCgS1rKRX/8 2YshVg5O/R/RzgJp4Lf8B1d+uF8pOJSG1BjmZjOd6s9+Wez4ifXMbIsDuUKCd9YVY8xy 1YUg== X-Gm-Message-State: ANoB5pmqZPNoeHfEjQEqwZabHAc8wJqdj+g16jPq8JDmiN3EBBb28fE9 lr2tLU9yGkp5Ge6VpDfOk0wq X-Received: by 2002:a05:6a00:1391:b0:575:eaa:c28c with SMTP id t17-20020a056a00139100b005750eaac28cmr23788242pfg.76.1669916751018; Thu, 01 Dec 2022 09:45:51 -0800 (PST) Received: from localhost.localdomain ([220.158.159.39]) by smtp.gmail.com with ESMTPSA id p4-20020a170902780400b0016d9b101413sm3898743pll.200.2022.12.01.09.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 09:45:50 -0800 (PST) From: Manivannan Sadhasivam To: martin.petersen@oracle.com, jejb@linux.ibm.com, andersson@kernel.org, vkoul@kernel.org Cc: quic_cang@quicinc.com, quic_asutoshd@quicinc.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, linux-scsi@vger.kernel.org, dmitry.baryshkov@linaro.org, ahalaney@redhat.com, abel.vesa@linaro.org, alim.akhtar@samsung.com, avri.altman@wdc.com, bvanassche@acm.org, Manivannan Sadhasivam Subject: [PATCH v4 19/23] scsi: ufs: core: Add support for reinitializing the UFS device Date: Thu, 1 Dec 2022 23:13:24 +0530 Message-Id: <20221201174328.870152-20-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221201174328.870152-1-manivannan.sadhasivam@linaro.org> References: <20221201174328.870152-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some platforms like Qcom, requires the UFS device to be reinitialized after switching to maximum gear speed. So add support for that in UFS core by introducing a new quirk (UFSHCD_CAP_REINIT_AFTER_MAX_GEAR_SWITCH) and doing the reinitialization, if the quirk is enabled by the controller driver. Suggested-by: Can Guo Signed-off-by: Manivannan Sadhasivam --- drivers/ufs/core/ufshcd.c | 63 +++++++++++++++++++++++++++++---------- include/ufs/ufshcd.h | 6 ++++ 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index e18c9f4463ec..55714accdfd4 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8153,27 +8153,18 @@ static int ufshcd_add_lus(struct ufs_hba *hba) return ret; } -/** - * ufshcd_probe_hba - probe hba to detect device and initialize it - * @hba: per-adapter instance - * @init_dev_params: whether or not to call ufshcd_device_params_init(). - * - * Execute link-startup and verify device initialization - */ -static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) +static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) { int ret; - unsigned long flags; - ktime_t start = ktime_get(); hba->ufshcd_state = UFSHCD_STATE_RESET; ret = ufshcd_link_startup(hba); if (ret) - goto out; + return ret; if (hba->quirks & UFSHCD_QUIRK_SKIP_PH_CONFIGURATION) - goto out; + return ret; /* Debug counters initialization */ ufshcd_clear_dbg_ufs_stats(hba); @@ -8184,12 +8175,12 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) /* Verify device initialization by sending NOP OUT UPIU */ ret = ufshcd_verify_dev_init(hba); if (ret) - goto out; + return ret; /* Initiate UFS initialization, and waiting until completion */ ret = ufshcd_complete_dev_init(hba); if (ret) - goto out; + return ret; /* * Initialize UFS device parameters used by driver, these @@ -8198,7 +8189,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) if (init_dev_params) { ret = ufshcd_device_params_init(hba); if (ret) - goto out; + return ret; } ufshcd_tune_unipro_params(hba); @@ -8219,11 +8210,51 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) if (ret) { dev_err(hba->dev, "%s: Failed setting power mode, err = %d\n", __func__, ret); + return ret; + } + } + + return 0; +} + +/** + * ufshcd_probe_hba - probe hba to detect device and initialize it + * @hba: per-adapter instance + * @init_dev_params: whether or not to call ufshcd_device_params_init(). + * + * Execute link-startup and verify device initialization + */ +static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) +{ + ktime_t start = ktime_get(); + unsigned long flags; + int ret; + + ret = ufshcd_device_init(hba, init_dev_params); + if (ret) + goto out; + + if (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH) { + /* Reset the device and controller before doing reinit */ + ufshcd_device_reset(hba); + ufshcd_hba_stop(hba); + ufshcd_vops_reinit_notify(hba); + ret = ufshcd_hba_enable(hba); + if (ret) { + dev_err(hba->dev, "Host controller enable failed\n"); + ufshcd_print_evt_hist(hba); + ufshcd_print_host_state(hba); goto out; } - ufshcd_print_pwr_info(hba); + + /* Reinit the device */ + ret = ufshcd_device_init(hba, init_dev_params); + if (ret) + goto out; } + ufshcd_print_pwr_info(hba); + /* * bActiveICCLevel is volatile for UFS device (as per latest v2.1 spec) * and for removable UFS card as well, hence always set the parameter. diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index af8c95077d96..443403d3be72 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -595,6 +595,12 @@ enum ufshcd_quirks { * auto-hibernate capability but it's FASTAUTO only. */ UFSHCD_QUIRK_HIBERN_FASTAUTO = 1 << 18, + + /* + * This quirk needs to be enabled if the host controller needs + * to reinit the device after switching to maximum gear. + */ + UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH = 1 << 19, }; enum ufshcd_caps { -- 2.25.1