xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_rule.h (revision 9410645520e9b820069761f3450ef6661418e279)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3 
4 #ifndef MLX5HWS_RULE_H_
5 #define MLX5HWS_RULE_H_
6 
7 enum {
8 	MLX5HWS_STE_CTRL_SZ = 20,
9 	MLX5HWS_ACTIONS_SZ = 12,
10 	MLX5HWS_MATCH_TAG_SZ = 32,
11 	MLX5HWS_JUMBO_TAG_SZ = 44,
12 };
13 
14 enum mlx5hws_rule_status {
15 	MLX5HWS_RULE_STATUS_UNKNOWN,
16 	MLX5HWS_RULE_STATUS_CREATING,
17 	MLX5HWS_RULE_STATUS_CREATED,
18 	MLX5HWS_RULE_STATUS_DELETING,
19 	MLX5HWS_RULE_STATUS_DELETED,
20 	MLX5HWS_RULE_STATUS_FAILING,
21 	MLX5HWS_RULE_STATUS_FAILED,
22 };
23 
24 enum mlx5hws_rule_move_state {
25 	MLX5HWS_RULE_RESIZE_STATE_IDLE,
26 	MLX5HWS_RULE_RESIZE_STATE_WRITING,
27 	MLX5HWS_RULE_RESIZE_STATE_DELETING,
28 };
29 
30 enum mlx5hws_rule_jumbo_match_tag_offset {
31 	MLX5HWS_RULE_JUMBO_MATCH_TAG_OFFSET_DW0 = 8,
32 };
33 
34 struct mlx5hws_rule_match_tag {
35 	union {
36 		u8 jumbo[MLX5HWS_JUMBO_TAG_SZ];
37 		struct {
38 			u8 reserved[MLX5HWS_ACTIONS_SZ];
39 			u8 match[MLX5HWS_MATCH_TAG_SZ];
40 		};
41 	};
42 };
43 
44 struct mlx5hws_rule_resize_info {
45 	struct mlx5hws_pool *action_ste_pool[2];
46 	u32 rtc_0;
47 	u32 rtc_1;
48 	u32 rule_idx;
49 	u8 state;
50 	u8 max_stes;
51 	u8 ctrl_seg[MLX5HWS_WQE_SZ_GTA_CTRL]; /* Ctrl segment of STE: 48 bytes */
52 	u8 data_seg[MLX5HWS_WQE_SZ_GTA_DATA]; /* Data segment of STE: 64 bytes */
53 };
54 
55 struct mlx5hws_rule {
56 	struct mlx5hws_matcher *matcher;
57 	union {
58 		struct mlx5hws_rule_match_tag tag;
59 		struct mlx5hws_rule_resize_info *resize_info;
60 	};
61 	u32 rtc_0; /* The RTC into which the STE was inserted */
62 	u32 rtc_1; /* The RTC into which the STE was inserted */
63 	int action_ste_idx; /* STE array index */
64 	u8 status; /* enum mlx5hws_rule_status */
65 	u8 action_ste_selector; /* For rule update - which action STE is in use */
66 	u8 pending_wqes;
67 	bool skip_delete; /* For complex rules - another rule with same tag
68 			   * still exists, so don't actually delete this rule.
69 			   */
70 };
71 
72 void mlx5hws_rule_free_action_ste(struct mlx5hws_rule *rule);
73 
74 int mlx5hws_rule_move_hws_remove(struct mlx5hws_rule *rule,
75 				 void *queue, void *user_data);
76 
77 int mlx5hws_rule_move_hws_add(struct mlx5hws_rule *rule,
78 			      struct mlx5hws_rule_attr *attr);
79 
80 bool mlx5hws_rule_move_in_progress(struct mlx5hws_rule *rule);
81 
82 void mlx5hws_rule_clear_resize_info(struct mlx5hws_rule *rule);
83 
84 #endif /* MLX5HWS_RULE_H_ */
85