drivers/fsi/fsi-occ.c
Source file repositories/reference/linux-study-clean/drivers/fsi/fsi-occ.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/fsi/fsi-occ.c- Extension
.c- Size
- 17544 bytes
- Lines
- 760
- Domain
- Driver Families
- Bucket
- drivers/fsi
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/device.hlinux/err.hlinux/errno.hlinux/fs.hlinux/fsi-sbefifo.hlinux/gfp.hlinux/idr.hlinux/kernel.hlinux/list.hlinux/miscdevice.hlinux/mm.hlinux/module.hlinux/mutex.hlinux/fsi-occ.hlinux/of.hlinux/of_platform.hlinux/platform_device.hlinux/sched.hlinux/slab.hlinux/uaccess.hlinux/unaligned.h
Detected Declarations
struct occstruct occ_responsestruct occ_clientenum versionsfunction occ_openfunction occ_readfunction occ_writefunction commandfunction occ_releasefunction occ_save_ffdcfunction occ_verify_checksumfunction occ_getsramfunction occ_putsramfunction occ_trigger_attnfunction fsi_occ_response_not_readyfunction fsi_occ_submitfunction occ_unregister_platform_childfunction occ_unregister_of_childfunction occ_probefunction occ_removefunction occ_initfunction occ_exitmodule init occ_initexport fsi_occ_submit
Annotated Snippet
static const struct file_operations occ_fops = {
.owner = THIS_MODULE,
.open = occ_open,
.read = occ_read,
.write = occ_write,
.release = occ_release,
};
static void occ_save_ffdc(struct occ *occ, __be32 *resp, size_t parsed_len,
size_t resp_len)
{
if (resp_len > parsed_len) {
size_t dh = resp_len - parsed_len;
size_t ffdc_len = (dh - 1) * 4; /* SBE words are four bytes */
__be32 *ffdc = &resp[parsed_len];
if (ffdc_len > occ->client_buffer_size)
ffdc_len = occ->client_buffer_size;
memcpy(occ->client_buffer, ffdc, ffdc_len);
occ->client_response_size = ffdc_len;
}
}
static int occ_verify_checksum(struct occ *occ, struct occ_response *resp,
u16 data_length)
{
/* Fetch the two bytes after the data for the checksum. */
u16 checksum_resp = get_unaligned_be16(&resp->data[data_length]);
u16 checksum;
u16 i;
checksum = resp->seq_no;
checksum += resp->cmd_type;
checksum += resp->return_status;
checksum += (data_length >> 8) + (data_length & 0xFF);
for (i = 0; i < data_length; ++i)
checksum += resp->data[i];
if (checksum != checksum_resp) {
dev_err(occ->dev, "Bad checksum: %04x!=%04x\n", checksum,
checksum_resp);
return -EBADE;
}
return 0;
}
static int occ_getsram(struct occ *occ, u32 offset, void *data, ssize_t len)
{
u32 data_len = ((len + 7) / 8) * 8; /* must be multiples of 8 B */
size_t cmd_len, parsed_len, resp_data_len;
size_t resp_len = OCC_MAX_RESP_WORDS;
__be32 *resp = occ->buffer;
__be32 cmd[6];
int idx = 0, rc;
/*
* Magic sequence to do SBE getsram command. SBE will fetch data from
* specified SRAM address.
*/
switch (occ->version) {
default:
case occ_p9:
cmd_len = 5;
cmd[2] = cpu_to_be32(1); /* Normal mode */
cmd[3] = cpu_to_be32(OCC_P9_SRAM_RSP_ADDR + offset);
break;
case occ_p10:
idx = 1;
cmd_len = 6;
cmd[2] = cpu_to_be32(OCC_P10_SRAM_MODE);
cmd[3] = 0;
cmd[4] = cpu_to_be32(OCC_P10_SRAM_RSP_ADDR + offset);
break;
}
cmd[0] = cpu_to_be32(cmd_len);
cmd[1] = cpu_to_be32(SBEFIFO_CMD_GET_OCC_SRAM);
cmd[4 + idx] = cpu_to_be32(data_len);
rc = sbefifo_submit(occ->sbefifo, cmd, cmd_len, resp, &resp_len);
if (rc)
return rc;
rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_GET_OCC_SRAM,
resp, resp_len, &parsed_len);
if (rc > 0) {
dev_err(occ->dev, "SRAM read returned failure status: %08x\n",
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/errno.h`, `linux/fs.h`, `linux/fsi-sbefifo.h`, `linux/gfp.h`, `linux/idr.h`, `linux/kernel.h`.
- Detected declarations: `struct occ`, `struct occ_response`, `struct occ_client`, `enum versions`, `function occ_open`, `function occ_read`, `function occ_write`, `function command`, `function occ_release`, `function occ_save_ffdc`.
- Atlas domain: Driver Families / drivers/fsi.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.