ixEthAccSysEnd.c
资源名称:ixp425BSP.rar [点击查看]
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:28k
源码类别:
VxWorks
开发平台:
C/C++
- /* ixEthAccSysEnd.c - Intel IXDP425 ixEth Init Module */
- /* Copyright 2002 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- modification history
- --------------------
- 01l,22oct02,jb Changing Autonegotiate message
- 01k,07oct02,jb Fix numbering
- 01j,07oct02,jb Fix naming
- 01i,07oct02,jb fix IP address
- 01h,23sep02,jb Adding default IP addresses from config.h
- 01g,05sep02,jb Changes to support Gold release of Intel Lib
- 01f,19aug02,jb Fix double inclusion
- 01e,01aug02,jb Continued developement
- 01d,31jul02,jb Fixing name errors
- 01c,17jul02,jb Renamed file, renaming bsp specific routines to segregate Intel
- library
- 01b,10jun02,jb Modifying to integrate ixEth
- 01a,27may02,jb Initial version from Intel
- */
- /*
- DESCRIPTION
- This file contains the board-specific routines for Ethernet adapter
- initialisation of Intel ixEthAcc devices.
- */
- #include <stddef.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "vxWorks.h"
- #include "sysLib.h"
- #include "ctype.h"
- #include "end.h" /* Common END structures. */
- #include "endLib.h"
- #include "inetLib.h"
- #undef ETHER_MAP_IP_MULTICAST
- #include "etherMultiLib.h" /* multicast stuff. */
- #include "ipProto.h" /* IP prototypes */
- #include "logLib.h"
- #include "net/mbuf.h"
- #include "net/unixLib.h"
- #include "net/protosw.h"
- #include "net/systm.h"
- #include "net/if_subr.h"
- #include "net/route.h"
- #include <inetLib.h>
- #include <ipProto.h>
- #include <netinet/in.h>
- #include <netinet/ip.h>
- #include <netinet/if_ether.h>
- #include "sys/socket.h"
- #include "sys/ioctl.h"
- #include "sys/times.h"
- #undef FORCE_CODELETS
- #include "IxTypes.h"
- #include "IxEthAcc.h"
- #include "IxQMgr.h"
- #include "IxNpeDl.h"
- #include "IxNpeMh.h"
- #ifndef FORCE_CODELETS
- #include "IxNpeMicrocode.h"
- #endif /* FORCE_CODELETS */
- #include "IxOsServices.h"
- #include "IxEthAcc.h"
- #include "ixp425.h" /* Chip level definitions required */
- #include "ixdp425.h"
- #include "config.h"
- #ifdef INCLUDE_IXETHACCEND
- /* DEBUG MACROS */
- #define SYS_END_DEBUG
- #ifdef SYS_END_DEBUG
- #define DRV_LOG printf
- #else
- #define DRV_LOG
- #endif /* SYS_END_DEBUG */
- #ifndef END_LD_STR_SIZE
- #define END_LD_STR_SIZE 80
- #endif
- /**< Max number of NPE uCode versions */
- #define IX_ETHACC_CODELET_NPE_LIST 20
- /**< Location of NPE image to download */
- #define IX_ETHACC_CODELET_NPE_IMG IX_NPEDL_MicrocodeImage
- #ifdef FORCE_CODELETS
- IMPORT unsigned IX_NPEDL_MicrocodeImage[];
- #endif
- #define NUM_ELEM(vector) (sizeof (vector) / sizeof ((vector)[0]))
- /* Imports from Monsoon */
- struct
- {
- int number; const char *string;
- } ixIpProtoValues[] =
- {
- {IPPROTO_IP, "IP"},
- {IPPROTO_TCP, "TCP"},
- {IPPROTO_UDP, "UDP"},
- {IPPROTO_ICMP, "ICMP"},
- {IPPROTO_IGMP, "IGMP"}
- };
- /* These are to simplify includes */
- #define IX_ETH_ACC_MII_STAT_REG 0x1 /* Status Register */
- #define IX_ETH_ACC_MII_STAT2_REG 0x11 /* Status Register 2*/
- #define IX_ETH_ACC_MII_SR_AUTO_NEG 0x0020 /* auto negotiation complete */
- #define IX_ETH_ACC_MII_SR2_FD 0x0200
- IMPORT END_OBJ* ixEthAccEndLoad (char *, void *);
- IMPORT END_TBL_ENTRY endDevTbl[];
- unsigned char sysIxEthAccEndEnetAddr[6] = { 0x00, 0x02,0xb3,0x3c,0x16,0x95};
- #if defined(IXDP_ETHACC_IP0_DEFAULT) && defined(IXDP_ETHACC_IP1_DEFAULT)
- LOCAL char *sysIxEthAccEndIpAddr[IX_ETH_ACC_NUMBER_OF_PORTS] =
- {
- IXDP_ETHACC_IP0_DEFAULT,
- IXDP_ETHACC_IP1_DEFAULT
- };
- #endif
- LOCAL char ixpEndLoadStr[IX_ETH_ACC_NUMBER_OF_PORTS][END_LD_STR_SIZE] =
- {
- { "0:"},
- { "0:"},
- };
- typedef struct _IXDP_ETHACC_PHY_CONF
- {
- BOOL speed100; /**< 100 Mbits */
- BOOL fullDuplex; /**< Full Duplex */
- BOOL autonegotiate; /**< Autonegotiation */
- } IXDP_ETHACC_PHY_CONF;
- PRIVATE IXDP_ETHACC_PHY_CONF ixdp425phyConf =
- {
- TRUE, /* 100 Mbits */
- TRUE, /* Full duplex */
- TRUE /* Autonegotiate */
- };
- #ifdef IXDP_ETHACC_USE_NVRAM_MAC
- static UCHAR ixdp425IntelMacPrefix[6] =
- {
- 0x00,
- 0xe0,
- 0x42,
- 0x00,
- 0x00,
- 0x00,
- };
- static UINT32 nvRamNpeMacAddr[IX_ETH_ACC_NUMBER_OF_PORTS] =
- {
- NV_MAC_ADRS_NPE1,
- NV_MAC_ADRS_NPE2,
- };
- #endif /* IXDP_ETHACC_USE_NVRAM_MAC */
- void ixEthernetHdrDump(const char * const mData);
- void ixIpHdrDump(const char * const mData);
- IxEthAccStatus ixEthAccMiiReadRtn (UINT8, UINT8, UINT16 *);
- extern void sysMicroDelay(int microseconds);
- BOOL ixdp425EthLibInitialised = FALSE;
- #if (BOARD_TYPE==CPF425O)
- UINT32 ixEthAccPhyAddresses[IX_ETH_ACC_NUMBER_OF_PORTS]={4,5};
- #elif (BOARD_TYPE==CPF425C)
- UINT32 ixEthAccPhyAddresses[IX_ETH_ACC_NUMBER_OF_PORTS]={1,0};
- #else
- #error "Unsupported embedway board"
- #endif
- PRIVATE BOOL phyPresent[IXP425_ETH_ACC_MII_MAX_ADDR];
- PRIVATE char ixnpeMaddrStr[IX_ETH_ACC_NUMBER_OF_PORTS][64];
- #ifdef FORCE_CODELETS
- /* Do Not call this routine - It is used to force code inclusion */
- PRIVATE void ixdp425ForceCodlets()
- {
- ixEthAccCodeletInit();
- }
- #endif /* FORCE_CODELETS */
- PRIVATE IX_STATUS ixdp425EthAccPhyInit(int port)
- {
- UINT16 regval;
- UINT32 phyAddr;
- UINT32 timeout;
- UINT32 i;
- #if BOARD_TYPE==CPF425O
- if (port == 0)
- return IX_SUCCESS;
- #endif
- if (ixEthAccMiiPhyScan(phyPresent) == ERROR)
- {
- return(IX_FAIL);
- }
- else
- {
- for (i = 0; i < IX_ETH_ACC_NUMBER_OF_PORTS; i++)
- {
- phyAddr = ixEthAccPhyAddresses[i];
- if (phyPresent[phyAddr] == 0)
- return(IX_FAIL);
- }
- }
- /* Reset each phy */
- for (i=0; i<IX_ETH_ACC_NUMBER_OF_PORTS; i++)
- {
- if (i != port || ixEthAccPhyAddresses[i] == 0xffffffff)
- continue;
- ixEthAccMiiPhyReset(ixEthAccPhyAddresses[i]);
- }
- /* Set each phy properties */
- for (i=0; i<IX_ETH_ACC_NUMBER_OF_PORTS; i++)
- {
- if (i != port || ixEthAccPhyAddresses[i] == 0xffffffff)
- continue;
- ixEthAccMiiPhyConfig(ixEthAccPhyAddresses[i],
- ixdp425phyConf.speed100,
- ixdp425phyConf.fullDuplex,
- ixdp425phyConf.autonegotiate);
- if ((ixdp425phyConf.autonegotiate) && (port ==1))
- {
- /* We need to delay here until Autonegotiate is complete */
- for ( timeout = 10; timeout; timeout-- )
- {
- /* A short delay */
- sysMicroDelay(50);
- /* Must do this read twice */
- ixEthAccMiiReadRtn(ixEthAccPhyAddresses[i], IX_ETH_ACC_MII_STAT_REG, ®val);
- ixEthAccMiiReadRtn(ixEthAccPhyAddresses[i], IX_ETH_ACC_MII_STAT_REG, ®val);
- if ((regval & IX_ETH_ACC_MII_SR_AUTO_NEG) != 0)
- break;
- }
- /* If connect failed, then report it */
- if ( (regval & IX_ETH_ACC_MII_SR_AUTO_NEG) == 0 )
- {
- printf("nixe ETH PHY %d Autonegotiate incompleten"
- , ixEthAccPhyAddresses[i]
- );
- #if 0
- /* allow autonegotiate for later */
- ixEthAccPhyAddresses[i] = 0xffffffff;
- #endif
- }
- }
- }
- /* Set the MAC to the same duplex mode as the phy */
- for (i=0; i<IX_ETH_ACC_NUMBER_OF_PORTS; i++)
- {
- if (i != port || ixEthAccPhyAddresses[i] == 0xffffffff)
- continue;
- if (ixdp425phyConf.fullDuplex)
- {
- ixEthAccPortDuplexModeSet (ixEthAccPhyAddresses[i], IX_ETH_ACC_FULL_DUPLEX);
- }
- else
- {
- ixEthAccPortDuplexModeSet (ixEthAccPhyAddresses[i], IX_ETH_ACC_HALF_DUPLEX);
- }
- /* Do a read status to add a delay. Must do this read twice */
- ixEthAccMiiReadRtn(ixEthAccPhyAddresses[i], IX_ETH_ACC_MII_STAT_REG, ®val);
- ixEthAccMiiReadRtn(ixEthAccPhyAddresses[i], IX_ETH_ACC_MII_STAT_REG, ®val);
- #ifdef SYS_END_DEBUG
- printf("nixe ETH PHY %d configuration:n"
- , ixEthAccPhyAddresses[i]
- );
- ixEthAccMiiShow(ixEthAccPhyAddresses[i]);
- #endif /* SYS_END_DEBUG */
- }
- return(IX_SUCCESS);
- }
- /**
- * @fn IX_STATUS ixdp425EthAccNpeInit(IxNpeDlNpeId npeId)
- *
- * @param npeId - ID of ixe to initialise
- *
- * Download microcode to the IXE. This function always downloads the latest
- * version of NPE microcode available.
- *
- * @return IX_SUCCESS - NPE successfuly initialised
- * @return IX_FAIL - Error initialising NPE
- */
- PRIVATE IX_STATUS ixdp425EthAccNpeInit(IxNpeDlNpeId npeId)
- {
- IxNpeDlVersionId npeIdList[IX_ETHACC_CODELET_NPE_LIST];
- UINT32 npeListSize = IX_ETHACC_CODELET_NPE_LIST;
- IxNpeDlVersionId tmpIdList = {0, 0, 0, 0};
- int i;
- tmpIdList.npeId = npeId;
- /* Stop the NPE before attempting a download */
- if (ixNpeDlNpeStopAndReset(npeId) != IX_SUCCESS)
- {
- printf("ixe %d stop and reset failedn"
- , (int)npeId
- );
- return(IX_FAIL);
- }
- /* Get the latest version of NPE code available */
- ixNpeDlAvailableVersionsListGet(npeIdList, &npeListSize);
- for (i = 0; i < npeListSize; i++)
- {
- if (npeIdList[i].npeId == npeId)
- {
- if (npeIdList[i].major >= tmpIdList.major)
- {
- tmpIdList.major = npeIdList[i].major;
- if (npeIdList[i].minor >= tmpIdList.minor)
- {
- tmpIdList.minor = npeIdList[i].minor;
- tmpIdList.buildId = npeIdList[i].buildId;
- }
- }
- }
- }
- #ifdef SYS_END_DEBUG
- printf("ixe %d Version informationn", tmpIdList.npeId - 1);
- printf("Major ID:t 0x%xn", tmpIdList.major);
- printf("Minor ID:t 0x%xn", tmpIdList.minor);
- printf("Build ID:t 0x%xn", tmpIdList.buildId);
- #endif /* SYS_END_DEBUG */
- /* Download NPE code */
- if (ixNpeDlVersionDownload(&tmpIdList, TRUE) != IX_SUCCESS)
- {
- printf("ixe %d download failedn"
- , tmpIdList.npeId
- );
- return(IX_FAIL);
- }
- return(IX_SUCCESS);
- }
- /**
- * @fn IX_STATUS ixdp425EthAccMacSet()
- *
- * Set the MAC address for available Ports on the board.
- * It is assumed that the MAC addresses are stored in non-volatile storage.
- *
- * @return IX_SUCCESS - MAC address successfuly set
- * @return IX_FAIL - Error setting MAC address
- */
- PRIVATE IX_STATUS ixdp425EthAccMacSet(int port)
- {
- IxEthAccMacAddr npeMacAddr;
- #ifdef IXDP_ETHACC_USE_NVRAM_MAC
- if (sysNvRamGet((UINT8 *)&npeMacAddr.macAddress,
- IX_IEEE803_MAC_ADDRESS_SIZE,
- nvRamNpeMacAddr[port]) == ERROR)
- {
- printf("ixe %d - Unable to read MAC address from non-volatile storage!n"
- , port
- );
- return(IX_FAIL);
- }
- /* Check for a valid MAC address - Only compare first three bytes */
- if ( bcmp( (char *)&npeMacAddr.macAddress, ixdp425IntelMacPrefix, 3) )
- {
- /* Don't have a valid MAC in NVRAM so we fall back to Intel's base addresses */
- bcopy ((char *)sysIxEthAccEndEnetAddr, (char *)npeMacAddr.macAddress, 6);
- npeMacAddr.macAddress[5] += port;
- printf("ixe ETH PHY %d Hard Coded MAC address is: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2xn"
- , port
- ,npeMacAddr.macAddress[0], npeMacAddr.macAddress[1]
- ,npeMacAddr.macAddress[2], npeMacAddr.macAddress[3]
- ,npeMacAddr.macAddress[4], npeMacAddr.macAddress[5]);
- }
- else
- {
- #ifdef SYS_END_DEBUG
- printf("ixe ETH PHY %d MAC address is: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2xn"
- , port
- ,npeMacAddr.macAddress[0], npeMacAddr.macAddress[1]
- ,npeMacAddr.macAddress[2], npeMacAddr.macAddress[3]
- ,npeMacAddr.macAddress[4], npeMacAddr.macAddress[5]);
- #endif /* SYS_END_DEBUG */
- }
- #else /* Hard encoded MAC */
- bcopy ((char *)sysIxEthAccEndEnetAddr, (char *)npeMacAddr.macAddress, 6);
- npeMacAddr.macAddress[5] += port;
- printf("ixe ETH PHY %d Hard Coded MAC address is: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2xn"
- , port
- ,npeMacAddr.macAddress[0], npeMacAddr.macAddress[1]
- ,npeMacAddr.macAddress[2], npeMacAddr.macAddress[3]
- ,npeMacAddr.macAddress[4], npeMacAddr.macAddress[5]);
- #endif
- if (ixEthAccPortUnicastMacAddressSet(port, &npeMacAddr) != IX_ETH_ACC_SUCCESS)
- {
- return(IX_FAIL);
- }
- return(IX_SUCCESS);
- }
- /**
- * @fn IX_STATUS ixdp425EthAccStartDispatch()
- *
- * @param BOOL interruptMode - start in interrupt or polled mode
- *
- * This function starts the Queue manager dispatch timer.
- *
- * @return IX_SUCCESS - Dispatch timer successfully started
- * @return IX_FAIL - Error starting dispatch timer
- */
- PRIVATE IX_STATUS ixdp425EthAccStartDispatch(BOOL interruptMode)
- {
- if (interruptMode) /* Interrupt mode */
- {
- /*
- * Hook the QM QLOW dispatcher to the interrupt controller.
- * The ethernet NPEs use queues 24 through 27.
- */
- if (ixOsServIntBind(IXP425_INT_LVL_QM1,
- (VOIDFUNCPTR)ixQMgrDispatcherLoopRun,
- (void *)IX_QMGR_QUELOW_GROUP) != IX_SUCCESS)
- {
- printf("ixe Ethernet Lib - Failed to bind to QM1 interruptn"
- );
- return(IX_FAIL);
- }
- }
- else /* Polled mode */
- {
- return(IX_FAIL);
- }
- return(IX_SUCCESS);
- }
- IX_STATUS ixdp425EthLibInit()
- {
- UINT32 i;
- if (ixdp425EthLibInitialised)
- {
- printf("ixe Ethernet Lib - Ethernet codelet already initialisedn");
- return(IX_SUCCESS);
- }
- /* Initialise Queue Manager */
- #ifdef SYS_END_DEBUG
- DRV_LOG("ixdp425EthLibInit: Initialising Queue Manager...n");
- #endif /* SYS_END_DEBUG */
- if (ixQMgrInit() != IX_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error initialising Intel queue manager!n");
- return(IX_FAIL);
- }
- /* Start the Queue Manager dispatcher loop */
- if (ixdp425EthAccStartDispatch(TRUE) != IX_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error starting Intel queue manager dispatch loop!n");
- return(IX_FAIL);
- }
- /* Initialise ixes */
- #ifdef SYS_END_DEBUG
- DRV_LOG("ixdp425EthLibInit: Initialising ixes...n");
- #endif /* SYS_END_DEBUG */
- if (ixdp425EthAccNpeInit(IX_NPEDL_NPEID_NPEB) != IX_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error initialising ixe 0!n");
- return(IX_FAIL);
- }
- if (ixdp425EthAccNpeInit(IX_NPEDL_NPEID_NPEC) != IX_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error initialising ixe 1!n");
- return(IX_FAIL);
- }
- /* Initialise NPE Message handler */
- #ifdef SYS_END_DEBUG
- DRV_LOG("nixdp425EthLibInit: Starting ixe message handler...n");
- #endif /* SYS_END_DEBUG */
- if (ixNpeMhInitialize(IX_NPEMH_NPEINTERRUPTS_YES) != IX_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error initialising ixe Message handler!n");
- return(IX_FAIL);
- }
- /* Start NPEs */
- #ifdef SYS_END_DEBUG
- DRV_LOG("ixdp425EthLibInit: Starting ixes...n");
- #endif /* SYS_END_DEBUG */
- if (ixNpeDlNpeExecutionStart(IX_NPEDL_NPEID_NPEB) != IX_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error starting ixe 0!n");
- return(IX_FAIL);
- }
- if (ixNpeDlNpeExecutionStart(IX_NPEDL_NPEID_NPEC) != IX_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error starting ixe 1!n");
- return(IX_FAIL);
- }
- /***********************************************************************
- *
- * System initialisation done. Now initialise Ethernet Access components.
- *
- ***********************************************************************/
- if (ixEthAccInit() != IX_ETH_ACC_SUCCESS)
- {
- printf("ixdp425EthLibInit: Error initialising ixe Ethernet access driver!n");
- return(IX_FAIL);
- }
- ixdp425EthLibInitialised = TRUE;
- return(IX_SUCCESS);
- }
- IX_STATUS ixdp425EthPhysInit(int port)
- {
- /* Initialise Ethernet ports */
- if (ixEthAccPortInit(port) != IX_ETH_ACC_SUCCESS)
- {
- printf("Error initialising ixe Ethernet port %d!n" , port);
- return(IX_FAIL);
- }
- /* Find and initialise all available PHYs */
- if (ixdp425EthAccPhyInit(port) != IX_SUCCESS)
- {
- printf("Error initialising PNE Ethernet phy %d!n" , port);
- return(IX_FAIL);
- }
- /* Program MAC addresses for available PHYs */
- if (ixdp425EthAccMacSet(port) != IX_SUCCESS)
- {
- printf("Error programming MAC address for Ethernet phy %d!n" , port);
- return(IX_FAIL);
- }
- if (ixEthAccPortTxFrameAppendFCSEnable(port) != IX_ETH_ACC_SUCCESS)
- {
- printf("Error setting ixEthAccPortTxFrameAppendFCSEnable mode for port %dn" , port);
- return(IX_FAIL);
- }
- if (ixEthAccPortRxFrameAppendFCSDisable(port) != IX_ETH_ACC_SUCCESS)
- {
- printf("Error setting ixEthAccPortRxFrameAppendFCSDisable mode for port %dn" , port);
- return(IX_FAIL);
- }
- /* Set scheduling discipline */
- ixEthAccTxSchedulingDisciplineSet(port, FIFO_NO_PRIORITY);
- return(IX_SUCCESS);
- }
- STATUS ixdp425EthEndMuxInit()
- {
- END_TBL_ENTRY *pDevTbl;
- UINT32 i;
- 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 (i=0; i<IX_ETH_ACC_NUMBER_OF_PORTS; i++)
- {
- #ifndef INCLUDE_IXETHACC_PORT0_END
- if ( i == 0 )
- continue;
- #endif
- #ifndef INCLUDE_IXETHACC_PORT1_END
- if ( i == 1 )
- continue;
- #endif
- /* Fill in the endDev entry for this device */
- pDevTbl->unit = i;
- pDevTbl->endLoadFunc = ixEthAccEndLoad;
- pDevTbl->endLoadString = ixpEndLoadStr[i];
- 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 Maskn"
- ,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%dn",n);
- sprintf(inetAddr, "%s", sysIxEthAccEndIpAddr[n]);
- goto hardCodedRetry;
- #else
- ipaddrOk = 0;
- printf("ixdp425EthEndStartUp: Invalid Address for ixe%d IP: %s Ignoringn",n,inetAddr);
- break;
- #endif
- }
- if ( inetAddr[++index] == 0 )
- break;
- }
- if ( ipaddrOk )
- {
- ifAddrSet(nameAndUnit, inetAddr);
- if( colon != NULL )
- {
- ifMaskSet(nameAndUnit, ixdp425EthEndMask);
- printf("ixdp425EthEndStartUp: ixe%d: IP Addr set to %s:%xn"
- ,n, inetAddr, ixdp425EthEndMask);
- }
- else
- {
- printf("ixdp425EthEndStartUp: ixe%d: IP Addr set to %sn",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",mBufPtr->m_len,0,0,0,0,0);
- logMsg("m_pkthdr.len: %d", mBufPtr->m_pkthdr.len,0,0,0,0,0);
- logMsg("m_next 0x%x",(UINT32)mBufPtr->m_next,0,0,0,0,0);
- logMsg("m_type 0x%x", mBufPtr->m_type,0,0,0,0,0);
- logMsg("data: ",0,0,0,0,0,0);
- for (j=0;j<mBufPtr->m_len/16;j++)
- {
- for (k=0;k<16;k++)
- {
- logMsg("0x%x ",mBufPtr->m_data[j*16 + k],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",
- 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:%02xn",
- etherDstAddr[0],
- etherDstAddr[1],
- etherDstAddr[2],
- etherDstAddr[3],
- etherDstAddr[4],
- etherDstAddr[5] );
- logMsg("Ethernet Src MAC: 0x%02x:%02x:%02x:%02x:%02x:%02xn",
- etherSrcAddr[0],
- etherSrcAddr[1],
- etherSrcAddr[2],
- etherSrcAddr[3],
- etherSrcAddr[4],
- etherSrcAddr[5] );
- logMsg("Ethernet Type (%X): %sn", 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 ipAddrStr[INET_ADDR_LEN];
- if (mData == NULL)
- {
- logMsg("ERROR: RNDIS detected NULL pointer in ixIpHdrDumpn",
- 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 ALIGNEDn", 0, 0, 0, 0, 0, 0);
- }
- logMsg("Total Length: %u 0x%08Xn",
- ntohs(((struct ip *) mData)->ip_len),(((struct ip *) mData)->ip_len) , 0, 0, 0, 0);
- logMsg("Protocol: %sn",
- (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, ipAddrStr);
- logMsg("Src Addr: %sn", (int)ipAddrStr, 0, 0, 0, 0, 0);
- inet_ntoa_b(dstAddr, ipAddrStr);
- logMsg("Dst Addr: %sn", (int)ipAddrStr, 0, 0, 0, 0, 0);
- }
- #endif /* INCLUDE_IXETHACCEND */