From patchwork Mon Apr 1 15:50:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13612875 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 1DDFE481D0 for ; Mon, 1 Apr 2024 15:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711986677; cv=none; b=N8Op5WxR+EFjrik453YdN0i+OXjytyNKJintMoIsyVEuSKOajhEMXGv4mIcVIgo7dX35aPRGXvZ4yxBORvl6B2hozcD0g7dJyPqCdFwFN/ZE2w9gKta/qoIyYJxYPqnP5MLhLeRdP6bte3xfaKhSHDvQtXlIf3q2GfVoYAYpDAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711986677; c=relaxed/simple; bh=Vc/z3bg7iR0DVyjnmsrW91gdlaGDMMW4LWUaKvK6QqA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VF1zgZaCVpCVbbRAbPKRzfAEEwRuwTto1hQx6sNwgBYIXRmX23FHCZ61iwAJiOFLzjieG0x+2RTkmohRNBJykPzWa17psdPLYYQhAzAQzQ2jVmauxWrZ6UZvKUK2oWeWZMDl+6uJ95KAy/sgxPEnZT/2Db/jZmzLFDXkIRq14eg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=u4lbsKRr; arc=none smtp.client-ip=209.85.215.179 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="u4lbsKRr" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso3253780a12.3 for ; Mon, 01 Apr 2024 08:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711986675; x=1712591475; 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=uDwUmdP1vEU79INAYOHEG2Uv5Heyb/Jl8ipwA/CjTc4=; b=u4lbsKRrlA54HXtvbpomTkl0f6e6nWwCS9j2C9jotwbVppSbukXJmmPIfMy7NFes2P MdFnHVCHPAMdoHkYOrXp4+L+7EfXDNBOV1NSbEsb7UxqVGQzTu9enoIZ0+r5/vWySrxo iVBSoRv8LUHxDgsOJJl1sHMcni2L22eLEeC5tz1CJk7m0FshK5PCw8Dqt1gUh0fhNu3G Yz0SelvQ0K8NsqGJC6Q9AsD9wdM1jYkcVA+qGJ622dJ3Ri90CFTTsJWlTvATkZBGAVUd Jl9Tx7jvTz7ljIAdreJ9fbEMFC4pL+r/GyDLyb0o4OJks+DsufkevUoG2AEKJGSsiRJC D+GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711986675; x=1712591475; 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=uDwUmdP1vEU79INAYOHEG2Uv5Heyb/Jl8ipwA/CjTc4=; b=KN6rJucONnud+SCgpF0mmF+i+OMhCvVvJXxPH971z4eUKjlSX4g5Tj788SKcc/ASC9 ynTHI8LucmLWL9tg0NDibY2kftMrevDMXQKmiCpZR0zWRI00h6S0j4YgipL7+aZlcaxt LKgAGfuNd1wM4pONDBZEwpUHIgLminqPzBXnsLsuGluOj/PjQ6x1hHJt7Yp+cf5JkqKS pJEUB9bVrAJYaik5v77UVS2NKw2RZFYqYwuAMrXOPwsIL+4UH66dgwcLurilkIc2DX+Y lA9+UJ7pxah+kAm++OINtG2G4Rcq3ZMlhaYNhDzqmckE0HWJdPKvFO/zvbOlbQpKPmEt +ucA== X-Forwarded-Encrypted: i=1; AJvYcCUrIRLmkiU1r3WXeuc6Y9rKUze7IbJ7NNGOCbhgKNVBshEMgaAnPdtNLmY6f+EKHUmNuJ+kkzVMqAznk6acLribq+n6uHy0gWC9z21N1Q== X-Gm-Message-State: AOJu0YxTDLzHL05+VV6O+alqBF8gWDfRQUZJNsjv7VuMleuY86s5FzeU bkdVUXpIHDruSMoxsI46EAVilDmWClWv2aDvmcs15TtVyIK9IOmxF9u6mmBxbw== X-Google-Smtp-Source: AGHT+IEWLEyA4X9iGW1nJeFH+7vpltiFlXGG1Pb1HOUF6XAwuJM+5rXzQLQVUU2jmlmWt0Ii+4+lpw== X-Received: by 2002:a17:902:dac2:b0:1dd:ba2c:c1c7 with SMTP id q2-20020a170902dac200b001ddba2cc1c7mr9986116plx.60.1711986675327; Mon, 01 Apr 2024 08:51:15 -0700 (PDT) Received: from [127.0.1.1] ([103.28.246.102]) by smtp.gmail.com with ESMTPSA id kh6-20020a170903064600b001e21957fecdsm8949076plb.246.2024.04.01.08.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 08:51:14 -0700 (PDT) From: Manivannan Sadhasivam Date: Mon, 01 Apr 2024 21:20:32 +0530 Subject: [PATCH v2 06/10] PCI: endpoint: Introduce EPC 'deinit' event and notify the EPF drivers Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-pci-epf-rework-v2-6-970dbe90b99d@linaro.org> References: <20240401-pci-epf-rework-v2-0-970dbe90b99d@linaro.org> In-Reply-To: <20240401-pci-epf-rework-v2-0-970dbe90b99d@linaro.org> To: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Kishon Vijay Abraham I , Thierry Reding , Jonathan Hunter , Jingoo Han Cc: linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, mhi@lists.linux.dev, linux-tegra@vger.kernel.org, Niklas Cassel , Manivannan Sadhasivam X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=8443; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=Vc/z3bg7iR0DVyjnmsrW91gdlaGDMMW4LWUaKvK6QqA=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmCtfVC2gNAc4d1W5XxVGJHcgt6DgfU0nRKF4Bk qfVCMA0LJiJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZgrX1QAKCRBVnxHm/pHO 9XNKB/4n42hVfJ6bcUVIaKI8YyqRrAp6g3FvHapE59XufDq96qaF11CwQrZwaXdPnPCUux9+PLi fp6wmp5Uw63mJSD85Hx5EsoQ1DyxwhygV2BIn4Q3ZFrqIO4xhhF7frh21LYKS9uHRj0pJSWACLD DCbK79DlZul9bLaxhtZYGZZBKGsPYZjkXPJMsbizyc9s8yIwbzsiD1f1mtCbh65DWz707syUIfy WfjOQN76wkSBCARWl4RuneKdg/8AUL2QnDGobGg8vJb3hOb4Z9HCGfg/2xidX25vJZEQRnpnfMe VXsCWAD2NwKmuCoWG9I53fDX5p3nn+idbjMLRhJ3Q4r/hj/W X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 As like the EPC 'init' event, that is used to signal the EPF drivers about the EPC initialization, let's introduce 'deinit' event that is used to signal EPC deinitialization. The EPC deinitialization applies only when any sort of fundamental reset is supported by the endpoint controller as per the PCIe spec. Reference: PCIe Base spec v5.0, sections 4.2.4.9.1 and 6.6.1. Currently, some EPC drivers like pcie-qcom-ep and pcie-tegra194 support PERST# as the fundamental reset. So the 'deinit' event will be notified to the EPF drivers when PERST# assert happens in the above mentioned EPC drivers. The EPF drivers, on receiving the event through the deinit() callback should reset the EPF state machine and also cleanup any configuration that got affected by the fundamental reset like BAR, DMA etc... This change also warrants skipping the cleanups in unbind() if already done in deinit(). Reviewed-by: Niklas Cassel Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-designware-ep.c | 1 - drivers/pci/controller/dwc/pcie-qcom-ep.c | 1 + drivers/pci/controller/dwc/pcie-tegra194.c | 1 + drivers/pci/endpoint/functions/pci-epf-mhi.c | 19 +++++++++++++++++++ drivers/pci/endpoint/functions/pci-epf-test.c | 17 +++++++++++++++-- drivers/pci/endpoint/pci-epc-core.c | 25 +++++++++++++++++++++++++ include/linux/pci-epc.h | 1 + include/linux/pci-epf.h | 2 ++ 8 files changed, 64 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index 47391d7d3a73..2063cf2049e5 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -632,7 +632,6 @@ void dw_pcie_ep_cleanup(struct dw_pcie_ep *ep) struct dw_pcie *pci = to_dw_pcie_from_ep(ep); dw_pcie_edma_remove(pci); - ep->epc->init_complete = false; } EXPORT_SYMBOL_GPL(dw_pcie_ep_cleanup); diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c index 50b1635e3cbb..e4b742355d57 100644 --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c @@ -501,6 +501,7 @@ static void qcom_pcie_perst_assert(struct dw_pcie *pci) { struct qcom_pcie_ep *pcie_ep = to_pcie_ep(pci); + pci_epc_deinit_notify(pci->ep.epc); dw_pcie_ep_cleanup(&pci->ep); qcom_pcie_disable_resources(pcie_ep); pcie_ep->link_status = QCOM_PCIE_EP_LINK_DISABLED; diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c index ddc23602eca7..d2223821e122 100644 --- a/drivers/pci/controller/dwc/pcie-tegra194.c +++ b/drivers/pci/controller/dwc/pcie-tegra194.c @@ -1715,6 +1715,7 @@ static void pex_ep_event_pex_rst_assert(struct tegra_pcie_dw *pcie) if (ret) dev_err(pcie->dev, "Failed to go Detect state: %d\n", ret); + pci_epc_deinit_notify(pcie->pci.ep.epc); dw_pcie_ep_cleanup(&pcie->pci.ep); reset_control_assert(pcie->core_rst); diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c index 4d5c638744a1..005916722ede 100644 --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c @@ -764,6 +764,24 @@ static int pci_epf_mhi_epc_init(struct pci_epf *epf) return 0; } +static void pci_epf_mhi_epc_deinit(struct pci_epf *epf) +{ + struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); + const struct pci_epf_mhi_ep_info *info = epf_mhi->info; + struct pci_epf_bar *epf_bar = &epf->bar[info->bar_num]; + struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl; + struct pci_epc *epc = epf->epc; + + if (mhi_cntrl->mhi_dev) { + mhi_ep_power_down(mhi_cntrl); + if (info->flags & MHI_EPF_USE_DMA) + pci_epf_mhi_dma_deinit(epf_mhi); + mhi_ep_unregister_controller(mhi_cntrl); + } + + pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar); +} + static int pci_epf_mhi_link_up(struct pci_epf *epf) { struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); @@ -898,6 +916,7 @@ static void pci_epf_mhi_unbind(struct pci_epf *epf) static const struct pci_epc_event_ops pci_epf_mhi_epc_event_ops = { .init = pci_epf_mhi_epc_init, + .deinit = pci_epf_mhi_epc_deinit, }; static const struct pci_epc_bus_event_ops pci_epf_mhi_bus_event_ops = { diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 8756ffc5977b..5933788b0e68 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -790,6 +790,15 @@ static int pci_epf_test_epc_init(struct pci_epf *epf) return 0; } +static void pci_epf_test_epc_deinit(struct pci_epf *epf) +{ + struct pci_epf_test *epf_test = epf_get_drvdata(epf); + + cancel_delayed_work(&epf_test->cmd_handler); + pci_epf_test_clean_dma_chan(epf_test); + pci_epf_test_clear_bar(epf); +} + static int pci_epf_test_link_up(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); @@ -802,6 +811,7 @@ static int pci_epf_test_link_up(struct pci_epf *epf) static const struct pci_epc_event_ops pci_epf_test_epc_event_ops = { .init = pci_epf_test_epc_init, + .deinit = pci_epf_test_epc_deinit, }; static const struct pci_epc_bus_event_ops pci_epf_test_bus_event_ops = { @@ -910,10 +920,13 @@ static int pci_epf_test_bind(struct pci_epf *epf) static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); + struct pci_epc *epc = epf->epc; cancel_delayed_work(&epf_test->cmd_handler); - pci_epf_test_clean_dma_chan(epf_test); - pci_epf_test_clear_bar(epf); + if (epc->init_complete) { + pci_epf_test_clean_dma_chan(epf_test); + pci_epf_test_clear_bar(epf); + } pci_epf_test_free_space(epf); } diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index fe3cb62dd866..05670c10371a 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -774,6 +774,31 @@ void pci_epc_notify_pending_init(struct pci_epc *epc, struct pci_epf *epf) } EXPORT_SYMBOL_GPL(pci_epc_notify_pending_init); +/** + * pci_epc_deinit_notify() - Notify the EPF device about EPC deinitialization + * @epc: the EPC device whose deinitialization is completed + * + * Invoke to notify the EPF device that the EPC deinitialization is completed. + */ +void pci_epc_deinit_notify(struct pci_epc *epc) +{ + struct pci_epf *epf; + + if (IS_ERR_OR_NULL(epc)) + return; + + mutex_lock(&epc->list_lock); + list_for_each_entry(epf, &epc->pci_epf, list) { + mutex_lock(&epf->lock); + if (epf->epc_event_ops && epf->epc_event_ops->deinit) + epf->epc_event_ops->deinit(epf); + mutex_unlock(&epf->lock); + } + epc->init_complete = false; + mutex_unlock(&epc->list_lock); +} +EXPORT_SYMBOL_GPL(pci_epc_deinit_notify); + /** * pci_epc_bme_notify() - Notify the EPF device that the EPC device has received * the BME event from the Root complex diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index acc5f96161fe..69dd7246c9db 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -226,6 +226,7 @@ void pci_epc_linkup(struct pci_epc *epc); void pci_epc_linkdown(struct pci_epc *epc); void pci_epc_init_notify(struct pci_epc *epc); void pci_epc_notify_pending_init(struct pci_epc *epc, struct pci_epf *epf); +void pci_epc_deinit_notify(struct pci_epc *epc); void pci_epc_bme_notify(struct pci_epc *epc); void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf, enum pci_epc_interface_type type); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index f4c2aaa6674c..74a0713661af 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -71,9 +71,11 @@ struct pci_epf_ops { /** * struct pci_epc_event_ops - Callbacks for capturing the EPC specific events * @init: Callback for the EPC initialization event + * @deinit: Callback for the EPC deinitialization event */ struct pci_epc_event_ops { int (*init)(struct pci_epf *epf); + void (*deinit)(struct pci_epf *epf); }; /**