]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/infiniband-diags/scripts/ibstatus
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / infiniband-diags / scripts / ibstatus
1 #!/bin/sh
2
3 # Usage ibstatus [devname[:port]]
4
5 infiniband_base="/sys/class/infiniband"
6 def_ibdev="mthca0"
7
8 usage() {
9         prog=`basename $0`
10         echo "Usage: " $prog " [-h] [devname[:portnum]]"
11         echo "  -h:     this help screen"
12         echo "  Examples:"
13         echo "          $prog mthca1            # shows status of all ports of 'mthca1'"
14         echo "          $prog mthca0:2  # shows status port number 2 of 'mthca0'"
15         echo "          $prog           # default: shows status of all '$def_ibdev' ports"
16         exit -1
17 }
18
19 fatal() {
20         echo "Fatal error: " $*
21         exit -1
22 }
23
24
25 port_status() {
26         port_dir="$infiniband_base/$1/ports/$2"
27         echo "Infiniband device '$1' port $2 status:"
28         echo "  default gid:    " `[ -r $port_dir/gids/0 ] && cat $port_dir/gids/0 || echo unknown`
29         echo "  base lid:       " `[ -r $port_dir/lid ] && cat $port_dir/lid || echo unknown`
30         echo "  sm lid:         " `[ -r $port_dir/sm_lid ] && cat $port_dir/sm_lid || echo unknown`
31         echo "  state:          " `[ -r $port_dir/state ] && cat $port_dir/state || echo unknown`
32         echo "  phys state:     " `[ -r $port_dir/phys_state ] && cat $port_dir/phys_state || echo unknown`
33         echo "  rate:           " `[ -r $port_dir/rate ] && cat $port_dir/rate || echo unknown`
34         echo
35 }
36
37 ib_status() {
38         ports_dir="$infiniband_base/$1/ports"
39
40         if ! [ -d "$ports_dir" ]; then
41                 fatal "device '$1': sys files not found ($ports_dir)"
42         fi
43
44         if [ "$2" = "+" ]; then
45                 ports=`(cd "$infiniband_base/$1/ports" 2>/dev/null || fatal No devices; echo *)`
46         else
47                 ports=$2
48         fi
49
50         for i in $ports; do
51                 port_status $1 $i
52         done
53 }
54
55 if [ "$1" = "-h" ]; then
56         usage
57 fi
58
59 if [ -z "$1" ]; then
60         cd $infiniband_base 2>/dev/null || fatal No devices
61         for dev in *; do
62                 ib_status $dev "+";
63         done
64         exit 0
65 fi
66
67 while [ "$1" ]; do
68         dev=`echo $1 | sed 's/:.*$//'`
69         port=`echo $1 | sed 's/^.*://'`
70
71         if [ "$port" = "$dev" ]; then
72                 port="+"
73         fi
74
75         ib_status $dev $port
76         shift
77 done