Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
0002 /* Copyright (c) 2019 Mellanox Technologies */
0003 
0004 #ifndef __MLX5_MAPPING_H__
0005 #define __MLX5_MAPPING_H__
0006 
0007 struct mapping_ctx;
0008 
0009 int mapping_add(struct mapping_ctx *ctx, void *data, u32 *id);
0010 int mapping_remove(struct mapping_ctx *ctx, u32 id);
0011 int mapping_find(struct mapping_ctx *ctx, u32 id, void *data);
0012 
0013 /* mapping uses an xarray to map data to ids in add(), and for find().
0014  * For locking, it uses a internal xarray spin lock for add()/remove(),
0015  * find() uses rcu_read_lock().
0016  * Choosing delayed_removal postpones the removal of a previously mapped
0017  * id by MAPPING_GRACE_PERIOD milliseconds.
0018  * This is to avoid races against hardware, where we mark the packet in
0019  * hardware with a previous id, and quick remove() and add() reusing the same
0020  * previous id. Then find() will get the new mapping instead of the old
0021  * which was used to mark the packet.
0022  */
0023 struct mapping_ctx *mapping_create(size_t data_size, u32 max_id,
0024                    bool delayed_removal);
0025 void mapping_destroy(struct mapping_ctx *ctx);
0026 
0027 /* adds mapping with an id or get an existing mapping with the same id
0028  */
0029 struct mapping_ctx *
0030 mapping_create_for_id(u64 id, u8 type, size_t data_size, u32 max_id, bool delayed_removal);
0031 
0032 #endif /* __MLX5_MAPPING_H__ */