-
Notifications
You must be signed in to change notification settings - Fork 74
/
netdev-pci-speed
executable file
·44 lines (41 loc) · 1.32 KB
/
netdev-pci-speed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
set -eu
DEVICE="$1"
if [ ! -d /sys/class/net/$DEVICE ]; then
echo "No such device $DEVICE"
exit 2
fi
BUS_ADDR="$(ethtool -i "$DEVICE" | grep bus | awk '{print $2}')"
DEV_SPEED="$(ethtool "$DEVICE" | grep Speed | egrep -o [0-9]+)"
if ! PCI_TYPE="$(dmidecode --type slot | grep -B6 "${BUS_ADDR%.*}" | egrep -m1 -o 'PCI Express [0-9] x[0-9]+')"; then
echo "$DEVICE is probably built-in"
exit 1
fi
read _ _ VERSION X <<< "$PCI_TYPE"
if [ "$VERSION" = '1' ]; then
[ "$X" = 'x1' ] && SLOT_SPEED=250
[ "$X" = 'x2' ] && SLOT_SPEED=500
[ "$X" = 'x4' ] && SLOT_SPEED=1000
[ "$X" = 'x8' ] && SLOT_SPEED=2000
[ "$X" = 'x16' ] && SLOT_SPEED=4000
elif [ "$VERSION" = '2' ]; then
[ "$X" = 'x1' ] && SLOT_SPEED=500
[ "$X" = 'x2' ] && SLOT_SPEED=1000
[ "$X" = 'x4' ] && SLOT_SPEED=2000
[ "$X" = 'x8' ] && SLOT_SPEED=4000
[ "$X" = 'x16' ] && SLOT_SPEED=8000
elif [ "$VERSION" = '3' ]; then
[ "$X" = 'x1' ] && SLOT_SPEED=984
[ "$X" = 'x2' ] && SLOT_SPEED=1970
[ "$X" = 'x4' ] && SLOT_SPEED=3940
[ "$X" = 'x8' ] && SLOT_SPEED=7880
[ "$X" = 'x16' ] && SLOT_SPEED=15800
elif [ "$VERSION" = '4' ]; then
[ "$X" = 'x1' ] && SLOT_SPEED=1969
[ "$X" = 'x2' ] && SLOT_SPEED=3940
[ "$X" = 'x4' ] && SLOT_SPEED=7880
[ "$X" = 'x8' ] && SLOT_SPEED=15750
[ "$X" = 'x16' ] && SLOT_SPEED=31500
fi
echo "$DEVICE $DEV_SPEED/$((SLOT_SPEED*8))"
exit 0