Skip to content
Snippets Groups Projects
Commit 461ede93 authored by John Hodge's avatar John Hodge
Browse files

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
parent cd0a4d84
No related merge requests found
...@@ -80,8 +80,9 @@ typedef struct sCard ...@@ -80,8 +80,9 @@ typedef struct sCard
char *TransmitBuffers[4]; char *TransmitBuffers[4];
tPAddr PhysTransmitBuffers[4]; tPAddr PhysTransmitBuffers[4];
BOOL TransmitInUse; // Flags for each transmit descriptor tMutex TransmitInUse[4];
int CurTXDecscriptor; tMutex CurTXProtector; //!< Protects \a .CurTXDescriptor
int CurTXDescriptor;
char Name[2]; char Name[2];
tVFS_Node Node; tVFS_Node Node;
...@@ -313,18 +314,20 @@ Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer ...@@ -313,18 +314,20 @@ Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer
ENTER("pNode XLength pBuffer", Node, Length, Buffer); ENTER("pNode XLength pBuffer", Node, Length, Buffer);
// TODO: Implement a semaphore for avaliable transmit buffers // TODO: Implement a semaphore for avaliable transmit buffers
td = card->CurTXDecscriptor;
// Find an avaliable descriptor // Find an avaliable descriptor
while( card->TransmitInUse & (1 << td) ) Mutex_Acquire(&card->CurTXProtector);
Threads_Yield(); td = card->CurTXDescriptor;
card->CurTXDescriptor ++;
card->CurTXDescriptor %= 4;
Mutex_Release(&card->CurTXProtector);
// - Lock it
Mutex_Acquire( &card->TransmitInUse[td] );
LOG("td = %i", td); LOG("td = %i", td);
// Transmit using descriptor `td` // Transmit using descriptor `td`
LOG("card->PhysTransmitBuffers[td] = %P", card->PhysTransmitBuffers[td]); LOG("card->PhysTransmitBuffers[td] = %P", card->PhysTransmitBuffers[td]);
card->TransmitInUse |= (1 << td);
outd(card->IOBase + TSAD0 + td*4, card->PhysTransmitBuffers[td]); outd(card->IOBase + TSAD0 + td*4, card->PhysTransmitBuffers[td]);
LOG("card->TransmitBuffers[td] = %p", card->TransmitBuffers[td]); LOG("card->TransmitBuffers[td] = %p", card->TransmitBuffers[td]);
// Copy to buffer // Copy to buffer
...@@ -337,9 +340,6 @@ Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer ...@@ -337,9 +340,6 @@ Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer
LOG("status = 0x%08x", status); LOG("status = 0x%08x", status);
outd(card->IOBase + TSD0 + td*4, status); outd(card->IOBase + TSD0 + td*4, status);
card->CurTXDecscriptor ++;
card->CurTXDecscriptor %= 4;
LEAVE('i', (int)Length); LEAVE('i', (int)Length);
return Length; return Length;
...@@ -388,7 +388,7 @@ void RTL8139_IRQHandler(int Num) ...@@ -388,7 +388,7 @@ void RTL8139_IRQHandler(int Num)
for( j = 0; j < 4; j ++ ) for( j = 0; j < 4; j ++ )
{ {
if( ind(card->IOBase + TSD0 + j*4) & 0x8000 ) { // TSD TOK if( ind(card->IOBase + TSD0 + j*4) & 0x8000 ) { // TSD TOK
card->TransmitInUse &= ~(1 << j); Mutex_Release( &card->TransmitInUse[j] );
// TODO: Update semaphore once implemented // TODO: Update semaphore once implemented
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment