From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stephen@networkplumber.org>
Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com
 [209.85.220.53]) by dpdk.org (Postfix) with ESMTP id A2276C660
 for <dev@dpdk.org>; Tue, 28 Apr 2015 18:36:38 +0200 (CEST)
Received: by pabsx10 with SMTP id sx10so261604pab.3
 for <dev@dpdk.org>; Tue, 28 Apr 2015 09:36:38 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=gMHvKLUzp0DE/gTdAOBABxCh2eyGhTNI5tw0IQDa3bQ=;
 b=JBz71sjlBgJ/DOt67zibu4Kp/unmp1JfjzP/tx5I1uS8o/YOi96HEAreaSXlO4yirk
 nDoxpW4IC4M+giflGYEkboyLRd2XS4thG8A8QuwEa5Daw36dyRhWFbG6ShFR/TCeDWkH
 TZA75nALoIErDTVNo0po9TCuXzJiTZAz/KWdq4yt5QtQ0LxTfR+M2L0HiMu8duB2ASZ2
 S3gzESjDTzGX145ut7AR1YN4HyFqbW6HbTD5nlDz1IBz1C2Rmh+mBuR0sOC/bT5p0pzY
 EdjYy+QeXVEYc1fJKPOxhT5QSnLVyYvRBghDKNi6iDsd/7m/tat66oho+tj565WmJTY0
 O/Fw==
X-Gm-Message-State: ALoCoQkEeuLKXWXy9YKFMKgh9IvNgXYwgEF9f5mt+/H0cZ2Q6ixUUBGe/83RcUjY5WNTMY/8NLse
X-Received: by 10.68.231.66 with SMTP id te2mr34004374pbc.118.1430238997995;
 Tue, 28 Apr 2015 09:36:37 -0700 (PDT)
Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net.
 [50.53.82.155])
 by mx.google.com with ESMTPSA id yc2sm22833392pbb.87.2015.04.28.09.36.37
 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Tue, 28 Apr 2015 09:36:37 -0700 (PDT)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Date: Tue, 28 Apr 2015 09:36:38 -0700
Message-Id: <1430239000-30881-2-git-send-email-stephen@networkplumber.org>
X-Mailer: git-send-email 2.1.4
In-Reply-To: <1430239000-30881-1-git-send-email-stephen@networkplumber.org>
References: <1430239000-30881-1-git-send-email-stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH 1/3] uio: fix irq handling with igb_uio
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: Tue, 28 Apr 2015 16:36:39 -0000

The introduction of uio_pci_generic broke interrupt handling with
igb_uio. The igb_uio device uses the kernel read/write method to
enable disable IRQ's; the uio_pci_generic has to use PCI intx
config read/write to enable disable interrupts.

Since igb_uio uses MSI-X the PCI intx config read/write won't
work.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       | 40 ++++++++++++++++++++--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 15 +++++---
 .../linuxapp/eal/include/exec-env/rte_interrupts.h |  3 +-
 3 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index 66deda2..3a84b3c 100644
--- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
@@ -361,7 +361,7 @@ vfio_disable_msix(struct rte_intr_handle *intr_handle) {
 #endif
 
 static int
-uio_intr_disable(struct rte_intr_handle *intr_handle)
+uio_intx_intr_disable(struct rte_intr_handle *intr_handle)
 {
 	unsigned char command_high;
 
@@ -385,7 +385,7 @@ uio_intr_disable(struct rte_intr_handle *intr_handle)
 }
 
 static int
-uio_intr_enable(struct rte_intr_handle *intr_handle)
+uio_intx_intr_enable(struct rte_intr_handle *intr_handle)
 {
 	unsigned char command_high;
 
@@ -408,6 +408,34 @@ uio_intr_enable(struct rte_intr_handle *intr_handle)
 	return 0;
 }
 
+static int
+uio_intr_disable(struct rte_intr_handle *intr_handle)
+{
+	const int value = 0;
+
+	if (write(intr_handle->fd, &value, sizeof(value)) < 0) {
+		RTE_LOG(ERR, EAL,
+			"Error disabling interrupts for fd %d (%s)\n",
+			intr_handle->fd, strerror(errno));
+		return -1;
+	}
+	return 0;
+}
+
+static int
+uio_intr_enable(struct rte_intr_handle *intr_handle)
+{
+	const int value = 1;
+
+	if (write(intr_handle->fd, &value, sizeof(value)) < 0) {
+		RTE_LOG(ERR, EAL,
+			"Error enabling interrupts for fd %d (%s)\n",
+			intr_handle->fd, strerror(errno));
+		return -1;
+	}
+	return 0;
+}
+
 int
 rte_intr_callback_register(struct rte_intr_handle *intr_handle,
 			rte_intr_callback_fn cb, void *cb_arg)
@@ -556,6 +584,10 @@ rte_intr_enable(struct rte_intr_handle *intr_handle)
 		if (uio_intr_enable(intr_handle))
 			return -1;
 		break;
+	case RTE_INTR_HANDLE_UIO_INTX:
+		if (uio_intx_intr_enable(intr_handle))
+			return -1;
+		break;
 	/* not used at this moment */
 	case RTE_INTR_HANDLE_ALARM:
 		return -1;
@@ -596,6 +628,10 @@ rte_intr_disable(struct rte_intr_handle *intr_handle)
 		if (uio_intr_disable(intr_handle))
 			return -1;
 		break;
+	case RTE_INTR_HANDLE_UIO_INTX:
+		if (uio_intx_intr_disable(intr_handle))
+			return -1;
+		break;
 	/* not used at this moment */
 	case RTE_INTR_HANDLE_ALARM:
 		return -1;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 2d1c69b..b5116a7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -299,7 +299,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 			devname, strerror(errno));
 		return -1;
 	}
-	dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
 
 	snprintf(cfgname, sizeof(cfgname),
 			"/sys/class/uio/uio%u/device/config", uio_num);
@@ -310,10 +309,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		return -1;
 	}
 
-	/* set bus master that is not done by uio_pci_generic */
-	if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
-		RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
-		return -1;
+	if (dev->kdrv == RTE_KDRV_IGB_UIO)
+		dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
+	else {
+		dev->intr_handle.type = RTE_INTR_HANDLE_UIO_INTX;
+
+		/* set bus master that is not done by uio_pci_generic */
+		if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
+			RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
+			return -1;
+		}
 	}
 
 	/* allocate the mapping details for secondary processes*/
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
index 6a159c7..bdeb3fc 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
@@ -40,7 +40,8 @@
 
 enum rte_intr_handle_type {
 	RTE_INTR_HANDLE_UNKNOWN = 0,
-	RTE_INTR_HANDLE_UIO,      /**< uio device handle */
+	RTE_INTR_HANDLE_UIO,          /**< uio device handle */
+	RTE_INTR_HANDLE_UIO_INTX,     /**< uio generic handle */
 	RTE_INTR_HANDLE_VFIO_LEGACY,  /**< vfio device handle (legacy) */
 	RTE_INTR_HANDLE_VFIO_MSI,     /**< vfio device handle (MSI) */
 	RTE_INTR_HANDLE_VFIO_MSIX,    /**< vfio device handle (MSIX) */
-- 
2.1.4