2 #define _BSD_COMPAT_H_ 1
3 /****************************************************************************/
5 * Provide compat routines for older linux kernels and BSD kernels
7 * Written by David McCullough <david_mccullough@mcafee.com>
8 * Copyright (C) 2010 David McCullough <david_mccullough@mcafee.com>
12 * The free distribution and use of this software in both source and binary
13 * form is allowed (with or without changes) provided that:
15 * 1. distributions of this source code include the above copyright
16 * notice, this list of conditions and the following disclaimer;
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;
22 * 3. the copyright holder's name is not used to endorse products
23 * built using this software without specific written permission.
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.
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.
35 /****************************************************************************/
37 #include <linux/version.h>
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) && !defined(AUTOCONF_INCLUDED)
39 #include <linux/config.h>
43 * fake some BSD driver interface stuff specifically for OCF use
46 typedef struct ocf_device
*device_t
;
49 int (*cryptodev_newsession
)(device_t dev
, u_int32_t
*sidp
, struct cryptoini
*cri
);
50 int (*cryptodev_freesession
)(device_t dev
, u_int64_t tid
);
51 int (*cryptodev_process
)(device_t dev
, struct cryptop
*crp
, int hint
);
52 int (*cryptodev_kprocess
)(device_t dev
, struct cryptkop
*krp
, int hint
);
54 #define DEVMETHOD(id, func) id: func
57 char name
[32]; /* the driver name */
58 char nameunit
[32]; /* the driver name + HW instance */
60 device_method_t methods
;
64 #define CRYPTODEV_NEWSESSION(dev, sid, cri) \
65 ((*(dev)->methods.cryptodev_newsession)(dev,sid,cri))
66 #define CRYPTODEV_FREESESSION(dev, sid) \
67 ((*(dev)->methods.cryptodev_freesession)(dev, sid))
68 #define CRYPTODEV_PROCESS(dev, crp, hint) \
69 ((*(dev)->methods.cryptodev_process)(dev, crp, hint))
70 #define CRYPTODEV_KPROCESS(dev, krp, hint) \
71 ((*(dev)->methods.cryptodev_kprocess)(dev, krp, hint))
73 #define device_get_name(dev) ((dev)->name)
74 #define device_get_nameunit(dev) ((dev)->nameunit)
75 #define device_get_unit(dev) ((dev)->unit)
76 #define device_get_softc(dev) ((dev)->softc)
78 #define softc_device_decl \
79 struct ocf_device _device; \
82 #define softc_device_init(_sc, _name, _unit, _methods) \
84 strncpy((_sc)->_device.name, _name, sizeof((_sc)->_device.name) - 1); \
85 snprintf((_sc)->_device.nameunit, sizeof((_sc)->_device.name), "%s%d", _name, _unit); \
86 (_sc)->_device.unit = _unit; \
87 (_sc)->_device.methods = _methods; \
88 (_sc)->_device.softc = (void *) _sc; \
89 *(device_t *)((softc_get_device(_sc))+1) = &(_sc)->_device; \
92 #define softc_get_device(_sc) (&(_sc)->_device)
95 * iomem support for 2.4 and 2.6 kernels
97 #include <linux/version.h>
98 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
99 #define ocf_iomem_t unsigned long
102 * implement simple workqueue like support for older kernels
105 #include <linux/tqueue.h>
107 #define work_struct tq_struct
109 #define INIT_WORK(wp, fp, ap) \
112 (wp)->routine = (fp); \
116 #define schedule_work(wp) \
118 queue_task((wp), &tq_immediate); \
119 mark_bh(IMMEDIATE_BH); \
122 #define flush_scheduled_work() run_task_queue(&tq_immediate)
125 #define ocf_iomem_t void __iomem *
127 #include <linux/workqueue.h>
131 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
132 #include <linux/fdtable.h>
133 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
134 #define files_fdtable(files) (files)
138 #undef module_param /* just in case */
139 #define module_param(a,b,c) MODULE_PARM(a,"i")
142 #define bzero(s,l) memset(s,0,l)
143 #define bcopy(s,d,l) memcpy(d,s,l)
144 #define bcmp(x, y, l) memcmp(x,y,l)
146 #define MIN(x,y) ((x) < (y) ? (x) : (y))
148 #define device_printf(dev, a...) ({ \
149 printk("%s: ", device_get_nameunit(dev)); printk(a); \
153 #define printf(fmt...) printk(fmt)
155 #define KASSERT(c,p) if (!(c)) { printk p ; } else
157 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
158 #define ocf_daemonize(str) \
160 spin_lock_irq(¤t->sigmask_lock); \
161 sigemptyset(¤t->blocked); \
162 recalc_sigpending(current); \
163 spin_unlock_irq(¤t->sigmask_lock); \
164 sprintf(current->comm, str);
166 #define ocf_daemonize(str) daemonize(str);
169 #define TAILQ_INSERT_TAIL(q,d,m) list_add_tail(&(d)->m, (q))
170 #define TAILQ_EMPTY(q) list_empty(q)
171 #define TAILQ_FOREACH(v, q, m) list_for_each_entry(v, q, m)
173 #define read_random(p,l) get_random_bytes(p,l)
175 #define DELAY(x) ((x) > 2000 ? mdelay((x)/1000) : udelay(x))
176 #define strtoul simple_strtoul
178 #define pci_get_vendor(dev) ((dev)->vendor)
179 #define pci_get_device(dev) ((dev)->device)
181 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
182 #define pci_set_consistent_dma_mask(dev, mask) (0)
184 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
185 #define pci_dma_sync_single_for_cpu pci_dma_sync_single
188 #ifndef DMA_32BIT_MASK
189 #define DMA_32BIT_MASK 0x00000000ffffffffULL
193 #define htole32(x) cpu_to_le32(x)
196 #define htobe32(x) cpu_to_be32(x)
199 #define htole16(x) cpu_to_le16(x)
202 #define htobe16(x) cpu_to_be16(x)
205 /* older kernels don't have these */
208 #if !defined(IRQ_NONE) && !defined(IRQ_RETVAL)
211 #define IRQ_WAKE_THREAD
213 #define irqreturn_t void
214 typedef irqreturn_t (*irq_handler_t
)(int irq
, void *arg
, struct pt_regs
*regs
);
217 #define IRQF_SHARED SA_SHIRQ
220 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
221 # define strlcpy(dest,src,len) \
222 ({strncpy(dest,src,(len)-1); ((char *)dest)[(len)-1] = '\0'; })
226 #define MAX_ERRNO 4095
229 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,5)
230 #include <linux/err.h>
233 #define IS_ERR_VALUE(x) ((unsigned long)(x) >= (unsigned long)-MAX_ERRNO)
238 * common debug for all
241 #define dprintk(a...) do { if (debug) printk(a); } while(0)
243 #define dprintk(a...)
247 /* Changed in 2.6.20, must use GFP_ATOMIC now */
248 #define SLAB_ATOMIC GFP_ATOMIC
252 * need some additional support for older kernels */
253 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,2)
254 #define pci_register_driver_compat(driver, rc) \
258 } else if (rc == 0) { \
261 pci_unregister_driver(driver); \
264 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
265 #define pci_register_driver_compat(driver,rc) ((rc) = (rc) < 0 ? (rc) : 0)
267 #define pci_register_driver_compat(driver,rc)
270 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
272 #include <linux/mm.h>
273 #include <asm/scatterlist.h>
275 static inline void sg_set_page(struct scatterlist
*sg
, struct page
*page
,
276 unsigned int len
, unsigned int offset
)
283 static inline void *sg_virt(struct scatterlist
*sg
)
285 return page_address(sg
->page
) + sg
->offset
;
288 #define sg_init_table(sg, n)
292 #ifndef late_initcall
293 #define late_initcall(init) module_init(init)
296 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) || !defined(CONFIG_SMP)
297 #define ocf_for_each_cpu(cpu) for ((cpu) = 0; (cpu) == 0; (cpu)++)
299 #define ocf_for_each_cpu(cpu) for_each_present_cpu(cpu)
302 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
303 #include <linux/sched.h>
304 #define kill_proc(p,s,v) send_sig(s,find_task_by_vpid(p),0)
307 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)
310 struct task_struct
*task
;
311 int (*func
)(void *arg
);
315 /* thread startup helper func */
316 static inline int ocf_run_thread(void *arg
)
318 struct ocf_thread
*t
= (struct ocf_thread
*) arg
;
320 return -1; /* very bad */
323 spin_lock_irq(¤t
->sigmask_lock
);
324 sigemptyset(¤t
->blocked
);
325 recalc_sigpending(current
);
326 spin_unlock_irq(¤t
->sigmask_lock
);
327 return (*t
->func
)(t
->arg
);
330 #define kthread_create(f,a,fmt...) \
332 struct ocf_thread t; \
337 p = kernel_thread(ocf_run_thread, &t, CLONE_FS|CLONE_FILES); \
338 while (p != (pid_t) -1 && t.task == NULL) \
341 snprintf(t.task->comm, sizeof(t.task->comm), fmt); \
345 #define kthread_bind(t,cpu) /**/
347 #define kthread_should_stop() (strcmp(current->comm, "stopping") == 0)
349 #define kthread_stop(t) \
351 strcpy((t)->comm, "stopping"); \
352 kill_proc((t)->pid, SIGTERM, 1); \
355 } while (kill_proc((t)->pid, SIGTERM, 1) == 0); \
359 #include <linux/kthread.h>
362 #endif /* __KERNEL__ */
364 /****************************************************************************/
365 #endif /* _BSD_COMPAT_H_ */
This page took 0.081043 seconds and 5 git commands to generate.