?? ne2000end.c
字號(hào):
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 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 */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -