xref: /qemu/include/sysemu/cryptodev-vhost.h (revision a1a62ced)
1042cea27SGonglei /*
2042cea27SGonglei  * QEMU Crypto Device Common Vhost Implement
3042cea27SGonglei  *
4042cea27SGonglei  * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5042cea27SGonglei  *
6042cea27SGonglei  * Authors:
7042cea27SGonglei  *    Gonglei <arei.gonglei@huawei.com>
8042cea27SGonglei  *    Jay Zhou <jianjay.zhou@huawei.com>
9042cea27SGonglei  *
10042cea27SGonglei  * This library is free software; you can redistribute it and/or
11042cea27SGonglei  * modify it under the terms of the GNU Lesser General Public
12042cea27SGonglei  * License as published by the Free Software Foundation; either
130dda001bSChetan Pant  * version 2.1 of the License, or (at your option) any later version.
14042cea27SGonglei  *
15042cea27SGonglei  * This library is distributed in the hope that it will be useful,
16042cea27SGonglei  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17042cea27SGonglei  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18042cea27SGonglei  * Lesser General Public License for more details.
19042cea27SGonglei  *
20042cea27SGonglei  * You should have received a copy of the GNU Lesser General Public
21042cea27SGonglei  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22042cea27SGonglei  *
23042cea27SGonglei  */
24042cea27SGonglei #ifndef CRYPTODEV_VHOST_H
25042cea27SGonglei #define CRYPTODEV_VHOST_H
26042cea27SGonglei 
27042cea27SGonglei #include "hw/virtio/vhost.h"
28042cea27SGonglei #include "hw/virtio/vhost-backend.h"
29042cea27SGonglei #include "chardev/char.h"
30042cea27SGonglei 
31042cea27SGonglei #include "sysemu/cryptodev.h"
32042cea27SGonglei 
33042cea27SGonglei 
34042cea27SGonglei typedef struct CryptoDevBackendVhostOptions {
35042cea27SGonglei     VhostBackendType backend_type;
36042cea27SGonglei     void *opaque;
37042cea27SGonglei     int total_queues;
38042cea27SGonglei     CryptoDevBackendClient *cc;
39042cea27SGonglei } CryptoDevBackendVhostOptions;
40042cea27SGonglei 
41042cea27SGonglei typedef struct CryptoDevBackendVhost {
42042cea27SGonglei     struct vhost_dev dev;
43042cea27SGonglei     struct vhost_virtqueue vqs[1];
44042cea27SGonglei     int backend;
45042cea27SGonglei     CryptoDevBackendClient *cc;
46042cea27SGonglei } CryptoDevBackendVhost;
47042cea27SGonglei 
48042cea27SGonglei /**
49042cea27SGonglei  * cryptodev_vhost_get_max_queues:
50042cea27SGonglei  * @crypto: the cryptodev backend common vhost object
51042cea27SGonglei  *
52042cea27SGonglei  * Get the maximum queue number of @crypto.
53042cea27SGonglei  *
54042cea27SGonglei  *
55042cea27SGonglei  * Returns: the maximum queue number
56042cea27SGonglei  */
57042cea27SGonglei uint64_t
58042cea27SGonglei cryptodev_vhost_get_max_queues(
59042cea27SGonglei                         CryptoDevBackendVhost *crypto);
60042cea27SGonglei 
61042cea27SGonglei 
62042cea27SGonglei /**
63042cea27SGonglei  * cryptodev_vhost_init:
64042cea27SGonglei  * @options: the common vhost object's option
65042cea27SGonglei  *
66042cea27SGonglei  * Creates a new cryptodev backend common vhost object
67042cea27SGonglei  *
68042cea27SGonglei  ** The returned object must be released with
69042cea27SGonglei  * cryptodev_vhost_cleanup() when no
70042cea27SGonglei  * longer required
71042cea27SGonglei  *
72042cea27SGonglei  * Returns: the cryptodev backend common vhost object
73042cea27SGonglei  */
74042cea27SGonglei struct CryptoDevBackendVhost *
75042cea27SGonglei cryptodev_vhost_init(
76042cea27SGonglei              CryptoDevBackendVhostOptions *options);
77042cea27SGonglei 
78042cea27SGonglei /**
79042cea27SGonglei  * cryptodev_vhost_cleanup:
80042cea27SGonglei  * @crypto: the cryptodev backend common vhost object
81042cea27SGonglei  *
82a1a62cedSMichael Tokarev  * Clean the resource associated with @crypto that realizaed
83042cea27SGonglei  * by cryptodev_vhost_init()
84042cea27SGonglei  *
85042cea27SGonglei  */
86042cea27SGonglei void cryptodev_vhost_cleanup(
87042cea27SGonglei                         CryptoDevBackendVhost *crypto);
88042cea27SGonglei 
89042cea27SGonglei /**
90042cea27SGonglei  * cryptodev_get_vhost:
91042cea27SGonglei  * @cc: the client object for each queue
92042cea27SGonglei  * @b: the cryptodev backend common vhost object
93042cea27SGonglei  * @queue: the cryptodev backend queue index
94042cea27SGonglei  *
95042cea27SGonglei  * Gets a new cryptodev backend common vhost object based on
96042cea27SGonglei  * @b and @queue
97042cea27SGonglei  *
98042cea27SGonglei  * Returns: the cryptodev backend common vhost object
99042cea27SGonglei  */
100042cea27SGonglei CryptoDevBackendVhost *
101042cea27SGonglei cryptodev_get_vhost(CryptoDevBackendClient *cc,
102042cea27SGonglei                             CryptoDevBackend *b,
103042cea27SGonglei                             uint16_t queue);
104042cea27SGonglei /**
105042cea27SGonglei  * cryptodev_vhost_start:
106042cea27SGonglei  * @dev: the virtio crypto object
107042cea27SGonglei  * @total_queues: the total count of queue
108042cea27SGonglei  *
109042cea27SGonglei  * Starts the vhost crypto logic
110042cea27SGonglei  *
111042cea27SGonglei  * Returns: 0 for success, negative for errors
112042cea27SGonglei  */
113042cea27SGonglei int cryptodev_vhost_start(VirtIODevice *dev, int total_queues);
114042cea27SGonglei 
115042cea27SGonglei /**
116042cea27SGonglei  * cryptodev_vhost_stop:
117042cea27SGonglei  * @dev: the virtio crypto object
118042cea27SGonglei  * @total_queues: the total count of queue
119042cea27SGonglei  *
120042cea27SGonglei  * Stops the vhost crypto logic
121042cea27SGonglei  *
122042cea27SGonglei  */
123042cea27SGonglei void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues);
124042cea27SGonglei 
125042cea27SGonglei /**
126042cea27SGonglei  * cryptodev_vhost_virtqueue_mask:
127042cea27SGonglei  * @dev: the virtio crypto object
128042cea27SGonglei  * @queue: the cryptodev backend queue index
129042cea27SGonglei  * @idx: the virtqueue index
130042cea27SGonglei  * @mask: mask or not (true or false)
131042cea27SGonglei  *
132042cea27SGonglei  * Mask/unmask events for @idx virtqueue on @dev device
133042cea27SGonglei  *
134042cea27SGonglei  */
135042cea27SGonglei void cryptodev_vhost_virtqueue_mask(VirtIODevice *dev,
136042cea27SGonglei                                            int queue,
137042cea27SGonglei                                            int idx, bool mask);
138042cea27SGonglei 
139042cea27SGonglei /**
140042cea27SGonglei  * cryptodev_vhost_virtqueue_pending:
141042cea27SGonglei  * @dev: the virtio crypto object
142042cea27SGonglei  * @queue: the cryptodev backend queue index
143042cea27SGonglei  * @idx: the virtqueue index
144042cea27SGonglei  *
145042cea27SGonglei  * Test and clear event pending status for @idx virtqueue on @dev device.
146042cea27SGonglei  * Should be called after unmask to avoid losing events.
147042cea27SGonglei  *
148042cea27SGonglei  * Returns: true for success, false for errors
149042cea27SGonglei  */
150042cea27SGonglei bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev,
151042cea27SGonglei                                               int queue, int idx);
152042cea27SGonglei 
153042cea27SGonglei #endif /* CRYPTODEV_VHOST_H */
154