Skip to content

Commit 7b38758

Browse files
committed
Fix EEPROM reading in DECchip 21040
1 parent 3857fed commit 7b38758

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/network/net_eeprom_nmc93cxx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ nmc93cxx_eeprom_close(void *priv)
263263
uint16_t *
264264
nmc93cxx_eeprom_data(nmc93cxx_eeprom_t *eeprom)
265265
{
266+
if (UNLIKELY(!eeprom))
267+
return NULL;
266268
/* Get EEPROM data array. */
267269
return &eeprom->dev.data[0];
268270
}

src/network/net_tulip.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ struct TULIPState {
324324
uint32_t mii_bitcnt;
325325

326326
/* 21040 ROM read address. */
327-
uint32_t rom_read_addr;
327+
uint8_t rom_read_addr;
328328

329329
uint32_t current_rx_desc;
330330
uint32_t current_tx_desc;
@@ -670,7 +670,7 @@ static uint32_t
670670
tulip_csr9_read(TULIPState *s)
671671
{
672672
if (s->device_info->local == 3) {
673-
return ((uint8_t*)nmc93cxx_eeprom_data(s->eeprom))[s->rom_read_addr++];
673+
return s->eeprom_data[s->rom_read_addr++];
674674
}
675675
if (s->csr[9] & CSR9_SR) {
676676
if (nmc93cxx_eeprom_read(s->eeprom)) {
@@ -717,7 +717,7 @@ tulip_read(uint32_t addr, void *opaque)
717717
data = s->csr[addr >> 3];
718718
break;
719719
}
720-
//pclog("[%04X:%08X]: CSR9 read %02x, data = %08x.\n", CS, cpu_state.pc, addr, data);
720+
pclog("[%04X:%08X]: CSR9 read %02x, data = %08x.\n", CS, cpu_state.pc, addr, data);
721721
return data;
722722
}
723723

@@ -906,7 +906,7 @@ tulip_write(uint32_t addr, uint32_t data, void *opaque)
906906
TULIPState *s = opaque;
907907
addr &= 127;
908908

909-
//pclog("[%04X:%08X]: Tulip Write >> 3: %02x, val=%08x.\n", CS, cpu_state.pc, addr >> 3, data);
909+
pclog("[%04X:%08X]: Tulip Write >> 3: %02x, val=%08x.\n", CS, cpu_state.pc, addr >> 3, data);
910910
switch (addr) {
911911
case CSR(0):
912912
s->csr[0] = data;
@@ -1266,11 +1266,11 @@ tulip_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv)
12661266
{
12671267
TULIPState *s = (TULIPState *) priv;
12681268

1269-
//pclog("PCI write=%02x, ret=%02x.\n", addr, val);
1269+
pclog("PCI write=%02x, ret=%02x.\n", addr, val);
12701270
switch (addr) {
12711271
case 0x04:
12721272
s->pci_conf[0x04] = val & 0x07;
1273-
//pclog("PCI write cmd: IOBase=%04x, MMIOBase=%08x, val=%02x.\n", s->PCIBase, s->MMIOBase, s->pci_conf[0x04]);
1273+
pclog("PCI write cmd: IOBase=%04x, MMIOBase=%08x, val=%02x.\n", s->PCIBase, s->MMIOBase, s->pci_conf[0x04]);
12741274
io_removehandler(s->PCIBase, 128,
12751275
tulip_readb_io, tulip_readw_io, tulip_readl_io,
12761276
tulip_writeb_io, tulip_writew_io, tulip_writel_io,
@@ -1280,7 +1280,7 @@ tulip_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv)
12801280
tulip_readb_io, tulip_readw_io, tulip_readl_io,
12811281
tulip_writeb_io, tulip_writew_io, tulip_writel_io,
12821282
priv);
1283-
//pclog("PCI write cmd: IOBase=%04x, MMIOBase=%08x, val=%02x.\n", s->PCIBase, s->MMIOBase, s->pci_conf[0x04]);
1283+
pclog("PCI write cmd: IOBase=%04x, MMIOBase=%08x, val=%02x.\n", s->PCIBase, s->MMIOBase, s->pci_conf[0x04]);
12841284
mem_mapping_disable(&s->memory);
12851285
if ((s->MMIOBase != 0) && (val & PCI_COMMAND_MEM))
12861286
mem_mapping_set_addr(&s->memory, s->MMIOBase, 128);
@@ -1300,7 +1300,7 @@ tulip_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv)
13001300
tulip_pci_bar[0].addr &= 0xffffff80;
13011301
s->PCIBase = tulip_pci_bar[0].addr;
13021302
if (s->pci_conf[0x4] & PCI_COMMAND_IO) {
1303-
//pclog("PCI write=%02x, base=%04x, io?=%x.\n", addr, s->PCIBase, s->pci_conf[0x4] & PCI_COMMAND_IO);
1303+
pclog("PCI write=%02x, base=%04x, io?=%x.\n", addr, s->PCIBase, s->pci_conf[0x4] & PCI_COMMAND_IO);
13041304
if (s->PCIBase != 0)
13051305
io_sethandler(s->PCIBase, 128,
13061306
tulip_readb_io, tulip_readw_io, tulip_readl_io,
@@ -1317,7 +1317,7 @@ tulip_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv)
13171317
tulip_pci_bar[1].addr &= 0xffffff80;
13181318
s->MMIOBase = tulip_pci_bar[1].addr;
13191319
if (s->pci_conf[0x4] & PCI_COMMAND_MEM) {
1320-
//pclog("PCI write=%02x, mmiobase=%08x, mmio?=%x.\n", addr, s->PCIBase, s->pci_conf[0x4] & PCI_COMMAND_MEM);
1320+
pclog("PCI write=%02x, mmiobase=%08x, mmio?=%x.\n", addr, s->PCIBase, s->pci_conf[0x4] & PCI_COMMAND_MEM);
13211321
if (s->MMIOBase != 0)
13221322
mem_mapping_set_addr(&s->memory, s->MMIOBase, 128);
13231323
}
@@ -1510,6 +1510,9 @@ nic_init(const device_t *info)
15101510
} else {
15111511
/* 21040 is supposed to only have MAC address in its serial ROM if Linux is correct. */
15121512
memset(s->eeprom_data, 0, sizeof(s->eeprom_data));
1513+
/* See if we have a local MAC address configured. */
1514+
mac = device_get_config_mac("mac", -1);
1515+
/*DEC OID*/
15131516
s->eeprom_data[0] = 0x00;
15141517
s->eeprom_data[1] = 0x00;
15151518
s->eeprom_data[2] = 0xF8;
@@ -1529,14 +1532,16 @@ nic_init(const device_t *info)
15291532
}
15301533
}
15311534

1532-
params.nwords = 64;
1533-
params.default_content = (uint16_t *) s->eeprom_data;
1534-
params.filename = filename;
1535-
snprintf(filename, sizeof(filename), "nmc93cxx_eeprom_%s_%d.nvr", info->internal_name, device_get_instance());
1536-
s->eeprom = device_add_parameters(&nmc93cxx_device, &params);
1537-
if (!s->eeprom) {
1538-
free(s);
1539-
return NULL;
1535+
if (info->local != 3) {
1536+
params.nwords = 64;
1537+
params.default_content = (uint16_t *) s->eeprom_data;
1538+
params.filename = filename;
1539+
snprintf(filename, sizeof(filename), "nmc93cxx_eeprom_%s_%d.nvr", info->internal_name, device_get_instance());
1540+
s->eeprom = device_add_parameters(&nmc93cxx_device, &params);
1541+
if (!s->eeprom) {
1542+
free(s);
1543+
return NULL;
1544+
}
15401545
}
15411546

15421547
tulip_pci_bar[0].addr_regs[0] = 1;
@@ -1551,11 +1556,11 @@ nic_init(const device_t *info)
15511556
tulip_pci_bar[2].addr = 0;
15521557

15531558
mem_mapping_disable(&s->bios_rom.mapping);
1554-
eeprom_data = (uint8_t *) &nmc93cxx_eeprom_data(s->eeprom)[0];
1559+
eeprom_data = (info->local == 3) ? s->eeprom_data : (uint8_t *) &nmc93cxx_eeprom_data(s->eeprom)[0];
15551560

15561561
//pclog("EEPROM Data Format=%02x, Count=%02x, MAC=%02x:%02x:%02x:%02x:%02x:%02x.\n", eeprom_data[0x12], eeprom_data[0x13], eeprom_data[0x14], eeprom_data[0x15], eeprom_data[0x16], eeprom_data[0x17], eeprom_data[0x18], eeprom_data[0x19]);
15571562
memcpy(s->mii_regs, tulip_mdi_default, sizeof(tulip_mdi_default));
1558-
s->nic = network_attach(s, &eeprom_data[20], tulip_receive, NULL);
1563+
s->nic = network_attach(s, &eeprom_data[(info->local == 3) ? 0 : 20], tulip_receive, NULL);
15591564
pci_add_card(PCI_ADD_NORMAL, tulip_pci_read, tulip_pci_write, s, &s->pci_slot);
15601565
tulip_reset(s);
15611566
return s;

0 commit comments

Comments
 (0)