From patchwork Thu Sep 8 03:42:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9320339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 37CDD60231 for ; Thu, 8 Sep 2016 03:44:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2294529552 for ; Thu, 8 Sep 2016 03:44:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16EC629554; Thu, 8 Sep 2016 03:44:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 408F929552 for ; Thu, 8 Sep 2016 03:44:14 +0000 (UTC) Received: from localhost ([::1]:44740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqG5-00021r-D5 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Sep 2016 23:44:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqFW-0001yI-FF for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:43:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhqFS-0005Sd-9q for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:43:37 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:16163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqFR-0005PY-BB for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:43:34 -0400 Received: from 172.24.1.47 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DMU12950; Thu, 08 Sep 2016 11:42:59 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Sep 2016 11:42:52 +0800 From: Gonglei To: , Date: Thu, 8 Sep 2016 11:42:25 +0800 Message-ID: <1473306156-176628-4-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.6.3.windows.1 In-Reply-To: <1473306156-176628-1-git-send-email-arei.gonglei@huawei.com> References: <1473306156-176628-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.57D0DE44.00D3, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: b8e4c837e42f914c2036632139c6c8ba X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Subject: [Qemu-devel] [PATCH v1 03/14] crypto: add cryptoLegacyHW stuff X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: weidong.huang@huawei.com, mst@redhat.com, john.griffin@intel.com, jianjay.zhou@huawei.com, Varun.Sethi@freescale.com, denglingli@chinamobile.com, hanweidong@huawei.com, agraf@suse.de, Gonglei , nmorey@kalray.eu, vincent.jardin@6wind.com, Ola.Liljedahl@arm.com, luonengjun@huawei.com, xin.zeng@intel.com, peter.huangpeng@huawei.com, liang.j.ma@intel.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, Jani.Kokkonen@huawei.com, brian.a.keating@intel.com, claudio.fontana@huawei.com, mike.caraman@nxp.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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__ */