1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3 
4 #ifndef HWS_CONTEXT_H_
5 #define HWS_CONTEXT_H_
6 
7 enum mlx5hws_context_flags {
8 	MLX5HWS_CONTEXT_FLAG_HWS_SUPPORT = 1 << 0,
9 	MLX5HWS_CONTEXT_FLAG_PRIVATE_PD = 1 << 1,
10 	MLX5HWS_CONTEXT_FLAG_BWC_SUPPORT = 1 << 2,
11 	MLX5HWS_CONTEXT_FLAG_NATIVE_SUPPORT = 1 << 3,
12 };
13 
14 enum mlx5hws_context_shared_stc_type {
15 	MLX5HWS_CONTEXT_SHARED_STC_DECAP_L3 = 0,
16 	MLX5HWS_CONTEXT_SHARED_STC_DOUBLE_POP = 1,
17 	MLX5HWS_CONTEXT_SHARED_STC_MAX = 2,
18 };
19 
20 struct mlx5hws_context_common_res {
21 	struct mlx5hws_action_default_stc *default_stc;
22 	struct mlx5hws_action_shared_stc *shared_stc[MLX5HWS_CONTEXT_SHARED_STC_MAX];
23 	struct mlx5hws_cmd_forward_tbl *default_miss;
24 };
25 
26 struct mlx5hws_context_debug_info {
27 	struct dentry *steering_debugfs;
28 	struct dentry *fdb_debugfs;
29 };
30 
31 struct mlx5hws_context_vports {
32 	u16 esw_manager_gvmi;
33 	u16 uplink_gvmi;
34 	struct xarray vport_gvmi_xa;
35 };
36 
37 struct mlx5hws_context {
38 	struct mlx5_core_dev *mdev;
39 	struct mlx5hws_cmd_query_caps *caps;
40 	u32 pd_num;
41 	struct mlx5hws_pool *stc_pool;
42 	struct mlx5hws_context_common_res common_res;
43 	struct mlx5hws_pattern_cache *pattern_cache;
44 	struct mlx5hws_definer_cache *definer_cache;
45 	struct mutex ctrl_lock; /* control lock to protect the whole context */
46 	enum mlx5hws_context_flags flags;
47 	struct mlx5hws_send_engine *send_queue;
48 	size_t queues;
49 	struct mutex *bwc_send_queue_locks; /* protect BWC queues */
50 	struct lock_class_key *bwc_lock_class_keys;
51 	struct list_head tbl_list;
52 	struct mlx5hws_context_debug_info debug_info;
53 	struct xarray peer_ctx_xa;
54 	struct mlx5hws_context_vports vports;
55 };
56 
mlx5hws_context_bwc_supported(struct mlx5hws_context * ctx)57 static inline bool mlx5hws_context_bwc_supported(struct mlx5hws_context *ctx)
58 {
59 	return ctx->flags & MLX5HWS_CONTEXT_FLAG_BWC_SUPPORT;
60 }
61 
mlx5hws_context_native_supported(struct mlx5hws_context * ctx)62 static inline bool mlx5hws_context_native_supported(struct mlx5hws_context *ctx)
63 {
64 	return ctx->flags & MLX5HWS_CONTEXT_FLAG_NATIVE_SUPPORT;
65 }
66 
67 bool mlx5hws_context_cap_dynamic_reparse(struct mlx5hws_context *ctx);
68 
69 u8 mlx5hws_context_get_reparse_mode(struct mlx5hws_context *ctx);
70 
71 #endif /* HWS_CONTEXT_H_ */
72