[PATCH v3 10/14] intel_gna: add interrupt handler

From: Maciej Kwapulinski
Date: Thu May 13 2021 - 07:03:42 EST


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: Maciej Kwapulinski <maciej.kwapulinski@xxxxxxxxxxxxxxx>
Tested-by: Savo Novakovic <savox.novakovic@xxxxxxxxx>
Co-developed-by: Tomasz Jankowski <tomasz1.jankowski@xxxxxxxxx>
Signed-off-by: Tomasz Jankowski <tomasz1.jankowski@xxxxxxxxx>
Co-developed-by: Jianxun Zhang <jianxun.zhang@xxxxxxxxxxxxxxx>
Signed-off-by: Jianxun Zhang <jianxun.zhang@xxxxxxxxxxxxxxx>
---
drivers/misc/intel/gna/device.c | 20 ++++++++++++++++++-
drivers/misc/intel/gna/device.h | 2 +-
drivers/misc/intel/gna/pci.c | 35 ++++++++++++++++++++++++++++++++-
3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/intel/gna/device.c b/drivers/misc/intel/gna/device.c
index ca988d3ec408..75d8e1675485 100644
--- a/drivers/misc/intel/gna/device.c
+++ b/drivers/misc/intel/gna/device.c
@@ -3,6 +3,7 @@

#include <linux/device.h>
#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
#include <linux/module.h>

#include "device.h"
@@ -23,6 +24,16 @@ static void gna_devm_idr_destroy(void *data)
idr_destroy(idr);
}

+static irqreturn_t gna_interrupt(int irq, void *priv)
+{
+ struct gna_private *gna_priv;
+
+ gna_priv = (struct gna_private *)priv;
+ gna_priv->dev_busy = false;
+ wake_up(&gna_priv->dev_busy_waitq);
+ return IRQ_HANDLED;
+}
+
static void gna_devm_destroy_workqueue(void *data)
{
struct workqueue_struct *request_wq = data;
@@ -51,7 +62,7 @@ static int gna_devm_create_singlethread_workqueue(struct gna_private *gna_priv)
return ret;
}

-int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase)
+int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase, int irq)
{
static atomic_t dev_last_idx = ATOMIC_INIT(-1);
struct gna_private *gna_priv;
@@ -124,6 +135,13 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
if (ret)
return ret;

+ ret = devm_request_irq(parent, irq, gna_interrupt,
+ IRQF_SHARED, dev_misc_name, gna_priv);
+ if (ret) {
+ dev_err(parent, "could not register for interrupt\n");
+ return ret;
+ }
+
return 0;
}

diff --git a/drivers/misc/intel/gna/device.h b/drivers/misc/intel/gna/device.h
index 65856d08729f..d3c86d649b5c 100644
--- a/drivers/misc/intel/gna/device.h
+++ b/drivers/misc/intel/gna/device.h
@@ -70,7 +70,7 @@ struct gna_private {
struct mutex memidr_lock;
};

-int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
+int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase, int irq);

static inline u32 gna_reg_read(struct gna_private *gna_priv, u32 reg)
{
diff --git a/drivers/misc/intel/gna/pci.c b/drivers/misc/intel/gna/pci.c
index 525e9de9d577..a31f0142a4f2 100644
--- a/drivers/misc/intel/gna/pci.c
+++ b/drivers/misc/intel/gna/pci.c
@@ -69,10 +69,33 @@ static const struct pci_device_id gna_pci_ids[] = {
{ }
};

+static void gna_pcim_free_irq_vectors(void *data)
+{
+ struct pci_dev *pcidev = data;
+
+ pci_free_irq_vectors(pcidev);
+}
+
+static int gna_pcim_alloc_irq_vectors(struct pci_dev *pcidev)
+{
+ int ret;
+
+ ret = pci_alloc_irq_vectors(pcidev, 1, 1, PCI_IRQ_ALL_TYPES);
+ if (ret < 0)
+ return ret;
+
+ ret = devm_add_action(&pcidev->dev, gna_pcim_free_irq_vectors, pcidev);
+ if (ret)
+ gna_pcim_free_irq_vectors(pcidev);
+
+ return ret;
+}
+
int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
{
struct gna_dev_info *dev_info;
void __iomem *iobase;
+ int irq;
int ret;

ret = pcim_enable_device(pcidev);
@@ -91,9 +114,19 @@ int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)

pci_set_master(pcidev);

+ ret = gna_pcim_alloc_irq_vectors(pcidev);
+ if (ret < 0)
+ return ret;
+
+ irq = pci_irq_vector(pcidev, 0);
+ if (unlikely(irq < 0)) {
+ dev_err(&pcidev->dev, "could not get irq number\n");
+ return -EIO;
+ }
+
dev_info = (struct gna_dev_info *)pci_id->driver_data;

- ret = gna_probe(&pcidev->dev, dev_info, iobase);
+ ret = gna_probe(&pcidev->dev, dev_info, iobase, irq);
if (ret) {
dev_err(&pcidev->dev, "could not initialize device\n");
return ret;
--
2.28.0