Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/card/queue.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2003 Russell King, All Rights Reserved. |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 5 | * Copyright 2006-2007 Pierre Ossman |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/blkdev.h> |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 15 | #include <linux/freezer.h> |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 16 | #include <linux/kthread.h> |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 17 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <linux/mmc/card.h> |
| 20 | #include <linux/mmc/host.h> |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 21 | #include "queue.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 23 | #define MMC_QUEUE_BOUNCESZ 65536 |
| 24 | |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 25 | #define MMC_QUEUE_SUSPENDED (1 << 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 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 | { |
Pierre Ossman | 9c9f2d6 | 2007-05-16 17:29:21 +0200 | [diff] [blame] | 32 | /* |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame^] | 33 | * We only like normal block requests and discards. |
Pierre Ossman | 9c9f2d6 | 2007-05-16 17:29:21 +0200 | [diff] [blame] | 34 | */ |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame^] | 35 | if (req->cmd_type != REQ_TYPE_FS && !(req->cmd_flags & REQ_DISCARD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | blk_dump_rq_flags(req, "MMC bad request"); |
Pierre Ossman | 9c9f2d6 | 2007-05-16 17:29:21 +0200 | [diff] [blame] | 37 | return BLKPREP_KILL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Pierre Ossman | 9c9f2d6 | 2007-05-16 17:29:21 +0200 | [diff] [blame] | 40 | req->cmd_flags |= REQ_DONTPREP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Pierre Ossman | 9c9f2d6 | 2007-05-16 17:29:21 +0200 | [diff] [blame] | 42 | return BLKPREP_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static int mmc_queue_thread(void *d) |
| 46 | { |
| 47 | struct mmc_queue *mq = d; |
| 48 | struct request_queue *q = mq->queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 50 | current->flags |= PF_MEMALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | down(&mq->thread_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | do { |
| 54 | struct request *req = NULL; |
| 55 | |
| 56 | spin_lock_irq(q->queue_lock); |
| 57 | set_current_state(TASK_INTERRUPTIBLE); |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 58 | if (!blk_queue_plugged(q)) |
| 59 | req = blk_fetch_request(q); |
Juha [êölä | c723e08a | 2006-08-06 09:58:22 +0100 | [diff] [blame] | 60 | mq->req = req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | spin_unlock_irq(q->queue_lock); |
| 62 | |
| 63 | if (!req) { |
Vitaly Wool | 7b30d28 | 2006-12-07 20:08:02 +0100 | [diff] [blame] | 64 | if (kthread_should_stop()) { |
| 65 | set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | break; |
Vitaly Wool | 7b30d28 | 2006-12-07 20:08:02 +0100 | [diff] [blame] | 67 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | up(&mq->thread_sem); |
| 69 | schedule(); |
| 70 | down(&mq->thread_sem); |
| 71 | continue; |
| 72 | } |
| 73 | set_current_state(TASK_RUNNING); |
| 74 | |
| 75 | mq->issue_fn(mq, req); |
| 76 | } while (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | up(&mq->thread_sem); |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Generic MMC request handler. This is called for any queue on a |
| 84 | * particular host. When the host is not busy, we look for a request |
| 85 | * on any queue on this host, and attempt to issue it. This may |
| 86 | * not be the queue we were asked to process. |
| 87 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 88 | static void mmc_request(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | struct mmc_queue *mq = q->queuedata; |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 91 | struct request *req; |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 92 | |
| 93 | if (!mq) { |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 94 | while ((req = blk_fetch_request(q)) != NULL) { |
| 95 | req->cmd_flags |= REQ_QUIET; |
Tejun Heo | 296b2f6 | 2009-05-08 11:54:15 +0900 | [diff] [blame] | 96 | __blk_end_request_all(req, -EIO); |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 97 | } |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 98 | return; |
| 99 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | if (!mq->req) |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 102 | wake_up_process(mq->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
| 106 | * mmc_init_queue - initialise a queue structure. |
| 107 | * @mq: mmc queue |
| 108 | * @card: mmc card to attach this queue |
| 109 | * @lock: queue lock |
| 110 | * |
| 111 | * Initialise a MMC card request queue. |
| 112 | */ |
| 113 | int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock) |
| 114 | { |
| 115 | struct mmc_host *host = card->host; |
| 116 | u64 limit = BLK_BOUNCE_HIGH; |
| 117 | int ret; |
| 118 | |
Greg Kroah-Hartman | fcaf71f | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 119 | if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask) |
| 120 | limit = *mmc_dev(host)->dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | mq->card = card; |
| 123 | mq->queue = blk_init_queue(mmc_request, lock); |
| 124 | if (!mq->queue) |
| 125 | return -ENOMEM; |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | mq->queue->queuedata = mq; |
| 128 | mq->req = NULL; |
| 129 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 130 | blk_queue_prep_rq(mq->queue, mmc_prep_request); |
FUJITA Tomonori | 00fff26 | 2010-07-03 17:45:40 +0900 | [diff] [blame] | 131 | blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN); |
Pierre Ossman | 8dddfe1 | 2008-10-14 20:04:46 +0200 | [diff] [blame] | 132 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame^] | 133 | if (mmc_can_erase(card)) { |
| 134 | queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mq->queue); |
| 135 | mq->queue->limits.max_discard_sectors = UINT_MAX; |
| 136 | if (card->erased_byte == 0) |
| 137 | mq->queue->limits.discard_zeroes_data = 1; |
| 138 | if (!mmc_can_trim(card) && is_power_of_2(card->erase_size)) { |
| 139 | mq->queue->limits.discard_granularity = |
| 140 | card->erase_size << 9; |
| 141 | mq->queue->limits.discard_alignment = |
| 142 | card->erase_size << 9; |
| 143 | } |
| 144 | } |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 145 | |
| 146 | #ifdef CONFIG_MMC_BLOCK_BOUNCE |
| 147 | if (host->max_hw_segs == 1) { |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 148 | unsigned int bouncesz; |
| 149 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 150 | bouncesz = MMC_QUEUE_BOUNCESZ; |
| 151 | |
| 152 | if (bouncesz > host->max_req_size) |
| 153 | bouncesz = host->max_req_size; |
| 154 | if (bouncesz > host->max_seg_size) |
| 155 | bouncesz = host->max_seg_size; |
Pierre Ossman | f3eb0aa | 2008-08-16 21:34:02 +0200 | [diff] [blame] | 156 | if (bouncesz > (host->max_blk_count * 512)) |
| 157 | bouncesz = host->max_blk_count * 512; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 158 | |
Pierre Ossman | f3eb0aa | 2008-08-16 21:34:02 +0200 | [diff] [blame] | 159 | if (bouncesz > 512) { |
| 160 | mq->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); |
| 161 | if (!mq->bounce_buf) { |
| 162 | printk(KERN_WARNING "%s: unable to " |
| 163 | "allocate bounce buffer\n", |
| 164 | mmc_card_name(card)); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (mq->bounce_buf) { |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 169 | blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY); |
Martin K. Petersen | 086fa5f | 2010-02-26 00:20:38 -0500 | [diff] [blame] | 170 | blk_queue_max_hw_sectors(mq->queue, bouncesz / 512); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 171 | blk_queue_max_segments(mq->queue, bouncesz / 512); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 172 | blk_queue_max_segment_size(mq->queue, bouncesz); |
| 173 | |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 174 | mq->sg = kmalloc(sizeof(struct scatterlist), |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 175 | GFP_KERNEL); |
| 176 | if (!mq->sg) { |
| 177 | ret = -ENOMEM; |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 178 | goto cleanup_queue; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 179 | } |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 180 | sg_init_table(mq->sg, 1); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 181 | |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 182 | mq->bounce_sg = kmalloc(sizeof(struct scatterlist) * |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 183 | bouncesz / 512, GFP_KERNEL); |
| 184 | if (!mq->bounce_sg) { |
| 185 | ret = -ENOMEM; |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 186 | goto cleanup_queue; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 187 | } |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 188 | sg_init_table(mq->bounce_sg, bouncesz / 512); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | #endif |
| 192 | |
| 193 | if (!mq->bounce_buf) { |
| 194 | blk_queue_bounce_limit(mq->queue, limit); |
Martin K. Petersen | 086fa5f | 2010-02-26 00:20:38 -0500 | [diff] [blame] | 195 | blk_queue_max_hw_sectors(mq->queue, |
Pierre Ossman | f3eb0aa | 2008-08-16 21:34:02 +0200 | [diff] [blame] | 196 | min(host->max_blk_count, host->max_req_size / 512)); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 197 | blk_queue_max_segments(mq->queue, host->max_hw_segs); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 198 | blk_queue_max_segment_size(mq->queue, host->max_seg_size); |
| 199 | |
Haavard Skinnemoen | 05e5b13 | 2007-11-23 10:19:00 +0100 | [diff] [blame] | 200 | mq->sg = kmalloc(sizeof(struct scatterlist) * |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 201 | host->max_phys_segs, GFP_KERNEL); |
| 202 | if (!mq->sg) { |
| 203 | ret = -ENOMEM; |
| 204 | goto cleanup_queue; |
| 205 | } |
Haavard Skinnemoen | 05e5b13 | 2007-11-23 10:19:00 +0100 | [diff] [blame] | 206 | sg_init_table(mq->sg, host->max_phys_segs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | init_MUTEX(&mq->thread_sem); |
| 210 | |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 211 | mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd"); |
| 212 | if (IS_ERR(mq->thread)) { |
| 213 | ret = PTR_ERR(mq->thread); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 214 | goto free_bounce_sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 217 | return 0; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 218 | free_bounce_sg: |
| 219 | if (mq->bounce_sg) |
| 220 | kfree(mq->bounce_sg); |
| 221 | mq->bounce_sg = NULL; |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 222 | cleanup_queue: |
| 223 | if (mq->sg) |
| 224 | kfree(mq->sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | mq->sg = NULL; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 226 | if (mq->bounce_buf) |
| 227 | kfree(mq->bounce_buf); |
| 228 | mq->bounce_buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | blk_cleanup_queue(mq->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return ret; |
| 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | void mmc_cleanup_queue(struct mmc_queue *mq) |
| 234 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 235 | struct request_queue *q = mq->queue; |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 236 | unsigned long flags; |
| 237 | |
Pierre Ossman | d2b46f6 | 2007-04-28 16:52:12 +0200 | [diff] [blame] | 238 | /* Make sure the queue isn't suspended, as that will deadlock */ |
| 239 | mmc_queue_resume(mq); |
| 240 | |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 241 | /* Then terminate our worker thread */ |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 242 | kthread_stop(mq->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 244 | /* Empty the queue */ |
| 245 | spin_lock_irqsave(q->queue_lock, flags); |
| 246 | q->queuedata = NULL; |
| 247 | blk_start_queue(q); |
| 248 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 249 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 250 | if (mq->bounce_sg) |
| 251 | kfree(mq->bounce_sg); |
| 252 | mq->bounce_sg = NULL; |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | kfree(mq->sg); |
| 255 | mq->sg = NULL; |
| 256 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 257 | if (mq->bounce_buf) |
| 258 | kfree(mq->bounce_buf); |
| 259 | mq->bounce_buf = NULL; |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | mq->card = NULL; |
| 262 | } |
| 263 | EXPORT_SYMBOL(mmc_cleanup_queue); |
| 264 | |
| 265 | /** |
| 266 | * mmc_queue_suspend - suspend a MMC request queue |
| 267 | * @mq: MMC queue to suspend |
| 268 | * |
| 269 | * Stop the block request queue, and wait for our thread to |
| 270 | * complete any outstanding requests. This ensures that we |
| 271 | * won't suspend while a request is being processed. |
| 272 | */ |
| 273 | void mmc_queue_suspend(struct mmc_queue *mq) |
| 274 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 275 | struct request_queue *q = mq->queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | unsigned long flags; |
| 277 | |
| 278 | if (!(mq->flags & MMC_QUEUE_SUSPENDED)) { |
| 279 | mq->flags |= MMC_QUEUE_SUSPENDED; |
| 280 | |
| 281 | spin_lock_irqsave(q->queue_lock, flags); |
| 282 | blk_stop_queue(q); |
| 283 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 284 | |
| 285 | down(&mq->thread_sem); |
| 286 | } |
| 287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * mmc_queue_resume - resume a previously suspended MMC request queue |
| 291 | * @mq: MMC queue to resume |
| 292 | */ |
| 293 | void mmc_queue_resume(struct mmc_queue *mq) |
| 294 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 295 | struct request_queue *q = mq->queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | unsigned long flags; |
| 297 | |
| 298 | if (mq->flags & MMC_QUEUE_SUSPENDED) { |
| 299 | mq->flags &= ~MMC_QUEUE_SUSPENDED; |
| 300 | |
| 301 | up(&mq->thread_sem); |
| 302 | |
| 303 | spin_lock_irqsave(q->queue_lock, flags); |
| 304 | blk_start_queue(q); |
| 305 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 306 | } |
| 307 | } |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 308 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 309 | /* |
| 310 | * Prepare the sg list(s) to be handed of to the host driver |
| 311 | */ |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 312 | unsigned int mmc_queue_map_sg(struct mmc_queue *mq) |
| 313 | { |
| 314 | unsigned int sg_len; |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 315 | size_t buflen; |
| 316 | struct scatterlist *sg; |
| 317 | int i; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 318 | |
| 319 | if (!mq->bounce_buf) |
| 320 | return blk_rq_map_sg(mq->queue, mq->req, mq->sg); |
| 321 | |
| 322 | BUG_ON(!mq->bounce_sg); |
| 323 | |
| 324 | sg_len = blk_rq_map_sg(mq->queue, mq->req, mq->bounce_sg); |
| 325 | |
| 326 | mq->bounce_sg_len = sg_len; |
| 327 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 328 | buflen = 0; |
| 329 | for_each_sg(mq->bounce_sg, sg, sg_len, i) |
| 330 | buflen += sg->length; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 331 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 332 | sg_init_one(mq->sg, mq->bounce_buf, buflen); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 333 | |
| 334 | return 1; |
| 335 | } |
| 336 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 337 | /* |
| 338 | * If writing, bounce the data to the buffer before the request |
| 339 | * is sent to the host driver |
| 340 | */ |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 341 | void mmc_queue_bounce_pre(struct mmc_queue *mq) |
| 342 | { |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 343 | unsigned long flags; |
| 344 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 345 | if (!mq->bounce_buf) |
| 346 | return; |
| 347 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 348 | if (rq_data_dir(mq->req) != WRITE) |
| 349 | return; |
| 350 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 351 | local_irq_save(flags); |
| 352 | sg_copy_to_buffer(mq->bounce_sg, mq->bounce_sg_len, |
| 353 | mq->bounce_buf, mq->sg[0].length); |
| 354 | local_irq_restore(flags); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 357 | /* |
| 358 | * If reading, bounce the data from the buffer after the request |
| 359 | * has been handled by the host driver |
| 360 | */ |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 361 | void mmc_queue_bounce_post(struct mmc_queue *mq) |
| 362 | { |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 363 | unsigned long flags; |
| 364 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 365 | if (!mq->bounce_buf) |
| 366 | return; |
| 367 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 368 | if (rq_data_dir(mq->req) != READ) |
| 369 | return; |
| 370 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 371 | local_irq_save(flags); |
| 372 | sg_copy_from_buffer(mq->bounce_sg, mq->bounce_sg_len, |
| 373 | mq->bounce_buf, mq->sg[0].length); |
| 374 | local_irq_restore(flags); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 375 | } |
| 376 | |