xref: /openbmc/linux/drivers/infiniband/hw/mlx5/fs.h (revision 83146efc)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /*
3  * Copyright (c) 2013-2020, Mellanox Technologies inc. All rights reserved.
4  */
5 
6 #ifndef _MLX5_IB_FS_H
7 #define _MLX5_IB_FS_H
8 
9 #include "mlx5_ib.h"
10 
11 #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
12 int mlx5_ib_fs_init(struct mlx5_ib_dev *dev);
13 void mlx5_ib_fs_cleanup_anchor(struct mlx5_ib_dev *dev);
14 #else
15 static inline int mlx5_ib_fs_init(struct mlx5_ib_dev *dev)
16 {
17 	dev->flow_db = kzalloc(sizeof(*dev->flow_db), GFP_KERNEL);
18 
19 	if (!dev->flow_db)
20 		return -ENOMEM;
21 
22 	mutex_init(&dev->flow_db->lock);
23 	return 0;
24 }
25 
26 inline void mlx5_ib_fs_cleanup_anchor(struct mlx5_ib_dev *dev) {}
27 #endif
28 
29 static inline void mlx5_ib_fs_cleanup(struct mlx5_ib_dev *dev)
30 {
31 	/* When a steering anchor is created, a special flow table is also
32 	 * created for the user to reference. Since the user can reference it,
33 	 * the kernel cannot trust that when the user destroys the steering
34 	 * anchor, they no longer reference the flow table.
35 	 *
36 	 * To address this issue, when a user destroys a steering anchor, only
37 	 * the flow steering rule in the table is destroyed, but the table
38 	 * itself is kept to deal with the above scenario. The remaining
39 	 * resources are only removed when the RDMA device is destroyed, which
40 	 * is a safe assumption that all references are gone.
41 	 */
42 	mlx5_ib_fs_cleanup_anchor(dev);
43 	kfree(dev->flow_db);
44 }
45 #endif /* _MLX5_IB_FS_H */
46