1
2
3
4
5
6
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>
14
15#include "ap_bus.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"
23
24#define CEX4A_MIN_MOD_SIZE 1
25#define CEX4A_MAX_MOD_SIZE_2K 256
26#define CEX4A_MAX_MOD_SIZE_4K 512
27
28#define CEX4C_MIN_MOD_SIZE 16
29#define CEX4C_MAX_MOD_SIZE 512
30
31
32
33
34
35
36#define CEX4_CLEANUP_TIME (900*HZ)
37
38MODULE_AUTHOR("IBM Corporation");
39MODULE_DESCRIPTION("CEX4/CEX5/CEX6/CEX7 Cryptographic Card device driver, " \
40 "Copyright IBM Corp. 2019");
41MODULE_LICENSE("GPL");
42
43static 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 { },
53};
54
55MODULE_DEVICE_TABLE(ap, zcrypt_cex4_card_ids);
56
57static struct ap_device_id zcrypt_cex4_queue_ids[] = {
58 { .dev_type = AP_DEVICE_TYPE_CEX4,
59 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
60 { .dev_type = AP_DEVICE_TYPE_CEX5,
61 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
62 { .dev_type = AP_DEVICE_TYPE_CEX6,
63 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
64 { .dev_type = AP_DEVICE_TYPE_CEX7,
65 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
66 { },
67};
68
69MODULE_DEVICE_TABLE(ap, zcrypt_cex4_queue_ids);
70
71
72
73
74static ssize_t cca_serialnr_show(struct device *dev,
75 struct device_attribute *attr,
76 char *buf)
77{
78 struct cca_info ci;
79 struct ap_card *ac = to_ap_card(dev);
80 struct zcrypt_card *zc = ac->private;
81
82 memset(&ci, 0, sizeof(ci));
83
84 if (ap_domain_index >= 0)
85 cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
86
87 return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial);
88}
89
90static struct device_attribute dev_attr_cca_serialnr =
91 __ATTR(serialnr, 0444, cca_serialnr_show, NULL);
92
93static struct attribute *cca_card_attrs[] = {
94 &dev_attr_cca_serialnr.attr,
95 NULL,
96};
97
98static const struct attribute_group cca_card_attr_grp = {
99 .attrs = cca_card_attrs,
100};
101
102
103
104
105static ssize_t cca_mkvps_show(struct device *dev,
106 struct device_attribute *attr,
107 char *buf)
108{
109 int n = 0;
110 struct cca_info ci;
111 struct zcrypt_queue *zq = to_ap_queue(dev)->private;
112 static const char * const cao_state[] = { "invalid", "valid" };
113 static const char * const new_state[] = { "empty", "partial", "full" };
114
115 memset(&ci, 0, sizeof(ci));
116
117 cca_get_info(AP_QID_CARD(zq->queue->qid),
118 AP_QID_QUEUE(zq->queue->qid),
119 &ci, zq->online);
120
121 if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3')
122 n = scnprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n",
123 new_state[ci.new_aes_mk_state - '1'],
124 ci.new_aes_mkvp);
125 else
126 n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n");
127
128 if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2')
129 n += scnprintf(buf + n, PAGE_SIZE - n,
130 "AES CUR: %s 0x%016llx\n",
131 cao_state[ci.cur_aes_mk_state - '1'],
132 ci.cur_aes_mkvp);
133 else
134 n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n");
135
136 if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2')
137 n += scnprintf(buf + n, PAGE_SIZE - n,
138 "AES OLD: %s 0x%016llx\n",
139 cao_state[ci.old_aes_mk_state - '1'],
140 ci.old_aes_mkvp);
141 else
142 n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n");
143
144 if (ci.new_apka_mk_state >= '1' && ci.new_apka_mk_state <= '3')
145 n += scnprintf(buf + n, PAGE_SIZE - n,
146 "APKA NEW: %s 0x%016llx\n",
147 new_state[ci.new_apka_mk_state - '1'],
148 ci.new_apka_mkvp);
149 else
150 n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n");
151
152 if (ci.cur_apka_mk_state >= '1' && ci.cur_apka_mk_state <= '2')
153 n += scnprintf(buf + n, PAGE_SIZE - n,
154 "APKA CUR: %s 0x%016llx\n",
155 cao_state[ci.cur_apka_mk_state - '1'],
156 ci.cur_apka_mkvp);
157 else
158 n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n");
159
160 if (ci.old_apka_mk_state >= '1' && ci.old_apka_mk_state <= '2')
161 n += scnprintf(buf + n, PAGE_SIZE - n,
162 "APKA OLD: %s 0x%016llx\n",
163 cao_state[ci.old_apka_mk_state - '1'],
164 ci.old_apka_mkvp);
165 else
166 n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n");
167
168 return n;
169}
170
171static struct device_attribute dev_attr_cca_mkvps =
172 __ATTR(mkvps, 0444, cca_mkvps_show, NULL);
173
174static struct attribute *cca_queue_attrs[] = {
175 &dev_attr_cca_mkvps.attr,
176 NULL,
177};
178
179static const struct attribute_group cca_queue_attr_grp = {
180 .attrs = cca_queue_attrs,
181};
182
183
184
185
186static ssize_t ep11_api_ordinalnr_show(struct device *dev,
187 struct device_attribute *attr,
188 char *buf)
189{
190 struct ep11_card_info ci;
191 struct ap_card *ac = to_ap_card(dev);
192 struct zcrypt_card *zc = ac->private;
193
194 memset(&ci, 0, sizeof(ci));
195
196 ep11_get_card_info(ac->id, &ci, zc->online);
197
198 if (ci.API_ord_nr > 0)
199 return scnprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr);
200 else
201 return scnprintf(buf, PAGE_SIZE, "\n");
202}
203
204static struct device_attribute dev_attr_ep11_api_ordinalnr =
205 __ATTR(API_ordinalnr, 0444, ep11_api_ordinalnr_show, NULL);
206
207static ssize_t ep11_fw_version_show(struct device *dev,
208 struct device_attribute *attr,
209 char *buf)
210{
211 struct ep11_card_info ci;
212 struct ap_card *ac = to_ap_card(dev);
213 struct zcrypt_card *zc = ac->private;
214
215 memset(&ci, 0, sizeof(ci));
216
217 ep11_get_card_info(ac->id, &ci, zc->online);
218
219 if (ci.FW_version > 0)
220 return scnprintf(buf, PAGE_SIZE, "%d.%d\n",
221 (int)(ci.FW_version >> 8),
222 (int)(ci.FW_version & 0xFF));
223 else
224 return scnprintf(buf, PAGE_SIZE, "\n");
225}
226
227static struct device_attribute dev_attr_ep11_fw_version =
228 __ATTR(FW_version, 0444, ep11_fw_version_show, NULL);
229
230static ssize_t ep11_serialnr_show(struct device *dev,
231 struct device_attribute *attr,
232 char *buf)
233{
234 struct ep11_card_info ci;
235 struct ap_card *ac = to_ap_card(dev);
236 struct zcrypt_card *zc = ac->private;
237
238 memset(&ci, 0, sizeof(ci));
239
240 ep11_get_card_info(ac->id, &ci, zc->online);
241
242 if (ci.serial[0])
243 return scnprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial);
244 else
245 return scnprintf(buf, PAGE_SIZE, "\n");
246}
247
248static struct device_attribute dev_attr_ep11_serialnr =
249 __ATTR(serialnr, 0444, ep11_serialnr_show, NULL);
250
251static const struct {
252 int mode_bit;
253 const char *mode_txt;
254} ep11_op_modes[] = {
255 { 0, "FIPS2009" },
256 { 1, "BSI2009" },
257 { 2, "FIPS2011" },
258 { 3, "BSI2011" },
259 { 6, "BSICC2017" },
260 { 0, NULL }
261};
262
263static ssize_t ep11_card_op_modes_show(struct device *dev,
264 struct device_attribute *attr,
265 char *buf)
266{
267 int i, n = 0;
268 struct ep11_card_info ci;
269 struct ap_card *ac = to_ap_card(dev);
270 struct zcrypt_card *zc = ac->private;
271
272 memset(&ci, 0, sizeof(ci));
273
274 ep11_get_card_info(ac->id, &ci, zc->online);
275
276 for (i = 0; ep11_op_modes[i].mode_txt; i++) {
277 if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
278 if (n > 0)
279 buf[n++] = ' ';
280 n += scnprintf(buf + n, PAGE_SIZE - n,
281 "%s", ep11_op_modes[i].mode_txt);
282 }
283 }
284 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
285
286 return n;
287}
288
289static struct device_attribute dev_attr_ep11_card_op_modes =
290 __ATTR(op_modes, 0444, ep11_card_op_modes_show, NULL);
291
292static struct attribute *ep11_card_attrs[] = {
293 &dev_attr_ep11_api_ordinalnr.attr,
294 &dev_attr_ep11_fw_version.attr,
295 &dev_attr_ep11_serialnr.attr,
296 &dev_attr_ep11_card_op_modes.attr,
297 NULL,
298};
299
300static const struct attribute_group ep11_card_attr_grp = {
301 .attrs = ep11_card_attrs,
302};
303
304
305
306
307
308static ssize_t ep11_mkvps_show(struct device *dev,
309 struct device_attribute *attr,
310 char *buf)
311{
312 int n = 0;
313 struct ep11_domain_info di;
314 struct zcrypt_queue *zq = to_ap_queue(dev)->private;
315 static const char * const cwk_state[] = { "invalid", "valid" };
316 static const char * const nwk_state[] = { "empty", "uncommitted",
317 "committed" };
318
319 memset(&di, 0, sizeof(di));
320
321 if (zq->online)
322 ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
323 AP_QID_QUEUE(zq->queue->qid),
324 &di);
325
326 if (di.cur_wk_state == '0') {
327 n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s -\n",
328 cwk_state[di.cur_wk_state - '0']);
329 } else if (di.cur_wk_state == '1') {
330 n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s 0x",
331 cwk_state[di.cur_wk_state - '0']);
332 bin2hex(buf + n, di.cur_wkvp, sizeof(di.cur_wkvp));
333 n += 2 * sizeof(di.cur_wkvp);
334 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
335 } else
336 n = scnprintf(buf, PAGE_SIZE, "WK CUR: - -\n");
337
338 if (di.new_wk_state == '0') {
339 n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s -\n",
340 nwk_state[di.new_wk_state - '0']);
341 } else if (di.new_wk_state >= '1' && di.new_wk_state <= '2') {
342 n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s 0x",
343 nwk_state[di.new_wk_state - '0']);
344 bin2hex(buf + n, di.new_wkvp, sizeof(di.new_wkvp));
345 n += 2 * sizeof(di.new_wkvp);
346 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
347 } else
348 n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: - -\n");
349
350 return n;
351}
352
353static struct device_attribute dev_attr_ep11_mkvps =
354 __ATTR(mkvps, 0444, ep11_mkvps_show, NULL);
355
356static ssize_t ep11_queue_op_modes_show(struct device *dev,
357 struct device_attribute *attr,
358 char *buf)
359{
360 int i, n = 0;
361 struct ep11_domain_info di;
362 struct zcrypt_queue *zq = to_ap_queue(dev)->private;
363
364 memset(&di, 0, sizeof(di));
365
366 if (zq->online)
367 ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
368 AP_QID_QUEUE(zq->queue->qid),
369 &di);
370
371 for (i = 0; ep11_op_modes[i].mode_txt; i++) {
372 if (di.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
373 if (n > 0)
374 buf[n++] = ' ';
375 n += scnprintf(buf + n, PAGE_SIZE - n,
376 "%s", ep11_op_modes[i].mode_txt);
377 }
378 }
379 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
380
381 return n;
382}
383
384static struct device_attribute dev_attr_ep11_queue_op_modes =
385 __ATTR(op_modes, 0444, ep11_queue_op_modes_show, NULL);
386
387static struct attribute *ep11_queue_attrs[] = {
388 &dev_attr_ep11_mkvps.attr,
389 &dev_attr_ep11_queue_op_modes.attr,
390 NULL,
391};
392
393static const struct attribute_group ep11_queue_attr_grp = {
394 .attrs = ep11_queue_attrs,
395};
396
397
398
399
400
401
402
403static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
404{
405
406
407
408
409 static const int CEX4A_SPEED_IDX[NUM_OPS] = {
410 14, 19, 249, 42, 228, 1458, 0, 0};
411 static const int CEX5A_SPEED_IDX[NUM_OPS] = {
412 8, 9, 20, 18, 66, 458, 0, 0};
413 static const int CEX6A_SPEED_IDX[NUM_OPS] = {
414 6, 9, 20, 17, 65, 438, 0, 0};
415 static const int CEX7A_SPEED_IDX[NUM_OPS] = {
416 6, 8, 17, 15, 54, 362, 0, 0};
417
418 static const int CEX4C_SPEED_IDX[NUM_OPS] = {
419 59, 69, 308, 83, 278, 2204, 209, 40};
420 static const int CEX5C_SPEED_IDX[] = {
421 24, 31, 50, 37, 90, 479, 27, 10};
422 static const int CEX6C_SPEED_IDX[NUM_OPS] = {
423 16, 20, 32, 27, 77, 455, 24, 9};
424 static const int CEX7C_SPEED_IDX[NUM_OPS] = {
425 14, 16, 26, 23, 64, 376, 23, 8};
426
427 static const int CEX4P_SPEED_IDX[NUM_OPS] = {
428 0, 0, 0, 0, 0, 0, 0, 50};
429 static const int CEX5P_SPEED_IDX[NUM_OPS] = {
430 0, 0, 0, 0, 0, 0, 0, 10};
431 static const int CEX6P_SPEED_IDX[NUM_OPS] = {
432 0, 0, 0, 0, 0, 0, 0, 9};
433 static const int CEX7P_SPEED_IDX[NUM_OPS] = {
434 0, 0, 0, 0, 0, 0, 0, 8};
435
436 struct ap_card *ac = to_ap_card(&ap_dev->device);
437 struct zcrypt_card *zc;
438 int rc = 0;
439
440 zc = zcrypt_card_alloc();
441 if (!zc)
442 return -ENOMEM;
443 zc->card = ac;
444 ac->private = zc;
445 if (ap_test_bit(&ac->functions, AP_FUNC_ACCEL)) {
446 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
447 zc->type_string = "CEX4A";
448 zc->user_space_type = ZCRYPT_CEX4;
449 zc->speed_rating = CEX4A_SPEED_IDX;
450 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
451 zc->type_string = "CEX5A";
452 zc->user_space_type = ZCRYPT_CEX5;
453 zc->speed_rating = CEX5A_SPEED_IDX;
454 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
455 zc->type_string = "CEX6A";
456 zc->user_space_type = ZCRYPT_CEX6;
457 zc->speed_rating = CEX6A_SPEED_IDX;
458 } else {
459 zc->type_string = "CEX7A";
460
461
462
463 zc->user_space_type = ZCRYPT_CEX6;
464 zc->speed_rating = CEX7A_SPEED_IDX;
465 }
466 zc->min_mod_size = CEX4A_MIN_MOD_SIZE;
467 if (ap_test_bit(&ac->functions, AP_FUNC_MEX4K) &&
468 ap_test_bit(&ac->functions, AP_FUNC_CRT4K)) {
469 zc->max_mod_size = CEX4A_MAX_MOD_SIZE_4K;
470 zc->max_exp_bit_length =
471 CEX4A_MAX_MOD_SIZE_4K;
472 } else {
473 zc->max_mod_size = CEX4A_MAX_MOD_SIZE_2K;
474 zc->max_exp_bit_length =
475 CEX4A_MAX_MOD_SIZE_2K;
476 }
477 } else if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
478 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
479 zc->type_string = "CEX4C";
480
481
482
483 zc->user_space_type = ZCRYPT_CEX3C;
484 zc->speed_rating = CEX4C_SPEED_IDX;
485 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
486 zc->type_string = "CEX5C";
487
488
489
490 zc->user_space_type = ZCRYPT_CEX3C;
491 zc->speed_rating = CEX5C_SPEED_IDX;
492 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
493 zc->type_string = "CEX6C";
494
495
496
497 zc->user_space_type = ZCRYPT_CEX3C;
498 zc->speed_rating = CEX6C_SPEED_IDX;
499 } else {
500 zc->type_string = "CEX7C";
501
502
503
504 zc->user_space_type = ZCRYPT_CEX3C;
505 zc->speed_rating = CEX7C_SPEED_IDX;
506 }
507 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
508 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
509 zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
510 } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
511 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
512 zc->type_string = "CEX4P";
513 zc->user_space_type = ZCRYPT_CEX4;
514 zc->speed_rating = CEX4P_SPEED_IDX;
515 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
516 zc->type_string = "CEX5P";
517 zc->user_space_type = ZCRYPT_CEX5;
518 zc->speed_rating = CEX5P_SPEED_IDX;
519 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
520 zc->type_string = "CEX6P";
521 zc->user_space_type = ZCRYPT_CEX6;
522 zc->speed_rating = CEX6P_SPEED_IDX;
523 } else {
524 zc->type_string = "CEX7P";
525
526
527
528 zc->user_space_type = ZCRYPT_CEX6;
529 zc->speed_rating = CEX7P_SPEED_IDX;
530 }
531 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
532 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
533 zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
534 } else {
535 zcrypt_card_free(zc);
536 return -ENODEV;
537 }
538 zc->online = 1;
539
540 rc = zcrypt_card_register(zc);
541 if (rc) {
542 ac->private = NULL;
543 zcrypt_card_free(zc);
544 return rc;
545 }
546
547 if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
548 rc = sysfs_create_group(&ap_dev->device.kobj,
549 &cca_card_attr_grp);
550 if (rc) {
551 zcrypt_card_unregister(zc);
552 ac->private = NULL;
553 zcrypt_card_free(zc);
554 }
555 } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
556 rc = sysfs_create_group(&ap_dev->device.kobj,
557 &ep11_card_attr_grp);
558 if (rc) {
559 zcrypt_card_unregister(zc);
560 ac->private = NULL;
561 zcrypt_card_free(zc);
562 }
563 }
564
565 return rc;
566}
567
568
569
570
571
572static void zcrypt_cex4_card_remove(struct ap_device *ap_dev)
573{
574 struct ap_card *ac = to_ap_card(&ap_dev->device);
575 struct zcrypt_card *zc = ac->private;
576
577 if (ap_test_bit(&ac->functions, AP_FUNC_COPRO))
578 sysfs_remove_group(&ap_dev->device.kobj, &cca_card_attr_grp);
579 else if (ap_test_bit(&ac->functions, AP_FUNC_EP11))
580 sysfs_remove_group(&ap_dev->device.kobj, &ep11_card_attr_grp);
581 if (zc)
582 zcrypt_card_unregister(zc);
583}
584
585static struct ap_driver zcrypt_cex4_card_driver = {
586 .probe = zcrypt_cex4_card_probe,
587 .remove = zcrypt_cex4_card_remove,
588 .ids = zcrypt_cex4_card_ids,
589 .flags = AP_DRIVER_FLAG_DEFAULT,
590};
591
592
593
594
595
596
597
598static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
599{
600 struct ap_queue *aq = to_ap_queue(&ap_dev->device);
601 struct zcrypt_queue *zq;
602 int rc;
603
604 if (ap_test_bit(&aq->card->functions, AP_FUNC_ACCEL)) {
605 zq = zcrypt_queue_alloc(aq->card->maxmsgsize);
606 if (!zq)
607 return -ENOMEM;
608 zq->ops = zcrypt_msgtype(MSGTYPE50_NAME,
609 MSGTYPE50_VARIANT_DEFAULT);
610 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
611 zq = zcrypt_queue_alloc(aq->card->maxmsgsize);
612 if (!zq)
613 return -ENOMEM;
614 zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
615 MSGTYPE06_VARIANT_DEFAULT);
616 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
617 zq = zcrypt_queue_alloc(aq->card->maxmsgsize);
618 if (!zq)
619 return -ENOMEM;
620 zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
621 MSGTYPE06_VARIANT_EP11);
622 } else {
623 return -ENODEV;
624 }
625
626 zq->queue = aq;
627 zq->online = 1;
628 atomic_set(&zq->load, 0);
629 ap_queue_init_state(aq);
630 ap_queue_init_reply(aq, &zq->reply);
631 aq->request_timeout = CEX4_CLEANUP_TIME;
632 aq->private = zq;
633 rc = zcrypt_queue_register(zq);
634 if (rc) {
635 aq->private = NULL;
636 zcrypt_queue_free(zq);
637 return rc;
638 }
639
640 if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
641 rc = sysfs_create_group(&ap_dev->device.kobj,
642 &cca_queue_attr_grp);
643 if (rc) {
644 zcrypt_queue_unregister(zq);
645 aq->private = NULL;
646 zcrypt_queue_free(zq);
647 }
648 } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
649 rc = sysfs_create_group(&ap_dev->device.kobj,
650 &ep11_queue_attr_grp);
651 if (rc) {
652 zcrypt_queue_unregister(zq);
653 aq->private = NULL;
654 zcrypt_queue_free(zq);
655 }
656 }
657
658 return rc;
659}
660
661
662
663
664
665static void zcrypt_cex4_queue_remove(struct ap_device *ap_dev)
666{
667 struct ap_queue *aq = to_ap_queue(&ap_dev->device);
668 struct zcrypt_queue *zq = aq->private;
669
670 if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO))
671 sysfs_remove_group(&ap_dev->device.kobj, &cca_queue_attr_grp);
672 else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11))
673 sysfs_remove_group(&ap_dev->device.kobj, &ep11_queue_attr_grp);
674 if (zq)
675 zcrypt_queue_unregister(zq);
676}
677
678static struct ap_driver zcrypt_cex4_queue_driver = {
679 .probe = zcrypt_cex4_queue_probe,
680 .remove = zcrypt_cex4_queue_remove,
681 .ids = zcrypt_cex4_queue_ids,
682 .flags = AP_DRIVER_FLAG_DEFAULT,
683};
684
685int __init zcrypt_cex4_init(void)
686{
687 int rc;
688
689 rc = ap_driver_register(&zcrypt_cex4_card_driver,
690 THIS_MODULE, "cex4card");
691 if (rc)
692 return rc;
693
694 rc = ap_driver_register(&zcrypt_cex4_queue_driver,
695 THIS_MODULE, "cex4queue");
696 if (rc)
697 ap_driver_unregister(&zcrypt_cex4_card_driver);
698
699 return rc;
700}
701
702void __exit zcrypt_cex4_exit(void)
703{
704 ap_driver_unregister(&zcrypt_cex4_queue_driver);
705 ap_driver_unregister(&zcrypt_cex4_card_driver);
706}
707
708module_init(zcrypt_cex4_init);
709module_exit(zcrypt_cex4_exit);
710