spum.h 5.3 KB

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