drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c- Extension
.c- Size
- 16137 bytes
- Lines
- 597
- 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/iopoll.hlinux/math64.hlib/aso.hen/tc/post_act.hmeter.hen/tc_priv.h
Detected Declarations
struct mlx5e_flow_meter_aso_objstruct mlx5e_flow_metersfunction mlx5e_flow_meter_cir_calcfunction mlx5e_flow_meter_cbs_calcfunction mlx5e_tc_meter_modifyfunction mlx5e_flow_meter_create_aso_objfunction mlx5e_flow_meter_destroy_aso_objfunction __mlx5e_flow_meter_allocfunction __mlx5e_flow_meter_freefunction __mlx5e_tc_meter_getfunction mlx5e_tc_meter_getfunction __mlx5e_tc_meter_putfunction mlx5e_tc_meter_putfunction mlx5e_tc_meter_allocfunction __mlx5e_tc_meter_updatefunction mlx5e_tc_meter_updatefunction mlx5e_tc_meter_replacefunction mlx5e_tc_meter_get_namespacefunction mlx5e_flow_meters_initfunction mlx5e_flow_meters_cleanupfunction mlx5e_tc_meter_get_statsfunction mlx5e_flow_meter_get_base_id
Annotated Snippet
struct mlx5e_flow_meter_aso_obj {
struct list_head entry;
int base_id;
int total_meters;
unsigned long meters_map[]; /* must be at the end of this struct */
};
struct mlx5e_flow_meters {
enum mlx5_flow_namespace_type ns_type;
struct mlx5_aso *aso;
struct mutex aso_lock; /* Protects aso operations */
int log_granularity;
u32 pdn;
DECLARE_HASHTABLE(hashtbl, 8);
struct mutex sync_lock; /* protect flow meter operations */
struct list_head partial_list;
struct list_head full_list;
struct mlx5_core_dev *mdev;
struct mlx5e_post_act *post_act;
};
static void
mlx5e_flow_meter_cir_calc(u64 cir, u8 *man, u8 *exp)
{
s64 _cir, _delta, delta = S64_MAX;
u8 e, _man = 0, _exp = 0;
u64 m;
for (e = 0; e <= 0x1F; e++) { /* exp width 5bit */
m = cir << e;
if ((s64)m < 0) /* overflow */
break;
m = div64_u64(m, MLX5_CONST_CIR);
if (m > 0xFF) /* man width 8 bit */
continue;
_cir = MLX5_CALC_CIR(m, e);
_delta = cir - _cir;
if (_delta < delta) {
_man = m;
_exp = e;
if (!_delta)
goto found;
delta = _delta;
}
}
found:
*man = _man;
*exp = _exp;
}
static void
mlx5e_flow_meter_cbs_calc(u64 cbs, u8 *man, u8 *exp)
{
s64 _cbs, _delta, delta = S64_MAX;
u8 e, _man = 0, _exp = 0;
u64 m;
for (e = 0; e <= 0x1F; e++) { /* exp width 5bit */
m = cbs >> e;
if (m > 0xFF) /* man width 8 bit */
continue;
_cbs = MLX5_CALC_CBS(m, e);
_delta = cbs - _cbs;
if (_delta < delta) {
_man = m;
_exp = e;
if (!_delta)
goto found;
delta = _delta;
}
}
found:
*man = _man;
*exp = _exp;
}
int
mlx5e_tc_meter_modify(struct mlx5_core_dev *mdev,
struct mlx5e_flow_meter_handle *meter,
struct mlx5e_flow_meter_params *meter_params)
{
struct mlx5_wqe_aso_ctrl_seg *aso_ctrl;
struct mlx5_wqe_aso_data_seg *aso_data;
struct mlx5e_flow_meters *flow_meters;
Annotation
- Immediate include surface: `linux/iopoll.h`, `linux/math64.h`, `lib/aso.h`, `en/tc/post_act.h`, `meter.h`, `en/tc_priv.h`.
- Detected declarations: `struct mlx5e_flow_meter_aso_obj`, `struct mlx5e_flow_meters`, `function mlx5e_flow_meter_cir_calc`, `function mlx5e_flow_meter_cbs_calc`, `function mlx5e_tc_meter_modify`, `function mlx5e_flow_meter_create_aso_obj`, `function mlx5e_flow_meter_destroy_aso_obj`, `function __mlx5e_flow_meter_alloc`, `function __mlx5e_flow_meter_free`, `function __mlx5e_tc_meter_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.