#!/bin/sh
#
#
#    Copyright (c) 1996-2006 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#
# NAME
#      setsplbmode - set or display SPLB mode
# 
# SYNOPSIS
#      setsplbmode [ mode | -show ]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This  command enables MFG mode if mode value is non-zero and
#      disables the SPLB mode if mode value is 0. The mode is saved
#      in flash memory and stays in that mode until the next execu-
#      tion of setsplbmode. The mode becomes active as soon as this
#      command  is  executed.  It does not require a reboot to take
#      effect.
# 
#      The SPLB mode, when enabled, forces spinsilk to disable  two
#      port loop-back for M->M connected ports.  This may be useful
#      to isolate internal switch problems from GBIC problems since
#      the  internal  paths  are  used  much  less  with  SPLB mode
#      enabled.
# 
#      The SPLB mode, when disabled, forces spinsilk  to  circulate
#      frames between pairs of M->M connected ports as follows:
# 
#      P1 TX >>> P1 RX -> P2 TX >>> P2 RX -> P1 TX
#      >>> cable or internal loop-back
#      ->  routing table entry
# 
#      The  connections  between pairs of M->M ports will be chosen
#      to exercise the connections between as many chips (or  bloom
#      quadrants)   as   possible   subject   to   the  setting  of
#      allow_intra_chip and  the  availability  of  pairs  of  M->M
#      ports.
# 
#      Any ports that are cross-cabled will be routed to each other
#      in the normal manner regardless of the setting of SPLB mode:
# 
#      P1 TX >>> P2 RX -> P1 TX   and
#      P2 TX >>> P1 RX -> P2 TX
# 
# OPTIONS
#      mode      Specify  the  SPLB  mode value. 0 means to disable
#                SPLB mode, any other value will enable SPLB  mode.
# 
#      -show     If specified or no mode is given, the current SPLB
#                mode will be displayed.
# 
# EXAMPLES
#      > setsplbmode -show
#      Splb Mode is 0 (Disabled).
# SEE ALSO
#      spinsilk(1d)
# 

#
#
# Load library -- must be first.
#
echo "Command not applicable to this platform."
exit 3


home="/fabos/share"
util="diagcommon.sh"
ok=0

if [ $# -eq 0 ]; then
	# Check RBAC permission on command
	/fabos/libexec/rbac_check `/bin/basename $0`
else
	# Check RBAC permission on identified options
	/fabos/libexec/rbac_check `/bin/basename $0` $1
fi

if [ $? -ne 0 ]; then
	exit 127
fi

for f in "./$util" "$FABOSHOME/share/$util" "$home/$util" ; do
	if [ -r $f ] ; then
		. $f
		ok=1
		break;
	fi
done
if [ $ok -ne 1 ] ; then
	echo "Error -- could not locate $util"
	exit 3
fi

#
# Program customization
#

config_string="diag.mode.splb"	# config string to update
config_name="Splb Mode"		# User name of config.
config_default=0		# default value
config_mode=$INTEGER		# config mode

syntax="`/bin/basename $0` [ mode \| -show ]" ; export syntax
bool_false="Disabled" ; export bool_false
bool_true="Enabled" ; export bool_true

#
# setsplbmode()
#
checkForShow "$config_name" "$config_string" "$config_mode" "$config_default" $1
val=`getValue $1`
if [ $? != 0 ] ; then exit 3 ; fi

if [ "$val" -ne "0" ]
then
	val=1
fi

if [ "$val" -ne "0" ]
then
     res=$bool_true
else
     res=$bool_false
fi
cur_val=`getConfig $config_string $config_mode $config_default`
if [ "$cur_val" != "$val" ]
then
	setConfig $config_string $config_mode $val
	updateConfig
	echo "$config_name is now $val ($res)."
else
	echo "$config_name is still $val ($res)."
fi
exit 0
