drivers/mmc/core/queue.c
Source file repositories/reference/linux-study-clean/drivers/mmc/core/queue.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mmc/core/queue.c- Extension
.c- Size
- 13480 bytes
- Lines
- 539
- Domain
- Driver Families
- Bucket
- drivers/mmc
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/module.hlinux/blkdev.hlinux/freezer.hlinux/scatterlist.hlinux/dma-mapping.hlinux/backing-dev.hlinux/mmc/card.hlinux/mmc/host.hqueue.hblock.hcore.hcard.hcrypto.hhost.h
Detected Declarations
function Copyrightfunction mmc_cqe_check_busyfunction mmc_cqe_can_dcmdfunction mmc_cqe_issue_typefunction mmc_issue_typefunction __mmc_cqe_recovery_notifierfunction mmc_cqe_recovery_notifierfunction mmc_cqe_timed_outfunction mmc_mq_timed_outfunction mmc_mq_recovery_handlerfunction mmc_queue_setup_discardfunction mmc_get_max_segmentsfunction mmc_mq_init_requestfunction mmc_mq_exit_requestfunction mmc_mq_queue_rqfunction mmc_merge_capablefunction mmc_queue_suspendfunction mmc_queue_resumefunction mmc_cleanup_queuefunction list
Annotated Snippet
static const struct blk_mq_ops mmc_mq_ops = {
.queue_rq = mmc_mq_queue_rq,
.init_request = mmc_mq_init_request,
.exit_request = mmc_mq_exit_request,
.complete = mmc_blk_mq_complete,
.timeout = mmc_mq_timed_out,
};
static struct gendisk *mmc_alloc_disk(struct mmc_queue *mq,
struct mmc_card *card, unsigned int features)
{
struct mmc_host *host = card->host;
struct queue_limits lim = {
.features = features,
};
struct gendisk *disk;
if (mmc_card_can_erase(card))
mmc_queue_setup_discard(card, &lim);
lim.max_hw_sectors = min(host->max_blk_count, host->max_req_size / 512);
if (mmc_card_mmc(card) && card->ext_csd.data_sector_size)
lim.logical_block_size = card->ext_csd.data_sector_size;
else
lim.logical_block_size = 512;
WARN_ON_ONCE(lim.logical_block_size != 512 &&
lim.logical_block_size != 4096);
/*
* Setting a virt_boundary implicity sets a max_segment_size, so try
* to set the hardware one here.
*/
if (host->can_dma_map_merge) {
lim.virt_boundary_mask = dma_get_merge_boundary(mmc_dev(host));
lim.max_segments = MMC_DMA_MAP_MERGE_SEGMENTS;
} else {
lim.max_segment_size =
round_down(host->max_seg_size, lim.logical_block_size);
lim.max_segments = host->max_segs;
}
if (mmc_host_is_spi(host) && host->use_spi_crc)
lim.features |= BLK_FEAT_STABLE_WRITES;
disk = blk_mq_alloc_disk(&mq->tag_set, &lim, mq);
if (IS_ERR(disk))
return disk;
mq->queue = disk->queue;
blk_queue_rq_timeout(mq->queue, 60 * HZ);
if (mmc_dev(host)->dma_parms)
dma_set_max_seg_size(mmc_dev(host), queue_max_segment_size(mq->queue));
INIT_WORK(&mq->recovery_work, mmc_mq_recovery_handler);
INIT_WORK(&mq->complete_work, mmc_blk_mq_complete_work);
mutex_init(&mq->complete_lock);
init_waitqueue_head(&mq->wait);
mmc_crypto_setup_queue(mq->queue, host);
return disk;
}
static inline bool mmc_merge_capable(struct mmc_host *host)
{
return host->caps2 & MMC_CAP2_MERGE_CAPABLE;
}
/* Set queue depth to get a reasonable value for q->nr_requests */
#define MMC_QUEUE_DEPTH 64
/**
* mmc_init_queue - initialise a queue structure.
* @mq: mmc queue
* @card: mmc card to attach this queue
* @features: block layer features (BLK_FEAT_*)
*
* Initialise a MMC card request queue.
*/
struct gendisk *mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
unsigned int features)
{
struct mmc_host *host = card->host;
struct gendisk *disk;
int ret;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/module.h`, `linux/blkdev.h`, `linux/freezer.h`, `linux/scatterlist.h`, `linux/dma-mapping.h`, `linux/backing-dev.h`, `linux/mmc/card.h`.
- Detected declarations: `function Copyright`, `function mmc_cqe_check_busy`, `function mmc_cqe_can_dcmd`, `function mmc_cqe_issue_type`, `function mmc_issue_type`, `function __mmc_cqe_recovery_notifier`, `function mmc_cqe_recovery_notifier`, `function mmc_cqe_timed_out`, `function mmc_mq_timed_out`, `function mmc_mq_recovery_handler`.
- Atlas domain: Driver Families / drivers/mmc.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.