spum.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2016 Broadcom
  4. */
  5. /*
  6. * This file contains SPU message definitions specific to SPU-M.
  7. */
  8. #ifndef _SPUM_H_
  9. #define _SPUM_H_
  10. #define SPU_CRYPTO_OPERATION_GENERIC 0x1
  11. /* Length of STATUS field in tx and rx packets */
  12. #define SPU_TX_STATUS_LEN 4
  13. /* SPU-M error codes */
  14. #define SPU_STATUS_MASK 0x0000FF00
  15. #define SPU_STATUS_SUCCESS 0x00000000
  16. #define SPU_STATUS_INVALID_ICV 0x00000100
  17. #define SPU_STATUS_ERROR_FLAG 0x00020000
  18. /* Request message. MH + EMH + BDESC + BD header */
  19. #define SPU_REQ_FIXED_LEN 24
  20. /*
  21. * Max length of a SPU message header. Used to allocate a buffer where
  22. * the SPU message header is constructed. Can be used for either a SPU-M
  23. * header or a SPU2 header.
  24. * For SPU-M, sum of the following:
  25. * MH - 4 bytes
  26. * EMH - 4
  27. * SCTX - 3 +
  28. * max auth key len - 64
  29. * max cipher key len - 264 (RC4)
  30. * max IV len - 16
  31. * BDESC - 12
  32. * BD header - 4
  33. * Total: 371
  34. *
  35. * For SPU2, FMD_SIZE (32) plus lengths of hash and cipher keys,
  36. * hash and cipher IVs. If SPU2 does not support RC4, then
  37. */
  38. #define SPU_HEADER_ALLOC_LEN (SPU_REQ_FIXED_LEN + MAX_KEY_SIZE + \
  39. MAX_KEY_SIZE + MAX_IV_SIZE)
  40. /*
  41. * Response message header length. Normally MH, EMH, BD header, but when
  42. * BD_SUPPRESS is used for hash requests, there is no BD header.
  43. */
  44. #define SPU_RESP_HDR_LEN 12
  45. #define SPU_HASH_RESP_HDR_LEN 8
  46. /*
  47. * Max value that can be represented in the Payload Length field of the BD
  48. * header. This is a 16-bit field.
  49. */
  50. #define SPUM_NS2_MAX_PAYLOAD (BIT(16) - 1)
  51. /*
  52. * NSP SPU is limited to ~9KB because of FA2 FIFO size limitations;
  53. * Set MAX_PAYLOAD to 8k to allow for addition of header, digest, etc.
  54. * and stay within limitation.
  55. */
  56. #define SPUM_NSP_MAX_PAYLOAD 8192
  57. /* Buffer Descriptor Header [BDESC]. SPU in big-endian mode. */
  58. struct BDESC_HEADER {
  59. __be16 offset_mac; /* word 0 [31-16] */
  60. __be16 length_mac; /* word 0 [15-0] */
  61. __be16 offset_crypto; /* word 1 [31-16] */
  62. __be16 length_crypto; /* word 1 [15-0] */
  63. __be16 offset_icv; /* word 2 [31-16] */
  64. __be16 offset_iv; /* word 2 [15-0] */
  65. };
  66. /* Buffer Data Header [BD]. SPU in big-endian mode. */
  67. struct BD_HEADER {
  68. __be16 size;
  69. __be16 prev_length;
  70. };
  71. /* Command Context Header. SPU-M in big endian mode. */
  72. struct MHEADER {
  73. u8 flags; /* [31:24] */
  74. u8 op_code; /* [23:16] */
  75. u16 reserved; /* [15:0] */
  76. };
  77. /* MH header flags bits */
  78. #define MH_SUPDT_PRES BIT(0)
  79. #define MH_HASH_PRES BIT(2)
  80. #define MH_BD_PRES BIT(3)
  81. #define MH_MFM_PRES BIT(4)
  82. #define MH_BDESC_PRES BIT(5)
  83. #define MH_SCTX_PRES BIT(7)
  84. /* SCTX word 0 bit offsets and fields masks */
  85. #define SCTX_SIZE 0x000000FF
  86. /* SCTX word 1 bit shifts and field masks */
  87. #define UPDT_OFST 0x000000FF /* offset of SCTX updateable fld */
  88. #define HASH_TYPE 0x00000300 /* hash alg operation type */
  89. #define HASH_TYPE_SHIFT 8
  90. #define HASH_MODE 0x00001C00 /* one of spu2_hash_mode */
  91. #define HASH_MODE_SHIFT 10
  92. #define HASH_ALG 0x0000E000 /* hash algorithm */
  93. #define HASH_ALG_SHIFT 13
  94. #define CIPHER_TYPE 0x00030000 /* encryption operation type */
  95. #define CIPHER_TYPE_SHIFT 16
  96. #define CIPHER_MODE 0x001C0000 /* encryption mode */
  97. #define CIPHER_MODE_SHIFT 18
  98. #define CIPHER_ALG 0x00E00000 /* encryption algo */
  99. #define CIPHER_ALG_SHIFT 21
  100. #define ICV_IS_512 BIT(27)
  101. #define ICV_IS_512_SHIFT 27
  102. #define CIPHER_ORDER BIT(30)
  103. #define CIPHER_ORDER_SHIFT 30
  104. #define CIPHER_INBOUND BIT(31)
  105. #define CIPHER_INBOUND_SHIFT 31
  106. /* SCTX word 2 bit shifts and field masks */
  107. #define EXP_IV_SIZE 0x7
  108. #define IV_OFFSET BIT(3)
  109. #define IV_OFFSET_SHIFT 3
  110. #define GEN_IV BIT(5)
  111. #define GEN_IV_SHIFT 5
  112. #define EXPLICIT_IV BIT(6)
  113. #define EXPLICIT_IV_SHIFT 6
  114. #define SCTX_IV BIT(7)
  115. #define SCTX_IV_SHIFT 7
  116. #define ICV_SIZE 0x0F00
  117. #define ICV_SIZE_SHIFT 8
  118. #define CHECK_ICV BIT(12)
  119. #define CHECK_ICV_SHIFT 12
  120. #define INSERT_ICV BIT(13)
  121. #define INSERT_ICV_SHIFT 13
  122. #define BD_SUPPRESS BIT(19)
  123. #define BD_SUPPRESS_SHIFT 19
  124. /* Generic Mode Security Context Structure [SCTX] */
  125. struct SCTX {
  126. /* word 0: protocol flags */
  127. __be32 proto_flags;
  128. /* word 1: cipher flags */
  129. __be32 cipher_flags;
  130. /* word 2: Extended cipher flags */
  131. __be32 ecf;
  132. };
  133. struct SPUHEADER {
  134. struct MHEADER mh;
  135. u32 emh;
  136. struct SCTX sa;
  137. };
  138. #endif /* _SPUM_H_ */