4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2018, DataDirect Networks Storage.
28 #include <obd_class.h>
29 #include <obd_cksum.h>
31 /* Server uses algos that perform at 50% or better of the Adler */
32 enum cksum_types obd_cksum_types_supported_server(const char *obd_name)
34 enum cksum_types ret = OBD_CKSUM_ADLER;
37 CDEBUG(D_INFO, "%s: checksum speed: crc %d, crc32c %d, adler %d, "
38 "t10ip512 %d, t10ip4k %d, t10crc512 %d, t10crc4k %d\n",
40 cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32)),
41 cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C)),
42 cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_ADLER)),
43 obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10IP512),
44 obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10IP4K),
45 obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10CRC512),
46 obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10CRC4K));
48 base_speed = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_ADLER)) / 2;
50 if (cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C)) >=
52 ret |= OBD_CKSUM_CRC32C;
54 if (cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32)) >=
56 ret |= OBD_CKSUM_CRC32;
58 if (obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10IP512) >= base_speed)
59 ret |= OBD_CKSUM_T10IP512;
61 if (obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10IP4K) >= base_speed)
62 ret |= OBD_CKSUM_T10IP4K;
64 if (obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10CRC512) >= base_speed)
65 ret |= OBD_CKSUM_T10CRC512;
67 if (obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10CRC4K) >= base_speed)
68 ret |= OBD_CKSUM_T10CRC4K;
72 EXPORT_SYMBOL(obd_cksum_types_supported_server);
74 /* The OBD_FL_CKSUM_* flags is packed into 5 bits of o_flags, since there can
75 * only be a single checksum type per RPC.
77 * The OBD_CKSUM_* type bits passed in ocd_cksum_types are a 32-bit bitmask
78 * since they need to represent the full range of checksum algorithms that
79 * both the client and server can understand.
81 * In case of an unsupported types/flags we fall back to ADLER
82 * because that is supported by all clients since 1.8
84 * In case multiple algorithms are supported the best one is used. */
85 u32 obd_cksum_type_pack(const char *obd_name, enum cksum_types cksum_type)
87 unsigned int performance = 0, tmp;
88 u32 flag = OBD_FL_CKSUM_ADLER;
90 if (cksum_type & OBD_CKSUM_CRC32) {
91 tmp = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32));
92 if (tmp > performance) {
94 flag = OBD_FL_CKSUM_CRC32;
97 if (cksum_type & OBD_CKSUM_CRC32C) {
98 tmp = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C));
99 if (tmp > performance) {
101 flag = OBD_FL_CKSUM_CRC32C;
104 if (cksum_type & OBD_CKSUM_ADLER) {
105 tmp = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_ADLER));
106 if (tmp > performance) {
108 flag = OBD_FL_CKSUM_ADLER;
112 if (cksum_type & OBD_CKSUM_T10IP512) {
113 tmp = obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10IP512);
114 if (tmp > performance) {
116 flag = OBD_FL_CKSUM_T10IP512;
120 if (cksum_type & OBD_CKSUM_T10IP4K) {
121 tmp = obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10IP4K);
122 if (tmp > performance) {
124 flag = OBD_FL_CKSUM_T10IP4K;
128 if (cksum_type & OBD_CKSUM_T10CRC512) {
129 tmp = obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10CRC512);
130 if (tmp > performance) {
132 flag = OBD_FL_CKSUM_T10CRC512;
136 if (cksum_type & OBD_CKSUM_T10CRC4K) {
137 tmp = obd_t10_cksum_speed(obd_name, OBD_CKSUM_T10CRC4K);
138 if (tmp > performance) {
140 flag = OBD_FL_CKSUM_T10CRC4K;
144 if (unlikely(cksum_type && !(cksum_type & OBD_CKSUM_ALL)))
145 CWARN("%s: unknown cksum type %x\n", obd_name, cksum_type);
149 EXPORT_SYMBOL(obd_cksum_type_pack);