[PATCH v9 16/19] media: ti: j721e-csi2rx: Return the partial frame as error

Rishikesh Donadkar posted 19 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v9 16/19] media: ti: j721e-csi2rx: Return the partial frame as error
Posted by Rishikesh Donadkar 1 month, 1 week ago
After draining, when a buffer is queued to the driver, ti will fill out
the buffer with a partial frame as some part of the frame is drained.
Return the partial frame with VB2_BUF_STATE_ERROR.

Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
---
 drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
index e713293696eb1..3922bd67e78da 100644
--- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
+++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
@@ -83,6 +83,7 @@ struct ti_csi2rx_buffer {
 enum ti_csi2rx_dma_state {
 	TI_CSI2RX_DMA_STOPPED,	/* Streaming not started yet. */
 	TI_CSI2RX_DMA_ACTIVE,	/* Streaming and pending DMA operation. */
+	TI_CSI2RX_DMA_DRAINING, /* Dumping all the data in drain buffer */
 };
 
 struct ti_csi2rx_dma {
@@ -728,12 +729,20 @@ static void ti_csi2rx_dma_callback(void *param)
 	spin_lock_irqsave(&dma->lock, flags);
 
 	WARN_ON(!list_is_first(&buf->list, &dma->submitted));
-	vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
+
+	if (dma->state == TI_CSI2RX_DMA_DRAINING) {
+		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
+		dma->state = TI_CSI2RX_DMA_ACTIVE;
+	} else {
+		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
+	}
+
 	list_del(&buf->list);
 
 	ti_csi2rx_dma_submit_pending(ctx);
 
 	if (list_empty(&dma->submitted)) {
+		dma->state = TI_CSI2RX_DMA_DRAINING;
 		if (ti_csi2rx_drain_dma(ctx))
 			dev_warn(ctx->csi->dev,
 				 "DMA drain failed on one of the transactions\n");
-- 
2.34.1
Re: [PATCH v9 16/19] media: ti: j721e-csi2rx: Return the partial frame as error
Posted by Tomi Valkeinen 3 weeks, 4 days ago
Hi,

On 30/12/2025 10:32, Rishikesh Donadkar wrote:
> After draining, when a buffer is queued to the driver, ti will fill out

s/ti/it/

> the buffer with a partial frame as some part of the frame is drained.
> Return the partial frame with VB2_BUF_STATE_ERROR.

Makes sense, if we have to return a partial frame. It would be nicer to
be able to skip that frame altogether (draining it fully).

In any case, as Jai said, please squash.

 Tomi

> Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
> ---
>  drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
> index e713293696eb1..3922bd67e78da 100644
> --- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
> +++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
> @@ -83,6 +83,7 @@ struct ti_csi2rx_buffer {
>  enum ti_csi2rx_dma_state {
>  	TI_CSI2RX_DMA_STOPPED,	/* Streaming not started yet. */
>  	TI_CSI2RX_DMA_ACTIVE,	/* Streaming and pending DMA operation. */
> +	TI_CSI2RX_DMA_DRAINING, /* Dumping all the data in drain buffer */
>  };
>  
>  struct ti_csi2rx_dma {
> @@ -728,12 +729,20 @@ static void ti_csi2rx_dma_callback(void *param)
>  	spin_lock_irqsave(&dma->lock, flags);
>  
>  	WARN_ON(!list_is_first(&buf->list, &dma->submitted));
> -	vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
> +
> +	if (dma->state == TI_CSI2RX_DMA_DRAINING) {
> +		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
> +		dma->state = TI_CSI2RX_DMA_ACTIVE;
> +	} else {
> +		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
> +	}
> +
>  	list_del(&buf->list);
>  
>  	ti_csi2rx_dma_submit_pending(ctx);
>  
>  	if (list_empty(&dma->submitted)) {
> +		dma->state = TI_CSI2RX_DMA_DRAINING;
>  		if (ti_csi2rx_drain_dma(ctx))
>  			dev_warn(ctx->csi->dev,
>  				 "DMA drain failed on one of the transactions\n");
Re: [PATCH v9 16/19] media: ti: j721e-csi2rx: Return the partial frame as error
Posted by Jai Luthra 1 month ago
Hi Rishikesh,

Quoting Rishikesh Donadkar (2025-12-30 14:02:17)
> After draining, when a buffer is queued to the driver, ti will fill out
> the buffer with a partial frame as some part of the frame is drained.
> Return the partial frame with VB2_BUF_STATE_ERROR.

This should be squashed with the previous patch which changes the drain
architecture and leads to the partial frames. So for the combined patch:

Reviewed-by: Jai Luthra <jai.luthra@ideasonboard.com>

> 
> Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
> ---
>  drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
> index e713293696eb1..3922bd67e78da 100644
> --- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
> +++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
> @@ -83,6 +83,7 @@ struct ti_csi2rx_buffer {
>  enum ti_csi2rx_dma_state {
>         TI_CSI2RX_DMA_STOPPED,  /* Streaming not started yet. */
>         TI_CSI2RX_DMA_ACTIVE,   /* Streaming and pending DMA operation. */
> +       TI_CSI2RX_DMA_DRAINING, /* Dumping all the data in drain buffer */
>  };
>  
>  struct ti_csi2rx_dma {
> @@ -728,12 +729,20 @@ static void ti_csi2rx_dma_callback(void *param)
>         spin_lock_irqsave(&dma->lock, flags);
>  
>         WARN_ON(!list_is_first(&buf->list, &dma->submitted));
> -       vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
> +
> +       if (dma->state == TI_CSI2RX_DMA_DRAINING) {
> +               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
> +               dma->state = TI_CSI2RX_DMA_ACTIVE;
> +       } else {
> +               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
> +       }
> +
>         list_del(&buf->list);
>  
>         ti_csi2rx_dma_submit_pending(ctx);
>  
>         if (list_empty(&dma->submitted)) {
> +               dma->state = TI_CSI2RX_DMA_DRAINING;
>                 if (ti_csi2rx_drain_dma(ctx))
>                         dev_warn(ctx->csi->dev,
>                                  "DMA drain failed on one of the transactions\n");
> -- 
> 2.34.1
> 
>
Re: [PATCH v9 16/19] media: ti: j721e-csi2rx: Return the partial frame as error
Posted by Rishikesh Donadkar 1 month ago
On 06/01/26 16:45, Jai Luthra wrote:
> Hi Rishikesh,

Hi Jai,

Thanks !

>
> Quoting Rishikesh Donadkar (2025-12-30 14:02:17)
>> After draining, when a buffer is queued to the driver, ti will fill out
>> the buffer with a partial frame as some part of the frame is drained.
>> Return the partial frame with VB2_BUF_STATE_ERROR.
> This should be squashed with the previous patch which changes the drain
> architecture and leads to the partial frames. So for the combined patch:

Will do.


Regards,

Rishikesh

>
> Reviewed-by: Jai Luthra <jai.luthra@ideasonboard.com>
>
>> Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
>> ---
>>   drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 11 ++++++++++-
>>   1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
>> index e713293696eb1..3922bd67e78da 100644
>> --- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
>> +++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
>> @@ -83,6 +83,7 @@ struct ti_csi2rx_buffer {
>>   enum ti_csi2rx_dma_state {
>>          TI_CSI2RX_DMA_STOPPED,  /* Streaming not started yet. */
>>          TI_CSI2RX_DMA_ACTIVE,   /* Streaming and pending DMA operation. */
>> +       TI_CSI2RX_DMA_DRAINING, /* Dumping all the data in drain buffer */
>>   };
>>   
>>   struct ti_csi2rx_dma {
>> @@ -728,12 +729,20 @@ static void ti_csi2rx_dma_callback(void *param)
>>          spin_lock_irqsave(&dma->lock, flags);
>>   
>>          WARN_ON(!list_is_first(&buf->list, &dma->submitted));
>> -       vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
>> +
>> +       if (dma->state == TI_CSI2RX_DMA_DRAINING) {
>> +               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
>> +               dma->state = TI_CSI2RX_DMA_ACTIVE;
>> +       } else {
>> +               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
>> +       }
>> +
>>          list_del(&buf->list);
>>   
>>          ti_csi2rx_dma_submit_pending(ctx);
>>   
>>          if (list_empty(&dma->submitted)) {
>> +               dma->state = TI_CSI2RX_DMA_DRAINING;
>>                  if (ti_csi2rx_drain_dma(ctx))
>>                          dev_warn(ctx->csi->dev,
>>                                   "DMA drain failed on one of the transactions\n");
>> -- 
>> 2.34.1
>>
>>