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_DRIVER_H 30171095Ssam#define XGE_HAL_DRIVER_H 31171095Ssam 32171095Ssam#include <dev/nxge/include/xge-os-pal.h> 33171095Ssam#include <dev/nxge/include/xge-list.h> 34171095Ssam#include <dev/nxge/include/xge-queue.h> 35171095Ssam#include <dev/nxge/include/xgehal-types.h> 36171095Ssam#include <dev/nxge/include/xgehal-config.h> 37171095Ssam#include <dev/nxge/include/xgehal-event.h> 38171095Ssam 39171095Ssam__EXTERN_BEGIN_DECLS 40171095Ssam 41171095Ssam/* maximum number of events consumed in a syncle poll() cycle */ 42173139Srwatson#define XGE_HAL_DRIVER_QUEUE_CONSUME_MAX 5 43171095Ssam 44171095Ssam 45171095Ssam/** 46171095Ssam * function xge_uld_sched_timer_cb_f - Per-device periodic timer 47171095Ssam * callback. 48171095Ssam * @devh: HAL device handle. 49171095Ssam * @userdata: Per-device user data (a.k.a. context) specified via 50171095Ssam * xge_hal_device_initialize(). 51171095Ssam * 52171095Ssam * Periodic or one-shot timer callback. If specified (that is, not NULL) 53171095Ssam * HAL invokes this callback periodically. The call is performed in the 54171095Ssam * interrupt context, or more exactly, in the context of HAL's ISR 55171095Ssam * xge_hal_device_continue_irq(). 56171095Ssam * 57171095Ssam * See also: xge_hal_device_initialize{} 58171095Ssam */ 59171095Ssamtypedef void (*xge_uld_sched_timer_cb_f)(xge_hal_device_h devh, void *userdata); 60171095Ssam 61171095Ssam/** 62171095Ssam * function xge_uld_link_up_f - Link-Up callback provided by upper-layer 63171095Ssam * driver. 64171095Ssam * @userdata: Opaque context set by the ULD via 65171095Ssam * xge_hal_device_private_set() 66171095Ssam * (typically - at HAL device iinitialization time). 67171095Ssam * 68171095Ssam * Link-up notification callback provided by the ULD. 69171095Ssam * This is one of the per-driver callbacks, see xge_hal_uld_cbs_t{}. 70171095Ssam * 71171095Ssam * See also: xge_hal_uld_cbs_t{}, xge_uld_link_down_f{}, 72171095Ssam * xge_hal_driver_initialize(), xge_hal_device_private_set(). 73171095Ssam */ 74171095Ssamtypedef void (*xge_uld_link_up_f) (void *userdata); 75171095Ssam 76171095Ssam/** 77171095Ssam * function xge_uld_link_down_f - Link-Down callback provided by 78171095Ssam * upper-layer driver. 79171095Ssam * @userdata: Opaque context set by the ULD via 80171095Ssam * xge_hal_device_private_set() 81171095Ssam * (typically - at HAL device iinitialization time). 82171095Ssam * 83171095Ssam * Link-Down notification callback provided by the upper-layer driver. 84171095Ssam * This is one of the per-driver callbacks, see xge_hal_uld_cbs_t{}. 85171095Ssam * 86171095Ssam * See also: xge_hal_uld_cbs_t{}, xge_uld_link_up_f{}, 87171095Ssam * xge_hal_driver_initialize(), xge_hal_device_private_set(). 88171095Ssam */ 89171095Ssamtypedef void (*xge_uld_link_down_f) (void *userdata); 90171095Ssam 91171095Ssam/** 92171095Ssam * function xge_uld_crit_err_f - Critical Error notification callback. 93171095Ssam * @userdata: Opaque context set by the ULD via 94171095Ssam * xge_hal_device_private_set() 95171095Ssam * (typically - at HAL device iinitialization time). 96171095Ssam * @type: Enumerated hw error, e.g.: double ECC. 97171095Ssam * @serr_data: Xframe status. 98171095Ssam * @ext_data: Extended data. The contents depends on the @type. 99171095Ssam * 100171095Ssam * Link-Down notification callback provided by the upper-layer driver. 101171095Ssam * This is one of the per-driver callbacks, see xge_hal_uld_cbs_t{}. 102171095Ssam * 103171095Ssam * See also: xge_hal_uld_cbs_t{}, xge_hal_event_e{}, 104171095Ssam * xge_hal_device_private_set(), xge_hal_driver_initialize(). 105171095Ssam */ 106171095Ssamtypedef void (*xge_uld_crit_err_f) (void *userdata, xge_hal_event_e type, 107173139Srwatson u64 ext_data); 108171095Ssam 109171095Ssam/** 110171095Ssam * function xge_uld_event_queued_f - Event-enqueued notification 111171095Ssam * callback. 112171095Ssam * @devh: HAL device handle. 113171095Ssam * @event_type: HAL- or ULD-defined event type. Note that HAL 114171095Ssam * events are enumerated by xge_hal_event_e{}. 115171095Ssam * 116171095Ssam * "Event-was-enqueued" notification callback provided by the upper-layer 117171095Ssam * driver. The callback is invoked (if defined, i.e., not NULL in the 118171095Ssam * xge_hal_uld_cbs_t{} structure) each time immediately after an event 119171095Ssam * is enqueued. 120171095Ssam * 121171095Ssam * See also: xge_hal_uld_cbs_t{}, xge_hal_device_private_set(), 122171095Ssam * xge_hal_driver_initialize(). 123171095Ssam */ 124171095Ssamtypedef void (*xge_uld_event_queued_f) (xge_hal_device_h devh, int event_type); 125171095Ssam 126171095Ssam/** 127171095Ssam * function xge_uld_event_f - ULD event callback. 128171095Ssam * @item: ULD-defined event, item of the xge_queue_t. 129171095Ssam * 130171095Ssam * ULD event callback. 131171095Ssam * Upper-layer driver can use HAL queue to serialize certain slow-path 132171095Ssam * events. HAL periodically polls the queue as part of the 133171095Ssam * xge_hal_device_poll() processing. When/if HAL discovers in the queue 134171095Ssam * an unkown event type it simply invokes the event callback 135171095Ssam * (which must be non-NULL and supplied by the ULD in this case). 136171095Ssam * 137171095Ssam * See also: xge_hal_uld_cbs_t{}, xge_hal_device_poll(), xge_queue_t{}, 138171095Ssam * xge_hal_driver_initialize(), xge_queue_item_t{}. 139171095Ssam */ 140171095Ssamtypedef void (*xge_uld_event_f) (xge_queue_item_t *item); 141171095Ssam 142171095Ssam/** 143171095Ssam * function xge_uld_before_device_poll_f - ULD "before-poll" callback. 144171095Ssam * @devh: HAL device handle. 145171095Ssam * 146171095Ssam * HAL invokes the callback from inside its xge_hal_device_poll() 147171095Ssam * implementation %prior to accessing the @devh device. This allows ULD to 148171095Ssam * perform per-device locking and/or context mapping, if required.. 149171095Ssam * The interface is currently used by AIX driver only. 150171095Ssam * To avoid using/implementing the callback set the corresponding field 151171095Ssam * in the xge_hal_uld_cbs_t{} structure to NULL. 152171095Ssam * 153171095Ssam * Returns: 0 on success, non-zero on failure. 154171095Ssam * 155171095Ssam * See also: xge_hal_driver_initialize(), xge_hal_uld_cbs_t{}, 156171095Ssam * xge_hal_device_poll(). 157171095Ssam */ 158171095Ssamtypedef int (*xge_uld_before_device_poll_f) (xge_hal_device_h devh); 159171095Ssam 160171095Ssam/** 161171095Ssam * function xge_uld_after_device_poll_f - ULD "after-poll" callback. 162171095Ssam * @devh: HAL device handle. 163171095Ssam * 164171095Ssam * Unless NULL is specified, 165171095Ssam * HAL invokes the callback from inside its xge_hal_device_poll() 166171095Ssam * implementation immediately %after it has completed polling the @devh 167171095Ssam * device. This allows ULD to undo the affects of 168171095Ssam * xge_uld_before_device_poll_f{}. 169171095Ssam * The interface is currently used by AIX driver only. 170171095Ssam * 171171095Ssam * See also: xge_hal_driver_initialize(), xge_hal_uld_cbs_t{}, 172171095Ssam * xge_hal_device_poll(). 173171095Ssam */ 174171095Ssamtypedef void (*xge_uld_after_device_poll_f) (xge_hal_device_h devh); 175171095Ssam 176171095Ssam/** 177171095Ssam * function xge_uld_xpak_alarm_log_f - ULD "XPAK alarm log" callback. 178171095Ssam * @devh: HAL device handle. 179171095Ssam * @type: TODO 180171095Ssam * 181171095Ssam * Unless NULL is specified, 182171095Ssam * HAL invokes the callback from inside __hal_chk_xpak_counter() 183171095Ssam */ 184171095Ssamtypedef void (*xge_uld_xpak_alarm_log_f) (xge_hal_device_h devh, xge_hal_xpak_alarm_type_e type); 185171095Ssam 186171095Ssam/** 187171095Ssam * struct xge_hal_uld_cbs_t - Upper-layer driver "slow-path" callbacks. 188171095Ssam * @link_up: See xge_uld_link_up_f{}. 189171095Ssam * @link_down: See xge_uld_link_down_f{}. 190171095Ssam * @crit_err: See xge_uld_crit_err_f{}. 191171095Ssam * @event: See xge_uld_event_f{}. 192171095Ssam * @event_queued: See xge_uld_event_queued_f{}. 193171095Ssam * @before_device_poll: See xge_uld_before_device_poll_f{}. 194171095Ssam * @after_device_poll: See xge_uld_after_device_poll_f{}. 195171095Ssam * @sched_timer: See xge_uld_sched_timer_cb_f{}. 196171095Ssam * @xpak_alarm_log: TODO 197171095Ssam * 198171095Ssam * Upper layer driver slow-path (per-driver) callbacks. 199171095Ssam * Implemented by ULD and provided to HAL via 200171095Ssam * xge_hal_driver_initialize(). 201171095Ssam * Note that these callbacks are not mandatory: HAL will not invoke 202171095Ssam * a callback if NULL is specified. 203171095Ssam * 204171095Ssam * Note that in addition to those, there are curently 2 per-channel callbacks 205171095Ssam * (completion and abort) specified at channel open time 206171095Ssam * via xge_hal_channel_open(). 207171095Ssam * 208171095Ssam * See also: xge_hal_driver_initialize(). 209171095Ssam */ 210171095Ssamtypedef struct xge_hal_uld_cbs_t { 211173139Srwatson xge_uld_link_up_f link_up; 212173139Srwatson xge_uld_link_down_f link_down; 213173139Srwatson xge_uld_crit_err_f crit_err; 214173139Srwatson xge_uld_event_f event; 215173139Srwatson xge_uld_event_queued_f event_queued; 216171095Ssam xge_uld_before_device_poll_f before_device_poll; 217173139Srwatson xge_uld_after_device_poll_f after_device_poll; 218173139Srwatson xge_uld_sched_timer_cb_f sched_timer; 219173139Srwatson xge_uld_xpak_alarm_log_f xpak_alarm_log; 220171095Ssam} xge_hal_uld_cbs_t; 221171095Ssam 222171095Ssam/** 223171095Ssam * struct xge_hal_driver_t - Represents HAL object. 224171095Ssam * @config: HAL configuration. 225171095Ssam * @devices: List of all PCI-enumerated Xframe devices in the system. 226171095Ssam * A single xge_hal_driver_t instance contains zero or more 227171095Ssam * Xframe devices. 228171095Ssam * @devices_lock: Lock to protect %devices when inserting/removing. 229171095Ssam * @is_initialized: True if HAL is initialized; false otherwise. 230171095Ssam * @uld_callbacks: Upper-layer driver callbacks. See xge_hal_uld_cbs_t{}. 231171095Ssam * @debug_module_mask: 32bit mask that defines which components of the 232171095Ssam * driver are to be traced. The trace-able components are: 233173139Srwatson * XGE_COMPONENT_HAL_CONFIG 0x1 234173139Srwatson * XGE_COMPONENT_HAL_FIFO 0x2 235173139Srwatson * XGE_COMPONENT_HAL_RING 0x4 236173139Srwatson * XGE_COMPONENT_HAL_CHANNEL 0x8 237173139Srwatson * XGE_COMPONENT_HAL_DEVICE 0x10 238173139Srwatson * XGE_COMPONENT_HAL_MM 0x20 239173139Srwatson * XGE_COMPONENT_HAL_QUEUE 0x40 240173139Srwatson * XGE_COMPONENT_HAL_STATS 0x100 241173139Srwatson * XGE_COMPONENT_OSDEP 0x1000 242173139Srwatson * XGE_COMPONENT_LL 0x2000 243173139Srwatson * XGE_COMPONENT_TOE 0x4000 244173139Srwatson * XGE_COMPONENT_RDMA 0x8000 245173139Srwatson * XGE_COMPONENT_ALL 0xffffffff 246171095Ssam * The @debug_module_mask allows to switch off and on tracing at runtime. 247171095Ssam * In addition, the traces for the same trace-able components can be 248171095Ssam * compiled out, based on the same mask provided via Makefile. 249171095Ssam * @debug_level: See xge_debug_level_e{}. 250171095Ssam * 251171095Ssam * HAL (driver) object. There is a single instance of this structure per HAL. 252171095Ssam */ 253171095Ssamtypedef struct xge_hal_driver_t { 254173139Srwatson xge_hal_driver_config_t config; 255171095Ssam int is_initialized; 256171095Ssam xge_hal_uld_cbs_t uld_callbacks; 257173139Srwatson u32 debug_module_mask; 258173139Srwatson int debug_level; 259171095Ssam} xge_hal_driver_t; 260171095Ssam 261171095Ssamextern xge_hal_driver_t *g_xge_hal_driver; 262171095Ssam 263171095Ssamstatic inline int 264171095Ssamxge_hal_driver_is_initialized(void) { 265173139Srwatson return g_xge_hal_driver->is_initialized; 266171095Ssam} 267171095Ssam 268171095Ssamstatic inline int 269171095Ssamxge_hal_driver_debug_module_mask(void) 270171095Ssam{ 271171095Ssam return g_xge_hal_driver->debug_module_mask; 272171095Ssam} 273171095Ssam 274171095Ssamstatic inline void 275171095Ssamxge_hal_driver_debug_module_mask_set(u32 new_mask) 276171095Ssam{ 277171095Ssam#if (defined(XGE_DEBUG_TRACE_MASK) && XGE_DEBUG_TRACE_MASK > 0) || \ 278173139Srwatson (defined(XGE_DEBUG_ERR_MASK) && XGE_DEBUG_ERR_MASK > 0) 279171095Ssam g_xge_hal_driver->debug_module_mask = new_mask; 280171095Ssam g_module_mask = (unsigned long *)&g_xge_hal_driver->debug_module_mask; 281171095Ssam#endif 282171095Ssam} 283171095Ssam 284171095Ssamstatic inline int 285171095Ssamxge_hal_driver_debug_level(void) { return g_xge_hal_driver->debug_level; } 286171095Ssam 287171095Ssamstatic inline void 288171095Ssamxge_hal_driver_debug_level_set(int new_level) 289171095Ssam{ 290171095Ssam#if (defined(XGE_DEBUG_TRACE_MASK) && XGE_DEBUG_TRACE_MASK > 0) || \ 291173139Srwatson (defined(XGE_DEBUG_ERR_MASK) && XGE_DEBUG_ERR_MASK > 0) 292171095Ssam g_xge_hal_driver->debug_level = new_level; 293171095Ssam g_level = &g_xge_hal_driver->debug_level; 294171095Ssam#endif 295171095Ssam} 296171095Ssam 297171095Ssamxge_hal_status_e xge_hal_driver_initialize(xge_hal_driver_config_t *config, 298173139Srwatson xge_hal_uld_cbs_t *uld_callbacks); 299171095Ssam 300171095Ssamvoid xge_hal_driver_terminate(void); 301171095Ssam 302171095Ssam#ifdef XGE_TRACE_INTO_CIRCULAR_ARR 303171095Ssamvoid xge_hal_driver_tracebuf_dump(void); 304171095Ssam 305171095Ssamxge_hal_status_e 306171095Ssamxge_hal_driver_tracebuf_read(int bufsize, char *retbuf, int *retsize); 307171095Ssam#else 308171095Ssam#define xge_hal_driver_tracebuf_dump() 309171095Ssam#define xge_hal_driver_tracebuf_read(a, b, c) (0); 310171095Ssam#endif 311171095Ssam 312171095Ssam__EXTERN_END_DECLS 313171095Ssam 314171095Ssam#endif /* XGE_HAL_DRIVER_H */ 315