Skip to contentSkip to conversation

eepro100: New patch series adds full GPXE support

Qemu-devel Superseded Stefan Weil 5 participants 62 messages Feb 14, 2010 – Mar 4, 2010

lore
Share & tools
lore
#0 lore raw

These patches contain fixes, enhancements and improvements for eepro100.

Even if some of these patches contain trivial changes which seem to be optional, they help to synchronize my maintainer version with the official QEMU version, so please apply them.

0001-eepro100-Fix-compiler-errors-from-debug-messages.patch 0002-eepro100-Add-missing-SCB-register-names.patch 0003-eepro100-Fix-PXE-boot.patch 0004-eepro100-Support-gpxe-boot-for-all-eepro100-devices.patch 0005-eepro100-Add-all-supported-devices-to-pci.c.patch (optional) 0006-eepro100-Add-TODO-list.patch 0007-eepro100-Update-copyright-notice.patch 0008-eepro100-Add-device-descriptions.patch 0009-eepro100-Use-symbolic-names-and-BIT-macros-in-binary.patch 0010-eepro100-Remove-old-unused-code.patch 0011-eepro100-Use-symbolic-names-for-bits-in-EEPROM-id.patch 0012-eepro100-Replace-variable-name-to-fix-a-compiler-war.patch 0013-eepro100-Support-RNR-interrupt.patch 0014-eepro100-Fix-CU-Start-command.patch 0015-eepro100-Prettify-code-no-functional-changes.patch 0016-eepro100-Use-tx.status.patch 0017-eepro100-New-function-for-reading-command-block.patch 0018-eepro100-Add-diagnose-command.patch 0019-eepro100-Remove-C-comments.patch 0020-eepro100-Keep-includes-sorted.patch

There still remain issues (incomplete endianess handling, buggy transmit command) which will be addressed later.

Regards,
Stefan Weil

#1 lore raw

PATCH 1/20 eepro100: Fix compiler errors from debug messages

When debug output was enabled (by defining DEBUG_EEPRO100), some debug messages resulted in a compiler error.

This is fixed here.

---
 hw/eepro100.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
hw/eepro100.c +7 -6
index b33dbb8..6580ca8 100644
@@ -56,7 +56,9 @@
 #define KiB 1024
 
 /* Debug EEPRO100 card. */
-//~ #define DEBUG_EEPRO100
+#if 0
+# define DEBUG_EEPRO100
+#endif
 
 #ifdef DEBUG_EEPRO100
 #define logout(fmt, ...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ## __VA_ARGS__)
@@ -874,9 +876,8 @@ static void action_command(EEPRO100State *s)
         cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
         uint16_t status = le16_to_cpu(s->tx.status);
         uint16_t command = le16_to_cpu(s->tx.command);
-        logout
-            ("val=0x%02x (cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-             val, status, command, s->tx.link);
+        logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
+               status, command, s->tx.link);
         bool bit_el = ((command & 0x8000) != 0);
         bool bit_s = ((command & 0x4000) != 0);
         bool bit_i = ((command & 0x2000) != 0);
@@ -891,7 +892,7 @@ static void action_command(EEPRO100State *s)
             break;
         case CmdIASetup:
             cpu_physical_memory_read(s->cb_address + 8, &s->conf.macaddr.a[0], 6);
-            TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6)));
+            TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6)));
             break;
         case CmdConfigure:
             cpu_physical_memory_read(s->cb_address + 8, &s->configuration[0],
@@ -1875,7 +1876,7 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
                            pci_mmio_map);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
+    logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6));
     assert(s->region[1] == 0);
 
     nic_reset(s);
Signature · 1 line
1.6.6.1
#2 lore raw

PATCH 2/20 eepro100: Add missing SCB register names

Some system control block registers were addressed using their offset value. Use symbolic names now and clean the documentation.

---
 hw/eepro100.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
hw/eepro100.c +10 -6
index 6580ca8..124bc49 100644
@@ -125,16 +125,20 @@
 /* Offsets to the various registers.
    All accesses need not be longword aligned. */
 enum speedo_offsets {
-    SCBStatus = 0,
+    SCBStatus = 0,              /* Status Word. */
     SCBAck = 1,
     SCBCmd = 2,                 /* Rx/Command Unit command and status. */
     SCBIntmask = 3,
     SCBPointer = 4,             /* General purpose pointer. */
     SCBPort = 8,                /* Misc. commands and operands.  */
-    SCBflash = 12, SCBeeprom = 14,      /* EEPROM and flash memory control. */
+    SCBflash = 12,              /* Flash memory control. */
+    SCBeeprom = 14,             /* EEPROM control. */
     SCBCtrlMDI = 16,            /* MDI interface control. */
     SCBEarlyRx = 20,            /* Early receive byte count. */
-    SCBFlow = 24,
+    SCBFlow = 24,               /* Flow Control. */
+    SCBpmdr = 27,               /* Power Management Driver. */
+    SCBgctrl = 28,              /* General Control. */
+    SCBgstat = 29,              /* General Status. */
 };
 
 /* A speedo3 transmit buffer descriptor with two buffers... */
@@ -1333,11 +1337,11 @@ static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr)
     case SCBeeprom:
         val = eepro100_read_eeprom(s);
         break;
-    case 0x1b:                 /* PMDR (power management driver register) */
+    case SCBpmdr:       /* Power Management Driver Register */
         val = 0;
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
-    case 0x1d:                 /* general status register */
+    case SCBgstat:      /* General Status Register */
         /* 100 Mbps full duplex, valid link */
         val = 0x07;
         TRACE(OTHER, logout("addr=General Status val=%02x\n", val));
@@ -1431,7 +1435,7 @@ static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val)
     case SCBFlow:       /* does not exist on 82557 */
     case SCBFlow + 1:
     case SCBFlow + 2:
-    case SCBFlow + 3:
+    case SCBpmdr:       /* does not exist on 82557 */
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBeeprom:
Signature · 1 line
1.6.6.1
#3 lore raw

PATCH 3/20 eepro100: Fix PXE boot

The phy handling was wrong for PXE, GPXE boot:
GPXE's eepro100 driver did not detect a valid link.

This is fixed here.

---
 hw/eepro100.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
hw/eepro100.c +14 -6
index 124bc49..994722d 100644
@@ -20,7 +20,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  *
  * Tested features (i82559):
- *      PXE boot (i386) no valid link
+ *      PXE boot (i386) ok
  *      Linux networking (i386) ok
  *
  * Untested:
@@ -33,10 +33,6 @@
  * Open Source Software Developer Manual
  */
 
-#if defined(TARGET_I386)
-# warning "PXE boot still not working!"
-#endif
-
 #include <stddef.h>             /* offsetof */
 #include <stdbool.h>
 #include "hw.h"
@@ -243,6 +239,17 @@ typedef struct {
     bool has_extended_tcb_support;
 } EEPRO100State;
 
+/* Word indices in EEPROM. */
+typedef enum {
+    eeprom_cnfg_mdix  = 0x03,
+    eeprom_id         = 0x05,
+    eeprom_phy_id     = 0x06,
+    eeprom_vendor_id  = 0x0c,
+    eeprom_config_asf = 0x0d,
+    eeprom_device_id  = 0x23,
+    eeprom_smbus_addr = 0x90,
+} EEPROMOffset;
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
     /* MDI Registers 0 - 6, 7 */
