keystone-sa.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Keystone crypto accelerator driver
  3. *
  4. * Copyright (C) 2013-2016 Texas Instruments Incorporated - http://www.ti.com
  5. * Contact: Sandeep Nair <sandeep_n@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. */
  16. #ifndef _KEYSTONE_SA_H_
  17. #define _KEYSTONE_SA_H_
  18. /*
  19. * This type represents the various packet types to be processed
  20. * by the PHP engine in SA.
  21. * It is used to identify the corresponding PHP processing function.
  22. */
  23. #define SA_CTX_PE_PKT_TYPE_3GPP_AIR 0 /* 3GPP Air Cipher */
  24. #define SA_CTX_PE_PKT_TYPE_SRTP 1 /* SRTP */
  25. #define SA_CTX_PE_PKT_TYPE_IPSEC_AH 2 /* IPSec Authentication Header */
  26. /* IPSec Encapsulating Security Payload */
  27. #define SA_CTX_PE_PKT_TYPE_IPSEC_ESP 3
  28. /* Indicates that it is in data mode, It may not be used by PHP */
  29. #define SA_CTX_PE_PKT_TYPE_NONE 4
  30. #define SA_CTX_ENC_TYPE1_SZ 64 /* Encryption SC with Key only */
  31. #define SA_CTX_ENC_TYPE2_SZ 96 /* Encryption SC with Key and Aux1 */
  32. #define SA_CTX_AUTH_TYPE1_SZ 64 /* Auth SC with Key only */
  33. #define SA_CTX_AUTH_TYPE2_SZ 96 /* Auth SC with Key and Aux1 */
  34. /* Size of security context for PHP engine */
  35. #define SA_CTX_PHP_PE_CTX_SZ 64
  36. #define SA_CTX_MAX_SZ (64 + SA_CTX_ENC_TYPE2_SZ + SA_CTX_AUTH_TYPE2_SZ)
  37. /*
  38. * Encoding of F/E control in SCCTL
  39. * Bit 0-1: Fetch PHP Bytes
  40. * Bit 2-3: Fetch Encryption/Air Ciphering Bytes
  41. * Bit 4-5: Fetch Authentication Bytes or Encr pass 2
  42. * Bit 6-7: Evict PHP Bytes
  43. *
  44. * where 00 = 0 bytes
  45. * 01 = 64 bytes
  46. * 10 = 96 bytes
  47. * 11 = 128 bytes
  48. */
  49. #define SA_CTX_DMA_SIZE_0 0
  50. #define SA_CTX_DMA_SIZE_64 1
  51. #define SA_CTX_DMA_SIZE_96 2
  52. #define SA_CTX_DMA_SIZE_128 3
  53. #define SA_CTX_SCCTL_MK_DMA_INFO(php_f, eng0_f, eng1_f, php_e) \
  54. ((php_f) | \
  55. ((eng0_f) << 2) | \
  56. ((eng1_f) << 4) | \
  57. ((php_e) << 6))
  58. /*
  59. * Byte offset of the owner word in SCCTL
  60. * in the security context
  61. */
  62. #define SA_CTX_SCCTL_OWNER_OFFSET 0
  63. /*
  64. * Assumption: CTX size is multiple of 32
  65. */
  66. #define SA_CTX_SIZE_TO_DMA_SIZE(ctx_sz) \
  67. ((ctx_sz) ? ((ctx_sz) / 32 - 1) : 0)
  68. #define SA_CTX_ENC_KEY_OFFSET 32
  69. #define SA_CTX_ENC_AUX1_OFFSET 64
  70. #define SA_CTX_ENC_AUX2_OFFSET 96
  71. #define SA_CTX_ENC_AUX3_OFFSET 112
  72. #define SA_CTX_ENC_AUX4_OFFSET 128
  73. /* Next Engine Select code in CP_ACE */
  74. #define SA_ENG_ID_EM1 2 /* Enc/Dec engine with AES/DEC core */
  75. #define SA_ENG_ID_EM2 3 /* Encryption/Decryption enginefor pass 2 */
  76. #define SA_ENG_ID_AM1 4 /* Auth. engine with SHA1/MD5/SHA2 core */
  77. #define SA_ENG_ID_AM2 5 /* Authentication engine for pass 2 */
  78. #define SA_ENG_ID_OUTPORT2 20 /* Egress module 2 */
  79. #define SA_ENG_ID_NONE 0xff
  80. #define SA_ENG_ID_FINAL SA_ENG_ID_OUTPORT2
  81. /*
  82. * Command Label Definitions
  83. */
  84. #define SA_CMDL_OFFSET_NESC 0 /* Next Engine Select Code */
  85. #define SA_CMDL_OFFSET_LABEL_LEN 1 /* Engine Command Label Length */
  86. /* 16-bit Length of Data to be processed */
  87. #define SA_CMDL_OFFSET_DATA_LEN 2
  88. #define SA_CMDL_OFFSET_DATA_OFFSET 4 /* Stat Data Offset */
  89. #define SA_CMDL_OFFSET_OPTION_CTRL1 5 /* Option Control Byte 1 */
  90. #define SA_CMDL_OFFSET_OPTION_CTRL2 6 /* Option Control Byte 2 */
  91. #define SA_CMDL_OFFSET_OPTION_CTRL3 7 /* Option Control Byte 3 */
  92. #define SA_CMDL_OFFSET_OPTION_BYTE 8
  93. #define SA_CMDL_HEADER_SIZE_BYTES 8
  94. #define SA_CMDL_OPTION_BYTES_MAX_SIZE 72
  95. #define SA_CMDL_MAX_SIZE_BYTES (SA_CMDL_HEADER_SIZE_BYTES + \
  96. SA_CMDL_OPTION_BYTES_MAX_SIZE)
  97. /* SWINFO word-0 flags */
  98. #define SA_SW_INFO_FLAG_EVICT 0x0001
  99. #define SA_SW_INFO_FLAG_TEAR 0x0002
  100. #define SA_SW_INFO_FLAG_NOPD 0x0004
  101. #define SA_CMD_ENCSS_EN 0x00000001
  102. #define SA_CMD_AUTHSS_EN 0x00000002
  103. #define SA_CMD_AIRSS_EN 0x00000004
  104. #define SA_CMD_TRNG_EN 0x00000008
  105. #define SA_CMD_PKA_EN 0x00000010
  106. #define SA_CMD_PHP1SS_EN 0x00000020
  107. #define SA_CMD_PHP2SS_EN 0x00000040
  108. #define SA_CMD_CTXCACH_EN 0x00000080
  109. #define SA_CMD_SA1_IN_EN 0x00000100
  110. #define SA_CMD_SA0_IN_EN 0x00000200
  111. #define SA_CMD_SA1_OUT_EN 0x00000400
  112. #define SA_CMD_SA0_OUT_EN 0x00000800
  113. /* GCM Operation Definitions */
  114. #define SA_GCM_SIZE 48
  115. /* OFFSET|LENGTH (LENGTH - in number of bytes, 1 = 8 bytes) */
  116. #define SA_GCM_OPT1 ((SA_CTX_ENC_AUX1_OFFSET + 24) | (8 >> 3))
  117. #define SA_GCM_OPT2 (SA_CTX_ENC_AUX2_OFFSET | (16 >> 3))
  118. #define SA_GCM_OPT3 (SA_CTX_ENC_AUX3_OFFSET | (16 >> 3))
  119. /* GMAC Operation Definitions */
  120. #define SA_GMAC_SIZE 48
  121. /* OFFSET|LENGTH (LENGTH - in number of bytes, 1 = 8 bytes) */
  122. #define SA_GMAC_OPT1 ((SA_CTX_ENC_AUX1_OFFSET + 16) | (8 >> 3))
  123. #define SA_GMAC_OPT2 (SA_CTX_ENC_AUX2_OFFSET | (16 >> 3))
  124. #define SA_GMAC_OPT3 (SA_CTX_ENC_AUX3_OFFSET | (16 >> 3))
  125. #endif