From nobody Fri Aug 7 04:31:12 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hGWS61wM8z6nrc8 for ; Fri, 07 Aug 2026 04:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hGWS5629zz3Cfq for ; Fri, 07 Aug 2026 04:31:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786077077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FC3gD718646iZ6eZFvBZqSYU8OH1k1QadwKTGCsjXzY=; b=Zj9cdsTVNdGzfvsBxntLATOG24/686ssWarjnR3LbBquZsln7icTzT3T3F+XoqZbb2yiuD h7+onLv233ONVXgFBawYiQsblCT0OxSQOv3k6e03gfMA7ONBsP7FJBLR0pTtKubEuW7hGu uw8vY9G1eiVk9P5aMECzGZZFTEHersnwagft3OJokPekKlPPzvdptmPNHUcsSbvnNDo5qh r2jxTzpyPriPdWVPzvLX5pRs+Md+dm7rUoBvxCZkBDussov463e3nWiv1e0VJA2Zsa4JT6 ZMAyOdJdSMeEl+hRffflwueTqYG+PgqCvJ+0Nes4C1GI/yGWE/q/tkzfLvzVGw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786077077; a=rsa-sha256; cv=none; b=pHlH/JH5a0kjqFOfuWIw0AMnM92lLMB8D1JIXb9crC5EciLaxn/33cj2wbNAJFCQ7WMKhc 611Rlr6jAuB09NA631aBQDHpLn5qIWHUufBlhOpMZEQR/yDweO69Vj6/0qsa6muEF57r9x G1tE5wQVaEczvCX2IrsJ7wk7c6aLBxpCypF06uR8H8zX7zWgeOKd9mrUJi7cTyOYvvVWC0 qJ9pEpXOLId9cAqYMBij7maWF+OcMMQAVJnH908+cQV424nghwEZfjvBqyQWpDAySaGIcl OoP+yJ/y0Idim+K6RynouSllSLM1MBbIs1xKfU2zqtNTS4+qkTH6ohqZIv8FTw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786077077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FC3gD718646iZ6eZFvBZqSYU8OH1k1QadwKTGCsjXzY=; b=NFS65DT8heiAr2trkOEgH06CfmyUllu1iDCfO1ZbTxol7bZLWT7s8xLjuuZjlCsicMAfqY zWpoPbXvn7zrPzR5l6CovirebGZs3UL/NoRrQNqMGlJQNvEWXsdm6ZD8Cwe5L9xXlBdDRH MAJl1ZfwLFY0G2d9WSrjkU0TqkICbWDmBoGKMJuUncxTIsHF+bWfnUat43dMVZ+QrY2rda JcPraY1ORVEzAuXyPpM9xtQRRagOC/yJBkWj7JgRzr9tepQCdw5VngWkYy4b64OtC3+qKg Pu1aL5ztKIeaTd+8wkbb19EAwVjGmcPut1XbImsc++Ji8EeIVQz5gvzqLZ9QgQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hGWS554QkzsJq for ; Fri, 07 Aug 2026 04:31:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2698a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 07 Aug 2026 04:31:12 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kevin Bowling Subject: git: a9752e9ac8a6 - main - pci: Preserve adjusted PCIe control state List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a9752e9ac8a635f49ca058dd7268298840c7e915 Auto-Submitted: auto-generated Date: Fri, 07 Aug 2026 04:31:12 +0000 Message-Id: <6a755f90.2698a.4e64aa79@gitrepo.freebsd.org> The branch main has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=a9752e9ac8a635f49ca058dd7268298840c7e915 commit a9752e9ac8a635f49ca058dd7268298840c7e915 Author: Kevin Bowling AuthorDate: 2026-08-06 09:36:43 +0000 Commit: Kevin Bowling CommitDate: 2026-08-07 04:30:50 +0000 pci: Preserve adjusted PCIe control state The PCI bus changes live capability registers after the initial configuration snapshot has been saved. A later driver reprobe restores that snapshot and can silently undo the adjustment. Update the cached Device Control and Root Control bits together with pcie_adjust_config() writes. Route the persistent Maximum Read Request setter and the bus-owned AER control changes through that helper as well, so they share the same restore semantics as MPS reconciliation. Document the persistent-write contract. Merge only explicitly adjusted bits into the saved image so unrelated or transient bits observed during the hardware read-modify-write cannot become persistent. MFC after: 2 weeks --- share/man/man9/pci.9 | 11 ++++++++++- sys/dev/pci/pci.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/share/man/man9/pci.9 b/share/man/man9/pci.9 index 4d69d3a4240f..c94982f5f218 100644 --- a/share/man/man9/pci.9 +++ b/share/man/man9/pci.9 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd May 18, 2026 +.Dd August 6, 2026 .Dt PCI 9 .Os .Sh NAME @@ -253,6 +253,15 @@ to the value in Any bits not specified in .Fa mask are preserved. +For 16-bit accesses to +.Dv PCIER_DEVICE_CTL +or +.Dv PCIER_ROOT_CTL , +the corresponding bits in the saved PCI configuration state are also updated +so the adjustment persists across configuration restores. +Use +.Fn pcie_write_config +for transient changes that must not be saved. The previous value of the register is returned. .Pp The diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index b690c3412356..95b8e831e743 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -2312,10 +2312,9 @@ pci_set_max_read_req(device_t dev, int size) if (size > 4096) size = 4096; size = (1 << (fls(size) - 1)); - val = pci_read_config(dev, cap + PCIER_DEVICE_CTL, 2); - val &= ~PCIEM_CTL_MAX_READ_REQUEST; - val |= (fls(size) - 8) << 12; - pci_write_config(dev, cap + PCIER_DEVICE_CTL, val, 2); + val = (fls(size) - 8) << 12; + pcie_adjust_config(dev, PCIER_DEVICE_CTL, + PCIEM_CTL_MAX_READ_REQUEST, val, 2); return (size); } @@ -2359,6 +2358,7 @@ pcie_adjust_config(device_t dev, int reg, uint32_t mask, uint32_t value, int width) { struct pci_devinfo *dinfo = device_get_ivars(dev); + uint16_t *saved; uint32_t old, new; int cap; @@ -2373,6 +2373,22 @@ pcie_adjust_config(device_t dev, int reg, uint32_t mask, uint32_t value, new = old & ~mask; new |= (value & mask); pci_write_config(dev, cap + reg, new, width); + /* Apply only the requested policy bits to the saved restore image. */ + if (width == 2) { + saved = NULL; + switch (reg) { + case PCIER_DEVICE_CTL: + saved = &dinfo->cfg.pcie.pcie_device_ctl; + break; + case PCIER_ROOT_CTL: + saved = &dinfo->cfg.pcie.pcie_root_ctl; + break; + } + if (saved != NULL) { + *saved &= ~(uint16_t)mask; + *saved |= (uint16_t)(value & mask); + } + } return (old); } @@ -4461,16 +4477,12 @@ pci_add_child_clear_aer(device_t dev, struct pci_devinfo *dinfo) { int aer; uint32_t r; - uint16_t r2; if (dinfo->cfg.pcie.pcie_location != 0 && dinfo->cfg.pcie.pcie_type == PCIEM_TYPE_ROOT_PORT) { - r2 = pci_read_config(dev, dinfo->cfg.pcie.pcie_location + - PCIER_ROOT_CTL, 2); - r2 &= ~(PCIEM_ROOT_CTL_SERR_CORR | - PCIEM_ROOT_CTL_SERR_NONFATAL | PCIEM_ROOT_CTL_SERR_FATAL); - pci_write_config(dev, dinfo->cfg.pcie.pcie_location + - PCIER_ROOT_CTL, r2, 2); + r = PCIEM_ROOT_CTL_SERR_CORR | + PCIEM_ROOT_CTL_SERR_NONFATAL | PCIEM_ROOT_CTL_SERR_FATAL; + pcie_adjust_config(dev, PCIER_ROOT_CTL, r, 0, 2); } if (pci_find_extcap(dev, PCIZ_AER, &aer) == 0) { r = pci_read_config(dev, aer + PCIR_AER_UC_STATUS, 4); @@ -4522,12 +4534,9 @@ pci_add_child_clear_aer(device_t dev, struct pci_devinfo *dinfo) PCIM_AER_COR_HEADER_LOG_OVFLOW); pci_write_config(dev, aer + PCIR_AER_COR_MASK, r, 4); - r = pci_read_config(dev, dinfo->cfg.pcie.pcie_location + - PCIER_DEVICE_CTL, 2); - r |= PCIEM_CTL_COR_ENABLE | PCIEM_CTL_NFER_ENABLE | + r = PCIEM_CTL_COR_ENABLE | PCIEM_CTL_NFER_ENABLE | PCIEM_CTL_FER_ENABLE | PCIEM_CTL_URR_ENABLE; - pci_write_config(dev, dinfo->cfg.pcie.pcie_location + - PCIER_DEVICE_CTL, r, 2); + pcie_adjust_config(dev, PCIER_DEVICE_CTL, r, r, 2); } }