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 84*f8253f1aSConrad Meyer /* 85*f8253f1aSConrad Meyer * Hardware capabilities. Different hardware revisions support different 86*f8253f1aSConrad Meyer * features. It is often useful to detect specific features than try to infer 87*f8253f1aSConrad Meyer * them from hardware version. 88*f8253f1aSConrad Meyer * 89*f8253f1aSConrad Meyer * Different channels may support different features too; for example, 'PQ' may 90*f8253f1aSConrad Meyer * only be supported on the first two channels of some hardware. 91*f8253f1aSConrad Meyer */ 92*f8253f1aSConrad Meyer #define IOAT_DMACAP_PB (1 << 0) 93*f8253f1aSConrad Meyer #define IOAT_DMACAP_CRC (1 << 1) 94*f8253f1aSConrad Meyer #define IOAT_DMACAP_MARKER_SKIP (1 << 2) 95*f8253f1aSConrad Meyer #define IOAT_DMACAP_OLD_XOR (1 << 3) 96*f8253f1aSConrad Meyer #define IOAT_DMACAP_DCA (1 << 4) 97*f8253f1aSConrad Meyer #define IOAT_DMACAP_MOVECRC (1 << 5) 98*f8253f1aSConrad Meyer #define IOAT_DMACAP_BFILL (1 << 6) 99*f8253f1aSConrad Meyer #define IOAT_DMACAP_EXT_APIC (1 << 7) 100*f8253f1aSConrad Meyer #define IOAT_DMACAP_XOR (1 << 8) 101*f8253f1aSConrad Meyer #define IOAT_DMACAP_PQ (1 << 9) 102*f8253f1aSConrad Meyer #define IOAT_DMACAP_DMA_DIF (1 << 10) 103*f8253f1aSConrad Meyer #define IOAT_DMACAP_DWBES (1 << 13) 104*f8253f1aSConrad Meyer #define IOAT_DMACAP_RAID16SS (1 << 17) 105*f8253f1aSConrad Meyer #define IOAT_DMACAP_DMAMC (1 << 18) 106*f8253f1aSConrad Meyer #define IOAT_DMACAP_CTOS (1 << 19) 107*f8253f1aSConrad Meyer 108*f8253f1aSConrad Meyer #define IOAT_DMACAP_STR \ 109*f8253f1aSConrad Meyer "\20\24Completion_Timeout_Support\23DMA_with_Multicasting_Support" \ 110*f8253f1aSConrad Meyer "\22RAID_Super_descriptors\16Descriptor_Write_Back_Error_Support" \ 111*f8253f1aSConrad Meyer "\13DMA_with_DIF\12PQ\11XOR\10Extended_APIC_ID\07Block_Fill\06Move_CRC" \ 112*f8253f1aSConrad Meyer "\05DCA\04Old_XOR\03Marker_Skipping\02CRC\01Page_Break" 113*f8253f1aSConrad Meyer 114e974f91cSConrad Meyer typedef void *bus_dmaengine_t; 115e974f91cSConrad Meyer struct bus_dmadesc; 116faefad9cSConrad Meyer typedef void (*bus_dmaengine_callback_t)(void *arg, int error); 117e974f91cSConrad Meyer 118f8f92e91SConrad Meyer unsigned ioat_get_nchannels(void); 119f8f92e91SConrad Meyer 120e974f91cSConrad Meyer /* 121e974f91cSConrad Meyer * Called first to acquire a reference to the DMA channel 1220ff814e8SConrad Meyer * 1230ff814e8SConrad Meyer * Flags may be M_WAITOK or M_NOWAIT. 124e974f91cSConrad Meyer */ 1250ff814e8SConrad Meyer bus_dmaengine_t ioat_get_dmaengine(uint32_t channel_index, int flags); 126e974f91cSConrad Meyer 127466b3540SConrad Meyer /* Release the DMA channel */ 128466b3540SConrad Meyer void ioat_put_dmaengine(bus_dmaengine_t dmaengine); 129466b3540SConrad Meyer 13031bf2875SConrad Meyer /* Check the DMA engine's HW version */ 13131bf2875SConrad Meyer int ioat_get_hwversion(bus_dmaengine_t dmaengine); 132bd81fe68SConrad Meyer size_t ioat_get_max_io_size(bus_dmaengine_t dmaengine); 133*f8253f1aSConrad Meyer uint32_t ioat_get_capabilities(bus_dmaengine_t dmaengine); 13431bf2875SConrad Meyer 135e974f91cSConrad Meyer /* 1365ca9fc2aSConrad Meyer * Set interrupt coalescing on a DMA channel. 1375ca9fc2aSConrad Meyer * 1385ca9fc2aSConrad Meyer * The argument is in microseconds. A zero value disables coalescing. Any 1395ca9fc2aSConrad Meyer * other value delays interrupt generation for N microseconds to provide 1405ca9fc2aSConrad Meyer * opportunity to coalesce multiple operations into a single interrupt. 1415ca9fc2aSConrad Meyer * 1425ca9fc2aSConrad Meyer * Returns an error status, or zero on success. 1435ca9fc2aSConrad Meyer * 1445ca9fc2aSConrad Meyer * - ERANGE if the given value exceeds the delay supported by the hardware. 1455ca9fc2aSConrad Meyer * (All current hardware supports a maximum of 0x3fff microseconds delay.) 1465ca9fc2aSConrad Meyer * - ENODEV if the hardware does not support interrupt coalescing. 1475ca9fc2aSConrad Meyer */ 1485ca9fc2aSConrad Meyer int ioat_set_interrupt_coalesce(bus_dmaengine_t dmaengine, uint16_t delay); 1495ca9fc2aSConrad Meyer 1505ca9fc2aSConrad Meyer /* 1515ca9fc2aSConrad Meyer * Return the maximum supported coalescing period, for use in 1525ca9fc2aSConrad Meyer * ioat_set_interrupt_coalesce(). If the hardware does not support coalescing, 1535ca9fc2aSConrad Meyer * returns zero. 1545ca9fc2aSConrad Meyer */ 1555ca9fc2aSConrad Meyer uint16_t ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine); 1565ca9fc2aSConrad Meyer 1575ca9fc2aSConrad Meyer /* 158e974f91cSConrad Meyer * Acquire must be called before issuing an operation to perform. Release is 159e974f91cSConrad Meyer * called after. Multiple operations can be issued within the context of one 160e974f91cSConrad Meyer * acquire and release 161e974f91cSConrad Meyer */ 162e974f91cSConrad Meyer void ioat_acquire(bus_dmaengine_t dmaengine); 163e974f91cSConrad Meyer void ioat_release(bus_dmaengine_t dmaengine); 1641502e363SConrad Meyer 1651502e363SConrad Meyer /* 1661502e363SConrad Meyer * Acquire_reserve can be called to ensure there is room for N descriptors. If 1671502e363SConrad Meyer * it succeeds, the next N valid operations will successfully enqueue. 1681502e363SConrad Meyer * 1691502e363SConrad Meyer * It may fail with: 1701502e363SConrad Meyer * - ENXIO if the channel is in an errored state, or the driver is being 1711502e363SConrad Meyer * unloaded 1721502e363SConrad Meyer * - EAGAIN if mflags included M_NOWAIT 1731502e363SConrad Meyer * 1741502e363SConrad Meyer * On failure, the caller does not hold the dmaengine. 1751502e363SConrad Meyer */ 1761502e363SConrad Meyer int ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags); 177e974f91cSConrad Meyer 1782a4fd6b1SConrad Meyer /* 1792a4fd6b1SConrad Meyer * Issue a blockfill operation. The 64-bit pattern 'fillpattern' is written to 1802a4fd6b1SConrad Meyer * 'len' physically contiguous bytes at 'dst'. 1811693d27bSConrad Meyer * 1821693d27bSConrad Meyer * Only supported on devices with the BFILL capability. 1832a4fd6b1SConrad Meyer */ 1842a4fd6b1SConrad Meyer struct bus_dmadesc *ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t dst, 1852a4fd6b1SConrad Meyer uint64_t fillpattern, bus_size_t len, bus_dmaengine_callback_t callback_fn, 1862a4fd6b1SConrad Meyer void *callback_arg, uint32_t flags); 1872a4fd6b1SConrad Meyer 188e974f91cSConrad Meyer /* Issues the copy data operation */ 189e974f91cSConrad Meyer struct bus_dmadesc *ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst, 190e974f91cSConrad Meyer bus_addr_t src, bus_size_t len, bus_dmaengine_callback_t callback_fn, 191e974f91cSConrad Meyer void *callback_arg, uint32_t flags); 192e974f91cSConrad Meyer 193e974f91cSConrad Meyer /* 1949950fde0SConrad Meyer * Issue a copy data operation, with constraints: 1959950fde0SConrad Meyer * - src1, src2, dst1, dst2 are all page-aligned addresses 1969950fde0SConrad Meyer * - The quantity to copy is exactly 2 pages; 1979950fde0SConrad Meyer * - src1 -> dst1, src2 -> dst2 1989950fde0SConrad Meyer * 1999950fde0SConrad Meyer * Why use this instead of normal _copy()? You can copy two non-contiguous 2009950fde0SConrad Meyer * pages (src, dst, or both) with one descriptor. 2019950fde0SConrad Meyer */ 2029950fde0SConrad Meyer struct bus_dmadesc *ioat_copy_8k_aligned(bus_dmaengine_t dmaengine, 2039950fde0SConrad Meyer bus_addr_t dst1, bus_addr_t dst2, bus_addr_t src1, bus_addr_t src2, 2049950fde0SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 2059950fde0SConrad Meyer 2069950fde0SConrad Meyer /* 207bec7ff79SConrad Meyer * Copy len bytes from dst to src, like ioat_copy(). 208bec7ff79SConrad Meyer * 209bec7ff79SConrad Meyer * Additionally, accumulate a CRC32C of the data. 210bec7ff79SConrad Meyer * 211bec7ff79SConrad Meyer * If initialseed is not NULL, the value it points to is used to seed the 212bec7ff79SConrad Meyer * initial value of the CRC32C. 213bec7ff79SConrad Meyer * 214bec7ff79SConrad Meyer * If flags include DMA_CRC_STORE and not DMA_CRC_INLINE, crcptr is written 215bec7ff79SConrad Meyer * with the 32-bit CRC32C result (in wire format). 216bec7ff79SConrad Meyer * 217bec7ff79SConrad Meyer * If flags include DMA_CRC_TEST and not DMA_CRC_INLINE, the computed CRC32C is 218bec7ff79SConrad Meyer * compared with the 32-bit CRC32C pointed to by crcptr. If they do not match, 219bec7ff79SConrad Meyer * a channel error is raised. 220bec7ff79SConrad Meyer * 221bec7ff79SConrad Meyer * If the DMA_CRC_INLINE flag is set, crcptr is ignored and the DMA engine uses 222bec7ff79SConrad Meyer * the 4 bytes trailing the source data (TEST) or the destination data (STORE). 223bec7ff79SConrad Meyer */ 224bec7ff79SConrad Meyer struct bus_dmadesc *ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t dst, 225bec7ff79SConrad Meyer bus_addr_t src, bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr, 226bec7ff79SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 227bec7ff79SConrad Meyer 228bec7ff79SConrad Meyer /* 229bec7ff79SConrad Meyer * ioat_crc() is nearly identical to ioat_copy_crc(), but does not actually 230bec7ff79SConrad Meyer * move data around. 231bec7ff79SConrad Meyer * 232bec7ff79SConrad Meyer * Like ioat_copy_crc, ioat_crc computes a CRC32C over len bytes pointed to by 233bec7ff79SConrad Meyer * src. The flags affect its operation in the same way, with one exception: 234bec7ff79SConrad Meyer * 235bec7ff79SConrad Meyer * If flags includes both DMA_CRC_STORE and DMA_CRC_INLINE, the computed CRC32C 236bec7ff79SConrad Meyer * is written to the 4 bytes trailing the *source* data. 237bec7ff79SConrad Meyer */ 238bec7ff79SConrad Meyer struct bus_dmadesc *ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src, 239bec7ff79SConrad Meyer bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr, 240bec7ff79SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 241bec7ff79SConrad Meyer 242bec7ff79SConrad Meyer /* 243e974f91cSConrad Meyer * Issues a null operation. This issues the operation to the hardware, but the 244e974f91cSConrad Meyer * hardware doesn't do anything with it. 245e974f91cSConrad Meyer */ 246e974f91cSConrad Meyer struct bus_dmadesc *ioat_null(bus_dmaengine_t dmaengine, 247e974f91cSConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags); 248e974f91cSConrad Meyer 249e974f91cSConrad Meyer 250e974f91cSConrad Meyer #endif /* __IOAT_H__ */ 251e974f91cSConrad Meyer 252