1 /* Acess2 RTL8139 Driver
2 * - By John Hodge (thePowersGang)
7 #define VERSION ((0<<8)|50)
12 #include <tpl_drv_network.h>
21 MAR4, MAR5, MAR6, MAR7,
23 RBSTART = 0x30, //!< Recieve Buffer Start
24 // ??, ??, ??, RST, RE, TE, ??, ??
40 int NumWaitingPackets;
43 tPAddr PhysReceiveBuffer;
53 MODULE_DEFINE(0, VERSION, RTL8139, RTL8139_Install, NULL, NULL);
54 int giRTL8139_CardCount;
55 tCard gpRTL8139_Cards;
59 * \brief Installs the RTL8139 Driver
61 int RTL8139_Install(char **Options)
67 giRTL8139_CardCount = PCI_CountDevices( 0x10EC, 0x8139, 0 );
69 gpRTL8139_Cards = calloc( giRTL8139_CardCount, sizeof(tCard) );
72 while( (id = PCI_GetDevice(0x10EC, 0x8139, 0, id)) != -1 )
74 base = PCI_AssignPort( id, 0, 0x100 );
75 gpRTL8139_Cards[i].IOBase = base;
76 gpRTL8139_Cards[i].IRQ = PCI_GetIRQ( id );
78 // Install IRQ Handler
79 IRQ_AddHandler(gpRTL8139_Cards[ k ].IRQ, RTL8136_IRQHandler);
82 outb( base + CONFIG1, 0x00 );
83 // Reset (0x10 to CMD)
84 outb( base + CMD, 0x10 );
86 gpRTL8139_Cards[i].ReceiveBuffer = MM_AllocDMA( 2, 32, &gpRTL8139_Cards[i].PhysReceiveBuffer );
87 // Set up recieve buffer
88 outl(base + RBSTART, (Uint32)gpRTL8139_Cards[i].PhysReceiveBuffer);
89 // Set IMR to Transmit OK and Receive OK
90 outw(base + IMR, 0x5);
92 // Set recieve buffer size, buffer wrap and recieve mask
93 outl(base + RCR, 0x8F);
95 outb(base + CMD, 0x0C); // Recive Enable and Transmit Enable
97 gpRTL8139_Cards[ i ].MacAddr[0] = inb(base+MAC0);
98 gpRTL8139_Cards[ i ].MacAddr[1] = inb(base+MAC1);
99 gpRTL8139_Cards[ i ].MacAddr[2] = inb(base+MAC2);
100 gpRTL8139_Cards[ i ].MacAddr[3] = inb(base+MAC3);
101 gpRTL8139_Cards[ i ].MacAddr[4] = inb(base+MAC4);
102 gpRTL8139_Cards[ i ].MacAddr[5] = inb(base+MAC5);
105 gpRTL8139_Cards[ i ].Name[0] = '0'+i;
106 gpRTL8139_Cards[ i ].Name[1] = '\0';
107 gpRTL8139_Cards[ i ].Node.ImplPtr = &gpRTL8139_Cards[ i ];
108 gpRTL8139_Cards[ i ].Node.NumACLs = 0;
109 gpRTL8139_Cards[ i ].Node.CTime = now();
110 gpRTL8139_Cards[ i ].Node.Write = RTL8139_Write;
111 gpRTL8139_Cards[ i ].Node.Read = RTL8139_Read;
112 gpRTL8139_Cards[ i ].Node.IOCtl = RTL8139_IOCtl;
114 Log_Log("RTL8139", "Card %i 0x%04x %02x:%02x:%02x:%02x:%02x:%02x",
116 gpRTL8139_Cards[ i ].MacAddr[0], gpRTL8139_Cards[ i ].MacAddr[1],
117 gpRTL8139_Cards[ i ].MacAddr[2], gpRTL8139_Cards[ i ].MacAddr[3],
118 gpRTL8139_Cards[ i ].MacAddr[4], gpRTL8139_Cards[ i ].MacAddr[5]
123 return MODULE_ERR_OK;