blob: 7f8148809efc87d4bd6d82ff6a765b1e150c0a06 [file] [log] [blame]
Unnati Gandhid42c0212015-06-03 12:03:24 +05301/* Copyright (c) 2012,2015, The Linux Foundation. All rights reserved.
Deepa Dinamani0a976552012-11-28 17:01:27 -08002
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __CRYPTO5_ENG_H__
30#define __CRYPYO5_ENG_H__
31
32#include <bits.h>
33#include <bam.h>
34#include <crypto_hash.h>
35
36/* CRYPTO registers */
37#define CRYPTO_VERSION(x) (x + 0x0000)
38#define CRYPTO_DATA_IN(x) (x + 0x0010)
39#define CRYPTO_DATA_OUT(x) (x + 0x0020)
40#define CRYPTO_STATUS(x) (x + 0x0100)
41#define CRYPTO_STATUS2(x) (x + 0x0104)
42#define CRYPTO_SEG_SIZE(x) (x + 0x0110)
43#define CRYPTO_GOPROC(x) (x + 0x0120)
44#define CRYPTO_ENGINES_AVAIL(x) (x + 0x0108)
45#define CRYPTO_ENCR_SEG_CFG(x) (x + 0x0200)
46#define CRYPTO_AUTH_SEG_CFG(x) (x + 0x0300)
47#define CRYPTO_AUTH_SEG_SIZE(x) (x + 0x0304)
48#define CRYPTO_AUTH_SEG_START(x) (x + 0x0308)
49#define CRYPTO_AUTH_IVn(x, n) (x + 0x0310 + 4*(n))
50#define CRYPTO_AUTH_BYTECNTn(x, n) (x + 0x0390 + 4*(n))
51#define CRYPTO_CONFIG(x) (x + 0x0400)
52#define CRYPTO_DEBUG(x) (x + 0x5004)
53
54/* Status register errors. */
55#define SW_ERR BIT(0)
56#define AXI_ERR BIT(14)
57#define HSD_ERR BIT(20)
58#define AUTH_BUSY BIT(8)
59
60/* Status2 register errors. */
61#define AXI_EXTRA BIT(1)
62
63/* CRYPTO_CONFIG register bit definitions */
64#define MASK_ERR_INTR BIT(0)
65#define MASK_OP_DONE_INTR BIT(1)
66#define MASK_DIN_INTR BIT(2)
67#define MASK_DOUT_INTR BIT(3)
68#define HIGH_SPD_IN_EN_N (0 << 4)
69#define PIPE_SET_SELECT_SHIFT 5
70#define LITTLE_ENDIAN_MODE BIT(9)
71#define MAX_QUEUED_REQS (0 << 14) /* 1 Max queued request. */
72#define REQ_SIZE (7 << 17) /* 8 beats */
73
74/* CRYPTO_AUTH_SEG_CFG register bit definitions */
75#define SEG_CFG_AUTH_ALG_SHA (1 << 0)
76#define SEG_CFG_AUTH_SIZE_SHA1 (0 << 9)
77#define SEG_CFG_AUTH_SIZE_SHA256 (1 << 9)
78#define SEG_CFG_LAST (1 << 16)
79
80/* The value to be written to the GOPROC register.
81 * Enable result dump option along with GO bit.
82 */
83#define GOPROC_GO (1 | 1 << 2)
84
85#define CRYPTO_READ_PIPE_INDEX 0
86#define CRYPTO_WRITE_PIPE_INDEX 1
87
88/* Burst length recommended by HPG for maximum throughput. */
89#define CRYPTO_BURST_LEN 64
90
91/* This value determines how much descriptor data can be advertised on
92 * the pipe sideband interface at a time.
93 * The recommendation is to make it the size of your largest descriptor.
94 * The max setting is 32KB.
95 */
96
97#define CRYPTO_MAX_THRESHOLD (32 * 1024)
98
99/* Basic CE setting to put the CE in HS mode. */
100#define CRYPTO_RESET_CONFIG 0xE000F
101
102struct crypto_bam_pipes
103{
104 uint8_t read_pipe;
105 uint8_t write_pipe;
Deepa Dinamani48637cd2013-07-09 14:04:21 -0700106 uint8_t read_pipe_grp;
107 uint8_t write_pipe_grp;
Deepa Dinamani0a976552012-11-28 17:01:27 -0800108};
109
110struct output_dump
111{
112 uint32_t auth_iv[16];
113 uint32_t auth_bytcnt[4];
114 uint32_t encr_cntr_iv[4];
115 uint32_t status;
116 uint32_t status2;
117 uint8_t burst_align_buf[24];
118}__PACKED;
119
120/* Struct to save the CE device info.
121 * base : Base addr of CE.
122 * instance : CE instance used.
123 * ce_array : ptr to the cmd elements array.
124 * ce_array_index : index within ce_array where the next cmd element needs to be added.
125 * cd_start : index within the ce_array to keep track of the num of
126 * cmd elements that need to be added in the next desc.
127 * dump : ptr to the result dump memory.
128 * bam : bam instance used with this CE.
Deepa Dinamanibcc62d22013-05-10 14:10:05 -0700129 * do_bam_init : Flag to determine if bam should be initalized.
Deepa Dinamani0a976552012-11-28 17:01:27 -0800130 */
131struct crypto_dev
132{
133 uint32_t base;
134 uint32_t instance;
135 struct cmd_element *ce_array;
136 uint32_t ce_array_index;
137 uint32_t cd_start;
138 struct output_dump *dump;
139 struct bam_instance bam;
Deepa Dinamanibcc62d22013-05-10 14:10:05 -0700140 uint8_t do_bam_init;
Deepa Dinamani0a976552012-11-28 17:01:27 -0800141};
142
143/* Struct to pass the initial params to CE.
144 * crypto_base : Base addr of the CE.
145 * crypto_instance : CE instance used.
146 * bam_base : Base addr of CE BAM.
147 * bam_ee : EE used for CE BAM.
148 * num_ce : Number of cmd elements to be allocated.
149 * read_fifo_size : Size of the BAM desc read fifo.
150 * write_fifo_size : Size of the BAM desc write fifo.
Deepa Dinamanibcc62d22013-05-10 14:10:05 -0700151 * do_bam_init : Flag to determine if bam should be initalized.
Deepa Dinamani0a976552012-11-28 17:01:27 -0800152 */
153struct crypto_init_params
154{
155 uint32_t crypto_base;
156 uint32_t crypto_instance;
157 uint32_t bam_base;
158 uint32_t bam_ee;
159 uint32_t num_ce;
160 uint32_t read_fifo_size;
161 uint32_t write_fifo_size;
Deepa Dinamanibcc62d22013-05-10 14:10:05 -0700162 uint8_t do_bam_init;
Deepa Dinamani0a976552012-11-28 17:01:27 -0800163 struct crypto_bam_pipes pipes;
164};
165
166void crypto5_init_params(struct crypto_dev *dev, struct crypto_init_params *params);
167void crypto5_init(struct crypto_dev *dev);
168void crypto5_set_ctx(struct crypto_dev *dev,
169 void *ctx_ptr,
170 crypto_auth_alg_type auth_alg);
171uint32_t crypto5_send_data(struct crypto_dev *dev,
172 void *ctx_ptr,
173 uint8_t *data_ptr);
174void crypto5_cleanup(struct crypto_dev *dev);
175uint32_t crypto5_get_digest(struct crypto_dev *dev,
176 uint8_t *digest_ptr,
177 crypto_auth_alg_type auth_alg);
178void crypto5_get_ctx(struct crypto_dev *dev, void *ctx_ptr);
179uint32_t crypto5_get_max_auth_blk_size(struct crypto_dev *dev);
Unnati Gandhid42c0212015-06-03 12:03:24 +0530180void crypto5_unlock_pipes(struct crypto_dev *dev);
Deepa Dinamani0a976552012-11-28 17:01:27 -0800181
182#endif