Linux CAN drivers development
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Vincent Mailhol <mailhol@kernel.org>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org
Subject: Re: [PATCH 0/4] can: automate IFF_ECHO flag for generic echo skbs
Date: Thu, 6 Aug 2026 14:01:11 +0200	[thread overview]
Message-ID: <d045b536-efd0-40a6-8357-e04c9db9236b@hartkopp.net> (raw)
In-Reply-To: <95290e92-68c4-4ce7-8a1a-7d23b0a268d5@kernel.org>

-CC linux-kernel@vger.kernel.org

On 05.08.26 23:06, Vincent Mailhol wrote:
> On 05/08/2026 at 18:17, Oliver Hartkopp wrote:

>> IMO it's the right approach that alloc_candev_mqs() sets the IFF_ECHO
>> flag and the default queue len.
> 
> For IFF_ECHO, this is exactly what this series does!

I just wanted to second you. This does not mean that I fully support the 
way it is implemented.

> For the default queue len, why not. I have not study this particular
> topic. But I think the IFF_ECHO and the queue len should be in separate
> series.

My patch does not even compile. I just wanted to lead the dicsussion 
into a direction to find a more versatile solution that covers virtual 
CAN interfaces, non-echo CAN interfaces and full featured (echo'ing) CAn 
interfaces.

>> What puzzles me is that the slcan driver is something in between which
>> is neither a real CAN hardware nor a virtual CAN interface.
> 
> My understanding it that devices which do not have a TX completion
> handler (like slcan or can327) have no benefits to implement the
> echo_skb framework and can instead simply rely on the PF_CAN core.

Right.

>> My idea would be to use alloc_candev() (-> alloc_candev_mqs()) only for
>> real CAN hardware devices and open code slcan and the virtual CAN
>> drivers ... which goes into the direction below.
>>
>> Any thoughts?
> 
> The logic I tried to follow in this series is that alloc_candev{,_mqs}()
> has two arguments:
> 
>    1. one for the priv structure
> 
>    2. one for the number of echo_skb
> 
> But then, when 2. is zero:
> 
>    alloc_candev{,_mqs}(..., 0)
> 
> means to me: give me all the features expect from the echo_skb.
> 
> With the above, there is no anomalies to see the slcan do:
> 
>    dev = alloc_candev(sizeof(*sl), 0);
> 
> So I don't see the point to open code the allocations in slcan. After
> patch #1 which corrects the echo skb count, the code describes correctly
> the behaviour.

To me ", 0);" is a silent switch which does not make clear that slcan 
and can327 do something different here.

We have 4 features:

- support of IFF_ECHO mode using echo_skb's
- support setting of bitrates via netlink
- support setting of whatever via ethtool
- use of TX queues (tx_queue_len != 0)

And I would like these features to be separately selected to be 
transparent about what the CAN driver needs and supports.

E.g. by defining a wrapper/define

dev = alloc_non_echo_candev(sizeof(*sl));

which calls

dev = alloc_candev(sizeof(*sl), 0);

And the same applies to the other features.

>> +    dev->tx_queue_len = CAN_TX_QUEUE_LEN;
> 
> 
> 
>> +    dev->flags |= IFF_ECHO;
> 
> I really prefer to have the IFF_ECHO gated under the
> 
> 	if (echo_skb_max) {
> 
> because it is tightly linked to the echo skb framework.

Definitely not. This is not what I meant with transparency.

> And yes, there are a couple drivers here and there which set IFF_ECHO
> without using the echo skb framework. But these are the drivers which
> implements their own custom echo skb logic. So it makes sense to have
> them open code the IFF_ECHO because they are also open coding the rest
> of the echo skb logic.
> 
> This goes back to my previous point that:
> 
>    alloc_candev{,_mqs}(..., 0)
> 
> means that the drivers do not use the framework echo skb. Such drivers
> fall in two categories:
> 
>    - No echo skb at all (e.g. slcan or can327): no IFF_ECHO
> 
>    - custom echo skb (e.g. grcan, janz-ican3): everything is open coded
>      -> explicit IFF_ECHO flag
> 

And that's why I would like to split these things up - at least by 
naming them differently.

>>       if (echo_skb_max) {
>>           priv->echo_skb_max = echo_skb_max;
>>           priv->echo_skb = (void *)priv +
>>               (size - echo_skb_max * sizeof(struct sk_buff *));
>>       }
>> diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
>> index 76e6b7b5c6a1..70263813ec40 100644
>> --- a/drivers/net/can/vcan.c
>> +++ b/drivers/net/can/vcan.c
>> @@ -167,16 +167,15 @@ static const struct ethtool_ops vcan_ethtool_ops = {
>>       .get_ts_info = ethtool_op_get_ts_info,
>>   };
>>
>>   static void vcan_setup(struct net_device *dev)
>>   {
>> -    dev->type        = ARPHRD_CAN;
>> -    dev->mtu        = CANXL_MTU;
>> -    dev->hard_header_len    = 0;
>> -    dev->addr_len        = 0;
>> -    dev->tx_queue_len    = 0;
>> -    dev->flags        = IFF_NOARP;
>> +    can_setup(dev);
>> +    dev->tx_queue_len = 0;
>> +    dev->mtu = CANXL_MTU;
>> +    dev->min_mtu = CAN_MTU;
>> +    dev->max_mtu = CANXL_MTU;
>>       can_set_ml_priv(dev, netdev_priv(dev));
>>       vcan_set_cap_info(dev);
> 
> In such example, please don't add parasite white space changes. It makes
> it hard to grasp what you are actually modifying.

Agreed. As I wrote above - it does not even compile and was never 
intended to be used as upstream code.

(..)

>> -void can_setup(struct net_device *dev);
>> +void can_setup(struct net_device *dev)
>> +{
>> +    dev->type = ARPHRD_CAN;
>> +    dev->mtu = CAN_MTU;
>> +    dev->min_mtu = CAN_MTU;
>> +    dev->max_mtu = CAN_MTU;
>> +    dev->hard_header_len = 0;
>> +    dev->addr_len = 0;
>> +
>> +    /* New-style flags. */
>> +    dev->flags = IFF_NOARP;
>> +    dev->features = NETIF_F_HW_CSUM;
>> +}
> 
> It is strange to have a non static inline function in a header. What was
> the motivation for pulling this out of dev.c?

Yeah. My thought was that we might reduce code duplication when we 
provice more granularity in those helper functions.

I moved it to dev.h to avoid the building of dev.c for the virtual CAN 
interfaces.

Best regards,
Oliver


  reply	other threads:[~2026-08-06 12:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 19:55 [PATCH 0/4] can: automate IFF_ECHO flag for generic echo skbs Vincent Mailhol
2026-08-04 19:55 ` [PATCH 1/4] can: slcan: do not allocate unused echo skb Vincent Mailhol
2026-08-04 19:55 ` [PATCH 2/4] can: fix IFF_ECHO example in documentation Vincent Mailhol
2026-08-05  6:08   ` Oliver Hartkopp
2026-08-04 19:55 ` [PATCH 3/4] can: dev: set IFF_ECHO when allocating echo skbs Vincent Mailhol
2026-08-04 19:55 ` [PATCH 4/4] can: treewide: remove redundant IFF_ECHO assignments Vincent Mailhol
2026-08-05  6:29 ` [PATCH 0/4] can: automate IFF_ECHO flag for generic echo skbs Oliver Hartkopp
2026-08-05  7:25   ` Vincent Mailhol
2026-08-05 16:17     ` Oliver Hartkopp
2026-08-05 21:06       ` Vincent Mailhol
2026-08-06 12:01         ` Oliver Hartkopp [this message]
2026-08-06 20:55           ` Vincent Mailhol
2026-08-07 10:56             ` Oliver Hartkopp
2026-08-07 11:52               ` Vincent Mailhol
2026-08-10 18:07                 ` Oliver Hartkopp

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=d045b536-efd0-40a6-8357-e04c9db9236b@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    /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