From patchwork Wed Dec 27 22:17:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13505511 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3795B481D7 for ; Wed, 27 Dec 2023 22:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="A5335x0G" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a2330a92ae6so624956166b.0 for ; Wed, 27 Dec 2023 14:17:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703715456; x=1704320256; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gK+Z+cJ3q8PnVX9vvxAmwYo7P5nCQEAASDVIG/h3FtI=; b=A5335x0GpX/qFf1RFyxvzOR+PyrltkD6t2s15lZXqFnYmvTH4o1Ql8LvlFYynTpGbb WbXGkIhS+ooJApPZfKI6TB5MuMQtQ+CZnXgnVFkw8mZW2FU+P3kUS9DhiiGT4oVrVBXF B2lPd8+/CVyHMKAhsXoFtNRgH/M0iMHdB66fJzsyFrUyQ4ngzXwTFawCb+ADasL7EBZR c9m+pq0yJPBkNavajT/8I6JYzXK1dszS6CsN+S8vcylq6zBxmpookvwBfkvqjIeKwZPT TaxwSfQZjyo7tGCTU5rHK1SoezqnJCQs+MpA3/OxS/Uexz9tvjgVAGhCWyp7zP571vuC RkyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703715456; x=1704320256; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gK+Z+cJ3q8PnVX9vvxAmwYo7P5nCQEAASDVIG/h3FtI=; b=QUZDjjw46nB6RNdwJpTZZWgpmMu1dmv+a0Adnaittgwjqigu0Nsm63m8OIpbBYxPXA ydqRJiSfE7KNTMRtuqdviUkUgBoGgpdyBZGEBf7U4QgJuM9UzAEkCfg6ZLFEXHy8zWDo ve06Wn8g698EILCYkY88u/Wznmzuu1tC9wh0N32SQ5e+EVpJiCqqs/BW9KJB0vrujesP TOudFqo7ZL4vbHB3Al2A6Qe7d6Yw/19slp+54ZJz3sNs1BIFubOIAMc3uiIjsNrJHjNF KL7pwDeTiVyTv7rVL7qLf4J+6JSDkEDDhGub2OBWTOmsUqhJgXyjDrf2G9ZbjQ/9QWzj U9lg== X-Gm-Message-State: AOJu0YzWPgYQRnDwIFkemHjdBvW+h/id+aPRA+aNB4N3LazPs0EMUe8E 96aOwMZm3IMxExF/fTq4jSsd17GF5NjnQQ== X-Google-Smtp-Source: AGHT+IEmGdAlzrAbtuChQoDwBsNDjEF9H0lhNM+GWDDSf4l/AEqFQDlgBOJqJA7RA0Rcl9c75JAhPw== X-Received: by 2002:a17:907:710e:b0:a27:59fa:51de with SMTP id zr14-20020a170907710e00b00a2759fa51demr376464ejb.0.1703715456417; Wed, 27 Dec 2023 14:17:36 -0800 (PST) Received: from [10.167.154.1] (178235179028.dynamic-4-waw-k-1-3-0.vectranet.pl. [178.235.179.28]) by smtp.gmail.com with ESMTPSA id ka12-20020a170907920c00b00a26ac57b951sm6245712ejb.23.2023.12.27.14.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 14:17:36 -0800 (PST) From: Konrad Dybcio Date: Wed, 27 Dec 2023 23:17:19 +0100 Subject: [PATCH 1/4] PCI: qcom: Reshuffle reset logic in 2_7_0 .init Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231227-topic-8280_pcie-v1-1-095491baf9e4@linaro.org> References: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> In-Reply-To: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> To: Manivannan Sadhasivam , Bjorn Andersson , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Philipp Zabel , Stanimir Varbanov , Andrew Murray , Vinod Koul Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1703715452; l=2311; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=Y85jS3ioUk1DQv8qH2gvXdl3T2x3NSOAYdPJTx3pyQM=; b=hoXqb4uT3vpTCXfQv6VngPZNtLPyrOIl3j8S1277XzoP0A9AZ2jiqAbd2P3bhkGsgoYh1p5+k 5ue8mA0U803CdHHnSBa93k4XkY3BdR9CeA7LBCBucFfkLjuLg/uUtYK X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= At least on SC8280XP, if the PCIe reset is asserted, the corresponding AUX_CLK will be stuck at 'off'. Assert the reset (which may end up being a NOP if it was previously asserted) and de-assert it back *before* turning on the clocks to avoid such cases. In addition to that, in case the clock bulk enable fails, assert the RC reset back, as the hardware is in an unknown state at best. Fixes: ed8cc3b1fc84 ("PCI: qcom: Add support for SDM845 PCIe controller") Signed-off-by: Konrad Dybcio --- drivers/pci/controller/dwc/pcie-qcom.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index 11c80555d975..1c5ab8c4ff39 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -900,27 +900,27 @@ static int qcom_pcie_init_2_7_0(struct qcom_pcie *pcie) return ret; } - ret = clk_bulk_prepare_enable(res->num_clks, res->clks); - if (ret < 0) - goto err_disable_regulators; - + /* Assert the reset to hold the RC in a known state */ ret = reset_control_assert(res->rst); if (ret) { dev_err(dev, "reset assert failed (%d)\n", ret); - goto err_disable_clocks; + goto err_disable_regulators; } - usleep_range(1000, 1500); + /* GCC_PCIE_n_AUX_CLK won't come up if the reset is asserted */ ret = reset_control_deassert(res->rst); if (ret) { dev_err(dev, "reset deassert failed (%d)\n", ret); - goto err_disable_clocks; + goto err_disable_regulators; } - /* Wait for reset to complete, required on SM8450 */ usleep_range(1000, 1500); + ret = clk_bulk_prepare_enable(res->num_clks, res->clks); + if (ret < 0) + goto err_assert_reset; + /* configure PCIe to RC mode */ writel(DEVICE_TYPE_RC, pcie->parf + PARF_DEVICE_TYPE); @@ -951,8 +951,9 @@ static int qcom_pcie_init_2_7_0(struct qcom_pcie *pcie) writel(val, pcie->parf + PARF_AXI_MSTR_WR_ADDR_HALT_V2); return 0; -err_disable_clocks: - clk_bulk_disable_unprepare(res->num_clks, res->clks); + +err_assert_reset: + reset_control_assert(res->rst); err_disable_regulators: regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies); From patchwork Wed Dec 27 22:17:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13505512 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36F444879D for ; Wed, 27 Dec 2023 22:17:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SzFB0SoH" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-40d4103aed7so67803635e9.3 for ; Wed, 27 Dec 2023 14:17:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703715458; x=1704320258; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=XL9QepTktwRzfZ1qfRmphE2ZEXra95fLycdHekby0tw=; b=SzFB0SoHfO6lnGAoYKGzsl3LyvoA6zou9C9a1N9/RGZHVPq/qEZzGvy9BaHFI+rDG2 Qn4Q9xR+8UfeZhsxpyfvNHKwWV7ZjIE4BKOZd23Rnp43CaGGCZM1JyfPbdCNlF2Slpav pC9gNcJ8JOY2QsZZBj0uQZYOFOdj/jFw3EE3cIMMVH37A6HZYrtij9pwfHO/VsXK1tl7 2xUiS4fwpGr4Hb67G5iZfbV8Eq7Bpa7rMcCKcyTQipG0WsY03LzU/lCc2D9tWC/Q5j8f 2LxFmOuJIBBVtiDYhNNAdX6gIkq+/MgYYvywbYjwDUKXU2WWxHch8ao/M9+P+iHz8GAl 9wuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703715458; x=1704320258; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XL9QepTktwRzfZ1qfRmphE2ZEXra95fLycdHekby0tw=; b=bZvgw8xGEI+cj/rkUwClp1a/IIBYjhamODX21GnuY9zAD2WQc5VvgPPegs6D6Nlw6b eF/LJQWypd89HQ3CbHWXyRKMTNl96wugI+iFqbQbI2bbR3QUDFUeKyqDDXvWYcf00nrC XZmTy9Pu26MY1UdnnLyZ1YdtuPvrEu0pTohC5RFT0rFzqa1OT4grd0amBBn8Pue1/ae8 hY8VnsEdSK6Mb0fYKbxedmSOWIXZ2weHxw5X65/Of6E+Jru9OSmd3P9zW0bzmevPB3hM jbqMJPpYjef05/to7qlsTAflHsPc5jCjCMWKUFoIqmIYIQ6HCOL5kI1qfcSYTrY8yIFj c+6Q== X-Gm-Message-State: AOJu0Yyh+nXXJCb9AoqtnSPmG6jPuiAHjSDTJcZyxBslCgfLHvCvQe9C YCtIu8PRpnDl5q70dqeDxdggNHLvsa217w== X-Google-Smtp-Source: AGHT+IFKSca7nTTTQLFFlnwqXjCbtcDKKbUOZbqtSZT1icxeWa+sWDrNIIqnQWtn+IzsLjf8TSfnyA== X-Received: by 2002:a05:600c:3d0f:b0:40d:43cf:275d with SMTP id bh15-20020a05600c3d0f00b0040d43cf275dmr5306262wmb.95.1703715458571; Wed, 27 Dec 2023 14:17:38 -0800 (PST) Received: from [10.167.154.1] (178235179028.dynamic-4-waw-k-1-3-0.vectranet.pl. [178.235.179.28]) by smtp.gmail.com with ESMTPSA id ka12-20020a170907920c00b00a26ac57b951sm6245712ejb.23.2023.12.27.14.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 14:17:38 -0800 (PST) From: Konrad Dybcio Date: Wed, 27 Dec 2023 23:17:20 +0100 Subject: [PATCH 2/4] PCI: qcom: Cache last icc bandwidth Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231227-topic-8280_pcie-v1-2-095491baf9e4@linaro.org> References: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> In-Reply-To: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> To: Manivannan Sadhasivam , Bjorn Andersson , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Philipp Zabel , Stanimir Varbanov , Andrew Murray , Vinod Koul Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1703715452; l=1504; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=qF9x2W0s+UbihjgEpXNx/tQIgEfBt4CokexyeClTC+s=; b=Ut2csbDk7i4ucgHp6UiLrRct7RJZYvkH0BNoyJ8o1AoM6NSg7odFU8uAlhMsvQEgQQw386KHm heme3d3SgUKDZ8ZSDcx8Df6lN0kgFUqgL2+0+7MI/sZqxjzPzB0J705 X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= In preparation for shutting down the RC, cache the last interconnect bandwidth vote to allow for icc tag setting. Signed-off-by: Konrad Dybcio --- drivers/pci/controller/dwc/pcie-qcom.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index 1c5ab8c4ff39..a02dc197c495 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -240,6 +240,7 @@ struct qcom_pcie { struct phy *phy; struct gpio_desc *reset; struct icc_path *icc_mem; + u32 last_bw; const struct qcom_pcie_cfg *cfg; struct dentry *debugfs; bool suspended; @@ -1387,6 +1388,8 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie) return ret; } + pcie->last_bw = QCOM_PCIE_LINK_SPEED_TO_BW(1); + return 0; } @@ -1415,6 +1418,8 @@ static void qcom_pcie_icc_update(struct qcom_pcie *pcie) dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n", ret); } + + pcie->last_bw = width * QCOM_PCIE_LINK_SPEED_TO_BW(speed); } static int qcom_pcie_link_transition_count(struct seq_file *s, void *data) @@ -1578,6 +1583,8 @@ static int qcom_pcie_suspend_noirq(struct device *dev) return ret; } + pcie->last_bw = kBps_to_icc(1); + /* * Turn OFF the resources only for controllers without active PCIe * devices. For controllers with active devices, the resources are kept From patchwork Wed Dec 27 22:17:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13505513 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E171248CD4 for ; Wed, 27 Dec 2023 22:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fvL3cTvl" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a26fbc3b9f2so234689866b.3 for ; Wed, 27 Dec 2023 14:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703715460; x=1704320260; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Qv1f3IGwStmHyloSnSBvki0PIRsmiqgftIEyyglb5rc=; b=fvL3cTvl8xoQCcbsfR86wsmEn3TW0hbGFsoXD5wOkUN/O91Gq+IjY3n+vxgnyD2ZDX qhA8lbuU8qTUBgtDmXRwb4K6qSvNTNnQZFcFffdhxqBCQSEm8Ak0ASXdfFzseSxMe/39 YixBJLk6UVKHE1MNC5k2eqtxdHlr40LcvhmLTWvJzXgfOK1RYfbPjD0nwquNmhUNqqcm IAc+V8mAR5LCIENEd5iWa6BCIDmyIIv5sdJRI5yXSgRte0sE6RT1fWPh5GEFB6hCSOYX nYxTh+0k/LgkUKkwfJmY7+U/jDwCZW5EwgyN1X42xnVEb+Dv428kcPO/NEWZeCN1TIJu T58g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703715460; x=1704320260; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qv1f3IGwStmHyloSnSBvki0PIRsmiqgftIEyyglb5rc=; b=X3t0r4ucXVdZU4PHzQXcsTxYnVMHJ8IuNbrvucdbdbzJ0v1KMMqZQWNqY0fb+4AhS+ Q891R6RYw7PJm6oKbYW1+Mw3KSKOwE+mlxFvRn40dKZcZedUj6GgD1Ji4x80I4UZH98U 22fC7cdoxdBTRPdNUN3PugdMSETMye8fpSFuQJhQTzY5y9aB1Va6NDBojeHHPkmBj5cU O3pKYCIDuUyQkYs7inPjTTszaNF4wB97rQmur+W4jUDNISLfin6H2O/HQJ5IykhaHW0v 3Dpb/4mz96HRZRoD8mP/W4nvd31xmfOg1bh+bhJaah/O/5kcA1XJFvQAST1tXiYg2iBZ 5bpg== X-Gm-Message-State: AOJu0YyPhFcfhNSyYbMPSLkapQBL+RkO+bH1hEp5Z6hyhbgQk7JOttjS 998VEKPh6WjaleS3W9eWEml5FgUzkbL6eQ== X-Google-Smtp-Source: AGHT+IEjDQu21xE/LPMlU62SFkip9Wm7Icngx8+XC8yCL5jhIVQvu5IRS8ODafE/Dqc3D1LdIZBM0Q== X-Received: by 2002:a17:906:6dd1:b0:a23:67d2:917e with SMTP id j17-20020a1709066dd100b00a2367d2917emr3472572ejt.49.1703715460247; Wed, 27 Dec 2023 14:17:40 -0800 (PST) Received: from [10.167.154.1] (178235179028.dynamic-4-waw-k-1-3-0.vectranet.pl. [178.235.179.28]) by smtp.gmail.com with ESMTPSA id ka12-20020a170907920c00b00a26ac57b951sm6245712ejb.23.2023.12.27.14.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 14:17:39 -0800 (PST) From: Konrad Dybcio Date: Wed, 27 Dec 2023 23:17:21 +0100 Subject: [PATCH 3/4] PCI: qcom: Read back PARF_LTSSM register Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231227-topic-8280_pcie-v1-3-095491baf9e4@linaro.org> References: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> In-Reply-To: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> To: Manivannan Sadhasivam , Bjorn Andersson , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Philipp Zabel , Stanimir Varbanov , Andrew Murray , Vinod Koul Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1703715452; l=809; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=SCdDoH6C4jQKG683KeNay0sGQ+ywn+l9rUD6/n0edxY=; b=5d7QgU89R2lgV1XIURi/gtDcJ2KsWZR9axUKhgApYl0LlE+UkpwW+FizXcSBfdubNhkkb/oop XAMjodXAI+FB9TyZR5HK4o5sVnLxz7aenGFYtzPk3DTqzr6bSb3Ntru X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= To ensure write completion, read the PARF_LTSSM register after setting the LTSSM enable bit before polling for "link up". Signed-off-by: Konrad Dybcio Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-qcom.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index a02dc197c495..3d77269e70da 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -540,6 +540,7 @@ static void qcom_pcie_2_3_2_ltssm_enable(struct qcom_pcie *pcie) val = readl(pcie->parf + PARF_LTSSM); val |= LTSSM_EN; writel(val, pcie->parf + PARF_LTSSM); + readl(pcie->parf + PARF_LTSSM); } static int qcom_pcie_get_resources_2_3_2(struct qcom_pcie *pcie) From patchwork Wed Dec 27 22:17:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13505514 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80B248CD4 for ; Wed, 27 Dec 2023 22:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="G0d0lnHw" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-40d60ad5f0bso6406435e9.0 for ; Wed, 27 Dec 2023 14:17:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703715462; x=1704320262; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JMW6ukEiM+bQd9qassIFQqfy72BMmAOOOw/d3jPA85w=; b=G0d0lnHwgcAIcmyksM9VgnpL/7oBNggZdwQO8Ia25EBTIfUHEFl6w4rGAW3MytS86u HtX95vYLFOl39FMS/bVQ7y6tvsVNBfySVjrFiXiPnrfrYkN8VktBBvRnPmL20SuVHIS+ NbhEk1dJ6HdD2nAfZXiO9jJ3UHTK4yQelZONJ7RlJRIPkkdTGVbmTGZGYQ/VjPQRT9YZ KqpkYNZ9szjsItVFMxKvX7RcB8yllEc9mPU/RptdmK1xOrCnLqGfOvGVOWULwnJvuXyN /EfMQEWgetUUcbDrQrd6PZjAyQGAAwqEzMwAI7yvBEXcMqN2fQHHwPEQ8x18/1Dp00hA vIBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703715462; x=1704320262; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JMW6ukEiM+bQd9qassIFQqfy72BMmAOOOw/d3jPA85w=; b=DT5/2Kmrg3Nk8GVzd38BwmUWoeG2ilRQ4tXZv0nUVx6JNBp7QVZFGLmT5P7qJNwnD8 XwMdhCtYCQolb42mclxT0RNIHFGDLOz9LGVPvmoE7jlHcapZFY0eJPEf1SC6OWAjlw4K gyODEUkLkH37LYwavp+ev4qYnti179k0z1+YCpGUmnWF7vDApy1XG9UC1wobYut/eE7y 3KnYs3EykD4drRAkwIRUfz0BmkaCsKElxnomUtAF75lyoAPKQns4ACDtmHfkRoFVGFTD B08cjuZMTpWGMQyP+Bo/MezmPiSpe8i0d/TXeM92xOYKTQVv0+bYQvvwnKtVsPp4x5Ii CCzw== X-Gm-Message-State: AOJu0YwtncPw4DXGZqGdHso2KBnfU3SjYtDg3DeJ1YdHBnzNPvFBMvBV p4peGfaV2djMg3IExWtc14HxOkaF6d2eaw== X-Google-Smtp-Source: AGHT+IEr15ffMgiQ3ANHhn07jb1hFR1fa4gU3lzjq5kUeQ+ddpFRXVz7e5oRD0tOd8r2C+rfmkD7hw== X-Received: by 2002:a05:600c:17c5:b0:40c:23f2:c12d with SMTP id y5-20020a05600c17c500b0040c23f2c12dmr5990327wmo.153.1703715462252; Wed, 27 Dec 2023 14:17:42 -0800 (PST) Received: from [10.167.154.1] (178235179028.dynamic-4-waw-k-1-3-0.vectranet.pl. [178.235.179.28]) by smtp.gmail.com with ESMTPSA id ka12-20020a170907920c00b00a26ac57b951sm6245712ejb.23.2023.12.27.14.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 14:17:41 -0800 (PST) From: Konrad Dybcio Date: Wed, 27 Dec 2023 23:17:22 +0100 Subject: [PATCH 4/4] PCI: qcom: Implement RC shutdown/power up Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231227-topic-8280_pcie-v1-4-095491baf9e4@linaro.org> References: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> In-Reply-To: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> To: Manivannan Sadhasivam , Bjorn Andersson , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Philipp Zabel , Stanimir Varbanov , Andrew Murray , Vinod Koul Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio , Bjorn Andersson X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1703715452; l=8228; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=SOHIxQch7KXN/NGvpDtApiAK8bsu3Kt0tHCXPIEY/a0=; b=xVcIdOfd/R7LBqRnVfBIvqWNV9w5aFC1KSyhcHiWwrzFkZhRInKUsu+Sd0pgORsK7kjNqLb7t QjPMlmRMzR7DcWsREhyibEnaO9tpu+uo+5rhSL+Z7jpgINJZP/23Rb+ X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Currently, we've only been minimizing the power draw while keeping the RC up at all times. This is suboptimal, as it draws a whole lot of power and prevents the SoC from power collapsing. Implement full shutdown and re-initialization to allow for powering off the controller. This is mainly intended for v1_9_0 (sc8280xp), but the hardware is rather similar across the board. More platform-specific details may be added in the future as necessary. Co-developed-by: Bjorn Andersson Signed-off-by: Konrad Dybcio --- drivers/pci/controller/dwc/Kconfig | 1 + drivers/pci/controller/dwc/pcie-qcom.c | 132 +++++++++++++++++++++++++-------- 2 files changed, 102 insertions(+), 31 deletions(-) diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index 5ac021dbd46a..591c4109ed62 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -268,6 +268,7 @@ config PCIE_DW_PLAT_EP config PCIE_QCOM bool "Qualcomm PCIe controller (host mode)" depends on OF && (ARCH_QCOM || COMPILE_TEST) + depends on QCOM_COMMAND_DB || QCOM_COMMAND_DB=n depends on PCI_MSI select PCIE_DW_HOST select CRC8 diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index 3d77269e70da..a9e24fcd1f66 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -30,13 +30,18 @@ #include #include #include +#include #include "../../pci.h" #include "pcie-designware.h" +#include +#include + /* PARF registers */ #define PARF_SYS_CTRL 0x00 #define PARF_PM_CTRL 0x20 +#define PARF_PM_STTS 0x24 #define PARF_PCS_DEEMPH 0x34 #define PARF_PCS_SWING 0x38 #define PARF_PHY_CTRL 0x40 @@ -80,7 +85,10 @@ #define L1_CLK_RMV_DIS BIT(1) /* PARF_PM_CTRL register fields */ -#define REQ_NOT_ENTR_L1 BIT(5) +#define REQ_NOT_ENTR_L1 BIT(5) /* "Prevent L0->L1" */ + +/* PARF_PM_STTS register fields */ +#define PM_ENTER_L23 BIT(5) /* PARF_PCS_DEEMPH register fields */ #define PCS_DEEMPH_TX_DEEMPH_GEN1(x) FIELD_PREP(GENMASK(21, 16), x) @@ -122,6 +130,7 @@ /* ELBI_SYS_CTRL register fields */ #define ELBI_SYS_CTRL_LT_ENABLE BIT(0) +#define ELBI_SYS_CTRL_PME_TURNOFF_MSG BIT(4) /* AXI_MSTR_RESP_COMP_CTRL0 register fields */ #define CFG_REMOTE_RD_REQ_BRIDGE_SIZE_2K 0x4 @@ -244,6 +253,7 @@ struct qcom_pcie { const struct qcom_pcie_cfg *cfg; struct dentry *debugfs; bool suspended; + bool soc_is_rpmh; }; #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) @@ -273,6 +283,24 @@ static int qcom_pcie_start_link(struct dw_pcie *pci) return 0; } +static int qcom_pcie_stop_link(struct dw_pcie *pci) +{ + struct qcom_pcie *pcie = to_qcom_pcie(pci); + u32 ret_l23, val; + + writel(ELBI_SYS_CTRL_PME_TURNOFF_MSG, pcie->elbi + ELBI_SYS_CTRL); + readl(pcie->elbi + ELBI_SYS_CTRL); + + ret_l23 = readl_poll_timeout(pcie->parf + PARF_PM_STTS, val, + val & PM_ENTER_L23, 10000, 100000); + if (ret_l23) { + dev_err(pci->dev, "Failed to enter L2/L3\n"); + return -ETIMEDOUT; + } + + return 0; +} + static void qcom_pcie_clear_hpc(struct dw_pcie *pci) { u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); @@ -991,9 +1019,19 @@ static void qcom_pcie_host_post_init_2_7_0(struct qcom_pcie *pcie) static void qcom_pcie_deinit_2_7_0(struct qcom_pcie *pcie) { struct qcom_pcie_resources_2_7_0 *res = &pcie->res.v2_7_0; + u32 val; + + /* Disable PCIe clocks and resets */ + val = readl(pcie->parf + PARF_PHY_CTRL); + val |= PHY_TEST_PWR_DOWN; + writel(val, pcie->parf + PARF_PHY_CTRL); + readl(pcie->parf + PARF_PHY_CTRL); clk_bulk_disable_unprepare(res->num_clks, res->clks); + reset_control_assert(res->rst); + usleep_range(2000, 2500); + regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies); } @@ -1553,6 +1591,9 @@ static int qcom_pcie_probe(struct platform_device *pdev) goto err_phy_exit; } + /* If the soc features RPMh, cmd_db must have been prepared by now */ + pcie->soc_is_rpmh = !cmd_db_ready(); + qcom_pcie_icc_update(pcie); if (pcie->mhi) @@ -1569,60 +1610,89 @@ static int qcom_pcie_probe(struct platform_device *pdev) return ret; } -static int qcom_pcie_suspend_noirq(struct device *dev) +static int qcom_pcie_resume_noirq(struct device *dev) { struct qcom_pcie *pcie = dev_get_drvdata(dev); int ret; /* - * Set minimum bandwidth required to keep data path functional during - * suspend. + * Undo the tag change from qcom_pcie_suspend_noirq first in case + * RPM(h) spontaneously decides to power collapse the platform based + * on other inputs. */ - ret = icc_set_bw(pcie->icc_mem, 0, kBps_to_icc(1)); + icc_set_tag(pcie->icc_mem, pcie->soc_is_rpmh ? QCOM_ICC_TAG_ALWAYS : RPM_ALWAYS_TAG); + /* Flush the tag change */ + ret = icc_set_bw(pcie->icc_mem, 0, pcie->last_bw); if (ret) { - dev_err(dev, "Failed to set interconnect bandwidth: %d\n", ret); + dev_err(pcie->pci->dev, "failed to set interconnect bandwidth: %d\n", ret); return ret; } - pcie->last_bw = kBps_to_icc(1); + /* Only check this now to make sure the icc vote is in before going furhter. */ + if (!pcie->suspended) + return 0; - /* - * Turn OFF the resources only for controllers without active PCIe - * devices. For controllers with active devices, the resources are kept - * ON and the link is expected to be in L0/L1 (sub)states. - * - * Turning OFF the resources for controllers with active PCIe devices - * will trigger access violation during the end of the suspend cycle, - * as kernel tries to access the PCIe devices config space for masking - * MSIs. - * - * Also, it is not desirable to put the link into L2/L3 state as that - * implies VDD supply will be removed and the devices may go into - * powerdown state. This will affect the lifetime of the storage devices - * like NVMe. - */ - if (!dw_pcie_link_up(pcie->pci)) { - qcom_pcie_host_deinit(&pcie->pci->pp); - pcie->suspended = true; - } + ret = qcom_pcie_host_init(&pcie->pci->pp); + if (ret) + goto revert_icc_tag; + + dw_pcie_setup_rc(&pcie->pci->pp); + + ret = qcom_pcie_start_link(pcie->pci); + if (ret) + goto deinit_host; + + /* Ignore the retval, the devices may come up later. */ + dw_pcie_wait_for_link(pcie->pci); + + qcom_pcie_icc_update(pcie); + + pcie->suspended = false; return 0; + +deinit_host: + qcom_pcie_host_deinit(&pcie->pci->pp); +revert_icc_tag: + icc_set_tag(pcie->icc_mem, pcie->soc_is_rpmh ? QCOM_ICC_TAG_WAKE : RPM_ACTIVE_TAG); + /* Ignore the retval, failing here would be tragic anyway.. */ + icc_set_bw(pcie->icc_mem, 0, pcie->last_bw); + + return ret; } -static int qcom_pcie_resume_noirq(struct device *dev) +static int qcom_pcie_suspend_noirq(struct device *dev) { struct qcom_pcie *pcie = dev_get_drvdata(dev); int ret; - if (pcie->suspended) { - ret = qcom_pcie_host_init(&pcie->pci->pp); + if (pcie->suspended) + return 0; + + if (dw_pcie_link_up(pcie->pci)) { + ret = qcom_pcie_stop_link(pcie->pci); if (ret) return ret; + } - pcie->suspended = false; + qcom_pcie_host_deinit(&pcie->pci->pp); + + /* + * The PCIe RC may be covertly accessed by the secure firmware on sleep exit. + * Use the WAKE bucket to let RPMh pull the plug on PCIe in sleep, + * but guarantee it comes back for resume. + */ + icc_set_tag(pcie->icc_mem, pcie->soc_is_rpmh ? QCOM_ICC_TAG_WAKE : RPM_ACTIVE_TAG); + /* Flush the tag change */ + ret = icc_set_bw(pcie->icc_mem, 0, pcie->last_bw); + if (ret) { + dev_err(pcie->pci->dev, "failed to set interconnect bandwidth: %d\n", ret); + + /* Revert everything and hope the next icc_set_bw goes through.. */ + return qcom_pcie_resume_noirq(dev); } - qcom_pcie_icc_update(pcie); + pcie->suspended = true; return 0; }