From patchwork Wed Sep 30 04:50:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 2314285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gk5ij4uj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=linux-pci+bounces-68663-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hw2cp1Hz3z1xxW for ; Thu, 01 Oct 2026 03:50:02 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id F11C31426CC for ; Wed, 30 Sep 2026 14:51:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 073F437D11A; Wed, 30 Sep 2026 14:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gk5ij4uj" X-Original-To: linux-pci@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B1DE4AB3C0; Wed, 30 Sep 2026 14:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779851; cv=none; b=a3TMeubEbxeorFQMEJ6Sc3l5z5qPYnvd5sQZPmUID8ovUxq0v4aCG68DlyzU3DuQt4KDY7/CdAFHksiBJvSMH0MUcuSnHTC4LqdL9Mx8KnxtFuIlXVzlLULvByFaRyyGESOecOisqwJ93ooWh/JFw5uJdMytAndYVCk3m1+kzII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779851; c=relaxed/simple; bh=rlNDwOLzu7ttLsyeROV+rK+yucTFtmlzkPThqRA5V+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EJYCLGtXxbjbYU6tacZB0YzkkbFfbx2vOmSwYF/4Kgxyae1FKZzxdVms2TfaUh5C8ZV1eSU1ub8HgipeLRXQ6G0ptYkcw6YVdN90ty7y29vc+wj8C7SkiKoIeLEtll8hsQJ6qkXeCH8GuXByjzh3PxhhQIL1BtLXANJ+CwAwnIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gk5ij4uj; arc=none smtp.client-ip=100.103.45.18 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D02721F00898; Wed, 30 Sep 2026 14:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790779838; bh=pLddcdeVhe5dBvuz28Kf0fu3WIAs8MgosfUWOghTQPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gk5ij4ujsCezLMd8CRsnjZtyu6WtHMKifO3zWhhWbyCcuZb1xH6plVtyyKB5xEfU2 czjGmI+kF7/iR51RMqdllhlUhnl15DOWTHTg5d4d+ktjJD1R6iPiauNf0yNnfyfOuG nYzDjnWbEsc/vmy4DIHJWEIoHvNpW1POLHvx6Cmzr50A1HyIMCGMJac34fbjMxhdY0 B84UqzmA7lAfozDdGgoO3tFygGfbjQ2RDkAmgEd8xdKWIaUqOmQ/pbjQYhosj4Bd7Y xDAO46+5NuN9i0Kt3/SU7AQcMBSVbxga3GpYyDySZqEuH56JqX2xA4oj3YiXu0RFqw FCqcoX5bXRlKw== From: Niklas Cassel To: Bjorn Helgaas , Bjorn Helgaas , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Heiko Stuebner , Yue Wang , Hans Zhang <18255117159@163.com>, Manivannan Sadhasivam , Frank Li Cc: Keith Busch , mx2pg@pm.me, dlemoal@kernel.org, Niklas Cassel , Lukas Wunner , Mahesh Vaidya , Ricardo Pardini , Shawn Lin , =?utf-8?q?Pali_Roh=C3=A1r?= , Neil Armstrong , Rob Herring , Jingoo Han , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Myron Stowe , Jon Mason , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-rockchip@lists.infradead.org Subject: [RFC PATCH 1/4] PCI: Update saved Max Payload Size in pcie_set_mps() Date: Wed, 30 Sep 2026 16:50:18 +0200 Message-ID: <20260930145017.1356088-7-cassel@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930145017.1356088-6-cassel@kernel.org> References: <20260930145017.1356088-6-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2978; i=cassel@kernel.org; h=from:subject; bh=rlNDwOLzu7ttLsyeROV+rK+yucTFtmlzkPThqRA5V+Q=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGLL2Kq48tTfu/UbLknfnnk+PVxez+Tfn/E3Tlcd6TH1E4 rfH9W+f11HKwiDGxSArpsji+8Nlf3G3+5TjindsYOawMoEMYeDiFICJJHkyMtxY37952cWwRSpv ouRPL9nM/tK0IXbCyUbzI8Yc782TFwcwMuyf/ziqUM25YJvDnq1p32Rz16XOrq2WePze0yayadK hg5wA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA pcie_set_mps() changes the Max Payload Size (MPS) in the Device Control register but leaves the copy saved by pci_save_state() alone, so the next pci_restore_state() puts back the old value. The PCI core does change the MPS of devices whose state has already been saved: pci_configure_mps() reduces a Root Port's MPS when a device with a smaller MPS Supported is hot-added directly below it (commit 9f0e89359775 ("PCI: Match Root Port's MPS to endpoint's MPSS as necessary")), and with "pci=pcie_bus_safe", pcie_bus_configure_settings() can do the same when pciehp calls it after a hot-add. The Root Port's state was saved when it was added and again when portdrv probed it. Since commit 3fc686d550f6 ("PCI/ERR: Add support for resetting the Root Ports in a platform-specific way"), pcibios_reset_secondary_bus() restores that saved state, without saving it first, after host->reset_root_port() has reset the Root Port, e.g. during AER recovery or on Link Down with the qcom and Rockchip DWC drivers. The Root Port then goes back to the old, larger MPS while the device below it is restored to the smaller one, so the Root Port may send TLPs that the device treats as Malformed. Update the saved copy of Device Control when pcie_set_mps() changes the MPS, like commit 909f7bf9b080 ("PCI: Update saved_config_space upon resource assignment") does for BARs. Fixes: 3fc686d550f6 ("PCI/ERR: Add support for resetting the Root Ports in a platform-specific way") Assisted-by: LLM Signed-off-by: Niklas Cassel --- drivers/pci/pci.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b2879a6be5f8..5b126cd342ca 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1736,6 +1736,24 @@ static void pci_restore_pcie_state(struct pci_dev *dev) pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]); } +/* + * Update the saved copy of the Device Control register after changing it, so + * that pci_restore_state() doesn't put back a stale value. Device Control is + * the first register saved by pci_save_pcie_state(). + */ +static void pcie_update_saved_devctl(struct pci_dev *dev, u16 clear, u16 set) +{ + struct pci_cap_saved_state *save_state; + u16 *devctl; + + save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); + if (!save_state) + return; + + devctl = (u16 *)&save_state->cap.data[0]; + *devctl = (*devctl & ~clear) | set; +} + static int pci_save_pcix_state(struct pci_dev *dev) { int pos; @@ -5970,8 +5988,12 @@ int pcie_set_mps(struct pci_dev *dev, int mps) ret = pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_PAYLOAD, v); + if (ret) + return pcibios_err_to_errno(ret); - return pcibios_err_to_errno(ret); + pcie_update_saved_devctl(dev, PCI_EXP_DEVCTL_PAYLOAD, v); + + return 0; } EXPORT_SYMBOL(pcie_set_mps); From patchwork Wed Sep 30 04:50:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 2314261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UF03NQee; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org; envelope-from=linux-pci+bounces-68665-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from tor.lore.kernel.org (tor.lore.kernel.org [IPv6:2600:3c04:e001:36c::12fc:5321]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hw1X21Ycrz1xxW for ; Thu, 01 Oct 2026 03:00:50 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 235F9E8264 for ; Wed, 30 Sep 2026 14:52:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C1704F30C4; Wed, 30 Sep 2026 14:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UF03NQee" X-Original-To: linux-pci@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC0EF4E50B5; Wed, 30 Sep 2026 14:50:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779860; cv=none; b=SI3ahqzVjX8v12p5CSy2OtGXG9GPlGEJv3HuJuakL2P8cKhMsXJ9MJf+gObs7WsCovIwZOluvDjf3MTFYs8DCsj63CLnUdR5oblDfucbNBUuGdFKsq3smsdHdowuGwDSH5w5Mj6dvbVG43vyN9m8XQJYqJcDPLQW24hW1K/90as= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779860; c=relaxed/simple; bh=BCQEhMxc3THDAhwCFlhAfbew/cs4Pi8oaTza++3BWS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sisQJwF6n0H4wekgZGzzJVbxmexaqBgm1rIApeoleot211knOmMzXzshGwAjFSkhWx93taqAotwSCRDGyNeBwmN4qDDUBgCO5Ve49R6BxMFxtcREzDh53YHDaNyKuvkOHVAT/DW1MrQj43+ulPjefowQiSa3mXuujIHNP9RYkYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UF03NQee; arc=none smtp.client-ip=100.103.45.18 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D76D1F0089B; Wed, 30 Sep 2026 14:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790779845; bh=TSwgvDJ8bCkdzK3KRzsQi4XHuw+AgxkAx3ktEHZzz7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UF03NQeeQFakrobM0QKdTXcDNv/0m37rMtVFftS14c7N/Iz9vdXCdLy3k1wzBufA/ 4cwrlObdOz/8fAOCtop9P+R1hPV5Krr0NmQqrZtbReTPhGNQeXHV2hLRpZ9osCgT21 WfNDEAWsfA/nGinp0bmHQ7TZldMoAoj1b/xOT6u2Ziode0StIC5SbFj7Pd5tqzPglD 2//t26pkX5Pi8BZtjWwmNAviV1bR8bAQmKOwytLtKgj3tj/OD6ioRtBLw/ZM/LaPBe dbKg+AnOGhBTmFWoMifEeLSKpS1gAiN6iIiD/c9ZBhW81s56nMGc/gvzJtRgc/AOBx /9I6LCo0E/FVw== From: Niklas Cassel To: Bjorn Helgaas , Bjorn Helgaas , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Heiko Stuebner , Yue Wang , Hans Zhang <18255117159@163.com>, Myron Stowe , Jon Mason Cc: Keith Busch , mx2pg@pm.me, dlemoal@kernel.org, Lukas Wunner , Frank Li , Mahesh Vaidya , Ricardo Pardini , Shawn Lin , =?utf-8?q?Pali_Roh=C3=A1r?= , Neil Armstrong , Rob Herring , Jingoo Han , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-rockchip@lists.infradead.org, Niklas Cassel Subject: [RFC PATCH 2/4] PCI: Match the hierarchy's MPS to a device's MPSS as necessary Date: Wed, 30 Sep 2026 16:50:19 +0200 Message-ID: <20260930145017.1356088-8-cassel@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930145017.1356088-6-cassel@kernel.org> References: <20260930145017.1356088-6-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5641; i=cassel@kernel.org; h=from:subject; bh=BT88USuGeykL9B1sorUB9b03FNnb7Rs3jMpDLquVOTo=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGLL2Kq66Uhy8PPC02t7wDNP/+w0sozSl5rziN/lYU6n+Y a2upMy2jlIWBjEuBlkxRRbfHy77i7vdpxxXvGMDM4eVCWQIAxenAExkWSfD/5xLLDPfl0bL7rwR f/BnPOdDnhbh9Wz8VVuXX97o+tHLy4iR4X3kRDelhOb7+85veLHOQKWmvyJn0uabbAUchs9XWjG sYAcA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA From: Hans Zhang <18255117159@163.com> pci_configure_mps() enumerates top-down and programs each device's Maximum Payload Size (MPS) to match its upstream bridge. When a device's MPS Supported (MPSS) is too small to match, commit 9f0e89359775 ("PCI: Match Root Port's MPS to endpoint's MPSS as necessary") reduces the upstream bridge instead, but only when that bridge is a Root Port. That covers an endpoint directly below a Root Port and nothing else. With a Switch in between, the Switch ports have already inherited the Root Port's larger MPS, the reduction is skipped because the upstream bridge is a Switch Downstream Port, and pcie_set_mps() then fails with -EINVAL for the endpoint. The endpoint is left below a port programmed for a larger MPS, so any larger TLP it receives is treated as Malformed. Multi-function devices hit the same hole from the other direction: reducing the Root Port for a function with a small MPSS leaves the sibling functions already programmed to the larger value. Walk the hierarchy from the Root Port down and reduce every device that is above the new value. Reducing only the ports between the device and the Root Port is not sufficient, because a Switch does not split TLPs: an already programmed sibling left at the larger MPS could emit a TLP too large for its egress port. As a result, a single device with a small MPSS now lowers the MPS of every device below its Root Port. Only do this while no device below the Root Port has been added or made available for driver binding, i.e., during the initial scan, or when devices are hot-added or rescanned into an empty hierarchy such as a slot directly below the Root Port. Such devices may have drivers bound and DMA in flight, so their MPS can't be changed safely. This is the same constraint that makes PCIE_BUS_SAFE limit fabrics with hotplug bridges below a Root Port to 128 bytes in pcie_find_smpss(). A device added next to devices that are already in use is left at its current MPS and pci_configure_mps() warns and suggests "pci=pcie_bus_safe", which is what already happens below a Switch today. This only affects PCIE_BUS_DEFAULT. PCIE_BUS_SAFE, PCIE_BUS_PERFORMANCE and PCIE_BUS_PEER2PEER program MPS in pcie_bus_configure_settings() and PCIE_BUS_TUNE_OFF doesn't touch it, so all of them return before this point. Fixes: 9f0e89359775 ("PCI: Match Root Port's MPS to endpoint's MPSS as necessary") Signed-off-by: Hans Zhang <18255117159@163.com> Assisted-by: LLM Co-developed-by: Niklas Cassel Signed-off-by: Niklas Cassel --- drivers/pci/probe.c | 66 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 27008e2ea5af..d8e58e5ef730 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2200,9 +2200,49 @@ int pci_setup_device(struct pci_dev *dev) return 0; } +static int pcie_reduce_mps(struct pci_dev *dev, void *data) +{ + int mps = *(int *)data; + int ret; + + /* MPS is of type 'RsvdP' for VFs */ + if (!pci_is_pcie(dev) || dev->is_virtfn) + return 0; + + if (pcie_get_mps(dev) > mps) { + ret = pcie_set_mps(dev, mps); + if (ret) + pci_warn(dev, "can't set Max Payload Size to %d; if necessary, use \"pci=pcie_bus_safe\" and report a bug\n", + mps); + } + + return 0; +} + +static int pci_dev_check_in_use(struct pci_dev *dev, void *data) +{ + bool *in_use = data; + + *in_use = pci_dev_is_added(dev) || !pci_dev_binding_disallowed(dev); + return *in_use; +} + +/* + * Return true if any device on or below @bus has been added or made available + * for driver binding, i.e., may have a driver bound and DMA in flight. + */ +static bool pci_bus_in_use(struct pci_bus *bus) +{ + bool in_use = false; + + pci_walk_bus(bus, pci_dev_check_in_use, &in_use); + return in_use; +} + static void pci_configure_mps(struct pci_dev *dev) { struct pci_dev *bridge = pci_upstream_bridge(dev); + struct pci_dev *rp; int mps, mpss, p_mps, rc; if (!pci_is_pcie(dev)) @@ -2252,10 +2292,28 @@ static void pci_configure_mps(struct pci_dev *dev) return; mpss = 128 << dev->pcie_mpss; - if (mpss < p_mps && pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT) { - pcie_set_mps(bridge, mpss); - pci_info(dev, "Upstream bridge's Max Payload Size set to %d (was %d, max %d)\n", - mpss, p_mps, 128 << bridge->pcie_mpss); + rp = pcie_find_root_port(bridge); + if (mpss < p_mps && rp && !pci_bus_in_use(rp->subordinate)) { + /* + * dev cannot be programmed to the MPS already in use above + * it, so reduce the hierarchy to what dev supports. A Switch + * does not split TLPs, so reducing only the upstream bridge + * is not enough: every port up to the Root Port has to come + * down as well, and so do the devices already programmed + * below that Root Port, which would otherwise be left sending + * TLPs too large for their egress port. + * + * Only do this while no device below the Root Port has been + * added or made available for driver binding, e.g., during + * the initial scan or when hot-adding into a slot directly + * below the Root Port. Such devices may have drivers bound + * and DMA in flight, so their MPS can't be changed safely + * (see pcie_find_smpss()). + */ + pcie_reduce_mps(rp, &mpss); + pci_walk_bus(rp->subordinate, pcie_reduce_mps, &mpss); + pci_info(dev, "Max Payload Size of %s hierarchy set to %d (was %d)\n", + pci_name(rp), mpss, p_mps); p_mps = pcie_get_mps(bridge); } From patchwork Wed Sep 30 04:50:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 2314225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eoMGnAJA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org; envelope-from=linux-pci+bounces-68664-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from tor.lore.kernel.org (tor.lore.kernel.org [IPv6:2600:3c04:e001:36c::12fc:5321]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hw0mb22MVz1y0d for ; Thu, 01 Oct 2026 02:26:39 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id A246A1428DE for ; Wed, 30 Sep 2026 14:51:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FD854F85D1; Wed, 30 Sep 2026 14:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eoMGnAJA" X-Original-To: linux-pci@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5FB23BB100; Wed, 30 Sep 2026 14:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779856; cv=none; b=cjDnYysllBR8GMsTdvE63E3RJeBo6YP0ylLGprKNofthafAeenBlHXSXj/JZ2nUELSRSpl8Gc4qSYDD52SRCZEOENZHcd1mhDoGkJBdD1LyWEKMqkcETXZjx9GiVAANDgnjBtUm3zNk8exOjMASxq6pquU/dJVn2pZ+DywbFm8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779856; c=relaxed/simple; bh=HFUU72rF2I+ZOsd+sEY/LlyKiP4iGFfKJvkVITxGLEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qi9BajQ/cxPQ5hOvg6dG0lWjwCx9ZYOQ8+6+fJ0ZK6O0DMTVlkCWecRc2hw4JhQgqea6XRFw7Av6KxstBYTEkzKGclMoSRMQkEhb609ywCF5nqtJEKwFkUUSNSdXPqJXmVppEDrz4bJdzSCjVex7NKO6kr3oOq91v44EgbZ1Acg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eoMGnAJA; arc=none smtp.client-ip=100.103.45.18 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8E421F00893; Wed, 30 Sep 2026 14:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790779851; bh=P/YXD0eThUuuTt4F9igzSS8LTHnkxXyp0Ys+DH4Vt5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eoMGnAJAT7k9Q/W+puZ7sbOAekBcynoxY8SGLfp+BhlNyPGzwX6s0JQaPFILE5sr7 r/by7vIrFqNA1p+cFtZopIrD+1u5xzY9MXXd51xU2kIib6sYko/t5jbcSnUy59L7j3 A2Z5jsM6jaYc5znlSktL3bmHlMTsFtXiU1ySfb6FtwG9Le7engpqaLXWM5LTYbx3Ku ffI7rgzoYOYuSUGi6WXs6FRps1IKmewiM2YyLiw3K19WvS5u77vmHXcdN9WNuCxZ6g 7ly1YMud9kd6t7XMCipT9RwL9cUSjcmE/8rVnnbjI26G1GzOGeRE44dxrz9mNh6jN2 N6SxT7h/XGX2g== From: Niklas Cassel To: Bjorn Helgaas , Bjorn Helgaas , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Heiko Stuebner , Yue Wang , Hans Zhang <18255117159@163.com> Cc: Keith Busch , mx2pg@pm.me, dlemoal@kernel.org, Niklas Cassel , Lukas Wunner , Frank Li , Mahesh Vaidya , Ricardo Pardini , Shawn Lin , =?utf-8?q?Pali_Roh=C3=A1r?= , Neil Armstrong , Rob Herring , Jingoo Han , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Myron Stowe , Jon Mason , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-rockchip@lists.infradead.org Subject: [RFC PATCH 3/4] PCI: Configure Root Port MPS after scanning its hierarchy Date: Wed, 30 Sep 2026 16:50:20 +0200 Message-ID: <20260930145017.1356088-9-cassel@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930145017.1356088-6-cassel@kernel.org> References: <20260930145017.1356088-6-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6471; i=cassel@kernel.org; h=from:subject; bh=HFUU72rF2I+ZOsd+sEY/LlyKiP4iGFfKJvkVITxGLEE=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGLL2Kq7Klj2e7y+kwi75nvMij9gfJY6sXqtEyx6TR5H2/ QuO3LjVUcrCIMbFICumyOL7w2V/cbf7lOOKd2xg5rAygQxh4OIUgIkoFDL8D2Eqr3qUHNf9zz65 jfnz0Yx181VVjuzMctd/z5S54p9uIiND36wPTy8snVM5285ucqtwr1v84TWla9N1upfOZVpzcnM XCwA= X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA With the default MPS strategy (PCIE_BUS_DEFAULT), pci_configure_mps() only matches each device's Maximum Payload Size (MPS) to its upstream bridge. Root Ports have no upstream bridge, so their MPS stays at whatever firmware or the hardware default (128 bytes) left there, and the hierarchy below them inherits that value even if the Root Port and all devices below it support more. Once the hierarchy below a Root Port has been scanned, and before drivers are bound, raise the Root Port and every device below it to the largest MPS they all support. Do this from pcie_bus_configure_settings(), which the host bridge, ACPI and hotplug paths call after scanning, and from pci_rescan_bus() and pci_rescan_bus_bridge_resize(), which don't. Leave a hierarchy alone if it contains a hotplug bridge other than the Root Port, typically a Switch Downstream Port: a device hot-added below it later can't lower the MPS of a hierarchy in use, so keep the MPS the hierarchy already had. pcie_find_smpss() already returns the minimum MPS for such hierarchies, which never raises anything. Don't raise an empty slot directly below a Root Port either; it is evaluated when a device is hot-added or rescanned there, which also allows raising the Root Port again after a device that supported less has been replaced. Hierarchies with devices that may already have a driver bound are never changed. Since PCIE_BUS_DEFAULT can now raise MPS above what firmware programmed, apply the Intel 5000/5100 read completion coalescing quirk to it as well. The other strategies are unchanged: PCIE_BUS_TUNE_OFF doesn't touch MPS, and PCIE_BUS_SAFE, PCIE_BUS_PERFORMANCE and PCIE_BUS_PEER2PEER already configure the hierarchy in pcie_bus_configure_settings(). Suggested-by: Manivannan Sadhasivam Co-developed-by: Hans Zhang <18255117159@163.com> Signed-off-by: Hans Zhang <18255117159@163.com> Assisted-by: LLM Signed-off-by: Niklas Cassel --- drivers/pci/probe.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/quirks.c | 3 +- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index d8e58e5ef730..5f37b480b51d 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3083,6 +3083,82 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data) return 0; } +static int pcie_raise_mps(struct pci_dev *dev, void *data) +{ + int mps = *(int *)data; + + /* MPS is of type 'RsvdP' for VFs */ + if (!pci_is_pcie(dev) || dev->is_virtfn) + return 0; + + if (pcie_get_mps(dev) < mps && pcie_set_mps(dev, mps)) + pci_err(dev, "can't set Max Payload Size to %d\n", mps); + + return 0; +} + +/* + * With PCIE_BUS_DEFAULT, pci_configure_mps() only matches each device to its + * upstream bridge, so a hierarchy inherits whatever MPS firmware, or the + * hardware default of 128 bytes, left in its Root Port. Once the hierarchy + * below a Root Port has been enumerated, raise it to the largest MPS that all + * of its devices support. + * + * Leave hierarchies with a hotplug bridge other than the Root Port alone: a + * device hot-added below it can't lower the MPS once the hierarchy is in use. + * pcie_find_smpss() returns the minimum MPS for such hierarchies, which never + * raises anything. A hotplug slot directly below the Root Port is fine: it + * is evaluated when a device is hot-added there, and an empty slot is not + * raised, so a Switch hot-added into it doesn't inherit a raised MPS. Also + * leave hierarchies alone once any of their devices may have a driver bound. + */ +static void pcie_bus_raise_default_mps(struct pci_bus *bus) +{ + struct pci_dev *rp = bus->self; + u8 smpss = rp->pcie_mpss; + int mps, old_mps; + + if (pci_pcie_type(rp) != PCI_EXP_TYPE_ROOT_PORT || + list_empty(&bus->devices) || pci_bus_in_use(bus)) + return; + + pci_walk_bus(bus, pcie_find_smpss, &smpss); + mps = 128 << smpss; + old_mps = pcie_get_mps(rp); + if (mps <= old_mps) + return; + + pcie_raise_mps(rp, &mps); + pci_walk_bus(bus, pcie_raise_mps, &mps); + pci_info(rp, "Max Payload Size of hierarchy set to %d (was %d)\n", + mps, old_mps); +} + +/* + * A rescan doesn't go through pcie_bus_configure_settings(), so give the Root + * Port hierarchies it may have populated the same chance to be raised: every + * hierarchy below a rescanned root bus, or the one @bus belongs to. + */ +static void pcie_rescan_raise_default_mps(struct pci_bus *bus) +{ + struct pci_bus *child; + struct pci_dev *rp; + + if (pcie_bus_config != PCIE_BUS_DEFAULT) + return; + + if (pci_is_root_bus(bus)) { + list_for_each_entry(child, &bus->children, node) + if (child->self && pci_is_pcie(child->self)) + pcie_bus_raise_default_mps(child); + return; + } + + rp = pcie_find_root_port(bus->self); + if (rp && rp->subordinate) + pcie_bus_raise_default_mps(rp->subordinate); +} + /* * pcie_bus_configure_settings() requires that pci_walk_bus work in a top-down, * parents then children fashion. If this changes, then this code will not @@ -3098,6 +3174,11 @@ void pcie_bus_configure_settings(struct pci_bus *bus) if (!pci_is_pcie(bus->self)) return; + if (pcie_bus_config == PCIE_BUS_DEFAULT) { + pcie_bus_raise_default_mps(bus); + return; + } + /* * FIXME - Peer to peer DMA is possible, though the endpoint would need * to be aware of the MPS of the destination. To work around this, @@ -3536,6 +3617,7 @@ unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge) max = pci_scan_child_bus(bus); pci_assign_unassigned_bridge_resources(bridge); + pcie_rescan_raise_default_mps(bus); pci_bus_add_devices(bus); @@ -3557,6 +3639,7 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) max = pci_scan_child_bus(bus); pci_assign_unassigned_bus_resources(bus); + pcie_rescan_raise_default_mps(bus); pci_bus_add_devices(bus); return max; diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index de9bbccda21f..da171f4babe4 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3452,8 +3452,7 @@ static void quirk_intel_mc_errata(struct pci_dev *dev) int err; u16 rcc; - if (pcie_bus_config == PCIE_BUS_TUNE_OFF || - pcie_bus_config == PCIE_BUS_DEFAULT) + if (pcie_bus_config == PCIE_BUS_TUNE_OFF) return; /* From patchwork Wed Sep 30 04:50:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 2314273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=h/+yFH0U; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org; envelope-from=linux-pci+bounces-68666-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sin.lore.kernel.org (sin.lore.kernel.org [IPv6:2600:3c15:e001:75::12fc:5321]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hw2Pt5dYFz1y0d for ; Thu, 01 Oct 2026 03:40:34 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sin.lore.kernel.org (Postfix) with ESMTP id 405D73A8DB for ; Wed, 30 Sep 2026 14:52:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 786CD4FB9A0; Wed, 30 Sep 2026 14:51:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h/+yFH0U" X-Original-To: linux-pci@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43B9C4D9F8C; Wed, 30 Sep 2026 14:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779870; cv=none; b=gdpvggoD76ZRhmt43U63yq298jQlZkHUEuLX0t9Sm9SJvkA4hFenHq6oZqHvSF3xfP95nfnCUQlOb9fehZAs4iSFIPA/mT1k1qblA7SpoeQhATcTHGp6cBO2zx0q7Yd0AaazDPliFAL6gEMefDuDmVC3StrGM8y9f3klP2qfj5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790779870; c=relaxed/simple; bh=13hGlIWyD0SkOkt/WuOMZQuHfHRWflkIydT4dnHWJuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OSYmMJmiZyugFI1jDRphyK6q1pUrcm3yL90n+nRtQZdDAdzCeQDwp+17LoSaNRmuh0D14I79kVL17lGfCNU5IiZ04XygLgh/r2Lmuabydhe5P07gFvrr8RI8vTnNNKIGhJRSwjZJL6zUQQmNIY8zVqvFABKAecnZO3Bdzq0qX6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h/+yFH0U; arc=none smtp.client-ip=100.103.45.18 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4ED5B1F00899; Wed, 30 Sep 2026 14:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790779857; bh=UhAtJfHaHtYaOU+oIY0SPZU9mOxMhuThiOOTuvPUlOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=h/+yFH0UqJye/HKFYFIOIYanYzLGyduTYbHX9yle3VN6ug1cnA5uw/pt6/39uXw7F ZBx0lyGu4R6Ms0k/qOg+WLSPZbHdZUKjPJvA8fSyoHUEy4iA7L+fyAQadSiv5Np7NX 8A02kNR3Ul+KeOuAxTQTrsZJe5K50jYiptw8fojOgtya0bHQC+b3p6yEvCwFGlnG73 oFcN+prPmt6yIejEky6kPe3dF8fdiPDdr28Qir3U5+nx81ylZMzooSvSoLcqcCEqcc F2n1GIBhJVZDTOAaNETCvfsQhQf7ZdaEjY/fmW5pmpOXldPgewuJPe5ZXs0++59UA+ rCuBVAiuwoqzw== From: Niklas Cassel To: Bjorn Helgaas , Bjorn Helgaas , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Heiko Stuebner , Yue Wang , Hans Zhang <18255117159@163.com>, Rob Herring , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl Cc: Keith Busch , mx2pg@pm.me, dlemoal@kernel.org, Lukas Wunner , Frank Li , Mahesh Vaidya , Ricardo Pardini , Shawn Lin , =?utf-8?q?Pali_Roh=C3=A1r?= , Jingoo Han , Myron Stowe , Jon Mason , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-rockchip@lists.infradead.org, Niklas Cassel Subject: [RFC PATCH 4/4] PCI: meson: Remove redundant MPS configuration Date: Wed, 30 Sep 2026 16:50:21 +0200 Message-ID: <20260930145017.1356088-10-cassel@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930145017.1356088-6-cassel@kernel.org> References: <20260930145017.1356088-6-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3435; i=cassel@kernel.org; h=from:subject; bh=DlAMD3ZfDs7mvVlNQPCYHQnXtzUhkG7b37ikG/cbBaY=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGLL2Kq7+0f6vu3LZwbeNU9Y7Sc48Wbvj1RzJuc90lrzUE xD5ovXyW0cpC4MYF4OsmCKL7w+X/cXd7lOOK96xgZnDygQyhIGLUwAm0hDI8M8qgmO5voxt29dj PEH5F7Qb89tyhc2rhJXLnqyyT960Xorhv9OW+jjHWb+ZfrKtl1K6teLQN/12hQcvOz0OT4jM1+f lYgMA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA From: Hans Zhang <18255117159@163.com> The Meson PCIe controller driver manually configures maximum payload size (MPS) through meson_set_max_payload, duplicating functionality now centralized in the PCI core. Deprecating redundant code simplifies the driver and aligns it with the consolidated MPS management strategy, improving long-term maintainability. With meson_set_max_payload() gone, meson_size_to_payload() is only used for MRRS. Rename it to meson_size_to_mrrs(), update the warning message, and drop the now-unused PCIE_CAP_MAX_PAYLOAD_SIZE and MAX_PAYLOAD_SIZE macros. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Hans Zhang <18255117159@163.com> Signed-off-by: Niklas Cassel --- drivers/pci/controller/dwc/pci-meson.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c index 8559d132dcde..1d3687566dda 100644 --- a/drivers/pci/controller/dwc/pci-meson.c +++ b/drivers/pci/controller/dwc/pci-meson.c @@ -21,7 +21,6 @@ #define to_meson_pcie(x) dev_get_drvdata((x)->dev) -#define PCIE_CAP_MAX_PAYLOAD_SIZE(x) ((x) << 5) #define PCIE_CAP_MAX_READ_REQ_SIZE(x) ((x) << 12) /* PCIe specific config registers */ @@ -37,7 +36,6 @@ #define PM_CURRENT_STATE(x) (((x) >> 7) & 0x1) #define PORT_CLK_RATE 100000000UL -#define MAX_PAYLOAD_SIZE 256 #define MAX_READ_REQ_SIZE 256 #define PCIE_RESET_DELAY 500 #define PCIE_SHARED_RESET 1 @@ -256,7 +254,7 @@ static void meson_pcie_ltssm_enable(struct meson_pcie *mp) meson_cfg_writel(mp, val, PCIE_CFG0); } -static int meson_size_to_payload(struct meson_pcie *mp, int size) +static int meson_size_to_mrrs(struct meson_pcie *mp, int size) { struct device *dev = mp->pci.dev; @@ -266,35 +264,19 @@ static int meson_size_to_payload(struct meson_pcie *mp, int size) * than 2^12, just set to default size 2^(1+7). */ if (!is_power_of_2(size) || size < 128 || size > 4096) { - dev_warn(dev, "payload size %d, set to default 256\n", size); + dev_warn(dev, "MRRS %d, set to default 256\n", size); return 1; } return fls(size) - 8; } -static void meson_set_max_payload(struct meson_pcie *mp, int size) -{ - struct dw_pcie *pci = &mp->pci; - u32 val; - u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); - int max_payload_size = meson_size_to_payload(mp, size); - - val = dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL); - val &= ~PCI_EXP_DEVCTL_PAYLOAD; - dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val); - - val = dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL); - val |= PCIE_CAP_MAX_PAYLOAD_SIZE(max_payload_size); - dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val); -} - static void meson_set_max_rd_req_size(struct meson_pcie *mp, int size) { struct dw_pcie *pci = &mp->pci; u32 val; u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); - int max_rd_req_size = meson_size_to_payload(mp, size); + int max_rd_req_size = meson_size_to_mrrs(mp, size); val = dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL); val &= ~PCI_EXP_DEVCTL_READRQ; @@ -363,7 +345,6 @@ static int meson_pcie_host_init(struct dw_pcie_rp *pp) pp->bridge->ops = &meson_pci_ops; - meson_set_max_payload(mp, MAX_PAYLOAD_SIZE); meson_set_max_rd_req_size(mp, MAX_READ_REQ_SIZE); return 0;