📄 mpllink.c
字号:
//******************************************************************************
//
// MPLLINK.C
//
// Copyright (c) 2004 National Semiconductor Corporation.
// All Rights Reserved
//
// MPL Link Processing.
//
// This file contains the API implementations for
// o MPL link configuration
// o Processing link change events
// o Reporting link status
//
//******************************************************************************
#include <mplinternal.h>
// Local helful debug macros
#undef ENTER
#undef EXIT
#undef ASSERT
#undef PRINT
#undef PRINTI
#undef PRINTS
#undef TBREAK
#define ENTER(fn) MPL_CENTER(DZONE_MPL_LINK, fn)
#define EXIT(fn) MPL_CEXIT(DZONE_MPL_LINK, fn)
#define ASSERT(le) MPL_CASSERT(DZONE_MPL_LINK, le)
#define PRINT(fmt) MPL_CTRACE(DZONE_MPL_LINK, fmt)
#define PRINTI(v) MPL_CTRACE(DZONE_MPL_LINK, (" "#v": %x \n",(NS_UINT)(v)))
#define PRINTS(v) MPL_CTRACE(DZONE_MPL_LINK, (" "#v": %s \n", v))
#define TBREAK(fmt) MPL_CTRACEBREAK(DZONE_MPL_LINK, fmt)
// Locals
static NS_BOOLEAN linkCompare(MPL_CONTEXT *pMplCtx, MPL_LINK_CFG *pLinkCfg);
static NS_VOID setPause(MPL_CONTEXT *pMplCtx);
//*****************************************************************************
// MplLinkCfg
// Configures the network media speed (10/100), duplex (half/full),
// negotiation (Auto/Forced) and network PAUSE parameters.
// When configuring auto mode, the speed and duplex setting passed should
// reflect the best case scenario i.e most desired speed and duplex
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// pLinkCfg
// Points to a MPL_LINK_CFG structure with the desired link
// configuration.
//
// Return Value
// NS_STATUS_SUCCESS
// Link configured and the link is UP.
// NS_STATUS_ASYNCH_COMPLETION
// Link is currently being configured or being negotiated.
// NS_STATUS_INVALID_PARM
// An invalid parameter was detected in the configuration structure.
// NS_STATUS_HARDWARE_FAILURE
// An expected failure occured while setting the link config
//
//*****************************************************************************
MPL_STATUS
MplLinkCfg (
IN NS_VOID *pMplHandle,
IN MPL_LINK_CFG *pLinkCfg
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
MPL_STATUS status;
ENTER(MplLinkCfg);
// FM: Assert for pLinkCfg == NULL
// We start with no link
pMplCtx->linkStatus = MPL_LINK_STATUS_NONE;
// Make a copy of the requested configuration.
OaiMemCopy(&pMplCtx->linkCfg, pLinkCfg, sizeof(MPL_LINK_CFG));
// If the current link matches what's requested then don't bother setting it.
if (linkCompare(pMplCtx, pLinkCfg) == NS_TRUE)
{
pMplCtx->linkStatus = MPL_LINK_STATUS_UP;
EXIT(MplLinkCfg);
return NS_STATUS_SUCCESS;
}
// Make sure we support the requested pause type
if ((pLinkCfg->pauseType) &&
(pMplCtx->caps.linkCaps.linkFlags != MPL_LINK_PAUSE_SYMMETRICAL))
{
// If the Mac does not support symmetric pause then make sure the
// requested direction matches the one supported
if (pLinkCfg->pauseType != pMplCtx->caps.linkCaps.linkFlags)
{
EXIT(MplLinkCfg);
return NS_STATUS_INVALID_PARM;
}
}
// Link is now down - Start the link setup process
pMplCtx->linkStatus = MPL_LINK_STATUS_DOWN;
// Setup the link on the Phy
status = MplPhyLinkSetup(pMplHandle);
// Check for Status
if (status != NS_STATUS_SUCCESS)
{
EXIT(MplLinkCfg);
return NS_STATUS_HARDWARE_FAILURE;
}
else
{
EXIT(MplLinkCfg);
return NS_STATUS_ASYNCH_COMPLETION;
}
}
//*****************************************************************************
// MplLinkGetCfg
// Returns the current link configuration on the device.
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// pLinkCfg
// Pointer to a caller allocated MPL_LINK_CFG structure in which the
// current link configuration is returned.
//
// Return Value
// NS_STATUS_SUCCESS
// The link configuration was successfully returned.
// NS_STATUS_FAILURE
// The link is not configured (yet).
//
//*****************************************************************************
MPL_STATUS
MplLinkGetCfg (
IN NS_VOID *pMplHandle,
OUT MPL_LINK_CFG *pLinkCfg
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
ENTER(MplLinkGetCfg);
// Make sure the link has been configured
if (pMplCtx->linkStatus == MPL_LINK_STATUS_NONE)
{
EXIT(MplLinkGetCfg);
return NS_STATUS_FAILURE;
}
// Copy our current configuration and return
OaiMemCopy(pLinkCfg, &pMplCtx->linkCfg, sizeof(MPL_LINK_CFG));
EXIT(MplLinkGetCfg);
return NS_STATUS_SUCCESS;
}
//*****************************************************************************
// MplLinkGetStatus
// Returns the link status reported on the device.
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
//
// Return Value
// MPL_LINK_STATUS_NONE
// An unexpected hardware error occurred while processing this request
// and the link state was not retrieved.
// MPL_LINK_STATUS_DOWN
// The link is down.
// MPL_LINK_STATUS_ACTIVE
// The link is currently being configured or negotiated.
// MPL_LINK_STATUS_UP
// The link is up
//
//*****************************************************************************
MPL_LINK_STATUS
MplLinkGetStatus (
IN NS_VOID *pMplHandle
)
{
ENTER(MplLinkGetStatus);
EXIT(MplLinkGetStatus);
// Query the hardware and return the status
return MplPhyGetLinkStatus(pMplHandle);
}
//*****************************************************************************
// MplLinkProcessChange
// Handles the link change event
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
//
// Return Value
// MPL_LINK_STATUS_DOWN
// The link is down.
// MPL_LINK_STATUS_ACTIVE
// The link is currently being configured or negotiated.
// MPL_LINK_STATUS_UP
// The link is up.
//
//*****************************************************************************
MPL_LINK_STATUS
MplLinkProcessChange (
IN NS_VOID *pMplHandle
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
ENTER(MplLinkProcessChange);
// Query the hardware on the latest status
switch (MplPhyGetLinkStatus(pMplHandle))
{
case MPL_LINK_STATUS_UP : // Link Up
// FM : Bounce logic needed?
pMplCtx->linkStatus = MPL_LINK_STATUS_UP;
break;
case MPL_LINK_STATUS_ACTIVE : // Link is Up, but AutoNeg still on
pMplCtx->linkStatus = MPL_LINK_STATUS_ACTIVE;
break;
case MPL_LINK_STATUS_DOWN : // Link Down
default :
pMplCtx->linkStatus = MPL_LINK_STATUS_DOWN;
break;
}
EXIT(MplLinkProcessChange);
return pMplCtx->linkStatus;
}
//*****************************************************************************
// MplLinkUpComplete
// Completes the configuration of the device following the
// auto-negotiation process.
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
//
// Return Value
// NS_STATUS_SUCCESS
// The link configuration is complete.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -