From patchwork Wed Oct 26 10:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 618809 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp317123pvb; Wed, 26 Oct 2022 04:01:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Dg9UOuXYRghy9yfFNAvdbPCEHlH2IcMtTrDYCJK19s9Pedf5o+v7i6Qla9aA08jWmLVjd X-Received: by 2002:a05:600c:548a:b0:3c6:dd03:2d31 with SMTP id iv10-20020a05600c548a00b003c6dd032d31mr2007086wmb.95.1666782092410; Wed, 26 Oct 2022 04:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666782092; cv=none; d=google.com; s=arc-20160816; b=mQnPvC4RDn8H5k0fa4DsAzjbBQ/9jCoRnycr3MtYlNhMO81qEH2k65rQSn67fQRXXc vPxKZsnqUIEBtxdSHixta4PsvvrUFQ0QMe9jJQzVKRbnBP2DYBxaE0U/8JN6xX3swKBI /udWCDf0oeFaq+XGOuVlwa+gMHBzBF0gVrrndykx87OZ2tQXiDyG7rq0XZQL+hVq+IzD SLJdpvkhTEojZovciVTji6qfLyBZMGGYLQnbqH3jt8z57C2w68P9NPO2xKJCPm4F/rG2 kHi/JEUP6wa9Hak81HsCMPuJE8M8DlIX93kmew8m+3VisDZLPKC6rjhS7Aqwf4Wfc+go UXxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3dWeuK1LQWnCrDceoCT+coyKRdO+N1O756x/1vJeQaQ=; b=MGzStkulEGDKzbikSUl6a8wmLOXLU2MxQApZ7GmokwJgjROfdL6qZwYrCcAz3Ty6aD Rk6aV/TkvqPrr/4bsE2GvLzk+21q/Ae0yXtJ3Wp3hDXWkJBAadC+vyw3gPgDGXfmSPdt rWLrr9GdxDHdLee2zoNcXW2rs7hWiM75kHfVFz1nPJGZMC0dT3/UupQdANTD7633+Ywz QJwlt7qULVggrFI3Vu4CZJbhmf0R1/CMxKTFaPosVqUu2IWb7JmgKFfg11mbWruk7O3X Q0CYOLysRmhIhWZQVq+SB3xWRRoaIFx+S/ocC5y+7cSyCim2iVQtRqHrOvxiC6fTfPnU 8jUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gLvEJxfr; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id s18-20020adfeb12000000b0022e5dcfe79csi3418957wrn.179.2022.10.26.04.01.32; Wed, 26 Oct 2022 04:01:32 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gLvEJxfr; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3EC0742B8E; Wed, 26 Oct 2022 13:01:23 +0200 (CEST) Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by mails.dpdk.org (Postfix) with ESMTP id 3E3BF40041 for ; Wed, 26 Oct 2022 13:01:19 +0200 (CEST) Received: by mail-wm1-f53.google.com with SMTP id t4so9896352wmj.5 for ; Wed, 26 Oct 2022 04:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3dWeuK1LQWnCrDceoCT+coyKRdO+N1O756x/1vJeQaQ=; b=gLvEJxfr3Eo4bYExAfSTQaWHJiIodlpbZFkuo8mjziOOI2HhyetTXt6fGfEFFivFqt vaJW7anYWV56x2z4KI+CBZcT2+5U3GmmDtkH1JCiuN4EL/0qadci6Vl5/JxruS85Gjiw 4RHX8eeYAUNr7AQfL2vgtYhWnnjwCmlLGb/p2X31gsBqKUjLnZ6uy270h1bPB+ZjKYyl EURBQT/NsEIr2yKnxBxlSFimtpVSzvKMohI5n/FSMSxOGCH5tOnR+/f6/U03BANTKkRU G2i+VuGSP76BDDFHyYL3LQd2o5TTT47w0Fh8IbbHacUWCivHfGGYrAckVGLfYxhE0fQ5 YxHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3dWeuK1LQWnCrDceoCT+coyKRdO+N1O756x/1vJeQaQ=; b=Vc+J/BpQtGnffBdlfsgb/OaN+F9k/pC8Uy32XBjy4aj7hUZZSvLGPOGO9viPVi3xAB /HAo0S6/8tfGZusrmaKNcQoV1oXKGH+k8FY36+4SQR3MOuzXbsykVJ9ImDG44mYN1teL XZKdhNGmK5SYEFcFphGu7klAFIw8XFQpMYRX0M1gduCThoK/+DnvnA8d7C4o96XrQNK9 qben6II0cMJLKtXCiJpV2zzIqbc1v+o716MYClFILd7+gIillmuxCi6Wk1IDCMUYdO/j f+5qkqTFegnLhW/01yQXFFiRTekXNyI2WX5SHHbKGkFh5TJF7PVmMrVntAjROWuaeE07 /jIA== X-Gm-Message-State: ACrzQf0SQnXJC7qWU5hX6yp9IYbWXoaYIMvDwQN6JsTP6ctP74n99KJL hsTdh32Zgop1DH46YwXnEXgFfA== X-Received: by 2002:a05:600c:4ed0:b0:3cd:3422:62d8 with SMTP id g16-20020a05600c4ed000b003cd342262d8mr1990745wmq.154.1666782078867; Wed, 26 Oct 2022 04:01:18 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id h14-20020a5d688e000000b0023660f6cecfsm4856094wru.80.2022.10.26.04.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:01:18 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella , "thomas@monjalon.net" Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v6 2/6] crypto/uadk: support basic operations Date: Wed, 26 Oct 2022 18:54:25 +0800 Message-Id: <20221026105429.1899867-3-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026105429.1899867-1-zhangfei.gao@linaro.org> References: <20221026105429.1899867-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Support the basic dev control operations: configure, close, start, stop and get info, as well as queue pairs operations. Signed-off-by: Zhangfei Gao --- drivers/crypto/uadk/uadk_crypto_pmd.c | 194 +++++++++++++++++- drivers/crypto/uadk/uadk_crypto_pmd_private.h | 19 ++ 2 files changed, 204 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/uadk/uadk_crypto_pmd.c b/drivers/crypto/uadk/uadk_crypto_pmd.c index 34df3ccbb9..b383029a45 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd.c +++ b/drivers/crypto/uadk/uadk_crypto_pmd.c @@ -17,16 +17,192 @@ static uint8_t uadk_cryptodev_driver_id; +static const struct rte_cryptodev_capabilities uadk_crypto_v2_capabilities[] = { + /* End of capabilities */ + RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() +}; + +/* Configure device */ +static int +uadk_crypto_pmd_config(struct rte_cryptodev *dev __rte_unused, + struct rte_cryptodev_config *config __rte_unused) +{ + return 0; +} + +/* Start device */ +static int +uadk_crypto_pmd_start(struct rte_cryptodev *dev __rte_unused) +{ + return 0; +} + +/* Stop device */ +static void +uadk_crypto_pmd_stop(struct rte_cryptodev *dev __rte_unused) +{ +} + +/* Close device */ +static int +uadk_crypto_pmd_close(struct rte_cryptodev *dev __rte_unused) +{ + return 0; +} + +/* Get device statistics */ +static void +uadk_crypto_pmd_stats_get(struct rte_cryptodev *dev, + struct rte_cryptodev_stats *stats) +{ + int qp_id; + + for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { + struct uadk_qp *qp = dev->data->queue_pairs[qp_id]; + + stats->enqueued_count += qp->qp_stats.enqueued_count; + stats->dequeued_count += qp->qp_stats.dequeued_count; + stats->enqueue_err_count += qp->qp_stats.enqueue_err_count; + stats->dequeue_err_count += qp->qp_stats.dequeue_err_count; + } +} + +/* Reset device statistics */ +static void +uadk_crypto_pmd_stats_reset(struct rte_cryptodev *dev __rte_unused) +{ + int qp_id; + + for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { + struct uadk_qp *qp = dev->data->queue_pairs[qp_id]; + + memset(&qp->qp_stats, 0, sizeof(qp->qp_stats)); + } +} + +/* Get device info */ +static void +uadk_crypto_pmd_info_get(struct rte_cryptodev *dev, + struct rte_cryptodev_info *dev_info) +{ + struct uadk_crypto_priv *priv = dev->data->dev_private; + + if (dev_info != NULL) { + dev_info->driver_id = dev->driver_id; + dev_info->driver_name = dev->device->driver->name; + dev_info->max_nb_queue_pairs = 128; + /* No limit of number of sessions */ + dev_info->sym.max_nb_sessions = 0; + dev_info->feature_flags = dev->feature_flags; + + if (priv->version == UADK_CRYPTO_V2) + dev_info->capabilities = uadk_crypto_v2_capabilities; + } +} + +/* Release queue pair */ +static int +uadk_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id) +{ + struct uadk_qp *qp = dev->data->queue_pairs[qp_id]; + + if (qp) { + rte_ring_free(qp->processed_pkts); + rte_free(qp); + dev->data->queue_pairs[qp_id] = NULL; + } + + return 0; +} + +/* set a unique name for the queue pair based on its name, dev_id and qp_id */ +static int +uadk_pmd_qp_set_unique_name(struct rte_cryptodev *dev, + struct uadk_qp *qp) +{ + unsigned int n = snprintf(qp->name, sizeof(qp->name), + "uadk_crypto_pmd_%u_qp_%u", + dev->data->dev_id, qp->id); + + if (n >= sizeof(qp->name)) + return -EINVAL; + + return 0; +} + +/* Create a ring to place process packets on */ +static struct rte_ring * +uadk_pmd_qp_create_processed_pkts_ring(struct uadk_qp *qp, + unsigned int ring_size, int socket_id) +{ + struct rte_ring *r = qp->processed_pkts; + + if (r) { + if (rte_ring_get_size(r) >= ring_size) { + UADK_LOG(INFO, "Reusing existing ring %s for processed packets", + qp->name); + return r; + } + + UADK_LOG(ERR, "Unable to reuse existing ring %s for processed packets", + qp->name); + return NULL; + } + + return rte_ring_create(qp->name, ring_size, socket_id, + RING_F_EXACT_SZ); +} + +static int +uadk_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id, + const struct rte_cryptodev_qp_conf *qp_conf, + int socket_id) +{ + struct uadk_qp *qp; + + /* Free memory prior to re-allocation if needed. */ + if (dev->data->queue_pairs[qp_id] != NULL) + uadk_crypto_pmd_qp_release(dev, qp_id); + + /* Allocate the queue pair data structure. */ + qp = rte_zmalloc_socket("uadk PMD Queue Pair", sizeof(*qp), + RTE_CACHE_LINE_SIZE, socket_id); + if (qp == NULL) + return (-ENOMEM); + + qp->id = qp_id; + dev->data->queue_pairs[qp_id] = qp; + + if (uadk_pmd_qp_set_unique_name(dev, qp)) + goto qp_setup_cleanup; + + qp->processed_pkts = uadk_pmd_qp_create_processed_pkts_ring(qp, + qp_conf->nb_descriptors, socket_id); + if (qp->processed_pkts == NULL) + goto qp_setup_cleanup; + + memset(&qp->qp_stats, 0, sizeof(qp->qp_stats)); + + return 0; + +qp_setup_cleanup: + if (qp) { + rte_free(qp); + qp = NULL; + } + return -EINVAL; +} + static struct rte_cryptodev_ops uadk_crypto_pmd_ops = { - .dev_configure = NULL, - .dev_start = NULL, - .dev_stop = NULL, - .dev_close = NULL, - .stats_get = NULL, - .stats_reset = NULL, - .dev_infos_get = NULL, - .queue_pair_setup = NULL, - .queue_pair_release = NULL, + .dev_configure = uadk_crypto_pmd_config, + .dev_start = uadk_crypto_pmd_start, + .dev_stop = uadk_crypto_pmd_stop, + .dev_close = uadk_crypto_pmd_close, + .stats_get = uadk_crypto_pmd_stats_get, + .stats_reset = uadk_crypto_pmd_stats_reset, + .dev_infos_get = uadk_crypto_pmd_info_get, + .queue_pair_setup = uadk_crypto_pmd_qp_setup, + .queue_pair_release = uadk_crypto_pmd_qp_release, .sym_session_get_size = NULL, .sym_session_configure = NULL, .sym_session_clear = NULL, diff --git a/drivers/crypto/uadk/uadk_crypto_pmd_private.h b/drivers/crypto/uadk/uadk_crypto_pmd_private.h index c4090f6119..3060583b54 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd_private.h +++ b/drivers/crypto/uadk/uadk_crypto_pmd_private.h @@ -6,6 +6,25 @@ #ifndef _UADK_CRYPTO_PMD_PRIVATE_H_ #define _UADK_CRYPTO_PMD_PRIVATE_H_ +/* Maximum length for digest (SHA-512 needs 64 bytes) */ +#define DIGEST_LENGTH_MAX 64 + +struct uadk_qp { + /* Ring for placing process packets */ + struct rte_ring *processed_pkts; + /* Queue pair statistics */ + struct rte_cryptodev_stats qp_stats; + /* Queue Pair Identifier */ + uint16_t id; + /* Unique Queue Pair Name */ + char name[RTE_CRYPTODEV_NAME_MAX_LEN]; + /* Buffer used to store the digest generated + * by the driver when verifying a digest provided + * by the user (using authentication verify operation) + */ + uint8_t temp_digest[DIGEST_LENGTH_MAX]; +} __rte_cache_aligned; + enum uadk_crypto_version { UADK_CRYPTO_V2, UADK_CRYPTO_V3,