1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/include/linux/mmc/core.h
5 #ifndef LINUX_MMC_CORE_H
6 #define LINUX_MMC_CORE_H
8 #include <linux/completion.h>
9 #include <linux/types.h>
29 #define MMC_CMD23_ARG_REL_WR (1 << 31)
30 #define MMC_CMD23_ARG_PACKED ((0 << 31) | (1 << 30))
31 #define MMC_CMD23_ARG_TAG_REQ (1 << 29)
33 unsigned int flags
; /* expected response type */
34 #define MMC_RSP_PRESENT (1 << 0)
35 #define MMC_RSP_136 (1 << 1) /* 136 bit response */
36 #define MMC_RSP_CRC (1 << 2) /* expect valid crc */
37 #define MMC_RSP_BUSY (1 << 3) /* card may send busy */
38 #define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
40 #define MMC_CMD_MASK (3 << 5) /* non-SPI command type */
41 #define MMC_CMD_AC (0 << 5)
42 #define MMC_CMD_ADTC (1 << 5)
43 #define MMC_CMD_BC (2 << 5)
44 #define MMC_CMD_BCR (3 << 5)
46 #define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */
47 #define MMC_RSP_SPI_S2 (1 << 8) /* second byte */
48 #define MMC_RSP_SPI_B4 (1 << 9) /* four data bytes */
49 #define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */
52 * These are the native response types, and correspond to valid bit
53 * patterns of the above flags. One additional valid pattern
54 * is all zeros, which means we don't expect a response.
56 #define MMC_RSP_NONE (0)
57 #define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
58 #define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
59 #define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
60 #define MMC_RSP_R3 (MMC_RSP_PRESENT)
61 #define MMC_RSP_R4 (MMC_RSP_PRESENT)
62 #define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
63 #define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
64 #define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
66 /* Can be used by core to poll after switch to MMC HS mode */
67 #define MMC_RSP_R1_NO_CRC (MMC_RSP_PRESENT|MMC_RSP_OPCODE)
69 #define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
72 * These are the SPI response types for MMC, SD, and SDIO cards.
73 * Commands return R1, with maybe more info. Zero is an error type;
74 * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
76 #define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)
77 #define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
78 #define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
79 #define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
80 #define MMC_RSP_SPI_R4 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
81 #define MMC_RSP_SPI_R5 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
82 #define MMC_RSP_SPI_R7 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
84 #define mmc_spi_resp_type(cmd) ((cmd)->flags & \
85 (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
88 * These are the command types.
90 #define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK)
92 unsigned int retries
; /* max number of retries */
93 int error
; /* command error */
96 * Standard errno values are used for errors, but some have specific
97 * meaning in the MMC layer:
99 * ETIMEDOUT Card took too long to respond
100 * EILSEQ Basic format problem with the received or sent data
101 * (e.g. CRC check failed, incorrect opcode in response
103 * EINVAL Request cannot be performed because of restrictions
104 * in hardware and/or the driver
105 * ENOMEDIUM Host can determine that the slot is empty and is
106 * actively failing requests
109 unsigned int busy_timeout
; /* busy detect timeout in ms */
110 struct mmc_data
*data
; /* data segment associated with cmd */
111 struct mmc_request
*mrq
; /* associated request */
115 unsigned int timeout_ns
; /* data timeout (in ns, max 80ms) */
116 unsigned int timeout_clks
; /* data timeout (in clocks) */
117 unsigned int blksz
; /* data block size */
118 unsigned int blocks
; /* number of blocks */
119 unsigned int blk_addr
; /* block address */
120 int error
; /* data error */
123 #define MMC_DATA_WRITE BIT(8)
124 #define MMC_DATA_READ BIT(9)
125 /* Extra flags used by CQE */
126 #define MMC_DATA_QBR BIT(10) /* CQE queue barrier*/
127 #define MMC_DATA_PRIO BIT(11) /* CQE high priority */
128 #define MMC_DATA_REL_WR BIT(12) /* Reliable write */
129 #define MMC_DATA_DAT_TAG BIT(13) /* Tag request */
130 #define MMC_DATA_FORCED_PRG BIT(14) /* Forced programming */
132 unsigned int bytes_xfered
;
134 struct mmc_command
*stop
; /* stop command */
135 struct mmc_request
*mrq
; /* associated request */
137 unsigned int sg_len
; /* size of scatter list */
138 int sg_count
; /* mapped sg entries */
139 struct scatterlist
*sg
; /* I/O scatter list */
140 s32 host_cookie
; /* host private data */
145 struct mmc_command
*sbc
; /* SET_BLOCK_COUNT for multiblock */
146 struct mmc_command
*cmd
;
147 struct mmc_data
*data
;
148 struct mmc_command
*stop
;
150 struct completion completion
;
151 struct completion cmd_completion
;
152 void (*done
)(struct mmc_request
*);/* completion function */
154 * Notify uppers layers (e.g. mmc block driver) that recovery is needed
155 * due to an error associated with the mmc_request. Currently used only
158 void (*recovery_notifier
)(struct mmc_request
*);
159 struct mmc_host
*host
;
161 /* Allow other commands during this ongoing data transfer or busy wait */
162 bool cap_cmd_during_tfr
;
169 void mmc_wait_for_req(struct mmc_host
*host
, struct mmc_request
*mrq
);
170 int mmc_wait_for_cmd(struct mmc_host
*host
, struct mmc_command
*cmd
,
173 int mmc_hw_reset(struct mmc_host
*host
);
174 int mmc_sw_reset(struct mmc_host
*host
);
175 void mmc_set_data_timeout(struct mmc_data
*data
, const struct mmc_card
*card
);
177 #endif /* LINUX_MMC_CORE_H */