summaryrefslogtreecommitdiffstats
path: root/extras/scripts/lsnet
blob: 0e882ad89be3e4ad135e2e2a795074daa9205e2f (plain)
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
45
46
47
48
49
50
51
#!/bin/bash

declare -A IDS
IDS["8086:10fb"]="82599ES PF"
IDS["8086:1583"]="XL710 PF"
IDS["8086:158b"]="XXV710 PF"
IDS["8086:154c"]="XXV710 VF"
IDS["8086:37d1"]="X722 PF"
IDS["8086:37cd"]="X722 VF"
IDS["8086:1889"]="AVF"
IDS["8086:1593"]="E810 PF"
IDS["15b3:1015"]="CX-4 Lx PF"
IDS["15b3:1017"]="CX-5 PF"
IDS["15b3:1019"]="CX-5 Ex PF"

echo "PCI Address  N PCI-ID       Driver    MAC address       Device Name    State Speed      Port Type"
echo "============ = =========== ========== ================= ============== ===== ========== ===================="

for d in /sys/bus/pci/devices/*; do
  class=$(cat $d/class)
  [ "${class}" == "0x020000" ] || continue
  pci_addr=$(basename $d)
  numa=$(cat $d/numa_node)
  vid=$(cat $d/vendor | sed -e s/0x//g)
  did=$(cat $d/device| sed -e s/0x//g)
  pci_id=${IDS[$vid:$did]}

  [ "$pci_id" == "" ] && pci_id="$vid:$did"

  if [ -e $d/driver ] ; then
    driver=$(basename $(readlink $d/driver))
  else
    driver=" "
  fi
  if [ -e $d/net ] ; then
    dev=$(basename $(ls $d/net | head -1))
    n=/sys/class/net/$dev
    mac=$(cat $n/address)
    oper=$(cat $n/operstate)
#    speed=$(sudo ethtool $dev | grep Speed | cut -d" " -f2)
##port=$(ethtool $dev 2> /dev/null | sed -ne 's/.*Port: \(.*\)/\1/p')
  else
    dev=" "
    mac=" "
    oper=" "
    speed=" "
    port=" "
  fi
  printf "%-12s %s %-11s %-10s %-17s %-14s %-5s %-10s %s\n" \
        $pci_addr $numa "$pci_id" $driver $mac $dev $oper $speed "$port"
done