📄 ks_config.c
字号:
/*---------------------------------------------------------------------------
Copyright (c) 2004-2006 Micrel, Inc. All rights reserved.
---------------------------------------------------------------------------
ks_config.c - KS884X switch configuration functions.
Author Date Version Description
PCD 03/17/06 1.0.0 took out workaround (disable DMA flow control when link is half duplex mode)
for "KS8841/2/P can't release backpressue". A4 device fix this problem.
THa 02/28/06 Do not use HW_WRITE_BYTE because of limitation of
some hardware platforms.
THa 02/23/06 Removed KS884X_HW conditional.
PCD 11/14/05 0.2.1 enable (1) Aggressive back off algorithm,
(2).No excessive collision drop.
(3).Flow control. (4).Back pressure
PCD 10/20/05 0.2.0 incorrect register offset in SwitchSetAddress().
THa 10/06/05 Disable flow control if half-duplex mode.
THa 07/07/05 Added auto fast aging.
THa 05/10/05 Updated file.
THa 10/14/04 Updated with latest specs.
THa 09/30/04 Updated for PCI version.
THa 02/13/04 Created file.
---------------------------------------------------------------------------
*/
#include "target.h"
#include "hardware.h"
#if 1
#define LINK_CHECK_FIX
#endif
/* -------------------------------------------------------------------------- */
#ifdef KS_ISA_BUS
ULONG SwapBytes (
ULONG dwData )
{
ULONG dwValue;
PUCHAR pSrc = ( PUCHAR ) &dwData;
PUCHAR pDst = ( PUCHAR ) &dwValue;
pDst[ 0 ] = pSrc[ 3 ];
pDst[ 1 ] = pSrc[ 2 ];
pDst[ 2 ] = pSrc[ 1 ];
pDst[ 3 ] = pSrc[ 0 ];
return( dwValue );
} /* SwapBytes */
#endif
/* -------------------------------------------------------------------------- */
/*
PortConfigGet
Description:
This function checks whether the specified bits of the port register
are set or not.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
UCHAR bBank
The bank of the port register.
UCHAR bOffset
The offset of the port register.
UCHAR bBits
ULONG ulBits
The data bits to check.
Return (BOOLEAN):
TRUE if the bits are set; otherwise FALSE.
*/
#ifdef KS_PCI_BUS
BOOLEAN PortConfigGet_PCI (
#else
BOOLEAN PortConfigGet_ISA (
#endif
PHARDWARE pHardware,
UCHAR bPort,
#ifdef KS_ISA_BUS
UCHAR bBank,
#endif
UCHAR bOffset,
UCHAR bBits )
{
UCHAR bData;
#ifdef KS_PCI_BUS
ULONG ulAddr;
PORT_CTRL_ADDR( bPort, ulAddr );
ulAddr += bOffset;
HW_READ_BYTE( pHardware, ulAddr, &bData );
#else
HardwareSelectBank( pHardware, ( UCHAR )( bBank + bPort *
PORT_BANK_INTERVAL ));
HW_READ_BYTE( pHardware, bOffset, &bData );
#endif
if ( ( bData & bBits ) == bBits )
return TRUE;
else
return FALSE;
} /* PortConfigGet */
/*
PortConfigSet
Description:
This routine sets or resets the specified bits of the port register.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
UCHAR bBank
The bank of the port register.
UCHAR bOffset
The offset of the port register.
UCHAR bBits
ULONG ulBits
The data bits to set.
BOOLEAN fSet
The flag indicating whether the bits are to be set or not.
Return (None):
*/
#ifdef KS_PCI_BUS
void PortConfigSet_PCI (
#else
void PortConfigSet_ISA (
#endif
PHARDWARE pHardware,
UCHAR bPort,
#ifdef KS_ISA_BUS
UCHAR bBank,
#endif
UCHAR bOffset,
#ifdef SH_16BIT_WRITE
USHORT bBits,
#else
UCHAR bBits,
#endif
BOOLEAN fSet )
{
#ifdef KS_PCI_BUS
ULONG ulAddr;
UCHAR bData;
PORT_CTRL_ADDR( bPort, ulAddr );
ulAddr += bOffset;
HW_READ_BYTE( pHardware, ulAddr, &bData );
if ( fSet )
bData |= bBits;
else
bData &= ~bBits;
HW_WRITE_BYTE( pHardware, ulAddr, bData );
#else
#ifdef SH_16BIT_WRITE
USHORT RegData;
UCHAR bShift = bOffset & 1;
bOffset &= ~1;
bBits <<= ( bShift << 3 );
HardwareSelectBank( pHardware, ( UCHAR )( bBank + bPort *
PORT_BANK_INTERVAL ));
HW_READ_WORD( pHardware, bOffset, &RegData );
if ( fSet )
RegData |= bBits;
else
RegData &= ~bBits;
HW_WRITE_WORD( pHardware, bOffset, RegData );
#else
UCHAR bData;
HardwareSelectBank( pHardware, ( UCHAR )( bBank + bPort *
PORT_BANK_INTERVAL ));
HW_READ_BYTE( pHardware, bOffset, &bData );
if ( fSet )
bData |= bBits;
else
bData &= ~bBits;
HW_WRITE_BYTE( pHardware, bOffset, bData );
#endif
#endif
} /* PortConfigSet */
#ifdef KS_PCI_BUS_
/*
PortConfigGetShift
Description:
This function checks whether the specified bits of the port register
are set or not.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
ULONG ulOffset
The offset of the port register.
UCHAR bShift
Number of bits to shift.
Return (BOOLEAN):
TRUE if the bits are set; otherwise FALSE.
*/
BOOLEAN PortConfigGetShift (
PHARDWARE pHardware,
UCHAR bPort,
ULONG ulOffset,
UCHAR bShift )
{
ULONG ulData;
ULONG ulBits = 1UL << bPort;
HW_READ_DWORD( pHardware, ulOffset, &ulData );
ulData >>= bShift;
if ( ( ulData & ulBits ) == ulBits )
return TRUE;
else
return FALSE;
} /* PortConfigGetShift */
/*
PortConfigSetShift
Description:
This routine sets or resets the specified bits of the port register.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
ULONG ulOffset
The offset of the port register.
UCHAR bShift
Number of bits to shift.
BOOLEAN fSet
The flag indicating whether the bits are to be set or not.
Return (None):
*/
void PortConfigSetShift (
PHARDWARE pHardware,
UCHAR bPort,
ULONG ulOffset,
UCHAR bShift,
BOOLEAN fSet )
{
ULONG ulData;
ULONG ulBits = 1UL << bPort;
HW_READ_DWORD( pHardware, ulOffset, &ulData );
ulBits <<= bShift;
if ( fSet )
ulData |= ulBits;
else
ulData &= ~ulBits;
HW_WRITE_DWORD( pHardware, ulOffset, ulData );
} /* PortConfigSetShift */
#endif
/*
PortConfigReadByte
Description:
This routine reads a byte from the port register.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
UCHAR bBank
The bank of the port register.
UCHAR bOffset
The offset of the port register.
PUCHAR pbData
Buffer to store the data.
Return (None):
*/
#ifdef KS_PCI_BUS
void PortConfigReadByte_PCI
#else
void PortConfigReadByte_ISA
#endif
(
PHARDWARE pHardware,
UCHAR bPort,
#ifdef KS_ISA_BUS
UCHAR bBank,
#endif
UCHAR bOffset,
PUCHAR pbData )
{
#ifdef KS_PCI_BUS
ULONG ulAddr;
PORT_CTRL_ADDR( bPort, ulAddr );
ulAddr += bOffset;
HW_READ_BYTE( pHardware, ulAddr, pbData );
#else
HardwareSelectBank( pHardware, ( UCHAR )( bBank + bPort *
PORT_BANK_INTERVAL ));
HW_READ_BYTE( pHardware, bOffset, pbData );
#endif
} /* PortConfigReadByte */
/*
PortConfigWriteByte
Description:
This routine writes a byte to the port register.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
UCHAR bBank
The bank of the port register.
UCHAR bOffset
The offset of the port register.
UCHAR bData
Data to write.
Return (None):
*/
#ifdef KS_PCI_BUS
void PortConfigWriteByte_PCI
#else
void PortConfigWriteByte_ISA
#endif
(
PHARDWARE pHardware,
UCHAR bPort,
#ifdef KS_ISA_BUS
UCHAR bBank,
#endif
UCHAR bOffset,
UCHAR bData )
{
#ifdef KS_PCI_BUS
ULONG ulAddr;
PORT_CTRL_ADDR( bPort, ulAddr );
ulAddr += bOffset;
HW_WRITE_BYTE( pHardware, ulAddr, bData );
#else
#ifdef SH_16BIT_WRITE
ASSERT( FALSE );
#endif
HardwareSelectBank( pHardware, ( UCHAR )( bBank + bPort *
PORT_BANK_INTERVAL ));
HW_WRITE_BYTE( pHardware, bOffset, bData );
#endif
} /* PortConfigWriteByte */
/*
PortConfigReadWord
Description:
This routine reads a word from the port register.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
UCHAR bBank
The bank of the port register.
UCHAR bOffset
The offset of the port register.
PUSHORT pwData
Buffer to store the data.
Return (None):
*/
#ifdef KS_PCI_BUS
void PortConfigReadWord_PCI
#else
void PortConfigReadWord_ISA
#endif
(
PHARDWARE pHardware,
UCHAR bPort,
#ifdef KS_ISA_BUS
UCHAR bBank,
#endif
UCHAR bOffset,
PUSHORT pwData )
{
#ifdef KS_PCI_BUS
ULONG ulAddr;
PORT_CTRL_ADDR( bPort, ulAddr );
ulAddr += bOffset;
HW_READ_WORD( pHardware, ulAddr, pwData );
#else
HardwareSelectBank( pHardware, ( UCHAR )( bBank + bPort *
PORT_BANK_INTERVAL ));
HW_READ_WORD( pHardware, bOffset, pwData );
#endif
} /* PortConfigReadWord */
/*
PortConfigWriteWord
Description:
This routine writes a word to the port register.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bPort
The port index.
UCHAR bBank
The bank of the port register.
UCHAR bOffset
The offset of the port register.
USHORT usData
Data to write.
Return (None):
*/
#ifdef KS_PCI_BUS
void PortConfigWriteWord_PCI
#else
void PortConfigWriteWord_ISA
#endif
(
PHARDWARE pHardware,
UCHAR bPort,
#ifdef KS_ISA_BUS
UCHAR bBank,
#endif
UCHAR bOffset,
USHORT usData )
{
#ifdef KS_PCI_BUS
ULONG ulAddr;
PORT_CTRL_ADDR( bPort, ulAddr );
ulAddr += bOffset;
HW_WRITE_WORD( pHardware, ulAddr, usData );
#else
HardwareSelectBank( pHardware, ( UCHAR )( bBank + bPort *
PORT_BANK_INTERVAL ));
HW_WRITE_WORD( pHardware, bOffset, usData );
#endif
} /* PortConfigWriteWord */
/* -------------------------------------------------------------------------- */
/*
SwitchConfigGet
Description:
This function checks whether the specified bits of the switch register
are set or not.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bOffset
ULONG ulOffset
The offset of the switch register.
UCHAR bBits
ULONG ulBits
The data bits to check.
Return (BOOLEAN):
TRUE if the bits are set; otherwise FALSE.
*/
#ifdef KS_PCI_BUS
BOOLEAN SwitchConfigGet_PCI (
#else
BOOLEAN SwitchConfigGet_ISA (
#endif
PHARDWARE pHardware,
int Offset,
UCHAR bBits )
{
UCHAR bData;
#ifdef KS_ISA_BUS
HardwareSelectBank( pHardware, REG_SWITCH_CTRL_BANK );
#endif
HW_READ_BYTE( pHardware, Offset, &bData );
if ( ( bData & bBits ) == bBits )
return TRUE;
else
return FALSE;
} /* SwitchConfigGet */
/*
SwitchConfigSet
Description:
This function sets or resets the specified bits of the switch register.
Parameters:
PHARDWARE pHardware
Pointer to hardware instance.
UCHAR bOffset
ULONG ulOffset
The offset of the switch register.
UCHAR bBits
ULONG ulBits
The data bits to check.
BOOLEAN fSet
The flag indicating whether the bits are to be set or not.
Return (None):
*/
#ifdef KS_PCI_BUS
void SwitchConfigSet_PCI (
#else
void SwitchConfigSet_ISA (
#endif
PHARDWARE pHardware,
int Offset,
#ifdef SH_16BIT_WRITE
USHORT bBits,
#else
UCHAR bBits,
#endif
BOOLEAN fSet )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -