From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
kernel@pengutronix.de,
"Vincent Mailhol" <mailhol.vincent@wanadoo.fr>,
"Stefan Mätje" <stefan.maetje@esd.eu>,
"Marc Kleine-Budde" <mkl@pengutronix.de>
Subject: [PATCH net-next 07/15] can: netlink: add can_priv::do_get_auto_tdcv() to retrieve tdcv from device
Date: Sun, 24 Oct 2021 22:43:17 +0200 [thread overview]
Message-ID: <20211024204325.3293425-8-mkl@pengutronix.de> (raw)
In-Reply-To: <20211024204325.3293425-1-mkl@pengutronix.de>
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
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.
Link: https://lore.kernel.org/all/20210918095637.20108-6-mailhol.vincent@wanadoo.fr
CC: Stefan Mätje <stefan.maetje@esd.eu>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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.33.0
next prev parent reply other threads:[~2021-10-24 20:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-24 20:43 pull-request: can-next 2021-10-24 Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 01/15] can: bcm: Use hrtimer_forward_now() Marc Kleine-Budde
2021-10-25 12:10 ` patchwork-bot+netdevbpf
2021-10-24 20:43 ` [PATCH net-next 02/15] can: bittiming: can_fixup_bittiming(): change type of tseg1 and alltseg to unsigned int Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 03/15] can: bittiming: allow TDC{V,O} to be zero and add can_tdc_const::tdc{v,o,f}_min Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 04/15] can: bittiming: change unit of TDC parameters to clock periods Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 05/15] can: bittiming: change can_calc_tdco()'s prototype to not directly modify priv Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 06/15] can: netlink: add interface for CAN-FD Transmitter Delay Compensation (TDC) Marc Kleine-Budde
2021-10-24 20:43 ` Marc Kleine-Budde [this message]
2021-10-24 20:43 ` [PATCH net-next 08/15] can: dev: add can_tdc_get_relative_tdco() helper function Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 09/15] can: at91/janz-ican3: replace snprintf() in show functions with sysfs_emit() Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 10/15] can: rcar: drop unneeded ARM dependency Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 11/15] can: mscan: mpc5xxx_can: Make use of the helper function dev_err_probe() Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 12/15] can: gs_usb: use %u to print unsigned values Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 13/15] can: peak_usb: CANFD: store 64-bits hw timestamps Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 14/15] can: xilinx_can: remove repeated word from the kernel-doc Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 15/15] can: xilinx_can: xcan_remove(): remove redundant netif_napi_del() Marc Kleine-Budde
2021-10-25 12:10 ` pull-request: can-next 2021-10-24 patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211024204325.3293425-8-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=netdev@vger.kernel.org \
--cc=stefan.maetje@esd.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).