@@ -632,9 +639,10 @@ static void nic_selective_reset(EEPRO100State * s)
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
-    eeprom_contents[0xa] = 0x4000;
+    eeprom_contents[eeprom_id] = 0x4000;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
+    eeprom_contents[eeprom_phy_id] = 1;
     uint16_t sum = 0;
     for (i = 0; i < EEPROM_SIZE - 1; i++) {
         sum += eeprom_contents[i];
Signature · 1 line
1.6.6.1
#4 lore raw

PATCH 3/20 eepro100: Fix PXE boot

The phy handling was wrong for PXE, GPXE boot:
GPXE's eepro100 driver did not detect a valid link.

This is fixed here.

V2 - Use UPPER_CASE for enum values

---
 hw/eepro100.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
hw/eepro100.c +14 -6
index 124bc49..f6764cc 100644
@@ -20,7 +20,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  *
  * Tested features (i82559):
- *      PXE boot (i386) no valid link
+ *      PXE boot (i386) ok
  *      Linux networking (i386) ok
  *
  * Untested:
@@ -33,10 +33,6 @@
  * Open Source Software Developer Manual
  */
 
-#if defined(TARGET_I386)
-# warning "PXE boot still not working!"
-#endif
-
 #include <stddef.h>             /* offsetof */
 #include <stdbool.h>
 #include "hw.h"
@@ -243,6 +239,17 @@ typedef struct {
     bool has_extended_tcb_support;
 } EEPRO100State;
 
+/* Word indices in EEPROM. */
+typedef enum {
+    EEPROM_CNFG_MDIX  = 0x03,
+    EEPROM_ID         = 0x05,
+    EEPROM_PHY_ID     = 0x06,
+    EEPROM_VENDOR_ID  = 0x0c,
+    EEPROM_CONFIG_ASF = 0x0d,
+    EEPROM_DEVICE_ID  = 0x23,
+    EEPROM_SMBUS_ADDR = 0x90,
+} EEPROMOffset;
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
     /* MDI Registers 0 - 6, 7 */
@@ -632,9 +639,10 @@ static void nic_selective_reset(EEPRO100State * s)
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
-    eeprom_contents[0xa] = 0x4000;
+    eeprom_contents[EEPROM_ID] = 0x4000;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
+    eeprom_contents[EEPROM_PHY_ID] = 1;
     uint16_t sum = 0;
     for (i = 0; i < EEPROM_SIZE - 1; i++) {
         sum += eeprom_contents[i];
Signature · 1 line
1.7.0
#5 lore raw

[Qemu-devel] Re: [PATCH 03/20] eepro100: Fix PXE boot

Quoted 8 lines · Stefan Weil

The phy handling was wrong for PXE, GPXE boot:
GPXE's eepro100 driver did not detect a valid link.

This is fixed here.

V2 - Use UPPER_CASE for enum values

Please repost the whole series, using prefix PATCHv3 and Cc me.

Thanks!

#6 lore raw

PATCH 4/20 eepro100: Support gpxe boot for all eepro100 devices

In reply to Stefan Weil

Only two boot ROM files are needed for all devices.

* Add these GPXE ROM files using new naming convention (as discussed on qemu-devel). Both files were created with http://rom-o-matic.net/, PCI vendor / device ids as in ROM filenames and option BANNER_TIMEOUT = 0.

* Remove old PXE ROM file for i82559er.
It was replaced by gpxe-eepro100-80861209.rom.

* Update pc-bios/README (and sort entries).

Full support still needs additional eepro100 fixes.

---
 hw/eepro100.c                      |   13 ++++++++++++-
 pc-bios/README                     |    4 ++--
 pc-bios/gpxe-eepro100-80861209.rom |  Bin 0 -> 56832 bytes
 pc-bios/gpxe-eepro100-80861229.rom |  Bin 0 -> 56832 bytes
 pc-bios/pxe-i82559er.bin           |  Bin 56832 -> 0 bytes
 5 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 pc-bios/gpxe-eepro100-80861209.rom
 create mode 100644 pc-bios/gpxe-eepro100-80861229.rom
 delete mode 100644 pc-bios/pxe-i82559er.bin
hw/eepro100.c +12 -1
index 994722d..179c544 100644
@@ -1975,6 +1975,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82550_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -1984,6 +1985,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82551_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -1993,6 +1995,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557a_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2002,6 +2005,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557b_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2011,6 +2015,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557c_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2020,6 +2025,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558a_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2029,6 +2035,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558b_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2038,6 +2045,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559a_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2047,6 +2055,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559b_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2056,6 +2065,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559c_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2065,7 +2075,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559er_init,
         .exit      = pci_nic_uninit,
-        .romfile   = "pxe-i82559er.bin",
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2075,6 +2085,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82562_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
pc-bios/README +2 -2
index 0570922..91f0ef1 100644
@@ -20,10 +20,10 @@
 - The PXE roms come from Rom-o-Matic gPXE 0.9.9 with BANNER_TIMEOUT=0
 
   e1000 8086:100E
-  pcnet32 1022:2000
+  eepro100 8086:1209, 8086:1229
   ns8390 1050:0940
+  pcnet32 1022:2000
   rtl8139 10ec:8139
-  eepro100 8086:1209
   virtio 1af4:1000
 
   http://rom-o-matic.net/
pc-bios/gpxe-eepro100-80861209.rom new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2ca59ec369fa3aa829aa64b80339dc9aaab9026f
GIT binary patch
pc-bios/gpxe-eepro100-80861229.rom new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..9cf397e3de03c4b6441893cf07d9ea63a36a65c8
GIT binary patch
pc-bios/pxe-i82559er.bin deleted binary +0 -0
deleted file mode 100644
index 2ca59ec369fa3aa829aa64b80339dc9aaab9026f..0000000000000000000000000000000000000000
GIT binary patch
Signature · 1 line
1.6.6.1
#7 lore raw

PATCH 5/20 eepro100: Add all supported devices to pci.c

All eepro100 devices work with drivers which
only use basic features.

They were tested with gpxe boot.

---
 hw/pci.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
hw/pci.c +18 -0
index eb2043e..1ba3f92 100644
@@ -1436,9 +1436,18 @@ void do_pci_info(Monitor *mon, QObject **ret_data)
 
 static const char * const pci_nic_models[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",
@@ -1448,9 +1457,18 @@ static const char * const pci_nic_models[] = {
 
 static const char * const pci_nic_names[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",
Signature · 1 line
1.6.6.1
#8 lore raw

PATCH 6/20 eepro100: Add TODO list

---
 hw/eepro100.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
hw/eepro100.c +8 -0
index 179c544..b93667a 100644
@@ -31,6 +31,14 @@
  *
  * Intel 8255x 10/100 Mbps Ethernet Controller Family
  * Open Source Software Developer Manual
+ *
+ * TODO:
+ *      * PHY emulation should be separated from nic emulation.
+ *        Most nic emulations could share the same phy code.
+ *      * i82550 is untested. It is programmed like the i82559.
+ *      * i82562 is untested. It is programmed like the i82559.
+ *      * Power management (i82558 and later) is not implemented.
+ *      * Wake-on-LAN is not implemented.
  */
 
 #include <stddef.h>             /* offsetof */
Signature · 1 line
1.6.6.1
#9 lore raw

PATCH 7/20 eepro100: Update copyright notice

---
 hw/eepro100.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
hw/eepro100.c +5 -5
index b93667a..3e2f008 100644
@@ -1,15 +1,15 @@
 /*
  * QEMU i8255x (PRO100) emulation
  *
- * Copyright (c) 2006-2007 Stefan Weil
+ * Copyright (C) 2006-2010 Stefan Weil
  *
  * Portions of the code are copies from grub / etherboot eepro100.c
  * and linux e100.c.
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) version 3 or any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,7 +17,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Tested features (i82559):
  *      PXE boot (i386) ok
Signature · 1 line
1.6.6.1
#10 lore raw

PATCH 8/20 eepro100: Add device descriptions

Add descriptions for all devices.
These descriptions are shown when users call
qemu -device ?

---
 hw/eepro100.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
hw/eepro100.c +12 -0
index 3e2f008..031fe69 100644
@@ -1980,6 +1980,7 @@ static int pci_i82562_init(PCIDevice *pci_dev)
 static PCIDeviceInfo eepro100_info[] = {
     {
         .qdev.name = "i82550",
+        .qdev.desc = "Intel i82550 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82550_init,
         .exit      = pci_nic_uninit,
@@ -1990,6 +1991,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82551",
+        .qdev.desc = "Intel i82551 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82551_init,
         .exit      = pci_nic_uninit,
@@ -2000,6 +2002,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557a",
+        .qdev.desc = "Intel i82557A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557a_init,
         .exit      = pci_nic_uninit,
@@ -2010,6 +2013,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557b",
+        .qdev.desc = "Intel i82557B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557b_init,
         .exit      = pci_nic_uninit,
@@ -2020,6 +2024,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557c",
+        .qdev.desc = "Intel i82557C Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557c_init,
         .exit      = pci_nic_uninit,
@@ -2030,6 +2035,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82558a",
+        .qdev.desc = "Intel i82558A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558a_init,
         .exit      = pci_nic_uninit,
@@ -2040,6 +2046,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82558b",
+        .qdev.desc = "Intel i82558B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558b_init,
         .exit      = pci_nic_uninit,
@@ -2050,6 +2057,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559a",
+        .qdev.desc = "Intel i82559A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559a_init,
         .exit      = pci_nic_uninit,
@@ -2060,6 +2068,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559b",
+        .qdev.desc = "Intel i82559B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559b_init,
         .exit      = pci_nic_uninit,
@@ -2070,6 +2079,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559c",
+        .qdev.desc = "Intel i82559C Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559c_init,
         .exit      = pci_nic_uninit,
@@ -2080,6 +2090,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559er",
+        .qdev.desc = "Intel i82559ER Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559er_init,
         .exit      = pci_nic_uninit,
@@ -2090,6 +2101,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82562",
+        .qdev.desc = "Intel i82562 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82562_init,
         .exit      = pci_nic_uninit,
Signature · 1 line
1.6.6.1
#11 lore raw

PATCH 9/20 eepro100: Use symbolic names and BIT macros in binary operations

Instead of magic numbers like 0x8000, symbolic names are used for the SCB command and status bits.

There are too many configuration bits to use symbolic names there, too. Using the BIT macro is a little help when comparing code and documentation.

For the same reason, some other constants were replaced by the BITS macro.

---
 hw/eepro100.c |   52 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 19 deletions(-)
hw/eepro100.c +33 -19
index 031fe69..1ce2cd1 100644
@@ -172,6 +172,20 @@ typedef struct {
     char packet[MAX_ETH_FRAME_SIZE + 4];
 } eepro100_rx_t;
 
+typedef enum {
+    COMMAND_EL = BIT(15),
+    COMMAND_S = BIT(14),
+    COMMAND_I = BIT(13),
+    COMMAND_NC = BIT(4),
+    COMMAND_SF = BIT(3),
+    COMMAND_CMD = BITS(2, 0),
+} scb_command_bit;
+
+typedef enum {
+    STATUS_C = BIT(15),
+    STATUS_OK = BIT(13),
+} scb_status_bit;
+
 typedef struct {
     uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions,
         tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
@@ -753,22 +767,22 @@ enum commands {
 
 static cu_state_t get_cu_state(EEPRO100State * s)
 {
-    return ((s->mem[SCBStatus] >> 6) & 0x03);
+    return ((s->mem[SCBStatus] & BITS(7, 6)) >> 6);
 }
 
 static void set_cu_state(EEPRO100State * s, cu_state_t state)
 {
-    s->mem[SCBStatus] = (s->mem[SCBStatus] & 0x3f) + (state << 6);
+    s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(7, 6)) + (state << 6);
 }
 
 static ru_state_t get_ru_state(EEPRO100State * s)
 {
-    return ((s->mem[SCBStatus] >> 2) & 0x0f);
+    return ((s->mem[SCBStatus] & BITS(5, 2)) >> 2);
 }
 
 static void set_ru_state(EEPRO100State * s, ru_state_t state)
 {
-    s->mem[SCBStatus] = (s->mem[SCBStatus] & 0xc3) + (state << 2);
+    s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(5, 2)) + (state << 2);
 }
 
 static void dump_statistics(EEPRO100State * s)
@@ -898,13 +912,13 @@ static void action_command(EEPRO100State *s)
         uint16_t command = le16_to_cpu(s->tx.command);
         logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
                status, command, s->tx.link);
-        bool bit_el = ((command & 0x8000) != 0);
-        bool bit_s = ((command & 0x4000) != 0);
-        bool bit_i = ((command & 0x2000) != 0);
-        bool bit_nc = ((command & 0x0010) != 0);
+        bool bit_el = ((command & COMMAND_EL) != 0);
+        bool bit_s = ((command & COMMAND_S) != 0);
+        bool bit_i = ((command & COMMAND_I) != 0);
+        bool bit_nc = ((command & COMMAND_NC) != 0);
         bool success = true;
-        //~ bool bit_sf = ((command & 0x0008) != 0);
-        uint16_t cmd = command & 0x0007;
+        //~ bool bit_sf = ((command & COMMAND_SF) != 0);
+        uint16_t cmd = command & COMMAND_CMD;
         s->cu_offset = le32_to_cpu(s->tx.link);
         switch (cmd) {
         case CmdNOp:
@@ -941,7 +955,7 @@ static void action_command(EEPRO100State *s)
             break;
         }
         /* Write new status. */
-        stw_phys(s->cb_address, status | 0x8000 | (success ? 0x2000 : 0));
+        stw_phys(s->cb_address, status | STATUS_C | (success ? STATUS_OK : 0));
         if (bit_i) {
             /* CU completed action. */
             eepro100_cx_interrupt(s);
@@ -1684,13 +1698,13 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         /* CSMA is disabled. */
         logout("%p received while CSMA is disabled\n", s);
         return -1;
-    } else if (size < 64 && (s->configuration[7] & 1)) {
+    } else if (size < 64 && (s->configuration[7] & BIT(0))) {
         /* Short frame and configuration byte 7/0 (discard short receive) set:
          * Short frame is discarded */
         logout("%p received short frame (%zu byte)\n", s, size);
         s->statistics.rx_short_frame_errors++;
         //~ return -1;
-    } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) {
+    } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
         /* Long frame and configuration byte 18/3 (long receive ok) not set:
          * Long frames are discarded. */
         logout("%p received long frame (%zu byte), ignored\n", s, size);
@@ -1713,7 +1727,7 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
           assert(mcast_idx < 64);
           if (s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))) {
             /* Multicast frame is allowed in hash table. */
-          } else if (s->configuration[15] & 1) {
+          } else if (s->configuration[15] & BIT(0)) {
               /* Promiscuous: receive all. */
               rfd_status |= 0x0004;
           } else {
@@ -1723,7 +1737,7 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         }
         /* TODO: Next not for promiscuous mode? */
         rfd_status |= 0x0002;
-    } else if (s->configuration[15] & 1) {
+    } else if (s->configuration[15] & BIT(0)) {
         /* Promiscuous: receive all. */
         TRACE(RXTX, logout("%p received frame in promiscuous mode, len=%zu\n", s, size));
         rfd_status |= 0x0004;
@@ -1764,23 +1778,23 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
     /* Early receive interrupt not supported. */
     //~ eepro100_er_interrupt(s);
     /* Receive CRC Transfer not supported. */
-    if (s->configuration[18] & 4) {
+    if (s->configuration[18] & BIT(2)) {
         missing("Receive CRC Transfer");
         return -1;
     }
     /* TODO: check stripping enable bit. */
-    //~ assert(!(s->configuration[17] & 1));
+    //~ assert(!(s->configuration[17] & BIT(0)));
     cpu_physical_memory_write(s->ru_base + s->ru_offset +
                               offsetof(eepro100_rx_t, packet), buf, size);
     s->statistics.rx_good_frames++;
     eepro100_fr_interrupt(s);
     s->ru_offset = le32_to_cpu(rx.link);
-    if (rfd_command & 0x8000) {
+    if (rfd_command & COMMAND_EL) {
         /* EL bit is set, so this was the last frame. */
         logout("receive: Running out of frames\n");
         set_ru_state(s, ru_suspended);
     }
-    if (rfd_command & 0x4000) {
+    if (rfd_command & COMMAND_S) {
         /* S bit is set. */
         set_ru_state(s, ru_suspended);
     }
Signature · 1 line
1.6.6.1
#12 lore raw

PATCH 10/20 eepro100: Remove old unused code

This code is no longer needed.

---
 hw/eepro100.c |   18 ------------------
 1 files changed, 0 insertions(+), 18 deletions(-)
hw/eepro100.c +0 -18
index 1ce2cd1..c647322 100644
@@ -469,24 +469,6 @@ static void pci_reset(EEPRO100State * s)
     PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   // latency timer = 32 clocks
     /* PCI Header Type */
     /* BIST (built-in self test) */
-#if defined(TARGET_I386)
-// !!! workaround for buggy bios
-//~ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0
-#endif
-#if 0
-    /* PCI Base Address Registers */
-    /* CSR Memory Mapped Base Address */
-    PCI_CONFIG_32(PCI_BASE_ADDRESS_0,
-                  PCI_BASE_ADDRESS_SPACE_MEMORY |
-                  PCI_BASE_ADDRESS_MEM_PREFETCH);
-    /* CSR I/O Mapped Base Address */
-    PCI_CONFIG_32(PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_SPACE_IO);
-#if 0
-    /* Flash Memory Mapped Base Address */
-    PCI_CONFIG_32(PCI_BASE_ADDRESS_2,
-                  0xfffe0000 | PCI_BASE_ADDRESS_SPACE_MEMORY);
-#endif
-#endif
     /* Expansion ROM Base Address (depends on boot disable!!!) */
     /* TODO: not needed, set when BAR is registered */
     PCI_CONFIG_32(PCI_ROM_ADDRESS, PCI_BASE_ADDRESS_SPACE_MEMORY);
Signature · 1 line
1.6.6.1
#13 lore raw

PATCH 11/20 eepro100: Use symbolic names for bits in EEPROM id

---
 hw/eepro100.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
hw/eepro100.c +16 -1
index c647322..01bcd6d 100644
@@ -272,6 +272,21 @@ typedef enum {
     eeprom_smbus_addr = 0x90,
 } EEPROMOffset;
 
+/* Bit values for EEPROM ID word. */
+typedef enum {
+    eeprom_id_mdm = BIT(0),     /* Modem */
+    eeprom_id_stb = BIT(1),     /* Standby Enable */
+    eeprom_id_wmr = BIT(2),     /* ??? */
+    eeprom_id_wol = BIT(5),     /* Wake on LAN */
+    eeprom_id_dpd = BIT(6),     /* Deep Power Down */
+    eeprom_id_alt = BIT(7),     /* */
+    /* BITS(10, 8) device revision */
+    eeprom_id_bd = BIT(11),     /* boot disable */
+    eeprom_id_id = BIT(13),     /* id bit */
+    /* BITS(15, 14) signature */
+    eeprom_id_valid = BIT(14),  /* signature for valid eeprom */
+} eeprom_id_bit;
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
     /* MDI Registers 0 - 6, 7 */
@@ -643,7 +658,7 @@ static void nic_selective_reset(EEPRO100State * s)
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
-    eeprom_contents[eeprom_id] = 0x4000;
+    eeprom_contents[eeprom_id] = eeprom_id_valid;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
     eeprom_contents[eeprom_phy_id] = 1;
Signature · 1 line
1.6.6.1
#14 lore raw

PATCH 11/20 eepro100: Use symbolic names for bits in EEPROM id

V2 - Use UPPER_CASE for enum values

---
 hw/eepro100.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
hw/eepro100.c +16 -1
index c2ff569..2a871b8 100644
@@ -272,6 +272,21 @@ typedef enum {
     EEPROM_SMBUS_ADDR = 0x90,
 } EEPROMOffset;
 
+/* Bit values for EEPROM ID word. */
+typedef enum {
+    EEPROM_ID_MDM = BIT(0),     /* Modem */
+    EEPROM_ID_STB = BIT(1),     /* Standby Enable */
+    EEPROM_ID_WMR = BIT(2),     /* ??? */
+    EEPROM_ID_WOL = BIT(5),     /* Wake on LAN */
+    EEPROM_ID_DPD = BIT(6),     /* Deep Power Down */
+    EEPROM_ID_ALT = BIT(7),     /* */
+    /* BITS(10, 8) device revision */
+    EEPROM_ID_BD = BIT(11),     /* boot disable */
+    EEPROM_ID_ID = BIT(13),     /* id bit */
+    /* BITS(15, 14) signature */
+    EEPROM_ID_VALID = BIT(14),  /* signature for valid eeprom */
+} eeprom_id_bit;
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
     /* MDI Registers 0 - 6, 7 */
@@ -643,7 +658,7 @@ static void nic_selective_reset(EEPRO100State * s)
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
-    eeprom_contents[EEPROM_ID] = 0x4000;
+    eeprom_contents[EEPROM_ID] = EEPROM_ID_VALID;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
     eeprom_contents[EEPROM_PHY_ID] = 1;
Signature · 1 line
1.7.0
#15 lore raw

[Qemu-devel] Re: [PATCH 11/20] eepro100: Use symbolic names for bits in EEPROM id

In reply to Stefan Weil
Quoted 17 lines · Stefan Weil
---
 hw/eepro100.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
hw/eepro100.c +4 -0
index c647322..01bcd6d 100644
@@ -272,6 +272,21 @@ typedef enum {
     eeprom_smbus_addr = 0x90,
 } EEPROMOffset;
 
+/* Bit values for EEPROM ID word. */
+typedef enum {
+    eeprom_id_mdm = BIT(0),     /* Modem */
+    eeprom_id_stb = BIT(1),     /* Standby Enable */

hw/eepro100.c typedef enum { · line 288

Quoted 10 lines
hw/eepro100.c +10 -0
+    eeprom_id_wmr = BIT(2),     /* ??? */
+    eeprom_id_wol = BIT(5),     /* Wake on LAN */
+    eeprom_id_dpd = BIT(6),     /* Deep Power Down */
+    eeprom_id_alt = BIT(7),     /* */
+    /* BITS(10, 8) device revision */
+    eeprom_id_bd = BIT(11),     /* boot disable */
+    eeprom_id_id = BIT(13),     /* id bit */
+    /* BITS(15, 14) signature */
+    eeprom_id_valid = BIT(14),  /* signature for valid eeprom */
+} eeprom_id_bit;

The type name is unused - don't add it?
Can constants be upper case?

Quoted 17 lines
hw/eepro100.c +2 -1
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
     /* MDI Registers 0 - 6, 7 */
@@ -643,7 +658,7 @@ static void nic_selective_reset(EEPRO100State * s)
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
-    eeprom_contents[eeprom_id] = 0x4000;
+    eeprom_contents[eeprom_id] = eeprom_id_valid;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
     eeprom_contents[eeprom_phy_id] = 1;
Signature · 1 line
1.6.6.1
#16 lore raw

[Qemu-devel] Re: [PATCH 11/20] eepro100: Use symbolic names for bits in EEPROM id

Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Stefan Weil

---
hw/eepro100.c | 17 ++++++++++++++++-

1 files changed, 16 insertions(+), 1 deletions(-)
hw/eepro100.c +0 -0
index c647322..01bcd6d 100644
@@ -272,6 +272,21 @@ typedef enum {
 eeprom_smbus_addr = 0x90,
 } EEPROMOffset;
 
Quoted 16 lines
Quoted 4 lines
hw/eepro100.c +4 -0
+/* Bit values for EEPROM ID word. */
+typedef enum {
+ eeprom_id_mdm = BIT(0), /* Modem */
+ eeprom_id_stb = BIT(1), /* Standby Enable */

hw/eepro100.c typedef enum { · line 288

Quoted 10 lines
hw/eepro100.c +10 -0
+ eeprom_id_wmr = BIT(2), /* ??? */
+ eeprom_id_wol = BIT(5), /* Wake on LAN */
+ eeprom_id_dpd = BIT(6), /* Deep Power Down */
+ eeprom_id_alt = BIT(7), /* */
+ /* BITS(10, 8) device revision */
+ eeprom_id_bd = BIT(11), /* boot disable */
+ eeprom_id_id = BIT(13), /* id bit */
+ /* BITS(15, 14) signature */
+ eeprom_id_valid = BIT(14), /* signature for valid eeprom */
+} eeprom_id_bit;

The type name is unused - don't add it?

Maybe it will be used some day?
Adding a type name now makes the code more uniform and avoids two deltas when it is used.

There are a lot of symbolic names which are unused today, for example most of above enum values. This is common practice.

Quoted 1 line

Can constants be upper case?

Of course they can. Is this a QEMU coding convention? I did not see a hint in CODING_STYLE.

If it is the coding style: UPPER_CASE or CamelCase? Will it be required for all future modifications of QEMU code?

Quoted 19 lines
Quoted 19 lines
hw/eepro100.c +2 -1
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
 /* MDI Registers 0 - 6, 7 */
@@ -643,7 +658,7 @@ static void nic_selective_reset(EEPRO100State * s)
 uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
 //~ eeprom93xx_reset(s->eeprom);
 memcpy(eeprom_contents, s->conf.macaddr.a, 6);
- eeprom_contents[eeprom_id] = 0x4000;
+ eeprom_contents[eeprom_id] = eeprom_id_valid;
 if (s->device == i82557B || s->device == i82557C)
 eeprom_contents[5] = 0x0100;
 eeprom_contents[eeprom_phy_id] = 1;
Signature · 1 line
1.6.6.1
#17 lore raw

[Qemu-devel] Re: [PATCH 11/20] eepro100: Use symbolic names for bits in EEPROM id

Quoted 40 lines · Stefan Weil
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Stefan Weil

---
hw/eepro100.c | 17 ++++++++++++++++-

1 files changed, 16 insertions(+), 1 deletions(-)
hw/eepro100.c +0 -0
index c647322..01bcd6d 100644
@@ -272,6 +272,21 @@ typedef enum {
 eeprom_smbus_addr = 0x90,
 } EEPROMOffset;
 
Quoted 16 lines
Quoted 4 lines
hw/eepro100.c +4 -0
+/* Bit values for EEPROM ID word. */
+typedef enum {
+ eeprom_id_mdm = BIT(0), /* Modem */
+ eeprom_id_stb = BIT(1), /* Standby Enable */

hw/eepro100.c typedef enum { · line 288

Quoted 10 lines
hw/eepro100.c +10 -0
+ eeprom_id_wmr = BIT(2), /* ??? */
+ eeprom_id_wol = BIT(5), /* Wake on LAN */
+ eeprom_id_dpd = BIT(6), /* Deep Power Down */
+ eeprom_id_alt = BIT(7), /* */
+ /* BITS(10, 8) device revision */
+ eeprom_id_bd = BIT(11), /* boot disable */
+ eeprom_id_id = BIT(13), /* id bit */
+ /* BITS(15, 14) signature */
+ eeprom_id_valid = BIT(14), /* signature for valid eeprom */
+} eeprom_id_bit;

The type name is unused - don't add it?

Maybe it will be used some day?
Adding a type name now makes the code more uniform and avoids two deltas when it is used.

There are a lot of symbolic names which are unused today, for example most of above enum values. This is common practice.

Quoted 6 lines
Quoted 1 line

Can constants be upper case?

Of course they can. Is this a QEMU coding convention? I did not see a hint in CODING_STYLE.

If it is the coding style: UPPER_CASE or CamelCase?

UPPER_CASE

Quoted 22 lines

Will it be required for all future modifications of QEMU code?

Quoted 19 lines
Quoted 19 lines
hw/eepro100.c +2 -1
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
 /* MDI Registers 0 - 6, 7 */
@@ -643,7 +658,7 @@ static void nic_selective_reset(EEPRO100State * s)
 uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
 //~ eeprom93xx_reset(s->eeprom);
 memcpy(eeprom_contents, s->conf.macaddr.a, 6);
- eeprom_contents[eeprom_id] = 0x4000;
+ eeprom_contents[eeprom_id] = eeprom_id_valid;
 if (s->device == i82557B || s->device == i82557C)
 eeprom_contents[5] = 0x0100;
 eeprom_contents[eeprom_phy_id] = 1;
Signature · 1 line
1.6.6.1
#18 lore raw

PATCH 12/20 eepro100: Replace variable name to fix a compiler warning

In reply to Stefan Weil

When compiling with -Wshadow, gcc gives a warning
which is fixed by renaming stat -> status.

---
 hw/eepro100.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/eepro100.c +6 -6
index 01bcd6d..b5bd05b 100644
@@ -392,14 +392,14 @@ static void eepro100_acknowledge(EEPRO100State * s)
     }
 }
 
-static void eepro100_interrupt(EEPRO100State * s, uint8_t stat)
+static void eepro100_interrupt(EEPRO100State * s, uint8_t status)
 {
     uint8_t mask = ~s->mem[SCBIntmask];
-    s->mem[SCBAck] |= stat;
-    stat = s->scb_stat = s->mem[SCBAck];
-    stat &= (mask | 0x0f);
-    //~ stat &= (~s->mem[SCBIntmask] | 0x0xf);
-    if (stat && (mask & 0x01)) {
+    s->mem[SCBAck] |= status;
+    status = s->scb_stat = s->mem[SCBAck];
+    status &= (mask | 0x0f);
+    //~ status &= (~s->mem[SCBIntmask] | 0x0xf);
+    if (status && (mask & 0x01)) {
         /* SCB mask and SCB Bit M do not disable interrupt. */
         enable_interrupt(s);
     } else if (s->int_stat) {
Signature · 1 line
1.6.6.1
#19 lore raw

PATCH 13/20 eepro100: Support RNR interrupt

The RNR interrupt is triggered under these conditions:

* the RU is not ready to receive a frame due to missing resources
* the RU is ready and a RU abort command was requested

---
 hw/eepro100.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
hw/eepro100.c +10 -3
index b5bd05b..37176cd 100644
@@ -120,7 +120,7 @@
 #define  RU_NOP         0x0000
 #define  RX_START       0x0001
 #define  RX_RESUME      0x0002
-#define  RX_ABORT       0x0004
+#define  RU_ABORT       0x0004
 #define  RX_ADDR_LOAD   0x0006
 #define  RX_RESUMENR    0x0007
 #define INT_MASK        0x0100
@@ -426,13 +426,11 @@ static void eepro100_fr_interrupt(EEPRO100State * s)
     eepro100_interrupt(s, 0x40);
 }
 
-#if 0
 static void eepro100_rnr_interrupt(EEPRO100State * s)
 {
     /* RU is not ready. */
     eepro100_interrupt(s, 0x10);
 }
-#endif
 
 static void eepro100_mdi_interrupt(EEPRO100State * s)
 {
@@ -1065,6 +1063,13 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         }
         set_ru_state(s, ru_ready);
         break;
+    case RU_ABORT:
+        /* RU abort. */
+        if (get_ru_state(s) == ru_ready) {
+            eepro100_rnr_interrupt(s);
+        }
+        set_ru_state(s, ru_idle);
+        break;
     case RX_ADDR_LOAD:
         /* Load RU base. */
         TRACE(OTHER, logout("val=0x%02x (RU base address)\n", val));
@@ -1747,6 +1752,8 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
     if (get_ru_state(s) != ru_ready) {
         /* No resources available. */
         logout("no resources, state=%u\n", get_ru_state(s));
+        /* TODO: RNR interrupt only at first failed frame? */
+        eepro100_rnr_interrupt(s);
         s->statistics.rx_resource_errors++;
         //~ assert(!"no resources");
         return -1;
Signature · 1 line
1.6.6.1
#20 lore raw

PATCH 14/20 eepro100: Fix CU Start command

CU Start is allowed when the CU is in the idle or suspended state.

---
 hw/eepro100.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/eepro100.c +6 -6
index 37176cd..8a139f7 100644
@@ -976,17 +976,17 @@ static void action_command(EEPRO100State *s)
 
 static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
 {
+    cu_state_t cu_state;
     switch (val) {
     case CU_NOP:
         /* No operation. */
         break;
     case CU_START:
-        if (get_cu_state(s) != cu_idle) {
-            /* Intel documentation says that CU must be idle for the CU
-             * start command. Intel driver for Linux also starts the CU
-             * from suspended state. */
-            logout("CU state is %u, should be %u\n", get_cu_state(s), cu_idle);
-            //~ assert(!"wrong CU state");
+        cu_state = get_cu_state(s);
+        if (cu_state != cu_idle && cu_state != cu_suspended) {
+            /* Intel documentation says that CU must be idle or suspended
+             * for the CU start command. */
+            logout("unexpected CU state is %u\n", cu_state);
         }
         set_cu_state(s, cu_active);
         s->cu_offset = s->pointer;
Signature · 1 line
1.6.6.1
#21 lore raw

PATCH 15/20 eepro100: Prettify code (no functional changes)

* Fix indentation.

---
 hw/eepro100.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
hw/eepro100.c +4 -4
index 8a139f7..368a9d6 100644
@@ -188,11 +188,11 @@ typedef enum {
 
 typedef struct {
     uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions,
-        tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
-        tx_multiple_collisions, tx_total_collisions;
+             tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
+             tx_multiple_collisions, tx_total_collisions;
     uint32_t rx_good_frames, rx_crc_errors, rx_alignment_errors,
-        rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
-        rx_short_frame_errors;
+             rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
+             rx_short_frame_errors;
     uint32_t fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported;
     uint16_t xmt_tco_frames, rcv_tco_frames;
     /* TODO: i82559 has six reserved statistics but a total of 24 dwords. */
Signature · 1 line
1.6.6.1
#22 lore raw

PATCH 16/20 eepro100: Use tx.status

There is no need for a local variable "status".
Using tx.status makes it clearer which status
is addressed.

---
 hw/eepro100.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/eepro100.c +3 -3
index 368a9d6..ebf0f7d 100644
@@ -903,10 +903,10 @@ static void action_command(EEPRO100State *s)
     for (;;) {
         s->cb_address = s->cu_base + s->cu_offset;
         cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
-        uint16_t status = le16_to_cpu(s->tx.status);
         uint16_t command = le16_to_cpu(s->tx.command);
+        s->tx.status = le16_to_cpu(s->tx.status);
         logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-               status, command, s->tx.link);
+               s->tx.status, command, s->tx.link);
         bool bit_el = ((command & COMMAND_EL) != 0);
         bool bit_s = ((command & COMMAND_S) != 0);
         bool bit_i = ((command & COMMAND_I) != 0);
@@ -950,7 +950,7 @@ static void action_command(EEPRO100State *s)
             break;
         }
         /* Write new status. */
-        stw_phys(s->cb_address, status | STATUS_C | (success ? STATUS_OK : 0));
+        stw_phys(s->cb_address, s->tx.status | STATUS_C | (success ? STATUS_OK : 0));
         if (bit_i) {
             /* CU completed action. */
             eepro100_cx_interrupt(s);
Signature · 1 line
1.6.6.1
#23 lore raw

PATCH 17/20 eepro100: New function for reading command block

Move code which reads the command block to the new function read_cb. The patch also fixes some endianess issues related to the command block and moves declarations of local variables to the beginning of the block.

---
 hw/eepro100.c |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)
hw/eepro100.c +28 -14
index ebf0f7d..43595eb 100644
@@ -798,6 +798,16 @@ static void dump_statistics(EEPRO100State * s)
     //~ missing("CU dump statistical counters");
 }
 
+static void read_cb(EEPRO100State *s)
+{
+    cpu_physical_memory_read(s->cb_address, (uint8_t *) &s->tx, sizeof(s->tx));
+    s->tx.status = le16_to_cpu(s->tx.status);
+    s->tx.command = le16_to_cpu(s->tx.command);
+    s->tx.link = le32_to_cpu(s->tx.link);
+    s->tx.tbd_array_addr = le32_to_cpu(s->tx.tbd_array_addr);
+    s->tx.tcb_bytes = le16_to_cpu(s->tx.tcb_bytes);
+}
+
 static void tx_command(EEPRO100State *s)
 {
     uint32_t tbd_array = le32_to_cpu(s->tx.tbd_array_addr);
@@ -901,21 +911,25 @@ static void set_multicast_list(EEPRO100State *s)
 static void action_command(EEPRO100State *s)
 {
     for (;;) {
-        s->cb_address = s->cu_base + s->cu_offset;
-        cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
-        uint16_t command = le16_to_cpu(s->tx.command);
-        s->tx.status = le16_to_cpu(s->tx.status);
-        logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-               s->tx.status, command, s->tx.link);
-        bool bit_el = ((command & COMMAND_EL) != 0);
-        bool bit_s = ((command & COMMAND_S) != 0);
-        bool bit_i = ((command & COMMAND_I) != 0);
-        bool bit_nc = ((command & COMMAND_NC) != 0);
+        bool bit_el;
+        bool bit_s;
+        bool bit_i;
+        bool bit_nc;
         bool success = true;
-        //~ bool bit_sf = ((command & COMMAND_SF) != 0);
-        uint16_t cmd = command & COMMAND_CMD;
-        s->cu_offset = le32_to_cpu(s->tx.link);
-        switch (cmd) {
+        s->cb_address = s->cu_base + s->cu_offset;
+        read_cb(s);
+        bit_el = ((s->tx.command & COMMAND_EL) != 0);
+        bit_s = ((s->tx.command & COMMAND_S) != 0);
+        bit_i = ((s->tx.command & COMMAND_I) != 0);
+        bit_nc = ((s->tx.command & COMMAND_NC) != 0);
+#if 0
+        bool bit_sf = ((s->tx.command & COMMAND_SF) != 0);
+#endif
+        s->cu_offset = s->tx.link;
+        TRACE(OTHER,
+              logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
+                     s->tx.status, s->tx.command, s->tx.link));
+        switch (s->tx.command & COMMAND_CMD) {
         case CmdNOp:
             /* Do nothing. */
             break;
Signature · 1 line
1.6.6.1
#24 lore raw

PATCH 18/20 eepro100: Add diagnose command

Real hardware would run an internal self-test.
The emulation just returns a passed status.

Original patch was from Reimar Döffinger, thanks.

---
 hw/eepro100.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/eepro100.c +5 -0
index 43595eb..1ac89ef 100644
@@ -958,6 +958,11 @@ static void action_command(EEPRO100State *s)
             /* Starting with offset 8, the command contains
              * 64 dwords microcode which we just ignore here. */
             break;
+        case CmdDiagnose:
+            TRACE(OTHER, logout("diagnose\n"));
+            /* Make sure error flag is not set. */
+            s->tx.status = 0;
+            break;
         default:
             missing("undefined command");
             success = false;
Signature · 1 line
1.6.6.1
#25 lore raw

PATCH 19/20 eepro100: Remove C++ comments

C++ comments are unwanted, so this is fixed here.

* Replace C++ comments by C comments.
* Put code which was deactivated by a C++ comment in #if 0...#endif.

---
 hw/eepro100.c |  185 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 126 insertions(+), 59 deletions(-)
hw/eepro100.c +126 -59
index 1ac89ef..0f5fffa 100644
@@ -154,11 +154,13 @@ typedef struct {
     uint16_t tcb_bytes;         /* transmit command block byte count (in lower 14 bits */
     uint8_t tx_threshold;       /* transmit threshold */
     uint8_t tbd_count;          /* TBD number */
-    //~ /* This constitutes two "TBD" entries: hdr and data */
-    //~ uint32_t tx_buf_addr0;  /* void *, header of frame to be transmitted.  */
-    //~ int32_t  tx_buf_size0;  /* Length of Tx hdr. */
-    //~ uint32_t tx_buf_addr1;  /* void *, data to be transmitted.  */
-    //~ int32_t  tx_buf_size1;  /* Length of Tx data. */
+#if 0
+    /* This constitutes two "TBD" entries: hdr and data */
+    uint32_t tx_buf_addr0;  /* void *, header of frame to be transmitted.  */
+    int32_t  tx_buf_size0;  /* Length of Tx hdr. */
+    uint32_t tx_buf_addr1;  /* void *, data to be transmitted.  */
+    int32_t  tx_buf_size1;  /* Length of Tx data. */
+#endif
 } eepro100_tx_t;
 
 /* Receive frame descriptor. */
@@ -398,7 +400,9 @@ static void eepro100_interrupt(EEPRO100State * s, uint8_t status)
     s->mem[SCBAck] |= status;
     status = s->scb_stat = s->mem[SCBAck];
     status &= (mask | 0x0f);
-    //~ status &= (~s->mem[SCBIntmask] | 0x0xf);
+#if 0
+    status &= (~s->mem[SCBIntmask] | 0x0xf);
+#endif
     if (status && (mask & 0x01)) {
         /* SCB mask and SCB Bit M do not disable interrupt. */
         enable_interrupt(s);
@@ -477,9 +481,11 @@ static void pci_reset(EEPRO100State * s)
     pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
     /* PCI Cache Line Size */
     /* check cache line size!!! */
-    //~ PCI_CONFIG_8(0x0c, 0x00);
+#if 0
+    PCI_CONFIG_8(0x0c, 0x00);
+#endif
     /* PCI Latency Timer */
-    PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   // latency timer = 32 clocks
+    PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   /* latency timer = 32 clocks */
     /* PCI Header Type */
     /* BIST (built-in self test) */
     /* Expansion ROM Base Address (depends on boot disable!!!) */
@@ -492,7 +498,7 @@ static void pci_reset(EEPRO100State * s)
     /* Interrupt Line */
     /* Interrupt Pin */
     /* TODO: RST# value should be 0 */
-    PCI_CONFIG_8(PCI_INTERRUPT_PIN, 1);      // interrupt pin 0
+    PCI_CONFIG_8(PCI_INTERRUPT_PIN, 1);      /* interrupt pin 0 */
     /* Minimum Grant */
     PCI_CONFIG_8(PCI_MIN_GNT, 0x08);
     /* Maximum Latency */
@@ -500,20 +506,20 @@ static void pci_reset(EEPRO100State * s)
 
     switch (device) {
     case i82550:
-        // TODO: check device id.
+        /* TODO: check device id. */
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* Revision ID: 0x0c, 0x0d, 0x0e. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
-        // TODO: check size of statistical counters.
+        /* TODO: check size of statistical counters. */
         s->stats_size = 80;
-        // TODO: check extended tcb support.
+        /* TODO: check extended tcb support. */
         s->has_extended_tcb_support = 1;
         break;
     case i82551:
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* Revision ID: 0x0f, 0x10. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0f);
-        // TODO: check size of statistical counters.
+        /* TODO: check size of statistical counters. */
         s->stats_size = 80;
         s->has_extended_tcb_support = 1;
         break;
@@ -572,7 +578,7 @@ static void pci_reset(EEPRO100State * s)
         PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
                                   PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
         PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
-        // TODO: Windows wants revision id 0x0c.
+        /* TODO: Windows wants revision id 0x0c. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0c);
 #if EEPROM_SIZE > 0
         PCI_CONFIG_16(PCI_SUBSYSTEM_VENDOR_ID, 0x8086);
@@ -590,7 +596,7 @@ static void pci_reset(EEPRO100State * s)
         s->has_extended_tcb_support = 1;
         break;
     case i82562:
-        // TODO: check device id.
+        /* TODO: check device id. */
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* TODO: wrong revision id. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
@@ -637,14 +643,16 @@ static void pci_reset(EEPRO100State * s)
 
 #if EEPROM_SIZE > 0
     if (device == i82557C || device == i82558B || device == i82559C) {
-        // TODO: get vendor id from EEPROM for i82557C or later.
-        // TODO: get device id from EEPROM for i82557C or later.
-        // TODO: status bit 4 can be disabled by EEPROM for i82558, i82559.
-        // TODO: header type is determined by EEPROM for i82559.
-        // TODO: get subsystem id from EEPROM for i82557C or later.
-        // TODO: get subsystem vendor id from EEPROM for i82557C or later.
-        // TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later.
-        // TODO: capability pointer depends on EEPROM for i82558.
+        /*
+        TODO: get vendor id from EEPROM for i82557C or later.
+        TODO: get device id from EEPROM for i82557C or later.
+        TODO: status bit 4 can be disabled by EEPROM for i82558, i82559.
+        TODO: header type is determined by EEPROM for i82559.
+        TODO: get subsystem id from EEPROM for i82557C or later.
+        TODO: get subsystem vendor id from EEPROM for i82557C or later.
+        TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later.
+        TODO: capability pointer depends on EEPROM for i82558.
+        */
         logout("Get device id and revision from EEPROM!!!\n");
     }
 #endif /* EEPROM_SIZE > 0 */
@@ -654,7 +662,9 @@ static void nic_selective_reset(EEPRO100State * s)
 {
     size_t i;
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
-    //~ eeprom93xx_reset(s->eeprom);
+#if 0
+    eeprom93xx_reset(s->eeprom);
+#endif
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
     eeprom_contents[eeprom_id] = eeprom_id_valid;
     if (s->device == i82557B || s->device == i82557C)
@@ -738,7 +748,7 @@ static void eepro100_write_status(EEPRO100State * s, uint16_t val)
 static uint16_t eepro100_read_command(EEPRO100State * s)
 {
     uint16_t val = 0xffff;
-    //~ TRACE(OTHER, logout("val=0x%04x\n", val));
+    TRACE(OTHER, logout("val=0x%04x\n", val));
     return val;
 }
 #endif
@@ -793,9 +803,11 @@ static void dump_statistics(EEPRO100State * s)
     stl_le_phys(s->statsaddr + 36, s->statistics.rx_good_frames);
     stl_le_phys(s->statsaddr + 48, s->statistics.rx_resource_errors);
     stl_le_phys(s->statsaddr + 60, s->statistics.rx_short_frame_errors);
-    //~ stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
-    //~ stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
-    //~ missing("CU dump statistical counters");
+#if 0
+    stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
+    stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
+    missing("CU dump statistical counters");
+#endif
 }
 
 static void read_cb(EEPRO100State *s)
@@ -832,7 +844,9 @@ static void tx_command(EEPRO100State *s)
     while (size < tcb_bytes) {
         uint32_t tx_buffer_address = ldl_phys(tbd_address);
         uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
-        //~ uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
+#if 0
+        uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
+#endif
         tbd_address += 8;
         TRACE(RXTX, logout
             ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n",
@@ -889,7 +903,9 @@ static void tx_command(EEPRO100State *s)
     s->statistics.tx_good_frames++;
     /* Transmit with bad status would raise an CX/TNO interrupt.
      * (82557 only). Emulation never has bad status. */
-    //~ eepro100_cx_interrupt(s);
+#if 0
+    eepro100_cx_interrupt(s);
+#endif
 }
 
 static void set_multicast_list(EEPRO100State *s)
@@ -1016,7 +1032,9 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
             logout("bad CU resume from CU state %u\n", get_cu_state(s));
             /* Workaround for bad Linux eepro100 driver which resumes
              * from idle state. */
-            //~ missing("cu resume");
+#if 0
+            missing("cu resume");
+#endif
             set_cu_state(s, cu_suspended);
         }
         if (get_cu_state(s) == cu_suspended) {
@@ -1067,7 +1085,9 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         /* RU start. */
         if (get_ru_state(s) != ru_idle) {
             logout("RU state is %u, should be %u\n", get_ru_state(s), ru_idle);
-            //~ assert(!"wrong RU state");
+#if 0
+            assert(!"wrong RU state");
+#endif
         }
         set_ru_state(s, ru_ready);
         s->ru_offset = s->pointer;
@@ -1078,7 +1098,9 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         if (get_ru_state(s) != ru_suspended) {
             logout("RU state is %u, should be %u\n", get_ru_state(s),
                    ru_suspended);
-            //~ assert(!"wrong RU state");
+#if 0
+            assert(!"wrong RU state");
+#endif
         }
         set_ru_state(s, ru_ready);
         break;
@@ -1140,7 +1162,9 @@ static void eepro100_write_eeprom(eeprom_t * eeprom, uint8_t val)
     TRACE(EEPROM, logout("val=0x%02x\n", val));
 
     /* mask unwriteable bits */
-    //~ val = SET_MASKED(val, 0x31, eeprom->value);
+#if 0
+    val = SET_MASKED(val, 0x31, eeprom->value);
+#endif
 
     int eecs = ((val & EEPROM_CS) != 0);
     int eesk = ((val & EEPROM_SK) != 0);
@@ -1222,7 +1246,9 @@ static void eepro100_write_mdi(EEPRO100State * s, uint32_t val)
           val, raiseint, mdi_op_name[opcode], phy, reg2name(reg), data));
     if (phy != 1) {
         /* Unsupported PHY address. */
-        //~ logout("phy must be 1 but is %u\n", phy);
+#if 0
+        logout("phy must be 1 but is %u\n", phy);
+#endif
         data = 0;
     } else if (opcode != 1 && opcode != 2) {
         /* Unsupported opcode. */
@@ -1368,16 +1394,22 @@ static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBAck:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBCmd:
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
-        //~ val = eepro100_read_command(s);
+#if 0
+        val = eepro100_read_command(s);
+#endif
         break;
     case SCBIntmask:
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
@@ -1413,7 +1445,9 @@ static uint16_t eepro100_read2(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
     case SCBCmd:
         TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val));
         break;
@@ -1437,11 +1471,15 @@ static uint32_t eepro100_read4(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
         break;
     case SCBPointer:
-        //~ val = eepro100_read_pointer(s);
+#if 0
+        val = eepro100_read_pointer(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
         break;
     case SCBPort:
@@ -1468,7 +1506,9 @@ static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val)
 
     switch (addr) {
     case SCBStatus:
-        //~ eepro100_write_status(s, val);
+#if 0
+        eepro100_write_status(s, val);
+#endif
         break;
     case SCBAck:
         eepro100_acknowledge(s);
@@ -1508,7 +1548,9 @@ static void eepro100_write2(EEPRO100State * s, uint32_t addr, uint16_t val)
 
     switch (addr) {
     case SCBStatus:
-        //~ eepro100_write_status(s, val);
+#if 0
+        eepro100_write_status(s, val);
+#endif
         eepro100_acknowledge(s);
         break;
     case SCBCmd:
@@ -1556,7 +1598,9 @@ static void eepro100_write4(EEPRO100State * s, uint32_t addr, uint32_t val)
 static uint32_t ioport_read1(void *opaque, uint32_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read1(s, addr - s->region[1]);
 }
 
@@ -1575,7 +1619,9 @@ static uint32_t ioport_read4(void *opaque, uint32_t addr)
 static void ioport_write1(void *opaque, uint32_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write1(s, addr - s->region[1], val);
 }
 
@@ -1623,42 +1669,54 @@ static void pci_map(PCIDevice * pci_dev, int region_num,
 static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write1(s, addr, val);
 }
 
 static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write2(s, addr, val);
 }
 
 static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write4(s, addr, val);
 }
 
 static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read1(s, addr);
 }
 
 static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read2(s, addr);
 }
 
 static uint32_t pci_mmio_readl(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read4(s, addr);
 }
 
@@ -1695,7 +1753,9 @@ static int nic_can_receive(VLANClientState *nc)
     EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     TRACE(RXTX, logout("%p\n", s));
     return get_ru_state(s) == ru_ready;
-    //~ return !eepro100_buffer_full(s);
+#if 0
+    return !eepro100_buffer_full(s);
+#endif
 }
 
 static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size)
@@ -1724,13 +1784,15 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
          * Short frame is discarded */
         logout("%p received short frame (%zu byte)\n", s, size);
         s->statistics.rx_short_frame_errors++;
-        //~ return -1;
+#if 0
+        return -1;
+#endif
     } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
         /* Long frame and configuration byte 18/3 (long receive ok) not set:
          * Long frames are discarded. */
         logout("%p received long frame (%zu byte), ignored\n", s, size);
         return -1;
-    } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) {       // !!!
+    } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) {       /* !!! */
         /* Frame matches individual address. */
         /* TODO: check configuration byte 15/4 (ignore U/L). */
         TRACE(RXTX, logout("%p received frame for me, len=%zu\n", s, size));
@@ -1774,11 +1836,12 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         /* TODO: RNR interrupt only at first failed frame? */
         eepro100_rnr_interrupt(s);
         s->statistics.rx_resource_errors++;
-        //~ assert(!"no resources");
+#if 0
+        assert(!"no resources");
+#endif
         return -1;
     }
-    //~ !!!
-//~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}}
+    /* !!! */
     eepro100_rx_t rx;
     cpu_physical_memory_read(s->ru_base + s->ru_offset, (uint8_t *) & rx,
                              offsetof(eepro100_rx_t, packet));
@@ -1799,14 +1862,18 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
              rfd_status);
     stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, count), size);
     /* Early receive interrupt not supported. */
-    //~ eepro100_er_interrupt(s);
+#if 0
+    eepro100_er_interrupt(s);
+#endif
     /* Receive CRC Transfer not supported. */
     if (s->configuration[18] & BIT(2)) {
         missing("Receive CRC Transfer");
         return -1;
     }
     /* TODO: check stripping enable bit. */
-    //~ assert(!(s->configuration[17] & BIT(0)));
+#if 0
+    assert(!(s->configuration[17] & BIT(0)));
+#endif
     cpu_physical_memory_write(s->ru_base + s->ru_offset +
                               offsetof(eepro100_rx_t, packet), buf, size);
     s->statistics.rx_good_frames++;
Signature · 1 line
1.6.6.1
#26 lore raw

PATCH 20/20 eepro100: Keep includes sorted

I always try to keep standard includes sorted
and add a comment why they are there (so they
can be removed when they are no longer needed).

---
 hw/eepro100.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/eepro100.c +1 -1
index 0f5fffa..3bd8bd3 100644
@@ -41,8 +41,8 @@
  *      * Wake-on-LAN is not implemented.
  */
 
+#include <stdbool.h>            /* bool */
 #include <stddef.h>             /* offsetof */
-#include <stdbool.h>
 #include "hw.h"
 #include "pci.h"
 #include "net.h"
Signature · 1 line
1.6.6.1
#27 lore raw

[Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c

In reply to Stefan Weil
Quoted 42 lines · Stefan Weil

All eepro100 devices work with drivers which
only use basic features.

They were tested with gpxe boot.

---
 hw/pci.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
hw/pci.c +12 -0
index eb2043e..1ba3f92 100644
@@ -1436,9 +1436,18 @@ void do_pci_info(Monitor *mon, QObject **ret_data)
 
 static const char * const pci_nic_models[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",
@@ -1448,9 +1457,18 @@ static const char * const pci_nic_models[] = {
 
 static const char * const pci_nic_names[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",

hw/pci.c static const char * const pci_nic_models[] = { · line 1474

Quoted 10 lines
hw/pci.c +6 -0
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",

One wonders: would it be cleaner to have a single eepro100 device with specific model as qdev option?

Signature · 1 line
MST
#28 lore raw

[Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c

Quoted 50 lines · Michael S. Tsirkin
Quoted 48 lines · Stefan Weil

All eepro100 devices work with drivers which
only use basic features.

They were tested with gpxe boot.

---
 hw/pci.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
hw/pci.c +17 -0
index eb2043e..1ba3f92 100644
@@ -1436,9 +1436,18 @@ void do_pci_info(Monitor *mon, QObject **ret_data)
 
 static const char * const pci_nic_models[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",
@@ -1448,9 +1457,18 @@ static const char * const pci_nic_models[] = {
 
 static const char * const pci_nic_names[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
Quoted 8 lines

hw/pci.c void do_pci_info(Monitor *mon, QObject **ret_data) · line 1453

Quoted 5 lines
hw/pci.c +1 -0
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",

One wonders: would it be cleaner to have a single eepro100 device with specific model as qdev option?

Technically that would be possible, too.
You could even have a single pci ethernet device and specify vendor and device id as qdev options.

I prefer the "official" device names which are also used in the Intel documentation. eepro100 or e100 are marketing names (more of them exist).

Please note that this patch was marked as optional. The arrays pci_nic_names and pci_nic_models are not really needed, and as soon as the table of available nics is automatically derived from the device information, all variants of i825xx are supported automatically.

Regards
Stefan Weil

#29 lore raw

[Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c

Quoted 68 lines · Stefan Weil
Quoted 50 lines · Michael S. Tsirkin
Quoted 48 lines · Stefan Weil

All eepro100 devices work with drivers which
only use basic features.

They were tested with gpxe boot.

---
 hw/pci.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
hw/pci.c +17 -0
index eb2043e..1ba3f92 100644
@@ -1436,9 +1436,18 @@ void do_pci_info(Monitor *mon, QObject **ret_data)
 
 static const char * const pci_nic_models[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",
@@ -1448,9 +1457,18 @@ static const char * const pci_nic_models[] = {
 
 static const char * const pci_nic_names[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
Quoted 8 lines

hw/pci.c void do_pci_info(Monitor *mon, QObject **ret_data) · line 1453

Quoted 5 lines
hw/pci.c +1 -0
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",

One wonders: would it be cleaner to have a single eepro100 device with specific model as qdev option?

Technically that would be possible, too.
You could even have a single pci ethernet device and specify vendor and device id as qdev options.

I prefer the "official" device names which are also used in the Intel documentation. eepro100 or e100 are marketing names (more of them exist).

Quoted 8 lines

Please note that this patch was marked as optional. The arrays pci_nic_names and pci_nic_models are not really needed, and as soon as the table of available nics is automatically derived from the device information, all variants of i825xx are supported automatically.

Regards
Stefan Weil

Gerd, any input on this patch?

Signature · 1 line
MST
#30 lore raw

[Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c

Quoted 19 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Weil
Quoted 17 lines
Quoted 17 lines
  static const char * const pci_nic_models[] = {
      "ne2k_pci",
hw/pci.c +9 -0
+    "i82550",
      "i82551",
+    "i82557a",
      "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
      "i82559er",
+    "i82562",
      "rtl8139",
      "e1000",
      "pcnet",
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

One wonders: would it be cleaner to have a single eepro100 device with specific model as qdev option?

No. I think it would be cleaner to use qdev even more. For that specific driver it would make sense to create a private Info struct, i.e. something like this:

E100PCIDeviceInfo {
PCIDeviceInfo pci;
[ model specific stuff such as has_extended_tcb_support here ]
};

Then go

static E100PCIDeviceInfo eepro100_info[] = {
    {
        .pci.qdev.name = "i82550",
        [ usual qdev stuff here ]
        has_extended_tcb_support = 0 | 1;
        [ more e100 device description bits here ]
    },
    [ ... ]
};

Then you can simply zap all the one-liner wrapper functions around nic_init(). nic_init() can get a pointer using something like this:

E100PCIDeviceInfo *einfo = DO_UPCAST(E100PCIDeviceInfo,

         pci.qdev, pci_dev->qdev.info);

and setup the device accordingly.

Quoted 3 lines
Quoted 3 lines

I prefer the "official" device names which are also used in the Intel documentation. eepro100 or e100 are marketing names (more of them exist).

qdev has aliases. You can add .qdev.alias = "eepro100" to one of the variants, then the eepro100 name will work as well.

Adding the marketing name to the .desc test is probably a good idea too because alot of people know the marketing name only.

Quoted 7 lines
Quoted 5 lines

Please note that this patch was marked as optional. The arrays pci_nic_names and pci_nic_models are not really needed, and as soon as the table of available nics is automatically derived from the device information, all variants of i825xx are supported automatically.

Gerd, any input on this patch?

Looks fine to me. When we switch over to walking the list of registered devices instead of having a hard-coded list of pci nic drivers all the eepro100 variants will show up in the list anyway.

cheers,
Gerd

#31 lore raw

[Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c

Quoted 56 lines · Gerd Hoffmann
Quoted 19 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Weil
Quoted 17 lines
Quoted 17 lines
  static const char * const pci_nic_models[] = {
      "ne2k_pci",
hw/pci.c +9 -0
+    "i82550",
      "i82551",
+    "i82557a",
      "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
      "i82559er",
+    "i82562",
      "rtl8139",
      "e1000",
      "pcnet",
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

One wonders: would it be cleaner to have a single eepro100 device with specific model as qdev option?

No. I think it would be cleaner to use qdev even more. For that specific driver it would make sense to create a private Info struct, i.e. something like this:

E100PCIDeviceInfo {
PCIDeviceInfo pci;
[ model specific stuff such as has_extended_tcb_support here ]
};

Then go

static E100PCIDeviceInfo eepro100_info[] = {
    {
        .pci.qdev.name = "i82550",
        [ usual qdev stuff here ]
        has_extended_tcb_support = 0 | 1;
        [ more e100 device description bits here ]
    },
    [ ... ]
};

Then you can simply zap all the one-liner wrapper functions around nic_init(). nic_init() can get a pointer using something like this:

E100PCIDeviceInfo *einfo = DO_UPCAST(E100PCIDeviceInfo,

         pci.qdev, pci_dev->qdev.info);

and setup the device accordingly.

Quoted 3 lines
Quoted 3 lines

I prefer the "official" device names which are also used in the Intel documentation. eepro100 or e100 are marketing names (more of them exist).

Quoted 5 lines

qdev has aliases. You can add .qdev.alias = "eepro100" to one of the variants, then the eepro100 name will work as well.

Adding the marketing name to the .desc test is probably a good idea too because alot of people know the marketing name only.

That's my thinking as well.

Quoted 14 lines
Quoted 7 lines
Quoted 5 lines

Please note that this patch was marked as optional. The arrays pci_nic_names and pci_nic_models are not really needed, and as soon as the table of available nics is automatically derived from the device information, all variants of i825xx are supported automatically.

Gerd, any input on this patch?

Looks fine to me. When we switch over to walking the list of registered devices instead of having a hard-coded list of pci nic drivers all the eepro100 variants will show up in the list anyway.

cheers,
Gerd

Signature · 1 line
MST
#32 lore raw

[Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c

Quoted 43 lines · Michael S. Tsirkin
Quoted 42 lines · Gerd Hoffmann
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Weil
Quoted 17 lines
Quoted 17 lines

static const char * const pci_nic_models[] = {
"ne2k_pci",
+ "i82550",
"i82551",
+ "i82557a",
"i82557b",
+ "i82557c",
+ "i82558a",
+ "i82558b",
+ "i82559a",
+ "i82559b",
+ "i82559c",
"i82559er",
+ "i82562",
"rtl8139",
"e1000",
"pcnet",

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

One wonders: would it be cleaner to have a single eepro100 device with specific model as qdev option?

No. I think it would be cleaner to use qdev even more. For that specific driver it would make sense to create a private Info struct, i.e. something like this:

E100PCIDeviceInfo {
PCIDeviceInfo pci;
[ model specific stuff such as has_extended_tcb_support here ] };

Then go

static E100PCIDeviceInfo eepro100_info[] = {
{
.pci.qdev.name = "i82550",
[ usual qdev stuff here ]
has_extended_tcb_support = 0 | 1;
[ more e100 device description bits here ]
},
[ ... ]
};

Quoted 7 lines
Quoted 7 lines

Then you can simply zap all the one-liner wrapper functions around nic_init(). nic_init() can get a pointer using something like this:

E100PCIDeviceInfo *einfo = DO_UPCAST(E100PCIDeviceInfo, pci.qdev, pci_dev->qdev.info);

and setup the device accordingly.

This would indeed simplify the code.

Although I don't like tricky programming like DO_UPCAST (because I saw too much code where tricky programming was faulty programming), I'll consider to modify the code as Gerd proposed.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

I prefer the "official" device names which are also used in the Intel documentation. eepro100 or e100 are marketing names (more of them exist).

qdev has aliases. You can add .qdev.alias = "eepro100" to one of the variants, then the eepro100 name will work as well.

Good idea. To keep the number of aliases small, I plan to add only one or two aliases: e100 (eepro100 only if a second alias is possible).

Why? e100 is the current linux driver name.
eepro100 was the former linux driver name.

Quoted 5 lines
Quoted 3 lines

Adding the marketing name to the .desc test is probably a good idea too because alot of people know the marketing name only.

That's my thinking as well.

Neither eepro100 nor e100 are marketing names (I was wrong when I wrote that in an earlier mail).

The marketing name was Intel EtherExpress Pro 100. I agree that it would help people to see this name, so I suggest adding it to qemu-doc.texi.

As far as I know, only insiders (and the old linux driver) used the abbreviations eepro100 and e100.

Look at your favorite search machine:
nobody sells / sold eepro100 cards.

If you want a less technical name than i82559c, e100 is the better choice - like e1000 for the successor.

Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

Please note that this patch was marked as optional. The arrays pci_nic_names and pci_nic_models are not really needed, and as soon as the table of available nics is automatically derived from the device information, all variants of i825xx are supported automatically.

Gerd, any input on this patch?

Looks fine to me. When we switch over to walking the list of registered devices instead of having a hard-coded list of pci nic drivers all the eepro100 variants will show up in the list anyway.

cheers,
Gerd

#33 lore raw

Re: [Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c

Quoted 5 lines · Stefan Weil

This would indeed simplify the code.

Although I don't like tricky programming like DO_UPCAST (because I saw too much code where tricky programming was faulty programming),

Yea, when coding C++ in C you need little tricks now and then ;)

You need that in one place only though, nic_init() can store a pointer in EEPRO100State and everybody can take the direct route then ...

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

qdev has aliases. You can add .qdev.alias = "eepro100" to one of the variants, then the eepro100 name will work as well.

Good idea. To keep the number of aliases small, I plan to add only one or two aliases: e100 (eepro100 only if a second alias is possible).

You can have one alias only.

Quoted 1 line

Why? e100 is the current linux driver name.

Reasonable choice, lines up with e1000.

Quoted 1 line

eepro100 was the former linux driver name.

And leaked into a bunch of places (like qemu source code) because of that. Probably only developers recognize the name though.

Quoted 3 lines

The marketing name was Intel EtherExpress Pro 100. I agree that it would help people to see this name, so I suggest adding it to qemu-doc.texi.

Maybe .desc too ?

cheers,
Gerd

#34 lore raw

Re: [Qemu-devel] [PATCH 01/20] eepro100: Fix compiler errors from debug messages

In reply to Stefan Weil
Quoted 7 lines · Stefan Weil

When debug output was enabled (by defining DEBUG_EEPRO100), some debug messages resulted in a compiler error.

This is fixed here.

Michael,

Can you take these through your tree?

Regards,

Anthony Liguori

Quoted 50 lines
---
  hw/eepro100.c |   13 +++++++------
  1 files changed, 7 insertions(+), 6 deletions(-)
hw/eepro100.c +7 -6
index b33dbb8..6580ca8 100644
@@ -56,7 +56,9 @@
  #define KiB 1024
 
  /* Debug EEPRO100 card. */
-//~ #define DEBUG_EEPRO100
+#if 0
+# define DEBUG_EEPRO100
+#endif
 
  #ifdef DEBUG_EEPRO100
  #define logout(fmt, ...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ## __VA_ARGS__)
@@ -874,9 +876,8 @@ static void action_command(EEPRO100State *s)
          cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
          uint16_t status = le16_to_cpu(s->tx.status);
          uint16_t command = le16_to_cpu(s->tx.command);
-        logout
-            ("val=0x%02x (cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-             val, status, command, s->tx.link);
+        logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
+               status, command, s->tx.link);
          bool bit_el = ((command&  0x8000) != 0);
          bool bit_s = ((command&  0x4000) != 0);
          bool bit_i = ((command&  0x2000) != 0);
@@ -891,7 +892,7 @@ static void action_command(EEPRO100State *s)
              break;
          case CmdIASetup:
              cpu_physical_memory_read(s->cb_address + 8,&s->conf.macaddr.a[0], 6);
-            TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6)));
+            TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6)));
              break;
          case CmdConfigure:
              cpu_physical_memory_read(s->cb_address + 8,&s->configuration[0],
@@ -1875,7 +1876,7 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
                             pci_mmio_map);
 
      qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
+    logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6));
      assert(s->region[1] == 0);
 
      nic_reset(s);
#35 lore raw

Re: [Qemu-devel] [PATCH 01/20] eepro100: Fix compiler errors from debug messages

Quoted 9 lines · Anthony Liguori
Quoted 7 lines · Stefan Weil

When debug output was enabled (by defining DEBUG_EEPRO100), some debug messages resulted in a compiler error.

This is fixed here.

Quoted 7 lines

Michael,

Can you take these through your tree?

Regards,

Anthony Liguori

Up to now, I got feedback for 2 of these 20 patches:

[PATCH 05/20] eepro100: Add all supported devices to pci.c
Michael asked whether it would be cleaner to have a single eepro100 device with specific model as qdev option. As long as there are no more opinions on this topic, I suggest to omit this single patch.

[PATCH 11/20] eepro100: Use symbolic names for bits in EEPROM id
Michael had two points: an unused type name and enum members which were written in lower_case instead of UPPER_CASE.

If there are no other open topics, I suggest to commit the patch series as it is (optionally without 05/20). Upper / lower case can be fixed later when this new rule is added to the style guide.

Regards,

Stefan Weil

#36 lore raw

PATCH v3 1/20 eepro100: Fix compiler errors from debug messages

In reply to Stefan Weil

When debug output was enabled (by defining DEBUG_EEPRO100), some debug messages resulted in a compiler error.

This is fixed here.

---
 hw/eepro100.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
hw/eepro100.c +7 -6
index b33dbb8..6580ca8 100644
@@ -56,7 +56,9 @@
 #define KiB 1024
 
 /* Debug EEPRO100 card. */
-//~ #define DEBUG_EEPRO100
+#if 0
+# define DEBUG_EEPRO100
+#endif
 
 #ifdef DEBUG_EEPRO100
 #define logout(fmt, ...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ## __VA_ARGS__)
@@ -874,9 +876,8 @@ static void action_command(EEPRO100State *s)
         cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
         uint16_t status = le16_to_cpu(s->tx.status);
         uint16_t command = le16_to_cpu(s->tx.command);
-        logout
-            ("val=0x%02x (cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-             val, status, command, s->tx.link);
+        logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
+               status, command, s->tx.link);
         bool bit_el = ((command & 0x8000) != 0);
         bool bit_s = ((command & 0x4000) != 0);
         bool bit_i = ((command & 0x2000) != 0);
@@ -891,7 +892,7 @@ static void action_command(EEPRO100State *s)
             break;
         case CmdIASetup:
             cpu_physical_memory_read(s->cb_address + 8, &s->conf.macaddr.a[0], 6);
-            TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6)));
+            TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6)));
             break;
         case CmdConfigure:
             cpu_physical_memory_read(s->cb_address + 8, &s->configuration[0],
@@ -1875,7 +1876,7 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
                            pci_mmio_map);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
+    logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6));
     assert(s->region[1] == 0);
 
     nic_reset(s);
Signature · 1 line
1.7.0
#37 lore raw

[Qemu-devel] Re: [PATCHv3 01/20] eepro100: Fix compiler errors from debug messages

Applied the series except patch 5.
Thanks!

Signature · 1 line
MST
#38 lore raw

PATCH v3 2/20 eepro100: Add missing SCB register names

In reply to Stefan Weil

Some system control block registers were addressed using their offset value. Use symbolic names now and clean the documentation.

---
 hw/eepro100.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
hw/eepro100.c +10 -6
index 6580ca8..124bc49 100644
@@ -125,16 +125,20 @@
 /* Offsets to the various registers.
    All accesses need not be longword aligned. */
 enum speedo_offsets {
-    SCBStatus = 0,
+    SCBStatus = 0,              /* Status Word. */
     SCBAck = 1,
     SCBCmd = 2,                 /* Rx/Command Unit command and status. */
     SCBIntmask = 3,
     SCBPointer = 4,             /* General purpose pointer. */
     SCBPort = 8,                /* Misc. commands and operands.  */
-    SCBflash = 12, SCBeeprom = 14,      /* EEPROM and flash memory control. */
+    SCBflash = 12,              /* Flash memory control. */
+    SCBeeprom = 14,             /* EEPROM control. */
     SCBCtrlMDI = 16,            /* MDI interface control. */
     SCBEarlyRx = 20,            /* Early receive byte count. */
-    SCBFlow = 24,
+    SCBFlow = 24,               /* Flow Control. */
+    SCBpmdr = 27,               /* Power Management Driver. */
+    SCBgctrl = 28,              /* General Control. */
+    SCBgstat = 29,              /* General Status. */
 };
 
 /* A speedo3 transmit buffer descriptor with two buffers... */
@@ -1333,11 +1337,11 @@ static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr)
     case SCBeeprom:
         val = eepro100_read_eeprom(s);
         break;
-    case 0x1b:                 /* PMDR (power management driver register) */
+    case SCBpmdr:       /* Power Management Driver Register */
         val = 0;
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
-    case 0x1d:                 /* general status register */
+    case SCBgstat:      /* General Status Register */
         /* 100 Mbps full duplex, valid link */
         val = 0x07;
         TRACE(OTHER, logout("addr=General Status val=%02x\n", val));
@@ -1431,7 +1435,7 @@ static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val)
     case SCBFlow:       /* does not exist on 82557 */
     case SCBFlow + 1:
     case SCBFlow + 2:
-    case SCBFlow + 3:
+    case SCBpmdr:       /* does not exist on 82557 */
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBeeprom:
Signature · 1 line
1.7.0
#39 lore raw

PATCH v3 3/20 eepro100: Fix PXE boot

In reply to Stefan Weil

The phy handling was wrong for PXE, GPXE boot:
GPXE's eepro100 driver did not detect a valid link.

This is fixed here.

V2 - Use UPPER_CASE for enum values

---
 hw/eepro100.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
hw/eepro100.c +14 -6
index 124bc49..f6764cc 100644
@@ -20,7 +20,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  *
  * Tested features (i82559):
- *      PXE boot (i386) no valid link
+ *      PXE boot (i386) ok
  *      Linux networking (i386) ok
  *
  * Untested:
@@ -33,10 +33,6 @@
  * Open Source Software Developer Manual
  */
 
-#if defined(TARGET_I386)
-# warning "PXE boot still not working!"
-#endif
-
 #include <stddef.h>             /* offsetof */
 #include <stdbool.h>
 #include "hw.h"
@@ -243,6 +239,17 @@ typedef struct {
     bool has_extended_tcb_support;
 } EEPRO100State;
 
+/* Word indices in EEPROM. */
+typedef enum {
+    EEPROM_CNFG_MDIX  = 0x03,
+    EEPROM_ID         = 0x05,
+    EEPROM_PHY_ID     = 0x06,
+    EEPROM_VENDOR_ID  = 0x0c,
+    EEPROM_CONFIG_ASF = 0x0d,
+    EEPROM_DEVICE_ID  = 0x23,
+    EEPROM_SMBUS_ADDR = 0x90,
+} EEPROMOffset;
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
     /* MDI Registers 0 - 6, 7 */
@@ -632,9 +639,10 @@ static void nic_selective_reset(EEPRO100State * s)
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
-    eeprom_contents[0xa] = 0x4000;
+    eeprom_contents[EEPROM_ID] = 0x4000;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
+    eeprom_contents[EEPROM_PHY_ID] = 1;
     uint16_t sum = 0;
     for (i = 0; i < EEPROM_SIZE - 1; i++) {
         sum += eeprom_contents[i];
Signature · 1 line
1.7.0
#40 lore raw

PATCH v3 4/20 eepro100: Support gpxe boot for all eepro100 devices

In reply to Stefan Weil

Only two boot ROM files are needed for all devices.

* Add these GPXE ROM files using new naming convention (as discussed on qemu-devel). Both files were created with http://rom-o-matic.net/, PCI vendor / device ids as in ROM filenames and option BANNER_TIMEOUT = 0.

* Remove old PXE ROM file for i82559er.
It was replaced by gpxe-eepro100-80861209.rom.

* Update pc-bios/README (and sort entries).

Full support still needs additional eepro100 fixes.

---
 hw/eepro100.c                      |   13 ++++++++++++-
 pc-bios/README                     |    4 ++--
 pc-bios/gpxe-eepro100-80861209.rom |  Bin 0 -> 56832 bytes
 pc-bios/gpxe-eepro100-80861229.rom |  Bin 0 -> 56832 bytes
 pc-bios/pxe-i82559er.bin           |  Bin 56832 -> 0 bytes
 5 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 pc-bios/gpxe-eepro100-80861209.rom
 create mode 100644 pc-bios/gpxe-eepro100-80861229.rom
 delete mode 100644 pc-bios/pxe-i82559er.bin
hw/eepro100.c +12 -1
index f6764cc..c072e90 100644
@@ -1975,6 +1975,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82550_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -1984,6 +1985,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82551_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -1993,6 +1995,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557a_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2002,6 +2005,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557b_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2011,6 +2015,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557c_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2020,6 +2025,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558a_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2029,6 +2035,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558b_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2038,6 +2045,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559a_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2047,6 +2055,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559b_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2056,6 +2065,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559c_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861229.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2065,7 +2075,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559er_init,
         .exit      = pci_nic_uninit,
-        .romfile   = "pxe-i82559er.bin",
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
@@ -2075,6 +2085,7 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82562_init,
         .exit      = pci_nic_uninit,
+        .romfile   = "gpxe-eepro100-80861209.rom",
         .qdev.props = (Property[]) {
             DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
             DEFINE_PROP_END_OF_LIST(),
pc-bios/README +2 -2
index ee68723..2fc48ed 100644
@@ -20,10 +20,10 @@
 - The PXE roms come from Rom-o-Matic gPXE 0.9.9 with BANNER_TIMEOUT=0
 
   e1000 8086:100E
-  pcnet32 1022:2000
+  eepro100 8086:1209, 8086:1229
   ns8390 1050:0940
+  pcnet32 1022:2000
   rtl8139 10ec:8139
-  eepro100 8086:1209
   virtio 1af4:1000
 
   http://rom-o-matic.net/
pc-bios/gpxe-eepro100-80861209.rom new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2ca59ec369fa3aa829aa64b80339dc9aaab9026f
GIT binary patch
pc-bios/gpxe-eepro100-80861229.rom new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..9cf397e3de03c4b6441893cf07d9ea63a36a65c8
GIT binary patch
pc-bios/pxe-i82559er.bin deleted binary +0 -0
deleted file mode 100644
index 2ca59ec369fa3aa829aa64b80339dc9aaab9026f..0000000000000000000000000000000000000000
GIT binary patch
Signature · 1 line
1.7.0
#41 lore raw

PATCH v3 5/20 eepro100: Add all supported devices to pci.c

In reply to Stefan Weil

All eepro100 devices work with drivers which
only use basic features.

They were tested with gpxe boot.

---
 hw/pci.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
hw/pci.c +18 -0
index eb2043e..1ba3f92 100644
@@ -1436,9 +1436,18 @@ void do_pci_info(Monitor *mon, QObject **ret_data)
 
 static const char * const pci_nic_models[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",
@@ -1448,9 +1457,18 @@ static const char * const pci_nic_models[] = {
 
 static const char * const pci_nic_names[] = {
     "ne2k_pci",
+    "i82550",
     "i82551",
+    "i82557a",
     "i82557b",
+    "i82557c",
+    "i82558a",
+    "i82558b",
+    "i82559a",
+    "i82559b",
+    "i82559c",
     "i82559er",
+    "i82562",
     "rtl8139",
     "e1000",
     "pcnet",
Signature · 1 line
1.7.0
#42 lore raw

PATCH v3 6/20 eepro100: Add TODO list

In reply to Stefan Weil
---
 hw/eepro100.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
hw/eepro100.c +8 -0
index c072e90..8ee4087 100644
@@ -31,6 +31,14 @@
  *
  * Intel 8255x 10/100 Mbps Ethernet Controller Family
  * Open Source Software Developer Manual
+ *
+ * TODO:
+ *      * PHY emulation should be separated from nic emulation.
+ *        Most nic emulations could share the same phy code.
+ *      * i82550 is untested. It is programmed like the i82559.
+ *      * i82562 is untested. It is programmed like the i82559.
+ *      * Power management (i82558 and later) is not implemented.
+ *      * Wake-on-LAN is not implemented.
  */
 
 #include <stddef.h>             /* offsetof */
Signature · 1 line
1.7.0
#43 lore raw

PATCH v3 7/20 eepro100: Update copyright notice

In reply to Stefan Weil
---
 hw/eepro100.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
hw/eepro100.c +5 -5
index 8ee4087..6c11209 100644
@@ -1,15 +1,15 @@
 /*
  * QEMU i8255x (PRO100) emulation
  *
- * Copyright (c) 2006-2007 Stefan Weil
+ * Copyright (C) 2006-2010 Stefan Weil
  *
  * Portions of the code are copies from grub / etherboot eepro100.c
  * and linux e100.c.
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) version 3 or any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,7 +17,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Tested features (i82559):
  *      PXE boot (i386) ok
Signature · 1 line
1.7.0
#44 lore raw

PATCH v3 8/20 eepro100: Add device descriptions

In reply to Stefan Weil

Add descriptions for all devices.
These descriptions are shown when users call
qemu -device ?

---
 hw/eepro100.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
hw/eepro100.c +12 -0
index 6c11209..d5d3abc 100644
@@ -1980,6 +1980,7 @@ static int pci_i82562_init(PCIDevice *pci_dev)
 static PCIDeviceInfo eepro100_info[] = {
     {
         .qdev.name = "i82550",
+        .qdev.desc = "Intel i82550 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82550_init,
         .exit      = pci_nic_uninit,
@@ -1990,6 +1991,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82551",
+        .qdev.desc = "Intel i82551 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82551_init,
         .exit      = pci_nic_uninit,
@@ -2000,6 +2002,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557a",
+        .qdev.desc = "Intel i82557A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557a_init,
         .exit      = pci_nic_uninit,
@@ -2010,6 +2013,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557b",
+        .qdev.desc = "Intel i82557B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557b_init,
         .exit      = pci_nic_uninit,
@@ -2020,6 +2024,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557c",
+        .qdev.desc = "Intel i82557C Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557c_init,
         .exit      = pci_nic_uninit,
@@ -2030,6 +2035,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82558a",
+        .qdev.desc = "Intel i82558A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558a_init,
         .exit      = pci_nic_uninit,
@@ -2040,6 +2046,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82558b",
+        .qdev.desc = "Intel i82558B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558b_init,
         .exit      = pci_nic_uninit,
@@ -2050,6 +2057,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559a",
+        .qdev.desc = "Intel i82559A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559a_init,
         .exit      = pci_nic_uninit,
@@ -2060,6 +2068,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559b",
+        .qdev.desc = "Intel i82559B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559b_init,
         .exit      = pci_nic_uninit,
@@ -2070,6 +2079,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559c",
+        .qdev.desc = "Intel i82559C Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559c_init,
         .exit      = pci_nic_uninit,
@@ -2080,6 +2090,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559er",
+        .qdev.desc = "Intel i82559ER Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559er_init,
         .exit      = pci_nic_uninit,
@@ -2090,6 +2101,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82562",
+        .qdev.desc = "Intel i82562 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82562_init,
         .exit      = pci_nic_uninit,
Signature · 1 line
1.7.0
#45 lore raw

[Qemu-devel] Re: [PATCHv3 08/20] eepro100: Add device descriptions

Quoted 5 lines · Stefan Weil

Add descriptions for all devices.
These descriptions are shown when users call
qemu -device ?

I still think descriptive names should also mention eepro100.

Quoted 106 lines
---
 hw/eepro100.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
hw/eepro100.c +12 -0
index 6c11209..d5d3abc 100644
@@ -1980,6 +1980,7 @@ static int pci_i82562_init(PCIDevice *pci_dev)
 static PCIDeviceInfo eepro100_info[] = {
     {
         .qdev.name = "i82550",
+        .qdev.desc = "Intel i82550 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82550_init,
         .exit      = pci_nic_uninit,
@@ -1990,6 +1991,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82551",
+        .qdev.desc = "Intel i82551 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82551_init,
         .exit      = pci_nic_uninit,
@@ -2000,6 +2002,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557a",
+        .qdev.desc = "Intel i82557A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557a_init,
         .exit      = pci_nic_uninit,
@@ -2010,6 +2013,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557b",
+        .qdev.desc = "Intel i82557B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557b_init,
         .exit      = pci_nic_uninit,
@@ -2020,6 +2024,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82557c",
+        .qdev.desc = "Intel i82557C Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557c_init,
         .exit      = pci_nic_uninit,
@@ -2030,6 +2035,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82558a",
+        .qdev.desc = "Intel i82558A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558a_init,
         .exit      = pci_nic_uninit,
@@ -2040,6 +2046,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82558b",
+        .qdev.desc = "Intel i82558B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558b_init,
         .exit      = pci_nic_uninit,
@@ -2050,6 +2057,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559a",
+        .qdev.desc = "Intel i82559A Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559a_init,
         .exit      = pci_nic_uninit,
@@ -2060,6 +2068,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559b",
+        .qdev.desc = "Intel i82559B Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559b_init,
         .exit      = pci_nic_uninit,
@@ -2070,6 +2079,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559c",
+        .qdev.desc = "Intel i82559C Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559c_init,
         .exit      = pci_nic_uninit,
@@ -2080,6 +2090,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82559er",
+        .qdev.desc = "Intel i82559ER Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559er_init,
         .exit      = pci_nic_uninit,
@@ -2090,6 +2101,7 @@ static PCIDeviceInfo eepro100_info[] = {
         },
     },{
         .qdev.name = "i82562",
+        .qdev.desc = "Intel i82562 Ethernet",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82562_init,
         .exit      = pci_nic_uninit,
Signature · 1 line
1.7.0
#46 lore raw

PATCH v3 9/20 eepro100: Use symbolic names and BIT macros in binary operations

In reply to Stefan Weil

Instead of magic numbers like 0x8000, symbolic names are used for the SCB command and status bits.

There are too many configuration bits to use symbolic names there, too. Using the BIT macro is a little help when comparing code and documentation.

For the same reason, some other constants were replaced by the BITS macro.

---
 hw/eepro100.c |   52 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 19 deletions(-)
hw/eepro100.c +33 -19
index d5d3abc..a58c640 100644
@@ -172,6 +172,20 @@ typedef struct {
     char packet[MAX_ETH_FRAME_SIZE + 4];
 } eepro100_rx_t;
 
+typedef enum {
+    COMMAND_EL = BIT(15),
+    COMMAND_S = BIT(14),
+    COMMAND_I = BIT(13),
+    COMMAND_NC = BIT(4),
+    COMMAND_SF = BIT(3),
+    COMMAND_CMD = BITS(2, 0),
+} scb_command_bit;
+
+typedef enum {
+    STATUS_C = BIT(15),
+    STATUS_OK = BIT(13),
+} scb_status_bit;
+
 typedef struct {
     uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions,
         tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
@@ -753,22 +767,22 @@ enum commands {
 
 static cu_state_t get_cu_state(EEPRO100State * s)
 {
-    return ((s->mem[SCBStatus] >> 6) & 0x03);
+    return ((s->mem[SCBStatus] & BITS(7, 6)) >> 6);
 }
 
 static void set_cu_state(EEPRO100State * s, cu_state_t state)
 {
-    s->mem[SCBStatus] = (s->mem[SCBStatus] & 0x3f) + (state << 6);
+    s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(7, 6)) + (state << 6);
 }
 
 static ru_state_t get_ru_state(EEPRO100State * s)
 {
-    return ((s->mem[SCBStatus] >> 2) & 0x0f);
+    return ((s->mem[SCBStatus] & BITS(5, 2)) >> 2);
 }
 
 static void set_ru_state(EEPRO100State * s, ru_state_t state)
 {
-    s->mem[SCBStatus] = (s->mem[SCBStatus] & 0xc3) + (state << 2);
+    s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(5, 2)) + (state << 2);
 }
 
 static void dump_statistics(EEPRO100State * s)
@@ -898,13 +912,13 @@ static void action_command(EEPRO100State *s)
         uint16_t command = le16_to_cpu(s->tx.command);
         logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
                status, command, s->tx.link);
-        bool bit_el = ((command & 0x8000) != 0);
-        bool bit_s = ((command & 0x4000) != 0);
-        bool bit_i = ((command & 0x2000) != 0);
-        bool bit_nc = ((command & 0x0010) != 0);
+        bool bit_el = ((command & COMMAND_EL) != 0);
+        bool bit_s = ((command & COMMAND_S) != 0);
+        bool bit_i = ((command & COMMAND_I) != 0);
+        bool bit_nc = ((command & COMMAND_NC) != 0);
         bool success = true;
-        //~ bool bit_sf = ((command & 0x0008) != 0);
-        uint16_t cmd = command & 0x0007;
+        //~ bool bit_sf = ((command & COMMAND_SF) != 0);
+        uint16_t cmd = command & COMMAND_CMD;
         s->cu_offset = le32_to_cpu(s->tx.link);
         switch (cmd) {
         case CmdNOp:
@@ -941,7 +955,7 @@ static void action_command(EEPRO100State *s)
             break;
         }
         /* Write new status. */
-        stw_phys(s->cb_address, status | 0x8000 | (success ? 0x2000 : 0));
+        stw_phys(s->cb_address, status | STATUS_C | (success ? STATUS_OK : 0));
         if (bit_i) {
             /* CU completed action. */
             eepro100_cx_interrupt(s);
@@ -1684,13 +1698,13 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         /* CSMA is disabled. */
         logout("%p received while CSMA is disabled\n", s);
         return -1;
-    } else if (size < 64 && (s->configuration[7] & 1)) {
+    } else if (size < 64 && (s->configuration[7] & BIT(0))) {
         /* Short frame and configuration byte 7/0 (discard short receive) set:
          * Short frame is discarded */
         logout("%p received short frame (%zu byte)\n", s, size);
         s->statistics.rx_short_frame_errors++;
         //~ return -1;
-    } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) {
+    } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
         /* Long frame and configuration byte 18/3 (long receive ok) not set:
          * Long frames are discarded. */
         logout("%p received long frame (%zu byte), ignored\n", s, size);
@@ -1713,7 +1727,7 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
           assert(mcast_idx < 64);
           if (s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))) {
             /* Multicast frame is allowed in hash table. */
-          } else if (s->configuration[15] & 1) {
+          } else if (s->configuration[15] & BIT(0)) {
               /* Promiscuous: receive all. */
               rfd_status |= 0x0004;
           } else {
@@ -1723,7 +1737,7 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         }
         /* TODO: Next not for promiscuous mode? */
         rfd_status |= 0x0002;
-    } else if (s->configuration[15] & 1) {
+    } else if (s->configuration[15] & BIT(0)) {
         /* Promiscuous: receive all. */
         TRACE(RXTX, logout("%p received frame in promiscuous mode, len=%zu\n", s, size));
         rfd_status |= 0x0004;
@@ -1764,23 +1778,23 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
     /* Early receive interrupt not supported. */
     //~ eepro100_er_interrupt(s);
     /* Receive CRC Transfer not supported. */
-    if (s->configuration[18] & 4) {
+    if (s->configuration[18] & BIT(2)) {
         missing("Receive CRC Transfer");
         return -1;
     }
     /* TODO: check stripping enable bit. */
-    //~ assert(!(s->configuration[17] & 1));
+    //~ assert(!(s->configuration[17] & BIT(0)));
     cpu_physical_memory_write(s->ru_base + s->ru_offset +
                               offsetof(eepro100_rx_t, packet), buf, size);
     s->statistics.rx_good_frames++;
     eepro100_fr_interrupt(s);
     s->ru_offset = le32_to_cpu(rx.link);
-    if (rfd_command & 0x8000) {
+    if (rfd_command & COMMAND_EL) {
         /* EL bit is set, so this was the last frame. */
         logout("receive: Running out of frames\n");
         set_ru_state(s, ru_suspended);
     }
-    if (rfd_command & 0x4000) {
+    if (rfd_command & COMMAND_S) {
         /* S bit is set. */
         set_ru_state(s, ru_suspended);
     }
Signature · 1 line
1.7.0
#47 lore raw

PATCH v3 10/20 eepro100: Remove old unused code

In reply to Stefan Weil

This code is no longer needed.

---
 hw/eepro100.c |   18 ------------------
 1 files changed, 0 insertions(+), 18 deletions(-)
hw/eepro100.c +0 -18
index a58c640..c2ff569 100644
@@ -469,24 +469,6 @@ static void pci_reset(EEPRO100State * s)
     PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   // latency timer = 32 clocks
     /* PCI Header Type */
     /* BIST (built-in self test) */
-#if defined(TARGET_I386)
-// !!! workaround for buggy bios
-//~ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0
-#endif
-#if 0
-    /* PCI Base Address Registers */
-    /* CSR Memory Mapped Base Address */
-    PCI_CONFIG_32(PCI_BASE_ADDRESS_0,
-                  PCI_BASE_ADDRESS_SPACE_MEMORY |
-                  PCI_BASE_ADDRESS_MEM_PREFETCH);
-    /* CSR I/O Mapped Base Address */
-    PCI_CONFIG_32(PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_SPACE_IO);
-#if 0
-    /* Flash Memory Mapped Base Address */
-    PCI_CONFIG_32(PCI_BASE_ADDRESS_2,
-                  0xfffe0000 | PCI_BASE_ADDRESS_SPACE_MEMORY);
-#endif
-#endif
     /* Expansion ROM Base Address (depends on boot disable!!!) */
     /* TODO: not needed, set when BAR is registered */
     PCI_CONFIG_32(PCI_ROM_ADDRESS, PCI_BASE_ADDRESS_SPACE_MEMORY);
Signature · 1 line
1.7.0
#48 lore raw

PATCH v3 11/20 eepro100: Use symbolic names for bits in EEPROM id

In reply to Stefan Weil

V2 - Use UPPER_CASE for enum values

---
 hw/eepro100.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
hw/eepro100.c +16 -1
index c2ff569..2a871b8 100644
@@ -272,6 +272,21 @@ typedef enum {
     EEPROM_SMBUS_ADDR = 0x90,
 } EEPROMOffset;
 
+/* Bit values for EEPROM ID word. */
+typedef enum {
+    EEPROM_ID_MDM = BIT(0),     /* Modem */
+    EEPROM_ID_STB = BIT(1),     /* Standby Enable */
+    EEPROM_ID_WMR = BIT(2),     /* ??? */
+    EEPROM_ID_WOL = BIT(5),     /* Wake on LAN */
+    EEPROM_ID_DPD = BIT(6),     /* Deep Power Down */
+    EEPROM_ID_ALT = BIT(7),     /* */
+    /* BITS(10, 8) device revision */
+    EEPROM_ID_BD = BIT(11),     /* boot disable */
+    EEPROM_ID_ID = BIT(13),     /* id bit */
+    /* BITS(15, 14) signature */
+    EEPROM_ID_VALID = BIT(14),  /* signature for valid eeprom */
+} eeprom_id_bit;
+
 /* Default values for MDI (PHY) registers */
 static const uint16_t eepro100_mdi_default[] = {
     /* MDI Registers 0 - 6, 7 */
@@ -643,7 +658,7 @@ static void nic_selective_reset(EEPRO100State * s)
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
-    eeprom_contents[EEPROM_ID] = 0x4000;
+    eeprom_contents[EEPROM_ID] = EEPROM_ID_VALID;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
     eeprom_contents[EEPROM_PHY_ID] = 1;
Signature · 1 line
1.7.0
#49 lore raw

PATCH v3 12/20 eepro100: Replace variable name to fix a compiler warning

In reply to Stefan Weil

When compiling with -Wshadow, gcc gives a warning
which is fixed by renaming stat -> status.

---
 hw/eepro100.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/eepro100.c +6 -6
index 2a871b8..7eaa876 100644
@@ -392,14 +392,14 @@ static void eepro100_acknowledge(EEPRO100State * s)
     }
 }
 
-static void eepro100_interrupt(EEPRO100State * s, uint8_t stat)
+static void eepro100_interrupt(EEPRO100State * s, uint8_t status)
 {
     uint8_t mask = ~s->mem[SCBIntmask];
-    s->mem[SCBAck] |= stat;
-    stat = s->scb_stat = s->mem[SCBAck];
-    stat &= (mask | 0x0f);
-    //~ stat &= (~s->mem[SCBIntmask] | 0x0xf);
-    if (stat && (mask & 0x01)) {
+    s->mem[SCBAck] |= status;
+    status = s->scb_stat = s->mem[SCBAck];
+    status &= (mask | 0x0f);
+    //~ status &= (~s->mem[SCBIntmask] | 0x0xf);
+    if (status && (mask & 0x01)) {
         /* SCB mask and SCB Bit M do not disable interrupt. */
         enable_interrupt(s);
     } else if (s->int_stat) {
Signature · 1 line
1.7.0
#50 lore raw

PATCH v3 13/20 eepro100: Support RNR interrupt

In reply to Stefan Weil

The RNR interrupt is triggered under these conditions:

* the RU is not ready to receive a frame due to missing resources
* the RU is ready and a RU abort command was requested

---
 hw/eepro100.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
hw/eepro100.c +10 -3
index 7eaa876..40d8db5 100644
@@ -120,7 +120,7 @@
 #define  RU_NOP         0x0000
 #define  RX_START       0x0001
 #define  RX_RESUME      0x0002
-#define  RX_ABORT       0x0004
+#define  RU_ABORT       0x0004
 #define  RX_ADDR_LOAD   0x0006
 #define  RX_RESUMENR    0x0007
 #define INT_MASK        0x0100
@@ -426,13 +426,11 @@ static void eepro100_fr_interrupt(EEPRO100State * s)
     eepro100_interrupt(s, 0x40);
 }
 
-#if 0
 static void eepro100_rnr_interrupt(EEPRO100State * s)
 {
     /* RU is not ready. */
     eepro100_interrupt(s, 0x10);
 }
-#endif
 
 static void eepro100_mdi_interrupt(EEPRO100State * s)
 {
@@ -1065,6 +1063,13 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         }
         set_ru_state(s, ru_ready);
         break;
+    case RU_ABORT:
+        /* RU abort. */
+        if (get_ru_state(s) == ru_ready) {
+            eepro100_rnr_interrupt(s);
+        }
+        set_ru_state(s, ru_idle);
+        break;
     case RX_ADDR_LOAD:
         /* Load RU base. */
         TRACE(OTHER, logout("val=0x%02x (RU base address)\n", val));
@@ -1747,6 +1752,8 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
     if (get_ru_state(s) != ru_ready) {
         /* No resources available. */
         logout("no resources, state=%u\n", get_ru_state(s));
+        /* TODO: RNR interrupt only at first failed frame? */
+        eepro100_rnr_interrupt(s);
         s->statistics.rx_resource_errors++;
         //~ assert(!"no resources");
         return -1;
Signature · 1 line
1.7.0
#51 lore raw

PATCH v3 14/20 eepro100: Fix CU Start command

In reply to Stefan Weil

CU Start is allowed when the CU is in the idle or suspended state.

---
 hw/eepro100.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/eepro100.c +6 -6
index 40d8db5..a9bf7a0 100644
@@ -976,17 +976,17 @@ static void action_command(EEPRO100State *s)
 
 static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
 {
+    cu_state_t cu_state;
     switch (val) {
     case CU_NOP:
         /* No operation. */
         break;
     case CU_START:
-        if (get_cu_state(s) != cu_idle) {
-            /* Intel documentation says that CU must be idle for the CU
-             * start command. Intel driver for Linux also starts the CU
-             * from suspended state. */
-            logout("CU state is %u, should be %u\n", get_cu_state(s), cu_idle);
-            //~ assert(!"wrong CU state");
+        cu_state = get_cu_state(s);
+        if (cu_state != cu_idle && cu_state != cu_suspended) {
+            /* Intel documentation says that CU must be idle or suspended
+             * for the CU start command. */
+            logout("unexpected CU state is %u\n", cu_state);
         }
         set_cu_state(s, cu_active);
         s->cu_offset = s->pointer;
Signature · 1 line
1.7.0
#52 lore raw

PATCH v3 15/20 eepro100: Prettify code (no functional changes)

In reply to Stefan Weil

* Fix indentation.

---
 hw/eepro100.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
hw/eepro100.c +4 -4
index a9bf7a0..cf4e0ac 100644
@@ -188,11 +188,11 @@ typedef enum {
 
 typedef struct {
     uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions,
-        tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
-        tx_multiple_collisions, tx_total_collisions;
+             tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
+             tx_multiple_collisions, tx_total_collisions;
     uint32_t rx_good_frames, rx_crc_errors, rx_alignment_errors,
-        rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
-        rx_short_frame_errors;
+             rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
+             rx_short_frame_errors;
     uint32_t fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported;
     uint16_t xmt_tco_frames, rcv_tco_frames;
     /* TODO: i82559 has six reserved statistics but a total of 24 dwords. */
Signature · 1 line
1.7.0
#53 lore raw

PATCH v3 16/20 eepro100: Use tx.status

In reply to Stefan Weil

There is no need for a local variable "status".
Using tx.status makes it clearer which status
is addressed.

---
 hw/eepro100.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/eepro100.c +3 -3
index cf4e0ac..f5aa306 100644
@@ -903,10 +903,10 @@ static void action_command(EEPRO100State *s)
     for (;;) {
         s->cb_address = s->cu_base + s->cu_offset;
         cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
-        uint16_t status = le16_to_cpu(s->tx.status);
         uint16_t command = le16_to_cpu(s->tx.command);
+        s->tx.status = le16_to_cpu(s->tx.status);
         logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-               status, command, s->tx.link);
+               s->tx.status, command, s->tx.link);
         bool bit_el = ((command & COMMAND_EL) != 0);
         bool bit_s = ((command & COMMAND_S) != 0);
         bool bit_i = ((command & COMMAND_I) != 0);
@@ -950,7 +950,7 @@ static void action_command(EEPRO100State *s)
             break;
         }
         /* Write new status. */
-        stw_phys(s->cb_address, status | STATUS_C | (success ? STATUS_OK : 0));
+        stw_phys(s->cb_address, s->tx.status | STATUS_C | (success ? STATUS_OK : 0));
         if (bit_i) {
             /* CU completed action. */
             eepro100_cx_interrupt(s);
Signature · 1 line
1.7.0
#54 lore raw

PATCH v3 17/20 eepro100: New function for reading command block

In reply to Stefan Weil

Move code which reads the command block to the new function read_cb. The patch also fixes some endianess issues related to the command block and moves declarations of local variables to the beginning of the block.

---
 hw/eepro100.c |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)
hw/eepro100.c +28 -14
index f5aa306..e10ce62 100644
@@ -798,6 +798,16 @@ static void dump_statistics(EEPRO100State * s)
     //~ missing("CU dump statistical counters");
 }
 
+static void read_cb(EEPRO100State *s)
+{
+    cpu_physical_memory_read(s->cb_address, (uint8_t *) &s->tx, sizeof(s->tx));
+    s->tx.status = le16_to_cpu(s->tx.status);
+    s->tx.command = le16_to_cpu(s->tx.command);
+    s->tx.link = le32_to_cpu(s->tx.link);
+    s->tx.tbd_array_addr = le32_to_cpu(s->tx.tbd_array_addr);
+    s->tx.tcb_bytes = le16_to_cpu(s->tx.tcb_bytes);
+}
+
 static void tx_command(EEPRO100State *s)
 {
     uint32_t tbd_array = le32_to_cpu(s->tx.tbd_array_addr);
@@ -901,21 +911,25 @@ static void set_multicast_list(EEPRO100State *s)
 static void action_command(EEPRO100State *s)
 {
     for (;;) {
-        s->cb_address = s->cu_base + s->cu_offset;
-        cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
-        uint16_t command = le16_to_cpu(s->tx.command);
-        s->tx.status = le16_to_cpu(s->tx.status);
-        logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-               s->tx.status, command, s->tx.link);
-        bool bit_el = ((command & COMMAND_EL) != 0);
-        bool bit_s = ((command & COMMAND_S) != 0);
-        bool bit_i = ((command & COMMAND_I) != 0);
-        bool bit_nc = ((command & COMMAND_NC) != 0);
+        bool bit_el;
+        bool bit_s;
+        bool bit_i;
+        bool bit_nc;
         bool success = true;
-        //~ bool bit_sf = ((command & COMMAND_SF) != 0);
-        uint16_t cmd = command & COMMAND_CMD;
-        s->cu_offset = le32_to_cpu(s->tx.link);
-        switch (cmd) {
+        s->cb_address = s->cu_base + s->cu_offset;
+        read_cb(s);
+        bit_el = ((s->tx.command & COMMAND_EL) != 0);
+        bit_s = ((s->tx.command & COMMAND_S) != 0);
+        bit_i = ((s->tx.command & COMMAND_I) != 0);
+        bit_nc = ((s->tx.command & COMMAND_NC) != 0);
+#if 0
+        bool bit_sf = ((s->tx.command & COMMAND_SF) != 0);
+#endif
+        s->cu_offset = s->tx.link;
+        TRACE(OTHER,
+              logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
+                     s->tx.status, s->tx.command, s->tx.link));
+        switch (s->tx.command & COMMAND_CMD) {
         case CmdNOp:
             /* Do nothing. */
             break;
Signature · 1 line
1.7.0
#55 lore raw

[Qemu-devel] Re: [PATCHv3 17/20] eepro100: New function for reading command block

Quoted 51 lines · Stefan Weil

Move code which reads the command block to the new function read_cb. The patch also fixes some endianess issues related to the command block and moves declarations of local variables to the beginning of the block.

---
 hw/eepro100.c |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)
hw/eepro100.c +14 -10
index f5aa306..e10ce62 100644
@@ -798,6 +798,16 @@ static void dump_statistics(EEPRO100State * s)
     //~ missing("CU dump statistical counters");
 }
 
+static void read_cb(EEPRO100State *s)
+{
+    cpu_physical_memory_read(s->cb_address, (uint8_t *) &s->tx, sizeof(s->tx));
+    s->tx.status = le16_to_cpu(s->tx.status);
+    s->tx.command = le16_to_cpu(s->tx.command);
+    s->tx.link = le32_to_cpu(s->tx.link);
+    s->tx.tbd_array_addr = le32_to_cpu(s->tx.tbd_array_addr);
+    s->tx.tcb_bytes = le16_to_cpu(s->tx.tcb_bytes);
+}
+
 static void tx_command(EEPRO100State *s)
 {
     uint32_t tbd_array = le32_to_cpu(s->tx.tbd_array_addr);
@@ -901,21 +911,25 @@ static void set_multicast_list(EEPRO100State *s)
 static void action_command(EEPRO100State *s)
 {
     for (;;) {
-        s->cb_address = s->cu_base + s->cu_offset;
-        cpu_physical_memory_read(s->cb_address, (uint8_t *)&s->tx, sizeof(s->tx));
-        uint16_t command = le16_to_cpu(s->tx.command);
-        s->tx.status = le16_to_cpu(s->tx.status);
-        logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
-               s->tx.status, command, s->tx.link);
-        bool bit_el = ((command & COMMAND_EL) != 0);
-        bool bit_s = ((command & COMMAND_S) != 0);
-        bool bit_i = ((command & COMMAND_I) != 0);
-        bool bit_nc = ((command & COMMAND_NC) != 0);
+        bool bit_el;
+        bool bit_s;
+        bool bit_i;
+        bool bit_nc;
         bool success = true;

hw/eepro100.c static void set_multicast_list(EEPRO100State *s) · line 924

Quoted 10 lines
hw/eepro100.c +6 -4
-        //~ bool bit_sf = ((command & COMMAND_SF) != 0);
-        uint16_t cmd = command & COMMAND_CMD;
-        s->cu_offset = le32_to_cpu(s->tx.link);
-        switch (cmd) {
+        s->cb_address = s->cu_base + s->cu_offset;
+        read_cb(s);
+        bit_el = ((s->tx.command & COMMAND_EL) != 0);
+        bit_s = ((s->tx.command & COMMAND_S) != 0);
+        bit_i = ((s->tx.command & COMMAND_I) != 0);
+        bit_nc = ((s->tx.command & COMMAND_NC) != 0);

() is never needed around the assigned value. this can be fixed separately though. AFAIK you also do not need != : values are coersed by assignment to bool correctly.
Again, can be fixed separately.

hw/eepro100.c static void set_multicast_list(EEPRO100State *s) · line 927

Quoted 3 lines
hw/eepro100.c +3 -0
+#if 0
+        bool bit_sf = ((s->tx.command & COMMAND_SF) != 0);
+#endif

Is the above likely to be useful?

Quoted 10 lines
hw/eepro100.c +5 -0
+        s->cu_offset = s->tx.link;
+        TRACE(OTHER,
+              logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
+                     s->tx.status, s->tx.command, s->tx.link));
+        switch (s->tx.command & COMMAND_CMD) {
         case CmdNOp:
             /* Do nothing. */
             break;
Signature · 1 line
1.7.0
#56 lore raw

PATCH v3 18/20 eepro100: Add diagnose command

In reply to Stefan Weil

Real hardware would run an internal self-test.
The emulation just returns a passed status.

Original patch was from Reimar Döffinger, thanks.

---
 hw/eepro100.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/eepro100.c +5 -0
index e10ce62..0f07b70 100644
@@ -958,6 +958,11 @@ static void action_command(EEPRO100State *s)
             /* Starting with offset 8, the command contains
              * 64 dwords microcode which we just ignore here. */
             break;
+        case CmdDiagnose:
+            TRACE(OTHER, logout("diagnose\n"));
+            /* Make sure error flag is not set. */
+            s->tx.status = 0;
+            break;
         default:
             missing("undefined command");
             success = false;
Signature · 1 line
1.7.0
#57 lore raw

PATCH v3 19/20 eepro100: Remove C++ comments

In reply to Stefan Weil

C++ comments are unwanted, so this is fixed here.

* Replace C++ comments by C comments.
* Put code which was deactivated by a C++ comment in #if 0...#endif.

---
 hw/eepro100.c |  185 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 126 insertions(+), 59 deletions(-)
hw/eepro100.c +126 -59
index 0f07b70..43a9060 100644
@@ -154,11 +154,13 @@ typedef struct {
     uint16_t tcb_bytes;         /* transmit command block byte count (in lower 14 bits */
     uint8_t tx_threshold;       /* transmit threshold */
     uint8_t tbd_count;          /* TBD number */
-    //~ /* This constitutes two "TBD" entries: hdr and data */
-    //~ uint32_t tx_buf_addr0;  /* void *, header of frame to be transmitted.  */
-    //~ int32_t  tx_buf_size0;  /* Length of Tx hdr. */
-    //~ uint32_t tx_buf_addr1;  /* void *, data to be transmitted.  */
-    //~ int32_t  tx_buf_size1;  /* Length of Tx data. */
+#if 0
+    /* This constitutes two "TBD" entries: hdr and data */
+    uint32_t tx_buf_addr0;  /* void *, header of frame to be transmitted.  */
+    int32_t  tx_buf_size0;  /* Length of Tx hdr. */
+    uint32_t tx_buf_addr1;  /* void *, data to be transmitted.  */
+    int32_t  tx_buf_size1;  /* Length of Tx data. */
+#endif
 } eepro100_tx_t;
 
 /* Receive frame descriptor. */
@@ -398,7 +400,9 @@ static void eepro100_interrupt(EEPRO100State * s, uint8_t status)
     s->mem[SCBAck] |= status;
     status = s->scb_stat = s->mem[SCBAck];
     status &= (mask | 0x0f);
-    //~ status &= (~s->mem[SCBIntmask] | 0x0xf);
+#if 0
+    status &= (~s->mem[SCBIntmask] | 0x0xf);
+#endif
     if (status && (mask & 0x01)) {
         /* SCB mask and SCB Bit M do not disable interrupt. */
         enable_interrupt(s);
@@ -477,9 +481,11 @@ static void pci_reset(EEPRO100State * s)
     pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
     /* PCI Cache Line Size */
     /* check cache line size!!! */
-    //~ PCI_CONFIG_8(0x0c, 0x00);
+#if 0
+    PCI_CONFIG_8(0x0c, 0x00);
+#endif
     /* PCI Latency Timer */
-    PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   // latency timer = 32 clocks
+    PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   /* latency timer = 32 clocks */
     /* PCI Header Type */
     /* BIST (built-in self test) */
     /* Expansion ROM Base Address (depends on boot disable!!!) */
@@ -492,7 +498,7 @@ static void pci_reset(EEPRO100State * s)
     /* Interrupt Line */
     /* Interrupt Pin */
     /* TODO: RST# value should be 0 */
-    PCI_CONFIG_8(PCI_INTERRUPT_PIN, 1);      // interrupt pin 0
+    PCI_CONFIG_8(PCI_INTERRUPT_PIN, 1);      /* interrupt pin 0 */
     /* Minimum Grant */
     PCI_CONFIG_8(PCI_MIN_GNT, 0x08);
     /* Maximum Latency */
@@ -500,20 +506,20 @@ static void pci_reset(EEPRO100State * s)
 
     switch (device) {
     case i82550:
-        // TODO: check device id.
+        /* TODO: check device id. */
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* Revision ID: 0x0c, 0x0d, 0x0e. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
-        // TODO: check size of statistical counters.
+        /* TODO: check size of statistical counters. */
         s->stats_size = 80;
-        // TODO: check extended tcb support.
+        /* TODO: check extended tcb support. */
         s->has_extended_tcb_support = 1;
         break;
     case i82551:
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* Revision ID: 0x0f, 0x10. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0f);
-        // TODO: check size of statistical counters.
+        /* TODO: check size of statistical counters. */
         s->stats_size = 80;
         s->has_extended_tcb_support = 1;
         break;
@@ -572,7 +578,7 @@ static void pci_reset(EEPRO100State * s)
         PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
                                   PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
         PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
-        // TODO: Windows wants revision id 0x0c.
+        /* TODO: Windows wants revision id 0x0c. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0c);
 #if EEPROM_SIZE > 0
         PCI_CONFIG_16(PCI_SUBSYSTEM_VENDOR_ID, 0x8086);
@@ -590,7 +596,7 @@ static void pci_reset(EEPRO100State * s)
         s->has_extended_tcb_support = 1;
         break;
     case i82562:
-        // TODO: check device id.
+        /* TODO: check device id. */
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* TODO: wrong revision id. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
@@ -637,14 +643,16 @@ static void pci_reset(EEPRO100State * s)
 
 #if EEPROM_SIZE > 0
     if (device == i82557C || device == i82558B || device == i82559C) {
-        // TODO: get vendor id from EEPROM for i82557C or later.
-        // TODO: get device id from EEPROM for i82557C or later.
-        // TODO: status bit 4 can be disabled by EEPROM for i82558, i82559.
-        // TODO: header type is determined by EEPROM for i82559.
-        // TODO: get subsystem id from EEPROM for i82557C or later.
-        // TODO: get subsystem vendor id from EEPROM for i82557C or later.
-        // TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later.
-        // TODO: capability pointer depends on EEPROM for i82558.
+        /*
+        TODO: get vendor id from EEPROM for i82557C or later.
+        TODO: get device id from EEPROM for i82557C or later.
+        TODO: status bit 4 can be disabled by EEPROM for i82558, i82559.
+        TODO: header type is determined by EEPROM for i82559.
+        TODO: get subsystem id from EEPROM for i82557C or later.
+        TODO: get subsystem vendor id from EEPROM for i82557C or later.
+        TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later.
+        TODO: capability pointer depends on EEPROM for i82558.
+        */
         logout("Get device id and revision from EEPROM!!!\n");
     }
 #endif /* EEPROM_SIZE > 0 */
@@ -654,7 +662,9 @@ static void nic_selective_reset(EEPRO100State * s)
 {
     size_t i;
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
-    //~ eeprom93xx_reset(s->eeprom);
+#if 0
+    eeprom93xx_reset(s->eeprom);
+#endif
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
     eeprom_contents[EEPROM_ID] = EEPROM_ID_VALID;
     if (s->device == i82557B || s->device == i82557C)
@@ -738,7 +748,7 @@ static void eepro100_write_status(EEPRO100State * s, uint16_t val)
 static uint16_t eepro100_read_command(EEPRO100State * s)
 {
     uint16_t val = 0xffff;
-    //~ TRACE(OTHER, logout("val=0x%04x\n", val));
+    TRACE(OTHER, logout("val=0x%04x\n", val));
     return val;
 }
 #endif
@@ -793,9 +803,11 @@ static void dump_statistics(EEPRO100State * s)
     stl_le_phys(s->statsaddr + 36, s->statistics.rx_good_frames);
     stl_le_phys(s->statsaddr + 48, s->statistics.rx_resource_errors);
     stl_le_phys(s->statsaddr + 60, s->statistics.rx_short_frame_errors);
-    //~ stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
-    //~ stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
-    //~ missing("CU dump statistical counters");
+#if 0
+    stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
+    stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
+    missing("CU dump statistical counters");
+#endif
 }
 
 static void read_cb(EEPRO100State *s)
@@ -832,7 +844,9 @@ static void tx_command(EEPRO100State *s)
     while (size < tcb_bytes) {
         uint32_t tx_buffer_address = ldl_phys(tbd_address);
         uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
-        //~ uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
+#if 0
+        uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
+#endif
         tbd_address += 8;
         TRACE(RXTX, logout
             ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n",
@@ -889,7 +903,9 @@ static void tx_command(EEPRO100State *s)
     s->statistics.tx_good_frames++;
     /* Transmit with bad status would raise an CX/TNO interrupt.
      * (82557 only). Emulation never has bad status. */
-    //~ eepro100_cx_interrupt(s);
+#if 0
+    eepro100_cx_interrupt(s);
+#endif
 }
 
 static void set_multicast_list(EEPRO100State *s)
@@ -1016,7 +1032,9 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
             logout("bad CU resume from CU state %u\n", get_cu_state(s));
             /* Workaround for bad Linux eepro100 driver which resumes
              * from idle state. */
-            //~ missing("cu resume");
+#if 0
+            missing("cu resume");
+#endif
             set_cu_state(s, cu_suspended);
         }
         if (get_cu_state(s) == cu_suspended) {
@@ -1067,7 +1085,9 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         /* RU start. */
         if (get_ru_state(s) != ru_idle) {
             logout("RU state is %u, should be %u\n", get_ru_state(s), ru_idle);
-            //~ assert(!"wrong RU state");
+#if 0
+            assert(!"wrong RU state");
+#endif
         }
         set_ru_state(s, ru_ready);
         s->ru_offset = s->pointer;
@@ -1078,7 +1098,9 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         if (get_ru_state(s) != ru_suspended) {
             logout("RU state is %u, should be %u\n", get_ru_state(s),
                    ru_suspended);
-            //~ assert(!"wrong RU state");
+#if 0
+            assert(!"wrong RU state");
+#endif
         }
         set_ru_state(s, ru_ready);
         break;
@@ -1140,7 +1162,9 @@ static void eepro100_write_eeprom(eeprom_t * eeprom, uint8_t val)
     TRACE(EEPROM, logout("val=0x%02x\n", val));
 
     /* mask unwriteable bits */
-    //~ val = SET_MASKED(val, 0x31, eeprom->value);
+#if 0
+    val = SET_MASKED(val, 0x31, eeprom->value);
+#endif
 
     int eecs = ((val & EEPROM_CS) != 0);
     int eesk = ((val & EEPROM_SK) != 0);
@@ -1222,7 +1246,9 @@ static void eepro100_write_mdi(EEPRO100State * s, uint32_t val)
           val, raiseint, mdi_op_name[opcode], phy, reg2name(reg), data));
     if (phy != 1) {
         /* Unsupported PHY address. */
-        //~ logout("phy must be 1 but is %u\n", phy);
+#if 0
+        logout("phy must be 1 but is %u\n", phy);
+#endif
         data = 0;
     } else if (opcode != 1 && opcode != 2) {
         /* Unsupported opcode. */
@@ -1368,16 +1394,22 @@ static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBAck:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBCmd:
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
-        //~ val = eepro100_read_command(s);
+#if 0
+        val = eepro100_read_command(s);
+#endif
         break;
     case SCBIntmask:
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
@@ -1413,7 +1445,9 @@ static uint16_t eepro100_read2(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
     case SCBCmd:
         TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val));
         break;
@@ -1437,11 +1471,15 @@ static uint32_t eepro100_read4(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
         break;
     case SCBPointer:
-        //~ val = eepro100_read_pointer(s);
+#if 0
+        val = eepro100_read_pointer(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
         break;
     case SCBPort:
@@ -1468,7 +1506,9 @@ static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val)
 
     switch (addr) {
     case SCBStatus:
-        //~ eepro100_write_status(s, val);
+#if 0
+        eepro100_write_status(s, val);
+#endif
         break;
     case SCBAck:
         eepro100_acknowledge(s);
@@ -1508,7 +1548,9 @@ static void eepro100_write2(EEPRO100State * s, uint32_t addr, uint16_t val)
 
     switch (addr) {
     case SCBStatus:
-        //~ eepro100_write_status(s, val);
+#if 0
+        eepro100_write_status(s, val);
+#endif
         eepro100_acknowledge(s);
         break;
     case SCBCmd:
@@ -1556,7 +1598,9 @@ static void eepro100_write4(EEPRO100State * s, uint32_t addr, uint32_t val)
 static uint32_t ioport_read1(void *opaque, uint32_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read1(s, addr - s->region[1]);
 }
 
@@ -1575,7 +1619,9 @@ static uint32_t ioport_read4(void *opaque, uint32_t addr)
 static void ioport_write1(void *opaque, uint32_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write1(s, addr - s->region[1], val);
 }
 
@@ -1623,42 +1669,54 @@ static void pci_map(PCIDevice * pci_dev, int region_num,
 static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write1(s, addr, val);
 }
 
 static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write2(s, addr, val);
 }
 
 static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write4(s, addr, val);
 }
 
 static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read1(s, addr);
 }
 
 static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read2(s, addr);
 }
 
 static uint32_t pci_mmio_readl(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read4(s, addr);
 }
 
@@ -1695,7 +1753,9 @@ static int nic_can_receive(VLANClientState *nc)
     EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     TRACE(RXTX, logout("%p\n", s));
     return get_ru_state(s) == ru_ready;
-    //~ return !eepro100_buffer_full(s);
+#if 0
+    return !eepro100_buffer_full(s);
+#endif
 }
 
 static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size)
@@ -1724,13 +1784,15 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
          * Short frame is discarded */
         logout("%p received short frame (%zu byte)\n", s, size);
         s->statistics.rx_short_frame_errors++;
-        //~ return -1;
+#if 0
+        return -1;
+#endif
     } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
         /* Long frame and configuration byte 18/3 (long receive ok) not set:
          * Long frames are discarded. */
         logout("%p received long frame (%zu byte), ignored\n", s, size);
         return -1;
-    } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) {       // !!!
+    } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) {       /* !!! */
         /* Frame matches individual address. */
         /* TODO: check configuration byte 15/4 (ignore U/L). */
         TRACE(RXTX, logout("%p received frame for me, len=%zu\n", s, size));
@@ -1774,11 +1836,12 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         /* TODO: RNR interrupt only at first failed frame? */
         eepro100_rnr_interrupt(s);
         s->statistics.rx_resource_errors++;
-        //~ assert(!"no resources");
+#if 0
+        assert(!"no resources");
+#endif
         return -1;
     }
-    //~ !!!
-//~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}}
+    /* !!! */
     eepro100_rx_t rx;
     cpu_physical_memory_read(s->ru_base + s->ru_offset, (uint8_t *) & rx,
                              offsetof(eepro100_rx_t, packet));
@@ -1799,14 +1862,18 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
              rfd_status);
     stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, count), size);
     /* Early receive interrupt not supported. */
-    //~ eepro100_er_interrupt(s);
+#if 0
+    eepro100_er_interrupt(s);
+#endif
     /* Receive CRC Transfer not supported. */
     if (s->configuration[18] & BIT(2)) {
         missing("Receive CRC Transfer");
         return -1;
     }
     /* TODO: check stripping enable bit. */
-    //~ assert(!(s->configuration[17] & BIT(0)));
+#if 0
+    assert(!(s->configuration[17] & BIT(0)));
+#endif
     cpu_physical_memory_write(s->ru_base + s->ru_offset +
                               offsetof(eepro100_rx_t, packet), buf, size);
     s->statistics.rx_good_frames++;
Signature · 1 line
1.7.0
#58 lore raw

[Qemu-devel] Re: [PATCHv3 19/20] eepro100: Remove C++ comments

Quoted 6 lines · Stefan Weil

C++ comments are unwanted, so this is fixed here.

* Replace C++ comments by C comments.
* Put code which was deactivated by a C++ comment in #if 0...#endif.

It would be nice to add some documentation to commented blocks, explaining why we still keep them around and what happens if they are uncommented.

Quoted 14 lines
---
 hw/eepro100.c |  185 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 126 insertions(+), 59 deletions(-)
hw/eepro100.c +0 -2
index 0f07b70..43a9060 100644
@@ -154,11 +154,13 @@ typedef struct {
     uint16_t tcb_bytes;         /* transmit command block byte count (in lower 14 bits */
     uint8_t tx_threshold;       /* transmit threshold */
     uint8_t tbd_count;          /* TBD number */
-    //~ /* This constitutes two "TBD" entries: hdr and data */
-    //~ uint32_t tx_buf_addr0;  /* void *, header of frame to be transmitted.  */

hw/eepro100.c typedef struct { · line 163

Quoted 10 lines
hw/eepro100.c +7 -3
-    //~ int32_t  tx_buf_size0;  /* Length of Tx hdr. */
-    //~ uint32_t tx_buf_addr1;  /* void *, data to be transmitted.  */
-    //~ int32_t  tx_buf_size1;  /* Length of Tx data. */
+#if 0
+    /* This constitutes two "TBD" entries: hdr and data */
+    uint32_t tx_buf_addr0;  /* void *, header of frame to be transmitted.  */
+    int32_t  tx_buf_size0;  /* Length of Tx hdr. */
+    uint32_t tx_buf_addr1;  /* void *, data to be transmitted.  */
+    int32_t  tx_buf_size1;  /* Length of Tx data. */
+#endif

Is it likely we'll uncomment this at some point? I note that you now use sizeof this structure: will adding these fields break anything?

Quoted 15 lines
hw/eepro100.c +3 -1
 } eepro100_tx_t;
 
 /* Receive frame descriptor. */
@@ -398,7 +400,9 @@ static void eepro100_interrupt(EEPRO100State * s, uint8_t status)
     s->mem[SCBAck] |= status;
     status = s->scb_stat = s->mem[SCBAck];
     status &= (mask | 0x0f);
-    //~ status &= (~s->mem[SCBIntmask] | 0x0xf);
+#if 0
+    status &= (~s->mem[SCBIntmask] | 0x0xf);
+#endif
     if (status && (mask & 0x01)) {
         /* SCB mask and SCB Bit M do not disable interrupt. */
         enable_interrupt(s);

hw/eepro100.c static void pci_reset(EEPRO100State * s) · line 486

Quoted 7 lines
hw/eepro100.c +3 -1
@@ -477,9 +481,11 @@ static void pci_reset(EEPRO100State * s)
     pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
     /* PCI Cache Line Size */
     /* check cache line size!!! */
-    //~ PCI_CONFIG_8(0x0c, 0x00);
+#if 0
+    PCI_CONFIG_8(0x0c, 0x00);
+#endif

It's safe to kill the above, 0 is the default anyway.

Quoted 423 lines
hw/eepro100.c +113 -52
     /* PCI Latency Timer */
-    PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   // latency timer = 32 clocks
+    PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20);   /* latency timer = 32 clocks */
     /* PCI Header Type */
     /* BIST (built-in self test) */
     /* Expansion ROM Base Address (depends on boot disable!!!) */
@@ -492,7 +498,7 @@ static void pci_reset(EEPRO100State * s)
     /* Interrupt Line */
     /* Interrupt Pin */
     /* TODO: RST# value should be 0 */
-    PCI_CONFIG_8(PCI_INTERRUPT_PIN, 1);      // interrupt pin 0
+    PCI_CONFIG_8(PCI_INTERRUPT_PIN, 1);      /* interrupt pin 0 */
     /* Minimum Grant */
     PCI_CONFIG_8(PCI_MIN_GNT, 0x08);
     /* Maximum Latency */
@@ -500,20 +506,20 @@ static void pci_reset(EEPRO100State * s)
 
     switch (device) {
     case i82550:
-        // TODO: check device id.
+        /* TODO: check device id. */
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* Revision ID: 0x0c, 0x0d, 0x0e. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
-        // TODO: check size of statistical counters.
+        /* TODO: check size of statistical counters. */
         s->stats_size = 80;
-        // TODO: check extended tcb support.
+        /* TODO: check extended tcb support. */
         s->has_extended_tcb_support = 1;
         break;
     case i82551:
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* Revision ID: 0x0f, 0x10. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0f);
-        // TODO: check size of statistical counters.
+        /* TODO: check size of statistical counters. */
         s->stats_size = 80;
         s->has_extended_tcb_support = 1;
         break;
@@ -572,7 +578,7 @@ static void pci_reset(EEPRO100State * s)
         PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
                                   PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
         PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
-        // TODO: Windows wants revision id 0x0c.
+        /* TODO: Windows wants revision id 0x0c. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0c);
 #if EEPROM_SIZE > 0
         PCI_CONFIG_16(PCI_SUBSYSTEM_VENDOR_ID, 0x8086);
@@ -590,7 +596,7 @@ static void pci_reset(EEPRO100State * s)
         s->has_extended_tcb_support = 1;
         break;
     case i82562:
-        // TODO: check device id.
+        /* TODO: check device id. */
         pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
         /* TODO: wrong revision id. */
         PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
@@ -637,14 +643,16 @@ static void pci_reset(EEPRO100State * s)
 
 #if EEPROM_SIZE > 0
     if (device == i82557C || device == i82558B || device == i82559C) {
-        // TODO: get vendor id from EEPROM for i82557C or later.
-        // TODO: get device id from EEPROM for i82557C or later.
-        // TODO: status bit 4 can be disabled by EEPROM for i82558, i82559.
-        // TODO: header type is determined by EEPROM for i82559.
-        // TODO: get subsystem id from EEPROM for i82557C or later.
-        // TODO: get subsystem vendor id from EEPROM for i82557C or later.
-        // TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later.
-        // TODO: capability pointer depends on EEPROM for i82558.
+        /*
+        TODO: get vendor id from EEPROM for i82557C or later.
+        TODO: get device id from EEPROM for i82557C or later.
+        TODO: status bit 4 can be disabled by EEPROM for i82558, i82559.
+        TODO: header type is determined by EEPROM for i82559.
+        TODO: get subsystem id from EEPROM for i82557C or later.
+        TODO: get subsystem vendor id from EEPROM for i82557C or later.
+        TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later.
+        TODO: capability pointer depends on EEPROM for i82558.
+        */
         logout("Get device id and revision from EEPROM!!!\n");
     }
 #endif /* EEPROM_SIZE > 0 */
@@ -654,7 +662,9 @@ static void nic_selective_reset(EEPRO100State * s)
 {
     size_t i;
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
-    //~ eeprom93xx_reset(s->eeprom);
+#if 0
+    eeprom93xx_reset(s->eeprom);
+#endif
     memcpy(eeprom_contents, s->conf.macaddr.a, 6);
     eeprom_contents[EEPROM_ID] = EEPROM_ID_VALID;
     if (s->device == i82557B || s->device == i82557C)
@@ -738,7 +748,7 @@ static void eepro100_write_status(EEPRO100State * s, uint16_t val)
 static uint16_t eepro100_read_command(EEPRO100State * s)
 {
     uint16_t val = 0xffff;
-    //~ TRACE(OTHER, logout("val=0x%04x\n", val));
+    TRACE(OTHER, logout("val=0x%04x\n", val));
     return val;
 }
 #endif
@@ -793,9 +803,11 @@ static void dump_statistics(EEPRO100State * s)
     stl_le_phys(s->statsaddr + 36, s->statistics.rx_good_frames);
     stl_le_phys(s->statsaddr + 48, s->statistics.rx_resource_errors);
     stl_le_phys(s->statsaddr + 60, s->statistics.rx_short_frame_errors);
-    //~ stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
-    //~ stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
-    //~ missing("CU dump statistical counters");
+#if 0
+    stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
+    stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
+    missing("CU dump statistical counters");
+#endif
 }
 
 static void read_cb(EEPRO100State *s)
@@ -832,7 +844,9 @@ static void tx_command(EEPRO100State *s)
     while (size < tcb_bytes) {
         uint32_t tx_buffer_address = ldl_phys(tbd_address);
         uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
-        //~ uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
+#if 0
+        uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
+#endif
         tbd_address += 8;
         TRACE(RXTX, logout
             ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n",
@@ -889,7 +903,9 @@ static void tx_command(EEPRO100State *s)
     s->statistics.tx_good_frames++;
     /* Transmit with bad status would raise an CX/TNO interrupt.
      * (82557 only). Emulation never has bad status. */
-    //~ eepro100_cx_interrupt(s);
+#if 0
+    eepro100_cx_interrupt(s);
+#endif
 }
 
 static void set_multicast_list(EEPRO100State *s)
@@ -1016,7 +1032,9 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
             logout("bad CU resume from CU state %u\n", get_cu_state(s));
             /* Workaround for bad Linux eepro100 driver which resumes
              * from idle state. */
-            //~ missing("cu resume");
+#if 0
+            missing("cu resume");
+#endif
             set_cu_state(s, cu_suspended);
         }
         if (get_cu_state(s) == cu_suspended) {
@@ -1067,7 +1085,9 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         /* RU start. */
         if (get_ru_state(s) != ru_idle) {
             logout("RU state is %u, should be %u\n", get_ru_state(s), ru_idle);
-            //~ assert(!"wrong RU state");
+#if 0
+            assert(!"wrong RU state");
+#endif
         }
         set_ru_state(s, ru_ready);
         s->ru_offset = s->pointer;
@@ -1078,7 +1098,9 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
         if (get_ru_state(s) != ru_suspended) {
             logout("RU state is %u, should be %u\n", get_ru_state(s),
                    ru_suspended);
-            //~ assert(!"wrong RU state");
+#if 0
+            assert(!"wrong RU state");
+#endif
         }
         set_ru_state(s, ru_ready);
         break;
@@ -1140,7 +1162,9 @@ static void eepro100_write_eeprom(eeprom_t * eeprom, uint8_t val)
     TRACE(EEPROM, logout("val=0x%02x\n", val));
 
     /* mask unwriteable bits */
-    //~ val = SET_MASKED(val, 0x31, eeprom->value);
+#if 0
+    val = SET_MASKED(val, 0x31, eeprom->value);
+#endif
 
     int eecs = ((val & EEPROM_CS) != 0);
     int eesk = ((val & EEPROM_SK) != 0);
@@ -1222,7 +1246,9 @@ static void eepro100_write_mdi(EEPRO100State * s, uint32_t val)
           val, raiseint, mdi_op_name[opcode], phy, reg2name(reg), data));
     if (phy != 1) {
         /* Unsupported PHY address. */
-        //~ logout("phy must be 1 but is %u\n", phy);
+#if 0
+        logout("phy must be 1 but is %u\n", phy);
+#endif
         data = 0;
     } else if (opcode != 1 && opcode != 2) {
         /* Unsupported opcode. */
@@ -1368,16 +1394,22 @@ static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBAck:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
         break;
     case SCBCmd:
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
-        //~ val = eepro100_read_command(s);
+#if 0
+        val = eepro100_read_command(s);
+#endif
         break;
     case SCBIntmask:
         TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
@@ -1413,7 +1445,9 @@ static uint16_t eepro100_read2(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
     case SCBCmd:
         TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val));
         break;
@@ -1437,11 +1471,15 @@ static uint32_t eepro100_read4(EEPRO100State * s, uint32_t addr)
 
     switch (addr) {
     case SCBStatus:
-        //~ val = eepro100_read_status(s);
+#if 0
+        val = eepro100_read_status(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
         break;
     case SCBPointer:
-        //~ val = eepro100_read_pointer(s);
+#if 0
+        val = eepro100_read_pointer(s);
+#endif
         TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
         break;
     case SCBPort:
@@ -1468,7 +1506,9 @@ static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val)
 
     switch (addr) {
     case SCBStatus:
-        //~ eepro100_write_status(s, val);
+#if 0
+        eepro100_write_status(s, val);
+#endif
         break;
     case SCBAck:
         eepro100_acknowledge(s);
@@ -1508,7 +1548,9 @@ static void eepro100_write2(EEPRO100State * s, uint32_t addr, uint16_t val)
 
     switch (addr) {
     case SCBStatus:
-        //~ eepro100_write_status(s, val);
+#if 0
+        eepro100_write_status(s, val);
+#endif
         eepro100_acknowledge(s);
         break;
     case SCBCmd:
@@ -1556,7 +1598,9 @@ static void eepro100_write4(EEPRO100State * s, uint32_t addr, uint32_t val)
 static uint32_t ioport_read1(void *opaque, uint32_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read1(s, addr - s->region[1]);
 }
 
@@ -1575,7 +1619,9 @@ static uint32_t ioport_read4(void *opaque, uint32_t addr)
 static void ioport_write1(void *opaque, uint32_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write1(s, addr - s->region[1], val);
 }
 
@@ -1623,42 +1669,54 @@ static void pci_map(PCIDevice * pci_dev, int region_num,
 static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write1(s, addr, val);
 }
 
 static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write2(s, addr, val);
 }
 
 static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
+#if 0
+    logout("addr=%s val=0x%02x\n", regname(addr), val);
+#endif
     eepro100_write4(s, addr, val);
 }
 
 static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read1(s, addr);
 }
 
 static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read2(s, addr);
 }
 
 static uint32_t pci_mmio_readl(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    //~ logout("addr=%s\n", regname(addr));
+#if 0
+    logout("addr=%s\n", regname(addr));
+#endif
     return eepro100_read4(s, addr);
 }
 
@@ -1695,7 +1753,9 @@ static int nic_can_receive(VLANClientState *nc)
     EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     TRACE(RXTX, logout("%p\n", s));
     return get_ru_state(s) == ru_ready;
-    //~ return !eepro100_buffer_full(s);
+#if 0
+    return !eepro100_buffer_full(s);
+#endif
 }
 
 static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size)
@@ -1724,13 +1784,15 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
          * Short frame is discarded */
         logout("%p received short frame (%zu byte)\n", s, size);
         s->statistics.rx_short_frame_errors++;
-        //~ return -1;
+#if 0
+        return -1;
+#endif
     } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
         /* Long frame and configuration byte 18/3 (long receive ok) not set:
          * Long frames are discarded. */
         logout("%p received long frame (%zu byte), ignored\n", s, size);
         return -1;
-    } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) {       // !!!
+    } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) {       /* !!! */
         /* Frame matches individual address. */
         /* TODO: check configuration byte 15/4 (ignore U/L). */
         TRACE(RXTX, logout("%p received frame for me, len=%zu\n", s, size));
@@ -1774,11 +1836,12 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         /* TODO: RNR interrupt only at first failed frame? */
         eepro100_rnr_interrupt(s);
         s->statistics.rx_resource_errors++;
-        //~ assert(!"no resources");
+#if 0
+        assert(!"no resources");
+#endif
         return -1;
     }
-    //~ !!!
-//~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}}
+    /* !!! */
     eepro100_rx_t rx;
     cpu_physical_memory_read(s->ru_base + s->ru_offset, (uint8_t *) & rx,
                              offsetof(eepro100_rx_t, packet));
@@ -1799,14 +1862,18 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
              rfd_status);
     stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, count), size);
     /* Early receive interrupt not supported. */
