@@ -12,21 +12,140 @@ function usage() {
1212 echo " -d, --disable <FID> disable the specified FID" ;
1313 echo " -e, --enable <FID> enable the specified FID" ;
1414 echo " -h, --help display this message" ;
15+ echo " -I, --IB-dev display IB-dev instead of netdev attributes" ;
1516 echo " -r, --rawids display 'type' as raw vendor/device IDs" ;
1617 echo " -v, --version display version info" ;
1718 echo ;
1819}
1920
20- function print_rnic () {
21- if [ $header -eq 0 ]; then
22- printf " FID Power PCI ID PCHID Type Port PNET ID Interface \n" ;
23- echo ' ------------------------------------------------------------------------------------ ' ;
24- header=1 ;
21+ function print_header () {
22+ if [ $IBdev -eq 0 ]; then
23+ printf " FID Power PCI_ID PCHID Type PPrt PNET_ID Net-Dev \n" ;
24+ else
25+ printf " FID Power PCI_ID PCHID Type IPrt PNET_ID IB-Dev\n " ;
2526 fi
26- printf " %3x %-5s %-12s %-4s %-14s %-4s %-16s %s\n" " $(( 16 #$fid )) " " $power " " $addr " " $pchid " " $dev_type " " $port " " $pnet " " $int " ;
27+ echo ' -----------------------------------------------------------------------------------------' ;
28+ }
29+
30+ function get_pnet_from_port() {
31+ local idx;
32+ local end;
33+ local lport=$port ;
34+
35+ if [ " $lport " == " n/a" ] || [ " $dev_type " == " RoCE_Express2" ]; then
36+ if [ $IBdev -eq 0 ]; then
37+ lport=0;
38+ else
39+ lport=1;
40+ fi
41+ fi
42+ [ $IBdev -ne 0 ] && let lport=$lport -1;
43+ (( idx= 16 * $lport + 1 ))
44+ (( end= $idx + 15 ))
45+ echo " $pnetids " | cut -c $idx -$end ;
46+ }
47+
48+ function print_rnic() {
49+ printf " %8x %-5s %-12s %-4s %-14s %-4s %-16s %s\n" " $(( 16 #$fid )) " " $power " " $addr " " $pchid " " $dev_type " " $port " " ` get_pnet_from_port` " " $int " ;
2750 (( printed++ )) ;
2851}
2952
53+ function print_rnics() {
54+ # iterate over slots, as powered-off devices won't show elsewhere
55+ for fid in ` ls -1 /sys/bus/pci/slots` ; do
56+ cd /sys/bus/pci/slots/$fid ;
57+ fid=" $fid " ;
58+ if [ " $target " != " " ] && [ " $fid " != " $target " ]; then
59+ continue ;
60+ fi
61+ power=` cat power` ;
62+ interfaces=" " ;
63+ port=" n/a" ;
64+ addr=" " ;
65+ int=" " ;
66+ if [ $power -eq 0 ]; then
67+ # device not yet hotplugged
68+ dev_type=" " ;
69+ pchid=" " ;
70+ pnet=" " ;
71+ print_rnic;
72+ continue ;
73+ fi
74+ # device is hotplugged - locate it
75+ for dev in ` ls -1 /sys/bus/pci/devices` ; do
76+ cd /sys/bus/pci/devices/$dev ;
77+ if [ " ` cat function_id` " == " 0x$fid " ]; then
78+ addr=$dev ;
79+ break ;
80+ fi
81+ done
82+ if [ " $addr " == " " ]; then
83+ echo " Error: No matching device found for FID $fid " >&2 ;
84+ continue ;
85+ fi
86+ cd /sys/bus/pci/devices/$addr ;
87+ id=` cat device` ;
88+ vend=` cat vendor` ;
89+ dev_type=" ${vend# 0x} :${id# 0x} " ;
90+ if [ $rawIDs -eq 0 ]; then
91+ case " $vend " in
92+ " 0x1014" ) # IBM
93+ case " $id " in
94+ " 0x04ed" ) dev_type=" ISM" ;
95+ int=" n/a" ;;
96+ " 0x044b" ) continue ;; # zEDC
97+ esac ;;
98+ " 0x15b3" ) # Mellanox
99+ case " $id " in
100+ " 0x1003" | \
101+ " 0x1004" ) dev_type=" RoCE_Express" ;;
102+ " 0x1016" ) dev_type=" RoCE_Express2" ;
103+ if [ -e port ]; then
104+ port=` cat port` ;
105+ if [ $IBdev -eq 0 ]; then
106+ let port=$port -1;
107+ else
108+ port=1;
109+ fi
110+ fi ;;
111+ esac ;;
112+ esac
113+ fi
114+ pchid=" ` cat pchid | sed ' s/^0x//' ` " ;
115+ pnetids=" ` cat util_string | tr -d ' \000' | iconv -f IBM-1047 -t ASCII` " ;
116+ if [ $IBdev -eq 0 ]; then
117+ if [ -d " net" ]; then
118+ interfaces=" ` ls -1 net` " ;
119+ else
120+ int=" n/a" ;
121+ print_rnic;
122+ continue ;
123+ fi
124+ # one device can have multiple interfaces (one per port)
125+ for int in $interfaces ; do
126+ cd /sys/bus/pci/devices/$addr /net/$int ;
127+ if [ " $dev_type " == " RoCE_Express" ] && [ -e dev_port ]; then
128+ port=` cat dev_port` ;
129+ fi
130+ print_rnic;
131+ done
132+ else
133+ if [ -d " infiniband" ]; then
134+ int=" ` ls -1 infiniband` " ;
135+ else
136+ int=" n/a" ;
137+ print_rnic;
138+ continue ;
139+ fi
140+ # only one IB interface per card
141+ cd /sys/bus/pci/devices/$addr /infiniband/$int
142+ for port in ` ls -1 ports` ; do
143+ print_rnic;
144+ done
145+ fi
146+ done
147+ }
148+
30149function format_fid() {
31150 res=" ${1# 0x} " ;
32151
@@ -43,12 +162,13 @@ if [ "`uname -m`" != "s390x" ] && [ "`uname -m`" != "s390" ]; then
43162 exit 1;
44163fi
45164
46- args=` getopt -u -o hrve :d: -l enable:,disable:,help,rawids,version -- $* ` ;
165+ args=` getopt -u -o hIrve :d: -l enable:,disable:,help,IB-dev ,rawids,version -- $* ` ;
47166[ $? -ne 0 ] && exit 2;
48167set -- $args ;
49168action=" print" ;
50169rawIDs=0;
51170target=" " ;
171+ IBdev=0;
52172printed=0;
53173while [ $# -gt 0 ]; do
54174 case $1 in
@@ -63,10 +183,12 @@ while [ $# -gt 0 ]; do
63183 " -h" | " --help" )
64184 usage;
65185 exit 0;;
186+ " -I" | " --IB-dev" )
187+ IBdev=1;;
66188 " -r" | " --rawids" )
67189 rawIDs=1;;
68190 " -v" | " --version" )
69- echo " smc_rnics utility, smc-tools-1.2.2 (4335826 )" ;
191+ echo " smc_rnics utility, smc-tools-1.3.0 (eb56148 )" ;
70192 exit 0;;
71193 " --" ) ;;
72194 * ) format_fid " $1 " ;
@@ -102,82 +224,8 @@ if [ "$action" != "print" ]; then
102224 exit 0;
103225fi
104226
105- header=0;
106- # iterate over slots, as powered-off devices won't show elsewhere
107- for fid in ` ls -1 /sys/bus/pci/slots` ; do
108- cd /sys/bus/pci/slots/$fid ;
109- fid=" $fid " ;
110- if [ " $target " != " " ] && [ " $fid " != " $target " ]; then
111- continue ;
112- fi
113- power=` cat power` ;
114- interfaces=" " ;
115- port=" " ;
116- addr=" " ;
117- int=" " ;
118- if [ $power -eq 0 ]; then
119- # device not yet hotplugged
120- dev_type=" " ;
121- pchid=" " ;
122- pnet=" " ;
123- print_rnic;
124- continue ;
125- fi
126- # device is hotplugged - locate it
127- for dev in ` ls -1 /sys/bus/pci/devices` ; do
128- cd /sys/bus/pci/devices/$dev ;
129- if [ " ` cat function_id` " == " 0x$fid " ]; then
130- addr=$dev ;
131- break ;
132- fi
133- done
134- if [ " $addr " == " " ]; then
135- echo " Error: No matching device found for FID $fid " >&2 ;
136- continue ;
137- fi
138- cd /sys/bus/pci/devices/$addr ;
139- id=` cat device` ;
140- vend=` cat vendor` ;
141- dev_type=" ${vend# 0x} :${id# 0x} " ;
142- if [ $rawIDs -eq 0 ]; then
143- case " $vend " in
144- " 0x1014" ) # IBM
145- case " $id " in
146- " 0x04ed" ) dev_type=" ISM" ;
147- port=" n/a" ;
148- int=" n/a" ;;
149- " 0x044b" ) continue ;; # zEDC
150- esac ;;
151- " 0x15b3" ) # Mellanox
152- case " $id " in
153- " 0x1003" | \
154- " 0x1004" ) dev_type=" RoCE Express" ;;
155- " 0x1016" ) dev_type=" RoCE Express2" ;;
156- esac ;;
157- esac
158- fi
159- pchid=" ` cat pchid | sed ' s/^0x//' ` " ;
160- pnet=" ` cat util_string | tr -d ' \000' | iconv -f IBM-1047 -t ASCII` " ;
161- if [ -d net ]; then
162- interfaces=" ` ls -1 net` " ;
163- fi
164- # one device can have multiple interfaces (one per port)
165- if [ " $interfaces " != " " ]; then
166- pnetids=" $pnet " ;
167- for int in $interfaces ; do
168- cd /sys/bus/pci/devices/$addr /net/$int ;
169- if [ -e dev_port ]; then
170- port=` cat dev_port` ;
171- (( idx= 16 * $port + 1 ))
172- (( end= $idx + 15 ))
173- pnet=` echo " $pnetids " | cut -c $idx -$end ` ;
174- fi
175- print_rnic;
176- done
177- continue ;
178- fi
179- print_rnic;
180- done
227+ print_header;
228+ print_rnics | sort -k 4;
181229
182230if [ " $target " != " " ] && [ $printed -eq 0 ]; then
183231 exit 8;
0 commit comments