Linux CAN drivers development
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Marc Kleine-Budde <mkl@pengutronix.de>, Max Staudt <max@enpas.org>
Cc: Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	linux-kernel@vger.kernel.org, linux-can@vger.kernel.org,
	michael@amarulasolutions.com,
	Amarula patchwork <linux-amarula@amarulasolutions.com>,
	Jeroen Hofstee <jhofstee@victronenergy.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Wolfgang Grandegger <wg@grandegger.com>,
	netdev@vger.kernel.org
Subject: Re: [RFC PATCH v3 8/9] can: slcan: add support to set bit time register (btr)
Date: Wed, 27 Jul 2022 22:12:13 +0200	[thread overview]
Message-ID: <fb31bfeb-e7bc-c7f8-db2c-f8d0c531af99@hartkopp.net> (raw)
In-Reply-To: <20220727182414.3mysdeam7mtnqyfx@pengutronix.de>



On 27.07.22 20:24, Marc Kleine-Budde wrote:
> On 27.07.2022 19:28:39, Max Staudt wrote:
>> On Wed, 27 Jul 2022 13:30:54 +0200
>> Marc Kleine-Budde <mkl@pengutronix.de> wrote:
>>
>>> As far as I understand, setting the btr is an alternative way to set the
>>> bitrate, right? I don't like the idea of poking arbitrary values into a
>>> hardware from user space.
>>
>> I agree with Marc here.
>>
>> This is a modification across the whole stack, specific to a single
>> device, when there are ways around.
>>
>> If I understand correctly, the CAN232 "S" command sets one of the fixed
>> bitrates, whereas "s" sets the two BTR registers. Now the question is,
>> what do BTR0/BTR1 mean, and what are they? If they are merely a divider
>> in a CAN controller's master clock, like in ELM327, then you could
>>
>>    a) Calculate the BTR values from the bitrate userspace requests, or
> 
> Most of the other CAN drivers write the BTR values into the register of
> the hardware. How are these BTR values transported into the driver?
> 
> There are 2 ways:
> 
> 1) - user space configures a bitrate
>     - the kernel calculates with the "struct can_bittiming_const" [1] given
>       by driver and the CAN clock rate the low level timing parameters.
> 
>       [1] https://elixir.bootlin.com/linux/v5.18/source/include/uapi/linux/can/netlink.h#L47
> 
> 2) - user space configures low level bit timing parameter
>       (Sample point in one-tenth of a percent, Time quanta (TQ) in
>        nanoseconds, Propagation segment in TQs, Phase buffer segment 1 in
>        TQs, Phase buffer segment 2 in TQs, Synchronisation jump width in
>        TQs)
>      - the kernel calculates the Bit-rate prescaler from the given TQ and
>        CAN clock rate
> 
> Both ways result in a fully calculated "struct can_bittiming" [2]. The
> driver translates this into the hardware specific BTR values and writes
> the into the registers.
> 
> If you know the CAN clock and the bit timing const parameters of the
> slcan's BTR register you can make use of the automatic BTR calculation,
> too. Maybe the framework needs some tweaking if the driver supports both
> fixed CAN bit rate _and_ "struct can_bittiming_const".
> 
> [2] https://elixir.bootlin.com/linux/v5.18/source/include/uapi/linux/can/netlink.h#L31
> 
>>    b) pre-calculate a huge table of possible bitrates and present them
>>       all to userspace. Sounds horrible, but that's what I did in can327,
>>       haha. Maybe I should have reigned them in a little, to the most
>>       useful values.
> 
> If your adapter only supports fixed values, then that's the only way to
> go.
> 
>>    c) just limit the bitrates to whatever seems most useful (like the
>>       "S" command's table), and let users complain if they really need
>>       something else. In the meantime, they are still free to slcand or
>>       minicom to their heart's content before attaching slcan, thanks to
>>       your backwards compatibility efforts.
> 
> In the early stages of the non-mainline CAN framework we had tables for
> BTR values for some fixed bit rates, but that turned out to be not
> scaleable.

The Microchip CAN BUS Analyzer Tool is another example for fixed bitrates:

https://elixir.bootlin.com/linux/v5.18.14/source/drivers/net/can/usb/mcba_usb.c#L156

So this might be the way to go here too ...

Best regards,
Oliver

> 
>> In short, to me, this isn't a deal breaker for your patch series.
> 
> Marc
> 

  reply	other threads:[~2022-07-27 20:12 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 21:02 [RFC PATCH v3 0/9] can: slcan: extend supported features (step 2) Dario Binacchi
2022-07-26 21:02 ` [RFC PATCH v3 1/9] can: slcan: use KBUILD_MODNAME and define pr_fmt to replace hardcoded names Dario Binacchi
2022-07-26 21:02 ` [RFC PATCH v3 2/9] can: slcan: remove useless header inclusions Dario Binacchi
2022-07-26 21:02 ` [RFC PATCH v3 3/9] can: slcan: remove legacy infrastructure Dario Binacchi
2022-07-27 17:09   ` Max Staudt
2022-07-26 21:02 ` [RFC PATCH v3 4/9] can: slcan: change every `slc' occurrence in `slcan' Dario Binacchi
2022-07-26 21:02 ` [RFC PATCH v3 5/9] can: slcan: use the generic can_change_mtu() Dario Binacchi
2022-07-26 21:02 ` [RFC PATCH v3 6/9] can: slcan: add support for listen-only mode Dario Binacchi
2022-07-26 21:02 ` [RFC PATCH v3 7/9] ethtool: add support to get/set CAN bit time register Dario Binacchi
2022-07-26 21:02 ` [RFC PATCH v3 8/9] can: slcan: add support to set bit time register (btr) Dario Binacchi
2022-07-27 11:30   ` Marc Kleine-Budde
2022-07-27 15:55     ` Dario Binacchi
2022-07-27 17:21       ` Marc Kleine-Budde
2022-07-27 17:28         ` Dario Binacchi
2022-07-27 17:33           ` Max Staudt
2022-07-27 18:23             ` Dario Binacchi
2022-07-27 17:28     ` Max Staudt
2022-07-27 18:24       ` Marc Kleine-Budde
2022-07-27 20:12         ` Oliver Hartkopp [this message]
2022-07-28  6:56           ` Marc Kleine-Budde
2022-07-28  7:36         ` Dario Binacchi
2022-07-28  9:02           ` Marc Kleine-Budde
2022-07-28 10:23             ` Dario Binacchi
2022-07-28 10:50               ` Marc Kleine-Budde
2022-07-28 10:57                 ` Max Staudt
2022-07-29  6:52                   ` Dario Binacchi
2022-07-29  7:33                     ` Marc Kleine-Budde
2022-07-31 15:54                       ` Dario Binacchi
2022-07-31 18:58                         ` Marc Kleine-Budde
2022-07-26 21:02 ` [RFC PATCH v3 9/9] MAINTAINERS: Add maintainer for the slcan driver Dario Binacchi
2022-07-27 18:31 ` [RFC PATCH v3 0/9] can: slcan: extend supported features (step 2) Marc Kleine-Budde

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=fb31bfeb-e7bc-c7f8-db2c-f8d0c531af99@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhofstee@victronenergy.com \
    --cc=kuba@kernel.org \
    --cc=linux-amarula@amarulasolutions.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=max@enpas.org \
    --cc=michael@amarulasolutions.com \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=wg@grandegger.com \
    /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