Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp686652pxy; Sat, 14 Aug 2021 20:36:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwb5+zhASlUCbwYVbE761jD13UxzzonnOF12H1nJFizAHLKKBYZs2vxmCU41FzTbbF0I425 X-Received: by 2002:aa7:c49a:: with SMTP id m26mr4670221edq.258.1628998613012; Sat, 14 Aug 2021 20:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628998613; cv=none; d=google.com; s=arc-20160816; b=jAvIMhQE+CVLb0OyHqyGAl+3fcXybQ0csAdMSGGS2TdR928nGhdtledXmI4OOqQ/rW nLIoTl4NALeNb2nvlOI4XtE1oTHQl4UHCXC06ekYBOTIymSlFOv1BcC2xDYsGE859V2H PfbUcTZWFqEk+kp4t4OEOvJeHFGapFBTCIfb+b027TeEVRX9zb1bKminQ5JpgtOH+Abr z50nb7JP4ogTgSjc/eYk6AQ4F9WC0sbpD6dZdS9/r/XmeBs9M3GZwaDe9Ctz00InpOMH w8G+PVukmPo3VJMv7IMcoxmfosnL5bQTOdaGehzXsVCjM5E2rmhXWu84tCYUV6KDFcX5 pKEA== 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=HXXCJLF8oRWruxm10sDb42FUh6swKAhRL0QvAOdeGBA=; b=nAokTCqMB3pZh6WppuRS4MA7wPvGLazMVHCs5uxBiKmpWSkhFxQA0Ol9Qz8LuIYXY3 BN6fANei9Jpcwljf5JrTy+ABDTDUXwayM+Pb51UdiGWEJFNGZErs9XNVm41cBMKhRI0+ UXlWbdkmYYn4hFqOLE+vKoxwPWSCMF3OHADZzCHrfKyX32tubhQp+7ny0y1WBxI4U0sA 7JmrVnmR5BDACvJQbUYJ8XGhjzWFQG+R4YWRGElkJJjW3vCjZ/D8scifRw7sBlakoVFl lht3TGJoU57MkAgHDpoR2Mg1t8VcmCX89l0aVWuXq3DrPPoA+gPKF47XZabVtKgzL/3g QmtQ== 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 l3si7725183ejd.407.2021.08.14.20.36.30; Sat, 14 Aug 2021 20:36:53 -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 S236638AbhHODeq (ORCPT + 99 others); Sat, 14 Aug 2021 23:34:46 -0400 Received: from smtp11.smtpout.orange.fr ([80.12.242.133]:30375 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236855AbhHODep (ORCPT ); Sat, 14 Aug 2021 23:34:45 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by mwinf5d21 with ME id hfZ7250050zjR6y03faDyh; Sun, 15 Aug 2021 05:34:15 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: bWFpbGhvbC52aW5jZW50QHdhbmFkb28uZnI= X-ME-Date: Sun, 15 Aug 2021 05:34:15 +0200 X-ME-IP: 114.149.34.46 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: =?UTF-8?q?Stefan=20M=C3=A4tje?= , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Mailhol , =?UTF-8?q?Stefan=20M=C3=A4tje?= Subject: [PATCH v5 6/7] can: netlink: add can_priv::do_get_auto_tdcv() to retrieve tdcv from device Date: Sun, 15 Aug 2021 12:32:47 +0900 Message-Id: <20210815033248.98111-7-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210815033248.98111-1-mailhol.vincent@wanadoo.fr> References: <20210815033248.98111-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 f05745c96b9c..776284593b5d 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -362,7 +362,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) @@ -435,8 +436,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 fa75e29182a3..266d0fe9de9d 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -74,6 +74,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.31.1