[PATCH 25/67 v2] staging: comedi: pcl818: fix (*cancel) when cmd->stop_src == TRIG_NONE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When using DMA, the async command (*cancel) operation is delayed until the
current DMA transfer is complete. When the DMA transfer finishes the interrupt
routine detects this and calls the (*cancel) again which should then cancel the
async command.

The current logic does not work when cmd->stop_src == TRIG_NONE. In this case
the (*cancel) function keeps delaying the cancel. The actual DMA does stop
because the DMA handler is not called to setup the next transfer but the
(*cancel) code is never executed.

Rename the 'irq_was_now_closed' flag in the private data to 'ai_cmd_canceled'
to clarify what it is.

Only set the flag in the (*cancel) when a DMA transfer is running and the
async command has not already been canceled. The interrupt routine then does
not need all the extra checks.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/pcl818.c | 45 +++++++++++++++------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c
index c820df2..6c91a7b 100644
--- a/drivers/staging/comedi/drivers/pcl818.c
+++ b/drivers/staging/comedi/drivers/pcl818.c
@@ -332,7 +332,7 @@ struct pcl818_private {
 	unsigned int divisor2;
 	unsigned int usefifo:1;
 	unsigned int ai_cmd_running:1;
-	unsigned int irq_was_now_closed:1;
+	unsigned int ai_cmd_canceled:1;
 };
 
 static const unsigned int muxonechan[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,	/*  used for gain list programming */
@@ -731,29 +731,22 @@ static irqreturn_t interrupt_pcl818(int irq, void *d)
 	struct comedi_device *dev = d;
 	struct pcl818_private *devpriv = dev->private;
 	struct comedi_subdevice *s = dev->read_subdev;
-	struct comedi_cmd *cmd = &s->async->cmd;
 
 	if (!dev->attached) {
 		comedi_error(dev, "premature interrupt");
 		return IRQ_HANDLED;
 	}
 
-	if (devpriv->ai_cmd_running && devpriv->irq_was_now_closed) {
-		if ((cmd->stop_src == TRIG_NONE ||
-		    (cmd->stop_src == TRIG_COUNT && devpriv->ai_act_scan > 0)) &&
-		    (devpriv->ai_mode == INT_TYPE_AI1_DMA ||
-		     devpriv->ai_mode == INT_TYPE_AI3_DMA)) {
-			/* The cleanup from ai_cancel() has been delayed
-			   until now because the card doesn't seem to like
-			   being reprogrammed while a DMA transfer is in
-			   progress.
-			 */
-			devpriv->ai_act_scan = 0;
-			s->cancel(dev, s);
-		}
-
+	if (devpriv->ai_cmd_canceled) {
+		/*
+		 * The cleanup from ai_cancel() has been delayed
+		 * until now because the card doesn't seem to like
+		 * being reprogrammed while a DMA transfer is in
+		 * progress.
+		 */
+		devpriv->ai_act_scan = 0;
+		s->cancel(dev, s);
 		outb(0, dev->iobase + PCL818_CLRINT);	/* clear INT request */
-
 		return IRQ_HANDLED;
 	}
 
@@ -820,7 +813,7 @@ static int pcl818_ai_cmd_mode(int mode, struct comedi_device *dev,
 	devpriv->ai_act_scan = cmd->stop_arg;
 	devpriv->ai_act_chan = 0;
 	devpriv->ai_cmd_running = 1;
-	devpriv->irq_was_now_closed = 0;
+	devpriv->ai_cmd_canceled = 0;
 	devpriv->act_chanlist_pos = 0;
 	devpriv->dma_runs_to_end = 0;
 
@@ -1065,12 +1058,14 @@ static int pcl818_ai_cancel(struct comedi_device *dev,
 	case INT_TYPE_AI3_DMA:
 		if (cmd->stop_src == TRIG_NONE ||
 		    (cmd->stop_src == TRIG_COUNT && devpriv->ai_act_scan > 0)) {
-			/*
-			 * Wait for running dma transfer to end,
-			 * do cleanup in interrupt.
-			 */
-			devpriv->irq_was_now_closed = 1;
-			return 0;
+			if (!devpriv->ai_cmd_canceled) {
+				/*
+				* Wait for running dma transfer to end,
+				* do cleanup in interrupt.
+				*/
+				devpriv->ai_cmd_canceled = 1;
+				return 0;
+			}
 		}
 		disable_dma(devpriv->dma);
 	case INT_TYPE_AI1_INT:
@@ -1092,7 +1087,7 @@ static int pcl818_ai_cancel(struct comedi_device *dev,
 		}
 		devpriv->ai_cmd_running = 0;
 		devpriv->ai_mode = 0;
-		devpriv->irq_was_now_closed = 0;
+		devpriv->ai_cmd_canceled = 0;
 		break;
 	}
 
-- 
1.8.5.2

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux