Skip to contentSkip to conversation

media: verisilicon: Fix VDPU2 decoder error handling

PATCH New Arun Iyengar 1 participant 3 messages Nov 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover media: verisilicon: Fix VDPU2 decoder error handling

The VDPU2 decoder reports failed decodes as done, and after an error its interrupt handler can finish a job while the decoder may still be active.

Tested on Orange Pi 5 (RK3588S), v7.3-based KASAN kernel:
5 bus errors and 5 timeouts, simulated by a test-only patch that injects the status bits, each reset once and ended the job; buffer-empty kept the job, output bit-exact; 186 resets in error-stream stress, no watchdog; VP8 61/61 and H.264 conformance unchanged. Build-tested on media next. MPEG-2, RK3399 and RK3568 untested.

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Changes in v4:
- Patch 2: soft-reset the decoder after a bus, stream or ASO error
or a timeout, before finishing the job (Nicolas)
- Rebased on media next
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Patch 2: read DEC_E before clearing the status, as G2 does (Sashiko)
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Patch 2: no reset after an error; handle the interrupt like the G2 handler instead (Nicolas)
- Link to v1: https://patch.msgid.link/[email protected]

---
Arun Iyengar (2):
media: verisilicon: Don't report VDPU2 decoder errors as success
media: verisilicon: Reset the VDPU2 decoder after an error

 .../platform/verisilicon/rockchip_vpu2_regs.h      |  4 +++
 .../media/platform/verisilicon/rockchip_vpu_hw.c   | 42 +++++++++++++++++++---
 2 files changed, 41 insertions(+), 5 deletions(-)

---
base-commit: b4e3c4b6a36fd76f57bf3e48638f68ddecc54ba4
change-id: 20261115-vdpu2-errreset-8688700393a3

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw

PATCH v4 1/2 media: verisilicon: Don't report VDPU2 decoder errors as success

The VDPU2 interrupt handler completes the job as done whenever the decoder raised an interrupt. DEC_IRQ is set for every interrupt, including timeouts, bus errors and stream errors, so failed decodes are returned to userspace as valid frames.

Check the picture ready bit instead, as the G1 handler does.

Fixes 879dee56a40c ("media: rockchip/vpu: Add MPEG2 decoding support to RK3399")
---
 drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +1 -1
index 02673be9878e..4bc1bdb41c70 100644
@@ -391,7 +391,7 @@ static irqreturn_t rockchip_vpu2_vdpu_irq(int irq, void *dev_id)
 	u32 status;
 
 	status = vdpu_read(vpu, VDPU_REG_INTERRUPT);
-	state = (status & VDPU_REG_INTERRUPT_DEC_IRQ) ?
+	state = (status & VDPU_REG_INTERRUPT_DEC_RDY_INT) ?
 		VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
 
 	vdpu_write(vpu, 0, VDPU_REG_INTERRUPT);
Signature · 1 line
2.55.0
#2 lore raw

PATCH v4 2/2 media: verisilicon: Reset the VDPU2 decoder after an error

In reply to Arun Iyengar

Ignore interrupts the decoder did not raise and report the error type.

After a bus, stream or ASO error or a timeout, soft-reset the decoder before its buffers go back to userspace: it may still be active. If only its input buffer ran empty, the decoder stays enabled; a later interrupt or the driver's watchdog then ends the job.

---
 .../platform/verisilicon/rockchip_vpu2_regs.h      |  4 +++
 .../media/platform/verisilicon/rockchip_vpu_hw.c   | 40 +++++++++++++++++++---
 2 files changed, 40 insertions(+), 4 deletions(-)
drivers/media/platform/verisilicon/rockchip_vpu2_regs.h +4 -0
index 49e40889545b..d11c84a18161 100644
@@ -347,6 +347,10 @@
 #define     VDPU_REG_INTERRUPT_DEC_RDY_INT		BIT(4)
 #define     VDPU_REG_INTERRUPT_DEC_IRQ_DIS		BIT(1)
 #define     VDPU_REG_INTERRUPT_DEC_IRQ			BIT(0)
+#define     VDPU_REG_INTERRUPT_DEC_ERRORS		(VDPU_REG_INTERRUPT_DEC_TIMEOUT | \
+						 VDPU_REG_INTERRUPT_DEC_ERROR_INT | \
+						 VDPU_REG_INTERRUPT_DEC_ASO_INT | \
+						 VDPU_REG_INTERRUPT_DEC_BUS_INT)
 #define VDPU_REG_AXI_CTRL			0x0e0
 #define     VDPU_REG_AXI_DEC_SEL			BIT(23)
 #define     VDPU_REG_CONFIG_DEC_DATA_DISC_E		BIT(22)
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +36 -4
index 4bc1bdb41c70..69552195c974 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/iopoll.h>
 
 #include "hantro.h"
 #include "hantro_jpeg.h"
@@ -384,17 +385,49 @@ static irqreturn_t rockchip_vpu1_vepu_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static void rockchip_vpu2_dec_soft_reset(struct hantro_dev *vpu)
+{
+	u32 val;
+
+	vdpu_write(vpu, 0, VDPU_REG_EN_FLAGS);
+	vdpu_write(vpu, 1, VDPU_REG_SOFT_RESET);
+	if (read_poll_timeout_atomic(vdpu_read, val, !val, 0, 5, false, vpu,
+				     VDPU_REG_SOFT_RESET))
+		dev_warn_ratelimited(vpu->dev, "decoder soft reset timed out\n");
+}
+
 static irqreturn_t rockchip_vpu2_vdpu_irq(int irq, void *dev_id)
 {
 	struct hantro_dev *vpu = dev_id;
 	enum vb2_buffer_state state;
-	u32 status;
+	u32 status, en;
 
 	status = vdpu_read(vpu, VDPU_REG_INTERRUPT);
+	if (!(status & VDPU_REG_INTERRUPT_DEC_IRQ))
+		return IRQ_NONE;
+
+	/* Read DEC_E with the status, before the clear. */
+	en = vdpu_read(vpu, VDPU_REG_EN_FLAGS);
+	vdpu_write(vpu, 0, VDPU_REG_INTERRUPT);
+
 	state = (status & VDPU_REG_INTERRUPT_DEC_RDY_INT) ?
 		VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+	if (state == VB2_BUF_STATE_ERROR) {
+		if (status & VDPU_REG_INTERRUPT_DEC_BUS_INT)
+			dev_warn_ratelimited(vpu->dev, "bus error detected.\n");
+		if (status & VDPU_REG_INTERRUPT_DEC_ERROR_INT)
+			dev_warn_ratelimited(vpu->dev, "decode error detected.\n");
+		if (status & VDPU_REG_INTERRUPT_DEC_TIMEOUT)
+			dev_warn_ratelimited(vpu->dev, "frame decode timed out.\n");
+
+		/* Buffer empty: a later interrupt or the watchdog ends the job. */
+		if (!(status & VDPU_REG_INTERRUPT_DEC_ERRORS) &&
+		    (en & VDPU_REG_INTERRUPT_DEC_E))
+			return IRQ_HANDLED;
+
+		rockchip_vpu2_dec_soft_reset(vpu);
+	}
 
-	vdpu_write(vpu, 0, VDPU_REG_INTERRUPT);
 	vdpu_write(vpu, 0, VDPU_REG_AXI_CTRL);
 
 	hantro_irq_done(vpu, state);
@@ -482,8 +515,7 @@ static void rockchip_vpu2_dec_reset(struct hantro_ctx *ctx)
 	struct hantro_dev *vpu = ctx->dev;
 
 	vdpu_write(vpu, VDPU_REG_INTERRUPT_DEC_IRQ_DIS, VDPU_REG_INTERRUPT);
-	vdpu_write(vpu, 0, VDPU_REG_EN_FLAGS);
-	vdpu_write(vpu, 1, VDPU_REG_SOFT_RESET);
+	rockchip_vpu2_dec_soft_reset(vpu);
 }
 
 static void rockchip_vpu2_enc_reset(struct hantro_ctx *ctx)
Signature · 1 line
2.55.0