Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2021 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <rte_malloc.h>
6 : : #include <rte_log.h>
7 : : #include <rte_errno.h>
8 : : #include <bus_pci_driver.h>
9 : : #include <rte_spinlock.h>
10 : : #include <rte_comp.h>
11 : : #include <rte_compressdev.h>
12 : : #include <rte_compressdev_pmd.h>
13 : :
14 : : #include <mlx5_glue.h>
15 : : #include <mlx5_common.h>
16 : : #include <mlx5_devx_cmds.h>
17 : : #include <mlx5_common_os.h>
18 : : #include <mlx5_common_devx.h>
19 : : #include <mlx5_common_mr.h>
20 : : #include <mlx5_prm.h>
21 : :
22 : : #include "mlx5_compress_utils.h"
23 : :
24 : : #define MLX5_COMPRESS_DRIVER_NAME mlx5_compress
25 : : #define MLX5_COMPRESS_MAX_QPS 1024
26 : : #define MLX5_COMP_MAX_WIN_SIZE_CONF 6u
27 : : #define MLX5_COMP_NUM_SUP_ALGO 4
28 : :
29 : : struct mlx5_compress_devarg_params {
30 : : uint32_t log_block_sz;
31 : : };
32 : :
33 : : struct mlx5_compress_xform {
34 : : LIST_ENTRY(mlx5_compress_xform) next;
35 : : enum rte_comp_xform_type type;
36 : : enum rte_comp_checksum_type csum_type;
37 : : uint32_t opcode;
38 : : uint32_t gga_ctrl1; /* BE. */
39 : : };
40 : :
41 : : struct mlx5_compress_priv {
42 : : TAILQ_ENTRY(mlx5_compress_priv) next;
43 : : struct rte_compressdev *compressdev;
44 : : struct mlx5_common_device *cdev; /* Backend mlx5 device. */
45 : : struct mlx5_uar uar;
46 : : struct rte_compressdev_config dev_config;
47 : : struct rte_compressdev_capabilities caps[MLX5_COMP_NUM_SUP_ALGO];
48 : : LIST_HEAD(xform_list, mlx5_compress_xform) xform_list;
49 : : rte_spinlock_t xform_sl;
50 : : uint32_t log_block_sz;
51 : : uint32_t crc32_opaq_offs;
52 : : };
53 : :
54 : : struct mlx5_compress_qp {
55 : : uint16_t qp_id;
56 : : uint16_t entries_n;
57 : : uint16_t pi;
58 : : uint16_t ci;
59 : : struct mlx5_mr_ctrl mr_ctrl;
60 : : int socket_id;
61 : : struct mlx5_devx_cq cq;
62 : : struct mlx5_devx_qp qp;
63 : : struct mlx5_pmd_mr opaque_mr;
64 : : struct rte_comp_op **ops;
65 : : struct mlx5_compress_priv *priv;
66 : : struct rte_compressdev_stats stats;
67 : : };
68 : :
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;
72 : :
73 : : int mlx5_compress_logtype;
74 : :
75 : : static void
76 : 0 : mlx5_compress_dev_info_get(struct rte_compressdev *dev,
77 : : struct rte_compressdev_info *info)
78 : : {
79 [ # # ]: 0 : if (dev != NULL && info != NULL) {
80 : 0 : struct mlx5_compress_priv *priv = dev->data->dev_private;
81 : :
82 : 0 : info->max_nb_queue_pairs = MLX5_COMPRESS_MAX_QPS;
83 : 0 : info->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
84 : 0 : info->capabilities = priv->caps;
85 : : }
86 : 0 : }
87 : :
88 : : static int
89 : 0 : mlx5_compress_dev_configure(struct rte_compressdev *dev,
90 : : struct rte_compressdev_config *config)
91 : : {
92 : : struct mlx5_compress_priv *priv;
93 : :
94 [ # # ]: 0 : if (dev == NULL || config == NULL)
95 : : return -EINVAL;
96 : 0 : priv = dev->data->dev_private;
97 : 0 : priv->dev_config = *config;
98 : 0 : return 0;
99 : : }
100 : :
101 : : static int
102 : 0 : mlx5_compress_dev_close(struct rte_compressdev *dev)
103 : : {
104 : : RTE_SET_USED(dev);
105 : 0 : return 0;
106 : : }
107 : :
108 : : static int
109 : 0 : mlx5_compress_qp_release(struct rte_compressdev *dev, uint16_t qp_id)
110 : : {
111 : 0 : struct mlx5_compress_qp *qp = dev->data->queue_pairs[qp_id];
112 : :
113 [ # # ]: 0 : if (qp->qp.qp != NULL)
114 : 0 : mlx5_devx_qp_destroy(&qp->qp);
115 [ # # ]: 0 : if (qp->cq.cq != NULL)
116 : 0 : mlx5_devx_cq_destroy(&qp->cq);
117 [ # # ]: 0 : if (qp->opaque_mr.obj != NULL) {
118 : 0 : void *opaq = qp->opaque_mr.addr;
119 : :
120 : 0 : mlx5_common_verbs_dereg_mr(&qp->opaque_mr);
121 : 0 : rte_free(opaq);
122 : : }
123 : 0 : mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
124 : 0 : rte_free(qp);
125 : 0 : dev->data->queue_pairs[qp_id] = NULL;
126 : 0 : return 0;
127 : : }
128 : :
129 : : static void
130 : 0 : mlx5_compress_init_qp(struct mlx5_compress_qp *qp)
131 : : {
132 : 0 : volatile struct mlx5_gga_wqe *restrict wqe =
133 : : (volatile struct mlx5_gga_wqe *)qp->qp.wqes;
134 : 0 : volatile union mlx5_gga_compress_opaque *opaq = qp->opaque_mr.addr;
135 [ # # ]: 0 : const uint32_t sq_ds = rte_cpu_to_be_32((qp->qp.qp->id << 8) | 4u);
136 : : const uint32_t flags = RTE_BE32(MLX5_COMP_ALWAYS <<
137 : : MLX5_COMP_MODE_OFFSET);
138 [ # # ]: 0 : const uint32_t opaq_lkey = rte_cpu_to_be_32(qp->opaque_mr.lkey);
139 : : int i;
140 : :
141 : : /* All the next fields state should stay constant. */
142 [ # # ]: 0 : for (i = 0; i < qp->entries_n; ++i, ++wqe) {
143 : 0 : wqe->sq_ds = sq_ds;
144 : 0 : wqe->flags = flags;
145 : 0 : wqe->opaque_lkey = opaq_lkey;
146 : 0 : wqe->opaque_vaddr = rte_cpu_to_be_64
147 : : ((uint64_t)(uintptr_t)&opaq[i]);
148 : : }
149 : 0 : }
150 : :
151 : : static int
152 : 0 : mlx5_compress_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
153 : : uint32_t max_inflight_ops, int socket_id)
154 : : {
155 : 0 : struct mlx5_compress_priv *priv = dev->data->dev_private;
156 : 0 : struct mlx5_hca_attr *attr = &priv->cdev->config.hca_attr;
157 : : struct mlx5_compress_qp *qp;
158 : 0 : struct mlx5_devx_cq_attr cq_attr = {
159 [ # # ]: 0 : .uar_page_id = mlx5_os_get_devx_uar_page_id(priv->uar.obj),
160 : : };
161 : 0 : struct mlx5_devx_qp_attr qp_attr = {
162 : 0 : .pd = priv->cdev->pdn,
163 [ # # ]: 0 : .uar_index = mlx5_os_get_devx_uar_page_id(priv->uar.obj),
164 : : .user_index = qp_id,
165 : : };
166 : : uint32_t log_ops_n = rte_log2_u32(max_inflight_ops);
167 : : uint32_t alloc_size = sizeof(*qp);
168 : : void *opaq_buf;
169 : : int ret;
170 : :
171 : : alloc_size = RTE_ALIGN(alloc_size, RTE_CACHE_LINE_SIZE);
172 : 0 : alloc_size += sizeof(struct rte_comp_op *) * (1u << log_ops_n);
173 : 0 : qp = rte_zmalloc_socket(__func__, alloc_size, RTE_CACHE_LINE_SIZE,
174 : : socket_id);
175 [ # # ]: 0 : if (qp == NULL) {
176 : 0 : DRV_LOG(ERR, "Failed to allocate qp memory.");
177 : 0 : rte_errno = ENOMEM;
178 : 0 : return -rte_errno;
179 : : }
180 : 0 : dev->data->queue_pairs[qp_id] = qp;
181 [ # # ]: 0 : if (mlx5_mr_ctrl_init(&qp->mr_ctrl, &priv->cdev->mr_scache.dev_gen,
182 : : priv->dev_config.socket_id)) {
183 : 0 : DRV_LOG(ERR, "Cannot allocate MR Btree for qp %u.",
184 : : (uint32_t)qp_id);
185 : 0 : rte_errno = ENOMEM;
186 : 0 : goto err;
187 : : }
188 : 0 : opaq_buf = rte_calloc(__func__, (size_t)1 << log_ops_n,
189 : : sizeof(union mlx5_gga_compress_opaque),
190 : : sizeof(union mlx5_gga_compress_opaque));
191 [ # # ]: 0 : if (opaq_buf == NULL) {
192 : 0 : DRV_LOG(ERR, "Failed to allocate opaque memory.");
193 : 0 : rte_errno = ENOMEM;
194 : 0 : goto err;
195 : : }
196 : 0 : qp->entries_n = 1 << log_ops_n;
197 : 0 : qp->socket_id = socket_id;
198 : 0 : qp->qp_id = qp_id;
199 : 0 : qp->priv = priv;
200 : 0 : qp->ops = (struct rte_comp_op **)RTE_ALIGN((uintptr_t)(qp + 1),
201 : : RTE_CACHE_LINE_SIZE);
202 [ # # ]: 0 : if (mlx5_common_verbs_reg_mr(priv->cdev->pd, opaq_buf, qp->entries_n *
203 : : sizeof(union mlx5_gga_compress_opaque),
204 : : &qp->opaque_mr) != 0) {
205 : 0 : rte_free(opaq_buf);
206 : 0 : DRV_LOG(ERR, "Failed to register opaque MR.");
207 : 0 : rte_errno = ENOMEM;
208 : 0 : goto err;
209 : : }
210 : 0 : ret = mlx5_devx_cq_create(priv->cdev->ctx, &qp->cq, log_ops_n, &cq_attr,
211 : : socket_id);
212 [ # # ]: 0 : if (ret != 0) {
213 : 0 : DRV_LOG(ERR, "Failed to create CQ.");
214 : 0 : goto err;
215 : : }
216 : 0 : qp_attr.cqn = qp->cq.cq->id;
217 : 0 : qp_attr.ts_format = mlx5_ts_format_conv(attr->qp_ts_format);
218 : 0 : qp_attr.num_of_receive_wqes = 0;
219 : 0 : qp_attr.num_of_send_wqbbs = RTE_BIT32(log_ops_n);
220 : 0 : qp_attr.mmo = attr->mmo_compress_qp_en || attr->mmo_dma_qp_en ||
221 : : attr->decomp_lz4_checksum_en ||
222 : : attr->decomp_lz4_no_checksum_en ||
223 : 0 : attr->decomp_deflate_v1_en || attr->decomp_deflate_v2_en;
224 : 0 : ret = mlx5_devx_qp_create(priv->cdev->ctx, &qp->qp,
225 : 0 : qp_attr.num_of_send_wqbbs *
226 : : MLX5_WQE_SIZE, &qp_attr, socket_id);
227 [ # # ]: 0 : if (ret != 0) {
228 : 0 : DRV_LOG(ERR, "Failed to create QP.");
229 : 0 : goto err;
230 : : }
231 : 0 : mlx5_compress_init_qp(qp);
232 : 0 : ret = mlx5_devx_qp2rts(&qp->qp, 0);
233 [ # # ]: 0 : if (ret)
234 : 0 : goto err;
235 : 0 : DRV_LOG(INFO, "QP %u: SQN=0x%X CQN=0x%X entries num = %u",
236 : : (uint32_t)qp_id, qp->qp.qp->id, qp->cq.cq->id, qp->entries_n);
237 : 0 : return 0;
238 : 0 : err:
239 : 0 : mlx5_compress_qp_release(dev, qp_id);
240 : 0 : return -1;
241 : : }
242 : :
243 : : static int
244 : 0 : mlx5_compress_xform_free(struct rte_compressdev *dev, void *xform)
245 : : {
246 : 0 : struct mlx5_compress_priv *priv = dev->data->dev_private;
247 : :
248 : 0 : rte_spinlock_lock(&priv->xform_sl);
249 [ # # ]: 0 : LIST_REMOVE((struct mlx5_compress_xform *)xform, next);
250 : : rte_spinlock_unlock(&priv->xform_sl);
251 : 0 : rte_free(xform);
252 : 0 : return 0;
253 : : }
254 : :
255 : : static int
256 : 0 : mlx5_compress_xform_validate(const struct rte_comp_xform *xform,
257 : : const struct mlx5_hca_attr *attr)
258 : : {
259 [ # # # ]: 0 : switch (xform->type) {
260 : 0 : case RTE_COMP_COMPRESS:
261 [ # # ]: 0 : if (xform->compress.algo == RTE_COMP_ALGO_NULL &&
262 [ # # ]: 0 : !attr->mmo_dma_qp_en && !attr->mmo_dma_sq_en) {
263 : 0 : DRV_LOG(ERR, "Not enough capabilities to support DMA operation, maybe old FW/OFED version?");
264 : 0 : return -ENOTSUP;
265 [ # # ]: 0 : } else if (!attr->mmo_compress_qp_en &&
266 : : !attr->mmo_compress_sq_en) {
267 : 0 : DRV_LOG(ERR, "Not enough capabilities to support compress operation.");
268 : 0 : return -ENOTSUP;
269 : : }
270 [ # # ]: 0 : if (xform->compress.algo == RTE_COMP_ALGO_LZ4) {
271 : 0 : DRV_LOG(ERR, "LZ4 compression is not supported.");
272 : 0 : return -ENOTSUP;
273 : : }
274 [ # # ]: 0 : if (xform->compress.level == RTE_COMP_LEVEL_NONE) {
275 : 0 : DRV_LOG(ERR, "Non-compressed block is not supported.");
276 : 0 : return -ENOTSUP;
277 : : }
278 [ # # ]: 0 : if (xform->compress.hash_algo != RTE_COMP_HASH_ALGO_NONE) {
279 : 0 : DRV_LOG(ERR, "SHA is not supported.");
280 : 0 : return -ENOTSUP;
281 : : }
282 [ # # ]: 0 : if (xform->compress.chksum == RTE_COMP_CHECKSUM_XXHASH32) {
283 : 0 : DRV_LOG(ERR, "xxHash32 checksum isn't supported in compress operation.");
284 : 0 : return -ENOTSUP;
285 : : }
286 : : break;
287 : 0 : case RTE_COMP_DECOMPRESS:
288 [ # # # # ]: 0 : switch (xform->decompress.algo) {
289 : 0 : case RTE_COMP_ALGO_NULL:
290 [ # # ]: 0 : if (!attr->mmo_dma_qp_en && !attr->mmo_dma_sq_en) {
291 : 0 : DRV_LOG(ERR, "Not enough capabilities to support DMA operation, maybe old FW/OFED version?");
292 : 0 : return -ENOTSUP;
293 : : }
294 : : break;
295 : 0 : case RTE_COMP_ALGO_DEFLATE:
296 : 0 : if (!attr->decomp_deflate_v1_en &&
297 [ # # ]: 0 : !attr->decomp_deflate_v2_en &&
298 : : !attr->mmo_decompress_sq_en) {
299 : 0 : DRV_LOG(ERR, "Not enough capabilities to support decompress DEFLATE algorithm, maybe old FW/OFED version?");
300 : 0 : return -ENOTSUP;
301 : : }
302 [ # # ]: 0 : switch (xform->decompress.chksum) {
303 : : case RTE_COMP_CHECKSUM_NONE:
304 : : case RTE_COMP_CHECKSUM_CRC32:
305 : : case RTE_COMP_CHECKSUM_ADLER32:
306 : : case RTE_COMP_CHECKSUM_CRC32_ADLER32:
307 : : break;
308 : 0 : case RTE_COMP_CHECKSUM_XXHASH32:
309 : : default:
310 : 0 : DRV_LOG(ERR, "DEFLATE algorithm doesn't support %u checksum.",
311 : : xform->decompress.chksum);
312 : 0 : return -ENOTSUP;
313 : : }
314 : : break;
315 : 0 : case RTE_COMP_ALGO_LZ4:
316 [ # # ]: 0 : if (!attr->decomp_lz4_no_checksum_en &&
317 : : !attr->decomp_lz4_checksum_en) {
318 : 0 : DRV_LOG(ERR, "Not enough capabilities to support decompress LZ4 algorithm, maybe old FW/OFED version?");
319 : 0 : return -ENOTSUP;
320 : : }
321 [ # # ]: 0 : if (xform->decompress.lz4.flags &
322 : : RTE_COMP_LZ4_FLAG_BLOCK_CHECKSUM) {
323 [ # # ]: 0 : if (!attr->decomp_lz4_checksum_en) {
324 : 0 : DRV_LOG(ERR, "Not enough capabilities to support decompress LZ4 block with checksum param, maybe old FW/OFED version?");
325 : 0 : return -ENOTSUP;
326 : : }
327 : : } else {
328 [ # # ]: 0 : if (!attr->decomp_lz4_no_checksum_en) {
329 : 0 : DRV_LOG(ERR, "Not enough capabilities to support decompress LZ4 block without checksum param, maybe old FW/OFED version?");
330 : 0 : return -ENOTSUP;
331 : : }
332 : : }
333 : 0 : if (xform->decompress.chksum !=
334 [ # # ]: 0 : RTE_COMP_CHECKSUM_XXHASH32 &&
335 : : xform->decompress.chksum !=
336 : : RTE_COMP_CHECKSUM_NONE) {
337 : 0 : DRV_LOG(ERR, "LZ4 algorithm supports only xxHash32 checksum.");
338 : 0 : return -ENOTSUP;
339 : : }
340 : : break;
341 : 0 : default:
342 : 0 : DRV_LOG(ERR, "Algorithm %u is not supported.",
343 : : xform->decompress.algo);
344 : 0 : return -ENOTSUP;
345 : : }
346 [ # # ]: 0 : if (xform->decompress.hash_algo != RTE_COMP_HASH_ALGO_NONE) {
347 : 0 : DRV_LOG(ERR, "SHA is not supported.");
348 : 0 : return -ENOTSUP;
349 : : }
350 : : break;
351 : 0 : default:
352 : 0 : DRV_LOG(ERR, "Xform type should be compress/decompress");
353 : 0 : return -ENOTSUP;
354 : : }
355 : : return 0;
356 : : }
357 : :
358 : : static int
359 : 0 : mlx5_compress_xform_create(struct rte_compressdev *dev,
360 : : const struct rte_comp_xform *xform,
361 : : void **private_xform)
362 : : {
363 : 0 : struct mlx5_compress_priv *priv = dev->data->dev_private;
364 : : struct mlx5_compress_xform *xfrm;
365 : : uint32_t size;
366 : : int ret;
367 : :
368 : 0 : ret = mlx5_compress_xform_validate(xform, &priv->cdev->config.hca_attr);
369 [ # # ]: 0 : if (ret < 0)
370 : : return ret;
371 : 0 : xfrm = rte_zmalloc_socket(__func__, sizeof(*xfrm), 0,
372 : : priv->dev_config.socket_id);
373 [ # # ]: 0 : if (xfrm == NULL)
374 : : return -ENOMEM;
375 : 0 : xfrm->opcode = MLX5_OPCODE_MMO;
376 : 0 : xfrm->type = xform->type;
377 [ # # # ]: 0 : switch (xform->type) {
378 : 0 : case RTE_COMP_COMPRESS:
379 [ # # # ]: 0 : switch (xform->compress.algo) {
380 : 0 : case RTE_COMP_ALGO_NULL:
381 : 0 : xfrm->opcode += MLX5_OPC_MOD_MMO_DMA <<
382 : : WQE_CSEG_OPC_MOD_OFFSET;
383 : 0 : break;
384 : 0 : case RTE_COMP_ALGO_DEFLATE:
385 : 0 : size = 1 << xform->compress.window_size;
386 [ # # ]: 0 : size /= MLX5_GGA_COMP_WIN_SIZE_UNITS;
387 : 0 : xfrm->gga_ctrl1 += RTE_MIN(rte_log2_u32(size),
388 : 0 : MLX5_COMP_MAX_WIN_SIZE_CONF) <<
389 : : WQE_GGA_COMP_WIN_SIZE_OFFSET;
390 : 0 : size = priv->log_block_sz;
391 : 0 : xfrm->gga_ctrl1 += size <<
392 : : WQE_GGA_COMP_BLOCK_SIZE_OFFSET;
393 : 0 : xfrm->opcode += MLX5_OPC_MOD_MMO_COMP <<
394 : : WQE_CSEG_OPC_MOD_OFFSET;
395 : 0 : size = xform->compress.deflate.huffman ==
396 : : RTE_COMP_HUFFMAN_DYNAMIC ?
397 [ # # ]: 0 : MLX5_GGA_COMP_LOG_DYNAMIC_SIZE_MAX :
398 : : MLX5_GGA_COMP_LOG_DYNAMIC_SIZE_MIN;
399 : 0 : xfrm->gga_ctrl1 += size <<
400 : : WQE_GGA_COMP_DYNAMIC_SIZE_OFFSET;
401 : 0 : break;
402 : 0 : default:
403 : 0 : goto err;
404 : : }
405 : 0 : xfrm->csum_type = xform->compress.chksum;
406 : 0 : break;
407 : 0 : case RTE_COMP_DECOMPRESS:
408 [ # # # # ]: 0 : switch (xform->decompress.algo) {
409 : 0 : case RTE_COMP_ALGO_NULL:
410 : 0 : xfrm->opcode += MLX5_OPC_MOD_MMO_DMA <<
411 : : WQE_CSEG_OPC_MOD_OFFSET;
412 : 0 : break;
413 : 0 : case RTE_COMP_ALGO_DEFLATE:
414 : 0 : xfrm->opcode += MLX5_OPC_MOD_MMO_DECOMP <<
415 : : WQE_CSEG_OPC_MOD_OFFSET;
416 : : xfrm->gga_ctrl1 += WQE_GGA_DECOMP_DEFLATE <<
417 : : WQE_GGA_DECOMP_TYPE_OFFSET;
418 : 0 : break;
419 : 0 : case RTE_COMP_ALGO_LZ4:
420 : 0 : xfrm->opcode += MLX5_OPC_MOD_MMO_DECOMP <<
421 : : WQE_CSEG_OPC_MOD_OFFSET;
422 : 0 : xfrm->gga_ctrl1 += WQE_GGA_DECOMP_LZ4 <<
423 : : WQE_GGA_DECOMP_TYPE_OFFSET;
424 [ # # ]: 0 : if (xform->decompress.lz4.flags &
425 : : RTE_COMP_LZ4_FLAG_BLOCK_CHECKSUM)
426 : 0 : xfrm->gga_ctrl1 +=
427 : : MLX5_GGA_DECOMP_LZ4_BLOCK_WITH_CHECKSUM <<
428 : : WQE_GGA_DECOMP_PARAMS_OFFSET;
429 : : else
430 : 0 : xfrm->gga_ctrl1 +=
431 : : MLX5_GGA_DECOMP_LZ4_BLOCK_WITHOUT_CHECKSUM
432 : : << WQE_GGA_DECOMP_PARAMS_OFFSET;
433 [ # # ]: 0 : if (xform->decompress.lz4.flags &
434 : : RTE_COMP_LZ4_FLAG_BLOCK_INDEPENDENCE)
435 : 0 : xfrm->gga_ctrl1 += 1u <<
436 : : WQE_GGA_DECOMP_BLOCK_INDEPENDENT_OFFSET;
437 : : break;
438 : 0 : default:
439 : 0 : goto err;
440 : : }
441 : 0 : xfrm->csum_type = xform->decompress.chksum;
442 : 0 : break;
443 : 0 : default:
444 : 0 : DRV_LOG(ERR, "Operation %u is not supported.", xform->type);
445 : 0 : goto err;
446 : : }
447 : 0 : DRV_LOG(DEBUG, "New xform: gga ctrl1 = 0x%08X opcode = 0x%08X csum "
448 : : "type = %d.", xfrm->gga_ctrl1, xfrm->opcode, xfrm->csum_type);
449 [ # # ]: 0 : xfrm->gga_ctrl1 = rte_cpu_to_be_32(xfrm->gga_ctrl1);
450 : 0 : rte_spinlock_lock(&priv->xform_sl);
451 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->xform_list, xfrm, next);
452 : : rte_spinlock_unlock(&priv->xform_sl);
453 : 0 : *private_xform = xfrm;
454 : 0 : return 0;
455 : 0 : err:
456 : 0 : rte_free(xfrm);
457 : 0 : return -ENOTSUP;
458 : : }
459 : :
460 : : static void
461 : 0 : mlx5_compress_dev_stop(struct rte_compressdev *dev)
462 : : {
463 : : RTE_SET_USED(dev);
464 : 0 : }
465 : :
466 : : static int
467 : 0 : mlx5_compress_dev_start(struct rte_compressdev *dev)
468 : : {
469 : 0 : struct mlx5_compress_priv *priv = dev->data->dev_private;
470 : :
471 : 0 : return mlx5_dev_mempool_subscribe(priv->cdev);
472 : : }
473 : :
474 : : static void
475 : 0 : mlx5_compress_stats_get(struct rte_compressdev *dev,
476 : : struct rte_compressdev_stats *stats)
477 : : {
478 : : int qp_id;
479 : :
480 [ # # ]: 0 : for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
481 : 0 : struct mlx5_compress_qp *qp = dev->data->queue_pairs[qp_id];
482 : :
483 : 0 : stats->enqueued_count += qp->stats.enqueued_count;
484 : 0 : stats->dequeued_count += qp->stats.dequeued_count;
485 : 0 : stats->enqueue_err_count += qp->stats.enqueue_err_count;
486 : 0 : stats->dequeue_err_count += qp->stats.dequeue_err_count;
487 : : }
488 : 0 : }
489 : :
490 : : static void
491 : 0 : mlx5_compress_stats_reset(struct rte_compressdev *dev)
492 : : {
493 : : int qp_id;
494 : :
495 [ # # ]: 0 : for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
496 : 0 : struct mlx5_compress_qp *qp = dev->data->queue_pairs[qp_id];
497 : :
498 : 0 : memset(&qp->stats, 0, sizeof(qp->stats));
499 : : }
500 : 0 : }
501 : :
502 : : static struct rte_compressdev_ops mlx5_compress_ops = {
503 : : .dev_configure = mlx5_compress_dev_configure,
504 : : .dev_start = mlx5_compress_dev_start,
505 : : .dev_stop = mlx5_compress_dev_stop,
506 : : .dev_close = mlx5_compress_dev_close,
507 : : .dev_infos_get = mlx5_compress_dev_info_get,
508 : : .stats_get = mlx5_compress_stats_get,
509 : : .stats_reset = mlx5_compress_stats_reset,
510 : : .queue_pair_setup = mlx5_compress_qp_setup,
511 : : .queue_pair_release = mlx5_compress_qp_release,
512 : : .private_xform_create = mlx5_compress_xform_create,
513 : : .private_xform_free = mlx5_compress_xform_free,
514 : : .stream_create = NULL,
515 : : .stream_free = NULL,
516 : : };
517 : :
518 : : static __rte_always_inline uint32_t
519 : : mlx5_compress_dseg_set(struct mlx5_compress_qp *qp,
520 : : volatile struct mlx5_wqe_dseg *restrict dseg,
521 : : struct rte_mbuf *restrict mbuf,
522 : : uint32_t offset, uint32_t len)
523 : : {
524 : 0 : uintptr_t addr = rte_pktmbuf_mtod_offset(mbuf, uintptr_t, offset);
525 : :
526 [ # # ]: 0 : dseg->bcount = rte_cpu_to_be_32(len);
527 [ # # ]: 0 : dseg->lkey = mlx5_mr_mb2mr(&qp->mr_ctrl, mbuf);
528 [ # # # # ]: 0 : dseg->pbuf = rte_cpu_to_be_64(addr);
529 : 0 : return dseg->lkey;
530 : : }
531 : :
532 : : static uint16_t
533 : 0 : mlx5_compress_enqueue_burst(void *queue_pair, struct rte_comp_op **ops,
534 : : uint16_t nb_ops)
535 : : {
536 : : struct mlx5_compress_qp *qp = queue_pair;
537 : 0 : volatile struct mlx5_gga_wqe *wqes = (volatile struct mlx5_gga_wqe *)
538 : : qp->qp.wqes, *wqe;
539 : : struct mlx5_compress_xform *xform;
540 : : struct rte_comp_op *op;
541 : 0 : uint16_t mask = qp->entries_n - 1;
542 : 0 : uint16_t remain = qp->entries_n - (qp->pi - qp->ci);
543 : : uint16_t idx;
544 : : bool invalid;
545 : :
546 : : if (remain < nb_ops)
547 : : nb_ops = remain;
548 : : else
549 : : remain = nb_ops;
550 [ # # ]: 0 : if (unlikely(remain == 0))
551 : : return 0;
552 : : do {
553 : 0 : idx = qp->pi & mask;
554 : 0 : wqe = &wqes[idx];
555 : 0 : rte_prefetch0(&wqes[(qp->pi + 1) & mask]);
556 : 0 : op = *ops++;
557 : 0 : xform = op->private_xform;
558 : : /*
559 : : * Check operation arguments and error cases:
560 : : * - Operation type must be state-less.
561 : : * - Compress operation flush flag must be FULL or FINAL.
562 : : * - Source and destination buffers must be mapped internally.
563 : : */
564 [ # # ]: 0 : invalid = op->op_type != RTE_COMP_OP_STATELESS ||
565 [ # # ]: 0 : (xform->type == RTE_COMP_COMPRESS &&
566 [ # # ]: 0 : op->flush_flag < RTE_COMP_FLUSH_FULL);
567 [ # # # # : 0 : if (unlikely(invalid ||
# # # # #
# ]
568 : : (mlx5_compress_dseg_set(qp, &wqe->gather,
569 : : op->m_src,
570 : : op->src.offset,
571 : : op->src.length) ==
572 : : UINT32_MAX) ||
573 : : (mlx5_compress_dseg_set(qp, &wqe->scatter,
574 : : op->m_dst,
575 : : op->dst.offset,
576 : : rte_pktmbuf_pkt_len(op->m_dst) -
577 : : op->dst.offset) ==
578 : : UINT32_MAX))) {
579 [ # # ]: 0 : op->status = invalid ? RTE_COMP_OP_STATUS_INVALID_ARGS :
580 : : RTE_COMP_OP_STATUS_ERROR;
581 : 0 : nb_ops -= remain;
582 [ # # ]: 0 : if (unlikely(nb_ops == 0))
583 : : return 0;
584 : : break;
585 : : }
586 : 0 : wqe->gga_ctrl1 = xform->gga_ctrl1;
587 [ # # ]: 0 : wqe->opcode = rte_cpu_to_be_32(xform->opcode + (qp->pi << 8));
588 : 0 : qp->ops[idx] = op;
589 : 0 : qp->pi++;
590 [ # # ]: 0 : } while (--remain);
591 : 0 : qp->stats.enqueued_count += nb_ops;
592 : 0 : mlx5_doorbell_ring(&qp->priv->uar.bf_db, *(volatile uint64_t *)wqe,
593 : 0 : qp->pi, &qp->qp.db_rec[MLX5_SND_DBR],
594 : 0 : !qp->priv->uar.dbnc);
595 : : return nb_ops;
596 : : }
597 : :
598 : : static void
599 : 0 : mlx5_compress_dump_err_objs(volatile uint32_t *cqe, volatile uint32_t *wqe,
600 : : volatile uint32_t *opaq)
601 : : {
602 : : size_t i;
603 : :
604 : 0 : DRV_LOG(ERR, "Error cqe:");
605 [ # # ]: 0 : for (i = 0; i < sizeof(struct mlx5_error_cqe) >> 2; i += 4)
606 : 0 : DRV_LOG(ERR, "%08X %08X %08X %08X", cqe[i], cqe[i + 1],
607 : : cqe[i + 2], cqe[i + 3]);
608 : 0 : DRV_LOG(ERR, "\nError wqe:");
609 [ # # ]: 0 : for (i = 0; i < sizeof(struct mlx5_gga_wqe) >> 2; i += 4)
610 : 0 : DRV_LOG(ERR, "%08X %08X %08X %08X", wqe[i], wqe[i + 1],
611 : : wqe[i + 2], wqe[i + 3]);
612 : 0 : DRV_LOG(ERR, "\nError opaq:");
613 [ # # ]: 0 : for (i = 0; i < sizeof(union mlx5_gga_compress_opaque) >> 2; i += 4)
614 : 0 : DRV_LOG(ERR, "%08X %08X %08X %08X", opaq[i], opaq[i + 1],
615 : : opaq[i + 2], opaq[i + 3]);
616 : 0 : }
617 : :
618 : : static void
619 : 0 : mlx5_compress_cqe_err_handle(struct mlx5_compress_qp *qp,
620 : : struct rte_comp_op *op)
621 : : {
622 : 0 : const uint32_t idx = qp->ci & (qp->entries_n - 1);
623 : 0 : volatile struct mlx5_error_cqe *cqe = (volatile struct mlx5_error_cqe *)
624 : 0 : &qp->cq.cqes[idx];
625 : 0 : volatile struct mlx5_gga_wqe *wqes = (volatile struct mlx5_gga_wqe *)
626 : : qp->qp.wqes;
627 : 0 : volatile union mlx5_gga_compress_opaque *opaq = qp->opaque_mr.addr;
628 : :
629 : 0 : volatile uint32_t *synd_word = RTE_PTR_ADD(cqe, MLX5_ERROR_CQE_SYNDROME_OFFSET);
630 [ # # # ]: 0 : switch (*synd_word) {
631 : 0 : case MLX5_GGA_COMP_OUT_OF_SPACE_SYNDROME_BE:
632 : 0 : op->status = RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED;
633 : 0 : DRV_LOG(DEBUG, "OUT OF SPACE error, output is bigger than dst buffer.");
634 : 0 : break;
635 : 0 : case MLX5_GGA_COMP_MISSING_BFINAL_SYNDROME_BE:
636 : 0 : DRV_LOG(DEBUG, "The last compressed block missed the B-final flag; maybe the compressed data is not complete or garbaged?");
637 : : /* fallthrough */
638 : 0 : default:
639 : 0 : op->status = RTE_COMP_OP_STATUS_ERROR;
640 : : }
641 : 0 : op->consumed = 0;
642 : 0 : op->produced = 0;
643 : 0 : op->output_chksum = 0;
644 : 0 : op->debug_status = rte_be_to_cpu_32(opaq[idx].syndrome) |
645 : 0 : ((uint64_t)rte_be_to_cpu_32(cqe->syndrome) << 32);
646 : 0 : mlx5_compress_dump_err_objs((volatile uint32_t *)cqe,
647 : 0 : (volatile uint32_t *)&wqes[idx],
648 : : (volatile uint32_t *)&opaq[idx]);
649 : 0 : qp->stats.dequeue_err_count++;
650 : 0 : }
651 : :
652 : : static uint16_t
653 : 0 : mlx5_compress_dequeue_burst(void *queue_pair, struct rte_comp_op **ops,
654 : : uint16_t nb_ops)
655 : : {
656 : : struct mlx5_compress_qp *qp = queue_pair;
657 : : volatile struct mlx5_compress_xform *restrict xform;
658 : : volatile struct mlx5_cqe *restrict cqe;
659 : 0 : volatile union mlx5_gga_compress_opaque *opaq = qp->opaque_mr.addr;
660 : : struct rte_comp_op *restrict op;
661 : 0 : const unsigned int cq_size = qp->entries_n;
662 : 0 : const unsigned int mask = cq_size - 1;
663 : : uint32_t idx;
664 : 0 : uint32_t next_idx = qp->ci & mask;
665 : 0 : const uint16_t max = RTE_MIN((uint16_t)(qp->pi - qp->ci), nb_ops);
666 : 0 : uint32_t crc32_idx = qp->priv->crc32_opaq_offs;
667 : : uint16_t i = 0;
668 : : int ret;
669 : :
670 [ # # ]: 0 : if (unlikely(max == 0))
671 : : return 0;
672 : : do {
673 : : idx = next_idx;
674 : 0 : next_idx = (qp->ci + 1) & mask;
675 : 0 : rte_prefetch0(&qp->cq.cqes[next_idx]);
676 : 0 : rte_prefetch0(qp->ops[next_idx]);
677 : 0 : op = qp->ops[idx];
678 [ # # ]: 0 : cqe = &qp->cq.cqes[idx];
679 : : ret = check_cqe(cqe, cq_size, qp->ci);
680 : : /*
681 : : * Be sure owner read is done before any other cookie field or
682 : : * opaque field.
683 : : */
684 : 0 : rte_io_rmb();
685 [ # # ]: 0 : if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
686 [ # # ]: 0 : if (likely(ret == MLX5_CQE_STATUS_HW_OWN))
687 : : break;
688 : 0 : mlx5_compress_cqe_err_handle(qp, op);
689 : : } else {
690 : 0 : xform = op->private_xform;
691 : 0 : op->status = RTE_COMP_OP_STATUS_SUCCESS;
692 : 0 : op->consumed = op->src.length;
693 : 0 : op->produced = rte_be_to_cpu_32(cqe->byte_cnt);
694 : : MLX5_ASSERT(cqe->byte_cnt ==
695 : : opaq[idx].scattered_length);
696 [ # # # # : 0 : switch (xform->csum_type) {
# ]
697 : 0 : case RTE_COMP_CHECKSUM_CRC32:
698 : 0 : op->output_chksum = (uint64_t)rte_be_to_cpu_32
699 : : (opaq[idx].data[crc32_idx]);
700 : 0 : break;
701 : 0 : case RTE_COMP_CHECKSUM_ADLER32:
702 : 0 : op->output_chksum = (uint64_t)rte_be_to_cpu_32
703 : : (opaq[idx].data[crc32_idx + 1]);
704 : 0 : break;
705 : 0 : case RTE_COMP_CHECKSUM_CRC32_ADLER32:
706 : 0 : op->output_chksum = (uint64_t)rte_be_to_cpu_32
707 : 0 : (opaq[idx].data[crc32_idx]) |
708 : 0 : ((uint64_t)rte_be_to_cpu_32
709 : 0 : (opaq[idx].data[crc32_idx + 1]) << 32);
710 : 0 : break;
711 : 0 : case RTE_COMP_CHECKSUM_XXHASH32:
712 : 0 : op->output_chksum = (uint64_t)rte_be_to_cpu_32
713 : : (opaq[idx].v2.xxh32);
714 : 0 : break;
715 : : default:
716 : : break;
717 : : }
718 : : }
719 : 0 : ops[i++] = op;
720 : 0 : qp->ci++;
721 [ # # ]: 0 : } while (i < max);
722 [ # # ]: 0 : if (likely(i != 0)) {
723 : 0 : rte_io_wmb();
724 [ # # ]: 0 : qp->cq.db_rec[0] = rte_cpu_to_be_32(qp->ci);
725 : 0 : qp->stats.dequeued_count += i;
726 : : }
727 : : return i;
728 : : }
729 : :
730 : : static int
731 : 0 : mlx5_compress_args_check_handler(const char *key, const char *val, void *opaque)
732 : : {
733 : : struct mlx5_compress_devarg_params *devarg_prms = opaque;
734 : :
735 [ # # ]: 0 : if (strcmp(key, "log-block-size") == 0) {
736 : 0 : errno = 0;
737 : 0 : devarg_prms->log_block_sz = (uint32_t)strtoul(val, NULL, 10);
738 [ # # ]: 0 : if (errno) {
739 : 0 : DRV_LOG(WARNING, "%s: \"%s\" is an invalid integer.",
740 : : key, val);
741 : 0 : return -errno;
742 : : }
743 : : }
744 : : return 0;
745 : : }
746 : :
747 : : static int
748 : 0 : mlx5_compress_handle_devargs(struct mlx5_kvargs_ctrl *mkvlist,
749 : : struct mlx5_compress_devarg_params *devarg_prms,
750 : : struct mlx5_hca_attr *att)
751 : : {
752 : 0 : const char **params = (const char *[]){
753 : : "log-block-size",
754 : : NULL,
755 : : };
756 : :
757 : 0 : devarg_prms->log_block_sz = MLX5_GGA_COMP_LOG_BLOCK_SIZE_MAX;
758 [ # # ]: 0 : if (mkvlist == NULL)
759 : : return 0;
760 [ # # ]: 0 : if (mlx5_kvargs_process(mkvlist, params,
761 : : mlx5_compress_args_check_handler,
762 : : devarg_prms) != 0) {
763 : 0 : DRV_LOG(ERR, "Devargs handler function Failed.");
764 : 0 : rte_errno = EINVAL;
765 : 0 : return -1;
766 : : }
767 [ # # ]: 0 : if (devarg_prms->log_block_sz > MLX5_GGA_COMP_LOG_BLOCK_SIZE_MAX ||
768 [ # # ]: 0 : devarg_prms->log_block_sz < att->compress_min_block_size) {
769 : 0 : DRV_LOG(WARNING, "Log block size provided is out of range("
770 : : "%u); default it to %u.",
771 : : devarg_prms->log_block_sz,
772 : : MLX5_GGA_COMP_LOG_BLOCK_SIZE_MAX);
773 : 0 : devarg_prms->log_block_sz = MLX5_GGA_COMP_LOG_BLOCK_SIZE_MAX;
774 : : }
775 : : return 0;
776 : : }
777 : :
778 : : static void
779 : 0 : mlx5_compress_fill_caps(struct mlx5_compress_priv *priv,
780 : : const struct mlx5_hca_attr *attr)
781 : : {
782 : : struct rte_compressdev_capabilities caps[] = {
783 : : {
784 : : .algo = RTE_COMP_ALGO_NULL,
785 : : .comp_feature_flags = RTE_COMP_FF_ADLER32_CHECKSUM |
786 : : RTE_COMP_FF_CRC32_CHECKSUM |
787 : : RTE_COMP_FF_CRC32_ADLER32_CHECKSUM |
788 : : RTE_COMP_FF_SHAREABLE_PRIV_XFORM,
789 : : },
790 : : {
791 : : .algo = RTE_COMP_ALGO_DEFLATE,
792 : : .comp_feature_flags = RTE_COMP_FF_ADLER32_CHECKSUM |
793 : : RTE_COMP_FF_CRC32_CHECKSUM |
794 : : RTE_COMP_FF_CRC32_ADLER32_CHECKSUM |
795 : : RTE_COMP_FF_SHAREABLE_PRIV_XFORM |
796 : : RTE_COMP_FF_HUFFMAN_FIXED |
797 : : RTE_COMP_FF_HUFFMAN_DYNAMIC,
798 : : .window_size = {.min = 10, .max = 15, .increment = 1},
799 : : },
800 : : {
801 : : .algo = RTE_COMP_ALGO_LZ4,
802 : : .comp_feature_flags = RTE_COMP_FF_XXHASH32_CHECKSUM |
803 : : RTE_COMP_FF_SHAREABLE_PRIV_XFORM |
804 : : RTE_COMP_FF_LZ4_BLOCK_INDEPENDENCE,
805 : : .window_size = {.min = 1, .max = 15, .increment = 1},
806 : : },
807 : : RTE_COMP_END_OF_CAPABILITIES_LIST()
808 : : };
809 : 0 : priv->caps[0] = caps[0];
810 : 0 : priv->caps[1] = caps[1];
811 [ # # ]: 0 : if (attr->decomp_lz4_checksum_en || attr->decomp_lz4_no_checksum_en) {
812 : 0 : priv->caps[2] = caps[2];
813 [ # # ]: 0 : if (attr->decomp_lz4_checksum_en)
814 : 0 : priv->caps[2].comp_feature_flags |=
815 : : RTE_COMP_FF_LZ4_BLOCK_WITH_CHECKSUM;
816 : 0 : priv->caps[3] = caps[3];
817 : : } else
818 : 0 : priv->caps[2] = caps[3];
819 : 0 : }
820 : :
821 : : static int
822 : 0 : mlx5_compress_dev_probe(struct mlx5_common_device *cdev,
823 : : struct mlx5_kvargs_ctrl *mkvlist)
824 : : {
825 : : struct rte_compressdev *compressdev;
826 : : struct mlx5_compress_priv *priv;
827 : 0 : struct mlx5_hca_attr *attr = &cdev->config.hca_attr;
828 : 0 : struct mlx5_compress_devarg_params devarg_prms = {0};
829 : 0 : struct rte_compressdev_pmd_init_params init_params = {
830 : : .name = "",
831 : 0 : .socket_id = cdev->dev->numa_node,
832 : : };
833 [ # # ]: 0 : const char *ibdev_name = mlx5_os_get_ctx_device_name(cdev->ctx);
834 : : uint32_t crc32_opaq_offset;
835 : :
836 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
837 : 0 : DRV_LOG(ERR, "Non-primary process type is not supported.");
838 : 0 : rte_errno = ENOTSUP;
839 : 0 : return -rte_errno;
840 : : }
841 : 0 : if (!attr->decomp_lz4_checksum_en && !attr->decomp_lz4_no_checksum_en &&
842 : : !attr->decomp_deflate_v1_en && !attr->decomp_deflate_v2_en &&
843 : : !attr->mmo_decompress_sq_en && !attr->mmo_compress_qp_en &&
844 [ # # ]: 0 : !attr->mmo_compress_sq_en && !attr->mmo_dma_qp_en &&
845 : : !attr->mmo_dma_sq_en) {
846 : 0 : DRV_LOG(ERR, "Not enough capabilities to support compress operations, maybe old FW/OFED version?");
847 : 0 : rte_errno = ENOTSUP;
848 : 0 : return -ENOTSUP;
849 : : }
850 : 0 : mlx5_compress_handle_devargs(mkvlist, &devarg_prms, attr);
851 : 0 : compressdev = rte_compressdev_pmd_create(ibdev_name, cdev->dev,
852 : : sizeof(*priv), &init_params);
853 [ # # ]: 0 : if (compressdev == NULL) {
854 : 0 : DRV_LOG(ERR, "Failed to create device \"%s\".", ibdev_name);
855 : 0 : return -ENODEV;
856 : : }
857 : 0 : DRV_LOG(INFO,
858 : : "Compress device %s was created successfully.", ibdev_name);
859 : 0 : compressdev->dev_ops = &mlx5_compress_ops;
860 : 0 : compressdev->dequeue_burst = mlx5_compress_dequeue_burst;
861 : 0 : compressdev->enqueue_burst = mlx5_compress_enqueue_burst;
862 : 0 : compressdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
863 : 0 : priv = compressdev->data->dev_private;
864 : 0 : priv->log_block_sz = devarg_prms.log_block_sz;
865 [ # # ]: 0 : if (attr->decomp_deflate_v2_en || attr->decomp_lz4_checksum_en ||
866 : : attr->decomp_lz4_no_checksum_en)
867 : : crc32_opaq_offset = offsetof(union mlx5_gga_compress_opaque,
868 : : v2.crc32);
869 : : else
870 : : crc32_opaq_offset = offsetof(union mlx5_gga_compress_opaque,
871 : : v1.crc32);
872 : : MLX5_ASSERT((crc32_opaq_offset % 4) == 0);
873 : 0 : priv->crc32_opaq_offs = crc32_opaq_offset / 4;
874 : 0 : priv->cdev = cdev;
875 : 0 : priv->compressdev = compressdev;
876 : 0 : mlx5_compress_fill_caps(priv, attr);
877 [ # # ]: 0 : if (mlx5_devx_uar_prepare(cdev, &priv->uar) != 0) {
878 : 0 : rte_compressdev_pmd_destroy(priv->compressdev);
879 : 0 : return -1;
880 : : }
881 : 0 : pthread_mutex_lock(&priv_list_lock);
882 : 0 : TAILQ_INSERT_TAIL(&mlx5_compress_priv_list, priv, next);
883 : 0 : pthread_mutex_unlock(&priv_list_lock);
884 : 0 : return 0;
885 : : }
886 : :
887 : : static int
888 : 0 : mlx5_compress_dev_remove(struct mlx5_common_device *cdev)
889 : : {
890 : : struct mlx5_compress_priv *priv = NULL;
891 : :
892 : 0 : pthread_mutex_lock(&priv_list_lock);
893 [ # # ]: 0 : TAILQ_FOREACH(priv, &mlx5_compress_priv_list, next)
894 [ # # ]: 0 : if (priv->compressdev->device == cdev->dev)
895 : : break;
896 [ # # ]: 0 : if (priv)
897 [ # # ]: 0 : TAILQ_REMOVE(&mlx5_compress_priv_list, priv, next);
898 : 0 : pthread_mutex_unlock(&priv_list_lock);
899 [ # # ]: 0 : if (priv) {
900 : 0 : mlx5_devx_uar_release(&priv->uar);
901 : 0 : rte_compressdev_pmd_destroy(priv->compressdev);
902 : : }
903 : 0 : return 0;
904 : : }
905 : :
906 : : static const struct rte_pci_id mlx5_compress_pci_id_map[] = {
907 : : {
908 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
909 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD2)
910 : : },
911 : : {
912 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
913 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD3)
914 : : },
915 : : {
916 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
917 : : PCI_DEVICE_ID_MELLANOX_CONNECTXVF)
918 : : },
919 : : {
920 : : .vendor_id = 0
921 : : }
922 : : };
923 : :
924 : : static struct mlx5_class_driver mlx5_compress_driver = {
925 : : .drv_class = MLX5_CLASS_COMPRESS,
926 : : .name = RTE_STR(MLX5_COMPRESS_DRIVER_NAME),
927 : : .id_table = mlx5_compress_pci_id_map,
928 : : .probe = mlx5_compress_dev_probe,
929 : : .remove = mlx5_compress_dev_remove,
930 : : };
931 : :
932 : 252 : RTE_INIT(rte_mlx5_compress_init)
933 : : {
934 : 252 : mlx5_common_init();
935 [ + - ]: 252 : if (mlx5_glue != NULL)
936 : 252 : mlx5_class_driver_register(&mlx5_compress_driver);
937 : 252 : }
938 : :
939 [ - + ]: 252 : RTE_LOG_REGISTER_DEFAULT(mlx5_compress_logtype, NOTICE)
940 : : RTE_PMD_EXPORT_NAME(MLX5_COMPRESS_DRIVER_NAME, __COUNTER__);
941 : : RTE_PMD_REGISTER_PCI_TABLE(MLX5_COMPRESS_DRIVER_NAME, mlx5_compress_pci_id_map);
942 : : RTE_PMD_REGISTER_KMOD_DEP(MLX5_COMPRESS_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");
|