-    //~ eepro100_er_interrupt(s);
+#if 0
+    eepro100_er_interrupt(s);
+#endif
     /* Receive CRC Transfer not supported. */
     if (s->configuration[18] & BIT(2)) {
         missing("Receive CRC Transfer");
         return -1;
     }
     /* TODO: check stripping enable bit. */
-    //~ assert(!(s->configuration[17] & BIT(0)));
+#if 0
+    assert(!(s->configuration[17] & BIT(0)));
+#endif
     cpu_physical_memory_write(s->ru_base + s->ru_offset +
                               offsetof(eepro100_rx_t, packet), buf, size);
     s->statistics.rx_good_frames++;
Signature · 1 line
1.7.0
#59 lore raw

[Qemu-devel] Re: [PATCHv3 19/20] eepro100: Remove C++ comments

Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Stefan Weil

C++ comments are unwanted, so this is fixed here.

* Replace C++ comments by C comments.
* Put code which was deactivated by a C++ comment in #if 0...#endif.

It would be nice to add some documentation to commented blocks, explaining why we still keep them around and what happens if they are uncommented.

Typically, later patches either use this deactivated code (maybe after some modifications), or they remove it completely. More documentation would help of course - I'll try my best :-)

The purpose of this patch was only elimination of C++ comments by formally transforming them to either C comments or by using the preprocessor #if.

