1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2016 6WIND S.A. 3 * Copyright 2016 Mellanox Technologies, Ltd 4 */ 5 6 #include <errno.h> 7 #include <stddef.h> 8 #include <stdint.h> 9 10 #include <rte_common.h> 11 #include <rte_errno.h> 12 #include <rte_branch_prediction.h> 13 #include <rte_string_fns.h> 14 #include <rte_mbuf_dyn.h> 15 #include "rte_ethdev.h" 16 #include "rte_flow_driver.h" 17 #include "rte_flow.h" 18 19 /* Mbuf dynamic field name for metadata. */ 20 int32_t rte_flow_dynf_metadata_offs = -1; 21 22 /* Mbuf dynamic field flag bit number for metadata. */ 23 uint64_t rte_flow_dynf_metadata_mask; 24 25 /** 26 * Flow elements description tables. 27 */ 28 struct rte_flow_desc_data { 29 const char *name; 30 size_t size; 31 size_t (*desc_fn)(void *dst, const void *src); 32 }; 33 34 /** 35 * 36 * @param buf 37 * Destination memory. 38 * @param data 39 * Source memory 40 * @param size 41 * Requested copy size 42 * @param desc 43 * rte_flow_desc_item - for flow item conversion. 44 * rte_flow_desc_action - for flow action conversion. 45 * @param type 46 * Offset into the desc param or negative value for private flow elements. 47 */ 48 static inline size_t 49 rte_flow_conv_copy(void *buf, const void *data, const size_t size, 50 const struct rte_flow_desc_data *desc, int type) 51 { 52 /** 53 * Allow PMD private flow item 54 */ 55 bool rte_type = type >= 0; 56 57 size_t sz = rte_type ? desc[type].size : sizeof(void *); 58 if (buf == NULL || data == NULL) 59 return 0; 60 rte_memcpy(buf, data, (size > sz ? sz : size)); 61 if (rte_type && desc[type].desc_fn) 62 sz += desc[type].desc_fn(size > 0 ? buf : NULL, data); 63 return sz; 64 } 65 66 static size_t 67 rte_flow_item_flex_conv(void *buf, const void *data) 68 { 69 struct rte_flow_item_flex *dst = buf; 70 const struct rte_flow_item_flex *src = data; 71 if (buf) { 72 dst->pattern = rte_memcpy 73 ((void *)((uintptr_t)(dst + 1)), src->pattern, 74 src->length); 75 } 76 return src->length; 77 } 78 79 /** Generate flow_item[] entry. */ 80 #define MK_FLOW_ITEM(t, s) \ 81 [RTE_FLOW_ITEM_TYPE_ ## t] = { \ 82 .name = # t, \ 83 .size = s, \ 84 .desc_fn = NULL,\ 85 } 86 87 #define MK_FLOW_ITEM_FN(t, s, fn) \ 88 [RTE_FLOW_ITEM_TYPE_ ## t] = {\ 89 .name = # t, \ 90 .size = s, \ 91 .desc_fn = fn, \ 92 } 93 94 /** Information about known flow pattern items. */ 95 static const struct rte_flow_desc_data rte_flow_desc_item[] = { 96 MK_FLOW_ITEM(END, 0), 97 MK_FLOW_ITEM(VOID, 0), 98 MK_FLOW_ITEM(INVERT, 0), 99 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)), 100 MK_FLOW_ITEM(PORT_ID, sizeof(struct rte_flow_item_port_id)), 101 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), 102 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)), 103 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)), 104 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)), 105 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)), 106 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)), 107 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)), 108 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)), 109 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)), 110 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)), 111 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)), 112 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)), 113 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)), 114 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)), 115 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)), 116 MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)), 117 MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)), 118 MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)), 119 MK_FLOW_ITEM(ESP, sizeof(struct rte_flow_item_esp)), 120 MK_FLOW_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)), 121 MK_FLOW_ITEM(VXLAN_GPE, sizeof(struct rte_flow_item_vxlan_gpe)), 122 MK_FLOW_ITEM(ARP_ETH_IPV4, sizeof(struct rte_flow_item_arp_eth_ipv4)), 123 MK_FLOW_ITEM(IPV6_EXT, sizeof(struct rte_flow_item_ipv6_ext)), 124 MK_FLOW_ITEM(IPV6_FRAG_EXT, sizeof(struct rte_flow_item_ipv6_frag_ext)), 125 MK_FLOW_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)), 126 MK_FLOW_ITEM(ICMP6_ND_NS, sizeof(struct rte_flow_item_icmp6_nd_ns)), 127 MK_FLOW_ITEM(ICMP6_ND_NA, sizeof(struct rte_flow_item_icmp6_nd_na)), 128 MK_FLOW_ITEM(ICMP6_ND_OPT, sizeof(struct rte_flow_item_icmp6_nd_opt)), 129 MK_FLOW_ITEM(ICMP6_ND_OPT_SLA_ETH, 130 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)), 131 MK_FLOW_ITEM(ICMP6_ND_OPT_TLA_ETH, 132 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)), 133 MK_FLOW_ITEM(MARK, sizeof(struct rte_flow_item_mark)), 134 MK_FLOW_ITEM(META, sizeof(struct rte_flow_item_meta)), 135 MK_FLOW_ITEM(TAG, sizeof(struct rte_flow_item_tag)), 136 MK_FLOW_ITEM(GRE_KEY, sizeof(rte_be32_t)), 137 MK_FLOW_ITEM(GRE_OPTION, sizeof(struct rte_flow_item_gre_opt)), 138 MK_FLOW_ITEM(GTP_PSC, sizeof(struct rte_flow_item_gtp_psc)), 139 MK_FLOW_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)), 140 MK_FLOW_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)), 141 MK_FLOW_ITEM(PPPOE_PROTO_ID, 142 sizeof(struct rte_flow_item_pppoe_proto_id)), 143 MK_FLOW_ITEM(NSH, sizeof(struct rte_flow_item_nsh)), 144 MK_FLOW_ITEM(IGMP, sizeof(struct rte_flow_item_igmp)), 145 MK_FLOW_ITEM(AH, sizeof(struct rte_flow_item_ah)), 146 MK_FLOW_ITEM(HIGIG2, sizeof(struct rte_flow_item_higig2_hdr)), 147 MK_FLOW_ITEM(L2TPV3OIP, sizeof(struct rte_flow_item_l2tpv3oip)), 148 MK_FLOW_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)), 149 MK_FLOW_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)), 150 MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)), 151 MK_FLOW_ITEM(INTEGRITY, sizeof(struct rte_flow_item_integrity)), 152 MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)), 153 MK_FLOW_ITEM(PORT_REPRESENTOR, sizeof(struct rte_flow_item_ethdev)), 154 MK_FLOW_ITEM(REPRESENTED_PORT, sizeof(struct rte_flow_item_ethdev)), 155 MK_FLOW_ITEM_FN(FLEX, sizeof(struct rte_flow_item_flex), 156 rte_flow_item_flex_conv), 157 MK_FLOW_ITEM(L2TPV2, sizeof(struct rte_flow_item_l2tpv2)), 158 MK_FLOW_ITEM(PPP, sizeof(struct rte_flow_item_ppp)), 159 MK_FLOW_ITEM(METER_COLOR, sizeof(struct rte_flow_item_meter_color)), 160 }; 161 162 /** Generate flow_action[] entry. */ 163 #define MK_FLOW_ACTION(t, s) \ 164 [RTE_FLOW_ACTION_TYPE_ ## t] = { \ 165 .name = # t, \ 166 .size = s, \ 167 .desc_fn = NULL,\ 168 } 169 170 #define MK_FLOW_ACTION_FN(t, fn) \ 171 [RTE_FLOW_ACTION_TYPE_ ## t] = { \ 172 .name = # t, \ 173 .size = 0, \ 174 .desc_fn = fn,\ 175 } 176 177 178 /** Information about known flow actions. */ 179 static const struct rte_flow_desc_data rte_flow_desc_action[] = { 180 MK_FLOW_ACTION(END, 0), 181 MK_FLOW_ACTION(VOID, 0), 182 MK_FLOW_ACTION(PASSTHRU, 0), 183 MK_FLOW_ACTION(JUMP, sizeof(struct rte_flow_action_jump)), 184 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)), 185 MK_FLOW_ACTION(FLAG, 0), 186 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)), 187 MK_FLOW_ACTION(DROP, 0), 188 MK_FLOW_ACTION(COUNT, sizeof(struct rte_flow_action_count)), 189 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), 190 MK_FLOW_ACTION(PF, 0), 191 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)), 192 MK_FLOW_ACTION(PORT_ID, sizeof(struct rte_flow_action_port_id)), 193 MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)), 194 MK_FLOW_ACTION(SECURITY, sizeof(struct rte_flow_action_security)), 195 MK_FLOW_ACTION(OF_DEC_NW_TTL, 0), 196 MK_FLOW_ACTION(OF_POP_VLAN, 0), 197 MK_FLOW_ACTION(OF_PUSH_VLAN, 198 sizeof(struct rte_flow_action_of_push_vlan)), 199 MK_FLOW_ACTION(OF_SET_VLAN_VID, 200 sizeof(struct rte_flow_action_of_set_vlan_vid)), 201 MK_FLOW_ACTION(OF_SET_VLAN_PCP, 202 sizeof(struct rte_flow_action_of_set_vlan_pcp)), 203 MK_FLOW_ACTION(OF_POP_MPLS, 204 sizeof(struct rte_flow_action_of_pop_mpls)), 205 MK_FLOW_ACTION(OF_PUSH_MPLS, 206 sizeof(struct rte_flow_action_of_push_mpls)), 207 MK_FLOW_ACTION(VXLAN_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)), 208 MK_FLOW_ACTION(VXLAN_DECAP, 0), 209 MK_FLOW_ACTION(NVGRE_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)), 210 MK_FLOW_ACTION(NVGRE_DECAP, 0), 211 MK_FLOW_ACTION(RAW_ENCAP, sizeof(struct rte_flow_action_raw_encap)), 212 MK_FLOW_ACTION(RAW_DECAP, sizeof(struct rte_flow_action_raw_decap)), 213 MK_FLOW_ACTION(SET_IPV4_SRC, 214 sizeof(struct rte_flow_action_set_ipv4)), 215 MK_FLOW_ACTION(SET_IPV4_DST, 216 sizeof(struct rte_flow_action_set_ipv4)), 217 MK_FLOW_ACTION(SET_IPV6_SRC, 218 sizeof(struct rte_flow_action_set_ipv6)), 219 MK_FLOW_ACTION(SET_IPV6_DST, 220 sizeof(struct rte_flow_action_set_ipv6)), 221 MK_FLOW_ACTION(SET_TP_SRC, 222 sizeof(struct rte_flow_action_set_tp)), 223 MK_FLOW_ACTION(SET_TP_DST, 224 sizeof(struct rte_flow_action_set_tp)), 225 MK_FLOW_ACTION(MAC_SWAP, 0), 226 MK_FLOW_ACTION(DEC_TTL, 0), 227 MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)), 228 MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)), 229 MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)), 230 MK_FLOW_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)), 231 MK_FLOW_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)), 232 MK_FLOW_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)), 233 MK_FLOW_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)), 234 MK_FLOW_ACTION(SET_TAG, sizeof(struct rte_flow_action_set_tag)), 235 MK_FLOW_ACTION(SET_META, sizeof(struct rte_flow_action_set_meta)), 236 MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)), 237 MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)), 238 MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)), 239 MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), 240 MK_FLOW_ACTION(MODIFY_FIELD, 241 sizeof(struct rte_flow_action_modify_field)), 242 /** 243 * Indirect action represented as handle of type 244 * (struct rte_flow_action_handle *) stored in conf field (see 245 * struct rte_flow_action); no need for additional structure to * store 246 * indirect action handle. 247 */ 248 MK_FLOW_ACTION(INDIRECT, 0), 249 MK_FLOW_ACTION(CONNTRACK, sizeof(struct rte_flow_action_conntrack)), 250 MK_FLOW_ACTION(PORT_REPRESENTOR, sizeof(struct rte_flow_action_ethdev)), 251 MK_FLOW_ACTION(REPRESENTED_PORT, sizeof(struct rte_flow_action_ethdev)), 252 MK_FLOW_ACTION(METER_MARK, sizeof(struct rte_flow_action_meter_mark)), 253 MK_FLOW_ACTION(SEND_TO_KERNEL, 0), 254 }; 255 256 int 257 rte_flow_dynf_metadata_register(void) 258 { 259 int offset; 260 int flag; 261 262 static const struct rte_mbuf_dynfield desc_offs = { 263 .name = RTE_MBUF_DYNFIELD_METADATA_NAME, 264 .size = sizeof(uint32_t), 265 .align = __alignof__(uint32_t), 266 }; 267 static const struct rte_mbuf_dynflag desc_flag = { 268 .name = RTE_MBUF_DYNFLAG_METADATA_NAME, 269 }; 270 271 offset = rte_mbuf_dynfield_register(&desc_offs); 272 if (offset < 0) 273 goto error; 274 flag = rte_mbuf_dynflag_register(&desc_flag); 275 if (flag < 0) 276 goto error; 277 rte_flow_dynf_metadata_offs = offset; 278 rte_flow_dynf_metadata_mask = RTE_BIT64(flag); 279 return 0; 280 281 error: 282 rte_flow_dynf_metadata_offs = -1; 283 rte_flow_dynf_metadata_mask = UINT64_C(0); 284 return -rte_errno; 285 } 286 287 static inline void 288 fts_enter(struct rte_eth_dev *dev) 289 { 290 if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE)) 291 pthread_mutex_lock(&dev->data->flow_ops_mutex); 292 } 293 294 static inline void 295 fts_exit(struct rte_eth_dev *dev) 296 { 297 if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE)) 298 pthread_mutex_unlock(&dev->data->flow_ops_mutex); 299 } 300 301 static int 302 flow_err(uint16_t port_id, int ret, struct rte_flow_error *error) 303 { 304 if (ret == 0) 305 return 0; 306 if (rte_eth_dev_is_removed(port_id)) 307 return rte_flow_error_set(error, EIO, 308 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 309 NULL, rte_strerror(EIO)); 310 return ret; 311 } 312 313 /* Get generic flow operations structure from a port. */ 314 const struct rte_flow_ops * 315 rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error) 316 { 317 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 318 const struct rte_flow_ops *ops; 319 int code; 320 321 if (unlikely(!rte_eth_dev_is_valid_port(port_id))) 322 code = ENODEV; 323 else if (unlikely(dev->dev_ops->flow_ops_get == NULL)) 324 /* flow API not supported with this driver dev_ops */ 325 code = ENOSYS; 326 else 327 code = dev->dev_ops->flow_ops_get(dev, &ops); 328 if (code == 0 && ops == NULL) 329 /* flow API not supported with this device */ 330 code = ENOSYS; 331 332 if (code != 0) { 333 rte_flow_error_set(error, code, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 334 NULL, rte_strerror(code)); 335 return NULL; 336 } 337 return ops; 338 } 339 340 /* Check whether a flow rule can be created on a given port. */ 341 int 342 rte_flow_validate(uint16_t port_id, 343 const struct rte_flow_attr *attr, 344 const struct rte_flow_item pattern[], 345 const struct rte_flow_action actions[], 346 struct rte_flow_error *error) 347 { 348 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 349 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 350 int ret; 351 352 if (likely(!!attr) && attr->transfer && 353 (attr->ingress || attr->egress)) { 354 return rte_flow_error_set(error, EINVAL, 355 RTE_FLOW_ERROR_TYPE_ATTR, 356 attr, "cannot use attr ingress/egress with attr transfer"); 357 } 358 359 if (unlikely(!ops)) 360 return -rte_errno; 361 if (likely(!!ops->validate)) { 362 fts_enter(dev); 363 ret = ops->validate(dev, attr, pattern, actions, error); 364 fts_exit(dev); 365 return flow_err(port_id, ret, error); 366 } 367 return rte_flow_error_set(error, ENOSYS, 368 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 369 NULL, rte_strerror(ENOSYS)); 370 } 371 372 /* Create a flow rule on a given port. */ 373 struct rte_flow * 374 rte_flow_create(uint16_t port_id, 375 const struct rte_flow_attr *attr, 376 const struct rte_flow_item pattern[], 377 const struct rte_flow_action actions[], 378 struct rte_flow_error *error) 379 { 380 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 381 struct rte_flow *flow; 382 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 383 384 if (unlikely(!ops)) 385 return NULL; 386 if (likely(!!ops->create)) { 387 fts_enter(dev); 388 flow = ops->create(dev, attr, pattern, actions, error); 389 fts_exit(dev); 390 if (flow == NULL) 391 flow_err(port_id, -rte_errno, error); 392 return flow; 393 } 394 rte_flow_error_set(error, ENOSYS, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 395 NULL, rte_strerror(ENOSYS)); 396 return NULL; 397 } 398 399 /* Destroy a flow rule on a given port. */ 400 int 401 rte_flow_destroy(uint16_t port_id, 402 struct rte_flow *flow, 403 struct rte_flow_error *error) 404 { 405 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 406 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 407 int ret; 408 409 if (unlikely(!ops)) 410 return -rte_errno; 411 if (likely(!!ops->destroy)) { 412 fts_enter(dev); 413 ret = ops->destroy(dev, flow, error); 414 fts_exit(dev); 415 return flow_err(port_id, ret, error); 416 } 417 return rte_flow_error_set(error, ENOSYS, 418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 419 NULL, rte_strerror(ENOSYS)); 420 } 421 422 /* Destroy all flow rules associated with a port. */ 423 int 424 rte_flow_flush(uint16_t port_id, 425 struct rte_flow_error *error) 426 { 427 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 428 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 429 int ret; 430 431 if (unlikely(!ops)) 432 return -rte_errno; 433 if (likely(!!ops->flush)) { 434 fts_enter(dev); 435 ret = ops->flush(dev, error); 436 fts_exit(dev); 437 return flow_err(port_id, ret, error); 438 } 439 return rte_flow_error_set(error, ENOSYS, 440 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 441 NULL, rte_strerror(ENOSYS)); 442 } 443 444 /* Query an existing flow rule. */ 445 int 446 rte_flow_query(uint16_t port_id, 447 struct rte_flow *flow, 448 const struct rte_flow_action *action, 449 void *data, 450 struct rte_flow_error *error) 451 { 452 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 453 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 454 int ret; 455 456 if (!ops) 457 return -rte_errno; 458 if (likely(!!ops->query)) { 459 fts_enter(dev); 460 ret = ops->query(dev, flow, action, data, error); 461 fts_exit(dev); 462 return flow_err(port_id, ret, error); 463 } 464 return rte_flow_error_set(error, ENOSYS, 465 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 466 NULL, rte_strerror(ENOSYS)); 467 } 468 469 /* Restrict ingress traffic to the defined flow rules. */ 470 int 471 rte_flow_isolate(uint16_t port_id, 472 int set, 473 struct rte_flow_error *error) 474 { 475 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 476 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 477 int ret; 478 479 if (!ops) 480 return -rte_errno; 481 if (likely(!!ops->isolate)) { 482 fts_enter(dev); 483 ret = ops->isolate(dev, set, error); 484 fts_exit(dev); 485 return flow_err(port_id, ret, error); 486 } 487 return rte_flow_error_set(error, ENOSYS, 488 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 489 NULL, rte_strerror(ENOSYS)); 490 } 491 492 /* Initialize flow error structure. */ 493 int 494 rte_flow_error_set(struct rte_flow_error *error, 495 int code, 496 enum rte_flow_error_type type, 497 const void *cause, 498 const char *message) 499 { 500 if (error) { 501 *error = (struct rte_flow_error){ 502 .type = type, 503 .cause = cause, 504 .message = message, 505 }; 506 } 507 rte_errno = code; 508 return -code; 509 } 510 511 /** Pattern item specification types. */ 512 enum rte_flow_conv_item_spec_type { 513 RTE_FLOW_CONV_ITEM_SPEC, 514 RTE_FLOW_CONV_ITEM_LAST, 515 RTE_FLOW_CONV_ITEM_MASK, 516 }; 517 518 /** 519 * Copy pattern item specification. 520 * 521 * @param[out] buf 522 * Output buffer. Can be NULL if @p size is zero. 523 * @param size 524 * Size of @p buf in bytes. 525 * @param[in] item 526 * Pattern item to copy specification from. 527 * @param type 528 * Specification selector for either @p spec, @p last or @p mask. 529 * 530 * @return 531 * Number of bytes needed to store pattern item specification regardless 532 * of @p size. @p buf contents are truncated to @p size if not large 533 * enough. 534 */ 535 static size_t 536 rte_flow_conv_item_spec(void *buf, const size_t size, 537 const struct rte_flow_item *item, 538 enum rte_flow_conv_item_spec_type type) 539 { 540 size_t off; 541 const void *data = 542 type == RTE_FLOW_CONV_ITEM_SPEC ? item->spec : 543 type == RTE_FLOW_CONV_ITEM_LAST ? item->last : 544 type == RTE_FLOW_CONV_ITEM_MASK ? item->mask : 545 NULL; 546 547 switch (item->type) { 548 union { 549 const struct rte_flow_item_raw *raw; 550 } spec; 551 union { 552 const struct rte_flow_item_raw *raw; 553 } last; 554 union { 555 const struct rte_flow_item_raw *raw; 556 } mask; 557 union { 558 const struct rte_flow_item_raw *raw; 559 } src; 560 union { 561 struct rte_flow_item_raw *raw; 562 } dst; 563 size_t tmp; 564 565 case RTE_FLOW_ITEM_TYPE_RAW: 566 spec.raw = item->spec; 567 last.raw = item->last ? item->last : item->spec; 568 mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask; 569 src.raw = data; 570 dst.raw = buf; 571 rte_memcpy(dst.raw, 572 (&(struct rte_flow_item_raw){ 573 .relative = src.raw->relative, 574 .search = src.raw->search, 575 .reserved = src.raw->reserved, 576 .offset = src.raw->offset, 577 .limit = src.raw->limit, 578 .length = src.raw->length, 579 }), 580 size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size); 581 off = sizeof(*dst.raw); 582 if (type == RTE_FLOW_CONV_ITEM_SPEC || 583 (type == RTE_FLOW_CONV_ITEM_MASK && 584 ((spec.raw->length & mask.raw->length) >= 585 (last.raw->length & mask.raw->length)))) 586 tmp = spec.raw->length & mask.raw->length; 587 else 588 tmp = last.raw->length & mask.raw->length; 589 if (tmp) { 590 off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern)); 591 if (size >= off + tmp) 592 dst.raw->pattern = rte_memcpy 593 ((void *)((uintptr_t)dst.raw + off), 594 src.raw->pattern, tmp); 595 off += tmp; 596 } 597 break; 598 default: 599 off = rte_flow_conv_copy(buf, data, size, 600 rte_flow_desc_item, item->type); 601 break; 602 } 603 return off; 604 } 605 606 /** 607 * Copy action configuration. 608 * 609 * @param[out] buf 610 * Output buffer. Can be NULL if @p size is zero. 611 * @param size 612 * Size of @p buf in bytes. 613 * @param[in] action 614 * Action to copy configuration from. 615 * 616 * @return 617 * Number of bytes needed to store pattern item specification regardless 618 * of @p size. @p buf contents are truncated to @p size if not large 619 * enough. 620 */ 621 static size_t 622 rte_flow_conv_action_conf(void *buf, const size_t size, 623 const struct rte_flow_action *action) 624 { 625 size_t off; 626 627 switch (action->type) { 628 union { 629 const struct rte_flow_action_rss *rss; 630 const struct rte_flow_action_vxlan_encap *vxlan_encap; 631 const struct rte_flow_action_nvgre_encap *nvgre_encap; 632 } src; 633 union { 634 struct rte_flow_action_rss *rss; 635 struct rte_flow_action_vxlan_encap *vxlan_encap; 636 struct rte_flow_action_nvgre_encap *nvgre_encap; 637 } dst; 638 size_t tmp; 639 int ret; 640 641 case RTE_FLOW_ACTION_TYPE_RSS: 642 src.rss = action->conf; 643 dst.rss = buf; 644 rte_memcpy(dst.rss, 645 (&(struct rte_flow_action_rss){ 646 .func = src.rss->func, 647 .level = src.rss->level, 648 .types = src.rss->types, 649 .key_len = src.rss->key_len, 650 .queue_num = src.rss->queue_num, 651 }), 652 size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size); 653 off = sizeof(*dst.rss); 654 if (src.rss->key_len && src.rss->key) { 655 off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key)); 656 tmp = sizeof(*src.rss->key) * src.rss->key_len; 657 if (size >= off + tmp) 658 dst.rss->key = rte_memcpy 659 ((void *)((uintptr_t)dst.rss + off), 660 src.rss->key, tmp); 661 off += tmp; 662 } 663 if (src.rss->queue_num) { 664 off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue)); 665 tmp = sizeof(*src.rss->queue) * src.rss->queue_num; 666 if (size >= off + tmp) 667 dst.rss->queue = rte_memcpy 668 ((void *)((uintptr_t)dst.rss + off), 669 src.rss->queue, tmp); 670 off += tmp; 671 } 672 break; 673 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP: 674 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP: 675 src.vxlan_encap = action->conf; 676 dst.vxlan_encap = buf; 677 RTE_BUILD_BUG_ON(sizeof(*src.vxlan_encap) != 678 sizeof(*src.nvgre_encap) || 679 offsetof(struct rte_flow_action_vxlan_encap, 680 definition) != 681 offsetof(struct rte_flow_action_nvgre_encap, 682 definition)); 683 off = sizeof(*dst.vxlan_encap); 684 if (src.vxlan_encap->definition) { 685 off = RTE_ALIGN_CEIL 686 (off, sizeof(*dst.vxlan_encap->definition)); 687 ret = rte_flow_conv 688 (RTE_FLOW_CONV_OP_PATTERN, 689 (void *)((uintptr_t)dst.vxlan_encap + off), 690 size > off ? size - off : 0, 691 src.vxlan_encap->definition, NULL); 692 if (ret < 0) 693 return 0; 694 if (size >= off + ret) 695 dst.vxlan_encap->definition = 696 (void *)((uintptr_t)dst.vxlan_encap + 697 off); 698 off += ret; 699 } 700 break; 701 default: 702 off = rte_flow_conv_copy(buf, action->conf, size, 703 rte_flow_desc_action, action->type); 704 break; 705 } 706 return off; 707 } 708 709 /** 710 * Copy a list of pattern items. 711 * 712 * @param[out] dst 713 * Destination buffer. Can be NULL if @p size is zero. 714 * @param size 715 * Size of @p dst in bytes. 716 * @param[in] src 717 * Source pattern items. 718 * @param num 719 * Maximum number of pattern items to process from @p src or 0 to process 720 * the entire list. In both cases, processing stops after 721 * RTE_FLOW_ITEM_TYPE_END is encountered. 722 * @param[out] error 723 * Perform verbose error reporting if not NULL. 724 * 725 * @return 726 * A positive value representing the number of bytes needed to store 727 * pattern items regardless of @p size on success (@p buf contents are 728 * truncated to @p size if not large enough), a negative errno value 729 * otherwise and rte_errno is set. 730 */ 731 static int 732 rte_flow_conv_pattern(struct rte_flow_item *dst, 733 const size_t size, 734 const struct rte_flow_item *src, 735 unsigned int num, 736 struct rte_flow_error *error) 737 { 738 uintptr_t data = (uintptr_t)dst; 739 size_t off; 740 size_t ret; 741 unsigned int i; 742 743 for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) { 744 /** 745 * allow PMD private flow item 746 */ 747 if (((int)src->type >= 0) && 748 ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) || 749 !rte_flow_desc_item[src->type].name)) 750 return rte_flow_error_set 751 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src, 752 "cannot convert unknown item type"); 753 if (size >= off + sizeof(*dst)) 754 *dst = (struct rte_flow_item){ 755 .type = src->type, 756 }; 757 off += sizeof(*dst); 758 if (!src->type) 759 num = i + 1; 760 } 761 num = i; 762 src -= num; 763 dst -= num; 764 do { 765 if (src->spec) { 766 off = RTE_ALIGN_CEIL(off, sizeof(double)); 767 ret = rte_flow_conv_item_spec 768 ((void *)(data + off), 769 size > off ? size - off : 0, src, 770 RTE_FLOW_CONV_ITEM_SPEC); 771 if (size && size >= off + ret) 772 dst->spec = (void *)(data + off); 773 off += ret; 774 775 } 776 if (src->last) { 777 off = RTE_ALIGN_CEIL(off, sizeof(double)); 778 ret = rte_flow_conv_item_spec 779 ((void *)(data + off), 780 size > off ? size - off : 0, src, 781 RTE_FLOW_CONV_ITEM_LAST); 782 if (size && size >= off + ret) 783 dst->last = (void *)(data + off); 784 off += ret; 785 } 786 if (src->mask) { 787 off = RTE_ALIGN_CEIL(off, sizeof(double)); 788 ret = rte_flow_conv_item_spec 789 ((void *)(data + off), 790 size > off ? size - off : 0, src, 791 RTE_FLOW_CONV_ITEM_MASK); 792 if (size && size >= off + ret) 793 dst->mask = (void *)(data + off); 794 off += ret; 795 } 796 ++src; 797 ++dst; 798 } while (--num); 799 return off; 800 } 801 802 /** 803 * Copy a list of actions. 804 * 805 * @param[out] dst 806 * Destination buffer. Can be NULL if @p size is zero. 807 * @param size 808 * Size of @p dst in bytes. 809 * @param[in] src 810 * Source actions. 811 * @param num 812 * Maximum number of actions to process from @p src or 0 to process the 813 * entire list. In both cases, processing stops after 814 * RTE_FLOW_ACTION_TYPE_END is encountered. 815 * @param[out] error 816 * Perform verbose error reporting if not NULL. 817 * 818 * @return 819 * A positive value representing the number of bytes needed to store 820 * actions regardless of @p size on success (@p buf contents are truncated 821 * to @p size if not large enough), a negative errno value otherwise and 822 * rte_errno is set. 823 */ 824 static int 825 rte_flow_conv_actions(struct rte_flow_action *dst, 826 const size_t size, 827 const struct rte_flow_action *src, 828 unsigned int num, 829 struct rte_flow_error *error) 830 { 831 uintptr_t data = (uintptr_t)dst; 832 size_t off; 833 size_t ret; 834 unsigned int i; 835 836 for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) { 837 /** 838 * allow PMD private flow action 839 */ 840 if (((int)src->type >= 0) && 841 ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) || 842 !rte_flow_desc_action[src->type].name)) 843 return rte_flow_error_set 844 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, 845 src, "cannot convert unknown action type"); 846 if (size >= off + sizeof(*dst)) 847 *dst = (struct rte_flow_action){ 848 .type = src->type, 849 }; 850 off += sizeof(*dst); 851 if (!src->type) 852 num = i + 1; 853 } 854 num = i; 855 src -= num; 856 dst -= num; 857 do { 858 if (src->conf) { 859 off = RTE_ALIGN_CEIL(off, sizeof(double)); 860 ret = rte_flow_conv_action_conf 861 ((void *)(data + off), 862 size > off ? size - off : 0, src); 863 if (size && size >= off + ret) 864 dst->conf = (void *)(data + off); 865 off += ret; 866 } 867 ++src; 868 ++dst; 869 } while (--num); 870 return off; 871 } 872 873 /** 874 * Copy flow rule components. 875 * 876 * This comprises the flow rule descriptor itself, attributes, pattern and 877 * actions list. NULL components in @p src are skipped. 878 * 879 * @param[out] dst 880 * Destination buffer. Can be NULL if @p size is zero. 881 * @param size 882 * Size of @p dst in bytes. 883 * @param[in] src 884 * Source flow rule descriptor. 885 * @param[out] error 886 * Perform verbose error reporting if not NULL. 887 * 888 * @return 889 * A positive value representing the number of bytes needed to store all 890 * components including the descriptor regardless of @p size on success 891 * (@p buf contents are truncated to @p size if not large enough), a 892 * negative errno value otherwise and rte_errno is set. 893 */ 894 static int 895 rte_flow_conv_rule(struct rte_flow_conv_rule *dst, 896 const size_t size, 897 const struct rte_flow_conv_rule *src, 898 struct rte_flow_error *error) 899 { 900 size_t off; 901 int ret; 902 903 rte_memcpy(dst, 904 (&(struct rte_flow_conv_rule){ 905 .attr = NULL, 906 .pattern = NULL, 907 .actions = NULL, 908 }), 909 size > sizeof(*dst) ? sizeof(*dst) : size); 910 off = sizeof(*dst); 911 if (src->attr_ro) { 912 off = RTE_ALIGN_CEIL(off, sizeof(double)); 913 if (size && size >= off + sizeof(*dst->attr)) 914 dst->attr = rte_memcpy 915 ((void *)((uintptr_t)dst + off), 916 src->attr_ro, sizeof(*dst->attr)); 917 off += sizeof(*dst->attr); 918 } 919 if (src->pattern_ro) { 920 off = RTE_ALIGN_CEIL(off, sizeof(double)); 921 ret = rte_flow_conv_pattern((void *)((uintptr_t)dst + off), 922 size > off ? size - off : 0, 923 src->pattern_ro, 0, error); 924 if (ret < 0) 925 return ret; 926 if (size && size >= off + (size_t)ret) 927 dst->pattern = (void *)((uintptr_t)dst + off); 928 off += ret; 929 } 930 if (src->actions_ro) { 931 off = RTE_ALIGN_CEIL(off, sizeof(double)); 932 ret = rte_flow_conv_actions((void *)((uintptr_t)dst + off), 933 size > off ? size - off : 0, 934 src->actions_ro, 0, error); 935 if (ret < 0) 936 return ret; 937 if (size >= off + (size_t)ret) 938 dst->actions = (void *)((uintptr_t)dst + off); 939 off += ret; 940 } 941 return off; 942 } 943 944 /** 945 * Retrieve the name of a pattern item/action type. 946 * 947 * @param is_action 948 * Nonzero when @p src represents an action type instead of a pattern item 949 * type. 950 * @param is_ptr 951 * Nonzero to write string address instead of contents into @p dst. 952 * @param[out] dst 953 * Destination buffer. Can be NULL if @p size is zero. 954 * @param size 955 * Size of @p dst in bytes. 956 * @param[in] src 957 * Depending on @p is_action, source pattern item or action type cast as a 958 * pointer. 959 * @param[out] error 960 * Perform verbose error reporting if not NULL. 961 * 962 * @return 963 * A positive value representing the number of bytes needed to store the 964 * name or its address regardless of @p size on success (@p buf contents 965 * are truncated to @p size if not large enough), a negative errno value 966 * otherwise and rte_errno is set. 967 */ 968 static int 969 rte_flow_conv_name(int is_action, 970 int is_ptr, 971 char *dst, 972 const size_t size, 973 const void *src, 974 struct rte_flow_error *error) 975 { 976 struct desc_info { 977 const struct rte_flow_desc_data *data; 978 size_t num; 979 }; 980 static const struct desc_info info_rep[2] = { 981 { rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), }, 982 { rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), }, 983 }; 984 const struct desc_info *const info = &info_rep[!!is_action]; 985 unsigned int type = (uintptr_t)src; 986 987 if (type >= info->num) 988 return rte_flow_error_set 989 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, 990 "unknown object type to retrieve the name of"); 991 if (!is_ptr) 992 return strlcpy(dst, info->data[type].name, size); 993 if (size >= sizeof(const char **)) 994 *((const char **)dst) = info->data[type].name; 995 return sizeof(const char **); 996 } 997 998 /** Helper function to convert flow API objects. */ 999 int 1000 rte_flow_conv(enum rte_flow_conv_op op, 1001 void *dst, 1002 size_t size, 1003 const void *src, 1004 struct rte_flow_error *error) 1005 { 1006 switch (op) { 1007 const struct rte_flow_attr *attr; 1008 1009 case RTE_FLOW_CONV_OP_NONE: 1010 return 0; 1011 case RTE_FLOW_CONV_OP_ATTR: 1012 attr = src; 1013 if (size > sizeof(*attr)) 1014 size = sizeof(*attr); 1015 rte_memcpy(dst, attr, size); 1016 return sizeof(*attr); 1017 case RTE_FLOW_CONV_OP_ITEM: 1018 return rte_flow_conv_pattern(dst, size, src, 1, error); 1019 case RTE_FLOW_CONV_OP_ACTION: 1020 return rte_flow_conv_actions(dst, size, src, 1, error); 1021 case RTE_FLOW_CONV_OP_PATTERN: 1022 return rte_flow_conv_pattern(dst, size, src, 0, error); 1023 case RTE_FLOW_CONV_OP_ACTIONS: 1024 return rte_flow_conv_actions(dst, size, src, 0, error); 1025 case RTE_FLOW_CONV_OP_RULE: 1026 return rte_flow_conv_rule(dst, size, src, error); 1027 case RTE_FLOW_CONV_OP_ITEM_NAME: 1028 return rte_flow_conv_name(0, 0, dst, size, src, error); 1029 case RTE_FLOW_CONV_OP_ACTION_NAME: 1030 return rte_flow_conv_name(1, 0, dst, size, src, error); 1031 case RTE_FLOW_CONV_OP_ITEM_NAME_PTR: 1032 return rte_flow_conv_name(0, 1, dst, size, src, error); 1033 case RTE_FLOW_CONV_OP_ACTION_NAME_PTR: 1034 return rte_flow_conv_name(1, 1, dst, size, src, error); 1035 } 1036 return rte_flow_error_set 1037 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, 1038 "unknown object conversion operation"); 1039 } 1040 1041 /** Store a full rte_flow description. */ 1042 size_t 1043 rte_flow_copy(struct rte_flow_desc *desc, size_t len, 1044 const struct rte_flow_attr *attr, 1045 const struct rte_flow_item *items, 1046 const struct rte_flow_action *actions) 1047 { 1048 /* 1049 * Overlap struct rte_flow_conv with struct rte_flow_desc in order 1050 * to convert the former to the latter without wasting space. 1051 */ 1052 struct rte_flow_conv_rule *dst = 1053 len ? 1054 (void *)((uintptr_t)desc + 1055 (offsetof(struct rte_flow_desc, actions) - 1056 offsetof(struct rte_flow_conv_rule, actions))) : 1057 NULL; 1058 size_t dst_size = 1059 len > sizeof(*desc) - sizeof(*dst) ? 1060 len - (sizeof(*desc) - sizeof(*dst)) : 1061 0; 1062 struct rte_flow_conv_rule src = { 1063 .attr_ro = NULL, 1064 .pattern_ro = items, 1065 .actions_ro = actions, 1066 }; 1067 int ret; 1068 1069 RTE_BUILD_BUG_ON(sizeof(struct rte_flow_desc) < 1070 sizeof(struct rte_flow_conv_rule)); 1071 if (dst_size && 1072 (&dst->pattern != &desc->items || 1073 &dst->actions != &desc->actions || 1074 (uintptr_t)(dst + 1) != (uintptr_t)(desc + 1))) { 1075 rte_errno = EINVAL; 1076 return 0; 1077 } 1078 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, dst, dst_size, &src, NULL); 1079 if (ret < 0) 1080 return 0; 1081 ret += sizeof(*desc) - sizeof(*dst); 1082 rte_memcpy(desc, 1083 (&(struct rte_flow_desc){ 1084 .size = ret, 1085 .attr = *attr, 1086 .items = dst_size ? dst->pattern : NULL, 1087 .actions = dst_size ? dst->actions : NULL, 1088 }), 1089 len > sizeof(*desc) ? sizeof(*desc) : len); 1090 return ret; 1091 } 1092 1093 int 1094 rte_flow_dev_dump(uint16_t port_id, struct rte_flow *flow, 1095 FILE *file, struct rte_flow_error *error) 1096 { 1097 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1098 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1099 int ret; 1100 1101 if (unlikely(!ops)) 1102 return -rte_errno; 1103 if (likely(!!ops->dev_dump)) { 1104 fts_enter(dev); 1105 ret = ops->dev_dump(dev, flow, file, error); 1106 fts_exit(dev); 1107 return flow_err(port_id, ret, error); 1108 } 1109 return rte_flow_error_set(error, ENOSYS, 1110 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1111 NULL, rte_strerror(ENOSYS)); 1112 } 1113 1114 int 1115 rte_flow_get_aged_flows(uint16_t port_id, void **contexts, 1116 uint32_t nb_contexts, struct rte_flow_error *error) 1117 { 1118 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1119 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1120 int ret; 1121 1122 if (unlikely(!ops)) 1123 return -rte_errno; 1124 if (likely(!!ops->get_aged_flows)) { 1125 fts_enter(dev); 1126 ret = ops->get_aged_flows(dev, contexts, nb_contexts, error); 1127 fts_exit(dev); 1128 return flow_err(port_id, ret, error); 1129 } 1130 return rte_flow_error_set(error, ENOTSUP, 1131 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1132 NULL, rte_strerror(ENOTSUP)); 1133 } 1134 1135 struct rte_flow_action_handle * 1136 rte_flow_action_handle_create(uint16_t port_id, 1137 const struct rte_flow_indir_action_conf *conf, 1138 const struct rte_flow_action *action, 1139 struct rte_flow_error *error) 1140 { 1141 struct rte_flow_action_handle *handle; 1142 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1143 1144 if (unlikely(!ops)) 1145 return NULL; 1146 if (unlikely(!ops->action_handle_create)) { 1147 rte_flow_error_set(error, ENOSYS, 1148 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, 1149 rte_strerror(ENOSYS)); 1150 return NULL; 1151 } 1152 handle = ops->action_handle_create(&rte_eth_devices[port_id], 1153 conf, action, error); 1154 if (handle == NULL) 1155 flow_err(port_id, -rte_errno, error); 1156 return handle; 1157 } 1158 1159 int 1160 rte_flow_action_handle_destroy(uint16_t port_id, 1161 struct rte_flow_action_handle *handle, 1162 struct rte_flow_error *error) 1163 { 1164 int ret; 1165 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1166 1167 if (unlikely(!ops)) 1168 return -rte_errno; 1169 if (unlikely(!ops->action_handle_destroy)) 1170 return rte_flow_error_set(error, ENOSYS, 1171 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1172 NULL, rte_strerror(ENOSYS)); 1173 ret = ops->action_handle_destroy(&rte_eth_devices[port_id], 1174 handle, error); 1175 return flow_err(port_id, ret, error); 1176 } 1177 1178 int 1179 rte_flow_action_handle_update(uint16_t port_id, 1180 struct rte_flow_action_handle *handle, 1181 const void *update, 1182 struct rte_flow_error *error) 1183 { 1184 int ret; 1185 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1186 1187 if (unlikely(!ops)) 1188 return -rte_errno; 1189 if (unlikely(!ops->action_handle_update)) 1190 return rte_flow_error_set(error, ENOSYS, 1191 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1192 NULL, rte_strerror(ENOSYS)); 1193 ret = ops->action_handle_update(&rte_eth_devices[port_id], handle, 1194 update, error); 1195 return flow_err(port_id, ret, error); 1196 } 1197 1198 int 1199 rte_flow_action_handle_query(uint16_t port_id, 1200 const struct rte_flow_action_handle *handle, 1201 void *data, 1202 struct rte_flow_error *error) 1203 { 1204 int ret; 1205 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1206 1207 if (unlikely(!ops)) 1208 return -rte_errno; 1209 if (unlikely(!ops->action_handle_query)) 1210 return rte_flow_error_set(error, ENOSYS, 1211 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1212 NULL, rte_strerror(ENOSYS)); 1213 ret = ops->action_handle_query(&rte_eth_devices[port_id], handle, 1214 data, error); 1215 return flow_err(port_id, ret, error); 1216 } 1217 1218 int 1219 rte_flow_tunnel_decap_set(uint16_t port_id, 1220 struct rte_flow_tunnel *tunnel, 1221 struct rte_flow_action **actions, 1222 uint32_t *num_of_actions, 1223 struct rte_flow_error *error) 1224 { 1225 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1226 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1227 1228 if (unlikely(!ops)) 1229 return -rte_errno; 1230 if (likely(!!ops->tunnel_decap_set)) { 1231 return flow_err(port_id, 1232 ops->tunnel_decap_set(dev, tunnel, actions, 1233 num_of_actions, error), 1234 error); 1235 } 1236 return rte_flow_error_set(error, ENOTSUP, 1237 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1238 NULL, rte_strerror(ENOTSUP)); 1239 } 1240 1241 int 1242 rte_flow_tunnel_match(uint16_t port_id, 1243 struct rte_flow_tunnel *tunnel, 1244 struct rte_flow_item **items, 1245 uint32_t *num_of_items, 1246 struct rte_flow_error *error) 1247 { 1248 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1249 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1250 1251 if (unlikely(!ops)) 1252 return -rte_errno; 1253 if (likely(!!ops->tunnel_match)) { 1254 return flow_err(port_id, 1255 ops->tunnel_match(dev, tunnel, items, 1256 num_of_items, error), 1257 error); 1258 } 1259 return rte_flow_error_set(error, ENOTSUP, 1260 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1261 NULL, rte_strerror(ENOTSUP)); 1262 } 1263 1264 int 1265 rte_flow_get_restore_info(uint16_t port_id, 1266 struct rte_mbuf *m, 1267 struct rte_flow_restore_info *restore_info, 1268 struct rte_flow_error *error) 1269 { 1270 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1271 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1272 1273 if (unlikely(!ops)) 1274 return -rte_errno; 1275 if (likely(!!ops->get_restore_info)) { 1276 return flow_err(port_id, 1277 ops->get_restore_info(dev, m, restore_info, 1278 error), 1279 error); 1280 } 1281 return rte_flow_error_set(error, ENOTSUP, 1282 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1283 NULL, rte_strerror(ENOTSUP)); 1284 } 1285 1286 int 1287 rte_flow_tunnel_action_decap_release(uint16_t port_id, 1288 struct rte_flow_action *actions, 1289 uint32_t num_of_actions, 1290 struct rte_flow_error *error) 1291 { 1292 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1293 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1294 1295 if (unlikely(!ops)) 1296 return -rte_errno; 1297 if (likely(!!ops->tunnel_action_decap_release)) { 1298 return flow_err(port_id, 1299 ops->tunnel_action_decap_release(dev, actions, 1300 num_of_actions, 1301 error), 1302 error); 1303 } 1304 return rte_flow_error_set(error, ENOTSUP, 1305 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1306 NULL, rte_strerror(ENOTSUP)); 1307 } 1308 1309 int 1310 rte_flow_tunnel_item_release(uint16_t port_id, 1311 struct rte_flow_item *items, 1312 uint32_t num_of_items, 1313 struct rte_flow_error *error) 1314 { 1315 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1316 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1317 1318 if (unlikely(!ops)) 1319 return -rte_errno; 1320 if (likely(!!ops->tunnel_item_release)) { 1321 return flow_err(port_id, 1322 ops->tunnel_item_release(dev, items, 1323 num_of_items, error), 1324 error); 1325 } 1326 return rte_flow_error_set(error, ENOTSUP, 1327 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1328 NULL, rte_strerror(ENOTSUP)); 1329 } 1330 1331 int 1332 rte_flow_pick_transfer_proxy(uint16_t port_id, uint16_t *proxy_port_id, 1333 struct rte_flow_error *error) 1334 { 1335 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1336 struct rte_eth_dev *dev; 1337 1338 if (unlikely(ops == NULL)) 1339 return -rte_errno; 1340 1341 if (ops->pick_transfer_proxy == NULL) { 1342 *proxy_port_id = port_id; 1343 return 0; 1344 } 1345 1346 dev = &rte_eth_devices[port_id]; 1347 1348 return flow_err(port_id, 1349 ops->pick_transfer_proxy(dev, proxy_port_id, error), 1350 error); 1351 } 1352 1353 struct rte_flow_item_flex_handle * 1354 rte_flow_flex_item_create(uint16_t port_id, 1355 const struct rte_flow_item_flex_conf *conf, 1356 struct rte_flow_error *error) 1357 { 1358 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1359 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1360 struct rte_flow_item_flex_handle *handle; 1361 1362 if (unlikely(!ops)) 1363 return NULL; 1364 if (unlikely(!ops->flex_item_create)) { 1365 rte_flow_error_set(error, ENOTSUP, 1366 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1367 NULL, rte_strerror(ENOTSUP)); 1368 return NULL; 1369 } 1370 handle = ops->flex_item_create(dev, conf, error); 1371 if (handle == NULL) 1372 flow_err(port_id, -rte_errno, error); 1373 return handle; 1374 } 1375 1376 int 1377 rte_flow_flex_item_release(uint16_t port_id, 1378 const struct rte_flow_item_flex_handle *handle, 1379 struct rte_flow_error *error) 1380 { 1381 int ret; 1382 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1383 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1384 1385 if (unlikely(!ops || !ops->flex_item_release)) 1386 return rte_flow_error_set(error, ENOTSUP, 1387 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1388 NULL, rte_strerror(ENOTSUP)); 1389 ret = ops->flex_item_release(dev, handle, error); 1390 return flow_err(port_id, ret, error); 1391 } 1392 1393 int 1394 rte_flow_info_get(uint16_t port_id, 1395 struct rte_flow_port_info *port_info, 1396 struct rte_flow_queue_info *queue_info, 1397 struct rte_flow_error *error) 1398 { 1399 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1400 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1401 1402 if (unlikely(!ops)) 1403 return -rte_errno; 1404 if (dev->data->dev_configured == 0) { 1405 RTE_FLOW_LOG(INFO, 1406 "Device with port_id=%"PRIu16" is not configured.\n", 1407 port_id); 1408 return -EINVAL; 1409 } 1410 if (port_info == NULL) { 1411 RTE_FLOW_LOG(ERR, "Port %"PRIu16" info is NULL.\n", port_id); 1412 return -EINVAL; 1413 } 1414 if (likely(!!ops->info_get)) { 1415 return flow_err(port_id, 1416 ops->info_get(dev, port_info, queue_info, error), 1417 error); 1418 } 1419 return rte_flow_error_set(error, ENOTSUP, 1420 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1421 NULL, rte_strerror(ENOTSUP)); 1422 } 1423 1424 int 1425 rte_flow_configure(uint16_t port_id, 1426 const struct rte_flow_port_attr *port_attr, 1427 uint16_t nb_queue, 1428 const struct rte_flow_queue_attr *queue_attr[], 1429 struct rte_flow_error *error) 1430 { 1431 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1432 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1433 int ret; 1434 1435 if (unlikely(!ops)) 1436 return -rte_errno; 1437 if (dev->data->dev_configured == 0) { 1438 RTE_FLOW_LOG(INFO, 1439 "Device with port_id=%"PRIu16" is not configured.\n", 1440 port_id); 1441 return -EINVAL; 1442 } 1443 if (dev->data->dev_started != 0) { 1444 RTE_FLOW_LOG(INFO, 1445 "Device with port_id=%"PRIu16" already started.\n", 1446 port_id); 1447 return -EINVAL; 1448 } 1449 if (port_attr == NULL) { 1450 RTE_FLOW_LOG(ERR, "Port %"PRIu16" info is NULL.\n", port_id); 1451 return -EINVAL; 1452 } 1453 if (queue_attr == NULL) { 1454 RTE_FLOW_LOG(ERR, "Port %"PRIu16" queue info is NULL.\n", port_id); 1455 return -EINVAL; 1456 } 1457 if (likely(!!ops->configure)) { 1458 ret = ops->configure(dev, port_attr, nb_queue, queue_attr, error); 1459 if (ret == 0) 1460 dev->data->flow_configured = 1; 1461 return flow_err(port_id, ret, error); 1462 } 1463 return rte_flow_error_set(error, ENOTSUP, 1464 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1465 NULL, rte_strerror(ENOTSUP)); 1466 } 1467 1468 struct rte_flow_pattern_template * 1469 rte_flow_pattern_template_create(uint16_t port_id, 1470 const struct rte_flow_pattern_template_attr *template_attr, 1471 const struct rte_flow_item pattern[], 1472 struct rte_flow_error *error) 1473 { 1474 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1475 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1476 struct rte_flow_pattern_template *template; 1477 1478 if (unlikely(!ops)) 1479 return NULL; 1480 if (dev->data->flow_configured == 0) { 1481 RTE_FLOW_LOG(INFO, 1482 "Flow engine on port_id=%"PRIu16" is not configured.\n", 1483 port_id); 1484 rte_flow_error_set(error, EINVAL, 1485 RTE_FLOW_ERROR_TYPE_STATE, 1486 NULL, rte_strerror(EINVAL)); 1487 return NULL; 1488 } 1489 if (template_attr == NULL) { 1490 RTE_FLOW_LOG(ERR, 1491 "Port %"PRIu16" template attr is NULL.\n", 1492 port_id); 1493 rte_flow_error_set(error, EINVAL, 1494 RTE_FLOW_ERROR_TYPE_ATTR, 1495 NULL, rte_strerror(EINVAL)); 1496 return NULL; 1497 } 1498 if (pattern == NULL) { 1499 RTE_FLOW_LOG(ERR, 1500 "Port %"PRIu16" pattern is NULL.\n", 1501 port_id); 1502 rte_flow_error_set(error, EINVAL, 1503 RTE_FLOW_ERROR_TYPE_ATTR, 1504 NULL, rte_strerror(EINVAL)); 1505 return NULL; 1506 } 1507 if (likely(!!ops->pattern_template_create)) { 1508 template = ops->pattern_template_create(dev, template_attr, 1509 pattern, error); 1510 if (template == NULL) 1511 flow_err(port_id, -rte_errno, error); 1512 return template; 1513 } 1514 rte_flow_error_set(error, ENOTSUP, 1515 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1516 NULL, rte_strerror(ENOTSUP)); 1517 return NULL; 1518 } 1519 1520 int 1521 rte_flow_pattern_template_destroy(uint16_t port_id, 1522 struct rte_flow_pattern_template *pattern_template, 1523 struct rte_flow_error *error) 1524 { 1525 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1526 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1527 1528 if (unlikely(!ops)) 1529 return -rte_errno; 1530 if (unlikely(pattern_template == NULL)) 1531 return 0; 1532 if (likely(!!ops->pattern_template_destroy)) { 1533 return flow_err(port_id, 1534 ops->pattern_template_destroy(dev, 1535 pattern_template, 1536 error), 1537 error); 1538 } 1539 return rte_flow_error_set(error, ENOTSUP, 1540 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1541 NULL, rte_strerror(ENOTSUP)); 1542 } 1543 1544 struct rte_flow_actions_template * 1545 rte_flow_actions_template_create(uint16_t port_id, 1546 const struct rte_flow_actions_template_attr *template_attr, 1547 const struct rte_flow_action actions[], 1548 const struct rte_flow_action masks[], 1549 struct rte_flow_error *error) 1550 { 1551 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1552 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1553 struct rte_flow_actions_template *template; 1554 1555 if (unlikely(!ops)) 1556 return NULL; 1557 if (dev->data->flow_configured == 0) { 1558 RTE_FLOW_LOG(INFO, 1559 "Flow engine on port_id=%"PRIu16" is not configured.\n", 1560 port_id); 1561 rte_flow_error_set(error, EINVAL, 1562 RTE_FLOW_ERROR_TYPE_STATE, 1563 NULL, rte_strerror(EINVAL)); 1564 return NULL; 1565 } 1566 if (template_attr == NULL) { 1567 RTE_FLOW_LOG(ERR, 1568 "Port %"PRIu16" template attr is NULL.\n", 1569 port_id); 1570 rte_flow_error_set(error, EINVAL, 1571 RTE_FLOW_ERROR_TYPE_ATTR, 1572 NULL, rte_strerror(EINVAL)); 1573 return NULL; 1574 } 1575 if (actions == NULL) { 1576 RTE_FLOW_LOG(ERR, 1577 "Port %"PRIu16" actions is NULL.\n", 1578 port_id); 1579 rte_flow_error_set(error, EINVAL, 1580 RTE_FLOW_ERROR_TYPE_ATTR, 1581 NULL, rte_strerror(EINVAL)); 1582 return NULL; 1583 } 1584 if (masks == NULL) { 1585 RTE_FLOW_LOG(ERR, 1586 "Port %"PRIu16" masks is NULL.\n", 1587 port_id); 1588 rte_flow_error_set(error, EINVAL, 1589 RTE_FLOW_ERROR_TYPE_ATTR, 1590 NULL, rte_strerror(EINVAL)); 1591 1592 } 1593 if (likely(!!ops->actions_template_create)) { 1594 template = ops->actions_template_create(dev, template_attr, 1595 actions, masks, error); 1596 if (template == NULL) 1597 flow_err(port_id, -rte_errno, error); 1598 return template; 1599 } 1600 rte_flow_error_set(error, ENOTSUP, 1601 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1602 NULL, rte_strerror(ENOTSUP)); 1603 return NULL; 1604 } 1605 1606 int 1607 rte_flow_actions_template_destroy(uint16_t port_id, 1608 struct rte_flow_actions_template *actions_template, 1609 struct rte_flow_error *error) 1610 { 1611 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1612 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1613 1614 if (unlikely(!ops)) 1615 return -rte_errno; 1616 if (unlikely(actions_template == NULL)) 1617 return 0; 1618 if (likely(!!ops->actions_template_destroy)) { 1619 return flow_err(port_id, 1620 ops->actions_template_destroy(dev, 1621 actions_template, 1622 error), 1623 error); 1624 } 1625 return rte_flow_error_set(error, ENOTSUP, 1626 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1627 NULL, rte_strerror(ENOTSUP)); 1628 } 1629 1630 struct rte_flow_template_table * 1631 rte_flow_template_table_create(uint16_t port_id, 1632 const struct rte_flow_template_table_attr *table_attr, 1633 struct rte_flow_pattern_template *pattern_templates[], 1634 uint8_t nb_pattern_templates, 1635 struct rte_flow_actions_template *actions_templates[], 1636 uint8_t nb_actions_templates, 1637 struct rte_flow_error *error) 1638 { 1639 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1640 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1641 struct rte_flow_template_table *table; 1642 1643 if (unlikely(!ops)) 1644 return NULL; 1645 if (dev->data->flow_configured == 0) { 1646 RTE_FLOW_LOG(INFO, 1647 "Flow engine on port_id=%"PRIu16" is not configured.\n", 1648 port_id); 1649 rte_flow_error_set(error, EINVAL, 1650 RTE_FLOW_ERROR_TYPE_STATE, 1651 NULL, rte_strerror(EINVAL)); 1652 return NULL; 1653 } 1654 if (table_attr == NULL) { 1655 RTE_FLOW_LOG(ERR, 1656 "Port %"PRIu16" table attr is NULL.\n", 1657 port_id); 1658 rte_flow_error_set(error, EINVAL, 1659 RTE_FLOW_ERROR_TYPE_ATTR, 1660 NULL, rte_strerror(EINVAL)); 1661 return NULL; 1662 } 1663 if (pattern_templates == NULL) { 1664 RTE_FLOW_LOG(ERR, 1665 "Port %"PRIu16" pattern templates is NULL.\n", 1666 port_id); 1667 rte_flow_error_set(error, EINVAL, 1668 RTE_FLOW_ERROR_TYPE_ATTR, 1669 NULL, rte_strerror(EINVAL)); 1670 return NULL; 1671 } 1672 if (actions_templates == NULL) { 1673 RTE_FLOW_LOG(ERR, 1674 "Port %"PRIu16" actions templates is NULL.\n", 1675 port_id); 1676 rte_flow_error_set(error, EINVAL, 1677 RTE_FLOW_ERROR_TYPE_ATTR, 1678 NULL, rte_strerror(EINVAL)); 1679 return NULL; 1680 } 1681 if (likely(!!ops->template_table_create)) { 1682 table = ops->template_table_create(dev, table_attr, 1683 pattern_templates, nb_pattern_templates, 1684 actions_templates, nb_actions_templates, 1685 error); 1686 if (table == NULL) 1687 flow_err(port_id, -rte_errno, error); 1688 return table; 1689 } 1690 rte_flow_error_set(error, ENOTSUP, 1691 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1692 NULL, rte_strerror(ENOTSUP)); 1693 return NULL; 1694 } 1695 1696 int 1697 rte_flow_template_table_destroy(uint16_t port_id, 1698 struct rte_flow_template_table *template_table, 1699 struct rte_flow_error *error) 1700 { 1701 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1702 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1703 1704 if (unlikely(!ops)) 1705 return -rte_errno; 1706 if (unlikely(template_table == NULL)) 1707 return 0; 1708 if (likely(!!ops->template_table_destroy)) { 1709 return flow_err(port_id, 1710 ops->template_table_destroy(dev, 1711 template_table, 1712 error), 1713 error); 1714 } 1715 return rte_flow_error_set(error, ENOTSUP, 1716 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1717 NULL, rte_strerror(ENOTSUP)); 1718 } 1719 1720 struct rte_flow * 1721 rte_flow_async_create(uint16_t port_id, 1722 uint32_t queue_id, 1723 const struct rte_flow_op_attr *op_attr, 1724 struct rte_flow_template_table *template_table, 1725 const struct rte_flow_item pattern[], 1726 uint8_t pattern_template_index, 1727 const struct rte_flow_action actions[], 1728 uint8_t actions_template_index, 1729 void *user_data, 1730 struct rte_flow_error *error) 1731 { 1732 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1733 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1734 struct rte_flow *flow; 1735 1736 flow = ops->async_create(dev, queue_id, 1737 op_attr, template_table, 1738 pattern, pattern_template_index, 1739 actions, actions_template_index, 1740 user_data, error); 1741 if (flow == NULL) 1742 flow_err(port_id, -rte_errno, error); 1743 return flow; 1744 } 1745 1746 int 1747 rte_flow_async_destroy(uint16_t port_id, 1748 uint32_t queue_id, 1749 const struct rte_flow_op_attr *op_attr, 1750 struct rte_flow *flow, 1751 void *user_data, 1752 struct rte_flow_error *error) 1753 { 1754 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1755 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1756 1757 return flow_err(port_id, 1758 ops->async_destroy(dev, queue_id, 1759 op_attr, flow, 1760 user_data, error), 1761 error); 1762 } 1763 1764 int 1765 rte_flow_push(uint16_t port_id, 1766 uint32_t queue_id, 1767 struct rte_flow_error *error) 1768 { 1769 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1770 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1771 1772 return flow_err(port_id, 1773 ops->push(dev, queue_id, error), 1774 error); 1775 } 1776 1777 int 1778 rte_flow_pull(uint16_t port_id, 1779 uint32_t queue_id, 1780 struct rte_flow_op_result res[], 1781 uint16_t n_res, 1782 struct rte_flow_error *error) 1783 { 1784 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1785 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1786 int ret; 1787 1788 ret = ops->pull(dev, queue_id, res, n_res, error); 1789 return ret ? ret : flow_err(port_id, ret, error); 1790 } 1791 1792 struct rte_flow_action_handle * 1793 rte_flow_async_action_handle_create(uint16_t port_id, 1794 uint32_t queue_id, 1795 const struct rte_flow_op_attr *op_attr, 1796 const struct rte_flow_indir_action_conf *indir_action_conf, 1797 const struct rte_flow_action *action, 1798 void *user_data, 1799 struct rte_flow_error *error) 1800 { 1801 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1802 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1803 struct rte_flow_action_handle *handle; 1804 1805 handle = ops->async_action_handle_create(dev, queue_id, op_attr, 1806 indir_action_conf, action, user_data, error); 1807 if (handle == NULL) 1808 flow_err(port_id, -rte_errno, error); 1809 return handle; 1810 } 1811 1812 int 1813 rte_flow_async_action_handle_destroy(uint16_t port_id, 1814 uint32_t queue_id, 1815 const struct rte_flow_op_attr *op_attr, 1816 struct rte_flow_action_handle *action_handle, 1817 void *user_data, 1818 struct rte_flow_error *error) 1819 { 1820 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1821 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1822 int ret; 1823 1824 ret = ops->async_action_handle_destroy(dev, queue_id, op_attr, 1825 action_handle, user_data, error); 1826 return flow_err(port_id, ret, error); 1827 } 1828 1829 int 1830 rte_flow_async_action_handle_update(uint16_t port_id, 1831 uint32_t queue_id, 1832 const struct rte_flow_op_attr *op_attr, 1833 struct rte_flow_action_handle *action_handle, 1834 const void *update, 1835 void *user_data, 1836 struct rte_flow_error *error) 1837 { 1838 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1839 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1840 int ret; 1841 1842 ret = ops->async_action_handle_update(dev, queue_id, op_attr, 1843 action_handle, update, user_data, error); 1844 return flow_err(port_id, ret, error); 1845 } 1846 1847 int 1848 rte_flow_async_action_handle_query(uint16_t port_id, 1849 uint32_t queue_id, 1850 const struct rte_flow_op_attr *op_attr, 1851 const struct rte_flow_action_handle *action_handle, 1852 void *data, 1853 void *user_data, 1854 struct rte_flow_error *error) 1855 { 1856 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1857 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1858 int ret; 1859 1860 ret = ops->async_action_handle_query(dev, queue_id, op_attr, 1861 action_handle, data, user_data, error); 1862 return flow_err(port_id, ret, error); 1863 } 1864