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