drivers/scsi/snic/snic_trc.c
Source file repositories/reference/linux-study-clean/drivers/scsi/snic/snic_trc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/snic/snic_trc.c- Extension
.c- Size
- 3187 bytes
- Lines
- 156
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/module.hlinux/mempool.hlinux/errno.hlinux/vmalloc.hsnic_io.hsnic.h
Detected Declarations
function snic_get_trc_buffunction snic_fmt_trc_datafunction snic_get_trc_datafunction snic_trc_initfunction snic_trc_free
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2014 Cisco Systems, Inc. All rights reserved.
#include <linux/module.h>
#include <linux/mempool.h>
#include <linux/errno.h>
#include <linux/vmalloc.h>
#include "snic_io.h"
#include "snic.h"
/*
* snic_get_trc_buf : Allocates a trace record and returns.
*/
struct snic_trc_data *
snic_get_trc_buf(void)
{
struct snic_trc *trc = &snic_glob->trc;
struct snic_trc_data *td = NULL;
unsigned long flags;
spin_lock_irqsave(&trc->lock, flags);
td = &trc->buf[trc->wr_idx];
trc->wr_idx++;
if (trc->wr_idx == trc->max_idx)
trc->wr_idx = 0;
if (trc->wr_idx != trc->rd_idx) {
spin_unlock_irqrestore(&trc->lock, flags);
goto end;
}
trc->rd_idx++;
if (trc->rd_idx == trc->max_idx)
trc->rd_idx = 0;
td->ts = 0; /* Marker for checking the record, for complete data*/
spin_unlock_irqrestore(&trc->lock, flags);
end:
return td;
} /* end of snic_get_trc_buf */
/*
* snic_fmt_trc_data : Formats trace data for printing.
*/
static int
snic_fmt_trc_data(struct snic_trc_data *td, char *buf, int buf_sz)
{
int len = 0;
struct timespec64 tmspec;
jiffies_to_timespec64(td->ts, &tmspec);
len += snprintf(buf, buf_sz,
"%ptSp %-25s %3d %4x %16llx %16llx %16llx %16llx %16llx\n",
&tmspec,
td->fn,
td->hno,
td->tag,
td->data[0], td->data[1], td->data[2], td->data[3],
td->data[4]);
return len;
} /* end of snic_fmt_trc_data */
/*
* snic_get_trc_data : Returns a formatted trace buffer.
*/
int
snic_get_trc_data(char *buf, int buf_sz)
{
struct snic_trc_data *td = NULL;
struct snic_trc *trc = &snic_glob->trc;
unsigned long flags;
spin_lock_irqsave(&trc->lock, flags);
if (trc->rd_idx == trc->wr_idx) {
spin_unlock_irqrestore(&trc->lock, flags);
return -1;
}
td = &trc->buf[trc->rd_idx];
if (td->ts == 0) {
/* write in progress. */
spin_unlock_irqrestore(&trc->lock, flags);
Annotation
- Immediate include surface: `linux/module.h`, `linux/mempool.h`, `linux/errno.h`, `linux/vmalloc.h`, `snic_io.h`, `snic.h`.
- Detected declarations: `function snic_get_trc_buf`, `function snic_fmt_trc_data`, `function snic_get_trc_data`, `function snic_trc_init`, `function snic_trc_free`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: source 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.