1*042cea27SGonglei /* 2*042cea27SGonglei * QEMU Crypto Device Common Vhost Implement 3*042cea27SGonglei * 4*042cea27SGonglei * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. 5*042cea27SGonglei * 6*042cea27SGonglei * Authors: 7*042cea27SGonglei * Gonglei <arei.gonglei@huawei.com> 8*042cea27SGonglei * Jay Zhou <jianjay.zhou@huawei.com> 9*042cea27SGonglei * 10*042cea27SGonglei * This library is free software; you can redistribute it and/or 11*042cea27SGonglei * modify it under the terms of the GNU Lesser General Public 12*042cea27SGonglei * License as published by the Free Software Foundation; either 13*042cea27SGonglei * version 2 of the License, or (at your option) any later version. 14*042cea27SGonglei * 15*042cea27SGonglei * This library is distributed in the hope that it will be useful, 16*042cea27SGonglei * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*042cea27SGonglei * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18*042cea27SGonglei * Lesser General Public License for more details. 19*042cea27SGonglei * 20*042cea27SGonglei * You should have received a copy of the GNU Lesser General Public 21*042cea27SGonglei * License along with this library; if not, see <http://www.gnu.org/licenses/>. 22*042cea27SGonglei * 23*042cea27SGonglei */ 24*042cea27SGonglei #ifndef CRYPTODEV_VHOST_H 25*042cea27SGonglei #define CRYPTODEV_VHOST_H 26*042cea27SGonglei 27*042cea27SGonglei #include "qemu-common.h" 28*042cea27SGonglei #include "hw/virtio/vhost.h" 29*042cea27SGonglei #include "hw/virtio/vhost-backend.h" 30*042cea27SGonglei #include "chardev/char.h" 31*042cea27SGonglei 32*042cea27SGonglei #include "sysemu/cryptodev.h" 33*042cea27SGonglei 34*042cea27SGonglei 35*042cea27SGonglei typedef struct CryptoDevBackendVhostOptions { 36*042cea27SGonglei VhostBackendType backend_type; 37*042cea27SGonglei void *opaque; 38*042cea27SGonglei int total_queues; 39*042cea27SGonglei CryptoDevBackendClient *cc; 40*042cea27SGonglei } CryptoDevBackendVhostOptions; 41*042cea27SGonglei 42*042cea27SGonglei typedef struct CryptoDevBackendVhost { 43*042cea27SGonglei struct vhost_dev dev; 44*042cea27SGonglei struct vhost_virtqueue vqs[1]; 45*042cea27SGonglei int backend; 46*042cea27SGonglei CryptoDevBackendClient *cc; 47*042cea27SGonglei } CryptoDevBackendVhost; 48*042cea27SGonglei 49*042cea27SGonglei /** 50*042cea27SGonglei * cryptodev_vhost_get_max_queues: 51*042cea27SGonglei * @crypto: the cryptodev backend common vhost object 52*042cea27SGonglei * 53*042cea27SGonglei * Get the maximum queue number of @crypto. 54*042cea27SGonglei * 55*042cea27SGonglei * 56*042cea27SGonglei * Returns: the maximum queue number 57*042cea27SGonglei */ 58*042cea27SGonglei uint64_t 59*042cea27SGonglei cryptodev_vhost_get_max_queues( 60*042cea27SGonglei CryptoDevBackendVhost *crypto); 61*042cea27SGonglei 62*042cea27SGonglei 63*042cea27SGonglei /** 64*042cea27SGonglei * cryptodev_vhost_init: 65*042cea27SGonglei * @options: the common vhost object's option 66*042cea27SGonglei * 67*042cea27SGonglei * Creates a new cryptodev backend common vhost object 68*042cea27SGonglei * 69*042cea27SGonglei ** The returned object must be released with 70*042cea27SGonglei * cryptodev_vhost_cleanup() when no 71*042cea27SGonglei * longer required 72*042cea27SGonglei * 73*042cea27SGonglei * Returns: the cryptodev backend common vhost object 74*042cea27SGonglei */ 75*042cea27SGonglei struct CryptoDevBackendVhost * 76*042cea27SGonglei cryptodev_vhost_init( 77*042cea27SGonglei CryptoDevBackendVhostOptions *options); 78*042cea27SGonglei 79*042cea27SGonglei /** 80*042cea27SGonglei * cryptodev_vhost_cleanup: 81*042cea27SGonglei * @crypto: the cryptodev backend common vhost object 82*042cea27SGonglei * 83*042cea27SGonglei * Clean the resouce associated with @crypto that realizaed 84*042cea27SGonglei * by cryptodev_vhost_init() 85*042cea27SGonglei * 86*042cea27SGonglei */ 87*042cea27SGonglei void cryptodev_vhost_cleanup( 88*042cea27SGonglei CryptoDevBackendVhost *crypto); 89*042cea27SGonglei 90*042cea27SGonglei /** 91*042cea27SGonglei * cryptodev_get_vhost: 92*042cea27SGonglei * @cc: the client object for each queue 93*042cea27SGonglei * @b: the cryptodev backend common vhost object 94*042cea27SGonglei * @queue: the cryptodev backend queue index 95*042cea27SGonglei * 96*042cea27SGonglei * Gets a new cryptodev backend common vhost object based on 97*042cea27SGonglei * @b and @queue 98*042cea27SGonglei * 99*042cea27SGonglei * Returns: the cryptodev backend common vhost object 100*042cea27SGonglei */ 101*042cea27SGonglei CryptoDevBackendVhost * 102*042cea27SGonglei cryptodev_get_vhost(CryptoDevBackendClient *cc, 103*042cea27SGonglei CryptoDevBackend *b, 104*042cea27SGonglei uint16_t queue); 105*042cea27SGonglei /** 106*042cea27SGonglei * cryptodev_vhost_start: 107*042cea27SGonglei * @dev: the virtio crypto object 108*042cea27SGonglei * @total_queues: the total count of queue 109*042cea27SGonglei * 110*042cea27SGonglei * Starts the vhost crypto logic 111*042cea27SGonglei * 112*042cea27SGonglei * Returns: 0 for success, negative for errors 113*042cea27SGonglei */ 114*042cea27SGonglei int cryptodev_vhost_start(VirtIODevice *dev, int total_queues); 115*042cea27SGonglei 116*042cea27SGonglei /** 117*042cea27SGonglei * cryptodev_vhost_stop: 118*042cea27SGonglei * @dev: the virtio crypto object 119*042cea27SGonglei * @total_queues: the total count of queue 120*042cea27SGonglei * 121*042cea27SGonglei * Stops the vhost crypto logic 122*042cea27SGonglei * 123*042cea27SGonglei */ 124*042cea27SGonglei void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues); 125*042cea27SGonglei 126*042cea27SGonglei /** 127*042cea27SGonglei * cryptodev_vhost_virtqueue_mask: 128*042cea27SGonglei * @dev: the virtio crypto object 129*042cea27SGonglei * @queue: the cryptodev backend queue index 130*042cea27SGonglei * @idx: the virtqueue index 131*042cea27SGonglei * @mask: mask or not (true or false) 132*042cea27SGonglei * 133*042cea27SGonglei * Mask/unmask events for @idx virtqueue on @dev device 134*042cea27SGonglei * 135*042cea27SGonglei */ 136*042cea27SGonglei void cryptodev_vhost_virtqueue_mask(VirtIODevice *dev, 137*042cea27SGonglei int queue, 138*042cea27SGonglei int idx, bool mask); 139*042cea27SGonglei 140*042cea27SGonglei /** 141*042cea27SGonglei * cryptodev_vhost_virtqueue_pending: 142*042cea27SGonglei * @dev: the virtio crypto object 143*042cea27SGonglei * @queue: the cryptodev backend queue index 144*042cea27SGonglei * @idx: the virtqueue index 145*042cea27SGonglei * 146*042cea27SGonglei * Test and clear event pending status for @idx virtqueue on @dev device. 147*042cea27SGonglei * Should be called after unmask to avoid losing events. 148*042cea27SGonglei * 149*042cea27SGonglei * Returns: true for success, false for errors 150*042cea27SGonglei */ 151*042cea27SGonglei bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev, 152*042cea27SGonglei int queue, int idx); 153*042cea27SGonglei 154*042cea27SGonglei #endif /* CRYPTODEV_VHOST_H */ 155