hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/mmc/host/cqhci.h
....@@ -1,13 +1,5 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /* 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.
113 */
124 #ifndef LINUX_MMC_CQHCI_H
135 #define LINUX_MMC_CQHCI_H
....@@ -30,10 +22,13 @@
3022
3123 /* capabilities */
3224 #define CQHCI_CAP 0x04
25
+#define CQHCI_CAP_CS 0x10000000 /* Crypto Support */
26
+
3327 /* configuration */
3428 #define CQHCI_CFG 0x08
3529 #define CQHCI_DCMD 0x00001000
3630 #define CQHCI_TASK_DESC_SZ 0x00000100
31
+#define CQHCI_CRYPTO_GENERAL_ENABLE 0x00000002
3732 #define CQHCI_ENABLE 0x00000001
3833
3934 /* control */
....@@ -47,8 +42,11 @@
4742 #define CQHCI_IS_TCC BIT(1)
4843 #define CQHCI_IS_RED BIT(2)
4944 #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 */
5047
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)
5250
5351 /* interrupt status enable */
5452 #define CQHCI_ISTE 0x14
....@@ -86,8 +84,12 @@
8684 /* task clear */
8785 #define CQHCI_TCLR 0x38
8886
87
+/* task descriptor processing error */
88
+#define CQHCI_TDPE 0x3c
89
+
8990 /* send status config 1 */
9091 #define CQHCI_SSC1 0x40
92
+#define CQHCI_SSC1_CBC_MASK GENMASK(19, 16)
9193
9294 /* send status config 2 */
9395 #define CQHCI_SSC2 0x44
....@@ -113,6 +115,10 @@
113115
114116 /* command response argument */
115117 #define CQHCI_CRA 0x5C
118
+
119
+/* crypto capabilities */
120
+#define CQHCI_CCAP 0x100
121
+#define CQHCI_CRYPTOCAP 0x104
116122
117123 #define CQHCI_INT_ALL 0xF
118124 #define CQHCI_IC_DEFAULT_ICCTH 31
....@@ -140,13 +146,73 @@
140146 #define CQHCI_CMD_TIMING(x) (((x) & 1) << 22)
141147 #define CQHCI_RESP_TYPE(x) (((x) & 0x3) << 23)
142148
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
+
143153 /* transfer descriptor fields */
144154 #define CQHCI_DAT_LENGTH(x) (((x) & 0xFFFF) << 16)
145155 #define CQHCI_DAT_ADDR_LO(x) (((x) & 0xFFFFFFFF) << 32)
146156 #define CQHCI_DAT_ADDR_HI(x) (((x) & 0xFFFFFFFF) << 0)
147157
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
+
148213 struct cqhci_host_ops;
149214 struct mmc_host;
215
+struct mmc_request;
150216 struct cqhci_slot;
151217
152218 struct cqhci_host {
....@@ -202,6 +268,12 @@
202268 struct completion halt_comp;
203269 wait_queue_head_t wait_queue;
204270 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
205277 };
206278
207279 struct cqhci_host_ops {
....@@ -210,6 +282,14 @@
210282 u32 (*read_l)(struct cqhci_host *host, int reg);
211283 void (*enable)(struct mmc_host *mmc);
212284 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
213293 };
214294
215295 static inline void cqhci_writel(struct cqhci_host *host, u32 val, int reg)
....@@ -234,7 +314,11 @@
234314 int data_error);
235315 int cqhci_init(struct cqhci_host *cq_host, struct mmc_host *mmc, bool dma64);
236316 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
+}
238322 int cqhci_resume(struct mmc_host *mmc);
239323
240324 #endif