Skip to content

Instantly share code, notes, and snippets.

@prestelpirate
Last active December 7, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prestelpirate/021891830de75949f459f8c8ee5930bb to your computer and use it in GitHub Desktop.
Save prestelpirate/021891830de75949f459f8c8ee5930bb to your computer and use it in GitHub Desktop.
Sun’s Cassini Ethernet (ce) cards are available in either 100mb or 1gb versions. The same driver is used for both. Problems arise because speed and duplex settings cannot be set from within /etc/system. Instead, a configuration file must be used. The syntax is cryptic and prone to mistakes – at the worst case, a poorly written configuration file…
#!/bin/ksh
#
# 2004-01-20 Tom Kranz (tom@siliconbunny.com)
#
# This script is distributed under the GNU Public License (GPL) with the
# following extra conditions:
# - attritbution must be maintained
# - CD-ROM or similar media for commercial distribution without the prior
# approval of the author
#
# This script will build a ce.conf file based on the type of ce interface
# (GigE or 100mb). We will pull apart path_to_inst to work this out
#
# The end result is to force 100fdx for 100mb ce interfaces, and to leave it all
# up to auto negotiation for the GigE interfaces
#
# See Sun Info Doc 72033 for more information
# See Sun Alert Notification 55360 for details of the evil that happens if this
# is not setup correctly
#
# NOTE WELL: seperate device paths for midframes and starfires!
# Nasty IFS hacking ahoy, so we need to save what we have
SAVEIFS=${IFS}
# Variables to source our files
# CHANGE THESE TO SUIT
PATH_TO_INST=path_to_inst
OUTPUT=ce.conf
# We need to save the existing ce.conf, then blow it away
if [[ -a ${OUTPUT} ]]
then
mv ${OUTPUT} ${OUTPUT}.sav
fi
# Our non-changing settings
# Note we can set 1000fdx and 100fdx to 1, because adv_autoneg_cap will always
# take priority over specific speed/duplex settings
OTHER_PARMS="adv_1000fdx_cap=0 adv_1000hdx_cap=0 adv_100fdx_cap=1 adv_100hdx_cap=0 adv_10fdx_cap=0 adv_10hdx_cap=0;"
# The auto negotiation setting - we can have a choice here
YES_AUTONEG="adv_autoneg_cap=1"
NO_AUTONEG="adv_autoneg_cap=0"
# Now we pull apart path_to_inst to work out what ce nodes we have
CARDS=`cat ${PATH_TO_INST} | grep \"ce\"`
# We'll take each line at a time, splitting things out until we get the
# data we need
IFS='
'
for INST in ${CARDS}
do
# We need to split on spaces again
IFS=" "
set -A DETAILS ${INST}
# First field in path_to_inst is the device path
INSTPATH=${DETAILS[0]}
# Now we need to chop up the device path to work out what sort of
# ce device we have
IFS="/"
set -A SNIPPET ${INSTPATH}
# Naturally the midframes have to handle things differently
if [ `uname -i` = "SUNW,Sun-Fire" ]
then
CE_TYPE=${SNIPPET[3]}
else
CE_TYPE=${SNIPPET[2]}
fi
# What do we do with what we've matched
case "${CE_TYPE}" in
pci*)
# If the device path has an extra pci* field in
# it, we know it's a 100mb interface
IFS=$SAVEIFS
if [ `uname -i` = "SUNW,Sun-Fire" ]
then
DEVPATH="/${SNIPPET[1]}/${SNIPPET[2]}/${SNIPPET[3]}"
UADDRESS=`echo ${INSTPATH} | cut -d@ -f5`
else
DEVPATH="/${SNIPPET[1]}/${SNIPPET[2]}"
UADDRESS=`echo ${INSTPATH} | cut -d@ -f4`
fi
# Behold the OUTPUT!
echo "name=\"pci108e,abba\" parent=\"${DEVPATH}\" unit-address=\"${UADDRESS} ${NO_AUTONEG} ${OTHER_PARMS}" >> ${OUTPUT}
echo "" >> ${OUTPUT}
;;
network*)
# Otherwise, it's a GigE interface
IFS=$SAVEIFS
if [ `uname -i` = "SUNW,Sun-Fire" ]
then
DEVPATH="/${SNIPPET[1]}/${SNIPPET[2]}"
UADDRESS=`echo ${INSTPATH} | cut -d@ -f4`
else
DEVPATH="/${SNIPPET[1]}"
UADDRESS=`echo ${INSTPATH} | cut -d@ -f3`
fi
# Behold the OUTPUT!
echo "name=\"pci108e,abba\" parent=\"${DEVPATH}\" unit-address=\"${UADDRESS} ${YES_AUTONEG} ${OTHER_PARMS}" >> ${OUTPUT}
echo "" >> ${OUTPUT}
;;
*)
# Just in case something unexpected happens
echo ""
echo "Unable to chop up device paths - check output and input files!"
echo ""
exit 1
;;
esac
# If you value sane output, please reset the IFS value back
IFS=$SAVEIFS
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment