atmel-ecc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2017, Microchip Technology Inc.
  4. * Author: Tudor Ambarus <tudor.ambarus@microchip.com>
  5. */
  6. #ifndef __ATMEL_ECC_H__
  7. #define __ATMEL_ECC_H__
  8. #define ATMEL_ECC_PRIORITY 300
  9. #define COMMAND 0x03 /* packet function */
  10. #define SLEEP_TOKEN 0x01
  11. #define WAKE_TOKEN_MAX_SIZE 8
  12. /* Definitions of Data and Command sizes */
  13. #define WORD_ADDR_SIZE 1
  14. #define COUNT_SIZE 1
  15. #define CRC_SIZE 2
  16. #define CMD_OVERHEAD_SIZE (COUNT_SIZE + CRC_SIZE)
  17. /* size in bytes of the n prime */
  18. #define ATMEL_ECC_NIST_P256_N_SIZE 32
  19. #define ATMEL_ECC_PUBKEY_SIZE (2 * ATMEL_ECC_NIST_P256_N_SIZE)
  20. #define STATUS_RSP_SIZE 4
  21. #define ECDH_RSP_SIZE (32 + CMD_OVERHEAD_SIZE)
  22. #define GENKEY_RSP_SIZE (ATMEL_ECC_PUBKEY_SIZE + \
  23. CMD_OVERHEAD_SIZE)
  24. #define READ_RSP_SIZE (4 + CMD_OVERHEAD_SIZE)
  25. #define MAX_RSP_SIZE GENKEY_RSP_SIZE
  26. /**
  27. * atmel_ecc_cmd - structure used for communicating with the device.
  28. * @word_addr: indicates the function of the packet sent to the device. This
  29. * byte should have a value of COMMAND for normal operation.
  30. * @count : number of bytes to be transferred to (or from) the device.
  31. * @opcode : the command code.
  32. * @param1 : the first parameter; always present.
  33. * @param2 : the second parameter; always present.
  34. * @data : optional remaining input data. Includes a 2-byte CRC.
  35. * @rxsize : size of the data received from i2c client.
  36. * @msecs : command execution time in milliseconds
  37. */
  38. struct atmel_ecc_cmd {
  39. u8 word_addr;
  40. u8 count;
  41. u8 opcode;
  42. u8 param1;
  43. u16 param2;
  44. u8 data[MAX_RSP_SIZE];
  45. u8 msecs;
  46. u16 rxsize;
  47. } __packed;
  48. /* Status/Error codes */
  49. #define STATUS_SIZE 0x04
  50. #define STATUS_NOERR 0x00
  51. #define STATUS_WAKE_SUCCESSFUL 0x11
  52. static const struct {
  53. u8 value;
  54. const char *error_text;
  55. } error_list[] = {
  56. { 0x01, "CheckMac or Verify miscompare" },
  57. { 0x03, "Parse Error" },
  58. { 0x05, "ECC Fault" },
  59. { 0x0F, "Execution Error" },
  60. { 0xEE, "Watchdog about to expire" },
  61. { 0xFF, "CRC or other communication error" },
  62. };
  63. /* Definitions for eeprom organization */
  64. #define CONFIG_ZONE 0
  65. /* Definitions for Indexes common to all commands */
  66. #define RSP_DATA_IDX 1 /* buffer index of data in response */
  67. #define DATA_SLOT_2 2 /* used for ECDH private key */
  68. /* Definitions for the device lock state */
  69. #define DEVICE_LOCK_ADDR 0x15
  70. #define LOCK_VALUE_IDX (RSP_DATA_IDX + 2)
  71. #define LOCK_CONFIG_IDX (RSP_DATA_IDX + 3)
  72. /*
  73. * Wake High delay to data communication (microseconds). SDA should be stable
  74. * high for this entire duration.
  75. */
  76. #define TWHI_MIN 1500
  77. #define TWHI_MAX 1550
  78. /* Wake Low duration */
  79. #define TWLO_USEC 60
  80. /* Command execution time (milliseconds) */
  81. #define MAX_EXEC_TIME_ECDH 58
  82. #define MAX_EXEC_TIME_GENKEY 115
  83. #define MAX_EXEC_TIME_READ 1
  84. /* Command opcode */
  85. #define OPCODE_ECDH 0x43
  86. #define OPCODE_GENKEY 0x40
  87. #define OPCODE_READ 0x02
  88. /* Definitions for the READ Command */
  89. #define READ_COUNT 7
  90. /* Definitions for the GenKey Command */
  91. #define GENKEY_COUNT 7
  92. #define GENKEY_MODE_PRIVATE 0x04
  93. /* Definitions for the ECDH Command */
  94. #define ECDH_COUNT 71
  95. #define ECDH_PREFIX_MODE 0x00
  96. #endif /* __ATMEL_ECC_H__ */