drivers/net/ethernet/mellanox/mlxsw/spectrum_port_range.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/spectrum_port_range.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/spectrum_port_range.c- Extension
.c- Size
- 5146 bytes
- Lines
- 201
- 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/bits.hlinux/netlink.hlinux/refcount.hlinux/xarray.hnet/devlink.hspectrum.h
Detected Declarations
struct mlxsw_sp_port_range_regstruct mlxsw_sp_port_range_corefunction mlxsw_sp_port_range_reg_configurefunction mlxsw_sp_port_range_reg_createfunction mlxsw_sp_port_range_reg_destroyfunction mlxsw_sp_port_range_reg_findfunction xa_for_eachfunction mlxsw_sp_port_range_reg_getfunction mlxsw_sp_port_range_reg_putfunction mlxsw_sp_port_range_reg_occ_getfunction mlxsw_sp_port_range_initfunction mlxsw_sp_port_range_fini
Annotated Snippet
struct mlxsw_sp_port_range_reg {
struct mlxsw_sp_port_range range;
refcount_t refcount;
u32 index;
};
struct mlxsw_sp_port_range_core {
struct xarray prr_xa;
struct xa_limit prr_ids;
atomic_t prr_count;
};
static int
mlxsw_sp_port_range_reg_configure(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_sp_port_range_reg *prr)
{
char pprr_pl[MLXSW_REG_PPRR_LEN];
/* We do not care if packet is IPv4/IPv6 and TCP/UDP, so set all four
* fields.
*/
mlxsw_reg_pprr_pack(pprr_pl, prr->index);
mlxsw_reg_pprr_ipv4_set(pprr_pl, true);
mlxsw_reg_pprr_ipv6_set(pprr_pl, true);
mlxsw_reg_pprr_src_set(pprr_pl, prr->range.source);
mlxsw_reg_pprr_dst_set(pprr_pl, !prr->range.source);
mlxsw_reg_pprr_tcp_set(pprr_pl, true);
mlxsw_reg_pprr_udp_set(pprr_pl, true);
mlxsw_reg_pprr_port_range_min_set(pprr_pl, prr->range.min);
mlxsw_reg_pprr_port_range_max_set(pprr_pl, prr->range.max);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pprr), pprr_pl);
}
static struct mlxsw_sp_port_range_reg *
mlxsw_sp_port_range_reg_create(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_sp_port_range *range,
struct netlink_ext_ack *extack)
{
struct mlxsw_sp_port_range_core *pr_core = mlxsw_sp->pr_core;
struct mlxsw_sp_port_range_reg *prr;
int err;
prr = kzalloc_obj(*prr);
if (!prr)
return ERR_PTR(-ENOMEM);
prr->range = *range;
refcount_set(&prr->refcount, 1);
err = xa_alloc(&pr_core->prr_xa, &prr->index, prr, pr_core->prr_ids,
GFP_KERNEL);
if (err) {
if (err == -EBUSY)
NL_SET_ERR_MSG_MOD(extack, "Exceeded number of port range registers");
goto err_xa_alloc;
}
err = mlxsw_sp_port_range_reg_configure(mlxsw_sp, prr);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to configure port range register");
goto err_reg_configure;
}
atomic_inc(&pr_core->prr_count);
return prr;
err_reg_configure:
xa_erase(&pr_core->prr_xa, prr->index);
err_xa_alloc:
kfree(prr);
return ERR_PTR(err);
}
static void mlxsw_sp_port_range_reg_destroy(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_port_range_reg *prr)
{
struct mlxsw_sp_port_range_core *pr_core = mlxsw_sp->pr_core;
atomic_dec(&pr_core->prr_count);
xa_erase(&pr_core->prr_xa, prr->index);
kfree(prr);
}
static struct mlxsw_sp_port_range_reg *
mlxsw_sp_port_range_reg_find(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_sp_port_range *range)
{
struct mlxsw_sp_port_range_core *pr_core = mlxsw_sp->pr_core;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/netlink.h`, `linux/refcount.h`, `linux/xarray.h`, `net/devlink.h`, `spectrum.h`.
- Detected declarations: `struct mlxsw_sp_port_range_reg`, `struct mlxsw_sp_port_range_core`, `function mlxsw_sp_port_range_reg_configure`, `function mlxsw_sp_port_range_reg_create`, `function mlxsw_sp_port_range_reg_destroy`, `function mlxsw_sp_port_range_reg_find`, `function xa_for_each`, `function mlxsw_sp_port_range_reg_get`, `function mlxsw_sp_port_range_reg_put`, `function mlxsw_sp_port_range_reg_occ_get`.
- 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.