Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Real Programmers think better when playing Adventure or Rogue.


devel / comp.arch.embedded / Re: Udev-based serial number dependent symlinks for PCIe UIO devices

SubjectAuthor
* Udev-based serial number dependent symlinks for PCIe UIO devicesWojciech Zabolotny
`* Re: Udev-based serial number dependent symlinks for PCIe UIO devicesDon Y
 `* Re: Udev-based serial number dependent symlinks for PCIe UIO devicesTheo
  `* Re: Udev-based serial number dependent symlinks for PCIe UIO devicesDon Y
   `- Re: Udev-based serial number dependent symlinks for PCIe UIO devicesWojciech Zabolotny

1
Udev-based serial number dependent symlinks for PCIe UIO devices

<3105b67e-544d-476f-89e1-89bd2b6fb77dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=461&group=comp.arch.embedded#461

  copy link   Newsgroups: comp.arch.embedded
X-Received: by 2002:ac8:4e3a:: with SMTP id d26mr7134142qtw.32.1621372655734;
Tue, 18 May 2021 14:17:35 -0700 (PDT)
X-Received: by 2002:a25:ae24:: with SMTP id a36mr10521438ybj.97.1621372655524;
Tue, 18 May 2021 14:17:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch.embedded
Date: Tue, 18 May 2021 14:17:35 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=95.160.103.141; posting-account=9fBPtgoAAADEI8zwcnuogZ04nxC8bclF
NNTP-Posting-Host: 95.160.103.141
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3105b67e-544d-476f-89e1-89bd2b6fb77dn@googlegroups.com>
Subject: Udev-based serial number dependent symlinks for PCIe UIO devices
From: wza...@gmail.com (Wojciech Zabolotny)
Injection-Date: Tue, 18 May 2021 21:17:35 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Wojciech Zabolotny - Tue, 18 May 2021 21:17 UTC

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

Re: Udev-based serial number dependent symlinks for PCIe UIO devices

<s8239g$fc8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=462&group=comp.arch.embedded#462

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: blockedo...@foo.invalid (Don Y)
Newsgroups: comp.arch.embedded
Subject: Re: Udev-based serial number dependent symlinks for PCIe UIO devices
Date: Tue, 18 May 2021 21:13:23 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <s8239g$fc8$1@dont-email.me>
References: <3105b67e-544d-476f-89e1-89bd2b6fb77dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 19 May 2021 04:13:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267984be5faaebda6c34f798e9856c05";
logging-data="15752"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+c6pIoOdKar3rKMhSzJ+er"
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101
Thunderbird/52.1.1
Cancel-Lock: sha1:UyF3Cmi09qlnMN8koKPZdy2Np78=
In-Reply-To: <3105b67e-544d-476f-89e1-89bd2b6fb77dn@googlegroups.com>
Content-Language: en-US
 by: Don Y - Wed, 19 May 2021 04:13 UTC

On 5/18/2021 2:17 PM, Wojciech Zabolotny wrote:
> 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.

