From nobody Sun Nov 15 08:19:05 2026 X-Original-To: dev-commits-src-all@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 4jS3mp2Js4z6yg4D for ; Sun, 15 Nov 2026 08:19:06 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jS3mp0Gvjz3Nrm for ; Sun, 15 Nov 2026 08:19:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794730746; 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=6OjGI09HNHKpct4dqSbmEI1AuKAwnCAzu1u7Iq1p614=; b=AfcNgCf/BZsyLxwcxF16u9A4S53mxDAM0NomKuTsp/Hw/niHYz6tHoqBm3pYavZLW4/gK3 bf71xmrjSA1xUEiph26IFZhnnnSfc00PSLq4/zem8hghVWzIuwQEA7Wgp4L5AaF/tsDgDg SvcjjBxGLzbjJO5GJIjCL1LZ2zA4NdSDOo9XVbJL8ytdmC4hCCTfpWwu+nFtHPKLQU0dvu q0BQhq+qx9HnyYz6fkbDmhGe0Ee+oxKQA7OCoJZ1axUmactP1fESqcqYgIqaSFVm1PrTrP JEnXGLFqIA0QyHzkS3oY75wIgUbrZhV1s467GjHeH384qp2i4gkJw4fFTfsjxA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794730746; b=OyhLaPCXoyRMXRwqdNIiTw846lXuulY3eCGu0DTl7U3yrwqpxl6ntLS0IyO4Xeoe7w0Sa6 RDx57rT1Enyz52EkyzoPTh44pi2iE4G3VvHvpdYyfht/vkAxyGeiuQTNEsLLSo7BA6DKd0 RIC8tHq6S5xb1Cd1Ejti1KwBFsw9oI2HZeTCQ/jtWz3MpsBtqRORcsxieZaNpI/TkwAuth XVlDvQnIjApXWyyopxOTFOzvmtsVyiCnBnyu9jGCS2t2ygRcVPBWECAY9DfCjlTNtF7zXT DZXrzyzcd0lM7IbAKccVfuaBJtBiuguZDCdDk1pTwvTVqy2mKUAgWE486c3CJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794730746; 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=6OjGI09HNHKpct4dqSbmEI1AuKAwnCAzu1u7Iq1p614=; b=l0RK+XVLM5F4YB73Kby0LA6176kJHmc6h6pw3sGhL+Lhzwl9N96eL2bE5ry78W0/3PJ55U 8PI5AIpsK0aRTYlidY1ZxioHGsYQl6mzo8Rps26rtu9LdofpSgiDiS8LKF2fsIAfdZGpQi kn3ApT19JhDVJVU+GE3l3aZIEpNOz1PHEjms98qfaknMkAlcVQVGyLFLTlEHgrSCvL3JsO j31yYz8cqATh9GGJuTs7RoyiwJupObY/ILhc9dwjSVJRG/ybJauOBKu61sNJx9EWYbIlKz 26/6tweDTqoPAsulSeXrTUJ9+MkPGbikQ3WwxJ8ASq+oSjrMTAIqkziJU/ONJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jS3mn73bQzy9L for ; Sun, 15 Nov 2026 08:19:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 10461 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 15 Nov 2026 08:19:05 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: e23c13a0c967 - main - pci_dw: Honor the max-link-speed property List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository 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: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e23c13a0c96772efe8fb3d1a88b219fb4ef189a2 Auto-Submitted: auto-generated Date: Sun, 15 Nov 2026 08:19:05 +0000 Message-Id: <6af96af9.10461.4f2b09fa@gitrepo.freebsd.org> The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=e23c13a0c96772efe8fb3d1a88b219fb4ef189a2 commit e23c13a0c96772efe8fb3d1a88b219fb4ef189a2 Author: Emmanuel Vadot AuthorDate: 2026-10-27 07:24:57 +0000 Commit: Emmanuel Vadot CommitDate: 2026-11-15 08:18:46 +0000 pci_dw: Honor the max-link-speed property The root port reports in LNKCAP the highest link speed the core was synthesized for, which can be more than the PHY behind it supports. On the RK3568 pcie2x1 the root port advertises 8GT/s while the PHY only does 5GT/s. The link stays at 2.5GT/s after the directed speed change. Read max-link-speed from the device tree and write it to the Max Link Speed field of LNKCAP and to the Target Link Speed field of LNKCTL2 before requesting the speed change. Nothing changes when the property is absent. Tested on a Quartz64 Model A with a Samsung 970 EVO Plus NVMe drive: the link now trains at 5GT/s and the sequential throughput goes from 200MB/s to 400MB/s. Differential Revision: https://reviews.freebsd.org/D61014 --- sys/dev/pci/pci_dw.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/dev/pci/pci_dw.h | 1 + 2 files changed, 55 insertions(+) diff --git a/sys/dev/pci/pci_dw.c b/sys/dev/pci/pci_dw.c index 7c9448a5593e..2ca1fc60c5b1 100644 --- a/sys/dev/pci/pci_dw.c +++ b/sys/dev/pci/pci_dw.c @@ -324,6 +324,52 @@ pci_dw_map_out_atu(struct pci_dw_softc *sc, int idx, int type, pci_addr, size)); } +#define DW_LINK_CTL2_TARGET_SPEED 0x000f + +static void +pci_dw_set_max_link_speed(struct pci_dw_softc *sc) +{ + uint32_t reg; + uint16_t ctl2; + u_int cap, ptr, n; + + if (sc->max_link_speed == 0) + return; + if (sc->max_link_speed > 4) { + device_printf(sc->dev, + "'max-link-speed' property have invalid value: %u\n", + sc->max_link_speed); + return; + } + + /* Find the PCI Express capability of the root port. */ + cap = 0; + ptr = DBI_RD1(sc, PCIR_CAP_PTR) & ~3; + for (n = 0; ptr != 0 && n < 48; n++) { + if (DBI_RD1(sc, ptr + PCICAP_ID) == PCIY_EXPRESS) { + cap = ptr; + break; + } + ptr = DBI_RD1(sc, ptr + PCICAP_NEXTPTR) & ~3; + } + if (cap == 0) { + device_printf(sc->dev, + "Cannot find the PCI Express capability\n"); + return; + } + + pci_dw_dbi_protect(sc, false); + reg = DBI_RD4(sc, cap + PCIER_LINK_CAP); + reg &= ~PCIEM_LINK_CAP_MAX_SPEED; + reg |= sc->max_link_speed; + DBI_WR4(sc, cap + PCIER_LINK_CAP, reg); + ctl2 = DBI_RD2(sc, cap + PCIER_LINK_CTL2); + ctl2 &= ~DW_LINK_CTL2_TARGET_SPEED; + ctl2 |= sc->max_link_speed; + DBI_WR2(sc, cap + PCIER_LINK_CTL2, ctl2); + pci_dw_dbi_protect(sc, true); +} + static int pci_dw_setup_hw(struct pci_dw_softc *sc) { @@ -421,6 +467,8 @@ pci_dw_setup_hw(struct pci_dw_softc *sc) } DBI_WR4(sc, DW_GEN2_CTRL, reg); + pci_dw_set_max_link_speed(sc); + reg = DBI_RD4(sc, DW_GEN2_CTRL); reg |= DIRECT_SPEED_CHANGE; DBI_WR4(sc, DW_GEN2_CTRL, reg); @@ -762,6 +810,12 @@ pci_dw_init(device_t dev) sc->num_lanes = 1; dprintf("%s: num lanes: %d\n", __func__, sc->num_lanes); + rv = OF_getencprop(sc->node, "max-link-speed", &sc->max_link_speed, + sizeof(sc->max_link_speed)); + if (rv != sizeof(sc->max_link_speed)) + sc->max_link_speed = 0; + dprintf("%s: max link speed: %u\n", __func__, sc->max_link_speed); + if (sc->num_lanes != 1 && sc->num_lanes != 2 && sc->num_lanes != 4 && sc->num_lanes != 8) { device_printf(dev, diff --git a/sys/dev/pci/pci_dw.h b/sys/dev/pci/pci_dw.h index 5b6f62ad6c84..15a7e705ac9e 100644 --- a/sys/dev/pci/pci_dw.h +++ b/sys/dev/pci/pci_dw.h @@ -116,6 +116,7 @@ struct pci_dw_softc { bus_dma_tag_t dmat; int num_lanes; + u_int max_link_speed; int num_out_regions; struct resource *iatu_ur_res; /* NB: May be dbi_res */ bus_addr_t iatu_ur_offset;