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_mk_state
>= '1' && ci
.new_mk_state
<= '3')
125 n
= scnprintf(buf
, PAGE_SIZE
, "AES NEW: %s 0x%016llx\n",
126 new_state
[ci
.new_mk_state
- '1'], ci
.new_mkvp
);
128 n
= scnprintf(buf
, PAGE_SIZE
, "AES NEW: - -\n");
130 if (ci
.cur_mk_state
>= '1' && ci
.cur_mk_state
<= '2')
131 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
,
132 "AES CUR: %s 0x%016llx\n",
133 cao_state
[ci
.cur_mk_state
- '1'], ci
.cur_mkvp
);
135 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "AES CUR: - -\n");
137 if (ci
.old_mk_state
>= '1' && ci
.old_mk_state
<= '2')
138 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
,
139 "AES OLD: %s 0x%016llx\n",
140 cao_state
[ci
.old_mk_state
- '1'], ci
.old_mkvp
);
142 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "AES OLD: - -\n");
147 static struct device_attribute dev_attr_cca_mkvps
=
148 __ATTR(mkvps
, 0444, cca_mkvps_show
, NULL
);
150 static struct attribute
*cca_queue_attrs
[] = {
151 &dev_attr_cca_mkvps
.attr
,
155 static const struct attribute_group cca_queue_attr_grp
= {
156 .attrs
= cca_queue_attrs
,
160 * EP11 card additional device attributes
162 static ssize_t
ep11_api_ordinalnr_show(struct device
*dev
,
163 struct device_attribute
*attr
,
166 struct ep11_card_info ci
;
167 struct ap_card
*ac
= to_ap_card(dev
);
168 struct zcrypt_card
*zc
= ac
->private;
170 memset(&ci
, 0, sizeof(ci
));
172 ep11_get_card_info(ac
->id
, &ci
, zc
->online
);
174 if (ci
.API_ord_nr
> 0)
175 return scnprintf(buf
, PAGE_SIZE
, "%u\n", ci
.API_ord_nr
);
177 return scnprintf(buf
, PAGE_SIZE
, "\n");
180 static struct device_attribute dev_attr_ep11_api_ordinalnr
=
181 __ATTR(API_ordinalnr
, 0444, ep11_api_ordinalnr_show
, NULL
);
183 static ssize_t
ep11_fw_version_show(struct device
*dev
,
184 struct device_attribute
*attr
,
187 struct ep11_card_info ci
;
188 struct ap_card
*ac
= to_ap_card(dev
);
189 struct zcrypt_card
*zc
= ac
->private;
191 memset(&ci
, 0, sizeof(ci
));
193 ep11_get_card_info(ac
->id
, &ci
, zc
->online
);
195 if (ci
.FW_version
> 0)
196 return scnprintf(buf
, PAGE_SIZE
, "%d.%d\n",
197 (int)(ci
.FW_version
>> 8),
198 (int)(ci
.FW_version
& 0xFF));
200 return scnprintf(buf
, PAGE_SIZE
, "\n");
203 static struct device_attribute dev_attr_ep11_fw_version
=
204 __ATTR(FW_version
, 0444, ep11_fw_version_show
, NULL
);
206 static ssize_t
ep11_serialnr_show(struct device
*dev
,
207 struct device_attribute
*attr
,
210 struct ep11_card_info ci
;
211 struct ap_card
*ac
= to_ap_card(dev
);
212 struct zcrypt_card
*zc
= ac
->private;
214 memset(&ci
, 0, sizeof(ci
));
216 ep11_get_card_info(ac
->id
, &ci
, zc
->online
);
219 return scnprintf(buf
, PAGE_SIZE
, "%16.16s\n", ci
.serial
);
221 return scnprintf(buf
, PAGE_SIZE
, "\n");
224 static struct device_attribute dev_attr_ep11_serialnr
=
225 __ATTR(serialnr
, 0444, ep11_serialnr_show
, NULL
);
227 static const struct {
229 const char *mode_txt
;
230 } ep11_op_modes
[] = {
239 static ssize_t
ep11_card_op_modes_show(struct device
*dev
,
240 struct device_attribute
*attr
,
244 struct ep11_card_info ci
;
245 struct ap_card
*ac
= to_ap_card(dev
);
246 struct zcrypt_card
*zc
= ac
->private;
248 memset(&ci
, 0, sizeof(ci
));
250 ep11_get_card_info(ac
->id
, &ci
, zc
->online
);
252 for (i
= 0; ep11_op_modes
[i
].mode_txt
; i
++) {
253 if (ci
.op_mode
& (1 << ep11_op_modes
[i
].mode_bit
)) {
256 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
,
257 "%s", ep11_op_modes
[i
].mode_txt
);
260 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "\n");
265 static struct device_attribute dev_attr_ep11_card_op_modes
=
266 __ATTR(op_modes
, 0444, ep11_card_op_modes_show
, NULL
);
268 static struct attribute
*ep11_card_attrs
[] = {
269 &dev_attr_ep11_api_ordinalnr
.attr
,
270 &dev_attr_ep11_fw_version
.attr
,
271 &dev_attr_ep11_serialnr
.attr
,
272 &dev_attr_ep11_card_op_modes
.attr
,
276 static const struct attribute_group ep11_card_attr_grp
= {
277 .attrs
= ep11_card_attrs
,
281 * EP11 queue additional device attributes
284 static ssize_t
ep11_mkvps_show(struct device
*dev
,
285 struct device_attribute
*attr
,
289 struct ep11_domain_info di
;
290 struct zcrypt_queue
*zq
= to_ap_queue(dev
)->private;
291 static const char * const cwk_state
[] = { "invalid", "valid" };
292 static const char * const nwk_state
[] = { "empty", "uncommitted",
295 memset(&di
, 0, sizeof(di
));
298 ep11_get_domain_info(AP_QID_CARD(zq
->queue
->qid
),
299 AP_QID_QUEUE(zq
->queue
->qid
),
302 if (di
.cur_wk_state
== '0') {
303 n
= scnprintf(buf
, PAGE_SIZE
, "WK CUR: %s -\n",
304 cwk_state
[di
.cur_wk_state
- '0']);
305 } else if (di
.cur_wk_state
== '1') {
306 n
= scnprintf(buf
, PAGE_SIZE
, "WK CUR: %s 0x",
307 cwk_state
[di
.cur_wk_state
- '0']);
308 bin2hex(buf
+ n
, di
.cur_wkvp
, sizeof(di
.cur_wkvp
));
309 n
+= 2 * sizeof(di
.cur_wkvp
);
310 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "\n");
312 n
= scnprintf(buf
, PAGE_SIZE
, "WK CUR: - -\n");
314 if (di
.new_wk_state
== '0') {
315 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "WK NEW: %s -\n",
316 nwk_state
[di
.new_wk_state
- '0']);
317 } else if (di
.new_wk_state
>= '1' && di
.new_wk_state
<= '2') {
318 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "WK NEW: %s 0x",
319 nwk_state
[di
.new_wk_state
- '0']);
320 bin2hex(buf
+ n
, di
.new_wkvp
, sizeof(di
.new_wkvp
));
321 n
+= 2 * sizeof(di
.new_wkvp
);
322 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "\n");
324 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "WK NEW: - -\n");
329 static struct device_attribute dev_attr_ep11_mkvps
=
330 __ATTR(mkvps
, 0444, ep11_mkvps_show
, NULL
);
332 static ssize_t
ep11_queue_op_modes_show(struct device
*dev
,
333 struct device_attribute
*attr
,
337 struct ep11_domain_info di
;
338 struct zcrypt_queue
*zq
= to_ap_queue(dev
)->private;
340 memset(&di
, 0, sizeof(di
));
343 ep11_get_domain_info(AP_QID_CARD(zq
->queue
->qid
),
344 AP_QID_QUEUE(zq
->queue
->qid
),
347 for (i
= 0; ep11_op_modes
[i
].mode_txt
; i
++) {
348 if (di
.op_mode
& (1 << ep11_op_modes
[i
].mode_bit
)) {
351 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
,
352 "%s", ep11_op_modes
[i
].mode_txt
);
355 n
+= scnprintf(buf
+ n
, PAGE_SIZE
- n
, "\n");
360 static struct device_attribute dev_attr_ep11_queue_op_modes
=
361 __ATTR(op_modes
, 0444, ep11_queue_op_modes_show
, NULL
);
363 static struct attribute
*ep11_queue_attrs
[] = {
364 &dev_attr_ep11_mkvps
.attr
,
365 &dev_attr_ep11_queue_op_modes
.attr
,
369 static const struct attribute_group ep11_queue_attr_grp
= {
370 .attrs
= ep11_queue_attrs
,
374 * Probe function for CEX4/CEX5/CEX6/CEX7 card device. It always
375 * accepts the AP device since the bus_match already checked
377 * @ap_dev: pointer to the AP device.
379 static int zcrypt_cex4_card_probe(struct ap_device
*ap_dev
)
382 * Normalized speed ratings per crypto adapter
383 * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY
385 static const int CEX4A_SPEED_IDX
[] = {
386 14, 19, 249, 42, 228, 1458, 0, 0};
387 static const int CEX5A_SPEED_IDX
[] = {
388 8, 9, 20, 18, 66, 458, 0, 0};
389 static const int CEX6A_SPEED_IDX
[] = {
390 6, 9, 20, 17, 65, 438, 0, 0};
391 static const int CEX7A_SPEED_IDX
[] = {
392 6, 8, 17, 15, 54, 362, 0, 0};
394 static const int CEX4C_SPEED_IDX
[] = {
395 59, 69, 308, 83, 278, 2204, 209, 40};
396 static const int CEX5C_SPEED_IDX
[] = {
397 24, 31, 50, 37, 90, 479, 27, 10};
398 static const int CEX6C_SPEED_IDX
[] = {
399 16, 20, 32, 27, 77, 455, 24, 9};
400 static const int CEX7C_SPEED_IDX
[] = {
401 14, 16, 26, 23, 64, 376, 23, 8};
403 static const int CEX4P_SPEED_IDX
[] = {
404 0, 0, 0, 0, 0, 0, 0, 50};
405 static const int CEX5P_SPEED_IDX
[] = {
406 0, 0, 0, 0, 0, 0, 0, 10};
407 static const int CEX6P_SPEED_IDX
[] = {
408 0, 0, 0, 0, 0, 0, 0, 9};
409 static const int CEX7P_SPEED_IDX
[] = {
410 0, 0, 0, 0, 0, 0, 0, 8};
412 struct ap_card
*ac
= to_ap_card(&ap_dev
->device
);
413 struct zcrypt_card
*zc
;
416 zc
= zcrypt_card_alloc();
421 if (ap_test_bit(&ac
->functions
, AP_FUNC_ACCEL
)) {
422 if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX4
) {
423 zc
->type_string
= "CEX4A";
424 zc
->user_space_type
= ZCRYPT_CEX4
;
425 memcpy(zc
->speed_rating
, CEX4A_SPEED_IDX
,
426 sizeof(CEX4A_SPEED_IDX
));
427 } else if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX5
) {
428 zc
->type_string
= "CEX5A";
429 zc
->user_space_type
= ZCRYPT_CEX5
;
430 memcpy(zc
->speed_rating
, CEX5A_SPEED_IDX
,
431 sizeof(CEX5A_SPEED_IDX
));
432 } else if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX6
) {
433 zc
->type_string
= "CEX6A";
434 zc
->user_space_type
= ZCRYPT_CEX6
;
435 memcpy(zc
->speed_rating
, CEX6A_SPEED_IDX
,
436 sizeof(CEX6A_SPEED_IDX
));
438 zc
->type_string
= "CEX7A";
439 /* wrong user space type, just for compatibility
440 * with the ZCRYPT_STATUS_MASK ioctl.
442 zc
->user_space_type
= ZCRYPT_CEX6
;
443 memcpy(zc
->speed_rating
, CEX7A_SPEED_IDX
,
444 sizeof(CEX7A_SPEED_IDX
));
446 zc
->min_mod_size
= CEX4A_MIN_MOD_SIZE
;
447 if (ap_test_bit(&ac
->functions
, AP_FUNC_MEX4K
) &&
448 ap_test_bit(&ac
->functions
, AP_FUNC_CRT4K
)) {
449 zc
->max_mod_size
= CEX4A_MAX_MOD_SIZE_4K
;
450 zc
->max_exp_bit_length
=
451 CEX4A_MAX_MOD_SIZE_4K
;
453 zc
->max_mod_size
= CEX4A_MAX_MOD_SIZE_2K
;
454 zc
->max_exp_bit_length
=
455 CEX4A_MAX_MOD_SIZE_2K
;
457 } else if (ap_test_bit(&ac
->functions
, AP_FUNC_COPRO
)) {
458 if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX4
) {
459 zc
->type_string
= "CEX4C";
460 /* wrong user space type, must be CEX4
461 * just keep it for cca compatibility
463 zc
->user_space_type
= ZCRYPT_CEX3C
;
464 memcpy(zc
->speed_rating
, CEX4C_SPEED_IDX
,
465 sizeof(CEX4C_SPEED_IDX
));
466 } else if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX5
) {
467 zc
->type_string
= "CEX5C";
468 /* wrong user space type, must be CEX5
469 * just keep it for cca compatibility
471 zc
->user_space_type
= ZCRYPT_CEX3C
;
472 memcpy(zc
->speed_rating
, CEX5C_SPEED_IDX
,
473 sizeof(CEX5C_SPEED_IDX
));
474 } else if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX6
) {
475 zc
->type_string
= "CEX6C";
476 /* wrong user space type, must be CEX6
477 * just keep it for cca compatibility
479 zc
->user_space_type
= ZCRYPT_CEX3C
;
480 memcpy(zc
->speed_rating
, CEX6C_SPEED_IDX
,
481 sizeof(CEX6C_SPEED_IDX
));
483 zc
->type_string
= "CEX7C";
484 /* wrong user space type, must be CEX7
485 * just keep it for cca compatibility
487 zc
->user_space_type
= ZCRYPT_CEX3C
;
488 memcpy(zc
->speed_rating
, CEX7C_SPEED_IDX
,
489 sizeof(CEX7C_SPEED_IDX
));
491 zc
->min_mod_size
= CEX4C_MIN_MOD_SIZE
;
492 zc
->max_mod_size
= CEX4C_MAX_MOD_SIZE
;
493 zc
->max_exp_bit_length
= CEX4C_MAX_MOD_SIZE
;
494 } else if (ap_test_bit(&ac
->functions
, AP_FUNC_EP11
)) {
495 if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX4
) {
496 zc
->type_string
= "CEX4P";
497 zc
->user_space_type
= ZCRYPT_CEX4
;
498 memcpy(zc
->speed_rating
, CEX4P_SPEED_IDX
,
499 sizeof(CEX4P_SPEED_IDX
));
500 } else if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX5
) {
501 zc
->type_string
= "CEX5P";
502 zc
->user_space_type
= ZCRYPT_CEX5
;
503 memcpy(zc
->speed_rating
, CEX5P_SPEED_IDX
,
504 sizeof(CEX5P_SPEED_IDX
));
505 } else if (ac
->ap_dev
.device_type
== AP_DEVICE_TYPE_CEX6
) {
506 zc
->type_string
= "CEX6P";
507 zc
->user_space_type
= ZCRYPT_CEX6
;
508 memcpy(zc
->speed_rating
, CEX6P_SPEED_IDX
,
509 sizeof(CEX6P_SPEED_IDX
));
511 zc
->type_string
= "CEX7P";
512 /* wrong user space type, just for compatibility
513 * with the ZCRYPT_STATUS_MASK ioctl.
515 zc
->user_space_type
= ZCRYPT_CEX6
;
516 memcpy(zc
->speed_rating
, CEX7P_SPEED_IDX
,
517 sizeof(CEX7P_SPEED_IDX
));
519 zc
->min_mod_size
= CEX4C_MIN_MOD_SIZE
;
520 zc
->max_mod_size
= CEX4C_MAX_MOD_SIZE
;
521 zc
->max_exp_bit_length
= CEX4C_MAX_MOD_SIZE
;
523 zcrypt_card_free(zc
);
528 rc
= zcrypt_card_register(zc
);
531 zcrypt_card_free(zc
);
535 if (ap_test_bit(&ac
->functions
, AP_FUNC_COPRO
)) {
536 rc
= sysfs_create_group(&ap_dev
->device
.kobj
,
539 zcrypt_card_unregister(zc
);
540 } else if (ap_test_bit(&ac
->functions
, AP_FUNC_EP11
)) {
541 rc
= sysfs_create_group(&ap_dev
->device
.kobj
,
542 &ep11_card_attr_grp
);
544 zcrypt_card_unregister(zc
);
552 * This is called to remove the CEX4/CEX5/CEX6/CEX7 card driver
553 * information if an AP card device is removed.
555 static void zcrypt_cex4_card_remove(struct ap_device
*ap_dev
)
557 struct ap_card
*ac
= to_ap_card(&ap_dev
->device
);
558 struct zcrypt_card
*zc
= ac
->private;
560 if (ap_test_bit(&ac
->functions
, AP_FUNC_COPRO
))
561 sysfs_remove_group(&ap_dev
->device
.kobj
, &cca_card_attr_grp
);
562 else if (ap_test_bit(&ac
->functions
, AP_FUNC_EP11
))
563 sysfs_remove_group(&ap_dev
->device
.kobj
, &ep11_card_attr_grp
);
565 zcrypt_card_unregister(zc
);
568 static struct ap_driver zcrypt_cex4_card_driver
= {
569 .probe
= zcrypt_cex4_card_probe
,
570 .remove
= zcrypt_cex4_card_remove
,
571 .ids
= zcrypt_cex4_card_ids
,
572 .flags
= AP_DRIVER_FLAG_DEFAULT
,
576 * Probe function for CEX4/CEX5/CEX6/CEX7 queue device. It always
577 * accepts the AP device since the bus_match already checked
579 * @ap_dev: pointer to the AP device.
581 static int zcrypt_cex4_queue_probe(struct ap_device
*ap_dev
)
583 struct ap_queue
*aq
= to_ap_queue(&ap_dev
->device
);
584 struct zcrypt_queue
*zq
;
587 if (ap_test_bit(&aq
->card
->functions
, AP_FUNC_ACCEL
)) {
588 zq
= zcrypt_queue_alloc(CEX4A_MAX_MESSAGE_SIZE
);
591 zq
->ops
= zcrypt_msgtype(MSGTYPE50_NAME
,
592 MSGTYPE50_VARIANT_DEFAULT
);
593 } else if (ap_test_bit(&aq
->card
->functions
, AP_FUNC_COPRO
)) {
594 zq
= zcrypt_queue_alloc(CEX4C_MAX_MESSAGE_SIZE
);
597 zq
->ops
= zcrypt_msgtype(MSGTYPE06_NAME
,
598 MSGTYPE06_VARIANT_DEFAULT
);
599 } else if (ap_test_bit(&aq
->card
->functions
, AP_FUNC_EP11
)) {
600 zq
= zcrypt_queue_alloc(CEX4C_MAX_MESSAGE_SIZE
);
603 zq
->ops
= zcrypt_msgtype(MSGTYPE06_NAME
,
604 MSGTYPE06_VARIANT_EP11
);
611 atomic_set(&zq
->load
, 0);
612 ap_queue_init_state(aq
);
613 ap_queue_init_reply(aq
, &zq
->reply
);
614 aq
->request_timeout
= CEX4_CLEANUP_TIME
,
616 rc
= zcrypt_queue_register(zq
);
619 zcrypt_queue_free(zq
);
623 if (ap_test_bit(&aq
->card
->functions
, AP_FUNC_COPRO
)) {
624 rc
= sysfs_create_group(&ap_dev
->device
.kobj
,
625 &cca_queue_attr_grp
);
627 zcrypt_queue_unregister(zq
);
628 } else if (ap_test_bit(&aq
->card
->functions
, AP_FUNC_EP11
)) {
629 rc
= sysfs_create_group(&ap_dev
->device
.kobj
,
630 &ep11_queue_attr_grp
);
632 zcrypt_queue_unregister(zq
);
640 * This is called to remove the CEX4/CEX5/CEX6/CEX7 queue driver
641 * information if an AP queue device is removed.
643 static void zcrypt_cex4_queue_remove(struct ap_device
*ap_dev
)
645 struct ap_queue
*aq
= to_ap_queue(&ap_dev
->device
);
646 struct zcrypt_queue
*zq
= aq
->private;
648 if (ap_test_bit(&aq
->card
->functions
, AP_FUNC_COPRO
))
649 sysfs_remove_group(&ap_dev
->device
.kobj
, &cca_queue_attr_grp
);
650 else if (ap_test_bit(&aq
->card
->functions
, AP_FUNC_EP11
))
651 sysfs_remove_group(&ap_dev
->device
.kobj
, &ep11_queue_attr_grp
);
653 zcrypt_queue_unregister(zq
);
656 static struct ap_driver zcrypt_cex4_queue_driver
= {
657 .probe
= zcrypt_cex4_queue_probe
,
658 .remove
= zcrypt_cex4_queue_remove
,
659 .ids
= zcrypt_cex4_queue_ids
,
660 .flags
= AP_DRIVER_FLAG_DEFAULT
,
663 int __init
zcrypt_cex4_init(void)
667 rc
= ap_driver_register(&zcrypt_cex4_card_driver
,
668 THIS_MODULE
, "cex4card");
672 rc
= ap_driver_register(&zcrypt_cex4_queue_driver
,
673 THIS_MODULE
, "cex4queue");
675 ap_driver_unregister(&zcrypt_cex4_card_driver
);
680 void __exit
zcrypt_cex4_exit(void)
682 ap_driver_unregister(&zcrypt_cex4_queue_driver
);
683 ap_driver_unregister(&zcrypt_cex4_card_driver
);
686 module_init(zcrypt_cex4_init
);
687 module_exit(zcrypt_cex4_exit
);