xref: /freebsd/sys/dev/ioat/ioat.h (revision 0ff814e85443f21ca752d25a481139db3b300b0e)
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
556ca07079SConrad Meyer #define	DMA_ALL_FLAGS	(DMA_INT_EN | DMA_NO_WAIT | DMA_FENCE)
56e974f91cSConrad Meyer 
5731bf2875SConrad Meyer /*
5831bf2875SConrad Meyer  * Hardware revision number.  Different hardware revisions support different
5931bf2875SConrad Meyer  * features.  For example, 3.2 cannot read from MMIO space, while 3.3 can.
6031bf2875SConrad Meyer  */
6131bf2875SConrad Meyer #define	IOAT_VER_3_0			0x30
6231bf2875SConrad Meyer #define	IOAT_VER_3_2			0x32
6331bf2875SConrad Meyer #define	IOAT_VER_3_3			0x33
6431bf2875SConrad Meyer 
65e974f91cSConrad Meyer typedef void *bus_dmaengine_t;
66e974f91cSConrad Meyer struct bus_dmadesc;
67faefad9cSConrad Meyer typedef void (*bus_dmaengine_callback_t)(void *arg, int error);
68e974f91cSConrad Meyer 
69e974f91cSConrad Meyer /*
70e974f91cSConrad Meyer  * Called first to acquire a reference to the DMA channel
71*0ff814e8SConrad Meyer  *
72*0ff814e8SConrad Meyer  * Flags may be M_WAITOK or M_NOWAIT.
73e974f91cSConrad Meyer  */
74*0ff814e8SConrad Meyer bus_dmaengine_t ioat_get_dmaengine(uint32_t channel_index, int flags);
75e974f91cSConrad Meyer 
76466b3540SConrad Meyer /* Release the DMA channel */
77466b3540SConrad Meyer void ioat_put_dmaengine(bus_dmaengine_t dmaengine);
78466b3540SConrad Meyer 
7931bf2875SConrad Meyer /* Check the DMA engine's HW version */
8031bf2875SConrad Meyer int ioat_get_hwversion(bus_dmaengine_t dmaengine);
81bd81fe68SConrad Meyer size_t ioat_get_max_io_size(bus_dmaengine_t dmaengine);
8231bf2875SConrad Meyer 
83e974f91cSConrad Meyer /*
845ca9fc2aSConrad Meyer  * Set interrupt coalescing on a DMA channel.
855ca9fc2aSConrad Meyer  *
865ca9fc2aSConrad Meyer  * The argument is in microseconds.  A zero value disables coalescing.  Any
875ca9fc2aSConrad Meyer  * other value delays interrupt generation for N microseconds to provide
885ca9fc2aSConrad Meyer  * opportunity to coalesce multiple operations into a single interrupt.
895ca9fc2aSConrad Meyer  *
905ca9fc2aSConrad Meyer  * Returns an error status, or zero on success.
915ca9fc2aSConrad Meyer  *
925ca9fc2aSConrad Meyer  * - ERANGE if the given value exceeds the delay supported by the hardware.
935ca9fc2aSConrad Meyer  *   (All current hardware supports a maximum of 0x3fff microseconds delay.)
945ca9fc2aSConrad Meyer  * - ENODEV if the hardware does not support interrupt coalescing.
955ca9fc2aSConrad Meyer  */
965ca9fc2aSConrad Meyer int ioat_set_interrupt_coalesce(bus_dmaengine_t dmaengine, uint16_t delay);
975ca9fc2aSConrad Meyer 
985ca9fc2aSConrad Meyer /*
995ca9fc2aSConrad Meyer  * Return the maximum supported coalescing period, for use in
1005ca9fc2aSConrad Meyer  * ioat_set_interrupt_coalesce().  If the hardware does not support coalescing,
1015ca9fc2aSConrad Meyer  * returns zero.
1025ca9fc2aSConrad Meyer  */
1035ca9fc2aSConrad Meyer uint16_t ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine);
1045ca9fc2aSConrad Meyer 
1055ca9fc2aSConrad Meyer /*
106e974f91cSConrad Meyer  * Acquire must be called before issuing an operation to perform. Release is
107e974f91cSConrad Meyer  * called after.  Multiple operations can be issued within the context of one
108e974f91cSConrad Meyer  * acquire and release
109e974f91cSConrad Meyer  */
110e974f91cSConrad Meyer void ioat_acquire(bus_dmaengine_t dmaengine);
111e974f91cSConrad Meyer void ioat_release(bus_dmaengine_t dmaengine);
1121502e363SConrad Meyer 
1131502e363SConrad Meyer /*
1141502e363SConrad Meyer  * Acquire_reserve can be called to ensure there is room for N descriptors.  If
1151502e363SConrad Meyer  * it succeeds, the next N valid operations will successfully enqueue.
1161502e363SConrad Meyer  *
1171502e363SConrad Meyer  * It may fail with:
1181502e363SConrad Meyer  *   - ENXIO if the channel is in an errored state, or the driver is being
1191502e363SConrad Meyer  *     unloaded
1201502e363SConrad Meyer  *   - EAGAIN if mflags included M_NOWAIT
1211502e363SConrad Meyer  *
1221502e363SConrad Meyer  * On failure, the caller does not hold the dmaengine.
1231502e363SConrad Meyer  */
1241502e363SConrad Meyer int ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags);
125e974f91cSConrad Meyer 
1262a4fd6b1SConrad Meyer /*
1272a4fd6b1SConrad Meyer  * Issue a blockfill operation.  The 64-bit pattern 'fillpattern' is written to
1282a4fd6b1SConrad Meyer  * 'len' physically contiguous bytes at 'dst'.
1291693d27bSConrad Meyer  *
1301693d27bSConrad Meyer  * Only supported on devices with the BFILL capability.
1312a4fd6b1SConrad Meyer  */
1322a4fd6b1SConrad Meyer struct bus_dmadesc *ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t dst,
1332a4fd6b1SConrad Meyer     uint64_t fillpattern, bus_size_t len, bus_dmaengine_callback_t callback_fn,
1342a4fd6b1SConrad Meyer     void *callback_arg, uint32_t flags);
1352a4fd6b1SConrad Meyer 
136e974f91cSConrad Meyer /* Issues the copy data operation */
137e974f91cSConrad Meyer struct bus_dmadesc *ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst,
138e974f91cSConrad Meyer     bus_addr_t src, bus_size_t len, bus_dmaengine_callback_t callback_fn,
139e974f91cSConrad Meyer     void *callback_arg, uint32_t flags);
140e974f91cSConrad Meyer 
141e974f91cSConrad Meyer /*
1429950fde0SConrad Meyer  * Issue a copy data operation, with constraints:
1439950fde0SConrad Meyer  *  - src1, src2, dst1, dst2 are all page-aligned addresses
1449950fde0SConrad Meyer  *  - The quantity to copy is exactly 2 pages;
1459950fde0SConrad Meyer  *  - src1 -> dst1, src2 -> dst2
1469950fde0SConrad Meyer  *
1479950fde0SConrad Meyer  * Why use this instead of normal _copy()?  You can copy two non-contiguous
1489950fde0SConrad Meyer  * pages (src, dst, or both) with one descriptor.
1499950fde0SConrad Meyer  */
1509950fde0SConrad Meyer struct bus_dmadesc *ioat_copy_8k_aligned(bus_dmaengine_t dmaengine,
1519950fde0SConrad Meyer     bus_addr_t dst1, bus_addr_t dst2, bus_addr_t src1, bus_addr_t src2,
1529950fde0SConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
1539950fde0SConrad Meyer 
1549950fde0SConrad Meyer /*
155e974f91cSConrad Meyer  * Issues a null operation. This issues the operation to the hardware, but the
156e974f91cSConrad Meyer  * hardware doesn't do anything with it.
157e974f91cSConrad Meyer  */
158e974f91cSConrad Meyer struct bus_dmadesc *ioat_null(bus_dmaengine_t dmaengine,
159e974f91cSConrad Meyer     bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags);
160e974f91cSConrad Meyer 
161e974f91cSConrad Meyer 
162e974f91cSConrad Meyer #endif /* __IOAT_H__ */
163e974f91cSConrad Meyer 
164