1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
4 #include <linux/kernel.h>
5 #include <linux/errno.h>
6 #include <linux/netdevice.h>
7 #include <linux/log2.h>
8 #include <net/net_namespace.h>
9 #include <net/flow_dissector.h>
10 #include <net/pkt_cls.h>
11 #include <net/tc_act/tc_gact.h>
12 #include <net/tc_act/tc_mirred.h>
13 #include <net/tc_act/tc_vlan.h>
16 #include "core_acl_flex_keys.h"
18 static int mlxsw_sp_policer_validate(const struct flow_action *action,
19 const struct flow_action_entry *act,
20 struct netlink_ext_ack *extack)
22 if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
23 NL_SET_ERR_MSG_MOD(extack,
24 "Offload not supported when exceed action is not drop");
28 if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
29 act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
30 NL_SET_ERR_MSG_MOD(extack,
31 "Offload not supported when conform action is not pipe or ok");
35 if (act->police.notexceed.act_id == FLOW_ACTION_ACCEPT &&
36 !flow_action_is_last_entry(action, act)) {
37 NL_SET_ERR_MSG_MOD(extack,
38 "Offload not supported when conform action is ok, but action is not last");
42 if (act->police.peakrate_bytes_ps ||
43 act->police.avrate || act->police.overhead) {
44 NL_SET_ERR_MSG_MOD(extack,
45 "Offload not supported when peakrate/avrate/overhead is configured");
49 if (act->police.rate_pkt_ps) {
50 NL_SET_ERR_MSG_MOD(extack,
51 "QoS offload not support packets per second");
58 static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
59 struct mlxsw_sp_flow_block *block,
60 struct mlxsw_sp_acl_rule_info *rulei,
61 struct flow_action *flow_action,
62 struct netlink_ext_ack *extack)
64 const struct flow_action_entry *act;
65 int mirror_act_count = 0;
66 int police_act_count = 0;
67 int sample_act_count = 0;
70 if (!flow_action_has_entries(flow_action))
72 if (!flow_action_mixed_hw_stats_check(flow_action, extack))
75 act = flow_action_first_entry_get(flow_action);
76 if (act->hw_stats & FLOW_ACTION_HW_STATS_DISABLED) {
78 } else if (act->hw_stats & FLOW_ACTION_HW_STATS_IMMEDIATE) {
79 /* Count action is inserted first */
80 err = mlxsw_sp_acl_rulei_act_count(mlxsw_sp, rulei, extack);
84 NL_SET_ERR_MSG_MOD(extack, "Unsupported action HW stats type");
88 flow_action_for_each(i, act, flow_action) {
90 case FLOW_ACTION_ACCEPT:
91 err = mlxsw_sp_acl_rulei_act_terminate(rulei);
93 NL_SET_ERR_MSG_MOD(extack, "Cannot append terminate action");
97 case FLOW_ACTION_DROP: {
100 if (mlxsw_sp_flow_block_is_mixed_bound(block)) {
101 NL_SET_ERR_MSG_MOD(extack, "Drop action is not supported when block is bound to ingress and egress");
104 ingress = mlxsw_sp_flow_block_is_ingress_bound(block);
105 err = mlxsw_sp_acl_rulei_act_drop(rulei, ingress,
106 act->user_cookie, extack);
108 NL_SET_ERR_MSG_MOD(extack, "Cannot append drop action");
112 /* Forbid block with this rulei to be bound
113 * to ingress/egress in future. Ingress rule is
114 * a blocker for egress and vice versa.
117 rulei->egress_bind_blocker = 1;
119 rulei->ingress_bind_blocker = 1;
122 case FLOW_ACTION_TRAP:
123 err = mlxsw_sp_acl_rulei_act_trap(rulei);
125 NL_SET_ERR_MSG_MOD(extack, "Cannot append trap action");
129 case FLOW_ACTION_GOTO: {
130 u32 chain_index = act->chain_index;
131 struct mlxsw_sp_acl_ruleset *ruleset;
134 ruleset = mlxsw_sp_acl_ruleset_lookup(mlxsw_sp, block,
136 MLXSW_SP_ACL_PROFILE_FLOWER);
138 return PTR_ERR(ruleset);
140 group_id = mlxsw_sp_acl_ruleset_group_id(ruleset);
141 err = mlxsw_sp_acl_rulei_act_jump(rulei, group_id);
143 NL_SET_ERR_MSG_MOD(extack, "Cannot append jump action");
148 case FLOW_ACTION_REDIRECT: {
149 struct net_device *out_dev;
150 struct mlxsw_sp_fid *fid;
153 if (mlxsw_sp_flow_block_is_egress_bound(block)) {
154 NL_SET_ERR_MSG_MOD(extack, "Redirect action is not supported on egress");
158 /* Forbid block with this rulei to be bound
159 * to egress in future.
161 rulei->egress_bind_blocker = 1;
163 fid = mlxsw_sp_acl_dummy_fid(mlxsw_sp);
164 fid_index = mlxsw_sp_fid_index(fid);
165 err = mlxsw_sp_acl_rulei_act_fid_set(mlxsw_sp, rulei,
171 err = mlxsw_sp_acl_rulei_act_fwd(mlxsw_sp, rulei,
177 case FLOW_ACTION_MIRRED: {
178 struct net_device *out_dev = act->dev;
180 if (mirror_act_count++) {
181 NL_SET_ERR_MSG_MOD(extack, "Multiple mirror actions per rule are not supported");
185 err = mlxsw_sp_acl_rulei_act_mirror(mlxsw_sp, rulei,
192 case FLOW_ACTION_VLAN_MANGLE: {
193 u16 proto = be16_to_cpu(act->vlan.proto);
194 u8 prio = act->vlan.prio;
195 u16 vid = act->vlan.vid;
197 err = mlxsw_sp_acl_rulei_act_vlan(mlxsw_sp, rulei,
199 proto, prio, extack);
204 case FLOW_ACTION_PRIORITY:
205 err = mlxsw_sp_acl_rulei_act_priority(mlxsw_sp, rulei,
211 case FLOW_ACTION_MANGLE: {
212 enum flow_action_mangle_base htype = act->mangle.htype;
213 __be32 be_mask = (__force __be32) act->mangle.mask;
214 __be32 be_val = (__force __be32) act->mangle.val;
215 u32 offset = act->mangle.offset;
216 u32 mask = be32_to_cpu(be_mask);
217 u32 val = be32_to_cpu(be_val);
219 err = mlxsw_sp_acl_rulei_act_mangle(mlxsw_sp, rulei,
226 case FLOW_ACTION_POLICE: {
229 if (police_act_count++) {
230 NL_SET_ERR_MSG_MOD(extack, "Multiple police actions per rule are not supported");
234 err = mlxsw_sp_policer_validate(flow_action, act, extack);
238 /* The kernel might adjust the requested burst size so
239 * that it is not exactly a power of two. Re-adjust it
240 * here since the hardware only supports burst sizes
241 * that are a power of two.
243 burst = roundup_pow_of_two(act->police.burst);
244 err = mlxsw_sp_acl_rulei_act_police(mlxsw_sp, rulei,
246 act->police.rate_bytes_ps,
252 case FLOW_ACTION_SAMPLE: {
253 if (sample_act_count++) {
254 NL_SET_ERR_MSG_MOD(extack, "Multiple sample actions per rule are not supported");
258 err = mlxsw_sp_acl_rulei_act_sample(mlxsw_sp, rulei,
260 act->sample.psample_group,
262 act->sample.trunc_size,
263 act->sample.truncate,
270 NL_SET_ERR_MSG_MOD(extack, "Unsupported action");
271 dev_err(mlxsw_sp->bus_info->dev, "Unsupported action\n");
276 if (rulei->ipv6_valid) {
277 NL_SET_ERR_MSG_MOD(extack, "Unsupported mangle field");
285 mlxsw_sp_flower_parse_meta_iif(struct mlxsw_sp_acl_rule_info *rulei,
286 const struct mlxsw_sp_flow_block *block,
287 const struct flow_match_meta *match,
288 struct netlink_ext_ack *extack)
290 struct mlxsw_sp_port *mlxsw_sp_port;
291 struct net_device *ingress_dev;
293 if (!match->mask->ingress_ifindex)
296 if (match->mask->ingress_ifindex != 0xFFFFFFFF) {
297 NL_SET_ERR_MSG_MOD(extack, "Unsupported ingress ifindex mask");
301 ingress_dev = __dev_get_by_index(block->net,
302 match->key->ingress_ifindex);
304 NL_SET_ERR_MSG_MOD(extack, "Can't find specified ingress port to match on");
308 if (!mlxsw_sp_port_dev_check(ingress_dev)) {
309 NL_SET_ERR_MSG_MOD(extack, "Can't match on non-mlxsw ingress port");
313 mlxsw_sp_port = netdev_priv(ingress_dev);
314 if (mlxsw_sp_port->mlxsw_sp != block->mlxsw_sp) {
315 NL_SET_ERR_MSG_MOD(extack, "Can't match on a port from different device");
319 mlxsw_sp_acl_rulei_keymask_u32(rulei,
320 MLXSW_AFK_ELEMENT_SRC_SYS_PORT,
321 mlxsw_sp_port->local_port,
327 static int mlxsw_sp_flower_parse_meta(struct mlxsw_sp_acl_rule_info *rulei,
328 struct flow_cls_offload *f,
329 struct mlxsw_sp_flow_block *block)
331 struct flow_rule *rule = flow_cls_offload_flow_rule(f);
332 struct flow_match_meta match;
334 if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_META))
337 flow_rule_match_meta(rule, &match);
339 mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_FDB_MISS,
340 match.key->l2_miss, match.mask->l2_miss);
342 return mlxsw_sp_flower_parse_meta_iif(rulei, block, &match,
346 static void mlxsw_sp_flower_parse_ipv4(struct mlxsw_sp_acl_rule_info *rulei,
347 struct flow_cls_offload *f)
349 struct flow_match_ipv4_addrs match;
351 flow_rule_match_ipv4_addrs(f->rule, &match);
353 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_0_31,
354 (char *) &match.key->src,
355 (char *) &match.mask->src, 4);
356 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_0_31,
357 (char *) &match.key->dst,
358 (char *) &match.mask->dst, 4);
361 static void mlxsw_sp_flower_parse_ipv6(struct mlxsw_sp_acl_rule_info *rulei,
362 struct flow_cls_offload *f)
364 struct flow_match_ipv6_addrs match;
366 flow_rule_match_ipv6_addrs(f->rule, &match);
368 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_96_127,
369 &match.key->src.s6_addr[0x0],
370 &match.mask->src.s6_addr[0x0], 4);
371 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_64_95,
372 &match.key->src.s6_addr[0x4],
373 &match.mask->src.s6_addr[0x4], 4);
374 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_32_63,
375 &match.key->src.s6_addr[0x8],
376 &match.mask->src.s6_addr[0x8], 4);
377 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_SRC_IP_0_31,
378 &match.key->src.s6_addr[0xC],
379 &match.mask->src.s6_addr[0xC], 4);
380 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_96_127,
381 &match.key->dst.s6_addr[0x0],
382 &match.mask->dst.s6_addr[0x0], 4);
383 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_64_95,
384 &match.key->dst.s6_addr[0x4],
385 &match.mask->dst.s6_addr[0x4], 4);
386 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_32_63,
387 &match.key->dst.s6_addr[0x8],
388 &match.mask->dst.s6_addr[0x8], 4);
389 mlxsw_sp_acl_rulei_keymask_buf(rulei, MLXSW_AFK_ELEMENT_DST_IP_0_31,
390 &match.key->dst.s6_addr[0xC],
391 &match.mask->dst.s6_addr[0xC], 4);
394 static int mlxsw_sp_flower_parse_ports(struct mlxsw_sp *mlxsw_sp,
395 struct mlxsw_sp_acl_rule_info *rulei,
396 struct flow_cls_offload *f,
399 const struct flow_rule *rule = flow_cls_offload_flow_rule(f);
400 struct flow_match_ports match;
402 if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS))
405 if (ip_proto != IPPROTO_TCP && ip_proto != IPPROTO_UDP) {
406 NL_SET_ERR_MSG_MOD(f->common.extack, "Only UDP and TCP keys are supported");
407 dev_err(mlxsw_sp->bus_info->dev, "Only UDP and TCP keys are supported\n");
411 flow_rule_match_ports(rule, &match);
412 mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_DST_L4_PORT,
413 ntohs(match.key->dst),
414 ntohs(match.mask->dst));
415 mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_SRC_L4_PORT,
416 ntohs(match.key->src),
417 ntohs(match.mask->src));
421 static int mlxsw_sp_flower_parse_tcp(struct mlxsw_sp *mlxsw_sp,
422 struct mlxsw_sp_acl_rule_info *rulei,
423 struct flow_cls_offload *f,
426 const struct flow_rule *rule = flow_cls_offload_flow_rule(f);
427 struct flow_match_tcp match;
429 if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_TCP))
432 if (ip_proto != IPPROTO_TCP) {
433 NL_SET_ERR_MSG_MOD(f->common.extack, "TCP keys supported only for TCP");
434 dev_err(mlxsw_sp->bus_info->dev, "TCP keys supported only for TCP\n");
438 flow_rule_match_tcp(rule, &match);
440 if (match.mask->flags & htons(0x0E00)) {
441 NL_SET_ERR_MSG_MOD(f->common.extack, "TCP flags match not supported on reserved bits");
442 dev_err(mlxsw_sp->bus_info->dev, "TCP flags match not supported on reserved bits\n");
446 mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_TCP_FLAGS,
447 ntohs(match.key->flags),
448 ntohs(match.mask->flags));
452 static int mlxsw_sp_flower_parse_ip(struct mlxsw_sp *mlxsw_sp,
453 struct mlxsw_sp_acl_rule_info *rulei,
454 struct flow_cls_offload *f,
457 const struct flow_rule *rule = flow_cls_offload_flow_rule(f);
458 struct flow_match_ip match;
460 if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IP))
463 if (n_proto != ETH_P_IP && n_proto != ETH_P_IPV6) {
464 NL_SET_ERR_MSG_MOD(f->common.extack, "IP keys supported only for IPv4/6");
465 dev_err(mlxsw_sp->bus_info->dev, "IP keys supported only for IPv4/6\n");
469 flow_rule_match_ip(rule, &match);
471 mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_TTL_,
472 match.key->ttl, match.mask->ttl);
474 mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_ECN,
475 match.key->tos & 0x3,
476 match.mask->tos & 0x3);
478 mlxsw_sp_acl_rulei_keymask_u32(rulei, MLXSW_AFK_ELEMENT_IP_DSCP,
480 match.mask->tos >> 2);
485 static int mlxsw_sp_flower_parse(struct mlxsw_sp *mlxsw_sp,
486 struct mlxsw_sp_flow_block *block,
487 struct mlxsw_sp_acl_rule_info *rulei,
488 struct flow_cls_offload *f)
490 struct flow_rule *rule = flow_cls_offload_flow_rule(f);
491 struct flow_dissector *dissector = rule->match.dissector;
492 u16 n_proto_mask = 0;
498 if (dissector->used_keys &
499 ~(BIT(FLOW_DISSECTOR_KEY_META) |
500 BIT(FLOW_DISSECTOR_KEY_CONTROL) |
501 BIT(FLOW_DISSECTOR_KEY_BASIC) |
502 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
503 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
504 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
505 BIT(FLOW_DISSECTOR_KEY_PORTS) |
506 BIT(FLOW_DISSECTOR_KEY_TCP) |
507 BIT(FLOW_DISSECTOR_KEY_IP) |
508 BIT(FLOW_DISSECTOR_KEY_VLAN))) {
509 dev_err(mlxsw_sp->bus_info->dev, "Unsupported key\n");
510 NL_SET_ERR_MSG_MOD(f->common.extack, "Unsupported key");
514 mlxsw_sp_acl_rulei_priority(rulei, f->common.prio);
516 err = mlxsw_sp_flower_parse_meta(rulei, f, block);
520 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
521 struct flow_match_control match;
523 flow_rule_match_control(rule, &match);
524 addr_type = match.key->addr_type;
527 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
528 struct flow_match_basic match;
530 flow_rule_match_basic(rule, &match);
531 n_proto_key = ntohs(match.key->n_proto);
532 n_proto_mask = ntohs(match.mask->n_proto);
534 if (n_proto_key == ETH_P_ALL) {
538 mlxsw_sp_acl_rulei_keymask_u32(rulei,
539 MLXSW_AFK_ELEMENT_ETHERTYPE,
540 n_proto_key, n_proto_mask);
542 ip_proto = match.key->ip_proto;
543 mlxsw_sp_acl_rulei_keymask_u32(rulei,
544 MLXSW_AFK_ELEMENT_IP_PROTO,
546 match.mask->ip_proto);
549 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
550 struct flow_match_eth_addrs match;
552 flow_rule_match_eth_addrs(rule, &match);
553 mlxsw_sp_acl_rulei_keymask_buf(rulei,
554 MLXSW_AFK_ELEMENT_DMAC_32_47,
557 mlxsw_sp_acl_rulei_keymask_buf(rulei,
558 MLXSW_AFK_ELEMENT_DMAC_0_31,
560 match.mask->dst + 2, 4);
561 mlxsw_sp_acl_rulei_keymask_buf(rulei,
562 MLXSW_AFK_ELEMENT_SMAC_32_47,
565 mlxsw_sp_acl_rulei_keymask_buf(rulei,
566 MLXSW_AFK_ELEMENT_SMAC_0_31,
568 match.mask->src + 2, 4);
571 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
572 struct flow_match_vlan match;
574 flow_rule_match_vlan(rule, &match);
575 if (mlxsw_sp_flow_block_is_egress_bound(block) &&
576 match.mask->vlan_id) {
577 NL_SET_ERR_MSG_MOD(f->common.extack, "vlan_id key is not supported on egress");
581 /* Forbid block with this rulei to be bound
582 * to egress in future.
584 rulei->egress_bind_blocker = 1;
586 if (match.mask->vlan_id != 0)
587 mlxsw_sp_acl_rulei_keymask_u32(rulei,
588 MLXSW_AFK_ELEMENT_VID,
590 match.mask->vlan_id);
591 if (match.mask->vlan_priority != 0)
592 mlxsw_sp_acl_rulei_keymask_u32(rulei,
593 MLXSW_AFK_ELEMENT_PCP,
594 match.key->vlan_priority,
595 match.mask->vlan_priority);
598 if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS)
599 mlxsw_sp_flower_parse_ipv4(rulei, f);
601 if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS)
602 mlxsw_sp_flower_parse_ipv6(rulei, f);
604 err = mlxsw_sp_flower_parse_ports(mlxsw_sp, rulei, f, ip_proto);
607 err = mlxsw_sp_flower_parse_tcp(mlxsw_sp, rulei, f, ip_proto);
611 err = mlxsw_sp_flower_parse_ip(mlxsw_sp, rulei, f, n_proto_key & n_proto_mask);
615 return mlxsw_sp_flower_parse_actions(mlxsw_sp, block, rulei,
620 static int mlxsw_sp_flower_mall_prio_check(struct mlxsw_sp_flow_block *block,
621 struct flow_cls_offload *f)
623 bool ingress = mlxsw_sp_flow_block_is_ingress_bound(block);
624 unsigned int mall_min_prio;
625 unsigned int mall_max_prio;
628 err = mlxsw_sp_mall_prio_get(block, f->common.chain_index,
629 &mall_min_prio, &mall_max_prio);
632 /* No matchall filters installed on this chain. */
634 NL_SET_ERR_MSG(f->common.extack, "Failed to get matchall priorities");
637 if (ingress && f->common.prio <= mall_min_prio) {
638 NL_SET_ERR_MSG(f->common.extack, "Failed to add in front of existing matchall rules");
641 if (!ingress && f->common.prio >= mall_max_prio) {
642 NL_SET_ERR_MSG(f->common.extack, "Failed to add behind of existing matchall rules");
648 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
649 struct mlxsw_sp_flow_block *block,
650 struct flow_cls_offload *f)
652 struct mlxsw_sp_acl_rule_info *rulei;
653 struct mlxsw_sp_acl_ruleset *ruleset;
654 struct mlxsw_sp_acl_rule *rule;
657 err = mlxsw_sp_flower_mall_prio_check(block, f);
661 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
662 f->common.chain_index,
663 MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
665 return PTR_ERR(ruleset);
667 rule = mlxsw_sp_acl_rule_create(mlxsw_sp, ruleset, f->cookie, NULL,
671 goto err_rule_create;
674 rulei = mlxsw_sp_acl_rule_rulei(rule);
675 err = mlxsw_sp_flower_parse(mlxsw_sp, block, rulei, f);
677 goto err_flower_parse;
679 err = mlxsw_sp_acl_rulei_commit(rulei);
681 goto err_rulei_commit;
683 err = mlxsw_sp_acl_rule_add(mlxsw_sp, rule);
687 mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
693 mlxsw_sp_acl_rule_destroy(mlxsw_sp, rule);
695 mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
699 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
700 struct mlxsw_sp_flow_block *block,
701 struct flow_cls_offload *f)
703 struct mlxsw_sp_acl_ruleset *ruleset;
704 struct mlxsw_sp_acl_rule *rule;
706 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
707 f->common.chain_index,
708 MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
712 rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
714 mlxsw_sp_acl_rule_del(mlxsw_sp, rule);
715 mlxsw_sp_acl_rule_destroy(mlxsw_sp, rule);
718 mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
721 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
722 struct mlxsw_sp_flow_block *block,
723 struct flow_cls_offload *f)
725 enum flow_action_hw_stats used_hw_stats = FLOW_ACTION_HW_STATS_DISABLED;
726 struct mlxsw_sp_acl_ruleset *ruleset;
727 struct mlxsw_sp_acl_rule *rule;
734 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
735 f->common.chain_index,
736 MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
737 if (WARN_ON(IS_ERR(ruleset)))
740 rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
744 err = mlxsw_sp_acl_rule_get_stats(mlxsw_sp, rule, &packets, &bytes,
745 &drops, &lastuse, &used_hw_stats);
747 goto err_rule_get_stats;
749 flow_stats_update(&f->stats, bytes, packets, drops, lastuse,
752 mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
756 mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
760 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
761 struct mlxsw_sp_flow_block *block,
762 struct flow_cls_offload *f)
764 struct mlxsw_sp_acl_ruleset *ruleset;
765 struct mlxsw_sp_acl_rule_info rulei;
768 memset(&rulei, 0, sizeof(rulei));
769 err = mlxsw_sp_flower_parse(mlxsw_sp, block, &rulei, f);
772 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
773 f->common.chain_index,
774 MLXSW_SP_ACL_PROFILE_FLOWER,
775 &rulei.values.elusage);
777 /* keep the reference to the ruleset */
778 return PTR_ERR_OR_ZERO(ruleset);
781 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
782 struct mlxsw_sp_flow_block *block,
783 struct flow_cls_offload *f)
785 struct mlxsw_sp_acl_ruleset *ruleset;
787 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
788 f->common.chain_index,
789 MLXSW_SP_ACL_PROFILE_FLOWER, NULL);
792 /* put the reference to the ruleset kept in create */
793 mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
794 mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
797 int mlxsw_sp_flower_prio_get(struct mlxsw_sp *mlxsw_sp,
798 struct mlxsw_sp_flow_block *block,
799 u32 chain_index, unsigned int *p_min_prio,
800 unsigned int *p_max_prio)
802 struct mlxsw_sp_acl_ruleset *ruleset;
804 ruleset = mlxsw_sp_acl_ruleset_lookup(mlxsw_sp, block,
806 MLXSW_SP_ACL_PROFILE_FLOWER);
808 /* In case there are no flower rules, the caller
809 * receives -ENOENT to indicate there is no need
810 * to check the priorities.
812 return PTR_ERR(ruleset);
813 mlxsw_sp_acl_ruleset_prio_get(ruleset, p_min_prio, p_max_prio);