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