Skip to content

Commit

Permalink
s390/zcrypt: Separate msgtype implementation from card modules.
Browse files Browse the repository at this point in the history
Msgtype implementations are now separated from card specific modules
and can be dynamically registered. Existing msgtype implementations
are restructured in modules.

Signed-off-by: Holger Dengler <hd@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Holger Dengler authored and Martin Schwidefsky committed Sep 26, 2012
1 parent b26bd94 commit 5e55a48
Show file tree
Hide file tree
Showing 10 changed files with 1,707 additions and 1,124 deletions.
1 change: 1 addition & 0 deletions drivers/s390/crypto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
ap-objs := ap_bus.o
obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o zcrypt_pcicc.o zcrypt_pcixcc.o
obj-$(CONFIG_ZCRYPT) += zcrypt_pcica.o zcrypt_cex2a.o
obj-$(CONFIG_ZCRYPT) += zcrypt_msgtype6.o zcrypt_msgtype50.o
73 changes: 70 additions & 3 deletions drivers/s390/crypto/zcrypt_api.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* zcrypt 2.1.0
*
* Copyright IBM Corp. 2001, 2006
* Copyright IBM Corp. 2001, 2012
* Author(s): Robert Burroughs
* Eric Rossman (edrossma@us.ibm.com)
* Cornelia Huck <cornelia.huck@de.ibm.com>
*
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
* Ralph Wuerthner <rwuerthn@de.ibm.com>
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -44,8 +45,8 @@
* Module description.
*/
MODULE_AUTHOR("IBM Corporation");
MODULE_DESCRIPTION("Cryptographic Coprocessor interface, "
"Copyright IBM Corp. 2001, 2006");
MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \
"Copyright IBM Corp. 2001, 2012");
MODULE_LICENSE("GPL");

static DEFINE_SPINLOCK(zcrypt_device_lock);
Expand All @@ -56,6 +57,9 @@ static atomic_t zcrypt_open_count = ATOMIC_INIT(0);
static int zcrypt_rng_device_add(void);
static void zcrypt_rng_device_remove(void);

static DEFINE_SPINLOCK(zcrypt_ops_list_lock);
static LIST_HEAD(zcrypt_ops_list);

/*
* Device attributes common for all crypto devices.
*/
Expand Down Expand Up @@ -215,6 +219,8 @@ int zcrypt_device_register(struct zcrypt_device *zdev)
{
int rc;

if (!zdev->ops)
return -ENODEV;
rc = sysfs_create_group(&zdev->ap_dev->device.kobj,
&zcrypt_device_attr_group);
if (rc)
Expand Down Expand Up @@ -269,6 +275,67 @@ void zcrypt_device_unregister(struct zcrypt_device *zdev)
}
EXPORT_SYMBOL(zcrypt_device_unregister);

void zcrypt_msgtype_register(struct zcrypt_ops *zops)
{
if (zops->owner) {
spin_lock_bh(&zcrypt_ops_list_lock);
list_add_tail(&zops->list, &zcrypt_ops_list);
spin_unlock_bh(&zcrypt_ops_list_lock);
}
}
EXPORT_SYMBOL(zcrypt_msgtype_register);

void zcrypt_msgtype_unregister(struct zcrypt_ops *zops)
{
spin_lock_bh(&zcrypt_ops_list_lock);
list_del_init(&zops->list);
spin_unlock_bh(&zcrypt_ops_list_lock);
}
EXPORT_SYMBOL(zcrypt_msgtype_unregister);

static inline
struct zcrypt_ops *__ops_lookup(unsigned char *name, int variant)
{
struct zcrypt_ops *zops;
int found = 0;

spin_lock_bh(&zcrypt_ops_list_lock);
list_for_each_entry(zops, &zcrypt_ops_list, list) {
if ((zops->variant == variant) &&
(!strncmp(zops->owner->name, name, MODULE_NAME_LEN))) {
found = 1;
break;
}
}
spin_unlock_bh(&zcrypt_ops_list_lock);

if (!found)
return NULL;
return zops;
}

struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *name, int variant)
{
struct zcrypt_ops *zops = NULL;

zops = __ops_lookup(name, variant);
if (!zops) {
request_module(name);
zops = __ops_lookup(name, variant);
}
if ((!zops) || (!try_module_get(zops->owner)))
return NULL;
return zops;
}
EXPORT_SYMBOL(zcrypt_msgtype_request);

void zcrypt_msgtype_release(struct zcrypt_ops *zops)
{
if (zops)
module_put(zops->owner);
}
EXPORT_SYMBOL(zcrypt_msgtype_release);

/**
* zcrypt_read (): Not supported beyond zcrypt 1.3.1.
*
Expand Down
10 changes: 9 additions & 1 deletion drivers/s390/crypto/zcrypt_api.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* zcrypt 2.1.0
*
* Copyright IBM Corp. 2001, 2006
* Copyright IBM Corp. 2001, 2012
* Author(s): Robert Burroughs
* Eric Rossman (edrossma@us.ibm.com)
* Cornelia Huck <cornelia.huck@de.ibm.com>
*
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
* Ralph Wuerthner <rwuerthn@de.ibm.com>
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -87,6 +88,9 @@ struct zcrypt_ops {
struct ica_rsa_modexpo_crt *);
long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *);
long (*rng)(struct zcrypt_device *, char *);
struct list_head list; /* zcrypt ops list. */
struct module *owner;
int variant;
};

struct zcrypt_device {
Expand Down Expand Up @@ -116,6 +120,10 @@ void zcrypt_device_get(struct zcrypt_device *);
int zcrypt_device_put(struct zcrypt_device *);
int zcrypt_device_register(struct zcrypt_device *);
void zcrypt_device_unregister(struct zcrypt_device *);
void zcrypt_msgtype_register(struct zcrypt_ops *);
void zcrypt_msgtype_unregister(struct zcrypt_ops *);
struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *, int);
void zcrypt_msgtype_release(struct zcrypt_ops *);
int zcrypt_api_init(void);
void zcrypt_api_exit(void);

Expand Down
Loading

0 comments on commit 5e55a48

Please sign in to comment.