-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctc_configure
More file actions
executable file
·262 lines (232 loc) · 7.7 KB
/
ctc_configure
File metadata and controls
executable file
·262 lines (232 loc) · 7.7 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#! /bin/bash
#
# ctc_configure
#
# Configures a CTC device
#
# Usage:
# ctc_configure <read channel> <write channel> <online> [<protocol>]
#
# read/write channel = x.y.ssss where
# x is always 0 until IBM creates something that uses that number
# y is the logical channel subsystem (lcss) number. Most often this is 0, but it could be non-zero
# ssss is the four digit subchannel address of the device, in hexidecimal, with leading zeros.
# online = 0 to take the device offline
# 1 to bring the device online
# protocol = 0 Compatibility with peers other than OS/390®, or z/OS, for example, a z/VM TCP service machine. This is the default.
# 1 Enhanced package checking for Linux peers.
# 3 For compatibility with OS/390 or z/OS peers.
# 4 For MPC connections to VTAM on traditional mainframe operating systems.
#
# Return values:
# 1 sysfs not mounted
# 2 Invalid status for <online>
# 3 No device found for read-channel
# 4 No device found for write-channel
# 5 Invalid device type
# 6 Device type mismatch
# 7 Could not load module
# 8 CCW devices grouped different devices
# 9 Could not group devices
# 10 Could not set device online
# 11 Could not set device offline
#
if [ "${DEBUG}" != "yes" ]; then
DEBUG="no"
fi
DATUM=$(date)
add_channel_for_cio() {
echo "$* # $DATUM" >> /boot/zipl/active_devices.txt
}
remove_channel_for_cio() {
[ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^$1/d" /boot/zipl/active_devices.txt
}
mesg () {
echo "$@"
}
exit_on_err() {
if [ "$2" == "online" ]; then
_state="10"
else
_state="11"
fi
case "$1" in
0) return 0 ;;
5) exit 6 ;;
21) exit 7 ;;
28) exit 8 ;;
31) exit 9 ;;
*) exit $_state ;;
esac
}
debug_mesg () {
case "$DEBUG" in
yes) mesg "$@" ;;
*) ;;
esac
}
# Get the mount point for sysfs
grep -qe ^'sysfs /sys' < /proc/mounts
if [ $? -ne 0 ]; then
mesg "/sysfs not present"
exit 1
fi
if [ $# -lt 3 ] ; then
echo "Usage: $0 <read channel> <write channel> <online> [<protocol>]"
echo " read/write channel = x.y.ssss where"
echo " x is always 0 until IBM creates something that uses that number"
echo " y is the logical channel subsystem (lcss) number. Most often this is 0, but it could be non-zero"
echo " ssss is the four digit subchannel address of the device, in hexidecimal, with leading zeros."
echo " online = 0 to take the device offline"
echo " 1 to bring the device online"
echo " protocol = 0 Compatibility with peers other than OS/390®, or z/OS, for example, a z/VM TCP service machine. This is the default."
echo " 1 Enhanced package checking for Linux peers."
echo " 3 For compatibility with OS/390 or z/OS peers."
echo " 4 For MPC connections to VTAM on traditional mainframe operating systems."
exit 1
fi
CTC_READ_CHAN=$1
CTC_WRITE_CHAN=$2
ONLINE=$3
CTC_MODE=$4
[ -z "$CTC_MODE" ] && CTC_MODE=0
if [ -z "$ONLINE" ] || [ "$ONLINE" -ne "1" -a "$ONLINE" -ne "0" ]; then
mesg "Invalid device status $ONLINE"
exit 2
fi
_ccw_dir=/sys/bus/ccw/devices
debug_mesg "Configuring CTC/LCS device ${CTC_READ_CHAN}/${CTC_WRITE_CHAN}"
if test ! -d "$_ccw_dir/$CTC_READ_CHAN" ; then #to be replaced
mesg "device $_ccw_dir/$CTC_READ_CHAN does not exist"
exit 3
fi
if test ! -d "$_ccw_dir/$CTC_WRITE_CHAN" ; then #to be replaced
mesg "device $_ccw_dir/$CTC_WRITE_CHAN does not exist"
exit 4
fi
CCW_CHAN_GROUP= #to be replaced
for ccw in $_ccw_dir/$CTC_READ_CHAN $_ccw_dir/$CTC_WRITE_CHAN; do
read _cu_type < $ccw/cutype
read _dev_type < $ccw/devtype
case "$_cu_type" in
3088/01)
# P/390 network adapter
CCW_CHAN_NAME="cu3088"
CCW_CHAN_GROUP="lcs"
;;
3088/08)
# Channel To Channel
CCW_CHAN_NAME="cu3088"
CCW_CHAN_GROUP="ctcm"
;;
3088/1e)
# FICON adapter
CCW_CHAN_NAME="cu3088"
CCW_CHAN_GROUP="ctcm"
;;
3088/1f)
# ESCON adapter (I.e. hardware CTC device)
CCW_CHAN_NAME="cu3088"
CCW_CHAN_GROUP="ctcm"
;;
3088/60)
# Lan Channel Station
CCW_CHAN_NAME="cu3088"
CCW_CHAN_GROUP="lcs"
;;
*)
CCW_CHAN_NAME=
;;
esac
if [ -z "$CCW_CHAN_NAME" ]; then
mesg "Not a valid CTC device (cu $_cutype, dev $_devtype)"
exit 5
fi
[ -z "$tmp_chan" ] && tmp_chan=$CCW_CHAN_GROUP
done
if [ "$tmp_chan" != "$CCW_CHAN_GROUP" ] ; then
mesg "CTC type mismatch (read: $tmp_chan, write: $CCW_CHAN_GROUP)"
exit 6
fi
_ccw_groupdir=/sys/bus/ccwgroup
# Check for grouping
_ccw_status_dir=
if [ -e ${_ccw_dir}/${CTC_READ_CHAN}/group_device ] ; then #to be replaced
_ccw_status_dir=$(cd -P ${_ccw_dir}/${CTC_READ_CHAN}/group_device; echo $PWD)
fi
if [ -e ${_ccw_dir}/${CTC_WRITE_CHAN}/group_device ] ; then #to be replaced
_tmp_status_dir=$(cd -P ${_ccw_dir}/${CTC_READ_CHAN}/group_device; echo $PWD)
if [ "$_ccw_status_dir" ] && [ "$_ccw_status_dir" != "$_tmp_status_dir" ] ; then #to be replaced
mesg "CCW devices grouped to different devices"
exit 8
fi
_ccw_status_dir=$_tmp_status_dir
fi
#
# Addresses are free (but may be bound to the wrong driver)
#
_ccw_drivers=/sys/bus/ccw/drivers #to be replaced
for i in ${CTC_READ_CHAN} ${CTC_WRITE_CHAN}
do
if [ "$CCW_CHAN_GROUP" = "lcs" ]
then
if [ -e "${_ccw_drivers}/ctcm/${i}" ] ; then
echo $i > ${_ccw_drivers}/ctcm/unbind
fi
if [ ! -e "${_ccw_drivers}/lcs/${i}" ] ; then
echo $i > ${_ccw_drivers}/ctcm/bind
fi
else
if [ -e "${_ccw_drivers}/lcs/${i}" ] ; then
echo $i > ${_ccw_drivers}/lcs/unbind
fi
if [ ! -e "${_ccw_drivers}/ctcm/${i}" ] ; then
echo $i > ${_ccw_drivers}/ctcm/bind
fi
fi
done
debug_mesg "Group is ${_ccw_groupdir}/drivers/${CCW_CHAN_GROUP}/group" #to be replaced
if [ -z "$_ccw_status_dir" ] ; then #to be replaced
echo "$CTC_READ_CHAN,$CTC_WRITE_CHAN" > ${_ccw_groupdir}/drivers/${CCW_CHAN_GROUP}/group
if [ -e ${_ccw_dir}/${CTC_READ_CHAN}/group_device ] ; then
_ccw_status_dir=$(cd -P ${_ccw_dir}/${CTC_READ_CHAN}/group_device; echo $PWD)
fi
fi
if [ -z "$_ccw_status_dir" -o ! -e "$_ccw_status_dir" ] ; then #to be replaced
mesg "Could not group $CCW_CHAN_GROUP devices $CTC_READ_CHAN/$CTC_WRITE_CHAN"
exit 9
fi
CCW_CHAN_ID=${_ccw_status_dir##*/}
read _ccw_dev_status < $_ccw_status_dir/online #to be replaced
if [ "$ONLINE" -eq 1 ]; then
# Set the device online
debug_mesg "Setting device online"
chzdev --enable ctc $CTC_READ_CHAN:$CTC_WRITE_CHAN protocol=$CTC_MODE
exit_on_err $? online
else
if [ "$_ccw_dev_status" -eq 1 ]; then
# Set the device offline
debug_mesg "Setting device offline"
chzdev --disable ctc $CTC_READ_CHAN:$CTC_WRITE_CHAN
exit_on_err $? offline
fi
# Always reset CTC Protocol
if [ "$CCW_CHAN_GROUP" != "lcs" ]; then
chzdev -q $CTC_READ_CHAN:$CTC_WRITE_CHAN protocol=0
fi
fi
if [ -d "$RULES_DIR" ]; then
remove_channel_for_cio "$CTC_READ_CHAN"
remove_channel_for_cio "$CTC_WRITE_CHAN"
if [ "$ONLINE" -eq "1" ]; then
add_channel_for_cio "$CTC_READ_CHAN,$CTC_WRITE_CHAN"
fi
fi
#check for 51-type rules
if [ -a /etc/udev/rules.d/51-ctcm-$CTC_READ_CHAN.rules ]; then
rm -rf /etc/udev/rules.d/51-ctcm-$CTC_READ_CHAN.rules
#re-check, if there are any 51-rules
if [ -a /etc/udev/rules.d/51-ctcm-$CTC_READ_CHAN.rules ]; then
echo "/etc/udev/rules.d/51-ctcm-$CTC_READ_CHAN.rules could not be deleted."
fi
fi