Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: sep: reworked crypto layer

This gets the SEP crypto layer up and running with things like dmcrypt.
It's a fairly big set of changes because it has to rework the whole context
handling system.

[This is picked out of the differences between the upstream driver and
the staging driver. I'm resolving the differences as a series of updates -AC]

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mark A. Allyn and committed by
Greg Kroah-Hartman
9196dc11 ab8ef351

+1719 -1423
+1674 -1388
drivers/staging/sep/sep_crypto.c
··· 88 88 * This will only print dump if DEBUG is set; it does 89 89 * follow kernel debug print enabling 90 90 */ 91 - static void crypto_sep_dump_message(struct sep_system_ctx *sctx) 91 + static void crypto_sep_dump_message(struct sep_device *sep, void *msg) 92 92 { 93 93 #if 0 94 94 u32 *p; 95 95 u32 *i; 96 96 int count; 97 97 98 - p = sctx->sep_used->shared_addr; 99 - i = (u32 *)sctx->msg; 100 - for (count = 0; count < 40 * 4; count += 4) 101 - dev_dbg(&sctx->sep_used->pdev->dev, 98 + p = sep->shared_addr; 99 + i = (u32 *)msg; 100 + for (count = 0; count < 10 * 4; count += 4) 101 + dev_dbg(&sep->pdev->dev, 102 102 "[PID%d] Word %d of the message is %x (local)%x\n", 103 103 current->pid, count/4, *p++, *i++); 104 104 #endif ··· 534 534 #endif 535 535 } 536 536 537 + /* Debug - prints only if DEBUG is defined */ 538 + static void sep_dump_ivs(struct ablkcipher_request *req, char *reason) 539 + 540 + { 541 + unsigned char *cptr; 542 + struct sep_aes_internal_context *aes_internal; 543 + struct sep_des_internal_context *des_internal; 544 + int ct1; 545 + 546 + struct this_task_ctx *ta_ctx; 547 + struct crypto_ablkcipher *tfm; 548 + struct sep_system_ctx *sctx; 549 + 550 + ta_ctx = ablkcipher_request_ctx(req); 551 + tfm = crypto_ablkcipher_reqtfm(req); 552 + sctx = crypto_ablkcipher_ctx(tfm); 553 + 554 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "IV DUMP - %s\n", reason); 555 + if ((ta_ctx->current_request == DES_CBC) && 556 + (ta_ctx->des_opmode == SEP_DES_CBC)) { 557 + 558 + des_internal = (struct sep_des_internal_context *) 559 + sctx->des_private_ctx.ctx_buf; 560 + /* print vendor */ 561 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 562 + "sep - vendor iv for DES\n"); 563 + cptr = (unsigned char *)des_internal->iv_context; 564 + for (ct1 = 0; ct1 < crypto_ablkcipher_ivsize(tfm); ct1 += 1) 565 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 566 + "%02x\n", *(cptr + ct1)); 567 + 568 + /* print walk */ 569 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 570 + "sep - walk from kernel crypto iv for DES\n"); 571 + cptr = (unsigned char *)ta_ctx->walk.iv; 572 + for (ct1 = 0; ct1 < crypto_ablkcipher_ivsize(tfm); ct1 += 1) 573 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 574 + "%02x\n", *(cptr + ct1)); 575 + } else if ((ta_ctx->current_request == AES_CBC) && 576 + (ta_ctx->aes_opmode == SEP_AES_CBC)) { 577 + 578 + aes_internal = (struct sep_aes_internal_context *) 579 + sctx->aes_private_ctx.cbuff; 580 + /* print vendor */ 581 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 582 + "sep - vendor iv for AES\n"); 583 + cptr = (unsigned char *)aes_internal->aes_ctx_iv; 584 + for (ct1 = 0; ct1 < crypto_ablkcipher_ivsize(tfm); ct1 += 1) 585 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 586 + "%02x\n", *(cptr + ct1)); 587 + 588 + /* print walk */ 589 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 590 + "sep - walk from kernel crypto iv for AES\n"); 591 + cptr = (unsigned char *)ta_ctx->walk.iv; 592 + for (ct1 = 0; ct1 < crypto_ablkcipher_ivsize(tfm); ct1 += 1) 593 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 594 + "%02x\n", *(cptr + ct1)); 595 + } 596 + } 597 + 537 598 /** 538 599 * RFC2451: Weak key check 539 600 * Returns: 1 (weak), 0 (not weak) ··· 732 671 733 672 /** 734 673 * sep_start_msg - 735 - * @sctx: pointer to struct sep_system_ctx 674 + * @ta_ctx: pointer to struct this_task_ctx 736 675 * @returns: offset to place for the next word in the message 737 676 * Set up pointer in message pool for new message 738 677 */ 739 - static u32 sep_start_msg(struct sep_system_ctx *sctx) 678 + static u32 sep_start_msg(struct this_task_ctx *ta_ctx) 740 679 { 741 680 u32 *word_ptr; 742 - sctx->msg_len_words = 2; 743 - sctx->msgptr = sctx->msg; 744 - memset(sctx->msg, 0, SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 745 - sctx->msgptr += sizeof(u32) * 2; 746 - word_ptr = (u32 *)sctx->msgptr; 681 + ta_ctx->msg_len_words = 2; 682 + ta_ctx->msgptr = ta_ctx->msg; 683 + memset(ta_ctx->msg, 0, SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 684 + ta_ctx->msgptr += sizeof(u32) * 2; 685 + word_ptr = (u32 *)ta_ctx->msgptr; 747 686 *word_ptr = SEP_START_MSG_TOKEN; 748 687 return sizeof(u32) * 2; 749 688 } 750 689 751 690 /** 752 691 * sep_end_msg - 753 - * @sctx: pointer to struct sep_system_ctx 692 + * @ta_ctx: pointer to struct this_task_ctx 754 693 * @messages_offset: current message offset 755 694 * Returns: 0 for success; <0 otherwise 756 695 * End message; set length and CRC; and 757 696 * send interrupt to the SEP 758 697 */ 759 - static void sep_end_msg(struct sep_system_ctx *sctx, u32 msg_offset) 698 + static void sep_end_msg(struct this_task_ctx *ta_ctx, u32 msg_offset) 760 699 { 761 700 u32 *word_ptr; 762 701 /* Msg size goes into msg after token */ 763 - sctx->msg_len_words = msg_offset / sizeof(u32) + 1; 764 - word_ptr = (u32 *)sctx->msgptr; 702 + ta_ctx->msg_len_words = msg_offset / sizeof(u32) + 1; 703 + word_ptr = (u32 *)ta_ctx->msgptr; 765 704 word_ptr += 1; 766 - *word_ptr = sctx->msg_len_words; 705 + *word_ptr = ta_ctx->msg_len_words; 767 706 768 707 /* CRC (currently 0) goes at end of msg */ 769 - word_ptr = (u32 *)(sctx->msgptr + msg_offset); 708 + word_ptr = (u32 *)(ta_ctx->msgptr + msg_offset); 770 709 *word_ptr = 0; 771 710 } 772 711 773 712 /** 774 713 * sep_start_inbound_msg - 775 - * @sctx: pointer to struct sep_system_ctx 714 + * @ta_ctx: pointer to struct this_task_ctx 776 715 * @msg_offset: offset to place for the next word in the message 777 716 * @returns: 0 for success; error value for failure 778 717 * Set up pointer in message pool for inbound message 779 718 */ 780 - static u32 sep_start_inbound_msg(struct sep_system_ctx *sctx, u32 *msg_offset) 719 + static u32 sep_start_inbound_msg(struct this_task_ctx *ta_ctx, u32 *msg_offset) 781 720 { 782 721 u32 *word_ptr; 783 722 u32 token; 784 723 u32 error = SEP_OK; 785 724 786 725 *msg_offset = sizeof(u32) * 2; 787 - word_ptr = (u32 *)sctx->msgptr; 726 + word_ptr = (u32 *)ta_ctx->msgptr; 788 727 token = *word_ptr; 789 - sctx->msg_len_words = *(word_ptr + 1); 728 + ta_ctx->msg_len_words = *(word_ptr + 1); 790 729 791 730 if (token != SEP_START_MSG_TOKEN) { 792 731 error = SEP_INVALID_START; ··· 800 739 801 740 /** 802 741 * sep_write_msg - 803 - * @sctx: pointer to struct sep_system_ctx 742 + * @ta_ctx: pointer to struct this_task_ctx 804 743 * @in_addr: pointer to start of parameter 805 744 * @size: size of parameter to copy (in bytes) 806 745 * @max_size: size to move up offset; SEP mesg is in word sizes ··· 808 747 * @byte_array: flag ti indicate wheter endian must be changed 809 748 * Copies data into the message area from caller 810 749 */ 811 - static void sep_write_msg(struct sep_system_ctx *sctx, void *in_addr, 750 + static void sep_write_msg(struct this_task_ctx *ta_ctx, void *in_addr, 812 751 u32 size, u32 max_size, u32 *msg_offset, u32 byte_array) 813 752 { 814 753 u32 *word_ptr; 815 754 void *void_ptr; 816 - void_ptr = sctx->msgptr + *msg_offset; 755 + void_ptr = ta_ctx->msgptr + *msg_offset; 817 756 word_ptr = (u32 *)void_ptr; 818 757 memcpy(void_ptr, in_addr, size); 819 758 *msg_offset += max_size; ··· 828 767 829 768 /** 830 769 * sep_make_header 831 - * @sctx: pointer to struct sep_system_ctx 770 + * @ta_ctx: pointer to struct this_task_ctx 832 771 * @msg_offset: pointer to current offset (is updated) 833 772 * @op_code: op code to put into message 834 773 * Puts op code into message and updates offset 835 774 */ 836 - static void sep_make_header(struct sep_system_ctx *sctx, u32 *msg_offset, 775 + static void sep_make_header(struct this_task_ctx *ta_ctx, u32 *msg_offset, 837 776 u32 op_code) 838 777 { 839 778 u32 *word_ptr; 840 779 841 - *msg_offset = sep_start_msg(sctx); 842 - word_ptr = (u32 *)(sctx->msgptr + *msg_offset); 780 + *msg_offset = sep_start_msg(ta_ctx); 781 + word_ptr = (u32 *)(ta_ctx->msgptr + *msg_offset); 843 782 *word_ptr = op_code; 844 783 *msg_offset += sizeof(u32); 845 784 } ··· 848 787 849 788 /** 850 789 * sep_read_msg - 851 - * @sctx: pointer to struct sep_system_ctx 790 + * @ta_ctx: pointer to struct this_task_ctx 852 791 * @in_addr: pointer to start of parameter 853 792 * @size: size of parameter to copy (in bytes) 854 793 * @max_size: size to move up offset; SEP mesg is in word sizes ··· 856 795 * @byte_array: flag ti indicate wheter endian must be changed 857 796 * Copies data out of the message area to caller 858 797 */ 859 - static void sep_read_msg(struct sep_system_ctx *sctx, void *in_addr, 798 + static void sep_read_msg(struct this_task_ctx *ta_ctx, void *in_addr, 860 799 u32 size, u32 max_size, u32 *msg_offset, u32 byte_array) 861 800 { 862 801 u32 *word_ptr; 863 802 void *void_ptr; 864 - void_ptr = sctx->msgptr + *msg_offset; 803 + void_ptr = ta_ctx->msgptr + *msg_offset; 865 804 word_ptr = (u32 *)void_ptr; 866 805 867 806 /* Do we need to manipulate endian? */ ··· 877 816 878 817 /** 879 818 * sep_verify_op - 880 - * @sctx: pointer to struct sep_system_ctx 819 + * @ta_ctx: pointer to struct this_task_ctx 881 820 * @op_code: expected op_code 882 821 * @msg_offset: pointer to current offset (is updated) 883 822 * @returns: 0 for success; error for failure 884 823 */ 885 - static u32 sep_verify_op(struct sep_system_ctx *sctx, u32 op_code, 824 + static u32 sep_verify_op(struct this_task_ctx *ta_ctx, u32 op_code, 886 825 u32 *msg_offset) 887 826 { 888 827 u32 error; 889 828 u32 in_ary[2]; 890 829 891 - struct sep_device *sep = sctx->sep_used; 830 + struct sep_device *sep = ta_ctx->sep_used; 892 831 893 832 dev_dbg(&sep->pdev->dev, "dumping return message\n"); 894 - error = sep_start_inbound_msg(sctx, msg_offset); 833 + error = sep_start_inbound_msg(ta_ctx, msg_offset); 895 834 if (error) { 896 835 dev_warn(&sep->pdev->dev, 897 836 "sep_start_inbound_msg error\n"); 898 837 return error; 899 838 } 900 839 901 - sep_read_msg(sctx, in_ary, sizeof(u32) * 2, sizeof(u32) * 2, 840 + sep_read_msg(ta_ctx, in_ary, sizeof(u32) * 2, sizeof(u32) * 2, 902 841 msg_offset, 0); 903 842 904 843 if (in_ary[0] != op_code) { ··· 924 863 925 864 /** 926 865 * sep_read_context - 927 - * @sctx: pointer to struct sep_system_ctx 866 + * @ta_ctx: pointer to struct this_task_ctx 928 867 * @msg_offset: point to current place in SEP msg; is updated 929 868 * @dst: pointer to place to put the context 930 869 * @len: size of the context structure (differs for crypro/hash) ··· 934 873 * it skips over some words in the msg area depending on the size 935 874 * of the context 936 875 */ 937 - static void sep_read_context(struct sep_system_ctx *sctx, u32 *msg_offset, 876 + static void sep_read_context(struct this_task_ctx *ta_ctx, u32 *msg_offset, 938 877 void *dst, u32 len) 939 878 { 940 879 u32 max_length = ((len + 3) / sizeof(u32)) * sizeof(u32); 941 - sep_read_msg(sctx, dst, len, max_length, msg_offset, 0); 880 + sep_read_msg(ta_ctx, dst, len, max_length, msg_offset, 0); 942 881 } 943 882 944 883 /** 945 884 * sep_write_context - 946 - * @sctx: pointer to struct sep_system_ctx 885 + * @ta_ctx: pointer to struct this_task_ctx 947 886 * @msg_offset: point to current place in SEP msg; is updated 948 887 * @src: pointer to the current context 949 888 * @len: size of the context structure (differs for crypro/hash) ··· 953 892 * it skips over some words in the msg area depending on the size 954 893 * of the context 955 894 */ 956 - static void sep_write_context(struct sep_system_ctx *sctx, u32 *msg_offset, 895 + static void sep_write_context(struct this_task_ctx *ta_ctx, u32 *msg_offset, 957 896 void *src, u32 len) 958 897 { 959 898 u32 max_length = ((len + 3) / sizeof(u32)) * sizeof(u32); 960 - sep_write_msg(sctx, src, len, max_length, msg_offset, 0); 899 + sep_write_msg(ta_ctx, src, len, max_length, msg_offset, 0); 961 900 } 962 901 963 902 /** 964 903 * sep_clear_out - 965 - * @sctx: pointer to struct sep_system_ctx 904 + * @ta_ctx: pointer to struct this_task_ctx 966 905 * Clear out crypto related values in sep device structure 967 906 * to enable device to be used by anyone; either kernel 968 907 * crypto or userspace app via middleware 969 908 */ 970 - static void sep_clear_out(struct sep_system_ctx *sctx) 909 + static void sep_clear_out(struct this_task_ctx *ta_ctx) 971 910 { 972 - if (sctx->src_sg_hold) { 973 - sep_free_sg_buf(sctx->src_sg_hold); 974 - sctx->src_sg_hold = NULL; 911 + if (ta_ctx->src_sg_hold) { 912 + sep_free_sg_buf(ta_ctx->src_sg_hold); 913 + ta_ctx->src_sg_hold = NULL; 975 914 } 976 915 977 - if (sctx->dst_sg_hold) { 978 - sep_free_sg_buf(sctx->dst_sg_hold); 979 - sctx->dst_sg_hold = NULL; 916 + if (ta_ctx->dst_sg_hold) { 917 + sep_free_sg_buf(ta_ctx->dst_sg_hold); 918 + ta_ctx->dst_sg_hold = NULL; 980 919 } 981 920 982 - sctx->src_sg = NULL; 983 - sctx->dst_sg = NULL; 921 + ta_ctx->src_sg = NULL; 922 + ta_ctx->dst_sg = NULL; 984 923 985 - sep_free_dma_table_data_handler(sctx->sep_used, &sctx->dma_ctx); 924 + sep_free_dma_table_data_handler(ta_ctx->sep_used, &ta_ctx->dma_ctx); 986 925 987 - if (sctx->i_own_sep) { 926 + if (ta_ctx->i_own_sep) { 988 927 /** 989 928 * The following unlocks the sep and makes it available 990 929 * to any other application 991 930 * First, null out crypto entries in sep before relesing it 992 931 */ 993 - sctx->sep_used->current_hash_req = NULL; 994 - sctx->sep_used->current_cypher_req = NULL; 995 - sctx->sep_used->current_request = 0; 996 - sctx->sep_used->current_hash_stage = 0; 997 - sctx->sep_used->sctx = NULL; 998 - sctx->sep_used->in_kernel = 0; 932 + ta_ctx->sep_used->current_hash_req = NULL; 933 + ta_ctx->sep_used->current_cypher_req = NULL; 934 + ta_ctx->sep_used->current_request = 0; 935 + ta_ctx->sep_used->current_hash_stage = 0; 936 + ta_ctx->sep_used->ta_ctx = NULL; 937 + ta_ctx->sep_used->in_kernel = 0; 999 938 1000 - sctx->call_status.status = 0; 939 + ta_ctx->call_status.status = 0; 1001 940 1002 941 /* Remove anything confidentail */ 1003 - memset(sctx->sep_used->shared_addr, 0, 942 + memset(ta_ctx->sep_used->shared_addr, 0, 1004 943 SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 1005 944 1006 - sep_queue_status_remove(sctx->sep_used, &sctx->queue_elem); 945 + sep_queue_status_remove(ta_ctx->sep_used, &ta_ctx->queue_elem); 1007 946 1008 947 #ifdef SEP_ENABLE_RUNTIME_PM 1009 - sctx->sep_used->in_use = 0; 1010 - pm_runtime_mark_last_busy(&sctx->sep_used->pdev->dev); 1011 - pm_runtime_put_autosuspend(&sctx->sep_used->pdev->dev); 948 + ta_ctx->sep_used->in_use = 0; 949 + pm_runtime_mark_last_busy(&ta_ctx->sep_used->pdev->dev); 950 + pm_runtime_put_autosuspend(&ta_ctx->sep_used->pdev->dev); 1012 951 #endif 1013 952 1014 - clear_bit(SEP_WORKING_LOCK_BIT, &sctx->sep_used->in_use_flags); 1015 - sctx->sep_used->pid_doing_transaction = 0; 953 + clear_bit(SEP_WORKING_LOCK_BIT, 954 + &ta_ctx->sep_used->in_use_flags); 955 + ta_ctx->sep_used->pid_doing_transaction = 0; 1016 956 1017 - dev_dbg(&sctx->sep_used->pdev->dev, 957 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1018 958 "[PID%d] waking up next transaction\n", 1019 959 current->pid); 1020 960 1021 961 clear_bit(SEP_TRANSACTION_STARTED_LOCK_BIT, 1022 - &sctx->sep_used->in_use_flags); 1023 - wake_up(&sctx->sep_used->event_transactions); 962 + &ta_ctx->sep_used->in_use_flags); 963 + wake_up(&ta_ctx->sep_used->event_transactions); 1024 964 1025 - sctx->i_own_sep = 0; 965 + ta_ctx->i_own_sep = 0; 1026 966 } 1027 967 } 1028 968 ··· 1031 969 * Release crypto infrastructure from EINPROGRESS and 1032 970 * clear sep_dev so that SEP is available to anyone 1033 971 */ 1034 - static void sep_crypto_release(struct sep_system_ctx *sctx, u32 error) 972 + static void sep_crypto_release(struct sep_system_ctx *sctx, 973 + struct this_task_ctx *ta_ctx, u32 error) 1035 974 { 1036 - struct ahash_request *hash_req = sctx->current_hash_req; 975 + struct ahash_request *hash_req = ta_ctx->current_hash_req; 1037 976 struct ablkcipher_request *cypher_req = 1038 - sctx->current_cypher_req; 1039 - struct sep_device *sep = sctx->sep_used; 977 + ta_ctx->current_cypher_req; 978 + struct sep_device *sep = ta_ctx->sep_used; 1040 979 1041 - sep_clear_out(sctx); 980 + sep_clear_out(ta_ctx); 981 + 982 + /** 983 + * This may not yet exist depending when we 984 + * chose to bail out. If it does exist, set 985 + * it to 1 986 + */ 987 + if (ta_ctx->are_we_done_yet != NULL) 988 + *ta_ctx->are_we_done_yet = 1; 1042 989 1043 990 if (cypher_req != NULL) { 1044 - if (cypher_req->base.complete == NULL) { 1045 - dev_dbg(&sep->pdev->dev, 1046 - "release is null for cypher!"); 1047 - } else { 1048 - cypher_req->base.complete( 1049 - &cypher_req->base, error); 991 + if ((sctx->key_sent == 1) || 992 + ((error != 0) && (error != -EINPROGRESS))) { 993 + if (cypher_req->base.complete == NULL) { 994 + dev_dbg(&sep->pdev->dev, 995 + "release is null for cypher!"); 996 + } else { 997 + cypher_req->base.complete( 998 + &cypher_req->base, error); 999 + } 1050 1000 } 1051 1001 } 1052 1002 ··· 1079 1005 * and it will return 0 if sep is now ours; error value if there 1080 1006 * were problems 1081 1007 */ 1082 - static int sep_crypto_take_sep(struct sep_system_ctx *sctx) 1008 + static int sep_crypto_take_sep(struct this_task_ctx *ta_ctx) 1083 1009 { 1084 - struct sep_device *sep = sctx->sep_used; 1010 + struct sep_device *sep = ta_ctx->sep_used; 1085 1011 int result; 1086 1012 struct sep_msgarea_hdr *my_msg_header; 1087 1013 1088 - my_msg_header = (struct sep_msgarea_hdr *)sctx->msg; 1014 + my_msg_header = (struct sep_msgarea_hdr *)ta_ctx->msg; 1089 1015 1090 1016 /* add to status queue */ 1091 - sctx->queue_elem = sep_queue_status_add(sep, my_msg_header->opcode, 1092 - sctx->nbytes, current->pid, 1017 + ta_ctx->queue_elem = sep_queue_status_add(sep, my_msg_header->opcode, 1018 + ta_ctx->nbytes, current->pid, 1093 1019 current->comm, sizeof(current->comm)); 1094 1020 1095 - if (!sctx->queue_elem) { 1021 + if (!ta_ctx->queue_elem) { 1096 1022 dev_dbg(&sep->pdev->dev, "[PID%d] updating queue" 1097 1023 " status error\n", current->pid); 1098 1024 return -EINVAL; ··· 1107 1033 pm_runtime_get_sync(&sep_dev->pdev->dev); 1108 1034 1109 1035 /* Copy in the message */ 1110 - memcpy(sep->shared_addr, sctx->msg, 1036 + memcpy(sep->shared_addr, ta_ctx->msg, 1111 1037 SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 1112 1038 1113 1039 /* Copy in the dcb information if there is any */ 1114 - if (sctx->dcb_region) { 1040 + if (ta_ctx->dcb_region) { 1115 1041 result = sep_activate_dcb_dmatables_context(sep, 1116 - &sctx->dcb_region, &sctx->dmatables_region, 1117 - sctx->dma_ctx); 1042 + &ta_ctx->dcb_region, &ta_ctx->dmatables_region, 1043 + ta_ctx->dma_ctx); 1118 1044 if (result) 1119 1045 return result; 1120 1046 } 1121 1047 1122 1048 /* Mark the device so we know how to finish the job in the tasklet */ 1123 - if (sctx->current_hash_req) 1124 - sep->current_hash_req = sctx->current_hash_req; 1049 + if (ta_ctx->current_hash_req) 1050 + sep->current_hash_req = ta_ctx->current_hash_req; 1125 1051 else 1126 - sep->current_cypher_req = sctx->current_cypher_req; 1052 + sep->current_cypher_req = ta_ctx->current_cypher_req; 1127 1053 1128 - sep->current_request = sctx->current_request; 1129 - sep->current_hash_stage = sctx->current_hash_stage; 1130 - sep->sctx = sctx; 1054 + sep->current_request = ta_ctx->current_request; 1055 + sep->current_hash_stage = ta_ctx->current_hash_stage; 1056 + sep->ta_ctx = ta_ctx; 1131 1057 sep->in_kernel = 1; 1132 - sctx->i_own_sep = 1; 1058 + ta_ctx->i_own_sep = 1; 1059 + 1060 + /* need to set bit first to avoid race condition with interrupt */ 1061 + set_bit(SEP_LEGACY_SENDMSG_DONE_OFFSET, &ta_ctx->call_status.status); 1133 1062 1134 1063 result = sep_send_command_handler(sep); 1135 1064 1136 1065 dev_dbg(&sep->pdev->dev, "[PID%d]: sending command to the sep\n", 1137 1066 current->pid); 1138 1067 1139 - if (!result) { 1140 - set_bit(SEP_LEGACY_SENDMSG_DONE_OFFSET, 1141 - &sctx->call_status.status); 1068 + if (!result) 1142 1069 dev_dbg(&sep->pdev->dev, "[PID%d]: command sent okay\n", 1143 1070 current->pid); 1071 + else { 1072 + dev_dbg(&sep->pdev->dev, "[PID%d]: cant send command\n", 1073 + current->pid); 1074 + clear_bit(SEP_LEGACY_SENDMSG_DONE_OFFSET, 1075 + &ta_ctx->call_status.status); 1144 1076 } 1145 1077 1146 1078 return result; 1147 1079 } 1148 1080 1149 - /* This needs to be run as a work queue as it can be put asleep */ 1150 - static void sep_crypto_block(void *data) 1081 + /** 1082 + * This function sets things up for a crypto data block process 1083 + * This does all preparation, but does not try to grab the 1084 + * sep 1085 + * @req: pointer to struct ablkcipher_request 1086 + * returns: 0 if all went well, non zero if error 1087 + */ 1088 + static int sep_crypto_block_data(struct ablkcipher_request *req) 1151 1089 { 1090 + 1152 1091 int int_error; 1153 1092 u32 msg_offset; 1154 1093 static u32 msg[10]; ··· 1172 1085 ssize_t copy_result; 1173 1086 int result; 1174 1087 1175 - u32 max_length; 1176 1088 struct scatterlist *new_sg; 1177 - struct ablkcipher_request *req; 1178 - struct sep_block_ctx *bctx; 1089 + struct this_task_ctx *ta_ctx; 1179 1090 struct crypto_ablkcipher *tfm; 1180 1091 struct sep_system_ctx *sctx; 1181 1092 1182 - req = (struct ablkcipher_request *)data; 1183 - bctx = ablkcipher_request_ctx(req); 1093 + struct sep_des_internal_context *des_internal; 1094 + struct sep_aes_internal_context *aes_internal; 1095 + 1096 + ta_ctx = ablkcipher_request_ctx(req); 1184 1097 tfm = crypto_ablkcipher_reqtfm(req); 1185 1098 sctx = crypto_ablkcipher_ctx(tfm); 1186 1099 1187 1100 /* start the walk on scatterlists */ 1188 - ablkcipher_walk_init(&bctx->walk, req->src, req->dst, req->nbytes); 1189 - dev_dbg(&sctx->sep_used->pdev->dev, "sep crypto block data size of %x\n", 1101 + ablkcipher_walk_init(&ta_ctx->walk, req->src, req->dst, req->nbytes); 1102 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "sep crypto block data size of %x\n", 1190 1103 req->nbytes); 1191 1104 1192 - int_error = ablkcipher_walk_phys(req, &bctx->walk); 1105 + int_error = ablkcipher_walk_phys(req, &ta_ctx->walk); 1193 1106 if (int_error) { 1194 - dev_warn(&sctx->sep_used->pdev->dev, "walk phys error %x\n", 1107 + dev_warn(&ta_ctx->sep_used->pdev->dev, "walk phys error %x\n", 1195 1108 int_error); 1196 - sep_crypto_release(sctx, -ENOMEM); 1197 - return; 1109 + return -ENOMEM; 1198 1110 } 1199 1111 1200 - /* check iv */ 1201 - if (bctx->des_opmode == SEP_DES_CBC) { 1202 - if (!bctx->walk.iv) { 1203 - dev_warn(&sctx->sep_used->pdev->dev, "no iv found\n"); 1204 - sep_crypto_release(sctx, -EINVAL); 1205 - return; 1206 - } 1207 - 1208 - memcpy(bctx->iv, bctx->walk.iv, SEP_DES_IV_SIZE_BYTES); 1209 - sep_dump(sctx->sep_used, "iv", bctx->iv, SEP_DES_IV_SIZE_BYTES); 1210 - } 1211 - 1212 - if (bctx->aes_opmode == SEP_AES_CBC) { 1213 - if (!bctx->walk.iv) { 1214 - dev_warn(&sctx->sep_used->pdev->dev, "no iv found\n"); 1215 - sep_crypto_release(sctx, -EINVAL); 1216 - return; 1217 - } 1218 - 1219 - memcpy(bctx->iv, bctx->walk.iv, SEP_AES_IV_SIZE_BYTES); 1220 - sep_dump(sctx->sep_used, "iv", bctx->iv, SEP_AES_IV_SIZE_BYTES); 1221 - } 1222 - 1223 - dev_dbg(&sctx->sep_used->pdev->dev, 1112 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1224 1113 "crypto block: src is %lx dst is %lx\n", 1225 1114 (unsigned long)req->src, (unsigned long)req->dst); 1226 1115 1227 1116 /* Make sure all pages are even block */ 1228 - int_error = sep_oddball_pages(sctx->sep_used, req->src, 1229 - req->nbytes, bctx->walk.blocksize, &new_sg, 1); 1117 + int_error = sep_oddball_pages(ta_ctx->sep_used, req->src, 1118 + req->nbytes, ta_ctx->walk.blocksize, &new_sg, 1); 1230 1119 1231 1120 if (int_error < 0) { 1232 - dev_warn(&sctx->sep_used->pdev->dev, "oddball page eerror\n"); 1233 - sep_crypto_release(sctx, -ENOMEM); 1234 - return; 1121 + dev_warn(&ta_ctx->sep_used->pdev->dev, "oddball page eerror\n"); 1122 + return -ENOMEM; 1235 1123 } else if (int_error == 1) { 1236 - sctx->src_sg = new_sg; 1237 - sctx->src_sg_hold = new_sg; 1124 + ta_ctx->src_sg = new_sg; 1125 + ta_ctx->src_sg_hold = new_sg; 1238 1126 } else { 1239 - sctx->src_sg = req->src; 1240 - sctx->src_sg_hold = NULL; 1127 + ta_ctx->src_sg = req->src; 1128 + ta_ctx->src_sg_hold = NULL; 1241 1129 } 1242 1130 1243 - int_error = sep_oddball_pages(sctx->sep_used, req->dst, 1244 - req->nbytes, bctx->walk.blocksize, &new_sg, 0); 1131 + int_error = sep_oddball_pages(ta_ctx->sep_used, req->dst, 1132 + req->nbytes, ta_ctx->walk.blocksize, &new_sg, 0); 1245 1133 1246 1134 if (int_error < 0) { 1247 - dev_warn(&sctx->sep_used->pdev->dev, "walk phys error %x\n", 1135 + dev_warn(&ta_ctx->sep_used->pdev->dev, "walk phys error %x\n", 1248 1136 int_error); 1249 - sep_crypto_release(sctx, -ENOMEM); 1250 - return; 1137 + return -ENOMEM; 1251 1138 } else if (int_error == 1) { 1252 - sctx->dst_sg = new_sg; 1253 - sctx->dst_sg_hold = new_sg; 1139 + ta_ctx->dst_sg = new_sg; 1140 + ta_ctx->dst_sg_hold = new_sg; 1254 1141 } else { 1255 - sctx->dst_sg = req->dst; 1256 - sctx->dst_sg_hold = NULL; 1142 + ta_ctx->dst_sg = req->dst; 1143 + ta_ctx->dst_sg_hold = NULL; 1257 1144 } 1258 1145 1259 - /* Do we need to perform init; ie; send key to sep? */ 1260 - if (sctx->key_sent == 0) { 1146 + /* set nbytes for queue status */ 1147 + ta_ctx->nbytes = req->nbytes; 1261 1148 1262 - dev_dbg(&sctx->sep_used->pdev->dev, "sending key\n"); 1149 + /* Key already done; this is for data */ 1150 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "sending data\n"); 1263 1151 1264 - /* put together message to SEP */ 1265 - /* Start with op code */ 1266 - sep_make_header(sctx, &msg_offset, bctx->init_opcode); 1152 + sep_dump_sg(ta_ctx->sep_used, 1153 + "block sg in", ta_ctx->src_sg); 1267 1154 1268 - /* now deal with IV */ 1269 - if (bctx->init_opcode == SEP_DES_INIT_OPCODE) { 1270 - if (bctx->des_opmode == SEP_DES_CBC) { 1271 - sep_write_msg(sctx, bctx->iv, 1272 - SEP_DES_IV_SIZE_BYTES, sizeof(u32) * 4, 1273 - &msg_offset, 1); 1274 - sep_dump(sctx->sep_used, "initial IV", 1275 - bctx->walk.iv, SEP_DES_IV_SIZE_BYTES); 1276 - } else { 1277 - /* Skip if ECB */ 1278 - msg_offset += 4 * sizeof(u32); 1279 - } 1155 + /* check for valid data and proper spacing */ 1156 + src_ptr = sg_virt(ta_ctx->src_sg); 1157 + dst_ptr = sg_virt(ta_ctx->dst_sg); 1158 + 1159 + if (!src_ptr || !dst_ptr || 1160 + (ta_ctx->current_cypher_req->nbytes % 1161 + crypto_ablkcipher_blocksize(tfm))) { 1162 + 1163 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1164 + "cipher block size odd\n"); 1165 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1166 + "cipher block size is %x\n", 1167 + crypto_ablkcipher_blocksize(tfm)); 1168 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1169 + "cipher data size is %x\n", 1170 + ta_ctx->current_cypher_req->nbytes); 1171 + return -EINVAL; 1172 + } 1173 + 1174 + if (partial_overlap(src_ptr, dst_ptr, 1175 + ta_ctx->current_cypher_req->nbytes)) { 1176 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1177 + "block partial overlap\n"); 1178 + return -EINVAL; 1179 + } 1180 + 1181 + /* Put together the message */ 1182 + sep_make_header(ta_ctx, &msg_offset, ta_ctx->block_opcode); 1183 + 1184 + /* If des, and size is 1 block, put directly in msg */ 1185 + if ((ta_ctx->block_opcode == SEP_DES_BLOCK_OPCODE) && 1186 + (req->nbytes == crypto_ablkcipher_blocksize(tfm))) { 1187 + 1188 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1189 + "writing out one block des\n"); 1190 + 1191 + copy_result = sg_copy_to_buffer( 1192 + ta_ctx->src_sg, sep_sg_nents(ta_ctx->src_sg), 1193 + small_buf, crypto_ablkcipher_blocksize(tfm)); 1194 + 1195 + if (copy_result != crypto_ablkcipher_blocksize(tfm)) { 1196 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1197 + "des block copy faild\n"); 1198 + return -ENOMEM; 1199 + } 1200 + 1201 + /* Put data into message */ 1202 + sep_write_msg(ta_ctx, small_buf, 1203 + crypto_ablkcipher_blocksize(tfm), 1204 + crypto_ablkcipher_blocksize(tfm) * 2, 1205 + &msg_offset, 1); 1206 + 1207 + /* Put size into message */ 1208 + sep_write_msg(ta_ctx, &req->nbytes, 1209 + sizeof(u32), sizeof(u32), &msg_offset, 0); 1210 + } else { 1211 + /* Otherwise, fill out dma tables */ 1212 + ta_ctx->dcb_input_data.app_in_address = src_ptr; 1213 + ta_ctx->dcb_input_data.data_in_size = req->nbytes; 1214 + ta_ctx->dcb_input_data.app_out_address = dst_ptr; 1215 + ta_ctx->dcb_input_data.block_size = 1216 + crypto_ablkcipher_blocksize(tfm); 1217 + ta_ctx->dcb_input_data.tail_block_size = 0; 1218 + ta_ctx->dcb_input_data.is_applet = 0; 1219 + ta_ctx->dcb_input_data.src_sg = ta_ctx->src_sg; 1220 + ta_ctx->dcb_input_data.dst_sg = ta_ctx->dst_sg; 1221 + 1222 + result = sep_create_dcb_dmatables_context_kernel( 1223 + ta_ctx->sep_used, 1224 + &ta_ctx->dcb_region, 1225 + &ta_ctx->dmatables_region, 1226 + &ta_ctx->dma_ctx, 1227 + &ta_ctx->dcb_input_data, 1228 + 1); 1229 + if (result) { 1230 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1231 + "crypto dma table create failed\n"); 1232 + return -EINVAL; 1233 + } 1234 + 1235 + /* Portion of msg is nulled (no data) */ 1236 + msg[0] = (u32)0; 1237 + msg[1] = (u32)0; 1238 + msg[2] = (u32)0; 1239 + msg[3] = (u32)0; 1240 + msg[4] = (u32)0; 1241 + sep_write_msg(ta_ctx, (void *)msg, sizeof(u32) * 5, 1242 + sizeof(u32) * 5, &msg_offset, 0); 1243 + } 1244 + 1245 + /** 1246 + * Before we write the message, we need to overwrite the 1247 + * vendor's IV with the one from our own ablkcipher walk 1248 + * iv because this is needed for dm-crypt 1249 + */ 1250 + sep_dump_ivs(req, "sending data block to sep\n"); 1251 + if ((ta_ctx->current_request == DES_CBC) && 1252 + (ta_ctx->des_opmode == SEP_DES_CBC)) { 1253 + 1254 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1255 + "overwrite vendor iv on DES\n"); 1256 + des_internal = (struct sep_des_internal_context *) 1257 + sctx->des_private_ctx.ctx_buf; 1258 + memcpy((void *)des_internal->iv_context, 1259 + ta_ctx->walk.iv, crypto_ablkcipher_ivsize(tfm)); 1260 + } else if ((ta_ctx->current_request == AES_CBC) && 1261 + (ta_ctx->aes_opmode == SEP_AES_CBC)) { 1262 + 1263 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1264 + "overwrite vendor iv on AES\n"); 1265 + aes_internal = (struct sep_aes_internal_context *) 1266 + sctx->aes_private_ctx.cbuff; 1267 + memcpy((void *)aes_internal->aes_ctx_iv, 1268 + ta_ctx->walk.iv, crypto_ablkcipher_ivsize(tfm)); 1269 + } 1270 + 1271 + /* Write context into message */ 1272 + if (ta_ctx->block_opcode == SEP_DES_BLOCK_OPCODE) { 1273 + sep_write_context(ta_ctx, &msg_offset, 1274 + &sctx->des_private_ctx, 1275 + sizeof(struct sep_des_private_context)); 1276 + sep_dump(ta_ctx->sep_used, "ctx to block des", 1277 + &sctx->des_private_ctx, 40); 1278 + } else { 1279 + sep_write_context(ta_ctx, &msg_offset, 1280 + &sctx->aes_private_ctx, 1281 + sizeof(struct sep_aes_private_context)); 1282 + sep_dump(ta_ctx->sep_used, "ctx to block aes", 1283 + &sctx->aes_private_ctx, 20); 1284 + } 1285 + 1286 + /* conclude message */ 1287 + sep_end_msg(ta_ctx, msg_offset); 1288 + 1289 + /* Parent (caller) is now ready to tell the sep to do ahead */ 1290 + return 0; 1291 + } 1292 + 1293 + 1294 + /** 1295 + * This function sets things up for a crypto key submit process 1296 + * This does all preparation, but does not try to grab the 1297 + * sep 1298 + * @req: pointer to struct ablkcipher_request 1299 + * returns: 0 if all went well, non zero if error 1300 + */ 1301 + static int sep_crypto_send_key(struct ablkcipher_request *req) 1302 + { 1303 + 1304 + int int_error; 1305 + u32 msg_offset; 1306 + static u32 msg[10]; 1307 + 1308 + u32 max_length; 1309 + struct this_task_ctx *ta_ctx; 1310 + struct crypto_ablkcipher *tfm; 1311 + struct sep_system_ctx *sctx; 1312 + 1313 + ta_ctx = ablkcipher_request_ctx(req); 1314 + tfm = crypto_ablkcipher_reqtfm(req); 1315 + sctx = crypto_ablkcipher_ctx(tfm); 1316 + 1317 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "sending key\n"); 1318 + 1319 + /* start the walk on scatterlists */ 1320 + ablkcipher_walk_init(&ta_ctx->walk, req->src, req->dst, req->nbytes); 1321 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1322 + "sep crypto block data size of %x\n", req->nbytes); 1323 + 1324 + int_error = ablkcipher_walk_phys(req, &ta_ctx->walk); 1325 + if (int_error) { 1326 + dev_warn(&ta_ctx->sep_used->pdev->dev, "walk phys error %x\n", 1327 + int_error); 1328 + return -ENOMEM; 1329 + } 1330 + 1331 + /* check iv */ 1332 + if ((ta_ctx->current_request == DES_CBC) && 1333 + (ta_ctx->des_opmode == SEP_DES_CBC)) { 1334 + if (!ta_ctx->walk.iv) { 1335 + dev_warn(&ta_ctx->sep_used->pdev->dev, "no iv found\n"); 1336 + return -EINVAL; 1337 + } 1338 + 1339 + memcpy(ta_ctx->iv, ta_ctx->walk.iv, SEP_DES_IV_SIZE_BYTES); 1340 + sep_dump(ta_ctx->sep_used, "iv", 1341 + ta_ctx->iv, SEP_DES_IV_SIZE_BYTES); 1342 + } 1343 + 1344 + if ((ta_ctx->current_request == AES_CBC) && 1345 + (ta_ctx->aes_opmode == SEP_AES_CBC)) { 1346 + if (!ta_ctx->walk.iv) { 1347 + dev_warn(&ta_ctx->sep_used->pdev->dev, "no iv found\n"); 1348 + return -EINVAL; 1349 + } 1350 + 1351 + memcpy(ta_ctx->iv, ta_ctx->walk.iv, SEP_AES_IV_SIZE_BYTES); 1352 + sep_dump(ta_ctx->sep_used, "iv", 1353 + ta_ctx->iv, SEP_AES_IV_SIZE_BYTES); 1354 + } 1355 + 1356 + /* put together message to SEP */ 1357 + /* Start with op code */ 1358 + sep_make_header(ta_ctx, &msg_offset, ta_ctx->init_opcode); 1359 + 1360 + /* now deal with IV */ 1361 + if (ta_ctx->init_opcode == SEP_DES_INIT_OPCODE) { 1362 + if (ta_ctx->des_opmode == SEP_DES_CBC) { 1363 + sep_write_msg(ta_ctx, ta_ctx->iv, 1364 + SEP_DES_IV_SIZE_BYTES, sizeof(u32) * 4, 1365 + &msg_offset, 1); 1366 + sep_dump(ta_ctx->sep_used, "initial IV", 1367 + ta_ctx->walk.iv, SEP_DES_IV_SIZE_BYTES); 1280 1368 } else { 1281 - max_length = ((SEP_AES_IV_SIZE_BYTES + 3) / 1282 - sizeof(u32)) * sizeof(u32); 1283 - if (bctx->aes_opmode == SEP_AES_CBC) { 1284 - sep_write_msg(sctx, bctx->iv, 1285 - SEP_AES_IV_SIZE_BYTES, max_length, 1286 - &msg_offset, 1); 1287 - sep_dump(sctx->sep_used, "initial IV", 1288 - bctx->walk.iv, SEP_AES_IV_SIZE_BYTES); 1289 - } else { 1369 + /* Skip if ECB */ 1370 + msg_offset += 4 * sizeof(u32); 1371 + } 1372 + } else { 1373 + max_length = ((SEP_AES_IV_SIZE_BYTES + 3) / 1374 + sizeof(u32)) * sizeof(u32); 1375 + if (ta_ctx->aes_opmode == SEP_AES_CBC) { 1376 + sep_write_msg(ta_ctx, ta_ctx->iv, 1377 + SEP_AES_IV_SIZE_BYTES, max_length, 1378 + &msg_offset, 1); 1379 + sep_dump(ta_ctx->sep_used, "initial IV", 1380 + ta_ctx->walk.iv, SEP_AES_IV_SIZE_BYTES); 1381 + } else { 1290 1382 /* Skip if ECB */ 1291 1383 msg_offset += max_length; 1292 1384 } 1293 1385 } 1294 1386 1295 - /* load the key */ 1296 - if (bctx->init_opcode == SEP_DES_INIT_OPCODE) { 1297 - sep_write_msg(sctx, (void *)&sctx->key.des.key1, 1298 - sizeof(u32) * 8, sizeof(u32) * 8, 1299 - &msg_offset, 1); 1387 + /* load the key */ 1388 + if (ta_ctx->init_opcode == SEP_DES_INIT_OPCODE) { 1389 + sep_write_msg(ta_ctx, (void *)&sctx->key.des.key1, 1390 + sizeof(u32) * 8, sizeof(u32) * 8, 1391 + &msg_offset, 1); 1300 1392 1301 - msg[0] = (u32)sctx->des_nbr_keys; 1302 - msg[1] = (u32)bctx->des_encmode; 1303 - msg[2] = (u32)bctx->des_opmode; 1393 + msg[0] = (u32)sctx->des_nbr_keys; 1394 + msg[1] = (u32)ta_ctx->des_encmode; 1395 + msg[2] = (u32)ta_ctx->des_opmode; 1304 1396 1305 - sep_write_msg(sctx, (void *)msg, 1306 - sizeof(u32) * 3, sizeof(u32) * 3, 1307 - &msg_offset, 0); 1308 - } else { 1309 - sep_write_msg(sctx, (void *)&sctx->key.aes, 1310 - sctx->keylen, 1311 - SEP_AES_MAX_KEY_SIZE_BYTES, 1312 - &msg_offset, 1); 1313 - 1314 - msg[0] = (u32)sctx->aes_key_size; 1315 - msg[1] = (u32)bctx->aes_encmode; 1316 - msg[2] = (u32)bctx->aes_opmode; 1317 - msg[3] = (u32)0; /* Secret key is not used */ 1318 - sep_write_msg(sctx, (void *)msg, 1319 - sizeof(u32) * 4, sizeof(u32) * 4, 1320 - &msg_offset, 0); 1321 - } 1322 - 1397 + sep_write_msg(ta_ctx, (void *)msg, 1398 + sizeof(u32) * 3, sizeof(u32) * 3, 1399 + &msg_offset, 0); 1323 1400 } else { 1401 + sep_write_msg(ta_ctx, (void *)&sctx->key.aes, 1402 + sctx->keylen, 1403 + SEP_AES_MAX_KEY_SIZE_BYTES, 1404 + &msg_offset, 1); 1324 1405 1325 - /* set nbytes for queue status */ 1326 - sctx->nbytes = req->nbytes; 1327 - 1328 - /* Key already done; this is for data */ 1329 - dev_dbg(&sctx->sep_used->pdev->dev, "sending data\n"); 1330 - 1331 - sep_dump_sg(sctx->sep_used, 1332 - "block sg in", sctx->src_sg); 1333 - 1334 - /* check for valid data and proper spacing */ 1335 - src_ptr = sg_virt(sctx->src_sg); 1336 - dst_ptr = sg_virt(sctx->dst_sg); 1337 - 1338 - if (!src_ptr || !dst_ptr || 1339 - (sctx->current_cypher_req->nbytes % 1340 - crypto_ablkcipher_blocksize(tfm))) { 1341 - 1342 - dev_warn(&sctx->sep_used->pdev->dev, 1343 - "cipher block size odd\n"); 1344 - dev_warn(&sctx->sep_used->pdev->dev, 1345 - "cipher block size is %x\n", 1346 - crypto_ablkcipher_blocksize(tfm)); 1347 - dev_warn(&sctx->sep_used->pdev->dev, 1348 - "cipher data size is %x\n", 1349 - sctx->current_cypher_req->nbytes); 1350 - sep_crypto_release(sctx, -EINVAL); 1351 - return; 1352 - } 1353 - 1354 - if (partial_overlap(src_ptr, dst_ptr, 1355 - sctx->current_cypher_req->nbytes)) { 1356 - dev_warn(&sctx->sep_used->pdev->dev, 1357 - "block partial overlap\n"); 1358 - sep_crypto_release(sctx, -EINVAL); 1359 - return; 1360 - } 1361 - 1362 - /* Put together the message */ 1363 - sep_make_header(sctx, &msg_offset, bctx->block_opcode); 1364 - 1365 - /* If des, and size is 1 block, put directly in msg */ 1366 - if ((bctx->block_opcode == SEP_DES_BLOCK_OPCODE) && 1367 - (req->nbytes == crypto_ablkcipher_blocksize(tfm))) { 1368 - 1369 - dev_dbg(&sctx->sep_used->pdev->dev, 1370 - "writing out one block des\n"); 1371 - 1372 - copy_result = sg_copy_to_buffer( 1373 - sctx->src_sg, sep_sg_nents(sctx->src_sg), 1374 - small_buf, crypto_ablkcipher_blocksize(tfm)); 1375 - 1376 - if (copy_result != crypto_ablkcipher_blocksize(tfm)) { 1377 - dev_warn(&sctx->sep_used->pdev->dev, 1378 - "des block copy faild\n"); 1379 - sep_crypto_release(sctx, -ENOMEM); 1380 - return; 1381 - } 1382 - 1383 - /* Put data into message */ 1384 - sep_write_msg(sctx, small_buf, 1385 - crypto_ablkcipher_blocksize(tfm), 1386 - crypto_ablkcipher_blocksize(tfm) * 2, 1387 - &msg_offset, 1); 1388 - 1389 - /* Put size into message */ 1390 - sep_write_msg(sctx, &req->nbytes, 1391 - sizeof(u32), sizeof(u32), &msg_offset, 0); 1392 - } else { 1393 - /* Otherwise, fill out dma tables */ 1394 - sctx->dcb_input_data.app_in_address = src_ptr; 1395 - sctx->dcb_input_data.data_in_size = req->nbytes; 1396 - sctx->dcb_input_data.app_out_address = dst_ptr; 1397 - sctx->dcb_input_data.block_size = 1398 - crypto_ablkcipher_blocksize(tfm); 1399 - sctx->dcb_input_data.tail_block_size = 0; 1400 - sctx->dcb_input_data.is_applet = 0; 1401 - sctx->dcb_input_data.src_sg = sctx->src_sg; 1402 - sctx->dcb_input_data.dst_sg = sctx->dst_sg; 1403 - 1404 - result = sep_create_dcb_dmatables_context_kernel( 1405 - sctx->sep_used, 1406 - &sctx->dcb_region, 1407 - &sctx->dmatables_region, 1408 - &sctx->dma_ctx, 1409 - &sctx->dcb_input_data, 1410 - 1); 1411 - if (result) { 1412 - dev_warn(&sctx->sep_used->pdev->dev, 1413 - "crypto dma table create failed\n"); 1414 - sep_crypto_release(sctx, -EINVAL); 1415 - return; 1416 - } 1417 - 1418 - /* Portion of msg is nulled (no data) */ 1419 - msg[0] = (u32)0; 1420 - msg[1] = (u32)0; 1421 - msg[2] = (u32)0; 1422 - msg[3] = (u32)0; 1423 - msg[4] = (u32)0; 1424 - sep_write_msg(sctx, (void *)msg, 1425 - sizeof(u32) * 5, 1426 - sizeof(u32) * 5, 1427 - &msg_offset, 0); 1428 - } 1429 - 1430 - /* Write context into message */ 1431 - if (bctx->block_opcode == SEP_DES_BLOCK_OPCODE) { 1432 - sep_write_context(sctx, &msg_offset, 1433 - &bctx->des_private_ctx, 1434 - sizeof(struct sep_des_private_context)); 1435 - sep_dump(sctx->sep_used, "ctx to block des", 1436 - &bctx->des_private_ctx, 40); 1437 - } else { 1438 - sep_write_context(sctx, &msg_offset, 1439 - &bctx->aes_private_ctx, 1440 - sizeof(struct sep_aes_private_context)); 1441 - sep_dump(sctx->sep_used, "ctx to block aes", 1442 - &bctx->aes_private_ctx, 20); 1443 - } 1406 + msg[0] = (u32)sctx->aes_key_size; 1407 + msg[1] = (u32)ta_ctx->aes_encmode; 1408 + msg[2] = (u32)ta_ctx->aes_opmode; 1409 + msg[3] = (u32)0; /* Secret key is not used */ 1410 + sep_write_msg(ta_ctx, (void *)msg, 1411 + sizeof(u32) * 4, sizeof(u32) * 4, 1412 + &msg_offset, 0); 1444 1413 } 1445 1414 1446 - /* conclude message and then tell sep to do its thing */ 1447 - sctx->done_with_transaction = 0; 1415 + /* conclude message */ 1416 + sep_end_msg(ta_ctx, msg_offset); 1448 1417 1449 - sep_end_msg(sctx, msg_offset); 1450 - result = sep_crypto_take_sep(sctx); 1451 - if (result) { 1452 - dev_warn(&sctx->sep_used->pdev->dev, 1453 - "sep_crypto_take_sep failed\n"); 1454 - sep_crypto_release(sctx, -EINVAL); 1418 + /* Parent (caller) is now ready to tell the sep to do ahead */ 1419 + return 0; 1420 + } 1421 + 1422 + 1423 + /* This needs to be run as a work queue as it can be put asleep */ 1424 + static void sep_crypto_block(void *data) 1425 + { 1426 + unsigned long end_time; 1427 + 1428 + int result; 1429 + 1430 + struct ablkcipher_request *req; 1431 + struct this_task_ctx *ta_ctx; 1432 + struct crypto_ablkcipher *tfm; 1433 + struct sep_system_ctx *sctx; 1434 + int are_we_done_yet; 1435 + 1436 + req = (struct ablkcipher_request *)data; 1437 + ta_ctx = ablkcipher_request_ctx(req); 1438 + tfm = crypto_ablkcipher_reqtfm(req); 1439 + sctx = crypto_ablkcipher_ctx(tfm); 1440 + 1441 + ta_ctx->are_we_done_yet = &are_we_done_yet; 1442 + 1443 + pr_debug("sep_crypto_block\n"); 1444 + pr_debug("tfm is %p sctx is %p ta_ctx is %p\n", 1445 + tfm, sctx, ta_ctx); 1446 + pr_debug("key_sent is %d\n", sctx->key_sent); 1447 + 1448 + /* do we need to send the key */ 1449 + if (sctx->key_sent == 0) { 1450 + are_we_done_yet = 0; 1451 + result = sep_crypto_send_key(req); /* prep to send key */ 1452 + if (result != 0) { 1453 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1454 + "could not prep key %x\n", result); 1455 + sep_crypto_release(sctx, ta_ctx, result); 1456 + return; 1457 + } 1458 + 1459 + result = sep_crypto_take_sep(ta_ctx); 1460 + if (result) { 1461 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1462 + "sep_crypto_take_sep for key send failed\n"); 1463 + sep_crypto_release(sctx, ta_ctx, result); 1464 + return; 1465 + } 1466 + 1467 + /* now we sit and wait up to a fixed time for completion */ 1468 + end_time = jiffies + (WAIT_TIME * HZ); 1469 + while ((time_before(jiffies, end_time)) && 1470 + (are_we_done_yet == 0)) 1471 + schedule(); 1472 + 1473 + /* Done waiting; still not done yet? */ 1474 + if (are_we_done_yet == 0) { 1475 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1476 + "Send key job never got done\n"); 1477 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 1478 + return; 1479 + } 1480 + 1481 + /* Set the key sent variable so this can be skipped later */ 1482 + sctx->key_sent = 1; 1483 + } 1484 + 1485 + /* Key sent (or maybe not if we did not have to), now send block */ 1486 + are_we_done_yet = 0; 1487 + 1488 + result = sep_crypto_block_data(req); 1489 + 1490 + if (result != 0) { 1491 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1492 + "could prep not send block %x\n", result); 1493 + sep_crypto_release(sctx, ta_ctx, result); 1455 1494 return; 1456 1495 } 1457 1496 1458 - /** 1459 - * Sep is now working. Lets wait up to 5 seconds 1460 - * for completion. If it does not complete, we will do 1461 - * a crypto release with -EINVAL to release the 1462 - * kernel crypto infrastructure and let the system 1463 - * continue to boot up 1464 - * We have to wait this long because some crypto 1465 - * operations can take a while 1466 - */ 1497 + result = sep_crypto_take_sep(ta_ctx); 1498 + if (result) { 1499 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1500 + "sep_crypto_take_sep for block send failed\n"); 1501 + sep_crypto_release(sctx, ta_ctx, result); 1502 + return; 1503 + } 1467 1504 1468 - dev_dbg(&sctx->sep_used->pdev->dev, 1469 - "waiting for done with transaction\n"); 1470 - 1471 - sctx->end_time = jiffies + (SEP_TRANSACTION_WAIT_TIME * HZ); 1472 - while ((time_before(jiffies, sctx->end_time)) && 1473 - (!sctx->done_with_transaction)) 1505 + /* now we sit and wait up to a fixed time for completion */ 1506 + end_time = jiffies + (WAIT_TIME * HZ); 1507 + while ((time_before(jiffies, end_time)) && (are_we_done_yet == 0)) 1474 1508 schedule(); 1475 1509 1476 - dev_dbg(&sctx->sep_used->pdev->dev, 1477 - "done waiting for done with transaction\n"); 1478 - 1479 - /* are we done? */ 1480 - if (!sctx->done_with_transaction) { 1481 - /* Nope, lets release and tell crypto no */ 1482 - dev_warn(&sctx->sep_used->pdev->dev, 1483 - "[PID%d] sep_crypto_block never finished\n", 1484 - current->pid); 1485 - sep_crypto_release(sctx, -EINVAL); 1510 + /* Done waiting; still not done yet? */ 1511 + if (are_we_done_yet == 0) { 1512 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1513 + "Send block job never got done\n"); 1514 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 1515 + return; 1486 1516 } 1517 + 1518 + /* That's it; entire thing done, get out of queue */ 1519 + 1520 + pr_debug("crypto_block leaving\n"); 1521 + pr_debug("tfm is %p sctx is %p ta_ctx is %p\n", tfm, sctx, ta_ctx); 1487 1522 } 1488 1523 1489 1524 /** ··· 1614 1405 static u32 crypto_post_op(struct sep_device *sep) 1615 1406 { 1616 1407 /* HERE */ 1617 - int int_error; 1618 1408 u32 u32_error; 1619 1409 u32 msg_offset; 1620 1410 ··· 1621 1413 static char small_buf[100]; 1622 1414 1623 1415 struct ablkcipher_request *req; 1624 - struct sep_block_ctx *bctx; 1416 + struct this_task_ctx *ta_ctx; 1625 1417 struct sep_system_ctx *sctx; 1626 1418 struct crypto_ablkcipher *tfm; 1419 + 1420 + struct sep_des_internal_context *des_internal; 1421 + struct sep_aes_internal_context *aes_internal; 1627 1422 1628 1423 if (!sep->current_cypher_req) 1629 1424 return -EINVAL; ··· 1634 1423 /* hold req since we need to submit work after clearing sep */ 1635 1424 req = sep->current_cypher_req; 1636 1425 1637 - bctx = ablkcipher_request_ctx(sep->current_cypher_req); 1426 + ta_ctx = ablkcipher_request_ctx(sep->current_cypher_req); 1638 1427 tfm = crypto_ablkcipher_reqtfm(sep->current_cypher_req); 1639 1428 sctx = crypto_ablkcipher_ctx(tfm); 1640 1429 1641 - dev_dbg(&sctx->sep_used->pdev->dev, "crypto post_op\n"); 1642 - dev_dbg(&sctx->sep_used->pdev->dev, "crypto post_op message dump\n"); 1643 - crypto_sep_dump_message(sctx); 1430 + pr_debug("crypto_post op\n"); 1431 + pr_debug("key_sent is %d tfm is %p sctx is %p ta_ctx is %p\n", 1432 + sctx->key_sent, tfm, sctx, ta_ctx); 1644 1433 1645 - sctx->done_with_transaction = 1; 1434 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "crypto post_op\n"); 1435 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "crypto post_op message dump\n"); 1436 + crypto_sep_dump_message(ta_ctx->sep_used, ta_ctx->msg); 1646 1437 1647 1438 /* first bring msg from shared area to local area */ 1648 - memcpy(sctx->msg, sep->shared_addr, 1439 + memcpy(ta_ctx->msg, sep->shared_addr, 1649 1440 SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 1650 1441 1651 1442 /* Is this the result of performing init (key to SEP */ 1652 1443 if (sctx->key_sent == 0) { 1653 1444 1654 1445 /* Did SEP do it okay */ 1655 - u32_error = sep_verify_op(sctx, bctx->init_opcode, 1446 + u32_error = sep_verify_op(ta_ctx, ta_ctx->init_opcode, 1656 1447 &msg_offset); 1657 1448 if (u32_error) { 1658 - dev_warn(&sctx->sep_used->pdev->dev, 1449 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1659 1450 "aes init error %x\n", u32_error); 1660 - sep_crypto_release(sctx, u32_error); 1451 + sep_crypto_release(sctx, ta_ctx, u32_error); 1661 1452 return u32_error; 1662 1453 } 1663 1454 1664 1455 /* Read Context */ 1665 - if (bctx->init_opcode == SEP_DES_INIT_OPCODE) { 1666 - sep_read_context(sctx, &msg_offset, 1667 - &bctx->des_private_ctx, 1456 + if (ta_ctx->init_opcode == SEP_DES_INIT_OPCODE) { 1457 + sep_read_context(ta_ctx, &msg_offset, 1458 + &sctx->des_private_ctx, 1668 1459 sizeof(struct sep_des_private_context)); 1669 1460 1670 - sep_dump(sctx->sep_used, "ctx init des", 1671 - &bctx->des_private_ctx, 40); 1461 + sep_dump(ta_ctx->sep_used, "ctx init des", 1462 + &sctx->des_private_ctx, 40); 1672 1463 } else { 1673 - sep_read_context(sctx, &msg_offset, 1674 - &bctx->aes_private_ctx, 1675 - sizeof(struct sep_des_private_context)); 1464 + sep_read_context(ta_ctx, &msg_offset, 1465 + &sctx->aes_private_ctx, 1466 + sizeof(struct sep_aes_private_context)); 1676 1467 1677 - sep_dump(sctx->sep_used, "ctx init aes", 1678 - &bctx->aes_private_ctx, 20); 1468 + sep_dump(ta_ctx->sep_used, "ctx init aes", 1469 + &sctx->aes_private_ctx, 20); 1679 1470 } 1680 1471 1681 - /* We are done with init. Now send out the data */ 1682 - /* first release the sep */ 1472 + sep_dump_ivs(req, "after sending key to sep\n"); 1473 + 1474 + /* key sent went okay; release sep, and set are_we_done_yet */ 1683 1475 sctx->key_sent = 1; 1684 - sep_crypto_release(sctx, -EINPROGRESS); 1685 - 1686 - spin_lock_irq(&queue_lock); 1687 - int_error = crypto_enqueue_request(&sep_queue, &req->base); 1688 - spin_unlock_irq(&queue_lock); 1689 - 1690 - if ((int_error != 0) && (int_error != -EINPROGRESS)) { 1691 - dev_warn(&sctx->sep_used->pdev->dev, 1692 - "spe cypher post op cant queue\n"); 1693 - sep_crypto_release(sctx, int_error); 1694 - return int_error; 1695 - } 1696 - 1697 - /* schedule the data send */ 1698 - int_error = sep_submit_work(sep->workqueue, sep_dequeuer, 1699 - (void *)&sep_queue); 1700 - 1701 - if (int_error) { 1702 - dev_warn(&sep->pdev->dev, 1703 - "cant submit work sep_crypto_block\n"); 1704 - sep_crypto_release(sctx, -EINVAL); 1705 - return -EINVAL; 1706 - } 1476 + sep_crypto_release(sctx, ta_ctx, -EINPROGRESS); 1707 1477 1708 1478 } else { 1709 1479 1710 1480 /** 1711 1481 * This is the result of a block request 1712 1482 */ 1713 - dev_dbg(&sctx->sep_used->pdev->dev, 1483 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1714 1484 "crypto_post_op block response\n"); 1715 1485 1716 - u32_error = sep_verify_op(sctx, bctx->block_opcode, 1486 + u32_error = sep_verify_op(ta_ctx, ta_ctx->block_opcode, 1717 1487 &msg_offset); 1718 1488 1719 1489 if (u32_error) { 1720 - dev_warn(&sctx->sep_used->pdev->dev, 1490 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1721 1491 "sep block error %x\n", u32_error); 1722 - sep_crypto_release(sctx, u32_error); 1492 + sep_crypto_release(sctx, ta_ctx, u32_error); 1723 1493 return -EINVAL; 1724 1494 } 1725 1495 1726 - if (bctx->block_opcode == SEP_DES_BLOCK_OPCODE) { 1496 + if (ta_ctx->block_opcode == SEP_DES_BLOCK_OPCODE) { 1727 1497 1728 - dev_dbg(&sctx->sep_used->pdev->dev, 1498 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1729 1499 "post op for DES\n"); 1730 1500 1731 1501 /* special case for 1 block des */ 1732 1502 if (sep->current_cypher_req->nbytes == 1733 1503 crypto_ablkcipher_blocksize(tfm)) { 1734 1504 1735 - sep_read_msg(sctx, small_buf, 1505 + sep_read_msg(ta_ctx, small_buf, 1736 1506 crypto_ablkcipher_blocksize(tfm), 1737 1507 crypto_ablkcipher_blocksize(tfm) * 2, 1738 1508 &msg_offset, 1); 1739 1509 1740 - dev_dbg(&sctx->sep_used->pdev->dev, 1510 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1741 1511 "reading in block des\n"); 1742 1512 1743 1513 copy_result = sg_copy_from_buffer( 1744 - sctx->dst_sg, 1745 - sep_sg_nents(sctx->dst_sg), 1514 + ta_ctx->dst_sg, 1515 + sep_sg_nents(ta_ctx->dst_sg), 1746 1516 small_buf, 1747 1517 crypto_ablkcipher_blocksize(tfm)); 1748 1518 1749 1519 if (copy_result != 1750 1520 crypto_ablkcipher_blocksize(tfm)) { 1751 1521 1752 - dev_warn(&sctx->sep_used->pdev->dev, 1522 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1753 1523 "des block copy faild\n"); 1754 - sep_crypto_release(sctx, -ENOMEM); 1524 + sep_crypto_release(sctx, ta_ctx, 1525 + -ENOMEM); 1755 1526 return -ENOMEM; 1756 1527 } 1757 1528 } 1758 1529 1759 1530 /* Read Context */ 1760 - sep_read_context(sctx, &msg_offset, 1761 - &bctx->des_private_ctx, 1531 + sep_read_context(ta_ctx, &msg_offset, 1532 + &sctx->des_private_ctx, 1762 1533 sizeof(struct sep_des_private_context)); 1763 1534 } else { 1764 1535 1765 - dev_dbg(&sctx->sep_used->pdev->dev, 1536 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1766 1537 "post op for AES\n"); 1767 1538 1768 1539 /* Skip the MAC Output */ 1769 1540 msg_offset += (sizeof(u32) * 4); 1770 1541 1771 1542 /* Read Context */ 1772 - sep_read_context(sctx, &msg_offset, 1773 - &bctx->aes_private_ctx, 1543 + sep_read_context(ta_ctx, &msg_offset, 1544 + &sctx->aes_private_ctx, 1774 1545 sizeof(struct sep_aes_private_context)); 1775 1546 } 1776 1547 1777 - sep_dump_sg(sctx->sep_used, 1778 - "block sg out", sctx->dst_sg); 1548 + sep_dump_sg(ta_ctx->sep_used, 1549 + "block sg out", ta_ctx->dst_sg); 1779 1550 1780 1551 /* Copy to correct sg if this block had oddball pages */ 1781 - if (sctx->dst_sg_hold) 1782 - sep_copy_sg(sctx->sep_used, 1783 - sctx->dst_sg, 1784 - sctx->current_cypher_req->dst, 1785 - sctx->current_cypher_req->nbytes); 1552 + if (ta_ctx->dst_sg_hold) 1553 + sep_copy_sg(ta_ctx->sep_used, 1554 + ta_ctx->dst_sg, 1555 + ta_ctx->current_cypher_req->dst, 1556 + ta_ctx->current_cypher_req->nbytes); 1557 + 1558 + /** 1559 + * Copy the iv's back to the walk.iv 1560 + * This is required for dm_crypt 1561 + */ 1562 + sep_dump_ivs(req, "got data block from sep\n"); 1563 + if ((ta_ctx->current_request == DES_CBC) && 1564 + (ta_ctx->des_opmode == SEP_DES_CBC)) { 1565 + 1566 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1567 + "returning result iv to walk on DES\n"); 1568 + des_internal = (struct sep_des_internal_context *) 1569 + sctx->des_private_ctx.ctx_buf; 1570 + memcpy(ta_ctx->walk.iv, 1571 + (void *)des_internal->iv_context, 1572 + crypto_ablkcipher_ivsize(tfm)); 1573 + } else if ((ta_ctx->current_request == AES_CBC) && 1574 + (ta_ctx->aes_opmode == SEP_AES_CBC)) { 1575 + 1576 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1577 + "returning result iv to walk on AES\n"); 1578 + aes_internal = (struct sep_aes_internal_context *) 1579 + sctx->aes_private_ctx.cbuff; 1580 + memcpy(ta_ctx->walk.iv, 1581 + (void *)aes_internal->aes_ctx_iv, 1582 + crypto_ablkcipher_ivsize(tfm)); 1583 + } 1786 1584 1787 1585 /* finished, release everything */ 1788 - sep_crypto_release(sctx, 0); 1586 + sep_crypto_release(sctx, ta_ctx, 0); 1789 1587 } 1588 + pr_debug("crypto_post_op done\n"); 1589 + pr_debug("key_sent is %d tfm is %p sctx is %p ta_ctx is %p\n", 1590 + sctx->key_sent, tfm, sctx, ta_ctx); 1591 + 1790 1592 return 0; 1791 1593 } 1792 1594 ··· 1808 1584 u32 u32_error; 1809 1585 u32 msg_offset; 1810 1586 struct crypto_ahash *tfm = crypto_ahash_reqtfm(sep->current_hash_req); 1811 - struct sep_hash_ctx *ctx = ahash_request_ctx(sep->current_hash_req); 1587 + struct this_task_ctx *ta_ctx = ahash_request_ctx(sep->current_hash_req); 1812 1588 struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 1813 - dev_dbg(&sctx->sep_used->pdev->dev, 1589 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1814 1590 "hash init post op\n"); 1815 1591 1816 - sctx->done_with_transaction = 1; 1817 - 1818 1592 /* first bring msg from shared area to local area */ 1819 - memcpy(sctx->msg, sep->shared_addr, 1593 + memcpy(ta_ctx->msg, sep->shared_addr, 1820 1594 SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 1821 1595 1822 - u32_error = sep_verify_op(sctx, SEP_HASH_INIT_OPCODE, 1596 + u32_error = sep_verify_op(ta_ctx, SEP_HASH_INIT_OPCODE, 1823 1597 &msg_offset); 1824 1598 1825 1599 if (u32_error) { 1826 - dev_warn(&sctx->sep_used->pdev->dev, "hash init error %x\n", 1600 + dev_warn(&ta_ctx->sep_used->pdev->dev, "hash init error %x\n", 1827 1601 u32_error); 1828 - sep_crypto_release(sctx, u32_error); 1602 + sep_crypto_release(sctx, ta_ctx, u32_error); 1829 1603 return u32_error; 1830 1604 } 1831 1605 1832 1606 /* Read Context */ 1833 - sep_read_context(sctx, &msg_offset, 1834 - &ctx->hash_private_ctx, 1607 + sep_read_context(ta_ctx, &msg_offset, 1608 + &sctx->hash_private_ctx, 1835 1609 sizeof(struct sep_hash_private_context)); 1836 1610 1837 1611 /* Signal to crypto infrastructure and clear out */ 1838 - dev_dbg(&sctx->sep_used->pdev->dev, "hash init post op done\n"); 1839 - sep_crypto_release(sctx, 0); 1612 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "hash init post op done\n"); 1613 + sep_crypto_release(sctx, ta_ctx, 0); 1840 1614 return 0; 1841 1615 } 1842 1616 ··· 1843 1621 u32 u32_error; 1844 1622 u32 msg_offset; 1845 1623 struct crypto_ahash *tfm = crypto_ahash_reqtfm(sep->current_hash_req); 1846 - struct sep_hash_ctx *ctx = ahash_request_ctx(sep->current_hash_req); 1624 + struct this_task_ctx *ta_ctx = ahash_request_ctx(sep->current_hash_req); 1847 1625 struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 1848 - dev_dbg(&sctx->sep_used->pdev->dev, 1626 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1849 1627 "hash update post op\n"); 1850 1628 1851 - sctx->done_with_transaction = 1; 1852 - 1853 1629 /* first bring msg from shared area to local area */ 1854 - memcpy(sctx->msg, sep->shared_addr, 1630 + memcpy(ta_ctx->msg, sep->shared_addr, 1855 1631 SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 1856 1632 1857 - u32_error = sep_verify_op(sctx, SEP_HASH_UPDATE_OPCODE, 1633 + u32_error = sep_verify_op(ta_ctx, SEP_HASH_UPDATE_OPCODE, 1858 1634 &msg_offset); 1859 1635 1860 1636 if (u32_error) { 1861 - dev_warn(&sctx->sep_used->pdev->dev, "hash init error %x\n", 1637 + dev_warn(&ta_ctx->sep_used->pdev->dev, "hash init error %x\n", 1862 1638 u32_error); 1863 - sep_crypto_release(sctx, u32_error); 1639 + sep_crypto_release(sctx, ta_ctx, u32_error); 1864 1640 return u32_error; 1865 1641 } 1866 1642 1867 1643 /* Read Context */ 1868 - sep_read_context(sctx, &msg_offset, 1869 - &ctx->hash_private_ctx, 1644 + sep_read_context(ta_ctx, &msg_offset, 1645 + &sctx->hash_private_ctx, 1870 1646 sizeof(struct sep_hash_private_context)); 1871 1647 1872 - sep_crypto_release(sctx, 0); 1648 + /** 1649 + * Following is only for finup; if we just completd the 1650 + * data portion of finup, we now need to kick off the 1651 + * finish portion of finup. 1652 + */ 1653 + 1654 + if (ta_ctx->sep_used->current_hash_stage == HASH_FINUP_DATA) { 1655 + 1656 + /* first reset stage to HASH_FINUP_FINISH */ 1657 + ta_ctx->sep_used->current_hash_stage = HASH_FINUP_FINISH; 1658 + 1659 + /* now enqueue the finish operation */ 1660 + spin_lock_irq(&queue_lock); 1661 + u32_error = crypto_enqueue_request(&sep_queue, 1662 + &ta_ctx->sep_used->current_hash_req->base); 1663 + spin_unlock_irq(&queue_lock); 1664 + 1665 + if ((u32_error != 0) && (u32_error != -EINPROGRESS)) { 1666 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1667 + "spe cypher post op cant queue\n"); 1668 + sep_crypto_release(sctx, ta_ctx, u32_error); 1669 + return u32_error; 1670 + } 1671 + 1672 + /* schedule the data send */ 1673 + u32_error = sep_submit_work(ta_ctx->sep_used->workqueue, 1674 + sep_dequeuer, (void *)&sep_queue); 1675 + 1676 + if (u32_error) { 1677 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1678 + "cant submit work sep_crypto_block\n"); 1679 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 1680 + return -EINVAL; 1681 + } 1682 + } 1683 + 1684 + /* Signal to crypto infrastructure and clear out */ 1685 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "hash update post op done\n"); 1686 + sep_crypto_release(sctx, ta_ctx, 0); 1873 1687 return 0; 1874 1688 } 1875 1689 ··· 1916 1658 u32 msg_offset; 1917 1659 struct crypto_ahash *tfm = crypto_ahash_reqtfm(sep->current_hash_req); 1918 1660 struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 1919 - dev_dbg(&sctx->sep_used->pdev->dev, 1661 + struct this_task_ctx *ta_ctx = ahash_request_ctx(sep->current_hash_req); 1662 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1920 1663 "hash final post op\n"); 1921 1664 1922 - sctx->done_with_transaction = 1; 1923 - 1924 1665 /* first bring msg from shared area to local area */ 1925 - memcpy(sctx->msg, sep->shared_addr, 1666 + memcpy(ta_ctx->msg, sep->shared_addr, 1926 1667 SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 1927 1668 1928 - u32_error = sep_verify_op(sctx, SEP_HASH_FINISH_OPCODE, 1669 + u32_error = sep_verify_op(ta_ctx, SEP_HASH_FINISH_OPCODE, 1929 1670 &msg_offset); 1930 1671 1931 1672 if (u32_error) { 1932 - dev_warn(&sctx->sep_used->pdev->dev, "hash finish error %x\n", 1673 + dev_warn(&ta_ctx->sep_used->pdev->dev, "hash finish error %x\n", 1933 1674 u32_error); 1934 - sep_crypto_release(sctx, u32_error); 1675 + sep_crypto_release(sctx, ta_ctx, u32_error); 1935 1676 return u32_error; 1936 1677 } 1937 1678 1938 1679 /* Grab the result */ 1939 - if (sctx->current_hash_req->result == NULL) { 1680 + if (ta_ctx->current_hash_req->result == NULL) { 1940 1681 /* Oops, null buffer; error out here */ 1941 - dev_warn(&sctx->sep_used->pdev->dev, 1682 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1942 1683 "hash finish null buffer\n"); 1943 - sep_crypto_release(sctx, (u32)-ENOMEM); 1684 + sep_crypto_release(sctx, ta_ctx, (u32)-ENOMEM); 1944 1685 return -ENOMEM; 1945 1686 } 1946 1687 1947 1688 max_length = (((SEP_HASH_RESULT_SIZE_WORDS * sizeof(u32)) + 3) / 1948 1689 sizeof(u32)) * sizeof(u32); 1949 1690 1950 - sep_read_msg(sctx, 1951 - sctx->current_hash_req->result, 1691 + sep_read_msg(ta_ctx, 1692 + ta_ctx->current_hash_req->result, 1952 1693 crypto_ahash_digestsize(tfm), max_length, 1953 1694 &msg_offset, 0); 1954 1695 1955 1696 /* Signal to crypto infrastructure and clear out */ 1956 - dev_dbg(&sctx->sep_used->pdev->dev, "hash finish post op done\n"); 1957 - sep_crypto_release(sctx, 0); 1697 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "hash finish post op done\n"); 1698 + sep_crypto_release(sctx, ta_ctx, 0); 1958 1699 return 0; 1959 1700 } 1960 1701 ··· 1964 1707 u32 msg_offset; 1965 1708 struct crypto_ahash *tfm = crypto_ahash_reqtfm(sep->current_hash_req); 1966 1709 struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 1967 - dev_dbg(&sctx->sep_used->pdev->dev, 1710 + struct this_task_ctx *ta_ctx = ahash_request_ctx(sep->current_hash_req); 1711 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1968 1712 "hash digest post op\n"); 1969 1713 1970 - sctx->done_with_transaction = 1; 1971 - 1972 1714 /* first bring msg from shared area to local area */ 1973 - memcpy(sctx->msg, sep->shared_addr, 1715 + memcpy(ta_ctx->msg, sep->shared_addr, 1974 1716 SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES); 1975 1717 1976 - u32_error = sep_verify_op(sctx, SEP_HASH_SINGLE_OPCODE, 1718 + u32_error = sep_verify_op(ta_ctx, SEP_HASH_SINGLE_OPCODE, 1977 1719 &msg_offset); 1978 1720 1979 1721 if (u32_error) { 1980 - dev_warn(&sctx->sep_used->pdev->dev, 1722 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1981 1723 "hash digest finish error %x\n", u32_error); 1982 1724 1983 - sep_crypto_release(sctx, u32_error); 1725 + sep_crypto_release(sctx, ta_ctx, u32_error); 1984 1726 return u32_error; 1985 1727 } 1986 1728 1987 1729 /* Grab the result */ 1988 - if (sctx->current_hash_req->result == NULL) { 1730 + if (ta_ctx->current_hash_req->result == NULL) { 1989 1731 /* Oops, null buffer; error out here */ 1990 - dev_warn(&sctx->sep_used->pdev->dev, 1732 + dev_warn(&ta_ctx->sep_used->pdev->dev, 1991 1733 "hash digest finish null buffer\n"); 1992 - sep_crypto_release(sctx, (u32)-ENOMEM); 1734 + sep_crypto_release(sctx, ta_ctx, (u32)-ENOMEM); 1993 1735 return -ENOMEM; 1994 1736 } 1995 1737 1996 1738 max_length = (((SEP_HASH_RESULT_SIZE_WORDS * sizeof(u32)) + 3) / 1997 1739 sizeof(u32)) * sizeof(u32); 1998 1740 1999 - sep_read_msg(sctx, 2000 - sctx->current_hash_req->result, 1741 + sep_read_msg(ta_ctx, 1742 + ta_ctx->current_hash_req->result, 2001 1743 crypto_ahash_digestsize(tfm), max_length, 2002 1744 &msg_offset, 0); 2003 1745 2004 1746 /* Signal to crypto infrastructure and clear out */ 2005 - dev_dbg(&sctx->sep_used->pdev->dev, 1747 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2006 1748 "hash digest finish post op done\n"); 2007 1749 2008 - sep_crypto_release(sctx, 0); 1750 + sep_crypto_release(sctx, ta_ctx, 0); 2009 1751 return 0; 2010 1752 } 2011 1753 ··· 2015 1759 */ 2016 1760 static void sep_finish(unsigned long data) 2017 1761 { 2018 - unsigned long flags; 2019 1762 struct sep_device *sep_dev; 2020 1763 int res; 2021 1764 ··· 2031 1776 return; 2032 1777 } 2033 1778 2034 - spin_lock_irqsave(&sep_dev->busy_lock, flags); 2035 1779 if (sep_dev->in_kernel == (u32)0) { 2036 - spin_unlock_irqrestore(&sep_dev->busy_lock, flags); 2037 1780 dev_warn(&sep_dev->pdev->dev, 2038 1781 "sep_finish; not in kernel operation\n"); 2039 1782 return; 2040 1783 } 2041 - spin_unlock_irqrestore(&sep_dev->busy_lock, flags); 2042 1784 2043 1785 /* Did we really do a sep command prior to this? */ 2044 1786 if (0 == test_bit(SEP_LEGACY_SENDMSG_DONE_OFFSET, 2045 - &sep_dev->sctx->call_status.status)) { 1787 + &sep_dev->ta_ctx->call_status.status)) { 2046 1788 2047 1789 dev_warn(&sep_dev->pdev->dev, "[PID%d] sendmsg not called\n", 2048 1790 current->pid); ··· 2108 1856 res = hash_init_post_op(sep_dev); 2109 1857 break; 2110 1858 case HASH_UPDATE: 1859 + case HASH_FINUP_DATA: 2111 1860 res = hash_update_post_op(sep_dev); 2112 1861 break; 1862 + case HASH_FINUP_FINISH: 2113 1863 case HASH_FINISH: 2114 1864 res = hash_final_post_op(sep_dev); 2115 1865 break; ··· 2119 1865 res = hash_digest_post_op(sep_dev); 2120 1866 break; 2121 1867 default: 2122 - dev_warn(&sep_dev->pdev->dev, 2123 - "invalid stage for hash finish\n"); 1868 + pr_debug("sep - invalid stage for hash finish\n"); 2124 1869 } 2125 1870 break; 2126 1871 default: 2127 - dev_warn(&sep_dev->pdev->dev, 2128 - "invalid request for finish\n"); 1872 + pr_debug("sep - invalid request for finish\n"); 2129 1873 } 2130 1874 2131 - if (res) { 2132 - dev_warn(&sep_dev->pdev->dev, 2133 - "finish returned error %x\n", res); 2134 - } 1875 + if (res) 1876 + pr_debug("sep - finish returned error %x\n", res); 2135 1877 } 2136 1878 2137 1879 static int sep_hash_cra_init(struct crypto_tfm *tfm) 2138 1880 { 2139 - struct sep_system_ctx *sctx = crypto_tfm_ctx(tfm); 2140 1881 const char *alg_name = crypto_tfm_alg_name(tfm); 2141 1882 2142 - sctx->sep_used = sep_dev; 2143 - 2144 - dev_dbg(&sctx->sep_used->pdev->dev, 2145 - "sep_hash_cra_init name is %s\n", alg_name); 1883 + pr_debug("sep_hash_cra_init name is %s\n", alg_name); 2146 1884 2147 1885 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), 2148 - sizeof(struct sep_hash_ctx)); 1886 + sizeof(struct this_task_ctx)); 2149 1887 return 0; 2150 1888 } 2151 1889 2152 1890 static void sep_hash_cra_exit(struct crypto_tfm *tfm) 2153 1891 { 2154 - struct sep_system_ctx *sctx = crypto_tfm_ctx(tfm); 2155 - 2156 - dev_dbg(&sctx->sep_used->pdev->dev, 2157 - "sep_hash_cra_exit\n"); 2158 - sctx->sep_used = NULL; 1892 + pr_debug("sep_hash_cra_exit\n"); 2159 1893 } 2160 1894 2161 1895 static void sep_hash_init(void *data) ··· 2152 1910 int result; 2153 1911 struct ahash_request *req; 2154 1912 struct crypto_ahash *tfm; 2155 - struct sep_hash_ctx *ctx; 1913 + struct this_task_ctx *ta_ctx; 2156 1914 struct sep_system_ctx *sctx; 1915 + unsigned long end_time; 1916 + int are_we_done_yet; 2157 1917 2158 1918 req = (struct ahash_request *)data; 2159 1919 tfm = crypto_ahash_reqtfm(req); 2160 - ctx = ahash_request_ctx(req); 2161 1920 sctx = crypto_ahash_ctx(tfm); 1921 + ta_ctx = ahash_request_ctx(req); 1922 + ta_ctx->sep_used = sep_dev; 2162 1923 2163 - dev_dbg(&sctx->sep_used->pdev->dev, 1924 + ta_ctx->are_we_done_yet = &are_we_done_yet; 1925 + 1926 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2164 1927 "sep_hash_init\n"); 2165 - sctx->current_hash_stage = HASH_INIT; 1928 + ta_ctx->current_hash_stage = HASH_INIT; 2166 1929 /* opcode and mode */ 2167 - sep_make_header(sctx, &msg_offset, SEP_HASH_INIT_OPCODE); 2168 - sep_write_msg(sctx, &ctx->hash_opmode, 1930 + sep_make_header(ta_ctx, &msg_offset, SEP_HASH_INIT_OPCODE); 1931 + sep_write_msg(ta_ctx, &ta_ctx->hash_opmode, 2169 1932 sizeof(u32), sizeof(u32), &msg_offset, 0); 2170 - sep_end_msg(sctx, msg_offset); 1933 + sep_end_msg(ta_ctx, msg_offset); 2171 1934 2172 - sctx->done_with_transaction = 0; 2173 - 2174 - result = sep_crypto_take_sep(sctx); 1935 + are_we_done_yet = 0; 1936 + result = sep_crypto_take_sep(ta_ctx); 2175 1937 if (result) { 2176 - dev_warn(&sctx->sep_used->pdev->dev, 1938 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2177 1939 "sep_hash_init take sep failed\n"); 2178 - sep_crypto_release(sctx, -EINVAL); 1940 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2179 1941 } 2180 1942 2181 - /** 2182 - * Sep is now working. Lets wait up to 5 seconds 2183 - * for completion. If it does not complete, we will do 2184 - * a crypto release with -EINVAL to release the 2185 - * kernel crypto infrastructure and let the system 2186 - * continue to boot up 2187 - * We have to wait this long because some crypto 2188 - * operations can take a while 2189 - */ 2190 - dev_dbg(&sctx->sep_used->pdev->dev, 2191 - "waiting for done with transaction\n"); 2192 - 2193 - sctx->end_time = jiffies + (SEP_TRANSACTION_WAIT_TIME * HZ); 2194 - while ((time_before(jiffies, sctx->end_time)) && 2195 - (!sctx->done_with_transaction)) 1943 + /* now we sit and wait up to a fixed time for completion */ 1944 + end_time = jiffies + (WAIT_TIME * HZ); 1945 + while ((time_before(jiffies, end_time)) && (are_we_done_yet == 0)) 2196 1946 schedule(); 2197 1947 2198 - dev_dbg(&sctx->sep_used->pdev->dev, 2199 - "done waiting for done with transaction\n"); 2200 - 2201 - /* are we done? */ 2202 - if (!sctx->done_with_transaction) { 2203 - /* Nope, lets release and tell crypto no */ 2204 - dev_warn(&sctx->sep_used->pdev->dev, 2205 - "[PID%d] sep_hash_init never finished\n", 2206 - current->pid); 2207 - sep_crypto_release(sctx, -EINVAL); 1948 + /* Done waiting; still not done yet? */ 1949 + if (are_we_done_yet == 0) { 1950 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 1951 + "hash init never got done\n"); 1952 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 1953 + return; 2208 1954 } 1955 + 2209 1956 } 2210 1957 2211 1958 static void sep_hash_update(void *data) ··· 2206 1975 u32 block_size; 2207 1976 u32 head_len; 2208 1977 u32 tail_len; 1978 + int are_we_done_yet; 1979 + 2209 1980 static u32 msg[10]; 2210 1981 static char small_buf[100]; 2211 1982 void *src_ptr; ··· 2215 1982 ssize_t copy_result; 2216 1983 struct ahash_request *req; 2217 1984 struct crypto_ahash *tfm; 2218 - struct sep_hash_ctx *ctx; 1985 + struct this_task_ctx *ta_ctx; 2219 1986 struct sep_system_ctx *sctx; 1987 + unsigned long end_time; 2220 1988 2221 1989 req = (struct ahash_request *)data; 2222 1990 tfm = crypto_ahash_reqtfm(req); 2223 - ctx = ahash_request_ctx(req); 2224 1991 sctx = crypto_ahash_ctx(tfm); 1992 + ta_ctx = ahash_request_ctx(req); 1993 + ta_ctx->sep_used = sep_dev; 1994 + 1995 + ta_ctx->are_we_done_yet = &are_we_done_yet; 2225 1996 2226 1997 /* length for queue status */ 2227 - sctx->nbytes = req->nbytes; 1998 + ta_ctx->nbytes = req->nbytes; 2228 1999 2229 - dev_dbg(&sctx->sep_used->pdev->dev, 2000 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2230 2001 "sep_hash_update\n"); 2231 - sctx->current_hash_stage = HASH_UPDATE; 2002 + ta_ctx->current_hash_stage = HASH_UPDATE; 2232 2003 len = req->nbytes; 2233 2004 2234 2005 block_size = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); 2235 2006 tail_len = req->nbytes % block_size; 2236 - dev_dbg(&sctx->sep_used->pdev->dev, "length is %x\n", len); 2237 - dev_dbg(&sctx->sep_used->pdev->dev, "block_size is %x\n", block_size); 2238 - dev_dbg(&sctx->sep_used->pdev->dev, "tail len is %x\n", tail_len); 2007 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "length is %x\n", len); 2008 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "block_size is %x\n", block_size); 2009 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "tail len is %x\n", tail_len); 2239 2010 2240 2011 /* Compute header/tail sizes */ 2241 - int_ctx = (struct sep_hash_internal_context *)&ctx-> 2012 + int_ctx = (struct sep_hash_internal_context *)&sctx-> 2242 2013 hash_private_ctx.internal_context; 2243 2014 head_len = (block_size - int_ctx->prev_update_bytes) % block_size; 2244 2015 tail_len = (req->nbytes - head_len) % block_size; 2245 2016 2246 2017 /* Make sure all pages are even block */ 2247 - int_error = sep_oddball_pages(sctx->sep_used, req->src, 2018 + int_error = sep_oddball_pages(ta_ctx->sep_used, req->src, 2248 2019 req->nbytes, 2249 2020 block_size, &new_sg, 1); 2250 2021 2251 2022 if (int_error < 0) { 2252 - dev_warn(&sctx->sep_used->pdev->dev, 2023 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2253 2024 "oddball pages error in crash update\n"); 2254 - sep_crypto_release(sctx, -ENOMEM); 2025 + sep_crypto_release(sctx, ta_ctx, -ENOMEM); 2255 2026 return; 2256 2027 } else if (int_error == 1) { 2257 - sctx->src_sg = new_sg; 2258 - sctx->src_sg_hold = new_sg; 2028 + ta_ctx->src_sg = new_sg; 2029 + ta_ctx->src_sg_hold = new_sg; 2259 2030 } else { 2260 - sctx->src_sg = req->src; 2261 - sctx->src_sg_hold = NULL; 2031 + ta_ctx->src_sg = req->src; 2032 + ta_ctx->src_sg_hold = NULL; 2262 2033 } 2263 2034 2264 - src_ptr = sg_virt(sctx->src_sg); 2035 + src_ptr = sg_virt(ta_ctx->src_sg); 2265 2036 2266 - if ((!req->nbytes) || (!ctx->sg)) { 2037 + if ((!req->nbytes) || (!ta_ctx->src_sg)) { 2267 2038 /* null data */ 2268 2039 src_ptr = NULL; 2269 2040 } 2270 2041 2271 - sep_dump_sg(sctx->sep_used, "hash block sg in", sctx->src_sg); 2042 + sep_dump_sg(ta_ctx->sep_used, "hash block sg in", ta_ctx->src_sg); 2272 2043 2273 - sctx->dcb_input_data.app_in_address = src_ptr; 2274 - sctx->dcb_input_data.data_in_size = req->nbytes - (head_len + tail_len); 2275 - sctx->dcb_input_data.app_out_address = NULL; 2276 - sctx->dcb_input_data.block_size = block_size; 2277 - sctx->dcb_input_data.tail_block_size = 0; 2278 - sctx->dcb_input_data.is_applet = 0; 2279 - sctx->dcb_input_data.src_sg = sctx->src_sg; 2280 - sctx->dcb_input_data.dst_sg = NULL; 2044 + ta_ctx->dcb_input_data.app_in_address = src_ptr; 2045 + ta_ctx->dcb_input_data.data_in_size = 2046 + req->nbytes - (head_len + tail_len); 2047 + ta_ctx->dcb_input_data.app_out_address = NULL; 2048 + ta_ctx->dcb_input_data.block_size = block_size; 2049 + ta_ctx->dcb_input_data.tail_block_size = 0; 2050 + ta_ctx->dcb_input_data.is_applet = 0; 2051 + ta_ctx->dcb_input_data.src_sg = ta_ctx->src_sg; 2052 + ta_ctx->dcb_input_data.dst_sg = NULL; 2281 2053 2282 2054 int_error = sep_create_dcb_dmatables_context_kernel( 2283 - sctx->sep_used, 2284 - &sctx->dcb_region, 2285 - &sctx->dmatables_region, 2286 - &sctx->dma_ctx, 2287 - &sctx->dcb_input_data, 2055 + ta_ctx->sep_used, 2056 + &ta_ctx->dcb_region, 2057 + &ta_ctx->dmatables_region, 2058 + &ta_ctx->dma_ctx, 2059 + &ta_ctx->dcb_input_data, 2288 2060 1); 2289 2061 if (int_error) { 2290 - dev_warn(&sctx->sep_used->pdev->dev, 2062 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2291 2063 "hash update dma table create failed\n"); 2292 - sep_crypto_release(sctx, -EINVAL); 2064 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2293 2065 return; 2294 2066 } 2295 2067 2296 2068 /* Construct message to SEP */ 2297 - sep_make_header(sctx, &msg_offset, SEP_HASH_UPDATE_OPCODE); 2069 + sep_make_header(ta_ctx, &msg_offset, SEP_HASH_UPDATE_OPCODE); 2298 2070 2299 2071 msg[0] = (u32)0; 2300 2072 msg[1] = (u32)0; 2301 2073 msg[2] = (u32)0; 2302 2074 2303 - sep_write_msg(sctx, msg, sizeof(u32) * 3, sizeof(u32) * 3, 2075 + sep_write_msg(ta_ctx, msg, sizeof(u32) * 3, sizeof(u32) * 3, 2304 2076 &msg_offset, 0); 2305 2077 2306 2078 /* Handle remainders */ 2307 2079 2308 2080 /* Head */ 2309 - sep_write_msg(sctx, &head_len, sizeof(u32), 2081 + sep_write_msg(ta_ctx, &head_len, sizeof(u32), 2310 2082 sizeof(u32), &msg_offset, 0); 2311 2083 2312 2084 if (head_len) { 2313 2085 copy_result = sg_copy_to_buffer( 2314 2086 req->src, 2315 - sep_sg_nents(sctx->src_sg), 2087 + sep_sg_nents(ta_ctx->src_sg), 2316 2088 small_buf, head_len); 2317 2089 2318 2090 if (copy_result != head_len) { 2319 - dev_warn(&sctx->sep_used->pdev->dev, 2091 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2320 2092 "sg head copy failure in hash block\n"); 2321 - sep_crypto_release(sctx, -ENOMEM); 2093 + sep_crypto_release(sctx, ta_ctx, -ENOMEM); 2322 2094 return; 2323 2095 } 2324 2096 2325 - sep_write_msg(sctx, small_buf, head_len, 2097 + sep_write_msg(ta_ctx, small_buf, head_len, 2326 2098 sizeof(u32) * 32, &msg_offset, 1); 2327 2099 } else { 2328 2100 msg_offset += sizeof(u32) * 32; 2329 2101 } 2330 2102 2331 2103 /* Tail */ 2332 - sep_write_msg(sctx, &tail_len, sizeof(u32), 2104 + sep_write_msg(ta_ctx, &tail_len, sizeof(u32), 2333 2105 sizeof(u32), &msg_offset, 0); 2334 2106 2335 2107 if (tail_len) { 2336 2108 copy_result = sep_copy_offset_sg( 2337 - sctx->sep_used, 2338 - sctx->src_sg, 2109 + ta_ctx->sep_used, 2110 + ta_ctx->src_sg, 2339 2111 req->nbytes - tail_len, 2340 2112 small_buf, tail_len); 2341 2113 2342 2114 if (copy_result != tail_len) { 2343 - dev_warn(&sctx->sep_used->pdev->dev, 2115 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2344 2116 "sg tail copy failure in hash block\n"); 2345 - sep_crypto_release(sctx, -ENOMEM); 2117 + sep_crypto_release(sctx, ta_ctx, -ENOMEM); 2346 2118 return; 2347 2119 } 2348 2120 2349 - sep_write_msg(sctx, small_buf, tail_len, 2121 + sep_write_msg(ta_ctx, small_buf, tail_len, 2350 2122 sizeof(u32) * 32, &msg_offset, 1); 2351 2123 } else { 2352 2124 msg_offset += sizeof(u32) * 32; 2353 2125 } 2354 2126 2355 2127 /* Context */ 2356 - sep_write_context(sctx, &msg_offset, &ctx->hash_private_ctx, 2128 + sep_write_context(ta_ctx, &msg_offset, &sctx->hash_private_ctx, 2357 2129 sizeof(struct sep_hash_private_context)); 2358 2130 2359 - sep_end_msg(sctx, msg_offset); 2360 - sctx->done_with_transaction = 0; 2361 - int_error = sep_crypto_take_sep(sctx); 2131 + sep_end_msg(ta_ctx, msg_offset); 2132 + are_we_done_yet = 0; 2133 + int_error = sep_crypto_take_sep(ta_ctx); 2362 2134 if (int_error) { 2363 - dev_warn(&sctx->sep_used->pdev->dev, 2135 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2364 2136 "sep_hash_update take sep failed\n"); 2365 - sep_crypto_release(sctx, -EINVAL); 2137 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2366 2138 } 2367 2139 2368 - /** 2369 - * Sep is now working. Lets wait up to 5 seconds 2370 - * for completion. If it does not complete, we will do 2371 - * a crypto release with -EINVAL to release the 2372 - * kernel crypto infrastructure and let the system 2373 - * continue to boot up 2374 - * We have to wait this long because some crypto 2375 - * operations can take a while 2376 - */ 2377 - dev_dbg(&sctx->sep_used->pdev->dev, 2378 - "waiting for done with transaction\n"); 2379 - 2380 - sctx->end_time = jiffies + (SEP_TRANSACTION_WAIT_TIME * HZ); 2381 - while ((time_before(jiffies, sctx->end_time)) && 2382 - (!sctx->done_with_transaction)) 2140 + /* now we sit and wait up to a fixed time for completion */ 2141 + end_time = jiffies + (WAIT_TIME * HZ); 2142 + while ((time_before(jiffies, end_time)) && (are_we_done_yet == 0)) 2383 2143 schedule(); 2384 2144 2385 - dev_dbg(&sctx->sep_used->pdev->dev, 2386 - "done waiting for done with transaction\n"); 2387 - 2388 - /* are we done? */ 2389 - if (!sctx->done_with_transaction) { 2390 - /* Nope, lets release and tell crypto no */ 2391 - dev_warn(&sctx->sep_used->pdev->dev, 2392 - "[PID%d] sep_hash_update never finished\n", 2393 - current->pid); 2394 - sep_crypto_release(sctx, -EINVAL); 2145 + /* Done waiting; still not done yet? */ 2146 + if (are_we_done_yet == 0) { 2147 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2148 + "hash update never got done\n"); 2149 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2150 + return; 2395 2151 } 2152 + 2396 2153 } 2397 2154 2398 2155 static void sep_hash_final(void *data) ··· 2390 2167 u32 msg_offset; 2391 2168 struct ahash_request *req; 2392 2169 struct crypto_ahash *tfm; 2393 - struct sep_hash_ctx *ctx; 2170 + struct this_task_ctx *ta_ctx; 2394 2171 struct sep_system_ctx *sctx; 2395 2172 int result; 2173 + unsigned long end_time; 2174 + int are_we_done_yet; 2396 2175 2397 2176 req = (struct ahash_request *)data; 2398 2177 tfm = crypto_ahash_reqtfm(req); 2399 - ctx = ahash_request_ctx(req); 2400 2178 sctx = crypto_ahash_ctx(tfm); 2179 + ta_ctx = ahash_request_ctx(req); 2180 + ta_ctx->sep_used = sep_dev; 2401 2181 2402 - dev_dbg(&sctx->sep_used->pdev->dev, 2182 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2403 2183 "sep_hash_final\n"); 2404 - sctx->current_hash_stage = HASH_FINISH; 2184 + ta_ctx->current_hash_stage = HASH_FINISH; 2185 + 2186 + ta_ctx->are_we_done_yet = &are_we_done_yet; 2405 2187 2406 2188 /* opcode and mode */ 2407 - sep_make_header(sctx, &msg_offset, SEP_HASH_FINISH_OPCODE); 2189 + sep_make_header(ta_ctx, &msg_offset, SEP_HASH_FINISH_OPCODE); 2408 2190 2409 2191 /* Context */ 2410 - sep_write_context(sctx, &msg_offset, &ctx->hash_private_ctx, 2192 + sep_write_context(ta_ctx, &msg_offset, &sctx->hash_private_ctx, 2411 2193 sizeof(struct sep_hash_private_context)); 2412 2194 2413 - sep_end_msg(sctx, msg_offset); 2414 - sctx->done_with_transaction = 0; 2415 - result = sep_crypto_take_sep(sctx); 2195 + sep_end_msg(ta_ctx, msg_offset); 2196 + are_we_done_yet = 0; 2197 + result = sep_crypto_take_sep(ta_ctx); 2416 2198 if (result) { 2417 - dev_warn(&sctx->sep_used->pdev->dev, 2199 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2418 2200 "sep_hash_final take sep failed\n"); 2419 - sep_crypto_release(sctx, -EINVAL); 2201 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2420 2202 } 2421 2203 2422 - /** 2423 - * Sep is now working. Lets wait up to 5 seconds 2424 - * for completion. If it does not complete, we will do 2425 - * a crypto release with -EINVAL to release the 2426 - * kernel crypto infrastructure and let the system 2427 - * continue to boot up 2428 - * We have to wait this long because some crypto 2429 - * operations can take a while 2430 - */ 2431 - dev_dbg(&sctx->sep_used->pdev->dev, 2432 - "waiting for done with transaction\n"); 2433 - 2434 - sctx->end_time = jiffies + (SEP_TRANSACTION_WAIT_TIME * HZ); 2435 - while ((time_before(jiffies, sctx->end_time)) && 2436 - (!sctx->done_with_transaction)) 2204 + /* now we sit and wait up to a fixed time for completion */ 2205 + end_time = jiffies + (WAIT_TIME * HZ); 2206 + while ((time_before(jiffies, end_time)) && (are_we_done_yet == 0)) 2437 2207 schedule(); 2438 2208 2439 - dev_dbg(&sctx->sep_used->pdev->dev, 2440 - "done waiting for done with transaction\n"); 2441 - 2442 - /* are we done? */ 2443 - if (!sctx->done_with_transaction) { 2444 - /* Nope, lets release and tell crypto no */ 2445 - dev_warn(&sctx->sep_used->pdev->dev, 2446 - "[PID%d] sep_hash_final never finished\n", 2447 - current->pid); 2448 - sep_crypto_release(sctx, -EINVAL); 2209 + /* Done waiting; still not done yet? */ 2210 + if (are_we_done_yet == 0) { 2211 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2212 + "hash final job never got done\n"); 2213 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2214 + return; 2449 2215 } 2216 + 2450 2217 } 2451 2218 2452 2219 static void sep_hash_digest(void *data) ··· 2447 2234 u32 msg[10]; 2448 2235 size_t copy_result; 2449 2236 int result; 2237 + int are_we_done_yet; 2450 2238 u32 tail_len; 2451 2239 static char small_buf[100]; 2452 2240 struct scatterlist *new_sg; ··· 2455 2241 2456 2242 struct ahash_request *req; 2457 2243 struct crypto_ahash *tfm; 2458 - struct sep_hash_ctx *ctx; 2244 + struct this_task_ctx *ta_ctx; 2459 2245 struct sep_system_ctx *sctx; 2246 + unsigned long end_time; 2460 2247 2461 2248 req = (struct ahash_request *)data; 2462 2249 tfm = crypto_ahash_reqtfm(req); 2463 - ctx = ahash_request_ctx(req); 2464 2250 sctx = crypto_ahash_ctx(tfm); 2251 + ta_ctx = ahash_request_ctx(req); 2252 + ta_ctx->sep_used = sep_dev; 2465 2253 2466 - dev_dbg(&sctx->sep_used->pdev->dev, 2254 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2467 2255 "sep_hash_digest\n"); 2468 - sctx->current_hash_stage = HASH_DIGEST; 2256 + ta_ctx->current_hash_stage = HASH_DIGEST; 2257 + 2258 + ta_ctx->are_we_done_yet = &are_we_done_yet; 2469 2259 2470 2260 /* length for queue status */ 2471 - sctx->nbytes = req->nbytes; 2261 + ta_ctx->nbytes = req->nbytes; 2472 2262 2473 2263 block_size = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); 2474 2264 tail_len = req->nbytes % block_size; 2475 - dev_dbg(&sctx->sep_used->pdev->dev, "length is %x\n", req->nbytes); 2476 - dev_dbg(&sctx->sep_used->pdev->dev, "block_size is %x\n", block_size); 2477 - dev_dbg(&sctx->sep_used->pdev->dev, "tail len is %x\n", tail_len); 2265 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "length is %x\n", req->nbytes); 2266 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "block_size is %x\n", block_size); 2267 + dev_dbg(&ta_ctx->sep_used->pdev->dev, "tail len is %x\n", tail_len); 2478 2268 2479 2269 /* Make sure all pages are even block */ 2480 - int_error = sep_oddball_pages(sctx->sep_used, req->src, 2270 + int_error = sep_oddball_pages(ta_ctx->sep_used, req->src, 2481 2271 req->nbytes, 2482 2272 block_size, &new_sg, 1); 2483 2273 2484 2274 if (int_error < 0) { 2485 - dev_warn(&sctx->sep_used->pdev->dev, 2275 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2486 2276 "oddball pages error in crash update\n"); 2487 - sep_crypto_release(sctx, -ENOMEM); 2277 + sep_crypto_release(sctx, ta_ctx, -ENOMEM); 2488 2278 return; 2489 2279 } else if (int_error == 1) { 2490 - sctx->src_sg = new_sg; 2491 - sctx->src_sg_hold = new_sg; 2280 + ta_ctx->src_sg = new_sg; 2281 + ta_ctx->src_sg_hold = new_sg; 2492 2282 } else { 2493 - sctx->src_sg = req->src; 2494 - sctx->src_sg_hold = NULL; 2283 + ta_ctx->src_sg = req->src; 2284 + ta_ctx->src_sg_hold = NULL; 2495 2285 } 2496 2286 2497 - src_ptr = sg_virt(sctx->src_sg); 2287 + src_ptr = sg_virt(ta_ctx->src_sg); 2498 2288 2499 - if ((!req->nbytes) || (!ctx->sg)) { 2289 + if ((!req->nbytes) || (!ta_ctx->src_sg)) { 2500 2290 /* null data */ 2501 2291 src_ptr = NULL; 2502 2292 } 2503 2293 2504 - sep_dump_sg(sctx->sep_used, "hash block sg in", sctx->src_sg); 2294 + sep_dump_sg(ta_ctx->sep_used, "hash block sg in", ta_ctx->src_sg); 2505 2295 2506 - sctx->dcb_input_data.app_in_address = src_ptr; 2507 - sctx->dcb_input_data.data_in_size = req->nbytes - tail_len; 2508 - sctx->dcb_input_data.app_out_address = NULL; 2509 - sctx->dcb_input_data.block_size = block_size; 2510 - sctx->dcb_input_data.tail_block_size = 0; 2511 - sctx->dcb_input_data.is_applet = 0; 2512 - sctx->dcb_input_data.src_sg = sctx->src_sg; 2513 - sctx->dcb_input_data.dst_sg = NULL; 2296 + ta_ctx->dcb_input_data.app_in_address = src_ptr; 2297 + ta_ctx->dcb_input_data.data_in_size = req->nbytes - tail_len; 2298 + ta_ctx->dcb_input_data.app_out_address = NULL; 2299 + ta_ctx->dcb_input_data.block_size = block_size; 2300 + ta_ctx->dcb_input_data.tail_block_size = 0; 2301 + ta_ctx->dcb_input_data.is_applet = 0; 2302 + ta_ctx->dcb_input_data.src_sg = ta_ctx->src_sg; 2303 + ta_ctx->dcb_input_data.dst_sg = NULL; 2514 2304 2515 2305 int_error = sep_create_dcb_dmatables_context_kernel( 2516 - sctx->sep_used, 2517 - &sctx->dcb_region, 2518 - &sctx->dmatables_region, 2519 - &sctx->dma_ctx, 2520 - &sctx->dcb_input_data, 2306 + ta_ctx->sep_used, 2307 + &ta_ctx->dcb_region, 2308 + &ta_ctx->dmatables_region, 2309 + &ta_ctx->dma_ctx, 2310 + &ta_ctx->dcb_input_data, 2521 2311 1); 2522 2312 if (int_error) { 2523 - dev_warn(&sctx->sep_used->pdev->dev, 2313 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2524 2314 "hash update dma table create failed\n"); 2525 - sep_crypto_release(sctx, -EINVAL); 2315 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2526 2316 return; 2527 2317 } 2528 2318 2529 2319 /* Construct message to SEP */ 2530 - sep_make_header(sctx, &msg_offset, SEP_HASH_SINGLE_OPCODE); 2531 - sep_write_msg(sctx, &ctx->hash_opmode, 2320 + sep_make_header(ta_ctx, &msg_offset, SEP_HASH_SINGLE_OPCODE); 2321 + sep_write_msg(ta_ctx, &ta_ctx->hash_opmode, 2532 2322 sizeof(u32), sizeof(u32), &msg_offset, 0); 2533 2323 2534 2324 msg[0] = (u32)0; 2535 2325 msg[1] = (u32)0; 2536 2326 msg[2] = (u32)0; 2537 2327 2538 - sep_write_msg(sctx, msg, sizeof(u32) * 3, sizeof(u32) * 3, 2328 + sep_write_msg(ta_ctx, msg, sizeof(u32) * 3, sizeof(u32) * 3, 2539 2329 &msg_offset, 0); 2540 2330 2541 2331 /* Tail */ 2542 - sep_write_msg(sctx, &tail_len, sizeof(u32), 2332 + sep_write_msg(ta_ctx, &tail_len, sizeof(u32), 2543 2333 sizeof(u32), &msg_offset, 0); 2544 2334 2545 2335 if (tail_len) { 2546 2336 copy_result = sep_copy_offset_sg( 2547 - sctx->sep_used, 2548 - sctx->src_sg, 2337 + ta_ctx->sep_used, 2338 + ta_ctx->src_sg, 2549 2339 req->nbytes - tail_len, 2550 2340 small_buf, tail_len); 2551 2341 2552 2342 if (copy_result != tail_len) { 2553 - dev_warn(&sctx->sep_used->pdev->dev, 2343 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2554 2344 "sg tail copy failure in hash block\n"); 2555 - sep_crypto_release(sctx, -ENOMEM); 2345 + sep_crypto_release(sctx, ta_ctx, -ENOMEM); 2556 2346 return; 2557 2347 } 2558 2348 2559 - sep_write_msg(sctx, small_buf, tail_len, 2349 + sep_write_msg(ta_ctx, small_buf, tail_len, 2560 2350 sizeof(u32) * 32, &msg_offset, 1); 2561 2351 } else { 2562 2352 msg_offset += sizeof(u32) * 32; 2563 2353 } 2564 2354 2565 - sep_end_msg(sctx, msg_offset); 2355 + sep_end_msg(ta_ctx, msg_offset); 2566 2356 2567 - sctx->done_with_transaction = 0; 2568 - 2569 - result = sep_crypto_take_sep(sctx); 2357 + are_we_done_yet = 0; 2358 + result = sep_crypto_take_sep(ta_ctx); 2570 2359 if (result) { 2571 - dev_warn(&sctx->sep_used->pdev->dev, 2360 + dev_warn(&ta_ctx->sep_used->pdev->dev, 2572 2361 "sep_hash_digest take sep failed\n"); 2573 - sep_crypto_release(sctx, -EINVAL); 2362 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2574 2363 } 2575 2364 2576 - /** 2577 - * Sep is now working. Lets wait up to 5 seconds 2578 - * for completion. If it does not complete, we will do 2579 - * a crypto release with -EINVAL to release the 2580 - * kernel crypto infrastructure and let the system 2581 - * continue to boot up 2582 - * We have to wait this long because some crypto 2583 - * operations can take a while 2584 - */ 2585 - dev_dbg(&sctx->sep_used->pdev->dev, 2586 - "waiting for done with transaction\n"); 2587 - 2588 - sctx->end_time = jiffies + (SEP_TRANSACTION_WAIT_TIME * HZ); 2589 - while ((time_before(jiffies, sctx->end_time)) && 2590 - (!sctx->done_with_transaction)) 2365 + /* now we sit and wait up to a fixed time for completion */ 2366 + end_time = jiffies + (WAIT_TIME * HZ); 2367 + while ((time_before(jiffies, end_time)) && (are_we_done_yet == 0)) 2591 2368 schedule(); 2592 2369 2593 - dev_dbg(&sctx->sep_used->pdev->dev, 2594 - "done waiting for done with transaction\n"); 2595 - 2596 - /* are we done? */ 2597 - if (!sctx->done_with_transaction) { 2598 - /* Nope, lets release and tell crypto no */ 2599 - dev_warn(&sctx->sep_used->pdev->dev, 2600 - "[PID%d] sep_hash_digest never finished\n", 2601 - current->pid); 2602 - sep_crypto_release(sctx, -EINVAL); 2370 + /* Done waiting; still not done yet? */ 2371 + if (are_we_done_yet == 0) { 2372 + dev_dbg(&ta_ctx->sep_used->pdev->dev, 2373 + "hash digest job never got done\n"); 2374 + sep_crypto_release(sctx, ta_ctx, -EINVAL); 2375 + return; 2603 2376 } 2377 + 2604 2378 } 2605 2379 2606 2380 /** ··· 2606 2404 struct ahash_request *hash_req; 2607 2405 struct sep_system_ctx *sctx; 2608 2406 struct crypto_ahash *hash_tfm; 2407 + struct this_task_ctx *ta_ctx; 2609 2408 2610 2409 2611 2410 this_queue = (struct crypto_queue *)data; ··· 2684 2481 return; 2685 2482 } 2686 2483 2687 - if (sctx->current_hash_stage == HASH_INIT) { 2484 + ta_ctx = ahash_request_ctx(hash_req); 2485 + 2486 + if (ta_ctx->current_hash_stage == HASH_INIT) { 2688 2487 pr_debug("sep crypto queue hash init\n"); 2689 2488 sep_hash_init((void *)hash_req); 2690 2489 return; 2691 - } else if (sctx->current_hash_stage == HASH_UPDATE) { 2490 + } else if (ta_ctx->current_hash_stage == HASH_UPDATE) { 2692 2491 pr_debug("sep crypto queue hash update\n"); 2693 2492 sep_hash_update((void *)hash_req); 2694 2493 return; 2695 - } else if (sctx->current_hash_stage == HASH_FINISH) { 2494 + } else if (ta_ctx->current_hash_stage == HASH_FINISH) { 2696 2495 pr_debug("sep crypto queue hash final\n"); 2697 2496 sep_hash_final((void *)hash_req); 2698 2497 return; 2699 - } else if (sctx->current_hash_stage == HASH_DIGEST) { 2498 + } else if (ta_ctx->current_hash_stage == HASH_DIGEST) { 2700 2499 pr_debug("sep crypto queue hash digest\n"); 2701 2500 sep_hash_digest((void *)hash_req); 2501 + return; 2502 + } else if (ta_ctx->current_hash_stage == HASH_FINUP_DATA) { 2503 + pr_debug("sep crypto queue hash digest\n"); 2504 + sep_hash_update((void *)hash_req); 2505 + return; 2506 + } else if (ta_ctx->current_hash_stage == HASH_FINUP_FINISH) { 2507 + pr_debug("sep crypto queue hash digest\n"); 2508 + sep_hash_final((void *)hash_req); 2702 2509 return; 2703 2510 } else { 2704 2511 pr_debug("sep crypto queue hash oops nothing\n"); ··· 2720 2507 static int sep_sha1_init(struct ahash_request *req) 2721 2508 { 2722 2509 int error; 2723 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2724 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2725 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2510 + int error1; 2511 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2726 2512 2727 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha1 init\n"); 2728 - sctx->current_request = SHA1; 2729 - sctx->current_hash_req = req; 2730 - sctx->current_cypher_req = NULL; 2731 - ctx->hash_opmode = SEP_HASH_SHA1; 2732 - sctx->current_hash_stage = HASH_INIT; 2513 + pr_debug("sep - doing sha1 init\n"); 2733 2514 2515 + /* Clear out task context */ 2516 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 2517 + 2518 + ta_ctx->sep_used = sep_dev; 2519 + ta_ctx->current_request = SHA1; 2520 + ta_ctx->current_hash_req = req; 2521 + ta_ctx->current_cypher_req = NULL; 2522 + ta_ctx->hash_opmode = SEP_HASH_SHA1; 2523 + ta_ctx->current_hash_stage = HASH_INIT; 2524 + 2525 + /* lock necessary so that only one entity touches the queues */ 2734 2526 spin_lock_irq(&queue_lock); 2735 2527 error = crypto_enqueue_request(&sep_queue, &req->base); 2528 + 2529 + if ((error != 0) && (error != -EINPROGRESS)) 2530 + pr_debug(" sep - crypto enqueue failed: %x\n", 2531 + error); 2532 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2533 + sep_dequeuer, (void *)&sep_queue); 2534 + if (error1) 2535 + pr_debug(" sep - workqueue submit failed: %x\n", 2536 + error1); 2736 2537 spin_unlock_irq(&queue_lock); 2737 - 2738 - if ((error != 0) && (error != -EINPROGRESS)) { 2739 - dev_warn(&sctx->sep_used->pdev->dev, 2740 - "sep sha1 init cant enqueue\n"); 2741 - sep_crypto_release(sctx, error); 2742 - return error; 2743 - } 2744 - 2745 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 2746 - (void *)&sep_queue); 2747 - if (error) { 2748 - dev_warn(&sctx->sep_used->pdev->dev, 2749 - "sha1 init cannot submit queue\n"); 2750 - sep_crypto_release(sctx, -EINVAL); 2751 - return -EINVAL; 2752 - } 2753 - return -EINPROGRESS; 2538 + /* We return result of crypto enqueue */ 2539 + return error; 2754 2540 } 2755 2541 2756 2542 static int sep_sha1_update(struct ahash_request *req) 2757 2543 { 2758 2544 int error; 2759 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2760 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2761 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2545 + int error1; 2546 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2762 2547 2763 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha1 update\n"); 2764 - sctx->current_request = SHA1; 2765 - sctx->current_hash_req = req; 2766 - sctx->current_cypher_req = NULL; 2767 - ctx->hash_opmode = SEP_HASH_SHA1; 2768 - sctx->current_hash_stage = HASH_INIT; 2548 + pr_debug("sep - doing sha1 update\n"); 2769 2549 2550 + ta_ctx->sep_used = sep_dev; 2551 + ta_ctx->current_request = SHA1; 2552 + ta_ctx->current_hash_req = req; 2553 + ta_ctx->current_cypher_req = NULL; 2554 + ta_ctx->hash_opmode = SEP_HASH_SHA1; 2555 + ta_ctx->current_hash_stage = HASH_UPDATE; 2556 + 2557 + /* lock necessary so that only one entity touches the queues */ 2770 2558 spin_lock_irq(&queue_lock); 2771 2559 error = crypto_enqueue_request(&sep_queue, &req->base); 2560 + 2561 + if ((error != 0) && (error != -EINPROGRESS)) 2562 + pr_debug(" sep - crypto enqueue failed: %x\n", 2563 + error); 2564 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2565 + sep_dequeuer, (void *)&sep_queue); 2566 + if (error1) 2567 + pr_debug(" sep - workqueue submit failed: %x\n", 2568 + error1); 2772 2569 spin_unlock_irq(&queue_lock); 2773 - 2774 - if ((error != 0) && (error != -EINPROGRESS)) { 2775 - dev_warn(&sctx->sep_used->pdev->dev, 2776 - "sep sha1 update cant enqueue\n"); 2777 - sep_crypto_release(sctx, error); 2778 - return error; 2779 - } 2780 - 2781 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 2782 - (void *)&sep_queue); 2783 - if (error) { 2784 - dev_warn(&sctx->sep_used->pdev->dev, 2785 - "sha1 update cannot submit queue\n"); 2786 - sep_crypto_release(sctx, -EINVAL); 2787 - return -EINVAL; 2788 - } 2789 - return -EINPROGRESS; 2570 + /* We return result of crypto enqueue */ 2571 + return error; 2790 2572 } 2791 2573 2792 2574 static int sep_sha1_final(struct ahash_request *req) 2793 2575 { 2794 2576 int error; 2795 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2796 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2797 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2798 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha1 final\n"); 2577 + int error1; 2578 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2579 + pr_debug("sep - doing sha1 final\n"); 2799 2580 2800 - sctx->current_request = SHA1; 2801 - sctx->current_hash_req = req; 2802 - sctx->current_cypher_req = NULL; 2803 - ctx->hash_opmode = SEP_HASH_SHA1; 2804 - sctx->current_hash_stage = HASH_FINISH; 2581 + ta_ctx->sep_used = sep_dev; 2582 + ta_ctx->current_request = SHA1; 2583 + ta_ctx->current_hash_req = req; 2584 + ta_ctx->current_cypher_req = NULL; 2585 + ta_ctx->hash_opmode = SEP_HASH_SHA1; 2586 + ta_ctx->current_hash_stage = HASH_FINISH; 2805 2587 2588 + /* lock necessary so that only one entity touches the queues */ 2806 2589 spin_lock_irq(&queue_lock); 2807 2590 error = crypto_enqueue_request(&sep_queue, &req->base); 2591 + 2592 + if ((error != 0) && (error != -EINPROGRESS)) 2593 + pr_debug(" sep - crypto enqueue failed: %x\n", 2594 + error); 2595 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2596 + sep_dequeuer, (void *)&sep_queue); 2597 + if (error1) 2598 + pr_debug(" sep - workqueue submit failed: %x\n", 2599 + error1); 2808 2600 spin_unlock_irq(&queue_lock); 2809 - 2810 - if ((error != 0) && (error != -EINPROGRESS)) { 2811 - dev_warn(&sctx->sep_used->pdev->dev, 2812 - "sep sha1 final cant enqueue\n"); 2813 - sep_crypto_release(sctx, error); 2814 - return error; 2815 - } 2816 - 2817 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 2818 - (void *)&sep_queue); 2819 - if (error) { 2820 - dev_warn(&sctx->sep_used->pdev->dev, 2821 - "sha1 final cannot submit queue\n"); 2822 - sep_crypto_release(sctx, -EINVAL); 2823 - return -EINVAL; 2824 - } 2825 - return -EINPROGRESS; 2826 - 2601 + /* We return result of crypto enqueue */ 2602 + return error; 2827 2603 } 2828 2604 2829 2605 static int sep_sha1_digest(struct ahash_request *req) 2830 2606 { 2831 2607 int error; 2832 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2833 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2834 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2835 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha1 digest\n"); 2608 + int error1; 2609 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2610 + pr_debug("sep - doing sha1 digest\n"); 2836 2611 2837 - sctx->current_request = SHA1; 2838 - sctx->current_hash_req = req; 2839 - sctx->current_cypher_req = NULL; 2840 - ctx->hash_opmode = SEP_HASH_SHA1; 2841 - sctx->current_hash_stage = HASH_DIGEST; 2612 + /* Clear out task context */ 2613 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 2842 2614 2615 + ta_ctx->sep_used = sep_dev; 2616 + ta_ctx->current_request = SHA1; 2617 + ta_ctx->current_hash_req = req; 2618 + ta_ctx->current_cypher_req = NULL; 2619 + ta_ctx->hash_opmode = SEP_HASH_SHA1; 2620 + ta_ctx->current_hash_stage = HASH_DIGEST; 2621 + 2622 + /* lock necessary so that only one entity touches the queues */ 2843 2623 spin_lock_irq(&queue_lock); 2844 2624 error = crypto_enqueue_request(&sep_queue, &req->base); 2625 + 2626 + if ((error != 0) && (error != -EINPROGRESS)) 2627 + pr_debug(" sep - crypto enqueue failed: %x\n", 2628 + error); 2629 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2630 + sep_dequeuer, (void *)&sep_queue); 2631 + if (error1) 2632 + pr_debug(" sep - workqueue submit failed: %x\n", 2633 + error1); 2845 2634 spin_unlock_irq(&queue_lock); 2635 + /* We return result of crypto enqueue */ 2636 + return error; 2637 + } 2846 2638 2847 - if ((error != 0) && (error != -EINPROGRESS)) { 2848 - dev_warn(&sctx->sep_used->pdev->dev, 2849 - "sep sha1 digest cant enqueue\n"); 2850 - sep_crypto_release(sctx, error); 2851 - return error; 2852 - } 2639 + static int sep_sha1_finup(struct ahash_request *req) 2640 + { 2641 + int error; 2642 + int error1; 2643 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2644 + pr_debug("sep - doing sha1 finup\n"); 2853 2645 2854 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 2855 - (void *)&sep_queue); 2856 - if (error) { 2857 - dev_warn(&sctx->sep_used->pdev->dev, 2858 - "sha1 digest cannot submit queue\n"); 2859 - sep_crypto_release(sctx, -EINVAL); 2860 - return -EINVAL; 2861 - } 2862 - return -EINPROGRESS; 2646 + ta_ctx->sep_used = sep_dev; 2647 + ta_ctx->current_request = SHA1; 2648 + ta_ctx->current_hash_req = req; 2649 + ta_ctx->current_cypher_req = NULL; 2650 + ta_ctx->hash_opmode = SEP_HASH_SHA1; 2651 + ta_ctx->current_hash_stage = HASH_FINUP_DATA; 2863 2652 2653 + /* lock necessary so that only one entity touches the queues */ 2654 + spin_lock_irq(&queue_lock); 2655 + error = crypto_enqueue_request(&sep_queue, &req->base); 2656 + 2657 + if ((error != 0) && (error != -EINPROGRESS)) 2658 + pr_debug(" sep - crypto enqueue failed: %x\n", 2659 + error); 2660 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2661 + sep_dequeuer, (void *)&sep_queue); 2662 + if (error1) 2663 + pr_debug(" sep - workqueue submit failed: %x\n", 2664 + error1); 2665 + spin_unlock_irq(&queue_lock); 2666 + /* We return result of crypto enqueue */ 2667 + return error; 2864 2668 } 2865 2669 2866 2670 static int sep_md5_init(struct ahash_request *req) 2867 2671 { 2868 2672 int error; 2869 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2870 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2871 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2872 - dev_dbg(&sctx->sep_used->pdev->dev, "doing md5 init\n"); 2673 + int error1; 2674 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2675 + pr_debug("sep - doing md5 init\n"); 2873 2676 2874 - sctx->current_request = MD5; 2875 - sctx->current_hash_req = req; 2876 - sctx->current_cypher_req = NULL; 2877 - ctx->hash_opmode = SEP_HASH_MD5; 2878 - sctx->current_hash_stage = HASH_INIT; 2677 + /* Clear out task context */ 2678 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 2879 2679 2680 + ta_ctx->sep_used = sep_dev; 2681 + ta_ctx->current_request = MD5; 2682 + ta_ctx->current_hash_req = req; 2683 + ta_ctx->current_cypher_req = NULL; 2684 + ta_ctx->hash_opmode = SEP_HASH_MD5; 2685 + ta_ctx->current_hash_stage = HASH_INIT; 2686 + 2687 + /* lock necessary so that only one entity touches the queues */ 2880 2688 spin_lock_irq(&queue_lock); 2881 2689 error = crypto_enqueue_request(&sep_queue, &req->base); 2690 + 2691 + if ((error != 0) && (error != -EINPROGRESS)) 2692 + pr_debug(" sep - crypto enqueue failed: %x\n", 2693 + error); 2694 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2695 + sep_dequeuer, (void *)&sep_queue); 2696 + if (error1) 2697 + pr_debug(" sep - workqueue submit failed: %x\n", 2698 + error1); 2882 2699 spin_unlock_irq(&queue_lock); 2883 - 2884 - if ((error != 0) && (error != -EINPROGRESS)) { 2885 - dev_warn(&sctx->sep_used->pdev->dev, 2886 - "sep md5 init cant enqueue\n"); 2887 - sep_crypto_release(sctx, error); 2888 - return error; 2889 - } 2890 - 2891 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 2892 - (void *)&sep_queue); 2893 - if (error) { 2894 - dev_warn(&sctx->sep_used->pdev->dev, 2895 - "md5 init cannot submit queue\n"); 2896 - sep_crypto_release(sctx, -EINVAL); 2897 - return -EINVAL; 2898 - } 2899 - return -EINPROGRESS; 2900 - 2700 + /* We return result of crypto enqueue */ 2701 + return error; 2901 2702 } 2902 2703 2903 2704 static int sep_md5_update(struct ahash_request *req) 2904 2705 { 2905 2706 int error; 2906 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2907 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2908 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2909 - dev_dbg(&sctx->sep_used->pdev->dev, "doing md5 update\n"); 2707 + int error1; 2708 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2709 + pr_debug("sep - doing md5 update\n"); 2910 2710 2911 - sctx->current_request = MD5; 2912 - sctx->current_hash_req = req; 2913 - sctx->current_cypher_req = NULL; 2914 - ctx->hash_opmode = SEP_HASH_MD5; 2915 - sctx->current_hash_stage = HASH_UPDATE; 2711 + ta_ctx->sep_used = sep_dev; 2712 + ta_ctx->current_request = MD5; 2713 + ta_ctx->current_hash_req = req; 2714 + ta_ctx->current_cypher_req = NULL; 2715 + ta_ctx->hash_opmode = SEP_HASH_MD5; 2716 + ta_ctx->current_hash_stage = HASH_UPDATE; 2916 2717 2718 + /* lock necessary so that only one entity touches the queues */ 2917 2719 spin_lock_irq(&queue_lock); 2918 2720 error = crypto_enqueue_request(&sep_queue, &req->base); 2721 + 2722 + if ((error != 0) && (error != -EINPROGRESS)) 2723 + pr_debug(" sep - crypto enqueue failed: %x\n", 2724 + error); 2725 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2726 + sep_dequeuer, (void *)&sep_queue); 2727 + if (error1) 2728 + pr_debug(" sep - workqueue submit failed: %x\n", 2729 + error1); 2919 2730 spin_unlock_irq(&queue_lock); 2920 - 2921 - if ((error != 0) && (error != -EINPROGRESS)) { 2922 - dev_warn(&sctx->sep_used->pdev->dev, 2923 - "md5 update cant enqueue\n"); 2924 - sep_crypto_release(sctx, error); 2925 - return error; 2926 - } 2927 - 2928 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 2929 - (void *)&sep_queue); 2930 - if (error) { 2931 - dev_warn(&sctx->sep_used->pdev->dev, 2932 - "md5 update cannot submit queue\n"); 2933 - sep_crypto_release(sctx, -EINVAL); 2934 - return -EINVAL; 2935 - } 2936 - return -EINPROGRESS; 2731 + /* We return result of crypto enqueue */ 2732 + return error; 2937 2733 } 2938 2734 2939 2735 static int sep_md5_final(struct ahash_request *req) 2940 2736 { 2941 2737 int error; 2942 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2943 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2944 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2945 - dev_dbg(&sctx->sep_used->pdev->dev, "doing md5 final\n"); 2738 + int error1; 2739 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2740 + pr_debug("sep - doing md5 final\n"); 2946 2741 2947 - sctx->current_request = MD5; 2948 - sctx->current_hash_req = req; 2949 - sctx->current_cypher_req = NULL; 2950 - ctx->hash_opmode = SEP_HASH_MD5; 2951 - sctx->current_hash_stage = HASH_FINISH; 2742 + ta_ctx->sep_used = sep_dev; 2743 + ta_ctx->current_request = MD5; 2744 + ta_ctx->current_hash_req = req; 2745 + ta_ctx->current_cypher_req = NULL; 2746 + ta_ctx->hash_opmode = SEP_HASH_MD5; 2747 + ta_ctx->current_hash_stage = HASH_FINISH; 2952 2748 2749 + /* lock necessary so that only one entity touches the queues */ 2953 2750 spin_lock_irq(&queue_lock); 2954 2751 error = crypto_enqueue_request(&sep_queue, &req->base); 2752 + 2753 + if ((error != 0) && (error != -EINPROGRESS)) 2754 + pr_debug(" sep - crypto enqueue failed: %x\n", 2755 + error); 2756 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2757 + sep_dequeuer, (void *)&sep_queue); 2758 + if (error1) 2759 + pr_debug(" sep - workqueue submit failed: %x\n", 2760 + error1); 2955 2761 spin_unlock_irq(&queue_lock); 2956 - 2957 - if ((error != 0) && (error != -EINPROGRESS)) { 2958 - dev_warn(&sctx->sep_used->pdev->dev, 2959 - "sep md5 final cant enqueue\n"); 2960 - sep_crypto_release(sctx, error); 2961 - return error; 2962 - } 2963 - 2964 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 2965 - (void *)&sep_queue); 2966 - if (error) { 2967 - dev_warn(&sctx->sep_used->pdev->dev, 2968 - "md5 final cannot submit queue\n"); 2969 - sep_crypto_release(sctx, -EINVAL); 2970 - return -EINVAL; 2971 - } 2972 - return -EINPROGRESS; 2973 - 2762 + /* We return result of crypto enqueue */ 2763 + return error; 2974 2764 } 2975 2765 2976 2766 static int sep_md5_digest(struct ahash_request *req) 2977 2767 { 2978 2768 int error; 2979 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 2980 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 2981 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2769 + int error1; 2770 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2982 2771 2983 - dev_dbg(&sctx->sep_used->pdev->dev, "doing md5 digest\n"); 2984 - sctx->current_request = MD5; 2985 - sctx->current_hash_req = req; 2986 - sctx->current_cypher_req = NULL; 2987 - ctx->hash_opmode = SEP_HASH_MD5; 2988 - sctx->current_hash_stage = HASH_DIGEST; 2772 + pr_debug("sep - doing md5 digest\n"); 2989 2773 2774 + /* Clear out task context */ 2775 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 2776 + 2777 + ta_ctx->sep_used = sep_dev; 2778 + ta_ctx->current_request = MD5; 2779 + ta_ctx->current_hash_req = req; 2780 + ta_ctx->current_cypher_req = NULL; 2781 + ta_ctx->hash_opmode = SEP_HASH_MD5; 2782 + ta_ctx->current_hash_stage = HASH_DIGEST; 2783 + 2784 + /* lock necessary so that only one entity touches the queues */ 2990 2785 spin_lock_irq(&queue_lock); 2991 2786 error = crypto_enqueue_request(&sep_queue, &req->base); 2787 + 2788 + if ((error != 0) && (error != -EINPROGRESS)) 2789 + pr_debug(" sep - crypto enqueue failed: %x\n", 2790 + error); 2791 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2792 + sep_dequeuer, (void *)&sep_queue); 2793 + if (error1) 2794 + pr_debug(" sep - workqueue submit failed: %x\n", 2795 + error1); 2992 2796 spin_unlock_irq(&queue_lock); 2797 + /* We return result of crypto enqueue */ 2798 + return error; 2799 + } 2993 2800 2994 - if ((error != 0) && (error != -EINPROGRESS)) { 2995 - dev_warn(&sctx->sep_used->pdev->dev, 2996 - "sep md5 digest cant enqueue\n"); 2997 - sep_crypto_release(sctx, error); 2998 - return error; 2999 - } 2801 + static int sep_md5_finup(struct ahash_request *req) 2802 + { 2803 + int error; 2804 + int error1; 2805 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3000 2806 3001 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3002 - (void *)&sep_queue); 3003 - if (error) { 3004 - dev_warn(&sctx->sep_used->pdev->dev, 3005 - "md5 digest cannot submit queue\n"); 3006 - sep_crypto_release(sctx, -EINVAL); 3007 - return -EINVAL; 3008 - } 3009 - return -EINPROGRESS; 2807 + pr_debug("sep - doing md5 finup\n"); 2808 + 2809 + ta_ctx->sep_used = sep_dev; 2810 + ta_ctx->current_request = MD5; 2811 + ta_ctx->current_hash_req = req; 2812 + ta_ctx->current_cypher_req = NULL; 2813 + ta_ctx->hash_opmode = SEP_HASH_MD5; 2814 + ta_ctx->current_hash_stage = HASH_FINUP_DATA; 2815 + 2816 + /* lock necessary so that only one entity touches the queues */ 2817 + spin_lock_irq(&queue_lock); 2818 + error = crypto_enqueue_request(&sep_queue, &req->base); 2819 + 2820 + if ((error != 0) && (error != -EINPROGRESS)) 2821 + pr_debug(" sep - crypto enqueue failed: %x\n", 2822 + error); 2823 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2824 + sep_dequeuer, (void *)&sep_queue); 2825 + if (error1) 2826 + pr_debug(" sep - workqueue submit failed: %x\n", 2827 + error1); 2828 + spin_unlock_irq(&queue_lock); 2829 + /* We return result of crypto enqueue */ 2830 + return error; 3010 2831 } 3011 2832 3012 2833 static int sep_sha224_init(struct ahash_request *req) 3013 2834 { 3014 2835 int error; 3015 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3016 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3017 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 3018 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha224 init\n"); 2836 + int error1; 2837 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2838 + pr_debug("sep - doing sha224 init\n"); 3019 2839 3020 - sctx->current_request = SHA224; 3021 - sctx->current_hash_req = req; 3022 - sctx->current_cypher_req = NULL; 3023 - ctx->hash_opmode = SEP_HASH_SHA224; 3024 - sctx->current_hash_stage = HASH_INIT; 2840 + /* Clear out task context */ 2841 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3025 2842 2843 + ta_ctx->sep_used = sep_dev; 2844 + ta_ctx->current_request = SHA224; 2845 + ta_ctx->current_hash_req = req; 2846 + ta_ctx->current_cypher_req = NULL; 2847 + ta_ctx->hash_opmode = SEP_HASH_SHA224; 2848 + ta_ctx->current_hash_stage = HASH_INIT; 2849 + 2850 + /* lock necessary so that only one entity touches the queues */ 3026 2851 spin_lock_irq(&queue_lock); 3027 2852 error = crypto_enqueue_request(&sep_queue, &req->base); 2853 + 2854 + if ((error != 0) && (error != -EINPROGRESS)) 2855 + pr_debug(" sep - crypto enqueue failed: %x\n", 2856 + error); 2857 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2858 + sep_dequeuer, (void *)&sep_queue); 2859 + if (error1) 2860 + pr_debug(" sep - workqueue submit failed: %x\n", 2861 + error1); 3028 2862 spin_unlock_irq(&queue_lock); 3029 - 3030 - if ((error != 0) && (error != -EINPROGRESS)) { 3031 - dev_warn(&sctx->sep_used->pdev->dev, 3032 - "sep sha224 init cant enqueue\n"); 3033 - sep_crypto_release(sctx, error); 3034 - return error; 3035 - } 3036 - 3037 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3038 - (void *)&sep_queue); 3039 - if (error) { 3040 - dev_warn(&sctx->sep_used->pdev->dev, 3041 - "sha224 init cannot submit queue\n"); 3042 - sep_crypto_release(sctx, -EINVAL); 3043 - return -EINVAL; 3044 - } 3045 - return -EINPROGRESS; 2863 + /* We return result of crypto enqueue */ 2864 + return error; 3046 2865 } 3047 2866 3048 2867 static int sep_sha224_update(struct ahash_request *req) 3049 2868 { 3050 2869 int error; 3051 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3052 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3053 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 3054 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha224 update\n"); 2870 + int error1; 2871 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2872 + pr_debug("sep - doing sha224 update\n"); 3055 2873 3056 - sctx->current_request = SHA224; 3057 - sctx->current_hash_req = req; 3058 - sctx->current_cypher_req = NULL; 3059 - ctx->hash_opmode = SEP_HASH_SHA224; 3060 - sctx->current_hash_stage = HASH_UPDATE; 2874 + ta_ctx->sep_used = sep_dev; 2875 + ta_ctx->current_request = SHA224; 2876 + ta_ctx->current_hash_req = req; 2877 + ta_ctx->current_cypher_req = NULL; 2878 + ta_ctx->hash_opmode = SEP_HASH_SHA224; 2879 + ta_ctx->current_hash_stage = HASH_UPDATE; 3061 2880 2881 + /* lock necessary so that only one entity touches the queues */ 3062 2882 spin_lock_irq(&queue_lock); 3063 2883 error = crypto_enqueue_request(&sep_queue, &req->base); 2884 + 2885 + if ((error != 0) && (error != -EINPROGRESS)) 2886 + pr_debug(" sep - crypto enqueue failed: %x\n", 2887 + error); 2888 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2889 + sep_dequeuer, (void *)&sep_queue); 2890 + if (error1) 2891 + pr_debug(" sep - workqueue submit failed: %x\n", 2892 + error1); 3064 2893 spin_unlock_irq(&queue_lock); 3065 - 3066 - if ((error != 0) && (error != -EINPROGRESS)) { 3067 - dev_warn(&sctx->sep_used->pdev->dev, 3068 - "sep sha224 update cant enqueue\n"); 3069 - sep_crypto_release(sctx, error); 3070 - return error; 3071 - } 3072 - 3073 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3074 - (void *)&sep_queue); 3075 - if (error) { 3076 - dev_warn(&sctx->sep_used->pdev->dev, 3077 - "sha224 update cannot submit queue\n"); 3078 - sep_crypto_release(sctx, -EINVAL); 3079 - return -EINVAL; 3080 - } 3081 - return -EINPROGRESS; 2894 + /* We return result of crypto enqueue */ 2895 + return error; 3082 2896 } 3083 2897 3084 2898 static int sep_sha224_final(struct ahash_request *req) 3085 2899 { 3086 2900 int error; 3087 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3088 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3089 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 3090 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha224 final\n"); 2901 + int error1; 2902 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 2903 + pr_debug("sep - doing sha224 final\n"); 3091 2904 3092 - sctx->current_request = SHA224; 3093 - sctx->current_hash_req = req; 3094 - sctx->current_cypher_req = NULL; 3095 - ctx->hash_opmode = SEP_HASH_SHA224; 3096 - sctx->current_hash_stage = HASH_FINISH; 2905 + ta_ctx->sep_used = sep_dev; 2906 + ta_ctx->current_request = SHA224; 2907 + ta_ctx->current_hash_req = req; 2908 + ta_ctx->current_cypher_req = NULL; 2909 + ta_ctx->hash_opmode = SEP_HASH_SHA224; 2910 + ta_ctx->current_hash_stage = HASH_FINISH; 3097 2911 2912 + /* lock necessary so that only one entity touches the queues */ 3098 2913 spin_lock_irq(&queue_lock); 3099 2914 error = crypto_enqueue_request(&sep_queue, &req->base); 2915 + 2916 + if ((error != 0) && (error != -EINPROGRESS)) 2917 + pr_debug(" sep - crypto enqueue failed: %x\n", 2918 + error); 2919 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2920 + sep_dequeuer, (void *)&sep_queue); 2921 + if (error1) 2922 + pr_debug(" sep - workqueue submit failed: %x\n", 2923 + error1); 3100 2924 spin_unlock_irq(&queue_lock); 3101 - 3102 - if ((error != 0) && (error != -EINPROGRESS)) { 3103 - dev_warn(&sctx->sep_used->pdev->dev, 3104 - "sep sha224 final cant enqueue\n"); 3105 - sep_crypto_release(sctx, error); 3106 - return error; 3107 - } 3108 - 3109 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3110 - (void *)&sep_queue); 3111 - if (error) { 3112 - dev_warn(&sctx->sep_used->pdev->dev, 3113 - "sha224 final cannot submit queue\n"); 3114 - sep_crypto_release(sctx, -EINVAL); 3115 - return -EINVAL; 3116 - } 3117 - return -EINPROGRESS; 2925 + /* We return result of crypto enqueue */ 2926 + return error; 3118 2927 } 3119 2928 3120 2929 static int sep_sha224_digest(struct ahash_request *req) 3121 2930 { 3122 2931 int error; 3123 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3124 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3125 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 2932 + int error1; 2933 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3126 2934 3127 - dev_dbg(&sctx->sep_used->pdev->dev, "doing 224 digest\n"); 3128 - sctx->current_request = SHA224; 3129 - sctx->current_hash_req = req; 3130 - sctx->current_cypher_req = NULL; 3131 - ctx->hash_opmode = SEP_HASH_SHA224; 3132 - sctx->current_hash_stage = HASH_DIGEST; 2935 + pr_debug("sep - doing sha224 digest\n"); 3133 2936 2937 + /* Clear out task context */ 2938 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 2939 + 2940 + ta_ctx->sep_used = sep_dev; 2941 + ta_ctx->current_request = SHA224; 2942 + ta_ctx->current_hash_req = req; 2943 + ta_ctx->current_cypher_req = NULL; 2944 + ta_ctx->hash_opmode = SEP_HASH_SHA224; 2945 + ta_ctx->current_hash_stage = HASH_DIGEST; 2946 + 2947 + /* lock necessary so that only one entity touches the queues */ 3134 2948 spin_lock_irq(&queue_lock); 3135 2949 error = crypto_enqueue_request(&sep_queue, &req->base); 2950 + 2951 + if ((error != 0) && (error != -EINPROGRESS)) 2952 + pr_debug(" sep - crypto enqueue failed: %x\n", 2953 + error); 2954 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2955 + sep_dequeuer, (void *)&sep_queue); 2956 + if (error1) 2957 + pr_debug(" sep - workqueue submit failed: %x\n", 2958 + error1); 3136 2959 spin_unlock_irq(&queue_lock); 2960 + /* We return result of crypto enqueue */ 2961 + return error; 2962 + } 3137 2963 3138 - if ((error != 0) && (error != -EINPROGRESS)) { 3139 - dev_warn(&sctx->sep_used->pdev->dev, 3140 - "sep sha224 digest cant enqueue\n"); 3141 - sep_crypto_release(sctx, error); 3142 - return error; 3143 - } 2964 + static int sep_sha224_finup(struct ahash_request *req) 2965 + { 2966 + int error; 2967 + int error1; 2968 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3144 2969 3145 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3146 - (void *)&sep_queue); 3147 - if (error) { 3148 - dev_warn(&sctx->sep_used->pdev->dev, 3149 - "sha256 digest cannot submit queue\n"); 3150 - sep_crypto_release(sctx, -EINVAL); 3151 - return -EINVAL; 3152 - } 3153 - return -EINPROGRESS; 2970 + pr_debug("sep - doing sha224 finup\n"); 2971 + 2972 + ta_ctx->sep_used = sep_dev; 2973 + ta_ctx->current_request = SHA224; 2974 + ta_ctx->current_hash_req = req; 2975 + ta_ctx->current_cypher_req = NULL; 2976 + ta_ctx->hash_opmode = SEP_HASH_SHA224; 2977 + ta_ctx->current_hash_stage = HASH_FINUP_DATA; 2978 + 2979 + /* lock necessary so that only one entity touches the queues */ 2980 + spin_lock_irq(&queue_lock); 2981 + error = crypto_enqueue_request(&sep_queue, &req->base); 2982 + 2983 + if ((error != 0) && (error != -EINPROGRESS)) 2984 + pr_debug(" sep - crypto enqueue failed: %x\n", 2985 + error); 2986 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 2987 + sep_dequeuer, (void *)&sep_queue); 2988 + if (error1) 2989 + pr_debug(" sep - workqueue submit failed: %x\n", 2990 + error1); 2991 + spin_unlock_irq(&queue_lock); 2992 + /* We return result of crypto enqueue */ 2993 + return error; 3154 2994 } 3155 2995 3156 2996 static int sep_sha256_init(struct ahash_request *req) 3157 2997 { 3158 2998 int error; 3159 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3160 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3161 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 3162 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha256 init\n"); 2999 + int error1; 3000 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3001 + pr_debug("sep - doing sha256 init\n"); 3163 3002 3164 - sctx->current_request = SHA256; 3165 - sctx->current_hash_req = req; 3166 - sctx->current_cypher_req = NULL; 3167 - ctx->hash_opmode = SEP_HASH_SHA256; 3168 - sctx->current_hash_stage = HASH_INIT; 3003 + /* Clear out task context */ 3004 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3169 3005 3006 + ta_ctx->sep_used = sep_dev; 3007 + ta_ctx->current_request = SHA256; 3008 + ta_ctx->current_hash_req = req; 3009 + ta_ctx->current_cypher_req = NULL; 3010 + ta_ctx->hash_opmode = SEP_HASH_SHA256; 3011 + ta_ctx->current_hash_stage = HASH_INIT; 3012 + 3013 + /* lock necessary so that only one entity touches the queues */ 3170 3014 spin_lock_irq(&queue_lock); 3171 3015 error = crypto_enqueue_request(&sep_queue, &req->base); 3016 + 3017 + if ((error != 0) && (error != -EINPROGRESS)) 3018 + pr_debug(" sep - crypto enqueue failed: %x\n", 3019 + error); 3020 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3021 + sep_dequeuer, (void *)&sep_queue); 3022 + if (error1) 3023 + pr_debug(" sep - workqueue submit failed: %x\n", 3024 + error1); 3172 3025 spin_unlock_irq(&queue_lock); 3173 - 3174 - if ((error != 0) && (error != -EINPROGRESS)) { 3175 - dev_warn(&sctx->sep_used->pdev->dev, 3176 - "sep sha256 init cant enqueue\n"); 3177 - sep_crypto_release(sctx, error); 3178 - return error; 3179 - } 3180 - 3181 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3182 - (void *)&sep_queue); 3183 - if (error) { 3184 - dev_warn(&sctx->sep_used->pdev->dev, 3185 - "sha256 init cannot submit queue\n"); 3186 - sep_crypto_release(sctx, -EINVAL); 3187 - return -EINVAL; 3188 - } 3189 - return -EINPROGRESS; 3026 + /* We return result of crypto enqueue */ 3027 + return error; 3190 3028 } 3191 3029 3192 3030 static int sep_sha256_update(struct ahash_request *req) 3193 3031 { 3194 3032 int error; 3195 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3196 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3197 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 3198 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha256 update\n"); 3033 + int error1; 3034 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3035 + pr_debug("sep - doing sha256 update\n"); 3199 3036 3200 - sctx->current_request = SHA256; 3201 - sctx->current_hash_req = req; 3202 - sctx->current_cypher_req = NULL; 3203 - ctx->hash_opmode = SEP_HASH_SHA256; 3204 - sctx->current_hash_stage = HASH_UPDATE; 3037 + ta_ctx->sep_used = sep_dev; 3038 + ta_ctx->current_request = SHA256; 3039 + ta_ctx->current_hash_req = req; 3040 + ta_ctx->current_cypher_req = NULL; 3041 + ta_ctx->hash_opmode = SEP_HASH_SHA256; 3042 + ta_ctx->current_hash_stage = HASH_UPDATE; 3205 3043 3044 + /* lock necessary so that only one entity touches the queues */ 3206 3045 spin_lock_irq(&queue_lock); 3207 3046 error = crypto_enqueue_request(&sep_queue, &req->base); 3047 + 3048 + if ((error != 0) && (error != -EINPROGRESS)) 3049 + pr_debug(" sep - crypto enqueue failed: %x\n", 3050 + error); 3051 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3052 + sep_dequeuer, (void *)&sep_queue); 3053 + if (error1) 3054 + pr_debug(" sep - workqueue submit failed: %x\n", 3055 + error1); 3208 3056 spin_unlock_irq(&queue_lock); 3209 - 3210 - if ((error != 0) && (error != -EINPROGRESS)) { 3211 - dev_warn(&sctx->sep_used->pdev->dev, 3212 - "sep sha256 update cant enqueue\n"); 3213 - sep_crypto_release(sctx, error); 3214 - return error; 3215 - } 3216 - 3217 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3218 - (void *)&sep_queue); 3219 - if (error) { 3220 - dev_warn(&sctx->sep_used->pdev->dev, 3221 - "sha256 update cannot submit queue\n"); 3222 - sep_crypto_release(sctx, -EINVAL); 3223 - return -EINVAL; 3224 - } 3225 - return -EINPROGRESS; 3057 + /* We return result of crypto enqueue */ 3058 + return error; 3226 3059 } 3227 3060 3228 3061 static int sep_sha256_final(struct ahash_request *req) 3229 3062 { 3230 3063 int error; 3231 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3232 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3233 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 3234 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha256 final\n"); 3064 + int error1; 3065 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3066 + pr_debug("sep - doing sha256 final\n"); 3235 3067 3236 - sctx->current_request = SHA256; 3237 - sctx->current_hash_req = req; 3238 - sctx->current_cypher_req = NULL; 3239 - ctx->hash_opmode = SEP_HASH_SHA256; 3240 - sctx->current_hash_stage = HASH_FINISH; 3068 + ta_ctx->sep_used = sep_dev; 3069 + ta_ctx->current_request = SHA256; 3070 + ta_ctx->current_hash_req = req; 3071 + ta_ctx->current_cypher_req = NULL; 3072 + ta_ctx->hash_opmode = SEP_HASH_SHA256; 3073 + ta_ctx->current_hash_stage = HASH_FINISH; 3241 3074 3075 + /* lock necessary so that only one entity touches the queues */ 3242 3076 spin_lock_irq(&queue_lock); 3243 3077 error = crypto_enqueue_request(&sep_queue, &req->base); 3078 + 3079 + if ((error != 0) && (error != -EINPROGRESS)) 3080 + pr_debug(" sep - crypto enqueue failed: %x\n", 3081 + error); 3082 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3083 + sep_dequeuer, (void *)&sep_queue); 3084 + if (error1) 3085 + pr_debug(" sep - workqueue submit failed: %x\n", 3086 + error1); 3244 3087 spin_unlock_irq(&queue_lock); 3245 - 3246 - if ((error != 0) && (error != -EINPROGRESS)) { 3247 - dev_warn(&sctx->sep_used->pdev->dev, 3248 - "sep sha256 final cant enqueue\n"); 3249 - sep_crypto_release(sctx, error); 3250 - return error; 3251 - } 3252 - 3253 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3254 - (void *)&sep_queue); 3255 - if (error) { 3256 - dev_warn(&sctx->sep_used->pdev->dev, 3257 - "sha256 final cannot submit queue\n"); 3258 - sep_crypto_release(sctx, -EINVAL); 3259 - return -EINVAL; 3260 - } 3261 - return -EINPROGRESS; 3088 + /* We return result of crypto enqueue */ 3089 + return error; 3262 3090 } 3263 3091 3264 3092 static int sep_sha256_digest(struct ahash_request *req) 3265 3093 { 3266 3094 int error; 3267 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 3268 - struct sep_hash_ctx *ctx = ahash_request_ctx(req); 3269 - struct sep_system_ctx *sctx = crypto_ahash_ctx(tfm); 3095 + int error1; 3096 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3270 3097 3271 - dev_dbg(&sctx->sep_used->pdev->dev, "doing sha256 digest\n"); 3272 - sctx->current_request = SHA256; 3273 - sctx->current_hash_req = req; 3274 - sctx->current_cypher_req = NULL; 3275 - ctx->hash_opmode = SEP_HASH_SHA256; 3276 - sctx->current_hash_stage = HASH_DIGEST; 3098 + pr_debug("sep - doing sha256 digest\n"); 3277 3099 3100 + /* Clear out task context */ 3101 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3102 + 3103 + ta_ctx->sep_used = sep_dev; 3104 + ta_ctx->current_request = SHA256; 3105 + ta_ctx->current_hash_req = req; 3106 + ta_ctx->current_cypher_req = NULL; 3107 + ta_ctx->hash_opmode = SEP_HASH_SHA256; 3108 + ta_ctx->current_hash_stage = HASH_DIGEST; 3109 + 3110 + /* lock necessary so that only one entity touches the queues */ 3278 3111 spin_lock_irq(&queue_lock); 3279 3112 error = crypto_enqueue_request(&sep_queue, &req->base); 3113 + 3114 + if ((error != 0) && (error != -EINPROGRESS)) 3115 + pr_debug(" sep - crypto enqueue failed: %x\n", 3116 + error); 3117 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3118 + sep_dequeuer, (void *)&sep_queue); 3119 + if (error1) 3120 + pr_debug(" sep - workqueue submit failed: %x\n", 3121 + error1); 3280 3122 spin_unlock_irq(&queue_lock); 3123 + /* We return result of crypto enqueue */ 3124 + return error; 3125 + } 3281 3126 3282 - if ((error != 0) && (error != -EINPROGRESS)) { 3283 - dev_warn(&sctx->sep_used->pdev->dev, 3284 - "sep sha256 digest cant enqueue\n"); 3285 - sep_crypto_release(sctx, error); 3286 - return error; 3287 - } 3127 + static int sep_sha256_finup(struct ahash_request *req) 3128 + { 3129 + int error; 3130 + int error1; 3131 + struct this_task_ctx *ta_ctx = ahash_request_ctx(req); 3288 3132 3289 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3290 - (void *)&sep_queue); 3291 - if (error) { 3292 - dev_warn(&sctx->sep_used->pdev->dev, 3293 - "sha256 digest cannot submit queue\n"); 3294 - sep_crypto_release(sctx, -EINVAL); 3295 - return -EINVAL; 3296 - } 3297 - return -EINPROGRESS; 3133 + pr_debug("sep - doing sha256 finup\n"); 3134 + 3135 + ta_ctx->sep_used = sep_dev; 3136 + ta_ctx->current_request = SHA256; 3137 + ta_ctx->current_hash_req = req; 3138 + ta_ctx->current_cypher_req = NULL; 3139 + ta_ctx->hash_opmode = SEP_HASH_SHA256; 3140 + ta_ctx->current_hash_stage = HASH_FINUP_DATA; 3141 + 3142 + /* lock necessary so that only one entity touches the queues */ 3143 + spin_lock_irq(&queue_lock); 3144 + error = crypto_enqueue_request(&sep_queue, &req->base); 3145 + 3146 + if ((error != 0) && (error != -EINPROGRESS)) 3147 + pr_debug(" sep - crypto enqueue failed: %x\n", 3148 + error); 3149 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3150 + sep_dequeuer, (void *)&sep_queue); 3151 + if (error1) 3152 + pr_debug(" sep - workqueue submit failed: %x\n", 3153 + error1); 3154 + spin_unlock_irq(&queue_lock); 3155 + /* We return result of crypto enqueue */ 3156 + return error; 3298 3157 } 3299 3158 3300 3159 static int sep_crypto_init(struct crypto_tfm *tfm) 3301 3160 { 3302 - struct sep_system_ctx *sctx = crypto_tfm_ctx(tfm); 3303 3161 const char *alg_name = crypto_tfm_alg_name(tfm); 3304 3162 3305 - sctx->sep_used = sep_dev; 3306 - 3307 3163 if (alg_name == NULL) 3308 - dev_dbg(&sctx->sep_used->pdev->dev, "alg is NULL\n"); 3164 + pr_debug("sep_crypto_init alg is NULL\n"); 3309 3165 else 3310 - dev_dbg(&sctx->sep_used->pdev->dev, "alg is %s\n", alg_name); 3166 + pr_debug("sep_crypto_init alg is %s\n", alg_name); 3311 3167 3312 - tfm->crt_ablkcipher.reqsize = sizeof(struct sep_block_ctx); 3313 - dev_dbg(&sctx->sep_used->pdev->dev, "sep_crypto_init\n"); 3168 + tfm->crt_ablkcipher.reqsize = sizeof(struct this_task_ctx); 3314 3169 return 0; 3315 3170 } 3316 3171 3317 3172 static void sep_crypto_exit(struct crypto_tfm *tfm) 3318 3173 { 3319 - struct sep_system_ctx *sctx = crypto_tfm_ctx(tfm); 3320 - dev_dbg(&sctx->sep_used->pdev->dev, "sep_crypto_exit\n"); 3321 - sctx->sep_used = NULL; 3174 + pr_debug("sep_crypto_exit\n"); 3322 3175 } 3323 3176 3324 3177 static int sep_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ··· 3392 3113 { 3393 3114 struct sep_system_ctx *sctx = crypto_ablkcipher_ctx(tfm); 3394 3115 3395 - dev_dbg(&sctx->sep_used->pdev->dev, "sep aes setkey\n"); 3116 + pr_debug("sep aes setkey\n"); 3396 3117 3118 + pr_debug("tfm is %p sctx is %p\n", tfm, sctx); 3397 3119 switch (keylen) { 3398 3120 case SEP_AES_KEY_128_SIZE: 3399 3121 sctx->aes_key_size = AES_128; ··· 3409 3129 sctx->aes_key_size = AES_512; 3410 3130 break; 3411 3131 default: 3412 - dev_warn(&sctx->sep_used->pdev->dev, "sep aes key size %x\n", 3132 + pr_debug("invalid sep aes key size %x\n", 3413 3133 keylen); 3414 3134 return -EINVAL; 3415 3135 } ··· 3420 3140 sctx->keylen = keylen; 3421 3141 /* Indicate to encrypt/decrypt function to send key to SEP */ 3422 3142 sctx->key_sent = 0; 3423 - sctx->last_block = 0; 3424 3143 3425 3144 return 0; 3426 3145 } ··· 3427 3148 static int sep_aes_ecb_encrypt(struct ablkcipher_request *req) 3428 3149 { 3429 3150 int error; 3430 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3431 - struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3432 - crypto_ablkcipher_reqtfm(req)); 3151 + int error1; 3152 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3433 3153 3434 - dev_dbg(&sctx->sep_used->pdev->dev, "sep aes ecb encrypt\n"); 3435 - sctx->current_request = AES_ECB; 3436 - sctx->current_hash_req = NULL; 3437 - sctx->current_cypher_req = req; 3438 - bctx->aes_encmode = SEP_AES_ENCRYPT; 3439 - bctx->aes_opmode = SEP_AES_ECB; 3440 - bctx->init_opcode = SEP_AES_INIT_OPCODE; 3441 - bctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3154 + pr_debug("sep - doing aes ecb encrypt\n"); 3442 3155 3156 + /* Clear out task context */ 3157 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3158 + 3159 + ta_ctx->sep_used = sep_dev; 3160 + ta_ctx->current_request = AES_ECB; 3161 + ta_ctx->current_hash_req = NULL; 3162 + ta_ctx->current_cypher_req = req; 3163 + ta_ctx->aes_encmode = SEP_AES_ENCRYPT; 3164 + ta_ctx->aes_opmode = SEP_AES_ECB; 3165 + ta_ctx->init_opcode = SEP_AES_INIT_OPCODE; 3166 + ta_ctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3167 + 3168 + /* lock necessary so that only one entity touches the queues */ 3443 3169 spin_lock_irq(&queue_lock); 3444 3170 error = crypto_enqueue_request(&sep_queue, &req->base); 3171 + 3172 + if ((error != 0) && (error != -EINPROGRESS)) 3173 + pr_debug(" sep - crypto enqueue failed: %x\n", 3174 + error); 3175 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3176 + sep_dequeuer, (void *)&sep_queue); 3177 + if (error1) 3178 + pr_debug(" sep - workqueue submit failed: %x\n", 3179 + error1); 3445 3180 spin_unlock_irq(&queue_lock); 3446 - 3447 - if ((error != 0) && (error != -EINPROGRESS)) { 3448 - dev_warn(&sctx->sep_used->pdev->dev, 3449 - "sep_aes_ecb_encrypt cant enqueue\n"); 3450 - sep_crypto_release(sctx, error); 3451 - return error; 3452 - } 3453 - 3454 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3455 - (void *)&sep_queue); 3456 - if (error) { 3457 - dev_warn(&sctx->sep_used->pdev->dev, 3458 - "sep_aes_ecb_encrypt cannot submit queue\n"); 3459 - sep_crypto_release(sctx, -EINVAL); 3460 - return -EINVAL; 3461 - } 3462 - return -EINPROGRESS; 3181 + /* We return result of crypto enqueue */ 3182 + return error; 3463 3183 } 3464 3184 3465 3185 static int sep_aes_ecb_decrypt(struct ablkcipher_request *req) 3466 3186 { 3467 3187 int error; 3468 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3469 - struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3470 - crypto_ablkcipher_reqtfm(req)); 3188 + int error1; 3189 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3471 3190 3472 - dev_dbg(&sctx->sep_used->pdev->dev, "sep aes ecb decrypt\n"); 3473 - sctx->current_request = AES_ECB; 3474 - sctx->current_hash_req = NULL; 3475 - sctx->current_cypher_req = req; 3476 - bctx->aes_encmode = SEP_AES_DECRYPT; 3477 - bctx->aes_opmode = SEP_AES_ECB; 3478 - bctx->init_opcode = SEP_AES_INIT_OPCODE; 3479 - bctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3191 + pr_debug("sep - doing aes ecb decrypt\n"); 3480 3192 3193 + /* Clear out task context */ 3194 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3195 + 3196 + ta_ctx->sep_used = sep_dev; 3197 + ta_ctx->current_request = AES_ECB; 3198 + ta_ctx->current_hash_req = NULL; 3199 + ta_ctx->current_cypher_req = req; 3200 + ta_ctx->aes_encmode = SEP_AES_DECRYPT; 3201 + ta_ctx->aes_opmode = SEP_AES_ECB; 3202 + ta_ctx->init_opcode = SEP_AES_INIT_OPCODE; 3203 + ta_ctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3204 + 3205 + /* lock necessary so that only one entity touches the queues */ 3481 3206 spin_lock_irq(&queue_lock); 3482 3207 error = crypto_enqueue_request(&sep_queue, &req->base); 3208 + 3209 + if ((error != 0) && (error != -EINPROGRESS)) 3210 + pr_debug(" sep - crypto enqueue failed: %x\n", 3211 + error); 3212 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3213 + sep_dequeuer, (void *)&sep_queue); 3214 + if (error1) 3215 + pr_debug(" sep - workqueue submit failed: %x\n", 3216 + error1); 3483 3217 spin_unlock_irq(&queue_lock); 3484 - 3485 - if ((error != 0) && (error != -EINPROGRESS)) { 3486 - dev_warn(&sctx->sep_used->pdev->dev, 3487 - "sep_aes_ecb_decrypt cant enqueue\n"); 3488 - sep_crypto_release(sctx, error); 3489 - return error; 3490 - } 3491 - 3492 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3493 - (void *)&sep_queue); 3494 - if (error) { 3495 - dev_warn(&sctx->sep_used->pdev->dev, 3496 - "sep_aes_ecb_decrypt cannot submit queue\n"); 3497 - sep_crypto_release(sctx, -EINVAL); 3498 - return -EINVAL; 3499 - } 3500 - return -EINPROGRESS; 3218 + /* We return result of crypto enqueue */ 3219 + return error; 3501 3220 } 3502 3221 3503 3222 static int sep_aes_cbc_encrypt(struct ablkcipher_request *req) 3504 3223 { 3505 3224 int error; 3506 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3225 + int error1; 3226 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3507 3227 struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3508 3228 crypto_ablkcipher_reqtfm(req)); 3509 3229 3510 - dev_dbg(&sctx->sep_used->pdev->dev, "sep aes cbc encrypt\n"); 3511 - sctx->current_request = AES_CBC; 3512 - sctx->current_hash_req = NULL; 3513 - sctx->current_cypher_req = req; 3514 - bctx->aes_encmode = SEP_AES_ENCRYPT; 3515 - bctx->aes_opmode = SEP_AES_CBC; 3516 - bctx->init_opcode = SEP_AES_INIT_OPCODE; 3517 - bctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3230 + pr_debug("sep - doing aes cbc encrypt\n"); 3518 3231 3232 + /* Clear out task context */ 3233 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3234 + 3235 + pr_debug("tfm is %p sctx is %p and ta_ctx is %p\n", 3236 + crypto_ablkcipher_reqtfm(req), sctx, ta_ctx); 3237 + 3238 + ta_ctx->sep_used = sep_dev; 3239 + ta_ctx->current_request = AES_CBC; 3240 + ta_ctx->current_hash_req = NULL; 3241 + ta_ctx->current_cypher_req = req; 3242 + ta_ctx->aes_encmode = SEP_AES_ENCRYPT; 3243 + ta_ctx->aes_opmode = SEP_AES_CBC; 3244 + ta_ctx->init_opcode = SEP_AES_INIT_OPCODE; 3245 + ta_ctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3246 + 3247 + /* lock necessary so that only one entity touches the queues */ 3519 3248 spin_lock_irq(&queue_lock); 3520 3249 error = crypto_enqueue_request(&sep_queue, &req->base); 3250 + 3251 + if ((error != 0) && (error != -EINPROGRESS)) 3252 + pr_debug(" sep - crypto enqueue failed: %x\n", 3253 + error); 3254 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3255 + sep_dequeuer, (void *)&sep_queue); 3256 + if (error1) 3257 + pr_debug(" sep - workqueue submit failed: %x\n", 3258 + error1); 3521 3259 spin_unlock_irq(&queue_lock); 3522 - 3523 - if ((error != 0) && (error != -EINPROGRESS)) { 3524 - dev_warn(&sctx->sep_used->pdev->dev, 3525 - "sep_aes_cbc_encrypt cant enqueue\n"); 3526 - sep_crypto_release(sctx, error); 3527 - return error; 3528 - } 3529 - 3530 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3531 - (void *)&sep_queue); 3532 - if (error) { 3533 - dev_warn(&sctx->sep_used->pdev->dev, 3534 - "sep_aes_cbc_encrypt cannot submit queue\n"); 3535 - sep_crypto_release(sctx, -EINVAL); 3536 - return -EINVAL; 3537 - } 3538 - return -EINPROGRESS; 3260 + /* We return result of crypto enqueue */ 3261 + return error; 3539 3262 } 3540 3263 3541 3264 static int sep_aes_cbc_decrypt(struct ablkcipher_request *req) 3542 3265 { 3543 3266 int error; 3544 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3267 + int error1; 3268 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3545 3269 struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3546 3270 crypto_ablkcipher_reqtfm(req)); 3547 3271 3548 - dev_dbg(&sctx->sep_used->pdev->dev, "sep aes cbc decrypt\n"); 3549 - sctx->current_request = AES_CBC; 3550 - sctx->current_hash_req = NULL; 3551 - sctx->current_cypher_req = req; 3552 - bctx->aes_encmode = SEP_AES_DECRYPT; 3553 - bctx->aes_opmode = SEP_AES_CBC; 3554 - bctx->init_opcode = SEP_AES_INIT_OPCODE; 3555 - bctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3272 + pr_debug("sep - doing aes cbc decrypt\n"); 3556 3273 3274 + pr_debug("tfm is %p sctx is %p and ta_ctx is %p\n", 3275 + crypto_ablkcipher_reqtfm(req), sctx, ta_ctx); 3276 + 3277 + /* Clear out task context */ 3278 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3279 + 3280 + ta_ctx->sep_used = sep_dev; 3281 + ta_ctx->current_request = AES_CBC; 3282 + ta_ctx->current_hash_req = NULL; 3283 + ta_ctx->current_cypher_req = req; 3284 + ta_ctx->aes_encmode = SEP_AES_DECRYPT; 3285 + ta_ctx->aes_opmode = SEP_AES_CBC; 3286 + ta_ctx->init_opcode = SEP_AES_INIT_OPCODE; 3287 + ta_ctx->block_opcode = SEP_AES_BLOCK_OPCODE; 3288 + 3289 + /* lock necessary so that only one entity touches the queues */ 3557 3290 spin_lock_irq(&queue_lock); 3558 3291 error = crypto_enqueue_request(&sep_queue, &req->base); 3292 + 3293 + if ((error != 0) && (error != -EINPROGRESS)) 3294 + pr_debug(" sep - crypto enqueue failed: %x\n", 3295 + error); 3296 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3297 + sep_dequeuer, (void *)&sep_queue); 3298 + if (error1) 3299 + pr_debug(" sep - workqueue submit failed: %x\n", 3300 + error1); 3559 3301 spin_unlock_irq(&queue_lock); 3560 - 3561 - if ((error != 0) && (error != -EINPROGRESS)) { 3562 - dev_warn(&sctx->sep_used->pdev->dev, 3563 - "sep_aes_cbc_decrypt cant enqueue\n"); 3564 - sep_crypto_release(sctx, error); 3565 - return error; 3566 - } 3567 - 3568 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3569 - (void *)&sep_queue); 3570 - if (error) { 3571 - dev_warn(&sctx->sep_used->pdev->dev, 3572 - "sep_aes_cbc_decrypt cannot submit queue\n"); 3573 - sep_crypto_release(sctx, -EINVAL); 3574 - return -EINVAL; 3575 - } 3576 - return -EINPROGRESS; 3302 + /* We return result of crypto enqueue */ 3303 + return error; 3577 3304 } 3578 3305 3579 3306 static int sep_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ··· 3589 3304 struct crypto_tfm *ctfm = crypto_ablkcipher_tfm(tfm); 3590 3305 u32 *flags = &ctfm->crt_flags; 3591 3306 3592 - dev_dbg(&sctx->sep_used->pdev->dev, "sep des setkey\n"); 3307 + pr_debug("sep des setkey\n"); 3593 3308 3594 3309 switch (keylen) { 3595 3310 case DES_KEY_SIZE: ··· 3602 3317 sctx->des_nbr_keys = DES_KEY_3; 3603 3318 break; 3604 3319 default: 3605 - dev_dbg(&sctx->sep_used->pdev->dev, "invalid key size %x\n", 3320 + pr_debug("invalid key size %x\n", 3606 3321 keylen); 3607 3322 return -EINVAL; 3608 3323 } ··· 3611 3326 (sep_weak_key(key, keylen))) { 3612 3327 3613 3328 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 3614 - dev_warn(&sctx->sep_used->pdev->dev, "weak key\n"); 3329 + pr_debug("weak key\n"); 3615 3330 return -EINVAL; 3616 3331 } 3617 3332 ··· 3620 3335 sctx->keylen = keylen; 3621 3336 /* Indicate to encrypt/decrypt function to send key to SEP */ 3622 3337 sctx->key_sent = 0; 3623 - sctx->last_block = 0; 3624 3338 3625 3339 return 0; 3626 3340 } ··· 3627 3343 static int sep_des_ebc_encrypt(struct ablkcipher_request *req) 3628 3344 { 3629 3345 int error; 3630 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3631 - struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3632 - crypto_ablkcipher_reqtfm(req)); 3346 + int error1; 3347 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3633 3348 3634 - dev_dbg(&sctx->sep_used->pdev->dev, "sep des ecb encrypt\n"); 3635 - sctx->current_request = DES_ECB; 3636 - sctx->current_hash_req = NULL; 3637 - sctx->current_cypher_req = req; 3638 - bctx->des_encmode = SEP_DES_ENCRYPT; 3639 - bctx->des_opmode = SEP_DES_ECB; 3640 - bctx->init_opcode = SEP_DES_INIT_OPCODE; 3641 - bctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3349 + pr_debug("sep - doing des ecb encrypt\n"); 3642 3350 3351 + /* Clear out task context */ 3352 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3353 + 3354 + ta_ctx->sep_used = sep_dev; 3355 + ta_ctx->current_request = DES_ECB; 3356 + ta_ctx->current_hash_req = NULL; 3357 + ta_ctx->current_cypher_req = req; 3358 + ta_ctx->des_encmode = SEP_DES_ENCRYPT; 3359 + ta_ctx->des_opmode = SEP_DES_ECB; 3360 + ta_ctx->init_opcode = SEP_DES_INIT_OPCODE; 3361 + ta_ctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3362 + 3363 + /* lock necessary so that only one entity touches the queues */ 3643 3364 spin_lock_irq(&queue_lock); 3644 3365 error = crypto_enqueue_request(&sep_queue, &req->base); 3366 + 3367 + if ((error != 0) && (error != -EINPROGRESS)) 3368 + pr_debug(" sep - crypto enqueue failed: %x\n", 3369 + error); 3370 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3371 + sep_dequeuer, (void *)&sep_queue); 3372 + if (error1) 3373 + pr_debug(" sep - workqueue submit failed: %x\n", 3374 + error1); 3645 3375 spin_unlock_irq(&queue_lock); 3646 - 3647 - if ((error != 0) && (error != -EINPROGRESS)) { 3648 - dev_warn(&sctx->sep_used->pdev->dev, 3649 - "sep_des_ecb_encrypt cant enqueue\n"); 3650 - sep_crypto_release(sctx, error); 3651 - return error; 3652 - } 3653 - 3654 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3655 - (void *)&sep_queue); 3656 - if (error) { 3657 - dev_warn(&sctx->sep_used->pdev->dev, 3658 - "sep_des_ecb_encrypt cannot submit queue\n"); 3659 - sep_crypto_release(sctx, -EINVAL); 3660 - return -EINVAL; 3661 - } 3662 - return -EINPROGRESS; 3376 + /* We return result of crypto enqueue */ 3377 + return error; 3663 3378 } 3664 3379 3665 3380 static int sep_des_ebc_decrypt(struct ablkcipher_request *req) 3666 3381 { 3667 3382 int error; 3668 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3669 - struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3670 - crypto_ablkcipher_reqtfm(req)); 3383 + int error1; 3384 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3671 3385 3672 - dev_dbg(&sctx->sep_used->pdev->dev, "sep des ecb decrypt\n"); 3673 - sctx->current_request = DES_ECB; 3674 - sctx->current_hash_req = NULL; 3675 - sctx->current_cypher_req = req; 3676 - bctx->des_encmode = SEP_DES_DECRYPT; 3677 - bctx->des_opmode = SEP_DES_ECB; 3678 - bctx->init_opcode = SEP_DES_INIT_OPCODE; 3679 - bctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3386 + pr_debug("sep - doing des ecb decrypt\n"); 3680 3387 3388 + /* Clear out task context */ 3389 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3390 + 3391 + ta_ctx->sep_used = sep_dev; 3392 + ta_ctx->current_request = DES_ECB; 3393 + ta_ctx->current_hash_req = NULL; 3394 + ta_ctx->current_cypher_req = req; 3395 + ta_ctx->des_encmode = SEP_DES_DECRYPT; 3396 + ta_ctx->des_opmode = SEP_DES_ECB; 3397 + ta_ctx->init_opcode = SEP_DES_INIT_OPCODE; 3398 + ta_ctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3399 + 3400 + /* lock necessary so that only one entity touches the queues */ 3681 3401 spin_lock_irq(&queue_lock); 3682 3402 error = crypto_enqueue_request(&sep_queue, &req->base); 3403 + 3404 + if ((error != 0) && (error != -EINPROGRESS)) 3405 + pr_debug(" sep - crypto enqueue failed: %x\n", 3406 + error); 3407 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3408 + sep_dequeuer, (void *)&sep_queue); 3409 + if (error1) 3410 + pr_debug(" sep - workqueue submit failed: %x\n", 3411 + error1); 3683 3412 spin_unlock_irq(&queue_lock); 3684 - 3685 - if ((error != 0) && (error != -EINPROGRESS)) { 3686 - dev_warn(&sctx->sep_used->pdev->dev, 3687 - "sep_des_ecb_decrypt cant enqueue\n"); 3688 - sep_crypto_release(sctx, error); 3689 - return error; 3690 - } 3691 - 3692 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3693 - (void *)&sep_queue); 3694 - if (error) { 3695 - dev_warn(&sctx->sep_used->pdev->dev, 3696 - "sep_des_ecb_decrypt cannot submit queue\n"); 3697 - sep_crypto_release(sctx, -EINVAL); 3698 - return -EINVAL; 3699 - } 3700 - return -EINPROGRESS; 3413 + /* We return result of crypto enqueue */ 3414 + return error; 3701 3415 } 3702 3416 3703 3417 static int sep_des_cbc_encrypt(struct ablkcipher_request *req) 3704 3418 { 3705 3419 int error; 3706 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3707 - struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3708 - crypto_ablkcipher_reqtfm(req)); 3420 + int error1; 3421 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3709 3422 3710 - dev_dbg(&sctx->sep_used->pdev->dev, "sep des cbc encrypt\n"); 3711 - sctx->current_request = DES_CBC; 3712 - sctx->current_hash_req = NULL; 3713 - sctx->current_cypher_req = req; 3714 - bctx->des_encmode = SEP_DES_ENCRYPT; 3715 - bctx->des_opmode = SEP_DES_CBC; 3716 - bctx->init_opcode = SEP_DES_INIT_OPCODE; 3717 - bctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3423 + pr_debug("sep - doing des cbc encrypt\n"); 3718 3424 3425 + /* Clear out task context */ 3426 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3427 + 3428 + ta_ctx->sep_used = sep_dev; 3429 + ta_ctx->current_request = DES_CBC; 3430 + ta_ctx->current_hash_req = NULL; 3431 + ta_ctx->current_cypher_req = req; 3432 + ta_ctx->des_encmode = SEP_DES_ENCRYPT; 3433 + ta_ctx->des_opmode = SEP_DES_CBC; 3434 + ta_ctx->init_opcode = SEP_DES_INIT_OPCODE; 3435 + ta_ctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3436 + 3437 + /* lock necessary so that only one entity touches the queues */ 3719 3438 spin_lock_irq(&queue_lock); 3720 3439 error = crypto_enqueue_request(&sep_queue, &req->base); 3440 + 3441 + if ((error != 0) && (error != -EINPROGRESS)) 3442 + pr_debug(" sep - crypto enqueue failed: %x\n", 3443 + error); 3444 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3445 + sep_dequeuer, (void *)&sep_queue); 3446 + if (error1) 3447 + pr_debug(" sep - workqueue submit failed: %x\n", 3448 + error1); 3721 3449 spin_unlock_irq(&queue_lock); 3722 - 3723 - if ((error != 0) && (error != -EINPROGRESS)) { 3724 - dev_warn(&sctx->sep_used->pdev->dev, 3725 - "sep_des_cbc_encrypt cant enqueue\n"); 3726 - sep_crypto_release(sctx, error); 3727 - return error; 3728 - } 3729 - 3730 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3731 - (void *)&sep_queue); 3732 - if (error) { 3733 - dev_warn(&sctx->sep_used->pdev->dev, 3734 - "sep_des_cbc_encrypt cannot submit queue\n"); 3735 - sep_crypto_release(sctx, -EINVAL); 3736 - return -EINVAL; 3737 - } 3738 - return -EINPROGRESS; 3450 + /* We return result of crypto enqueue */ 3451 + return error; 3739 3452 } 3740 3453 3741 3454 static int sep_des_cbc_decrypt(struct ablkcipher_request *req) 3742 3455 { 3743 3456 int error; 3744 - struct sep_block_ctx *bctx = ablkcipher_request_ctx(req); 3745 - struct sep_system_ctx *sctx = crypto_ablkcipher_ctx( 3746 - crypto_ablkcipher_reqtfm(req)); 3457 + int error1; 3458 + struct this_task_ctx *ta_ctx = ablkcipher_request_ctx(req); 3747 3459 3748 - dev_dbg(&sctx->sep_used->pdev->dev, "sep des cbc decrypt\n"); 3749 - sctx->current_request = DES_CBC; 3750 - sctx->current_hash_req = NULL; 3751 - sctx->current_cypher_req = req; 3752 - bctx->des_encmode = SEP_DES_DECRYPT; 3753 - bctx->des_opmode = SEP_DES_CBC; 3754 - bctx->init_opcode = SEP_DES_INIT_OPCODE; 3755 - bctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3460 + pr_debug("sep - doing des ecb decrypt\n"); 3756 3461 3462 + /* Clear out task context */ 3463 + memset(ta_ctx, 0, sizeof(struct this_task_ctx)); 3464 + 3465 + ta_ctx->sep_used = sep_dev; 3466 + ta_ctx->current_request = DES_CBC; 3467 + ta_ctx->current_hash_req = NULL; 3468 + ta_ctx->current_cypher_req = req; 3469 + ta_ctx->des_encmode = SEP_DES_DECRYPT; 3470 + ta_ctx->des_opmode = SEP_DES_CBC; 3471 + ta_ctx->init_opcode = SEP_DES_INIT_OPCODE; 3472 + ta_ctx->block_opcode = SEP_DES_BLOCK_OPCODE; 3473 + 3474 + /* lock necessary so that only one entity touches the queues */ 3757 3475 spin_lock_irq(&queue_lock); 3758 3476 error = crypto_enqueue_request(&sep_queue, &req->base); 3477 + 3478 + if ((error != 0) && (error != -EINPROGRESS)) 3479 + pr_debug(" sep - crypto enqueue failed: %x\n", 3480 + error); 3481 + error1 = sep_submit_work(ta_ctx->sep_used->workqueue, 3482 + sep_dequeuer, (void *)&sep_queue); 3483 + if (error1) 3484 + pr_debug(" sep - workqueue submit failed: %x\n", 3485 + error1); 3759 3486 spin_unlock_irq(&queue_lock); 3760 - 3761 - if ((error != 0) && (error != -EINPROGRESS)) { 3762 - dev_warn(&sctx->sep_used->pdev->dev, 3763 - "sep_des_cbc_decrypt cant enqueue\n"); 3764 - sep_crypto_release(sctx, error); 3765 - return error; 3766 - } 3767 - 3768 - error = sep_submit_work(sctx->sep_used->workqueue, sep_dequeuer, 3769 - (void *)&sep_queue); 3770 - if (error) { 3771 - dev_warn(&sctx->sep_used->pdev->dev, 3772 - "sep_des_cbc_decrypt cannot submit queue\n"); 3773 - sep_crypto_release(sctx, -EINVAL); 3774 - return -EINVAL; 3775 - } 3776 - return -EINPROGRESS; 3487 + /* We return result of crypto enqueue */ 3488 + return error; 3777 3489 } 3778 3490 3779 3491 static struct ahash_alg hash_algs[] = { ··· 3778 3498 .update = sep_sha1_update, 3779 3499 .final = sep_sha1_final, 3780 3500 .digest = sep_sha1_digest, 3501 + .finup = sep_sha1_finup, 3781 3502 .halg = { 3782 3503 .digestsize = SHA1_DIGEST_SIZE, 3783 3504 .base = { ··· 3801 3520 .update = sep_md5_update, 3802 3521 .final = sep_md5_final, 3803 3522 .digest = sep_md5_digest, 3523 + .finup = sep_md5_finup, 3804 3524 .halg = { 3805 3525 .digestsize = MD5_DIGEST_SIZE, 3806 3526 .base = { ··· 3824 3542 .update = sep_sha224_update, 3825 3543 .final = sep_sha224_final, 3826 3544 .digest = sep_sha224_digest, 3545 + .finup = sep_sha224_finup, 3827 3546 .halg = { 3828 3547 .digestsize = SHA224_DIGEST_SIZE, 3829 3548 .base = { ··· 3847 3564 .update = sep_sha256_update, 3848 3565 .final = sep_sha256_final, 3849 3566 .digest = sep_sha256_digest, 3567 + .finup = sep_sha256_finup, 3850 3568 .halg = { 3851 3569 .digestsize = SHA256_DIGEST_SIZE, 3852 3570 .base = { ··· 3905 3621 .max_keysize = AES_MAX_KEY_SIZE, 3906 3622 .setkey = sep_aes_setkey, 3907 3623 .encrypt = sep_aes_cbc_encrypt, 3624 + .ivsize = AES_BLOCK_SIZE, 3908 3625 .decrypt = sep_aes_cbc_decrypt, 3909 3626 } 3910 3627 }, ··· 3946 3661 .max_keysize = DES_KEY_SIZE, 3947 3662 .setkey = sep_des_setkey, 3948 3663 .encrypt = sep_des_cbc_encrypt, 3664 + .ivsize = DES_BLOCK_SIZE, 3949 3665 .decrypt = sep_des_cbc_decrypt, 3950 3666 } 3951 3667 }, ··· 4000 3714 4001 3715 crypto_init_queue(&sep_queue, SEP_QUEUE_LENGTH); 4002 3716 4003 - sep_dev->workqueue = create_workqueue("sep_crypto_workqueue"); 3717 + sep_dev->workqueue = create_singlethread_workqueue( 3718 + "sep_crypto_workqueue"); 4004 3719 if (!sep_dev->workqueue) { 4005 3720 dev_warn(&sep_dev->pdev->dev, "cant create workqueue\n"); 4006 3721 return -ENOMEM; ··· 4010 3723 i = 0; 4011 3724 j = 0; 4012 3725 4013 - spin_lock_init(&sep_dev->busy_lock); 4014 3726 spin_lock_init(&queue_lock); 4015 3727 4016 3728 err = 0;
+44 -33
drivers/staging/sep/sep_crypto.h
··· 117 117 118 118 #define SEP_TRANSACTION_WAIT_TIME 5 119 119 120 - #define SEP_QUEUE_LENGTH 10 120 + #define SEP_QUEUE_LENGTH 2 121 121 /* Macros */ 122 122 #ifndef __LITTLE_ENDIAN 123 123 #define CHG_ENDIAN(val) \ ··· 270 270 u8 internal_context[sizeof(struct sep_hash_internal_context)]; 271 271 }; 272 272 273 + union key_t { 274 + struct sep_des_key des; 275 + u32 aes[SEP_AES_MAX_KEY_SIZE_WORDS]; 276 + }; 277 + 273 278 /* Context structures for crypto API */ 274 - struct sep_block_ctx { 275 - struct sep_device *sep; 279 + /** 280 + * Structure for this current task context 281 + * This same structure is used for both hash 282 + * and crypt in order to reduce duplicate code 283 + * for stuff that is done for both hash operations 284 + * and crypto operations. We cannot trust that the 285 + * system context is not pulled out from under 286 + * us during operation to operation, so all 287 + * critical stuff such as data pointers must 288 + * be in in a context that is exclusive for this 289 + * particular task at hand. 290 + */ 291 + struct this_task_ctx { 292 + struct sep_device *sep_used; 276 293 u32 done; 277 294 unsigned char iv[100]; 278 295 enum des_enc_mode des_encmode; ··· 301 284 size_t data_length; 302 285 size_t ivlen; 303 286 struct ablkcipher_walk walk; 304 - struct sep_des_private_context des_private_ctx; 305 - struct sep_aes_private_context aes_private_ctx; 306 - }; 307 - 308 - struct sep_hash_ctx { 309 - u32 done; 310 - unsigned char *buf; 311 - size_t buflen; 312 - unsigned char *dgst; 313 - int digest_size_words; 314 - int digest_size_bytes; 315 - int block_size_words; 316 - int block_size_bytes; 317 - struct scatterlist *sg; 318 - enum hash_op_mode hash_opmode; 319 - struct sep_hash_private_context hash_private_ctx; 320 - }; 321 - 322 - struct sep_system_ctx { 323 - struct sep_device *sep_used; 324 - union key_t { 325 - struct sep_des_key des; 326 - u32 aes[SEP_AES_MAX_KEY_SIZE_WORDS]; 327 - } key; 328 287 int i_own_sep; /* Do I have custody of the sep? */ 329 - size_t keylen; 330 - enum des_numkey des_nbr_keys; 331 - enum aes_keysize aes_key_size; 332 - u32 key_sent; /* Indicate if key is sent to sep */ 333 - u32 last_block; /* Indicate that this is the final block */ 334 288 struct sep_call_status call_status; 335 289 struct build_dcb_struct_kernel dcb_input_data; 336 290 struct sep_dma_context *dma_ctx; ··· 319 331 struct ahash_request *current_hash_req; 320 332 struct ablkcipher_request *current_cypher_req; 321 333 enum type_of_request current_request; 334 + int digest_size_words; 335 + int digest_size_bytes; 336 + int block_size_words; 337 + int block_size_bytes; 338 + enum hash_op_mode hash_opmode; 322 339 enum hash_stage current_hash_stage; 323 - int done_with_transaction; 340 + /** 341 + * Not that this is a pointer. The are_we_done_yet variable is 342 + * allocated by the task function. This way, even if the kernel 343 + * crypto infrastructure has grabbed the task structure out from 344 + * under us, the task function can still see this variable. 345 + */ 346 + int *are_we_done_yet; 324 347 unsigned long end_time; 348 + }; 349 + 350 + struct sep_system_ctx { 351 + union key_t key; 352 + size_t keylen; 353 + int key_sent; 354 + enum des_numkey des_nbr_keys; 355 + enum aes_keysize aes_key_size; 356 + unsigned long end_time; 357 + struct sep_des_private_context des_private_ctx; 358 + struct sep_aes_private_context aes_private_ctx; 359 + struct sep_hash_private_context hash_private_ctx; 325 360 }; 326 361 327 362 /* work queue structures */
+1 -2
drivers/staging/sep/sep_dev.h
··· 93 93 enum hash_stage current_hash_stage; 94 94 struct ahash_request *current_hash_req; 95 95 struct ablkcipher_request *current_cypher_req; 96 - struct sep_system_ctx *sctx; 97 - spinlock_t busy_lock; 96 + struct this_task_ctx *ta_ctx; 98 97 struct workqueue_struct *workqueue; 99 98 }; 100 99