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 14a8b991b5SMarkus Armbruster #ifndef QEMU_VIRTIO_CRYPTO_H 15a8b991b5SMarkus Armbruster #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" 21*db1015e9SEduardo Habkost #include "qom/object.h" 22ea4d8ac2SGonglei 23ea4d8ac2SGonglei 24ea4d8ac2SGonglei #define DEBUG_VIRTIO_CRYPTO 0 25ea4d8ac2SGonglei 26ea4d8ac2SGonglei #define DPRINTF(fmt, ...) \ 27ea4d8ac2SGonglei do { \ 28ea4d8ac2SGonglei if (DEBUG_VIRTIO_CRYPTO) { \ 29ea4d8ac2SGonglei fprintf(stderr, "virtio_crypto: " fmt, ##__VA_ARGS__); \ 30ea4d8ac2SGonglei } \ 31ea4d8ac2SGonglei } while (0) 32ea4d8ac2SGonglei 33ea4d8ac2SGonglei 34ea4d8ac2SGonglei #define TYPE_VIRTIO_CRYPTO "virtio-crypto-device" 35*db1015e9SEduardo Habkost typedef struct VirtIOCrypto VirtIOCrypto; 36ea4d8ac2SGonglei #define VIRTIO_CRYPTO(obj) \ 37ea4d8ac2SGonglei OBJECT_CHECK(VirtIOCrypto, (obj), TYPE_VIRTIO_CRYPTO) 38ea4d8ac2SGonglei #define VIRTIO_CRYPTO_GET_PARENT_CLASS(obj) \ 39ea4d8ac2SGonglei OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_CRYPTO) 40ea4d8ac2SGonglei 41ea4d8ac2SGonglei 42ea4d8ac2SGonglei typedef struct VirtIOCryptoConf { 43ea4d8ac2SGonglei CryptoDevBackend *cryptodev; 44050652d9SGonglei 45050652d9SGonglei /* Supported service mask */ 46050652d9SGonglei uint32_t crypto_services; 47050652d9SGonglei 48050652d9SGonglei /* Detailed algorithms mask */ 49050652d9SGonglei uint32_t cipher_algo_l; 50050652d9SGonglei uint32_t cipher_algo_h; 51050652d9SGonglei uint32_t hash_algo; 52050652d9SGonglei uint32_t mac_algo_l; 53050652d9SGonglei uint32_t mac_algo_h; 54050652d9SGonglei uint32_t aead_algo; 55050652d9SGonglei 56050652d9SGonglei /* Maximum length of cipher key */ 57050652d9SGonglei uint32_t max_cipher_key_len; 58050652d9SGonglei /* Maximum length of authenticated key */ 59050652d9SGonglei uint32_t max_auth_key_len; 60050652d9SGonglei /* Maximum size of each crypto request's content */ 61050652d9SGonglei uint64_t max_size; 62ea4d8ac2SGonglei } VirtIOCryptoConf; 63ea4d8ac2SGonglei 64ea4d8ac2SGonglei struct VirtIOCrypto; 65ea4d8ac2SGonglei 66ea4d8ac2SGonglei typedef struct VirtIOCryptoReq { 67ea4d8ac2SGonglei VirtQueueElement elem; 68ea4d8ac2SGonglei /* flags of operation, such as type of algorithm */ 69ea4d8ac2SGonglei uint32_t flags; 7004b9b37eSGonglei struct virtio_crypto_inhdr *in; 7104b9b37eSGonglei struct iovec *in_iov; /* Head address of dest iovec */ 7204b9b37eSGonglei unsigned int in_num; /* Number of dest iovec */ 7304b9b37eSGonglei size_t in_len; 74ea4d8ac2SGonglei VirtQueue *vq; 75ea4d8ac2SGonglei struct VirtIOCrypto *vcrypto; 76ea4d8ac2SGonglei union { 77ea4d8ac2SGonglei CryptoDevBackendSymOpInfo *sym_op_info; 78ea4d8ac2SGonglei } u; 79ea4d8ac2SGonglei } VirtIOCryptoReq; 80ea4d8ac2SGonglei 8120cb2ffdSGonglei typedef struct VirtIOCryptoQueue { 8220cb2ffdSGonglei VirtQueue *dataq; 8320cb2ffdSGonglei QEMUBH *dataq_bh; 8420cb2ffdSGonglei struct VirtIOCrypto *vcrypto; 8520cb2ffdSGonglei } VirtIOCryptoQueue; 8620cb2ffdSGonglei 87*db1015e9SEduardo Habkost struct VirtIOCrypto { 88ea4d8ac2SGonglei VirtIODevice parent_obj; 89ea4d8ac2SGonglei 90ea4d8ac2SGonglei VirtQueue *ctrl_vq; 9120cb2ffdSGonglei VirtIOCryptoQueue *vqs; 92ea4d8ac2SGonglei VirtIOCryptoConf conf; 93ea4d8ac2SGonglei CryptoDevBackend *cryptodev; 94ea4d8ac2SGonglei 95ea4d8ac2SGonglei uint32_t max_queues; 96ea4d8ac2SGonglei uint32_t status; 97ea4d8ac2SGonglei 98ea4d8ac2SGonglei int multiqueue; 99ea4d8ac2SGonglei uint32_t curr_queues; 100ea4d8ac2SGonglei size_t config_size; 1015da73dabSGonglei uint8_t vhost_started; 102*db1015e9SEduardo Habkost }; 103ea4d8ac2SGonglei 104a8b991b5SMarkus Armbruster #endif /* QEMU_VIRTIO_CRYPTO_H */ 105