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

📄 ixethaccsysend.c

📁 INTEL IXP425的VXWORKS BSP
💻 C
📖 第 1 页 / 共 3 页
字号:
    }        return IX_SUCCESS;}/* this function is called suring muxUnload */IX_STATUS ixdp425EthLibUnload(int port){  #ifdef SYS_END_DEBUG        DRV_LOG("ixdp425EthLibUnload(%d)\n", port);#endif /* SYS_END_DEBUG */    /* ensure the traffic is stopped */    return ixdp425EthLibStop(port);}STATUS ixdp425EthEndMuxInit()    {    END_TBL_ENTRY     *pDevTbl;    UINT32 phyNo;    for ( pDevTbl = endDevTbl; pDevTbl->endLoadFunc != END_TBL_END; pDevTbl++ )        ; /* Do nothing as we just want the increment */    /* TODO - How to we tie phys ports to ixe's ?????? */    for (phyNo=0; phyNo<IX_ETH_ACC_NUMBER_OF_PORTS; phyNo++)        {#ifndef INCLUDE_IXETHACC_PORT0_END        if ( phyNo == 0 )            continue;#endif#ifndef INCLUDE_IXETHACC_PORT1_END        if ( phyNo == 1 )            continue;#endif        /* Fill in the endDev entry for this device */        pDevTbl->unit = phyNo;        pDevTbl->endLoadFunc = ixEthAccEndLoad;        pDevTbl->endLoadString = ixpEndLoadStr[phyNo];        pDevTbl->endLoan = 1;        pDevTbl->pBSP = NULL;        pDevTbl->processed = FALSE;        pDevTbl++;        }    return OK;    }STATUS ixdp425EthEndStartUp()    {    END_TBL_ENTRY     *pDevTbl;    END_OBJ *         pCookie = NULL;    UINT32 ixdp425EthEndMask;    UINT8 nvImage[NV_RAM_IF_SIZE+1];    UINT8 inetAddr[INET_ADDR_LEN];    UINT8 nameAndUnit[32];    UINT8 pNetDev[32];    char *colon;    int n = 0,index,ipaddrOk;    sysNvRamGet(nvImage, NV_RAM_IF_SIZE, NV_RAM_IF_START_OFFSET);    for ( pDevTbl = endDevTbl            ; pDevTbl->endLoadFunc != END_TBL_END && n < IX_ETH_ACC_NUMBER_OF_PORTS            ; pDevTbl++ )        {        if ( pDevTbl->endLoadFunc != ixEthAccEndLoad )            continue;        if ( pDevTbl->processed == FALSE )            {            /* Add in mux END */            pCookie = muxDevLoad (pDevTbl->unit,                                  pDevTbl->endLoadFunc,                                  pDevTbl->endLoadString,                                  pDevTbl->endLoan,                                   pDevTbl->pBSP);            if (pCookie == NULL)                {                printf("ixdp425EthEndStartUp: muxDevLoad failed for ixp device entry %d!\n"                       , n                      );                n++;                continue;                }             else                {                /* Start END */                if (muxDevStart(pCookie) == ERROR)                    {                    printf("ixdp425EthEndStartUp: muxDevStart failed for ixp device entry %d!\n"                           , n                          );                    n++;                    continue;                    }                }            }        ipaddrOk = 1;        /* If the EthAccEnd interface is not already attached, we should bring it up here          and assign an IP address*/        sprintf(pNetDev,"%s","ixe");        sprintf(nameAndUnit,"%s%d","ixe", n);        /* need to figure out if this has been configured already */        if (ifAddrGet(nameAndUnit,inetAddr) == ERROR)            {            if (ipAttach(n, pNetDev) != OK)                {                printf ("ixdp425EthEndStartUp: Failed to attach to device %s, unit: %d", pNetDev,n);                }             else                {                /* See if an address is in nvram */                /* Get IP address */                index = NV_IP_ADRS_NPE1 + n*SIZE_OF_IP_ADDRESS - NV_RAM_IF_START_OFFSET;                memcpy(inetAddr, &nvImage[index],SIZE_OF_IP_ADDRESS);                inetAddr[SIZE_OF_IP_ADDRESS]=0;hardCodedRetry:                /* See if there is a mask */                if ( (colon = strchr(inetAddr, ':')) )                    {                    *colon = 0;                    colon++;                    for(index = 0; index < 6; index++)                        {                        if( isxdigit(colon[index] == 0 ) )                            {                            printf("ixdp425EthEndStartUp: Invalid Mask for ixe%d IP: %s:%s Discarding Mask\n"                                ,n,inetAddr, colon);                            colon = NULL;                            break;                            }                        }                    if(colon != NULL)                        {                        sscanf(colon, "%x", &ixdp425EthEndMask);                        }                    }                /* Check to see if its a valid IP address */                for(index = 0; index < SIZE_OF_IP_ADDRESS; )                    {                    if ( !isdigit(inetAddr[index]) && inetAddr[index] != '.' )                        {#if defined(IXDP_ETHACC_IP0_DEFAULT) && defined(IXDP_ETHACC_IP1_DEFAULT)                        printf("ixdp425EthEndStartUp: Forcing Hard Coded IP Address for ixe%d\n",n);                        sprintf(inetAddr, "%s", sysIxEthAccEndIpAddr[n]);                        goto hardCodedRetry;#else                        ipaddrOk = 0;                        printf("ixdp425EthEndStartUp: Invalid Address for ixe%d IP: %s Ignoring\n",n,inetAddr);                        break;#endif                        }                    if ( inetAddr[++index] == 0 )                        break;                    }                if ( ipaddrOk )                    {                    ifAddrSet(nameAndUnit, inetAddr);                    if( colon != NULL )                        {                        ifMaskSet(nameAndUnit, ixdp425EthEndMask);                        printf("                ixe%d: IP Addr set to %s:%x\n"                                ,n, inetAddr, ixdp425EthEndMask);                        }                    else                        {                        printf("                ixe%d: IP Addr set to %s\n",n, inetAddr);                        }                    }                }            }        n++;        }    return OK;    }const char *ixIpProtoStrGet (const UINT8 ipProto)    {    UINT32 index;    for (index = 0 ; index < NUM_ELEM(ixIpProtoValues) ; index++)        {        if (ixIpProtoValues[index].number == ipProto)            {            return ixIpProtoValues[index].string;            }        }    return "Unknown IP protocol";    }struct    {    int number; const char *string;    } ixEtherTypeValues[] =     {    {ETHERTYPE_PUP,         "PUP"},    {ETHERTYPE_IP,          "IP"},    {ETHERTYPE_ARP,         "ARP"},    {ETHERTYPE_REVARP,      "Reverse ARP"}    };const char *ixEthernetTypeStrGet (const UINT16 etherType)    {    UINT32 index;    for (index = 0 ; index < NUM_ELEM(ixEtherTypeValues) ; index++)        {        if (ixEtherTypeValues[index].number == etherType)            {            return ixEtherTypeValues[index].string;            }        }    return "Unknown Ethernet Type";    }void dumpMbufPtr(IX_MBUF *mBufPtr)    {    UINT32 j,k;    logMsg("m_len:        %d\n",mBufPtr->m_len,0,0,0,0,0);    logMsg("m_pkthdr.len: %d\n", mBufPtr->m_pkthdr.len,0,0,0,0,0);    logMsg("m_next        0x%x\n",(UINT32)mBufPtr->m_next,0,0,0,0,0);    logMsg("m_type        0x%x\n", mBufPtr->m_type,0,0,0,0,0);    for (j=0;j<mBufPtr->m_len/16;j++)        {        for (k=0;k<16;k++)            {            logMsg("data: 0x%x\n",mBufPtr->m_data[j*16 + k],0,0,0,0,0);            }        }    logMsg("\n",0,0,0,0,0,0);    ixEthernetHdrDump(mBufPtr->m_data);    }/****************************************************************************** * * This function can be used to output the Ethernet headers of messages. The * inputted mData pointer is assumed to point to the start of the Ethernet  * header * *****************************************************************************/void ixEthernetHdrDump(const char * const mData)    {    static unsigned char *etherSrcAddr = NULL;    static unsigned char *etherDstAddr = NULL;    static unsigned etherType = 0;    const char *etherTypeStr = NULL;    BOOL nonIpHdrDetected;    if ( (mData == NULL) )        {        logMsg("ERROR: RNDIS detected NULL pointer in ixEthernetDump\n",               0,0,0,0,0,0);        return;        }    logMsg("*** Ethernet Header ***\n", 0, 0, 0, 0, 0, 0);    etherDstAddr = ((struct ether_header *) mData)->ether_dhost;    etherSrcAddr = ((struct ether_header *) mData)->ether_shost;    etherType = ntohs(((struct ether_header *) mData)->ether_type);    if (etherType != ETHERTYPE_IP)        {        nonIpHdrDetected = TRUE;        logMsg("[this is non-IP data]\n", 0, 0, 0, 0, 0, 0);        }     else        {        nonIpHdrDetected = FALSE;        logMsg("[this is IP data]\n", 0, 0, 0, 0, 0 ,0);        }    etherTypeStr = ixEthernetTypeStrGet((const UINT16)etherType);    logMsg("Ethernet Dst MAC: 0x%02x:%02x:%02x:%02x:%02x:%02x\n",           etherDstAddr[0],           etherDstAddr[1],           etherDstAddr[2],            etherDstAddr[3],            etherDstAddr[4],            etherDstAddr[5] );    logMsg("Ethernet Src MAC: 0x%02x:%02x:%02x:%02x:%02x:%02x\n",           etherSrcAddr[0],           etherSrcAddr[1],           etherSrcAddr[2],            etherSrcAddr[3],            etherSrcAddr[4],            etherSrcAddr[5] );    logMsg("Ethernet Type (%X): %s\n", etherType, (int)etherTypeStr, 0, 0, 0, 0);    if (!nonIpHdrDetected)        {        ixIpHdrDump(mData + 14 );        }    }/****************************************************************************** * * This function can be used to output the IP headers of messages. The inputted * mData pointer is assumed to point to the start of the IP header * *****************************************************************************/void ixIpHdrDump(const char * const mData)    {    static struct in_addr srcAddr;    static struct in_addr dstAddr;    static char ipSrcAddrStr[INET_ADDR_LEN];    static char ipDstAddrStr[INET_ADDR_LEN];    if (mData == NULL)        {        logMsg("ERROR: RNDIS detected NULL pointer in ixIpHdrDump\n",               0,0,0,0,0,0);        return;        }    /*     * Check for a non word aligned header     */    if (((UINT32) mData) % 4 == 0)        {        logMsg("*** IP Header ***\n", 0, 0, 0, 0, 0, 0);        }     else        {        logMsg("*** IP Header *** WARNING: THIS IS NOT WORD ALIGNED\n", 0, 0, 0, 0, 0, 0);        }    logMsg("Total Length: %u 0x%08X\n",           ntohs(((struct ip *) mData)->ip_len),(((struct ip *) mData)->ip_len) , 0, 0, 0, 0);    logMsg("Protocol: %s\n",           (int)ixIpProtoStrGet(((struct ip *) mData)->ip_p), 0, 0, 0, 0, 0);    /*     * Potential for the source IP address to be on a half word     * boundary. E.g. If the RNDIS header is word aligned (44 bytes      * long), the Ethernet header follows directly (14 bytes), and     * then the IP header is directly after that, then the IP      * will be on a half word boundary... This may have performance     * impacts on the system.     */    memcpy(&(srcAddr.s_addr),           &(((struct ip *)mData)->ip_src.s_addr),           sizeof (UINT32));    memcpy( &(dstAddr.s_addr),            &(((struct ip *)mData)->ip_dst.s_addr),            sizeof (UINT32));    /*     * Get the IP addresses in string dotted decimal format     */    inet_ntoa_b(srcAddr, ipSrcAddrStr);    logMsg("Src Addr: %s\n", (int)ipSrcAddrStr, 0, 0, 0, 0, 0);    inet_ntoa_b(dstAddr, ipDstAddrStr);    logMsg("Dst Addr: %s\n", (int)ipDstAddrStr, 0, 0, 0, 0, 0);    }void ixEthAccEndEthernetLinkStatusMonitor(void)    {    unsigned phyNum = 0;    unsigned ticksPerSecond = 0;    BOOL linkUp[IX_ETH_ACC_NUMBER_OF_PORTS] = {FALSE, FALSE};    enum { IX_END_UNKNOWN_MODE, IX_END_FULL_DUPLEX_MODE, IX_END_HALF_DUPLEX_MODE }           lastDuplexMode[IX_ETH_ACC_NUMBER_OF_PORTS]               = {  IX_END_UNKNOWN_MODE, IX_END_UNKNOWN_MODE };    IXDP_ETHACC_PHY_CONF currentPhyConfig[IX_ETH_ACC_NUMBER_OF_PORTS];    ticksPerSecond = sysClkRateGet();         /*     * Start the infinite loop     */    while (1)        {        for (phyNum = 0; phyNum < IX_ETH_ACC_NUMBER_OF_PORTS; phyNum++)            {            /* check the PHY is initialized */            if (ixEthAccPhyAddresses[phyNum] == 0xffffffff)                continue;                        /*             * Determine the link status             */            if (IX_ETH_ACC_SUCCESS !=                 ixEthAccMiiLinkStatus(ixEthAccPhyAddresses[phyNum],                                      &linkUp[phyNum],                                      &(currentPhyConfig[phyNum].speed100),                                      &(currentPhyConfig[phyNum].fullDuplex),                                       &(currentPhyConfig[phyNum].autonegotiate)))                {                printf("%s: Warning - ixEthAccMiiLinkStatus failed on PHY%d. "                       "Can't determine\nthe auto negotiated parameters.Using "                       " default values.\n",                       "ixEthAccEndEthernetLinkStatusMonitor",                       phyNum);                 }	                 /*             * Update the MAC mode to match the PHY mode. If autonegotiotion is not enabled,             * then the MAC mode is already set during initialisation. If autonegotiation              * is enabled, the MAC mode may change at any time.             */            if (linkUp[phyNum] && currentPhyConfig[phyNum].autonegotiate)                {                if (currentPhyConfig[phyNum].fullDuplex)                    {                    /* check if the MAC mode is already set */                    if (lastDuplexMode[phyNum] != IX_END_FULL_DUPLEX_MODE)                        {                        ixEthAccPortDuplexModeSet (phyNum,                                                   IX_ETH_ACC_FULL_DUPLEX);                        lastDuplexMode[phyNum] = IX_END_FULL_DUPLEX_MODE;#ifdef SYS_END_DEBUG                        printf("Port %d set to Full duplex\n", phyNum);#endif                        }                    }                else                    {                    /* check if the MAC mode is already set */                    if (lastDuplexMode[phyNum] != IX_END_HALF_DUPLEX_MODE)                        {                        ixEthAccPortDuplexModeSet (phyNum,                                                   IX_ETH_ACC_HALF_DUPLEX);                        lastDuplexMode[phyNum] = IX_END_HALF_DUPLEX_MODE;#ifdef SYS_END_DEBUG                        printf("Port %d set to Half duplex\n", phyNum);#endif                        }                    }                } /* if duplex */            } /* for phyNum */        /*         * This function should poll the MII link status approximately every          * 4 seconds         */        taskDelay((4 * ticksPerSecond) / IX_ETH_ACC_NUMBER_OF_PORTS);        } /* End of while (1)*/    } #endif /* INCLUDE_IXETHACCEND */

⌨️ 快捷键说明

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