⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ks_table.c

📁 MICREL 网卡驱动 FOR CE 5.0
💻 C
📖 第 1 页 / 共 3 页
字号:
#define STATIC_MAC_TABLE_FWD_PORTS   0x00070000
#define STATIC_MAC_TABLE_VALID       0x00080000
#define STATIC_MAC_TABLE_OVERRIDE    0x00100000
#define STATIC_MAC_TABLE_USE_FID     0x00200000
#define STATIC_MAC_TABLE_FID         0x03C00000

#define STATIC_MAC_FWD_PORTS_SHIFT   16
#define STATIC_MAC_FID_SHIFT         22

/*
#define VLAN_TABLE_VID               00-00000000-00000FFF
#define VLAN_TABLE_FID               00-00000000-0000F000
#define VLAN_TABLE_MEMBERSHIP        00-00000000-00070000
#define VLAN_TABLE_VALID             00-00000000-00080000
*/

#define VLAN_TABLE_VID               0x00000FFF
#define VLAN_TABLE_FID               0x0000F000
#define VLAN_TABLE_MEMBERSHIP        0x00070000
#define VLAN_TABLE_VALID             0x00080000

#define VLAN_TABLE_FID_SHIFT         12
#define VLAN_TABLE_MEMBERSHIP_SHIFT  16

/*
#define DYNAMIC_MAC_TABLE_ADDR        00-0000FFFF-FFFFFFFF
#define DYNAMIC_MAC_TABLE_FID         00-000F0000-00000000
#define DYNAMIC_MAC_TABLE_SRC_PORT    00-00300000-00000000
#define DYNAMIC_MAC_TABLE_TIMESTAMP   00-00C00000-00000000
#define DYNAMIC_MAC_TABLE_ENTRIES     03-FF000000-00000000
#define DYNAMIC_MAC_TABLE_MAC_EMPTY   04-00000000-00000000
#define DYNAMIC_MAC_TABLE_RESERVED    78-00000000-00000000
#define DYNAMIC_MAC_TABLE_NOT_READY   80-00000000-00000000
*/

#define DYNAMIC_MAC_TABLE_ADDR       0x0000FFFF
#define DYNAMIC_MAC_TABLE_FID        0x000F0000
#define DYNAMIC_MAC_TABLE_SRC_PORT   0x00300000
#define DYNAMIC_MAC_TABLE_TIMESTAMP  0x00C00000
#define DYNAMIC_MAC_TABLE_ENTRIES    0xFF000000

#define DYNAMIC_MAC_TABLE_ENTRIES_H    0x03
#define DYNAMIC_MAC_TABLE_MAC_EMPTY    0x04
#define DYNAMIC_MAC_TABLE_RESERVED     0x78
#define DYNAMIC_MAC_TABLE_NOT_READY    0x80

#define DYNAMIC_MAC_FID_SHIFT        16
#define DYNAMIC_MAC_SRC_PORT_SHIFT   20
#define DYNAMIC_MAC_TIMESTAMP_SHIFT  22
#define DYNAMIC_MAC_ENTRIES_SHIFT    24
#define DYNAMIC_MAC_ENTRIES_H_SHIFT  16

/*
#define MIB_COUNTER_VALUE            00-00000000-3FFFFFFF
#define MIB_COUNTER_VALID            00-00000000-40000000
#define MIB_COUNTER_OVERFLOW         00-00000000-80000000
*/

#define MIB_COUNTER_VALUE            0x3FFFFFFF
#define MIB_COUNTER_VALID            0x40000000
#define MIB_COUNTER_VALID_SWAPPED    0x00000040
#define MIB_COUNTER_OVERFLOW         0x80000000

#define MIB_COUNTER_PACKET_DROPPED   0x0000FFFF

/* -------------------------------------------------------------------------- */

/*
    SwitchReadDynMacTable

    Description:
        This function reads an entry of the dynamic MAC table of the switch.
        Hardware interrupts are disabled to minimize corruption of read data.

    Parameters:
        PHARDWARE pHardware
            Pointer to hardware instance.

        USHORT wAddr
            The address of the entry.

        PUCHAR MacAddr
            Buffer to store the MAC address.

        PUCHAR pbFID
            Buffer to store the FID.

        PUCHAR pbSrcPort
            Buffer to store the source port number.

        PUCHAR pbTimestamp
            Buffer to store the timestamp.

        PUSHORT pwEntries
            Buffer to store the number of entries.  If this is zero, the table
            is empty and so this function should not be called again until
            later.

    Return (BOOLEAN):
        TRUE if the entry is successfully read; otherwise FALSE.
*/

#ifdef KS_PCI_BUS
BOOLEAN SwitchReadDynMacTable_PCI
#else
BOOLEAN SwitchReadDynMacTable_ISA
#endif
(
    PHARDWARE pHardware,
    USHORT    wAddr,
    PUCHAR    MacAddr,
    PUCHAR    pbFID,
    PUCHAR    pbSrcPort,
    PUCHAR    pbTimestamp,
    PUSHORT   pwEntries
)
{
    ULONG   dwDataHi = 0;
    ULONG   dwDataLo;
    UCHAR   bAddr;
    UCHAR   bCtrl;
    UCHAR   bData = 0;
    USHORT  wCtrlAddr;
    BOOLEAN rc = FALSE;

#ifdef KS_PCI_BUS
    ULONG   InterruptMask;

#else
    USHORT   InterruptMask;
#endif

    bAddr = ( UCHAR ) wAddr;
    bCtrl = ( UCHAR )(( TABLE_DYNAMIC_MAC << TABLE_SEL_SHIFT ) | ( wAddr >> 8 )
                        | TABLE_READ );

    wCtrlAddr = bCtrl;
    wCtrlAddr = (wCtrlAddr << 8) | bAddr ;

    /* Save the current interrupt mask and block all interrupts. */
    InterruptMask = HardwareBlockInterrupt( pHardware );

#ifdef KS_ISA_BUS
    HardwareWriteRegWord( pHardware,
                          (UCHAR)REG_IND_ACC_CTRL_BANK,
                          (UCHAR)REG_IACR_OFFSET,
                          wCtrlAddr
                        );

    HardwareReadRegByte( pHardware,
                         (UCHAR)REG_IND_ACC_CTRL_BANK,
                         (UCHAR)REG_ACC_DATA_8_OFFSET,
                         &bData
                       );
    HardwareReadRegDWord( pHardware,
                          (UCHAR)REG_IND_ACC_CTRL_BANK,
                          (UCHAR)REG_ACC_DATA_4_OFFSET,
                          &dwDataHi
                        );
#else

    HW_WRITE_WORD( pHardware, REG_IACR_OFFSET, wCtrlAddr );
    HW_READ_BYTE( pHardware, REG_ACC_DATA_8_OFFSET, &bData );
    HW_READ_DWORD( pHardware, REG_ACC_DATA_4_OFFSET, &dwDataHi );
#endif

    /* Entry is not ready for accessing */
    if ( ( bData & DYNAMIC_MAC_TABLE_NOT_READY ) )
    {
        *pwEntries = 0;
    }
    /* Entry is ready for accessing */
    else
    {
        /* There is no valid entry in the table */
        if ( ( bData & DYNAMIC_MAC_TABLE_MAC_EMPTY ) )
        {
            *pwEntries = 0;
        }
        /* At least one valid entry in the table */
        else
        {
            /* check out how many valid entry in the table */
            *pwEntries = ( USHORT )(
                         (((( ULONG ) bData & DYNAMIC_MAC_TABLE_ENTRIES_H ) <<
                              DYNAMIC_MAC_ENTRIES_H_SHIFT ) |
                          ((( dwDataHi & DYNAMIC_MAC_TABLE_ENTRIES ) >>
                              DYNAMIC_MAC_ENTRIES_SHIFT ))) + 1 );

            /* get the detail of dynamaic MAC table information */
            HW_READ_DWORD( pHardware, REG_ACC_DATA_0_OFFSET, &dwDataLo );
            MacAddr[ 5 ] = ( UCHAR ) dwDataLo;
            MacAddr[ 4 ] = ( UCHAR )( dwDataLo >> 8 );
            MacAddr[ 3 ] = ( UCHAR )( dwDataLo >> 16 );
            MacAddr[ 2 ] = ( UCHAR )( dwDataLo >> 24 );
            MacAddr[ 1 ] = ( UCHAR ) dwDataHi;
            MacAddr[ 0 ] = ( UCHAR )( dwDataHi >> 8 );
            *pbFID = ( UCHAR )(( dwDataHi & DYNAMIC_MAC_TABLE_FID ) >>
                                 DYNAMIC_MAC_FID_SHIFT );
            *pbSrcPort = ( UCHAR )(( dwDataHi & DYNAMIC_MAC_TABLE_SRC_PORT ) >>
                                     DYNAMIC_MAC_SRC_PORT_SHIFT );
            *pbTimestamp = ( UCHAR )(( dwDataHi & DYNAMIC_MAC_TABLE_TIMESTAMP ) >>
                                     DYNAMIC_MAC_TIMESTAMP_SHIFT );
            rc = TRUE;

        } /* if ( ( dwDataHi & DYNAMIC_MAC_TABLE_MAC_EMPTY ) ) */

    } /* if ( ( bData & DYNAMIC_MAC_TABLE_NOT_READY ) ) */

    /* Restore the interrupt mask. */
    HardwareSetInterrupt( pHardware, InterruptMask );

    return( rc );
}  /* SwitchReadDynMacTable */

/* -------------------------------------------------------------------------- */

#if defined( KS_ISA_BUS )  ||  !defined( KS_ISA )
/*
    SwitchReadStaticMacTable

    Description:
        This function reads an entry of the static MAC table of the switch.  It
        calls SwitchReadTableQword() to get the data.

    Parameters:
        PHARDWARE pHardware
            Pointer to hardware instance.

        USHORT wAddr
            The address of the entry.

        PUCHAR MacAddr
            Buffer to store the MAC address.

        PUCHAR pbPorts
            Buffer to store the port members.

        PBOOLEAN pfOverride
            Buffer to store the override flag.

        PBOOLEAN pfUserFID
            Buffer to store the use FID flag which indicates the FID is valid.

        PUCHAR pbFID
            Buffer to store the FID.

    Return (BOOLEAN):
        TRUE if the entry is valid; otherwise FALSE.
*/

BOOLEAN SwitchReadStaticMacTable (
    PHARDWARE pHardware,
    USHORT    wAddr,
    PUCHAR    MacAddr,
    PUCHAR    pbPorts,
    PBOOLEAN  pfOverride,
    PBOOLEAN  pfUseFID,
    PUCHAR    pbFID )
{
    ULONG dwDataHi;
    ULONG dwDataLo;

    ASSERT( pHardware->m_bAcquire );

#ifdef KS_ISA_BUS
#ifdef KS_PCI
    if ( !pHardware->m_fPCI )
#endif
    {
        /* DBG_PRINT ("SwitchReadStaticMacTable(ISA)\n"); */

        SwitchReadTableQword_ISA( pHardware, TABLE_STATIC_MAC, wAddr,
            &dwDataHi, &dwDataLo );
    }

#ifdef KS_PCI
    else
#endif
#endif

#ifdef KS_PCI
    {
        /*DBG_PRINT ("SwitchReadStaticMacTable(PCI)\n");*/

        SwitchReadTableQword_PCI( pHardware, TABLE_STATIC_MAC, wAddr,
            &dwDataHi, &dwDataLo );
    }
#endif
    if ( ( dwDataHi & STATIC_MAC_TABLE_VALID ) )
    {

#ifdef KS_ISA_BUS
#ifdef KS_PCI
        if ( !pHardware->m_fPCI )
#endif
        {
            MacAddr[ 5 ] = ( UCHAR ) dwDataLo;
            MacAddr[ 4 ] = ( UCHAR )( dwDataLo >> 8 );
            MacAddr[ 3 ] = ( UCHAR )( dwDataLo >> 16 );
            MacAddr[ 2 ] = ( UCHAR )( dwDataLo >> 24 );
        }

#ifdef KS_PCI
        else
#endif
#endif

#ifdef KS_PCI
        {
            MacAddr[ 5 ] = ( UCHAR ) dwDataLo;
            MacAddr[ 4 ] = ( UCHAR )( dwDataLo >> 8 );
            MacAddr[ 3 ] = ( UCHAR )( dwDataLo >> 16 );
            MacAddr[ 2 ] = ( UCHAR )( dwDataLo >> 24 );
        }
#endif
        MacAddr[ 1 ] = ( UCHAR ) dwDataHi;
        MacAddr[ 0 ] = ( UCHAR )( dwDataHi >> 8 );
        *pbPorts = ( UCHAR )(( dwDataHi & STATIC_MAC_TABLE_FWD_PORTS ) >>
            STATIC_MAC_FWD_PORTS_SHIFT );
        *pfOverride = ( dwDataHi & STATIC_MAC_TABLE_OVERRIDE ) ? TRUE : FALSE;
        *pfUseFID = ( dwDataHi & STATIC_MAC_TABLE_USE_FID ) ? TRUE : FALSE;
        *pbFID = ( UCHAR )(( dwDataHi & STATIC_MAC_TABLE_FID ) >>
            STATIC_MAC_FID_SHIFT );
        return TRUE;
    }
    return FALSE;
}  /* SwitchReadStaticMacTable */


/*
    SwitchWriteStaticMacTable

    Description:
        This routine writes an entry of the static MAC table of the switch.  It
        calls SwitchWriteTableQword() to write the data.

    Parameters:
        PHARDWARE pHardware
            Pointer to hardware instance.

        USHORT wAddr
            The address of the entry.

        PUCHAR MacAddr
            The MAC address.

        UCHAR bPorts
            The port members.

        BOOLEAN fOverride
            The override flag to override the port receive/transmit settings.

        BOOLEAN fValid
            The valid flag to indicate entry is valid.

        BOOLEAN fUserFID
            The use FID flag to indicate the FID is valid.

        UCHAR bFID
            The FID value.

    Return (None):
*/

void SwitchWriteStaticMacTable (
    PHARDWARE pHardware,
    USHORT    wAddr,
    PUCHAR    MacAddr,
    UCHAR     bPorts,
    BOOLEAN   fOverride,
    BOOLEAN   fValid,
    BOOLEAN   fUseFID,
    UCHAR     bFID )
{
    ULONG dwDataHi;
    ULONG dwDataLo;

    ASSERT( pHardware->m_bAcquire );

#ifdef KS_ISA_BUS
#ifdef KS_PCI
    if ( !pHardware->m_fPCI )
#endif
    {
        dwDataLo = *(( PULONG ) &MacAddr[ 2 ]);
    }

#ifdef KS_PCI
    else
#endif
#endif

#ifdef KS_PCI
    {
        dwDataLo = (( ULONG ) MacAddr[ 2 ] << 24 ) |
            (( ULONG ) MacAddr[ 3 ] << 16 ) |
            (( ULONG ) MacAddr[ 4 ] << 8 ) | MacAddr[ 5 ];
    }
#endif
    dwDataHi = (( ULONG ) MacAddr[ 0 ] << 8 ) | MacAddr[ 1 ];
    dwDataHi |= ( ULONG ) bPorts << STATIC_MAC_FWD_PORTS_SHIFT;
    if ( fOverride )
    {
        dwDataHi |= STATIC_MAC_TABLE_OVERRIDE;
    }
    if ( fUseFID )
    {
        dwDataHi |= STATIC_MAC_TABLE_USE_FID;
        dwDataHi |= ( ULONG ) bFID << STATIC_MAC_FID_SHIFT;
    }
    if ( fValid )
    {
        dwDataHi |= STATIC_MAC_TABLE_VALID;
    }

#ifdef KS_ISA_BUS
#ifdef KS_PCI
    if ( !pHardware->m_fPCI )
#endif
    {
        SwitchWriteTableQword_ISA( pHardware, TABLE_STATIC_MAC, wAddr,
            dwDataHi, dwDataLo );
    }

#ifdef KS_PCI
    else
#endif
#endif

#ifdef KS_PCI
    {
        SwitchWriteTableQword_PCI( pHardware, TABLE_STATIC_MAC, wAddr,
            dwDataHi, dwDataLo );
    }
#endif
}  /* SwitchWriteStaticMacTable */

/* -------------------------------------------------------------------------- */

/*
    SwitchReadVlanTable

    Description:
        This function reads an entry of the VLAN table of the switch.  It calls
        SwitchReadTable() to get the data.

    Parameters:
        PHARDWARE pHardware
            Pointer to hardware instance.

        USHORT wAddr
            The address of the entry.

        PUSHORT pwVID
            Buffer to store the VID.

        PUCHAR pbFID
            Buffer to store the VID.

        PUCHAR pbMember
            Buffer to store the port membership.

    Return (BOOLEAN):
        TRUE if the entry is valid; otherwise FALSE.
*/

BOOLEAN SwitchReadVlanTable (
    PHARDWARE pHardware,
    USHORT    wAddr,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -