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 #include "lib/fs_ttc.h"
9
10 struct mlx5e_post_act;
11 struct mlx5e_tc_table;
12
13 enum {
14 MLX5E_TC_FT_LEVEL = 0,
15 MLX5E_TC_TTC_FT_LEVEL,
16 MLX5E_TC_MISS_LEVEL,
17 };
18
19 enum {
20 MLX5E_TC_PRIO = 0,
21 MLX5E_PROMISC_PRIO,
22 MLX5E_NIC_PRIO,
23 };
24
25 struct mlx5e_flow_table {
26 int num_groups;
27 struct mlx5_flow_table *t;
28 struct mlx5_flow_group **g;
29 };
30
31 struct mlx5e_l2_rule {
32 u8 addr[ETH_ALEN + 2];
33 struct mlx5_flow_handle *rule;
34 };
35
36 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
37
38 struct mlx5e_promisc_table {
39 struct mlx5e_flow_table ft;
40 struct mlx5_flow_handle *rule;
41 };
42
43 /* Forward declaration and APIs to get private fields of vlan_table */
44 struct mlx5e_vlan_table;
45 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan);
46 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan);
47
48 struct mlx5e_l2_table {
49 struct mlx5e_flow_table ft;
50 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
51 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
52 struct mlx5e_l2_rule broadcast;
53 struct mlx5e_l2_rule allmulti;
54 struct mlx5_flow_handle *trap_rule;
55 bool broadcast_enabled;
56 bool allmulti_enabled;
57 bool promisc_enabled;
58 };
59
60 #define MLX5E_NUM_INDIR_TIRS (MLX5_NUM_INDIR_TIRS)
61
62 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
63 MLX5_HASH_FIELD_SEL_DST_IP)
64 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
65 MLX5_HASH_FIELD_SEL_DST_IP |\
66 MLX5_HASH_FIELD_SEL_L4_SPORT |\
67 MLX5_HASH_FIELD_SEL_L4_DPORT)
68 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
69 MLX5_HASH_FIELD_SEL_DST_IP |\
70 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
71
72 /* NIC promisc FT level */
73 enum {
74 MLX5E_PROMISC_FT_LEVEL,
75 };
76
77 /* NIC prio FTS */
78 enum {
79 MLX5E_VLAN_FT_LEVEL,
80 MLX5E_L2_FT_LEVEL,
81 MLX5E_TTC_FT_LEVEL,
82 MLX5E_INNER_TTC_FT_LEVEL,
83 MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
84 MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
85 #ifdef CONFIG_MLX5_EN_TLS
86 MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
87 #endif
88 #ifdef CONFIG_MLX5_EN_ARFS
89 MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
90 #endif
91 #if defined(CONFIG_MLX5_EN_IPSEC) || defined(CONFIG_MLX5_EN_PSP)
92 MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
93 MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
94 MLX5E_ACCEL_FS_POL_FT_LEVEL,
95 MLX5E_ACCEL_FS_POL_MISS_FT_LEVEL,
96 MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL,
97 #endif
98 };
99
100 struct mlx5e_flow_steering;
101 struct mlx5e_rx_res;
102
103 #ifdef CONFIG_MLX5_EN_ARFS
104 struct mlx5e_arfs_tables;
105
106 int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
107 struct mlx5e_rx_res *rx_res, bool ntuple);
108 void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple);
109 int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs);
110 int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs);
111 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
112 u16 rxq_index, u32 flow_id);
113 #else
mlx5e_arfs_create_tables(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res,bool ntuple)114 static inline int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
115 struct mlx5e_rx_res *rx_res, bool ntuple)
116 { return 0; }
mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering * fs,bool ntuple)117 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple) {}
mlx5e_arfs_enable(struct mlx5e_flow_steering * fs)118 static inline int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs)
119 { return -EOPNOTSUPP; }
mlx5e_arfs_disable(struct mlx5e_flow_steering * fs)120 static inline int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs)
121 { return -EOPNOTSUPP; }
122 #endif
123
124 #ifdef CONFIG_MLX5_EN_TLS
125 struct mlx5e_accel_fs_tcp;
126 #endif
127
128 struct mlx5e_profile;
129 struct mlx5e_fs_udp;
130 struct mlx5e_fs_any;
131 struct mlx5e_ptp_fs;
132
133 void mlx5e_set_ttc_params(struct mlx5e_flow_steering *fs,
134 struct mlx5e_rx_res *rx_res,
135 struct ttc_params *ttc_params, bool tunnel,
136 bool ipsec_rss);
137
138 void mlx5e_destroy_ttc_table(struct mlx5e_flow_steering *fs);
139 int mlx5e_create_ttc_table(struct mlx5e_flow_steering *fs,
140 struct mlx5e_rx_res *rx_res);
141
142 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
143
144 void mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
145 void mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
146
147 int mlx5e_create_flow_steering(struct mlx5e_flow_steering *fs,
148 struct mlx5e_rx_res *rx_res,
149 const struct mlx5e_profile *profile,
150 struct net_device *netdev);
151 void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple,
152 const struct mlx5e_profile *profile);
153
154 struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile,
155 struct mlx5_core_dev *mdev,
156 bool state_destroy,
157 struct dentry *dfs_root);
158 void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs);
159 struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs);
160 struct mlx5e_tc_table *mlx5e_fs_get_tc(struct mlx5e_flow_steering *fs);
161 struct mlx5e_l2_table *mlx5e_fs_get_l2(struct mlx5e_flow_steering *fs);
162 struct mlx5_flow_namespace *mlx5e_fs_get_ns(struct mlx5e_flow_steering *fs, bool egress);
163 void mlx5e_fs_set_ns(struct mlx5e_flow_steering *fs, struct mlx5_flow_namespace *ns, bool egress);
164
mlx5e_fs_has_arfs(struct net_device * netdev)165 static inline bool mlx5e_fs_has_arfs(struct net_device *netdev)
166 {
167 return IS_ENABLED(CONFIG_MLX5_EN_ARFS) &&
168 netdev->hw_features & NETIF_F_NTUPLE;
169 }
170
mlx5e_fs_want_arfs(struct net_device * netdev)171 static inline bool mlx5e_fs_want_arfs(struct net_device *netdev)
172 {
173 return IS_ENABLED(CONFIG_MLX5_EN_ARFS) &&
174 netdev->features & NETIF_F_NTUPLE;
175 }
176
177 #ifdef CONFIG_MLX5_EN_RXNFC
178 struct mlx5e_ethtool_steering *mlx5e_fs_get_ethtool(struct mlx5e_flow_steering *fs);
179 #endif
180 struct mlx5_ttc_table *mlx5e_fs_get_ttc(struct mlx5e_flow_steering *fs, bool inner);
181 void mlx5e_fs_set_ttc(struct mlx5e_flow_steering *fs, struct mlx5_ttc_table *ttc, bool inner);
182 #ifdef CONFIG_MLX5_EN_ARFS
183 struct mlx5e_arfs_tables *mlx5e_fs_get_arfs(struct mlx5e_flow_steering *fs);
184 void mlx5e_fs_set_arfs(struct mlx5e_flow_steering *fs, struct mlx5e_arfs_tables *arfs);
185 #endif
186 struct mlx5e_ptp_fs *mlx5e_fs_get_ptp(struct mlx5e_flow_steering *fs);
187 void mlx5e_fs_set_ptp(struct mlx5e_flow_steering *fs, struct mlx5e_ptp_fs *ptp_fs);
188 struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs);
189 void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any);
190 struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs);
191 void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp);
192 #ifdef CONFIG_MLX5_EN_TLS
193 struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs);
194 void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp);
195 #endif
196 void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy);
197 void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs, bool vlan_strip_disable);
198
199 struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs);
200 int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num);
201 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs);
202 int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num);
203 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs);
204 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, struct net_device *netdev);
205 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs,
206 struct net_device *netdev,
207 __be16 proto, u16 vid);
208 int mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering *fs,
209 struct net_device *netdev,
210 __be16 proto, u16 vid);
211 void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *netdev);
212
213 struct dentry *mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering *fs);
214
215 #define fs_err(fs, fmt, ...) \
216 mlx5_core_err(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
217
218 #define fs_dbg(fs, fmt, ...) \
219 mlx5_core_dbg(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
220
221 #define fs_warn(fs, fmt, ...) \
222 mlx5_core_warn(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
223
224 #define fs_warn_once(fs, fmt, ...) \
225 mlx5_core_warn_once(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
226
227 #endif /* __MLX5E_FLOW_STEER_H__ */
228
229