/drivers/crypto/virtio/virtio_crypto_common.h

https://bitbucket.org/updatelee/v4l-updatelee · C Header · 128 lines · 73 code · 25 blank · 30 comment · 0 complexity · 6ae89aa423bb9e4de0c5b1dcc615f7c4 MD5 · raw file

  1. /* Common header for Virtio crypto device.
  2. *
  3. * Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
  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 as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _VIRTIO_CRYPTO_COMMON_H
  19. #define _VIRTIO_CRYPTO_COMMON_H
  20. #include <linux/virtio.h>
  21. #include <linux/crypto.h>
  22. #include <linux/spinlock.h>
  23. #include <crypto/aead.h>
  24. #include <crypto/aes.h>
  25. #include <crypto/engine.h>
  26. /* Internal representation of a data virtqueue */
  27. struct data_queue {
  28. /* Virtqueue associated with this send _queue */
  29. struct virtqueue *vq;
  30. /* To protect the vq operations for the dataq */
  31. spinlock_t lock;
  32. /* Name of the tx queue: dataq.$index */
  33. char name[32];
  34. struct crypto_engine *engine;
  35. };
  36. struct virtio_crypto {
  37. struct virtio_device *vdev;
  38. struct virtqueue *ctrl_vq;
  39. struct data_queue *data_vq;
  40. /* To protect the vq operations for the controlq */
  41. spinlock_t ctrl_lock;
  42. /* Maximum of data queues supported by the device */
  43. u32 max_data_queues;
  44. /* Number of queue currently used by the driver */
  45. u32 curr_queue;
  46. /* Maximum length of cipher key */
  47. u32 max_cipher_key_len;
  48. /* Maximum length of authenticated key */
  49. u32 max_auth_key_len;
  50. /* Maximum size of per request */
  51. u64 max_size;
  52. /* Control VQ buffers: protected by the ctrl_lock */
  53. struct virtio_crypto_op_ctrl_req ctrl;
  54. struct virtio_crypto_session_input input;
  55. struct virtio_crypto_inhdr ctrl_status;
  56. unsigned long status;
  57. atomic_t ref_count;
  58. struct list_head list;
  59. struct module *owner;
  60. uint8_t dev_id;
  61. /* Does the affinity hint is set for virtqueues? */
  62. bool affinity_hint_set;
  63. };
  64. struct virtio_crypto_sym_session_info {
  65. /* Backend session id, which come from the host side */
  66. __u64 session_id;
  67. };
  68. struct virtio_crypto_request;
  69. typedef void (*virtio_crypto_data_callback)
  70. (struct virtio_crypto_request *vc_req, int len);
  71. struct virtio_crypto_request {
  72. uint8_t status;
  73. struct virtio_crypto_op_data_req *req_data;
  74. struct scatterlist **sgs;
  75. struct data_queue *dataq;
  76. virtio_crypto_data_callback alg_cb;
  77. };
  78. int virtcrypto_devmgr_add_dev(struct virtio_crypto *vcrypto_dev);
  79. struct list_head *virtcrypto_devmgr_get_head(void);
  80. void virtcrypto_devmgr_rm_dev(struct virtio_crypto *vcrypto_dev);
  81. struct virtio_crypto *virtcrypto_devmgr_get_first(void);
  82. int virtcrypto_dev_in_use(struct virtio_crypto *vcrypto_dev);
  83. int virtcrypto_dev_get(struct virtio_crypto *vcrypto_dev);
  84. void virtcrypto_dev_put(struct virtio_crypto *vcrypto_dev);
  85. int virtcrypto_dev_started(struct virtio_crypto *vcrypto_dev);
  86. struct virtio_crypto *virtcrypto_get_dev_node(int node);
  87. int virtcrypto_dev_start(struct virtio_crypto *vcrypto);
  88. void virtcrypto_dev_stop(struct virtio_crypto *vcrypto);
  89. int virtio_crypto_ablkcipher_crypt_req(
  90. struct crypto_engine *engine, void *vreq);
  91. void
  92. virtcrypto_clear_request(struct virtio_crypto_request *vc_req);
  93. static inline int virtio_crypto_get_current_node(void)
  94. {
  95. int cpu, node;
  96. cpu = get_cpu();
  97. node = topology_physical_package_id(cpu);
  98. put_cpu();
  99. return node;
  100. }
  101. int virtio_crypto_algs_register(void);
  102. void virtio_crypto_algs_unregister(void);
  103. #endif /* _VIRTIO_CRYPTO_COMMON_H */