queue.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef MMC_QUEUE_H
  3. #define MMC_QUEUE_H
  4. #include <linux/types.h>
  5. #include <linux/blkdev.h>
  6. #include <linux/blk-mq.h>
  7. #include <linux/mmc/core.h>
  8. #include <linux/mmc/host.h>
  9. #ifdef CONFIG_MTK_EMMC_HW_CQ
  10. static inline bool mmc_req_is_special(struct request *req)
  11. {
  12. return req &&
  13. (req_op(req) == REQ_OP_FLUSH ||
  14. req_op(req) == REQ_OP_DISCARD ||
  15. req_op(req) == REQ_OP_SECURE_ERASE);
  16. }
  17. #endif
  18. static inline struct mmc_queue_req *req_to_mmc_queue_req(struct request *rq)
  19. {
  20. return blk_mq_rq_to_pdu(rq);
  21. }
  22. struct mmc_queue_req;
  23. static inline struct request *mmc_queue_req_to_req(struct mmc_queue_req *mqr)
  24. {
  25. return blk_mq_rq_from_pdu(mqr);
  26. }
  27. struct task_struct;
  28. struct mmc_blk_data;
  29. struct mmc_blk_ioc_data;
  30. struct mmc_blk_request {
  31. #ifdef CONFIG_MTK_EMMC_CQ_SUPPORT
  32. struct mmc_request mrq_que;
  33. #endif
  34. struct mmc_request mrq;
  35. struct mmc_command sbc;
  36. #ifdef CONFIG_MTK_EMMC_CQ_SUPPORT
  37. struct mmc_command que;
  38. #endif
  39. struct mmc_command cmd;
  40. struct mmc_command stop;
  41. struct mmc_data data;
  42. int retune_retry_done;
  43. };
  44. /**
  45. * enum mmc_drv_op - enumerates the operations in the mmc_queue_req
  46. * @MMC_DRV_OP_IOCTL: ioctl operation
  47. * @MMC_DRV_OP_IOCTL_RPMB: RPMB-oriented ioctl operation
  48. * @MMC_DRV_OP_BOOT_WP: write protect boot partitions
  49. * @MMC_DRV_OP_GET_CARD_STATUS: get card status
  50. * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card
  51. */
  52. enum mmc_drv_op {
  53. MMC_DRV_OP_IOCTL,
  54. MMC_DRV_OP_IOCTL_RPMB,
  55. MMC_DRV_OP_BOOT_WP,
  56. MMC_DRV_OP_GET_CARD_STATUS,
  57. MMC_DRV_OP_GET_EXT_CSD,
  58. };
  59. struct mmc_queue_req {
  60. #if defined(CONFIG_MTK_EMMC_CQ_SUPPORT) || defined(CONFIG_MTK_EMMC_HW_CQ)
  61. struct request *req;
  62. #endif
  63. struct mmc_blk_request brq;
  64. struct scatterlist *sg;
  65. struct mmc_async_req areq;
  66. enum mmc_drv_op drv_op;
  67. int drv_op_result;
  68. void *drv_op_data;
  69. unsigned int ioc_count;
  70. #ifdef CONFIG_MTK_EMMC_CQ_SUPPORT
  71. atomic_t index;
  72. #endif
  73. #ifdef CONFIG_MTK_EMMC_HW_CQ
  74. struct mmc_cmdq_req cmdq_req;
  75. #endif
  76. };
  77. struct mmc_queue {
  78. struct mmc_card *card;
  79. struct task_struct *thread;
  80. struct semaphore thread_sem;
  81. #ifdef CONFIG_MTK_EMMC_HW_CQ
  82. unsigned long flags;
  83. #define MMC_QUEUE_SUSPENDED (1 << 0)
  84. #else
  85. bool suspended;
  86. #endif
  87. bool asleep;
  88. struct mmc_blk_data *blkdata;
  89. struct request_queue *queue;
  90. #ifdef CONFIG_MTK_EMMC_CQ_SUPPORT
  91. struct mmc_queue_req mqrq[EMMC_MAX_QUEUE_DEPTH];
  92. #endif
  93. /*
  94. * FIXME: this counter is not a very reliable way of keeping
  95. * track of how many requests that are ongoing. Switch to just
  96. * letting the block core keep track of requests and per-request
  97. * associated mmc_queue_req data.
  98. */
  99. atomic_t qcnt;
  100. #ifdef CONFIG_MTK_EMMC_HW_CQ
  101. struct mmc_queue_req *mqrq_cmdq;
  102. struct work_struct cmdq_err_work;
  103. struct completion cmdq_pending_req_done;
  104. struct completion cmdq_shutdown_complete;
  105. struct request *cmdq_req_peeked;
  106. int (*err_check_fn)(struct mmc_card *card, struct mmc_async_req *areq);
  107. void (*cmdq_shutdown)(struct mmc_queue *mq);
  108. int (*issue_fn)(struct mmc_queue *mq, struct request *req);
  109. int (*cmdq_issue_fn)(struct mmc_queue *mq,
  110. struct request *req);
  111. void (*cmdq_complete_fn)(struct request *req);
  112. void (*cmdq_error_fn)(struct mmc_queue *mq);
  113. enum blk_eh_timer_return (*cmdq_req_timed_out)(struct request *req);
  114. #endif
  115. };
  116. #if defined(CONFIG_MTK_EMMC_CQ_SUPPORT) || defined(CONFIG_MTK_EMMC_HW_CQ)
  117. #define IS_RT_CLASS_REQ(x) \
  118. (IOPRIO_PRIO_CLASS(req_get_ioprio(x)) == IOPRIO_CLASS_RT)
  119. #endif
  120. extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
  121. const char *, int);
  122. extern void mmc_cleanup_queue(struct mmc_queue *);
  123. #ifdef CONFIG_MTK_EMMC_HW_CQ
  124. extern int mmc_queue_suspend(struct mmc_queue *mq, int wait);
  125. #else
  126. extern void mmc_queue_suspend(struct mmc_queue *);
  127. #endif
  128. extern void mmc_queue_resume(struct mmc_queue *);
  129. #ifdef CONFIG_MTK_EMMC_HW_CQ
  130. extern unsigned int mmc_cmdq_queue_map_sg(struct mmc_queue *mq,
  131. struct mmc_queue_req *mqrq);
  132. #endif
  133. extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
  134. struct mmc_queue_req *);
  135. #ifdef CONFIG_MTK_EMMC_CQ_SUPPORT
  136. extern void mmc_wait_cmdq_empty(struct mmc_host *host);
  137. extern bool mmc_blk_part_cmdq_en(struct mmc_queue *mq);
  138. #endif
  139. #ifdef CONFIG_MTK_EMMC_HW_CQ
  140. extern int mmc_cmdq_init(struct mmc_queue *mq, struct mmc_card *card);
  141. extern void mmc_cmdq_clean(struct mmc_queue *mq, struct mmc_card *card);
  142. #endif
  143. #endif