From 564178a05a8223885cb625c445579c244c4bf382 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Sun, 4 Aug 2019 00:38:38 -0700 Subject: [PATCH] Automatically select port upstream of device when necessary --- scripts/pcie_set_speed.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/pcie_set_speed.sh b/scripts/pcie_set_speed.sh index e59b348d7..988dc6abc 100755 --- a/scripts/pcie_set_speed.sh +++ b/scripts/pcie_set_speed.sh @@ -17,11 +17,13 @@ if [ ! -e "/sys/bus/pci/devices/$dev" ]; then exit 1 fi +pciec=$(setpci -s $dev CAP_EXP+02.W) +pt=$((("0x$pciec" & 0xF0) >> 4)) + port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev"))) -if [[ $port != pci* ]]; then - echo "Note: it may be necessary to run this on the corresponding upstream port" - echo "Device $dev is connected to upstream port $port" +if (($pt == 0)) || (($pt == 1)) || (($pt == 5)); then + dev=$port fi lc=$(setpci -s $dev CAP_EXP+0c.L)