diff mbox

[v2,10/15] virtio-crypto: set capacity of crypto legacy hardware

Message ID 1473738741-220600-11-git-send-email-arei.gonglei@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gonglei (Arei) Sept. 13, 2016, 3:52 a.m. UTC
Set the crypto legacy hardware's capacity according to the
backend peer cryptodev's capacity. We only support only one
queue at present.

Virtio crypto device is a kind of crypto legacy hardware.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 crypto/crypto.c           | 17 +++++++++++++++++
 hw/virtio/virtio-crypto.c | 18 +++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/crypto/crypto.c b/crypto/crypto.c
index 184f837..ba99d7c 100644
--- a/crypto/crypto.c
+++ b/crypto/crypto.c
@@ -228,6 +228,7 @@  qemu_new_crypto_legacy_hw(CryptoClientInfo *info,
     CryptoLegacyHWState *crypto;
     CryptoClientState **peers = conf->peers.ccs;
     int i, queues = MAX(1, conf->peers.queues);
+    int has_set = 0;
 
     assert(info->type == CRYPTO_CLIENT_OPTIONS_KIND_LEGACY_HW);
     assert(info->size >= sizeof(CryptoLegacyHWState));
@@ -242,6 +243,22 @@  qemu_new_crypto_legacy_hw(CryptoClientInfo *info,
                               NULL);
         crypto->ccs[i].queue_index = i;
         crypto->ccs[i].ready = true;
+        /* The mask bits of crypto_services and algos in
+           CryptoLegacyHWConf is set only once */
+        if (has_set == 0 && peers[i]) {
+            conf->crypto_services = peers[i]->crypto_services;
+            conf->cipher_algo_l = peers[i]->cipher_algo_l;
+            conf->cipher_algo_h = peers[i]->cipher_algo_h;
+            conf->hash_algo = peers[i]->hash_algo;
+            conf->mac_algo_l = peers[i]->mac_algo_l;
+            conf->mac_algo_h = peers[i]->mac_algo_h;
+            conf->asym_algo = peers[i]->asym_algo;
+            conf->kdf_algo = peers[i]->kdf_algo;
+            conf->aead_algo = peers[i]->aead_algo;
+            conf->primitive_algo = peers[i]->primitive_algo;
+
+            has_set = 1;
+        }
     }
 
     return crypto;
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 23c5041..b5a108f 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -197,7 +197,23 @@  static Property virtio_crypto_properties[] = {
 
 static void virtio_crypto_get_config(VirtIODevice *vdev, uint8_t *config)
 {
-
+    VirtIOCrypto *c = VIRTIO_CRYPTO(vdev);
+    struct virtio_crypto_config crypto_cfg;
+
+    crypto_cfg.status = c->status;
+    crypto_cfg.max_dataqueues = c->max_queues;
+    crypto_cfg.crypto_services = c->legacy_conf.crypto_services;
+    crypto_cfg.cipher_algo_l = c->legacy_conf.cipher_algo_l;
+    crypto_cfg.cipher_algo_h = c->legacy_conf.cipher_algo_h;
+    crypto_cfg.hash_algo = c->legacy_conf.hash_algo;
+    crypto_cfg.mac_algo_l = c->legacy_conf.mac_algo_l;
+    crypto_cfg.mac_algo_h = c->legacy_conf.mac_algo_h;
+    crypto_cfg.asym_algo = c->legacy_conf.asym_algo;
+    crypto_cfg.kdf_algo = c->legacy_conf.kdf_algo;
+    crypto_cfg.aead_algo = c->legacy_conf.aead_algo;
+    crypto_cfg.primitive_algo = c->legacy_conf.primitive_algo;
+
+    memcpy(config, &crypto_cfg, c->config_size;
 }
 
 static void virtio_crypto_set_config(VirtIODevice *vdev, const uint8_t *config)