summaryrefslogtreecommitdiff
path: root/src/drivers/net/rtl8139.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/net/rtl8139.c')
-rw-r--r--src/drivers/net/rtl8139.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/drivers/net/rtl8139.c b/src/drivers/net/rtl8139.c
index a24afbe..78a552a 100644
--- a/src/drivers/net/rtl8139.c
+++ b/src/drivers/net/rtl8139.c
@@ -2,18 +2,10 @@
#include "string.h"
#include "stdio.h"
+#include "stdlib.h"
#define DEBUG
-/*
-Offset (from IO base) Size Name
-0x08 8 MAR0-7
-0x30 4 RBSTART
-0x37 1 CMD
-0x3C 2 IMR
-0x3E 2 ISR
-*/
-
static rtl8139_vtable_t const rtl8139_vtable = {
{
rtl8139_activate,
@@ -26,6 +18,7 @@ static rtl8139_vtable_t const rtl8139_vtable = {
// registers
#define REG_MAC0 0x00
+#define REG_RBSTART 0x30
#define REG_CMD 0x37
#define REG_IMR 0x3C
#define REG_ISR 0x3E
@@ -80,6 +73,9 @@ static rtl8139_vtable_t const rtl8139_vtable = {
ISR_RECEIVE_BUFFER_OVERFLOW | ISR_TRANSMIT_ERROR | ISR_TRANSMIT_OK | \
ISR_RECEIVE_ERROR | ISR_RECEIVE_OK
+// for now we follow the guide line on OSDEV on the size of the receive buffer
+#define RECEIVE_BUFFER_SIZE 8192 + 16
+
void rtl8139_init( rtl8139_t *rtl8139, pci_device_descriptor_t *descriptor, interrupt_t *interrupt, void *context )
{
memset( rtl8139, 0, sizeof( rtl8139_t ) );
@@ -94,6 +90,7 @@ void rtl8139_init( rtl8139_t *rtl8139, pci_device_descriptor_t *descriptor, inte
port8_init( &rtl8139->MAC_port[i], descriptor->port_base + REG_MAC0 + i );
}
port8_init( &rtl8139->CMD_port, descriptor->port_base + REG_CMD );
+ port32_init( &rtl8139->RBSTART_port, descriptor->port_base + REG_RBSTART );
port16_init( &rtl8139->IMR_port, descriptor->port_base + REG_IMR );
port16_init( &rtl8139->ISR_port, descriptor->port_base + REG_ISR );
port32_init( &rtl8139->TCR_port, descriptor->port_base + REG_TCR );
@@ -159,6 +156,10 @@ void rtl8139_init( rtl8139_t *rtl8139, pci_device_descriptor_t *descriptor, inte
port32_write( &rtl8139->TCR_port, TCR_IFG_STANDARD | TCR_MXDMA_2048 );
port32_write( &rtl8139->RCR_port, RCR_MXDMA_UNLIMITED | RCR_ACCEPT_BROADCAST | RCR_ACCEPT_PHYS_MATCH );
+ // allocate receive buffer and register it
+ rtl8139->receive_buffer = (uint8_t *)malloc( RECEIVE_BUFFER_SIZE );
+ port32_write( &rtl8139->RBSTART_port, (uint32_t)rtl8139->receive_buffer );
+
// register interrupts we are interested in (we want all and
// filter them in the interrupt handler), read ISR to clear
// the current values (if there are bits set)
@@ -189,7 +190,9 @@ void rtl8139_deactivate( void *obj )
void rtl8139_deinit( void *obj )
{
- // nothing to do
+ rtl8139_t *rtl8139 = (rtl8139_t *)obj;
+
+ free( rtl8139->receive_buffer );
}
uint32_t rtl8139_handle_interrupt( interrupt_handler_t *handler, uint32_t esp )