Page MenuHomeFreeBSD

Add USB support for location based device unit numbers
Needs ReviewPublic

Authored by hselasky on Thu, Oct 3, 12:02 PM.

Details

Summary

Add USB support for location based device unit numbers.

Sponsored by: Mellanox Technologies

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 26847

Event Timeline

hselasky created this revision.Thu, Oct 3, 12:02 PM
hselasky updated this revision to Diff 62870.Thu, Oct 3, 12:19 PM

Fix bug in uniq number compuation. Controller number must be last.

imp added a comment.Thu, Oct 3, 3:45 PM

Unit numbers are kinda lame. Wouldn't it be better to add aliases?

@imp: We can have both if the TTY layers support it.

Could you implement a tty_makedevalias() function ?

At least with this patch the sysctls are coherent, pointing to only one device.

There is people who expect the first serial device they plug-in to be ttyU0 (me for example) and there are people who would prefer the unit number to stay the same independent of the order the devices are detected (me as well).

I would prefer aliases as well, so we can have both. I didn't check whether it actually is a match to your problem, but how about tty_makealias() in sys/tty.h?

sys/tty.h-int tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
sys/tty.h- const char *fmt, ...) printflike(4, 5);
sys/tty.h-#define TTYMK_CLONING 0x1
sys/tty.h-#define tty_makedev(tp, cred, fmt, ...) \
sys/tty.h- (void )tty_makedevf((tp), (cred), 0, (fmt), __VA_ARGS__) sys/tty.h:#define tty_makealias(tp,fmt,...) \ sys/tty.h- make_dev_alias((tp)->t_dev, fmt,
VA_ARGS__)
sys/tty.h-
sys/tty.h-/* Signalling processes. */
sys/tty.h-void tty_signal_sessleader(struct tty *tp, int signal);
sys/tty.h-void tty_signal_pgrp(struct tty *tp, int signal);

I do remember from way back talks about naming schemes for USB devices in the USB device tree, something like usb-1-3-2 being a device plugged into port 2 of a hub that is plugged into port 3 of a hub plugged into port 1 of the root hub.

imp added a comment.Thu, Oct 3, 7:38 PM

There is people who expect the first serial device they plug-in to be ttyU0 (me for example) and there are people who would prefer the unit number to stay the same independent of the order the devices are detected (me as well).
I would prefer aliases as well, so we can have both. I didn't check whether it actually is a match to your problem, but how about tty_makealias() in sys/tty.h?
sys/tty.h-int tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
sys/tty.h- const char *fmt, ...) printflike(4, 5);
sys/tty.h-#define TTYMK_CLONING 0x1
sys/tty.h-#define tty_makedev(tp, cred, fmt, ...) \
sys/tty.h- (void )tty_makedevf((tp), (cred), 0, (fmt), __VA_ARGS__) sys/tty.h:#define tty_makealias(tp,fmt,...) \ sys/tty.h- make_dev_alias((tp)->t_dev, fmt,
VA_ARGS__)
sys/tty.h-
sys/tty.h-/* Signalling processes. */
sys/tty.h-void tty_signal_sessleader(struct tty *tp, int signal);
sys/tty.h-void tty_signal_pgrp(struct tty *tp, int signal);
I do remember from way back talks about naming schemes for USB devices in the USB device tree, something like usb-1-3-2 being a device plugged into port 2 of a hub that is plugged into port 3 of a hub plugged into port 1 of the root hub.

I'd prefer the alias stuff as well. I think we have what we need, but if not I'm happy to fix things that are broken.

There's a number of different ways to have the aliases setup, and at times code in ucom will be the answer, and other times code in devfs and/or devd might be better. The whole device_t vs dev_t stuff will get in the way here, I fear...

avg added a subscriber: avg.Fri, Oct 4, 1:23 PM

Why is this needed at all? What's the motivation?

@avg: It is needed for embedded, where for example tree USB modems control different things and you have apps that should connect to the same modem after boot.

avg added a comment.Fri, Oct 4, 9:24 PM

I see.
I think that the problem can be solved quite easily with devd, but maybe it's not good for embedded solutions.
Also, I am not sure how stable the unit numbers are going to be with respect to add-in USB controllers and external USB hubs.

I do not have any objections.

emaste added a subscriber: emaste.Tue, Oct 8, 2:16 PM
emaste added a comment.Tue, Oct 8, 3:06 PM

My use case for something like this is a USB-serial console server where I might have 16 different USB-serial adapters attached to various USB hubs; I intended to address it by using the serial number in each device.

@hselasky can you give an example of the unit numbers that would be generated by this patch?

avg added a comment.Tue, Oct 8, 3:16 PM

My use case for something like this is a USB-serial console server where I might have 16 different USB-serial adapters attached to various USB hubs; I intended to address it by using the serial number in each device.

Yes, I am doing something like that now.

attach 1001 {
        match "vendor"          "0x12d1";
        match "product"         "0x1506";
        action "ln -sf /dev/cua$ttyname.0 /dev/3g";
};

notify 1001 {
        match "system"          "USB";
        match "subsystem"       "DEVICE";
        match "type"            "DETACH";
        match "vendor"          "0x12d1";
        match "product"         "0x1506";
        action "unlink /dev/3g";
};

attach 1001 {
        match "vendor"          "0x2341";
        match "product"         "0x0043";
        action "ln -sf /dev/cua$ttyname /dev/arduino";
};

notify 1001 {
        match "system"          "USB";
        match "subsystem"       "DEVICE";
        match "type"            "DETACH";
        match "vendor"          "0x2341";
        match "product"         "0x0043";
        action "unlink /dev/arduino";
};

Requires manual configuration though.
At the same time, it's quite flexible.
Of course, totally identical devices (down to serial numbers) can still cause confusion.

emaste added a comment.Tue, Oct 8, 4:12 PM

Of course, totally identical devices (down to serial numbers) can still cause confusion.

Indeed; most of the cheap USB-serial adapters (e.g. the ones available on aliexpress.com for about $1 USD) have the same (often empty) serial number. I found that the cp210x devices can be reprogrammed. https://github.com/emaste/cp210x-cfg is my trivial FreeBSD port of a configuration tool I use to give them unique serial numbers.