Author: gonzo
Date: Sun Oct  9 04:29:42 2016
New Revision: 306897
URL: https://svnweb.freebsd.org/changeset/base/306897

Log:
  Fix MSI allocation for NVidia Tegra
  
  - Fix range check
  - Due to checking found value in for(;;) condition irq after loop was
      always + 1 from actually found slot and wrong entry was marked as
      used which lead to returning slot 0 for all requests.

Modified:
  head/sys/arm/nvidia/tegra_pcie.c

Modified: head/sys/arm/nvidia/tegra_pcie.c
==============================================================================
--- head/sys/arm/nvidia/tegra_pcie.c    Sun Oct  9 03:20:58 2016        
(r306896)
+++ head/sys/arm/nvidia/tegra_pcie.c    Sun Oct  9 04:29:42 2016        
(r306897)
@@ -710,7 +710,7 @@ tegra_pcib_msi_alloc_msi(device_t dev, d
        mtx_lock(&sc->mtx);
 
        found = false;
-       for (irq = 0; irq < TEGRA_PCIB_MAX_MSI && !found; irq++) {
+       for (irq = 0; (irq + count - 1) < TEGRA_PCIB_MAX_MSI; irq++) {
                /* Start on an aligned interrupt */
                if ((irq & (maxcount - 1)) != 0)
                        continue;
@@ -719,20 +719,17 @@ tegra_pcib_msi_alloc_msi(device_t dev, d
                found = true;
 
                /* Check this range is valid */
-               for (end_irq = irq; end_irq != irq + count - 1; end_irq++) {
-                       /* No free interrupts */
-                       if (end_irq == (TEGRA_PCIB_MAX_MSI - 1)) {
-                               found = false;
-                               break;
-                       }
-
+               for (end_irq = irq; end_irq < irq + count; end_irq++) {
                        /* This is already used */
-                       if ((sc->isrcs[irq].flags & TEGRA_FLAG_MSI_USED) ==
+                       if ((sc->isrcs[end_irq].flags & TEGRA_FLAG_MSI_USED) ==
                            TEGRA_FLAG_MSI_USED) {
                                found = false;
                                break;
                        }
                }
+
+               if (found)
+                       break;
        }
 
        /* Not enough interrupts were found */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to