From 655d3b63b036b70714adbdae685055f1bda0f8f1 Mon Sep 17 00:00:00 2001 From: Amos Kong Date: Thu, 17 Oct 2013 16:38:34 +0800 Subject: [PATCH 1/3] net: update nic info during device reset macaddr is reset during device reset, but nic info isn't updated, this problem exists in e1000 & rtl8139 Signed-off-by: Amos Kong Acked-by: Michael S. Tsirkin Signed-off-by: Stefan Hajnoczi --- hw/net/e1000.c | 1 + hw/net/rtl8139.c | 1 + 2 files changed, 2 insertions(+) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 151d25e0b7..9a1c46e8ca 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -401,6 +401,7 @@ static void e1000_reset(void *opaque) d->mac_reg[RA] |= macaddr[i] << (8 * i); d->mac_reg[RA + 1] |= (i < 2) ? macaddr[i + 4] << (8 * i) : 0; } + qemu_format_nic_info_str(qemu_get_queue(d->nic), macaddr); } static void diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index c31199f8c8..9b4a6501d7 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -1214,6 +1214,7 @@ static void rtl8139_reset(DeviceState *d) /* restore MAC address */ memcpy(s->phys, s->conf.macaddr.a, 6); + qemu_format_nic_info_str(qemu_get_queue(s->nic), s->phys); /* reset interrupt mask */ s->IntrStatus = 0; From 7c36507c2b8776266f50c5e2739bd18279953b93 Mon Sep 17 00:00:00 2001 From: Amos Kong Date: Thu, 17 Oct 2013 15:02:49 +0800 Subject: [PATCH 2/3] net/e1000: update network information when macaddr is changed in guest If we change macaddr in guest by 'ifconfig eth0 hw ether 12:12:12:34:35:36', the mac register of e1000 is already updated, but we don't update network information in qemu. Therefor, the information in monitor is wrong. This patch updates nic info when the second part of macaddr is written. Signed-off-by: Amos Kong Signed-off-by: Stefan Hajnoczi --- hw/net/e1000.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 9a1c46e8ca..70a59fde7f 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -1106,7 +1106,15 @@ mac_read_clr8(E1000State *s, int index) static void mac_writereg(E1000State *s, int index, uint32_t val) { + uint32_t macaddr[2]; + s->mac_reg[index] = val; + + if (index == RA + 1) { + macaddr[0] = cpu_to_le32(s->mac_reg[RA]); + macaddr[1] = cpu_to_le32(s->mac_reg[RA + 1]); + qemu_format_nic_info_str(qemu_get_queue(s->nic), (uint8_t *)macaddr); + } } static void From 23c37c37f0280761072c23bf67d3a4f3c0ff25aa Mon Sep 17 00:00:00 2001 From: Amos Kong Date: Thu, 17 Oct 2013 15:02:50 +0800 Subject: [PATCH 3/3] net/rtl8139: update network information when macaddr is changed in guest rtl8139 has same problem as e1000, nic info isn't updated when macaddr is changed in guest. This patch updates the nic info when the last bit of macaddr is written. Signed-off-by: Amos Kong Signed-off-by: Stefan Hajnoczi --- hw/net/rtl8139.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index 9b4a6501d7..3225f3d3e5 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -2741,9 +2741,13 @@ static void rtl8139_io_writeb(void *opaque, uint8_t addr, uint32_t val) switch (addr) { - case MAC0 ... MAC0+5: + case MAC0 ... MAC0+4: s->phys[addr - MAC0] = val; break; + case MAC0+5: + s->phys[addr - MAC0] = val; + qemu_format_nic_info_str(qemu_get_queue(s->nic), s->phys); + break; case MAC0+6 ... MAC0+7: /* reserved */ break;