#!/bin/bash
#
# hwup-lcs
# $Id: hwup-lcs 1415 2006-02-16 09:16:36Z hare $
#
# Configuration script for LCS devices
# Sets the port number if configured and 
# sets the adapter online
#

SCRIPTNAME=${0##*/}
HWDESC=$1

# Read in common functions
. ./scripts/functions
test -r ./config && . ./config

# Check for variables
if test -z "$SYSFS"; then
    message "sysfs not mounted, aborting."
    exit 1
fi

if [ -z "$DEVPATH" ]; then
    message "no device path given, aborting."
    exit 1
fi

# Read in the configuration file
. ./hwcfg-${HWDESC}

# Set sysfs paths
_ccwgroup_dir=${SYSFS}${DEVPATH}

# Check whether the channel group is configured
message_n "Configuring device ${_ccwgroup_dir##*/}: "
if test -d "$_ccwgroup_dir" ; then
    read _online < $_ccwgroup_dir/online
    # We do not check for the value of CCW_CHAN_MODE, since we
    # might want to switch back and forth between several modes
    if test "$_online" -eq "0" ; then
	if [ "$CCW_CHAN_MODE" ]; then
	    message_n "(port $CCH_CHAN_MODE) "
	    echo "$CCW_CHAN_MODE" > $_ccwgroup_dir/portno
	else
	    CCW_CHAN_MODE=0
	fi
	if [ "$LCS_LANCMD_TIMEOUT" ]; then
	    message_n "(timeout $LCS_LANCMD_TIMEOUT) "
	    echo "$LCS_LANCMD_TIMEOUT" > $_ccwgroup_dir/lancmd_timeout
	else
	    LCS_LANCMD_TIMEOUT=0
	fi
	echo "1" > $_ccwgroup_dir/online
	message "ok."
    else
	message "already online."
    fi
else
    message "not available."
fi

#EOF
