staging/irda/net: Drop extraneous parentheses around test
[linux-2.6/btrfs-unstable.git] / drivers / crypto / atmel-ecc.h
blob25232c8abcc2e9a1981a159a0e387c627fe48ca5
1 /*
2 * Copyright (c) 2017, Microchip Technology Inc.
3 * Author: Tudor Ambarus <tudor.ambarus@microchip.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef __ATMEL_ECC_H__
20 #define __ATMEL_ECC_H__
22 #define ATMEL_ECC_PRIORITY 300
24 #define COMMAND 0x03 /* packet function */
25 #define SLEEP_TOKEN 0x01
26 #define WAKE_TOKEN_MAX_SIZE 8
28 /* Definitions of Data and Command sizes */
29 #define WORD_ADDR_SIZE 1
30 #define COUNT_SIZE 1
31 #define CRC_SIZE 2
32 #define CMD_OVERHEAD_SIZE (COUNT_SIZE + CRC_SIZE)
34 /* size in bytes of the n prime */
35 #define ATMEL_ECC_NIST_P256_N_SIZE 32
36 #define ATMEL_ECC_PUBKEY_SIZE (2 * ATMEL_ECC_NIST_P256_N_SIZE)
38 #define STATUS_RSP_SIZE 4
39 #define ECDH_RSP_SIZE (32 + CMD_OVERHEAD_SIZE)
40 #define GENKEY_RSP_SIZE (ATMEL_ECC_PUBKEY_SIZE + \
41 CMD_OVERHEAD_SIZE)
42 #define READ_RSP_SIZE (4 + CMD_OVERHEAD_SIZE)
43 #define MAX_RSP_SIZE GENKEY_RSP_SIZE
45 /**
46 * atmel_ecc_cmd - structure used for communicating with the device.
47 * @word_addr: indicates the function of the packet sent to the device. This
48 * byte should have a value of COMMAND for normal operation.
49 * @count : number of bytes to be transferred to (or from) the device.
50 * @opcode : the command code.
51 * @param1 : the first parameter; always present.
52 * @param2 : the second parameter; always present.
53 * @data : optional remaining input data. Includes a 2-byte CRC.
54 * @rxsize : size of the data received from i2c client.
55 * @msecs : command execution time in milliseconds
57 struct atmel_ecc_cmd {
58 u8 word_addr;
59 u8 count;
60 u8 opcode;
61 u8 param1;
62 u16 param2;
63 u8 data[MAX_RSP_SIZE];
64 u8 msecs;
65 u16 rxsize;
66 } __packed;
68 /* Status/Error codes */
69 #define STATUS_SIZE 0x04
70 #define STATUS_NOERR 0x00
71 #define STATUS_WAKE_SUCCESSFUL 0x11
73 static const struct {
74 u8 value;
75 const char *error_text;
76 } error_list[] = {
77 { 0x01, "CheckMac or Verify miscompare" },
78 { 0x03, "Parse Error" },
79 { 0x05, "ECC Fault" },
80 { 0x0F, "Execution Error" },
81 { 0xEE, "Watchdog about to expire" },
82 { 0xFF, "CRC or other communication error" },
85 /* Definitions for eeprom organization */
86 #define CONFIG_ZONE 0
88 /* Definitions for Indexes common to all commands */
89 #define RSP_DATA_IDX 1 /* buffer index of data in response */
90 #define DATA_SLOT_2 2 /* used for ECDH private key */
92 /* Definitions for the device lock state */
93 #define DEVICE_LOCK_ADDR 0x15
94 #define LOCK_VALUE_IDX (RSP_DATA_IDX + 2)
95 #define LOCK_CONFIG_IDX (RSP_DATA_IDX + 3)
98 * Wake High delay to data communication (microseconds). SDA should be stable
99 * high for this entire duration.
101 #define TWHI_MIN 1500
102 #define TWHI_MAX 1550
104 /* Wake Low duration */
105 #define TWLO_USEC 60
107 /* Command execution time (milliseconds) */
108 #define MAX_EXEC_TIME_ECDH 58
109 #define MAX_EXEC_TIME_GENKEY 115
110 #define MAX_EXEC_TIME_READ 1
112 /* Command opcode */
113 #define OPCODE_ECDH 0x43
114 #define OPCODE_GENKEY 0x40
115 #define OPCODE_READ 0x02
117 /* Definitions for the READ Command */
118 #define READ_COUNT 7
120 /* Definitions for the GenKey Command */
121 #define GENKEY_COUNT 7
122 #define GENKEY_MODE_PRIVATE 0x04
124 /* Definitions for the ECDH Command */
125 #define ECDH_COUNT 71
126 #define ECDH_PREFIX_MODE 0x00
128 #endif /* __ATMEL_ECC_H__ */