Udev-based serial number dependent symlinks for PCIe UIO devices

I'm working at a system, where a server manages multiple PCIe data acquisition cards. Each card has its individual serial number available in the extended PCIe configuration space. The cards are controlled as UIO devices. Unfortunately, it appears that the card are sometimes enumerated in the random order. Proper management of the system requires that there are symlinks created with names permanently associated with the individual cards. Of course, I wanted to use udev for that purpose. Unfortunately, udev does not provide the Device Serial Number capability between the device attributes. The DSN may be read with "lspci -vvv":

[...] Capabilities: [100 v1] Device Serial Number 12-34-56-78-90-ab-cd-ef [...]

My solution consists of two parts.

  1. The udev rule (file: /etc/udev/rules.d/30-daq.rules) =========== SUBSYSTEM=="uio" PROGRAM="/opt/bin/uio_namer" SYMLINK="%c" ===========
  2. The program that is run for each found uio device and: a. Checks if it is our board (end returns non-zero status if it is not) b. Outputs the name of the desired symlink to the standard output and returns 0 status when it is our device. I have implemented it fully in bash. Of course it can be implemented in C using the libpci, or in Python. The program receives the information from udev in the environment variables. The most important is DEVPATH.

(file: /opt/bin/uio_namer) ======================= #!/bin/sh DEVID=abba:3342 SLOTNAME=`basename \`readlink /sys/${DEVPATH}/device\`` DLSPCI=`lspci -vvv -s ${SLOTNAME}` #Check if it is our device if [ -z "`echo ${DLSPCI} | grep Device | grep ${DEVID}`" ] ; then # It is not our device exit 1 fi DSNCAP=`lspci -vvv -s ${SLOTNAME} | grep "Device Serial Number" ` echo daq/${DSNCAP##*" "} ========================

For recognized boards, the device files are created in the /dev/daq directory as the board's serial numbers. For example: /dev/daq/12-34-56-78-90-ab-cd-ef

I hope that the above solution may be useful for others as well. With best regards, Wojtek

Reply to
Wojciech Zabolotny
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.