drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c- Extension
.c- Size
- 15263 bytes
- Lines
- 564
- 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/mlx5/driver.heswitch.hpriv.hsf/dev/dev.hmlx5_ifc_vhca_event.hvhca_event.hecpf.hdiag/sf_tracepoint.h
Detected Declarations
struct mlx5_sfstruct mlx5_sf_tablefunction mlx5_sf_lookup_by_function_idfunction mlx5_sf_function_id_insertfunction mlx5_sf_function_id_erasefunction mlx5_sf_allocfunction mlx5_sf_freefunction mlx5_sf_to_devlink_statefunction mlx5_sf_to_devlink_opstatefunction mlx5_sf_is_activefunction mlx5_devlink_sf_port_fn_state_getfunction mlx5_sf_activatefunction mlx5_sf_deactivatefunction mlx5_sf_state_setfunction mlx5_devlink_sf_port_fn_state_setfunction mlx5_sf_addfunction mlx5_sf_new_check_attrfunction mlx5_esw_sf_controller_to_pfnumfunction mlx5_sf_table_supportedfunction mlx5_devlink_sf_port_newfunction mlx5_sf_deallocfunction mlx5_sf_delfunction mlx5_devlink_sf_port_delfunction mlx5_sf_state_update_checkfunction mlx5_sf_vhca_eventfunction mlx5_sf_del_allfunction mlx5_sf_esw_eventfunction mlx5_sf_mdev_eventfunction mlx5_sf_notifiers_initfunction mlx5_sf_table_initfunction mlx5_sf_notifiers_cleanupfunction mlx5_sf_table_cleanupfunction mlx5_sf_table_empty
Annotated Snippet
struct mlx5_sf {
struct mlx5_devlink_port dl_port;
unsigned int port_index;
u32 controller;
u16 id;
u16 hw_fn_id;
u16 hw_state;
};
static void *mlx5_sf_by_dl_port(struct devlink_port *dl_port)
{
struct mlx5_devlink_port *mlx5_dl_port = mlx5_devlink_port_get(dl_port);
return container_of(mlx5_dl_port, struct mlx5_sf, dl_port);
}
struct mlx5_sf_table {
struct mlx5_core_dev *dev; /* To refer from notifier context. */
struct xarray function_ids; /* function id based lookup. */
struct mutex sf_state_lock; /* Serializes sf state among user cmds & vhca event handler. */
};
static struct mlx5_sf *
mlx5_sf_lookup_by_function_id(struct mlx5_sf_table *table, unsigned int fn_id)
{
return xa_load(&table->function_ids, fn_id);
}
static int mlx5_sf_function_id_insert(struct mlx5_sf_table *table, struct mlx5_sf *sf)
{
return xa_insert(&table->function_ids, sf->hw_fn_id, sf, GFP_KERNEL);
}
static void mlx5_sf_function_id_erase(struct mlx5_sf_table *table, struct mlx5_sf *sf)
{
xa_erase(&table->function_ids, sf->hw_fn_id);
}
static struct mlx5_sf *
mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
u32 controller, u32 sfnum, struct netlink_ext_ack *extack)
{
unsigned int dl_port_index;
struct mlx5_sf *sf;
u16 hw_fn_id;
int id_err;
int err;
if (!mlx5_esw_offloads_controller_valid(esw, controller)) {
NL_SET_ERR_MSG_MOD(extack, "Invalid controller number");
return ERR_PTR(-EINVAL);
}
id_err = mlx5_sf_hw_table_sf_alloc(table->dev, controller, sfnum);
if (id_err < 0) {
err = id_err;
goto id_err;
}
sf = kzalloc_obj(*sf);
if (!sf) {
err = -ENOMEM;
goto alloc_err;
}
sf->id = id_err;
hw_fn_id = mlx5_sf_sw_to_hw_id(table->dev, controller, sf->id);
dl_port_index = mlx5_esw_vport_to_devlink_port_index(table->dev, hw_fn_id);
sf->port_index = dl_port_index;
sf->hw_fn_id = hw_fn_id;
sf->hw_state = MLX5_VHCA_STATE_ALLOCATED;
sf->controller = controller;
err = mlx5_sf_function_id_insert(table, sf);
if (err)
goto insert_err;
return sf;
insert_err:
kfree(sf);
alloc_err:
mlx5_sf_hw_table_sf_free(table->dev, controller, id_err);
id_err:
if (err == -EEXIST)
NL_SET_ERR_MSG_MOD(extack, "SF already exist. Choose different sfnum");
return ERR_PTR(err);
}
static void mlx5_sf_free(struct mlx5_sf_table *table, struct mlx5_sf *sf)
{
Annotation
- Immediate include surface: `linux/mlx5/driver.h`, `eswitch.h`, `priv.h`, `sf/dev/dev.h`, `mlx5_ifc_vhca_event.h`, `vhca_event.h`, `ecpf.h`, `diag/sf_tracepoint.h`.
- Detected declarations: `struct mlx5_sf`, `struct mlx5_sf_table`, `function mlx5_sf_lookup_by_function_id`, `function mlx5_sf_function_id_insert`, `function mlx5_sf_function_id_erase`, `function mlx5_sf_alloc`, `function mlx5_sf_free`, `function mlx5_sf_to_devlink_state`, `function mlx5_sf_to_devlink_opstate`, `function mlx5_sf_is_active`.
- 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.