Browse Source

net: bundle all offloads in a single struct

The set_offload() argument list is already pretty long and
we are going to introduce soon a bunch of additional offloads.

Replace the offload arguments with a single struct and update
all the relevant call-sites.

No functional changes intended.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <a9d4dd043b8c71b791e9ff05e17ef06072d9714e.1758549625.git.pabeni@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
pull/305/head
Paolo Abeni 11 months ago
committed by Michael S. Tsirkin
parent
commit
e5fd02d825
  1. 5
      hw/net/e1000e_core.c
  2. 5
      hw/net/igb_core.c
  3. 19
      hw/net/virtio-net.c
  4. 13
      hw/net/vmxnet3.c
  5. 15
      include/net/net.h
  6. 5
      net/net.c
  7. 3
      net/netmap.c
  8. 3
      net/tap-bsd.c
  9. 21
      net/tap-linux.c
  10. 4
      net/tap-solaris.c
  11. 3
      net/tap-stub.c
  12. 8
      net/tap.c
  13. 4
      net/tap_int.h

5
hw/net/e1000e_core.c

@ -2822,8 +2822,9 @@ e1000e_update_rx_offloads(E1000ECore *core)
trace_e1000e_rx_set_cso(cso_state); trace_e1000e_rx_set_cso(cso_state);
if (core->has_vnet) { if (core->has_vnet) {
qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, NetOffloads ol = { .csum = cso_state };
cso_state, 0, 0, 0, 0, 0, 0);
qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, &ol);
} }
} }

5
hw/net/igb_core.c

@ -3058,8 +3058,9 @@ igb_update_rx_offloads(IGBCore *core)
trace_e1000e_rx_set_cso(cso_state); trace_e1000e_rx_set_cso(cso_state);
if (core->has_vnet) { if (core->has_vnet) {
qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, NetOffloads ol = {.csum = cso_state };
cso_state, 0, 0, 0, 0, 0, 0);
qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, &ol);
} }
} }

19
hw/net/virtio-net.c

@ -773,14 +773,17 @@ static uint64_t virtio_net_bad_features(VirtIODevice *vdev)
static void virtio_net_apply_guest_offloads(VirtIONet *n) static void virtio_net_apply_guest_offloads(VirtIONet *n)
{ {
qemu_set_offload(qemu_get_queue(n->nic)->peer, NetOffloads ol = {
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_CSUM)), .csum = !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_CSUM)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)), .tso4 = !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)), .tso6 = !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)), .ecn = !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)), .ufo = !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO4)), .uso4 = !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO4)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6))); .uso6 = !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6)),
};
qemu_set_offload(qemu_get_queue(n->nic)->peer, &ol);
} }
static uint64_t virtio_net_guest_offloads_by_features(uint64_t features) static uint64_t virtio_net_guest_offloads_by_features(uint64_t features)

13
hw/net/vmxnet3.c

@ -1322,14 +1322,11 @@ static void vmxnet3_update_features(VMXNET3State *s)
s->lro_supported, rxcso_supported, s->lro_supported, rxcso_supported,
s->rx_vlan_stripping); s->rx_vlan_stripping);
if (s->peer_has_vhdr) { if (s->peer_has_vhdr) {
qemu_set_offload(qemu_get_queue(s->nic)->peer, NetOffloads ol = { .csum = rxcso_supported,
rxcso_supported, .tso4 = s->lro_supported,
s->lro_supported, .tso6 = s->lro_supported };
s->lro_supported,
0, qemu_set_offload(qemu_get_queue(s->nic)->peer, &ol);
0,
0,
0);
} }
} }

15
include/net/net.h

