1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2020 Mellanox Technologies, Ltd 3 */ 4 5 #ifndef RTE_PMD_MLX5_FLOW_OS_H_ 6 #define RTE_PMD_MLX5_FLOW_OS_H_ 7 8 #include "mlx5_flow.h" 9 10 #ifdef HAVE_IBV_FLOW_DV_SUPPORT 11 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops; 12 #endif 13 14 /** 15 * Get OS enforced flow type. MLX5_FLOW_TYPE_MAX means "non enforced type". 16 * 17 * @return 18 * Flow type (MLX5_FLOW_TYPE_MAX) 19 */ 20 static inline enum mlx5_flow_drv_type 21 mlx5_flow_os_get_type(void) 22 { 23 return MLX5_FLOW_TYPE_MAX; 24 } 25 26 /** 27 * Check if item type is supported. 28 * 29 * @param item 30 * Item type to check. 31 * 32 * @return 33 * True is this item type is supported, false if not supported. 34 */ 35 static inline bool 36 mlx5_flow_os_item_supported(int item __rte_unused) 37 { 38 return true; 39 } 40 41 /** 42 * Check if action type is supported. 43 * 44 * @param action 45 * Action type to check. 46 * 47 * @return 48 * True is this action type is supported, false if not supported. 49 */ 50 static inline bool 51 mlx5_flow_os_action_supported(int action __rte_unused) 52 { 53 return true; 54 } 55 56 /** 57 * Create flow rule. 58 * 59 * @param[in] matcher 60 * Pointer to match mask structure. 61 * @param[in] match_value 62 * Pointer to match value structure. 63 * @param[in] num_actions 64 * Number of actions in flow rule. 65 * @param[in] actions 66 * Pointer to array of flow rule actions. 67 * @param[out] flow 68 * Pointer to a valid flow rule object on success, NULL otherwise. 69 * 70 * @return 71 * 0 on success, or -1 on failure and errno is set. 72 */ 73 static inline int 74 mlx5_flow_os_create_flow(void *matcher, void *match_value, 75 size_t num_actions, void *actions[], void **flow) 76 { 77 *flow = mlx5_glue->dv_create_flow(matcher, match_value, 78 num_actions, actions); 79 return (*flow) ? 0 : -1; 80 } 81 82 /** 83 * Destroy flow rule. 84 * 85 * @param[in] drv_flow_ptr 86 * Pointer to flow rule object. 87 * 88 * @return 89 * 0 on success, or the value of errno on failure. 90 */ 91 static inline int 92 mlx5_flow_os_destroy_flow(void *drv_flow_ptr) 93 { 94 return mlx5_glue->dv_destroy_flow(drv_flow_ptr); 95 } 96 97 /** 98 * Create flow table. 99 * 100 * @param[in] domain 101 * Pointer to relevant domain. 102 * @param[in] table_id 103 * Table ID. 104 * @param[out] table 105 * Pointer to a valid flow table object on success, NULL otherwise. 106 * 107 * @return 108 * 0 on success, or -1 on failure and errno is set. 109 */ 110 static inline int 111 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table) 112 { 113 *table = mlx5_glue->dr_create_flow_tbl(domain, table_id); 114 return (*table) ? 0 : -1; 115 } 116 117 /** 118 * Destroy flow table. 119 * 120 * @param[in] table 121 * Pointer to table object to destroy. 122 * 123 * @return 124 * 0 on success, or the value of errno on failure. 125 */ 126 static inline int 127 mlx5_flow_os_destroy_flow_tbl(void *table) 128 { 129 return mlx5_glue->dr_destroy_flow_tbl(table); 130 } 131 132 /** 133 * Create flow matcher in a flow table. 134 * 135 * @param[in] ctx 136 * Pointer to relevant device context. 137 * @param[in] attr 138 * Pointer to relevant attributes. 139 * @param[in] table 140 * Pointer to table object. 141 * @param[out] matcher 142 * Pointer to a valid flow matcher object on success, NULL otherwise. 143 * 144 * @return 145 * 0 on success, or -1 on failure and errno is set. 146 */ 147 static inline int 148 mlx5_flow_os_create_flow_matcher(void *ctx, void *attr, void *table, 149 void **matcher) 150 { 151 *matcher = mlx5_glue->dv_create_flow_matcher(ctx, attr, table); 152 return (*matcher) ? 0 : -1; 153 } 154 155 /** 156 * Destroy flow matcher. 157 * 158 * @param[in] matcher 159 * Pointer to matcher object to destroy. 160 * 161 * @return 162 * 0 on success, or the value of errno on failure. 163 */ 164 static inline int 165 mlx5_flow_os_destroy_flow_matcher(void *matcher) 166 { 167 return mlx5_glue->dv_destroy_flow_matcher(matcher); 168 } 169 170 /** 171 * Create flow action: packet reformat. 172 * 173 * @param[in] ctx 174 * Pointer to relevant device context. 175 * @param[in] domain 176 * Pointer to domain handler. 177 * @param[in] resource 178 * Pointer to action data resource. 179 * @param[out] action 180 * Pointer to a valid action on success, NULL otherwise. 181 * 182 * 183 * @return 184 * 0 on success, or -1 on failure and errno is set. 185 */ 186 static inline int 187 mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain, 188 void *resource, void **action) 189 { 190 struct mlx5_flow_dv_encap_decap_resource *res = 191 (struct mlx5_flow_dv_encap_decap_resource *)resource; 192 193 *action = mlx5_glue->dv_create_flow_action_packet_reformat 194 (ctx, res->reformat_type, res->ft_type, 195 domain, res->flags, res->size, 196 (res->size ? res->buf : NULL)); 197 return (*action) ? 0 : -1; 198 } 199 200 /** 201 * Create flow action: modify header. 202 * 203 * @param[in] ctx 204 * Pointer to relevant device context. 205 * @param[in] domain 206 * Pointer to domain handler. 207 * @param[in] resource 208 * Pointer to action data resource. 209 * @param[in] actions_len 210 * Total length of actions data in resource. 211 * @param[out] action 212 * Pointer to a valid action on success, NULL otherwise. 213 * 214 * 215 * @return 216 * 0 on success, or -1 on failure and errno is set. 217 */ 218 static inline int 219 mlx5_flow_os_create_flow_action_modify_header(void *ctx, void *domain, 220 void *resource, 221 uint32_t actions_len, 222 void **action) 223 { 224 struct mlx5_flow_dv_modify_hdr_resource *res = 225 (struct mlx5_flow_dv_modify_hdr_resource *)resource; 226 227 *action = mlx5_glue->dv_create_flow_action_modify_header 228 (ctx, res->ft_type, domain, res->flags, 229 actions_len, (uint64_t *)res->actions); 230 return (*action) ? 0 : -1; 231 } 232 233 /** 234 * Create flow action: destination flow table. 235 * 236 * @param[in] tbl_obj 237 * Pointer to destination table object. 238 * @param[out] action 239 * Pointer to a valid action on success, NULL otherwise. 240 * 241 * @return 242 * 0 on success, or -1 on failure and errno is set. 243 */ 244 static inline int 245 mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action) 246 { 247 *action = mlx5_glue->dr_create_flow_action_dest_flow_tbl(tbl_obj); 248 return (*action) ? 0 : -1; 249 } 250 251 /** 252 * Create flow action: destination port. 253 * 254 * @param[in] domain 255 * Pointer to domain handler. 256 * @param[in] port_id 257 * Destination port ID. 258 * @param[out] action 259 * Pointer to a valid action on success, NULL otherwise. 260 * 261 * @return 262 * 0 on success, or -1 on failure and errno is set. 263 */ 264 static inline int 265 mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id, 266 void **action) 267 { 268 /* 269 * Depending on rdma_core version the glue routine calls 270 * either mlx5dv_dr_action_create_dest_ib_port(domain, dev_port) 271 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id). 272 */ 273 *action = mlx5_glue->dr_create_flow_action_dest_port(domain, port_id); 274 return (*action) ? 0 : -1; 275 } 276 277 /** 278 * Create flow action: push vlan. 279 * 280 * @param[in] domain 281 * Pointer to domain handler. 282 * @param[in] vlan_tag 283 * VLAN tag value. 284 * @param[out] action 285 * Pointer to a valid action on success, NULL otherwise. 286 * 287 * @return 288 * 0 on success, or -1 on failure and errno is set. 289 */ 290 static inline int 291 mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag, 292 void **action) 293 { 294 *action = mlx5_glue->dr_create_flow_action_push_vlan(domain, vlan_tag); 295 return (*action) ? 0 : -1; 296 } 297 298 /** 299 * Create flow action: count. 300 * 301 * @param[in] cnt_obj 302 * Pointer to DevX counter object. 303 * @param[in] offset 304 * Offset of counter in array. 305 * @param[out] action 306 * Pointer to a valid action on success, NULL otherwise. 307 * 308 * @return 309 * 0 on success, or -1 on failure and errno is set. 310 */ 311 static inline int 312 mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset, 313 void **action) 314 { 315 *action = mlx5_glue->dv_create_flow_action_counter(cnt_obj, offset); 316 return (*action) ? 0 : -1; 317 } 318 319 /** 320 * Create flow action: tag. 321 * 322 * @param[in] tag 323 * Tag value. 324 * @param[out] action 325 * Pointer to a valid action on success, NULL otherwise. 326 * 327 * @return 328 * 0 on success, or -1 on failure and errno is set. 329 */ 330 static inline int 331 mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action) 332 { 333 *action = mlx5_glue->dv_create_flow_action_tag(tag); 334 return (*action) ? 0 : -1; 335 } 336 337 /** 338 * Create flow action: drop. 339 * 340 * @param[out] action 341 * Pointer to a valid action on success, NULL otherwise. 342 * 343 * @return 344 * 0 on success, or -1 on failure and errno is set. 345 */ 346 static inline int 347 mlx5_flow_os_create_flow_action_drop(void **action) 348 { 349 *action = mlx5_glue->dr_create_flow_action_drop(); 350 return (*action) ? 0 : -1; 351 } 352 353 /** 354 * Create flow action: default miss. 355 * 356 * @param[out] action 357 * Pointer to a valid action on success, NULL otherwise. 358 * 359 * @return 360 * 0 on success, or -1 on failure and errno is set. 361 */ 362 static inline int 363 mlx5_flow_os_create_flow_action_default_miss(void **action) 364 { 365 *action = mlx5_glue->dr_create_flow_action_default_miss(); 366 return (*action) ? 0 : -1; 367 } 368 369 /** 370 * Create flow action: dest_devx_tir 371 * 372 * @param[in] tir 373 * Pointer to DevX tir object 374 * @param[out] action 375 * Pointer to a valid action on success, NULL otherwise. 376 * 377 * @return 378 * 0 on success, or -1 on failure and errno is set. 379 */ 380 static inline int 381 mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir, 382 void **action) 383 { 384 #ifdef HAVE_IBV_FLOW_DV_SUPPORT 385 *action = mlx5_glue->dv_create_flow_action_dest_devx_tir(tir->obj); 386 return (*action) ? 0 : -1; 387 #else 388 /* If no DV support - skip the operation and return success */ 389 RTE_SET_USED(tir); 390 *action = 0; 391 return 0; 392 #endif 393 } 394 395 /** 396 * Create flow action: sampler 397 * 398 * @param[in] attr 399 * Pointer to sampler attribute 400 * @param[out] action 401 * Pointer to a valid action on success, NULL otherwise. 402 * 403 * @return 404 * 0 on success, or -1 on failure and errno is set. 405 */ 406 static inline int 407 mlx5_os_flow_dr_create_flow_action_sampler 408 (struct mlx5dv_dr_flow_sampler_attr *attr, 409 void **action) 410 { 411 *action = mlx5_glue->dr_create_flow_action_sampler(attr); 412 return (*action) ? 0 : -1; 413 } 414 415 /** 416 * Create flow action: dest_array 417 * 418 * @param[in] domain 419 * Pointer to relevant domain. 420 * @param[in] num_dest 421 * Number of destinations array. 422 * @param[in] dests 423 * Array of destination attributes. 424 * @param[out] action 425 * Pointer to a valid action on success, NULL otherwise. 426 * 427 * @return 428 * 0 on success, or -1 on failure and errno is set. 429 */ 430 static inline int 431 mlx5_os_flow_dr_create_flow_action_dest_array 432 (void *domain, 433 size_t num_dest, 434 struct mlx5dv_dr_action_dest_attr *dests[], 435 void **action) 436 { 437 *action = mlx5_glue->dr_create_flow_action_dest_array( 438 domain, num_dest, dests); 439 return (*action) ? 0 : -1; 440 } 441 442 /** 443 * Destroy flow action. 444 * 445 * @param[in] action 446 * Pointer to action object to destroy. 447 * 448 * @return 449 * 0 on success, or the value of errno on failure. 450 */ 451 static inline int 452 mlx5_flow_os_destroy_flow_action(void *action) 453 { 454 return mlx5_glue->destroy_flow_action(action); 455 } 456 457 /** 458 * OS wrapper over Verbs API. 459 * Adjust flow priority based on the highest layer and the request priority. 460 * 461 * @param[in] dev 462 * Pointer to the Ethernet device structure. 463 * @param[in] priority 464 * The rule base priority. 465 * @param[in] subpriority 466 * The priority based on the items. 467 * 468 * @return 469 * The new priority. 470 */ 471 static inline uint32_t 472 mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority, 473 uint32_t subpriority) 474 { 475 return mlx5_flow_adjust_priority(dev, priority, subpriority); 476 } 477 478 static inline int 479 mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags) 480 { 481 return mlx5_glue->dr_sync_domain(domain, flags); 482 } 483 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */ 484