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

📄 rtl8019end.c

📁 s2410测试程序,源码,用来深入了解三星2410芯片
💻 C
📖 第 1 页 / 共 5 页
字号:
    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);    END_TX_SEM_GIVE (&pDrvCtrl->endObj);    /* update statistics */    END_ERR_ADD (&pDrvCtrl->endObj, MIB2_OUT_UCAST, +1);    return (OK);    }/********************************************************************************* rtl8019PacketGet - get next received message** Get next received message.  Returns NULL if none are* ready.** RETURNS: ptr to next packet, or NULL if none ready.*/LOCAL int rtl8019PacketGet    (    RTL8019END_DEVICE	*pDrvCtrl,    char		*pData    )    {    UINT        packetSize;    UCHAR	uppByteCnt;    UINT8       tempPage;               /* used in buffer validation */    UINT8       pageCount;              /* used in buffer validation */    UINT        packetLen = 0;    RTL8019_HEADER  h;        if (pDrvCtrl->nextPacket == pDrvCtrl->current)	return (0);	      rtl8019DataIn (pDrvCtrl,		  (((UINT)pDrvCtrl->nextPacket << 8) & 0x0000ffff),		  sizeof (RTL8019_HEADER), (char *) &h);		  		      /*     * Calculate upper byte count in case it's corrupted,     * though this supposedly happens only in StarLAN applications     * with bus clock frequence greater than 4 mHz.     */    if (h.next > pDrvCtrl->nextPacket)	uppByteCnt = (UCHAR) (h.next - pDrvCtrl->nextPacket);    else	uppByteCnt = (UCHAR) ((RTL8019_PSTOP - pDrvCtrl->nextPacket)			      + (h.next - RTL8019_PSTART));    if (h.lowByteCnt > 0xfc)	uppByteCnt -= 2;    else	uppByteCnt -= 1;    h.uppByteCnt = uppByteCnt;    /* 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 (RTL8019_HEADER)			  + (ENE_PAGESIZE - 1)) / ENE_PAGESIZE);    tempPage = (UCHAR) (pDrvCtrl->nextPacket + pageCount);    if (tempPage >= RTL8019_PSTOP)	tempPage -= (RTL8019_PSTOP - RTL8019_PSTART);    if ((h.next != tempPage) ||	(h.next < RTL8019_PSTART) || (h.next >= RTL8019_PSTOP))	{	/* can't trust anything now */	pDrvCtrl->stats.badPacket++;	pDrvCtrl->stats.rerror++;	/* stop and restart the interface */	if (!(pDrvCtrl->flags & (END_OVERWRITE|END_OVERWRITE2)))	    rtl8019Config (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 > RTL8019_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 */    rtl8019DataIn (pDrvCtrl,		  ((UINT)pDrvCtrl->nextPacket << 8) + sizeof (RTL8019_HEADER),		  packetLen,		  pData);		      DUMP_DATA((char*)pData, packetLen );       doneGet:    /*DBG_PRINTF(("%d, Next = %x\n", __LINE__, pDrvCtrl->nextPacket));*/    pDrvCtrl->nextPacket = h.next;    SYS_OUT_CHAR (pDrvCtrl, ENE_BOUND,                     (pDrvCtrl->nextPacket != RTL8019_PSTART ?		     pDrvCtrl->nextPacket - 1 : RTL8019_PSTOP - 1));        return (packetLen);    }/******************************************************************************** rtl8019PollRecv - 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 rtl8019PollRecv    (    void*	pCookie,	/* device ptr */    M_BLK_ID	pMblk    )    {    int len;    RTL8019END_DEVICE* pDrvCtrl = (RTL8019END_DEVICE *) pCookie;    /* If no packet is available return immediately */    pDrvCtrl->current = rtl8019GetCurr (pDrvCtrl);    if (pDrvCtrl->nextPacket == pDrvCtrl->current)        return ((STATUS) (EAGAIN));    /* Upper layer provides the buffer, make sure it's big enough. */    if ((pMblk->mBlkHdr.mLen < RTL8019_BUFSIZ)	|| !(pMblk->mBlkHdr.mFlags & M_EXT))	{        return ((STATUS) (EAGAIN));	}    len = rtl8019PacketGet (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;    return (OK);    }/********************************************************************************* rtl8019PollSend - 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 rtl8019PollSend    (    void*	pCookie,	/* device ptr */    M_BLK_ID	pMblk    )    {    char *	pBuf;    UCHAR	cmdStat;    int		len;    RTL8019END_DEVICE* pDrvCtrl = (RTL8019END_DEVICE *) pCookie;    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 */    rtl8019DataOut (pDrvCtrl, pDrvCtrl->packetBuf, len, (RTL8019_TSTART << 8));    /* Flush the write pipe */    CACHE_PIPE_FLUSH ();    /* kick Transmitter */    SYS_OUT_CHAR (pDrvCtrl, ENE_TSTART, RTL8019_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);     return (OK);    }/********************************************************************************* rtl8019PollStart - start polled mode operations** RETURNS: OK or ERROR.*/LOCAL STATUS rtl8019PollStart    (    RTL8019END_DEVICE* pDrvCtrl    )    {    int oldLevel;    oldLevel = intLock ();    pDrvCtrl->flags |= END_POLLING;    pDrvCtrl->imask = 0;    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);    intUnlock (oldLevel);    return (OK);    }/********************************************************************************* rtl8019PollStop - 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 rtl8019PollStop    (    RTL8019END_DEVICE* pDrvCtrl    )    {    int oldLevel;    oldLevel = intLock ();    pDrvCtrl->flags &= ~END_POLLING;    pDrvCtrl->imask = RTL8019_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);    DBG_PRINTF (("rtl8019PollStop: imask=%x flags=%x\n",		pDrvCtrl->imask, pDrvCtrl->flags));    intUnlock (oldLevel);    return (OK);    }/******************************************************************************** rtl8019AddrFilterSet - set the address filter for multicast addresses** This routine loops through all of the multicast addresses on the list* of addresses (added with the endAddrAdd() routine) and sets the* device's filter appropriately.** NOMANUAL*/LOCAL void rtl8019AddrFilterSet    (    RTL8019END_DEVICE *pDrvCtrl    )    {    int i;    int eAddr;    u_char enetChar;    u_char *pCp;    u_long crc;    ETHER_MULTI* pCurr;    /*     * There are 8 multicast address registers (MAR0-7) which     * decode the multicast addresses to be received.  These     * registers provide filtering of multicast addresses hashed     * by the CRC hardware logic.  All destination addresses are     * fed through the CRC hardware logic and when the last bit     * of the destination address enters the CRC hardware, the     * 6 MSB's of the CRC generator are latched.  These six bits     * are then used to index a unique filter bit (FB0-63, 64 since     * there are eight-8bit registers, and 2^6 = 64) in the multicast     * address registers.   If the index filter bit is set,     * the packet is accepted.     *     * To configure MAR0-7 to accept a specific multicast address,     * the above sequence must be also be duplicated in software to     * determine which filter bit in the multicast registers should     * be set for a given multicast address.   Several bits can be     * set to accept several multicast addresses.     *     * The standard AUTODIN-II polynomial is used for the 32-bit CRC     * hash index calculation.  The AUTODIN-II, FDDI, ethernet     * polynomial for 32 bit CRC is 0x04c11db7, as deemed kosher     * by the mighty polynomial gods of error awareness.     *     * The polynomial is expressed:     *     *   ( x^32 + x^26 + x^23 + x^22 + x^16 +     *     x^12 + x^11 + x^10 + x^8  + x^7  +     *            x^5  + x^4  + x^2  + x^1  + 1 ) = 0x04c11db7     *     * Where x = base 2 (binary) and x^32 is ignored for CRC.     *     */    /* initialize (clear) all filter bits */    for (i = 0; i < 8; ++i)	pDrvCtrl->mcastFilter[i] = 0;    /* set the proper MAR0-7 filter bit(s) for every address */    for (pCurr = END_MULTI_LST_FIRST (&pDrvCtrl->endObj);	 pCurr != NULL;	 pCurr = END_MULTI_LST_NEXT(pCurr))	{	pCp = (unsigned char *)&pCurr->addr;	crc = 0xffffffff;  /* initial CRC seed */	/* build the CRC for the 6 byte adrs */	for (eAddr = 0; eAddr < 6; eAddr++)	    {	    enetChar = *pCp++;            crc = rtl8019CrcWork (enetChar, crc);	    }	/*	 * We now have the crc for the current address and we are	 * interested in the 6 most significant bits of the crc	 * for indexing because that is whats latched by the CRC	 * hardware logic.	 *	 * Which of the eight MAR registers, 0-7, is indexed with	 * the upper three bits of the six.  Which of the eight bits	 * to set in that MAR register is indexed by the lower three	 * bits of the six.	 */	/* get six msb */	crc >>= 26;	crc &= 0x3f;	/* high 3 bit index MAR reg, low three bits index reg bit */	pDrvCtrl->mcastFilter[crc >> 3] |= (1 << (crc & 7));	}    }/******************************************************************************* rtl8019CrcWork - return CRC using a 32 bit polynomial** This is a work routine used by rtl8019AddrFilterSet** NOMANUAL**/LOCAL UINT32 rtl8019CrcWork    (    UINT8 inChar,    UINT32 inCrc    )    {    UINT8 work = 0;    UINT8 wrap;    int i;    /*     * standard CRC algorithm, 8 bit stream.     */    for (i = 0; i < 8; i++)        {        wrap = (inCrc >> 31);        inCrc <<= 1;        work  = ((work << 1) | wrap) ^ inChar;        if (work & 1)            {            inCrc ^= CRC32_POLYNOMIAL;            }         work >>= 1;         inChar >>= 1;         }     return (inCrc);     }/******************************************************************************* rtl8019MCastAdd - 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 rtl8019MCastAdd    (    void*	pCookie,	/* device ptr */    char*	pAddress    )    {    RTL8019END_DEVICE* pDrvCtrl = (RTL8019END_DEVICE *) pCookie;    DBG_PRINTF (("rtl8019MCastAdd - %02x:%02x:%02x:%02x:%02x:%02x\n",		pAddress[0]&0xff, pAddress[1]&0xff, pAddress[2]&0xff,		pAddress[3]&

⌨️ 快捷键说明

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