From patchwork Mon Apr 22 14:31:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 790964 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp2390912wrm; Mon, 22 Apr 2024 07:31:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUwg8R9JfDtTtRzSE5/Sj+3l+t8ZHb4/qOL9pqwuMXatR/VzoUAijFHcO7teA28pmDtl4F23FQolGOq4pzJjWtd X-Google-Smtp-Source: AGHT+IGCtYWpv99OFBxXxCl9NHfutp/bPlyxRn+ckjFD6KclS4VyoVccIam7HPbAudlgVxExqsB4 X-Received: by 2002:a05:651c:223:b0:2d6:f7d4:a393 with SMTP id z3-20020a05651c022300b002d6f7d4a393mr5711514ljn.9.1713796292601; Mon, 22 Apr 2024 07:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713796292; cv=none; d=google.com; s=arc-20160816; b=wg7JZSEMsI4kVBdDEmYYqtALaf27mQ+6la5TAvdU3PZKPrSvAST4LINGxFXPJ9m3YT Vy02hNg4POyXbhxM2XoaHYrXgRO+45lC9hdYXRirVFrdSDm7El2gtEZPcEh2Qlwcbtk+ QTQWHda2QQBPldUFcxDz7Jx5rQSEyYC9b7aBOg6o/PBxoZ8itW7h8D4usry2KmWb3j/p LB4ZC+HO0LpmT2FS32Zo7zljj8sLAtzrUKdXfPJMlMw+N3vM91uaF8MsjkxSpgvRbph2 vCeo6Ok33NrWZFpVgZlMpt1ieH7Eudx4DWZ6sYYu9ifLtg6b0eITOwHiPLLowtKo6Cxg jXbA== 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=wSOE5wNtNhcmzGDyBKj5myVPivsEg4c2BjxALL+8p8M=; fh=N6ystvY2g7QTpz2QKkAMt/Nu9xETjtRlVAZxgmiIO6M=; b=Nb6IT9NNCnlXHfzJEc59OnxiBuANR6PO2/Z9IOJUKtvD07puMDXanFTHlC2X8XYb8u 1lI5Fn0bwLliIomHHtpTAGn2bymBdMyvS4YfjbuUadQ/5+se5X5GvjkhCvx12mIC2nzB bjQ5JM2mrLrYbxP7DW5v0dObhH1kdaVW71xFAcoYdvK3+lJMDd0MdGLtvBdbyqB4K+LX /8jg/ZtWjRKu77V8DOW2jS7o8F4UZStGv6KHU+vRgrvfebwiA3tdyXpX872qQSyGJoHO Iy9Ge0Ajd3JG4y+puLzI9RMHVPoCcJmw0f9DQJ+efBlOd/ePDz1xFLyLk/FDMV1wu75/ tTsA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XMyRwOJH; 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 b7-20020a05600c4e0700b0041a77b2ce19si730872wmq.5.2024.04.22.07.31.32; Mon, 22 Apr 2024 07:31: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=XMyRwOJH; 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 mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36C9B40633; Mon, 22 Apr 2024 16:31:23 +0200 (CEST) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by mails.dpdk.org (Postfix) with ESMTP id 2B888402F0 for ; Mon, 22 Apr 2024 16:31:21 +0200 (CEST) Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5c66b093b86so3810492a12.0 for ; Mon, 22 Apr 2024 07:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713796280; x=1714401080; darn=dpdk.org; 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=wSOE5wNtNhcmzGDyBKj5myVPivsEg4c2BjxALL+8p8M=; b=XMyRwOJHnxS68dR2TszNbuxTjT1nn6eFtHQKOC3l08YjQ1LNgBappnhbXxIiDqPv4r Qzs7s+VUyBVknoLvXxsBkvd2iUIbLsN6rpaHPOV8FoMxXWfQCO+QLj/pVrXgnpOIYJEz 9EMf12biXsApKbOJXSTDalhj6P1HcwKFTmYwL3unI1pzlvttVSf7Wyr3jwGdZEUoXEDQ sF1zzWnNhAwmqupROHRky/pan1LPOv58AY8wmRPUJQVYRTpGBfmlxn/N1AUzgbjX3o/D cDJLDrVoiksXaxeBSVDhu9QWNzZWwmNbRZit4qL5b9Ah8LozQwiRJB47JU8OEWZuq+qU pWDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713796280; x=1714401080; 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=wSOE5wNtNhcmzGDyBKj5myVPivsEg4c2BjxALL+8p8M=; b=cwIaUQFoqTgylN1hJTIbN+HYkDxqoTzrRiganmFWG7fx2vWAOa7sSLXlHQPeZWs5d2 fBKdqmKQK2CuVjtlJyPdBMsc/aYnchj5CoFUcTJgXVG/YG6opi/CxBP40T9Dkds2xKm9 stdF00c5gcVTmcmVInctI9A4xiVFnGQIzoAogLjN3N9dHlfLHOd/VmMIP+Ve2mdELmjs FSlPEu/owcb0fYt7APOfSKp6L6ig9oJQhmnTWq9Z+P+Pevt2iCSIWmAKuw8XtFuarQBi YSaHhpn8ZkVLeqvmfxqjvKwZ2Ot99AiTyBwWZBC+8tfwGfKq4WK3larptXFJqCPLg7LM 5r/w== X-Gm-Message-State: AOJu0Yw9+DpfGbW6p1X882cDmHpjeudoSN5XvltSA8fLgElNaXW1n/gk revWCiByaDbn3Bm6AJMhUUlq5BK3p91t833mVBIs8JZtm7KFczFti/qO7OnHisM= X-Received: by 2002:a17:90a:2ca5:b0:2a2:6244:32b5 with SMTP id n34-20020a17090a2ca500b002a2624432b5mr13952678pjd.11.1713796280319; Mon, 22 Apr 2024 07:31:20 -0700 (PDT) Received: from localhost.localdomain ([121.37.54.139]) by smtp.gmail.com with ESMTPSA id v17-20020a17090ad59100b0029c19285192sm9481284pju.44.2024.04.22.07.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 07:31:19 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Fan Zhang , Ashish Gupta Cc: dev@dpdk.org, Zhangfei Gao Subject: [PATCH 2/3] compress/uadk: support basic operations Date: Mon, 22 Apr 2024 14:31:01 +0000 Message-Id: <20240422143102.251-3-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240422143102.251-1-zhangfei.gao@linaro.org> References: <20240422143102.251-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, infos_get, and queue pairs operations, etc. Signed-off-by: Zhangfei Gao --- drivers/compress/uadk/uadk_compress_pmd.c | 325 +++++++++++++++++- .../compress/uadk/uadk_compress_pmd_private.h | 16 + 2 files changed, 330 insertions(+), 11 deletions(-) diff --git a/drivers/compress/uadk/uadk_compress_pmd.c b/drivers/compress/uadk/uadk_compress_pmd.c index d73524ce84..25858855e6 100644 --- a/drivers/compress/uadk/uadk_compress_pmd.c +++ b/drivers/compress/uadk/uadk_compress_pmd.c @@ -12,18 +12,321 @@ #include "uadk_compress_pmd_private.h" +static const struct +rte_compressdev_capabilities uadk_compress_pmd_capabilities[] = { + { /* Deflate */ + .algo = RTE_COMP_ALGO_DEFLATE, + .comp_feature_flags = RTE_COMP_FF_SHAREABLE_PRIV_XFORM | + RTE_COMP_FF_HUFFMAN_FIXED | + RTE_COMP_FF_HUFFMAN_DYNAMIC, + }, + + RTE_COMP_END_OF_CAPABILITIES_LIST() +}; + +static int +uadk_compress_pmd_config(struct rte_compressdev *dev, + struct rte_compressdev_config *config) +{ + char mp_name[RTE_MEMPOOL_NAMESIZE]; + struct uadk_compress_priv *priv; + struct rte_mempool *mp; + int ret; + + if (dev == NULL || config == NULL) + return -EINVAL; + + snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, + "stream_mp_%u", dev->data->dev_id); + priv = dev->data->dev_private; + + /* alloc resources */ + ret = wd_comp_env_init(NULL); + if (ret < 0) + return -EINVAL; + + mp = priv->mp; + if (mp == NULL) { + mp = rte_mempool_create(mp_name, + config->max_nb_priv_xforms + + config->max_nb_streams, + sizeof(struct uadk_stream), + 0, 0, NULL, NULL, NULL, + NULL, config->socket_id, 0); + if (mp == NULL) { + UADK_LOG(ERR, "Cannot create private xform pool on socket %d\n", + config->socket_id); + ret = -ENOMEM; + goto err_mempool; + } + priv->mp = mp; + } + + return 0; + +err_mempool: + wd_comp_env_uninit(); + return ret; +} + +static int +uadk_compress_pmd_start(struct rte_compressdev *dev __rte_unused) +{ + return 0; +} + +static void +uadk_compress_pmd_stop(struct rte_compressdev *dev __rte_unused) +{ +} + +static int +uadk_compress_pmd_close(struct rte_compressdev *dev) +{ + struct uadk_compress_priv *priv = + (struct uadk_compress_priv *)dev->data->dev_private; + + /* free resources */ + rte_mempool_free(priv->mp); + priv->mp = NULL; + wd_comp_env_uninit(); + + return 0; +} + +static void +uadk_compress_pmd_stats_get(struct rte_compressdev *dev, + struct rte_compressdev_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; + } +} + +static void +uadk_compress_pmd_stats_reset(struct rte_compressdev *dev) +{ + 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)); + } +} + +static void +uadk_compress_pmd_info_get(struct rte_compressdev *dev, + struct rte_compressdev_info *dev_info) +{ + if (dev_info != NULL) { + dev_info->driver_name = dev->device->driver->name; + dev_info->feature_flags = dev->feature_flags; + dev_info->capabilities = uadk_compress_pmd_capabilities; + } +} + +static int +uadk_compress_pmd_qp_release(struct rte_compressdev *dev, uint16_t qp_id) +{ + struct uadk_qp *qp = dev->data->queue_pairs[qp_id]; + + if (qp != NULL) { + rte_ring_free(qp->processed_pkts); + rte_free(qp); + dev->data->queue_pairs[qp_id] = NULL; + } + + return 0; +} + +static int +uadk_pmd_qp_set_unique_name(struct rte_compressdev *dev, + struct uadk_qp *qp) +{ + unsigned int n = snprintf(qp->name, sizeof(qp->name), + "uadk_pmd_%u_qp_%u", + dev->data->dev_id, qp->id); + + if (n >= sizeof(qp->name)) + return -EINVAL; + + return 0; +} + +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_compress_pmd_qp_setup(struct rte_compressdev *dev, uint16_t qp_id, + uint32_t max_inflight_ops, int socket_id) +{ + struct uadk_qp *qp = NULL; + + /* Free memory prior to re-allocation if needed. */ + if (dev->data->queue_pairs[qp_id] != NULL) + uadk_compress_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, + max_inflight_ops, 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 int +uadk_compress_pmd_xform_create(struct rte_compressdev *dev, + const struct rte_comp_xform *xform, + void **private_xform) +{ + struct uadk_compress_priv *priv = dev->data->dev_private; + struct wd_comp_sess_setup setup = {0}; + struct sched_params param = {0}; + struct uadk_stream *stream; + handle_t handle; + + if (xform == NULL) { + UADK_LOG(ERR, "invalid xform struct"); + return -EINVAL; + } + + if (rte_mempool_get(priv->mp, private_xform)) { + UADK_LOG(ERR, "Couldn't get object from session mempool"); + return -ENOMEM; + } + + stream = *((struct uadk_stream **)private_xform); + + switch (xform->type) { + case RTE_COMP_COMPRESS: + switch (xform->compress.algo) { + case RTE_COMP_ALGO_NULL: + break; + case RTE_COMP_ALGO_DEFLATE: + setup.alg_type = WD_DEFLATE; + setup.win_sz = WD_COMP_WS_8K; + setup.comp_lv = WD_COMP_L8; + setup.op_type = WD_DIR_COMPRESS; + param.type = setup.op_type; + param.numa_id = -1; /* choose nearby numa node */ + setup.sched_param = ¶m; + break; + default: + goto err; + } + break; + case RTE_COMP_DECOMPRESS: + switch (xform->decompress.algo) { + case RTE_COMP_ALGO_NULL: + break; + case RTE_COMP_ALGO_DEFLATE: + setup.alg_type = WD_DEFLATE; + setup.comp_lv = WD_COMP_L8; + setup.op_type = WD_DIR_DECOMPRESS; + param.type = setup.op_type; + param.numa_id = -1; /* choose nearby numa node */ + setup.sched_param = ¶m; + break; + default: + goto err; + } + break; + default: + UADK_LOG(ERR, "Algorithm %u is not supported.", xform->type); + goto err; + } + + handle = wd_comp_alloc_sess(&setup); + if (!handle) + goto err; + + stream->handle = handle; + stream->type = xform->type; + + return 0; + +err: + rte_mempool_put(priv->mp, private_xform); + return -EINVAL; +} + +static int +uadk_compress_pmd_xform_free(struct rte_compressdev *dev __rte_unused, void *private_xform) +{ + struct uadk_stream *stream = (struct uadk_stream *)private_xform; + struct rte_mempool *mp; + + if (!stream) + return -EINVAL; + + wd_comp_free_sess(stream->handle); + memset(stream, 0, sizeof(struct uadk_stream)); + mp = rte_mempool_from_obj(stream); + rte_mempool_put(mp, stream); + + return 0; +} + static struct rte_compressdev_ops uadk_compress_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, - .private_xform_create = NULL, - .private_xform_free = NULL, + .dev_configure = uadk_compress_pmd_config, + .dev_start = uadk_compress_pmd_start, + .dev_stop = uadk_compress_pmd_stop, + .dev_close = uadk_compress_pmd_close, + .stats_get = uadk_compress_pmd_stats_get, + .stats_reset = uadk_compress_pmd_stats_reset, + .dev_infos_get = uadk_compress_pmd_info_get, + .queue_pair_setup = uadk_compress_pmd_qp_setup, + .queue_pair_release = uadk_compress_pmd_qp_release, + .private_xform_create = uadk_compress_pmd_xform_create, + .private_xform_free = uadk_compress_pmd_xform_free, .stream_create = NULL, .stream_free = NULL, }; diff --git a/drivers/compress/uadk/uadk_compress_pmd_private.h b/drivers/compress/uadk/uadk_compress_pmd_private.h index a96aea7c73..97a921316e 100644 --- a/drivers/compress/uadk/uadk_compress_pmd_private.h +++ b/drivers/compress/uadk/uadk_compress_pmd_private.h @@ -10,6 +10,22 @@ struct uadk_compress_priv { struct rte_mempool *mp; }; +struct __rte_cache_aligned uadk_qp { + /* Ring for placing process packets */ + struct rte_ring *processed_pkts; + /* Queue pair statistics */ + struct rte_compressdev_stats qp_stats; + /* Queue Pair Identifier */ + uint16_t id; + /* Unique Queue Pair Name */ + char name[RTE_COMPRESSDEV_NAME_MAX_LEN]; +}; + +struct __rte_cache_aligned uadk_stream { + handle_t handle; + enum rte_comp_xform_type type; +}; + extern int uadk_compress_logtype; #define UADK_LOG(level, fmt, ...) \