-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsmc_rnics
More file actions
executable file
·369 lines (342 loc) · 8.69 KB
/
Copy pathsmc_rnics
File metadata and controls
executable file
·369 lines (342 loc) · 8.69 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/bin/bash
# Copyright IBM Corp. 2018, 2022
VERSION="1.8.7";
function usage() {
echo;
echo "Usage: smc_rnics [ OPTIONS ] [ FID ]";
echo;
echo "List RNICs";
echo;
echo " -a, --all include disabled devices in output";
echo " -d, --disable <FID> disable the specified FID";
echo " -e, --enable <FID> enable the specified FID";
echo " -h, --help display this message";
echo " -I, --IB-dev display IB-dev instead of netdev attributes";
echo " -r, --rawids display 'type' as raw vendor/device IDs";
echo " -v, --version display version info";
echo;
}
function print_header() {
if [ $IBdev -eq 1 ] && [ $rawIDs -eq 1 ]; then
printf "FID Power PCI_ID PCHID Type PFT VFN IPrt PNET_ID IB-Dev\n";
echo '----------------------------------------------------------------------------------------------------';
elif [ $IBdev -eq 1 ]; then
printf "FID Power PCI_ID PCHID Type PFT VF IPrt PNET_ID IB-Dev\n";
echo '----------------------------------------------------------------------------------------------------';
elif [ $rawIDs -eq 1 ]; then
printf "FID Power PCI_ID PCHID Type PFT VFN PPrt PNET_ID Net-Dev\n";
echo '----------------------------------------------------------------------------------------------------'
else
printf "FID Power PCI_ID PCHID Type PFT VF PPrt PNET_ID Net-Dev\n";
echo '----------------------------------------------------------------------------------------------------';
fi
}
function get_softset_pnet_id() {
local res="n/a";
local line;
local id;
local iface;
local dev;
local prt;
while read -r line; do
read id iface dev prt <<< $line;
if [[ ("$iface" != "n/a" && "$iface" == "$int") || ("$dev" != "n/a" && "$dev" == "$addr") ]]; then
if [ "$prt" != "255" ] && [ "$prt" != "$iport" ]; then
continue;
fi
res="$id*";
fi
done <<< "$(smc_pnet)"
echo "$res";
}
function get_pnet_from_port() {
local idx;
local end;
local lport=$port;
local iport;
local res;
if [ "$lport" == "" ]; then
echo "";
return;
fi
if [ "$lport" == "n/a" ] || [ "$dev_type" != "RoCE_Express" ]; then
lport=0;
else
[ $IBdev -ne 0 ] && let lport=$lport-1;
fi
(( iport=$lport+1 ))
(( idx=16*$lport+1 ))
(( end=$idx+15 ))
res="`echo "$pnetids" | cut -c $idx-$end | sed 's/ //g'`";
if [ "$res" == "" ]; then
res="`get_softset_pnet_id`";
fi
echo $res;
}
function print_rnic() {
if [ $rawIDs -eq 1 ]; then
printf "%4x %-5s %-12s %-4s %-15s %-4s %-3s %-4s %-17s %s\n" \
"$((16#$fid))" "$power" "$addr" "$pchid" "$dev_type" "$pft" "${vfn:+$((16#${vfn#0x}))}" "$port" "`get_pnet_from_port`" "$int";
else
printf "%4x %-5s %-12s %-4s %-15s %-4s %-3s %-4s %-17s %s\n" \
"$((16#$fid))" "$power" "$addr" "$pchid" "$dev_type" "$pft" "$vfn" "$port" "`get_pnet_from_port`" "$int";
fi
(( printed++ ));
}
function set_RoCE_pft_and_vfn() {
local lpft=$1;
local lvfn=$((16#${2#0x}));
case "$lpft" in
"0x02") pft="ROC"; vfn="y";;
"0x05") pft="ISM"; vfn="y";;
"0x0a") pft="ROC2"; vfn="y";;
"0x0c") pft="NETH"; vfn="y";;
"0x0f") pft="NETD";
if (( $lvfn != 0 )); then
vfn="y";
else
vfn="n";
fi;;
*)
vfn="$lvfn";;
esac
}
function set_RoCE_dev_and_port() {
dev_type="$1";
if [ -e port ]; then
port=`cat port`;
if [ $port -eq 0 ]; then
port="n/a";
else
if [ $IBdev -eq 0 ]; then
let port=$port-1;
else
port=1;
fi
fi
fi;
}
function set_by_firmware_lvl() {
local iface;
local name;
local lvl;
which ethtool >/dev/null 2>&1;
if [ $? -eq 0 ] && [ "$int" != "n/a" ] && [ -d "net" ]; then
iface="`ls -1 net | head -1`";
lvl="`ethtool -i $iface | grep -e "^firmware-version:" | awk '{print($2)}'`";
if [ "${lvl%%.*}" == "22" ]; then
name="RoCE_Express3";
elif [ "${lvl%%.*}" == "14" ]; then
name="RoCE_Express2";
fi
fi
set_RoCE_dev_and_port $name;
}
function set_by_pciid(){
case "$vend" in
"0x1014" ) # IBM
case "$id" in
"0x04ed") dev_type="ISM";
int="n/a";;
esac;;
"0x15b3" ) # Mellanox
case "$id" in
"0x1003" | \
"0x1004") dev_type="RoCE_Express";
multiport_f=1;;
"0x1016") set_RoCE_dev_and_port "RoCE_Express2";;
"0x101e") set_by_firmware_lvl;;
*) set_RoCE_dev_and_port "Mlx_$id";;
esac;;
esac
}
function print_rnics() {
# iterate over slots, as powered-off devices won't show elsewhere
for fid in `ls -1 /sys/bus/pci/slots`; do
cd /sys/bus/pci/slots/$fid;
fid="$fid";
if [ "$target" != "" ] && [ "$fid" != "$target" ]; then
continue;
fi
power=`cat power`;
interfaces="";
port="n/a";
addr="";
int="";
if [ $power -eq 0 ]; then
# device not yet hotplugged
if [ $all -ne 0 ]; then
dev_type="";
pchid="";
pft="";
pnet="";
port="";
vfn="";
print_rnic;
fi
continue;
fi
# device is hotplugged - locate it
for dev in `ls -1 /sys/bus/pci/devices`; do
cd /sys/bus/pci/devices/$dev;
if [ "`cat function_id`" == "0x$fid" ]; then
addr=$dev;
break;
fi
done
if [ "$addr" == "" ]; then
echo "Error: No matching device found for FID $fid" >&2;
continue;
fi
cd /sys/bus/pci/devices/$addr;
id=`cat device`;
vend=`cat vendor`;
dev_type="${vend#0x}:${id#0x}";
pft=`cat pft`;
vfn=`cat vfn`;
multiport_f=0;
if [ $rawIDs -eq 0 ]; then
# prefer PFT for disamgibuating devices
case "$pft" in
"0x05") dev_type="ISM";
int="n/a";
set_RoCE_pft_and_vfn "$pft" "$vfn";;
"0x02") dev_type="RoCE_Express";
multiport_f=1;
set_RoCE_pft_and_vfn "$pft" "$vfn";;
"0x0a") set_by_firmware_lvl;
set_RoCE_pft_and_vfn "$pft" "$vfn";;
"0x0c" | \
"0x0f") set_RoCE_dev_and_port "Network_Express";
set_RoCE_pft_and_vfn "$pft" "$vfn";;
*)
# but if that fails go via the pci IDs
set_by_pciid
# For unknown PCI vendors, determine VF flag based on VFN value.
# This ensures consistent handling even for unrecognized vendor devices
[ "$dev_type" = "${vend#0x}:${id#0x}" ] && [ $all -eq 0 ] && continue
if (( 16#${vfn#0x} != 0 )); then
vfn="y";
else
vfn="n";
fi;;
esac
else
set_RoCE_dev_and_port "$dev_type";
[ "0x15b3" = "$vend" ] && [ "0x1004" = "$id" ] && multiport_f=1;
fi
pchid="`cat pchid | sed 's/^0x//'`";
pnetids="`cat util_string | sed 's/\x0/\x40/g' | iconv -f IBM-1047 -t ASCII`";
if [ $IBdev -eq 0 ]; then
if [ -d "net" ]; then
interfaces="`ls -1 net`";
else
int="n/a";
print_rnic;
continue;
fi
for int in $interfaces; do
# one device can have multiple interfaces (one per port)
cd /sys/bus/pci/devices/$addr/net/$int;
if [ $multiport_f -eq 1 ] && [ -e dev_port ]; then
port=`cat dev_port`;
fi
print_rnic;
done
else
if [ -d "infiniband" ]; then
int="`ls -1 infiniband`";
else
int="n/a";
print_rnic;
continue;
fi
# only one IB interface per card
cd /sys/bus/pci/devices/$addr/infiniband/$int
for port in `ls -1 ports`; do
print_rnic;
done
fi
done
}
function format_fid() {
res="${1#0x}";
if [[ ! "$res" =~ ^[[:xdigit:]]+$ ]]; then
printf "Error: '%s' is not a valid FID\n" "$res" >&2;
exit 3;
fi
res="`printf "%08x" $((16#$res))`";
}
args=`getopt -u -o hIrvae:d: -l all,enable:,disable:,help,IB-dev,rawids,version -- $*`;
[ $? -ne 0 ] && exit 2;
set -- $args;
action="print";
rawIDs=0;
all=0;
target="";
IBdev=0;
printed=0;
while [ $# -gt 0 ]; do
case $1 in
"-a" | "--all" )
all=1;;
"-e" | "--enable" )
action="enable";
fid=$2;
shift;;
"-d" | "--disable" )
action="disable";
fid=$2;
shift;;
"-h" | "--help" )
usage;
exit 0;;
"-I" | "--IB-dev" )
IBdev=1;;
"-r" | "--rawids" )
rawIDs=1;;
"-v" | "--version" )
echo "smc_rnics utility, smc-tools-$VERSION";
exit 0;;
"--" ) ;;
* ) format_fid "$1";
target="$res";
esac
shift;
done
if [ "`uname -m`" != "s390x" ] && [ "`uname -m`" != "s390" ]; then
printf "Error: s390/s390x supported only\n" >&2;
exit 1;
fi
if [ "$action" != "print" ]; then
if [ "$target" != "" ]; then
usage;
exit 4;
fi
format_fid "$fid";
fid="$res";
ufid=`printf "%x" $((16#$fid))`; # representation without leading zeros
if [ ! -d /sys/bus/pci/slots/$fid ]; then
echo "Error: FID $ufid does not exist" >&2;
exit 5;
fi
power=`cat /sys/bus/pci/slots/$fid/power 2>/dev/null`;
val=0;
[ "$action" == "enable" ] && val=1;
if [ $power -eq $val ]; then
echo "Error: FID $ufid is already ${action}d" >&2;
exit 6;
fi
echo $val > /sys/bus/pci/slots/$fid/power 2>/dev/null;
if [ $? -ne 0 ]; then
echo "Error: Failed to $action FID $ufid" >&2;
exit 7;
fi
exit 0;
fi
print_header;
print_rnics | sort -k 1;
if [ "$target" != "" ] && [ $printed -eq 0 ]; then
exit 8;
fi
exit 0;