drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c- Extension
.c- Size
- 11491 bytes
- Lines
- 462
- 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.hvhca_event.hpriv.hsf.hmlx5_ifc_vhca_event.hecpf.hmlx5_core.heswitch.hdiag/sf_tracepoint.hdevlink.h
Detected Declarations
struct mlx5_sf_hwstruct mlx5_sf_hwc_tablestruct mlx5_sf_hw_tablefunction mlx5_sf_controller_to_hwcfunction mlx5_sf_sw_to_hw_idfunction mlx5_sf_hw_to_sw_idfunction mlx5_sf_table_fn_to_hwcfunction mlx5_sf_hw_table_id_allocfunction mlx5_sf_hw_table_id_freefunction mlx5_sf_hw_table_sf_allocfunction mlx5_sf_hw_table_sf_freefunction mlx5_sf_hw_table_hwc_sf_freefunction mlx5_sf_hw_table_sf_deferred_freefunction mlx5_sf_hw_table_hwc_dealloc_allfunction mlx5_sf_hw_table_dealloc_allfunction mlx5_sf_hw_table_hwc_initfunction mlx5_sf_hw_table_hwc_cleanupfunction mlx5_sf_hw_table_res_unregisterfunction mlx5_sf_hw_table_res_registerfunction mlx5_sf_hw_table_initfunction mlx5_sf_hw_table_cleanupfunction mlx5_sf_hw_vhca_eventfunction mlx5_sf_hw_notifier_initfunction mlx5_sf_hw_notifier_cleanupfunction mlx5_sf_hw_table_destroyfunction mlx5_sf_hw_table_supported
Annotated Snippet
struct mlx5_sf_hw {
u32 usr_sfnum;
u8 allocated: 1;
u8 pending_delete: 1;
};
struct mlx5_sf_hwc_table {
struct mlx5_sf_hw *sfs;
int max_fn;
u16 start_fn_id;
u32 controller;
};
enum {
MLX5_SF_HWC_LOCAL,
MLX5_SF_HWC_EXT_HOST,
MLX5_SF_HWC_FIRST_SPF,
};
struct mlx5_sf_hw_table {
struct mutex table_lock; /* Serializes sf deletion and vhca state change handler. */
struct mlx5_sf_hwc_table *hwc;
int num_hwc;
};
static struct mlx5_sf_hwc_table *
mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
int i;
for (i = MLX5_SF_HWC_FIRST_SPF; i < table->num_hwc; i++) {
if (table->hwc[i].controller == controller)
return &table->hwc[i];
}
return &table->hwc[!!controller];
}
u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u16 sw_id)
{
struct mlx5_sf_hwc_table *hwc;
hwc = mlx5_sf_controller_to_hwc(dev, controller);
return hwc->start_fn_id + sw_id;
}
static u16 mlx5_sf_hw_to_sw_id(struct mlx5_sf_hwc_table *hwc, u16 hw_id)
{
return hw_id - hwc->start_fn_id;
}
static struct mlx5_sf_hwc_table *
mlx5_sf_table_fn_to_hwc(struct mlx5_sf_hw_table *table, u16 fn_id)
{
int i;
for (i = 0; i < table->num_hwc; i++) {
if (table->hwc[i].max_fn &&
fn_id >= table->hwc[i].start_fn_id &&
fn_id < (table->hwc[i].start_fn_id + table->hwc[i].max_fn))
return &table->hwc[i];
}
return NULL;
}
static int mlx5_sf_hw_table_id_alloc(struct mlx5_core_dev *dev,
struct mlx5_sf_hw_table *table,
u32 controller,
u32 usr_sfnum)
{
struct mlx5_sf_hwc_table *hwc;
int free_idx = -1;
int i;
hwc = mlx5_sf_controller_to_hwc(dev, controller);
if (!hwc->sfs)
return -ENOSPC;
for (i = 0; i < hwc->max_fn; i++) {
if (!hwc->sfs[i].allocated && free_idx == -1) {
free_idx = i;
continue;
}
if (hwc->sfs[i].allocated && hwc->sfs[i].usr_sfnum == usr_sfnum)
return -EEXIST;
}
if (free_idx == -1)
Annotation
- Immediate include surface: `linux/mlx5/driver.h`, `vhca_event.h`, `priv.h`, `sf.h`, `mlx5_ifc_vhca_event.h`, `ecpf.h`, `mlx5_core.h`, `eswitch.h`.
- Detected declarations: `struct mlx5_sf_hw`, `struct mlx5_sf_hwc_table`, `struct mlx5_sf_hw_table`, `function mlx5_sf_controller_to_hwc`, `function mlx5_sf_sw_to_hw_id`, `function mlx5_sf_hw_to_sw_id`, `function mlx5_sf_table_fn_to_hwc`, `function mlx5_sf_hw_table_id_alloc`, `function mlx5_sf_hw_table_id_free`, `function mlx5_sf_hw_table_sf_alloc`.
- 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.