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