Commit 236fb2ab authored by Martin Schwidefsky's avatar Martin Schwidefsky

s390/zcrypt: simplify message type handling

Now that the message type modules are linked with the zcrypt_api
into a single module the zcrypt_ops_list is initialized by
the module init function of the zcyppt.ko module. After that
the list is static and all message types are present.

Drop the zcrypt_ops_list_lock spinlock and the module handling
in regard to the message types.
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent fc1d3f02
...@@ -71,7 +71,6 @@ EXPORT_SYMBOL(zcrypt_rescan_req); ...@@ -71,7 +71,6 @@ EXPORT_SYMBOL(zcrypt_rescan_req);
static int zcrypt_rng_device_add(void); static int zcrypt_rng_device_add(void);
static void zcrypt_rng_device_remove(void); static void zcrypt_rng_device_remove(void);
static DEFINE_SPINLOCK(zcrypt_ops_list_lock);
static LIST_HEAD(zcrypt_ops_list); static LIST_HEAD(zcrypt_ops_list);
static debug_info_t *zcrypt_dbf_common; static debug_info_t *zcrypt_dbf_common;
...@@ -318,61 +317,25 @@ EXPORT_SYMBOL(zcrypt_device_unregister); ...@@ -318,61 +317,25 @@ EXPORT_SYMBOL(zcrypt_device_unregister);
void zcrypt_msgtype_register(struct zcrypt_ops *zops) void zcrypt_msgtype_register(struct zcrypt_ops *zops)
{ {
spin_lock_bh(&zcrypt_ops_list_lock);
list_add_tail(&zops->list, &zcrypt_ops_list); 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) void zcrypt_msgtype_unregister(struct zcrypt_ops *zops)
{ {
spin_lock_bh(&zcrypt_ops_list_lock);
list_del_init(&zops->list); list_del_init(&zops->list);
spin_unlock_bh(&zcrypt_ops_list_lock);
} }
EXPORT_SYMBOL(zcrypt_msgtype_unregister);
static inline struct zcrypt_ops *zcrypt_msgtype(unsigned char *name, int variant)
struct zcrypt_ops *__ops_lookup(unsigned char *name, int variant)
{ {
struct zcrypt_ops *zops; struct zcrypt_ops *zops;
int found = 0;
spin_lock_bh(&zcrypt_ops_list_lock); list_for_each_entry(zops, &zcrypt_ops_list, list)
list_for_each_entry(zops, &zcrypt_ops_list, list) {
if ((zops->variant == variant) && if ((zops->variant == variant) &&
(!strncmp(zops->name, name, sizeof(zops->name)))) { (!strncmp(zops->name, name, sizeof(zops->name))))
found = 1; return zops;
break; return NULL;
}
}
if (!found || !try_module_get(zops->owner))
zops = NULL;
spin_unlock_bh(&zcrypt_ops_list_lock);
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("%s", name);
zops = __ops_lookup(name, variant);
}
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); EXPORT_SYMBOL(zcrypt_msgtype);
/** /**
* zcrypt_read (): Not supported beyond zcrypt 1.3.1. * zcrypt_read (): Not supported beyond zcrypt 1.3.1.
......
...@@ -133,8 +133,7 @@ int zcrypt_device_register(struct zcrypt_device *); ...@@ -133,8 +133,7 @@ int zcrypt_device_register(struct zcrypt_device *);
void zcrypt_device_unregister(struct zcrypt_device *); void zcrypt_device_unregister(struct zcrypt_device *);
void zcrypt_msgtype_register(struct zcrypt_ops *); void zcrypt_msgtype_register(struct zcrypt_ops *);
void zcrypt_msgtype_unregister(struct zcrypt_ops *); void zcrypt_msgtype_unregister(struct zcrypt_ops *);
struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *, int); struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
void zcrypt_msgtype_release(struct zcrypt_ops *);
int zcrypt_api_init(void); int zcrypt_api_init(void);
void zcrypt_api_exit(void); void zcrypt_api_exit(void);
......
...@@ -122,8 +122,7 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev) ...@@ -122,8 +122,7 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
} }
if (!zdev) if (!zdev)
return -ENODEV; return -ENODEV;
zdev->ops = zcrypt_msgtype_request(MSGTYPE50_NAME, zdev->ops = zcrypt_msgtype(MSGTYPE50_NAME, MSGTYPE50_VARIANT_DEFAULT);
MSGTYPE50_VARIANT_DEFAULT);
zdev->ap_dev = ap_dev; zdev->ap_dev = ap_dev;
zdev->online = 1; zdev->online = 1;
ap_device_init_reply(ap_dev, &zdev->reply); ap_device_init_reply(ap_dev, &zdev->reply);
...@@ -131,7 +130,6 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev) ...@@ -131,7 +130,6 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
rc = zcrypt_device_register(zdev); rc = zcrypt_device_register(zdev);
if (rc) { if (rc) {
ap_dev->private = NULL; ap_dev->private = NULL;
zcrypt_msgtype_release(zdev->ops);
zcrypt_device_free(zdev); zcrypt_device_free(zdev);
} }
return rc; return rc;
...@@ -144,10 +142,8 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev) ...@@ -144,10 +142,8 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
static void zcrypt_cex2a_remove(struct ap_device *ap_dev) static void zcrypt_cex2a_remove(struct ap_device *ap_dev)
{ {
struct zcrypt_device *zdev = ap_dev->private; struct zcrypt_device *zdev = ap_dev->private;
struct zcrypt_ops *zops = zdev->ops;
zcrypt_device_unregister(zdev); zcrypt_device_unregister(zdev);
zcrypt_msgtype_release(zops);
} }
int __init zcrypt_cex2a_init(void) int __init zcrypt_cex2a_init(void)
......
...@@ -102,8 +102,8 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev) ...@@ -102,8 +102,8 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
CEX4A_MAX_MOD_SIZE_2K; CEX4A_MAX_MOD_SIZE_2K;
} }
zdev->short_crt = 1; zdev->short_crt = 1;
zdev->ops = zcrypt_msgtype_request(MSGTYPE50_NAME, zdev->ops = zcrypt_msgtype(MSGTYPE50_NAME,
MSGTYPE50_VARIANT_DEFAULT); MSGTYPE50_VARIANT_DEFAULT);
} else if (ap_test_bit(&ap_dev->functions, AP_FUNC_COPRO)) { } else if (ap_test_bit(&ap_dev->functions, AP_FUNC_COPRO)) {
zdev = zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE); zdev = zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE);
if (!zdev) if (!zdev)
...@@ -120,8 +120,8 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev) ...@@ -120,8 +120,8 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
zdev->max_mod_size = CEX4C_MAX_MOD_SIZE; zdev->max_mod_size = CEX4C_MAX_MOD_SIZE;
zdev->max_exp_bit_length = CEX4C_MAX_MOD_SIZE; zdev->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
zdev->short_crt = 0; zdev->short_crt = 0;
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME, zdev->ops = zcrypt_msgtype(MSGTYPE06_NAME,
MSGTYPE06_VARIANT_DEFAULT); MSGTYPE06_VARIANT_DEFAULT);
} else if (ap_test_bit(&ap_dev->functions, AP_FUNC_EP11)) { } else if (ap_test_bit(&ap_dev->functions, AP_FUNC_EP11)) {
zdev = zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE); zdev = zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE);
if (!zdev) if (!zdev)
...@@ -138,8 +138,8 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev) ...@@ -138,8 +138,8 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
zdev->max_mod_size = CEX4C_MAX_MOD_SIZE; zdev->max_mod_size = CEX4C_MAX_MOD_SIZE;
zdev->max_exp_bit_length = CEX4C_MAX_MOD_SIZE; zdev->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
zdev->short_crt = 0; zdev->short_crt = 0;
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME, zdev->ops = zcrypt_msgtype(MSGTYPE06_NAME,
MSGTYPE06_VARIANT_EP11); MSGTYPE06_VARIANT_EP11);
} }
break; break;
} }
...@@ -151,7 +151,6 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev) ...@@ -151,7 +151,6 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
ap_dev->private = zdev; ap_dev->private = zdev;
rc = zcrypt_device_register(zdev); rc = zcrypt_device_register(zdev);
if (rc) { if (rc) {
zcrypt_msgtype_release(zdev->ops);
ap_dev->private = NULL; ap_dev->private = NULL;
zcrypt_device_free(zdev); zcrypt_device_free(zdev);
} }
...@@ -165,12 +164,9 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev) ...@@ -165,12 +164,9 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
static void zcrypt_cex4_remove(struct ap_device *ap_dev) static void zcrypt_cex4_remove(struct ap_device *ap_dev)
{ {
struct zcrypt_device *zdev = ap_dev->private; struct zcrypt_device *zdev = ap_dev->private;
struct zcrypt_ops *zops;
if (zdev) { if (zdev) {
zops = zdev->ops;
zcrypt_device_unregister(zdev); zcrypt_device_unregister(zdev);
zcrypt_msgtype_release(zops);
} }
} }
......
...@@ -322,11 +322,11 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev) ...@@ -322,11 +322,11 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
return rc; return rc;
} }
if (rc) if (rc)
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME, zdev->ops = zcrypt_msgtype(MSGTYPE06_NAME,
MSGTYPE06_VARIANT_DEFAULT); MSGTYPE06_VARIANT_DEFAULT);
else else
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME, zdev->ops = zcrypt_msgtype(MSGTYPE06_NAME,
MSGTYPE06_VARIANT_NORNG); MSGTYPE06_VARIANT_NORNG);
ap_device_init_reply(ap_dev, &zdev->reply); ap_device_init_reply(ap_dev, &zdev->reply);
ap_dev->private = zdev; ap_dev->private = zdev;
rc = zcrypt_device_register(zdev); rc = zcrypt_device_register(zdev);
...@@ -336,7 +336,6 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev) ...@@ -336,7 +336,6 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
out_free: out_free:
ap_dev->private = NULL; ap_dev->private = NULL;
zcrypt_msgtype_release(zdev->ops);
zcrypt_device_free(zdev); zcrypt_device_free(zdev);
return rc; return rc;
} }
...@@ -348,10 +347,8 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev) ...@@ -348,10 +347,8 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
static void zcrypt_pcixcc_remove(struct ap_device *ap_dev) static void zcrypt_pcixcc_remove(struct ap_device *ap_dev)
{ {
struct zcrypt_device *zdev = ap_dev->private; struct zcrypt_device *zdev = ap_dev->private;
struct zcrypt_ops *zops = zdev->ops;
zcrypt_device_unregister(zdev); zcrypt_device_unregister(zdev);
zcrypt_msgtype_release(zops);
} }
int __init zcrypt_pcixcc_init(void) int __init zcrypt_pcixcc_init(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment