Skip to content

Commit 0961c3b

Browse files
committed
lib/crc-t10dif: add support for arch overrides
Following what was done for CRC32, add support for architecture-specific override of the CRC-T10DIF library. This will allow the CRC-T10DIF library functions to access architecture-optimized code directly. Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent be3c45b commit 0961c3b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

include/linux/crc-t10dif.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
#define CRC_T10DIF_DIGEST_SIZE 2
88
#define CRC_T10DIF_BLOCK_SIZE 1
99

10+
u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len);
1011
u16 crc_t10dif_generic(u16 crc, const u8 *p, size_t len);
1112

1213
static inline u16 crc_t10dif_update(u16 crc, const u8 *p, size_t len)
1314
{
15+
if (IS_ENABLED(CONFIG_CRC_T10DIF_ARCH))
16+
return crc_t10dif_arch(crc, p, len);
1417
return crc_t10dif_generic(crc, p, len);
1518
}
1619

@@ -19,4 +22,13 @@ static inline u16 crc_t10dif(const u8 *p, size_t len)
1922
return crc_t10dif_update(0, p, len);
2023
}
2124

25+
#if IS_ENABLED(CONFIG_CRC_T10DIF_ARCH)
26+
bool crc_t10dif_is_optimized(void);
27+
#else
28+
static inline bool crc_t10dif_is_optimized(void)
29+
{
30+
return false;
31+
}
32+
#endif
33+
2234
#endif

lib/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,38 @@ config CRC_T10DIF
161161
kernel tree needs to calculate CRC checks for use with the
162162
SCSI data integrity subsystem.
163163

164+
config ARCH_HAS_CRC_T10DIF
165+
bool
166+
167+
choice
168+
prompt "CRC-T10DIF implementation"
169+
depends on CRC_T10DIF
170+
default CRC_T10DIF_IMPL_ARCH if ARCH_HAS_CRC_T10DIF
171+
default CRC_T10DIF_IMPL_GENERIC if !ARCH_HAS_CRC_T10DIF
172+
help
173+
This option allows you to override the default choice of CRC-T10DIF
174+
implementation.
175+
176+
config CRC_T10DIF_IMPL_ARCH
177+
bool "Architecture-optimized" if ARCH_HAS_CRC_T10DIF
178+
help
179+
Use the optimized implementation of CRC-T10DIF for the selected
180+
architecture. It is recommended to keep this enabled, as it can
181+
greatly improve CRC-T10DIF performance.
182+
183+
config CRC_T10DIF_IMPL_GENERIC
184+
bool "Generic implementation"
185+
help
186+
Use the generic table-based implementation of CRC-T10DIF. Selecting
187+
this will reduce code size slightly but can greatly reduce CRC-T10DIF
188+
performance.
189+
190+
endchoice
191+
192+
config CRC_T10DIF_ARCH
193+
tristate
194+
default CRC_T10DIF if CRC_T10DIF_IMPL_ARCH
195+
164196
config CRC64_ROCKSOFT
165197
tristate "CRC calculation for the Rocksoft model CRC64"
166198
select CRC64

0 commit comments

Comments
 (0)