1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef _LINUX_OBD_SUPPORT
24 #define _LINUX_OBD_SUPPORT
27 #error Do not #include this file directly. #include <obd_support.h> instead
31 #ifndef AUTOCONF_INCLUDED
32 #include <linux/config.h>
34 #include <linux/autoconf.h>
35 #include <linux/slab.h>
36 #include <linux/highmem.h>
38 #include <libcfs/kp30.h>
39 #include <linux/lustre_compat25.h>
40 #include <lustre/lustre_idl.h>
42 /* Prefer the kernel's version, if it exports it, because it might be
43 * optimized for this CPU. */
44 #if defined(__KERNEL__) && (defined(CONFIG_CRC32) || defined(CONFIG_CRC32_MODULE))
45 # include <linux/crc32.h>
47 /* crc32_le lifted from the Linux kernel, which had the following to say:
49 * This code is in the public domain; copyright abandoned.
50 * Liability for non-performance of this code is limited to the amount
51 * you paid for it. Since it is distributed for free, your refund will
52 * be very very small. If it breaks, you get to keep both pieces.
54 #define CRCPOLY_LE 0xedb88320
56 * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
57 * @crc - seed value for computation. ~0 for Ethernet, sometimes 0 for
58 * other uses, or the previous crc32 value if computing incrementally.
59 * @p - pointer to buffer over which CRC is run
60 * @len - length of buffer @p
62 static inline __u32 crc32_le(__u32 crc, unsigned char const *p, size_t len)
67 for (i = 0; i < 8; i++)
68 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
75 # include <linux/zutil.h>
79 #else /* ! __KERNEL__ */
83 static inline __u32 zlib_adler32(__u32 adler, unsigned char const *p,
86 return adler32(adler, p, len);
89 #endif /* __KERNEL__ */
91 static inline __u32 init_checksum(cksum_type_t cksum_type)
101 CERROR("Unknown checksum type (%x)!!!\n", cksum_type);
107 static inline __u32 compute_checksum(__u32 cksum, unsigned char const *p,
108 size_t len, cksum_type_t cksum_type)
111 case OBD_CKSUM_CRC32:
112 return crc32_le(cksum, p, len);
114 case OBD_CKSUM_ADLER:
115 return zlib_adler32(cksum, p, len);
118 CERROR("Unknown checksum type (%x)!!!\n", cksum_type);
124 static inline obd_flag cksum_type_pack(cksum_type_t cksum_type)
127 case OBD_CKSUM_CRC32:
128 return OBD_FL_CKSUM_CRC32;
130 case OBD_CKSUM_ADLER:
131 return OBD_FL_CKSUM_ADLER;
134 CWARN("unknown cksum type %x\n", cksum_type);
136 return OBD_FL_CKSUM_CRC32;
139 static inline cksum_type_t cksum_type_unpack(obd_flag o_flags)
141 o_flags &= OBD_FL_CKSUM_ALL;
142 if ((o_flags - 1) & o_flags)
143 CWARN("several checksum types are set: %x\n", o_flags);
144 if (o_flags & OBD_FL_CKSUM_ADLER)
146 return OBD_CKSUM_ADLER;
148 CWARN("checksum type is set to adler32, but adler32 is not "
149 "supported (%x)\n", o_flags);
151 return OBD_CKSUM_CRC32;
155 # include <linux/types.h>
156 # include <linux/blkdev.h>
158 # define OBD_SLEEP_ON(wq, state) wait_event_interruptible(wq, state)
159 #else /* !__KERNEL__ */
160 # define LTIME_S(time) (time)
161 /* for obd_class.h */
163 # define ERR_PTR(a) ((void *)(a))
165 #endif /* __KERNEL__ */