2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef _LINUX_INTERRUPT_H_
32 #define _LINUX_INTERRUPT_H_
34 #include <linux/device.h>
35 #include <linux/pci.h>
40 typedef irqreturn_t (*irq_handler_t)(int, void *);
42 #define IRQ_RETVAL(x) ((x) != IRQ_NONE)
44 #define IRQF_SHARED RF_SHAREABLE
47 struct list_head links;
51 irqreturn_t (*handler)(int, void *);
57 _irq_rid(struct device *dev, int irq)
61 return irq - dev->msix + 1;
65 _irq_handler(void *ent)
70 irqe->handler(irqe->irq, irqe->arg);
73 static inline struct irq_ent *
74 _irq_ent(struct device *dev, int irq)
78 list_for_each_entry(irqe, &dev->irqents, links)
86 request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
87 const char *name, void *arg)
95 dev = _pci_find_irq_dev(irq);
98 rid = _irq_rid(dev, irq);
99 res = bus_alloc_resource_any(dev->bsddev, SYS_RES_IRQ, &rid,
103 irqe = kmalloc(sizeof(*irqe), GFP_KERNEL);
107 irqe->handler = handler;
109 error = bus_setup_intr(dev->bsddev, res, INTR_TYPE_NET | INTR_MPSAFE,
110 NULL, _irq_handler, irqe, &irqe->tag);
112 bus_release_resource(dev->bsddev, SYS_RES_IRQ, rid, irqe->res);
116 list_add(&irqe->links, &dev->irqents);
122 bind_irq_to_cpu(unsigned int irq, int cpu_id)
124 struct irq_ent *irqe;
127 dev = _pci_find_irq_dev(irq);
131 irqe = _irq_ent(dev, irq);
135 return (-bus_bind_intr(dev->bsddev, irqe->res, cpu_id));
139 free_irq(unsigned int irq, void *device)
141 struct irq_ent *irqe;
145 dev = _pci_find_irq_dev(irq);
148 rid = _irq_rid(dev, irq);
149 irqe = _irq_ent(dev, irq);
152 bus_teardown_intr(dev->bsddev, irqe->res, irqe->tag);
153 bus_release_resource(dev->bsddev, SYS_RES_IRQ, rid, irqe->res);
154 list_del(&irqe->links);
158 #endif /* _LINUX_INTERRUPT_H_ */