X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FNetwork%2FNE2000%2Fne2000.c;h=288db5f425cfe6ddf9b58be1e1b2986312e3dfd8;hb=ae3a0bf446529bfb50eb91a0fb90b72140d9f2ed;hp=387e539bd16e60076de293665181525f12b35ff9;hpb=7a6f6e32e52d0d9d9d740e66e55a3b67fb7669c7;p=tpg%2Facess2.git diff --git a/Modules/Network/NE2000/ne2000.c b/Modules/Network/NE2000/ne2000.c index 387e539b..288db5f4 100644 --- a/Modules/Network/NE2000/ne2000.c +++ b/Modules/Network/NE2000/ne2000.c @@ -3,13 +3,13 @@ * * See: ~/Sources/bochs/bochs.../iodev/ne2k.cc */ -#define DEBUG 0 +#define DEBUG 1 #define VERSION ((0<<8)|50) #include #include #include #include -#include +#include #include // === CONSTANTS === @@ -75,9 +75,7 @@ typedef struct sNe2k_Card { int NextRXPage; //!< Next expected RX page int NextMemPage; //!< Next Card Memory page to use - - //Uint8 Buffer[RX_BUF_SIZE*256]; - + char Name[2]; // "0" tVFS_Node Node; //!< VFS Node Uint8 MacAddr[6]; //!< Cached MAC address @@ -93,7 +91,7 @@ Uint64 Ne2k_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int Ne2k_int_ReadDMA(tCard *Card, int FirstPage, int NumPages, void *Buffer); Uint8 Ne2k_int_GetWritePage(tCard *Card, Uint16 Length); -void Ne2k_IRQHandler(int IntNum); +void Ne2k_IRQHandler(int IntNum, void *Ptr); // === GLOBALS === MODULE_DEFINE(0, VERSION, Ne2k, Ne2k_Install, NULL, NULL); @@ -120,14 +118,15 @@ tCard *gpNe2k_Cards = NULL; int Ne2k_Install(char **Options) { int i, j, k; - int count, id, base; + int count, base; + tPCIDev id; // --- Scan PCI Bus --- // Count Cards giNe2k_CardCount = 0; for( i = 0; i < NUM_COMPAT_DEVICES; i ++ ) { - giNe2k_CardCount += PCI_CountDevices( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device, 0 ); + giNe2k_CardCount += PCI_CountDevices( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device ); } if( giNe2k_CardCount == 0 ) { @@ -141,19 +140,19 @@ int Ne2k_Install(char **Options) for( i = 0; i < NUM_COMPAT_DEVICES; i ++ ) { - count = PCI_CountDevices( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device, 0 ); + count = PCI_CountDevices( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device ); for( j = 0; j < count; j ++,k ++ ) { - id = PCI_GetDevice( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device, 0, j ); + id = PCI_GetDevice( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device, j ); // Create Structure - base = PCI_AssignPort( id, 0, 0x20 ); + base = PCI_GetBAR( id, 0 ); gpNe2k_Cards[ k ].IOBase = base; gpNe2k_Cards[ k ].IRQ = PCI_GetIRQ( id ); gpNe2k_Cards[ k ].NextMemPage = 64; gpNe2k_Cards[ k ].NextRXPage = RX_FIRST; // Install IRQ Handler - IRQ_AddHandler(gpNe2k_Cards[ k ].IRQ, Ne2k_IRQHandler); + IRQ_AddHandler(gpNe2k_Cards[ k ].IRQ, Ne2k_IRQHandler, &gpNe2k_Cards[k]); // Reset Card outb( base + 0x1F, inb(base + 0x1F) ); @@ -169,13 +168,13 @@ int Ne2k_Install(char **Options) outb( base + ISR, 0xFF ); outb( base + RCR, 0x20 ); // Reciever to Monitor outb( base + TCR, 0x02 ); // Transmitter OFF (TCR.LB = 1, Internal Loopback) + + // Read MAC Address outb( base + RBCR0, 6*4 ); // Remote Byte Count outb( base + RBCR1, 0 ); outb( base + RSAR0, 0 ); // Clear Source Address outb( base + RSAR1, 0 ); outb( base + CMD, 0x0A ); // Remote Read, Start - - // Read MAC Address gpNe2k_Cards[ k ].MacAddr[0] = inb(base+0x10);// inb(base+0x10); gpNe2k_Cards[ k ].MacAddr[1] = inb(base+0x10);// inb(base+0x10); gpNe2k_Cards[ k ].MacAddr[2] = inb(base+0x10);// inb(base+0x10); @@ -192,15 +191,6 @@ int Ne2k_Install(char **Options) outb( base+RCR, 0x0F ); // Set WRAP and allow all packet matches outb( base+TCR, 0x00 ); // Set Normal Transmitter mode outb( base+TPSR, 0x40); // Set Transmit Start - // Set MAC Address - /* - Ne2k_WriteReg(base, MAC0, gpNe2k_Cards[ k ].MacAddr[0]); - Ne2k_WriteReg(base, MAC1, gpNe2k_Cards[ k ].MacAddr[1]); - Ne2k_WriteReg(base, MAC2, gpNe2k_Cards[ k ].MacAddr[2]); - Ne2k_WriteReg(base, MAC3, gpNe2k_Cards[ k ].MacAddr[3]); - Ne2k_WriteReg(base, MAC4, gpNe2k_Cards[ k ].MacAddr[4]); - Ne2k_WriteReg(base, MAC5, gpNe2k_Cards[ k ].MacAddr[5]); - */ Log_Log("Ne2k", "Card %i 0x%04x IRQ%i %02x:%02x:%02x:%02x:%02x:%02x", k, base, gpNe2k_Cards[ k ].IRQ, @@ -300,6 +290,8 @@ Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer); + // TODO: Lock + // Sanity Check Length if(Length > TX_BUF_SIZE*256) { Log_Warning( @@ -371,7 +363,11 @@ Uint64 Ne2k_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer); // Wait for packets - Semaphore_Wait( &Card->Semaphore, 1 ); + if( Semaphore_Wait( &Card->Semaphore, 1 ) != 1 ) + { + // Error or interrupted + LEAVE_RET('i', 0); + } outb(Card->IOBase, 0x22 | (1 << 6)); // Page 6 LOG("CURR : 0x%02x", inb(Card->IOBase + CURR)); @@ -403,10 +399,7 @@ Uint64 Ne2k_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) LOG("pktHdr->Length (%i) > 256 - 4, allocated buffer %p", pktHdr->Length, buf); - if(!buf) { - LEAVE('i', -1); - return -1; - } + if(!buf) LEAVE_RET('i', -1); // Copy the already read data memcpy(buf, data, 256); @@ -513,39 +506,35 @@ Uint8 Ne2k_int_GetWritePage(tCard *Card, Uint16 Length) /** * \fn void Ne2k_IRQHandler(int IntNum) */ -void Ne2k_IRQHandler(int IntNum) +void Ne2k_IRQHandler(int IntNum, void *Ptr) { - int i; Uint8 byte; - for( i = 0; i < giNe2k_CardCount; i++ ) - { - if(gpNe2k_Cards[i].IRQ == IntNum) - { - byte = inb( gpNe2k_Cards[i].IOBase + ISR ); - - LOG("byte = 0x%02x", byte); - + tCard *card = Ptr; + + if(card->IRQ != IntNum) return; + + byte = inb( card->IOBase + ISR ); + + LOG("byte = 0x%02x", byte); - // Reset All (save for RDMA), that's polled - outb( gpNe2k_Cards[i].IOBase + ISR, 0xFF&(~0x40) ); - // 0: Packet recieved (no error) - if( byte & 1 ) - { - //if( gpNe2k_Cards[i].NumWaitingPackets > MAX_PACKET_QUEUE ) - // gpNe2k_Cards[i].NumWaitingPackets = MAX_PACKET_QUEUE; - Semaphore_Signal( &gpNe2k_Cards[i].Semaphore, 1 ); - } - // 1: Packet sent (no error) - // 2: Recieved with error - // 3: Transmission Halted (Excessive Collisions) - // 4: Recieve Buffer Exhausted - // 5: - // 6: Remote DMA Complete - // 7: Reset + // Reset All (save for RDMA), that's polled + outb( card->IOBase + ISR, 0xFF&(~0x40) ); - return ; + // 0: Packet recieved (no error) + if( byte & 1 ) + { + //if( card->NumWaitingPackets > MAX_PACKET_QUEUE ) + // card->NumWaitingPackets = MAX_PACKET_QUEUE; + if( Semaphore_Signal( &card->Semaphore, 1 ) != 1 ) { + // Oops? } } - Log_Warning("Ne2k", "Recieved Unknown IRQ %i", IntNum); + // 1: Packet sent (no error) + // 2: Recieved with error + // 3: Transmission Halted (Excessive Collisions) + // 4: Recieve Buffer Exhausted + // 5: + // 6: Remote DMA Complete + // 7: Reset }