qcedevi.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * QTI crypto Driver
  4. *
  5. * Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
  6. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  7. */
  8. #ifndef __CRYPTO_MSM_QCEDEVI_H
  9. #define __CRYPTO_MSM_QCEDEVI_H
  10. #include <linux/interrupt.h>
  11. #include <linux/cdev.h>
  12. #include <crypto/hash.h>
  13. #include "qcom_crypto_device.h"
  14. #include "fips_status.h"
  15. #include "qce.h"
  16. #include "qcedev_smmu.h"
  17. #define CACHE_LINE_SIZE 64
  18. #define CE_SHA_BLOCK_SIZE SHA256_BLOCK_SIZE
  19. enum qcedev_crypto_oper_type {
  20. QCEDEV_CRYPTO_OPER_CIPHER = 0,
  21. QCEDEV_CRYPTO_OPER_SHA = 1,
  22. QCEDEV_CRYPTO_OPER_OFFLOAD_CIPHER = 2,
  23. QCEDEV_CRYPTO_OPER_LAST
  24. };
  25. struct qcedev_handle;
  26. struct qcedev_cipher_req {
  27. struct skcipher_request creq;
  28. void *cookie;
  29. };
  30. struct qcedev_sha_req {
  31. struct ahash_request sreq;
  32. void *cookie;
  33. };
  34. struct qcedev_sha_ctxt {
  35. uint32_t auth_data[4];
  36. uint8_t digest[QCEDEV_MAX_SHA_DIGEST];
  37. uint32_t diglen;
  38. uint8_t trailing_buf[64];
  39. uint32_t trailing_buf_len;
  40. uint8_t first_blk;
  41. uint8_t last_blk;
  42. uint8_t authkey[QCEDEV_MAX_SHA_BLOCK_SIZE];
  43. bool init_done;
  44. };
  45. struct qcedev_async_req {
  46. struct list_head list;
  47. struct completion complete;
  48. enum qcedev_crypto_oper_type op_type;
  49. union {
  50. struct qcedev_cipher_op_req cipher_op_req;
  51. struct qcedev_sha_op_req sha_op_req;
  52. struct qcedev_offload_cipher_op_req offload_cipher_op_req;
  53. };
  54. union {
  55. struct qcedev_cipher_req cipher_req;
  56. struct qcedev_sha_req sha_req;
  57. };
  58. struct qcedev_handle *handle;
  59. int err;
  60. wait_queue_head_t wait_q;
  61. uint16_t state;
  62. bool timed_out;
  63. };
  64. /**********************************************************************
  65. * Register ourselves as a char device to be able to access the dev driver
  66. * from userspace.
  67. */
  68. #define QCEDEV_DEV "qce"
  69. struct qcedev_control {
  70. /* CE features supported by platform */
  71. struct msm_ce_hw_support platform_support;
  72. uint32_t ce_lock_count;
  73. uint32_t high_bw_req_count;
  74. /* CE features/algorithms supported by HW engine*/
  75. struct ce_hw_support ce_support;
  76. /* replaced msm_bus with interconnect path */
  77. struct icc_path *icc_path;
  78. /* average and peak bw values for interconnect */
  79. uint32_t icc_avg_bw;
  80. uint32_t icc_peak_bw;
  81. /* char device */
  82. struct cdev cdev;
  83. int minor;
  84. /* qce handle */
  85. void *qce;
  86. /* platform device */
  87. struct platform_device *pdev;
  88. unsigned int magic;
  89. struct list_head ready_commands;
  90. struct qcedev_async_req *active_command;
  91. spinlock_t lock;
  92. struct tasklet_struct done_tasklet;
  93. struct list_head context_banks;
  94. struct qcedev_mem_client *mem_client;
  95. };
  96. struct qcedev_handle {
  97. /* qcedev control handle */
  98. struct qcedev_control *cntl;
  99. /* qce internal sha context*/
  100. struct qcedev_sha_ctxt sha_ctxt;
  101. /* qcedev mapped buffer list */
  102. struct qcedev_buffer_list registeredbufs;
  103. };
  104. void qcedev_cipher_req_cb(void *cookie, unsigned char *icv,
  105. unsigned char *iv, int ret);
  106. void qcedev_sha_req_cb(void *cookie, unsigned char *digest,
  107. unsigned char *authdata, int ret);
  108. #endif /* __CRYPTO_MSM_QCEDEVI_H */