blob: 547b457c4251f5e8be71e33e7e9980d281ba6dd9 [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
Linus Walleij304419d2017-05-18 11:29:32 +020011static inline struct mmc_queue_req *req_to_mmc_queue_req(struct request *rq)
12{
13 return blk_mq_rq_to_pdu(rq);
14}
15
Linus Walleij67e69d52017-05-19 15:37:27 +020016struct mmc_queue_req;
17
18static inline struct request *mmc_queue_req_to_req(struct mmc_queue_req *mqr)
19{
20 return blk_mq_rq_from_pdu(mqr);
21}
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023struct task_struct;
Linus Walleij7db30282016-11-18 13:36:15 +010024struct mmc_blk_data;
Linus Walleij614f0382017-05-18 11:29:34 +020025struct mmc_blk_ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Per Forlin97868a22011-07-09 17:12:36 -040027struct mmc_blk_request {
28 struct mmc_request mrq;
29 struct mmc_command sbc;
30 struct mmc_command cmd;
31 struct mmc_command stop;
32 struct mmc_data data;
Adrian Hunterb8360a42015-05-07 13:10:24 +030033 int retune_retry_done;
Per Forlin97868a22011-07-09 17:12:36 -040034};
35
Linus Walleij02166a02017-05-19 15:37:28 +020036/**
37 * enum mmc_drv_op - enumerates the operations in the mmc_queue_req
38 * @MMC_DRV_OP_IOCTL: ioctl operation
Linus Walleij97548572017-09-20 10:02:00 +020039 * @MMC_DRV_OP_IOCTL_RPMB: RPMB-oriented ioctl operation
Linus Walleij0493f6f2017-05-19 15:37:30 +020040 * @MMC_DRV_OP_BOOT_WP: write protect boot partitions
Linus Walleij627c3cc2017-08-20 23:39:08 +020041 * @MMC_DRV_OP_GET_CARD_STATUS: get card status
42 * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card
Linus Walleij02166a02017-05-19 15:37:28 +020043 */
44enum mmc_drv_op {
45 MMC_DRV_OP_IOCTL,
Linus Walleij97548572017-09-20 10:02:00 +020046 MMC_DRV_OP_IOCTL_RPMB,
Linus Walleij0493f6f2017-05-19 15:37:30 +020047 MMC_DRV_OP_BOOT_WP,
Linus Walleij627c3cc2017-08-20 23:39:08 +020048 MMC_DRV_OP_GET_CARD_STATUS,
49 MMC_DRV_OP_GET_EXT_CSD,
Linus Walleij02166a02017-05-19 15:37:28 +020050};
51
Per Forlin97868a22011-07-09 17:12:36 -040052struct mmc_queue_req {
Per Forlin97868a22011-07-09 17:12:36 -040053 struct mmc_blk_request brq;
54 struct scatterlist *sg;
Linus Walleij74f5ba32017-02-01 13:47:55 +010055 struct mmc_async_req areq;
Linus Walleij02166a02017-05-19 15:37:28 +020056 enum mmc_drv_op drv_op;
Linus Walleij0493f6f2017-05-19 15:37:30 +020057 int drv_op_result;
Linus Walleij69f75992017-08-20 23:39:06 +020058 void *drv_op_data;
Linus Walleij3ecd8cf2017-05-18 11:29:35 +020059 unsigned int ioc_count;
Per Forlin97868a22011-07-09 17:12:36 -040060};
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062struct mmc_queue {
63 struct mmc_card *card;
Christoph Hellwig87598a22006-11-13 20:23:52 +010064 struct task_struct *thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 struct semaphore thread_sem;
Linus Walleij9491be52017-02-01 13:47:56 +010066 bool suspended;
Adrian Huntere0097cf2016-11-29 12:09:10 +020067 bool asleep;
Linus Walleij7db30282016-11-18 13:36:15 +010068 struct mmc_blk_data *blkdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 struct request_queue *queue;
Linus Walleij304419d2017-05-18 11:29:32 +020070 /*
71 * FIXME: this counter is not a very reliable way of keeping
72 * track of how many requests that are ongoing. Switch to just
73 * letting the block core keep track of requests and per-request
74 * associated mmc_queue_req data.
75 */
Adrian Huntercdf8a6f2017-03-13 14:36:35 +020076 int qcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
Adrian Hunterd09408a2011-06-23 13:40:28 +030079extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
80 const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern void mmc_cleanup_queue(struct mmc_queue *);
82extern void mmc_queue_suspend(struct mmc_queue *);
83extern void mmc_queue_resume(struct mmc_queue *);
Per Forlin97868a22011-07-09 17:12:36 -040084extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
85 struct mmc_queue_req *);
Pierre Ossman98ccf142007-05-12 00:26:16 +020086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#endif