1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019 Mellanox Technologies */
3 
4 #ifndef __MLX5_MAPPING_H__
5 #define __MLX5_MAPPING_H__
6 
7 struct mapping_ctx;
8 
9 int mapping_add(struct mapping_ctx *ctx, void *data, u32 *id);
10 int mapping_remove(struct mapping_ctx *ctx, u32 id);
11 int mapping_find(struct mapping_ctx *ctx, u32 id, void *data);
12 
13 /* mapping uses an xarray to map data to ids in add(), and for find().
14  * For locking, it uses a internal xarray spin lock for add()/remove(),
15  * find() uses rcu_read_lock().
16  * Choosing delayed_removal postpones the removal of a previously mapped
17  * id by MAPPING_GRACE_PERIOD milliseconds.
18  * This is to avoid races against hardware, where we mark the packet in
19  * hardware with a previous id, and quick remove() and add() reusing the same
20  * previous id. Then find() will get the new mapping instead of the old
21  * which was used to mark the packet.
22  */
23 struct mapping_ctx *mapping_create(size_t data_size, u32 max_id,
24 				   bool delayed_removal);
25 void mapping_destroy(struct mapping_ctx *ctx);
26 
27 /* adds mapping with an id or get an existing mapping with the same id
28  */
29 struct mapping_ctx *
30 mapping_create_for_id(u64 id, u8 type, size_t data_size, u32 max_id, bool delayed_removal);
31 
32 #endif /* __MLX5_MAPPING_H__ */
33