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

📄 ne2000end.c

📁 是vxworks下的网卡芯片RTL8019驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
** 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 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 ne2000AddrFilterSet    (    NE2000END_DEVICE *pDrvCtrl    )    {    int i;    int eAddr;    u_char enetChar;    u_char *pCp;    u_long crc;    ETHER_MULTI* pCurr;    ENDLOGMSG (("ne2000AddrFilterSet\n", 0, 0, 0, 0, 0, 0));    /*     * 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 = ne2000CrcWork (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));	}    }/******************************************************************************* ne2000CrcWork - return CRC using a 32 bit polynomial** This is a work routine used by ne2000AddrFilterSet** NOMANUAL**/LOCAL UINT32 ne2000CrcWork    (    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);     }/******************************************************************************* 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;    pDrvCtrl = (NE2000END_DEVICE *) pCookie;    /* mark the interface -- down */    END_FLAGS_CLR (&pDrvCtrl->endObj, IFF_UP | IFF_RUNNING);    /* Disable device interrupts */    pDrvCtrl->imask = 0;    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);    /* stop device */    SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_NODMA | CMD_PAGE0 | CMD_STOP);    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]

⌨️ 快捷键说明

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