a23fd118e437af0a7877dd313db8fdaa3537c675yl * CDDL HEADER START
a23fd118e437af0a7877dd313db8fdaa3537c675yl * The contents of this file are subject to the terms of the
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Common Development and Distribution License (the "License").
a23fd118e437af0a7877dd313db8fdaa3537c675yl * You may not use this file except in compliance with the License.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a23fd118e437af0a7877dd313db8fdaa3537c675yl * See the License for the specific language governing permissions
a23fd118e437af0a7877dd313db8fdaa3537c675yl * and limitations under the License.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * When distributing Covered Code, include this CDDL HEADER in each
a23fd118e437af0a7877dd313db8fdaa3537c675yl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * If applicable, add the following below this CDDL HEADER, with the
a23fd118e437af0a7877dd313db8fdaa3537c675yl * fields enclosed by brackets "[]" replaced with your own identifying
a23fd118e437af0a7877dd313db8fdaa3537c675yl * information: Portions Copyright [yyyy] [name of copyright owner]
a23fd118e437af0a7877dd313db8fdaa3537c675yl * CDDL HEADER END
8347601bcb0a439f6e50fc36b4039a73d08700e1yl * Copyright (c) 2002-2006 Neterion, Inc.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * __hal_mempool_grow
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Will resize mempool up to %num_allocate value.
a23fd118e437af0a7877dd313db8fdaa3537c675yl__hal_mempool_grow(xge_hal_mempool_t *mempool, int num_allocate,
a23fd118e437af0a7877dd313db8fdaa3537c675yl int i, first_time = mempool->memblocks_allocated == 0 ? 1 : 0;
a23fd118e437af0a7877dd313db8fdaa3537c675yl "__hal_mempool_grow: can grow anymore");
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* allocate DMA-capable memblock */
a23fd118e437af0a7877dd313db8fdaa3537c675yl mempool->memblocks_arr[i] = xge_os_dma_malloc(mempool->pdev,
a23fd118e437af0a7877dd313db8fdaa3537c675yl "memblock[%d]: out of DMA memory", i);
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* allocate memblock's private part. Each DMA memblock
a23fd118e437af0a7877dd313db8fdaa3537c675yl * has a space allocated for item's private usage upon
a23fd118e437af0a7877dd313db8fdaa3537c675yl * mempool's user request. Each time mempool grows, it will
a23fd118e437af0a7877dd313db8fdaa3537c675yl * allocate new memblock and its private part at once.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * This helps to minimize memory usage a lot. */
a23fd118e437af0a7877dd313db8fdaa3537c675yl mempool->memblocks_priv_arr[i] = xge_os_malloc(mempool->pdev,
a23fd118e437af0a7877dd313db8fdaa3537c675yl "memblock_priv[%d]: out of virtual memory, "
a23fd118e437af0a7877dd313db8fdaa3537c675yl "requested %d(%d:%d) bytes", i,
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* map memblock to physical memory */
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_os_free(mempool->pdev, mempool->memblocks_priv_arr[i],
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* fill the items hash array */
a23fd118e437af0a7877dd313db8fdaa3537c675yl for (j=0; j<n_items; j++) {
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* let caller to do more job on each item */
a23fd118e437af0a7877dd313db8fdaa3537c675yl for (k=0; k<j; k++) {
8347601bcb0a439f6e50fc36b4039a73d08700e1yl "dma_addr 0x"XGE_OS_LLXFMT, i, mempool->memblock_size / 1024,
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* increment actual number of allocated memblocks */
a23fd118e437af0a7877dd313db8fdaa3537c675yl * xge_hal_mempool_create
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @memblock_size:
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @items_initial:
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @items_max:
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @item_size:
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @item_func:
a23fd118e437af0a7877dd313db8fdaa3537c675yl * This function will create memory pool object. Pool may grow but will
a23fd118e437af0a7877dd313db8fdaa3537c675yl * never shrink. Pool consists of number of dynamically allocated blocks
a23fd118e437af0a7877dd313db8fdaa3537c675yl * with size enough to hold %items_initial number of items. Memory is
a23fd118e437af0a7877dd313db8fdaa3537c675yl * DMA-able but client must map/unmap before interoperating with the device.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * See also: xge_os_dma_map(), xge_hal_dma_unmap(), xge_hal_status_e{}.
a23fd118e437af0a7877dd313db8fdaa3537c675yl__hal_mempool_create(pci_dev_h pdev, int memblock_size, int item_size,
a23fd118e437af0a7877dd313db8fdaa3537c675yl "memblock_size %d < item_size %d: misconfiguration",
a23fd118e437af0a7877dd313db8fdaa3537c675yl mempool->memblocks_max = (items_max + mempool->items_per_memblock - 1) /
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* allocate array of memblocks */
8347601bcb0a439f6e50fc36b4039a73d08700e1yl mempool->memblocks_arr = (void ** ) xge_os_malloc(mempool->pdev,
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_debug_mm(XGE_ERR, "memblocks_arr allocation failure");
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* allocate array of private parts of items per memblocks */
8347601bcb0a439f6e50fc36b4039a73d08700e1yl mempool->memblocks_priv_arr = (void **) xge_os_malloc(mempool->pdev,
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_debug_mm(XGE_ERR, "memblocks_priv_arr allocation failure");
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* allocate array of memblocks DMA objects */
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_debug_mm(XGE_ERR, "memblocks_dma_arr allocation failure");
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* allocate hash array of items */
8347601bcb0a439f6e50fc36b4039a73d08700e1yl mempool->items_arr = (void **) xge_os_malloc(mempool->pdev,
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_os_memzero(mempool->items_arr, sizeof(void *) * mempool->items_max);
8347601bcb0a439f6e50fc36b4039a73d08700e1yl mempool->shadow_items_arr = (void **) xge_os_malloc(mempool->pdev,
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_debug_mm(XGE_ERR, "shadow_items_arr allocation failure");
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* calculate initial number of memblocks */
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* pre-allocate the mempool */
a23fd118e437af0a7877dd313db8fdaa3537c675yl status = __hal_mempool_grow(mempool, memblocks_to_allocate, &allocated);
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_os_memcpy(mempool->shadow_items_arr, mempool->items_arr,
a23fd118e437af0a7877dd313db8fdaa3537c675yl "total: allocated %dk of DMA-capable memory",
a23fd118e437af0a7877dd313db8fdaa3537c675yl * xge_hal_mempool_destroy
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* to skip last partially filled(if any) memblock */
a23fd118e437af0a7877dd313db8fdaa3537c675yl /* let caller to do more job on each item */
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_os_free(mempool->pdev, mempool->memblocks_priv_arr[i],
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_os_dma_free(mempool->pdev, mempool->memblocks_arr[i],
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_os_free(mempool->pdev, mempool->items_arr, sizeof(void*) *