重新排序多端口卡上的串行端口

重新排序多端口卡上的串行端口

我有一台 Red Hat Enterprise 6.2 机器,带有两个板载串行端口和一个带有 8 个附加串行端口的 PCIe 卡(16C950 UART,兼容 16C550)。我添加了内核选项8250.nr_uarts=10,以便所有设备都显示在/dev.

正如预期的那样,两个板载设备显示为 ttyS0 和 ttyS1,但 PCIe 卡上的串行端口并未按其 I/O 端口排序,正如我所期望的那样。否则,设备工作正常,只是 tty 顺序与主板分支电缆上的顺序不匹配,这不太优雅。关于如何更改顺序有什么想法吗?

输出形式setserial

# setserial -g /dev/ttyS*
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: 16650, Port: 0xdf30, IRQ: 30
/dev/ttyS3, UART: 16650, Port: 0xdf38, IRQ: 30
/dev/ttyS4, UART: 16650, Port: 0xdf00, IRQ: 30      <-- Why is this one not ttyS2?
/dev/ttyS5, UART: 16650, Port: 0xdf08, IRQ: 30
/dev/ttyS6, UART: 16650, Port: 0xdf10, IRQ: 30
/dev/ttyS7, UART: 16650, Port: 0xdf18, IRQ: 30
/dev/ttyS8, UART: 16650, Port: 0xdf20, IRQ: 30
/dev/ttyS9, UART: 16650, Port: 0xdf28, IRQ: 30

查看dmesg,它以正确的顺序找到它们,但从 ttyS4 开始最低的 I/O 端口:

# dmesg | grep ttyS
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
00:06: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
00:07: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
0000:05:00.0: ttyS4 at I/O 0xdf00 (irq = 30) is a ST16650
0000:05:00.0: ttyS5 at I/O 0xdf08 (irq = 30) is a ST16650
0000:05:00.0: ttyS6 at I/O 0xdf10 (irq = 30) is a ST16650
0000:05:00.0: ttyS7 at I/O 0xdf18 (irq = 30) is a ST16650
0000:05:00.0: ttyS8 at I/O 0xdf20 (irq = 30) is a ST16650
0000:05:00.0: ttyS9 at I/O 0xdf28 (irq = 30) is a ST16650
0000:05:00.0: ttyS2 at I/O 0xdf30 (irq = 30) is a ST16650
0000:05:00.0: ttyS3 at I/O 0xdf38 (irq = 30) is a ST16650

尝试使用setserial更改端口似乎不起作用,它总是报告设备正忙(这是从重新启动开始的,没有任何东西访问设备)。

# setserial /dev/ttyS2 port 0xdf00
Cannot set serial info: Device or resource busy

编辑:感谢 Gilles 提供的信息,我现在主要使用 udev 来工作,该 udev 编写了一个有序的姓名通过匹配核心姓名。 info的输出udevadm显示这是唯一可用于唯一标识各个设备的参数(ttyS[2-9] 都报告相同的信息,除了核心范围)。

# udevadm info -a -n /dev/ttyS2
  looking at device '/devices/pci0000:00/0000:00:07.0/0000:05:00.0/tty/ttyS2':
    KERNEL=="ttyS2"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:07.0/0000:05:00.0':
    KERNELS=="0000:05:00.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="serial"
    ATTRS{vendor}=="0x494f"
    ATTRS{device}=="0x10a9"
    ATTRS{subsystem_vendor}=="0x0000"
    ATTRS{subsystem_device}=="0x0000"
    ATTRS{class}=="0x070002"
    ATTRS{irq}=="30"
    ATTRS{local_cpus}=="0000ff"
    ATTRS{local_cpulist}=="0-7"

我的新 udev 规则:

SUBSYSTEM=="tty", DRIVERS=="serial", ATTRS{vendor}=="0x494f", KERNEL=="ttyS4", NAME="ttyS2"
# [snipped 7 more rules for each device]

答案1

您应该能够使用以下命令更改设备名称乌德夫规则。跑步udevadm info -a -n /dev/ttyS2获取您的设备的特性。查找唯一标识多端口卡的属性以及标识端口的一个属性。然后为每个端口编写udev规则。规则可能如下所示:

SUBSYSTEM=="tty", DRIVERS=="serial", ATTRS{vendor}=="Yoyodyne", ATTRS{port}=="0xdf00", NAME="ttyS2"
SUBSYSTEM=="tty", DRIVERS=="serial", ATTRS{vendor}=="Yoyodyne", ATTRS{port}=="0xdf80", NAME="ttyS3"

跑步udevadm trigger(使用正确的--attr-match-…选项)将规则重新应用到已连接的设备。

相关内容