From patchwork Wed Oct 21 11:27:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6AD08B7B9D for ; Wed, 21 Oct 2009 23:48:26 +1100 (EST) Received: from localhost ([127.0.0.1]:44134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0ac3-00039R-4m for incoming@patchwork.ozlabs.org; Wed, 21 Oct 2009 08:48:23 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0ZOE-0006mk-AM for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:30:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0ZO7-0006i4-5T for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:59 -0400 Received: from [199.232.76.173] (port=57335 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0ZO3-0006f2-P0 for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8471) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0ZO2-0002xs-RD for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:51 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBToqh015716 for ; Wed, 21 Oct 2009 07:29:50 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTmRE026742; Wed, 21 Oct 2009 07:29:49 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 4FB86463C9; Wed, 21 Oct 2009 12:27:59 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 21 Oct 2009 12:27:54 +0100 Message-Id: <1256124478-2988-16-git-send-email-markmc@redhat.com> In-Reply-To: <1256124478-2988-1-git-send-email-markmc@redhat.com> References: <1256124478-2988-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 15/19] net: add tap_set_offload() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This API allows virtio-net to enable various offload features on a tap interface - e.g. to tell the host kernel it can pass up partial checksums to userspace. Signed-off-by: Mark McLoughlin --- net.c | 24 ++++++++++++++++++++++++ net.h | 1 + tap-linux.h | 7 +++++++ 3 files changed, 32 insertions(+), 0 deletions(-) diff --git a/net.c b/net.c index b44495d..746a3d6 100644 --- a/net.c +++ b/net.c @@ -1287,6 +1287,9 @@ int tap_has_vnet_hdr(VLANClientState *vc) void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr) { } +void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn) +{ +} #else /* !defined(_WIN32) */ /* Maximum GSO packet size (64k) plus plenty of room for @@ -1524,6 +1527,27 @@ static int tap_probe_vnet_hdr(int fd) return ifr.ifr_flags & IFF_VNET_HDR; } +void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn) +{ + TAPState *s = vc->opaque; + unsigned int offload = 0; + + if (csum) { + offload |= TUN_F_CSUM; + if (tso4) + offload |= TUN_F_TSO4; + if (tso6) + offload |= TUN_F_TSO6; + if ((tso4 || tso6) && ecn) + offload |= TUN_F_TSO_ECN; + } + + if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) { + fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n", + strerror(errno)); + } +} + static void tap_cleanup(VLANClientState *vc) { TAPState *s = vc->opaque; diff --git a/net.h b/net.h index 6255e2b..a0f0359 100644 --- a/net.h +++ b/net.h @@ -170,5 +170,6 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev, int tap_has_vnet_hdr(VLANClientState *vc); void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr); +void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn); #endif diff --git a/tap-linux.h b/tap-linux.h index 8e75348..241cf83 100644 --- a/tap-linux.h +++ b/tap-linux.h @@ -22,6 +22,7 @@ /* Ioctl defines */ #define TUNSETIFF _IOW('T', 202, int) #define TUNGETFEATURES _IOR('T', 207, unsigned int) +#define TUNSETOFFLOAD _IOW('T', 208, unsigned int) #define TUNGETIFF _IOR('T', 210, unsigned int) #define TUNSETSNDBUF _IOW('T', 212, int) @@ -30,6 +31,12 @@ #define IFF_NO_PI 0x1000 #define IFF_VNET_HDR 0x4000 +/* Features for GSO (TUNSETOFFLOAD). */ +#define TUN_F_CSUM 0x01 /* You can hand me unchecksummed packets. */ +#define TUN_F_TSO4 0x02 /* I can handle TSO for IPv4 packets */ +#define TUN_F_TSO6 0x04 /* I can handle TSO for IPv6 packets */ +#define TUN_F_TSO_ECN 0x08 /* I can handle TSO with ECN bits. */ + struct virtio_net_hdr { uint8_t flags;