]> Git Repo - J-linux.git/blob - include/linux/mmc/core.h
Merge tag 'vfs-6.13-rc7.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[J-linux.git] / include / linux / mmc / core.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *  linux/include/linux/mmc/core.h
4  */
5 #ifndef LINUX_MMC_CORE_H
6 #define LINUX_MMC_CORE_H
7
8 #include <linux/completion.h>
9 #include <linux/types.h>
10
11 struct mmc_data;
12 struct mmc_request;
13
14 #define UHS2_MAX_PAYLOAD_LEN 2
15 #define UHS2_MAX_RESP_LEN 20
16
17 struct uhs2_command {
18         u16     header;
19         u16     arg;
20         __be32  payload[UHS2_MAX_PAYLOAD_LEN];
21         u8      payload_len;
22         u8      packet_len;
23         u8      tmode_half_duplex;
24         u8      uhs2_resp[UHS2_MAX_RESP_LEN];   /* UHS2 native cmd resp */
25         u8      uhs2_resp_len;                  /* UHS2 native cmd resp len */
26 };
27
28 struct mmc_command {
29         u32                     opcode;
30         u32                     arg;
31 #define MMC_CMD23_ARG_REL_WR    (1 << 31)
32 #define MMC_CMD23_ARG_TAG_REQ   (1 << 29)
33         u32                     resp[4];
34         unsigned int            flags;          /* expected response type */
35 #define MMC_RSP_PRESENT (1 << 0)
36 #define MMC_RSP_136     (1 << 1)                /* 136 bit response */
37 #define MMC_RSP_CRC     (1 << 2)                /* expect valid crc */
38 #define MMC_RSP_BUSY    (1 << 3)                /* card may send busy */
39 #define MMC_RSP_OPCODE  (1 << 4)                /* response contains opcode */
40
41 #define MMC_CMD_MASK    (3 << 5)                /* non-SPI command type */
42 #define MMC_CMD_AC      (0 << 5)
43 #define MMC_CMD_ADTC    (1 << 5)
44 #define MMC_CMD_BC      (2 << 5)
45 #define MMC_CMD_BCR     (3 << 5)
46
47 #define MMC_RSP_SPI_S1  (1 << 7)                /* one status byte */
48 #define MMC_RSP_SPI_S2  (1 << 8)                /* second byte */
49 #define MMC_RSP_SPI_B4  (1 << 9)                /* four data bytes */
50 #define MMC_RSP_SPI_BUSY (1 << 10)              /* card may send busy */
51
52 /*
53  * These are the native response types, and correspond to valid bit
54  * patterns of the above flags.  One additional valid pattern
55  * is all zeros, which means we don't expect a response.
56  */
57 #define MMC_RSP_NONE    (0)
58 #define MMC_RSP_R1      (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
59 #define MMC_RSP_R1B     (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
60 #define MMC_RSP_R2      (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
61 #define MMC_RSP_R3      (MMC_RSP_PRESENT)
62 #define MMC_RSP_R4      (MMC_RSP_PRESENT)
63 #define MMC_RSP_R5      (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
64 #define MMC_RSP_R6      (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
65 #define MMC_RSP_R7      (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
66
67 /* Can be used by core to poll after switch to MMC HS mode */
68 #define MMC_RSP_R1_NO_CRC       (MMC_RSP_PRESENT|MMC_RSP_OPCODE)
69
70 #define mmc_resp_type(cmd)      ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
71
72 /*
73  * These are the SPI response types for MMC, SD, and SDIO cards.
74  * Commands return R1, with maybe more info.  Zero is an error type;
75  * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
76  */
77 #define MMC_RSP_SPI_R1  (MMC_RSP_SPI_S1)
78 #define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
79 #define MMC_RSP_SPI_R2  (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
80 #define MMC_RSP_SPI_R3  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
81 #define MMC_RSP_SPI_R4  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
82 #define MMC_RSP_SPI_R5  (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
83 #define MMC_RSP_SPI_R7  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
84
85 #define mmc_spi_resp_type(cmd)  ((cmd)->flags & \
86                 (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
87
88 /*
89  * These are the command types.
90  */
91 #define mmc_cmd_type(cmd)       ((cmd)->flags & MMC_CMD_MASK)
92
93         unsigned int            retries;        /* max number of retries */
94         int                     error;          /* command error */
95
96 /*
97  * Standard errno values are used for errors, but some have specific
98  * meaning in the MMC layer:
99  *
100  * ETIMEDOUT    Card took too long to respond
101  * EILSEQ       Basic format problem with the received or sent data
102  *              (e.g. CRC check failed, incorrect opcode in response
103  *              or bad end bit)
104  * EINVAL       Request cannot be performed because of restrictions
105  *              in hardware and/or the driver
106  * ENOMEDIUM    Host can determine that the slot is empty and is
107  *              actively failing requests
108  */
109
110         unsigned int            busy_timeout;   /* busy detect timeout in ms */
111         struct mmc_data         *data;          /* data segment associated with cmd */
112         struct mmc_request      *mrq;           /* associated request */
113
114         struct uhs2_command     *uhs2_cmd;      /* UHS2 command */
115
116         /* for SDUC */
117         bool has_ext_addr;
118         u8 ext_addr;
119 };
120
121 struct mmc_data {
122         unsigned int            timeout_ns;     /* data timeout (in ns, max 80ms) */
123         unsigned int            timeout_clks;   /* data timeout (in clocks) */
124         unsigned int            blksz;          /* data block size */
125         unsigned int            blocks;         /* number of blocks */
126         unsigned int            blk_addr;       /* block address */
127         int                     error;          /* data error */
128         unsigned int            flags;
129
130 #define MMC_DATA_WRITE          BIT(8)
131 #define MMC_DATA_READ           BIT(9)
132 /* Extra flags used by CQE */
133 #define MMC_DATA_QBR            BIT(10)         /* CQE queue barrier*/
134 #define MMC_DATA_PRIO           BIT(11)         /* CQE high priority */
135 #define MMC_DATA_REL_WR         BIT(12)         /* Reliable write */
136 #define MMC_DATA_DAT_TAG        BIT(13)         /* Tag request */
137 #define MMC_DATA_FORCED_PRG     BIT(14)         /* Forced programming */
138
139         unsigned int            bytes_xfered;
140
141         struct mmc_command      *stop;          /* stop command */
142         struct mmc_request      *mrq;           /* associated request */
143
144         unsigned int            sg_len;         /* size of scatter list */
145         int                     sg_count;       /* mapped sg entries */
146         struct scatterlist      *sg;            /* I/O scatter list */
147         s32                     host_cookie;    /* host private data */
148 };
149
150 struct mmc_host;
151 struct mmc_request {
152         struct mmc_command      *sbc;           /* SET_BLOCK_COUNT for multiblock */
153         struct mmc_command      *cmd;
154         struct mmc_data         *data;
155         struct mmc_command      *stop;
156
157         struct completion       completion;
158         struct completion       cmd_completion;
159         void                    (*done)(struct mmc_request *);/* completion function */
160         /*
161          * Notify uppers layers (e.g. mmc block driver) that recovery is needed
162          * due to an error associated with the mmc_request. Currently used only
163          * by CQE.
164          */
165         void                    (*recovery_notifier)(struct mmc_request *);
166         struct mmc_host         *host;
167
168         /* Allow other commands during this ongoing data transfer or busy wait */
169         bool                    cap_cmd_during_tfr;
170
171         int                     tag;
172
173 #ifdef CONFIG_MMC_CRYPTO
174         const struct bio_crypt_ctx *crypto_ctx;
175         int                     crypto_key_slot;
176 #endif
177         struct uhs2_command     uhs2_cmd;
178 };
179
180 struct mmc_card;
181
182 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq);
183 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd,
184                 int retries);
185
186 int mmc_hw_reset(struct mmc_card *card);
187 int mmc_sw_reset(struct mmc_card *card);
188 void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card);
189
190 #endif /* LINUX_MMC_CORE_H */
This page took 0.03823 seconds and 4 git commands to generate.