#!/bin/sh -c "echo This script should not be run directly.; exit 1"
################################################################
# Myricom GM networking software and documentation
# Copyright 2001, 2002 by Myricom, Inc.
# All rights reserved.  See the file `COPYING' for copyright notice.
################################################################
# authors: maxstern@myri.com, glenn@myri.com
# $Source: /repository/gm/drivers/aix/gm_arch_install,v $
################################################################
# Required entry points
################################################################

# Make sure we find the right tools on this machine, regardless of
# the user's path.
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/bin/X11
export PATH

gm_aix_gm_devnames=/dev/null
gm_aix_version_checked=0

gm_arch_install_program=cp
gm_arch_driver_start_command="/usr/local/etc/rc.d/gm start"

gm_arch_stop_gm ()
{
    gm_aix_find_devnames
    for devname in ${gm_aix_gm_devnames}
    do
	gm_verbose_echo "`date`"
	gm_echo Stopping GM driver for ${devname} -- please stand by.
	gm_arch_stop_ethernet
	gm_do rmdev -l ${devname}
    done
}

gm_arch_start_gm ()
{
    gm_aix_find_devnames
    for devname in ${gm_aix_gm_devnames}
    do
	devstat=`lsdev -C -r status -l ${devname}`
	if test x$devstat = xAvailable
	then
	    gm_arch_stop_gm
	fi
    done
    gm_verbose_echo "`date`"
    gm_echo Starting GM driver -- please stand by.
    gm_aix_check_version || return $?
    gm_do sync  || return $?
    for devname in ${gm_aix_gm_devnames}
    do
	gm_do cfgmgr -v -l ${devname} || return $?
    done
}

gm_arch_stop_ethernet ()
{
    # Return without doing anything for now.
    gm_echo Not stopping ethernet emulation -- must be done by hand
    return 0

    # The real code might look something like this:
    gm_aix_find_devnames
    for devname in ${gm_aix_gm_devnames}
    do
	netname=`echo "${devname}" | sed -e 's/ent/en/'`
	gm_verbose_echo "`date`"
	gm_echo Stopping ethernet emulation for ${netname} -- please stand by.
	gm_do /etc/ifconfig ${netname} down > /dev/null 2>&1
	gm_do /etc/ifconfig ${netname} detach > /dev/null 2>&1
    done
}

gm_arch_start_ethernet ()
{
    # Return without doing anything for now.
    gm_echo Not starting ethernet emulation -- must be done by hand
    return 0

    # The real code might look something like this:
    gm_aix_find_devnames
    for devname in ${gm_aix_gm_devnames}
    do
	netname=`echo "${devname}" | sed -e 's/ent/en/'`
	gm_verbose_echo "`date`"
	gm_echo Starting ethernet emulation for ${netname} -- please stand by.
	ifconfig ${netname} $IPADDR up
    done
}

gm_arch_install_ethernet ()
{
    gm_verbose_echo "`date`"
    true

#   gm_mkdir /usr/local/etc/rc.d \
#   && gm_cp ${prefix}/etc/init.d/myri /usr/local/etc/rc.d/myri \
#   && gm_do sync \
#   && gm_log_uninstall_command "/usr/local/etc/rc.d/myri stop"
}

gm_arch_install_gm ()
{
    if test "$gm_verbose" = 0
    then
        installp_flag=""
    else
        installp_flag="-V4"
    fi
    gm_verbose_echo "`date`"
    gm_aix_check_version \
    && gm_mkdir /usr/local/etc/rc.d \
    && gm_do installp -acFNqX -d ${prefix}/sbin/image ${installp_flag} devices.pci.c1144380.rte \
    && gm_cp ${prefix}/etc/init.d/gm /usr/local/etc/rc.d/gm \
    && gm_do sync \
    && gm_log_uninstall_command "/usr/local/etc/rc.d/gm stop"
}

################################################################
# AIX-specific functions
################################################################

gm_aix_check_version ()
{
    if test $gm_aix_version_checked != 0
    then
	return 0
    fi

#   We support AIX 4.3 and AIX 5; v.r = 4.3 or v.r = 5.*
    aix_version=`uname -v`
    aix_release=`uname -r`
    gm_verbose_echo "aix_version = $aix_version"
    gm_verbose_echo "aix_release = $aix_release"
    if (test "$aix_version" = "4") && (test "$aix_release" = "3")
    then
	status=0
    elif test "$aix_version" = "5"
    then
	status=0
    else	
	gm_echo AIX-"$aix_version"."$aix_release" is not supported by this GM release.
	status=1
    fi
    gm_aix_version_checked=1
    return $status
}


gm_aix_find_devnames ()
{
#   Find all the device names of Myrinet devices.

    if test x"$GM_DEVNAME" = x
    then
        gm_aix_gm_devnames=`lsdev -C -t gmpci -r name'` \
        || gm_die "You must set GM_DEVNAME to the device you want to configure"
    else
        gm_aix_gm_devnames="$GM_DEVNAME"
    fi
    if test x"$gm_aix_gm_devnames" = x
    then
	gm_die "No Myrinet device found - set GM_DEVNAME to the device you want to configure"
    fi
}
