diff mbox

reset nic when we init it

Message ID 4D64C7F2.2070909@cn.fujitsu.com
State New
Headers show

Commit Message

Wen Congyang Feb. 23, 2011, 8:40 a.m. UTC
When we hotplug a nic to guest OS, we can see it
but the mac address of nic is wrong.

The reason of this bug is guest OS does not reset
nic, and we init eeprom(rtl8139) only when we reset
nic.

I think we should reset nic when we init it.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>

---
 hw/e1000.c     |   14 ++++++++------
 hw/pcnet-pci.c |   19 +++++++++++--------
 hw/rtl8139.c   |    1 +
 3 files changed, 20 insertions(+), 14 deletions(-)
diff mbox

Patch

diff --git a/hw/e1000.c b/hw/e1000.c
index 0a4574c..5bd91a8 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1137,6 +1137,12 @@  static NetClientInfo net_e1000_info = {
     .link_status_changed = e1000_set_link_status,
 };
 
+static void qdev_e1000_reset(DeviceState *dev)
+{
+    E1000State *d = DO_UPCAST(E1000State, dev.qdev, dev);
+    e1000_reset(d);
+}
+
 static int pci_e1000_init(PCIDevice *pci_dev)
 {
     E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);
@@ -1186,13 +1192,9 @@  static int pci_e1000_init(PCIDevice *pci_dev)
 
     add_boot_device_path(d->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
 
-    return 0;
-}
+    qdev_e1000_reset(&pci_dev->qdev);
 
-static void qdev_e1000_reset(DeviceState *dev)
-{
-    E1000State *d = DO_UPCAST(E1000State, dev.qdev, dev);
-    e1000_reset(d);
+    return 0;
 }
 
 static PCIDeviceInfo e1000_info = {
diff --git a/hw/pcnet-pci.c b/hw/pcnet-pci.c
index 339a401..205f2c7 100644
--- a/hw/pcnet-pci.c
+++ b/hw/pcnet-pci.c
@@ -265,11 +265,19 @@  static NetClientInfo net_pci_pcnet_info = {
     .cleanup = pci_pcnet_cleanup,
 };
 
+static void pci_reset(DeviceState *dev)
+{
+    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev);
+
+    pcnet_h_reset(&d->state);
+}
+
 static int pci_pcnet_init(PCIDevice *pci_dev)
 {
     PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev);
     PCNetState *s = &d->state;
     uint8_t *pci_conf;
+    int ret;
 
 #if 0
     printf("sizeof(RMD)=%d, sizeof(TMD)=%d\n",
@@ -315,14 +323,9 @@  static int pci_pcnet_init(PCIDevice *pci_dev)
         }
     }
 
-    return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
-}
-
-static void pci_reset(DeviceState *dev)
-{
-    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev);
-
-    pcnet_h_reset(&d->state);
+    ret = pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
+    pci_reset(&pci_dev->qdev);
+    return ret;
 }
 
 static PCIDeviceInfo pcnet_info = {
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index a22530c..15425a8 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3405,6 +3405,7 @@  static int pci_rtl8139_init(PCIDevice *dev)
     rtl8139_set_next_tctr_time(s, qemu_get_clock(vm_clock));
 
     add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet-phy@0");
+    rtl8139_reset(&dev->qdev);
 
     return 0;
 }