picfgmp.c

来自「vt6528芯片交换机API函数和文档运行程序」· C语言 代码 · 共 210 行

C
210
字号
/*
 * 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:
 *
 */


#if !defined(__MACRO_H__)
#include "macro.h"
#endif
#include "str.h"
#include "piportmp.h"
#include "picfgmp.h"




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

/*---------------------  Static Types  ------------------------------*/

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

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

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

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

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




// Transfer between 1bit logical pointer config mask and 3/4Byte physical mask (used by sniffer APIs)
void PICFGMP_v1bLogPtrMskTo4BPhyMsk(PUINT8 abyCfgMsk)
{
#ifdef __BIG_ENDIAN
    *(PUINT32)abyCfgMsk = REV_DWORD(*(PUINT32)abyCfgMsk);
#endif
    *(PUINT32)abyCfgMsk = PIPORTMP_dwLogPtrMskToPhyMsk(*(PUINT32)abyCfgMsk);
}


// Transfer from 4Byte physical mask to 1bit log pointer mask
void PICFGMP_v4BPhyMskTo1bLogPtrMsk(PUINT8 abyCfgMsk)
{
    *(PUINT32)abyCfgMsk = PIPORTMP_dwPhyMskToLogPtrMsk(*(PUINT32)abyCfgMsk);
#ifdef __BIG_ENDIAN       
    *(PUINT32)abyCfgMsk = REV_DWORD(*(PUINT32)abyCfgMsk);
#endif
}


// Transfer between logical pointer config mask and physical mask (used by VLAN APIs)
void PICFGMP_v2bLogPtrMskTo4BPhyMsk (PUINT8 abyCfgMsk, PUINT32 pdwPhyMskHi, PUINT32 pdwPhyMskLo)
{
    UINT32  dwShftBuf = 0x00000001;   // 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);
}


// Transfer from 2bit log pointer mask to 4Byte physical mask
void   PICFGMP_vCvt2bLogPtrMskTo4BPhyMsk (PUINT8 abyCfgMsk)
{
    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)
{
    UINT32 dwPhyMskHi, dwPhyMskLo;
    UINT8 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 & 0x00000001 )
               abyCfgMsk[si] |= byShftBuf;
            dwPhyMskLo >>= 1;
            byShftBuf <<= 1;
            if (dwPhyMskHi & 0x00000001 )
               abyCfgMsk[si] |= byShftBuf;
            dwPhyMskHi >>= 1;
            byShftBuf <<= 1;
        }
    }
}


// Transfer between 2bit logical pointer config mask and 2bit physical mask (used by VLAN ingress filter APIs)
void PICFGMP_v2bLogPtrMskTo2bPhyMsk (PUINT8 abyCfgMsk, PUINT8 abyPhyMsk)
{
    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 & 0x00000001)
                        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)
{
    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 + =
减小字号Ctrl + -
显示快捷键?