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