From nobody Fri Jan 16 19:40:51 2026 X-Original-To: dev-commits-src-branches@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 4dt9FJ194Fz6NlZc for ; Fri, 16 Jan 2026 19:40:52 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dt9FH5QT0z3x51 for ; Fri, 16 Jan 2026 19:40:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768592451; 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=bqIxZnYq2+4DfPvJ29OoZCrH6AnFasV9waxjcuobHBc=; b=yaCTWGet2uqanwHBAwXw9uNIMaFe3QFXIrqv4hU19mHUEz9Uxt+UqkEKK1BANMASU/mFbG /gjIqNh0MkK61z5Dcwx9aLySTXNhgE8cfsiBxGjq7jAnHf0cXSTEq6fUazn2ETZIGtGTST GD56VtXucRiraWAdjEQXVxoMU1N/PhoiFadojJWhPYqY6TOssMsisFLzvQ9VpJfUkPn7YP vfPfsBQ5c+enqoBhJVO/4+HIfqZYkTPPl/S6pfPb5+gtIp6q1qNvnTKbA4fv/bnwIwV9ci V0dLA6F2hwhE1b3Q1n7UGPA8iqUxwO3V3YmZvQEq7frU9QpdUXIvTdqK2yJ9wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768592451; 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=bqIxZnYq2+4DfPvJ29OoZCrH6AnFasV9waxjcuobHBc=; b=YsFC7DuLxYQGTqV5CutQfiiP4lp4aMsQ7tfsJxWLwMlOmzX6IUl2dxe9WXGX50waeu9eB+ XLEeVXac4uZsDKU+DMztb1cJ8k+yTSvCReyfpj8ttheMRyp70yRlR1RK0YXzX2slii0Xxa 4Gw+m23UqsTEw9lT/R+EZc+fFkELIYQP+CT4AkXjwtKE88HEnpHeRcMdSf2dysI2uNRpru cKGCnw39mnzleBuzc77PFM22E8AZ217MDq9Xz+jGZLrTkYMdQ+cMCM8Y7AbjL+qxe5KnvQ IABFKLskP7O64GWrCUr/bJVuEXYJP+nxAfytCKs6xiQjBpERf9K533sXF8an5Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768592451; a=rsa-sha256; cv=none; b=f3l78wc8JC/8pPOhHvAoxTbWNMNfblx82cQS5GvjLyzSyCzd44xqPh+yd/fa2ZVNMd5xdf Srko5OliyMA9X4/oIzfguo8uwHztxmUqlDswFFaRSt9IZkHPWqhK25o+tqXZOiT4Ui7NAH sqbiC5x8pGNlvZIRnlaG91Eo+8eG23RSP0mMT9W2L4D+O/RLLXO322eMqg0YyU8upmy3/1 lOnSyREPciCT8n8qLisH8wt46+2D5rs8cF/vgzpBObYFxqFJe4e8L06ipQhJFFwhcuE5I3 iSRhGAeRs/XE5hN+dYs15P7YhZ+y2NcXj1eLsBI8643vt7ugirWCbcRKB45AKg== 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 4dt9FH4zj1zCVZ for ; Fri, 16 Jan 2026 19:40:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id da23 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 16 Jan 2026 19:40:51 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Bjoern A. Zeeb Subject: git: c017775775ee - stable/14 - LinuxKPI: pci: implement [linuxkpi_]pcim_request_all_regions() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c017775775ee7548a071806042b0294e94824991 Auto-Submitted: auto-generated Date: Fri, 16 Jan 2026 19:40:51 +0000 Message-Id: <696a9443.da23.3d8b3ba3@gitrepo.freebsd.org> The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=c017775775ee7548a071806042b0294e94824991 commit c017775775ee7548a071806042b0294e94824991 Author: Bjoern A. Zeeb AuthorDate: 2025-07-31 18:28:22 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-01-16 19:37:47 +0000 LinuxKPI: pci: implement [linuxkpi_]pcim_request_all_regions() Factor out the pci_request_region() implementation into an internal function and make pci_request_region() a simple wrapperaround it. Likewise implement pcim_request_all_regions() as a loop calling pci_request_region() for each entry. In two cases which we returned an error before (bar index is valid but bar is not (no len), and neither IO nor MEM) we now reutrn success (nothing to do for us). Otherwise callers, especially pcim_request_all_regions() would error out for the wrong reasons. This seems to also match the expected behaviour of pci_request_region(). Sponsored by: The FreeBSD Foundation (intially) Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D52068 LinuxKPI: pci: undo the pci_resource_len() check in lkpi_pci_request_region() Creating non-passthru SR-IOV interfaces on a mlx5en(4) failed. The problem lies in the pci_resource_len() call but not that the BAR length is tmeporary 0 but in that we call lkpi_pci_get_bar() with a true argument which will create the BAR resource for us and report the approriate length back. However, the later call to bus_alloc_resource_any() will then fail given the resource already exists. Restore the previous behaviour and let bus_alloc_resource_any() do the work. Adjust the return values from -ENODEV to -EBUSY to match callers expectations. In linuxkpi_pcim_request_all_regions(), like in linuxkpi_pci_request_regions(), filter out the -EBUSY errors as "not an error" and try the next bar. This also seems to be consistent with the expectations of the callers. PR: 290793 Reported by: David BOYER (jcduss13 gmail.com) Tested on: mlx5en, iwlwifi, mt7921 Reviewed by: kib Fixes: 7e21158d44cd "implement [linuxkpi_]pcim_request_all_regions()" Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D53902 (cherry picked from commit 7e21158d44cd46e720395604ca6f00f2fa36b20c) (cherry picked from commit ff31767e530abb4a54131af199fed6ec946a5fa4) (cherry picked from commit ed29ffd396e522a45ab1980c12a75b3409b51712) (cherry picked from commit 2032abb31cbe067d41067a81e529d91f1bace4c9) --- sys/compat/linuxkpi/common/include/linux/pci.h | 11 ++++-- sys/compat/linuxkpi/common/src/linux_pci.c | 52 +++++++++++++++++++++----- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index 20bd399b6170..c22a4403a823 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -347,7 +347,6 @@ struct pci_dev { spinlock_t pcie_cap_lock; }; -int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name); int pci_alloc_irq_vectors(struct pci_dev *pdev, int minv, int maxv, unsigned int flags); bool pci_device_is_present(struct pci_dev *pdev); @@ -361,7 +360,9 @@ void *linuxkpi_pcim_iomap(struct pci_dev *, int, unsigned long); void linuxkpi_pci_iounmap(struct pci_dev *pdev, void *res); int linuxkpi_pcim_iomap_regions(struct pci_dev *pdev, uint32_t mask, const char *name); +int linuxkpi_pci_request_region(struct pci_dev *, int, const char *); int linuxkpi_pci_request_regions(struct pci_dev *pdev, const char *res_name); +int linuxkpi_pcim_request_all_regions(struct pci_dev *, const char *); void linuxkpi_pci_release_region(struct pci_dev *pdev, int bar); void linuxkpi_pci_release_regions(struct pci_dev *pdev); int linuxkpi_pci_enable_msix(struct pci_dev *pdev, struct msix_entry *entries, @@ -541,12 +542,16 @@ done: return (pdev->bus->self); } +#define pci_request_region(pdev, bar, res_name) \ + linuxkpi_pci_request_region(pdev, bar, res_name) #define pci_release_region(pdev, bar) \ linuxkpi_pci_release_region(pdev, bar) -#define pci_release_regions(pdev) \ - linuxkpi_pci_release_regions(pdev) #define pci_request_regions(pdev, res_name) \ linuxkpi_pci_request_regions(pdev, res_name) +#define pci_release_regions(pdev) \ + linuxkpi_pci_release_regions(pdev) +#define pcim_request_all_regions(pdev, name) \ + linuxkpi_pcim_request_all_regions(pdev, name) static inline void lkpi_pci_disable_msix(struct pci_dev *pdev) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 0d8cfdeb576d..deea5df06c4a 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -1140,8 +1140,9 @@ pci_resource_len(struct pci_dev *pdev, int bar) return (rle->count); } -int -pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) +static int +lkpi_pci_request_region(struct pci_dev *pdev, int bar, const char *res_name, + bool managed) { struct resource *res; struct pci_devres *dr; @@ -1149,9 +1150,13 @@ pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) int rid; int type; + if (!lkpi_pci_bar_id_valid(bar)) + return (-EINVAL); + type = pci_resource_type(pdev, bar); if (type < 0) - return (-ENODEV); + return (0); + rid = PCIR_BAR(bar); res = bus_alloc_resource_any(pdev->dev.bsddev, type, &rid, RF_ACTIVE|RF_SHAREABLE); @@ -1159,16 +1164,21 @@ pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) device_printf(pdev->dev.bsddev, "%s: failed to alloc " "bar %d type %d rid %d\n", __func__, bar, type, PCIR_BAR(bar)); - return (-ENODEV); + return (-EBUSY); } /* * It seems there is an implicit devres tracking on these if the device - * is managed; otherwise the resources are not automatiaclly freed on - * FreeBSD/LinuxKPI tough they should be/are expected to be by Linux - * drivers. + * is managed (lkpi_pci_devres_find() case); otherwise the resources are + * not automatically freed on FreeBSD/LinuxKPI though they should be/are + * expected to be by Linux drivers. + * Otherwise if we are called from a pcim-function with the managed + * argument set, we need to track devres independent of pdev->managed. */ - dr = lkpi_pci_devres_find(pdev); + if (managed) + dr = lkpi_pci_devres_get_alloc(pdev); + else + dr = lkpi_pci_devres_find(pdev); if (dr != NULL) { dr->region_mask |= (1 << bar); dr->region_table[bar] = res; @@ -1184,6 +1194,12 @@ pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) return (0); } +int +linuxkpi_pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) +{ + return (lkpi_pci_request_region(pdev, bar, res_name, false)); +} + int linuxkpi_pci_request_regions(struct pci_dev *pdev, const char *res_name) { @@ -1192,7 +1208,25 @@ linuxkpi_pci_request_regions(struct pci_dev *pdev, const char *res_name) for (i = 0; i <= PCIR_MAX_BAR_0; i++) { error = pci_request_region(pdev, i, res_name); - if (error && error != -ENODEV) { + if (error && error != -EBUSY) { + pci_release_regions(pdev); + return (error); + } + } + return (0); +} + +int +linuxkpi_pcim_request_all_regions(struct pci_dev *pdev, const char *res_name) +{ + int bar, error; + + for (bar = 0; bar <= PCIR_MAX_BAR_0; bar++) { + error = lkpi_pci_request_region(pdev, bar, res_name, true); + if (error != 0 && error != -EBUSY) { + device_printf(pdev->dev.bsddev, "%s: bar %d res_name '%s': " + "lkpi_pci_request_region returned %d\n", __func__, + bar, res_name, error); pci_release_regions(pdev); return (error); }