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 _LINUX_INTERRUPT_H_ 32 #define _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 int lkpi_request_irq(struct device *, unsigned int, irq_handler_t, 48 irq_handler_t, unsigned long, const char *, void *); 49 int lkpi_enable_irq(unsigned int); 50 void lkpi_disable_irq(unsigned int); 51 int lkpi_bind_irq_to_cpu(unsigned int, int); 52 void lkpi_free_irq(unsigned int, void *); 53 void lkpi_devm_free_irq(struct device *, unsigned int, void *); 54 55 static inline int 56 request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, 57 const char *name, void *arg) 58 { 59 60 return (lkpi_request_irq(NULL, irq, handler, NULL, flags, name, arg)); 61 } 62 63 static inline int 64 request_threaded_irq(int irq, irq_handler_t handler, 65 irq_handler_t thread_handler, unsigned long flags, 66 const char *name, void *arg) 67 { 68 69 return (lkpi_request_irq(NULL, irq, handler, thread_handler, 70 flags, name, arg)); 71 } 72 73 static inline int 74 devm_request_threaded_irq(struct device *dev, int irq, 75 irq_handler_t handler, irq_handler_t thread_handler, 76 unsigned long flags, const char *name, void *arg) 77 { 78 79 return (lkpi_request_irq(dev, irq, handler, thread_handler, 80 flags, name, arg)); 81 } 82 83 static inline int 84 enable_irq(unsigned int irq) 85 { 86 return (lkpi_enable_irq(irq)); 87 } 88 89 static inline void 90 disable_irq(unsigned int irq) 91 { 92 lkpi_disable_irq(irq); 93 } 94 95 static inline int 96 bind_irq_to_cpu(unsigned int irq, int cpu_id) 97 { 98 return (lkpi_bind_irq_to_cpu(irq, cpu_id)); 99 } 100 101 static inline void 102 free_irq(unsigned int irq, void *device) 103 { 104 lkpi_free_irq(irq, device); 105 } 106 107 static inline void 108 devm_free_irq(struct device *xdev, unsigned int irq, void *p) 109 { 110 lkpi_devm_free_irq(xdev, irq, p); 111 } 112 113 static inline int 114 irq_set_affinity_hint(int vector, cpumask_t *mask) 115 { 116 int error; 117 118 if (mask != NULL) 119 error = intr_setaffinity(vector, CPU_WHICH_IRQ, mask); 120 else 121 error = intr_setaffinity(vector, CPU_WHICH_IRQ, cpuset_root); 122 123 return (-error); 124 } 125 126 /* 127 * LinuxKPI tasklet support 128 */ 129 typedef void tasklet_func_t(unsigned long); 130 131 struct tasklet_struct { 132 TAILQ_ENTRY(tasklet_struct) entry; 133 tasklet_func_t *func; 134 /* Our "state" implementation is different. Avoid same name as Linux. */ 135 volatile u_int tasklet_state; 136 atomic_t count; 137 unsigned long data; 138 }; 139 140 #define DECLARE_TASKLET(_name, _func, _data) \ 141 struct tasklet_struct _name = { .func = (_func), .data = (_data) } 142 143 #define tasklet_hi_schedule(t) tasklet_schedule(t) 144 145 extern void tasklet_schedule(struct tasklet_struct *); 146 extern void tasklet_kill(struct tasklet_struct *); 147 extern void tasklet_init(struct tasklet_struct *, tasklet_func_t *, 148 unsigned long data); 149 extern void tasklet_enable(struct tasklet_struct *); 150 extern void tasklet_disable(struct tasklet_struct *); 151 extern void tasklet_disable_nosync(struct tasklet_struct *); 152 extern int tasklet_trylock(struct tasklet_struct *); 153 extern void tasklet_unlock(struct tasklet_struct *); 154 extern void tasklet_unlock_wait(struct tasklet_struct *ts); 155 156 #endif /* _LINUX_INTERRUPT_H_ */ 157