drivers/scsi/sd.c
Source file repositories/reference/linux-study-clean/drivers/scsi/sd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/sd.c- Extension
.c- Size
- 120719 bytes
- Lines
- 4524
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/bio-integrity.hlinux/module.hlinux/fs.hlinux/kernel.hlinux/mm.hlinux/hdreg.hlinux/errno.hlinux/idr.hlinux/interrupt.hlinux/init.hlinux/blkdev.hlinux/blkpg.hlinux/blk-pm.hlinux/delay.hlinux/rw_hint.hlinux/major.hlinux/mutex.hlinux/string_helpers.hlinux/slab.hlinux/sed-opal.hlinux/pm_runtime.hlinux/pr.hlinux/t10-pi.hlinux/uaccess.hlinux/unaligned.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_dbg.hscsi/scsi_device.hscsi/scsi_devinfo.hscsi/scsi_driver.hscsi/scsi_eh.h
Detected Declarations
function sd_large_pool_createfunction sd_large_pool_destroyfunction sd_disable_discardfunction sd_config_discardfunction sd_set_flush_flagfunction cache_type_storefunction manage_start_stop_showfunction manage_system_start_stop_showfunction manage_system_start_stop_storefunction manage_runtime_start_stop_showfunction manage_runtime_start_stop_storefunction manage_shutdown_showfunction manage_shutdown_storefunction manage_restart_showfunction manage_restart_storefunction allow_restart_showfunction allow_restart_storefunction cache_type_showfunction FUA_showfunction protection_type_showfunction protection_type_storefunction protection_mode_showfunction app_tag_own_showfunction thin_provisioning_showfunction provisioning_mode_showfunction provisioning_mode_storefunction zeroing_mode_showfunction zeroing_mode_storefunction max_medium_access_timeouts_showfunction max_medium_access_timeouts_storefunction max_write_same_blocks_showfunction max_write_same_blocks_storefunction zoned_cap_showfunction max_retries_storefunction max_retries_showfunction scsi_disk_releasefunction sd_default_probefunction sd_sec_submitfunction sd_prot_opfunction sd_prot_flag_maskfunction sd_setup_protect_cmndfunction sd_setup_unmap_cmndfunction sd_config_atomicfunction sd_setup_write_same16_cmndfunction sd_setup_write_same10_cmndfunction sd_setup_write_zeroes_cmndfunction sd_disable_write_samefunction sd_config_write_same
Annotated Snippet
error = device_add(&sdkp->disk_dev);
if (error) {
put_device(&sdkp->disk_dev);
put_disk(gd);
goto out;
}
dev_set_drvdata(dev, sdkp);
gd->major = sd_major((index & 0xf0) >> 4);
gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00);
gd->minors = SD_MINORS;
gd->fops = &sd_fops;
gd->private_data = sdkp;
/* defaults, until the device tells us otherwise */
sdp->sector_size = 512;
sdkp->capacity = 0;
sdkp->media_present = 1;
sdkp->write_prot = 0;
sdkp->cache_override = 0;
sdkp->WCE = 0;
sdkp->RCD = 0;
sdkp->ATO = 0;
sdkp->first_scan = 1;
sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS;
sd_revalidate_disk(gd);
if (sdp->sector_size > PAGE_SIZE) {
if (sd_large_pool_create()) {
error = -ENOMEM;
goto out_free_index;
}
}
if (sdp->removable) {
gd->flags |= GENHD_FL_REMOVABLE;
gd->events |= DISK_EVENT_MEDIA_CHANGE;
gd->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT;
}
blk_pm_runtime_init(sdp->request_queue, dev);
if (sdp->rpm_autosuspend) {
pm_runtime_set_autosuspend_delay(dev,
sdp->host->rpm_autosuspend_delay);
}
error = device_add_disk(dev, gd, NULL);
if (error) {
device_unregister(&sdkp->disk_dev);
put_disk(gd);
if (sdp->sector_size > PAGE_SIZE)
sd_large_pool_destroy();
goto out;
}
if (sdkp->security) {
sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit);
if (sdkp->opal_dev)
sd_printk(KERN_NOTICE, sdkp, "supports TCG Opal\n");
}
sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n",
sdp->removable ? "removable " : "");
scsi_autopm_put_device(sdp);
return 0;
out_free_index:
ida_free(&sd_index_ida, index);
out_put:
put_disk(gd);
out_free:
kfree(sdkp);
out:
scsi_autopm_put_device(sdp);
return error;
}
static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
{
unsigned char cmd[6] = { START_STOP }; /* START_VALID */
struct scsi_sense_hdr sshdr;
struct scsi_failure failure_defs[] = {
{
/* Power on, reset, or bus device reset occurred */
.sense = UNIT_ATTENTION,
.asc = 0x29,
.ascq = 0,
Annotation
- Immediate include surface: `linux/bio-integrity.h`, `linux/module.h`, `linux/fs.h`, `linux/kernel.h`, `linux/mm.h`, `linux/hdreg.h`, `linux/errno.h`, `linux/idr.h`.
- Detected declarations: `function sd_large_pool_create`, `function sd_large_pool_destroy`, `function sd_disable_discard`, `function sd_config_discard`, `function sd_set_flush_flag`, `function cache_type_store`, `function manage_start_stop_show`, `function manage_system_start_stop_show`, `function manage_system_start_stop_store`, `function manage_runtime_start_stop_show`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: integration 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.