From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stephen@networkplumber.org>
Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com
 [209.85.220.52]) by dpdk.org (Postfix) with ESMTP id C593A592E
 for <dev@dpdk.org>; Fri, 25 Jul 2014 19:36:23 +0200 (CEST)
Received: by mail-pa0-f52.google.com with SMTP id bj1so6464330pad.11
 for <dev@dpdk.org>; Fri, 25 Jul 2014 10:37:55 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version
 :content-type:content-transfer-encoding;
 bh=5hcSZXrg1+cEAME2yFLPYc/i0/XjtfwtrOLBFE1bJE4=;
 b=P3I7OznyhT4TP2lBhzdyPxXEeZSV2rKykDGs90FsOWM3AzjWAYWsPjhtWSbqROrcQM
 M5OL5nyh9EC9h4vudsmzrNGhdNQZhA4VJnF4Uj1wSw1XAhv7hP7dH7hVCchLKG6VCXvP
 QZIwjisrnpz5IyOGPlHjn0Gr1PatgiklQddum3cFq+J98PP8nxY0AQZ81IYoVWsRs4wG
 SoYpmJEMgknfYrRLimjVnqtT0uVYy002Cm6h6fZD0g+uXQExOBobeXmJGXK6fRcMnSJu
 0TSKjwkWCkw5gsKChvpG2Yfhcb59kzzVNgf7p2W+M6ezCzmhei3xL+cLWBwhfU/Q3z3t
 Ietg==
X-Gm-Message-State: ALoCoQm4o5Lcg1yje+F5tHGF9l9QtaJK20dxlD9IWmM62thKLV5R/iQQ9Dd6rFVcsJ/l2HNZ8gEv
X-Received: by 10.67.22.65 with SMTP id hq1mr5386265pad.137.1406309875347;
 Fri, 25 Jul 2014 10:37:55 -0700 (PDT)
Received: from haswell.linuxnetplumber.net
 (static-50-53-72-226.bvtn.or.frontiernet.net. [50.53.72.226])
 by mx.google.com with ESMTPSA id fx5sm9448852pbb.62.2014.07.25.10.37.54
 for <multiple recipients>
 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Fri, 25 Jul 2014 10:37:55 -0700 (PDT)
Date: Fri, 25 Jul 2014 10:36:27 -0700
From: Stephen Hemminger <stephen@networkplumber.org>
To: Thomas Monjalon <thomas.monjalon@6wind.com>, Yerden Zhumabekov
 <e_zhumabekov@sts.kz>
Message-ID: <20140725103627.4ca989b7@haswell.linuxnetplumber.net>
X-Mailer: Claws Mail 3.10.1 (GTK+ 2.24.24; x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 1/2] igb_uio: fix compability on old kernel
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: Fri, 25 Jul 2014 17:36:24 -0000

Add more compatibility wrappers, and split out all the wrapper
code to a separate file. Builds on Debian Squeeze (2.6.32) which
is oldest version of kernel current DPDK supports.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

---
 lib/librte_eal/linuxapp/igb_uio/compat.h  |  103 ++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/igb_uio/igb_uio.c |   81 -----------------------
 2 files changed, 104 insertions(+), 80 deletions(-)

