blob: 3557d5c51141da7cec0d961947d54dbeec7390f4 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright (C) 2003 Russell King, All Rights Reserved.
Pierre Ossman98ac2162006-12-23 20:03:02 +01004 * Copyright 2006-2007 Pierre Ossman
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09006#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/module.h>
8#include <linux/blkdev.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -07009#include <linux/freezer.h>
Christoph Hellwig87598a22006-11-13 20:23:52 +010010#include <linux/kthread.h>
Jens Axboe45711f12007-10-22 21:19:53 +020011#include <linux/scatterlist.h>
Santosh Shilimkar8e0cb8a2013-07-29 14:20:15 +010012#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include <linux/mmc/card.h>
15#include <linux/mmc/host.h>
Linus Walleij29eb7bd2016-09-20 11:34:38 +020016
Pierre Ossman98ac2162006-12-23 20:03:02 +010017#include "queue.h"
Linus Walleij29eb7bd2016-09-20 11:34:38 +020018#include "block.h"
Ulf Hansson55244c52017-01-13 14:14:08 +010019#include "core.h"
Ulf Hansson4facdde2017-01-13 14:14:14 +010020#include "card.h"
Adrian Hunter81196972017-11-29 15:41:03 +020021#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Adrian Hunter1e8e55b2017-11-29 15:41:04 +020023static inline bool mmc_cqe_dcmd_busy(struct mmc_queue *mq)
24{
25 /* Allow only 1 DCMD at a time */
26 return mq->in_flight[MMC_ISSUE_DCMD];
27}
28
29void mmc_cqe_check_busy(struct mmc_queue *mq)
30{
31 if ((mq->cqe_busy & MMC_CQE_DCMD_BUSY) && !mmc_cqe_dcmd_busy(mq))
32 mq->cqe_busy &= ~MMC_CQE_DCMD_BUSY;
33
34 mq->cqe_busy &= ~MMC_CQE_QUEUE_FULL;
35}
36
37static inline bool mmc_cqe_can_dcmd(struct mmc_host *host)
38{
39 return host->caps2 & MMC_CAP2_CQE_DCMD;
40}
41
Colin Ian King15ff2942017-11-30 11:37:38 +000042static enum mmc_issue_type mmc_cqe_issue_type(struct mmc_host *host,
43 struct request *req)
Adrian Hunter1e8e55b2017-11-29 15:41:04 +020044{
45 switch (req_op(req)) {
46 case REQ_OP_DRV_IN:
47 case REQ_OP_DRV_OUT:
48 case REQ_OP_DISCARD:
49 case REQ_OP_SECURE_ERASE:
50 return MMC_ISSUE_SYNC;
51 case REQ_OP_FLUSH:
52 return mmc_cqe_can_dcmd(host) ? MMC_ISSUE_DCMD : MMC_ISSUE_SYNC;
53 default:
54 return MMC_ISSUE_ASYNC;
55 }
56}
57
Adrian Hunter81196972017-11-29 15:41:03 +020058enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req)
59{
Adrian Hunter1e8e55b2017-11-29 15:41:04 +020060 struct mmc_host *host = mq->card->host;
61
62 if (mq->use_cqe)
63 return mmc_cqe_issue_type(host, req);
64
Adrian Hunter81196972017-11-29 15:41:03 +020065 if (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE)
66 return MMC_ISSUE_ASYNC;
67
68 return MMC_ISSUE_SYNC;
69}
70
Adrian Hunter1e8e55b2017-11-29 15:41:04 +020071static void __mmc_cqe_recovery_notifier(struct mmc_queue *mq)
72{
73 if (!mq->recovery_needed) {
74 mq->recovery_needed = true;
75 schedule_work(&mq->recovery_work);
76 }
77}
78
79void mmc_cqe_recovery_notifier(struct mmc_request *mrq)
80{
81 struct mmc_queue_req *mqrq = container_of(mrq, struct mmc_queue_req,
82 brq.mrq);
83 struct request *req = mmc_queue_req_to_req(mqrq);
84 struct request_queue *q = req->q;
85 struct mmc_queue *mq = q->queuedata;
86 unsigned long flags;
87
Christoph Hellwigf5d72c52018-11-16 09:10:06 +010088 spin_lock_irqsave(&mq->lock, flags);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +020089 __mmc_cqe_recovery_notifier(mq);
Christoph Hellwigf5d72c52018-11-16 09:10:06 +010090 spin_unlock_irqrestore(&mq->lock, flags);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +020091}
92
93static enum blk_eh_timer_return mmc_cqe_timed_out(struct request *req)
94{
95 struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
96 struct mmc_request *mrq = &mqrq->brq.mrq;
97 struct mmc_queue *mq = req->q->queuedata;
98 struct mmc_host *host = mq->card->host;
99 enum mmc_issue_type issue_type = mmc_issue_type(mq, req);
100 bool recovery_needed = false;
101
102 switch (issue_type) {
103 case MMC_ISSUE_ASYNC:
104 case MMC_ISSUE_DCMD:
105 if (host->cqe_ops->cqe_timeout(host, mrq, &recovery_needed)) {
106 if (recovery_needed)
107 __mmc_cqe_recovery_notifier(mq);
108 return BLK_EH_RESET_TIMER;
109 }
Christoph Hellwigad73d6f2018-05-29 15:52:35 +0200110 /* No timeout (XXX: huh? comment doesn't make much sense) */
111 blk_mq_complete_request(req);
112 return BLK_EH_DONE;
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200113 default:
114 /* Timeout is handled by mmc core */
115 return BLK_EH_RESET_TIMER;
116 }
117}
118
Adrian Hunter81196972017-11-29 15:41:03 +0200119static enum blk_eh_timer_return mmc_mq_timed_out(struct request *req,
120 bool reserved)
121{
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200122 struct request_queue *q = req->q;
123 struct mmc_queue *mq = q->queuedata;
124 unsigned long flags;
125 int ret;
126
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100127 spin_lock_irqsave(&mq->lock, flags);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200128
129 if (mq->recovery_needed || !mq->use_cqe)
130 ret = BLK_EH_RESET_TIMER;
131 else
132 ret = mmc_cqe_timed_out(req);
133
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100134 spin_unlock_irqrestore(&mq->lock, flags);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200135
136 return ret;
137}
138
139static void mmc_mq_recovery_handler(struct work_struct *work)
140{
141 struct mmc_queue *mq = container_of(work, struct mmc_queue,
142 recovery_work);
143 struct request_queue *q = mq->queue;
144
145 mmc_get_card(mq->card, &mq->ctx);
146
147 mq->in_recovery = true;
148
Adrian Hunter10f21df42017-11-29 15:41:07 +0200149 if (mq->use_cqe)
150 mmc_blk_cqe_recovery(mq);
151 else
152 mmc_blk_mq_recovery(mq);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200153
154 mq->in_recovery = false;
155
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100156 spin_lock_irq(&mq->lock);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200157 mq->recovery_needed = false;
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100158 spin_unlock_irq(&mq->lock);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200159
160 mmc_put_card(mq->card, &mq->ctx);
161
162 blk_mq_run_hw_queues(q, true);
Adrian Hunter81196972017-11-29 15:41:03 +0200163}
164
Linus Walleij304419d2017-05-18 11:29:32 +0200165static struct scatterlist *mmc_alloc_sg(int sg_len, gfp_t gfp)
Per Forlin97868a22011-07-09 17:12:36 -0400166{
167 struct scatterlist *sg;
168
Linus Walleij304419d2017-05-18 11:29:32 +0200169 sg = kmalloc_array(sg_len, sizeof(*sg), gfp);
Adrian Hunter7b410d02017-03-13 14:36:36 +0200170 if (sg)
Per Forlin97868a22011-07-09 17:12:36 -0400171 sg_init_table(sg, sg_len);
Per Forlin97868a22011-07-09 17:12:36 -0400172
173 return sg;
174}
175
Adrian Huntere056a1b2011-06-28 17:16:02 +0300176static void mmc_queue_setup_discard(struct request_queue *q,
177 struct mmc_card *card)
178{
179 unsigned max_discard;
180
181 max_discard = mmc_calc_max_discard(card);
182 if (!max_discard)
183 return;
184
Bart Van Assche8b904b52018-03-07 17:10:10 -0800185 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
Jens Axboe2bb4cd52015-07-14 08:15:12 -0600186 blk_queue_max_discard_sectors(q, max_discard);
Adrian Huntere056a1b2011-06-28 17:16:02 +0300187 q->limits.discard_granularity = card->pref_erase << 9;
188 /* granularity must not be greater than max. discard */
189 if (card->pref_erase > max_discard)
190 q->limits.discard_granularity = 0;
Maya Erez775a9362013-04-18 15:41:55 +0300191 if (mmc_can_secure_erase_trim(card))
Bart Van Assche8b904b52018-03-07 17:10:10 -0800192 blk_queue_flag_set(QUEUE_FLAG_SECERASE, q);
Adrian Huntere056a1b2011-06-28 17:16:02 +0300193}
194
Linus Walleij304419d2017-05-18 11:29:32 +0200195/**
196 * mmc_init_request() - initialize the MMC-specific per-request data
197 * @q: the request queue
198 * @req: the request
199 * @gfp: memory allocation policy
200 */
Adrian Hunter81196972017-11-29 15:41:03 +0200201static int __mmc_init_request(struct mmc_queue *mq, struct request *req,
202 gfp_t gfp)
Adrian Hunterf2b8b522016-11-29 12:09:12 +0200203{
Linus Walleij304419d2017-05-18 11:29:32 +0200204 struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req);
Linus Walleij304419d2017-05-18 11:29:32 +0200205 struct mmc_card *card = mq->card;
206 struct mmc_host *host = card->host;
Adrian Hunterc8539822016-11-29 12:09:11 +0200207
Linus Walleijde3ee992017-09-20 10:56:14 +0200208 mq_rq->sg = mmc_alloc_sg(host->max_segs, gfp);
209 if (!mq_rq->sg)
210 return -ENOMEM;
Adrian Hunter64e29e422016-11-29 12:09:13 +0200211
Adrian Hunterc5bda0c2016-11-29 12:09:15 +0200212 return 0;
213}
Adrian Hunter64e29e422016-11-29 12:09:13 +0200214
Linus Walleij304419d2017-05-18 11:29:32 +0200215static void mmc_exit_request(struct request_queue *q, struct request *req)
Adrian Hunterc5bda0c2016-11-29 12:09:15 +0200216{
Linus Walleij304419d2017-05-18 11:29:32 +0200217 struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req);
Adrian Hunter64e29e422016-11-29 12:09:13 +0200218
Linus Walleij304419d2017-05-18 11:29:32 +0200219 kfree(mq_rq->sg);
220 mq_rq->sg = NULL;
Adrian Hunterc09949c2016-11-29 12:09:14 +0200221}
222
Adrian Hunter81196972017-11-29 15:41:03 +0200223static int mmc_mq_init_request(struct blk_mq_tag_set *set, struct request *req,
224 unsigned int hctx_idx, unsigned int numa_node)
225{
226 return __mmc_init_request(set->driver_data, req, GFP_KERNEL);
227}
228
229static void mmc_mq_exit_request(struct blk_mq_tag_set *set, struct request *req,
230 unsigned int hctx_idx)
231{
232 struct mmc_queue *mq = set->driver_data;
233
234 mmc_exit_request(mq->queue, req);
235}
236
Adrian Hunter81196972017-11-29 15:41:03 +0200237static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
238 const struct blk_mq_queue_data *bd)
239{
240 struct request *req = bd->rq;
241 struct request_queue *q = req->q;
242 struct mmc_queue *mq = q->queuedata;
243 struct mmc_card *card = mq->card;
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200244 struct mmc_host *host = card->host;
Adrian Hunter81196972017-11-29 15:41:03 +0200245 enum mmc_issue_type issue_type;
246 enum mmc_issued issued;
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200247 bool get_card, cqe_retune_ok;
Adrian Hunter81196972017-11-29 15:41:03 +0200248 int ret;
249
250 if (mmc_card_removed(mq->card)) {
251 req->rq_flags |= RQF_QUIET;
252 return BLK_STS_IOERR;
253 }
254
255 issue_type = mmc_issue_type(mq, req);
256
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100257 spin_lock_irq(&mq->lock);
Adrian Hunter81196972017-11-29 15:41:03 +0200258
Adrian Hunter26caddf2018-08-21 15:05:55 +0300259 if (mq->recovery_needed || mq->busy) {
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100260 spin_unlock_irq(&mq->lock);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200261 return BLK_STS_RESOURCE;
262 }
263
Adrian Hunter81196972017-11-29 15:41:03 +0200264 switch (issue_type) {
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200265 case MMC_ISSUE_DCMD:
266 if (mmc_cqe_dcmd_busy(mq)) {
267 mq->cqe_busy |= MMC_CQE_DCMD_BUSY;
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100268 spin_unlock_irq(&mq->lock);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200269 return BLK_STS_RESOURCE;
270 }
271 break;
Adrian Hunter81196972017-11-29 15:41:03 +0200272 case MMC_ISSUE_ASYNC:
273 break;
274 default:
275 /*
276 * Timeouts are handled by mmc core, and we don't have a host
277 * API to abort requests, so we can't handle the timeout anyway.
278 * However, when the timeout happens, blk_mq_complete_request()
279 * no longer works (to stop the request disappearing under us).
280 * To avoid racing with that, set a large timeout.
281 */
282 req->timeout = 600 * HZ;
283 break;
284 }
285
Adrian Hunter26caddf2018-08-21 15:05:55 +0300286 /* Parallel dispatch of requests is not supported at the moment */
287 mq->busy = true;
288
Adrian Hunter81196972017-11-29 15:41:03 +0200289 mq->in_flight[issue_type] += 1;
290 get_card = (mmc_tot_in_flight(mq) == 1);
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200291 cqe_retune_ok = (mmc_cqe_qcnt(mq) == 1);
Adrian Hunter81196972017-11-29 15:41:03 +0200292
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100293 spin_unlock_irq(&mq->lock);
Adrian Hunter81196972017-11-29 15:41:03 +0200294
295 if (!(req->rq_flags & RQF_DONTPREP)) {
296 req_to_mmc_queue_req(req)->retries = 0;
297 req->rq_flags |= RQF_DONTPREP;
298 }
299
300 if (get_card)
301 mmc_get_card(card, &mq->ctx);
302
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200303 if (mq->use_cqe) {
304 host->retune_now = host->need_retune && cqe_retune_ok &&
305 !host->hold_retune;
306 }
307
Adrian Hunter81196972017-11-29 15:41:03 +0200308 blk_mq_start_request(req);
309
310 issued = mmc_blk_mq_issue_rq(mq, req);
311
312 switch (issued) {
313 case MMC_REQ_BUSY:
314 ret = BLK_STS_RESOURCE;
315 break;
316 case MMC_REQ_FAILED_TO_START:
317 ret = BLK_STS_IOERR;
318 break;
319 default:
320 ret = BLK_STS_OK;
321 break;
322 }
323
324 if (issued != MMC_REQ_STARTED) {
325 bool put_card = false;
326
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100327 spin_lock_irq(&mq->lock);
Adrian Hunter81196972017-11-29 15:41:03 +0200328 mq->in_flight[issue_type] -= 1;
329 if (mmc_tot_in_flight(mq) == 0)
330 put_card = true;
Adrian Hunter26caddf2018-08-21 15:05:55 +0300331 mq->busy = false;
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100332 spin_unlock_irq(&mq->lock);
Adrian Hunter81196972017-11-29 15:41:03 +0200333 if (put_card)
334 mmc_put_card(card, &mq->ctx);
Adrian Hunter26caddf2018-08-21 15:05:55 +0300335 } else {
336 WRITE_ONCE(mq->busy, false);
Adrian Hunter81196972017-11-29 15:41:03 +0200337 }
338
339 return ret;
340}
341
342static const struct blk_mq_ops mmc_mq_ops = {
343 .queue_rq = mmc_mq_queue_rq,
344 .init_request = mmc_mq_init_request,
345 .exit_request = mmc_mq_exit_request,
346 .complete = mmc_blk_mq_complete,
347 .timeout = mmc_mq_timed_out,
348};
349
Adrian Hunterc8b5fd02017-09-22 15:36:57 +0300350static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
351{
352 struct mmc_host *host = card->host;
353 u64 limit = BLK_BOUNCE_HIGH;
Ming Leic53336c2019-02-28 00:02:11 +0800354 unsigned block_size = 512;
Adrian Hunterc8b5fd02017-09-22 15:36:57 +0300355
356 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
357 limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
358
Bart Van Assche8b904b52018-03-07 17:10:10 -0800359 blk_queue_flag_set(QUEUE_FLAG_NONROT, mq->queue);
360 blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, mq->queue);
Adrian Hunterc8b5fd02017-09-22 15:36:57 +0300361 if (mmc_can_erase(card))
362 mmc_queue_setup_discard(mq->queue, card);
363
364 blk_queue_bounce_limit(mq->queue, limit);
365 blk_queue_max_hw_sectors(mq->queue,
366 min(host->max_blk_count, host->max_req_size / 512));
367 blk_queue_max_segments(mq->queue, host->max_segs);
Ming Leic53336c2019-02-28 00:02:11 +0800368
369 if (mmc_card_mmc(card))
370 block_size = card->ext_csd.data_sector_size;
371
372 blk_queue_logical_block_size(mq->queue, block_size);
373 blk_queue_max_segment_size(mq->queue,
374 round_down(host->max_seg_size, block_size));
Adrian Hunterc8b5fd02017-09-22 15:36:57 +0300375
Christoph Hellwigcf1db7f2019-06-05 21:08:27 +0200376 dma_set_max_seg_size(mmc_dev(host), queue_max_segment_size(mq->queue));
377
Adrian Hunter1e8e55b2017-11-29 15:41:04 +0200378 INIT_WORK(&mq->recovery_work, mmc_mq_recovery_handler);
Adrian Hunter81196972017-11-29 15:41:03 +0200379 INIT_WORK(&mq->complete_work, mmc_blk_mq_complete_work);
380
381 mutex_init(&mq->complete_lock);
382
383 init_waitqueue_head(&mq->wait);
384}
385
Christoph Hellwigb061b322018-11-14 17:02:16 +0100386/* Set queue depth to get a reasonable value for q->nr_requests */
387#define MMC_QUEUE_DEPTH 64
388
389/**
390 * mmc_init_queue - initialise a queue structure.
391 * @mq: mmc queue
392 * @card: mmc card to attach this queue
Christoph Hellwigb061b322018-11-14 17:02:16 +0100393 *
394 * Initialise a MMC card request queue.
395 */
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100396int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card)
Adrian Hunter81196972017-11-29 15:41:03 +0200397{
Christoph Hellwigb061b322018-11-14 17:02:16 +0100398 struct mmc_host *host = card->host;
Adrian Hunter81196972017-11-29 15:41:03 +0200399 int ret;
400
Christoph Hellwigb061b322018-11-14 17:02:16 +0100401 mq->card = card;
402 mq->use_cqe = host->cqe_enabled;
Christoph Hellwigf5d72c52018-11-16 09:10:06 +0100403
404 spin_lock_init(&mq->lock);
Christoph Hellwigb061b322018-11-14 17:02:16 +0100405
Adrian Hunter81196972017-11-29 15:41:03 +0200406 memset(&mq->tag_set, 0, sizeof(mq->tag_set));
Christoph Hellwigb061b322018-11-14 17:02:16 +0100407 mq->tag_set.ops = &mmc_mq_ops;
408 /*
409 * The queue depth for CQE must match the hardware because the request
410 * tag is used to index the hardware queue.
411 */
412 if (mq->use_cqe)
413 mq->tag_set.queue_depth =
414 min_t(int, card->ext_csd.cmdq_depth, host->cqe_qdepth);
415 else
416 mq->tag_set.queue_depth = MMC_QUEUE_DEPTH;
Adrian Hunter81196972017-11-29 15:41:03 +0200417 mq->tag_set.numa_node = NUMA_NO_NODE;
Ming Lei56d18f62019-02-15 19:13:24 +0800418 mq->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
Adrian Hunter81196972017-11-29 15:41:03 +0200419 mq->tag_set.nr_hw_queues = 1;
420 mq->tag_set.cmd_size = sizeof(struct mmc_queue_req);
421 mq->tag_set.driver_data = mq;
422
423 ret = blk_mq_alloc_tag_set(&mq->tag_set);
424 if (ret)
425 return ret;
426
427 mq->queue = blk_mq_init_queue(&mq->tag_set);
428 if (IS_ERR(mq->queue)) {
429 ret = PTR_ERR(mq->queue);
430 goto free_tag_set;
431 }
432
Adrian Hunter81196972017-11-29 15:41:03 +0200433 mq->queue->queuedata = mq;
Christoph Hellwigb061b322018-11-14 17:02:16 +0100434 blk_queue_rq_timeout(mq->queue, 60 * HZ);
Adrian Hunter81196972017-11-29 15:41:03 +0200435
Christoph Hellwigb061b322018-11-14 17:02:16 +0100436 mmc_setup_queue(mq, card);
Adrian Hunter81196972017-11-29 15:41:03 +0200437 return 0;
438
439free_tag_set:
440 blk_mq_free_tag_set(&mq->tag_set);
Adrian Hunter81196972017-11-29 15:41:03 +0200441 return ret;
442}
443
Adrian Hunter0fbfd122017-11-29 15:41:18 +0200444void mmc_queue_suspend(struct mmc_queue *mq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Adrian Hunter81196972017-11-29 15:41:03 +0200446 blk_mq_quiesce_queue(mq->queue);
Pierre Ossman89b4e132006-11-14 22:08:16 +0100447
Adrian Hunter81196972017-11-29 15:41:03 +0200448 /*
449 * The host remains claimed while there are outstanding requests, so
450 * simply claiming and releasing here ensures there are none.
451 */
452 mmc_claim_host(mq->card->host);
453 mmc_release_host(mq->card->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Adrian Hunter0fbfd122017-11-29 15:41:18 +0200456void mmc_queue_resume(struct mmc_queue *mq)
Adrian Hunter81196972017-11-29 15:41:03 +0200457{
458 blk_mq_unquiesce_queue(mq->queue);
459}
460
Adrian Hunter81196972017-11-29 15:41:03 +0200461void mmc_cleanup_queue(struct mmc_queue *mq)
462{
463 struct request_queue *q = mq->queue;
Adrian Hunter81196972017-11-29 15:41:03 +0200464
Adrian Hunter0fbfd122017-11-29 15:41:18 +0200465 /*
466 * The legacy code handled the possibility of being suspended,
467 * so do that here too.
468 */
469 if (blk_queue_quiesced(q))
470 blk_mq_unquiesce_queue(q);
Adrian Hunter81196972017-11-29 15:41:03 +0200471
Adrian Hunter81196972017-11-29 15:41:03 +0200472 blk_cleanup_queue(q);
Raul E Rangel43d8dab2019-05-02 13:07:14 -0600473 blk_mq_free_tag_set(&mq->tag_set);
Adrian Hunter81196972017-11-29 15:41:03 +0200474
475 /*
476 * A request can be completed before the next request, potentially
477 * leaving a complete_work with nothing to do. Such a work item might
478 * still be queued at this point. Flush it.
479 */
480 flush_work(&mq->complete_work);
481
482 mq->card = NULL;
483}
484
Pierre Ossman2ff1fa62008-07-22 14:35:42 +0200485/*
486 * Prepare the sg list(s) to be handed of to the host driver
487 */
Per Forlin97868a22011-07-09 17:12:36 -0400488unsigned int mmc_queue_map_sg(struct mmc_queue *mq, struct mmc_queue_req *mqrq)
Pierre Ossman98ccf142007-05-12 00:26:16 +0200489{
Linus Walleij67e69d52017-05-19 15:37:27 +0200490 struct request *req = mmc_queue_req_to_req(mqrq);
Pierre Ossman98ccf142007-05-12 00:26:16 +0200491
Linus Walleijde3ee992017-09-20 10:56:14 +0200492 return blk_rq_map_sg(mq->queue, req, mqrq->sg);
Pierre Ossman98ccf142007-05-12 00:26:16 +0200493}