linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] rcar-csi2: Update handling of transfer error
@ 2020-11-12 22:51 Niklas Söderlund
  2020-11-12 22:51 ` [PATCH 1/4] rcar-vin: Do not try to stop stream if not running Niklas Söderlund
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Niklas Söderlund @ 2020-11-12 22:51 UTC (permalink / raw)
  To: linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

Hello,

This series adapts the R-Car CSI-2 receiver recovery logic to match 
updates in the datasheet. The later datasheets recommend that the whole 
video pipeline shall be stopped if an transmission error is detected 
instead of just restarting the CSI-2 receiver.

To do this we leverage the recent changes to support suspend/resume of 
time the whole pipeline and inform the C-Car VIN driver of the detected 
error so it can stop the whole pipeline and inform user-space of the 
detected fault.

Patch 1/4 and 2/4 fixes faults in the VIN driver that where detected 
when working on this. Patch 3/4 prepares the VIN driver to deal with the 
EOS event from R-Car CSI-2 driver And patch 4/4 changes the error logic 
of the CSI-2 receiver to match the datasheet.

This is tested on M3-N and a fault is injected by quickly removing and 
re-inserting the HDMI cable while streaming. This method does not always 
hit and is time consuming. To consistently prove correctness of handling 
a fake fault was introduced by a HACK and a debugfs entry.

Niklas Söderlund (4):
  rcar-vin: Do not try to stop stream if not running
  rcar-vin: Route events to correct video device
  rcar-vin: Stop stream when subdevice signal EOS
  rcar-csi2: Do not try to recover after transfer error

 drivers/media/platform/rcar-vin/rcar-csi2.c | 14 +++--
 drivers/media/platform/rcar-vin/rcar-dma.c  |  5 ++
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 58 ++++++++++++++++++---
 3 files changed, 63 insertions(+), 14 deletions(-)

-- 
2.29.2


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

* [PATCH 1/4] rcar-vin: Do not try to stop stream if not running
  2020-11-12 22:51 [PATCH 0/4] rcar-csi2: Update handling of transfer error Niklas Söderlund
@ 2020-11-12 22:51 ` Niklas Söderlund
  2020-11-16 16:28   ` Jacopo Mondi
  2020-11-12 22:51 ` [PATCH 2/4] rcar-vin: Route events to correct video device Niklas Söderlund
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Niklas Söderlund @ 2020-11-12 22:51 UTC (permalink / raw)
  To: linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

Do not attempt to stop the streaming if the stream is not running.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
index 5a5f0e5007478c8d..eae25972ed7df2b6 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -1302,6 +1302,11 @@ void rvin_stop_streaming(struct rvin_dev *vin)
 
 	spin_lock_irqsave(&vin->qlock, flags);
 
+	if (vin->state == STOPPED) {
+		spin_unlock_irqrestore(&vin->qlock, flags);
+		return;
+	}
+
 	vin->state = STOPPING;
 
 	/* Wait until only scratch buffer is used, max 3 interrupts. */
-- 
2.29.2


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

