2 * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/mlx5/fs.h>
35 #include "en/params.h"
36 #include "en/xsk/umem.h"
38 struct mlx5e_ethtool_rule {
39 struct list_head list;
40 struct ethtool_rx_flow_spec flow_spec;
41 struct mlx5_flow_handle *rule;
42 struct mlx5e_ethtool_table *eth_ft;
45 static void put_flow_table(struct mlx5e_ethtool_table *eth_ft)
47 if (!--eth_ft->num_rules) {
48 mlx5_destroy_flow_table(eth_ft->ft);
53 #define MLX5E_ETHTOOL_L3_L4_PRIO 0
54 #define MLX5E_ETHTOOL_L2_PRIO (MLX5E_ETHTOOL_L3_L4_PRIO + ETHTOOL_NUM_L3_L4_FTS)
55 #define MLX5E_ETHTOOL_NUM_ENTRIES 64000
56 #define MLX5E_ETHTOOL_NUM_GROUPS 10
57 static struct mlx5e_ethtool_table *get_flow_table(struct mlx5e_priv *priv,
58 struct ethtool_rx_flow_spec *fs,
61 struct mlx5_flow_table_attr ft_attr = {};
62 struct mlx5e_ethtool_table *eth_ft;
63 struct mlx5_flow_namespace *ns;
64 struct mlx5_flow_table *ft;
69 switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
74 max_tuples = ETHTOOL_NUM_L3_L4_FTS;
75 prio = MLX5E_ETHTOOL_L3_L4_PRIO + (max_tuples - num_tuples);
76 eth_ft = &priv->fs.ethtool.l3_l4_ft[prio];
80 max_tuples = ETHTOOL_NUM_L3_L4_FTS;
81 prio = MLX5E_ETHTOOL_L3_L4_PRIO + (max_tuples - num_tuples);
82 eth_ft = &priv->fs.ethtool.l3_l4_ft[prio];
85 max_tuples = ETHTOOL_NUM_L2_FTS;
86 prio = max_tuples - num_tuples;
87 eth_ft = &priv->fs.ethtool.l2_ft[prio];
88 prio += MLX5E_ETHTOOL_L2_PRIO;
91 return ERR_PTR(-EINVAL);
98 ns = mlx5_get_flow_namespace(priv->mdev,
99 MLX5_FLOW_NAMESPACE_ETHTOOL);
101 return ERR_PTR(-EOPNOTSUPP);
103 table_size = min_t(u32, BIT(MLX5_CAP_FLOWTABLE(priv->mdev,
104 flow_table_properties_nic_receive.log_max_ft_size)),
105 MLX5E_ETHTOOL_NUM_ENTRIES);
108 ft_attr.max_fte = table_size;
109 ft_attr.autogroup.max_num_groups = MLX5E_ETHTOOL_NUM_GROUPS;
110 ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
118 static void mask_spec(u8 *mask, u8 *val, size_t size)
122 for (i = 0; i < size; i++, mask++, val++)
123 *((u8 *)val) = *((u8 *)mask) & *((u8 *)val);
126 #define MLX5E_FTE_SET(header_p, fld, v) \
127 MLX5_SET(fte_match_set_lyr_2_4, header_p, fld, v)
129 #define MLX5E_FTE_ADDR_OF(header_p, fld) \
130 MLX5_ADDR_OF(fte_match_set_lyr_2_4, header_p, fld)
133 set_ip4(void *headers_c, void *headers_v, __be32 ip4src_m,
134 __be32 ip4src_v, __be32 ip4dst_m, __be32 ip4dst_v)
137 memcpy(MLX5E_FTE_ADDR_OF(headers_v, src_ipv4_src_ipv6.ipv4_layout.ipv4),
138 &ip4src_v, sizeof(ip4src_v));
139 memcpy(MLX5E_FTE_ADDR_OF(headers_c, src_ipv4_src_ipv6.ipv4_layout.ipv4),
140 &ip4src_m, sizeof(ip4src_m));
143 memcpy(MLX5E_FTE_ADDR_OF(headers_v, dst_ipv4_dst_ipv6.ipv4_layout.ipv4),
144 &ip4dst_v, sizeof(ip4dst_v));
145 memcpy(MLX5E_FTE_ADDR_OF(headers_c, dst_ipv4_dst_ipv6.ipv4_layout.ipv4),
146 &ip4dst_m, sizeof(ip4dst_m));
149 MLX5E_FTE_SET(headers_c, ethertype, 0xffff);
150 MLX5E_FTE_SET(headers_v, ethertype, ETH_P_IP);
154 set_ip6(void *headers_c, void *headers_v, __be32 ip6src_m[4],
155 __be32 ip6src_v[4], __be32 ip6dst_m[4], __be32 ip6dst_v[4])
157 u8 ip6_sz = MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6);
159 if (!ipv6_addr_any((struct in6_addr *)ip6src_m)) {
160 memcpy(MLX5E_FTE_ADDR_OF(headers_v, src_ipv4_src_ipv6.ipv6_layout.ipv6),
162 memcpy(MLX5E_FTE_ADDR_OF(headers_c, src_ipv4_src_ipv6.ipv6_layout.ipv6),
165 if (!ipv6_addr_any((struct in6_addr *)ip6dst_m)) {
166 memcpy(MLX5E_FTE_ADDR_OF(headers_v, dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
168 memcpy(MLX5E_FTE_ADDR_OF(headers_c, dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
172 MLX5E_FTE_SET(headers_c, ethertype, 0xffff);
173 MLX5E_FTE_SET(headers_v, ethertype, ETH_P_IPV6);
177 set_tcp(void *headers_c, void *headers_v, __be16 psrc_m, __be16 psrc_v,
178 __be16 pdst_m, __be16 pdst_v)
181 MLX5E_FTE_SET(headers_c, tcp_sport, ntohs(psrc_m));
182 MLX5E_FTE_SET(headers_v, tcp_sport, ntohs(psrc_v));
185 MLX5E_FTE_SET(headers_c, tcp_dport, ntohs(pdst_m));
186 MLX5E_FTE_SET(headers_v, tcp_dport, ntohs(pdst_v));
189 MLX5E_FTE_SET(headers_c, ip_protocol, 0xffff);
190 MLX5E_FTE_SET(headers_v, ip_protocol, IPPROTO_TCP);
194 set_udp(void *headers_c, void *headers_v, __be16 psrc_m, __be16 psrc_v,
195 __be16 pdst_m, __be16 pdst_v)
198 MLX5E_FTE_SET(headers_c, udp_sport, ntohs(psrc_m));
199 MLX5E_FTE_SET(headers_v, udp_sport, ntohs(psrc_v));
203 MLX5E_FTE_SET(headers_c, udp_dport, ntohs(pdst_m));
204 MLX5E_FTE_SET(headers_v, udp_dport, ntohs(pdst_v));
207 MLX5E_FTE_SET(headers_c, ip_protocol, 0xffff);
208 MLX5E_FTE_SET(headers_v, ip_protocol, IPPROTO_UDP);
212 parse_tcp4(void *headers_c, void *headers_v, struct ethtool_rx_flow_spec *fs)
214 struct ethtool_tcpip4_spec *l4_mask = &fs->m_u.tcp_ip4_spec;
215 struct ethtool_tcpip4_spec *l4_val = &fs->h_u.tcp_ip4_spec;
217 set_ip4(headers_c, headers_v, l4_mask->ip4src, l4_val->ip4src,
218 l4_mask->ip4dst, l4_val->ip4dst);
220 set_tcp(headers_c, headers_v, l4_mask->psrc, l4_val->psrc,
221 l4_mask->pdst, l4_val->pdst);
225 parse_udp4(void *headers_c, void *headers_v, struct ethtool_rx_flow_spec *fs)
227 struct ethtool_tcpip4_spec *l4_mask = &fs->m_u.udp_ip4_spec;
228 struct ethtool_tcpip4_spec *l4_val = &fs->h_u.udp_ip4_spec;
230 set_ip4(headers_c, headers_v, l4_mask->ip4src, l4_val->ip4src,
231 l4_mask->ip4dst, l4_val->ip4dst);
233 set_udp(headers_c, headers_v, l4_mask->psrc, l4_val->psrc,
234 l4_mask->pdst, l4_val->pdst);
238 parse_ip4(void *headers_c, void *headers_v, struct ethtool_rx_flow_spec *fs)
240 struct ethtool_usrip4_spec *l3_mask = &fs->m_u.usr_ip4_spec;
241 struct ethtool_usrip4_spec *l3_val = &fs->h_u.usr_ip4_spec;
243 set_ip4(headers_c, headers_v, l3_mask->ip4src, l3_val->ip4src,
244 l3_mask->ip4dst, l3_val->ip4dst);
246 if (l3_mask->proto) {
247 MLX5E_FTE_SET(headers_c, ip_protocol, l3_mask->proto);
248 MLX5E_FTE_SET(headers_v, ip_protocol, l3_val->proto);
253 parse_ip6(void *headers_c, void *headers_v, struct ethtool_rx_flow_spec *fs)
255 struct ethtool_usrip6_spec *l3_mask = &fs->m_u.usr_ip6_spec;
256 struct ethtool_usrip6_spec *l3_val = &fs->h_u.usr_ip6_spec;
258 set_ip6(headers_c, headers_v, l3_mask->ip6src,
259 l3_val->ip6src, l3_mask->ip6dst, l3_val->ip6dst);
261 if (l3_mask->l4_proto) {
262 MLX5E_FTE_SET(headers_c, ip_protocol, l3_mask->l4_proto);
263 MLX5E_FTE_SET(headers_v, ip_protocol, l3_val->l4_proto);
268 parse_tcp6(void *headers_c, void *headers_v, struct ethtool_rx_flow_spec *fs)
270 struct ethtool_tcpip6_spec *l4_mask = &fs->m_u.tcp_ip6_spec;
271 struct ethtool_tcpip6_spec *l4_val = &fs->h_u.tcp_ip6_spec;
273 set_ip6(headers_c, headers_v, l4_mask->ip6src,
274 l4_val->ip6src, l4_mask->ip6dst, l4_val->ip6dst);
276 set_tcp(headers_c, headers_v, l4_mask->psrc, l4_val->psrc,
277 l4_mask->pdst, l4_val->pdst);
281 parse_udp6(void *headers_c, void *headers_v, struct ethtool_rx_flow_spec *fs)
283 struct ethtool_tcpip6_spec *l4_mask = &fs->m_u.udp_ip6_spec;
284 struct ethtool_tcpip6_spec *l4_val = &fs->h_u.udp_ip6_spec;
286 set_ip6(headers_c, headers_v, l4_mask->ip6src,
287 l4_val->ip6src, l4_mask->ip6dst, l4_val->ip6dst);
289 set_udp(headers_c, headers_v, l4_mask->psrc, l4_val->psrc,
290 l4_mask->pdst, l4_val->pdst);
294 parse_ether(void *headers_c, void *headers_v, struct ethtool_rx_flow_spec *fs)
296 struct ethhdr *eth_mask = &fs->m_u.ether_spec;
297 struct ethhdr *eth_val = &fs->h_u.ether_spec;
299 mask_spec((u8 *)eth_mask, (u8 *)eth_val, sizeof(*eth_mask));
300 ether_addr_copy(MLX5E_FTE_ADDR_OF(headers_c, smac_47_16), eth_mask->h_source);
301 ether_addr_copy(MLX5E_FTE_ADDR_OF(headers_v, smac_47_16), eth_val->h_source);
302 ether_addr_copy(MLX5E_FTE_ADDR_OF(headers_c, dmac_47_16), eth_mask->h_dest);
303 ether_addr_copy(MLX5E_FTE_ADDR_OF(headers_v, dmac_47_16), eth_val->h_dest);
304 MLX5E_FTE_SET(headers_c, ethertype, ntohs(eth_mask->h_proto));
305 MLX5E_FTE_SET(headers_v, ethertype, ntohs(eth_val->h_proto));
309 set_cvlan(void *headers_c, void *headers_v, __be16 vlan_tci)
311 MLX5E_FTE_SET(headers_c, cvlan_tag, 1);
312 MLX5E_FTE_SET(headers_v, cvlan_tag, 1);
313 MLX5E_FTE_SET(headers_c, first_vid, 0xfff);
314 MLX5E_FTE_SET(headers_v, first_vid, ntohs(vlan_tci));
318 set_dmac(void *headers_c, void *headers_v,
319 unsigned char m_dest[ETH_ALEN], unsigned char v_dest[ETH_ALEN])
321 ether_addr_copy(MLX5E_FTE_ADDR_OF(headers_c, dmac_47_16), m_dest);
322 ether_addr_copy(MLX5E_FTE_ADDR_OF(headers_v, dmac_47_16), v_dest);
325 static int set_flow_attrs(u32 *match_c, u32 *match_v,
326 struct ethtool_rx_flow_spec *fs)
328 void *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_c,
330 void *outer_headers_v = MLX5_ADDR_OF(fte_match_param, match_v,
332 u32 flow_type = fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT);
336 parse_tcp4(outer_headers_c, outer_headers_v, fs);
339 parse_udp4(outer_headers_c, outer_headers_v, fs);
342 parse_ip4(outer_headers_c, outer_headers_v, fs);
345 parse_tcp6(outer_headers_c, outer_headers_v, fs);
348 parse_udp6(outer_headers_c, outer_headers_v, fs);
351 parse_ip6(outer_headers_c, outer_headers_v, fs);
354 parse_ether(outer_headers_c, outer_headers_v, fs);
360 if ((fs->flow_type & FLOW_EXT) &&
361 (fs->m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)))
362 set_cvlan(outer_headers_c, outer_headers_v, fs->h_ext.vlan_tci);
364 if (fs->flow_type & FLOW_MAC_EXT &&
365 !is_zero_ether_addr(fs->m_ext.h_dest)) {
366 mask_spec(fs->m_ext.h_dest, fs->h_ext.h_dest, ETH_ALEN);
367 set_dmac(outer_headers_c, outer_headers_v, fs->m_ext.h_dest,
374 static void add_rule_to_list(struct mlx5e_priv *priv,
375 struct mlx5e_ethtool_rule *rule)
377 struct mlx5e_ethtool_rule *iter;
378 struct list_head *head = &priv->fs.ethtool.rules;
380 list_for_each_entry(iter, &priv->fs.ethtool.rules, list) {
381 if (iter->flow_spec.location > rule->flow_spec.location)
385 priv->fs.ethtool.tot_num_rules++;
386 list_add(&rule->list, head);
389 static bool outer_header_zero(u32 *match_criteria)
391 int size = MLX5_FLD_SZ_BYTES(fte_match_param, outer_headers);
392 char *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_criteria,
395 return outer_headers_c[0] == 0 && !memcmp(outer_headers_c,
400 static struct mlx5_flow_handle *
401 add_ethtool_flow_rule(struct mlx5e_priv *priv,
402 struct mlx5_flow_table *ft,
403 struct ethtool_rx_flow_spec *fs)
405 struct mlx5_flow_act flow_act = { .flags = FLOW_ACT_NO_APPEND };
406 struct mlx5_flow_destination *dst = NULL;
407 struct mlx5_flow_handle *rule;
408 struct mlx5_flow_spec *spec;
411 spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
413 return ERR_PTR(-ENOMEM);
414 err = set_flow_attrs(spec->match_criteria, spec->match_value,
419 if (fs->ring_cookie == RX_CLS_FLOW_DISC) {
420 flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP;
422 struct mlx5e_params *params = &priv->channels.params;
423 enum mlx5e_rq_group group;
424 struct mlx5e_tir *tir;
427 mlx5e_qid_get_ch_and_group(params, fs->ring_cookie, &ix, &group);
428 tir = group == MLX5E_RQ_GROUP_XSK ? priv->xsk_tir : priv->direct_tir;
430 dst = kzalloc(sizeof(*dst), GFP_KERNEL);
436 dst->type = MLX5_FLOW_DESTINATION_TYPE_TIR;
437 dst->tir_num = tir[ix].tirn;
438 flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
441 spec->match_criteria_enable = (!outer_header_zero(spec->match_criteria));
442 spec->flow_context.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG;
443 rule = mlx5_add_flow_rules(ft, spec, &flow_act, dst, dst ? 1 : 0);
446 netdev_err(priv->netdev, "%s: failed to add ethtool steering rule: %d\n",
453 return err ? ERR_PTR(err) : rule;
456 static void del_ethtool_rule(struct mlx5e_priv *priv,
457 struct mlx5e_ethtool_rule *eth_rule)
460 mlx5_del_flow_rules(eth_rule->rule);
461 list_del(ð_rule->list);
462 priv->fs.ethtool.tot_num_rules--;
463 put_flow_table(eth_rule->eth_ft);
467 static struct mlx5e_ethtool_rule *find_ethtool_rule(struct mlx5e_priv *priv,
470 struct mlx5e_ethtool_rule *iter;
472 list_for_each_entry(iter, &priv->fs.ethtool.rules, list) {
473 if (iter->flow_spec.location == location)
479 static struct mlx5e_ethtool_rule *get_ethtool_rule(struct mlx5e_priv *priv,
482 struct mlx5e_ethtool_rule *eth_rule;
484 eth_rule = find_ethtool_rule(priv, location);
486 del_ethtool_rule(priv, eth_rule);
488 eth_rule = kzalloc(sizeof(*eth_rule), GFP_KERNEL);
490 return ERR_PTR(-ENOMEM);
492 add_rule_to_list(priv, eth_rule);
496 #define MAX_NUM_OF_ETHTOOL_RULES BIT(10)
498 #define all_ones(field) (field == (__force typeof(field))-1)
499 #define all_zeros_or_all_ones(field) \
500 ((field) == 0 || (field) == (__force typeof(field))-1)
502 static int validate_ethter(struct ethtool_rx_flow_spec *fs)
504 struct ethhdr *eth_mask = &fs->m_u.ether_spec;
507 if (!is_zero_ether_addr(eth_mask->h_dest))
509 if (!is_zero_ether_addr(eth_mask->h_source))
511 if (eth_mask->h_proto)
516 static int validate_tcpudp4(struct ethtool_rx_flow_spec *fs)
518 struct ethtool_tcpip4_spec *l4_mask = &fs->m_u.tcp_ip4_spec;
532 /* Flow is TCP/UDP */
536 static int validate_ip4(struct ethtool_rx_flow_spec *fs)
538 struct ethtool_usrip4_spec *l3_mask = &fs->m_u.usr_ip4_spec;
541 if (l3_mask->l4_4_bytes || l3_mask->tos ||
542 fs->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4)
554 static int validate_ip6(struct ethtool_rx_flow_spec *fs)
556 struct ethtool_usrip6_spec *l3_mask = &fs->m_u.usr_ip6_spec;
559 if (l3_mask->l4_4_bytes || l3_mask->tclass)
561 if (!ipv6_addr_any((struct in6_addr *)l3_mask->ip6src))
564 if (!ipv6_addr_any((struct in6_addr *)l3_mask->ip6dst))
566 if (l3_mask->l4_proto)
572 static int validate_tcpudp6(struct ethtool_rx_flow_spec *fs)
574 struct ethtool_tcpip6_spec *l4_mask = &fs->m_u.tcp_ip6_spec;
580 if (!ipv6_addr_any((struct in6_addr *)l4_mask->ip6src))
583 if (!ipv6_addr_any((struct in6_addr *)l4_mask->ip6dst))
590 /* Flow is TCP/UDP */
594 static int validate_vlan(struct ethtool_rx_flow_spec *fs)
596 if (fs->m_ext.vlan_etype ||
597 fs->m_ext.vlan_tci != cpu_to_be16(VLAN_VID_MASK))
600 if (fs->m_ext.vlan_tci &&
601 (be16_to_cpu(fs->h_ext.vlan_tci) >= VLAN_N_VID))
607 static int validate_flow(struct mlx5e_priv *priv,
608 struct ethtool_rx_flow_spec *fs)
613 if (fs->location >= MAX_NUM_OF_ETHTOOL_RULES)
616 if (fs->ring_cookie != RX_CLS_FLOW_DISC)
617 if (!mlx5e_qid_validate(priv->profile, &priv->channels.params,
621 switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
623 num_tuples += validate_ethter(fs);
627 ret = validate_tcpudp4(fs);
633 ret = validate_ip4(fs);
640 ret = validate_tcpudp6(fs);
646 ret = validate_ip6(fs);
654 if ((fs->flow_type & FLOW_EXT)) {
655 ret = validate_vlan(fs);
661 if (fs->flow_type & FLOW_MAC_EXT &&
662 !is_zero_ether_addr(fs->m_ext.h_dest))
669 mlx5e_ethtool_flow_replace(struct mlx5e_priv *priv,
670 struct ethtool_rx_flow_spec *fs)
672 struct mlx5e_ethtool_table *eth_ft;
673 struct mlx5e_ethtool_rule *eth_rule;
674 struct mlx5_flow_handle *rule;
678 num_tuples = validate_flow(priv, fs);
679 if (num_tuples <= 0) {
680 netdev_warn(priv->netdev, "%s: flow is not valid %d\n",
681 __func__, num_tuples);
685 eth_ft = get_flow_table(priv, fs, num_tuples);
687 return PTR_ERR(eth_ft);
689 eth_rule = get_ethtool_rule(priv, fs->location);
690 if (IS_ERR(eth_rule)) {
691 put_flow_table(eth_ft);
692 return PTR_ERR(eth_rule);
695 eth_rule->flow_spec = *fs;
696 eth_rule->eth_ft = eth_ft;
699 goto del_ethtool_rule;
701 rule = add_ethtool_flow_rule(priv, eth_ft->ft, fs);
704 goto del_ethtool_rule;
707 eth_rule->rule = rule;
712 del_ethtool_rule(priv, eth_rule);
718 mlx5e_ethtool_flow_remove(struct mlx5e_priv *priv, int location)
720 struct mlx5e_ethtool_rule *eth_rule;
723 if (location >= MAX_NUM_OF_ETHTOOL_RULES)
726 eth_rule = find_ethtool_rule(priv, location);
732 del_ethtool_rule(priv, eth_rule);
738 mlx5e_ethtool_get_flow(struct mlx5e_priv *priv,
739 struct ethtool_rxnfc *info, int location)
741 struct mlx5e_ethtool_rule *eth_rule;
743 if (location < 0 || location >= MAX_NUM_OF_ETHTOOL_RULES)
746 list_for_each_entry(eth_rule, &priv->fs.ethtool.rules, list) {
747 if (eth_rule->flow_spec.location == location) {
748 info->fs = eth_rule->flow_spec;
757 mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv,
758 struct ethtool_rxnfc *info, u32 *rule_locs)
764 info->data = MAX_NUM_OF_ETHTOOL_RULES;
765 while ((!err || err == -ENOENT) && idx < info->rule_cnt) {
766 err = mlx5e_ethtool_get_flow(priv, info, location);
768 rule_locs[idx++] = location;
774 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv)
776 struct mlx5e_ethtool_rule *iter;
777 struct mlx5e_ethtool_rule *temp;
779 list_for_each_entry_safe(iter, temp, &priv->fs.ethtool.rules, list)
780 del_ethtool_rule(priv, iter);
783 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv)
785 INIT_LIST_HEAD(&priv->fs.ethtool.rules);
788 static enum mlx5e_traffic_types flow_type_to_traffic_type(u32 flow_type)
792 return MLX5E_TT_IPV4_TCP;
794 return MLX5E_TT_IPV6_TCP;
796 return MLX5E_TT_IPV4_UDP;
798 return MLX5E_TT_IPV6_UDP;
800 return MLX5E_TT_IPV4_IPSEC_AH;
802 return MLX5E_TT_IPV6_IPSEC_AH;
804 return MLX5E_TT_IPV4_IPSEC_ESP;
806 return MLX5E_TT_IPV6_IPSEC_ESP;
808 return MLX5E_TT_IPV4;
810 return MLX5E_TT_IPV6;
812 return MLX5E_NUM_INDIR_TIRS;
816 static int mlx5e_set_rss_hash_opt(struct mlx5e_priv *priv,
817 struct ethtool_rxnfc *nfc)
819 int inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
820 enum mlx5e_traffic_types tt;
821 u8 rx_hash_field = 0;
824 tt = flow_type_to_traffic_type(nfc->flow_type);
825 if (tt == MLX5E_NUM_INDIR_TIRS)
828 /* RSS does not support anything other than hashing to queues
829 * on src IP, dest IP, TCP/UDP src port and TCP/UDP dest
832 if (nfc->flow_type != TCP_V4_FLOW &&
833 nfc->flow_type != TCP_V6_FLOW &&
834 nfc->flow_type != UDP_V4_FLOW &&
835 nfc->flow_type != UDP_V6_FLOW)
838 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
839 RXH_L4_B_0_1 | RXH_L4_B_2_3))
842 if (nfc->data & RXH_IP_SRC)
843 rx_hash_field |= MLX5_HASH_FIELD_SEL_SRC_IP;
844 if (nfc->data & RXH_IP_DST)
845 rx_hash_field |= MLX5_HASH_FIELD_SEL_DST_IP;
846 if (nfc->data & RXH_L4_B_0_1)
847 rx_hash_field |= MLX5_HASH_FIELD_SEL_L4_SPORT;
848 if (nfc->data & RXH_L4_B_2_3)
849 rx_hash_field |= MLX5_HASH_FIELD_SEL_L4_DPORT;
851 in = kvzalloc(inlen, GFP_KERNEL);
855 mutex_lock(&priv->state_lock);
857 if (rx_hash_field == priv->rss_params.rx_hash_fields[tt])
860 priv->rss_params.rx_hash_fields[tt] = rx_hash_field;
861 mlx5e_modify_tirs_hash(priv, in, inlen);
864 mutex_unlock(&priv->state_lock);
869 static int mlx5e_get_rss_hash_opt(struct mlx5e_priv *priv,
870 struct ethtool_rxnfc *nfc)
872 enum mlx5e_traffic_types tt;
875 tt = flow_type_to_traffic_type(nfc->flow_type);
876 if (tt == MLX5E_NUM_INDIR_TIRS)
879 hash_field = priv->rss_params.rx_hash_fields[tt];
882 if (hash_field & MLX5_HASH_FIELD_SEL_SRC_IP)
883 nfc->data |= RXH_IP_SRC;
884 if (hash_field & MLX5_HASH_FIELD_SEL_DST_IP)
885 nfc->data |= RXH_IP_DST;
886 if (hash_field & MLX5_HASH_FIELD_SEL_L4_SPORT)
887 nfc->data |= RXH_L4_B_0_1;
888 if (hash_field & MLX5_HASH_FIELD_SEL_L4_DPORT)
889 nfc->data |= RXH_L4_B_2_3;
894 int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
896 struct mlx5e_priv *priv = netdev_priv(dev);
900 case ETHTOOL_SRXCLSRLINS:
901 err = mlx5e_ethtool_flow_replace(priv, &cmd->fs);
903 case ETHTOOL_SRXCLSRLDEL:
904 err = mlx5e_ethtool_flow_remove(priv, cmd->fs.location);
907 err = mlx5e_set_rss_hash_opt(priv, cmd);
917 int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
918 struct ethtool_rxnfc *info, u32 *rule_locs)
920 struct mlx5e_priv *priv = netdev_priv(dev);
924 case ETHTOOL_GRXCLSRLCNT:
925 info->rule_cnt = priv->fs.ethtool.tot_num_rules;
927 case ETHTOOL_GRXCLSRULE:
928 err = mlx5e_ethtool_get_flow(priv, info, info->fs.location);
930 case ETHTOOL_GRXCLSRLALL:
931 err = mlx5e_ethtool_get_all_flows(priv, info, rule_locs);
934 err = mlx5e_get_rss_hash_opt(priv, info);