postinstall revision 6029a2d88c01674debfd7c2e16c941a97302b739
#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
#
# Function: check_add_drv()
#
# This function will check if the module has an entry in etc/name_to_major
# If not simply calls add_drv with the arguments given. If there is
# such an entry in name_to_major file, it adds entries in driver_aliases
# driver_classes and minor_perm if necessary.
# The syntax of this function is the same as add_drv.
check_add_drv()
{
if [ "$BASEDIR" = "" ]
then
BASEDIR=/
fi
alias=""
class=""
ADD_ALIAS=0
ADD_CLASS=0
ADD_MINOR=0
OPTIND=1
IS_NET_DRIVER=0
cmd="add_drv"
NO_CMD=
while getopts i:b:m:c:N opt
do
case $opt in
N ) NO_CMD=1;;
i ) ADD_ALIAS=1
alias=$OPTARG
cmd=$cmd" -i '$alias'"
;;
m ) ADD_MINOR=1
minor=$OPTARG
cmd=$cmd" -m '$minor'"
;;
c) ADD_CLASS=1
class=$OPTARG
cmd=$cmd" -c $class"
;;
b) BASEDIR=$OPTARG
cmd=$cmd" -b $BASEDIR"
;;
\?) echo "check_add_drv can not handle this option"
return
;;
esac
done
shift `/usr/bin/expr $OPTIND - 1`
drvname=$1
cmd=$cmd" "$drvname
drvname=`echo $drvname | /usr/bin/sed 's;.*/;;g'`
/usr/bin/grep "^$drvname[ ]" $BASEDIR/etc/name_to_major > /dev/null 2>&1
if [ "$NO_CMD" = "" -a $? -ne 0 ]
then
eval $cmd
else
# entry already in name_to_major, add alias, class, minorperm
# if necessary
if [ $ADD_ALIAS = 1 ]
then
for i in $alias
do
/usr/bin/egrep "^$drvname[ ]+$i" $BASEDIR/etc/driver_aliases>/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "$drvname $i" >> $BASEDIR/etc/driver_aliases
fi
done
fi
if [ $ADD_CLASS = 1 ]
then
/usr/bin/egrep "^$drvname[ ]+$class( | |$)" $BASEDIR/etc/driver_classes > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "$drvname\t$class" >> $BASEDIR/etc/driver_classes
fi
fi
if [ $ADD_MINOR = 1 ]
then
/usr/bin/grep "^$drvname:" $BASEDIR/etc/minor_perm > /dev/null 2>&1
if [ $? -ne 0 ]
then
minorentry="$drvname:$minor"
echo $minorentry >> $BASEDIR/etc/minor_perm
fi
fi
fi
}
# Function : addmegasastargets
# This function adds the targets from 0-128 into the
# ${BASEDIR}/kernel/drv/sd.conf file.
addmegasastargets()
{
SDCONF=${BASEDIR}/kernel/drv/sd.conf
HEADER="# MEGA AUTOGENERATED CONFIGURATION : START (DO NOT DELETE/ALTER THIS LINE)"
FOOTER="# MEGA AUTOGENERATED CONFIGURATION : END (DO NOT DELETE/ALTER THIS LINE)"
HEADER2="# WARNING : LINES ADDED WITHIN THIS MEGA CONF SECTION"
HEADER3="# WOULD GET DELETED WHEN THE MEGA DRIVER PACKAGE IS REMOVED"
LINEENDPATTERN="parent=\"mega_sas\""
GREP=/usr/bin/grep
CP=/usr/bin/cp
MV=/usr/bin/mv
RM=/usr/bin/rm
target=0
# check if $SDCONF exists
if [ ! -f $SDCONF ]
then
echo "ERROR : $SDCONF file does not exist"
exit 0
fi
$GREP -w "$HEADER" $SDCONF >/dev/null 2>&1
slstatus=$?
$GREP -w "$FOOTER" $SDCONF >/dev/null 2>&1
elstatus=$?
$GREP -w "$LINEENDPATTERN" $SDCONF >/dev/null 2>&1
lestatus=$?
# If any mega_sas related entries exist
# remove them
if [ $slstatus -eq 0 -o $elstatus -eq 0 -o $lestatus -eq 0 ]
then
# Shouldn't enter this condition unless the
# file has been corrupted
# do a dirty remove
$RM -f /tmp/$$.conf >/dev/null 2>&1
cat $SDCONF | $GREP -v "$LINEENDPATTERN" | $GREP -v "$HEADER" \
| $GREP -v "$FOOTER" | $GREP -v "$HEADER2" \
| $GREP -v "$HEADER3" >> /tmp/$$.conf
if [ $? -eq 0 ]
then
$CP /tmp/$$.conf $SDCONF
$RM -f /tmp/$$.conf >/dev/null 2>&1
else
$RM -f /tmp/$$.conf >/dev/null 2>&1
echo "ERROR while cleaning up mega_sas related info in $SDCONF file"
# return, since something bad happened
# and we don't want to continue adding
# more mega_sas related lines
exit 0
fi
fi
# Store the lines to be added
megasaslines="${HEADER}\n"
megasaslines="${megasaslines}${HEADER2}\n"
megasaslines="${megasaslines}${HEADER3}\n"
while [ $target -le 128 ]
do
megasaslines="${megasaslines}name=\"sd\" class=\"scsi\" target=$target lun=0 parent=\"mega_sas\";\n"
target=`expr $target + 1`
done
megasaslines="$megasaslines$FOOTER"
# add a new line if the last line of $SDCONF
# file is not empty (This is required to make sure
# that we don't end up piling newlines every time
# we add/remove this package)
lastline=`tail -1 $SDCONF`
if [ "X$lastline" != "X" ]
then
megasaslines="\n$megasaslines"
fi
# Copy the $SDCONF into /tmp as a backup
$RM -f /tmp/sd.conf.$$ >/dev/null 2>&1
$CP -p $SDCONF /tmp/sd.conf.$$ >/dev/null 2>&1
# Now put all the lines into SDCONF file
# in one shot
echo $megasaslines >> $SDCONF
if [ $? -ne 0 ]
then
echo "ERROR occurred while adding mega_sas targets into $SDCONF file"
# Revert back the backup file in case we added a few lines and
# then the error happened
$MV /tmp/sd.conf.$$ $SDCONF > /dev/null 2>&1
exit 0
fi
$RM -f /tmp/sd.conf.$$ >/dev/null 2>&1
}
addmegasastargets
# We should all use main PCI ID entries. The 4-tuple entries are used to patch
# specific cards, or they will be wrongly matched by other drivers.
check_add_drv -b "${BASEDIR}" -i \
'"pci1028,15.1028.1f01"
"pci1028,15.1028.1f02"
"pci1028,15.1028.1f03"
"pci1000,60.1028.1f0a"
"pci1000,60.1028.1f0b"
"pci1000,60.1028.1f0c"
"pci1000,60.1028.1f0d"
"pci1000,60.1028.1f11"
"pci1000,411.1000.1001"
"pci1000,411.1000.1002"
"pci1000,411.1000.1003"
"pci1000,411.1000.1004"
"pci1000,411.1000.2004"
"pci1000,411.1000.2005"
"pci1000,411.1000.100c"
"pci1000,411.1000.100d"
"pci1000,411.1000.1008"
"pci1000,413.1000.1005"
"pci1000,409.1000.1009"
"pci1000,60.1000.1006"
"pci1000,60.1000.100a"
"pci1000,60.1000.100e"
"pci1000,60.1000.100f"
"pci1000,60.1000.1010"
"pci1000,60.1000.1011"
"pci1000,60.1000.1012"
"pci1000,60.1000.1013"
"pci1000,60.1000.1014"
"pci1000,60.1000.1015"
"pci1000,60.1000.1016"
"pci1000,60.1000.1017"
"pci1000,60.1000.1018"
"pci1000,60.1000.1019"
"pci1000,60.1000.101a"
"pci1000,60.1000.101b"
"pci1000,60.1014.363"
"pci1000,60.1014.364"
"pci1000,60.1014.365"
"pci1000,60.1014.379"
"pci1000,60.1170.2f"
"pci1000,60.1170.36"
"pci1000,60.1043.824d"
"pci1000,411.1734.1081"
"pci1000,411.1734.10a3"
"pci1000,411.1033.8287"
"pci1000,60.1033.835a"
"pci1000,60.1734.10f9"
"pci1000,60.1734.1102"
"pci1000,411.8086.1001"
"pci1000,411.8086.1003"
"pci1000,411.8086.3500"
"pci1000,411.8086.3501"
"pci1000,411.8086.3504"
"pci1000,411.8086.3490"
"pci1000,60.8086.34cc"
"pci1000,60.8086.34cd"
"pci1000,411.8086.3507"
"pci1000,411.1054.3016"
"pci1000,60.1054.3019"
"pci1000,60.8086.1006"
"pci1000,60.8086.100a"
"pci1000,60.8086.1010"
"pci1000,60.17aa.6b7c"
"pci1000,60.15d9.c080"
"pci1000,60.1000.1458"' \
-c scsi mega_sas