Import version 1.8.3
[s390-tools.git] / zconf / lszcrypt
bloba0c947379a31ae484fcc28b2e295c9ab1cce6cf9
1 #!/bin/bash
2 #==============================================================================
3 # Copyright IBM Corp. 2008.
5 # lszcrypt
7 # Script to display zcrypt devices and configuration settings.
9 # Author(s): Ralph Wuerthner <rwuerthn@de.ibm.com>
10 # Felix Beck <felix.beck@de.ibm.com>
12 # This file is part of s390-tools
14 # s390-tools is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # s390-tools is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with s390-tools; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #==============================================================================
29 CMD="$( basename $0 )"
31 function print_usage() {
32 cat <<-EOF
33 Usage: $CMD [<options>] [<cryptographic adapter ids>]
34 Display zcrypt device and configuration information.
36 <options>
37 -b|--bus
38 Show AP bus attributes and exit.
39 -V|--verbose
40 Increase verbose level for cryptographic adapter information. Maximum
41 verbose level is two.
42 -v|--version
43 Show version information and exit.
44 -h|--help
45 Show this help text and exit.
47 <cryptographic adapter ids>
48 List of cryptographic adapter ids separated by blanks which will be displayed.
49 If not ids are given all available adapters are displayed.
50 EOF
53 function print_version() {
54 cat <<-EOF
55 $CMD: version %S390_TOOLS_VERSION%
56 Copyright IBM Corp. 2007
57 EOF
60 invalid_cmdline() {
61 echo "$CMD: $*" >&2
62 echo "Try '$CMD --help' for more information." >&2
63 exit 1
66 show_bus() {
67 AP="$SYSFS/bus/ap"
68 DOMAIN="$( cat $AP/ap_domain 2> /dev/null )"
69 CONFIG_TIME="$( cat $AP/config_time 2> /dev/null )"
70 POLL_TIMEOUT="$( cat $AP/poll_timeout 2> /dev/null )"
71 if [ "$( cat $AP/poll_thread 2> /dev/null )" -eq 1 ] ; then
72 POLL_THREAD="enabled"
73 else
74 POLL_THREAD="disabled"
76 if [ "$( cat $AP/ap_interrupts 2> /dev/null )" -eq 1 ] ; then
77 AP_INTERRUPTS="enabled"
78 else
79 AP_INTERRUPTS="disabled"
81 echo "ap_domain=$DOMAIN"
82 if [ -f "$AP/ap_interrupts" ] ; then
83 echo "ap_interrupts are $AP_INTERRUPTS"
85 echo "config_time=$CONFIG_TIME (seconds)"
86 echo "poll_thread is $POLL_THREAD"
87 if [ -f "$AP/poll_timeout" ] ; then
88 echo "poll_timeout=$POLL_TIMEOUT (nanoseconds)"
92 show_device() {
93 CARD="$1"
94 DEV="$SYSFS/bus/ap/devices/$CARD"
95 if [ ! -d "$DEV" ] ; then
96 echo "$CMD: error - cryptographic adapter $CARD does not exist!" >&2
97 exit 1
99 if [ -r $DEV/type ] ; then
100 TYPE="$( cat $DEV/type 2> /dev/null )"
101 else
102 TYPE=unknown
104 if [ -r $DEV/online ] ; then
105 if [ "$( cat $DEV/online 2> /dev/null )" -eq 0 ] ; then
106 ONLINE=offline
107 else
108 ONLINE=online
110 else
111 ONLINE=unknown
113 case $VERBOSE in
114 0) echo "$CARD: $TYPE"
116 1) printf "%s: %-11s %-7s\n" $CARD $TYPE $ONLINE
119 HWTYPE="$( cat $DEV/hwtype 2> /dev/null )"
120 DEPTH="$( cat $DEV/depth 2> /dev/null )"
121 REQ_CNT="$( cat $DEV/request_count 2> /dev/null )"
122 printf "%s: %-11s %-7s hwtype=%-2d depth=%d request_count=%-10d\n" \
123 $CARD $TYPE $ONLINE $HWTYPE $DEPTH $REQ_CNT
124 esac
127 # Parse command line
128 TEMP=`getopt -o bhvV \
129 --long bus,help,version,verbose \
130 -n "$CMD" -- "$@"`
131 if [ $? != 0 ] ; then
132 exit 1
134 eval set -- "$TEMP"
136 SHOW_BUS=
137 VERBOSE=0
138 while true ; do
139 case "$1" in
140 -b|--bus) SHOW_BUS=1
141 shift;;
142 -h|--help) print_usage
143 exit 0;;
144 -v|--version) print_version
145 exit 0;;
146 -V|--verbose) let VERBOSE++
147 shift;;
148 --) shift; break;;
149 *) echo "Internal error!" ; exit 1;;
150 esac
151 done
153 # Check sysfs and zcrypt availability
154 if [ -z "$( cat /proc/filesystems | grep sysfs )" ] ; then
155 echo "$CMD: error - sysfs support required!" >&2
156 exit 1
158 SYSFS="$( cat /proc/mounts | awk '$3=="sysfs" { print $2 ; exit }' )"
159 if [ -z "$SYSFS" ] ; then
160 echo "$CMD: error - sysfs filesystem must be mounted!" >&2
161 exit 1
163 if [ ! -d "$SYSFS/bus/ap" ] ; then
164 echo "$CMD: error - cryptographic device driver zcrypt is not loaded!" >&2
165 exit 1
168 if [ -n "$SHOW_BUS" ] ; then
169 show_bus
170 exit 0
173 if [ $# -eq 0 ] ; then
174 DEVLIST="$( find $SYSFS/bus/ap/devices -name 'card*' -printf '%f\n' | sort )"
175 for CARD in $DEVLIST ; do
176 show_device $CARD
177 done
178 else
179 for ID in "$@" ; do
180 CARD="$( printf "card%02x" "$ID" 2> /dev/null )"
181 if [ $? -ne 0 ] ; then
182 invalid_cmdline "error - '$ID' is an invalid cryptographic adapter id!"
184 show_device $CARD
185 done