Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  linux/include/linux/mmc/core.h
0004  */
0005 #ifndef LINUX_MMC_CORE_H
0006 #define LINUX_MMC_CORE_H
0007 
0008 #include <linux/completion.h>
0009 #include <linux/types.h>
0010 
0011 struct mmc_data;
0012 struct mmc_request;
0013 
0014 enum mmc_blk_status {
0015     MMC_BLK_SUCCESS = 0,
0016     MMC_BLK_PARTIAL,
0017     MMC_BLK_CMD_ERR,
0018     MMC_BLK_RETRY,
0019     MMC_BLK_ABORT,
0020     MMC_BLK_DATA_ERR,
0021     MMC_BLK_ECC_ERR,
0022     MMC_BLK_NOMEDIUM,
0023     MMC_BLK_NEW_REQUEST,
0024 };
0025 
0026 struct mmc_command {
0027     u32         opcode;
0028     u32         arg;
0029 #define MMC_CMD23_ARG_REL_WR    (1 << 31)
0030 #define MMC_CMD23_ARG_PACKED    ((0 << 31) | (1 << 30))
0031 #define MMC_CMD23_ARG_TAG_REQ   (1 << 29)
0032     u32         resp[4];
0033     unsigned int        flags;      /* expected response type */
0034 #define MMC_RSP_PRESENT (1 << 0)
0035 #define MMC_RSP_136 (1 << 1)        /* 136 bit response */
0036 #define MMC_RSP_CRC (1 << 2)        /* expect valid crc */
0037 #define MMC_RSP_BUSY    (1 << 3)        /* card may send busy */
0038 #define MMC_RSP_OPCODE  (1 << 4)        /* response contains opcode */
0039 
0040 #define MMC_CMD_MASK    (3 << 5)        /* non-SPI command type */
0041 #define MMC_CMD_AC  (0 << 5)
0042 #define MMC_CMD_ADTC    (1 << 5)
0043 #define MMC_CMD_BC  (2 << 5)
0044 #define MMC_CMD_BCR (3 << 5)
0045 
0046 #define MMC_RSP_SPI_S1  (1 << 7)        /* one status byte */
0047 #define MMC_RSP_SPI_S2  (1 << 8)        /* second byte */
0048 #define MMC_RSP_SPI_B4  (1 << 9)        /* four data bytes */
0049 #define MMC_RSP_SPI_BUSY (1 << 10)      /* card may send busy */
0050 
0051 /*
0052  * These are the native response types, and correspond to valid bit
0053  * patterns of the above flags.  One additional valid pattern
0054  * is all zeros, which means we don't expect a response.
0055  */
0056 #define MMC_RSP_NONE    (0)
0057 #define MMC_RSP_R1  (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
0058 #define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
0059 #define MMC_RSP_R2  (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
0060 #define MMC_RSP_R3  (MMC_RSP_PRESENT)
0061 #define MMC_RSP_R4  (MMC_RSP_PRESENT)
0062 #define MMC_RSP_R5  (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
0063 #define MMC_RSP_R6  (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
0064 #define MMC_RSP_R7  (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
0065 
0066 /* Can be used by core to poll after switch to MMC HS mode */
0067 #define MMC_RSP_R1_NO_CRC   (MMC_RSP_PRESENT|MMC_RSP_OPCODE)
0068 
0069 #define mmc_resp_type(cmd)  ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
0070 
0071 /*
0072  * These are the SPI response types for MMC, SD, and SDIO cards.
0073  * Commands return R1, with maybe more info.  Zero is an error type;
0074  * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
0075  */
0076 #define MMC_RSP_SPI_R1  (MMC_RSP_SPI_S1)
0077 #define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
0078 #define MMC_RSP_SPI_R2  (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
0079 #define MMC_RSP_SPI_R3  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
0080 #define MMC_RSP_SPI_R4  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
0081 #define MMC_RSP_SPI_R5  (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
0082 #define MMC_RSP_SPI_R7  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
0083 
0084 #define mmc_spi_resp_type(cmd)  ((cmd)->flags & \
0085         (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
0086 
0087 /*
0088  * These are the command types.
0089  */
0090 #define mmc_cmd_type(cmd)   ((cmd)->flags & MMC_CMD_MASK)
0091 
0092     unsigned int        retries;    /* max number of retries */
0093     int         error;      /* command error */
0094 
0095 /*
0096  * Standard errno values are used for errors, but some have specific
0097  * meaning in the MMC layer:
0098  *
0099  * ETIMEDOUT    Card took too long to respond
0100  * EILSEQ       Basic format problem with the received or sent data
0101  *              (e.g. CRC check failed, incorrect opcode in response
0102  *              or bad end bit)
0103  * EINVAL       Request cannot be performed because of restrictions
0104  *              in hardware and/or the driver
0105  * ENOMEDIUM    Host can determine that the slot is empty and is
0106  *              actively failing requests
0107  */
0108 
0109     unsigned int        busy_timeout;   /* busy detect timeout in ms */
0110     struct mmc_data     *data;      /* data segment associated with cmd */
0111     struct mmc_request  *mrq;       /* associated request */
0112 };
0113 
0114 struct mmc_data {
0115     unsigned int        timeout_ns; /* data timeout (in ns, max 80ms) */
0116     unsigned int        timeout_clks;   /* data timeout (in clocks) */
0117     unsigned int        blksz;      /* data block size */
0118     unsigned int        blocks;     /* number of blocks */
0119     unsigned int        blk_addr;   /* block address */
0120     int         error;      /* data error */
0121     unsigned int        flags;
0122 
0123 #define MMC_DATA_WRITE      BIT(8)
0124 #define MMC_DATA_READ       BIT(9)
0125 /* Extra flags used by CQE */
0126 #define MMC_DATA_QBR        BIT(10)     /* CQE queue barrier*/
0127 #define MMC_DATA_PRIO       BIT(11)     /* CQE high priority */
0128 #define MMC_DATA_REL_WR     BIT(12)     /* Reliable write */
0129 #define MMC_DATA_DAT_TAG    BIT(13)     /* Tag request */
0130 #define MMC_DATA_FORCED_PRG BIT(14)     /* Forced programming */
0131 
0132     unsigned int        bytes_xfered;
0133 
0134     struct mmc_command  *stop;      /* stop command */
0135     struct mmc_request  *mrq;       /* associated request */
0136 
0137     unsigned int        sg_len;     /* size of scatter list */
0138     int         sg_count;   /* mapped sg entries */
0139     struct scatterlist  *sg;        /* I/O scatter list */
0140     s32         host_cookie;    /* host private data */
0141 };
0142 
0143 struct mmc_host;
0144 struct mmc_request {
0145     struct mmc_command  *sbc;       /* SET_BLOCK_COUNT for multiblock */
0146     struct mmc_command  *cmd;
0147     struct mmc_data     *data;
0148     struct mmc_command  *stop;
0149 
0150     struct completion   completion;
0151     struct completion   cmd_completion;
0152     void            (*done)(struct mmc_request *);/* completion function */
0153     /*
0154      * Notify uppers layers (e.g. mmc block driver) that recovery is needed
0155      * due to an error associated with the mmc_request. Currently used only
0156      * by CQE.
0157      */
0158     void            (*recovery_notifier)(struct mmc_request *);
0159     struct mmc_host     *host;
0160 
0161     /* Allow other commands during this ongoing data transfer or busy wait */
0162     bool            cap_cmd_during_tfr;
0163 
0164     int         tag;
0165 
0166 #ifdef CONFIG_MMC_CRYPTO
0167     const struct bio_crypt_ctx *crypto_ctx;
0168     int         crypto_key_slot;
0169 #endif
0170 };
0171 
0172 struct mmc_card;
0173 
0174 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq);
0175 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd,
0176         int retries);
0177 
0178 int mmc_hw_reset(struct mmc_card *card);
0179 int mmc_sw_reset(struct mmc_card *card);
0180 void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card);
0181 
0182 #endif /* LINUX_MMC_CORE_H */