crc-t10dif.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Accelerated CRC-T10DIF using ARM NEON and Crypto Extensions instructions
  4. *
  5. * Copyright (C) 2016 Linaro Ltd <ard.biesheuvel@linaro.org>
  6. */
  7. #include <asm/simd.h>
  8. static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
  9. static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pmull);
  10. #define CRC_T10DIF_PMULL_CHUNK_SIZE 16U
  11. asmlinkage u16 crc_t10dif_pmull64(u16 init_crc, const u8 *buf, size_t len);
  12. asmlinkage void crc_t10dif_pmull8(u16 init_crc, const u8 *buf, size_t len,
  13. u8 out[16]);
  14. static inline u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length)
  15. {
  16. if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE && likely(may_use_simd())) {
  17. if (static_branch_likely(&have_pmull)) {
  18. scoped_ksimd()
  19. return crc_t10dif_pmull64(crc, data, length);
  20. } else if (length > CRC_T10DIF_PMULL_CHUNK_SIZE &&
  21. static_branch_likely(&have_neon)) {
  22. u8 buf[16] __aligned(16);
  23. scoped_ksimd()
  24. crc_t10dif_pmull8(crc, data, length, buf);
  25. return crc_t10dif_generic(0, buf, sizeof(buf));
  26. }
  27. }
  28. return crc_t10dif_generic(crc, data, length);
  29. }
  30. #define crc_t10dif_mod_init_arch crc_t10dif_mod_init_arch
  31. static void crc_t10dif_mod_init_arch(void)
  32. {
  33. if (elf_hwcap & HWCAP_NEON) {
  34. static_branch_enable(&have_neon);
  35. if (elf_hwcap2 & HWCAP2_PMULL)
  36. static_branch_enable(&have_pmull);
  37. }
  38. }