Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp119122lqt; Thu, 18 Apr 2024 09:58:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUv0WTmudY448wbSdV5QRzCuQ7qZNHZ/obN755K3qYjbyDsHCMExSo0LHMc6h3/vDLWVEAf8pM+jVw9H9pYa46poVs930GC8jy34cKB5Q== X-Google-Smtp-Source: AGHT+IEGtHQIOBq4TaUfPDpqXmgX0obNIv0kKM3LhCpGjIjXm88pZh1qcVtsLW/3vPbI/XLMn7ag X-Received: by 2002:a17:906:4152:b0:a52:9e:45c3 with SMTP id l18-20020a170906415200b00a52009e45c3mr2201800ejk.35.1713459491084; Thu, 18 Apr 2024 09:58:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713459491; cv=pass; d=google.com; s=arc-20160816; b=Tq6IRyElQ7Jbon919WowRiR2+hne0VYalXP/tm7JR5AMmYmpvBinI8j98NsD7CV/X/ /5Sv+MX8U0olTrzsAqFdeylP9G80XzHxzZR3beuZMfei+QwMxuOQcDgWC8E26gb5zirr mE14UjD6RAzEfjLB05w23RnYjFQi0UKg0xihdiUspidpjjKuxXJOBLqKiP+JdwnkchOP ujja7ELVgZBXXT7X6TvTEp4i2qRNeqyorWXpiYIC2qVedl0dgFec6XNFbEDnEJmFAjjb iKhVmren/CBYj/N2BxywONH/TEIxTJAu7ucgJrlk2CpppvNYeXfT7WeLRXVmK6rbuzxh TlnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=6GI+bfSpKFQufBXzhyzn2snixrfj9YklVS6ureOVzSw=; fh=UQq7t8uvK2iUNO1MW2Ou8S2LAb+LVP9puPAKMbRd+Ns=; b=UUVmtHqsBNwr+yudgfvc2g8jlUSWAhygFVM2vEXXNiyqBMdhKl5GAkkSxpzAqtbyEp yGkme3Qtbqz1Of1DMS8f12s0ZRbksDrSd+3tbSH299DItuUpo5XwtRhFFj2zgVMa54sa vy5k15OaXMjTBRLlJI1A+K4v1RC4YOf3yvmgE+ubreMPiWV5u0wJh7itQuszNc8maHZB V7paZYzgml2Fs8cerkLckgyAc/umk49KYq9QdmAOADH9cjliWon8iGCwprqM9Kit5KKV iaktHufbnSFIp1X8kmce2t1KE293KZ4qyDCJoB2mMKMW49jAFwrhdrOkr0QGPqvE9foo Gbvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=bOY1D7T4; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-150525-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150525-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j26-20020a170906475a00b00a52177fae29si1152940ejs.393.2024.04.18.09.58.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:58:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150525-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=bOY1D7T4; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-150525-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150525-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CBD5B1F21F03 for ; Thu, 18 Apr 2024 16:58:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87A9D176FA8; Thu, 18 Apr 2024 16:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="bOY1D7T4" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (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 37214171E57; Thu, 18 Apr 2024 16:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459443; cv=none; b=TgVQ/mMewTo/AOUCqD5Yb3n8Ii4eEXyUzFu2ExVM173zcQSV+HQWrhr/ps9K+ubmVlYQ99Rirtwg5L80+zPgszvOO8AHdvepYnNyOYRTcBaGSYBjFMs6WHb4hToXk6kyMbgO9r3VtY35kM8Pidy2XKpszficOK7VLRf8viFKZkE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459443; c=relaxed/simple; bh=Ik9EQbMe8HbPkSq9sr1NNJbIkQ1gQWFBQhm04HdPJ9w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=kes7jxeOPDjiV/rCl7nPYPROA6waj0ljQEbUC/y+zRLgyDPpIshF/Td/YlYwI2+M0wF5Xh/knPnJ9hp0WhYjanw1QBamIkihTcOo022PZaSrHrltuoqKDztaosPes4Rp86IdHBoYGWC0t97tPZi0YG4208oOBzMzEB7nmNRKWIs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=bOY1D7T4; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1713459442; x=1744995442; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=Ik9EQbMe8HbPkSq9sr1NNJbIkQ1gQWFBQhm04HdPJ9w=; b=bOY1D7T4s8c/Mn/x3Q1r13PR5LbCNQfttZtdHM4C99uEOg6dJ2kquADw fOk10Od+hrUfCuky0oMXgpsP3zc+m9rPm71iNclrZpCiDHVuTrRz495Ge l4rbbXuAjpzXJ5mzyNRgseMVvyW4D3QialTfnCzSyBV5/yuZXhRSCUe2e dRBKexTZ4MZdKC0mA6C5vB5jWXcV80XrnGNk8PyAq4sSkPzEaRtgMtX+N wWm/MS1D8ab1sHY3mxD5qXWAeuH6gJhxyRtONxHPzUDM31XJgRZtwURy+ 8xpKofbAGIsxiZ1ciXw5LMoquMSyD60ZqRkf5PxFNfY0fQIinXn+bxjds A==; X-CSE-ConnectionGUID: IpAKQTwwQLuvUOb4hfuiSQ== X-CSE-MsgGUID: xFkCMSo1RuO+dq8goH7Zsg== X-IronPort-AV: E=Sophos;i="6.07,212,1708412400"; d="scan'208";a="188927092" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Apr 2024 09:57:20 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 18 Apr 2024 09:56:57 -0700 Received: from DEN-DL-M70577.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 18 Apr 2024 09:56:54 -0700 From: Daniel Machon Date: Thu, 18 Apr 2024 18:56:37 +0200 Subject: [PATCH net-next v2 4/5] net: sparx5: add the tc glue to support port mirroring Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20240418-port-mirroring-v2-4-20642868b386@microchip.com> References: <20240418-port-mirroring-v2-0-20642868b386@microchip.com> In-Reply-To: <20240418-port-mirroring-v2-0-20642868b386@microchip.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lars Povlsen , "Steen Hegelund" , , Russell King CC: , , , Horatiu Vultur , "Russell King (Oracle)" , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Vladimir Oltean , Yue Haibing , Daniel Machon X-Mailer: b4 0.14-dev Add the necessary tc glue to add and delete mirror rules through tc matchall. Signed-off-by: Daniel Machon Reviewed-by: Steen Hegelund --- .../ethernet/microchip/sparx5/sparx5_tc_matchall.c | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c index 2a33b347098f..4f9ae026fa47 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c @@ -36,6 +36,13 @@ static void sparx5_tc_matchall_parse_action(struct sparx5_port *port, entry->cookie = cookie; } +static void +sparx5_tc_matchall_parse_mirror_action(struct sparx5_mall_entry *entry, + struct flow_action_entry *action) +{ + entry->mirror.port = netdev_priv(action->dev); +} + static int sparx5_tc_matchall_replace(struct net_device *ndev, struct tc_cls_matchall_offload *tmo, bool ingress) @@ -65,6 +72,31 @@ static int sparx5_tc_matchall_replace(struct net_device *ndev, sparx5 = port->sparx5; switch (action->id) { + case FLOW_ACTION_MIRRED: + sparx5_tc_matchall_parse_mirror_action(mall_entry, action); + err = sparx5_mirror_add(mall_entry); + if (err) { + switch (err) { + case -EEXIST: + NL_SET_ERR_MSG_MOD(tmo->common.extack, + "Mirroring already exists"); + break; + case -EINVAL: + NL_SET_ERR_MSG_MOD(tmo->common.extack, + "Cannot mirror a monitor port"); + break; + case -ENOENT: + NL_SET_ERR_MSG_MOD(tmo->common.extack, + "No more mirror probes available"); + break; + default: + NL_SET_ERR_MSG_MOD(tmo->common.extack, + "Unknown error"); + break; + } + return err; + } + break; case FLOW_ACTION_GOTO: err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev, tmo->common.chain_index, @@ -108,14 +140,16 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev, struct sparx5_port *port = netdev_priv(ndev); struct sparx5 *sparx5 = port->sparx5; struct sparx5_mall_entry *entry; - int err; + int err = 0; entry = sparx5_tc_matchall_entry_find(&sparx5->mall_entries, tmo->cookie); if (!entry) return -ENOENT; - if (entry->type == FLOW_ACTION_GOTO) { + if (entry->type == FLOW_ACTION_MIRRED) { + sparx5_mirror_del(entry); + } else if (entry->type == FLOW_ACTION_GOTO) { err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev, 0, 0, tmo->cookie, false); } else { -- 2.34.1