1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _LINUX_OBD_SUPPORT
38 #define _LINUX_OBD_SUPPORT
41 #error Do not #include this file directly. #include <obd_support.h> instead
45 #ifndef AUTOCONF_INCLUDED
46 #include <linux/config.h>
48 #include <linux/autoconf.h>
49 #include <linux/slab.h>
50 #include <linux/highmem.h>
52 #include <libcfs/kp30.h>
53 #include <linux/lustre_compat25.h>
54 #include <lustre/lustre_idl.h>
56 /* Prefer the kernel's version, if it exports it, because it might be
57 * optimized for this CPU. */
58 #if defined(__KERNEL__) && (defined(CONFIG_CRC32) || defined(CONFIG_CRC32_MODULE))
59 # include <linux/crc32.h>
61 /* crc32_le lifted from the Linux kernel, which had the following to say:
63 * This code is in the public domain; copyright abandoned.
64 * Liability for non-performance of this code is limited to the amount
65 * you paid for it. Since it is distributed for free, your refund will
66 * be very very small. If it breaks, you get to keep both pieces.
68 #define CRCPOLY_LE 0xedb88320
70 * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
71 * @crc - seed value for computation. ~0 for Ethernet, sometimes 0 for
72 * other uses, or the previous crc32 value if computing incrementally.
73 * @p - pointer to buffer over which CRC is run
74 * @len - length of buffer @p
76 static inline __u32 crc32_le(__u32 crc, unsigned char const *p, size_t len)
81 for (i = 0; i < 8; i++)
82 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
89 # include <linux/zutil.h>
93 #else /* ! __KERNEL__ */
97 static inline __u32 zlib_adler32(__u32 adler, unsigned char const *p,
100 return adler32(adler, p, len);
103 #endif /* __KERNEL__ */
105 static inline __u32 init_checksum(cksum_type_t cksum_type)
108 case OBD_CKSUM_CRC32:
111 case OBD_CKSUM_ADLER:
115 CERROR("Unknown checksum type (%x)!!!\n", cksum_type);
121 static inline __u32 compute_checksum(__u32 cksum, unsigned char const *p,
122 size_t len, cksum_type_t cksum_type)
125 case OBD_CKSUM_CRC32:
126 return crc32_le(cksum, p, len);
128 case OBD_CKSUM_ADLER:
129 return zlib_adler32(cksum, p, len);
132 CERROR("Unknown checksum type (%x)!!!\n", cksum_type);
138 static inline obd_flag cksum_type_pack(cksum_type_t cksum_type)
141 case OBD_CKSUM_CRC32:
142 return OBD_FL_CKSUM_CRC32;
144 case OBD_CKSUM_ADLER:
145 return OBD_FL_CKSUM_ADLER;
148 CWARN("unknown cksum type %x\n", cksum_type);
150 return OBD_FL_CKSUM_CRC32;
153 static inline cksum_type_t cksum_type_unpack(obd_flag o_flags)
155 o_flags &= OBD_FL_CKSUM_ALL;
156 if ((o_flags - 1) & o_flags)
157 CWARN("several checksum types are set: %x\n", o_flags);
158 if (o_flags & OBD_FL_CKSUM_ADLER)
160 return OBD_CKSUM_ADLER;
162 CWARN("checksum type is set to adler32, but adler32 is not "
163 "supported (%x)\n", o_flags);
165 return OBD_CKSUM_CRC32;
169 # include <linux/types.h>
170 # include <linux/blkdev.h>
173 #define OBD_FAIL_WRITE(obd, id, sb) \
175 if (OBD_FAIL_CHECK(id)) { \
176 CERROR("obd_fail_loc=%x, fail write operation on %s\n", \
178 lvfs_set_rdonly(obd, sb); \
179 /* We set FAIL_ONCE because we never "un-fail" a device */ \
180 obd_fail_loc |= OBD_FAILED | OBD_FAIL_ONCE; \
184 #define OBD_SLEEP_ON(wq, state) wait_event_interruptible(wq, state)
187 #else /* !__KERNEL__ */
188 # define LTIME_S(time) (time)
189 /* for obd_class.h */
191 # define ERR_PTR(a) ((void *)(a))
193 #endif /* __KERNEL__ */