1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#include "IxOsal.h"
54
55#define IX_OSAL_BUFFER_FREE_PROTECTION
56
57
58
59
60
61#ifdef IX_OSAL_USE_DEFAULT_BUFFER_MGT
62
63
64#define IX_OSAL_MBUF_SYS_SIGNATURE (0x8BADF00D)
65#define IX_OSAL_MBUF_SYS_SIGNATURE_MASK (0xEFFFFFFF)
66#define IX_OSAL_MBUF_USED_FLAG (0x10000000)
67#define IX_OSAL_MBUF_SYS_SIGNATURE_INIT(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr) = (UINT32)IX_OSAL_MBUF_SYS_SIGNATURE
68
69
70
71
72
73
74
75
76
77
78#ifdef IX_OSAL_BUFFER_FREE_PROTECTION
79
80#define IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) (IX_OSAL_MBUF_SIGNATURE (bufPtr)&(IX_OSAL_MBUF_SYS_SIGNATURE_MASK) )
81#define IX_OSAL_MBUF_SET_SYS_SIGNATURE(bufPtr) do { \
82 IX_OSAL_MBUF_SIGNATURE (bufPtr)&(~IX_OSAL_MBUF_SYS_SIGNATURE_MASK);\
83 IX_OSAL_MBUF_SIGNATURE (bufPtr)|=IX_OSAL_MBUF_SYS_SIGNATURE; \
84 }while(0)
85
86#define IX_OSAL_MBUF_SET_USED_FLAG(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr)|=IX_OSAL_MBUF_USED_FLAG
87#define IX_OSAL_MBUF_CLEAR_USED_FLAG(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr)&=~IX_OSAL_MBUF_USED_FLAG
88#define IX_OSAL_MBUF_ISSET_USED_FLAG(bufPtr) (IX_OSAL_MBUF_SIGNATURE (bufPtr)&IX_OSAL_MBUF_USED_FLAG)
89
90#else
91
92#define IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr)
93#define IX_OSAL_MBUF_SET_SYS_SIGNATURE(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr) = IX_OSAL_MBUF_SYS_SIGNATURE
94
95#endif
96
97
98
99
100
101
102
103
104
105#define IX_OSAL_BUFF_FREE_BITS 32
106
107PRIVATE UINT32 ixOsalBuffFreePools[IX_OSAL_MBUF_MAX_POOLS /
108 IX_OSAL_BUFF_FREE_BITS];
109
110PUBLIC IX_OSAL_MBUF_POOL ixOsalBuffPools[IX_OSAL_MBUF_MAX_POOLS];
111
112static int ixOsalBuffPoolsInUse = 0;
113
114#ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
115PRIVATE IX_OSAL_MBUF *
116ixOsalBuffPoolMbufInit (UINT32 mbufSizeAligned,
117 UINT32 dataSizeAligned,
118 IX_OSAL_MBUF_POOL *poolPtr);
119#endif
120
121PRIVATE IX_OSAL_MBUF_POOL * ixOsalPoolAlloc (void);
122
123
124
125
126
127
128
129PRIVATE IX_OSAL_MBUF_POOL *
130ixOsalPoolAlloc (void)
131{
132 register unsigned int i = 0;
133
134
135
136
137
138 if (ixOsalBuffPoolsInUse >= IX_OSAL_MBUF_MAX_POOLS)
139 {
140
141
142
143 return NULL;
144 }
145
146 while (ixOsalBuffFreePools[i / IX_OSAL_BUFF_FREE_BITS] &
147 (1 << (i % IX_OSAL_BUFF_FREE_BITS)))
148 i++;
149
150
151
152 ixOsalBuffFreePools[i / IX_OSAL_BUFF_FREE_BITS] |=
153 (1 << (i % IX_OSAL_BUFF_FREE_BITS));
154
155 memset (&ixOsalBuffPools[i], 0, sizeof (IX_OSAL_MBUF_POOL));
156
157 ixOsalBuffPools[i].poolIdx = i;
158 ixOsalBuffPoolsInUse++;
159
160 return &ixOsalBuffPools[i];
161}
162
163
164#ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
165PRIVATE IX_OSAL_MBUF *
166ixOsalBuffPoolMbufInit (UINT32 mbufSizeAligned,
167 UINT32 dataSizeAligned,
168 IX_OSAL_MBUF_POOL *poolPtr)
169{
170 UINT8 *dataPtr;
171 IX_OSAL_MBUF *realMbufPtr;
172
173 realMbufPtr = (IX_OSAL_MBUF *) IX_OSAL_CACHE_DMA_MALLOC (mbufSizeAligned);
174 IX_OSAL_ASSERT (realMbufPtr != NULL);
175 memset (realMbufPtr, 0, mbufSizeAligned);
176
177
178 dataPtr = (UINT8 *) IX_OSAL_CACHE_DMA_MALLOC (dataSizeAligned);
179 IX_OSAL_ASSERT (dataPtr != NULL);
180 memset (dataPtr, 0, dataSizeAligned);
181
182
183 IX_OSAL_MBUF_MDATA (realMbufPtr) = dataPtr;
184 IX_OSAL_MBUF_ALLOCATED_BUFF_DATA (realMbufPtr) = (UINT32)dataPtr;
185
186 IX_OSAL_MBUF_MLEN (realMbufPtr) = dataSizeAligned;
187 IX_OSAL_MBUF_ALLOCATED_BUFF_LEN (realMbufPtr) = dataSizeAligned;
188
189 IX_OSAL_MBUF_NET_POOL (realMbufPtr) = (IX_OSAL_MBUF_POOL *) poolPtr;
190
191 IX_OSAL_MBUF_SYS_SIGNATURE_INIT(realMbufPtr);
192
193
194 poolPtr->mbufMemSize += mbufSizeAligned;
195 poolPtr->dataMemSize += dataSizeAligned;
196
197 return realMbufPtr;
198}
199#endif
200
201
202
203
204
205PUBLIC IX_OSAL_MBUF_POOL *
206ixOsalPoolInit (UINT32 count, UINT32 size, const char *name)
207{
208
209
210
211
212#ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
213 UINT32 i, mbufSizeAligned, dataSizeAligned;
214 IX_OSAL_MBUF *currentMbufPtr = NULL;
215#else
216 void *poolBufPtr;
217 void *poolDataPtr;
218 int mbufMemSize;
219 int dataMemSize;
220#endif
221
222 IX_OSAL_MBUF_POOL *poolPtr = NULL;
223
224 if (count <= 0)
225 {
226 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
227 IX_OSAL_LOG_DEV_STDOUT,
228 "ixOsalPoolInit(): " "count = 0 \n", 0, 0, 0, 0, 0, 0);
229 return NULL;
230 }
231
232 if (name == NULL)
233 {
234 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
235 IX_OSAL_LOG_DEV_STDOUT,
236 "ixOsalPoolInit(): " "NULL name \n", 0, 0, 0, 0, 0, 0);
237 return NULL;
238 }
239
240 if (strlen (name) > IX_OSAL_MBUF_POOL_NAME_LEN)
241 {
242 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
243 IX_OSAL_LOG_DEV_STDOUT,
244 "ixOsalPoolInit(): "
245 "ERROR - name length should be no greater than %d \n",
246 IX_OSAL_MBUF_POOL_NAME_LEN, 0, 0, 0, 0, 0);
247 return NULL;
248 }
249
250
251
252
253
254#ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
255
256 poolPtr = ixOsalPoolAlloc ();
257
258 if (poolPtr == NULL)
259 {
260 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
261 IX_OSAL_LOG_DEV_STDOUT,
262 "ixOsalPoolInit(): " "Fail to Get PoolPtr \n", 0, 0, 0, 0, 0, 0);
263 return NULL;
264 }
265
266 mbufSizeAligned = IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));
267 dataSizeAligned = IX_OSAL_MBUF_POOL_SIZE_ALIGN(size);
268
269 poolPtr->nextFreeBuf = NULL;
270 poolPtr->mbufMemPtr = NULL;
271 poolPtr->dataMemPtr = NULL;
272 poolPtr->bufDataSize = dataSizeAligned;
273 poolPtr->totalBufsInPool = count;
274 poolPtr->poolAllocType = IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC;
275 strcpy (poolPtr->name, name);
276
277
278 for (i = 0; i < count; i++)
279 {
280
281 currentMbufPtr = ixOsalBuffPoolMbufInit (mbufSizeAligned,
282 dataSizeAligned,
283 poolPtr);
284
285#ifdef IX_OSAL_BUFFER_FREE_PROTECTION
286
287
288
289
290
291 IX_OSAL_MBUF_SET_USED_FLAG(currentMbufPtr);
292#endif
293
294 ixOsalMbufFree (currentMbufPtr);
295
296
297 IX_OSAL_CACHE_FLUSH (currentMbufPtr, mbufSizeAligned);
298 }
299
300
301
302
303 poolPtr->freeBufsInPool = count;
304
305#else
306
307 poolBufPtr = IX_OSAL_MBUF_POOL_MBUF_AREA_ALLOC (count, mbufMemSize);
308 IX_OSAL_ASSERT (poolBufPtr != NULL);
309 poolDataPtr =
310 IX_OSAL_MBUF_POOL_DATA_AREA_ALLOC (count, size, dataMemSize);
311 IX_OSAL_ASSERT (poolDataPtr != NULL);
312
313 poolPtr = ixOsalNoAllocPoolInit (poolBufPtr, poolDataPtr,
314 count, size, name);
315 if (poolPtr == NULL)
316 {
317 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
318 IX_OSAL_LOG_DEV_STDOUT,
319 "ixOsalPoolInit(): " "Fail to get pool ptr \n", 0, 0, 0, 0, 0, 0);
320 return NULL;
321 }
322
323 poolPtr->poolAllocType = IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC;
324
325#endif
326 return poolPtr;
327}
328
329PUBLIC IX_OSAL_MBUF_POOL *
330ixOsalNoAllocPoolInit (void *poolBufPtr,
331 void *poolDataPtr, UINT32 count, UINT32 size, const char *name)
332{
333 UINT32 i, mbufSizeAligned, sizeAligned;
334 IX_OSAL_MBUF *currentMbufPtr = NULL;
335 IX_OSAL_MBUF *nextMbufPtr = NULL;
336 IX_OSAL_MBUF_POOL *poolPtr = NULL;
337
338
339
340
341 if (poolBufPtr == NULL)
342 {
343 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
344 IX_OSAL_LOG_DEV_STDOUT,
345 "ixOsalNoAllocPoolInit(): "
346 "ERROR - NULL poolBufPtr \n", 0, 0, 0, 0, 0, 0);
347 return NULL;
348 }
349
350 if (count <= 0)
351 {
352 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
353 IX_OSAL_LOG_DEV_STDOUT,
354 "ixOsalNoAllocPoolInit(): "
355 "ERROR - count must > 0 \n", 0, 0, 0, 0, 0, 0);
356 return NULL;
357 }
358
359 if (name == NULL)
360 {
361 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
362 IX_OSAL_LOG_DEV_STDOUT,
363 "ixOsalNoAllocPoolInit(): "
364 "ERROR - NULL name ptr \n", 0, 0, 0, 0, 0, 0);
365 return NULL;
366 }
367
368 if (strlen (name) > IX_OSAL_MBUF_POOL_NAME_LEN)
369 {
370 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
371 IX_OSAL_LOG_DEV_STDOUT,
372 "ixOsalNoAllocPoolInit(): "
373 "ERROR - name length should be no greater than %d \n",
374 IX_OSAL_MBUF_POOL_NAME_LEN, 0, 0, 0, 0, 0);
375 return NULL;
376 }
377
378 poolPtr = ixOsalPoolAlloc ();
379
380 if (poolPtr == NULL)
381 {
382 return NULL;
383 }
384
385
386
387
388 mbufSizeAligned =
389 IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));
390
391
392
393 memset (poolBufPtr, 0, mbufSizeAligned * count);
394
395 if (poolDataPtr != NULL)
396 {
397
398
399
400 sizeAligned = IX_OSAL_MBUF_POOL_SIZE_ALIGN (size);
401
402
403
404 memset (poolDataPtr, 0, sizeAligned * count);
405 }
406 else
407 {
408 sizeAligned = 0;
409 }
410
411
412
413
414 strcpy ((poolPtr)->name, name);
415
416 poolPtr->dataMemPtr = poolDataPtr;
417 poolPtr->mbufMemPtr = poolBufPtr;
418 poolPtr->bufDataSize = sizeAligned;
419 poolPtr->totalBufsInPool = count;
420 poolPtr->mbufMemSize = mbufSizeAligned * count;
421 poolPtr->dataMemSize = sizeAligned * count;
422
423 currentMbufPtr = (IX_OSAL_MBUF *) poolBufPtr;
424
425 poolPtr->nextFreeBuf = currentMbufPtr;
426
427 for (i = 0; i < count; i++)
428 {
429 if (i < (count - 1))
430 {
431 nextMbufPtr =
432 (IX_OSAL_MBUF *) ((unsigned) currentMbufPtr +
433 mbufSizeAligned);
434 }
435 else
436 {
437 nextMbufPtr = NULL;
438 }
439 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (currentMbufPtr) = nextMbufPtr;
440 IX_OSAL_MBUF_NET_POOL (currentMbufPtr) = poolPtr;
441
442 IX_OSAL_MBUF_SYS_SIGNATURE_INIT(currentMbufPtr);
443
444 if (poolDataPtr != NULL)
445 {
446 IX_OSAL_MBUF_MDATA (currentMbufPtr) = poolDataPtr;
447 IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(currentMbufPtr) = (UINT32) poolDataPtr;
448
449 IX_OSAL_MBUF_MLEN (currentMbufPtr) = sizeAligned;
450 IX_OSAL_MBUF_ALLOCATED_BUFF_LEN(currentMbufPtr) = sizeAligned;
451
452 poolDataPtr = (void *) ((unsigned) poolDataPtr + sizeAligned);
453 }
454
455 currentMbufPtr = nextMbufPtr;
456 }
457
458
459
460
461 poolPtr->freeBufsInPool = count;
462
463 poolPtr->poolAllocType = IX_OSAL_MBUF_POOL_TYPE_USER_ALLOC;
464
465 return poolPtr;
466}
467
468
469
470
471PUBLIC IX_OSAL_MBUF *
472ixOsalMbufAlloc (IX_OSAL_MBUF_POOL * poolPtr)
473{
474 int lock;
475 IX_OSAL_MBUF *newBufPtr = NULL;
476
477
478
479
480 if (poolPtr == NULL)
481 {
482 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
483 IX_OSAL_LOG_DEV_STDOUT,
484 "ixOsalMbufAlloc(): "
485 "ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);
486 return NULL;
487 }
488
489 lock = ixOsalIrqLock ();
490
491 newBufPtr = poolPtr->nextFreeBuf;
492 if (newBufPtr)
493 {
494 poolPtr->nextFreeBuf =
495 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (newBufPtr);
496 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (newBufPtr) = NULL;
497
498
499
500
501 poolPtr->freeBufsInPool--;
502 }
503 else
504 {
505
506 ixOsalIrqUnlock (lock);
507
508 return NULL;
509 }
510
511#ifdef IX_OSAL_BUFFER_FREE_PROTECTION
512
513 IX_OSAL_MBUF_SET_USED_FLAG(newBufPtr);
514#endif
515
516 ixOsalIrqUnlock (lock);
517
518 return newBufPtr;
519}
520
521PUBLIC IX_OSAL_MBUF *
522ixOsalMbufFree (IX_OSAL_MBUF * bufPtr)
523{
524 int lock;
525 IX_OSAL_MBUF_POOL *poolPtr;
526
527 IX_OSAL_MBUF *nextBufPtr = NULL;
528
529
530
531
532 if (bufPtr == NULL)
533 {
534 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
535 IX_OSAL_LOG_DEV_STDOUT,
536 "ixOsalMbufFree(): "
537 "ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);
538 return NULL;
539 }
540
541
542
543 lock = ixOsalIrqLock ();
544
545#ifdef IX_OSAL_BUFFER_FREE_PROTECTION
546
547
548 if(!IX_OSAL_MBUF_ISSET_USED_FLAG(bufPtr))
549 {
550 return NULL;
551 }
552 IX_OSAL_MBUF_CLEAR_USED_FLAG(bufPtr);
553#endif
554
555 poolPtr = IX_OSAL_MBUF_NET_POOL (bufPtr);
556
557
558
559
560 if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)
561 {
562 IX_OSAL_ENSURE ( (IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) == IX_OSAL_MBUF_SYS_SIGNATURE),
563 "ixOsalBuffPoolBufFree: ERROR - Invalid mbuf signature.");
564 }
565
566 nextBufPtr = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (bufPtr);
567
568 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (bufPtr) = poolPtr->nextFreeBuf;
569 poolPtr->nextFreeBuf = bufPtr;
570
571
572
573
574 poolPtr->freeBufsInPool++;
575
576 ixOsalIrqUnlock (lock);
577
578 return nextBufPtr;
579}
580
581PUBLIC void
582ixOsalMbufChainFree (IX_OSAL_MBUF * bufPtr)
583{
584 while ((bufPtr = ixOsalMbufFree (bufPtr)));
585}
586
587
588
589
590PUBLIC void
591ixOsalMbufPoolShow (IX_OSAL_MBUF_POOL * poolPtr)
592{
593 IX_OSAL_MBUF *nextBufPtr;
594 int count = 0;
595 int lock;
596
597
598
599
600 if (poolPtr == NULL)
601 {
602 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
603 IX_OSAL_LOG_DEV_STDOUT,
604 "ixOsalBuffPoolShow(): "
605 "ERROR - Invalid Parameter", 0, 0, 0, 0, 0, 0);
606
607
608
609 return;
610 }
611
612 lock = ixOsalIrqLock ();
613 count = poolPtr->freeBufsInPool;
614 nextBufPtr = poolPtr->nextFreeBuf;
615 ixOsalIrqUnlock (lock);
616
617 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,
618 IX_OSAL_LOG_DEV_STDOUT, "=== POOL INFORMATION ===\n", 0, 0, 0,
619 0, 0, 0);
620 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
621 "Pool Name: %s\n",
622 (unsigned int) poolPtr->name, 0, 0, 0, 0, 0);
623 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
624 "Pool Allocation Type: %d\n",
625 (unsigned int) poolPtr->poolAllocType, 0, 0, 0, 0, 0);
626 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
627 "Pool Mbuf Mem Usage (bytes): %d\n",
628 (unsigned int) poolPtr->mbufMemSize, 0, 0, 0, 0, 0);
629 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
630 "Pool Data Mem Usage (bytes): %d\n",
631 (unsigned int) poolPtr->dataMemSize, 0, 0, 0, 0, 0);
632 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
633 "Mbuf Data Capacity (bytes): %d\n",
634 (unsigned int) poolPtr->bufDataSize, 0, 0, 0, 0, 0);
635 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
636 "Total Mbufs in Pool: %d\n",
637 (unsigned int) poolPtr->totalBufsInPool, 0, 0, 0, 0, 0);
638 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
639 "Available Mbufs: %d\n", (unsigned int) count, 0,
640 0, 0, 0, 0);
641 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
642 "Next Available Mbuf: %p\n", (unsigned int) nextBufPtr,
643 0, 0, 0, 0, 0);
644
645 if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_USER_ALLOC)
646 {
647 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,
648 IX_OSAL_LOG_DEV_STDOUT,
649 "Mbuf Mem Area Start address: %p\n",
650 (unsigned int) poolPtr->mbufMemPtr, 0, 0, 0, 0, 0);
651 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
652 "Data Mem Area Start address: %p\n",
653 (unsigned int) poolPtr->dataMemPtr, 0, 0, 0, 0, 0);
654 }
655}
656
657PUBLIC void
658ixOsalMbufDataPtrReset (IX_OSAL_MBUF * bufPtr)
659{
660 IX_OSAL_MBUF_POOL *poolPtr;
661 UINT8 *poolDataPtr;
662
663 if (bufPtr == NULL)
664 {
665 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
666 "ixOsalBuffPoolBufDataPtrReset"
667 ": ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);
668 return;
669 }
670
671 poolPtr = (IX_OSAL_MBUF_POOL *) IX_OSAL_MBUF_NET_POOL (bufPtr);
672 poolDataPtr = poolPtr->dataMemPtr;
673
674 if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)
675 {
676 if (IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) != IX_OSAL_MBUF_SYS_SIGNATURE)
677 {
678 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
679 "ixOsalBuffPoolBufDataPtrReset"
680 ": invalid mbuf, cannot reset mData pointer\n", 0, 0,
681 0, 0, 0, 0);
682 return;
683 }
684 IX_OSAL_MBUF_MDATA (bufPtr) = (UINT8*)IX_OSAL_MBUF_ALLOCATED_BUFF_DATA (bufPtr);
685 }
686 else
687 {
688 if (poolDataPtr)
689 {
690 unsigned int bufSize = poolPtr->bufDataSize;
691 unsigned int bufDataAddr =
692 (unsigned int) IX_OSAL_MBUF_MDATA (bufPtr);
693 unsigned int poolDataAddr = (unsigned int) poolDataPtr;
694
695
696
697
698
699
700 bufDataAddr = ((bufDataAddr - poolDataAddr) / bufSize) * bufSize;
701 IX_OSAL_MBUF_MDATA (bufPtr) = &poolDataPtr[bufDataAddr];
702 }
703 else
704 {
705 ixOsalLog (IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT,
706 "ixOsalBuffPoolBufDataPtrReset"
707 ": cannot be used if user supplied NULL pointer for pool data area "
708 "when pool was created\n", 0, 0, 0, 0, 0, 0);
709 return;
710 }
711 }
712
713}
714
715
716
717
718PUBLIC IX_STATUS
719ixOsalBuffPoolUninit (IX_OSAL_MBUF_POOL * pool)
720{
721 if (!pool)
722 {
723 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
724 "ixOsalBuffPoolUninit: NULL ptr \n", 0, 0, 0, 0, 0, 0);
725 return IX_FAIL;
726 }
727
728 if (pool->freeBufsInPool != pool->totalBufsInPool)
729 {
730 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
731 "ixOsalBuffPoolUninit: need to return all ptrs to the pool first! \n",
732 0, 0, 0, 0, 0, 0);
733 return IX_FAIL;
734 }
735
736 if (pool->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)
737 {
738#ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
739 UINT32 i;
740 IX_OSAL_MBUF* pBuf;
741
742 pBuf = pool->nextFreeBuf;
743
744 for (i= pool->freeBufsInPool; i >0 && pBuf!=NULL ;i--){
745 IX_OSAL_MBUF* pBufTemp;
746 pBufTemp = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(pBuf);
747
748 IX_OSAL_CACHE_DMA_FREE( (void *) (IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(pBuf)) );
749
750 IX_OSAL_CACHE_DMA_FREE(pBuf);
751 pBuf = pBufTemp;
752 }
753
754#else
755 IX_OSAL_CACHE_DMA_FREE (pool->mbufMemPtr);
756 IX_OSAL_CACHE_DMA_FREE (pool->dataMemPtr);
757#endif
758 }
759
760 ixOsalBuffFreePools[pool->poolIdx / IX_OSAL_BUFF_FREE_BITS] &=
761 ~(1 << (pool->poolIdx % IX_OSAL_BUFF_FREE_BITS));
762 ixOsalBuffPoolsInUse--;
763 return IX_SUCCESS;
764}
765
766
767
768
769PUBLIC UINT32
770ixOsalBuffPoolDataAreaSizeGet (int count, int size)
771{
772 UINT32 memorySize;
773 memorySize = count * IX_OSAL_MBUF_POOL_SIZE_ALIGN (size);
774 return memorySize;
775}
776
777
778
779
780PUBLIC UINT32
781ixOsalBuffPoolMbufAreaSizeGet (int count)
782{
783 UINT32 memorySize;
784 memorySize =
785 count * IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));
786 return memorySize;
787}
788
789
790
791
792PUBLIC UINT32 ixOsalBuffPoolFreeCountGet(IX_OSAL_MBUF_POOL * poolPtr)
793
794{
795
796 return poolPtr->freeBufsInPool;
797
798}
799
800#endif
801