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