Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1004097ybt; Fri, 19 Jun 2020 21:17:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7yTUovTI51ZKdO5A1AWvmYwDQtutNT66qvHoWi1ir/f7lg+fedpUmHPZpkc4ViVyjd+N1 X-Received: by 2002:a17:906:9257:: with SMTP id c23mr6398799ejx.86.1592626652622; Fri, 19 Jun 2020 21:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592626652; cv=none; d=google.com; s=arc-20160816; b=Rw/2Y2iS4UfHnasQY6UoMWskUnbET4dif1JUsSIvEwFDYDYxoY/EyvdFNMrghitKWw 4GW/whhROUqpf6xOBjo23Q4t4MFJFvUWb92IYDrKP5JCpip19XQAksJ12/x8gtZxyRLD 0syRzTll1gWate3MDrjjvgDtUu0Y2fLO752GF+BqfB/EvM1mmR4tL94/772NlhvXE14S tREMmudm4ljasZeqetGMpFhyI7Rl5wSCa5/PrpUj8EKGmCmPjWbF/S4LQVLlNVGIzmo0 z88lTs3/xrItVY0CHLUbW0XjVZHeaA9xLrXgrL9q32rjh2QPP8KVoejnulm5CDr7oGf0 nXqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=1qy/C6i+VfkzL79sdT2rkj95MDVIr/oS3LL3rDiuPu4=; b=eyTQ50+5sESAk3VN3+fqFciTtYzT5Whwc6ASc0X4e7tqOWxYxDLgAQd3nKxOgZ1rJ0 FrpsQEGh2Ig3RonpLiR90Xq/rbLkeMWEpGX99AQXq2ffGehuRuz4sWSytOYKevsenonI /UawL4KWaP01Y1Wn0HEA1urrZk9/c5Fm7qH6fPWO4Dxt5dlm5DxR32I+tnwVprcFAEdy gyaEOEMIjQQHBsU94I9wgfeH4ZHt7IJRyRr80w8fum6LR42OGdXMG5h6Kl5/Y5RZkXTB WNPy1BWk6JUEYDI/x5RGo6IC8UIoerlphdfZisTRmfZHf4VoWn89DRSoLGqc04A4Rh3a go5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si743883edt.433.2020.06.19.21.17.11; Fri, 19 Jun 2020 21:17:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403802AbgFSRrT (ORCPT + 99 others); Fri, 19 Jun 2020 13:47:19 -0400 Received: from smtp1.de.adit-jv.com ([93.241.18.167]:44817 "EHLO smtp1.de.adit-jv.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391317AbgFSRrQ (ORCPT ); Fri, 19 Jun 2020 13:47:16 -0400 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 4D5453C057C; Fri, 19 Jun 2020 19:47:13 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Vk8qxqVgzSCj; Fri, 19 Jun 2020 19:47:07 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 67C663C00BA; Fri, 19 Jun 2020 19:47:07 +0200 (CEST) Received: from vmlxhi-121.localdomain (10.72.92.132) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.487.0; Fri, 19 Jun 2020 19:47:06 +0200 From: Michael Rodin To: =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Mauro Carvalho Chehab , , , CC: Michael Rodin , , , Subject: [PATCH 1/2] [RFC] media: rcar-vin: send a V4L2 event to vdev if no frame captured after a timeout Date: Fri, 19 Jun 2020 19:46:10 +0200 Message-ID: <1592588777-100596-1-git-send-email-mrodin@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.72.92.132] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Data flow from an upstream subdevice can stop permanently due to: - CSI2 transmission errors - silent failure of the source subdevice - disconnection of the source subdevice In those cases userspace waits for new buffers for an infinitely long time. In order to address this issue, use a timer to monitor, that rvin_irq() is capturing at least one frame within a IRQ_TIMEOUT_MS period. Otherwise send a new private v4l2 event to userspace. This event is exported to userspace via a new uapi header. Signed-off-by: Michael Rodin --- drivers/media/platform/rcar-vin/rcar-dma.c | 21 +++++++++++++++++++++ drivers/media/platform/rcar-vin/rcar-v4l2.c | 1 + drivers/media/platform/rcar-vin/rcar-vin.h | 6 ++++++ include/uapi/linux/rcar-vin.h | 10 ++++++++++ 4 files changed, 38 insertions(+) create mode 100644 include/uapi/linux/rcar-vin.h diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c index 1a30cd0..bf8d733 100644 --- a/drivers/media/platform/rcar-vin/rcar-dma.c +++ b/drivers/media/platform/rcar-vin/rcar-dma.c @@ -937,6 +937,20 @@ static void rvin_capture_stop(struct rvin_dev *vin) #define RVIN_TIMEOUT_MS 100 #define RVIN_RETRIES 10 +static const struct v4l2_event rvin_irq_timeout = { + .type = V4L2_EVENT_RCAR_VIN_IRQ_TIMEOUT, +}; + +static void rvin_irq_timer_function(struct timer_list *timer) +{ + struct rvin_dev *vin = container_of(timer, struct rvin_dev, + irq_timer); + + vin_err(vin, "%s: frame completion timeout after %i ms!\n", + __func__, IRQ_TIMEOUT_MS); + v4l2_event_queue(&vin->vdev, &rvin_irq_timeout); +} + static irqreturn_t rvin_irq(int irq, void *data) { struct rvin_dev *vin = data; @@ -1008,6 +1022,8 @@ static irqreturn_t rvin_irq(int irq, void *data) vin_dbg(vin, "Dropping frame %u\n", vin->sequence); } + mod_timer(&vin->irq_timer, jiffies + msecs_to_jiffies(IRQ_TIMEOUT_MS)); + vin->sequence++; /* Prepare for next frame */ @@ -1252,6 +1268,8 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) if (ret) dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, vin->scratch_phys); + else + mod_timer(&vin->irq_timer, jiffies + msecs_to_jiffies(IRQ_TIMEOUT_MS)); return ret; } @@ -1305,6 +1323,8 @@ static void rvin_stop_streaming(struct vb2_queue *vq) /* Free scratch buffer. */ dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, vin->scratch_phys); + + del_timer_sync(&vin->irq_timer); } static const struct vb2_ops rvin_qops = { @@ -1370,6 +1390,7 @@ int rvin_dma_register(struct rvin_dev *vin, int irq) goto error; } + timer_setup(&vin->irq_timer, rvin_irq_timer_function, 0); return 0; error: rvin_dma_unregister(vin); diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c index f421e25..c644134 100644 --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c @@ -581,6 +581,7 @@ static int rvin_subscribe_event(struct v4l2_fh *fh, { switch (sub->type) { case V4L2_EVENT_SOURCE_CHANGE: + case V4L2_EVENT_RCAR_VIN_IRQ_TIMEOUT: return v4l2_event_subscribe(fh, sub, 4, NULL); } return v4l2_ctrl_subscribe_event(fh, sub); diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index c19d077..7408f67 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -14,12 +14,14 @@ #define __RCAR_VIN__ #include +#include #include #include #include #include #include +#include /* Number of HW buffers */ #define HW_BUFFER_NUM 3 @@ -30,6 +32,8 @@ /* Max number on VIN instances that can be in a system */ #define RCAR_VIN_NUM 8 +#define IRQ_TIMEOUT_MS 1000 + struct rvin_group; enum model_id { @@ -196,6 +200,7 @@ struct rvin_info { * @compose: active composing * @src_rect: active size of the video source * @std: active video standard of the video source + * @irq_timer: monitors regular capturing of frames in rvin_irq() * * @alpha: Alpha component to fill in for supported pixel formats */ @@ -240,6 +245,7 @@ struct rvin_dev { struct v4l2_rect src_rect; v4l2_std_id std; + struct timer_list irq_timer; unsigned int alpha; }; diff --git a/include/uapi/linux/rcar-vin.h b/include/uapi/linux/rcar-vin.h new file mode 100644 index 00000000..4eb7f5e --- /dev/null +++ b/include/uapi/linux/rcar-vin.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +#ifndef RCAR_VIN_USER_H +#define RCAR_VIN_USER_H + +/* class for events sent by the rcar-vin driver */ +#define V4L2_EVENT_RCAR_VIN_CLASS V4L2_EVENT_PRIVATE_START +#define V4L2_EVENT_RCAR_VIN_IRQ_TIMEOUT (V4L2_EVENT_RCAR_VIN_CLASS | 0x1) + +#endif /* RCAR_VIN_USER_H */ -- 2.7.4