drivers/net/ethernet/mellanox/mlx5/core/rl.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/rl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/rl.c- Extension
.c- Size
- 13192 bytes
- Lines
- 460
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/mlx5/driver.hmlx5_core.h
Detected Declarations
function Copyrightfunction mlx5_qos_element_type_supportedfunction mlx5_create_scheduling_element_cmdfunction mlx5_modify_scheduling_element_cmdfunction mlx5_destroy_scheduling_element_cmdfunction mlx5_rl_are_equal_rawfunction mlx5_set_pp_rate_limit_cmdfunction mlx5_rl_is_in_rangefunction mlx5_rl_are_equalfunction mlx5_rl_table_getfunction mlx5_rl_table_putfunction mlx5_rl_table_freefunction mlx5_rl_entry_getfunction mlx5_rl_entry_putfunction mlx5_rl_add_rate_rawfunction mlx5_rl_remove_rate_rawfunction mlx5_rl_add_ratefunction mlx5_rl_remove_ratefunction mlx5_init_rl_tablefunction mlx5_cleanup_rl_tableexport mlx5_rl_is_in_rangeexport mlx5_rl_are_equalexport mlx5_rl_add_rate_rawexport mlx5_rl_remove_rate_rawexport mlx5_rl_add_rateexport mlx5_rl_remove_rate
Annotated Snippet
if (dedicated) {
if (!table->rl_entry[i].refcount)
return &table->rl_entry[i];
continue;
}
if (table->rl_entry[i].refcount) {
if (table->rl_entry[i].dedicated)
continue;
if (mlx5_rl_are_equal_raw(&table->rl_entry[i], rl_in,
uid))
return &table->rl_entry[i];
} else if (!empty_found) {
empty_found = true;
ret_entry = &table->rl_entry[i];
}
}
return ret_entry;
}
static int mlx5_set_pp_rate_limit_cmd(struct mlx5_core_dev *dev,
struct mlx5_rl_entry *entry, bool set)
{
u32 in[MLX5_ST_SZ_DW(set_pp_rate_limit_in)] = {};
void *pp_context;
pp_context = MLX5_ADDR_OF(set_pp_rate_limit_in, in, ctx);
MLX5_SET(set_pp_rate_limit_in, in, opcode,
MLX5_CMD_OP_SET_PP_RATE_LIMIT);
MLX5_SET(set_pp_rate_limit_in, in, uid, entry->uid);
MLX5_SET(set_pp_rate_limit_in, in, rate_limit_index, entry->index);
if (set)
memcpy(pp_context, entry->rl_raw, sizeof(entry->rl_raw));
return mlx5_cmd_exec_in(dev, set_pp_rate_limit, in);
}
bool mlx5_rl_is_in_range(struct mlx5_core_dev *dev, u32 rate)
{
struct mlx5_rl_table *table = &dev->priv.rl_table;
return (rate <= table->max_rate && rate >= table->min_rate);
}
EXPORT_SYMBOL(mlx5_rl_is_in_range);
bool mlx5_rl_are_equal(struct mlx5_rate_limit *rl_0,
struct mlx5_rate_limit *rl_1)
{
return ((rl_0->rate == rl_1->rate) &&
(rl_0->max_burst_sz == rl_1->max_burst_sz) &&
(rl_0->typical_pkt_sz == rl_1->typical_pkt_sz));
}
EXPORT_SYMBOL(mlx5_rl_are_equal);
static int mlx5_rl_table_get(struct mlx5_rl_table *table)
{
int i;
lockdep_assert_held(&table->rl_lock);
if (table->rl_entry) {
table->refcount++;
return 0;
}
table->rl_entry = kzalloc_objs(struct mlx5_rl_entry, table->max_size);
if (!table->rl_entry)
return -ENOMEM;
/* The index represents the index in HW rate limit table
* Index 0 is reserved for unlimited rate
*/
for (i = 0; i < table->max_size; i++)
table->rl_entry[i].index = i + 1;
table->refcount++;
return 0;
}
static void mlx5_rl_table_put(struct mlx5_rl_table *table)
{
lockdep_assert_held(&table->rl_lock);
if (--table->refcount)
return;
kfree(table->rl_entry);
table->rl_entry = NULL;
}
static void mlx5_rl_table_free(struct mlx5_core_dev *dev, struct mlx5_rl_table *table)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mlx5/driver.h`, `mlx5_core.h`.
- Detected declarations: `function Copyright`, `function mlx5_qos_element_type_supported`, `function mlx5_create_scheduling_element_cmd`, `function mlx5_modify_scheduling_element_cmd`, `function mlx5_destroy_scheduling_element_cmd`, `function mlx5_rl_are_equal_raw`, `function mlx5_set_pp_rate_limit_cmd`, `function mlx5_rl_is_in_range`, `function mlx5_rl_are_equal`, `function mlx5_rl_table_get`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration 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.