[{"id":28854,"web_url":"https://patchwork.libcamera.org/comment/28854/","msgid":"<3ecdosfweu5dg2uvdz5tdz2zwkxsinxg7f67jfpg3xhoe4vscp@6wdzmol6rlaj>","date":"2024-03-05T08:57:51","subject":"Re: [PATCH/RFC 11/32] libcamera: v4l2_subdevice: Update to the new\n\tkernel routing API","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Laurent,\n  one question\n\nOn Fri, Mar 01, 2024 at 11:21:00PM +0200, Laurent Pinchart wrote:\n> The subdev embedded data support series includes a change to the\n> VIDIOC_SUBDEV_G_ROUTING and VIDIOC_SUBDEV_S_ROUTING ioctls that impacts\n> the userspace API.\n>\n> Update to the new API. Backward compatibility can't be easily preserved\n> as the ioctl structure size has changed. This is not a major issue, as\n> the routing API isn't enabled in any upstream kernel.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/v4l2_subdevice.cpp | 43 ++++++++++++++++++++++++++------\n>  1 file changed, 35 insertions(+), 8 deletions(-)\n>\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 3653f57a7d10..d5d400cdfd58 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -1332,19 +1332,23 @@ int V4L2Subdevice::getRouting(Routing *routing, Whence whence)\n>  \trt.which = whence;\n>\n>  \tint ret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt);\n> -\tif (ret == 0 || ret == -ENOTTY)\n> -\t\treturn ret;\n> -\n> -\tif (ret != -ENOSPC) {\n> -\t\tLOG(V4L2, Error)\n> -\t\t\t<< \"Failed to retrieve number of routes: \"\n> -\t\t\t<< strerror(-ret);\n> +\tif (ret) {\n> +\t\tif (ret != -ENOTTY)\n\nIf we get here, it means\n\n\tcaps_.hasStreams()\n\nIf a subdevice claims stream support, shouldn't the routing kAPI be\nenabled, or is it still legit to get a ENOTTY back ?\n\nThanks\n  j\n\n> +\t\t\tLOG(V4L2, Error)\n> +\t\t\t\t<< \"Failed to retrieve number of routes: \"\n> +\t\t\t\t<< strerror(-ret);\n>  \t\treturn ret;\n>  \t}\n>\n> +\tif (!rt.num_routes)\n> +\t\treturn 0;\n> +\n>  \tstd::vector<struct v4l2_subdev_route> routes{ rt.num_routes };\n>  \trt.routes = reinterpret_cast<uintptr_t>(routes.data());\n>\n> +\trt.len_routes = rt.num_routes;\n> +\trt.num_routes = 0;\n> +\n>  \tret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt);\n>  \tif (ret) {\n>  \t\tLOG(V4L2, Error)\n> @@ -1391,6 +1395,7 @@ int V4L2Subdevice::setRouting(Routing *routing, Whence whence)\n>\n>  \tstruct v4l2_subdev_routing rt = {};\n>  \trt.which = whence;\n> +\trt.len_routes = routes.size();\n>  \trt.num_routes = routes.size();\n>  \trt.routes = reinterpret_cast<uintptr_t>(routes.data());\n>\n> @@ -1400,7 +1405,29 @@ int V4L2Subdevice::setRouting(Routing *routing, Whence whence)\n>  \t\treturn ret;\n>  \t}\n>\n> -\troutes.resize(rt.num_routes);\n> +\t/*\n> +\t * The kernel wants to return more routes than we have space for. We\n> +\t * need to issue a VIDIOC_SUBDEV_G_ROUTING call.\n> +\t */\n> +\tif (rt.num_routes > routes.size()) {\n> +\t\troutes.resize(rt.num_routes);\n> +\n> +\t\trt.len_routes = rt.num_routes;\n> +\t\trt.num_routes = 0;\n> +\n> +\t\tret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt);\n> +\t\tif (ret) {\n> +\t\t\tLOG(V4L2, Error)\n> +\t\t\t\t<< \"Failed to retrieve routes: \" << strerror(-ret);\n> +\t\t\treturn ret;\n> +\t\t}\n> +\t}\n> +\n> +\tif (rt.num_routes != routes.size()) {\n> +\t\tLOG(V4L2, Error) << \"Invalid number of routes\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n>  \trouting->resize(rt.num_routes);\n>\n>  \tfor (const auto &[i, route] : utils::enumerate(routes))\n> --\n> Regards,\n>\n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6CBC0C326B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  5 Mar 2024 08:57:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BB5FE62871;\n\tTue,  5 Mar 2024 09:57:57 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 154D562865\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Mar 2024 09:57:56 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2001:b07:5d2e:52c9:cc1e:e404:491f:e6ea])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 74A33CC8;\n\tTue,  5 Mar 2024 09:57:38 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"R74Ub5jR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1709629058;\n\tbh=N7n7TmPbTOmMjJ0d0dX7GuWAHF16/ut5FmliRPeSNsU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=R74Ub5jR/JbV4KXu3D1vCjOqGHpeaUV2OO8uI63BzKaQN/z7BtQIo08eTG8En3w8D\n\tDgWGKNtW241+wQCSMGoMs+V4xvyG21re5FQUj6eDv9YfKnhSB3Q8fCOwPfYCzGc3PA\n\tnTn5kttrjv6jbj1NNg+9S5mBj8OJlMwCZpFQrmbQ=","Date":"Tue, 5 Mar 2024 09:57:51 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH/RFC 11/32] libcamera: v4l2_subdevice: Update to the new\n\tkernel routing API","Message-ID":"<3ecdosfweu5dg2uvdz5tdz2zwkxsinxg7f67jfpg3xhoe4vscp@6wdzmol6rlaj>","References":"<20240301212121.9072-1-laurent.pinchart@ideasonboard.com>\n\t<20240301212121.9072-12-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240301212121.9072-12-laurent.pinchart@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org, Sakari Ailus <sakari.ailus@iki.fi>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":28859,"web_url":"https://patchwork.libcamera.org/comment/28859/","msgid":"<20240305092829.GJ12503@pendragon.ideasonboard.com>","date":"2024-03-05T09:28:29","subject":"Re: [PATCH/RFC 11/32] libcamera: v4l2_subdevice: Update to the new\n\tkernel routing API","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Tue, Mar 05, 2024 at 09:57:51AM +0100, Jacopo Mondi wrote:\n> Hi Laurent,\n>   one question\n> \n> On Fri, Mar 01, 2024 at 11:21:00PM +0200, Laurent Pinchart wrote:\n> > The subdev embedded data support series includes a change to the\n> > VIDIOC_SUBDEV_G_ROUTING and VIDIOC_SUBDEV_S_ROUTING ioctls that impacts\n> > the userspace API.\n> >\n> > Update to the new API. Backward compatibility can't be easily preserved\n> > as the ioctl structure size has changed. This is not a major issue, as\n> > the routing API isn't enabled in any upstream kernel.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/libcamera/v4l2_subdevice.cpp | 43 ++++++++++++++++++++++++++------\n> >  1 file changed, 35 insertions(+), 8 deletions(-)\n> >\n> > diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> > index 3653f57a7d10..d5d400cdfd58 100644\n> > --- a/src/libcamera/v4l2_subdevice.cpp\n> > +++ b/src/libcamera/v4l2_subdevice.cpp\n> > @@ -1332,19 +1332,23 @@ int V4L2Subdevice::getRouting(Routing *routing, Whence whence)\n> >  \trt.which = whence;\n> >\n> >  \tint ret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt);\n> > -\tif (ret == 0 || ret == -ENOTTY)\n> > -\t\treturn ret;\n> > -\n> > -\tif (ret != -ENOSPC) {\n> > -\t\tLOG(V4L2, Error)\n> > -\t\t\t<< \"Failed to retrieve number of routes: \"\n> > -\t\t\t<< strerror(-ret);\n> > +\tif (ret) {\n> > +\t\tif (ret != -ENOTTY)\n> \n> If we get here, it means\n> \n> \tcaps_.hasStreams()\n> \n> If a subdevice claims stream support, shouldn't the routing kAPI be\n> enabled, or is it still legit to get a ENOTTY back ?\n\nGood question. For setRouting() I think it may be considered legit, but\nfor getRouting(), likely not. I'll drop the check and log an error\nunconditionally.\n\n> > +\t\t\tLOG(V4L2, Error)\n> > +\t\t\t\t<< \"Failed to retrieve number of routes: \"\n> > +\t\t\t\t<< strerror(-ret);\n> >  \t\treturn ret;\n> >  \t}\n> >\n> > +\tif (!rt.num_routes)\n> > +\t\treturn 0;\n> > +\n> >  \tstd::vector<struct v4l2_subdev_route> routes{ rt.num_routes };\n> >  \trt.routes = reinterpret_cast<uintptr_t>(routes.data());\n> >\n> > +\trt.len_routes = rt.num_routes;\n> > +\trt.num_routes = 0;\n> > +\n> >  \tret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt);\n> >  \tif (ret) {\n> >  \t\tLOG(V4L2, Error)\n> > @@ -1391,6 +1395,7 @@ int V4L2Subdevice::setRouting(Routing *routing, Whence whence)\n> >\n> >  \tstruct v4l2_subdev_routing rt = {};\n> >  \trt.which = whence;\n> > +\trt.len_routes = routes.size();\n> >  \trt.num_routes = routes.size();\n> >  \trt.routes = reinterpret_cast<uintptr_t>(routes.data());\n> >\n> > @@ -1400,7 +1405,29 @@ int V4L2Subdevice::setRouting(Routing *routing, Whence whence)\n> >  \t\treturn ret;\n> >  \t}\n> >\n> > -\troutes.resize(rt.num_routes);\n> > +\t/*\n> > +\t * The kernel wants to return more routes than we have space for. We\n> > +\t * need to issue a VIDIOC_SUBDEV_G_ROUTING call.\n> > +\t */\n> > +\tif (rt.num_routes > routes.size()) {\n> > +\t\troutes.resize(rt.num_routes);\n> > +\n> > +\t\trt.len_routes = rt.num_routes;\n> > +\t\trt.num_routes = 0;\n> > +\n> > +\t\tret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt);\n> > +\t\tif (ret) {\n> > +\t\t\tLOG(V4L2, Error)\n> > +\t\t\t\t<< \"Failed to retrieve routes: \" << strerror(-ret);\n> > +\t\t\treturn ret;\n> > +\t\t}\n> > +\t}\n> > +\n> > +\tif (rt.num_routes != routes.size()) {\n> > +\t\tLOG(V4L2, Error) << \"Invalid number of routes\";\n> > +\t\treturn -EINVAL;\n> > +\t}\n> > +\n> >  \trouting->resize(rt.num_routes);\n> >\n> >  \tfor (const auto &[i, route] : utils::enumerate(routes))","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id AAF02C326B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  5 Mar 2024 09:28:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4D47E62875;\n\tTue,  5 Mar 2024 10:28:29 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 177546286C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Mar 2024 10:28:28 +0100 (CET)","from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi\n\t[89.27.53.110])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0AC88A27;\n\tTue,  5 Mar 2024 10:28:10 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"uJ+HpP6Y\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1709630891;\n\tbh=0uLzFXh8FokydkAzVfpUdupch8Sl5F001yHnZG11R3U=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=uJ+HpP6Y34Gd53uNnCanBVEF6CywkX53iGRTfdeTLdjctw7k3jQhk3coiClQnbZZR\n\tb4DzDdZWu/zUVPUYIFuv54PVmELkpl7f1uf6JRTerUEUr+ljCixVfPu9eWNktYPCk9\n\tPkFLXNADox0xQnzf0EvxZ9uF6VLReD7ykgW8Iv+I=","Date":"Tue, 5 Mar 2024 11:28:29 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"Re: [PATCH/RFC 11/32] libcamera: v4l2_subdevice: Update to the new\n\tkernel routing API","Message-ID":"<20240305092829.GJ12503@pendragon.ideasonboard.com>","References":"<20240301212121.9072-1-laurent.pinchart@ideasonboard.com>\n\t<20240301212121.9072-12-laurent.pinchart@ideasonboard.com>\n\t<3ecdosfweu5dg2uvdz5tdz2zwkxsinxg7f67jfpg3xhoe4vscp@6wdzmol6rlaj>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<3ecdosfweu5dg2uvdz5tdz2zwkxsinxg7f67jfpg3xhoe4vscp@6wdzmol6rlaj>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org, Sakari Ailus <sakari.ailus@iki.fi>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]