change console=tty0 to enable linux framebuffer console
[jz_uboot.git] / cpu / ixp / npe / include / IxOsalBufferMgt.h
blob497ed047101841c3416d8c4a69af10b742079d74
1 /**
2 * @file IxOsalBufferMgt.h
4 * @brief OSAL Buffer pool management and buffer management definitions.
6 * Design Notes:
8 * @par
9 * IXP400 SW Release version 2.0
11 * -- Copyright Notice --
13 * @par
14 * Copyright 2001-2005, Intel Corporation.
15 * All rights reserved.
17 * @par
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. Neither the name of the Intel Corporation nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * @par
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * SUCH DAMAGE.
43 * @par
44 * -- End of Copyright Notice --
46 /* @par
47 * -- Copyright Notice --
49 * @par
50 * Copyright 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
51 * The Regents of the University of California. All rights reserved.
53 * @par
54 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
56 * are met:
57 * 1. Redistributions of source code must retain the above copyright
58 * notice, this list of conditions and the following disclaimer.
59 * 2. Redistributions in binary form must reproduce the above copyright
60 * notice, this list of conditions and the following disclaimer in the
61 * documentation and/or other materials provided with the distribution.
62 * 3. Neither the name of the University nor the names of its contributors
63 * may be used to endorse or promote products derived from this software
64 * without specific prior written permission.
66 * @par
67 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
68 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
71 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77 * SUCH DAMAGE.
79 * @par
80 * -- End of Copyright Notice --
83 #ifndef IxOsalBufferMgt_H
84 #define IxOsalBufferMgt_H
86 #include "IxOsal.h"
87 /**
88 * @defgroup IxOsalBufferMgt OSAL Buffer Management Module.
90 * @brief Buffer management module for IxOsal
92 * @{
95 /**
96 * @ingroup IxOsalBufferMgt
98 * @def IX_OSAL_MBUF_MAX_POOLS
100 * @brief The maximum number of pools that can be allocated, must be
101 * a multiple of 32 as required by implementation logic.
102 * @note This can safely be increased if more pools are required.
104 #define IX_OSAL_MBUF_MAX_POOLS 32
107 * @ingroup IxOsalBufferMgt
109 * @def IX_OSAL_MBUF_POOL_NAME_LEN
111 * @brief The maximum string length of the pool name
113 #define IX_OSAL_MBUF_POOL_NAME_LEN 64
118 * Define IX_OSAL_MBUF
122 /* forward declaration of internal structure */
123 struct __IXP_BUF;
126 * OS can define it in IxOsalOs.h to skip the following
127 * definition.
129 #ifndef IX_OSAL_ATTRIBUTE_ALIGN32
130 #define IX_OSAL_ATTRIBUTE_ALIGN32 __attribute__ ((aligned(32)))
131 #endif
133 /* release v1.4 backward compatible definitions */
134 struct __IX_MBUF
136 struct __IXP_BUF *ix_next IX_OSAL_ATTRIBUTE_ALIGN32;
137 struct __IXP_BUF *ix_nextPacket;
138 UINT8 *ix_data;
139 UINT32 ix_len;
140 unsigned char ix_type;
141 unsigned char ix_flags;
142 unsigned short ix_reserved;
143 UINT32 ix_rsvd;
144 UINT32 ix_PktLen;
145 void *ix_priv;
148 struct __IX_CTRL
150 UINT32 ix_reserved[2]; /**< Reserved field */
151 UINT32 ix_signature; /**< Field to indicate if buffers are allocated by the system */
152 UINT32 ix_allocated_len; /**< Allocated buffer length */
153 UINT32 ix_allocated_data; /**< Allocated buffer data pointer */
154 void *ix_pool; /**< pointer to the buffer pool */
155 struct __IXP_BUF *ix_chain; /**< chaining */
156 void *ix_osbuf_ptr; /**< Storage for OS-specific buffer pointer */
159 struct __IX_NE_SHARED
161 UINT32 reserved[8] IX_OSAL_ATTRIBUTE_ALIGN32; /**< Reserved area for NPE Service-specific usage */
166 * IXP buffer structure
168 typedef struct __IXP_BUF
170 struct __IX_MBUF ix_mbuf IX_OSAL_ATTRIBUTE_ALIGN32; /**< buffer header */
171 struct __IX_CTRL ix_ctrl; /**< buffer management */
172 struct __IX_NE_SHARED ix_ne; /**< Reserved area for NPE Service-specific usage*/
173 } IXP_BUF;
178 * @ingroup IxOsalBufferMgt
180 * @def typedef IX_OSAL_MBUF
182 * @brief Generic IXP mbuf format.
184 typedef IXP_BUF IX_OSAL_MBUF;
188 * @ingroup IxOsalBufferMgt
190 * @def IX_OSAL_IXP_NEXT_BUFFER_IN_PKT_PTR(m_blk_ptr)
192 * @brief Return pointer to the next mbuf in a single packet
194 #define IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(m_blk_ptr) \
195 (m_blk_ptr)->ix_mbuf.ix_next
199 * @ingroup IxOsalBufferMgt
201 * @def IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(m_blk_ptr)
203 * @brief Return pointer to the next packet in the chain
205 #define IX_OSAL_MBUF_NEXT_PKT_IN_CHAIN_PTR(m_blk_ptr) \
206 (m_blk_ptr)->ix_mbuf.ix_nextPacket
210 * @ingroup IxOsalBufferMgt
212 * @def IX_OSAL_MBUF_MDATA(m_blk_ptr)
214 * @brief Return pointer to the data in the mbuf
216 #define IX_OSAL_MBUF_MDATA(m_blk_ptr) (m_blk_ptr)->ix_mbuf.ix_data
219 * @ingroup IxOsalBufferMgt
221 * @def IX_OSAL_MBUF_MLEN(m_blk_ptr)
223 * @brief Return the data length
225 #define IX_OSAL_MBUF_MLEN(m_blk_ptr) \
226 (m_blk_ptr)->ix_mbuf.ix_len
229 * @ingroup IxOsalBufferMgt
231 * @def IX_OSAL_MBUF_MTYPE(m_blk_ptr)
233 * @brief Return the data type in the mbuf
235 #define IX_OSAL_MBUF_MTYPE(m_blk_ptr) \
236 (m_blk_ptr)->ix_mbuf.ix_type
240 * @ingroup IxOsalBufferMgt
242 * @def IX_OSAL_MBUF_FLAGS(m_blk_ptr)
244 * @brief Return the buffer flags
246 #define IX_OSAL_MBUF_FLAGS(m_blk_ptr) \
247 (m_blk_ptr)->ix_mbuf.ix_flags
251 * @ingroup IxOsalBufferMgt
253 * @def IX_OSAL_MBUF_NET_POOL(m_blk_ptr)
255 * @brief Return pointer to a network pool
257 #define IX_OSAL_MBUF_NET_POOL(m_blk_ptr) \
258 (m_blk_ptr)->ix_ctrl.ix_pool
263 * @ingroup IxOsalBufferMgt
265 * @def IX_OSAL_MBUF_PKT_LEN(m_blk_ptr)
267 * @brief Return the total length of all the data in
268 * the mbuf chain for this packet
270 #define IX_OSAL_MBUF_PKT_LEN(m_blk_ptr) \
271 (m_blk_ptr)->ix_mbuf.ix_PktLen
277 * @ingroup IxOsalBufferMgt
279 * @def IX_OSAL_MBUF_PRIV(m_blk_ptr)
281 * @brief Return the private field
283 #define IX_OSAL_MBUF_PRIV(m_blk_ptr) \
284 (m_blk_ptr)->ix_mbuf.ix_priv
289 * @ingroup IxOsalBufferMgt
291 * @def IX_OSAL_MBUF_SIGNATURE(m_blk_ptr)
293 * @brief Return the signature field of IX_OSAL_MBUF
295 #define IX_OSAL_MBUF_SIGNATURE(m_blk_ptr) \
296 (m_blk_ptr)->ix_ctrl.ix_signature
300 * @ingroup IxOsalBufferMgt
302 * @def IX_OSAL_MBUF_OSBUF_PTR(m_blk_ptr)
304 * @brief Return ix_osbuf_ptr field of IX_OSAL_MBUF, which is used to store OS-specific buffer pointer during a buffer conversion.
306 #define IX_OSAL_MBUF_OSBUF_PTR(m_blk_ptr) \
307 (m_blk_ptr)->ix_ctrl.ix_osbuf_ptr
311 * @ingroup IxOsalBufferMgt
313 * @def IX_OSAL_MBUF_ALLOCATED_BUFF_LEN(m_blk_ptr)
315 * @brief Return the allocated buffer size
317 #define IX_OSAL_MBUF_ALLOCATED_BUFF_LEN(m_blk_ptr) \
318 (m_blk_ptr)->ix_ctrl.ix_allocated_len
321 * @ingroup IxOsalBufferMgt
323 * @def IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(m_blk_ptr)
325 * @brief Return the allocated buffer pointer
327 #define IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(m_blk_ptr) \
328 (m_blk_ptr)->ix_ctrl.ix_allocated_data
332 /* Name length */
333 #define IX_OSAL_MBUF_POOL_NAME_LEN 64
336 /****************************************************
337 * Macros for buffer pool management
338 ****************************************************/
341 * @ingroup IxOsalBufferMgt
343 * @def IX_OSAL_MBUF_POOL_FREE_COUNT(m_pool_ptr
345 * @brief Return the total number of freed buffers left in the pool.
347 #define IX_OSAL_MBUF_POOL_FREE_COUNT(m_pool_ptr) \
348 ixOsalBuffPoolFreeCountGet(m_pool_ptr)
351 * @ingroup IxOsalBufferMgt
353 * @def IX_OSAL_MBUF_POOL_SIZE_ALIGN
355 * @brief This macro takes an integer as an argument and
356 * rounds it up to be a multiple of the memory cache-line
357 * size.
359 * @param int [in] size - the size integer to be rounded up
361 * @return int - the size, rounded up to a multiple of
362 * the cache-line size
364 #define IX_OSAL_MBUF_POOL_SIZE_ALIGN(size) \
365 ((((size) + (IX_OSAL_CACHE_LINE_SIZE - 1)) / \
366 IX_OSAL_CACHE_LINE_SIZE) * \
367 IX_OSAL_CACHE_LINE_SIZE)
369 /* Don't use this directly, use macro */
370 PUBLIC UINT32 ixOsalBuffPoolMbufAreaSizeGet (int count);
374 * @ingroup IxOsalBufferMgt
376 * @def IX_OSAL_MBUF_POOL_MBUF_AREA_SIZE_ALIGNED
378 * @brief This macro calculates, from the number of mbufs required, the
379 * size of the memory area required to contain the mbuf headers for the
380 * buffers in the pool. The size to be used for each mbuf header is
381 * rounded up to a multiple of the cache-line size, to ensure
382 * each mbuf header aligns on a cache-line boundary.
383 * This macro is used by IX_OSAL_MBUF_POOL_MBUF_AREA_ALLOC()
385 * @param int [in] count - the number of buffers the pool will contain
387 * @return int - the total size required for the pool mbuf area (aligned)
389 #define IX_OSAL_MBUF_POOL_MBUF_AREA_SIZE_ALIGNED(count) \
390 ixOsalBuffPoolMbufAreaSizeGet(count)
393 /* Don't use this directly, use macro */
394 PUBLIC UINT32 ixOsalBuffPoolDataAreaSizeGet (int count, int size);
398 * @ingroup IxOsalBufferMgt
400 * @def IX_OSAL_MBUF_POOL_DATA_AREA_SIZE_ALIGNED
402 * @brief This macro calculates, from the number of mbufs required and the
403 * size of the data portion for each mbuf, the size of the data memory area
404 * required. The size is adjusted to ensure alignment on cache line boundaries.
405 * This macro is used by IX_OSAL_MBUF_POOL_DATA_AREA_ALLOC()
408 * @param int [in] count - The number of mbufs in the pool.
409 * @param int [in] size - The desired size for each mbuf data portion.
410 * This size will be rounded up to a multiple of the
411 * cache-line size to ensure alignment on cache-line
412 * boundaries for each data block.
414 * @return int - the total size required for the pool data area (aligned)
416 #define IX_OSAL_MBUF_POOL_DATA_AREA_SIZE_ALIGNED(count, size) \
417 ixOsalBuffPoolDataAreaSizeGet((count), (size))
421 * @ingroup IxOsalBufferMgt
423 * @def IX_OSAL_MBUF_POOL_MBUF_AREA_ALLOC
425 * @brief Allocates the memory area needed for the number of mbuf headers
426 * specified by <i>count</i>.
427 * This macro ensures the mbuf headers align on cache line boundaries.
428 * This macro evaluates to a pointer to the memory allocated.
430 * @param int [in] count - the number of mbufs the pool will contain
431 * @param int [out] memAreaSize - the total amount of memory allocated
433 * @return void * - a pointer to the allocated memory area
435 #define IX_OSAL_MBUF_POOL_MBUF_AREA_ALLOC(count, memAreaSize) \
436 IX_OSAL_CACHE_DMA_MALLOC((memAreaSize = \
437 IX_OSAL_MBUF_POOL_MBUF_AREA_SIZE_ALIGNED(count)))
440 * @ingroup IxOsalBufferMgt
442 * @def IX_OSAL_MBUF_POOL_DATA_AREA_ALLOC
444 * @brief Allocates the memory pool for the data portion of the pool mbufs.
445 * The number of mbufs is specified by <i>count</i>. The size of the data
446 * portion of each mbuf is specified by <i>size</i>.
447 * This macro ensures the mbufs are aligned on cache line boundaries
448 * This macro evaluates to a pointer to the memory allocated.
450 * @param int [in] count - the number of mbufs the pool will contain
451 * @param int [in] size - the desired size (in bytes) required for the data
452 * portion of each mbuf. Note that this size may be
453 * rounded up to ensure alignment on cache-line
454 * boundaries.
455 * @param int [out] memAreaSize - the total amount of memory allocated
457 * @return void * - a pointer to the allocated memory area
459 #define IX_OSAL_MBUF_POOL_DATA_AREA_ALLOC(count, size, memAreaSize) \
460 IX_OSAL_CACHE_DMA_MALLOC((memAreaSize = \
461 IX_OSAL_MBUF_POOL_DATA_AREA_SIZE_ALIGNED(count,size)))
466 * @ingroup IxOsalBufferMgt
468 * @def IX_OSAL_MBUF_POOL_INIT
470 * @brief Wrapper macro for ixOsalPoolInit()
471 * See function description below for details.
473 #define IX_OSAL_MBUF_POOL_INIT(count, size, name) \
474 ixOsalPoolInit((count), (size), (name))
477 * @ingroup IxOsalBufferMgt
479 * @def IX_OSAL_MBUF_NO_ALLOC_POOL_INIT
481 * @return Pointer to the new pool or NULL if the initialization failed.
483 * @brief Wrapper macro for ixOsalNoAllocPoolInit()
484 * See function description below for details.
487 #define IX_OSAL_MBUF_NO_ALLOC_POOL_INIT(bufPtr, dataPtr, count, size, name) \
488 ixOsalNoAllocPoolInit( (bufPtr), (dataPtr), (count), (size), (name))
491 * @ingroup IxOsalBufferMgt
493 * @def IX_OSAL_MBUF_POOL_GET
495 * @brief Wrapper macro for ixOsalMbufAlloc()
496 * See function description below for details.
498 #define IX_OSAL_MBUF_POOL_GET(poolPtr) \
499 ixOsalMbufAlloc(poolPtr)
502 * @ingroup IxOsalBufferMgt
504 * @def IX_OSAL_MBUF_POOL_PUT
506 * @brief Wrapper macro for ixOsalMbufFree()
507 * See function description below for details.
509 #define IX_OSAL_MBUF_POOL_PUT(bufPtr) \
510 ixOsalMbufFree(bufPtr)
513 * @ingroup IxOsalBufferMgt
515 * @def IX_OSAL_MBUF_POOL_PUT_CHAIN
517 * @brief Wrapper macro for ixOsalMbufChainFree()
518 * See function description below for details.
520 #define IX_OSAL_MBUF_POOL_PUT_CHAIN(bufPtr) \
521 ixOsalMbufChainFree(bufPtr)
524 * @ingroup IxOsalBufferMgt
526 * @def IX_OSAL_MBUF_POOL_SHOW
528 * @brief Wrapper macro for ixOsalMbufPoolShow()
529 * See function description below for details.
531 #define IX_OSAL_MBUF_POOL_SHOW(poolPtr) \
532 ixOsalMbufPoolShow(poolPtr)
535 * @ingroup IxOsalBufferMgt
537 * @def IX_OSAL_MBUF_POOL_MDATA_RESET
539 * @brief Wrapper macro for ixOsalMbufDataPtrReset()
540 * See function description below for details.
542 #define IX_OSAL_MBUF_POOL_MDATA_RESET(bufPtr) \
543 ixOsalMbufDataPtrReset(bufPtr)
546 * @ingroup IxOsalBufferMgt
548 * @def IX_OSAL_MBUF_POOL_UNINIT
550 * @brief Wrapper macro for ixOsalBuffPoolUninit()
551 * See function description below for details.
553 #define IX_OSAL_MBUF_POOL_UNINIT(m_pool_ptr) \
554 ixOsalBuffPoolUninit(m_pool_ptr)
557 * Include OS-specific bufferMgt definitions
559 #include "IxOsalOsBufferMgt.h"
563 * @ingroup IxOsalBufferMgt
565 * @def IX_OSAL_CONVERT_OSBUF_TO_IXPBUF( osBufPtr, ixpBufPtr)
567 * @brief Convert pre-allocated os-specific buffer format to OSAL IXP_BUF (IX_OSAL_MBUF) format.
568 * It is users' responsibility to provide pre-allocated and valid buffer pointers.
569 * @param osBufPtr (in) - a pre-allocated os-specific buffer pointer.
570 * @param ixpBufPtr (in)- a pre-allocated OSAL IXP_BUF pointer
571 * @return None
573 #define IX_OSAL_CONVERT_OSBUF_TO_IXPBUF( osBufPtr, ixpBufPtr) \
574 IX_OSAL_OS_CONVERT_OSBUF_TO_IXPBUF( osBufPtr, ixpBufPtr)
578 * @ingroup IxOsalBufferMgt
580 * @def IX_OSAL_CONVERT_IXPBUF_TO_OSBUF( ixpBufPtr, osBufPtr)
582 * @brief Convert pre-allocated OSAL IXP_BUF (IX_OSAL_MBUF) format to os-specific buffer pointers.
583 * @param ixpBufPtr (in) - OSAL IXP_BUF pointer
584 * @param osBufPtr (out) - os-specific buffer pointer.
585 * @return None
588 #define IX_OSAL_CONVERT_IXPBUF_TO_OSBUF( ixpBufPtr, osBufPtr) \
589 IX_OSAL_OS_CONVERT_IXPBUF_TO_OSBUF( ixpBufPtr, osBufPtr)
592 PUBLIC IX_OSAL_MBUF_POOL *ixOsalPoolInit (UINT32 count,
593 UINT32 size, const char *name);
595 PUBLIC IX_OSAL_MBUF_POOL *ixOsalNoAllocPoolInit (void *poolBufPtr,
596 void *poolDataPtr,
597 UINT32 count,
598 UINT32 size,
599 const char *name);
601 PUBLIC IX_OSAL_MBUF *ixOsalMbufAlloc (IX_OSAL_MBUF_POOL * pool);
603 PUBLIC IX_OSAL_MBUF *ixOsalMbufFree (IX_OSAL_MBUF * mbuf);
605 PUBLIC void ixOsalMbufChainFree (IX_OSAL_MBUF * mbuf);
607 PUBLIC void ixOsalMbufDataPtrReset (IX_OSAL_MBUF * mbuf);
609 PUBLIC void ixOsalMbufPoolShow (IX_OSAL_MBUF_POOL * pool);
611 PUBLIC IX_STATUS ixOsalBuffPoolUninit (IX_OSAL_MBUF_POOL * pool);
613 PUBLIC UINT32 ixOsalBuffPoolFreeCountGet(IX_OSAL_MBUF_POOL * pool);
617 * @} IxOsalBufferMgt
621 #endif /* IxOsalBufferMgt_H */