+
+void RTL8139_IRQHandler(int Num)
+{
+ int i, j;
+ tCard *card;
+ Uint8 status;
+ for( i = 0; i < giRTL8139_CardCount; i ++ )
+ {
+ card = &gaRTL8139_Cards[i];
+ if( Num != card->IRQ ) break;
+
+ status = inb(card->IOBase + ISR);
+
+ // Transmit OK, a transmit descriptor is now free
+ if( status & FLAG_ISR_TOK )
+ {
+ outb(card->IOBase + ISR, FLAG_ISR_TOK);
+ for( j = 0; j < 4; j ++ )
+ {
+ if( ind(card->IOBase + TSD0 + j) & 0x8000 ) { // TSD TOK
+ card->TransmitInUse &= ~(1 << j);
+ // TODO: Update semaphore once implemented
+ }
+ }
+ }
+
+ // Recieve OK, inform read
+ if( status & FLAG_ISR_ROK )
+ {
+ int read_ofs, end_ofs;
+ int packet_count = 0;
+
+ // Scan recieve buffer for packets
+ end_ofs = ind(card->IOBase + CBA) - card->PhysReceiveBuffer;
+ read_ofs = card->SeenOfs;
+ if( read_ofs > end_ofs )
+ {
+ while( read_ofs < card->ReceiveBufferLength )
+ {
+ packet_count ++;
+ read_ofs += *(Uint16*)&card->ReceiveBuffer[read_ofs+1] + 2;
+ }
+ read_ofs = 0;
+ }
+ while( read_ofs < end_ofs )
+ {
+ packet_count ++;
+ read_ofs += *(Uint16*)&card->ReceiveBuffer[read_ofs+1] + 2;
+ }
+ card->SeenOfs = read_ofs;
+
+ Semaphore_Signal( &card->ReadSemaphore, packet_count );
+ if( packet_count )
+ VFS_MarkAvaliable( &card->Node, 1 );
+
+ outb(card->IOBase + ISR, FLAG_ISR_ROK);
+ }
+ }
+}