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