crc-t10dif.h 1.4 KB

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