summaryrefslogtreecommitdiffstats
path: root/ccw_init
blob: 42bc0427e73815f62fcce3bfe1f096cc32ce6ae2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#! /bin/sh

[ -z "$DEVPATH" ] && exit 0
[ "$SUBSYSTEM" != "ccw" ] && exit 0

[ -e /etc/ccw.conf ] && MODE="dracut" || MODE="normal"

get_config_line_by_subchannel()
{
    local CHANNEL
    CHANNEL="$1"
    while read line; do
        IFS=,
        set $line
        for i in $@; do
            if [ "$CHANNEL" = "$i" ]; then
                echo $line
                return 0
             fi
        done
    done < /etc/ccw.conf
    return 1
}

CHANNEL=${DEVPATH##*/}

if [ $MODE = "dracut" ]; then
    CONFIG_LINE=$(get_config_line_by_subchannel $CHANNEL)

    [ $? -ne 0 -o -z "$CONFIG_LINE" ] && break

    set $CONFIG_LINE
    NETTYPE=$1
    shift
    SUBCHANNELS="$1"
    OPTIONS=""
    shift
    while [ $# -gt 0 ]; do
        case $1 in
            *=*) OPTIONS="$OPTIONS $1";;
            [0-9]*) SUBCHANNELS="$SUBCHANNELS,$1";;
        esac
        shift
    done
elif [ $MODE = "normal" ]; then
    NOLOCALE="yes"

    . /etc/sysconfig/network-scripts/network-functions

    CONFIG_FILE=$(get_config_by_subchannel $CHANNEL)

    if [ -n "$CONFIG_FILE" ]; then
	. $CONFIG_FILE
    else
	exit 1
    fi
else
    echo "Unknown mode=$MODE"
    exit 1
fi


# now we have extracted these variables from the config files:
# SUBCHANNELS
# OPTIONS

# put LAYER2 option into its own variable
ORIG_OPTIONS=$OPTIONS
set $OPTIONS
OPTIONS=""
while [ $# -gt 0 ]; do
    case $1 in
        layer2=*) LAYER2=${1##layer2=};;
        *=*) OPTIONS="$OPTIONS $1";;
    esac
    shift
done

# translate variables from the interface config files to OPTIONS
if [ -n "$PORTNAME" ]; then
        if [ "$NETTYPE" = "lcs" ]; then
		OPTIONS="$OPTIONS portno=$PORTNAME"
        else
		OPTIONS="$OPTIONS portname=$PORTNAME"
        fi
fi
if [ "$NETTYPE" = "ctc" -a -n "$CTCPROT" ]; then
	OPTIONS="$OPTIONS protocol=$CTCPROTO"
fi

# SUBCHANNELS is only set on mainframe ccwgroup devices
[ -z "$SUBCHANNELS" -o -z "$NETTYPE" ] && exit 0
if [ "$NETTYPE" = "ctc" ]; then
    DIR="/sys/bus/ccwgroup/drivers/ctcm"
else
    DIR="/sys/bus/ccwgroup/drivers/$NETTYPE"
fi

i=0
while [ $i -lt 20 ]; do
    [ -e $DIR ] && break
    sleep 0.1
    i=$(($i+1))
done

# driver missing or not loaded
[ ! -e $DIR ] && exit 0

CHANNEL1=${SUBCHANNELS//,*/}
SYSDIR="$DIR/$CHANNEL1"

[ -e $SYSDIR ] && exit 0

# check if the interface is already online
if [ -e $SYSDIR/online ]; then
    read on <$SYSDIR/online
    [ "$on" = "1" ] && exit 0
fi

DRIVER=$(readlink $DEVPATH/driver)
DRIVER=${DRIVER##*/}
CHANNEL2=${SUBCHANNELS##*,}
if [ "$DRIVER" = "lcs" -a "$NETTYPE" = "ctc" ]; then
    echo "$CHANNEL" > /sys/bus/ccw/drivers/lcs/unbind
    echo "$CHANNEL" > /sys/bus/ccw/drivers/ctcm/bind
    echo "$CHANNEL2" > /sys/bus/ccw/drivers/lcs/unbind
    echo "$CHANNEL2" > /sys/bus/ccw/drivers/ctcm/bind
fi
if [ "$DRIVER" = "ctcm" -a "$NETTYPE" = "lcs" ]; then
    echo "$CHANNEL" > /sys/bus/ccw/drivers/ctcm/unbind
    echo "$CHANNEL" > /sys/bus/ccw/drivers/lcs/bind
    echo "$CHANNEL2" > /sys/bus/ccw/drivers/ctcm/unbind
    echo "$CHANNEL2" > /sys/bus/ccw/drivers/lcs/bind
fi

if [ ! -e $SYSDIR ]; then
    echo "$SUBCHANNELS" > $DIR/group
    i=0
    while [ $i -lt 20 ]; do
        [ -e $SYSDIR ] && break
        sleep 0.1
        i=$(($i+1))
    done

    [ ! -e $SYSDIR ] && exit 1
fi

# check if the interface is already online
if [ -e $SYSDIR/online ]; then
    read on <$SYSDIR/online
    [ "$on" = "1" ] && exit 0
fi

# first set layer2, other options may depend on it
[ -n "$LAYER2" ] && echo $LAYER2 > $SYSDIR/layer2

if [ -n "$OPTIONS" ]; then
    for i in $OPTIONS; do
	OPT=${i%%=*}
	VAL=${i##*=}
	if [ -e "$SYSDIR/$OPT" ]; then
    	    echo "$VAL" > "$SYSDIR/$OPT" || \
            echo "Could not set value \"$VAL\" for OPTION \"$OPT\" with SUBCHANNELS \"$SUBCHANNELS\""
        else
    	    echo "OPTION \"$OPT\" does not exist for SUBCHANNELS \"$SUBCHANNELS\""
        fi
    done
fi

[ -e $SYSDIR/online ] && echo 1 > $SYSDIR/online