blob: ce9249852f266ff55088ffbc7da7ab81d89b773f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef MMC_QUEUE_H
3#define MMC_QUEUE_H
4
Ulf Hansson066185d2017-01-13 14:14:07 +01005#include <linux/types.h>
6#include <linux/blkdev.h>
Linus Walleij304419d2017-05-18 11:29:32 +02007#include <linux/blk-mq.h>
Ulf Hansson066185d2017-01-13 14:14:07 +01008#include <linux/mmc/core.h>
9#include <linux/mmc/host.h>
10
Adrian Hunter81196972017-11-29 15:41:03 +020011enum mmc_issued {
12 MMC_REQ_STARTED,
13 MMC_REQ_BUSY,
14 MMC_REQ_FAILED_TO_START,
15 MMC_REQ_FINISHED,
16};
17
18enum mmc_issue_type {
19 MMC_ISSUE_SYNC,
20 MMC_ISSUE_ASYNC,
21 MMC_ISSUE_MAX,
22};
23
Linus Walleij304419d2017-05-18 11:29:32 +020024static inline struct mmc_queue_req *req_to_mmc_queue_req(struct request *rq)
25{
26 return blk_mq_rq_to_pdu(rq);
27}
28
Linus Walleij67e69d52017-05-19 15:37:27 +020029struct mmc_queue_req;
30
31static inline struct request *mmc_queue_req_to_req(struct mmc_queue_req *mqr)
32{
33 return blk_mq_rq_from_pdu(mqr);
34}
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036struct task_struct;
Linus Walleij7db30282016-11-18 13:36:15 +010037struct mmc_blk_data;
Linus Walleij614f0382017-05-18 11:29:34 +020038struct mmc_blk_ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Per Forlin97868a22011-07-09 17:12:36 -040040struct mmc_blk_request {
41 struct mmc_request mrq;
42 struct mmc_command sbc;
43 struct mmc_command cmd;
44 struct mmc_command stop;
45 struct mmc_data data;
Adrian Hunterb8360a42015-05-07 13:10:24 +030046 int retune_retry_done;
Per Forlin97868a22011-07-09 17:12:36 -040047};
48
Linus Walleij02166a02017-05-19 15:37:28 +020049/**
50 * enum mmc_drv_op - enumerates the operations in the mmc_queue_req
51 * @MMC_DRV_OP_IOCTL: ioctl operation
Linus Walleij97548572017-09-20 10:02:00 +020052 * @MMC_DRV_OP_IOCTL_RPMB: RPMB-oriented ioctl operation
Linus Walleij0493f6f2017-05-19 15:37:30 +020053 * @MMC_DRV_OP_BOOT_WP: write protect boot partitions
Linus Walleij627c3cc2017-08-20 23:39:08 +020054 * @MMC_DRV_OP_GET_CARD_STATUS: get card status
55 * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card
Linus Walleij02166a02017-05-19 15:37:28 +020056 */
57enum mmc_drv_op {
58 MMC_DRV_OP_IOCTL,
Linus Walleij97548572017-09-20 10:02:00 +020059 MMC_DRV_OP_IOCTL_RPMB,
Linus Walleij0493f6f2017-05-19 15:37:30 +020060 MMC_DRV_OP_BOOT_WP,
Linus Walleij627c3cc2017-08-20 23:39:08 +020061 MMC_DRV_OP_GET_CARD_STATUS,
62 MMC_DRV_OP_GET_EXT_CSD,
Linus Walleij02166a02017-05-19 15:37:28 +020063};
64
Per Forlin97868a22011-07-09 17:12:36 -040065struct mmc_queue_req {
Per Forlin97868a22011-07-09 17:12:36 -040066 struct mmc_blk_request brq;
67 struct scatterlist *sg;
Linus Walleij74f5ba32017-02-01 13:47:55 +010068 struct mmc_async_req areq;
Linus Walleij02166a02017-05-19 15:37:28 +020069 enum mmc_drv_op drv_op;
Linus Walleij0493f6f2017-05-19 15:37:30 +020070 int drv_op_result;
Linus Walleij69f75992017-08-20 23:39:06 +020071 void *drv_op_data;
Linus Walleij3ecd8cf2017-05-18 11:29:35 +020072 unsigned int ioc_count;
Adrian Hunter81196972017-11-29 15:41:03 +020073 int retries;
Per Forlin97868a22011-07-09 17:12:36 -040074};
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076struct mmc_queue {
77 struct mmc_card *card;
Christoph Hellwig87598a22006-11-13 20:23:52 +010078 struct task_struct *thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 struct semaphore thread_sem;
Adrian Hunter81196972017-11-29 15:41:03 +020080 struct mmc_ctx ctx;
81 struct blk_mq_tag_set tag_set;
Linus Walleij9491be52017-02-01 13:47:56 +010082 bool suspended;
Adrian Huntere0097cf2016-11-29 12:09:10 +020083 bool asleep;
Linus Walleij7db30282016-11-18 13:36:15 +010084 struct mmc_blk_data *blkdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 struct request_queue *queue;
Linus Walleij304419d2017-05-18 11:29:32 +020086 /*
87 * FIXME: this counter is not a very reliable way of keeping
88 * track of how many requests that are ongoing. Switch to just
89 * letting the block core keep track of requests and per-request
90 * associated mmc_queue_req data.
91 */
Adrian Huntercdf8a6f2017-03-13 14:36:35 +020092 int qcnt;
Adrian Hunter81196972017-11-29 15:41:03 +020093
94 int in_flight[MMC_ISSUE_MAX];
95 bool rw_wait;
96 bool waiting;
97 wait_queue_head_t wait;
98 struct request *complete_req;
99 struct mutex complete_lock;
100 struct work_struct complete_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
102
Adrian Hunterd09408a2011-06-23 13:40:28 +0300103extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
104 const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern void mmc_cleanup_queue(struct mmc_queue *);
106extern void mmc_queue_suspend(struct mmc_queue *);
107extern void mmc_queue_resume(struct mmc_queue *);
Per Forlin97868a22011-07-09 17:12:36 -0400108extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
109 struct mmc_queue_req *);
Pierre Ossman98ccf142007-05-12 00:26:16 +0200110
Adrian Hunter81196972017-11-29 15:41:03 +0200111enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req);
112
113static inline int mmc_tot_in_flight(struct mmc_queue *mq)
114{
115 return mq->in_flight[MMC_ISSUE_SYNC] +
116 mq->in_flight[MMC_ISSUE_ASYNC];
117}
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#endif