extending the RTL8139 driver for the new PCI interface

This commit is contained in:
Stefan Lankes 2012-07-26 09:09:58 +02:00
parent 3e01fbad68
commit ac20297df9
2 changed files with 27 additions and 23 deletions

View file

@ -51,7 +51,14 @@
// Beside Receive OK (ROK) interrupt, this mask enable all other interrupts
#define INT_MASK_NO_ROK (ISR_TOK|ISR_RXOVW|ISR_TER|ISR_RER)
board_t board_tbl[] =
typedef struct {
char *vendor_str;
char *device_str;
uint32_t vendor;
uint32_t device;
} board_t;
static board_t board_tbl[] =
{
{"RealTek", "RealTek RTL8139", 0x10ec, 0x8139},
{"RealTek", "RealTek RTL8129 Fast Ethernet", 0x10ec, 0x8129},
@ -318,10 +325,20 @@ err_t rtl8139if_init(struct netif* netif)
uint16_t tmp16, speed;
uint8_t tmp8;
static uint8_t num = 0;
//task_t* task = per_core(current_task);
pci_info_t pci_info;
LWIP_ASSERT("netif != NULL", (netif != NULL));
tmp8 = 0;
while (board_tbl[tmp8].vendor_str) {
if (pci_get_device_info(board_tbl[tmp8].vendor, board_tbl[tmp8].device, &pci_info) == 0)
break;
tmp8++;
}
if (!board_tbl[tmp8].vendor_str)
return ERR_ARG;
rtl8139if = kmalloc(sizeof(rtl1839if_t));
if (!rtl8139if) {
LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_init: out of memory\n"));
@ -329,6 +346,9 @@ err_t rtl8139if_init(struct netif* netif)
}
memset(rtl8139if, 0x00, sizeof(rtl1839if_t));
rtl8139if->iobase = pci_info.base[0];
rtl8139if->irq = pci_info.irq;
/* allocate the receive buffer */
rtl8139if->rx_buffer = mem_allocation(RX_BUF_LEN + 16 /* header size */, MAP_KERNEL_SPACE|MAP_NO_CACHE);
if (!(rtl8139if->rx_buffer)) {
@ -354,20 +374,10 @@ err_t rtl8139if_init(struct netif* netif)
netif->state = rtl8139if;
mynetif = netif;
tmp8 = 0;
while (board_tbl[tmp8].vendor_str) {
if (pci_get_device_info(board_tbl[tmp8].vendor, board_tbl[tmp8].device,
&rtl8139if->iobase, &rtl8139if->irq) == 0)
break;
tmp8++;
}
if (!board_tbl[tmp8].vendor_str)
return ERR_ARG;
tmp32 = inportl(rtl8139if->iobase + TCR);
if (tmp32 == 0xFFFFFF) {
LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_init: ERROR\n"));
kfree(rtl8139if, sizeof(rtl1839if_t));
return ERR_ARG;
}
@ -376,7 +386,7 @@ err_t rtl8139if_init(struct netif* netif)
irq_install_handler(rtl8139if->irq+32, rtl8139if_handler);
LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_init: found %s at iobase 0x%x (irq %u)\n", board_tbl[tmp8].device_str,
LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_init: Found %s at iobase 0x%x (irq %u)\n", board_tbl[tmp8].device_str,
rtl8139if->iobase, rtl8139if->irq));
// determine the mac address of this card
LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_init: MAC address "));
@ -402,6 +412,7 @@ err_t rtl8139if_init(struct netif* netif)
if (!tmp16) {
// it seems not to work
kprintf("RTL8139 reset failed\n");
kfree(rtl8139if, sizeof(rtl1839if_t));
return ERR_ARG;
}

View file

@ -206,13 +206,6 @@
#define TSD_OWN (1 << 13) // Tx DMA operation finished (driver must set to 0 when TBC is written)
#define TSD_SIZE 0x1fff // Descriptor size, the total size in bytes of data to send (max 1792)
typedef struct {
char *vendor_str;
char *device_str;
uint32_t vendor;
uint32_t device;
} board_t;
/*
* Helper struct to hold private data used to operate your ethernet interface.
*/
@ -222,11 +215,11 @@ typedef struct rtl1839if {
uint8_t* tx_buffer[4];
uint8_t* rx_buffer;
uint32_t iobase;
uint32_t irq;
uint32_t tx_queue;
uint32_t tx_complete;
uint16_t rx_pos;
uint8_t tx_inuse[4];
uint8_t irq;
volatile uint8_t polling;
} rtl1839if_t;