?? zl5011xpki.c
字號:
/********************************************************************************
*
* File name: zl5011xPki.c
*
* Version: 47
*
* Author: PJE
*
* Date created: 16/04/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
*
* This file contains all the functions that will initialise and control
* the Packet Queue Module.
* The Lan ports should only be referred to by number, and the number
* that support 1Gbit can be a simple number. This means that the number of ports and
* the speed they support can be easily changed.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 18/04/2002 PJE Done easy bits - compile OK.
* 2 17/05/2002 PJE tested most.
* 3 21/05/2002 PJE tested rest.
* 4 31/05/2002 PJE most review items done.
* 5 05/06/2002 PJE review items done.
* 6 06/06/2002 PJE PKI review items tested.
* 7 10/06/2002 PJE bug - stepped outside status checking.
* 8 14/06/2002 PJE bugs from partial review.
* 9 18/06/2002 PJE bugs from partial review.
* 10 18/06/2002 PJE reorganised intr masks.
* 11 24/06/2002 PJE review items complete.
* 12 26/06/2002 PJE bug - left Uint64T in Borland mode
* 13 08/07/2002 PJE fiddle the port link down bit
* 14 11/07/2002 PJE new fns PkiEnable(Disable)PcsInterrupt
* 15 16/08/2002 MRC Added ifndef to delay to allow compiler command
* line override.
* 16 27/08/2002 MRC minor review comments
* 17 28/08/2002 PJE First clear the interrupts before enabling.
* 18 29/08/2002 PJE removed bug introduced clearing the interrupts
* 20 27/09/2002 DJA Function zl5011xAdd64bit renamed to zl5011xPkiAdd64bit
* Function zl5011xSubtract64bit renamed to zl5011xPkiSubtract64bit
* SOS version updated
* 21 02/10/2002 DJA ZL5011X_TRACE messages fixed up
* 22 07/10/2002 PJE new fns zl5011xPkiEnable/DisableWrapInterrupts,
* zl5011xPkiGetPcsStatus
* 23 11/10/2002 PJE peer rev itms
* 24 11/10/2002 PJE debug zl5011xPkiEnableWrapInterrupts
* 25 23/10/2002 PJE zl5011xPkiSetPacketFiltering had bits in wrong order
* 26 25/10/2002 PJE API tidy up
* 27 30/10/2002 MRC Fixed compiler warning and changed to using the
* 64 bit structure from compiler.h
* 28 31/10/2002 MRC Added variants + minor fixes
* 29 03/04/2003 MRC Modified the read counters function to disable
* interrupts around handling the upper words
* 30 07/04/2003 MRC Changed polarity of wrap interrupt mask bits
* 31 06/05/2003 ARW Fixed a bug in zl5011xPkiReadCounters
* 32 03/06/2003 PJE SetMaxPacketLength define, PCS intr is self clearing and
* mask reg is ONE to mask off the intr.
* 33 06/06/2003 PJE Bugfix added to zl5011xPkiEnablePcsInterrupt():
* ports 2 & 3 need ZL5011X_PKI_SPECIAL_PCS_MODE for PCS intr
* 34 30/06/2003 PJE removed unwanted reference writeBits
* 35 29/07/2003 APL Renamed global wanLimits structure to devLimits
* 36 11/08/2003 MRC Reordered function calls in configure fn
* 37 08/09/2003 APL Set both linkdown bit and reset bit to disable port
* in PkiEnablePort. Removed PkiReset function
* 38 23/07/2004 MRC Fixed some compiler warnings
* 39 29/07/2004 MRC Fixed some compiler warnings
* 40 06/09/2004 APL Added port remapping for new device variants
* 41 08/09/2004 MRC Added option to call library fn for 64 bit calcs
* 42 13/09/2004 APL Renamed port mapping functions following review
* 43 22/09/2004 APL Added ability to control Linkup LEDs for devices
* where this is not in the main control register
* 44 06/10/2004 APL Improved robustness of port mapping functions
* 45 09/12/2004 MRC Added extra device variants
* 46 31/01/2005 APL Added Zl30301/2 device variants
* Enable support for long packets
* 47 03/02/2005 APL Renamed device ID's to allow new family members
*
*******************************************************************************/
/***************** INCLUDE FILES *****************************/
#include "zl5011x.h"
#include "zl5011xPki.h"
#include "zl5011xPkiMap.h"
#include "zl5011xUtilLib.h"
/***************** # DEFINES **********************************************/
/* define types for 64 bit numbers. This is being done locally to this file
and its usage should be minimised. */
#ifdef _ZL5011X_DISABLE_64_BIT_OPERATIONS
#include "gmp.h"
#include "gmp-impl.h"
typedef mpz_t Uint64T;
#else
typedef unsigned OS_INT64 Uint64T;
#endif
#define ZL5011X_PKI_FRAME_SIZE_BITS 0x7fff /* used in SetMaxPacketLength */
#define ZL5011X_MAX_PHY_ADDRESS 31 /* The PHY ID field in the MDIO register
is 5 bits in size */
#define ZL5011X_MAX_PHY_REGISTER 31 /* The REG ADR field in the MDIO register
is 5 bits in size */
#define ZL5011X_MDIO_PHY_POLL_TIMEOUT 100 /* Polling loop timeout delay, 1 second
(100 * 10 mS) */
#ifndef ZL5011X_WAIT_10MS
#define ZL5011X_WAIT_10MS 10
#endif
#ifdef _DEBUG
#ifdef static
#undef static
#endif
#define static
#endif
/***************** EXPORTED GLOBAL VARIABLES *****************************/
/***************** STATIC GLOBAL VARIABLES *****************************/
/* Map of external port number to internal port number.*/
/* ZL5011X_INVALID indicates that the requested external port is not supported
on this device */
static const Sint8T InternalPorts[ZL_MAX_NUM_DEVICE_TYPES][ZL5011X_MAX_NUM_LAN_PORTS] =
{
{ 0, 1, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50110 */
{ 0, 1, 2, 3 }, /* ZL_DEVICE_ZL50111 */
{ 0, 1, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50114 */
{ 1, ZL5011X_INVALID, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50115 */
{ 1, ZL5011X_INVALID, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50116 */
{ 1, ZL5011X_INVALID, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50117 */
{ 1, 3, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50118 */
{ 1, 3, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50119 */
{ 1, 3, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL50120 */
{ 0, 1, 2, 3 }, /* ZL_DEVICE_ZL50130 */
{ 0, 1, 2, 3 }, /* ZL_DEVICE_ZL80041 */
{ 1, 3, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL30300 */
{ 1, 3, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL30301 */
{ 1, 3, ZL5011X_INVALID, ZL5011X_INVALID }, /* ZL_DEVICE_ZL30302 */
};
/***************** STATIC FUNCTION DECLARATIONS *****************************/
static zlStatusE zl5011xPkiSetPcsSignalDetectMask(zl5011xParamsS *zl5011xParams,
Uint8T portNum,
zl5011xBooleanE enablePcsDet);
static zlStatusE zl5011xPkiAdd64bit( Uint64S *pUint64X,
Uint64S *pUint64Y);
static zlStatusE zl5011xPkiSubtract64bit( Uint64S *pUint64Pos,
Uint64S *pUint64Neg);
/***************** EXPORTED FUNCTION DEFINTIONS ***************************/
/*******************************************************************************
Function:
zl5011xPkiInit
Description:
Called at initialisation time.
Sets the ports into low power mode.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
Returns:
zlStatusE
Remarks:
*******************************************************************************/
extern zlStatusE zl5011xPkiInit(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
Uint8T portNum= 0;
ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiInit:", 0, 0, 0, 0, 0, 0);
/* reset 64 bit stats to disabled */
zl5011xParams->pki.lanPort[ portNum].macStats64bits = ZL5011X_FALSE;
/* disable the ports to put them in power saving mode */
for( portNum= 0;( portNum< ZL5011X_MAX_NUM_LAN_PORTS)&&( status== ZL5011X_OK); portNum++)
{
status= zl5011xPkiEnablePort(zl5011xParams, portNum, ZL5011X_FALSE );
}
if( status == ZL5011X_OK)
{
/* pulse reset bit for all stats reset */
status = zl5011xReadModWrite(zl5011xParams, ZL5011X_PKI0_CTRL,
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_STA_RESET),
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_STA_RESET));
}
if( status == ZL5011X_OK)
{
status = zl5011xReadModWrite(zl5011xParams, ZL5011X_PKI0_CTRL, 0,
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_STA_RESET));
}
/* Set Pcs SignalDetectMask to inactive for all ports */
for( portNum= 0;( portNum< ZL5011X_MAX_NUM_LAN_PORTS)&&( status== ZL5011X_OK); portNum++)
{
status= zl5011xPkiSetPcsSignalDetectMask(zl5011xParams, portNum, ZL5011X_FALSE );
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPkiConfigure
Description:
Configure the Lan port mode etc.
Resets all of the counters in the MAC and the s/w to 0.
If 64 bit statistics are required, then the interrupts for wrap on the required
counters is enabled and the interrupt mask set for this port.
(the ISR is already initialised).
Inputs:
zl5011xParams - Pointer to the structure for this device instance
Uint8T portNum - port number 0 to 3
Uint8T * macAddress, - MAC address - 6 bytes
Uint32T pktLength - max packet length
zl5011xMacTypeE macType - interface type - MII, GMII, PCS
Uint32T pktFilterMask - packet filtering mask - broadcast, multicast, non-matching
unicast
zl5011xBooleanE vlanEnabled - VLAN aware enable / disable
zl5011xBooleanE macStats64bits - statistics mode - 32 or 64 bit
Outputs:
Returns:
zlStatusE
Remarks:
*******************************************************************************/
extern zlStatusE zl5011xPkiConfigure(zl5011xParamsS *zl5011xParams,
Uint8T portNum,
Uint8T * macAddress,
Uint32T pktLength,
zl5011xMacTypeE macType,
zl5011xBooleanE filterBroadcast,
zl5011xBooleanE filterMulticast,
zl5011xBooleanE filterWrongUnicast,
zl5011xBooleanE vlanEnabled,
zl5011xBooleanE macStats64bits)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiConfigure: port number %d,"
" packet length %d, mac type %d, "
" vlan enabled %d, mac stats 64 bits %d",
portNum, pktLength, macType, vlanEnabled, macStats64bits, 0);
/* check enums are in range. */
if( status== ZL5011X_OK)
{
status= ZL5011X_CHECK_MAC_TYPE( macType);
}
if( status== ZL5011X_OK)
{
status= ZL5011X_CHECK_BOOLEAN( filterBroadcast);
}
if( status== ZL5011X_OK)
{
status= ZL5011X_CHECK_BOOLEAN( filterMulticast);
}
if( status== ZL5011X_OK)
{
status= ZL5011X_CHECK_BOOLEAN( filterWrongUnicast);
}
if( status== ZL5011X_OK)
{
status= ZL5011X_CHECK_BOOLEAN( vlanEnabled);
}
if( status== ZL5011X_OK)
{
status= ZL5011X_CHECK_BOOLEAN( macStats64bits);
}
if( status== ZL5011X_OK)
{
if( macAddress== NULL)
{
status= ZL5011X_PARAMETER_INVALID;
}
}
/* set mac type - MII, GMII, PCS */
if( status== ZL5011X_OK)
{
status= zl5011xPkiSetInterfaceType(zl5011xParams, portNum, macType);
}
/* set statistics mode - 32 or 64 bit */
if( status== ZL5011X_OK)
{
zl5011xParams->pki.lanPort[ portNum].macStats64bits= macStats64bits;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -