All of lore.kernel.org
 help / color / mirror / Atom feed
* assignment of spi to can channels
@ 2020-12-16 10:43 Sven Schuchmann
  2020-12-16 13:26 ` Marc Kleine-Budde
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Schuchmann @ 2020-12-16 10:43 UTC (permalink / raw)
  To: linux-can

Hello,
I have a question regarding the assignment of spi to can channels.
At this time I see sometimes this:

[    6.665217] mcp251xfd spi0.0 can0: MCP2518FD rev0.0 (-RX_INT ...
[    6.675670] mcp251xfd spi1.0 can1: MCP2518FD rev0.0 (-RX_INT ...

and sometimes this:

[    6.612654] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_INT ...
[    6.623504] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_INT ...

Probably asked a thousand times but I did not find
a solution: How can I fix the assignment from spi0.0 to can0
and spi1.0 to can1?

   Sven



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: assignment of spi to can channels
  2020-12-16 10:43 assignment of spi to can channels Sven Schuchmann
@ 2020-12-16 13:26 ` Marc Kleine-Budde
  2020-12-16 15:05   ` Patrick Menschel
  2020-12-16 17:49   ` AW: " Sven Schuchmann
  0 siblings, 2 replies; 8+ messages in thread
From: Marc Kleine-Budde @ 2020-12-16 13:26 UTC (permalink / raw)
  To: Sven Schuchmann, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 2542 bytes --]

