From patchwork Wed Oct 23 13:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13847138 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2089.outbound.protection.outlook.com [40.107.22.89]) (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 D77611C82F0; Wed, 23 Oct 2024 13:53:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691602; cv=fail; b=LH+DGEhhtxlvCPNY5SXIqA7/wd/i8PtW/dULNvebeEYn4WuItKF7YxmedEPYPzVKmX3QkXM4wkUR1F2iGDUH9Ri0LEuyTRi9UmIdpECPKXezdTCEHengUmxSNuBdsl/3UZm46/1cux8yyfJMOOlScSe1xxLSMDa4j/ovLUcvYWU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691602; c=relaxed/simple; bh=qDQ4/apa5Np7DxGWe6lGoYYxJFhwh5/w/d6B/gN64uk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=h0Gpxc00UADtrfq+FiUKP96DsrKuMKDUWn1loL9CcWAZcVLBp60m6Gz0WNBgVuWimVBbsF1tE16irVf8QEGQxVI9/GG/aC+D5N631XV76FBSM2X6KjSc/GgMDgc7l82MHN36gUEKhmZ3V+jQKQsVr4oWWu+lzigOBNguzA8+rqo= 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=jsRC3kJT; arc=fail smtp.client-ip=40.107.22.89 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="jsRC3kJT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L8XftjDaiDdxLqNCQmM83of4erS2zY5fUtwywEp0GM9B7U0K1EstZPqLIA0MgUtAv3YJHymBXqo3Of3qhF3D+oK43ktNF3iK4ZEbyURCTYABiFcmavteElD+uc5vPTrwT2wqZw8dGPmxWmDLwgbwlP2sYOTBHI8FU1sYary3711BTJOv1OgTcAKf5rHWTCr/CN5ioLqXVvAJ8EaXmCuR1Fun+hE+JCAR6Ghg8cOh6QRSGoPWqAlIgSvYkcT5bJFry1cBypuoE6za+Oi7tmV8Vxi0woLQsg8qt0hhrSmcfA4cjJOEFzdDfIvQOjSxZOafDmPkEaF6tM1p6hJfMASTmw== 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=GJhl1Detx37WtzzPxfRpyz7V2fR+D6VNo/usW0FxOm0=; b=YeTJ/YH1/HV8DHlCx7mYY6i4YvPs7+8PyDR/ScC6eIvogD7N4ntfGdblb190hBX9ZK7YiK5eOCkNUGPEz7CEVKsaNsXcnGNCI2Fk+5DeHOS16LOUNPaQjoTdaBQLGGW/WbhdEItCLb7kyc10tv3JCe+KzmGbab3jIFa5gLT8B8QruglyqPbUPCM8uRahlvfRRa0ZATTC5OgDuxuiwgXqJchp0+xG+aBRgigbAlaKTOyJkAeFs4m8CljNisw5LyKku34rq2DB1xIZZ4HL/ErgDNtjDhSVJw3OkrcpoWw4B24WaMVCOH+qCwMXPhxGpeV8SAIlKWdEPA4ds70yLIIeSA== 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=GJhl1Detx37WtzzPxfRpyz7V2fR+D6VNo/usW0FxOm0=; b=jsRC3kJTVpHQrh7eC6+FYPiKniNbK2Q7L+NlIeRm42Ez3ahmrr/96Tvat+RoZxWwoe4PERU3/S7T0/XDiLx+DCDPyU78DCG6InFVhEEZ4QBeGpYmneoQxAAKTATuLT1WchQjdtOsvZrP0OKbPC7MkVaZ8P442Dbr2AbtU6lbvxp8eM/zoG5Z0A4wxagz3r72XrKFnBDcZK8wg13qkHvOs9Wm2+d2rTYRR4UnlcOb/M0bHta+TcWmC+zRMv4tywuS+p7fMhzCy9Nrhcm0sVzfR1/1ZuCW8VhAUaljvm5wmC5vHYqrcY6H6xsmj33M1NsiwihCizjME77LR8YgJXRdMQ== 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 AS1PR04MB9683.eurprd04.prod.outlook.com (2603:10a6:20b:473::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.18; Wed, 23 Oct 2024 13:53:10 +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.8093.014; Wed, 23 Oct 2024 13:53:10 +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 v3 net-next 6/6] net: mscc: ocelot: allow tc-flower mirred action towards foreign interfaces Date: Wed, 23 Oct 2024 16:52:51 +0300 Message-ID: <20241023135251.1752488-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241023135251.1752488-1-vladimir.oltean@nxp.com> References: <20241023135251.1752488-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR10CA0105.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:28::34) 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_|AS1PR04MB9683:EE_ X-MS-Office365-Filtering-Correlation-Id: 44b3559d-3226-42f2-5f4a-08dcf36a07cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|366016|52116014|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: RrsnBsbfGVqFo0rmpBfg3938QxBRi5rlXYhlV10Jq3Y+btWKrZNLgzzRsx+iNM7q1lgKnJtjDLAhX2zrq/2vVs1xqvHlf1AeoGbkikdWJyNMqwfzvMQL4bS3a3t8TffYNMuop6yhehQoCxVQ9j70PbwQQxKOec3RjoVB1wKWgnoyOorIvMeDGOMnT5y1ODJ9QiAUOxca2lFlmFoHyt1h7clnfMSJTwyiufZtbZ1pq7M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3KncGvAC88nBc23junDcwvi2eiaJmME4vpAyfJeV/RoraEHKSUIp6ueSghb1hXbjVw+72ykWnXeo= 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)(366016)(52116014)(376014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6vDxSwcFzfLr4o1LoS+UH2jdiCtwjJQoEnUSCi67e4eDbo4x/a4Q2aFRUV95sC+tAgseWGQf3QWHIgGr6siWL/Td2hQCIuNONKL3UKQB07gGKiX9e5nNqHJ7C81++6I27+FE6ImSM61y0cpip2FuqRc9DLBWpOq7JM7iLPOC9R3HN+8/FelL8uorTfvHgmOomgftaeJkDPNZLb5HcsDAMknMl4/yIbgHJnCJSwmjDXarXKWSCE5bj9vars2MLN5QbxAbpSGvJD1wMhXKyHeLBg0g9hvRciOamdZr9GQsvmeI/iOkzGUT8tguy/E/6zVxbjvOhpUbqDcoDBO7+sPp9Bhr8/B0WIuSxYvGLJNXAsiKuo14CzxiIGbOxoEcTW9OpfxsdS2jJAI4G6bWT0TfkRXXqD3J7mWV8ZnKxcXf6K+O+3LKyoBYpJGp6q3p3LSRVzB7AmgyHT9Jq84cjyAkzMQHetLCYvEKf/YiHwXbew1t3GBcTxit8f9KqF1aV3NGSPmjCaJ9hGK04DN3hFhfqUdCJiLmqyge3a8qL8o9jXDhN9nf9gd8mAsx8baKLLyhwK1hvQO0J4XsrnX7a5BJBHgdsxCyRmb+rn+SSNz3/e6xpJYfReBSWIdJdIQiNhL2+LH3qWpQiYotVNU4U+n2oli1PUWvVc68A5xs429ITwbcEEaAURc0FRBfFEej38qIRyfjMdHQX2wM+IU/4Nzdo1JKOvIofTYTumEURpxQ3jsr+xCik7VIWPELx8H7TCNPLuj4pyfOzJtbrKmeQINojfEU8J/glFuI8oqnNlcACfZmT937pJCeMaavPrMigoigQ1ZOJSt8nJHesf4d5mZk01Q7e+ZQngj3KyOs76S+89Hg7hWzrhZf80E40ur/AqSDUVdocDkhaUe1Yp13o63msdFJbujHSnT136zYbdBlYp6YA6ThmrPqcsXls3szBkapIgWNttkXiWMJaqUlb3JKGA7CCh6jWmj3zbFtDe0yZHxkWwn6RKdcPMh2egGXT1rIHYNsOSGMKV+fwiflOulujdNoOdMFU8IaIwGWXFWyUMTcwL6tNHp53p09f0LsFrWnnNrt7h8LpoF8kBA68PvlRIYoaMD2T7LAD7fYdC6TdwD2jXg06CFtT2vf6gzeGUNADvkob2nW3+/CK6rjgzDvfAuMPdujvnYWrpp7m0qSbpSzr3NU9oDDq2wUxc27IBnE3r6aR0sOCe8lFnK9vcq4ZAFYo9Dpc6I23c1y89dy13s+B2BYeL7BIi9vei9CnInemgjWa84SdLlrdVL2xhwWKUEywQF/XDnYMc6IhDPUoJwoSnWIhtMZzRpNU/4RJ/MGFZuPpi/Lp0DZP1hrddviftikUp7suUywdnm/wHpm7kgsh5fHbnS/FEtubtretd3lIg/tEug6hLLx+abjoNJydj9KHo6r5MHa4NsDDRI7ONKVkIXDNcXG2lB7FkCKDzXL+UT442dafK4hNrDtsy3eqoyrHI0TfAKQuSkKAPRS1yp/FeV5XvOuhSyrJaw+CB3QFLF7LjKt5Rfuamfb+mMw7/ps/c3dCne0NQtDIXUlFpXYebWaGqwmveWiOmrd+I4HwToADvvzVSBEcd3nNFuchA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44b3559d-3226-42f2-5f4a-08dcf36a07cd X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7779.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 13:53:10.4027 (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: /HOQmtUmMmRCCF50vUVGIC8Ij+I6/NnwnWCEK+Aa0cWX6FHD4bXRiINuEeSZGTCRSLoOzwm8v3hLkXMbQVxBeA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9683 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 --- v2->v3: s/f->skip_sw/f->common.skip_sw/ 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..986b1f150e3b 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->common.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;