| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - This file is provided under a dual BSD/GPLv2 license. When using or |
|---|
| 3 | | - redistributing this file, you may do so under either license. |
|---|
| 4 | | - |
|---|
| 5 | | - GPL LICENSE SUMMARY |
|---|
| 6 | | - Copyright(c) 2014 Intel Corporation. |
|---|
| 7 | | - This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - it under the terms of version 2 of the GNU General Public License as |
|---|
| 9 | | - published by the Free Software Foundation. |
|---|
| 10 | | - |
|---|
| 11 | | - This program is distributed in the hope that it will be useful, but |
|---|
| 12 | | - WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 14 | | - General Public License for more details. |
|---|
| 15 | | - |
|---|
| 16 | | - Contact Information: |
|---|
| 17 | | - qat-linux@intel.com |
|---|
| 18 | | - |
|---|
| 19 | | - BSD LICENSE |
|---|
| 20 | | - Copyright(c) 2014 Intel Corporation. |
|---|
| 21 | | - Redistribution and use in source and binary forms, with or without |
|---|
| 22 | | - modification, are permitted provided that the following conditions |
|---|
| 23 | | - are met: |
|---|
| 24 | | - |
|---|
| 25 | | - * Redistributions of source code must retain the above copyright |
|---|
| 26 | | - notice, this list of conditions and the following disclaimer. |
|---|
| 27 | | - * Redistributions in binary form must reproduce the above copyright |
|---|
| 28 | | - notice, this list of conditions and the following disclaimer in |
|---|
| 29 | | - the documentation and/or other materials provided with the |
|---|
| 30 | | - distribution. |
|---|
| 31 | | - * Neither the name of Intel Corporation nor the names of its |
|---|
| 32 | | - contributors may be used to endorse or promote products derived |
|---|
| 33 | | - from this software without specific prior written permission. |
|---|
| 34 | | - |
|---|
| 35 | | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 36 | | - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 37 | | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 38 | | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 39 | | - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 40 | | - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 41 | | - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 42 | | - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 43 | | - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 44 | | - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 45 | | - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 46 | | -*/ |
|---|
| 47 | | - |
|---|
| 1 | +// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) |
|---|
| 2 | +/* Copyright(c) 2014 - 2020 Intel Corporation */ |
|---|
| 48 | 3 | #include <linux/module.h> |
|---|
| 49 | 4 | #include <crypto/internal/rsa.h> |
|---|
| 50 | 5 | #include <crypto/internal/akcipher.h> |
|---|
| .. | .. |
|---|
| 332 | 287 | } else { |
|---|
| 333 | 288 | int shift = ctx->p_size - req->src_len; |
|---|
| 334 | 289 | |
|---|
| 335 | | - qat_req->src_align = dma_zalloc_coherent(dev, |
|---|
| 336 | | - ctx->p_size, |
|---|
| 337 | | - &qat_req->in.dh.in.b, |
|---|
| 338 | | - GFP_KERNEL); |
|---|
| 290 | + qat_req->src_align = dma_alloc_coherent(dev, |
|---|
| 291 | + ctx->p_size, |
|---|
| 292 | + &qat_req->in.dh.in.b, |
|---|
| 293 | + GFP_KERNEL); |
|---|
| 339 | 294 | if (unlikely(!qat_req->src_align)) |
|---|
| 340 | 295 | return ret; |
|---|
| 341 | 296 | |
|---|
| .. | .. |
|---|
| 360 | 315 | goto unmap_src; |
|---|
| 361 | 316 | |
|---|
| 362 | 317 | } else { |
|---|
| 363 | | - qat_req->dst_align = dma_zalloc_coherent(dev, ctx->p_size, |
|---|
| 364 | | - &qat_req->out.dh.r, |
|---|
| 365 | | - GFP_KERNEL); |
|---|
| 318 | + qat_req->dst_align = dma_alloc_coherent(dev, ctx->p_size, |
|---|
| 319 | + &qat_req->out.dh.r, |
|---|
| 320 | + GFP_KERNEL); |
|---|
| 366 | 321 | if (unlikely(!qat_req->dst_align)) |
|---|
| 367 | 322 | goto unmap_src; |
|---|
| 368 | 323 | } |
|---|
| .. | .. |
|---|
| 384 | 339 | |
|---|
| 385 | 340 | msg->pke_mid.src_data_addr = qat_req->phy_in; |
|---|
| 386 | 341 | msg->pke_mid.dest_data_addr = qat_req->phy_out; |
|---|
| 387 | | - msg->pke_mid.opaque = (uint64_t)(__force long)qat_req; |
|---|
| 342 | + msg->pke_mid.opaque = (u64)(__force long)qat_req; |
|---|
| 388 | 343 | msg->input_param_count = n_input_params; |
|---|
| 389 | 344 | msg->output_param_count = 1; |
|---|
| 390 | 345 | |
|---|
| 391 | 346 | do { |
|---|
| 392 | | - ret = adf_send_message(ctx->inst->pke_tx, (uint32_t *)msg); |
|---|
| 347 | + ret = adf_send_message(ctx->inst->pke_tx, (u32 *)msg); |
|---|
| 393 | 348 | } while (ret == -EBUSY && ctr++ < 100); |
|---|
| 394 | 349 | |
|---|
| 395 | 350 | if (!ret) |
|---|
| .. | .. |
|---|
| 447 | 402 | return -EINVAL; |
|---|
| 448 | 403 | |
|---|
| 449 | 404 | ctx->p_size = params->p_size; |
|---|
| 450 | | - ctx->p = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_p, GFP_KERNEL); |
|---|
| 405 | + ctx->p = dma_alloc_coherent(dev, ctx->p_size, &ctx->dma_p, GFP_KERNEL); |
|---|
| 451 | 406 | if (!ctx->p) |
|---|
| 452 | 407 | return -ENOMEM; |
|---|
| 453 | 408 | memcpy(ctx->p, params->p, ctx->p_size); |
|---|
| .. | .. |
|---|
| 458 | 413 | return 0; |
|---|
| 459 | 414 | } |
|---|
| 460 | 415 | |
|---|
| 461 | | - ctx->g = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_g, GFP_KERNEL); |
|---|
| 416 | + ctx->g = dma_alloc_coherent(dev, ctx->p_size, &ctx->dma_g, GFP_KERNEL); |
|---|
| 462 | 417 | if (!ctx->g) |
|---|
| 463 | 418 | return -ENOMEM; |
|---|
| 464 | 419 | memcpy(ctx->g + (ctx->p_size - params->g_size), params->g, |
|---|
| .. | .. |
|---|
| 503 | 458 | if (ret < 0) |
|---|
| 504 | 459 | goto err_clear_ctx; |
|---|
| 505 | 460 | |
|---|
| 506 | | - ctx->xa = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_xa, |
|---|
| 507 | | - GFP_KERNEL); |
|---|
| 461 | + ctx->xa = dma_alloc_coherent(dev, ctx->p_size, &ctx->dma_xa, |
|---|
| 462 | + GFP_KERNEL); |
|---|
| 508 | 463 | if (!ctx->xa) { |
|---|
| 509 | 464 | ret = -ENOMEM; |
|---|
| 510 | 465 | goto err_clear_ctx; |
|---|
| .. | .. |
|---|
| 737 | 692 | } else { |
|---|
| 738 | 693 | int shift = ctx->key_sz - req->src_len; |
|---|
| 739 | 694 | |
|---|
| 740 | | - qat_req->src_align = dma_zalloc_coherent(dev, ctx->key_sz, |
|---|
| 741 | | - &qat_req->in.rsa.enc.m, |
|---|
| 742 | | - GFP_KERNEL); |
|---|
| 695 | + qat_req->src_align = dma_alloc_coherent(dev, ctx->key_sz, |
|---|
| 696 | + &qat_req->in.rsa.enc.m, |
|---|
| 697 | + GFP_KERNEL); |
|---|
| 743 | 698 | if (unlikely(!qat_req->src_align)) |
|---|
| 744 | 699 | return ret; |
|---|
| 745 | 700 | |
|---|
| .. | .. |
|---|
| 756 | 711 | goto unmap_src; |
|---|
| 757 | 712 | |
|---|
| 758 | 713 | } else { |
|---|
| 759 | | - qat_req->dst_align = dma_zalloc_coherent(dev, ctx->key_sz, |
|---|
| 760 | | - &qat_req->out.rsa.enc.c, |
|---|
| 761 | | - GFP_KERNEL); |
|---|
| 714 | + qat_req->dst_align = dma_alloc_coherent(dev, ctx->key_sz, |
|---|
| 715 | + &qat_req->out.rsa.enc.c, |
|---|
| 716 | + GFP_KERNEL); |
|---|
| 762 | 717 | if (unlikely(!qat_req->dst_align)) |
|---|
| 763 | 718 | goto unmap_src; |
|---|
| 764 | 719 | |
|---|
| .. | .. |
|---|
| 779 | 734 | |
|---|
| 780 | 735 | msg->pke_mid.src_data_addr = qat_req->phy_in; |
|---|
| 781 | 736 | msg->pke_mid.dest_data_addr = qat_req->phy_out; |
|---|
| 782 | | - msg->pke_mid.opaque = (uint64_t)(__force long)qat_req; |
|---|
| 737 | + msg->pke_mid.opaque = (u64)(__force long)qat_req; |
|---|
| 783 | 738 | msg->input_param_count = 3; |
|---|
| 784 | 739 | msg->output_param_count = 1; |
|---|
| 785 | 740 | do { |
|---|
| 786 | | - ret = adf_send_message(ctx->inst->pke_tx, (uint32_t *)msg); |
|---|
| 741 | + ret = adf_send_message(ctx->inst->pke_tx, (u32 *)msg); |
|---|
| 787 | 742 | } while (ret == -EBUSY && ctr++ < 100); |
|---|
| 788 | 743 | |
|---|
| 789 | 744 | if (!ret) |
|---|
| .. | .. |
|---|
| 881 | 836 | } else { |
|---|
| 882 | 837 | int shift = ctx->key_sz - req->src_len; |
|---|
| 883 | 838 | |
|---|
| 884 | | - qat_req->src_align = dma_zalloc_coherent(dev, ctx->key_sz, |
|---|
| 885 | | - &qat_req->in.rsa.dec.c, |
|---|
| 886 | | - GFP_KERNEL); |
|---|
| 839 | + qat_req->src_align = dma_alloc_coherent(dev, ctx->key_sz, |
|---|
| 840 | + &qat_req->in.rsa.dec.c, |
|---|
| 841 | + GFP_KERNEL); |
|---|
| 887 | 842 | if (unlikely(!qat_req->src_align)) |
|---|
| 888 | 843 | return ret; |
|---|
| 889 | 844 | |
|---|
| .. | .. |
|---|
| 900 | 855 | goto unmap_src; |
|---|
| 901 | 856 | |
|---|
| 902 | 857 | } else { |
|---|
| 903 | | - qat_req->dst_align = dma_zalloc_coherent(dev, ctx->key_sz, |
|---|
| 904 | | - &qat_req->out.rsa.dec.m, |
|---|
| 905 | | - GFP_KERNEL); |
|---|
| 858 | + qat_req->dst_align = dma_alloc_coherent(dev, ctx->key_sz, |
|---|
| 859 | + &qat_req->out.rsa.dec.m, |
|---|
| 860 | + GFP_KERNEL); |
|---|
| 906 | 861 | if (unlikely(!qat_req->dst_align)) |
|---|
| 907 | 862 | goto unmap_src; |
|---|
| 908 | 863 | |
|---|
| .. | .. |
|---|
| 927 | 882 | |
|---|
| 928 | 883 | msg->pke_mid.src_data_addr = qat_req->phy_in; |
|---|
| 929 | 884 | msg->pke_mid.dest_data_addr = qat_req->phy_out; |
|---|
| 930 | | - msg->pke_mid.opaque = (uint64_t)(__force long)qat_req; |
|---|
| 885 | + msg->pke_mid.opaque = (u64)(__force long)qat_req; |
|---|
| 931 | 886 | if (ctx->crt_mode) |
|---|
| 932 | 887 | msg->input_param_count = 6; |
|---|
| 933 | 888 | else |
|---|
| .. | .. |
|---|
| 935 | 890 | |
|---|
| 936 | 891 | msg->output_param_count = 1; |
|---|
| 937 | 892 | do { |
|---|
| 938 | | - ret = adf_send_message(ctx->inst->pke_tx, (uint32_t *)msg); |
|---|
| 893 | + ret = adf_send_message(ctx->inst->pke_tx, (u32 *)msg); |
|---|
| 939 | 894 | } while (ret == -EBUSY && ctr++ < 100); |
|---|
| 940 | 895 | |
|---|
| 941 | 896 | if (!ret) |
|---|
| .. | .. |
|---|
| 989 | 944 | goto err; |
|---|
| 990 | 945 | |
|---|
| 991 | 946 | ret = -ENOMEM; |
|---|
| 992 | | - ctx->n = dma_zalloc_coherent(dev, ctx->key_sz, &ctx->dma_n, GFP_KERNEL); |
|---|
| 947 | + ctx->n = dma_alloc_coherent(dev, ctx->key_sz, &ctx->dma_n, GFP_KERNEL); |
|---|
| 993 | 948 | if (!ctx->n) |
|---|
| 994 | 949 | goto err; |
|---|
| 995 | 950 | |
|---|
| .. | .. |
|---|
| 1018 | 973 | return -EINVAL; |
|---|
| 1019 | 974 | } |
|---|
| 1020 | 975 | |
|---|
| 1021 | | - ctx->e = dma_zalloc_coherent(dev, ctx->key_sz, &ctx->dma_e, GFP_KERNEL); |
|---|
| 976 | + ctx->e = dma_alloc_coherent(dev, ctx->key_sz, &ctx->dma_e, GFP_KERNEL); |
|---|
| 1022 | 977 | if (!ctx->e) |
|---|
| 1023 | 978 | return -ENOMEM; |
|---|
| 1024 | 979 | |
|---|
| .. | .. |
|---|
| 1044 | 999 | goto err; |
|---|
| 1045 | 1000 | |
|---|
| 1046 | 1001 | ret = -ENOMEM; |
|---|
| 1047 | | - ctx->d = dma_zalloc_coherent(dev, ctx->key_sz, &ctx->dma_d, GFP_KERNEL); |
|---|
| 1002 | + ctx->d = dma_alloc_coherent(dev, ctx->key_sz, &ctx->dma_d, GFP_KERNEL); |
|---|
| 1048 | 1003 | if (!ctx->d) |
|---|
| 1049 | 1004 | goto err; |
|---|
| 1050 | 1005 | |
|---|
| .. | .. |
|---|
| 1077 | 1032 | qat_rsa_drop_leading_zeros(&ptr, &len); |
|---|
| 1078 | 1033 | if (!len) |
|---|
| 1079 | 1034 | goto err; |
|---|
| 1080 | | - ctx->p = dma_zalloc_coherent(dev, half_key_sz, &ctx->dma_p, GFP_KERNEL); |
|---|
| 1035 | + ctx->p = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_p, GFP_KERNEL); |
|---|
| 1081 | 1036 | if (!ctx->p) |
|---|
| 1082 | 1037 | goto err; |
|---|
| 1083 | 1038 | memcpy(ctx->p + (half_key_sz - len), ptr, len); |
|---|
| .. | .. |
|---|
| 1088 | 1043 | qat_rsa_drop_leading_zeros(&ptr, &len); |
|---|
| 1089 | 1044 | if (!len) |
|---|
| 1090 | 1045 | goto free_p; |
|---|
| 1091 | | - ctx->q = dma_zalloc_coherent(dev, half_key_sz, &ctx->dma_q, GFP_KERNEL); |
|---|
| 1046 | + ctx->q = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_q, GFP_KERNEL); |
|---|
| 1092 | 1047 | if (!ctx->q) |
|---|
| 1093 | 1048 | goto free_p; |
|---|
| 1094 | 1049 | memcpy(ctx->q + (half_key_sz - len), ptr, len); |
|---|
| .. | .. |
|---|
| 1099 | 1054 | qat_rsa_drop_leading_zeros(&ptr, &len); |
|---|
| 1100 | 1055 | if (!len) |
|---|
| 1101 | 1056 | goto free_q; |
|---|
| 1102 | | - ctx->dp = dma_zalloc_coherent(dev, half_key_sz, &ctx->dma_dp, |
|---|
| 1103 | | - GFP_KERNEL); |
|---|
| 1057 | + ctx->dp = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_dp, |
|---|
| 1058 | + GFP_KERNEL); |
|---|
| 1104 | 1059 | if (!ctx->dp) |
|---|
| 1105 | 1060 | goto free_q; |
|---|
| 1106 | 1061 | memcpy(ctx->dp + (half_key_sz - len), ptr, len); |
|---|
| .. | .. |
|---|
| 1111 | 1066 | qat_rsa_drop_leading_zeros(&ptr, &len); |
|---|
| 1112 | 1067 | if (!len) |
|---|
| 1113 | 1068 | goto free_dp; |
|---|
| 1114 | | - ctx->dq = dma_zalloc_coherent(dev, half_key_sz, &ctx->dma_dq, |
|---|
| 1115 | | - GFP_KERNEL); |
|---|
| 1069 | + ctx->dq = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_dq, |
|---|
| 1070 | + GFP_KERNEL); |
|---|
| 1116 | 1071 | if (!ctx->dq) |
|---|
| 1117 | 1072 | goto free_dp; |
|---|
| 1118 | 1073 | memcpy(ctx->dq + (half_key_sz - len), ptr, len); |
|---|
| .. | .. |
|---|
| 1123 | 1078 | qat_rsa_drop_leading_zeros(&ptr, &len); |
|---|
| 1124 | 1079 | if (!len) |
|---|
| 1125 | 1080 | goto free_dq; |
|---|
| 1126 | | - ctx->qinv = dma_zalloc_coherent(dev, half_key_sz, &ctx->dma_qinv, |
|---|
| 1127 | | - GFP_KERNEL); |
|---|
| 1081 | + ctx->qinv = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_qinv, |
|---|
| 1082 | + GFP_KERNEL); |
|---|
| 1128 | 1083 | if (!ctx->qinv) |
|---|
| 1129 | 1084 | goto free_dq; |
|---|
| 1130 | 1085 | memcpy(ctx->qinv + (half_key_sz - len), ptr, len); |
|---|
| .. | .. |
|---|
| 1300 | 1255 | static struct akcipher_alg rsa = { |
|---|
| 1301 | 1256 | .encrypt = qat_rsa_enc, |
|---|
| 1302 | 1257 | .decrypt = qat_rsa_dec, |
|---|
| 1303 | | - .sign = qat_rsa_dec, |
|---|
| 1304 | | - .verify = qat_rsa_enc, |
|---|
| 1305 | 1258 | .set_pub_key = qat_rsa_setpubkey, |
|---|
| 1306 | 1259 | .set_priv_key = qat_rsa_setprivkey, |
|---|
| 1307 | 1260 | .max_size = qat_rsa_max_size, |
|---|