xref: /openbmc/qemu/include/hw/virtio/virtio-crypto.h (revision a28498b1f9591e12dcbfdf06dc8f54e15926760e)
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"
21db1015e9SEduardo 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"
358063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(VirtIOCrypto, 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;
53*0e660a6fSzhenwei pi     uint32_t akcipher_algo;
54050652d9SGonglei 
55050652d9SGonglei     /* Maximum length of cipher key */
56050652d9SGonglei     uint32_t max_cipher_key_len;
57050652d9SGonglei     /* Maximum length of authenticated key */
58050652d9SGonglei     uint32_t max_auth_key_len;
59050652d9SGonglei     /* Maximum size of each crypto request's content */
60050652d9SGonglei     uint64_t max_size;
61ea4d8ac2SGonglei } VirtIOCryptoConf;
62ea4d8ac2SGonglei 
63ea4d8ac2SGonglei struct VirtIOCrypto;
64ea4d8ac2SGonglei 
65ea4d8ac2SGonglei typedef struct VirtIOCryptoReq {
66ea4d8ac2SGonglei     VirtQueueElement elem;
67ea4d8ac2SGonglei     /* flags of operation, such as type of algorithm */
68ea4d8ac2SGonglei     uint32_t flags;
6904b9b37eSGonglei     struct virtio_crypto_inhdr *in;
7004b9b37eSGonglei     struct iovec *in_iov; /* Head address of dest iovec */
7104b9b37eSGonglei     unsigned int in_num; /* Number of dest iovec */
7204b9b37eSGonglei     size_t in_len;
73ea4d8ac2SGonglei     VirtQueue *vq;
74ea4d8ac2SGonglei     struct VirtIOCrypto *vcrypto;
75*0e660a6fSzhenwei pi     CryptoDevBackendOpInfo op_info;
76ea4d8ac2SGonglei } VirtIOCryptoReq;
77ea4d8ac2SGonglei 
7820cb2ffdSGonglei typedef struct VirtIOCryptoQueue {
7920cb2ffdSGonglei     VirtQueue *dataq;
8020cb2ffdSGonglei     QEMUBH *dataq_bh;
8120cb2ffdSGonglei     struct VirtIOCrypto *vcrypto;
8220cb2ffdSGonglei } VirtIOCryptoQueue;
8320cb2ffdSGonglei 
84db1015e9SEduardo Habkost struct VirtIOCrypto {
85ea4d8ac2SGonglei     VirtIODevice parent_obj;
86ea4d8ac2SGonglei 
87ea4d8ac2SGonglei     VirtQueue *ctrl_vq;
8820cb2ffdSGonglei     VirtIOCryptoQueue *vqs;
89ea4d8ac2SGonglei     VirtIOCryptoConf conf;
90ea4d8ac2SGonglei     CryptoDevBackend *cryptodev;
91ea4d8ac2SGonglei 
92ea4d8ac2SGonglei     uint32_t max_queues;
93ea4d8ac2SGonglei     uint32_t status;
94ea4d8ac2SGonglei 
95ea4d8ac2SGonglei     int multiqueue;
96ea4d8ac2SGonglei     uint32_t curr_queues;
97ea4d8ac2SGonglei     size_t config_size;
985da73dabSGonglei     uint8_t vhost_started;
99db1015e9SEduardo Habkost };
100ea4d8ac2SGonglei 
101a8b991b5SMarkus Armbruster #endif /* QEMU_VIRTIO_CRYPTO_H */
102