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

📄 picfgmp.c

📁 VIA VT6524 8口网管交换机源码
💻 C
字号:
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This software is copyrighted by and is the sole property of
 * VIA Networking Technologies, Inc. This software may only be used
 * in accordance with the corresponding license agreement. Any unauthorized
 * use, duplication, transmission, distribution, or disclosure of this
 * software is expressly forbidden.
 *
 * This software is provided by VIA Networking Technologies, Inc. "as is"
 * and any express or implied warranties, including, but not limited to, the
 * implied warranties of merchantability and fitness for a particular purpose
 * are disclaimed. In no event shall VIA Networking Technologies, Inc.
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages.
 *
 *
 * File:    picfgmp.c
 *
 * Purpose: Config buffer and physical port mapping functions
 *
 * Author:  Tevin Chen
 *
 * Date:    Jan 08, 2002
 *
 * Functions:
 *
 * Revision History:
 *
 */


#include "str.h"
#include "piportmp.h"
#include "picfgmp.h"
#ifndef __ASIC_VT6524
#if !defined(__BITOP_H__)
#include "bitop.h"
#endif
#endif




/*---------------------  Static Definitions -------------------------*/

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/

/*---------------------  Static Macros  -----------------------------*/

/*---------------------  Export Variables  --------------------------*/

/*---------------------  Static Functions  --------------------------*/

/*---------------------  Internal Definitions  ----------------------*/

/*---------------------  Export Functions  --------------------------*/

#ifndef __ASIC_VT6524
// Transfer between 1bit logical pointer config mask and 3/4Byte physical mask (used by sniffer APIs)
void PICFGMP_v1bLogPtrMskTo4BPhyMsk(PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    BITvEndianConvert(abyCfgMsk, 4);
    *(PUINT32)abyCfgMsk = PIPORTMP_dwLogPtrMskToPhyMsk(*(PUINT32)abyCfgMsk);
}
// Transfer from 4Byte physical mask to 1bit log pointer mask
void PICFGMP_v4BPhyMskTo1bLogPtrMsk(PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    *(PUINT32)abyCfgMsk = PIPORTMP_dwPhyMskToLogPtrMsk(*(PUINT32)abyCfgMsk);
    BITvEndianConvert(abyCfgMsk, 4);
}
#else
// Transfer between 1bit logical pointer config mask and 3/4Byte physical mask (used by sniffer APIs)
UINT32 PICFGMP_dw1bLogPtrMskTo4BPhyMsk(PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    UINT32  dwCfgMsk = 0;
    UINT8   si = BYTE_NUM_OF_CFGBUF_BIT_MASK-1;

    while (1) {
        dwCfgMsk |= abyCfgMsk[si];
        if (si > 0) {
            dwCfgMsk <<= 8;
            si--;
        }
        else
            return PIPORTMP_dwLogPtrMskToPhyMsk(dwCfgMsk);
    }
}

void PICFGMP_v1bLogPtrMskTo3BPhyMsk (PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    UINT32  dwPhyMsk;

    // Transfer into 4-byte variable then copy the desired bytes
    dwPhyMsk = PICFGMP_dw1bLogPtrMskTo4BPhyMsk(abyCfgMsk);

    STRvMemcpy(abyCfgMsk, (PBYTE)(&dwPhyMsk)+1, BYTE_NUM_OF_CFGBUF_BIT_MASK);
}

void PICFGMP_v3BPhyMskTo1bLogPtrMsk (PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    UINT32  dwLogPtrMsk = 0;
    UINT8   si;

    // Transfer into 4-byte variable then copy the desired bytes
    STRvMemcpy((PBYTE)(&dwLogPtrMsk)+1, abyCfgMsk, BYTE_NUM_OF_CFGBUF_BIT_MASK);
    dwLogPtrMsk = PIPORTMP_dwPhyMskToLogPtrMsk(dwLogPtrMsk);

    // Transfer from 4Byte to 1b config mask
    for (si = 0; si < BYTE_NUM_OF_CFGBUF_BIT_MASK; si++) {
        abyCfgMsk[si] = dwLogPtrMsk & 0xFF;
        dwLogPtrMsk >>= 8;
    }
}
#endif


