summaryrefslogtreecommitdiffstats
path: root/ccw_init
blob: 032c2731bf959957e4a0aaf727e9f47aa36eb209 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#! /bin/sh

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

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

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

# borrowed from network-scrips, initscripts along with the get_config_by_subchannel
[ -z "$__sed_discard_ignored_files" ] && __sed_discard_ignored_files='/\(~\|\.bak\|\.old\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'

get_config_by_subchannel ()
{
    LANG=C grep -E -i -l \
        "^[[:space:]]*SUBCHANNELS=['\"]?([0-9]\.[0-9]\.[a-f0-9]+,){0,2}${1}(,[0-9]\.[0-9]\.[a-f0-9]+){0,2}['\"]?([[:space:]]+#|[[:space:]]*$)" \
        /etc/sysconfig/network-scripts/ifcfg-* \
        | LC_ALL=C sed -e "$__sed_discard_ignored_files"
}

get_config_by_subchannel_nm ()
{
    LANG=C grep -E -i -l \
        "^s390-subchannels=([0-9]\.[0-9]\.[a-f0-9]+;){0,2}${1};([0-9]\.[0-9]\.[a-f0-9]+;){0,2}$" \
        /etc/NetworkManager/system-connections/*.nmconnection \
        | LC_ALL=C sed -e "$__sed_discard_ignored_files"
}

CHANNEL=${DEVPATH##*/}

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

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

    IFS=","
    set $CONFIG_LINE
    IFS="$OLD_IFS"
    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"

    CONFIG_FILE=$(get_config_by_subchannel $CHANNEL)

    if [ -n "$CONFIG_FILE" ]; then
	. $CONFIG_FILE
    else
	CONFIG_FILE=$(get_config_by_subchannel_nm $CHANNEL)
	if [ -n "$CONFIG_FILE" ]; then
	    NETTYPE=$(sed -nr "/^\[ethernet\]/ { :l /^s390-nettype[ ]*=/ { s/.*=[ ]*//; p; q;}; n; b l;}" $CONFIG_FILE)
	    SUBCHANNELS=$(sed -nr "/^\[ethernet\]/ { :l /^s390-subchannels[ ]*=/ { s/.*=[ ]*//; p; q;}; n; b l;}" $CONFIG_FILE | sed -e "s/;/,/g" -e "s/,$//")
	    LAYER2=$(sed -nr "/^\[ethernet-s390-options\]/ { :l /^layer2[ ]*=/ { s/.*=[ ]*//; p; q;}; n; b l;}" $CONFIG_FILE)
	else
	    exit 1
	fi
    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
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=$CTCPROT"
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

IFS=","
set $SUBCHANNELS
IFS="$OLD_IFS"
CHANNEL1=$1
CHANNEL2=$2
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

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