VFS - Rework to remove function pointers from tVFS_Node
[tpg/acess2.git] / Modules / Network / NE2000 / ne2000.c
index eb3673f..d05b2a3 100644 (file)
@@ -86,24 +86,32 @@ typedef struct sNe2k_Card {
 char   *Ne2k_ReadDir(tVFS_Node *Node, int Pos);
 tVFS_Node      *Ne2k_FindDir(tVFS_Node *Node, const char *Name);
  int   Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data);
-Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
+Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer);
 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);
+tVFS_NodeType  gNe2K_RootNodeType = {
+       .ReadDir = Ne2k_ReadDir,
+       .FindDir = Ne2k_FindDir,
+       .IOCtl = Ne2k_IOCtl
+       };
+tVFS_NodeType  gNe2K_DevNodeType = {
+       .Write = Ne2k_Write,
+       .Read = Ne2k_Read,
+       .IOCtl = Ne2k_IOCtl     
+       };
 tDevFS_Driver  gNe2k_DriverInfo = {
        NULL, "ne2k",
        {
        .NumACLs = 1,
        .ACLs = &gVFS_ACL_EveryoneRX,
        .Flags = VFS_FFLAG_DIRECTORY,
-       .ReadDir = Ne2k_ReadDir,
-       .FindDir = Ne2k_FindDir,
-       .IOCtl = Ne2k_IOCtl
+       .Type = &gNe2K_RootNodeType
        }
 };
 Uint16 gNe2k_BaseAddress;
@@ -129,10 +137,7 @@ int Ne2k_Install(char **Options)
                giNe2k_CardCount += PCI_CountDevices( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device );
        }
        
-       if( giNe2k_CardCount == 0 ) {
-               Log_Warning("Ne2k", "No cards detected");
-               return MODULE_ERR_NOTNEEDED;
-       }
+       if( giNe2k_CardCount == 0 )     return MODULE_ERR_NOTNEEDED;
        
        // Enumerate Cards
        k = 0;
@@ -152,7 +157,7 @@ int Ne2k_Install(char **Options)
                        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) );
@@ -205,9 +210,7 @@ int Ne2k_Install(char **Options)
                        gpNe2k_Cards[ k ].Node.ImplPtr = &gpNe2k_Cards[ k ];
                        gpNe2k_Cards[ k ].Node.NumACLs = 0;     // Root Only
                        gpNe2k_Cards[ k ].Node.CTime = now();
-                       gpNe2k_Cards[ k ].Node.Write = Ne2k_Write;
-                       gpNe2k_Cards[ k ].Node.Read = Ne2k_Read;
-                       gpNe2k_Cards[ k ].Node.IOCtl = Ne2k_IOCtl;
+                       gpNe2k_Cards[ k ].Node.Type = &gNe2K_DevNodeType;
                        
                        // Initialise packet semaphore
                        // - Start at zero, no max
@@ -278,13 +281,13 @@ int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data)
 }
 
 /**
- * \fn Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+ * \fn Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer)
  * \brief Send a packet from the network card
  */
-Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer)
 {
        tCard   *Card = (tCard*)Node->ImplPtr;
-       Uint16  *buf = Buffer;
+       const Uint16    *buf = Buffer;
         int    rem = Length;
         int    page;
        
@@ -506,41 +509,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;
-                               if( Semaphore_Signal( &gpNe2k_Cards[i].Semaphore, 1 ) != 1 ) {
-                                       // Oops?
-                               }
-                       }
-                       // 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
 }

UCC git Repository :: git.ucc.asn.au