[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff
From: |
Gonglei |
Subject: |
[Qemu-devel] [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff |
Date: |
Tue, 13 Sep 2016 11:52:09 +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 46b3b9e..4f0efb7 100644
--- a/include/crypto/crypto.h
+++ b/include/crypto/crypto.h
@@ -31,6 +31,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 *);
@@ -59,6 +60,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);
@@ -74,5 +93,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 v2 02/15] crypto: introduce crypto queue handler, Gonglei, 2016/09/12