aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>2016-08-25 05:14:15 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2016-12-14 10:33:38 -0500
commit34a15167739412750846d4f1a5540d9e592fd815 (patch)
tree6436d8097ae4f2e3d0d70e13c7983ea714167448
parent9af3e04ee41e6841b2accb9dc96562bcf4e59916 (diff)
s390/zcrypt: Introduce workload balancing
Crypto requests are very different in complexity and thus runtime. Also various crypto adapters are differ with regard to the execution time. Crypto requests can be balanced much better when the request type and eligible crypto adapters are rated in a more precise granularity. Therefore, request weights and adapter speed rates for dedicated requests will be introduced. Signed-off-by: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
-rw-r--r--drivers/s390/crypto/zcrypt_api.c308
-rw-r--r--drivers/s390/crypto/zcrypt_api.h26
-rw-r--r--drivers/s390/crypto/zcrypt_cex2a.c12
-rw-r--r--drivers/s390/crypto/zcrypt_cex4.c36
-rw-r--r--drivers/s390/crypto/zcrypt_msgtype50.c32
-rw-r--r--drivers/s390/crypto/zcrypt_msgtype50.h3
-rw-r--r--drivers/s390/crypto/zcrypt_msgtype6.c403
-rw-r--r--drivers/s390/crypto/zcrypt_msgtype6.h17
-rw-r--r--drivers/s390/crypto/zcrypt_pcixcc.c41
9 files changed, 629 insertions, 249 deletions
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index dc6d891a7b48..28913e540096 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -151,18 +151,16 @@ static inline int zcrypt_process_rescan(void)
151 * Need to be called while holding the zcrypt device list lock. 151 * Need to be called while holding the zcrypt device list lock.
152 * Note: cards with speed_rating of 0 are kept at the end of the list. 152 * Note: cards with speed_rating of 0 are kept at the end of the list.
153 */ 153 */
154static void __zcrypt_increase_preference(struct zcrypt_device *zdev) 154static void __zcrypt_increase_preference(struct zcrypt_device *zdev,
155 unsigned int weight)
155{ 156{
156 struct zcrypt_device *tmp; 157 struct zcrypt_device *tmp;
157 struct list_head *l; 158 struct list_head *l;
158 159
159 if (zdev->speed_rating == 0) 160 zdev->load -= weight;
160 return;
161 for (l = zdev->list.prev; l != &zcrypt_device_list; l = l->prev) { 161 for (l = zdev->list.prev; l != &zcrypt_device_list; l = l->prev) {
162 tmp = list_entry(l, struct zcrypt_device, list); 162 tmp = list_entry(l, struct zcrypt_device, list);
163 if ((tmp->request_count + 1) * tmp->speed_rating <= 163 if (tmp->load <= zdev->load)
164 (zdev->request_count + 1) * zdev->speed_rating &&
165 tmp->speed_rating != 0)
166 break; 164 break;
167 } 165 }
168 if (l == zdev->list.prev) 166 if (l == zdev->list.prev)
@@ -179,18 +177,16 @@ static void __zcrypt_increase_preference(struct zcrypt_device *zdev)
179 * Need to be called while holding the zcrypt device list lock. 177 * Need to be called while holding the zcrypt device list lock.
180 * Note: cards with speed_rating of 0 are kept at the end of the list. 178 * Note: cards with speed_rating of 0 are kept at the end of the list.
181 */ 179 */
182static void __zcrypt_decrease_preference(struct zcrypt_device *zdev) 180static void __zcrypt_decrease_preference(struct zcrypt_device *zdev,
181 unsigned int weight)
183{ 182{
184 struct zcrypt_device *tmp; 183 struct zcrypt_device *tmp;
185 struct list_head *l; 184 struct list_head *l;
186 185
187 if (zdev->speed_rating == 0) 186 zdev->load += weight;
188 return;
189 for (l = zdev->list.next; l != &zcrypt_device_list; l = l->next) { 187 for (l = zdev->list.next; l != &zcrypt_device_list; l = l->next) {
190 tmp = list_entry(l, struct zcrypt_device, list); 188 tmp = list_entry(l, struct zcrypt_device, list);
191 if ((tmp->request_count + 1) * tmp->speed_rating > 189 if (tmp->load > zdev->load)
192 (zdev->request_count + 1) * zdev->speed_rating ||
193 tmp->speed_rating == 0)
194 break; 190 break;
195 } 191 }
196 if (l == zdev->list.next) 192 if (l == zdev->list.next)
@@ -270,7 +266,7 @@ int zcrypt_device_register(struct zcrypt_device *zdev)
270 ZCRYPT_DBF_DEV(DBF_INFO, zdev, "dev%04xo%dreg", zdev->ap_dev->qid, 266 ZCRYPT_DBF_DEV(DBF_INFO, zdev, "dev%04xo%dreg", zdev->ap_dev->qid,
271 zdev->online); 267 zdev->online);
272 list_add_tail(&zdev->list, &zcrypt_device_list); 268 list_add_tail(&zdev->list, &zcrypt_device_list);
273 __zcrypt_increase_preference(zdev); 269 __zcrypt_increase_preference(zdev, 0); /* sort devices acc. weight */
274 zcrypt_device_count++; 270 zcrypt_device_count++;
275 spin_unlock_bh(&zcrypt_device_lock); 271 spin_unlock_bh(&zcrypt_device_lock);
276 if (zdev->ops->rng) { 272 if (zdev->ops->rng) {
@@ -386,8 +382,9 @@ static int zcrypt_release(struct inode *inode, struct file *filp)
386 */ 382 */
387static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex) 383static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
388{ 384{
389 struct zcrypt_device *zdev; 385 struct zcrypt_device *zdev, *pref_zdev = NULL;
390 int rc; 386 int rc;
387 unsigned int weight, func_code, pref_weight = 0;
391 388
392 if (mex->outputdatalength < mex->inputdatalength) 389 if (mex->outputdatalength < mex->inputdatalength)
393 return -EINVAL; 390 return -EINVAL;
@@ -398,6 +395,10 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
398 */ 395 */
399 mex->outputdatalength = mex->inputdatalength; 396 mex->outputdatalength = mex->inputdatalength;
400 397
398 rc = get_rsa_modex_fc(mex, &func_code);
399 if (rc)
400 return rc;
401
401 spin_lock_bh(&zcrypt_device_lock); 402 spin_lock_bh(&zcrypt_device_lock);
402 list_for_each_entry(zdev, &zcrypt_device_list, list) { 403 list_for_each_entry(zdev, &zcrypt_device_list, list) {
403 if (!zdev->online || 404 if (!zdev->online ||
@@ -405,34 +406,52 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
405 zdev->min_mod_size > mex->inputdatalength || 406 zdev->min_mod_size > mex->inputdatalength ||
406 zdev->max_mod_size < mex->inputdatalength) 407 zdev->max_mod_size < mex->inputdatalength)
407 continue; 408 continue;
408 zcrypt_device_get(zdev); 409 weight = zdev->speed_rating[func_code];
409 get_device(&zdev->ap_dev->device); 410 if (!pref_zdev) {
410 zdev->request_count++; 411 pref_zdev = zdev;
411 __zcrypt_decrease_preference(zdev); 412 pref_weight = weight;
412 if (try_module_get(zdev->ap_dev->drv->driver.owner)) { 413 continue;
413 spin_unlock_bh(&zcrypt_device_lock);
414 rc = zdev->ops->rsa_modexpo(zdev, mex);
415 spin_lock_bh(&zcrypt_device_lock);
416 module_put(zdev->ap_dev->drv->driver.owner);
417 } 414 }
418 else 415 if ((pref_zdev->load + pref_weight) > (zdev->load + weight)) {
419 rc = -EAGAIN; 416 pref_zdev = zdev;
420 zdev->request_count--; 417 pref_weight = weight;
421 __zcrypt_increase_preference(zdev); 418 continue;
422 put_device(&zdev->ap_dev->device); 419 }
423 zcrypt_device_put(zdev); 420 if ((pref_zdev->load + pref_weight) <= zdev->load)
421 break; /* Load on remaining devices too high - abort */
422 }
423
424 if (!pref_zdev) {
424 spin_unlock_bh(&zcrypt_device_lock); 425 spin_unlock_bh(&zcrypt_device_lock);
425 return rc; 426 return -ENODEV;
426 } 427 }
428 __zcrypt_decrease_preference(pref_zdev, pref_weight);
429 zcrypt_device_get(pref_zdev);
430 get_device(&pref_zdev->ap_dev->device);
431 pref_zdev->request_count++;
432 if (try_module_get(pref_zdev->ap_dev->drv->driver.owner)) {
433 spin_unlock_bh(&zcrypt_device_lock);
434 rc = -ENODEV;
435 rc = pref_zdev->ops->rsa_modexpo(pref_zdev, mex);
436 spin_lock_bh(&zcrypt_device_lock);
437 module_put(pref_zdev->ap_dev->drv->driver.owner);
438 } else
439 rc = -EAGAIN;
440
441 pref_zdev->request_count--;
442 __zcrypt_increase_preference(pref_zdev, pref_weight);
443 put_device(&pref_zdev->ap_dev->device);
444 zcrypt_device_put(pref_zdev);
427 spin_unlock_bh(&zcrypt_device_lock); 445 spin_unlock_bh(&zcrypt_device_lock);
428 return -ENODEV; 446 return rc;
429} 447}
430 448
431static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt) 449static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
432{ 450{
433 struct zcrypt_device *zdev; 451 struct zcrypt_device *zdev, *pref_zdev = NULL;
434 unsigned long long z1, z2, z3; 452 unsigned long long z1, z2, z3;
435 int rc, copied; 453 int rc, copied;
454 unsigned int weight, func_code, pref_weight = 0;
436 455
437 if (crt->outputdatalength < crt->inputdatalength) 456 if (crt->outputdatalength < crt->inputdatalength)
438 return -EINVAL; 457 return -EINVAL;
@@ -443,6 +462,10 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
443 */ 462 */
444 crt->outputdatalength = crt->inputdatalength; 463 crt->outputdatalength = crt->inputdatalength;
445 464
465 rc = get_rsa_crt_fc(crt, &func_code);
466 if (rc)
467 return rc;
468
446 copied = 0; 469 copied = 0;
447 restart: 470 restart:
448 spin_lock_bh(&zcrypt_device_lock); 471 spin_lock_bh(&zcrypt_device_lock);
@@ -489,33 +512,54 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
489 /* The device can't handle this request. */ 512 /* The device can't handle this request. */
490 continue; 513 continue;
491 } 514 }
492 zcrypt_device_get(zdev); 515
493 get_device(&zdev->ap_dev->device); 516 weight = zdev->speed_rating[func_code];
494 zdev->request_count++; 517 if (!pref_zdev) {
495 __zcrypt_decrease_preference(zdev); 518 pref_zdev = zdev;
496 if (try_module_get(zdev->ap_dev->drv->driver.owner)) { 519 pref_weight = weight;
497 spin_unlock_bh(&zcrypt_device_lock); 520 continue;
498 rc = zdev->ops->rsa_modexpo_crt(zdev, crt); 521 }
499 spin_lock_bh(&zcrypt_device_lock); 522 if ((pref_zdev->load + pref_weight) > (zdev->load + weight)) {
500 module_put(zdev->ap_dev->drv->driver.owner); 523 pref_zdev = zdev;
524 pref_weight = weight;
525 continue;
501 } 526 }
502 else 527 if ((pref_zdev->load + pref_weight) <= zdev->load)
503 rc = -EAGAIN; 528 break; /* Load on remaining devices too high - abort */
504 zdev->request_count--; 529 }
505 __zcrypt_increase_preference(zdev); 530 if (!pref_zdev) {
506 put_device(&zdev->ap_dev->device);
507 zcrypt_device_put(zdev);
508 spin_unlock_bh(&zcrypt_device_lock); 531 spin_unlock_bh(&zcrypt_device_lock);
509 return rc; 532 return -ENODEV;
510 } 533 }
534 __zcrypt_decrease_preference(pref_zdev, pref_weight);
535 zcrypt_device_get(pref_zdev);
536 get_device(&pref_zdev->ap_dev->device);
537 pref_zdev->request_count++;
538 if (try_module_get(pref_zdev->ap_dev->drv->driver.owner)) {
539 spin_unlock_bh(&zcrypt_device_lock);
540 rc = pref_zdev->ops->rsa_modexpo_crt(pref_zdev, crt);
541 spin_lock_bh(&zcrypt_device_lock);
542 module_put(pref_zdev->ap_dev->drv->driver.owner);
543 } else
544 rc = -EAGAIN;
545 pref_zdev->request_count--;
546 __zcrypt_increase_preference(pref_zdev, pref_weight);
547 put_device(&pref_zdev->ap_dev->device);
548 zcrypt_device_put(pref_zdev);
511 spin_unlock_bh(&zcrypt_device_lock); 549 spin_unlock_bh(&zcrypt_device_lock);
512 return -ENODEV; 550 return rc;
513} 551}
514 552
515static long zcrypt_send_cprb(struct ica_xcRB *xcRB) 553static long zcrypt_send_cprb(struct ica_xcRB *xcRB)
516{ 554{
517 struct zcrypt_device *zdev; 555 struct zcrypt_device *zdev, *pref_zdev = NULL;
556 unsigned int weight = 0, func_code = 0, pref_weight = 0;
518 int rc; 557 int rc;
558 struct ap_message ap_msg;
559
560 rc = get_cprb_fc(xcRB, &ap_msg, &func_code);
561 if (rc)
562 return rc;
519 563
520 spin_lock_bh(&zcrypt_device_lock); 564 spin_lock_bh(&zcrypt_device_lock);
521 list_for_each_entry(zdev, &zcrypt_device_list, list) { 565 list_for_each_entry(zdev, &zcrypt_device_list, list) {
@@ -524,27 +568,42 @@ static long zcrypt_send_cprb(struct ica_xcRB *xcRB)
524 (xcRB->user_defined != AUTOSELECT && 568 (xcRB->user_defined != AUTOSELECT &&
525 AP_QID_DEVICE(zdev->ap_dev->qid) != xcRB->user_defined)) 569 AP_QID_DEVICE(zdev->ap_dev->qid) != xcRB->user_defined))
526 continue; 570 continue;
527 zcrypt_device_get(zdev); 571
528 get_device(&zdev->ap_dev->device); 572 weight = speed_idx_cca(func_code) * zdev->speed_rating[SECKEY];
529 zdev->request_count++; 573 if (!pref_zdev) {
530 __zcrypt_decrease_preference(zdev); 574 pref_zdev = zdev;
531 if (try_module_get(zdev->ap_dev->drv->driver.owner)) { 575 pref_weight = weight;
532 spin_unlock_bh(&zcrypt_device_lock); 576 continue;
533 rc = zdev->ops->send_cprb(zdev, xcRB); 577 }
534 spin_lock_bh(&zcrypt_device_lock); 578 if ((pref_zdev->load + pref_weight) > (zdev->load + weight)) {
535 module_put(zdev->ap_dev->drv->driver.owner); 579 pref_zdev = zdev;
580 pref_weight = weight;
581 continue;
536 } 582 }
537 else 583 if ((pref_zdev->load + pref_weight) <= zdev->load)
538 rc = -EAGAIN; 584 break; /* Load on remaining devices too high - abort */
539 zdev->request_count--; 585 }
540 __zcrypt_increase_preference(zdev); 586 if (!pref_zdev) {
541 put_device(&zdev->ap_dev->device);
542 zcrypt_device_put(zdev);
543 spin_unlock_bh(&zcrypt_device_lock); 587 spin_unlock_bh(&zcrypt_device_lock);
544 return rc; 588 return -ENODEV;
545 } 589 }
590 __zcrypt_decrease_preference(pref_zdev, pref_weight);
591 zcrypt_device_get(pref_zdev);
592 get_device(&pref_zdev->ap_dev->device);
593 pref_zdev->request_count++;
594 if (try_module_get(pref_zdev->ap_dev->drv->driver.owner)) {
595 spin_unlock_bh(&zcrypt_device_lock);
596 rc = pref_zdev->ops->send_cprb(pref_zdev, xcRB, &ap_msg);
597 spin_lock_bh(&zcrypt_device_lock);
598 module_put(pref_zdev->ap_dev->drv->driver.owner);
599 } else
600 rc = -EAGAIN;
601 pref_zdev->request_count--;
602 __zcrypt_increase_preference(pref_zdev, pref_weight);
603 put_device(&pref_zdev->ap_dev->device);
604 zcrypt_device_put(pref_zdev);
546 spin_unlock_bh(&zcrypt_device_lock); 605 spin_unlock_bh(&zcrypt_device_lock);
547 return -ENODEV; 606 return rc;
548} 607}
549 608
550struct ep11_target_dev_list { 609struct ep11_target_dev_list {
@@ -568,7 +627,9 @@ static bool is_desired_ep11dev(unsigned int dev_qid,
568 627
569static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb) 628static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
570{ 629{
571 struct zcrypt_device *zdev; 630 struct zcrypt_device *zdev, *pref_zdev = NULL;
631 struct ap_message ap_msg;
632 unsigned int weight = 0, func_code = 0, pref_weight = 0;
572 bool autoselect = false; 633 bool autoselect = false;
573 int rc; 634 int rc;
574 struct ep11_target_dev_list ep11_dev_list = { 635 struct ep11_target_dev_list ep11_dev_list = {
@@ -596,6 +657,10 @@ static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
596 return -EFAULT; 657 return -EFAULT;
597 } 658 }
598 659
660 rc = get_ep11cprb_fc(xcrb, &ap_msg, &func_code);
661 if (rc)
662 return rc;
663
599 spin_lock_bh(&zcrypt_device_lock); 664 spin_lock_bh(&zcrypt_device_lock);
600 list_for_each_entry(zdev, &zcrypt_device_list, list) { 665 list_for_each_entry(zdev, &zcrypt_device_list, list) {
601 /* check if device is eligible */ 666 /* check if device is eligible */
@@ -608,58 +673,93 @@ static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
608 !autoselect) 673 !autoselect)
609 continue; 674 continue;
610 675
611 zcrypt_device_get(zdev); 676 weight = speed_idx_ep11(func_code) * zdev->speed_rating[SECKEY];
612 get_device(&zdev->ap_dev->device); 677 if (!pref_zdev) {
613 zdev->request_count++; 678 pref_zdev = zdev;
614 __zcrypt_decrease_preference(zdev); 679 pref_weight = weight;
615 if (try_module_get(zdev->ap_dev->drv->driver.owner)) { 680 continue;
616 spin_unlock_bh(&zcrypt_device_lock); 681 }
617 rc = zdev->ops->send_ep11_cprb(zdev, xcrb); 682 if ((pref_zdev->load + pref_weight) > (zdev->load + weight)) {
618 spin_lock_bh(&zcrypt_device_lock); 683 pref_zdev = zdev;
619 module_put(zdev->ap_dev->drv->driver.owner); 684 pref_weight = weight;
620 } else { 685 continue;
621 rc = -EAGAIN; 686 }
622 } 687 if ((pref_zdev->load + pref_weight) <= zdev->load)
623 zdev->request_count--; 688 break; /* Load on remaining devices too high - abort */
624 __zcrypt_increase_preference(zdev); 689 }
625 put_device(&zdev->ap_dev->device); 690 if (!pref_zdev) {
626 zcrypt_device_put(zdev);
627 spin_unlock_bh(&zcrypt_device_lock); 691 spin_unlock_bh(&zcrypt_device_lock);
628 return rc; 692 return -ENODEV;
693 }
694
695 zcrypt_device_get(pref_zdev);
696 get_device(&pref_zdev->ap_dev->device);
697 pref_zdev->request_count++;
698 if (try_module_get(pref_zdev->ap_dev->drv->driver.owner)) {
699 spin_unlock_bh(&zcrypt_device_lock);
700 rc = pref_zdev->ops->send_ep11_cprb(pref_zdev, xcrb, &ap_msg);
701 spin_lock_bh(&zcrypt_device_lock);
702 module_put(pref_zdev->ap_dev->drv->driver.owner);
703 } else {
704 rc = -EAGAIN;
629 } 705 }
706 pref_zdev->request_count--;
707 put_device(&pref_zdev->ap_dev->device);
708 zcrypt_device_put(pref_zdev);
630 spin_unlock_bh(&zcrypt_device_lock); 709 spin_unlock_bh(&zcrypt_device_lock);
631 return -ENODEV; 710 return rc;
632} 711}
633 712
634static long zcrypt_rng(char *buffer) 713static long zcrypt_rng(char *buffer)
635{ 714{
636 struct zcrypt_device *zdev; 715 struct zcrypt_device *zdev, *pref_zdev = NULL;
716 struct ap_message ap_msg;
717 unsigned int weight = 0, func_code = 0, pref_weight = 0;
637 int rc; 718 int rc;
638 719
720 rc = get_rng_fc(&ap_msg, &func_code);
721 if (rc)
722 return rc;
723
639 spin_lock_bh(&zcrypt_device_lock); 724 spin_lock_bh(&zcrypt_device_lock);
640 list_for_each_entry(zdev, &zcrypt_device_list, list) { 725 list_for_each_entry(zdev, &zcrypt_device_list, list) {
641 if (!zdev->online || !zdev->ops->rng) 726 if (!zdev->online || !zdev->ops->rng)
642 continue; 727 continue;
643 zcrypt_device_get(zdev); 728
644 get_device(&zdev->ap_dev->device); 729 weight = zdev->speed_rating[func_code];
645 zdev->request_count++; 730 if (!pref_zdev) {
646 __zcrypt_decrease_preference(zdev); 731 pref_zdev = zdev;
647 if (try_module_get(zdev->ap_dev->drv->driver.owner)) { 732 pref_weight = weight;
648 spin_unlock_bh(&zcrypt_device_lock); 733 continue;
649 rc = zdev->ops->rng(zdev, buffer); 734 }
650 spin_lock_bh(&zcrypt_device_lock); 735 if ((pref_zdev->load + pref_weight) > (zdev->load + weight)) {
651 module_put(zdev->ap_dev->drv->driver.owner); 736 pref_zdev = zdev;
652 } else 737 pref_weight = weight;
653 rc = -EAGAIN; 738 continue;
654 zdev->request_count--; 739 }
655 __zcrypt_increase_preference(zdev); 740 if ((pref_zdev->load + pref_weight) <= zdev->load)
656 put_device(&zdev->ap_dev->device); 741 break; /* Load on remaining devices too high - abort */
657 zcrypt_device_put(zdev); 742 }
743 if (!pref_zdev) {
658 spin_unlock_bh(&zcrypt_device_lock); 744 spin_unlock_bh(&zcrypt_device_lock);
659 return rc; 745 return -ENODEV;
660 } 746 }
747
748 zcrypt_device_get(pref_zdev);
749 get_device(&pref_zdev->ap_dev->device);
750 pref_zdev->request_count++;
751 if (try_module_get(pref_zdev->ap_dev->drv->driver.owner)) {
752 spin_unlock_bh(&zcrypt_device_lock);
753 rc = pref_zdev->ops->rng(pref_zdev, buffer, &ap_msg);
754 spin_lock_bh(&zcrypt_device_lock);
755 module_put(pref_zdev->ap_dev->drv->driver.owner);
756 } else
757 rc = -EAGAIN;
758 pref_zdev->request_count--;
759 put_device(&pref_zdev->ap_dev->device);
760 zcrypt_device_put(pref_zdev);
661 spin_unlock_bh(&zcrypt_device_lock); 761 spin_unlock_bh(&zcrypt_device_lock);
662 return -ENODEV; 762 return rc;
663} 763}
664 764
665static void zcrypt_status_mask(char status[AP_DEVICES]) 765static void zcrypt_status_mask(char status[AP_DEVICES])
diff --git a/drivers/s390/crypto/zcrypt_api.h b/drivers/s390/crypto/zcrypt_api.h
index 326ecdc0417f..3d0d1e25d751 100644
--- a/drivers/s390/crypto/zcrypt_api.h
+++ b/drivers/s390/crypto/zcrypt_api.h
@@ -84,15 +84,32 @@ struct ica_z90_status {
84 */ 84 */
85#define ZCRYPT_RNG_BUFFER_SIZE 4096 85#define ZCRYPT_RNG_BUFFER_SIZE 4096
86 86
87/*
88 * Identifier for Crypto Request Performance Index
89 */
90enum crypto_ops {
91 MEX_1K = 0,
92 MEX_2K,
93 MEX_4K,
94 CRT_1K,
95 CRT_2K,
96 CRT_4K,
97 HWRNG,
98 SECKEY,
99 NUM_OPS
100};
101
87struct zcrypt_device; 102struct zcrypt_device;
88 103
89struct zcrypt_ops { 104struct zcrypt_ops {
90 long (*rsa_modexpo)(struct zcrypt_device *, struct ica_rsa_modexpo *); 105 long (*rsa_modexpo)(struct zcrypt_device *, struct ica_rsa_modexpo *);
91 long (*rsa_modexpo_crt)(struct zcrypt_device *, 106 long (*rsa_modexpo_crt)(struct zcrypt_device *,
92 struct ica_rsa_modexpo_crt *); 107 struct ica_rsa_modexpo_crt *);
93 long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *); 108 long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *,
94 long (*send_ep11_cprb)(struct zcrypt_device *, struct ep11_urb *); 109 struct ap_message *);
95 long (*rng)(struct zcrypt_device *, char *); 110 long (*send_ep11_cprb)(struct zcrypt_device *, struct ep11_urb *,
111 struct ap_message *);
112 long (*rng)(struct zcrypt_device *, char *, struct ap_message *);
96 struct list_head list; /* zcrypt ops list. */ 113 struct list_head list; /* zcrypt ops list. */
97 struct module *owner; 114 struct module *owner;
98 int variant; 115 int variant;
@@ -112,7 +129,8 @@ struct zcrypt_device {
112 int min_mod_size; /* Min number of bits. */ 129 int min_mod_size; /* Min number of bits. */
113 int max_mod_size; /* Max number of bits. */ 130 int max_mod_size; /* Max number of bits. */
114 int short_crt; /* Card has crt length restriction. */ 131 int short_crt; /* Card has crt length restriction. */
115 int speed_rating; /* Speed of the crypto device. */ 132 int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */
133 int load; /* Utilization of the crypto device */
116 134
117 int request_count; /* # current requests. */ 135 int request_count; /* # current requests. */
118 136
diff --git a/drivers/s390/crypto/zcrypt_cex2a.c b/drivers/s390/crypto/zcrypt_cex2a.c
index d892cb539139..4bb13eadd0f1 100644
--- a/drivers/s390/crypto/zcrypt_cex2a.c
+++ b/drivers/s390/crypto/zcrypt_cex2a.c
@@ -43,9 +43,6 @@
43#define CEX3A_MIN_MOD_SIZE CEX2A_MIN_MOD_SIZE 43#define CEX3A_MIN_MOD_SIZE CEX2A_MIN_MOD_SIZE
44#define CEX3A_MAX_MOD_SIZE 512 /* 4096 bits */ 44#define CEX3A_MAX_MOD_SIZE 512 /* 4096 bits */
45 45
46#define CEX2A_SPEED_RATING 970
47#define CEX3A_SPEED_RATING 900 /* Fixme: Needs finetuning */
48
49#define CEX2A_MAX_MESSAGE_SIZE 0x390 /* sizeof(struct type50_crb2_msg) */ 46#define CEX2A_MAX_MESSAGE_SIZE 0x390 /* sizeof(struct type50_crb2_msg) */
50#define CEX2A_MAX_RESPONSE_SIZE 0x110 /* max outputdatalength + type80_hdr */ 47#define CEX2A_MAX_RESPONSE_SIZE 0x110 /* max outputdatalength + type80_hdr */
51 48
@@ -87,6 +84,8 @@ static struct ap_driver zcrypt_cex2a_driver = {
87static int zcrypt_cex2a_probe(struct ap_device *ap_dev) 84static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
88{ 85{
89 struct zcrypt_device *zdev = NULL; 86 struct zcrypt_device *zdev = NULL;
87 int CEX2A_SPEED_IDX[] = { 800, 1000, 2000, 900, 1200, 2400, 0};
88 int CEX3A_SPEED_IDX[] = { 400, 500, 1000, 450, 550, 1200, 0};
90 int rc = 0; 89 int rc = 0;
91 90
92 switch (ap_dev->device_type) { 91 switch (ap_dev->device_type) {
@@ -99,7 +98,8 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
99 zdev->min_mod_size = CEX2A_MIN_MOD_SIZE; 98 zdev->min_mod_size = CEX2A_MIN_MOD_SIZE;
100 zdev->max_mod_size = CEX2A_MAX_MOD_SIZE; 99 zdev->max_mod_size = CEX2A_MAX_MOD_SIZE;
101 zdev->short_crt = 1; 100 zdev->short_crt = 1;
102 zdev->speed_rating = CEX2A_SPEED_RATING; 101 memcpy(zdev->speed_rating, CEX2A_SPEED_IDX,
102 sizeof(CEX2A_SPEED_IDX));
103 zdev->max_exp_bit_length = CEX2A_MAX_MOD_SIZE; 103 zdev->max_exp_bit_length = CEX2A_MAX_MOD_SIZE;
104 break; 104 break;
105 case AP_DEVICE_TYPE_CEX3A: 105 case AP_DEVICE_TYPE_CEX3A:
@@ -117,7 +117,8 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
117 zdev->max_exp_bit_length = CEX3A_MAX_MOD_SIZE; 117 zdev->max_exp_bit_length = CEX3A_MAX_MOD_SIZE;
118 } 118 }
119 zdev->short_crt = 1; 119 zdev->short_crt = 1;
120 zdev->speed_rating = CEX3A_SPEED_RATING; 120 memcpy(zdev->speed_rating, CEX3A_SPEED_IDX,
121 sizeof(CEX3A_SPEED_IDX));
121 break; 122 break;
122 } 123 }
123 if (!zdev) 124 if (!zdev)
@@ -125,6 +126,7 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
125 zdev->ops = zcrypt_msgtype(MSGTYPE50_NAME, MSGTYPE50_VARIANT_DEFAULT); 126 zdev->ops = zcrypt_msgtype(MSGTYPE50_NAME, MSGTYPE50_VARIANT_DEFAULT);
126 zdev->ap_dev = ap_dev; 127 zdev->ap_dev = ap_dev;
127 zdev->online = 1; 128 zdev->online = 1;
129 zdev->load = zdev->speed_rating[0];
128 ap_device_init_reply(ap_dev, &zdev->reply); 130 ap_device_init_reply(ap_dev, &zdev->reply);
129 ap_dev->private = zdev; 131 ap_dev->private = zdev;
130 rc = zcrypt_device_register(zdev); 132 rc = zcrypt_device_register(zdev);
diff --git a/drivers/s390/crypto/zcrypt_cex4.c b/drivers/s390/crypto/zcrypt_cex4.c
index e98bdbe45d2c..ff28ad543c30 100644
--- a/drivers/s390/crypto/zcrypt_cex4.c
+++ b/drivers/s390/crypto/zcrypt_cex4.c
@@ -24,13 +24,6 @@
24#define CEX4C_MIN_MOD_SIZE 16 /* 256 bits */ 24#define CEX4C_MIN_MOD_SIZE 16 /* 256 bits */
25#define CEX4C_MAX_MOD_SIZE 512 /* 4096 bits */ 25#define CEX4C_MAX_MOD_SIZE 512 /* 4096 bits */
26 26
27#define CEX4A_SPEED_RATING 900 /* TODO new card, new speed rating */
28#define CEX4C_SPEED_RATING 6500 /* TODO new card, new speed rating */
29#define CEX4P_SPEED_RATING 7000 /* TODO new card, new speed rating */
30#define CEX5A_SPEED_RATING 450 /* TODO new card, new speed rating */
31#define CEX5C_SPEED_RATING 3250 /* TODO new card, new speed rating */
32#define CEX5P_SPEED_RATING 3500 /* TODO new card, new speed rating */
33
34#define CEX4A_MAX_MESSAGE_SIZE MSGTYPE50_CRB3_MAX_MSG_SIZE 27#define CEX4A_MAX_MESSAGE_SIZE MSGTYPE50_CRB3_MAX_MSG_SIZE
35#define CEX4C_MAX_MESSAGE_SIZE MSGTYPE06_MAX_MSG_SIZE 28#define CEX4C_MAX_MESSAGE_SIZE MSGTYPE06_MAX_MSG_SIZE
36 29
@@ -71,6 +64,16 @@ static struct ap_driver zcrypt_cex4_driver = {
71static int zcrypt_cex4_probe(struct ap_device *ap_dev) 64static int zcrypt_cex4_probe(struct ap_device *ap_dev)
72{ 65{
73 struct zcrypt_device *zdev = NULL; 66 struct zcrypt_device *zdev = NULL;
67 /*
68 * Normalized speed ratings per crypto adapter
69 * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY
70 */
71 int CEX4A_SPEED_IDX[] = { 5, 6, 59, 20, 115, 581, 0, 0};
72 int CEX5A_SPEED_IDX[] = { 3, 3, 6, 8, 32, 218, 0, 0};
73 int CEX4C_SPEED_IDX[] = { 24, 25, 82, 41, 138, 1111, 79, 8};
74 int CEX5C_SPEED_IDX[] = { 10, 14, 23, 17, 45, 242, 63, 4};
75 int CEX4P_SPEED_IDX[] = {142, 198, 1852, 203, 331, 1563, 0, 8};
76 int CEX5P_SPEED_IDX[] = { 49, 67, 131, 52, 85, 287, 0, 4};
74 int rc = 0; 77 int rc = 0;
75 78
76 switch (ap_dev->device_type) { 79 switch (ap_dev->device_type) {
@@ -82,10 +85,12 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
82 return -ENOMEM; 85 return -ENOMEM;
83 if (ap_dev->device_type == AP_DEVICE_TYPE_CEX4) { 86 if (ap_dev->device_type == AP_DEVICE_TYPE_CEX4) {
84 zdev->type_string = "CEX4A"; 87 zdev->type_string = "CEX4A";
85 zdev->speed_rating = CEX4A_SPEED_RATING; 88 memcpy(zdev->speed_rating, CEX4A_SPEED_IDX,
89 sizeof(CEX4A_SPEED_IDX));
86 } else { 90 } else {
87 zdev->type_string = "CEX5A"; 91 zdev->type_string = "CEX5A";
88 zdev->speed_rating = CEX5A_SPEED_RATING; 92 memcpy(zdev->speed_rating, CEX5A_SPEED_IDX,
93 sizeof(CEX5A_SPEED_IDX));
89 } 94 }
90 zdev->user_space_type = ZCRYPT_CEX3A; 95 zdev->user_space_type = ZCRYPT_CEX3A;
91 zdev->min_mod_size = CEX4A_MIN_MOD_SIZE; 96 zdev->min_mod_size = CEX4A_MIN_MOD_SIZE;
@@ -110,10 +115,12 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
110 return -ENOMEM; 115 return -ENOMEM;
111 if (ap_dev->device_type == AP_DEVICE_TYPE_CEX4) { 116 if (ap_dev->device_type == AP_DEVICE_TYPE_CEX4) {
112 zdev->type_string = "CEX4C"; 117 zdev->type_string = "CEX4C";
113 zdev->speed_rating = CEX4C_SPEED_RATING; 118 memcpy(zdev->speed_rating, CEX4C_SPEED_IDX,
119 sizeof(CEX4C_SPEED_IDX));
114 } else { 120 } else {
115 zdev->type_string = "CEX5C"; 121 zdev->type_string = "CEX5C";
116 zdev->speed_rating = CEX5C_SPEED_RATING; 122 memcpy(zdev->speed_rating, CEX5C_SPEED_IDX,
123 sizeof(CEX5C_SPEED_IDX));
117 } 124 }
118 zdev->user_space_type = ZCRYPT_CEX3C; 125 zdev->user_space_type = ZCRYPT_CEX3C;
119 zdev->min_mod_size = CEX4C_MIN_MOD_SIZE; 126 zdev->min_mod_size = CEX4C_MIN_MOD_SIZE;
@@ -128,10 +135,12 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
128 return -ENOMEM; 135 return -ENOMEM;
129 if (ap_dev->device_type == AP_DEVICE_TYPE_CEX4) { 136 if (ap_dev->device_type == AP_DEVICE_TYPE_CEX4) {
130 zdev->type_string = "CEX4P"; 137 zdev->type_string = "CEX4P";
131 zdev->speed_rating = CEX4P_SPEED_RATING; 138 memcpy(zdev->speed_rating, CEX4P_SPEED_IDX,
139 sizeof(CEX4P_SPEED_IDX));
132 } else { 140 } else {
133 zdev->type_string = "CEX5P"; 141 zdev->type_string = "CEX5P";
134 zdev->speed_rating = CEX5P_SPEED_RATING; 142 memcpy(zdev->speed_rating, CEX5P_SPEED_IDX,
143 sizeof(CEX5P_SPEED_IDX));
135 } 144 }
136 zdev->user_space_type = ZCRYPT_CEX4; 145 zdev->user_space_type = ZCRYPT_CEX4;
137 zdev->min_mod_size = CEX4C_MIN_MOD_SIZE; 146 zdev->min_mod_size = CEX4C_MIN_MOD_SIZE;
@@ -147,6 +156,7 @@ static int zcrypt_cex4_probe(struct ap_device *ap_dev)
147 return -ENODEV; 156 return -ENODEV;
148 zdev->ap_dev = ap_dev; 157 zdev->ap_dev = ap_dev;
149 zdev->online = 1; 158 zdev->online = 1;
159 zdev->load = zdev->speed_rating[0];
150 ap_device_init_reply(ap_dev, &zdev->reply); 160 ap_device_init_reply(ap_dev, &zdev->reply);
151 ap_dev->private = zdev; 161 ap_dev->private = zdev;
152 rc = zcrypt_device_register(zdev); 162 rc = zcrypt_device_register(zdev);
diff --git a/drivers/s390/crypto/zcrypt_msgtype50.c b/drivers/s390/crypto/zcrypt_msgtype50.c
index 7bafba83390a..fb97479af3f8 100644
--- a/drivers/s390/crypto/zcrypt_msgtype50.c
+++ b/drivers/s390/crypto/zcrypt_msgtype50.c
@@ -173,6 +173,38 @@ struct type80_hdr {
173 unsigned char reserved3[8]; 173 unsigned char reserved3[8];
174} __packed; 174} __packed;
175 175
176unsigned int get_rsa_modex_fc(struct ica_rsa_modexpo *mex, int *fcode)
177{
178
179 if (!mex->inputdatalength)
180 return -EINVAL;
181
182 if (mex->inputdatalength <= 128) /* 1024 bit */
183 *fcode = MEX_1K;
184 else if (mex->inputdatalength <= 256) /* 2048 bit */
185 *fcode = MEX_2K;
186 else /* 4096 bit */
187 *fcode = MEX_4K;
188
189 return 0;
190}
191
192unsigned int get_rsa_crt_fc(struct ica_rsa_modexpo_crt *crt, int *fcode)
193{
194
195 if (!crt->inputdatalength)
196 return -EINVAL;
197
198 if (crt->inputdatalength <= 128) /* 1024 bit */
199 *fcode = CRT_1K;
200 else if (crt->inputdatalength <= 256) /* 2048 bit */
201 *fcode = CRT_2K;
202 else /* 4096 bit */
203 *fcode = CRT_4K;
204
205 return 0;
206}
207
176/** 208/**
177 * Convert a ICAMEX message to a type50 MEX message. 209 * Convert a ICAMEX message to a type50 MEX message.
178 * 210 *
diff --git a/drivers/s390/crypto/zcrypt_msgtype50.h b/drivers/s390/crypto/zcrypt_msgtype50.h
index eeb41c0f34ae..5cc280318ee7 100644
--- a/drivers/s390/crypto/zcrypt_msgtype50.h
+++ b/drivers/s390/crypto/zcrypt_msgtype50.h
@@ -35,6 +35,9 @@
35 35
36#define MSGTYPE_ADJUSTMENT 0x08 /*type04 extension (not needed in type50)*/ 36#define MSGTYPE_ADJUSTMENT 0x08 /*type04 extension (not needed in type50)*/
37 37
38unsigned int get_rsa_modex_fc(struct ica_rsa_modexpo *, int *);
39unsigned int get_rsa_crt_fc(struct ica_rsa_modexpo_crt *, int *);
40
38void zcrypt_msgtype50_init(void); 41void zcrypt_msgtype50_init(void);
39void zcrypt_msgtype50_exit(void); 42void zcrypt_msgtype50_exit(void);
40 43
diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
index f71949685ff5..957a88d5768b 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.c
+++ b/drivers/s390/crypto/zcrypt_msgtype6.c
@@ -149,6 +149,112 @@ static struct CPRBX static_cprbx = {
149 .func_id = {0x54, 0x32}, 149 .func_id = {0x54, 0x32},
150}; 150};
151 151
152int speed_idx_cca(int req_type)
153{
154 switch (req_type) {
155 case 0x4142:
156 case 0x4149:
157 case 0x414D:
158 case 0x4341:
159 case 0x4344:
160 case 0x4354:
161 case 0x4358:
162 case 0x444B:
163 case 0x4558:
164 case 0x4643:
165 case 0x4651:
166 case 0x4C47:
167 case 0x4C4B:
168 case 0x4C51:
169 case 0x4F48:
170 case 0x504F:
171 case 0x5053:
172 case 0x5058:
173 case 0x5343:
174 case 0x5344:
175 case 0x5345:
176 case 0x5350:
177 return LOW;
178 case 0x414B:
179 case 0x4345:
180 case 0x4349:
181 case 0x434D:
182 case 0x4847:
183 case 0x4849:
184 case 0x484D:
185 case 0x4850:
186 case 0x4851:
187 case 0x4954:
188 case 0x4958:
189 case 0x4B43:
190 case 0x4B44:
191 case 0x4B45:
192 case 0x4B47:
193 case 0x4B48:
194 case 0x4B49:
195 case 0x4B4E:
196 case 0x4B50:
197 case 0x4B52:
198 case 0x4B54:
199 case 0x4B58:
200 case 0x4D50:
201 case 0x4D53:
202 case 0x4D56:
203 case 0x4D58:
204 case 0x5044:
205 case 0x5045:
206 case 0x5046:
207 case 0x5047:
208 case 0x5049:
209 case 0x504B:
210 case 0x504D:
211 case 0x5254:
212 case 0x5347:
213 case 0x5349:
214 case 0x534B:
215 case 0x534D:
216 case 0x5356:
217 case 0x5358:
218 case 0x5443:
219 case 0x544B:
220 case 0x5647:
221 return HIGH;
222 default:
223 return MEDIUM;
224 }
225}
226
227int speed_idx_ep11(int req_type)
228{
229 switch (req_type) {
230 case 1:
231 case 2:
232 case 36:
233 case 37:
234 case 38:
235 case 39:
236 case 40:
237 return LOW;
238 case 17:
239 case 18:
240 case 19:
241 case 20:
242 case 21:
243 case 22:
244 case 26:
245 case 30:
246 case 31:
247 case 32:
248 case 33:
249 case 34:
250 case 35:
251 return HIGH;
252 default:
253 return MEDIUM;
254 }
255}
256
257
152/** 258/**
153 * Convert a ICAMEX message to a type6 MEX message. 259 * Convert a ICAMEX message to a type6 MEX message.
154 * 260 *
@@ -297,9 +403,9 @@ struct type86_fmt2_msg {
297 struct type86_fmt2_ext fmt2; 403 struct type86_fmt2_ext fmt2;
298} __packed; 404} __packed;
299 405
300static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev, 406static int XCRB_msg_to_type6CPRB_msgX(struct ap_message *ap_msg,
301 struct ap_message *ap_msg, 407 struct ica_xcRB *xcRB,
302 struct ica_xcRB *xcRB) 408 unsigned int *fcode)
303{ 409{
304 static struct type6_hdr static_type6_hdrX = { 410 static struct type6_hdr static_type6_hdrX = {
305 .type = 0x06, 411 .type = 0x06,
@@ -379,6 +485,8 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
379 memcpy(msg->hdr.function_code, function_code, 485 memcpy(msg->hdr.function_code, function_code,
380 sizeof(msg->hdr.function_code)); 486 sizeof(msg->hdr.function_code));
381 487
488 *fcode = (msg->hdr.function_code[0] << 8) | msg->hdr.function_code[1];
489
382 if (memcmp(function_code, "US", 2) == 0) 490 if (memcmp(function_code, "US", 2) == 0)
383 ap_msg->special = 1; 491 ap_msg->special = 1;
384 else 492 else
@@ -392,12 +500,10 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
392 return 0; 500 return 0;
393} 501}
394 502
395static int xcrb_msg_to_type6_ep11cprb_msgx(struct zcrypt_device *zdev, 503static int xcrb_msg_to_type6_ep11cprb_msgx(struct ap_message *ap_msg,
396 struct ap_message *ap_msg, 504 struct ep11_urb *xcRB,
397 struct ep11_urb *xcRB) 505 unsigned int *fcode)
398{ 506{
399 unsigned int lfmt;
400
401 static struct type6_hdr static_type6_ep11_hdr = { 507 static struct type6_hdr static_type6_ep11_hdr = {
402 .type = 0x06, 508 .type = 0x06,
403 .rqid = {0x00, 0x01}, 509 .rqid = {0x00, 0x01},
@@ -421,7 +527,7 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(struct zcrypt_device *zdev,
421 unsigned char dom_tag; /* fixed value 0x4 */ 527 unsigned char dom_tag; /* fixed value 0x4 */
422 unsigned char dom_len; /* fixed value 0x4 */ 528 unsigned char dom_len; /* fixed value 0x4 */
423 unsigned int dom_val; /* domain id */ 529 unsigned int dom_val; /* domain id */
424 } __packed * payload_hdr; 530 } __packed * payload_hdr = NULL;
425 531
426 if (CEIL4(xcRB->req_len) < xcRB->req_len) 532 if (CEIL4(xcRB->req_len) < xcRB->req_len)
427 return -EINVAL; /* overflow after alignment*/ 533 return -EINVAL; /* overflow after alignment*/
@@ -450,36 +556,7 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(struct zcrypt_device *zdev,
450 return -EFAULT; 556 return -EFAULT;
451 } 557 }
452 558
453 /* 559 *fcode = speed_idx_ep11(payload_hdr->func_val & 0xFFFF);
454 The target domain field within the cprb body/payload block will be
455 replaced by the usage domain for non-management commands only.
456 Therefore we check the first bit of the 'flags' parameter for
457 management command indication.
458 0 - non management command
459 1 - management command
460 */
461 if (!((msg->cprbx.flags & 0x80) == 0x80)) {
462 msg->cprbx.target_id = (unsigned int)
463 AP_QID_QUEUE(zdev->ap_dev->qid);
464
465 if ((msg->pld_lenfmt & 0x80) == 0x80) { /*ext.len.fmt 2 or 3*/
466 switch (msg->pld_lenfmt & 0x03) {
467 case 1:
468 lfmt = 2;
469 break;
470 case 2:
471 lfmt = 3;
472 break;
473 default:
474 return -EINVAL;
475 }
476 } else {
477 lfmt = 1; /* length format #1 */
478 }
479 payload_hdr = (struct pld_hdr *)((&(msg->pld_lenfmt))+lfmt);
480 payload_hdr->dom_val = (unsigned int)
481 AP_QID_QUEUE(zdev->ap_dev->qid);
482 }
483 return 0; 560 return 0;
484} 561}
485 562
@@ -989,6 +1066,36 @@ out_free:
989 return rc; 1066 return rc;
990} 1067}
991 1068
1069unsigned int get_cprb_fc(struct ica_xcRB *xcRB,
1070 struct ap_message *ap_msg,
1071 int *func_code)
1072{
1073 struct response_type resp_type = {
1074 .type = PCIXCC_RESPONSE_TYPE_XCRB,
1075 };
1076 int rc;
1077
1078 ap_init_message(ap_msg);
1079 ap_msg->message = kmalloc(MSGTYPE06_MAX_MSG_SIZE, GFP_KERNEL);
1080 if (!ap_msg->message)
1081 return -ENOMEM;
1082 ap_msg->receive = zcrypt_msgtype6_receive;
1083 ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
1084 atomic_inc_return(&zcrypt_step);
1085 ap_msg->private = kmalloc(sizeof(resp_type), GFP_KERNEL);
1086 if (!ap_msg->private) {
1087 kzfree(ap_msg->message);
1088 return -ENOMEM;
1089 }
1090 memcpy(ap_msg->private, &resp_type, sizeof(resp_type));
1091 rc = XCRB_msg_to_type6CPRB_msgX(ap_msg, xcRB, func_code);
1092 if (rc) {
1093 kzfree(ap_msg->message);
1094 kzfree(ap_msg->private);
1095 }
1096 return rc;
1097}
1098
992/** 1099/**
993 * The request distributor calls this function if it picked the PCIXCC/CEX2C 1100 * The request distributor calls this function if it picked the PCIXCC/CEX2C
994 * device to handle a send_cprb request. 1101 * device to handle a send_cprb request.
@@ -997,37 +1104,55 @@ out_free:
997 * @xcRB: pointer to the send_cprb request buffer 1104 * @xcRB: pointer to the send_cprb request buffer
998 */ 1105 */
999static long zcrypt_msgtype6_send_cprb(struct zcrypt_device *zdev, 1106static long zcrypt_msgtype6_send_cprb(struct zcrypt_device *zdev,
1000 struct ica_xcRB *xcRB) 1107 struct ica_xcRB *xcRB,
1108 struct ap_message *ap_msg)
1001{ 1109{
1002 struct ap_message ap_msg;
1003 struct response_type resp_type = {
1004 .type = PCIXCC_RESPONSE_TYPE_XCRB,
1005 };
1006 int rc; 1110 int rc;
1111 struct response_type *rtype = (struct response_type *)(ap_msg->private);
1007 1112
1008 ap_init_message(&ap_msg); 1113 init_completion(&rtype->work);
1009 ap_msg.message = kmalloc(MSGTYPE06_MAX_MSG_SIZE, GFP_KERNEL); 1114 ap_queue_message(zdev->ap_dev, ap_msg);
1010 if (!ap_msg.message) 1115 rc = wait_for_completion_interruptible(&rtype->work);
1011 return -ENOMEM;
1012 ap_msg.receive = zcrypt_msgtype6_receive;
1013 ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
1014 atomic_inc_return(&zcrypt_step);
1015 ap_msg.private = &resp_type;
1016 rc = XCRB_msg_to_type6CPRB_msgX(zdev, &ap_msg, xcRB);
1017 if (rc)
1018 goto out_free;
1019 init_completion(&resp_type.work);
1020 ap_queue_message(zdev->ap_dev, &ap_msg);
1021 rc = wait_for_completion_interruptible(&resp_type.work);
1022 if (rc == 0) { 1116 if (rc == 0) {
1023 rc = ap_msg.rc; 1117 rc = ap_msg->rc;
1024 if (rc == 0) 1118 if (rc == 0)
1025 rc = convert_response_xcrb(zdev, &ap_msg, xcRB); 1119 rc = convert_response_xcrb(zdev, ap_msg, xcRB);
1026 } else 1120 } else
1027 /* Signal pending. */ 1121 /* Signal pending. */
1028 ap_cancel_message(zdev->ap_dev, &ap_msg); 1122 ap_cancel_message(zdev->ap_dev, ap_msg);
1029out_free: 1123
1030 kzfree(ap_msg.message); 1124 kzfree(ap_msg->message);
1125 kzfree(ap_msg->private);
1126 return rc;
1127}
1128
1129unsigned int get_ep11cprb_fc(struct ep11_urb *xcrb,
1130 struct ap_message *ap_msg,
1131 int *func_code)
1132{
1133 struct response_type resp_type = {
1134 .type = PCIXCC_RESPONSE_TYPE_EP11,
1135 };
1136 int rc;
1137
1138 ap_init_message(ap_msg);
1139 ap_msg->message = kmalloc(MSGTYPE06_MAX_MSG_SIZE, GFP_KERNEL);
1140 if (!ap_msg->message)
1141 return -ENOMEM;
1142 ap_msg->receive = zcrypt_msgtype6_receive_ep11;
1143 ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
1144 atomic_inc_return(&zcrypt_step);
1145 ap_msg->private = kmalloc(sizeof(resp_type), GFP_KERNEL);
1146 if (!ap_msg->private) {
1147 kzfree(ap_msg->message);
1148 return -ENOMEM;
1149 }
1150 memcpy(ap_msg->private, &resp_type, sizeof(resp_type));
1151 rc = xcrb_msg_to_type6_ep11cprb_msgx(ap_msg, xcrb, func_code);
1152 if (rc) {
1153 kzfree(ap_msg->message);
1154 kzfree(ap_msg->private);
1155 }
1031 return rc; 1156 return rc;
1032} 1157}
1033 1158
@@ -1039,41 +1164,101 @@ out_free:
1039 * @xcRB: pointer to the ep11 user request block 1164 * @xcRB: pointer to the ep11 user request block
1040 */ 1165 */
1041static long zcrypt_msgtype6_send_ep11_cprb(struct zcrypt_device *zdev, 1166static long zcrypt_msgtype6_send_ep11_cprb(struct zcrypt_device *zdev,
1042 struct ep11_urb *xcrb) 1167 struct ep11_urb *xcrb,
1168 struct ap_message *ap_msg)
1043{ 1169{
1044 struct ap_message ap_msg;
1045 struct response_type resp_type = {
1046 .type = PCIXCC_RESPONSE_TYPE_EP11,
1047 };
1048 int rc; 1170 int rc;
1171 unsigned int lfmt;
1172 struct response_type *rtype = (struct response_type *)(ap_msg->private);
1173 struct {
1174 struct type6_hdr hdr;
1175 struct ep11_cprb cprbx;
1176 unsigned char pld_tag; /* fixed value 0x30 */
1177 unsigned char pld_lenfmt; /* payload length format */
1178 } __packed * msg = ap_msg->message;
1179 struct pld_hdr {
1180 unsigned char func_tag; /* fixed value 0x4 */
1181 unsigned char func_len; /* fixed value 0x4 */
1182 unsigned int func_val; /* function ID */
1183 unsigned char dom_tag; /* fixed value 0x4 */
1184 unsigned char dom_len; /* fixed value 0x4 */
1185 unsigned int dom_val; /* domain id */
1186 } __packed * payload_hdr = NULL;
1049 1187
1050 ap_init_message(&ap_msg); 1188
1051 ap_msg.message = kmalloc(MSGTYPE06_MAX_MSG_SIZE, GFP_KERNEL); 1189 /**
1052 if (!ap_msg.message) 1190 * The target domain field within the cprb body/payload block will be
1053 return -ENOMEM; 1191 * replaced by the usage domain for non-management commands only.
1054 ap_msg.receive = zcrypt_msgtype6_receive_ep11; 1192 * Therefore we check the first bit of the 'flags' parameter for
1055 ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 1193 * management command indication.
1056 atomic_inc_return(&zcrypt_step); 1194 * 0 - non management command
1057 ap_msg.private = &resp_type; 1195 * 1 - management command
1058 rc = xcrb_msg_to_type6_ep11cprb_msgx(zdev, &ap_msg, xcrb); 1196 */
1059 if (rc) 1197 if (!((msg->cprbx.flags & 0x80) == 0x80)) {
1060 goto out_free; 1198 msg->cprbx.target_id = (unsigned int)
1061 init_completion(&resp_type.work); 1199 AP_QID_QUEUE(zdev->ap_dev->qid);
1062 ap_queue_message(zdev->ap_dev, &ap_msg); 1200
1063 rc = wait_for_completion_interruptible(&resp_type.work); 1201 if ((msg->pld_lenfmt & 0x80) == 0x80) { /*ext.len.fmt 2 or 3*/
1202 switch (msg->pld_lenfmt & 0x03) {
1203 case 1:
1204 lfmt = 2;
1205 break;
1206 case 2:
1207 lfmt = 3;
1208 break;
1209 default:
1210 return -EINVAL;
1211 }
1212 } else {
1213 lfmt = 1; /* length format #1 */
1214 }
1215 payload_hdr = (struct pld_hdr *)((&(msg->pld_lenfmt))+lfmt);
1216 payload_hdr->dom_val = (unsigned int)
1217 AP_QID_QUEUE(zdev->ap_dev->qid);
1218 }
1219
1220 init_completion(&rtype->work);
1221 ap_queue_message(zdev->ap_dev, ap_msg);
1222 rc = wait_for_completion_interruptible(&rtype->work);
1064 if (rc == 0) { 1223 if (rc == 0) {
1065 rc = ap_msg.rc; 1224 rc = ap_msg->rc;
1066 if (rc == 0) 1225 if (rc == 0)
1067 rc = convert_response_ep11_xcrb(zdev, &ap_msg, xcrb); 1226 rc = convert_response_ep11_xcrb(zdev, ap_msg, xcrb);
1068 } else 1227 } else
1069 /* Signal pending. */ 1228 /* Signal pending. */
1070 ap_cancel_message(zdev->ap_dev, &ap_msg); 1229 ap_cancel_message(zdev->ap_dev, ap_msg);
1071 1230
1072out_free: 1231 kzfree(ap_msg->message);
1073 kzfree(ap_msg.message); 1232 kzfree(ap_msg->private);
1074 return rc; 1233 return rc;
1075} 1234}
1076 1235
1236unsigned int get_rng_fc(struct ap_message *ap_msg, int *func_code)
1237{
1238 struct response_type resp_type = {
1239 .type = PCIXCC_RESPONSE_TYPE_XCRB,
1240 };
1241
1242 ap_init_message(ap_msg);
1243 ap_msg->message = kmalloc(MSGTYPE06_MAX_MSG_SIZE, GFP_KERNEL);
1244 if (!ap_msg->message)
1245 return -ENOMEM;
1246 ap_msg->receive = zcrypt_msgtype6_receive;
1247 ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
1248 atomic_inc_return(&zcrypt_step);
1249 ap_msg->private = kmalloc(sizeof(resp_type), GFP_KERNEL);
1250 if (!ap_msg->private) {
1251 kzfree(ap_msg->message);
1252 return -ENOMEM;
1253 }
1254 memcpy(ap_msg->private, &resp_type, sizeof(resp_type));
1255
1256 rng_type6CPRB_msgX(ap_msg, ZCRYPT_RNG_BUFFER_SIZE);
1257
1258 *func_code = HWRNG;
1259 return 0;
1260}
1261
1077/** 1262/**
1078 * The request distributor calls this function if it picked the PCIXCC/CEX2C 1263 * The request distributor calls this function if it picked the PCIXCC/CEX2C
1079 * device to generate random data. 1264 * device to generate random data.
@@ -1081,36 +1266,36 @@ out_free:
1081 * PCIXCC/CEX2C device to the request distributor 1266 * PCIXCC/CEX2C device to the request distributor
1082 * @buffer: pointer to a memory page to return random data 1267 * @buffer: pointer to a memory page to return random data
1083 */ 1268 */
1084
1085static long zcrypt_msgtype6_rng(struct zcrypt_device *zdev, 1269static long zcrypt_msgtype6_rng(struct zcrypt_device *zdev,
1086 char *buffer) 1270 char *buffer, struct ap_message *ap_msg)
1087{ 1271{
1088 struct ap_message ap_msg; 1272 struct {
1089 struct response_type resp_type = { 1273 struct type6_hdr hdr;
1090 .type = PCIXCC_RESPONSE_TYPE_XCRB, 1274 struct CPRBX cprbx;
1091 }; 1275 char function_code[2];
1276 short int rule_length;
1277 char rule[8];
1278 short int verb_length;
1279 short int key_length;
1280 } __packed * msg = ap_msg->message;
1281 struct response_type *rtype = (struct response_type *)(ap_msg->private);
1092 int rc; 1282 int rc;
1093 1283
1094 ap_init_message(&ap_msg); 1284 msg->cprbx.domain = AP_QID_QUEUE(zdev->ap_dev->qid);
1095 ap_msg.message = kmalloc(MSGTYPE06_MAX_MSG_SIZE, GFP_KERNEL); 1285
1096 if (!ap_msg.message) 1286 init_completion(&rtype->work);
1097 return -ENOMEM; 1287 ap_queue_message(zdev->ap_dev, ap_msg);
1098 ap_msg.receive = zcrypt_msgtype6_receive; 1288 rc = wait_for_completion_interruptible(&rtype->work);
1099 ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
1100 atomic_inc_return(&zcrypt_step);
1101 ap_msg.private = &resp_type;
1102 rng_type6CPRB_msgX(zdev->ap_dev, &ap_msg, ZCRYPT_RNG_BUFFER_SIZE);
1103 init_completion(&resp_type.work);
1104 ap_queue_message(zdev->ap_dev, &ap_msg);
1105 rc = wait_for_completion_interruptible(&resp_type.work);
1106 if (rc == 0) { 1289 if (rc == 0) {
1107 rc = ap_msg.rc; 1290 rc = ap_msg->rc;
1108 if (rc == 0) 1291 if (rc == 0)
1109 rc = convert_response_rng(zdev, &ap_msg, buffer); 1292 rc = convert_response_rng(zdev, ap_msg, buffer);
1110 } else 1293 } else
1111 /* Signal pending. */ 1294 /* Signal pending. */
1112 ap_cancel_message(zdev->ap_dev, &ap_msg); 1295 ap_cancel_message(zdev->ap_dev, ap_msg);
1113 kfree(ap_msg.message); 1296
1297 kzfree(ap_msg->message);
1298 kzfree(ap_msg->private);
1114 return rc; 1299 return rc;
1115} 1300}
1116 1301
diff --git a/drivers/s390/crypto/zcrypt_msgtype6.h b/drivers/s390/crypto/zcrypt_msgtype6.h
index 5750c4377bfa..a360dbe3c7d2 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.h
+++ b/drivers/s390/crypto/zcrypt_msgtype6.h
@@ -116,15 +116,25 @@ struct type86_fmt2_ext {
116 unsigned int offset4; /* 0x00000000 */ 116 unsigned int offset4; /* 0x00000000 */
117} __packed; 117} __packed;
118 118
119unsigned int get_cprb_fc(struct ica_xcRB *, struct ap_message *, int *);
120unsigned int get_ep11cprb_fc(struct ep11_urb *, struct ap_message *, int *);
121unsigned int get_rng_fc(struct ap_message *, int *);
122
123#define LOW 10
124#define MEDIUM 100
125#define HIGH 500
126
127int speed_idx_cca(int);
128int speed_idx_ep11(int);
129
119/** 130/**
120 * Prepare a type6 CPRB message for random number generation 131 * Prepare a type6 CPRB message for random number generation
121 * 132 *
122 * @ap_dev: AP device pointer 133 * @ap_dev: AP device pointer
123 * @ap_msg: pointer to AP message 134 * @ap_msg: pointer to AP message
124 */ 135 */
125static inline void rng_type6CPRB_msgX(struct ap_device *ap_dev, 136static inline void rng_type6CPRB_msgX(struct ap_message *ap_msg,
126 struct ap_message *ap_msg, 137 unsigned int random_number_length)
127 unsigned random_number_length)
128{ 138{
129 struct { 139 struct {
130 struct type6_hdr hdr; 140 struct type6_hdr hdr;
@@ -156,7 +166,6 @@ static inline void rng_type6CPRB_msgX(struct ap_device *ap_dev,
156 msg->hdr.FromCardLen2 = random_number_length, 166 msg->hdr.FromCardLen2 = random_number_length,
157 msg->cprbx = local_cprbx; 167 msg->cprbx = local_cprbx;
158 msg->cprbx.rpl_datal = random_number_length, 168 msg->cprbx.rpl_datal = random_number_length,
159 msg->cprbx.domain = AP_QID_QUEUE(ap_dev->qid);
160 memcpy(msg->function_code, msg->hdr.function_code, 0x02); 169 memcpy(msg->function_code, msg->hdr.function_code, 0x02);
161 msg->rule_length = 0x0a; 170 msg->rule_length = 0x0a;
162 memcpy(msg->rule, "RANDOM ", 8); 171 memcpy(msg->rule, "RANDOM ", 8);
diff --git a/drivers/s390/crypto/zcrypt_pcixcc.c b/drivers/s390/crypto/zcrypt_pcixcc.c
index 8491541f72cf..43de39c74944 100644
--- a/drivers/s390/crypto/zcrypt_pcixcc.c
+++ b/drivers/s390/crypto/zcrypt_pcixcc.c
@@ -46,11 +46,6 @@
46#define CEX3C_MIN_MOD_SIZE PCIXCC_MIN_MOD_SIZE 46#define CEX3C_MIN_MOD_SIZE PCIXCC_MIN_MOD_SIZE
47#define CEX3C_MAX_MOD_SIZE 512 /* 4096 bits */ 47#define CEX3C_MAX_MOD_SIZE 512 /* 4096 bits */
48 48
49#define PCIXCC_MCL2_SPEED_RATING 7870
50#define PCIXCC_MCL3_SPEED_RATING 7870
51#define CEX2C_SPEED_RATING 7000
52#define CEX3C_SPEED_RATING 6500
53
54#define PCIXCC_MAX_ICA_MESSAGE_SIZE 0x77c /* max size type6 v2 crt message */ 49#define PCIXCC_MAX_ICA_MESSAGE_SIZE 0x77c /* max size type6 v2 crt message */
55#define PCIXCC_MAX_ICA_RESPONSE_SIZE 0x77c /* max size type86 v2 reply */ 50#define PCIXCC_MAX_ICA_RESPONSE_SIZE 0x77c /* max size type86 v2 reply */
56 51
@@ -220,6 +215,15 @@ static int zcrypt_pcixcc_rng_supported(struct ap_device *ap_dev)
220 struct type86_fmt2_ext fmt2; 215 struct type86_fmt2_ext fmt2;
221 struct CPRBX cprbx; 216 struct CPRBX cprbx;
222 } __attribute__((packed)) *reply; 217 } __attribute__((packed)) *reply;
218 struct {
219 struct type6_hdr hdr;
220 struct CPRBX cprbx;
221 char function_code[2];
222 short int rule_length;
223 char rule[8];
224 short int verb_length;
225 short int key_length;
226 } __packed * msg;
223 int rc, i; 227 int rc, i;
224 228
225 ap_init_message(&ap_msg); 229 ap_init_message(&ap_msg);
@@ -227,7 +231,11 @@ static int zcrypt_pcixcc_rng_supported(struct ap_device *ap_dev)
227 if (!ap_msg.message) 231 if (!ap_msg.message)
228 return -ENOMEM; 232 return -ENOMEM;
229 233
230 rng_type6CPRB_msgX(ap_dev, &ap_msg, 4); 234 rng_type6CPRB_msgX(&ap_msg, 4);
235
236 msg = ap_msg.message;
237 msg->cprbx.domain = AP_QID_QUEUE(ap_dev->qid);
238
231 rc = ap_send(ap_dev->qid, 0x0102030405060708ULL, ap_msg.message, 239 rc = ap_send(ap_dev->qid, 0x0102030405060708ULL, ap_msg.message,
232 ap_msg.length); 240 ap_msg.length);
233 if (rc) 241 if (rc)
@@ -267,6 +275,14 @@ out_free:
267static int zcrypt_pcixcc_probe(struct ap_device *ap_dev) 275static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
268{ 276{
269 struct zcrypt_device *zdev; 277 struct zcrypt_device *zdev;
278 /*
279 * Normalized speed ratings per crypto adapter
280 * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY
281 */
282 int PCIXCC_MCL2_SPEED_IDX[] = {10, 10, 10, 10, 10, 10, 10, 10};
283 int PCIXCC_MCL3_SPEED_IDX[] = { 8, 8, 8, 8, 8, 8, 8, 8};
284 int CEX2C_SPEED_IDX[] = {1000, 1400, 2400, 1100, 1500, 2600, 100, 12};
285 int CEX3C_SPEED_IDX[] = { 500, 700, 1400, 550, 800, 1500, 80, 10};
270 int rc = 0; 286 int rc = 0;
271 287
272 zdev = zcrypt_device_alloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE); 288 zdev = zcrypt_device_alloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE);
@@ -284,13 +300,15 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
284 zdev->user_space_type = rc; 300 zdev->user_space_type = rc;
285 if (rc == ZCRYPT_PCIXCC_MCL2) { 301 if (rc == ZCRYPT_PCIXCC_MCL2) {
286 zdev->type_string = "PCIXCC_MCL2"; 302 zdev->type_string = "PCIXCC_MCL2";
287 zdev->speed_rating = PCIXCC_MCL2_SPEED_RATING; 303 memcpy(zdev->speed_rating, PCIXCC_MCL2_SPEED_IDX,
304 sizeof(PCIXCC_MCL2_SPEED_IDX));
288 zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE_OLD; 305 zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE_OLD;
289 zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE; 306 zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE;
290 zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE; 307 zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE;
291 } else { 308 } else {
292 zdev->type_string = "PCIXCC_MCL3"; 309 zdev->type_string = "PCIXCC_MCL3";
293 zdev->speed_rating = PCIXCC_MCL3_SPEED_RATING; 310 memcpy(zdev->speed_rating, PCIXCC_MCL3_SPEED_IDX,
311 sizeof(PCIXCC_MCL3_SPEED_IDX));
294 zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE; 312 zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE;
295 zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE; 313 zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE;
296 zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE; 314 zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE;
@@ -299,7 +317,8 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
299 case AP_DEVICE_TYPE_CEX2C: 317 case AP_DEVICE_TYPE_CEX2C:
300 zdev->user_space_type = ZCRYPT_CEX2C; 318 zdev->user_space_type = ZCRYPT_CEX2C;
301 zdev->type_string = "CEX2C"; 319 zdev->type_string = "CEX2C";
302 zdev->speed_rating = CEX2C_SPEED_RATING; 320 memcpy(zdev->speed_rating, CEX2C_SPEED_IDX,
321 sizeof(CEX2C_SPEED_IDX));
303 zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE; 322 zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE;
304 zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE; 323 zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE;
305 zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE; 324 zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE;
@@ -307,7 +326,8 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
307 case AP_DEVICE_TYPE_CEX3C: 326 case AP_DEVICE_TYPE_CEX3C:
308 zdev->user_space_type = ZCRYPT_CEX3C; 327 zdev->user_space_type = ZCRYPT_CEX3C;
309 zdev->type_string = "CEX3C"; 328 zdev->type_string = "CEX3C";
310 zdev->speed_rating = CEX3C_SPEED_RATING; 329 memcpy(zdev->speed_rating, CEX3C_SPEED_IDX,
330 sizeof(CEX3C_SPEED_IDX));
311 zdev->min_mod_size = CEX3C_MIN_MOD_SIZE; 331 zdev->min_mod_size = CEX3C_MIN_MOD_SIZE;
312 zdev->max_mod_size = CEX3C_MAX_MOD_SIZE; 332 zdev->max_mod_size = CEX3C_MAX_MOD_SIZE;
313 zdev->max_exp_bit_length = CEX3C_MAX_MOD_SIZE; 333 zdev->max_exp_bit_length = CEX3C_MAX_MOD_SIZE;
@@ -315,6 +335,7 @@ static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
315 default: 335 default:
316 goto out_free; 336 goto out_free;
317 } 337 }
338 zdev->load = zdev->speed_rating[0];
318 339
319 rc = zcrypt_pcixcc_rng_supported(ap_dev); 340 rc = zcrypt_pcixcc_rng_supported(ap_dev);
320 if (rc < 0) { 341 if (rc < 0) {