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@securecomputing.com>
8 * Copyright (C) 2007 David McCullough <david_mccullough@securecomputing.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 /****************************************************************************/
38 * fake some BSD driver interface stuff specifically for OCF use
41 typedef struct ocf_device
*device_t
;
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
);
49 #define DEVMETHOD(id, func) id: func
52 char name
[32]; /* the driver name */
53 char nameunit
[32]; /* the driver name + HW instance */
55 device_method_t methods
;
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))
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)
73 #define softc_device_decl \
74 struct ocf_device _device; \
77 #define softc_device_init(_sc, _name, _unit, _methods) \
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; \
87 #define softc_get_device(_sc) (&(_sc)->_device)
90 * iomem support for 2.4 and 2.6 kernels
92 #include <linux/version.h>
93 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
94 #define ocf_iomem_t unsigned long
97 * implement simple workqueue like support for older kernels
100 #include <linux/tqueue.h>
102 #define work_struct tq_struct
104 #define INIT_WORK(wp, fp, ap) \
107 (wp)->routine = (fp); \
111 #define schedule_work(wp) \
113 queue_task((wp), &tq_immediate); \
114 mark_bh(IMMEDIATE_BH); \
117 #define flush_scheduled_work() run_task_queue(&tq_immediate)
120 #define ocf_iomem_t void __iomem *
122 #include <linux/workqueue.h>
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)
133 #undef module_param /* just in case */
134 #define module_param(a,b,c) MODULE_PARM(a,"i")
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)
141 #define MIN(x,y) ((x) < (y) ? (x) : (y))
143 #define device_printf(dev, a...) ({ \
144 printk("%s: ", device_get_nameunit(dev)); printk(a); \
148 #define printf(fmt...) printk(fmt)
150 #define KASSERT(c,p) if (!(c)) { printk p ; } else
152 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
153 #define ocf_daemonize(str) \
155 spin_lock_irq(¤t->sigmask_lock); \
156 sigemptyset(¤t->blocked); \
157 recalc_sigpending(current); \
158 spin_unlock_irq(¤t->sigmask_lock); \
159 sprintf(current->comm, str);
161 #define ocf_daemonize(str) daemonize(str);
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)
168 #define read_random(p,l) get_random_bytes(p,l)
170 #define DELAY(x) ((x) > 2000 ? mdelay((x)/1000) : udelay(x))
171 #define strtoul simple_strtoul
173 #define pci_get_vendor(dev) ((dev)->vendor)
174 #define pci_get_device(dev) ((dev)->device)
176 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
177 #define pci_set_consistent_dma_mask(dev, mask) (0)
179 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
180 #define pci_dma_sync_single_for_cpu pci_dma_sync_single
183 #ifndef DMA_32BIT_MASK
184 #define DMA_32BIT_MASK 0x00000000ffffffffULL
187 #define htole32(x) cpu_to_le32(x)
188 #define htobe32(x) cpu_to_be32(x)
189 #define htole16(x) cpu_to_le16(x)
190 #define htobe16(x) cpu_to_be16(x)
192 /* older kernels don't have these */
197 #define irqreturn_t void
200 #define IRQF_SHARED SA_SHIRQ
203 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
204 # define strlcpy(dest,src,len) \
205 ({strncpy(dest,src,(len)-1); ((char *)dest)[(len)-1] = '\0'; })
209 #define MAX_ERRNO 4095
212 #define IS_ERR_VALUE(x) ((unsigned long)(x) >= (unsigned long)-MAX_ERRNO)
216 * common debug for all
219 #define dprintk(a...) do { if (debug) printk(a); } while(0)
221 #define dprintk(a...)
225 /* Changed in 2.6.20, must use GFP_ATOMIC now */
226 #define SLAB_ATOMIC GFP_ATOMIC
230 * need some additional support for older kernels */
231 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,2)
232 #define pci_register_driver_compat(driver, rc) \
236 } else if (rc == 0) { \
239 pci_unregister_driver(driver); \
242 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
243 #define pci_register_driver_compat(driver,rc) ((rc) = (rc) < 0 ? (rc) : 0)
245 #define pci_register_driver_compat(driver,rc)
248 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
250 #include <asm/scatterlist.h>
252 static inline void sg_set_page(struct scatterlist
*sg
, struct page
*page
,
253 unsigned int len
, unsigned int offset
)
260 static inline void *sg_virt(struct scatterlist
*sg
)
262 return page_address(sg
->page
) + sg
->offset
;
267 #endif /* __KERNEL__ */
269 /****************************************************************************/
270 #endif /* _BSD_COMPAT_H_ */
This page took 0.054096 seconds and 5 git commands to generate.