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_TT - 1)
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 #ifdef CONFIG_MLX5_EN_IPSEC
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
137 void mlx5e_destroy_ttc_table(struct mlx5e_flow_steering *fs);
138 int mlx5e_create_ttc_table(struct mlx5e_flow_steering *fs,
139 struct mlx5e_rx_res *rx_res);
140
141 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
142
143 void mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
144 void mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
145
146 int mlx5e_create_flow_steering(struct mlx5e_flow_steering *fs,
147 struct mlx5e_rx_res *rx_res,
148 const struct mlx5e_profile *profile,
149 struct net_device *netdev);
150 void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple,
151 const struct mlx5e_profile *profile);
152
153 struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile,
154 struct mlx5_core_dev *mdev,
155 bool state_destroy,
156 struct dentry *dfs_root);
157 void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs);
158 struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs);
159 struct mlx5e_tc_table *mlx5e_fs_get_tc(struct mlx5e_flow_steering *fs);
160 struct mlx5e_l2_table *mlx5e_fs_get_l2(struct mlx5e_flow_steering *fs);
161 struct mlx5_flow_namespace *mlx5e_fs_get_ns(struct mlx5e_flow_steering *fs, bool egress);
162 void mlx5e_fs_set_ns(struct mlx5e_flow_steering *fs, struct mlx5_flow_namespace *ns, bool egress);
163
mlx5e_fs_has_arfs(struct net_device * netdev)164 static inline bool mlx5e_fs_has_arfs(struct net_device *netdev)
165 {
166 return IS_ENABLED(CONFIG_MLX5_EN_ARFS) &&
167 netdev->hw_features & NETIF_F_NTUPLE;
168 }
169
mlx5e_fs_want_arfs(struct net_device * netdev)170 static inline bool mlx5e_fs_want_arfs(struct net_device *netdev)
171 {
172 return IS_ENABLED(CONFIG_MLX5_EN_ARFS) &&
173 netdev->features & NETIF_F_NTUPLE;
174 }
175
176 #ifdef CONFIG_MLX5_EN_RXNFC
177 struct mlx5e_ethtool_steering *mlx5e_fs_get_ethtool(struct mlx5e_flow_steering *fs);
178 #endif
179 struct mlx5_ttc_table *mlx5e_fs_get_ttc(struct mlx5e_flow_steering *fs, bool inner);
180 void mlx5e_fs_set_ttc(struct mlx5e_flow_steering *fs, struct mlx5_ttc_table *ttc, bool inner);
181 #ifdef CONFIG_MLX5_EN_ARFS
182 struct mlx5e_arfs_tables *mlx5e_fs_get_arfs(struct mlx5e_flow_steering *fs);
183 void mlx5e_fs_set_arfs(struct mlx5e_flow_steering *fs, struct mlx5e_arfs_tables *arfs);
184 #endif
185 struct mlx5e_ptp_fs *mlx5e_fs_get_ptp(struct mlx5e_flow_steering *fs);
186 void mlx5e_fs_set_ptp(struct mlx5e_flow_steering *fs, struct mlx5e_ptp_fs *ptp_fs);
187 struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs);
188 void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any);
189 struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs);
190 void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp);
191 #ifdef CONFIG_MLX5_EN_TLS
192 struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs);
193 void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp);
194 #endif
195 void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy);
196 void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs, bool vlan_strip_disable);
197
198 struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs);
199 int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num);
200 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs);
201 int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num);
202 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs);
203 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, struct net_device *netdev);
204 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs,
205 struct net_device *netdev,
206 __be16 proto, u16 vid);
207 int mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering *fs,
208 struct net_device *netdev,
209 __be16 proto, u16 vid);
210 void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *netdev);
211
212 struct dentry *mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering *fs);
213
214 #define fs_err(fs, fmt, ...) \
215 mlx5_core_err(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
216
217 #define fs_dbg(fs, fmt, ...) \
218 mlx5_core_dbg(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
219
220 #define fs_warn(fs, fmt, ...) \
221 mlx5_core_warn(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
222
223 #define fs_warn_once(fs, fmt, ...) \
224 mlx5_core_warn_once(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
225
226 #endif /* __MLX5E_FLOW_STEER_H__ */
227
228