1a23fd11yl/*
2a23fd11yl * CDDL HEADER START
3a23fd11yl *
4a23fd11yl * The contents of this file are subject to the terms of the
5a23fd11yl * Common Development and Distribution License (the "License").
6a23fd11yl * You may not use this file except in compliance with the License.
7a23fd11yl *
8a23fd11yl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9a23fd11yl * or http://www.opensolaris.org/os/licensing.
10a23fd11yl * See the License for the specific language governing permissions
11a23fd11yl * and limitations under the License.
12a23fd11yl *
13a23fd11yl * When distributing Covered Code, include this CDDL HEADER in each
14a23fd11yl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15a23fd11yl * If applicable, add the following below this CDDL HEADER, with the
16a23fd11yl * fields enclosed by brackets "[]" replaced with your own identifying
17a23fd11yl * information: Portions Copyright [yyyy] [name of copyright owner]
18a23fd11yl *
19a23fd11yl * CDDL HEADER END
20a23fd11yl *
218347601yl * Copyright (c) 2002-2006 Neterion, Inc.
22a23fd11yl */
23a23fd11yl
24a23fd11yl#ifndef XGE_HAL_DRIVER_H
25a23fd11yl#define XGE_HAL_DRIVER_H
26a23fd11yl
27a23fd11yl#include "xge-os-pal.h"
28a23fd11yl#include "xge-list.h"
29a23fd11yl#include "xge-queue.h"
30a23fd11yl#include "xgehal-types.h"
31a23fd11yl#include "xgehal-config.h"
32a23fd11yl#include "xgehal-event.h"
33a23fd11yl
348347601yl__EXTERN_BEGIN_DECLS
358347601yl
36a23fd11yl/* maximum number of events consumed in a syncle poll() cycle */
37a23fd11yl#define XGE_HAL_DRIVER_QUEUE_CONSUME_MAX	5
38a23fd11yl
39a23fd11yl
40a23fd11yl/**
41a23fd11yl * function xge_uld_sched_timer_cb_f - Per-device periodic timer
42a23fd11yl * callback.
43a23fd11yl * @devh: HAL device handle.
44a23fd11yl * @userdata: Per-device user data (a.k.a. context) specified via
45a23fd11yl * xge_hal_device_initialize().
46a23fd11yl *
47a23fd11yl * Periodic or one-shot timer callback. If specified (that is, not NULL)
48a23fd11yl * HAL invokes this callback periodically. The call is performed in the
49a23fd11yl * interrupt context, or more exactly, in the context of HAL's ISR
50a23fd11yl * xge_hal_device_continue_irq().
51a23fd11yl *
52a23fd11yl * See also: xge_hal_device_initialize{}
53a23fd11yl */
54a23fd11yltypedef void (*xge_uld_sched_timer_cb_f)(xge_hal_device_h devh, void *userdata);
55a23fd11yl
56a23fd11yl/**
57a23fd11yl * function xge_uld_link_up_f - Link-Up callback provided by upper-layer
58a23fd11yl * driver.
59a23fd11yl * @userdata: Opaque context set by the ULD via
60a23fd11yl * xge_hal_device_private_set()
61a23fd11yl * (typically - at HAL device iinitialization time).
62a23fd11yl *
63a23fd11yl * Link-up notification callback provided by the ULD.
64a23fd11yl * This is one of the per-driver callbacks, see xge_hal_uld_cbs_t{}.
65a23fd11yl *
66a23fd11yl * See also: xge_hal_uld_cbs_t{}, xge_uld_link_down_f{},
67a23fd11yl * xge_hal_driver_initialize(), xge_hal_device_private_set().
68a23fd11yl */
69a23fd11yltypedef void (*xge_uld_link_up_f) (void *userdata);
70a23fd11yl
71a23fd11yl/**
72a23fd11yl * function xge_uld_link_down_f - Link-Down callback provided by
73a23fd11yl * upper-layer driver.
74a23fd11yl * @userdata: Opaque context set by the ULD via
75a23fd11yl * xge_hal_device_private_set()
76a23fd11yl * (typically - at HAL device iinitialization time).
77a23fd11yl *
78a23fd11yl * Link-Down notification callback provided by the upper-layer driver.
79a23fd11yl * This is one of the per-driver callbacks, see xge_hal_uld_cbs_t{}.
80a23fd11yl *
81a23fd11yl * See also: xge_hal_uld_cbs_t{}, xge_uld_link_up_f{},
82a23fd11yl * xge_hal_driver_initialize(), xge_hal_device_private_set().
83a23fd11yl */
84a23fd11yltypedef void (*xge_uld_link_down_f) (void *userdata);
85a23fd11yl
86a23fd11yl/**
87a23fd11yl * function xge_uld_crit_err_f - Critical Error notification callback.
88a23fd11yl * @userdata: Opaque context set by the ULD via
89a23fd11yl * xge_hal_device_private_set()
90a23fd11yl * (typically - at HAL device iinitialization time).
91a23fd11yl * @type: Enumerated hw error, e.g.: double ECC.
92a23fd11yl * @serr_data: Xframe status.
93a23fd11yl * @ext_data: Extended data. The contents depends on the @type.
94a23fd11yl *
95a23fd11yl * Link-Down notification callback provided by the upper-layer driver.
96a23fd11yl * This is one of the per-driver callbacks, see xge_hal_uld_cbs_t{}.
97a23fd11yl *
98a23fd11yl * See also: xge_hal_uld_cbs_t{}, xge_hal_event_e{},
99a23fd11yl * xge_hal_device_private_set(), xge_hal_driver_initialize().
100a23fd11yl */
101a23fd11yltypedef void (*xge_uld_crit_err_f) (void *userdata, xge_hal_event_e type,
102a23fd11yl		u64 ext_data);
103a23fd11yl
104a23fd11yl/**
105a23fd11yl * function xge_uld_event_queued_f - Event-enqueued notification
106a23fd11yl * callback.
107a23fd11yl * @devh: HAL device handle.
108a23fd11yl * @event_type: HAL- or ULD-defined event type. Note that HAL
109a23fd11yl *              events are enumerated by xge_hal_event_e{}.
110a23fd11yl *
111a23fd11yl * "Event-was-enqueued" notification callback provided by the upper-layer
112a23fd11yl * driver. The callback is invoked (if defined, i.e., not NULL in the
113a23fd11yl * xge_hal_uld_cbs_t{} structure) each time immediately after an event
114a23fd11yl * is enqueued.
115a23fd11yl *
116a23fd11yl * See also: xge_hal_uld_cbs_t{}, xge_hal_device_private_set(),
117a23fd11yl * xge_hal_driver_initialize().
118a23fd11yl */
119a23fd11yltypedef void (*xge_uld_event_queued_f) (xge_hal_device_h devh, int event_type);
120a23fd11yl
121a23fd11yl/**
122a23fd11yl * function xge_uld_event_f - ULD event callback.
123a23fd11yl * @item: ULD-defined event, item of the xge_queue_t.
124a23fd11yl *
125a23fd11yl * ULD event callback.
126a23fd11yl * Upper-layer driver can use HAL queue to serialize certain slow-path
127a23fd11yl * events. HAL periodically polls the queue as part of the
128a23fd11yl * xge_hal_device_poll() processing. When/if HAL discovers in the queue
129a23fd11yl * an unkown event type it simply invokes the event callback
130a23fd11yl * (which must be non-NULL and supplied by the ULD in this case).
131a23fd11yl *
132a23fd11yl * See also: xge_hal_uld_cbs_t{}, xge_hal_device_poll(), xge_queue_t{},
133a23fd11yl * xge_hal_driver_initialize(), xge_queue_item_t{}.
134a23fd11yl */
135a23fd11yltypedef void (*xge_uld_event_f) (xge_queue_item_t *item);
136a23fd11yl
137a23fd11yl/**
138a23fd11yl * function xge_uld_before_device_poll_f - ULD "before-poll" callback.
139a23fd11yl * @devh: HAL device handle.
140a23fd11yl *
141a23fd11yl * HAL invokes the callback from inside its xge_hal_device_poll()
142a23fd11yl * implementation %prior to accessing the @devh device. This allows ULD to
143a23fd11yl * perform per-device locking and/or context mapping, if required..
144a23fd11yl * The interface is currently used by AIX driver only.
145a23fd11yl * To avoid using/implementing the callback set the corresponding field
146a23fd11yl * in the xge_hal_uld_cbs_t{} structure to NULL.
147a23fd11yl *
148a23fd11yl * Returns: 0 on success, non-zero on failure.
149a23fd11yl *
150a23fd11yl * See also: xge_hal_driver_initialize(), xge_hal_uld_cbs_t{},
151a23fd11yl * xge_hal_device_poll().
152a23fd11yl */
153a23fd11yltypedef int (*xge_uld_before_device_poll_f) (xge_hal_device_h devh);
154a23fd11yl
155a23fd11yl/**
156a23fd11yl * function xge_uld_after_device_poll_f - ULD "after-poll" callback.
157a23fd11yl * @devh: HAL device handle.
158a23fd11yl *
159a23fd11yl * Unless NULL is specified,
160a23fd11yl * HAL invokes the callback from inside its xge_hal_device_poll()
161a23fd11yl * implementation immediately %after it has completed polling the @devh
162a23fd11yl * device. This allows ULD to undo the affects of
163a23fd11yl * xge_uld_before_device_poll_f{}.
164a23fd11yl * The interface is currently used by AIX driver only.
165a23fd11yl *
166a23fd11yl * See also: xge_hal_driver_initialize(), xge_hal_uld_cbs_t{},
167a23fd11yl * xge_hal_device_poll().
168a23fd11yl */
169a23fd11yltypedef void (*xge_uld_after_device_poll_f) (xge_hal_device_h devh);
170a23fd11yl
171a23fd11yl/**
1728347601yl * function xge_uld_xpak_alarm_log_f - ULD "XPAK alarm log" callback.
1738347601yl * @devh: HAL device handle.
1747eced41xw * @type: TODO
1758347601yl *
1768347601yl * Unless NULL is specified,
1778347601yl * HAL invokes the callback from inside __hal_chk_xpak_counter()
1788347601yl */
1798347601yltypedef void (*xge_uld_xpak_alarm_log_f) (xge_hal_device_h devh, xge_hal_xpak_alarm_type_e type);
1808347601yl
1818347601yl/**
182a23fd11yl * struct xge_hal_uld_cbs_t - Upper-layer driver "slow-path" callbacks.
183a23fd11yl * @link_up: See xge_uld_link_up_f{}.
184a23fd11yl * @link_down: See xge_uld_link_down_f{}.
185a23fd11yl * @crit_err: See xge_uld_crit_err_f{}.
186a23fd11yl * @event: See xge_uld_event_f{}.
187a23fd11yl * @event_queued: See xge_uld_event_queued_f{}.
188a23fd11yl * @before_device_poll: See xge_uld_before_device_poll_f{}.
189a23fd11yl * @after_device_poll: See xge_uld_after_device_poll_f{}.
190a23fd11yl * @sched_timer: See xge_uld_sched_timer_cb_f{}.
1917eced41xw * @xpak_alarm_log: TODO
192a23fd11yl *
193a23fd11yl * Upper layer driver slow-path (per-driver) callbacks.
194a23fd11yl * Implemented by ULD and provided to HAL via
195a23fd11yl * xge_hal_driver_initialize().
196a23fd11yl * Note that these callbacks are not mandatory: HAL will not invoke
197a23fd11yl * a callback if NULL is specified.
198a23fd11yl *
199a23fd11yl * Note that in addition to those, there are curently 2 per-channel callbacks
200a23fd11yl * (completion and abort) specified at channel open time
201a23fd11yl * via xge_hal_channel_open().
202a23fd11yl *
203a23fd11yl * See also: xge_hal_driver_initialize().
204a23fd11yl */
205a23fd11yltypedef struct xge_hal_uld_cbs_t {
206a23fd11yl	xge_uld_link_up_f		link_up;
207a23fd11yl	xge_uld_link_down_f		link_down;
208a23fd11yl	xge_uld_crit_err_f		crit_err;
209a23fd11yl	xge_uld_event_f			event;
210a23fd11yl	xge_uld_event_queued_f		event_queued;
211a23fd11yl	xge_uld_before_device_poll_f    before_device_poll;
212a23fd11yl	xge_uld_after_device_poll_f	after_device_poll;
213a23fd11yl	xge_uld_sched_timer_cb_f	sched_timer;
2148347601yl	xge_uld_xpak_alarm_log_f	xpak_alarm_log;
215a23fd11yl} xge_hal_uld_cbs_t;
216a23fd11yl
217a23fd11yl/**
218a23fd11yl * struct xge_hal_driver_t - Represents HAL object.
219a23fd11yl * @config: HAL configuration.
220a23fd11yl * @devices: List of all PCI-enumerated Xframe devices in the system.
221a23fd11yl * A single xge_hal_driver_t instance contains zero or more
222a23fd11yl * Xframe devices.
223a23fd11yl * @devices_lock: Lock to protect %devices when inserting/removing.
224a23fd11yl * @is_initialized: True if HAL is initialized; false otherwise.
225a23fd11yl * @uld_callbacks: Upper-layer driver callbacks. See xge_hal_uld_cbs_t{}.
226a23fd11yl * @debug_module_mask: 32bit mask that defines which components of the
227a23fd11yl * driver are to be traced. The trace-able components are:
228a23fd11yl *	XGE_COMPONENT_HAL_CONFIG		0x1
229a23fd11yl *	XGE_COMPONENT_HAL_FIFO			0x2
230a23fd11yl *	XGE_COMPONENT_HAL_RING			0x4
231a23fd11yl *	XGE_COMPONENT_HAL_CHANNEL		0x8
232a23fd11yl *	XGE_COMPONENT_HAL_DEVICE		0x10
233a23fd11yl *	XGE_COMPONENT_HAL_MM			0x20
234a23fd11yl *	XGE_COMPONENT_HAL_QUEUE			0x40
235a23fd11yl *	XGE_COMPONENT_HAL_STATS			0x100
236a23fd11yl *	XGE_COMPONENT_OSDEP			0x1000
237a23fd11yl *	XGE_COMPONENT_LL			0x2000
238a23fd11yl *	XGE_COMPONENT_TOE			0x4000
239a23fd11yl *	XGE_COMPONENT_RDMA			0x8000
240a23fd11yl *	XGE_COMPONENT_ALL			0xffffffff
241a23fd11yl * The @debug_module_mask allows to switch off and on tracing at runtime.
242a23fd11yl * In addition, the traces for the same trace-able components can be
243a23fd11yl * compiled out, based on the same mask provided via Makefile.
244a23fd11yl * @debug_level: See xge_debug_level_e{}.
245a23fd11yl *
246a23fd11yl * HAL (driver) object. There is a single instance of this structure per HAL.
247a23fd11yl */
248a23fd11yltypedef struct xge_hal_driver_t {
249a23fd11yl	xge_hal_driver_config_t		config;
250a23fd11yl	int                             is_initialized;
251a23fd11yl	xge_hal_uld_cbs_t               uld_callbacks;
252a23fd11yl	u32				debug_module_mask;
253a23fd11yl	int				debug_level;
254a23fd11yl} xge_hal_driver_t;
255a23fd11yl
256a23fd11ylextern xge_hal_driver_t *g_xge_hal_driver;
257a23fd11yl
258a23fd11ylstatic inline int
259a23fd11ylxge_hal_driver_is_initialized(void) {
260a23fd11yl        return g_xge_hal_driver->is_initialized;
261a23fd11yl}
262a23fd11yl
263a23fd11ylstatic inline int
264a23fd11ylxge_hal_driver_debug_module_mask(void)
265a23fd11yl{
266a23fd11yl	return g_xge_hal_driver->debug_module_mask;
267a23fd11yl}
268a23fd11yl
269a23fd11ylstatic inline void
270a23fd11ylxge_hal_driver_debug_module_mask_set(u32 new_mask)
271a23fd11yl{
272a23fd11yl#if (defined(XGE_DEBUG_TRACE_MASK) && XGE_DEBUG_TRACE_MASK > 0) || \
273a23fd11yl    (defined(XGE_DEBUG_ERR_MASK) && XGE_DEBUG_ERR_MASK > 0)
274a23fd11yl	g_xge_hal_driver->debug_module_mask = new_mask;
2757eced41xw	g_module_mask = (unsigned long *)&g_xge_hal_driver->debug_module_mask;
276a23fd11yl#endif
277a23fd11yl}
278a23fd11yl
279a23fd11ylstatic inline int
280a23fd11ylxge_hal_driver_debug_level(void) { return g_xge_hal_driver->debug_level; }
281a23fd11yl
282a23fd11ylstatic inline void
283a23fd11ylxge_hal_driver_debug_level_set(int new_level)
284a23fd11yl{
285a23fd11yl#if (defined(XGE_DEBUG_TRACE_MASK) && XGE_DEBUG_TRACE_MASK > 0) || \
286a23fd11yl    (defined(XGE_DEBUG_ERR_MASK) && XGE_DEBUG_ERR_MASK > 0)
287a23fd11yl	g_xge_hal_driver->debug_level = new_level;
288a23fd11yl	g_level = &g_xge_hal_driver->debug_level;
289a23fd11yl#endif
290a23fd11yl}
291a23fd11yl
292a23fd11ylxge_hal_status_e xge_hal_driver_initialize(xge_hal_driver_config_t *config,
293a23fd11yl		xge_hal_uld_cbs_t *uld_callbacks);
294a23fd11yl
295a23fd11ylvoid xge_hal_driver_terminate(void);
296a23fd11yl
297a23fd11yl#ifdef XGE_TRACE_INTO_CIRCULAR_ARR
298a23fd11ylvoid xge_hal_driver_tracebuf_dump(void);
2997eced41xw
3007eced41xwxge_hal_status_e
3017eced41xwxge_hal_driver_tracebuf_read(int bufsize, char *retbuf, int *retsize);
302a23fd11yl#else
303a23fd11yl#define xge_hal_driver_tracebuf_dump()
3047eced41xw#define xge_hal_driver_tracebuf_read(a, b, c) (0);
305a23fd11yl#endif
306a23fd11yl
3078347601yl__EXTERN_END_DECLS
308a23fd11yl
309a23fd11yl#endif /* XGE_HAL_DRIVER_H */
310