1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2012, 2019
4 * Author(s): Holger Dengler <hd@linux.vnet.ibm.com>
7 #include <linux/module.h>
8 #include <linux/slab.h>
9 #include <linux/init.h>
10 #include <linux/err.h>
11 #include <linux/atomic.h>
12 #include <linux/uaccess.h>
13 #include <linux/mod_devicetable.h>
16 #include "zcrypt_api.h"
17 #include "zcrypt_msgtype6.h"
18 #include "zcrypt_msgtype50.h"
19 #include "zcrypt_error.h"
20 #include "zcrypt_cex4.h"
21 #include "zcrypt_ccamisc.h"
22 #include "zcrypt_ep11misc.h"
24 #define CEX4A_MIN_MOD_SIZE 1 /* 8 bits */
25 #define CEX4A_MAX_MOD_SIZE_2K 256 /* 2048 bits */
26 #define CEX4A_MAX_MOD_SIZE_4K 512 /* 4096 bits */
28 #define CEX4C_MIN_MOD_SIZE 16 /* 256 bits */
29 #define CEX4C_MAX_MOD_SIZE 512 /* 4096 bits */
31 #define CEX4A_MAX_MESSAGE_SIZE MSGTYPE50_CRB3_MAX_MSG_SIZE
32 #define CEX4C_MAX_MESSAGE_SIZE MSGTYPE06_MAX_MSG_SIZE
34 /* Waiting time for requests to be processed.
35 * Currently there are some types of request which are not deterministic.
36 * But the maximum time limit managed by the stomper code is set to 60sec.
37 * Hence we have to wait at least that time period.
39 #define CEX4_CLEANUP_TIME (900*HZ)
41 MODULE_AUTHOR("IBM Corporation");
42 MODULE_DESCRIPTION("CEX4/CEX5/CEX6/CEX7 Cryptographic Card device driver, " \
43 "Copyright IBM Corp. 2019");
44 MODULE_LICENSE("GPL");
46 static struct ap_device_id zcrypt_cex4_card_ids[] = {
47 { .dev_type = AP_DEVICE_TYPE_CEX4,
48 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
49 { .dev_type = AP_DEVICE_TYPE_CEX5,
50 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
51 { .dev_type = AP_DEVICE_TYPE_CEX6,
52 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
53 { .dev_type = AP_DEVICE_TYPE_CEX7,
54 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
55 { /* end of list */ },
58 MODULE_DEVICE_TABLE(ap, zcrypt_cex4_card_ids);
60 static struct ap_device_id zcrypt_cex4_queue_ids[] = {
61 { .dev_type = AP_DEVICE_TYPE_CEX4,
62 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
63 { .dev_type = AP_DEVICE_TYPE_CEX5,
64 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
65 { .dev_type = AP_DEVICE_TYPE_CEX6,
66 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
67 { .dev_type = AP_DEVICE_TYPE_CEX7,
68 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
69 { /* end of list */ },
72 MODULE_DEVICE_TABLE(ap, zcrypt_cex4_queue_ids);
75 * CCA card additional device attributes
77 static ssize_t cca_serialnr_show(struct device *dev,
78 struct device_attribute *attr,
82 struct ap_card *ac = to_ap_card(dev);
83 struct zcrypt_card *zc = ac->private;
85 memset(&ci, 0, sizeof(ci));
87 if (ap_domain_index >= 0)
88 cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
90 return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial);
93 static struct device_attribute dev_attr_cca_serialnr =
94 __ATTR(serialnr, 0444, cca_serialnr_show, NULL);
96 static struct attribute *cca_card_attrs[] = {
97 &dev_attr_cca_serialnr.attr,
101 static const struct attribute_group cca_card_attr_grp = {
102 .attrs = cca_card_attrs,
106 * CCA queue additional device attributes
108 static ssize_t cca_mkvps_show(struct device *dev,
109 struct device_attribute *attr,
114 struct zcrypt_queue *zq = to_ap_queue(dev)->private;
115 static const char * const cao_state[] = { "invalid", "valid" };
116 static const char * const new_state[] = { "empty", "partial", "full" };
118 memset(&ci, 0, sizeof(ci));
120 cca_get_info(AP_QID_CARD(zq->queue->qid),
121 AP_QID_QUEUE(zq->queue->qid),
124 if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3')
125 n = scnprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n",
126 new_state[ci.new_aes_mk_state - '1'],
129 n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n");
131 if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2')
132 n += scnprintf(buf + n, PAGE_SIZE - n,
133 "AES CUR: %s 0x%016llx\n",
134 cao_state[ci.cur_aes_mk_state - '1'],
137 n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n");
139 if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2')
140 n += scnprintf(buf + n, PAGE_SIZE - n,
141 "AES OLD: %s 0x%016llx\n",
142 cao_state[ci.old_aes_mk_state - '1'],
145 n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n");
147 if (ci.new_apka_mk_state >= '1' && ci.new_apka_mk_state <= '3')
148 n += scnprintf(buf + n, PAGE_SIZE - n,
149 "APKA NEW: %s 0x%016llx\n",
150 new_state[ci.new_apka_mk_state - '1'],
153 n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n");
155 if (ci.cur_apka_mk_state >= '1' && ci.cur_apka_mk_state <= '2')
156 n += scnprintf(buf + n, PAGE_SIZE - n,
157 "APKA CUR: %s 0x%016llx\n",
158 cao_state[ci.cur_apka_mk_state - '1'],
161 n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n");
163 if (ci.old_apka_mk_state >= '1' && ci.old_apka_mk_state <= '2')
164 n += scnprintf(buf + n, PAGE_SIZE - n,
165 "APKA OLD: %s 0x%016llx\n",
166 cao_state[ci.old_apka_mk_state - '1'],
169 n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n");
174 static struct device_attribute dev_attr_cca_mkvps =
175 __ATTR(mkvps, 0444, cca_mkvps_show, NULL);
177 static struct attribute *cca_queue_attrs[] = {
178 &dev_attr_cca_mkvps.attr,
182 static const struct attribute_group cca_queue_attr_grp = {
183 .attrs = cca_queue_attrs,
187 * EP11 card additional device attributes
189 static ssize_t ep11_api_ordinalnr_show(struct device *dev,
190 struct device_attribute *attr,
193 struct ep11_card_info ci;
194 struct ap_card *ac = to_ap_card(dev);
195 struct zcrypt_card *zc = ac->private;
197 memset(&ci, 0, sizeof(ci));
199 ep11_get_card_info(ac->id, &ci, zc->online);
201 if (ci.API_ord_nr > 0)
202 return scnprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr);
204 return scnprintf(buf, PAGE_SIZE, "\n");
207 static struct device_attribute dev_attr_ep11_api_ordinalnr =
208 __ATTR(API_ordinalnr, 0444, ep11_api_ordinalnr_show, NULL);
210 static ssize_t ep11_fw_version_show(struct device *dev,
211 struct device_attribute *attr,
214 struct ep11_card_info ci;
215 struct ap_card *ac = to_ap_card(dev);
216 struct zcrypt_card *zc = ac->private;
218 memset(&ci, 0, sizeof(ci));
220 ep11_get_card_info(ac->id, &ci, zc->online);
222 if (ci.FW_version > 0)
223 return scnprintf(buf, PAGE_SIZE, "%d.%d\n",
224 (int)(ci.FW_version >> 8),
225 (int)(ci.FW_version & 0xFF));
227 return scnprintf(buf, PAGE_SIZE, "\n");
230 static struct device_attribute dev_attr_ep11_fw_version =
231 __ATTR(FW_version, 0444, ep11_fw_version_show, NULL);
233 static ssize_t ep11_serialnr_show(struct device *dev,
234 struct device_attribute *attr,
237 struct ep11_card_info ci;
238 struct ap_card *ac = to_ap_card(dev);
239 struct zcrypt_card *zc = ac->private;
241 memset(&ci, 0, sizeof(ci));
243 ep11_get_card_info(ac->id, &ci, zc->online);
246 return scnprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial);
248 return scnprintf(buf, PAGE_SIZE, "\n");
251 static struct device_attribute dev_attr_ep11_serialnr =
252 __ATTR(serialnr, 0444, ep11_serialnr_show, NULL);
254 static const struct {
256 const char *mode_txt;
257 } ep11_op_modes[] = {
266 static ssize_t ep11_card_op_modes_show(struct device *dev,
267 struct device_attribute *attr,
271 struct ep11_card_info ci;
272 struct ap_card *ac = to_ap_card(dev);
273 struct zcrypt_card *zc = ac->private;
275 memset(&ci, 0, sizeof(ci));
277 ep11_get_card_info(ac->id, &ci, zc->online);
279 for (i = 0; ep11_op_modes[i].mode_txt; i++) {
280 if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
283 n += scnprintf(buf + n, PAGE_SIZE - n,
284 "%s", ep11_op_modes[i].mode_txt);
287 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
292 static struct device_attribute dev_attr_ep11_card_op_modes =
293 __ATTR(op_modes, 0444, ep11_card_op_modes_show, NULL);
295 static struct attribute *ep11_card_attrs[] = {
296 &dev_attr_ep11_api_ordinalnr.attr,
297 &dev_attr_ep11_fw_version.attr,
298 &dev_attr_ep11_serialnr.attr,
299 &dev_attr_ep11_card_op_modes.attr,
303 static const struct attribute_group ep11_card_attr_grp = {
304 .attrs = ep11_card_attrs,
308 * EP11 queue additional device attributes
311 static ssize_t ep11_mkvps_show(struct device *dev,
312 struct device_attribute *attr,
316 struct ep11_domain_info di;
317 struct zcrypt_queue *zq = to_ap_queue(dev)->private;
318 static const char * const cwk_state[] = { "invalid", "valid" };
319 static const char * const nwk_state[] = { "empty", "uncommitted",
322 memset(&di, 0, sizeof(di));
325 ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
326 AP_QID_QUEUE(zq->queue->qid),
329 if (di.cur_wk_state == '0') {
330 n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s -\n",
331 cwk_state[di.cur_wk_state - '0']);
332 } else if (di.cur_wk_state == '1') {
333 n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s 0x",
334 cwk_state[di.cur_wk_state - '0']);
335 bin2hex(buf + n, di.cur_wkvp, sizeof(di.cur_wkvp));
336 n += 2 * sizeof(di.cur_wkvp);
337 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
339 n = scnprintf(buf, PAGE_SIZE, "WK CUR: - -\n");
341 if (di.new_wk_state == '0') {
342 n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s -\n",
343 nwk_state[di.new_wk_state - '0']);
344 } else if (di.new_wk_state >= '1' && di.new_wk_state <= '2') {
345 n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s 0x",
346 nwk_state[di.new_wk_state - '0']);
347 bin2hex(buf + n, di.new_wkvp, sizeof(di.new_wkvp));
348 n += 2 * sizeof(di.new_wkvp);
349 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
351 n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: - -\n");
356 static struct device_attribute dev_attr_ep11_mkvps =
357 __ATTR(mkvps, 0444, ep11_mkvps_show, NULL);
359 static ssize_t ep11_queue_op_modes_show(struct device *dev,
360 struct device_attribute *attr,
364 struct ep11_domain_info di;
365 struct zcrypt_queue *zq = to_ap_queue(dev)->private;
367 memset(&di, 0, sizeof(di));
370 ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
371 AP_QID_QUEUE(zq->queue->qid),
374 for (i = 0; ep11_op_modes[i].mode_txt; i++) {
375 if (di.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
378 n += scnprintf(buf + n, PAGE_SIZE - n,
379 "%s", ep11_op_modes[i].mode_txt);
382 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
387 static struct device_attribute dev_attr_ep11_queue_op_modes =
388 __ATTR(op_modes, 0444, ep11_queue_op_modes_show, NULL);
390 static struct attribute *ep11_queue_attrs[] = {
391 &dev_attr_ep11_mkvps.attr,
392 &dev_attr_ep11_queue_op_modes.attr,
396 static const struct attribute_group ep11_queue_attr_grp = {
397 .attrs = ep11_queue_attrs,
401 * Probe function for CEX4/CEX5/CEX6/CEX7 card device. It always
402 * accepts the AP device since the bus_match already checked
404 * @ap_dev: pointer to the AP device.
406 static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
409 * Normalized speed ratings per crypto adapter
410 * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY
412 static const int CEX4A_SPEED_IDX[] = {
413 14, 19, 249, 42, 228, 1458, 0, 0};
414 static const int CEX5A_SPEED_IDX[] = {
415 8, 9, 20, 18, 66, 458, 0, 0};
416 static const int CEX6A_SPEED_IDX[] = {
417 6, 9, 20, 17, 65, 438, 0, 0};
418 static const int CEX7A_SPEED_IDX[] = {
419 6, 8, 17, 15, 54, 362, 0, 0};
421 static const int CEX4C_SPEED_IDX[] = {
422 59, 69, 308, 83, 278, 2204, 209, 40};
423 static const int CEX5C_SPEED_IDX[] = {
424 24, 31, 50, 37, 90, 479, 27, 10};
425 static const int CEX6C_SPEED_IDX[] = {
426 16, 20, 32, 27, 77, 455, 24, 9};
427 static const int CEX7C_SPEED_IDX[] = {
428 14, 16, 26, 23, 64, 376, 23, 8};
430 static const int CEX4P_SPEED_IDX[] = {
431 0, 0, 0, 0, 0, 0, 0, 50};
432 static const int CEX5P_SPEED_IDX[] = {
433 0, 0, 0, 0, 0, 0, 0, 10};
434 static const int CEX6P_SPEED_IDX[] = {
435 0, 0, 0, 0, 0, 0, 0, 9};
436 static const int CEX7P_SPEED_IDX[] = {
437 0, 0, 0, 0, 0, 0, 0, 8};
439 struct ap_card *ac = to_ap_card(&ap_dev->device);
440 struct zcrypt_card *zc;
443 zc = zcrypt_card_alloc();
448 if (ap_test_bit(&ac->functions, AP_FUNC_ACCEL)) {
449 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
450 zc->type_string = "CEX4A";
451 zc->user_space_type = ZCRYPT_CEX4;
452 memcpy(zc->speed_rating, CEX4A_SPEED_IDX,
453 sizeof(CEX4A_SPEED_IDX));
454 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
455 zc->type_string = "CEX5A";
456 zc->user_space_type = ZCRYPT_CEX5;
457 memcpy(zc->speed_rating, CEX5A_SPEED_IDX,
458 sizeof(CEX5A_SPEED_IDX));
459 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
460 zc->type_string = "CEX6A";
461 zc->user_space_type = ZCRYPT_CEX6;
462 memcpy(zc->speed_rating, CEX6A_SPEED_IDX,
463 sizeof(CEX6A_SPEED_IDX));
465 zc->type_string = "CEX7A";
466 /* wrong user space type, just for compatibility
467 * with the ZCRYPT_STATUS_MASK ioctl.
469 zc->user_space_type = ZCRYPT_CEX6;
470 memcpy(zc->speed_rating, CEX7A_SPEED_IDX,
471 sizeof(CEX7A_SPEED_IDX));
473 zc->min_mod_size = CEX4A_MIN_MOD_SIZE;
474 if (ap_test_bit(&ac->functions, AP_FUNC_MEX4K) &&
475 ap_test_bit(&ac->functions, AP_FUNC_CRT4K)) {
476 zc->max_mod_size = CEX4A_MAX_MOD_SIZE_4K;
477 zc->max_exp_bit_length =
478 CEX4A_MAX_MOD_SIZE_4K;
480 zc->max_mod_size = CEX4A_MAX_MOD_SIZE_2K;
481 zc->max_exp_bit_length =
482 CEX4A_MAX_MOD_SIZE_2K;
484 } else if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
485 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
486 zc->type_string = "CEX4C";
487 /* wrong user space type, must be CEX4
488 * just keep it for cca compatibility
490 zc->user_space_type = ZCRYPT_CEX3C;
491 memcpy(zc->speed_rating, CEX4C_SPEED_IDX,
492 sizeof(CEX4C_SPEED_IDX));
493 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
494 zc->type_string = "CEX5C";
495 /* wrong user space type, must be CEX5
496 * just keep it for cca compatibility
498 zc->user_space_type = ZCRYPT_CEX3C;
499 memcpy(zc->speed_rating, CEX5C_SPEED_IDX,
500 sizeof(CEX5C_SPEED_IDX));
501 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
502 zc->type_string = "CEX6C";
503 /* wrong user space type, must be CEX6
504 * just keep it for cca compatibility
506 zc->user_space_type = ZCRYPT_CEX3C;
507 memcpy(zc->speed_rating, CEX6C_SPEED_IDX,
508 sizeof(CEX6C_SPEED_IDX));
510 zc->type_string = "CEX7C";
511 /* wrong user space type, must be CEX7
512 * just keep it for cca compatibility
514 zc->user_space_type = ZCRYPT_CEX3C;
515 memcpy(zc->speed_rating, CEX7C_SPEED_IDX,
516 sizeof(CEX7C_SPEED_IDX));
518 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
519 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
520 zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
521 } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
522 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
523 zc->type_string = "CEX4P";
524 zc->user_space_type = ZCRYPT_CEX4;
525 memcpy(zc->speed_rating, CEX4P_SPEED_IDX,
526 sizeof(CEX4P_SPEED_IDX));
527 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
528 zc->type_string = "CEX5P";
529 zc->user_space_type = ZCRYPT_CEX5;
530 memcpy(zc->speed_rating, CEX5P_SPEED_IDX,
531 sizeof(CEX5P_SPEED_IDX));
532 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
533 zc->type_string = "CEX6P";
534 zc->user_space_type = ZCRYPT_CEX6;
535 memcpy(zc->speed_rating, CEX6P_SPEED_IDX,
536 sizeof(CEX6P_SPEED_IDX));
538 zc->type_string = "CEX7P";
539 /* wrong user space type, just for compatibility
540 * with the ZCRYPT_STATUS_MASK ioctl.
542 zc->user_space_type = ZCRYPT_CEX6;
543 memcpy(zc->speed_rating, CEX7P_SPEED_IDX,
544 sizeof(CEX7P_SPEED_IDX));
546 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
547 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
548 zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
550 zcrypt_card_free(zc);
555 rc = zcrypt_card_register(zc);
558 zcrypt_card_free(zc);
562 if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
563 rc = sysfs_create_group(&ap_dev->device.kobj,
566 zcrypt_card_unregister(zc);
568 zcrypt_card_free(zc);
570 } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
571 rc = sysfs_create_group(&ap_dev->device.kobj,
572 &ep11_card_attr_grp);
574 zcrypt_card_unregister(zc);
576 zcrypt_card_free(zc);
584 * This is called to remove the CEX4/CEX5/CEX6/CEX7 card driver
585 * information if an AP card device is removed.
587 static void zcrypt_cex4_card_remove(struct ap_device *ap_dev)
589 struct ap_card *ac = to_ap_card(&ap_dev->device);
590 struct zcrypt_card *zc = ac->private;
592 if (ap_test_bit(&ac->functions, AP_FUNC_COPRO))
593 sysfs_remove_group(&ap_dev->device.kobj, &cca_card_attr_grp);
594 else if (ap_test_bit(&ac->functions, AP_FUNC_EP11))
595 sysfs_remove_group(&ap_dev->device.kobj, &ep11_card_attr_grp);
597 zcrypt_card_unregister(zc);
600 static struct ap_driver zcrypt_cex4_card_driver = {
601 .probe = zcrypt_cex4_card_probe,
602 .remove = zcrypt_cex4_card_remove,
603 .ids = zcrypt_cex4_card_ids,
604 .flags = AP_DRIVER_FLAG_DEFAULT,
608 * Probe function for CEX4/CEX5/CEX6/CEX7 queue device. It always
609 * accepts the AP device since the bus_match already checked
611 * @ap_dev: pointer to the AP device.
613 static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
615 struct ap_queue *aq = to_ap_queue(&ap_dev->device);
616 struct zcrypt_queue *zq;
619 if (ap_test_bit(&aq->card->functions, AP_FUNC_ACCEL)) {
620 zq = zcrypt_queue_alloc(CEX4A_MAX_MESSAGE_SIZE);
623 zq->ops = zcrypt_msgtype(MSGTYPE50_NAME,
624 MSGTYPE50_VARIANT_DEFAULT);
625 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
626 zq = zcrypt_queue_alloc(CEX4C_MAX_MESSAGE_SIZE);
629 zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
630 MSGTYPE06_VARIANT_DEFAULT);
631 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
632 zq = zcrypt_queue_alloc(CEX4C_MAX_MESSAGE_SIZE);
635 zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
636 MSGTYPE06_VARIANT_EP11);
643 atomic_set(&zq->load, 0);
644 ap_queue_init_state(aq);
645 ap_queue_init_reply(aq, &zq->reply);
646 aq->request_timeout = CEX4_CLEANUP_TIME,
648 rc = zcrypt_queue_register(zq);
651 zcrypt_queue_free(zq);
655 if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
656 rc = sysfs_create_group(&ap_dev->device.kobj,
657 &cca_queue_attr_grp);
659 zcrypt_queue_unregister(zq);
661 zcrypt_queue_free(zq);
663 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
664 rc = sysfs_create_group(&ap_dev->device.kobj,
665 &ep11_queue_attr_grp);
667 zcrypt_queue_unregister(zq);
669 zcrypt_queue_free(zq);
677 * This is called to remove the CEX4/CEX5/CEX6/CEX7 queue driver
678 * information if an AP queue device is removed.
680 static void zcrypt_cex4_queue_remove(struct ap_device *ap_dev)
682 struct ap_queue *aq = to_ap_queue(&ap_dev->device);
683 struct zcrypt_queue *zq = aq->private;
685 if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO))
686 sysfs_remove_group(&ap_dev->device.kobj, &cca_queue_attr_grp);
687 else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11))
688 sysfs_remove_group(&ap_dev->device.kobj, &ep11_queue_attr_grp);
690 zcrypt_queue_unregister(zq);
693 static struct ap_driver zcrypt_cex4_queue_driver = {
694 .probe = zcrypt_cex4_queue_probe,
695 .remove = zcrypt_cex4_queue_remove,
696 .ids = zcrypt_cex4_queue_ids,
697 .flags = AP_DRIVER_FLAG_DEFAULT,
700 int __init zcrypt_cex4_init(void)
704 rc = ap_driver_register(&zcrypt_cex4_card_driver,
705 THIS_MODULE, "cex4card");
709 rc = ap_driver_register(&zcrypt_cex4_queue_driver,
710 THIS_MODULE, "cex4queue");
712 ap_driver_unregister(&zcrypt_cex4_card_driver);
717 void __exit zcrypt_cex4_exit(void)
719 ap_driver_unregister(&zcrypt_cex4_queue_driver);
720 ap_driver_unregister(&zcrypt_cex4_card_driver);
723 module_init(zcrypt_cex4_init);
724 module_exit(zcrypt_cex4_exit);