drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c- Extension
.c- Size
- 53877 bytes
- Lines
- 1995
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/kernel.hlinux/netlink.hnet/devlink.huapi/linux/devlink.hcore.hreg.hspectrum.hspectrum_trap.h
Detected Declarations
struct mlxsw_sp_trap_policer_itemstruct mlxsw_sp_trap_group_itemstruct mlxsw_sp_trap_itemfunction mlxsw_sp_rx_listenerfunction mlxsw_sp_rx_drop_listenerfunction mlxsw_sp_rx_acl_drop_listenerfunction __mlxsw_sp_rx_no_mark_listenerfunction mlxsw_sp_rx_no_mark_listenerfunction mlxsw_sp_rx_mark_listenerfunction mlxsw_sp_rx_l3_mark_listenerfunction mlxsw_sp_rx_ptp_listenerfunction mlxsw_sp_sample_tx_port_getfunction mlxsw_sp_psample_md_initfunction mlxsw_sp_rx_sample_listenerfunction mlxsw_sp_rx_sample_tx_listenerfunction mlxsw_sp_rx_sample_acl_listenerfunction mlxsw_sp_trap_policer_item_lookupfunction mlxsw_sp_trap_group_item_lookupfunction mlxsw_sp_trap_item_lookupfunction mlxsw_sp_trap_cpu_policers_setfunction mlxsw_sp_trap_dummy_group_initfunction mlxsw_sp_trap_policer_items_arr_initfunction mlxsw_sp_trap_policer_items_arr_finifunction mlxsw_sp_trap_policers_initfunction mlxsw_sp_trap_policers_finifunction mlxsw_sp_trap_group_items_arr_initfunction mlxsw_sp_trap_group_items_arr_finifunction mlxsw_sp_trap_groups_initfunction mlxsw_sp_trap_groups_finifunction mlxsw_sp_trap_listener_is_validfunction mlxsw_sp_trap_items_arr_initfunction mlxsw_sp_trap_items_arr_finifunction mlxsw_sp_traps_initfunction mlxsw_sp_traps_finifunction mlxsw_sp_devlink_traps_initfunction mlxsw_sp_devlink_traps_finifunction mlxsw_sp_trap_initfunction mlxsw_sp_trap_finifunction mlxsw_sp_trap_action_setfunction __mlxsw_sp_trap_group_initfunction mlxsw_sp_trap_group_initfunction mlxsw_sp_trap_group_setfunction mlxsw_sp_trap_policer_item_initfunction mlxsw_sp_trap_policer_item_finifunction mlxsw_sp_trap_policer_bsfunction __mlxsw_sp_trap_policer_setfunction mlxsw_sp_trap_policer_initfunction mlxsw_sp_trap_policer_fini
Annotated Snippet
struct mlxsw_sp_trap_policer_item {
struct devlink_trap_policer policer;
u16 hw_id;
};
struct mlxsw_sp_trap_group_item {
struct devlink_trap_group group;
u16 hw_group_id;
u8 priority;
u8 fixed_policer:1; /* Whether policer binding can change */
};
#define MLXSW_SP_TRAP_LISTENERS_MAX 3
struct mlxsw_sp_trap_item {
struct devlink_trap trap;
struct mlxsw_listener listeners_arr[MLXSW_SP_TRAP_LISTENERS_MAX];
u8 is_source:1;
};
/* All driver-specific traps must be documented in
* Documentation/networking/devlink/mlxsw.rst
*/
enum {
DEVLINK_MLXSW_TRAP_ID_BASE = DEVLINK_TRAP_GENERIC_ID_MAX,
DEVLINK_MLXSW_TRAP_ID_IRIF_DISABLED,
DEVLINK_MLXSW_TRAP_ID_ERIF_DISABLED,
};
#define DEVLINK_MLXSW_TRAP_NAME_IRIF_DISABLED \
"irif_disabled"
#define DEVLINK_MLXSW_TRAP_NAME_ERIF_DISABLED \
"erif_disabled"
#define MLXSW_SP_TRAP_METADATA DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT
enum {
/* Packet was mirrored from ingress. */
MLXSW_SP_MIRROR_REASON_INGRESS = 1,
/* Packet was mirrored from policy engine. */
MLXSW_SP_MIRROR_REASON_POLICY_ENGINE = 2,
/* Packet was early dropped. */
MLXSW_SP_MIRROR_REASON_INGRESS_WRED = 9,
/* Packet was mirrored from egress. */
MLXSW_SP_MIRROR_REASON_EGRESS = 14,
};
static int mlxsw_sp_rx_listener(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
u16 local_port,
struct mlxsw_sp_port *mlxsw_sp_port)
{
struct mlxsw_sp_port_pcpu_stats *pcpu_stats;
if (unlikely(!mlxsw_sp_port)) {
dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: skb received for non-existent port\n",
local_port);
kfree_skb(skb);
return -EINVAL;
}
skb->dev = mlxsw_sp_port->dev;
pcpu_stats = this_cpu_ptr(mlxsw_sp_port->pcpu_stats);
u64_stats_update_begin(&pcpu_stats->syncp);
pcpu_stats->rx_packets++;
pcpu_stats->rx_bytes += skb->len;
u64_stats_update_end(&pcpu_stats->syncp);
skb->protocol = eth_type_trans(skb, skb->dev);
return 0;
}
static void mlxsw_sp_rx_drop_listener(struct sk_buff *skb, u16 local_port,
void *trap_ctx)
{
struct devlink_port *in_devlink_port;
struct mlxsw_sp_port *mlxsw_sp_port;
struct mlxsw_sp *mlxsw_sp;
struct devlink *devlink;
int err;
mlxsw_sp = devlink_trap_ctx_priv(trap_ctx);
mlxsw_sp_port = mlxsw_sp->ports[local_port];
err = mlxsw_sp_rx_listener(mlxsw_sp, skb, local_port, mlxsw_sp_port);
if (err)
return;
devlink = priv_to_devlink(mlxsw_sp->core);
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/kernel.h`, `linux/netlink.h`, `net/devlink.h`, `uapi/linux/devlink.h`, `core.h`, `reg.h`, `spectrum.h`.
- Detected declarations: `struct mlxsw_sp_trap_policer_item`, `struct mlxsw_sp_trap_group_item`, `struct mlxsw_sp_trap_item`, `function mlxsw_sp_rx_listener`, `function mlxsw_sp_rx_drop_listener`, `function mlxsw_sp_rx_acl_drop_listener`, `function __mlxsw_sp_rx_no_mark_listener`, `function mlxsw_sp_rx_no_mark_listener`, `function mlxsw_sp_rx_mark_listener`, `function mlxsw_sp_rx_l3_mark_listener`.
- 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.