summaryrefslogtreecommitdiffstats
path: root/include/sysemu/cryptodev-vhost.h
blob: e8cab1356e490a436e9f7ab729e3df9b9a0c6b7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * QEMU Crypto Device Common Vhost Implement
 *
 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
 *
 * Authors:
 *    Gonglei <arei.gonglei@huawei.com>
 *    Jay Zhou <jianjay.zhou@huawei.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 */
#ifndef CRYPTODEV_VHOST_H
#define CRYPTODEV_VHOST_H

#include "hw/virtio/vhost.h"
#include "hw/virtio/vhost-backend.h"
#include "chardev/char.h"

#include "sysemu/cryptodev.h"


typedef struct CryptoDevBackendVhostOptions {
    VhostBackendType backend_type;
    void *opaque;
    int total_queues;
    CryptoDevBackendClient *cc;
} CryptoDevBackendVhostOptions;

typedef struct CryptoDevBackendVhost {
    struct vhost_dev dev;
    struct vhost_virtqueue vqs[1];
    int backend;
    CryptoDevBackendClient *cc;
} CryptoDevBackendVhost;

/**
 * cryptodev_vhost_get_max_queues:
 * @crypto: the cryptodev backend common vhost object
 *
 * Get the maximum queue number of @crypto.
 *
 *
 * Returns: the maximum queue number
 */
uint64_t
cryptodev_vhost_get_max_queues(
                        CryptoDevBackendVhost *crypto);


/**
 * cryptodev_vhost_init:
 * @options: the common vhost object's option
 *
 * Creates a new cryptodev backend common vhost object
 *
 ** The returned object must be released with
 * cryptodev_vhost_cleanup() when no
 * longer required
 *
 * Returns: the cryptodev backend common vhost object
 */
struct CryptoDevBackendVhost *
cryptodev_vhost_init(
             CryptoDevBackendVhostOptions *options);

/**
 * cryptodev_vhost_cleanup:
 * @crypto: the cryptodev backend common vhost object
 *
 * Clean the resouce associated with @crypto that realizaed
 * by cryptodev_vhost_init()
 *
 */
void cryptodev_vhost_cleanup(
                        CryptoDevBackendVhost *crypto);

/**
 * cryptodev_get_vhost:
 * @cc: the client object for each queue
 * @b: the cryptodev backend common vhost object
 * @queue: the cryptodev backend queue index
 *
 * Gets a new cryptodev backend common vhost object based on
 * @b and @queue
 *
 * Returns: the cryptodev backend common vhost object
 */
CryptoDevBackendVhost *
cryptodev_get_vhost(CryptoDevBackendClient *cc,
                            CryptoDevBackend *b,
                            uint16_t queue);
/**
 * cryptodev_vhost_start:
 * @dev: the virtio crypto object
 * @total_queues: the total count of queue
 *
 * Starts the vhost crypto logic
 *
 * Returns: 0 for success, negative for errors
 */
int cryptodev_vhost_start(VirtIODevice *dev, int total_queues);

/**
 * cryptodev_vhost_stop:
 * @dev: the virtio crypto object
 * @total_queues: the total count of queue
 *
 * Stops the vhost crypto logic
 *
 */
void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues);

/**
 * cryptodev_vhost_virtqueue_mask:
 * @dev: the virtio crypto object
 * @queue: the cryptodev backend queue index
 * @idx: the virtqueue index
 * @mask: mask or not (true or false)
 *
 * Mask/unmask events for @idx virtqueue on @dev device
 *
 */
void cryptodev_vhost_virtqueue_mask(VirtIODevice *dev,
                                           int queue,
                                           int idx, bool mask);

/**
 * cryptodev_vhost_virtqueue_pending:
 * @dev: the virtio crypto object
 * @queue: the cryptodev backend queue index
 * @idx: the virtqueue index
 *
 * Test and clear event pending status for @idx virtqueue on @dev device.
 * Should be called after unmask to avoid losing events.
 *
 * Returns: true for success, false for errors
 */
bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev,
                                              int queue, int idx);

#endif /* CRYPTODEV_VHOST_H */