Merge pull request #3516 from Cacodemon345/tulip-24110

Add DECchip 24110 NIC emulation
This commit is contained in:
Jasmine Iwanek
2023-08-06 20:53:17 -04:00
committed by GitHub
5 changed files with 207 additions and 8 deletions

View File

@@ -1 +1,2 @@
extern const device_t dec_tulip_device; extern const device_t dec_tulip_device;
extern const device_t dec_tulip_21140_device;

View File

@@ -15,7 +15,7 @@
set(net_sources) set(net_sources)
list(APPEND net_sources network.c net_pcap.c net_slirp.c net_dp8390.c net_3c501.c list(APPEND net_sources network.c net_pcap.c net_slirp.c net_dp8390.c net_3c501.c
net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c net_null.c net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c net_null.c
net_eeprom_nmc93cxx.c net_tulip.c net_rtl8139.c) net_eeprom_nmc93cxx.c net_tulip.c net_rtl8139.c net_l80225.c)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp) pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp)

42
src/network/net_l80225.c Normal file
View File

@@ -0,0 +1,42 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <86box/86box.h>
#include <86box/timer.h>
#include <86box/pci.h>
#include <86box/io.h>
#include <86box/mem.h>
#include <86box/dma.h>
#include <86box/device.h>
#include <86box/thread.h>
#include <86box/network.h>
uint16_t
l80225_mii_readw(uint16_t* regs, uint16_t addr)
{
switch (addr)
{
case 0x1:
return 0x782D;
case 0x2:
return 0b10110;
case 0x3:
return 0xF830;
case 0x5:
return 0x41E1;
case 0x18:
return 0xC0;
default:
return regs[addr];
}
return 0;
}
void
l80225_mii_writew(uint16_t* regs, uint16_t addr, uint16_t val)
{
regs[addr] = val;
}

View File