#60 lore raw

[Qemu-devel] Re: [PATCHv3 19/20] eepro100: Remove C++ comments

Quoted 14 lines · Stefan Weil
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Stefan Weil

C++ comments are unwanted, so this is fixed here.

* Replace C++ comments by C comments.
* Put code which was deactivated by a C++ comment in #if 0...#endif.

It would be nice to add some documentation to commented blocks, explaining why we still keep them around and what happens if they are uncommented.

Quoted 6 lines

Typically, later patches either use this deactivated code (maybe after some modifications), or they remove it completely. More documentation would help of course - I'll try my best :-)

The purpose of this patch was only elimination of C++ comments by formally transforming them to either C comments or by using the preprocessor #if.

Yes, I understand that.

#61 lore raw

PATCH v3 20/20 eepro100: Keep includes sorted

In reply to Stefan Weil

I always try to keep standard includes sorted
and add a comment why they are there (so they
can be removed when they are no longer needed).

---
 hw/eepro100.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/eepro100.c +1 -1
index 43a9060..45ab497 100644
@@ -41,8 +41,8 @@
  *      * Wake-on-LAN is not implemented.
  */
 
+#include <stdbool.h>            /* bool */
 #include <stddef.h>             /* offsetof */
-#include <stdbool.h>
 #include "hw.h"
 #include "pci.h"
 #include "net.h"
Signature · 1 line
1.7.0