2 * Copyright (C) 2012 Intel Corporation
4 * Copyright (C) 2018 Alexander Motin <mav@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
37 #include <sys/domainset.h>
39 #include <sys/ioccom.h>
40 #include <sys/kernel.h>
43 #include <sys/malloc.h>
44 #include <sys/module.h>
45 #include <sys/mutex.h>
49 #include <sys/sysctl.h>
50 #include <sys/taskqueue.h>
52 #include <dev/pci/pcireg.h>
53 #include <dev/pci/pcivar.h>
54 #include <machine/bus.h>
55 #include <machine/resource.h>
56 #include <machine/stdarg.h>
64 #include "ioat_internal.h"
66 #ifndef BUS_SPACE_MAXADDR_40BIT
67 #define BUS_SPACE_MAXADDR_40BIT MIN(BUS_SPACE_MAXADDR, 0xFFFFFFFFFFULL)
69 #ifndef BUS_SPACE_MAXADDR_46BIT
70 #define BUS_SPACE_MAXADDR_46BIT MIN(BUS_SPACE_MAXADDR, 0x3FFFFFFFFFFFULL)
73 static int ioat_probe(device_t device);
74 static int ioat_attach(device_t device);
75 static int ioat_detach(device_t device);
76 static int ioat_setup_intr(struct ioat_softc *ioat);
77 static int ioat_teardown_intr(struct ioat_softc *ioat);
78 static int ioat3_attach(device_t device);
79 static int ioat_start_channel(struct ioat_softc *ioat);
80 static int ioat_map_pci_bar(struct ioat_softc *ioat);
81 static void ioat_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg,
83 static void ioat_interrupt_handler(void *arg);
84 static boolean_t ioat_model_resets_msix(struct ioat_softc *ioat);
85 static int chanerr_to_errno(uint32_t);
86 static void ioat_process_events(struct ioat_softc *ioat, boolean_t intr);
87 static inline uint32_t ioat_get_active(struct ioat_softc *ioat);
88 static inline uint32_t ioat_get_ring_space(struct ioat_softc *ioat);
89 static void ioat_free_ring(struct ioat_softc *, uint32_t size,
90 struct ioat_descriptor *);
91 static int ioat_reserve_space(struct ioat_softc *, uint32_t, int mflags);
92 static union ioat_hw_descriptor *ioat_get_descriptor(struct ioat_softc *,
94 static struct ioat_descriptor *ioat_get_ring_entry(struct ioat_softc *,
96 static void ioat_halted_debug(struct ioat_softc *, uint32_t);
97 static void ioat_poll_timer_callback(void *arg);
98 static void dump_descriptor(void *hw_desc);
99 static void ioat_submit_single(struct ioat_softc *ioat);
100 static void ioat_comp_update_map(void *arg, bus_dma_segment_t *seg, int nseg,
102 static int ioat_reset_hw(struct ioat_softc *ioat);
103 static void ioat_reset_hw_task(void *, int);
104 static void ioat_setup_sysctl(device_t device);
105 static int sysctl_handle_reset(SYSCTL_HANDLER_ARGS);
106 static void ioat_get(struct ioat_softc *);
107 static void ioat_put(struct ioat_softc *);
108 static void ioat_drain_locked(struct ioat_softc *);
110 #define ioat_log_message(v, ...) do { \
111 if ((v) <= g_ioat_debug_level) { \
112 device_printf(ioat->device, __VA_ARGS__); \
116 MALLOC_DEFINE(M_IOAT, "ioat", "ioat driver memory allocations");
117 SYSCTL_NODE(_hw, OID_AUTO, ioat, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
120 static int g_force_legacy_interrupts;
121 SYSCTL_INT(_hw_ioat, OID_AUTO, force_legacy_interrupts, CTLFLAG_RDTUN,
122 &g_force_legacy_interrupts, 0, "Set to non-zero to force MSI-X disabled");
124 int g_ioat_debug_level = 0;
125 SYSCTL_INT(_hw_ioat, OID_AUTO, debug_level, CTLFLAG_RWTUN, &g_ioat_debug_level,
126 0, "Set log level (0-3) for ioat(4). Higher is more verbose.");
128 unsigned g_ioat_ring_order = 13;
129 SYSCTL_UINT(_hw_ioat, OID_AUTO, ring_order, CTLFLAG_RDTUN, &g_ioat_ring_order,
130 0, "Set IOAT ring order. (1 << this) == ring size.");
133 * OS <-> Driver interface structures
135 static device_method_t ioat_pci_methods[] = {
136 /* Device interface */
137 DEVMETHOD(device_probe, ioat_probe),
138 DEVMETHOD(device_attach, ioat_attach),
139 DEVMETHOD(device_detach, ioat_detach),
143 static driver_t ioat_pci_driver = {
146 sizeof(struct ioat_softc),
149 static devclass_t ioat_devclass;
150 DRIVER_MODULE(ioat, pci, ioat_pci_driver, ioat_devclass, 0, 0);
151 MODULE_VERSION(ioat, 1);
154 * Private data structures
156 static struct ioat_softc *ioat_channel[IOAT_MAX_CHANNELS];
157 static unsigned ioat_channel_index = 0;
158 SYSCTL_UINT(_hw_ioat, OID_AUTO, channels, CTLFLAG_RD, &ioat_channel_index, 0,
159 "Number of IOAT channels attached");
160 static struct mtx ioat_list_mtx;
161 MTX_SYSINIT(ioat_list_mtx, &ioat_list_mtx, "ioat list mtx", MTX_DEF);
168 { 0x34308086, "TBG IOAT Ch0" },
169 { 0x34318086, "TBG IOAT Ch1" },
170 { 0x34328086, "TBG IOAT Ch2" },
171 { 0x34338086, "TBG IOAT Ch3" },
172 { 0x34298086, "TBG IOAT Ch4" },
173 { 0x342a8086, "TBG IOAT Ch5" },
174 { 0x342b8086, "TBG IOAT Ch6" },
175 { 0x342c8086, "TBG IOAT Ch7" },
177 { 0x37108086, "JSF IOAT Ch0" },
178 { 0x37118086, "JSF IOAT Ch1" },
179 { 0x37128086, "JSF IOAT Ch2" },
180 { 0x37138086, "JSF IOAT Ch3" },
181 { 0x37148086, "JSF IOAT Ch4" },
182 { 0x37158086, "JSF IOAT Ch5" },
183 { 0x37168086, "JSF IOAT Ch6" },
184 { 0x37178086, "JSF IOAT Ch7" },
185 { 0x37188086, "JSF IOAT Ch0 (RAID)" },
186 { 0x37198086, "JSF IOAT Ch1 (RAID)" },
188 { 0x3c208086, "SNB IOAT Ch0" },
189 { 0x3c218086, "SNB IOAT Ch1" },
190 { 0x3c228086, "SNB IOAT Ch2" },
191 { 0x3c238086, "SNB IOAT Ch3" },
192 { 0x3c248086, "SNB IOAT Ch4" },
193 { 0x3c258086, "SNB IOAT Ch5" },
194 { 0x3c268086, "SNB IOAT Ch6" },
195 { 0x3c278086, "SNB IOAT Ch7" },
196 { 0x3c2e8086, "SNB IOAT Ch0 (RAID)" },
197 { 0x3c2f8086, "SNB IOAT Ch1 (RAID)" },
199 { 0x0e208086, "IVB IOAT Ch0" },
200 { 0x0e218086, "IVB IOAT Ch1" },
201 { 0x0e228086, "IVB IOAT Ch2" },
202 { 0x0e238086, "IVB IOAT Ch3" },
203 { 0x0e248086, "IVB IOAT Ch4" },
204 { 0x0e258086, "IVB IOAT Ch5" },
205 { 0x0e268086, "IVB IOAT Ch6" },
206 { 0x0e278086, "IVB IOAT Ch7" },
207 { 0x0e2e8086, "IVB IOAT Ch0 (RAID)" },
208 { 0x0e2f8086, "IVB IOAT Ch1 (RAID)" },
210 { 0x2f208086, "HSW IOAT Ch0" },
211 { 0x2f218086, "HSW IOAT Ch1" },
212 { 0x2f228086, "HSW IOAT Ch2" },
213 { 0x2f238086, "HSW IOAT Ch3" },
214 { 0x2f248086, "HSW IOAT Ch4" },
215 { 0x2f258086, "HSW IOAT Ch5" },
216 { 0x2f268086, "HSW IOAT Ch6" },
217 { 0x2f278086, "HSW IOAT Ch7" },
218 { 0x2f2e8086, "HSW IOAT Ch0 (RAID)" },
219 { 0x2f2f8086, "HSW IOAT Ch1 (RAID)" },
221 { 0x0c508086, "BWD IOAT Ch0" },
222 { 0x0c518086, "BWD IOAT Ch1" },
223 { 0x0c528086, "BWD IOAT Ch2" },
224 { 0x0c538086, "BWD IOAT Ch3" },
226 { 0x6f508086, "BDXDE IOAT Ch0" },
227 { 0x6f518086, "BDXDE IOAT Ch1" },
228 { 0x6f528086, "BDXDE IOAT Ch2" },
229 { 0x6f538086, "BDXDE IOAT Ch3" },
231 { 0x6f208086, "BDX IOAT Ch0" },
232 { 0x6f218086, "BDX IOAT Ch1" },
233 { 0x6f228086, "BDX IOAT Ch2" },
234 { 0x6f238086, "BDX IOAT Ch3" },
235 { 0x6f248086, "BDX IOAT Ch4" },
236 { 0x6f258086, "BDX IOAT Ch5" },
237 { 0x6f268086, "BDX IOAT Ch6" },
238 { 0x6f278086, "BDX IOAT Ch7" },
239 { 0x6f2e8086, "BDX IOAT Ch0 (RAID)" },
240 { 0x6f2f8086, "BDX IOAT Ch1 (RAID)" },
242 { 0x20218086, "SKX IOAT" },
245 MODULE_PNP_INFO("W32:vendor/device;D:#", pci, ioat, pci_ids,
249 * OS <-> Driver linkage functions
252 ioat_probe(device_t device)
257 type = pci_get_devid(device);
258 for (ep = pci_ids; ep < &pci_ids[nitems(pci_ids)]; ep++) {
259 if (ep->type == type) {
260 device_set_desc(device, ep->desc);
268 ioat_attach(device_t device)
270 struct ioat_softc *ioat;
273 ioat = DEVICE2SOFTC(device);
274 ioat->device = device;
275 if (bus_get_domain(device, &ioat->domain) != 0)
277 ioat->cpu = CPU_FFS(&cpuset_domain[ioat->domain]) - 1;
279 ioat->cpu = CPU_FIRST();
281 error = ioat_map_pci_bar(ioat);
285 ioat->version = ioat_read_cbver(ioat);
286 if (ioat->version < IOAT_VER_3_0) {
291 error = ioat3_attach(device);
295 error = pci_enable_busmaster(device);
299 error = ioat_setup_intr(ioat);
303 error = ioat_reset_hw(ioat);
307 ioat_process_events(ioat, FALSE);
308 ioat_setup_sysctl(device);
310 mtx_lock(&ioat_list_mtx);
311 for (i = 0; i < IOAT_MAX_CHANNELS; i++) {
312 if (ioat_channel[i] == NULL)
315 if (i >= IOAT_MAX_CHANNELS) {
316 mtx_unlock(&ioat_list_mtx);
317 device_printf(device, "Too many I/OAT devices in system\n");
322 ioat_channel[i] = ioat;
323 if (i >= ioat_channel_index)
324 ioat_channel_index = i + 1;
325 mtx_unlock(&ioat_list_mtx);
336 ioat_bus_dmamap_destroy(struct ioat_softc *ioat, const char *func,
337 bus_dma_tag_t dmat, bus_dmamap_t map)
341 error = bus_dmamap_destroy(dmat, map);
344 "%s: bus_dmamap_destroy failed %d\n", func, error);
351 ioat_detach(device_t device)
353 struct ioat_softc *ioat;
356 ioat = DEVICE2SOFTC(device);
358 mtx_lock(&ioat_list_mtx);
359 ioat_channel[ioat->chan_idx] = NULL;
360 while (ioat_channel_index > 0 &&
361 ioat_channel[ioat_channel_index - 1] == NULL)
362 ioat_channel_index--;
363 mtx_unlock(&ioat_list_mtx);
366 taskqueue_drain(taskqueue_thread, &ioat->reset_task);
368 mtx_lock(&ioat->submit_lock);
369 ioat->quiescing = TRUE;
370 ioat->destroying = TRUE;
371 wakeup(&ioat->quiescing);
372 wakeup(&ioat->resetting);
374 ioat_drain_locked(ioat);
375 mtx_unlock(&ioat->submit_lock);
376 mtx_lock(&ioat->cleanup_lock);
377 while (ioat_get_active(ioat) > 0)
378 msleep(&ioat->tail, &ioat->cleanup_lock, 0, "ioat_drain", 1);
379 mtx_unlock(&ioat->cleanup_lock);
381 ioat_teardown_intr(ioat);
382 callout_drain(&ioat->poll_timer);
384 pci_disable_busmaster(device);
386 if (ioat->pci_resource != NULL)
387 bus_release_resource(device, SYS_RES_MEMORY,
388 ioat->pci_resource_id, ioat->pci_resource);
390 if (ioat->data_tag != NULL) {
391 for (i = 0; i < 1 << ioat->ring_size_order; i++) {
392 error = ioat_bus_dmamap_destroy(ioat, __func__,
393 ioat->data_tag, ioat->ring[i].src_dmamap);
397 for (i = 0; i < 1 << ioat->ring_size_order; i++) {
398 error = ioat_bus_dmamap_destroy(ioat, __func__,
399 ioat->data_tag, ioat->ring[i].dst_dmamap);
404 for (i = 0; i < 1 << ioat->ring_size_order; i++) {
405 error = ioat_bus_dmamap_destroy(ioat, __func__,
406 ioat->data_tag, ioat->ring[i].src2_dmamap);
410 for (i = 0; i < 1 << ioat->ring_size_order; i++) {
411 error = ioat_bus_dmamap_destroy(ioat, __func__,
412 ioat->data_tag, ioat->ring[i].dst2_dmamap);
417 bus_dma_tag_destroy(ioat->data_tag);
420 if (ioat->ring != NULL)
421 ioat_free_ring(ioat, 1 << ioat->ring_size_order, ioat->ring);
423 if (ioat->comp_update != NULL) {
424 bus_dmamap_unload(ioat->comp_update_tag, ioat->comp_update_map);
425 bus_dmamem_free(ioat->comp_update_tag, ioat->comp_update,
426 ioat->comp_update_map);
427 bus_dma_tag_destroy(ioat->comp_update_tag);
430 if (ioat->hw_desc_ring != NULL) {
431 bus_dmamap_unload(ioat->hw_desc_tag, ioat->hw_desc_map);
432 bus_dmamem_free(ioat->hw_desc_tag, ioat->hw_desc_ring,
434 bus_dma_tag_destroy(ioat->hw_desc_tag);
441 ioat_teardown_intr(struct ioat_softc *ioat)
444 if (ioat->tag != NULL)
445 bus_teardown_intr(ioat->device, ioat->res, ioat->tag);
447 if (ioat->res != NULL)
448 bus_release_resource(ioat->device, SYS_RES_IRQ,
449 rman_get_rid(ioat->res), ioat->res);
451 pci_release_msi(ioat->device);
456 ioat_start_channel(struct ioat_softc *ioat)
458 struct ioat_dma_hw_descriptor *hw_desc;
459 struct ioat_descriptor *desc;
460 struct bus_dmadesc *dmadesc;
465 ioat_acquire(&ioat->dmaengine);
467 /* Submit 'NULL' operation manually to avoid quiescing flag */
468 desc = ioat_get_ring_entry(ioat, ioat->head);
469 hw_desc = &ioat_get_descriptor(ioat, ioat->head)->dma;
470 dmadesc = &desc->bus_dmadesc;
472 dmadesc->callback_fn = NULL;
473 dmadesc->callback_arg = NULL;
475 hw_desc->u.control_raw = 0;
476 hw_desc->u.control_generic.op = IOAT_OP_COPY;
477 hw_desc->u.control_generic.completion_update = 1;
479 hw_desc->src_addr = 0;
480 hw_desc->dest_addr = 0;
481 hw_desc->u.control.null = 1;
483 ioat_submit_single(ioat);
484 ioat_release(&ioat->dmaengine);
486 for (i = 0; i < 100; i++) {
488 status = ioat_get_chansts(ioat);
489 if (is_ioat_idle(status))
493 chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET);
494 ioat_log_message(0, "could not start channel: "
495 "status = %#jx error = %b\n", (uintmax_t)status, (int)chanerr,
501 * Initialize Hardware
504 ioat3_attach(device_t device)
506 struct ioat_softc *ioat;
507 struct ioat_descriptor *ring;
508 struct ioat_dma_hw_descriptor *dma_hw_desc;
512 int i, num_descriptors;
517 ioat = DEVICE2SOFTC(device);
518 ioat->capabilities = ioat_read_dmacapability(ioat);
520 ioat_log_message(0, "Capabilities: %b\n", (int)ioat->capabilities,
523 xfercap = ioat_read_xfercap(ioat);
524 ioat->max_xfer_size = 1 << xfercap;
526 ioat->intrdelay_supported = (ioat_read_2(ioat, IOAT_INTRDELAY_OFFSET) &
527 IOAT_INTRDELAY_SUPPORTED) != 0;
528 if (ioat->intrdelay_supported)
529 ioat->intrdelay_max = IOAT_INTRDELAY_US_MASK;
531 /* TODO: need to check DCA here if we ever do XOR/PQ */
533 mtx_init(&ioat->submit_lock, "ioat_submit", NULL, MTX_DEF);
534 mtx_init(&ioat->cleanup_lock, "ioat_cleanup", NULL, MTX_DEF);
535 callout_init(&ioat->poll_timer, 1);
536 TASK_INIT(&ioat->reset_task, 0, ioat_reset_hw_task, ioat);
538 /* Establish lock order for Witness */
539 mtx_lock(&ioat->cleanup_lock);
540 mtx_lock(&ioat->submit_lock);
541 mtx_unlock(&ioat->submit_lock);
542 mtx_unlock(&ioat->cleanup_lock);
544 ioat->is_submitter_processing = FALSE;
546 if (ioat->version >= IOAT_VER_3_3)
547 lowaddr = BUS_SPACE_MAXADDR_48BIT;
548 else if (ioat->version >= IOAT_VER_3_2)
549 lowaddr = BUS_SPACE_MAXADDR_46BIT;
551 lowaddr = BUS_SPACE_MAXADDR_40BIT;
553 error = bus_dma_tag_create(bus_get_dma_tag(ioat->device),
554 sizeof(uint64_t), 0x0, lowaddr, BUS_SPACE_MAXADDR, NULL, NULL,
555 sizeof(uint64_t), 1, sizeof(uint64_t), 0, NULL, NULL,
556 &ioat->comp_update_tag);
560 error = bus_dmamem_alloc(ioat->comp_update_tag,
561 (void **)&ioat->comp_update, BUS_DMA_ZERO | BUS_DMA_WAITOK,
562 &ioat->comp_update_map);
566 error = bus_dmamap_load(ioat->comp_update_tag, ioat->comp_update_map,
567 ioat->comp_update, sizeof(uint64_t), ioat_comp_update_map, ioat,
572 ioat->ring_size_order = g_ioat_ring_order;
573 num_descriptors = 1 << ioat->ring_size_order;
574 ringsz = sizeof(struct ioat_dma_hw_descriptor) * num_descriptors;
576 error = bus_dma_tag_create(bus_get_dma_tag(ioat->device),
577 2 * 1024 * 1024, 0x0, lowaddr, BUS_SPACE_MAXADDR, NULL, NULL,
578 ringsz, 1, ringsz, 0, NULL, NULL, &ioat->hw_desc_tag);
582 error = bus_dmamem_alloc(ioat->hw_desc_tag, &hw_desc,
583 BUS_DMA_ZERO | BUS_DMA_WAITOK, &ioat->hw_desc_map);
587 error = bus_dmamap_load(ioat->hw_desc_tag, ioat->hw_desc_map, hw_desc,
588 ringsz, ioat_dmamap_cb, &ioat->hw_desc_bus_addr, BUS_DMA_NOWAIT);
592 ioat->hw_desc_ring = hw_desc;
594 error = bus_dma_tag_create(bus_get_dma_tag(ioat->device),
595 1, 0, lowaddr, BUS_SPACE_MAXADDR, NULL, NULL,
596 ioat->max_xfer_size, 1, ioat->max_xfer_size, 0, NULL, NULL,
600 ioat->ring = malloc_domainset(num_descriptors * sizeof(*ring), M_IOAT,
601 DOMAINSET_PREF(ioat->domain), M_ZERO | M_WAITOK);
604 for (i = 0; i < num_descriptors; i++) {
605 memset(&ring[i].bus_dmadesc, 0, sizeof(ring[i].bus_dmadesc));
607 error = bus_dmamap_create(ioat->data_tag, 0,
608 &ring[i].src_dmamap);
611 "%s: bus_dmamap_create failed %d\n", __func__,
615 error = bus_dmamap_create(ioat->data_tag, 0,
616 &ring[i].dst_dmamap);
619 "%s: bus_dmamap_create failed %d\n", __func__,
623 error = bus_dmamap_create(ioat->data_tag, 0,
624 &ring[i].src2_dmamap);
627 "%s: bus_dmamap_create failed %d\n", __func__,
631 error = bus_dmamap_create(ioat->data_tag, 0,
632 &ring[i].dst2_dmamap);
635 "%s: bus_dmamap_create failed %d\n", __func__,
641 for (i = 0; i < num_descriptors; i++) {
642 dma_hw_desc = &ioat->hw_desc_ring[i].dma;
643 dma_hw_desc->next = RING_PHYS_ADDR(ioat, i + 1);
646 ioat->tail = ioat->head = 0;
647 *ioat->comp_update = ioat->last_seen =
648 RING_PHYS_ADDR(ioat, ioat->tail - 1);
653 ioat_map_pci_bar(struct ioat_softc *ioat)
656 ioat->pci_resource_id = PCIR_BAR(0);
657 ioat->pci_resource = bus_alloc_resource_any(ioat->device,
658 SYS_RES_MEMORY, &ioat->pci_resource_id, RF_ACTIVE);
660 if (ioat->pci_resource == NULL) {
661 ioat_log_message(0, "unable to allocate pci resource\n");
665 ioat->pci_bus_tag = rman_get_bustag(ioat->pci_resource);
666 ioat->pci_bus_handle = rman_get_bushandle(ioat->pci_resource);
671 ioat_comp_update_map(void *arg, bus_dma_segment_t *seg, int nseg, int error)
673 struct ioat_softc *ioat = arg;
675 KASSERT(error == 0, ("%s: error:%d", __func__, error));
676 ioat->comp_update_bus_addr = seg[0].ds_addr;
680 ioat_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
684 KASSERT(error == 0, ("%s: error:%d", __func__, error));
686 *baddr = segs->ds_addr;
690 * Interrupt setup and handlers
693 ioat_setup_intr(struct ioat_softc *ioat)
695 uint32_t num_vectors;
698 boolean_t force_legacy_interrupts;
701 force_legacy_interrupts = FALSE;
703 if (!g_force_legacy_interrupts && pci_msix_count(ioat->device) >= 1) {
705 pci_alloc_msix(ioat->device, &num_vectors);
706 if (num_vectors == 1)
712 ioat->res = bus_alloc_resource_any(ioat->device, SYS_RES_IRQ,
713 &ioat->rid, RF_ACTIVE);
716 ioat->res = bus_alloc_resource_any(ioat->device, SYS_RES_IRQ,
717 &ioat->rid, RF_SHAREABLE | RF_ACTIVE);
719 if (ioat->res == NULL) {
720 ioat_log_message(0, "bus_alloc_resource failed\n");
725 error = bus_setup_intr(ioat->device, ioat->res, INTR_MPSAFE |
726 INTR_TYPE_MISC, NULL, ioat_interrupt_handler, ioat, &ioat->tag);
728 ioat_log_message(0, "bus_setup_intr failed\n");
732 ioat_write_intrctrl(ioat, IOAT_INTRCTRL_MASTER_INT_EN);
737 ioat_model_resets_msix(struct ioat_softc *ioat)
741 pciid = pci_get_devid(ioat->device);
760 ioat_interrupt_handler(void *arg)
762 struct ioat_softc *ioat = arg;
764 ioat->stats.interrupts++;
765 ioat_process_events(ioat, TRUE);
769 chanerr_to_errno(uint32_t chanerr)
774 if ((chanerr & (IOAT_CHANERR_XSADDERR | IOAT_CHANERR_XDADDERR)) != 0)
776 if ((chanerr & (IOAT_CHANERR_RDERR | IOAT_CHANERR_WDERR)) != 0)
778 /* This one is probably our fault: */
779 if ((chanerr & IOAT_CHANERR_NDADDERR) != 0)
785 ioat_process_events(struct ioat_softc *ioat, boolean_t intr)
787 struct ioat_descriptor *desc;
788 struct bus_dmadesc *dmadesc;
789 uint64_t comp_update, status;
790 uint32_t completed, chanerr;
794 mtx_lock(&ioat->cleanup_lock);
796 if (!mtx_trylock(&ioat->cleanup_lock))
801 * Don't run while the hardware is being reset. Reset is responsible
802 * for blocking new work and draining & completing existing work, so
803 * there is nothing to do until new work is queued after reset anyway.
805 if (ioat->resetting_cleanup) {
806 mtx_unlock(&ioat->cleanup_lock);
811 comp_update = *ioat->comp_update;
812 status = comp_update & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_MASK;
814 if (status < ioat->hw_desc_bus_addr ||
815 status >= ioat->hw_desc_bus_addr + (1 << ioat->ring_size_order) *
816 sizeof(struct ioat_generic_hw_descriptor))
817 panic("Bogus completion address %jx (channel %u)",
818 (uintmax_t)status, ioat->chan_idx);
820 if (status == ioat->last_seen) {
822 * If we landed in process_events and nothing has been
823 * completed, check for a timeout due to channel halt.
827 CTR4(KTR_IOAT, "%s channel=%u hw_status=0x%lx last_seen=0x%lx",
828 __func__, ioat->chan_idx, comp_update, ioat->last_seen);
830 while (RING_PHYS_ADDR(ioat, ioat->tail - 1) != status) {
831 desc = ioat_get_ring_entry(ioat, ioat->tail);
832 dmadesc = &desc->bus_dmadesc;
833 CTR5(KTR_IOAT, "channel=%u completing desc idx %u (%p) ok cb %p(%p)",
834 ioat->chan_idx, ioat->tail, dmadesc, dmadesc->callback_fn,
835 dmadesc->callback_arg);
837 bus_dmamap_unload(ioat->data_tag, desc->src_dmamap);
838 bus_dmamap_unload(ioat->data_tag, desc->dst_dmamap);
839 bus_dmamap_unload(ioat->data_tag, desc->src2_dmamap);
840 bus_dmamap_unload(ioat->data_tag, desc->dst2_dmamap);
842 if (dmadesc->callback_fn != NULL)
843 dmadesc->callback_fn(dmadesc->callback_arg, 0);
848 CTR5(KTR_IOAT, "%s channel=%u head=%u tail=%u active=%u", __func__,
849 ioat->chan_idx, ioat->head, ioat->tail, ioat_get_active(ioat));
851 if (completed != 0) {
852 ioat->last_seen = RING_PHYS_ADDR(ioat, ioat->tail - 1);
853 ioat->stats.descriptors_processed += completed;
858 ioat_write_chanctrl(ioat, IOAT_CHANCTRL_RUN);
859 mtx_unlock(&ioat->cleanup_lock);
862 * The device doesn't seem to reliably push suspend/halt statuses to
863 * the channel completion memory address, so poll the device register
864 * here. For performance reasons skip it on interrupts, do it only
865 * on much more rare polling events.
868 comp_update = ioat_get_chansts(ioat) & IOAT_CHANSTS_STATUS;
869 if (!is_ioat_halted(comp_update) && !is_ioat_suspended(comp_update))
872 ioat->stats.channel_halts++;
875 * Fatal programming error on this DMA channel. Flush any outstanding
876 * work with error status and restart the engine.
878 mtx_lock(&ioat->submit_lock);
879 ioat->quiescing = TRUE;
880 mtx_unlock(&ioat->submit_lock);
883 * This is safe to do here because the submit queue is quiesced. We
884 * know that we will drain all outstanding events, so ioat_reset_hw
885 * can't deadlock. It is necessary to protect other ioat_process_event
886 * threads from racing ioat_reset_hw, reading an indeterminate hw
887 * state, and attempting to continue issuing completions.
889 mtx_lock(&ioat->cleanup_lock);
890 ioat->resetting_cleanup = TRUE;
892 chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET);
893 if (1 <= g_ioat_debug_level)
894 ioat_halted_debug(ioat, chanerr);
895 ioat->stats.last_halt_chanerr = chanerr;
897 while (ioat_get_active(ioat) > 0) {
898 desc = ioat_get_ring_entry(ioat, ioat->tail);
899 dmadesc = &desc->bus_dmadesc;
900 CTR5(KTR_IOAT, "channel=%u completing desc idx %u (%p) err cb %p(%p)",
901 ioat->chan_idx, ioat->tail, dmadesc, dmadesc->callback_fn,
902 dmadesc->callback_arg);
904 if (dmadesc->callback_fn != NULL)
905 dmadesc->callback_fn(dmadesc->callback_arg,
906 chanerr_to_errno(chanerr));
909 ioat->stats.descriptors_processed++;
910 ioat->stats.descriptors_error++;
912 CTR5(KTR_IOAT, "%s channel=%u head=%u tail=%u active=%u", __func__,
913 ioat->chan_idx, ioat->head, ioat->tail, ioat_get_active(ioat));
915 /* Clear error status */
916 ioat_write_4(ioat, IOAT_CHANERR_OFFSET, chanerr);
918 mtx_unlock(&ioat->cleanup_lock);
920 ioat_log_message(0, "Resetting channel to recover from error\n");
921 error = taskqueue_enqueue(taskqueue_thread, &ioat->reset_task);
923 ("%s: taskqueue_enqueue failed: %d", __func__, error));
927 ioat_reset_hw_task(void *ctx, int pending __unused)
929 struct ioat_softc *ioat;
933 ioat_log_message(1, "%s: Resetting channel\n", __func__);
935 error = ioat_reset_hw(ioat);
936 KASSERT(error == 0, ("%s: reset failed: %d", __func__, error));
944 ioat_get_nchannels(void)
947 return (ioat_channel_index);
951 ioat_get_dmaengine(uint32_t index, int flags)
953 struct ioat_softc *ioat;
955 KASSERT((flags & ~(M_NOWAIT | M_WAITOK)) == 0,
956 ("invalid flags: 0x%08x", flags));
957 KASSERT((flags & (M_NOWAIT | M_WAITOK)) != (M_NOWAIT | M_WAITOK),
958 ("invalid wait | nowait"));
960 mtx_lock(&ioat_list_mtx);
961 if (index >= ioat_channel_index ||
962 (ioat = ioat_channel[index]) == NULL) {
963 mtx_unlock(&ioat_list_mtx);
966 mtx_lock(&ioat->submit_lock);
967 mtx_unlock(&ioat_list_mtx);
969 if (ioat->destroying) {
970 mtx_unlock(&ioat->submit_lock);
975 if (ioat->quiescing) {
976 if ((flags & M_NOWAIT) != 0) {
978 mtx_unlock(&ioat->submit_lock);
982 while (ioat->quiescing && !ioat->destroying)
983 msleep(&ioat->quiescing, &ioat->submit_lock, 0, "getdma", 0);
985 if (ioat->destroying) {
987 mtx_unlock(&ioat->submit_lock);
991 mtx_unlock(&ioat->submit_lock);
992 return (&ioat->dmaengine);
996 ioat_put_dmaengine(bus_dmaengine_t dmaengine)
998 struct ioat_softc *ioat;
1000 ioat = to_ioat_softc(dmaengine);
1001 mtx_lock(&ioat->submit_lock);
1003 mtx_unlock(&ioat->submit_lock);
1007 ioat_get_hwversion(bus_dmaengine_t dmaengine)
1009 struct ioat_softc *ioat;
1011 ioat = to_ioat_softc(dmaengine);
1012 return (ioat->version);
1016 ioat_get_max_io_size(bus_dmaengine_t dmaengine)
1018 struct ioat_softc *ioat;
1020 ioat = to_ioat_softc(dmaengine);
1021 return (ioat->max_xfer_size);
1025 ioat_get_capabilities(bus_dmaengine_t dmaengine)
1027 struct ioat_softc *ioat;
1029 ioat = to_ioat_softc(dmaengine);
1030 return (ioat->capabilities);
1034 ioat_get_domain(bus_dmaengine_t dmaengine, int *domain)
1036 struct ioat_softc *ioat;
1038 ioat = to_ioat_softc(dmaengine);
1039 return (bus_get_domain(ioat->device, domain));
1043 ioat_set_interrupt_coalesce(bus_dmaengine_t dmaengine, uint16_t delay)
1045 struct ioat_softc *ioat;
1047 ioat = to_ioat_softc(dmaengine);
1048 if (!ioat->intrdelay_supported)
1050 if (delay > ioat->intrdelay_max)
1053 ioat_write_2(ioat, IOAT_INTRDELAY_OFFSET, delay);
1054 ioat->cached_intrdelay =
1055 ioat_read_2(ioat, IOAT_INTRDELAY_OFFSET) & IOAT_INTRDELAY_US_MASK;
1060 ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine)
1062 struct ioat_softc *ioat;
1064 ioat = to_ioat_softc(dmaengine);
1065 return (ioat->intrdelay_max);
1069 ioat_acquire(bus_dmaengine_t dmaengine)
1071 struct ioat_softc *ioat;
1073 ioat = to_ioat_softc(dmaengine);
1074 mtx_lock(&ioat->submit_lock);
1075 CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
1076 ioat->acq_head = ioat->head;
1080 ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags)
1082 struct ioat_softc *ioat;
1085 ioat = to_ioat_softc(dmaengine);
1086 ioat_acquire(dmaengine);
1088 error = ioat_reserve_space(ioat, n, mflags);
1090 ioat_release(dmaengine);
1095 ioat_release(bus_dmaengine_t dmaengine)
1097 struct ioat_softc *ioat;
1099 ioat = to_ioat_softc(dmaengine);
1100 CTR3(KTR_IOAT, "%s channel=%u dispatch1 head=%u", __func__,
1101 ioat->chan_idx, ioat->head);
1102 KFAIL_POINT_CODE(DEBUG_FP, ioat_release, /* do nothing */);
1103 CTR3(KTR_IOAT, "%s channel=%u dispatch2 head=%u", __func__,
1104 ioat->chan_idx, ioat->head);
1106 if (ioat->acq_head != ioat->head) {
1107 ioat_write_2(ioat, IOAT_DMACOUNT_OFFSET,
1108 (uint16_t)ioat->head);
1110 if (!callout_pending(&ioat->poll_timer)) {
1111 callout_reset_on(&ioat->poll_timer, 1,
1112 ioat_poll_timer_callback, ioat, ioat->cpu);
1115 mtx_unlock(&ioat->submit_lock);
1118 static struct ioat_descriptor *
1119 ioat_op_generic(struct ioat_softc *ioat, uint8_t op,
1120 uint32_t size, uint64_t src, uint64_t dst,
1121 bus_dmaengine_callback_t callback_fn, void *callback_arg,
1124 struct ioat_generic_hw_descriptor *hw_desc;
1125 struct ioat_descriptor *desc;
1126 bus_dma_segment_t seg;
1127 int mflags, nseg, error;
1129 mtx_assert(&ioat->submit_lock, MA_OWNED);
1131 KASSERT((flags & ~_DMA_GENERIC_FLAGS) == 0,
1132 ("Unrecognized flag(s): %#x", flags & ~_DMA_GENERIC_FLAGS));
1133 KASSERT(size <= ioat->max_xfer_size, ("%s: size too big (%u > %u)",
1134 __func__, (unsigned)size, ioat->max_xfer_size));
1136 if ((flags & DMA_NO_WAIT) != 0)
1141 if (ioat_reserve_space(ioat, 1, mflags) != 0)
1144 desc = ioat_get_ring_entry(ioat, ioat->head);
1145 hw_desc = &ioat_get_descriptor(ioat, ioat->head)->generic;
1147 hw_desc->u.control_raw = 0;
1148 hw_desc->u.control_generic.op = op;
1149 hw_desc->u.control_generic.completion_update = 1;
1151 if ((flags & DMA_INT_EN) != 0)
1152 hw_desc->u.control_generic.int_enable = 1;
1153 if ((flags & DMA_FENCE) != 0)
1154 hw_desc->u.control_generic.fence = 1;
1156 hw_desc->size = size;
1160 error = _bus_dmamap_load_phys(ioat->data_tag, desc->src_dmamap,
1161 src, size, 0, &seg, &nseg);
1163 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1164 " failed %d\n", __func__, error);
1167 hw_desc->src_addr = seg.ds_addr;
1172 error = _bus_dmamap_load_phys(ioat->data_tag, desc->dst_dmamap,
1173 dst, size, 0, &seg, &nseg);
1175 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1176 " failed %d\n", __func__, error);
1179 hw_desc->dest_addr = seg.ds_addr;
1182 desc->bus_dmadesc.callback_fn = callback_fn;
1183 desc->bus_dmadesc.callback_arg = callback_arg;
1187 struct bus_dmadesc *
1188 ioat_null(bus_dmaengine_t dmaengine, bus_dmaengine_callback_t callback_fn,
1189 void *callback_arg, uint32_t flags)
1191 struct ioat_dma_hw_descriptor *hw_desc;
1192 struct ioat_descriptor *desc;
1193 struct ioat_softc *ioat;
1195 ioat = to_ioat_softc(dmaengine);
1196 CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
1198 desc = ioat_op_generic(ioat, IOAT_OP_COPY, 8, 0, 0, callback_fn,
1199 callback_arg, flags);
1203 hw_desc = &ioat_get_descriptor(ioat, desc->id)->dma;
1204 hw_desc->u.control.null = 1;
1205 ioat_submit_single(ioat);
1206 return (&desc->bus_dmadesc);
1209 struct bus_dmadesc *
1210 ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst,
1211 bus_addr_t src, bus_size_t len, bus_dmaengine_callback_t callback_fn,
1212 void *callback_arg, uint32_t flags)
1214 struct ioat_dma_hw_descriptor *hw_desc;
1215 struct ioat_descriptor *desc;
1216 struct ioat_softc *ioat;
1218 ioat = to_ioat_softc(dmaengine);
1219 desc = ioat_op_generic(ioat, IOAT_OP_COPY, len, src, dst, callback_fn,
1220 callback_arg, flags);
1224 hw_desc = &ioat_get_descriptor(ioat, desc->id)->dma;
1225 if (g_ioat_debug_level >= 3)
1226 dump_descriptor(hw_desc);
1228 ioat_submit_single(ioat);
1229 CTR6(KTR_IOAT, "%s channel=%u desc=%p dest=%lx src=%lx len=%lx",
1230 __func__, ioat->chan_idx, &desc->bus_dmadesc, dst, src, len);
1231 return (&desc->bus_dmadesc);
1234 struct bus_dmadesc *
1235 ioat_copy_8k_aligned(bus_dmaengine_t dmaengine, bus_addr_t dst1,
1236 bus_addr_t dst2, bus_addr_t src1, bus_addr_t src2,
1237 bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags)
1239 struct ioat_dma_hw_descriptor *hw_desc;
1240 struct ioat_descriptor *desc;
1241 struct ioat_softc *ioat;
1242 bus_size_t src1_len, dst1_len;
1243 bus_dma_segment_t seg;
1246 ioat = to_ioat_softc(dmaengine);
1247 CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
1249 KASSERT(((src1 | src2 | dst1 | dst2) & PAGE_MASK) == 0,
1250 ("%s: addresses are not page-aligned", __func__));
1252 desc = ioat_op_generic(ioat, IOAT_OP_COPY, 2 * PAGE_SIZE, 0, 0,
1253 callback_fn, callback_arg, flags);
1257 hw_desc = &ioat_get_descriptor(ioat, desc->id)->dma;
1259 src1_len = (src2 != src1 + PAGE_SIZE) ? PAGE_SIZE : 2 * PAGE_SIZE;
1261 error = _bus_dmamap_load_phys(ioat->data_tag,
1262 desc->src_dmamap, src1, src1_len, 0, &seg, &nseg);
1264 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1265 " failed %d\n", __func__, error);
1268 hw_desc->src_addr = seg.ds_addr;
1269 if (src1_len != 2 * PAGE_SIZE) {
1270 hw_desc->u.control.src_page_break = 1;
1272 error = _bus_dmamap_load_phys(ioat->data_tag,
1273 desc->src2_dmamap, src2, PAGE_SIZE, 0, &seg, &nseg);
1275 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1276 " failed %d\n", __func__, error);
1279 hw_desc->next_src_addr = seg.ds_addr;
1282 dst1_len = (dst2 != dst1 + PAGE_SIZE) ? PAGE_SIZE : 2 * PAGE_SIZE;
1284 error = _bus_dmamap_load_phys(ioat->data_tag,
1285 desc->dst_dmamap, dst1, dst1_len, 0, &seg, &nseg);
1287 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1288 " failed %d\n", __func__, error);
1291 hw_desc->dest_addr = seg.ds_addr;
1292 if (dst1_len != 2 * PAGE_SIZE) {
1293 hw_desc->u.control.dest_page_break = 1;
1295 error = _bus_dmamap_load_phys(ioat->data_tag,
1296 desc->dst2_dmamap, dst2, PAGE_SIZE, 0, &seg, &nseg);
1298 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1299 " failed %d\n", __func__, error);
1302 hw_desc->next_dest_addr = seg.ds_addr;
1305 if (g_ioat_debug_level >= 3)
1306 dump_descriptor(hw_desc);
1308 ioat_submit_single(ioat);
1309 return (&desc->bus_dmadesc);
1312 struct bus_dmadesc *
1313 ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t dst, bus_addr_t src,
1314 bus_size_t len, uint32_t *initialseed, bus_addr_t crcptr,
1315 bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags)
1317 struct ioat_crc32_hw_descriptor *hw_desc;
1318 struct ioat_descriptor *desc;
1319 struct ioat_softc *ioat;
1322 bus_dma_segment_t seg;
1325 ioat = to_ioat_softc(dmaengine);
1326 CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
1328 KASSERT((ioat->capabilities & IOAT_DMACAP_MOVECRC) != 0,
1329 ("%s: device lacks MOVECRC capability", __func__));
1330 teststore = (flags & _DMA_CRC_TESTSTORE);
1331 KASSERT(teststore != _DMA_CRC_TESTSTORE,
1332 ("%s: TEST and STORE invalid", __func__));
1333 KASSERT(teststore != 0 || (flags & DMA_CRC_INLINE) == 0,
1334 ("%s: INLINE invalid without TEST or STORE", __func__));
1336 switch (teststore) {
1338 op = IOAT_OP_MOVECRC_STORE;
1341 op = IOAT_OP_MOVECRC_TEST;
1344 KASSERT(teststore == 0, ("bogus"));
1345 op = IOAT_OP_MOVECRC;
1349 desc = ioat_op_generic(ioat, op, len, src, dst, callback_fn,
1350 callback_arg, flags & ~_DMA_CRC_FLAGS);
1354 hw_desc = &ioat_get_descriptor(ioat, desc->id)->crc32;
1356 if ((flags & DMA_CRC_INLINE) == 0) {
1358 error = _bus_dmamap_load_phys(ioat->data_tag,
1359 desc->dst2_dmamap, crcptr, sizeof(uint32_t), 0,
1362 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1363 " failed %d\n", __func__, error);
1366 hw_desc->crc_address = seg.ds_addr;
1368 hw_desc->u.control.crc_location = 1;
1370 if (initialseed != NULL) {
1371 hw_desc->u.control.use_seed = 1;
1372 hw_desc->seed = *initialseed;
1375 if (g_ioat_debug_level >= 3)
1376 dump_descriptor(hw_desc);
1378 ioat_submit_single(ioat);
1379 return (&desc->bus_dmadesc);
1382 struct bus_dmadesc *
1383 ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src, bus_size_t len,
1384 uint32_t *initialseed, bus_addr_t crcptr,
1385 bus_dmaengine_callback_t callback_fn, void *callback_arg, uint32_t flags)
1387 struct ioat_crc32_hw_descriptor *hw_desc;
1388 struct ioat_descriptor *desc;
1389 struct ioat_softc *ioat;
1392 bus_dma_segment_t seg;
1395 ioat = to_ioat_softc(dmaengine);
1396 CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
1398 KASSERT((ioat->capabilities & IOAT_DMACAP_CRC) != 0,
1399 ("%s: device lacks CRC capability", __func__));
1400 teststore = (flags & _DMA_CRC_TESTSTORE);
1401 KASSERT(teststore != _DMA_CRC_TESTSTORE,
1402 ("%s: TEST and STORE invalid", __func__));
1403 KASSERT(teststore != 0 || (flags & DMA_CRC_INLINE) == 0,
1404 ("%s: INLINE invalid without TEST or STORE", __func__));
1406 switch (teststore) {
1408 op = IOAT_OP_CRC_STORE;
1411 op = IOAT_OP_CRC_TEST;
1414 KASSERT(teststore == 0, ("bogus"));
1419 desc = ioat_op_generic(ioat, op, len, src, 0, callback_fn,
1420 callback_arg, flags & ~_DMA_CRC_FLAGS);
1424 hw_desc = &ioat_get_descriptor(ioat, desc->id)->crc32;
1426 if ((flags & DMA_CRC_INLINE) == 0) {
1428 error = _bus_dmamap_load_phys(ioat->data_tag,
1429 desc->dst2_dmamap, crcptr, sizeof(uint32_t), 0,
1432 ioat_log_message(0, "%s: _bus_dmamap_load_phys"
1433 " failed %d\n", __func__, error);
1436 hw_desc->crc_address = seg.ds_addr;
1438 hw_desc->u.control.crc_location = 1;
1440 if (initialseed != NULL) {
1441 hw_desc->u.control.use_seed = 1;
1442 hw_desc->seed = *initialseed;
1445 if (g_ioat_debug_level >= 3)
1446 dump_descriptor(hw_desc);
1448 ioat_submit_single(ioat);
1449 return (&desc->bus_dmadesc);
1452 struct bus_dmadesc *
1453 ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t dst, uint64_t fillpattern,
1454 bus_size_t len, bus_dmaengine_callback_t callback_fn, void *callback_arg,
1457 struct ioat_fill_hw_descriptor *hw_desc;
1458 struct ioat_descriptor *desc;
1459 struct ioat_softc *ioat;
1461 ioat = to_ioat_softc(dmaengine);
1462 CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
1464 KASSERT((ioat->capabilities & IOAT_DMACAP_BFILL) != 0,
1465 ("%s: device lacks BFILL capability", __func__));
1467 desc = ioat_op_generic(ioat, IOAT_OP_FILL, len, 0, dst,
1468 callback_fn, callback_arg, flags);
1472 hw_desc = &ioat_get_descriptor(ioat, desc->id)->fill;
1473 hw_desc->src_data = fillpattern;
1474 if (g_ioat_debug_level >= 3)
1475 dump_descriptor(hw_desc);
1477 ioat_submit_single(ioat);
1478 return (&desc->bus_dmadesc);
1484 static inline uint32_t
1485 ioat_get_active(struct ioat_softc *ioat)
1488 return ((ioat->head - ioat->tail) & ((1 << ioat->ring_size_order) - 1));
1491 static inline uint32_t
1492 ioat_get_ring_space(struct ioat_softc *ioat)
1495 return ((1 << ioat->ring_size_order) - ioat_get_active(ioat) - 1);
1499 * Reserves space in this IOAT descriptor ring by ensuring enough slots remain
1502 * If mflags contains M_WAITOK, blocks until enough space is available.
1504 * Returns zero on success, or an errno on error. If num_descs is beyond the
1505 * maximum ring size, returns EINVAl; if allocation would block and mflags
1506 * contains M_NOWAIT, returns EAGAIN.
1508 * Must be called with the submit_lock held; returns with the lock held. The
1509 * lock may be dropped to allocate the ring.
1511 * (The submit_lock is needed to add any entries to the ring, so callers are
1512 * assured enough room is available.)
1515 ioat_reserve_space(struct ioat_softc *ioat, uint32_t num_descs, int mflags)
1520 mtx_assert(&ioat->submit_lock, MA_OWNED);
1524 if (num_descs < 1 || num_descs >= (1 << ioat->ring_size_order)) {
1530 if (ioat->quiescing) {
1535 if (ioat_get_ring_space(ioat) >= num_descs)
1538 CTR3(KTR_IOAT, "%s channel=%u starved (%u)", __func__,
1539 ioat->chan_idx, num_descs);
1541 if (!dug && !ioat->is_submitter_processing) {
1542 ioat->is_submitter_processing = TRUE;
1543 mtx_unlock(&ioat->submit_lock);
1545 CTR2(KTR_IOAT, "%s channel=%u attempting to process events",
1546 __func__, ioat->chan_idx);
1547 ioat_process_events(ioat, FALSE);
1549 mtx_lock(&ioat->submit_lock);
1551 KASSERT(ioat->is_submitter_processing == TRUE,
1552 ("is_submitter_processing"));
1553 ioat->is_submitter_processing = FALSE;
1554 wakeup(&ioat->tail);
1558 if ((mflags & M_WAITOK) == 0) {
1562 CTR2(KTR_IOAT, "%s channel=%u blocking on completions",
1563 __func__, ioat->chan_idx);
1564 msleep(&ioat->tail, &ioat->submit_lock, 0,
1570 mtx_assert(&ioat->submit_lock, MA_OWNED);
1571 KASSERT(!ioat->quiescing || error == ENXIO,
1572 ("reserved during quiesce"));
1577 ioat_free_ring(struct ioat_softc *ioat, uint32_t size,
1578 struct ioat_descriptor *ring)
1581 free_domain(ring, M_IOAT);
1584 static struct ioat_descriptor *
1585 ioat_get_ring_entry(struct ioat_softc *ioat, uint32_t index)
1588 return (&ioat->ring[index % (1 << ioat->ring_size_order)]);
1591 static union ioat_hw_descriptor *
1592 ioat_get_descriptor(struct ioat_softc *ioat, uint32_t index)
1595 return (&ioat->hw_desc_ring[index % (1 << ioat->ring_size_order)]);
1599 ioat_halted_debug(struct ioat_softc *ioat, uint32_t chanerr)
1601 union ioat_hw_descriptor *desc;
1603 ioat_log_message(0, "Channel halted (%b)\n", (int)chanerr,
1608 mtx_assert(&ioat->cleanup_lock, MA_OWNED);
1610 desc = ioat_get_descriptor(ioat, ioat->tail + 0);
1611 dump_descriptor(desc);
1613 desc = ioat_get_descriptor(ioat, ioat->tail + 1);
1614 dump_descriptor(desc);
1618 ioat_poll_timer_callback(void *arg)
1620 struct ioat_softc *ioat;
1623 CTR1(KTR_IOAT, "%s", __func__);
1625 ioat_process_events(ioat, FALSE);
1627 mtx_lock(&ioat->submit_lock);
1628 if (ioat_get_active(ioat) > 0)
1629 callout_schedule(&ioat->poll_timer, 1);
1630 mtx_unlock(&ioat->submit_lock);
1637 ioat_submit_single(struct ioat_softc *ioat)
1640 mtx_assert(&ioat->submit_lock, MA_OWNED);
1643 CTR4(KTR_IOAT, "%s channel=%u head=%u tail=%u", __func__,
1644 ioat->chan_idx, ioat->head, ioat->tail);
1646 ioat->stats.descriptors_submitted++;
1650 ioat_reset_hw(struct ioat_softc *ioat)
1657 CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
1659 mtx_lock(&ioat->submit_lock);
1660 while (ioat->resetting && !ioat->destroying)
1661 msleep(&ioat->resetting, &ioat->submit_lock, 0, "IRH_drain", 0);
1662 if (ioat->destroying) {
1663 mtx_unlock(&ioat->submit_lock);
1666 ioat->resetting = TRUE;
1667 ioat->quiescing = TRUE;
1668 mtx_unlock(&ioat->submit_lock);
1669 mtx_lock(&ioat->cleanup_lock);
1670 while (ioat_get_active(ioat) > 0)
1671 msleep(&ioat->tail, &ioat->cleanup_lock, 0, "ioat_drain", 1);
1674 * Suspend ioat_process_events while the hardware and softc are in an
1675 * indeterminate state.
1677 ioat->resetting_cleanup = TRUE;
1678 mtx_unlock(&ioat->cleanup_lock);
1680 CTR2(KTR_IOAT, "%s channel=%u quiesced and drained", __func__,
1683 status = ioat_get_chansts(ioat);
1684 if (is_ioat_active(status) || is_ioat_idle(status))
1687 /* Wait at most 20 ms */
1688 for (timeout = 0; (is_ioat_active(status) || is_ioat_idle(status)) &&
1689 timeout < 20; timeout++) {
1691 status = ioat_get_chansts(ioat);
1693 if (timeout == 20) {
1698 KASSERT(ioat_get_active(ioat) == 0, ("active after quiesce"));
1700 chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET);
1701 ioat_write_4(ioat, IOAT_CHANERR_OFFSET, chanerr);
1703 CTR2(KTR_IOAT, "%s channel=%u hardware suspended", __func__,
1707 * IOAT v3 workaround - CHANERRMSK_INT with 3E07h to masks out errors
1708 * that can cause stability issues for IOAT v3.
1710 pci_write_config(ioat->device, IOAT_CFG_CHANERRMASK_INT_OFFSET, 0x3e07,
1712 chanerr = pci_read_config(ioat->device, IOAT_CFG_CHANERR_INT_OFFSET, 4);
1713 pci_write_config(ioat->device, IOAT_CFG_CHANERR_INT_OFFSET, chanerr, 4);
1716 * BDXDE and BWD models reset MSI-X registers on device reset.
1717 * Save/restore their contents manually.
1719 if (ioat_model_resets_msix(ioat)) {
1720 ioat_log_message(1, "device resets MSI-X registers; saving\n");
1721 pci_save_state(ioat->device);
1725 CTR2(KTR_IOAT, "%s channel=%u hardware reset", __func__,
1728 /* Wait at most 20 ms */
1729 for (timeout = 0; ioat_reset_pending(ioat) && timeout < 20; timeout++)
1731 if (timeout == 20) {
1736 if (ioat_model_resets_msix(ioat)) {
1737 ioat_log_message(1, "device resets registers; restored\n");
1738 pci_restore_state(ioat->device);
1741 /* Reset attempts to return the hardware to "halted." */
1742 status = ioat_get_chansts(ioat);
1743 if (is_ioat_active(status) || is_ioat_idle(status)) {
1744 /* So this really shouldn't happen... */
1745 ioat_log_message(0, "Device is active after a reset?\n");
1746 ioat_write_chanctrl(ioat, IOAT_CHANCTRL_RUN);
1751 chanerr = ioat_read_4(ioat, IOAT_CHANERR_OFFSET);
1753 mtx_lock(&ioat->cleanup_lock);
1754 ioat_halted_debug(ioat, chanerr);
1755 mtx_unlock(&ioat->cleanup_lock);
1761 * Bring device back online after reset. Writing CHAINADDR brings the
1762 * device back to active.
1764 * The internal ring counter resets to zero, so we have to start over
1767 ioat->tail = ioat->head = 0;
1768 *ioat->comp_update = ioat->last_seen =
1769 RING_PHYS_ADDR(ioat, ioat->tail - 1);
1771 ioat_write_chanctrl(ioat, IOAT_CHANCTRL_RUN);
1772 ioat_write_chancmp(ioat, ioat->comp_update_bus_addr);
1773 ioat_write_chainaddr(ioat, RING_PHYS_ADDR(ioat, 0));
1775 CTR2(KTR_IOAT, "%s channel=%u configured channel", __func__,
1779 /* Enqueues a null operation and ensures it completes. */
1781 error = ioat_start_channel(ioat);
1782 CTR2(KTR_IOAT, "%s channel=%u started channel", __func__,
1787 * Resume completions now that ring state is consistent.
1789 mtx_lock(&ioat->cleanup_lock);
1790 ioat->resetting_cleanup = FALSE;
1791 mtx_unlock(&ioat->cleanup_lock);
1793 /* Unblock submission of new work */
1794 mtx_lock(&ioat->submit_lock);
1795 ioat->quiescing = FALSE;
1796 wakeup(&ioat->quiescing);
1798 ioat->resetting = FALSE;
1799 wakeup(&ioat->resetting);
1801 CTR2(KTR_IOAT, "%s channel=%u reset done", __func__, ioat->chan_idx);
1802 mtx_unlock(&ioat->submit_lock);
1808 sysctl_handle_chansts(SYSCTL_HANDLER_ARGS)
1810 struct ioat_softc *ioat;
1817 status = ioat_get_chansts(ioat) & IOAT_CHANSTS_STATUS;
1819 sbuf_new_for_sysctl(&sb, NULL, 256, req);
1821 case IOAT_CHANSTS_ACTIVE:
1822 sbuf_printf(&sb, "ACTIVE");
1824 case IOAT_CHANSTS_IDLE:
1825 sbuf_printf(&sb, "IDLE");
1827 case IOAT_CHANSTS_SUSPENDED:
1828 sbuf_printf(&sb, "SUSPENDED");
1830 case IOAT_CHANSTS_HALTED:
1831 sbuf_printf(&sb, "HALTED");
1833 case IOAT_CHANSTS_ARMED:
1834 sbuf_printf(&sb, "ARMED");
1837 sbuf_printf(&sb, "UNKNOWN");
1840 error = sbuf_finish(&sb);
1843 if (error != 0 || req->newptr == NULL)
1849 sysctl_handle_dpi(SYSCTL_HANDLER_ARGS)
1851 struct ioat_softc *ioat;
1853 #define PRECISION "1"
1854 const uintmax_t factor = 10;
1859 sbuf_new_for_sysctl(&sb, NULL, 16, req);
1861 if (ioat->stats.interrupts == 0) {
1862 sbuf_printf(&sb, "NaN");
1865 rate = ioat->stats.descriptors_processed * factor /
1866 ioat->stats.interrupts;
1867 sbuf_printf(&sb, "%ju.%." PRECISION "ju", rate / factor,
1871 error = sbuf_finish(&sb);
1873 if (error != 0 || req->newptr == NULL)
1879 sysctl_handle_reset(SYSCTL_HANDLER_ARGS)
1881 struct ioat_softc *ioat;
1887 error = SYSCTL_OUT(req, &arg, sizeof(arg));
1888 if (error != 0 || req->newptr == NULL)
1891 error = SYSCTL_IN(req, &arg, sizeof(arg));
1896 error = ioat_reset_hw(ioat);
1902 dump_descriptor(void *hw_desc)
1906 for (i = 0; i < 2; i++) {
1907 for (j = 0; j < 8; j++)
1908 printf("%08x ", ((uint32_t *)hw_desc)[i * 8 + j]);
1914 ioat_setup_sysctl(device_t device)
1916 struct sysctl_oid_list *par, *statpar, *state, *hammer;
1917 struct sysctl_ctx_list *ctx;
1918 struct sysctl_oid *tree, *tmp;
1919 struct ioat_softc *ioat;
1921 ioat = DEVICE2SOFTC(device);
1922 ctx = device_get_sysctl_ctx(device);
1923 tree = device_get_sysctl_tree(device);
1924 par = SYSCTL_CHILDREN(tree);
1926 SYSCTL_ADD_INT(ctx, par, OID_AUTO, "version", CTLFLAG_RD,
1927 &ioat->version, 0, "HW version (0xMM form)");
1928 SYSCTL_ADD_UINT(ctx, par, OID_AUTO, "max_xfer_size", CTLFLAG_RD,
1929 &ioat->max_xfer_size, 0, "HW maximum transfer size");
1930 SYSCTL_ADD_INT(ctx, par, OID_AUTO, "intrdelay_supported", CTLFLAG_RD,
1931 &ioat->intrdelay_supported, 0, "Is INTRDELAY supported");
1932 SYSCTL_ADD_U16(ctx, par, OID_AUTO, "intrdelay_max", CTLFLAG_RD,
1933 &ioat->intrdelay_max, 0,
1934 "Maximum configurable INTRDELAY on this channel (microseconds)");
1936 tmp = SYSCTL_ADD_NODE(ctx, par, OID_AUTO, "state",
1937 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "IOAT channel internal state");
1938 state = SYSCTL_CHILDREN(tmp);
1940 SYSCTL_ADD_UINT(ctx, state, OID_AUTO, "ring_size_order", CTLFLAG_RD,
1941 &ioat->ring_size_order, 0, "SW descriptor ring size order");
1942 SYSCTL_ADD_UINT(ctx, state, OID_AUTO, "head", CTLFLAG_RD, &ioat->head,
1943 0, "SW descriptor head pointer index");
1944 SYSCTL_ADD_UINT(ctx, state, OID_AUTO, "tail", CTLFLAG_RD, &ioat->tail,
1945 0, "SW descriptor tail pointer index");
1947 SYSCTL_ADD_UQUAD(ctx, state, OID_AUTO, "last_completion", CTLFLAG_RD,
1948 ioat->comp_update, "HW addr of last completion");
1950 SYSCTL_ADD_INT(ctx, state, OID_AUTO, "is_submitter_processing",
1951 CTLFLAG_RD, &ioat->is_submitter_processing, 0,
1952 "submitter processing");
1954 SYSCTL_ADD_PROC(ctx, state, OID_AUTO, "chansts",
1955 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NEEDGIANT, ioat, 0,
1956 sysctl_handle_chansts, "A", "String of the channel status");
1958 SYSCTL_ADD_U16(ctx, state, OID_AUTO, "intrdelay", CTLFLAG_RD,
1959 &ioat->cached_intrdelay, 0,
1960 "Current INTRDELAY on this channel (cached, microseconds)");
1962 tmp = SYSCTL_ADD_NODE(ctx, par, OID_AUTO, "hammer",
1963 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL,
1964 "Big hammers (mostly for testing)");
1965 hammer = SYSCTL_CHILDREN(tmp);
1967 SYSCTL_ADD_PROC(ctx, hammer, OID_AUTO, "force_hw_reset",
1968 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, ioat, 0,
1969 sysctl_handle_reset, "I", "Set to non-zero to reset the hardware");
1971 tmp = SYSCTL_ADD_NODE(ctx, par, OID_AUTO, "stats",
1972 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "IOAT channel statistics");
1973 statpar = SYSCTL_CHILDREN(tmp);
1975 SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "interrupts",
1976 CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.interrupts,
1977 "Number of interrupts processed on this channel");
1978 SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "descriptors",
1979 CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.descriptors_processed,
1980 "Number of descriptors processed on this channel");
1981 SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "submitted",
1982 CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.descriptors_submitted,
1983 "Number of descriptors submitted to this channel");
1984 SYSCTL_ADD_UQUAD(ctx, statpar, OID_AUTO, "errored",
1985 CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.descriptors_error,
1986 "Number of descriptors failed by channel errors");
1987 SYSCTL_ADD_U32(ctx, statpar, OID_AUTO, "halts",
1988 CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.channel_halts, 0,
1989 "Number of times the channel has halted");
1990 SYSCTL_ADD_U32(ctx, statpar, OID_AUTO, "last_halt_chanerr",
1991 CTLFLAG_RW | CTLFLAG_STATS, &ioat->stats.last_halt_chanerr, 0,
1992 "The raw CHANERR when the channel was last halted");
1994 SYSCTL_ADD_PROC(ctx, statpar, OID_AUTO, "desc_per_interrupt",
1995 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NEEDGIANT, ioat, 0,
1996 sysctl_handle_dpi, "A", "Descriptors per interrupt");
2000 ioat_get(struct ioat_softc *ioat)
2003 mtx_assert(&ioat->submit_lock, MA_OWNED);
2004 KASSERT(ioat->refcnt < UINT32_MAX, ("refcnt overflow"));
2010 ioat_put(struct ioat_softc *ioat)
2013 mtx_assert(&ioat->submit_lock, MA_OWNED);
2014 KASSERT(ioat->refcnt >= 1, ("refcnt error"));
2016 if (--ioat->refcnt == 0)
2017 wakeup(&ioat->refcnt);
2021 ioat_drain_locked(struct ioat_softc *ioat)
2024 mtx_assert(&ioat->submit_lock, MA_OWNED);
2026 while (ioat->refcnt > 0)
2027 msleep(&ioat->refcnt, &ioat->submit_lock, 0, "ioat_drain", 0);
2031 #define _db_show_lock(lo) LOCK_CLASS(lo)->lc_ddb_show(lo)
2032 #define db_show_lock(lk) _db_show_lock(&(lk)->lock_object)
2033 DB_SHOW_COMMAND(ioat, db_show_ioat)
2035 struct ioat_softc *sc;
2040 idx = (unsigned)addr;
2041 if (idx >= ioat_channel_index)
2044 sc = ioat_channel[idx];
2045 db_printf("ioat softc at %p\n", sc);
2049 db_printf(" version: %d\n", sc->version);
2050 db_printf(" chan_idx: %u\n", sc->chan_idx);
2051 db_printf(" submit_lock: ");
2052 db_show_lock(&sc->submit_lock);
2054 db_printf(" capabilities: %b\n", (int)sc->capabilities,
2056 db_printf(" cached_intrdelay: %u\n", sc->cached_intrdelay);
2057 db_printf(" *comp_update: 0x%jx\n", (uintmax_t)*sc->comp_update);
2059 db_printf(" poll_timer:\n");
2060 db_printf(" c_time: %ju\n", (uintmax_t)sc->poll_timer.c_time);
2061 db_printf(" c_arg: %p\n", sc->poll_timer.c_arg);
2062 db_printf(" c_func: %p\n", sc->poll_timer.c_func);
2063 db_printf(" c_lock: %p\n", sc->poll_timer.c_lock);
2064 db_printf(" c_flags: 0x%x\n", (unsigned)sc->poll_timer.c_flags);
2066 db_printf(" quiescing: %d\n", (int)sc->quiescing);
2067 db_printf(" destroying: %d\n", (int)sc->destroying);
2068 db_printf(" is_submitter_processing: %d\n",
2069 (int)sc->is_submitter_processing);
2070 db_printf(" intrdelay_supported: %d\n", (int)sc->intrdelay_supported);
2071 db_printf(" resetting: %d\n", (int)sc->resetting);
2073 db_printf(" head: %u\n", sc->head);
2074 db_printf(" tail: %u\n", sc->tail);
2075 db_printf(" ring_size_order: %u\n", sc->ring_size_order);
2076 db_printf(" last_seen: 0x%lx\n", sc->last_seen);
2077 db_printf(" ring: %p\n", sc->ring);
2078 db_printf(" descriptors: %p\n", sc->hw_desc_ring);
2079 db_printf(" descriptors (phys): 0x%jx\n",
2080 (uintmax_t)sc->hw_desc_bus_addr);
2082 db_printf(" ring[%u] (tail):\n", sc->tail %
2083 (1 << sc->ring_size_order));
2084 db_printf(" id: %u\n", ioat_get_ring_entry(sc, sc->tail)->id);
2085 db_printf(" addr: 0x%lx\n",
2086 RING_PHYS_ADDR(sc, sc->tail));
2087 db_printf(" next: 0x%lx\n",
2088 ioat_get_descriptor(sc, sc->tail)->generic.next);
2090 db_printf(" ring[%u] (head - 1):\n", (sc->head - 1) %
2091 (1 << sc->ring_size_order));
2092 db_printf(" id: %u\n", ioat_get_ring_entry(sc, sc->head - 1)->id);
2093 db_printf(" addr: 0x%lx\n",
2094 RING_PHYS_ADDR(sc, sc->head - 1));
2095 db_printf(" next: 0x%lx\n",
2096 ioat_get_descriptor(sc, sc->head - 1)->generic.next);
2098 db_printf(" ring[%u] (head):\n", (sc->head) %
2099 (1 << sc->ring_size_order));
2100 db_printf(" id: %u\n", ioat_get_ring_entry(sc, sc->head)->id);
2101 db_printf(" addr: 0x%lx\n",
2102 RING_PHYS_ADDR(sc, sc->head));
2103 db_printf(" next: 0x%lx\n",
2104 ioat_get_descriptor(sc, sc->head)->generic.next);
2106 for (idx = 0; idx < (1 << sc->ring_size_order); idx++)
2107 if ((*sc->comp_update & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_MASK)
2108 == RING_PHYS_ADDR(sc, idx))
2109 db_printf(" ring[%u] == hardware tail\n", idx);
2111 db_printf(" cleanup_lock: ");
2112 db_show_lock(&sc->cleanup_lock);
2114 db_printf(" refcnt: %u\n", sc->refcnt);
2115 db_printf(" stats:\n");
2116 db_printf(" interrupts: %lu\n", sc->stats.interrupts);
2117 db_printf(" descriptors_processed: %lu\n", sc->stats.descriptors_processed);
2118 db_printf(" descriptors_error: %lu\n", sc->stats.descriptors_error);
2119 db_printf(" descriptors_submitted: %lu\n", sc->stats.descriptors_submitted);
2121 db_printf(" channel_halts: %u\n", sc->stats.channel_halts);
2122 db_printf(" last_halt_chanerr: %u\n", sc->stats.last_halt_chanerr);
2127 db_printf(" hw status:\n");
2128 db_printf(" status: 0x%lx\n", ioat_get_chansts(sc));
2129 db_printf(" chanctrl: 0x%x\n",
2130 (unsigned)ioat_read_2(sc, IOAT_CHANCTRL_OFFSET));
2131 db_printf(" chancmd: 0x%x\n",
2132 (unsigned)ioat_read_1(sc, IOAT_CHANCMD_OFFSET));
2133 db_printf(" dmacount: 0x%x\n",
2134 (unsigned)ioat_read_2(sc, IOAT_DMACOUNT_OFFSET));
2135 db_printf(" chainaddr: 0x%lx\n",
2136 ioat_read_double_4(sc, IOAT_CHAINADDR_OFFSET_LOW));
2137 db_printf(" chancmp: 0x%lx\n",
2138 ioat_read_double_4(sc, IOAT_CHANCMP_OFFSET_LOW));
2139 db_printf(" chanerr: %b\n",
2140 (int)ioat_read_4(sc, IOAT_CHANERR_OFFSET), IOAT_CHANERR_STR);
2143 db_printf("usage: show ioat <0-%u>\n", ioat_channel_index);