Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2003 Russell King, All Rights Reserved. |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 3 | * Copyright 2006-2007 Pierre Ossman |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/blkdev.h> |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 13 | #include <linux/freezer.h> |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 14 | #include <linux/kthread.h> |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 15 | #include <linux/scatterlist.h> |
Santosh Shilimkar | 8e0cb8a | 2013-07-29 14:20:15 +0100 | [diff] [blame] | 16 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include <linux/mmc/card.h> |
| 19 | #include <linux/mmc/host.h> |
Linus Walleij | 29eb7bd | 2016-09-20 11:34:38 +0200 | [diff] [blame] | 20 | |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 21 | #include "queue.h" |
Linus Walleij | 29eb7bd | 2016-09-20 11:34:38 +0200 | [diff] [blame] | 22 | #include "block.h" |
Ulf Hansson | 55244c5 | 2017-01-13 14:14:08 +0100 | [diff] [blame] | 23 | #include "core.h" |
Ulf Hansson | 4facdde | 2017-01-13 14:14:14 +0100 | [diff] [blame] | 24 | #include "card.h" |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 25 | #include "host.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | /* |
Pierre Ossman | 9c9f2d6 | 2007-05-16 17:29:21 +0200 | [diff] [blame] | 28 | * Prepare a MMC request. This just filters out odd stuff. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | static int mmc_prep_request(struct request_queue *q, struct request *req) |
| 31 | { |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 32 | struct mmc_queue *mq = q->queuedata; |
| 33 | |
Linus Walleij | 14f4ca7 | 2017-09-20 10:02:01 +0200 | [diff] [blame] | 34 | if (mq && mmc_card_removed(mq->card)) |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 35 | return BLKPREP_KILL; |
| 36 | |
Christoph Hellwig | e806402 | 2016-10-20 15:12:13 +0200 | [diff] [blame] | 37 | req->rq_flags |= RQF_DONTPREP; |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 38 | req_to_mmc_queue_req(req)->retries = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Pierre Ossman | 9c9f2d6 | 2007-05-16 17:29:21 +0200 | [diff] [blame] | 40 | return BLKPREP_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 43 | static inline bool mmc_cqe_dcmd_busy(struct mmc_queue *mq) |
| 44 | { |
| 45 | /* Allow only 1 DCMD at a time */ |
| 46 | return mq->in_flight[MMC_ISSUE_DCMD]; |
| 47 | } |
| 48 | |
| 49 | void mmc_cqe_check_busy(struct mmc_queue *mq) |
| 50 | { |
| 51 | if ((mq->cqe_busy & MMC_CQE_DCMD_BUSY) && !mmc_cqe_dcmd_busy(mq)) |
| 52 | mq->cqe_busy &= ~MMC_CQE_DCMD_BUSY; |
| 53 | |
| 54 | mq->cqe_busy &= ~MMC_CQE_QUEUE_FULL; |
| 55 | } |
| 56 | |
| 57 | static inline bool mmc_cqe_can_dcmd(struct mmc_host *host) |
| 58 | { |
| 59 | return host->caps2 & MMC_CAP2_CQE_DCMD; |
| 60 | } |
| 61 | |
| 62 | enum mmc_issue_type mmc_cqe_issue_type(struct mmc_host *host, |
| 63 | struct request *req) |
| 64 | { |
| 65 | switch (req_op(req)) { |
| 66 | case REQ_OP_DRV_IN: |
| 67 | case REQ_OP_DRV_OUT: |
| 68 | case REQ_OP_DISCARD: |
| 69 | case REQ_OP_SECURE_ERASE: |
| 70 | return MMC_ISSUE_SYNC; |
| 71 | case REQ_OP_FLUSH: |
| 72 | return mmc_cqe_can_dcmd(host) ? MMC_ISSUE_DCMD : MMC_ISSUE_SYNC; |
| 73 | default: |
| 74 | return MMC_ISSUE_ASYNC; |
| 75 | } |
| 76 | } |
| 77 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 78 | enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req) |
| 79 | { |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 80 | struct mmc_host *host = mq->card->host; |
| 81 | |
| 82 | if (mq->use_cqe) |
| 83 | return mmc_cqe_issue_type(host, req); |
| 84 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 85 | if (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE) |
| 86 | return MMC_ISSUE_ASYNC; |
| 87 | |
| 88 | return MMC_ISSUE_SYNC; |
| 89 | } |
| 90 | |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 91 | static void __mmc_cqe_recovery_notifier(struct mmc_queue *mq) |
| 92 | { |
| 93 | if (!mq->recovery_needed) { |
| 94 | mq->recovery_needed = true; |
| 95 | schedule_work(&mq->recovery_work); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | void mmc_cqe_recovery_notifier(struct mmc_request *mrq) |
| 100 | { |
| 101 | struct mmc_queue_req *mqrq = container_of(mrq, struct mmc_queue_req, |
| 102 | brq.mrq); |
| 103 | struct request *req = mmc_queue_req_to_req(mqrq); |
| 104 | struct request_queue *q = req->q; |
| 105 | struct mmc_queue *mq = q->queuedata; |
| 106 | unsigned long flags; |
| 107 | |
| 108 | spin_lock_irqsave(q->queue_lock, flags); |
| 109 | __mmc_cqe_recovery_notifier(mq); |
| 110 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 111 | } |
| 112 | |
| 113 | static enum blk_eh_timer_return mmc_cqe_timed_out(struct request *req) |
| 114 | { |
| 115 | struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); |
| 116 | struct mmc_request *mrq = &mqrq->brq.mrq; |
| 117 | struct mmc_queue *mq = req->q->queuedata; |
| 118 | struct mmc_host *host = mq->card->host; |
| 119 | enum mmc_issue_type issue_type = mmc_issue_type(mq, req); |
| 120 | bool recovery_needed = false; |
| 121 | |
| 122 | switch (issue_type) { |
| 123 | case MMC_ISSUE_ASYNC: |
| 124 | case MMC_ISSUE_DCMD: |
| 125 | if (host->cqe_ops->cqe_timeout(host, mrq, &recovery_needed)) { |
| 126 | if (recovery_needed) |
| 127 | __mmc_cqe_recovery_notifier(mq); |
| 128 | return BLK_EH_RESET_TIMER; |
| 129 | } |
| 130 | /* No timeout */ |
| 131 | return BLK_EH_HANDLED; |
| 132 | default: |
| 133 | /* Timeout is handled by mmc core */ |
| 134 | return BLK_EH_RESET_TIMER; |
| 135 | } |
| 136 | } |
| 137 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 138 | static enum blk_eh_timer_return mmc_mq_timed_out(struct request *req, |
| 139 | bool reserved) |
| 140 | { |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 141 | struct request_queue *q = req->q; |
| 142 | struct mmc_queue *mq = q->queuedata; |
| 143 | unsigned long flags; |
| 144 | int ret; |
| 145 | |
| 146 | spin_lock_irqsave(q->queue_lock, flags); |
| 147 | |
| 148 | if (mq->recovery_needed || !mq->use_cqe) |
| 149 | ret = BLK_EH_RESET_TIMER; |
| 150 | else |
| 151 | ret = mmc_cqe_timed_out(req); |
| 152 | |
| 153 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 154 | |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | static void mmc_mq_recovery_handler(struct work_struct *work) |
| 159 | { |
| 160 | struct mmc_queue *mq = container_of(work, struct mmc_queue, |
| 161 | recovery_work); |
| 162 | struct request_queue *q = mq->queue; |
| 163 | |
| 164 | mmc_get_card(mq->card, &mq->ctx); |
| 165 | |
| 166 | mq->in_recovery = true; |
| 167 | |
Adrian Hunter | 10f21df4 | 2017-11-29 15:41:07 +0200 | [diff] [blame^] | 168 | if (mq->use_cqe) |
| 169 | mmc_blk_cqe_recovery(mq); |
| 170 | else |
| 171 | mmc_blk_mq_recovery(mq); |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 172 | |
| 173 | mq->in_recovery = false; |
| 174 | |
| 175 | spin_lock_irq(q->queue_lock); |
| 176 | mq->recovery_needed = false; |
| 177 | spin_unlock_irq(q->queue_lock); |
| 178 | |
| 179 | mmc_put_card(mq->card, &mq->ctx); |
| 180 | |
| 181 | blk_mq_run_hw_queues(q, true); |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | static int mmc_queue_thread(void *d) |
| 185 | { |
| 186 | struct mmc_queue *mq = d; |
| 187 | struct request_queue *q = mq->queue; |
Adrian Hunter | e0097cf | 2016-11-29 12:09:10 +0200 | [diff] [blame] | 188 | struct mmc_context_info *cntx = &mq->card->host->context_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 190 | current->flags |= PF_MEMALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | down(&mq->thread_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | do { |
Adrian Hunter | cdf8a6f | 2017-03-13 14:36:35 +0200 | [diff] [blame] | 194 | struct request *req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | spin_lock_irq(q->queue_lock); |
| 197 | set_current_state(TASK_INTERRUPTIBLE); |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 198 | req = blk_fetch_request(q); |
Adrian Hunter | e0097cf | 2016-11-29 12:09:10 +0200 | [diff] [blame] | 199 | mq->asleep = false; |
| 200 | cntx->is_waiting_last_req = false; |
| 201 | cntx->is_new_req = false; |
| 202 | if (!req) { |
| 203 | /* |
| 204 | * Dispatch queue is empty so set flags for |
| 205 | * mmc_request_fn() to wake us up. |
| 206 | */ |
Adrian Hunter | cdf8a6f | 2017-03-13 14:36:35 +0200 | [diff] [blame] | 207 | if (mq->qcnt) |
Adrian Hunter | e0097cf | 2016-11-29 12:09:10 +0200 | [diff] [blame] | 208 | cntx->is_waiting_last_req = true; |
| 209 | else |
| 210 | mq->asleep = true; |
| 211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | spin_unlock_irq(q->queue_lock); |
| 213 | |
Adrian Hunter | cdf8a6f | 2017-03-13 14:36:35 +0200 | [diff] [blame] | 214 | if (req || mq->qcnt) { |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 215 | set_current_state(TASK_RUNNING); |
Linus Walleij | 29eb7bd | 2016-09-20 11:34:38 +0200 | [diff] [blame] | 216 | mmc_blk_issue_rq(mq, req); |
Rabin Vincent | a8c27c0 | 2015-06-14 19:26:11 +0200 | [diff] [blame] | 217 | cond_resched(); |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 218 | } else { |
Vitaly Wool | 7b30d28 | 2006-12-07 20:08:02 +0100 | [diff] [blame] | 219 | if (kthread_should_stop()) { |
| 220 | set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | break; |
Vitaly Wool | 7b30d28 | 2006-12-07 20:08:02 +0100 | [diff] [blame] | 222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | up(&mq->thread_sem); |
| 224 | schedule(); |
| 225 | down(&mq->thread_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } while (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | up(&mq->thread_sem); |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Generic MMC request handler. This is called for any queue on a |
| 235 | * particular host. When the host is not busy, we look for a request |
| 236 | * on any queue on this host, and attempt to issue it. This may |
| 237 | * not be the queue we were asked to process. |
| 238 | */ |
Venkatraman S | 1b50f5f | 2012-04-13 17:54:11 +0530 | [diff] [blame] | 239 | static void mmc_request_fn(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
| 241 | struct mmc_queue *mq = q->queuedata; |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 242 | struct request *req; |
Konstantin Dorfman | 2220eed | 2013-01-14 14:28:17 -0500 | [diff] [blame] | 243 | struct mmc_context_info *cntx; |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 244 | |
| 245 | if (!mq) { |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 246 | while ((req = blk_fetch_request(q)) != NULL) { |
Christoph Hellwig | e806402 | 2016-10-20 15:12:13 +0200 | [diff] [blame] | 247 | req->rq_flags |= RQF_QUIET; |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 248 | __blk_end_request_all(req, BLK_STS_IOERR); |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 249 | } |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 250 | return; |
| 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Konstantin Dorfman | 2220eed | 2013-01-14 14:28:17 -0500 | [diff] [blame] | 253 | cntx = &mq->card->host->context_info; |
Adrian Hunter | e0097cf | 2016-11-29 12:09:10 +0200 | [diff] [blame] | 254 | |
| 255 | if (cntx->is_waiting_last_req) { |
| 256 | cntx->is_new_req = true; |
| 257 | wake_up_interruptible(&cntx->wait); |
| 258 | } |
| 259 | |
| 260 | if (mq->asleep) |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 261 | wake_up_process(mq->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 264 | static struct scatterlist *mmc_alloc_sg(int sg_len, gfp_t gfp) |
Per Forlin | 97868a2 | 2011-07-09 17:12:36 -0400 | [diff] [blame] | 265 | { |
| 266 | struct scatterlist *sg; |
| 267 | |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 268 | sg = kmalloc_array(sg_len, sizeof(*sg), gfp); |
Adrian Hunter | 7b410d0 | 2017-03-13 14:36:36 +0200 | [diff] [blame] | 269 | if (sg) |
Per Forlin | 97868a2 | 2011-07-09 17:12:36 -0400 | [diff] [blame] | 270 | sg_init_table(sg, sg_len); |
Per Forlin | 97868a2 | 2011-07-09 17:12:36 -0400 | [diff] [blame] | 271 | |
| 272 | return sg; |
| 273 | } |
| 274 | |
Adrian Hunter | e056a1b | 2011-06-28 17:16:02 +0300 | [diff] [blame] | 275 | static void mmc_queue_setup_discard(struct request_queue *q, |
| 276 | struct mmc_card *card) |
| 277 | { |
| 278 | unsigned max_discard; |
| 279 | |
| 280 | max_discard = mmc_calc_max_discard(card); |
| 281 | if (!max_discard) |
| 282 | return; |
| 283 | |
| 284 | queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q); |
Jens Axboe | 2bb4cd5 | 2015-07-14 08:15:12 -0600 | [diff] [blame] | 285 | blk_queue_max_discard_sectors(q, max_discard); |
Adrian Hunter | e056a1b | 2011-06-28 17:16:02 +0300 | [diff] [blame] | 286 | q->limits.discard_granularity = card->pref_erase << 9; |
| 287 | /* granularity must not be greater than max. discard */ |
| 288 | if (card->pref_erase > max_discard) |
| 289 | q->limits.discard_granularity = 0; |
Maya Erez | 775a936 | 2013-04-18 15:41:55 +0300 | [diff] [blame] | 290 | if (mmc_can_secure_erase_trim(card)) |
Christoph Hellwig | 288dab8 | 2016-06-09 16:00:36 +0200 | [diff] [blame] | 291 | queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q); |
Adrian Hunter | e056a1b | 2011-06-28 17:16:02 +0300 | [diff] [blame] | 292 | } |
| 293 | |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 294 | /** |
| 295 | * mmc_init_request() - initialize the MMC-specific per-request data |
| 296 | * @q: the request queue |
| 297 | * @req: the request |
| 298 | * @gfp: memory allocation policy |
| 299 | */ |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 300 | static int __mmc_init_request(struct mmc_queue *mq, struct request *req, |
| 301 | gfp_t gfp) |
Adrian Hunter | f2b8b52 | 2016-11-29 12:09:12 +0200 | [diff] [blame] | 302 | { |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 303 | struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req); |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 304 | struct mmc_card *card = mq->card; |
| 305 | struct mmc_host *host = card->host; |
Adrian Hunter | c853982 | 2016-11-29 12:09:11 +0200 | [diff] [blame] | 306 | |
Linus Walleij | de3ee99 | 2017-09-20 10:56:14 +0200 | [diff] [blame] | 307 | mq_rq->sg = mmc_alloc_sg(host->max_segs, gfp); |
| 308 | if (!mq_rq->sg) |
| 309 | return -ENOMEM; |
Adrian Hunter | 64e29e42 | 2016-11-29 12:09:13 +0200 | [diff] [blame] | 310 | |
Adrian Hunter | c5bda0c | 2016-11-29 12:09:15 +0200 | [diff] [blame] | 311 | return 0; |
| 312 | } |
Adrian Hunter | 64e29e42 | 2016-11-29 12:09:13 +0200 | [diff] [blame] | 313 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 314 | static int mmc_init_request(struct request_queue *q, struct request *req, |
| 315 | gfp_t gfp) |
| 316 | { |
| 317 | return __mmc_init_request(q->queuedata, req, gfp); |
| 318 | } |
| 319 | |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 320 | static void mmc_exit_request(struct request_queue *q, struct request *req) |
Adrian Hunter | c5bda0c | 2016-11-29 12:09:15 +0200 | [diff] [blame] | 321 | { |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 322 | struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req); |
Adrian Hunter | 64e29e42 | 2016-11-29 12:09:13 +0200 | [diff] [blame] | 323 | |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 324 | kfree(mq_rq->sg); |
| 325 | mq_rq->sg = NULL; |
Adrian Hunter | c09949c | 2016-11-29 12:09:14 +0200 | [diff] [blame] | 326 | } |
| 327 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 328 | static int mmc_mq_init_request(struct blk_mq_tag_set *set, struct request *req, |
| 329 | unsigned int hctx_idx, unsigned int numa_node) |
| 330 | { |
| 331 | return __mmc_init_request(set->driver_data, req, GFP_KERNEL); |
| 332 | } |
| 333 | |
| 334 | static void mmc_mq_exit_request(struct blk_mq_tag_set *set, struct request *req, |
| 335 | unsigned int hctx_idx) |
| 336 | { |
| 337 | struct mmc_queue *mq = set->driver_data; |
| 338 | |
| 339 | mmc_exit_request(mq->queue, req); |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | * We use BLK_MQ_F_BLOCKING and have only 1 hardware queue, which means requests |
| 344 | * will not be dispatched in parallel. |
| 345 | */ |
| 346 | static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx, |
| 347 | const struct blk_mq_queue_data *bd) |
| 348 | { |
| 349 | struct request *req = bd->rq; |
| 350 | struct request_queue *q = req->q; |
| 351 | struct mmc_queue *mq = q->queuedata; |
| 352 | struct mmc_card *card = mq->card; |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 353 | struct mmc_host *host = card->host; |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 354 | enum mmc_issue_type issue_type; |
| 355 | enum mmc_issued issued; |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 356 | bool get_card, cqe_retune_ok; |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 357 | int ret; |
| 358 | |
| 359 | if (mmc_card_removed(mq->card)) { |
| 360 | req->rq_flags |= RQF_QUIET; |
| 361 | return BLK_STS_IOERR; |
| 362 | } |
| 363 | |
| 364 | issue_type = mmc_issue_type(mq, req); |
| 365 | |
| 366 | spin_lock_irq(q->queue_lock); |
| 367 | |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 368 | if (mq->recovery_needed) { |
| 369 | spin_unlock_irq(q->queue_lock); |
| 370 | return BLK_STS_RESOURCE; |
| 371 | } |
| 372 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 373 | switch (issue_type) { |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 374 | case MMC_ISSUE_DCMD: |
| 375 | if (mmc_cqe_dcmd_busy(mq)) { |
| 376 | mq->cqe_busy |= MMC_CQE_DCMD_BUSY; |
| 377 | spin_unlock_irq(q->queue_lock); |
| 378 | return BLK_STS_RESOURCE; |
| 379 | } |
| 380 | break; |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 381 | case MMC_ISSUE_ASYNC: |
| 382 | break; |
| 383 | default: |
| 384 | /* |
| 385 | * Timeouts are handled by mmc core, and we don't have a host |
| 386 | * API to abort requests, so we can't handle the timeout anyway. |
| 387 | * However, when the timeout happens, blk_mq_complete_request() |
| 388 | * no longer works (to stop the request disappearing under us). |
| 389 | * To avoid racing with that, set a large timeout. |
| 390 | */ |
| 391 | req->timeout = 600 * HZ; |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | mq->in_flight[issue_type] += 1; |
| 396 | get_card = (mmc_tot_in_flight(mq) == 1); |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 397 | cqe_retune_ok = (mmc_cqe_qcnt(mq) == 1); |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 398 | |
| 399 | spin_unlock_irq(q->queue_lock); |
| 400 | |
| 401 | if (!(req->rq_flags & RQF_DONTPREP)) { |
| 402 | req_to_mmc_queue_req(req)->retries = 0; |
| 403 | req->rq_flags |= RQF_DONTPREP; |
| 404 | } |
| 405 | |
| 406 | if (get_card) |
| 407 | mmc_get_card(card, &mq->ctx); |
| 408 | |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 409 | if (mq->use_cqe) { |
| 410 | host->retune_now = host->need_retune && cqe_retune_ok && |
| 411 | !host->hold_retune; |
| 412 | } |
| 413 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 414 | blk_mq_start_request(req); |
| 415 | |
| 416 | issued = mmc_blk_mq_issue_rq(mq, req); |
| 417 | |
| 418 | switch (issued) { |
| 419 | case MMC_REQ_BUSY: |
| 420 | ret = BLK_STS_RESOURCE; |
| 421 | break; |
| 422 | case MMC_REQ_FAILED_TO_START: |
| 423 | ret = BLK_STS_IOERR; |
| 424 | break; |
| 425 | default: |
| 426 | ret = BLK_STS_OK; |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | if (issued != MMC_REQ_STARTED) { |
| 431 | bool put_card = false; |
| 432 | |
| 433 | spin_lock_irq(q->queue_lock); |
| 434 | mq->in_flight[issue_type] -= 1; |
| 435 | if (mmc_tot_in_flight(mq) == 0) |
| 436 | put_card = true; |
| 437 | spin_unlock_irq(q->queue_lock); |
| 438 | if (put_card) |
| 439 | mmc_put_card(card, &mq->ctx); |
| 440 | } |
| 441 | |
| 442 | return ret; |
| 443 | } |
| 444 | |
| 445 | static const struct blk_mq_ops mmc_mq_ops = { |
| 446 | .queue_rq = mmc_mq_queue_rq, |
| 447 | .init_request = mmc_mq_init_request, |
| 448 | .exit_request = mmc_mq_exit_request, |
| 449 | .complete = mmc_blk_mq_complete, |
| 450 | .timeout = mmc_mq_timed_out, |
| 451 | }; |
| 452 | |
Adrian Hunter | c8b5fd0 | 2017-09-22 15:36:57 +0300 | [diff] [blame] | 453 | static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card) |
| 454 | { |
| 455 | struct mmc_host *host = card->host; |
| 456 | u64 limit = BLK_BOUNCE_HIGH; |
| 457 | |
| 458 | if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask) |
| 459 | limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT; |
| 460 | |
| 461 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); |
| 462 | queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, mq->queue); |
| 463 | if (mmc_can_erase(card)) |
| 464 | mmc_queue_setup_discard(mq->queue, card); |
| 465 | |
| 466 | blk_queue_bounce_limit(mq->queue, limit); |
| 467 | blk_queue_max_hw_sectors(mq->queue, |
| 468 | min(host->max_blk_count, host->max_req_size / 512)); |
| 469 | blk_queue_max_segments(mq->queue, host->max_segs); |
| 470 | blk_queue_max_segment_size(mq->queue, host->max_seg_size); |
| 471 | |
| 472 | /* Initialize thread_sem even if it is not used */ |
| 473 | sema_init(&mq->thread_sem, 1); |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 474 | |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 475 | INIT_WORK(&mq->recovery_work, mmc_mq_recovery_handler); |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 476 | INIT_WORK(&mq->complete_work, mmc_blk_mq_complete_work); |
| 477 | |
| 478 | mutex_init(&mq->complete_lock); |
| 479 | |
| 480 | init_waitqueue_head(&mq->wait); |
| 481 | } |
| 482 | |
| 483 | static int mmc_mq_init_queue(struct mmc_queue *mq, int q_depth, |
| 484 | const struct blk_mq_ops *mq_ops, spinlock_t *lock) |
| 485 | { |
| 486 | int ret; |
| 487 | |
| 488 | memset(&mq->tag_set, 0, sizeof(mq->tag_set)); |
| 489 | mq->tag_set.ops = mq_ops; |
| 490 | mq->tag_set.queue_depth = q_depth; |
| 491 | mq->tag_set.numa_node = NUMA_NO_NODE; |
| 492 | mq->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE | |
| 493 | BLK_MQ_F_BLOCKING; |
| 494 | mq->tag_set.nr_hw_queues = 1; |
| 495 | mq->tag_set.cmd_size = sizeof(struct mmc_queue_req); |
| 496 | mq->tag_set.driver_data = mq; |
| 497 | |
| 498 | ret = blk_mq_alloc_tag_set(&mq->tag_set); |
| 499 | if (ret) |
| 500 | return ret; |
| 501 | |
| 502 | mq->queue = blk_mq_init_queue(&mq->tag_set); |
| 503 | if (IS_ERR(mq->queue)) { |
| 504 | ret = PTR_ERR(mq->queue); |
| 505 | goto free_tag_set; |
| 506 | } |
| 507 | |
| 508 | mq->queue->queue_lock = lock; |
| 509 | mq->queue->queuedata = mq; |
| 510 | |
| 511 | return 0; |
| 512 | |
| 513 | free_tag_set: |
| 514 | blk_mq_free_tag_set(&mq->tag_set); |
| 515 | |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | /* Set queue depth to get a reasonable value for q->nr_requests */ |
| 520 | #define MMC_QUEUE_DEPTH 64 |
| 521 | |
| 522 | static int mmc_mq_init(struct mmc_queue *mq, struct mmc_card *card, |
| 523 | spinlock_t *lock) |
| 524 | { |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 525 | struct mmc_host *host = card->host; |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 526 | int q_depth; |
| 527 | int ret; |
| 528 | |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 529 | /* |
| 530 | * The queue depth for CQE must match the hardware because the request |
| 531 | * tag is used to index the hardware queue. |
| 532 | */ |
| 533 | if (mq->use_cqe) |
| 534 | q_depth = min_t(int, card->ext_csd.cmdq_depth, host->cqe_qdepth); |
| 535 | else |
| 536 | q_depth = MMC_QUEUE_DEPTH; |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 537 | |
| 538 | ret = mmc_mq_init_queue(mq, q_depth, &mmc_mq_ops, lock); |
| 539 | if (ret) |
| 540 | return ret; |
| 541 | |
| 542 | blk_queue_rq_timeout(mq->queue, 60 * HZ); |
| 543 | |
| 544 | mmc_setup_queue(mq, card); |
| 545 | |
| 546 | return 0; |
Adrian Hunter | c8b5fd0 | 2017-09-22 15:36:57 +0300 | [diff] [blame] | 547 | } |
| 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | /** |
| 550 | * mmc_init_queue - initialise a queue structure. |
| 551 | * @mq: mmc queue |
| 552 | * @card: mmc card to attach this queue |
| 553 | * @lock: queue lock |
Adrian Hunter | d09408a | 2011-06-23 13:40:28 +0300 | [diff] [blame] | 554 | * @subname: partition subname |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | * |
| 556 | * Initialise a MMC card request queue. |
| 557 | */ |
Adrian Hunter | d09408a | 2011-06-23 13:40:28 +0300 | [diff] [blame] | 558 | int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, |
| 559 | spinlock_t *lock, const char *subname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
| 561 | struct mmc_host *host = card->host; |
Adrian Hunter | c5bda0c | 2016-11-29 12:09:15 +0200 | [diff] [blame] | 562 | int ret = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | mq->card = card; |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 565 | |
Adrian Hunter | 1e8e55b | 2017-11-29 15:41:04 +0200 | [diff] [blame] | 566 | mq->use_cqe = host->cqe_enabled; |
| 567 | |
| 568 | if (mq->use_cqe || mmc_host_use_blk_mq(host)) |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 569 | return mmc_mq_init(mq, card, lock); |
| 570 | |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 571 | mq->queue = blk_alloc_queue(GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | if (!mq->queue) |
| 573 | return -ENOMEM; |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 574 | mq->queue->queue_lock = lock; |
| 575 | mq->queue->request_fn = mmc_request_fn; |
| 576 | mq->queue->init_rq_fn = mmc_init_request; |
| 577 | mq->queue->exit_rq_fn = mmc_exit_request; |
| 578 | mq->queue->cmd_size = sizeof(struct mmc_queue_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | mq->queue->queuedata = mq; |
Linus Walleij | 304419d | 2017-05-18 11:29:32 +0200 | [diff] [blame] | 580 | mq->qcnt = 0; |
| 581 | ret = blk_init_allocated_queue(mq->queue); |
| 582 | if (ret) { |
| 583 | blk_cleanup_queue(mq->queue); |
| 584 | return ret; |
| 585 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 587 | blk_queue_prep_rq(mq->queue, mmc_prep_request); |
| 588 | |
Adrian Hunter | c8b5fd0 | 2017-09-22 15:36:57 +0300 | [diff] [blame] | 589 | mmc_setup_queue(mq, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Adrian Hunter | d09408a | 2011-06-23 13:40:28 +0300 | [diff] [blame] | 591 | mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd/%d%s", |
| 592 | host->index, subname ? subname : ""); |
Ethan Du | de528fa | 2010-09-30 18:40:27 -0400 | [diff] [blame] | 593 | |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 594 | if (IS_ERR(mq->thread)) { |
| 595 | ret = PTR_ERR(mq->thread); |
Adrian Hunter | c09949c | 2016-11-29 12:09:14 +0200 | [diff] [blame] | 596 | goto cleanup_queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 599 | return 0; |
Per Forlin | 97868a2 | 2011-07-09 17:12:36 -0400 | [diff] [blame] | 600 | |
Adrian Hunter | 7b410d0 | 2017-03-13 14:36:36 +0200 | [diff] [blame] | 601 | cleanup_queue: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | blk_cleanup_queue(mq->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | return ret; |
| 604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 606 | static void mmc_mq_queue_suspend(struct mmc_queue *mq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 608 | blk_mq_quiesce_queue(mq->queue); |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 609 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 610 | /* |
| 611 | * The host remains claimed while there are outstanding requests, so |
| 612 | * simply claiming and releasing here ensures there are none. |
| 613 | */ |
| 614 | mmc_claim_host(mq->card->host); |
| 615 | mmc_release_host(mq->card->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 618 | static void mmc_mq_queue_resume(struct mmc_queue *mq) |
| 619 | { |
| 620 | blk_mq_unquiesce_queue(mq->queue); |
| 621 | } |
| 622 | |
| 623 | static void __mmc_queue_suspend(struct mmc_queue *mq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 625 | struct request_queue *q = mq->queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | unsigned long flags; |
| 627 | |
Linus Walleij | 9491be5 | 2017-02-01 13:47:56 +0100 | [diff] [blame] | 628 | if (!mq->suspended) { |
| 629 | mq->suspended |= true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | spin_lock_irqsave(q->queue_lock, flags); |
| 632 | blk_stop_queue(q); |
| 633 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 634 | |
| 635 | down(&mq->thread_sem); |
| 636 | } |
| 637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 639 | static void __mmc_queue_resume(struct mmc_queue *mq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 641 | struct request_queue *q = mq->queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | unsigned long flags; |
| 643 | |
Linus Walleij | 9491be5 | 2017-02-01 13:47:56 +0100 | [diff] [blame] | 644 | if (mq->suspended) { |
| 645 | mq->suspended = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | up(&mq->thread_sem); |
| 648 | |
| 649 | spin_lock_irqsave(q->queue_lock, flags); |
| 650 | blk_start_queue(q); |
| 651 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 652 | } |
| 653 | } |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 654 | |
Adrian Hunter | 8119697 | 2017-11-29 15:41:03 +0200 | [diff] [blame] | 655 | void mmc_cleanup_queue(struct mmc_queue *mq) |
| 656 | { |
| 657 | struct request_queue *q = mq->queue; |
| 658 | unsigned long flags; |
| 659 | |
| 660 | if (q->mq_ops) { |
| 661 | /* |
| 662 | * The legacy code handled the possibility of being suspended, |
| 663 | * so do that here too. |
| 664 | */ |
| 665 | if (blk_queue_quiesced(q)) |
| 666 | blk_mq_unquiesce_queue(q); |
| 667 | goto out_cleanup; |
| 668 | } |
| 669 | |
| 670 | /* Make sure the queue isn't suspended, as that will deadlock */ |
| 671 | mmc_queue_resume(mq); |
| 672 | |
| 673 | /* Then terminate our worker thread */ |
| 674 | kthread_stop(mq->thread); |
| 675 | |
| 676 | /* Empty the queue */ |
| 677 | spin_lock_irqsave(q->queue_lock, flags); |
| 678 | q->queuedata = NULL; |
| 679 | blk_start_queue(q); |
| 680 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 681 | |
| 682 | out_cleanup: |
| 683 | blk_cleanup_queue(q); |
| 684 | |
| 685 | /* |
| 686 | * A request can be completed before the next request, potentially |
| 687 | * leaving a complete_work with nothing to do. Such a work item might |
| 688 | * still be queued at this point. Flush it. |
| 689 | */ |
| 690 | flush_work(&mq->complete_work); |
| 691 | |
| 692 | mq->card = NULL; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * mmc_queue_suspend - suspend a MMC request queue |
| 697 | * @mq: MMC queue to suspend |
| 698 | * |
| 699 | * Stop the block request queue, and wait for our thread to |
| 700 | * complete any outstanding requests. This ensures that we |
| 701 | * won't suspend while a request is being processed. |
| 702 | */ |
| 703 | void mmc_queue_suspend(struct mmc_queue *mq) |
| 704 | { |
| 705 | struct request_queue *q = mq->queue; |
| 706 | |
| 707 | if (q->mq_ops) |
| 708 | mmc_mq_queue_suspend(mq); |
| 709 | else |
| 710 | __mmc_queue_suspend(mq); |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * mmc_queue_resume - resume a previously suspended MMC request queue |
| 715 | * @mq: MMC queue to resume |
| 716 | */ |
| 717 | void mmc_queue_resume(struct mmc_queue *mq) |
| 718 | { |
| 719 | struct request_queue *q = mq->queue; |
| 720 | |
| 721 | if (q->mq_ops) |
| 722 | mmc_mq_queue_resume(mq); |
| 723 | else |
| 724 | __mmc_queue_resume(mq); |
| 725 | } |
| 726 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 727 | /* |
| 728 | * Prepare the sg list(s) to be handed of to the host driver |
| 729 | */ |
Per Forlin | 97868a2 | 2011-07-09 17:12:36 -0400 | [diff] [blame] | 730 | unsigned int mmc_queue_map_sg(struct mmc_queue *mq, struct mmc_queue_req *mqrq) |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 731 | { |
Linus Walleij | 67e69d5 | 2017-05-19 15:37:27 +0200 | [diff] [blame] | 732 | struct request *req = mmc_queue_req_to_req(mqrq); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 733 | |
Linus Walleij | de3ee99 | 2017-09-20 10:56:14 +0200 | [diff] [blame] | 734 | return blk_rq_map_sg(mq->queue, req, mqrq->sg); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 735 | } |