1ea4d8ac2SGonglei /* 2ea4d8ac2SGonglei * Virtio crypto Support 3ea4d8ac2SGonglei * 4ea4d8ac2SGonglei * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. 5ea4d8ac2SGonglei * 6ea4d8ac2SGonglei * Authors: 7ea4d8ac2SGonglei * Gonglei <arei.gonglei@huawei.com> 8ea4d8ac2SGonglei * 9ea4d8ac2SGonglei * This work is licensed under the terms of the GNU GPL, version 2 or 10ea4d8ac2SGonglei * (at your option) any later version. See the COPYING file in the 11ea4d8ac2SGonglei * top-level directory. 12ea4d8ac2SGonglei */ 13ea4d8ac2SGonglei 14ea4d8ac2SGonglei #ifndef _QEMU_VIRTIO_CRYPTO_H 15ea4d8ac2SGonglei #define _QEMU_VIRTIO_CRYPTO_H 16ea4d8ac2SGonglei 17ea4d8ac2SGonglei #include "standard-headers/linux/virtio_crypto.h" 18ea4d8ac2SGonglei #include "hw/virtio/virtio.h" 19ea4d8ac2SGonglei #include "sysemu/iothread.h" 20ea4d8ac2SGonglei #include "sysemu/cryptodev.h" 21ea4d8ac2SGonglei 22ea4d8ac2SGonglei 23ea4d8ac2SGonglei #define DEBUG_VIRTIO_CRYPTO 0 24ea4d8ac2SGonglei 25ea4d8ac2SGonglei #define DPRINTF(fmt, ...) \ 26ea4d8ac2SGonglei do { \ 27ea4d8ac2SGonglei if (DEBUG_VIRTIO_CRYPTO) { \ 28ea4d8ac2SGonglei fprintf(stderr, "virtio_crypto: " fmt, ##__VA_ARGS__); \ 29ea4d8ac2SGonglei } \ 30ea4d8ac2SGonglei } while (0) 31ea4d8ac2SGonglei 32ea4d8ac2SGonglei 33ea4d8ac2SGonglei #define TYPE_VIRTIO_CRYPTO "virtio-crypto-device" 34ea4d8ac2SGonglei #define VIRTIO_CRYPTO(obj) \ 35ea4d8ac2SGonglei OBJECT_CHECK(VirtIOCrypto, (obj), TYPE_VIRTIO_CRYPTO) 36ea4d8ac2SGonglei #define VIRTIO_CRYPTO_GET_PARENT_CLASS(obj) \ 37ea4d8ac2SGonglei OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_CRYPTO) 38ea4d8ac2SGonglei 39ea4d8ac2SGonglei 40ea4d8ac2SGonglei typedef struct VirtIOCryptoConf { 41ea4d8ac2SGonglei CryptoDevBackend *cryptodev; 42050652d9SGonglei 43050652d9SGonglei /* Supported service mask */ 44050652d9SGonglei uint32_t crypto_services; 45050652d9SGonglei 46050652d9SGonglei /* Detailed algorithms mask */ 47050652d9SGonglei uint32_t cipher_algo_l; 48050652d9SGonglei uint32_t cipher_algo_h; 49050652d9SGonglei uint32_t hash_algo; 50050652d9SGonglei uint32_t mac_algo_l; 51050652d9SGonglei uint32_t mac_algo_h; 52050652d9SGonglei uint32_t aead_algo; 53050652d9SGonglei 54050652d9SGonglei /* Maximum length of cipher key */ 55050652d9SGonglei uint32_t max_cipher_key_len; 56050652d9SGonglei /* Maximum length of authenticated key */ 57050652d9SGonglei uint32_t max_auth_key_len; 58050652d9SGonglei /* Maximum size of each crypto request's content */ 59050652d9SGonglei uint64_t max_size; 60ea4d8ac2SGonglei } VirtIOCryptoConf; 61ea4d8ac2SGonglei 62ea4d8ac2SGonglei struct VirtIOCrypto; 63ea4d8ac2SGonglei 64ea4d8ac2SGonglei typedef struct VirtIOCryptoReq { 65ea4d8ac2SGonglei VirtQueueElement elem; 66ea4d8ac2SGonglei /* flags of operation, such as type of algorithm */ 67ea4d8ac2SGonglei uint32_t flags; 6804b9b37eSGonglei struct virtio_crypto_inhdr *in; 6904b9b37eSGonglei struct iovec *in_iov; /* Head address of dest iovec */ 7004b9b37eSGonglei unsigned int in_num; /* Number of dest iovec */ 7104b9b37eSGonglei size_t in_len; 72ea4d8ac2SGonglei VirtQueue *vq; 73ea4d8ac2SGonglei struct VirtIOCrypto *vcrypto; 74ea4d8ac2SGonglei union { 75ea4d8ac2SGonglei CryptoDevBackendSymOpInfo *sym_op_info; 76ea4d8ac2SGonglei } u; 77ea4d8ac2SGonglei } VirtIOCryptoReq; 78ea4d8ac2SGonglei 7920cb2ffdSGonglei typedef struct VirtIOCryptoQueue { 8020cb2ffdSGonglei VirtQueue *dataq; 8120cb2ffdSGonglei QEMUBH *dataq_bh; 8220cb2ffdSGonglei struct VirtIOCrypto *vcrypto; 8320cb2ffdSGonglei } VirtIOCryptoQueue; 8420cb2ffdSGonglei 85ea4d8ac2SGonglei typedef struct VirtIOCrypto { 86ea4d8ac2SGonglei VirtIODevice parent_obj; 87ea4d8ac2SGonglei 88ea4d8ac2SGonglei VirtQueue *ctrl_vq; 8920cb2ffdSGonglei VirtIOCryptoQueue *vqs; 90ea4d8ac2SGonglei VirtIOCryptoConf conf; 91ea4d8ac2SGonglei CryptoDevBackend *cryptodev; 92ea4d8ac2SGonglei 93ea4d8ac2SGonglei uint32_t max_queues; 94ea4d8ac2SGonglei uint32_t status; 95ea4d8ac2SGonglei 96ea4d8ac2SGonglei int multiqueue; 97ea4d8ac2SGonglei uint32_t curr_queues; 98ea4d8ac2SGonglei size_t config_size; 99*5da73dabSGonglei uint8_t vhost_started; 100ea4d8ac2SGonglei } VirtIOCrypto; 101ea4d8ac2SGonglei 102ea4d8ac2SGonglei #endif /* _QEMU_VIRTIO_CRYPTO_H */ 103