drivers/net/ethernet/marvell/prestera/prestera_span.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/marvell/prestera/prestera_span.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/marvell/prestera/prestera_span.c- Extension
.c- Size
- 3843 bytes
- Lines
- 192
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- 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/kernel.hlinux/list.hprestera.hprestera_hw.hprestera_acl.hprestera_flow.hprestera_span.h
Detected Declarations
struct prestera_span_entrystruct prestera_spanfunction prestera_span_entry_createfunction prestera_span_entry_delfunction prestera_span_entry_find_by_idfunction list_for_each_entryfunction prestera_span_entry_find_by_portfunction list_for_each_entryfunction prestera_span_getfunction prestera_span_putfunction prestera_span_rule_addfunction prestera_span_rule_delfunction prestera_span_initfunction prestera_span_fini
Annotated Snippet
struct prestera_span_entry {
struct list_head list;
struct prestera_port *port;
refcount_t ref_count;
u8 id;
};
struct prestera_span {
struct prestera_switch *sw;
struct list_head entries;
};
static struct prestera_span_entry *
prestera_span_entry_create(struct prestera_port *port, u8 span_id)
{
struct prestera_span_entry *entry;
entry = kzalloc_obj(*entry);
if (!entry)
return ERR_PTR(-ENOMEM);
refcount_set(&entry->ref_count, 1);
entry->port = port;
entry->id = span_id;
list_add_tail(&entry->list, &port->sw->span->entries);
return entry;
}
static void prestera_span_entry_del(struct prestera_span_entry *entry)
{
list_del(&entry->list);
kfree(entry);
}
static struct prestera_span_entry *
prestera_span_entry_find_by_id(struct prestera_span *span, u8 span_id)
{
struct prestera_span_entry *entry;
list_for_each_entry(entry, &span->entries, list) {
if (entry->id == span_id)
return entry;
}
return NULL;
}
static struct prestera_span_entry *
prestera_span_entry_find_by_port(struct prestera_span *span,
struct prestera_port *port)
{
struct prestera_span_entry *entry;
list_for_each_entry(entry, &span->entries, list) {
if (entry->port == port)
return entry;
}
return NULL;
}
static int prestera_span_get(struct prestera_port *port, u8 *span_id)
{
u8 new_span_id;
struct prestera_switch *sw = port->sw;
struct prestera_span_entry *entry;
int err;
entry = prestera_span_entry_find_by_port(sw->span, port);
if (entry) {
refcount_inc(&entry->ref_count);
*span_id = entry->id;
return 0;
}
err = prestera_hw_span_get(port, &new_span_id);
if (err)
return err;
entry = prestera_span_entry_create(port, new_span_id);
if (IS_ERR(entry)) {
prestera_hw_span_release(sw, new_span_id);
return PTR_ERR(entry);
}
*span_id = new_span_id;
return 0;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/list.h`, `prestera.h`, `prestera_hw.h`, `prestera_acl.h`, `prestera_flow.h`, `prestera_span.h`.
- Detected declarations: `struct prestera_span_entry`, `struct prestera_span`, `function prestera_span_entry_create`, `function prestera_span_entry_del`, `function prestera_span_entry_find_by_id`, `function list_for_each_entry`, `function prestera_span_entry_find_by_port`, `function list_for_each_entry`, `function prestera_span_get`, `function prestera_span_put`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source 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.