hw/net: e1000: Correct the initial value of VET register
PATCH v4 1/3 hw/net: e1000: Correct the initial value of VET register
From: Christina Wang <[email protected]>
The initial value of VLAN Ether Type (VET) register is 0x8100, as per the manual and real hardware.
While Linux e1000 driver always writes VET register to 0x8100, it is not always the case for everyone. Drivers relying on the reset value of VET won't be able to transmit and receive VLAN frames in QEMU.
---
Changes in v4:
- Only keep hw_compat_6_0[] changes
- Use e1000_vet_init_need() instead of touching other flags
Changes in v3:
- add a "init-vet" property for versioned machines
hw/core/machine.c | 1 + hw/net/e1000.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
hw/core/machine.c +1 -0
@@ -41,6 +41,7 @@ GlobalProperty hw_compat_6_0[] = { { "gpex-pcihost", "allow-unmapped-accesses", "false" }, { "i8042", "extended-state", "false"}, { "nvme-ns", "eui64-default", "off"}, + { "e1000", "init-vet", "off" }, };const size_t hw_compat_6_0_len =G_N_ELEMENTS (hw_compat_6_0);
hw/net/e1000.c +17 -0
@@ -29,6 +29,7 @@#include "hw/pci/pci.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" +#include "net/eth.h" #include "net/net.h" #include "net/checksum.h" #include "sysemu/sysemu.h"
@@ -130,10 +131,13 @@ struct E1000State_st {#define E1000_FLAG_MIT_BIT 1#define E1000_FLAG_MAC_BIT 2#define E1000_FLAG_TSO_BIT 3 +#define E1000_FLAG_VET_BIT 4#define E1000_FLAG_AUTONEG (1 << E1000_FLAG_AUTONEG_BIT)#define E1000_FLAG_MIT (1 << E1000_FLAG_MIT_BIT)#define E1000_FLAG_MAC (1 << E1000_FLAG_MAC_BIT)#define E1000_FLAG_TSO (1 << E1000_FLAG_TSO_BIT) +#define E1000_FLAG_VET (1 << E1000_FLAG_VET_BIT) +uint32_t compat_flags;bool received_tx_tso;bool use_tso_for_migration;
@@ -361,6 +365,13 @@ e1000_autoneg_timer(void *opaque) } } +static bool e1000_vet_init_need (void *opaque) +{ +E1000State *s = opaque; + +return chkflag (VET ); +} +static void e1000_reset (void *opaque) {E1000State *d = opaque;
@@ -386,6 +397,10 @@ static void e1000_reset(void *opaque) }e1000x_reset_mac_addr (d->nic, d->mac_reg, macaddr); + +if (e1000_vet_init_need (d)) { + d->mac_reg[VET ] =ETH_P_VLAN ; + } } static void
@@ -1737,6 +1752,8 @@ static Property e1000_properties[] = { compat_flags, E1000_FLAG_MAC_BIT, true),DEFINE_PROP_BIT ("migrate_tso_props" , E1000State, compat_flags,E1000_FLAG_TSO_BIT , true), +DEFINE_PROP_BIT ("init-vet" , E1000State, + compat_flags,E1000_FLAG_VET_BIT , true), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.25.1
PATCH v4 2/3 hw/net: e1000e: Correct the initial value of VET register
From: Christina Wang <[email protected]>
The initial value of VLAN Ether Type (VET) register is 0x8100, as per the manual and real hardware.
While Linux e1000e driver always writes VET register to 0x8100, it is not always the case for everyone. Drivers relying on the reset value of VET won't be able to transmit and receive VLAN frames in QEMU.
Unlike e1000 in QEMU, e1000e uses a field 'vet' in "struct E1000Core" to cache the value of VET register, but the cache only gets updated when VET register is written. To always get a consistent VET value no matter VET is written or remains its reset value, drop the 'vet' field and use 'core->mac[VET]' directly.
---
Changes in v4:
- Only keep hw_compat_6_0[] changes
Changes in v3:
- add a "init-vet" property for versioned machines
Changes in v2:
- keep the 'vet' field in "struct E1000Core" for migration compatibility
hw/core/machine.c | 1 + hw/net/e1000e.c | 8 +++++++- hw/net/e1000e_core.c | 9 ++++----- 3 files changed, 12 insertions(+), 6 deletions(-)
hw/core/machine.c +1 -0
@@ -42,6 +42,7 @@ GlobalProperty hw_compat_6_0[] = { { "i8042", "extended-state", "false"}, { "nvme-ns", "eui64-default", "off"}, { "e1000", "init-vet", "off" }, + { "e1000e", "init-vet", "off" }, };const size_t hw_compat_6_0_len =G_N_ELEMENTS (hw_compat_6_0);
hw/net/e1000e.c +7 -1
@@ -35,6 +35,7 @@#include "qemu/osdep.h" #include "qemu/units.h" +#include "net/eth.h" #include "net/net.h" #include "net/tap.h" #include "qemu/module.h"
@@ -79,7 +80,7 @@ struct E1000EState {bool disable_vnet;E1000ECore core; - +bool init_vet; };#define E1000E_MMIO_IDX 0
@@ -527,6 +528,10 @@ static void e1000e_qdev_reset(DeviceState *dev)trace_e1000e_cb_qdev_reset ();e1000e_core_reset (&s->core); + +if (s->init_vet) { + s->core.mac[VET ] =ETH_P_VLAN ; + } }static int e1000e_pre_save (void *opaque)
@@ -666,6 +671,7 @@ static Property e1000e_properties[] = { e1000e_prop_subsys_ven, uint16_t),DEFINE_PROP_SIGNED ("subsys" , E1000EState, subsys,0 , e1000e_prop_subsys, uint16_t), +DEFINE_PROP_BOOL ("init-vet" , E1000EState, init_vet, true), DEFINE_PROP_END_OF_LIST(), };
hw/net/e1000e_core.c +4 -5
@@ -731,7 +731,7 @@ e1000e_process_tx_desc(E1000ECore *core,if (e1000x_vlan_enabled (core->mac) &&e1000x_is_vlan_txd (txd_lower)) {net_tx_pkt_setup_vlan_header_ex (tx->tx_pkt, -le16_to_cpu (dp->upper.fields.special), core->vet); +le16_to_cpu (dp->upper.fields.special), core->mac[VET ]); }if (e1000e_tx_pkt_send (core, tx, queue_index)) {e1000e_on_tx_done_update_stats (core, tx->tx_pkt);
@@ -1012,7 +1012,7 @@ e1000e_receive_filter(E1000ECore *core, const uint8_t *buf, int size) {uint32_t rctl = core->mac[RCTL ]; -if (e1000x_is_vlan_packet (buf, core->vet) && +if (e1000x_is_vlan_packet (buf, core->mac[VET ]) &&e1000x_vlan_rx_filter_enabled (core->mac)) {uint16_t vid =lduw_be_p (buf +14 ); uint32_t vfta = ldl_le_p((uint32_t *)(core->mac + VFTA) +
@@ -1686,7 +1686,7 @@ e1000e_receive_iov(E1000ECore *core, const struct iovec *iov, int iovcnt) }net_rx_pkt_attach_iovec_ex (core->rx_pkt, iov, iovcnt, iov_ofs, -e1000x_vlan_enabled (core->mac), core->vet); +e1000x_vlan_enabled (core->mac), core->mac[VET ]);e1000e_rss_parse_packet (core, core->rx_pkt, &rss_info);e1000e_rx_ring_init (core, &rxr, rss_info.queue);
@@ -2397,8 +2397,7 @@ static void e1000e_set_vet(E1000ECore *core, int index, uint32_t val) { core->mac[VET ] = val &0xffff ; - core->vet =le16_to_cpu (core->mac[VET ]); -trace_e1000e_vlan_vet (core->vet); +trace_e1000e_vlan_vet (core->mac[VET ]); } static void
Signature · 1 line
2.25.1
Re: [PATCH v4 2/3] hw/net: e1000e: Correct the initial value of VET register
Hi Jason,
Quoted 28 lines · Bin Meng
From: Christina Wang <[email protected]>
The initial value of VLAN Ether Type (VET) register is
0x8100, as per the manual and real hardware.While Linux e1000e driver always writes VET register to
0x8100, it is not always the case for everyone. Drivers relying on the reset value of VET won't be able to transmit and receive VLAN frames in QEMU.Unlike e1000 in QEMU, e1000e uses a field 'vet' in "struct E1000Core" to cache the value of VET register, but the cache only gets updated when VET register is written. To always get a consistent VET value no matter VET is written or remains its reset value, drop the 'vet' field and use 'core->mac[VET]' directly.
Reported-by Markus Carlstedt <[email protected]>Signed-off-by Christina Wang <[email protected]>Signed-off-by Bin Meng <[email protected]>---
Changes in v4:
- Only keep hw_compat_6_0[] changesChanges in v3:
- add a "init-vet" property for versioned machines
Quoted 8 lines
Changes in v2:
- keep the 'vet' field in "struct E1000Core" for migration compatibilityhw/core/machine.c | 1 + hw/net/e1000e.c | 8 +++++++- hw/net/e1000e_core.c | 9 ++++----- 3 files changed, 12 insertions(+), 6 deletions(-)
Will this series be in 6.1?
Regards,
Bin
Re: [PATCH v4 2/3] hw/net: e1000e: Correct the initial value of VET register
Quoted 38 lines · Bin Meng
Hi Jason,
Quoted 27 lines · Bin Meng
From: Christina Wang <[email protected]>
The initial value of VLAN Ether Type (VET) register is
0x8100, as per the manual and real hardware.While Linux e1000e driver always writes VET register to
0x8100, it is not always the case for everyone. Drivers relying on the reset value of VET won't be able to transmit and receive VLAN frames in QEMU.Unlike e1000 in QEMU, e1000e uses a field 'vet' in "struct E1000Core" to cache the value of VET register, but the cache only gets updated when VET register is written. To always get a consistent VET value no matter VET is written or remains its reset value, drop the 'vet' field and use 'core->mac[VET]' directly.
Reported-by Markus Carlstedt <[email protected]>Signed-off-by Christina Wang <[email protected]>Signed-off-by Bin Meng <[email protected]>---
Changes in v4:
- Only keep hw_compat_6_0[] changesChanges in v3:
- add a "init-vet" property for versioned machinesQuoted 8 lines
Changes in v2:
- keep the 'vet' field in "struct E1000Core" for migration compatibilityhw/core/machine.c | 1 + hw/net/e1000e.c | 8 +++++++- hw/net/e1000e_core.c | 9 ++++----- 3 files changed, 12 insertions(+), 6 deletions(-)
Quoted 4 lines
Will this series be in 6.1?
Regards,
Bin
Yes, I've applied them.
Thanks
PATCH v4 3/3 hw/net: e1000e: Don't zero out the VLAN tag in the legacy RX descriptor
In reply to Bin MengFrom: Christina Wang <[email protected]>
In the legacy RX descriptor mode, VLAN tag was saved to d->special by e1000e_build_rx_metadata() in e1000e_write_lgcy_rx_descr(), but it was then zeroed out again at the end of the call, which is wrong.
---
(no changes since v1)
hw/net/e1000e_core.c | 1 - 1 file changed, 1 deletion(-)
hw/net/e1000e_core.c +0 -1
@@ -1285,7 +1285,6 @@ e1000e_write_lgcy_rx_descr(E1000ECore *core, uint8_t *desc, &d->special); d->errors = (uint8_t ) (le32_to_cpu (status_flags) >>24 ); d->status = (uint8_t )le32_to_cpu (status_flags); - d->special =0 ; } static inline void
Signature · 1 line
2.25.1