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>
36 #include <linux/irqreturn.h>
41 typedef irqreturn_t (*irq_handler_t)(int, void *);
43 #define IRQF_SHARED RF_SHAREABLE
46 struct list_head links;
50 irqreturn_t (*handler)(int, void *);
56 linux_irq_rid(struct device *dev, unsigned int irq)
58 /* check for MSI- or MSIX- interrupt */
59 if (irq >= dev->irq_start && irq < dev->irq_end)
60 return (irq - dev->irq_start + 1);
65 extern void linux_irq_handler(void *);
67 static inline struct irq_ent *
68 linux_irq_ent(struct device *dev, unsigned int irq)
72 list_for_each_entry(irqe, &dev->irqents, links)
80 request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
81 const char *name, void *arg)
89 dev = linux_pci_find_irq_dev(irq);
92 rid = linux_irq_rid(dev, irq);
93 res = bus_alloc_resource_any(dev->bsddev, SYS_RES_IRQ, &rid,
97 irqe = kmalloc(sizeof(*irqe), GFP_KERNEL);
101 irqe->handler = handler;
103 error = bus_setup_intr(dev->bsddev, res, INTR_TYPE_NET | INTR_MPSAFE,
104 NULL, linux_irq_handler, irqe, &irqe->tag);
106 bus_release_resource(dev->bsddev, SYS_RES_IRQ, rid, irqe->res);
110 list_add(&irqe->links, &dev->irqents);
116 enable_irq(unsigned int irq)
118 struct irq_ent *irqe;
121 dev = linux_pci_find_irq_dev(irq);
124 irqe = linux_irq_ent(dev, irq);
125 if (irqe == NULL || irqe->tag != NULL)
127 return -bus_setup_intr(dev->bsddev, irqe->res, INTR_TYPE_NET | INTR_MPSAFE,
128 NULL, linux_irq_handler, irqe, &irqe->tag);
132 disable_irq(unsigned int irq)
134 struct irq_ent *irqe;
137 dev = linux_pci_find_irq_dev(irq);
140 irqe = linux_irq_ent(dev, irq);
143 if (irqe->tag != NULL)
144 bus_teardown_intr(dev->bsddev, irqe->res, irqe->tag);
149 bind_irq_to_cpu(unsigned int irq, int cpu_id)
151 struct irq_ent *irqe;
154 dev = linux_pci_find_irq_dev(irq);
158 irqe = linux_irq_ent(dev, irq);
162 return (-bus_bind_intr(dev->bsddev, irqe->res, cpu_id));
166 free_irq(unsigned int irq, void *device)
168 struct irq_ent *irqe;
172 dev = linux_pci_find_irq_dev(irq);
175 rid = linux_irq_rid(dev, irq);
176 irqe = linux_irq_ent(dev, irq);
179 if (irqe->tag != NULL)
180 bus_teardown_intr(dev->bsddev, irqe->res, irqe->tag);
181 bus_release_resource(dev->bsddev, SYS_RES_IRQ, rid, irqe->res);
182 list_del(&irqe->links);
187 * LinuxKPI tasklet support
189 typedef void tasklet_func_t(unsigned long);
191 struct tasklet_struct {
192 TAILQ_ENTRY(tasklet_struct) entry;
193 tasklet_func_t *func;
194 /* Our "state" implementation is different. Avoid same name as Linux. */
195 volatile u_int tasklet_state;
200 #define DECLARE_TASKLET(_name, _func, _data) \
201 struct tasklet_struct _name = { .func = (_func), .data = (_data) }
203 #define tasklet_hi_schedule(t) tasklet_schedule(t)
205 extern void tasklet_schedule(struct tasklet_struct *);
206 extern void tasklet_kill(struct tasklet_struct *);
207 extern void tasklet_init(struct tasklet_struct *, tasklet_func_t *,
209 extern void tasklet_enable(struct tasklet_struct *);
210 extern void tasklet_disable(struct tasklet_struct *);
211 extern int tasklet_trylock(struct tasklet_struct *);
212 extern void tasklet_unlock(struct tasklet_struct *);
213 extern void tasklet_unlock_wait(struct tasklet_struct *ts);
215 #endif /* _LINUX_INTERRUPT_H_ */