Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / en / fs.h
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2018 Mellanox Technologies. */
3
4 #ifndef __MLX5E_FLOW_STEER_H__
5 #define __MLX5E_FLOW_STEER_H__
6
7 #include "mod_hdr.h"
8
9 enum {
10         MLX5E_TC_FT_LEVEL = 0,
11         MLX5E_TC_TTC_FT_LEVEL,
12 };
13
14 struct mlx5e_tc_table {
15         /* Protects the dynamic assignment of the t parameter
16          * which is the nic tc root table.
17          */
18         struct mutex                    t_lock;
19         struct mlx5_flow_table          *t;
20         struct mlx5_fs_chains           *chains;
21
22         struct rhashtable               ht;
23
24         struct mod_hdr_tbl mod_hdr;
25         struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */
26         DECLARE_HASHTABLE(hairpin_tbl, 8);
27
28         struct notifier_block     netdevice_nb;
29         struct netdev_net_notifier      netdevice_nn;
30
31         struct mlx5_tc_ct_priv         *ct;
32 };
33
34 struct mlx5e_flow_table {
35         int num_groups;
36         struct mlx5_flow_table *t;
37         struct mlx5_flow_group **g;
38 };
39
40 struct mlx5e_l2_rule {
41         u8  addr[ETH_ALEN + 2];
42         struct mlx5_flow_handle *rule;
43 };
44
45 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
46
47 struct mlx5e_promisc_table {
48         struct mlx5e_flow_table ft;
49         struct mlx5_flow_handle *rule;
50 };
51
52 /* Forward declaration and APIs to get private fields of vlan_table */
53 struct mlx5e_vlan_table;
54 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan);
55 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan);
56
57 struct mlx5e_l2_table {
58         struct mlx5e_flow_table    ft;
59         struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
60         struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
61         struct mlx5e_l2_rule       broadcast;
62         struct mlx5e_l2_rule       allmulti;
63         struct mlx5_flow_handle    *trap_rule;
64         bool                       broadcast_enabled;
65         bool                       allmulti_enabled;
66         bool                       promisc_enabled;
67 };
68
69 enum mlx5e_traffic_types {
70         MLX5E_TT_IPV4_TCP,
71         MLX5E_TT_IPV6_TCP,
72         MLX5E_TT_IPV4_UDP,
73         MLX5E_TT_IPV6_UDP,
74         MLX5E_TT_IPV4_IPSEC_AH,
75         MLX5E_TT_IPV6_IPSEC_AH,
76         MLX5E_TT_IPV4_IPSEC_ESP,
77         MLX5E_TT_IPV6_IPSEC_ESP,
78         MLX5E_TT_IPV4,
79         MLX5E_TT_IPV6,
80         MLX5E_TT_ANY,
81         MLX5E_NUM_TT,
82         MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
83 };
84
85 struct mlx5e_tirc_config {
86         u8 l3_prot_type;
87         u8 l4_prot_type;
88         u32 rx_hash_fields;
89 };
90
91 #define MLX5_HASH_IP            (MLX5_HASH_FIELD_SEL_SRC_IP   |\
92                                  MLX5_HASH_FIELD_SEL_DST_IP)
93 #define MLX5_HASH_IP_L4PORTS    (MLX5_HASH_FIELD_SEL_SRC_IP   |\
94                                  MLX5_HASH_FIELD_SEL_DST_IP   |\
95                                  MLX5_HASH_FIELD_SEL_L4_SPORT |\
96                                  MLX5_HASH_FIELD_SEL_L4_DPORT)
97 #define MLX5_HASH_IP_IPSEC_SPI  (MLX5_HASH_FIELD_SEL_SRC_IP   |\
98                                  MLX5_HASH_FIELD_SEL_DST_IP   |\
99                                  MLX5_HASH_FIELD_SEL_IPSEC_SPI)
100
101 enum mlx5e_tunnel_types {
102         MLX5E_TT_IPV4_GRE,
103         MLX5E_TT_IPV6_GRE,
104         MLX5E_TT_IPV4_IPIP,
105         MLX5E_TT_IPV6_IPIP,
106         MLX5E_TT_IPV4_IPV6,
107         MLX5E_TT_IPV6_IPV6,
108         MLX5E_NUM_TUNNEL_TT,
109 };
110
111 bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev);
112
113 struct mlx5e_ttc_rule {
114         struct mlx5_flow_handle *rule;
115         struct mlx5_flow_destination default_dest;
116 };
117
118 /* L3/L4 traffic type classifier */
119 struct mlx5e_ttc_table {
120         struct mlx5e_flow_table ft;
121         struct mlx5e_ttc_rule rules[MLX5E_NUM_TT];
122         struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
123 };
124
125 /* NIC prio FTS */
126 enum {
127         MLX5E_PROMISC_FT_LEVEL,
128         MLX5E_VLAN_FT_LEVEL,
129         MLX5E_L2_FT_LEVEL,
130         MLX5E_TTC_FT_LEVEL,
131         MLX5E_INNER_TTC_FT_LEVEL,
132         MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
133         MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
134 #ifdef CONFIG_MLX5_EN_TLS
135         MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
136 #endif
137 #ifdef CONFIG_MLX5_EN_ARFS
138         MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
139 #endif
140 #ifdef CONFIG_MLX5_EN_IPSEC
141         MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
142         MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
143 #endif
144 };
145
146 #define MLX5E_TTC_NUM_GROUPS    3
147 #define MLX5E_TTC_GROUP1_SIZE   (BIT(3) + MLX5E_NUM_TUNNEL_TT)
148 #define MLX5E_TTC_GROUP2_SIZE    BIT(1)
149 #define MLX5E_TTC_GROUP3_SIZE    BIT(0)
150 #define MLX5E_TTC_TABLE_SIZE    (MLX5E_TTC_GROUP1_SIZE +\
151                                  MLX5E_TTC_GROUP2_SIZE +\
152                                  MLX5E_TTC_GROUP3_SIZE)
153
154 #define MLX5E_INNER_TTC_NUM_GROUPS      3
155 #define MLX5E_INNER_TTC_GROUP1_SIZE     BIT(3)
156 #define MLX5E_INNER_TTC_GROUP2_SIZE     BIT(1)
157 #define MLX5E_INNER_TTC_GROUP3_SIZE     BIT(0)
158 #define MLX5E_INNER_TTC_TABLE_SIZE      (MLX5E_INNER_TTC_GROUP1_SIZE +\
159                                          MLX5E_INNER_TTC_GROUP2_SIZE +\
160                                          MLX5E_INNER_TTC_GROUP3_SIZE)
161
162 #ifdef CONFIG_MLX5_EN_RXNFC
163
164 struct mlx5e_ethtool_table {
165         struct mlx5_flow_table *ft;
166         int                    num_rules;
167 };
168
169 #define ETHTOOL_NUM_L3_L4_FTS 7
170 #define ETHTOOL_NUM_L2_FTS 4
171
172 struct mlx5e_ethtool_steering {
173         struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
174         struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
175         struct list_head                rules;
176         int                             tot_num_rules;
177 };
178
179 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
180 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
181 int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
182 int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
183                             struct ethtool_rxnfc *info, u32 *rule_locs);
184 #else
185 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv)    { }
186 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
187 static inline int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
188 { return -EOPNOTSUPP; }
189 static inline int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
190                                           struct ethtool_rxnfc *info, u32 *rule_locs)
191 { return -EOPNOTSUPP; }
192 #endif /* CONFIG_MLX5_EN_RXNFC */
193
194 #ifdef CONFIG_MLX5_EN_ARFS
195 struct mlx5e_arfs_tables;
196
197 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
198 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
199 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
200 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
201 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
202                         u16 rxq_index, u32 flow_id);
203 #else
204 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
205 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
206 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
207 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
208 #endif
209
210 #ifdef CONFIG_MLX5_EN_TLS
211 struct mlx5e_accel_fs_tcp;
212 #endif
213
214 struct mlx5e_fs_udp;
215 struct mlx5e_fs_any;
216 struct mlx5e_ptp_fs;
217
218 struct mlx5e_flow_steering {
219         struct mlx5_flow_namespace      *ns;
220         struct mlx5_flow_namespace      *egress_ns;
221 #ifdef CONFIG_MLX5_EN_RXNFC
222         struct mlx5e_ethtool_steering   ethtool;
223 #endif
224         struct mlx5e_tc_table           tc;
225         struct mlx5e_promisc_table      promisc;
226         struct mlx5e_vlan_table         *vlan;
227         struct mlx5e_l2_table           l2;
228         struct mlx5e_ttc_table          ttc;
229         struct mlx5e_ttc_table          inner_ttc;
230 #ifdef CONFIG_MLX5_EN_ARFS
231         struct mlx5e_arfs_tables       *arfs;
232 #endif
233 #ifdef CONFIG_MLX5_EN_TLS
234         struct mlx5e_accel_fs_tcp      *accel_tcp;
235 #endif
236         struct mlx5e_fs_udp            *udp;
237         struct mlx5e_fs_any            *any;
238         struct mlx5e_ptp_fs            *ptp_fs;
239 };
240
241 struct ttc_params {
242         struct mlx5_flow_table_attr ft_attr;
243         u32 any_tt_tirn;
244         u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
245         struct mlx5e_ttc_table *inner_ttc;
246 };
247
248 void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
249 void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
250 void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
251
252 int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
253                            struct mlx5e_ttc_table *ttc);
254 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
255                              struct mlx5e_ttc_table *ttc);
256
257 int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
258                                  struct mlx5e_ttc_table *ttc);
259 void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
260                                    struct mlx5e_ttc_table *ttc);
261
262 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
263 int mlx5e_ttc_fwd_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type,
264                        struct mlx5_flow_destination *new_dest);
265 struct mlx5_flow_destination
266 mlx5e_ttc_get_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
267 int mlx5e_ttc_fwd_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
268
269 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
270 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
271
272 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
273 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
274
275 u8 mlx5e_get_proto_by_tunnel_type(enum mlx5e_tunnel_types tt);
276 int mlx5e_add_vlan_trap(struct mlx5e_priv *priv, int  trap_id, int tir_num);
277 void mlx5e_remove_vlan_trap(struct mlx5e_priv *priv);
278 int mlx5e_add_mac_trap(struct mlx5e_priv *priv, int  trap_id, int tir_num);
279 void mlx5e_remove_mac_trap(struct mlx5e_priv *priv);
280
281 #endif /* __MLX5E_FLOW_STEER_H__ */
282