git: e86707418c8e - main - LinuxKPI: PCI: add counter for linux_dma_map_phys_common() errors

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 03 Apr 2022 23:07:05 UTC
The branch main has been updated by bz:

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

commit e86707418c8e84e1ebf8b4c5f35ff641c234d067
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-03-30 17:38:23 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-04-03 23:05:47 +0000

    LinuxKPI: PCI: add counter for linux_dma_map_phys_common() errors
    
    LinuxKPI is asking for single-segment mappings.  Some (wireless) drivers
    are using this to map multi-pages and our busdma framework is not very
    friendly to that as single-segments [D31823].  Add a counter so we can
    track when this happens to gather more information.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    hselasky
    MFC after:      3 days
    Differential Revision: https://reviews.freebsd.org/D34715
---
 sys/compat/linuxkpi/common/src/linux_pci.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index f8ae03d2bf28..34bac3843378 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/pci/pci_iov.h>
 #include <dev/backlight/backlight.h>
 
+#include <linux/kernel.h>
 #include <linux/kobject.h>
 #include <linux/device.h>
 #include <linux/slab.h>
@@ -77,6 +78,14 @@ __FBSDID("$FreeBSD$");
 /* Undef the linux function macro defined in linux/pci.h */
 #undef pci_get_class
 
+extern int linuxkpi_debug;
+
+SYSCTL_DECL(_compat_linuxkpi);
+
+static counter_u64_t lkpi_pci_nseg1_fail;
+SYSCTL_COUNTER_U64(_compat_linuxkpi, OID_AUTO, lkpi_pci_nseg1_fail, CTLFLAG_RD,
+    &lkpi_pci_nseg1_fail, "Count of busdma mapping failures of single-segment");
+
 static device_probe_t linux_pci_probe;
 static device_attach_t linux_pci_attach;
 static device_detach_t linux_pci_detach;
@@ -796,7 +805,7 @@ linux_dma_init(void *arg)
 	linux_dma_obj_zone = uma_zcreate("linux_dma_object",
 	    sizeof(struct linux_dma_obj), NULL, NULL, NULL, NULL,
 	    UMA_ALIGN_PTR, 0);
-
+	lkpi_pci_nseg1_fail = counter_u64_alloc(M_WAITOK);
 }
 SYSINIT(linux_dma, SI_SUB_DRIVERS, SI_ORDER_THIRD, linux_dma_init, NULL);
 
@@ -804,6 +813,7 @@ static void
 linux_dma_uninit(void *arg)
 {
 
+	counter_u64_free(lkpi_pci_nseg1_fail);
 	uma_zdestroy(linux_dma_obj_zone);
 	uma_zdestroy(linux_dma_trie_zone);
 }
@@ -866,6 +876,9 @@ linux_dma_map_phys_common(struct device *dev, vm_paddr_t phys, size_t len,
 		bus_dmamap_destroy(obj->dmat, obj->dmamap);
 		DMA_PRIV_UNLOCK(priv);
 		uma_zfree(linux_dma_obj_zone, obj);
+		counter_u64_add(lkpi_pci_nseg1_fail, 1);
+		if (linuxkpi_debug)
+			dump_stack();
 		return (0);
 	}