drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c- Extension
.c- Size
- 48396 bytes
- Lines
- 1743
- 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.
- 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/if_bridge.hlinux/list.hlinux/mutex.hlinux/refcount.hlinux/rtnetlink.hlinux/workqueue.hnet/arp.hnet/gre.hnet/lag.hnet/ndisc.hnet/ip6_tunnel.hspectrum.hspectrum_ipip.hspectrum_span.hspectrum_switchdev.h
Detected Declarations
struct mlxsw_sp_spanstruct mlxsw_sp_span_analyzed_portstruct mlxsw_sp_span_trigger_entrystruct mlxsw_sp_span_trigger_opsenum mlxsw_sp_span_trigger_typefunction mlxsw_sp_span_occ_getfunction mlxsw_sp_span_initfunction mlxsw_sp_span_finifunction mlxsw_sp1_span_cpu_can_handlefunction mlxsw_sp1_span_entry_cpu_parmsfunction mlxsw_sp1_span_entry_cpu_configurefunction mlxsw_sp1_span_entry_cpu_deconfigurefunction mlxsw_sp_span_entry_phys_parmsfunction mlxsw_sp_span_entry_phys_configurefunction mlxsw_sp_span_entry_deconfigure_commonfunction mlxsw_sp_span_entry_phys_deconfigurefunction mlxsw_sp_span_dmacfunction mlxsw_sp_span_entry_unoffloadablefunction mlxsw_sp_span_entry_bridge_8021qfunction mlxsw_sp_span_entry_bridge_8021dfunction mlxsw_sp_span_entry_bridgefunction mlxsw_sp_span_entry_vlanfunction mlxsw_sp_span_entry_lagfunction mlxsw_sp_span_entry_tunnel_parms_commonfunction mlxsw_sp_span_gretap4_routefunction mlxsw_sp_span_entry_gretap4_parmsfunction mlxsw_sp_span_entry_gretap4_configurefunction mlxsw_sp_span_entry_gretap4_deconfigurefunction mlxsw_sp_span_gretap6_routefunction mlxsw_sp_span_entry_gretap6_parmsfunction mlxsw_sp_span_entry_gretap6_configurefunction mlxsw_sp_span_entry_gretap6_deconfigurefunction mlxsw_sp_span_vlan_can_handlefunction mlxsw_sp_span_entry_vlan_parmsfunction mlxsw_sp_span_entry_vlan_configurefunction mlxsw_sp_span_entry_vlan_deconfigurefunction mlxsw_sp2_span_cpu_can_handlefunction mlxsw_sp2_span_entry_cpu_parmsfunction mlxsw_sp2_span_entry_cpu_configurefunction mlxsw_sp2_span_entry_cpu_deconfigurefunction mlxsw_sp_span_entry_nop_parmsfunction mlxsw_sp_span_entry_nop_configurefunction mlxsw_sp_span_entry_nop_deconfigurefunction mlxsw_sp_span_entry_configurefunction mlxsw_sp_span_entry_deconfigurefunction mlxsw_sp_span_policer_id_base_setfunction mlxsw_sp_span_policer_id_base_unsetfunction mlxsw_sp_span_entry_create
Annotated Snippet
struct mlxsw_sp_span {
struct work_struct work;
struct mlxsw_sp *mlxsw_sp;
const struct mlxsw_sp_span_trigger_ops **span_trigger_ops_arr;
const struct mlxsw_sp_span_entry_ops **span_entry_ops_arr;
size_t span_entry_ops_arr_size;
struct list_head analyzed_ports_list;
struct mutex analyzed_ports_lock; /* Protects analyzed_ports_list */
struct list_head trigger_entries_list;
u16 policer_id_base;
refcount_t policer_id_base_ref_count;
atomic_t active_entries_count;
int entries_count;
struct mlxsw_sp_span_entry entries[] __counted_by(entries_count);
};
struct mlxsw_sp_span_analyzed_port {
struct list_head list; /* Member of analyzed_ports_list */
refcount_t ref_count;
u16 local_port;
bool ingress;
};
struct mlxsw_sp_span_trigger_entry {
struct list_head list; /* Member of trigger_entries_list */
struct mlxsw_sp_span *span;
const struct mlxsw_sp_span_trigger_ops *ops;
refcount_t ref_count;
u16 local_port;
enum mlxsw_sp_span_trigger trigger;
struct mlxsw_sp_span_trigger_parms parms;
};
enum mlxsw_sp_span_trigger_type {
MLXSW_SP_SPAN_TRIGGER_TYPE_PORT,
MLXSW_SP_SPAN_TRIGGER_TYPE_GLOBAL,
};
struct mlxsw_sp_span_trigger_ops {
int (*bind)(struct mlxsw_sp_span_trigger_entry *trigger_entry);
void (*unbind)(struct mlxsw_sp_span_trigger_entry *trigger_entry);
bool (*matches)(struct mlxsw_sp_span_trigger_entry *trigger_entry,
enum mlxsw_sp_span_trigger trigger,
struct mlxsw_sp_port *mlxsw_sp_port);
int (*enable)(struct mlxsw_sp_span_trigger_entry *trigger_entry,
struct mlxsw_sp_port *mlxsw_sp_port, u8 tc);
void (*disable)(struct mlxsw_sp_span_trigger_entry *trigger_entry,
struct mlxsw_sp_port *mlxsw_sp_port, u8 tc);
};
static void mlxsw_sp_span_respin_work(struct work_struct *work);
static u64 mlxsw_sp_span_occ_get(void *priv)
{
const struct mlxsw_sp *mlxsw_sp = priv;
return atomic_read(&mlxsw_sp->span->active_entries_count);
}
int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
struct mlxsw_sp_span *span;
int i, entries_count, err;
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_SPAN))
return -EIO;
entries_count = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_SPAN);
span = kzalloc_flex(*span, entries, entries_count);
if (!span)
return -ENOMEM;
refcount_set(&span->policer_id_base_ref_count, 0);
span->entries_count = entries_count;
atomic_set(&span->active_entries_count, 0);
mutex_init(&span->analyzed_ports_lock);
INIT_LIST_HEAD(&span->analyzed_ports_list);
INIT_LIST_HEAD(&span->trigger_entries_list);
span->mlxsw_sp = mlxsw_sp;
mlxsw_sp->span = span;
for (i = 0; i < mlxsw_sp->span->entries_count; i++)
mlxsw_sp->span->entries[i].id = i;
err = mlxsw_sp->span_ops->init(mlxsw_sp);
if (err)
goto err_init;
devl_resource_occ_get_register(devlink, MLXSW_SP_RESOURCE_SPAN,
mlxsw_sp_span_occ_get, mlxsw_sp);
Annotation
- Immediate include surface: `linux/if_bridge.h`, `linux/list.h`, `linux/mutex.h`, `linux/refcount.h`, `linux/rtnetlink.h`, `linux/workqueue.h`, `net/arp.h`, `net/gre.h`.
- Detected declarations: `struct mlxsw_sp_span`, `struct mlxsw_sp_span_analyzed_port`, `struct mlxsw_sp_span_trigger_entry`, `struct mlxsw_sp_span_trigger_ops`, `enum mlxsw_sp_span_trigger_type`, `function mlxsw_sp_span_occ_get`, `function mlxsw_sp_span_init`, `function mlxsw_sp_span_fini`, `function mlxsw_sp1_span_cpu_can_handle`, `function mlxsw_sp1_span_entry_cpu_parms`.
- Atlas domain: Driver Families / drivers/net.
- 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.