virtio_crypto_common.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Common header for Virtio crypto device.
  3. *
  4. * Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
  5. */
  6. #ifndef _VIRTIO_CRYPTO_COMMON_H
  7. #define _VIRTIO_CRYPTO_COMMON_H
  8. #include <linux/virtio.h>
  9. #include <linux/crypto.h>
  10. #include <linux/spinlock.h>
  11. #include <crypto/aead.h>
  12. #include <crypto/aes.h>
  13. #include <crypto/engine.h>
  14. /* Internal representation of a data virtqueue */
  15. struct data_queue {
  16. /* Virtqueue associated with this send _queue */
  17. struct virtqueue *vq;
  18. /* To protect the vq operations for the dataq */
  19. spinlock_t lock;
  20. /* Name of the tx queue: dataq.$index */
  21. char name[32];
  22. struct crypto_engine *engine;
  23. };
  24. struct virtio_crypto {
  25. struct virtio_device *vdev;
  26. struct virtqueue *ctrl_vq;
  27. struct data_queue *data_vq;
  28. /* To protect the vq operations for the controlq */
  29. spinlock_t ctrl_lock;
  30. /* Maximum of data queues supported by the device */
  31. u32 max_data_queues;
  32. /* Number of queue currently used by the driver */
  33. u32 curr_queue;
  34. /*
  35. * Specifies the services mask which the device support,
  36. * see VIRTIO_CRYPTO_SERVICE_*
  37. */
  38. u32 crypto_services;
  39. /* Detailed algorithms mask */
  40. u32 cipher_algo_l;
  41. u32 cipher_algo_h;
  42. u32 hash_algo;
  43. u32 mac_algo_l;
  44. u32 mac_algo_h;
  45. u32 aead_algo;
  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. bool virtcrypto_algo_is_supported(struct virtio_crypto *vcrypto_dev,
  87. uint32_t service,
  88. uint32_t algo);
  89. struct virtio_crypto *virtcrypto_get_dev_node(int node,
  90. uint32_t service,
  91. uint32_t algo);
  92. int virtcrypto_dev_start(struct virtio_crypto *vcrypto);
  93. void virtcrypto_dev_stop(struct virtio_crypto *vcrypto);
  94. int virtio_crypto_ablkcipher_crypt_req(
  95. struct crypto_engine *engine, void *vreq);
  96. void
  97. virtcrypto_clear_request(struct virtio_crypto_request *vc_req);
  98. static inline int virtio_crypto_get_current_node(void)
  99. {
  100. int cpu, node;
  101. cpu = get_cpu();
  102. node = topology_physical_package_id(cpu);
  103. put_cpu();
  104. return node;
  105. }
  106. int virtio_crypto_algs_register(struct virtio_crypto *vcrypto);
  107. void virtio_crypto_algs_unregister(struct virtio_crypto *vcrypto);
  108. #endif /* _VIRTIO_CRYPTO_COMMON_H */