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 | /* |
| 33 | * We only like normal block requests. |
| 34 | */ |
Pierre Ossman | d6d8de3 | 2008-08-16 20:43:48 +0200 | [diff] [blame] | 35 | if (!blk_fs_request(req)) { |
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); |
Pierre Ossman | 9102895 | 2008-08-16 21:15:50 +0200 | [diff] [blame] | 131 | blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN, NULL); |
Pierre Ossman | 8dddfe1 | 2008-10-14 20:04:46 +0200 | [diff] [blame] | 132 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 133 | |
| 134 | #ifdef CONFIG_MMC_BLOCK_BOUNCE |
| 135 | if (host->max_hw_segs == 1) { |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 136 | unsigned int bouncesz; |
| 137 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 138 | bouncesz = MMC_QUEUE_BOUNCESZ; |
| 139 | |
| 140 | if (bouncesz > host->max_req_size) |
| 141 | bouncesz = host->max_req_size; |
| 142 | if (bouncesz > host->max_seg_size) |
| 143 | bouncesz = host->max_seg_size; |
Pierre Ossman | f3eb0aa | 2008-08-16 21:34:02 +0200 | [diff] [blame] | 144 | if (bouncesz > (host->max_blk_count * 512)) |
| 145 | bouncesz = host->max_blk_count * 512; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 146 | |
Pierre Ossman | f3eb0aa | 2008-08-16 21:34:02 +0200 | [diff] [blame] | 147 | if (bouncesz > 512) { |
| 148 | mq->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); |
| 149 | if (!mq->bounce_buf) { |
| 150 | printk(KERN_WARNING "%s: unable to " |
| 151 | "allocate bounce buffer\n", |
| 152 | mmc_card_name(card)); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (mq->bounce_buf) { |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 157 | blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY); |
Martin K. Petersen | 086fa5f | 2010-02-26 00:20:38 -0500 | [diff] [blame] | 158 | blk_queue_max_hw_sectors(mq->queue, bouncesz / 512); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 159 | blk_queue_max_segments(mq->queue, bouncesz / 512); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 160 | blk_queue_max_segment_size(mq->queue, bouncesz); |
| 161 | |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 162 | mq->sg = kmalloc(sizeof(struct scatterlist), |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 163 | GFP_KERNEL); |
| 164 | if (!mq->sg) { |
| 165 | ret = -ENOMEM; |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 166 | goto cleanup_queue; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 167 | } |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 168 | sg_init_table(mq->sg, 1); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 169 | |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 170 | mq->bounce_sg = kmalloc(sizeof(struct scatterlist) * |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 171 | bouncesz / 512, GFP_KERNEL); |
| 172 | if (!mq->bounce_sg) { |
| 173 | ret = -ENOMEM; |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 174 | goto cleanup_queue; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 175 | } |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 176 | sg_init_table(mq->bounce_sg, bouncesz / 512); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | #endif |
| 180 | |
| 181 | if (!mq->bounce_buf) { |
| 182 | blk_queue_bounce_limit(mq->queue, limit); |
Martin K. Petersen | 086fa5f | 2010-02-26 00:20:38 -0500 | [diff] [blame] | 183 | blk_queue_max_hw_sectors(mq->queue, |
Pierre Ossman | f3eb0aa | 2008-08-16 21:34:02 +0200 | [diff] [blame] | 184 | min(host->max_blk_count, host->max_req_size / 512)); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 185 | blk_queue_max_segments(mq->queue, host->max_hw_segs); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 186 | blk_queue_max_segment_size(mq->queue, host->max_seg_size); |
| 187 | |
Haavard Skinnemoen | 05e5b13 | 2007-11-23 10:19:00 +0100 | [diff] [blame] | 188 | mq->sg = kmalloc(sizeof(struct scatterlist) * |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 189 | host->max_phys_segs, GFP_KERNEL); |
| 190 | if (!mq->sg) { |
| 191 | ret = -ENOMEM; |
| 192 | goto cleanup_queue; |
| 193 | } |
Haavard Skinnemoen | 05e5b13 | 2007-11-23 10:19:00 +0100 | [diff] [blame] | 194 | sg_init_table(mq->sg, host->max_phys_segs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | init_MUTEX(&mq->thread_sem); |
| 198 | |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 199 | mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd"); |
| 200 | if (IS_ERR(mq->thread)) { |
| 201 | ret = PTR_ERR(mq->thread); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 202 | goto free_bounce_sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 205 | return 0; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 206 | free_bounce_sg: |
| 207 | if (mq->bounce_sg) |
| 208 | kfree(mq->bounce_sg); |
| 209 | mq->bounce_sg = NULL; |
Pierre Ossman | aafabfa | 2007-08-09 14:28:02 +0200 | [diff] [blame] | 210 | cleanup_queue: |
| 211 | if (mq->sg) |
| 212 | kfree(mq->sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | mq->sg = NULL; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 214 | if (mq->bounce_buf) |
| 215 | kfree(mq->bounce_buf); |
| 216 | mq->bounce_buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | blk_cleanup_queue(mq->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return ret; |
| 219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | void mmc_cleanup_queue(struct mmc_queue *mq) |
| 222 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 223 | struct request_queue *q = mq->queue; |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 224 | unsigned long flags; |
| 225 | |
Pierre Ossman | d2b46f6 | 2007-04-28 16:52:12 +0200 | [diff] [blame] | 226 | /* Make sure the queue isn't suspended, as that will deadlock */ |
| 227 | mmc_queue_resume(mq); |
| 228 | |
Pierre Ossman | 89b4e13 | 2006-11-14 22:08:16 +0100 | [diff] [blame] | 229 | /* Then terminate our worker thread */ |
Christoph Hellwig | 87598a2 | 2006-11-13 20:23:52 +0100 | [diff] [blame] | 230 | kthread_stop(mq->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 232 | /* Empty the queue */ |
| 233 | spin_lock_irqsave(q->queue_lock, flags); |
| 234 | q->queuedata = NULL; |
| 235 | blk_start_queue(q); |
| 236 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 237 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 238 | if (mq->bounce_sg) |
| 239 | kfree(mq->bounce_sg); |
| 240 | mq->bounce_sg = NULL; |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | kfree(mq->sg); |
| 243 | mq->sg = NULL; |
| 244 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 245 | if (mq->bounce_buf) |
| 246 | kfree(mq->bounce_buf); |
| 247 | mq->bounce_buf = NULL; |
| 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | mq->card = NULL; |
| 250 | } |
| 251 | EXPORT_SYMBOL(mmc_cleanup_queue); |
| 252 | |
| 253 | /** |
| 254 | * mmc_queue_suspend - suspend a MMC request queue |
| 255 | * @mq: MMC queue to suspend |
| 256 | * |
| 257 | * Stop the block request queue, and wait for our thread to |
| 258 | * complete any outstanding requests. This ensures that we |
| 259 | * won't suspend while a request is being processed. |
| 260 | */ |
| 261 | void mmc_queue_suspend(struct mmc_queue *mq) |
| 262 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 263 | struct request_queue *q = mq->queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | unsigned long flags; |
| 265 | |
| 266 | if (!(mq->flags & MMC_QUEUE_SUSPENDED)) { |
| 267 | mq->flags |= MMC_QUEUE_SUSPENDED; |
| 268 | |
| 269 | spin_lock_irqsave(q->queue_lock, flags); |
| 270 | blk_stop_queue(q); |
| 271 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 272 | |
| 273 | down(&mq->thread_sem); |
| 274 | } |
| 275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * mmc_queue_resume - resume a previously suspended MMC request queue |
| 279 | * @mq: MMC queue to resume |
| 280 | */ |
| 281 | void mmc_queue_resume(struct mmc_queue *mq) |
| 282 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 283 | struct request_queue *q = mq->queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | unsigned long flags; |
| 285 | |
| 286 | if (mq->flags & MMC_QUEUE_SUSPENDED) { |
| 287 | mq->flags &= ~MMC_QUEUE_SUSPENDED; |
| 288 | |
| 289 | up(&mq->thread_sem); |
| 290 | |
| 291 | spin_lock_irqsave(q->queue_lock, flags); |
| 292 | blk_start_queue(q); |
| 293 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 294 | } |
| 295 | } |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 296 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 297 | /* |
| 298 | * Prepare the sg list(s) to be handed of to the host driver |
| 299 | */ |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 300 | unsigned int mmc_queue_map_sg(struct mmc_queue *mq) |
| 301 | { |
| 302 | unsigned int sg_len; |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 303 | size_t buflen; |
| 304 | struct scatterlist *sg; |
| 305 | int i; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 306 | |
| 307 | if (!mq->bounce_buf) |
| 308 | return blk_rq_map_sg(mq->queue, mq->req, mq->sg); |
| 309 | |
| 310 | BUG_ON(!mq->bounce_sg); |
| 311 | |
| 312 | sg_len = blk_rq_map_sg(mq->queue, mq->req, mq->bounce_sg); |
| 313 | |
| 314 | mq->bounce_sg_len = sg_len; |
| 315 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 316 | buflen = 0; |
| 317 | for_each_sg(mq->bounce_sg, sg, sg_len, i) |
| 318 | buflen += sg->length; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 319 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 320 | sg_init_one(mq->sg, mq->bounce_buf, buflen); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 321 | |
| 322 | return 1; |
| 323 | } |
| 324 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 325 | /* |
| 326 | * If writing, bounce the data to the buffer before the request |
| 327 | * is sent to the host driver |
| 328 | */ |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 329 | void mmc_queue_bounce_pre(struct mmc_queue *mq) |
| 330 | { |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 331 | unsigned long flags; |
| 332 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 333 | if (!mq->bounce_buf) |
| 334 | return; |
| 335 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 336 | if (rq_data_dir(mq->req) != WRITE) |
| 337 | return; |
| 338 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 339 | local_irq_save(flags); |
| 340 | sg_copy_to_buffer(mq->bounce_sg, mq->bounce_sg_len, |
| 341 | mq->bounce_buf, mq->sg[0].length); |
| 342 | local_irq_restore(flags); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 345 | /* |
| 346 | * If reading, bounce the data from the buffer after the request |
| 347 | * has been handled by the host driver |
| 348 | */ |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 349 | void mmc_queue_bounce_post(struct mmc_queue *mq) |
| 350 | { |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 351 | unsigned long flags; |
| 352 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 353 | if (!mq->bounce_buf) |
| 354 | return; |
| 355 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 356 | if (rq_data_dir(mq->req) != READ) |
| 357 | return; |
| 358 | |
Pierre Ossman | 2ff1fa6 | 2008-07-22 14:35:42 +0200 | [diff] [blame] | 359 | local_irq_save(flags); |
| 360 | sg_copy_from_buffer(mq->bounce_sg, mq->bounce_sg_len, |
| 361 | mq->bounce_buf, mq->sg[0].length); |
| 362 | local_irq_restore(flags); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 363 | } |
| 364 | |