vmx.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Routines supporting VMX instructions on the Power 8
  3. *
  4. * Copyright (C) 2015 International Business Machines Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 only.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. * Author: Marcelo Henrique Cerri <mhcerri@br.ibm.com>
  20. */
  21. #include <linux/module.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/types.h>
  24. #include <linux/err.h>
  25. #include <linux/crypto.h>
  26. #include <asm/cputable.h>
  27. #include <crypto/internal/hash.h>
  28. extern struct shash_alg p8_ghash_alg;
  29. extern struct crypto_alg p8_aes_alg;
  30. extern struct crypto_alg p8_aes_cbc_alg;
  31. extern struct crypto_alg p8_aes_ctr_alg;
  32. static struct crypto_alg *algs[] = {
  33. &p8_aes_alg,
  34. &p8_aes_cbc_alg,
  35. &p8_aes_ctr_alg,
  36. NULL,
  37. };
  38. int __init p8_init(void)
  39. {
  40. int ret = 0;
  41. struct crypto_alg **alg_it;
  42. if (!(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
  43. return -ENODEV;
  44. for (alg_it = algs; *alg_it; alg_it++) {
  45. ret = crypto_register_alg(*alg_it);
  46. printk(KERN_INFO "crypto_register_alg '%s' = %d\n",
  47. (*alg_it)->cra_name, ret);
  48. if (ret) {
  49. for (alg_it--; alg_it >= algs; alg_it--)
  50. crypto_unregister_alg(*alg_it);
  51. break;
  52. }
  53. }
  54. if (ret)
  55. return ret;
  56. ret = crypto_register_shash(&p8_ghash_alg);
  57. if (ret) {
  58. for (alg_it = algs; *alg_it; alg_it++)
  59. crypto_unregister_alg(*alg_it);
  60. }
  61. return ret;
  62. }
  63. void __exit p8_exit(void)
  64. {
  65. struct crypto_alg **alg_it;
  66. for (alg_it = algs; *alg_it; alg_it++) {
  67. printk(KERN_INFO "Removing '%s'\n", (*alg_it)->cra_name);
  68. crypto_unregister_alg(*alg_it);
  69. }
  70. crypto_unregister_shash(&p8_ghash_alg);
  71. }
  72. module_init(p8_init);
  73. module_exit(p8_exit);
  74. MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>");
  75. MODULE_DESCRIPTION("IBM VMX cryptographic acceleration instructions "
  76. "support on Power 8");
  77. MODULE_LICENSE("GPL");
  78. MODULE_VERSION("1.0.0");