#!/bin/sh
# This script will download runcode into NIC and setup the tuning parameters
#  in EEPROM.  NOTE: Must be root for script to work.
#
# $1 = device name (ie. ess0, ess1...) for multi card support, default is ess0.
#
#Indigo2/R4K
IP22="-e -c 0x5000 -t 0x100 -o 0x500000 -s 0xf4240 -i 0x20 -x 0x500000 \
         -r 0x200000 -h 0x0 -w 0x80 -d 0x80"

#Origin200/R10K
IP27="-e -c 0x5000 -t 0x100 -o 0x500000 -s 0xf4240 -i 0x20 -x 0x500000 \
         -r 0x200000 -h 0xb4 -w 0x80 -d 0x80"

#Indigo2/R10K
IP28="-e -c 0x5000 -t 0x100 -o 0x500000 -s 0xf4240 -i 0x20 -x 0x500000 \
         -r 0x200000 -h 0xc0 -w 0x80 -d 0x80"

#Octane/R10K
IP30="-e -c 0x5000 -t 0x100 -o 0x500000 -s 0xf4240 -i 0x20 -x 0x500000 \
         -r 0x200000 -h 0xb4 -w 0x80 -d 0x80"

#O2/R5K/R10K
IP32="-e -c 0x5000 -t 0x100 -o 0x500000 -s 0xf4240 -i 0x20 -x 0x500000 \
         -r 0x200000 -h 0xb4 -w 0x80 -d 0x80"

ESSDIR=/usr/Essential/hippi
ESSBIN=$ESSDIR/bin
ESSFW=$ESSDIR/firmware

DEV=ess0
if [ $# -eq 1 ]
then
  DEV=$1
fi

# Turn OFF Device
CMD="$ESSBIN/esshippi off $DEV"
eval $CMD
if [ $? -ne 0 ]
then
  echo " -ERROR: Failed to cycle NIC off (MUST be root),"
  echo "         command: $CMD"
  exit 1
fi
sleep 2

# No longer needed.
# Download RunCode into EEPROM
#CMD="$ESSBIN/essdnld -D $DEV -r $ESSFW/runcode.nic"
#eval $CMD
#if [ $? -ne 0 ]
#then
#  echo " -ERROR: Failed to download RunCode,"
#  echo "         command: $CMD"
#  exit 1
#fi
#sleep 2

# Update Tuning Parameters into EEPROM
echo "Update NIC tuning parameters"
TYPE=`uname -m`
eval IP_TYPE=\$$TYPE
if test "$IP_TYPE" != ""
then
   CMD="$ESSBIN/esstune -D $DEV $IP_TYPE"
   eval $CMD
   if [ $? -ne 0 ]
   then
      echo " -ERROR: Failed to setup NIC tuning parameters,"
      echo "         command: $CMD"
      exit 1
   fi
else
  echo " -ERROR: Failed to setup NIC tuning parameters,"
  echo "         System type ($TYPE) not supported"
  exit 1
fi

echo "** Please reboot machine now for changes to become effective **"
