#include "3C90x.h"
void
Apple3Com3C90x::receivePacket( void * pkt, UInt32 * pkt_len, UInt32 timeout )
{
UInt32 status;
UInt32 pktLength;
SInt32 us_timeout = timeout * 1000;
*pkt_len = 0;
if ( !_linkTest && ( _driverEnableCount == 0 ) ) return;
do {
for ( status = _rxRingTail->status;
status & kRxDescStatusUpCompleteMask;
status = _rxRingTail->status )
{
pktLength = GetBitField( RxDescStatus, Length, status );
if ( ( status & kRxDescStatusUpErrorMask ) ||
( pktLength < ( kIOEthernetMinPacketSize - kIOEthernetCRCSize ) ) )
{
LOG_DEBUG("receivePacket: bad packet\n");
_rxRingTail->status = 0;
_rxRingTail = _rxRingTail->drvNext;
sendCommand( UpUnStall );
}
else
{
*pkt_len = pktLength;
if ( pkt )
bcopy( _rxRingTail->drvMbuf->m_data, pkt, *pkt_len );
_rxRingTail->status = 0;
_rxRingTail = _rxRingTail->drvNext;
sendCommand( UpUnStall );
return;
}
}
if ( _linkTest )
{
if ( timeout ) IOSleep( 10 );
us_timeout -= 10 * 1000;
}
else
{
IODelay( 50 );
us_timeout -= 50;
}
}
while ( us_timeout > 0 );
}
void Apple3Com3C90x::sendPacket( void * pkt, UInt32 pkt_len )
{
#define kSendPacketDelayLoops 100000
#define kSendPacketSleepLoops 100
int i;
const int maxLoops = (_linkTest) ? kSendPacketSleepLoops :
kSendPacketDelayLoops;
if ( ( _txRingFree == 0 ) || ( pkt_len > MCLBYTES ) )
return;
if ( !_linkTest && ( _driverEnableCount == 0 ) )
return;
for ( i = 0; (i < maxLoops) && getDnListPtr(); i++ )
{
if (_linkTest) IOSleep( 10 );
else IODelay( 10 );
}
if ( i >= maxLoops )
{
IOLog("sendPacket: idle poll timed out\n");
return;
}
_newWDCounters[ kWDInterruptsRetired ] += 1;
if ( _txRingHead->drvMbuf != NULL )
{
LOG_DEBUG("sendPacket: mbuf not NULL\n");
}
_kdpMbuf->m_next = 0;
bcopy( pkt, mtod(_kdpMbuf, void *), pkt_len );
_kdpMbuf->m_pkthdr.len = _kdpMbuf->m_len = pkt_len;
if ( updateTxDescriptor( _txRingHead, _kdpMbuf ) == false )
{
LOG_DEBUG("sendPacket: updateTxDescriptor error\n");
return;
}
_txRingHead->nextPtr = 0;
sendCommandWait( DnStall );
_txRingHead->drvPrevious->nextPtr = _txRingHead->drvPhysAddr;
setDnListPtr( _txRingHead->drvPhysAddr );
sendCommand( DnUnStall );
for ( i = 0; (i < maxLoops) && getDnListPtr(); i++ )
{
if (_linkTest) IOSleep( 10 );
else IODelay( 10 );
}
if ( i >= maxLoops )
{
IOLog("sendPacket: idle poll timed out\n");
}
}