xref: /trueos/sys/dev/vxge/vxgehal/vxgehal-blockpool.h (revision 8fe640108653f13042f1b15213769e338aa524f6)
1 /*-
2  * Copyright(c) 2002-2011 Exar Corp.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification are permitted provided the following conditions are met:
7  *
8  *    1. Redistributions of source code must retain the above copyright notice,
9  *       this list of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
30  */
31 /*$FreeBSD$*/
32 
33 #ifndef	VXGE_HAL_BLOCKPOOL_H
34 #define	VXGE_HAL_BLOCKPOOL_H
35 
36 __EXTERN_BEGIN_DECLS
37 
38 /*
39  * struct __hal_blockpool_entry_t - Block private data structure
40  * @item: List header used to link.
41  * @length: Length of the block
42  * @memblock: Virtual address block
43  * @dma_addr: DMA Address of the block.
44  * @dma_handle: DMA handle of the block.
45  * @acc_handle: DMA acc handle
46  *
47  * Block is allocated with a header to put the blocks into list.
48  *
49  */
50 typedef struct __hal_blockpool_entry_t {
51 	vxge_list_t item;
52 	u32	length;
53 	void   *memblock;
54 	dma_addr_t dma_addr;
55 	pci_dma_h dma_handle;
56 	pci_dma_acc_h acc_handle;
57 } __hal_blockpool_entry_t;
58 
59 /*
60  * struct __hal_blockpool_t - Block Pool
61  * @hldev: HAL device
62  * @block_size: size of each block.
63  * @Pool_size: Number of blocks in the pool
64  * @pool_incr: Number of blocks to be requested/freed at a time from OS
65  * @pool_min: Minimum number of block below which to request additional blocks
66  * @pool_max: Maximum number of blocks above which to free additional blocks
67  * @req_out: Number of block requests with OS out standing
68  * @dma_flags: DMA flags
69  * @free_block_list: List of free blocks
70  * @pool_lock: Spin lock for the pool
71  *
72  * Block pool contains the DMA blocks preallocated.
73  *
74  */
75 typedef struct __hal_blockpool_t {
76 	vxge_hal_device_h hldev;
77 	u32	block_size;
78 	u32	pool_size;
79 	u32	pool_incr;
80 	u32	pool_min;
81 	u32	pool_max;
82 	u32	req_out;
83 	u32	dma_flags;
84 	vxge_list_t free_block_list;
85 	vxge_list_t free_entry_list;
86 
87 #if defined(VXGE_HAL_BP_POST) || defined(VXGE_HAL_BP_POST_IRQ)
88 	spinlock_t pool_lock;
89 #endif
90 
91 } __hal_blockpool_t;
92 
93 vxge_hal_status_e
94 __hal_blockpool_create(vxge_hal_device_h hldev,
95     __hal_blockpool_t *blockpool,
96     u32 pool_size,
97     u32 pool_incr,
98     u32 pool_min,
99     u32 pool_max);
100 
101 void
102 __hal_blockpool_destroy(__hal_blockpool_t *blockpool);
103 
104 __hal_blockpool_entry_t *
105 __hal_blockpool_block_allocate(vxge_hal_device_h hldev,
106     u32 size);
107 
108 void
109 __hal_blockpool_block_free(vxge_hal_device_h hldev,
110     __hal_blockpool_entry_t *entry);
111 
112 void *
113 __hal_blockpool_malloc(vxge_hal_device_h hldev,
114     u32 size,
115     dma_addr_t *dma_addr,
116     pci_dma_h *dma_handle,
117     pci_dma_acc_h *acc_handle);
118 
119 void
120 __hal_blockpool_free(vxge_hal_device_h hldev,
121     void *memblock,
122     u32 size,
123     dma_addr_t *dma_addr,
124     pci_dma_h *dma_handle,
125     pci_dma_acc_h *acc_handle);
126 
127 vxge_hal_status_e
128 __hal_blockpool_list_allocate(vxge_hal_device_h hldev,
129     vxge_list_t *blocklist, u32 count);
130 
131 void
132 __hal_blockpool_list_free(vxge_hal_device_h hldev,
133     vxge_list_t *blocklist);
134 
135 __EXTERN_END_DECLS
136 
137 #endif	/* VXGE_HAL_BLOCKPOOL_H */
138