#!/bin/bash
#
# hwup-ctc
# $Id: hwup-ctc,v 1.5 2004/04/29 15:08:54 hare Exp $
#
# Configuration script for CTC devices
# Sets the protocol mode if configured and 
# sets the adapter online
#

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

# Read in common functions
. ./scripts/functions

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

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

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

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

# Check whether the channel group is configured
if test "$CCW_CHAN_NUM" -gt 1 -a -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
	    echo "$CCW_CHAN_MODE" > $_ccwgroup_dir/protocol
	else
	    CCW_CHAN_MODE=0
	fi
	echo "1" > $_ccwgroup_dir/online
	message "$SCRIPTNAME: Device $HWD_BUSID activated (proto $CCW_CHAN_MODE)"
    else
	message "$SCRIPTNAME: Device $HWD_BUSID is online, cannot configure!"
    fi
else
    message "$SCRIPTNAME: Device group $HWD_BUSID not configured!"
fi

#EOF
