All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [media] saa7164: use an MSI interrupt when available
@ 2015-02-26  3:19 Brendan McGrath
  2015-02-26 15:12 ` Steven Toth
  0 siblings, 1 reply; 14+ messages in thread
From: Brendan McGrath @ 2015-02-26  3:19 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Hans Verkuil, linux-media; +Cc: Brendan McGrath

From: Brendan McGrath <redmcg@redmandi.dyndns.org>

[media] saa7164: use an MSI interrupt when available

Fixes a known crash which most commonly occurs when multiple saa7164 
chips are in use.

Signed-off-by: Brendan McGrath <redmcg@redmandi.dyndns.org>
---
  drivers/media/pci/saa7164/saa7164-core.c | 34 
++++++++++++++++++++++++++++++--
  drivers/media/pci/saa7164/saa7164.h      |  1 +
  2 files changed, 33 insertions(+), 2 deletions(-)


This patch falls back to the original code - a 'shared' interrupt - when 
MSI is not available (or encounters an error).

Many of today's cards that use the saa7164 chip operate on a PCI-E bus 
(thus MSI should be available). Examples: the Hauppage HVR-2200 and HVR-2250

This enhancement also fixes an issue that was causing the driver to crash:
http://permalink.gmane.org/gmane.linux.drivers.video-input-infrastructure/83948

I believe the root cause of the crash is due to a DMA/IRQ race 
condition. It most commonly occurs when the saa7164 driver is dealing 
with more than one saa7164 chip (the HVR-2200 and HVR-2250 for example 
have two - one for each tuner). Given MSI avoids DMA/IRQ race conditions 
- this would explain why the patch works as a fix.




diff --git a/drivers/media/pci/saa7164/saa7164-core.c 
b/drivers/media/pci/saa7164/saa7164-core.c
index 4b0bec3..083bea4 100644
--- a/drivers/media/pci/saa7164/saa7164-core.c
+++ b/drivers/media/pci/saa7164/saa7164-core.c
@@ -1230,8 +1230,33 @@ static int saa7164_initdev(struct pci_dev *pci_dev,
          goto fail_irq;
      }

-    err = request_irq(pci_dev->irq, saa7164_irq,
-        IRQF_SHARED, dev->name, dev);
+    /* irq bit */
+    err = pci_enable_msi(pci_dev);
+
+    if (!err) {
+        /* no error - so request an msi interrupt */
+        err = request_irq(pci_dev->irq, saa7164_irq, 0,
+                  dev->name, dev);
+
+        if (err) {
+            /* fall back to legacy interrupt */
+            printk(KERN_ERR "%s() Failed to get an MSI interrupt."
+                " Falling back to a shared IRQ\n", __func__);
+            pci_disable_msi(pci_dev);
+        } else {
+            dev->msi = true;
+        }
+    }
+
+    if (err) {
+        dev->msi = false;
+        /* if we have an error (i.e. we don't have an interrupt)
+             - fallback to legacy interrupt */
+
+        err = request_irq(pci_dev->irq, saa7164_irq,
+                    IRQF_SHARED, dev->name, dev);
+    }
+
      if (err < 0) {
          printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
              pci_dev->irq);
@@ -1441,6 +1466,11 @@ static void saa7164_finidev(struct pci_dev *pci_dev)
      /* unregister stuff */
      free_irq(pci_dev->irq, dev);

+    if (dev->msi) {
+        pci_disable_msi(pci_dev);
+        dev->msi = false;
+    }
+
      mutex_lock(&devlist);
      list_del(&dev->devlist);
      mutex_unlock(&devlist);
diff --git a/drivers/media/pci/saa7164/saa7164.h 
b/drivers/media/pci/saa7164/saa7164.h
index cd1a07c..6df4b252 100644
--- a/drivers/media/pci/saa7164/saa7164.h
+++ b/drivers/media/pci/saa7164/saa7164.h
@@ -459,6 +459,7 @@ struct saa7164_dev {
      /* Interrupt status and ack registers */
      u32 int_status;
      u32 int_ack;
+    u32 msi;

      struct cmd            cmds[SAA_CMD_MAX_MSG_UNITS];
      struct mutex            lock;
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-06-05  5:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-26  3:19 [PATCH] [media] saa7164: use an MSI interrupt when available Brendan McGrath
2015-02-26 15:12 ` Steven Toth
2015-02-26 20:32   ` Kyle Sanderson
2015-02-26 20:45     ` Steven Toth
2015-02-26 23:06       ` Kyle Sanderson
2015-02-26 23:29   ` [PATCHv2] " Brendan McGrath
2015-02-27 16:01     ` Steven Toth
2015-03-01  0:14     ` [PATCHv3] " Brendan McGrath
2015-03-04  3:42       ` catchall
2015-03-14  3:27       ` [PATCHv4] " Brendan McGrath
2015-04-08 20:43         ` Mauro Carvalho Chehab
2015-04-10  6:39           ` [PATCHv5] " Brendan McGrath
2015-06-05  4:42             ` Kyle Sanderson
2015-06-05  5:09               ` Brendan McGrath

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.