pipeline: add table action for packet tag
[dpdk.git] / lib / librte_pipeline / rte_table_action.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef __INCLUDE_RTE_TABLE_ACTION_H__
6 #define __INCLUDE_RTE_TABLE_ACTION_H__
7
8 /**
9  * @file
10  * RTE Pipeline Table Actions
11  *
12  * This API provides a common set of actions for pipeline tables to speed up
13  * application development.
14  *
15  * Each match-action rule added to a pipeline table has associated data that
16  * stores the action context. This data is input to the table action handler
17  * called for every input packet that hits the rule as part of the table lookup
18  * during the pipeline execution. The pipeline library allows the user to define
19  * his own table actions by providing customized table action handlers (table
20  * lookup) and complete freedom of setting the rules and their data (table rule
21  * add/delete). While the user can still follow this process, this API is
22  * intended to provide a quicker development alternative for a set of predefined
23  * actions.
24  *
25  * The typical steps to use this API are:
26  *  - Define a table action profile. This is a configuration template that can
27  *    potentially be shared by multiple tables from the same or different
28  *    pipelines, with different tables from the same pipeline likely to use
29  *    different action profiles. For every table using a given action profile,
30  *    the profile defines the set of actions and the action configuration to be
31  *    implemented for all the table rules. API functions:
32  *    rte_table_action_profile_create(),
33  *    rte_table_action_profile_action_register(),
34  *    rte_table_action_profile_freeze().
35  *
36  *  - Instantiate the table action profile to create table action objects. Each
37  *    pipeline table has its own table action object. API functions:
38  *    rte_table_action_create().
39  *
40  *  - Use the table action object to generate the pipeline table action handlers
41  *    (invoked by the pipeline table lookup operation). API functions:
42  *    rte_table_action_table_params_get().
43  *
44  *  - Use the table action object to generate the rule data (for the pipeline
45  *    table rule add operation) based on given action parameters. API functions:
46  *    rte_table_action_apply().
47  *
48  *  - Use the table action object to read action data (e.g. stats counters) for
49  *    any given rule. API functions: rte_table_action_XYZ_read().
50  *
51  * @warning
52  * @b EXPERIMENTAL: this API may change without prior notice
53  */
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 #include <stdint.h>
60
61 #include <rte_compat.h>
62 #include <rte_ether.h>
63 #include <rte_meter.h>
64 #include <rte_table_hash.h>
65
66 #include "rte_pipeline.h"
67
68 /** Table actions. */
69 enum rte_table_action_type {
70         /** Forward to next pipeline table, output port or drop. */
71         RTE_TABLE_ACTION_FWD = 0,
72
73         /**  Load balance. */
74         RTE_TABLE_ACTION_LB,
75
76         /**  Traffic Metering and Policing. */
77         RTE_TABLE_ACTION_MTR,
78
79         /**  Traffic Management. */
80         RTE_TABLE_ACTION_TM,
81
82         /** Packet encapsulations. */
83         RTE_TABLE_ACTION_ENCAP,
84
85         /** Network Address Translation (NAT). */
86         RTE_TABLE_ACTION_NAT,
87
88         /** Time to Live (TTL) update. */
89         RTE_TABLE_ACTION_TTL,
90
91         /** Statistics. */
92         RTE_TABLE_ACTION_STATS,
93
94         /** Timestamp. */
95         RTE_TABLE_ACTION_TIME,
96
97         /** Crypto. */
98         RTE_TABLE_ACTION_SYM_CRYPTO,
99
100         /** Tag. */
101         RTE_TABLE_ACTION_TAG,
102 };
103
104 /** Common action configuration (per table action profile). */
105 struct rte_table_action_common_config {
106         /** Input packet Internet Protocol (IP) version. Non-zero for IPv4, zero
107          * for IPv6.
108          */
109         int ip_version;
110
111         /** IP header offset within the input packet buffer. Offset 0 points to
112          * the first byte of the MBUF structure.
113          */
114         uint32_t ip_offset;
115 };
116
117 /**
118  * RTE_TABLE_ACTION_FWD
119  */
120 /** Forward action parameters (per table rule). */
121 struct rte_table_action_fwd_params {
122         /** Forward action. */
123         enum rte_pipeline_action action;
124
125         /** Pipeline table ID or output port ID. */
126         uint32_t id;
127 };
128
129 /**
130  * RTE_TABLE_ACTION_LB
131  */
132 /** Load balance key size min (number of bytes). */
133 #define RTE_TABLE_ACTION_LB_KEY_SIZE_MIN                    8
134
135 /** Load balance key size max (number of bytes). */
136 #define RTE_TABLE_ACTION_LB_KEY_SIZE_MAX                    64
137
138 /** Load balance table size. */
139 #define RTE_TABLE_ACTION_LB_TABLE_SIZE                      8
140
141 /** Load balance action configuration (per table action profile). */
142 struct rte_table_action_lb_config {
143         /** Key size (number of bytes). */
144         uint32_t key_size;
145
146         /** Key offset within the input packet buffer. Offset 0 points to the
147          * first byte of the MBUF structure.
148          */
149         uint32_t key_offset;
150
151         /** Key mask (*key_size* bytes are valid). */
152         uint8_t key_mask[RTE_TABLE_ACTION_LB_KEY_SIZE_MAX];
153
154         /** Hash function. */
155         rte_table_hash_op_hash f_hash;
156
157         /** Seed value for *f_hash*. */
158         uint64_t seed;
159
160         /** Output value offset within the input packet buffer. Offset 0 points
161          * to the first byte of the MBUF structure.
162          */
163         uint32_t out_offset;
164 };
165
166 /** Load balance action parameters (per table rule). */
167 struct rte_table_action_lb_params {
168         /** Table defining the output values and their weights. The weights are
169          * set in 1/RTE_TABLE_ACTION_LB_TABLE_SIZE increments. To assign a
170          * weight of N/RTE_TABLE_ACTION_LB_TABLE_SIZE to a given output value
171          * (0 <= N <= RTE_TABLE_ACTION_LB_TABLE_SIZE), the same output value
172          * needs to show up exactly N times in this table.
173          */
174         uint32_t out[RTE_TABLE_ACTION_LB_TABLE_SIZE];
175 };
176
177 /**
178  * RTE_TABLE_ACTION_MTR
179  */
180 /** Max number of traffic classes (TCs). */
181 #define RTE_TABLE_ACTION_TC_MAX                                  4
182
183 /** Max number of queues per traffic class. */
184 #define RTE_TABLE_ACTION_TC_QUEUE_MAX                            4
185
186 /** Differentiated Services Code Point (DSCP) translation table entry. */
187 struct rte_table_action_dscp_table_entry {
188         /** Traffic class. Used by the meter or the traffic management actions.
189          * Has to be strictly smaller than *RTE_TABLE_ACTION_TC_MAX*. Traffic
190          * class 0 is the highest priority.
191          */
192         uint32_t tc_id;
193
194         /** Traffic class queue. Used by the traffic management action. Has to
195          * be strictly smaller than *RTE_TABLE_ACTION_TC_QUEUE_MAX*.
196          */
197         uint32_t tc_queue_id;
198
199         /** Packet color. Used by the meter action as the packet input color
200          * for the color aware mode of the traffic metering algorithm.
201          */
202         enum rte_meter_color color;
203 };
204
205 /** DSCP translation table. */
206 struct rte_table_action_dscp_table {
207         /** Array of DSCP table entries */
208         struct rte_table_action_dscp_table_entry entry[64];
209 };
210
211 /** Supported traffic metering algorithms. */
212 enum rte_table_action_meter_algorithm {
213         /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
214         RTE_TABLE_ACTION_METER_SRTCM,
215
216         /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
217         RTE_TABLE_ACTION_METER_TRTCM,
218 };
219
220 /** Traffic metering profile (configuration template). */
221 struct rte_table_action_meter_profile {
222         /** Traffic metering algorithm. */
223         enum rte_table_action_meter_algorithm alg;
224
225         RTE_STD_C11
226         union {
227                 /** Only valid when *alg* is set to srTCM - IETF RFC 2697. */
228                 struct rte_meter_srtcm_params srtcm;
229
230                 /** Only valid when *alg* is set to trTCM - IETF RFC 2698. */
231                 struct rte_meter_trtcm_params trtcm;
232         };
233 };
234
235 /** Policer actions. */
236 enum rte_table_action_policer {
237         /** Recolor the packet as green. */
238         RTE_TABLE_ACTION_POLICER_COLOR_GREEN = 0,
239
240         /** Recolor the packet as yellow. */
241         RTE_TABLE_ACTION_POLICER_COLOR_YELLOW,
242
243         /** Recolor the packet as red. */
244         RTE_TABLE_ACTION_POLICER_COLOR_RED,
245
246         /** Drop the packet. */
247         RTE_TABLE_ACTION_POLICER_DROP,
248
249         /** Number of policer actions. */
250         RTE_TABLE_ACTION_POLICER_MAX
251 };
252
253 /** Meter action configuration per traffic class. */
254 struct rte_table_action_mtr_tc_params {
255         /** Meter profile ID. */
256         uint32_t meter_profile_id;
257
258         /** Policer actions. */
259         enum rte_table_action_policer policer[e_RTE_METER_COLORS];
260 };
261
262 /** Meter action statistics counters per traffic class. */
263 struct rte_table_action_mtr_counters_tc {
264         /** Number of packets per color at the output of the traffic metering
265          * and before the policer actions are executed. Only valid when
266          * *n_packets_valid* is non-zero.
267          */
268         uint64_t n_packets[e_RTE_METER_COLORS];
269
270         /** Number of packet bytes per color at the output of the traffic
271          * metering and before the policer actions are executed. Only valid when
272          * *n_bytes_valid* is non-zero.
273          */
274         uint64_t n_bytes[e_RTE_METER_COLORS];
275
276         /** When non-zero, the *n_packets* field is valid. */
277         int n_packets_valid;
278
279         /** When non-zero, the *n_bytes* field is valid. */
280         int n_bytes_valid;
281 };
282
283 /** Meter action configuration (per table action profile). */
284 struct rte_table_action_mtr_config {
285         /** Meter algorithm. */
286         enum rte_table_action_meter_algorithm alg;
287
288         /** Number of traffic classes. Each traffic class has its own traffic
289          * meter and policer instances. Needs to be equal to either 1 or to
290          * *RTE_TABLE_ACTION_TC_MAX*.
291          */
292         uint32_t n_tc;
293
294         /** When non-zero, the *n_packets* meter stats counter is enabled,
295          * otherwise it is disabled.
296          *
297          * @see struct rte_table_action_mtr_counters_tc
298          */
299         int n_packets_enabled;
300
301         /** When non-zero, the *n_bytes* meter stats counter is enabled,
302          * otherwise it is disabled.
303          *
304          * @see struct rte_table_action_mtr_counters_tc
305          */
306         int n_bytes_enabled;
307 };
308
309 /** Meter action parameters (per table rule). */
310 struct rte_table_action_mtr_params {
311         /** Traffic meter and policer parameters for each of the *tc_mask*
312          * traffic classes.
313          */
314         struct rte_table_action_mtr_tc_params mtr[RTE_TABLE_ACTION_TC_MAX];
315
316         /** Bit mask defining which traffic class parameters are valid in *mtr*.
317          * If bit N is set in *tc_mask*, then parameters for traffic class N are
318          * valid in *mtr*.
319          */
320         uint32_t tc_mask;
321 };
322
323 /** Meter action statistics counters (per table rule). */
324 struct rte_table_action_mtr_counters {
325         /** Stats counters for each of the *tc_mask* traffic classes. */
326         struct rte_table_action_mtr_counters_tc stats[RTE_TABLE_ACTION_TC_MAX];
327
328         /** Bit mask defining which traffic class parameters are valid in *mtr*.
329          * If bit N is set in *tc_mask*, then parameters for traffic class N are
330          * valid in *mtr*.
331          */
332         uint32_t tc_mask;
333 };
334
335 /**
336  * RTE_TABLE_ACTION_TM
337  */
338 /** Traffic management action configuration (per table action profile). */
339 struct rte_table_action_tm_config {
340         /** Number of subports per port. */
341         uint32_t n_subports_per_port;
342
343         /** Number of pipes per subport. */
344         uint32_t n_pipes_per_subport;
345 };
346
347 /** Traffic management action parameters (per table rule). */
348 struct rte_table_action_tm_params {
349         /** Subport ID. */
350         uint32_t subport_id;
351
352         /** Pipe ID. */
353         uint32_t pipe_id;
354 };
355
356 /**
357  * RTE_TABLE_ACTION_ENCAP
358  */
359 /** Supported packet encapsulation types. */
360 enum rte_table_action_encap_type {
361         /** IP -> { Ether | IP } */
362         RTE_TABLE_ACTION_ENCAP_ETHER = 0,
363
364         /** IP -> { Ether | VLAN | IP } */
365         RTE_TABLE_ACTION_ENCAP_VLAN,
366
367         /** IP -> { Ether | S-VLAN | C-VLAN | IP } */
368         RTE_TABLE_ACTION_ENCAP_QINQ,
369
370         /** IP -> { Ether | MPLS | IP } */
371         RTE_TABLE_ACTION_ENCAP_MPLS,
372
373         /** IP -> { Ether | PPPoE | PPP | IP } */
374         RTE_TABLE_ACTION_ENCAP_PPPOE,
375
376         /** Ether -> { Ether | IP | UDP | VXLAN | Ether }
377          * Ether -> { Ether | VLAN | IP | UDP | VXLAN | Ether }
378          */
379         RTE_TABLE_ACTION_ENCAP_VXLAN,
380 };
381
382 /** Pre-computed Ethernet header fields for encapsulation action. */
383 struct rte_table_action_ether_hdr {
384         struct ether_addr da; /**< Destination address. */
385         struct ether_addr sa; /**< Source address. */
386 };
387
388 /** Pre-computed VLAN header fields for encapsulation action. */
389 struct rte_table_action_vlan_hdr {
390         uint8_t pcp; /**< Priority Code Point (PCP). */
391         uint8_t dei; /**< Drop Eligibility Indicator (DEI). */
392         uint16_t vid; /**< VLAN Identifier (VID). */
393 };
394
395 /** Pre-computed MPLS header fields for encapsulation action. */
396 struct rte_table_action_mpls_hdr {
397         uint32_t label; /**< Label. */
398         uint8_t tc; /**< Traffic Class (TC). */
399         uint8_t ttl; /**< Time to Live (TTL). */
400 };
401
402 /** Pre-computed PPPoE header fields for encapsulation action. */
403 struct rte_table_action_pppoe_hdr {
404         uint16_t session_id; /**< Session ID. */
405 };
406
407 /** Pre-computed IPv4 header fields for encapsulation action. */
408 struct rte_table_action_ipv4_header {
409         uint32_t sa; /**< Source address. */
410         uint32_t da; /**< Destination address. */
411         uint8_t dscp; /**< DiffServ Code Point (DSCP). */
412         uint8_t ttl; /**< Time To Live (TTL). */
413 };
414
415 /** Pre-computed IPv6 header fields for encapsulation action. */
416 struct rte_table_action_ipv6_header {
417         uint8_t sa[16]; /**< Source address. */
418         uint8_t da[16]; /**< Destination address. */
419         uint32_t flow_label; /**< Flow label. */
420         uint8_t dscp; /**< DiffServ Code Point (DSCP). */
421         uint8_t hop_limit; /**< Hop Limit (HL). */
422 };
423
424 /** Pre-computed UDP header fields for encapsulation action. */
425 struct rte_table_action_udp_header {
426         uint16_t sp; /**< Source port. */
427         uint16_t dp; /**< Destination port. */
428 };
429
430 /** Pre-computed VXLAN header fields for encapsulation action. */
431 struct rte_table_action_vxlan_hdr {
432         uint32_t vni; /**< VXLAN Network Identifier (VNI). */
433 };
434
435 /** Ether encap parameters. */
436 struct rte_table_action_encap_ether_params {
437         struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
438 };
439
440 /** VLAN encap parameters. */
441 struct rte_table_action_encap_vlan_params {
442         struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
443         struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
444 };
445
446 /** QinQ encap parameters. */
447 struct rte_table_action_encap_qinq_params {
448         struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
449         struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
450         struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
451 };
452
453 /** Max number of MPLS labels per output packet for MPLS encapsulation. */
454 #ifndef RTE_TABLE_ACTION_MPLS_LABELS_MAX
455 #define RTE_TABLE_ACTION_MPLS_LABELS_MAX                   4
456 #endif
457
458 /** MPLS encap parameters. */
459 struct rte_table_action_encap_mpls_params {
460         /** Ethernet header. */
461         struct rte_table_action_ether_hdr ether;
462
463         /** MPLS header. */
464         struct rte_table_action_mpls_hdr mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
465
466         /** Number of MPLS labels in MPLS header. */
467         uint32_t mpls_count;
468
469         /** Non-zero for MPLS unicast, zero for MPLS multicast. */
470         int unicast;
471 };
472
473 /** PPPoE encap parameters. */
474 struct rte_table_action_encap_pppoe_params {
475         struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
476         struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
477 };
478
479 /** VXLAN encap parameters. */
480 struct rte_table_action_encap_vxlan_params {
481         struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
482         struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
483
484         RTE_STD_C11
485         union {
486                 struct rte_table_action_ipv4_header ipv4; /**< IPv4 header. */
487                 struct rte_table_action_ipv6_header ipv6; /**< IPv6 header. */
488         };
489
490         struct rte_table_action_udp_header udp; /**< UDP header. */
491         struct rte_table_action_vxlan_hdr vxlan; /**< VXLAN header. */
492 };
493
494 /** Encap action configuration (per table action profile). */
495 struct rte_table_action_encap_config {
496         /** Bit mask defining the set of packet encapsulations enabled for the
497          * current table action profile. If bit (1 << N) is set in *encap_mask*,
498          * then packet encapsulation N is enabled, otherwise it is disabled.
499          *
500          * @see enum rte_table_action_encap_type
501          */
502         uint64_t encap_mask;
503
504         /** Encapsulation type specific configuration. */
505         RTE_STD_C11
506         union {
507                 struct {
508                         /** Input packet to be encapsulated: offset within the
509                          * input packet buffer to the start of the Ethernet
510                          * frame to be encapsulated. Offset 0 points to the
511                          * first byte of the MBUF structure.
512                          */
513                         uint32_t data_offset;
514
515                         /** Encapsulation header: non-zero when encapsulation
516                          * header includes a VLAN tag, zero otherwise.
517                          */
518                         int vlan;
519
520                         /** Encapsulation header: IP version of the IP header
521                          * within the encapsulation header. Non-zero for IPv4,
522                          * zero for IPv6.
523                          */
524                         int ip_version;
525                 } vxlan; /**< VXLAN specific configuration. */
526         };
527 };
528
529 /** Encap action parameters (per table rule). */
530 struct rte_table_action_encap_params {
531         /** Encapsulation type. */
532         enum rte_table_action_encap_type type;
533
534         RTE_STD_C11
535         union {
536                 /** Only valid when *type* is set to Ether. */
537                 struct rte_table_action_encap_ether_params ether;
538
539                 /** Only valid when *type* is set to VLAN. */
540                 struct rte_table_action_encap_vlan_params vlan;
541
542                 /** Only valid when *type* is set to QinQ. */
543                 struct rte_table_action_encap_qinq_params qinq;
544
545                 /** Only valid when *type* is set to MPLS. */
546                 struct rte_table_action_encap_mpls_params mpls;
547
548                 /** Only valid when *type* is set to PPPoE. */
549                 struct rte_table_action_encap_pppoe_params pppoe;
550
551                 /** Only valid when *type* is set to VXLAN. */
552                 struct rte_table_action_encap_vxlan_params vxlan;
553         };
554 };
555
556 /**
557  * RTE_TABLE_ACTION_NAT
558  */
559 /** NAT action configuration (per table action profile). */
560 struct rte_table_action_nat_config {
561         /** When non-zero, the IP source address and L4 protocol source port are
562          * translated. When zero, the IP destination address and L4 protocol
563          * destination port are translated.
564          */
565         int source_nat;
566
567         /** Layer 4 protocol, for example TCP (0x06) or UDP (0x11). The checksum
568          * field is computed differently and placed at different header offset
569          * by each layer 4 protocol.
570          */
571         uint8_t proto;
572 };
573
574 /** NAT action parameters (per table rule). */
575 struct rte_table_action_nat_params {
576         /** IP version for *addr*: non-zero for IPv4, zero for IPv6. */
577         int ip_version;
578
579         /** IP address. */
580         union {
581                 /** IPv4 address; only valid when *ip_version* is non-zero. */
582                 uint32_t ipv4;
583
584                 /** IPv6 address; only valid when *ip_version* is set to 0. */
585                 uint8_t ipv6[16];
586         } addr;
587
588         /** Port. */
589         uint16_t port;
590 };
591
592 /**
593  * RTE_TABLE_ACTION_TTL
594  */
595 /** TTL action configuration (per table action profile). */
596 struct rte_table_action_ttl_config {
597         /** When non-zero, the input packets whose updated IPv4 Time to Live
598          * (TTL) field or IPv6 Hop Limit (HL) field is zero are dropped.
599          * When zero, the input packets whose updated IPv4 TTL field or IPv6 HL
600          * field is zero are forwarded as usual (typically for debugging
601          * purpose).
602          */
603         int drop;
604
605         /** When non-zero, the *n_packets* stats counter for TTL action is
606          * enabled, otherwise disabled.
607          *
608          * @see struct rte_table_action_ttl_counters
609          */
610         int n_packets_enabled;
611 };
612
613 /** TTL action parameters (per table rule). */
614 struct rte_table_action_ttl_params {
615         /** When non-zero, decrement the IPv4 TTL field and update the checksum
616          * field, or decrement the IPv6 HL field. When zero, the IPv4 TTL field
617          * or the IPv6 HL field is not changed.
618          */
619         int decrement;
620 };
621
622 /** TTL action statistics packets (per table rule). */
623 struct rte_table_action_ttl_counters {
624         /** Number of IPv4 packets whose updated TTL field is zero or IPv6
625          * packets whose updated HL field is zero.
626          */
627         uint64_t n_packets;
628 };
629
630 /**
631  * RTE_TABLE_ACTION_STATS
632  */
633 /** Stats action configuration (per table action profile). */
634 struct rte_table_action_stats_config {
635         /** When non-zero, the *n_packets* stats counter is enabled, otherwise
636          * disabled.
637          *
638          * @see struct rte_table_action_stats_counters
639          */
640         int n_packets_enabled;
641
642         /** When non-zero, the *n_bytes* stats counter is enabled, otherwise
643          * disabled.
644          *
645          * @see struct rte_table_action_stats_counters
646          */
647         int n_bytes_enabled;
648 };
649
650 /** Stats action parameters (per table rule). */
651 struct rte_table_action_stats_params {
652         /** Initial value for the *n_packets* stats counter. Typically set to 0.
653          *
654          * @see struct rte_table_action_stats_counters
655          */
656         uint64_t n_packets;
657
658         /** Initial value for the *n_bytes* stats counter. Typically set to 0.
659          *
660          * @see struct rte_table_action_stats_counters
661          */
662         uint64_t n_bytes;
663 };
664
665 /** Stats action counters (per table rule). */
666 struct rte_table_action_stats_counters {
667         /** Number of packets. Valid only when *n_packets_valid* is non-zero. */
668         uint64_t n_packets;
669
670         /** Number of bytes. Valid only when *n_bytes_valid* is non-zero. */
671         uint64_t n_bytes;
672
673         /** When non-zero, the *n_packets* field is valid, otherwise invalid. */
674         int n_packets_valid;
675
676         /** When non-zero, the *n_bytes* field is valid, otherwise invalid. */
677         int n_bytes_valid;
678 };
679
680 /**
681  * RTE_TABLE_ACTION_TIME
682  */
683 /** Timestamp action parameters (per table rule). */
684 struct rte_table_action_time_params {
685         /** Initial timestamp value. Typically set to current time. */
686         uint64_t time;
687 };
688
689 /**
690  * RTE_TABLE_ACTION_CRYPTO
691  */
692 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX
693 #define RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX         (16)
694 #endif
695
696 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX
697 #define RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX        (16)
698 #endif
699
700 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET
701 #define RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET                           \
702         (sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op))
703 #endif
704
705 /** Common action structure to store the data's value, length, and offset */
706 struct rte_table_action_vlo {
707         uint8_t *val;
708         uint32_t length;
709         uint32_t offset;
710 };
711
712 /** Symmetric crypto action configuration (per table action profile). */
713 struct rte_table_action_sym_crypto_config {
714         /** Target Cryptodev ID. */
715         uint8_t cryptodev_id;
716
717         /**
718          * Offset to rte_crypto_op structure within the input packet buffer.
719          * Offset 0 points to the first byte of the MBUF structure.
720          */
721         uint32_t op_offset;
722
723         /** The mempool for creating cryptodev sessions. */
724         struct rte_mempool *mp_create;
725
726         /** The mempool for initializing cryptodev sessions. */
727         struct rte_mempool *mp_init;
728 };
729
730 /** Symmetric Crypto action parameters (per table rule). */
731 struct rte_table_action_sym_crypto_params {
732
733         /** Xform pointer contains all relevant information */
734         struct rte_crypto_sym_xform *xform;
735
736         /**
737          * Offset within the input packet buffer to the first byte of data
738          * to be processed by the crypto unit. Offset 0 points to the first
739          * byte of the MBUF structure.
740          */
741         uint32_t data_offset;
742
743         union {
744                 struct {
745                         /** Cipher iv data. */
746                         struct rte_table_action_vlo cipher_iv;
747
748                         /** Cipher iv data. */
749                         struct rte_table_action_vlo cipher_iv_update;
750
751                         /** Auth iv data. */
752                         struct rte_table_action_vlo auth_iv;
753
754                         /** Auth iv data. */
755                         struct rte_table_action_vlo auth_iv_update;
756
757                 } cipher_auth;
758
759                 struct {
760                         /** AEAD AAD data. */
761                         struct rte_table_action_vlo aad;
762
763                         /** AEAD iv data. */
764                         struct rte_table_action_vlo iv;
765
766                         /** AEAD AAD data. */
767                         struct rte_table_action_vlo aad_update;
768
769                         /** AEAD iv data. */
770                         struct rte_table_action_vlo iv_update;
771
772                 } aead;
773         };
774 };
775
776 /**
777  * RTE_TABLE_ACTION_TAG
778  */
779 /** Tag action parameters (per table rule). */
780 struct rte_table_action_tag_params {
781         /** Tag to be attached to the input packet. */
782         uint32_t tag;
783 };
784
785 /**
786  * Table action profile.
787  */
788 struct rte_table_action_profile;
789
790 /**
791  * Table action profile create.
792  *
793  * @param[in] common
794  *   Common action configuration.
795  * @return
796  *   Table action profile handle on success, NULL otherwise.
797  */
798 struct rte_table_action_profile * __rte_experimental
799 rte_table_action_profile_create(struct rte_table_action_common_config *common);
800
801 /**
802  * Table action profile free.
803  *
804  * @param[in] profile
805  *   Table profile action handle (needs to be valid).
806  * @return
807  *   Zero on success, non-zero error code otherwise.
808  */
809 int __rte_experimental
810 rte_table_action_profile_free(struct rte_table_action_profile *profile);
811
812 /**
813  * Table action profile action register.
814  *
815  * @param[in] profile
816  *   Table profile action handle (needs to be valid and not in frozen state).
817  * @param[in] type
818  *   Specific table action to be registered for *profile*.
819  * @param[in] action_config
820  *   Configuration for the *type* action.
821  *   If struct rte_table_action_*type*_config is defined by the Table Action
822  *   API, it needs to point to a valid instance of this structure, otherwise it
823  *   needs to be set to NULL.
824  * @return
825  *   Zero on success, non-zero error code otherwise.
826  */
827 int __rte_experimental
828 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
829         enum rte_table_action_type type,
830         void *action_config);
831
832 /**
833  * Table action profile freeze.
834  *
835  * Once this function is called successfully, the given profile enters the
836  * frozen state with the following immediate effects: no more actions can be
837  * registered for this profile, so the profile can be instantiated to create
838  * table action objects.
839  *
840  * @param[in] profile
841  *   Table profile action handle (needs to be valid and not in frozen state).
842  * @return
843  *   Zero on success, non-zero error code otherwise.
844  *
845  * @see rte_table_action_create()
846  */
847 int __rte_experimental
848 rte_table_action_profile_freeze(struct rte_table_action_profile *profile);
849
850 /**
851  * Table action.
852  */
853 struct rte_table_action;
854
855 /**
856  * Table action create.
857  *
858  * Instantiates the given table action profile to create a table action object.
859  *
860  * @param[in] profile
861  *   Table profile action handle (needs to be valid and in frozen state).
862  * @param[in] socket_id
863  *   CPU socket ID where the internal data structures required by the new table
864  *   action object should be allocated.
865  * @return
866  *   Handle to table action object on success, NULL on error.
867  *
868  * @see rte_table_action_create()
869  */
870 struct rte_table_action * __rte_experimental
871 rte_table_action_create(struct rte_table_action_profile *profile,
872         uint32_t socket_id);
873
874 /**
875  * Table action free.
876  *
877  * @param[in] action
878  *   Handle to table action object (needs to be valid).
879  * @return
880  *   Zero on success, non-zero error code otherwise.
881  */
882 int __rte_experimental
883 rte_table_action_free(struct rte_table_action *action);
884
885 /**
886  * Table action table params get.
887  *
888  * @param[in] action
889  *   Handle to table action object (needs to be valid).
890  * @param[inout] params
891  *   Pipeline table parameters (needs to be pre-allocated).
892  * @return
893  *   Zero on success, non-zero error code otherwise.
894  */
895 int __rte_experimental
896 rte_table_action_table_params_get(struct rte_table_action *action,
897         struct rte_pipeline_table_params *params);
898
899 /**
900  * Table action apply.
901  *
902  * @param[in] action
903  *   Handle to table action object (needs to be valid).
904  * @param[in] data
905  *   Data byte array (typically table rule data) to apply action *type* on.
906  * @param[in] type
907  *   Specific table action previously registered for the table action profile of
908  *   the *action* object.
909  * @param[in] action_params
910  *   Parameters for the *type* action.
911  *   If struct rte_table_action_*type*_params is defined by the Table Action
912  *   API, it needs to point to a valid instance of this structure, otherwise it
913  *   needs to be set to NULL.
914  * @return
915  *   Zero on success, non-zero error code otherwise.
916  */
917 int __rte_experimental
918 rte_table_action_apply(struct rte_table_action *action,
919         void *data,
920         enum rte_table_action_type type,
921         void *action_params);
922
923 /**
924  * Table action DSCP table update.
925  *
926  * @param[in] action
927  *   Handle to table action object (needs to be valid).
928  * @param[in] dscp_mask
929  *   64-bit mask defining the DSCP table entries to be updated. If bit N is set
930  *   in this bit mask, then DSCP table entry N is to be updated, otherwise not.
931  * @param[in] table
932  *   DSCP table.
933  * @return
934  *   Zero on success, non-zero error code otherwise.
935  */
936 int __rte_experimental
937 rte_table_action_dscp_table_update(struct rte_table_action *action,
938         uint64_t dscp_mask,
939         struct rte_table_action_dscp_table *table);
940
941 /**
942  * Table action meter profile add.
943  *
944  * @param[in] action
945  *   Handle to table action object (needs to be valid).
946  * @param[in] meter_profile_id
947  *   Meter profile ID to be used for the *profile* once it is successfully added
948  *   to the *action* object (needs to be unused by the set of meter profiles
949  *   currently registered for the *action* object).
950  * @param[in] profile
951  *   Meter profile to be added.
952  * @return
953  *   Zero on success, non-zero error code otherwise.
954  */
955 int __rte_experimental
956 rte_table_action_meter_profile_add(struct rte_table_action *action,
957         uint32_t meter_profile_id,
958         struct rte_table_action_meter_profile *profile);
959
960 /**
961  * Table action meter profile delete.
962  *
963  * @param[in] action
964  *   Handle to table action object (needs to be valid).
965  * @param[in] meter_profile_id
966  *   Meter profile ID of the meter profile to be deleted from the *action*
967  *   object (needs to be valid for the *action* object).
968  * @return
969  *   Zero on success, non-zero error code otherwise.
970  */
971 int __rte_experimental
972 rte_table_action_meter_profile_delete(struct rte_table_action *action,
973         uint32_t meter_profile_id);
974
975 /**
976  * Table action meter read.
977  *
978  * @param[in] action
979  *   Handle to table action object (needs to be valid).
980  * @param[in] data
981  *   Data byte array (typically table rule data) with meter action previously
982  *   applied on it.
983  * @param[in] tc_mask
984  *   Bit mask defining which traffic classes should have the meter stats
985  *   counters read from *data* and stored into *stats*. If bit N is set in this
986  *   bit mask, then traffic class N is part of this operation, otherwise it is
987  *   not. If bit N is set in this bit mask, then traffic class N must be one of
988  *   the traffic classes that are enabled for the meter action in the table
989  *   action profile used by the *action* object.
990  * @param[inout] stats
991  *   When non-NULL, it points to the area where the meter stats counters read
992  *   from *data* are saved. Only the meter stats counters for the *tc_mask*
993  *   traffic classes are read and stored to *stats*.
994  * @param[in] clear
995  *   When non-zero, the meter stats counters are cleared (i.e. set to zero),
996  *   otherwise the counters are not modified. When the read operation is enabled
997  *   (*stats* is non-NULL), the clear operation is performed after the read
998  *   operation is completed.
999  * @return
1000  *   Zero on success, non-zero error code otherwise.
1001  */
1002 int __rte_experimental
1003 rte_table_action_meter_read(struct rte_table_action *action,
1004         void *data,
1005         uint32_t tc_mask,
1006         struct rte_table_action_mtr_counters *stats,
1007         int clear);
1008
1009 /**
1010  * Table action TTL read.
1011  *
1012  * @param[in] action
1013  *   Handle to table action object (needs to be valid).
1014  * @param[in] data
1015  *   Data byte array (typically table rule data) with TTL action previously
1016  *   applied on it.
1017  * @param[inout] stats
1018  *   When non-NULL, it points to the area where the TTL stats counters read from
1019  *   *data* are saved.
1020  * @param[in] clear
1021  *   When non-zero, the TTL stats counters are cleared (i.e. set to zero),
1022  *   otherwise the counters are not modified. When the read operation is enabled
1023  *   (*stats* is non-NULL), the clear operation is performed after the read
1024  *   operation is completed.
1025  * @return
1026  *   Zero on success, non-zero error code otherwise.
1027  */
1028 int __rte_experimental
1029 rte_table_action_ttl_read(struct rte_table_action *action,
1030         void *data,
1031         struct rte_table_action_ttl_counters *stats,
1032         int clear);
1033
1034 /**
1035  * Table action stats read.
1036  *
1037  * @param[in] action
1038  *   Handle to table action object (needs to be valid).
1039  * @param[in] data
1040  *   Data byte array (typically table rule data) with stats action previously
1041  *   applied on it.
1042  * @param[inout] stats
1043  *   When non-NULL, it points to the area where the stats counters read from
1044  *   *data* are saved.
1045  * @param[in] clear
1046  *   When non-zero, the stats counters are cleared (i.e. set to zero), otherwise
1047  *   the counters are not modified. When the read operation is enabled (*stats*
1048  *   is non-NULL), the clear operation is performed after the read operation is
1049  *   completed.
1050  * @return
1051  *   Zero on success, non-zero error code otherwise.
1052  */
1053 int __rte_experimental
1054 rte_table_action_stats_read(struct rte_table_action *action,
1055         void *data,
1056         struct rte_table_action_stats_counters *stats,
1057         int clear);
1058
1059 /**
1060  * Table action timestamp read.
1061  *
1062  * @param[in] action
1063  *   Handle to table action object (needs to be valid).
1064  * @param[in] data
1065  *   Data byte array (typically table rule data) with timestamp action
1066  *   previously applied on it.
1067  * @param[inout] timestamp
1068  *   Pre-allocated memory where the timestamp read from *data* is saved (has to
1069  *   be non-NULL).
1070  * @return
1071  *   Zero on success, non-zero error code otherwise.
1072  */
1073 int __rte_experimental
1074 rte_table_action_time_read(struct rte_table_action *action,
1075         void *data,
1076         uint64_t *timestamp);
1077
1078 /**
1079  * Table action cryptodev symmetric session get.
1080  *
1081  * @param[in] action
1082  *   Handle to table action object (needs to be valid).
1083  * @param[in] data
1084  *   Data byte array (typically table rule data) with sym crypto action.
1085  * @return
1086  *   The pointer to the session on success, NULL otherwise.
1087  */
1088 struct rte_cryptodev_sym_session *__rte_experimental
1089 rte_table_action_crypto_sym_session_get(struct rte_table_action *action,
1090         void *data);
1091
1092 #ifdef __cplusplus
1093 }
1094 #endif
1095
1096 #endif /* __INCLUDE_RTE_TABLE_ACTION_H__ */