xref: /freebsd/sys/compat/linuxkpi/common/include/linux/interrupt.h (revision a9e0f316b3da4144c654cf77542bc5c51632e896)
18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky  * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Panasas, Inc.
58d59ecb2SHans Petter Selasky  * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky  * All rights reserved.
78d59ecb2SHans Petter Selasky  *
88d59ecb2SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky  * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky  * are met:
118d59ecb2SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky  *    disclaimer.
148d59ecb2SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky  *
188d59ecb2SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky  */
29307f78f3SVladimir Kondratyev #ifndef	_LINUXKPI_LINUX_INTERRUPT_H_
30307f78f3SVladimir Kondratyev #define	_LINUXKPI_LINUX_INTERRUPT_H_
318d59ecb2SHans Petter Selasky 
32602e4e43SBjoern A. Zeeb #include <linux/cpu.h>
338d59ecb2SHans Petter Selasky #include <linux/device.h>
348d59ecb2SHans Petter Selasky #include <linux/pci.h>
357353335dSHans Petter Selasky #include <linux/irqreturn.h>
36602e4e43SBjoern A. Zeeb #include <linux/hardirq.h>
378d59ecb2SHans Petter Selasky 
38d16b6cb1SBjoern A. Zeeb #include <sys/param.h>
39602e4e43SBjoern A. Zeeb #include <sys/interrupt.h>
408d59ecb2SHans Petter Selasky 
418d59ecb2SHans Petter Selasky typedef	irqreturn_t	(*irq_handler_t)(int, void *);
428d59ecb2SHans Petter Selasky 
4396ab16ebSVladimir Kondratyev #define	IRQF_SHARED		0x0004	/* Historically */
44bc81a2b7SBjoern A. Zeeb #define	IRQF_NOBALANCING	0
45bc81a2b7SBjoern A. Zeeb 
46bc81a2b7SBjoern A. Zeeb #define	IRQ_DISABLE_UNLAZY	0
478d59ecb2SHans Petter Selasky 
48210e756dSJean-Sébastien Pédron #define	IRQ_NOTCONNECTED	(1U << 31)
49210e756dSJean-Sébastien Pédron 
5066ea3906SVladimir Kondratyev int  lkpi_request_irq(struct device *, unsigned int, irq_handler_t,
5166ea3906SVladimir Kondratyev 	irq_handler_t, unsigned long, const char *, void *);
5266ea3906SVladimir Kondratyev int  lkpi_enable_irq(unsigned int);
5366ea3906SVladimir Kondratyev void lkpi_disable_irq(unsigned int);
5466ea3906SVladimir Kondratyev int  lkpi_bind_irq_to_cpu(unsigned int, int);
5566ea3906SVladimir Kondratyev void lkpi_free_irq(unsigned int, void *);
5666ea3906SVladimir Kondratyev void lkpi_devm_free_irq(struct device *, unsigned int, void *);
578d59ecb2SHans Petter Selasky 
58d16b6cb1SBjoern A. Zeeb static inline int
request_irq(unsigned int irq,irq_handler_t handler,unsigned long flags,const char * name,void * arg)59d16b6cb1SBjoern A. Zeeb request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
60d16b6cb1SBjoern A. Zeeb     const char *name, void *arg)
61d16b6cb1SBjoern A. Zeeb {
62d16b6cb1SBjoern A. Zeeb 
6366ea3906SVladimir Kondratyev 	return (lkpi_request_irq(NULL, irq, handler, NULL, flags, name, arg));
64d16b6cb1SBjoern A. Zeeb }
65d16b6cb1SBjoern A. Zeeb 
66d16b6cb1SBjoern A. Zeeb 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)67d16b6cb1SBjoern A. Zeeb request_threaded_irq(int irq, irq_handler_t handler,
68d16b6cb1SBjoern A. Zeeb     irq_handler_t thread_handler, unsigned long flags,
69d16b6cb1SBjoern A. Zeeb     const char *name, void *arg)
70d16b6cb1SBjoern A. Zeeb {
71d16b6cb1SBjoern A. Zeeb 
7266ea3906SVladimir Kondratyev 	return (lkpi_request_irq(NULL, irq, handler, thread_handler,
73d16b6cb1SBjoern A. Zeeb 	    flags, name, arg));
74d16b6cb1SBjoern A. Zeeb }
75d16b6cb1SBjoern A. Zeeb 
76d16b6cb1SBjoern A. Zeeb static inline int
devm_request_irq(struct device * dev,int irq,irq_handler_t handler,unsigned long flags,const char * name,void * arg)776e8d6761SBjoern A. Zeeb devm_request_irq(struct device *dev, int irq,
786e8d6761SBjoern A. Zeeb     irq_handler_t handler, unsigned long flags, const char *name, void *arg)
796e8d6761SBjoern A. Zeeb {
806e8d6761SBjoern A. Zeeb 
816e8d6761SBjoern A. Zeeb 	return (lkpi_request_irq(dev, irq, handler, NULL, flags, name, arg));
826e8d6761SBjoern A. Zeeb }
836e8d6761SBjoern A. Zeeb 
846e8d6761SBjoern A. Zeeb 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)85d16b6cb1SBjoern A. Zeeb devm_request_threaded_irq(struct device *dev, int irq,
86d16b6cb1SBjoern A. Zeeb     irq_handler_t handler, irq_handler_t thread_handler,
87d16b6cb1SBjoern A. Zeeb     unsigned long flags, const char *name, void *arg)
88d16b6cb1SBjoern A. Zeeb {
89d16b6cb1SBjoern A. Zeeb 
9066ea3906SVladimir Kondratyev 	return (lkpi_request_irq(dev, irq, handler, thread_handler,
91d16b6cb1SBjoern A. Zeeb 	    flags, name, arg));
928d59ecb2SHans Petter Selasky }
938d59ecb2SHans Petter Selasky 
948d59ecb2SHans Petter Selasky static inline int
enable_irq(unsigned int irq)95219ff59cSHans Petter Selasky enable_irq(unsigned int irq)
96219ff59cSHans Petter Selasky {
9766ea3906SVladimir Kondratyev 	return (lkpi_enable_irq(irq));
98219ff59cSHans Petter Selasky }
99219ff59cSHans Petter Selasky 
100219ff59cSHans Petter Selasky static inline void
disable_irq(unsigned int irq)101219ff59cSHans Petter Selasky disable_irq(unsigned int irq)
102219ff59cSHans Petter Selasky {
10366ea3906SVladimir Kondratyev 	lkpi_disable_irq(irq);
104219ff59cSHans Petter Selasky }
105219ff59cSHans Petter Selasky 
106bc81a2b7SBjoern A. Zeeb static inline void
disable_irq_nosync(unsigned int irq)107bc81a2b7SBjoern A. Zeeb disable_irq_nosync(unsigned int irq)
108bc81a2b7SBjoern A. Zeeb {
109bc81a2b7SBjoern A. Zeeb 	lkpi_disable_irq(irq);
110bc81a2b7SBjoern A. Zeeb }
111bc81a2b7SBjoern A. Zeeb 
112219ff59cSHans Petter Selasky static inline int
bind_irq_to_cpu(unsigned int irq,int cpu_id)1138d59ecb2SHans Petter Selasky bind_irq_to_cpu(unsigned int irq, int cpu_id)
1148d59ecb2SHans Petter Selasky {
11566ea3906SVladimir Kondratyev 	return (lkpi_bind_irq_to_cpu(irq, cpu_id));
1168d59ecb2SHans Petter Selasky }
1178d59ecb2SHans Petter Selasky 
1188d59ecb2SHans Petter Selasky static inline void
free_irq(unsigned int irq,void * device)11966ea3906SVladimir Kondratyev free_irq(unsigned int irq, void *device)
1208d59ecb2SHans Petter Selasky {
12166ea3906SVladimir Kondratyev 	lkpi_free_irq(irq, device);
1228d59ecb2SHans Petter Selasky }
1238d59ecb2SHans Petter Selasky 
124d16b6cb1SBjoern A. Zeeb static inline void
devm_free_irq(struct device * xdev,unsigned int irq,void * p)125d16b6cb1SBjoern A. Zeeb devm_free_irq(struct device *xdev, unsigned int irq, void *p)
126d16b6cb1SBjoern A. Zeeb {
12766ea3906SVladimir Kondratyev 	lkpi_devm_free_irq(xdev, irq, p);
128d16b6cb1SBjoern A. Zeeb }
129d16b6cb1SBjoern A. Zeeb 
130602e4e43SBjoern A. Zeeb static inline int
irq_set_affinity_hint(int vector,const cpumask_t * mask)1314c72d075SBjoern A. Zeeb irq_set_affinity_hint(int vector, const cpumask_t *mask)
132602e4e43SBjoern A. Zeeb {
133602e4e43SBjoern A. Zeeb 	int error;
134602e4e43SBjoern A. Zeeb 
135602e4e43SBjoern A. Zeeb 	if (mask != NULL)
136*a9e0f316SElliott Mitchell 		error = intr_setaffinity(vector, CPU_WHICH_IRQ, mask);
137602e4e43SBjoern A. Zeeb 	else
138602e4e43SBjoern A. Zeeb 		error = intr_setaffinity(vector, CPU_WHICH_IRQ, cpuset_root);
139602e4e43SBjoern A. Zeeb 
140602e4e43SBjoern A. Zeeb 	return (-error);
141602e4e43SBjoern A. Zeeb }
142602e4e43SBjoern A. Zeeb 
1434b56afafSBjoern A. Zeeb static inline struct msi_desc *
irq_get_msi_desc(unsigned int irq)1444b56afafSBjoern A. Zeeb irq_get_msi_desc(unsigned int irq)
1454b56afafSBjoern A. Zeeb {
1464b56afafSBjoern A. Zeeb 
1474b56afafSBjoern A. Zeeb 	return (lkpi_pci_msi_desc_alloc(irq));
1484b56afafSBjoern A. Zeeb }
1494b56afafSBjoern A. Zeeb 
150bc81a2b7SBjoern A. Zeeb static inline void
irq_set_status_flags(unsigned int irq __unused,unsigned long flags __unused)151bc81a2b7SBjoern A. Zeeb irq_set_status_flags(unsigned int irq __unused, unsigned long flags __unused)
152bc81a2b7SBjoern A. Zeeb {
153bc81a2b7SBjoern A. Zeeb }
154bc81a2b7SBjoern A. Zeeb 
155ef23481aSHans Petter Selasky /*
156ef23481aSHans Petter Selasky  * LinuxKPI tasklet support
157ef23481aSHans Petter Selasky  */
158f2978460SBjoern A. Zeeb struct tasklet_struct;
159ef23481aSHans Petter Selasky typedef void tasklet_func_t(unsigned long);
160f2978460SBjoern A. Zeeb typedef void tasklet_callback_t(struct tasklet_struct *);
161ef23481aSHans Petter Selasky 
162ef23481aSHans Petter Selasky struct tasklet_struct {
163ef23481aSHans Petter Selasky 	TAILQ_ENTRY(tasklet_struct) entry;
164ef23481aSHans Petter Selasky 	tasklet_func_t *func;
165480995dcSJohannes Lundberg 	/* Our "state" implementation is different. Avoid same name as Linux. */
166480995dcSJohannes Lundberg 	volatile u_int tasklet_state;
167480995dcSJohannes Lundberg 	atomic_t count;
168ef23481aSHans Petter Selasky 	unsigned long data;
169f2978460SBjoern A. Zeeb 	tasklet_callback_t *callback;
170f2978460SBjoern A. Zeeb 	bool use_callback;
171ef23481aSHans Petter Selasky };
172ef23481aSHans Petter Selasky 
1736575da5eSHans Petter Selasky #define	DECLARE_TASKLET(_name, _func, _data)	\
1746575da5eSHans Petter Selasky struct tasklet_struct _name = { .func = (_func), .data = (_data) }
175ef23481aSHans Petter Selasky 
176ef23481aSHans Petter Selasky #define	tasklet_hi_schedule(t)	tasklet_schedule(t)
177ef23481aSHans Petter Selasky 
178f2978460SBjoern A. Zeeb /* Some other compat code in the tree has this defined as well. */
179f2978460SBjoern A. Zeeb #define	from_tasklet(_dev, _t, _field)		\
180f2978460SBjoern A. Zeeb     container_of(_t, typeof(*(_dev)), _field)
181f2978460SBjoern A. Zeeb 
182f2978460SBjoern A. Zeeb void tasklet_setup(struct tasklet_struct *, tasklet_callback_t *);
183ef23481aSHans Petter Selasky extern void tasklet_schedule(struct tasklet_struct *);
184ef23481aSHans Petter Selasky extern void tasklet_kill(struct tasklet_struct *);
185ef23481aSHans Petter Selasky extern void tasklet_init(struct tasklet_struct *, tasklet_func_t *,
186ef23481aSHans Petter Selasky     unsigned long data);
187f1f7e04aSHans Petter Selasky extern void tasklet_enable(struct tasklet_struct *);
188f1f7e04aSHans Petter Selasky extern void tasklet_disable(struct tasklet_struct *);
1899781105bSNeel Chauhan extern void tasklet_disable_nosync(struct tasklet_struct *);
190480995dcSJohannes Lundberg extern int tasklet_trylock(struct tasklet_struct *);
191480995dcSJohannes Lundberg extern void tasklet_unlock(struct tasklet_struct *);
192480995dcSJohannes Lundberg extern void tasklet_unlock_wait(struct tasklet_struct *ts);
1932272ccaaSJean-Sébastien Pédron #define	tasklet_unlock_spin_wait(ts)	tasklet_unlock_wait(ts)
194ef23481aSHans Petter Selasky 
195307f78f3SVladimir Kondratyev #endif	/* _LINUXKPI_LINUX_INTERRUPT_H_ */
196