1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2019 Solarflare Communications Inc.
5 * Copyright 2020-2022 Xilinx Inc.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation, incorporated herein by reference.
12 #include <net/pkt_cls.h>
13 #include <net/vxlan.h>
14 #include <net/geneve.h>
16 #include "tc_bindings.h"
18 #include "ef100_rep.h"
21 static enum efx_encap_type efx_tc_indr_netdev_type(struct net_device *net_dev)
23 if (netif_is_vxlan(net_dev))
24 return EFX_ENCAP_TYPE_VXLAN;
25 if (netif_is_geneve(net_dev))
26 return EFX_ENCAP_TYPE_GENEVE;
28 return EFX_ENCAP_TYPE_NONE;
31 #define EFX_EFV_PF NULL
32 /* Look up the representor information (efv) for a device.
33 * May return NULL for the PF (us), or an error pointer for a device that
34 * isn't supported as a TC offload endpoint
36 static struct efx_rep *efx_tc_flower_lookup_efv(struct efx_nic *efx,
37 struct net_device *dev)
42 return ERR_PTR(-EOPNOTSUPP);
43 /* Is it us (the PF)? */
44 if (dev == efx->net_dev)
46 /* Is it an efx vfrep at all? */
47 if (dev->netdev_ops != &efx_ef100_rep_netdev_ops)
48 return ERR_PTR(-EOPNOTSUPP);
49 /* Is it ours? We don't support TC rules that include another
50 * EF100's netdevices (not even on another port of the same NIC).
52 efv = netdev_priv(dev);
53 if (efv->parent != efx)
54 return ERR_PTR(-EOPNOTSUPP);
58 /* Convert a driver-internal vport ID into an internal device (PF or VF) */
59 static s64 efx_tc_flower_internal_mport(struct efx_nic *efx, struct efx_rep *efv)
65 if (!efv) /* device is PF (us) */
66 efx_mae_mport_uplink(efx, &mport);
67 else /* device is repr */
68 efx_mae_mport_mport(efx, efv->mport, &mport);
72 /* Convert a driver-internal vport ID into an external device (wire or VF) */
73 static s64 efx_tc_flower_external_mport(struct efx_nic *efx, struct efx_rep *efv)
79 if (!efv) /* device is PF (us) */
80 efx_mae_mport_wire(efx, &mport);
81 else /* device is repr */
82 efx_mae_mport_mport(efx, efv->mport, &mport);
86 static const struct rhashtable_params efx_tc_encap_match_ht_params = {
87 .key_len = offsetof(struct efx_tc_encap_match, linkage),
89 .head_offset = offsetof(struct efx_tc_encap_match, linkage),
92 static const struct rhashtable_params efx_tc_match_action_ht_params = {
93 .key_len = sizeof(unsigned long),
94 .key_offset = offsetof(struct efx_tc_flow_rule, cookie),
95 .head_offset = offsetof(struct efx_tc_flow_rule, linkage),
98 static void efx_tc_free_action_set(struct efx_nic *efx,
99 struct efx_tc_action_set *act, bool in_hw)
101 /* Failure paths calling this on the 'cursor' action set in_hw=false,
102 * because if the alloc had succeeded we'd've put it in acts.list and
103 * not still have it in act.
106 efx_mae_free_action_set(efx, act->fw_id);
107 /* in_hw is true iff we are on an acts.list; make sure to
108 * remove ourselves from that list before we are freed.
110 list_del(&act->list);
113 efx_tc_flower_put_counter_index(efx, act->count);
117 static void efx_tc_free_action_set_list(struct efx_nic *efx,
118 struct efx_tc_action_set_list *acts,
121 struct efx_tc_action_set *act, *next;
123 /* Failure paths set in_hw=false, because usually the acts didn't get
124 * to efx_mae_alloc_action_set_list(); if they did, the failure tree
125 * has a separate efx_mae_free_action_set_list() before calling us.
128 efx_mae_free_action_set_list(efx, acts);
129 /* Any act that's on the list will be in_hw even if the list isn't */
130 list_for_each_entry_safe(act, next, &acts->list, list)
131 efx_tc_free_action_set(efx, act, true);
132 /* Don't kfree, as acts is embedded inside a struct efx_tc_flow_rule */
135 static void efx_tc_flow_free(void *ptr, void *arg)
137 struct efx_tc_flow_rule *rule = ptr;
138 struct efx_nic *efx = arg;
140 netif_err(efx, drv, efx->net_dev,
141 "tc rule %lx still present at teardown, removing\n",
144 efx_mae_delete_rule(efx, rule->fw_id);
146 /* Release entries in subsidiary tables */
147 efx_tc_free_action_set_list(efx, &rule->acts, true);
152 /* Boilerplate for the simple 'copy a field' cases */
153 #define _MAP_KEY_AND_MASK(_name, _type, _tcget, _tcfield, _field) \
154 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_##_name)) { \
155 struct flow_match_##_type fm; \
157 flow_rule_match_##_tcget(rule, &fm); \
158 match->value._field = fm.key->_tcfield; \
159 match->mask._field = fm.mask->_tcfield; \
161 #define MAP_KEY_AND_MASK(_name, _type, _tcfield, _field) \
162 _MAP_KEY_AND_MASK(_name, _type, _type, _tcfield, _field)
163 #define MAP_ENC_KEY_AND_MASK(_name, _type, _tcget, _tcfield, _field) \
164 _MAP_KEY_AND_MASK(ENC_##_name, _type, _tcget, _tcfield, _field)
166 static int efx_tc_flower_parse_match(struct efx_nic *efx,
167 struct flow_rule *rule,
168 struct efx_tc_match *match,
169 struct netlink_ext_ack *extack)
171 struct flow_dissector *dissector = rule->match.dissector;
172 unsigned char ipv = 0;
174 /* Owing to internal TC infelicities, the IPV6_ADDRS key might be set
175 * even on IPv4 filters; so rather than relying on dissector->used_keys
176 * we check the addr_type in the CONTROL key. If we don't find it (or
177 * it's masked, which should never happen), we treat both IPV4_ADDRS
178 * and IPV6_ADDRS as absent.
180 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
181 struct flow_match_control fm;
183 flow_rule_match_control(rule, &fm);
184 if (IS_ALL_ONES(fm.mask->addr_type))
185 switch (fm.key->addr_type) {
186 case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
189 case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
196 if (fm.mask->flags & FLOW_DIS_IS_FRAGMENT) {
197 match->value.ip_frag = fm.key->flags & FLOW_DIS_IS_FRAGMENT;
198 match->mask.ip_frag = true;
200 if (fm.mask->flags & FLOW_DIS_FIRST_FRAG) {
201 match->value.ip_firstfrag = fm.key->flags & FLOW_DIS_FIRST_FRAG;
202 match->mask.ip_firstfrag = true;
204 if (fm.mask->flags & ~(FLOW_DIS_IS_FRAGMENT | FLOW_DIS_FIRST_FRAG)) {
205 NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported match on control.flags %#x",
210 if (dissector->used_keys &
211 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
212 BIT(FLOW_DISSECTOR_KEY_BASIC) |
213 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
214 BIT(FLOW_DISSECTOR_KEY_VLAN) |
215 BIT(FLOW_DISSECTOR_KEY_CVLAN) |
216 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
217 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
218 BIT(FLOW_DISSECTOR_KEY_PORTS) |
219 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID) |
220 BIT(FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS) |
221 BIT(FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS) |
222 BIT(FLOW_DISSECTOR_KEY_ENC_PORTS) |
223 BIT(FLOW_DISSECTOR_KEY_ENC_CONTROL) |
224 BIT(FLOW_DISSECTOR_KEY_TCP) |
225 BIT(FLOW_DISSECTOR_KEY_IP))) {
226 NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported flower keys %#x",
227 dissector->used_keys);
231 MAP_KEY_AND_MASK(BASIC, basic, n_proto, eth_proto);
232 /* Make sure we're IP if any L3/L4 keys used. */
233 if (!IS_ALL_ONES(match->mask.eth_proto) ||
234 !(match->value.eth_proto == htons(ETH_P_IP) ||
235 match->value.eth_proto == htons(ETH_P_IPV6)))
236 if (dissector->used_keys &
237 (BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
238 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
239 BIT(FLOW_DISSECTOR_KEY_PORTS) |
240 BIT(FLOW_DISSECTOR_KEY_IP) |
241 BIT(FLOW_DISSECTOR_KEY_TCP))) {
242 NL_SET_ERR_MSG_FMT_MOD(extack, "L3/L4 flower keys %#x require protocol ipv[46]",
243 dissector->used_keys);
247 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
248 struct flow_match_vlan fm;
250 flow_rule_match_vlan(rule, &fm);
251 if (fm.mask->vlan_id || fm.mask->vlan_priority || fm.mask->vlan_tpid) {
252 match->value.vlan_proto[0] = fm.key->vlan_tpid;
253 match->mask.vlan_proto[0] = fm.mask->vlan_tpid;
254 match->value.vlan_tci[0] = cpu_to_be16(fm.key->vlan_priority << 13 |
256 match->mask.vlan_tci[0] = cpu_to_be16(fm.mask->vlan_priority << 13 |
261 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CVLAN)) {
262 struct flow_match_vlan fm;
264 flow_rule_match_cvlan(rule, &fm);
265 if (fm.mask->vlan_id || fm.mask->vlan_priority || fm.mask->vlan_tpid) {
266 match->value.vlan_proto[1] = fm.key->vlan_tpid;
267 match->mask.vlan_proto[1] = fm.mask->vlan_tpid;
268 match->value.vlan_tci[1] = cpu_to_be16(fm.key->vlan_priority << 13 |
270 match->mask.vlan_tci[1] = cpu_to_be16(fm.mask->vlan_priority << 13 |
275 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
276 struct flow_match_eth_addrs fm;
278 flow_rule_match_eth_addrs(rule, &fm);
279 ether_addr_copy(match->value.eth_saddr, fm.key->src);
280 ether_addr_copy(match->value.eth_daddr, fm.key->dst);
281 ether_addr_copy(match->mask.eth_saddr, fm.mask->src);
282 ether_addr_copy(match->mask.eth_daddr, fm.mask->dst);
285 MAP_KEY_AND_MASK(BASIC, basic, ip_proto, ip_proto);
286 /* Make sure we're TCP/UDP if any L4 keys used. */
287 if ((match->value.ip_proto != IPPROTO_UDP &&
288 match->value.ip_proto != IPPROTO_TCP) || !IS_ALL_ONES(match->mask.ip_proto))
289 if (dissector->used_keys &
290 (BIT(FLOW_DISSECTOR_KEY_PORTS) |
291 BIT(FLOW_DISSECTOR_KEY_TCP))) {
292 NL_SET_ERR_MSG_FMT_MOD(extack, "L4 flower keys %#x require ipproto udp or tcp",
293 dissector->used_keys);
296 MAP_KEY_AND_MASK(IP, ip, tos, ip_tos);
297 MAP_KEY_AND_MASK(IP, ip, ttl, ip_ttl);
299 MAP_KEY_AND_MASK(IPV4_ADDRS, ipv4_addrs, src, src_ip);
300 MAP_KEY_AND_MASK(IPV4_ADDRS, ipv4_addrs, dst, dst_ip);
304 MAP_KEY_AND_MASK(IPV6_ADDRS, ipv6_addrs, src, src_ip6);
305 MAP_KEY_AND_MASK(IPV6_ADDRS, ipv6_addrs, dst, dst_ip6);
308 MAP_KEY_AND_MASK(PORTS, ports, src, l4_sport);
309 MAP_KEY_AND_MASK(PORTS, ports, dst, l4_dport);
310 MAP_KEY_AND_MASK(TCP, tcp, flags, tcp_flags);
311 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL)) {
312 struct flow_match_control fm;
314 flow_rule_match_enc_control(rule, &fm);
315 if (fm.mask->flags) {
316 NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported match on enc_control.flags %#x",
320 if (!IS_ALL_ONES(fm.mask->addr_type)) {
321 NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported enc addr_type mask %u (key %u)",
326 switch (fm.key->addr_type) {
327 case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
328 MAP_ENC_KEY_AND_MASK(IPV4_ADDRS, ipv4_addrs, enc_ipv4_addrs,
330 MAP_ENC_KEY_AND_MASK(IPV4_ADDRS, ipv4_addrs, enc_ipv4_addrs,
334 case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
335 MAP_ENC_KEY_AND_MASK(IPV6_ADDRS, ipv6_addrs, enc_ipv6_addrs,
337 MAP_ENC_KEY_AND_MASK(IPV6_ADDRS, ipv6_addrs, enc_ipv6_addrs,
342 NL_SET_ERR_MSG_FMT_MOD(extack,
343 "Unsupported enc addr_type %u (supported are IPv4, IPv6)",
347 MAP_ENC_KEY_AND_MASK(IP, ip, enc_ip, tos, enc_ip_tos);
348 MAP_ENC_KEY_AND_MASK(IP, ip, enc_ip, ttl, enc_ip_ttl);
349 MAP_ENC_KEY_AND_MASK(PORTS, ports, enc_ports, src, enc_sport);
350 MAP_ENC_KEY_AND_MASK(PORTS, ports, enc_ports, dst, enc_dport);
351 MAP_ENC_KEY_AND_MASK(KEYID, enc_keyid, enc_keyid, keyid, enc_keyid);
352 } else if (dissector->used_keys &
353 (BIT(FLOW_DISSECTOR_KEY_ENC_KEYID) |
354 BIT(FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS) |
355 BIT(FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS) |
356 BIT(FLOW_DISSECTOR_KEY_ENC_IP) |
357 BIT(FLOW_DISSECTOR_KEY_ENC_PORTS))) {
358 NL_SET_ERR_MSG_FMT_MOD(extack, "Flower enc keys require enc_control (keys: %#x)",
359 dissector->used_keys);
366 static int efx_tc_flower_record_encap_match(struct efx_nic *efx,
367 struct efx_tc_match *match,
368 enum efx_encap_type type,
369 struct netlink_ext_ack *extack)
371 struct efx_tc_encap_match *encap, *old;
375 /* We require that the socket-defining fields (IP addrs and UDP dest
376 * port) are present and exact-match. Other fields are currently not
377 * allowed. This meets what OVS will ask for, and means that we don't
378 * need to handle difficult checks for overlapping matches as could
379 * come up if we allowed masks or varying sets of match fields.
381 if (match->mask.enc_dst_ip | match->mask.enc_src_ip) {
382 if (!IS_ALL_ONES(match->mask.enc_dst_ip)) {
383 NL_SET_ERR_MSG_MOD(extack,
384 "Egress encap match is not exact on dst IP address");
387 if (!IS_ALL_ONES(match->mask.enc_src_ip)) {
388 NL_SET_ERR_MSG_MOD(extack,
389 "Egress encap match is not exact on src IP address");
393 if (!ipv6_addr_any(&match->mask.enc_dst_ip6) ||
394 !ipv6_addr_any(&match->mask.enc_src_ip6)) {
395 NL_SET_ERR_MSG_MOD(extack,
396 "Egress encap match on both IPv4 and IPv6, don't understand");
401 if (!efx_ipv6_addr_all_ones(&match->mask.enc_dst_ip6)) {
402 NL_SET_ERR_MSG_MOD(extack,
403 "Egress encap match is not exact on dst IP address");
406 if (!efx_ipv6_addr_all_ones(&match->mask.enc_src_ip6)) {
407 NL_SET_ERR_MSG_MOD(extack,
408 "Egress encap match is not exact on src IP address");
413 if (!IS_ALL_ONES(match->mask.enc_dport)) {
414 NL_SET_ERR_MSG_MOD(extack, "Egress encap match is not exact on dst UDP port");
417 if (match->mask.enc_sport) {
418 NL_SET_ERR_MSG_MOD(extack, "Egress encap match on src UDP port not supported");
421 if (match->mask.enc_ip_tos) {
422 NL_SET_ERR_MSG_MOD(extack, "Egress encap match on IP ToS not supported");
425 if (match->mask.enc_ip_ttl) {
426 NL_SET_ERR_MSG_MOD(extack, "Egress encap match on IP TTL not supported");
430 rc = efx_mae_check_encap_match_caps(efx, ipv6, extack);
432 NL_SET_ERR_MSG_FMT_MOD(extack, "MAE hw reports no support for IPv%d encap matches",
437 encap = kzalloc(sizeof(*encap), GFP_USER);
440 encap->src_ip = match->value.enc_src_ip;
441 encap->dst_ip = match->value.enc_dst_ip;
443 encap->src_ip6 = match->value.enc_src_ip6;
444 encap->dst_ip6 = match->value.enc_dst_ip6;
446 encap->udp_dport = match->value.enc_dport;
447 encap->tun_type = type;
448 old = rhashtable_lookup_get_insert_fast(&efx->tc->encap_match_ht,
450 efx_tc_encap_match_ht_params);
452 /* don't need our new entry */
454 if (old->tun_type != type) {
455 NL_SET_ERR_MSG_FMT_MOD(extack,
456 "Egress encap match with conflicting tun_type %u != %u",
457 old->tun_type, type);
460 if (!refcount_inc_not_zero(&old->ref))
462 /* existing entry found */
465 rc = efx_mae_register_encap_match(efx, encap);
467 NL_SET_ERR_MSG_MOD(extack, "Failed to record egress encap match in HW");
470 refcount_set(&encap->ref, 1);
472 match->encap = encap;
475 rhashtable_remove_fast(&efx->tc->encap_match_ht, &encap->linkage,
476 efx_tc_encap_match_ht_params);
481 static void efx_tc_flower_release_encap_match(struct efx_nic *efx,
482 struct efx_tc_encap_match *encap)
486 if (!refcount_dec_and_test(&encap->ref))
487 return; /* still in use */
489 rc = efx_mae_unregister_encap_match(efx, encap);
491 /* Display message but carry on and remove entry from our
492 * SW tables, because there's not much we can do about it.
494 netif_err(efx, drv, efx->net_dev,
495 "Failed to release encap match %#x, rc %d\n",
497 rhashtable_remove_fast(&efx->tc->encap_match_ht, &encap->linkage,
498 efx_tc_encap_match_ht_params);
502 static void efx_tc_delete_rule(struct efx_nic *efx, struct efx_tc_flow_rule *rule)
504 efx_mae_delete_rule(efx, rule->fw_id);
506 /* Release entries in subsidiary tables */
507 efx_tc_free_action_set_list(efx, &rule->acts, true);
508 if (rule->match.encap)
509 efx_tc_flower_release_encap_match(efx, rule->match.encap);
510 rule->fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
513 static const char *efx_tc_encap_type_name(enum efx_encap_type typ)
516 case EFX_ENCAP_TYPE_NONE:
518 case EFX_ENCAP_TYPE_VXLAN:
520 case EFX_ENCAP_TYPE_GENEVE:
523 pr_warn_once("Unknown efx_encap_type %d encountered\n", typ);
528 /* For details of action order constraints refer to SF-123102-TC-1§12.6.1 */
529 enum efx_tc_action_order {
536 /* Determine whether we can add @new action without violating order */
537 static bool efx_tc_flower_action_order_ok(const struct efx_tc_action_set *act,
538 enum efx_tc_action_order new)
541 case EFX_TC_AO_DECAP:
545 case EFX_TC_AO_VLAN_POP:
546 if (act->vlan_pop >= 2)
548 /* If we've already pushed a VLAN, we can't then pop it;
549 * the hardware would instead try to pop an existing VLAN
550 * before pushing the new one.
555 case EFX_TC_AO_VLAN_PUSH:
556 if (act->vlan_push >= 2)
559 case EFX_TC_AO_COUNT:
563 case EFX_TC_AO_DELIVER:
564 return !act->deliver;
566 /* Bad caller. Whatever they wanted to do, say they can't. */
572 static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
573 struct net_device *net_dev,
574 struct flow_cls_offload *tc)
576 struct flow_rule *fr = flow_cls_offload_flow_rule(tc);
577 struct netlink_ext_ack *extack = tc->common.extack;
578 struct efx_tc_flow_rule *rule = NULL, *old = NULL;
579 struct efx_tc_action_set *act = NULL;
580 bool found = false, uplinked = false;
581 const struct flow_action_entry *fa;
582 struct efx_tc_match match;
583 struct efx_rep *to_efv;
588 memset(&match, 0, sizeof(match));
589 rc = efx_tc_flower_parse_match(efx, fr, &match, NULL);
592 /* The rule as given to us doesn't specify a source netdevice.
593 * But, determining whether packets from a VF should match it is
594 * complicated, so leave those to the software slowpath: qualify
595 * the filter with source m-port == wire.
597 rc = efx_tc_flower_external_mport(efx, EFX_EFV_PF);
599 NL_SET_ERR_MSG_MOD(extack, "Failed to identify ingress m-port for foreign filter");
602 match.value.ingress_port = rc;
603 match.mask.ingress_port = ~0;
605 if (tc->common.chain_index) {
606 NL_SET_ERR_MSG_MOD(extack, "No support for nonzero chain_index");
609 match.mask.recirc_id = 0xff;
611 flow_action_for_each(i, fa, &fr->action) {
613 case FLOW_ACTION_REDIRECT:
614 case FLOW_ACTION_MIRRED: /* mirred means mirror here */
615 to_efv = efx_tc_flower_lookup_efv(efx, fa->dev);
624 if (!found) { /* We don't care. */
625 netif_dbg(efx, drv, efx->net_dev,
626 "Ignoring foreign filter that doesn't egdev us\n");
631 rc = efx_mae_match_check_caps(efx, &match.mask, NULL);
635 if (efx_tc_match_is_encap(&match.mask)) {
636 enum efx_encap_type type;
638 type = efx_tc_indr_netdev_type(net_dev);
639 if (type == EFX_ENCAP_TYPE_NONE) {
640 NL_SET_ERR_MSG_MOD(extack,
641 "Egress encap match on unsupported tunnel device");
646 rc = efx_mae_check_encap_type_supported(efx, type);
648 NL_SET_ERR_MSG_FMT_MOD(extack,
649 "Firmware reports no support for %s encap match",
650 efx_tc_encap_type_name(type));
654 rc = efx_tc_flower_record_encap_match(efx, &match, type,
659 /* This is not a tunnel decap rule, ignore it */
660 netif_dbg(efx, drv, efx->net_dev,
661 "Ignoring foreign filter without encap match\n");
666 rule = kzalloc(sizeof(*rule), GFP_USER);
671 INIT_LIST_HEAD(&rule->acts.list);
672 rule->cookie = tc->cookie;
673 old = rhashtable_lookup_get_insert_fast(&efx->tc->match_action_ht,
675 efx_tc_match_action_ht_params);
677 netif_dbg(efx, drv, efx->net_dev,
678 "Ignoring already-offloaded rule (cookie %lx)\n",
684 act = kzalloc(sizeof(*act), GFP_USER);
690 /* Parse actions. For foreign rules we only support decap & redirect.
691 * See corresponding code in efx_tc_flower_replace() for theory of
692 * operation & how 'act' cursor is used.
694 flow_action_for_each(i, fa, &fr->action) {
695 struct efx_tc_action_set save;
698 case FLOW_ACTION_REDIRECT:
699 case FLOW_ACTION_MIRRED:
700 /* See corresponding code in efx_tc_flower_replace() for
701 * long explanations of what's going on here.
705 struct efx_tc_counter_index *ctr;
707 if (!(fa->hw_stats & FLOW_ACTION_HW_STATS_DELAYED)) {
708 NL_SET_ERR_MSG_FMT_MOD(extack,
709 "hw_stats_type %u not supported (only 'delayed')",
714 if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_COUNT)) {
719 ctr = efx_tc_flower_get_counter_index(efx,
721 EFX_TC_COUNTER_TYPE_AR);
724 NL_SET_ERR_MSG_MOD(extack, "Failed to obtain a counter");
730 if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_DELIVER)) {
733 NL_SET_ERR_MSG_MOD(extack,
734 "Deliver action violates action order (can't happen)");
737 to_efv = efx_tc_flower_lookup_efv(efx, fa->dev);
738 /* PF implies egdev is us, in which case we really
739 * want to deliver to the uplink (because this is an
740 * ingress filter). If we don't recognise the egdev
741 * at all, then we'd better trap so SW can handle it.
745 if (to_efv == EFX_EFV_PF) {
750 rc = efx_tc_flower_internal_mport(efx, to_efv);
752 NL_SET_ERR_MSG_MOD(extack, "Failed to identify egress m-port");
755 act->dest_mport = rc;
757 rc = efx_mae_alloc_action_set(efx, act);
759 NL_SET_ERR_MSG_MOD(extack,
760 "Failed to write action set to hw (mirred)");
763 list_add_tail(&act->list, &rule->acts.list);
765 if (fa->id == FLOW_ACTION_REDIRECT)
766 break; /* end of the line */
767 /* Mirror, so continue on with saved act */
768 act = kzalloc(sizeof(*act), GFP_USER);
775 case FLOW_ACTION_TUNNEL_DECAP:
776 if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_DECAP)) {
778 NL_SET_ERR_MSG_MOD(extack, "Decap action violates action order");
782 /* If we previously delivered/trapped to uplink, now
783 * that we've decapped we'll want another copy if we
784 * try to deliver/trap to uplink again.
789 NL_SET_ERR_MSG_FMT_MOD(extack, "Unhandled action %u",
798 /* Not shot/redirected, so deliver to default dest (which is
799 * the uplink, as this is an ingress filter)
801 efx_mae_mport_uplink(efx, &act->dest_mport);
804 rc = efx_mae_alloc_action_set(efx, act);
806 NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (deliver)");
809 list_add_tail(&act->list, &rule->acts.list);
810 act = NULL; /* Prevent double-free in error path */
815 netif_dbg(efx, drv, efx->net_dev,
816 "Successfully parsed foreign filter (cookie %lx)\n",
819 rc = efx_mae_alloc_action_set_list(efx, &rule->acts);
821 NL_SET_ERR_MSG_MOD(extack, "Failed to write action set list to hw");
824 rc = efx_mae_insert_rule(efx, &rule->match, EFX_TC_PRIO_TC,
825 rule->acts.fw_id, &rule->fw_id);
827 NL_SET_ERR_MSG_MOD(extack, "Failed to insert rule in hw");
833 efx_mae_free_action_set_list(efx, &rule->acts);
835 /* We failed to insert the rule, so free up any entries we created in
839 efx_tc_free_action_set(efx, act, false);
841 rhashtable_remove_fast(&efx->tc->match_action_ht,
843 efx_tc_match_action_ht_params);
844 efx_tc_free_action_set_list(efx, &rule->acts, false);
848 efx_tc_flower_release_encap_match(efx, match.encap);
852 static int efx_tc_flower_replace(struct efx_nic *efx,
853 struct net_device *net_dev,
854 struct flow_cls_offload *tc,
857 struct flow_rule *fr = flow_cls_offload_flow_rule(tc);
858 struct netlink_ext_ack *extack = tc->common.extack;
859 struct efx_tc_flow_rule *rule = NULL, *old;
860 struct efx_tc_action_set *act = NULL;
861 const struct flow_action_entry *fa;
862 struct efx_rep *from_efv, *to_efv;
863 struct efx_tc_match match;
867 if (!tc_can_offload_extack(efx->net_dev, extack))
869 if (WARN_ON(!efx->tc))
871 if (WARN_ON(!efx->tc->up))
874 from_efv = efx_tc_flower_lookup_efv(efx, net_dev);
875 if (IS_ERR(from_efv)) {
876 /* Not from our PF or representors, so probably a tunnel dev */
877 return efx_tc_flower_replace_foreign(efx, net_dev, tc);
880 if (efv != from_efv) {
882 NL_SET_ERR_MSG_FMT_MOD(extack, "for %s efv is %snull but from_efv is %snull (can't happen)",
883 netdev_name(net_dev), efv ? "non-" : "",
884 from_efv ? "non-" : "");
889 memset(&match, 0, sizeof(match));
890 rc = efx_tc_flower_external_mport(efx, from_efv);
892 NL_SET_ERR_MSG_MOD(extack, "Failed to identify ingress m-port");
895 match.value.ingress_port = rc;
896 match.mask.ingress_port = ~0;
897 rc = efx_tc_flower_parse_match(efx, fr, &match, extack);
900 if (efx_tc_match_is_encap(&match.mask)) {
901 NL_SET_ERR_MSG_MOD(extack, "Ingress enc_key matches not supported");
906 if (tc->common.chain_index) {
907 NL_SET_ERR_MSG_MOD(extack, "No support for nonzero chain_index");
910 match.mask.recirc_id = 0xff;
912 rc = efx_mae_match_check_caps(efx, &match.mask, extack);
916 rule = kzalloc(sizeof(*rule), GFP_USER);
919 INIT_LIST_HEAD(&rule->acts.list);
920 rule->cookie = tc->cookie;
921 old = rhashtable_lookup_get_insert_fast(&efx->tc->match_action_ht,
923 efx_tc_match_action_ht_params);
925 netif_dbg(efx, drv, efx->net_dev,
926 "Already offloaded rule (cookie %lx)\n", tc->cookie);
928 NL_SET_ERR_MSG_MOD(extack, "Rule already offloaded");
933 act = kzalloc(sizeof(*act), GFP_USER);
940 * DOC: TC action translation
942 * Actions in TC are sequential and cumulative, with delivery actions
943 * potentially anywhere in the order. The EF100 MAE, however, takes
944 * an 'action set list' consisting of 'action sets', each of which is
945 * applied to the _original_ packet, and consists of a set of optional
946 * actions in a fixed order with delivery at the end.
947 * To translate between these two models, we maintain a 'cursor', @act,
948 * which describes the cumulative effect of all the packet-mutating
949 * actions encountered so far; on handling a delivery (mirred or drop)
950 * action, once the action-set has been inserted into hardware, we
951 * append @act to the action-set list (@rule->acts); if this is a pipe
952 * action (mirred mirror) we then allocate a new @act with a copy of
953 * the cursor state _before_ the delivery action, otherwise we set @act
955 * This ensures that every allocated action-set is either attached to
956 * @rule->acts or pointed to by @act (and never both), and that only
957 * those action-sets in @rule->acts exist in hardware. Consequently,
958 * in the failure path, @act only needs to be freed in memory, whereas
959 * for @rule->acts we remove each action-set from hardware before
960 * freeing it (efx_tc_free_action_set_list()), even if the action-set
961 * list itself is not in hardware.
963 flow_action_for_each(i, fa, &fr->action) {
964 struct efx_tc_action_set save;
968 /* more actions after a non-pipe action */
969 NL_SET_ERR_MSG_MOD(extack, "Action follows non-pipe action");
974 if ((fa->id == FLOW_ACTION_REDIRECT ||
975 fa->id == FLOW_ACTION_MIRRED ||
976 fa->id == FLOW_ACTION_DROP) && fa->hw_stats) {
977 struct efx_tc_counter_index *ctr;
979 /* Currently the only actions that want stats are
980 * mirred and gact (ok, shot, trap, goto-chain), which
981 * means we want stats just before delivery. Also,
982 * note that tunnel_key set shouldn't change the length
983 * — it's only the subsequent mirred that does that,
984 * and the stats are taken _before_ the mirred action
987 if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_COUNT)) {
988 /* All supported actions that count either steal
989 * (gact shot, mirred redirect) or clone act
990 * (mirred mirror), so we should never get two
991 * count actions on one action_set.
993 NL_SET_ERR_MSG_MOD(extack, "Count-action conflict (can't happen)");
998 if (!(fa->hw_stats & FLOW_ACTION_HW_STATS_DELAYED)) {
999 NL_SET_ERR_MSG_FMT_MOD(extack, "hw_stats_type %u not supported (only 'delayed')",
1005 ctr = efx_tc_flower_get_counter_index(efx, tc->cookie,
1006 EFX_TC_COUNTER_TYPE_AR);
1009 NL_SET_ERR_MSG_MOD(extack, "Failed to obtain a counter");
1016 case FLOW_ACTION_DROP:
1017 rc = efx_mae_alloc_action_set(efx, act);
1019 NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (drop)");
1022 list_add_tail(&act->list, &rule->acts.list);
1023 act = NULL; /* end of the line */
1025 case FLOW_ACTION_REDIRECT:
1026 case FLOW_ACTION_MIRRED:
1029 if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_DELIVER)) {
1032 NL_SET_ERR_MSG_MOD(extack, "Deliver action violates action order (can't happen)");
1036 to_efv = efx_tc_flower_lookup_efv(efx, fa->dev);
1037 if (IS_ERR(to_efv)) {
1038 NL_SET_ERR_MSG_MOD(extack, "Mirred egress device not on switch");
1039 rc = PTR_ERR(to_efv);
1042 rc = efx_tc_flower_external_mport(efx, to_efv);
1044 NL_SET_ERR_MSG_MOD(extack, "Failed to identify egress m-port");
1047 act->dest_mport = rc;
1049 rc = efx_mae_alloc_action_set(efx, act);
1051 NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (mirred)");
1054 list_add_tail(&act->list, &rule->acts.list);
1056 if (fa->id == FLOW_ACTION_REDIRECT)
1057 break; /* end of the line */
1058 /* Mirror, so continue on with saved act */
1060 act = kzalloc(sizeof(*act), GFP_USER);
1067 case FLOW_ACTION_VLAN_POP:
1068 if (act->vlan_push) {
1070 } else if (efx_tc_flower_action_order_ok(act, EFX_TC_AO_VLAN_POP)) {
1073 NL_SET_ERR_MSG_MOD(extack,
1074 "More than two VLAN pops, or action order violated");
1079 case FLOW_ACTION_VLAN_PUSH:
1080 if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_VLAN_PUSH)) {
1082 NL_SET_ERR_MSG_MOD(extack,
1083 "More than two VLAN pushes, or action order violated");
1086 tci = fa->vlan.vid & VLAN_VID_MASK;
1087 tci |= fa->vlan.prio << VLAN_PRIO_SHIFT;
1088 act->vlan_tci[act->vlan_push] = cpu_to_be16(tci);
1089 act->vlan_proto[act->vlan_push] = fa->vlan.proto;
1093 NL_SET_ERR_MSG_FMT_MOD(extack, "Unhandled action %u",
1101 /* Not shot/redirected, so deliver to default dest */
1102 if (from_efv == EFX_EFV_PF)
1103 /* Rule applies to traffic from the wire,
1104 * and default dest is thus the PF
1106 efx_mae_mport_uplink(efx, &act->dest_mport);
1108 /* Representor, so rule applies to traffic from
1109 * representee, and default dest is thus the rep.
1110 * All reps use the same mport for delivery
1112 efx_mae_mport_mport(efx, efx->tc->reps_mport_id,
1115 rc = efx_mae_alloc_action_set(efx, act);
1117 NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (deliver)");
1120 list_add_tail(&act->list, &rule->acts.list);
1121 act = NULL; /* Prevent double-free in error path */
1124 netif_dbg(efx, drv, efx->net_dev,
1125 "Successfully parsed filter (cookie %lx)\n",
1128 rule->match = match;
1130 rc = efx_mae_alloc_action_set_list(efx, &rule->acts);
1132 NL_SET_ERR_MSG_MOD(extack, "Failed to write action set list to hw");
1135 rc = efx_mae_insert_rule(efx, &rule->match, EFX_TC_PRIO_TC,
1136 rule->acts.fw_id, &rule->fw_id);
1138 NL_SET_ERR_MSG_MOD(extack, "Failed to insert rule in hw");
1144 efx_mae_free_action_set_list(efx, &rule->acts);
1146 /* We failed to insert the rule, so free up any entries we created in
1147 * subsidiary tables.
1150 efx_tc_free_action_set(efx, act, false);
1152 rhashtable_remove_fast(&efx->tc->match_action_ht,
1154 efx_tc_match_action_ht_params);
1155 efx_tc_free_action_set_list(efx, &rule->acts, false);
1161 static int efx_tc_flower_destroy(struct efx_nic *efx,
1162 struct net_device *net_dev,
1163 struct flow_cls_offload *tc)
1165 struct netlink_ext_ack *extack = tc->common.extack;
1166 struct efx_tc_flow_rule *rule;
1168 rule = rhashtable_lookup_fast(&efx->tc->match_action_ht, &tc->cookie,
1169 efx_tc_match_action_ht_params);
1171 /* Only log a message if we're the ingress device. Otherwise
1172 * it's a foreign filter and we might just not have been
1173 * interested (e.g. we might not have been the egress device
1176 if (!IS_ERR(efx_tc_flower_lookup_efv(efx, net_dev)))
1177 netif_warn(efx, drv, efx->net_dev,
1178 "Filter %lx not found to remove\n", tc->cookie);
1179 NL_SET_ERR_MSG_MOD(extack, "Flow cookie not found in offloaded rules");
1183 /* Remove it from HW */
1184 efx_tc_delete_rule(efx, rule);
1185 /* Delete it from SW */
1186 rhashtable_remove_fast(&efx->tc->match_action_ht, &rule->linkage,
1187 efx_tc_match_action_ht_params);
1188 netif_dbg(efx, drv, efx->net_dev, "Removed filter %lx\n", rule->cookie);
1193 static int efx_tc_flower_stats(struct efx_nic *efx, struct net_device *net_dev,
1194 struct flow_cls_offload *tc)
1196 struct netlink_ext_ack *extack = tc->common.extack;
1197 struct efx_tc_counter_index *ctr;
1198 struct efx_tc_counter *cnt;
1201 ctr = efx_tc_flower_find_counter_index(efx, tc->cookie);
1203 /* See comment in efx_tc_flower_destroy() */
1204 if (!IS_ERR(efx_tc_flower_lookup_efv(efx, net_dev)))
1205 if (net_ratelimit())
1206 netif_warn(efx, drv, efx->net_dev,
1207 "Filter %lx not found for stats\n",
1209 NL_SET_ERR_MSG_MOD(extack, "Flow cookie not found in offloaded rules");
1212 if (WARN_ON(!ctr->cnt)) /* can't happen */
1216 spin_lock_bh(&cnt->lock);
1217 /* Report only new pkts/bytes since last time TC asked */
1218 packets = cnt->packets;
1220 flow_stats_update(&tc->stats, bytes - cnt->old_bytes,
1221 packets - cnt->old_packets, 0, cnt->touched,
1222 FLOW_ACTION_HW_STATS_DELAYED);
1223 cnt->old_packets = packets;
1224 cnt->old_bytes = bytes;
1225 spin_unlock_bh(&cnt->lock);
1229 int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev,
1230 struct flow_cls_offload *tc, struct efx_rep *efv)
1237 mutex_lock(&efx->tc->mutex);
1238 switch (tc->command) {
1239 case FLOW_CLS_REPLACE:
1240 rc = efx_tc_flower_replace(efx, net_dev, tc, efv);
1242 case FLOW_CLS_DESTROY:
1243 rc = efx_tc_flower_destroy(efx, net_dev, tc);
1245 case FLOW_CLS_STATS:
1246 rc = efx_tc_flower_stats(efx, net_dev, tc);
1252 mutex_unlock(&efx->tc->mutex);
1256 static int efx_tc_configure_default_rule(struct efx_nic *efx, u32 ing_port,
1257 u32 eg_port, struct efx_tc_flow_rule *rule)
1259 struct efx_tc_action_set_list *acts = &rule->acts;
1260 struct efx_tc_match *match = &rule->match;
1261 struct efx_tc_action_set *act;
1264 match->value.ingress_port = ing_port;
1265 match->mask.ingress_port = ~0;
1266 act = kzalloc(sizeof(*act), GFP_KERNEL);
1270 act->dest_mport = eg_port;
1271 rc = efx_mae_alloc_action_set(efx, act);
1274 EFX_WARN_ON_PARANOID(!list_empty(&acts->list));
1275 list_add_tail(&act->list, &acts->list);
1276 rc = efx_mae_alloc_action_set_list(efx, acts);
1279 rc = efx_mae_insert_rule(efx, match, EFX_TC_PRIO_DFLT,
1280 acts->fw_id, &rule->fw_id);
1285 efx_mae_free_action_set_list(efx, acts);
1287 list_del(&act->list);
1288 efx_mae_free_action_set(efx, act->fw_id);
1294 static int efx_tc_configure_default_rule_pf(struct efx_nic *efx)
1296 struct efx_tc_flow_rule *rule = &efx->tc->dflt.pf;
1297 u32 ing_port, eg_port;
1299 efx_mae_mport_uplink(efx, &ing_port);
1300 efx_mae_mport_wire(efx, &eg_port);
1301 return efx_tc_configure_default_rule(efx, ing_port, eg_port, rule);
1304 static int efx_tc_configure_default_rule_wire(struct efx_nic *efx)
1306 struct efx_tc_flow_rule *rule = &efx->tc->dflt.wire;
1307 u32 ing_port, eg_port;
1309 efx_mae_mport_wire(efx, &ing_port);
1310 efx_mae_mport_uplink(efx, &eg_port);
1311 return efx_tc_configure_default_rule(efx, ing_port, eg_port, rule);
1314 int efx_tc_configure_default_rule_rep(struct efx_rep *efv)
1316 struct efx_tc_flow_rule *rule = &efv->dflt;
1317 struct efx_nic *efx = efv->parent;
1318 u32 ing_port, eg_port;
1320 efx_mae_mport_mport(efx, efv->mport, &ing_port);
1321 efx_mae_mport_mport(efx, efx->tc->reps_mport_id, &eg_port);
1322 return efx_tc_configure_default_rule(efx, ing_port, eg_port, rule);
1325 void efx_tc_deconfigure_default_rule(struct efx_nic *efx,
1326 struct efx_tc_flow_rule *rule)
1328 if (rule->fw_id != MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL)
1329 efx_tc_delete_rule(efx, rule);
1330 rule->fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
1333 static int efx_tc_configure_rep_mport(struct efx_nic *efx)
1335 u32 rep_mport_label;
1338 rc = efx_mae_allocate_mport(efx, &efx->tc->reps_mport_id, &rep_mport_label);
1341 pci_dbg(efx->pci_dev, "created rep mport 0x%08x (0x%04x)\n",
1342 efx->tc->reps_mport_id, rep_mport_label);
1343 /* Use mport *selector* as vport ID */
1344 efx_mae_mport_mport(efx, efx->tc->reps_mport_id,
1345 &efx->tc->reps_mport_vport_id);
1349 static void efx_tc_deconfigure_rep_mport(struct efx_nic *efx)
1351 efx_mae_free_mport(efx, efx->tc->reps_mport_id);
1352 efx->tc->reps_mport_id = MAE_MPORT_SELECTOR_NULL;
1355 int efx_tc_insert_rep_filters(struct efx_nic *efx)
1357 struct efx_filter_spec promisc, allmulti;
1360 if (efx->type->is_vf)
1364 efx_filter_init_rx(&promisc, EFX_FILTER_PRI_REQUIRED, 0, 0);
1365 efx_filter_set_uc_def(&promisc);
1366 efx_filter_set_vport_id(&promisc, efx->tc->reps_mport_vport_id);
1367 rc = efx_filter_insert_filter(efx, &promisc, false);
1370 efx->tc->reps_filter_uc = rc;
1371 efx_filter_init_rx(&allmulti, EFX_FILTER_PRI_REQUIRED, 0, 0);
1372 efx_filter_set_mc_def(&allmulti);
1373 efx_filter_set_vport_id(&allmulti, efx->tc->reps_mport_vport_id);
1374 rc = efx_filter_insert_filter(efx, &allmulti, false);
1377 efx->tc->reps_filter_mc = rc;
1381 void efx_tc_remove_rep_filters(struct efx_nic *efx)
1383 if (efx->type->is_vf)
1387 if (efx->tc->reps_filter_mc >= 0)
1388 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, efx->tc->reps_filter_mc);
1389 efx->tc->reps_filter_mc = -1;
1390 if (efx->tc->reps_filter_uc >= 0)
1391 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, efx->tc->reps_filter_uc);
1392 efx->tc->reps_filter_uc = -1;
1395 int efx_init_tc(struct efx_nic *efx)
1399 rc = efx_mae_get_caps(efx, efx->tc->caps);
1402 if (efx->tc->caps->match_field_count > MAE_NUM_FIELDS)
1403 /* Firmware supports some match fields the driver doesn't know
1404 * about. Not fatal, unless any of those fields are required
1405 * (MAE_FIELD_SUPPORTED_MATCH_ALWAYS) but if so we don't know.
1407 netif_warn(efx, probe, efx->net_dev,
1408 "FW reports additional match fields %u\n",
1409 efx->tc->caps->match_field_count);
1410 if (efx->tc->caps->action_prios < EFX_TC_PRIO__NUM) {
1411 netif_err(efx, probe, efx->net_dev,
1412 "Too few action prios supported (have %u, need %u)\n",
1413 efx->tc->caps->action_prios, EFX_TC_PRIO__NUM);
1416 rc = efx_tc_configure_default_rule_pf(efx);
1419 rc = efx_tc_configure_default_rule_wire(efx);
1422 rc = efx_tc_configure_rep_mport(efx);
1426 rc = flow_indr_dev_register(efx_tc_indr_setup_cb, efx);
1432 void efx_fini_tc(struct efx_nic *efx)
1434 /* We can get called even if efx_init_struct_tc() failed */
1438 flow_indr_dev_unregister(efx_tc_indr_setup_cb, efx, efx_tc_block_unbind);
1439 efx_tc_deconfigure_rep_mport(efx);
1440 efx_tc_deconfigure_default_rule(efx, &efx->tc->dflt.pf);
1441 efx_tc_deconfigure_default_rule(efx, &efx->tc->dflt.wire);
1442 efx->tc->up = false;
1445 /* At teardown time, all TC filter rules (and thus all resources they created)
1446 * should already have been removed. If we find any in our hashtables, make a
1447 * cursory attempt to clean up the software side.
1449 static void efx_tc_encap_match_free(void *ptr, void *__unused)
1451 struct efx_tc_encap_match *encap = ptr;
1453 WARN_ON(refcount_read(&encap->ref));
1457 int efx_init_struct_tc(struct efx_nic *efx)
1461 if (efx->type->is_vf)
1464 efx->tc = kzalloc(sizeof(*efx->tc), GFP_KERNEL);
1467 efx->tc->caps = kzalloc(sizeof(struct mae_caps), GFP_KERNEL);
1468 if (!efx->tc->caps) {
1470 goto fail_alloc_caps;
1472 INIT_LIST_HEAD(&efx->tc->block_list);
1474 mutex_init(&efx->tc->mutex);
1475 init_waitqueue_head(&efx->tc->flush_wq);
1476 rc = efx_tc_init_counters(efx);
1479 rc = rhashtable_init(&efx->tc->encap_match_ht, &efx_tc_encap_match_ht_params);
1481 goto fail_encap_match_ht;
1482 rc = rhashtable_init(&efx->tc->match_action_ht, &efx_tc_match_action_ht_params);
1484 goto fail_match_action_ht;
1485 efx->tc->reps_filter_uc = -1;
1486 efx->tc->reps_filter_mc = -1;
1487 INIT_LIST_HEAD(&efx->tc->dflt.pf.acts.list);
1488 efx->tc->dflt.pf.fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
1489 INIT_LIST_HEAD(&efx->tc->dflt.wire.acts.list);
1490 efx->tc->dflt.wire.fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
1491 efx->extra_channel_type[EFX_EXTRA_CHANNEL_TC] = &efx_tc_channel_type;
1493 fail_match_action_ht:
1494 rhashtable_destroy(&efx->tc->encap_match_ht);
1495 fail_encap_match_ht:
1496 efx_tc_destroy_counters(efx);
1498 mutex_destroy(&efx->tc->mutex);
1499 kfree(efx->tc->caps);
1506 void efx_fini_struct_tc(struct efx_nic *efx)
1511 mutex_lock(&efx->tc->mutex);
1512 EFX_WARN_ON_PARANOID(efx->tc->dflt.pf.fw_id !=
1513 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
1514 EFX_WARN_ON_PARANOID(efx->tc->dflt.wire.fw_id !=
1515 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
1516 rhashtable_free_and_destroy(&efx->tc->match_action_ht, efx_tc_flow_free,
1518 rhashtable_free_and_destroy(&efx->tc->encap_match_ht,
1519 efx_tc_encap_match_free, NULL);
1520 efx_tc_fini_counters(efx);
1521 mutex_unlock(&efx->tc->mutex);
1522 mutex_destroy(&efx->tc->mutex);
1523 kfree(efx->tc->caps);