1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2021 Mellanox Technologies, Ltd
5 #include <rte_malloc.h>
9 #include <rte_spinlock.h>
11 #include <rte_compressdev.h>
12 #include <rte_compressdev_pmd.h>
14 #include <mlx5_glue.h>
15 #include <mlx5_common.h>
16 #include <mlx5_common_pci.h>
17 #include <mlx5_devx_cmds.h>
18 #include <mlx5_common_os.h>
19 #include <mlx5_common_devx.h>
20 #include <mlx5_common_mr.h>
23 #include "mlx5_compress_utils.h"
25 #define MLX5_COMPRESS_DRIVER_NAME mlx5_compress
26 #define MLX5_COMPRESS_LOG_NAME pmd.compress.mlx5
27 #define MLX5_COMPRESS_MAX_QPS 1024
28 #define MLX5_COMP_MAX_WIN_SIZE_CONF 6u
30 struct mlx5_compress_xform {
31 LIST_ENTRY(mlx5_compress_xform) next;
32 enum rte_comp_xform_type type;
33 enum rte_comp_checksum_type csum_type;
35 uint32_t gga_ctrl1; /* BE. */
38 struct mlx5_compress_priv {
39 TAILQ_ENTRY(mlx5_compress_priv) next;
40 struct ibv_context *ctx; /* Device context. */
41 struct rte_pci_device *pci_dev;
42 struct rte_compressdev *cdev;
44 uint32_t pdn; /* Protection Domain number. */
45 uint8_t min_block_size;
46 /* Minimum huffman block size supported by the device. */
48 struct rte_compressdev_config dev_config;
49 LIST_HEAD(xform_list, mlx5_compress_xform) xform_list;
50 rte_spinlock_t xform_sl;
51 struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
54 struct mlx5_compress_qp {
59 volatile uint64_t *uar_addr;
60 struct mlx5_mr_ctrl mr_ctrl;
62 struct mlx5_devx_cq cq;
63 struct mlx5_devx_sq sq;
64 struct mlx5_pmd_mr opaque_mr;
65 struct rte_comp_op **ops;
66 struct mlx5_compress_priv *priv;
69 TAILQ_HEAD(mlx5_compress_privs, mlx5_compress_priv) mlx5_compress_priv_list =
70 TAILQ_HEAD_INITIALIZER(mlx5_compress_priv_list);
71 static pthread_mutex_t priv_list_lock = PTHREAD_MUTEX_INITIALIZER;
73 int mlx5_compress_logtype;
75 const struct rte_compressdev_capabilities mlx5_caps[RTE_COMP_ALGO_LIST_END];
79 mlx5_compress_dev_info_get(struct rte_compressdev *dev,
80 struct rte_compressdev_info *info)
84 info->max_nb_queue_pairs = MLX5_COMPRESS_MAX_QPS;
85 info->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
86 info->capabilities = mlx5_caps;
91 mlx5_compress_dev_configure(struct rte_compressdev *dev,
92 struct rte_compressdev_config *config)
94 struct mlx5_compress_priv *priv;
96 if (dev == NULL || config == NULL)
98 priv = dev->data->dev_private;
99 priv->dev_config = *config;
104 mlx5_compress_dev_close(struct rte_compressdev *dev)
111 mlx5_compress_qp_release(struct rte_compressdev *dev, uint16_t qp_id)
113 struct mlx5_compress_qp *qp = dev->data->queue_pairs[qp_id];
115 if (qp->sq.sq != NULL)
116 mlx5_devx_sq_destroy(&qp->sq);
117 if (qp->cq.cq != NULL)
118 mlx5_devx_cq_destroy(&qp->cq);
119 if (qp->opaque_mr.obj != NULL) {
120 void *opaq = qp->opaque_mr.addr;
122 mlx5_common_verbs_dereg_mr(&qp->opaque_mr);
126 mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
128 dev->data->queue_pairs[qp_id] = NULL;
133 mlx5_compress_init_sq(struct mlx5_compress_qp *qp)
135 volatile struct mlx5_gga_wqe *restrict wqe =
136 (volatile struct mlx5_gga_wqe *)qp->sq.wqes;
137 volatile struct mlx5_gga_compress_opaque *opaq = qp->opaque_mr.addr;
138 const uint32_t sq_ds = rte_cpu_to_be_32((qp->sq.sq->id << 8) | 4u);
139 const uint32_t flags = RTE_BE32(MLX5_COMP_ALWAYS <<
140 MLX5_COMP_MODE_OFFSET);
141 const uint32_t opaq_lkey = rte_cpu_to_be_32(qp->opaque_mr.lkey);
144 /* All the next fields state should stay constant. */
145 for (i = 0; i < qp->entries_n; ++i, ++wqe) {
148 wqe->opaque_lkey = opaq_lkey;
149 wqe->opaque_vaddr = rte_cpu_to_be_64
150 ((uint64_t)(uintptr_t)&opaq[i]);
155 mlx5_compress_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
156 uint32_t max_inflight_ops, int socket_id)
158 struct mlx5_compress_priv *priv = dev->data->dev_private;
159 struct mlx5_compress_qp *qp;
160 struct mlx5_devx_cq_attr cq_attr = {
161 .uar_page_id = mlx5_os_get_devx_uar_page_id(priv->uar),
163 struct mlx5_devx_create_sq_attr sq_attr = {
165 .wq_attr = (struct mlx5_devx_wq_attr){
167 .uar_page = mlx5_os_get_devx_uar_page_id(priv->uar),
170 struct mlx5_devx_modify_sq_attr modify_attr = {
171 .state = MLX5_SQC_STATE_RDY,
173 uint32_t log_ops_n = rte_log2_u32(max_inflight_ops);
174 uint32_t alloc_size = sizeof(*qp);
178 alloc_size = RTE_ALIGN(alloc_size, RTE_CACHE_LINE_SIZE);
179 alloc_size += sizeof(struct rte_comp_op *) * (1u << log_ops_n);
180 qp = rte_zmalloc_socket(__func__, alloc_size, RTE_CACHE_LINE_SIZE,
183 DRV_LOG(ERR, "Failed to allocate qp memory.");
187 dev->data->queue_pairs[qp_id] = qp;
188 opaq_buf = rte_calloc(__func__, 1u << log_ops_n,
189 sizeof(struct mlx5_gga_compress_opaque),
190 sizeof(struct mlx5_gga_compress_opaque));
191 if (opaq_buf == NULL) {
192 DRV_LOG(ERR, "Failed to allocate opaque memory.");
196 if (mlx5_mr_btree_init(&qp->mr_ctrl.cache_bh, MLX5_MR_BTREE_CACHE_N,
197 priv->dev_config.socket_id)) {
198 DRV_LOG(ERR, "Cannot allocate MR Btree for qp %u.",
203 qp->entries_n = 1 << log_ops_n;
204 qp->socket_id = socket_id;
207 qp->ops = (struct rte_comp_op **)RTE_ALIGN((uintptr_t)(qp + 1),
208 RTE_CACHE_LINE_SIZE);
209 qp->uar_addr = mlx5_os_get_devx_uar_reg_addr(priv->uar);
210 MLX5_ASSERT(qp->uar_addr);
211 if (mlx5_common_verbs_reg_mr(priv->pd, opaq_buf, qp->entries_n *
212 sizeof(struct mlx5_gga_compress_opaque),
213 &qp->opaque_mr) != 0) {
215 DRV_LOG(ERR, "Failed to register opaque MR.");
219 ret = mlx5_devx_cq_create(priv->ctx, &qp->cq, log_ops_n, &cq_attr,
222 DRV_LOG(ERR, "Failed to create CQ.");
225 sq_attr.cqn = qp->cq.cq->id;
226 ret = mlx5_devx_sq_create(priv->ctx, &qp->sq, log_ops_n, &sq_attr,
229 DRV_LOG(ERR, "Failed to create SQ.");
232 mlx5_compress_init_sq(qp);
233 ret = mlx5_devx_cmd_modify_sq(qp->sq.sq, &modify_attr);
235 DRV_LOG(ERR, "Can't change SQ state to ready.");
238 DRV_LOG(INFO, "QP %u: SQN=0x%X CQN=0x%X entries num = %u\n",
239 (uint32_t)qp_id, qp->sq.sq->id, qp->cq.cq->id, qp->entries_n);
242 mlx5_compress_qp_release(dev, qp_id);
247 mlx5_compress_xform_free(struct rte_compressdev *dev, void *xform)
249 struct mlx5_compress_priv *priv = dev->data->dev_private;
251 rte_spinlock_lock(&priv->xform_sl);
252 LIST_REMOVE((struct mlx5_compress_xform *)xform, next);
253 rte_spinlock_unlock(&priv->xform_sl);
259 mlx5_compress_xform_create(struct rte_compressdev *dev,
260 const struct rte_comp_xform *xform,
261 void **private_xform)
263 struct mlx5_compress_priv *priv = dev->data->dev_private;
264 struct mlx5_compress_xform *xfrm;
267 if (xform->type == RTE_COMP_COMPRESS && xform->compress.level ==
268 RTE_COMP_LEVEL_NONE) {
269 DRV_LOG(ERR, "Non-compressed block is not supported.");
272 if ((xform->type == RTE_COMP_COMPRESS && xform->compress.hash_algo !=
273 RTE_COMP_HASH_ALGO_NONE) || (xform->type == RTE_COMP_DECOMPRESS &&
274 xform->decompress.hash_algo != RTE_COMP_HASH_ALGO_NONE)) {
275 DRV_LOG(ERR, "SHA is not supported.");
278 xfrm = rte_zmalloc_socket(__func__, sizeof(*xfrm), 0,
279 priv->dev_config.socket_id);
282 xfrm->opcode = MLX5_OPCODE_MMO;
283 xfrm->type = xform->type;
284 switch (xform->type) {
285 case RTE_COMP_COMPRESS:
286 switch (xform->compress.algo) {
287 case RTE_COMP_ALGO_NULL:
288 xfrm->opcode += MLX5_OPC_MOD_MMO_DMA <<
289 WQE_CSEG_OPC_MOD_OFFSET;
291 case RTE_COMP_ALGO_DEFLATE:
292 size = 1 << xform->compress.window_size;
293 size /= MLX5_GGA_COMP_WIN_SIZE_UNITS;
294 xfrm->gga_ctrl1 += RTE_MIN(rte_log2_u32(size),
295 MLX5_COMP_MAX_WIN_SIZE_CONF) <<
296 WQE_GGA_COMP_WIN_SIZE_OFFSET;
297 if (xform->compress.level == RTE_COMP_LEVEL_PMD_DEFAULT)
298 size = MLX5_GGA_COMP_LOG_BLOCK_SIZE_MAX;
300 size = priv->min_block_size - 1 +
301 xform->compress.level;
302 xfrm->gga_ctrl1 += RTE_MIN(size,
303 MLX5_GGA_COMP_LOG_BLOCK_SIZE_MAX) <<
304 WQE_GGA_COMP_BLOCK_SIZE_OFFSET;
305 xfrm->opcode += MLX5_OPC_MOD_MMO_COMP <<
306 WQE_CSEG_OPC_MOD_OFFSET;
307 size = xform->compress.deflate.huffman ==
308 RTE_COMP_HUFFMAN_DYNAMIC ?
309 MLX5_GGA_COMP_LOG_DYNAMIC_SIZE_MAX :
310 MLX5_GGA_COMP_LOG_DYNAMIC_SIZE_MIN;
311 xfrm->gga_ctrl1 += size <<
312 WQE_GGA_COMP_DYNAMIC_SIZE_OFFSET;
317 xfrm->csum_type = xform->compress.chksum;
319 case RTE_COMP_DECOMPRESS:
320 switch (xform->decompress.algo) {
321 case RTE_COMP_ALGO_NULL:
322 xfrm->opcode += MLX5_OPC_MOD_MMO_DMA <<
323 WQE_CSEG_OPC_MOD_OFFSET;
325 case RTE_COMP_ALGO_DEFLATE:
326 xfrm->opcode += MLX5_OPC_MOD_MMO_DECOMP <<
327 WQE_CSEG_OPC_MOD_OFFSET;
332 xfrm->csum_type = xform->decompress.chksum;
335 DRV_LOG(ERR, "Algorithm %u is not supported.", xform->type);
338 DRV_LOG(DEBUG, "New xform: gga ctrl1 = 0x%08X opcode = 0x%08X csum "
339 "type = %d.", xfrm->gga_ctrl1, xfrm->opcode, xfrm->csum_type);
340 xfrm->gga_ctrl1 = rte_cpu_to_be_32(xfrm->gga_ctrl1);
341 rte_spinlock_lock(&priv->xform_sl);
342 LIST_INSERT_HEAD(&priv->xform_list, xfrm, next);
343 rte_spinlock_unlock(&priv->xform_sl);
344 *private_xform = xfrm;
352 mlx5_compress_dev_stop(struct rte_compressdev *dev)
358 mlx5_compress_dev_start(struct rte_compressdev *dev)
364 static struct rte_compressdev_ops mlx5_compress_ops = {
365 .dev_configure = mlx5_compress_dev_configure,
366 .dev_start = mlx5_compress_dev_start,
367 .dev_stop = mlx5_compress_dev_stop,
368 .dev_close = mlx5_compress_dev_close,
369 .dev_infos_get = mlx5_compress_dev_info_get,
372 .queue_pair_setup = mlx5_compress_qp_setup,
373 .queue_pair_release = mlx5_compress_qp_release,
374 .private_xform_create = mlx5_compress_xform_create,
375 .private_xform_free = mlx5_compress_xform_free,
376 .stream_create = NULL,
380 static __rte_always_inline uint32_t
381 mlx5_compress_dseg_set(struct mlx5_compress_qp *qp,
382 volatile struct mlx5_wqe_dseg *restrict dseg,
383 struct rte_mbuf *restrict mbuf,
384 uint32_t offset, uint32_t len)
386 uintptr_t addr = rte_pktmbuf_mtod_offset(mbuf, uintptr_t, offset);
388 dseg->bcount = rte_cpu_to_be_32(len);
389 dseg->lkey = mlx5_mr_addr2mr_bh(qp->priv->pd, 0, &qp->priv->mr_scache,
391 !!(mbuf->ol_flags & EXT_ATTACHED_MBUF));
392 dseg->pbuf = rte_cpu_to_be_64(addr);
397 mlx5_compress_enqueue_burst(void *queue_pair, struct rte_comp_op **ops,
400 struct mlx5_compress_qp *qp = queue_pair;
401 volatile struct mlx5_gga_wqe *wqes = (volatile struct mlx5_gga_wqe *)
403 struct mlx5_compress_xform *xform;
404 struct rte_comp_op *op;
405 uint16_t mask = qp->entries_n - 1;
406 uint16_t remain = qp->entries_n - (qp->pi - qp->ci);
414 if (unlikely(remain == 0))
419 rte_prefetch0(&wqes[(qp->pi + 1) & mask]);
421 xform = op->private_xform;
423 * Check operation arguments and error cases:
424 * - Operation type must be state-less.
425 * - Compress operation flush flag must be FULL or FINAL.
426 * - Source and destination buffers must be mapped internally.
428 invalid = op->op_type != RTE_COMP_OP_STATELESS ||
429 (xform->type == RTE_COMP_COMPRESS &&
430 op->flush_flag < RTE_COMP_FLUSH_FULL);
431 if (unlikely(invalid ||
432 (mlx5_compress_dseg_set(qp, &wqe->gather,
437 (mlx5_compress_dseg_set(qp, &wqe->scatter,
440 rte_pktmbuf_pkt_len(op->m_dst) -
443 op->status = invalid ? RTE_COMP_OP_STATUS_INVALID_ARGS :
444 RTE_COMP_OP_STATUS_ERROR;
446 if (unlikely(nb_ops == 0))
450 wqe->gga_ctrl1 = xform->gga_ctrl1;
451 wqe->opcode = rte_cpu_to_be_32(xform->opcode + (qp->pi << 8));
456 qp->sq.db_rec[MLX5_SND_DBR] = rte_cpu_to_be_32(qp->pi);
458 *qp->uar_addr = *(volatile uint64_t *)wqe; /* Assume 64 bit ARCH.*/
464 mlx5_compress_dump_err_objs(volatile uint32_t *cqe, volatile uint32_t *wqe,
465 volatile uint32_t *opaq)
469 DRV_LOG(ERR, "Error cqe:");
470 for (i = 0; i < sizeof(struct mlx5_err_cqe) >> 2; i += 4)
471 DRV_LOG(ERR, "%08X %08X %08X %08X", cqe[i], cqe[i + 1],
472 cqe[i + 2], cqe[i + 3]);
473 DRV_LOG(ERR, "\nError wqe:");
474 for (i = 0; i < sizeof(struct mlx5_gga_wqe) >> 2; i += 4)
475 DRV_LOG(ERR, "%08X %08X %08X %08X", wqe[i], wqe[i + 1],
476 wqe[i + 2], wqe[i + 3]);
477 DRV_LOG(ERR, "\nError opaq:");
478 for (i = 0; i < sizeof(struct mlx5_gga_compress_opaque) >> 2; i += 4)
479 DRV_LOG(ERR, "%08X %08X %08X %08X", opaq[i], opaq[i + 1],
480 opaq[i + 2], opaq[i + 3]);
484 mlx5_compress_cqe_err_handle(struct mlx5_compress_qp *qp,
485 struct rte_comp_op *op)
487 const uint32_t idx = qp->ci & (qp->entries_n - 1);
488 volatile struct mlx5_err_cqe *cqe = (volatile struct mlx5_err_cqe *)
490 volatile struct mlx5_gga_wqe *wqes = (volatile struct mlx5_gga_wqe *)
492 volatile struct mlx5_gga_compress_opaque *opaq = qp->opaque_mr.addr;
494 op->status = RTE_COMP_OP_STATUS_ERROR;
497 op->output_chksum = 0;
498 op->debug_status = rte_be_to_cpu_32(opaq[idx].syndrom) |
499 ((uint64_t)rte_be_to_cpu_32(cqe->syndrome) << 32);
500 mlx5_compress_dump_err_objs((volatile uint32_t *)cqe,
501 (volatile uint32_t *)&wqes[idx],
502 (volatile uint32_t *)&opaq[idx]);
506 mlx5_compress_dequeue_burst(void *queue_pair, struct rte_comp_op **ops,
509 struct mlx5_compress_qp *qp = queue_pair;
510 volatile struct mlx5_compress_xform *restrict xform;
511 volatile struct mlx5_cqe *restrict cqe;
512 volatile struct mlx5_gga_compress_opaque *opaq = qp->opaque_mr.addr;
513 struct rte_comp_op *restrict op;
514 const unsigned int cq_size = qp->entries_n;
515 const unsigned int mask = cq_size - 1;
517 uint32_t next_idx = qp->ci & mask;
518 const uint16_t max = RTE_MIN((uint16_t)(qp->pi - qp->ci), nb_ops);
522 if (unlikely(max == 0))
526 next_idx = (qp->ci + 1) & mask;
527 rte_prefetch0(&qp->cq.cqes[next_idx]);
528 rte_prefetch0(qp->ops[next_idx]);
530 cqe = &qp->cq.cqes[idx];
531 ret = check_cqe(cqe, cq_size, qp->ci);
533 * Be sure owner read is done before any other cookie field or
537 if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
538 if (likely(ret == MLX5_CQE_STATUS_HW_OWN))
540 mlx5_compress_cqe_err_handle(qp, op);
542 xform = op->private_xform;
543 op->status = RTE_COMP_OP_STATUS_SUCCESS;
544 op->consumed = op->src.length;
545 op->produced = rte_be_to_cpu_32(cqe->byte_cnt);
546 MLX5_ASSERT(cqe->byte_cnt ==
547 qp->opaque_buf[idx].scattered_length);
548 switch (xform->csum_type) {
549 case RTE_COMP_CHECKSUM_CRC32:
550 op->output_chksum = (uint64_t)rte_be_to_cpu_32
553 case RTE_COMP_CHECKSUM_ADLER32:
554 op->output_chksum = (uint64_t)rte_be_to_cpu_32
555 (opaq[idx].adler32) << 32;
557 case RTE_COMP_CHECKSUM_CRC32_ADLER32:
558 op->output_chksum = (uint64_t)rte_be_to_cpu_32
560 ((uint64_t)rte_be_to_cpu_32
561 (opaq[idx].adler32) << 32);
570 if (likely(i != 0)) {
572 qp->cq.db_rec[0] = rte_cpu_to_be_32(qp->ci);
577 static struct ibv_device *
578 mlx5_compress_get_ib_device_match(struct rte_pci_addr *addr)
581 struct ibv_device **ibv_list = mlx5_glue->get_device_list(&n);
582 struct ibv_device *ibv_match = NULL;
584 if (ibv_list == NULL) {
589 struct rte_pci_addr paddr;
591 DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name);
592 if (mlx5_dev_to_pci_addr(ibv_list[n]->ibdev_path, &paddr) != 0)
594 if (rte_pci_addr_cmp(addr, &paddr) != 0)
596 ibv_match = ibv_list[n];
599 if (ibv_match == NULL)
601 mlx5_glue->free_device_list(ibv_list);
606 mlx5_compress_hw_global_release(struct mlx5_compress_priv *priv)
608 if (priv->pd != NULL) {
609 claim_zero(mlx5_glue->dealloc_pd(priv->pd));
612 if (priv->uar != NULL) {
613 mlx5_glue->devx_free_uar(priv->uar);
619 mlx5_compress_pd_create(struct mlx5_compress_priv *priv)
621 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
622 struct mlx5dv_obj obj;
623 struct mlx5dv_pd pd_info;
626 priv->pd = mlx5_glue->alloc_pd(priv->ctx);
627 if (priv->pd == NULL) {
628 DRV_LOG(ERR, "Failed to allocate PD.");
629 return errno ? -errno : -ENOMEM;
631 obj.pd.in = priv->pd;
632 obj.pd.out = &pd_info;
633 ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_PD);
635 DRV_LOG(ERR, "Fail to get PD object info.");
636 mlx5_glue->dealloc_pd(priv->pd);
640 priv->pdn = pd_info.pdn;
644 DRV_LOG(ERR, "Cannot get pdn - no DV support.");
646 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
650 mlx5_compress_hw_global_prepare(struct mlx5_compress_priv *priv)
652 if (mlx5_compress_pd_create(priv) != 0)
654 priv->uar = mlx5_devx_alloc_uar(priv->ctx, -1);
655 if (priv->uar == NULL || mlx5_os_get_devx_uar_reg_addr(priv->uar) ==
658 claim_zero(mlx5_glue->dealloc_pd(priv->pd));
659 DRV_LOG(ERR, "Failed to allocate UAR.");
666 * DPDK callback to register a PCI device.
668 * This function spawns compress device out of a given PCI device.
671 * PCI driver structure (mlx5_compress_driver).
673 * PCI device information.
676 * 0 on success, 1 to skip this driver, a negative errno value otherwise
677 * and rte_errno is set.
680 mlx5_compress_pci_probe(struct rte_pci_driver *pci_drv,
681 struct rte_pci_device *pci_dev)
683 struct ibv_device *ibv;
684 struct rte_compressdev *cdev;
685 struct ibv_context *ctx;
686 struct mlx5_compress_priv *priv;
687 struct mlx5_hca_attr att = { 0 };
688 struct rte_compressdev_pmd_init_params init_params = {
690 .socket_id = pci_dev->device.numa_node,
693 RTE_SET_USED(pci_drv);
694 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
695 DRV_LOG(ERR, "Non-primary process type is not supported.");
699 ibv = mlx5_compress_get_ib_device_match(&pci_dev->addr);
701 DRV_LOG(ERR, "No matching IB device for PCI slot "
702 PCI_PRI_FMT ".", pci_dev->addr.domain,
703 pci_dev->addr.bus, pci_dev->addr.devid,
704 pci_dev->addr.function);
707 DRV_LOG(INFO, "PCI information matches for device \"%s\".", ibv->name);
708 ctx = mlx5_glue->dv_open_device(ibv);
710 DRV_LOG(ERR, "Failed to open IB device \"%s\".", ibv->name);
714 if (mlx5_devx_cmd_query_hca_attr(ctx, &att) != 0 ||
715 att.mmo_compress_en == 0 || att.mmo_decompress_en == 0 ||
716 att.mmo_dma_en == 0) {
717 DRV_LOG(ERR, "Not enough capabilities to support compress "
718 "operations, maybe old FW/OFED version?");
719 claim_zero(mlx5_glue->close_device(ctx));
723 cdev = rte_compressdev_pmd_create(ibv->name, &pci_dev->device,
724 sizeof(*priv), &init_params);
726 DRV_LOG(ERR, "Failed to create device \"%s\".", ibv->name);
727 claim_zero(mlx5_glue->close_device(ctx));
731 "Compress device %s was created successfully.", ibv->name);
732 cdev->dev_ops = &mlx5_compress_ops;
733 cdev->dequeue_burst = mlx5_compress_dequeue_burst;
734 cdev->enqueue_burst = mlx5_compress_enqueue_burst;
735 cdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
736 priv = cdev->data->dev_private;
738 priv->pci_dev = pci_dev;
740 priv->min_block_size = att.compress_min_block_size;
741 if (mlx5_compress_hw_global_prepare(priv) != 0) {
742 rte_compressdev_pmd_destroy(priv->cdev);
743 claim_zero(mlx5_glue->close_device(priv->ctx));
746 if (mlx5_mr_btree_init(&priv->mr_scache.cache,
747 MLX5_MR_BTREE_CACHE_N * 2, rte_socket_id()) != 0) {
748 DRV_LOG(ERR, "Failed to allocate shared cache MR memory.");
749 mlx5_compress_hw_global_release(priv);
750 rte_compressdev_pmd_destroy(priv->cdev);
751 claim_zero(mlx5_glue->close_device(priv->ctx));
755 priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr;
756 priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr;
757 pthread_mutex_lock(&priv_list_lock);
758 TAILQ_INSERT_TAIL(&mlx5_compress_priv_list, priv, next);
759 pthread_mutex_unlock(&priv_list_lock);
764 * DPDK callback to remove a PCI device.
766 * This function removes all compress devices belong to a given PCI device.
769 * Pointer to the PCI device.
772 * 0 on success, the function cannot fail.
775 mlx5_compress_pci_remove(struct rte_pci_device *pdev)
777 struct mlx5_compress_priv *priv = NULL;
779 pthread_mutex_lock(&priv_list_lock);
780 TAILQ_FOREACH(priv, &mlx5_compress_priv_list, next)
781 if (rte_pci_addr_cmp(&priv->pci_dev->addr, &pdev->addr) != 0)
784 TAILQ_REMOVE(&mlx5_compress_priv_list, priv, next);
785 pthread_mutex_unlock(&priv_list_lock);
787 mlx5_mr_release_cache(&priv->mr_scache);
788 mlx5_compress_hw_global_release(priv);
789 rte_compressdev_pmd_destroy(priv->cdev);
790 claim_zero(mlx5_glue->close_device(priv->ctx));
795 static const struct rte_pci_id mlx5_compress_pci_id_map[] = {
797 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
798 PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF)
805 static struct mlx5_pci_driver mlx5_compress_driver = {
806 .driver_class = MLX5_CLASS_COMPRESS,
809 .name = RTE_STR(MLX5_COMPRESS_DRIVER_NAME),
811 .id_table = mlx5_compress_pci_id_map,
812 .probe = mlx5_compress_pci_probe,
813 .remove = mlx5_compress_pci_remove,
818 RTE_INIT(rte_mlx5_compress_init)
821 if (mlx5_glue != NULL)
822 mlx5_pci_driver_register(&mlx5_compress_driver);
825 RTE_LOG_REGISTER(mlx5_compress_logtype, MLX5_COMPRESS_LOG_NAME, NOTICE)
826 RTE_PMD_EXPORT_NAME(MLX5_COMPRESS_DRIVER_NAME, __COUNTER__);
827 RTE_PMD_REGISTER_PCI_TABLE(MLX5_COMPRESS_DRIVER_NAME, mlx5_compress_pci_id_map);
828 RTE_PMD_REGISTER_KMOD_DEP(MLX5_COMPRESS_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");