On 12/16/20 11:43 AM, Sven Schuchmann wrote:
> Hello,
> I have a question regarding the assignment of spi to can channels.
> At this time I see sometimes this:
> 
> [    6.665217] mcp251xfd spi0.0 can0: MCP2518FD rev0.0 (-RX_INT ...
> [    6.675670] mcp251xfd spi1.0 can1: MCP2518FD rev0.0 (-RX_INT ...
> 
> and sometimes this:
> 
> [    6.612654] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_INT ...
> [    6.623504] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_INT ...
> 
> Probably asked a thousand times but I did not find
> a solution: How can I fix the assignment from spi0.0 to can0
> and spi1.0 to can1?

The classic solution would be a udev rule in e.g. /etc/udev/rules.d/70-can.rules"

> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="mcp0"
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="mcp1"
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi2.0/net/can?", NAME="mcp2"
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi2.1/net/can?", NAME="mcp3"

Figure out the exact DEVPATH with

> udevadm test /sys/class/net/can0
> udevadm test /sys/class/net/can1

Note, with older versions of udev it was possible to rename interfaces within
the same namespace, e.g. use "NAME=can0". I think this doesn't work with newer
udevs anymore, so in this example "mcp?" is used.

The above udev-only approach is from some old documentation I found, but not
tested. I'm using the modern systemd approach...


The modern approach is to use systemd-networkd, this requires systemd > 246, as
the older versions don't have the chip select "-cs-" in the "Path".

/etc/systemd/network/70-mcp251xfd0.link:
> [Match]
> Driver=mcp251xfd
> # RPI3 RPI4
> Path=platform-3f204000.spi-cs-0 platform-fe204000.spi-cs-0
> 
> [Link]
> Name=mcp251xfd0

Again use "udevadm test /sys/class/net/can0", but the "Path" in the .link file
corresponds to ID_PATH from udevadm test. See "man systemd.link" for details.

And use this file to configure the CAN interface.

/etc/systemd/network/80-can.network:
> [Match]
> Name=mcp251x*
> 
> [CAN]
> BitRate=500K
> RestartSec=1s

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: assignment of spi to can channels
  2020-12-16 13:26 ` Marc Kleine-Budde
@ 2020-12-16 15:05   ` Patrick Menschel
  2020-12-16 17:49   ` AW: " Sven Schuchmann
  1 sibling, 0 replies; 8+ messages in thread
From: Patrick Menschel @ 2020-12-16 15:05 UTC (permalink / raw)
  To: Marc Kleine-Budde, Sven Schuchmann; +Cc: linux-can

Hi,

we had this topic 2 years ago [1] [2].
The udev solution was the winner but it was suggested to have unique
identifiers provided in the devicetree.
Sort of an equivalent to the predictable network device names.

[1]
https://lore.kernel.org/linux-devicetree/CAL_JsqKudVXevW2YdEPvbOgK4CoszjqKNvCDrvKx-iOqRj0KWg@mail.gmail.com/
[2] https://marc.info/?l=linux-can&m=153675634529327&w=2
--
Patrick


^ permalink raw reply	[flat|nested] 8+ messages in thread

* AW: assignment of spi to can channels
  2020-12-16 13:26 ` Marc Kleine-Budde
  2020-12-16 15:05   ` Patrick Menschel
@ 2020-12-16 17:49   ` Sven Schuchmann
  2020-12-16 20:27     ` Marc Kleine-Budde
  1 sibling, 1 reply; 8+ messages in thread
From: Sven Schuchmann @ 2020-12-16 17:49 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can

> -----Ursprüngliche Nachricht-----
> Von: Marc Kleine-Budde <mkl@pengutronix.de>
> Gesendet: Mittwoch, 16. Dezember 2020 14:27
> An: Sven Schuchmann <schuchmann@schleissheimer.de>; linux-can@vger.kernel.org
> Betreff: Re: assignment of spi to can channels
> 
> The classic solution would be a udev rule in e.g. /etc/udev/rules.d/70-can.rules"
> 
> > SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="mcp0"
> > SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="mcp1"
> > SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi2.0/net/can?", NAME="mcp2"
> > SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi2.1/net/can?", NAME="mcp3"
> 
> Figure out the exact DEVPATH with
> 
> > udevadm test /sys/class/net/can0
> > udevadm test /sys/class/net/can1
> 
> Note, with older versions of udev it was possible to rename interfaces within
> the same namespace, e.g. use "NAME=can0". I think this doesn't work with newer
> udevs anymore, so in this example "mcp?" is used.
> 
Since I am on systemd 241 on a RaspberryPi I decided to go for udev style

created /etc/udev/rules.d/70-can.rules with
SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="can0"
SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="can1"

and tadaaaaa:
[    6.917578] spi_master spi1: will run message pump with realtime priority
[    6.936957] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_...
[    6.956523] spi_master spi0: will run message pump with realtime priority
[    6.971942] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_...
[    7.006515] mcp251xfd spi1.0 rename3: renamed from can0
[    7.041681] mcp251xfd spi0.0 can0: renamed from can1
[    7.091563] mcp251xfd spi1.0 can1: renamed from rename3

Thank you Marc!

   Sven

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: AW: assignment of spi to can channels
  2020-12-16 17:49   ` AW: " Sven Schuchmann
@ 2020-12-16 20:27     ` Marc Kleine-Budde
  2020-12-16 22:11       ` AW: " Sven Schuchmann
  0 siblings, 1 reply; 8+ messages in thread
From: Marc Kleine-Budde @ 2020-12-16 20:27 UTC (permalink / raw)
  To: Sven Schuchmann, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 1545 bytes --]

On 12/16/20 6:49 PM, Sven Schuchmann wrote:
>> Note, with older versions of udev it was possible to rename interfaces within
>> the same namespace, e.g. use "NAME=can0". I think this doesn't work with newer
>> udevs anymore, so in this example "mcp?" is used.
>>
> Since I am on systemd 241 on a RaspberryPi I decided to go for udev style
> 
> created /etc/udev/rules.d/70-can.rules with
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="can0"
> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="can1"

Note: IFAIK this will not work with newer versions of udev....

> and tadaaaaa:
> [    6.917578] spi_master spi1: will run message pump with realtime priority
> [    6.936957] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_...
> [    6.956523] spi_master spi0: will run message pump with realtime priority
> [    6.971942] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_...
> [    7.006515] mcp251xfd spi1.0 rename3: renamed from can0
> [    7.041681] mcp251xfd spi0.0 can0: renamed from can1
> [    7.091563] mcp251xfd spi1.0 can1: renamed from rename3

...the "rename" trick doesn't work anymore. Better use a differnet name, e.g.:
mcp0 and mcp1.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* AW: AW: assignment of spi to can channels
  2020-12-16 20:27     ` Marc Kleine-Budde
@ 2020-12-16 22:11       ` Sven Schuchmann
  2020-12-17 14:11         ` Patrick Menschel
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Schuchmann @ 2020-12-16 22:11 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can

> -----Ursprüngliche Nachricht-----
> Von: Marc Kleine-Budde <mkl@pengutronix.de>
> Gesendet: Mittwoch, 16. Dezember 2020 21:27
> > created /etc/udev/rules.d/70-can.rules with
> > SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="can0"
> > SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="can1"
> 
> Note: IFAIK this will not work with newer versions of udev....
> 
> > and tadaaaaa:
> > [    6.917578] spi_master spi1: will run message pump with realtime priority
> > [    6.936957] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_...
> > [    6.956523] spi_master spi0: will run message pump with realtime priority
> > [    6.971942] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_...
> > [    7.006515] mcp251xfd spi1.0 rename3: renamed from can0
> > [    7.041681] mcp251xfd spi0.0 can0: renamed from can1
> > [    7.091563] mcp251xfd spi1.0 can1: renamed from rename3
> 
> ...the "rename" trick doesn't work anymore. Better use a differnet name, e.g.:
> mcp0 and mcp1.

okay, understood and renamed:
[    6.673732] mcp251xfd spi0.0 mcp0: renamed from can0
[    6.716051] mcp251xfd spi1.0 mcp1: renamed from can1

Thanks!

   Sven

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: assignment of spi to can channels
  2020-12-16 22:11       ` AW: " Sven Schuchmann
@ 2020-12-17 14:11         ` Patrick Menschel
  2020-12-23 13:29           ` Patrick Menschel
  0 siblings, 1 reply; 8+ messages in thread
From: Patrick Menschel @ 2020-12-17 14:11 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can

Hi Marc,

just curious.
Would it violate any conventions to set the netdevice name from the
device tree node name when calling alloc_candev() in mcp251xfd_probe()?

https://github.com/marckleinebudde/linux/blob/mcp251xfd-uinc/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c#L2821

The thing is, a dt overlay from a HAT eeprom would not provide the
necessary udev rules but it contains knowledge about the (connector)
name which could be set by the driver.

Thanks and Best Regards,

Patrick

[1]
https://lore.kernel.org/linux-devicetree/CAL_JsqKudVXevW2YdEPvbOgK4CoszjqKNvCDrvKx-iOqRj0KWg@mail.gmail.com/

Am 16.12.20 um 23:11 schrieb Sven Schuchmann:
>> -----Ursprüngliche Nachricht-----
>> Von: Marc Kleine-Budde <mkl@pengutronix.de>
>> Gesendet: Mittwoch, 16. Dezember 2020 21:27
>>> created /etc/udev/rules.d/70-can.rules with
>>> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="can0"
>>> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="can1"
>>
>> Note: IFAIK this will not work with newer versions of udev....
>>
>>> and tadaaaaa:
>>> [    6.917578] spi_master spi1: will run message pump with realtime priority
>>> [    6.936957] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_...
>>> [    6.956523] spi_master spi0: will run message pump with realtime priority
>>> [    6.971942] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_...
>>> [    7.006515] mcp251xfd spi1.0 rename3: renamed from can0
>>> [    7.041681] mcp251xfd spi0.0 can0: renamed from can1
>>> [    7.091563] mcp251xfd spi1.0 can1: renamed from rename3
>>
>> ...the "rename" trick doesn't work anymore. Better use a differnet name, e.g.:
>> mcp0 and mcp1.
> 
> okay, understood and renamed:
> [    6.673732] mcp251xfd spi0.0 mcp0: renamed from can0
> [    6.716051] mcp251xfd spi1.0 mcp1: renamed from can1
> 
> Thanks!
> 
>    Sven
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: assignment of spi to can channels
  2020-12-17 14:11         ` Patrick Menschel
@ 2020-12-23 13:29           ` Patrick Menschel
  0 siblings, 0 replies; 8+ messages in thread
From: Patrick Menschel @ 2020-12-23 13:29 UTC (permalink / raw)
  To: Marc Kleine-Budde, Sven Schuchmann; +Cc: linux-can

Bumping on this topic again. A

https://www.seeedstudio.com/CAN-BUS-FD-HAT-for-Raspberry-Pi-p-4742.html

arrived at my place today. I updated the rpi-0w-1 to latest official
packages and it turns out, everything found its way into release and
seems to be working fine.

There is one thing bugging me though, it runs on different SPIs then
Sven's board. My setup is

dtoverlay=mcp251xfd,spi0-0,interrupt=25
dtoverlay=mcp251xfd,spi0-1,interrupt=24

SUBSYSTEM=="net", ACTION=="add",
DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="mcp0"
SUBSYSTEM=="net", ACTION=="add",
DEVPATH=="/devices/platform/soc/*/*/*/spi0.1/net/can?", NAME="mcp1"


pi@rpi-0w-1:~ $ dmesg | grep -Ei can\|spi
[   30.107770] CAN device driver interface
[   30.280715] spi_master spi0: will run message pump with realtime priority
[   30.316946] mcp251xfd spi0.1 can0: MCP2518FD rev0.0 (-RX_INT
-MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:20.00MHz
r:17.00MHz e:0.00MHz) successfully initialized.
[   30.379053] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_INT
-MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:20.00MHz
r:17.00MHz e:0.00MHz) successfully initialized.
[   30.528401] mcp251xfd spi0.0 mcp0: renamed from can1
[   30.613025] mcp251xfd spi0.1 mcp1: renamed from can0


