.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* Copyright (c) 2015, The Linux Foundation. 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 | 3 | */ |
---|
12 | 4 | #ifndef LINUX_MMC_CQHCI_H |
---|
13 | 5 | #define LINUX_MMC_CQHCI_H |
---|
.. | .. |
---|
30 | 22 | |
---|
31 | 23 | /* capabilities */ |
---|
32 | 24 | #define CQHCI_CAP 0x04 |
---|
| 25 | +#define CQHCI_CAP_CS 0x10000000 /* Crypto Support */ |
---|
| 26 | + |
---|
33 | 27 | /* configuration */ |
---|
34 | 28 | #define CQHCI_CFG 0x08 |
---|
35 | 29 | #define CQHCI_DCMD 0x00001000 |
---|
36 | 30 | #define CQHCI_TASK_DESC_SZ 0x00000100 |
---|
| 31 | +#define CQHCI_CRYPTO_GENERAL_ENABLE 0x00000002 |
---|
37 | 32 | #define CQHCI_ENABLE 0x00000001 |
---|
38 | 33 | |
---|
39 | 34 | /* control */ |
---|
.. | .. |
---|
47 | 42 | #define CQHCI_IS_TCC BIT(1) |
---|
48 | 43 | #define CQHCI_IS_RED BIT(2) |
---|
49 | 44 | #define CQHCI_IS_TCL BIT(3) |
---|
| 45 | +#define CQHCI_IS_GCE BIT(4) /* General Crypto Error */ |
---|
| 46 | +#define CQHCI_IS_ICCE BIT(5) /* Invalid Crypto Config Error */ |
---|
50 | 47 | |
---|
51 | | -#define CQHCI_IS_MASK (CQHCI_IS_TCC | CQHCI_IS_RED) |
---|
| 48 | +#define CQHCI_IS_MASK (CQHCI_IS_TCC | CQHCI_IS_RED | \ |
---|
| 49 | + CQHCI_IS_GCE | CQHCI_IS_ICCE) |
---|
52 | 50 | |
---|
53 | 51 | /* interrupt status enable */ |
---|
54 | 52 | #define CQHCI_ISTE 0x14 |
---|
.. | .. |
---|
86 | 84 | /* task clear */ |
---|
87 | 85 | #define CQHCI_TCLR 0x38 |
---|
88 | 86 | |
---|
| 87 | +/* task descriptor processing error */ |
---|
| 88 | +#define CQHCI_TDPE 0x3c |
---|
| 89 | + |
---|
89 | 90 | /* send status config 1 */ |
---|
90 | 91 | #define CQHCI_SSC1 0x40 |
---|
| 92 | +#define CQHCI_SSC1_CBC_MASK GENMASK(19, 16) |
---|
91 | 93 | |
---|
92 | 94 | /* send status config 2 */ |
---|
93 | 95 | #define CQHCI_SSC2 0x44 |
---|
.. | .. |
---|
113 | 115 | |
---|
114 | 116 | /* command response argument */ |
---|
115 | 117 | #define CQHCI_CRA 0x5C |
---|
| 118 | + |
---|
| 119 | +/* crypto capabilities */ |
---|
| 120 | +#define CQHCI_CCAP 0x100 |
---|
| 121 | +#define CQHCI_CRYPTOCAP 0x104 |
---|
116 | 122 | |
---|
117 | 123 | #define CQHCI_INT_ALL 0xF |
---|
118 | 124 | #define CQHCI_IC_DEFAULT_ICCTH 31 |
---|
.. | .. |
---|
140 | 146 | #define CQHCI_CMD_TIMING(x) (((x) & 1) << 22) |
---|
141 | 147 | #define CQHCI_RESP_TYPE(x) (((x) & 0x3) << 23) |
---|
142 | 148 | |
---|
| 149 | +/* crypto task descriptor fields (for bits 64-127 of task descriptor) */ |
---|
| 150 | +#define CQHCI_CRYPTO_ENABLE_BIT (1ULL << 47) |
---|
| 151 | +#define CQHCI_CRYPTO_KEYSLOT(x) ((u64)(x) << 32) |
---|
| 152 | + |
---|
143 | 153 | /* transfer descriptor fields */ |
---|
144 | 154 | #define CQHCI_DAT_LENGTH(x) (((x) & 0xFFFF) << 16) |
---|
145 | 155 | #define CQHCI_DAT_ADDR_LO(x) (((x) & 0xFFFFFFFF) << 32) |
---|
146 | 156 | #define CQHCI_DAT_ADDR_HI(x) (((x) & 0xFFFFFFFF) << 0) |
---|
147 | 157 | |
---|
| 158 | +/* CCAP - Crypto Capability 100h */ |
---|
| 159 | +union cqhci_crypto_capabilities { |
---|
| 160 | + __le32 reg_val; |
---|
| 161 | + struct { |
---|
| 162 | + u8 num_crypto_cap; |
---|
| 163 | + u8 config_count; |
---|
| 164 | + u8 reserved; |
---|
| 165 | + u8 config_array_ptr; |
---|
| 166 | + }; |
---|
| 167 | +}; |
---|
| 168 | + |
---|
| 169 | +enum cqhci_crypto_key_size { |
---|
| 170 | + CQHCI_CRYPTO_KEY_SIZE_INVALID = 0, |
---|
| 171 | + CQHCI_CRYPTO_KEY_SIZE_128 = 1, |
---|
| 172 | + CQHCI_CRYPTO_KEY_SIZE_192 = 2, |
---|
| 173 | + CQHCI_CRYPTO_KEY_SIZE_256 = 3, |
---|
| 174 | + CQHCI_CRYPTO_KEY_SIZE_512 = 4, |
---|
| 175 | +}; |
---|
| 176 | + |
---|
| 177 | +enum cqhci_crypto_alg { |
---|
| 178 | + CQHCI_CRYPTO_ALG_AES_XTS = 0, |
---|
| 179 | + CQHCI_CRYPTO_ALG_BITLOCKER_AES_CBC = 1, |
---|
| 180 | + CQHCI_CRYPTO_ALG_AES_ECB = 2, |
---|
| 181 | + CQHCI_CRYPTO_ALG_ESSIV_AES_CBC = 3, |
---|
| 182 | +}; |
---|
| 183 | + |
---|
| 184 | +/* x-CRYPTOCAP - Crypto Capability X */ |
---|
| 185 | +union cqhci_crypto_cap_entry { |
---|
| 186 | + __le32 reg_val; |
---|
| 187 | + struct { |
---|
| 188 | + u8 algorithm_id; |
---|
| 189 | + u8 sdus_mask; /* Supported data unit size mask */ |
---|
| 190 | + u8 key_size; |
---|
| 191 | + u8 reserved; |
---|
| 192 | + }; |
---|
| 193 | +}; |
---|
| 194 | + |
---|
| 195 | +#define CQHCI_CRYPTO_CONFIGURATION_ENABLE (1 << 7) |
---|
| 196 | +#define CQHCI_CRYPTO_KEY_MAX_SIZE 64 |
---|
| 197 | +/* x-CRYPTOCFG - Crypto Configuration X */ |
---|
| 198 | +union cqhci_crypto_cfg_entry { |
---|
| 199 | + __le32 reg_val[32]; |
---|
| 200 | + struct { |
---|
| 201 | + u8 crypto_key[CQHCI_CRYPTO_KEY_MAX_SIZE]; |
---|
| 202 | + u8 data_unit_size; |
---|
| 203 | + u8 crypto_cap_idx; |
---|
| 204 | + u8 reserved_1; |
---|
| 205 | + u8 config_enable; |
---|
| 206 | + u8 reserved_multi_host; |
---|
| 207 | + u8 reserved_2; |
---|
| 208 | + u8 vsb[2]; |
---|
| 209 | + u8 reserved_3[56]; |
---|
| 210 | + }; |
---|
| 211 | +}; |
---|
| 212 | + |
---|
148 | 213 | struct cqhci_host_ops; |
---|
149 | 214 | struct mmc_host; |
---|
| 215 | +struct mmc_request; |
---|
150 | 216 | struct cqhci_slot; |
---|
151 | 217 | |
---|
152 | 218 | struct cqhci_host { |
---|
.. | .. |
---|
202 | 268 | struct completion halt_comp; |
---|
203 | 269 | wait_queue_head_t wait_queue; |
---|
204 | 270 | struct cqhci_slot *slot; |
---|
| 271 | + |
---|
| 272 | +#ifdef CONFIG_MMC_CRYPTO |
---|
| 273 | + union cqhci_crypto_capabilities crypto_capabilities; |
---|
| 274 | + union cqhci_crypto_cap_entry *crypto_cap_array; |
---|
| 275 | + u32 crypto_cfg_register; |
---|
| 276 | +#endif |
---|
205 | 277 | }; |
---|
206 | 278 | |
---|
207 | 279 | struct cqhci_host_ops { |
---|
.. | .. |
---|
210 | 282 | u32 (*read_l)(struct cqhci_host *host, int reg); |
---|
211 | 283 | void (*enable)(struct mmc_host *mmc); |
---|
212 | 284 | void (*disable)(struct mmc_host *mmc, bool recovery); |
---|
| 285 | + void (*update_dcmd_desc)(struct mmc_host *mmc, struct mmc_request *mrq, |
---|
| 286 | + u64 *data); |
---|
| 287 | + void (*pre_enable)(struct mmc_host *mmc); |
---|
| 288 | + void (*post_disable)(struct mmc_host *mmc); |
---|
| 289 | +#ifdef CONFIG_MMC_CRYPTO |
---|
| 290 | + int (*program_key)(struct cqhci_host *cq_host, |
---|
| 291 | + const union cqhci_crypto_cfg_entry *cfg, int slot); |
---|
| 292 | +#endif |
---|
213 | 293 | }; |
---|
214 | 294 | |
---|
215 | 295 | static inline void cqhci_writel(struct cqhci_host *host, u32 val, int reg) |
---|
.. | .. |
---|
234 | 314 | int data_error); |
---|
235 | 315 | int cqhci_init(struct cqhci_host *cq_host, struct mmc_host *mmc, bool dma64); |
---|
236 | 316 | struct cqhci_host *cqhci_pltfm_init(struct platform_device *pdev); |
---|
237 | | -int cqhci_suspend(struct mmc_host *mmc); |
---|
| 317 | +int cqhci_deactivate(struct mmc_host *mmc); |
---|
| 318 | +static inline int cqhci_suspend(struct mmc_host *mmc) |
---|
| 319 | +{ |
---|
| 320 | + return cqhci_deactivate(mmc); |
---|
| 321 | +} |
---|
238 | 322 | int cqhci_resume(struct mmc_host *mmc); |
---|
239 | 323 | |
---|
240 | 324 | #endif |
---|