drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_ptrn.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_ptrn.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_ptrn.c- Extension
.c- Size
- 6084 bytes
- Lines
- 245
- 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
dr_types.hmlx5_ifc_dr_ste_v1.h
Detected Declarations
struct mlx5dr_ptrn_mgrenum dr_ptrn_modify_hdr_action_idfunction dr_ptrn_compare_modify_hdrfunction dr_ptrn_find_cached_patternfunction list_for_each_entry_safefunction dr_ptrn_alloc_patternfunction dr_ptrn_free_patternfunction mlx5dr_ptrn_cache_get_patternfunction mlx5dr_ptrn_cache_put_patternfunction mlx5dr_ptrn_mgr_destroyfunction list_for_each_entry_safe
Annotated Snippet
struct mlx5dr_ptrn_mgr {
struct mlx5dr_domain *dmn;
struct mlx5dr_icm_pool *ptrn_icm_pool;
/* cache for modify_header ptrn */
struct list_head ptrn_list;
struct mutex modify_hdr_mutex; /* protect the pattern cache */
};
/* Cache structure and functions */
static bool dr_ptrn_compare_modify_hdr(size_t cur_num_of_actions,
__be64 cur_hw_actions[],
size_t num_of_actions,
__be64 hw_actions[])
{
int i;
if (cur_num_of_actions != num_of_actions)
return false;
for (i = 0; i < num_of_actions; i++) {
u8 action_id =
MLX5_GET(ste_double_action_set_v1, &hw_actions[i], action_id);
if (action_id == DR_PTRN_MODIFY_HDR_ACTION_ID_COPY) {
if (hw_actions[i] != cur_hw_actions[i])
return false;
} else {
if ((__force __be32)hw_actions[i] !=
(__force __be32)cur_hw_actions[i])
return false;
}
}
return true;
}
static struct mlx5dr_ptrn_obj *
dr_ptrn_find_cached_pattern(struct mlx5dr_ptrn_mgr *mgr,
size_t num_of_actions,
__be64 hw_actions[])
{
struct mlx5dr_ptrn_obj *cached_pattern;
struct mlx5dr_ptrn_obj *tmp;
list_for_each_entry_safe(cached_pattern, tmp, &mgr->ptrn_list, list) {
if (dr_ptrn_compare_modify_hdr(cached_pattern->num_of_actions,
(__be64 *)cached_pattern->data,
num_of_actions,
hw_actions)) {
/* Put this pattern in the head of the list,
* as we will probably use it more.
*/
list_del_init(&cached_pattern->list);
list_add(&cached_pattern->list, &mgr->ptrn_list);
return cached_pattern;
}
}
return NULL;
}
static struct mlx5dr_ptrn_obj *
dr_ptrn_alloc_pattern(struct mlx5dr_ptrn_mgr *mgr,
u16 num_of_actions, u8 *data)
{
struct mlx5dr_ptrn_obj *pattern;
struct mlx5dr_icm_chunk *chunk;
u32 chunk_size;
u32 index;
chunk_size = ilog2(roundup_pow_of_two(num_of_actions));
/* HW modify action index granularity is at least 64B */
chunk_size = max_t(u32, chunk_size, DR_CHUNK_SIZE_8);
chunk = mlx5dr_icm_alloc_chunk(mgr->ptrn_icm_pool, chunk_size);
if (!chunk)
return NULL;
index = (mlx5dr_icm_pool_get_chunk_icm_addr(chunk) -
mgr->dmn->info.caps.hdr_modify_pattern_icm_addr) /
DR_ACTION_CACHE_LINE_SIZE;
pattern = kzalloc_obj(*pattern);
if (!pattern)
goto free_chunk;
pattern->data = kzalloc(num_of_actions * DR_MODIFY_ACTION_SIZE *
sizeof(*pattern->data), GFP_KERNEL);
if (!pattern->data)
goto free_pattern;
Annotation
- Immediate include surface: `dr_types.h`, `mlx5_ifc_dr_ste_v1.h`.
- Detected declarations: `struct mlx5dr_ptrn_mgr`, `enum dr_ptrn_modify_hdr_action_id`, `function dr_ptrn_compare_modify_hdr`, `function dr_ptrn_find_cached_pattern`, `function list_for_each_entry_safe`, `function dr_ptrn_alloc_pattern`, `function dr_ptrn_free_pattern`, `function mlx5dr_ptrn_cache_get_pattern`, `function mlx5dr_ptrn_cache_put_pattern`, `function mlx5dr_ptrn_mgr_destroy`.
- 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.