qcedevi.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* QTI crypto Driver
  2. *
  3. * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 and
  7. * only version 2 as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __CRYPTO_MSM_QCEDEVI_H
  15. #define __CRYPTO_MSM_QCEDEVI_H
  16. #include <linux/interrupt.h>
  17. #include <linux/miscdevice.h>
  18. #include <crypto/hash.h>
  19. #include <linux/platform_data/qcom_crypto_device.h>
  20. #include <linux/fips_status.h>
  21. #include "qce.h"
  22. #define CACHE_LINE_SIZE 32
  23. #define CE_SHA_BLOCK_SIZE SHA256_BLOCK_SIZE
  24. /* FIPS global status variable */
  25. extern enum fips_status g_fips140_status;
  26. /*FIPS140-2 call back for DRBG self test */
  27. extern void *drbg_call_back;
  28. enum qcedev_crypto_oper_type {
  29. QCEDEV_CRYPTO_OPER_CIPHER = 0,
  30. QCEDEV_CRYPTO_OPER_SHA = 1,
  31. QCEDEV_CRYPTO_OPER_LAST
  32. };
  33. struct qcedev_handle;
  34. struct qcedev_cipher_req {
  35. struct ablkcipher_request creq;
  36. void *cookie;
  37. };
  38. struct qcedev_sha_req {
  39. struct ahash_request sreq;
  40. void *cookie;
  41. };
  42. struct qcedev_sha_ctxt {
  43. uint32_t auth_data[4];
  44. uint8_t digest[QCEDEV_MAX_SHA_DIGEST];
  45. uint32_t diglen;
  46. uint8_t trailing_buf[64];
  47. uint32_t trailing_buf_len;
  48. uint8_t first_blk;
  49. uint8_t last_blk;
  50. uint8_t authkey[QCEDEV_MAX_SHA_BLOCK_SIZE];
  51. bool init_done;
  52. };
  53. struct qcedev_async_req {
  54. struct list_head list;
  55. struct completion complete;
  56. enum qcedev_crypto_oper_type op_type;
  57. union {
  58. struct qcedev_cipher_op_req cipher_op_req;
  59. struct qcedev_sha_op_req sha_op_req;
  60. };
  61. union {
  62. struct qcedev_cipher_req cipher_req;
  63. struct qcedev_sha_req sha_req;
  64. };
  65. struct qcedev_handle *handle;
  66. int err;
  67. };
  68. /**********************************************************************
  69. * Register ourselves as a misc device to be able to access the dev driver
  70. * from userspace. */
  71. #define QCEDEV_DEV "qcedev"
  72. struct qcedev_control {
  73. /* CE features supported by platform */
  74. struct msm_ce_hw_support platform_support;
  75. uint32_t ce_lock_count;
  76. uint32_t high_bw_req_count;
  77. /* CE features/algorithms supported by HW engine*/
  78. struct ce_hw_support ce_support;
  79. uint32_t bus_scale_handle;
  80. /* misc device */
  81. struct miscdevice miscdevice;
  82. /* qce handle */
  83. void *qce;
  84. /* platform device */
  85. struct platform_device *pdev;
  86. unsigned magic;
  87. struct list_head ready_commands;
  88. struct qcedev_async_req *active_command;
  89. spinlock_t lock;
  90. struct tasklet_struct done_tasklet;
  91. };
  92. struct qcedev_handle {
  93. /* qcedev control handle */
  94. struct qcedev_control *cntl;
  95. /* qce internal sha context*/
  96. struct qcedev_sha_ctxt sha_ctxt;
  97. };
  98. void qcedev_cipher_req_cb(void *cookie, unsigned char *icv,
  99. unsigned char *iv, int ret);
  100. void qcedev_sha_req_cb(void *cookie, unsigned char *digest,
  101. unsigned char *authdata, int ret);
  102. extern int _do_msm_fips_drbg_init(void *rng_dev);
  103. #ifdef CONFIG_FIPS_ENABLE
  104. /*
  105. * Self test for Cipher algorithms
  106. */
  107. int _fips_qcedev_cipher_selftest(struct qcedev_control *podev);
  108. /*
  109. * Self test for SHA / HMAC
  110. */
  111. int _fips_qcedev_sha_selftest(struct qcedev_control *podev);
  112. /*
  113. * Update FIPs Global status Status
  114. */
  115. static inline enum fips_status _fips_update_status(enum fips_status status)
  116. {
  117. return (status == FIPS140_STATUS_PASS) ?
  118. FIPS140_STATUS_QCRYPTO_ALLOWED :
  119. FIPS140_STATUS_FAIL;
  120. }
  121. #else
  122. static inline int _fips_qcedev_cipher_selftest(struct qcedev_control *podev)
  123. {
  124. return 0;
  125. }
  126. static inline int _fips_qcedev_sha_selftest(struct qcedev_control *podev)
  127. {
  128. return 0;
  129. }
  130. static inline enum fips_status _fips_update_status(enum fips_status status)
  131. {
  132. return FIPS140_STATUS_NA;
  133. }
  134. #endif /* CONFIG_FIPS_ENABLE */
  135. #endif /* __CRYPTO_MSM_QCEDEVI_H */