hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/s390/crypto/zcrypt_cex4.c
....@@ -1,6 +1,6 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /*
3
- * Copyright IBM Corp. 2012
3
+ * Copyright IBM Corp. 2012, 2019
44 * Author(s): Holger Dengler <hd@linux.vnet.ibm.com>
55 */
66
....@@ -18,6 +18,8 @@
1818 #include "zcrypt_msgtype50.h"
1919 #include "zcrypt_error.h"
2020 #include "zcrypt_cex4.h"
21
+#include "zcrypt_ccamisc.h"
22
+#include "zcrypt_ep11misc.h"
2123
2224 #define CEX4A_MIN_MOD_SIZE 1 /* 8 bits */
2325 #define CEX4A_MAX_MOD_SIZE_2K 256 /* 2048 bits */
....@@ -37,8 +39,8 @@
3739 #define CEX4_CLEANUP_TIME (900*HZ)
3840
3941 MODULE_AUTHOR("IBM Corporation");
40
-MODULE_DESCRIPTION("CEX4 Cryptographic Card device driver, " \
41
- "Copyright IBM Corp. 2012");
42
+MODULE_DESCRIPTION("CEX4/CEX5/CEX6/CEX7 Cryptographic Card device driver, " \
43
+ "Copyright IBM Corp. 2019");
4244 MODULE_LICENSE("GPL");
4345
4446 static struct ap_device_id zcrypt_cex4_card_ids[] = {
....@@ -47,6 +49,8 @@
4749 { .dev_type = AP_DEVICE_TYPE_CEX5,
4850 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
4951 { .dev_type = AP_DEVICE_TYPE_CEX6,
52
+ .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
53
+ { .dev_type = AP_DEVICE_TYPE_CEX7,
5054 .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
5155 { /* end of list */ },
5256 };
....@@ -60,14 +64,343 @@
6064 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
6165 { .dev_type = AP_DEVICE_TYPE_CEX6,
6266 .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
67
+ { .dev_type = AP_DEVICE_TYPE_CEX7,
68
+ .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
6369 { /* end of list */ },
6470 };
6571
6672 MODULE_DEVICE_TABLE(ap, zcrypt_cex4_queue_ids);
6773
74
+/*
75
+ * CCA card additional device attributes
76
+ */
77
+static ssize_t cca_serialnr_show(struct device *dev,
78
+ struct device_attribute *attr,
79
+ char *buf)
80
+{
81
+ struct cca_info ci;
82
+ struct ap_card *ac = to_ap_card(dev);
83
+ struct zcrypt_card *zc = ac->private;
84
+
85
+ memset(&ci, 0, sizeof(ci));
86
+
87
+ if (ap_domain_index >= 0)
88
+ cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
89
+
90
+ return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial);
91
+}
92
+
93
+static struct device_attribute dev_attr_cca_serialnr =
94
+ __ATTR(serialnr, 0444, cca_serialnr_show, NULL);
95
+
96
+static struct attribute *cca_card_attrs[] = {
97
+ &dev_attr_cca_serialnr.attr,
98
+ NULL,
99
+};
100
+
101
+static const struct attribute_group cca_card_attr_grp = {
102
+ .attrs = cca_card_attrs,
103
+};
104
+
105
+ /*
106
+ * CCA queue additional device attributes
107
+ */
108
+static ssize_t cca_mkvps_show(struct device *dev,
109
+ struct device_attribute *attr,
110
+ char *buf)
111
+{
112
+ int n = 0;
113
+ struct cca_info ci;
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" };
117
+
118
+ memset(&ci, 0, sizeof(ci));
119
+
120
+ cca_get_info(AP_QID_CARD(zq->queue->qid),
121
+ AP_QID_QUEUE(zq->queue->qid),
122
+ &ci, zq->online);
123
+
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'],
127
+ ci.new_aes_mkvp);
128
+ else
129
+ n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n");
130
+
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'],
135
+ ci.cur_aes_mkvp);
136
+ else
137
+ n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n");
138
+
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'],
143
+ ci.old_aes_mkvp);
144
+ else
145
+ n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n");
146
+
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'],
151
+ ci.new_apka_mkvp);
152
+ else
153
+ n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n");
154
+
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'],
159
+ ci.cur_apka_mkvp);
160
+ else
161
+ n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n");
162
+
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'],
167
+ ci.old_apka_mkvp);
168
+ else
169
+ n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n");
170
+
171
+ return n;
172
+}
173
+
174
+static struct device_attribute dev_attr_cca_mkvps =
175
+ __ATTR(mkvps, 0444, cca_mkvps_show, NULL);
176
+
177
+static struct attribute *cca_queue_attrs[] = {
178
+ &dev_attr_cca_mkvps.attr,
179
+ NULL,
180
+};
181
+
182
+static const struct attribute_group cca_queue_attr_grp = {
183
+ .attrs = cca_queue_attrs,
184
+};
185
+
186
+/*
187
+ * EP11 card additional device attributes
188
+ */
189
+static ssize_t ep11_api_ordinalnr_show(struct device *dev,
190
+ struct device_attribute *attr,
191
+ char *buf)
192
+{
193
+ struct ep11_card_info ci;
194
+ struct ap_card *ac = to_ap_card(dev);
195
+ struct zcrypt_card *zc = ac->private;
196
+
197
+ memset(&ci, 0, sizeof(ci));
198
+
199
+ ep11_get_card_info(ac->id, &ci, zc->online);
200
+
201
+ if (ci.API_ord_nr > 0)
202
+ return scnprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr);
203
+ else
204
+ return scnprintf(buf, PAGE_SIZE, "\n");
205
+}
206
+
207
+static struct device_attribute dev_attr_ep11_api_ordinalnr =
208
+ __ATTR(API_ordinalnr, 0444, ep11_api_ordinalnr_show, NULL);
209
+
210
+static ssize_t ep11_fw_version_show(struct device *dev,
211
+ struct device_attribute *attr,
212
+ char *buf)
213
+{
214
+ struct ep11_card_info ci;
215
+ struct ap_card *ac = to_ap_card(dev);
216
+ struct zcrypt_card *zc = ac->private;
217
+
218
+ memset(&ci, 0, sizeof(ci));
219
+
220
+ ep11_get_card_info(ac->id, &ci, zc->online);
221
+
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));
226
+ else
227
+ return scnprintf(buf, PAGE_SIZE, "\n");
228
+}
229
+
230
+static struct device_attribute dev_attr_ep11_fw_version =
231
+ __ATTR(FW_version, 0444, ep11_fw_version_show, NULL);
232
+
233
+static ssize_t ep11_serialnr_show(struct device *dev,
234
+ struct device_attribute *attr,
235
+ char *buf)
236
+{
237
+ struct ep11_card_info ci;
238
+ struct ap_card *ac = to_ap_card(dev);
239
+ struct zcrypt_card *zc = ac->private;
240
+
241
+ memset(&ci, 0, sizeof(ci));
242
+
243
+ ep11_get_card_info(ac->id, &ci, zc->online);
244
+
245
+ if (ci.serial[0])
246
+ return scnprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial);
247
+ else
248
+ return scnprintf(buf, PAGE_SIZE, "\n");
249
+}
250
+
251
+static struct device_attribute dev_attr_ep11_serialnr =
252
+ __ATTR(serialnr, 0444, ep11_serialnr_show, NULL);
253
+
254
+static const struct {
255
+ int mode_bit;
256
+ const char *mode_txt;
257
+} ep11_op_modes[] = {
258
+ { 0, "FIPS2009" },
259
+ { 1, "BSI2009" },
260
+ { 2, "FIPS2011" },
261
+ { 3, "BSI2011" },
262
+ { 6, "BSICC2017" },
263
+ { 0, NULL }
264
+};
265
+
266
+static ssize_t ep11_card_op_modes_show(struct device *dev,
267
+ struct device_attribute *attr,
268
+ char *buf)
269
+{
270
+ int i, n = 0;
271
+ struct ep11_card_info ci;
272
+ struct ap_card *ac = to_ap_card(dev);
273
+ struct zcrypt_card *zc = ac->private;
274
+
275
+ memset(&ci, 0, sizeof(ci));
276
+
277
+ ep11_get_card_info(ac->id, &ci, zc->online);
278
+
279
+ for (i = 0; ep11_op_modes[i].mode_txt; i++) {
280
+ if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
281
+ if (n > 0)
282
+ buf[n++] = ' ';
283
+ n += scnprintf(buf + n, PAGE_SIZE - n,
284
+ "%s", ep11_op_modes[i].mode_txt);
285
+ }
286
+ }
287
+ n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
288
+
289
+ return n;
290
+}
291
+
292
+static struct device_attribute dev_attr_ep11_card_op_modes =
293
+ __ATTR(op_modes, 0444, ep11_card_op_modes_show, NULL);
294
+
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,
300
+ NULL,
301
+};
302
+
303
+static const struct attribute_group ep11_card_attr_grp = {
304
+ .attrs = ep11_card_attrs,
305
+};
306
+
307
+/*
308
+ * EP11 queue additional device attributes
309
+ */
310
+
311
+static ssize_t ep11_mkvps_show(struct device *dev,
312
+ struct device_attribute *attr,
313
+ char *buf)
314
+{
315
+ int n = 0;
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",
320
+ "committed" };
321
+
322
+ memset(&di, 0, sizeof(di));
323
+
324
+ if (zq->online)
325
+ ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
326
+ AP_QID_QUEUE(zq->queue->qid),
327
+ &di);
328
+
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");
338
+ } else
339
+ n = scnprintf(buf, PAGE_SIZE, "WK CUR: - -\n");
340
+
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");
350
+ } else
351
+ n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: - -\n");
352
+
353
+ return n;
354
+}
355
+
356
+static struct device_attribute dev_attr_ep11_mkvps =
357
+ __ATTR(mkvps, 0444, ep11_mkvps_show, NULL);
358
+
359
+static ssize_t ep11_queue_op_modes_show(struct device *dev,
360
+ struct device_attribute *attr,
361
+ char *buf)
362
+{
363
+ int i, n = 0;
364
+ struct ep11_domain_info di;
365
+ struct zcrypt_queue *zq = to_ap_queue(dev)->private;
366
+
367
+ memset(&di, 0, sizeof(di));
368
+
369
+ if (zq->online)
370
+ ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
371
+ AP_QID_QUEUE(zq->queue->qid),
372
+ &di);
373
+
374
+ for (i = 0; ep11_op_modes[i].mode_txt; i++) {
375
+ if (di.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
376
+ if (n > 0)
377
+ buf[n++] = ' ';
378
+ n += scnprintf(buf + n, PAGE_SIZE - n,
379
+ "%s", ep11_op_modes[i].mode_txt);
380
+ }
381
+ }
382
+ n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
383
+
384
+ return n;
385
+}
386
+
387
+static struct device_attribute dev_attr_ep11_queue_op_modes =
388
+ __ATTR(op_modes, 0444, ep11_queue_op_modes_show, NULL);
389
+
390
+static struct attribute *ep11_queue_attrs[] = {
391
+ &dev_attr_ep11_mkvps.attr,
392
+ &dev_attr_ep11_queue_op_modes.attr,
393
+ NULL,
394
+};
395
+
396
+static const struct attribute_group ep11_queue_attr_grp = {
397
+ .attrs = ep11_queue_attrs,
398
+};
399
+
68400 /**
69
- * Probe function for CEX4 card device. It always accepts the AP device
70
- * since the bus_match already checked the hardware type.
401
+ * Probe function for CEX4/CEX5/CEX6/CEX7 card device. It always
402
+ * accepts the AP device since the bus_match already checked
403
+ * the hardware type.
71404 * @ap_dev: pointer to the AP device.
72405 */
73406 static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
....@@ -76,26 +409,32 @@
76409 * Normalized speed ratings per crypto adapter
77410 * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY
78411 */
79
- static const int CEX4A_SPEED_IDX[] = {
80
- 14, 19, 249, 42, 228, 1458, 0, 0};
81
- static const int CEX5A_SPEED_IDX[] = {
82
- 8, 9, 20, 18, 66, 458, 0, 0};
83
- static const int CEX6A_SPEED_IDX[] = {
84
- 6, 9, 20, 17, 65, 438, 0, 0};
412
+ static const int CEX4A_SPEED_IDX[NUM_OPS] = {
413
+ 14, 19, 249, 42, 228, 1458, 0, 0};
414
+ static const int CEX5A_SPEED_IDX[NUM_OPS] = {
415
+ 8, 9, 20, 18, 66, 458, 0, 0};
416
+ static const int CEX6A_SPEED_IDX[NUM_OPS] = {
417
+ 6, 9, 20, 17, 65, 438, 0, 0};
418
+ static const int CEX7A_SPEED_IDX[NUM_OPS] = {
419
+ 6, 8, 17, 15, 54, 362, 0, 0};
85420
86
- static const int CEX4C_SPEED_IDX[] = {
421
+ static const int CEX4C_SPEED_IDX[NUM_OPS] = {
87422 59, 69, 308, 83, 278, 2204, 209, 40};
88423 static const int CEX5C_SPEED_IDX[] = {
89
- 24, 31, 50, 37, 90, 479, 27, 10};
90
- static const int CEX6C_SPEED_IDX[] = {
91
- 16, 20, 32, 27, 77, 455, 23, 9};
424
+ 24, 31, 50, 37, 90, 479, 27, 10};
425
+ static const int CEX6C_SPEED_IDX[NUM_OPS] = {
426
+ 16, 20, 32, 27, 77, 455, 24, 9};
427
+ static const int CEX7C_SPEED_IDX[NUM_OPS] = {
428
+ 14, 16, 26, 23, 64, 376, 23, 8};
92429
93
- static const int CEX4P_SPEED_IDX[] = {
94
- 224, 313, 3560, 359, 605, 2827, 0, 50};
95
- static const int CEX5P_SPEED_IDX[] = {
96
- 63, 84, 156, 83, 142, 533, 0, 10};
97
- static const int CEX6P_SPEED_IDX[] = {
98
- 55, 70, 121, 73, 129, 522, 0, 9};
430
+ static const int CEX4P_SPEED_IDX[NUM_OPS] = {
431
+ 0, 0, 0, 0, 0, 0, 0, 50};
432
+ static const int CEX5P_SPEED_IDX[NUM_OPS] = {
433
+ 0, 0, 0, 0, 0, 0, 0, 10};
434
+ static const int CEX6P_SPEED_IDX[NUM_OPS] = {
435
+ 0, 0, 0, 0, 0, 0, 0, 9};
436
+ static const int CEX7P_SPEED_IDX[NUM_OPS] = {
437
+ 0, 0, 0, 0, 0, 0, 0, 8};
99438
100439 struct ap_card *ac = to_ap_card(&ap_dev->device);
101440 struct zcrypt_card *zc;
....@@ -110,18 +449,22 @@
110449 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
111450 zc->type_string = "CEX4A";
112451 zc->user_space_type = ZCRYPT_CEX4;
113
- memcpy(zc->speed_rating, CEX4A_SPEED_IDX,
114
- sizeof(CEX4A_SPEED_IDX));
452
+ zc->speed_rating = CEX4A_SPEED_IDX;
115453 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
116454 zc->type_string = "CEX5A";
117455 zc->user_space_type = ZCRYPT_CEX5;
118
- memcpy(zc->speed_rating, CEX5A_SPEED_IDX,
119
- sizeof(CEX5A_SPEED_IDX));
120
- } else {
456
+ zc->speed_rating = CEX5A_SPEED_IDX;
457
+ } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
121458 zc->type_string = "CEX6A";
122459 zc->user_space_type = ZCRYPT_CEX6;
123
- memcpy(zc->speed_rating, CEX6A_SPEED_IDX,
124
- sizeof(CEX6A_SPEED_IDX));
460
+ zc->speed_rating = CEX6A_SPEED_IDX;
461
+ } else {
462
+ zc->type_string = "CEX7A";
463
+ /* wrong user space type, just for compatibility
464
+ * with the ZCRYPT_STATUS_MASK ioctl.
465
+ */
466
+ zc->user_space_type = ZCRYPT_CEX6;
467
+ zc->speed_rating = CEX7A_SPEED_IDX;
125468 }
126469 zc->min_mod_size = CEX4A_MIN_MOD_SIZE;
127470 if (ap_test_bit(&ac->functions, AP_FUNC_MEX4K) &&
....@@ -141,24 +484,28 @@
141484 * just keep it for cca compatibility
142485 */
143486 zc->user_space_type = ZCRYPT_CEX3C;
144
- memcpy(zc->speed_rating, CEX4C_SPEED_IDX,
145
- sizeof(CEX4C_SPEED_IDX));
487
+ zc->speed_rating = CEX4C_SPEED_IDX;
146488 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
147489 zc->type_string = "CEX5C";
148490 /* wrong user space type, must be CEX5
149491 * just keep it for cca compatibility
150492 */
151493 zc->user_space_type = ZCRYPT_CEX3C;
152
- memcpy(zc->speed_rating, CEX5C_SPEED_IDX,
153
- sizeof(CEX5C_SPEED_IDX));
154
- } else {
494
+ zc->speed_rating = CEX5C_SPEED_IDX;
495
+ } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
155496 zc->type_string = "CEX6C";
156497 /* wrong user space type, must be CEX6
157498 * just keep it for cca compatibility
158499 */
159500 zc->user_space_type = ZCRYPT_CEX3C;
160
- memcpy(zc->speed_rating, CEX6C_SPEED_IDX,
161
- sizeof(CEX6C_SPEED_IDX));
501
+ zc->speed_rating = CEX6C_SPEED_IDX;
502
+ } else {
503
+ zc->type_string = "CEX7C";
504
+ /* wrong user space type, must be CEX7
505
+ * just keep it for cca compatibility
506
+ */
507
+ zc->user_space_type = ZCRYPT_CEX3C;
508
+ zc->speed_rating = CEX7C_SPEED_IDX;
162509 }
163510 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
164511 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
....@@ -167,18 +514,22 @@
167514 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
168515 zc->type_string = "CEX4P";
169516 zc->user_space_type = ZCRYPT_CEX4;
170
- memcpy(zc->speed_rating, CEX4P_SPEED_IDX,
171
- sizeof(CEX4P_SPEED_IDX));
517
+ zc->speed_rating = CEX4P_SPEED_IDX;
172518 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
173519 zc->type_string = "CEX5P";
174520 zc->user_space_type = ZCRYPT_CEX5;
175
- memcpy(zc->speed_rating, CEX5P_SPEED_IDX,
176
- sizeof(CEX5P_SPEED_IDX));
177
- } else {
521
+ zc->speed_rating = CEX5P_SPEED_IDX;
522
+ } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
178523 zc->type_string = "CEX6P";
179524 zc->user_space_type = ZCRYPT_CEX6;
180
- memcpy(zc->speed_rating, CEX6P_SPEED_IDX,
181
- sizeof(CEX6P_SPEED_IDX));
525
+ zc->speed_rating = CEX6P_SPEED_IDX;
526
+ } else {
527
+ zc->type_string = "CEX7P";
528
+ /* wrong user space type, just for compatibility
529
+ * with the ZCRYPT_STATUS_MASK ioctl.
530
+ */
531
+ zc->user_space_type = ZCRYPT_CEX6;
532
+ zc->speed_rating = CEX7P_SPEED_IDX;
182533 }
183534 zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
184535 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
....@@ -193,19 +544,43 @@
193544 if (rc) {
194545 ac->private = NULL;
195546 zcrypt_card_free(zc);
547
+ return rc;
548
+ }
549
+
550
+ if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
551
+ rc = sysfs_create_group(&ap_dev->device.kobj,
552
+ &cca_card_attr_grp);
553
+ if (rc) {
554
+ zcrypt_card_unregister(zc);
555
+ ac->private = NULL;
556
+ zcrypt_card_free(zc);
557
+ }
558
+ } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
559
+ rc = sysfs_create_group(&ap_dev->device.kobj,
560
+ &ep11_card_attr_grp);
561
+ if (rc) {
562
+ zcrypt_card_unregister(zc);
563
+ ac->private = NULL;
564
+ zcrypt_card_free(zc);
565
+ }
196566 }
197567
198568 return rc;
199569 }
200570
201571 /**
202
- * This is called to remove the CEX4 card driver information
203
- * if an AP card device is removed.
572
+ * This is called to remove the CEX4/CEX5/CEX6/CEX7 card driver
573
+ * information if an AP card device is removed.
204574 */
205575 static void zcrypt_cex4_card_remove(struct ap_device *ap_dev)
206576 {
207
- struct zcrypt_card *zc = to_ap_card(&ap_dev->device)->private;
577
+ struct ap_card *ac = to_ap_card(&ap_dev->device);
578
+ struct zcrypt_card *zc = ac->private;
208579
580
+ if (ap_test_bit(&ac->functions, AP_FUNC_COPRO))
581
+ sysfs_remove_group(&ap_dev->device.kobj, &cca_card_attr_grp);
582
+ else if (ap_test_bit(&ac->functions, AP_FUNC_EP11))
583
+ sysfs_remove_group(&ap_dev->device.kobj, &ep11_card_attr_grp);
209584 if (zc)
210585 zcrypt_card_unregister(zc);
211586 }
....@@ -218,8 +593,9 @@
218593 };
219594
220595 /**
221
- * Probe function for CEX4 queue device. It always accepts the AP device
222
- * since the bus_match already checked the hardware type.
596
+ * Probe function for CEX4/CEX5/CEX6/CEX7 queue device. It always
597
+ * accepts the AP device since the bus_match already checked
598
+ * the hardware type.
223599 * @ap_dev: pointer to the AP device.
224600 */
225601 static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
....@@ -249,9 +625,11 @@
249625 } else {
250626 return -ENODEV;
251627 }
628
+
252629 zq->queue = aq;
253630 zq->online = 1;
254631 atomic_set(&zq->load, 0);
632
+ ap_queue_init_state(aq);
255633 ap_queue_init_reply(aq, &zq->reply);
256634 aq->request_timeout = CEX4_CLEANUP_TIME,
257635 aq->private = zq;
....@@ -259,20 +637,43 @@
259637 if (rc) {
260638 aq->private = NULL;
261639 zcrypt_queue_free(zq);
640
+ return rc;
641
+ }
642
+
643
+ if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
644
+ rc = sysfs_create_group(&ap_dev->device.kobj,
645
+ &cca_queue_attr_grp);
646
+ if (rc) {
647
+ zcrypt_queue_unregister(zq);
648
+ aq->private = NULL;
649
+ zcrypt_queue_free(zq);
650
+ }
651
+ } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
652
+ rc = sysfs_create_group(&ap_dev->device.kobj,
653
+ &ep11_queue_attr_grp);
654
+ if (rc) {
655
+ zcrypt_queue_unregister(zq);
656
+ aq->private = NULL;
657
+ zcrypt_queue_free(zq);
658
+ }
262659 }
263660
264661 return rc;
265662 }
266663
267664 /**
268
- * This is called to remove the CEX4 queue driver information
269
- * if an AP queue device is removed.
665
+ * This is called to remove the CEX4/CEX5/CEX6/CEX7 queue driver
666
+ * information if an AP queue device is removed.
270667 */
271668 static void zcrypt_cex4_queue_remove(struct ap_device *ap_dev)
272669 {
273670 struct ap_queue *aq = to_ap_queue(&ap_dev->device);
274671 struct zcrypt_queue *zq = aq->private;
275672
673
+ if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO))
674
+ sysfs_remove_group(&ap_dev->device.kobj, &cca_queue_attr_grp);
675
+ else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11))
676
+ sysfs_remove_group(&ap_dev->device.kobj, &ep11_queue_attr_grp);
276677 if (zq)
277678 zcrypt_queue_unregister(zq);
278679 }
....@@ -280,8 +681,6 @@
280681 static struct ap_driver zcrypt_cex4_queue_driver = {
281682 .probe = zcrypt_cex4_queue_probe,
282683 .remove = zcrypt_cex4_queue_remove,
283
- .suspend = ap_queue_suspend,
284
- .resume = ap_queue_resume,
285684 .ids = zcrypt_cex4_queue_ids,
286685 .flags = AP_DRIVER_FLAG_DEFAULT,
287686 };