mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Initial s390-tools-2.0.0 import
This commit is based on the s390-tools-1.39.0 version. Changes on top of s390-tools-1.39.0: - Add MIT license to all source files - Add LICENSE file - Transform REAMDE to README.md (markdown) - Add AUTHORS.md file - Add CONTRIBUTING.md file - Move changelog from README to CHANGELOG.md file Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
include ../../common.mak
|
||||
|
||||
all: chzcrypt lszcrypt
|
||||
|
||||
libs = $(rootdir)/libutil/libutil.a
|
||||
|
||||
chzcrypt: chzcrypt.o misc.o $(libs)
|
||||
lszcrypt: lszcrypt.o misc.o $(libs)
|
||||
|
||||
install: all
|
||||
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 chzcrypt $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 lszcrypt $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -d -m 755 $(DESTDIR)$(MANDIR)/man8
|
||||
$(INSTALL) -m 644 -c chzcrypt.8 $(DESTDIR)$(MANDIR)/man8
|
||||
$(INSTALL) -m 644 -c lszcrypt.8 $(DESTDIR)$(MANDIR)/man8
|
||||
|
||||
clean:
|
||||
rm -f *.o chzcrypt lszcrypt
|
||||
|
||||
.PHONY: all install clean
|
||||
@@ -0,0 +1,112 @@
|
||||
.\" Copyright 2017 IBM Corp.
|
||||
.\" s390-tools is free software; you can redistribute it and/or modify
|
||||
.\" it under the terms of the MIT license. See LICENSE for details.
|
||||
.\"
|
||||
.TH CHZCRYPT 8 "AUG 2008" "s390-tools"
|
||||
.SH NAME
|
||||
chzcrypt \- modify zcrypt configuration
|
||||
.SH SYNOPSIS
|
||||
.TP 9
|
||||
.B chzcrypt
|
||||
.B -e
|
||||
.RB "|"
|
||||
.B -d
|
||||
.RB "( " -a " | "
|
||||
.I <device id>
|
||||
[...] )
|
||||
.TP
|
||||
.B chzcrypt
|
||||
.RB "[ " -p " | " -n " ] [ " -t
|
||||
.I <timeout>
|
||||
]
|
||||
.TP
|
||||
.B chzcrypt
|
||||
.RB "[ " -c
|
||||
.I <timeout>
|
||||
]
|
||||
.TP
|
||||
.B chzcrypt
|
||||
.RB "[ " -q
|
||||
.I <domain>
|
||||
]
|
||||
.TP
|
||||
.B chzcrypt -h
|
||||
.TP
|
||||
.B chzcrypt -v
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B chzcrypt
|
||||
command is used to configure cryptographic devices managed by zcrypt and
|
||||
modify zcrypt's AP bus attributes.
|
||||
|
||||
Attributes may vary depending on the kernel
|
||||
version.
|
||||
.B chzcrypt
|
||||
requires that the sysfs filesystem is mounted.
|
||||
.SH OPTIONS
|
||||
.TP 8
|
||||
.B -e, --enable
|
||||
Set the given cryptographic device(s) online.
|
||||
.TP 8
|
||||
.B -d, --disable
|
||||
Set the given cryptographic device(s) offline.
|
||||
.TP 8
|
||||
.B -a, --all
|
||||
Set all available cryptographic device(s) online or offline.
|
||||
.TP 8
|
||||
.B <device id>
|
||||
Specifies a cryptographic device which will be set either online or offline.
|
||||
The device can either be a card device or a queue device.
|
||||
|
||||
Please note that the card device and queue device representation are both
|
||||
in hexadecimal notation.
|
||||
.TP 8
|
||||
.B -p, --poll-thread-enable
|
||||
Enable zcrypt's poll thread.
|
||||
.TP 8
|
||||
.B -n, --poll-thread-disable
|
||||
Disable zcrypt's poll thread.
|
||||
.TP 8
|
||||
.BI "-c, --config-time" " <timeout>"
|
||||
Set configuration timer for re-scanning the AP bus to
|
||||
.I <timeout>
|
||||
seconds.
|
||||
.TP 8
|
||||
.BI "-t, --poll-timeout" " <poll_timeout>"
|
||||
Set poll timer to run poll tasklet all
|
||||
.I <poll_timeout>
|
||||
nanoseconds.
|
||||
.TP 8
|
||||
.BI "-q, --default-domain" " <domain>"
|
||||
Set the new default domain of the AP bus to <domain>.
|
||||
The number of available domains can be retrieved with the lszcrypt
|
||||
command ('-d' option).
|
||||
.TP 8
|
||||
.B -V, --verbose
|
||||
Print verbose messages.
|
||||
.TP 8
|
||||
.B -h, --help
|
||||
Print help text and exit.
|
||||
.TP 8
|
||||
.B -v, --version
|
||||
Print version information and exit.
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
.B chzcrypt -e 0 1 12
|
||||
Will set the cryptographic card devices 0, 1 and 12 online.
|
||||
.TP
|
||||
.B chzcrypt -e 01.0038
|
||||
Will set the cryptographic device '10.0038' respectively card id 16
|
||||
(0x10) with domain 56 (0x38) online.
|
||||
.TP
|
||||
.B chzcrypt -d -a
|
||||
Will set all available cryptographic devices offline.
|
||||
.TP
|
||||
.B chzcrypt -c 60 -n
|
||||
Will set configuration timer for re-scanning the AP bus to 60 seconds and
|
||||
disable zcrypt's poll thread.
|
||||
.TP
|
||||
.B chzcrypt -q 67
|
||||
Will set the default domain to 67.
|
||||
.SH SEE ALSO
|
||||
\fBlszcrypt\fR(8)
|
||||
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
* chzcrypt - Tool to modify zcrypt configuration
|
||||
*
|
||||
* Copyright IBM Corp. 2008, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <argz.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lib/util_base.h"
|
||||
#include "lib/util_file.h"
|
||||
#include "lib/util_libc.h"
|
||||
#include "lib/util_opt.h"
|
||||
#include "lib/util_panic.h"
|
||||
#include "lib/util_path.h"
|
||||
#include "lib/util_prg.h"
|
||||
#include "lib/util_scandir.h"
|
||||
#include "lib/zt_common.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
/*
|
||||
* Private data
|
||||
*/
|
||||
struct chzcrypt_l {
|
||||
int verbose;
|
||||
} l;
|
||||
|
||||
struct chzcrypt_l *chzcrypt_l = &l;
|
||||
|
||||
/*
|
||||
* Program configuration
|
||||
*/
|
||||
const struct util_prg prg = {
|
||||
.desc = "Modify zcrypt configuration.",
|
||||
.args = "[DEVICE_IDS]",
|
||||
.copyright_vec = {
|
||||
{
|
||||
.owner = "IBM Corp.",
|
||||
.pub_first = 2008,
|
||||
.pub_last = 2017,
|
||||
},
|
||||
UTIL_PRG_COPYRIGHT_END
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration of command line options
|
||||
*/
|
||||
static struct util_opt opt_vec[] = {
|
||||
{
|
||||
.option = { "enable", no_argument, NULL, 'e'},
|
||||
.argument = "DEVICE_IDS",
|
||||
.desc = "Set the given cryptographic device(s) online"
|
||||
},
|
||||
{
|
||||
.option = { "disable", no_argument, NULL, 'd'},
|
||||
.argument = "DEVICE_IDS",
|
||||
.desc = "Set the given cryptographic device(s) offline",
|
||||
},
|
||||
{
|
||||
.option = { "all", no_argument, NULL, 'a'},
|
||||
.desc = "Set all available cryptographic device(s) "
|
||||
"online/offline, must be used in conjunction "
|
||||
"with the enable or disable option",
|
||||
},
|
||||
{
|
||||
.option = { "poll-thread-enable", no_argument, NULL, 'p'},
|
||||
.desc = "Enable zcrypt's poll thread",
|
||||
},
|
||||
{
|
||||
.option = { "poll-thread-disable", no_argument, NULL, 'n'},
|
||||
.desc = "Disable zcrypt's poll thread",
|
||||
},
|
||||
{
|
||||
.option = { "config-time", required_argument, NULL, 'c'},
|
||||
.argument = "TIMEOUT",
|
||||
.desc = "Set configuration timer for re-scanning the AP bus "
|
||||
"to TIMEOUT seconds",
|
||||
},
|
||||
{
|
||||
.option = { "poll-timeout", required_argument, NULL, 't'},
|
||||
.argument = "TIMEOUT",
|
||||
.desc = "Set poll timer to run poll tasklet all TIMEOUT "
|
||||
"nanoseconds after a request has been queued",
|
||||
},
|
||||
{
|
||||
.option = { "default-domain", required_argument, NULL, 'q'},
|
||||
.argument = "DOMAIN",
|
||||
.desc = "Set new default domain to DOMAIN",
|
||||
},
|
||||
{
|
||||
.option = { "verbose", no_argument, NULL, 'V'},
|
||||
.desc = "Print verbose messages",
|
||||
},
|
||||
UTIL_OPT_HELP,
|
||||
UTIL_OPT_VERSION,
|
||||
UTIL_OPT_END
|
||||
};
|
||||
|
||||
/*
|
||||
* Print if verbose is set
|
||||
*/
|
||||
#define verbose(x...) \
|
||||
do { \
|
||||
if (!l.verbose) \
|
||||
break; \
|
||||
printf(x); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Set poll settings
|
||||
*/
|
||||
static void poll_thread_set(const char *mode_str)
|
||||
{
|
||||
long mode, mode_read = -1;
|
||||
char *attr;
|
||||
|
||||
sscanf(mode_str, "%ld", &mode);
|
||||
if (mode == 1)
|
||||
verbose("Enabling poll thread.\n");
|
||||
else
|
||||
verbose("Disabling poll thread.\n");
|
||||
attr = util_path_sysfs("bus/ap/poll_thread");
|
||||
if (!util_path_is_writable(attr))
|
||||
errx(EXIT_FAILURE, "Error - can't write to %s.\n Wrong permissions"
|
||||
" or wrong tools version.", attr);
|
||||
util_file_write_l(mode, 10, attr);
|
||||
util_file_read_l(&mode_read, 10, attr);
|
||||
if (mode != mode_read)
|
||||
errx(EXIT_FAILURE, "Error - unable to change poll thread setting.");
|
||||
free(attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set timer
|
||||
*/
|
||||
static void config_time_set(const char *timeout_str)
|
||||
{
|
||||
long timeout, timeout_read;
|
||||
char *attr;
|
||||
|
||||
if (sscanf(timeout_str, "%ld", &timeout) != 1) {
|
||||
errx(EXIT_FAILURE, "Error - invalid configuration timeout '%s'.", timeout_str);
|
||||
}
|
||||
attr = util_path_sysfs("bus/ap/config_time");
|
||||
verbose("Setting configuration timer to %ld seconds.\n", timeout);
|
||||
if (!util_path_is_writable(attr))
|
||||
errx(EXIT_FAILURE, "Error - can't write to %s.\n Wrong permissions"
|
||||
" or wrong tools version.", attr);
|
||||
util_file_write_l(timeout, 10, attr);
|
||||
util_file_read_l(&timeout_read, 10, attr);
|
||||
if (timeout != timeout_read)
|
||||
errx(EXIT_FAILURE, "Error - unable to change configuration timer setting.");
|
||||
free(attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set poll timeout
|
||||
*/
|
||||
static void poll_timeout_set(const char *poll_timeout_str)
|
||||
{
|
||||
long poll_timeout, poll_timeout_read;
|
||||
char *attr;
|
||||
|
||||
if (sscanf(poll_timeout_str, "%ld", &poll_timeout) != 1)
|
||||
errx(EXIT_FAILURE, "Error - invalid poll timeout '%s'.", poll_timeout_str);
|
||||
attr = util_path_sysfs("bus/ap/poll_timeout");
|
||||
verbose("Setting poll timeout to %ld seconds.\n", poll_timeout);
|
||||
if (!util_path_is_writable(attr))
|
||||
errx(EXIT_FAILURE, "Error - can't write to %s.\n Wrong permissions"
|
||||
" or wrong tools version.", attr);
|
||||
util_file_write_l(poll_timeout, 10, attr);
|
||||
util_file_read_l(&poll_timeout_read, 10, attr);
|
||||
if (poll_timeout != poll_timeout_read)
|
||||
errx(EXIT_FAILURE, "Error - unable to change poll timeout setting.");
|
||||
free(attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set default domain
|
||||
*/
|
||||
static void default_domain_set(const char *default_domain_str)
|
||||
{
|
||||
long max_dom, default_domain, default_domain_read;
|
||||
char *attr, *ap_max_domain_id;
|
||||
|
||||
sscanf(default_domain_str, "%li", &default_domain);
|
||||
ap_max_domain_id = util_path_sysfs("bus/ap/ap_max_domain_id");
|
||||
util_file_read_l(&max_dom, 10, ap_max_domain_id);
|
||||
if (default_domain < 0 || default_domain > max_dom)
|
||||
errx(EXIT_FAILURE, "Error - invalid default domain '%s'.", default_domain_str);
|
||||
attr = util_path_sysfs("bus/ap/ap_domain");
|
||||
if (!util_path_is_writable(attr))
|
||||
errx(EXIT_FAILURE, "Error - can't write to %s.\n Wrong permissions"
|
||||
" or wrong tools version.", attr);
|
||||
verbose("Setting default domain to %ld.\n", default_domain);
|
||||
util_file_write_l(default_domain, 10, attr);
|
||||
util_file_read_l(&default_domain_read, 10, attr);
|
||||
if (default_domain != default_domain_read)
|
||||
errx(EXIT_FAILURE, "Error - unable to change default domain.");
|
||||
free(ap_max_domain_id);
|
||||
free(attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print invalid commandline error message and then exit with error code
|
||||
*/
|
||||
#define invalid_cmdline_exit(x...) \
|
||||
do { \
|
||||
fprintf(stderr, "%s: ", program_invocation_short_name); \
|
||||
fprintf(stderr, x); \
|
||||
util_prg_print_parse_error(); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Get device list from sysfs
|
||||
*/
|
||||
static void dev_list_all(char **argz, size_t *len)
|
||||
{
|
||||
struct dirent **de_vec;
|
||||
int count, i;
|
||||
char *path;
|
||||
|
||||
path = util_path_sysfs("bus/ap/devices/");
|
||||
count = util_scandir(&de_vec, NULL, path, "card.*");
|
||||
if (count < 0)
|
||||
errx(EXIT_FAILURE, "Error - Could not read directory %s.", path);
|
||||
*argz = NULL;
|
||||
*len = 0;
|
||||
for (i = 0; i < count; i++)
|
||||
util_assert(argz_add(argz, len, de_vec[i]->d_name) == 0,
|
||||
"Out of memory\n");
|
||||
util_scandir_free(de_vec, count);
|
||||
free(path);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get device list from commandline
|
||||
*/
|
||||
static void dev_list_argv(char **argz, size_t *len, char * const argv[])
|
||||
{
|
||||
if (argv[0] == NULL)
|
||||
errx(EXIT_FAILURE, "Need to specify at least one device ID.");
|
||||
|
||||
util_assert(argz_create(argv, argz, len) == 0, "Out of memory\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Describe adapter ids
|
||||
*/
|
||||
void print_adapter_id_help(void)
|
||||
{
|
||||
printf("\n");
|
||||
printf("DEVICE_IDS\n");
|
||||
printf(" List of cryptographic device ids separated by blanks which will be set\n");
|
||||
printf(" online/offline. Must be used in conjunction with the enable or disable option.\n");
|
||||
|
||||
printf(" DEVICE_ID could either be card device id ('<card-id>') or queue device id\n");
|
||||
printf(" '<card-id>.<domain-id>').\n");
|
||||
printf(" \n");
|
||||
printf("EXAMPLE:\n");
|
||||
printf(" Disable the cryptographic device with card id '02' (inclusive all queues).\n");
|
||||
printf(" #>chzcrypt -d 02\n");
|
||||
printf(" \n");
|
||||
printf(" Enable the cryptographic devices with card id '03' and domain id '0005'.\n");
|
||||
printf(" #>chzcrypt -e 03.0005\n");
|
||||
printf(" \n");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse options and execute the command
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *online, *online_text = NULL, *poll_thread, *config_time;
|
||||
const char *poll_timeout, *default_domain;
|
||||
char *path, *dev_path, *dev, *dev_list, device[256], online_read[2];
|
||||
bool all = false, actionset = false;
|
||||
size_t len;
|
||||
int id, dom, c, i, j;
|
||||
|
||||
for (i=0; i < argc; i++)
|
||||
for (j=2; j < (int) strlen(argv[i]); j++)
|
||||
if (argv[i][j] == '_')
|
||||
argv[i][j] = '-';
|
||||
|
||||
online = poll_thread = config_time = poll_timeout = default_domain = NULL;
|
||||
util_prg_init(&prg);
|
||||
util_opt_init(opt_vec, NULL);
|
||||
while (1) {
|
||||
c = util_opt_getopt_long(argc, argv);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'e':
|
||||
actionset = true;
|
||||
online = "1";
|
||||
online_text = "online";
|
||||
break;
|
||||
case 'd':
|
||||
actionset = true;
|
||||
online = "0";
|
||||
online_text = "offline";
|
||||
break;
|
||||
case 'a':
|
||||
all = true;
|
||||
break;
|
||||
case 'p':
|
||||
actionset = true;
|
||||
poll_thread = "1";
|
||||
break;
|
||||
case 'n':
|
||||
actionset = true;
|
||||
poll_thread = "0";
|
||||
break;
|
||||
case 'c':
|
||||
actionset = true;
|
||||
config_time = optarg;
|
||||
break;
|
||||
case 't':
|
||||
actionset = true;
|
||||
poll_timeout = optarg;
|
||||
break;
|
||||
case 'q':
|
||||
actionset = true;
|
||||
default_domain = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
l.verbose = true;
|
||||
break;
|
||||
case 'h':
|
||||
util_prg_print_help();
|
||||
util_opt_print_help();
|
||||
print_adapter_id_help();
|
||||
return EXIT_SUCCESS;
|
||||
case 'v':
|
||||
util_prg_print_version();
|
||||
return EXIT_SUCCESS;
|
||||
default:
|
||||
util_opt_print_parse_error(c, argv);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (!actionset)
|
||||
invalid_cmdline_exit("Error - missing argument.\n");
|
||||
path = util_path_sysfs("bus/ap");
|
||||
if (!util_path_is_dir(path))
|
||||
errx(EXIT_FAILURE, "Crypto device driver not available.");
|
||||
free(path);
|
||||
if (poll_thread) {
|
||||
poll_thread_set(poll_thread);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (config_time) {
|
||||
config_time_set(config_time);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (poll_timeout) {
|
||||
poll_timeout_set(poll_timeout);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (default_domain) {
|
||||
default_domain_set(default_domain);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (all)
|
||||
dev_list_all(&dev_list, &len);
|
||||
else
|
||||
dev_list_argv(&dev_list, &len, &argv[optind]);
|
||||
|
||||
if (online && len == 0)
|
||||
errx(EXIT_FAILURE, "Error - missing cryptographic device id(s).");
|
||||
|
||||
for (dev = dev_list; dev != NULL; dev = argz_next(dev_list, len, dev)) {
|
||||
if (strncmp(dev, "card", 4) == 0) {
|
||||
/* dev == "card2" */
|
||||
sscanf(dev, "card%02x", &id);
|
||||
sprintf(device, "card%02x", id);
|
||||
} else if (strncmp(dev, "0x", 2) == 0) {
|
||||
/* dev == "0x.." */
|
||||
sscanf(dev, "0x%02x", &id);
|
||||
sprintf(device, "card%02x", id);
|
||||
} else if (misc_regex_match(dev, "^[0-9a-fA-F]+$")) {
|
||||
/* dev == "2" */
|
||||
sscanf(dev, "%02x", &id);
|
||||
sprintf(device, "card%02x", id);
|
||||
} else {
|
||||
/* Form: 01.0003 ? */
|
||||
if (sscanf(dev, "%02x.%04x", &id, &dom) != 2)
|
||||
errx(EXIT_FAILURE, "Error - cryptographic device %s malformed.", dev);
|
||||
sprintf(device, "card%02x/%02x.%04x", id, id, dom);
|
||||
}
|
||||
dev_path = util_path_sysfs("bus/ap/devices/%s", device);
|
||||
if (!util_path_is_dir(dev_path))
|
||||
errx(EXIT_FAILURE, "Error - cryptographic device %s does not exist.", device);
|
||||
if (!util_path_is_writable("%s/online", dev_path))
|
||||
continue;
|
||||
verbose("Setting cryptographic device %s %s\n", device, online_text);
|
||||
util_file_write_s(online, "%s/online", dev_path);
|
||||
util_file_read_line(online_read, sizeof(online_read), "%s/online", dev_path);
|
||||
if (strcmp(online, online_read) != 0)
|
||||
errx(EXIT_FAILURE, "Error - unable to set cryptographic device %s %s.", device, online_text);
|
||||
free(dev_path);
|
||||
}
|
||||
free(dev_list);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
.\" lszcrypt.8
|
||||
.\"
|
||||
.\" Copyright 2017 IBM Corp.
|
||||
.\" s390-tools is free software; you can redistribute it and/or modify
|
||||
.\" it under the terms of the MIT license. See LICENSE for details.
|
||||
.\"
|
||||
.\" use
|
||||
.\" groff -man -Tutf8 lszcrypt.8
|
||||
.\" or
|
||||
.\" nroff -man lszcrypt.8
|
||||
.\" to process this source
|
||||
.\"
|
||||
.TH LSZCRYPT 8 "AUG 2008" "s390-tools"
|
||||
.SH NAME
|
||||
lszcrypt \- display zcrypt device and configuration information
|
||||
.SH SYNOPSIS
|
||||
.TP 9
|
||||
.B lszcrypt
|
||||
.RB "[ " -V " ] "
|
||||
[
|
||||
.I <device id>
|
||||
[...]]
|
||||
.TP
|
||||
.B lszcrypt
|
||||
.B -c
|
||||
<device id>
|
||||
.TP
|
||||
.B lszcrypt -b
|
||||
.TP
|
||||
.B lszcrypt -d
|
||||
.TP
|
||||
.B lszcrypt -h
|
||||
.TP
|
||||
.B lszcrypt -v
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B lszcrypt
|
||||
command is used to display information about cryptographic devices managed by
|
||||
zcrypt and the AP bus attributes of zcrypt. Displayed information depends on the
|
||||
kernel version.
|
||||
.B lszcrypt
|
||||
requires that sysfs is mounted.
|
||||
.P
|
||||
The following information can be displayed for each cryptographic
|
||||
device: card ID, domain ID, card type (symbolic), mode, online status,
|
||||
hardware card type (numeric), installed function facilities, card capability,
|
||||
hardware queue depth, request count, number of requests in hardware queue, and
|
||||
the number of outstanding requests.
|
||||
The following AP bus attributes can be displayed: AP domain, Max AP domain,
|
||||
configuration timer, poll thread status, poll timeout, and AP interrupt
|
||||
status.
|
||||
.SH OPTIONS
|
||||
.TP 8
|
||||
.B -V, --verbose
|
||||
The verbose level for cryptographic device information.
|
||||
With this verbose level additional information like hardware card type,
|
||||
hardware queue depth, pending request queue count, outstanding
|
||||
request queue count, and installed function facilities are displayed.
|
||||
.TP 8
|
||||
.B <device id>
|
||||
Specifies a cryptographic device to display. A cryptographic device can be
|
||||
either a card device or a queue device. If no devices are specified information
|
||||
about all available devices is displayed.
|
||||
|
||||
Please note that the card device representation and the queue device are both
|
||||
in hexadecimal notation.
|
||||
.TP 8
|
||||
.B -b, --bus
|
||||
Displays the AP bus attributes and exits.
|
||||
.TP 8
|
||||
.B -c, --capability <card device id>
|
||||
Shows the capabilities of a cryptographic card device of hardware type 6 or
|
||||
higher. The card device id value may be given as decimal or hex value (with
|
||||
a leading 0x). The capabilities of a cryptographic card device depend on
|
||||
the card type and the installed function facilities. A cryptographic card
|
||||
device can provide one or more of the following capabilities:
|
||||
.RS
|
||||
.IP "o" 3
|
||||
RSA 2K Clear Key
|
||||
.IP "o"
|
||||
RSA 4K Clear Key
|
||||
.IP "o"
|
||||
CCA Secure Key
|
||||
.IP "o"
|
||||
EP11 Secure Key
|
||||
.IP "o"
|
||||
Long RNG
|
||||
.RE
|
||||
.TP 8
|
||||
.B -d, --domains
|
||||
Shows the usage and control domains of the cryptographic devices.
|
||||
The displayed domains of the cryptographic device depends on the initial
|
||||
cryptographic configuration.
|
||||
.RS
|
||||
.IP "o" 2
|
||||
'C' indicate a control domain
|
||||
.IP "o"
|
||||
'U' indicate a usage domain
|
||||
.IP "o"
|
||||
'B' indicate both (control and usage domain)
|
||||
.RE
|
||||
.TP 8
|
||||
.B -h, --help
|
||||
Displays help text and exits.
|
||||
.TP 8
|
||||
.B -v, --version
|
||||
Displays version information and exits.
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
.B lszcrypt
|
||||
Displays the card/domain ID, card type (short name), mode (long name), online
|
||||
status and request count of all available cryptographic devices.
|
||||
.TP
|
||||
.B lszcrypt 1 3 5
|
||||
Displays the card/domain ID, card type, mode, online status and request count
|
||||
for cryptographic devices 1, 3, and 5.
|
||||
.TP
|
||||
.B lszcrypt -V 3 7 11
|
||||
Displays the card/domain ID, card type, mode, online status, request count,
|
||||
number of requests in the hardware queue, number of outstanding requests and
|
||||
installed function facilities for cryptographic devices 3, 7 and 17 (0x11).
|
||||
.TP
|
||||
.B lszcrypt 10.0038
|
||||
Displays information of the cryptographic device '10.0038' respectively card
|
||||
id 16 (0x10) with domain 56 (0x38).
|
||||
.TP
|
||||
.B lszcrypt .0038
|
||||
Displays information of all available queue devices (potentially multiple
|
||||
adapters) with domain 56 (0x38).
|
||||
.TP
|
||||
.B lszcrypt -b
|
||||
Displays AP bus information.
|
||||
.TP
|
||||
.B lszcrypt -c 7
|
||||
.RS
|
||||
.br
|
||||
Coprocessor card07 provides capability for:
|
||||
.br
|
||||
CCA Secure Key
|
||||
.br
|
||||
RSA 4K Clear Key
|
||||
.br
|
||||
Long RNG
|
||||
.RE
|
||||
.SH SEE ALSO
|
||||
\fBchzcrypt\fR(8)
|
||||
@@ -0,0 +1,668 @@
|
||||
/**
|
||||
* lszcrypt - Display zcrypt devices and configuration settings
|
||||
*
|
||||
* Copyright IBM Corp. 2008, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/util_base.h"
|
||||
#include "lib/util_file.h"
|
||||
#include "lib/util_opt.h"
|
||||
#include "lib/util_panic.h"
|
||||
#include "lib/util_path.h"
|
||||
#include "lib/util_prg.h"
|
||||
#include "lib/util_proc.h"
|
||||
#include "lib/util_rec.h"
|
||||
#include "lib/util_scandir.h"
|
||||
#include "lib/zt_common.h"
|
||||
|
||||
/*
|
||||
* Private data
|
||||
*/
|
||||
struct lszcrypt_l {
|
||||
int verbose;
|
||||
} l;
|
||||
|
||||
struct lszcrypt_l *lszcrypt_l = &l;
|
||||
|
||||
/*
|
||||
* Capabilities
|
||||
*/
|
||||
#define CAP_RSA2K "RSA 2K Clear Key"
|
||||
#define CAP_RSA4K "RSA 4K Clear Key"
|
||||
#define CAP_CCA "CCA Secure Key"
|
||||
#define CAP_RNG "Long RNG"
|
||||
#define CAP_EP11 "EP11 Secure Key"
|
||||
|
||||
/*
|
||||
* Card types
|
||||
*/
|
||||
#define MASK_APSC 0x80000000
|
||||
#define MASK_RSA4K 0x60000000
|
||||
#define MASK_COPRO 0x10000000
|
||||
#define MASK_ACCEL 0x08000000
|
||||
#define MASK_EP11 0x04000000
|
||||
|
||||
/*
|
||||
* Program configuration
|
||||
*/
|
||||
const struct util_prg prg = {
|
||||
.desc = "Display zcrypt device and configuration information.",
|
||||
.args = "[DEVICE_IDS]",
|
||||
.copyright_vec = {
|
||||
{
|
||||
.owner = "IBM Corp.",
|
||||
.pub_first = 2008,
|
||||
.pub_last = 2017,
|
||||
},
|
||||
UTIL_PRG_COPYRIGHT_END
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration of command line options
|
||||
*/
|
||||
static struct util_opt opt_vec[] = {
|
||||
{
|
||||
.option = {"bus", 0, NULL, 'b'},
|
||||
.desc = "Show AP bus attributes then exit",
|
||||
},
|
||||
{
|
||||
.option = { "capability", required_argument, NULL, 'c'},
|
||||
.argument = "DEVICE_ID",
|
||||
.desc = "Show the capabilities of a cryptographic device",
|
||||
},
|
||||
{
|
||||
.option = {"domains", 0, NULL, 'd'},
|
||||
.desc = "Show the configured AP usage and control domains",
|
||||
},
|
||||
{
|
||||
.option = {"verbose", 0, NULL, 'V'},
|
||||
.desc = "Print verbose messages",
|
||||
},
|
||||
UTIL_OPT_HELP,
|
||||
UTIL_OPT_VERSION,
|
||||
UTIL_OPT_END
|
||||
};
|
||||
|
||||
/*
|
||||
* Show bus
|
||||
*/
|
||||
static void show_bus(void)
|
||||
{
|
||||
long domain, max_domain, config_time, value;
|
||||
unsigned long long poll_timeout;
|
||||
const char *poll_thread, *ap_interrupts;
|
||||
char *ap;
|
||||
|
||||
/* check if ap driver is available */
|
||||
ap = util_path_sysfs("bus/ap");
|
||||
if (!util_path_is_dir(ap))
|
||||
errx(EXIT_FAILURE, "Crypto device driver not available.");
|
||||
|
||||
util_file_read_l(&domain, 10, "%s/ap_domain", ap);
|
||||
util_file_read_l(&max_domain, 10, "%s/ap_max_domain_id", ap);
|
||||
util_file_read_l(&config_time, 10, "%s/config_time", ap);
|
||||
util_file_read_ull(&poll_timeout, 10, "%s/poll_timeout", ap);
|
||||
util_file_read_l(&value, 10, "%s/poll_thread", ap);
|
||||
if (value == 1)
|
||||
poll_thread = "enabled";
|
||||
else
|
||||
poll_thread = "disabled";
|
||||
util_file_read_l(&value, 10, "%s/ap_interrupts", ap);
|
||||
if (value == 1)
|
||||
ap_interrupts = "enabled";
|
||||
else
|
||||
ap_interrupts = "disabled";
|
||||
printf("ap_domain=0x%lx\n", domain);
|
||||
printf("ap_max_domain_id=0x%lx\n", max_domain);
|
||||
if (util_path_is_reg_file("%s/ap_interrupts", ap))
|
||||
printf("ap_interrupts are %s\n", ap_interrupts);
|
||||
printf("config_time=%ld (seconds)\n", config_time);
|
||||
printf("poll_thread is %s\n", poll_thread);
|
||||
if (util_path_is_reg_file("%s/poll_timeout", ap))
|
||||
printf("poll_timeout=%llu (nanoseconds)\n", poll_timeout);
|
||||
free(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print domain array using util_rec
|
||||
*/
|
||||
static void show_domains_util_rec(char *domain_array[])
|
||||
{
|
||||
struct util_rec *rec = util_rec_new_wide("-");
|
||||
char buf[256];
|
||||
int i, x, n;
|
||||
|
||||
util_rec_def(rec, "domain", UTIL_REC_ALIGN_RIGHT, 6, "DOMAIN");
|
||||
for (i = 0; i < 16; i++) {
|
||||
sprintf(buf, "%02x", i);
|
||||
util_rec_def(rec, buf, UTIL_REC_ALIGN_RIGHT, 2, buf);
|
||||
}
|
||||
|
||||
util_rec_print_hdr(rec);
|
||||
n = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
sprintf(buf, "%02x", i * 16);
|
||||
util_rec_set(rec, "domain", buf);
|
||||
for (x = 0; x < 16; x++) {
|
||||
sprintf(buf, "%02x", x);
|
||||
util_rec_set(rec, buf, domain_array[n++]);
|
||||
}
|
||||
util_rec_print(rec);
|
||||
}
|
||||
util_rec_free(rec);
|
||||
printf("------------------------------------------------------\n");
|
||||
printf("C: Control domain\n");
|
||||
printf("U: Usage domain\n");
|
||||
printf("B: Both (Control + Usage domain)\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Show domains
|
||||
*/
|
||||
static void show_domains(void)
|
||||
{
|
||||
char ctrl_domain_mask[67], usag_domain_mask[67], byte_str[3] = {};
|
||||
int ctrl_chunk, usag_chunk;
|
||||
char *ap, *domain_array[32 * 8 + 4];
|
||||
int i, x, n;
|
||||
uint8_t dom_mask_bit;
|
||||
|
||||
/* check if ap driver is available */
|
||||
ap = util_path_sysfs("bus/ap");
|
||||
if (!util_path_is_dir(ap))
|
||||
errx(EXIT_FAILURE, "Crypto device driver not available.");
|
||||
|
||||
util_file_read_line(ctrl_domain_mask, sizeof(ctrl_domain_mask),
|
||||
"%s/ap_control_domain_mask", ap);
|
||||
util_file_read_line(usag_domain_mask, sizeof(usag_domain_mask),
|
||||
"%s/ap_usage_domain_mask", ap);
|
||||
/* remove leading '0x' from domain mask string */
|
||||
memmove(&ctrl_domain_mask[0], &ctrl_domain_mask[2],
|
||||
sizeof(ctrl_domain_mask) - 2);
|
||||
memmove(&usag_domain_mask[0], &usag_domain_mask[2],
|
||||
sizeof(usag_domain_mask) - 2);
|
||||
n = 0;
|
||||
for (i = 0; i < 32; i++) {
|
||||
dom_mask_bit = 0x80;
|
||||
memcpy(byte_str, &ctrl_domain_mask[i * 2], 2);
|
||||
sscanf(byte_str, "%02x", &ctrl_chunk);
|
||||
memcpy(byte_str, &usag_domain_mask[i * 2], 2);
|
||||
sscanf(byte_str, "%02x", &usag_chunk);
|
||||
for (x = 1; x <= 8; x++) {
|
||||
if (ctrl_chunk & dom_mask_bit &&
|
||||
usag_chunk & dom_mask_bit)
|
||||
domain_array[n] = "B"; /* c/u */
|
||||
else if (ctrl_chunk & dom_mask_bit)
|
||||
domain_array[n] = "C";
|
||||
else if (usag_chunk & dom_mask_bit)
|
||||
domain_array[n] = "U";
|
||||
else
|
||||
domain_array[n] = ".";
|
||||
dom_mask_bit = dom_mask_bit >> 1;
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
for (i = n; i < 260; i++)
|
||||
domain_array[n++] = "";
|
||||
|
||||
show_domains_util_rec(domain_array);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show capability
|
||||
*/
|
||||
static void show_capability(const char *id_str)
|
||||
{
|
||||
unsigned long func_val;
|
||||
long hwtype, id;
|
||||
char *p, *ap, *dev, card[7];
|
||||
|
||||
/* check if ap driver is available */
|
||||
ap = util_path_sysfs("bus/ap");
|
||||
if (!util_path_is_dir(ap))
|
||||
errx(EXIT_FAILURE, "Crypto device driver not available.");
|
||||
|
||||
id = strtol(id_str, &p, 0);
|
||||
if (id < 0 || id > 255 || p == id_str || *p != '\0')
|
||||
errx(EXIT_FAILURE, "Error - '%s' is an invalid cryptographic device id.", id_str);
|
||||
snprintf(card, sizeof(card), "card%02lx", id);
|
||||
dev = util_path_sysfs("devices/ap/%s", card);
|
||||
if (!util_path_is_dir(dev))
|
||||
errx(EXIT_FAILURE, "Error - cryptographic device %s does not exist.", card);
|
||||
util_file_read_l(&hwtype, 10, "%s/hwtype", dev);
|
||||
/* If sysfs attribute is missing, set functions to 0 */
|
||||
if (util_file_read_ul(&func_val, 16, "%s/ap_functions", dev))
|
||||
func_val = 0x00000000;
|
||||
/* Skip devices, which are not supported by zcrypt layer */
|
||||
if (!util_path_is_readable("%s/type", dev) ||
|
||||
!util_path_is_readable("%s/online", dev)) {
|
||||
printf("Detailed capability information for %s (hardware type %ld) is not available.\n", card, hwtype);
|
||||
return;
|
||||
}
|
||||
printf("%s provides capability for:\n", card);
|
||||
switch (hwtype) {
|
||||
case 6:
|
||||
case 8:
|
||||
if (func_val & MASK_RSA4K)
|
||||
printf("%s", CAP_RSA4K);
|
||||
else
|
||||
printf("%s", CAP_RSA2K);
|
||||
break;
|
||||
case 7:
|
||||
case 9:
|
||||
printf("%s\n", CAP_RSA4K);
|
||||
printf("%s\n", CAP_CCA);
|
||||
printf("%s", CAP_RNG);
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
if (func_val & MASK_ACCEL) {
|
||||
if (func_val & MASK_RSA4K)
|
||||
printf("%s", CAP_RSA4K);
|
||||
else
|
||||
printf("%s", CAP_RSA2K);
|
||||
} else if (func_val & MASK_COPRO) {
|
||||
printf("%s\n", CAP_RSA4K);
|
||||
printf("%s\n", CAP_CCA);
|
||||
printf("%s", CAP_RNG);
|
||||
} else if (func_val & MASK_EP11) {
|
||||
printf("%s", CAP_EP11);
|
||||
} else {
|
||||
|
||||
printf("Detailed capability information for %s (hardware type %ld) is not available.", card, hwtype);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("Detailed capability information for %s (hardware type %ld) is not available.", card, hwtype);
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Read subdevice default attributes
|
||||
*/
|
||||
static void read_subdev_rec_default(struct util_rec *rec, const char *grp_dev,
|
||||
const char *sub_dev)
|
||||
{
|
||||
unsigned long facility;
|
||||
char buf[256];
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/type", grp_dev);
|
||||
util_rec_set(rec, "type", buf);
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/%s/online", grp_dev, sub_dev);
|
||||
if (strcmp(buf, "0") == 0)
|
||||
util_rec_set(rec, "online", "offline");
|
||||
else
|
||||
util_rec_set(rec, "online", "online");
|
||||
|
||||
util_file_read_ul(&facility, 16, "%s/ap_functions", grp_dev);
|
||||
if (facility & MASK_COPRO)
|
||||
util_rec_set(rec, "mode", "CCA-Coproc");
|
||||
else if (facility & MASK_ACCEL)
|
||||
util_rec_set(rec, "mode", "Accelerator");
|
||||
else if (facility & MASK_EP11)
|
||||
util_rec_set(rec, "mode", "EP11-Coproc");
|
||||
else
|
||||
util_rec_set(rec, "mode", "Unknown");
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/%s/request_count",
|
||||
grp_dev, sub_dev);
|
||||
util_rec_set(rec, "request_count", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read subdevice verbose attributes
|
||||
*/
|
||||
static void read_subdev_rec_verbose(struct util_rec *rec, const char *grp_dev,
|
||||
const char *sub_dev)
|
||||
{
|
||||
unsigned long facility;
|
||||
char buf[256];
|
||||
long depth;
|
||||
|
||||
if (l.verbose == 0)
|
||||
return;
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/%s/pendingq_count",
|
||||
grp_dev, sub_dev);
|
||||
util_rec_set(rec, "pendingq_count", buf);
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/%s/requestq_count",
|
||||
grp_dev, sub_dev);
|
||||
util_rec_set(rec, "requestq_count", buf);
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/hwtype", grp_dev);
|
||||
util_rec_set(rec, "hwtype", buf);
|
||||
|
||||
util_file_read_l(&depth, 10, "%s/depth", grp_dev);
|
||||
util_rec_set(rec, "depth", "%02d", depth + 1);
|
||||
|
||||
util_file_read_ul(&facility, 16, "%s/ap_functions", grp_dev);
|
||||
util_rec_set(rec, "facility", "0x%08x", facility);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show one subdevice
|
||||
*/
|
||||
static void show_subdevice(struct util_rec *rec, const char *grp_dev,
|
||||
const char *sub_dev)
|
||||
{
|
||||
if (!util_path_is_dir("%s/%s", grp_dev, sub_dev))
|
||||
errx(EXIT_FAILURE, "Error - cryptographic device %s/%s does not exist.", grp_dev, sub_dev);
|
||||
|
||||
/* Skip devices, which are not supported by zcrypt layer */
|
||||
if (!util_path_is_readable("%s/type", grp_dev) ||
|
||||
!util_path_is_readable("%s/%s/online", grp_dev, sub_dev))
|
||||
return;
|
||||
|
||||
util_rec_set(rec, "card", sub_dev);
|
||||
read_subdev_rec_default(rec, grp_dev, sub_dev);
|
||||
read_subdev_rec_verbose(rec, grp_dev, sub_dev);
|
||||
|
||||
util_rec_print(rec);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show subdevices
|
||||
*/
|
||||
static void show_subdevices(struct util_rec *rec, const char *grp_dev)
|
||||
{
|
||||
struct dirent **dev_vec;
|
||||
int i, count;
|
||||
|
||||
count = util_scandir(&dev_vec, alphasort, grp_dev, "..\\....");
|
||||
if (count < 1)
|
||||
errx(EXIT_FAILURE, "Error - no subdevices found for %s.\n", grp_dev);
|
||||
for (i = 0; i < count; i++)
|
||||
show_subdevice(rec, grp_dev, dev_vec[i]->d_name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read default attributes
|
||||
*/
|
||||
static void read_rec_default(struct util_rec *rec, const char *grp_dev)
|
||||
{
|
||||
unsigned long facility;
|
||||
char buf[256];
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/type", grp_dev);
|
||||
util_rec_set(rec, "type", buf);
|
||||
|
||||
util_file_read_ul(&facility, 16, "%s/ap_functions", grp_dev);
|
||||
if (facility & MASK_COPRO)
|
||||
util_rec_set(rec, "mode", "CCA-Coproc");
|
||||
else if (facility & MASK_ACCEL)
|
||||
util_rec_set(rec, "mode", "Accelerator");
|
||||
else if (facility & MASK_EP11)
|
||||
util_rec_set(rec, "mode", "EP11-Coproc");
|
||||
else
|
||||
util_rec_set(rec, "mode", "Unknown");
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/online", grp_dev);
|
||||
if (strcmp(buf, "0") == 0)
|
||||
util_rec_set(rec, "online", "offline");
|
||||
else
|
||||
util_rec_set(rec, "online", "online");
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/request_count", grp_dev);
|
||||
util_rec_set(rec, "request_count", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read verbose attributes
|
||||
*/
|
||||
static void read_rec_verbose(struct util_rec *rec, const char *grp_dev)
|
||||
{
|
||||
unsigned long facility;
|
||||
char buf[256];
|
||||
long depth;
|
||||
|
||||
if (l.verbose == 0)
|
||||
return;
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/pendingq_count", grp_dev);
|
||||
util_rec_set(rec, "pendingq_count", buf);
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/requestq_count", grp_dev);
|
||||
util_rec_set(rec, "requestq_count", buf);
|
||||
|
||||
util_file_read_line(buf, sizeof(buf), "%s/hwtype", grp_dev);
|
||||
util_rec_set(rec, "hwtype", buf);
|
||||
|
||||
util_file_read_l(&depth, 10, "%s/depth", grp_dev);
|
||||
util_rec_set(rec, "depth", "%02d", depth + 1);
|
||||
|
||||
util_file_read_ul(&facility, 16, "%s/ap_functions", grp_dev);
|
||||
util_rec_set(rec, "facility", "0x%08x", facility);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show device: device is in the form "card00", "card01", ...
|
||||
*/
|
||||
static void show_device(struct util_rec *rec, const char *device)
|
||||
{
|
||||
char *grp_dev, card[3];
|
||||
|
||||
util_rec_set(rec, "card", card);
|
||||
|
||||
strcpy(card, &device[4]);
|
||||
grp_dev = util_path_sysfs("devices/ap/%s", device);
|
||||
if (!util_path_is_dir(grp_dev))
|
||||
errx(EXIT_FAILURE, "Error - cryptographic device %s does not exist.", device);
|
||||
/* Skip devices, which are not supported by zcrypt layer */
|
||||
if (!util_path_is_readable("%s/type", grp_dev) ||
|
||||
!util_path_is_readable("%s/online", grp_dev)) {
|
||||
goto out_free;
|
||||
}
|
||||
util_rec_set(rec, "card", card);
|
||||
|
||||
read_rec_default(rec, grp_dev);
|
||||
read_rec_verbose(rec, grp_dev);
|
||||
|
||||
util_rec_print(rec);
|
||||
show_subdevices(rec, grp_dev);
|
||||
out_free:
|
||||
free(grp_dev);
|
||||
}
|
||||
|
||||
/*
|
||||
* Define the *default* attributes
|
||||
*/
|
||||
static void define_rec_default(struct util_rec *rec)
|
||||
{
|
||||
util_rec_def(rec, "card", UTIL_REC_ALIGN_LEFT, 11, "CARD.DOMAIN");
|
||||
util_rec_def(rec, "type", UTIL_REC_ALIGN_LEFT, 5, "TYPE");
|
||||
util_rec_def(rec, "mode", UTIL_REC_ALIGN_LEFT, 11, "MODE");
|
||||
util_rec_def(rec, "online", UTIL_REC_ALIGN_LEFT, 7, "STATUS");
|
||||
util_rec_def(rec, "request_count", UTIL_REC_ALIGN_RIGHT, 11,
|
||||
"REQUEST_CNT");
|
||||
}
|
||||
|
||||
/*
|
||||
* Define the *verbose* attributes
|
||||
*/
|
||||
static void define_rec_verbose(struct util_rec *rec)
|
||||
{
|
||||
if (l.verbose == 0)
|
||||
return;
|
||||
util_rec_def(rec, "pendingq_count", UTIL_REC_ALIGN_RIGHT, 12,
|
||||
"PENDINGQ_CNT");
|
||||
util_rec_def(rec, "requestq_count", UTIL_REC_ALIGN_RIGHT, 12,
|
||||
"REQUESTQ_CNT");
|
||||
util_rec_def(rec, "hwtype", UTIL_REC_ALIGN_RIGHT, 7, "HW_TYPE");
|
||||
util_rec_def(rec, "depth", UTIL_REC_ALIGN_RIGHT, 7, "Q_DEPTH");
|
||||
util_rec_def(rec, "facility", UTIL_REC_ALIGN_LEFT, 10, "FUNCTIONS");
|
||||
}
|
||||
|
||||
/*
|
||||
* Show all devices
|
||||
*/
|
||||
static void show_devices_all(void)
|
||||
{
|
||||
struct util_rec *rec = util_rec_new_wide("-");
|
||||
struct dirent **dev_vec;
|
||||
int i, count;
|
||||
char *ap, *path;
|
||||
|
||||
/* check if ap driver is available */
|
||||
ap = util_path_sysfs("bus/ap");
|
||||
if (!util_path_is_dir(ap))
|
||||
errx(EXIT_FAILURE, "Crypto device driver not available.");
|
||||
|
||||
/* Define the record */
|
||||
define_rec_default(rec);
|
||||
define_rec_verbose(rec);
|
||||
|
||||
/* Scan the devices */
|
||||
path = util_path_sysfs("devices/ap/");
|
||||
count = util_scandir(&dev_vec, alphasort, path, "card[0-9a-fA-F]+");
|
||||
if (count < 1)
|
||||
errx(EXIT_FAILURE, "No crypto card devices found.");
|
||||
util_rec_print_hdr(rec);
|
||||
for (i = 0; i < count; i++)
|
||||
show_device(rec, dev_vec[i]->d_name);
|
||||
free(path);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show devices specified on commandline
|
||||
*/
|
||||
static void show_devices_argv(char *argv[])
|
||||
{
|
||||
struct util_rec *rec = util_rec_new_wide("-");
|
||||
struct dirent **dev_vec, **subdev_vec;
|
||||
char *ap, *grp_dev, *path, card[7], sub_dev[7];
|
||||
int id, dom, i, n, dev_cnt, sub_cnt;
|
||||
|
||||
/* check if ap driver is available */
|
||||
ap = util_path_sysfs("bus/ap");
|
||||
if (!util_path_is_dir(ap))
|
||||
errx(EXIT_FAILURE, "Crypto device driver not available.");
|
||||
|
||||
/* Define the record */
|
||||
define_rec_default(rec);
|
||||
define_rec_verbose(rec);
|
||||
|
||||
util_rec_print_hdr(rec);
|
||||
for (i = 0; argv[i] != NULL; i++) {
|
||||
id = -1;
|
||||
dom = -1;
|
||||
if (sscanf(argv[i], "%x.%x", &id, &dom) >= 1) {
|
||||
/* at least the id field was valid */
|
||||
if (id >= 0 && dom >= 0) { /* single subdevice */
|
||||
sprintf(sub_dev, "%02x.%04x", id, dom);
|
||||
grp_dev = util_path_sysfs("devices/ap/card%02x",
|
||||
id);
|
||||
show_subdevice(rec, grp_dev, sub_dev);
|
||||
free(grp_dev);
|
||||
} else { /* group device */
|
||||
sprintf(card, "card%02x", id);
|
||||
show_device(rec, card);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sscanf(argv[i]+1, "%x", &dom) == 1) {
|
||||
/* list specific domains of all adapters */
|
||||
path = util_path_sysfs("devices/ap/");
|
||||
dev_cnt = util_scandir(&dev_vec, alphasort, path,
|
||||
"card[0-9a-fA-F]+");
|
||||
if (dev_cnt < 1)
|
||||
errx(EXIT_FAILURE, "No crypto card devices found.");
|
||||
free(path);
|
||||
for (i = 0; i < dev_cnt; i++) {
|
||||
path = util_path_sysfs("devices/ap/%s",
|
||||
dev_vec[i]->d_name);
|
||||
sub_cnt = util_scandir(&subdev_vec, alphasort,
|
||||
path,
|
||||
"[0-9a-fA-F]+.%04x",
|
||||
dom);
|
||||
if (sub_cnt < 1)
|
||||
errx(EXIT_FAILURE, "No queue devices with given domain value found.");
|
||||
for (n = 0; n < sub_cnt; n++) {
|
||||
show_subdevice(rec, path,
|
||||
subdev_vec[n]->d_name);
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
printf("Invalid adpater id!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Describe adapter ids
|
||||
*/
|
||||
void print_adapter_id_help(void)
|
||||
{
|
||||
printf("\n");
|
||||
printf("DEVICE_IDS\n");
|
||||
printf(" List of cryptographic device ids separated by blanks which will be displayed.\n");
|
||||
printf(" DEVICE_ID could either be card device id ('<card-id>') or queue device id\n");
|
||||
printf(" '<card-id>.<domain-id>'). To filter all devices according to a dedicated\n");
|
||||
printf(" domain just provide '.<domain-id>'.\n");
|
||||
printf(" If no ids are given, all available devices are displayed.\n");
|
||||
printf("\n");
|
||||
printf("EXAMPLE:\n");
|
||||
printf(" List all cryptographic devices with card id '02'.\n");
|
||||
printf(" #>lszcrypt 02\n");
|
||||
printf("\n");
|
||||
printf(" List cryptographic devices with card id '02' and domain id '0005'.\n");
|
||||
printf(" #>lszcrypt 02.0005\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Entry point
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
|
||||
util_prg_init(&prg);
|
||||
util_opt_init(opt_vec, NULL);
|
||||
while (1) {
|
||||
c = util_opt_getopt_long(argc, argv);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'b':
|
||||
show_bus();
|
||||
return EXIT_SUCCESS;
|
||||
case 'c':
|
||||
show_capability(optarg);
|
||||
return EXIT_SUCCESS;
|
||||
case 'd':
|
||||
show_domains();
|
||||
return EXIT_SUCCESS;
|
||||
case 'V':
|
||||
l.verbose++;
|
||||
break;
|
||||
case 'h':
|
||||
util_prg_print_help();
|
||||
util_opt_print_help();
|
||||
print_adapter_id_help();
|
||||
return EXIT_SUCCESS;
|
||||
case 'v':
|
||||
util_prg_print_version();
|
||||
return EXIT_SUCCESS;
|
||||
default:
|
||||
util_opt_print_parse_error(c, argv);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (optind == argc)
|
||||
show_devices_all();
|
||||
else
|
||||
show_devices_argv(&argv[optind]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Misc - Local helper functions
|
||||
*
|
||||
* Copyright IBM Corp. 2016, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <regex.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "lib/util_panic.h"
|
||||
#include "misc.h"
|
||||
|
||||
/**
|
||||
* Test string against regular expression
|
||||
*
|
||||
* @param[in] str String to investigate
|
||||
* @param[in] regex Regular expression
|
||||
*
|
||||
* @returns true String matches with regular expression
|
||||
* false No match
|
||||
*/
|
||||
bool misc_regex_match(const char *str, const char *regex)
|
||||
{
|
||||
regmatch_t pmatch[1];
|
||||
regex_t preg;
|
||||
int rc;
|
||||
|
||||
rc = regcomp(&preg, regex, REG_EXTENDED);
|
||||
util_assert(rc == 0, "The regcomp() function failed: rc = %d\n", rc);
|
||||
|
||||
rc = regexec(&preg, str, (size_t) 1, pmatch, 0);
|
||||
regfree(&preg);
|
||||
return rc == 0 ? true : false;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* misc - Local helper functions
|
||||
*
|
||||
* Copyright IBM Corp. 2016, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool misc_regex_match(const char *str, const char *regex);
|
||||
|
||||
#endif /* MISC_H */
|
||||
Reference in New Issue
Block a user