git: 8d76cbe16b42 - stable/14 - LinuxKPI: pci: implementation of [lkpi_]pci_get_slot()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Fri, 16 Jan 2026 19:41:07 UTC
The branch stable/14 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=8d76cbe16b42749336cf369fbba850bfb30e5cd6

commit 8d76cbe16b42749336cf369fbba850bfb30e5cd6
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-04 20:19:48 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-01-16 19:37:50 +0000

    LinuxKPI: pci: implementation of [lkpi_]pci_get_slot()
    
    Like lkpi_pci_get_domain_bus_and_slot() implement lkpi_pci_get_slot()
    using pci_find_bsf() instead of pci_find_dbsf() (no domain).
    This is needed for a wireless driver.
    
    Unfortunately the name [pci_get_slot()] collides with the native PCI
    function.  Add a guard around it and disable the use when the native
    version is required (in lkpifill_pci_dev() and in bnxt/bnxt_en; if the
    latter gets fixed we can probably also fix work around it in the former;
    further conflicts in drm-kmod 6.1-lts, 6.6-lts, and master were resolved).
    
    Sponsored by:   The FreeBSD Foundation (initially)
    Reviewed by:    dumbbell
    Differential Revision:  https://reviews.freebsd.org/D52065
    
    (cherry picked from commit 4179e6b78297369f0cf0eae1076e01e5151c5cbe)
    (cherry picked from commit 62c3b77d1d1084dc46663eed52e288307b5c7e64)
---
 sys/compat/linuxkpi/common/include/linux/pci.h |  6 ++++++
 sys/compat/linuxkpi/common/src/linux_pci.c     | 15 +++++++++++++++
 sys/dev/bnxt/bnxt_en/if_bnxt.c                 |  1 +
 3 files changed, 22 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index c22a4403a823..da0a713dbee8 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -1311,6 +1311,12 @@ struct pci_dev *lkpi_pci_get_domain_bus_and_slot(int domain,
 #define	pci_get_domain_bus_and_slot(domain, bus, devfn)	\
 	lkpi_pci_get_domain_bus_and_slot(domain, bus, devfn)
 
+struct pci_dev *lkpi_pci_get_slot(struct pci_bus *, unsigned int);
+#ifndef	WANT_NATIVE_PCI_GET_SLOT
+#define	pci_get_slot(_pbus, _devfn)				\
+    lkpi_pci_get_slot(_pbus, _devfn)
+#endif
+
 static inline int
 pci_domain_nr(struct pci_bus *pbus)
 {
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index 1e6278418c83..4745e0416067 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -68,6 +68,7 @@
 #include <linux/mm.h>
 #include <linux/io.h>
 #include <linux/vmalloc.h>
+#define	WANT_NATIVE_PCI_GET_SLOT
 #include <linux/pci.h>
 #include <linux/compat.h>
 
@@ -468,6 +469,20 @@ lkpi_pci_get_domain_bus_and_slot(int domain, unsigned int bus,
 	return (pdev);
 }
 
+struct pci_dev *
+lkpi_pci_get_slot(struct pci_bus *pbus, unsigned int devfn)
+{
+	device_t dev;
+	struct pci_dev *pdev;
+
+	dev = pci_find_bsf(pbus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
+	if (dev == NULL)
+		return (NULL);
+
+	pdev = lkpinew_pci_dev(dev);
+	return (pdev);
+}
+
 static int
 linux_pci_probe(device_t dev)
 {
diff --git a/sys/dev/bnxt/bnxt_en/if_bnxt.c b/sys/dev/bnxt/bnxt_en/if_bnxt.c
index 169255c9433e..a8c353e1c406 100644
--- a/sys/dev/bnxt/bnxt_en/if_bnxt.c
+++ b/sys/dev/bnxt/bnxt_en/if_bnxt.c
@@ -49,6 +49,7 @@
 #include <net/ethernet.h>
 #include <net/iflib.h>
 
+#define	WANT_NATIVE_PCI_GET_SLOT
 #include <linux/pci.h>
 #include <linux/kmod.h>
 #include <linux/module.h>