@@ -295,6 +295,7 @@ struct tulip_descriptor {
struct TULIPState { struct TULIPState {
uint8_t dev; uint8_t dev;
const device_t* device_info;
uint16_t subsys_id, subsys_ven_id; uint16_t subsys_id, subsys_ven_id;
mem_mapping_t memory; mem_mapping_t memory;
netcard_t *nic; netcard_t *nic;
@@ -658,7 +659,7 @@ static const uint16_t tulip_mdi_default[] = {
0x0000, 0x0000,
0x0000, 0x0000,
0x0000, 0x0000,
0x0000, 0x3800,
0x0000, 0x0000,
/* MDI Registers 16 - 31 */ /* MDI Registers 16 - 31 */
0x0003, 0x0003,
@@ -681,6 +682,7 @@ static const uint16_t tulip_mdi_default[] = {
/* Readonly mask for MDI (PHY) registers */ /* Readonly mask for MDI (PHY) registers */
static const uint16_t tulip_mdi_mask[] = { static const uint16_t tulip_mdi_mask[] = {
/* MDI Registers 0 - 6, 7 */
0x0000, 0x0000,
0xffff, 0xffff,
0xffff, 0xffff,
@@ -689,6 +691,7 @@ static const uint16_t tulip_mdi_mask[] = {
0xffff, 0xffff,
0xffff, 0xffff,
0x0000, 0x0000,
/* MDI Registers 8 - 15 */
0x0000, 0x0000,
0x0000, 0x0000,
0x0000, 0x0000,
@@ -697,6 +700,7 @@ static const uint16_t tulip_mdi_mask[] = {
0x0000, 0x0000,
0x0000, 0x0000,
0x0000, 0x0000,
/* MDI Registers 16 - 31 */
0x0fff, 0x0fff,
0x0000, 0x0000,
0xffff, 0xffff,
@@ -715,12 +719,15 @@ static const uint16_t tulip_mdi_mask[] = {
0x0000, 0x0000,
}; };
extern uint16_t l80225_mii_readw(uint16_t* regs, uint16_t addr);
extern void l80225_mii_writew(uint16_t* regs, uint16_t addr, uint16_t val);
static uint16_t static uint16_t
tulip_mii_read(TULIPState *s, int phy, int reg) tulip_mii_read(TULIPState *s, int phy, int reg)
{ {
uint16_t ret = 0; uint16_t ret = 0;
if (phy == 1) { if (phy == 1) {
ret = s->mii_regs[reg]; ret = l80225_mii_readw(s->mii_regs, reg);
} }
return ret; return ret;
} }
@@ -732,8 +739,7 @@ tulip_mii_write(TULIPState *s, int phy, int reg, uint16_t data)
return; return;
} }
s->mii_regs[reg] &= ~tulip_mdi_mask[reg]; return l80225_mii_writew(s->mii_regs, reg, data);
s->mii_regs[reg] |= (data & tulip_mdi_mask[reg]);
} }
static void static void
@@ -1065,6 +1071,7 @@ tulip_write(uint32_t addr, uint32_t data, void *opaque)
tulip_xmit_list_update(s); tulip_xmit_list_update(s);
} else { } else {
tulip_update_ts(s, CSR5_TS_STOPPED); tulip_update_ts(s, CSR5_TS_STOPPED);
s->csr[5] |= CSR5_TPS;
} }
break; break;
@@ -1321,6 +1328,137 @@ static const uint8_t eeprom_default[128] = {
0x00, 0x00,
}; };
static const uint8_t eeprom_default_24110[128] = {
0x46,
0x26,
0x00,
0x01,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x56,
0x08,
0x04,
0x01,
0x00, /* TODO: Change the MAC Address to the correct one. */
0x80,
0x48,
0xc3,
0x3e,
0xa7,
0x00,
0x1e,
0x00,
0x00,
0x00,
0x08,
0xff,
0x01,
0x8d,
0x01,
0x00,
0x00,
0x00,
0x00,
0x78,
0xe0,
0x01,
0x00,
0x50,
0x00,
0x18,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0xe8,
0x6b,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x80,
0x48,
0xb3,
0x0e,
0xa7,
0x40,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
};
static void static void
tulip_fill_eeprom(TULIPState *s) tulip_fill_eeprom(TULIPState *s)
{ {
@@ -1344,7 +1482,7 @@ tulip_pci_read(int func, int addr, void *p)
case 0x01: case 0x01:
return 0x10; return 0x10;
case 0x02: case 0x02:
return 0x19; return s->device_info->local ? 0x09 : 0x19;
case 0x03: case 0x03:
return 0x00; return 0x00;
case 0x07: case 0x07:
@@ -1427,7 +1565,9 @@ nic_init(const device_t *info)
if (!s) if (!s)
return NULL; return NULL;
memcpy(eeprom_default_local, eeprom_default, sizeof(eeprom_default));
s->device_info = info;
memcpy(eeprom_default_local, s->device_info->local ? eeprom_default_24110 : eeprom_default, sizeof(eeprom_default));
tulip_idblock_crc((uint16_t *) eeprom_default_local); tulip_idblock_crc((uint16_t *) eeprom_default_local);
(((uint16_t *) eeprom_default_local))[63] = (tulip_srom_crc((uint8_t *) eeprom_default_local, 126)); (((uint16_t *) eeprom_default_local))[63] = (tulip_srom_crc((uint8_t *) eeprom_default_local, 126));
@@ -1443,6 +1583,7 @@ nic_init(const device_t *info)
memcpy(s->mii_regs, tulip_mdi_default, sizeof(tulip_mdi_default)); memcpy(s->mii_regs, tulip_mdi_default, sizeof(tulip_mdi_default));
s->nic = network_attach(s, (uint8_t *) &nmc93cxx_eeprom_data(s->eeprom)[10], tulip_receive, NULL); s->nic = network_attach(s, (uint8_t *) &nmc93cxx_eeprom_data(s->eeprom)[10], tulip_receive, NULL);
s->dev = pci_add_card(PCI_ADD_NETWORK, tulip_pci_read, tulip_pci_write, s); s->dev = pci_add_card(PCI_ADD_NETWORK, tulip_pci_read, tulip_pci_write, s);
mem_mapping_add(&s->memory, 0, 0, NULL, NULL, tulip_read, NULL, NULL, tulip_write, NULL, MEM_MAPPING_EXTERNAL, s);
tulip_reset(s); tulip_reset(s);
return s; return s;
} }
@@ -1466,3 +1607,17 @@ const device_t dec_tulip_device = {
.force_redraw = NULL, .force_redraw = NULL,
.config = NULL .config = NULL
}; };
const device_t dec_tulip_21140_device = {
.name = "Kingston KNE100TX (DECchip 21140 \"Tulip FasterNet\")",
.internal_name = "dec_21140_tulip",
.flags = DEVICE_PCI,
.local = 1,
.init = nic_init,
.close = nic_close,
.reset = tulip_reset,
{ .available = NULL },
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};

View File

@@ -120,6 +120,7 @@ static const device_t *net_cards[] = {
&pcnet_am79c960_vlb_device, &pcnet_am79c960_vlb_device,
&dec_tulip_device, &dec_tulip_device,
&rtl8139c_plus_device, &rtl8139c_plus_device,
&dec_tulip_21140_device,
NULL NULL
}; };