1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
5 #include <rte_rawdev_pmd.h>
6 #include <rte_memzone.h>
7 #include <rte_common.h>
9 #include "ioat_private.h"
12 idxd_rawdev_close(struct rte_rawdev *dev __rte_unused)
18 idxd_dev_dump(struct rte_rawdev *dev, FILE *f)
20 struct idxd_rawdev *idxd = dev->dev_private;
21 struct rte_idxd_rawdev *rte_idxd = &idxd->public;
24 fprintf(f, "Raw Device #%d\n", dev->dev_id);
25 fprintf(f, "Driver: %s\n\n", dev->driver_name);
27 fprintf(f, "Portal: %p\n", rte_idxd->portal);
28 fprintf(f, "Batch Ring size: %u\n", rte_idxd->batch_ring_sz);
29 fprintf(f, "Comp Handle Ring size: %u\n\n", rte_idxd->hdl_ring_sz);
31 fprintf(f, "Next batch: %u\n", rte_idxd->next_batch);
32 fprintf(f, "Next batch to be completed: %u\n", rte_idxd->next_completed);
33 for (i = 0; i < rte_idxd->batch_ring_sz; i++) {
34 struct rte_idxd_desc_batch *b = &rte_idxd->batch_ring[i];
35 fprintf(f, "Batch %u @%p: submitted=%u, op_count=%u, hdl_end=%u\n",
36 i, b, b->submitted, b->op_count, b->hdl_end);
40 fprintf(f, "Next free hdl: %u\n", rte_idxd->next_free_hdl);
41 fprintf(f, "Last completed hdl: %u\n", rte_idxd->last_completed_hdl);
42 fprintf(f, "Next returned hdl: %u\n", rte_idxd->next_ret_hdl);
48 idxd_dev_configure(const struct rte_rawdev *dev,
49 rte_rawdev_obj_t config, size_t config_size)
51 struct idxd_rawdev *idxd = dev->dev_private;
52 struct rte_idxd_rawdev *rte_idxd = &idxd->public;
53 struct rte_ioat_rawdev_config *cfg = config;
54 uint16_t max_desc = cfg->ring_size;
55 uint16_t max_batches = max_desc / BATCH_SIZE;
58 if (config_size != sizeof(*cfg))
62 IOAT_PMD_ERR("%s: Error, device is started.", __func__);
66 rte_idxd->hdls_disable = cfg->hdls_disable;
68 /* limit the batches to what can be stored in hardware */
69 if (max_batches > idxd->max_batches) {
70 IOAT_PMD_DEBUG("Ring size of %u is too large for this device, need to limit to %u batches of %u",
71 max_desc, idxd->max_batches, BATCH_SIZE);
72 max_batches = idxd->max_batches;
73 max_desc = max_batches * BATCH_SIZE;
75 if (!rte_is_power_of_2(max_desc))
76 max_desc = rte_align32pow2(max_desc);
77 IOAT_PMD_DEBUG("Rawdev %u using %u descriptors in %u batches",
78 dev->dev_id, max_desc, max_batches);
80 /* in case we are reconfiguring a device, free any existing memory */
81 rte_free(rte_idxd->batch_ring);
82 rte_free(rte_idxd->hdl_ring);
84 rte_idxd->batch_ring = rte_zmalloc(NULL,
85 sizeof(*rte_idxd->batch_ring) * max_batches, 0);
86 if (rte_idxd->batch_ring == NULL)
89 rte_idxd->hdl_ring = rte_zmalloc(NULL,
90 sizeof(*rte_idxd->hdl_ring) * max_desc, 0);
91 if (rte_idxd->hdl_ring == NULL) {
92 rte_free(rte_idxd->batch_ring);
93 rte_idxd->batch_ring = NULL;
96 rte_idxd->batch_ring_sz = max_batches;
97 rte_idxd->hdl_ring_sz = max_desc;
99 for (i = 0; i < rte_idxd->batch_ring_sz; i++) {
100 struct rte_idxd_desc_batch *b = &rte_idxd->batch_ring[i];
101 b->batch_desc.completion = rte_mem_virt2iova(&b->comp);
102 b->batch_desc.desc_addr = rte_mem_virt2iova(&b->null_desc);
103 b->batch_desc.op_flags = (idxd_op_batch << IDXD_CMD_OP_SHIFT) |
104 IDXD_FLAG_COMPLETION_ADDR_VALID |
105 IDXD_FLAG_REQUEST_COMPLETION;
112 idxd_rawdev_create(const char *name, struct rte_device *dev,
113 const struct idxd_rawdev *base_idxd,
114 const struct rte_rawdev_ops *ops)
116 struct idxd_rawdev *idxd;
117 struct rte_rawdev *rawdev = NULL;
118 const struct rte_memzone *mz = NULL;
119 char mz_name[RTE_MEMZONE_NAMESIZE];
122 RTE_BUILD_BUG_ON(sizeof(struct rte_idxd_hw_desc) != 64);
123 RTE_BUILD_BUG_ON(offsetof(struct rte_idxd_hw_desc, size) != 32);
124 RTE_BUILD_BUG_ON(sizeof(struct rte_idxd_completion) != 32);
127 IOAT_PMD_ERR("Invalid name of the device!");
132 /* Allocate device structure */
133 rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct idxd_rawdev),
135 if (rawdev == NULL) {
136 IOAT_PMD_ERR("Unable to allocate raw device");
141 snprintf(mz_name, sizeof(mz_name), "rawdev%u_private", rawdev->dev_id);
142 mz = rte_memzone_reserve(mz_name, sizeof(struct idxd_rawdev),
143 dev->numa_node, RTE_MEMZONE_IOVA_CONTIG);
145 IOAT_PMD_ERR("Unable to reserve memzone for private data\n");
149 rawdev->dev_private = mz->addr;
150 rawdev->dev_ops = ops;
151 rawdev->device = dev;
152 rawdev->driver_name = IOAT_PMD_RAWDEV_NAME_STR;
154 idxd = rawdev->dev_private;
155 *idxd = *base_idxd; /* copy over the main fields already passed in */
156 idxd->public.type = RTE_IDXD_DEV;
157 idxd->rawdev = rawdev;
164 rte_rawdev_pmd_release(rawdev);