1*0aeed3e9SJustin Hibbits /******************************************************************************
2*0aeed3e9SJustin Hibbits
3*0aeed3e9SJustin Hibbits � 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc.
4*0aeed3e9SJustin Hibbits All rights reserved.
5*0aeed3e9SJustin Hibbits
6*0aeed3e9SJustin Hibbits This is proprietary source code of Freescale Semiconductor Inc.,
7*0aeed3e9SJustin Hibbits and its use is subject to the NetComm Device Drivers EULA.
8*0aeed3e9SJustin Hibbits The copyright notice above does not evidence any actual or intended
9*0aeed3e9SJustin Hibbits publication of such source code.
10*0aeed3e9SJustin Hibbits
11*0aeed3e9SJustin Hibbits ALTERNATIVELY, redistribution and use in source and binary forms, with
12*0aeed3e9SJustin Hibbits or without modification, are permitted provided that the following
13*0aeed3e9SJustin Hibbits conditions are met:
14*0aeed3e9SJustin Hibbits * Redistributions of source code must retain the above copyright
15*0aeed3e9SJustin Hibbits notice, this list of conditions and the following disclaimer.
16*0aeed3e9SJustin Hibbits * Redistributions in binary form must reproduce the above copyright
17*0aeed3e9SJustin Hibbits notice, this list of conditions and the following disclaimer in the
18*0aeed3e9SJustin Hibbits documentation and/or other materials provided with the distribution.
19*0aeed3e9SJustin Hibbits * Neither the name of Freescale Semiconductor nor the
20*0aeed3e9SJustin Hibbits names of its contributors may be used to endorse or promote products
21*0aeed3e9SJustin Hibbits derived from this software without specific prior written permission.
22*0aeed3e9SJustin Hibbits
23*0aeed3e9SJustin Hibbits THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24*0aeed3e9SJustin Hibbits EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25*0aeed3e9SJustin Hibbits WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26*0aeed3e9SJustin Hibbits DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27*0aeed3e9SJustin Hibbits DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28*0aeed3e9SJustin Hibbits (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29*0aeed3e9SJustin Hibbits LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30*0aeed3e9SJustin Hibbits ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31*0aeed3e9SJustin Hibbits (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32*0aeed3e9SJustin Hibbits SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*0aeed3e9SJustin Hibbits *
34*0aeed3e9SJustin Hibbits
35*0aeed3e9SJustin Hibbits **************************************************************************/
36*0aeed3e9SJustin Hibbits /******************************************************************************
37*0aeed3e9SJustin Hibbits @File bm.c
38*0aeed3e9SJustin Hibbits
39*0aeed3e9SJustin Hibbits @Description BM
40*0aeed3e9SJustin Hibbits *//***************************************************************************/
41*0aeed3e9SJustin Hibbits #include "error_ext.h"
42*0aeed3e9SJustin Hibbits #include "std_ext.h"
43*0aeed3e9SJustin Hibbits #include "string_ext.h"
44*0aeed3e9SJustin Hibbits #include "mem_ext.h"
45*0aeed3e9SJustin Hibbits #include "core_ext.h"
46*0aeed3e9SJustin Hibbits
47*0aeed3e9SJustin Hibbits #include "bm.h"
48*0aeed3e9SJustin Hibbits
49*0aeed3e9SJustin Hibbits
50*0aeed3e9SJustin Hibbits #define __ERR_MODULE__ MODULE_BM
51*0aeed3e9SJustin Hibbits
52*0aeed3e9SJustin Hibbits
53*0aeed3e9SJustin Hibbits /****************************************/
54*0aeed3e9SJustin Hibbits /* static functions */
55*0aeed3e9SJustin Hibbits /****************************************/
56*0aeed3e9SJustin Hibbits
57*0aeed3e9SJustin Hibbits /* (De)Registration of depletion notification callbacks */
depletion_link(t_BmPool * p_BmPool)58*0aeed3e9SJustin Hibbits static void depletion_link(t_BmPool *p_BmPool)
59*0aeed3e9SJustin Hibbits {
60*0aeed3e9SJustin Hibbits t_BmPortal *p_Portal = (t_BmPortal *)p_BmPool->h_BmPortal;
61*0aeed3e9SJustin Hibbits
62*0aeed3e9SJustin Hibbits NCSW_PLOCK(p_Portal);
63*0aeed3e9SJustin Hibbits p_Portal->depletionPoolsTable[p_BmPool->bpid] = p_BmPool;
64*0aeed3e9SJustin Hibbits bm_isr_bscn_mask(p_Portal->p_BmPortalLow, (uint8_t)p_BmPool->bpid, 1);
65*0aeed3e9SJustin Hibbits PUNLOCK(p_Portal);
66*0aeed3e9SJustin Hibbits }
67*0aeed3e9SJustin Hibbits
depletion_unlink(t_BmPool * p_BmPool)68*0aeed3e9SJustin Hibbits static void depletion_unlink(t_BmPool *p_BmPool)
69*0aeed3e9SJustin Hibbits {
70*0aeed3e9SJustin Hibbits t_BmPortal *p_Portal = (t_BmPortal *)p_BmPool->h_BmPortal;
71*0aeed3e9SJustin Hibbits
72*0aeed3e9SJustin Hibbits NCSW_PLOCK(p_Portal);
73*0aeed3e9SJustin Hibbits p_Portal->depletionPoolsTable[p_BmPool->bpid] = NULL;
74*0aeed3e9SJustin Hibbits bm_isr_bscn_mask(p_Portal->p_BmPortalLow, (uint8_t)p_BmPool->bpid, 0);
75*0aeed3e9SJustin Hibbits PUNLOCK(p_Portal);
76*0aeed3e9SJustin Hibbits }
77*0aeed3e9SJustin Hibbits
BmPoolRelease(t_BmPool * p_BmPool,t_Handle h_BmPortal,struct bm_buffer * bufs,uint8_t num,uint32_t flags)78*0aeed3e9SJustin Hibbits static t_Error BmPoolRelease(t_BmPool *p_BmPool,
79*0aeed3e9SJustin Hibbits t_Handle h_BmPortal,
80*0aeed3e9SJustin Hibbits struct bm_buffer *bufs,
81*0aeed3e9SJustin Hibbits uint8_t num,
82*0aeed3e9SJustin Hibbits uint32_t flags)
83*0aeed3e9SJustin Hibbits {
84*0aeed3e9SJustin Hibbits ASSERT_COND(num && (num <= 8));
85*0aeed3e9SJustin Hibbits if (p_BmPool->flags & BMAN_POOL_FLAG_NO_RELEASE)
86*0aeed3e9SJustin Hibbits return ERROR_CODE(E_INVALID_VALUE);
87*0aeed3e9SJustin Hibbits
88*0aeed3e9SJustin Hibbits /* Without stockpile, this API is a pass-through to the h/w operation */
89*0aeed3e9SJustin Hibbits if (!(p_BmPool->flags & BMAN_POOL_FLAG_STOCKPILE))
90*0aeed3e9SJustin Hibbits return BmPortalRelease(h_BmPortal, p_BmPool->bpid, bufs, num, flags);
91*0aeed3e9SJustin Hibbits
92*0aeed3e9SJustin Hibbits /* This needs some explanation. Adding the given buffers may take the
93*0aeed3e9SJustin Hibbits * stockpile over the threshold, but in fact the stockpile may already
94*0aeed3e9SJustin Hibbits * *be* over the threshold if a previous release-to-hw attempt had
95*0aeed3e9SJustin Hibbits * failed. So we have 3 cases to cover;
96*0aeed3e9SJustin Hibbits * 1. we add to the stockpile and don't hit the threshold,
97*0aeed3e9SJustin Hibbits * 2. we add to the stockpile, hit the threshold and release-to-hw,
98*0aeed3e9SJustin Hibbits * 3. we have to release-to-hw before adding to the stockpile
99*0aeed3e9SJustin Hibbits * (not enough room in the stockpile for case 2).
100*0aeed3e9SJustin Hibbits * Our constraints on thresholds guarantee that in case 3, there must be
101*0aeed3e9SJustin Hibbits * at least 8 bufs already in the stockpile, so all release-to-hw ops
102*0aeed3e9SJustin Hibbits * are for 8 bufs. Despite all this, the API must indicate whether the
103*0aeed3e9SJustin Hibbits * given buffers were taken off the caller's hands, irrespective of
104*0aeed3e9SJustin Hibbits * whether a release-to-hw was attempted. */
105*0aeed3e9SJustin Hibbits while (num)
106*0aeed3e9SJustin Hibbits {
107*0aeed3e9SJustin Hibbits /* Add buffers to stockpile if they fit */
108*0aeed3e9SJustin Hibbits if ((p_BmPool->spFill + num) <= p_BmPool->spMaxBufs)
109*0aeed3e9SJustin Hibbits {
110*0aeed3e9SJustin Hibbits memcpy(PTR_MOVE(p_BmPool->sp, sizeof(struct bm_buffer) * (p_BmPool->spFill)),
111*0aeed3e9SJustin Hibbits bufs,
112*0aeed3e9SJustin Hibbits sizeof(struct bm_buffer) * num);
113*0aeed3e9SJustin Hibbits p_BmPool->spFill += num;
114*0aeed3e9SJustin Hibbits num = 0; /* --> will return success no matter what */
115*0aeed3e9SJustin Hibbits }
116*0aeed3e9SJustin Hibbits else
117*0aeed3e9SJustin Hibbits /* Do hw op if hitting the high-water threshold */
118*0aeed3e9SJustin Hibbits {
119*0aeed3e9SJustin Hibbits t_Error ret = BmPortalRelease(h_BmPortal,
120*0aeed3e9SJustin Hibbits p_BmPool->bpid,
121*0aeed3e9SJustin Hibbits (struct bm_buffer *)PTR_MOVE(p_BmPool->sp, sizeof(struct bm_buffer) * (p_BmPool->spFill - p_BmPool->spBufsCmd)),
122*0aeed3e9SJustin Hibbits p_BmPool->spBufsCmd,
123*0aeed3e9SJustin Hibbits flags);
124*0aeed3e9SJustin Hibbits if (ret)
125*0aeed3e9SJustin Hibbits return (num ? ret : E_OK);
126*0aeed3e9SJustin Hibbits p_BmPool->spFill -= p_BmPool->spBufsCmd;
127*0aeed3e9SJustin Hibbits }
128*0aeed3e9SJustin Hibbits }
129*0aeed3e9SJustin Hibbits
130*0aeed3e9SJustin Hibbits return E_OK;
131*0aeed3e9SJustin Hibbits }
132*0aeed3e9SJustin Hibbits
BmPoolAcquire(t_BmPool * p_BmPool,t_Handle h_BmPortal,struct bm_buffer * bufs,uint8_t num,uint32_t flags)133*0aeed3e9SJustin Hibbits static int BmPoolAcquire(t_BmPool *p_BmPool,t_Handle h_BmPortal,
134*0aeed3e9SJustin Hibbits struct bm_buffer *bufs, uint8_t num, uint32_t flags)
135*0aeed3e9SJustin Hibbits {
136*0aeed3e9SJustin Hibbits ASSERT_COND(IN_RANGE(1, num, 8));
137*0aeed3e9SJustin Hibbits if (p_BmPool->flags & BMAN_POOL_FLAG_ONLY_RELEASE)
138*0aeed3e9SJustin Hibbits return 0;
139*0aeed3e9SJustin Hibbits
140*0aeed3e9SJustin Hibbits /* Without stockpile, this API is a pass-through to the h/w operation */
141*0aeed3e9SJustin Hibbits if (!(p_BmPool->flags & BMAN_POOL_FLAG_STOCKPILE))
142*0aeed3e9SJustin Hibbits return BmPortalAcquire(h_BmPortal, p_BmPool->bpid, bufs, num);
143*0aeed3e9SJustin Hibbits /* Only need a h/w op if we'll hit the low-water thresh */
144*0aeed3e9SJustin Hibbits if (!(flags & BMAN_ACQUIRE_FLAG_STOCKPILE) &&
145*0aeed3e9SJustin Hibbits ((p_BmPool->spFill - num) < p_BmPool->spMinBufs))
146*0aeed3e9SJustin Hibbits {
147*0aeed3e9SJustin Hibbits p_BmPool->spFill += BmPortalAcquire(h_BmPortal,
148*0aeed3e9SJustin Hibbits p_BmPool->bpid,
149*0aeed3e9SJustin Hibbits (struct bm_buffer *)PTR_MOVE(p_BmPool->sp, sizeof(struct bm_buffer) * (p_BmPool->spFill)),
150*0aeed3e9SJustin Hibbits p_BmPool->spBufsCmd);
151*0aeed3e9SJustin Hibbits }
152*0aeed3e9SJustin Hibbits else if (p_BmPool->spFill < num)
153*0aeed3e9SJustin Hibbits return 0;
154*0aeed3e9SJustin Hibbits if (!p_BmPool->spFill)
155*0aeed3e9SJustin Hibbits return 0;
156*0aeed3e9SJustin Hibbits memcpy(bufs,
157*0aeed3e9SJustin Hibbits PTR_MOVE(p_BmPool->sp, sizeof(struct bm_buffer) * (p_BmPool->spFill - num)),
158*0aeed3e9SJustin Hibbits sizeof(struct bm_buffer) * num);
159*0aeed3e9SJustin Hibbits p_BmPool->spFill -= num;
160*0aeed3e9SJustin Hibbits return num;
161*0aeed3e9SJustin Hibbits }
162*0aeed3e9SJustin Hibbits
BmPoolFree(t_BmPool * p_BmPool,bool discardBuffers)163*0aeed3e9SJustin Hibbits static t_Error BmPoolFree(t_BmPool *p_BmPool, bool discardBuffers)
164*0aeed3e9SJustin Hibbits {
165*0aeed3e9SJustin Hibbits t_Handle h_BufContext;
166*0aeed3e9SJustin Hibbits void *p_Data;
167*0aeed3e9SJustin Hibbits
168*0aeed3e9SJustin Hibbits ASSERT_COND(p_BmPool);
169*0aeed3e9SJustin Hibbits
170*0aeed3e9SJustin Hibbits if (!p_BmPool->shadowMode)
171*0aeed3e9SJustin Hibbits {
172*0aeed3e9SJustin Hibbits if (p_BmPool->flags & BMAN_POOL_FLAG_DEPLETION)
173*0aeed3e9SJustin Hibbits {
174*0aeed3e9SJustin Hibbits depletion_unlink(p_BmPool);
175*0aeed3e9SJustin Hibbits BmUnSetPoolThresholds(p_BmPool->h_Bm, p_BmPool->bpid);
176*0aeed3e9SJustin Hibbits }
177*0aeed3e9SJustin Hibbits while (TRUE)
178*0aeed3e9SJustin Hibbits {
179*0aeed3e9SJustin Hibbits p_Data = BM_POOL_GetBuf(p_BmPool, p_BmPool->h_BmPortal);
180*0aeed3e9SJustin Hibbits if (!p_Data)
181*0aeed3e9SJustin Hibbits break;
182*0aeed3e9SJustin Hibbits h_BufContext = BM_POOL_GetBufferContext(p_BmPool, p_Data);
183*0aeed3e9SJustin Hibbits if (!discardBuffers)
184*0aeed3e9SJustin Hibbits p_BmPool->bufferPoolInfo.f_PutBuf(p_BmPool->bufferPoolInfo.h_BufferPool, p_Data, h_BufContext);
185*0aeed3e9SJustin Hibbits }
186*0aeed3e9SJustin Hibbits BmBpidPut(p_BmPool->h_Bm, p_BmPool->bpid);
187*0aeed3e9SJustin Hibbits }
188*0aeed3e9SJustin Hibbits
189*0aeed3e9SJustin Hibbits if (p_BmPool->sp)
190*0aeed3e9SJustin Hibbits XX_Free(p_BmPool->sp);
191*0aeed3e9SJustin Hibbits
192*0aeed3e9SJustin Hibbits XX_Free(p_BmPool);
193*0aeed3e9SJustin Hibbits
194*0aeed3e9SJustin Hibbits return E_OK;
195*0aeed3e9SJustin Hibbits }
196*0aeed3e9SJustin Hibbits
197*0aeed3e9SJustin Hibbits /****************************************/
198*0aeed3e9SJustin Hibbits /* API Init unit functions */
199*0aeed3e9SJustin Hibbits /****************************************/
200*0aeed3e9SJustin Hibbits
BM_POOL_Config(t_BmPoolParam * p_BmPoolParam)201*0aeed3e9SJustin Hibbits t_Handle BM_POOL_Config(t_BmPoolParam *p_BmPoolParam)
202*0aeed3e9SJustin Hibbits {
203*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool;
204*0aeed3e9SJustin Hibbits
205*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPoolParam, E_INVALID_HANDLE, NULL);
206*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPoolParam->h_Bm, E_INVALID_HANDLE, NULL);
207*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE((p_BmPoolParam->shadowMode ||
208*0aeed3e9SJustin Hibbits (p_BmPoolParam->bufferPoolInfo.h_BufferPool &&
209*0aeed3e9SJustin Hibbits p_BmPoolParam->bufferPoolInfo.f_GetBuf &&
210*0aeed3e9SJustin Hibbits p_BmPoolParam->bufferPoolInfo.f_PutBuf &&
211*0aeed3e9SJustin Hibbits p_BmPoolParam->bufferPoolInfo.bufferSize)), E_INVALID_STATE, NULL);
212*0aeed3e9SJustin Hibbits
213*0aeed3e9SJustin Hibbits p_BmPool = (t_BmPool*)XX_Malloc(sizeof(t_BmPool));
214*0aeed3e9SJustin Hibbits if (!p_BmPool)
215*0aeed3e9SJustin Hibbits {
216*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("BM Pool obj!!!"));
217*0aeed3e9SJustin Hibbits return NULL;
218*0aeed3e9SJustin Hibbits }
219*0aeed3e9SJustin Hibbits memset(p_BmPool, 0, sizeof(t_BmPool));
220*0aeed3e9SJustin Hibbits
221*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams = (t_BmPoolDriverParams *)XX_Malloc(sizeof(t_BmPoolDriverParams));
222*0aeed3e9SJustin Hibbits if (!p_BmPool->p_BmPoolDriverParams)
223*0aeed3e9SJustin Hibbits {
224*0aeed3e9SJustin Hibbits XX_Free(p_BmPool);
225*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("Bm Pool driver parameters"));
226*0aeed3e9SJustin Hibbits return NULL;
227*0aeed3e9SJustin Hibbits }
228*0aeed3e9SJustin Hibbits memset(p_BmPool->p_BmPoolDriverParams, 0, sizeof(t_BmPoolDriverParams));
229*0aeed3e9SJustin Hibbits
230*0aeed3e9SJustin Hibbits p_BmPool->h_Bm = p_BmPoolParam->h_Bm;
231*0aeed3e9SJustin Hibbits p_BmPool->h_BmPortal = p_BmPoolParam->h_BmPortal;
232*0aeed3e9SJustin Hibbits p_BmPool->h_App = p_BmPoolParam->h_App;
233*0aeed3e9SJustin Hibbits p_BmPool->numOfBuffers = p_BmPoolParam->numOfBuffers;
234*0aeed3e9SJustin Hibbits p_BmPool->shadowMode = p_BmPoolParam->shadowMode;
235*0aeed3e9SJustin Hibbits
236*0aeed3e9SJustin Hibbits if (!p_BmPool->h_BmPortal)
237*0aeed3e9SJustin Hibbits {
238*0aeed3e9SJustin Hibbits p_BmPool->h_BmPortal = BmGetPortalHandle(p_BmPool->h_Bm);
239*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool->h_BmPortal, E_INVALID_HANDLE, NULL);
240*0aeed3e9SJustin Hibbits }
241*0aeed3e9SJustin Hibbits
242*0aeed3e9SJustin Hibbits memcpy(&p_BmPool->bufferPoolInfo, &p_BmPoolParam->bufferPoolInfo, sizeof(t_BufferPoolInfo));
243*0aeed3e9SJustin Hibbits if (!p_BmPool->bufferPoolInfo.f_PhysToVirt)
244*0aeed3e9SJustin Hibbits p_BmPool->bufferPoolInfo.f_PhysToVirt = XX_PhysToVirt;
245*0aeed3e9SJustin Hibbits if (!p_BmPool->bufferPoolInfo.f_VirtToPhys)
246*0aeed3e9SJustin Hibbits p_BmPool->bufferPoolInfo.f_VirtToPhys = XX_VirtToPhys;
247*0aeed3e9SJustin Hibbits
248*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams->dynamicBpid = DEFAULT_dynamicBpid;
249*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams->useDepletion = DEFAULT_useDepletion;
250*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams->useStockpile = DEFAULT_useStockpile;
251*0aeed3e9SJustin Hibbits
252*0aeed3e9SJustin Hibbits if (p_BmPool->shadowMode)
253*0aeed3e9SJustin Hibbits {
254*0aeed3e9SJustin Hibbits p_BmPool->numOfBuffers = 0;
255*0aeed3e9SJustin Hibbits BM_POOL_ConfigBpid(p_BmPool, p_BmPoolParam->bpid);
256*0aeed3e9SJustin Hibbits }
257*0aeed3e9SJustin Hibbits
258*0aeed3e9SJustin Hibbits return p_BmPool;
259*0aeed3e9SJustin Hibbits }
260*0aeed3e9SJustin Hibbits
BM_POOL_Init(t_Handle h_BmPool)261*0aeed3e9SJustin Hibbits t_Error BM_POOL_Init(t_Handle h_BmPool)
262*0aeed3e9SJustin Hibbits {
263*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
264*0aeed3e9SJustin Hibbits t_Error err;
265*0aeed3e9SJustin Hibbits
266*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool, E_INVALID_HANDLE);
267*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE);
268*0aeed3e9SJustin Hibbits
269*0aeed3e9SJustin Hibbits p_BmPool->flags |= (p_BmPool->p_BmPoolDriverParams->dynamicBpid)?BMAN_POOL_FLAG_DYNAMIC_BPID:0;
270*0aeed3e9SJustin Hibbits p_BmPool->flags |= (p_BmPool->p_BmPoolDriverParams->useStockpile)?BMAN_POOL_FLAG_STOCKPILE:0;
271*0aeed3e9SJustin Hibbits p_BmPool->flags |= ((!p_BmPool->shadowMode) &&
272*0aeed3e9SJustin Hibbits (p_BmPool->p_BmPoolDriverParams->useDepletion))?BMAN_POOL_FLAG_DEPLETION:0;
273*0aeed3e9SJustin Hibbits
274*0aeed3e9SJustin Hibbits if (p_BmPool->flags & BMAN_POOL_FLAG_DYNAMIC_BPID)
275*0aeed3e9SJustin Hibbits {
276*0aeed3e9SJustin Hibbits if((p_BmPool->bpid = (uint8_t)BmBpidGet(p_BmPool->h_Bm, FALSE, (uint32_t)0)) == (uint8_t)ILLEGAL_BASE)
277*0aeed3e9SJustin Hibbits {
278*0aeed3e9SJustin Hibbits BM_POOL_Free(p_BmPool);
279*0aeed3e9SJustin Hibbits RETURN_ERROR(CRITICAL, E_INVALID_STATE, ("can't allocate new dynamic pool id"));
280*0aeed3e9SJustin Hibbits }
281*0aeed3e9SJustin Hibbits }
282*0aeed3e9SJustin Hibbits else
283*0aeed3e9SJustin Hibbits {
284*0aeed3e9SJustin Hibbits if (BmBpidGet(p_BmPool->h_Bm, TRUE, (uint32_t)p_BmPool->bpid) == (uint32_t)ILLEGAL_BASE)
285*0aeed3e9SJustin Hibbits {
286*0aeed3e9SJustin Hibbits BM_POOL_Free(p_BmPool);
287*0aeed3e9SJustin Hibbits RETURN_ERROR(CRITICAL, E_INVALID_STATE, ("can't force pool id %d", p_BmPool->bpid));
288*0aeed3e9SJustin Hibbits }
289*0aeed3e9SJustin Hibbits }
290*0aeed3e9SJustin Hibbits if (p_BmPool->flags & BMAN_POOL_FLAG_DEPLETION)
291*0aeed3e9SJustin Hibbits {
292*0aeed3e9SJustin Hibbits if(BmSetPoolThresholds(p_BmPool->h_Bm, p_BmPool->bpid, p_BmPool->p_BmPoolDriverParams->depletionThresholds))
293*0aeed3e9SJustin Hibbits {
294*0aeed3e9SJustin Hibbits BM_POOL_Free(p_BmPool);
295*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("can't set thresh for pool bpid %d",p_BmPool->bpid));
296*0aeed3e9SJustin Hibbits }
297*0aeed3e9SJustin Hibbits
298*0aeed3e9SJustin Hibbits depletion_link(p_BmPool);
299*0aeed3e9SJustin Hibbits }
300*0aeed3e9SJustin Hibbits
301*0aeed3e9SJustin Hibbits if (p_BmPool->flags & BMAN_POOL_FLAG_STOCKPILE)
302*0aeed3e9SJustin Hibbits {
303*0aeed3e9SJustin Hibbits p_BmPool->sp = (struct bm_buffer *)XX_Malloc(sizeof(struct bm_buffer) * p_BmPool->spMaxBufs);
304*0aeed3e9SJustin Hibbits if (!p_BmPool->sp)
305*0aeed3e9SJustin Hibbits {
306*0aeed3e9SJustin Hibbits BM_POOL_Free(p_BmPool);
307*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NO_MEMORY, ("Bm Pool Stockpile"));
308*0aeed3e9SJustin Hibbits }
309*0aeed3e9SJustin Hibbits memset(p_BmPool->sp, 0, sizeof(struct bm_buffer) * p_BmPool->spMaxBufs);
310*0aeed3e9SJustin Hibbits }
311*0aeed3e9SJustin Hibbits
312*0aeed3e9SJustin Hibbits XX_Free(p_BmPool->p_BmPoolDriverParams);
313*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams = NULL;
314*0aeed3e9SJustin Hibbits
315*0aeed3e9SJustin Hibbits /*******************/
316*0aeed3e9SJustin Hibbits /* Create buffers */
317*0aeed3e9SJustin Hibbits /*******************/
318*0aeed3e9SJustin Hibbits if ((err = BM_POOL_FillBufs (p_BmPool, p_BmPool->h_BmPortal, p_BmPool->numOfBuffers)) != E_OK)
319*0aeed3e9SJustin Hibbits {
320*0aeed3e9SJustin Hibbits BM_POOL_Free(p_BmPool);
321*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, err, NO_MSG);
322*0aeed3e9SJustin Hibbits }
323*0aeed3e9SJustin Hibbits
324*0aeed3e9SJustin Hibbits return E_OK;
325*0aeed3e9SJustin Hibbits }
326*0aeed3e9SJustin Hibbits
BM_POOL_Free(t_Handle h_BmPool)327*0aeed3e9SJustin Hibbits t_Error BM_POOL_Free(t_Handle h_BmPool)
328*0aeed3e9SJustin Hibbits {
329*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(h_BmPool, E_INVALID_HANDLE);
330*0aeed3e9SJustin Hibbits
331*0aeed3e9SJustin Hibbits return BmPoolFree(h_BmPool, FALSE);
332*0aeed3e9SJustin Hibbits }
333*0aeed3e9SJustin Hibbits
BM_POOL_ConfigBpid(t_Handle h_BmPool,uint8_t bpid)334*0aeed3e9SJustin Hibbits t_Error BM_POOL_ConfigBpid(t_Handle h_BmPool, uint8_t bpid)
335*0aeed3e9SJustin Hibbits {
336*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
337*0aeed3e9SJustin Hibbits
338*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool, E_INVALID_HANDLE);
339*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE);
340*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE);
341*0aeed3e9SJustin Hibbits
342*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams->dynamicBpid = FALSE;
343*0aeed3e9SJustin Hibbits p_BmPool->bpid = bpid;
344*0aeed3e9SJustin Hibbits
345*0aeed3e9SJustin Hibbits return E_OK;
346*0aeed3e9SJustin Hibbits }
347*0aeed3e9SJustin Hibbits
348*0aeed3e9SJustin Hibbits
BM_POOL_ConfigDepletion(t_Handle h_BmPool,t_BmDepletionCallback * f_Depletion,uint32_t * p_Thresholds)349*0aeed3e9SJustin Hibbits t_Error BM_POOL_ConfigDepletion(t_Handle h_BmPool, t_BmDepletionCallback *f_Depletion, uint32_t *p_Thresholds)
350*0aeed3e9SJustin Hibbits {
351*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
352*0aeed3e9SJustin Hibbits
353*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool, E_INVALID_HANDLE);
354*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE);
355*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(f_Depletion, E_INVALID_HANDLE);
356*0aeed3e9SJustin Hibbits
357*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams->useDepletion = TRUE;
358*0aeed3e9SJustin Hibbits p_BmPool->f_Depletion = f_Depletion;
359*0aeed3e9SJustin Hibbits memcpy(&p_BmPool->p_BmPoolDriverParams->depletionThresholds,
360*0aeed3e9SJustin Hibbits p_Thresholds,
361*0aeed3e9SJustin Hibbits sizeof(p_BmPool->p_BmPoolDriverParams->depletionThresholds));
362*0aeed3e9SJustin Hibbits
363*0aeed3e9SJustin Hibbits return E_OK;
364*0aeed3e9SJustin Hibbits }
365*0aeed3e9SJustin Hibbits
BM_POOL_ConfigStockpile(t_Handle h_BmPool,uint16_t maxBuffers,uint16_t minBuffers)366*0aeed3e9SJustin Hibbits t_Error BM_POOL_ConfigStockpile(t_Handle h_BmPool, uint16_t maxBuffers, uint16_t minBuffers)
367*0aeed3e9SJustin Hibbits {
368*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
369*0aeed3e9SJustin Hibbits
370*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool, E_INVALID_HANDLE);
371*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE);
372*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(maxBuffers, E_INVALID_STATE);
373*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(maxBuffers >= minBuffers, E_INVALID_STATE);
374*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR((p_BmPool->shadowMode ||
375*0aeed3e9SJustin Hibbits ((maxBuffers * 2) <= p_BmPool->numOfBuffers)),
376*0aeed3e9SJustin Hibbits E_INVALID_STATE);
377*0aeed3e9SJustin Hibbits
378*0aeed3e9SJustin Hibbits p_BmPool->p_BmPoolDriverParams->useStockpile = TRUE;
379*0aeed3e9SJustin Hibbits p_BmPool->spMaxBufs = maxBuffers;
380*0aeed3e9SJustin Hibbits p_BmPool->spMinBufs = minBuffers;
381*0aeed3e9SJustin Hibbits p_BmPool->spBufsCmd = DEFAULT_numOfBufsPerCmd;
382*0aeed3e9SJustin Hibbits
383*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR((p_BmPool->spMaxBufs >=
384*0aeed3e9SJustin Hibbits (p_BmPool->spMinBufs + p_BmPool->spBufsCmd)),
385*0aeed3e9SJustin Hibbits E_INVALID_STATE);
386*0aeed3e9SJustin Hibbits
387*0aeed3e9SJustin Hibbits return E_OK;
388*0aeed3e9SJustin Hibbits }
389*0aeed3e9SJustin Hibbits
BM_POOL_ConfigBuffContextMode(t_Handle h_BmPool,bool en)390*0aeed3e9SJustin Hibbits t_Error BM_POOL_ConfigBuffContextMode(t_Handle h_BmPool, bool en)
391*0aeed3e9SJustin Hibbits {
392*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
393*0aeed3e9SJustin Hibbits
394*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool, E_INVALID_HANDLE);
395*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE);
396*0aeed3e9SJustin Hibbits
397*0aeed3e9SJustin Hibbits p_BmPool->noBuffCtxt = !en;
398*0aeed3e9SJustin Hibbits
399*0aeed3e9SJustin Hibbits return E_OK;
400*0aeed3e9SJustin Hibbits }
401*0aeed3e9SJustin Hibbits
BM_POOL_GetBuf(t_Handle h_BmPool,t_Handle h_BmPortal)402*0aeed3e9SJustin Hibbits void * BM_POOL_GetBuf(t_Handle h_BmPool, t_Handle h_BmPortal)
403*0aeed3e9SJustin Hibbits {
404*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
405*0aeed3e9SJustin Hibbits struct bm_buffer bufs[1];
406*0aeed3e9SJustin Hibbits uint8_t retBufsNum;
407*0aeed3e9SJustin Hibbits uint64_t physAddr;
408*0aeed3e9SJustin Hibbits uint32_t flags = 0;
409*0aeed3e9SJustin Hibbits
410*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool, E_INVALID_HANDLE, NULL);
411*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE, NULL);
412*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool->bufferPoolInfo.f_PhysToVirt, E_INVALID_STATE, NULL);
413*0aeed3e9SJustin Hibbits
414*0aeed3e9SJustin Hibbits if (!h_BmPortal)
415*0aeed3e9SJustin Hibbits {
416*0aeed3e9SJustin Hibbits if (p_BmPool->h_BmPortal)
417*0aeed3e9SJustin Hibbits h_BmPortal = p_BmPool->h_BmPortal;
418*0aeed3e9SJustin Hibbits else
419*0aeed3e9SJustin Hibbits {
420*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool->h_Bm, E_INVALID_HANDLE, NULL);
421*0aeed3e9SJustin Hibbits h_BmPortal = BmGetPortalHandle(p_BmPool->h_Bm);
422*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(h_BmPortal, E_INVALID_HANDLE, NULL);
423*0aeed3e9SJustin Hibbits }
424*0aeed3e9SJustin Hibbits }
425*0aeed3e9SJustin Hibbits
426*0aeed3e9SJustin Hibbits retBufsNum = (uint8_t)BmPoolAcquire(p_BmPool, h_BmPortal, bufs, 1, flags);
427*0aeed3e9SJustin Hibbits if (!retBufsNum)
428*0aeed3e9SJustin Hibbits {
429*0aeed3e9SJustin Hibbits REPORT_ERROR(TRACE, E_NOT_AVAILABLE, ("buffer"));
430*0aeed3e9SJustin Hibbits return NULL;
431*0aeed3e9SJustin Hibbits }
432*0aeed3e9SJustin Hibbits physAddr = (uint64_t)bufs[0].lo;
433*0aeed3e9SJustin Hibbits physAddr |= (uint64_t)(((uint64_t)bufs[0].hi << 32) & 0x000000ff00000000LL);
434*0aeed3e9SJustin Hibbits DBG(TRACE,("Get Buffer : poolId %d, address 0x%016llx",
435*0aeed3e9SJustin Hibbits p_BmPool->bpid,
436*0aeed3e9SJustin Hibbits p_BmPool->bufferPoolInfo.f_PhysToVirt((physAddress_t)physAddr)));
437*0aeed3e9SJustin Hibbits
438*0aeed3e9SJustin Hibbits return p_BmPool->bufferPoolInfo.f_PhysToVirt((physAddress_t)physAddr);
439*0aeed3e9SJustin Hibbits }
440*0aeed3e9SJustin Hibbits
BM_POOL_PutBuf(t_Handle h_BmPool,t_Handle h_BmPortal,void * p_Buff)441*0aeed3e9SJustin Hibbits t_Error BM_POOL_PutBuf(t_Handle h_BmPool, t_Handle h_BmPortal, void *p_Buff)
442*0aeed3e9SJustin Hibbits {
443*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
444*0aeed3e9SJustin Hibbits uint64_t physAddress;
445*0aeed3e9SJustin Hibbits struct bm_buffer bufs[1];
446*0aeed3e9SJustin Hibbits
447*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool, E_INVALID_HANDLE);
448*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_BmPool->p_BmPoolDriverParams, E_INVALID_STATE);
449*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Buff, E_NULL_POINTER);
450*0aeed3e9SJustin Hibbits
451*0aeed3e9SJustin Hibbits physAddress = (uint64_t)(XX_VirtToPhys(p_Buff));
452*0aeed3e9SJustin Hibbits
453*0aeed3e9SJustin Hibbits bufs[0].bpid = p_BmPool->bpid;
454*0aeed3e9SJustin Hibbits bufs[0].hi = (uint8_t)((physAddress & 0x000000ff00000000LL) >> 32);
455*0aeed3e9SJustin Hibbits bufs[0].lo = (uint32_t)(physAddress & 0xffffffff);
456*0aeed3e9SJustin Hibbits
457*0aeed3e9SJustin Hibbits DBG(TRACE,("Put Buffer : poolId %d, address 0x%016llx, phys 0x%016llx",
458*0aeed3e9SJustin Hibbits p_BmPool->bpid, (uint64_t)PTR_TO_UINT(p_Buff), physAddress));
459*0aeed3e9SJustin Hibbits
460*0aeed3e9SJustin Hibbits if (!h_BmPortal)
461*0aeed3e9SJustin Hibbits {
462*0aeed3e9SJustin Hibbits if (p_BmPool->h_BmPortal)
463*0aeed3e9SJustin Hibbits h_BmPortal = p_BmPool->h_BmPortal;
464*0aeed3e9SJustin Hibbits else
465*0aeed3e9SJustin Hibbits {
466*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool->h_Bm, E_INVALID_HANDLE);
467*0aeed3e9SJustin Hibbits h_BmPortal = BmGetPortalHandle(p_BmPool->h_Bm);
468*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(h_BmPortal, E_INVALID_HANDLE);
469*0aeed3e9SJustin Hibbits }
470*0aeed3e9SJustin Hibbits }
471*0aeed3e9SJustin Hibbits
472*0aeed3e9SJustin Hibbits return BmPoolRelease(p_BmPool, h_BmPortal, bufs, 1, BMAN_RELEASE_FLAG_WAIT);
473*0aeed3e9SJustin Hibbits }
474*0aeed3e9SJustin Hibbits
BM_POOL_FillBufs(t_Handle h_BmPool,t_Handle h_BmPortal,uint32_t numBufs)475*0aeed3e9SJustin Hibbits t_Error BM_POOL_FillBufs(t_Handle h_BmPool, t_Handle h_BmPortal, uint32_t numBufs)
476*0aeed3e9SJustin Hibbits {
477*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
478*0aeed3e9SJustin Hibbits
479*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool, E_INVALID_HANDLE);
480*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_BmPool->p_BmPoolDriverParams, E_INVALID_STATE);
481*0aeed3e9SJustin Hibbits
482*0aeed3e9SJustin Hibbits if (!h_BmPortal)
483*0aeed3e9SJustin Hibbits {
484*0aeed3e9SJustin Hibbits if (p_BmPool->h_BmPortal)
485*0aeed3e9SJustin Hibbits h_BmPortal = p_BmPool->h_BmPortal;
486*0aeed3e9SJustin Hibbits else
487*0aeed3e9SJustin Hibbits {
488*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmPool->h_Bm, E_INVALID_HANDLE);
489*0aeed3e9SJustin Hibbits h_BmPortal = BmGetPortalHandle(p_BmPool->h_Bm);
490*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(h_BmPortal, E_INVALID_HANDLE);
491*0aeed3e9SJustin Hibbits }
492*0aeed3e9SJustin Hibbits }
493*0aeed3e9SJustin Hibbits
494*0aeed3e9SJustin Hibbits while (numBufs--)
495*0aeed3e9SJustin Hibbits {
496*0aeed3e9SJustin Hibbits uint8_t *p_Data;
497*0aeed3e9SJustin Hibbits t_Error res;
498*0aeed3e9SJustin Hibbits t_Handle h_BufContext;
499*0aeed3e9SJustin Hibbits
500*0aeed3e9SJustin Hibbits p_Data = p_BmPool->bufferPoolInfo.f_GetBuf(p_BmPool->bufferPoolInfo.h_BufferPool, &h_BufContext);
501*0aeed3e9SJustin Hibbits if(!p_Data)
502*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("run-out of buffers for bpid %d",p_BmPool->bpid));
503*0aeed3e9SJustin Hibbits
504*0aeed3e9SJustin Hibbits if (!p_BmPool->noBuffCtxt)
505*0aeed3e9SJustin Hibbits *(t_Handle *)(p_Data - sizeof(t_Handle)) = h_BufContext;
506*0aeed3e9SJustin Hibbits
507*0aeed3e9SJustin Hibbits if ((res = BM_POOL_PutBuf(p_BmPool, h_BmPortal, p_Data)) != E_OK)
508*0aeed3e9SJustin Hibbits RETURN_ERROR(CRITICAL, res, ("Seeding reserved buffer pool failed"));
509*0aeed3e9SJustin Hibbits }
510*0aeed3e9SJustin Hibbits
511*0aeed3e9SJustin Hibbits return E_OK;
512*0aeed3e9SJustin Hibbits }
513*0aeed3e9SJustin Hibbits
BM_POOL_GetId(t_Handle h_BmPool)514*0aeed3e9SJustin Hibbits uint8_t BM_POOL_GetId(t_Handle h_BmPool)
515*0aeed3e9SJustin Hibbits {
516*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
517*0aeed3e9SJustin Hibbits
518*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool, E_INVALID_HANDLE, 0);
519*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE, 0);
520*0aeed3e9SJustin Hibbits
521*0aeed3e9SJustin Hibbits return p_BmPool->bpid;
522*0aeed3e9SJustin Hibbits }
523*0aeed3e9SJustin Hibbits
BM_POOL_GetBufferSize(t_Handle h_BmPool)524*0aeed3e9SJustin Hibbits uint16_t BM_POOL_GetBufferSize(t_Handle h_BmPool)
525*0aeed3e9SJustin Hibbits {
526*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
527*0aeed3e9SJustin Hibbits
528*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool, E_INVALID_HANDLE, 0);
529*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE, 0);
530*0aeed3e9SJustin Hibbits
531*0aeed3e9SJustin Hibbits return p_BmPool->bufferPoolInfo.bufferSize;
532*0aeed3e9SJustin Hibbits }
533*0aeed3e9SJustin Hibbits
BM_POOL_GetBufferContext(t_Handle h_BmPool,void * p_Buff)534*0aeed3e9SJustin Hibbits t_Handle BM_POOL_GetBufferContext(t_Handle h_BmPool, void *p_Buff)
535*0aeed3e9SJustin Hibbits {
536*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
537*0aeed3e9SJustin Hibbits
538*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool, E_INVALID_HANDLE, NULL);
539*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE, NULL);
540*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_Buff, E_NULL_POINTER, NULL);
541*0aeed3e9SJustin Hibbits
542*0aeed3e9SJustin Hibbits if (p_BmPool->noBuffCtxt)
543*0aeed3e9SJustin Hibbits return NULL;
544*0aeed3e9SJustin Hibbits
545*0aeed3e9SJustin Hibbits return *(t_Handle *)PTR_MOVE(p_Buff, -(sizeof(t_Handle)));
546*0aeed3e9SJustin Hibbits }
547*0aeed3e9SJustin Hibbits
BM_POOL_GetCounter(t_Handle h_BmPool,e_BmPoolCounters counter)548*0aeed3e9SJustin Hibbits uint32_t BM_POOL_GetCounter(t_Handle h_BmPool, e_BmPoolCounters counter)
549*0aeed3e9SJustin Hibbits {
550*0aeed3e9SJustin Hibbits t_BmPool *p_BmPool = (t_BmPool *)h_BmPool;
551*0aeed3e9SJustin Hibbits
552*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmPool, E_INVALID_HANDLE, 0);
553*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_BmPool->p_BmPoolDriverParams, E_INVALID_HANDLE, 0);
554*0aeed3e9SJustin Hibbits
555*0aeed3e9SJustin Hibbits switch(counter)
556*0aeed3e9SJustin Hibbits {
557*0aeed3e9SJustin Hibbits case(e_BM_POOL_COUNTERS_CONTENT):
558*0aeed3e9SJustin Hibbits return BmGetCounter(p_BmPool->h_Bm, e_BM_IM_COUNTERS_POOL_CONTENT, p_BmPool->bpid);
559*0aeed3e9SJustin Hibbits case(e_BM_POOL_COUNTERS_SW_DEPLETION):
560*0aeed3e9SJustin Hibbits return (p_BmPool->swDepletionCount +=
561*0aeed3e9SJustin Hibbits BmGetCounter(p_BmPool->h_Bm, e_BM_IM_COUNTERS_POOL_SW_DEPLETION, p_BmPool->bpid));
562*0aeed3e9SJustin Hibbits case(e_BM_POOL_COUNTERS_HW_DEPLETION):
563*0aeed3e9SJustin Hibbits return (p_BmPool->hwDepletionCount +=
564*0aeed3e9SJustin Hibbits BmGetCounter(p_BmPool->h_Bm, e_BM_IM_COUNTERS_POOL_HW_DEPLETION, p_BmPool->bpid));
565*0aeed3e9SJustin Hibbits default:
566*0aeed3e9SJustin Hibbits break;
567*0aeed3e9SJustin Hibbits }
568*0aeed3e9SJustin Hibbits
569*0aeed3e9SJustin Hibbits /* should never get here */
570*0aeed3e9SJustin Hibbits ASSERT_COND(FALSE);
571*0aeed3e9SJustin Hibbits
572*0aeed3e9SJustin Hibbits return 0;
573*0aeed3e9SJustin Hibbits }
574