As it happens it runs on a rpi zero w . Is there some sort of stress
test I could run to see the platform limits?

--
Patrick


>>> -----Ursprüngliche Nachricht-----
>>> Von: Marc Kleine-Budde <mkl@pengutronix.de>
>>> Gesendet: Mittwoch, 16. Dezember 2020 21:27
>>>> created /etc/udev/rules.d/70-can.rules with
>>>> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi0.0/net/can?", NAME="can0"
>>>> SUBSYSTEM=="net", ACTION=="add", DEVPATH=="/devices/platform/soc/*/*/*/spi1.0/net/can?", NAME="can1"
>>>
>>> Note: IFAIK this will not work with newer versions of udev....
>>>
>>>> and tadaaaaa:
>>>> [    6.917578] spi_master spi1: will run message pump with realtime priority
>>>> [    6.936957] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_...
>>>> [    6.956523] spi_master spi0: will run message pump with realtime priority
>>>> [    6.971942] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_...
>>>> [    7.006515] mcp251xfd spi1.0 rename3: renamed from can0
>>>> [    7.041681] mcp251xfd spi0.0 can0: renamed from can1
>>>> [    7.091563] mcp251xfd spi1.0 can1: renamed from rename3
>>>
>>> ...the "rename" trick doesn't work anymore. Better use a differnet name, e.g.:
>>> mcp0 and mcp1.
>>
>> okay, understood and renamed:
>> [    6.673732] mcp251xfd spi0.0 mcp0: renamed from can0
>> [    6.716051] mcp251xfd spi1.0 mcp1: renamed from can1
>>
>> Thanks!
>>
>>    Sven
>>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-12-23 13:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 10:43 assignment of spi to can channels Sven Schuchmann
2020-12-16 13:26 ` Marc Kleine-Budde
2020-12-16 15:05   ` Patrick Menschel
2020-12-16 17:49   ` AW: " Sven Schuchmann
2020-12-16 20:27     ` Marc Kleine-Budde
2020-12-16 22:11       ` AW: " Sven Schuchmann
2020-12-17 14:11         ` Patrick Menschel
2020-12-23 13:29           ` Patrick Menschel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.