* [PATCH 2/4] rcar-vin: Route events to correct video device
  2020-11-12 22:51 [PATCH 0/4] rcar-csi2: Update handling of transfer error Niklas Söderlund
  2020-11-12 22:51 ` [PATCH 1/4] rcar-vin: Do not try to stop stream if not running Niklas Söderlund
@ 2020-11-12 22:51 ` Niklas Söderlund
  2020-11-16 16:54   ` Jacopo Mondi
  2020-11-12 22:51 ` [PATCH 3/4] rcar-vin: Stop stream when subdevice signal EOS Niklas Söderlund
  2020-11-12 22:51 ` [PATCH 4/4] rcar-csi2: Do not try to recover after transfer error Niklas Söderlund
  3 siblings, 1 reply; 12+ messages in thread
From: Niklas Söderlund @ 2020-11-12 22:51 UTC (permalink / raw)
  To: linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

The event route for VIN running with a media controller (Gen3) is
incorrect as all events are only routed to the video device that are
used to register the async notifier.

Remedy this be examining which subdevice generated the event and route
it to all VIN(s) that are connected to that subdevice.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 44 ++++++++++++++++++---
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 3e7a3ae2a6b97045..dca3ab1656a66cef 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -966,18 +966,50 @@ void rvin_v4l2_unregister(struct rvin_dev *vin)
 	video_unregister_device(&vin->vdev);
 }
 
+static void rvin_notify_video_device(struct rvin_dev *vin,
+				     unsigned int notification, void *arg)
+{
+	switch (notification) {
+	case V4L2_DEVICE_NOTIFY_EVENT:
+		v4l2_event_queue(&vin->vdev, arg);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rvin_notify(struct v4l2_subdev *sd,
 			unsigned int notification, void *arg)
 {
+	struct v4l2_subdev *remote;
+	struct rvin_group *group;
+	struct media_pad *pad;
 	struct rvin_dev *vin =
 		container_of(sd->v4l2_dev, struct rvin_dev, v4l2_dev);
+	unsigned int i;
 
-	switch (notification) {
-	case V4L2_DEVICE_NOTIFY_EVENT:
-		v4l2_event_queue(&vin->vdev, arg);
-		break;
-	default:
-		break;
+	/* If no media controller, no need to route the event. */
+	if (!vin->info->use_mc) {
+		rvin_notify_video_device(vin, notification, arg);
+		return;
+	}
+
+	group = vin->group;
+
+	for (i = 0; i < RCAR_VIN_NUM; i++) {
+		vin = group->vin[i];
+		if (!vin)
+			continue;
+
+		pad = media_entity_remote_pad(&vin->pad);
+		if (!pad)
+			continue;
+
+		remote = media_entity_to_v4l2_subdev(pad->entity);
+		if (remote != sd)
+			continue;
+
+		rvin_notify_video_device(vin, notification, arg);
 	}
 }
 
-- 
2.29.2


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

* [PATCH 3/4] rcar-vin: Stop stream when subdevice signal EOS
  2020-11-12 22:51 [PATCH 0/4] rcar-csi2: Update handling of transfer error Niklas Söderlund
  2020-11-12 22:51 ` [PATCH 1/4] rcar-vin: Do not try to stop stream if not running Niklas Söderlund
  2020-11-12 22:51 ` [PATCH 2/4] rcar-vin: Route events to correct video device Niklas Söderlund
@ 2020-11-12 22:51 ` Niklas Söderlund
  2020-11-16 16:58   ` Jacopo Mondi
  2020-11-12 22:51 ` [PATCH 4/4] rcar-csi2: Do not try to recover after transfer error Niklas Söderlund
  3 siblings, 1 reply; 12+ messages in thread
From: Niklas Söderlund @ 2020-11-12 22:51 UTC (permalink / raw)
  To: linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

