net/sfc: support group flows in tunnel offload
[dpdk.git] / drivers / net / sfc / sfc_flow_tunnel.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2021 Xilinx, Inc.
4  */
5
6 #ifndef _SFC_FLOW_TUNNEL_H
7 #define _SFC_FLOW_TUNNEL_H
8
9 #include <limits.h>
10 #include <stdbool.h>
11 #include <stdint.h>
12
13 #include "efx.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /** Flow Tunnel (FT) SW entry ID */
20 typedef uint8_t sfc_ft_id_t;
21
22 #define SFC_FT_TUNNEL_MARK_BITS \
23         (sizeof(sfc_ft_id_t) * CHAR_BIT)
24
25 #define SFC_FT_USER_MARK_BITS \
26         (sizeof(uint32_t) * CHAR_BIT - SFC_FT_TUNNEL_MARK_BITS)
27
28 #define SFC_FT_USER_MARK_MASK \
29         RTE_LEN2MASK(SFC_FT_USER_MARK_BITS, uint32_t)
30
31 #define SFC_FT_GET_TUNNEL_MARK(_mark) \
32         ((_mark) >> SFC_FT_USER_MARK_BITS)
33
34 #define SFC_FT_TUNNEL_MARK_INVALID      (0)
35
36 #define SFC_FT_TUNNEL_MARK_TO_ID(_tunnel_mark) \
37         ((_tunnel_mark) - 1)
38
39 #define SFC_FT_ID_TO_TUNNEL_MARK(_id) \
40         ((_id) + 1)
41
42 #define SFC_FT_ID_TO_MARK(_id) \
43         (SFC_FT_ID_TO_TUNNEL_MARK(_id) << SFC_FT_USER_MARK_BITS)
44
45 #define SFC_FT_GET_USER_MARK(_mark) \
46         ((_mark) & SFC_FT_USER_MARK_MASK)
47
48 #define SFC_FT_MAX_NTUNNELS \
49         (RTE_LEN2MASK(SFC_FT_TUNNEL_MARK_BITS, uint8_t) - 1)
50
51 struct sfc_flow_tunnel {
52         bool                            jump_rule_is_set;
53         efx_tunnel_protocol_t           encap_type;
54         unsigned int                    refcnt;
55         sfc_ft_id_t                     id;
56 };
57
58 struct sfc_adapter;
59
60 bool sfc_flow_tunnel_is_supported(struct sfc_adapter *sa);
61
62 bool sfc_flow_tunnel_is_active(struct sfc_adapter *sa);
63
64 struct sfc_flow_tunnel *sfc_flow_tunnel_pick(struct sfc_adapter *sa,
65                                              uint32_t ft_mark);
66
67 int sfc_flow_tunnel_detect_jump_rule(struct sfc_adapter *sa,
68                                      const struct rte_flow_action *actions,
69                                      struct sfc_flow_spec_mae *spec,
70                                      struct rte_flow_error *error);
71
72 #ifdef __cplusplus
73 }
74 #endif
75 #endif /* _SFC_FLOW_TUNNEL_H */