⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oai.h

📁 NATIONAL公司DP83816芯片Linux下驱动
💻 H
字号:

//*****************************************************************************
//
//  OAI.H
//
//  Copyright (c) 2004 National Semiconductor Corporation.
//  All Rights Reserved
//
//  This header file contains OS-specific services, data-type definitions,
//  etc. required by MPL. This file must be customized for each OS/Platform
//  and re-named OAI.H.  A version of this file will typically be created 
//  for each platform and exist in the NSM driver's source directory.
//
//*****************************************************************************

#ifndef _OAI_H_
#define _OAI_H_

// This brings in all the NSM specific definitions
#include <nsmos.h>

//******************************** MPL General Options ************************
// Modify the following to set the desire MPL options
//*****************************************************************************

// On Big endian machines, uncomment the following line or define it via
// the compiler command line
//  NOTE!!! = Read the instructions under the OaiReadIoXX and OaiWriteIoXX too!
// #define MPL_BIG_ENDIAN

//**************************** END OF MPL General Options *********************

//******************************** MPL Board Options ************************
// Modify the following to set options based on board design
//*****************************************************************************
// On MacPhyter boards *without* a EEPROM on them disable the below
//#define MPL_NO_EEPROM

// On MacPhyter boards that use an EXTERNAL Phy disable the below
// #define MPL_EXTERNAL_PHY
//**************************** END OF MPL Board Options *********************


//******************************** MPL Diag Mode ******************************
// Modify the following to enable MPL Diagnostics Mode
//*****************************************************************************

#ifdef NSM_DIAG_MODE
#define MPL_DIAG_MODE
#endif

//******************************** MPL Task Offload ***************************
// Modify the following to define MPL task offload behavior
//*****************************************************************************

// Uncomment to enable statistics collection task
//#define MPL_TASK_STAT

// Uncomment to enable VLAN offload task
#define MPL_TASK_VLAN

// Uncomment to enable multicast filtering task
#define MPL_TASK_RECEIVE_FILTER

// Uncomment to enable checksum offload task
//#define MPL_TASK_STAT

//**************************** END OF MPL Task Offload Options ****************


//******************** MPL COMPILER INDEPENDENT DATA TYPES ********************
// Modify the following to define MPL data types in terms of native
// compiler data types.
//*****************************************************************************

// Note: On platforms where the natural integer size is less then 32-bits
// in size (eg 16-bit platforms), NS_UINT and NS_SINT must be defined as a 
// data type no less then 32-bits in size.
typedef unsigned int        NS_UINT;
typedef int                 NS_SINT;

// Fixed width data types/pointers  
typedef unsigned char       NS_CHAR;
typedef unsigned char       NS_UINT8;
typedef char                NS_SINT8;
typedef unsigned short      NS_UINT16;
typedef short               NS_SINT16;
typedef unsigned long       NS_UINT32;
typedef long                NS_SINT32;

// Abstract data type for physical address references
typedef unsigned int        NS_ADDR;

//**************** END OF MPL COMPILER INDEPENDENT DATA TYPES *****************

// Defines the maximum number of physical adapters supported by MPL.
// Customize this value appropriate to the environment.
#define MPL_MAX_ADAPTERS        8

//******************* OAI DATA DECLARATIONS (DO NOT MODIFY) *******************

//**********************************************************************
// Function parameter annotation macros.
//**********************************************************************
#ifndef IN
    #define IN 
#endif // IN
#ifndef OUT
    #define OUT
#endif // OUT

// Void types
typedef void                NS_VOID;

// Boolean data type
typedef NS_UINT             NS_BOOLEAN;
#define NS_TRUE             1
#define NS_FALSE            0

// Handle structure for returning module opaque fields
typedef NS_UINT     MPL_HANDLE;

// timer callback function pointer (see OaixxxTimer functions)
typedef NS_VOID (MPL_TIMERCALLBACK)(NS_VOID *pTimerArg);

// Mac address
typedef NS_UINT8 *MPL_MAC_ADDR;  

// handle for DMA region (see OaiAlloc/FreeDmaRegion)
typedef struct _MPL_MEM_REGION {
    NS_VOID *pAddr;    // aligned (as requested in alloc request) region ptr, logical
    NS_ADDR  phyAddr;  // aligned (as requested in alloc request) region ptr, physical
} MPL_MEM_REGION;

// NSM DMA Mem region descriptor (derived from above)
typedef struct _NSM_MEM_REGION {
    // In line with MPL_MEM_REGION
    NS_VOID *pAddr;    // aligned (as requested in alloc request) region ptr, logical
    NS_ADDR  phyAddr;  // aligned (as requested in alloc request) region ptr, physical
   
    // All NSM Extensions
    NS_UINT  size;
} NSM_MEM_REGION;

//************************** OAI FUNCTION PROTOTYPES **************************
// The following are function declarations of OS services required by MPL.
// Each function must be implemented in using native OS API's and linked
// with MPL
//*****************************************************************************

#if defined(__cplusplus)
extern "C"
{
#endif

//+++++ I/O access Functions
// BIG Endian Note!!
//  In some architectures or specifically the kernel ports have IO APIs
//  e.g inl, readl, outl or writel etc do the required swaps - Since MPL
//  does a similar swap too we would end with no swap at all. Hence to
//  handle such unique kernel ports it is important to swap the data (16/32)
//  in the functions below - This would result in an additional swap 
//  correcting the data

//Read from PCI memory-mapped or  IO location 'pAddr'.
#ifdef NSM_IO_MAP
#define OaiIoRead32(pClientDevHndl, pAddr) \
         (NS_UINT32)inl((NS_UINT32)(pAddr))

#define OaiIoRead16(pClientDevHndl, pAddr) \
         (NS_UINT16)inw((NS_UINT32)(pAddr))

#define OaiIoRead8(pClientDevHndl, pAddr) \
         (NS_UINT8)inb((NS_UINT32)(pAddr))

#else //NSM_IO_MAP

#define OaiIoRead32(pClientDevHndl, pAddr) \
         (NS_UINT32)readl((pAddr))

#define OaiIoRead16(pClientDevHndl, pAddr) \
         (NS_UINT16)readw((pAddr))

#define OaiIoRead8(pClientDevHndl, pAddr) \
         (NS_UINT8)readb((pAddr))
#endif //NSM_IO_MAP

//Write to PCI memory-mapped or IO location 'pAddr'.
#ifdef NSM_IO_MAP
#define OaiIoWrite32(pClientDevHndl, pAddr, writeData) \
         outl((NS_UINT32)(writeData), (NS_UINT32)(pAddr))

#define OaiIoWrite16(pClientDevHndl, pAddr, writeData) \
         outw((NS_UINT16)(writeData), (NS_UINT32)(pAddr))

#define OaiIoWrite8(pClientDevHndl, pAddr, writeData) \
         outb((NS_UINT8)(writeData), (NS_UINT32)(pAddr))

#else //NSM_IO_MAP

#define OaiIoWrite32(pClientDevHndl, pAddr, writeData) \
         writel((NS_UINT32)(writeData), (pAddr))

#define OaiIoWrite16(pClientDevHndl, pAddr, writeData) \
         writew((NS_UINT16)(writeData), (pAddr))

#define OaiIoWrite8(pClientDevHndl, pAddr, writeData) \
         writeb((NS_UINT8)(writeData), (pAddr))
#endif //NSM_IO_MAP

//+++++ Host Memory Functions

//Allocate/free a region in host memory suitable for DMA
NS_BOOLEAN
OaiAllocDmaRegion(
    IN NS_VOID          *pClientDevHndl,
    IN NS_UINT           size,
    IN NS_UINT           byteAlignment,
    OUT MPL_MEM_REGION **pRgnHndl
    );

NS_VOID
OaiFreeDmaRegion(
    IN NS_VOID            *pClientDevHndl,
    IN MPL_MEM_REGION     *pRgnHndl
    );

//Allocate/free general purpose host memory
#define OaiMalloc(regionSize) \
         kmalloc((regionSize), GFP_KERNEL)

#define OaiFree(regionSize, startAddrLogical) \
         kfree((startAddrLogical))

//Copy/zero host memory
#define OaiMemCopy(dest, src, len) \
         memcpy((void *)(dest), (void *)(src), (len))

#define OaiZeroMem(pMemRegion, regionSize) \
         memset((void *)(pMemRegion), 0x0, (regionSize))

//+++++ Timer Functions

//Delay program execution for 'sleepInterval' usec
#define OaiSleep(sleepInterval) { \
         if ((sleepInterval) > 1000)              \
            mdelay((sleepInterval)/1000);         \
         else                                     \
            udelay((sleepInterval));              \
         }

//Return 10ms tick count
#define OaiGetTickCount() jiffies

//Allocate/free/start/cancel periodic timer w/ callback 'pTimerFunction'
NS_BOOLEAN
OaiCreateTimer( 
    IN MPL_TIMERCALLBACK  pTimerFunction,
    IN NS_VOID           *pTimerArg,
    OUT NS_VOID         **pTimerHandle
    );

NS_VOID
OaiDeleteTimer(
    IN NS_VOID *pTimerHandle
    );

NS_VOID 
OaiStartTimer(
    IN NS_VOID *pTimerHandle,
    IN NS_UINT  delayInMsec
    );

NS_BOOLEAN
OaiCancelTimer(
    IN NS_VOID *pTimerHandle
    );

//+++++ Resource Synchronization Functions

//Initialize/free/acquire/release multiprocessor-safe synchronization lock
NS_BOOLEAN
OaiCreateLock(
    OUT NS_VOID **pLockHandle
    );

NS_VOID
OaiDestroyLock(
    IN NS_VOID *pLockHandle
    );

NS_VOID
OaiAcquireLock(
    IN NS_VOID *pLockHandle
    );

NS_VOID
OaiReleaseLock(
    IN NS_VOID *pLockHandle
    );

#if defined(__cplusplus)
}
#endif 


//+++++ Debug Output Abstractions - Define appropriate to the environment.

// OAI_DEBUG_MSG takes a base string parameter, and zero or more optional 
// insertion parameters.
#define OAI_DEBUG_MSG printk

// OAI_DEBUG_BREAK breaks into the debugger.
#define OAI_DEBUG_BREAK printk


//********************** END OF OAI FUNCTION PROTOTYPES ***********************


#endif // _OAI_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -