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

📄 ne2000end.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 4 页
字号:
    /* compute packet size excluding Ethernet checksum bytes */    packetSize = (((UINT)h.uppByteCnt << 8) + h.lowByteCnt) - 4;    /* Check for packet (and header) shifted in memory (by heavy load).     * The method and solution are recommended by 3Com in their     * EtherLink II Adapter Technical Manual, with the addition of     * a reasonableness check on the next-page link.     */    pageCount = (UCHAR) ((packetSize + 4 + sizeof (NE2000_HEADER) + (ENE_PAGESIZE - 1))		 / ENE_PAGESIZE);    tempPage = (UCHAR) (pDrvCtrl->nextPacket + pageCount);    if (tempPage >= NE2000_PSTOP)	tempPage -= (NE2000_PSTOP - NE2000_PSTART);    if ((h.next != tempPage) ||	(h.next < NE2000_PSTART) || (h.next >= NE2000_PSTOP))	{	/* can't trust anything now */	pDrvCtrl->stats.badPacket++;	pDrvCtrl->stats.rerror++;	/* stop and restart the interface */	if (!(pDrvCtrl->flags & (END_OVERWRITE|END_OVERWRITE2)))	    ne2000Config (pDrvCtrl, TRUE);	return (-1);	}    /* reject runts, although we are configured to reject them */    if (packetSize < 60)	{	pDrvCtrl->stats.shortPacket++;	goto doneGet;	}    /* reject packets larger than our scratch buffer */    if (packetSize > NE2000_BUFSIZ)	goto doneGet;    if (h.rstat & RSTAT_PRX)	{	/* 3Com says this status marks a packet bit-shifted in memory;	 * the data cannot be trusted but the NIC header is OK.	 */	if (h.rstat & (RSTAT_DFR | RSTAT_DIS))	    {	    pDrvCtrl->stats.badPacket++;	    pDrvCtrl->stats.rerror++;	    goto doneGet;	    }	pDrvCtrl->stats.rnoerror++;	}    else	{	if (h.rstat & RSTAT_DFR)	    pDrvCtrl->stats.jabber++;	pDrvCtrl->stats.rerror++;	goto doneGet;	}    /* Signal that we received a good packet */    packetLen = packetSize;    /* copy separated frame to a temporary buffer */    ne2000DataIn (pDrvCtrl,		  ((UINT)pDrvCtrl->nextPacket << 8) + sizeof (NE2000_HEADER),		  packetLen,		  pData);doneGet:    pDrvCtrl->nextPacket = h.next;    SYS_OUT_CHAR (pDrvCtrl, ENE_BOUND,		  (pDrvCtrl->nextPacket != NE2000_PSTART ?		   pDrvCtrl->nextPacket - 1 : NE2000_PSTOP - 1));    return (packetLen);    }/******************************************************************************** ne2000PollRecv - routine to receive a packet in polled mode.** This routine is called by a user to try and get a packet from the* device.*/LOCAL STATUS ne2000PollRecv    (    void*	pCookie,	/* device ptr */    M_BLK_ID	pMblk    )    {    int len;    NE2000END_DEVICE* pDrvCtrl = (NE2000END_DEVICE *) pCookie;    /* If no packet is available return immediately */    pDrvCtrl->current = ne2000GetCurr (pDrvCtrl);    if (pDrvCtrl->nextPacket == pDrvCtrl->current)        return ((STATUS) (EAGAIN));    /* Upper layer provides the buffer, make sure it's big enough. */    if ((pMblk->mBlkHdr.mLen < NE2000_BUFSIZ)	|| !(pMblk->mBlkHdr.mFlags & M_EXT))	{        return ((STATUS) (EAGAIN));	}    ENDLOGMSG (("ne2000PollRecv: enter: imask=%02x\n",		pDrvCtrl->imask, 0, 0, 0, 0, 0));    len = ne2000PacketGet (pDrvCtrl, pMblk->mBlkHdr.mData + pDrvCtrl->offset);    if (len <= 0)        return ((STATUS) (EAGAIN));    pMblk->mBlkHdr.mFlags |= M_PKTHDR;    pMblk->mBlkHdr.mLen   = len;    pMblk->mBlkPktHdr.len = len;    /* Adjust mData to match n23000PacketGet() above */    pMblk->mBlkHdr.mData += pDrvCtrl->offset;    ENDLOGMSG (("ne2000PollRecv: done: imask=%02x\n",		pDrvCtrl->imask, 0, 0, 0, 0, 0));    return (OK);    }/********************************************************************************* ne2000PollSend - routine to send a packet in polled mode.** This routine is called by a user to try and send a packet on the* device.*/static STATUS ne2000PollSend    (    void*	pCookie,	/* device ptr */    M_BLK_ID	pMblk    )    {    char *	pBuf;    UCHAR	cmdStat;    int		len;    NE2000END_DEVICE* pDrvCtrl = (NE2000END_DEVICE *) pCookie;        ENDLOGMSG (("ne2000PollSend: enter: imask=%x flags=%x\n",		pDrvCtrl->imask, pDrvCtrl->flags, 0, 0, 0, 0));    SYS_IN_CHAR (pDrvCtrl, ENE_CMD, &cmdStat);    while (cmdStat & CMD_TXP)	SYS_IN_CHAR (pDrvCtrl, ENE_DATA, &cmdStat);    /* Get the next TXD */    pBuf = pDrvCtrl->packetBuf;    len = netMblkToBufCopy (pMblk, pBuf, NULL);    len = max (len, ETHERSMALL);    /* Transfer to the device */    ne2000DataOut (pDrvCtrl, pDrvCtrl->packetBuf, len, (NE2000_TSTART << 8));    /* Flush the write pipe */        CACHE_PIPE_FLUSH ();        /* kick Transmitter */    SYS_OUT_CHAR (pDrvCtrl, ENE_TSTART, NE2000_TSTART);    SYS_OUT_CHAR (pDrvCtrl, ENE_TCNTH, len >> 8);    SYS_OUT_CHAR (pDrvCtrl, ENE_TCNTL, len & 0xff);    SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_TXP | CMD_START);    /* update statistics */    END_ERR_ADD (&pDrvCtrl->endObj, MIB2_OUT_UCAST, +1);    /* Flush the write pipe */    CACHE_PIPE_FLUSH ();    /* Spin until the packet has been sent */    SYS_IN_CHAR (pDrvCtrl, ENE_CMD, &cmdStat);    while (cmdStat & CMD_TXP)	SYS_IN_CHAR (pDrvCtrl, ENE_CMD, &cmdStat);    ENDLOGMSG (("ne2000PollSend: done: imask=%x flags=%x\n",		pDrvCtrl->imask, pDrvCtrl->flags, 0, 0, 0, 0));    return (OK);    }/********************************************************************************* ne2000PollStart - start polled mode operations** RETURNS: OK or ERROR.*/LOCAL STATUS ne2000PollStart    (    NE2000END_DEVICE* pDrvCtrl    )    {    int oldLevel;    oldLevel = intLock ();    ENDLOGMSG (("ne2000PollStart: imask=%x flags=%x\n",		pDrvCtrl->imask, pDrvCtrl->flags, 0, 0, 0, 0));    pDrvCtrl->flags |= END_POLLING;    pDrvCtrl->imask = 0;    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);    intUnlock (oldLevel);    return (OK);    }/********************************************************************************* ne2000PollStop - stop polled mode operations** This function terminates polled mode operation.  The device returns to* interrupt mode.** The device interrupts are enabled, the current mode flag is switched* to indicate interrupt mode and the device is then reconfigured for* interrupt operation.** RETURNS: OK or ERROR.*/LOCAL STATUS ne2000PollStop    (    NE2000END_DEVICE* pDrvCtrl    )    {    int oldLevel;    oldLevel = intLock ();    pDrvCtrl->flags &= ~END_POLLING;    pDrvCtrl->imask = NE2000_ALL_INTS;    /* leave recv int disabled if in receive loop. */    if (pDrvCtrl->flags & END_RECV_HANDLING_FLAG)	pDrvCtrl->imask &= ~IM_PRXE;    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);    ENDLOGMSG (("ne2000PollStop: imask=%x flags=%x\n",		pDrvCtrl->imask, pDrvCtrl->flags, 0, 0, 0, 0));    intUnlock (oldLevel);    return (OK);    }/******************************************************************************** ne2000AddrFilterSet - set the address filter for multicast addresses** This routine goes through all of the multicast addresses on the list* of addresses (added with the endAddrAdd() routine) and sets the* device's filter correctly.** NOMANUAL*/LOCAL void ne2000AddrFilterSet    (    NE2000END_DEVICE *pDrvCtrl    )    {    int i;    int len;    int count;    u_char c;    u_char *pCp;    u_long crc;    ETHER_MULTI* pCurr;    ENDLOGMSG (("ne2000AddrFilterSet\n", 0, 0, 0, 0, 0, 0));    /* clear filter to begin with */    for (i = 0; i < 8; ++i)	pDrvCtrl->mcastFilter[i] = 0;    /* now map each multicast addr into the filter */    for (pCurr = END_MULTI_LST_FIRST (&pDrvCtrl->endObj);	 pCurr != NULL;	 pCurr = END_MULTI_LST_NEXT(pCurr))	{	/*	 * AUTODIN-II, adapted for ethernet (bit reversed),	 * taken from the ln7990End.c driver	 */	pCp = (unsigned char *)&pCurr->addr;	crc = 0xffffffff;	for (len = 6; --len >= 0;)	    {	    c = *pCp++;	    for (count = 0; count < 8; count++)		{		if ((c & 0x01) ^ (crc & 0x01))		    {		    crc >>= 1;		    crc = crc ^ 0xedb88320;		    }		else		    {		    crc >>= 1;		    }		c >>= 1;		}	    }	/* Just want the 6 most significant bits. */	crc = crc >> 26;	/* Turn on the corresponding bit in the filter. */	pDrvCtrl->mcastFilter[crc >> 3] |= (1 << (crc & 0x07));	}    }/******************************************************************************* ne2000MCastAdd - add a multicast address for the device** This routine adds a multicast address to whatever the driver* is already listening for.  It then resets the address filter.*/LOCAL STATUS ne2000MCastAdd    (    void*	pCookie,	/* device ptr */    char*	pAddress    )    {    NE2000END_DEVICE* pDrvCtrl = (NE2000END_DEVICE *) pCookie;    ENDLOGMSG (("ne2000MCastAdd - %02x:%02x:%02x:%02x:%02x:%02x\n",		pAddress[0]&0xff, pAddress[1]&0xff, pAddress[2]&0xff,		pAddress[3]&0xff, pAddress[4]&0xff, pAddress[5]&0xff));    if (etherMultiAdd (&pDrvCtrl->endObj.multiList, pAddress) == ENETRESET)	{	ne2000Config (pDrvCtrl, TRUE);	}    return (OK);    }/******************************************************************************* ne2000MCastDel - delete a multicast address for the device** This routine removes a multicast address from whatever the driver* is listening for.  It then resets the address filter.*/LOCAL STATUS ne2000MCastDel    (    void*	pCookie,	/* device ptr */    char*	pAddress    )    {    NE2000END_DEVICE* pDrvCtrl = (NE2000END_DEVICE *) pCookie;    ENDLOGMSG (("ne2000MCastDel - %02x:%02x:%02x:%02x:%02x:%02x\n",		pAddress[0]&0xff, pAddress[1]&0xff, pAddress[2]&0xff,		pAddress[3]&0xff, pAddress[4]&0xff, pAddress[5]&0xff));    if (etherMultiDel (&pDrvCtrl->endObj.multiList, (char *)pAddress) == ENETRESET)	{	ne2000Config (pDrvCtrl, TRUE);	}    return (OK);    }/******************************************************************************* ne2000MCastGet - get the multicast address list for the device** This routine gets the multicast list of whatever the driver* is already listening for.*/LOCAL STATUS ne2000MCastGet    (    void*		pCookie,	/* device ptr */    MULTI_TABLE*	pTable    )    {    int error;    NE2000END_DEVICE* pDrvCtrl = (NE2000END_DEVICE *) pCookie;    ENDLOGMSG (("ne2000MCastGet\n", 0, 0, 0, 0, 0, 0));    error = etherMultiGet (&pDrvCtrl->endObj.multiList, pTable);    return (error);    }/******************************************************************************** ne2000Stop - stop the device** This function calls BSP functions to disconnect interrupts and stop* the device from operating in interrupt mode.** RETURNS: OK or ERROR*/LOCAL STATUS ne2000Stop    (    void *pCookie    )    {    STATUS result = OK;    NE2000END_DEVICE* pDrvCtrl = (NE2000END_DEVICE *) pCookie;    /* TODO - stop/disable the device. */    ENDLOGMSG (("ne2000Stop\n", 0, 0, 0, 0, 0, 0));    SYS_INT_DISCONNECT (pDrvCtrl, ne2000Int, (int)pDrvCtrl, &result);    if (result == ERROR)	ENDLOGMSG (("Could not disconnect interrupt!\n", 1, 2, 3, 4, 5, 6));    return (result);    }/******************************************************************************** ne2000Unload - unload a driver from the system** This function first brings down the device, and then frees any* stuff that was allocated by the driver in the load function.*/LOCAL STATUS ne2000Unload    (    void *pCookie    )    {    NE2000END_DEVICE* pDrvCtrl = (NE2000END_DEVICE *) pCookie;    ENDLOGMSG (("ne2000Unload\n", 0, 0, 0, 0, 0, 0));    END_OBJECT_UNLOAD (&pDrvCtrl->endObj); /* generic end unload functions */    return (OK);    }/******************************************************************************** ne2000EnetAddrGet - get enet address** NOMANUAL*/LOCAL void ne2000EnetAddrGet    (    NE2000END_DEVICE* pDrvCtrl    )    {    int i;    if (pDrvCtrl->usePromEnetAddr)	{	SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_NODMA | CMD_PAGE0 | CMD_START);	SYS_OUT_CHAR (pDrvCtrl, ENE_RSAR0, NE2000_EADDR_LOC);	SYS_OUT_CHAR (pDrvCtrl, ENE_RSAR1, NE2000_CONFIG_PAGE);	SYS_OUT_CHAR (pDrvCtrl, ENE_RBCR0, (EADDR_LEN * 2) & 0xff);	SYS_OUT_CHAR (pDrvCtrl, ENE_RBCR1, (EADDR_LEN * 2) >> 8);	SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_RREAD | CMD_START);	for (i = 0; i < 6; ++i)	    {	    char ch;	    	    SYS_IN_CHAR (pDrvCtrl, ENE_DATA, &pDrvCtrl->enetAddr[i]);	    /* Must consume "duplicate" high bytes in 8-bit mode */	    if (pDrvCtrl->byteAccess)		SYS_IN_CHAR (pDrvCtrl, ENE_DATA, &ch);	    }	/* check for enet addr of all zeros (unprogrammed) */	for (i = 0; i < 6; ++i)	    if (pDrvCtrl->enetAddr[i])		return;	}    /* get the enet addr from the BSP. */    for (i = 0; i < 6; ++i)	pDrvCtrl->enetAddr[i] = ne2000EnetAddr[i];	    }/******************************************************************************** ne2000GetCurr - get current page** RETURNS: current page that ENE is working on** NOMANUAL*/LOCAL UCHAR ne2000GetCurr    (    NE2000END_DEVICE* pDrvCtrl    )    {    UCHAR curr;    /* get CURR register */    SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_PAGE1);    SYS_IN_CHAR (pDrvCtrl, ENE_CURR, &curr);    SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_PAGE0);    return (curr);    }

⌨️ 快捷键说明

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