From nobody Fri Apr 10 14:07:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1210C32772 for ; Tue, 23 Aug 2022 16:29:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244476AbiHWQ3N (ORCPT ); Tue, 23 Aug 2022 12:29:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244223AbiHWQ2i (ORCPT ); Tue, 23 Aug 2022 12:28:38 -0400 Received: from syslogsrv (unknown [217.20.186.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04A5F11C962; Tue, 23 Aug 2022 05:56:11 -0700 (PDT) Received: from fg200.ow.s ([172.20.254.44] helo=localhost.localdomain) by syslogsrv with esmtp (Exim 4.90_1) (envelope-from ) id 1oQSGV-000FXN-Gm; Tue, 23 Aug 2022 14:40:15 +0300 From: Maksym Glubokiy To: Taras Chornyi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serhiy Boiko , Maksym Glubokiy , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 1/3] net: prestera: acl: extract matchall logic into a separate file Date: Tue, 23 Aug 2022 14:39:56 +0300 Message-Id: <20220823113958.2061401-2-maksym.glubokiy@plvision.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823113958.2061401-1-maksym.glubokiy@plvision.eu> References: <20220823113958.2061401-1-maksym.glubokiy@plvision.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Serhiy Boiko This commit adds more clarity to handling of TC_CLSMATCHALL_REPLACE and TC_CLSMATCHALL_DESTROY events by calling newly added *_mall_*() handlers instead of directly calling SPAN API. This also extracts matchall rules management out of SPAN API since SPAN is a hardware module which is used to implement 'matchall egress mirred' action only. Signed-off-by: Taras Chornyi Signed-off-by: Serhiy Boiko Signed-off-by: Maksym Glubokiy --- .../net/ethernet/marvell/prestera/Makefile | 2 +- .../ethernet/marvell/prestera/prestera_flow.c | 9 +-- .../marvell/prestera/prestera_matchall.c | 66 +++++++++++++++++++ .../marvell/prestera/prestera_matchall.h | 15 +++++ .../ethernet/marvell/prestera/prestera_span.c | 60 +---------------- .../ethernet/marvell/prestera/prestera_span.h | 10 +-- 6 files changed, 96 insertions(+), 66 deletions(-) create mode 100644 drivers/net/ethernet/marvell/prestera/prestera_matchall= .c create mode 100644 drivers/net/ethernet/marvell/prestera/prestera_matchall= .h diff --git a/drivers/net/ethernet/marvell/prestera/Makefile b/drivers/net/e= thernet/marvell/prestera/Makefile index d395f4131648..df14cee80153 100644 --- a/drivers/net/ethernet/marvell/prestera/Makefile +++ b/drivers/net/ethernet/marvell/prestera/Makefile @@ -4,6 +4,6 @@ prestera-objs :=3D prestera_main.o prestera_hw.o prestera_= dsa.o \ prestera_rxtx.o prestera_devlink.o prestera_ethtool.o \ prestera_switchdev.o prestera_acl.o prestera_flow.o \ prestera_flower.o prestera_span.o prestera_counter.o \ - prestera_router.o prestera_router_hw.o + prestera_router.o prestera_router_hw.o prestera_matchall.o =20 obj-$(CONFIG_PRESTERA_PCI) +=3D prestera_pci.o diff --git a/drivers/net/ethernet/marvell/prestera/prestera_flow.c b/driver= s/net/ethernet/marvell/prestera/prestera_flow.c index 2262693bd5cf..3f81eef167fa 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_flow.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_flow.c @@ -7,8 +7,9 @@ #include "prestera.h" #include "prestera_acl.h" #include "prestera_flow.h" -#include "prestera_span.h" #include "prestera_flower.h" +#include "prestera_matchall.h" +#include "prestera_span.h" =20 static LIST_HEAD(prestera_block_cb_list); =20 @@ -17,9 +18,9 @@ static int prestera_flow_block_mall_cb(struct prestera_fl= ow_block *block, { switch (f->command) { case TC_CLSMATCHALL_REPLACE: - return prestera_span_replace(block, f); + return prestera_mall_replace(block, f); case TC_CLSMATCHALL_DESTROY: - prestera_span_destroy(block); + prestera_mall_destroy(block); return 0; default: return -EOPNOTSUPP; @@ -263,7 +264,7 @@ static void prestera_setup_flow_block_unbind(struct pre= stera_port *port, =20 block =3D flow_block_cb_priv(block_cb); =20 - prestera_span_destroy(block); + prestera_mall_destroy(block); =20 err =3D prestera_flow_block_unbind(block, port); if (err) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_matchall.c b/dr= ivers/net/ethernet/marvell/prestera/prestera_matchall.c new file mode 100644 index 000000000000..54573c6a6fe2 --- /dev/null +++ b/drivers/net/ethernet/marvell/prestera/prestera_matchall.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 +/* Copyright (c) 2019-2022 Marvell International Ltd. All rights reserved = */ + +#include +#include + +#include "prestera.h" +#include "prestera_hw.h" +#include "prestera_flow.h" +#include "prestera_flower.h" +#include "prestera_matchall.h" +#include "prestera_span.h" + +int prestera_mall_replace(struct prestera_flow_block *block, + struct tc_cls_matchall_offload *f) +{ + struct prestera_flow_block_binding *binding; + __be16 protocol =3D f->common.protocol; + struct flow_action_entry *act; + struct prestera_port *port; + int err; + + if (!flow_offload_has_one_action(&f->rule->action)) { + NL_SET_ERR_MSG(f->common.extack, + "Only singular actions are supported"); + return -EOPNOTSUPP; + } + + act =3D &f->rule->action.entries[0]; + + if (!prestera_netdev_check(act->dev)) { + NL_SET_ERR_MSG(f->common.extack, + "Only Marvell Prestera port is supported"); + return -EINVAL; + } + if (!tc_cls_can_offload_and_chain0(act->dev, &f->common)) + return -EOPNOTSUPP; + if (act->id !=3D FLOW_ACTION_MIRRED) + return -EOPNOTSUPP; + if (protocol !=3D htons(ETH_P_ALL)) + return -EOPNOTSUPP; + + port =3D netdev_priv(act->dev); + + list_for_each_entry(binding, &block->binding_list, list) { + err =3D prestera_span_rule_add(binding, port); + if (err) + goto rollback; + } + + return 0; + +rollback: + list_for_each_entry_continue_reverse(binding, + &block->binding_list, list) + prestera_span_rule_del(binding); + return err; +} + +void prestera_mall_destroy(struct prestera_flow_block *block) +{ + struct prestera_flow_block_binding *binding; + + list_for_each_entry(binding, &block->binding_list, list) + prestera_span_rule_del(binding); +} diff --git a/drivers/net/ethernet/marvell/prestera/prestera_matchall.h b/dr= ivers/net/ethernet/marvell/prestera/prestera_matchall.h new file mode 100644 index 000000000000..31ad4d02ecbb --- /dev/null +++ b/drivers/net/ethernet/marvell/prestera/prestera_matchall.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* Copyright (c) 2022 Marvell International Ltd. All rights reserved. */ + +#ifndef _PRESTERA_MATCHALL_H_ +#define _PRESTERA_MATCHALL_H_ + +#include + +struct prestera_flow_block; + +int prestera_mall_replace(struct prestera_flow_block *block, + struct tc_cls_matchall_offload *f); +void prestera_mall_destroy(struct prestera_flow_block *block); + +#endif /* _PRESTERA_MATCHALL_H_ */ diff --git a/drivers/net/ethernet/marvell/prestera/prestera_span.c b/driver= s/net/ethernet/marvell/prestera/prestera_span.c index 845e9d8c8cc7..766413b9ba1b 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_span.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_span.c @@ -120,8 +120,8 @@ static int prestera_span_put(struct prestera_switch *sw= , u8 span_id) return 0; } =20 -static int prestera_span_rule_add(struct prestera_flow_block_binding *bind= ing, - struct prestera_port *to_port) +int prestera_span_rule_add(struct prestera_flow_block_binding *binding, + struct prestera_port *to_port) { struct prestera_switch *sw =3D binding->port->sw; u8 span_id; @@ -145,7 +145,7 @@ static int prestera_span_rule_add(struct prestera_flow_= block_binding *binding, return 0; } =20 -static int prestera_span_rule_del(struct prestera_flow_block_binding *bind= ing) +int prestera_span_rule_del(struct prestera_flow_block_binding *binding) { int err; =20 @@ -161,60 +161,6 @@ static int prestera_span_rule_del(struct prestera_flow= _block_binding *binding) return 0; } =20 -int prestera_span_replace(struct prestera_flow_block *block, - struct tc_cls_matchall_offload *f) -{ - struct prestera_flow_block_binding *binding; - __be16 protocol =3D f->common.protocol; - struct flow_action_entry *act; - struct prestera_port *port; - int err; - - if (!flow_offload_has_one_action(&f->rule->action)) { - NL_SET_ERR_MSG(f->common.extack, - "Only singular actions are supported"); - return -EOPNOTSUPP; - } - - act =3D &f->rule->action.entries[0]; - - if (!prestera_netdev_check(act->dev)) { - NL_SET_ERR_MSG(f->common.extack, - "Only Marvell Prestera port is supported"); - return -EINVAL; - } - if (!tc_cls_can_offload_and_chain0(act->dev, &f->common)) - return -EOPNOTSUPP; - if (act->id !=3D FLOW_ACTION_MIRRED) - return -EOPNOTSUPP; - if (protocol !=3D htons(ETH_P_ALL)) - return -EOPNOTSUPP; - - port =3D netdev_priv(act->dev); - - list_for_each_entry(binding, &block->binding_list, list) { - err =3D prestera_span_rule_add(binding, port); - if (err) - goto rollback; - } - - return 0; - -rollback: - list_for_each_entry_continue_reverse(binding, - &block->binding_list, list) - prestera_span_rule_del(binding); - return err; -} - -void prestera_span_destroy(struct prestera_flow_block *block) -{ - struct prestera_flow_block_binding *binding; - - list_for_each_entry(binding, &block->binding_list, list) - prestera_span_rule_del(binding); -} - int prestera_span_init(struct prestera_switch *sw) { struct prestera_span *span; diff --git a/drivers/net/ethernet/marvell/prestera/prestera_span.h b/driver= s/net/ethernet/marvell/prestera/prestera_span.h index f0644521f78a..4958ce820b52 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_span.h +++ b/drivers/net/ethernet/marvell/prestera/prestera_span.h @@ -8,13 +8,15 @@ =20 #define PRESTERA_SPAN_INVALID_ID -1 =20 +struct prestera_port; struct prestera_switch; -struct prestera_flow_block; +struct prestera_flow_block_binding; =20 int prestera_span_init(struct prestera_switch *sw); void prestera_span_fini(struct prestera_switch *sw); -int prestera_span_replace(struct prestera_flow_block *block, - struct tc_cls_matchall_offload *f); -void prestera_span_destroy(struct prestera_flow_block *block); + +int prestera_span_rule_add(struct prestera_flow_block_binding *binding, + struct prestera_port *to_port); +int prestera_span_rule_del(struct prestera_flow_block_binding *binding); =20 #endif /* _PRESTERA_SPAN_H_ */ --=20 2.25.1