lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210216160525.5028-11-maciej.kwapulinski@linux.intel.com>
Date:   Tue, 16 Feb 2021 17:05:23 +0100
From:   Maciej Kwapulinski <maciej.kwapulinski@...ux.intel.com>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Arnd Bergmann <arnd@...db.de>,
        Jonathan Corbet <corbet@....net>,
        Derek Kiernan <derek.kiernan@...inx.com>,
        Dragan Cvetic <dragan.cvetic@...inx.com>
Cc:     linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
        Maciej Kwapulinski <maciej.kwapulinski@...ux.intel.com>,
        Tomasz Jankowski <tomasz1.jankowski@...el.com>,
        Savo Novakovic <savox.novakovic@...el.com>,
        Jianxun Zhang <jianxun.zhang@...ux.intel.com>
Subject: [PATCH v1 10/12] gna: add interrupt handler

From: Tomasz Jankowski <tomasz1.jankowski@...el.com>

An interrupt is generated by the hardware when a scoring job is
done. The interrupt handler wakes up the work queue to resume
the processing on the current request.

Signed-off-by: Tomasz Jankowski <tomasz1.jankowski@...el.com>
Tested-by: Savo Novakovic <savox.novakovic@...el.com>
Co-developed-by: Jianxun Zhang <jianxun.zhang@...ux.intel.com>
Signed-off-by: Jianxun Zhang <jianxun.zhang@...ux.intel.com>
Signed-off-by: Maciej Kwapulinski <maciej.kwapulinski@...ux.intel.com>
---
 drivers/misc/gna/gna_device.c | 32 ++++++++++++++++++++++++++++++--
 drivers/misc/gna/gna_device.h |  2 ++
 drivers/misc/gna/gna_hw.c     | 10 ++++++++++
 drivers/misc/gna/gna_hw.h     |  2 ++
 4 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/gna/gna_device.c b/drivers/misc/gna/gna_device.c
index a229f51fb17b..5198326e8af4 100644
--- a/drivers/misc/gna/gna_device.c
+++ b/drivers/misc/gna/gna_device.c
@@ -182,6 +182,27 @@ int gna_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
 		goto err_clear_master;
 	}
 
+	ret = pci_alloc_irq_vectors(pcidev, 1, 1, PCI_IRQ_ALL_TYPES);
+	if (ret < 0)
+		goto err_clear_master;
+
+	gna_priv->irq = pci_irq_vector(pcidev, 0);
+	if (unlikely(gna_priv->irq < 0)) {
+		dev_err(&pcidev->dev, "could not obtain irq number\n");
+		ret = -EIO;
+		goto err_free_irq_vector;
+	}
+
+	ret = request_irq(gna_priv->irq, gna_interrupt,
+				   IRQF_SHARED, GNA_DRV_NAME, gna_priv);
+
+	if (ret) {
+		dev_err(&pcidev->dev, "could not register for interrupt\n");
+		goto err_free_irq_vector;
+	}
+
+	dev_dbg(&pcidev->dev, "irq num %d\n", gna_priv->irq);
+
 	/* Map BAR0 */
 	gna_priv->bar0.iostart = pci_resource_start(pcidev, 0);
 	gna_priv->bar0.iosize = pci_resource_len(pcidev, 0);
@@ -189,7 +210,7 @@ int gna_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
 	if (!gna_priv->bar0.mem_addr) {
 		dev_err(&pcidev->dev, "could not map BAR 0\n");
 		ret = -EINVAL;
-		goto err_clear_master;
+		goto err_free_irq;
 	}
 
 	dev_dbg(&pcidev->dev, "bar0 io start: 0x%llx\n", (unsigned long long)gna_priv->bar0.iostart);
@@ -199,11 +220,15 @@ int gna_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
 	ret = gna_dev_init(gna_priv, pcidev, pci_id);
 	if (ret) {
 		dev_err(&pcidev->dev, "could not initialize gna private structure\n");
-		goto err_clear_master;
+		goto err_free_irq;
 	}
 
 	return 0;
 
+err_free_irq:
+	free_irq(gna_priv->irq, gna_priv);
+err_free_irq_vector:
+	pci_free_irq_vectors(pcidev);
 err_clear_master:
 	pci_clear_master(pcidev);
 err_release_regions:
@@ -219,7 +244,10 @@ void gna_remove(struct pci_dev *pcidev)
 
 	gna_priv = pci_get_drvdata(pcidev);
 
+	free_irq(gna_priv->irq, gna_priv);
+
 	gna_dev_deinit(gna_priv);
+	pci_free_irq_vectors(pcidev);
 
 	pci_clear_master(pcidev);
 	pci_release_regions(pcidev);
diff --git a/drivers/misc/gna/gna_device.h b/drivers/misc/gna/gna_device.h
index 0855972cd085..77cd1a458367 100644
--- a/drivers/misc/gna/gna_device.h
+++ b/drivers/misc/gna/gna_device.h
@@ -46,12 +46,14 @@ struct gna_private {
 	struct device dev;
 	struct cdev cdev;
 
+	/* hardware status set by interrupt handler */
 	u32 hw_status;
 
 	/* device related resources */
 	struct gna_pci_bar bar0;
 	struct gna_drv_info info;
 	struct gna_hw_info hw_info;
+	int irq;
 
 	struct gna_mmu_object mmu;
 	/* lock protecting mmu structure */
diff --git a/drivers/misc/gna/gna_hw.c b/drivers/misc/gna/gna_hw.c
index 48e09e5f3ca8..6146cbd43004 100644
--- a/drivers/misc/gna/gna_hw.c
+++ b/drivers/misc/gna/gna_hw.c
@@ -124,3 +124,13 @@ void gna_abort_hw(struct gna_private *gna_priv)
 	if (i == 0)
 		dev_err(&gna_priv->dev, "abort did not complete\n");
 }
+
+irqreturn_t gna_interrupt(int irq, void *priv)
+{
+	struct gna_private *gna_priv;
+
+	gna_priv = (struct gna_private *)priv;
+	gna_priv->busy = false;
+	wake_up(&gna_priv->busy_waitq);
+	return IRQ_HANDLED;
+}
diff --git a/drivers/misc/gna/gna_hw.h b/drivers/misc/gna/gna_hw.h
index 4da29870c4dc..4dfa05937943 100644
--- a/drivers/misc/gna/gna_hw.h
+++ b/drivers/misc/gna/gna_hw.h
@@ -6,6 +6,7 @@
 
 #include <linux/bits.h>
 #include <linux/bitfield.h>
+#include <linux/interrupt.h>
 #include <linux/io.h>
 
 /* GNA MMIO registers */
@@ -70,6 +71,7 @@ struct gna_desc_info {
 struct gna_private;
 struct gna_compute_cfg;
 
+irqreturn_t gna_interrupt(int irq, void *ctx);
 void gna_abort_hw(struct gna_private *gna_priv);
 bool gna_hw_perf_enabled(struct gna_private *gna_priv);
 int gna_parse_hw_status(struct gna_private *gna_priv, u32 hw_status);
-- 
2.28.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