?? zl5011xpki.c
字號:
/* set Mac Address */
if( status== ZL5011X_OK)
{
status= zl5011xPkiSetMacAddress(zl5011xParams, portNum, macAddress);
}
/* set packet length */
if( status== ZL5011X_OK)
{
status= zl5011xPkiSetMaxPacketLength(zl5011xParams, portNum, pktLength);
}
/* set packet filtering mask
* broadcast, multicast, non-matching unicast, respectively. */
if( status== ZL5011X_OK)
{
status= zl5011xPkiSetPacketFiltering(zl5011xParams,
portNum,
filterBroadcast,
filterMulticast,
filterWrongUnicast);
}
/* set VLAN aware enable / disable */
if( status== ZL5011X_OK)
{
status= zl5011xPkiSetVlanMode(zl5011xParams, portNum, vlanEnabled );
}
/* Resets all the counters in the MAC to zero. */
if( status == ZL5011X_OK)
{
Uint32T mask = 0;
/* For long packets, set the reg_long_pkt bit*/
if ((pktLength > 1518) || ((vlanEnabled == ZL5011X_TRUE) && (pktLength > 1522)))
{
mask = ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_LONG_PKT;
}
/* pulse reset bit for all stats reset */
mask |= ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_STA_RESET;
status = zl5011xReadModWrite(zl5011xParams, ZL5011X_PKI0_CTRL,
mask, mask);
}
if( status == ZL5011X_OK)
{
/* Take reset bit low to complete the pulse */
status = zl5011xReadModWrite(zl5011xParams, ZL5011X_PKI0_CTRL, 0,
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_STA_RESET));
}
/* zero the structure contents */
if( status == ZL5011X_OK)
{
(void)memset( &(zl5011xParams->pki.lanPort[ portNum].macStats), 0,
sizeof(zl5011xParams->pki.lanPort[ portNum].macStats));
/* If 64 bit stats, set which counters should wrap according to MIB */
if(macStats64bits == ZL5011X_TRUE)
{
status= zl5011xPkiSetWrapInterruptMask(zl5011xParams, portNum,
ZL5011X_PKI_MASK_SPECIFIED_64BIT );
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPkiSetMacAddress
Description:
This writes the 48 bit address to the two registers.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Uint8T portNum - port number 0 to 3
Uint8T * macAddress, - MAC address - 6 bytes
Outputs:
Returns:
zlStatusE
Remarks:
*******************************************************************************/
extern zlStatusE zl5011xPkiSetMacAddress(zl5011xParamsS *zl5011xParams,
Uint8T portNum,
Uint8T * macAddress)
{
zlStatusE status = ZL5011X_OK;
Uint32T pkiAddress=0, i;
ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiSetMacAddress: port number %d ", portNum, 0,
0, 0, 0, 0);
/* write MAC address in ZL5011X_PKIn_ADR_.. registers */
if( status== ZL5011X_OK)
{
pkiAddress= ZL5011X_PKI0_ADR_LO+ (2* portNum* sizeof( Uint32T));
for( i= 0; (i< ZL5011X_MAC_SIZE )&& (status == ZL5011X_OK); i++)
{
switch( i)
{
case 0:
status = zl5011xWrite(zl5011xParams, pkiAddress, *macAddress);
break;
case 1:
status = zl5011xReadModWrite(zl5011xParams,
pkiAddress,
(Uint32T)(*(macAddress+ 1))<< 8,
ZL5011X_8BIT_MASK<< 8);
break;
case 2:
status = zl5011xReadModWrite(zl5011xParams,
pkiAddress,
(Uint32T)(*(macAddress+ 2))<< 16,
ZL5011X_8BIT_MASK<< 16);
break;
case 3:
status = zl5011xReadModWrite(zl5011xParams,
pkiAddress,
(Uint32T)(*(macAddress+ 3))<< 24,
ZL5011X_8BIT_MASK<< 24);
break;
case 4: /* Move up to register for upper 2 numbers */
pkiAddress= ZL5011X_PKI0_ADR_HI+ 2* portNum* sizeof( Uint32T);
status = zl5011xWrite(zl5011xParams, pkiAddress,
(Uint32T)(*(macAddress+ 4)));
break;
case 5:
status = zl5011xReadModWrite(zl5011xParams,
pkiAddress,
(Uint32T)(*(macAddress+ 5))<< 8,
ZL5011X_8BIT_MASK<< 8);
break;
default:
break;
}
if( status== ZL5011X_OK)
{
zl5011xParams->pki.lanPort[ portNum].macAddress[i ]= *(macAddress+ i);
}
}
ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiSetMacAddress: mac address %.2x %.2x %.2x %.2x %.2x %.2x",
zl5011xParams->pki.lanPort[ portNum].macAddress[0 ],
zl5011xParams->pki.lanPort[ portNum].macAddress[1 ],
zl5011xParams->pki.lanPort[ portNum].macAddress[2 ],
zl5011xParams->pki.lanPort[ portNum].macAddress[3 ],
zl5011xParams->pki.lanPort[ portNum].macAddress[4 ],
zl5011xParams->pki.lanPort[ portNum].macAddress[5 ]);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPkiSetMaxPacketLength
Description:
This writes the max pkt length to relevant port Frame Size Register.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Uint8T portNum - port number 0 to 3
Uint32T pktLength - max packet length
Outputs:
Returns:
zlStatusE
Remarks:
*******************************************************************************/
extern zlStatusE zl5011xPkiSetMaxPacketLength(zl5011xParamsS *zl5011xParams,
Uint8T portNum,
Uint32T pktLength )
{
zlStatusE status = ZL5011X_OK;
Uint32T pkiAddress=0;
ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiSetMaxPacketLength: port number %d packet length %ld ",
portNum, pktLength, 0, 0, 0, 0);
/* check pktLength in range */
if( pktLength > ZL5011X_PKI_FRAME_SIZE_BITS)
{
status= ZL5011X_PARAMETER_INVALID;
}
/* write max pkt length to relevant port Frame Size Register */
if( status== ZL5011X_OK)
{
pkiAddress= ZL5011X_PKI0_FRAME_SIZE+ (portNum* sizeof( Uint32T));
status = zl5011xReadModWrite(zl5011xParams, pkiAddress, pktLength, ZL5011X_PKI_FRAME_SIZE_BITS);
if( status== ZL5011X_OK)
{
zl5011xParams->pki.lanPort[ portNum].maxPacketLength= pktLength;
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPkiEnablePort
Description:
When disabled, the port is held in reset. and the linkdown bit is set.
The statistics counters and interrrupts are disabled. Note: on ENABLE the
wrap interrupts must be set seperately.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Uint8T portNum - port number 0 to 3
zl5011xBooleanE portEnabled - Port enable / disable
Outputs:
Returns:
zlStatusE
Remarks:
*******************************************************************************/
extern zlStatusE zl5011xPkiEnablePort(zl5011xParamsS *zl5011xParams,
Uint8T portNum,
zl5011xBooleanE portEnabled )
{
zlStatusE status = ZL5011X_OK;
Uint32T pkiAddress = 0;
Uint8T linkdownBitReg = portNum;
ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiEnablePort: port number %d enable %d",
portNum, portEnabled, 0, 0, 0, 0);
if( status== ZL5011X_OK)
{
/* Find which register controls the linkdown LED for this port.*/
switch (zl5011xParams->deviceType)
{
case ZL_DEVICE_ZL50110:
case ZL_DEVICE_ZL50114:
case ZL_DEVICE_ZL50115:
case ZL_DEVICE_ZL50116:
case ZL_DEVICE_ZL50117:
case ZL_DEVICE_ZL50118:
case ZL_DEVICE_ZL50119:
case ZL_DEVICE_ZL50120:
case ZL_DEVICE_ZL30300:
case ZL_DEVICE_ZL30301:
case ZL_DEVICE_ZL30302:
linkdownBitReg = portNum ^ 0x3;
break;
default:
/* For remaining devices the linkdown LED is controlled directly by the
port control register */
linkdownBitReg = portNum;
break;
}
if(portEnabled == ZL5011X_FALSE)
{ /* Actions to disable the port */
/* disable interrupts */
status= zl5011xPkiSetWrapInterruptMask(zl5011xParams, portNum,
ZL5011X_ZERO_ALL );
/* write relevant Control Reg link_down bit HIGH to take the link down and to hold it in reset */
if( status== ZL5011X_OK)
{
pkiAddress= ZL5011X_PKI0_CTRL+ (portNum* sizeof( Uint32T));
status = zl5011xReadModWrite(zl5011xParams, pkiAddress,
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_LINKDOWN) | (ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_N_RESET),
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_LINKDOWN) | (ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_N_RESET));
}
/* For devices that require it write relevant Control Reg bit HIGH to indicate
the linkdown state */
if( status== ZL5011X_OK)
{
if (portNum != linkdownBitReg)
{
pkiAddress= ZL5011X_PKI0_CTRL+ (linkdownBitReg* sizeof( Uint32T));
status = zl5011xReadModWrite(zl5011xParams, pkiAddress,
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_LINKDOWN),
(ZL5011X_1BIT_MASK << ZL5011X_PKI_CTRL_REG_LINKDOWN));
}
}
/* and update the status in the device structure */
if( status== ZL5011X_OK)
{
zl5011xParams->pki.lanPort[ portNum].macControl.linkDown= ZL5011X_TRUE;
}
}
else if(portEnabled == ZL5011X_TRUE)/* to enable the port */
{
/* make sure port is out of reset and the linkdown bit is low (i.e. link up) */
if( status== ZL5011X_OK)
{
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -