remove the old broadcom wl driver for linux 2.4
[openwrt/svn-archive/archive.git] / target / linux / generic-2.4 / files / crypto / ocf / ocf-compat.h
1 #ifndef _BSD_COMPAT_H_
2 #define _BSD_COMPAT_H_ 1
3 /****************************************************************************/
4 /*
5 * Provide compat routines for older linux kernels and BSD kernels
6 *
7 * Written by David McCullough <david_mccullough@mcafee.com>
8 * Copyright (C) 2010 David McCullough <david_mccullough@mcafee.com>
9 *
10 * LICENSE TERMS
11 *
12 * The free distribution and use of this software in both source and binary
13 * form is allowed (with or without changes) provided that:
14 *
15 * 1. distributions of this source code include the above copyright
16 * notice, this list of conditions and the following disclaimer;
17 *
18 * 2. distributions in binary form include the above copyright
19 * notice, this list of conditions and the following disclaimer
20 * in the documentation and/or other associated materials;
21 *
22 * 3. the copyright holder's name is not used to endorse products
23 * built using this software without specific written permission.
24 *
25 * ALTERNATIVELY, provided that this notice is retained in full, this file
26 * may be distributed under the terms of the GNU General Public License (GPL),
27 * in which case the provisions of the GPL apply INSTEAD OF those given above.
28 *
29 * DISCLAIMER
30 *
31 * This software is provided 'as is' with no explicit or implied warranties
32 * in respect of its properties, including, but not limited to, correctness
33 * and/or fitness for purpose.
34 */
35 /****************************************************************************/
36 #ifdef __KERNEL__
37 /*
38 * fake some BSD driver interface stuff specifically for OCF use
39 */
40
41 typedef struct ocf_device *device_t;
42
43 typedef struct {
44 int (*cryptodev_newsession)(device_t dev, u_int32_t *sidp, struct cryptoini *cri);
45 int (*cryptodev_freesession)(device_t dev, u_int64_t tid);
46 int (*cryptodev_process)(device_t dev, struct cryptop *crp, int hint);
47 int (*cryptodev_kprocess)(device_t dev, struct cryptkop *krp, int hint);
48 } device_method_t;
49 #define DEVMETHOD(id, func) id: func
50
51 struct ocf_device {
52 char name[32]; /* the driver name */
53 char nameunit[32]; /* the driver name + HW instance */
54 int unit;
55 device_method_t methods;
56 void *softc;
57 };
58
59 #define CRYPTODEV_NEWSESSION(dev, sid, cri) \
60 ((*(dev)->methods.cryptodev_newsession)(dev,sid,cri))
61 #define CRYPTODEV_FREESESSION(dev, sid) \
62 ((*(dev)->methods.cryptodev_freesession)(dev, sid))
63 #define CRYPTODEV_PROCESS(dev, crp, hint) \
64 ((*(dev)->methods.cryptodev_process)(dev, crp, hint))
65 #define CRYPTODEV_KPROCESS(dev, krp, hint) \
66 ((*(dev)->methods.cryptodev_kprocess)(dev, krp, hint))
67
68 #define device_get_name(dev) ((dev)->name)
69 #define device_get_nameunit(dev) ((dev)->nameunit)
70 #define device_get_unit(dev) ((dev)->unit)
71 #define device_get_softc(dev) ((dev)->softc)
72
73 #define softc_device_decl \
74 struct ocf_device _device; \
75 device_t
76
77 #define softc_device_init(_sc, _name, _unit, _methods) \
78 if (1) {\
79 strncpy((_sc)->_device.name, _name, sizeof((_sc)->_device.name) - 1); \
80 snprintf((_sc)->_device.nameunit, sizeof((_sc)->_device.name), "%s%d", _name, _unit); \
81 (_sc)->_device.unit = _unit; \
82 (_sc)->_device.methods = _methods; \
83 (_sc)->_device.softc = (void *) _sc; \
84 *(device_t *)((softc_get_device(_sc))+1) = &(_sc)->_device; \
85 } else
86
87 #define softc_get_device(_sc) (&(_sc)->_device)
88
89 /*
90 * iomem support for 2.4 and 2.6 kernels
91 */
92 #include <linux/version.h>
93 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
94 #define ocf_iomem_t unsigned long
95
96 /*
97 * implement simple workqueue like support for older kernels
98 */
99
100 #include <linux/tqueue.h>
101
102 #define work_struct tq_struct
103
104 #define INIT_WORK(wp, fp, ap) \
105 do { \
106 (wp)->sync = 0; \
107 (wp)->routine = (fp); \
108 (wp)->data = (ap); \
109 } while (0)
110
111 #define schedule_work(wp) \
112 do { \
113 queue_task((wp), &tq_immediate); \
114 mark_bh(IMMEDIATE_BH); \
115 } while (0)
116
117 #define flush_scheduled_work() run_task_queue(&tq_immediate)
118
119 #else
120 #define ocf_iomem_t void __iomem *
121
122 #include <linux/workqueue.h>
123
124 #endif
125
126 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
127 #include <linux/fdtable.h>
128 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
129 #define files_fdtable(files) (files)
130 #endif
131
132 #ifdef MODULE_PARM
133 #undef module_param /* just in case */
134 #define module_param(a,b,c) MODULE_PARM(a,"i")
135 #endif
136
137 #define bzero(s,l) memset(s,0,l)
138 #define bcopy(s,d,l) memcpy(d,s,l)
139 #define bcmp(x, y, l) memcmp(x,y,l)
140
141 #define MIN(x,y) ((x) < (y) ? (x) : (y))
142
143 #define device_printf(dev, a...) ({ \
144 printk("%s: ", device_get_nameunit(dev)); printk(a); \
145 })
146
147 #undef printf
148 #define printf(fmt...) printk(fmt)
149
150 #define KASSERT(c,p) if (!(c)) { printk p ; } else
151
152 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
153 #define ocf_daemonize(str) \
154 daemonize(); \
155 spin_lock_irq(&current->sigmask_lock); \
156 sigemptyset(&current->blocked); \
157 recalc_sigpending(current); \
158 spin_unlock_irq(&current->sigmask_lock); \
159 sprintf(current->comm, str);
160 #else
161 #define ocf_daemonize(str) daemonize(str);
162 #endif
163
164 #define TAILQ_INSERT_TAIL(q,d,m) list_add_tail(&(d)->m, (q))
165 #define TAILQ_EMPTY(q) list_empty(q)
166 #define TAILQ_FOREACH(v, q, m) list_for_each_entry(v, q, m)
167
168 #define read_random(p,l) get_random_bytes(p,l)
169
170 #define DELAY(x) ((x) > 2000 ? mdelay((x)/1000) : udelay(x))
171 #define strtoul simple_strtoul
172
173 #define pci_get_vendor(dev) ((dev)->vendor)
174 #define pci_get_device(dev) ((dev)->device)
175
176 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
177 #define pci_set_consistent_dma_mask(dev, mask) (0)
178 #endif
179 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
180 #define pci_dma_sync_single_for_cpu pci_dma_sync_single
181 #endif
182
183 #ifndef DMA_32BIT_MASK
184 #define DMA_32BIT_MASK 0x00000000ffffffffULL
185 #endif
186
187 #ifndef htole32
188 #define htole32(x) cpu_to_le32(x)
189 #endif
190 #ifndef htobe32
191 #define htobe32(x) cpu_to_be32(x)
192 #endif
193 #ifndef htole16
194 #define htole16(x) cpu_to_le16(x)
195 #endif
196 #ifndef htobe16
197 #define htobe16(x) cpu_to_be16(x)
198 #endif
199
200 /* older kernels don't have these */
201
202 #include <asm/irq.h>
203 #if !defined(IRQ_NONE) && !defined(IRQ_RETVAL)
204 #define IRQ_NONE
205 #define IRQ_HANDLED
206 #define IRQ_WAKE_THREAD
207 #define IRQ_RETVAL
208 #define irqreturn_t void
209 typedef irqreturn_t (*irq_handler_t)(int irq, void *arg, struct pt_regs *regs);
210 #endif
211 #ifndef IRQF_SHARED
212 #define IRQF_SHARED SA_SHIRQ
213 #endif
214
215 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
216 # define strlcpy(dest,src,len) \
217 ({strncpy(dest,src,(len)-1); ((char *)dest)[(len)-1] = '\0'; })
218 #endif
219
220 #ifndef MAX_ERRNO
221 #define MAX_ERRNO 4095
222 #endif
223 #ifndef IS_ERR_VALUE
224 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,5)
225 #include <linux/err.h>
226 #endif
227 #ifndef IS_ERR_VALUE
228 #define IS_ERR_VALUE(x) ((unsigned long)(x) >= (unsigned long)-MAX_ERRNO)
229 #endif
230 #endif
231
232 /*
233 * common debug for all
234 */
235 #if 1
236 #define dprintk(a...) do { if (debug) printk(a); } while(0)
237 #else
238 #define dprintk(a...)
239 #endif
240
241 #ifndef SLAB_ATOMIC
242 /* Changed in 2.6.20, must use GFP_ATOMIC now */
243 #define SLAB_ATOMIC GFP_ATOMIC
244 #endif
245
246 /*
247 * need some additional support for older kernels */
248 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,2)
249 #define pci_register_driver_compat(driver, rc) \
250 do { \
251 if ((rc) > 0) { \
252 (rc) = 0; \
253 } else if (rc == 0) { \
254 (rc) = -ENODEV; \
255 } else { \
256 pci_unregister_driver(driver); \
257 } \
258 } while (0)
259 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
260 #define pci_register_driver_compat(driver,rc) ((rc) = (rc) < 0 ? (rc) : 0)
261 #else
262 #define pci_register_driver_compat(driver,rc)
263 #endif
264
265 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
266
267 #include <linux/mm.h>
268 #include <asm/scatterlist.h>
269
270 static inline void sg_set_page(struct scatterlist *sg, struct page *page,
271 unsigned int len, unsigned int offset)
272 {
273 sg->page = page;
274 sg->offset = offset;
275 sg->length = len;
276 }
277
278 static inline void *sg_virt(struct scatterlist *sg)
279 {
280 return page_address(sg->page) + sg->offset;
281 }
282
283 #define sg_init_table(sg, n)
284
285 #endif
286
287 #ifndef late_initcall
288 #define late_initcall(init) module_init(init)
289 #endif
290
291 #endif /* __KERNEL__ */
292
293 /****************************************************************************/
294 #endif /* _BSD_COMPAT_H_ */