.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Cryptographic API. |
---|
3 | 4 | * Support for Nomadik hardware crypto engine. |
---|
.. | .. |
---|
8 | 9 | * Author: Berne Hebark <berne.herbark@stericsson.com> for ST-Ericsson. |
---|
9 | 10 | * Author: Niklas Hernaeus <niklas.hernaeus@stericsson.com> for ST-Ericsson. |
---|
10 | 11 | * Author: Andreas Westin <andreas.westin@stericsson.com> for ST-Ericsson. |
---|
11 | | - * License terms: GNU General Public License (GPL) version 2 |
---|
12 | 12 | */ |
---|
13 | 13 | |
---|
14 | 14 | #define pr_fmt(fmt) "hashX hashX: " fmt |
---|
15 | 15 | |
---|
16 | 16 | #include <linux/clk.h> |
---|
17 | 17 | #include <linux/device.h> |
---|
| 18 | +#include <linux/dma-mapping.h> |
---|
18 | 19 | #include <linux/err.h> |
---|
19 | 20 | #include <linux/init.h> |
---|
20 | 21 | #include <linux/io.h> |
---|
.. | .. |
---|
140 | 141 | { |
---|
141 | 142 | struct dma_async_tx_descriptor *desc = NULL; |
---|
142 | 143 | struct dma_chan *channel = NULL; |
---|
143 | | - dma_cookie_t cookie; |
---|
144 | 144 | |
---|
145 | 145 | if (direction != DMA_TO_DEVICE) { |
---|
146 | 146 | dev_err(ctx->device->dev, "%s: Invalid DMA direction\n", |
---|
.. | .. |
---|
176 | 176 | desc->callback = hash_dma_callback; |
---|
177 | 177 | desc->callback_param = ctx; |
---|
178 | 178 | |
---|
179 | | - cookie = dmaengine_submit(desc); |
---|
| 179 | + dmaengine_submit(desc); |
---|
180 | 180 | dma_async_issue_pending(channel); |
---|
181 | 181 | |
---|
182 | 182 | return 0; |
---|
.. | .. |
---|
546 | 546 | * |
---|
547 | 547 | * Initialize structures. |
---|
548 | 548 | */ |
---|
549 | | -static int hash_init(struct ahash_request *req) |
---|
| 549 | +static int ux500_hash_init(struct ahash_request *req) |
---|
550 | 550 | { |
---|
551 | 551 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); |
---|
552 | 552 | struct hash_ctx *ctx = crypto_ahash_ctx(tfm); |
---|
.. | .. |
---|
806 | 806 | * HW peripheral, otherwise we first copy data |
---|
807 | 807 | * to a local buffer |
---|
808 | 808 | */ |
---|
809 | | - if ((0 == (((u32)data_buffer) % 4)) && |
---|
| 809 | + if (IS_ALIGNED((unsigned long)data_buffer, 4) && |
---|
810 | 810 | (0 == *index)) |
---|
811 | 811 | hash_processblock(device_data, |
---|
812 | 812 | (const u32 *)data_buffer, |
---|
.. | .. |
---|
864 | 864 | if (ret) |
---|
865 | 865 | return ret; |
---|
866 | 866 | |
---|
867 | | - dev_dbg(device_data->dev, "%s: (ctx=0x%x)!\n", __func__, (u32) ctx); |
---|
| 867 | + dev_dbg(device_data->dev, "%s: (ctx=0x%lx)!\n", __func__, |
---|
| 868 | + (unsigned long)ctx); |
---|
868 | 869 | |
---|
869 | 870 | if (req_ctx->updated) { |
---|
870 | 871 | ret = hash_resume_state(device_data, &device_data->state); |
---|
.. | .. |
---|
969 | 970 | if (ret) |
---|
970 | 971 | return ret; |
---|
971 | 972 | |
---|
972 | | - dev_dbg(device_data->dev, "%s: (ctx=0x%x)!\n", __func__, (u32) ctx); |
---|
| 973 | + dev_dbg(device_data->dev, "%s: (ctx=0x%lx)!\n", __func__, |
---|
| 974 | + (unsigned long)ctx); |
---|
973 | 975 | |
---|
974 | 976 | if (req_ctx->updated) { |
---|
975 | 977 | ret = hash_resume_state(device_data, &device_data->state); |
---|
.. | .. |
---|
1071 | 1073 | struct hash_ctx *ctx = crypto_ahash_ctx(tfm); |
---|
1072 | 1074 | struct hash_req_ctx *req_ctx = ahash_request_ctx(req); |
---|
1073 | 1075 | struct crypto_hash_walk walk; |
---|
1074 | | - int msg_length = crypto_hash_walk_first(req, &walk); |
---|
1075 | | - |
---|
1076 | | - /* Empty message ("") is correct indata */ |
---|
1077 | | - if (msg_length == 0) |
---|
1078 | | - return ret; |
---|
| 1076 | + int msg_length; |
---|
1079 | 1077 | |
---|
1080 | 1078 | index = req_ctx->state.index; |
---|
1081 | 1079 | buffer = (u8 *)req_ctx->state.buffer; |
---|
| 1080 | + |
---|
| 1081 | + ret = hash_get_device_data(ctx, &device_data); |
---|
| 1082 | + if (ret) |
---|
| 1083 | + return ret; |
---|
| 1084 | + |
---|
| 1085 | + msg_length = crypto_hash_walk_first(req, &walk); |
---|
| 1086 | + |
---|
| 1087 | + /* Empty message ("") is correct indata */ |
---|
| 1088 | + if (msg_length == 0) { |
---|
| 1089 | + ret = 0; |
---|
| 1090 | + goto release_dev; |
---|
| 1091 | + } |
---|
1082 | 1092 | |
---|
1083 | 1093 | /* Check if ctx->state.length + msg_length |
---|
1084 | 1094 | overflows */ |
---|
1085 | 1095 | if (msg_length > (req_ctx->state.length.low_word + msg_length) && |
---|
1086 | 1096 | HASH_HIGH_WORD_MAX_VAL == req_ctx->state.length.high_word) { |
---|
1087 | 1097 | pr_err("%s: HASH_MSG_LENGTH_OVERFLOW!\n", __func__); |
---|
1088 | | - return -EPERM; |
---|
| 1098 | + ret = crypto_hash_walk_done(&walk, -EPERM); |
---|
| 1099 | + goto release_dev; |
---|
1089 | 1100 | } |
---|
1090 | | - |
---|
1091 | | - ret = hash_get_device_data(ctx, &device_data); |
---|
1092 | | - if (ret) |
---|
1093 | | - return ret; |
---|
1094 | 1101 | |
---|
1095 | 1102 | /* Main loop */ |
---|
1096 | 1103 | while (0 != msg_length) { |
---|
.. | .. |
---|
1101 | 1108 | if (ret) { |
---|
1102 | 1109 | dev_err(device_data->dev, "%s: hash_internal_hw_update() failed!\n", |
---|
1103 | 1110 | __func__); |
---|
1104 | | - goto out; |
---|
| 1111 | + crypto_hash_walk_done(&walk, ret); |
---|
| 1112 | + goto release_dev; |
---|
1105 | 1113 | } |
---|
1106 | 1114 | |
---|
1107 | 1115 | msg_length = crypto_hash_walk_done(&walk, 0); |
---|
.. | .. |
---|
1111 | 1119 | dev_dbg(device_data->dev, "%s: indata length=%d, bin=%d\n", |
---|
1112 | 1120 | __func__, req_ctx->state.index, req_ctx->state.bit_index); |
---|
1113 | 1121 | |
---|
1114 | | -out: |
---|
| 1122 | +release_dev: |
---|
1115 | 1123 | release_hash_device(device_data); |
---|
1116 | 1124 | |
---|
1117 | 1125 | return ret; |
---|
.. | .. |
---|
1273 | 1281 | else |
---|
1274 | 1282 | loop_ctr = SHA256_DIGEST_SIZE / sizeof(u32); |
---|
1275 | 1283 | |
---|
1276 | | - dev_dbg(device_data->dev, "%s: digest array:(0x%x)\n", |
---|
1277 | | - __func__, (u32) digest); |
---|
| 1284 | + dev_dbg(device_data->dev, "%s: digest array:(0x%lx)\n", |
---|
| 1285 | + __func__, (unsigned long)digest); |
---|
1278 | 1286 | |
---|
1279 | 1287 | /* Copy result into digest array */ |
---|
1280 | 1288 | for (count = 0; count < loop_ctr; count++) { |
---|
.. | .. |
---|
1359 | 1367 | ctx->config.oper_mode = HASH_OPER_MODE_HASH; |
---|
1360 | 1368 | ctx->digestsize = SHA1_DIGEST_SIZE; |
---|
1361 | 1369 | |
---|
1362 | | - return hash_init(req); |
---|
| 1370 | + return ux500_hash_init(req); |
---|
1363 | 1371 | } |
---|
1364 | 1372 | |
---|
1365 | 1373 | static int ahash_sha256_init(struct ahash_request *req) |
---|
.. | .. |
---|
1372 | 1380 | ctx->config.oper_mode = HASH_OPER_MODE_HASH; |
---|
1373 | 1381 | ctx->digestsize = SHA256_DIGEST_SIZE; |
---|
1374 | 1382 | |
---|
1375 | | - return hash_init(req); |
---|
| 1383 | + return ux500_hash_init(req); |
---|
1376 | 1384 | } |
---|
1377 | 1385 | |
---|
1378 | 1386 | static int ahash_sha1_digest(struct ahash_request *req) |
---|
.. | .. |
---|
1425 | 1433 | ctx->config.oper_mode = HASH_OPER_MODE_HMAC; |
---|
1426 | 1434 | ctx->digestsize = SHA1_DIGEST_SIZE; |
---|
1427 | 1435 | |
---|
1428 | | - return hash_init(req); |
---|
| 1436 | + return ux500_hash_init(req); |
---|
1429 | 1437 | } |
---|
1430 | 1438 | |
---|
1431 | 1439 | static int hmac_sha256_init(struct ahash_request *req) |
---|
.. | .. |
---|
1438 | 1446 | ctx->config.oper_mode = HASH_OPER_MODE_HMAC; |
---|
1439 | 1447 | ctx->digestsize = SHA256_DIGEST_SIZE; |
---|
1440 | 1448 | |
---|
1441 | | - return hash_init(req); |
---|
| 1449 | + return ux500_hash_init(req); |
---|
1442 | 1450 | } |
---|
1443 | 1451 | |
---|
1444 | 1452 | static int hmac_sha1_digest(struct ahash_request *req) |
---|
.. | .. |
---|
1515 | 1523 | .conf.algorithm = HASH_ALGO_SHA1, |
---|
1516 | 1524 | .conf.oper_mode = HASH_OPER_MODE_HASH, |
---|
1517 | 1525 | .hash = { |
---|
1518 | | - .init = hash_init, |
---|
| 1526 | + .init = ux500_hash_init, |
---|
1519 | 1527 | .update = ahash_update, |
---|
1520 | 1528 | .final = ahash_final, |
---|
1521 | 1529 | .digest = ahash_sha1_digest, |
---|
.. | .. |
---|
1538 | 1546 | .conf.algorithm = HASH_ALGO_SHA256, |
---|
1539 | 1547 | .conf.oper_mode = HASH_OPER_MODE_HASH, |
---|
1540 | 1548 | .hash = { |
---|
1541 | | - .init = hash_init, |
---|
| 1549 | + .init = ux500_hash_init, |
---|
1542 | 1550 | .update = ahash_update, |
---|
1543 | 1551 | .final = ahash_final, |
---|
1544 | 1552 | .digest = ahash_sha256_digest, |
---|
.. | .. |
---|
1561 | 1569 | .conf.algorithm = HASH_ALGO_SHA1, |
---|
1562 | 1570 | .conf.oper_mode = HASH_OPER_MODE_HMAC, |
---|
1563 | 1571 | .hash = { |
---|
1564 | | - .init = hash_init, |
---|
| 1572 | + .init = ux500_hash_init, |
---|
1565 | 1573 | .update = ahash_update, |
---|
1566 | 1574 | .final = ahash_final, |
---|
1567 | 1575 | .digest = hmac_sha1_digest, |
---|
.. | .. |
---|
1585 | 1593 | .conf.algorithm = HASH_ALGO_SHA256, |
---|
1586 | 1594 | .conf.oper_mode = HASH_OPER_MODE_HMAC, |
---|
1587 | 1595 | .hash = { |
---|
1588 | | - .init = hash_init, |
---|
| 1596 | + .init = ux500_hash_init, |
---|
1589 | 1597 | .update = ahash_update, |
---|
1590 | 1598 | .final = ahash_final, |
---|
1591 | 1599 | .digest = hmac_sha256_digest, |
---|