@ -35,6 +35,16 @@ typedef struct NICConf {
int32_t bootindex; int32_t bootindex;
} NICConf; } NICConf;
typedef struct NetOffloads {
bool csum;
bool tso4;
bool tso6;
bool ecn;
bool ufo;
bool uso4;
bool uso6;
} NetOffloads;
#define DEFINE_NIC_PROPERTIES(_state, _conf) \ #define DEFINE_NIC_PROPERTIES(_state, _conf) \
DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
DEFINE_PROP_NETDEV("netdev", _state, _conf.peers) DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
@ -57,7 +67,7 @@ typedef bool (HasUfo)(NetClientState *);
typedef bool (HasUso)(NetClientState *); typedef bool (HasUso)(NetClientState *);
typedef bool (HasVnetHdr)(NetClientState *); typedef bool (HasVnetHdr)(NetClientState *);
typedef bool (HasVnetHdrLen)(NetClientState *, int); typedef bool (HasVnetHdrLen)(NetClientState *, int);
typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, int); typedef void (SetOffload)(NetClientState *, const NetOffloads *);
typedef int (GetVnetHdrLen)(NetClientState *); typedef int (GetVnetHdrLen)(NetClientState *);
typedef void (SetVnetHdrLen)(NetClientState *, int); typedef void (SetVnetHdrLen)(NetClientState *, int);
typedef bool (GetVnetHashSupportedTypes)(NetClientState *, uint32_t *); typedef bool (GetVnetHashSupportedTypes)(NetClientState *, uint32_t *);
@ -189,8 +199,7 @@ bool qemu_has_ufo(NetClientState *nc);
bool qemu_has_uso(NetClientState *nc); bool qemu_has_uso(NetClientState *nc);
bool qemu_has_vnet_hdr(NetClientState *nc); bool qemu_has_vnet_hdr(NetClientState *nc);
bool qemu_has_vnet_hdr_len(NetClientState *nc, int len); bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, void qemu_set_offload(NetClientState *nc, const NetOffloads *ol);
int ecn, int ufo, int uso4, int uso6);
int qemu_get_vnet_hdr_len(NetClientState *nc); int qemu_get_vnet_hdr_len(NetClientState *nc);
void qemu_set_vnet_hdr_len(NetClientState *nc, int len); void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
bool qemu_get_vnet_hash_supported_types(NetClientState *nc, uint32_t *types); bool qemu_get_vnet_hash_supported_types(NetClientState *nc, uint32_t *types);

5
net/net.c

@ -540,14 +540,13 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int len)
return nc->info->has_vnet_hdr_len(nc, len); return nc->info->has_vnet_hdr_len(nc, len);
} }
void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, void qemu_set_offload(NetClientState *nc, const NetOffloads *ol)
int ecn, int ufo, int uso4, int uso6)
{ {
if (!nc || !nc->info->set_offload) { if (!nc || !nc->info->set_offload) {
return; return;
} }
nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo, uso4, uso6); nc->info->set_offload(nc, ol);
} }
int qemu_get_vnet_hdr_len(NetClientState *nc) int qemu_get_vnet_hdr_len(NetClientState *nc)

3
net/netmap.c

@ -366,8 +366,7 @@ static void netmap_set_vnet_hdr_len(NetClientState *nc, int len)
} }
} }
static void netmap_set_offload(NetClientState *nc, int csum, int tso4, int tso6, static void netmap_set_offload(NetClientState *nc, const NetOffloads *ol)
int ecn, int ufo, int uso4, int uso6)
{ {
NetmapState *s = DO_UPCAST(NetmapState, nc, nc); NetmapState *s = DO_UPCAST(NetmapState, nc, nc);

3
net/tap-bsd.c

@ -239,8 +239,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
return -EINVAL; return -EINVAL;
} }
void tap_fd_set_offload(int fd, int csum, int tso4, void tap_fd_set_offload(int fd, const NetOffloads *ol)
int tso6, int ecn, int ufo, int uso4, int uso6)
{ {
} }

21
net/tap-linux.c

