📄 ether_test.c
字号:
/* It worked! */
mask_557_ints (); /* Disable 557 interrupt */
printf ("\nEthernet controller passed. Press return to continue.\n");
sgets (buf);
}
}
/* Perform internal self test - returns OK if sucessful, ERROR if not. */
static int i557SelfTest ()
{
volatile struct selfTest *pSelfTestMem;
UINT32 oldWord2;
long delay;
UINT32 temp;
int rtnVal;
/* reset the 82557 to start with a clean slate */
resetChip();
/* Allocate some memory for the self test */
pSelfTestMem = (struct selfTest *) malloc (sizeof(struct selfTest));
if (pSelfTestMem == NULL)
{
printf ("Couldn't get memory for self test.\n");
return (ERROR);
}
printf ("Sending PORT* self-test command...\n");
printf ("Local Dump address = 0x%X\n", pSelfTestMem);
/* Set all bits in second word, wait until it changes or a timeout */
pSelfTestMem->u.word2 = ~0;
oldWord2 = pSelfTestMem->u.word2;
temp = ((UINT32) pSelfTestMem) + PORT_SELF_TEST;
portWrite (temp);
/* Wait for test completion or for timeout */
for (delay = 0; (delay < MAX_DELAY) && (pSelfTestMem->u.word2 == oldWord2); delay++); /* Wait... */
/* Print results */
printf ("Self test result: %s\n", (pSelfTestMem->u.bits.selfTest) ? "Fail" : "Pass");
printf ("ROM content test: %s\n", (pSelfTestMem->u.bits.romTest) ? "Fail" : "Pass");
printf ("Register test: %s\n", (pSelfTestMem->u.bits.regTest) ? "Fail" : "Pass");
printf ("Diagnose test: %s\n", (pSelfTestMem->u.bits.diagnTest) ? "Fail" : "Pass");
printf ("ROM signature: 0x%X\n", pSelfTestMem->romSig);
rtnVal = pSelfTestMem->u.bits.selfTest ? ERROR : OK;
return (rtnVal);
}
/* Initialize the 82557. */
static int i557Init (void)
{
/* Get memory for system data structures */
if ( ((pRfd = (struct rfd *) malloc (sizeof(struct rfd))) == NULL) ||
((pPacketBuf = malloc(ETHERMTU + sizeof(UINT16) + 6)) == NULL) ||
((pCmdBlock = (union cmdBlock *) malloc (sizeof(union cmdBlock))) == NULL) )
{
printf ("Memory allocation failed.\n");
return (ERROR);
}
/* Set EL bits in command block and rfd so we don't fall of the end */
pCmdBlock->nop.el = END_OF_LIST;
pRfd->el = END_OF_LIST;
/* Reset chip and initialize */
printf ("Initializing... ");
/* Reset 82557 */
resetChip ();
/* set up the CU and RU base values to 0x0 */
sendCommand (LOAD_CU_BASE, RU_NOP, 0);
sendCommand (CU_NOP, LOAD_RU_BASE, 0);
/* Initialize interrupts */
/* if it is the onboard i82559, it does not use the conventional PCI
interrupt routines because the interrupt is not multiplexed onto
the PCI bus */
if ((unit_busno == 2) && (unit_devno == 0) && (unit_funcno == 0))
{
if (isr_connect (ENET_INT_ID, (VOIDFUNCPTR)i557IntHandler, 0xdeadbeef) != OK)
{
printf ("Error connecting Ethernet interrupt!\n");
return (ERROR);
}
if (enable_external_interrupt (ENET_INT_ID) != OK)
{
printf ("Error enabling Ethernet interrupt!\n");
return (ERROR);
}
}
else /* use regular PCI int connect scheme */
{
if (pci_isr_connect (unit_intpin, unit_busno, unit_devno, i557IntHandler, 0xdeadbeef) != OK)
{
printf ("Error connecting Ethernet interrupt!\n");
return (ERROR);
}
}
unmask_557_ints();
printf ("Done\n");
return (OK);
}
static int initPHY (UINT32 device_type, int loop_mode)
{
UINT16 temp_reg;
UINT8 revision;
/* strip off revision and phy. id information */
revision = (UINT8)(device_type & REVISION_MASK);
device_type &= ~REVISION_MASK;
switch (device_type)
{
case ICS1890_PHY_ID:
temp_reg = readMDI (0, MDI_DEFAULT_PHY_ADDR, MDI_PHY_CTRL); /* get ready for loopback setting */
switch (loop_mode)
{
case EXT_LOOP_BACK: /* loopback on the MII interface */
temp_reg |= MDI_CTRL_LOOPBACK; /* MII loopback */
break;
case INT_LOOP_BACK:
default:
break;
}
writeMDI(0, MDI_DEFAULT_PHY_ADDR, MDI_PHY_CTRL, temp_reg);
break;
case DP83840_PHY_ID: /* set the Intel-specified "must set" bits */
temp_reg = readMDI (0,MDI_DEFAULT_PHY_ADDR, DP83840_PCR_REG);
temp_reg |= (PCR_TXREADY_SEL | PCR_FCONNECT);
writeMDI (0,MDI_DEFAULT_PHY_ADDR, DP83840_PCR_REG, temp_reg);
/* get ready for loopback setting */
temp_reg = readMDI (0,MDI_DEFAULT_PHY_ADDR, DP83840_LOOPBACK_REG);
temp_reg &= CLEAR_LOOP_BITS;
switch (loop_mode)
{
case EXT_LOOP_BACK:
temp_reg |= TWISTER_LOOPBACK;
break;
case INT_LOOP_BACK:
default:
break;
}
writeMDI (0,MDI_DEFAULT_PHY_ADDR, DP83840_LOOPBACK_REG, temp_reg);
break;
case I82553_PHY_ID:
case I82553_REVAB_PHY_ID:
case I82555_PHY_ID:
break;
default:
return (ERROR);
break;
}
return (OK);
}
/* Set hardware address of the 82557. */
static int i557AddrSet ()
{
printf ("Setting hardware ethernet address to ");
printf ("%02X:%02X:%02X:", node_address[0], node_address[1], node_address[2]);
printf ("%02X:%02X:%02X... ", node_address[3], node_address[4], node_address[5]);
/* Set up iaSetup command block and execute */
bzero ((char *) pCmdBlock, sizeof(union cmdBlock));
pCmdBlock->iaSetup.code = IA_SETUP;
pCmdBlock->iaSetup.el = END_OF_LIST;
bcopy (node_address, pCmdBlock->iaSetup.enetAddr, sizeof(node_address));
sendCommand (CU_START, RU_NOP, ((UINT32)pCmdBlock));
if ((waitForInt() == ERROR) || (pCmdBlock->iaSetup.ok != 1))
{
printf ("failed. Status: 0x%04X.\n", pSCB->cmdStat.words.status);
printf ("C bit = %d\n",pCmdBlock->iaSetup.c);
printf ("OK bit = %d\n",pCmdBlock->iaSetup.ok);
return (ERROR);
}
printf ("done.\n");
return (OK);
}
/* Configure the 82557. */
static int i557Config (UINT8 loopBackMode) /* None, int, or ext 1, 2 (see etherTest.h) */
{
printf ("\nConfiguring for ");
switch (loopBackMode)
{
case INT_LOOP_BACK:
printf ("internal loopback... ");
break;
case EXT_LOOP_BACK:
printf ("external loopback, LPBK* active... ");
break;
default:
printf ("Unknown loopback mode, exiting...\n");
return (ERROR);
}
/* Set up configure command block and execute */
bzero ((char *) pCmdBlock, sizeof(union cmdBlock));
pCmdBlock->configure.code = CONFIGURE;
pCmdBlock->configure.el = END_OF_LIST;
pCmdBlock->configure.configData[ 0] = CONFIG_BYTE_00;
pCmdBlock->configure.configData[ 1] = CONFIG_BYTE_01;
pCmdBlock->configure.configData[ 2] = CONFIG_BYTE_02;
pCmdBlock->configure.configData[ 3] = CONFIG_BYTE_03;
pCmdBlock->configure.configData[ 4] = CONFIG_BYTE_04;
pCmdBlock->configure.configData[ 5] = CONFIG_BYTE_05;
pCmdBlock->configure.configData[ 6] = CONFIG_BYTE_06;
pCmdBlock->configure.configData[ 7] = CONFIG_BYTE_07;
pCmdBlock->configure.configData[ 8] = CONFIG_BYTE_08;
pCmdBlock->configure.configData[ 9] = CONFIG_BYTE_09;
pCmdBlock->configure.configData[10] = CONFIG_BYTE_10 | loopBackMode;
pCmdBlock->configure.configData[11] = CONFIG_BYTE_11;
pCmdBlock->configure.configData[12] = CONFIG_BYTE_12;
pCmdBlock->configure.configData[13] = CONFIG_BYTE_13;
pCmdBlock->configure.configData[14] = CONFIG_BYTE_14;
pCmdBlock->configure.configData[15] = CONFIG_BYTE_15;
pCmdBlock->configure.configData[16] = CONFIG_BYTE_16;
pCmdBlock->configure.configData[17] = CONFIG_BYTE_17;
pCmdBlock->configure.configData[18] = CONFIG_BYTE_18;
if (link_speed == SPEED_100M)
pCmdBlock->configure.configData[19] = CONFIG_BYTE_19_100T;
else
{
pCmdBlock->configure.configData[19] = CONFIG_BYTE_19_10T;
pCmdBlock->configure.configData[20] = CONFIG_BYTE_20;
pCmdBlock->configure.configData[21] = CONFIG_BYTE_21;
}
sendCommand (CU_START, RU_NOP, ((UINT32)pCmdBlock));
if ((waitForInt() == ERROR) || (pCmdBlock->configure.ok != 1))
{
printf ("failed. Status: 0x%04X.\n",
pSCB->cmdStat.words.status);
return (ERROR);
}
initPHY (phy_id, loopBackMode); /* set up the PHY interface appropriately */
printf ("done.\n");
return (OK);
}
static int i557RUStart ()
{
volatile long delay;
#if 0
printf ("Enabling receiver... ");
#endif
bzero ((char *) pRfd, sizeof(struct rfd));
/* Set end-of-list bit in the rfd so we don't fall off the end */
pRfd->el = END_OF_LIST;
pRfd->s = 1;
pRfd->sf = 0; /* Simplified mode */
pRfd->rbdAddr = (UINT8 *) 0xffffffff; /* No RBD */
/* buffer size: */
pRfd->size = sizeof (pRfd->rxData) + sizeof (pRfd->destAddr) + sizeof (pRfd->sourceAddr) + sizeof (pRfd->length);
sendCommand (CU_NOP, RU_START, ((UINT32)pRfd));
/*
* Poll, can't use waitForInt (), as this step doesn't generate interrupts.
*/
i557Status = 0;
/* Wait for timeout (i557Status changes) or RU_STAT is RU_READY */
for (delay = 0; (delay < MAX_DELAY) && (pSCB->cmdStat.bits.rus != RU_READY); delay++)
; /* Wait... */
if (pSCB->cmdStat.bits.rus != RU_READY)
{
printf ("failed. Status: 0x%04X.\n",
pSCB->cmdStat.words.status);
return (ERROR);
}
#if 0
printf ("done. Status: 0x%04X.\n", pSCB->cmdStat.words.status);
#endif
return (OK);
}
/*
* Get packet ready to send out over the network. Buffer should be
* ETHERMTU + sizeof(enet_addr) + sizeof(UINT16)
*/
static void setUpPacket (char *pBuf)/* Where to put it */
{
bcopy (node_address, pBuf, sizeof(node_address));
pBuf += sizeof(node_address); /* skip dest. address */
*((UINT16 *) pBuf) = 0;
pBuf += sizeof(UINT16); /* skip length field */
makePacket (pBuf, ETHERMTU);
}
/* Send and verify a packet using the current loopback mode. */
static int txPacket (char *pBuf) /* Dest addr, ethertype, buffer */
{
int status = OK;
/* Set up transmit command block and execute */
bzero ((char *) pCmdBlock, sizeof(union cmdBlock));
pCmdBlock->transmit.code = TRANSMIT;
pCmdBlock->transmit.el = END_OF_LIST;
pCmdBlock->transmit.sf = 0; /* Simplified mode */
pCmdBlock->transmit.tbdAddr = (UINT8 *) 0xffffffff; /* No TBD */
pCmdBlock->transmit.eof = 1; /* Entire frame here */
/* # bytes to tx: */
pCmdBlock->transmit.tcbCount = sizeof (pCmdBlock->transmit.destAddr) + sizeof (pCmdBlock->transmit.length) +
sizeof (pCmdBlock->transmit.txData);
#if 0
printf ("destAddr size = %d\n", sizeof (pCmdBlock->transmit.destAddr));
printf ("length size = %d\n", sizeof (pCmdBlock->transmit.length));
printf ("Transmitting %d bytes\n", pCmdBlock->transmit.tcbCount);
#endif
bcopy (pBuf, pCmdBlock->transmit.destAddr, sizeof(node_address) + sizeof(UINT16) + ETHERMTU);
rxSem = 0; /* no Receive interrupt */
sendCommand (CU_START, RU_NOP, ((UINT32)pCmdBlock));
if (waitForInt() == ERROR)
{
printf ("No Transmit Interrupt\n");
status = ERROR;
}
if (pCmdBlock->transmit.ok != 1)
{
printf ("tx failed. Status: 0x%04X.\n",
pSCB->cmdStat.words.status);
status = ERROR;
}
if (status == ERROR)
{
printf ("Transmit OK = %d\n", pCmdBlock->transmit.ok);
return (ERROR);
}
#if 1
if (waitForRxInt() == ERROR)
{
printf ("No Receive Interrupt\n");
status = ERROR;
}
if (pRfd->ok != 1)
{
printf ("rx failed. Status: 0x%04X.\n", pSCB->cmdStat.words.status);
status = ERROR;
}
#if 1
/* If RU still ready, hang for receive interrupt */
if (pSCB->cmdStat.bits.rus == RU_READY)
{
if (waitForRxInt() == ERROR)
{
printf ("No Receive Interrupt\n");
status = ERROR;
}
if (pRfd->ok != 1)
{
printf ("rx failed. Status: 0x%04X.\n", pSCB->cmdStat.words.status);
status = ERROR;
}
}
#endif
if (status == ERROR)
{
printf ("\nTransmit Stats:\n");
printf ("---------------\n");
printf ("Transmit OK = %d\n", pCmdBlock->transmit.ok);
printf ("\nReceive Stats:\n");
printf ("---------------\n\n");
printf ("Receive OK = %d\n", pRfd->ok);
printf ("CRC Error = %d\n", pRfd->crcErr);
printf ("Alignment Error = %d\n", pRfd->alignErr);
printf ("Resource Error = %d\n", pRfd->noRsrc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -