/* * vxge_hal_driver_initialize - Initialize HAL. * @config: HAL configuration, see vxge_hal_driver_config_t {}. * @uld_callbacks: Upper-layer driver callbacks, e.g. link-up. * * HAL initialization entry point. Not to confuse with device initialization * (note that HAL "contains" zero or more X3100 devices). * * Returns: VXGE_HAL_OK - success; * VXGE_HAL_ERR_BAD_DRIVER_CONFIG - Driver configuration params invalid. * * See also: vxge_hal_device_initialize(), vxge_hal_status_e {}, * vxge_hal_uld_cbs_t {}. */ vxge_hal_status_e vxge_hal_driver_initialize( vxge_hal_driver_config_t *config, vxge_hal_uld_cbs_t *uld_callbacks) { vxge_hal_status_e status; g_vxge_hal_driver = &g_driver; if ((status = vxge_hal_driver_config_check(config)) != VXGE_HAL_OK) return (status); vxge_os_memzero(g_vxge_hal_driver, sizeof(__hal_driver_t)); /* apply config */ vxge_os_memcpy(&g_vxge_hal_driver->config, config, sizeof(vxge_hal_driver_config_t)); /* apply ULD callbacks */ vxge_os_memcpy(&g_vxge_hal_driver->uld_callbacks, uld_callbacks, sizeof(vxge_hal_uld_cbs_t)); vxge_hal_driver_debug_set(config->level); g_vxge_hal_driver->is_initialized = 1; return (VXGE_HAL_OK); }
/* * __hal_mempool_grow * * Will resize mempool up to %num_allocate value. */ static vxge_hal_status_e __hal_mempool_grow( vxge_hal_mempool_t *mempool, u32 num_allocate, u32 *num_allocated) { u32 i, j, k, item_index, is_last; u32 first_time = mempool->memblocks_allocated == 0 ? 1 : 0; u32 n_items = mempool->items_per_memblock; u32 start_block_idx = mempool->memblocks_allocated; u32 end_block_idx = mempool->memblocks_allocated + num_allocate; __hal_device_t *hldev; vxge_assert(mempool != NULL); hldev = (__hal_device_t *) mempool->devh; vxge_hal_trace_log_mm("==> %s:%s:%d", __FILE__, __func__, __LINE__); vxge_hal_trace_log_mm( "mempool = 0x"VXGE_OS_STXFMT", num_allocate = %d, " "num_allocated = 0x"VXGE_OS_STXFMT, (ptr_t) mempool, num_allocate, (ptr_t) num_allocated); *num_allocated = 0; if (end_block_idx > mempool->memblocks_max) { vxge_hal_err_log_mm("%s", "__hal_mempool_grow: can grow anymore"); vxge_hal_trace_log_mm("<== %s:%s:%d Result: %d", __FILE__, __func__, __LINE__, VXGE_HAL_ERR_OUT_OF_MEMORY); return (VXGE_HAL_ERR_OUT_OF_MEMORY); } for (i = start_block_idx; i < end_block_idx; i++) { void *the_memblock; vxge_hal_mempool_dma_t *dma_object; is_last = ((end_block_idx - 1) == i); dma_object = mempool->memblocks_dma_arr + i; /* * allocate memblock's private part. Each DMA memblock * has a space allocated for item's private usage upon * mempool's user request. Each time mempool grows, it will * allocate new memblock and its private part at once. * This helps to minimize memory usage a lot. */ mempool->memblocks_priv_arr[i] = vxge_os_malloc( ((__hal_device_t *) mempool->devh)->header.pdev, mempool->items_priv_size * n_items); if (mempool->memblocks_priv_arr[i] == NULL) { vxge_hal_err_log_mm("memblock_priv[%d]: \ out of virtual memory, " "requested %d(%d:%d) bytes", i, mempool->items_priv_size * n_items, mempool->items_priv_size, n_items); vxge_hal_trace_log_mm("<== %s:%s:%d Result: %d", __FILE__, __func__, __LINE__, VXGE_HAL_ERR_OUT_OF_MEMORY); return (VXGE_HAL_ERR_OUT_OF_MEMORY); } vxge_os_memzero(mempool->memblocks_priv_arr[i], mempool->items_priv_size * n_items); /* allocate DMA-capable memblock */ mempool->memblocks_arr[i] = __hal_blockpool_malloc(mempool->devh, mempool->memblock_size, &dma_object->addr, &dma_object->handle, &dma_object->acc_handle); if (mempool->memblocks_arr[i] == NULL) { vxge_os_free( ((__hal_device_t *) mempool->devh)->header.pdev, mempool->memblocks_priv_arr[i], mempool->items_priv_size * n_items); vxge_hal_err_log_mm("memblock[%d]: \ out of DMA memory", i); vxge_hal_trace_log_mm("<== %s:%s:%d Result: %d", __FILE__, __func__, __LINE__, VXGE_HAL_ERR_OUT_OF_MEMORY); return (VXGE_HAL_ERR_OUT_OF_MEMORY); }