1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2022 Intel Corporation
5 #include <rte_malloc.h>
8 #include "qat_comp_pmd.h"
10 #define QAT_PMD_COMP_SGL_DEF_SEGMENTS 16
12 struct qat_comp_gen_dev_ops qat_comp_gen_dev_ops[QAT_N_GENS];
14 struct stream_create_info {
15 struct qat_comp_dev_private *comp_dev;
21 qat_comp_capabilities_info qat_comp_get_capa_info(
22 enum qat_device_gen qat_dev_gen, struct qat_pci_device *qat_dev)
24 struct qat_comp_capabilities_info ret = { .data = NULL, .size = 0 };
26 if (qat_dev_gen >= QAT_N_GENS)
28 RTE_FUNC_PTR_OR_ERR_RET(qat_comp_gen_dev_ops[qat_dev_gen]
29 .qat_comp_get_capabilities, ret);
30 return qat_comp_gen_dev_ops[qat_dev_gen]
31 .qat_comp_get_capabilities(qat_dev);
35 qat_comp_stats_get(struct rte_compressdev *dev,
36 struct rte_compressdev_stats *stats)
38 struct qat_common_stats qat_stats = {0};
39 struct qat_comp_dev_private *qat_priv;
41 if (stats == NULL || dev == NULL) {
42 QAT_LOG(ERR, "invalid ptr: stats %p, dev %p", stats, dev);
45 qat_priv = dev->data->dev_private;
47 qat_stats_get(qat_priv->qat_dev, &qat_stats, QAT_SERVICE_COMPRESSION);
48 stats->enqueued_count = qat_stats.enqueued_count;
49 stats->dequeued_count = qat_stats.dequeued_count;
50 stats->enqueue_err_count = qat_stats.enqueue_err_count;
51 stats->dequeue_err_count = qat_stats.dequeue_err_count;
55 qat_comp_stats_reset(struct rte_compressdev *dev)
57 struct qat_comp_dev_private *qat_priv;
60 QAT_LOG(ERR, "invalid compressdev ptr %p", dev);
63 qat_priv = dev->data->dev_private;
65 qat_stats_reset(qat_priv->qat_dev, QAT_SERVICE_COMPRESSION);
70 qat_comp_qp_release(struct rte_compressdev *dev, uint16_t queue_pair_id)
72 struct qat_comp_dev_private *qat_private = dev->data->dev_private;
73 struct qat_qp **qp_addr =
74 (struct qat_qp **)&(dev->data->queue_pairs[queue_pair_id]);
75 struct qat_qp *qp = (struct qat_qp *)*qp_addr;
76 enum qat_device_gen qat_dev_gen = qat_private->qat_dev->qat_dev_gen;
79 QAT_LOG(DEBUG, "Release comp qp %u on device %d",
80 queue_pair_id, dev->data->dev_id);
82 qat_private->qat_dev->qps_in_use[QAT_SERVICE_COMPRESSION][queue_pair_id]
86 for (i = 0; i < qp->nb_descriptors; i++) {
87 struct qat_comp_op_cookie *cookie = qp->op_cookies[i];
89 rte_free(cookie->qat_sgl_src_d);
90 rte_free(cookie->qat_sgl_dst_d);
93 return qat_qp_release(qat_dev_gen, (struct qat_qp **)
94 &(dev->data->queue_pairs[queue_pair_id]));
98 qat_comp_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
99 uint32_t max_inflight_ops, int socket_id)
101 struct qat_qp_config qat_qp_conf = {0};
102 struct qat_qp **qp_addr =
103 (struct qat_qp **)&(dev->data->queue_pairs[qp_id]);
104 struct qat_comp_dev_private *qat_private = dev->data->dev_private;
105 struct qat_pci_device *qat_dev = qat_private->qat_dev;
110 /* If qp is already in use free ring memory and qp metadata. */
111 if (*qp_addr != NULL) {
112 ret = qat_comp_qp_release(dev, qp_id);
116 if (qp_id >= qat_qps_per_service(qat_dev,
117 QAT_SERVICE_COMPRESSION)) {
118 QAT_LOG(ERR, "qp_id %u invalid for this device", qp_id);
123 qat_qp_conf.hw = qat_qp_get_hw_data(qat_dev, QAT_SERVICE_COMPRESSION,
125 if (qat_qp_conf.hw == NULL) {
126 QAT_LOG(ERR, "qp_id %u invalid for this device", qp_id);
129 qat_qp_conf.cookie_size = sizeof(struct qat_comp_op_cookie);
130 qat_qp_conf.nb_descriptors = max_inflight_ops;
131 qat_qp_conf.socket_id = socket_id;
132 qat_qp_conf.service_str = "comp";
134 ret = qat_qp_setup(qat_private->qat_dev, qp_addr, qp_id, &qat_qp_conf);
137 /* store a link to the qp in the qat_pci_device */
138 qat_private->qat_dev->qps_in_use[QAT_SERVICE_COMPRESSION][qp_id]
141 qp = (struct qat_qp *)*qp_addr;
142 qp->min_enq_burst_threshold = qat_private->min_enq_burst_threshold;
144 for (i = 0; i < qp->nb_descriptors; i++) {
146 struct qat_comp_op_cookie *cookie =
150 cookie->cookie_index = i;
152 cookie->qat_sgl_src_d = rte_zmalloc_socket(NULL,
153 sizeof(struct qat_sgl) +
154 sizeof(struct qat_flat_buf) *
155 QAT_PMD_COMP_SGL_DEF_SEGMENTS,
156 64, dev->data->socket_id);
158 cookie->qat_sgl_dst_d = rte_zmalloc_socket(NULL,
159 sizeof(struct qat_sgl) +
160 sizeof(struct qat_flat_buf) *
161 QAT_PMD_COMP_SGL_DEF_SEGMENTS,
162 64, dev->data->socket_id);
164 if (cookie->qat_sgl_src_d == NULL ||
165 cookie->qat_sgl_dst_d == NULL) {
166 QAT_LOG(ERR, "Can't allocate SGL"
168 qat_private->qat_dev->name);
172 cookie->qat_sgl_src_phys_addr =
173 rte_malloc_virt2iova(cookie->qat_sgl_src_d);
175 cookie->qat_sgl_dst_phys_addr =
176 rte_malloc_virt2iova(cookie->qat_sgl_dst_d);
178 cookie->dst_nb_elems = cookie->src_nb_elems =
179 QAT_PMD_COMP_SGL_DEF_SEGMENTS;
181 cookie->socket_id = dev->data->socket_id;
190 #define QAT_IM_BUFFER_DEBUG 0
191 const struct rte_memzone *
192 qat_comp_setup_inter_buffers(struct qat_comp_dev_private *comp_dev,
195 char inter_buff_mz_name[RTE_MEMZONE_NAMESIZE];
196 const struct rte_memzone *memzone;
197 uint8_t *mz_start = NULL;
198 rte_iova_t mz_start_phys = 0;
199 struct array_of_ptrs *array_of_pointers;
200 int size_of_ptr_array;
202 uint32_t offset_of_flat_buffs;
204 int num_im_sgls = qat_comp_get_num_im_bufs_required(
205 comp_dev->qat_dev->qat_dev_gen);
207 QAT_LOG(DEBUG, "QAT COMP device %s needs %d sgls",
208 comp_dev->qat_dev->name, num_im_sgls);
209 snprintf(inter_buff_mz_name, RTE_MEMZONE_NAMESIZE,
210 "%s_inter_buff", comp_dev->qat_dev->name);
211 memzone = rte_memzone_lookup(inter_buff_mz_name);
212 if (memzone != NULL) {
213 QAT_LOG(DEBUG, "QAT COMP im buffer memzone created already");
217 /* Create multiple memzones to hold intermediate buffers and associated
218 * meta-data needed by the firmware.
219 * The first memzone contains:
220 * - a list of num_im_sgls physical pointers to sgls
221 * All other memzones contain:
222 * - the sgl structure, pointing to QAT_NUM_BUFS_IN_IM_SGL flat buffers
223 * - the flat buffers: QAT_NUM_BUFS_IN_IM_SGL buffers,
225 * num_im_sgls depends on the hardware generation of the device
226 * buff_size comes from the user via the config file
229 size_of_ptr_array = num_im_sgls * sizeof(phys_addr_t);
230 offset_of_flat_buffs = sizeof(struct qat_inter_sgl);
231 full_size = offset_of_flat_buffs +
232 buff_size * QAT_NUM_BUFS_IN_IM_SGL;
234 memzone = rte_memzone_reserve_aligned(inter_buff_mz_name,
236 comp_dev->compressdev->data->socket_id,
237 RTE_MEMZONE_IOVA_CONTIG, QAT_64_BYTE_ALIGN);
238 if (memzone == NULL) {
240 "Can't allocate intermediate buffers for device %s",
241 comp_dev->qat_dev->name);
245 mz_start = (uint8_t *)memzone->addr;
246 mz_start_phys = memzone->iova;
247 QAT_LOG(DEBUG, "Memzone %s: addr = %p, phys = 0x%"PRIx64
248 ", size required %d, size created %zu",
249 inter_buff_mz_name, mz_start, mz_start_phys,
250 size_of_ptr_array, memzone->len);
252 array_of_pointers = (struct array_of_ptrs *)mz_start;
253 for (i = 0; i < num_im_sgls; i++) {
254 const struct rte_memzone *mz;
255 struct qat_inter_sgl *sgl;
258 snprintf(inter_buff_mz_name, RTE_MEMZONE_NAMESIZE,
259 "%s_inter_buff_%d", comp_dev->qat_dev->name, i);
260 mz = rte_memzone_lookup(inter_buff_mz_name);
262 mz = rte_memzone_reserve_aligned(inter_buff_mz_name,
264 comp_dev->compressdev->data->socket_id,
265 RTE_MEMZONE_IOVA_CONTIG,
269 "Can't allocate intermediate buffers for device %s",
270 comp_dev->qat_dev->name);
272 snprintf(inter_buff_mz_name,
273 RTE_MEMZONE_NAMESIZE,
275 comp_dev->qat_dev->name,
279 inter_buff_mz_name));
281 rte_memzone_free(memzone);
286 QAT_LOG(DEBUG, "Memzone %s: addr = %p, phys = 0x%"PRIx64
287 ", size required %d, size created %zu",
288 inter_buff_mz_name, mz->addr, mz->iova,
291 array_of_pointers->pointer[i] = mz->iova;
293 sgl = (struct qat_inter_sgl *) mz->addr;
294 sgl->num_bufs = QAT_NUM_BUFS_IN_IM_SGL;
295 sgl->num_mapped_bufs = 0;
298 #if QAT_IM_BUFFER_DEBUG
299 QAT_LOG(DEBUG, " : phys addr of sgl[%i] in array_of_pointers"
300 " = 0x%"PRIx64, i, array_of_pointers->pointer[i]);
301 QAT_LOG(DEBUG, " : virt address of sgl[%i] = %p", i, sgl);
303 for (lb = 0; lb < QAT_NUM_BUFS_IN_IM_SGL; lb++) {
304 sgl->buffers[lb].addr =
305 mz->iova + offset_of_flat_buffs +
307 sgl->buffers[lb].len = buff_size;
308 sgl->buffers[lb].resrvd = 0;
309 #if QAT_IM_BUFFER_DEBUG
311 " : sgl->buffers[%d].addr = 0x%"PRIx64", len=%d",
312 lb, sgl->buffers[lb].addr, sgl->buffers[lb].len);
316 #if QAT_IM_BUFFER_DEBUG
317 QAT_DP_HEXDUMP_LOG(DEBUG, "IM buffer memzone start:",
318 memzone->addr, size_of_ptr_array);
323 static struct rte_mempool *
324 qat_comp_create_xform_pool(struct qat_comp_dev_private *comp_dev,
325 struct rte_compressdev_config *config,
326 uint32_t num_elements)
328 char xform_pool_name[RTE_MEMPOOL_NAMESIZE];
329 struct rte_mempool *mp;
331 snprintf(xform_pool_name, RTE_MEMPOOL_NAMESIZE,
332 "%s_xforms", comp_dev->qat_dev->name);
334 QAT_LOG(DEBUG, "xformpool: %s", xform_pool_name);
335 mp = rte_mempool_lookup(xform_pool_name);
338 QAT_LOG(DEBUG, "xformpool already created");
339 if (mp->size != num_elements) {
340 QAT_LOG(DEBUG, "xformpool wrong size - delete it");
341 rte_mempool_free(mp);
343 comp_dev->xformpool = NULL;
348 mp = rte_mempool_create(xform_pool_name,
350 qat_comp_xform_size(), 0, 0,
351 NULL, NULL, NULL, NULL, config->socket_id,
354 QAT_LOG(ERR, "Err creating mempool %s w %d elements of size %d",
355 xform_pool_name, num_elements, qat_comp_xform_size());
363 qat_comp_stream_init(struct rte_mempool *mp __rte_unused, void *opaque,
364 void *obj, unsigned int obj_idx)
366 struct stream_create_info *info = opaque;
367 struct qat_comp_stream *stream = obj;
368 char mz_name[RTE_MEMZONE_NAMESIZE];
369 const struct rte_memzone *memzone;
370 struct qat_inter_sgl *ram_banks_desc;
372 /* find a memzone for RAM banks */
373 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "%s_%u_rambanks",
374 info->comp_dev->qat_dev->name, obj_idx);
375 memzone = rte_memzone_lookup(mz_name);
376 if (memzone == NULL) {
377 /* allocate a memzone for compression state and RAM banks */
378 memzone = rte_memzone_reserve_aligned(mz_name,
379 QAT_STATE_REGISTERS_MAX_SIZE
380 + sizeof(struct qat_inter_sgl)
381 + QAT_INFLATE_CONTEXT_SIZE,
383 RTE_MEMZONE_IOVA_CONTIG, QAT_64_BYTE_ALIGN);
384 if (memzone == NULL) {
386 "Can't allocate RAM banks for device %s, object %u",
387 info->comp_dev->qat_dev->name, obj_idx);
388 info->error = -ENOMEM;
393 /* prepare the buffer list descriptor for RAM banks */
394 ram_banks_desc = (struct qat_inter_sgl *)
395 (((uint8_t *) memzone->addr) + QAT_STATE_REGISTERS_MAX_SIZE);
396 ram_banks_desc->num_bufs = 1;
397 ram_banks_desc->buffers[0].len = QAT_INFLATE_CONTEXT_SIZE;
398 ram_banks_desc->buffers[0].addr = memzone->iova
399 + QAT_STATE_REGISTERS_MAX_SIZE
400 + sizeof(struct qat_inter_sgl);
402 memset(stream, 0, qat_comp_stream_size());
403 stream->memzone = memzone;
404 stream->state_registers_decomp = memzone->addr;
405 stream->state_registers_decomp_phys = memzone->iova;
406 stream->inflate_context = ((uint8_t *) memzone->addr)
407 + QAT_STATE_REGISTERS_MAX_SIZE;
408 stream->inflate_context_phys = memzone->iova
409 + QAT_STATE_REGISTERS_MAX_SIZE;
413 qat_comp_stream_destroy(struct rte_mempool *mp __rte_unused,
414 void *opaque __rte_unused, void *obj,
415 unsigned obj_idx __rte_unused)
417 struct qat_comp_stream *stream = obj;
419 rte_memzone_free(stream->memzone);
422 static struct rte_mempool *
423 qat_comp_create_stream_pool(struct qat_comp_dev_private *comp_dev,
425 uint32_t num_elements)
427 char stream_pool_name[RTE_MEMPOOL_NAMESIZE];
428 struct rte_mempool *mp;
430 snprintf(stream_pool_name, RTE_MEMPOOL_NAMESIZE,
431 "%s_streams", comp_dev->qat_dev->name);
433 QAT_LOG(DEBUG, "streampool: %s", stream_pool_name);
434 mp = rte_mempool_lookup(stream_pool_name);
437 QAT_LOG(DEBUG, "streampool already created");
438 if (mp->size != num_elements) {
439 QAT_LOG(DEBUG, "streampool wrong size - delete it");
440 rte_mempool_obj_iter(mp, qat_comp_stream_destroy, NULL);
441 rte_mempool_free(mp);
443 comp_dev->streampool = NULL;
448 struct stream_create_info info = {
449 .comp_dev = comp_dev,
450 .socket_id = socket_id,
453 mp = rte_mempool_create(stream_pool_name,
455 qat_comp_stream_size(), 0, 0,
456 NULL, NULL, qat_comp_stream_init, &info,
460 "Err creating mempool %s w %d elements of size %d",
461 stream_pool_name, num_elements,
462 qat_comp_stream_size());
463 } else if (info.error) {
464 rte_mempool_obj_iter(mp, qat_comp_stream_destroy, NULL);
466 "Destroying mempool %s as at least one element failed initialisation",
468 rte_mempool_free(mp);
477 _qat_comp_dev_config_clear(struct qat_comp_dev_private *comp_dev)
479 /* Free intermediate buffers */
480 if (comp_dev->interm_buff_mz) {
481 char mz_name[RTE_MEMZONE_NAMESIZE];
482 int i = qat_comp_get_num_im_bufs_required(
483 comp_dev->qat_dev->qat_dev_gen);
486 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
488 comp_dev->qat_dev->name, i);
489 rte_memzone_free(rte_memzone_lookup(mz_name));
491 rte_memzone_free(comp_dev->interm_buff_mz);
492 comp_dev->interm_buff_mz = NULL;
495 /* Free private_xform pool */
496 if (comp_dev->xformpool) {
497 /* Free internal mempool for private xforms */
498 rte_mempool_free(comp_dev->xformpool);
499 comp_dev->xformpool = NULL;
502 /* Free stream pool */
503 if (comp_dev->streampool) {
504 rte_mempool_obj_iter(comp_dev->streampool,
505 qat_comp_stream_destroy, NULL);
506 rte_mempool_free(comp_dev->streampool);
507 comp_dev->streampool = NULL;
512 qat_comp_dev_config(struct rte_compressdev *dev,
513 struct rte_compressdev_config *config)
515 struct qat_comp_dev_private *comp_dev = dev->data->dev_private;
518 if (config->max_nb_priv_xforms) {
519 comp_dev->xformpool = qat_comp_create_xform_pool(comp_dev,
520 config, config->max_nb_priv_xforms);
521 if (comp_dev->xformpool == NULL) {
526 comp_dev->xformpool = NULL;
528 if (config->max_nb_streams) {
529 comp_dev->streampool = qat_comp_create_stream_pool(comp_dev,
530 config->socket_id, config->max_nb_streams);
531 if (comp_dev->streampool == NULL) {
536 comp_dev->streampool = NULL;
541 _qat_comp_dev_config_clear(comp_dev);
546 qat_comp_dev_start(struct rte_compressdev *dev __rte_unused)
552 qat_comp_dev_stop(struct rte_compressdev *dev __rte_unused)
558 qat_comp_dev_close(struct rte_compressdev *dev)
562 struct qat_comp_dev_private *comp_dev = dev->data->dev_private;
564 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
565 ret = qat_comp_qp_release(dev, i);
570 _qat_comp_dev_config_clear(comp_dev);
576 qat_comp_dev_info_get(struct rte_compressdev *dev,
577 struct rte_compressdev_info *info)
579 struct qat_comp_dev_private *comp_dev = dev->data->dev_private;
580 struct qat_pci_device *qat_dev = comp_dev->qat_dev;
583 info->max_nb_queue_pairs =
584 qat_qps_per_service(qat_dev,
585 QAT_SERVICE_COMPRESSION);
586 info->feature_flags = dev->feature_flags;
587 info->capabilities = comp_dev->qat_dev_capabilities;
592 qat_comp_pmd_enq_deq_dummy_op_burst(void *qp __rte_unused,
593 struct rte_comp_op **ops __rte_unused,
594 uint16_t nb_ops __rte_unused)
596 QAT_DP_LOG(ERR, "QAT PMD detected wrong FW version !");
600 static struct rte_compressdev_ops compress_qat_dummy_ops = {
602 /* Device related operations */
603 .dev_configure = NULL,
605 .dev_stop = qat_comp_dev_stop,
606 .dev_close = qat_comp_dev_close,
607 .dev_infos_get = NULL,
610 .stats_reset = qat_comp_stats_reset,
611 .queue_pair_setup = NULL,
612 .queue_pair_release = qat_comp_qp_release,
614 /* Compression related operations */
615 .private_xform_create = NULL,
616 .private_xform_free = qat_comp_private_xform_free
620 qat_comp_dequeue_burst(void *qp, struct rte_comp_op **ops, uint16_t nb_ops)
622 return qat_dequeue_op_burst(qp, (void **)ops, qat_comp_process_response,
627 qat_comp_pmd_dequeue_first_op_burst(void *qp, struct rte_comp_op **ops,
630 uint16_t ret = qat_comp_dequeue_burst(qp, ops, nb_ops);
631 struct qat_qp *tmp_qp = (struct qat_qp *)qp;
634 if ((*ops)->debug_status ==
635 (uint64_t)ERR_CODE_QAT_COMP_WRONG_FW) {
636 tmp_qp->qat_dev->comp_dev->compressdev->enqueue_burst =
637 qat_comp_pmd_enq_deq_dummy_op_burst;
638 tmp_qp->qat_dev->comp_dev->compressdev->dequeue_burst =
639 qat_comp_pmd_enq_deq_dummy_op_burst;
641 tmp_qp->qat_dev->comp_dev->compressdev->dev_ops =
642 &compress_qat_dummy_ops;
644 "This QAT hardware doesn't support compression operation");
647 tmp_qp->qat_dev->comp_dev->compressdev->dequeue_burst =
648 qat_comp_dequeue_burst;
654 /* An rte_driver is needed in the registration of the device with compressdev.
655 * The actual qat pci's rte_driver can't be used as its name represents
656 * the whole pci device with all services. Think of this as a holder for a name
657 * for the compression part of the pci device.
659 static const char qat_comp_drv_name[] = RTE_STR(COMPRESSDEV_NAME_QAT_PMD);
660 static const struct rte_driver compdev_qat_driver = {
661 .name = qat_comp_drv_name,
662 .alias = qat_comp_drv_name
666 qat_comp_dev_create(struct qat_pci_device *qat_pci_dev,
667 struct qat_dev_cmd_param *qat_dev_cmd_param)
670 struct qat_device_info *qat_dev_instance =
671 &qat_pci_devs[qat_pci_dev->qat_dev_id];
672 struct rte_compressdev_pmd_init_params init_params = {
674 .socket_id = qat_dev_instance->pci_dev->device.numa_node,
676 char name[RTE_COMPRESSDEV_NAME_MAX_LEN];
677 char capa_memz_name[RTE_COMPRESSDEV_NAME_MAX_LEN];
678 struct rte_compressdev *compressdev;
679 struct qat_comp_dev_private *comp_dev;
680 struct qat_comp_capabilities_info capabilities_info;
681 const struct rte_compressdev_capabilities *capabilities;
682 const struct qat_comp_gen_dev_ops *qat_comp_gen_ops =
683 &qat_comp_gen_dev_ops[qat_pci_dev->qat_dev_gen];
686 snprintf(name, RTE_COMPRESSDEV_NAME_MAX_LEN, "%s_%s",
687 qat_pci_dev->name, "comp");
688 QAT_LOG(DEBUG, "Creating QAT COMP device %s", name);
690 if (qat_comp_gen_ops->compressdev_ops == NULL) {
691 QAT_LOG(DEBUG, "Device %s does not support compression", name);
695 /* Populate subset device to use in compressdev device creation */
696 qat_dev_instance->comp_rte_dev.driver = &compdev_qat_driver;
697 qat_dev_instance->comp_rte_dev.numa_node =
698 qat_dev_instance->pci_dev->device.numa_node;
699 qat_dev_instance->comp_rte_dev.devargs = NULL;
701 compressdev = rte_compressdev_pmd_create(name,
702 &(qat_dev_instance->comp_rte_dev),
703 sizeof(struct qat_comp_dev_private),
706 if (compressdev == NULL)
709 compressdev->dev_ops = qat_comp_gen_ops->compressdev_ops;
711 compressdev->enqueue_burst = (compressdev_enqueue_pkt_burst_t)
712 qat_enqueue_comp_op_burst;
713 compressdev->dequeue_burst = qat_comp_pmd_dequeue_first_op_burst;
714 compressdev->feature_flags =
715 qat_comp_gen_ops->qat_comp_get_feature_flags();
717 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
720 snprintf(capa_memz_name, RTE_COMPRESSDEV_NAME_MAX_LEN,
721 "QAT_COMP_CAPA_GEN_%d",
722 qat_pci_dev->qat_dev_gen);
724 comp_dev = compressdev->data->dev_private;
725 comp_dev->qat_dev = qat_pci_dev;
726 comp_dev->compressdev = compressdev;
728 capabilities_info = qat_comp_get_capa_info(qat_pci_dev->qat_dev_gen,
731 if (capabilities_info.data == NULL) {
733 "QAT gen %d capabilities unknown, default to GEN1",
734 qat_pci_dev->qat_dev_gen);
735 capabilities_info = qat_comp_get_capa_info(QAT_GEN1,
739 capabilities = capabilities_info.data;
740 capa_size = capabilities_info.size;
742 comp_dev->capa_mz = rte_memzone_lookup(capa_memz_name);
743 if (comp_dev->capa_mz == NULL) {
744 comp_dev->capa_mz = rte_memzone_reserve(capa_memz_name,
748 if (comp_dev->capa_mz == NULL) {
750 "Error allocating memzone for capabilities, destroying PMD for %s",
752 memset(&qat_dev_instance->comp_rte_dev, 0,
753 sizeof(qat_dev_instance->comp_rte_dev));
754 rte_compressdev_pmd_destroy(compressdev);
758 memcpy(comp_dev->capa_mz->addr, capabilities, capa_size);
759 comp_dev->qat_dev_capabilities = comp_dev->capa_mz->addr;
762 if (qat_dev_cmd_param[i].name == NULL)
764 if (!strcmp(qat_dev_cmd_param[i].name, COMP_ENQ_THRESHOLD_NAME))
765 comp_dev->min_enq_burst_threshold =
766 qat_dev_cmd_param[i].val;
769 qat_pci_dev->comp_dev = comp_dev;
772 "Created QAT COMP device %s as compressdev instance %d",
773 name, compressdev->data->dev_id);
778 qat_comp_dev_destroy(struct qat_pci_device *qat_pci_dev)
780 struct qat_comp_dev_private *comp_dev;
782 if (qat_pci_dev == NULL)
785 comp_dev = qat_pci_dev->comp_dev;
786 if (comp_dev == NULL)
789 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
790 rte_memzone_free(qat_pci_dev->comp_dev->capa_mz);
792 /* clean up any resources used by the device */
793 qat_comp_dev_close(comp_dev->compressdev);
795 rte_compressdev_pmd_destroy(comp_dev->compressdev);
796 qat_pci_dev->comp_dev = NULL;