Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef MMC_QUEUE_H
0003 #define MMC_QUEUE_H
0004 
0005 #include <linux/types.h>
0006 #include <linux/blkdev.h>
0007 #include <linux/blk-mq.h>
0008 #include <linux/mmc/core.h>
0009 #include <linux/mmc/host.h>
0010 
0011 enum mmc_issued {
0012     MMC_REQ_STARTED,
0013     MMC_REQ_BUSY,
0014     MMC_REQ_FAILED_TO_START,
0015     MMC_REQ_FINISHED,
0016 };
0017 
0018 enum mmc_issue_type {
0019     MMC_ISSUE_SYNC,
0020     MMC_ISSUE_DCMD,
0021     MMC_ISSUE_ASYNC,
0022     MMC_ISSUE_MAX,
0023 };
0024 
0025 static inline struct mmc_queue_req *req_to_mmc_queue_req(struct request *rq)
0026 {
0027     return blk_mq_rq_to_pdu(rq);
0028 }
0029 
0030 struct mmc_queue_req;
0031 
0032 static inline struct request *mmc_queue_req_to_req(struct mmc_queue_req *mqr)
0033 {
0034     return blk_mq_rq_from_pdu(mqr);
0035 }
0036 
0037 struct mmc_blk_data;
0038 struct mmc_blk_ioc_data;
0039 
0040 struct mmc_blk_request {
0041     struct mmc_request  mrq;
0042     struct mmc_command  sbc;
0043     struct mmc_command  cmd;
0044     struct mmc_command  stop;
0045     struct mmc_data     data;
0046 };
0047 
0048 /**
0049  * enum mmc_drv_op - enumerates the operations in the mmc_queue_req
0050  * @MMC_DRV_OP_IOCTL: ioctl operation
0051  * @MMC_DRV_OP_IOCTL_RPMB: RPMB-oriented ioctl operation
0052  * @MMC_DRV_OP_BOOT_WP: write protect boot partitions
0053  * @MMC_DRV_OP_GET_CARD_STATUS: get card status
0054  * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card
0055  */
0056 enum mmc_drv_op {
0057     MMC_DRV_OP_IOCTL,
0058     MMC_DRV_OP_IOCTL_RPMB,
0059     MMC_DRV_OP_BOOT_WP,
0060     MMC_DRV_OP_GET_CARD_STATUS,
0061     MMC_DRV_OP_GET_EXT_CSD,
0062 };
0063 
0064 struct mmc_queue_req {
0065     struct mmc_blk_request  brq;
0066     struct scatterlist  *sg;
0067     enum mmc_drv_op     drv_op;
0068     int         drv_op_result;
0069     void            *drv_op_data;
0070     unsigned int        ioc_count;
0071     int         retries;
0072 };
0073 
0074 struct mmc_queue {
0075     struct mmc_card     *card;
0076     struct mmc_ctx      ctx;
0077     struct blk_mq_tag_set   tag_set;
0078     struct mmc_blk_data *blkdata;
0079     struct request_queue    *queue;
0080     spinlock_t      lock;
0081     int         in_flight[MMC_ISSUE_MAX];
0082     unsigned int        cqe_busy;
0083 #define MMC_CQE_DCMD_BUSY   BIT(0)
0084     bool            busy;
0085     bool            recovery_needed;
0086     bool            in_recovery;
0087     bool            rw_wait;
0088     bool            waiting;
0089     struct work_struct  recovery_work;
0090     wait_queue_head_t   wait;
0091     struct request      *recovery_req;
0092     struct request      *complete_req;
0093     struct mutex        complete_lock;
0094     struct work_struct  complete_work;
0095 };
0096 
0097 struct gendisk *mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card);
0098 extern void mmc_cleanup_queue(struct mmc_queue *);
0099 extern void mmc_queue_suspend(struct mmc_queue *);
0100 extern void mmc_queue_resume(struct mmc_queue *);
0101 extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
0102                      struct mmc_queue_req *);
0103 
0104 void mmc_cqe_check_busy(struct mmc_queue *mq);
0105 void mmc_cqe_recovery_notifier(struct mmc_request *mrq);
0106 
0107 enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req);
0108 
0109 static inline int mmc_tot_in_flight(struct mmc_queue *mq)
0110 {
0111     return mq->in_flight[MMC_ISSUE_SYNC] +
0112            mq->in_flight[MMC_ISSUE_DCMD] +
0113            mq->in_flight[MMC_ISSUE_ASYNC];
0114 }
0115 
0116 static inline int mmc_cqe_qcnt(struct mmc_queue *mq)
0117 {
0118     return mq->in_flight[MMC_ISSUE_DCMD] +
0119            mq->in_flight[MMC_ISSUE_ASYNC];
0120 }
0121 
0122 #endif