| 1 |
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
| 2 |
/* Copyright (c) 2024 NVIDIA Corporation & Affiliates */ |
| 3 |
|
| 4 |
#ifndef MLX5HWS_H_ |
| 5 |
#define MLX5HWS_H_ |
| 6 |
|
| 7 |
struct mlx5hws_context; |
| 8 |
struct mlx5hws_table; |
| 9 |
struct mlx5hws_matcher; |
| 10 |
struct mlx5hws_rule; |
| 11 |
|
| 12 |
enum mlx5hws_table_type { |
| 13 |
MLX5HWS_TABLE_TYPE_FDB, |
| 14 |
MLX5HWS_TABLE_TYPE_MAX, |
| 15 |
}; |
| 16 |
|
| 17 |
enum mlx5hws_matcher_resource_mode { |
| 18 |
/* Allocate resources based on number of rules with minimal failure probability */ |
| 19 |
MLX5HWS_MATCHER_RESOURCE_MODE_RULE, |
| 20 |
/* Allocate fixed size hash table based on given column and rows */ |
| 21 |
MLX5HWS_MATCHER_RESOURCE_MODE_HTABLE, |
| 22 |
}; |
| 23 |
|
| 24 |
enum mlx5hws_action_type { |
| 25 |
MLX5HWS_ACTION_TYP_LAST, |
| 26 |
MLX5HWS_ACTION_TYP_REFORMAT_TNL_L2_TO_L2, |
| 27 |
MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L2, |
| 28 |
MLX5HWS_ACTION_TYP_REFORMAT_TNL_L3_TO_L2, |
| 29 |
MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L3, |
| 30 |
MLX5HWS_ACTION_TYP_DROP, |
| 31 |
MLX5HWS_ACTION_TYP_MISS, |
| 32 |
MLX5HWS_ACTION_TYP_TBL, |
| 33 |
MLX5HWS_ACTION_TYP_CTR, |
| 34 |
MLX5HWS_ACTION_TYP_TAG, |
| 35 |
MLX5HWS_ACTION_TYP_MODIFY_HDR, |
| 36 |
MLX5HWS_ACTION_TYP_VPORT, |
| 37 |
MLX5HWS_ACTION_TYP_POP_VLAN, |
| 38 |
MLX5HWS_ACTION_TYP_PUSH_VLAN, |
| 39 |
MLX5HWS_ACTION_TYP_ASO_METER, |
| 40 |
MLX5HWS_ACTION_TYP_INSERT_HEADER, |
| 41 |
MLX5HWS_ACTION_TYP_REMOVE_HEADER, |
| 42 |
MLX5HWS_ACTION_TYP_RANGE, |
| 43 |
MLX5HWS_ACTION_TYP_SAMPLER, |
| 44 |
MLX5HWS_ACTION_TYP_DEST_ARRAY, |
| 45 |
MLX5HWS_ACTION_TYP_MAX, |
| 46 |
}; |
| 47 |
|
| 48 |
enum mlx5hws_action_flags { |
| 49 |
MLX5HWS_ACTION_FLAG_HWS_FDB = 1 << 0, |
| 50 |
/* Shared action can be used over a few threads, since the |
| 51 |
* data is written only once at the creation of the action. |
| 52 |
*/ |
| 53 |
MLX5HWS_ACTION_FLAG_SHARED = 1 << 1, |
| 54 |
}; |
| 55 |
|
| 56 |
enum mlx5hws_action_aso_meter_color { |
| 57 |
MLX5HWS_ACTION_ASO_METER_COLOR_RED = 0x0, |
| 58 |
MLX5HWS_ACTION_ASO_METER_COLOR_YELLOW = 0x1, |
| 59 |
MLX5HWS_ACTION_ASO_METER_COLOR_GREEN = 0x2, |
| 60 |
MLX5HWS_ACTION_ASO_METER_COLOR_UNDEFINED = 0x3, |
| 61 |
}; |
| 62 |
|
| 63 |
enum mlx5hws_send_queue_actions { |
| 64 |
/* Start executing all pending queued rules */ |
| 65 |
MLX5HWS_SEND_QUEUE_ACTION_DRAIN_ASYNC = 1 << 0, |
| 66 |
/* Start executing all pending queued rules wait till completion */ |
| 67 |
MLX5HWS_SEND_QUEUE_ACTION_DRAIN_SYNC = 1 << 1, |
| 68 |
}; |
| 69 |
|
| 70 |
struct mlx5hws_context_attr { |
| 71 |
u16 queues; |
| 72 |
u16 queue_size; |
| 73 |
}; |
| 74 |
|
| 75 |
struct mlx5hws_table_attr { |
| 76 |
enum mlx5hws_table_type type; |
| 77 |
u32 level; |
| 78 |
u16 uid; |
| 79 |
}; |
| 80 |
|
| 81 |
enum mlx5hws_matcher_flow_src { |
| 82 |
MLX5HWS_MATCHER_FLOW_SRC_ANY = 0x0, |
| 83 |
MLX5HWS_MATCHER_FLOW_SRC_WIRE = 0x1, |
| 84 |
MLX5HWS_MATCHER_FLOW_SRC_VPORT = 0x2, |
| 85 |
}; |
| 86 |
|
| 87 |
enum mlx5hws_matcher_insert_mode { |
| 88 |
MLX5HWS_MATCHER_INSERT_BY_HASH = 0x0, |
| 89 |
MLX5HWS_MATCHER_INSERT_BY_INDEX = 0x1, |
| 90 |
}; |
| 91 |
|
| 92 |
enum mlx5hws_matcher_distribute_mode { |
| 93 |
MLX5HWS_MATCHER_DISTRIBUTE_BY_HASH = 0x0, |
| 94 |
MLX5HWS_MATCHER_DISTRIBUTE_BY_LINEAR = 0x1, |
| 95 |
}; |
| 96 |
|
| 97 |
enum mlx5hws_matcher_size_type { |
| 98 |
MLX5HWS_MATCHER_SIZE_TYPE_RX, |
| 99 |
MLX5HWS_MATCHER_SIZE_TYPE_TX, |
| 100 |
MLX5HWS_MATCHER_SIZE_TYPE_MAX, |
| 101 |
}; |
| 102 |
|
| 103 |
union mlx5hws_matcher_size { |
| 104 |
struct { |
| 105 |
u8 sz_row_log; |
| 106 |
u8 sz_col_log; |
| 107 |
} table; |
| 108 |
|
| 109 |
struct { |
| 110 |
u8 num_log; |
| 111 |
} rule; |
| 112 |
}; |
| 113 |
|
| 114 |
struct mlx5hws_matcher_attr { |
| 115 |
/* Processing priority inside table */ |
| 116 |
u32 priority; |
| 117 |
/* Provide all rules with unique rule_idx in num_log range to reduce locking */ |
| 118 |
bool optimize_using_rule_idx; |
| 119 |
/* Resource mode and corresponding size */ |
| 120 |
enum mlx5hws_matcher_resource_mode mode; |
| 121 |
/* Optimize insertion in case packet origin is the same for all rules */ |
| 122 |
enum mlx5hws_matcher_flow_src optimize_flow_src; |
| 123 |
/* Define the insertion and distribution modes for this matcher */ |
| 124 |
enum mlx5hws_matcher_insert_mode insert_mode; |
| 125 |
enum mlx5hws_matcher_distribute_mode distribute_mode; |
| 126 |
/* Define whether the created matcher supports resizing into a bigger matcher */ |
| 127 |
bool resizable; |
| 128 |
union mlx5hws_matcher_size size[MLX5HWS_MATCHER_SIZE_TYPE_MAX]; |
| 129 |
/* Optional AT attach configuration - Max number of additional AT */ |
| 130 |
u8 max_num_of_at_attach; |
| 131 |
/* Optional end FT (miss FT ID) for match RTC (for isolated matcher) */ |
| 132 |
u32 isolated_matcher_end_ft_id; |
| 133 |
}; |
| 134 |
|
| 135 |
struct mlx5hws_rule_attr { |
| 136 |
void *user_data; |
| 137 |
/* Valid if matcher optimize_using_rule_idx is set or |
| 138 |
* if matcher is configured to insert rules by index. |
| 139 |
*/ |
| 140 |
u32 rule_idx; |
| 141 |
u32 flow_source; |
| 142 |
u16 queue_id; |
| 143 |
u32 burst:1; |
| 144 |
}; |
| 145 |
|
| 146 |
/* In actions that take offset, the offset is unique, pointing to a single |
| 147 |
* resource and the user should not reuse the same index because data changing |
| 148 |
* is not atomic. |
| 149 |
*/ |
| 150 |
struct mlx5hws_rule_action { |
| 151 |
struct mlx5hws_action *action; |
| 152 |
union { |
| 153 |
struct { |
| 154 |
u32 value; |
| 155 |
} tag; |
| 156 |
|
| 157 |
struct { |
| 158 |
u32 offset; |
| 159 |
} counter; |
| 160 |
|
| 161 |
struct { |
| 162 |
u32 offset; |
| 163 |
u8 *data; |
| 164 |
} modify_header; |
| 165 |
|
| 166 |
struct { |
| 167 |
u32 offset; |
| 168 |
u8 hdr_idx; |
| 169 |
u8 *data; |
| 170 |
} reformat; |
| 171 |
|
| 172 |
struct { |
| 173 |
__be32 vlan_hdr; |
| 174 |
} push_vlan; |
| 175 |
|
| 176 |
struct { |
| 177 |
u32 offset; |
| 178 |
enum mlx5hws_action_aso_meter_color init_color; |
| 179 |
} aso_meter; |
| 180 |
}; |
| 181 |
}; |
| 182 |
|
| 183 |
struct mlx5hws_action_reformat_header { |
| 184 |
size_t sz; |
| 185 |
void *data; |
| 186 |
}; |
| 187 |
|
| 188 |
struct mlx5hws_action_insert_header { |
| 189 |
struct mlx5hws_action_reformat_header hdr; |
| 190 |
/* PRM start anchor to which header will be inserted */ |
| 191 |
u8 anchor; |
| 192 |
/* Header insertion offset in bytes, from the start |
| 193 |
* anchor to the location where new header will be inserted. |
| 194 |
*/ |
| 195 |
u8 offset; |
| 196 |
/* Indicates this header insertion adds encapsulation header to the packet, |
| 197 |
* requiring device to update offloaded fields (for example IPv4 total length). |
| 198 |
*/ |
| 199 |
bool encap; |
| 200 |
}; |
| 201 |
|
| 202 |
struct mlx5hws_action_remove_header_attr { |
| 203 |
/* PRM start anchor from which header will be removed */ |
| 204 |
u8 anchor; |
| 205 |
/* Header remove offset in bytes, from the start |
| 206 |
* anchor to the location where remove header starts. |
| 207 |
*/ |
| 208 |
u8 offset; |
| 209 |
/* Indicates the removed header size in bytes */ |
| 210 |
size_t size; |
| 211 |
}; |
| 212 |
|
| 213 |
struct mlx5hws_action_mh_pattern { |
| 214 |
/* Byte size of modify actions provided by "data" */ |
| 215 |
size_t sz; |
| 216 |
/* PRM format modify actions pattern */ |
| 217 |
__be64 *data; |
| 218 |
}; |
| 219 |
|
| 220 |
struct mlx5hws_action_dest_attr { |
| 221 |
/* Required destination action to forward the packet */ |
| 222 |
struct mlx5hws_action *dest; |
| 223 |
/* Optional reformat action */ |
| 224 |
struct mlx5hws_action *reformat; |
| 225 |
bool is_wire_ft; |
| 226 |
}; |
| 227 |
|
| 228 |
/** |
| 229 |
* mlx5hws_is_supported - Check whether HWS is supported |
| 230 |
* |
| 231 |
* @mdev: The device to check. |
| 232 |
* |
| 233 |
* Return: true if supported, false otherwise. |
| 234 |
*/ |
| 235 |
static inline bool mlx5hws_is_supported(struct mlx5_core_dev *mdev) |
| 236 |
{ |
| 237 |
u8 ignore_flow_level_rtc_valid; |
| 238 |
u8 wqe_based_flow_table_update; |
| 239 |
|
| 240 |
wqe_based_flow_table_update = |
| 241 |
MLX5_CAP_GEN(mdev, wqe_based_flow_table_update_cap); |
| 242 |
ignore_flow_level_rtc_valid = |
| 243 |
MLX5_CAP_FLOWTABLE(mdev, |
| 244 |
flow_table_properties_nic_receive.ignore_flow_level_rtc_valid); |
| 245 |
|
| 246 |
return wqe_based_flow_table_update && ignore_flow_level_rtc_valid; |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* mlx5hws_context_open - Open a context used for direct rule insertion |
| 251 |
* using hardware steering. |
| 252 |
* |
| 253 |
* @mdev: The device to be used for HWS. |
| 254 |
* @attr: Attributes used for context open. |
| 255 |
* |
| 256 |
* Return: pointer to mlx5hws_context on success NULL otherwise. |
| 257 |
*/ |
| 258 |
struct mlx5hws_context * |
| 259 |
mlx5hws_context_open(struct mlx5_core_dev *mdev, |
| 260 |
struct mlx5hws_context_attr *attr); |
| 261 |
|
| 262 |
/** |
| 263 |
* mlx5hws_context_close - Close a context used for direct hardware steering. |
| 264 |
* |
| 265 |
* @ctx: mlx5hws context to close. |
| 266 |
* |
| 267 |
* Return: zero on success non zero otherwise. |
| 268 |
*/ |
| 269 |
int mlx5hws_context_close(struct mlx5hws_context *ctx); |
| 270 |
|
| 271 |
/** |
| 272 |
* mlx5hws_context_set_peer - Set a peer context. |
| 273 |
* Each context can have multiple contexts as peers. |
| 274 |
* |
| 275 |
* @ctx: The context in which the peer_ctx will be peered to it. |
| 276 |
* @peer_ctx: The peer context. |
| 277 |
* @peer_vhca_id: The peer context vhca id. |
| 278 |
*/ |
| 279 |
void mlx5hws_context_set_peer(struct mlx5hws_context *ctx, |
| 280 |
struct mlx5hws_context *peer_ctx, |
| 281 |
u16 peer_vhca_id); |
| 282 |
|
| 283 |
/** |
| 284 |
* mlx5hws_table_create - Create a new direct rule table. |
| 285 |
* Each table can contain multiple matchers. |
| 286 |
* |
| 287 |
* @ctx: The context in which the new table will be opened. |
| 288 |
* @attr: Attributes used for table creation. |
| 289 |
* |
| 290 |
* Return: pointer to mlx5hws_table on success NULL otherwise. |
| 291 |
*/ |
| 292 |
struct mlx5hws_table * |
| 293 |
mlx5hws_table_create(struct mlx5hws_context *ctx, |
| 294 |
struct mlx5hws_table_attr *attr); |
| 295 |
|
| 296 |
/** |
| 297 |
* mlx5hws_table_destroy - Destroy direct rule table. |
| 298 |
* |
| 299 |
* @tbl: Table to destroy. |
| 300 |
* |
| 301 |
* Return: zero on success non zero otherwise. |
| 302 |
*/ |
| 303 |
int mlx5hws_table_destroy(struct mlx5hws_table *tbl); |
| 304 |
|
| 305 |
/** |
| 306 |
* mlx5hws_table_get_id() - Get ID of the flow table. |
| 307 |
* |
| 308 |
* @tbl:Table to get ID of. |
| 309 |
* |
| 310 |
* Return: ID of the table. |
| 311 |
*/ |
| 312 |
u32 mlx5hws_table_get_id(struct mlx5hws_table *tbl); |
| 313 |
|
| 314 |
/** |
| 315 |
* mlx5hws_table_set_default_miss - Set default miss table for mlx5hws_table |
| 316 |
* by using another mlx5hws_table. |
| 317 |
* Traffic which all table matchers miss will be forwarded to miss table. |
| 318 |
* |
| 319 |
* @tbl: Source table |
| 320 |
* @miss_tbl: Target (miss) table, or NULL to remove current miss table |
| 321 |
* |
| 322 |
* Return: zero on success non zero otherwise. |
| 323 |
*/ |
| 324 |
int mlx5hws_table_set_default_miss(struct mlx5hws_table *tbl, |
| 325 |
struct mlx5hws_table *miss_tbl); |
| 326 |
|
| 327 |
/** |
| 328 |
* mlx5hws_match_template_create - Create a new match template based on items mask. |
| 329 |
* The match template will be used for matcher creation. |
| 330 |
* |
| 331 |
* @ctx: The context in which the new template will be created. |
| 332 |
* @match_param: Describe the mask based on PRM match parameters. |
| 333 |
* @match_param_sz: Size of match param buffer. |
| 334 |
* @match_criteria_enable: Bitmap for each sub-set in match_criteria buffer. |
| 335 |
* |
| 336 |
* Return: Pointer to mlx5hws_match_template on success, NULL otherwise. |
| 337 |
*/ |
| 338 |
struct mlx5hws_match_template * |
| 339 |
mlx5hws_match_template_create(struct mlx5hws_context *ctx, |
| 340 |
u32 *match_param, |
| 341 |
u32 match_param_sz, |
| 342 |
u8 match_criteria_enable); |
| 343 |
|
| 344 |
/** |
| 345 |
* mlx5hws_match_template_destroy - Destroy a match template. |
| 346 |
* |
| 347 |
* @mt: Match template to destroy. |
| 348 |
* |
| 349 |
* Return: Zero on success, non-zero otherwise. |
| 350 |
*/ |
| 351 |
int mlx5hws_match_template_destroy(struct mlx5hws_match_template *mt); |
| 352 |
|
| 353 |
/** |
| 354 |
* mlx5hws_action_template_create - Create a new action template based on an action_type array. |
| 355 |
* |
| 356 |
* @action_type: An array of actions based on the order of actions which will be provided |
| 357 |
* with rule_actions to mlx5hws_rule_create. The last action is marked |
| 358 |
* using MLX5HWS_ACTION_TYP_LAST. |
| 359 |
* |
| 360 |
* Return: Pointer to mlx5hws_action_template on success, NULL otherwise. |
| 361 |
*/ |
| 362 |
struct mlx5hws_action_template * |
| 363 |
mlx5hws_action_template_create(enum mlx5hws_action_type action_type[]); |
| 364 |
|
| 365 |
/** |
| 366 |
* mlx5hws_action_template_destroy - Destroy action template. |
| 367 |
* |
| 368 |
* @at: Action template to destroy. |
| 369 |
* |
| 370 |
* Return: zero on success non zero otherwise. |
| 371 |
*/ |
| 372 |
int mlx5hws_action_template_destroy(struct mlx5hws_action_template *at); |
| 373 |
|
| 374 |
/** |
| 375 |
* mlx5hws_matcher_create - Create a new direct rule matcher. |
| 376 |
* |
| 377 |
* Each matcher can contain multiple rules. Matchers on the table will be |
| 378 |
* processed by priority. Matching fields and mask are described by the |
| 379 |
* match template. In some cases, multiple match templates can be used on |
| 380 |
* the same matcher. |
| 381 |
* |
| 382 |
* @table: The table in which the new matcher will be opened. |
| 383 |
* @mt: Array of match templates to be used on matcher. |
| 384 |
* @num_of_mt: Number of match templates in mt array. |
| 385 |
* @at: Array of action templates to be used on matcher. |
| 386 |
* @num_of_at: Number of action templates in at array. |
| 387 |
* @attr: Attributes used for matcher creation. |
| 388 |
* |
| 389 |
* Return: Pointer to mlx5hws_matcher on success, NULL otherwise. |
| 390 |
* |
| 391 |
*/ |
| 392 |
struct mlx5hws_matcher * |
| 393 |
mlx5hws_matcher_create(struct mlx5hws_table *table, |
| 394 |
struct mlx5hws_match_template *mt[], |
| 395 |
u8 num_of_mt, |
| 396 |
struct mlx5hws_action_template *at[], |
| 397 |
u8 num_of_at, |
| 398 |
struct mlx5hws_matcher_attr *attr); |
| 399 |
|
| 400 |
/** |
| 401 |
* mlx5hws_matcher_destroy - Destroy a direct rule matcher. |
| 402 |
* |
| 403 |
* @matcher: Matcher to destroy. |
| 404 |
* |
| 405 |
* Return: Zero on success, non-zero otherwise. |
| 406 |
*/ |
| 407 |
int mlx5hws_matcher_destroy(struct mlx5hws_matcher *matcher); |
| 408 |
|
| 409 |
/** |
| 410 |
* mlx5hws_matcher_attach_at - Attach a new action template to a direct rule matcher. |
| 411 |
* |
| 412 |
* @matcher: Matcher to attach the action template to. |
| 413 |
* @at: Action template to be attached to the matcher. |
| 414 |
* |
| 415 |
* Return: Zero on success, non-zero otherwise. |
| 416 |
*/ |
| 417 |
int mlx5hws_matcher_attach_at(struct mlx5hws_matcher *matcher, |
| 418 |
struct mlx5hws_action_template *at); |
| 419 |
|
| 420 |
/** |
| 421 |
* mlx5hws_matcher_resize_set_target - Link two matchers and enable moving rules. |
| 422 |
* |
| 423 |
* Both matchers must be in the same table type, must be created with the |
| 424 |
* 'resizable' property, and should have the same characteristics (e.g., same |
| 425 |
* match templates and action templates). It is the user's responsibility to |
| 426 |
* ensure that the destination matcher is allocated with the appropriate size. |
| 427 |
* |
| 428 |
* Once the function is completed, the user is: |
| 429 |
* - Allowed to move rules from the source into the destination matcher. |
| 430 |
* - No longer allowed to insert rules into the source matcher. |
| 431 |
* |
| 432 |
* The user is always allowed to insert rules into the destination matcher and |
| 433 |
* to delete rules from any matcher. |
| 434 |
* |
| 435 |
* @src_matcher: Source matcher for moving rules from. |
| 436 |
* @dst_matcher: Destination matcher for moving rules to. |
| 437 |
* |
| 438 |
* Return: Zero on successful move, non-zero otherwise. |
| 439 |
*/ |
| 440 |
int mlx5hws_matcher_resize_set_target(struct mlx5hws_matcher *src_matcher, |
| 441 |
struct mlx5hws_matcher *dst_matcher); |
| 442 |
|
| 443 |
/** |
| 444 |
* mlx5hws_matcher_resize_rule_move - Enqueue moving rule operation. |
| 445 |
* |
| 446 |
* This function enqueues the operation of moving a rule from the source |
| 447 |
* matcher to the destination matcher. |
| 448 |
* |
| 449 |
* @src_matcher: Matcher that the rule belongs to. |
| 450 |
* @rule: The rule to move. |
| 451 |
* @attr: Rule attributes. |
| 452 |
* |
| 453 |
* Return: Zero on success, non-zero otherwise. |
| 454 |
*/ |
| 455 |
int mlx5hws_matcher_resize_rule_move(struct mlx5hws_matcher *src_matcher, |
| 456 |
struct mlx5hws_rule *rule, |
| 457 |
struct mlx5hws_rule_attr *attr); |
| 458 |
|
| 459 |
/** |
| 460 |
* mlx5hws_rule_create - Enqueue create rule operation. |
| 461 |
* |
| 462 |
* @matcher: The matcher in which the new rule will be created. |
| 463 |
* @mt_idx: Match template index to create the match with. |
| 464 |
* @match_param: The match parameter PRM buffer used for value matching. |
| 465 |
* @at_idx: Action template index to apply the actions with. |
| 466 |
* @rule_actions: Rule actions to be executed on match. |
| 467 |
* @attr: Rule creation attributes. |
| 468 |
* @rule_handle: A valid rule handle. The handle doesn't require any initialization. |
| 469 |
* |
| 470 |
* Return: Zero on successful enqueue, non-zero otherwise. |
| 471 |
*/ |
| 472 |
int mlx5hws_rule_create(struct mlx5hws_matcher *matcher, |
| 473 |
u8 mt_idx, |
| 474 |
u32 *match_param, |
| 475 |
u8 at_idx, |
| 476 |
struct mlx5hws_rule_action rule_actions[], |
| 477 |
struct mlx5hws_rule_attr *attr, |
| 478 |
struct mlx5hws_rule *rule_handle); |
| 479 |
|
| 480 |
/** |
| 481 |
* mlx5hws_rule_destroy - Enqueue destroy rule operation. |
| 482 |
* |
| 483 |
* @rule: The rule destruction to enqueue. |
| 484 |
* @attr: Rule destruction attributes. |
| 485 |
* |
| 486 |
* Return: Zero on successful enqueue, non-zero otherwise. |
| 487 |
*/ |
| 488 |
int mlx5hws_rule_destroy(struct mlx5hws_rule *rule, |
| 489 |
struct mlx5hws_rule_attr *attr); |
| 490 |
|
| 491 |
/** |
| 492 |
* mlx5hws_rule_action_update - Enqueue update actions on an existing rule. |
| 493 |
* |
| 494 |
* @rule: A valid rule handle to update. |
| 495 |
* @at_idx: Action template index to update the actions with. |
| 496 |
* @rule_actions: Rule actions to be executed on match. |
| 497 |
* @attr: Rule update attributes. |
| 498 |
* |
| 499 |
* Return: Zero on successful enqueue, non-zero otherwise. |
| 500 |
*/ |
| 501 |
int mlx5hws_rule_action_update(struct mlx5hws_rule *rule, |
| 502 |
u8 at_idx, |
| 503 |
struct mlx5hws_rule_action rule_actions[], |
| 504 |
struct mlx5hws_rule_attr *attr); |
| 505 |
|
| 506 |
/** |
| 507 |
* mlx5hws_action_get_type - Get action type. |
| 508 |
* |
| 509 |
* @action: The action to get the type of. |
| 510 |
* |
| 511 |
* Return: action type. |
| 512 |
*/ |
| 513 |
enum mlx5hws_action_type |
| 514 |
mlx5hws_action_get_type(struct mlx5hws_action *action); |
| 515 |
|
| 516 |
/** |
| 517 |
* mlx5hws_action_get_dev - Get mlx5 core device. |
| 518 |
* |
| 519 |
* @action: The action to get the device from. |
| 520 |
* |
| 521 |
* Return: mlx5 core device. |
| 522 |
*/ |
| 523 |
struct mlx5_core_dev *mlx5hws_action_get_dev(struct mlx5hws_action *action); |
| 524 |
|
| 525 |
/** |
| 526 |
* mlx5hws_action_create_dest_drop - Create a direct rule drop action. |
| 527 |
* |
| 528 |
* @ctx: The context in which the new action will be created. |
| 529 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 530 |
* |
| 531 |
* Return: Pointer to mlx5hws_action on success, NULL otherwise. |
| 532 |
*/ |
| 533 |
struct mlx5hws_action * |
| 534 |
mlx5hws_action_create_dest_drop(struct mlx5hws_context *ctx, |
| 535 |
u32 flags); |
| 536 |
|
| 537 |
/** |
| 538 |
* mlx5hws_action_create_default_miss - Create a direct rule default miss action. |
| 539 |
* Defaults are RX: Drop, TX: Wire. |
| 540 |
* |
| 541 |
* @ctx: The context in which the new action will be created. |
| 542 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 543 |
* |
| 544 |
* Return: Pointer to mlx5hws_action on success, NULL otherwise. |
| 545 |
*/ |
| 546 |
struct mlx5hws_action * |
| 547 |
mlx5hws_action_create_default_miss(struct mlx5hws_context *ctx, |
| 548 |
u32 flags); |
| 549 |
|
| 550 |
/** |
| 551 |
* mlx5hws_action_create_dest_table - Create direct rule goto table action. |
| 552 |
* |
| 553 |
* @ctx: The context in which the new action will be created. |
| 554 |
* @tbl: Destination table. |
| 555 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 556 |
* |
| 557 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 558 |
*/ |
| 559 |
struct mlx5hws_action * |
| 560 |
mlx5hws_action_create_dest_table(struct mlx5hws_context *ctx, |
| 561 |
struct mlx5hws_table *tbl, |
| 562 |
u32 flags); |
| 563 |
|
| 564 |
/** |
| 565 |
* mlx5hws_action_create_dest_table_num - Create direct rule goto table number action. |
| 566 |
* |
| 567 |
* @ctx: The context in which the new action will be created. |
| 568 |
* @tbl_num: Destination table number. |
| 569 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 570 |
* |
| 571 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 572 |
*/ |
| 573 |
struct mlx5hws_action * |
| 574 |
mlx5hws_action_create_dest_table_num(struct mlx5hws_context *ctx, |
| 575 |
u32 tbl_num, u32 flags); |
| 576 |
|
| 577 |
/** |
| 578 |
* mlx5hws_action_create_dest_match_range - Create direct rule range match action. |
| 579 |
* |
| 580 |
* @ctx: The context in which the new action will be created. |
| 581 |
* @field: Field to comapare the value. |
| 582 |
* @hit_ft: Flow table to go to on hit. |
| 583 |
* @miss_ft: Flow table to go to on miss. |
| 584 |
* @min: Minimal value of the field to be considered as hit. |
| 585 |
* @max: Maximal value of the field to be considered as hit. |
| 586 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 587 |
* |
| 588 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 589 |
*/ |
| 590 |
struct mlx5hws_action * |
| 591 |
mlx5hws_action_create_dest_match_range(struct mlx5hws_context *ctx, |
| 592 |
u32 field, |
| 593 |
struct mlx5_flow_table *hit_ft, |
| 594 |
struct mlx5_flow_table *miss_ft, |
| 595 |
u32 min, u32 max, u32 flags); |
| 596 |
|
| 597 |
/** |
| 598 |
* mlx5hws_action_create_flow_sampler - Create direct rule flow sampler action. |
| 599 |
* |
| 600 |
* @ctx: The context in which the new action will be created. |
| 601 |
* @sampler_id: Flow sampler object ID. |
| 602 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 603 |
* |
| 604 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 605 |
*/ |
| 606 |
struct mlx5hws_action * |
| 607 |
mlx5hws_action_create_flow_sampler(struct mlx5hws_context *ctx, |
| 608 |
u32 sampler_id, u32 flags); |
| 609 |
|
| 610 |
/** |
| 611 |
* mlx5hws_action_create_dest_vport - Create direct rule goto vport action. |
| 612 |
* |
| 613 |
* @ctx: The context in which the new action will be created. |
| 614 |
* @vport_num: Destination vport number. |
| 615 |
* @vhca_id_valid: Tells if the vhca_id parameter is valid. |
| 616 |
* @vhca_id: VHCA ID of the destination vport. |
| 617 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 618 |
* |
| 619 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 620 |
*/ |
| 621 |
struct mlx5hws_action * |
| 622 |
mlx5hws_action_create_dest_vport(struct mlx5hws_context *ctx, |
| 623 |
u16 vport_num, |
| 624 |
bool vhca_id_valid, |
| 625 |
u16 vhca_id, |
| 626 |
u32 flags); |
| 627 |
|
| 628 |
/** |
| 629 |
* mlx5hws_action_create_tag - Create direct rule TAG action. |
| 630 |
* |
| 631 |
* @ctx: The context in which the new action will be created. |
| 632 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 633 |
* |
| 634 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 635 |
*/ |
| 636 |
struct mlx5hws_action * |
| 637 |
mlx5hws_action_create_tag(struct mlx5hws_context *ctx, u32 flags); |
| 638 |
|
| 639 |
/** |
| 640 |
* mlx5hws_action_create_counter - Create direct rule counter action. |
| 641 |
* |
| 642 |
* @ctx: The context in which the new action will be created. |
| 643 |
* @obj_id: Direct rule counter object ID. |
| 644 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 645 |
* |
| 646 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 647 |
*/ |
| 648 |
struct mlx5hws_action * |
| 649 |
mlx5hws_action_create_counter(struct mlx5hws_context *ctx, |
| 650 |
u32 obj_id, |
| 651 |
u32 flags); |
| 652 |
|
| 653 |
/** |
| 654 |
* mlx5hws_action_create_reformat - Create direct rule reformat action. |
| 655 |
* |
| 656 |
* @ctx: The context in which the new action will be created. |
| 657 |
* @reformat_type: Type of reformat prefixed with MLX5HWS_ACTION_TYP_REFORMAT. |
| 658 |
* @num_of_hdrs: Number of provided headers in "hdrs" array. |
| 659 |
* @hdrs: Headers array containing header information. |
| 660 |
* @log_bulk_size: Number of unique values used with this reformat. |
| 661 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 662 |
* |
| 663 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 664 |
*/ |
| 665 |
struct mlx5hws_action * |
| 666 |
mlx5hws_action_create_reformat(struct mlx5hws_context *ctx, |
| 667 |
enum mlx5hws_action_type reformat_type, |
| 668 |
u8 num_of_hdrs, |
| 669 |
struct mlx5hws_action_reformat_header *hdrs, |
| 670 |
u32 log_bulk_size, |
| 671 |
u32 flags); |
| 672 |
|
| 673 |
/** |
| 674 |
* mlx5hws_action_create_modify_header - Create direct rule modify header action. |
| 675 |
* |
| 676 |
* @ctx: The context in which the new action will be created. |
| 677 |
* @num_of_patterns: Number of provided patterns in "patterns" array. |
| 678 |
* @patterns: Patterns array containing pattern information. |
| 679 |
* @log_bulk_size: Number of unique values used with this pattern. |
| 680 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 681 |
* |
| 682 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 683 |
*/ |
| 684 |
struct mlx5hws_action * |
| 685 |
mlx5hws_action_create_modify_header(struct mlx5hws_context *ctx, |
| 686 |
u8 num_of_patterns, |
| 687 |
struct mlx5hws_action_mh_pattern *patterns, |
| 688 |
u32 log_bulk_size, |
| 689 |
u32 flags); |
| 690 |
|
| 691 |
/** |
| 692 |
* mlx5hws_action_create_aso_meter - Create direct rule ASO flow meter action. |
| 693 |
* |
| 694 |
* @ctx: The context in which the new action will be created. |
| 695 |
* @obj_id: ASO object ID. |
| 696 |
* @return_reg_c: Copy the ASO object value into this reg_c, |
| 697 |
* after a packet hits a rule with this ASO object. |
| 698 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 699 |
* |
| 700 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 701 |
*/ |
| 702 |
struct mlx5hws_action * |
| 703 |
mlx5hws_action_create_aso_meter(struct mlx5hws_context *ctx, |
| 704 |
u32 obj_id, |
| 705 |
u8 return_reg_c, |
| 706 |
u32 flags); |
| 707 |
|
| 708 |
/** |
| 709 |
* mlx5hws_action_create_pop_vlan - Create direct rule pop vlan action. |
| 710 |
* |
| 711 |
* @ctx: The context in which the new action will be created. |
| 712 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 713 |
* |
| 714 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 715 |
*/ |
| 716 |
struct mlx5hws_action * |
| 717 |
mlx5hws_action_create_pop_vlan(struct mlx5hws_context *ctx, u32 flags); |
| 718 |
|
| 719 |
/** |
| 720 |
* mlx5hws_action_create_push_vlan - Create direct rule push vlan action. |
| 721 |
* |
| 722 |
* @ctx: The context in which the new action will be created. |
| 723 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 724 |
* |
| 725 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 726 |
*/ |
| 727 |
struct mlx5hws_action * |
| 728 |
mlx5hws_action_create_push_vlan(struct mlx5hws_context *ctx, u32 flags); |
| 729 |
|
| 730 |
/** |
| 731 |
* mlx5hws_action_create_dest_array - Create a dest array action, this action can |
| 732 |
* duplicate packets and forward to multiple destinations in the destination list. |
| 733 |
* |
| 734 |
* @ctx: The context in which the new action will be created. |
| 735 |
* @num_dest: The number of dests attributes. |
| 736 |
* @dests: The destination array. Each contains a destination action and can |
| 737 |
* have additional actions. |
| 738 |
* @flags: Action creation flags (enum mlx5hws_action_flags). |
| 739 |
* |
| 740 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 741 |
*/ |
| 742 |
struct mlx5hws_action * |
| 743 |
mlx5hws_action_create_dest_array(struct mlx5hws_context *ctx, size_t num_dest, |
| 744 |
struct mlx5hws_action_dest_attr *dests, |
| 745 |
u32 flags); |
| 746 |
|
| 747 |
/** |
| 748 |
* mlx5hws_action_create_insert_header - Create insert header action. |
| 749 |
* |
| 750 |
* @ctx: The context in which the new action will be created. |
| 751 |
* @num_of_hdrs: Number of provided headers in "hdrs" array. |
| 752 |
* @hdrs: Headers array containing header information. |
| 753 |
* @log_bulk_size: Number of unique values used with this insert header. |
| 754 |
* @flags: Action creation flags. (enum mlx5hws_action_flags) |
| 755 |
* |
| 756 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 757 |
*/ |
| 758 |
struct mlx5hws_action * |
| 759 |
mlx5hws_action_create_insert_header(struct mlx5hws_context *ctx, |
| 760 |
u8 num_of_hdrs, |
| 761 |
struct mlx5hws_action_insert_header *hdrs, |
| 762 |
u32 log_bulk_size, |
| 763 |
u32 flags); |
| 764 |
|
| 765 |
/** |
| 766 |
* mlx5hws_action_create_remove_header - Create remove header action. |
| 767 |
* |
| 768 |
* @ctx: The context in which the new action will be created. |
| 769 |
* @attr: attributes that specifie the remove header type, PRM start anchor and |
| 770 |
* the PRM end anchor or the PRM start anchor and remove size in bytes. |
| 771 |
* @flags: Action creation flags. (enum mlx5hws_action_flags) |
| 772 |
* |
| 773 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 774 |
*/ |
| 775 |
struct mlx5hws_action * |
| 776 |
mlx5hws_action_create_remove_header(struct mlx5hws_context *ctx, |
| 777 |
struct mlx5hws_action_remove_header_attr *attr, |
| 778 |
u32 flags); |
| 779 |
|
| 780 |
/** |
| 781 |
* mlx5hws_action_create_last - Create direct rule LAST action. |
| 782 |
* |
| 783 |
* @ctx: The context in which the new action will be created. |
| 784 |
* @flags: Action creation flags. (enum mlx5hws_action_flags) |
| 785 |
* |
| 786 |
* Return: pointer to mlx5hws_action on success NULL otherwise. |
| 787 |
*/ |
| 788 |
struct mlx5hws_action * |
| 789 |
mlx5hws_action_create_last(struct mlx5hws_context *ctx, u32 flags); |
| 790 |
|
| 791 |
/** |
| 792 |
* mlx5hws_action_destroy - Destroy direct rule action. |
| 793 |
* |
| 794 |
* @action: The action to destroy. |
| 795 |
* |
| 796 |
* Return: zero on success non zero otherwise. |
| 797 |
*/ |
| 798 |
int mlx5hws_action_destroy(struct mlx5hws_action *action); |
| 799 |
|
| 800 |
enum mlx5hws_flow_op_status { |
| 801 |
MLX5HWS_FLOW_OP_SUCCESS, |
| 802 |
MLX5HWS_FLOW_OP_ERROR, |
| 803 |
}; |
| 804 |
|
| 805 |
struct mlx5hws_flow_op_result { |
| 806 |
enum mlx5hws_flow_op_status status; |
| 807 |
void *user_data; |
| 808 |
}; |
| 809 |
|
| 810 |
/** |
| 811 |
* mlx5hws_send_queue_poll - Poll queue for rule creation and deletions completions. |
| 812 |
* |
| 813 |
* @ctx: The context to which the queue belong to. |
| 814 |
* @queue_id: The id of the queue to poll. |
| 815 |
* @res: Completion array. |
| 816 |
* @res_nb: Maximum number of results to return. |
| 817 |
* |
| 818 |
* Return: negative number on failure, the number of completions otherwise. |
| 819 |
*/ |
| 820 |
int mlx5hws_send_queue_poll(struct mlx5hws_context *ctx, |
| 821 |
u16 queue_id, |
| 822 |
struct mlx5hws_flow_op_result res[], |
| 823 |
u32 res_nb); |
| 824 |
|
| 825 |
/** |
| 826 |
* mlx5hws_send_queue_action - Perform an action on the queue |
| 827 |
* |
| 828 |
* @ctx: The context to which the queue belong to. |
| 829 |
* @queue_id: The id of the queue to perform the action on. |
| 830 |
* @actions: Actions to perform on the queue (enum mlx5hws_send_queue_actions) |
| 831 |
* |
| 832 |
* Return: zero on success non zero otherwise. |
| 833 |
*/ |
| 834 |
int mlx5hws_send_queue_action(struct mlx5hws_context *ctx, |
| 835 |
u16 queue_id, |
| 836 |
u32 actions); |
| 837 |
|
| 838 |
/** |
| 839 |
* mlx5hws_debug_dump - Dump HWS info |
| 840 |
* |
| 841 |
* @ctx: The context which to dump the info from. |
| 842 |
* |
| 843 |
* Return: zero on success non zero otherwise. |
| 844 |
*/ |
| 845 |
int mlx5hws_debug_dump(struct mlx5hws_context *ctx); |
| 846 |
|
| 847 |
struct mlx5hws_bwc_matcher; |
| 848 |
struct mlx5hws_bwc_rule; |
| 849 |
|
| 850 |
struct mlx5hws_match_parameters { |
| 851 |
size_t match_sz; |
| 852 |
u32 *match_buf; /* Device spec format */ |
| 853 |
}; |
| 854 |
|
| 855 |
/** |
| 856 |
* mlx5hws_bwc_matcher_create - Create a new BWC direct rule matcher. |
| 857 |
* |
| 858 |
* This function does the following: |
| 859 |
* - creates match template based on flow items |
| 860 |
* - creates an empty action template |
| 861 |
* - creates a usual mlx5hws_matcher with these mt and at, setting |
| 862 |
* its size to minimal |
| 863 |
* Notes: |
| 864 |
* - table->ctx must have BWC support |
| 865 |
* - complex rules are not supported |
| 866 |
* |
| 867 |
* @table: The table in which the new matcher will be opened |
| 868 |
* @priority: Priority for this BWC matcher |
| 869 |
* @match_criteria_enable: Bitmask that defines matching criteria |
| 870 |
* @mask: Match parameters |
| 871 |
* |
| 872 |
* Return: pointer to mlx5hws_bwc_matcher on success or NULL otherwise. |
| 873 |
*/ |
| 874 |
struct mlx5hws_bwc_matcher * |
| 875 |
mlx5hws_bwc_matcher_create(struct mlx5hws_table *table, |
| 876 |
u32 priority, |
| 877 |
u8 match_criteria_enable, |
| 878 |
struct mlx5hws_match_parameters *mask); |
| 879 |
|
| 880 |
/** |
| 881 |
* mlx5hws_bwc_matcher_destroy - Destroy BWC direct rule matcher. |
| 882 |
* |
| 883 |
* @bwc_matcher: Matcher to destroy |
| 884 |
* |
| 885 |
* Return: zero on success, non zero otherwise |
| 886 |
*/ |
| 887 |
int mlx5hws_bwc_matcher_destroy(struct mlx5hws_bwc_matcher *bwc_matcher); |
| 888 |
|
| 889 |
/** |
| 890 |
* mlx5hws_bwc_rule_create - Create a new BWC rule. |
| 891 |
* |
| 892 |
* Unlike the usual rule creation function, this one is blocking: when the |
| 893 |
* function returns, the rule is written to its place (no need to poll). |
| 894 |
* This function does the following: |
| 895 |
* - finds matching action template based on the provided rule_actions, or |
| 896 |
* creates new action template if matching action template doesn't exist |
| 897 |
* - updates corresponding BWC matcher stats |
| 898 |
* - if needed, the function performs rehash: |
| 899 |
* - creates a new matcher based on mt, at, new_sz |
| 900 |
* - moves all the existing matcher rules to the new matcher |
| 901 |
* - removes the old matcher |
| 902 |
* - inserts new rule |
| 903 |
* - polls till completion is received |
| 904 |
* Notes: |
| 905 |
* - matcher->tbl->ctx must have BWC support |
| 906 |
* - separate BWC ctx queues are used |
| 907 |
* |
| 908 |
* @bwc_matcher: The BWC matcher in which the new rule will be created. |
| 909 |
* @params: Match perameters |
| 910 |
* @flow_source: Flow source for this rule |
| 911 |
* @rule_actions: Rule action to be executed on match |
| 912 |
* |
| 913 |
* Return: valid BWC rule handle on success, NULL otherwise |
| 914 |
*/ |
| 915 |
struct mlx5hws_bwc_rule * |
| 916 |
mlx5hws_bwc_rule_create(struct mlx5hws_bwc_matcher *bwc_matcher, |
| 917 |
struct mlx5hws_match_parameters *params, |
| 918 |
u32 flow_source, |
| 919 |
struct mlx5hws_rule_action rule_actions[]); |
| 920 |
|
| 921 |
/** |
| 922 |
* mlx5hws_bwc_rule_destroy - Destroy BWC direct rule. |
| 923 |
* |
| 924 |
* @bwc_rule: Rule to destroy. |
| 925 |
* |
| 926 |
* Return: zero on success, non zero otherwise. |
| 927 |
*/ |
| 928 |
int mlx5hws_bwc_rule_destroy(struct mlx5hws_bwc_rule *bwc_rule); |
| 929 |
|
| 930 |
/** |
| 931 |
* mlx5hws_bwc_rule_action_update - Update actions on an existing BWC rule. |
| 932 |
* |
| 933 |
* @bwc_rule: Rule to update |
| 934 |
* @rule_actions: Rule action to update with |
| 935 |
* |
| 936 |
* Return: zero on successful update, non zero otherwise. |
| 937 |
*/ |
| 938 |
int mlx5hws_bwc_rule_action_update(struct mlx5hws_bwc_rule *bwc_rule, |
| 939 |
struct mlx5hws_rule_action rule_actions[]); |
| 940 |
|
| 941 |
#endif |