From 3522b3ba5dcc7cf1d73f9128f03201f999ed9dc4 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 3 Aug 2023 00:26:15 +0600 Subject: [PATCH 1/4] Add DECchip 24110 NIC emulation --- src/include/86box/net_tulip.h | 3 +- src/network/net_tulip.c | 152 +++++++++++++++++++++++++++++++++- src/network/network.c | 1 + 3 files changed, 153 insertions(+), 3 deletions(-) diff --git a/src/include/86box/net_tulip.h b/src/include/86box/net_tulip.h index 492d5a40f..681b89c97 100644 --- a/src/include/86box/net_tulip.h +++ b/src/include/86box/net_tulip.h @@ -1 +1,2 @@ -extern const device_t dec_tulip_device; \ No newline at end of file +extern const device_t dec_tulip_device; +extern const device_t dec_tulip_21140_device; \ No newline at end of file diff --git a/src/network/net_tulip.c b/src/network/net_tulip.c index c599a69db..f9aa662d1 100644 --- a/src/network/net_tulip.c +++ b/src/network/net_tulip.c @@ -296,6 +296,7 @@ struct tulip_descriptor { struct TULIPState { uint8_t dev; + const device_t* device_info; uint16_t subsys_id, subsys_ven_id; mem_mapping_t memory; netcard_t *nic; @@ -1322,6 +1323,137 @@ static const uint8_t eeprom_default[128] = { 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 tulip_fill_eeprom(TULIPState *s) { @@ -1345,7 +1477,7 @@ tulip_pci_read(int func, int addr, void *p) case 0x01: return 0x10; case 0x02: - return 0x19; + return s->device_info->local ? 0x09 : 0x19; case 0x03: return 0x00; case 0x07: @@ -1428,7 +1560,9 @@ nic_init(const device_t *info) if (!s) 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); (((uint16_t *) eeprom_default_local))[63] = (tulip_srom_crc((uint8_t *) eeprom_default_local, 126)); @@ -1467,3 +1601,17 @@ const device_t dec_tulip_device = { .force_redraw = 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 +}; diff --git a/src/network/network.c b/src/network/network.c index 71cffe176..7778e5ed3 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -120,6 +120,7 @@ static const device_t *net_cards[] = { &pcnet_am79c960_vlb_device, &dec_tulip_device, &rtl8139c_plus_device, + &dec_tulip_21140_device, NULL }; From f1548b3fe6d13eece1272e08b998fffc4c8752cd Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 4 Aug 2023 00:03:04 +0600 Subject: [PATCH 2/4] net_tulip: Return TX suspended status --- src/network/net_tulip.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/network/net_tulip.c b/src/network/net_tulip.c index f9aa662d1..cddcb59d1 100644 --- a/src/network/net_tulip.c +++ b/src/network/net_tulip.c @@ -1067,6 +1067,7 @@ tulip_write(uint32_t addr, uint32_t data, void *opaque) tulip_xmit_list_update(s); } else { tulip_update_ts(s, CSR5_TS_STOPPED); + s->csr[5] |= CSR5_TPS; } break; From 76faa5ef758ddef9e35397964e629d67cb477733 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 4 Aug 2023 00:03:22 +0600 Subject: [PATCH 3/4] net_tulip.c: Add memory mapping --- src/network/net_tulip.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/network/net_tulip.c b/src/network/net_tulip.c index cddcb59d1..e1f04aaa2 100644 --- a/src/network/net_tulip.c +++ b/src/network/net_tulip.c @@ -1579,6 +1579,7 @@ nic_init(const device_t *info) 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->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); return s; } From 57decf2e72810fafb514c2f1793868874b5c69b0 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 4 Aug 2023 15:04:58 +0600 Subject: [PATCH 4/4] net_tulip: L80225 transceiver emulation --- src/network/CMakeLists.txt | 2 +- src/network/net_l80225.c | 42 ++++++++++++++++++++++++++++++++++++++ src/network/net_tulip.c | 13 ++++++++---- 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/network/net_l80225.c diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 0920fcf26..b0ba913d5 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -15,7 +15,7 @@ set(net_sources) 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_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) pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp) diff --git a/src/network/net_l80225.c b/src/network/net_l80225.c new file mode 100644 index 000000000..40764aa67 --- /dev/null +++ b/src/network/net_l80225.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include + +#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; +} \ No newline at end of file diff --git a/src/network/net_tulip.c b/src/network/net_tulip.c index e1f04aaa2..421b05d3d 100644 --- a/src/network/net_tulip.c +++ b/src/network/net_tulip.c @@ -660,7 +660,7 @@ static const uint16_t tulip_mdi_default[] = { 0x0000, 0x0000, 0x0000, - 0x0000, + 0x3800, 0x0000, /* MDI Registers 16 - 31 */ 0x0003, @@ -683,6 +683,7 @@ static const uint16_t tulip_mdi_default[] = { /* Readonly mask for MDI (PHY) registers */ static const uint16_t tulip_mdi_mask[] = { + /* MDI Registers 0 - 6, 7 */ 0x0000, 0xffff, 0xffff, @@ -691,6 +692,7 @@ static const uint16_t tulip_mdi_mask[] = { 0xffff, 0xffff, 0x0000, + /* MDI Registers 8 - 15 */ 0x0000, 0x0000, 0x0000, @@ -699,6 +701,7 @@ static const uint16_t tulip_mdi_mask[] = { 0x0000, 0x0000, 0x0000, + /* MDI Registers 16 - 31 */ 0x0fff, 0x0000, 0xffff, @@ -717,12 +720,15 @@ static const uint16_t tulip_mdi_mask[] = { 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 tulip_mii_read(TULIPState *s, int phy, int reg) { uint16_t ret = 0; if (phy == 1) { - ret = s->mii_regs[reg]; + ret = l80225_mii_readw(s->mii_regs, reg); } return ret; } @@ -734,8 +740,7 @@ tulip_mii_write(TULIPState *s, int phy, int reg, uint16_t data) return; } - s->mii_regs[reg] &= ~tulip_mdi_mask[reg]; - s->mii_regs[reg] |= (data & tulip_mdi_mask[reg]); + return l80225_mii_writew(s->mii_regs, reg, data); } static void