Release 4.15 drivers/mmc/core/queue.c
/*
* Copyright (C) 2003 Russell King, All Rights Reserved.
* Copyright 2006-2007 Pierre Ossman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/blkdev.h>
#include <linux/freezer.h>
#include <linux/kthread.h>
#include <linux/scatterlist.h>
#include <linux/dma-mapping.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include "queue.h"
#include "block.h"
#include "core.h"
#include "card.h"
/*
* Prepare a MMC request. This just filters out odd stuff.
*/
static int mmc_prep_request(struct request_queue *q, struct request *req)
{
struct mmc_queue *mq = q->queuedata;
if (mq && mmc_card_removed(mq->card))
return BLKPREP_KILL;
req->rq_flags |= RQF_DONTPREP;
return BLKPREP_OK;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sujit Reddy Thumma | 23 | 47.92% | 1 | 25.00% |
Russell King | 22 | 45.83% | 1 | 25.00% |
Christoph Hellwig | 2 | 4.17% | 1 | 25.00% |
Pierre Ossman | 1 | 2.08% | 1 | 25.00% |
Total | 48 | 100.00% | 4 | 100.00% |
static int mmc_queue_thread(void *d)
{
struct mmc_queue *mq = d;
struct request_queue *q = mq->queue;
struct mmc_context_info *cntx = &mq->card->host->context_info;
current->flags |= PF_MEMALLOC;
down(&mq->thread_sem);
do {
struct request *req;
spin_lock_irq(q->queue_lock);
set_current_state(TASK_INTERRUPTIBLE);
req = blk_fetch_request(q);
mq->asleep = false;
cntx->is_waiting_last_req = false;
cntx->is_new_req = false;
if (!req) {
/*
* Dispatch queue is empty so set flags for
* mmc_request_fn() to wake us up.
*/
if (mq->qcnt)
cntx->is_waiting_last_req = true;
else
mq->asleep = true;
}
spin_unlock_irq(q->queue_lock);
if (req || mq->qcnt) {
set_current_state(TASK_RUNNING);
mmc_blk_issue_rq(mq, req);
cond_resched();
} else {
if (kthread_should_stop()) {
set_current_state(TASK_RUNNING);
break;
}
up(&mq->thread_sem);
schedule();
down(&mq->thread_sem);
}
} while (1);
up(&mq->thread_sem);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 93 | 44.50% | 4 | 33.33% |
Adrian Hunter | 58 | 27.75% | 2 | 16.67% |
Seungwon Jeon | 36 | 17.22% | 1 | 8.33% |
Per Forlin | 15 | 7.18% | 1 | 8.33% |
Rabin Vincent | 3 | 1.44% | 1 | 8.33% |
Juha Yrjölä | 2 | 0.96% | 1 | 8.33% |
Tejun Heo | 1 | 0.48% | 1 | 8.33% |
Linus Walleij | 1 | 0.48% | 1 | 8.33% |
Total | 209 | 100.00% | 12 | 100.00% |
/*
* Generic MMC request handler. This is called for any queue on a
* particular host. When the host is not busy, we look for a request
* on any queue on this host, and attempt to issue it. This may
* not be the queue we were asked to process.
*/
static void mmc_request_fn(struct request_queue *q)
{
struct mmc_queue *mq = q->queuedata;
struct request *req;
struct mmc_context_info *cntx;
if (!mq) {
while ((req = blk_fetch_request(q)) != NULL) {
req->rq_flags |= RQF_QUIET;
__blk_end_request_all(req, BLK_STS_IOERR);
}
return;
}
cntx = &mq->card->host->context_info;
if (cntx->is_waiting_last_req) {
cntx->is_new_req = true;
wake_up_interruptible(&cntx->wait);
}
if (mq->asleep)
wake_up_process(mq->thread);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Konstantin Dorfman | 38 | 33.93% | 1 | 7.69% |
Pierre Ossman | 30 | 26.79% | 1 | 7.69% |
Russell King | 25 | 22.32% | 1 | 7.69% |
Adrian Hunter | 7 | 6.25% | 2 | 15.38% |
Christoph Hellwig | 5 | 4.46% | 3 | 23.08% |
Tejun Heo | 2 | 1.79% | 2 | 15.38% |
Per Forlin | 2 | 1.79% | 1 | 7.69% |
Jens Axboe | 2 | 1.79% | 1 | 7.69% |
Venkatraman Sathiyamoorthy | 1 | 0.89% | 1 | 7.69% |
Total | 112 | 100.00% | 13 | 100.00% |
static struct scatterlist *mmc_alloc_sg(int sg_len, gfp_t gfp)
{
struct scatterlist *sg;
sg = kmalloc_array(sg_len, sizeof(*sg), gfp);
if (sg)
sg_init_table(sg, sg_len);
return sg;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Per Forlin | 38 | 79.17% | 1 | 25.00% |
SF Markus Elfring | 5 | 10.42% | 1 | 25.00% |
Linus Walleij | 4 | 8.33% | 1 | 25.00% |
Venkatraman Sathiyamoorthy | 1 | 2.08% | 1 | 25.00% |
Total | 48 | 100.00% | 4 | 100.00% |
static void mmc_queue_setup_discard(struct request_queue *q,
struct mmc_card *card)
{
unsigned max_discard;
max_discard = mmc_calc_max_discard(card);
if (!max_discard)
return;
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
blk_queue_max_discard_sectors(q, max_discard);
q->limits.discard_granularity = card->pref_erase << 9;
/* granularity must not be greater than max. discard */
if (card->pref_erase > max_discard)
q->limits.discard_granularity = 0;
if (mmc_can_secure_erase_trim(card))
queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Adrian Hunter | 84 | 94.38% | 1 | 33.33% |
Jens Axboe | 4 | 4.49% | 1 | 33.33% |
Christoph Hellwig | 1 | 1.12% | 1 | 33.33% |
Total | 89 | 100.00% | 3 | 100.00% |
/**
* mmc_init_request() - initialize the MMC-specific per-request data
* @q: the request queue
* @req: the request
* @gfp: memory allocation policy
*/
static int mmc_init_request(struct request_queue *q, struct request *req,
gfp_t gfp)
{
struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req);
struct mmc_queue *mq = q->queuedata;
struct mmc_card *card = mq->card;
struct mmc_host *host = card->host;
mq_rq->sg = mmc_alloc_sg(host->max_segs, gfp);
if (!mq_rq->sg)
return -ENOMEM;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Adrian Hunter | 50 | 60.24% | 5 | 83.33% |
Linus Walleij | 33 | 39.76% | 1 | 16.67% |
Total | 83 | 100.00% | 6 | 100.00% |
static void mmc_exit_request(struct request_queue *q, struct request *req)
{
struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req);
kfree(mq_rq->sg);
mq_rq->sg = NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Walleij | 31 | 79.49% | 1 | 33.33% |
Adrian Hunter | 8 | 20.51% | 2 | 66.67% |
Total | 39 | 100.00% | 3 | 100.00% |
static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
{
struct mmc_host *host = card->host;
u64 limit = BLK_BOUNCE_HIGH;
if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue);
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, mq->queue);
if (mmc_can_erase(card))
mmc_queue_setup_discard(mq->queue, card);
blk_queue_bounce_limit(mq->queue, limit);
blk_queue_max_hw_sectors(mq->queue,
min(host->max_blk_count, host->max_req_size / 512));
blk_queue_max_segments(mq->queue, host->max_segs);
blk_queue_max_segment_size(mq->queue, host->max_seg_size);
/* Initialize thread_sem even if it is not used */
sema_init(&mq->thread_sem, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Adrian Hunter | 100 | 63.29% | 1 | 14.29% |
Russell King | 44 | 27.85% | 4 | 57.14% |
Greg Kroah-Hartman | 9 | 5.70% | 1 | 14.29% |
Santosh Shilimkar | 5 | 3.16% | 1 | 14.29% |
Total | 158 | 100.00% | 7 | 100.00% |
/**
* mmc_init_queue - initialise a queue structure.
* @mq: mmc queue
* @card: mmc card to attach this queue
* @lock: queue lock
* @subname: partition subname
*
* Initialise a MMC card request queue.
*/
int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
spinlock_t *lock, const char *subname)
{
struct mmc_host *host = card->host;
int ret = -ENOMEM;
mq->card = card;
mq->queue = blk_alloc_queue(GFP_KERNEL);
if (!mq->queue)
return -ENOMEM;
mq->queue->queue_lock = lock;
mq->queue->request_fn = mmc_request_fn;
mq->queue->init_rq_fn = mmc_init_request;
mq->queue->exit_rq_fn = mmc_exit_request;
mq->queue->cmd_size = sizeof(struct mmc_queue_req);
mq->queue->queuedata = mq;
mq->qcnt = 0;
ret = blk_init_allocated_queue(mq->queue);
if (ret) {
blk_cleanup_queue(mq->queue);
return ret;
}
blk_queue_prep_rq(mq->queue, mmc_prep_request);
mmc_setup_queue(mq, card);
mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd/%d%s",
host->index, subname ? subname : "");
if (IS_ERR(mq->thread)) {
ret = PTR_ERR(mq->thread);
goto cleanup_queue;
}
return 0;
cleanup_queue:
blk_cleanup_queue(mq->queue);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 68 | 30.22% | 3 | 17.65% |
Linus Walleij | 61 | 27.11% | 1 | 5.88% |
Adrian Hunter | 54 | 24.00% | 5 | 29.41% |
Christoph Hellwig | 15 | 6.67% | 1 | 5.88% |
Pierre Ossman | 12 | 5.33% | 3 | 17.65% |
Per Forlin | 10 | 4.44% | 2 | 11.76% |
Ethan Du | 4 | 1.78% | 1 | 5.88% |
Mike Snitzer | 1 | 0.44% | 1 | 5.88% |
Total | 225 | 100.00% | 17 | 100.00% |
void mmc_cleanup_queue(struct mmc_queue *mq)
{
struct request_queue *q = mq->queue;
unsigned long flags;
/* Make sure the queue isn't suspended, as that will deadlock */
mmc_queue_resume(mq);
/* Then terminate our worker thread */
kthread_stop(mq->thread);
/* Empty the queue */
spin_lock_irqsave(q->queue_lock, flags);
q->queuedata = NULL;
blk_start_queue(q);
spin_unlock_irqrestore(q->queue_lock, flags);
mq->card = NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pierre Ossman | 27 | 36.99% | 1 | 16.67% |
Russell King | 22 | 30.14% | 2 | 33.33% |
Adrian Hunter | 22 | 30.14% | 2 | 33.33% |
Jens Axboe | 2 | 2.74% | 1 | 16.67% |
Total | 73 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(mmc_cleanup_queue);
/**
* mmc_queue_suspend - suspend a MMC request queue
* @mq: MMC queue to suspend
*
* Stop the block request queue, and wait for our thread to
* complete any outstanding requests. This ensures that we
* won't suspend while a request is being processed.
*/
void mmc_queue_suspend(struct mmc_queue *mq)
{
struct request_queue *q = mq->queue;
unsigned long flags;
if (!mq->suspended) {
mq->suspended |= true;
spin_lock_irqsave(q->queue_lock, flags);
blk_stop_queue(q);
spin_unlock_irqrestore(q->queue_lock, flags);
down(&mq->thread_sem);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 64 | 92.75% | 1 | 33.33% |
Linus Walleij | 3 | 4.35% | 1 | 33.33% |
Jens Axboe | 2 | 2.90% | 1 | 33.33% |
Total | 69 | 100.00% | 3 | 100.00% |
/**
* mmc_queue_resume - resume a previously suspended MMC request queue
* @mq: MMC queue to resume
*/
void mmc_queue_resume(struct mmc_queue *mq)
{
struct request_queue *q = mq->queue;
unsigned long flags;
if (mq->suspended) {
mq->suspended = false;
up(&mq->thread_sem);
spin_lock_irqsave(q->queue_lock, flags);
blk_start_queue(q);
spin_unlock_irqrestore(q->queue_lock, flags);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 62 | 91.18% | 1 | 33.33% |
Linus Walleij | 4 | 5.88% | 1 | 33.33% |
Jens Axboe | 2 | 2.94% | 1 | 33.33% |
Total | 68 | 100.00% | 3 | 100.00% |
/*
* Prepare the sg list(s) to be handed of to the host driver
*/
unsigned int mmc_queue_map_sg(struct mmc_queue *mq, struct mmc_queue_req *mqrq)
{
struct request *req = mmc_queue_req_to_req(mqrq);
return blk_rq_map_sg(mq->queue, req, mqrq->sg);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pierre Ossman | 24 | 60.00% | 1 | 33.33% |
Linus Walleij | 10 | 25.00% | 1 | 33.33% |
Per Forlin | 6 | 15.00% | 1 | 33.33% |
Total | 40 | 100.00% | 3 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 422 | 32.14% | 9 | 15.00% |
Adrian Hunter | 384 | 29.25% | 11 | 18.33% |
Linus Walleij | 151 | 11.50% | 4 | 6.67% |
Pierre Ossman | 97 | 7.39% | 7 | 11.67% |
Per Forlin | 71 | 5.41% | 3 | 5.00% |
Konstantin Dorfman | 38 | 2.89% | 1 | 1.67% |
Seungwon Jeon | 36 | 2.74% | 1 | 1.67% |
Christoph Hellwig | 26 | 1.98% | 4 | 6.67% |
Sujit Reddy Thumma | 23 | 1.75% | 1 | 1.67% |
Jens Axboe | 15 | 1.14% | 3 | 5.00% |
Greg Kroah-Hartman | 9 | 0.69% | 1 | 1.67% |
Santosh Shilimkar | 8 | 0.61% | 1 | 1.67% |
Ulf Hansson | 7 | 0.53% | 3 | 5.00% |
Tejun Heo | 6 | 0.46% | 3 | 5.00% |
SF Markus Elfring | 5 | 0.38% | 1 | 1.67% |
Ethan Du | 4 | 0.30% | 1 | 1.67% |
Rafael J. Wysocki | 3 | 0.23% | 1 | 1.67% |
Rabin Vincent | 3 | 0.23% | 1 | 1.67% |
Venkatraman Sathiyamoorthy | 2 | 0.15% | 2 | 3.33% |
Juha Yrjölä | 2 | 0.15% | 1 | 1.67% |
Mike Snitzer | 1 | 0.08% | 1 | 1.67% |
Total | 1313 | 100.00% | 60 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.