Skip to content

Instantly share code, notes, and snippets.

@LeTink
Last active September 19, 2018 19:41
Show Gist options
  • Save LeTink/beccc9b7cc465263819e50bd0fbf0a54 to your computer and use it in GitHub Desktop.
Save LeTink/beccc9b7cc465263819e50bd0fbf0a54 to your computer and use it in GitHub Desktop.
set USB3 back to USB2
One of our standard hardware classes doesn't handle a large number (32) of daisy-chained USB Serials well, it exhausts lanes.
As a workaround we set the capabilities of the USB port in question back to lower standards, which seems to do what we want.
# /etc/udev/rules.d/
# udev rules to go with set_usb2
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1a40", ATTR{idProduct}=="0201", TAG+="systemd", ENV{SYSTEMD_WANTS}="set_usb2.service"
# /etc/systemd/system/
[Unit]
Description=switch USB for serials to USB2
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/local/bin/set_usb2.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
# this goes in /usr/local/bin/
[ -h /sys/class/tty/ttyUSB0 ] || exit 1
pci_id=$( /usr/bin/realpath /sys/class/tty/ttyUSB0 | awk -F'/' '{print gensub(/....:(.*)/, "\\1","1",$5)}' )
usb_id=$( lspci -n| awk -v id=$pci_id '$0 ~ id {print $3}' )
/usr/bin/setpci -H1 -d $usb_id d0.l=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment