Blame IbaTools/portdown/opaportconfig.sh

Packit 857059
#!/bin/bash
Packit 857059
# BEGIN_ICS_COPYRIGHT8 ****************************************
Packit 857059
# 
Packit 857059
# Copyright (c) 2015, Intel Corporation
Packit 857059
# 
Packit 857059
# Redistribution and use in source and binary forms, with or without
Packit 857059
# modification, are permitted provided that the following conditions are met:
Packit 857059
# 
Packit 857059
#     * Redistributions of source code must retain the above copyright notice,
Packit 857059
#       this list of conditions and the following disclaimer.
Packit 857059
#     * Redistributions in binary form must reproduce the above copyright
Packit 857059
#       notice, this list of conditions and the following disclaimer in the
Packit 857059
#       documentation and/or other materials provided with the distribution.
Packit 857059
#     * Neither the name of Intel Corporation nor the names of its contributors
Packit 857059
#       may be used to endorse or promote products derived from this software
Packit 857059
#       without specific prior written permission.
Packit 857059
# 
Packit 857059
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 857059
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 857059
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 857059
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit 857059
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 857059
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 857059
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit 857059
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit 857059
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 857059
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 857059
# 
Packit 857059
# END_ICS_COPYRIGHT8   ****************************************
Packit 857059
Packit 857059
# [ICS VERSION STRING: unknown]
Packit 857059
Packit 857059
# opaportconfig arguments
Packit 857059
# -s speed = new link speeds enabled (default is 0)
Packit 857059
#        0 - no-op
Packit 857059
#        1 - 2.5 Gb/s
Packit 857059
#        2 - 5 Gb/s
Packit 857059
#        4 - 10 Gb/s
Packit 857059
#        to enable multiple speeds, use sum of desired speeds
Packit 857059
#        255 - enable all supported
Packit 857059
#
Packit 857059
HFIPORTS="1:1"	# space separated list of HFI:PORT to act on
Packit 857059
# other examples: (uncomment exactly 1)
Packit 857059
#HFIPORTS="1:2"	# port 2 on HFI 1
Packit 857059
#HFIPORTS="1:1 1:2"	# port 1 and 2 on HFI 1
Packit 857059
#HFIPORTS="1:1 2:1"	# port 1 on HFI 1 and port 1 on HFI 2
Packit 857059
# Below will force DDR
Packit 857059
ARGS="-s 2"		# additional arguments to use for all HFIs/PORTs
Packit 857059
# Other examples: (uncomment exactly 1)
Packit 857059
#ARGS="-s 1"		# force SDR
Packit 857059
#ARGS="-s 4"		# force QDR
Packit 857059
#ARGS="-s 3"		# negotiate SDR or DDR
Packit 857059
#ARGS="-s 7"		# negotiate SDR, DDR or QDR
Packit 857059
Packit 857059
# opaportconfig     use opaportconfig to force link speed
Packit 857059
#
Packit 857059
# chkconfig: 35 16 84
Packit 857059
# description: Force HFI port speed
Packit 857059
# processname:
Packit 857059
### BEGIN INIT INFO
Packit 857059
# Provides:       opaportconfig
Packit 857059
# Required-Start: openibd
Packit 857059
# Required-Stop:
Packit 857059
# Default-Start:  2 3 5
Packit 857059
# Default-Stop:	  0 1 2
Packit 857059
# Description:    use opaportconfig to force link speed
Packit 857059
### END INIT INFO
Packit 857059
Packit 857059
PATH=/bin:/sbin:/usr/bin:/usr/sbin
Packit 857059
Packit 857059
# just in case no functions script
Packit 857059
echo_success() { echo "[  OK  ]"; }
Packit 857059
echo_failure() { echo "[FAILED]"; }
Packit 857059
Packit 857059
my_rc_status_v()
Packit 857059
{
Packit 857059
	res=$?
Packit 857059
	if [ $res -eq 0 ]
Packit 857059
	then
Packit 857059
		echo_success
Packit 857059
	else
Packit 857059
		echo_failure
Packit 857059
	fi
Packit 857059
	echo
Packit 857059
	my_rc_status_all=$(($my_rc_status_all || $res))
Packit 857059
}
Packit 857059
Packit 857059
if [ -f /etc/init.d/functions ]; then
Packit 857059
    . /etc/init.d/functions
Packit 857059
elif [ -f /etc/rc.d/init.d/functions ] ; then
Packit 857059
    . /etc/rc.d/init.d/functions
Packit 857059
elif [ -s /etc/rc.status ]; then
Packit 857059
	. /etc/rc.status
Packit 857059
	rc_reset
Packit 857059
	my_rc_status_v()
Packit 857059
	{
Packit 857059
		res=$?
Packit 857059
		[ $res -eq 0 ] || false
Packit 857059
		rc_status -v
Packit 857059
		my_rc_status_all=$(($my_rc_status_all || $res))
Packit 857059
	}
Packit 857059
fi
Packit 857059
Packit 857059
my_rc_status_all=0
Packit 857059
my_rc_exit()     { exit $my_rc_status_all; }
Packit 857059
my_rc_status()   { my_rc_status_all=$(($my_rc_status_all || $?)); }
Packit 857059
Packit 857059
cmd=$1
Packit 857059
Packit 857059
Usage()
Packit 857059
{
Packit 857059
	echo "Usage: $0 [start|stop|restart]" >&2
Packit 857059
	echo " start       - configure port" >&2
Packit 857059
	echo " stop        - Noop" >&2
Packit 857059
	echo " restart     - restart (eg. stop then start) the Port config" >&2
Packit 857059
	echo " status      - show present port configuration" >&2
Packit 857059
	exit 2
Packit 857059
}
Packit 857059
Packit 857059
start()
Packit 857059
{
Packit 857059
	local res hfi port hfiport
Packit 857059
Packit 857059
	echo -n "Starting opaportconfig: "
Packit 857059
	res=0
Packit 857059
	for hfiport in $HFIPORTS
Packit 857059
	do
Packit 857059
		hfi=$(echo $hfiport|cut -f1 -d:)
Packit 857059
		port=$(echo $hfiport|cut -f2 -d:)
Packit 857059
		echo -n "Setting HFI $hfi Port $port: "
Packit 857059
 		/sbin/opaportconfig -h $hfi -p $port $ARGS >/dev/null
Packit 857059
		res=$(($res || $?))
Packit 857059
		[ $res -eq 0 ] || false
Packit 857059
		my_rc_status_v
Packit 857059
	done
Packit 857059
	if [ $res -eq 0 ]
Packit 857059
	then
Packit 857059
		touch /var/lock/subsys/opaportconfig
Packit 857059
	fi
Packit 857059
	return $res
Packit 857059
}
Packit 857059
Packit 857059
stop()
Packit 857059
{
Packit 857059
	local res
Packit 857059
Packit 857059
	echo -n "Stopping opaportconfig: "
Packit 857059
	# nothing to do
Packit 857059
	res=0
Packit 857059
	my_rc_status_v
Packit 857059
	rm -f /var/lock/subsys/opaportconfig
Packit 857059
	return $res
Packit 857059
}
Packit 857059
Packit 857059
status()
Packit 857059
{
Packit 857059
	local res hfi port hfiport
Packit 857059
Packit 857059
	echo -n "Checking port state: "
Packit 857059
	res=0
Packit 857059
	for hfiport in $HFIPORTS
Packit 857059
	do
Packit 857059
		hfi=$(echo $hfiport|cut -f1 -d:)
Packit 857059
		port=$(echo $hfiport|cut -f2 -d:)
Packit 857059
		echo -n "HFI $hfi "
Packit 857059
		/sbin/opaportconfig -h $hfi -p $port -v|tail -15
Packit 857059
		res=$(($res || $?))
Packit 857059
		[ $res -eq 0 ] || false
Packit 857059
		my_rc_status_v
Packit 857059
	done
Packit 857059
	return $res
Packit 857059
}
Packit 857059
Packit 857059
case "$cmd" in
Packit 857059
	start)
Packit 857059
		start;;
Packit 857059
	stop)
Packit 857059
		stop;;
Packit 857059
	restart)
Packit 857059
		stop; start;;
Packit 857059
	status)
Packit 857059
		status;;
Packit 857059
	*)
Packit 857059
		Usage;;
Packit 857059
esac
Packit 857059
Packit 857059
my_rc_exit