2
#==============================================================================
3
# Copyright IBM Corp. 2007
7
# Script to modify channel-path state.
9
# Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
11
# This file is part of s390-tools
13
# s390-tools is free software; you can redistribute it and/or modify
14
# it under the terms of the GNU General Public License as published by
15
# the Free Software Foundation; either version 2 of the License, or
16
# (at your option) any later version.
18
# s390-tools is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with s390-tools; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#==============================================================================
29
VERSION="%S390_TOOLS_VERSION%"
38
Usage: ${TOOLNAME} COMMAND CHPID
40
Modify the state of channel-path CHPID. CHPID can be a single, hexadecimal
41
channel-path identifier, a comma-separated list or a range of identifiers.
44
-v, --vary VALUE Logically vary channel-path to VALUE (1=on, 0=off)
45
-c, --configure VALUE Configure channel-path to VALUE (1=on, 0=standby)
46
-a, --attribute KEY=VALUE Set channel-path attribute KEY to VALUE
47
-h, --help Print this help, then exit
48
--version Print version information, then exit
52
# Print version information
53
function print_version()
56
${TOOLNAME}: version ${VERSION}.
57
Copyright IBM Corp. 2007
61
# Print channel-path directory
62
function get_chp_dir()
66
DIR=$(printf "%s/devices/css%x/chp%x.%x" "$SYSFS" "$1" "$1" "$2")
67
if [ ! -d $DIR ] ; then
68
DIR=$(printf "%s/devices/css%x/chp%x.%02x" "$SYSFS" "$1" "$1" \
74
# Write and check attribute value
75
function write_value()
82
if [ ! -f $DIR/$KEY ] ; then
83
echo "failed - no such attribute"
86
if [ ! -w $DIR/$KEY ] ; then
87
echo "failed - attribute not writable"
90
if ! echo $VAL > $DIR/$KEY ; then
91
echo "failed - write failed"
94
if ! read < $DIR/$KEY VAL2 ; then
95
echo "failed - could not determine new attribute value"
98
# Skip value comparison for 'status' attribute because input
99
# can be specified in different ways
100
if [ "$KEY" != "status" ] ; then
101
if [ "$VAL" != "$VAL2" ] ; then
102
echo "failed - attribute value not as expected"
109
# Configure channel-path
117
if [ "$VAL" == "0" ] ; then
123
printf "Configure %s %x.%02x... " $OP $CSS $NUM
124
write_value $DIR "configure" $VAL
134
if [ "$4" == "0" ] ; then
140
printf "Vary %s %x.%02x... " $VAL $CSS $NUM
141
write_value $DIR "status" $VAL
144
# Modify channel-path attribute
153
printf "Attribute %s=%s %x.%02x... " $KEY $VAL $CSS $NUM
154
write_value $DIR $KEY $VAL
157
# Make sure only one command is specified
158
function check_and_set_command()
160
if [ ! -z "$COMMAND" ] ; then
161
echo "$TOOLNAME: Only one of --vary, --configure or " \
162
"--attribute allowed" >&2
168
# Make sure command argument was specified correctly
169
function check_and_set_value()
171
if [ -z "$1" ] ; then
172
echo "$TOOLNAME: --${COMMAND} requires an argument" >&2
175
if [ "$COMMAND" == "attribute" ] ; then
179
if [ "$KEY" == "$1" ] || [ -z "$KEY" ] || [ -z "$VAL" ] ; then
180
echo "$TOOLNAME: --attribute requires an argument " \
188
# Extract css id from channel-path id string
189
function get_chpid_css()
197
if [ "$CSS" == "$CHPID" ] ; then
200
let RESULT="0x$CSS" 2>/dev/null
201
if [ -z "$RESULT" ] ; then
202
echo "$TOOLNAME: Invalid channel-path identifier " \
206
if [ "$RESULT" -lt 0 ] || [ $RESULT -gt $MAX_CHPID_CSS ] ; then
207
echo "$TOOLNAME: Invalid channel-path identifier " \
215
# Extract id from channel-path id string
216
function get_chpid_id()
224
let RESULT="0x$ID" 2>/dev/null
225
if [ -z "$RESULT" ] ; then
226
echo "$TOOLNAME: Invalid channel-path identifier '$CHPID'" >&2
229
if [ "$RESULT" -lt 0 ] || [ $RESULT -gt $MAX_CHPID_ID ] ; then
230
echo "$TOOLNAME: Invalid channel-path identifier '$CHPID'" >&2
236
# Perform command specified by COMMAND and VALUE
237
function perform_command()
243
DIR=$(get_chp_dir "$CSS" "$ID")
244
if [ ! -d "$DIR" ] ; then
245
printf "Skipping unknown channel-path "
246
printf "%x.%02x\n" $CSS $ID
251
vary $CSS $ID $DIR $VALUE
254
configure $CSS $ID $DIR $VALUE
257
attribute $CSS $ID $DIR $VALUE
262
# Calculate iterator steps for chpid loop
263
function get_iterator_step()
272
if [ $CSS1 -eq $CSS2 ] ;then
273
if [ $ID1 -le $ID2 ] ; then
278
elif [ $CSS1 -lt $CSS2 ] ; then
287
function loop_chpids()
296
get_iterator_step STEP $1 $2 $3 $4
300
eval $FUNC $CSS1 $ID1
302
if [ $CSS1 -eq $CSS2 ] && [ $ID1 -eq $ID2 ] ; then
307
if [ $ID1 -lt 0 ] ; then
310
elif [ $ID2 -gt 255 ] ; then
317
# Parse command line parameters
321
while [ $# -gt 0 ]; do
332
check_and_set_command "vary"
333
check_and_set_value "$2"
337
check_and_set_command "configure"
338
check_and_set_value "$2"
342
check_and_set_command "attribute"
343
check_and_set_value "$2"
347
echo "$TOOLNAME: Invalid option $1" >&2
348
echo "Try '$TOOLNAME --help' for more information" >&2
352
if [ -z "$CHPID_LIST" ] ; then
355
CHPID_LIST="$CHPID_LIST,$1"
362
if [ -z "$COMMAND" ] ; then
363
echo "$TOOLNAME: One of --vary, --configure or --attribute required" >&2
367
if [ -z "$CHPID_LIST" ] ; then
368
echo "$TOOLNAME: Need to specify at least one channel-path ID" >&2
372
if [ ! -e "$SYSFS" ] ; then
373
echo "$TOOLNAME: $SYSFS does not exist" >&2
377
if [ ! -d "$SYSFS" ] ; then
378
echo "$TOOLNAME: $SYSFS is not a directory" >&2
382
# Loop over comma-separated list
384
for CHPID in $CHPID_LIST ; do
385
if [ -z "$CHPID" ] ; then
388
CHPID_FROM=${CHPID%%-*}
389
if [ "$CHPID" == "$CHPID_FROM" ] ; then
392
CHPID_TO=${CHPID##*-}
393
if [ -z "$CHPID_TO" ] ; then
394
echo "$TOOLNAME: Invalid channel-path identifier " \
399
get_chpid_css FROM_CSS $CHPID_FROM
400
get_chpid_id FROM_ID $CHPID_FROM
401
get_chpid_css TO_CSS $CHPID_TO
402
get_chpid_id TO_ID $CHPID_TO
403
loop_chpids $FROM_CSS $FROM_ID $TO_CSS $TO_ID perform_command