From patchwork Sat Oct 8 08:37:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 613384 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp765426pvb; Sat, 8 Oct 2022 01:38:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/jTOIsLqB22ogHxbYRl+6jqLEZDdp7UIxGYmPKV1IWIVqr4rM2TwtsIuFlB+ZC/92G2tc X-Received: by 2002:a5d:5a05:0:b0:22e:5b81:c295 with SMTP id bq5-20020a5d5a05000000b0022e5b81c295mr5560204wrb.588.1665218337889; Sat, 08 Oct 2022 01:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665218337; cv=none; d=google.com; s=arc-20160816; b=B/6MjfXWxgpc8qGfshEHYeyGGQUyEIjDZk+kN/n/3m+JxKUAcNALSxy1HZKJQMGnr1 ClsxNSDHGYzr9YsmpM+z827kEOhGr1bA57RNAb1lmPRNkDJgfUlfXAcI9j4rep6lP2Yn 8itND4JiT1lokafJ0MfA19ZIVyBWwQnFOc27yNNO+cQt2JnzMu86EjRCa2yAZCTBDOZJ qdsKPk/tUhxs4MXhPN2M5cQjxAlNW6joGWZfNNHjcp3JaiK5O0+mkLSPRf3CexlUo4gX hlT7wc9bd2t9iW1DkITlgNsXKNF3boDNCwVVPc7I6NkuvPsukFwPvRLXSwC3l3M/b7Jj Lq0Q== 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=LX3QS7kCsI0ekLmf6HUfMpA9o/qewoy1mX3D5nebvhI=; b=EntTATJODmvyHVeovn5SeCUjjQp/qCuFtHWaW06JyTZjTlpMjD/uH+cWpSH6HBWu4C S74615u5Cm13uo5Xtv189SKEycwpHg65mJRJRzkeVXY2vRsJHZ+bM30AWBf8Y+CJU+Xn SHgdg5cxl+ypoejr2gilEeF4LwUWqYveqvGkXyQB6BpF7mCWBXiOtfDndM7C2zdbhQYr Gs6lABfuoJinzc/XTHy/PlBuE6k9JLhowUo1L1NIBI7Ebsmh8hMPtR8izPYyBdeBxMvU 6y3sb8X8jNQZJrYB9WIucDWHwCRLDWAc2Vo4nhhERcGHcX3bXN7eYbS5t8MGm0HXnbgI Y6iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXCZU1JY; 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 h10-20020a5d548a000000b00226d70e56c4si2824801wrv.416.2022.10.08.01.38.57; Sat, 08 Oct 2022 01:38:57 -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=GXCZU1JY; 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 D9D2142B84; Sat, 8 Oct 2022 10:38:55 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 11AA942B77 for ; Sat, 8 Oct 2022 10:38:55 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id b2so6427817plc.7 for ; Sat, 08 Oct 2022 01:38:54 -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=LX3QS7kCsI0ekLmf6HUfMpA9o/qewoy1mX3D5nebvhI=; b=GXCZU1JYfgWL47dUg0fxbaQ15ybQOxEvuQasE8HOmBag+4xDM5fZze5feskezfb9Z2 wcZv0VEiNw4tzzPFFeFeXZAdY8Yq3FFbdor/WraUCz2o2U+pg0Akroq0Zsh1QXm6mJVJ 06UlAzELhFYGs0h1Zw1rRMoBfuUqpvn3QAUZ9V00+T7eW3EV7UXz9Gz0EHeWcRDhSjdp O7YmVj42oIzcJZsbYLiBVa9ypxPnfnkU5MiNpcPctBL2TXB5cdZiou/Pvi0vhgYqjZ2c khSI0i9wyJ3PB7fgwZW8zGAUJPwGLWkD1uPOH2JSy6qfswqRRkZAX2Ma0YEsnLuaW+Hl vIcA== 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=LX3QS7kCsI0ekLmf6HUfMpA9o/qewoy1mX3D5nebvhI=; b=6ltNr02DNvIHKeNJTMnHcUs+DIDrpvNySJyB8VEx2d3UZgRpqZl+kORiyjBB5BvVc/ Z3rxt38h8H/uJeXszb3BTNyT0vHlsgGM+1TIN1M5E6doLKghPXfgFa3fw3Fuv/9ZWhMd +OQhqKE/0BP4ZRmdcS9dmaH9MzQmdQbKv0Oap/uI+9myp9QpJtqW9vMKcrTqrxYiQtBL 9ohvtsAEr4MR4+0WkdWyNbGOn/YGOEDe2yEHrTWPtF7imj+z3Ch+IZX0hl1Jk6Egi7b8 7Awpz9DSTZXJzWvsxxnsHdnCbtRHUzSqEyM4bkU0NKxUe+Eem01ShOj0mT4DaTDB/8U9 T8vg== X-Gm-Message-State: ACrzQf2QqmHYBSOJACpbjOptx4ErembT+GD4otW+esb/PF8n7jsamgQb yw8WZ/T2aHUUyEMXOPYjMHEOPw== X-Received: by 2002:a17:90b:1d07:b0:203:6732:e280 with SMTP id on7-20020a17090b1d0700b002036732e280mr20015284pjb.172.1665218334353; Sat, 08 Oct 2022 01:38:54 -0700 (PDT) Received: from localhost.localdomain ([194.5.48.65]) by smtp.gmail.com with ESMTPSA id n1-20020a17090a2bc100b0020a0571b354sm2644371pje.57.2022.10.08.01.38.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Oct 2022 01:38:53 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH resend v3 2/6] crypto/uadk: support basic operations Date: Sat, 8 Oct 2022 16:37:43 +0800 Message-Id: <20221008083747.6559-3-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221008083747.6559-1-zhangfei.gao@linaro.org> References: <20221008083747.6559-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 | 213 ++++++++++++++++++++++++-- 1 file changed, 204 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/uadk/uadk_crypto_pmd.c b/drivers/crypto/uadk/uadk_crypto_pmd.c index ec9bb174c7..1d1a4b2897 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd.c +++ b/drivers/crypto/uadk/uadk_crypto_pmd.c @@ -12,6 +12,25 @@ #include #include +/* 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, @@ -30,16 +49,192 @@ RTE_LOG_REGISTER_DEFAULT(uadk_crypto_logtype, INFO); "%s() line %u: " fmt "\n", __func__, __LINE__, \ ## __VA_ARGS__) +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,