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; 42*050652d9SGonglei 43*050652d9SGonglei /* Supported service mask */ 44*050652d9SGonglei uint32_t crypto_services; 45*050652d9SGonglei 46*050652d9SGonglei /* Detailed algorithms mask */ 47*050652d9SGonglei uint32_t cipher_algo_l; 48*050652d9SGonglei uint32_t cipher_algo_h; 49*050652d9SGonglei uint32_t hash_algo; 50*050652d9SGonglei uint32_t mac_algo_l; 51*050652d9SGonglei uint32_t mac_algo_h; 52*050652d9SGonglei uint32_t aead_algo; 53*050652d9SGonglei 54*050652d9SGonglei /* Maximum length of cipher key */ 55*050652d9SGonglei uint32_t max_cipher_key_len; 56*050652d9SGonglei /* Maximum length of authenticated key */ 57*050652d9SGonglei uint32_t max_auth_key_len; 58*050652d9SGonglei /* Maximum size of each crypto request's content */ 59*050652d9SGonglei 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; 68ea4d8ac2SGonglei VirtQueue *vq; 69ea4d8ac2SGonglei struct VirtIOCrypto *vcrypto; 70ea4d8ac2SGonglei union { 71ea4d8ac2SGonglei CryptoDevBackendSymOpInfo *sym_op_info; 72ea4d8ac2SGonglei } u; 73ea4d8ac2SGonglei } VirtIOCryptoReq; 74ea4d8ac2SGonglei 75ea4d8ac2SGonglei typedef struct VirtIOCrypto { 76ea4d8ac2SGonglei VirtIODevice parent_obj; 77ea4d8ac2SGonglei 78ea4d8ac2SGonglei VirtQueue *ctrl_vq; 79ea4d8ac2SGonglei 80ea4d8ac2SGonglei VirtIOCryptoConf conf; 81ea4d8ac2SGonglei CryptoDevBackend *cryptodev; 82ea4d8ac2SGonglei 83ea4d8ac2SGonglei uint32_t max_queues; 84ea4d8ac2SGonglei uint32_t status; 85ea4d8ac2SGonglei 86ea4d8ac2SGonglei int multiqueue; 87ea4d8ac2SGonglei uint32_t curr_queues; 88ea4d8ac2SGonglei size_t config_size; 89ea4d8ac2SGonglei } VirtIOCrypto; 90ea4d8ac2SGonglei 91ea4d8ac2SGonglei #endif /* _QEMU_VIRTIO_CRYPTO_H */ 92