1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright IBM Corp. 2001, 2018
4 * Author(s): Robert Burroughs
5 * Eric Rossman (edrossma@us.ibm.com)
6 * Cornelia Huck <cornelia.huck@de.ibm.com>
8 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
9 * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
10 * Ralph Wuerthner <rwuerthn@de.ibm.com>
11 * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
12 * Multiple device nodes: Harald Freudenberger <freude@linux.ibm.com>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/miscdevice.h>
20 #include <linux/compat.h>
21 #include <linux/slab.h>
22 #include <linux/atomic.h>
23 #include <linux/uaccess.h>
24 #include <linux/hw_random.h>
25 #include <linux/debugfs.h>
26 #include <linux/cdev.h>
27 #include <linux/ctype.h>
28 #include <linux/capability.h>
29 #include <asm/debug.h>
31 #define CREATE_TRACE_POINTS
32 #include <asm/trace/zcrypt.h>
34 #include "zcrypt_api.h"
35 #include "zcrypt_debug.h"
37 #include "zcrypt_msgtype6.h"
38 #include "zcrypt_msgtype50.h"
39 #include "zcrypt_ccamisc.h"
40 #include "zcrypt_ep11misc.h"
45 MODULE_AUTHOR("IBM Corporation");
46 MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \
47 "Copyright IBM Corp. 2001, 2012");
48 MODULE_LICENSE("GPL");
51 * zcrypt tracepoint functions
53 EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_req
);
54 EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_rep
);
56 static int zcrypt_hwrng_seed
= 1;
57 module_param_named(hwrng_seed
, zcrypt_hwrng_seed
, int, 0440);
58 MODULE_PARM_DESC(hwrng_seed
, "Turn on/off hwrng auto seed, default is 1 (on).");
60 DEFINE_SPINLOCK(zcrypt_list_lock
);
61 LIST_HEAD(zcrypt_card_list
);
62 int zcrypt_device_count
;
64 static atomic_t zcrypt_open_count
= ATOMIC_INIT(0);
65 static atomic_t zcrypt_rescan_count
= ATOMIC_INIT(0);
67 atomic_t zcrypt_rescan_req
= ATOMIC_INIT(0);
68 EXPORT_SYMBOL(zcrypt_rescan_req
);
70 static LIST_HEAD(zcrypt_ops_list
);
72 /* Zcrypt related debug feature stuff. */
73 debug_info_t
*zcrypt_dbf_info
;
76 * Process a rescan of the transport layer.
78 * Returns 1, if the rescan has been processed, otherwise 0.
80 static inline int zcrypt_process_rescan(void)
82 if (atomic_read(&zcrypt_rescan_req
)) {
83 atomic_set(&zcrypt_rescan_req
, 0);
84 atomic_inc(&zcrypt_rescan_count
);
85 ap_bus_force_rescan();
86 ZCRYPT_DBF(DBF_INFO
, "rescan count=%07d\n",
87 atomic_inc_return(&zcrypt_rescan_count
));
93 void zcrypt_msgtype_register(struct zcrypt_ops
*zops
)
95 list_add_tail(&zops
->list
, &zcrypt_ops_list
);
98 void zcrypt_msgtype_unregister(struct zcrypt_ops
*zops
)
100 list_del_init(&zops
->list
);
103 struct zcrypt_ops
*zcrypt_msgtype(unsigned char *name
, int variant
)
105 struct zcrypt_ops
*zops
;
107 list_for_each_entry(zops
, &zcrypt_ops_list
, list
)
108 if ((zops
->variant
== variant
) &&
109 (!strncmp(zops
->name
, name
, sizeof(zops
->name
))))
113 EXPORT_SYMBOL(zcrypt_msgtype
);
116 * Multi device nodes extension functions.
119 #ifdef CONFIG_ZCRYPT_MULTIDEVNODES
123 static struct class *zcrypt_class
;
124 static dev_t zcrypt_devt
;
125 static struct cdev zcrypt_cdev
;
128 struct device device
;
129 struct ap_perms perms
;
132 #define to_zcdn_dev(x) container_of((x), struct zcdn_device, device)
134 #define ZCDN_MAX_NAME 32
136 static int zcdn_create(const char *name
);
137 static int zcdn_destroy(const char *name
);
140 * Find zcdn device by name.
141 * Returns reference to the zcdn device which needs to be released
142 * with put_device() after use.
144 static inline struct zcdn_device
*find_zcdndev_by_name(const char *name
)
146 struct device
*dev
= class_find_device_by_name(zcrypt_class
, name
);
148 return dev
? to_zcdn_dev(dev
) : NULL
;
152 * Find zcdn device by devt value.
153 * Returns reference to the zcdn device which needs to be released
154 * with put_device() after use.
156 static inline struct zcdn_device
*find_zcdndev_by_devt(dev_t devt
)
158 struct device
*dev
= class_find_device_by_devt(zcrypt_class
, devt
);
160 return dev
? to_zcdn_dev(dev
) : NULL
;
163 static ssize_t
ioctlmask_show(struct device
*dev
,
164 struct device_attribute
*attr
,
168 struct zcdn_device
*zcdndev
= to_zcdn_dev(dev
);
170 if (mutex_lock_interruptible(&ap_perms_mutex
))
175 for (i
= 0; i
< sizeof(zcdndev
->perms
.ioctlm
) / sizeof(long); i
++)
176 snprintf(buf
+ 2 + 2 * i
* sizeof(long),
177 PAGE_SIZE
- 2 - 2 * i
* sizeof(long),
178 "%016lx", zcdndev
->perms
.ioctlm
[i
]);
179 buf
[2 + 2 * i
* sizeof(long)] = '\n';
180 buf
[2 + 2 * i
* sizeof(long) + 1] = '\0';
181 rc
= 2 + 2 * i
* sizeof(long) + 1;
183 mutex_unlock(&ap_perms_mutex
);
188 static ssize_t
ioctlmask_store(struct device
*dev
,
189 struct device_attribute
*attr
,
190 const char *buf
, size_t count
)
193 struct zcdn_device
*zcdndev
= to_zcdn_dev(dev
);
195 rc
= ap_parse_mask_str(buf
, zcdndev
->perms
.ioctlm
,
196 AP_IOCTLS
, &ap_perms_mutex
);
203 static DEVICE_ATTR_RW(ioctlmask
);
205 static ssize_t
apmask_show(struct device
*dev
,
206 struct device_attribute
*attr
,
210 struct zcdn_device
*zcdndev
= to_zcdn_dev(dev
);
212 if (mutex_lock_interruptible(&ap_perms_mutex
))
217 for (i
= 0; i
< sizeof(zcdndev
->perms
.apm
) / sizeof(long); i
++)
218 snprintf(buf
+ 2 + 2 * i
* sizeof(long),
219 PAGE_SIZE
- 2 - 2 * i
* sizeof(long),
220 "%016lx", zcdndev
->perms
.apm
[i
]);
221 buf
[2 + 2 * i
* sizeof(long)] = '\n';
222 buf
[2 + 2 * i
* sizeof(long) + 1] = '\0';
223 rc
= 2 + 2 * i
* sizeof(long) + 1;
225 mutex_unlock(&ap_perms_mutex
);
230 static ssize_t
apmask_store(struct device
*dev
,
231 struct device_attribute
*attr
,
232 const char *buf
, size_t count
)
235 struct zcdn_device
*zcdndev
= to_zcdn_dev(dev
);
237 rc
= ap_parse_mask_str(buf
, zcdndev
->perms
.apm
,
238 AP_DEVICES
, &ap_perms_mutex
);
245 static DEVICE_ATTR_RW(apmask
);
247 static ssize_t
aqmask_show(struct device
*dev
,
248 struct device_attribute
*attr
,
252 struct zcdn_device
*zcdndev
= to_zcdn_dev(dev
);
254 if (mutex_lock_interruptible(&ap_perms_mutex
))
259 for (i
= 0; i
< sizeof(zcdndev
->perms
.aqm
) / sizeof(long); i
++)
260 snprintf(buf
+ 2 + 2 * i
* sizeof(long),
261 PAGE_SIZE
- 2 - 2 * i
* sizeof(long),
262 "%016lx", zcdndev
->perms
.aqm
[i
]);
263 buf
[2 + 2 * i
* sizeof(long)] = '\n';
264 buf
[2 + 2 * i
* sizeof(long) + 1] = '\0';
265 rc
= 2 + 2 * i
* sizeof(long) + 1;
267 mutex_unlock(&ap_perms_mutex
);
272 static ssize_t
aqmask_store(struct device
*dev
,
273 struct device_attribute
*attr
,
274 const char *buf
, size_t count
)
277 struct zcdn_device
*zcdndev
= to_zcdn_dev(dev
);
279 rc
= ap_parse_mask_str(buf
, zcdndev
->perms
.aqm
,
280 AP_DOMAINS
, &ap_perms_mutex
);
287 static DEVICE_ATTR_RW(aqmask
);
289 static struct attribute
*zcdn_dev_attrs
[] = {
290 &dev_attr_ioctlmask
.attr
,
291 &dev_attr_apmask
.attr
,
292 &dev_attr_aqmask
.attr
,
296 static struct attribute_group zcdn_dev_attr_group
= {
297 .attrs
= zcdn_dev_attrs
300 static const struct attribute_group
*zcdn_dev_attr_groups
[] = {
301 &zcdn_dev_attr_group
,
305 static ssize_t
zcdn_create_store(struct class *class,
306 struct class_attribute
*attr
,
307 const char *buf
, size_t count
)
310 char name
[ZCDN_MAX_NAME
];
312 strncpy(name
, skip_spaces(buf
), sizeof(name
));
313 name
[sizeof(name
) - 1] = '\0';
315 rc
= zcdn_create(strim(name
));
317 return rc
? rc
: count
;
320 static const struct class_attribute class_attr_zcdn_create
=
321 __ATTR(create
, 0600, NULL
, zcdn_create_store
);
323 static ssize_t
zcdn_destroy_store(struct class *class,
324 struct class_attribute
*attr
,
325 const char *buf
, size_t count
)
328 char name
[ZCDN_MAX_NAME
];
330 strncpy(name
, skip_spaces(buf
), sizeof(name
));
331 name
[sizeof(name
) - 1] = '\0';
333 rc
= zcdn_destroy(strim(name
));
335 return rc
? rc
: count
;
338 static const struct class_attribute class_attr_zcdn_destroy
=
339 __ATTR(destroy
, 0600, NULL
, zcdn_destroy_store
);
341 static void zcdn_device_release(struct device
*dev
)
343 struct zcdn_device
*zcdndev
= to_zcdn_dev(dev
);
345 ZCRYPT_DBF(DBF_INFO
, "releasing zcdn device %d:%d\n",
346 MAJOR(dev
->devt
), MINOR(dev
->devt
));
351 static int zcdn_create(const char *name
)
355 char nodename
[ZCDN_MAX_NAME
];
356 struct zcdn_device
*zcdndev
;
358 if (mutex_lock_interruptible(&ap_perms_mutex
))
361 /* check if device node with this name already exists */
363 zcdndev
= find_zcdndev_by_name(name
);
365 put_device(&zcdndev
->device
);
371 /* find an unused minor number */
372 for (i
= 0; i
< ZCRYPT_MAX_MINOR_NODES
; i
++) {
373 devt
= MKDEV(MAJOR(zcrypt_devt
), MINOR(zcrypt_devt
) + i
);
374 zcdndev
= find_zcdndev_by_devt(devt
);
376 put_device(&zcdndev
->device
);
380 if (i
== ZCRYPT_MAX_MINOR_NODES
) {
385 /* alloc and prepare a new zcdn device */
386 zcdndev
= kzalloc(sizeof(*zcdndev
), GFP_KERNEL
);
391 zcdndev
->device
.release
= zcdn_device_release
;
392 zcdndev
->device
.class = zcrypt_class
;
393 zcdndev
->device
.devt
= devt
;
394 zcdndev
->device
.groups
= zcdn_dev_attr_groups
;
396 strncpy(nodename
, name
, sizeof(nodename
));
398 snprintf(nodename
, sizeof(nodename
),
399 ZCRYPT_NAME
"_%d", (int) MINOR(devt
));
400 nodename
[sizeof(nodename
)-1] = '\0';
401 if (dev_set_name(&zcdndev
->device
, nodename
)) {
405 rc
= device_register(&zcdndev
->device
);
407 put_device(&zcdndev
->device
);
411 ZCRYPT_DBF(DBF_INFO
, "created zcdn device %d:%d\n",
412 MAJOR(devt
), MINOR(devt
));
415 mutex_unlock(&ap_perms_mutex
);
419 static int zcdn_destroy(const char *name
)
422 struct zcdn_device
*zcdndev
;
424 if (mutex_lock_interruptible(&ap_perms_mutex
))
427 /* try to find this zcdn device */
428 zcdndev
= find_zcdndev_by_name(name
);
435 * The zcdn device is not hard destroyed. It is subject to
436 * reference counting and thus just needs to be unregistered.
438 put_device(&zcdndev
->device
);
439 device_unregister(&zcdndev
->device
);
442 mutex_unlock(&ap_perms_mutex
);
446 static void zcdn_destroy_all(void)
450 struct zcdn_device
*zcdndev
;
452 mutex_lock(&ap_perms_mutex
);
453 for (i
= 0; i
< ZCRYPT_MAX_MINOR_NODES
; i
++) {
454 devt
= MKDEV(MAJOR(zcrypt_devt
), MINOR(zcrypt_devt
) + i
);
455 zcdndev
= find_zcdndev_by_devt(devt
);
457 put_device(&zcdndev
->device
);
458 device_unregister(&zcdndev
->device
);
461 mutex_unlock(&ap_perms_mutex
);
467 * zcrypt_read (): Not supported beyond zcrypt 1.3.1.
469 * This function is not supported beyond zcrypt 1.3.1.
471 static ssize_t
zcrypt_read(struct file
*filp
, char __user
*buf
,
472 size_t count
, loff_t
*f_pos
)
478 * zcrypt_write(): Not allowed.
480 * Write is is not allowed
482 static ssize_t
zcrypt_write(struct file
*filp
, const char __user
*buf
,
483 size_t count
, loff_t
*f_pos
)
489 * zcrypt_open(): Count number of users.
491 * Device open function to count number of users.
493 static int zcrypt_open(struct inode
*inode
, struct file
*filp
)
495 struct ap_perms
*perms
= &ap_perms
;
497 #ifdef CONFIG_ZCRYPT_MULTIDEVNODES
498 if (filp
->f_inode
->i_cdev
== &zcrypt_cdev
) {
499 struct zcdn_device
*zcdndev
;
501 if (mutex_lock_interruptible(&ap_perms_mutex
))
503 zcdndev
= find_zcdndev_by_devt(filp
->f_inode
->i_rdev
);
504 /* find returns a reference, no get_device() needed */
505 mutex_unlock(&ap_perms_mutex
);
507 perms
= &zcdndev
->perms
;
510 filp
->private_data
= (void *) perms
;
512 atomic_inc(&zcrypt_open_count
);
513 return stream_open(inode
, filp
);
517 * zcrypt_release(): Count number of users.
519 * Device close function to count number of users.
521 static int zcrypt_release(struct inode
*inode
, struct file
*filp
)
523 #ifdef CONFIG_ZCRYPT_MULTIDEVNODES
524 if (filp
->f_inode
->i_cdev
== &zcrypt_cdev
) {
525 struct zcdn_device
*zcdndev
;
527 mutex_lock(&ap_perms_mutex
);
528 zcdndev
= find_zcdndev_by_devt(filp
->f_inode
->i_rdev
);
529 mutex_unlock(&ap_perms_mutex
);
531 /* 2 puts here: one for find, one for open */
532 put_device(&zcdndev
->device
);
533 put_device(&zcdndev
->device
);
538 atomic_dec(&zcrypt_open_count
);
542 static inline int zcrypt_check_ioctl(struct ap_perms
*perms
,
546 int ioctlnr
= (cmd
& _IOC_NRMASK
) >> _IOC_NRSHIFT
;
548 if (ioctlnr
> 0 && ioctlnr
< AP_IOCTLS
) {
549 if (test_bit_inv(ioctlnr
, perms
->ioctlm
))
555 "ioctl check failed: ioctlnr=0x%04x rc=%d\n",
561 static inline bool zcrypt_check_card(struct ap_perms
*perms
, int card
)
563 return test_bit_inv(card
, perms
->apm
) ? true : false;
566 static inline bool zcrypt_check_queue(struct ap_perms
*perms
, int queue
)
568 return test_bit_inv(queue
, perms
->aqm
) ? true : false;
571 static inline struct zcrypt_queue
*zcrypt_pick_queue(struct zcrypt_card
*zc
,
572 struct zcrypt_queue
*zq
,
573 struct module
**pmod
,
576 if (!zq
|| !try_module_get(zq
->queue
->ap_dev
.drv
->driver
.owner
))
578 zcrypt_queue_get(zq
);
579 get_device(&zq
->queue
->ap_dev
.device
);
580 atomic_add(weight
, &zc
->load
);
581 atomic_add(weight
, &zq
->load
);
583 *pmod
= zq
->queue
->ap_dev
.drv
->driver
.owner
;
587 static inline void zcrypt_drop_queue(struct zcrypt_card
*zc
,
588 struct zcrypt_queue
*zq
,
593 atomic_sub(weight
, &zc
->load
);
594 atomic_sub(weight
, &zq
->load
);
595 put_device(&zq
->queue
->ap_dev
.device
);
596 zcrypt_queue_put(zq
);
600 static inline bool zcrypt_card_compare(struct zcrypt_card
*zc
,
601 struct zcrypt_card
*pref_zc
,
603 unsigned int pref_weight
)
607 weight
+= atomic_read(&zc
->load
);
608 pref_weight
+= atomic_read(&pref_zc
->load
);
609 if (weight
== pref_weight
)
610 return atomic64_read(&zc
->card
->total_request_count
) <
611 atomic64_read(&pref_zc
->card
->total_request_count
);
612 return weight
< pref_weight
;
615 static inline bool zcrypt_queue_compare(struct zcrypt_queue
*zq
,
616 struct zcrypt_queue
*pref_zq
,
618 unsigned int pref_weight
)
622 weight
+= atomic_read(&zq
->load
);
623 pref_weight
+= atomic_read(&pref_zq
->load
);
624 if (weight
== pref_weight
)
625 return zq
->queue
->total_request_count
<
626 pref_zq
->queue
->total_request_count
;
627 return weight
< pref_weight
;
633 static long zcrypt_rsa_modexpo(struct ap_perms
*perms
,
634 struct zcrypt_track
*tr
,
635 struct ica_rsa_modexpo
*mex
)
637 struct zcrypt_card
*zc
, *pref_zc
;
638 struct zcrypt_queue
*zq
, *pref_zq
;
639 struct ap_message ap_msg
;
640 unsigned int wgt
= 0, pref_wgt
= 0;
641 unsigned int func_code
;
642 int cpen
, qpen
, qid
= 0, rc
= -ENODEV
;
645 trace_s390_zcrypt_req(mex
, TP_ICARSAMODEXPO
);
647 ap_init_message(&ap_msg
);
649 #ifdef CONFIG_ZCRYPT_DEBUG
650 if (tr
&& tr
->fi
.cmd
)
651 ap_msg
.fi
.cmd
= tr
->fi
.cmd
;
654 if (mex
->outputdatalength
< mex
->inputdatalength
) {
661 * As long as outputdatalength is big enough, we can set the
662 * outputdatalength equal to the inputdatalength, since that is the
663 * number of bytes we will copy in any case
665 mex
->outputdatalength
= mex
->inputdatalength
;
667 rc
= get_rsa_modex_fc(mex
, &func_code
);
673 spin_lock(&zcrypt_list_lock
);
674 for_each_zcrypt_card(zc
) {
675 /* Check for useable accelarator or CCA card */
676 if (!zc
->online
|| !zc
->card
->config
||
677 !(zc
->card
->functions
& 0x18000000))
679 /* Check for size limits */
680 if (zc
->min_mod_size
> mex
->inputdatalength
||
681 zc
->max_mod_size
< mex
->inputdatalength
)
683 /* check if device node has admission for this card */
684 if (!zcrypt_check_card(perms
, zc
->card
->id
))
686 /* get weight index of the card device */
687 wgt
= zc
->speed_rating
[func_code
];
688 /* penalty if this msg was previously sent via this card */
689 cpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
690 AP_QID_CARD(tr
->last_qid
) == zc
->card
->id
) ?
691 TRACK_AGAIN_CARD_WEIGHT_PENALTY
: 0;
692 if (!zcrypt_card_compare(zc
, pref_zc
, wgt
+ cpen
, pref_wgt
))
694 for_each_zcrypt_queue(zq
, zc
) {
695 /* check if device is useable and eligible */
696 if (!zq
->online
|| !zq
->ops
->rsa_modexpo
||
699 /* check if device node has admission for this queue */
700 if (!zcrypt_check_queue(perms
,
701 AP_QID_QUEUE(zq
->queue
->qid
)))
703 /* penalty if the msg was previously sent at this qid */
704 qpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
705 tr
->last_qid
== zq
->queue
->qid
) ?
706 TRACK_AGAIN_QUEUE_WEIGHT_PENALTY
: 0;
707 if (!zcrypt_queue_compare(zq
, pref_zq
,
708 wgt
+ cpen
+ qpen
, pref_wgt
))
712 pref_wgt
= wgt
+ cpen
+ qpen
;
715 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, &mod
, wgt
);
716 spin_unlock(&zcrypt_list_lock
);
723 qid
= pref_zq
->queue
->qid
;
724 rc
= pref_zq
->ops
->rsa_modexpo(pref_zq
, mex
, &ap_msg
);
726 spin_lock(&zcrypt_list_lock
);
727 zcrypt_drop_queue(pref_zc
, pref_zq
, mod
, wgt
);
728 spin_unlock(&zcrypt_list_lock
);
731 ap_release_message(&ap_msg
);
736 trace_s390_zcrypt_rep(mex
, func_code
, rc
,
737 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
741 static long zcrypt_rsa_crt(struct ap_perms
*perms
,
742 struct zcrypt_track
*tr
,
743 struct ica_rsa_modexpo_crt
*crt
)
745 struct zcrypt_card
*zc
, *pref_zc
;
746 struct zcrypt_queue
*zq
, *pref_zq
;
747 struct ap_message ap_msg
;
748 unsigned int wgt
= 0, pref_wgt
= 0;
749 unsigned int func_code
;
750 int cpen
, qpen
, qid
= 0, rc
= -ENODEV
;
753 trace_s390_zcrypt_req(crt
, TP_ICARSACRT
);
755 ap_init_message(&ap_msg
);
757 #ifdef CONFIG_ZCRYPT_DEBUG
758 if (tr
&& tr
->fi
.cmd
)
759 ap_msg
.fi
.cmd
= tr
->fi
.cmd
;
762 if (crt
->outputdatalength
< crt
->inputdatalength
) {
769 * As long as outputdatalength is big enough, we can set the
770 * outputdatalength equal to the inputdatalength, since that is the
771 * number of bytes we will copy in any case
773 crt
->outputdatalength
= crt
->inputdatalength
;
775 rc
= get_rsa_crt_fc(crt
, &func_code
);
781 spin_lock(&zcrypt_list_lock
);
782 for_each_zcrypt_card(zc
) {
783 /* Check for useable accelarator or CCA card */
784 if (!zc
->online
|| !zc
->card
->config
||
785 !(zc
->card
->functions
& 0x18000000))
787 /* Check for size limits */
788 if (zc
->min_mod_size
> crt
->inputdatalength
||
789 zc
->max_mod_size
< crt
->inputdatalength
)
791 /* check if device node has admission for this card */
792 if (!zcrypt_check_card(perms
, zc
->card
->id
))
794 /* get weight index of the card device */
795 wgt
= zc
->speed_rating
[func_code
];
796 /* penalty if this msg was previously sent via this card */
797 cpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
798 AP_QID_CARD(tr
->last_qid
) == zc
->card
->id
) ?
799 TRACK_AGAIN_CARD_WEIGHT_PENALTY
: 0;
800 if (!zcrypt_card_compare(zc
, pref_zc
, wgt
+ cpen
, pref_wgt
))
802 for_each_zcrypt_queue(zq
, zc
) {
803 /* check if device is useable and eligible */
804 if (!zq
->online
|| !zq
->ops
->rsa_modexpo_crt
||
807 /* check if device node has admission for this queue */
808 if (!zcrypt_check_queue(perms
,
809 AP_QID_QUEUE(zq
->queue
->qid
)))
811 /* penalty if the msg was previously sent at this qid */
812 qpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
813 tr
->last_qid
== zq
->queue
->qid
) ?
814 TRACK_AGAIN_QUEUE_WEIGHT_PENALTY
: 0;
815 if (!zcrypt_queue_compare(zq
, pref_zq
,
816 wgt
+ cpen
+ qpen
, pref_wgt
))
820 pref_wgt
= wgt
+ cpen
+ qpen
;
823 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, &mod
, wgt
);
824 spin_unlock(&zcrypt_list_lock
);
831 qid
= pref_zq
->queue
->qid
;
832 rc
= pref_zq
->ops
->rsa_modexpo_crt(pref_zq
, crt
, &ap_msg
);
834 spin_lock(&zcrypt_list_lock
);
835 zcrypt_drop_queue(pref_zc
, pref_zq
, mod
, wgt
);
836 spin_unlock(&zcrypt_list_lock
);
839 ap_release_message(&ap_msg
);
844 trace_s390_zcrypt_rep(crt
, func_code
, rc
,
845 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
849 static long _zcrypt_send_cprb(bool userspace
, struct ap_perms
*perms
,
850 struct zcrypt_track
*tr
,
851 struct ica_xcRB
*xcRB
)
853 struct zcrypt_card
*zc
, *pref_zc
;
854 struct zcrypt_queue
*zq
, *pref_zq
;
855 struct ap_message ap_msg
;
856 unsigned int wgt
= 0, pref_wgt
= 0;
857 unsigned int func_code
;
858 unsigned short *domain
, tdom
;
859 int cpen
, qpen
, qid
= 0, rc
= -ENODEV
;
862 trace_s390_zcrypt_req(xcRB
, TB_ZSECSENDCPRB
);
865 ap_init_message(&ap_msg
);
867 #ifdef CONFIG_ZCRYPT_DEBUG
868 if (tr
&& tr
->fi
.cmd
)
869 ap_msg
.fi
.cmd
= tr
->fi
.cmd
;
870 if (tr
&& tr
->fi
.action
== AP_FI_ACTION_CCA_AGENT_FF
) {
871 ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid agent_ID 'FF'\n",
872 __func__
, tr
->fi
.cmd
);
873 xcRB
->agent_ID
= 0x4646;
877 rc
= get_cprb_fc(userspace
, xcRB
, &ap_msg
, &func_code
, &domain
);
882 * If a valid target domain is set and this domain is NOT a usage
883 * domain but a control only domain, use the default domain as target.
886 if (tdom
< AP_DOMAINS
&&
887 !ap_test_config_usage_domain(tdom
) &&
888 ap_test_config_ctrl_domain(tdom
) &&
889 ap_domain_index
>= 0)
890 tdom
= ap_domain_index
;
894 spin_lock(&zcrypt_list_lock
);
895 for_each_zcrypt_card(zc
) {
896 /* Check for useable CCA card */
897 if (!zc
->online
|| !zc
->card
->config
||
898 !(zc
->card
->functions
& 0x10000000))
900 /* Check for user selected CCA card */
901 if (xcRB
->user_defined
!= AUTOSELECT
&&
902 xcRB
->user_defined
!= zc
->card
->id
)
904 /* check if device node has admission for this card */
905 if (!zcrypt_check_card(perms
, zc
->card
->id
))
907 /* get weight index of the card device */
908 wgt
= speed_idx_cca(func_code
) * zc
->speed_rating
[SECKEY
];
909 /* penalty if this msg was previously sent via this card */
910 cpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
911 AP_QID_CARD(tr
->last_qid
) == zc
->card
->id
) ?
912 TRACK_AGAIN_CARD_WEIGHT_PENALTY
: 0;
913 if (!zcrypt_card_compare(zc
, pref_zc
, wgt
+ cpen
, pref_wgt
))
915 for_each_zcrypt_queue(zq
, zc
) {
916 /* check for device useable and eligible */
918 !zq
->ops
->send_cprb
||
919 !zq
->queue
->config
||
920 (tdom
!= AUTOSEL_DOM
&&
921 tdom
!= AP_QID_QUEUE(zq
->queue
->qid
)))
923 /* check if device node has admission for this queue */
924 if (!zcrypt_check_queue(perms
,
925 AP_QID_QUEUE(zq
->queue
->qid
)))
927 /* penalty if the msg was previously sent at this qid */
928 qpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
929 tr
->last_qid
== zq
->queue
->qid
) ?
930 TRACK_AGAIN_QUEUE_WEIGHT_PENALTY
: 0;
931 if (!zcrypt_queue_compare(zq
, pref_zq
,
932 wgt
+ cpen
+ qpen
, pref_wgt
))
936 pref_wgt
= wgt
+ cpen
+ qpen
;
939 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, &mod
, wgt
);
940 spin_unlock(&zcrypt_list_lock
);
947 /* in case of auto select, provide the correct domain */
948 qid
= pref_zq
->queue
->qid
;
949 if (*domain
== AUTOSEL_DOM
)
950 *domain
= AP_QID_QUEUE(qid
);
952 #ifdef CONFIG_ZCRYPT_DEBUG
953 if (tr
&& tr
->fi
.action
== AP_FI_ACTION_CCA_DOM_INVAL
) {
954 ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid domain\n",
955 __func__
, tr
->fi
.cmd
);
960 rc
= pref_zq
->ops
->send_cprb(userspace
, pref_zq
, xcRB
, &ap_msg
);
962 spin_lock(&zcrypt_list_lock
);
963 zcrypt_drop_queue(pref_zc
, pref_zq
, mod
, wgt
);
964 spin_unlock(&zcrypt_list_lock
);
967 ap_release_message(&ap_msg
);
972 trace_s390_zcrypt_rep(xcRB
, func_code
, rc
,
973 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
977 long zcrypt_send_cprb(struct ica_xcRB
*xcRB
)
979 return _zcrypt_send_cprb(false, &ap_perms
, NULL
, xcRB
);
981 EXPORT_SYMBOL(zcrypt_send_cprb
);
983 static bool is_desired_ep11_card(unsigned int dev_id
,
984 unsigned short target_num
,
985 struct ep11_target_dev
*targets
)
987 while (target_num
-- > 0) {
988 if (targets
->ap_id
== dev_id
|| targets
->ap_id
== AUTOSEL_AP
)
995 static bool is_desired_ep11_queue(unsigned int dev_qid
,
996 unsigned short target_num
,
997 struct ep11_target_dev
*targets
)
999 int card
= AP_QID_CARD(dev_qid
), dom
= AP_QID_QUEUE(dev_qid
);
1001 while (target_num
-- > 0) {
1002 if ((targets
->ap_id
== card
|| targets
->ap_id
== AUTOSEL_AP
) &&
1003 (targets
->dom_id
== dom
|| targets
->dom_id
== AUTOSEL_DOM
))
1010 static long _zcrypt_send_ep11_cprb(bool userspace
, struct ap_perms
*perms
,
1011 struct zcrypt_track
*tr
,
1012 struct ep11_urb
*xcrb
)
1014 struct zcrypt_card
*zc
, *pref_zc
;
1015 struct zcrypt_queue
*zq
, *pref_zq
;
1016 struct ep11_target_dev
*targets
;
1017 unsigned short target_num
;
1018 unsigned int wgt
= 0, pref_wgt
= 0;
1019 unsigned int func_code
;
1020 struct ap_message ap_msg
;
1021 int cpen
, qpen
, qid
= 0, rc
= -ENODEV
;
1024 trace_s390_zcrypt_req(xcrb
, TP_ZSENDEP11CPRB
);
1026 ap_init_message(&ap_msg
);
1028 #ifdef CONFIG_ZCRYPT_DEBUG
1029 if (tr
&& tr
->fi
.cmd
)
1030 ap_msg
.fi
.cmd
= tr
->fi
.cmd
;
1033 target_num
= (unsigned short) xcrb
->targets_num
;
1035 /* empty list indicates autoselect (all available targets) */
1037 if (target_num
!= 0) {
1038 struct ep11_target_dev __user
*uptr
;
1040 targets
= kcalloc(target_num
, sizeof(*targets
), GFP_KERNEL
);
1047 uptr
= (struct ep11_target_dev __force __user
*) xcrb
->targets
;
1048 if (z_copy_from_user(userspace
, targets
, uptr
,
1049 target_num
* sizeof(*targets
))) {
1056 rc
= get_ep11cprb_fc(userspace
, xcrb
, &ap_msg
, &func_code
);
1062 spin_lock(&zcrypt_list_lock
);
1063 for_each_zcrypt_card(zc
) {
1064 /* Check for useable EP11 card */
1065 if (!zc
->online
|| !zc
->card
->config
||
1066 !(zc
->card
->functions
& 0x04000000))
1068 /* Check for user selected EP11 card */
1070 !is_desired_ep11_card(zc
->card
->id
, target_num
, targets
))
1072 /* check if device node has admission for this card */
1073 if (!zcrypt_check_card(perms
, zc
->card
->id
))
1075 /* get weight index of the card device */
1076 wgt
= speed_idx_ep11(func_code
) * zc
->speed_rating
[SECKEY
];
1077 /* penalty if this msg was previously sent via this card */
1078 cpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
1079 AP_QID_CARD(tr
->last_qid
) == zc
->card
->id
) ?
1080 TRACK_AGAIN_CARD_WEIGHT_PENALTY
: 0;
1081 if (!zcrypt_card_compare(zc
, pref_zc
, wgt
+ cpen
, pref_wgt
))
1083 for_each_zcrypt_queue(zq
, zc
) {
1084 /* check if device is useable and eligible */
1086 !zq
->ops
->send_ep11_cprb
||
1087 !zq
->queue
->config
||
1089 !is_desired_ep11_queue(zq
->queue
->qid
,
1090 target_num
, targets
)))
1092 /* check if device node has admission for this queue */
1093 if (!zcrypt_check_queue(perms
,
1094 AP_QID_QUEUE(zq
->queue
->qid
)))
1096 /* penalty if the msg was previously sent at this qid */
1097 qpen
= (tr
&& tr
->again_counter
&& tr
->last_qid
&&
1098 tr
->last_qid
== zq
->queue
->qid
) ?
1099 TRACK_AGAIN_QUEUE_WEIGHT_PENALTY
: 0;
1100 if (!zcrypt_queue_compare(zq
, pref_zq
,
1101 wgt
+ cpen
+ qpen
, pref_wgt
))
1105 pref_wgt
= wgt
+ cpen
+ qpen
;
1108 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, &mod
, wgt
);
1109 spin_unlock(&zcrypt_list_lock
);
1116 qid
= pref_zq
->queue
->qid
;
1117 rc
= pref_zq
->ops
->send_ep11_cprb(userspace
, pref_zq
, xcrb
, &ap_msg
);
1119 spin_lock(&zcrypt_list_lock
);
1120 zcrypt_drop_queue(pref_zc
, pref_zq
, mod
, wgt
);
1121 spin_unlock(&zcrypt_list_lock
);
1126 ap_release_message(&ap_msg
);
1131 trace_s390_zcrypt_rep(xcrb
, func_code
, rc
,
1132 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
1136 long zcrypt_send_ep11_cprb(struct ep11_urb
*xcrb
)
1138 return _zcrypt_send_ep11_cprb(false, &ap_perms
, NULL
, xcrb
);
1140 EXPORT_SYMBOL(zcrypt_send_ep11_cprb
);
1142 static long zcrypt_rng(char *buffer
)
1144 struct zcrypt_card
*zc
, *pref_zc
;
1145 struct zcrypt_queue
*zq
, *pref_zq
;
1146 unsigned int wgt
= 0, pref_wgt
= 0;
1147 unsigned int func_code
;
1148 struct ap_message ap_msg
;
1149 unsigned int domain
;
1150 int qid
= 0, rc
= -ENODEV
;
1153 trace_s390_zcrypt_req(buffer
, TP_HWRNGCPRB
);
1155 ap_init_message(&ap_msg
);
1156 rc
= get_rng_fc(&ap_msg
, &func_code
, &domain
);
1162 spin_lock(&zcrypt_list_lock
);
1163 for_each_zcrypt_card(zc
) {
1164 /* Check for useable CCA card */
1165 if (!zc
->online
|| !zc
->card
->config
||
1166 !(zc
->card
->functions
& 0x10000000))
1168 /* get weight index of the card device */
1169 wgt
= zc
->speed_rating
[func_code
];
1170 if (!zcrypt_card_compare(zc
, pref_zc
, wgt
, pref_wgt
))
1172 for_each_zcrypt_queue(zq
, zc
) {
1173 /* check if device is useable and eligible */
1174 if (!zq
->online
|| !zq
->ops
->rng
||
1177 if (!zcrypt_queue_compare(zq
, pref_zq
, wgt
, pref_wgt
))
1184 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, &mod
, wgt
);
1185 spin_unlock(&zcrypt_list_lock
);
1192 qid
= pref_zq
->queue
->qid
;
1193 rc
= pref_zq
->ops
->rng(pref_zq
, buffer
, &ap_msg
);
1195 spin_lock(&zcrypt_list_lock
);
1196 zcrypt_drop_queue(pref_zc
, pref_zq
, mod
, wgt
);
1197 spin_unlock(&zcrypt_list_lock
);
1200 ap_release_message(&ap_msg
);
1201 trace_s390_zcrypt_rep(buffer
, func_code
, rc
,
1202 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
1206 static void zcrypt_device_status_mask(struct zcrypt_device_status
*devstatus
)
1208 struct zcrypt_card
*zc
;
1209 struct zcrypt_queue
*zq
;
1210 struct zcrypt_device_status
*stat
;
1213 memset(devstatus
, 0, MAX_ZDEV_ENTRIES
1214 * sizeof(struct zcrypt_device_status
));
1216 spin_lock(&zcrypt_list_lock
);
1217 for_each_zcrypt_card(zc
) {
1218 for_each_zcrypt_queue(zq
, zc
) {
1219 card
= AP_QID_CARD(zq
->queue
->qid
);
1220 if (card
>= MAX_ZDEV_CARDIDS
)
1222 queue
= AP_QID_QUEUE(zq
->queue
->qid
);
1223 stat
= &devstatus
[card
* AP_DOMAINS
+ queue
];
1224 stat
->hwtype
= zc
->card
->ap_dev
.device_type
;
1225 stat
->functions
= zc
->card
->functions
>> 26;
1226 stat
->qid
= zq
->queue
->qid
;
1227 stat
->online
= zq
->online
? 0x01 : 0x00;
1230 spin_unlock(&zcrypt_list_lock
);
1233 void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext
*devstatus
)
1235 struct zcrypt_card
*zc
;
1236 struct zcrypt_queue
*zq
;
1237 struct zcrypt_device_status_ext
*stat
;
1240 memset(devstatus
, 0, MAX_ZDEV_ENTRIES_EXT
1241 * sizeof(struct zcrypt_device_status_ext
));
1243 spin_lock(&zcrypt_list_lock
);
1244 for_each_zcrypt_card(zc
) {
1245 for_each_zcrypt_queue(zq
, zc
) {
1246 card
= AP_QID_CARD(zq
->queue
->qid
);
1247 queue
= AP_QID_QUEUE(zq
->queue
->qid
);
1248 stat
= &devstatus
[card
* AP_DOMAINS
+ queue
];
1249 stat
->hwtype
= zc
->card
->ap_dev
.device_type
;
1250 stat
->functions
= zc
->card
->functions
>> 26;
1251 stat
->qid
= zq
->queue
->qid
;
1252 stat
->online
= zq
->online
? 0x01 : 0x00;
1255 spin_unlock(&zcrypt_list_lock
);
1257 EXPORT_SYMBOL(zcrypt_device_status_mask_ext
);
1259 int zcrypt_device_status_ext(int card
, int queue
,
1260 struct zcrypt_device_status_ext
*devstat
)
1262 struct zcrypt_card
*zc
;
1263 struct zcrypt_queue
*zq
;
1265 memset(devstat
, 0, sizeof(*devstat
));
1267 spin_lock(&zcrypt_list_lock
);
1268 for_each_zcrypt_card(zc
) {
1269 for_each_zcrypt_queue(zq
, zc
) {
1270 if (card
== AP_QID_CARD(zq
->queue
->qid
) &&
1271 queue
== AP_QID_QUEUE(zq
->queue
->qid
)) {
1272 devstat
->hwtype
= zc
->card
->ap_dev
.device_type
;
1273 devstat
->functions
= zc
->card
->functions
>> 26;
1274 devstat
->qid
= zq
->queue
->qid
;
1275 devstat
->online
= zq
->online
? 0x01 : 0x00;
1276 spin_unlock(&zcrypt_list_lock
);
1281 spin_unlock(&zcrypt_list_lock
);
1285 EXPORT_SYMBOL(zcrypt_device_status_ext
);
1287 static void zcrypt_status_mask(char status
[], size_t max_adapters
)
1289 struct zcrypt_card
*zc
;
1290 struct zcrypt_queue
*zq
;
1293 memset(status
, 0, max_adapters
);
1294 spin_lock(&zcrypt_list_lock
);
1295 for_each_zcrypt_card(zc
) {
1296 for_each_zcrypt_queue(zq
, zc
) {
1297 card
= AP_QID_CARD(zq
->queue
->qid
);
1298 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
1299 || card
>= max_adapters
)
1301 status
[card
] = zc
->online
? zc
->user_space_type
: 0x0d;
1304 spin_unlock(&zcrypt_list_lock
);
1307 static void zcrypt_qdepth_mask(char qdepth
[], size_t max_adapters
)
1309 struct zcrypt_card
*zc
;
1310 struct zcrypt_queue
*zq
;
1313 memset(qdepth
, 0, max_adapters
);
1314 spin_lock(&zcrypt_list_lock
);
1316 for_each_zcrypt_card(zc
) {
1317 for_each_zcrypt_queue(zq
, zc
) {
1318 card
= AP_QID_CARD(zq
->queue
->qid
);
1319 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
1320 || card
>= max_adapters
)
1322 spin_lock(&zq
->queue
->lock
);
1324 zq
->queue
->pendingq_count
+
1325 zq
->queue
->requestq_count
;
1326 spin_unlock(&zq
->queue
->lock
);
1330 spin_unlock(&zcrypt_list_lock
);
1333 static void zcrypt_perdev_reqcnt(u32 reqcnt
[], size_t max_adapters
)
1335 struct zcrypt_card
*zc
;
1336 struct zcrypt_queue
*zq
;
1340 memset(reqcnt
, 0, sizeof(int) * max_adapters
);
1341 spin_lock(&zcrypt_list_lock
);
1343 for_each_zcrypt_card(zc
) {
1344 for_each_zcrypt_queue(zq
, zc
) {
1345 card
= AP_QID_CARD(zq
->queue
->qid
);
1346 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
1347 || card
>= max_adapters
)
1349 spin_lock(&zq
->queue
->lock
);
1350 cnt
= zq
->queue
->total_request_count
;
1351 spin_unlock(&zq
->queue
->lock
);
1352 reqcnt
[card
] = (cnt
< UINT_MAX
) ? (u32
) cnt
: UINT_MAX
;
1356 spin_unlock(&zcrypt_list_lock
);
1359 static int zcrypt_pendingq_count(void)
1361 struct zcrypt_card
*zc
;
1362 struct zcrypt_queue
*zq
;
1366 spin_lock(&zcrypt_list_lock
);
1368 for_each_zcrypt_card(zc
) {
1369 for_each_zcrypt_queue(zq
, zc
) {
1370 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
1372 spin_lock(&zq
->queue
->lock
);
1373 pendingq_count
+= zq
->queue
->pendingq_count
;
1374 spin_unlock(&zq
->queue
->lock
);
1378 spin_unlock(&zcrypt_list_lock
);
1379 return pendingq_count
;
1382 static int zcrypt_requestq_count(void)
1384 struct zcrypt_card
*zc
;
1385 struct zcrypt_queue
*zq
;
1389 spin_lock(&zcrypt_list_lock
);
1391 for_each_zcrypt_card(zc
) {
1392 for_each_zcrypt_queue(zq
, zc
) {
1393 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
1395 spin_lock(&zq
->queue
->lock
);
1396 requestq_count
+= zq
->queue
->requestq_count
;
1397 spin_unlock(&zq
->queue
->lock
);
1401 spin_unlock(&zcrypt_list_lock
);
1402 return requestq_count
;
1405 static int icarsamodexpo_ioctl(struct ap_perms
*perms
, unsigned long arg
)
1408 struct zcrypt_track tr
;
1409 struct ica_rsa_modexpo mex
;
1410 struct ica_rsa_modexpo __user
*umex
= (void __user
*) arg
;
1412 memset(&tr
, 0, sizeof(tr
));
1413 if (copy_from_user(&mex
, umex
, sizeof(mex
)))
1416 #ifdef CONFIG_ZCRYPT_DEBUG
1417 if (mex
.inputdatalength
& (1U << 31)) {
1418 if (!capable(CAP_SYS_ADMIN
))
1420 tr
.fi
.cmd
= (u16
)(mex
.inputdatalength
>> 16);
1422 mex
.inputdatalength
&= 0x0000FFFF;
1426 rc
= zcrypt_rsa_modexpo(perms
, &tr
, &mex
);
1429 #ifdef CONFIG_ZCRYPT_DEBUG
1430 if (rc
== -EAGAIN
&& (tr
.fi
.flags
& AP_FI_FLAG_NO_RETRY
))
1433 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1434 /* on failure: retry once again after a requested rescan */
1435 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1437 rc
= zcrypt_rsa_modexpo(perms
, &tr
, &mex
);
1440 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1442 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ICARSAMODEXPO rc=%d\n", rc
);
1445 return put_user(mex
.outputdatalength
, &umex
->outputdatalength
);
1448 static int icarsacrt_ioctl(struct ap_perms
*perms
, unsigned long arg
)
1451 struct zcrypt_track tr
;
1452 struct ica_rsa_modexpo_crt crt
;
1453 struct ica_rsa_modexpo_crt __user
*ucrt
= (void __user
*) arg
;
1455 memset(&tr
, 0, sizeof(tr
));
1456 if (copy_from_user(&crt
, ucrt
, sizeof(crt
)))
1459 #ifdef CONFIG_ZCRYPT_DEBUG
1460 if (crt
.inputdatalength
& (1U << 31)) {
1461 if (!capable(CAP_SYS_ADMIN
))
1463 tr
.fi
.cmd
= (u16
)(crt
.inputdatalength
>> 16);
1465 crt
.inputdatalength
&= 0x0000FFFF;
1469 rc
= zcrypt_rsa_crt(perms
, &tr
, &crt
);
1472 #ifdef CONFIG_ZCRYPT_DEBUG
1473 if (rc
== -EAGAIN
&& (tr
.fi
.flags
& AP_FI_FLAG_NO_RETRY
))
1476 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1477 /* on failure: retry once again after a requested rescan */
1478 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1480 rc
= zcrypt_rsa_crt(perms
, &tr
, &crt
);
1483 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1485 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ICARSACRT rc=%d\n", rc
);
1488 return put_user(crt
.outputdatalength
, &ucrt
->outputdatalength
);
1491 static int zsecsendcprb_ioctl(struct ap_perms
*perms
, unsigned long arg
)
1494 struct ica_xcRB xcRB
;
1495 struct zcrypt_track tr
;
1496 struct ica_xcRB __user
*uxcRB
= (void __user
*) arg
;
1498 memset(&tr
, 0, sizeof(tr
));
1499 if (copy_from_user(&xcRB
, uxcRB
, sizeof(xcRB
)))
1502 #ifdef CONFIG_ZCRYPT_DEBUG
1503 if (xcRB
.status
& (1U << 31)) {
1504 if (!capable(CAP_SYS_ADMIN
))
1506 tr
.fi
.cmd
= (u16
)(xcRB
.status
>> 16);
1508 xcRB
.status
&= 0x0000FFFF;
1512 rc
= _zcrypt_send_cprb(true, perms
, &tr
, &xcRB
);
1515 #ifdef CONFIG_ZCRYPT_DEBUG
1516 if (rc
== -EAGAIN
&& (tr
.fi
.flags
& AP_FI_FLAG_NO_RETRY
))
1519 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1520 /* on failure: retry once again after a requested rescan */
1521 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1523 rc
= _zcrypt_send_cprb(true, perms
, &tr
, &xcRB
);
1526 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1528 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ZSENDCPRB rc=%d status=0x%x\n",
1530 if (copy_to_user(uxcRB
, &xcRB
, sizeof(xcRB
)))
1535 static int zsendep11cprb_ioctl(struct ap_perms
*perms
, unsigned long arg
)
1538 struct ep11_urb xcrb
;
1539 struct zcrypt_track tr
;
1540 struct ep11_urb __user
*uxcrb
= (void __user
*)arg
;
1542 memset(&tr
, 0, sizeof(tr
));
1543 if (copy_from_user(&xcrb
, uxcrb
, sizeof(xcrb
)))
1546 #ifdef CONFIG_ZCRYPT_DEBUG
1547 if (xcrb
.req_len
& (1ULL << 63)) {
1548 if (!capable(CAP_SYS_ADMIN
))
1550 tr
.fi
.cmd
= (u16
)(xcrb
.req_len
>> 48);
1552 xcrb
.req_len
&= 0x0000FFFFFFFFFFFFULL
;
1556 rc
= _zcrypt_send_ep11_cprb(true, perms
, &tr
, &xcrb
);
1559 #ifdef CONFIG_ZCRYPT_DEBUG
1560 if (rc
== -EAGAIN
&& (tr
.fi
.flags
& AP_FI_FLAG_NO_RETRY
))
1563 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1564 /* on failure: retry once again after a requested rescan */
1565 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1567 rc
= _zcrypt_send_ep11_cprb(true, perms
, &tr
, &xcrb
);
1570 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1572 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ZSENDEP11CPRB rc=%d\n", rc
);
1573 if (copy_to_user(uxcrb
, &xcrb
, sizeof(xcrb
)))
1578 static long zcrypt_unlocked_ioctl(struct file
*filp
, unsigned int cmd
,
1582 struct ap_perms
*perms
=
1583 (struct ap_perms
*) filp
->private_data
;
1585 rc
= zcrypt_check_ioctl(perms
, cmd
);
1591 return icarsamodexpo_ioctl(perms
, arg
);
1593 return icarsacrt_ioctl(perms
, arg
);
1595 return zsecsendcprb_ioctl(perms
, arg
);
1597 return zsendep11cprb_ioctl(perms
, arg
);
1598 case ZCRYPT_DEVICE_STATUS
: {
1599 struct zcrypt_device_status_ext
*device_status
;
1600 size_t total_size
= MAX_ZDEV_ENTRIES_EXT
1601 * sizeof(struct zcrypt_device_status_ext
);
1603 device_status
= kzalloc(total_size
, GFP_KERNEL
);
1606 zcrypt_device_status_mask_ext(device_status
);
1607 if (copy_to_user((char __user
*) arg
, device_status
,
1610 kfree(device_status
);
1613 case ZCRYPT_STATUS_MASK
: {
1614 char status
[AP_DEVICES
];
1616 zcrypt_status_mask(status
, AP_DEVICES
);
1617 if (copy_to_user((char __user
*) arg
, status
, sizeof(status
)))
1621 case ZCRYPT_QDEPTH_MASK
: {
1622 char qdepth
[AP_DEVICES
];
1624 zcrypt_qdepth_mask(qdepth
, AP_DEVICES
);
1625 if (copy_to_user((char __user
*) arg
, qdepth
, sizeof(qdepth
)))
1629 case ZCRYPT_PERDEV_REQCNT
: {
1632 reqcnt
= kcalloc(AP_DEVICES
, sizeof(u32
), GFP_KERNEL
);
1635 zcrypt_perdev_reqcnt(reqcnt
, AP_DEVICES
);
1636 if (copy_to_user((int __user
*) arg
, reqcnt
,
1637 sizeof(u32
) * AP_DEVICES
))
1642 case Z90STAT_REQUESTQ_COUNT
:
1643 return put_user(zcrypt_requestq_count(), (int __user
*) arg
);
1644 case Z90STAT_PENDINGQ_COUNT
:
1645 return put_user(zcrypt_pendingq_count(), (int __user
*) arg
);
1646 case Z90STAT_TOTALOPEN_COUNT
:
1647 return put_user(atomic_read(&zcrypt_open_count
),
1648 (int __user
*) arg
);
1649 case Z90STAT_DOMAIN_INDEX
:
1650 return put_user(ap_domain_index
, (int __user
*) arg
);
1654 case ZDEVICESTATUS
: {
1655 /* the old ioctl supports only 64 adapters */
1656 struct zcrypt_device_status
*device_status
;
1657 size_t total_size
= MAX_ZDEV_ENTRIES
1658 * sizeof(struct zcrypt_device_status
);
1660 device_status
= kzalloc(total_size
, GFP_KERNEL
);
1663 zcrypt_device_status_mask(device_status
);
1664 if (copy_to_user((char __user
*) arg
, device_status
,
1667 kfree(device_status
);
1670 case Z90STAT_STATUS_MASK
: {
1671 /* the old ioctl supports only 64 adapters */
1672 char status
[MAX_ZDEV_CARDIDS
];
1674 zcrypt_status_mask(status
, MAX_ZDEV_CARDIDS
);
1675 if (copy_to_user((char __user
*) arg
, status
, sizeof(status
)))
1679 case Z90STAT_QDEPTH_MASK
: {
1680 /* the old ioctl supports only 64 adapters */
1681 char qdepth
[MAX_ZDEV_CARDIDS
];
1683 zcrypt_qdepth_mask(qdepth
, MAX_ZDEV_CARDIDS
);
1684 if (copy_to_user((char __user
*) arg
, qdepth
, sizeof(qdepth
)))
1688 case Z90STAT_PERDEV_REQCNT
: {
1689 /* the old ioctl supports only 64 adapters */
1690 u32 reqcnt
[MAX_ZDEV_CARDIDS
];
1692 zcrypt_perdev_reqcnt(reqcnt
, MAX_ZDEV_CARDIDS
);
1693 if (copy_to_user((int __user
*) arg
, reqcnt
, sizeof(reqcnt
)))
1697 /* unknown ioctl number */
1699 ZCRYPT_DBF(DBF_DEBUG
, "unknown ioctl 0x%08x\n", cmd
);
1700 return -ENOIOCTLCMD
;
1704 #ifdef CONFIG_COMPAT
1706 * ioctl32 conversion routines
1708 struct compat_ica_rsa_modexpo
{
1709 compat_uptr_t inputdata
;
1710 unsigned int inputdatalength
;
1711 compat_uptr_t outputdata
;
1712 unsigned int outputdatalength
;
1713 compat_uptr_t b_key
;
1714 compat_uptr_t n_modulus
;
1717 static long trans_modexpo32(struct ap_perms
*perms
, struct file
*filp
,
1718 unsigned int cmd
, unsigned long arg
)
1720 struct compat_ica_rsa_modexpo __user
*umex32
= compat_ptr(arg
);
1721 struct compat_ica_rsa_modexpo mex32
;
1722 struct ica_rsa_modexpo mex64
;
1723 struct zcrypt_track tr
;
1726 memset(&tr
, 0, sizeof(tr
));
1727 if (copy_from_user(&mex32
, umex32
, sizeof(mex32
)))
1729 mex64
.inputdata
= compat_ptr(mex32
.inputdata
);
1730 mex64
.inputdatalength
= mex32
.inputdatalength
;
1731 mex64
.outputdata
= compat_ptr(mex32
.outputdata
);
1732 mex64
.outputdatalength
= mex32
.outputdatalength
;
1733 mex64
.b_key
= compat_ptr(mex32
.b_key
);
1734 mex64
.n_modulus
= compat_ptr(mex32
.n_modulus
);
1736 rc
= zcrypt_rsa_modexpo(perms
, &tr
, &mex64
);
1739 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1740 /* on failure: retry once again after a requested rescan */
1741 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1743 rc
= zcrypt_rsa_modexpo(perms
, &tr
, &mex64
);
1746 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1749 return put_user(mex64
.outputdatalength
,
1750 &umex32
->outputdatalength
);
1753 struct compat_ica_rsa_modexpo_crt
{
1754 compat_uptr_t inputdata
;
1755 unsigned int inputdatalength
;
1756 compat_uptr_t outputdata
;
1757 unsigned int outputdatalength
;
1758 compat_uptr_t bp_key
;
1759 compat_uptr_t bq_key
;
1760 compat_uptr_t np_prime
;
1761 compat_uptr_t nq_prime
;
1762 compat_uptr_t u_mult_inv
;
1765 static long trans_modexpo_crt32(struct ap_perms
*perms
, struct file
*filp
,
1766 unsigned int cmd
, unsigned long arg
)
1768 struct compat_ica_rsa_modexpo_crt __user
*ucrt32
= compat_ptr(arg
);
1769 struct compat_ica_rsa_modexpo_crt crt32
;
1770 struct ica_rsa_modexpo_crt crt64
;
1771 struct zcrypt_track tr
;
1774 memset(&tr
, 0, sizeof(tr
));
1775 if (copy_from_user(&crt32
, ucrt32
, sizeof(crt32
)))
1777 crt64
.inputdata
= compat_ptr(crt32
.inputdata
);
1778 crt64
.inputdatalength
= crt32
.inputdatalength
;
1779 crt64
.outputdata
= compat_ptr(crt32
.outputdata
);
1780 crt64
.outputdatalength
= crt32
.outputdatalength
;
1781 crt64
.bp_key
= compat_ptr(crt32
.bp_key
);
1782 crt64
.bq_key
= compat_ptr(crt32
.bq_key
);
1783 crt64
.np_prime
= compat_ptr(crt32
.np_prime
);
1784 crt64
.nq_prime
= compat_ptr(crt32
.nq_prime
);
1785 crt64
.u_mult_inv
= compat_ptr(crt32
.u_mult_inv
);
1787 rc
= zcrypt_rsa_crt(perms
, &tr
, &crt64
);
1790 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1791 /* on failure: retry once again after a requested rescan */
1792 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1794 rc
= zcrypt_rsa_crt(perms
, &tr
, &crt64
);
1797 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1800 return put_user(crt64
.outputdatalength
,
1801 &ucrt32
->outputdatalength
);
1804 struct compat_ica_xcRB
{
1805 unsigned short agent_ID
;
1806 unsigned int user_defined
;
1807 unsigned short request_ID
;
1808 unsigned int request_control_blk_length
;
1809 unsigned char padding1
[16 - sizeof(compat_uptr_t
)];
1810 compat_uptr_t request_control_blk_addr
;
1811 unsigned int request_data_length
;
1812 char padding2
[16 - sizeof(compat_uptr_t
)];
1813 compat_uptr_t request_data_address
;
1814 unsigned int reply_control_blk_length
;
1815 char padding3
[16 - sizeof(compat_uptr_t
)];
1816 compat_uptr_t reply_control_blk_addr
;
1817 unsigned int reply_data_length
;
1818 char padding4
[16 - sizeof(compat_uptr_t
)];
1819 compat_uptr_t reply_data_addr
;
1820 unsigned short priority_window
;
1821 unsigned int status
;
1824 static long trans_xcRB32(struct ap_perms
*perms
, struct file
*filp
,
1825 unsigned int cmd
, unsigned long arg
)
1827 struct compat_ica_xcRB __user
*uxcRB32
= compat_ptr(arg
);
1828 struct compat_ica_xcRB xcRB32
;
1829 struct zcrypt_track tr
;
1830 struct ica_xcRB xcRB64
;
1833 memset(&tr
, 0, sizeof(tr
));
1834 if (copy_from_user(&xcRB32
, uxcRB32
, sizeof(xcRB32
)))
1836 xcRB64
.agent_ID
= xcRB32
.agent_ID
;
1837 xcRB64
.user_defined
= xcRB32
.user_defined
;
1838 xcRB64
.request_ID
= xcRB32
.request_ID
;
1839 xcRB64
.request_control_blk_length
=
1840 xcRB32
.request_control_blk_length
;
1841 xcRB64
.request_control_blk_addr
=
1842 compat_ptr(xcRB32
.request_control_blk_addr
);
1843 xcRB64
.request_data_length
=
1844 xcRB32
.request_data_length
;
1845 xcRB64
.request_data_address
=
1846 compat_ptr(xcRB32
.request_data_address
);
1847 xcRB64
.reply_control_blk_length
=
1848 xcRB32
.reply_control_blk_length
;
1849 xcRB64
.reply_control_blk_addr
=
1850 compat_ptr(xcRB32
.reply_control_blk_addr
);
1851 xcRB64
.reply_data_length
= xcRB32
.reply_data_length
;
1852 xcRB64
.reply_data_addr
=
1853 compat_ptr(xcRB32
.reply_data_addr
);
1854 xcRB64
.priority_window
= xcRB32
.priority_window
;
1855 xcRB64
.status
= xcRB32
.status
;
1857 rc
= _zcrypt_send_cprb(true, perms
, &tr
, &xcRB64
);
1860 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1861 /* on failure: retry once again after a requested rescan */
1862 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1864 rc
= _zcrypt_send_cprb(true, perms
, &tr
, &xcRB64
);
1867 } while (rc
== -EAGAIN
&& tr
.again_counter
< TRACK_AGAIN_MAX
);
1868 xcRB32
.reply_control_blk_length
= xcRB64
.reply_control_blk_length
;
1869 xcRB32
.reply_data_length
= xcRB64
.reply_data_length
;
1870 xcRB32
.status
= xcRB64
.status
;
1871 if (copy_to_user(uxcRB32
, &xcRB32
, sizeof(xcRB32
)))
1876 static long zcrypt_compat_ioctl(struct file
*filp
, unsigned int cmd
,
1880 struct ap_perms
*perms
=
1881 (struct ap_perms
*) filp
->private_data
;
1883 rc
= zcrypt_check_ioctl(perms
, cmd
);
1887 if (cmd
== ICARSAMODEXPO
)
1888 return trans_modexpo32(perms
, filp
, cmd
, arg
);
1889 if (cmd
== ICARSACRT
)
1890 return trans_modexpo_crt32(perms
, filp
, cmd
, arg
);
1891 if (cmd
== ZSECSENDCPRB
)
1892 return trans_xcRB32(perms
, filp
, cmd
, arg
);
1893 return zcrypt_unlocked_ioctl(filp
, cmd
, arg
);
1898 * Misc device file operations.
1900 static const struct file_operations zcrypt_fops
= {
1901 .owner
= THIS_MODULE
,
1902 .read
= zcrypt_read
,
1903 .write
= zcrypt_write
,
1904 .unlocked_ioctl
= zcrypt_unlocked_ioctl
,
1905 #ifdef CONFIG_COMPAT
1906 .compat_ioctl
= zcrypt_compat_ioctl
,
1908 .open
= zcrypt_open
,
1909 .release
= zcrypt_release
,
1910 .llseek
= no_llseek
,
1916 static struct miscdevice zcrypt_misc_device
= {
1917 .minor
= MISC_DYNAMIC_MINOR
,
1919 .fops
= &zcrypt_fops
,
1922 static int zcrypt_rng_device_count
;
1923 static u32
*zcrypt_rng_buffer
;
1924 static int zcrypt_rng_buffer_index
;
1925 static DEFINE_MUTEX(zcrypt_rng_mutex
);
1927 static int zcrypt_rng_data_read(struct hwrng
*rng
, u32
*data
)
1932 * We don't need locking here because the RNG API guarantees serialized
1933 * read method calls.
1935 if (zcrypt_rng_buffer_index
== 0) {
1936 rc
= zcrypt_rng((char *) zcrypt_rng_buffer
);
1937 /* on failure: retry once again after a requested rescan */
1938 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1939 rc
= zcrypt_rng((char *) zcrypt_rng_buffer
);
1942 zcrypt_rng_buffer_index
= rc
/ sizeof(*data
);
1944 *data
= zcrypt_rng_buffer
[--zcrypt_rng_buffer_index
];
1945 return sizeof(*data
);
1948 static struct hwrng zcrypt_rng_dev
= {
1950 .data_read
= zcrypt_rng_data_read
,
1954 int zcrypt_rng_device_add(void)
1958 mutex_lock(&zcrypt_rng_mutex
);
1959 if (zcrypt_rng_device_count
== 0) {
1960 zcrypt_rng_buffer
= (u32
*) get_zeroed_page(GFP_KERNEL
);
1961 if (!zcrypt_rng_buffer
) {
1965 zcrypt_rng_buffer_index
= 0;
1966 if (!zcrypt_hwrng_seed
)
1967 zcrypt_rng_dev
.quality
= 0;
1968 rc
= hwrng_register(&zcrypt_rng_dev
);
1971 zcrypt_rng_device_count
= 1;
1973 zcrypt_rng_device_count
++;
1974 mutex_unlock(&zcrypt_rng_mutex
);
1978 free_page((unsigned long) zcrypt_rng_buffer
);
1980 mutex_unlock(&zcrypt_rng_mutex
);
1984 void zcrypt_rng_device_remove(void)
1986 mutex_lock(&zcrypt_rng_mutex
);
1987 zcrypt_rng_device_count
--;
1988 if (zcrypt_rng_device_count
== 0) {
1989 hwrng_unregister(&zcrypt_rng_dev
);
1990 free_page((unsigned long) zcrypt_rng_buffer
);
1992 mutex_unlock(&zcrypt_rng_mutex
);
1996 * Wait until the zcrypt api is operational.
1997 * The AP bus scan and the binding of ap devices to device drivers is
1998 * an asynchronous job. This function waits until these initial jobs
1999 * are done and so the zcrypt api should be ready to serve crypto
2000 * requests - if there are resources available. The function uses an
2001 * internal timeout of 60s. The very first caller will either wait for
2002 * ap bus bindings complete or the timeout happens. This state will be
2003 * remembered for further callers which will only be blocked until a
2004 * decision is made (timeout or bindings complete).
2005 * On timeout -ETIME is returned, on success the return value is 0.
2007 int zcrypt_wait_api_operational(void)
2009 static DEFINE_MUTEX(zcrypt_wait_api_lock
);
2010 static int zcrypt_wait_api_state
;
2013 rc
= mutex_lock_interruptible(&zcrypt_wait_api_lock
);
2017 switch (zcrypt_wait_api_state
) {
2019 /* initial state, invoke wait for the ap bus complete */
2020 rc
= ap_wait_init_apqn_bindings_complete(
2021 msecs_to_jiffies(60 * 1000));
2024 /* ap bus bindings are complete */
2025 zcrypt_wait_api_state
= 1;
2028 /* interrupted, go back to caller */
2032 ZCRYPT_DBF(DBF_WARN
,
2033 "%s ap_wait_init_apqn_bindings_complete() returned with ETIME\n",
2035 zcrypt_wait_api_state
= -ETIME
;
2039 ZCRYPT_DBF(DBF_DEBUG
,
2040 "%s ap_wait_init_apqn_bindings_complete() failure rc=%d\n",
2046 /* a previous caller already found ap bus bindings complete */
2050 /* a previous caller had timeout or other failure */
2051 rc
= zcrypt_wait_api_state
;
2055 mutex_unlock(&zcrypt_wait_api_lock
);
2059 EXPORT_SYMBOL(zcrypt_wait_api_operational
);
2061 int __init
zcrypt_debug_init(void)
2063 zcrypt_dbf_info
= debug_register("zcrypt", 1, 1,
2064 DBF_MAX_SPRINTF_ARGS
* sizeof(long));
2065 debug_register_view(zcrypt_dbf_info
, &debug_sprintf_view
);
2066 debug_set_level(zcrypt_dbf_info
, DBF_ERR
);
2071 void zcrypt_debug_exit(void)
2073 debug_unregister(zcrypt_dbf_info
);
2076 #ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2078 static int __init
zcdn_init(void)
2082 /* create a new class 'zcrypt' */
2083 zcrypt_class
= class_create(THIS_MODULE
, ZCRYPT_NAME
);
2084 if (IS_ERR(zcrypt_class
)) {
2085 rc
= PTR_ERR(zcrypt_class
);
2086 goto out_class_create_failed
;
2088 zcrypt_class
->dev_release
= zcdn_device_release
;
2090 /* alloc device minor range */
2091 rc
= alloc_chrdev_region(&zcrypt_devt
,
2092 0, ZCRYPT_MAX_MINOR_NODES
,
2095 goto out_alloc_chrdev_failed
;
2097 cdev_init(&zcrypt_cdev
, &zcrypt_fops
);
2098 zcrypt_cdev
.owner
= THIS_MODULE
;
2099 rc
= cdev_add(&zcrypt_cdev
, zcrypt_devt
, ZCRYPT_MAX_MINOR_NODES
);
2101 goto out_cdev_add_failed
;
2103 /* need some class specific sysfs attributes */
2104 rc
= class_create_file(zcrypt_class
, &class_attr_zcdn_create
);
2106 goto out_class_create_file_1_failed
;
2107 rc
= class_create_file(zcrypt_class
, &class_attr_zcdn_destroy
);
2109 goto out_class_create_file_2_failed
;
2113 out_class_create_file_2_failed
:
2114 class_remove_file(zcrypt_class
, &class_attr_zcdn_create
);
2115 out_class_create_file_1_failed
:
2116 cdev_del(&zcrypt_cdev
);
2117 out_cdev_add_failed
:
2118 unregister_chrdev_region(zcrypt_devt
, ZCRYPT_MAX_MINOR_NODES
);
2119 out_alloc_chrdev_failed
:
2120 class_destroy(zcrypt_class
);
2121 out_class_create_failed
:
2125 static void zcdn_exit(void)
2127 class_remove_file(zcrypt_class
, &class_attr_zcdn_create
);
2128 class_remove_file(zcrypt_class
, &class_attr_zcdn_destroy
);
2130 cdev_del(&zcrypt_cdev
);
2131 unregister_chrdev_region(zcrypt_devt
, ZCRYPT_MAX_MINOR_NODES
);
2132 class_destroy(zcrypt_class
);
2138 * zcrypt_api_init(): Module initialization.
2140 * The module initialization code.
2142 int __init
zcrypt_api_init(void)
2146 rc
= zcrypt_debug_init();
2150 #ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2156 /* Register the request sprayer. */
2157 rc
= misc_register(&zcrypt_misc_device
);
2159 goto out_misc_register_failed
;
2161 zcrypt_msgtype6_init();
2162 zcrypt_msgtype50_init();
2166 out_misc_register_failed
:
2167 #ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2170 zcrypt_debug_exit();
2176 * zcrypt_api_exit(): Module termination.
2178 * The module termination code.
2180 void __exit
zcrypt_api_exit(void)
2182 #ifdef CONFIG_ZCRYPT_MULTIDEVNODES
2185 misc_deregister(&zcrypt_misc_device
);
2186 zcrypt_msgtype6_exit();
2187 zcrypt_msgtype50_exit();
2188 zcrypt_ccamisc_exit();
2189 zcrypt_ep11misc_exit();
2190 zcrypt_debug_exit();
2193 module_init(zcrypt_api_init
);
2194 module_exit(zcrypt_api_exit
);