--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/lib/librte_eal/linuxapp/igb_uio/compat.h	2014-07-25 10:29:58.664127988 -0700
@@ -0,0 +1,103 @@
+/*
+ * Minimal wrappers to allow compiling igb_uio on older kernels.
+ */
+
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
+#define pci_cfg_access_lock   pci_block_user_cfg_access
+#define pci_cfg_access_unlock pci_unblock_user_cfg_access
+#endif
+
+#ifndef PCI_MSIX_ENTRY_SIZE
+#define PCI_MSIX_ENTRY_SIZE             16
+#define  PCI_MSIX_ENTRY_LOWER_ADDR      0
+#define  PCI_MSIX_ENTRY_UPPER_ADDR      4
+#define  PCI_MSIX_ENTRY_DATA            8
+#define  PCI_MSIX_ENTRY_VECTOR_CTRL     12
+#define   PCI_MSIX_ENTRY_CTRL_MASKBIT   1
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
+static int pci_num_vf(struct pci_dev *dev)
+{
+	struct iov {
+		int pos;
+		int nres;
+		u32 cap;
+		u16 ctrl;
+		u16 total;
+		u16 initial;
+		u16 nr_virtfn;
+	} *iov = (struct iov *)dev->sriov;
+
+	if (!dev->is_physfn)
+		return 0;
+
+	return iov->nr_virtfn;
+}
+#endif
+
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
+
+/* Check if INTX works to control irq's.
+ * Set's INTX_DISABLE flag and reads it back
+ */
+static bool pci_intx_mask_supported(struct pci_dev *pdev)
+{
+	bool mask_supported = false;
+	uint16_t orig, new;
+
+	pci_block_user_cfg_access(pdev);
+	pci_read_config_word(pdev, PCI_COMMAND, &orig);
+	pci_write_config_word(pdev, PCI_COMMAND,
+			      orig ^ PCI_COMMAND_INTX_DISABLE);
+	pci_read_config_word(pdev, PCI_COMMAND, &new);
+
+	if ((new ^ orig) & ~PCI_COMMAND_INTX_DISABLE) {
+		dev_err(&pdev->dev, "Command register changed from "
+			"0x%x to 0x%x: driver or hardware bug?\n", orig, new);
+	} else if ((new ^ orig) & PCI_COMMAND_INTX_DISABLE) {
+		mask_supported = true;
+		pci_write_config_word(pdev, PCI_COMMAND, orig);
+	}
+	pci_unblock_user_cfg_access(pdev);
+
+	return mask_supported;
+}
+
+static bool pci_check_and_mask_intx(struct pci_dev *pdev)
+{
+	bool pending;
+	uint32_t status;
+
+	pci_block_user_cfg_access(pdev);
+	pci_read_config_dword(pdev, PCI_COMMAND, &status);
+
+	/* interrupt is not ours, goes to out */
+	pending = (((status >> 16) & PCI_STATUS_INTERRUPT) != 0);
+	if (pending) {
+		uint16_t old, new;
+
+		old = status;
+		if (status != 0)
+			new = old & (~PCI_COMMAND_INTX_DISABLE);
+		else
+			new = old | PCI_COMMAND_INTX_DISABLE;
+
+		if (old != new)
+			pci_write_config_word(pdev, PCI_COMMAND, new);
+	}
+	pci_unblock_user_cfg_access(pdev);
+
+	return pending;
+}
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
+/* Compatability wrapper for new kernel API for IRQ */
+#define irq_data	irq_desc
+#define irq_get_irq_data(irq)	irq_to_desc(irq)
+#define irq_data_get_msi(data)	get_irq_desc_msi(data)
+#endif
+
--- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c	2014-07-25 10:29:58.668128002 -0700
+++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c	2014-07-25 10:29:58.664127988 -0700
@@ -37,10 +37,7 @@
 #endif
 #include <rte_pci_dev_features.h>
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
-#define pci_cfg_access_lock   pci_block_user_cfg_access
-#define pci_cfg_access_unlock pci_unblock_user_cfg_access
-#endif
+#include "compat.h"
 
 #ifdef RTE_PCI_CONFIG
 #define PCI_SYS_FILE_BUF_SIZE      10
@@ -70,26 +67,6 @@ igbuio_get_uio_pci_dev(struct uio_info *
 }
 
 /* sriov sysfs */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
-static int pci_num_vf(struct pci_dev *dev)
-{
-	struct iov {
-		int pos;
-		int nres;
-		u32 cap;
-		u16 ctrl;
-		u16 total;
-		u16 initial;
-		u16 nr_virtfn;
-	} *iov = (struct iov *)dev->sriov;
-
-	if (!dev->is_physfn)
-		return 0;
-
-	return iov->nr_virtfn;
-}
-#endif
-
 static ssize_t
 show_max_vfs(struct device *dev, struct device_attribute *attr,
 	     char *buf)
@@ -228,62 +205,6 @@ static struct attribute *dev_attrs[] = {
 static const struct attribute_group dev_attr_grp = {
 	.attrs = dev_attrs,
 };
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
-/* Check if INTX works to control irq's.
- * Set's INTX_DISABLE flag and reads it back
- */
-static bool pci_intx_mask_supported(struct pci_dev *pdev)
-{
-	bool mask_supported = false;
-	uint16_t orig, new;
-
-	pci_block_user_cfg_access(pdev);
-	pci_read_config_word(pdev, PCI_COMMAND, &orig);
-	pci_write_config_word(pdev, PCI_COMMAND,
-			      orig ^ PCI_COMMAND_INTX_DISABLE);
-	pci_read_config_word(pdev, PCI_COMMAND, &new);
-
-	if ((new ^ orig) & ~PCI_COMMAND_INTX_DISABLE) {
-		dev_err(&pdev->dev, "Command register changed from "
-			"0x%x to 0x%x: driver or hardware bug?\n", orig, new);
-	} else if ((new ^ orig) & PCI_COMMAND_INTX_DISABLE) {
-		mask_supported = true;
-		pci_write_config_word(pdev, PCI_COMMAND, orig);
-	}
-	pci_unblock_user_cfg_access(pdev);
-
-	return mask_supported;
-}
-
-static bool pci_check_and_mask_intx(struct pci_dev *pdev)
-{
-	bool pending;
-	uint32_t status;
-
-	pci_block_user_cfg_access(pdev);
-	pci_read_config_dword(pdev, PCI_COMMAND, &status);
-
-	/* interrupt is not ours, goes to out */
-	pending = (((status >> 16) & PCI_STATUS_INTERRUPT) != 0);
-	if (pending) {
-		uint16_t old, new;
-
-		old = status;
-		if (status != 0)
-			new = old & (~PCI_COMMAND_INTX_DISABLE);
-		else
-			new = old | PCI_COMMAND_INTX_DISABLE;
-
-		if (old != new)
-			pci_write_config_word(pdev, PCI_COMMAND, new);
-	}
-	pci_unblock_user_cfg_access(pdev);
-
-	return pending;
-}
-#endif
-
 /*
  * It masks the msix on/off of generating MSI-X messages.
  */