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 55*bec7ff79SConrad Meyer #define _DMA_GENERIC_FLAGS (DMA_INT_EN | DMA_NO_WAIT | DMA_FENCE) 56*bec7ff79SConrad Meyer 57*bec7ff79SConrad Meyer /* 58*bec7ff79SConrad Meyer * Emit a CRC32C as the result of a ioat_copy_crc() or ioat_crc(). 59*bec7ff79SConrad Meyer */ 60*bec7ff79SConrad Meyer #define DMA_CRC_STORE 0x8 61*bec7ff79SConrad Meyer 62*bec7ff79SConrad Meyer /* 63*bec7ff79SConrad Meyer * Compare the CRC32C of a ioat_copy_crc() or ioat_crc() against an expeceted 64*bec7ff79SConrad Meyer * value. It is invalid to specify both TEST and STORE. 65*bec7ff79SConrad Meyer */ 66*bec7ff79SConrad Meyer #define DMA_CRC_TEST 0x10 67*bec7ff79SConrad Meyer #define _DMA_CRC_TESTSTORE (DMA_CRC_STORE | DMA_CRC_TEST) 68*bec7ff79SConrad Meyer 69*bec7ff79SConrad Meyer /* 70*bec7ff79SConrad Meyer * Use an inline comparison CRC32C or emit an inline CRC32C result. Invalid 71*bec7ff79SConrad Meyer * without one of STORE or TEST. 72*bec7ff79SConrad Meyer */ 73*bec7ff79SConrad Meyer #define DMA_CRC_INLINE 0x20 74*bec7ff79SConrad 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 88e974f91cSConrad Meyer /* 89e974f91cSConrad Meyer * Called first to acquire a reference to the DMA channel 900ff814e8SConrad Meyer * 910ff814e8SConrad Meyer * Flags may be M_WAITOK or M_NOWAIT. 92e974f91cSConrad Meyer */ 930ff814e8SConrad Meyer bus_dmaengine_t ioat_get_dmaengine(uint32_t channel_index, int flags); 94e974f91cSConrad Meyer 95466b3540SConrad Meyer /* Release the DMA channel */ 96466b3540SConrad Meyer void ioat_put_dmaengine(bus_dmaengine_t dmaengine); 97466b3540SConrad Meyer 9831bf2875SConrad Meyer /* Check the DMA engine's HW version */ 9931bf2875SConrad Meyer int ioat_get_hwversion(bus_dmaengine_t dmaengine); 100bd81fe68SConrad Meyer size_t ioat_get_max_io_size(bus_dmaengine_t dmaengine); 10131bf2875SConrad Meyer 102e974f91cSConrad Meyer /* 1035ca9fc2aSConrad Meyer * Set interrupt coalescing on a DMA channel. 1045ca9fc2aSConrad Meyer * 1055ca9fc2aSConrad Meyer * The argument is in microseconds. A zero value disables coalescing. Any 1065ca9fc2aSConrad Meyer * other value delays interrupt generation for N microseconds to provide 1075ca9fc2aSConrad Meyer * opportunity to coalesce multiple operations into a single interrupt. 1085ca9fc2aSConrad Meyer * 1095ca9fc2aSConrad Meyer * Returns an error status, or zero on success. 1105ca9fc2aSConrad Meyer * 1115ca9fc2aSConrad Meyer * - ERANGE if the given value exceeds the delay supported by the hardware. 1125ca9fc2aSConrad Meyer * (All current hardware supports a maximum of 0x3fff microseconds delay.) 1135ca9fc2aSConrad Meyer * - ENODEV if the hardware does not support interrupt coalescing. 1145ca9fc2aSConrad Meyer */ 1155ca9fc2aSConrad Meyer int ioat_set_interrupt_coalesce(bus_dmaengine_t dmaengine, uint16_t delay); 1165ca9fc2aSConrad Meyer 1175ca9fc2aSConrad Meyer /* 1185ca9fc2aSConrad Meyer * Return the maximum supported coalescing period, for use in 1195ca9fc2aSConrad Meyer * ioat_set_interrupt_coalesce(). If the hardware does not support coalescing, 1205ca9fc2aSConrad Meyer * returns zero. 1215ca9fc2aSConrad Meyer */ 1225ca9fc2aSConrad Meyer uint16_t ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine); 1235ca9fc2aSConrad Meyer 1245ca9fc2aSConrad Meyer /* 125e974f91cSConrad Meyer * Acquire must be called before issuing an operation to perform. Release is 126e974f91cSConrad Meyer * called after. Multiple operations can be issued within the context of one 127e974f91cSConrad Meyer * acquire and release 128e974f91cSConrad Meyer */ 129e974f91cSConrad Meyer void ioat_acquire(bus_dmaengine_t dmaengine); 130e974f91cSConrad Meyer void ioat_release(bus_dmaengine_t dmaengine); 1311502e363SConrad Meyer 1321502e363SConrad Meyer /* 1331502e363SConrad Meyer * Acquire_reserve can be called to ensure there is room for N descriptors. If 1341502e363SConrad Meyer * it succeeds, the next N valid operations will successfully enqueue. 1351502e363SConrad Meyer * 1361502e363SConrad Meyer * It may fail with: 1371502e363SConrad Meyer * - ENXIO if the channel is in an errored state, or the driver is being 1381502e363SConrad Meyer * unloaded 1391502e363SConrad Meyer * - EAGAIN if mflags included M_NOWAIT 1401502e363SConrad Meyer * 1411502e363SConrad Meyer * On failure, the caller does not hold the dmaengine. 1421502e363SConrad Meyer */ 1431502e363SConrad Meyer int ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags); 144e974f91cSConrad Meyer 1452a4fd6b1SConrad Meyer /* 1462a4fd6b1SConrad Meyer * Issue a blockfill operation. The 64-bit pattern 'fillpattern' is written to 1472a4fd6b1SConrad Meyer * 'len' physically contiguous bytes at 'dst'. 1481693d27bSConrad Meyer * 1491693d27bSConrad Meyer * Only supported on devices with the BFILL capability. 1502a4fd6b1SConrad Meyer */ 1512a4fd6b1SConrad Meyer struct bus_dmadesc *ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t dst, 1522a4fd6b1SConrad Meyer uint64_t fillpattern, bus_size_t len, bus_dmaengine_callback_t callback_fn, 1532a4fd6b1SConrad Meyer void *callback_arg, uint32_t flags); 1542a4fd6b1SConrad Meyer 155e974f91cSConrad Meyer /* Issues the copy data operation */ 156e974f91cSConrad Meyer struct bus_dmadesc *ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst, 157e974f91cSConrad Meyer bus_addr_t src, bus_size_t len, bus_dmaengine_callback_t callback_fn, 158e974f91cSConrad Meyer void *callback_arg, uint32_t flags); 159e974f91cSConrad Meyer 160e974f91cSConrad Meyer /* 1619950fde0SConrad Meyer * Issue a copy data operation, with constraints: 1629950fde0SConrad Meyer * - src1, src2, dst1, dst2 are all page-aligned addresses 1639950fde0SConrad Meyer * - The quantity to copy is exactly 2 pages; 1649950fde0SConrad Meyer * - src1 -> dst1, src2 -> dst2 1659950fde0SConrad Meyer * 1669950fde0SConrad Meyer * Why use this instead of normal _copy()? You can copy two non-contiguous 1679950fde0SConrad Meyer * pages (src, dst, or both) with one descriptor. 1689950fde0SConrad Meyer */ 1699950fde0SConrad Meyer struct bus_dmadesc *ioat_copy_8k_aligned(bus_dmaengine_t dmaengine, 1709950fde0SConrad Meyer bus_addr_t dst1, bus_addr_t dst2, bus_addr_t src1, bus_addr_t src2, 1719950fde0SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 1729950fde0SConrad Meyer 1739950fde0SConrad Meyer /* 174*bec7ff79SConrad Meyer * Copy len bytes from dst to src, like ioat_copy(). 175*bec7ff79SConrad Meyer * 176*bec7ff79SConrad Meyer * Additionally, accumulate a CRC32C of the data. 177*bec7ff79SConrad Meyer * 178*bec7ff79SConrad Meyer * If initialseed is not NULL, the value it points to is used to seed the 179*bec7ff79SConrad Meyer * initial value of the CRC32C. 180*bec7ff79SConrad Meyer * 181*bec7ff79SConrad Meyer * If flags include DMA_CRC_STORE and not DMA_CRC_INLINE, crcptr is written 182*bec7ff79SConrad Meyer * with the 32-bit CRC32C result (in wire format). 183*bec7ff79SConrad Meyer * 184*bec7ff79SConrad Meyer * If flags include DMA_CRC_TEST and not DMA_CRC_INLINE, the computed CRC32C is 185*bec7ff79SConrad Meyer * compared with the 32-bit CRC32C pointed to by crcptr. If they do not match, 186*bec7ff79SConrad Meyer * a channel error is raised. 187*bec7ff79SConrad Meyer * 188*bec7ff79SConrad Meyer * If the DMA_CRC_INLINE flag is set, crcptr is ignored and the DMA engine uses 189*bec7ff79SConrad Meyer * the 4 bytes trailing the source data (TEST) or the destination data (STORE). 190*bec7ff79SConrad Meyer */ 191*bec7ff79SConrad Meyer struct bus_dmadesc *ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t dst, 192*bec7ff79SConrad Meyer bus_addr_t src, bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr, 193*bec7ff79SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 194*bec7ff79SConrad Meyer 195*bec7ff79SConrad Meyer /* 196*bec7ff79SConrad Meyer * ioat_crc() is nearly identical to ioat_copy_crc(), but does not actually 197*bec7ff79SConrad Meyer * move data around. 198*bec7ff79SConrad Meyer * 199*bec7ff79SConrad Meyer * Like ioat_copy_crc, ioat_crc computes a CRC32C over len bytes pointed to by 200*bec7ff79SConrad Meyer * src. The flags affect its operation in the same way, with one exception: 201*bec7ff79SConrad Meyer * 202*bec7ff79SConrad Meyer * If flags includes both DMA_CRC_STORE and DMA_CRC_INLINE, the computed CRC32C 203*bec7ff79SConrad Meyer * is written to the 4 bytes trailing the *source* data. 204*bec7ff79SConrad Meyer */ 205*bec7ff79SConrad Meyer struct bus_dmadesc *ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src, 206*bec7ff79SConrad Meyer bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr, 207*bec7ff79SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 208*bec7ff79SConrad Meyer 209*bec7ff79SConrad Meyer /* 210e974f91cSConrad Meyer * Issues a null operation. This issues the operation to the hardware, but the 211e974f91cSConrad Meyer * hardware doesn't do anything with it. 212e974f91cSConrad Meyer */ 213e974f91cSConrad Meyer struct bus_dmadesc *ioat_null(bus_dmaengine_t dmaengine, 214e974f91cSConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 215e974f91cSConrad Meyer 216e974f91cSConrad Meyer 217e974f91cSConrad Meyer #endif /* __IOAT_H__ */ 218e974f91cSConrad Meyer 219