1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2012, 2022
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 /* Waiting time for requests to be processed.
32 * Currently there are some types of request which are not deterministic.
33 * But the maximum time limit managed by the stomper code is set to 60sec.
34 * Hence we have to wait at least that time period.
36 #define CEX4_CLEANUP_TIME (900 * HZ)
38 MODULE_AUTHOR("IBM Corporation");
39 MODULE_DESCRIPTION("CEX[45678] Cryptographic Card device driver, " \
40 "Copyright IBM Corp. 2022");
41 MODULE_LICENSE("GPL");
43 static struct ap_device_id zcrypt_cex4_card_ids[] = {
44 { .dev_type = AP_DEVICE_TYPE_CEX4,
45 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
46 { .dev_type = AP_DEVICE_TYPE_CEX5,
47 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
48 { .dev_type = AP_DEVICE_TYPE_CEX6,
49 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
50 { .dev_type = AP_DEVICE_TYPE_CEX7,
51 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
52 { .dev_type = AP_DEVICE_TYPE_CEX8,
53 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
54 { /* end of list */ },
57 MODULE_DEVICE_TABLE(ap, zcrypt_cex4_card_ids);
59 static struct ap_device_id zcrypt_cex4_queue_ids[] = {
60 { .dev_type = AP_DEVICE_TYPE_CEX4,
61 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
62 { .dev_type = AP_DEVICE_TYPE_CEX5,
63 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
64 { .dev_type = AP_DEVICE_TYPE_CEX6,
65 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
66 { .dev_type = AP_DEVICE_TYPE_CEX7,
67 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
68 { .dev_type = AP_DEVICE_TYPE_CEX8,
69 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
70 { /* end of list */ },
73 MODULE_DEVICE_TABLE(ap, zcrypt_cex4_queue_ids);
76 * CCA card additional device attributes
78 static ssize_t cca_serialnr_show(struct device *dev,
79 struct device_attribute *attr,
82 struct zcrypt_card *zc = dev_get_drvdata(dev);
84 struct ap_card *ac = to_ap_card(dev);
86 memset(&ci, 0, sizeof(ci));
88 if (ap_domain_index >= 0)
89 cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
91 return sysfs_emit(buf, "%s\n", ci.serial);
94 static struct device_attribute dev_attr_cca_serialnr =
95 __ATTR(serialnr, 0444, cca_serialnr_show, NULL);
97 static struct attribute *cca_card_attrs[] = {
98 &dev_attr_cca_serialnr.attr,
102 static const struct attribute_group cca_card_attr_grp = {
103 .attrs = cca_card_attrs,
107 * CCA queue additional device attributes
109 static ssize_t cca_mkvps_show(struct device *dev,
110 struct device_attribute *attr,
113 struct zcrypt_queue *zq = dev_get_drvdata(dev);
116 static const char * const cao_state[] = { "invalid", "valid" };
117 static const char * const new_state[] = { "empty", "partial", "full" };
119 memset(&ci, 0, sizeof(ci));
121 cca_get_info(AP_QID_CARD(zq->queue->qid),
122 AP_QID_QUEUE(zq->queue->qid),
125 if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3')
126 n += sysfs_emit_at(buf, n, "AES NEW: %s 0x%016llx\n",
127 new_state[ci.new_aes_mk_state - '1'],
130 n += sysfs_emit_at(buf, n, "AES NEW: - -\n");
132 if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2')
133 n += sysfs_emit_at(buf, n, "AES CUR: %s 0x%016llx\n",
134 cao_state[ci.cur_aes_mk_state - '1'],
137 n += sysfs_emit_at(buf, n, "AES CUR: - -\n");
139 if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2')
140 n += sysfs_emit_at(buf, n, "AES OLD: %s 0x%016llx\n",
141 cao_state[ci.old_aes_mk_state - '1'],
144 n += sysfs_emit_at(buf, n, "AES OLD: - -\n");
146 if (ci.new_apka_mk_state >= '1' && ci.new_apka_mk_state <= '3')
147 n += sysfs_emit_at(buf, n, "APKA NEW: %s 0x%016llx\n",
148 new_state[ci.new_apka_mk_state - '1'],
151 n += sysfs_emit_at(buf, n, "APKA NEW: - -\n");
153 if (ci.cur_apka_mk_state >= '1' && ci.cur_apka_mk_state <= '2')
154 n += sysfs_emit_at(buf, n, "APKA CUR: %s 0x%016llx\n",
155 cao_state[ci.cur_apka_mk_state - '1'],
158 n += sysfs_emit_at(buf, n, "APKA CUR: - -\n");
160 if (ci.old_apka_mk_state >= '1' && ci.old_apka_mk_state <= '2')
161 n += sysfs_emit_at(buf, n, "APKA OLD: %s 0x%016llx\n",
162 cao_state[ci.old_apka_mk_state - '1'],
165 n += sysfs_emit_at(buf, n, "APKA OLD: - -\n");
167 if (ci.new_asym_mk_state >= '1' && ci.new_asym_mk_state <= '3')
168 n += sysfs_emit_at(buf, n, "ASYM NEW: %s 0x%016llx%016llx\n",
169 new_state[ci.new_asym_mk_state - '1'],
170 *((u64 *)(ci.new_asym_mkvp)),
171 *((u64 *)(ci.new_asym_mkvp + sizeof(u64))));
173 n += sysfs_emit_at(buf, n, "ASYM NEW: - -\n");
175 if (ci.cur_asym_mk_state >= '1' && ci.cur_asym_mk_state <= '2')
176 n += sysfs_emit_at(buf, n, "ASYM CUR: %s 0x%016llx%016llx\n",
177 cao_state[ci.cur_asym_mk_state - '1'],
178 *((u64 *)(ci.cur_asym_mkvp)),
179 *((u64 *)(ci.cur_asym_mkvp + sizeof(u64))));
181 n += sysfs_emit_at(buf, n, "ASYM CUR: - -\n");
183 if (ci.old_asym_mk_state >= '1' && ci.old_asym_mk_state <= '2')
184 n += sysfs_emit_at(buf, n, "ASYM OLD: %s 0x%016llx%016llx\n",
185 cao_state[ci.old_asym_mk_state - '1'],
186 *((u64 *)(ci.old_asym_mkvp)),
187 *((u64 *)(ci.old_asym_mkvp + sizeof(u64))));
189 n += sysfs_emit_at(buf, n, "ASYM OLD: - -\n");
194 static struct device_attribute dev_attr_cca_mkvps =
195 __ATTR(mkvps, 0444, cca_mkvps_show, NULL);
197 static struct attribute *cca_queue_attrs[] = {
198 &dev_attr_cca_mkvps.attr,
202 static const struct attribute_group cca_queue_attr_grp = {
203 .attrs = cca_queue_attrs,
207 * EP11 card additional device attributes
209 static ssize_t ep11_api_ordinalnr_show(struct device *dev,
210 struct device_attribute *attr,
213 struct zcrypt_card *zc = dev_get_drvdata(dev);
214 struct ep11_card_info ci;
215 struct ap_card *ac = to_ap_card(dev);
217 memset(&ci, 0, sizeof(ci));
219 ep11_get_card_info(ac->id, &ci, zc->online);
221 if (ci.API_ord_nr > 0)
222 return sysfs_emit(buf, "%u\n", ci.API_ord_nr);
224 return sysfs_emit(buf, "\n");
227 static struct device_attribute dev_attr_ep11_api_ordinalnr =
228 __ATTR(API_ordinalnr, 0444, ep11_api_ordinalnr_show, NULL);
230 static ssize_t ep11_fw_version_show(struct device *dev,
231 struct device_attribute *attr,
234 struct zcrypt_card *zc = dev_get_drvdata(dev);
235 struct ep11_card_info ci;
236 struct ap_card *ac = to_ap_card(dev);
238 memset(&ci, 0, sizeof(ci));
240 ep11_get_card_info(ac->id, &ci, zc->online);
242 if (ci.FW_version > 0)
243 return sysfs_emit(buf, "%d.%d\n",
244 (int)(ci.FW_version >> 8),
245 (int)(ci.FW_version & 0xFF));
247 return sysfs_emit(buf, "\n");
250 static struct device_attribute dev_attr_ep11_fw_version =
251 __ATTR(FW_version, 0444, ep11_fw_version_show, NULL);
253 static ssize_t ep11_serialnr_show(struct device *dev,
254 struct device_attribute *attr,
257 struct zcrypt_card *zc = dev_get_drvdata(dev);
258 struct ep11_card_info ci;
259 struct ap_card *ac = to_ap_card(dev);
261 memset(&ci, 0, sizeof(ci));
263 ep11_get_card_info(ac->id, &ci, zc->online);
266 return sysfs_emit(buf, "%16.16s\n", ci.serial);
268 return sysfs_emit(buf, "\n");
271 static struct device_attribute dev_attr_ep11_serialnr =
272 __ATTR(serialnr, 0444, ep11_serialnr_show, NULL);
274 static const struct {
276 const char *mode_txt;
277 } ep11_op_modes[] = {
286 static ssize_t ep11_card_op_modes_show(struct device *dev,
287 struct device_attribute *attr,
290 struct zcrypt_card *zc = dev_get_drvdata(dev);
292 struct ep11_card_info ci;
293 struct ap_card *ac = to_ap_card(dev);
295 memset(&ci, 0, sizeof(ci));
297 ep11_get_card_info(ac->id, &ci, zc->online);
299 for (i = 0; ep11_op_modes[i].mode_txt; i++) {
300 if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
303 n += sysfs_emit_at(buf, n, "%s",
304 ep11_op_modes[i].mode_txt);
307 n += sysfs_emit_at(buf, n, "\n");
312 static struct device_attribute dev_attr_ep11_card_op_modes =
313 __ATTR(op_modes, 0444, ep11_card_op_modes_show, NULL);
315 static struct attribute *ep11_card_attrs[] = {
316 &dev_attr_ep11_api_ordinalnr.attr,
317 &dev_attr_ep11_fw_version.attr,
318 &dev_attr_ep11_serialnr.attr,
319 &dev_attr_ep11_card_op_modes.attr,
323 static const struct attribute_group ep11_card_attr_grp = {
324 .attrs = ep11_card_attrs,
328 * EP11 queue additional device attributes
331 static ssize_t ep11_mkvps_show(struct device *dev,
332 struct device_attribute *attr,
335 struct zcrypt_queue *zq = dev_get_drvdata(dev);
337 struct ep11_domain_info di;
338 static const char * const cwk_state[] = { "invalid", "valid" };
339 static const char * const nwk_state[] = { "empty", "uncommitted",
342 memset(&di, 0, sizeof(di));
345 ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
346 AP_QID_QUEUE(zq->queue->qid),
349 if (di.cur_wk_state == '0') {
350 n = sysfs_emit(buf, "WK CUR: %s -\n",
351 cwk_state[di.cur_wk_state - '0']);
352 } else if (di.cur_wk_state == '1') {
353 n = sysfs_emit(buf, "WK CUR: %s 0x",
354 cwk_state[di.cur_wk_state - '0']);
355 bin2hex(buf + n, di.cur_wkvp, sizeof(di.cur_wkvp));
356 n += 2 * sizeof(di.cur_wkvp);
357 n += sysfs_emit_at(buf, n, "\n");
359 n = sysfs_emit(buf, "WK CUR: - -\n");
362 if (di.new_wk_state == '0') {
363 n += sysfs_emit_at(buf, n, "WK NEW: %s -\n",
364 nwk_state[di.new_wk_state - '0']);
365 } else if (di.new_wk_state >= '1' && di.new_wk_state <= '2') {
366 n += sysfs_emit_at(buf, n, "WK NEW: %s 0x",
367 nwk_state[di.new_wk_state - '0']);
368 bin2hex(buf + n, di.new_wkvp, sizeof(di.new_wkvp));
369 n += 2 * sizeof(di.new_wkvp);
370 n += sysfs_emit_at(buf, n, "\n");
372 n += sysfs_emit_at(buf, n, "WK NEW: - -\n");
378 static struct device_attribute dev_attr_ep11_mkvps =
379 __ATTR(mkvps, 0444, ep11_mkvps_show, NULL);
381 static ssize_t ep11_queue_op_modes_show(struct device *dev,
382 struct device_attribute *attr,
385 struct zcrypt_queue *zq = dev_get_drvdata(dev);
387 struct ep11_domain_info di;
389 memset(&di, 0, sizeof(di));
392 ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
393 AP_QID_QUEUE(zq->queue->qid),
396 for (i = 0; ep11_op_modes[i].mode_txt; i++) {
397 if (di.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
400 n += sysfs_emit_at(buf, n, "%s",
401 ep11_op_modes[i].mode_txt);
404 n += sysfs_emit_at(buf, n, "\n");
409 static struct device_attribute dev_attr_ep11_queue_op_modes =
410 __ATTR(op_modes, 0444, ep11_queue_op_modes_show, NULL);
412 static struct attribute *ep11_queue_attrs[] = {
413 &dev_attr_ep11_mkvps.attr,
414 &dev_attr_ep11_queue_op_modes.attr,
418 static const struct attribute_group ep11_queue_attr_grp = {
419 .attrs = ep11_queue_attrs,
423 * Probe function for CEX[45678] card device. It always
424 * accepts the AP device since the bus_match already checked
426 * @ap_dev: pointer to the AP device.
428 static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
431 * Normalized speed ratings per crypto adapter
432 * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY
434 static const int CEX4A_SPEED_IDX[NUM_OPS] = {
435 14, 19, 249, 42, 228, 1458, 0, 0};
436 static const int CEX5A_SPEED_IDX[NUM_OPS] = {
437 8, 9, 20, 18, 66, 458, 0, 0};
438 static const int CEX6A_SPEED_IDX[NUM_OPS] = {
439 6, 9, 20, 17, 65, 438, 0, 0};
440 static const int CEX7A_SPEED_IDX[NUM_OPS] = {
441 6, 8, 17, 15, 54, 362, 0, 0};
442 static const int CEX8A_SPEED_IDX[NUM_OPS] = {
443 6, 8, 17, 15, 54, 362, 0, 0};
445 static const int CEX4C_SPEED_IDX[NUM_OPS] = {
446 59, 69, 308, 83, 278, 2204, 209, 40};
447 static const int CEX5C_SPEED_IDX[] = {
448 24, 31, 50, 37, 90, 479, 27, 10};
449 static const int CEX6C_SPEED_IDX[NUM_OPS] = {
450 16, 20, 32, 27, 77, 455, 24, 9};
451 static const int CEX7C_SPEED_IDX[NUM_OPS] = {
452 14, 16, 26, 23, 64, 376, 23, 8};
453 static const int CEX8C_SPEED_IDX[NUM_OPS] = {
454 14, 16, 26, 23, 64, 376, 23, 8};
456 static const int CEX4P_SPEED_IDX[NUM_OPS] = {
457 0, 0, 0, 0, 0, 0, 0, 50};
458 static const int CEX5P_SPEED_IDX[NUM_OPS] = {
459 0, 0, 0, 0, 0, 0, 0, 10};
460 static const int CEX6P_SPEED_IDX[NUM_OPS] = {
461 0, 0, 0, 0, 0, 0, 0, 9};
462 static const int CEX7P_SPEED_IDX[NUM_OPS] = {
463 0, 0, 0, 0, 0, 0, 0, 8};
464 static const int CEX8P_SPEED_IDX[NUM_OPS] = {
465 0, 0, 0, 0, 0, 0, 0, 8};
467 struct ap_card *ac = to_ap_card(&ap_dev->device);
468 struct zcrypt_card *zc;
471 zc = zcrypt_card_alloc();
475 dev_set_drvdata(&ap_dev->device, zc);
476 if (ap_test_bit(&ac->functions, AP_FUNC_ACCEL)) {
477 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
478 zc->type_string = "CEX4A";
479 zc->user_space_type = ZCRYPT_CEX4;
480 zc->speed_rating = CEX4A_SPEED_IDX;
481 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
482 zc->type_string = "CEX5A";
483 zc->user_space_type = ZCRYPT_CEX5;
484 zc->speed_rating = CEX5A_SPEED_IDX;
485 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
486 zc->type_string = "CEX6A";
487 zc->user_space_type = ZCRYPT_CEX6;
488 zc->speed_rating = CEX6A_SPEED_IDX;
489 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX7) {
490 zc->type_string = "CEX7A";
491 zc->speed_rating = CEX7A_SPEED_IDX;
492 /* wrong user space type, just for compatibility
493 * with the ZCRYPT_STATUS_MASK ioctl.
495 zc->user_space_type = ZCRYPT_CEX6;
497 zc->type_string = "CEX8A";
498 zc->speed_rating = CEX8A_SPEED_IDX;
499 /* wrong user space type, just for compatibility
500 * with the ZCRYPT_STATUS_MASK ioctl.
502 zc->user_space_type = ZCRYPT_CEX6;
504 zc->min_mod_size = CEX4A_MIN_MOD_SIZE;
505 if (ap_test_bit(&ac->functions, AP_FUNC_MEX4K) &&
506 ap_test_bit(&ac->functions, AP_FUNC_CRT4K)) {
507 zc->max_mod_size = CEX4A_MAX_MOD_SIZE_4K;
508 zc->max_exp_bit_length =
509 CEX4A_MAX_MOD_SIZE_4K;
511 zc->max_mod_size = CEX4A_MAX_MOD_SIZE_2K;
512 zc->max_exp_bit_length =
513 CEX4A_MAX_MOD_SIZE_2K;
515 } else if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
516 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
517 zc->type_string = "CEX4C";
518 zc->speed_rating = CEX4C_SPEED_IDX;
519 /* wrong user space type, must be CEX3C
520 * just keep it for cca compatibility
522 zc->user_space_type = ZCRYPT_CEX3C;
523 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
524 zc->type_string = "CEX5C";
525 zc->speed_rating = CEX5C_SPEED_IDX;
526 /* wrong user space type, must be CEX3C
527 * just keep it for cca compatibility
529 zc->user_space_type = ZCRYPT_CEX3C;
530 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
531 zc->type_string = "CEX6C";
532 zc->speed_rating = CEX6C_SPEED_IDX;
533 /* wrong user space type, must be CEX3C
534 * just keep it for cca compatibility
536 zc->user_space_type = ZCRYPT_CEX3C;
537 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX7) {
538 zc->type_string = "CEX7C";
539 zc->speed_rating = CEX7C_SPEED_IDX;
540 /* wrong user space type, must be CEX3C
541 * just keep it for cca compatibility
543 zc->user_space_type = ZCRYPT_CEX3C;
545 zc->type_string = "CEX8C";
546 zc->speed_rating = CEX8C_SPEED_IDX;
547 /* wrong user space type, must be CEX3C
548 * just keep it for cca compatibility
550 zc->user_space_type = ZCRYPT_CEX3C;
552 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
553 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
554 zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
555 } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
556 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
557 zc->type_string = "CEX4P";
558 zc->user_space_type = ZCRYPT_CEX4;
559 zc->speed_rating = CEX4P_SPEED_IDX;
560 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
561 zc->type_string = "CEX5P";
562 zc->user_space_type = ZCRYPT_CEX5;
563 zc->speed_rating = CEX5P_SPEED_IDX;
564 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
565 zc->type_string = "CEX6P";
566 zc->user_space_type = ZCRYPT_CEX6;
567 zc->speed_rating = CEX6P_SPEED_IDX;
568 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX7) {
569 zc->type_string = "CEX7P";
570 zc->speed_rating = CEX7P_SPEED_IDX;
571 /* wrong user space type, just for compatibility
572 * with the ZCRYPT_STATUS_MASK ioctl.
574 zc->user_space_type = ZCRYPT_CEX6;
576 zc->type_string = "CEX8P";
577 zc->speed_rating = CEX8P_SPEED_IDX;
578 /* wrong user space type, just for compatibility
579 * with the ZCRYPT_STATUS_MASK ioctl.
581 zc->user_space_type = ZCRYPT_CEX6;
583 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
584 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
585 zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
587 zcrypt_card_free(zc);
592 rc = zcrypt_card_register(zc);
594 zcrypt_card_free(zc);
598 if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
599 rc = sysfs_create_group(&ap_dev->device.kobj,
602 zcrypt_card_unregister(zc);
603 zcrypt_card_free(zc);
605 } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
606 rc = sysfs_create_group(&ap_dev->device.kobj,
607 &ep11_card_attr_grp);
609 zcrypt_card_unregister(zc);
610 zcrypt_card_free(zc);
618 * This is called to remove the CEX[45678] card driver
619 * information if an AP card device is removed.
621 static void zcrypt_cex4_card_remove(struct ap_device *ap_dev)
623 struct zcrypt_card *zc = dev_get_drvdata(&ap_dev->device);
624 struct ap_card *ac = to_ap_card(&ap_dev->device);
626 if (ap_test_bit(&ac->functions, AP_FUNC_COPRO))
627 sysfs_remove_group(&ap_dev->device.kobj, &cca_card_attr_grp);
628 else if (ap_test_bit(&ac->functions, AP_FUNC_EP11))
629 sysfs_remove_group(&ap_dev->device.kobj, &ep11_card_attr_grp);
631 zcrypt_card_unregister(zc);
634 static struct ap_driver zcrypt_cex4_card_driver = {
635 .probe = zcrypt_cex4_card_probe,
636 .remove = zcrypt_cex4_card_remove,
637 .ids = zcrypt_cex4_card_ids,
638 .flags = AP_DRIVER_FLAG_DEFAULT,
642 * Probe function for CEX[45678] queue device. It always
643 * accepts the AP device since the bus_match already checked
645 * @ap_dev: pointer to the AP device.
647 static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
649 struct ap_queue *aq = to_ap_queue(&ap_dev->device);
650 struct zcrypt_queue *zq;
653 if (ap_test_bit(&aq->card->functions, AP_FUNC_ACCEL)) {
654 zq = zcrypt_queue_alloc(aq->card->maxmsgsize);
657 zq->ops = zcrypt_msgtype(MSGTYPE50_NAME,
658 MSGTYPE50_VARIANT_DEFAULT);
659 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
660 zq = zcrypt_queue_alloc(aq->card->maxmsgsize);
663 zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
664 MSGTYPE06_VARIANT_DEFAULT);
665 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
666 zq = zcrypt_queue_alloc(aq->card->maxmsgsize);
669 zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
670 MSGTYPE06_VARIANT_EP11);
677 atomic_set(&zq->load, 0);
678 ap_queue_init_state(aq);
679 ap_queue_init_reply(aq, &zq->reply);
680 aq->request_timeout = CEX4_CLEANUP_TIME;
681 dev_set_drvdata(&ap_dev->device, zq);
682 rc = zcrypt_queue_register(zq);
684 zcrypt_queue_free(zq);
688 if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
689 rc = sysfs_create_group(&ap_dev->device.kobj,
690 &cca_queue_attr_grp);
692 zcrypt_queue_unregister(zq);
693 zcrypt_queue_free(zq);
695 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
696 rc = sysfs_create_group(&ap_dev->device.kobj,
697 &ep11_queue_attr_grp);
699 zcrypt_queue_unregister(zq);
700 zcrypt_queue_free(zq);
708 * This is called to remove the CEX[45678] queue driver
709 * information if an AP queue device is removed.
711 static void zcrypt_cex4_queue_remove(struct ap_device *ap_dev)
713 struct zcrypt_queue *zq = dev_get_drvdata(&ap_dev->device);
714 struct ap_queue *aq = to_ap_queue(&ap_dev->device);
716 if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO))
717 sysfs_remove_group(&ap_dev->device.kobj, &cca_queue_attr_grp);
718 else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11))
719 sysfs_remove_group(&ap_dev->device.kobj, &ep11_queue_attr_grp);
721 zcrypt_queue_unregister(zq);
724 static struct ap_driver zcrypt_cex4_queue_driver = {
725 .probe = zcrypt_cex4_queue_probe,
726 .remove = zcrypt_cex4_queue_remove,
727 .ids = zcrypt_cex4_queue_ids,
728 .flags = AP_DRIVER_FLAG_DEFAULT,
731 int __init zcrypt_cex4_init(void)
735 rc = ap_driver_register(&zcrypt_cex4_card_driver,
736 THIS_MODULE, "cex4card");
740 rc = ap_driver_register(&zcrypt_cex4_queue_driver,
741 THIS_MODULE, "cex4queue");
743 ap_driver_unregister(&zcrypt_cex4_card_driver);
748 void __exit zcrypt_cex4_exit(void)
750 ap_driver_unregister(&zcrypt_cex4_queue_driver);
751 ap_driver_unregister(&zcrypt_cex4_card_driver);
754 module_init(zcrypt_cex4_init);
755 module_exit(zcrypt_cex4_exit);