Gonglei | 042cea2 | 2018-03-01 21:46:28 +0800 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Crypto Device Common Vhost Implement |
| 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 | #ifndef CRYPTODEV_VHOST_H |
| 25 | #define CRYPTODEV_VHOST_H |
| 26 | |
Gonglei | 042cea2 | 2018-03-01 21:46:28 +0800 | [diff] [blame] | 27 | #include "hw/virtio/vhost.h" |
| 28 | #include "hw/virtio/vhost-backend.h" |
| 29 | #include "chardev/char.h" |
| 30 | |
| 31 | #include "sysemu/cryptodev.h" |
| 32 | |
| 33 | |
| 34 | typedef struct CryptoDevBackendVhostOptions { |
| 35 | VhostBackendType backend_type; |
| 36 | void *opaque; |
| 37 | int total_queues; |
| 38 | CryptoDevBackendClient *cc; |
| 39 | } CryptoDevBackendVhostOptions; |
| 40 | |
| 41 | typedef struct CryptoDevBackendVhost { |
| 42 | struct vhost_dev dev; |
| 43 | struct vhost_virtqueue vqs[1]; |
| 44 | int backend; |
| 45 | CryptoDevBackendClient *cc; |
| 46 | } CryptoDevBackendVhost; |
| 47 | |
| 48 | /** |
| 49 | * cryptodev_vhost_get_max_queues: |
| 50 | * @crypto: the cryptodev backend common vhost object |
| 51 | * |
| 52 | * Get the maximum queue number of @crypto. |
| 53 | * |
| 54 | * |
| 55 | * Returns: the maximum queue number |
| 56 | */ |
| 57 | uint64_t |
| 58 | cryptodev_vhost_get_max_queues( |
| 59 | CryptoDevBackendVhost *crypto); |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * cryptodev_vhost_init: |
| 64 | * @options: the common vhost object's option |
| 65 | * |
| 66 | * Creates a new cryptodev backend common vhost object |
| 67 | * |
| 68 | ** The returned object must be released with |
| 69 | * cryptodev_vhost_cleanup() when no |
| 70 | * longer required |
| 71 | * |
| 72 | * Returns: the cryptodev backend common vhost object |
| 73 | */ |
| 74 | struct CryptoDevBackendVhost * |
| 75 | cryptodev_vhost_init( |
| 76 | CryptoDevBackendVhostOptions *options); |
| 77 | |
| 78 | /** |
| 79 | * cryptodev_vhost_cleanup: |
| 80 | * @crypto: the cryptodev backend common vhost object |
| 81 | * |
| 82 | * Clean the resouce associated with @crypto that realizaed |
| 83 | * by cryptodev_vhost_init() |
| 84 | * |
| 85 | */ |
| 86 | void cryptodev_vhost_cleanup( |
| 87 | CryptoDevBackendVhost *crypto); |
| 88 | |
| 89 | /** |
| 90 | * cryptodev_get_vhost: |
| 91 | * @cc: the client object for each queue |
| 92 | * @b: the cryptodev backend common vhost object |
| 93 | * @queue: the cryptodev backend queue index |
| 94 | * |
| 95 | * Gets a new cryptodev backend common vhost object based on |
| 96 | * @b and @queue |
| 97 | * |
| 98 | * Returns: the cryptodev backend common vhost object |
| 99 | */ |
| 100 | CryptoDevBackendVhost * |
| 101 | cryptodev_get_vhost(CryptoDevBackendClient *cc, |
| 102 | CryptoDevBackend *b, |
| 103 | uint16_t queue); |
| 104 | /** |
| 105 | * cryptodev_vhost_start: |
| 106 | * @dev: the virtio crypto object |
| 107 | * @total_queues: the total count of queue |
| 108 | * |
| 109 | * Starts the vhost crypto logic |
| 110 | * |
| 111 | * Returns: 0 for success, negative for errors |
| 112 | */ |
| 113 | int cryptodev_vhost_start(VirtIODevice *dev, int total_queues); |
| 114 | |
| 115 | /** |
| 116 | * cryptodev_vhost_stop: |
| 117 | * @dev: the virtio crypto object |
| 118 | * @total_queues: the total count of queue |
| 119 | * |
| 120 | * Stops the vhost crypto logic |
| 121 | * |
| 122 | */ |
| 123 | void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues); |
| 124 | |
| 125 | /** |
| 126 | * cryptodev_vhost_virtqueue_mask: |
| 127 | * @dev: the virtio crypto object |
| 128 | * @queue: the cryptodev backend queue index |
| 129 | * @idx: the virtqueue index |
| 130 | * @mask: mask or not (true or false) |
| 131 | * |
| 132 | * Mask/unmask events for @idx virtqueue on @dev device |
| 133 | * |
| 134 | */ |
| 135 | void cryptodev_vhost_virtqueue_mask(VirtIODevice *dev, |
| 136 | int queue, |
| 137 | int idx, bool mask); |
| 138 | |
| 139 | /** |
| 140 | * cryptodev_vhost_virtqueue_pending: |
| 141 | * @dev: the virtio crypto object |
| 142 | * @queue: the cryptodev backend queue index |
| 143 | * @idx: the virtqueue index |
| 144 | * |
| 145 | * Test and clear event pending status for @idx virtqueue on @dev device. |
| 146 | * Should be called after unmask to avoid losing events. |
| 147 | * |
| 148 | * Returns: true for success, false for errors |
| 149 | */ |
| 150 | bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev, |
| 151 | int queue, int idx); |
| 152 | |
| 153 | #endif /* CRYPTODEV_VHOST_H */ |