Merge branch 'dsa-sort'
[linux-2.6/btrfs-unstable.git] / samples / mic / mpssd / mpss
blob5fcf9fa4b082184c6502bd8afb8fcba1d94dcf11
1 #!/bin/bash
2 # Intel MIC Platform Software Stack (MPSS)
4 # Copyright(c) 2013 Intel Corporation.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2, as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # The full GNU General Public License is included in this distribution in
16 # the file called "COPYING".
18 # Intel MIC User Space Tools.
20 # mpss Start mpssd.
22 # chkconfig: 2345 95 05
23 # description: start MPSS stack processing.
25 ### BEGIN INIT INFO
26 # Provides: mpss
27 # Required-Start:
28 # Required-Stop:
29 # Short-Description: MPSS stack control
30 # Description: MPSS stack control
31 ### END INIT INFO
33 # Source function library.
34 . /etc/init.d/functions
36 exec=/usr/sbin/mpssd
37 sysfs="/sys/class/mic"
38 mic_modules="mic_host mic_x100_dma scif vop"
40 start()
42 [ -x $exec ] || exit 5
44 if [ "`ps -e | awk '{print $4}' | grep mpssd | head -1`" = "mpssd" ]; then
45 echo -e $"MPSSD already running! "
46 success
47 echo
48 return 0
51 echo -e $"Starting MPSS Stack"
52 echo -e $"Loading MIC drivers:" $mic_modules
54 modprobe -a $mic_modules
55 RETVAL=$?
56 if [ $RETVAL -ne 0 ]; then
57 failure
58 echo
59 return $RETVAL
62 # Start the daemon
63 echo -n $"Starting MPSSD "
64 $exec
65 RETVAL=$?
66 if [ $RETVAL -ne 0 ]; then
67 failure
68 echo
69 return $RETVAL
71 success
72 echo
74 sleep 5
76 # Boot the cards
77 micctrl -b
79 # Wait till ping works
80 for f in $sysfs/*
82 count=100
83 ipaddr=`cat $f/cmdline`
84 ipaddr=${ipaddr#*address,}
85 ipaddr=`echo $ipaddr | cut -d, -f1 | cut -d\; -f1`
86 while [ $count -ge 0 ]
88 echo -e "Pinging "`basename $f`" "
89 ping -c 1 $ipaddr &> /dev/null
90 RETVAL=$?
91 if [ $RETVAL -eq 0 ]; then
92 success
93 break
95 sleep 1
96 count=`expr $count - 1`
97 done
98 [ $RETVAL -ne 0 ] && failure || success
99 echo
100 done
101 return $RETVAL
104 stop()
106 echo -e $"Shutting down MPSS Stack: "
108 # Bail out if module is unloaded
109 if [ ! -d "$sysfs" ]; then
110 echo -n $"Module unloaded "
111 success
112 echo
113 return 0
116 # Shut down the cards.
117 micctrl -S
119 # Wait for the cards to go offline
120 for f in $sysfs/*
122 while [ "`cat $f/state`" != "ready" ]
124 sleep 1
125 echo -e "Waiting for "`basename $f`" to become ready"
126 done
127 done
129 # Display the status of the cards
130 micctrl -s
132 # Kill MPSSD now
133 echo -n $"Killing MPSSD"
134 killall -9 mpssd 2>/dev/null
135 RETVAL=$?
136 [ $RETVAL -ne 0 ] && failure || success
137 echo
138 return $RETVAL
141 restart()
143 stop
144 sleep 5
145 start
148 status()
150 micctrl -s
151 if [ "`ps -e | awk '{print $4}' | grep mpssd | head -n 1`" = "mpssd" ]; then
152 echo "mpssd is running"
153 else
154 echo "mpssd is stopped"
156 return 0
159 unload()
161 if [ ! -d "$sysfs" ]; then
162 echo -n $"No MIC_HOST Module: "
163 success
164 echo
165 return
168 stop
170 sleep 5
171 echo -n $"Removing MIC drivers:" $mic_modules
172 modprobe -r $mic_modules
173 RETVAL=$?
174 [ $RETVAL -ne 0 ] && failure || success
175 echo
176 return $RETVAL
179 case $1 in
180 start)
181 start
183 stop)
184 stop
186 restart)
187 restart
189 status)
190 status
192 unload)
193 unload
196 echo $"Usage: $0 {start|stop|restart|status|unload}"
197 exit 2
198 esac
200 exit $?