1e974f91cSConrad Meyer /*- 2e974f91cSConrad Meyer * Copyright (C) 2012 Intel Corporation 3e974f91cSConrad Meyer * All rights reserved. 42f03a95fSAlexander Motin * Copyright (C) 2018 Alexander Motin <mav@FreeBSD.org> 5e974f91cSConrad Meyer * 6e974f91cSConrad Meyer * Redistribution and use in source and binary forms, with or without 7e974f91cSConrad Meyer * modification, are permitted provided that the following conditions 8e974f91cSConrad Meyer * are met: 9e974f91cSConrad Meyer * 1. Redistributions of source code must retain the above copyright 10e974f91cSConrad Meyer * notice, this list of conditions and the following disclaimer. 11e974f91cSConrad Meyer * 2. Redistributions in binary form must reproduce the above copyright 12e974f91cSConrad Meyer * notice, this list of conditions and the following disclaimer in the 13e974f91cSConrad Meyer * documentation and/or other materials provided with the distribution. 14e974f91cSConrad Meyer * 15e974f91cSConrad Meyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16e974f91cSConrad Meyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17e974f91cSConrad Meyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18e974f91cSConrad Meyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19e974f91cSConrad Meyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20e974f91cSConrad Meyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21e974f91cSConrad Meyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22e974f91cSConrad Meyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23e974f91cSConrad Meyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24e974f91cSConrad Meyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25e974f91cSConrad Meyer * SUCH DAMAGE. 26e974f91cSConrad Meyer */ 27e974f91cSConrad Meyer 28e974f91cSConrad Meyer #include <sys/cdefs.h> 29e974f91cSConrad Meyer __FBSDID("$FreeBSD$"); 30e974f91cSConrad Meyer 310bb35debSConrad Meyer #include "opt_ddb.h" 320bb35debSConrad Meyer 33e974f91cSConrad Meyer #include <sys/param.h> 34e974f91cSConrad Meyer #include <sys/systm.h> 35e974f91cSConrad Meyer #include <sys/bus.h> 36e974f91cSConrad Meyer #include <sys/conf.h> 37657dc81dSAlexander Motin #include <sys/domainset.h> 3876305bb8SConrad Meyer #include <sys/fail.h> 39e974f91cSConrad Meyer #include <sys/ioccom.h> 40e974f91cSConrad Meyer #include <sys/kernel.h> 41e2e050c8SConrad Meyer #include <sys/ktr.h> 42e974f91cSConrad Meyer #include <sys/lock.h> 43e974f91cSConrad Meyer #include <sys/malloc.h> 44e974f91cSConrad Meyer #include <sys/module.h> 45e974f91cSConrad Meyer #include <sys/mutex.h> 46e974f91cSConrad Meyer #include <sys/rman.h> 47faefad9cSConrad Meyer #include <sys/sbuf.h> 48657dc81dSAlexander Motin #include <sys/smp.h> 49e974f91cSConrad Meyer #include <sys/sysctl.h> 50374b05e1SConrad Meyer #include <sys/taskqueue.h> 51e974f91cSConrad Meyer #include <sys/time.h> 52e974f91cSConrad Meyer #include <dev/pci/pcireg.h> 53e974f91cSConrad Meyer #include <dev/pci/pcivar.h> 54e974f91cSConrad Meyer #include <machine/bus.h> 55e974f91cSConrad Meyer #include <machine/resource.h> 56e974f91cSConrad Meyer #include <machine/stdarg.h> 57e974f91cSConrad Meyer 580bb35debSConrad Meyer #ifdef DDB 590bb35debSConrad Meyer #include <ddb/ddb.h> 600bb35debSConrad Meyer #endif 610bb35debSConrad Meyer 62e974f91cSConrad Meyer #include "ioat.h" 63e974f91cSConrad Meyer #include "ioat_hw.h" 64e974f91cSConrad Meyer #include "ioat_internal.h" 65e974f91cSConrad Meyer 66519e8baaSConrad Meyer #ifndef BUS_SPACE_MAXADDR_40BIT 671f4a469dSAlexander Motin #define BUS_SPACE_MAXADDR_40BIT MIN(BUS_SPACE_MAXADDR, 0xFFFFFFFFFFULL) 681f4a469dSAlexander Motin #endif 691f4a469dSAlexander Motin #ifndef BUS_SPACE_MAXADDR_46BIT 701f4a469dSAlexander Motin #define BUS_SPACE_MAXADDR_46BIT MIN(BUS_SPACE_MAXADDR, 0x3FFFFFFFFFFFULL) 71519e8baaSConrad Meyer #endif 72fe720f5aSConrad Meyer 7371bf3900SAlexander Motin static int ioat_modevent(module_t mod, int type, void *data); 74e974f91cSConrad Meyer static int ioat_probe(device_t device); 75e974f91cSConrad Meyer static int ioat_attach(device_t device); 76e974f91cSConrad Meyer static int ioat_detach(device_t device); 774253ea50SConrad Meyer static int ioat_setup_intr(struct ioat_softc *ioat); 784253ea50SConrad Meyer static int ioat_teardown_intr(struct ioat_softc *ioat); 79e974f91cSConrad Meyer static int ioat3_attach(device_t device); 80cea5b880SConrad Meyer static int ioat_start_channel(struct ioat_softc *ioat); 81e974f91cSConrad Meyer static int ioat_map_pci_bar(struct ioat_softc *ioat); 82e974f91cSConrad Meyer static void ioat_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, 83e974f91cSConrad Meyer int error); 84e974f91cSConrad Meyer static void ioat_interrupt_handler(void *arg); 850d1a05d9SConrad Meyer static boolean_t ioat_model_resets_msix(struct ioat_softc *ioat); 86faefad9cSConrad Meyer static int chanerr_to_errno(uint32_t); 872f03a95fSAlexander Motin static void ioat_process_events(struct ioat_softc *ioat, boolean_t intr); 88e974f91cSConrad Meyer static inline uint32_t ioat_get_active(struct ioat_softc *ioat); 89e974f91cSConrad Meyer static inline uint32_t ioat_get_ring_space(struct ioat_softc *ioat); 90bf8553eaSConrad Meyer static void ioat_free_ring(struct ioat_softc *, uint32_t size, 918e269d99SConrad Meyer struct ioat_descriptor *); 92bf8553eaSConrad Meyer static int ioat_reserve_space(struct ioat_softc *, uint32_t, int mflags); 938e269d99SConrad Meyer static union ioat_hw_descriptor *ioat_get_descriptor(struct ioat_softc *, 948e269d99SConrad Meyer uint32_t index); 958e269d99SConrad Meyer static struct ioat_descriptor *ioat_get_ring_entry(struct ioat_softc *, 96e974f91cSConrad Meyer uint32_t index); 97faefad9cSConrad Meyer static void ioat_halted_debug(struct ioat_softc *, uint32_t); 985ac77963SConrad Meyer static void ioat_poll_timer_callback(void *arg); 99e974f91cSConrad Meyer static void dump_descriptor(void *hw_desc); 100e974f91cSConrad Meyer static void ioat_submit_single(struct ioat_softc *ioat); 101e974f91cSConrad Meyer static void ioat_comp_update_map(void *arg, bus_dma_segment_t *seg, int nseg, 102e974f91cSConrad Meyer int error); 103e974f91cSConrad Meyer static int ioat_reset_hw(struct ioat_softc *ioat); 104374b05e1SConrad Meyer static void ioat_reset_hw_task(void *, int); 105e974f91cSConrad Meyer static void ioat_setup_sysctl(device_t device); 106f7157235SConrad Meyer static int sysctl_handle_reset(SYSCTL_HANDLER_ARGS); 1072f03a95fSAlexander Motin static void ioat_get(struct ioat_softc *); 1082f03a95fSAlexander Motin static void ioat_put(struct ioat_softc *); 1095f77bd3eSConrad Meyer static void ioat_drain_locked(struct ioat_softc *); 110e974f91cSConrad Meyer 1111c25420eSConrad Meyer #define ioat_log_message(v, ...) do { \ 1121c25420eSConrad Meyer if ((v) <= g_ioat_debug_level) { \ 1131c25420eSConrad Meyer device_printf(ioat->device, __VA_ARGS__); \ 1141c25420eSConrad Meyer } \ 1151c25420eSConrad Meyer } while (0) 1161c25420eSConrad Meyer 117e974f91cSConrad Meyer MALLOC_DEFINE(M_IOAT, "ioat", "ioat driver memory allocations"); 1187029da5cSPawel Biernacki SYSCTL_NODE(_hw, OID_AUTO, ioat, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 1197029da5cSPawel Biernacki "ioat node"); 120e974f91cSConrad Meyer 121e974f91cSConrad Meyer static int g_force_legacy_interrupts; 122e974f91cSConrad Meyer SYSCTL_INT(_hw_ioat, OID_AUTO, force_legacy_interrupts, CTLFLAG_RDTUN, 123e974f91cSConrad Meyer &g_force_legacy_interrupts, 0, "Set to non-zero to force MSI-X disabled"); 124e974f91cSConrad Meyer 1251c25420eSConrad Meyer int g_ioat_debug_level = 0; 126e974f91cSConrad Meyer SYSCTL_INT(_hw_ioat, OID_AUTO, debug_level, CTLFLAG_RWTUN, &g_ioat_debug_level, 127e974f91cSConrad Meyer 0, "Set log level (0-3) for ioat(4). Higher is more verbose."); 128e974f91cSConrad Meyer 129a0992979SConrad Meyer unsigned g_ioat_ring_order = 13; 130a0992979SConrad Meyer SYSCTL_UINT(_hw_ioat, OID_AUTO, ring_order, CTLFLAG_RDTUN, &g_ioat_ring_order, 131a0992979SConrad Meyer 0, "Set IOAT ring order. (1 << this) == ring size."); 132a0992979SConrad Meyer 133e974f91cSConrad Meyer /* 134e974f91cSConrad Meyer * OS <-> Driver interface structures 135e974f91cSConrad Meyer */ 136e974f91cSConrad Meyer static device_method_t ioat_pci_methods[] = { 137e974f91cSConrad Meyer /* Device interface */ 138e974f91cSConrad Meyer DEVMETHOD(device_probe, ioat_probe), 139e974f91cSConrad Meyer DEVMETHOD(device_attach, ioat_attach), 140e974f91cSConrad Meyer DEVMETHOD(device_detach, ioat_detach), 141aa853cb4SEnji Cooper DEVMETHOD_END 142e974f91cSConrad Meyer }; 143e974f91cSConrad Meyer 144e974f91cSConrad Meyer static driver_t ioat_pci_driver = { 145e974f91cSConrad Meyer "ioat", 146e974f91cSConrad Meyer ioat_pci_methods, 147e974f91cSConrad Meyer sizeof(struct ioat_softc), 148e974f91cSConrad Meyer }; 149e974f91cSConrad Meyer 150*ff318bf6SJohn Baldwin DRIVER_MODULE(ioat, pci, ioat_pci_driver, ioat_modevent, NULL); 151c2b69205SConrad Meyer MODULE_VERSION(ioat, 1); 152e974f91cSConrad Meyer 153e974f91cSConrad Meyer /* 154e974f91cSConrad Meyer * Private data structures 155e974f91cSConrad Meyer */ 156e974f91cSConrad Meyer static struct ioat_softc *ioat_channel[IOAT_MAX_CHANNELS]; 157df1928aaSConrad Meyer static unsigned ioat_channel_index = 0; 158df1928aaSConrad Meyer SYSCTL_UINT(_hw_ioat, OID_AUTO, channels, CTLFLAG_RD, &ioat_channel_index, 0, 159e974f91cSConrad Meyer "Number of IOAT channels attached"); 1602f03a95fSAlexander Motin static struct mtx ioat_list_mtx; 1612f03a95fSAlexander Motin MTX_SYSINIT(ioat_list_mtx, &ioat_list_mtx, "ioat list mtx", MTX_DEF); 162e974f91cSConrad Meyer 163e974f91cSConrad Meyer static struct _pcsid 164e974f91cSConrad Meyer { 165e974f91cSConrad Meyer u_int32_t type; 166e974f91cSConrad Meyer const char *desc; 167e974f91cSConrad Meyer } pci_ids[] = { 168e974f91cSConrad Meyer { 0x34308086, "TBG IOAT Ch0" }, 169e974f91cSConrad Meyer { 0x34318086, "TBG IOAT Ch1" }, 170e974f91cSConrad Meyer { 0x34328086, "TBG IOAT Ch2" }, 171e974f91cSConrad Meyer { 0x34338086, "TBG IOAT Ch3" }, 172e974f91cSConrad Meyer { 0x34298086, "TBG IOAT Ch4" }, 173e974f91cSConrad Meyer { 0x342a8086, "TBG IOAT Ch5" }, 174e974f91cSConrad Meyer { 0x342b8086, "TBG IOAT Ch6" }, 175e974f91cSConrad Meyer { 0x342c8086, "TBG IOAT Ch7" }, 176e974f91cSConrad Meyer 177e974f91cSConrad Meyer { 0x37108086, "JSF IOAT Ch0" }, 178e974f91cSConrad Meyer { 0x37118086, "JSF IOAT Ch1" }, 179e974f91cSConrad Meyer { 0x37128086, "JSF IOAT Ch2" }, 180e974f91cSConrad Meyer { 0x37138086, "JSF IOAT Ch3" }, 181e974f91cSConrad Meyer { 0x37148086, "JSF IOAT Ch4" }, 182e974f91cSConrad Meyer { 0x37158086, "JSF IOAT Ch5" }, 183e974f91cSConrad Meyer { 0x37168086, "JSF IOAT Ch6" }, 184e974f91cSConrad Meyer { 0x37178086, "JSF IOAT Ch7" }, 185e974f91cSConrad Meyer { 0x37188086, "JSF IOAT Ch0 (RAID)" }, 186e974f91cSConrad Meyer { 0x37198086, "JSF IOAT Ch1 (RAID)" }, 187e974f91cSConrad Meyer 188e974f91cSConrad Meyer { 0x3c208086, "SNB IOAT Ch0" }, 189e974f91cSConrad Meyer { 0x3c218086, "SNB IOAT Ch1" }, 190e974f91cSConrad Meyer { 0x3c228086, "SNB IOAT Ch2" }, 191e974f91cSConrad Meyer { 0x3c238086, "SNB IOAT Ch3" }, 192e974f91cSConrad Meyer { 0x3c248086, "SNB IOAT Ch4" }, 193e974f91cSConrad Meyer { 0x3c258086, "SNB IOAT Ch5" }, 194e974f91cSConrad Meyer { 0x3c268086, "SNB IOAT Ch6" }, 195e974f91cSConrad Meyer { 0x3c278086, "SNB IOAT Ch7" }, 196e974f91cSConrad Meyer { 0x3c2e8086, "SNB IOAT Ch0 (RAID)" }, 197e974f91cSConrad Meyer { 0x3c2f8086, "SNB IOAT Ch1 (RAID)" }, 198e974f91cSConrad Meyer 199e974f91cSConrad Meyer { 0x0e208086, "IVB IOAT Ch0" }, 200e974f91cSConrad Meyer { 0x0e218086, "IVB IOAT Ch1" }, 201e974f91cSConrad Meyer { 0x0e228086, "IVB IOAT Ch2" }, 202e974f91cSConrad Meyer { 0x0e238086, "IVB IOAT Ch3" }, 203e974f91cSConrad Meyer { 0x0e248086, "IVB IOAT Ch4" }, 204e974f91cSConrad Meyer { 0x0e258086, "IVB IOAT Ch5" }, 205e974f91cSConrad Meyer { 0x0e268086, "IVB IOAT Ch6" }, 206e974f91cSConrad Meyer { 0x0e278086, "IVB IOAT Ch7" }, 207e974f91cSConrad Meyer { 0x0e2e8086, "IVB IOAT Ch0 (RAID)" }, 208e974f91cSConrad Meyer { 0x0e2f8086, "IVB IOAT Ch1 (RAID)" }, 209e974f91cSConrad Meyer 210e974f91cSConrad Meyer { 0x2f208086, "HSW IOAT Ch0" }, 211e974f91cSConrad Meyer { 0x2f218086, "HSW IOAT Ch1" }, 212e974f91cSConrad Meyer { 0x2f228086, "HSW IOAT Ch2" }, 213e974f91cSConrad Meyer { 0x2f238086, "HSW IOAT Ch3" }, 214e974f91cSConrad Meyer { 0x2f248086, "HSW IOAT Ch4" }, 215e974f91cSConrad Meyer { 0x2f258086, "HSW IOAT Ch5" }, 216e974f91cSConrad Meyer { 0x2f268086, "HSW IOAT Ch6" }, 217e974f91cSConrad Meyer { 0x2f278086, "HSW IOAT Ch7" }, 218e974f91cSConrad Meyer { 0x2f2e8086, "HSW IOAT Ch0 (RAID)" }, 219e974f91cSConrad Meyer { 0x2f2f8086, "HSW IOAT Ch1 (RAID)" }, 220e974f91cSConrad Meyer 221e974f91cSConrad Meyer { 0x0c508086, "BWD IOAT Ch0" }, 222e974f91cSConrad Meyer { 0x0c518086, "BWD IOAT Ch1" }, 223e974f91cSConrad Meyer { 0x0c528086, "BWD IOAT Ch2" }, 224e974f91cSConrad Meyer { 0x0c538086, "BWD IOAT Ch3" }, 225e974f91cSConrad Meyer 226e974f91cSConrad Meyer { 0x6f508086, "BDXDE IOAT Ch0" }, 227e974f91cSConrad Meyer { 0x6f518086, "BDXDE IOAT Ch1" }, 228e974f91cSConrad Meyer { 0x6f528086, "BDXDE IOAT Ch2" }, 229e974f91cSConrad Meyer { 0x6f538086, "BDXDE IOAT Ch3" }, 230e974f91cSConrad Meyer 2315afc2508SConrad Meyer { 0x6f208086, "BDX IOAT Ch0" }, 2325afc2508SConrad Meyer { 0x6f218086, "BDX IOAT Ch1" }, 2335afc2508SConrad Meyer { 0x6f228086, "BDX IOAT Ch2" }, 2345afc2508SConrad Meyer { 0x6f238086, "BDX IOAT Ch3" }, 2355afc2508SConrad Meyer { 0x6f248086, "BDX IOAT Ch4" }, 2365afc2508SConrad Meyer { 0x6f258086, "BDX IOAT Ch5" }, 2375afc2508SConrad Meyer { 0x6f268086, "BDX IOAT Ch6" }, 2385afc2508SConrad Meyer { 0x6f278086, "BDX IOAT Ch7" }, 2395afc2508SConrad Meyer { 0x6f2e8086, "BDX IOAT Ch0 (RAID)" }, 2405afc2508SConrad Meyer { 0x6f2f8086, "BDX IOAT Ch1 (RAID)" }, 24108f16d0cSConrad Meyer 24208f16d0cSConrad Meyer { 0x20218086, "SKX IOAT" }, 243e974f91cSConrad Meyer }; 244e974f91cSConrad Meyer 245d2064cf0SWarner Losh MODULE_PNP_INFO("W32:vendor/device;D:#", pci, ioat, pci_ids, 246329e817fSWarner Losh nitems(pci_ids)); 247a64bf59cSConrad Meyer 248e974f91cSConrad Meyer /* 249e974f91cSConrad Meyer * OS <-> Driver linkage functions 250e974f91cSConrad Meyer */ 251e974f91cSConrad Meyer static int 25271bf3900SAlexander Motin ioat_modevent(module_t mod __unused, int type, void *data __unused) 25371bf3900SAlexander Motin { 25471bf3900SAlexander Motin switch(type) { 25571bf3900SAlexander Motin case MOD_LOAD: 25671bf3900SAlexander Motin break; 25771bf3900SAlexander Motin 25871bf3900SAlexander Motin case MOD_UNLOAD: 25971bf3900SAlexander Motin ioat_test_detach(); 26071bf3900SAlexander Motin break; 26171bf3900SAlexander Motin 26271bf3900SAlexander Motin case MOD_SHUTDOWN: 26371bf3900SAlexander Motin break; 26471bf3900SAlexander Motin 26571bf3900SAlexander Motin default: 26671bf3900SAlexander Motin return (EOPNOTSUPP); 26771bf3900SAlexander Motin } 26871bf3900SAlexander Motin 26971bf3900SAlexander Motin return (0); 27071bf3900SAlexander Motin } 27171bf3900SAlexander Motin 27271bf3900SAlexander Motin static int 273e974f91cSConrad Meyer ioat_probe(device_t device) 274e974f91cSConrad Meyer { 275e974f91cSConrad Meyer struct _pcsid *ep; 276e974f91cSConrad Meyer u_int32_t type; 277e974f91cSConrad Meyer 278e974f91cSConrad Meyer type = pci_get_devid(device); 279a64bf59cSConrad Meyer for (ep = pci_ids; ep < &pci_ids[nitems(pci_ids)]; ep++) { 280e974f91cSConrad Meyer if (ep->type == type) { 281e974f91cSConrad Meyer device_set_desc(device, ep->desc); 282e974f91cSConrad Meyer return (0); 283e974f91cSConrad Meyer } 284e974f91cSConrad Meyer } 285e974f91cSConrad Meyer return (ENXIO); 286e974f91cSConrad Meyer } 287e974f91cSConrad Meyer 288e974f91cSConrad Meyer static int 289e974f91cSConrad Meyer ioat_attach(device_t device) 290e974f91cSConrad Meyer { 291e974f91cSConrad Meyer struct ioat_softc *ioat; 2922f03a95fSAlexander Motin int error, i; 293e974f91cSConrad Meyer 294e974f91cSConrad Meyer ioat = DEVICE2SOFTC(device); 295e974f91cSConrad Meyer ioat->device = device; 296657dc81dSAlexander Motin if (bus_get_domain(device, &ioat->domain) != 0) 297657dc81dSAlexander Motin ioat->domain = 0; 298657dc81dSAlexander Motin ioat->cpu = CPU_FFS(&cpuset_domain[ioat->domain]) - 1; 299657dc81dSAlexander Motin if (ioat->cpu < 0) 300657dc81dSAlexander Motin ioat->cpu = CPU_FIRST(); 301e974f91cSConrad Meyer 302e974f91cSConrad Meyer error = ioat_map_pci_bar(ioat); 303e974f91cSConrad Meyer if (error != 0) 304e974f91cSConrad Meyer goto err; 305e974f91cSConrad Meyer 306e974f91cSConrad Meyer ioat->version = ioat_read_cbver(ioat); 307e974f91cSConrad Meyer if (ioat->version < IOAT_VER_3_0) { 308e974f91cSConrad Meyer error = ENODEV; 309e974f91cSConrad Meyer goto err; 310e974f91cSConrad Meyer } 311e974f91cSConrad Meyer 312e974f91cSConrad Meyer error = ioat3_attach(device); 313e974f91cSConrad Meyer if (error != 0) 314e974f91cSConrad Meyer goto err; 315e974f91cSConrad Meyer 316e974f91cSConrad Meyer error = pci_enable_busmaster(device); 317e974f91cSConrad Meyer if (error != 0) 318e974f91cSConrad Meyer goto err; 319e974f91cSConrad Meyer 320466b3540SConrad Meyer error = ioat_setup_intr(ioat); 321466b3540SConrad Meyer if (error != 0) 322466b3540SConrad Meyer goto err; 323466b3540SConrad Meyer 324cea5b880SConrad Meyer error = ioat_reset_hw(ioat); 3257afbb263SConrad Meyer if (error != 0) 326466b3540SConrad Meyer goto err; 3277afbb263SConrad Meyer 3282f03a95fSAlexander Motin ioat_process_events(ioat, FALSE); 3297afbb263SConrad Meyer ioat_setup_sysctl(device); 3307afbb263SConrad Meyer 3312f03a95fSAlexander Motin mtx_lock(&ioat_list_mtx); 3322f03a95fSAlexander Motin for (i = 0; i < IOAT_MAX_CHANNELS; i++) { 3332f03a95fSAlexander Motin if (ioat_channel[i] == NULL) 3342f03a95fSAlexander Motin break; 3352f03a95fSAlexander Motin } 3362f03a95fSAlexander Motin if (i >= IOAT_MAX_CHANNELS) { 3372f03a95fSAlexander Motin mtx_unlock(&ioat_list_mtx); 3382f03a95fSAlexander Motin device_printf(device, "Too many I/OAT devices in system\n"); 3392f03a95fSAlexander Motin error = ENXIO; 3402f03a95fSAlexander Motin goto err; 3412f03a95fSAlexander Motin } 3422f03a95fSAlexander Motin ioat->chan_idx = i; 3432f03a95fSAlexander Motin ioat_channel[i] = ioat; 3442f03a95fSAlexander Motin if (i >= ioat_channel_index) 3452f03a95fSAlexander Motin ioat_channel_index = i + 1; 3462f03a95fSAlexander Motin mtx_unlock(&ioat_list_mtx); 3472f03a95fSAlexander Motin 3487afbb263SConrad Meyer ioat_test_attach(); 349e974f91cSConrad Meyer 350e974f91cSConrad Meyer err: 351e974f91cSConrad Meyer if (error != 0) 352e974f91cSConrad Meyer ioat_detach(device); 353e974f91cSConrad Meyer return (error); 354e974f91cSConrad Meyer } 355e974f91cSConrad Meyer 356b80b32a2STycho Nightingale static inline int 357b80b32a2STycho Nightingale ioat_bus_dmamap_destroy(struct ioat_softc *ioat, const char *func, 358b80b32a2STycho Nightingale bus_dma_tag_t dmat, bus_dmamap_t map) 359b80b32a2STycho Nightingale { 360b80b32a2STycho Nightingale int error; 361b80b32a2STycho Nightingale 362b80b32a2STycho Nightingale error = bus_dmamap_destroy(dmat, map); 363b80b32a2STycho Nightingale if (error != 0) { 364b80b32a2STycho Nightingale ioat_log_message(0, 365b80b32a2STycho Nightingale "%s: bus_dmamap_destroy failed %d\n", func, error); 366b80b32a2STycho Nightingale } 367b80b32a2STycho Nightingale 368b80b32a2STycho Nightingale return (error); 369b80b32a2STycho Nightingale } 370b80b32a2STycho Nightingale 371e974f91cSConrad Meyer static int 372e974f91cSConrad Meyer ioat_detach(device_t device) 373e974f91cSConrad Meyer { 374e974f91cSConrad Meyer struct ioat_softc *ioat; 375b80b32a2STycho Nightingale int i, error; 376e974f91cSConrad Meyer 377e974f91cSConrad Meyer ioat = DEVICE2SOFTC(device); 3787afbb263SConrad Meyer 3792f03a95fSAlexander Motin mtx_lock(&ioat_list_mtx); 3802f03a95fSAlexander Motin ioat_channel[ioat->chan_idx] = NULL; 3812f03a95fSAlexander Motin while (ioat_channel_index > 0 && 3822f03a95fSAlexander Motin ioat_channel[ioat_channel_index - 1] == NULL) 3832f03a95fSAlexander Motin ioat_channel_index--; 3842f03a95fSAlexander Motin mtx_unlock(&ioat_list_mtx); 3852f03a95fSAlexander Motin 386374b05e1SConrad Meyer taskqueue_drain(taskqueue_thread, &ioat->reset_task); 3875f77bd3eSConrad Meyer 3882f03a95fSAlexander Motin mtx_lock(&ioat->submit_lock); 3895f77bd3eSConrad Meyer ioat->quiescing = TRUE; 3900ff814e8SConrad Meyer ioat->destroying = TRUE; 3910ff814e8SConrad Meyer wakeup(&ioat->quiescing); 39293f7f84aSConrad Meyer wakeup(&ioat->resetting); 3930ff814e8SConrad Meyer 3945f77bd3eSConrad Meyer ioat_drain_locked(ioat); 3952f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 3962f03a95fSAlexander Motin mtx_lock(&ioat->cleanup_lock); 3972f03a95fSAlexander Motin while (ioat_get_active(ioat) > 0) 3982f03a95fSAlexander Motin msleep(&ioat->tail, &ioat->cleanup_lock, 0, "ioat_drain", 1); 3992f03a95fSAlexander Motin mtx_unlock(&ioat->cleanup_lock); 400fe720f5aSConrad Meyer 401fe720f5aSConrad Meyer ioat_teardown_intr(ioat); 4025ac77963SConrad Meyer callout_drain(&ioat->poll_timer); 403e974f91cSConrad Meyer 404e974f91cSConrad Meyer pci_disable_busmaster(device); 405e974f91cSConrad Meyer 406e974f91cSConrad Meyer if (ioat->pci_resource != NULL) 407e974f91cSConrad Meyer bus_release_resource(device, SYS_RES_MEMORY, 408e974f91cSConrad Meyer ioat->pci_resource_id, ioat->pci_resource); 409e974f91cSConrad Meyer 410b80b32a2STycho Nightingale if (ioat->data_tag != NULL) { 411b80b32a2STycho Nightingale for (i = 0; i < 1 << ioat->ring_size_order; i++) { 412b80b32a2STycho Nightingale error = ioat_bus_dmamap_destroy(ioat, __func__, 413b80b32a2STycho Nightingale ioat->data_tag, ioat->ring[i].src_dmamap); 414b80b32a2STycho Nightingale if (error != 0) 415b80b32a2STycho Nightingale return (error); 416b80b32a2STycho Nightingale } 417b80b32a2STycho Nightingale for (i = 0; i < 1 << ioat->ring_size_order; i++) { 418b80b32a2STycho Nightingale error = ioat_bus_dmamap_destroy(ioat, __func__, 419b80b32a2STycho Nightingale ioat->data_tag, ioat->ring[i].dst_dmamap); 420b80b32a2STycho Nightingale if (error != 0) 421b80b32a2STycho Nightingale return (error); 422b80b32a2STycho Nightingale } 423b80b32a2STycho Nightingale 424b80b32a2STycho Nightingale for (i = 0; i < 1 << ioat->ring_size_order; i++) { 425b80b32a2STycho Nightingale error = ioat_bus_dmamap_destroy(ioat, __func__, 426b80b32a2STycho Nightingale ioat->data_tag, ioat->ring[i].src2_dmamap); 427b80b32a2STycho Nightingale if (error != 0) 428b80b32a2STycho Nightingale return (error); 429b80b32a2STycho Nightingale } 430b80b32a2STycho Nightingale for (i = 0; i < 1 << ioat->ring_size_order; i++) { 431b80b32a2STycho Nightingale error = ioat_bus_dmamap_destroy(ioat, __func__, 432b80b32a2STycho Nightingale ioat->data_tag, ioat->ring[i].dst2_dmamap); 433b80b32a2STycho Nightingale if (error != 0) 434b80b32a2STycho Nightingale return (error); 435b80b32a2STycho Nightingale } 436b80b32a2STycho Nightingale 437b80b32a2STycho Nightingale bus_dma_tag_destroy(ioat->data_tag); 438b80b32a2STycho Nightingale } 439b80b32a2STycho Nightingale 440bf8553eaSConrad Meyer if (ioat->ring != NULL) 441bf8553eaSConrad Meyer ioat_free_ring(ioat, 1 << ioat->ring_size_order, ioat->ring); 442e974f91cSConrad Meyer 443e974f91cSConrad Meyer if (ioat->comp_update != NULL) { 444e974f91cSConrad Meyer bus_dmamap_unload(ioat->comp_update_tag, ioat->comp_update_map); 445e974f91cSConrad Meyer bus_dmamem_free(ioat->comp_update_tag, ioat->comp_update, 446e974f91cSConrad Meyer ioat->comp_update_map); 447e974f91cSConrad Meyer bus_dma_tag_destroy(ioat->comp_update_tag); 448e974f91cSConrad Meyer } 449e974f91cSConrad Meyer 4508e269d99SConrad Meyer if (ioat->hw_desc_ring != NULL) { 4518e269d99SConrad Meyer bus_dmamap_unload(ioat->hw_desc_tag, ioat->hw_desc_map); 4528e269d99SConrad Meyer bus_dmamem_free(ioat->hw_desc_tag, ioat->hw_desc_ring, 4538e269d99SConrad Meyer ioat->hw_desc_map); 454e974f91cSConrad Meyer bus_dma_tag_destroy(ioat->hw_desc_tag); 4558e269d99SConrad Meyer } 456e974f91cSConrad Meyer 4574253ea50SConrad Meyer return (0); 4584253ea50SConrad Meyer } 4594253ea50SConrad Meyer 4604253ea50SConrad Meyer static int 4614253ea50SConrad Meyer ioat_teardown_intr(struct ioat_softc *ioat) 4624253ea50SConrad Meyer { 4634253ea50SConrad Meyer 464e974f91cSConrad Meyer if (ioat->tag != NULL) 4654253ea50SConrad Meyer bus_teardown_intr(ioat->device, ioat->res, ioat->tag); 466e974f91cSConrad Meyer 467e974f91cSConrad Meyer if (ioat->res != NULL) 4684253ea50SConrad Meyer bus_release_resource(ioat->device, SYS_RES_IRQ, 469e974f91cSConrad Meyer rman_get_rid(ioat->res), ioat->res); 470e974f91cSConrad Meyer 4714253ea50SConrad Meyer pci_release_msi(ioat->device); 472e974f91cSConrad Meyer return (0); 473e974f91cSConrad Meyer } 474e974f91cSConrad Meyer 475e974f91cSConrad Meyer static int 476cea5b880SConrad Meyer ioat_start_channel(struct ioat_softc *ioat) 477e974f91cSConrad Meyer { 478fe8712f8SConrad Meyer struct ioat_dma_hw_descriptor *hw_desc; 479fe8712f8SConrad Meyer struct ioat_descriptor *desc; 480fe8712f8SConrad Meyer struct bus_dmadesc *dmadesc; 481e974f91cSConrad Meyer uint64_t status; 482e974f91cSConrad Meyer uint32_t chanerr; 483e974f91cSConrad Meyer int i; 484e974f91cSConrad Meyer 485e974f91cSConrad Meyer ioat_acquire(&ioat->dmaengine); 486fe8712f8SConrad Meyer 487fe8712f8SConrad Meyer /* Submit 'NULL' operation manually to avoid quiescing flag */ 488fe8712f8SConrad Meyer desc = ioat_get_ring_entry(ioat, ioat->head); 4898e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, ioat->head)->dma; 490fe8712f8SConrad Meyer dmadesc = &desc->bus_dmadesc; 491fe8712f8SConrad Meyer 492fe8712f8SConrad Meyer dmadesc->callback_fn = NULL; 493fe8712f8SConrad Meyer dmadesc->callback_arg = NULL; 494fe8712f8SConrad Meyer 495fe8712f8SConrad Meyer hw_desc->u.control_raw = 0; 496fe8712f8SConrad Meyer hw_desc->u.control_generic.op = IOAT_OP_COPY; 497fe8712f8SConrad Meyer hw_desc->u.control_generic.completion_update = 1; 498fe8712f8SConrad Meyer hw_desc->size = 8; 499fe8712f8SConrad Meyer hw_desc->src_addr = 0; 500fe8712f8SConrad Meyer hw_desc->dest_addr = 0; 501fe8712f8SConrad Meyer hw_desc->u.control.null = 1; 502fe8712f8SConrad Meyer 503fe8712f8SConrad Meyer ioat_submit_single(ioat); 504e974f91cSConrad Meyer ioat_release(&ioat->dmaengine); 505e974f91cSConrad Meyer 506e974f91cSConrad Meyer for (i = 0; i < 100; i++) { 507e974f91cSConrad Meyer DELAY(1); 508e974f91cSConrad Meyer status = ioat_get_chansts(ioat); 509e974f91cSConrad Meyer if (is_ioat_idle(status)) 510e974f91cSConrad Meyer return (0); 511e974f91cSConrad Meyer } 512e974f91cSConrad Meyer 513e974f91cSConrad Meyer chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET); 514e974f91cSConrad Meyer ioat_log_message(0, "could not start channel: " 51559acd4baSConrad Meyer "status = %#jx error = %b\n", (uintmax_t)status, (int)chanerr, 51659acd4baSConrad Meyer IOAT_CHANERR_STR); 517e974f91cSConrad Meyer return (ENXIO); 518e974f91cSConrad Meyer } 519e974f91cSConrad Meyer 520e974f91cSConrad Meyer /* 521e974f91cSConrad Meyer * Initialize Hardware 522e974f91cSConrad Meyer */ 523e974f91cSConrad Meyer static int 524e974f91cSConrad Meyer ioat3_attach(device_t device) 525e974f91cSConrad Meyer { 526e974f91cSConrad Meyer struct ioat_softc *ioat; 5278e269d99SConrad Meyer struct ioat_descriptor *ring; 528e974f91cSConrad Meyer struct ioat_dma_hw_descriptor *dma_hw_desc; 5298e269d99SConrad Meyer void *hw_desc; 5301f4a469dSAlexander Motin bus_addr_t lowaddr; 5318e269d99SConrad Meyer size_t ringsz; 532e974f91cSConrad Meyer int i, num_descriptors; 533e974f91cSConrad Meyer int error; 534e974f91cSConrad Meyer uint8_t xfercap; 535e974f91cSConrad Meyer 536e974f91cSConrad Meyer error = 0; 537e974f91cSConrad Meyer ioat = DEVICE2SOFTC(device); 5381693d27bSConrad Meyer ioat->capabilities = ioat_read_dmacapability(ioat); 5391693d27bSConrad Meyer 54048fed014SConrad Meyer ioat_log_message(0, "Capabilities: %b\n", (int)ioat->capabilities, 5411693d27bSConrad Meyer IOAT_DMACAP_STR); 542e974f91cSConrad Meyer 543e974f91cSConrad Meyer xfercap = ioat_read_xfercap(ioat); 544e974f91cSConrad Meyer ioat->max_xfer_size = 1 << xfercap; 545e974f91cSConrad Meyer 5465ca9fc2aSConrad Meyer ioat->intrdelay_supported = (ioat_read_2(ioat, IOAT_INTRDELAY_OFFSET) & 5475ca9fc2aSConrad Meyer IOAT_INTRDELAY_SUPPORTED) != 0; 5485ca9fc2aSConrad Meyer if (ioat->intrdelay_supported) 5495ca9fc2aSConrad Meyer ioat->intrdelay_max = IOAT_INTRDELAY_US_MASK; 5505ca9fc2aSConrad Meyer 551e974f91cSConrad Meyer /* TODO: need to check DCA here if we ever do XOR/PQ */ 552e974f91cSConrad Meyer 553e974f91cSConrad Meyer mtx_init(&ioat->submit_lock, "ioat_submit", NULL, MTX_DEF); 554faefad9cSConrad Meyer mtx_init(&ioat->cleanup_lock, "ioat_cleanup", NULL, MTX_DEF); 5555ac77963SConrad Meyer callout_init(&ioat->poll_timer, 1); 556374b05e1SConrad Meyer TASK_INIT(&ioat->reset_task, 0, ioat_reset_hw_task, ioat); 557e974f91cSConrad Meyer 558faefad9cSConrad Meyer /* Establish lock order for Witness */ 559faefad9cSConrad Meyer mtx_lock(&ioat->cleanup_lock); 5602f03a95fSAlexander Motin mtx_lock(&ioat->submit_lock); 561faefad9cSConrad Meyer mtx_unlock(&ioat->submit_lock); 5622f03a95fSAlexander Motin mtx_unlock(&ioat->cleanup_lock); 563faefad9cSConrad Meyer 56425ad9585SConrad Meyer ioat->is_submitter_processing = FALSE; 565e974f91cSConrad Meyer 5661f4a469dSAlexander Motin if (ioat->version >= IOAT_VER_3_3) 5671f4a469dSAlexander Motin lowaddr = BUS_SPACE_MAXADDR_48BIT; 5681f4a469dSAlexander Motin else if (ioat->version >= IOAT_VER_3_2) 5691f4a469dSAlexander Motin lowaddr = BUS_SPACE_MAXADDR_46BIT; 5701f4a469dSAlexander Motin else 5711f4a469dSAlexander Motin lowaddr = BUS_SPACE_MAXADDR_40BIT; 5721f4a469dSAlexander Motin 5731f4a469dSAlexander Motin error = bus_dma_tag_create(bus_get_dma_tag(ioat->device), 5741f4a469dSAlexander Motin sizeof(uint64_t), 0x0, lowaddr, BUS_SPACE_MAXADDR, NULL, NULL, 575e974f91cSConrad Meyer sizeof(uint64_t), 1, sizeof(uint64_t), 0, NULL, NULL, 576e974f91cSConrad Meyer &ioat->comp_update_tag); 5771f4a469dSAlexander Motin if (error != 0) 5781f4a469dSAlexander Motin return (error); 579e974f91cSConrad Meyer 580e974f91cSConrad Meyer error = bus_dmamem_alloc(ioat->comp_update_tag, 5813eb70a09SAlexander Motin (void **)&ioat->comp_update, BUS_DMA_ZERO | BUS_DMA_WAITOK, 5823eb70a09SAlexander Motin &ioat->comp_update_map); 5831f4a469dSAlexander Motin if (error != 0) 5841f4a469dSAlexander Motin return (error); 585e974f91cSConrad Meyer 586e974f91cSConrad Meyer error = bus_dmamap_load(ioat->comp_update_tag, ioat->comp_update_map, 587e974f91cSConrad Meyer ioat->comp_update, sizeof(uint64_t), ioat_comp_update_map, ioat, 5883eb70a09SAlexander Motin BUS_DMA_NOWAIT); 589e974f91cSConrad Meyer if (error != 0) 590e974f91cSConrad Meyer return (error); 591e974f91cSConrad Meyer 592a0992979SConrad Meyer ioat->ring_size_order = g_ioat_ring_order; 593e974f91cSConrad Meyer num_descriptors = 1 << ioat->ring_size_order; 5948e269d99SConrad Meyer ringsz = sizeof(struct ioat_dma_hw_descriptor) * num_descriptors; 595e974f91cSConrad Meyer 5968e269d99SConrad Meyer error = bus_dma_tag_create(bus_get_dma_tag(ioat->device), 5971f4a469dSAlexander Motin 2 * 1024 * 1024, 0x0, lowaddr, BUS_SPACE_MAXADDR, NULL, NULL, 5981f4a469dSAlexander Motin ringsz, 1, ringsz, 0, NULL, NULL, &ioat->hw_desc_tag); 5998e269d99SConrad Meyer if (error != 0) 6008e269d99SConrad Meyer return (error); 6018e269d99SConrad Meyer 6028e269d99SConrad Meyer error = bus_dmamem_alloc(ioat->hw_desc_tag, &hw_desc, 6038e269d99SConrad Meyer BUS_DMA_ZERO | BUS_DMA_WAITOK, &ioat->hw_desc_map); 6048e269d99SConrad Meyer if (error != 0) 6058e269d99SConrad Meyer return (error); 6068e269d99SConrad Meyer 6078e269d99SConrad Meyer error = bus_dmamap_load(ioat->hw_desc_tag, ioat->hw_desc_map, hw_desc, 6083eb70a09SAlexander Motin ringsz, ioat_dmamap_cb, &ioat->hw_desc_bus_addr, BUS_DMA_NOWAIT); 6098e269d99SConrad Meyer if (error) 6108e269d99SConrad Meyer return (error); 6118e269d99SConrad Meyer 6128e269d99SConrad Meyer ioat->hw_desc_ring = hw_desc; 613e974f91cSConrad Meyer 614b80b32a2STycho Nightingale error = bus_dma_tag_create(bus_get_dma_tag(ioat->device), 6151f4a469dSAlexander Motin 1, 0, lowaddr, BUS_SPACE_MAXADDR, NULL, NULL, 616b80b32a2STycho Nightingale ioat->max_xfer_size, 1, ioat->max_xfer_size, 0, NULL, NULL, 617b80b32a2STycho Nightingale &ioat->data_tag); 6181f4a469dSAlexander Motin if (error != 0) 619b80b32a2STycho Nightingale return (error); 620657dc81dSAlexander Motin ioat->ring = malloc_domainset(num_descriptors * sizeof(*ring), M_IOAT, 621657dc81dSAlexander Motin DOMAINSET_PREF(ioat->domain), M_ZERO | M_WAITOK); 622e974f91cSConrad Meyer 623e974f91cSConrad Meyer ring = ioat->ring; 624e974f91cSConrad Meyer for (i = 0; i < num_descriptors; i++) { 6258e269d99SConrad Meyer memset(&ring[i].bus_dmadesc, 0, sizeof(ring[i].bus_dmadesc)); 6268e269d99SConrad Meyer ring[i].id = i; 627b80b32a2STycho Nightingale error = bus_dmamap_create(ioat->data_tag, 0, 628b80b32a2STycho Nightingale &ring[i].src_dmamap); 629b80b32a2STycho Nightingale if (error != 0) { 630b80b32a2STycho Nightingale ioat_log_message(0, 631b80b32a2STycho Nightingale "%s: bus_dmamap_create failed %d\n", __func__, 632b80b32a2STycho Nightingale error); 633b80b32a2STycho Nightingale return (error); 634b80b32a2STycho Nightingale } 635b80b32a2STycho Nightingale error = bus_dmamap_create(ioat->data_tag, 0, 636b80b32a2STycho Nightingale &ring[i].dst_dmamap); 637b80b32a2STycho Nightingale if (error != 0) { 638b80b32a2STycho Nightingale ioat_log_message(0, 639b80b32a2STycho Nightingale "%s: bus_dmamap_create failed %d\n", __func__, 640b80b32a2STycho Nightingale error); 641b80b32a2STycho Nightingale return (error); 642b80b32a2STycho Nightingale } 643b80b32a2STycho Nightingale error = bus_dmamap_create(ioat->data_tag, 0, 644b80b32a2STycho Nightingale &ring[i].src2_dmamap); 645b80b32a2STycho Nightingale if (error != 0) { 646b80b32a2STycho Nightingale ioat_log_message(0, 647b80b32a2STycho Nightingale "%s: bus_dmamap_create failed %d\n", __func__, 648b80b32a2STycho Nightingale error); 649b80b32a2STycho Nightingale return (error); 650b80b32a2STycho Nightingale } 651b80b32a2STycho Nightingale error = bus_dmamap_create(ioat->data_tag, 0, 652b80b32a2STycho Nightingale &ring[i].dst2_dmamap); 653b80b32a2STycho Nightingale if (error != 0) { 654b80b32a2STycho Nightingale ioat_log_message(0, 655b80b32a2STycho Nightingale "%s: bus_dmamap_create failed %d\n", __func__, 656b80b32a2STycho Nightingale error); 657b80b32a2STycho Nightingale return (error); 658b80b32a2STycho Nightingale } 659e974f91cSConrad Meyer } 660e974f91cSConrad Meyer 6618e269d99SConrad Meyer for (i = 0; i < num_descriptors; i++) { 6628e269d99SConrad Meyer dma_hw_desc = &ioat->hw_desc_ring[i].dma; 6638e269d99SConrad Meyer dma_hw_desc->next = RING_PHYS_ADDR(ioat, i + 1); 664e974f91cSConrad Meyer } 665e974f91cSConrad Meyer 666348efb14SAlexander Motin ioat->tail = ioat->head = 0; 667348efb14SAlexander Motin *ioat->comp_update = ioat->last_seen = 668348efb14SAlexander Motin RING_PHYS_ADDR(ioat, ioat->tail - 1); 669e974f91cSConrad Meyer return (0); 670e974f91cSConrad Meyer } 671e974f91cSConrad Meyer 672e974f91cSConrad Meyer static int 673e974f91cSConrad Meyer ioat_map_pci_bar(struct ioat_softc *ioat) 674e974f91cSConrad Meyer { 675e974f91cSConrad Meyer 676e974f91cSConrad Meyer ioat->pci_resource_id = PCIR_BAR(0); 677e88e14b9SConrad Meyer ioat->pci_resource = bus_alloc_resource_any(ioat->device, 678e88e14b9SConrad Meyer SYS_RES_MEMORY, &ioat->pci_resource_id, RF_ACTIVE); 679e974f91cSConrad Meyer 680e974f91cSConrad Meyer if (ioat->pci_resource == NULL) { 681e974f91cSConrad Meyer ioat_log_message(0, "unable to allocate pci resource\n"); 682e974f91cSConrad Meyer return (ENODEV); 683e974f91cSConrad Meyer } 684e974f91cSConrad Meyer 685e974f91cSConrad Meyer ioat->pci_bus_tag = rman_get_bustag(ioat->pci_resource); 686e974f91cSConrad Meyer ioat->pci_bus_handle = rman_get_bushandle(ioat->pci_resource); 687e974f91cSConrad Meyer return (0); 688e974f91cSConrad Meyer } 689e974f91cSConrad Meyer 690e974f91cSConrad Meyer static void 691e974f91cSConrad Meyer ioat_comp_update_map(void *arg, bus_dma_segment_t *seg, int nseg, int error) 692e974f91cSConrad Meyer { 693e974f91cSConrad Meyer struct ioat_softc *ioat = arg; 694e974f91cSConrad Meyer 695cea5b880SConrad Meyer KASSERT(error == 0, ("%s: error:%d", __func__, error)); 696e974f91cSConrad Meyer ioat->comp_update_bus_addr = seg[0].ds_addr; 697e974f91cSConrad Meyer } 698e974f91cSConrad Meyer 699e974f91cSConrad Meyer static void 700e974f91cSConrad Meyer ioat_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error) 701e974f91cSConrad Meyer { 702e974f91cSConrad Meyer bus_addr_t *baddr; 703e974f91cSConrad Meyer 704cea5b880SConrad Meyer KASSERT(error == 0, ("%s: error:%d", __func__, error)); 705e974f91cSConrad Meyer baddr = arg; 706e974f91cSConrad Meyer *baddr = segs->ds_addr; 707e974f91cSConrad Meyer } 708e974f91cSConrad Meyer 709e974f91cSConrad Meyer /* 710e974f91cSConrad Meyer * Interrupt setup and handlers 711e974f91cSConrad Meyer */ 712e974f91cSConrad Meyer static int 7134253ea50SConrad Meyer ioat_setup_intr(struct ioat_softc *ioat) 714e974f91cSConrad Meyer { 715e974f91cSConrad Meyer uint32_t num_vectors; 716e974f91cSConrad Meyer int error; 717e974f91cSConrad Meyer boolean_t use_msix; 718e974f91cSConrad Meyer 719e974f91cSConrad Meyer use_msix = FALSE; 720e974f91cSConrad Meyer 721e974f91cSConrad Meyer if (!g_force_legacy_interrupts && pci_msix_count(ioat->device) >= 1) { 722e974f91cSConrad Meyer num_vectors = 1; 723e974f91cSConrad Meyer pci_alloc_msix(ioat->device, &num_vectors); 724e974f91cSConrad Meyer if (num_vectors == 1) 725e974f91cSConrad Meyer use_msix = TRUE; 726e974f91cSConrad Meyer } 727e974f91cSConrad Meyer 728e974f91cSConrad Meyer if (use_msix) { 729e974f91cSConrad Meyer ioat->rid = 1; 730e974f91cSConrad Meyer ioat->res = bus_alloc_resource_any(ioat->device, SYS_RES_IRQ, 731e974f91cSConrad Meyer &ioat->rid, RF_ACTIVE); 732e974f91cSConrad Meyer } else { 733e974f91cSConrad Meyer ioat->rid = 0; 734e974f91cSConrad Meyer ioat->res = bus_alloc_resource_any(ioat->device, SYS_RES_IRQ, 735e974f91cSConrad Meyer &ioat->rid, RF_SHAREABLE | RF_ACTIVE); 736e974f91cSConrad Meyer } 737e974f91cSConrad Meyer if (ioat->res == NULL) { 738e974f91cSConrad Meyer ioat_log_message(0, "bus_alloc_resource failed\n"); 739e974f91cSConrad Meyer return (ENOMEM); 740e974f91cSConrad Meyer } 741e974f91cSConrad Meyer 742e974f91cSConrad Meyer ioat->tag = NULL; 743e974f91cSConrad Meyer error = bus_setup_intr(ioat->device, ioat->res, INTR_MPSAFE | 744e974f91cSConrad Meyer INTR_TYPE_MISC, NULL, ioat_interrupt_handler, ioat, &ioat->tag); 745e974f91cSConrad Meyer if (error != 0) { 746e974f91cSConrad Meyer ioat_log_message(0, "bus_setup_intr failed\n"); 747e974f91cSConrad Meyer return (error); 748e974f91cSConrad Meyer } 749e974f91cSConrad Meyer 750e974f91cSConrad Meyer ioat_write_intrctrl(ioat, IOAT_INTRCTRL_MASTER_INT_EN); 751e974f91cSConrad Meyer return (0); 752e974f91cSConrad Meyer } 753e974f91cSConrad Meyer 7544253ea50SConrad Meyer static boolean_t 7550d1a05d9SConrad Meyer ioat_model_resets_msix(struct ioat_softc *ioat) 7564253ea50SConrad Meyer { 7574253ea50SConrad Meyer u_int32_t pciid; 7584253ea50SConrad Meyer 7594253ea50SConrad Meyer pciid = pci_get_devid(ioat->device); 7604253ea50SConrad Meyer switch (pciid) { 7610d1a05d9SConrad Meyer /* BWD: */ 7620d1a05d9SConrad Meyer case 0x0c508086: 7630d1a05d9SConrad Meyer case 0x0c518086: 7640d1a05d9SConrad Meyer case 0x0c528086: 7650d1a05d9SConrad Meyer case 0x0c538086: 7660d1a05d9SConrad Meyer /* BDXDE: */ 7674253ea50SConrad Meyer case 0x6f508086: 7684253ea50SConrad Meyer case 0x6f518086: 7694253ea50SConrad Meyer case 0x6f528086: 7704253ea50SConrad Meyer case 0x6f538086: 7714253ea50SConrad Meyer return (TRUE); 7724253ea50SConrad Meyer } 7734253ea50SConrad Meyer 7744253ea50SConrad Meyer return (FALSE); 7754253ea50SConrad Meyer } 7764253ea50SConrad Meyer 777e974f91cSConrad Meyer static void 778e974f91cSConrad Meyer ioat_interrupt_handler(void *arg) 779e974f91cSConrad Meyer { 780e974f91cSConrad Meyer struct ioat_softc *ioat = arg; 781e974f91cSConrad Meyer 78201fbbc88SConrad Meyer ioat->stats.interrupts++; 7832f03a95fSAlexander Motin ioat_process_events(ioat, TRUE); 784e974f91cSConrad Meyer } 785e974f91cSConrad Meyer 786faefad9cSConrad Meyer static int 787faefad9cSConrad Meyer chanerr_to_errno(uint32_t chanerr) 788faefad9cSConrad Meyer { 789faefad9cSConrad Meyer 790faefad9cSConrad Meyer if (chanerr == 0) 791faefad9cSConrad Meyer return (0); 792faefad9cSConrad Meyer if ((chanerr & (IOAT_CHANERR_XSADDERR | IOAT_CHANERR_XDADDERR)) != 0) 793faefad9cSConrad Meyer return (EFAULT); 794faefad9cSConrad Meyer if ((chanerr & (IOAT_CHANERR_RDERR | IOAT_CHANERR_WDERR)) != 0) 795faefad9cSConrad Meyer return (EIO); 796faefad9cSConrad Meyer /* This one is probably our fault: */ 797faefad9cSConrad Meyer if ((chanerr & IOAT_CHANERR_NDADDERR) != 0) 798faefad9cSConrad Meyer return (EIO); 799faefad9cSConrad Meyer return (EIO); 800faefad9cSConrad Meyer } 801faefad9cSConrad Meyer 802e974f91cSConrad Meyer static void 8032f03a95fSAlexander Motin ioat_process_events(struct ioat_softc *ioat, boolean_t intr) 804e974f91cSConrad Meyer { 805e974f91cSConrad Meyer struct ioat_descriptor *desc; 806e974f91cSConrad Meyer struct bus_dmadesc *dmadesc; 807e974f91cSConrad Meyer uint64_t comp_update, status; 808faefad9cSConrad Meyer uint32_t completed, chanerr; 809f955fec7SMateusz Guzik int error __diagused; 810e974f91cSConrad Meyer 8118acd3f12SAlexander Motin if (intr) { 812e974f91cSConrad Meyer mtx_lock(&ioat->cleanup_lock); 8138acd3f12SAlexander Motin } else { 8148acd3f12SAlexander Motin if (!mtx_trylock(&ioat->cleanup_lock)) 8158acd3f12SAlexander Motin return; 8168acd3f12SAlexander Motin } 817e974f91cSConrad Meyer 818fe8712f8SConrad Meyer /* 819fe8712f8SConrad Meyer * Don't run while the hardware is being reset. Reset is responsible 820fe8712f8SConrad Meyer * for blocking new work and draining & completing existing work, so 821fe8712f8SConrad Meyer * there is nothing to do until new work is queued after reset anyway. 822fe8712f8SConrad Meyer */ 823fe8712f8SConrad Meyer if (ioat->resetting_cleanup) { 824fe8712f8SConrad Meyer mtx_unlock(&ioat->cleanup_lock); 825fe8712f8SConrad Meyer return; 826fe8712f8SConrad Meyer } 827fe8712f8SConrad Meyer 828e974f91cSConrad Meyer completed = 0; 8290d0f2640SConrad Meyer comp_update = *ioat->comp_update; 830e974f91cSConrad Meyer status = comp_update & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_MASK; 831e974f91cSConrad Meyer 8328e269d99SConrad Meyer if (status < ioat->hw_desc_bus_addr || 8338e269d99SConrad Meyer status >= ioat->hw_desc_bus_addr + (1 << ioat->ring_size_order) * 8348e269d99SConrad Meyer sizeof(struct ioat_generic_hw_descriptor)) 8358e269d99SConrad Meyer panic("Bogus completion address %jx (channel %u)", 8368e269d99SConrad Meyer (uintmax_t)status, ioat->chan_idx); 8378e269d99SConrad Meyer 8381bbc06b8SConrad Meyer if (status == ioat->last_seen) { 8391bbc06b8SConrad Meyer /* 8401bbc06b8SConrad Meyer * If we landed in process_events and nothing has been 8411bbc06b8SConrad Meyer * completed, check for a timeout due to channel halt. 8421bbc06b8SConrad Meyer */ 8431bbc06b8SConrad Meyer goto out; 8441bbc06b8SConrad Meyer } 845dc465059SConrad Meyer CTR4(KTR_IOAT, "%s channel=%u hw_status=0x%lx last_seen=0x%lx", 846dc465059SConrad Meyer __func__, ioat->chan_idx, comp_update, ioat->last_seen); 8471bbc06b8SConrad Meyer 8488e269d99SConrad Meyer while (RING_PHYS_ADDR(ioat, ioat->tail - 1) != status) { 849e974f91cSConrad Meyer desc = ioat_get_ring_entry(ioat, ioat->tail); 850e974f91cSConrad Meyer dmadesc = &desc->bus_dmadesc; 85105e4cffbSConrad Meyer CTR5(KTR_IOAT, "channel=%u completing desc idx %u (%p) ok cb %p(%p)", 85205e4cffbSConrad Meyer ioat->chan_idx, ioat->tail, dmadesc, dmadesc->callback_fn, 853520f6023SConrad Meyer dmadesc->callback_arg); 854e974f91cSConrad Meyer 855b80b32a2STycho Nightingale bus_dmamap_unload(ioat->data_tag, desc->src_dmamap); 856b80b32a2STycho Nightingale bus_dmamap_unload(ioat->data_tag, desc->dst_dmamap); 857b80b32a2STycho Nightingale bus_dmamap_unload(ioat->data_tag, desc->src2_dmamap); 858b80b32a2STycho Nightingale bus_dmamap_unload(ioat->data_tag, desc->dst2_dmamap); 859b80b32a2STycho Nightingale 860faefad9cSConrad Meyer if (dmadesc->callback_fn != NULL) 861faefad9cSConrad Meyer dmadesc->callback_fn(dmadesc->callback_arg, 0); 862e974f91cSConrad Meyer 863466b3540SConrad Meyer completed++; 864e974f91cSConrad Meyer ioat->tail++; 865e974f91cSConrad Meyer } 86605e4cffbSConrad Meyer CTR5(KTR_IOAT, "%s channel=%u head=%u tail=%u active=%u", __func__, 86705e4cffbSConrad Meyer ioat->chan_idx, ioat->head, ioat->tail, ioat_get_active(ioat)); 868e974f91cSConrad Meyer 8690283c0f5SConrad Meyer if (completed != 0) { 8708e269d99SConrad Meyer ioat->last_seen = RING_PHYS_ADDR(ioat, ioat->tail - 1); 87101fbbc88SConrad Meyer ioat->stats.descriptors_processed += completed; 8722f03a95fSAlexander Motin wakeup(&ioat->tail); 8730283c0f5SConrad Meyer } 87401fbbc88SConrad Meyer 8751bbc06b8SConrad Meyer out: 876e974f91cSConrad Meyer ioat_write_chanctrl(ioat, IOAT_CHANCTRL_RUN); 877e974f91cSConrad Meyer mtx_unlock(&ioat->cleanup_lock); 878faefad9cSConrad Meyer 879ea9e23edSConrad Meyer /* 880ea9e23edSConrad Meyer * The device doesn't seem to reliably push suspend/halt statuses to 881ea9e23edSConrad Meyer * the channel completion memory address, so poll the device register 8822f03a95fSAlexander Motin * here. For performance reasons skip it on interrupts, do it only 8832f03a95fSAlexander Motin * on much more rare polling events. 884ea9e23edSConrad Meyer */ 8852f03a95fSAlexander Motin if (!intr) 886ea9e23edSConrad Meyer comp_update = ioat_get_chansts(ioat) & IOAT_CHANSTS_STATUS; 887d2c55e5aSConrad Meyer if (!is_ioat_halted(comp_update) && !is_ioat_suspended(comp_update)) 888faefad9cSConrad Meyer return; 889faefad9cSConrad Meyer 89001fbbc88SConrad Meyer ioat->stats.channel_halts++; 89101fbbc88SConrad Meyer 892faefad9cSConrad Meyer /* 893faefad9cSConrad Meyer * Fatal programming error on this DMA channel. Flush any outstanding 894faefad9cSConrad Meyer * work with error status and restart the engine. 895faefad9cSConrad Meyer */ 896faefad9cSConrad Meyer mtx_lock(&ioat->submit_lock); 897faefad9cSConrad Meyer ioat->quiescing = TRUE; 8982f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 8992f03a95fSAlexander Motin 9003a370919SConrad Meyer /* 9012f03a95fSAlexander Motin * This is safe to do here because the submit queue is quiesced. We 9022f03a95fSAlexander Motin * know that we will drain all outstanding events, so ioat_reset_hw 9032f03a95fSAlexander Motin * can't deadlock. It is necessary to protect other ioat_process_event 9042f03a95fSAlexander Motin * threads from racing ioat_reset_hw, reading an indeterminate hw 9052f03a95fSAlexander Motin * state, and attempting to continue issuing completions. 9063a370919SConrad Meyer */ 9072f03a95fSAlexander Motin mtx_lock(&ioat->cleanup_lock); 9083a370919SConrad Meyer ioat->resetting_cleanup = TRUE; 909faefad9cSConrad Meyer 910faefad9cSConrad Meyer chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET); 911985efa77SConrad Meyer if (1 <= g_ioat_debug_level) 912faefad9cSConrad Meyer ioat_halted_debug(ioat, chanerr); 91301fbbc88SConrad Meyer ioat->stats.last_halt_chanerr = chanerr; 914faefad9cSConrad Meyer 915faefad9cSConrad Meyer while (ioat_get_active(ioat) > 0) { 916faefad9cSConrad Meyer desc = ioat_get_ring_entry(ioat, ioat->tail); 917faefad9cSConrad Meyer dmadesc = &desc->bus_dmadesc; 91805e4cffbSConrad Meyer CTR5(KTR_IOAT, "channel=%u completing desc idx %u (%p) err cb %p(%p)", 91905e4cffbSConrad Meyer ioat->chan_idx, ioat->tail, dmadesc, dmadesc->callback_fn, 920520f6023SConrad Meyer dmadesc->callback_arg); 921faefad9cSConrad Meyer 922faefad9cSConrad Meyer if (dmadesc->callback_fn != NULL) 923faefad9cSConrad Meyer dmadesc->callback_fn(dmadesc->callback_arg, 924faefad9cSConrad Meyer chanerr_to_errno(chanerr)); 925faefad9cSConrad Meyer 926faefad9cSConrad Meyer ioat->tail++; 92701fbbc88SConrad Meyer ioat->stats.descriptors_processed++; 92801fbbc88SConrad Meyer ioat->stats.descriptors_error++; 929faefad9cSConrad Meyer } 93005e4cffbSConrad Meyer CTR5(KTR_IOAT, "%s channel=%u head=%u tail=%u active=%u", __func__, 93105e4cffbSConrad Meyer ioat->chan_idx, ioat->head, ioat->tail, ioat_get_active(ioat)); 932faefad9cSConrad Meyer 933faefad9cSConrad Meyer /* Clear error status */ 934faefad9cSConrad Meyer ioat_write_4(ioat, IOAT_CHANERR_OFFSET, chanerr); 935faefad9cSConrad Meyer 936faefad9cSConrad Meyer mtx_unlock(&ioat->cleanup_lock); 937faefad9cSConrad Meyer 938faefad9cSConrad Meyer ioat_log_message(0, "Resetting channel to recover from error\n"); 939374b05e1SConrad Meyer error = taskqueue_enqueue(taskqueue_thread, &ioat->reset_task); 940374b05e1SConrad Meyer KASSERT(error == 0, 941374b05e1SConrad Meyer ("%s: taskqueue_enqueue failed: %d", __func__, error)); 942374b05e1SConrad Meyer } 943374b05e1SConrad Meyer 944374b05e1SConrad Meyer static void 945374b05e1SConrad Meyer ioat_reset_hw_task(void *ctx, int pending __unused) 946374b05e1SConrad Meyer { 947374b05e1SConrad Meyer struct ioat_softc *ioat; 948f955fec7SMateusz Guzik int error __diagused; 949374b05e1SConrad Meyer 950374b05e1SConrad Meyer ioat = ctx; 951374b05e1SConrad Meyer ioat_log_message(1, "%s: Resetting channel\n", __func__); 952374b05e1SConrad Meyer 953faefad9cSConrad Meyer error = ioat_reset_hw(ioat); 954faefad9cSConrad Meyer KASSERT(error == 0, ("%s: reset failed: %d", __func__, error)); 955e974f91cSConrad Meyer } 956e974f91cSConrad Meyer 957e974f91cSConrad Meyer /* 958e974f91cSConrad Meyer * User API functions 959e974f91cSConrad Meyer */ 960f8f92e91SConrad Meyer unsigned 961f8f92e91SConrad Meyer ioat_get_nchannels(void) 962f8f92e91SConrad Meyer { 963f8f92e91SConrad Meyer 964f8f92e91SConrad Meyer return (ioat_channel_index); 965f8f92e91SConrad Meyer } 966f8f92e91SConrad Meyer 967e974f91cSConrad Meyer bus_dmaengine_t 9680ff814e8SConrad Meyer ioat_get_dmaengine(uint32_t index, int flags) 969e974f91cSConrad Meyer { 9700ff814e8SConrad Meyer struct ioat_softc *ioat; 9710ff814e8SConrad Meyer 9720ff814e8SConrad Meyer KASSERT((flags & ~(M_NOWAIT | M_WAITOK)) == 0, 9730ff814e8SConrad Meyer ("invalid flags: 0x%08x", flags)); 9740ff814e8SConrad Meyer KASSERT((flags & (M_NOWAIT | M_WAITOK)) != (M_NOWAIT | M_WAITOK), 9750ff814e8SConrad Meyer ("invalid wait | nowait")); 976e974f91cSConrad Meyer 9772f03a95fSAlexander Motin mtx_lock(&ioat_list_mtx); 9782f03a95fSAlexander Motin if (index >= ioat_channel_index || 9792f03a95fSAlexander Motin (ioat = ioat_channel[index]) == NULL) { 9802f03a95fSAlexander Motin mtx_unlock(&ioat_list_mtx); 981e974f91cSConrad Meyer return (NULL); 9822f03a95fSAlexander Motin } 9832f03a95fSAlexander Motin mtx_lock(&ioat->submit_lock); 9842f03a95fSAlexander Motin mtx_unlock(&ioat_list_mtx); 9855f77bd3eSConrad Meyer 9862f03a95fSAlexander Motin if (ioat->destroying) { 9872f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 9880ff814e8SConrad Meyer return (NULL); 9890ff814e8SConrad Meyer } 9900ff814e8SConrad Meyer 9912f03a95fSAlexander Motin ioat_get(ioat); 9922f03a95fSAlexander Motin if (ioat->quiescing) { 9932f03a95fSAlexander Motin if ((flags & M_NOWAIT) != 0) { 9942f03a95fSAlexander Motin ioat_put(ioat); 9952f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 9962f03a95fSAlexander Motin return (NULL); 9972f03a95fSAlexander Motin } 9982f03a95fSAlexander Motin 9992f03a95fSAlexander Motin while (ioat->quiescing && !ioat->destroying) 10002f03a95fSAlexander Motin msleep(&ioat->quiescing, &ioat->submit_lock, 0, "getdma", 0); 10012f03a95fSAlexander Motin 10022f03a95fSAlexander Motin if (ioat->destroying) { 10032f03a95fSAlexander Motin ioat_put(ioat); 10042f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 10052f03a95fSAlexander Motin return (NULL); 10062f03a95fSAlexander Motin } 10072f03a95fSAlexander Motin } 10082f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 10092f03a95fSAlexander Motin return (&ioat->dmaengine); 1010466b3540SConrad Meyer } 1011466b3540SConrad Meyer 1012466b3540SConrad Meyer void 1013466b3540SConrad Meyer ioat_put_dmaengine(bus_dmaengine_t dmaengine) 1014466b3540SConrad Meyer { 1015466b3540SConrad Meyer struct ioat_softc *ioat; 1016466b3540SConrad Meyer 1017466b3540SConrad Meyer ioat = to_ioat_softc(dmaengine); 10182f03a95fSAlexander Motin mtx_lock(&ioat->submit_lock); 10192f03a95fSAlexander Motin ioat_put(ioat); 10202f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 1021e974f91cSConrad Meyer } 1022e974f91cSConrad Meyer 10235ca9fc2aSConrad Meyer int 102431bf2875SConrad Meyer ioat_get_hwversion(bus_dmaengine_t dmaengine) 102531bf2875SConrad Meyer { 102631bf2875SConrad Meyer struct ioat_softc *ioat; 102731bf2875SConrad Meyer 102831bf2875SConrad Meyer ioat = to_ioat_softc(dmaengine); 102931bf2875SConrad Meyer return (ioat->version); 103031bf2875SConrad Meyer } 103131bf2875SConrad Meyer 1032bd81fe68SConrad Meyer size_t 1033bd81fe68SConrad Meyer ioat_get_max_io_size(bus_dmaengine_t dmaengine) 1034bd81fe68SConrad Meyer { 1035bd81fe68SConrad Meyer struct ioat_softc *ioat; 1036bd81fe68SConrad Meyer 1037bd81fe68SConrad Meyer ioat = to_ioat_softc(dmaengine); 1038bd81fe68SConrad Meyer return (ioat->max_xfer_size); 1039bd81fe68SConrad Meyer } 1040bd81fe68SConrad Meyer 1041f8253f1aSConrad Meyer uint32_t 1042f8253f1aSConrad Meyer ioat_get_capabilities(bus_dmaengine_t dmaengine) 1043f8253f1aSConrad Meyer { 1044f8253f1aSConrad Meyer struct ioat_softc *ioat; 1045f8253f1aSConrad Meyer 1046f8253f1aSConrad Meyer ioat = to_ioat_softc(dmaengine); 1047f8253f1aSConrad Meyer return (ioat->capabilities); 1048f8253f1aSConrad Meyer } 1049f8253f1aSConrad Meyer 105031bf2875SConrad Meyer int 10517280125eSAlexander Motin ioat_get_domain(bus_dmaengine_t dmaengine, int *domain) 10527280125eSAlexander Motin { 10537280125eSAlexander Motin struct ioat_softc *ioat; 10547280125eSAlexander Motin 10557280125eSAlexander Motin ioat = to_ioat_softc(dmaengine); 10567280125eSAlexander Motin return (bus_get_domain(ioat->device, domain)); 10577280125eSAlexander Motin } 10587280125eSAlexander Motin 10597280125eSAlexander Motin int 10605ca9fc2aSConrad Meyer ioat_set_interrupt_coalesce(bus_dmaengine_t dmaengine, uint16_t delay) 10615ca9fc2aSConrad Meyer { 10625ca9fc2aSConrad Meyer struct ioat_softc *ioat; 10635ca9fc2aSConrad Meyer 10645ca9fc2aSConrad Meyer ioat = to_ioat_softc(dmaengine); 10655ca9fc2aSConrad Meyer if (!ioat->intrdelay_supported) 10665ca9fc2aSConrad Meyer return (ENODEV); 10675ca9fc2aSConrad Meyer if (delay > ioat->intrdelay_max) 10685ca9fc2aSConrad Meyer return (ERANGE); 10695ca9fc2aSConrad Meyer 10705ca9fc2aSConrad Meyer ioat_write_2(ioat, IOAT_INTRDELAY_OFFSET, delay); 10715ca9fc2aSConrad Meyer ioat->cached_intrdelay = 10725ca9fc2aSConrad Meyer ioat_read_2(ioat, IOAT_INTRDELAY_OFFSET) & IOAT_INTRDELAY_US_MASK; 10735ca9fc2aSConrad Meyer return (0); 10745ca9fc2aSConrad Meyer } 10755ca9fc2aSConrad Meyer 10765ca9fc2aSConrad Meyer uint16_t 10775ca9fc2aSConrad Meyer ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine) 10785ca9fc2aSConrad Meyer { 10795ca9fc2aSConrad Meyer struct ioat_softc *ioat; 10805ca9fc2aSConrad Meyer 10815ca9fc2aSConrad Meyer ioat = to_ioat_softc(dmaengine); 10825ca9fc2aSConrad Meyer return (ioat->intrdelay_max); 10835ca9fc2aSConrad Meyer } 10845ca9fc2aSConrad Meyer 1085e974f91cSConrad Meyer void 1086e974f91cSConrad Meyer ioat_acquire(bus_dmaengine_t dmaengine) 1087e974f91cSConrad Meyer { 1088e974f91cSConrad Meyer struct ioat_softc *ioat; 1089e974f91cSConrad Meyer 1090e974f91cSConrad Meyer ioat = to_ioat_softc(dmaengine); 1091e974f91cSConrad Meyer mtx_lock(&ioat->submit_lock); 1092520f6023SConrad Meyer CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx); 109358a639b7SConrad Meyer ioat->acq_head = ioat->head; 1094e974f91cSConrad Meyer } 1095e974f91cSConrad Meyer 10961502e363SConrad Meyer int 10971502e363SConrad Meyer ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags) 10981502e363SConrad Meyer { 10991502e363SConrad Meyer struct ioat_softc *ioat; 11001502e363SConrad Meyer int error; 11011502e363SConrad Meyer 11021502e363SConrad Meyer ioat = to_ioat_softc(dmaengine); 11031502e363SConrad Meyer ioat_acquire(dmaengine); 11041502e363SConrad Meyer 11051502e363SConrad Meyer error = ioat_reserve_space(ioat, n, mflags); 11061502e363SConrad Meyer if (error != 0) 11071502e363SConrad Meyer ioat_release(dmaengine); 11081502e363SConrad Meyer return (error); 11091502e363SConrad Meyer } 11101502e363SConrad Meyer 1111e974f91cSConrad Meyer void 1112e974f91cSConrad Meyer ioat_release(bus_dmaengine_t dmaengine) 1113e974f91cSConrad Meyer { 1114e974f91cSConrad Meyer struct ioat_softc *ioat; 1115e974f91cSConrad Meyer 1116e974f91cSConrad Meyer ioat = to_ioat_softc(dmaengine); 11172f03a95fSAlexander Motin CTR3(KTR_IOAT, "%s channel=%u dispatch1 head=%u", __func__, 11182f03a95fSAlexander Motin ioat->chan_idx, ioat->head); 111976305bb8SConrad Meyer KFAIL_POINT_CODE(DEBUG_FP, ioat_release, /* do nothing */); 11202f03a95fSAlexander Motin CTR3(KTR_IOAT, "%s channel=%u dispatch2 head=%u", __func__, 11212f03a95fSAlexander Motin ioat->chan_idx, ioat->head); 112276305bb8SConrad Meyer 112358a639b7SConrad Meyer if (ioat->acq_head != ioat->head) { 112458a639b7SConrad Meyer ioat_write_2(ioat, IOAT_DMACOUNT_OFFSET, 11252f03a95fSAlexander Motin (uint16_t)ioat->head); 1126f44abf1fSConrad Meyer 11272f03a95fSAlexander Motin if (!callout_pending(&ioat->poll_timer)) { 1128657dc81dSAlexander Motin callout_reset_on(&ioat->poll_timer, 1, 1129657dc81dSAlexander Motin ioat_poll_timer_callback, ioat, ioat->cpu); 113058a639b7SConrad Meyer } 1131f44abf1fSConrad Meyer } 1132e974f91cSConrad Meyer mtx_unlock(&ioat->submit_lock); 1133e974f91cSConrad Meyer } 1134e974f91cSConrad Meyer 11359e3bbf26SConrad Meyer static struct ioat_descriptor * 11369e3bbf26SConrad Meyer ioat_op_generic(struct ioat_softc *ioat, uint8_t op, 11379e3bbf26SConrad Meyer uint32_t size, uint64_t src, uint64_t dst, 11389e3bbf26SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, 11399e3bbf26SConrad Meyer uint32_t flags) 1140e974f91cSConrad Meyer { 11419e3bbf26SConrad Meyer struct ioat_generic_hw_descriptor *hw_desc; 1142e974f91cSConrad Meyer struct ioat_descriptor *desc; 1143b80b32a2STycho Nightingale bus_dma_segment_t seg; 1144b80b32a2STycho Nightingale int mflags, nseg, error; 1145e974f91cSConrad Meyer 11469e3bbf26SConrad Meyer mtx_assert(&ioat->submit_lock, MA_OWNED); 11479e3bbf26SConrad Meyer 1148bec7ff79SConrad Meyer KASSERT((flags & ~_DMA_GENERIC_FLAGS) == 0, 1149bec7ff79SConrad Meyer ("Unrecognized flag(s): %#x", flags & ~_DMA_GENERIC_FLAGS)); 1150630d9800SAlexander Motin KASSERT(size <= ioat->max_xfer_size, ("%s: size too big (%u > %u)", 1151630d9800SAlexander Motin __func__, (unsigned)size, ioat->max_xfer_size)); 1152630d9800SAlexander Motin 1153bf8553eaSConrad Meyer if ((flags & DMA_NO_WAIT) != 0) 1154bf8553eaSConrad Meyer mflags = M_NOWAIT; 1155bf8553eaSConrad Meyer else 1156bf8553eaSConrad Meyer mflags = M_WAITOK; 1157e974f91cSConrad Meyer 1158bf8553eaSConrad Meyer if (ioat_reserve_space(ioat, 1, mflags) != 0) 1159e974f91cSConrad Meyer return (NULL); 1160e974f91cSConrad Meyer 1161e974f91cSConrad Meyer desc = ioat_get_ring_entry(ioat, ioat->head); 11628e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, ioat->head)->generic; 1163e974f91cSConrad Meyer 1164e974f91cSConrad Meyer hw_desc->u.control_raw = 0; 11659e3bbf26SConrad Meyer hw_desc->u.control_generic.op = op; 11669e3bbf26SConrad Meyer hw_desc->u.control_generic.completion_update = 1; 1167e974f91cSConrad Meyer 1168e974f91cSConrad Meyer if ((flags & DMA_INT_EN) != 0) 11699e3bbf26SConrad Meyer hw_desc->u.control_generic.int_enable = 1; 11706ca07079SConrad Meyer if ((flags & DMA_FENCE) != 0) 11716ca07079SConrad Meyer hw_desc->u.control_generic.fence = 1; 1172e974f91cSConrad Meyer 11739e3bbf26SConrad Meyer hw_desc->size = size; 1174b80b32a2STycho Nightingale 1175b80b32a2STycho Nightingale if (src != 0) { 1176b80b32a2STycho Nightingale nseg = -1; 1177b80b32a2STycho Nightingale error = _bus_dmamap_load_phys(ioat->data_tag, desc->src_dmamap, 1178b80b32a2STycho Nightingale src, size, 0, &seg, &nseg); 1179b80b32a2STycho Nightingale if (error != 0) { 1180b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1181b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1182b80b32a2STycho Nightingale return (NULL); 1183b80b32a2STycho Nightingale } 1184b80b32a2STycho Nightingale hw_desc->src_addr = seg.ds_addr; 1185b80b32a2STycho Nightingale } 1186b80b32a2STycho Nightingale 1187b80b32a2STycho Nightingale if (dst != 0) { 1188b80b32a2STycho Nightingale nseg = -1; 1189b80b32a2STycho Nightingale error = _bus_dmamap_load_phys(ioat->data_tag, desc->dst_dmamap, 1190b80b32a2STycho Nightingale dst, size, 0, &seg, &nseg); 1191b80b32a2STycho Nightingale if (error != 0) { 1192b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1193b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1194b80b32a2STycho Nightingale return (NULL); 1195b80b32a2STycho Nightingale } 1196b80b32a2STycho Nightingale hw_desc->dest_addr = seg.ds_addr; 1197b80b32a2STycho Nightingale } 1198e974f91cSConrad Meyer 1199e974f91cSConrad Meyer desc->bus_dmadesc.callback_fn = callback_fn; 1200e974f91cSConrad Meyer desc->bus_dmadesc.callback_arg = callback_arg; 12019e3bbf26SConrad Meyer return (desc); 12029e3bbf26SConrad Meyer } 1203e974f91cSConrad Meyer 12049e3bbf26SConrad Meyer struct bus_dmadesc * 12059e3bbf26SConrad Meyer ioat_null(bus_dmaengine_t dmaengine, bus_dmaengine_callback_t callback_fn, 12069e3bbf26SConrad Meyer void *callback_arg, uint32_t flags) 12079e3bbf26SConrad Meyer { 12089e3bbf26SConrad Meyer struct ioat_dma_hw_descriptor *hw_desc; 12099e3bbf26SConrad Meyer struct ioat_descriptor *desc; 12109e3bbf26SConrad Meyer struct ioat_softc *ioat; 12119e3bbf26SConrad Meyer 12129e3bbf26SConrad Meyer ioat = to_ioat_softc(dmaengine); 1213520f6023SConrad Meyer CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx); 12149e3bbf26SConrad Meyer 12159e3bbf26SConrad Meyer desc = ioat_op_generic(ioat, IOAT_OP_COPY, 8, 0, 0, callback_fn, 12169e3bbf26SConrad Meyer callback_arg, flags); 12179e3bbf26SConrad Meyer if (desc == NULL) 12189e3bbf26SConrad Meyer return (NULL); 12199e3bbf26SConrad Meyer 12208e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, desc->id)->dma; 12219e3bbf26SConrad Meyer hw_desc->u.control.null = 1; 1222e974f91cSConrad Meyer ioat_submit_single(ioat); 1223e974f91cSConrad Meyer return (&desc->bus_dmadesc); 1224e974f91cSConrad Meyer } 1225e974f91cSConrad Meyer 1226e974f91cSConrad Meyer struct bus_dmadesc * 1227e974f91cSConrad Meyer ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst, 1228e974f91cSConrad Meyer bus_addr_t src, bus_size_t len, bus_dmaengine_callback_t callback_fn, 1229e974f91cSConrad Meyer void *callback_arg, uint32_t flags) 1230e974f91cSConrad Meyer { 1231e974f91cSConrad Meyer struct ioat_dma_hw_descriptor *hw_desc; 12329e3bbf26SConrad Meyer struct ioat_descriptor *desc; 1233e974f91cSConrad Meyer struct ioat_softc *ioat; 1234e974f91cSConrad Meyer 1235e974f91cSConrad Meyer ioat = to_ioat_softc(dmaengine); 12369e3bbf26SConrad Meyer desc = ioat_op_generic(ioat, IOAT_OP_COPY, len, src, dst, callback_fn, 12379e3bbf26SConrad Meyer callback_arg, flags); 12389e3bbf26SConrad Meyer if (desc == NULL) 1239e974f91cSConrad Meyer return (NULL); 1240e974f91cSConrad Meyer 12418e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, desc->id)->dma; 1242e974f91cSConrad Meyer if (g_ioat_debug_level >= 3) 1243e974f91cSConrad Meyer dump_descriptor(hw_desc); 1244e974f91cSConrad Meyer 1245e974f91cSConrad Meyer ioat_submit_single(ioat); 124605e4cffbSConrad Meyer CTR6(KTR_IOAT, "%s channel=%u desc=%p dest=%lx src=%lx len=%lx", 124705e4cffbSConrad Meyer __func__, ioat->chan_idx, &desc->bus_dmadesc, dst, src, len); 1248e974f91cSConrad Meyer return (&desc->bus_dmadesc); 1249e974f91cSConrad Meyer } 1250e974f91cSConrad Meyer 12512a4fd6b1SConrad Meyer struct bus_dmadesc * 12529950fde0SConrad Meyer ioat_copy_8k_aligned(bus_dmaengine_t dmaengine, bus_addr_t dst1, 12539950fde0SConrad Meyer bus_addr_t dst2, bus_addr_t src1, bus_addr_t src2, 12549950fde0SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags) 12559950fde0SConrad Meyer { 12569950fde0SConrad Meyer struct ioat_dma_hw_descriptor *hw_desc; 12579950fde0SConrad Meyer struct ioat_descriptor *desc; 12589950fde0SConrad Meyer struct ioat_softc *ioat; 1259b80b32a2STycho Nightingale bus_size_t src1_len, dst1_len; 1260b80b32a2STycho Nightingale bus_dma_segment_t seg; 1261b80b32a2STycho Nightingale int nseg, error; 12629950fde0SConrad Meyer 12639950fde0SConrad Meyer ioat = to_ioat_softc(dmaengine); 1264520f6023SConrad Meyer CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx); 12659950fde0SConrad Meyer 1266630d9800SAlexander Motin KASSERT(((src1 | src2 | dst1 | dst2) & PAGE_MASK) == 0, 1267630d9800SAlexander Motin ("%s: addresses are not page-aligned", __func__)); 12689950fde0SConrad Meyer 1269b80b32a2STycho Nightingale desc = ioat_op_generic(ioat, IOAT_OP_COPY, 2 * PAGE_SIZE, 0, 0, 12709950fde0SConrad Meyer callback_fn, callback_arg, flags); 12719950fde0SConrad Meyer if (desc == NULL) 12729950fde0SConrad Meyer return (NULL); 12739950fde0SConrad Meyer 12748e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, desc->id)->dma; 1275b80b32a2STycho Nightingale 1276b80b32a2STycho Nightingale src1_len = (src2 != src1 + PAGE_SIZE) ? PAGE_SIZE : 2 * PAGE_SIZE; 1277b80b32a2STycho Nightingale nseg = -1; 1278b80b32a2STycho Nightingale error = _bus_dmamap_load_phys(ioat->data_tag, 1279b80b32a2STycho Nightingale desc->src_dmamap, src1, src1_len, 0, &seg, &nseg); 1280b80b32a2STycho Nightingale if (error != 0) { 1281b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1282b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1283b80b32a2STycho Nightingale return (NULL); 12849950fde0SConrad Meyer } 1285b80b32a2STycho Nightingale hw_desc->src_addr = seg.ds_addr; 1286b80b32a2STycho Nightingale if (src1_len != 2 * PAGE_SIZE) { 1287b80b32a2STycho Nightingale hw_desc->u.control.src_page_break = 1; 1288b80b32a2STycho Nightingale nseg = -1; 1289b80b32a2STycho Nightingale error = _bus_dmamap_load_phys(ioat->data_tag, 1290b80b32a2STycho Nightingale desc->src2_dmamap, src2, PAGE_SIZE, 0, &seg, &nseg); 1291b80b32a2STycho Nightingale if (error != 0) { 1292b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1293b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1294b80b32a2STycho Nightingale return (NULL); 1295b80b32a2STycho Nightingale } 1296b80b32a2STycho Nightingale hw_desc->next_src_addr = seg.ds_addr; 1297b80b32a2STycho Nightingale } 1298b80b32a2STycho Nightingale 1299b80b32a2STycho Nightingale dst1_len = (dst2 != dst1 + PAGE_SIZE) ? PAGE_SIZE : 2 * PAGE_SIZE; 1300b80b32a2STycho Nightingale nseg = -1; 1301b80b32a2STycho Nightingale error = _bus_dmamap_load_phys(ioat->data_tag, 1302b80b32a2STycho Nightingale desc->dst_dmamap, dst1, dst1_len, 0, &seg, &nseg); 1303b80b32a2STycho Nightingale if (error != 0) { 1304b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1305b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1306b80b32a2STycho Nightingale return (NULL); 1307b80b32a2STycho Nightingale } 1308b80b32a2STycho Nightingale hw_desc->dest_addr = seg.ds_addr; 1309b80b32a2STycho Nightingale if (dst1_len != 2 * PAGE_SIZE) { 13109950fde0SConrad Meyer hw_desc->u.control.dest_page_break = 1; 1311b80b32a2STycho Nightingale nseg = -1; 1312b80b32a2STycho Nightingale error = _bus_dmamap_load_phys(ioat->data_tag, 1313b80b32a2STycho Nightingale desc->dst2_dmamap, dst2, PAGE_SIZE, 0, &seg, &nseg); 1314b80b32a2STycho Nightingale if (error != 0) { 1315b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1316b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1317b80b32a2STycho Nightingale return (NULL); 1318b80b32a2STycho Nightingale } 1319b80b32a2STycho Nightingale hw_desc->next_dest_addr = seg.ds_addr; 13209950fde0SConrad Meyer } 13219950fde0SConrad Meyer 13229950fde0SConrad Meyer if (g_ioat_debug_level >= 3) 13239950fde0SConrad Meyer dump_descriptor(hw_desc); 13249950fde0SConrad Meyer 13259950fde0SConrad Meyer ioat_submit_single(ioat); 13269950fde0SConrad Meyer return (&desc->bus_dmadesc); 13279950fde0SConrad Meyer } 13289950fde0SConrad Meyer 13299950fde0SConrad Meyer struct bus_dmadesc * 1330bec7ff79SConrad Meyer ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t dst, bus_addr_t src, 1331bec7ff79SConrad Meyer bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr, 1332bec7ff79SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags) 1333bec7ff79SConrad Meyer { 1334bec7ff79SConrad Meyer struct ioat_crc32_hw_descriptor *hw_desc; 1335bec7ff79SConrad Meyer struct ioat_descriptor *desc; 1336bec7ff79SConrad Meyer struct ioat_softc *ioat; 1337bec7ff79SConrad Meyer uint32_t teststore; 1338bec7ff79SConrad Meyer uint8_t op; 1339b80b32a2STycho Nightingale bus_dma_segment_t seg; 1340b80b32a2STycho Nightingale int nseg, error; 1341bec7ff79SConrad Meyer 1342bec7ff79SConrad Meyer ioat = to_ioat_softc(dmaengine); 1343520f6023SConrad Meyer CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx); 1344bec7ff79SConrad Meyer 1345630d9800SAlexander Motin KASSERT((ioat->capabilities & IOAT_DMACAP_MOVECRC) != 0, 1346630d9800SAlexander Motin ("%s: device lacks MOVECRC capability", __func__)); 1347bec7ff79SConrad Meyer teststore = (flags & _DMA_CRC_TESTSTORE); 1348630d9800SAlexander Motin KASSERT(teststore != _DMA_CRC_TESTSTORE, 1349630d9800SAlexander Motin ("%s: TEST and STORE invalid", __func__)); 1350630d9800SAlexander Motin KASSERT(teststore != 0 || (flags & DMA_CRC_INLINE) == 0, 1351630d9800SAlexander Motin ("%s: INLINE invalid without TEST or STORE", __func__)); 1352bec7ff79SConrad Meyer 1353bec7ff79SConrad Meyer switch (teststore) { 1354bec7ff79SConrad Meyer case DMA_CRC_STORE: 1355bec7ff79SConrad Meyer op = IOAT_OP_MOVECRC_STORE; 1356bec7ff79SConrad Meyer break; 1357bec7ff79SConrad Meyer case DMA_CRC_TEST: 1358bec7ff79SConrad Meyer op = IOAT_OP_MOVECRC_TEST; 1359bec7ff79SConrad Meyer break; 1360bec7ff79SConrad Meyer default: 1361bec7ff79SConrad Meyer KASSERT(teststore == 0, ("bogus")); 1362bec7ff79SConrad Meyer op = IOAT_OP_MOVECRC; 1363bec7ff79SConrad Meyer break; 1364bec7ff79SConrad Meyer } 1365bec7ff79SConrad Meyer 1366bec7ff79SConrad Meyer desc = ioat_op_generic(ioat, op, len, src, dst, callback_fn, 1367bec7ff79SConrad Meyer callback_arg, flags & ~_DMA_CRC_FLAGS); 1368bec7ff79SConrad Meyer if (desc == NULL) 1369bec7ff79SConrad Meyer return (NULL); 1370bec7ff79SConrad Meyer 13718e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, desc->id)->crc32; 1372bec7ff79SConrad Meyer 1373b80b32a2STycho Nightingale if ((flags & DMA_CRC_INLINE) == 0) { 1374b80b32a2STycho Nightingale nseg = -1; 13751f4a469dSAlexander Motin error = _bus_dmamap_load_phys(ioat->data_tag, 13761f4a469dSAlexander Motin desc->dst2_dmamap, crcptr, sizeof(uint32_t), 0, 1377b80b32a2STycho Nightingale &seg, &nseg); 1378b80b32a2STycho Nightingale if (error != 0) { 1379b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1380b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1381b80b32a2STycho Nightingale return (NULL); 1382b80b32a2STycho Nightingale } 1383b80b32a2STycho Nightingale hw_desc->crc_address = seg.ds_addr; 1384b80b32a2STycho Nightingale } else 1385bec7ff79SConrad Meyer hw_desc->u.control.crc_location = 1; 1386bec7ff79SConrad Meyer 1387bec7ff79SConrad Meyer if (initialseed != NULL) { 1388bec7ff79SConrad Meyer hw_desc->u.control.use_seed = 1; 1389bec7ff79SConrad Meyer hw_desc->seed = *initialseed; 1390bec7ff79SConrad Meyer } 1391bec7ff79SConrad Meyer 1392bec7ff79SConrad Meyer if (g_ioat_debug_level >= 3) 1393bec7ff79SConrad Meyer dump_descriptor(hw_desc); 1394bec7ff79SConrad Meyer 1395bec7ff79SConrad Meyer ioat_submit_single(ioat); 1396bec7ff79SConrad Meyer return (&desc->bus_dmadesc); 1397bec7ff79SConrad Meyer } 1398bec7ff79SConrad Meyer 1399bec7ff79SConrad Meyer struct bus_dmadesc * 1400bec7ff79SConrad Meyer ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src, bus_size_t len, 1401bec7ff79SConrad Meyer uint32_t *initialseed, bus_addr_t crcptr, 1402bec7ff79SConrad Meyer bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags) 1403bec7ff79SConrad Meyer { 1404bec7ff79SConrad Meyer struct ioat_crc32_hw_descriptor *hw_desc; 1405bec7ff79SConrad Meyer struct ioat_descriptor *desc; 1406bec7ff79SConrad Meyer struct ioat_softc *ioat; 1407bec7ff79SConrad Meyer uint32_t teststore; 1408bec7ff79SConrad Meyer uint8_t op; 1409b80b32a2STycho Nightingale bus_dma_segment_t seg; 1410b80b32a2STycho Nightingale int nseg, error; 1411bec7ff79SConrad Meyer 1412bec7ff79SConrad Meyer ioat = to_ioat_softc(dmaengine); 1413520f6023SConrad Meyer CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx); 1414bec7ff79SConrad Meyer 1415630d9800SAlexander Motin KASSERT((ioat->capabilities & IOAT_DMACAP_CRC) != 0, 1416630d9800SAlexander Motin ("%s: device lacks CRC capability", __func__)); 1417bec7ff79SConrad Meyer teststore = (flags & _DMA_CRC_TESTSTORE); 1418630d9800SAlexander Motin KASSERT(teststore != _DMA_CRC_TESTSTORE, 1419630d9800SAlexander Motin ("%s: TEST and STORE invalid", __func__)); 1420630d9800SAlexander Motin KASSERT(teststore != 0 || (flags & DMA_CRC_INLINE) == 0, 1421630d9800SAlexander Motin ("%s: INLINE invalid without TEST or STORE", __func__)); 1422bec7ff79SConrad Meyer 1423bec7ff79SConrad Meyer switch (teststore) { 1424bec7ff79SConrad Meyer case DMA_CRC_STORE: 1425bec7ff79SConrad Meyer op = IOAT_OP_CRC_STORE; 1426bec7ff79SConrad Meyer break; 1427bec7ff79SConrad Meyer case DMA_CRC_TEST: 1428bec7ff79SConrad Meyer op = IOAT_OP_CRC_TEST; 1429bec7ff79SConrad Meyer break; 1430bec7ff79SConrad Meyer default: 1431bec7ff79SConrad Meyer KASSERT(teststore == 0, ("bogus")); 1432bec7ff79SConrad Meyer op = IOAT_OP_CRC; 1433bec7ff79SConrad Meyer break; 1434bec7ff79SConrad Meyer } 1435bec7ff79SConrad Meyer 1436bec7ff79SConrad Meyer desc = ioat_op_generic(ioat, op, len, src, 0, callback_fn, 1437bec7ff79SConrad Meyer callback_arg, flags & ~_DMA_CRC_FLAGS); 1438bec7ff79SConrad Meyer if (desc == NULL) 1439bec7ff79SConrad Meyer return (NULL); 1440bec7ff79SConrad Meyer 14418e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, desc->id)->crc32; 1442bec7ff79SConrad Meyer 1443b80b32a2STycho Nightingale if ((flags & DMA_CRC_INLINE) == 0) { 1444b80b32a2STycho Nightingale nseg = -1; 14451f4a469dSAlexander Motin error = _bus_dmamap_load_phys(ioat->data_tag, 14461f4a469dSAlexander Motin desc->dst2_dmamap, crcptr, sizeof(uint32_t), 0, 1447b80b32a2STycho Nightingale &seg, &nseg); 1448b80b32a2STycho Nightingale if (error != 0) { 1449b80b32a2STycho Nightingale ioat_log_message(0, "%s: _bus_dmamap_load_phys" 1450b80b32a2STycho Nightingale " failed %d\n", __func__, error); 1451b80b32a2STycho Nightingale return (NULL); 1452b80b32a2STycho Nightingale } 1453b80b32a2STycho Nightingale hw_desc->crc_address = seg.ds_addr; 1454b80b32a2STycho Nightingale } else 1455bec7ff79SConrad Meyer hw_desc->u.control.crc_location = 1; 1456bec7ff79SConrad Meyer 1457bec7ff79SConrad Meyer if (initialseed != NULL) { 1458bec7ff79SConrad Meyer hw_desc->u.control.use_seed = 1; 1459bec7ff79SConrad Meyer hw_desc->seed = *initialseed; 1460bec7ff79SConrad Meyer } 1461bec7ff79SConrad Meyer 1462bec7ff79SConrad Meyer if (g_ioat_debug_level >= 3) 1463bec7ff79SConrad Meyer dump_descriptor(hw_desc); 1464bec7ff79SConrad Meyer 1465bec7ff79SConrad Meyer ioat_submit_single(ioat); 1466bec7ff79SConrad Meyer return (&desc->bus_dmadesc); 1467bec7ff79SConrad Meyer } 1468bec7ff79SConrad Meyer 1469bec7ff79SConrad Meyer struct bus_dmadesc * 14702a4fd6b1SConrad Meyer ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t dst, uint64_t fillpattern, 14712a4fd6b1SConrad Meyer bus_size_t len, bus_dmaengine_callback_t callback_fn, void *callback_arg, 14722a4fd6b1SConrad Meyer uint32_t flags) 14732a4fd6b1SConrad Meyer { 14742a4fd6b1SConrad Meyer struct ioat_fill_hw_descriptor *hw_desc; 14752a4fd6b1SConrad Meyer struct ioat_descriptor *desc; 14762a4fd6b1SConrad Meyer struct ioat_softc *ioat; 14772a4fd6b1SConrad Meyer 14782a4fd6b1SConrad Meyer ioat = to_ioat_softc(dmaengine); 1479520f6023SConrad Meyer CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx); 14802a4fd6b1SConrad Meyer 1481630d9800SAlexander Motin KASSERT((ioat->capabilities & IOAT_DMACAP_BFILL) != 0, 1482630d9800SAlexander Motin ("%s: device lacks BFILL capability", __func__)); 14832a4fd6b1SConrad Meyer 1484b80b32a2STycho Nightingale desc = ioat_op_generic(ioat, IOAT_OP_FILL, len, 0, dst, 14852a4fd6b1SConrad Meyer callback_fn, callback_arg, flags); 14862a4fd6b1SConrad Meyer if (desc == NULL) 14872a4fd6b1SConrad Meyer return (NULL); 14882a4fd6b1SConrad Meyer 14898e269d99SConrad Meyer hw_desc = &ioat_get_descriptor(ioat, desc->id)->fill; 1490b80b32a2STycho Nightingale hw_desc->src_data = fillpattern; 14912a4fd6b1SConrad Meyer if (g_ioat_debug_level >= 3) 14922a4fd6b1SConrad Meyer dump_descriptor(hw_desc); 14932a4fd6b1SConrad Meyer 14942a4fd6b1SConrad Meyer ioat_submit_single(ioat); 14952a4fd6b1SConrad Meyer return (&desc->bus_dmadesc); 14962a4fd6b1SConrad Meyer } 14972a4fd6b1SConrad Meyer 1498e974f91cSConrad Meyer /* 1499e974f91cSConrad Meyer * Ring Management 1500e974f91cSConrad Meyer */ 1501e974f91cSConrad Meyer static inline uint32_t 1502e974f91cSConrad Meyer ioat_get_active(struct ioat_softc *ioat) 1503e974f91cSConrad Meyer { 1504e974f91cSConrad Meyer 1505e974f91cSConrad Meyer return ((ioat->head - ioat->tail) & ((1 << ioat->ring_size_order) - 1)); 1506e974f91cSConrad Meyer } 1507e974f91cSConrad Meyer 1508e974f91cSConrad Meyer static inline uint32_t 1509e974f91cSConrad Meyer ioat_get_ring_space(struct ioat_softc *ioat) 1510e974f91cSConrad Meyer { 1511e974f91cSConrad Meyer 1512e974f91cSConrad Meyer return ((1 << ioat->ring_size_order) - ioat_get_active(ioat) - 1); 1513e974f91cSConrad Meyer } 1514e974f91cSConrad Meyer 1515bf8553eaSConrad Meyer /* 1516bf8553eaSConrad Meyer * Reserves space in this IOAT descriptor ring by ensuring enough slots remain 1517bf8553eaSConrad Meyer * for 'num_descs'. 1518bf8553eaSConrad Meyer * 1519bf8553eaSConrad Meyer * If mflags contains M_WAITOK, blocks until enough space is available. 1520bf8553eaSConrad Meyer * 1521bf8553eaSConrad Meyer * Returns zero on success, or an errno on error. If num_descs is beyond the 1522bf8553eaSConrad Meyer * maximum ring size, returns EINVAl; if allocation would block and mflags 1523bf8553eaSConrad Meyer * contains M_NOWAIT, returns EAGAIN. 1524bf8553eaSConrad Meyer * 1525bf8553eaSConrad Meyer * Must be called with the submit_lock held; returns with the lock held. The 1526bf8553eaSConrad Meyer * lock may be dropped to allocate the ring. 1527bf8553eaSConrad Meyer * 1528bf8553eaSConrad Meyer * (The submit_lock is needed to add any entries to the ring, so callers are 1529bf8553eaSConrad Meyer * assured enough room is available.) 1530bf8553eaSConrad Meyer */ 1531e974f91cSConrad Meyer static int 1532bf8553eaSConrad Meyer ioat_reserve_space(struct ioat_softc *ioat, uint32_t num_descs, int mflags) 1533e974f91cSConrad Meyer { 153425ad9585SConrad Meyer boolean_t dug; 1535bf8553eaSConrad Meyer int error; 1536e974f91cSConrad Meyer 1537bf8553eaSConrad Meyer mtx_assert(&ioat->submit_lock, MA_OWNED); 1538bf8553eaSConrad Meyer error = 0; 153925ad9585SConrad Meyer dug = FALSE; 1540e974f91cSConrad Meyer 1541a0992979SConrad Meyer if (num_descs < 1 || num_descs >= (1 << ioat->ring_size_order)) { 1542bf8553eaSConrad Meyer error = EINVAL; 1543bf8553eaSConrad Meyer goto out; 1544e974f91cSConrad Meyer } 154508a6b96aSConrad Meyer 154608a6b96aSConrad Meyer for (;;) { 15475f77bd3eSConrad Meyer if (ioat->quiescing) { 15485f77bd3eSConrad Meyer error = ENXIO; 15495f77bd3eSConrad Meyer goto out; 15505f77bd3eSConrad Meyer } 1551bf8553eaSConrad Meyer 1552bf8553eaSConrad Meyer if (ioat_get_ring_space(ioat) >= num_descs) 1553bf8553eaSConrad Meyer goto out; 1554bf8553eaSConrad Meyer 155505e4cffbSConrad Meyer CTR3(KTR_IOAT, "%s channel=%u starved (%u)", __func__, 155605e4cffbSConrad Meyer ioat->chan_idx, num_descs); 155705e4cffbSConrad Meyer 1558a0992979SConrad Meyer if (!dug && !ioat->is_submitter_processing) { 155925ad9585SConrad Meyer ioat->is_submitter_processing = TRUE; 156025ad9585SConrad Meyer mtx_unlock(&ioat->submit_lock); 156125ad9585SConrad Meyer 156205e4cffbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u attempting to process events", 156305e4cffbSConrad Meyer __func__, ioat->chan_idx); 15642f03a95fSAlexander Motin ioat_process_events(ioat, FALSE); 156525ad9585SConrad Meyer 156625ad9585SConrad Meyer mtx_lock(&ioat->submit_lock); 156725ad9585SConrad Meyer dug = TRUE; 156825ad9585SConrad Meyer KASSERT(ioat->is_submitter_processing == TRUE, 156925ad9585SConrad Meyer ("is_submitter_processing")); 157025ad9585SConrad Meyer ioat->is_submitter_processing = FALSE; 157125ad9585SConrad Meyer wakeup(&ioat->tail); 157225ad9585SConrad Meyer continue; 157325ad9585SConrad Meyer } 157425ad9585SConrad Meyer 1575a0992979SConrad Meyer if ((mflags & M_WAITOK) == 0) { 1576a0992979SConrad Meyer error = EAGAIN; 1577a0992979SConrad Meyer break; 1578a0992979SConrad Meyer } 157905e4cffbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u blocking on completions", 158005e4cffbSConrad Meyer __func__, ioat->chan_idx); 1581bf8553eaSConrad Meyer msleep(&ioat->tail, &ioat->submit_lock, 0, 1582a0992979SConrad Meyer "ioat_full", 0); 1583bf8553eaSConrad Meyer continue; 1584bf8553eaSConrad Meyer } 1585bf8553eaSConrad Meyer 1586bf8553eaSConrad Meyer out: 1587bf8553eaSConrad Meyer mtx_assert(&ioat->submit_lock, MA_OWNED); 158808a6b96aSConrad Meyer KASSERT(!ioat->quiescing || error == ENXIO, 158908a6b96aSConrad Meyer ("reserved during quiesce")); 1590bf8553eaSConrad Meyer return (error); 1591bf8553eaSConrad Meyer } 1592bf8553eaSConrad Meyer 1593bf8553eaSConrad Meyer static void 1594bf8553eaSConrad Meyer ioat_free_ring(struct ioat_softc *ioat, uint32_t size, 15958e269d99SConrad Meyer struct ioat_descriptor *ring) 1596bf8553eaSConrad Meyer { 1597bf8553eaSConrad Meyer 159896ad26eeSMark Johnston free(ring, M_IOAT); 1599e974f91cSConrad Meyer } 1600e974f91cSConrad Meyer 1601e974f91cSConrad Meyer static struct ioat_descriptor * 1602e974f91cSConrad Meyer ioat_get_ring_entry(struct ioat_softc *ioat, uint32_t index) 1603e974f91cSConrad Meyer { 1604e974f91cSConrad Meyer 16058e269d99SConrad Meyer return (&ioat->ring[index % (1 << ioat->ring_size_order)]); 16068e269d99SConrad Meyer } 16078e269d99SConrad Meyer 16088e269d99SConrad Meyer static union ioat_hw_descriptor * 16098e269d99SConrad Meyer ioat_get_descriptor(struct ioat_softc *ioat, uint32_t index) 16108e269d99SConrad Meyer { 16118e269d99SConrad Meyer 16128e269d99SConrad Meyer return (&ioat->hw_desc_ring[index % (1 << ioat->ring_size_order)]); 1613e974f91cSConrad Meyer } 1614e974f91cSConrad Meyer 1615e974f91cSConrad Meyer static void 16168f274637SConrad Meyer ioat_halted_debug(struct ioat_softc *ioat, uint32_t chanerr) 1617e974f91cSConrad Meyer { 16188e269d99SConrad Meyer union ioat_hw_descriptor *desc; 16198f274637SConrad Meyer 162059acd4baSConrad Meyer ioat_log_message(0, "Channel halted (%b)\n", (int)chanerr, 162159acd4baSConrad Meyer IOAT_CHANERR_STR); 16228f274637SConrad Meyer if (chanerr == 0) 16238f274637SConrad Meyer return; 16248f274637SConrad Meyer 1625faefad9cSConrad Meyer mtx_assert(&ioat->cleanup_lock, MA_OWNED); 1626faefad9cSConrad Meyer 16278e269d99SConrad Meyer desc = ioat_get_descriptor(ioat, ioat->tail + 0); 16288e269d99SConrad Meyer dump_descriptor(desc); 16298f274637SConrad Meyer 16308e269d99SConrad Meyer desc = ioat_get_descriptor(ioat, ioat->tail + 1); 16318e269d99SConrad Meyer dump_descriptor(desc); 16328f274637SConrad Meyer } 16338f274637SConrad Meyer 16348f274637SConrad Meyer static void 16355ac77963SConrad Meyer ioat_poll_timer_callback(void *arg) 16365ac77963SConrad Meyer { 16375ac77963SConrad Meyer struct ioat_softc *ioat; 16385ac77963SConrad Meyer 16395ac77963SConrad Meyer ioat = arg; 1640630d9800SAlexander Motin CTR1(KTR_IOAT, "%s", __func__); 16415ac77963SConrad Meyer 16422f03a95fSAlexander Motin ioat_process_events(ioat, FALSE); 16432f03a95fSAlexander Motin 16442f03a95fSAlexander Motin mtx_lock(&ioat->submit_lock); 16452f03a95fSAlexander Motin if (ioat_get_active(ioat) > 0) 16462f03a95fSAlexander Motin callout_schedule(&ioat->poll_timer, 1); 16472f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 16485ac77963SConrad Meyer } 16495ac77963SConrad Meyer 1650e974f91cSConrad Meyer /* 1651e974f91cSConrad Meyer * Support Functions 1652e974f91cSConrad Meyer */ 1653e974f91cSConrad Meyer static void 1654e974f91cSConrad Meyer ioat_submit_single(struct ioat_softc *ioat) 1655e974f91cSConrad Meyer { 1656e974f91cSConrad Meyer 16575a8af401SConrad Meyer mtx_assert(&ioat->submit_lock, MA_OWNED); 16585a8af401SConrad Meyer 16592f03a95fSAlexander Motin ioat->head++; 16602f03a95fSAlexander Motin CTR4(KTR_IOAT, "%s channel=%u head=%u tail=%u", __func__, 16612f03a95fSAlexander Motin ioat->chan_idx, ioat->head, ioat->tail); 1662e974f91cSConrad Meyer 166301fbbc88SConrad Meyer ioat->stats.descriptors_submitted++; 1664e974f91cSConrad Meyer } 1665e974f91cSConrad Meyer 1666e974f91cSConrad Meyer static int 1667e974f91cSConrad Meyer ioat_reset_hw(struct ioat_softc *ioat) 1668e974f91cSConrad Meyer { 1669e974f91cSConrad Meyer uint64_t status; 1670e974f91cSConrad Meyer uint32_t chanerr; 1671cea5b880SConrad Meyer unsigned timeout; 16725f77bd3eSConrad Meyer int error; 16735f77bd3eSConrad Meyer 1674520f6023SConrad Meyer CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx); 16756d41e1edSConrad Meyer 16762f03a95fSAlexander Motin mtx_lock(&ioat->submit_lock); 167793f7f84aSConrad Meyer while (ioat->resetting && !ioat->destroying) 16782f03a95fSAlexander Motin msleep(&ioat->resetting, &ioat->submit_lock, 0, "IRH_drain", 0); 167993f7f84aSConrad Meyer if (ioat->destroying) { 16802f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 168193f7f84aSConrad Meyer return (ENXIO); 168293f7f84aSConrad Meyer } 168393f7f84aSConrad Meyer ioat->resetting = TRUE; 16845f77bd3eSConrad Meyer ioat->quiescing = TRUE; 16852f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 16862f03a95fSAlexander Motin mtx_lock(&ioat->cleanup_lock); 16872f03a95fSAlexander Motin while (ioat_get_active(ioat) > 0) 16882f03a95fSAlexander Motin msleep(&ioat->tail, &ioat->cleanup_lock, 0, "ioat_drain", 1); 1689e974f91cSConrad Meyer 1690fe8712f8SConrad Meyer /* 1691fe8712f8SConrad Meyer * Suspend ioat_process_events while the hardware and softc are in an 1692fe8712f8SConrad Meyer * indeterminate state. 1693fe8712f8SConrad Meyer */ 1694fe8712f8SConrad Meyer ioat->resetting_cleanup = TRUE; 1695fe8712f8SConrad Meyer mtx_unlock(&ioat->cleanup_lock); 1696fe8712f8SConrad Meyer 1697ee5642bbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u quiesced and drained", __func__, 1698ee5642bbSConrad Meyer ioat->chan_idx); 1699ee5642bbSConrad Meyer 1700e974f91cSConrad Meyer status = ioat_get_chansts(ioat); 1701e974f91cSConrad Meyer if (is_ioat_active(status) || is_ioat_idle(status)) 1702e974f91cSConrad Meyer ioat_suspend(ioat); 1703e974f91cSConrad Meyer 1704e974f91cSConrad Meyer /* Wait at most 20 ms */ 1705e974f91cSConrad Meyer for (timeout = 0; (is_ioat_active(status) || is_ioat_idle(status)) && 1706e974f91cSConrad Meyer timeout < 20; timeout++) { 1707e974f91cSConrad Meyer DELAY(1000); 1708e974f91cSConrad Meyer status = ioat_get_chansts(ioat); 1709e974f91cSConrad Meyer } 17105f77bd3eSConrad Meyer if (timeout == 20) { 17115f77bd3eSConrad Meyer error = ETIMEDOUT; 17125f77bd3eSConrad Meyer goto out; 17135f77bd3eSConrad Meyer } 1714e974f91cSConrad Meyer 1715cea5b880SConrad Meyer KASSERT(ioat_get_active(ioat) == 0, ("active after quiesce")); 1716cea5b880SConrad Meyer 1717e974f91cSConrad Meyer chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET); 1718e974f91cSConrad Meyer ioat_write_4(ioat, IOAT_CHANERR_OFFSET, chanerr); 1719e974f91cSConrad Meyer 1720ee5642bbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u hardware suspended", __func__, 1721ee5642bbSConrad Meyer ioat->chan_idx); 1722ee5642bbSConrad Meyer 1723e974f91cSConrad Meyer /* 1724e974f91cSConrad Meyer * IOAT v3 workaround - CHANERRMSK_INT with 3E07h to masks out errors 1725e974f91cSConrad Meyer * that can cause stability issues for IOAT v3. 1726e974f91cSConrad Meyer */ 1727e974f91cSConrad Meyer pci_write_config(ioat->device, IOAT_CFG_CHANERRMASK_INT_OFFSET, 0x3e07, 1728e974f91cSConrad Meyer 4); 1729e974f91cSConrad Meyer chanerr = pci_read_config(ioat->device, IOAT_CFG_CHANERR_INT_OFFSET, 4); 1730e974f91cSConrad Meyer pci_write_config(ioat->device, IOAT_CFG_CHANERR_INT_OFFSET, chanerr, 4); 1731e974f91cSConrad Meyer 17320d1a05d9SConrad Meyer /* 17330d1a05d9SConrad Meyer * BDXDE and BWD models reset MSI-X registers on device reset. 17340d1a05d9SConrad Meyer * Save/restore their contents manually. 17350d1a05d9SConrad Meyer */ 1736f7157235SConrad Meyer if (ioat_model_resets_msix(ioat)) { 1737f7157235SConrad Meyer ioat_log_message(1, "device resets MSI-X registers; saving\n"); 17380d1a05d9SConrad Meyer pci_save_state(ioat->device); 1739f7157235SConrad Meyer } 17400d1a05d9SConrad Meyer 1741e974f91cSConrad Meyer ioat_reset(ioat); 1742ee5642bbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u hardware reset", __func__, 1743ee5642bbSConrad Meyer ioat->chan_idx); 1744e974f91cSConrad Meyer 1745e974f91cSConrad Meyer /* Wait at most 20 ms */ 1746e974f91cSConrad Meyer for (timeout = 0; ioat_reset_pending(ioat) && timeout < 20; timeout++) 1747e974f91cSConrad Meyer DELAY(1000); 17485f77bd3eSConrad Meyer if (timeout == 20) { 17495f77bd3eSConrad Meyer error = ETIMEDOUT; 17505f77bd3eSConrad Meyer goto out; 17515f77bd3eSConrad Meyer } 1752e974f91cSConrad Meyer 1753f7157235SConrad Meyer if (ioat_model_resets_msix(ioat)) { 1754f7157235SConrad Meyer ioat_log_message(1, "device resets registers; restored\n"); 17550d1a05d9SConrad Meyer pci_restore_state(ioat->device); 1756f7157235SConrad Meyer } 17574253ea50SConrad Meyer 1758cea5b880SConrad Meyer /* Reset attempts to return the hardware to "halted." */ 1759cea5b880SConrad Meyer status = ioat_get_chansts(ioat); 1760cea5b880SConrad Meyer if (is_ioat_active(status) || is_ioat_idle(status)) { 1761cea5b880SConrad Meyer /* So this really shouldn't happen... */ 1762cea5b880SConrad Meyer ioat_log_message(0, "Device is active after a reset?\n"); 1763cea5b880SConrad Meyer ioat_write_chanctrl(ioat, IOAT_CHANCTRL_RUN); 17645f77bd3eSConrad Meyer error = 0; 17655f77bd3eSConrad Meyer goto out; 1766e974f91cSConrad Meyer } 1767e974f91cSConrad Meyer 1768cea5b880SConrad Meyer chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET); 17695f77bd3eSConrad Meyer if (chanerr != 0) { 1770faefad9cSConrad Meyer mtx_lock(&ioat->cleanup_lock); 1771faefad9cSConrad Meyer ioat_halted_debug(ioat, chanerr); 1772faefad9cSConrad Meyer mtx_unlock(&ioat->cleanup_lock); 17735f77bd3eSConrad Meyer error = EIO; 17745f77bd3eSConrad Meyer goto out; 17755f77bd3eSConrad Meyer } 1776cea5b880SConrad Meyer 1777cea5b880SConrad Meyer /* 1778cea5b880SConrad Meyer * Bring device back online after reset. Writing CHAINADDR brings the 1779cea5b880SConrad Meyer * device back to active. 1780cea5b880SConrad Meyer * 1781cea5b880SConrad Meyer * The internal ring counter resets to zero, so we have to start over 1782cea5b880SConrad Meyer * at zero as well. 1783cea5b880SConrad Meyer */ 17842f03a95fSAlexander Motin ioat->tail = ioat->head = 0; 1785348efb14SAlexander Motin *ioat->comp_update = ioat->last_seen = 1786348efb14SAlexander Motin RING_PHYS_ADDR(ioat, ioat->tail - 1); 1787cea5b880SConrad Meyer 1788cea5b880SConrad Meyer ioat_write_chanctrl(ioat, IOAT_CHANCTRL_RUN); 1789cea5b880SConrad Meyer ioat_write_chancmp(ioat, ioat->comp_update_bus_addr); 17908e269d99SConrad Meyer ioat_write_chainaddr(ioat, RING_PHYS_ADDR(ioat, 0)); 17915f77bd3eSConrad Meyer error = 0; 1792ee5642bbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u configured channel", __func__, 1793ee5642bbSConrad Meyer ioat->chan_idx); 17945f77bd3eSConrad Meyer 17955f77bd3eSConrad Meyer out: 17961bbc06b8SConrad Meyer /* Enqueues a null operation and ensures it completes. */ 1797ee5642bbSConrad Meyer if (error == 0) { 17981bbc06b8SConrad Meyer error = ioat_start_channel(ioat); 1799ee5642bbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u started channel", __func__, 1800ee5642bbSConrad Meyer ioat->chan_idx); 1801ee5642bbSConrad Meyer } 18021bbc06b8SConrad Meyer 1803fe8712f8SConrad Meyer /* 1804fe8712f8SConrad Meyer * Resume completions now that ring state is consistent. 1805fe8712f8SConrad Meyer */ 1806fe8712f8SConrad Meyer mtx_lock(&ioat->cleanup_lock); 1807fe8712f8SConrad Meyer ioat->resetting_cleanup = FALSE; 1808fe8712f8SConrad Meyer mtx_unlock(&ioat->cleanup_lock); 180993f7f84aSConrad Meyer 1810fe8712f8SConrad Meyer /* Unblock submission of new work */ 18112f03a95fSAlexander Motin mtx_lock(&ioat->submit_lock); 1812fe8712f8SConrad Meyer ioat->quiescing = FALSE; 1813fe8712f8SConrad Meyer wakeup(&ioat->quiescing); 1814fe8712f8SConrad Meyer 1815fe8712f8SConrad Meyer ioat->resetting = FALSE; 1816fe8712f8SConrad Meyer wakeup(&ioat->resetting); 18171bbc06b8SConrad Meyer 1818ee5642bbSConrad Meyer CTR2(KTR_IOAT, "%s channel=%u reset done", __func__, ioat->chan_idx); 18192f03a95fSAlexander Motin mtx_unlock(&ioat->submit_lock); 1820fe8712f8SConrad Meyer 18215f77bd3eSConrad Meyer return (error); 1822cea5b880SConrad Meyer } 1823cea5b880SConrad Meyer 1824f7157235SConrad Meyer static int 1825faefad9cSConrad Meyer sysctl_handle_chansts(SYSCTL_HANDLER_ARGS) 1826faefad9cSConrad Meyer { 1827faefad9cSConrad Meyer struct ioat_softc *ioat; 1828faefad9cSConrad Meyer struct sbuf sb; 1829faefad9cSConrad Meyer uint64_t status; 1830faefad9cSConrad Meyer int error; 1831faefad9cSConrad Meyer 1832faefad9cSConrad Meyer ioat = arg1; 1833faefad9cSConrad Meyer 1834faefad9cSConrad Meyer status = ioat_get_chansts(ioat) & IOAT_CHANSTS_STATUS; 1835faefad9cSConrad Meyer 1836faefad9cSConrad Meyer sbuf_new_for_sysctl(&sb, NULL, 256, req); 1837faefad9cSConrad Meyer switch (status) { 1838faefad9cSConrad Meyer case IOAT_CHANSTS_ACTIVE: 1839faefad9cSConrad Meyer sbuf_printf(&sb, "ACTIVE"); 1840faefad9cSConrad Meyer break; 1841faefad9cSConrad Meyer case IOAT_CHANSTS_IDLE: 1842faefad9cSConrad Meyer sbuf_printf(&sb, "IDLE"); 1843faefad9cSConrad Meyer break; 1844faefad9cSConrad Meyer case IOAT_CHANSTS_SUSPENDED: 1845faefad9cSConrad Meyer sbuf_printf(&sb, "SUSPENDED"); 1846faefad9cSConrad Meyer break; 1847faefad9cSConrad Meyer case IOAT_CHANSTS_HALTED: 1848faefad9cSConrad Meyer sbuf_printf(&sb, "HALTED"); 1849faefad9cSConrad Meyer break; 1850faefad9cSConrad Meyer case IOAT_CHANSTS_ARMED: 1851faefad9cSConrad Meyer sbuf_printf(&sb, "ARMED"); 1852faefad9cSConrad Meyer break; 1853faefad9cSConrad Meyer default: 1854faefad9cSConrad Meyer sbuf_printf(&sb, "UNKNOWN"); 1855faefad9cSConrad Meyer break; 1856faefad9cSConrad Meyer } 1857faefad9cSConrad Meyer error = sbuf_finish(&sb); 1858faefad9cSConrad Meyer sbuf_delete(&sb); 1859faefad9cSConrad Meyer 1860faefad9cSConrad Meyer if (error != 0 || req->newptr == NULL) 1861faefad9cSConrad Meyer return (error); 1862faefad9cSConrad Meyer return (EINVAL); 1863faefad9cSConrad Meyer } 1864faefad9cSConrad Meyer 1865faefad9cSConrad Meyer static int 186601fbbc88SConrad Meyer sysctl_handle_dpi(SYSCTL_HANDLER_ARGS) 186701fbbc88SConrad Meyer { 186801fbbc88SConrad Meyer struct ioat_softc *ioat; 186901fbbc88SConrad Meyer struct sbuf sb; 187001fbbc88SConrad Meyer #define PRECISION "1" 187101fbbc88SConrad Meyer const uintmax_t factor = 10; 187201fbbc88SConrad Meyer uintmax_t rate; 187301fbbc88SConrad Meyer int error; 187401fbbc88SConrad Meyer 187501fbbc88SConrad Meyer ioat = arg1; 187601fbbc88SConrad Meyer sbuf_new_for_sysctl(&sb, NULL, 16, req); 187701fbbc88SConrad Meyer 187801fbbc88SConrad Meyer if (ioat->stats.interrupts == 0) { 187901fbbc88SConrad Meyer sbuf_printf(&sb, "NaN"); 188001fbbc88SConrad Meyer goto out; 188101fbbc88SConrad Meyer } 188201fbbc88SConrad Meyer rate = ioat->stats.descriptors_processed * factor / 188301fbbc88SConrad Meyer ioat->stats.interrupts; 188401fbbc88SConrad Meyer sbuf_printf(&sb, "%ju.%." PRECISION "ju", rate / factor, 188501fbbc88SConrad Meyer rate % factor); 188601fbbc88SConrad Meyer #undef PRECISION 188701fbbc88SConrad Meyer out: 188801fbbc88SConrad Meyer error = sbuf_finish(&sb); 188901fbbc88SConrad Meyer sbuf_delete(&sb); 189001fbbc88SConrad Meyer if (error != 0 || req->newptr == NULL) 189101fbbc88SConrad Meyer return (error); 189201fbbc88SConrad Meyer return (EINVAL); 189301fbbc88SConrad Meyer } 189401fbbc88SConrad Meyer 189501fbbc88SConrad Meyer static int 1896f7157235SConrad Meyer sysctl_handle_reset(SYSCTL_HANDLER_ARGS) 1897f7157235SConrad Meyer { 1898f7157235SConrad Meyer struct ioat_softc *ioat; 1899f7157235SConrad Meyer int error, arg; 1900f7157235SConrad Meyer 1901f7157235SConrad Meyer ioat = arg1; 1902f7157235SConrad Meyer 1903f7157235SConrad Meyer arg = 0; 1904f7157235SConrad Meyer error = SYSCTL_OUT(req, &arg, sizeof(arg)); 1905f7157235SConrad Meyer if (error != 0 || req->newptr == NULL) 1906f7157235SConrad Meyer return (error); 1907f7157235SConrad Meyer 1908f7157235SConrad Meyer error = SYSCTL_IN(req, &arg, sizeof(arg)); 1909f7157235SConrad Meyer if (error != 0) 1910f7157235SConrad Meyer return (error); 1911f7157235SConrad Meyer 1912f7157235SConrad Meyer if (arg != 0) 1913f7157235SConrad Meyer error = ioat_reset_hw(ioat); 1914f7157235SConrad Meyer 1915f7157235SConrad Meyer return (error); 1916f7157235SConrad Meyer } 1917f7157235SConrad Meyer 1918e974f91cSConrad Meyer static void 1919e974f91cSConrad Meyer dump_descriptor(void *hw_desc) 1920e974f91cSConrad Meyer { 1921e974f91cSConrad Meyer int i, j; 1922e974f91cSConrad Meyer 1923e974f91cSConrad Meyer for (i = 0; i < 2; i++) { 1924e974f91cSConrad Meyer for (j = 0; j < 8; j++) 1925e974f91cSConrad Meyer printf("%08x ", ((uint32_t *)hw_desc)[i * 8 + j]); 1926e974f91cSConrad Meyer printf("\n"); 1927e974f91cSConrad Meyer } 1928e974f91cSConrad Meyer } 1929e974f91cSConrad Meyer 1930e974f91cSConrad Meyer static void 1931e974f91cSConrad Meyer ioat_setup_sysctl(device_t device) 1932e974f91cSConrad Meyer { 193301fbbc88SConrad Meyer struct sysctl_oid_list *par, *statpar, *state, *hammer; 1934f7157235SConrad Meyer struct sysctl_ctx_list *ctx; 193501fbbc88SConrad Meyer struct sysctl_oid *tree, *tmp; 1936e974f91cSConrad Meyer struct ioat_softc *ioat; 1937e974f91cSConrad Meyer 1938e974f91cSConrad Meyer ioat = DEVICE2SOFTC(device); 1939f7157235SConrad Meyer ctx = device_get_sysctl_ctx(device); 1940f7157235SConrad Meyer tree = device_get_sysctl_tree(device); 1941f7157235SConrad Meyer par = SYSCTL_CHILDREN(tree); 1942e974f91cSConrad Meyer 194365e4f8adSConrad Meyer SYSCTL_ADD_INT(ctx, par, OID_AUTO, "version", CTLFLAG_RD, 194465e4f8adSConrad Meyer &ioat->version, 0, "HW version (0xMM form)"); 194565e4f8adSConrad Meyer SYSCTL_ADD_UINT(ctx, par, OID_AUTO, "max_xfer_size", CTLFLAG_RD, 194665e4f8adSConrad Meyer &ioat->max_xfer_size, 0, "HW maximum transfer size"); 19475ca9fc2aSConrad Meyer SYSCTL_ADD_INT(ctx, par, OID_AUTO, "intrdelay_supported", CTLFLAG_RD, 19485ca9fc2aSConrad Meyer &ioat->intrdelay_supported, 0, "Is INTRDELAY supported"); 19495ca9fc2aSConrad Meyer SYSCTL_ADD_U16(ctx, par, OID_AUTO, "intrdelay_max", CTLFLAG_RD, 19505ca9fc2aSConrad Meyer &ioat->intrdelay_max, 0, 19515ca9fc2aSConrad Meyer "Maximum configurable INTRDELAY on this channel (microseconds)"); 195265e4f8adSConrad Meyer 19537029da5cSPawel Biernacki tmp = SYSCTL_ADD_NODE(ctx, par, OID_AUTO, "state", 19547029da5cSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "IOAT channel internal state"); 195501fbbc88SConrad Meyer state = SYSCTL_CHILDREN(tmp); 195601fbbc88SConrad Meyer 195701fbbc88SConrad Meyer SYSCTL_ADD_UINT(ctx, state, OID_AUTO, "ring_size_order", CTLFLAG_RD, 1958bf8553eaSConrad Meyer &ioat->ring_size_order, 0, "SW descriptor ring size order"); 195901fbbc88SConrad Meyer SYSCTL_ADD_UINT(ctx, state, OID_AUTO, "head", CTLFLAG_RD, &ioat->head, 196001fbbc88SConrad Meyer 0, "SW descriptor head pointer index"); 196101fbbc88SConrad Meyer SYSCTL_ADD_UINT(ctx, state, OID_AUTO, "tail", CTLFLAG_RD, &ioat->tail, 196201fbbc88SConrad Meyer 0, "SW descriptor tail pointer index"); 1963f7157235SConrad Meyer 196401fbbc88SConrad Meyer SYSCTL_ADD_UQUAD(ctx, state, OID_AUTO, "last_completion", CTLFLAG_RD, 196565e4f8adSConrad Meyer ioat->comp_update, "HW addr of last completion"); 196665e4f8adSConrad Meyer 196725ad9585SConrad Meyer SYSCTL_ADD_INT(ctx, state, OID_AUTO, "is_submitter_processing", 196825ad9585SConrad Meyer CTLFLAG_RD, &ioat->is_submitter_processing, 0, 196925ad9585SConrad Meyer "submitter processing"); 197065e4f8adSConrad Meyer 197101fbbc88SConrad Meyer SYSCTL_ADD_PROC(ctx, state, OID_AUTO, "chansts", 1972b776de67SAlexander Motin CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, ioat, 0, 19737029da5cSPawel Biernacki sysctl_handle_chansts, "A", "String of the channel status"); 197401fbbc88SConrad Meyer 19755ca9fc2aSConrad Meyer SYSCTL_ADD_U16(ctx, state, OID_AUTO, "intrdelay", CTLFLAG_RD, 19765ca9fc2aSConrad Meyer &ioat->cached_intrdelay, 0, 19775ca9fc2aSConrad Meyer "Current INTRDELAY on this channel (cached, microseconds)"); 19785ca9fc2aSConrad Meyer 19797029da5cSPawel Biernacki tmp = SYSCTL_ADD_NODE(ctx, par, OID_AUTO, "hammer", 19807029da5cSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 198101fbbc88SConrad Meyer "Big hammers (mostly for testing)"); 198201fbbc88SConrad Meyer hammer = SYSCTL_CHILDREN(tmp); 198301fbbc88SConrad Meyer 198401fbbc88SConrad Meyer SYSCTL_ADD_PROC(ctx, hammer, OID_AUTO, "force_hw_reset", 1985b776de67SAlexander Motin CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, ioat, 0, 19867029da5cSPawel Biernacki sysctl_handle_reset, "I", "Set to non-zero to reset the hardware"); 198701fbbc88SConrad Meyer 19887029da5cSPawel Biernacki tmp = SYSCTL_ADD_NODE(ctx, par, OID_AUTO, "stats", 19897029da5cSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "IOAT channel statistics"); 199001fbbc88SConrad Meyer statpar = SYSCTL_CHILDREN(tmp); 199101fbbc88SConrad Meyer 199283b82cd4SEric van Gyzen SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "interrupts", 199383b82cd4SEric van Gyzen CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.interrupts, 199401fbbc88SConrad Meyer "Number of interrupts processed on this channel"); 199583b82cd4SEric van Gyzen SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "descriptors", 199683b82cd4SEric van Gyzen CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.descriptors_processed, 199701fbbc88SConrad Meyer "Number of descriptors processed on this channel"); 199883b82cd4SEric van Gyzen SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "submitted", 199983b82cd4SEric van Gyzen CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.descriptors_submitted, 200001fbbc88SConrad Meyer "Number of descriptors submitted to this channel"); 200183b82cd4SEric van Gyzen SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "errored", 200283b82cd4SEric van Gyzen CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.descriptors_error, 200301fbbc88SConrad Meyer "Number of descriptors failed by channel errors"); 200483b82cd4SEric van Gyzen SYSCTL_ADD_U32(ctx, statpar, OID_AUTO, "halts", 200583b82cd4SEric van Gyzen CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.channel_halts, 0, 200601fbbc88SConrad Meyer "Number of times the channel has halted"); 200783b82cd4SEric van Gyzen SYSCTL_ADD_U32(ctx, statpar, OID_AUTO, "last_halt_chanerr", 200883b82cd4SEric van Gyzen CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.last_halt_chanerr, 0, 200901fbbc88SConrad Meyer "The raw CHANERR when the channel was last halted"); 201001fbbc88SConrad Meyer 201101fbbc88SConrad Meyer SYSCTL_ADD_PROC(ctx, statpar, OID_AUTO, "desc_per_interrupt", 2012b776de67SAlexander Motin CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, ioat, 0, 20137029da5cSPawel Biernacki sysctl_handle_dpi, "A", "Descriptors per interrupt"); 2014e974f91cSConrad Meyer } 2015466b3540SConrad Meyer 20162f03a95fSAlexander Motin static void 20172f03a95fSAlexander Motin ioat_get(struct ioat_softc *ioat) 2018466b3540SConrad Meyer { 2019faefad9cSConrad Meyer 20202f03a95fSAlexander Motin mtx_assert(&ioat->submit_lock, MA_OWNED); 20212f03a95fSAlexander Motin KASSERT(ioat->refcnt < UINT32_MAX, ("refcnt overflow")); 20222f03a95fSAlexander Motin 20232f03a95fSAlexander Motin ioat->refcnt++; 2024faefad9cSConrad Meyer } 2025faefad9cSConrad Meyer 20262f03a95fSAlexander Motin static void 20272f03a95fSAlexander Motin ioat_put(struct ioat_softc *ioat) 2028faefad9cSConrad Meyer { 2029faefad9cSConrad Meyer 20302f03a95fSAlexander Motin mtx_assert(&ioat->submit_lock, MA_OWNED); 20312f03a95fSAlexander Motin KASSERT(ioat->refcnt >= 1, ("refcnt error")); 2032faefad9cSConrad Meyer 20332f03a95fSAlexander Motin if (--ioat->refcnt == 0) 20342f03a95fSAlexander Motin wakeup(&ioat->refcnt); 2035466b3540SConrad Meyer } 2036466b3540SConrad Meyer 2037466b3540SConrad Meyer static void 20385f77bd3eSConrad Meyer ioat_drain_locked(struct ioat_softc *ioat) 2039466b3540SConrad Meyer { 2040466b3540SConrad Meyer 20412f03a95fSAlexander Motin mtx_assert(&ioat->submit_lock, MA_OWNED); 20422f03a95fSAlexander Motin 2043466b3540SConrad Meyer while (ioat->refcnt > 0) 20442f03a95fSAlexander Motin msleep(&ioat->refcnt, &ioat->submit_lock, 0, "ioat_drain", 0); 2045466b3540SConrad Meyer } 20460bb35debSConrad Meyer 20470bb35debSConrad Meyer #ifdef DDB 20480bb35debSConrad Meyer #define _db_show_lock(lo) LOCK_CLASS(lo)->lc_ddb_show(lo) 20490bb35debSConrad Meyer #define db_show_lock(lk) _db_show_lock(&(lk)->lock_object) 20500bb35debSConrad Meyer DB_SHOW_COMMAND(ioat, db_show_ioat) 20510bb35debSConrad Meyer { 20520bb35debSConrad Meyer struct ioat_softc *sc; 20530bb35debSConrad Meyer unsigned idx; 20540bb35debSConrad Meyer 20550bb35debSConrad Meyer if (!have_addr) 20560bb35debSConrad Meyer goto usage; 20570bb35debSConrad Meyer idx = (unsigned)addr; 205835b7a45eSConrad Meyer if (idx >= ioat_channel_index) 20590bb35debSConrad Meyer goto usage; 20600bb35debSConrad Meyer 20610bb35debSConrad Meyer sc = ioat_channel[idx]; 20620bb35debSConrad Meyer db_printf("ioat softc at %p\n", sc); 20630bb35debSConrad Meyer if (sc == NULL) 20640bb35debSConrad Meyer return; 20650bb35debSConrad Meyer 20660bb35debSConrad Meyer db_printf(" version: %d\n", sc->version); 20670bb35debSConrad Meyer db_printf(" chan_idx: %u\n", sc->chan_idx); 20680bb35debSConrad Meyer db_printf(" submit_lock: "); 20690bb35debSConrad Meyer db_show_lock(&sc->submit_lock); 20700bb35debSConrad Meyer 20710bb35debSConrad Meyer db_printf(" capabilities: %b\n", (int)sc->capabilities, 20720bb35debSConrad Meyer IOAT_DMACAP_STR); 20730bb35debSConrad Meyer db_printf(" cached_intrdelay: %u\n", sc->cached_intrdelay); 20740bb35debSConrad Meyer db_printf(" *comp_update: 0x%jx\n", (uintmax_t)*sc->comp_update); 20750bb35debSConrad Meyer 20765ac77963SConrad Meyer db_printf(" poll_timer:\n"); 20775ac77963SConrad Meyer db_printf(" c_time: %ju\n", (uintmax_t)sc->poll_timer.c_time); 20785ac77963SConrad Meyer db_printf(" c_arg: %p\n", sc->poll_timer.c_arg); 20795ac77963SConrad Meyer db_printf(" c_func: %p\n", sc->poll_timer.c_func); 20805ac77963SConrad Meyer db_printf(" c_lock: %p\n", sc->poll_timer.c_lock); 20815ac77963SConrad Meyer db_printf(" c_flags: 0x%x\n", (unsigned)sc->poll_timer.c_flags); 20825ac77963SConrad Meyer 20830bb35debSConrad Meyer db_printf(" quiescing: %d\n", (int)sc->quiescing); 20840bb35debSConrad Meyer db_printf(" destroying: %d\n", (int)sc->destroying); 208525ad9585SConrad Meyer db_printf(" is_submitter_processing: %d\n", 208625ad9585SConrad Meyer (int)sc->is_submitter_processing); 20870bb35debSConrad Meyer db_printf(" intrdelay_supported: %d\n", (int)sc->intrdelay_supported); 208893f7f84aSConrad Meyer db_printf(" resetting: %d\n", (int)sc->resetting); 20890bb35debSConrad Meyer 20900bb35debSConrad Meyer db_printf(" head: %u\n", sc->head); 20910bb35debSConrad Meyer db_printf(" tail: %u\n", sc->tail); 20920bb35debSConrad Meyer db_printf(" ring_size_order: %u\n", sc->ring_size_order); 20930bb35debSConrad Meyer db_printf(" last_seen: 0x%lx\n", sc->last_seen); 20940bb35debSConrad Meyer db_printf(" ring: %p\n", sc->ring); 20958e269d99SConrad Meyer db_printf(" descriptors: %p\n", sc->hw_desc_ring); 20968e269d99SConrad Meyer db_printf(" descriptors (phys): 0x%jx\n", 20978e269d99SConrad Meyer (uintmax_t)sc->hw_desc_bus_addr); 20980bb35debSConrad Meyer 209935b7a45eSConrad Meyer db_printf(" ring[%u] (tail):\n", sc->tail % 210035b7a45eSConrad Meyer (1 << sc->ring_size_order)); 210135b7a45eSConrad Meyer db_printf(" id: %u\n", ioat_get_ring_entry(sc, sc->tail)->id); 210235b7a45eSConrad Meyer db_printf(" addr: 0x%lx\n", 21038e269d99SConrad Meyer RING_PHYS_ADDR(sc, sc->tail)); 210435b7a45eSConrad Meyer db_printf(" next: 0x%lx\n", 21058e269d99SConrad Meyer ioat_get_descriptor(sc, sc->tail)->generic.next); 210635b7a45eSConrad Meyer 210735b7a45eSConrad Meyer db_printf(" ring[%u] (head - 1):\n", (sc->head - 1) % 210835b7a45eSConrad Meyer (1 << sc->ring_size_order)); 210935b7a45eSConrad Meyer db_printf(" id: %u\n", ioat_get_ring_entry(sc, sc->head - 1)->id); 211035b7a45eSConrad Meyer db_printf(" addr: 0x%lx\n", 21118e269d99SConrad Meyer RING_PHYS_ADDR(sc, sc->head - 1)); 211235b7a45eSConrad Meyer db_printf(" next: 0x%lx\n", 21138e269d99SConrad Meyer ioat_get_descriptor(sc, sc->head - 1)->generic.next); 211435b7a45eSConrad Meyer 211535b7a45eSConrad Meyer db_printf(" ring[%u] (head):\n", (sc->head) % 211635b7a45eSConrad Meyer (1 << sc->ring_size_order)); 211735b7a45eSConrad Meyer db_printf(" id: %u\n", ioat_get_ring_entry(sc, sc->head)->id); 211835b7a45eSConrad Meyer db_printf(" addr: 0x%lx\n", 21198e269d99SConrad Meyer RING_PHYS_ADDR(sc, sc->head)); 212035b7a45eSConrad Meyer db_printf(" next: 0x%lx\n", 21218e269d99SConrad Meyer ioat_get_descriptor(sc, sc->head)->generic.next); 212235b7a45eSConrad Meyer 212335b7a45eSConrad Meyer for (idx = 0; idx < (1 << sc->ring_size_order); idx++) 212435b7a45eSConrad Meyer if ((*sc->comp_update & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_MASK) 21258e269d99SConrad Meyer == RING_PHYS_ADDR(sc, idx)) 212635b7a45eSConrad Meyer db_printf(" ring[%u] == hardware tail\n", idx); 212735b7a45eSConrad Meyer 21280bb35debSConrad Meyer db_printf(" cleanup_lock: "); 21290bb35debSConrad Meyer db_show_lock(&sc->cleanup_lock); 21300bb35debSConrad Meyer 21310bb35debSConrad Meyer db_printf(" refcnt: %u\n", sc->refcnt); 21320bb35debSConrad Meyer db_printf(" stats:\n"); 21330bb35debSConrad Meyer db_printf(" interrupts: %lu\n", sc->stats.interrupts); 21340bb35debSConrad Meyer db_printf(" descriptors_processed: %lu\n", sc->stats.descriptors_processed); 21350bb35debSConrad Meyer db_printf(" descriptors_error: %lu\n", sc->stats.descriptors_error); 21360bb35debSConrad Meyer db_printf(" descriptors_submitted: %lu\n", sc->stats.descriptors_submitted); 21370bb35debSConrad Meyer 21380bb35debSConrad Meyer db_printf(" channel_halts: %u\n", sc->stats.channel_halts); 21390bb35debSConrad Meyer db_printf(" last_halt_chanerr: %u\n", sc->stats.last_halt_chanerr); 21400bb35debSConrad Meyer 21410bb35debSConrad Meyer if (db_pager_quit) 21420bb35debSConrad Meyer return; 21430bb35debSConrad Meyer 21440bb35debSConrad Meyer db_printf(" hw status:\n"); 21450bb35debSConrad Meyer db_printf(" status: 0x%lx\n", ioat_get_chansts(sc)); 21460bb35debSConrad Meyer db_printf(" chanctrl: 0x%x\n", 21470bb35debSConrad Meyer (unsigned)ioat_read_2(sc, IOAT_CHANCTRL_OFFSET)); 21480bb35debSConrad Meyer db_printf(" chancmd: 0x%x\n", 21490bb35debSConrad Meyer (unsigned)ioat_read_1(sc, IOAT_CHANCMD_OFFSET)); 21500bb35debSConrad Meyer db_printf(" dmacount: 0x%x\n", 21510bb35debSConrad Meyer (unsigned)ioat_read_2(sc, IOAT_DMACOUNT_OFFSET)); 21520bb35debSConrad Meyer db_printf(" chainaddr: 0x%lx\n", 21530bb35debSConrad Meyer ioat_read_double_4(sc, IOAT_CHAINADDR_OFFSET_LOW)); 21540bb35debSConrad Meyer db_printf(" chancmp: 0x%lx\n", 21550bb35debSConrad Meyer ioat_read_double_4(sc, IOAT_CHANCMP_OFFSET_LOW)); 21560bb35debSConrad Meyer db_printf(" chanerr: %b\n", 21570bb35debSConrad Meyer (int)ioat_read_4(sc, IOAT_CHANERR_OFFSET), IOAT_CHANERR_STR); 21580bb35debSConrad Meyer return; 21590bb35debSConrad Meyer usage: 21600bb35debSConrad Meyer db_printf("usage: show ioat <0-%u>\n", ioat_channel_index); 21610bb35debSConrad Meyer return; 21620bb35debSConrad Meyer } 21630bb35debSConrad Meyer #endif /* DDB */ 2164