1 /*-
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.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
13 * disclaimer.
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.
17 *
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.
28 *
29 * $FreeBSD$
30 */
31 #ifndef _LINUXKPI_LINUX_INTERRUPT_H_
32 #define _LINUXKPI_LINUX_INTERRUPT_H_
33
34 #include <linux/cpu.h>
35 #include <linux/device.h>
36 #include <linux/pci.h>
37 #include <linux/irqreturn.h>
38 #include <linux/hardirq.h>
39
40 #include <sys/param.h>
41 #include <sys/interrupt.h>
42
43 typedef irqreturn_t (*irq_handler_t)(int, void *);
44
45 #define IRQF_SHARED RF_SHAREABLE
46
47 struct irq_ent;
48
49 void linux_irq_handler(void *);
50 void lkpi_devm_irq_release(struct device *, void *);
51 void lkpi_irq_release(struct device *, struct irq_ent *);
52 int lkpi_request_irq(struct device *, unsigned int, irq_handler_t,
53 irq_handler_t, unsigned long, const char *, void *);
54 int lkpi_enable_irq(unsigned int);
55 void lkpi_disable_irq(unsigned int);
56 int lkpi_bind_irq_to_cpu(unsigned int, int);
57 void lkpi_free_irq(unsigned int, void *);
58 void lkpi_devm_free_irq(struct device *, unsigned int, void *);
59
60 static inline int
request_irq(unsigned int irq,irq_handler_t handler,unsigned long flags,const char * name,void * arg)61 request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
62 const char *name, void *arg)
63 {
64
65 return (lkpi_request_irq(NULL, irq, handler, NULL, flags, name, arg));
66 }
67
68 static inline int
request_threaded_irq(int irq,irq_handler_t handler,irq_handler_t thread_handler,unsigned long flags,const char * name,void * arg)69 request_threaded_irq(int irq, irq_handler_t handler,
70 irq_handler_t thread_handler, unsigned long flags,
71 const char *name, void *arg)
72 {
73
74 return (lkpi_request_irq(NULL, irq, handler, thread_handler,
75 flags, name, arg));
76 }
77
78 static inline int
devm_request_threaded_irq(struct device * dev,int irq,irq_handler_t handler,irq_handler_t thread_handler,unsigned long flags,const char * name,void * arg)79 devm_request_threaded_irq(struct device *dev, int irq,
80 irq_handler_t handler, irq_handler_t thread_handler,
81 unsigned long flags, const char *name, void *arg)
82 {
83
84 return (lkpi_request_irq(dev, irq, handler, thread_handler,
85 flags, name, arg));
86 }
87
88 static inline int
enable_irq(unsigned int irq)89 enable_irq(unsigned int irq)
90 {
91 return (lkpi_enable_irq(irq));
92 }
93
94 static inline void
disable_irq(unsigned int irq)95 disable_irq(unsigned int irq)
96 {
97 lkpi_disable_irq(irq);
98 }
99
100 static inline int
bind_irq_to_cpu(unsigned int irq,int cpu_id)101 bind_irq_to_cpu(unsigned int irq, int cpu_id)
102 {
103 return (lkpi_bind_irq_to_cpu(irq, cpu_id));
104 }
105
106 static inline void
free_irq(unsigned int irq,void * device)107 free_irq(unsigned int irq, void *device)
108 {
109 lkpi_free_irq(irq, device);
110 }
111
112 static inline void
devm_free_irq(struct device * xdev,unsigned int irq,void * p)113 devm_free_irq(struct device *xdev, unsigned int irq, void *p)
114 {
115 lkpi_devm_free_irq(xdev, irq, p);
116 }
117
118 static inline int
irq_set_affinity_hint(int vector,cpumask_t * mask)119 irq_set_affinity_hint(int vector, cpumask_t *mask)
120 {
121 int error;
122
123 if (mask != NULL)
124 error = intr_setaffinity(vector, CPU_WHICH_IRQ, mask);
125 else
126 error = intr_setaffinity(vector, CPU_WHICH_IRQ, cpuset_root);
127
128 return (-error);
129 }
130
131 /*
132 * LinuxKPI tasklet support
133 */
134 typedef void tasklet_func_t(unsigned long);
135
136 struct tasklet_struct {
137 TAILQ_ENTRY(tasklet_struct) entry;
138 tasklet_func_t *func;
139 /* Our "state" implementation is different. Avoid same name as Linux. */
140 volatile u_int tasklet_state;
141 atomic_t count;
142 unsigned long data;
143 };
144
145 #define DECLARE_TASKLET(_name, _func, _data) \
146 struct tasklet_struct _name = { .func = (_func), .data = (_data) }
147
148 #define tasklet_hi_schedule(t) tasklet_schedule(t)
149
150 extern void tasklet_schedule(struct tasklet_struct *);
151 extern void tasklet_kill(struct tasklet_struct *);
152 extern void tasklet_init(struct tasklet_struct *, tasklet_func_t *,
153 unsigned long data);
154 extern void tasklet_enable(struct tasklet_struct *);
155 extern void tasklet_disable(struct tasklet_struct *);
156 extern void tasklet_disable_nosync(struct tasklet_struct *);
157 extern int tasklet_trylock(struct tasklet_struct *);
158 extern void tasklet_unlock(struct tasklet_struct *);
159 extern void tasklet_unlock_wait(struct tasklet_struct *ts);
160
161 #endif /* _LINUXKPI_LINUX_INTERRUPT_H_ */
162