xref: /openbmc/qemu/backends/cryptodev-vhost.c (revision 042cea27)
1 /*
2  * QEMU Cryptodev backend for QEMU cipher APIs
3  *
4  * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5  *
6  * Authors:
7  *    Gonglei <arei.gonglei@huawei.com>
8  *    Jay Zhou <jianjay.zhou@huawei.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #include "qemu/osdep.h"
26 #include "sysemu/cryptodev-vhost.h"
27 
28 #ifdef CONFIG_VHOST_CRYPTO
29 uint64_t
30 cryptodev_vhost_get_max_queues(
31                         CryptoDevBackendVhost *crypto)
32 {
33     return crypto->dev.max_queues;
34 }
35 
36 void cryptodev_vhost_cleanup(CryptoDevBackendVhost *crypto)
37 {
38     vhost_dev_cleanup(&crypto->dev);
39     g_free(crypto);
40 }
41 
42 struct CryptoDevBackendVhost *
43 cryptodev_vhost_init(
44              CryptoDevBackendVhostOptions *options)
45 {
46     int r;
47     CryptoDevBackendVhost *crypto;
48 
49     crypto = g_new(CryptoDevBackendVhost, 1);
50     crypto->dev.max_queues = 1;
51     crypto->dev.nvqs = 1;
52     crypto->dev.vqs = crypto->vqs;
53 
54     crypto->cc = options->cc;
55 
56     crypto->dev.protocol_features = 0;
57     crypto->backend = -1;
58 
59     /* vhost-user needs vq_index to initiate a specific queue pair */
60     crypto->dev.vq_index = crypto->cc->queue_index * crypto->dev.nvqs;
61 
62     r = vhost_dev_init(&crypto->dev, options->opaque, options->backend_type, 0);
63     if (r < 0) {
64         goto fail;
65     }
66 
67     return crypto;
68 fail:
69     g_free(crypto);
70     return NULL;
71 }
72 
73 #else
74 uint64_t
75 cryptodev_vhost_get_max_queues(CryptoDevBackendVhost *crypto)
76 {
77     return 0;
78 }
79 
80 void cryptodev_vhost_cleanup(CryptoDevBackendVhost *crypto)
81 {
82 }
83 
84 struct CryptoDevBackendVhost *
85 cryptodev_vhost_init(CryptoDevBackendVhostOptions *options)
86 {
87     return NULL;
88 }
89 #endif
90