4 * @Abstract: Buf pool implementation: static version
9 * Copyright (c) 2007 Atheros Communications Inc.
10 * All rights reserved.
15 #include <Magpie_api.h>
16 #include <cmnos_api.h>
17 #include <buf_pool_api.h>
19 #include <vdesc_api.h>
20 #include <adf_os_mem.h>
22 #include "buf_pool_static.h"
24 LOCAL htc_handle_t _buf_pool_static_init(adf_net_handle_t handle);
25 LOCAL void _buf_pool_static_create_pool(pool_handle_t handle, BUF_POOL_ID poolId, int nItems, int nSize);
26 LOCAL adf_nbuf_t _buf_pool_static_alloc_buf(pool_handle_t handle, BUF_POOL_ID poolId, int reserve);
27 LOCAL adf_nbuf_t _buf_pool_static_alloc_buf_align(pool_handle_t handle, BUF_POOL_ID poolId, int reserve, int align);
28 LOCAL void _buf_pool_static_free_buf(pool_handle_t handle, BUF_POOL_ID poolId, adf_nbuf_t buf);
29 LOCAL void _buf_pool_static_shutdown(pool_handle_t handle);
31 BUF_POOL_STATIC_CONTEXT g_poolCtx;
33 void buf_pool_module_install(struct buf_pool_api *pAPIs)
35 pAPIs->_init = _buf_pool_static_init;
36 pAPIs->_create_pool = _buf_pool_static_create_pool;
37 pAPIs->_alloc_buf = _buf_pool_static_alloc_buf;
38 pAPIs->_alloc_buf_align = _buf_pool_static_alloc_buf_align;
39 pAPIs->_free_buf = _buf_pool_static_free_buf;
40 pAPIs->_shutdown = _buf_pool_static_shutdown;
43 LOCAL pool_handle_t _buf_pool_static_init(adf_os_handle_t handle)
48 for(i=0; i < POOL_ID_MAX; i++) {
49 g_poolCtx.bufQ[i] = NULL;
54 BUF_POOL_STATIC_CONTEXT *ctx;
56 //ctx = (BUF_POOL_static_CONTEXT *)A_ALLOCRAM(sizeof(BUF_POOL_static_CONTEXT));
57 ctx = (BUF_POOL_STATIC_CONTEXT *)adf_os_mem_alloc(sizeof(BUF_POOL_STATIC_CONTEXT));
58 ctx->NetHandle = handle;
64 LOCAL void _buf_pool_static_shutdown(pool_handle_t handle)
66 // SHALL NOT BE USED in FW
69 LOCAL void _buf_pool_static_create_pool(pool_handle_t handle, BUF_POOL_ID poolId, int nItems, int nSize)
75 //BUF_POOL_STATIC_CONTEXT *ctx = (BUF_POOL_STATIC_CONTEXT *)handle;
77 for ( i = 0; i < nItems; i++) {
78 buf = VBUF_alloc_vbuf();
79 desc = VDESC_alloc_vdesc();
81 desc->buf_addr = (A_UINT8 *)adf_os_mem_alloc(nSize);
82 desc->buf_size = nSize;
83 desc->data_offset = 0;
87 buf->desc_list = desc;
89 if ( g_poolCtx.bufQ[poolId] == NULL ) {
90 g_poolCtx.bufQ[poolId] = buf;
92 buf->next_buf = g_poolCtx.bufQ[poolId];
93 g_poolCtx.bufQ[poolId] = buf;
98 LOCAL adf_nbuf_t _buf_pool_static_alloc_buf(pool_handle_t handle, BUF_POOL_ID poolId, int reserve)
102 buf = g_poolCtx.bufQ[poolId];
104 g_poolCtx.bufQ[poolId] = buf->next_buf;
106 buf->next_buf = NULL;
107 buf->desc_list->data_offset = reserve;
108 buf->desc_list->data_size = 0;
115 LOCAL adf_nbuf_t _buf_pool_static_alloc_buf_align(pool_handle_t handle, BUF_POOL_ID poolId, int reserve, int align)
117 return _buf_pool_static_alloc_buf(handle, poolId, reserve);
120 LOCAL void _buf_pool_static_free_buf(pool_handle_t handle, BUF_POOL_ID poolId, adf_nbuf_t buf)
122 if ( g_poolCtx.bufQ[poolId] == NULL ) {
123 g_poolCtx.bufQ[poolId] = buf;
125 buf->next_buf = g_poolCtx.bufQ[poolId];
126 g_poolCtx.bufQ[poolId] = buf;