From patchwork Thu Oct 17 16:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13840378 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2055.outbound.protection.outlook.com [40.107.21.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E54261E0DDD; Thu, 17 Oct 2024 16:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729184000; cv=fail; b=M9FVZVqkDVFVG9HB9MxhfimD7kzNTDSYXuGnA1cKlMWVUZ5AbQrcv97S20PTpJsJy76Y1dLYCBgJM5Z2Dq8+Hki/G6Tfzw2AX05RIL2DH8ziN6fpaQPDrz0ZZ5cfypylKO+m8E8XphtYdtWQhgUecZCKH2dWssLLN9RntWU0K38= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729184000; c=relaxed/simple; bh=pp/6Hc+CF4lcRCy0fDbuM11wJ7x1nCijkK5SXkZ/zgo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=t6ETSaQdOwgDoiWGJwACwYBb2/6bcq9lxR2pMBFoHJH3uO+l4/WBGYOxDkxPKEsk/WSvjCANzJB+1dwp4nOJHQDjdmP6zI5jlA5ieDg1roXZuHkmHh78kbGDLLPGtmBVwlJuUNzvjhNix/ORqw+vYTaCPM5zm7AiKfjHQxLe5Q4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=T7u3pwdC; arc=fail smtp.client-ip=40.107.21.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="T7u3pwdC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GVy1/ml0eSouyJDAzyp5ZeHN2oSCmqkMGXgs9HhUZe7ebE5HRTVUU+tw8QWqbaTkVtt+wK5mtEp4FNqKdnaEop8pgaNG+eP5/EkXshv9Em6sQu3Cfee815WyZDuVT2q6ClzSKgQf/0wxWvYIGwqcyy9o5a3Iw1vx4zfd9B5Lhm46Oi/kTsO1ExDf1LEVDdo/Mrkkn8u8+IbWdjZuHULZexJq8ePULmecdOLjuoXzvRhRbEp+3pEcnUjKvChw7VMKQNmEZLMcl+kmxcV11Yzi3TGjmNrUIBcFWo4Gpa7ibqA95NFDh0uYzeNSLhOcXii1FUY5JHmpgaBJpsRYmTH93g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8FbCvt4SDdBMdT39XRoF1F5uTz2UYEJVMtFE5iLC5tM=; b=x+KRLk/Zm1k0KNCy2ORWGDguYZgdWEpakT/QJHNKNurAEgSCLYWhoSgwJ7HBPYFnWuj3pOMz2sFdREtW9pr8dLL1jogf3WMvK9bxqIV+/TZyhJLEo/mJiF3wPeR/kR7oD01RdLYaGJu2Sl+n8D5+y+m7B5oNa1oeqi/DfRphMoaLDEdaOXDpXLzgwklhIzmaFdbHLnPVXD6v2nfKLlp+vLQtDACGvYf8TYOoUXWUwDaFc9l4MfcjMqsFZ+LthuRZTv83sutkkJ1g+8YqUJsyt2NBRvdocPtAx7c876I7bJiyAAD5VABqtcZsCFFqOWRFRfRte8axd1Q37ExmGrBFzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8FbCvt4SDdBMdT39XRoF1F5uTz2UYEJVMtFE5iLC5tM=; b=T7u3pwdCjwBvv7OX3EVZe0kpraLSXCvSou86YoTgGLVhH/79CzaB5F/7mjJdpHhPuMX/yjPgoKq1byYzls0qzY4YtG33R6aE6otTadu9fYsEiDlpoYRGhw/FQUfSu5iroT4495GtuRvgt5OY8Xlmd8ME/gaENNPxcVySq7KU+LmpZW6AgUYRToKuwmKYY2CaBbmV1kuEiTEJ3bCN6r3Lbpsq4kVT6adhqJHRmrvjDkJ2qtRhlwMviRYgbZcS+vdehfOPK9K++ApkwTf12XMTSe7CT2CeK2VqojySww7js2dJfia9n78YZ06lprSrWyRmQjy9IKWtyq2at7fJby2Vsg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM8PR04MB7779.eurprd04.prod.outlook.com (2603:10a6:20b:24b::14) by VE1PR04MB7456.eurprd04.prod.outlook.com (2603:10a6:800:1ac::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.22; Thu, 17 Oct 2024 16:52:49 +0000 Received: from AM8PR04MB7779.eurprd04.prod.outlook.com ([fe80::7417:d17f:8d97:44d2]) by AM8PR04MB7779.eurprd04.prod.outlook.com ([fe80::7417:d17f:8d97:44d2%3]) with mapi id 15.20.8069.016; Thu, 17 Oct 2024 16:52:49 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Petr Machata , Ido Schimmel , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vlad Buslov , Simon Horman , Christian Marangi , Arun Ramadoss , =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= , linux-kernel@vger.kernel.org Subject: [PATCH v2 net-next 6/6] net: mscc: ocelot: allow tc-flower mirred action towards foreign interfaces Date: Thu, 17 Oct 2024 19:52:15 +0300 Message-ID: <20241017165215.3709000-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241017165215.3709000-1-vladimir.oltean@nxp.com> References: <20241017165215.3709000-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR07CA0259.eurprd07.prod.outlook.com (2603:10a6:803:b4::26) To AM8PR04MB7779.eurprd04.prod.outlook.com (2603:10a6:20b:24b::14) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8PR04MB7779:EE_|VE1PR04MB7456:EE_ X-MS-Office365-Filtering-Correlation-Id: 658cc462-abe2-4e46-5bcf-08dceecc222b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024|52116014|38350700014; X-Microsoft-Antispam-Message-Info: GcQrJcVsTqPWSmRHZ1gGL5Rhav5gb4codOflKeA6PYbn33PIhIilUeuxbqfG+6IdZ8Yz02I+tmg+gArCisvIEWths6/aWozeOSMh7dkfOASbSEtIsYu+LamSFFIZoULe2K1pfgPKwHHZfhZYLb83kJVbo8rb9FVq4iUzpppKYHB81HfpGsmgD4jVzrmWgZnZO/ERqQZPXmvaLkaDez7HdBLbDZElFgsMzHZo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XBc3VDhwZtQvb13/TyKcPGd3GtNwQqDjlV63vCKNCakZcVSVQpLAK0lwUtHWMs3Flme9YqBLBCUjb/UyqT56rQD6LpVLDbPqJk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7779.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YSqBdQtUnszXuyHGQETLJEFWn94aJqQY3yTXeOvNzGUaGim2Pab8IG4DVRvSB6tQhWCjCY2ClkEC7R2V4D0Lde+LQ5ABQMCG7nrKG5kYH/uKw2wbQHHnuWN6v5+ztPUQ8x5N5PgzDiYDuLDpal84rdaWmlPeTgPnZ1KQ7LHAhPR8k9D3RAgWMFER/o1gAKBc7gGVgg9D44oBmtCjVEIh2HaYkdtVlCwAU4Nx5svzH8BEmsntpkJMNYiFBXlGUNvnMRuR/hS50W/Zvoau/Zkj+rslJT6Oeq+4Mgg7ukc9H4f/Zv4tXBzq0fPBU5KebhJvWR4q+SylWoNKwVq88R+7W9nE9NglRZDrs8qzPX8xlakn/UJyWyVz3CrMBnX7VfyBewVCmVkgYCqiY9JFd2l0neCx6ZWOZeNcVNYPKaErxyRZbOcS78ZrANrKwPCiYa3EQUgJnTxoau2QDReXPDRJaX6nedHNuZ/Zk1e5RW0G1JTeVJPUNnkOSwaYNqbw+a4Yd360Zrmp3raP26hO2FKQBqgVeaHkNILRHTQsEAqnn6Rx+R1EhpYBtKDy80fEipIzheCgGSvdP0nyLId0o6t2ZvR+/+F/8koi28ujfCICo8tJuDKuyyhI/LQAUNNGVvCaOEwMc62ZV+/npK+B4D806lIKGlYhnBFhd8g+Up/jtNv2HPxfwOfnWHexxiJYdtljCcOssUGbqJeeBKIIHtKjgHaXc5yjF87vO7/cs9yhc1wVAdbAuUOopfF46wQ0wyoUfsw6ly+LSADQtO/NRPs0vBMhnw6DeZF+Vbiqk2rLspP9vx1bJiuDqciCiUDuTxrF5I4burs7YF1g2vXwSgVaS2P4l3nrFct+XpkffitxHznhwZ4PUHTotNTIrZ1FwhwxSKzpCGJJNEiWqZCmMElkw6oyLNtEMbDhMNqyg2H0of5kS2VrJU9aW7kBBkqIVSzq5gJDnNXETGv6m0CI3myD/nBCNbuwle3Pbmmk0kHBDLoL0rR1wrF5prquNL+q8rl1sRku+B7bgCUoqnaZNzsiqKRo2h0tO7htiPozwSrJM+Ao7JDEOWIgNvhWniSROqd3Kg1On/g7rt5GRKYim+Cr6mZIVs3Kvv8Z1WKZX+3eAz7teqkuW+mcuXOZPy3WfXiAlsrlveqk+YNg0T/BycZ1RsKVO64vEJpljKUoqRjLrCUhTq/mjJWIz/5no+VFGmQGU8oJWxrH2N3rrkTnLe1RahyOM+MimGLIwtFCDTqDBGwIcRKWFNnSVS5Jzuom2Qa/W75v/VdXqK/OJPdSeJupGDsvTlyvUry5QM8SrG2aoD7iTgAwNAvR+MXgzKjFBO3kjOHSo7dFITZaLvyiqffRlF9wyoP10pzNdYCaOXwK0Wrut+CiY+8kDYESwUILKzrmzK+ybUsoxqtnpr52y412fHeLGcuObLeAxT+3MF4ZKy3HSzwikwAy7Gshq2u/Szy9N34DKSxBv/JSB8D+DuVr7CaKQVpunUTewSWPcHleLnvIaUXUCMA4WhKeb6kDCXrf+ZTBjEuuY0w+aWMbugwTSqm560KE9TTf5JgkEGJZuCwNg+AsebvzuBu0TNFLbg1AGVjVhe4JiPEED59XP6qlDA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 658cc462-abe2-4e46-5bcf-08dceecc222b X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7779.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2024 16:52:49.4981 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2atl3tRqzsMuUzqW4Jg63DTM6ckvccjItkih3oOxcilseEv3HGn7dhueG/PcWTQif085yjCjJGLYBtV8S5N0Qw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7456 X-Patchwork-Delegate: kuba@kernel.org Debugging certain flows in the offloaded switch data path can be done by installing two tc-mirred filters for mirroring: one in the hardware data path, which copies the frames to the CPU, and one which takes the frame from there and mirrors it to a virtual interface like a dummy device, where it can be seen with tcpdump. The effect of having 2 filters run on the same packet can be obtained by default using tc, by not specifying either the 'skip_sw' or 'skip_hw' keywords. Instead of refusing to offload mirroring/redirecting packets towards interfaces that aren't switch ports, just treat every other destination for what it is: something that is handled in software, behind the CPU port. Usage: $ ip link add dummy0 type dummy; ip link set dummy0 up $ tc qdisc add dev swp0 clsact $ tc filter add dev swp0 ingress protocol ip flower action mirred ingress mirror dev dummy0 Signed-off-by: Vladimir Oltean --- v1->v2: allow mirroring to the ingress of another ocelot port (using software) drivers/net/ethernet/mscc/ocelot_flower.c | 54 ++++++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_flower.c b/drivers/net/ethernet/mscc/ocelot_flower.c index a057ec3dab97..e502226df4e7 100644 --- a/drivers/net/ethernet/mscc/ocelot_flower.c +++ b/drivers/net/ethernet/mscc/ocelot_flower.c @@ -228,6 +228,32 @@ ocelot_flower_parse_egress_vlan_modify(struct ocelot_vcap_filter *filter, return 0; } +static int +ocelot_flower_parse_egress_port(struct ocelot *ocelot, struct flow_cls_offload *f, + const struct flow_action_entry *a, bool mirror, + struct netlink_ext_ack *extack) +{ + const char *act_string = mirror ? "mirror" : "redirect"; + int egress_port = ocelot->ops->netdev_to_port(a->dev); + enum flow_action_id offloadable_act_id; + + offloadable_act_id = mirror ? FLOW_ACTION_MIRRED : FLOW_ACTION_REDIRECT; + + /* Mirroring towards foreign interfaces is handled in software */ + if (egress_port < 0 || a->id != offloadable_act_id) { + if (f->skip_sw) { + NL_SET_ERR_MSG_FMT(extack, + "Can only %s to %s if filter also runs in software", + act_string, egress_port < 0 ? + "CPU" : "ingress of ocelot port"); + return -EOPNOTSUPP; + } + egress_port = ocelot->num_phys_ports; + } + + return egress_port; +} + static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, bool ingress, struct flow_cls_offload *f, struct ocelot_vcap_filter *filter) @@ -356,6 +382,7 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, filter->type = OCELOT_VCAP_FILTER_OFFLOAD; break; case FLOW_ACTION_REDIRECT: + case FLOW_ACTION_REDIRECT_INGRESS: if (filter->block_id != VCAP_IS2) { NL_SET_ERR_MSG_MOD(extack, "Redirect action can only be offloaded to VCAP IS2"); @@ -366,17 +393,19 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, "Last action must be GOTO"); return -EOPNOTSUPP; } - egress_port = ocelot->ops->netdev_to_port(a->dev); - if (egress_port < 0) { - NL_SET_ERR_MSG_MOD(extack, - "Destination not an ocelot port"); - return -EOPNOTSUPP; - } + + egress_port = ocelot_flower_parse_egress_port(ocelot, f, + a, false, + extack); + if (egress_port < 0) + return egress_port; + filter->action.mask_mode = OCELOT_MASK_MODE_REDIRECT; filter->action.port_mask = BIT(egress_port); filter->type = OCELOT_VCAP_FILTER_OFFLOAD; break; case FLOW_ACTION_MIRRED: + case FLOW_ACTION_MIRRED_INGRESS: if (filter->block_id != VCAP_IS2) { NL_SET_ERR_MSG_MOD(extack, "Mirror action can only be offloaded to VCAP IS2"); @@ -387,12 +416,13 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, "Last action must be GOTO"); return -EOPNOTSUPP; } - egress_port = ocelot->ops->netdev_to_port(a->dev); - if (egress_port < 0) { - NL_SET_ERR_MSG_MOD(extack, - "Destination not an ocelot port"); - return -EOPNOTSUPP; - } + + egress_port = ocelot_flower_parse_egress_port(ocelot, f, + a, true, + extack); + if (egress_port < 0) + return egress_port; + filter->egress_port.value = egress_port; filter->action.mirror_ena = true; filter->type = OCELOT_VCAP_FILTER_OFFLOAD;