[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 03/14] crypto: add cryptoLegacyHW stuff
From: |
Gonglei |
Subject: |
[Qemu-devel] [PATCH v1 03/14] crypto: add cryptoLegacyHW stuff |
Date: |
Thu, 8 Sep 2016 11:42:25 +0800 |
In previous patch, we define CryptoLegacyHWOptions in
qapi-schema.json. we introduce the new/delete funciton
about crypto legacy hardware device.
Note: legacy cryptographic device support muliple queue.
Signed-off-by: Gonglei <address@hidden>
---
crypto/crypto.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++
include/crypto/crypto.h | 29 +++++++++++++++++++
2 files changed, 103 insertions(+)
diff --git a/crypto/crypto.c b/crypto/crypto.c
index a0e4a34..3f760fd 100644
--- a/crypto/crypto.c
+++ b/crypto/crypto.c
@@ -197,3 +197,77 @@ int qemu_send_crypto_packet_async(CryptoClientState
*sender,
return qemu_crypto_queue_send(queue, flags, sender,
opaque, sent_cb);
}
+
+CryptoLegacyHWState *
+qemu_new_crypto_legacy_hw(CryptoClientInfo *info,
+ CryptoLegacyHWConf *conf,
+ const char *model,
+ const char *name,
+ void *opaque)
+{
+ CryptoLegacyHWState *crypto;
+ CryptoClientState **peers = conf->peers.ccs;
+ int i, queues = MAX(1, conf->peers.queues);
+
+ assert(info->type == CRYPTO_CLIENT_OPTIONS_KIND_LEGACY_HW);
+ assert(info->size >= sizeof(CryptoLegacyHWState));
+
+ crypto = g_malloc0(info->size + sizeof(CryptoClientState) * queues);
+ crypto->ccs = (void *)crypto + info->size;
+ crypto->opaque = opaque;
+ crypto->conf = conf;
+
+ for (i = 0; i < queues; i++) {
+ crypto_client_setup(&crypto->ccs[i], info, peers[i], model, name,
+ NULL);
+ crypto->ccs[i].queue_index = i;
+ crypto->ccs[i].ready = true;
+ }
+
+ return crypto;
+}
+
+static void qemu_cleanup_crypto_client(CryptoClientState *cc)
+{
+ QTAILQ_REMOVE(&crypto_clients, cc, next);
+
+ if (cc->info->cleanup) {
+ cc->info->cleanup(cc);
+ }
+}
+
+static void qemu_free_crypto_client(CryptoClientState *cc)
+{
+ if (cc->incoming_queue) {
+ qemu_del_crypto_queue(cc->incoming_queue);
+ }
+ if (cc->peer) {
+ cc->peer->peer = NULL;
+ }
+ g_free(cc->model);
+ g_free(cc->name);
+
+ if (cc->destructor) {
+ cc->destructor(cc);
+ }
+}
+
+CryptoClientState *
+qemu_get_crypto_subqueue(CryptoLegacyHWState *crypto, int queue_index)
+{
+ return crypto->ccs + queue_index;
+}
+
+void qemu_del_crypto_legacy_hw(CryptoLegacyHWState *crypto)
+{
+ int i, queues = MAX(crypto->conf->peers.queues, 1);
+
+ for (i = queues - 1; i >= 0; i--) {
+ CryptoClientState *cc = qemu_get_crypto_subqueue(crypto, i);
+
+ qemu_cleanup_crypto_client(cc);
+ qemu_free_crypto_client(cc);
+ }
+
+ g_free(crypto);
+}
diff --git a/include/crypto/crypto.h b/include/crypto/crypto.h
index 94cfc9f..0bb7d73 100644
--- a/include/crypto/crypto.h
+++ b/include/crypto/crypto.h
@@ -32,6 +32,7 @@
#include "qapi-types.h"
#include "crypto/crypto-queue.h"
+#define MAX_CRYPTO_QUEUE_NUM 64
typedef void (CryptoPoll)(CryptoClientState *, bool);
typedef void (CryptoCleanup) (CryptoClientState *);
@@ -60,6 +61,24 @@ struct CryptoClientState {
CryptoClientDestructor *destructor;
};
+/* qdev crypto legacy hardware properties */
+
+typedef struct CryptoLegacyHWPeers {
+ CryptoClientState *ccs[MAX_CRYPTO_QUEUE_NUM];
+ int32_t queues;
+} CryptoLegacyHWPeers;
+
+typedef struct CryptoLegacyHWConf {
+ CryptoLegacyHWPeers peers;
+} CryptoLegacyHWConf;
+
+typedef struct CryptoLegacyHWState {
+ CryptoClientState *ccs;
+ void *opaque;
+ CryptoLegacyHWConf *conf;
+ bool peer_deleted;
+} CryptoLegacyHWState;
+
int crypto_client_init(QemuOpts *opts, Error **errp);
int crypto_init_clients(void);
@@ -75,5 +94,15 @@ int qemu_send_crypto_packet_async(CryptoClientState *sender,
unsigned flags,
void *opaque,
CryptoPacketSent *sent_cb);
+CryptoLegacyHWState *
+qemu_new_crypto_legacy_hw(CryptoClientInfo *info,
+ CryptoLegacyHWConf *conf,
+ const char *model,
+ const char *name,
+ void *opaque);
+void qemu_del_crypto_legacy_hw(CryptoLegacyHWState *crypto);
+
+CryptoClientState *
+qemu_get_crypto_subqueue(CryptoLegacyHWState *crypto, int queue_index);
#endif /* QCRYPTO_CRYPTO_H__ */
--
1.7.12.4
- [Qemu-devel] [PATCH v1 00/14] virtio-crypto: introduce framework and device emulation, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 06/14] crypto: add internal handle logic layer, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 01/14] crypto: introduce cryptodev backend and crypto legacy hardware, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 03/14] crypto: add cryptoLegacyHW stuff,
Gonglei <=
- [Qemu-devel] [PATCH v1 12/14] virtio-crypto: add destroy session logic, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 05/14] crypto: add cryptodev-linux as a cryptodev backend, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 07/14] virtio-crypto: introduce virtio-crypto.h, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 14/14] virtio-crypto: add data virtqueue processing handler, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 13/14] virtio-crypto: get correct input data address for each request, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 10/14] virtio-crypto: set capacity of crypto legacy hardware, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 11/14] virtio-crypto: add control queue handler, Gonglei, 2016/09/07
- [Qemu-devel] [PATCH v1 09/14] virtio-crypto: add virtio crypto realization modle, Gonglei, 2016/09/07