queue.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 mmc_blk_data;
  31. struct mmc_blk_ioc_data;
  32. struct mmc_blk_request {
  33. struct mmc_request mrq;
  34. struct mmc_command sbc;
  35. struct mmc_command cmd;
  36. struct mmc_command stop;
  37. struct mmc_data data;
  38. };
  39. /**
  40. * enum mmc_drv_op - enumerates the operations in the mmc_queue_req
  41. * @MMC_DRV_OP_IOCTL: ioctl operation
  42. * @MMC_DRV_OP_IOCTL_RPMB: RPMB-oriented ioctl operation
  43. * @MMC_DRV_OP_BOOT_WP: write protect boot partitions
  44. * @MMC_DRV_OP_GET_CARD_STATUS: get card status
  45. * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card
  46. */
  47. enum mmc_drv_op {
  48. MMC_DRV_OP_IOCTL,
  49. MMC_DRV_OP_IOCTL_RPMB,
  50. MMC_DRV_OP_BOOT_WP,
  51. MMC_DRV_OP_GET_CARD_STATUS,
  52. MMC_DRV_OP_GET_EXT_CSD,
  53. };
  54. struct mmc_queue_req {
  55. struct mmc_blk_request brq;
  56. struct scatterlist *sg;
  57. enum mmc_drv_op drv_op;
  58. int drv_op_result;
  59. void *drv_op_data;
  60. unsigned int ioc_count;
  61. int retries;
  62. };
  63. struct mmc_queue {
  64. struct mmc_card *card;
  65. struct mmc_ctx ctx;
  66. struct blk_mq_tag_set tag_set;
  67. struct mmc_blk_data *blkdata;
  68. struct request_queue *queue;
  69. int in_flight[MMC_ISSUE_MAX];
  70. unsigned int cqe_busy;
  71. #define MMC_CQE_DCMD_BUSY BIT(0)
  72. #define MMC_CQE_QUEUE_FULL BIT(1)
  73. bool busy;
  74. bool use_cqe;
  75. bool recovery_needed;
  76. bool in_recovery;
  77. bool rw_wait;
  78. bool waiting;
  79. struct work_struct recovery_work;
  80. wait_queue_head_t wait;
  81. struct request *recovery_req;
  82. struct request *complete_req;
  83. struct mutex complete_lock;
  84. struct work_struct complete_work;
  85. };
  86. extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
  87. const char *);
  88. extern void mmc_cleanup_queue(struct mmc_queue *);
  89. extern void mmc_queue_suspend(struct mmc_queue *);
  90. extern void mmc_queue_resume(struct mmc_queue *);
  91. extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
  92. struct mmc_queue_req *);
  93. void mmc_cqe_check_busy(struct mmc_queue *mq);
  94. void mmc_cqe_recovery_notifier(struct mmc_request *mrq);
  95. enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req);
  96. static inline int mmc_tot_in_flight(struct mmc_queue *mq)
  97. {
  98. return mq->in_flight[MMC_ISSUE_SYNC] +
  99. mq->in_flight[MMC_ISSUE_DCMD] +
  100. mq->in_flight[MMC_ISSUE_ASYNC];
  101. }
  102. static inline int mmc_cqe_qcnt(struct mmc_queue *mq)
  103. {
  104. return mq->in_flight[MMC_ISSUE_DCMD] +
  105. mq->in_flight[MMC_ISSUE_ASYNC];
  106. }
  107. #endif