1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2021 Intel Corporation
5 #include <rte_malloc.h>
6 #include <rte_common.h>
9 #include "idxd_internal.h"
11 #define IDXD_PMD_NAME_STR "dmadev_idxd"
14 idxd_dmadev_create(const char *name, struct rte_device *dev,
15 const struct idxd_dmadev *base_idxd,
16 const struct rte_dma_dev_ops *ops)
18 struct idxd_dmadev *idxd = NULL;
19 struct rte_dma_dev *dmadev = NULL;
23 IDXD_PMD_ERR("Invalid name of the device!");
28 /* Allocate device structure */
29 dmadev = rte_dma_pmd_allocate(name, dev->numa_node, sizeof(struct idxd_dmadev));
31 IDXD_PMD_ERR("Unable to allocate dma device");
35 dmadev->dev_ops = ops;
38 idxd = dmadev->data->dev_private;
39 *idxd = *base_idxd; /* copy over the main fields already passed in */
40 idxd->dmadev = dmadev;
42 /* allocate batch index ring and completion ring.
43 * The +1 is because we can never fully use
44 * the ring, otherwise read == write means both full and empty.
46 idxd->batch_comp_ring = rte_zmalloc_socket(NULL, (sizeof(idxd->batch_idx_ring[0]) +
47 sizeof(idxd->batch_comp_ring[0])) * (idxd->max_batches + 1),
48 sizeof(idxd->batch_comp_ring[0]), dev->numa_node);
49 if (idxd->batch_comp_ring == NULL) {
50 IDXD_PMD_ERR("Unable to reserve memory for batch data\n");
54 idxd->batch_idx_ring = (void *)&idxd->batch_comp_ring[idxd->max_batches+1];
55 idxd->batch_iova = rte_mem_virt2iova(idxd->batch_comp_ring);
57 dmadev->fp_obj->dev_private = idxd;
59 idxd->dmadev->state = RTE_DMA_DEV_READY;
65 rte_dma_pmd_release(name);
72 RTE_LOG_REGISTER_DEFAULT(idxd_pmd_logtype, WARNING);