📄 mplcommon.h
字号:
//**********************************************************************
//
// MPLCOMMON.H
//
// Copyright (c) 2004 National Semiconductor Corporation.
// All Rights Reserved
//
// Defines data structures that are common between the MPL layer
// and any higher layer or NSM.
// This is included via mplclient.h - Do not include this directly!
//
//**********************************************************************
#ifndef _MPLCOMMON_H_
#define _MPLCOMMON_H_
//**********************************************************************
// MPL Status Return Codes
//**********************************************************************
// Test
typedef unsigned int MPL_STATUS;
#define NS_STATUS_SUCCESS 0x00
#define NS_STATUS_FAILURE 0x01
#define NS_STATUS_NOT_PRESENT 0x02
#define NS_STATUS_NO_MORE_ITEMS 0x03
#define NS_STATUS_INVALID_PARM 0x04
#define NS_STATUS_INVALID_PARAMETER NS_STATUS_INVALID_PARM //For Compatibility
#define NS_STATUS_RESOURCES 0x05
#define NS_STATUS_NOT_SUPPORTED 0x06
#define NS_STATUS_ABORTED 0x07
#define NS_STATUS_HARDWARE_FAILURE 0x08
#define NS_STATUS_ASYNCH_COMPLETION 0x09
#define NS_STATUS_TIMEOUT 0x0A
#define NS_STATUS_OVERFLOW 0x0B
//**********************************************************************
// Some common data types we use.
//**********************************************************************
#ifndef NULL
#define NULL (void*)0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define MTU_ETHERNET 1518
#define HDR_ETHERNET 14
#define IEEE_802_3_FCS_HASH_FUNC 0x04C11DB6
//**********************************************************************
// CMD-STATUS bit definitions for the Transmit and Receive descriptors
// Defined here since the MplSetPacketXXX and MplQueryPacketXXX macros
// defined in mplclient.h need them
//**********************************************************************
// Cmdsts bit Definitions
#define CS_OWN 0x80000000
#define CS_MORE 0x40000000
#define CS_INTR 0x20000000
#define CS_SUPCRC 0x10000000
#define CS_OK 0x08000000
#define CS_OWN_INTR 0xA0000000 // OWN+INTR
#define ECS_VPKT 0x00010000 // Ext Status - VLAN
// CmdSts Tx Err bits
#define CS_ERR_TXA 0x04000000
#define CS_ERR_TFU 0x02000000
#define CS_ERR_TX_CRS 0x01000000
#define CS_ERR_TX_TD 0x00800000
#define CS_ERR_TX_ED 0x00400000
#define CS_ERR_TX_OWC 0x00200000
#define CS_ERR_TX_EC 0x00100000
// CmdSts Rx Err bits
#define CS_RXA 0x04000000
#define CS_ERR_RXO 0x02000000
#define CS_ERR_RX_LONG 0x00400000
#define CS_ERR_RX_RUNT 0x00200000
#define CS_ERR_RX_ISE 0x00100000
#define CS_ERR_RX_CRCE 0x00080000
#define CS_ERR_RX_FAE 0x00040000
#define CS_LBP 0x00020000
#define CS_ERR_RX_COL 0x00010000
#define CS_LEN_MASK 0x00000FFF
#define CS_MAX_FRAG_SIZE 0x07FF
// Endian Swapped Cmdsts definitions
#ifdef MPL_BIG_ENDIAN
#define CS_OWN_ES 0x00000080
#define CS_MORE_ES 0x00000040
#define CS_INTR_ES 0x00000020
#define CS_OK_ES 0x00000008
#define CS_LEN_MASK_ES 0xFF0F0000
#else
#define CS_OWN_ES CS_OWN
#define CS_MORE_ES CS_MORE
#define CS_INTR_ES CS_INTR
#define CS_OK_ES CS_OK
#define CS_LEN_MASK_ES CS_LEN_MASK
#endif // MPL_BIG_ENDIAN
//**********************************************************************
// Data structures and macros for MPL list management library
//**********************************************************************
typedef struct _MPL_LIST_NODE {
struct _MPL_LIST_NODE *next;
struct _MPL_LIST_NODE *prev;
} MPL_LIST_NODE;
typedef struct _MPL_LIST {
// These two should be at the start always
MPL_LIST_NODE *next;
MPL_LIST_NODE *prev;
NS_VOID *lock;
NS_UINT entries;
} MPL_LIST;
// List Locking APIs
//*****************************************************************************
// MPL_LIST_LOCK
//
// Clients should use this API to lock a list - required for traversal APIs
// only. The add/del APIs implicitly lock the list.
//
// Parameters
// list
// A pointer to the list
//
// Return Value
//
//*****************************************************************************
#define MPL_LIST_LOCK(list) \
if ((list)->lock) \
OaiAcquireLock((list)->lock)
//*****************************************************************************
// MPL_LIST_UNLOCK
//
// Clients should use this API to lock a list - required for traversal APIs
// only. The add/del APIs implicitly lock the list.
//
// Parameters
// list
// A pointer to the list
//
// Return Value
//
//*****************************************************************************
#define MPL_LIST_UNLOCK(list) \
if ((list)->lock) \
OaiReleaseLock((list)->lock)
// Traversal APIs
//*****************************************************************************
// MPL_LIST_GET_HEAD
//
// Clients should use this API to get the head(first) node in a list
//
// Parameters
// list
// A pointer to the list
//
// Return Value
// Pointer to the head node in the list
//
//*****************************************************************************
#define MPL_LIST_GET_HEAD(list) \
(list)->next
//*****************************************************************************
// MPL_LIST_GET_TAIL
//
// Clients should use this API to get the tail(last) node in a list
//
// Parameters
// list
// A pointer to the list
//
// Return Value
// Pointer to the tail node in the list
//
//*****************************************************************************
#define MPL_LIST_GET_TAIL(list) \
(list)->prev
//*****************************************************************************
// MPL_LIST_GET_NEXT
//
// Clients should use this API to get the tail(last) node in a list
// Note: Clients should follow this call with MPL_LIST_CHK_END to verify if
// the node returned by this API is valid i.e. we have not looped back to the
// begining of the list
//
// Parameters
// node
// A pointer to the current node
//
// Return Value
// Pointer to the next node
//
//*****************************************************************************
#define MPL_LIST_GET_NEXT(node) \
(node)->next
//*****************************************************************************
// MPL_LIST_GET_SIZE
//
// Clients should use this API to get the number of entries in the list
//
// Parameters
// list
// A pointer to the list
//
// Return Value
// Count of entries in the list
//
//*****************************************************************************
#define MPL_LIST_GET_SIZE(list) \
(list)->entries
//*****************************************************************************
// MPL_LIST_CHK_END
//
// Clients should use this API to check if a node is valid i.e. if the
// traversal has looped back.
// Note: Client should always check the validity of a node
// that they get from MPL_LIST_GET_NEXT by calling this API.
//
// Parameters
// list
// A pointer to the list
// node
// The node that needs to be verified
//
// Return Value
// NS_TRUE : If we looped back and this node is a repeat
// NS_FALSE: If the node is valid and we have'nt looped back
//
//*****************************************************************************
#define MPL_LIST_CHK_END(list, node) \
(((node) == (MPL_LIST_NODE *)(list)) ? NS_TRUE : NS_FALSE)
//*****************************************************************************
// MPL_LIST_GET_ENTRY
//
// Clients should use this API to get the parent container structure that
// holds the MPL_LIST_NODE entry.
//
// Parameters
// node
// The MPL_LIST_NODE pointer that in part of the parent container. This
// node pointer is used by MPL_LIST library to track the list.
// type
// The data structure that defines the type for the parent container
// structure. For exp. struct xyz, EHI_SOCK_STRUCT etc. This is needed
// for since the typeof operator is not supported in all platforms.
// member
// The name that client uses within the parent container structure
// for the MPL_LIST_NODE entry.
//
// Return Value
// A pointer to the parent container structure that hold the MPL_LIST_NODE
//
//*****************************************************************************
#define MPL_LIST_GET_ENTRY(node, type, member) \
((type *)((NS_ADDR)(node) - (NS_ADDR)(&((type *)0)->member)))
#if defined(__cplusplus)
extern "C"
{
#endif
MPL_STATUS
MplListInit(
IN MPL_LIST *list,
IN NS_BOOLEAN safe);
NS_VOID
MplListDeInit(
IN MPL_LIST *list);
NS_VOID
MplListAddHead(
IN MPL_LIST *list,
IN MPL_LIST_NODE *newNode);
NS_VOID
MplListAddTail(
IN MPL_LIST *list,
IN MPL_LIST_NODE *newNode);
NS_VOID
MplListDel(
IN MPL_LIST *list,
IN MPL_LIST_NODE *node);
#if defined(__cplusplus)
}
#endif
#endif // _MPLCOMMON_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -