xref: /freebsd/sys/dev/ioat/ioat.h (revision f8f92e9180b21f817a1738bdcdd9c5fd3abd5601)
1e974f91cSConrad Meyer /*-
2e974f91cSConrad Meyer  * Copyright (C) 2012 Intel Corporation
3e974f91cSConrad Meyer  * All rights reserved.
4e974f91cSConrad Meyer  *
5e974f91cSConrad Meyer  * Redistribution and use in source and binary forms, with or without
6e974f91cSConrad Meyer  * modification, are permitted provided that the following conditions
7e974f91cSConrad Meyer  * are met:
8e974f91cSConrad Meyer  * 1. Redistributions of source code must retain the above copyright
9e974f91cSConrad Meyer  *    notice, this list of conditions and the following disclaimer.
10e974f91cSConrad Meyer  * 2. Redistributions in binary form must reproduce the above copyright
11e974f91cSConrad Meyer  *    notice, this list of conditions and the following disclaimer in the
12e974f91cSConrad Meyer  *    documentation and/or other materials provided with the distribution.
13e974f91cSConrad Meyer  *
14e974f91cSConrad Meyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15e974f91cSConrad Meyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16e974f91cSConrad Meyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17e974f91cSConrad Meyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18e974f91cSConrad Meyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19e974f91cSConrad Meyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20e974f91cSConrad Meyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21e974f91cSConrad Meyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22e974f91cSConrad Meyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23e974f91cSConrad Meyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24e974f91cSConrad Meyer  * SUCH DAMAGE.
25e974f91cSConrad Meyer  */
26e974f91cSConrad Meyer 
27e974f91cSConrad Meyer __FBSDID("$FreeBSD$");
28e974f91cSConrad Meyer 
29e974f91cSConrad Meyer #ifndef __IOAT_H__
30e974f91cSConrad Meyer #define __IOAT_H__
31e974f91cSConrad Meyer 
32e974f91cSConrad Meyer #include <sys/param.h>
33e974f91cSConrad Meyer #include <machine/bus.h>
34e974f91cSConrad Meyer 
35e974f91cSConrad Meyer /*
36e974f91cSConrad Meyer  * This file defines the public interface to the IOAT driver.
37e974f91cSConrad Meyer  */
38e974f91cSConrad Meyer 
39e974f91cSConrad Meyer /*
40e974f91cSConrad Meyer  * Enables an interrupt for this operation. Typically, you would only enable
41e974f91cSConrad Meyer  * this on the last operation in a group
42e974f91cSConrad Meyer  */
43e974f91cSConrad Meyer #define	DMA_INT_EN	0x1
44bf8553eaSConrad Meyer /*
45bf8553eaSConrad Meyer  * Like M_NOWAIT.  Operations will return NULL if they cannot allocate a
46bf8553eaSConrad Meyer  * descriptor without blocking.
47bf8553eaSConrad Meyer  */
48bf8553eaSConrad Meyer #define	DMA_NO_WAIT	0x2
496ca07079SConrad Meyer /*
506ca07079SConrad Meyer  * Disallow prefetching the source of the following operation.  Ordinarily, DMA
516ca07079SConrad Meyer  * operations can be pipelined on some hardware.  E.g., operation 2's source
526ca07079SConrad Meyer  * may be prefetched before operation 1 completes.
536ca07079SConrad Meyer  */
546ca07079SConrad Meyer #define	DMA_FENCE	0x4
55bec7ff79SConrad Meyer #define	_DMA_GENERIC_FLAGS	(DMA_INT_EN | DMA_NO_WAIT | DMA_FENCE)
56bec7ff79SConrad Meyer 
57bec7ff79SConrad Meyer /*
58bec7ff79SConrad Meyer  * Emit a CRC32C as the result of a ioat_copy_crc() or ioat_crc().
59bec7ff79SConrad Meyer  */
60bec7ff79SConrad Meyer #define	DMA_CRC_STORE	0x8
61bec7ff79SConrad Meyer 
62bec7ff79SConrad Meyer /*
63bec7ff79SConrad Meyer  * Compare the CRC32C of a ioat_copy_crc() or ioat_crc() against an expeceted
64bec7ff79SConrad Meyer  * value.  It is invalid to specify both TEST and STORE.
65bec7ff79SConrad Meyer  */
66bec7ff79SConrad Meyer #define	DMA_CRC_TEST	0x10
67bec7ff79SConrad Meyer #define	_DMA_CRC_TESTSTORE	(DMA_CRC_STORE | DMA_CRC_TEST)
68bec7ff79SConrad Meyer 
69bec7ff79SConrad Meyer /*
70bec7ff79SConrad Meyer  * Use an inline comparison CRC32C or emit an inline CRC32C result.  Invalid
71bec7ff79SConrad Meyer  * without one of STORE or TEST.
72bec7ff79SConrad Meyer  */
73bec7ff79SConrad Meyer #define	DMA_CRC_INLINE	0x20
74bec7ff79SConrad Meyer #define	_DMA_CRC_FLAGS	(DMA_CRC_STORE | DMA_CRC_TEST | DMA_CRC_INLINE)
75e974f91cSConrad Meyer 
7631bf2875SConrad Meyer /*
7731bf2875SConrad Meyer  * Hardware revision number.  Different hardware revisions support different
7831bf2875SConrad Meyer  * features.  For example, 3.2 cannot read from MMIO space, while 3.3 can.
7931bf2875SConrad Meyer  */
8031bf2875SConrad Meyer #define	IOAT_VER_3_0			0x30
8131bf2875SConrad Meyer #define	IOAT_VER_3_2			0x32
8231bf2875SConrad Meyer #define	IOAT_VER_3_3			0x33
8331bf2875SConrad Meyer 
84e974f91cSConrad Meyer typedef void *bus_dmaengine_t;
85e974f91cSConrad Meyer struct bus_dmadesc;
86faefad9cSConrad Meyer typedef void (*bus_dmaengine_callback_t)(void *arg, int error);
87e974f91cSConrad Meyer 
88*f8f92e91SConrad Meyer unsigned ioat_get_nchannels(void);
89*f8f92e91SConrad Meyer 
90e974f91cSConrad Meyer /*
91e974f91cSConrad Meyer  * Called first to acquire a reference to the DMA channel
920ff814e8SConrad Meyer  *
930ff814e8SConrad Meyer  * Flags may be M_WAITOK or M_NOWAIT.
94e974f91cSConrad Meyer  */
950ff814e8SConrad Meyer bus_dmaengine_t ioat_get_dmaengine(uint32_t channel_index, int flags);
96e974f91cSConrad Meyer 
97466b3540SConrad Meyer /* Release the DMA channel */
98466b3540SConrad Meyer void ioat_put_dmaengine(bus_dmaengine_t dmaengine);
99466b3540SConrad Meyer 
10031bf2875SConrad Meyer /* Check the DMA engine's HW version */
10131bf2875SConrad Meyer int ioat_get_hwversion(bus_dmaengine_t dmaengine);
102bd81fe68SConrad Meyer size_t ioat_get_max_io_size(bus_dmaengine_t dmaengine);
10331bf2875SConrad Meyer 
104e974f91cSConrad Meyer /*
1055ca9fc2aSConrad Meyer  * Set interrupt coalescing on a DMA channel.
1065ca9fc2aSConrad Meyer  *
1075ca9fc2aSConrad Meyer  * The argument is in microseconds.  A zero value disables coalescing.  Any
1085ca9fc2aSConrad Meyer  * other value delays interrupt generation for N microseconds to provide
1095ca9fc2aSConrad Meyer  * opportunity to coalesce multiple operations into a single interrupt.
1105ca9fc2aSConrad Meyer  *
1115ca9fc2aSConrad Meyer  * Returns an error status, or zero on success.
1125ca9fc2aSConrad Meyer  *
1135ca9fc2aSConrad Meyer  * - ERANGE if the given value exceeds the delay supported by the hardware.
1145ca9fc2aSConrad Meyer  *   (All current hardware supports a maximum of 0x3fff microseconds delay.)
1155ca9fc2aSConrad Meyer  * - ENODEV if the hardware does not support interrupt coalescing.
1165ca9fc2aSConrad Meyer  */
1175ca9fc2aSConrad Meyer int ioat_set_interrupt_coalesce(bus_dmaengine_t dmaengine, uint16_t delay);
1185ca9fc2aSConrad Meyer 
1195ca9fc2aSConrad Meyer /*
1205ca9fc2aSConrad Meyer  * Return the maximum supported coalescing period, for use in
1215ca9fc2aSConrad Meyer  * ioat_set_interrupt_coalesce().  If the hardware does not support coalescing,
1225ca9fc2aSConrad Meyer  * returns zero.
1235ca9fc2aSConrad Meyer  */
1245ca9fc2aSConrad Meyer uint16_t ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine);
1255ca9fc2aSConrad Meyer 
1265ca9fc2aSConrad Meyer /*
127e974f91cSConrad Meyer  * Acquire must be called before issuing an operation to perform. Release is
128e974f91cSConrad Meyer  * called after.  Multiple operations can be issued within the context of one
129e974f91cSConrad Meyer  * acquire and release
130e974f91cSConrad Meyer  */
131e974f91cSConrad Meyer void ioat_acquire(bus_dmaengine_t dmaengine);
132e974f91cSConrad Meyer void ioat_release(bus_dmaengine_t dmaengine);
1331502e363SConrad Meyer 
1341502e363SConrad Meyer /*
1351502e363SConrad Meyer  * Acquire_reserve can be called to ensure there is room for N descriptors.  If
1361502e363SConrad Meyer  * it succeeds, the next N valid operations will successfully enqueue.
1371502e363SConrad Meyer  *
1381502e363SConrad Meyer  * It may fail with:
1391502e363SConrad Meyer  *   - ENXIO if the channel is in an errored state, or the driver is being
1401502e363SConrad Meyer  *     unloaded
1411502e363SConrad Meyer  *   - EAGAIN if mflags included M_NOWAIT
1421502e363SConrad Meyer  *
1431502e363SConrad Meyer  * On failure, the caller does not hold the dmaengine.
1441502e363SConrad Meyer  */
1451502e363SConrad Meyer int ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags);
146e974f91cSConrad Meyer 
1472a4fd6b1SConrad Meyer /*
1482a4fd6b1SConrad Meyer  * Issue a blockfill operation.  The 64-bit pattern 'fillpattern' is written to
1492a4fd6b1SConrad Meyer  * 'len' physically contiguous bytes at 'dst'.
1501693d27bSConrad Meyer  *
1511693d27bSConrad Meyer  * Only supported on devices with the BFILL capability.
1522a4fd6b1SConrad Meyer  */
1532a4fd6b1SConrad Meyer struct bus_dmadesc *ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t dst,
1542a4fd6b1SConrad Meyer     uint64_t fillpattern, bus_size_t len, bus_dmaengine_callback_t callback_fn,
1552a4fd6b1SConrad Meyer     void *callback_arg, uint32_t flags);
1562a4fd6b1SConrad Meyer 
157e974f91cSConrad Meyer /* Issues the copy data operation */
158e974f91cSConrad Meyer struct bus_dmadesc *ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst,
159e974f91cSConrad Meyer     bus_addr_t src, bus_size_t len, bus_dmaengine_callback_t callback_fn,
160e974f91cSConrad Meyer     void *callback_arg, uint32_t flags);
161e974f91cSConrad Meyer 
162e974f91cSConrad Meyer /*
1639950fde0SConrad Meyer  * Issue a copy data operation, with constraints:
1649950fde0SConrad Meyer  *  - src1, src2, dst1, dst2 are all page-aligned addresses
1659950fde0SConrad Meyer  *  - The quantity to copy is exactly 2 pages;
1669950fde0SConrad Meyer  *  - src1 -> dst1, src2 -> dst2
1679950fde0SConrad Meyer  *
1689950fde0SConrad Meyer  * Why use this instead of normal _copy()?  You can copy two non-contiguous
1699950fde0SConrad Meyer  * pages (src, dst, or both) with one descriptor.
1709950fde0SConrad Meyer  */
1719950fde0SConrad Meyer struct bus_dmadesc *ioat_copy_8k_aligned(bus_dmaengine_t dmaengine,
1729950fde0SConrad Meyer     bus_addr_t dst1, bus_addr_t dst2, bus_addr_t src1, bus_addr_t src2,
1739950fde0SConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
1749950fde0SConrad Meyer 
1759950fde0SConrad Meyer /*
176bec7ff79SConrad Meyer  * Copy len bytes from dst to src, like ioat_copy().
177bec7ff79SConrad Meyer  *
178bec7ff79SConrad Meyer  * Additionally, accumulate a CRC32C of the data.
179bec7ff79SConrad Meyer  *
180bec7ff79SConrad Meyer  * If initialseed is not NULL, the value it points to is used to seed the
181bec7ff79SConrad Meyer  * initial value of the CRC32C.
182bec7ff79SConrad Meyer  *
183bec7ff79SConrad Meyer  * If flags include DMA_CRC_STORE and not DMA_CRC_INLINE, crcptr is written
184bec7ff79SConrad Meyer  * with the 32-bit CRC32C result (in wire format).
185bec7ff79SConrad Meyer  *
186bec7ff79SConrad Meyer  * If flags include DMA_CRC_TEST and not DMA_CRC_INLINE, the computed CRC32C is
187bec7ff79SConrad Meyer  * compared with the 32-bit CRC32C pointed to by crcptr.  If they do not match,
188bec7ff79SConrad Meyer  * a channel error is raised.
189bec7ff79SConrad Meyer  *
190bec7ff79SConrad Meyer  * If the DMA_CRC_INLINE flag is set, crcptr is ignored and the DMA engine uses
191bec7ff79SConrad Meyer  * the 4 bytes trailing the source data (TEST) or the destination data (STORE).
192bec7ff79SConrad Meyer  */
193bec7ff79SConrad Meyer struct bus_dmadesc *ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t dst,
194bec7ff79SConrad Meyer     bus_addr_t src, bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr,
195bec7ff79SConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
196bec7ff79SConrad Meyer 
197bec7ff79SConrad Meyer /*
198bec7ff79SConrad Meyer  * ioat_crc() is nearly identical to ioat_copy_crc(), but does not actually
199bec7ff79SConrad Meyer  * move data around.
200bec7ff79SConrad Meyer  *
201bec7ff79SConrad Meyer  * Like ioat_copy_crc, ioat_crc computes a CRC32C over len bytes pointed to by
202bec7ff79SConrad Meyer  * src.  The flags affect its operation in the same way, with one exception:
203bec7ff79SConrad Meyer  *
204bec7ff79SConrad Meyer  * If flags includes both DMA_CRC_STORE and DMA_CRC_INLINE, the computed CRC32C
205bec7ff79SConrad Meyer  * is written to the 4 bytes trailing the *source* data.
206bec7ff79SConrad Meyer  */
207bec7ff79SConrad Meyer struct bus_dmadesc *ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src,
208bec7ff79SConrad Meyer     bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr,
209bec7ff79SConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
210bec7ff79SConrad Meyer 
211bec7ff79SConrad Meyer /*
212e974f91cSConrad Meyer  * Issues a null operation. This issues the operation to the hardware, but the
213e974f91cSConrad Meyer  * hardware doesn't do anything with it.
214e974f91cSConrad Meyer  */
215e974f91cSConrad Meyer struct bus_dmadesc *ioat_null(bus_dmaengine_t dmaengine,
216e974f91cSConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
217e974f91cSConrad Meyer 
218e974f91cSConrad Meyer 
219e974f91cSConrad Meyer #endif /* __IOAT_H__ */
220e974f91cSConrad Meyer 
221