core.h 5.9 KB

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