drivers/scsi/scsi_lib.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_lib.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_lib.c- Extension
.c- Size
- 96428 bytes
- Lines
- 3602
- Domain
- Driver Families
- Bucket
- drivers/scsi
- 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/bio.hlinux/bitops.hlinux/blkdev.hlinux/completion.hlinux/ctype.hlinux/kernel.hlinux/export.hlinux/init.hlinux/pci.hlinux/delay.hlinux/hardirq.hlinux/scatterlist.hlinux/blk-mq.hlinux/blk-integrity.hlinux/ratelimit.hlinux/unaligned.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_dbg.hscsi/scsi_device.hscsi/scsi_driver.hscsi/scsi_eh.hscsi/scsi_host.hscsi/scsi_transport.hscsi/scsi_dh.htrace/events/scsi.hscsi_debugfs.hscsi_priv.hscsi_logging.hscsi_lib_test.c
Detected Declarations
function scsi_init_sense_cachefunction scsi_set_blockedfunction stallfunction scsi_mq_requeue_cmdfunction scsi_queue_insertfunction scsi_queue_insertfunction scsi_failures_reset_retriesfunction scsi_check_passthroughfunction scsi_execute_cmdfunction scsi_eh_scmd_addfunction scsi_device_unbusyfunction scsi_kick_sdev_queuefunction scsi_single_lun_runfunction scsi_device_is_busyfunction scsi_target_is_busyfunction scsi_host_is_busyfunction scsi_starved_list_runfunction scsi_run_queuefunction scsi_requeue_run_queuefunction scsi_run_host_queuesfunction scsi_uninit_cmdfunction scsi_free_sgtablesfunction scsi_mq_uninit_cmdfunction scsi_run_queue_asyncfunction scsi_end_requestfunction scsi_result_to_blk_statusfunction scsi_rq_err_bytesfunction scsi_cmd_runtime_exceecedfunction scsi_io_completion_actionfunction scsi_log_completionfunction scsi_io_completionfunction cachefunction scsi_io_completionfunction scsi_cmd_needs_dma_drainfunction scsi_alloc_sgtablesfunction scsi_initialize_rqfunction scsi_cleanup_rqfunction scsi_init_commandfunction scsi_setup_scsi_cmndfunction scsi_device_state_checkfunction scsi_dev_queue_readyfunction atomic_dec_returnfunction scsi_target_queue_readyfunction scsi_host_queue_readyfunction scsi_mq_lld_busyfunction scsi_completefunction scsi_dispatch_cmdfunction scsi_mq_inline_sgl_size
Annotated Snippet
static const struct blk_mq_ops scsi_mq_ops_no_commit = {
.get_budget = scsi_mq_get_budget,
.put_budget = scsi_mq_put_budget,
.queue_rq = scsi_queue_rq,
.complete = scsi_complete,
.timeout = scsi_timeout,
#ifdef CONFIG_BLK_DEBUG_FS
.show_rq = scsi_show_rq,
#endif
.init_request = scsi_mq_init_request,
.exit_request = scsi_mq_exit_request,
.cleanup_rq = scsi_cleanup_rq,
.busy = scsi_mq_lld_busy,
.map_queues = scsi_map_queues,
.init_hctx = scsi_init_hctx,
.poll = scsi_mq_poll,
.set_rq_budget_token = scsi_mq_set_rq_budget_token,
.get_rq_budget_token = scsi_mq_get_rq_budget_token,
};
static void scsi_commit_rqs(struct blk_mq_hw_ctx *hctx)
{
struct Scsi_Host *shost = hctx->driver_data;
shost->hostt->commit_rqs(shost, hctx->queue_num);
}
static const struct blk_mq_ops scsi_mq_ops = {
.get_budget = scsi_mq_get_budget,
.put_budget = scsi_mq_put_budget,
.queue_rq = scsi_queue_rq,
.commit_rqs = scsi_commit_rqs,
.complete = scsi_complete,
.timeout = scsi_timeout,
#ifdef CONFIG_BLK_DEBUG_FS
.show_rq = scsi_show_rq,
#endif
.init_request = scsi_mq_init_request,
.exit_request = scsi_mq_exit_request,
.cleanup_rq = scsi_cleanup_rq,
.busy = scsi_mq_lld_busy,
.map_queues = scsi_map_queues,
.init_hctx = scsi_init_hctx,
.poll = scsi_mq_poll,
.set_rq_budget_token = scsi_mq_set_rq_budget_token,
.get_rq_budget_token = scsi_mq_get_rq_budget_token,
};
int scsi_mq_setup_tags(struct Scsi_Host *shost)
{
unsigned int cmd_size, sgl_size;
struct blk_mq_tag_set *tag_set = &shost->tag_set;
sgl_size = max_t(unsigned int, sizeof(struct scatterlist),
scsi_mq_inline_sgl_size(shost));
cmd_size = sizeof(struct scsi_cmnd) + shost->hostt->cmd_size + sgl_size;
if (scsi_host_get_prot(shost))
cmd_size += sizeof(struct scsi_data_buffer) +
sizeof(struct scatterlist) * SCSI_INLINE_PROT_SG_CNT;
memset(tag_set, 0, sizeof(*tag_set));
if (shost->hostt->commit_rqs)
tag_set->ops = &scsi_mq_ops;
else
tag_set->ops = &scsi_mq_ops_no_commit;
tag_set->nr_hw_queues = shost->nr_hw_queues ? : 1;
tag_set->nr_maps = shost->nr_maps ? : 1;
tag_set->queue_depth = shost->can_queue + shost->nr_reserved_cmds;
tag_set->reserved_tags = shost->nr_reserved_cmds;
tag_set->cmd_size = cmd_size;
tag_set->numa_node = dev_to_node(shost->dma_dev);
if (shost->hostt->tag_alloc_policy_rr)
tag_set->flags |= BLK_MQ_F_TAG_RR;
if (shost->queuecommand_may_block)
tag_set->flags |= BLK_MQ_F_BLOCKING;
tag_set->driver_data = shost;
if (shost->host_tagset)
tag_set->flags |= BLK_MQ_F_TAG_HCTX_SHARED;
return blk_mq_alloc_tag_set(tag_set);
}
void scsi_mq_free_tags(struct kref *kref)
{
struct Scsi_Host *shost = container_of(kref, typeof(*shost),
tagset_refcnt);
blk_mq_free_tag_set(&shost->tag_set);
complete(&shost->tagset_freed);
Annotation
- Immediate include surface: `linux/bio.h`, `linux/bitops.h`, `linux/blkdev.h`, `linux/completion.h`, `linux/ctype.h`, `linux/kernel.h`, `linux/export.h`, `linux/init.h`.
- Detected declarations: `function scsi_init_sense_cache`, `function scsi_set_blocked`, `function stall`, `function scsi_mq_requeue_cmd`, `function scsi_queue_insert`, `function scsi_queue_insert`, `function scsi_failures_reset_retries`, `function scsi_check_passthrough`, `function scsi_execute_cmd`, `function scsi_eh_scmd_add`.
- Atlas domain: Driver Families / drivers/scsi.
- 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.