xref: /freebsd/sys/dev/ioat/ioat_internal.h (revision b81eee4a223460fc326de905c6d127bc985078c4)
1e974f91cSConrad Meyer /*-
2e974f91cSConrad Meyer  * Copyright (C) 2012 Intel Corporation
3e974f91cSConrad Meyer  * All rights reserved.
4e974f91cSConrad Meyer  *
5e974f91cSConrad Meyer  * Redistribution and use in source and binary forms, with or without
6e974f91cSConrad Meyer  * modification, are permitted provided that the following conditions
7e974f91cSConrad Meyer  * are met:
8e974f91cSConrad Meyer  * 1. Redistributions of source code must retain the above copyright
9e974f91cSConrad Meyer  *    notice, this list of conditions and the following disclaimer.
10e974f91cSConrad Meyer  * 2. Redistributions in binary form must reproduce the above copyright
11e974f91cSConrad Meyer  *    notice, this list of conditions and the following disclaimer in the
12e974f91cSConrad Meyer  *    documentation and/or other materials provided with the distribution.
13e974f91cSConrad Meyer  *
14e974f91cSConrad Meyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15e974f91cSConrad Meyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16e974f91cSConrad Meyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17e974f91cSConrad Meyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18e974f91cSConrad Meyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19e974f91cSConrad Meyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20e974f91cSConrad Meyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21e974f91cSConrad Meyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22e974f91cSConrad Meyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23e974f91cSConrad Meyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24e974f91cSConrad Meyer  * SUCH DAMAGE.
25e974f91cSConrad Meyer  */
26e974f91cSConrad Meyer 
27e974f91cSConrad Meyer __FBSDID("$FreeBSD$");
28e974f91cSConrad Meyer 
29e974f91cSConrad Meyer #ifndef __IOAT_INTERNAL_H__
30e974f91cSConrad Meyer #define __IOAT_INTERNAL_H__
31e974f91cSConrad Meyer 
32e974f91cSConrad Meyer #define DEVICE2SOFTC(dev) ((struct ioat_softc *) device_get_softc(dev))
33e974f91cSConrad Meyer 
34e974f91cSConrad Meyer #define	ioat_read_chancnt(ioat) \
35e974f91cSConrad Meyer 	ioat_read_1((ioat), IOAT_CHANCNT_OFFSET)
36e974f91cSConrad Meyer 
37e974f91cSConrad Meyer #define	ioat_read_xfercap(ioat) \
38*b81eee4aSConrad Meyer 	(ioat_read_1((ioat), IOAT_XFERCAP_OFFSET) & IOAT_XFERCAP_VALID_MASK)
39e974f91cSConrad Meyer 
40e974f91cSConrad Meyer #define	ioat_write_intrctrl(ioat, value) \
41e974f91cSConrad Meyer 	ioat_write_1((ioat), IOAT_INTRCTRL_OFFSET, (value))
42e974f91cSConrad Meyer 
43e974f91cSConrad Meyer #define	ioat_read_cbver(ioat) \
44e974f91cSConrad Meyer 	(ioat_read_1((ioat), IOAT_CBVER_OFFSET) & 0xFF)
45e974f91cSConrad Meyer 
46e974f91cSConrad Meyer #define	ioat_read_dmacapability(ioat) \
47e974f91cSConrad Meyer 	ioat_read_4((ioat), IOAT_DMACAPABILITY_OFFSET)
48e974f91cSConrad Meyer 
49e974f91cSConrad Meyer #define	ioat_write_chanctrl(ioat, value) \
50e974f91cSConrad Meyer 	ioat_write_2((ioat), IOAT_CHANCTRL_OFFSET, (value))
51e974f91cSConrad Meyer 
52e974f91cSConrad Meyer static __inline uint64_t
53e974f91cSConrad Meyer ioat_bus_space_read_8_lower_first(bus_space_tag_t tag,
54e974f91cSConrad Meyer     bus_space_handle_t handle, bus_size_t offset)
55e974f91cSConrad Meyer {
56e974f91cSConrad Meyer 	return (bus_space_read_4(tag, handle, offset) |
57e974f91cSConrad Meyer 	    ((uint64_t)bus_space_read_4(tag, handle, offset + 4)) << 32);
58e974f91cSConrad Meyer }
59e974f91cSConrad Meyer 
60e974f91cSConrad Meyer static __inline void
61e974f91cSConrad Meyer ioat_bus_space_write_8_lower_first(bus_space_tag_t tag,
62e974f91cSConrad Meyer     bus_space_handle_t handle, bus_size_t offset, uint64_t val)
63e974f91cSConrad Meyer {
64e974f91cSConrad Meyer 	bus_space_write_4(tag, handle, offset, val);
65e974f91cSConrad Meyer 	bus_space_write_4(tag, handle, offset + 4, val >> 32);
66e974f91cSConrad Meyer }
67e974f91cSConrad Meyer 
68f3e30f97SConrad Meyer #ifdef __i386__
69e974f91cSConrad Meyer #define ioat_bus_space_read_8 ioat_bus_space_read_8_lower_first
70e974f91cSConrad Meyer #define ioat_bus_space_write_8 ioat_bus_space_write_8_lower_first
71e974f91cSConrad Meyer #else
72e974f91cSConrad Meyer #define ioat_bus_space_read_8(tag, handle, offset) \
73e974f91cSConrad Meyer 	bus_space_read_8((tag), (handle), (offset))
74e974f91cSConrad Meyer #define ioat_bus_space_write_8(tag, handle, offset, val) \
75e974f91cSConrad Meyer 	bus_space_write_8((tag), (handle), (offset), (val))
76e974f91cSConrad Meyer #endif
77e974f91cSConrad Meyer 
78e974f91cSConrad Meyer #define ioat_read_1(ioat, offset) \
79e974f91cSConrad Meyer 	bus_space_read_1((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
80e974f91cSConrad Meyer 	    (offset))
81e974f91cSConrad Meyer 
82e974f91cSConrad Meyer #define ioat_read_2(ioat, offset) \
83e974f91cSConrad Meyer 	bus_space_read_2((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
84e974f91cSConrad Meyer 	    (offset))
85e974f91cSConrad Meyer 
86e974f91cSConrad Meyer #define ioat_read_4(ioat, offset) \
87e974f91cSConrad Meyer 	bus_space_read_4((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
88e974f91cSConrad Meyer 	    (offset))
89e974f91cSConrad Meyer 
90e974f91cSConrad Meyer #define ioat_read_8(ioat, offset) \
91e974f91cSConrad Meyer 	ioat_bus_space_read_8((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
92e974f91cSConrad Meyer 	    (offset))
93e974f91cSConrad Meyer 
94e974f91cSConrad Meyer #define ioat_read_double_4(ioat, offset) \
95e974f91cSConrad Meyer 	ioat_bus_space_read_8_lower_first((ioat)->pci_bus_tag, \
96e974f91cSConrad Meyer 	    (ioat)->pci_bus_handle, (offset))
97e974f91cSConrad Meyer 
98e974f91cSConrad Meyer #define ioat_write_1(ioat, offset, value) \
99e974f91cSConrad Meyer 	bus_space_write_1((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
100e974f91cSConrad Meyer 	    (offset), (value))
101e974f91cSConrad Meyer 
102e974f91cSConrad Meyer #define ioat_write_2(ioat, offset, value) \
103e974f91cSConrad Meyer 	bus_space_write_2((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
104e974f91cSConrad Meyer 	    (offset), (value))
105e974f91cSConrad Meyer 
106e974f91cSConrad Meyer #define ioat_write_4(ioat, offset, value) \
107e974f91cSConrad Meyer 	bus_space_write_4((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
108e974f91cSConrad Meyer 	    (offset), (value))
109e974f91cSConrad Meyer 
110e974f91cSConrad Meyer #define ioat_write_8(ioat, offset, value) \
111e974f91cSConrad Meyer 	ioat_bus_space_write_8((ioat)->pci_bus_tag, (ioat)->pci_bus_handle, \
112e974f91cSConrad Meyer 	    (offset), (value))
113e974f91cSConrad Meyer 
114e974f91cSConrad Meyer #define ioat_write_double_4(ioat, offset, value) \
115e974f91cSConrad Meyer 	ioat_bus_space_write_8_lower_first((ioat)->pci_bus_tag, \
116e974f91cSConrad Meyer 	    (ioat)->pci_bus_handle, (offset), (value))
117e974f91cSConrad Meyer 
118e974f91cSConrad Meyer MALLOC_DECLARE(M_IOAT);
119e974f91cSConrad Meyer 
120e974f91cSConrad Meyer SYSCTL_DECL(_hw_ioat);
121e974f91cSConrad Meyer 
122e974f91cSConrad Meyer void ioat_log_message(int verbosity, char *fmt, ...);
123e974f91cSConrad Meyer 
124e974f91cSConrad Meyer struct ioat_dma_hw_descriptor {
125e974f91cSConrad Meyer 	uint32_t size;
126e974f91cSConrad Meyer 	union {
127e974f91cSConrad Meyer 		uint32_t control_raw;
128e974f91cSConrad Meyer 		struct {
129e974f91cSConrad Meyer 			uint32_t int_enable:1;
130e974f91cSConrad Meyer 			uint32_t src_snoop_disable:1;
131e974f91cSConrad Meyer 			uint32_t dest_snoop_disable:1;
132e974f91cSConrad Meyer 			uint32_t completion_update:1;
133e974f91cSConrad Meyer 			uint32_t fence:1;
134e974f91cSConrad Meyer 			uint32_t null:1;
135e974f91cSConrad Meyer 			uint32_t src_page_break:1;
136e974f91cSConrad Meyer 			uint32_t dest_page_break:1;
137e974f91cSConrad Meyer 			uint32_t bundle:1;
138e974f91cSConrad Meyer 			uint32_t dest_dca:1;
139e974f91cSConrad Meyer 			uint32_t hint:1;
140e974f91cSConrad Meyer 			uint32_t reserved:13;
141e974f91cSConrad Meyer 			#define IOAT_OP_COPY 0x00
142e974f91cSConrad Meyer 			uint32_t op:8;
143e974f91cSConrad Meyer 		} control;
144e974f91cSConrad Meyer 	} u;
145e974f91cSConrad Meyer 	uint64_t src_addr;
146e974f91cSConrad Meyer 	uint64_t dest_addr;
147e974f91cSConrad Meyer 	uint64_t next;
148e974f91cSConrad Meyer 	uint64_t reserved;
149e974f91cSConrad Meyer 	uint64_t reserved2;
150e974f91cSConrad Meyer 	uint64_t user1;
151e974f91cSConrad Meyer 	uint64_t user2;
152e974f91cSConrad Meyer };
153e974f91cSConrad Meyer 
154e974f91cSConrad Meyer struct ioat_fill_hw_descriptor {
155e974f91cSConrad Meyer 	uint32_t size;
156e974f91cSConrad Meyer 	union {
157e974f91cSConrad Meyer 		uint32_t control_raw;
158e974f91cSConrad Meyer 		struct {
159e974f91cSConrad Meyer 			uint32_t int_enable:1;
160e974f91cSConrad Meyer 			uint32_t reserved:1;
161e974f91cSConrad Meyer 			uint32_t dest_snoop_disable:1;
162e974f91cSConrad Meyer 			uint32_t completion_update:1;
163e974f91cSConrad Meyer 			uint32_t fence:1;
164e974f91cSConrad Meyer 			uint32_t reserved2:2;
165e974f91cSConrad Meyer 			uint32_t dest_page_break:1;
166e974f91cSConrad Meyer 			uint32_t bundle:1;
167e974f91cSConrad Meyer 			uint32_t reserved3:15;
168e974f91cSConrad Meyer 			#define IOAT_OP_FILL 0x01
169e974f91cSConrad Meyer 			uint32_t op:8;
170e974f91cSConrad Meyer 		} control;
171e974f91cSConrad Meyer 	} u;
172e974f91cSConrad Meyer 	uint64_t src_data;
173e974f91cSConrad Meyer 	uint64_t dest_addr;
174e974f91cSConrad Meyer 	uint64_t next;
175e974f91cSConrad Meyer 	uint64_t reserved;
176e974f91cSConrad Meyer 	uint64_t next_dest_addr;
177e974f91cSConrad Meyer 	uint64_t user1;
178e974f91cSConrad Meyer 	uint64_t user2;
179e974f91cSConrad Meyer };
180e974f91cSConrad Meyer 
181e974f91cSConrad Meyer struct ioat_xor_hw_descriptor {
182e974f91cSConrad Meyer 	uint32_t size;
183e974f91cSConrad Meyer 	union {
184e974f91cSConrad Meyer 		uint32_t control_raw;
185e974f91cSConrad Meyer 		struct {
186e974f91cSConrad Meyer 			uint32_t int_enable:1;
187e974f91cSConrad Meyer 			uint32_t src_snoop_disable:1;
188e974f91cSConrad Meyer 			uint32_t dest_snoop_disable:1;
189e974f91cSConrad Meyer 			uint32_t completion_update:1;
190e974f91cSConrad Meyer 			uint32_t fence:1;
191e974f91cSConrad Meyer 			uint32_t src_count:3;
192e974f91cSConrad Meyer 			uint32_t bundle:1;
193e974f91cSConrad Meyer 			uint32_t dest_dca:1;
194e974f91cSConrad Meyer 			uint32_t hint:1;
195e974f91cSConrad Meyer 			uint32_t reserved:13;
196e974f91cSConrad Meyer 			#define IOAT_OP_XOR 0x87
197e974f91cSConrad Meyer 			#define IOAT_OP_XOR_VAL 0x88
198e974f91cSConrad Meyer 			uint32_t op:8;
199e974f91cSConrad Meyer 		} control;
200e974f91cSConrad Meyer 	} u;
201e974f91cSConrad Meyer 	uint64_t src_addr;
202e974f91cSConrad Meyer 	uint64_t dest_addr;
203e974f91cSConrad Meyer 	uint64_t next;
204e974f91cSConrad Meyer 	uint64_t src_addr2;
205e974f91cSConrad Meyer 	uint64_t src_addr3;
206e974f91cSConrad Meyer 	uint64_t src_addr4;
207e974f91cSConrad Meyer 	uint64_t src_addr5;
208e974f91cSConrad Meyer };
209e974f91cSConrad Meyer 
210e974f91cSConrad Meyer struct ioat_xor_ext_hw_descriptor {
211e974f91cSConrad Meyer 	uint64_t src_addr6;
212e974f91cSConrad Meyer 	uint64_t src_addr7;
213e974f91cSConrad Meyer 	uint64_t src_addr8;
214e974f91cSConrad Meyer 	uint64_t next;
215e974f91cSConrad Meyer 	uint64_t reserved[4];
216e974f91cSConrad Meyer };
217e974f91cSConrad Meyer 
218e974f91cSConrad Meyer struct ioat_pq_hw_descriptor {
219e974f91cSConrad Meyer 	uint32_t size;
220e974f91cSConrad Meyer 	union {
221e974f91cSConrad Meyer 		uint32_t control_raw;
222e974f91cSConrad Meyer 		struct {
223e974f91cSConrad Meyer 			uint32_t int_enable:1;
224e974f91cSConrad Meyer 			uint32_t src_snoop_disable:1;
225e974f91cSConrad Meyer 			uint32_t dest_snoop_disable:1;
226e974f91cSConrad Meyer 			uint32_t completion_update:1;
227e974f91cSConrad Meyer 			uint32_t fence:1;
228e974f91cSConrad Meyer 			uint32_t src_count:3;
229e974f91cSConrad Meyer 			uint32_t bundle:1;
230e974f91cSConrad Meyer 			uint32_t dest_dca:1;
231e974f91cSConrad Meyer 			uint32_t hint:1;
232e974f91cSConrad Meyer 			uint32_t p_disable:1;
233e974f91cSConrad Meyer 			uint32_t q_disable:1;
234e974f91cSConrad Meyer 			uint32_t reserved:11;
235e974f91cSConrad Meyer 			#define IOAT_OP_PQ 0x89
236e974f91cSConrad Meyer 			#define IOAT_OP_PQ_VAL 0x8a
237e974f91cSConrad Meyer 			uint32_t op:8;
238e974f91cSConrad Meyer 		} control;
239e974f91cSConrad Meyer 	} u;
240e974f91cSConrad Meyer 	uint64_t src_addr;
241e974f91cSConrad Meyer 	uint64_t p_addr;
242e974f91cSConrad Meyer 	uint64_t next;
243e974f91cSConrad Meyer 	uint64_t src_addr2;
244e974f91cSConrad Meyer 	uint64_t src_addr3;
245e974f91cSConrad Meyer 	uint8_t  coef[8];
246e974f91cSConrad Meyer 	uint64_t q_addr;
247e974f91cSConrad Meyer };
248e974f91cSConrad Meyer 
249e974f91cSConrad Meyer struct ioat_pq_ext_hw_descriptor {
250e974f91cSConrad Meyer 	uint64_t src_addr4;
251e974f91cSConrad Meyer 	uint64_t src_addr5;
252e974f91cSConrad Meyer 	uint64_t src_addr6;
253e974f91cSConrad Meyer 	uint64_t next;
254e974f91cSConrad Meyer 	uint64_t src_addr7;
255e974f91cSConrad Meyer 	uint64_t src_addr8;
256e974f91cSConrad Meyer 	uint64_t reserved[2];
257e974f91cSConrad Meyer };
258e974f91cSConrad Meyer 
259e974f91cSConrad Meyer struct ioat_pq_update_hw_descriptor {
260e974f91cSConrad Meyer 	uint32_t size;
261e974f91cSConrad Meyer 	union {
262e974f91cSConrad Meyer 		uint32_t control_raw;
263e974f91cSConrad Meyer 		struct {
264e974f91cSConrad Meyer 			uint32_t int_enable:1;
265e974f91cSConrad Meyer 			uint32_t src_snoop_disable:1;
266e974f91cSConrad Meyer 			uint32_t dest_snoop_disable:1;
267e974f91cSConrad Meyer 			uint32_t completion_update:1;
268e974f91cSConrad Meyer 			uint32_t fence:1;
269e974f91cSConrad Meyer 			uint32_t src_cnt:3;
270e974f91cSConrad Meyer 			uint32_t bundle:1;
271e974f91cSConrad Meyer 			uint32_t dest_dca:1;
272e974f91cSConrad Meyer 			uint32_t hint:1;
273e974f91cSConrad Meyer 			uint32_t p_disable:1;
274e974f91cSConrad Meyer 			uint32_t q_disable:1;
275e974f91cSConrad Meyer 			uint32_t reserved:3;
276e974f91cSConrad Meyer 			uint32_t coef:8;
277e974f91cSConrad Meyer 			#define IOAT_OP_PQ_UP 0x8b
278e974f91cSConrad Meyer 			uint32_t op:8;
279e974f91cSConrad Meyer 		} control;
280e974f91cSConrad Meyer 	} u;
281e974f91cSConrad Meyer 	uint64_t src_addr;
282e974f91cSConrad Meyer 	uint64_t p_addr;
283e974f91cSConrad Meyer 	uint64_t next;
284e974f91cSConrad Meyer 	uint64_t src_addr2;
285e974f91cSConrad Meyer 	uint64_t p_src;
286e974f91cSConrad Meyer 	uint64_t q_src;
287e974f91cSConrad Meyer 	uint64_t q_addr;
288e974f91cSConrad Meyer };
289e974f91cSConrad Meyer 
290e974f91cSConrad Meyer struct ioat_raw_hw_descriptor {
291e974f91cSConrad Meyer 	uint64_t field[8];
292e974f91cSConrad Meyer };
293e974f91cSConrad Meyer 
294e974f91cSConrad Meyer struct bus_dmadesc {
295e974f91cSConrad Meyer 	bus_dmaengine_callback_t callback_fn;
296e974f91cSConrad Meyer 	void			 *callback_arg;
297e974f91cSConrad Meyer };
298e974f91cSConrad Meyer 
299e974f91cSConrad Meyer struct ioat_descriptor {
300e974f91cSConrad Meyer 	struct bus_dmadesc	bus_dmadesc;
301e974f91cSConrad Meyer 	union {
302e974f91cSConrad Meyer 		struct ioat_dma_hw_descriptor		*dma;
303e974f91cSConrad Meyer 		struct ioat_fill_hw_descriptor		*fill;
304e974f91cSConrad Meyer 		struct ioat_xor_hw_descriptor		*xor;
305e974f91cSConrad Meyer 		struct ioat_xor_ext_hw_descriptor	*xor_ext;
306e974f91cSConrad Meyer 		struct ioat_pq_hw_descriptor		*pq;
307e974f91cSConrad Meyer 		struct ioat_pq_ext_hw_descriptor	*pq_ext;
308e974f91cSConrad Meyer 		struct ioat_raw_hw_descriptor		*raw;
309e974f91cSConrad Meyer 	} u;
310e974f91cSConrad Meyer 	uint32_t		id;
311e974f91cSConrad Meyer 	uint32_t		length;
312e974f91cSConrad Meyer 	enum validate_flags	*validate_result;
313e974f91cSConrad Meyer 	bus_addr_t		hw_desc_bus_addr;
314e974f91cSConrad Meyer };
315e974f91cSConrad Meyer 
316e974f91cSConrad Meyer /* One of these per allocated PCI device. */
317e974f91cSConrad Meyer struct ioat_softc {
318e974f91cSConrad Meyer 	bus_dmaengine_t		dmaengine;
319e974f91cSConrad Meyer #define	to_ioat_softc(_dmaeng)						\
320e974f91cSConrad Meyer ({									\
321e974f91cSConrad Meyer 	bus_dmaengine_t *_p = (_dmaeng);				\
322e974f91cSConrad Meyer 	(struct ioat_softc *)((char *)_p -				\
323e974f91cSConrad Meyer 	    offsetof(struct ioat_softc, dmaengine));			\
324e974f91cSConrad Meyer })
325e974f91cSConrad Meyer 
326e974f91cSConrad Meyer 	int			version;
327e974f91cSConrad Meyer 
328e974f91cSConrad Meyer 	struct mtx		submit_lock;
329e974f91cSConrad Meyer 	int			num_interrupts;
330e974f91cSConrad Meyer 	device_t		device;
331e974f91cSConrad Meyer 	bus_space_tag_t		pci_bus_tag;
332e974f91cSConrad Meyer 	bus_space_handle_t	pci_bus_handle;
333e974f91cSConrad Meyer 	int			pci_resource_id;
334e974f91cSConrad Meyer 	struct resource		*pci_resource;
335e974f91cSConrad Meyer 	uint32_t		max_xfer_size;
336e974f91cSConrad Meyer 
337e974f91cSConrad Meyer 	struct resource		*res;
338e974f91cSConrad Meyer 	int			rid;
339e974f91cSConrad Meyer 	void			*tag;
340e974f91cSConrad Meyer 
341e974f91cSConrad Meyer 	bus_dma_tag_t		hw_desc_tag;
342e974f91cSConrad Meyer 	bus_dmamap_t		hw_desc_map;
343e974f91cSConrad Meyer 
344e974f91cSConrad Meyer 	bus_dma_tag_t		comp_update_tag;
345e974f91cSConrad Meyer 	bus_dmamap_t		comp_update_map;
346e974f91cSConrad Meyer 	uint64_t		*comp_update;
347e974f91cSConrad Meyer 	bus_addr_t		comp_update_bus_addr;
348e974f91cSConrad Meyer 
349e974f91cSConrad Meyer 	struct callout		timer;
350e974f91cSConrad Meyer 
351e974f91cSConrad Meyer 	boolean_t		is_resize_pending;
352e974f91cSConrad Meyer 	boolean_t		is_completion_pending;
353e974f91cSConrad Meyer 	boolean_t		is_reset_pending;
354e974f91cSConrad Meyer 	boolean_t		is_channel_running;
355e974f91cSConrad Meyer 	boolean_t		is_waiting_for_ack;
356e974f91cSConrad Meyer 
357e974f91cSConrad Meyer 	uint32_t		xfercap_log;
358e974f91cSConrad Meyer 	uint32_t		head;
359e974f91cSConrad Meyer 	uint32_t		tail;
360e974f91cSConrad Meyer 	uint16_t		reserved;
361e974f91cSConrad Meyer 	uint32_t		ring_size_order;
362e974f91cSConrad Meyer 	bus_addr_t		last_seen;
363e974f91cSConrad Meyer 
364e974f91cSConrad Meyer 	struct ioat_descriptor	**ring;
365e974f91cSConrad Meyer 
366e974f91cSConrad Meyer 	struct mtx		cleanup_lock;
367e974f91cSConrad Meyer };
368e974f91cSConrad Meyer 
369e974f91cSConrad Meyer static inline uint64_t
370e974f91cSConrad Meyer ioat_get_chansts(struct ioat_softc *ioat)
371e974f91cSConrad Meyer {
372e974f91cSConrad Meyer 	uint64_t status;
373e974f91cSConrad Meyer 
374e974f91cSConrad Meyer 	if (ioat->version >= IOAT_VER_3_3)
375e974f91cSConrad Meyer 		status = ioat_read_8(ioat, IOAT_CHANSTS_OFFSET);
376e974f91cSConrad Meyer 	else
377e974f91cSConrad Meyer 		/* Must read lower 4 bytes before upper 4 bytes. */
378e974f91cSConrad Meyer 		status = ioat_read_double_4(ioat, IOAT_CHANSTS_OFFSET);
379e974f91cSConrad Meyer 	return (status);
380e974f91cSConrad Meyer }
381e974f91cSConrad Meyer 
382e974f91cSConrad Meyer static inline void
383e974f91cSConrad Meyer ioat_write_chancmp(struct ioat_softc *ioat, uint64_t addr)
384e974f91cSConrad Meyer {
385e974f91cSConrad Meyer 
386e974f91cSConrad Meyer 	if (ioat->version >= IOAT_VER_3_3)
387e974f91cSConrad Meyer 		ioat_write_8(ioat, IOAT_CHANCMP_OFFSET_LOW, addr);
388e974f91cSConrad Meyer 	else
389e974f91cSConrad Meyer 		ioat_write_double_4(ioat, IOAT_CHANCMP_OFFSET_LOW, addr);
390e974f91cSConrad Meyer }
391e974f91cSConrad Meyer 
392e974f91cSConrad Meyer static inline void
393e974f91cSConrad Meyer ioat_write_chainaddr(struct ioat_softc *ioat, uint64_t addr)
394e974f91cSConrad Meyer {
395e974f91cSConrad Meyer 
396e974f91cSConrad Meyer 	if (ioat->version >= IOAT_VER_3_3)
397e974f91cSConrad Meyer 		ioat_write_8(ioat, IOAT_CHAINADDR_OFFSET_LOW, addr);
398e974f91cSConrad Meyer 	else
399e974f91cSConrad Meyer 		ioat_write_double_4(ioat, IOAT_CHAINADDR_OFFSET_LOW, addr);
400e974f91cSConrad Meyer }
401e974f91cSConrad Meyer 
402e974f91cSConrad Meyer static inline boolean_t
403e974f91cSConrad Meyer is_ioat_active(uint64_t status)
404e974f91cSConrad Meyer {
405e974f91cSConrad Meyer 	return ((status & IOAT_CHANSTS_STATUS) == IOAT_CHANSTS_ACTIVE);
406e974f91cSConrad Meyer }
407e974f91cSConrad Meyer 
408e974f91cSConrad Meyer static inline boolean_t
409e974f91cSConrad Meyer is_ioat_idle(uint64_t status)
410e974f91cSConrad Meyer {
411e974f91cSConrad Meyer 	return ((status & IOAT_CHANSTS_STATUS) == IOAT_CHANSTS_IDLE);
412e974f91cSConrad Meyer }
413e974f91cSConrad Meyer 
414e974f91cSConrad Meyer static inline boolean_t
415e974f91cSConrad Meyer is_ioat_halted(uint64_t status)
416e974f91cSConrad Meyer {
417e974f91cSConrad Meyer 	return ((status & IOAT_CHANSTS_STATUS) == IOAT_CHANSTS_HALTED);
418e974f91cSConrad Meyer }
419e974f91cSConrad Meyer 
420e974f91cSConrad Meyer static inline boolean_t
421e974f91cSConrad Meyer is_ioat_suspended(uint64_t status)
422e974f91cSConrad Meyer {
423e974f91cSConrad Meyer 	return ((status & IOAT_CHANSTS_STATUS) == IOAT_CHANSTS_SUSPENDED);
424e974f91cSConrad Meyer }
425e974f91cSConrad Meyer 
426e974f91cSConrad Meyer static inline void
427e974f91cSConrad Meyer ioat_suspend(struct ioat_softc *ioat)
428e974f91cSConrad Meyer {
429e974f91cSConrad Meyer 	ioat_write_1(ioat, IOAT_CHANCMD_OFFSET, IOAT_CHANCMD_SUSPEND);
430e974f91cSConrad Meyer }
431e974f91cSConrad Meyer 
432e974f91cSConrad Meyer static inline void
433e974f91cSConrad Meyer ioat_reset(struct ioat_softc *ioat)
434e974f91cSConrad Meyer {
435e974f91cSConrad Meyer 	ioat_write_1(ioat, IOAT_CHANCMD_OFFSET, IOAT_CHANCMD_RESET);
436e974f91cSConrad Meyer }
437e974f91cSConrad Meyer 
438e974f91cSConrad Meyer static inline boolean_t
439e974f91cSConrad Meyer ioat_reset_pending(struct ioat_softc *ioat)
440e974f91cSConrad Meyer {
441e974f91cSConrad Meyer 	uint8_t cmd;
442e974f91cSConrad Meyer 
443e974f91cSConrad Meyer 	cmd = ioat_read_1(ioat, IOAT_CHANCMD_OFFSET);
444e974f91cSConrad Meyer 	return ((cmd & IOAT_CHANCMD_RESET) != 0);
445e974f91cSConrad Meyer }
446e974f91cSConrad Meyer 
447e974f91cSConrad Meyer #endif /* __IOAT_INTERNAL_H__ */
448