/* Copyright (c) 2008-2012 Freescale Semiconductor, Inc1* All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233/**************************************************************************//**34@File ncsw_ext.h3536@Description General NetCommSw Standard Definitions37*//***************************************************************************/3839#ifndef __NCSW_EXT_H40#define __NCSW_EXT_H414243#include "memcpy_ext.h"4445#define WRITE_BLOCK IOMemSet32 /* include memcpy_ext.h */46#define COPY_BLOCK Mem2IOCpy32 /* include memcpy_ext.h */4748#define PTR_TO_UINT(_ptr) ((uintptr_t)(_ptr))49#define UINT_TO_PTR(_val) ((void*)(uintptr_t)(_val))5051#define PTR_MOVE(_ptr, _offset) (void*)((uint8_t*)(_ptr) + (_offset))525354#define WRITE_UINT8_UINT24(arg, data08, data24) \55WRITE_UINT32(arg,((uint32_t)(data08)<<24)|((uint32_t)(data24)&0x00FFFFFF))56#define WRITE_UINT24_UINT8(arg, data24, data08) \57WRITE_UINT32(arg,((uint32_t)(data24)<< 8)|((uint32_t)(data08)&0x000000FF))5859/* Little-Endian access macros */6061#define WRITE_UINT16_LE(arg, data) \62WRITE_UINT16((arg), SwapUint16(data))6364#define WRITE_UINT32_LE(arg, data) \65WRITE_UINT32((arg), SwapUint32(data))6667#define WRITE_UINT64_LE(arg, data) \68WRITE_UINT64((arg), SwapUint64(data))6970#define GET_UINT16_LE(arg) \71SwapUint16(GET_UINT16(arg))7273#define GET_UINT32_LE(arg) \74SwapUint32(GET_UINT32(arg))7576#define GET_UINT64_LE(arg) \77SwapUint64(GET_UINT64(arg))7879/* Write and Read again macros */80#define WRITE_UINT_SYNC(size, arg, data) \81do { \82WRITE_UINT##size((arg), (data)); \83CORE_MemoryBarrier(); \84} while (0)8586#define WRITE_UINT8_SYNC(arg, data) WRITE_UINT_SYNC(8, (arg), (data))8788#define WRITE_UINT16_SYNC(arg, data) WRITE_UINT_SYNC(16, (arg), (data))89#define WRITE_UINT32_SYNC(arg, data) WRITE_UINT_SYNC(32, (arg), (data))9091#define MAKE_UINT64(high32, low32) (((uint64_t)high32 << 32) | (low32))929394/*----------------------*/95/* Miscellaneous macros */96/*----------------------*/9798#define UNUSED(_x) ((void)(_x))99100#define KILOBYTE 0x400UL /* 1024 */101#define MEGABYTE (KILOBYTE * KILOBYTE) /* 1024*1024 */102#define GIGABYTE ((uint64_t)(KILOBYTE * MEGABYTE)) /* 1024*1024*1024 */103#define TERABYTE ((uint64_t)(KILOBYTE * GIGABYTE)) /* 1024*1024*1024*1024 */104105#ifndef NO_IRQ106#define NO_IRQ (0)107#endif108#define NCSW_MASTER_ID (0)109110/* Macro for checking if a number is a power of 2 */111#define POWER_OF_2(n) (!((n) & ((n)-1)))112113/* Macro for calculating log of base 2 */114#define LOG2(num, log2Num) \115do \116{ \117uint64_t tmp = (num); \118log2Num = 0; \119while (tmp > 1) \120{ \121log2Num++; \122tmp >>= 1; \123} \124} while (0)125126#define NEXT_POWER_OF_2(_num, _nextPow) \127do \128{ \129if (POWER_OF_2(_num)) \130_nextPow = (_num); \131else \132{ \133uint64_t tmp = (_num); \134_nextPow = 1; \135while (tmp) \136{ \137_nextPow <<= 1; \138tmp >>= 1; \139} \140} \141} while (0)142143/* Ceiling division - not the fastest way, but safer in terms of overflow */144#define DIV_CEIL(x,y) (((x)/(y)) + (((((x)/(y))*(y)) == (x)) ? 0 : 1))145146/* Round up a number to be a multiple of a second number */147#define ROUND_UP(x,y) ((((x) + (y) - 1) / (y)) * (y))148149/* Timing macro for converting usec units to number of ticks. */150/* (number of usec * clock_Hz) / 1,000,000) - since */151/* clk is in MHz units, no division needed. */152#define USEC_TO_CLK(usec,clk) ((usec) * (clk))153#define CYCLES_TO_USEC(cycles,clk) ((cycles) / (clk))154155/* Timing macros for converting between nsec units and number of clocks. */156#define NSEC_TO_CLK(nsec,clk) DIV_CEIL(((nsec) * (clk)), 1000)157#define CYCLES_TO_NSEC(cycles,clk) (((cycles) * 1000) / (clk))158159/* Timing macros for converting between psec units and number of clocks. */160#define PSEC_TO_CLK(psec,clk) DIV_CEIL(((psec) * (clk)), 1000000)161#define CYCLES_TO_PSEC(cycles,clk) (((cycles) * 1000000) / (clk))162163/* Min, Max macros */164#define IN_RANGE(min,val,max) ((min)<=(val) && (val)<=(max))165166#define ABS(a) ((a<0)?(a*-1):a)167168#if !(defined(ARRAY_SIZE))169#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))170#endif /* !defined(ARRAY_SIZE) */171172173/* possible alignments */174#define HALF_WORD_ALIGNMENT 2175#define WORD_ALIGNMENT 4176#define DOUBLE_WORD_ALIGNMENT 8177#define BURST_ALIGNMENT 32178179#define HALF_WORD_ALIGNED 0x00000001180#define WORD_ALIGNED 0x00000003181#define DOUBLE_WORD_ALIGNED 0x00000007182#define BURST_ALIGNED 0x0000001f183#ifndef IS_ALIGNED184#define IS_ALIGNED(n,align) (!((uint32_t)(n) & (align - 1)))185#endif /* IS_ALIGNED */186187188#define LAST_BUF 1189#define FIRST_BUF 2190#define SINGLE_BUF (LAST_BUF | FIRST_BUF)191#define MIDDLE_BUF 4192193#define ARRAY_END -1194195#define ILLEGAL_BASE (~0)196197#define BUF_POSITION(first, last) state[(!!(last))<<1 | !!(first)]198#define DECLARE_POSITION static uint8_t state[4] = { (uint8_t)MIDDLE_BUF, (uint8_t)FIRST_BUF, (uint8_t)LAST_BUF, (uint8_t)SINGLE_BUF };199200201/**************************************************************************//**202@Description Timers operation mode203*//***************************************************************************/204typedef enum e_TimerMode205{206e_TIMER_MODE_INVALID = 0,207e_TIMER_MODE_FREE_RUN, /**< Free run - counter continues to increase208after reaching the reference value. */209e_TIMER_MODE_PERIODIC, /**< Periodic - counter restarts counting from 0210after reaching the reference value. */211e_TIMER_MODE_SINGLE /**< Single (one-shot) - counter stops counting212after reaching the reference value. */213} e_TimerMode;214215216/**************************************************************************//**217@Description Enumeration (bit flags) of communication modes (Transmit,218receive or both).219*//***************************************************************************/220typedef enum e_CommMode221{222e_COMM_MODE_NONE = 0, /**< No transmit/receive communication */223e_COMM_MODE_RX = 1, /**< Only receive communication */224e_COMM_MODE_TX = 2, /**< Only transmit communication */225e_COMM_MODE_RX_AND_TX = 3 /**< Both transmit and receive communication */226} e_CommMode;227228/**************************************************************************//**229@Description General Diagnostic Mode230*//***************************************************************************/231typedef enum e_DiagMode232{233e_DIAG_MODE_NONE = 0, /**< Normal operation; no diagnostic mode */234e_DIAG_MODE_CTRL_LOOPBACK, /**< Loopback in the controller */235e_DIAG_MODE_CHIP_LOOPBACK, /**< Loopback in the chip but not in the236controller; e.g. IO-pins, SerDes, etc. */237e_DIAG_MODE_PHY_LOOPBACK, /**< Loopback in the external PHY */238e_DIAG_MODE_EXT_LOOPBACK, /**< Loopback in the external line (beyond the PHY) */239e_DIAG_MODE_CTRL_ECHO, /**< Echo incoming data by the controller */240e_DIAG_MODE_PHY_ECHO /**< Echo incoming data by the PHY */241} e_DiagMode;242243/**************************************************************************//**244@Description Possible RxStore callback responses.245*//***************************************************************************/246typedef enum e_RxStoreResponse247{248e_RX_STORE_RESPONSE_PAUSE /**< Pause invoking callback with received data;249in polling mode, start again invoking callback250only next time user invokes the receive routine;251in interrupt mode, start again invoking callback252only next time a receive event triggers an interrupt;253in all cases, received data that are pending are not254lost, rather, their processing is temporarily deferred;255in all cases, received data are processed in the order256in which they were received. */257, e_RX_STORE_RESPONSE_CONTINUE /**< Continue invoking callback with received data. */258} e_RxStoreResponse;259260261/**************************************************************************//**262@Description General Handle263*//***************************************************************************/264typedef void * t_Handle; /**< handle, used as object's descriptor */265266/**************************************************************************//**267@Description MUTEX type268*//***************************************************************************/269typedef uint32_t t_Mutex;270271/**************************************************************************//**272@Description Error Code.273274The high word of the error code is the code of the software275module (driver). The low word is the error type (e_ErrorType).276To get the values from the error code, use GET_ERROR_TYPE()277and GET_ERROR_MODULE().278*//***************************************************************************/279typedef uint32_t t_Error;280281/**************************************************************************//**282@Description General prototype of interrupt service routine (ISR).283284@Param[in] handle - Optional handle of the module handling the interrupt.285286@Return None287*//***************************************************************************/288typedef void (t_Isr)(t_Handle handle);289290/**************************************************************************//**291@Anchor mem_attr292293@Collection Memory Attributes294295Various attributes of memory partitions. These values may be296or'ed together to create a mask of all memory attributes.297@{298*//***************************************************************************/299#define MEMORY_ATTR_CACHEABLE 0x00000001300/**< Memory is cacheable */301#define MEMORY_ATTR_QE_2ND_BUS_ACCESS 0x00000002302/**< Memory can be accessed by QUICC Engine303through its secondary bus interface */304305/* @} */306307308/**************************************************************************//**309@Function t_GetBufFunction310311@Description User callback function called by driver to get data buffer.312313User provides this function. Driver invokes it.314315@Param[in] h_BufferPool - A handle to buffer pool manager316@Param[out] p_BufContextHandle - Returns the user's private context that317should be associated with the buffer318319@Return Pointer to data buffer, NULL if error320*//***************************************************************************/321typedef uint8_t * (t_GetBufFunction)(t_Handle h_BufferPool,322t_Handle *p_BufContextHandle);323324/**************************************************************************//**325@Function t_PutBufFunction326327@Description User callback function called by driver to return data buffer.328329User provides this function. Driver invokes it.330331@Param[in] h_BufferPool - A handle to buffer pool manager332@Param[in] p_Buffer - A pointer to buffer to return333@Param[in] h_BufContext - The user's private context associated with334the returned buffer335336@Return E_OK on success; Error code otherwise337*//***************************************************************************/338typedef t_Error (t_PutBufFunction)(t_Handle h_BufferPool,339uint8_t *p_Buffer,340t_Handle h_BufContext);341342/**************************************************************************//**343@Function t_PhysToVirt344345@Description Translates a physical address to the matching virtual address.346347@Param[in] addr - The physical address to translate.348349@Return Virtual address.350*//***************************************************************************/351typedef void * t_PhysToVirt(physAddress_t addr);352353/**************************************************************************//**354@Function t_VirtToPhys355356@Description Translates a virtual address to the matching physical address.357358@Param[in] addr - The virtual address to translate.359360@Return Physical address.361*//***************************************************************************/362typedef physAddress_t t_VirtToPhys(void *addr);363364/**************************************************************************//**365@Description Buffer Pool Information Structure.366*//***************************************************************************/367typedef struct t_BufferPoolInfo368{369t_Handle h_BufferPool; /**< A handle to the buffer pool manager */370t_GetBufFunction *f_GetBuf; /**< User callback to get a free buffer */371t_PutBufFunction *f_PutBuf; /**< User callback to return a buffer */372uint16_t bufferSize; /**< Buffer size (in bytes) */373374t_PhysToVirt *f_PhysToVirt; /**< User callback to translate pool buffers375physical addresses to virtual addresses */376t_VirtToPhys *f_VirtToPhys; /**< User callback to translate pool buffers377virtual addresses to physical addresses */378} t_BufferPoolInfo;379380381/**************************************************************************//**382@Description User callback function called by driver when transmit completed.383384User provides this function. Driver invokes it.385386@Param[in] h_App - Application's handle, as was provided to the387driver by the user388@Param[in] queueId - Transmit queue ID389@Param[in] p_Data - Pointer to the data buffer390@Param[in] h_BufContext - The user's private context associated with391the given data buffer392@Param[in] status - Transmit status and errors393@Param[in] flags - Driver-dependent information394*//***************************************************************************/395typedef void (t_TxConfFunction)(t_Handle h_App,396uint32_t queueId,397uint8_t *p_Data,398t_Handle h_BufContext,399uint16_t status,400uint32_t flags);401402/**************************************************************************//**403@Description User callback function called by driver with receive data.404405User provides this function. Driver invokes it.406407@Param[in] h_App - Application's handle, as was provided to the408driver by the user409@Param[in] queueId - Receive queue ID410@Param[in] p_Data - Pointer to the buffer with received data411@Param[in] h_BufContext - The user's private context associated with412the given data buffer413@Param[in] length - Length of received data414@Param[in] status - Receive status and errors415@Param[in] position - Position of buffer in frame416@Param[in] flags - Driver-dependent information417418@Retval e_RX_STORE_RESPONSE_CONTINUE - order the driver to continue Rx419operation for all ready data.420@Retval e_RX_STORE_RESPONSE_PAUSE - order the driver to stop Rx operation.421*//***************************************************************************/422typedef e_RxStoreResponse (t_RxStoreFunction)(t_Handle h_App,423uint32_t queueId,424uint8_t *p_Data,425t_Handle h_BufContext,426uint32_t length,427uint16_t status,428uint8_t position,429uint32_t flags);430431432#endif /* __NCSW_EXT_H */433434435