📄 dpx_api.c
字号:
/******************************************************************************/
/** COPYRIGHT (C) 1999 PMC-SIERRA, INC. ALL RIGHTS RESERVED. **/
/**--------------------------------------------------------------------------**/
/** This software embodies materials and concepts which are proprietary and **/
/** confidential to PMC-Sierra, Inc. **/
/** PMC-Sierra distributes this software to its customers pursuant to the **/
/** terms and conditions of the Device Driver Software License Agreement **/
/** contained in the text file software.lic that is distributed along with **/
/** the device driver software. This software can only be utilized if all **/
/** terms and conditions of the Device Driver Software License Agreement are **/
/** accepted. If there are any questions, concerns, or if the Device Driver **/
/** Software License Agreement text file, software.lic, is missing please **/
/** contact PMC-Sierra for assistance. **/
/**--------------------------------------------------------------------------**/
/** **/
/******************************************************************************/
/*******************************************************************************
** MODULE : Duplex device drivers (API) source file
**
** FILE : Dpx_api.c
**
** DESCRIPTION: This file contains code for Duplex device driver API.
**
**
** NOTES :
**
*******************************************************************************/
/*
** MODIFICATION HISTORY:
**
** $Log: dpx_api.c.rca $
**
** Revision: 1.1 Wed Aug 16 16:22:16 2000 bhalwani
** Beta-1.0
**
**
** 6 06/15/00 Bhalwani Vortex chipset driver beta-1.0
** 5 06/15/00 Bhalwani Vortex chipset driver Alpha-1.30
** 4 05/17/00 chenkemi changed DEVICE_CHK_OVERRIDE compiler switch name
** 3 04/07/00 chenkemi added FIFO reset
** 2 02/07/00 chenkemi alpha-001
** 1 08/02/99 chenkemi Initial Version
**
** 28 04/07/00 chenkemi added FIFO reset routine
** 27 01/13/00 chenkemi enables Rev.B and add a new CW "DEVICE_CHK_OVERRIDE"
** 26 08/02/99 chenkemi added PV compiler switch around chip revision check and
** RAM fix
** 25 07/22/99 chenkemi Beta-1.0
** 24 07/22/99 chenkemi added DPX_DEBUG_MSG_ON compiler switch
** 23 07/14/99 chenkemi moved the RAM Init call into duplexAdd routine
** 22 07/02/99 chenkemi renamed DUPLEX_DEV_ID
** 21 07/01/99 chenkemi added a compiler switch for address range check in
** duplexRead() and duplexWrite().
** 20 06/29/99 chenkemi fixed a bug a Indirect access of Tx Clocked Serial
** registers
** 19 06/28/99 chenkemi moved the HSS disable code after the
** sysDuplexIntRemoveHandle().
** 18 06/23/99 chenkemi added a new error code "DPX_ERR_DEV_ID_TYPE, and fix a
** bug in duplexHssActiveLnkSetCfg().
** 17 06/17/99 chenkemi renamed error code for Cell TX/Rx failure
** 16 06/16/99 chenkemi fixed Insert/Extract Cell APIs. It works for AAL5 PDU
** data Rx/Tx.
** 15 06/11/99 chenkemi modified duplexExtractCell
** 14 06/09/99 chenkemi excluded DPX_ACTIVE from Valid State list of the 4
** indirect register access APIs.
** 13 05/28/99 chenkemi In "duplexRegisterTest()", replace hard coded value
** with DPX_REGISTER_TEST_VALUE constant.
** Clean up headers and comments
** 12 05/27/99 chenkemi Re-organized header files
** 11 05/25/99 chenkemi code cleanup after code review.
** 10 04/20/99 chenkemi added a compiler switch in "duplexActivate()" to allow
** PV to activate the duplex device without state check.
** 9 04/14/99 chenkemi changed a comment in the dpxAdd code
** 8 04/12/99 chenkemi added access timeout for "indirect serial channel"
** registers.
** 7 04/08/99 chenkemi reorganized the file : fit to length limit
** 6 03/31/99 chenkemi moved out the callback installations from
** duplexActivate().
** 5 03/30/99 chenkemi added statistical couns data structure and API.
** 4 03/22/99 chenkemi change "dpxregisterTest" state check to "DPX_PRESENT"
** 3 03/16/99 chenkemi Version Alpha1.1
** 2 03/10/99 chenkemi Fixed interrupt bug, and added more API functions.
** 1 03/02/99 chenkemi Initial Version
**
*/
/** include files **/
#include "dpx_api.h"
#include "dpx.h"
#define DPX_DEBUG_MSG_ON 0 /* if 0, no debug message display */
/** external functions **/
/** external data **/
/** public data **/
sDPX_GDD *psDpxGdd = DPX_NULL;
/** public functions **/
/** private data **/
/** private functions **/
/*******************************************************************************
**
** duplexModuleInit
** ___________________________________________________________________________
**
** DESCRIPTION: Performs module level initialization of the device driver.
** This involves allocating memory for the GDD and initializing
** the data structure.
**
** VALID STATES: Not applicable
**
** SIDE EFFECTS: None
**
** INPUTS: None
**
** OUTPUTS: None
**
** RETURN CODES: DPX_SUCCESS
** DPX_ERR_MEM_ALLOC (memory allocation failure)
** DPX_ERR_MODULE_ALREADY_INIT
**
*******************************************************************************/
INT4 duplexModuleInit(VOID)
{
UINT1 u1NextDev;
INT4 ErrorCode = DPX_SUCCESS;
/* assume success, unless proven otherwise! */
if(psDpxGdd != DPX_NULL)
{
ErrorCode = DPX_ERR_MODULE_ALREADY_INIT;
return(ErrorCode);
}
if((psDpxGdd = (sDPX_GDD*)sysDuplexMemAlloc(sizeof(sDPX_GDD))) == DPX_NULL)
{
ErrorCode = DPX_ERR_MEM_ALLOC;
return(ErrorCode);
}
/* initialize the GDD data structure */
/* and init all DDB ptr's to DPX_NULL */
psDpxGdd->u1NumDevs = 0;
psDpxGdd->u4Reserved = 0x0000;
for(u1NextDev=0; u1NextDev < DPX_MAX_NUM_DEVS; ++u1NextDev)
{
psDpxGdd->pDdb[u1NextDev] = DPX_NULL;
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexModuleShutdown
** ___________________________________________________________________________
**
** DESCRIPTION: Performs module level shutdown of the device driver. This
** involves deallocating all device dependent data structures
** for the DDB and GDD
**
** VALID STATES: Not applicable
**
** SIDE EFFECTS: None
**
** INPUTS: None
**
** OUTPUTS: None
**
** RETURN CODES: None
**
*******************************************************************************/
VOID duplexModuleShutdown(VOID)
{
UINT1 u1NextDev;
/* if GDD is allocated, deallocate all DDBs, then deallocate GDD */
if(psDpxGdd != DPX_NULL)
{
/* free each Device Data Block(DDB) memory, before deallocating GDD */
for(u1NextDev=0; u1NextDev < DPX_MAX_NUM_DEVS; ++u1NextDev)
{
if(psDpxGdd->pDdb[u1NextDev] != DPX_NULL)
{
/* reset the device no matter what state it is in */
duplexReset(psDpxGdd->pDdb[u1NextDev]);
/* delete the device */
duplexDelete(psDpxGdd->pDdb[u1NextDev]);
}
}
sysDuplexMemFree(psDpxGdd);
/* update module state */
psDpxGdd = DPX_NULL;
}
return;
}
/*******************************************************************************
**
** duplexAdd
** ___________________________________________________________________________
**
** DESCRIPTION: Detects the new device in the hardware, allocates memory for
** the device data block (DDB), stores the user's context for
** the device and returns the pointer to the DDB as a handle
** back to the user. The device handle should be used to
** identify the device on which the operation is to be
** performed.
** This function also reads the Configuration Pins Status
** register to determine the configuration of the SCI/ANY-PHY
** and Clocked Serial data interfaces, which sets the device
** mode in the DDB.
**
** VALID STATES: DPX_EMPTY
**
** SIDE EFFECTS: Device is put in the DPX_PRESENT state. A software reset is
** applied to the device.
**
** INPUTS: usrCtxt - pointer to user maintained context information for
** the device being added
**
** OUTPUTS: pDuplex - pointer to the DUPLEX device handle that contains
** context information maintained by the driver. The
** variable type, DUPLEX, is actually the following
** user-defined type: #define DUPLEX (void *)
** This prevents the application from accessing the
** DDB directly.
**
** RETURN CODES: DPX_SUCCESS
** DPX_ERR_INVALID_STATE (device is in an invalid state)
** DPX_ERR_DEV_NOT_DETECTED (device was not detected)
** DPX_ERR_DEV_ID_TYPE (invalid device ID and/or type)
** DPX_ERR_MEM_ALLOC (memory allocation failure)
** DPX_ERR_DEV_ALREADY_ADDED (the device already been added)
**
*******************************************************************************/
INT4 duplexAdd(DPX_USR_CTXT usrCtxt, DUPLEX *pDuplex)
{
UINT1 u1NextDev = DPX_MAX_NUM_DEVS, u1Next, u1DdbIdx;
INT4 ErrorCode;
UINT1 u1DevIdType;
sDPX_DDB *psDpxDDB;
/* check if the module has been initilized or not */
if( psDpxGdd == DPX_NULL)
{
ErrorCode = DPX_ERR_MOD_NOT_INIT;
return (ErrorCode);
}
if(psDpxGdd->u1NumDevs == DPX_MAX_NUM_DEVS)
{
ErrorCode = DPX_ERR_EXCEED_MAX_DEVS;
return (ErrorCode);
}
/* allocate a block of DDB memory */
if((psDpxDDB = (sDPX_DDB*)sysDuplexMemAlloc(sizeof(sDPX_DDB))) == DPX_NULL)
{
ErrorCode = DPX_ERR_MEM_ALLOC;
return (ErrorCode);
}
/* this function currently resides in dpx_hw.c file */
ErrorCode = sysDuplexDeviceDetect(usrCtxt, &(psDpxDDB->pSysInfo),
&(psDpxDDB->u4BaseAddr));
if(ErrorCode != DPX_SUCCESS)
{
sysDuplexMemFree(psDpxDDB);
return (ErrorCode); /* DPX_ERR_DEV_NOT_DETECTED */
}
/* check the device type and ID to see if the correct DUPLEX revision */
sysDuplexRawRead((char *) (psDpxDDB->u4BaseAddr + DPX_REG_MASTER_RESET_ID),
u1DevIdType);
#ifndef DPX_CSW_CHK_OVERRIDE
if(((u1DevIdType & DPX_MASK_MASTER_ID) > DUPLEX_DEV_ID_REV_B) ||
(((u1DevIdType & DPX_MASK_MASTER_TYPE) >> 4) != DUPLEX_DEV_TYPE))
{
sysDuplexMemFree(psDpxDDB);
ErrorCode = DPX_ERR_DEV_ID_TYPE;
return (ErrorCode);
}
#endif
/* check to see if the same device has already been added */
ErrorCode = duplexFindDevFromBaseAddr(psDpxDDB->u4BaseAddr, pDuplex,
&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
sysDuplexMemFree(psDpxDDB);
ErrorCode = DPX_ERR_DEV_ALREADY_ADDED;
return (ErrorCode);
}
/* check the device interface mode */
psDpxDDB->eDevMode = duplexHWDevMode(psDpxDDB->u4BaseAddr);
/* initialize DDB entry in GDD table */
/*-----------------------------------*/
/* pSysInfo member and u4BaseAddr already set */
/*--------------------------------------------*/
psDpxDDB->usrCtxt = usrCtxt;
psDpxDDB->eDevState = DPX_PRESENT;
psDpxDDB->u1IntrProcEn = DPX_INACTIVE_LOW;
sysDuplexMemset((VOID *)&(psDpxDDB->sInitVector), 0,
sizeof(sDPX_INIT_VECTOR));
/* initialize snapshots of all DUPLEX interrupt flags to INACTIVE, */
sysDuplexMemset((VOID *)&(psDpxDDB->sIntEnbls), DPX_INACTIVE_LOW,
sizeof(sDPX_INT_ENBLS));
/* initialize all Duplex callback functions to DPX_NULL */
psDpxDDB->indNotify = DPX_NULL;
psDpxDDB->indRxBOC = DPX_NULL;
psDpxDDB->indRxBOC = DPX_NULL;
psDpxDDB->pCellTypeFn = DPX_NULL;
psDpxDDB->u4Reserved = 0x00;
/* initialize the statistical counts */
sysDuplexMemset((VOID *)&(psDpxDDB->sStatCounts), 0,
sizeof(sDPX_STAT_COUNTS));
/* create/initialize the Semaphore ID in the sDPX_STAT_COUNTS */
psDpxDDB->lockId = sysDuplexSemCreate();
if(psDpxDDB->lockId == NULL)
{
sysDuplexMemFree(psDpxDDB);
return(DPX_ERR_MEM_ALLOC);
}
/* point to handle for device requested - from now on the user can access*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -