1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright IBM Corp. 2001, 2012
6 * Author(s): Robert Burroughs
7 * Eric Rossman (edrossma@us.ibm.com)
8 * Cornelia Huck <cornelia.huck@de.ibm.com>
10 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
11 * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
12 * Ralph Wuerthner <rwuerthn@de.ibm.com>
13 * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/interrupt.h>
19 #include <linux/miscdevice.h>
21 #include <linux/proc_fs.h>
22 #include <linux/seq_file.h>
23 #include <linux/compat.h>
24 #include <linux/slab.h>
25 #include <linux/atomic.h>
26 #include <linux/uaccess.h>
27 #include <linux/hw_random.h>
28 #include <linux/debugfs.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"
43 MODULE_AUTHOR("IBM Corporation");
44 MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \
45 "Copyright IBM Corp. 2001, 2012");
46 MODULE_LICENSE("GPL");
49 * zcrypt tracepoint functions
51 EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_req
);
52 EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_rep
);
54 static int zcrypt_hwrng_seed
= 1;
55 module_param_named(hwrng_seed
, zcrypt_hwrng_seed
, int, S_IRUSR
|S_IRGRP
);
56 MODULE_PARM_DESC(hwrng_seed
, "Turn on/off hwrng auto seed, default is 1 (on).");
58 DEFINE_SPINLOCK(zcrypt_list_lock
);
59 LIST_HEAD(zcrypt_card_list
);
60 int zcrypt_device_count
;
62 static atomic_t zcrypt_open_count
= ATOMIC_INIT(0);
63 static atomic_t zcrypt_rescan_count
= ATOMIC_INIT(0);
65 atomic_t zcrypt_rescan_req
= ATOMIC_INIT(0);
66 EXPORT_SYMBOL(zcrypt_rescan_req
);
68 static LIST_HEAD(zcrypt_ops_list
);
70 /* Zcrypt related debug feature stuff. */
71 debug_info_t
*zcrypt_dbf_info
;
74 * Process a rescan of the transport layer.
76 * Returns 1, if the rescan has been processed, otherwise 0.
78 static inline int zcrypt_process_rescan(void)
80 if (atomic_read(&zcrypt_rescan_req
)) {
81 atomic_set(&zcrypt_rescan_req
, 0);
82 atomic_inc(&zcrypt_rescan_count
);
83 ap_bus_force_rescan();
84 ZCRYPT_DBF(DBF_INFO
, "rescan count=%07d\n",
85 atomic_inc_return(&zcrypt_rescan_count
));
91 void zcrypt_msgtype_register(struct zcrypt_ops
*zops
)
93 list_add_tail(&zops
->list
, &zcrypt_ops_list
);
96 void zcrypt_msgtype_unregister(struct zcrypt_ops
*zops
)
98 list_del_init(&zops
->list
);
101 struct zcrypt_ops
*zcrypt_msgtype(unsigned char *name
, int variant
)
103 struct zcrypt_ops
*zops
;
105 list_for_each_entry(zops
, &zcrypt_ops_list
, list
)
106 if ((zops
->variant
== variant
) &&
107 (!strncmp(zops
->name
, name
, sizeof(zops
->name
))))
111 EXPORT_SYMBOL(zcrypt_msgtype
);
114 * zcrypt_read (): Not supported beyond zcrypt 1.3.1.
116 * This function is not supported beyond zcrypt 1.3.1.
118 static ssize_t
zcrypt_read(struct file
*filp
, char __user
*buf
,
119 size_t count
, loff_t
*f_pos
)
125 * zcrypt_write(): Not allowed.
127 * Write is is not allowed
129 static ssize_t
zcrypt_write(struct file
*filp
, const char __user
*buf
,
130 size_t count
, loff_t
*f_pos
)
136 * zcrypt_open(): Count number of users.
138 * Device open function to count number of users.
140 static int zcrypt_open(struct inode
*inode
, struct file
*filp
)
142 atomic_inc(&zcrypt_open_count
);
143 return nonseekable_open(inode
, filp
);
147 * zcrypt_release(): Count number of users.
149 * Device close function to count number of users.
151 static int zcrypt_release(struct inode
*inode
, struct file
*filp
)
153 atomic_dec(&zcrypt_open_count
);
157 static inline struct zcrypt_queue
*zcrypt_pick_queue(struct zcrypt_card
*zc
,
158 struct zcrypt_queue
*zq
,
161 if (!zq
|| !try_module_get(zq
->queue
->ap_dev
.drv
->driver
.owner
))
163 zcrypt_queue_get(zq
);
164 get_device(&zq
->queue
->ap_dev
.device
);
165 atomic_add(weight
, &zc
->load
);
166 atomic_add(weight
, &zq
->load
);
171 static inline void zcrypt_drop_queue(struct zcrypt_card
*zc
,
172 struct zcrypt_queue
*zq
,
175 struct module
*mod
= zq
->queue
->ap_dev
.drv
->driver
.owner
;
178 atomic_sub(weight
, &zc
->load
);
179 atomic_sub(weight
, &zq
->load
);
180 put_device(&zq
->queue
->ap_dev
.device
);
181 zcrypt_queue_put(zq
);
185 static inline bool zcrypt_card_compare(struct zcrypt_card
*zc
,
186 struct zcrypt_card
*pref_zc
,
187 unsigned weight
, unsigned pref_weight
)
191 weight
+= atomic_read(&zc
->load
);
192 pref_weight
+= atomic_read(&pref_zc
->load
);
193 if (weight
== pref_weight
)
194 return atomic_read(&zc
->card
->total_request_count
) >
195 atomic_read(&pref_zc
->card
->total_request_count
);
196 return weight
> pref_weight
;
199 static inline bool zcrypt_queue_compare(struct zcrypt_queue
*zq
,
200 struct zcrypt_queue
*pref_zq
,
201 unsigned weight
, unsigned pref_weight
)
205 weight
+= atomic_read(&zq
->load
);
206 pref_weight
+= atomic_read(&pref_zq
->load
);
207 if (weight
== pref_weight
)
208 return zq
->queue
->total_request_count
>
209 pref_zq
->queue
->total_request_count
;
210 return weight
> pref_weight
;
216 static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo
*mex
)
218 struct zcrypt_card
*zc
, *pref_zc
;
219 struct zcrypt_queue
*zq
, *pref_zq
;
220 unsigned int weight
, pref_weight
;
221 unsigned int func_code
;
222 int qid
= 0, rc
= -ENODEV
;
224 trace_s390_zcrypt_req(mex
, TP_ICARSAMODEXPO
);
226 if (mex
->outputdatalength
< mex
->inputdatalength
) {
232 * As long as outputdatalength is big enough, we can set the
233 * outputdatalength equal to the inputdatalength, since that is the
234 * number of bytes we will copy in any case
236 mex
->outputdatalength
= mex
->inputdatalength
;
238 rc
= get_rsa_modex_fc(mex
, &func_code
);
244 spin_lock(&zcrypt_list_lock
);
245 for_each_zcrypt_card(zc
) {
246 /* Check for online accelarator and CCA cards */
247 if (!zc
->online
|| !(zc
->card
->functions
& 0x18000000))
249 /* Check for size limits */
250 if (zc
->min_mod_size
> mex
->inputdatalength
||
251 zc
->max_mod_size
< mex
->inputdatalength
)
253 /* get weight index of the card device */
254 weight
= zc
->speed_rating
[func_code
];
255 if (zcrypt_card_compare(zc
, pref_zc
, weight
, pref_weight
))
257 for_each_zcrypt_queue(zq
, zc
) {
258 /* check if device is online and eligible */
259 if (!zq
->online
|| !zq
->ops
->rsa_modexpo
)
261 if (zcrypt_queue_compare(zq
, pref_zq
,
262 weight
, pref_weight
))
266 pref_weight
= weight
;
269 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, weight
);
270 spin_unlock(&zcrypt_list_lock
);
277 qid
= pref_zq
->queue
->qid
;
278 rc
= pref_zq
->ops
->rsa_modexpo(pref_zq
, mex
);
280 spin_lock(&zcrypt_list_lock
);
281 zcrypt_drop_queue(pref_zc
, pref_zq
, weight
);
282 spin_unlock(&zcrypt_list_lock
);
285 trace_s390_zcrypt_rep(mex
, func_code
, rc
,
286 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
290 static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt
*crt
)
292 struct zcrypt_card
*zc
, *pref_zc
;
293 struct zcrypt_queue
*zq
, *pref_zq
;
294 unsigned int weight
, pref_weight
;
295 unsigned int func_code
;
296 int qid
= 0, rc
= -ENODEV
;
298 trace_s390_zcrypt_req(crt
, TP_ICARSACRT
);
300 if (crt
->outputdatalength
< crt
->inputdatalength
) {
306 * As long as outputdatalength is big enough, we can set the
307 * outputdatalength equal to the inputdatalength, since that is the
308 * number of bytes we will copy in any case
310 crt
->outputdatalength
= crt
->inputdatalength
;
312 rc
= get_rsa_crt_fc(crt
, &func_code
);
318 spin_lock(&zcrypt_list_lock
);
319 for_each_zcrypt_card(zc
) {
320 /* Check for online accelarator and CCA cards */
321 if (!zc
->online
|| !(zc
->card
->functions
& 0x18000000))
323 /* Check for size limits */
324 if (zc
->min_mod_size
> crt
->inputdatalength
||
325 zc
->max_mod_size
< crt
->inputdatalength
)
327 /* get weight index of the card device */
328 weight
= zc
->speed_rating
[func_code
];
329 if (zcrypt_card_compare(zc
, pref_zc
, weight
, pref_weight
))
331 for_each_zcrypt_queue(zq
, zc
) {
332 /* check if device is online and eligible */
333 if (!zq
->online
|| !zq
->ops
->rsa_modexpo_crt
)
335 if (zcrypt_queue_compare(zq
, pref_zq
,
336 weight
, pref_weight
))
340 pref_weight
= weight
;
343 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, weight
);
344 spin_unlock(&zcrypt_list_lock
);
351 qid
= pref_zq
->queue
->qid
;
352 rc
= pref_zq
->ops
->rsa_modexpo_crt(pref_zq
, crt
);
354 spin_lock(&zcrypt_list_lock
);
355 zcrypt_drop_queue(pref_zc
, pref_zq
, weight
);
356 spin_unlock(&zcrypt_list_lock
);
359 trace_s390_zcrypt_rep(crt
, func_code
, rc
,
360 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
364 long zcrypt_send_cprb(struct ica_xcRB
*xcRB
)
366 struct zcrypt_card
*zc
, *pref_zc
;
367 struct zcrypt_queue
*zq
, *pref_zq
;
368 struct ap_message ap_msg
;
369 unsigned int weight
, pref_weight
;
370 unsigned int func_code
;
371 unsigned short *domain
;
372 int qid
= 0, rc
= -ENODEV
;
374 trace_s390_zcrypt_req(xcRB
, TB_ZSECSENDCPRB
);
376 rc
= get_cprb_fc(xcRB
, &ap_msg
, &func_code
, &domain
);
382 spin_lock(&zcrypt_list_lock
);
383 for_each_zcrypt_card(zc
) {
384 /* Check for online CCA cards */
385 if (!zc
->online
|| !(zc
->card
->functions
& 0x10000000))
387 /* Check for user selected CCA card */
388 if (xcRB
->user_defined
!= AUTOSELECT
&&
389 xcRB
->user_defined
!= zc
->card
->id
)
391 /* get weight index of the card device */
392 weight
= speed_idx_cca(func_code
) * zc
->speed_rating
[SECKEY
];
393 if (zcrypt_card_compare(zc
, pref_zc
, weight
, pref_weight
))
395 for_each_zcrypt_queue(zq
, zc
) {
396 /* check if device is online and eligible */
398 !zq
->ops
->send_cprb
||
399 ((*domain
!= (unsigned short) AUTOSELECT
) &&
400 (*domain
!= AP_QID_QUEUE(zq
->queue
->qid
))))
402 if (zcrypt_queue_compare(zq
, pref_zq
,
403 weight
, pref_weight
))
407 pref_weight
= weight
;
410 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, weight
);
411 spin_unlock(&zcrypt_list_lock
);
418 /* in case of auto select, provide the correct domain */
419 qid
= pref_zq
->queue
->qid
;
420 if (*domain
== (unsigned short) AUTOSELECT
)
421 *domain
= AP_QID_QUEUE(qid
);
423 rc
= pref_zq
->ops
->send_cprb(pref_zq
, xcRB
, &ap_msg
);
425 spin_lock(&zcrypt_list_lock
);
426 zcrypt_drop_queue(pref_zc
, pref_zq
, weight
);
427 spin_unlock(&zcrypt_list_lock
);
430 trace_s390_zcrypt_rep(xcRB
, func_code
, rc
,
431 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
434 EXPORT_SYMBOL(zcrypt_send_cprb
);
436 static bool is_desired_ep11_card(unsigned int dev_id
,
437 unsigned short target_num
,
438 struct ep11_target_dev
*targets
)
440 while (target_num
-- > 0) {
441 if (dev_id
== targets
->ap_id
)
448 static bool is_desired_ep11_queue(unsigned int dev_qid
,
449 unsigned short target_num
,
450 struct ep11_target_dev
*targets
)
452 while (target_num
-- > 0) {
453 if (AP_MKQID(targets
->ap_id
, targets
->dom_id
) == dev_qid
)
460 static long zcrypt_send_ep11_cprb(struct ep11_urb
*xcrb
)
462 struct zcrypt_card
*zc
, *pref_zc
;
463 struct zcrypt_queue
*zq
, *pref_zq
;
464 struct ep11_target_dev
*targets
;
465 unsigned short target_num
;
466 unsigned int weight
, pref_weight
;
467 unsigned int func_code
;
468 struct ap_message ap_msg
;
469 int qid
= 0, rc
= -ENODEV
;
471 trace_s390_zcrypt_req(xcrb
, TP_ZSENDEP11CPRB
);
473 target_num
= (unsigned short) xcrb
->targets_num
;
475 /* empty list indicates autoselect (all available targets) */
477 if (target_num
!= 0) {
478 struct ep11_target_dev __user
*uptr
;
480 targets
= kcalloc(target_num
, sizeof(*targets
), GFP_KERNEL
);
486 uptr
= (struct ep11_target_dev __force __user
*) xcrb
->targets
;
487 if (copy_from_user(targets
, uptr
,
488 target_num
* sizeof(*targets
))) {
494 rc
= get_ep11cprb_fc(xcrb
, &ap_msg
, &func_code
);
500 spin_lock(&zcrypt_list_lock
);
501 for_each_zcrypt_card(zc
) {
502 /* Check for online EP11 cards */
503 if (!zc
->online
|| !(zc
->card
->functions
& 0x04000000))
505 /* Check for user selected EP11 card */
507 !is_desired_ep11_card(zc
->card
->id
, target_num
, targets
))
509 /* get weight index of the card device */
510 weight
= speed_idx_ep11(func_code
) * zc
->speed_rating
[SECKEY
];
511 if (zcrypt_card_compare(zc
, pref_zc
, weight
, pref_weight
))
513 for_each_zcrypt_queue(zq
, zc
) {
514 /* check if device is online and eligible */
516 !zq
->ops
->send_ep11_cprb
||
518 !is_desired_ep11_queue(zq
->queue
->qid
,
519 target_num
, targets
)))
521 if (zcrypt_queue_compare(zq
, pref_zq
,
522 weight
, pref_weight
))
526 pref_weight
= weight
;
529 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, weight
);
530 spin_unlock(&zcrypt_list_lock
);
537 qid
= pref_zq
->queue
->qid
;
538 rc
= pref_zq
->ops
->send_ep11_cprb(pref_zq
, xcrb
, &ap_msg
);
540 spin_lock(&zcrypt_list_lock
);
541 zcrypt_drop_queue(pref_zc
, pref_zq
, weight
);
542 spin_unlock(&zcrypt_list_lock
);
547 trace_s390_zcrypt_rep(xcrb
, func_code
, rc
,
548 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
552 static long zcrypt_rng(char *buffer
)
554 struct zcrypt_card
*zc
, *pref_zc
;
555 struct zcrypt_queue
*zq
, *pref_zq
;
556 unsigned int weight
, pref_weight
;
557 unsigned int func_code
;
558 struct ap_message ap_msg
;
560 int qid
= 0, rc
= -ENODEV
;
562 trace_s390_zcrypt_req(buffer
, TP_HWRNGCPRB
);
564 rc
= get_rng_fc(&ap_msg
, &func_code
, &domain
);
570 spin_lock(&zcrypt_list_lock
);
571 for_each_zcrypt_card(zc
) {
572 /* Check for online CCA cards */
573 if (!zc
->online
|| !(zc
->card
->functions
& 0x10000000))
575 /* get weight index of the card device */
576 weight
= zc
->speed_rating
[func_code
];
577 if (zcrypt_card_compare(zc
, pref_zc
, weight
, pref_weight
))
579 for_each_zcrypt_queue(zq
, zc
) {
580 /* check if device is online and eligible */
581 if (!zq
->online
|| !zq
->ops
->rng
)
583 if (zcrypt_queue_compare(zq
, pref_zq
,
584 weight
, pref_weight
))
588 pref_weight
= weight
;
591 pref_zq
= zcrypt_pick_queue(pref_zc
, pref_zq
, weight
);
592 spin_unlock(&zcrypt_list_lock
);
597 qid
= pref_zq
->queue
->qid
;
598 rc
= pref_zq
->ops
->rng(pref_zq
, buffer
, &ap_msg
);
600 spin_lock(&zcrypt_list_lock
);
601 zcrypt_drop_queue(pref_zc
, pref_zq
, weight
);
602 spin_unlock(&zcrypt_list_lock
);
605 trace_s390_zcrypt_rep(buffer
, func_code
, rc
,
606 AP_QID_CARD(qid
), AP_QID_QUEUE(qid
));
610 void zcrypt_device_status_mask(struct zcrypt_device_matrix
*matrix
)
612 struct zcrypt_card
*zc
;
613 struct zcrypt_queue
*zq
;
614 struct zcrypt_device_status
*stat
;
616 memset(matrix
, 0, sizeof(*matrix
));
617 spin_lock(&zcrypt_list_lock
);
618 for_each_zcrypt_card(zc
) {
619 for_each_zcrypt_queue(zq
, zc
) {
620 stat
= matrix
->device
;
621 stat
+= AP_QID_CARD(zq
->queue
->qid
) * MAX_ZDEV_DOMAINS
;
622 stat
+= AP_QID_QUEUE(zq
->queue
->qid
);
623 stat
->hwtype
= zc
->card
->ap_dev
.device_type
;
624 stat
->functions
= zc
->card
->functions
>> 26;
625 stat
->qid
= zq
->queue
->qid
;
626 stat
->online
= zq
->online
? 0x01 : 0x00;
629 spin_unlock(&zcrypt_list_lock
);
631 EXPORT_SYMBOL(zcrypt_device_status_mask
);
633 static void zcrypt_status_mask(char status
[AP_DEVICES
])
635 struct zcrypt_card
*zc
;
636 struct zcrypt_queue
*zq
;
638 memset(status
, 0, sizeof(char) * AP_DEVICES
);
639 spin_lock(&zcrypt_list_lock
);
640 for_each_zcrypt_card(zc
) {
641 for_each_zcrypt_queue(zq
, zc
) {
642 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
644 status
[AP_QID_CARD(zq
->queue
->qid
)] =
645 zc
->online
? zc
->user_space_type
: 0x0d;
648 spin_unlock(&zcrypt_list_lock
);
651 static void zcrypt_qdepth_mask(char qdepth
[AP_DEVICES
])
653 struct zcrypt_card
*zc
;
654 struct zcrypt_queue
*zq
;
656 memset(qdepth
, 0, sizeof(char) * AP_DEVICES
);
657 spin_lock(&zcrypt_list_lock
);
659 for_each_zcrypt_card(zc
) {
660 for_each_zcrypt_queue(zq
, zc
) {
661 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
663 spin_lock(&zq
->queue
->lock
);
664 qdepth
[AP_QID_CARD(zq
->queue
->qid
)] =
665 zq
->queue
->pendingq_count
+
666 zq
->queue
->requestq_count
;
667 spin_unlock(&zq
->queue
->lock
);
671 spin_unlock(&zcrypt_list_lock
);
674 static void zcrypt_perdev_reqcnt(int reqcnt
[AP_DEVICES
])
676 struct zcrypt_card
*zc
;
677 struct zcrypt_queue
*zq
;
679 memset(reqcnt
, 0, sizeof(int) * AP_DEVICES
);
680 spin_lock(&zcrypt_list_lock
);
682 for_each_zcrypt_card(zc
) {
683 for_each_zcrypt_queue(zq
, zc
) {
684 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
686 spin_lock(&zq
->queue
->lock
);
687 reqcnt
[AP_QID_CARD(zq
->queue
->qid
)] =
688 zq
->queue
->total_request_count
;
689 spin_unlock(&zq
->queue
->lock
);
693 spin_unlock(&zcrypt_list_lock
);
696 static int zcrypt_pendingq_count(void)
698 struct zcrypt_card
*zc
;
699 struct zcrypt_queue
*zq
;
703 spin_lock(&zcrypt_list_lock
);
705 for_each_zcrypt_card(zc
) {
706 for_each_zcrypt_queue(zq
, zc
) {
707 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
709 spin_lock(&zq
->queue
->lock
);
710 pendingq_count
+= zq
->queue
->pendingq_count
;
711 spin_unlock(&zq
->queue
->lock
);
715 spin_unlock(&zcrypt_list_lock
);
716 return pendingq_count
;
719 static int zcrypt_requestq_count(void)
721 struct zcrypt_card
*zc
;
722 struct zcrypt_queue
*zq
;
726 spin_lock(&zcrypt_list_lock
);
728 for_each_zcrypt_card(zc
) {
729 for_each_zcrypt_queue(zq
, zc
) {
730 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
732 spin_lock(&zq
->queue
->lock
);
733 requestq_count
+= zq
->queue
->requestq_count
;
734 spin_unlock(&zq
->queue
->lock
);
738 spin_unlock(&zcrypt_list_lock
);
739 return requestq_count
;
742 static int zcrypt_count_type(int type
)
744 struct zcrypt_card
*zc
;
745 struct zcrypt_queue
*zq
;
749 spin_lock(&zcrypt_list_lock
);
750 for_each_zcrypt_card(zc
) {
751 if (zc
->card
->id
!= type
)
753 for_each_zcrypt_queue(zq
, zc
) {
754 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
759 spin_unlock(&zcrypt_list_lock
);
764 * zcrypt_ica_status(): Old, depracted combi status call.
766 * Old, deprecated combi status call.
768 static long zcrypt_ica_status(struct file
*filp
, unsigned long arg
)
770 struct ica_z90_status
*pstat
;
773 pstat
= kzalloc(sizeof(*pstat
), GFP_KERNEL
);
776 pstat
->totalcount
= zcrypt_device_count
;
777 pstat
->leedslitecount
= zcrypt_count_type(ZCRYPT_PCICA
);
778 pstat
->leeds2count
= zcrypt_count_type(ZCRYPT_PCICC
);
779 pstat
->requestqWaitCount
= zcrypt_requestq_count();
780 pstat
->pendingqWaitCount
= zcrypt_pendingq_count();
781 pstat
->totalOpenCount
= atomic_read(&zcrypt_open_count
);
782 pstat
->cryptoDomain
= ap_domain_index
;
783 zcrypt_status_mask(pstat
->status
);
784 zcrypt_qdepth_mask(pstat
->qdepth
);
786 if (copy_to_user((void __user
*) arg
, pstat
, sizeof(*pstat
)))
792 static long zcrypt_unlocked_ioctl(struct file
*filp
, unsigned int cmd
,
798 case ICARSAMODEXPO
: {
799 struct ica_rsa_modexpo __user
*umex
= (void __user
*) arg
;
800 struct ica_rsa_modexpo mex
;
801 if (copy_from_user(&mex
, umex
, sizeof(mex
)))
804 rc
= zcrypt_rsa_modexpo(&mex
);
805 } while (rc
== -EAGAIN
);
806 /* on failure: retry once again after a requested rescan */
807 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
809 rc
= zcrypt_rsa_modexpo(&mex
);
810 } while (rc
== -EAGAIN
);
812 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ICARSAMODEXPO rc=%d\n", rc
);
815 return put_user(mex
.outputdatalength
, &umex
->outputdatalength
);
818 struct ica_rsa_modexpo_crt __user
*ucrt
= (void __user
*) arg
;
819 struct ica_rsa_modexpo_crt crt
;
820 if (copy_from_user(&crt
, ucrt
, sizeof(crt
)))
823 rc
= zcrypt_rsa_crt(&crt
);
824 } while (rc
== -EAGAIN
);
825 /* on failure: retry once again after a requested rescan */
826 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
828 rc
= zcrypt_rsa_crt(&crt
);
829 } while (rc
== -EAGAIN
);
831 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ICARSACRT rc=%d\n", rc
);
834 return put_user(crt
.outputdatalength
, &ucrt
->outputdatalength
);
837 struct ica_xcRB __user
*uxcRB
= (void __user
*) arg
;
838 struct ica_xcRB xcRB
;
839 if (copy_from_user(&xcRB
, uxcRB
, sizeof(xcRB
)))
842 rc
= zcrypt_send_cprb(&xcRB
);
843 } while (rc
== -EAGAIN
);
844 /* on failure: retry once again after a requested rescan */
845 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
847 rc
= zcrypt_send_cprb(&xcRB
);
848 } while (rc
== -EAGAIN
);
850 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ZSENDCPRB rc=%d\n", rc
);
851 if (copy_to_user(uxcRB
, &xcRB
, sizeof(xcRB
)))
855 case ZSENDEP11CPRB
: {
856 struct ep11_urb __user
*uxcrb
= (void __user
*)arg
;
857 struct ep11_urb xcrb
;
858 if (copy_from_user(&xcrb
, uxcrb
, sizeof(xcrb
)))
861 rc
= zcrypt_send_ep11_cprb(&xcrb
);
862 } while (rc
== -EAGAIN
);
863 /* on failure: retry once again after a requested rescan */
864 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
866 rc
= zcrypt_send_ep11_cprb(&xcrb
);
867 } while (rc
== -EAGAIN
);
869 ZCRYPT_DBF(DBF_DEBUG
, "ioctl ZSENDEP11CPRB rc=%d\n", rc
);
870 if (copy_to_user(uxcrb
, &xcrb
, sizeof(xcrb
)))
874 case ZDEVICESTATUS
: {
875 struct zcrypt_device_matrix
*device_status
;
877 device_status
= kzalloc(sizeof(struct zcrypt_device_matrix
),
882 zcrypt_device_status_mask(device_status
);
884 if (copy_to_user((char __user
*) arg
, device_status
,
885 sizeof(struct zcrypt_device_matrix
))) {
886 kfree(device_status
);
890 kfree(device_status
);
893 case Z90STAT_STATUS_MASK
: {
894 char status
[AP_DEVICES
];
895 zcrypt_status_mask(status
);
896 if (copy_to_user((char __user
*) arg
, status
,
897 sizeof(char) * AP_DEVICES
))
901 case Z90STAT_QDEPTH_MASK
: {
902 char qdepth
[AP_DEVICES
];
903 zcrypt_qdepth_mask(qdepth
);
904 if (copy_to_user((char __user
*) arg
, qdepth
,
905 sizeof(char) * AP_DEVICES
))
909 case Z90STAT_PERDEV_REQCNT
: {
910 int reqcnt
[AP_DEVICES
];
911 zcrypt_perdev_reqcnt(reqcnt
);
912 if (copy_to_user((int __user
*) arg
, reqcnt
,
913 sizeof(int) * AP_DEVICES
))
917 case Z90STAT_REQUESTQ_COUNT
:
918 return put_user(zcrypt_requestq_count(), (int __user
*) arg
);
919 case Z90STAT_PENDINGQ_COUNT
:
920 return put_user(zcrypt_pendingq_count(), (int __user
*) arg
);
921 case Z90STAT_TOTALOPEN_COUNT
:
922 return put_user(atomic_read(&zcrypt_open_count
),
924 case Z90STAT_DOMAIN_INDEX
:
925 return put_user(ap_domain_index
, (int __user
*) arg
);
927 * Deprecated ioctls. Don't add another device count ioctl,
928 * you can count them yourself in the user space with the
929 * output of the Z90STAT_STATUS_MASK ioctl.
932 return zcrypt_ica_status(filp
, arg
);
933 case Z90STAT_TOTALCOUNT
:
934 return put_user(zcrypt_device_count
, (int __user
*) arg
);
935 case Z90STAT_PCICACOUNT
:
936 return put_user(zcrypt_count_type(ZCRYPT_PCICA
),
938 case Z90STAT_PCICCCOUNT
:
939 return put_user(zcrypt_count_type(ZCRYPT_PCICC
),
941 case Z90STAT_PCIXCCMCL2COUNT
:
942 return put_user(zcrypt_count_type(ZCRYPT_PCIXCC_MCL2
),
944 case Z90STAT_PCIXCCMCL3COUNT
:
945 return put_user(zcrypt_count_type(ZCRYPT_PCIXCC_MCL3
),
947 case Z90STAT_PCIXCCCOUNT
:
948 return put_user(zcrypt_count_type(ZCRYPT_PCIXCC_MCL2
) +
949 zcrypt_count_type(ZCRYPT_PCIXCC_MCL3
),
951 case Z90STAT_CEX2CCOUNT
:
952 return put_user(zcrypt_count_type(ZCRYPT_CEX2C
),
954 case Z90STAT_CEX2ACOUNT
:
955 return put_user(zcrypt_count_type(ZCRYPT_CEX2A
),
958 /* unknown ioctl number */
965 * ioctl32 conversion routines
967 struct compat_ica_rsa_modexpo
{
968 compat_uptr_t inputdata
;
969 unsigned int inputdatalength
;
970 compat_uptr_t outputdata
;
971 unsigned int outputdatalength
;
973 compat_uptr_t n_modulus
;
976 static long trans_modexpo32(struct file
*filp
, unsigned int cmd
,
979 struct compat_ica_rsa_modexpo __user
*umex32
= compat_ptr(arg
);
980 struct compat_ica_rsa_modexpo mex32
;
981 struct ica_rsa_modexpo mex64
;
984 if (copy_from_user(&mex32
, umex32
, sizeof(mex32
)))
986 mex64
.inputdata
= compat_ptr(mex32
.inputdata
);
987 mex64
.inputdatalength
= mex32
.inputdatalength
;
988 mex64
.outputdata
= compat_ptr(mex32
.outputdata
);
989 mex64
.outputdatalength
= mex32
.outputdatalength
;
990 mex64
.b_key
= compat_ptr(mex32
.b_key
);
991 mex64
.n_modulus
= compat_ptr(mex32
.n_modulus
);
993 rc
= zcrypt_rsa_modexpo(&mex64
);
994 } while (rc
== -EAGAIN
);
995 /* on failure: retry once again after a requested rescan */
996 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
998 rc
= zcrypt_rsa_modexpo(&mex64
);
999 } while (rc
== -EAGAIN
);
1002 return put_user(mex64
.outputdatalength
,
1003 &umex32
->outputdatalength
);
1006 struct compat_ica_rsa_modexpo_crt
{
1007 compat_uptr_t inputdata
;
1008 unsigned int inputdatalength
;
1009 compat_uptr_t outputdata
;
1010 unsigned int outputdatalength
;
1011 compat_uptr_t bp_key
;
1012 compat_uptr_t bq_key
;
1013 compat_uptr_t np_prime
;
1014 compat_uptr_t nq_prime
;
1015 compat_uptr_t u_mult_inv
;
1018 static long trans_modexpo_crt32(struct file
*filp
, unsigned int cmd
,
1021 struct compat_ica_rsa_modexpo_crt __user
*ucrt32
= compat_ptr(arg
);
1022 struct compat_ica_rsa_modexpo_crt crt32
;
1023 struct ica_rsa_modexpo_crt crt64
;
1026 if (copy_from_user(&crt32
, ucrt32
, sizeof(crt32
)))
1028 crt64
.inputdata
= compat_ptr(crt32
.inputdata
);
1029 crt64
.inputdatalength
= crt32
.inputdatalength
;
1030 crt64
.outputdata
= compat_ptr(crt32
.outputdata
);
1031 crt64
.outputdatalength
= crt32
.outputdatalength
;
1032 crt64
.bp_key
= compat_ptr(crt32
.bp_key
);
1033 crt64
.bq_key
= compat_ptr(crt32
.bq_key
);
1034 crt64
.np_prime
= compat_ptr(crt32
.np_prime
);
1035 crt64
.nq_prime
= compat_ptr(crt32
.nq_prime
);
1036 crt64
.u_mult_inv
= compat_ptr(crt32
.u_mult_inv
);
1038 rc
= zcrypt_rsa_crt(&crt64
);
1039 } while (rc
== -EAGAIN
);
1040 /* on failure: retry once again after a requested rescan */
1041 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1043 rc
= zcrypt_rsa_crt(&crt64
);
1044 } while (rc
== -EAGAIN
);
1047 return put_user(crt64
.outputdatalength
,
1048 &ucrt32
->outputdatalength
);
1051 struct compat_ica_xcRB
{
1052 unsigned short agent_ID
;
1053 unsigned int user_defined
;
1054 unsigned short request_ID
;
1055 unsigned int request_control_blk_length
;
1056 unsigned char padding1
[16 - sizeof (compat_uptr_t
)];
1057 compat_uptr_t request_control_blk_addr
;
1058 unsigned int request_data_length
;
1059 char padding2
[16 - sizeof (compat_uptr_t
)];
1060 compat_uptr_t request_data_address
;
1061 unsigned int reply_control_blk_length
;
1062 char padding3
[16 - sizeof (compat_uptr_t
)];
1063 compat_uptr_t reply_control_blk_addr
;
1064 unsigned int reply_data_length
;
1065 char padding4
[16 - sizeof (compat_uptr_t
)];
1066 compat_uptr_t reply_data_addr
;
1067 unsigned short priority_window
;
1068 unsigned int status
;
1069 } __attribute__((packed
));
1071 static long trans_xcRB32(struct file
*filp
, unsigned int cmd
,
1074 struct compat_ica_xcRB __user
*uxcRB32
= compat_ptr(arg
);
1075 struct compat_ica_xcRB xcRB32
;
1076 struct ica_xcRB xcRB64
;
1079 if (copy_from_user(&xcRB32
, uxcRB32
, sizeof(xcRB32
)))
1081 xcRB64
.agent_ID
= xcRB32
.agent_ID
;
1082 xcRB64
.user_defined
= xcRB32
.user_defined
;
1083 xcRB64
.request_ID
= xcRB32
.request_ID
;
1084 xcRB64
.request_control_blk_length
=
1085 xcRB32
.request_control_blk_length
;
1086 xcRB64
.request_control_blk_addr
=
1087 compat_ptr(xcRB32
.request_control_blk_addr
);
1088 xcRB64
.request_data_length
=
1089 xcRB32
.request_data_length
;
1090 xcRB64
.request_data_address
=
1091 compat_ptr(xcRB32
.request_data_address
);
1092 xcRB64
.reply_control_blk_length
=
1093 xcRB32
.reply_control_blk_length
;
1094 xcRB64
.reply_control_blk_addr
=
1095 compat_ptr(xcRB32
.reply_control_blk_addr
);
1096 xcRB64
.reply_data_length
= xcRB32
.reply_data_length
;
1097 xcRB64
.reply_data_addr
=
1098 compat_ptr(xcRB32
.reply_data_addr
);
1099 xcRB64
.priority_window
= xcRB32
.priority_window
;
1100 xcRB64
.status
= xcRB32
.status
;
1102 rc
= zcrypt_send_cprb(&xcRB64
);
1103 } while (rc
== -EAGAIN
);
1104 /* on failure: retry once again after a requested rescan */
1105 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1107 rc
= zcrypt_send_cprb(&xcRB64
);
1108 } while (rc
== -EAGAIN
);
1109 xcRB32
.reply_control_blk_length
= xcRB64
.reply_control_blk_length
;
1110 xcRB32
.reply_data_length
= xcRB64
.reply_data_length
;
1111 xcRB32
.status
= xcRB64
.status
;
1112 if (copy_to_user(uxcRB32
, &xcRB32
, sizeof(xcRB32
)))
1117 static long zcrypt_compat_ioctl(struct file
*filp
, unsigned int cmd
,
1120 if (cmd
== ICARSAMODEXPO
)
1121 return trans_modexpo32(filp
, cmd
, arg
);
1122 if (cmd
== ICARSACRT
)
1123 return trans_modexpo_crt32(filp
, cmd
, arg
);
1124 if (cmd
== ZSECSENDCPRB
)
1125 return trans_xcRB32(filp
, cmd
, arg
);
1126 return zcrypt_unlocked_ioctl(filp
, cmd
, arg
);
1131 * Misc device file operations.
1133 static const struct file_operations zcrypt_fops
= {
1134 .owner
= THIS_MODULE
,
1135 .read
= zcrypt_read
,
1136 .write
= zcrypt_write
,
1137 .unlocked_ioctl
= zcrypt_unlocked_ioctl
,
1138 #ifdef CONFIG_COMPAT
1139 .compat_ioctl
= zcrypt_compat_ioctl
,
1141 .open
= zcrypt_open
,
1142 .release
= zcrypt_release
,
1143 .llseek
= no_llseek
,
1149 static struct miscdevice zcrypt_misc_device
= {
1150 .minor
= MISC_DYNAMIC_MINOR
,
1152 .fops
= &zcrypt_fops
,
1156 * Deprecated /proc entry support.
1158 static struct proc_dir_entry
*zcrypt_entry
;
1160 static void sprintcl(struct seq_file
*m
, unsigned char *addr
, unsigned int len
)
1164 for (i
= 0; i
< len
; i
++)
1165 seq_printf(m
, "%01x", (unsigned int) addr
[i
]);
1169 static void sprintrw(struct seq_file
*m
, unsigned char *addr
, unsigned int len
)
1175 for (c
= 0; c
< (len
/ 16); c
++) {
1176 sprintcl(m
, addr
+inl
, 16);
1181 sprintcl(m
, addr
+inl
, cx
);
1187 static void sprinthx(unsigned char *title
, struct seq_file
*m
,
1188 unsigned char *addr
, unsigned int len
)
1192 seq_printf(m
, "\n%s\n", title
);
1194 for (r
= 0; r
< (len
/ 64); r
++) {
1195 sprintrw(m
, addr
+inl
, 64);
1200 sprintrw(m
, addr
+inl
, rx
);
1206 static void sprinthx4(unsigned char *title
, struct seq_file
*m
,
1207 unsigned int *array
, unsigned int len
)
1209 seq_printf(m
, "\n%s\n", title
);
1210 seq_hex_dump(m
, " ", DUMP_PREFIX_NONE
, 32, 4, array
, len
, false);
1214 static int zcrypt_proc_show(struct seq_file
*m
, void *v
)
1216 char workarea
[sizeof(int) * AP_DEVICES
];
1218 seq_printf(m
, "\nzcrypt version: %d.%d.%d\n",
1219 ZCRYPT_VERSION
, ZCRYPT_RELEASE
, ZCRYPT_VARIANT
);
1220 seq_printf(m
, "Cryptographic domain: %d\n", ap_domain_index
);
1221 seq_printf(m
, "Total device count: %d\n", zcrypt_device_count
);
1222 seq_printf(m
, "PCICA count: %d\n", zcrypt_count_type(ZCRYPT_PCICA
));
1223 seq_printf(m
, "PCICC count: %d\n", zcrypt_count_type(ZCRYPT_PCICC
));
1224 seq_printf(m
, "PCIXCC MCL2 count: %d\n",
1225 zcrypt_count_type(ZCRYPT_PCIXCC_MCL2
));
1226 seq_printf(m
, "PCIXCC MCL3 count: %d\n",
1227 zcrypt_count_type(ZCRYPT_PCIXCC_MCL3
));
1228 seq_printf(m
, "CEX2C count: %d\n", zcrypt_count_type(ZCRYPT_CEX2C
));
1229 seq_printf(m
, "CEX2A count: %d\n", zcrypt_count_type(ZCRYPT_CEX2A
));
1230 seq_printf(m
, "CEX3C count: %d\n", zcrypt_count_type(ZCRYPT_CEX3C
));
1231 seq_printf(m
, "CEX3A count: %d\n", zcrypt_count_type(ZCRYPT_CEX3A
));
1232 seq_printf(m
, "requestq count: %d\n", zcrypt_requestq_count());
1233 seq_printf(m
, "pendingq count: %d\n", zcrypt_pendingq_count());
1234 seq_printf(m
, "Total open handles: %d\n\n",
1235 atomic_read(&zcrypt_open_count
));
1236 zcrypt_status_mask(workarea
);
1237 sprinthx("Online devices: 1=PCICA 2=PCICC 3=PCIXCC(MCL2) "
1238 "4=PCIXCC(MCL3) 5=CEX2C 6=CEX2A 7=CEX3C 8=CEX3A",
1239 m
, workarea
, AP_DEVICES
);
1240 zcrypt_qdepth_mask(workarea
);
1241 sprinthx("Waiting work element counts", m
, workarea
, AP_DEVICES
);
1242 zcrypt_perdev_reqcnt((int *) workarea
);
1243 sprinthx4("Per-device successfully completed request counts",
1244 m
, (unsigned int *) workarea
, AP_DEVICES
);
1248 static int zcrypt_proc_open(struct inode
*inode
, struct file
*file
)
1250 return single_open(file
, zcrypt_proc_show
, NULL
);
1253 static void zcrypt_disable_card(int index
)
1255 struct zcrypt_card
*zc
;
1256 struct zcrypt_queue
*zq
;
1258 spin_lock(&zcrypt_list_lock
);
1259 for_each_zcrypt_card(zc
) {
1260 for_each_zcrypt_queue(zq
, zc
) {
1261 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
1264 ap_flush_queue(zq
->queue
);
1267 spin_unlock(&zcrypt_list_lock
);
1270 static void zcrypt_enable_card(int index
)
1272 struct zcrypt_card
*zc
;
1273 struct zcrypt_queue
*zq
;
1275 spin_lock(&zcrypt_list_lock
);
1276 for_each_zcrypt_card(zc
) {
1277 for_each_zcrypt_queue(zq
, zc
) {
1278 if (AP_QID_QUEUE(zq
->queue
->qid
) != ap_domain_index
)
1281 ap_flush_queue(zq
->queue
);
1284 spin_unlock(&zcrypt_list_lock
);
1287 static ssize_t
zcrypt_proc_write(struct file
*file
, const char __user
*buffer
,
1288 size_t count
, loff_t
*pos
)
1290 unsigned char *lbuf
, *ptr
;
1297 #define LBUFSIZE 1200UL
1298 lbuf
= kmalloc(LBUFSIZE
, GFP_KERNEL
);
1302 local_count
= min(LBUFSIZE
- 1, count
);
1303 if (copy_from_user(lbuf
, buffer
, local_count
) != 0) {
1307 lbuf
[local_count
] = '\0';
1309 ptr
= strstr(lbuf
, "Online devices");
1312 ptr
= strstr(ptr
, "\n");
1317 if (strstr(ptr
, "Waiting work element counts") == NULL
)
1320 for (j
= 0; j
< 64 && *ptr
; ptr
++) {
1322 * '0' for no device, '1' for PCICA, '2' for PCICC,
1323 * '3' for PCIXCC_MCL2, '4' for PCIXCC_MCL3,
1324 * '5' for CEX2C and '6' for CEX2A'
1325 * '7' for CEX3C and '8' for CEX3A
1327 if (*ptr
>= '0' && *ptr
<= '8')
1329 else if (*ptr
== 'd' || *ptr
== 'D')
1330 zcrypt_disable_card(j
++);
1331 else if (*ptr
== 'e' || *ptr
== 'E')
1332 zcrypt_enable_card(j
++);
1333 else if (*ptr
!= ' ' && *ptr
!= '\t')
1341 static const struct file_operations zcrypt_proc_fops
= {
1342 .owner
= THIS_MODULE
,
1343 .open
= zcrypt_proc_open
,
1345 .llseek
= seq_lseek
,
1346 .release
= single_release
,
1347 .write
= zcrypt_proc_write
,
1350 static int zcrypt_rng_device_count
;
1351 static u32
*zcrypt_rng_buffer
;
1352 static int zcrypt_rng_buffer_index
;
1353 static DEFINE_MUTEX(zcrypt_rng_mutex
);
1355 static int zcrypt_rng_data_read(struct hwrng
*rng
, u32
*data
)
1360 * We don't need locking here because the RNG API guarantees serialized
1361 * read method calls.
1363 if (zcrypt_rng_buffer_index
== 0) {
1364 rc
= zcrypt_rng((char *) zcrypt_rng_buffer
);
1365 /* on failure: retry once again after a requested rescan */
1366 if ((rc
== -ENODEV
) && (zcrypt_process_rescan()))
1367 rc
= zcrypt_rng((char *) zcrypt_rng_buffer
);
1370 zcrypt_rng_buffer_index
= rc
/ sizeof *data
;
1372 *data
= zcrypt_rng_buffer
[--zcrypt_rng_buffer_index
];
1373 return sizeof *data
;
1376 static struct hwrng zcrypt_rng_dev
= {
1378 .data_read
= zcrypt_rng_data_read
,
1382 int zcrypt_rng_device_add(void)
1386 mutex_lock(&zcrypt_rng_mutex
);
1387 if (zcrypt_rng_device_count
== 0) {
1388 zcrypt_rng_buffer
= (u32
*) get_zeroed_page(GFP_KERNEL
);
1389 if (!zcrypt_rng_buffer
) {
1393 zcrypt_rng_buffer_index
= 0;
1394 if (!zcrypt_hwrng_seed
)
1395 zcrypt_rng_dev
.quality
= 0;
1396 rc
= hwrng_register(&zcrypt_rng_dev
);
1399 zcrypt_rng_device_count
= 1;
1401 zcrypt_rng_device_count
++;
1402 mutex_unlock(&zcrypt_rng_mutex
);
1406 free_page((unsigned long) zcrypt_rng_buffer
);
1408 mutex_unlock(&zcrypt_rng_mutex
);
1412 void zcrypt_rng_device_remove(void)
1414 mutex_lock(&zcrypt_rng_mutex
);
1415 zcrypt_rng_device_count
--;
1416 if (zcrypt_rng_device_count
== 0) {
1417 hwrng_unregister(&zcrypt_rng_dev
);
1418 free_page((unsigned long) zcrypt_rng_buffer
);
1420 mutex_unlock(&zcrypt_rng_mutex
);
1423 int __init
zcrypt_debug_init(void)
1425 zcrypt_dbf_info
= debug_register("zcrypt", 1, 1,
1426 DBF_MAX_SPRINTF_ARGS
* sizeof(long));
1427 debug_register_view(zcrypt_dbf_info
, &debug_sprintf_view
);
1428 debug_set_level(zcrypt_dbf_info
, DBF_ERR
);
1433 void zcrypt_debug_exit(void)
1435 debug_unregister(zcrypt_dbf_info
);
1439 * zcrypt_api_init(): Module initialization.
1441 * The module initialization code.
1443 int __init
zcrypt_api_init(void)
1447 rc
= zcrypt_debug_init();
1451 atomic_set(&zcrypt_rescan_req
, 0);
1453 /* Register the request sprayer. */
1454 rc
= misc_register(&zcrypt_misc_device
);
1458 /* Set up the proc file system */
1459 zcrypt_entry
= proc_create("driver/z90crypt", 0644, NULL
,
1461 if (!zcrypt_entry
) {
1466 zcrypt_msgtype6_init();
1467 zcrypt_msgtype50_init();
1471 misc_deregister(&zcrypt_misc_device
);
1477 * zcrypt_api_exit(): Module termination.
1479 * The module termination code.
1481 void __exit
zcrypt_api_exit(void)
1483 remove_proc_entry("driver/z90crypt", NULL
);
1484 misc_deregister(&zcrypt_misc_device
);
1485 zcrypt_msgtype6_exit();
1486 zcrypt_msgtype50_exit();
1487 zcrypt_debug_exit();
1490 module_init(zcrypt_api_init
);
1491 module_exit(zcrypt_api_exit
);