Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp119208lqt; Thu, 18 Apr 2024 09:58:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVw9ExyXRCxBDbk8uNL1ZiQt45Tgr7anXwv3GtVVgQE5BqlGnuscyKCOuI07h1fE77RJa86YwdCjqOTeixaRBuRWwWX4FoNbE5p1nJG1w== X-Google-Smtp-Source: AGHT+IE/IDEaFcEDSNel5FeJMAp4eWno1urHXP5b+9Y0sbht829LAxX5jvctAL5jmj7ZDdHe48Tb X-Received: by 2002:a17:90a:d3c5:b0:2a0:4e60:ba46 with SMTP id d5-20020a17090ad3c500b002a04e60ba46mr4152750pjw.16.1713459501396; Thu, 18 Apr 2024 09:58:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713459501; cv=pass; d=google.com; s=arc-20160816; b=SVqDyA20DJgRm0voHDsAVvojbUPHHZgQRCdFo9WHvaxhczDi5WrZPH8FqeVSFENdFC 9Stn6B1HAP8dMb5ak+wBzPuap7Slv8IgnDwnno2L1zlBBDpvrc48QhRfVb7gHeD5ts7c cxSOqNdL2HvWvEodbJq9nx1itOa54y7lcV1gjCiK+8P6uXoETu81NGRHnPyiiu6RXJE3 76l+ezYO9TDKNP3pKqDDi4VfEF/OhTIUuqeZJs7G1ibYKTNXr/ZMVZ8Mtug2KqFK9SaR s2y7hrQkRB0am/5w1Q5ZKNe9Z4uUT3A5cDqyKQorHPsW+CyK4eoujyoSSHkwRrgGgXY8 tBYw== 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=VPn1y/qpv0nLz7/gRA7kwkE1Lio7Ewd+eE+RIoEmS+M=; fh=UQq7t8uvK2iUNO1MW2Ou8S2LAb+LVP9puPAKMbRd+Ns=; b=wJYYggKm+Y5rcESJt+vSWeUWuwPRyePXvzcbNan8uh6O2sfoqmc8SVMx59UH1DjOk1 GFtZ4L/EWoYBohSTf8gc8RncuGJ93mfSldhKddM1J53CaMnzv3QtinkH82nl1wqpeZfH FKJsRieAL6DjlFWKSTD/G5KNDf5+PARMuU9TAf/B/qTo3RVOVzVWn/GjT/X+rEgwpbL0 9z0gPfCE7ReNJ55QTLjZeOerSrB5hcg0JF5UL9MkqnjbxoMnOu7adUUSFEAlaVXinogx 9hk9xxi+z0gToNWO7jJmeJ2i8apPSLgHxOAm83/fa/Q7HxRgzYzOQFWOE7I6/gC2yImW NShw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="k2/ST5Gv"; 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-150523-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150523-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u19-20020a17090abb1300b002a5ffe8552csi3382043pjr.150.2024.04.18.09.58.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:58:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150523-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="k2/ST5Gv"; 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-150523-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150523-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 12C4C285D43 for ; Thu, 18 Apr 2024 16:57:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 452B7173343; Thu, 18 Apr 2024 16:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="k2/ST5Gv" 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 90BA216F29F; Thu, 18 Apr 2024 16:57:20 +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=1713459442; cv=none; b=tP2IrrzGZ2VDpugT2JvKuWJHqJJTI+YuSGju8ngnSsOhbDZQECT7oLZtt5EhNTXFtAEIzAXz4/K5X+icvt8o9bQfFmAu+yxoBjRQ7AKvzrBleTqOyVPgwb/0tZnL4MkMapwVyMvda5HSN4pH+es4+5DMGVyOQnNwFAs0ZB6W2bM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459442; c=relaxed/simple; bh=JSxhXh6RPEu44GhG9pzlc/+ekiyPeScDzIdegYj3TeE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=k0kn9MpcUXPNcgMU1NrylL/CZLzGgumq42wyGpfkgDQivbwgd2zSdk1R85l/zf0ppUoeJDEaHrd2b6auQZoIc87g7j03Now0V28jDZw7cWl2/CB7BSut1BND/j+ywkqXNkGBarsjcEoYvQZYL9ftQCB7BtXrwE3WyATPlLd81Q8= 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=k2/ST5Gv; 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=1713459440; x=1744995440; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=JSxhXh6RPEu44GhG9pzlc/+ekiyPeScDzIdegYj3TeE=; b=k2/ST5GvWVQDCeKE5py/HfitdtKCoxzFPkHBGclyIx9UtLr3+Qpn3weU T+84N+JbLfVjRVakMV6/zQkbytY1Nm10AARz8dkWICbKyZfNGIQCrWUEU cdWMTZTvYLvUyQouqbjdml/mOCcg7pmRlJP9xgtxU/mZm3HXj3xiTPaRh 9MY7XgcN5BShqG6dmzuCOyqdNHBFqvDTfImp75FeehKen3+rC3tV6ODke 8nmEx4hKlAON8WuihqnzdE+f0ORp3HGXUZr4njLtAWE/bh++V+F/1WdMa INNhQRtJQXfNG114vR/u7py0B5y2lMUSg0cMkm8lEpxok4+RIaCXohiDP Q==; X-CSE-ConnectionGUID: IpAKQTwwQLuvUOb4hfuiSQ== X-CSE-MsgGUID: iOTLrk4UTDWqDF7PYp7tHw== X-IronPort-AV: E=Sophos;i="6.07,212,1708412400"; d="scan'208";a="188927089" 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:19 -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:50 -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:47 -0700 From: Daniel Machon Date: Thu, 18 Apr 2024 18:56:35 +0200 Subject: [PATCH net-next v2 2/5] net: sparx5: add bookkeeping code for matchall rules 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-2-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 In preparation for new tc matchall rules, we add a bit of bookkeeping code to keep track of them. The rules are identified by the cookie passed from the tc stack. Signed-off-by: Daniel Machon Reviewed-by: Steen Hegelund --- .../net/ethernet/microchip/sparx5/sparx5_main.c | 3 ++ .../net/ethernet/microchip/sparx5/sparx5_main.h | 10 ++++ .../ethernet/microchip/sparx5/sparx5_tc_matchall.c | 62 +++++++++++++++++++--- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c index 3c066b62e689..b64c814eac11 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c @@ -899,6 +899,9 @@ static int mchp_sparx5_probe(struct platform_device *pdev) dev_err(sparx5->dev, "PTP failed\n"); goto cleanup_ports; } + + INIT_LIST_HEAD(&sparx5->mall_entries); + goto cleanup_config; cleanup_ports: diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h index 316fed5f2735..4de37a5387a4 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "sparx5_main_regs.h" @@ -227,6 +228,14 @@ struct sparx5_mdb_entry { u16 pgid_idx; }; +struct sparx5_mall_entry { + struct list_head list; + struct sparx5_port *port; + unsigned long cookie; + enum flow_action_id type; + bool ingress; +}; + #define SPARX5_PTP_TIMEOUT msecs_to_jiffies(10) #define SPARX5_SKB_CB(skb) \ ((struct sparx5_skb_cb *)((skb)->cb)) @@ -295,6 +304,7 @@ struct sparx5 { struct vcap_control *vcap_ctrl; /* PGID allocation map */ u8 pgid_map[PGID_TABLE_SIZE]; + struct list_head mall_entries; /* Common root for debugfs */ struct dentry *debugfs_root; }; diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c index d88a93f22606..2a33b347098f 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c @@ -11,11 +11,37 @@ #include "sparx5_main.h" #include "sparx5_vcap_impl.h" +static struct sparx5_mall_entry * +sparx5_tc_matchall_entry_find(struct list_head *entries, unsigned long cookie) +{ + struct sparx5_mall_entry *entry; + + list_for_each_entry(entry, entries, list) { + if (entry->cookie == cookie) + return entry; + } + + return NULL; +} + +static void sparx5_tc_matchall_parse_action(struct sparx5_port *port, + struct sparx5_mall_entry *entry, + struct flow_action_entry *action, + bool ingress, + unsigned long cookie) +{ + entry->port = port; + entry->type = action->id; + entry->ingress = ingress; + entry->cookie = cookie; +} + static int sparx5_tc_matchall_replace(struct net_device *ndev, struct tc_cls_matchall_offload *tmo, bool ingress) { struct sparx5_port *port = netdev_priv(ndev); + struct sparx5_mall_entry *mall_entry; struct flow_action_entry *action; struct sparx5 *sparx5; int err; @@ -27,6 +53,16 @@ static int sparx5_tc_matchall_replace(struct net_device *ndev, } action = &tmo->rule->action.entries[0]; + mall_entry = kzalloc(sizeof(*mall_entry), GFP_KERNEL); + if (!mall_entry) + return -ENOMEM; + + sparx5_tc_matchall_parse_action(port, + mall_entry, + action, + ingress, + tmo->cookie); + sparx5 = port->sparx5; switch (action->id) { case FLOW_ACTION_GOTO: @@ -59,6 +95,9 @@ static int sparx5_tc_matchall_replace(struct net_device *ndev, NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action"); return -EOPNOTSUPP; } + + list_add_tail(&mall_entry->list, &sparx5->mall_entries); + return 0; } @@ -67,19 +106,26 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev, bool ingress) { struct sparx5_port *port = netdev_priv(ndev); - struct sparx5 *sparx5; + struct sparx5 *sparx5 = port->sparx5; + struct sparx5_mall_entry *entry; int err; - sparx5 = port->sparx5; - if (!tmo->rule && tmo->cookie) { + entry = sparx5_tc_matchall_entry_find(&sparx5->mall_entries, + tmo->cookie); + if (!entry) + return -ENOENT; + + if (entry->type == FLOW_ACTION_GOTO) { err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev, 0, 0, tmo->cookie, false); - if (err) - return err; - return 0; + } else { + NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action"); + err = -EOPNOTSUPP; } - NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action"); - return -EOPNOTSUPP; + + list_del(&entry->list); + + return err; } int sparx5_tc_matchall(struct net_device *ndev, -- 2.34.1