From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <yuanhan.liu@linux.intel.com>
Received: from mga03.intel.com (mga03.intel.com [134.134.136.65])
 by dpdk.org (Postfix) with ESMTP id 35AEF2B86
 for <dev@dpdk.org>; Mon, 26 Dec 2016 08:52:00 +0100 (CET)
Received: from fmsmga005.fm.intel.com ([10.253.24.32])
 by orsmga103.jf.intel.com with ESMTP; 25 Dec 2016 23:51:59 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.33,404,1477983600"; d="scan'208";a="46784401"
Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.67.162])
 by fmsmga005.fm.intel.com with ESMTP; 25 Dec 2016 23:51:58 -0800
Date: Mon, 26 Dec 2016 15:53:46 +0800
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: Jianfeng Tan <jianfeng.tan@intel.com>
Cc: dev@dpdk.org, ferruh.yigit@intel.com, cunming.liang@intel.com
Message-ID: <20161226075346.GE19288@yliu-dev.sh.intel.com>
References: <1480689075-66977-1-git-send-email-jianfeng.tan@intel.com>
 <1482477266-39199-1-git-send-email-jianfeng.tan@intel.com>
 <1482477266-39199-7-git-send-email-jianfeng.tan@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1482477266-39199-7-git-send-email-jianfeng.tan@intel.com>
User-Agent: Mutt/1.5.23 (2014-03-12)
Subject: Re: [dpdk-dev] [PATCH v2 6/7] net/virtio_user: enable offloading
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 26 Dec 2016 07:52:01 -0000

On Fri, Dec 23, 2016 at 07:14:25AM +0000, Jianfeng Tan wrote:
> When used with vhost kernel backend, we can offload at both directions.
>   - From vhost kernel to virtio_user, the offload is enabled so that
>     DPDK app can trust the flow is checksum-correct; and if DPDK app
>     sends it through another port, the checksum needs to be
>     recalculated or offloaded. It also applies to TSO.
>   - From virtio_user to vhost_kernel, the offload is enabled so that
>     kernel can trust the flow is L4-checksum-correct, no need to verify
>     it; if kernel will consume it, DPDK app should make sure the
>     l3-checksum is correctly set.
> 
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> ---
>  drivers/net/virtio/virtio_user/vhost_kernel.c | 61 ++++++++++++++++++++++++++-
>  1 file changed, 59 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c
> index 8984c5c..fb3c454 100644
> --- a/drivers/net/virtio/virtio_user/vhost_kernel.c
> +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c
> @@ -91,6 +91,13 @@ struct vhost_memory_kernel {
>  #define IFF_ATTACH_QUEUE 0x0200
>  #define IFF_DETACH_QUEUE 0x0400
>  
> +/* 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. */
> +#define TUN_F_UFO	0x10	/* I can handle UFO packets */
> +
>  /* Constants */
>  #define TUN_DEF_SNDBUF	(1ull << 20)
>  #define PATH_NET_TUN	"/dev/net/tun"
> @@ -173,6 +180,28 @@ prepare_vhost_memory_kernel(void)
>  	return vm;
>  }
>  
> +/* with below features, vhost kernel does not need to do the checksum and TSO,
> + * these info will be passed to virtio_user through virtio net header.
> + */
> +static const uint64_t guest_offloads_mask =

The typical way is to define it as macro?

> +	(1ULL << VIRTIO_NET_F_GUEST_CSUM) |
> +	(1ULL << VIRTIO_NET_F_GUEST_TSO4) |
> +	(1ULL << VIRTIO_NET_F_GUEST_TSO6) |
> +	(1ULL << VIRTIO_NET_F_GUEST_ECN)  |
> +	(1ULL << VIRTIO_NET_F_GUEST_UFO);
> +
> @@ -271,6 +314,12 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
>  	int hdr_size;
>  	int vhostfd;
>  	int tapfd;
> +	unsigned int offload =
> +			TUN_F_CSUM |
> +			TUN_F_TSO4 |
> +			TUN_F_TSO6 |
> +			TUN_F_TSO_ECN |
> +			TUN_F_UFO;

Same here?

	--yliu