[I don't run Linux, so...]

Can't you adjust the kernel configuration so that it forces
certain probes to yield certain "devices"?

E.g., instead of letting NetBSD probe disk drives in whatever order
it encounters them -- and assigning device names in that order -- I
build my kernels so certain device names are set aside for specific
devices (which may or may not be present at any given boot).

So, the first "free" probed device might be /dev/xx4 instead of
/dev/xx0 -- because I want to ensure /dev/xx0 is available for
a *specific* device instead of letting it go to the "first one
found".

Re: Udev-based serial number dependent symlinks for PCIe UIO devices

<Aqf*Tmtky@news.chiark.greenend.org.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=463&group=comp.arch.embedded#463

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!news.niel.me!nntp.terraraq.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!.POSTED!not-for-mail
From: theom+n...@chiark.greenend.org.uk (Theo)
Newsgroups: comp.arch.embedded
Subject: Re: Udev-based serial number dependent symlinks for PCIe UIO devices
Date: 19 May 2021 09:30:46 +0100 (BST)
Organization: University of Cambridge, England
Lines: 27
Message-ID: <Aqf*Tmtky@news.chiark.greenend.org.uk>
References: <3105b67e-544d-476f-89e1-89bd2b6fb77dn@googlegroups.com> <s8239g$fc8$1@dont-email.me>
NNTP-Posting-Host: chiark.greenend.org.uk
X-Trace: chiark.greenend.org.uk 1621413048 2818 212.13.197.229 (19 May 2021 08:30:48 GMT)
X-Complaints-To: abuse@chiark.greenend.org.uk
NNTP-Posting-Date: Wed, 19 May 2021 08:30:48 +0000 (UTC)
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (Linux/3.16.0-7-amd64 (x86_64))
Originator: theom@chiark.greenend.org.uk ([212.13.197.229])
 by: Theo - Wed, 19 May 2021 08:30 UTC

Don Y <blockedofcourse@foo.invalid> wrote:
> Can't you adjust the kernel configuration so that it forces
> certain probes to yield certain "devices"?
>
> E.g., instead of letting NetBSD probe disk drives in whatever order
> it encounters them -- and assigning device names in that order -- I
> build my kernels so certain device names are set aside for specific
> devices (which may or may not be present at any given boot).

That's what udev does. udev has a set of rules that indicate how devices
should be turned into device nodes, be it by physical location (PCI slot),
vendor/product ID, serial number, etc. It also sets ownership and
permissions of those device nodes (so only certain users can access a
device node). It handles creating and removing device nodes as devices are
hot plugged. It's all just some textual config files, no kernel compilation
needed.

The problem in this case is that PCI devices don't as standard support a
serial number in the way that USB or SATA does, and so this manufacturer has
done their own thing in the way the serial number is embedded. That is why
some helper code is needed to expose the serial number to udev to use in its
device naming.

(although I would have expected a rule that sets up device nodes named by
PCI slot to be equally predictable)

Theo

Re: Udev-based serial number dependent symlinks for PCIe UIO devices

<s82jjh$9q6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=464&group=comp.arch.embedded#464

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: blockedo...@foo.invalid (Don Y)
Newsgroups: comp.arch.embedded
Subject: Re: Udev-based serial number dependent symlinks for PCIe UIO devices
Date: Wed, 19 May 2021 01:51:45 -0700
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <s82jjh$9q6$1@dont-email.me>
References: <3105b67e-544d-476f-89e1-89bd2b6fb77dn@googlegroups.com>
<s8239g$fc8$1@dont-email.me> <Aqf*Tmtky@news.chiark.greenend.org.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 19 May 2021 08:52:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267984be5faaebda6c34f798e9856c05";
logging-data="10054"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1ukfG6ChLEK9HNSyu7VQR"
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101
Thunderbird/52.1.1
Cancel-Lock: sha1:DuOYjIE81nvSnr/tRnI3dfqLwRM=
In-Reply-To: <Aqf*Tmtky@news.chiark.greenend.org.uk>
Content-Language: en-US
 by: Don Y - Wed, 19 May 2021 08:51 UTC

On 5/19/2021 1:30 AM, Theo wrote:
> Don Y <blockedofcourse@foo.invalid> wrote:
>> Can't you adjust the kernel configuration so that it forces
>> certain probes to yield certain "devices"?
>>
>> E.g., instead of letting NetBSD probe disk drives in whatever order
>> it encounters them -- and assigning device names in that order -- I
>> build my kernels so certain device names are set aside for specific
>> devices (which may or may not be present at any given boot).
>
> That's what udev does. udev has a set of rules that indicate how devices
> should be turned into device nodes, be it by physical location (PCI slot),
> vendor/product ID, serial number, etc. It also sets ownership and
> permissions of those device nodes (so only certain users can access a
> device node).

OK. In NetBSD, that's part of the kernel configuration.
Things like permissions and device types (char vs block)
are handled in reasonably static files:

---------
device-major ccd char 300 block 300 ccd
device-major vnd char 301 block 301 vnd
device-major md char 302 block 302 md
device-major ld char 303 block 303 ld
device-major raid char 304 block 304 raid
device-major cgd char 305 block 305 cgd

# scsibus and its children
device-major scsibus char 310 scsibus
device-major sd char 311 block 311 sd
device-major st char 312 block 312 st
device-major cd char 313 block 313 cd
device-major ch char 314 ch
device-major ss char 315 ss
device-major uk char 316 uk
device-major ses char 317 ses
device-major se char 318 se

device-major fd char 320 block 320 fdc
....
device-major com char 260 com
device-major lpt char 261 lpt
....
-------

while the binding of device identifiers is part of the "config"
file:

------
# SCSI devices
sd* at scsibus? target ? lun ? # SCSI disk drives
st* at scsibus? target ? lun ? # SCSI tape drives
cd* at scsibus? target ? lun ? # SCSI CD-ROM drives
ch* at scsibus? target ? lun ? # SCSI autochangers
ses* at scsibus? target ? lun ? # SCSI Enclosure Services devices
ss* at scsibus? target ? lun ? # SCSI scanners
uk* at scsibus? target ? lun ? # SCSI unknown
----

E.g., in the above, I could ensure sd3 was always a particular
device on a particular scsibus at a particular SCSI ID by
creating an entry with the various wildcards (? *) replaced
by specific values. The probe will preallocate those so
they aren't assigned to some other device that happened
to be Nth in order of detection.

> It handles creating and removing device nodes as devices are
> hot plugged. It's all just some textual config files, no kernel compilation
> needed.
>
> The problem in this case is that PCI devices don't as standard support a
> serial number in the way that USB or SATA does, and so this manufacturer has
> done their own thing in the way the serial number is embedded. That is why
> some helper code is needed to expose the serial number to udev to use in its
> device naming.

Ah. I'd have thought an alternative would just be to ensure devices
of that specific *type* (manufacturer) were probed in an order that
could be enforced by the equivalent of the scheme I mentioned above.

> (although I would have expected a rule that sets up device nodes named by
> PCI slot to be equally predictable)

I guess one unanswered question is whether Wojciech is bolting his solution
onto an existing system *or* designing a system from scratch (in which case,
you would assume he could exercise some control over how the hardware is
"built"/pieced together)

Re: Udev-based serial number dependent symlinks for PCIe UIO devices

<1f482843-f180-445a-8b33-c9bede407b08n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=465&group=comp.arch.embedded#465

  copy link   Newsgroups: comp.arch.embedded
X-Received: by 2002:a0c:ef45:: with SMTP id t5mr12157781qvs.26.1621418395784;
Wed, 19 May 2021 02:59:55 -0700 (PDT)
X-Received: by 2002:a25:6f85:: with SMTP id k127mr14712397ybc.270.1621418395449;
Wed, 19 May 2021 02:59:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.swapon.de!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch.embedded
Date: Wed, 19 May 2021 02:59:55 -0700 (PDT)
In-Reply-To: <s82jjh$9q6$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=95.160.103.141; posting-account=9fBPtgoAAADEI8zwcnuogZ04nxC8bclF
NNTP-Posting-Host: 95.160.103.141
References: <3105b67e-544d-476f-89e1-89bd2b6fb77dn@googlegroups.com>
<s8239g$fc8$1@dont-email.me> <Aqf*Tmtky@news.chiark.greenend.org.uk> <s82jjh$9q6$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1f482843-f180-445a-8b33-c9bede407b08n@googlegroups.com>
Subject: Re: Udev-based serial number dependent symlinks for PCIe UIO devices
From: wza...@gmail.com (Wojciech Zabolotny)
Injection-Date: Wed, 19 May 2021 09:59:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5369
 by: Wojciech Zabolotny - Wed, 19 May 2021 09:59 UTC

środa, 19 maja 2021 o 10:52:06 UTC+2 Don Y napisał(a):
> On 5/19/2021 1:30 AM, Theo wrote:
> > Don Y <blocked...@foo.invalid> wrote:
> >> Can't you adjust the kernel configuration so that it forces
> >> certain probes to yield certain "devices"?
> >>
> >> E.g., instead of letting NetBSD probe disk drives in whatever order
> >> it encounters them -- and assigning device names in that order -- I
> >> build my kernels so certain device names are set aside for specific
> >> devices (which may or may not be present at any given boot).
> >
> > That's what udev does. udev has a set of rules that indicate how devices
> > should be turned into device nodes, be it by physical location (PCI slot),
> > vendor/product ID, serial number, etc. It also sets ownership and
> > permissions of those device nodes (so only certain users can access a
> > device node).
> OK. In NetBSD, that's part of the kernel configuration.
> Things like permissions and device types (char vs block)
> are handled in reasonably static files:
>
> ---------
> device-major ccd char 300 block 300 ccd
> device-major vnd char 301 block 301 vnd
> device-major md char 302 block 302 md
> device-major ld char 303 block 303 ld
> device-major raid char 304 block 304 raid
> device-major cgd char 305 block 305 cgd
>
> # scsibus and its children
> device-major scsibus char 310 scsibus
> device-major sd char 311 block 311 sd
> device-major st char 312 block 312 st
> device-major cd char 313 block 313 cd
> device-major ch char 314 ch
> device-major ss char 315 ss
> device-major uk char 316 uk
> device-major ses char 317 ses
> device-major se char 318 se
>
> device-major fd char 320 block 320 fdc
> ...
> device-major com char 260 com
> device-major lpt char 261 lpt
> ...
> -------
>
> while the binding of device identifiers is part of the "config"
> file:
>
> ------
> # SCSI devices
> sd* at scsibus? target ? lun ? # SCSI disk drives
> st* at scsibus? target ? lun ? # SCSI tape drives
> cd* at scsibus? target ? lun ? # SCSI CD-ROM drives
> ch* at scsibus? target ? lun ? # SCSI autochangers
> ses* at scsibus? target ? lun ? # SCSI Enclosure Services devices
> ss* at scsibus? target ? lun ? # SCSI scanners
> uk* at scsibus? target ? lun ? # SCSI unknown
> ----
>
> E.g., in the above, I could ensure sd3 was always a particular
> device on a particular scsibus at a particular SCSI ID by
> creating an entry with the various wildcards (? *) replaced
> by specific values. The probe will preallocate those so
> they aren't assigned to some other device that happened
> to be Nth in order of detection.
> > It handles creating and removing device nodes as devices are
> > hot plugged. It's all just some textual config files, no kernel compilation
> > needed.
> >
> > The problem in this case is that PCI devices don't as standard support a
> > serial number in the way that USB or SATA does, and so this manufacturer has
> > done their own thing in the way the serial number is embedded. That is why
> > some helper code is needed to expose the serial number to udev to use in its
> > device naming.
> Ah. I'd have thought an alternative would just be to ensure devices
> of that specific *type* (manufacturer) were probed in an order that
> could be enforced by the equivalent of the scheme I mentioned above.
> > (although I would have expected a rule that sets up device nodes named by
> > PCI slot to be equally predictable)
> I guess one unanswered question is whether Wojciech is bolting his solution
> onto an existing system *or* designing a system from scratch (in which case,
> you would assume he could exercise some control over how the hardware is
> "built"/pieced together)

The end user wants to be able to run it on standard Debian GNU/Linux OS.

BR,
Wojtek

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor