core.h 6.0 KB

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