Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2541737pxv; Sat, 24 Jul 2021 21:04:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9OT+/v9Y5a3bbccleApQb2uuSxGRa/I7oA3W1zKq+Ypg6CCoSTib2I4F8Lq3U6QkqFZWQ X-Received: by 2002:a5e:d80e:: with SMTP id l14mr9707104iok.79.1627185854931; Sat, 24 Jul 2021 21:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627185854; cv=none; d=google.com; s=arc-20160816; b=nYzqSDyMVkgrgRmfnCmByG/mfUWbcxRevOua6ax/DfkwADDl7g9t90qrXdHJ2znsqE 5DwSYla1sc2cMezFWoaL6S+3OMgsouh2f5icTOmEASKJ9bUaxO0lyp/dD3pR77AXZ9v2 YomtaEijg5slLnWKuNIcCH1FxtUpANneH06a2CBsY6765buviiwDRRfJjpbLJsdBX3Il aFaBniGCg2oxVLw8hPWnh3xpRQxGzHNHa5C/BvA4Y3MBn3futnxwROyFYGeG6HBOc9IG gqGpYdYtTUX9YP9/DWEOiGCMJjdn639Demy/2G2IUOHC/giZ8rZlYEGMxNAtggN8MiTi TZqQ== 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=fdmG3WG+Fl0BSnXJiqQEACHTkoffgPGp8XBicBQYpOo=; b=J2vUzrz5R6BpFSYBsrkbcYNxFDofYQJLRoYmlhaIPQy3bV+y6Uw7wudA2H2NVA2ipg UjYeGr2fp5k73Gu3q5rzW5ecRJyEplKewH2SUpChQjZ14qavz+s3P4RN6lweLqMI/875 oD9zt9lIoe+NeH58Mchm3hCVpTKhAWKcpjS0z2yQzvbwfiLYbmnMP4yGzZKpAY6LMOqU ZgyLV/V9PbAYMjyXjwNGOu9UXLj7JbEOOpLhYfLU64EsbUfP4BHEJlVNMJh4yqyxhB7F zaM63nuueaZhUEiWfG6cPC48e04llhzXtqnvvmz/xRZ/QRRhxHfDkJydR7Q8YpocjMGX 1Z7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bUyKH/yL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si19695977ilf.150.2021.07.24.21.03.51; Sat, 24 Jul 2021 21:04:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bUyKH/yL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229609AbhGYDWB (ORCPT + 99 others); Sat, 24 Jul 2021 23:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbhGYDV4 (ORCPT ); Sat, 24 Jul 2021 23:21:56 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46ECC061765 for ; Sat, 24 Jul 2021 21:02:26 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id q6so6839428oiw.7 for ; Sat, 24 Jul 2021 21:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fdmG3WG+Fl0BSnXJiqQEACHTkoffgPGp8XBicBQYpOo=; b=bUyKH/yL3uKMbRoFBycdV+AfDTE8ss1Qs1/Iw/icuLQwu0o4EOMDP7GIRMNwKcr9kW TI689VHRtv20TGBCCfe8QuPkiTDNYfaDpm4xbygf5xNYpF4L01c/QeVtBXhDpqxFeuiz dgvdUIOW6fmhDCjZSPqduzmtRWmExefdakj4p3o0RbSUhQu+mGrk+nggXMFUOeb481cQ JFPJdoh+CivVAFlrOF70psrME2PALWFTsqKG9GxYCzIGecNlisqhJvwRv7bTnnxyPael w+GNjKNDJbfaDWklYcEOAZw5MxZSL1sGyQy8sZgkCeqLL2mU8A1UkbZJWmCzwHMyjVUP 3a7g== 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:mime-version:content-transfer-encoding; bh=fdmG3WG+Fl0BSnXJiqQEACHTkoffgPGp8XBicBQYpOo=; b=tyAsEJOCVlbZTuWTdnmnorkFqY6pX0K0PpEMM4R0ky8krcuvnAgOdmOCYjoHlv/zND SEgVZ4eW9bkin/N2/gOQXYeHJLHikVrDVlIfh7VjIM1w4kYc9MXYF6HnO+D6POkqU2GQ yQHUvb+Wlnd0bo1JH51UXYmkdIgUlGGbwaE2l0GVg/W/al1bU0Rj/1qVFpAMQeRP/6n8 /vs9xXbkJb5rlVtVcPmG3n19boQKjB3Jmdz1wyIGhONbdQPCZxZdBpRWgFlwsyyIjTFo jj6HD0h32GlvaM5Y1PAJ2lMskJ1EQHS4p2Q37wOOUlhp4h2ZOeLwdIZbJdVXrLZQpn2T ySLw== X-Gm-Message-State: AOAM5306TkUVrkLhhqyCIDQa72b61YekRGmDfvH4/OdWBtZAuQy9ZW6Q Ttrw0lzbpCoQGL6KmbXighnuLA== X-Received: by 2002:aca:4355:: with SMTP id q82mr13228367oia.165.1627185746154; Sat, 24 Jul 2021 21:02:26 -0700 (PDT) Received: from localhost.localdomain (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id q20sm872910otv.50.2021.07.24.21.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 21:02:25 -0700 (PDT) From: Bjorn Andersson To: Bjorn Helgaas , Rob Herring , Stanimir Varbanov , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= Cc: linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] PCI: qcom: Introduce enable/disable resource ops Date: Sat, 24 Jul 2021 21:00:36 -0700 Message-Id: <20210725040038.3966348-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210725040038.3966348-1-bjorn.andersson@linaro.org> References: <20210725040038.3966348-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current model of doing resource enablement and controller initialization in a single "init" function invoked after dw_pcie_host_init() is invoked might result in clocks not being enabled at the time the "msi" interrupt fires. One such case happens reliably on the SC8180x (8cx) Snapdragon laptops, where it's seems like the bootloader touches PCIe and leaves things in a state that the "msi" interrupt will fire before we have a change to enable the clocks, resulting in an access of unclocked hardware. Introduce a two new callbacks, allowing the individual resource handling functions to be split between enable/init and deinit/disable. Helper functions for enable, disable and deinit are introduced to handle the fact that these functions may now be left without implementation. init is given a wrapper for symmetry. Signed-off-by: Bjorn Andersson --- drivers/pci/controller/dwc/pcie-qcom.c | 42 +++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index 8a7a300163e5..8a64a126de2b 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -181,9 +181,11 @@ struct qcom_pcie; struct qcom_pcie_ops { int (*get_resources)(struct qcom_pcie *pcie); + int (*enable_resources)(struct qcom_pcie *pcie); int (*init)(struct qcom_pcie *pcie); int (*post_init)(struct qcom_pcie *pcie); void (*deinit)(struct qcom_pcie *pcie); + void (*disable_resources)(struct qcom_pcie *pcie); void (*post_deinit)(struct qcom_pcie *pcie); void (*ltssm_enable)(struct qcom_pcie *pcie); int (*config_sid)(struct qcom_pcie *pcie); @@ -1345,6 +1347,31 @@ static int qcom_pcie_config_sid_sm8250(struct qcom_pcie *pcie) return 0; } +static int qcom_pcie_enable_resources(struct qcom_pcie *pcie) +{ + if (pcie->ops->enable_resources) + return pcie->ops->enable_resources(pcie); + + return 0; +} + +static int qcom_pcie_init(struct qcom_pcie *pcie) +{ + return pcie->ops->init(pcie); +} + +static void qcom_pcie_deinit(struct qcom_pcie *pcie) +{ + if (pcie->ops->deinit) + pcie->ops->deinit(pcie); +} + +static void qcom_pcie_disable_resources(struct qcom_pcie *pcie) +{ + if (pcie->ops->disable_resources) + pcie->ops->disable_resources(pcie); +} + static int qcom_pcie_host_init(struct pcie_port *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); @@ -1353,7 +1380,7 @@ static int qcom_pcie_host_init(struct pcie_port *pp) qcom_ep_reset_assert(pcie); - ret = pcie->ops->init(pcie); + ret = qcom_pcie_init(pcie); if (ret) return ret; @@ -1384,7 +1411,7 @@ static int qcom_pcie_host_init(struct pcie_port *pp) err_disable_phy: phy_power_off(pcie->phy); err_deinit: - pcie->ops->deinit(pcie); + qcom_pcie_deinit(pcie); return ret; } @@ -1520,10 +1547,14 @@ static int qcom_pcie_probe(struct platform_device *pdev) pp->ops = &qcom_pcie_dw_ops; + ret = qcom_pcie_enable_resources(pcie); + if (ret) + goto err_pm_runtime_put; + ret = phy_init(pcie->phy); if (ret) { pm_runtime_disable(&pdev->dev); - goto err_pm_runtime_put; + goto err_disable_resources; } platform_set_drvdata(pdev, pcie); @@ -1532,11 +1563,14 @@ static int qcom_pcie_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "cannot initialize host\n"); pm_runtime_disable(&pdev->dev); - goto err_pm_runtime_put; + goto err_disable_resources; } return 0; +err_disable_resources: + qcom_pcie_disable_resources(pcie); + err_pm_runtime_put: pm_runtime_put(dev); pm_runtime_disable(dev); -- 2.29.2