1a23fd118Syl /* 2a23fd118Syl * CDDL HEADER START 3a23fd118Syl * 4a23fd118Syl * The contents of this file are subject to the terms of the 5a23fd118Syl * Common Development and Distribution License (the "License"). 6a23fd118Syl * You may not use this file except in compliance with the License. 7a23fd118Syl * 8a23fd118Syl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9a23fd118Syl * or http://www.opensolaris.org/os/licensing. 10a23fd118Syl * See the License for the specific language governing permissions 11a23fd118Syl * and limitations under the License. 12a23fd118Syl * 13a23fd118Syl * When distributing Covered Code, include this CDDL HEADER in each 14a23fd118Syl * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15a23fd118Syl * If applicable, add the following below this CDDL HEADER, with the 16a23fd118Syl * fields enclosed by brackets "[]" replaced with your own identifying 17a23fd118Syl * information: Portions Copyright [yyyy] [name of copyright owner] 18a23fd118Syl * 19a23fd118Syl * CDDL HEADER END 20a23fd118Syl * 21*8347601bSyl * Copyright (c) 2002-2006 Neterion, Inc. 22a23fd118Syl */ 23a23fd118Syl 24a23fd118Syl #ifndef XGE_HAL_MM_H 25a23fd118Syl #define XGE_HAL_MM_H 26a23fd118Syl 27a23fd118Syl #include "xge-os-pal.h" 28a23fd118Syl #include "xge-debug.h" 29a23fd118Syl #include "xgehal-types.h" 30a23fd118Syl #include "xgehal-driver.h" 31a23fd118Syl 32*8347601bSyl __EXTERN_BEGIN_DECLS 33*8347601bSyl 34a23fd118Syl typedef void* xge_hal_mempool_h; 35a23fd118Syl 36a23fd118Syl /* 37a23fd118Syl * struct xge_hal_mempool_dma_t - Represents DMA objects passed to the 38a23fd118Syl caller. 39a23fd118Syl */ 40a23fd118Syl typedef struct xge_hal_mempool_dma_t { 41a23fd118Syl dma_addr_t addr; 42a23fd118Syl pci_dma_h handle; 43a23fd118Syl pci_dma_acc_h acc_handle; 44a23fd118Syl } xge_hal_mempool_dma_t; 45a23fd118Syl 46a23fd118Syl /* 47a23fd118Syl * xge_hal_mempool_item_f - Mempool item alloc/free callback 48a23fd118Syl * @mempoolh: Memory pool handle. 49a23fd118Syl * @item: Item that gets allocated or freed. 50a23fd118Syl * @index: Item's index in the memory pool. 51a23fd118Syl * @is_last: True, if this item is the last one in the pool; false - otherwise. 52a23fd118Syl * userdat: Per-pool user context. 53a23fd118Syl * 54a23fd118Syl * Memory pool allocation/deallocation callback. 55a23fd118Syl */ 56a23fd118Syl typedef xge_hal_status_e (*xge_hal_mempool_item_f) (xge_hal_mempool_h mempoolh, 57a23fd118Syl void *memblock, int memblock_index, 58a23fd118Syl xge_hal_mempool_dma_t *dma_object, void *item, 59a23fd118Syl int index, int is_last, void *userdata); 60a23fd118Syl 61a23fd118Syl /* 62a23fd118Syl * struct xge_hal_mempool_t - Memory pool. 63a23fd118Syl */ 64a23fd118Syl typedef struct xge_hal_mempool_t { 65a23fd118Syl xge_hal_mempool_item_f item_func_alloc; 66a23fd118Syl xge_hal_mempool_item_f item_func_free; 67a23fd118Syl void *userdata; 68a23fd118Syl void **memblocks_arr; 69a23fd118Syl void **memblocks_priv_arr; 70a23fd118Syl xge_hal_mempool_dma_t *memblocks_dma_arr; 71a23fd118Syl pci_dev_h pdev; 72a23fd118Syl int memblock_size; 73a23fd118Syl int memblocks_max; 74a23fd118Syl int memblocks_allocated; 75a23fd118Syl int item_size; 76a23fd118Syl int items_max; 77a23fd118Syl int items_initial; 78a23fd118Syl int items_current; 79a23fd118Syl int items_per_memblock; 80a23fd118Syl void **items_arr; 81a23fd118Syl void **shadow_items_arr; 82a23fd118Syl int items_priv_size; 83a23fd118Syl } xge_hal_mempool_t; 84a23fd118Syl 85a23fd118Syl /* 86a23fd118Syl * __hal_mempool_item - Returns pointer to the item in the mempool 87a23fd118Syl * items array. 88a23fd118Syl */ 89a23fd118Syl static inline void* 90a23fd118Syl __hal_mempool_item(xge_hal_mempool_t *mempool, int index) 91a23fd118Syl { 92a23fd118Syl return mempool->items_arr[index]; 93a23fd118Syl } 94a23fd118Syl 95a23fd118Syl /* 96a23fd118Syl * __hal_mempool_item_priv - will return pointer on per item private space 97a23fd118Syl */ 98a23fd118Syl static inline void* 99a23fd118Syl __hal_mempool_item_priv(xge_hal_mempool_t *mempool, int memblock_idx, 100a23fd118Syl void *item, int *memblock_item_idx) 101a23fd118Syl { 102a23fd118Syl ptrdiff_t offset; 103a23fd118Syl void *memblock = mempool->memblocks_arr[memblock_idx]; 104a23fd118Syl 105a23fd118Syl xge_assert(memblock); 106a23fd118Syl 107a23fd118Syl offset = (int)((char * )item - (char *)memblock); 108a23fd118Syl xge_assert(offset >= 0 && offset < mempool->memblock_size); 109a23fd118Syl 110a23fd118Syl (*memblock_item_idx) = (int) offset / mempool->item_size; 111a23fd118Syl xge_assert((*memblock_item_idx) < mempool->items_per_memblock); 112a23fd118Syl 113a23fd118Syl return (char*)mempool->memblocks_priv_arr[memblock_idx] + 114a23fd118Syl (*memblock_item_idx) * mempool->items_priv_size; 115a23fd118Syl } 116a23fd118Syl 117a23fd118Syl /* 118a23fd118Syl * __hal_mempool_items_arr - will return pointer to the items array in the 119a23fd118Syl * mempool. 120a23fd118Syl */ 121a23fd118Syl static inline void* 122a23fd118Syl __hal_mempool_items_arr(xge_hal_mempool_t *mempool) 123a23fd118Syl { 124a23fd118Syl return mempool->items_arr; 125a23fd118Syl } 126a23fd118Syl 127a23fd118Syl /* 128a23fd118Syl * __hal_mempool_memblock - will return pointer to the memblock in the 129a23fd118Syl * mempool memblocks array. 130a23fd118Syl */ 131a23fd118Syl static inline void* 132a23fd118Syl __hal_mempool_memblock(xge_hal_mempool_t *mempool, int memblock_idx) 133a23fd118Syl { 134a23fd118Syl xge_assert(mempool->memblocks_arr[memblock_idx]); 135a23fd118Syl return mempool->memblocks_arr[memblock_idx]; 136a23fd118Syl } 137a23fd118Syl 138a23fd118Syl /* 139a23fd118Syl * __hal_mempool_memblock_dma - will return pointer to the dma block 140a23fd118Syl * corresponds to the memblock(identified by memblock_idx) in the mempool. 141a23fd118Syl */ 142a23fd118Syl static inline xge_hal_mempool_dma_t* 143a23fd118Syl __hal_mempool_memblock_dma(xge_hal_mempool_t *mempool, int memblock_idx) 144a23fd118Syl { 145a23fd118Syl return mempool->memblocks_dma_arr + memblock_idx; 146a23fd118Syl } 147a23fd118Syl 148a23fd118Syl xge_hal_status_e __hal_mempool_grow(xge_hal_mempool_t *mempool, 149a23fd118Syl int num_allocate, int *num_allocated); 150a23fd118Syl 151a23fd118Syl xge_hal_mempool_t* __hal_mempool_create(pci_dev_h pdev, int memblock_size, 152a23fd118Syl int item_size, int private_size, int items_initial, 153a23fd118Syl int items_max, xge_hal_mempool_item_f item_func_alloc, 154a23fd118Syl xge_hal_mempool_item_f item_func_free, void *userdata); 155a23fd118Syl 156a23fd118Syl void __hal_mempool_destroy(xge_hal_mempool_t *mempool); 157a23fd118Syl 158*8347601bSyl 159*8347601bSyl #ifdef XGEHAL_RNIC 160*8347601bSyl 161*8347601bSyl xge_hal_status_e 162*8347601bSyl __hal_allocate_dma_register(pci_dev_h pdev, int size, 163*8347601bSyl void **dma_register, xge_hal_mempool_dma_t *dma_object); 164*8347601bSyl 165*8347601bSyl void 166*8347601bSyl __hal_free_dma_register(pci_dev_h pdev, int size, 167*8347601bSyl void *dma_register, xge_hal_mempool_dma_t *dma_object); 168*8347601bSyl 169*8347601bSyl #endif 170*8347601bSyl 171*8347601bSyl __EXTERN_END_DECLS 172*8347601bSyl 173a23fd118Syl #endif /* XGE_HAL_MM_H */ 174