From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ferruh.yigit@intel.com>
Received: from mga14.intel.com (mga14.intel.com [192.55.52.115])
 by dpdk.org (Postfix) with ESMTP id 7842C8D38
 for <dev@dpdk.org>; Thu, 15 Sep 2016 17:49:30 +0200 (CEST)
Received: from fmsmga006.fm.intel.com ([10.253.24.20])
 by fmsmga103.fm.intel.com with ESMTP; 15 Sep 2016 08:49:29 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.30,339,1470726000"; 
   d="scan'208";a="8961434"
Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain)
 ([10.237.217.46])
 by fmsmga006.fm.intel.com with ESMTP; 15 Sep 2016 08:49:28 -0700
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
 Ferruh Yigit <ferruh.yigit@itnel.com>
Date: Thu, 15 Sep 2016 16:46:45 +0100
Message-Id: <1473954405-7150-20-git-send-email-ferruh.yigit@intel.com>
X-Mailer: git-send-email 1.7.0.7
In-Reply-To: <1473954405-7150-1-git-send-email-ferruh.yigit@intel.com>
References: <1473954405-7150-1-git-send-email-ferruh.yigit@intel.com>
Subject: [dpdk-dev] [PATCH 19/19] kni: move kernel version ifdefs to compat
	header
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <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: Thu, 15 Sep 2016 15:49:30 -0000

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/linuxapp/kni/compat.h    | 12 ++++++++++++
 lib/librte_eal/linuxapp/kni/kni_vhost.c | 16 +++++-----------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/linuxapp/kni/compat.h b/lib/librte_eal/linuxapp/kni/compat.h
index 9ae50a7..78da08e 100644
--- a/lib/librte_eal/linuxapp/kni/compat.h
+++ b/lib/librte_eal/linuxapp/kni/compat.h
@@ -20,6 +20,14 @@
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
 #define sk_sleep(s) ((s)->sk_sleep)
+#else
+#define HAVE_SOCKET_WQ
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
+#define HAVE_STATIC_SOCK_MAP_FD
+#else
+#define kni_sock_map_fd(s) sock_map_fd(s, 0)
 #endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
@@ -39,6 +47,10 @@
 #define HAVE_REBUILD_HEADER
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+#define HAVE_SK_ALLOC_KERN_PARAM
+#endif
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
 #define HAVE_TRANS_START_HELPER
 #endif
diff --git a/lib/librte_eal/linuxapp/kni/kni_vhost.c b/lib/librte_eal/linuxapp/kni/kni_vhost.c
index 3ba0c57..f54c34b 100644
--- a/lib/librte_eal/linuxapp/kni/kni_vhost.c
+++ b/lib/librte_eal/linuxapp/kni/kni_vhost.c
@@ -40,7 +40,7 @@
 
 #define RX_BURST_SZ 4
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
+#ifdef HAVE_STATIC_SOCK_MAP_FD
 static int kni_sock_map_fd(struct socket *sock)
 {
 	struct file *file;
@@ -57,8 +57,6 @@ static int kni_sock_map_fd(struct socket *sock)
 	fd_install(fd, file);
 	return fd;
 }
-#else
-#define kni_sock_map_fd(s)             sock_map_fd(s, 0)
 #endif
 
 static struct proto kni_raw_proto = {
@@ -225,17 +223,13 @@ kni_sock_poll(struct file *file, struct socket *sock, poll_table *wait)
 		return POLLERR;
 
 	kni = q->kni;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
+#ifdef HAVE_SOCKET_WQ
 	pr_debug("start kni_poll on group %d, wq 0x%16llx\n",
 		  kni->group_id, (uint64_t)sock->wq);
+	poll_wait(file, &sock->wq->wait, wait);
 #else
 	pr_debug("start kni_poll on group %d, wait at 0x%16llx\n",
 		  kni->group_id, (uint64_t)&sock->wait);
-#endif
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
-	poll_wait(file, &sock->wq->wait, wait);
-#else
 	poll_wait(file, &sock->wait, wait);
 #endif
 
@@ -663,7 +657,7 @@ kni_vhost_backend_init(struct kni_dev *kni)
 	if (kni->vhost_queue != NULL)
 		return -1;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+#ifdef HAVE_SK_ALLOC_KERN_PARAM
 	q = (struct kni_vhost_queue *)sk_alloc(net, AF_UNSPEC, GFP_KERNEL,
 			&kni_raw_proto, 0);
 #else
@@ -729,7 +723,7 @@ kni_vhost_backend_init(struct kni_dev *kni)
 
 	kni->vq_status = BE_START;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
+#ifdef HAVE_SOCKET_WQ
 	pr_debug("backend init sockfd=%d, sock->wq=0x%16llx,sk->sk_wq=0x%16llx",
 		  q->sockfd, (uint64_t)q->sock->wq,
 		  (uint64_t)q->sk.sk_wq);
-- 
2.7.4