xref: /freebsd/sys/compat/linuxkpi/common/include/linux/interrupt.h (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
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 #define	IRQF_NOBALANCING	0
47 
48 #define	IRQ_DISABLE_UNLAZY	0
49 
50 #define	IRQ_NOTCONNECTED	(1U << 31)
51 
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
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
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
79 devm_request_irq(struct device *dev, int irq,
80     irq_handler_t handler, unsigned long flags, const char *name, void *arg)
81 {
82 
83 	return (lkpi_request_irq(dev, irq, handler, NULL, flags, name, arg));
84 }
85 
86 static inline int
87 devm_request_threaded_irq(struct device *dev, int irq,
88     irq_handler_t handler, irq_handler_t thread_handler,
89     unsigned long flags, const char *name, void *arg)
90 {
91 
92 	return (lkpi_request_irq(dev, irq, handler, thread_handler,
93 	    flags, name, arg));
94 }
95 
96 static inline int
97 enable_irq(unsigned int irq)
98 {
99 	return (lkpi_enable_irq(irq));
100 }
101 
102 static inline void
103 disable_irq(unsigned int irq)
104 {
105 	lkpi_disable_irq(irq);
106 }
107 
108 static inline void
109 disable_irq_nosync(unsigned int irq)
110 {
111 	lkpi_disable_irq(irq);
112 }
113 
114 static inline int
115 bind_irq_to_cpu(unsigned int irq, int cpu_id)
116 {
117 	return (lkpi_bind_irq_to_cpu(irq, cpu_id));
118 }
119 
120 static inline void
121 free_irq(unsigned int irq, void *device)
122 {
123 	lkpi_free_irq(irq, device);
124 }
125 
126 static inline void
127 devm_free_irq(struct device *xdev, unsigned int irq, void *p)
128 {
129 	lkpi_devm_free_irq(xdev, irq, p);
130 }
131 
132 static inline int
133 irq_set_affinity_hint(int vector, const cpumask_t *mask)
134 {
135 	int error;
136 
137 	if (mask != NULL)
138 		error = intr_setaffinity(vector, CPU_WHICH_IRQ, __DECONST(cpumask_t *, mask));
139 	else
140 		error = intr_setaffinity(vector, CPU_WHICH_IRQ, cpuset_root);
141 
142 	return (-error);
143 }
144 
145 static inline struct msi_desc *
146 irq_get_msi_desc(unsigned int irq)
147 {
148 
149 	return (lkpi_pci_msi_desc_alloc(irq));
150 }
151 
152 static inline void
153 irq_set_status_flags(unsigned int irq __unused, unsigned long flags __unused)
154 {
155 }
156 
157 /*
158  * LinuxKPI tasklet support
159  */
160 struct tasklet_struct;
161 typedef void tasklet_func_t(unsigned long);
162 typedef void tasklet_callback_t(struct tasklet_struct *);
163 
164 struct tasklet_struct {
165 	TAILQ_ENTRY(tasklet_struct) entry;
166 	tasklet_func_t *func;
167 	/* Our "state" implementation is different. Avoid same name as Linux. */
168 	volatile u_int tasklet_state;
169 	atomic_t count;
170 	unsigned long data;
171 	tasklet_callback_t *callback;
172 	bool use_callback;
173 };
174 
175 #define	DECLARE_TASKLET(_name, _func, _data)	\
176 struct tasklet_struct _name = { .func = (_func), .data = (_data) }
177 
178 #define	tasklet_hi_schedule(t)	tasklet_schedule(t)
179 
180 /* Some other compat code in the tree has this defined as well. */
181 #define	from_tasklet(_dev, _t, _field)		\
182     container_of(_t, typeof(*(_dev)), _field)
183 
184 void tasklet_setup(struct tasklet_struct *, tasklet_callback_t *);
185 extern void tasklet_schedule(struct tasklet_struct *);
186 extern void tasklet_kill(struct tasklet_struct *);
187 extern void tasklet_init(struct tasklet_struct *, tasklet_func_t *,
188     unsigned long data);
189 extern void tasklet_enable(struct tasklet_struct *);
190 extern void tasklet_disable(struct tasklet_struct *);
191 extern void tasklet_disable_nosync(struct tasklet_struct *);
192 extern int tasklet_trylock(struct tasklet_struct *);
193 extern void tasklet_unlock(struct tasklet_struct *);
194 extern void tasklet_unlock_wait(struct tasklet_struct *ts);
195 #define	tasklet_unlock_spin_wait(ts)	tasklet_unlock_wait(ts)
196 
197 #endif	/* _LINUXKPI_LINUX_INTERRUPT_H_ */
198