fs.h 1.4 KB

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