?? mplpwr.c
字號:
//******************************************************************************
//
// MPLPWR.C
//
// Copyright (c) 2004 National Semiconductor Corporation.
// All Rights Reserved
//
// MPL Power Management Module.
//
// This file contains the API implementations for
// o Configuring the power state on the device
// o WoL related configuration and status reporting
//
//******************************************************************************
#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_PWR, fn)
#define EXIT(fn) MPL_CEXIT(DZONE_MPL_PWR, fn)
#define ASSERT(le) MPL_CASSERT(DZONE_MPL_PWR, le)
#define PRINT(fmt) MPL_CTRACE(DZONE_MPL_PWR, fmt)
#define PRINTI(v) MPL_CTRACE(DZONE_MPL_PWR, (" "#v": %x \n",(NS_UINT)(v)))
#define PRINTS(v) MPL_CTRACE(DZONE_MPL_PWR, (" "#v": %s \n", v))
#define TBREAK(fmt) MPL_CTRACEBREAK(DZONE_MPL_PWR, fmt)
// Locals
static NS_VOID cfgWakeEvts (MPL_CONTEXT *pMplCtx);
static NS_VOID cfgWakePatterns(MPL_CONTEXT *pMplCtx);
#ifdef LINUX_POWER_DEBUG
static NS_VOID printWakeReason(MPL_CONTEXT *pMplCtx);
#endif
//*****************************************************************************
// MplPowerSetState
// Set a new power state on the device
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// newState
// New power state that needs to be set on the device
// pmeEnable
// When set to NS_TRUE, MPL enables PME on the device
// Some OSs do this automatically, some do not
//
// Return Value
// NS_STATUS_SUCCESS
// The new state was successfully set
// NS_STATUS_FAILURE
// The device could not be set to the new state
//
//*****************************************************************************
MPL_STATUS
MplPowerSetState(
IN NS_VOID *pMplHandle,
IN MPL_POWER_STATE newState,
IN NS_BOOLEAN pmeEnable
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
MPL_STATUS status = NS_STATUS_SUCCESS;
ENTER(MplPowerSetState);
if ((pMplCtx->pwrState == MPL_POWER_STATE_HIGH) &&
(newState == MPL_POWER_STATE_LOW))
{
// Entering Low Power state from a High Power state
// This function expects Int to be disabled and Rx Reset Complete
// before calling it
// Take a register snap-shot
setSoftRegs(pMplHandle, MPL_REGS_CURRENT);
// Configure Wake events
cfgWakeEvts(pMplCtx);
// Configure Wake Patterns if any
cfgWakePatterns(pMplCtx);
// Put the receiver in "Silent Receive" mode
MPL_WRITE32(pMplCtx, CR, RX_DIS);
MPL_WRITE32(pMplCtx, RXDP, 0x0);
MPL_WRITE32(pMplCtx, CR, RX_EN);
// Enable PME if NSM wants us to - This depends on the OS, some do
// it themselves, for the rest we do it
if (pmeEnable == NS_TRUE)
{
// Using the PME backdoor
if (MPL_READ32(pMplCtx, WCSR) & WAKEON_MASK)
{
// WOL event is enabled - So set PMEEN
MPL_WRITE32(pMplCtx, CCSR, pMplCtx->ccsrReg | PMEEN | PMESTS);
}
else
{
// Write whatever was there by default
// Note PMEEN bit is loaded from EEPROM
MPL_WRITE32(pMplCtx, CCSR, pMplCtx->ccsrReg);
}
}
// Set the new state - LOW
pMplCtx->pwrState = MPL_POWER_STATE_LOW;
}
else if ((pMplCtx->pwrState == MPL_POWER_STATE_LOW) &&
(newState == MPL_POWER_STATE_HIGH))
{
// Entering High Power state from a Low Power state
#ifdef LINUX_POWER_DEBUG
printWakeReason(pMplCtx);
#endif
// If PME was enabled then clear status
if (pmeEnable == NS_TRUE)
{
// Clear any wake events configured on the device
MPL_WRITE32(pMplCtx, CCSR, PMESTS);
}
// Not doing MAC/PHY Resets
// Set registers with last known snap-shot
setHardRegs(pMplCtx);
// Set the MAC address - to last know value
MplSetMacAddress(pMplCtx, pMplCtx->permMacAddr);
#ifdef MPL_TASK_RECEIVE_FILTER
// Reload Receive hash filter (Multicast and Unicast)
MplTaskFilterReload(pMplCtx);
#endif // MPL_TASK_RECEIVE_FILTER
// Notify the device about the head node on the Rxd ring
// Not enabling RX yet, the replenish API will take care of it
MPL_WRITE32(pMplCtx, RXDP, pMplCtx->rxQueue.ringPA);
// Notify the device about the head node on the Txd ring
MPL_WRITE32(pMplCtx, TXDP, pMplCtx->txQueue[0].ringPA);
MPL_WRITE32(pMplCtx, TXDP1, pMplCtx->txQueue[1].ringPA);
MPL_WRITE32(pMplCtx, TXDP2, pMplCtx->txQueue[2].ringPA);
MPL_WRITE32(pMplCtx, TXDP3, pMplCtx->txQueue[3].ringPA);
// Set the new state - HIGH
pMplCtx->pwrState = MPL_POWER_STATE_HIGH;
}
EXIT(MplPowerSetState);
return status;
}
//*****************************************************************************
// MplWolCfg
// Configure the WOL operation on the device
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// wakeEnable
// Flag to enable (set to NS_TRUE) or disable (set to NS_FALSE) Wol
// wakeType
// When WOL is enabled, represents a bit-map of wake-up events that
// needs to be enabled. It is a logical OR of,
// MPL_WOL_MAGIC - Enable wake on Magic Pattern.
// MPL_WOL_PATTERN - Enable wake on pattern match (Patterns needs
// to be separately defined).
// MPL_WOL_BROADCAST - Enable wake on any broadcast packet.
// MPL_WOL_MULTICAST - Enable wake on multicast packet.
// MPL_WOL_DIRECTED - Enable wake on directed (unicast) packet to
// the device's address.
// MPL_WOL_LINK - Enable wake on link status change.
// MPL_WOL_ARP - Enable wake on any ARP packet.
//
// Return Value
// NS_STATUS_SUCCESS
// The WOL events were successfully enabled or disabled (depending
// on wakeEnable).
// NS_STATUS_INVALID_PARM
// The wake event type is not supported on the device.
//
//*****************************************************************************
MPL_STATUS
MplWolCfg(
IN NS_VOID *pMplHandle,
IN NS_BOOLEAN wakeEnable,
IN NS_UINT wakeType
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
MPL_STATUS status = NS_STATUS_SUCCESS;
ENTER(MplWolCfg);
pMplCtx->pwrWakeType = 0x0;
if (wakeEnable == NS_TRUE)
{
// Enable WOL - Make sure wake evt is one that we support
if (wakeType & ~(MPL_WOL_MAGIC |
MPL_WOL_PATTERNS |
MPL_WOL_BROADCAST |
MPL_WOL_MULTICAST |
MPL_WOL_DIRECTED |
MPL_WOL_LINK |
MPL_WOL_ARP))
{
status = NS_STATUS_INVALID_PARM;
}
else
{
pMplCtx->pwrWakeType = wakeType;
}
}
EXIT(MplWolCfg);
return status;
}
//*****************************************************************************
// MplWolGetCfg
// Retrieve the current WOL configuration on the device
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// pWakeType
// Pointer to caller provider variable in which the bit-map of wake-up
// events currently enabled is returned. It is a logical OR of,
// MPL_WOL_MAGIC - Enable wake on Magic Pattern.
// MPL_WOL_PATTERN - Enable wake on pattern match (Patterns needs to
// be separately defined).
// MPL_WOL_BROADCAST - Enable wake on any broadcast packet.
// MPL_WOL_MULTICAST - Enable wake on multicast packet.
// MPL_WOL_DIRECTED - Enable wake on directed (unicast) packet to
// the device's address.
// MPL_WOL_LINK - Enable wake on link status change.
// MPL_WOL_ARP - Enable wake on any ARP packet.
//
// Return Value
// NS_STATUS_SUCCESS
// The WOL configuration was returned successfully
//
//*****************************************************************************
MPL_STATUS
MplWolGetCfg(
IN NS_VOID *pMplHandle,
IN NS_UINT *pWakeType
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
ENTER(MplWolGetCfg);
*pWakeType = pMplCtx->pwrWakeType;
EXIT(MplWolGetCfg);
return NS_STATUS_SUCCESS;
}
//*****************************************************************************
// MplWolClearPattern
// Clear all WOL wake patterns on the device
//
// Parameters
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -