micctrl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/bash
  2. # Intel MIC Platform Software Stack (MPSS)
  3. #
  4. # Copyright(c) 2013 Intel Corporation.
  5. #
  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.
  9. #
  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.
  14. #
  15. # The full GNU General Public License is included in this distribution in
  16. # the file called "COPYING".
  17. #
  18. # Intel MIC User Space Tools.
  19. #
  20. # micctrl - Controls MIC boot/start/stop.
  21. #
  22. # chkconfig: 2345 95 05
  23. # description: start MPSS stack processing.
  24. #
  25. ### BEGIN INIT INFO
  26. # Provides: micctrl
  27. ### END INIT INFO
  28. # Source function library.
  29. . /etc/init.d/functions
  30. sysfs="/sys/class/mic"
  31. _status()
  32. {
  33. f=$sysfs/$1
  34. echo -e $1 state: "`cat $f/state`" shutdown_status: "`cat $f/shutdown_status`"
  35. }
  36. status()
  37. {
  38. if [ "`echo $1 | head -c3`" == "mic" ]; then
  39. _status $1
  40. return $?
  41. fi
  42. for f in $sysfs/*
  43. do
  44. _status `basename $f`
  45. RETVAL=$?
  46. [ $RETVAL -ne 0 ] && return $RETVAL
  47. done
  48. return 0
  49. }
  50. _reset()
  51. {
  52. f=$sysfs/$1
  53. echo reset > $f/state
  54. }
  55. reset()
  56. {
  57. if [ "`echo $1 | head -c3`" == "mic" ]; then
  58. _reset $1
  59. return $?
  60. fi
  61. for f in $sysfs/*
  62. do
  63. _reset `basename $f`
  64. RETVAL=$?
  65. [ $RETVAL -ne 0 ] && return $RETVAL
  66. done
  67. return 0
  68. }
  69. _boot()
  70. {
  71. f=$sysfs/$1
  72. echo "linux" > $f/bootmode
  73. echo "mic/uos.img" > $f/firmware
  74. echo "mic/$1.image" > $f/ramdisk
  75. echo "boot" > $f/state
  76. }
  77. boot()
  78. {
  79. if [ "`echo $1 | head -c3`" == "mic" ]; then
  80. _boot $1
  81. return $?
  82. fi
  83. for f in $sysfs/*
  84. do
  85. _boot `basename $f`
  86. RETVAL=$?
  87. [ $RETVAL -ne 0 ] && return $RETVAL
  88. done
  89. return 0
  90. }
  91. _shutdown()
  92. {
  93. f=$sysfs/$1
  94. echo shutdown > $f/state
  95. }
  96. shutdown()
  97. {
  98. if [ "`echo $1 | head -c3`" == "mic" ]; then
  99. _shutdown $1
  100. return $?
  101. fi
  102. for f in $sysfs/*
  103. do
  104. _shutdown `basename $f`
  105. RETVAL=$?
  106. [ $RETVAL -ne 0 ] && return $RETVAL
  107. done
  108. return 0
  109. }
  110. _wait()
  111. {
  112. f=$sysfs/$1
  113. while [ "`cat $f/state`" != "offline" -a "`cat $f/state`" != "online" ]
  114. do
  115. sleep 1
  116. echo -e "Waiting for $1 to go offline"
  117. done
  118. }
  119. wait()
  120. {
  121. if [ "`echo $1 | head -c3`" == "mic" ]; then
  122. _wait $1
  123. return $?
  124. fi
  125. # Wait for the cards to go offline
  126. for f in $sysfs/*
  127. do
  128. _wait `basename $f`
  129. RETVAL=$?
  130. [ $RETVAL -ne 0 ] && return $RETVAL
  131. done
  132. return 0
  133. }
  134. if [ ! -d "$sysfs" ]; then
  135. echo -e $"Module unloaded "
  136. exit 3
  137. fi
  138. case $1 in
  139. -s)
  140. status $2
  141. ;;
  142. -r)
  143. reset $2
  144. ;;
  145. -b)
  146. boot $2
  147. ;;
  148. -S)
  149. shutdown $2
  150. ;;
  151. -w)
  152. wait $2
  153. ;;
  154. *)
  155. echo $"Usage: $0 {-s (status) |-r (reset) |-b (boot) |-S (shutdown) |-w (wait)}"
  156. exit 2
  157. esac
  158. exit $?