blob: 4aa6ceb50ad8ec492709fe636f6073ec4215d0fe [file] [log] [blame]
Sahitya Tummala02b59422015-05-06 10:41:16 +05301/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -07002 *
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#ifndef LINUX_MMC_CQ_HCI_H
13#define LINUX_MMC_CQ_HCI_H
14#include <linux/mmc/core.h>
15
16/* registers */
17/* version */
18#define CQVER 0x00
19/* capabilities */
20#define CQCAP 0x04
Veerabhadrarao Badiganti87ddf1b2016-12-11 20:16:58 +053021#define CQCAP_CS (1 << 28)
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -070022/* configuration */
23#define CQCFG 0x08
24#define CQ_DCMD 0x00001000
25#define CQ_TASK_DESC_SZ 0x00000100
26#define CQ_ENABLE 0x00000001
Veerabhadrarao Badiganti87ddf1b2016-12-11 20:16:58 +053027#define CQ_ICE_ENABLE 0x00000002
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -070028
29/* control */
30#define CQCTL 0x0C
31#define CLEAR_ALL_TASKS 0x00000100
32#define HALT 0x00000001
33
34/* interrupt status */
35#define CQIS 0x10
36#define CQIS_HAC (1 << 0)
37#define CQIS_TCC (1 << 1)
38#define CQIS_RED (1 << 2)
39#define CQIS_TCL (1 << 3)
40
41/* interrupt status enable */
42#define CQISTE 0x14
43
44/* interrupt signal enable */
45#define CQISGE 0x18
46
47/* interrupt coalescing */
48#define CQIC 0x1C
49#define CQIC_ENABLE (1 << 31)
50#define CQIC_RESET (1 << 16)
51#define CQIC_ICCTHWEN (1 << 15)
52#define CQIC_ICCTH(x) ((x & 0x1F) << 8)
53#define CQIC_ICTOVALWEN (1 << 7)
54#define CQIC_ICTOVAL(x) (x & 0x7F)
55
56/* task list base address */
57#define CQTDLBA 0x20
58
59/* task list base address upper */
60#define CQTDLBAU 0x24
61
62/* door-bell */
63#define CQTDBR 0x28
64
65/* task completion notification */
66#define CQTCN 0x2C
67
68/* device queue status */
69#define CQDQS 0x30
70
71/* device pending tasks */
72#define CQDPT 0x34
73
74/* task clear */
75#define CQTCLR 0x38
76
77/* send status config 1 */
78#define CQSSC1 0x40
79/*
80 * Value n means CQE would send CMD13 during the transfer of data block
81 * BLOCK_CNT-n
82 */
Asutosh Das5b81f132015-10-06 09:53:33 +053083#define SEND_QSR_INTERVAL 0x70001
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -070084
85/* send status config 2 */
86#define CQSSC2 0x44
87
88/* response for dcmd */
89#define CQCRDCT 0x48
90
91/* response mode error mask */
92#define CQRMEM 0x50
Dov Levenglick2b678302015-07-01 14:24:20 +030093#define CQ_EXCEPTION (1 << 6)
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -070094
95/* task error info */
96#define CQTERRI 0x54
97
Asutosh Das02e30862015-05-20 16:52:04 +053098/* CQTERRI bit fields */
99#define CQ_RMECI 0x1F
100#define CQ_RMETI (0x1F << 8)
101#define CQ_RMEFV (1 << 15)
102#define CQ_DTECI (0x3F << 16)
103#define CQ_DTETI (0x1F << 24)
104#define CQ_DTEFV (1 << 31)
105
106#define GET_CMD_ERR_TAG(__r__) ((__r__ & CQ_RMETI) >> 8)
107#define GET_DAT_ERR_TAG(__r__) ((__r__ & CQ_DTETI) >> 24)
108
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700109/* command response index */
110#define CQCRI 0x58
111
112/* command response argument */
113#define CQCRA 0x5C
114
115#define CQ_INT_ALL 0xF
116#define CQIC_DEFAULT_ICCTH 31
117#define CQIC_DEFAULT_ICTOVAL 1
118
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700119/* attribute fields */
120#define VALID(x) ((x & 1) << 0)
121#define END(x) ((x & 1) << 1)
122#define INT(x) ((x & 1) << 2)
123#define ACT(x) ((x & 0x7) << 3)
124
125/* data command task descriptor fields */
126#define FORCED_PROG(x) ((x & 1) << 6)
127#define CONTEXT(x) ((x & 0xF) << 7)
128#define DATA_TAG(x) ((x & 1) << 11)
129#define DATA_DIR(x) ((x & 1) << 12)
130#define PRIORITY(x) ((x & 1) << 13)
131#define QBAR(x) ((x & 1) << 14)
132#define REL_WRITE(x) ((x & 1) << 15)
133#define BLK_COUNT(x) ((x & 0xFFFF) << 16)
134#define BLK_ADDR(x) ((x & 0xFFFFFFFF) << 32)
135
136/* direct command task descriptor fields */
137#define CMD_INDEX(x) ((x & 0x3F) << 16)
138#define CMD_TIMING(x) ((x & 1) << 22)
139#define RESP_TYPE(x) ((x & 0x3) << 23)
140
141/* transfer descriptor fields */
142#define DAT_LENGTH(x) ((x & 0xFFFF) << 16)
143#define DAT_ADDR_LO(x) ((x & 0xFFFFFFFF) << 32)
144#define DAT_ADDR_HI(x) ((x & 0xFFFFFFFF) << 0)
145
Asutosh Dasc0ed9c42015-05-29 15:39:37 +0530146#define CQ_VENDOR_CFG 0x100
147#define CMDQ_SEND_STATUS_TRIGGER (1 << 31)
148
Veerabhadrarao Badiganti87ddf1b2016-12-11 20:16:58 +0530149#define CQ_TASK_DESC_TASK_PARAMS_SIZE 8
150#define CQ_TASK_DESC_ICE_PARAMS_SIZE 8
151
Venkat Gopalakrishnane77c64d2015-09-28 18:53:18 -0700152struct task_history {
153 u64 task;
154 bool is_dcmd;
155};
156
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700157struct cmdq_host {
158 const struct cmdq_host_ops *ops;
159 void __iomem *mmio;
160 struct mmc_host *mmc;
161
162 /* 64 bit DMA */
163 bool dma64;
164 int num_slots;
165
166 u32 dcmd_slot;
167 u32 caps;
168#define CMDQ_TASK_DESC_SZ_128 0x1
Veerabhadrarao Badiganti87ddf1b2016-12-11 20:16:58 +0530169#define CMDQ_CAP_CRYPTO_SUPPORT 0x2
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700170
171 u32 quirks;
172#define CMDQ_QUIRK_SHORT_TXFR_DESC_SZ 0x1
173#define CMDQ_QUIRK_NO_DCMD 0x2
174
175 bool enabled;
176 bool halted;
177 bool init_done;
178
179 u8 *desc_base;
180
181 /* total descriptor size */
182 u8 slot_sz;
183
184 /* 64/128 bit depends on CQCFG */
185 u8 task_desc_len;
186
187 /* 64 bit on 32-bit arch, 128 bit on 64-bit */
188 u8 link_desc_len;
189
190 u8 *trans_desc_base;
191 /* same length as transfer descriptor */
192 u8 trans_desc_len;
193
194 dma_addr_t desc_dma_base;
195 dma_addr_t trans_desc_dma_base;
196
Venkat Gopalakrishnane77c64d2015-09-28 18:53:18 -0700197 struct task_history *thist;
198 u8 thist_idx;
199
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700200 struct completion halt_comp;
201 struct mmc_request **mrq_slot;
202 void *private;
203};
204
205struct cmdq_host_ops {
Sahitya Tummala87231ce2016-04-12 13:24:51 +0530206 void (*set_transfer_params)(struct mmc_host *mmc);
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700207 void (*set_data_timeout)(struct mmc_host *mmc, u32 val);
208 void (*clear_set_irqs)(struct mmc_host *mmc, bool clear);
209 void (*set_block_size)(struct mmc_host *mmc);
210 void (*dump_vendor_regs)(struct mmc_host *mmc);
211 void (*write_l)(struct cmdq_host *host, u32 val, int reg);
212 u32 (*read_l)(struct cmdq_host *host, int reg);
213 void (*clear_set_dumpregs)(struct mmc_host *mmc, bool set);
Ritesh Harjani6b2ea572015-07-15 13:23:05 +0530214 void (*enhanced_strobe_mask)(struct mmc_host *mmc, bool set);
Asutosh Das02e30862015-05-20 16:52:04 +0530215 int (*reset)(struct mmc_host *mmc);
Konstantin Dorfmanfa321072015-05-31 10:10:13 +0300216 void (*post_cqe_halt)(struct mmc_host *mmc);
Sahitya Tummala02b59422015-05-06 10:41:16 +0530217 int (*crypto_cfg)(struct mmc_host *mmc, struct mmc_request *mrq,
Veerabhadrarao Badiganti87ddf1b2016-12-11 20:16:58 +0530218 u32 slot, u64 *ice_ctx);
Sahitya Tummala82a19752015-09-01 16:44:08 +0530219 void (*crypto_cfg_reset)(struct mmc_host *mmc, unsigned int slot);
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700220};
221
222static inline void cmdq_writel(struct cmdq_host *host, u32 val, int reg)
223{
Ritesh Harjaniee93d262015-12-30 15:53:49 +0530224 if (unlikely(host->ops && host->ops->write_l))
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700225 host->ops->write_l(host, val, reg);
226 else
227 writel_relaxed(val, host->mmio + reg);
228}
229
230static inline u32 cmdq_readl(struct cmdq_host *host, int reg)
231{
Ritesh Harjaniee93d262015-12-30 15:53:49 +0530232 if (unlikely(host->ops && host->ops->read_l))
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700233 return host->ops->read_l(host, reg);
234 else
235 return readl_relaxed(host->mmio + reg);
236}
237
Asutosh Das02e30862015-05-20 16:52:04 +0530238extern irqreturn_t cmdq_irq(struct mmc_host *mmc, int err);
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -0700239extern int cmdq_init(struct cmdq_host *cq_host, struct mmc_host *mmc,
240 bool dma64);
241extern struct cmdq_host *cmdq_pltfm_init(struct platform_device *pdev);
242#endif