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# mpss Start mpssd. 10# 11# chkconfig: 2345 95 05 12# description: start MPSS stack processing. 13# 14### BEGIN INIT INFO 15# Provides: mpss 16# Required-Start: 17# Required-Stop: 18# Short-Description: MPSS stack control 19# Description: MPSS stack control 20### END INIT INFO 21 22# Source function library. 23. /etc/init.d/functions 24 25exec=/usr/sbin/mpssd 26sysfs="/sys/class/mic" 27mic_modules="mic_host mic_x100_dma scif vop" 28 29start() 30{ 31 [ -x $exec ] || exit 5 32 33 if [ "`ps -e | awk '{print $4}' | grep mpssd | head -1`" = "mpssd" ]; then 34 echo -e $"MPSSD already running! " 35 success 36 echo 37 return 0 38 fi 39 40 echo -e $"Starting MPSS Stack" 41 echo -e $"Loading MIC drivers:" $mic_modules 42 43 modprobe -a $mic_modules 44 RETVAL=$? 45 if [ $RETVAL -ne 0 ]; then 46 failure 47 echo 48 return $RETVAL 49 fi 50 51 # Start the daemon 52 echo -n $"Starting MPSSD " 53 $exec 54 RETVAL=$? 55 if [ $RETVAL -ne 0 ]; then 56 failure 57 echo 58 return $RETVAL 59 fi 60 success 61 echo 62 63 sleep 5 64 65 # Boot the cards 66 micctrl -b 67 68 # Wait till ping works 69 for f in $sysfs/* 70 do 71 count=100 72 ipaddr=`cat $f/cmdline` 73 ipaddr=${ipaddr#*address,} 74 ipaddr=`echo $ipaddr | cut -d, -f1 | cut -d\; -f1` 75 while [ $count -ge 0 ] 76 do 77 echo -e "Pinging "`basename $f`" " 78 ping -c 1 $ipaddr &> /dev/null 79 RETVAL=$? 80 if [ $RETVAL -eq 0 ]; then 81 success 82 break 83 fi 84 sleep 1 85 count=`expr $count - 1` 86 done 87 [ $RETVAL -ne 0 ] && failure || success 88 echo 89 done 90 return $RETVAL 91} 92 93stop() 94{ 95 echo -e $"Shutting down MPSS Stack: " 96 97 # Bail out if module is unloaded 98 if [ ! -d "$sysfs" ]; then 99 echo -n $"Module unloaded " 100 success 101 echo 102 return 0 103 fi 104 105 # Shut down the cards. 106 micctrl -S 107 108 # Wait for the cards to go offline 109 for f in $sysfs/* 110 do 111 while [ "`cat $f/state`" != "ready" ] 112 do 113 sleep 1 114 echo -e "Waiting for "`basename $f`" to become ready" 115 done 116 done 117 118 # Display the status of the cards 119 micctrl -s 120 121 # Kill MPSSD now 122 echo -n $"Killing MPSSD" 123 killall -9 mpssd 2>/dev/null 124 RETVAL=$? 125 [ $RETVAL -ne 0 ] && failure || success 126 echo 127 return $RETVAL 128} 129 130restart() 131{ 132 stop 133 sleep 5 134 start 135} 136 137status() 138{ 139 micctrl -s 140 if [ "`ps -e | awk '{print $4}' | grep mpssd | head -n 1`" = "mpssd" ]; then 141 echo "mpssd is running" 142 else 143 echo "mpssd is stopped" 144 fi 145 return 0 146} 147 148unload() 149{ 150 if [ ! -d "$sysfs" ]; then 151 echo -n $"No MIC_HOST Module: " 152 success 153 echo 154 return 155 fi 156 157 stop 158 159 sleep 5 160 echo -n $"Removing MIC drivers:" $mic_modules 161 modprobe -r $mic_modules 162 RETVAL=$? 163 [ $RETVAL -ne 0 ] && failure || success 164 echo 165 return $RETVAL 166} 167 168case $1 in 169 start) 170 start 171 ;; 172 stop) 173 stop 174 ;; 175 restart) 176 restart 177 ;; 178 status) 179 status 180 ;; 181 unload) 182 unload 183 ;; 184 *) 185 echo $"Usage: $0 {start|stop|restart|status|unload}" 186 exit 2 187esac 188 189exit $? 190