1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
5 #ifndef _RTE_IOAT_RAWDEV_H_
6 #define _RTE_IOAT_RAWDEV_H_
9 * @file rte_ioat_rawdev.h
11 * Definitions for using the ioat rawdev device driver
14 * @b EXPERIMENTAL: these structures and APIs may change without prior notice
17 #include <x86intrin.h>
18 #include <rte_atomic.h>
19 #include <rte_memory.h>
20 #include <rte_memzone.h>
21 #include <rte_prefetch.h>
22 #include "rte_ioat_spec.h"
24 /** Name of the device driver */
25 #define IOAT_PMD_RAWDEV_NAME rawdev_ioat
26 /** String reported as the device driver name by rte_rawdev_info_get() */
27 #define IOAT_PMD_RAWDEV_NAME_STR "rawdev_ioat"
30 * Configuration structure for an ioat rawdev instance
32 * This structure is to be passed as the ".dev_private" parameter when
33 * calling the rte_rawdev_get_info() and rte_rawdev_configure() APIs on
34 * an ioat rawdev instance.
36 struct rte_ioat_rawdev_config {
37 unsigned short ring_size;
42 * Structure representing a device instance
44 struct rte_ioat_rawdev {
45 struct rte_rawdev *rawdev;
46 const struct rte_memzone *mz;
47 const struct rte_memzone *desc_mz;
49 volatile struct rte_ioat_registers *regs;
50 phys_addr_t status_addr;
51 phys_addr_t ring_addr;
53 unsigned short ring_size;
54 struct rte_ioat_generic_hw_desc *desc_ring;
55 __m128i *hdls; /* completion handles for returning to user */
58 unsigned short next_read;
59 unsigned short next_write;
61 /* some statistics for tracking, if added/changed update xstats fns*/
62 uint64_t enqueue_failed __rte_cache_aligned;
67 /* to report completions, the device will write status back here */
68 volatile uint64_t status __rte_cache_aligned;
72 * Enqueue a copy operation onto the ioat device
74 * This queues up a copy operation to be performed by hardware, but does not
75 * trigger hardware to begin that operation.
78 * The rawdev device id of the ioat instance
80 * The physical address of the source buffer
82 * The physical address of the destination buffer
84 * The length of the data to be copied
86 * An opaque handle for the source data, to be returned when this operation
87 * has been completed and the user polls for the completion details
89 * An opaque handle for the destination data, to be returned when this
90 * operation has been completed and the user polls for the completion details
92 * A flag parameter indicating that hardware should not begin to perform any
93 * subsequently enqueued copy operations until after this operation has
96 * Number of operations enqueued, either 0 or 1
99 rte_ioat_enqueue_copy(int dev_id, phys_addr_t src, phys_addr_t dst,
100 unsigned int length, uintptr_t src_hdl, uintptr_t dst_hdl,
103 struct rte_ioat_rawdev *ioat = rte_rawdevs[dev_id].dev_private;
104 unsigned short read = ioat->next_read;
105 unsigned short write = ioat->next_write;
106 unsigned short mask = ioat->ring_size - 1;
107 unsigned short space = mask + read - write;
108 struct rte_ioat_generic_hw_desc *desc;
111 ioat->enqueue_failed++;
115 ioat->next_write = write + 1;
118 desc = &ioat->desc_ring[write];
120 /* set descriptor write-back every 16th descriptor */
121 desc->u.control_raw = (uint32_t)((!!fence << 4) | (!(write & 0xF)) << 3);
122 desc->src_addr = src;
123 desc->dest_addr = dst;
125 ioat->hdls[write] = _mm_set_epi64x((int64_t)dst_hdl, (int64_t)src_hdl);
126 rte_prefetch0(&ioat->desc_ring[ioat->next_write & mask]);
133 * Trigger hardware to begin performing enqueued copy operations
135 * This API is used to write the "doorbell" to the hardware to trigger it
136 * to begin the copy operations previously enqueued by rte_ioat_enqueue_copy()
139 * The rawdev device id of the ioat instance
142 rte_ioat_do_copies(int dev_id)
144 struct rte_ioat_rawdev *ioat = rte_rawdevs[dev_id].dev_private;
145 ioat->desc_ring[(ioat->next_write - 1) & (ioat->ring_size - 1)].u
146 .control.completion_update = 1;
147 rte_compiler_barrier();
148 ioat->regs->dmacount = ioat->next_write;
149 ioat->started = ioat->enqueued;
154 * Returns the index of the last completed operation.
157 rte_ioat_get_last_completed(struct rte_ioat_rawdev *ioat, int *error)
159 uint64_t status = ioat->status;
161 /* lower 3 bits indicate "transfer status" : active, idle, halted.
162 * We can ignore bit 0.
164 *error = status & (RTE_IOAT_CHANSTS_SUSPENDED | RTE_IOAT_CHANSTS_ARMED);
165 return (status - ioat->ring_addr) >> 6;
169 * Returns details of copy operations that have been completed
171 * Returns to the caller the user-provided "handles" for the copy operations
172 * which have been completed by the hardware, and not already returned by
173 * a previous call to this API.
176 * The rawdev device id of the ioat instance
178 * The number of entries which can fit in the src_hdls and dst_hdls
179 * arrays, i.e. max number of completed operations to report
181 * Array to hold the source handle parameters of the completed copies
183 * Array to hold the destination handle parameters of the completed copies
185 * -1 on error, with rte_errno set appropriately.
186 * Otherwise number of completed operations i.e. number of entries written
187 * to the src_hdls and dst_hdls array parameters.
190 rte_ioat_completed_copies(int dev_id, uint8_t max_copies,
191 uintptr_t *src_hdls, uintptr_t *dst_hdls)
193 struct rte_ioat_rawdev *ioat = rte_rawdevs[dev_id].dev_private;
194 unsigned short mask = (ioat->ring_size - 1);
195 unsigned short read = ioat->next_read;
196 unsigned short end_read, count;
200 end_read = (rte_ioat_get_last_completed(ioat, &error) + 1) & mask;
201 count = (end_read - (read & mask)) & mask;
208 if (count > max_copies)
211 for (; i < count - 1; i += 2, read += 2) {
212 __m128i hdls0 = _mm_load_si128(&ioat->hdls[read & mask]);
213 __m128i hdls1 = _mm_load_si128(&ioat->hdls[(read + 1) & mask]);
215 _mm_storeu_si128((void *)&src_hdls[i],
216 _mm_unpacklo_epi64(hdls0, hdls1));
217 _mm_storeu_si128((void *)&dst_hdls[i],
218 _mm_unpackhi_epi64(hdls0, hdls1));
220 for (; i < count; i++, read++) {
221 uintptr_t *hdls = (void *)&ioat->hdls[read & mask];
222 src_hdls[i] = hdls[0];
223 dst_hdls[i] = hdls[1];
226 ioat->next_read = read;
227 ioat->completed += count;
231 #endif /* _RTE_IOAT_RAWDEV_H_ */