1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2019 Mellanox Technologies. */
3
4 #include <linux/types.h>
5 #include "dr_types.h"
6
7 struct mlx5dr_fw_recalc_cs_ft *
mlx5dr_fw_create_recalc_cs_ft(struct mlx5dr_domain * dmn,u16 vport_num)8 mlx5dr_fw_create_recalc_cs_ft(struct mlx5dr_domain *dmn, u16 vport_num)
9 {
10 struct mlx5dr_cmd_create_flow_table_attr ft_attr = {};
11 struct mlx5dr_fw_recalc_cs_ft *recalc_cs_ft;
12 u32 table_id, group_id, modify_hdr_id;
13 u64 rx_icm_addr, modify_ttl_action;
14 int ret;
15
16 recalc_cs_ft = kzalloc(sizeof(*recalc_cs_ft), GFP_KERNEL);
17 if (!recalc_cs_ft)
18 return NULL;
19
20 ft_attr.table_type = MLX5_FLOW_TABLE_TYPE_FDB;
21 ft_attr.level = dmn->info.caps.max_ft_level - 1;
22 ft_attr.term_tbl = true;
23
24 ret = mlx5dr_cmd_create_flow_table(dmn->mdev,
25 &ft_attr,
26 &rx_icm_addr,
27 &table_id);
28 if (ret) {
29 mlx5dr_err(dmn, "Failed creating TTL W/A FW flow table %d\n", ret);
30 goto free_ttl_tbl;
31 }
32
33 ret = mlx5dr_cmd_create_empty_flow_group(dmn->mdev,
34 MLX5_FLOW_TABLE_TYPE_FDB,
35 table_id, &group_id);
36 if (ret) {
37 mlx5dr_err(dmn, "Failed creating TTL W/A FW flow group %d\n", ret);
38 goto destroy_flow_table;
39 }
40
41 /* Modify TTL action by adding zero to trigger CS recalculation */
42 modify_ttl_action = 0;
43 MLX5_SET(set_action_in, &modify_ttl_action, action_type, MLX5_ACTION_TYPE_ADD);
44 MLX5_SET(set_action_in, &modify_ttl_action, field, MLX5_ACTION_IN_FIELD_OUT_IP_TTL);
45
46 ret = mlx5dr_cmd_alloc_modify_header(dmn->mdev, MLX5_FLOW_TABLE_TYPE_FDB, 1,
47 &modify_ttl_action,
48 &modify_hdr_id);
49 if (ret) {
50 mlx5dr_err(dmn, "Failed modify header TTL %d\n", ret);
51 goto destroy_flow_group;
52 }
53
54 ret = mlx5dr_cmd_set_fte_modify_and_vport(dmn->mdev,
55 MLX5_FLOW_TABLE_TYPE_FDB,
56 table_id, group_id, modify_hdr_id,
57 vport_num);
58 if (ret) {
59 mlx5dr_err(dmn, "Failed setting TTL W/A flow table entry %d\n", ret);
60 goto dealloc_modify_header;
61 }
62
63 recalc_cs_ft->modify_hdr_id = modify_hdr_id;
64 recalc_cs_ft->rx_icm_addr = rx_icm_addr;
65 recalc_cs_ft->table_id = table_id;
66 recalc_cs_ft->group_id = group_id;
67
68 return recalc_cs_ft;
69
70 dealloc_modify_header:
71 mlx5dr_cmd_dealloc_modify_header(dmn->mdev, modify_hdr_id);
72 destroy_flow_group:
73 mlx5dr_cmd_destroy_flow_group(dmn->mdev,
74 MLX5_FLOW_TABLE_TYPE_FDB,
75 table_id, group_id);
76 destroy_flow_table:
77 mlx5dr_cmd_destroy_flow_table(dmn->mdev, table_id, MLX5_FLOW_TABLE_TYPE_FDB);
78 free_ttl_tbl:
79 kfree(recalc_cs_ft);
80 return NULL;
81 }
82
mlx5dr_fw_destroy_recalc_cs_ft(struct mlx5dr_domain * dmn,struct mlx5dr_fw_recalc_cs_ft * recalc_cs_ft)83 void mlx5dr_fw_destroy_recalc_cs_ft(struct mlx5dr_domain *dmn,
84 struct mlx5dr_fw_recalc_cs_ft *recalc_cs_ft)
85 {
86 mlx5dr_cmd_del_flow_table_entry(dmn->mdev,
87 MLX5_FLOW_TABLE_TYPE_FDB,
88 recalc_cs_ft->table_id);
89 mlx5dr_cmd_dealloc_modify_header(dmn->mdev, recalc_cs_ft->modify_hdr_id);
90 mlx5dr_cmd_destroy_flow_group(dmn->mdev,
91 MLX5_FLOW_TABLE_TYPE_FDB,
92 recalc_cs_ft->table_id,
93 recalc_cs_ft->group_id);
94 mlx5dr_cmd_destroy_flow_table(dmn->mdev,
95 recalc_cs_ft->table_id,
96 MLX5_FLOW_TABLE_TYPE_FDB);
97
98 kfree(recalc_cs_ft);
99 }
100
mlx5dr_fw_create_md_tbl(struct mlx5dr_domain * dmn,struct mlx5dr_cmd_flow_destination_hw_info * dest,int num_dest,bool reformat_req,u32 * tbl_id,u32 * group_id,bool ignore_flow_level,u32 flow_source)101 int mlx5dr_fw_create_md_tbl(struct mlx5dr_domain *dmn,
102 struct mlx5dr_cmd_flow_destination_hw_info *dest,
103 int num_dest,
104 bool reformat_req,
105 u32 *tbl_id,
106 u32 *group_id,
107 bool ignore_flow_level,
108 u32 flow_source)
109 {
110 struct mlx5dr_cmd_create_flow_table_attr ft_attr = {};
111 struct mlx5dr_cmd_fte_info fte_info = {};
112 u32 val[MLX5_ST_SZ_DW_MATCH_PARAM] = {};
113 struct mlx5dr_cmd_ft_info ft_info = {};
114 int ret;
115
116 ft_attr.table_type = MLX5_FLOW_TABLE_TYPE_FDB;
117 ft_attr.level = min_t(int, dmn->info.caps.max_ft_level - 2,
118 MLX5_FT_MAX_MULTIPATH_LEVEL);
119 ft_attr.reformat_en = reformat_req;
120 ft_attr.decap_en = reformat_req;
121
122 ret = mlx5dr_cmd_create_flow_table(dmn->mdev, &ft_attr, NULL, tbl_id);
123 if (ret) {
124 mlx5dr_err(dmn, "Failed creating multi dest FW flow table %d\n", ret);
125 return ret;
126 }
127
128 ret = mlx5dr_cmd_create_empty_flow_group(dmn->mdev,
129 MLX5_FLOW_TABLE_TYPE_FDB,
130 *tbl_id, group_id);
131 if (ret) {
132 mlx5dr_err(dmn, "Failed creating multi dest FW flow group %d\n", ret);
133 goto free_flow_table;
134 }
135
136 ft_info.id = *tbl_id;
137 ft_info.type = FS_FT_FDB;
138 fte_info.action.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
139 fte_info.dests_size = num_dest;
140 fte_info.val = val;
141 fte_info.dest_arr = dest;
142 fte_info.ignore_flow_level = ignore_flow_level;
143 fte_info.flow_context.flow_source = flow_source;
144
145 ret = mlx5dr_cmd_set_fte(dmn->mdev, 0, 0, &ft_info, *group_id, &fte_info);
146 if (ret) {
147 mlx5dr_err(dmn, "Failed setting fte into table %d\n", ret);
148 goto free_flow_group;
149 }
150
151 return 0;
152
153 free_flow_group:
154 mlx5dr_cmd_destroy_flow_group(dmn->mdev, MLX5_FLOW_TABLE_TYPE_FDB,
155 *tbl_id, *group_id);
156 free_flow_table:
157 mlx5dr_cmd_destroy_flow_table(dmn->mdev, *tbl_id,
158 MLX5_FLOW_TABLE_TYPE_FDB);
159 return ret;
160 }
161
mlx5dr_fw_destroy_md_tbl(struct mlx5dr_domain * dmn,u32 tbl_id,u32 group_id)162 void mlx5dr_fw_destroy_md_tbl(struct mlx5dr_domain *dmn,
163 u32 tbl_id, u32 group_id)
164 {
165 mlx5dr_cmd_del_flow_table_entry(dmn->mdev, FS_FT_FDB, tbl_id);
166 mlx5dr_cmd_destroy_flow_group(dmn->mdev,
167 MLX5_FLOW_TABLE_TYPE_FDB,
168 tbl_id, group_id);
169 mlx5dr_cmd_destroy_flow_table(dmn->mdev, tbl_id,
170 MLX5_FLOW_TABLE_TYPE_FDB);
171 }
172