]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/include/spdk/ioat.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / include / spdk / ioat.h
CommitLineData
7c673cae
FG
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file
35 * I/OAT DMA engine driver public interface
36 */
37
38#ifndef SPDK_IOAT_H
39#define SPDK_IOAT_H
40
11fdf7f2
TL
41#include "spdk/stdinc.h"
42
7c673cae
FG
43#ifdef __cplusplus
44extern "C" {
45#endif
46
7c673cae
FG
47#include "spdk/env.h"
48
49/**
50 * Opaque handle for a single I/OAT channel returned by \ref spdk_ioat_probe().
51 */
52struct spdk_ioat_chan;
53
54/**
55 * Signature for callback function invoked when a request is completed.
56 *
11fdf7f2
TL
57 * \param arg User-specified opaque value corresponding to cb_arg from the
58 * request submission.
7c673cae
FG
59 */
60typedef void (*spdk_ioat_req_cb)(void *arg);
61
62/**
63 * Callback for spdk_ioat_probe() enumeration.
64 *
65 * \param cb_ctx User-specified opaque value corresponding to cb_ctx from spdk_ioat_probe().
66 * \param pci_dev PCI device that is being probed.
67 *
68 * \return true to attach to this device.
69 */
70typedef bool (*spdk_ioat_probe_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev);
71
72/**
11fdf7f2
TL
73 * Callback for spdk_ioat_probe() to report a device that has been attached to
74 * the userspace I/OAT driver.
7c673cae
FG
75 *
76 * \param cb_ctx User-specified opaque value corresponding to cb_ctx from spdk_ioat_probe().
77 * \param pci_dev PCI device that was attached to the driver.
78 * \param ioat I/OAT channel that was attached to the driver.
79 */
80typedef void (*spdk_ioat_attach_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev,
81 struct spdk_ioat_chan *ioat);
82
83/**
11fdf7f2
TL
84 * Enumerate the I/OAT devices attached to the system and attach the userspace
85 * I/OAT driver to them if desired.
7c673cae 86 *
11fdf7f2
TL
87 * If called more than once, only devices that are not already attached to the
88 * SPDK I/OAT driver will be reported.
89 *
90 * To stop using the controller and release its associated resources, call
91 * spdk_ioat_detach() with the ioat_channel instance returned by this function.
7c673cae 92 *
11fdf7f2
TL
93 * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of
94 * the callbacks.
95 * \param probe_cb will be called once per I/OAT device found in the system.
96 * \param attach_cb will be called for devices for which probe_cb returned true
97 * once the I/OAT controller has been attached to the userspace driver.
7c673cae 98 *
11fdf7f2 99 * \return 0 on success, -1 on failure.
7c673cae
FG
100 */
101int spdk_ioat_probe(void *cb_ctx, spdk_ioat_probe_cb probe_cb, spdk_ioat_attach_cb attach_cb);
102
103/**
11fdf7f2 104 * Detach specified device returned by spdk_ioat_probe() from the I/OAT driver.
7c673cae
FG
105 *
106 * \param ioat I/OAT channel to detach from the driver.
11fdf7f2
TL
107 */
108void spdk_ioat_detach(struct spdk_ioat_chan *ioat);
7c673cae
FG
109
110/**
9f95a23c
TL
111 * Build a DMA engine memory copy request.
112 *
113 * This function will build the descriptor in the channel's ring. The
114 * caller must also explicitly call spdk_ioat_flush to submit the
115 * descriptor, possibly after building additional descriptors.
116 *
117 * \param chan I/OAT channel to build request.
118 * \param cb_arg Opaque value which will be passed back as the arg parameter in
119 * the completion callback.
120 * \param cb_fn Callback function which will be called when the request is complete.
121 * \param dst Destination virtual address.
122 * \param src Source virtual address.
123 * \param nbytes Number of bytes to copy.
124 *
125 * \return 0 on success, negative errno on failure.
126 */
127int spdk_ioat_build_copy(struct spdk_ioat_chan *chan,
128 void *cb_arg, spdk_ioat_req_cb cb_fn,
129 void *dst, const void *src, uint64_t nbytes);
130
131/**
132 * Build and submit a DMA engine memory copy request.
133 *
134 * This function will build the descriptor in the channel's ring and then
135 * immediately submit it by writing the channel's doorbell. Calling this
136 * function does not require a subsequent call to spdk_ioat_flush.
7c673cae
FG
137 *
138 * \param chan I/OAT channel to submit request.
11fdf7f2
TL
139 * \param cb_arg Opaque value which will be passed back as the arg parameter in
140 * the completion callback.
7c673cae
FG
141 * \param cb_fn Callback function which will be called when the request is complete.
142 * \param dst Destination virtual address.
143 * \param src Source virtual address.
144 * \param nbytes Number of bytes to copy.
11fdf7f2
TL
145 *
146 * \return 0 on success, negative errno on failure.
7c673cae 147 */
11fdf7f2
TL
148int spdk_ioat_submit_copy(struct spdk_ioat_chan *chan,
149 void *cb_arg, spdk_ioat_req_cb cb_fn,
150 void *dst, const void *src, uint64_t nbytes);
7c673cae
FG
151
152/**
9f95a23c
TL
153 * Build a DMA engine memory fill request.
154 *
155 * This function will build the descriptor in the channel's ring. The
156 * caller must also explicitly call spdk_ioat_flush to submit the
157 * descriptor, possibly after building additional descriptors.
158 *
159 * \param chan I/OAT channel to build request.
160 * \param cb_arg Opaque value which will be passed back as the cb_arg parameter
161 * in the completion callback.
162 * \param cb_fn Callback function which will be called when the request is complete.
163 * \param dst Destination virtual address.
164 * \param fill_pattern Repeating eight-byte pattern to use for memory fill.
165 * \param nbytes Number of bytes to fill.
166 *
167 * \return 0 on success, negative errno on failure.
168 */
169int spdk_ioat_build_fill(struct spdk_ioat_chan *chan,
170 void *cb_arg, spdk_ioat_req_cb cb_fn,
171 void *dst, uint64_t fill_pattern, uint64_t nbytes);
172
173/**
174 * Build and submit a DMA engine memory fill request.
175 *
176 * This function will build the descriptor in the channel's ring and then
177 * immediately submit it by writing the channel's doorbell. Calling this
178 * function does not require a subsequent call to spdk_ioat_flush.
7c673cae
FG
179 *
180 * \param chan I/OAT channel to submit request.
11fdf7f2
TL
181 * \param cb_arg Opaque value which will be passed back as the cb_arg parameter
182 * in the completion callback.
7c673cae
FG
183 * \param cb_fn Callback function which will be called when the request is complete.
184 * \param dst Destination virtual address.
185 * \param fill_pattern Repeating eight-byte pattern to use for memory fill.
186 * \param nbytes Number of bytes to fill.
11fdf7f2
TL
187 *
188 * \return 0 on success, negative errno on failure.
7c673cae 189 */
11fdf7f2
TL
190int spdk_ioat_submit_fill(struct spdk_ioat_chan *chan,
191 void *cb_arg, spdk_ioat_req_cb cb_fn,
192 void *dst, uint64_t fill_pattern, uint64_t nbytes);
7c673cae 193
9f95a23c
TL
194/**
195 * Flush previously built descriptors.
196 *
197 * Descriptors are flushed by writing the channel's dmacount doorbell
198 * register. This function enables batching multiple descriptors followed by
199 * a single doorbell write.
200 *
201 * \param chan I/OAT channel to flush.
202 */
203void spdk_ioat_flush(struct spdk_ioat_chan *chan);
204
7c673cae
FG
205/**
206 * Check for completed requests on an I/OAT channel.
207 *
208 * \param chan I/OAT channel to check for completions.
209 *
11fdf7f2 210 * \return 0 on success, negative errno on failure.
7c673cae
FG
211 */
212int spdk_ioat_process_events(struct spdk_ioat_chan *chan);
213
214/**
215 * DMA engine capability flags
216 */
217enum spdk_ioat_dma_capability_flags {
218 SPDK_IOAT_ENGINE_COPY_SUPPORTED = 0x1, /**< The memory copy is supported */
219 SPDK_IOAT_ENGINE_FILL_SUPPORTED = 0x2, /**< The memory fill is supported */
220};
221
222/**
223 * Get the DMA engine capabilities.
224 *
225 * \param chan I/OAT channel to query.
226 *
11fdf7f2 227 * \return a combination of flags from spdk_ioat_dma_capability_flags().
7c673cae
FG
228 */
229uint32_t spdk_ioat_get_dma_capabilities(struct spdk_ioat_chan *chan);
230
231#ifdef __cplusplus
232}
233#endif
234
235#endif