Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _DRIVERS_CRYPTO_MSM_QCE40_H_ |
| 14 | #define _DRIVERS_CRYPTO_MSM_QCE40_H_ |
| 15 | |
| 16 | |
| 17 | #define GET_VIRT_ADDR(x) \ |
| 18 | ((uint32_t)pce_dev->coh_vmem + \ |
| 19 | ((uint32_t)x - pce_dev->coh_pmem)) |
| 20 | #define GET_PHYS_ADDR(x) \ |
| 21 | (pce_dev->coh_pmem + ((unsigned char *)x - \ |
| 22 | pce_dev->coh_vmem)) |
| 23 | |
| 24 | /* Sets the adddress of a command list in command pointer list */ |
| 25 | #define QCE_SET_CMD_PTR(x) \ |
| 26 | (uint32_t)(DMOV_CMD_ADDR(GET_PHYS_ADDR((unsigned char *)x))) |
| 27 | |
| 28 | /* Sets the adddress of the last command list in command pointer list */ |
| 29 | #define SET_LAST_CMD_PTR(x) \ |
| 30 | ((DMOV_CMD_ADDR(x)) | CMD_PTR_LP) |
| 31 | |
| 32 | /* Get the adddress of the last command list in command pointer list */ |
| 33 | #define QCE_SET_LAST_CMD_PTR(x) \ |
| 34 | SET_LAST_CMD_PTR((GET_PHYS_ADDR((unsigned char *)x))) |
| 35 | |
| 36 | |
Mona Hossain | 5f5dde1 | 2011-09-12 10:28:34 -0700 | [diff] [blame] | 37 | /* MAX Data xfer block size between DM and CE */ |
| 38 | #define MAX_ADM_CE_BLOCK_SIZE 64 |
Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 39 | #define ADM_DESC_LENGTH_MASK 0xffff |
| 40 | #define ADM_DESC_LENGTH(x) (x & ADM_DESC_LENGTH_MASK) |
| 41 | |
| 42 | #define ADM_STATUS_OK 0x80000002 |
| 43 | |
| 44 | /* QCE max number of descriptor in a descriptor list */ |
| 45 | #define QCE_MAX_NUM_DESC 128 |
| 46 | |
| 47 | #define CRYPTO_REG_SIZE 0x4 |
| 48 | |
| 49 | struct dmov_desc { |
| 50 | uint32_t addr; |
| 51 | uint32_t len; |
| 52 | }; |
| 53 | |
| 54 | /* State of DM channel */ |
| 55 | enum qce_chan_st_enum { |
| 56 | QCE_CHAN_STATE_IDLE = 0, |
| 57 | QCE_CHAN_STATE_IN_PROG = 1, |
| 58 | QCE_CHAN_STATE_COMP = 2, |
| 59 | QCE_CHAN_STATE_LAST |
| 60 | }; |
| 61 | |
| 62 | /* CE buffers */ |
| 63 | struct ce_reg_buffer_addr { |
| 64 | |
| 65 | unsigned char *reset_buf_64; |
| 66 | unsigned char *version; |
| 67 | |
| 68 | unsigned char *encr_seg_cfg_size_start; |
| 69 | unsigned char *encr_key; |
| 70 | unsigned char *encr_xts_key; |
| 71 | unsigned char *encr_cntr_iv; |
| 72 | unsigned char *encr_mask; |
| 73 | unsigned char *encr_xts_du_size; |
| 74 | |
| 75 | unsigned char *auth_seg_cfg_size_start; |
| 76 | unsigned char *auth_key; |
| 77 | unsigned char *auth_iv; |
| 78 | unsigned char *auth_result; |
| 79 | unsigned char *auth_nonce_info; |
| 80 | unsigned char *auth_byte_count; |
| 81 | |
| 82 | unsigned char *seg_size; |
| 83 | unsigned char *go_proc; |
| 84 | unsigned char *status; |
| 85 | |
| 86 | unsigned char *pad; |
| 87 | unsigned char *ignore_data; |
| 88 | }; |
| 89 | |
| 90 | /* CE buffers */ |
| 91 | struct ce_reg_buffers { |
| 92 | |
| 93 | unsigned char reset_buf_64[64]; |
| 94 | unsigned char version[CRYPTO_REG_SIZE]; |
| 95 | |
| 96 | unsigned char encr_seg_cfg_size_start[3 * CRYPTO_REG_SIZE]; |
| 97 | unsigned char encr_key[8 * CRYPTO_REG_SIZE]; |
| 98 | unsigned char encr_xts_key[8 * CRYPTO_REG_SIZE]; |
| 99 | unsigned char encr_cntr_iv[4 * CRYPTO_REG_SIZE]; |
| 100 | unsigned char encr_mask[CRYPTO_REG_SIZE]; |
| 101 | unsigned char encr_xts_du_size[CRYPTO_REG_SIZE]; |
| 102 | |
| 103 | unsigned char auth_seg_cfg_size_start[3 * CRYPTO_REG_SIZE]; |
| 104 | unsigned char auth_key[16 * CRYPTO_REG_SIZE]; |
| 105 | unsigned char auth_iv[16 * CRYPTO_REG_SIZE]; |
| 106 | unsigned char auth_result[16 * CRYPTO_REG_SIZE]; |
| 107 | unsigned char auth_nonce_info[4 * CRYPTO_REG_SIZE]; |
| 108 | unsigned char auth_byte_count[4 * CRYPTO_REG_SIZE]; |
| 109 | |
| 110 | unsigned char seg_size[CRYPTO_REG_SIZE]; |
| 111 | unsigned char go_proc[CRYPTO_REG_SIZE]; |
| 112 | unsigned char status[CRYPTO_REG_SIZE]; |
| 113 | |
Mona Hossain | 5f5dde1 | 2011-09-12 10:28:34 -0700 | [diff] [blame] | 114 | unsigned char pad[2 * MAX_ADM_CE_BLOCK_SIZE]; |
Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /* CE Command lists */ |
| 118 | struct ce_cmdlists { |
| 119 | dmov_s *get_hw_version; |
Mona Hossain | b8db743 | 2011-11-17 12:33:24 -0800 | [diff] [blame] | 120 | dmov_s *clear_status; |
Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 121 | dmov_s *get_status_ocu; |
| 122 | |
| 123 | dmov_s *set_cipher_cfg; |
| 124 | |
| 125 | dmov_s *set_cipher_aes_128_key; |
| 126 | dmov_s *set_cipher_aes_256_key; |
| 127 | dmov_s *set_cipher_des_key; |
| 128 | dmov_s *set_cipher_3des_key; |
| 129 | |
| 130 | dmov_s *set_cipher_aes_128_xts_key; |
| 131 | dmov_s *set_cipher_aes_256_xts_key; |
| 132 | dmov_s *set_cipher_xts_du_size; |
| 133 | |
| 134 | dmov_s *set_cipher_aes_iv; |
| 135 | dmov_s *set_cipher_aes_xts_iv; |
Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 136 | dmov_s *set_cipher_des_iv; |
Mona Hossain | b8db743 | 2011-11-17 12:33:24 -0800 | [diff] [blame] | 137 | dmov_s *get_cipher_iv; |
Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 138 | |
| 139 | dmov_s *set_cipher_mask; |
| 140 | |
| 141 | dmov_s *set_auth_cfg; |
| 142 | dmov_s *set_auth_key_128; |
| 143 | dmov_s *set_auth_key_256; |
| 144 | dmov_s *set_auth_key_512; |
| 145 | dmov_s *set_auth_iv_16; |
| 146 | dmov_s *get_auth_result_16; |
| 147 | dmov_s *set_auth_iv_20; |
| 148 | dmov_s *get_auth_result_20; |
| 149 | dmov_s *set_auth_iv_32; |
| 150 | dmov_s *get_auth_result_32; |
| 151 | dmov_s *set_auth_byte_count; |
| 152 | dmov_s *get_auth_byte_count; |
| 153 | |
| 154 | dmov_s *set_auth_nonce_info; |
| 155 | |
| 156 | dmov_s *reset_cipher_key; |
| 157 | dmov_s *reset_cipher_xts_key; |
| 158 | dmov_s *reset_cipher_iv; |
| 159 | dmov_s *reset_cipher_cfg; |
| 160 | dmov_s *reset_auth_key; |
| 161 | dmov_s *reset_auth_iv; |
| 162 | dmov_s *reset_auth_cfg; |
| 163 | dmov_s *reset_auth_byte_count; |
| 164 | |
| 165 | dmov_s *set_seg_size_ocb; |
| 166 | dmov_s *get_status_wait; |
| 167 | dmov_s *set_go_proc; |
| 168 | |
| 169 | dmov_sg *ce_data_in; |
| 170 | dmov_sg *ce_data_out; |
| 171 | }; |
| 172 | |
| 173 | /* Command pointer lists */ |
| 174 | struct ce_cmdptrlists_ops { |
| 175 | |
| 176 | uint32_t probe_ce_hw; |
| 177 | uint32_t cipher_aes_128_cbc_ctr; |
| 178 | uint32_t cipher_aes_256_cbc_ctr; |
| 179 | uint32_t cipher_aes_128_ecb; |
| 180 | uint32_t cipher_aes_256_ecb; |
| 181 | uint32_t cipher_aes_128_xts; |
| 182 | uint32_t cipher_aes_256_xts; |
| 183 | uint32_t cipher_des_cbc; |
| 184 | uint32_t cipher_des_ecb; |
| 185 | uint32_t cipher_3des_cbc; |
| 186 | uint32_t cipher_3des_ecb; |
| 187 | uint32_t auth_sha1; |
| 188 | uint32_t auth_sha256; |
| 189 | uint32_t auth_sha1_hmac; |
| 190 | uint32_t auth_sha256_hmac; |
| 191 | uint32_t auth_aes_128_cmac; |
| 192 | uint32_t auth_aes_256_cmac; |
| 193 | uint32_t aead_aes_128_ccm; |
| 194 | uint32_t aead_aes_256_ccm; |
| 195 | |
| 196 | uint32_t cipher_ce_out; |
Mona Hossain | b8db743 | 2011-11-17 12:33:24 -0800 | [diff] [blame] | 197 | uint32_t cipher_ce_out_get_iv; |
Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 198 | uint32_t aead_ce_out; |
| 199 | }; |
| 200 | |
| 201 | /* DM data structure with buffers, commandlists & commmand pointer lists */ |
| 202 | struct ce_dm_data { |
| 203 | unsigned int chan_ce_in; /* ADM channel used for CE input |
| 204 | * and auth result if authentication |
| 205 | * only operation. */ |
| 206 | unsigned int chan_ce_out; /* ADM channel used for CE output, |
| 207 | * and icv for esp */ |
| 208 | |
| 209 | unsigned int crci_in; /* CRCI for CE DM IN Channel */ |
| 210 | unsigned int crci_out; /* CRCI for CE DM OUT Channel */ |
| 211 | |
| 212 | enum qce_chan_st_enum chan_ce_in_state; /* chan ce_in state */ |
| 213 | enum qce_chan_st_enum chan_ce_out_state; /* chan ce_out state */ |
| 214 | |
| 215 | int chan_ce_in_status; /* chan ce_in status */ |
| 216 | int chan_ce_out_status; /* chan ce_out status */ |
| 217 | |
| 218 | struct dmov_desc *ce_out_src_desc; |
| 219 | struct dmov_desc *ce_out_dst_desc; |
| 220 | struct dmov_desc *ce_in_src_desc; |
| 221 | struct dmov_desc *ce_in_dst_desc; |
| 222 | |
| 223 | int ce_out_src_desc_index; |
| 224 | int ce_out_dst_desc_index; |
| 225 | int ce_in_src_desc_index; |
| 226 | int ce_in_dst_desc_index; |
| 227 | |
Mona Hossain | 5f5dde1 | 2011-09-12 10:28:34 -0700 | [diff] [blame] | 228 | int ce_block_size; |
| 229 | |
Mona Hossain | 3b574d8 | 2011-09-01 15:02:01 -0700 | [diff] [blame] | 230 | dma_addr_t phy_ce_out_ignore; |
| 231 | dma_addr_t phy_ce_pad; |
| 232 | |
| 233 | struct ce_reg_buffer_addr buffer; |
| 234 | struct ce_cmdlists cmdlist; |
| 235 | struct ce_cmdptrlists_ops cmdptrlist; |
| 236 | |
| 237 | struct msm_dmov_cmd *chan_ce_in_cmd; |
| 238 | struct msm_dmov_cmd *chan_ce_out_cmd; |
| 239 | }; |
| 240 | #endif /* _DRIVERS_CRYPTO_MSM_QCE40_H */ |