0b15456
#!/bin/sh
0b15456
0b15456
# config file syntax:
0b15456
# deviceno   sysfs_opts...
0b15456
#
0b15456
# Examples:
0b15456
# 0.0.0203 readonly=1 failfast=1
0b15456
# 0.0.0204
0b15456
# 0.0.0205 erplog=1
0b15456
0b15456
[ -z "$DEVPATH" ] && exit 0
0b15456
[ "$ACTION" != "add" ] && exit 0
0b15456
0b15456
CHANNEL=${DEVPATH##*/}
0b15456
0b15456
CONFIG=/etc/dasd.conf
0b15456
PATH=/sbin:/bin
0b15456
export PATH
0b15456
0b15456
warn() {
0b15456
    [ -e /dev/kmsg ] && echo "<4>dasdconf.sh Warning: $@" > /dev/kmsg
0b15456
    echo "dasdconf.sh Warning: $@" >&2
0b15456
}
0b15456
0b15456
if [ -f "$CONFIG" ]; then
0b15456
    if [ ! -d /sys/bus/ccw/drivers/dasd-eckd ] && [ ! -d /sys/bus/ccw/drivers/dasd-fba ]; then
0b15456
	#warn "No dasd-eckd or dasd-eckd loaded"
0b15456
        exit 0
0b15456
    fi
0b15456
    sed 'y/ABCDEF/abcdef/' < $CONFIG | while read line; do
0b15456
        case $line in
0b15456
            \#*) ;;
0b15456
            *)
0b15456
                [ -z "$line" ] && continue
0b15456
                set $line
0b15456
0b15456
		# if we are in single add mode, only add the new CHANNEL
0b15456
		[ "$SUBSYSTEM" = "ccw" ] && [ "$1" != "$CHANNEL" ] && continue
0b15456
0b15456
                DEVICE=$1
0b15456
                SYSFSPATH=
0b15456
0b15456
                if [ -r "/sys/bus/ccw/drivers/dasd-eckd/$DEVICE" ]; then
0b15456
                    SYSFSPATH="/sys/bus/ccw/drivers/dasd-eckd/$DEVICE"
0b15456
                elif [ -r "/sys/bus/ccw/drivers/dasd-fba/$DEVICE" ]; then
0b15456
                    SYSFSPATH="/sys/bus/ccw/drivers/dasd-fba/$DEVICE"
0b15456
                else
0b15456
		    # if we are in single add mode, this is a failure!
0b15456
		    [ "$SUBSYSTEM" = "ccw" ] && warn "Could not find $DEVICE in sysfs"
0b15456
                    continue
0b15456
                fi
0b15456
0b15456
		# skip already onlined devices
0b15456
		if [ "$(cat $SYSFSPATH/online)" = "1" ]; then
0b15456
		    if [ "$SUBSYSTEM" = "ccw" ]; then
0b15456
		        # if we are in single add mode, we should not touch the device
0b15456
			warn "$DEVICE is already online, not configuring"
0b15456
			exit 0
0b15456
		    fi
0b15456
		    continue
0b15456
		fi
0b15456
0b15456
                shift
0b15456
                while [ -n "$1" ]; do
0b15456
                    (
0b15456
                        attribute="$1"
0b15456
                        IFS="="
0b15456
                        set $attribute
0b15456
0b15456
                        if [ "$1" = "use_diag" ]; then
0b15456
			    # this module better only returns after
0b15456
			    # all sysfs entries have the "use_diag" file
0b15456
                            modprobe dasd_diag_mod
0b15456
                        fi
0b15456
0b15456
                        if [ -r "$SYSFSPATH/$1" ]; then
0b15456
                            echo $2 > $SYSFSPATH/$1 || warn "Could not set $1=$2 for $DEVICE"
0b15456
                        else
0b15456
			    warn "$1 does not exist for $DEVICE"
0b15456
                        fi
0b15456
                    )
0b15456
                    shift
0b15456
                done
0b15456
		
0b15456
		# Now, put the device online
0b15456
                echo 1 > $SYSFSPATH/online || echo "Could not activate $DEVICE"
0b15456
0b15456
		# if we are in single add mode, we are done
0b15456
		[ "$SUBSYSTEM" = "ccw" ] && exit 0
0b15456
                ;;
0b15456
        esac
0b15456
    done
0b15456
fi
0b15456
exit 0