And the RTL8139.
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
#include <86box/86box.h>
|
#include <86box/86box.h>
|
||||||
#include <86box/timer.h>
|
#include <86box/timer.h>
|
||||||
#include <86box/pci.h>
|
#include <86box/pci.h>
|
||||||
|
#include <86box/random.h>
|
||||||
#include <86box/io.h>
|
#include <86box/io.h>
|
||||||
#include <86box/mem.h>
|
#include <86box/mem.h>
|
||||||
#include <86box/dma.h>
|
#include <86box/dma.h>
|
||||||
@@ -3300,9 +3301,11 @@ nic_init(const device_t *info)
|
|||||||
RTL8139State *s = calloc(1, sizeof(RTL8139State));
|
RTL8139State *s = calloc(1, sizeof(RTL8139State));
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
char eeprom_filename[1024] = { 0 };
|
char eeprom_filename[1024] = { 0 };
|
||||||
|
uint8_t *mac_bytes;
|
||||||
|
uint32_t mac;
|
||||||
|
|
||||||
mem_mapping_add(&s->bar_mem, 0, 0, rtl8139_io_readb, rtl8139_io_readw, rtl8139_io_readl, rtl8139_io_writeb, rtl8139_io_writew, rtl8139_io_writel, NULL, MEM_MAPPING_EXTERNAL, s);
|
mem_mapping_add(&s->bar_mem, 0, 0, rtl8139_io_readb, rtl8139_io_readw, rtl8139_io_readl, rtl8139_io_writeb, rtl8139_io_writew, rtl8139_io_writel, NULL, MEM_MAPPING_EXTERNAL, s);
|
||||||
pci_add_card(PCI_ADD_NETWORK, rtl8139_pci_read, rtl8139_pci_write, s, &s->pci_slot);
|
pci_add_card(PCI_ADD_NORMAL, rtl8139_pci_read, rtl8139_pci_write, s, &s->pci_slot);
|
||||||
s->inst = device_get_instance();
|
s->inst = device_get_instance();
|
||||||
|
|
||||||
snprintf(eeprom_filename, sizeof(eeprom_filename), "eeprom_rtl8139c_plus_%d.nvr", s->inst);
|
snprintf(eeprom_filename, sizeof(eeprom_filename), "eeprom_rtl8139c_plus_%d.nvr", s->inst);
|
||||||
@@ -3321,11 +3324,37 @@ nic_init(const device_t *info)
|
|||||||
s->eeprom.contents[2] = 0x8139;
|
s->eeprom.contents[2] = 0x8139;
|
||||||
|
|
||||||
/* XXX: Get proper MAC addresses from real EEPROM dumps. OID taken from net_ne2000.c */
|
/* XXX: Get proper MAC addresses from real EEPROM dumps. OID taken from net_ne2000.c */
|
||||||
|
#ifdef USE_REALTEK_OID
|
||||||
s->eeprom.contents[7] = 0xe000;
|
s->eeprom.contents[7] = 0xe000;
|
||||||
s->eeprom.contents[8] = 0x124c;
|
s->eeprom.contents[8] = 0x124c;
|
||||||
|
#else
|
||||||
|
s->eeprom.contents[7] = 0x1400;
|
||||||
|
s->eeprom.contents[8] = 0x122a;
|
||||||
|
#endif
|
||||||
s->eeprom.contents[9] = 0x1413;
|
s->eeprom.contents[9] = 0x1413;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mac_bytes = (uint8_t *) &(s->eeprom.contents[7]);
|
||||||
|
|
||||||
|
/* See if we have a local MAC address configured. */
|
||||||
|
mac = device_get_config_mac("mac", -1);
|
||||||
|
|
||||||
|
/* Set up our BIA. */
|
||||||
|
if (mac & 0xff000000) {
|
||||||
|
/* Generate new local MAC. */
|
||||||
|
mac_bytes[3] = random_generate();
|
||||||
|
mac_bytes[4] = random_generate();
|
||||||
|
mac_bytes[5] = random_generate();
|
||||||
|
mac = (((int) mac_bytes[3]) << 16);
|
||||||
|
mac |= (((int) mac_bytes[4]) << 8);
|
||||||
|
mac |= ((int) mac_bytes[5]);
|
||||||
|
device_set_config_mac("mac", mac);
|
||||||
|
} else {
|
||||||
|
mac_bytes[3] = (mac >> 16) & 0xff;
|
||||||
|
mac_bytes[4] = (mac >> 8) & 0xff;
|
||||||
|
mac_bytes[5] = (mac & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
s->nic = network_attach(s, (uint8_t *) &s->eeprom.contents[7], rtl8139_do_receive, rtl8139_set_link_status);
|
s->nic = network_attach(s, (uint8_t *) &s->eeprom.contents[7], rtl8139_do_receive, rtl8139_set_link_status);
|
||||||
timer_add(&s->timer, rtl8139_timer, s, 0);
|
timer_add(&s->timer, rtl8139_timer, s, 0);
|
||||||
timer_on_auto(&s->timer, 1000000.0 / cpu_pci_speed);
|
timer_on_auto(&s->timer, 1000000.0 / cpu_pci_speed);
|
||||||
@@ -3354,6 +3383,19 @@ nic_close(void *priv)
|
|||||||
free(priv);
|
free(priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
static const device_config_t rtl8139c_config[] = {
|
||||||
|
{
|
||||||
|
.name = "mac",
|
||||||
|
.description = "MAC Address",
|
||||||
|
.type = CONFIG_MAC,
|
||||||
|
.default_string = "",
|
||||||
|
.default_int = -1
|
||||||
|
},
|
||||||
|
{ .name = "", .description = "", .type = CONFIG_END }
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
const device_t rtl8139c_plus_device = {
|
const device_t rtl8139c_plus_device = {
|
||||||
.name = "Realtek RTL8139C+",
|
.name = "Realtek RTL8139C+",
|
||||||
.internal_name = "rtl8139c+",
|
.internal_name = "rtl8139c+",
|
||||||
@@ -3365,5 +3407,5 @@ const device_t rtl8139c_plus_device = {
|
|||||||
{ .available = NULL },
|
{ .available = NULL },
|
||||||
.speed_changed = NULL,
|
.speed_changed = NULL,
|
||||||
.force_redraw = NULL,
|
.force_redraw = NULL,
|
||||||
.config = NULL
|
.config = rtl8139c_config
|
||||||
};
|
};
|
||||||
|
@@ -1060,9 +1060,15 @@ static const uint8_t eeprom_default[128] = {
|
|||||||
0x08,
|
0x08,
|
||||||
0x04,
|
0x04,
|
||||||
0x01,
|
0x01,
|
||||||
|
#ifdef USE_DEC_OID
|
||||||
0x00,
|
0x00,
|
||||||
0x80,
|
0x80,
|
||||||
0x48,
|
0x48,
|
||||||
|
#else
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0xcb,
|
||||||
|
#endif
|
||||||
0xb3,
|
0xb3,
|
||||||
0x0e,
|
0x0e,
|
||||||
0xa7,
|
0xa7,
|
||||||
@@ -1192,12 +1198,12 @@ static const uint8_t eeprom_default_24110[128] = {
|
|||||||
0x08,
|
0x08,
|
||||||
0x04,
|
0x04,
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /* TODO: Change the MAC Address to the correct one. */
|
0x00, /* Obtained from a Linux dump from the real Kingston KNE110TX: 00:C0:F0:16:2A:CB */
|
||||||
0x80,
|
0xc0,
|
||||||
0x48,
|
0xf0,
|
||||||
0xc3,
|
0x16,
|
||||||
0x3e,
|
0x2a,
|
||||||
0xa7,
|
0xcb,
|
||||||
0x00,
|
0x00,
|
||||||
0x1e,
|
0x1e,
|
||||||
0x00,
|
0x00,
|
||||||
@@ -1468,7 +1474,7 @@ nic_close(void *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const device_config_t dec_tulip_pci_config[] = {
|
static const device_config_t dec_tulip_config[] = {
|
||||||
{
|
{
|
||||||
.name = "mac",
|
.name = "mac",
|
||||||
.description = "MAC Address",
|
.description = "MAC Address",
|
||||||
@@ -1491,7 +1497,7 @@ const device_t dec_tulip_device = {
|
|||||||
{ .available = NULL },
|
{ .available = NULL },
|
||||||
.speed_changed = NULL,
|
.speed_changed = NULL,
|
||||||
.force_redraw = NULL,
|
.force_redraw = NULL,
|
||||||
.config = dec_tulip_pci_config
|
.config = dec_tulip_config
|
||||||
};
|
};
|
||||||
|
|
||||||
const device_t dec_tulip_21140_device = {
|
const device_t dec_tulip_21140_device = {
|
||||||
@@ -1505,7 +1511,7 @@ const device_t dec_tulip_21140_device = {
|
|||||||
{ .available = NULL },
|
{ .available = NULL },
|
||||||
.speed_changed = NULL,
|
.speed_changed = NULL,
|
||||||
.force_redraw = NULL,
|
.force_redraw = NULL,
|
||||||
.config = dec_tulip_pci_config
|
.config = dec_tulip_config
|
||||||
};
|
};
|
||||||
|
|
||||||
const device_t dec_tulip_21140_vpc_device = {
|
const device_t dec_tulip_21140_vpc_device = {
|
||||||
@@ -1519,5 +1525,5 @@ const device_t dec_tulip_21140_vpc_device = {
|
|||||||
{ .available = NULL },
|
{ .available = NULL },
|
||||||
.speed_changed = NULL,
|
.speed_changed = NULL,
|
||||||
.force_redraw = NULL,
|
.force_redraw = NULL,
|
||||||
.config = dec_tulip_pci_config
|
.config = dec_tulip_config
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user