xref: /freebsd/sys/dev/ioat/ioat.h (revision 685dc743dc3b5645e34836464128e1c0558b404b)
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 #ifndef __IOAT_H__
27e974f91cSConrad Meyer #define __IOAT_H__
28e974f91cSConrad Meyer 
29e974f91cSConrad Meyer #include <sys/param.h>
30e974f91cSConrad Meyer #include <machine/bus.h>
31e974f91cSConrad Meyer 
32e974f91cSConrad Meyer /*
33e974f91cSConrad Meyer  * This file defines the public interface to the IOAT driver.
34e974f91cSConrad Meyer  */
35e974f91cSConrad Meyer 
36e974f91cSConrad Meyer /*
37e974f91cSConrad Meyer  * Enables an interrupt for this operation. Typically, you would only enable
38e974f91cSConrad Meyer  * this on the last operation in a group
39e974f91cSConrad Meyer  */
40e974f91cSConrad Meyer #define	DMA_INT_EN	0x1
41bf8553eaSConrad Meyer /*
42bf8553eaSConrad Meyer  * Like M_NOWAIT.  Operations will return NULL if they cannot allocate a
43bf8553eaSConrad Meyer  * descriptor without blocking.
44bf8553eaSConrad Meyer  */
45bf8553eaSConrad Meyer #define	DMA_NO_WAIT	0x2
466ca07079SConrad Meyer /*
476ca07079SConrad Meyer  * Disallow prefetching the source of the following operation.  Ordinarily, DMA
486ca07079SConrad Meyer  * operations can be pipelined on some hardware.  E.g., operation 2's source
496ca07079SConrad Meyer  * may be prefetched before operation 1 completes.
506ca07079SConrad Meyer  */
516ca07079SConrad Meyer #define	DMA_FENCE	0x4
52bec7ff79SConrad Meyer #define	_DMA_GENERIC_FLAGS	(DMA_INT_EN | DMA_NO_WAIT | DMA_FENCE)
53bec7ff79SConrad Meyer 
54bec7ff79SConrad Meyer /*
55bec7ff79SConrad Meyer  * Emit a CRC32C as the result of a ioat_copy_crc() or ioat_crc().
56bec7ff79SConrad Meyer  */
57bec7ff79SConrad Meyer #define	DMA_CRC_STORE	0x8
58bec7ff79SConrad Meyer 
59bec7ff79SConrad Meyer /*
60bec7ff79SConrad Meyer  * Compare the CRC32C of a ioat_copy_crc() or ioat_crc() against an expeceted
61bec7ff79SConrad Meyer  * value.  It is invalid to specify both TEST and STORE.
62bec7ff79SConrad Meyer  */
63bec7ff79SConrad Meyer #define	DMA_CRC_TEST	0x10
64bec7ff79SConrad Meyer #define	_DMA_CRC_TESTSTORE	(DMA_CRC_STORE | DMA_CRC_TEST)
65bec7ff79SConrad Meyer 
66bec7ff79SConrad Meyer /*
67bec7ff79SConrad Meyer  * Use an inline comparison CRC32C or emit an inline CRC32C result.  Invalid
68bec7ff79SConrad Meyer  * without one of STORE or TEST.
69bec7ff79SConrad Meyer  */
70bec7ff79SConrad Meyer #define	DMA_CRC_INLINE	0x20
71bec7ff79SConrad Meyer #define	_DMA_CRC_FLAGS	(DMA_CRC_STORE | DMA_CRC_TEST | DMA_CRC_INLINE)
72e974f91cSConrad Meyer 
7331bf2875SConrad Meyer /*
7431bf2875SConrad Meyer  * Hardware revision number.  Different hardware revisions support different
7531bf2875SConrad Meyer  * features.  For example, 3.2 cannot read from MMIO space, while 3.3 can.
7631bf2875SConrad Meyer  */
7731bf2875SConrad Meyer #define	IOAT_VER_3_0			0x30
7831bf2875SConrad Meyer #define	IOAT_VER_3_2			0x32
7931bf2875SConrad Meyer #define	IOAT_VER_3_3			0x33
8031bf2875SConrad Meyer 
81f8253f1aSConrad Meyer /*
82f8253f1aSConrad Meyer  * Hardware capabilities.  Different hardware revisions support different
83f8253f1aSConrad Meyer  * features.  It is often useful to detect specific features than try to infer
84f8253f1aSConrad Meyer  * them from hardware version.
85f8253f1aSConrad Meyer  *
86f8253f1aSConrad Meyer  * Different channels may support different features too; for example, 'PQ' may
87f8253f1aSConrad Meyer  * only be supported on the first two channels of some hardware.
88f8253f1aSConrad Meyer  */
89f8253f1aSConrad Meyer #define	IOAT_DMACAP_PB			(1 << 0)
90f8253f1aSConrad Meyer #define	IOAT_DMACAP_CRC			(1 << 1)
91f8253f1aSConrad Meyer #define	IOAT_DMACAP_MARKER_SKIP		(1 << 2)
92f8253f1aSConrad Meyer #define	IOAT_DMACAP_OLD_XOR		(1 << 3)
93f8253f1aSConrad Meyer #define	IOAT_DMACAP_DCA			(1 << 4)
94f8253f1aSConrad Meyer #define	IOAT_DMACAP_MOVECRC		(1 << 5)
95f8253f1aSConrad Meyer #define	IOAT_DMACAP_BFILL		(1 << 6)
96f8253f1aSConrad Meyer #define	IOAT_DMACAP_EXT_APIC		(1 << 7)
97f8253f1aSConrad Meyer #define	IOAT_DMACAP_XOR			(1 << 8)
98f8253f1aSConrad Meyer #define	IOAT_DMACAP_PQ			(1 << 9)
99f8253f1aSConrad Meyer #define	IOAT_DMACAP_DMA_DIF		(1 << 10)
100f8253f1aSConrad Meyer #define	IOAT_DMACAP_DWBES		(1 << 13)
101f8253f1aSConrad Meyer #define	IOAT_DMACAP_RAID16SS		(1 << 17)
102f8253f1aSConrad Meyer #define	IOAT_DMACAP_DMAMC		(1 << 18)
103f8253f1aSConrad Meyer #define	IOAT_DMACAP_CTOS		(1 << 19)
104f8253f1aSConrad Meyer 
105f8253f1aSConrad Meyer #define	IOAT_DMACAP_STR \
106f8253f1aSConrad Meyer     "\20\24Completion_Timeout_Support\23DMA_with_Multicasting_Support" \
107f8253f1aSConrad Meyer     "\22RAID_Super_descriptors\16Descriptor_Write_Back_Error_Support" \
108f8253f1aSConrad Meyer     "\13DMA_with_DIF\12PQ\11XOR\10Extended_APIC_ID\07Block_Fill\06Move_CRC" \
109f8253f1aSConrad Meyer     "\05DCA\04Old_XOR\03Marker_Skipping\02CRC\01Page_Break"
110f8253f1aSConrad Meyer 
111e974f91cSConrad Meyer typedef void *bus_dmaengine_t;
112e974f91cSConrad Meyer struct bus_dmadesc;
113faefad9cSConrad Meyer typedef void (*bus_dmaengine_callback_t)(void *arg, int error);
114e974f91cSConrad Meyer 
115f8f92e91SConrad Meyer unsigned ioat_get_nchannels(void);
116f8f92e91SConrad Meyer 
117e974f91cSConrad Meyer /*
118e974f91cSConrad Meyer  * Called first to acquire a reference to the DMA channel
1190ff814e8SConrad Meyer  *
1200ff814e8SConrad Meyer  * Flags may be M_WAITOK or M_NOWAIT.
121e974f91cSConrad Meyer  */
1220ff814e8SConrad Meyer bus_dmaengine_t ioat_get_dmaengine(uint32_t channel_index, int flags);
123e974f91cSConrad Meyer 
124466b3540SConrad Meyer /* Release the DMA channel */
125466b3540SConrad Meyer void ioat_put_dmaengine(bus_dmaengine_t dmaengine);
126466b3540SConrad Meyer 
12731bf2875SConrad Meyer /* Check the DMA engine's HW version */
12831bf2875SConrad Meyer int ioat_get_hwversion(bus_dmaengine_t dmaengine);
129bd81fe68SConrad Meyer size_t ioat_get_max_io_size(bus_dmaengine_t dmaengine);
130f8253f1aSConrad Meyer uint32_t ioat_get_capabilities(bus_dmaengine_t dmaengine);
131*7280125eSAlexander Motin int ioat_get_domain(bus_dmaengine_t dmaengine, int *domain);
13231bf2875SConrad Meyer 
133e974f91cSConrad Meyer /*
1345ca9fc2aSConrad Meyer  * Set interrupt coalescing on a DMA channel.
1355ca9fc2aSConrad Meyer  *
1365ca9fc2aSConrad Meyer  * The argument is in microseconds.  A zero value disables coalescing.  Any
1375ca9fc2aSConrad Meyer  * other value delays interrupt generation for N microseconds to provide
1385ca9fc2aSConrad Meyer  * opportunity to coalesce multiple operations into a single interrupt.
1395ca9fc2aSConrad Meyer  *
1405ca9fc2aSConrad Meyer  * Returns an error status, or zero on success.
1415ca9fc2aSConrad Meyer  *
1425ca9fc2aSConrad Meyer  * - ERANGE if the given value exceeds the delay supported by the hardware.
1435ca9fc2aSConrad Meyer  *   (All current hardware supports a maximum of 0x3fff microseconds delay.)
1445ca9fc2aSConrad Meyer  * - ENODEV if the hardware does not support interrupt coalescing.
1455ca9fc2aSConrad Meyer  */
1465ca9fc2aSConrad Meyer int ioat_set_interrupt_coalesce(bus_dmaengine_t dmaengine, uint16_t delay);
1475ca9fc2aSConrad Meyer 
1485ca9fc2aSConrad Meyer /*
1495ca9fc2aSConrad Meyer  * Return the maximum supported coalescing period, for use in
1505ca9fc2aSConrad Meyer  * ioat_set_interrupt_coalesce().  If the hardware does not support coalescing,
1515ca9fc2aSConrad Meyer  * returns zero.
1525ca9fc2aSConrad Meyer  */
1535ca9fc2aSConrad Meyer uint16_t ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine);
1545ca9fc2aSConrad Meyer 
1555ca9fc2aSConrad Meyer /*
156e974f91cSConrad Meyer  * Acquire must be called before issuing an operation to perform. Release is
157e974f91cSConrad Meyer  * called after.  Multiple operations can be issued within the context of one
158e974f91cSConrad Meyer  * acquire and release
159e974f91cSConrad Meyer  */
160e974f91cSConrad Meyer void ioat_acquire(bus_dmaengine_t dmaengine);
161e974f91cSConrad Meyer void ioat_release(bus_dmaengine_t dmaengine);
1621502e363SConrad Meyer 
1631502e363SConrad Meyer /*
1641502e363SConrad Meyer  * Acquire_reserve can be called to ensure there is room for N descriptors.  If
1651502e363SConrad Meyer  * it succeeds, the next N valid operations will successfully enqueue.
1661502e363SConrad Meyer  *
1671502e363SConrad Meyer  * It may fail with:
1681502e363SConrad Meyer  *   - ENXIO if the channel is in an errored state, or the driver is being
1691502e363SConrad Meyer  *     unloaded
1701502e363SConrad Meyer  *   - EAGAIN if mflags included M_NOWAIT
1711502e363SConrad Meyer  *
1721502e363SConrad Meyer  * On failure, the caller does not hold the dmaengine.
1731502e363SConrad Meyer  */
174236b57feSConrad Meyer int ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags)
175236b57feSConrad Meyer     __result_use_check;
176e974f91cSConrad Meyer 
1772a4fd6b1SConrad Meyer /*
1782a4fd6b1SConrad Meyer  * Issue a blockfill operation.  The 64-bit pattern 'fillpattern' is written to
1792a4fd6b1SConrad Meyer  * 'len' physically contiguous bytes at 'dst'.
1801693d27bSConrad Meyer  *
1811693d27bSConrad Meyer  * Only supported on devices with the BFILL capability.
1822a4fd6b1SConrad Meyer  */
1832a4fd6b1SConrad Meyer struct bus_dmadesc *ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t dst,
1842a4fd6b1SConrad Meyer     uint64_t fillpattern, bus_size_t len, bus_dmaengine_callback_t callback_fn,
1852a4fd6b1SConrad Meyer     void *callback_arg, uint32_t flags);
1862a4fd6b1SConrad Meyer 
187e974f91cSConrad Meyer /* Issues the copy data operation */
188e974f91cSConrad Meyer struct bus_dmadesc *ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst,
189e974f91cSConrad Meyer     bus_addr_t src, bus_size_t len, bus_dmaengine_callback_t callback_fn,
190e974f91cSConrad Meyer     void *callback_arg, uint32_t flags);
191e974f91cSConrad Meyer 
192e974f91cSConrad Meyer /*
1939950fde0SConrad Meyer  * Issue a copy data operation, with constraints:
1949950fde0SConrad Meyer  *  - src1, src2, dst1, dst2 are all page-aligned addresses
1959950fde0SConrad Meyer  *  - The quantity to copy is exactly 2 pages;
1969950fde0SConrad Meyer  *  - src1 -> dst1, src2 -> dst2
1979950fde0SConrad Meyer  *
1989950fde0SConrad Meyer  * Why use this instead of normal _copy()?  You can copy two non-contiguous
1999950fde0SConrad Meyer  * pages (src, dst, or both) with one descriptor.
2009950fde0SConrad Meyer  */
2019950fde0SConrad Meyer struct bus_dmadesc *ioat_copy_8k_aligned(bus_dmaengine_t dmaengine,
2029950fde0SConrad Meyer     bus_addr_t dst1, bus_addr_t dst2, bus_addr_t src1, bus_addr_t src2,
2039950fde0SConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
2049950fde0SConrad Meyer 
2059950fde0SConrad Meyer /*
206bec7ff79SConrad Meyer  * Copy len bytes from dst to src, like ioat_copy().
207bec7ff79SConrad Meyer  *
208bec7ff79SConrad Meyer  * Additionally, accumulate a CRC32C of the data.
209bec7ff79SConrad Meyer  *
210bec7ff79SConrad Meyer  * If initialseed is not NULL, the value it points to is used to seed the
211bec7ff79SConrad Meyer  * initial value of the CRC32C.
212bec7ff79SConrad Meyer  *
213bec7ff79SConrad Meyer  * If flags include DMA_CRC_STORE and not DMA_CRC_INLINE, crcptr is written
214bec7ff79SConrad Meyer  * with the 32-bit CRC32C result (in wire format).
215bec7ff79SConrad Meyer  *
216bec7ff79SConrad Meyer  * If flags include DMA_CRC_TEST and not DMA_CRC_INLINE, the computed CRC32C is
217bec7ff79SConrad Meyer  * compared with the 32-bit CRC32C pointed to by crcptr.  If they do not match,
218bec7ff79SConrad Meyer  * a channel error is raised.
219bec7ff79SConrad Meyer  *
220bec7ff79SConrad Meyer  * If the DMA_CRC_INLINE flag is set, crcptr is ignored and the DMA engine uses
221bec7ff79SConrad Meyer  * the 4 bytes trailing the source data (TEST) or the destination data (STORE).
222bec7ff79SConrad Meyer  */
223bec7ff79SConrad Meyer struct bus_dmadesc *ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t dst,
224bec7ff79SConrad Meyer     bus_addr_t src, bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr,
225bec7ff79SConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
226bec7ff79SConrad Meyer 
227bec7ff79SConrad Meyer /*
228bec7ff79SConrad Meyer  * ioat_crc() is nearly identical to ioat_copy_crc(), but does not actually
229bec7ff79SConrad Meyer  * move data around.
230bec7ff79SConrad Meyer  *
231bec7ff79SConrad Meyer  * Like ioat_copy_crc, ioat_crc computes a CRC32C over len bytes pointed to by
232bec7ff79SConrad Meyer  * src.  The flags affect its operation in the same way, with one exception:
233bec7ff79SConrad Meyer  *
234bec7ff79SConrad Meyer  * If flags includes both DMA_CRC_STORE and DMA_CRC_INLINE, the computed CRC32C
235bec7ff79SConrad Meyer  * is written to the 4 bytes trailing the *source* data.
236bec7ff79SConrad Meyer  */
237bec7ff79SConrad Meyer struct bus_dmadesc *ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src,
238bec7ff79SConrad Meyer     bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr,
239bec7ff79SConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
240bec7ff79SConrad Meyer 
241bec7ff79SConrad Meyer /*
242e974f91cSConrad Meyer  * Issues a null operation. This issues the operation to the hardware, but the
243e974f91cSConrad Meyer  * hardware doesn't do anything with it.
244e974f91cSConrad Meyer  */
245e974f91cSConrad Meyer struct bus_dmadesc *ioat_null(bus_dmaengine_t dmaengine,
246e974f91cSConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
247e974f91cSConrad Meyer 
248e974f91cSConrad Meyer 
249e974f91cSConrad Meyer #endif /* __IOAT_H__ */
250e974f91cSConrad Meyer 
251