Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp589005pxb; Sat, 18 Sep 2021 11:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQizOVKu6O5dk3cfAGTqhw3jxs+GWtvI4m3wX/8Ju615hWEWaY7up2EQvG4IQ2KrN8bIM6 X-Received: by 2002:a5d:9283:: with SMTP id s3mr566714iom.75.1631989440832; Sat, 18 Sep 2021 11:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631989440; cv=none; d=google.com; s=arc-20160816; b=NXRC+6c7Dm1KsHjdl8UnjS017wJwqsnO3UUiqE+rDFrOp7K2qRysbo2szQwTV5FxXW LPQGcWWPzsZj6SLfV/9Cmg4oSC/MuSoEueUQqaWa+In8Y8kz0XNuON9fdPFI1szvun3L rZigm8etIURL0zyHKuIYBL9Sjz71pRX5/zZR4FsGtgkV9LrdDuOwMfFANhq1FsWfeqAo bAgOdfQ2Ba1XtOgblrVICwwQ9Qb1it+dNvDC4wSj11n7xpjiB5Dc7TWm0k3Mvq+XvSWR amlFF3CSqjCAEfxyD3g37RAJhI68m/hAkqGvuh32J3aW/ZsR9nMKLAwoXJ24gjWxTajX r4tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ADF0iUbR4VjZFqI4+mPFtFnun0JiIT3Azb3cmqUB4qc=; b=W1n1CogI9tq/OvbmR0FNIuJ9WMLyk7phHsN4BQ+SI+S75Y7hNwDwLea89lHu8ApzSg N3RXgOnnnr84BYEoncqVIkv8XdQuwh9UvBXL51po1yC5lEcBUWbrbtjpdZa6zDqWVHbH H4G2M4ZBean/tpm4w2aKxcikxTjGIyBV7Je+n9ZO3nCHodgeFr9L7MD04QTnWdMstuaE YGmh8WwS6+niUAVXwdtWCph+kTSPXnLFh04aytE4/RyH4tAheA4CMPGOpNuYD2eFrhnc c3ZJMg9ijUxJD3PVt8Zj8IchFip1Lg72xspRSypqW6/qTSEKX5EFOpIwRg8jWTjeoglR z8Kw== 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 r2si8239503ila.178.2021.09.18.11.23.48; Sat, 18 Sep 2021 11:24:00 -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 S244874AbhIRJ71 (ORCPT + 99 others); Sat, 18 Sep 2021 05:59:27 -0400 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:52757 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244791AbhIRJ7V (ORCPT ); Sat, 18 Sep 2021 05:59:21 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by smtp.orange.fr with ESMTPA id RX5Zmuh4X1yYBRX6Ym0kIi; Sat, 18 Sep 2021 11:57:57 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Sat, 18 Sep 2021 11:57:57 +0200 X-ME-IP: 114.149.34.46 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Stefan=20M=C3=A4tje?= , Vincent Mailhol , =?UTF-8?q?Stefan=20M=C3=A4tje?= Subject: [PATCH v6 5/6] can: netlink: add can_priv::do_get_auto_tdcv() to retrieve tdcv from device Date: Sat, 18 Sep 2021 18:56:36 +0900 Message-Id: <20210918095637.20108-6-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210918095637.20108-1-mailhol.vincent@wanadoo.fr> References: <20210918095637.20108-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some CAN device can measure the TDCV (Transmission Delay Compensation Value) automatically for each transmitted CAN frames. A callback function do_get_auto_tdcv() is added to retrieve that value. This function is used only if CAN_CTRLMODE_TDC_AUTO is enabled (if CAN_CTRLMODE_TDC_MANUAL is selected, the TDCV value is provided by the user). If the device does not support reporting of TDCV, do_get_auto_tdcv() should be set to NULL and TDCV will not be reported by the netlink interface. On success, do_get_auto_tdcv() shall return 0. If the value can not be measured by the device, for example because network is down or because no frames were transmitted yet, can_priv::do_get_auto_tdcv() shall return a negative error code (e.g. -EINVAL) to signify that the value is not yet available. In such cases, TDCV is not reported by the netlink interface. CC: Stefan Mätje Signed-off-by: Vincent Mailhol --- drivers/net/can/dev/netlink.c | 15 ++++++++++++--- include/linux/can/dev.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index c77cc6ae88b6..95cca4e5251f 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -372,7 +372,8 @@ static size_t can_tdc_get_size(const struct net_device *dev) } if (can_tdc_is_enabled(priv)) { - if (priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL) + if (priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL || + priv->do_get_auto_tdcv) size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV */ size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCO */ if (priv->tdc_const->tdcf_max) @@ -445,8 +446,16 @@ static int can_tdc_fill_info(struct sk_buff *skb, const struct net_device *dev) goto err_cancel; if (can_tdc_is_enabled(priv)) { - if (priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL && - nla_put_u32(skb, IFLA_CAN_TDC_TDCV, tdc->tdcv)) + u32 tdcv; + int err = -EINVAL; + + if (priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL) { + tdcv = tdc->tdcv; + err = 0; + } else if (priv->do_get_auto_tdcv) { + err = priv->do_get_auto_tdcv(dev, &tdcv); + } + if (!err && nla_put_u32(skb, IFLA_CAN_TDC_TDCV, tdcv)) goto err_cancel; if (nla_put_u32(skb, IFLA_CAN_TDC_TDCO, tdc->tdco)) goto err_cancel; diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 6dacbbb41e68..b4aa0f048cab 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -82,6 +82,7 @@ struct can_priv { enum can_state *state); int (*do_get_berr_counter)(const struct net_device *dev, struct can_berr_counter *bec); + int (*do_get_auto_tdcv)(const struct net_device *dev, u32 *tdcv); unsigned int echo_skb_max; struct sk_buff **echo_skb; -- 2.32.0