From: John Hodge Date: Thu, 4 Aug 2011 00:06:08 +0000 (+0800) Subject: RT8139 - Fixed to use Mutexes to control access to TXDescs X-Git-Tag: rel0.10~21 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=461ede932582098035c9b1360f9fb40524d4af34;p=tpg%2Facess2.git RT8139 - Fixed to use Mutexes to control access to TXDescs - Mutex protected current TX descriptor to stop two threads getting the same TX. - Changed in use bitfield to a mutex to stop collisions - Also fixed a spelling error --- diff --git a/Modules/Network/RTL8139/rtl8139.c b/Modules/Network/RTL8139/rtl8139.c index c479d62a..af4ace71 100644 --- a/Modules/Network/RTL8139/rtl8139.c +++ b/Modules/Network/RTL8139/rtl8139.c @@ -80,8 +80,9 @@ typedef struct sCard char *TransmitBuffers[4]; tPAddr PhysTransmitBuffers[4]; - BOOL TransmitInUse; // Flags for each transmit descriptor - int CurTXDecscriptor; + tMutex TransmitInUse[4]; + tMutex CurTXProtector; //!< Protects \a .CurTXDescriptor + int CurTXDescriptor; char Name[2]; tVFS_Node Node; @@ -313,18 +314,20 @@ Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer ENTER("pNode XLength pBuffer", Node, Length, Buffer); // TODO: Implement a semaphore for avaliable transmit buffers - - td = card->CurTXDecscriptor; - + // Find an avaliable descriptor - while( card->TransmitInUse & (1 << td) ) - Threads_Yield(); + Mutex_Acquire(&card->CurTXProtector); + td = card->CurTXDescriptor; + card->CurTXDescriptor ++; + card->CurTXDescriptor %= 4; + Mutex_Release(&card->CurTXProtector); + // - Lock it + Mutex_Acquire( &card->TransmitInUse[td] ); LOG("td = %i", td); // Transmit using descriptor `td` LOG("card->PhysTransmitBuffers[td] = %P", card->PhysTransmitBuffers[td]); - card->TransmitInUse |= (1 << td); outd(card->IOBase + TSAD0 + td*4, card->PhysTransmitBuffers[td]); LOG("card->TransmitBuffers[td] = %p", card->TransmitBuffers[td]); // Copy to buffer @@ -337,9 +340,6 @@ Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer LOG("status = 0x%08x", status); outd(card->IOBase + TSD0 + td*4, status); - card->CurTXDecscriptor ++; - card->CurTXDecscriptor %= 4; - LEAVE('i', (int)Length); return Length; @@ -388,7 +388,7 @@ void RTL8139_IRQHandler(int Num) for( j = 0; j < 4; j ++ ) { if( ind(card->IOBase + TSD0 + j*4) & 0x8000 ) { // TSD TOK - card->TransmitInUse &= ~(1 << j); + Mutex_Release( &card->TransmitInUse[j] ); // TODO: Update semaphore once implemented } }