diff options
author | Holger Dengler <hd@linux.vnet.ibm.com> | 2012-08-28 10:45:36 -0400 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2012-09-26 09:44:55 -0400 |
commit | 5e55a488c87aa6cc269b04bfec99e835f03b2c2d (patch) | |
tree | 59d848f6cf6a67a520a3bd482a853b2955cf97d2 /drivers/s390/crypto/zcrypt_api.c | |
parent | b26bd9413c8359bd9f5c9bd1b789a10ebd2bb484 (diff) |
s390/zcrypt: Separate msgtype implementation from card modules.
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>
Diffstat (limited to 'drivers/s390/crypto/zcrypt_api.c')
-rw-r--r-- | drivers/s390/crypto/zcrypt_api.c | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c index 2f94132246a1..f1f026e0b189 100644 --- a/drivers/s390/crypto/zcrypt_api.c +++ b/drivers/s390/crypto/zcrypt_api.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * zcrypt 2.1.0 | 2 | * zcrypt 2.1.0 |
3 | * | 3 | * |
4 | * Copyright IBM Corp. 2001, 2006 | 4 | * Copyright IBM Corp. 2001, 2012 |
5 | * Author(s): Robert Burroughs | 5 | * Author(s): Robert Burroughs |
6 | * Eric Rossman (edrossma@us.ibm.com) | 6 | * Eric Rossman (edrossma@us.ibm.com) |
7 | * Cornelia Huck <cornelia.huck@de.ibm.com> | 7 | * Cornelia Huck <cornelia.huck@de.ibm.com> |
@@ -9,6 +9,7 @@ | |||
9 | * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) | 9 | * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) |
10 | * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> | 10 | * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> |
11 | * Ralph Wuerthner <rwuerthn@de.ibm.com> | 11 | * Ralph Wuerthner <rwuerthn@de.ibm.com> |
12 | * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com> | ||
12 | * | 13 | * |
13 | * This program is free software; you can redistribute it and/or modify | 14 | * This program 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 | * it under the terms of the GNU General Public License as published by |
@@ -44,8 +45,8 @@ | |||
44 | * Module description. | 45 | * Module description. |
45 | */ | 46 | */ |
46 | MODULE_AUTHOR("IBM Corporation"); | 47 | MODULE_AUTHOR("IBM Corporation"); |
47 | MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " | 48 | MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \ |
48 | "Copyright IBM Corp. 2001, 2006"); | 49 | "Copyright IBM Corp. 2001, 2012"); |
49 | MODULE_LICENSE("GPL"); | 50 | MODULE_LICENSE("GPL"); |
50 | 51 | ||
51 | static DEFINE_SPINLOCK(zcrypt_device_lock); | 52 | static DEFINE_SPINLOCK(zcrypt_device_lock); |
@@ -56,6 +57,9 @@ static atomic_t zcrypt_open_count = ATOMIC_INIT(0); | |||
56 | static int zcrypt_rng_device_add(void); | 57 | static int zcrypt_rng_device_add(void); |
57 | static void zcrypt_rng_device_remove(void); | 58 | static void zcrypt_rng_device_remove(void); |
58 | 59 | ||
60 | static DEFINE_SPINLOCK(zcrypt_ops_list_lock); | ||
61 | static LIST_HEAD(zcrypt_ops_list); | ||
62 | |||
59 | /* | 63 | /* |
60 | * Device attributes common for all crypto devices. | 64 | * Device attributes common for all crypto devices. |
61 | */ | 65 | */ |
@@ -215,6 +219,8 @@ int zcrypt_device_register(struct zcrypt_device *zdev) | |||
215 | { | 219 | { |
216 | int rc; | 220 | int rc; |
217 | 221 | ||
222 | if (!zdev->ops) | ||
223 | return -ENODEV; | ||
218 | rc = sysfs_create_group(&zdev->ap_dev->device.kobj, | 224 | rc = sysfs_create_group(&zdev->ap_dev->device.kobj, |
219 | &zcrypt_device_attr_group); | 225 | &zcrypt_device_attr_group); |
220 | if (rc) | 226 | if (rc) |
@@ -269,6 +275,67 @@ void zcrypt_device_unregister(struct zcrypt_device *zdev) | |||
269 | } | 275 | } |
270 | EXPORT_SYMBOL(zcrypt_device_unregister); | 276 | EXPORT_SYMBOL(zcrypt_device_unregister); |
271 | 277 | ||
278 | void zcrypt_msgtype_register(struct zcrypt_ops *zops) | ||
279 | { | ||
280 | if (zops->owner) { | ||
281 | spin_lock_bh(&zcrypt_ops_list_lock); | ||
282 | list_add_tail(&zops->list, &zcrypt_ops_list); | ||
283 | spin_unlock_bh(&zcrypt_ops_list_lock); | ||
284 | } | ||
285 | } | ||
286 | EXPORT_SYMBOL(zcrypt_msgtype_register); | ||
287 | |||
288 | void zcrypt_msgtype_unregister(struct zcrypt_ops *zops) | ||
289 | { | ||
290 | spin_lock_bh(&zcrypt_ops_list_lock); | ||
291 | list_del_init(&zops->list); | ||
292 | spin_unlock_bh(&zcrypt_ops_list_lock); | ||
293 | } | ||
294 | EXPORT_SYMBOL(zcrypt_msgtype_unregister); | ||
295 | |||
296 | static inline | ||
297 | struct zcrypt_ops *__ops_lookup(unsigned char *name, int variant) | ||
298 | { | ||
299 | struct zcrypt_ops *zops; | ||
300 | int found = 0; | ||
301 | |||
302 | spin_lock_bh(&zcrypt_ops_list_lock); | ||
303 | list_for_each_entry(zops, &zcrypt_ops_list, list) { | ||
304 | if ((zops->variant == variant) && | ||
305 | (!strncmp(zops->owner->name, name, MODULE_NAME_LEN))) { | ||
306 | found = 1; | ||
307 | break; | ||
308 | } | ||
309 | } | ||
310 | spin_unlock_bh(&zcrypt_ops_list_lock); | ||
311 | |||
312 | if (!found) | ||
313 | return NULL; | ||
314 | return zops; | ||
315 | } | ||
316 | |||
317 | struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *name, int variant) | ||
318 | { | ||
319 | struct zcrypt_ops *zops = NULL; | ||
320 | |||
321 | zops = __ops_lookup(name, variant); | ||
322 | if (!zops) { | ||
323 | request_module(name); | ||
324 | zops = __ops_lookup(name, variant); | ||
325 | } | ||
326 | if ((!zops) || (!try_module_get(zops->owner))) | ||
327 | return NULL; | ||
328 | return zops; | ||
329 | } | ||
330 | EXPORT_SYMBOL(zcrypt_msgtype_request); | ||
331 | |||
332 | void zcrypt_msgtype_release(struct zcrypt_ops *zops) | ||
333 | { | ||
334 | if (zops) | ||
335 | module_put(zops->owner); | ||
336 | } | ||
337 | EXPORT_SYMBOL(zcrypt_msgtype_release); | ||
338 | |||
272 | /** | 339 | /** |
273 | * zcrypt_read (): Not supported beyond zcrypt 1.3.1. | 340 | * zcrypt_read (): Not supported beyond zcrypt 1.3.1. |
274 | * | 341 | * |