When a subdevice signals end of stream stop the VIN in addition to
informing user-space of the event.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index dca3ab1656a66cef..fcaf68c3428b80fd 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -969,9 +969,23 @@ void rvin_v4l2_unregister(struct rvin_dev *vin)
 static void rvin_notify_video_device(struct rvin_dev *vin,
 				     unsigned int notification, void *arg)
 {
+	const struct v4l2_event *event;
+
 	switch (notification) {
 	case V4L2_DEVICE_NOTIFY_EVENT:
-		v4l2_event_queue(&vin->vdev, arg);
+		event = arg;
+
+		switch (event->type) {
+		case V4L2_EVENT_EOS:
+			rvin_stop_streaming(vin);
+			v4l2_info(&vin->v4l2_dev,
+				  "Subdevice signaled end of stream, stopping.\n");
+			break;
+		default:
+			break;
+		}
+
+		v4l2_event_queue(&vin->vdev, event);
 		break;
 	default:
 		break;
-- 
2.29.2


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

* [PATCH 4/4] rcar-csi2: Do not try to recover after transfer error
  2020-11-12 22:51 [PATCH 0/4] rcar-csi2: Update handling of transfer error Niklas Söderlund
                   ` (2 preceding siblings ...)
  2020-11-12 22:51 ` [PATCH 3/4] rcar-vin: Stop stream when subdevice signal EOS Niklas Söderlund
@ 2020-11-12 22:51 ` Niklas Söderlund
  2020-11-16 17:09   ` Jacopo Mondi
  3 siblings, 1 reply; 12+ messages in thread
From: Niklas Söderlund @ 2020-11-12 22:51 UTC (permalink / raw)
  To: linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

Instead of restarting the R-Car CSI-2 receiver if a transmission error
is detected inform the R-Car VIN driver of the error so it can stop the
whole pipeline and inform user-space. This is done to reflect a updated
usage recommendation in later versions of the datasheet.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index 945d2eb8723367f0..a7212ecc46572a3b 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -773,21 +773,19 @@ static irqreturn_t rcsi2_irq(int irq, void *data)
 
 	rcsi2_write(priv, INTERRSTATE_REG, err_status);
 
-	dev_info(priv->dev, "Transfer error, restarting CSI-2 receiver\n");
-
 	return IRQ_WAKE_THREAD;
 }
 
 static irqreturn_t rcsi2_irq_thread(int irq, void *data)
 {
 	struct rcar_csi2 *priv = data;
+	struct v4l2_event event = {
+		.type = V4L2_EVENT_EOS,
+	};
 
-	mutex_lock(&priv->lock);
-	rcsi2_stop(priv);
-	usleep_range(1000, 2000);
-	if (rcsi2_start(priv))
-		dev_warn(priv->dev, "Failed to restart CSI-2 receiver\n");
-	mutex_unlock(&priv->lock);
+	dev_err(priv->dev, "Transfer error detected.\n");
+
+	v4l2_subdev_notify_event(&priv->subdev, &event);
 
 	return IRQ_HANDLED;
 }
-- 
2.29.2


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

* Re: [PATCH 1/4] rcar-vin: Do not try to stop stream if not running
  2020-11-12 22:51 ` [PATCH 1/4] rcar-vin: Do not try to stop stream if not running Niklas Söderlund
@ 2020-11-16 16:28   ` Jacopo Mondi
  2021-01-15  0:15     ` Niklas Söderlund
  0 siblings, 1 reply; 12+ messages in thread
From: Jacopo Mondi @ 2020-11-16 16:28 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc

Hi Niklas,

On Thu, Nov 12, 2020 at 11:51:44PM +0100, Niklas Söderlund wrote:
> Do not attempt to stop the streaming if the stream is not running.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
>  drivers/media/platform/rcar-vin/rcar-dma.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
> index 5a5f0e5007478c8d..eae25972ed7df2b6 100644
> --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> @@ -1302,6 +1302,11 @@ void rvin_stop_streaming(struct rvin_dev *vin)
>
>  	spin_lock_irqsave(&vin->qlock, flags);
>
> +	if (vin->state == STOPPED) {
> +		spin_unlock_irqrestore(&vin->qlock, flags);
> +		return;

Do I read it right that, in case a double stop is attempted, returning
here is not enough as the caller:

{
	rvin_stop_streaming(vin);

	/* Free scratch buffer. */
	dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch,
			  vin->scratch_phys);

	return_unused_buffers(vin, VB2_BUF_STATE_ERROR);
}

Are the potential double call to dma_free_coherent and the buffer
return procedure harmless ?

Thanks
   j

> +	}
> +
>  	vin->state = STOPPING;
>
>  	/* Wait until only scratch buffer is used, max 3 interrupts. */
> --
> 2.29.2
>

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

* Re: [PATCH 2/4] rcar-vin: Route events to correct video device
  2020-11-12 22:51 ` [PATCH 2/4] rcar-vin: Route events to correct video device Niklas Söderlund
@ 2020-11-16 16:54   ` Jacopo Mondi
  0 siblings, 0 replies; 12+ messages in thread
From: Jacopo Mondi @ 2020-11-16 16:54 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc

Hi Niklas,

On Thu, Nov 12, 2020 at 11:51:45PM +0100, Niklas Söderlund wrote:
> The event route for VIN running with a media controller (Gen3) is
> incorrect as all events are only routed to the video device that are
> used to register the async notifier.
>
> Remedy this be examining which subdevice generated the event and route
> it to all VIN(s) that are connected to that subdevice.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

This was easy to miss indeed!

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks
  j

> ---
>  drivers/media/platform/rcar-vin/rcar-v4l2.c | 44 ++++++++++++++++++---
>  1 file changed, 38 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index 3e7a3ae2a6b97045..dca3ab1656a66cef 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -966,18 +966,50 @@ void rvin_v4l2_unregister(struct rvin_dev *vin)
>  	video_unregister_device(&vin->vdev);
>  }
>
> +static void rvin_notify_video_device(struct rvin_dev *vin,
> +				     unsigned int notification, void *arg)
> +{
> +	switch (notification) {
> +	case V4L2_DEVICE_NOTIFY_EVENT:
> +		v4l2_event_queue(&vin->vdev, arg);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
>  static void rvin_notify(struct v4l2_subdev *sd,
>  			unsigned int notification, void *arg)
>  {
> +	struct v4l2_subdev *remote;
> +	struct rvin_group *group;
> +	struct media_pad *pad;
>  	struct rvin_dev *vin =
>  		container_of(sd->v4l2_dev, struct rvin_dev, v4l2_dev);
> +	unsigned int i;
>
> -	switch (notification) {
> -	case V4L2_DEVICE_NOTIFY_EVENT:
> -		v4l2_event_queue(&vin->vdev, arg);
> -		break;
> -	default:
> -		break;
> +	/* If no media controller, no need to route the event. */
> +	if (!vin->info->use_mc) {
> +		rvin_notify_video_device(vin, notification, arg);
> +		return;
> +	}
> +
> +	group = vin->group;
> +
> +	for (i = 0; i < RCAR_VIN_NUM; i++) {
> +		vin = group->vin[i];
> +		if (!vin)
> +			continue;
> +
> +		pad = media_entity_remote_pad(&vin->pad);
> +		if (!pad)
> +			continue;
> +
> +		remote = media_entity_to_v4l2_subdev(pad->entity);
> +		if (remote != sd)
> +			continue;
> +
> +		rvin_notify_video_device(vin, notification, arg);
>  	}
>  }
>
> --
> 2.29.2
>

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

* Re: [PATCH 3/4] rcar-vin: Stop stream when subdevice signal EOS
  2020-11-12 22:51 ` [PATCH 3/4] rcar-vin: Stop stream when subdevice signal EOS Niklas Söderlund
@ 2020-11-16 16:58   ` Jacopo Mondi
  2021-01-15  0:17     ` Niklas Söderlund
  0 siblings, 1 reply; 12+ messages in thread
From: Jacopo Mondi @ 2020-11-16 16:58 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc

Hi Niklas,

On Thu, Nov 12, 2020 at 11:51:46PM +0100, Niklas Söderlund wrote:
> When a subdevice signals end of stream stop the VIN in addition to
> informing user-space of the event.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
>  drivers/media/platform/rcar-vin/rcar-v4l2.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index dca3ab1656a66cef..fcaf68c3428b80fd 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -969,9 +969,23 @@ void rvin_v4l2_unregister(struct rvin_dev *vin)
>  static void rvin_notify_video_device(struct rvin_dev *vin,
>  				     unsigned int notification, void *arg)
>  {
> +	const struct v4l2_event *event;
> +

Can this go inside the switch ?

>  	switch (notification) {
>  	case V4L2_DEVICE_NOTIFY_EVENT:
> -		v4l2_event_queue(&vin->vdev, arg);
> +		event = arg;
> +
> +		switch (event->type) {
> +		case V4L2_EVENT_EOS:

As there's only a case where this happen, this could be an if, but I
see a switch is consistent with the existing one. Up to you.

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks
   j

> +			rvin_stop_streaming(vin);
> +			v4l2_info(&vin->v4l2_dev,
> +				  "Subdevice signaled end of stream, stopping.\n");
> +			break;
> +		default:
> +			break;
> +		}
> +
> +		v4l2_event_queue(&vin->vdev, event);
>  		break;
>  	default:
>  		break;
> --
> 2.29.2
>

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

* Re: [PATCH 4/4] rcar-csi2: Do not try to recover after transfer error
  2020-11-12 22:51 ` [PATCH 4/4] rcar-csi2: Do not try to recover after transfer error Niklas Söderlund
@ 2020-11-16 17:09   ` Jacopo Mondi
  2021-01-15  0:19     ` Niklas Söderlund
  0 siblings, 1 reply; 12+ messages in thread
From: Jacopo Mondi @ 2020-11-16 17:09 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc

Hi Niklas,

On Thu, Nov 12, 2020 at 11:51:47PM +0100, Niklas Söderlund wrote:
> Instead of restarting the R-Car CSI-2 receiver if a transmission error
> is detected inform the R-Car VIN driver of the error so it can stop the
> whole pipeline and inform user-space. This is done to reflect a updated
> usage recommendation in later versions of the datasheet.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
>  drivers/media/platform/rcar-vin/rcar-csi2.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index 945d2eb8723367f0..a7212ecc46572a3b 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -773,21 +773,19 @@ static irqreturn_t rcsi2_irq(int irq, void *data)
>
>  	rcsi2_write(priv, INTERRSTATE_REG, err_status);
>
> -	dev_info(priv->dev, "Transfer error, restarting CSI-2 receiver\n");
> -
>  	return IRQ_WAKE_THREAD;
>  }
>
>  static irqreturn_t rcsi2_irq_thread(int irq, void *data)
>  {
>  	struct rcar_csi2 *priv = data;
> +	struct v4l2_event event = {
> +		.type = V4L2_EVENT_EOS,
> +	};
>
> -	mutex_lock(&priv->lock);
> -	rcsi2_stop(priv);
> -	usleep_range(1000, 2000);
> -	if (rcsi2_start(priv))
> -		dev_warn(priv->dev, "Failed to restart CSI-2 receiver\n");
> -	mutex_unlock(&priv->lock);
> +	dev_err(priv->dev, "Transfer error detected.\n");
> +
> +	v4l2_subdev_notify_event(&priv->subdev, &event);

Is event handling synchronous with the notification ? I mean, now that
the sleep has gone, is this worth a threaded irq ?

Thanks
  j

>
>  	return IRQ_HANDLED;
>  }
> --
> 2.29.2
>

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

* Re: [PATCH 1/4] rcar-vin: Do not try to stop stream if not running
  2020-11-16 16:28   ` Jacopo Mondi
@ 2021-01-15  0:15     ` Niklas Söderlund
  0 siblings, 0 replies; 12+ messages in thread
From: Niklas Söderlund @ 2021-01-15  0:15 UTC (permalink / raw)
  To: Jacopo Mondi; +Cc: linux-media, linux-renesas-soc

Hi Jacopo,

Thanks for your feedback.

On 2020-11-16 17:28:38 +0100, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Thu, Nov 12, 2020 at 11:51:44PM +0100, Niklas Söderlund wrote:
> > Do not attempt to stop the streaming if the stream is not running.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > ---
> >  drivers/media/platform/rcar-vin/rcar-dma.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
> > index 5a5f0e5007478c8d..eae25972ed7df2b6 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> > @@ -1302,6 +1302,11 @@ void rvin_stop_streaming(struct rvin_dev *vin)
> >
> >  	spin_lock_irqsave(&vin->qlock, flags);
> >
> > +	if (vin->state == STOPPED) {
> > +		spin_unlock_irqrestore(&vin->qlock, flags);
> > +		return;
> 
> Do I read it right that, in case a double stop is attempted, returning
> here is not enough as the caller:
> 
> {
> 	rvin_stop_streaming(vin);
> 
> 	/* Free scratch buffer. */
> 	dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch,
> 			  vin->scratch_phys);
> 
> 	return_unused_buffers(vin, VB2_BUF_STATE_ERROR);
> }
> 
> Are the potential double call to dma_free_coherent and the buffer
> return procedure harmless ?

Yes.

> 
> Thanks
>    j
> 
> > +	}
> > +
> >  	vin->state = STOPPING;
> >
> >  	/* Wait until only scratch buffer is used, max 3 interrupts. */
> > --
> > 2.29.2
> >

-- 
Regards,
Niklas Söderlund

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

* Re: [PATCH 3/4] rcar-vin: Stop stream when subdevice signal EOS
  2020-11-16 16:58   ` Jacopo Mondi
@ 2021-01-15  0:17     ` Niklas Söderlund
  0 siblings, 0 replies; 12+ messages in thread
From: Niklas Söderlund @ 2021-01-15  0:17 UTC (permalink / raw)
  To: Jacopo Mondi; +Cc: linux-media, linux-renesas-soc

Hi Jacopo,

Thanks for your comments.

On 2020-11-16 17:58:14 +0100, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Thu, Nov 12, 2020 at 11:51:46PM +0100, Niklas Söderlund wrote:
> > When a subdevice signals end of stream stop the VIN in addition to
> > informing user-space of the event.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > ---
> >  drivers/media/platform/rcar-vin/rcar-v4l2.c | 16 +++++++++++++++-
> >  1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> > index dca3ab1656a66cef..fcaf68c3428b80fd 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> > @@ -969,9 +969,23 @@ void rvin_v4l2_unregister(struct rvin_dev *vin)
> >  static void rvin_notify_video_device(struct rvin_dev *vin,
> >  				     unsigned int notification, void *arg)
> >  {
> > +	const struct v4l2_event *event;
> > +
> 
> Can this go inside the switch ?

It could but I dislike creating 'case FOO: { }' blocks as I think they 
are hard to read and un C like ;-P

> 
> >  	switch (notification) {
> >  	case V4L2_DEVICE_NOTIFY_EVENT:
> > -		v4l2_event_queue(&vin->vdev, arg);
> > +		event = arg;
> > +
> > +		switch (event->type) {
> > +		case V4L2_EVENT_EOS:
> 
> As there's only a case where this happen, this could be an if, but I
> see a switch is consistent with the existing one. Up to you.

I been bitten by this in the past so now days I go straight for the 
switch() construct :-)

> 
> Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks!

> 
> Thanks
>    j
> 
> > +			rvin_stop_streaming(vin);
> > +			v4l2_info(&vin->v4l2_dev,
> > +				  "Subdevice signaled end of stream, stopping.\n");
> > +			break;
> > +		default:
> > +			break;
> > +		}
> > +
> > +		v4l2_event_queue(&vin->vdev, event);
> >  		break;
> >  	default:
> >  		break;
> > --
> > 2.29.2
> >

-- 
Regards,
Niklas Söderlund

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

* Re: [PATCH 4/4] rcar-csi2: Do not try to recover after transfer error
  2020-11-16 17:09   ` Jacopo Mondi
@ 2021-01-15  0:19     ` Niklas Söderlund
  0 siblings, 0 replies; 12+ messages in thread
From: Niklas Söderlund @ 2021-01-15  0:19 UTC (permalink / raw)
  To: Jacopo Mondi; +Cc: linux-media, linux-renesas-soc

Hi Jacopo,

Thanks for your feedback.

On 2020-11-16 18:09:32 +0100, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Thu, Nov 12, 2020 at 11:51:47PM +0100, Niklas Söderlund wrote:
> > Instead of restarting the R-Car CSI-2 receiver if a transmission error
> > is detected inform the R-Car VIN driver of the error so it can stop the
> > whole pipeline and inform user-space. This is done to reflect a updated
> > usage recommendation in later versions of the datasheet.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > ---
> >  drivers/media/platform/rcar-vin/rcar-csi2.c | 14 ++++++--------
> >  1 file changed, 6 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > index 945d2eb8723367f0..a7212ecc46572a3b 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > @@ -773,21 +773,19 @@ static irqreturn_t rcsi2_irq(int irq, void *data)
> >
> >  	rcsi2_write(priv, INTERRSTATE_REG, err_status);
> >
> > -	dev_info(priv->dev, "Transfer error, restarting CSI-2 receiver\n");
> > -
> >  	return IRQ_WAKE_THREAD;
> >  }
> >
> >  static irqreturn_t rcsi2_irq_thread(int irq, void *data)
> >  {
> >  	struct rcar_csi2 *priv = data;
> > +	struct v4l2_event event = {
> > +		.type = V4L2_EVENT_EOS,
> > +	};
> >
> > -	mutex_lock(&priv->lock);
> > -	rcsi2_stop(priv);
> > -	usleep_range(1000, 2000);
> > -	if (rcsi2_start(priv))
> > -		dev_warn(priv->dev, "Failed to restart CSI-2 receiver\n");
> > -	mutex_unlock(&priv->lock);
> > +	dev_err(priv->dev, "Transfer error detected.\n");
> > +
> > +	v4l2_subdev_notify_event(&priv->subdev, &event);
> 
> Is event handling synchronous with the notification ? I mean, now that
> the sleep has gone, is this worth a threaded irq ?

I had the same line of thought, as far as I can tell the "remote side" 
event handling is done in the callers context. So I definitely think a 
threaded irq model is needed here as we have no idea what the "remote 
side" in a different driver will do :-)

> 
> Thanks
>   j
> 
> >
> >  	return IRQ_HANDLED;
> >  }
> > --
> > 2.29.2
> >

-- 
Regards,
Niklas Söderlund

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

end of thread, other threads:[~2021-01-15  0:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 22:51 [PATCH 0/4] rcar-csi2: Update handling of transfer error Niklas Söderlund
2020-11-12 22:51 ` [PATCH 1/4] rcar-vin: Do not try to stop stream if not running Niklas Söderlund
2020-11-16 16:28   ` Jacopo Mondi
2021-01-15  0:15     ` Niklas Söderlund
2020-11-12 22:51 ` [PATCH 2/4] rcar-vin: Route events to correct video device Niklas Söderlund
2020-11-16 16:54   ` Jacopo Mondi
2020-11-12 22:51 ` [PATCH 3/4] rcar-vin: Stop stream when subdevice signal EOS Niklas Söderlund
2020-11-16 16:58   ` Jacopo Mondi
2021-01-15  0:17     ` Niklas Söderlund
2020-11-12 22:51 ` [PATCH 4/4] rcar-csi2: Do not try to recover after transfer error Niklas Söderlund
2020-11-16 17:09   ` Jacopo Mondi
2021-01-15  0:19     ` Niklas Söderlund

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).