queue.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. enum mmc_issued {
  10. MMC_REQ_STARTED,
  11. MMC_REQ_BUSY,
  12. MMC_REQ_FAILED_TO_START,
  13. MMC_REQ_FINISHED,
  14. };
  15. enum mmc_issue_type {
  16. MMC_ISSUE_SYNC,
  17. MMC_ISSUE_DCMD,
  18. MMC_ISSUE_ASYNC,
  19. MMC_ISSUE_MAX,
  20. };
  21. static inline struct mmc_queue_req *req_to_mmc_queue_req(struct request *rq)
  22. {
  23. return blk_mq_rq_to_pdu(rq);
  24. }
  25. struct mmc_queue_req;
  26. static inline struct request *mmc_queue_req_to_req(struct mmc_queue_req *mqr)
  27. {
  28. return blk_mq_rq_from_pdu(mqr);
  29. }
  30. struct task_struct;
  31. struct mmc_blk_data;
  32. struct mmc_blk_ioc_data;
  33. struct mmc_blk_request {
  34. struct mmc_request mrq;
  35. struct mmc_command sbc;
  36. struct mmc_command cmd;
  37. struct mmc_command stop;
  38. struct mmc_data data;
  39. int retune_retry_done;
  40. };
  41. /**
  42. * enum mmc_drv_op - enumerates the operations in the mmc_queue_req
  43. * @MMC_DRV_OP_IOCTL: ioctl operation
  44. * @MMC_DRV_OP_IOCTL_RPMB: RPMB-oriented ioctl operation
  45. * @MMC_DRV_OP_BOOT_WP: write protect boot partitions
  46. * @MMC_DRV_OP_GET_CARD_STATUS: get card status
  47. * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card
  48. */
  49. enum mmc_drv_op {
  50. MMC_DRV_OP_IOCTL,
  51. MMC_DRV_OP_IOCTL_RPMB,
  52. MMC_DRV_OP_BOOT_WP,
  53. MMC_DRV_OP_GET_CARD_STATUS,
  54. MMC_DRV_OP_GET_EXT_CSD,
  55. };
  56. struct mmc_queue_req {
  57. struct mmc_blk_request brq;
  58. struct scatterlist *sg;
  59. struct mmc_async_req areq;
  60. enum mmc_drv_op drv_op;
  61. int drv_op_result;
  62. void *drv_op_data;
  63. unsigned int ioc_count;
  64. int retries;
  65. };
  66. struct mmc_queue {
  67. struct mmc_card *card;
  68. struct task_struct *thread;
  69. struct semaphore thread_sem;
  70. struct mmc_ctx ctx;
  71. struct blk_mq_tag_set tag_set;
  72. bool suspended;
  73. bool asleep;
  74. struct mmc_blk_data *blkdata;
  75. struct request_queue *queue;
  76. /*
  77. * FIXME: this counter is not a very reliable way of keeping
  78. * track of how many requests that are ongoing. Switch to just
  79. * letting the block core keep track of requests and per-request
  80. * associated mmc_queue_req data.
  81. */
  82. int qcnt;
  83. int in_flight[MMC_ISSUE_MAX];
  84. unsigned int cqe_busy;
  85. #define MMC_CQE_DCMD_BUSY BIT(0)
  86. #define MMC_CQE_QUEUE_FULL BIT(1)
  87. bool use_cqe;
  88. bool recovery_needed;
  89. bool in_recovery;
  90. bool rw_wait;
  91. bool waiting;
  92. struct work_struct recovery_work;
  93. wait_queue_head_t wait;
  94. struct request *complete_req;
  95. struct mutex complete_lock;
  96. struct work_struct complete_work;
  97. };
  98. extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
  99. const char *);
  100. extern void mmc_cleanup_queue(struct mmc_queue *);
  101. extern void mmc_queue_suspend(struct mmc_queue *);
  102. extern void mmc_queue_resume(struct mmc_queue *);
  103. extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
  104. struct mmc_queue_req *);
  105. void mmc_cqe_check_busy(struct mmc_queue *mq);
  106. void mmc_cqe_recovery_notifier(struct mmc_request *mrq);
  107. enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req);
  108. static inline int mmc_tot_in_flight(struct mmc_queue *mq)
  109. {
  110. return mq->in_flight[MMC_ISSUE_SYNC] +
  111. mq->in_flight[MMC_ISSUE_DCMD] +
  112. mq->in_flight[MMC_ISSUE_ASYNC];
  113. }
  114. static inline int mmc_cqe_qcnt(struct mmc_queue *mq)
  115. {
  116. return mq->in_flight[MMC_ISSUE_DCMD] +
  117. mq->in_flight[MMC_ISSUE_ASYNC];
  118. }
  119. #endif