OpenSolaris_b135/pkgdefs/common_files/i.pmcsconf

#!/bin/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 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

PATH=/usr/bin:/usr/sbin:$PATH; export PATH
PREFIX=/tmp/pmcs.conf.$$

add_comment_for_vhci_class()
{
	if grep "^# As a pHCI driver, pmcs must spec" $1 > /dev/null 2>&1; then
		return
	fi
	cat >> $1 << EOF
#
# As a pHCI driver, pmcs must specify the vHCI class it belongs to (scsi_vhci).
#
EOF
}

add_comment_for_mpxio_disable()
{
	if grep "^# By default, MPxIO will be enabled" $1 > /dev/null 2>&1; then
		return
	fi
	cat >> $1 << EOF
#
# By default, MPxIO will be enabled on all pmcs controllers. To disable MPxIO
# for all pmcs controllers, set:
#
#mpxio-disable="yes";

#
# You can disable MPxIO on a per-HBA basis.  Per port settings override the
# global setting for the specified ports. To disable MPxIO for the controller
# whose unit-address is 0 and whose parent is /pci@0/pci10de,5d@e, set:
#
#name="pmcs" parent="/pci@0/pci10de,5d@e" unit-address="0" mpxio-disable="yes";

EOF
}

add_comment_for_debug()
{
	if grep "^# Global debug settings may be set " $1 > /dev/null 2>&1; then
		return
	fi
	cat >> $1 << EOF
#
# Global debug settings may be set using the 'pmcs-debug-mask' property.
# Any combination of values may be set according to the following:
#
# 0x0001 - Basic info; shouldn't print anything during normal operation
# 0x0002 - Small amount of I/O information during normal operation
# 0x0004 - Much more info during I/O; will impact performance
# 0x0008 - Very verbose at all times; definitely a performance impact
# 0x0010 - Debug information with regard to discovery/configuration
# 0x0020 - Debug information with regard to iport
# 0x0040 - Debug information with regard to map
# 0x0080 - Report on SCSI underflow status
# 0x0100 - Report SCSI status for every command
# 0x0200 - PHY lock/unlock debug (very noisy)
# 0x0400 - Debug information with regard to device state
#
pmcs-debug-mask=0x71;

EOF
}

update_pmcsconf()
{
	NEWHDR1=$PREFIX.hdr1
	NEWHDR2=$PREFIX.hdr2
	TMPFILE=$PREFIX.tmp
	
	# replace old copyright with new one	
	HEADER="^#.* Copyright.*Sun Microsystems.*$"
	if grep "$HEADER" $1 > $NEWHDR1 2>/dev/null; then
		# replace / by \/
		sed "s/\\//\\\\\\//g" $NEWHDR1 > $NEWHDR2 2>/dev/null
		if sed "s/$HEADER/`cat $NEWHDR2`/" $2 > $TMPFILE 2>/dev/null
		then
			cp $TMPFILE $2
		fi
	fi

	# ddi-vhci-class: Add comment
	add_comment_for_vhci_class $2

	# ddi-vhci-class: Add property
	grep '^ddi-vhci-class' $2 > /dev/null 2>&1
	if [ $? != 0 ] ; then
		# add the property
		echo 'ddi-vhci-class="scsi_vhci";' >> $2
		echo '' >> $2
	fi

	# mpxio-disable: Add comment
	add_comment_for_mpxio_disable $2

	# pmcs-debug-mask: Add comment
	add_comment_for_debug $2

	rm -f $NEWHDR1 $NEWHDR2 $TMPFILE
}

if read src dest; then
	if [ ! -f $dest ]; then
		cp $src $dest
	else
		# upgrading solaris
		update_pmcsconf $src $dest
	fi

fi

exit 0