2 * Copyright(c) 2002-2011 Exar Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification are permitted provided the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * 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 * 3. Neither the name of the Exar Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include <dev/vxge/vxgehal/vxgehal.h>
35 static __hal_driver_t g_driver;
36 __hal_driver_t *g_vxge_hal_driver;
38 #if defined(VXGE_OS_MEMORY_CHECK)
39 vxge_os_malloc_t g_malloc_arr[VXGE_OS_MALLOC_CNT_MAX];
45 * Runtime tracing support
50 * vxge_hal_driver_initialize - Initialize HAL.
51 * @config: HAL configuration, see vxge_hal_driver_config_t {}.
52 * @uld_callbacks: Upper-layer driver callbacks, e.g. link-up.
54 * HAL initialization entry point. Not to confuse with device initialization
55 * (note that HAL "contains" zero or more X3100 devices).
57 * Returns: VXGE_HAL_OK - success;
58 * VXGE_HAL_ERR_BAD_DRIVER_CONFIG - Driver configuration params invalid.
60 * See also: vxge_hal_device_initialize(), vxge_hal_status_e {},
61 * vxge_hal_uld_cbs_t {}.
64 vxge_hal_driver_initialize(
65 vxge_hal_driver_config_t *config,
66 vxge_hal_uld_cbs_t *uld_callbacks)
68 vxge_hal_status_e status;
69 g_vxge_hal_driver = &g_driver;
71 if ((status = vxge_hal_driver_config_check(config)) != VXGE_HAL_OK)
74 vxge_os_memzero(g_vxge_hal_driver, sizeof(__hal_driver_t));
77 vxge_os_memcpy(&g_vxge_hal_driver->config, config,
78 sizeof(vxge_hal_driver_config_t));
80 /* apply ULD callbacks */
81 vxge_os_memcpy(&g_vxge_hal_driver->uld_callbacks, uld_callbacks,
82 sizeof(vxge_hal_uld_cbs_t));
84 vxge_hal_driver_debug_set(config->level);
86 g_vxge_hal_driver->is_initialized = 1;
92 * vxge_hal_driver_terminate - Terminate HAL.
94 * HAL termination entry point.
96 * See also: vxge_hal_device_terminate().
99 vxge_hal_driver_terminate(void)
101 g_vxge_hal_driver->is_initialized = 0;
103 g_vxge_hal_driver = NULL;
105 #if defined(VXGE_OS_MEMORY_CHECK)
109 vxge_os_printf("OSPAL: max g_malloc_cnt %d\n", g_malloc_cnt);
110 for (i = 0; i < g_malloc_cnt; i++) {
111 if (g_malloc_arr[i].ptr != NULL) {
112 vxge_os_printf("OSPAL: memory leak detected at "
113 "%s:%lu:"VXGE_OS_LLXFMT":%lu\n",
114 g_malloc_arr[i].file,
115 g_malloc_arr[i].line,
116 (u64) (ptr_t) g_malloc_arr[i].ptr,
117 g_malloc_arr[i].size);
122 vxge_os_printf("OSPAL: %d memory leaks detected\n",
125 vxge_os_println("OSPAL: no memory leaks detected\n");
132 * vxge_hal_driver_debug_set - Set the debug module, level and timestamp
133 * @level: Debug level as defined in enum vxge_debug_level_e
135 * This routine is used to dynamically change the debug output
138 vxge_hal_driver_debug_set(
139 vxge_debug_level_e level)
141 g_vxge_hal_driver->debug_level = level;
148 g_debug_level |= VXGE_TRACE;
152 g_debug_level |= VXGE_INFO;
156 g_debug_level |= VXGE_ERR;
165 * vxge_hal_driver_debug_get - Get the debug level
167 * This routine returns the current debug level set
170 vxge_hal_driver_debug_get(void)
172 return (g_vxge_hal_driver->debug_level);