drivers/memstick/core/mspro_block.c
Source file repositories/reference/linux-study-clean/drivers/memstick/core/mspro_block.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/memstick/core/mspro_block.c- Extension
.c- Size
- 38010 bytes
- Lines
- 1399
- Domain
- Driver Families
- Bucket
- drivers/memstick
- 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.
- 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/blk-mq.hlinux/idr.hlinux/hdreg.hlinux/kthread.hlinux/delay.hlinux/slab.hlinux/mutex.hlinux/memstick.hlinux/module.h
Detected Declarations
struct mspro_sys_attrstruct mspro_attr_entrystruct mspro_attributestruct mspro_sys_infostruct mspro_mbrstruct mspro_specfilestruct mspro_devinfostruct mspro_block_datafunction mspro_block_bd_free_diskfunction mspro_block_bd_getgeofunction mspro_block_attr_show_defaultfunction mspro_block_attr_show_sysinfofunction mspro_block_attr_show_modelnamefunction mspro_block_attr_show_mbrfunction mspro_block_attr_show_specfilefunction mspro_block_attr_show_devinfofunction mspro_block_attr_showfunction finishedfunction h_mspro_block_defaultfunction h_mspro_block_default_badfunction h_mspro_block_get_rofunction h_mspro_block_wait_for_cedfunction h_mspro_block_transfer_datafunction h_mspro_block_setup_cmdfunction mspro_block_issue_reqfunction mspro_block_complete_reqfunction mspro_block_stopfunction mspro_block_startfunction mspro_queue_rqfunction mspro_block_wait_for_cedfunction mspro_block_set_interfacefunction mspro_block_switch_interfacefunction mspro_block_read_attributesfunction mspro_block_init_cardfunction mspro_block_init_diskfunction mspro_block_data_clearfunction mspro_block_check_cardfunction mspro_block_probefunction mspro_block_removefunction mspro_block_suspendfunction mspro_block_resumefunction mspro_block_initfunction mspro_block_exitmodule init mspro_block_init
Annotated Snippet
static const struct blk_mq_ops mspro_mq_ops = {
.queue_rq = mspro_queue_rq,
};
static int mspro_block_init_disk(struct memstick_dev *card)
{
struct mspro_block_data *msb = memstick_get_drvdata(card);
struct queue_limits lim = {
.logical_block_size = msb->page_size,
.max_hw_sectors = MSPRO_BLOCK_MAX_PAGES,
.max_segments = MSPRO_BLOCK_MAX_SEGS,
.max_segment_size = MSPRO_BLOCK_MAX_PAGES * msb->page_size,
};
struct mspro_devinfo *dev_info = NULL;
struct mspro_sys_info *sys_info = NULL;
struct mspro_sys_attr *s_attr = NULL;
int rc, disk_id;
unsigned long capacity;
for (rc = 0; msb->attr_group.attrs[rc]; ++rc) {
s_attr = mspro_from_sysfs_attr(msb->attr_group.attrs[rc]);
if (s_attr->id == MSPRO_BLOCK_ID_DEVINFO)
dev_info = s_attr->data;
else if (s_attr->id == MSPRO_BLOCK_ID_SYSINFO)
sys_info = s_attr->data;
}
if (!dev_info || !sys_info)
return -ENODEV;
msb->cylinders = be16_to_cpu(dev_info->cylinders);
msb->heads = be16_to_cpu(dev_info->heads);
msb->sectors_per_track = be16_to_cpu(dev_info->sectors_per_track);
msb->page_size = be16_to_cpu(sys_info->unit_size);
mutex_lock(&mspro_block_disk_lock);
disk_id = idr_alloc(&mspro_block_disk_idr, card, 0, 256, GFP_KERNEL);
mutex_unlock(&mspro_block_disk_lock);
if (disk_id < 0)
return disk_id;
rc = blk_mq_alloc_sq_tag_set(&msb->tag_set, &mspro_mq_ops, 2, 0);
if (rc)
goto out_release_id;
msb->disk = blk_mq_alloc_disk(&msb->tag_set, &lim, card);
if (IS_ERR(msb->disk)) {
rc = PTR_ERR(msb->disk);
goto out_free_tag_set;
}
msb->queue = msb->disk->queue;
msb->disk->major = major;
msb->disk->first_minor = disk_id << MSPRO_BLOCK_PART_SHIFT;
msb->disk->minors = 1 << MSPRO_BLOCK_PART_SHIFT;
msb->disk->fops = &ms_block_bdops;
msb->disk->private_data = msb;
sprintf(msb->disk->disk_name, "mspblk%d", disk_id);
capacity = be16_to_cpu(sys_info->user_block_count);
capacity *= be16_to_cpu(sys_info->block_size);
capacity *= msb->page_size >> 9;
set_capacity(msb->disk, capacity);
dev_dbg(&card->dev, "capacity set %ld\n", capacity);
if (msb->read_only)
set_disk_ro(msb->disk, true);
rc = device_add_disk(&card->dev, msb->disk, NULL);
if (rc)
goto out_cleanup_disk;
msb->active = 1;
return 0;
out_cleanup_disk:
put_disk(msb->disk);
out_free_tag_set:
blk_mq_free_tag_set(&msb->tag_set);
out_release_id:
mutex_lock(&mspro_block_disk_lock);
idr_remove(&mspro_block_disk_idr, disk_id);
mutex_unlock(&mspro_block_disk_lock);
return rc;
}
static void mspro_block_data_clear(struct mspro_block_data *msb)
{
Annotation
- Immediate include surface: `linux/blk-mq.h`, `linux/idr.h`, `linux/hdreg.h`, `linux/kthread.h`, `linux/delay.h`, `linux/slab.h`, `linux/mutex.h`, `linux/memstick.h`.
- Detected declarations: `struct mspro_sys_attr`, `struct mspro_attr_entry`, `struct mspro_attribute`, `struct mspro_sys_info`, `struct mspro_mbr`, `struct mspro_specfile`, `struct mspro_devinfo`, `struct mspro_block_data`, `function mspro_block_bd_free_disk`, `function mspro_block_bd_getgeo`.
- Atlas domain: Driver Families / drivers/memstick.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.