1171095Ssam/*-
2171095Ssam * Copyright (c) 2002-2007 Neterion, Inc.
3171095Ssam * All rights reserved.
4171095Ssam *
5171095Ssam * Redistribution and use in source and binary forms, with or without
6171095Ssam * modification, are permitted provided that the following conditions
7171095Ssam * are met:
8171095Ssam * 1. Redistributions of source code must retain the above copyright
9171095Ssam *    notice, this list of conditions and the following disclaimer.
10171095Ssam * 2. Redistributions in binary form must reproduce the above copyright
11171095Ssam *    notice, this list of conditions and the following disclaimer in the
12171095Ssam *    documentation and/or other materials provided with the distribution.
13171095Ssam *
14171095Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15171095Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16171095Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17171095Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18171095Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19171095Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20171095Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21171095Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22171095Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23171095Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24171095Ssam * SUCH DAMAGE.
25171095Ssam *
26171095Ssam * $FreeBSD$
27171095Ssam */
28171095Ssam
29171095Ssam#ifndef XGE_HAL_CHANNEL_H
30171095Ssam#define XGE_HAL_CHANNEL_H
31171095Ssam
32171095Ssam#include <dev/nxge/include/xge-os-pal.h>
33171095Ssam#include <dev/nxge/include/xge-list.h>
34171095Ssam#include <dev/nxge/include/xgehal-types.h>
35171095Ssam#include <dev/nxge/include/xgehal-stats.h>
36171095Ssam
37171095Ssam__EXTERN_BEGIN_DECLS
38171095Ssam
39171095Ssam/**
40171095Ssam * enum xge_hal_channel_type_e - Enumerated channel types.
41171095Ssam * @XGE_HAL_CHANNEL_TYPE_FIFO: fifo.
42171095Ssam * @XGE_HAL_CHANNEL_TYPE_RING: ring.
43171095Ssam * @XGE_HAL_CHANNEL_TYPE_SEND_QUEUE: Send Queue
44171095Ssam * @XGE_HAL_CHANNEL_TYPE_RECEIVE_QUEUE: Receive Queue
45171095Ssam * @XGE_HAL_CHANNEL_TYPE_COMPLETION_QUEUE: Receive queue completion queue
46171095Ssam * @XGE_HAL_CHANNEL_TYPE_UP_MESSAGE_QUEUE: Up message queue
47171095Ssam * @XGE_HAL_CHANNEL_TYPE_DOWN_MESSAGE_QUEUE: Down message queue
48171095Ssam * @XGE_HAL_CHANNEL_TYPE_MAX: Maximum number of HAL-supported
49171095Ssam * (and recognized) channel types. Currently: two.
50171095Ssam *
51171095Ssam * Enumerated channel types. Currently there are only two link-layer
52171095Ssam * channels - Xframe fifo and Xframe ring. In the future the list will grow.
53171095Ssam */
54171095Ssamtypedef enum xge_hal_channel_type_e {
55171095Ssam	XGE_HAL_CHANNEL_TYPE_FIFO,
56171095Ssam	XGE_HAL_CHANNEL_TYPE_RING,
57171095Ssam	XGE_HAL_CHANNEL_TYPE_SEND_QUEUE,
58171095Ssam	XGE_HAL_CHANNEL_TYPE_RECEIVE_QUEUE,
59171095Ssam	XGE_HAL_CHANNEL_TYPE_COMPLETION_QUEUE,
60171095Ssam	XGE_HAL_CHANNEL_TYPE_UP_MESSAGE_QUEUE,
61171095Ssam	XGE_HAL_CHANNEL_TYPE_DOWN_MESSAGE_QUEUE,
62171095Ssam	XGE_HAL_CHANNEL_TYPE_MAX
63171095Ssam} xge_hal_channel_type_e;
64171095Ssam
65171095Ssam/**
66171095Ssam * enum xge_hal_channel_flag_e - Channel flags.
67171095Ssam * @XGE_HAL_CHANNEL_FLAG_NONE: zero (nil) flag.
68171095Ssam * @XGE_HAL_CHANNEL_FLAG_USE_TX_LOCK: use lock when posting transmit
69171095Ssam * descriptor.
70171095Ssam * @XGE_HAL_CHANNEL_FLAG_FREE_RXD: to-be-defined.
71171095Ssam *
72171095Ssam * Channel opening flags. Reserved for future usage.
73171095Ssam */
74171095Ssamtypedef enum xge_hal_channel_flag_e {
75173139Srwatson	XGE_HAL_CHANNEL_FLAG_NONE       = 0x0,
76173139Srwatson	XGE_HAL_CHANNEL_FLAG_USE_TX_LOCK    = 0x1,
77173139Srwatson	XGE_HAL_CHANNEL_FLAG_FREE_RXD           = 0x2
78171095Ssam} xge_hal_channel_flag_e;
79171095Ssam
80171095Ssam/**
81171095Ssam * enum xge_hal_dtr_state_e - Descriptor (DTR) state.
82171095Ssam * @XGE_HAL_DTR_STATE_NONE: Invalid state.
83171095Ssam * @XGE_HAL_DTR_STATE_AVAIL: Descriptor is available for reservation
84171095Ssam * (via xge_hal_fifo_dtr_reserve(), xge_hal_ring_dtr_reserve(), etc.).
85171095Ssam * @XGE_HAL_DTR_STATE_POSTED: Descriptor is posted for processing by the
86171095Ssam * device.
87171095Ssam * @XGE_HAL_DTR_STATE_FREED: Descriptor is free and can be reused for
88171095Ssam * filling-in and posting later.
89171095Ssam *
90171095Ssam * Xframe/HAL descriptor states. For more on descriptor states and transitions
91171095Ssam * please refer to ch_intern{}.
92171095Ssam *
93171095Ssam * See also: xge_hal_channel_dtr_term_f{}.
94171095Ssam */
95171095Ssamtypedef enum xge_hal_dtr_state_e {
96173139Srwatson	XGE_HAL_DTR_STATE_NONE      = 0,
97173139Srwatson	XGE_HAL_DTR_STATE_AVAIL     = 1,
98173139Srwatson	XGE_HAL_DTR_STATE_POSTED    = 2,
99173139Srwatson	XGE_HAL_DTR_STATE_FREED     = 3
100171095Ssam} xge_hal_dtr_state_e;
101171095Ssam
102171095Ssam/**
103171095Ssam * enum xge_hal_channel_reopen_e - Channel open, close, or reopen option.
104171095Ssam * @XGE_HAL_CHANNEL_RESET_ONLY: Do not (de)allocate channel; used with
105171095Ssam * xge_hal_channel_open(), xge_hal_channel_close().
106171095Ssam * @XGE_HAL_CHANNEL_OC_NORMAL: Do (de)allocate channel; used with
107171095Ssam * xge_hal_channel_open(), xge_hal_channel_close().
108171095Ssam *
109171095Ssam * Enumerates options used with channel open and close operations.
110171095Ssam * The @XGE_HAL_CHANNEL_RESET_ONLY can be used when resetting the device;
111171095Ssam * in this case there is actually no need to free and then again malloc
112171095Ssam * the memory (including DMA-able memory) used for channel operation.
113171095Ssam */
114171095Ssamtypedef enum xge_hal_channel_reopen_e {
115173139Srwatson	XGE_HAL_CHANNEL_RESET_ONLY  = 1,
116173139Srwatson	XGE_HAL_CHANNEL_OC_NORMAL   = 2
117171095Ssam} xge_hal_channel_reopen_e;
118171095Ssam
119171095Ssam/**
120171095Ssam * function xge_hal_channel_callback_f - Channel callback.
121171095Ssam * @channelh: Channel "containing" 1 or more completed descriptors.
122171095Ssam * @dtrh: First completed descriptor.
123171095Ssam * @t_code: Transfer code, as per Xframe User Guide.
124171095Ssam *          Returned by HAL.
125171095Ssam * @host_control: Opaque 64bit data stored by ULD inside the Xframe
126171095Ssam *            descriptor prior to posting the latter on the channel
127171095Ssam *            via xge_hal_fifo_dtr_post() or xge_hal_ring_dtr_post().
128171095Ssam *            The @host_control is returned as is to the ULD with each
129171095Ssam *            completed descriptor.
130171095Ssam * @userdata: Opaque per-channel data specified at channel open
131171095Ssam *            time, via xge_hal_channel_open().
132171095Ssam *
133171095Ssam * Channel completion callback (type declaration). A single per-channel
134171095Ssam * callback is specified at channel open time, via
135171095Ssam * xge_hal_channel_open().
136171095Ssam * Typically gets called as part of the processing of the Interrupt
137171095Ssam * Service Routine.
138171095Ssam *
139171095Ssam * Channel callback gets called by HAL if, and only if, there is at least
140171095Ssam * one new completion on a given ring or fifo channel. Upon processing the
141171095Ssam * first @dtrh ULD is _supposed_ to continue consuming completions
142171095Ssam * using�one of the following HAL APIs:
143171095Ssam *    - xge_hal_fifo_dtr_next_completed()
144171095Ssam *      or
145171095Ssam *    - xge_hal_ring_dtr_next_completed().
146171095Ssam *
147171095Ssam * Note that failure to process new completions in a timely fashion
148171095Ssam * leads to XGE_HAL_INF_OUT_OF_DESCRIPTORS condition.
149171095Ssam *
150171095Ssam * Non-zero @t_code means failure to process (transmit or receive, depending
151171095Ssam * on the channel type) the descriptor.
152171095Ssam *
153171095Ssam * In the "transmit" case the failure could happen, for instance, when the
154171095Ssam * link is down, in which case Xframe completes the descriptor because it
155171095Ssam * is not able to send the data out.
156171095Ssam *
157171095Ssam * For details please refer to Xframe User Guide.
158171095Ssam *
159171095Ssam * See also: xge_hal_fifo_dtr_next_completed(),
160171095Ssam * xge_hal_ring_dtr_next_completed(), xge_hal_channel_dtr_term_f{}.
161171095Ssam */
162171095Ssamtypedef xge_hal_status_e (*xge_hal_channel_callback_f)
163173139Srwatson	            (xge_hal_channel_h channelh, xge_hal_dtr_h dtrh,
164173139Srwatson	             u8 t_code, void *userdata);
165171095Ssam
166171095Ssam/**
167171095Ssam * function xge_hal_channel_dtr_init_f - Initialize descriptor callback.
168171095Ssam * @channelh: Channel "containing" the @dtrh descriptor.
169171095Ssam * @dtrh: Descriptor.
170171095Ssam * @index: Index of the descriptor in the channel's set of descriptors.
171171095Ssam * @userdata: Per-channel user data (a.k.a. context) specified at
172171095Ssam * channel open time, via xge_hal_channel_open().
173171095Ssam * @reopen: See  xge_hal_channel_reopen_e{}.
174171095Ssam *
175171095Ssam * Initialize descriptor callback. Unless NULL is specified in the
176171095Ssam * xge_hal_channel_attr_t{} structure passed to xge_hal_channel_open()),
177171095Ssam * HAL invokes the callback as part of the xge_hal_channel_open()
178171095Ssam * implementation.
179171095Ssam * For the ring type of channel the ULD is expected to fill in this descriptor
180171095Ssam * with buffer(s) and control information.
181171095Ssam * For the fifo type of channel the ULD could use the callback to
182171095Ssam * pre-set DMA mappings and/or alignment buffers.
183171095Ssam *
184171095Ssam * See also: xge_hal_channel_attr_t{}, xge_hal_channel_dtr_term_f{}.
185171095Ssam */
186171095Ssamtypedef xge_hal_status_e (*xge_hal_channel_dtr_init_f)
187173139Srwatson	            (xge_hal_channel_h channelh,
188173139Srwatson	             xge_hal_dtr_h dtrh,
189173139Srwatson	             int index,
190173139Srwatson	             void *userdata,
191173139Srwatson	             xge_hal_channel_reopen_e reopen);
192171095Ssam
193171095Ssam/**
194171095Ssam * function xge_hal_channel_dtr_term_f - Terminate descriptor callback.
195171095Ssam * @channelh: Channel "containing" the @dtrh descriptor.
196171095Ssam * @dtrh: First completed descriptor.
197171095Ssam * @state: One of the xge_hal_dtr_state_e{} enumerated states.
198171095Ssam * @userdata: Per-channel user data (a.k.a. context) specified at
199171095Ssam * channel open time, via xge_hal_channel_open().
200171095Ssam * @reopen: See  xge_hal_channel_reopen_e{}.
201171095Ssam *
202171095Ssam * Terminate descriptor callback. Unless NULL is specified in the
203171095Ssam * xge_hal_channel_attr_t{} structure passed to xge_hal_channel_open()),
204171095Ssam * HAL invokes the callback as part of closing the corresponding
205171095Ssam * channel, prior to de-allocating the channel and associated data
206171095Ssam * structures (including descriptors).
207171095Ssam * ULD should utilize the callback to (for instance) unmap
208171095Ssam * and free DMA data buffers associated with the posted (state =
209171095Ssam * XGE_HAL_DTR_STATE_POSTED) descriptors,
210171095Ssam * as well as other relevant cleanup functions.
211171095Ssam *
212171095Ssam * See also: xge_hal_channel_attr_t{}, xge_hal_channel_dtr_init_f{}.
213171095Ssam */
214171095Ssamtypedef void (*xge_hal_channel_dtr_term_f) (xge_hal_channel_h channelh,
215173139Srwatson	                    xge_hal_dtr_h dtrh,
216173139Srwatson	                    xge_hal_dtr_state_e state,
217173139Srwatson	                    void *userdata,
218173139Srwatson	                    xge_hal_channel_reopen_e reopen);
219171095Ssam
220171095Ssam
221171095Ssam/**
222171095Ssam * struct xge_hal_channel_attr_t - Channel open "template".
223171095Ssam * @type: xge_hal_channel_type_e channel type.
224171095Ssam * @vp_id: Virtual path id
225171095Ssam * @post_qid: Queue ID to post descriptors. For the link layer this
226171095Ssam *            number should be in the 0..7 range.
227171095Ssam * @compl_qid: Completion queue ID. Must be set to zero for the link layer.
228171095Ssam * @callback: Channel completion callback. HAL invokes the callback when there
229171095Ssam *            are new completions on that channel. In many implementations
230171095Ssam *            the @callback executes in the hw interrupt context.
231171095Ssam * @dtr_init: Channel's descriptor-initialize callback.
232171095Ssam *            See xge_hal_channel_dtr_init_f{}.
233171095Ssam *            If not NULL, HAL invokes the callback when opening
234171095Ssam *            the channel via xge_hal_channel_open().
235171095Ssam * @dtr_term: Channel's descriptor-terminate callback. If not NULL,
236171095Ssam *          HAL invokes the callback when closing the corresponding channel.
237171095Ssam *          See also xge_hal_channel_dtr_term_f{}.
238171095Ssam * @userdata: User-defined "context" of _that_ channel. Passed back to the
239171095Ssam *            user as one of the @callback, @dtr_init, and @dtr_term arguments.
240171095Ssam * @per_dtr_space: If specified (i.e., greater than zero): extra space
241171095Ssam *              reserved by HAL per each transmit or receive (depending on the
242171095Ssam *              channel type) descriptor. Can be used to store,
243171095Ssam *              and retrieve on completion, information specific
244171095Ssam *              to the upper-layer.
245171095Ssam * @flags: xge_hal_channel_flag_e enumerated flags.
246171095Ssam *
247171095Ssam * Channel open "template". User fills the structure with channel
248171095Ssam * attributes and passes it to xge_hal_channel_open().
249171095Ssam * Usage: See ex_open{}.
250171095Ssam */
251171095Ssamtypedef struct xge_hal_channel_attr_t {
252173139Srwatson	xge_hal_channel_type_e      type;
253173139Srwatson	int             post_qid;
254173139Srwatson	int             compl_qid;
255173139Srwatson	xge_hal_channel_callback_f  callback;
256173139Srwatson	xge_hal_channel_dtr_init_f  dtr_init;
257173139Srwatson	xge_hal_channel_dtr_term_f  dtr_term;
258173139Srwatson	void                *userdata;
259173139Srwatson	int             per_dtr_space;
260173139Srwatson	xge_hal_channel_flag_e      flags;
261171095Ssam} xge_hal_channel_attr_t;
262171095Ssam
263171095Ssam/*
264171095Ssam * xge_hal_channel_t
265171095Ssam * ---------- complete/free section ---------------
266171095Ssam * @item: List item; used to maintain a list of open channels.
267171095Ssam * @callback: Channel completion callback. See
268171095Ssam * xge_hal_channel_callback_f.
269171095Ssam * @compl_index: Completion index. At any point in time points on the
270171095Ssam *               position in the channel, which will contain next
271171095Ssam *               to-be-completed descriptor.
272171095Ssam * @length: Channel length. Currently allocated number of descriptors.
273171095Ssam *          The channel length "grows" when more descriptors get allocated.
274171095Ssam *          See _hal_mempool_grow.
275171095Ssam * @free_arr: Free array. Contains completed descriptors that were freed
276171095Ssam *            (i.e., handed over back to HAL) by ULD.
277171095Ssam *            See xge_hal_fifo_dtr_free(), xge_hal_ring_dtr_free().
278171095Ssam * @free_lock: Lock to protect @free_arr.
279171095Ssam * ----------- reserve/post section ---------------
280171095Ssam * @post_index: Post index. At any point in time points on the
281171095Ssam *              position in the channel, which'll contain next to-be-posted
282171095Ssam *              descriptor.
283171095Ssam * @post_lock: Lock to serialize multiple concurrent "posters" of descriptors
284171095Ssam *             on the given channel.
285171095Ssam * @reserve_arr: Reserve array. Contains descriptors that can be reserved
286171095Ssam *               by ULD for the subsequent send or receive operation.
287171095Ssam *               See xge_hal_fifo_dtr_reserve(),
288171095Ssam *               xge_hal_ring_dtr_reserve().
289171095Ssam * @reserve_length: Length of the @reserve_arr. The length dynamically
290171095Ssam *                  changes: it decrements each time descriptor is reserved.
291171095Ssam * @reserve_lock: Lock to serialize multiple concurrent threads accessing
292171095Ssam *                @reserve_arr.
293171095Ssam * @reserve_threshold: Reserve threshold. Minimal number of free descriptors
294171095Ssam *                     that ought to be preserved in the channel at all times.
295171095Ssam *                     Note that @reserve_threshold >= 0 &&
296171095Ssam *                     @reserve_threshold < @reserve_max.
297171095Ssam * ------------ common section --------------------
298171095Ssam * @devh: Device handle. HAL device object that contains _this_ channel.
299171095Ssam * @dmah: Channel's DMA address. Used to synchronize (to/from device)
300171095Ssam *        descriptors.
301171095Ssam * @regh0: Base address of the device memory space handle. Copied from HAL device
302171095Ssam *         at channel open time.
303171095Ssam * @regh1: Base address of the device memory space handle. Copied from HAL device
304171095Ssam *         at channel open time.
305171095Ssam * @userdata: Per-channel opaque (void*) user-defined context, which may be
306171095Ssam *            upper-layer driver object, ULP connection, etc.
307171095Ssam *            Once channel is open, @userdata is passed back to user via
308171095Ssam *            xge_hal_channel_callback_f.
309171095Ssam * @work_arr: Work array. Contains descriptors posted to the channel.
310171095Ssam *            Note that at any point in time @work_arr contains 3 types of
311171095Ssam *            descriptors:
312171095Ssam *            1) posted but not yet consumed by Xframe device;
313171095Ssam *            2) consumed but not yet completed;
314171095Ssam *            3) completed but not yet freed
315171095Ssam *            (via xge_hal_fifo_dtr_free() or xge_hal_ring_dtr_free())
316171095Ssam * @saved_arr: Array used internally to optimize channel full-duplex
317171095Ssam *             operation.
318171095Ssam * @stats: Channel statistcis. Includes HAL internal counters, including
319171095Ssam *         for instance, number of times out-of-descriptors
320171095Ssam *         (see XGE_HAL_INF_OUT_OF_DESCRIPTORS) condition happened.
321171095Ssam * ------------- "slow" section  ------------------
322171095Ssam * @type: Channel type. See xge_hal_channel_type_e{}.
323171095Ssam * @vp_id: Virtual path id
324171095Ssam * @post_qid: Identifies Xframe queue used for posting descriptors.
325171095Ssam * @compl_qid: Identifies Xframe completion queue.
326171095Ssam * @flags: Channel flags. See xge_hal_channel_flag_e{}.
327171095Ssam * @reserve_initial: Initial number of descriptors allocated at channel open
328171095Ssam *                   time (see xge_hal_channel_open()). The number of
329171095Ssam *                   channel descriptors can grow at runtime
330171095Ssam *                   up to @reserve_max value.
331171095Ssam * @reserve_max: Maximum number of channel descriptors. See @reserve_initial.
332171095Ssam * @is_open: True, if channel is open; false - otherwise.
333171095Ssam * @per_dtr_space: Per-descriptor space (in bytes) that channel user can utilize
334171095Ssam *                 to store per-operation control information.
335171095Ssam * HAL channel object. HAL devices (see xge_hal_device_t{}) contains
336171095Ssam * zero or more channels. HAL channel contains zero or more descriptors. The
337171095Ssam * latter are used by ULD(s) to manage the device and/or send and receive data
338171095Ssam * to remote peer(s) via the channel.
339171095Ssam *
340171095Ssam * See also: xge_hal_channel_type_e{}, xge_hal_channel_flag_e,
341171095Ssam * xge_hal_channel_callback_f{}
342171095Ssam */
343171095Ssamtypedef struct {
344171095Ssam	/* complete/free section */
345173139Srwatson	xge_list_t          item;
346173139Srwatson	xge_hal_channel_callback_f  callback;
347173139Srwatson	void                **free_arr;
348173139Srwatson	int             length;
349173139Srwatson	int             free_length;
350171095Ssam#if defined(XGE_HAL_RX_MULTI_FREE_IRQ) || defined(XGE_HAL_TX_MULTI_FREE_IRQ) || \
351173139Srwatson	defined(XGE_HAL_RX_MULTI_FREE) || defined(XGE_HAL_TX_MULTI_FREE)
352173139Srwatson	spinlock_t          free_lock;
353171095Ssam#endif
354173139Srwatson	int             compl_index;
355173139Srwatson	unsigned int            usage_cnt;
356173139Srwatson	unsigned int            poll_bytes;
357171095Ssam
358171095Ssam	/* reserve/post data path section */
359173139Srwatson	int             terminating;
360171095Ssam#ifdef __XGE_WIN__
361173139Srwatson	int             __xge_os_attr_cacheline_aligned
362173139Srwatson	                post_index;
363171095Ssam#else
364173139Srwatson	int             post_index
365173139Srwatson	                __xge_os_attr_cacheline_aligned;
366171095Ssam#endif
367173139Srwatson	spinlock_t          reserve_lock;
368173139Srwatson	spinlock_t          post_lock;
369171095Ssam
370173139Srwatson	void                **reserve_arr;
371173139Srwatson	int             reserve_length;
372173139Srwatson	int             reserve_threshold;
373173139Srwatson	int             reserve_top;
374171095Ssam	int                             unused1;
375171095Ssam
376171095Ssam	/* common section */
377173139Srwatson	xge_hal_device_h        devh;
378171095Ssam	pci_dev_h                       pdev;
379173139Srwatson	pci_reg_h           regh0;
380173139Srwatson	pci_reg_h           regh1;
381173139Srwatson	void                *userdata;
382173139Srwatson	void                **work_arr;
383173139Srwatson	void                **saved_arr;
384173139Srwatson	void                **orig_arr;
385173139Srwatson	xge_hal_stats_channel_info_t    stats;
386171095Ssam
387171095Ssam	/* slow section */
388173139Srwatson	xge_hal_channel_type_e      type;
389173139Srwatson	int             post_qid;
390173139Srwatson	int             compl_qid;
391173139Srwatson	xge_hal_channel_flag_e      flags;
392173139Srwatson	int             reserve_initial;
393173139Srwatson	int             reserve_max;
394173139Srwatson	int             is_open;
395173139Srwatson	int             per_dtr_space;
396173139Srwatson	xge_hal_channel_dtr_term_f  dtr_term;
397173139Srwatson	xge_hal_channel_dtr_init_f  dtr_init;
398171095Ssam	/* MSI stuff */
399173139Srwatson	u32             msi_msg;
400173139Srwatson	u8              rti;
401173139Srwatson	u8              tti;
402171095Ssam	u16                             unused2;
403171095Ssam	/* MSI-X stuff */
404173139Srwatson	u64             msix_address;
405173139Srwatson	u32             msix_data;
406173139Srwatson	int             msix_idx;
407173139Srwatson	volatile int            in_interrupt;
408173139Srwatson	    unsigned int            magic;
409171095Ssam#ifdef __XGE_WIN__
410171095Ssam} __xge_os_attr_cacheline_aligned xge_hal_channel_t ;
411171095Ssam#else
412171095Ssam} xge_hal_channel_t __xge_os_attr_cacheline_aligned;
413171095Ssam#endif
414171095Ssam
415171095Ssam/* ========================== CHANNEL PRIVATE API ========================= */
416171095Ssam
417171095Ssamxge_hal_status_e
418171095Ssam__hal_channel_initialize(xge_hal_channel_h channelh,
419173139Srwatson	    xge_hal_channel_attr_t *attr, void **reserve_arr,
420173139Srwatson	    int reserve_initial, int reserve_max, int reserve_threshold);
421171095Ssam
422171095Ssamvoid __hal_channel_terminate(xge_hal_channel_h channelh);
423171095Ssam
424171095Ssamxge_hal_channel_t*
425171095Ssam__hal_channel_allocate(xge_hal_device_h devh, int post_qid,
426173139Srwatson	    xge_hal_channel_type_e  type);
427171095Ssam
428171095Ssamvoid __hal_channel_free(xge_hal_channel_t *channel);
429171095Ssam
430171095Ssam#if defined(XGE_DEBUG_FP) && (XGE_DEBUG_FP & XGE_DEBUG_FP_CHANNEL)
431171095Ssam#define __HAL_STATIC_CHANNEL
432171095Ssam#define __HAL_INLINE_CHANNEL
433171095Ssam
434171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL xge_hal_status_e
435171095Ssam__hal_channel_dtr_alloc(xge_hal_channel_h channelh, xge_hal_dtr_h *dtrh);
436171095Ssam
437171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL void
438171095Ssam__hal_channel_dtr_post(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh);
439171095Ssam
440171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL void
441171095Ssam__hal_channel_dtr_try_complete(xge_hal_channel_h channelh, xge_hal_dtr_h *dtrh);
442171095Ssam
443171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL void
444171095Ssam__hal_channel_dtr_complete(xge_hal_channel_h channelh);
445171095Ssam
446171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL void
447171095Ssam__hal_channel_dtr_free(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh);
448171095Ssam
449171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL void
450171095Ssam__hal_channel_dtr_dealloc(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh);
451171095Ssam
452171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL void
453171095Ssam__hal_channel_dtr_restore(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh,
454173139Srwatson	          int offset);
455171095Ssam
456171095Ssam/* ========================== CHANNEL PUBLIC API ========================= */
457171095Ssam
458171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL int
459171095Ssamxge_hal_channel_dtr_count(xge_hal_channel_h channelh);
460171095Ssam
461171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL void*
462171095Ssamxge_hal_channel_userdata(xge_hal_channel_h channelh);
463171095Ssam
464171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL int
465171095Ssamxge_hal_channel_id(xge_hal_channel_h channelh);
466171095Ssam
467171095Ssam__HAL_STATIC_CHANNEL __HAL_INLINE_CHANNEL int
468171095Ssamxge_hal_check_alignment(dma_addr_t dma_pointer, int size, int alignment,
469173139Srwatson	    int copy_size);
470171095Ssam
471171095Ssam#else /* XGE_FASTPATH_EXTERN */
472171095Ssam#define __HAL_STATIC_CHANNEL static
473171095Ssam#define __HAL_INLINE_CHANNEL inline
474171095Ssam#include <dev/nxge/xgehal/xgehal-channel-fp.c>
475171095Ssam#endif /* XGE_FASTPATH_INLINE */
476171095Ssam
477171095Ssamxge_hal_status_e
478171095Ssamxge_hal_channel_open(xge_hal_device_h hldev, xge_hal_channel_attr_t *attr,
479173139Srwatson	         xge_hal_channel_h *channel,
480173139Srwatson	         xge_hal_channel_reopen_e reopen);
481171095Ssam
482171095Ssamvoid xge_hal_channel_close(xge_hal_channel_h channelh,
483173139Srwatson	                       xge_hal_channel_reopen_e reopen);
484171095Ssam
485171095Ssamvoid xge_hal_channel_abort(xge_hal_channel_h channelh,
486173139Srwatson	                       xge_hal_channel_reopen_e reopen);
487171095Ssam
488171095Ssam__EXTERN_END_DECLS
489171095Ssam
490171095Ssam#endif /* XGE_HAL_CHANNEL_H */
491