public inbox for linux-can@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: "Stefan Mätje" <Stefan.Maetje@esd.eu>,
	"engnfrc@gmail.com" <engnfrc@gmail.com>,
	"mailhol.vincent@wanadoo.fr" <mailhol.vincent@wanadoo.fr>
Cc: "linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Subject: Re: ip link valid options checking
Date: Sat, 10 Jul 2021 12:19:08 +0200	[thread overview]
Message-ID: <2b09f159-097c-feab-ad5f-d65523f90a5c@hartkopp.net> (raw)
In-Reply-To: <b1da5bb9b940c7cb262184ec828568a38af8f5af.camel@esd.eu>

Hi Stefan,

On 09.07.21 17:07, Stefan Mätje wrote:
> Am Freitag, den 09.07.2021, 14:00 +0200 schrieb Vincent MAILHOL:

> 
> Unfortunately the netlink kernel interface gives access only to the
> IFLA_CAN_CTRLMODE data which boils down to an access of the netdev_priv(dev)-
>> priv->ctrlmode flags set in the driver (see also in a Linux tree under
> drivers/net/can/dev/netlink.c). But the "ctrlmode" flags represent only the
> current setup. So you can see if CAN-FD mode is currently enabled.
> 
> But I think the thread opener wants to know in advance if the kernel gives us
> the information what modes a certain driver supports. That is encoded in
> netdev_priv(dev)->priv->ctrlmode_supported and netdev_priv(dev)->priv-
>> ctrlmode_static. But for these flags there is no netlink interface to
> interrogate that settings at the moment.
> 
> So you can't see in advance if a CAN driver would support for instance triple-
> sampling or the CAN_CTRLMODE_CC_LEN8_DLC mode. To know it you must try to set
> such option atm. I think.

Yes, but the settings of priv->ctrlmode_static may lead into problems 
too as there might be a fixed setting that can not be altered.

As you already pointed out the netlink interface only provides the 
current setting of priv->ctrlmode.

Btw. the struct can_ctrlmode has two u32 elements, so we could use the 
mask element to pass the priv->ctrlmode_supported value to the user space:

diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index e38c2566aff4..91c6ae06a576 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -259,11 +259,12 @@ static size_t can_get_size(const struct net_device 
*dev)
  }

  static int can_fill_info(struct sk_buff *skb, const struct net_device 
*dev)
  {
         struct can_priv *priv = netdev_priv(dev);
-       struct can_ctrlmode cm = {.flags = priv->ctrlmode};
+       struct can_ctrlmode cm = {.flags = priv->ctrlmode,
+               .mask = priv->ctrlmode_supported};
         struct can_berr_counter bec = { };
         enum can_state state = priv->state;

         if (priv->do_get_state)
                 priv->do_get_state(dev, &state);

Additionally we could also make the mask element in struct can_ctrlmode 
a union with a 'supported' element ...

But this is, what would be needed here, right?

Best regards,
Oliver

  reply	other threads:[~2021-07-10 10:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-07 17:45 ip link valid options checking Joshua Quesenberry
2021-07-09 12:00 ` Vincent MAILHOL
2021-07-09 15:07   ` Stefan Mätje
2021-07-10 10:19     ` Oliver Hartkopp [this message]
2021-07-13 19:54       ` Stefan Mätje

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=2b09f159-097c-feab-ad5f-d65523f90a5c@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=Stefan.Maetje@esd.eu \
    --cc=engnfrc@gmail.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    /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