vxgehal-blockpool.h revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright(c) 2002-2011 Exar Corp.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification are permitted provided the following conditions are met:
9 *
10 *    1. Redistributions of source code must retain the above copyright notice,
11 *       this list of conditions and the following disclaimer.
12 *
13 *    2. Redistributions in binary form must reproduce the above copyright
14 *       notice, this list of conditions and the following disclaimer in the
15 *       documentation and/or other materials provided with the distribution.
16 *
17 *    3. Neither the name of the Exar Corporation nor the names of its
18 *       contributors may be used to endorse or promote products derived from
19 *       this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33/*$FreeBSD: stable/11/sys/dev/vxge/vxgehal/vxgehal-blockpool.h 330897 2018-03-14 03:19:51Z eadler $*/
34
35#ifndef	VXGE_HAL_BLOCKPOOL_H
36#define	VXGE_HAL_BLOCKPOOL_H
37
38__EXTERN_BEGIN_DECLS
39
40/*
41 * struct __hal_blockpool_entry_t - Block private data structure
42 * @item: List header used to link.
43 * @length: Length of the block
44 * @memblock: Virtual address block
45 * @dma_addr: DMA Address of the block.
46 * @dma_handle: DMA handle of the block.
47 * @acc_handle: DMA acc handle
48 *
49 * Block is allocated with a header to put the blocks into list.
50 *
51 */
52typedef struct __hal_blockpool_entry_t {
53	vxge_list_t item;
54	u32	length;
55	void   *memblock;
56	dma_addr_t dma_addr;
57	pci_dma_h dma_handle;
58	pci_dma_acc_h acc_handle;
59} __hal_blockpool_entry_t;
60
61/*
62 * struct __hal_blockpool_t - Block Pool
63 * @hldev: HAL device
64 * @block_size: size of each block.
65 * @Pool_size: Number of blocks in the pool
66 * @pool_incr: Number of blocks to be requested/freed at a time from OS
67 * @pool_min: Minimum number of block below which to request additional blocks
68 * @pool_max: Maximum number of blocks above which to free additional blocks
69 * @req_out: Number of block requests with OS out standing
70 * @dma_flags: DMA flags
71 * @free_block_list: List of free blocks
72 * @pool_lock: Spin lock for the pool
73 *
74 * Block pool contains the DMA blocks preallocated.
75 *
76 */
77typedef struct __hal_blockpool_t {
78	vxge_hal_device_h hldev;
79	u32	block_size;
80	u32	pool_size;
81	u32	pool_incr;
82	u32	pool_min;
83	u32	pool_max;
84	u32	req_out;
85	u32	dma_flags;
86	vxge_list_t free_block_list;
87	vxge_list_t free_entry_list;
88
89#if defined(VXGE_HAL_BP_POST) || defined(VXGE_HAL_BP_POST_IRQ)
90	spinlock_t pool_lock;
91#endif
92
93} __hal_blockpool_t;
94
95vxge_hal_status_e
96__hal_blockpool_create(vxge_hal_device_h hldev,
97    __hal_blockpool_t *blockpool,
98    u32 pool_size,
99    u32 pool_incr,
100    u32 pool_min,
101    u32 pool_max);
102
103void
104__hal_blockpool_destroy(__hal_blockpool_t *blockpool);
105
106__hal_blockpool_entry_t *
107__hal_blockpool_block_allocate(vxge_hal_device_h hldev,
108    u32 size);
109
110void
111__hal_blockpool_block_free(vxge_hal_device_h hldev,
112    __hal_blockpool_entry_t *entry);
113
114void *
115__hal_blockpool_malloc(vxge_hal_device_h hldev,
116    u32 size,
117    dma_addr_t *dma_addr,
118    pci_dma_h *dma_handle,
119    pci_dma_acc_h *acc_handle);
120
121void
122__hal_blockpool_free(vxge_hal_device_h hldev,
123    void *memblock,
124    u32 size,
125    dma_addr_t *dma_addr,
126    pci_dma_h *dma_handle,
127    pci_dma_acc_h *acc_handle);
128
129vxge_hal_status_e
130__hal_blockpool_list_allocate(vxge_hal_device_h hldev,
131    vxge_list_t *blocklist, u32 count);
132
133void
134__hal_blockpool_list_free(vxge_hal_device_h hldev,
135    vxge_list_t *blocklist);
136
137__EXTERN_END_DECLS
138
139#endif	/* VXGE_HAL_BLOCKPOOL_H */
140