drivers/scsi/scsi_common.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_common.c- Extension
.c- Size
- 10378 bytes
- Lines
- 402
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bug.hlinux/kernel.hlinux/string.hlinux/errno.hlinux/module.huapi/linux/pr.hlinux/unaligned.hscsi/scsi_common.h
Detected Declarations
function scsi_pr_type_to_blockfunction block_pr_type_to_scsifunction scsilun_to_intfunction int_to_scsilunfunction scsi_normalize_sensefunction offunction scsi_build_sense_bufferfunction scsi_set_sense_informationfunction scsi_set_sense_field_pointerexport scsi_command_size_tblexport scsi_device_typeexport scsi_pr_type_to_blockexport block_pr_type_to_scsiexport scsilun_to_intexport int_to_scsilunexport scsi_normalize_senseexport scsi_sense_desc_findexport scsi_build_sense_bufferexport scsi_set_sense_informationexport scsi_set_sense_field_pointer
Annotated Snippet
if (sb_len > 7) {
sb_len = min(sb_len, sense_buffer[7] + 8);
if (sb_len > 12)
sshdr->asc = sense_buffer[12];
if (sb_len > 13)
sshdr->ascq = sense_buffer[13];
}
}
return true;
}
EXPORT_SYMBOL(scsi_normalize_sense);
/**
* scsi_sense_desc_find - search for a given descriptor type in descriptor sense data format.
* @sense_buffer: byte array of descriptor format sense data
* @sb_len: number of valid bytes in sense_buffer
* @desc_type: value of descriptor type to find
* (e.g. 0 -> information)
*
* Notes:
* only valid when sense data is in descriptor format
*
* Return value:
* pointer to start of (first) descriptor if found else NULL
*/
const u8 * scsi_sense_desc_find(const u8 * sense_buffer, int sb_len,
int desc_type)
{
int add_sen_len, add_len, desc_len, k;
const u8 * descp;
if ((sb_len < 8) || (0 == (add_sen_len = sense_buffer[7])))
return NULL;
if ((sense_buffer[0] < 0x72) || (sense_buffer[0] > 0x73))
return NULL;
add_sen_len = (add_sen_len < (sb_len - 8)) ?
add_sen_len : (sb_len - 8);
descp = &sense_buffer[8];
for (desc_len = 0, k = 0; k < add_sen_len; k += desc_len) {
descp += desc_len;
add_len = (k < (add_sen_len - 1)) ? descp[1]: -1;
desc_len = add_len + 2;
if (descp[0] == desc_type)
return descp;
if (add_len < 0) // short descriptor ??
break;
}
return NULL;
}
EXPORT_SYMBOL(scsi_sense_desc_find);
/**
* scsi_build_sense_buffer - build sense data in a buffer
* @desc: Sense format (non-zero == descriptor format,
* 0 == fixed format)
* @buf: Where to build sense data
* @key: Sense key
* @asc: Additional sense code
* @ascq: Additional sense code qualifier
*
**/
void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq)
{
if (desc) {
buf[0] = 0x72; /* descriptor, current */
buf[1] = key;
buf[2] = asc;
buf[3] = ascq;
buf[7] = 0;
} else {
buf[0] = 0x70; /* fixed, current */
buf[2] = key;
buf[7] = 0xa;
buf[12] = asc;
buf[13] = ascq;
}
}
EXPORT_SYMBOL(scsi_build_sense_buffer);
/**
* scsi_set_sense_information - set the information field in a
* formatted sense data buffer
* @buf: Where to build sense data
* @buf_len: buffer length
* @info: 64-bit information value to be set
*
* Return value:
* 0 on success or -EINVAL for invalid sense buffer length
**/
Annotation
- Immediate include surface: `linux/bug.h`, `linux/kernel.h`, `linux/string.h`, `linux/errno.h`, `linux/module.h`, `uapi/linux/pr.h`, `linux/unaligned.h`, `scsi/scsi_common.h`.
- Detected declarations: `function scsi_pr_type_to_block`, `function block_pr_type_to_scsi`, `function scsilun_to_int`, `function int_to_scsilun`, `function scsi_normalize_sense`, `function of`, `function scsi_build_sense_buffer`, `function scsi_set_sense_information`, `function scsi_set_sense_field_pointer`, `export scsi_command_size_tbl`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: integration implementation candidate.
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.