This patch introduces the header of virtio crypto emulation. Signed-off-by: Gonglei <arei.gong...@huawei.com> --- include/hw/virtio/virtio-crypto.h | 84 ++++++++++++++++++++++++++ include/standard-headers/linux/virtio_crypto.h | 34 +++++------ 2 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 include/hw/virtio/virtio-crypto.h
diff --git a/include/hw/virtio/virtio-crypto.h b/include/hw/virtio/virtio-crypto.h new file mode 100644 index 0000000..fa97e97 --- /dev/null +++ b/include/hw/virtio/virtio-crypto.h @@ -0,0 +1,84 @@ +/* + * Virtio crypto Support + * + * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. + * + * Authors: + * Gonglei <arei.gong...@huawei.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#ifndef _QEMU_VIRTIO_CRYPTO_H +#define _QEMU_VIRTIO_CRYPTO_H + +#include "standard-headers/linux/virtio_crypto.h" +#include "hw/virtio/virtio.h" +#include "sysemu/iothread.h" +#include "crypto/crypto.h" + +#define VIRTIO_ID_CRYPTO 20 + +/* #define DEBUG_VIRTIO_CRYPTO */ + +#ifdef DEBUG_VIRTIO_CRYPTO +#define DPRINTF(fmt, ...) \ +do { printf("virtio_crypto: " fmt , ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) do { } while (0) +#endif + +#define TYPE_VIRTIO_CRYPTO "virtio-crypto-device" +#define VIRTIO_CRYPTO(obj) \ + OBJECT_CHECK(VirtIOCrypto, (obj), TYPE_VIRTIO_CRYPTO) +#define VIRTIO_CRYPTO_GET_PARENT_CLASS(obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_CRYPTO) + + +/* Limit the number of packets that can be sent via a single flush + * of the TX queue. This gives us a guaranteed exit condition and + * ensures fairness in the io path. 256 conveniently matches the + * length of the TX queue and shows a good balance of performance + * and latency. */ +#define VIRTIO_CRYPTO_TX_BURST 256 + +typedef struct VirtIOCryptoConf { + int32_t txburst; +} VirtIOCryptoConf; + +struct VirtIOCrypto; + +typedef struct VirtIOCryptoQueue { + VirtQueue *dataq; + QEMUBH *tx_bh; + int tx_waiting; + struct { + VirtQueueElement *elem; + uint32_t flags; + CryptoSymOpInfo *op_info; + void *idata_hva; + } async_tx; + struct VirtIOCrypto *vcrypto; +} VirtIOCryptoQueue; + +typedef struct VirtIOCrypto { + VirtIODevice parent_obj; + + VirtIOCryptoQueue *vqs; + VirtQueue *ctrl_vq; + CryptoLegacyHWState *crypto; + CryptoLegacyHWConf legacy_conf; + + VirtIOCryptoConf conf; + int32_t tx_burst; + uint32_t max_queues; + uint32_t status; + + int multiqueue; + uint32_t curr_queues; + size_t config_size; +} VirtIOCrypto; + +#endif /* _QEMU_VIRTIO_CRYPTO_H */ diff --git a/include/standard-headers/linux/virtio_crypto.h b/include/standard-headers/linux/virtio_crypto.h index 443b2a8..5d8b37e 100644 --- a/include/standard-headers/linux/virtio_crypto.h +++ b/include/standard-headers/linux/virtio_crypto.h @@ -13,7 +13,7 @@ #define VIRTIO_CRYPTO_OPCODE(service, op) ((service << 8) | (op)) -struct virtio_crypto_ctrl_header{ +struct virtio_crypto_ctrl_header { #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \ VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02) #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \ @@ -65,7 +65,7 @@ struct virtio_crypto_cipher_session_para { }; struct virtio_crypto_session_input { - // Device-writable part + /* Device-writable part */ __virtio64 session_id; __virtio32 status; __virtio32 padding; @@ -205,7 +205,7 @@ struct virtio_crypto_sym_create_session_req { struct virtio_crypto_alg_chain_session_req chain; } u; - // Device-readable part + /* Device-readable part */ /* No operation */ #define VIRTIO_CRYPTO_SYM_OP_NONE 0 @@ -219,9 +219,9 @@ struct virtio_crypto_sym_create_session_req { }; struct virtio_crypto_destroy_session_req { - // Device-readable part + /* Device-readable part */ __virtio64 session_id; - // Device-writable part + /* Device-writable part */ __virtio32 status; __virtio32 padding; }; @@ -331,24 +331,24 @@ struct virtio_crypto_aead_output { }; struct virtio_crypto_cipher_data_req { - // Device-readable part + /* Device-readable part */ struct virtio_crypto_cipher_para para; struct virtio_crypto_cipher_output odata; - // Device-writable part + /* Device-writable part */ struct virtio_crypto_cipher_input idata; }; struct virtio_crypto_hash_data_req { - // Device-readable part + /* Device-readable part */ struct virtio_crypto_hash_output odata; - // Device-writable part + /* Device-writable part */ struct virtio_crypto_hash_input idata; }; struct virtio_crypto_mac_data_req { - // Device-readable part + /* Device-readable part */ struct virtio_crypto_mac_output odata; - // Device-writable part + /* Device-writable part */ struct virtio_crypto_mac_input idata; }; @@ -359,7 +359,7 @@ struct virtio_crypto_alg_chain_data_para { struct virtio_crypto_alg_chain_data_output { struct virtio_crypto_cipher_output cipher; - // Device-readable part + /* Device-readable part */ __virtio64 aad_data_addr; /* additional auth data guest address */ __virtio32 aad_len; /* length of additional auth data */ __virtio32 padding; @@ -370,10 +370,10 @@ struct virtio_crypto_alg_chain_data_input { }; struct virtio_crypto_alg_chain_data_req { - // Device-readable part + /* Device-readable part */ struct virtio_crypto_alg_chain_data_para para; struct virtio_crypto_alg_chain_data_output odata; - // Device-writable part + /* Device-writable part */ struct virtio_crypto_alg_chain_data_input idata; }; @@ -383,7 +383,7 @@ struct virtio_crypto_sym_data_req { struct virtio_crypto_alg_chain_data_req chain; } u; - // Device-readable part + /* Device-readable part */ /* See above VIRTIO_CRYPTO_SYM_OP_* */ __virtio32 op_type; @@ -391,10 +391,10 @@ struct virtio_crypto_sym_data_req { }; struct virtio_crypto_aead_data_req { - // Device-readable part + /* Device-readable part */ struct virtio_crypto_aead_para para; struct virtio_crypto_aead_output odata; - // Device-writable part + /* Device-writable part */ struct virtio_crypto_aead_input idata; }; -- 1.7.12.4