xref: /openbmc/qemu/include/hw/virtio/virtio-crypto.h (revision 8fa3b702)
1 /*
2  * Virtio crypto Support
3  *
4  * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5  *
6  * Authors:
7  *    Gonglei <arei.gonglei@huawei.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or
10  * (at your option) any later version.  See the COPYING file in the
11  * top-level directory.
12  */
13 
14 #ifndef QEMU_VIRTIO_CRYPTO_H
15 #define QEMU_VIRTIO_CRYPTO_H
16 
17 #include "standard-headers/linux/virtio_crypto.h"
18 #include "hw/virtio/virtio.h"
19 #include "sysemu/iothread.h"
20 #include "sysemu/cryptodev.h"
21 #include "qom/object.h"
22 
23 
24 #define DEBUG_VIRTIO_CRYPTO 0
25 
26 #define DPRINTF(fmt, ...) \
27 do { \
28     if (DEBUG_VIRTIO_CRYPTO) { \
29         fprintf(stderr, "virtio_crypto: " fmt, ##__VA_ARGS__); \
30     } \
31 } while (0)
32 
33 
34 #define TYPE_VIRTIO_CRYPTO "virtio-crypto-device"
35 typedef struct VirtIOCrypto VirtIOCrypto;
36 DECLARE_INSTANCE_CHECKER(VirtIOCrypto, VIRTIO_CRYPTO,
37                          TYPE_VIRTIO_CRYPTO)
38 #define VIRTIO_CRYPTO_GET_PARENT_CLASS(obj) \
39         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_CRYPTO)
40 
41 
42 typedef struct VirtIOCryptoConf {
43     CryptoDevBackend *cryptodev;
44 
45     /* Supported service mask */
46     uint32_t crypto_services;
47 
48     /* Detailed algorithms mask */
49     uint32_t cipher_algo_l;
50     uint32_t cipher_algo_h;
51     uint32_t hash_algo;
52     uint32_t mac_algo_l;
53     uint32_t mac_algo_h;
54     uint32_t aead_algo;
55 
56     /* Maximum length of cipher key */
57     uint32_t max_cipher_key_len;
58     /* Maximum length of authenticated key */
59     uint32_t max_auth_key_len;
60     /* Maximum size of each crypto request's content */
61     uint64_t max_size;
62 } VirtIOCryptoConf;
63 
64 struct VirtIOCrypto;
65 
66 typedef struct VirtIOCryptoReq {
67     VirtQueueElement elem;
68     /* flags of operation, such as type of algorithm */
69     uint32_t flags;
70     struct virtio_crypto_inhdr *in;
71     struct iovec *in_iov; /* Head address of dest iovec */
72     unsigned int in_num; /* Number of dest iovec */
73     size_t in_len;
74     VirtQueue *vq;
75     struct VirtIOCrypto *vcrypto;
76     union {
77         CryptoDevBackendSymOpInfo *sym_op_info;
78     } u;
79 } VirtIOCryptoReq;
80 
81 typedef struct VirtIOCryptoQueue {
82     VirtQueue *dataq;
83     QEMUBH *dataq_bh;
84     struct VirtIOCrypto *vcrypto;
85 } VirtIOCryptoQueue;
86 
87 struct VirtIOCrypto {
88     VirtIODevice parent_obj;
89 
90     VirtQueue *ctrl_vq;
91     VirtIOCryptoQueue *vqs;
92     VirtIOCryptoConf conf;
93     CryptoDevBackend *cryptodev;
94 
95     uint32_t max_queues;
96     uint32_t status;
97 
98     int multiqueue;
99     uint32_t curr_queues;
100     size_t config_size;
101     uint8_t vhost_started;
102 };
103 
104 #endif /* QEMU_VIRTIO_CRYPTO_H */
105