// Transfer between logical pointer config mask and physical mask (used by VLAN APIs)
void PICFGMP_v2bLogPtrMskTo4BPhyMsk (PUINT8 abyCfgMsk, PUINT32 pdwPhyMskHi, PUINT32 pdwPhyMskLo) DIRECT_FUNTYPE_REENT
{
    UINT32  dwShftBuf = 0x01;   // Cannot save this buffer since the value of abyCfgMsk cannot shift
    UINT8   byShftBuf, si, sj;

    *pdwPhyMskLo = 0;
    *pdwPhyMskHi = 0;

    // (24 ports)*(2 bits) => 6 bytes
    for (si = 0; si < BYTE_NUM_OF_CFGBUF_BIT_MASK*2; si++) {
        // Statistic bit mbr in a single byte
        byShftBuf = 0x01;
        for (sj = 0; sj < 4; sj++) {    // 1 Byte => 4*(2bits)
            if ( abyCfgMsk[si] & byShftBuf )
               *pdwPhyMskLo |= dwShftBuf;
            byShftBuf <<= 1;
            if ( abyCfgMsk[si] & byShftBuf )
               *pdwPhyMskHi |= dwShftBuf;
            byShftBuf <<= 1;
            dwShftBuf <<= 1;
        }
    }

    // Transfer from logical pointer mask to physical mask
    *pdwPhyMskHi = PIPORTMP_dwLogPtrMskToPhyMsk(*pdwPhyMskHi);
    *pdwPhyMskLo = PIPORTMP_dwLogPtrMskToPhyMsk(*pdwPhyMskLo);
}
#ifndef __ASIC_VT6524
// Transfer from 2bit log pointer mask to 4Byte physical mask
void   PICFGMP_vCvt2bLogPtrMskTo4BPhyMsk (PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    UINT32  dwPhyMskHi, dwPhyMskLo;

    // Transfer into 4-byte variable then copy the 3 desired bytes
    PICFGMP_v2bLogPtrMskTo4BPhyMsk(abyCfgMsk, &dwPhyMskHi, &dwPhyMskLo);

    *((PUINT32)(abyCfgMsk+4)) = dwPhyMskHi;
    *((PUINT32)abyCfgMsk) = dwPhyMskLo;
}
// Transfer from 4Byte physical mask to 2bit log pointer mask
void   PICFGMP_vCvt4BPhyMskTo2bLogPtrMsk (PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    UINT32 dwPhyMskHi, dwPhyMskLo;
    BYTE si, sj, byShftBuf;

    dwPhyMskHi = PIPORTMP_dwPhyMskToLogPtrMsk(*((PUINT32)(abyCfgMsk+4)));
    dwPhyMskLo = PIPORTMP_dwPhyMskToLogPtrMsk(*((PUINT32)abyCfgMsk));

    // (26 ports)*(2 bits) => 8 bytes
    for (si = 0; si < BYTE_NUM_OF_CFGBUF_BIT_MASK*2; si++) {
        // Clear buffer
        abyCfgMsk[si] = 0;
        // Statistic bit mbr in a single byte
        byShftBuf = 0x01;
        for (sj = 0; sj < 4; sj++) {    // 1 Byte => 4*(2bits)
            if ( dwPhyMskLo & 0x01 )
               abyCfgMsk[si] |= byShftBuf;
            dwPhyMskLo >>= 1;
            byShftBuf <<= 1;
            if ( dwPhyMskHi & 0x01 )
               abyCfgMsk[si] |= byShftBuf;
            dwPhyMskHi >>= 1;
            byShftBuf <<= 1;
        }
    }
}
#else
void PICFGMP_v2bLogPtrMskTo3BPhyMsk (PUINT8 abyCfgMsk)   DIRECT_FUNTYPE_REENT
{
    UINT32  dwPhyMskHi, dwPhyMskLo;

    // Transfer into 4-byte variable then copy the 3 desired bytes
    PICFGMP_v2bLogPtrMskTo4BPhyMsk(abyCfgMsk, &dwPhyMskHi, &dwPhyMskLo);

    STRvMemcpy(abyCfgMsk+BYTE_NUM_OF_CFGBUF_BIT_MASK, (PBYTE)(&dwPhyMskHi)+1, BYTE_NUM_OF_CFGBUF_BIT_MASK);
    STRvMemcpy(abyCfgMsk, (PBYTE)(&dwPhyMskLo)+1, BYTE_NUM_OF_CFGBUF_BIT_MASK);
}

void PICFGMP_v3BPhyMskTo2bLogPtrMsk (PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    UINT32  dwLogPtrMskHi = 0, dwLogPtrMskLo = 0;
    UINT8   byShftBuf, si, sj;

    // Transfer into 4-byte variable then copy the 3 desired bytes
    STRvMemcpy((PBYTE)(&dwLogPtrMskHi)+1, abyCfgMsk+BYTE_NUM_OF_CFGBUF_BIT_MASK, BYTE_NUM_OF_CFGBUF_BIT_MASK);
    STRvMemcpy((PBYTE)(&dwLogPtrMskLo)+1, abyCfgMsk, BYTE_NUM_OF_CFGBUF_BIT_MASK);

    // Transfer from physical mask to logical pointer mask
    dwLogPtrMskHi = PIPORTMP_dwPhyMskToLogPtrMsk(dwLogPtrMskHi);
    dwLogPtrMskLo = PIPORTMP_dwPhyMskToLogPtrMsk(dwLogPtrMskLo);

    // (24 ports)*(2 bits) => 6 bytes
    for (si = 0; si < BYTE_NUM_OF_CFGBUF_BIT_MASK*2; si++) {
        // Clear buffer
        abyCfgMsk[si] = 0;
        // Statistic bit mbr in a single byte
        byShftBuf = 0x01;
        for (sj = 0; sj < 4; sj++) {    // 1 Byte => 4*(2bits)
            if ( dwLogPtrMskLo & 0x01 )
               abyCfgMsk[si] |= byShftBuf;
            dwLogPtrMskLo >>= 1;
            byShftBuf <<= 1;
            if ( dwLogPtrMskHi & 0x01 )
               abyCfgMsk[si] |= byShftBuf;
            dwLogPtrMskHi >>= 1;
            byShftBuf <<= 1;
        }
    }
}
#endif


// Transfer between 2bit logical pointer config mask and 2bit physical mask (used by VLAN ingress filter APIs)
void PICFGMP_v2bLogPtrMskTo2bPhyMsk (PUINT8 abyCfgMsk, PUINT8 abyPhyMsk) DIRECT_FUNTYPE_REENT
{
    UINT32  dwPortBuf;
    UINT8   abyCfgBuf[BYTE_NUM_OF_CFGBUF_BIT_MASK*2];
    UINT8   byPhyId, byValBuf, si, sj;

    // Preserve source mask (to support overlapping) and clear destination buffer
    for (si = 0; si < BYTE_NUM_OF_CFGBUF_BIT_MASK*2; si++) {
        abyCfgBuf[si] = abyCfgMsk[si];
        abyPhyMsk[si] = 0;
    }

    // Transfer operation ( 1Byte => 4*(2bits) )
    for (si = 0; si < g_byLogIdNum; si++)
    {
        byPhyId = PIPORTMP_byLogPtrToPhyId(si);
        byValBuf = ( abyCfgBuf[si/4] >> ((si%4)*2) ) & 0x03;
        if (byValBuf != 0) {
            // Handle trunk group
            if (byPhyId == ENTRY_END_FLAG) {
                dwPortBuf = PIPORTMP_dwLogPtrToPhyMsk(si);
                for (sj = 0; sj < SWITCH_PORT_NUM; sj++) {
                    if (dwPortBuf & 0x01)
                        abyPhyMsk[sj/4] |= ( byValBuf << ((sj%4)*2) );
                    dwPortBuf >>= 1;
                }
            }
            // Handle single port
            else
                abyPhyMsk[byPhyId/4] |= ( byValBuf << ((byPhyId%4)*2) );
        }
    }
}

void PICFGMP_v2bPhyMskTo2bLogPtrMsk (PUINT8 abyPhyMsk, PUINT8 abyCfgMsk) DIRECT_FUNTYPE_REENT
{
    UINT8   byLogPtr, byValBuf, si;
    UINT8   abyPhyBuf[BYTE_NUM_OF_CFGBUF_BIT_MASK*2];

    // Preserve source mask (to support overlapping) and clear destination buffer
    for (si = 0; si < BYTE_NUM_OF_CFGBUF_BIT_MASK*2; si++) {
        abyPhyBuf[si] = abyPhyMsk[si];
        abyCfgMsk[si] = 0;
    }

    // Transfer operation ( 1Byte => 4*(2bits) )
    for (si = 0; si < SWITCH_PORT_NUM; si++) {
        byValBuf = ( abyPhyBuf[si/4] >> ((si%4)*2) ) & 0x03;
        if (byValBuf != 0) {
            byLogPtr = PIPORTMP_byPhyIdToLogPtr(si);
            abyCfgMsk[byLogPtr/4] |= ( byValBuf << ((byLogPtr%4)*2) );
        }
    }
}

⌨️ 快捷键说明

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