Add initial 2.6.22 support
[~emulex/for-vlad/old/compat.git] / include / linux / compat-2.6.31.h
1 #ifndef LINUX_26_31_COMPAT_H
2 #define LINUX_26_31_COMPAT_H
3
4 #include <linux/autoconf.h>
5 #include <linux/version.h>
6
7 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31))
8
9 #include <linux/skbuff.h>
10 #include <linux/workqueue.h>
11 #include <linux/interrupt.h>
12 #include <net/dst.h>
13 #include <net/genetlink.h>
14 #include <linux/ethtool.h>
15
16 /*
17  * These macros allow us to backport rfkill without any
18  * changes on cfg80211 through compat.diff. Note that this
19  * file will be included by rfkill_backport.h so we must
20  * not conflict with things there.
21  */
22 #define rfkill_get_led_trigger_name     backport_rfkill_get_led_trigger_name
23 #define rfkill_set_led_trigger_name     backport_rfkill_set_led_trigger_name
24 #define rfkill_set_hw_state     backport_rfkill_set_hw_state
25 #define rfkill_set_sw_state     backport_rfkill_set_sw_state
26 #define rfkill_init_sw_state    backport_rfkill_init_sw_state
27 #define rfkill_set_states       backport_rfkill_set_states
28 #define rfkill_pause_polling    backport_rfkill_pause_polling
29 #define rfkill_resume_polling   backport_rfkill_resume_polling
30 #define rfkill_blocked          backport_rfkill_blocked
31 #define rfkill_alloc            backport_rfkill_alloc
32 #define rfkill_register         backport_rfkill_register
33 #define rfkill_unregister       backport_rfkill_unregister
34 #define rfkill_destroy          backport_rfkill_destroy
35
36 #ifndef ERFKILL
37 #if !defined(CONFIG_ALPHA) && !defined(CONFIG_MIPS) && !defined(CONFIG_PARISC) && !defined(CONFIG_SPARC)
38 #define ERFKILL         132     /* Operation not possible due to RF-kill */
39 #endif
40 #ifdef CONFIG_ALPHA
41 #define ERFKILL         138     /* Operation not possible due to RF-kill */
42 #endif
43 #ifdef CONFIG_MIPS
44 #define ERFKILL         167     /* Operation not possible due to RF-kill */
45 #endif
46 #ifdef CONFIG_PARISC
47 #define ERFKILL         256     /* Operation not possible due to RF-kill */
48 #endif
49 #ifdef CONFIG_SPARC
50 #define ERFKILL         134     /* Operation not possible due to RF-kill */
51 #endif
52 #endif
53
54 #ifndef NETDEV_PRE_UP
55 #define NETDEV_PRE_UP           0x000D
56 #endif
57
58 #ifndef SDIO_DEVICE_ID_MARVELL_8688WLAN
59 #define SDIO_DEVICE_ID_MARVELL_8688WLAN         0x9104
60 #endif
61
62 struct compat_threaded_irq {
63         unsigned int irq;
64         irq_handler_t handler;
65         irq_handler_t thread_fn;
66         void *dev_id;
67         char wq_name[64];
68         struct workqueue_struct *wq;
69         struct work_struct work;
70 };
71
72 /*
73  * kmemleak was introduced on 2.6.31, since older kernels do not have
74  * we simply ignore its tuning.
75  */
76 static inline void kmemleak_ignore(const void *ptr)
77 {
78         return;
79 }
80
81 static inline void kmemleak_not_leak(const void *ptr)
82 {
83         return;
84 }
85
86 static inline void kmemleak_no_scan(const void *ptr)
87 {
88         return;
89 }
90
91 /*
92  * Added via adf30907d63893e4208dfe3f5c88ae12bc2f25d5
93  *
94  * There is no _sk_dst on older kernels, so just set the
95  * old dst to NULL and release it directly.
96  */
97 static inline void skb_dst_drop(struct sk_buff *skb)
98 {
99         dst_release(skb->dst);
100         skb->dst = NULL;
101 }
102
103 static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
104 {
105         return (struct dst_entry *)skb->dst;
106 }
107
108 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
109 {
110         skb->dst = dst;
111 }
112
113 static inline struct rtable *skb_rtable(const struct sk_buff *skb)
114 {
115         return (struct rtable *)skb_dst(skb);
116 }
117
118 extern int genl_register_family_with_ops(struct genl_family *family,
119         struct genl_ops *ops, size_t n_ops);
120
121
122 /* Backport threaded IRQ support */
123
124 static inline
125 void compat_irq_work(struct work_struct *work)
126 {
127         struct compat_threaded_irq *comp = container_of(work, struct compat_threaded_irq, work);
128         comp->thread_fn(comp->irq, comp->dev_id);
129 }
130
131 static inline
132 irqreturn_t compat_irq_dispatcher(int irq, void *dev_id)
133 {
134         struct compat_threaded_irq *comp = dev_id;
135         irqreturn_t res;
136
137         res = comp->handler(irq, comp->dev_id);
138         if (res == IRQ_WAKE_THREAD) {
139                 queue_work(comp->wq, &comp->work);
140                 res = IRQ_HANDLED;
141         }
142
143         return res;
144 }
145
146 static inline
147 int compat_request_threaded_irq(struct compat_threaded_irq *comp,
148                                 unsigned int irq,
149                                 irq_handler_t handler,
150                                 irq_handler_t thread_fn,
151                                 unsigned long flags,
152                                 const char *name,
153                                 void *dev_id)
154 {
155         comp->irq = irq;
156         comp->handler = handler;
157         comp->thread_fn = thread_fn;
158         comp->dev_id = dev_id;
159         INIT_WORK(&comp->work, compat_irq_work);
160
161         if (!comp->wq) {
162                 snprintf(comp->wq_name, sizeof(comp->wq_name),
163                          "compirq/%u-%s", irq, name);
164                 comp->wq = create_singlethread_workqueue(comp->wq_name);
165                 if (!comp->wq) {
166                         printk(KERN_ERR "Failed to create compat-threaded-IRQ workqueue %s\n",
167                                comp->wq_name);
168                         return -ENOMEM;
169                 }
170         }
171         return request_irq(irq, compat_irq_dispatcher, flags, name, comp);
172 }
173
174 static inline
175 void compat_free_threaded_irq(struct compat_threaded_irq *comp)
176 {
177         free_irq(comp->irq, comp);
178 }
179
180 static inline
181 void compat_destroy_threaded_irq(struct compat_threaded_irq *comp)
182 {
183         if (comp->wq)
184                 destroy_workqueue(comp->wq);
185         comp->wq = NULL;
186 }
187
188 static inline
189 void compat_synchronize_threaded_irq(struct compat_threaded_irq *comp)
190 {
191         synchronize_irq(comp->irq);
192         cancel_work_sync(&comp->work);
193 }
194
195
196 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */
197
198 #endif /* LINUX_26_31_COMPAT_H */