2016-10-28 10:33:24 +02:00
|
|
|
/*
|
|
|
|
* Virtio crypto Support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Gonglei <arei.gonglei@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.
|
|
|
|
*/
|
|
|
|
|
2019-03-15 15:51:21 +01:00
|
|
|
#ifndef QEMU_VIRTIO_CRYPTO_H
|
|
|
|
#define QEMU_VIRTIO_CRYPTO_H
|
2016-10-28 10:33:24 +02:00
|
|
|
|
|
|
|
#include "standard-headers/linux/virtio_crypto.h"
|
|
|
|
#include "hw/virtio/virtio.h"
|
|
|
|
#include "sysemu/iothread.h"
|
|
|
|
#include "sysemu/cryptodev.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2016-10-28 10:33:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
#define DEBUG_VIRTIO_CRYPTO 0
|
|
|
|
|
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (DEBUG_VIRTIO_CRYPTO) { \
|
|
|
|
fprintf(stderr, "virtio_crypto: " fmt, ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
#define TYPE_VIRTIO_CRYPTO "virtio-crypto-device"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOCrypto, VIRTIO_CRYPTO)
|
2016-10-28 10:33:24 +02:00
|
|
|
#define VIRTIO_CRYPTO_GET_PARENT_CLASS(obj) \
|
|
|
|
OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_CRYPTO)
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct VirtIOCryptoConf {
|
|
|
|
CryptoDevBackend *cryptodev;
|
2016-10-28 10:33:26 +02:00
|
|
|
|
|
|
|
/* Supported service mask */
|
|
|
|
uint32_t crypto_services;
|
|
|
|
|
|
|
|
/* Detailed algorithms mask */
|
|
|
|
uint32_t cipher_algo_l;
|
|
|
|
uint32_t cipher_algo_h;
|
|
|
|
uint32_t hash_algo;
|
|
|
|
uint32_t mac_algo_l;
|
|
|
|
uint32_t mac_algo_h;
|
|
|
|
uint32_t aead_algo;
|
2022-06-11 08:42:43 +02:00
|
|
|
uint32_t akcipher_algo;
|
2016-10-28 10:33:26 +02:00
|
|
|
|
|
|
|
/* Maximum length of cipher key */
|
|
|
|
uint32_t max_cipher_key_len;
|
|
|
|
/* Maximum length of authenticated key */
|
|
|
|
uint32_t max_auth_key_len;
|
|
|
|
/* Maximum size of each crypto request's content */
|
|
|
|
uint64_t max_size;
|
2016-10-28 10:33:24 +02:00
|
|
|
} VirtIOCryptoConf;
|
|
|
|
|
|
|
|
struct VirtIOCrypto;
|
|
|
|
|
|
|
|
typedef struct VirtIOCryptoReq {
|
|
|
|
VirtQueueElement elem;
|
|
|
|
/* flags of operation, such as type of algorithm */
|
|
|
|
uint32_t flags;
|
2016-10-28 10:33:28 +02:00
|
|
|
struct virtio_crypto_inhdr *in;
|
|
|
|
struct iovec *in_iov; /* Head address of dest iovec */
|
|
|
|
unsigned int in_num; /* Number of dest iovec */
|
|
|
|
size_t in_len;
|
2016-10-28 10:33:24 +02:00
|
|
|
VirtQueue *vq;
|
|
|
|
struct VirtIOCrypto *vcrypto;
|
2022-06-11 08:42:43 +02:00
|
|
|
CryptoDevBackendOpInfo op_info;
|
2016-10-28 10:33:24 +02:00
|
|
|
} VirtIOCryptoReq;
|
|
|
|
|
2016-10-28 10:33:30 +02:00
|
|
|
typedef struct VirtIOCryptoQueue {
|
|
|
|
VirtQueue *dataq;
|
|
|
|
QEMUBH *dataq_bh;
|
|
|
|
struct VirtIOCrypto *vcrypto;
|
|
|
|
} VirtIOCryptoQueue;
|
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct VirtIOCrypto {
|
2016-10-28 10:33:24 +02:00
|
|
|
VirtIODevice parent_obj;
|
|
|
|
|
|
|
|
VirtQueue *ctrl_vq;
|
2016-10-28 10:33:30 +02:00
|
|
|
VirtIOCryptoQueue *vqs;
|
2016-10-28 10:33:24 +02:00
|
|
|
VirtIOCryptoConf conf;
|
|
|
|
CryptoDevBackend *cryptodev;
|
|
|
|
|
|
|
|
uint32_t max_queues;
|
|
|
|
uint32_t status;
|
|
|
|
|
|
|
|
int multiqueue;
|
|
|
|
uint32_t curr_queues;
|
|
|
|
size_t config_size;
|
2018-03-01 14:46:29 +01:00
|
|
|
uint8_t vhost_started;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2016-10-28 10:33:24 +02:00
|
|
|
|
2019-03-15 15:51:21 +01:00
|
|
|
#endif /* QEMU_VIRTIO_CRYPTO_H */
|