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