SocketCAN device mapping to hardware CAN port

This forum covers PCAN-Linux and Linux development issues concerning our products
Locked
bernhard.hoeckner
Posts: 4
Joined: Tue 17. Nov 2020, 11:38

SocketCAN device mapping to hardware CAN port

Post by bernhard.hoeckner » Tue 17. Nov 2020, 12:01

Hi,

until now i had a single PCI Express Peak CAN device which i use with the kernel main line driver and SocketCan. This works pretty smooth!

Now we add another physically separated CAN bus which results either in two PCI Express CAN cards or in one PCI Express CAN card with two ports.

How can i now ensure that a certain SocketCAN network device (e.g. can0) is consitently mapped to the same hardware CAN port?

cheers,
Bernhard

M.Maidhof
Support
Support
Posts: 1751
Joined: Wed 22. Sep 2010, 14:00

Re: SocketCAN device mapping to hardware CAN port

Post by M.Maidhof » Tue 17. Nov 2020, 13:24

Hi,

when using the main line kernel driver with two different cards, it is not safe that the SocketCAN network device is consistently mapped to the same hardware port. In that case the use of the peak-linux-driver in Netdev mode and using the assign parameter to fix the devices to a given device number of the card will be an option. See manual of the peak-linux-driver for more details:

http://www.peak-system.com/fileadmin/me ... an_eng.pdf

AFAIK using a two channel card with the main line kernel driver should also work without mixing canX devices during different bootups.

regards

Michael

bernhard.hoeckner
Posts: 4
Joined: Tue 17. Nov 2020, 11:38

Re: SocketCAN device mapping to hardware CAN port

Post by bernhard.hoeckner » Fri 27. Nov 2020, 15:07

Hi,

some more questions came up regarding your answer:

Regarding two different cards:
when using the main line kernel driver with two different cards, it is not safe that the SocketCAN network device is consistently mapped to the same hardware port.
Would checking the PCI bus mappings and having according Udev rules help?

* show pci bus mappings for peak adapter:

Code: Select all

lspci | grep -ni peak
* show network device mapping to pci bus id:

Code: Select all

ls -la /sys/class/net/

Code: Select all

ls -la /sys/class/net/ | grep can
----

Regarding mainline driver/netdev-mode:
In that case the use of the peak-linux-driver in Netdev mode and using the assign parameter to fix the devices to a given device number of the card will be an option
Our application is build around using SocketCAN. So we would like to continue using this.

PCAN-Driver-Linux_UserMan_eng 4.8 sounds like i can use the peak-linux-driver in netdev mode as a drop-in for the mainline driver with SocketCAN. Is this true?

PCAN-Driver-Linux_UserMan_eng 4.8 mentions:
Since kernel version 3.6, the netdev interface with all of the PEAK-System PC CAN interfaces is natively included in the mainline kernel. So, there is no need to install the PCAN driver for Linux when planning to use the SocketCAN interface in applications.
Is there a way to use the "assign parameter" you mentioned via the mainline kernel as well?

If this is answered in PCAN-Driver-Linux_UserMan_eng 4.8, i will read it some more :)

Thx, Bernhard

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: SocketCAN device mapping to hardware CAN port

Post by M.Heidemann » Fri 27. Nov 2020, 16:15

Hello,

We would recommend to use either a two channel card, as
it will not reiterate devices to our knowledge or to use the NetDev-variant of our PCAN-Linux driver.

We don't know if your proposed solution could worked, as we have not tested this and cannot conclusively answer this.

Yes, the PCAN-Linux driver built in NetDev mode is a defacto stand-in for the mainline-driver with additonal features, such as the assign-parameter, hence why my colleague Michael suggested this as a solution.

The assign-parameter is described in detail in chapter 4.8 of the PCAN-Linux driver documentation:

http://www.peak-system.com/fileadmin/me ... an_eng.pdf

For the assign-parameter to work a device-id has to be set, the following forum thread showcases this:

viewtopic.php?f=7&t=1861&p=5423&hilit=devid#p5423

Here a little example using the pcan-settings utility:

Make sure you use the assign paramter for every available channel, the channels come up as, for example, pcanpci32 -33 (using „cat /proc/pcan“):

You can check the current device ID like this (from the driver directory):

sudo test/pcan-settings -f=/dev/pcanpci32 -d

The next step would be assigning a DeviceID to each device (from the driver directory):

sudo test/pcan-settings -f=/dev/pcanpci32 -d=0
sudo test/pcan-settings -f=/dev/pcanpci33 -d=1

etc ..

Afterwards just add the line:

options pcan assign=devid

in /etc/modprobe.d/pcan.conf with your text-editor,
like it is described in the forum post.

On next startup the channels will be assigned to the device ID you have set before.

For further questions, feel free to conact me again.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

bernhard.hoeckner
Posts: 4
Joined: Tue 17. Nov 2020, 11:38

Re: SocketCAN device mapping to hardware CAN port

Post by bernhard.hoeckner » Mon 30. Nov 2020, 16:12

hi,

Sorry for my slow comprehension ;)
  • in case of two seperate Peak PCI CAN cards
    • we should use the PCAN-Linux driver in NetDev mode, and use the assign-parameter by setting the device-id for the single-channel cards as we need them.
  • in case of a two channel Peak PCI CAN card, we have two options:
    • we can use the PCAN-Linux driver in NetDev mode and use the assign-parameter by setting the device-id for the single-channel cards as we need them.
    • we continue using the main-line kernel driver, and the channels should not mix the canX mapping per boot.
Either way, we can continue using SocketCAN as main API.

---

So to conclude:
As our preferred option is to use a two-channel Peak PCI CAN card, we can continue to use the main-line kernel driver, and should not expect any mixing of the mapping.

Thanks for your support!

Bernhard

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: SocketCAN device mapping to hardware CAN port

Post by M.Heidemann » Mon 30. Nov 2020, 16:22

Hello,

Yes, to our knowledge this is the easiest approach and the channel should not be mixed up on the same device.

You still can use the proprietary PCAN-Linux driver and the "assign-parameter" for the unlikely case that an issue does arise with this solution.

Either solution will support the use of SocketCAN.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

bernhard.hoeckner
Posts: 4
Joined: Tue 17. Nov 2020, 11:38

Re: SocketCAN device mapping to hardware CAN port

Post by bernhard.hoeckner » Mon 30. Nov 2020, 16:24

Perfect!

Awesome support, thanks for your help!

Bernhard

Locked