#!/bin/bash
#
# Deconfigures a ccw interface.
# $Id: hwdown-ccw,v 1.4 2004/04/29 15:08:54 hare Exp $
#
# Currently handles ctc, qeth, and dasd devices.
# lcs and escon support untested.
# 

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

# Read in common functions
. ./scripts/functions


if test -z "$SYSFS"; then
    mesg sysfs not mounted, aborting.
    exit 1
fi

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

# Set defaults
if [ -z "$HWD_DEVPATH" ]; then
    HWD_DEVPATH=${SYSFS}/bus/ccwgroup/devices/${HWD_BUSID}
fi

if [ ! -d "$HWD_DEVPATH" ]; then
    message "$SCRIPTNAME: No hardware devicepath given, cannot configure"
    exit 1
fi

if [ -z "$CCW_CHAN_NUM" ] ; then
    CCW_CHAN_NUM="1"
fi

# Deconfigure interface
if test "$CCW_CHAN_NUM" -gt 1 ; then
    read _online < $HWD_DEVPATH/online
    # Device group configured, set it offline
    if [ $_online -ne 0 ]; then
	echo "0" > $HWD_DEVPATH/online
	message "$SCRIPTNAME: Device group $HWD_BUSID offline"
    fi
    # We cannot use hotplug events here as the
    # devices are already gone from sysfs
    echo "1" > $HWD_DEVPATH/ungroup
    message "$SCRIPTNAME: Device group $HWD_BUSID deconfigured"
else
    echo "0" > $HWD_DEVPATH/online
    if [ -w $HWD_DEVPATH/use_diag ]; then
	echo "0" > $HWD_DEVPATH/use_diag
    fi
    message "$SCRIPTNAME: Device $HWD_BUSID offline"
fi