@ -244,8 +244,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
abort(); abort();
} }
void tap_fd_set_offload(int fd, int csum, int tso4, void tap_fd_set_offload(int fd, const NetOffloads *ol)
int tso6, int ecn, int ufo, int uso4, int uso6)
{ {
unsigned int offload = 0; unsigned int offload = 0;
@ -254,20 +253,24 @@ void tap_fd_set_offload(int fd, int csum, int tso4,
return; return;
} }
if (csum) { if (ol->csum) {
offload |= TUN_F_CSUM; offload |= TUN_F_CSUM;
if (tso4) if (ol->tso4) {
offload |= TUN_F_TSO4; offload |= TUN_F_TSO4;
if (tso6) }
if (ol->tso6) {
offload |= TUN_F_TSO6; offload |= TUN_F_TSO6;
if ((tso4 || tso6) && ecn) }
if ((ol->tso4 || ol->tso6) && ol->ecn) {
offload |= TUN_F_TSO_ECN; offload |= TUN_F_TSO_ECN;
if (ufo) }
if (ol->ufo) {
offload |= TUN_F_UFO; offload |= TUN_F_UFO;
if (uso4) { }
if (ol->uso4) {
offload |= TUN_F_USO4; offload |= TUN_F_USO4;
} }
if (uso6) { if (ol->uso6) {
offload |= TUN_F_USO6; offload |= TUN_F_USO6;
} }
} }

4
net/tap-solaris.c

@ -27,6 +27,7 @@
#include "tap_int.h" #include "tap_int.h"
#include "qemu/ctype.h" #include "qemu/ctype.h"
#include "qemu/cutils.h" #include "qemu/cutils.h"
#include "net/net.h"
#include <sys/ethernet.h> #include <sys/ethernet.h>
#include <sys/sockio.h> #include <sys/sockio.h>
@ -240,8 +241,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
return -EINVAL; return -EINVAL;
} }
void tap_fd_set_offload(int fd, int csum, int tso4, void tap_fd_set_offload(int fd, const NetOffloads *ol)
int tso6, int ecn, int ufo, int uso4, int uso6)
{ {
} }

3
net/tap-stub.c

@ -66,8 +66,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
return -EINVAL; return -EINVAL;
} }
void tap_fd_set_offload(int fd, int csum, int tso4, void tap_fd_set_offload(int fd, const NetOffloads *ol)
int tso6, int ecn, int ufo, int uso4, int uso6)
{ {
} }

8
net/tap.c

@ -285,15 +285,14 @@ static int tap_set_vnet_be(NetClientState *nc, bool is_be)
return tap_fd_set_vnet_be(s->fd, is_be); return tap_fd_set_vnet_be(s->fd, is_be);
} }
static void tap_set_offload(NetClientState *nc, int csum, int tso4, static void tap_set_offload(NetClientState *nc, const NetOffloads *ol)
int tso6, int ecn, int ufo, int uso4, int uso6)
{ {
TAPState *s = DO_UPCAST(TAPState, nc, nc); TAPState *s = DO_UPCAST(TAPState, nc, nc);
if (s->fd < 0) { if (s->fd < 0) {
return; return;
} }
tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo, uso4, uso6); tap_fd_set_offload(s->fd, ol);
} }
static void tap_exit_notify(Notifier *notifier, void *data) static void tap_exit_notify(Notifier *notifier, void *data)
@ -391,6 +390,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
int fd, int fd,
int vnet_hdr) int vnet_hdr)
{ {
NetOffloads ol = {};
NetClientState *nc; NetClientState *nc;
TAPState *s; TAPState *s;
@ -404,7 +404,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
s->has_ufo = tap_probe_has_ufo(s->fd); s->has_ufo = tap_probe_has_ufo(s->fd);
s->has_uso = tap_probe_has_uso(s->fd); s->has_uso = tap_probe_has_uso(s->fd);
s->enabled = true; s->enabled = true;
tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0); tap_set_offload(&s->nc, &ol);
/* /*
* Make sure host header length is set correctly in tap: * Make sure host header length is set correctly in tap:
* it might have been modified by another instance of qemu. * it might have been modified by another instance of qemu.

4
net/tap_int.h

@ -27,6 +27,7 @@
#define NET_TAP_INT_H #define NET_TAP_INT_H
#include "qapi/qapi-types-net.h" #include "qapi/qapi-types-net.h"
#include "net/net.h"
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
int vnet_hdr_required, int mq_required, Error **errp); int vnet_hdr_required, int mq_required, Error **errp);
@ -37,8 +38,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp);
int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp);
int tap_probe_has_ufo(int fd); int tap_probe_has_ufo(int fd);
int tap_probe_has_uso(int fd); int tap_probe_has_uso(int fd);
void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo, void tap_fd_set_offload(int fd, const NetOffloads *ol);
int uso4, int uso6);
void tap_fd_set_vnet_hdr_len(int fd, int len); void tap_fd_set_vnet_hdr_len(int fd, int len);
int tap_fd_set_vnet_le(int fd, int vnet_is_le); int tap_fd_set_vnet_le(int fd, int vnet_is_le);
int tap_fd_set_vnet_be(int fd, int vnet_is_be); int tap_fd_set_vnet_be(int fd, int vnet_is_be);

Loading…
Cancel
Save