Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1769383lqm; Fri, 3 May 2024 06:15:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVAe0GpNOpZPBlxaNfu1scOB1R7HSSHU+ijDlWOeeTcbZU6ziikcjPbzhFNeiGB4LS0EhvqRiFJB9tFa1X3XPyyARkpR60lIvdfTxgLMg== X-Google-Smtp-Source: AGHT+IHqecHEHIQ1HQLyEPIzUJImpeVdD0/849zKs91Tu/eLan/xzV047Omczr0tbED22P0CV0S0 X-Received: by 2002:a50:bb45:0:b0:572:8b30:bef7 with SMTP id y63-20020a50bb45000000b005728b30bef7mr1471910ede.2.1714742104140; Fri, 03 May 2024 06:15:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714742104; cv=pass; d=google.com; s=arc-20160816; b=Ldsc1+KoDV+zIHQ7wztDBKDIBaccJlyUqVSOYh3WF5EPRljUVWl5ezu3coQOxf/iF/ 1JfVH358rNfPl56bWmQeg5M8rjQ+E7GgC8O9buSNGjju2RFJEl5/+HFvitPw+G+QyEN4 jl8arHwc93EagRM2STaH4EFNCaeeqPj/USdfdxp3ASg/S0UCeP9v04obMTiLsKx8dXQX U13WobPY6DLOruBUoxRbPYVCQcsjPTvY1V9/pu4t79Kq2KNYQOsicUz4G+t3Fln9iGxy Z4FinIKb1z5Y4j9VR+7oR4D4f14x+b4r6Bii2Wa0efn2pbhA4jz1egjR176Z5xa8cXOI mTbA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=kmQjfv58QMYRQ5/sZVVTjZckHQgCh4heFMlhfKITSEQ=; fh=tqC39tIlS6D/RAQt4n0YdpNSF39XxlRBPCEXedsdbGs=; b=XWR7lX9XopnLSCgs0ZGHBhN1bKHkzcd+aIQcVu7P4EIEfx0gGnGqnbPgm4/2nlsPX/ dgRLBCO3wOSYCXJSIJMgf0SBmeV47xuutPyeUfhdVq/VBjfgQ7GYn4Ul9q/vXLjAWegz HvNHjgI+R5lut653sR3w0ZppEiXDHa1dRylCYJSyrzeAX/4ZnUNVlMsJfHF2v2ixBonj 1MLk7SBbYfxiH+M1F7aiRAQB1/gyRgER+UkGBvYpJS+9C7FZWC1wMi0sI8HOqbmlTZ+K 9F6HJscmuj21WpF8fJy3XApVomWY8MXzKImoAJOHuYsOtTwjyPVFli5UnwC/fSjtt0V5 2erw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-167678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167678-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w6-20020a056402070600b00572a07b01a5si1494973edx.650.2024.05.03.06.15.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 06:15:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-167678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167678-linux.lists.archive=gmail.com@vger.kernel.org" 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 D8CC01F22560 for ; Fri, 3 May 2024 13:15:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27B48154C1C; Fri, 3 May 2024 13:14:14 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 A434215358F for ; Fri, 3 May 2024 13:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714742052; cv=none; b=X9VQ9hrnkijRKkGwCaPOHnsRvIe6WKyIt8yUiGoyIwDhUKdj29soAXltRqf7X08C3l4SRfX4nnaDxJyJz4qvvIgROc/hXxBUVsUs+QCCOCNKR/mAe92x3mVuB0K7Ci+IjH9aRKsjMNVPGvEGoRHd9JT8FVq9whTt+BEkYAslUDA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714742052; c=relaxed/simple; bh=CMmR1PQCL8CPLw2XGxubBH3eRd4+D/IB7iVro70lnfQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n8/gcBXBPOx8Rjs8IyFL5SOz96WsLy994/v3a1DOhqqyv+2eA7I4je47RU/oZbGhFLEsRBfgaJzbIexhOOm0AAGtkR5UmCfmDAcajLAhtZsRUwK6ehD2thP+yP9ibJbrf1iu6ZR6LkJ8x2Uf70Tz15eCoyboRLBI8sIZAM5jZr8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s2sjb-0006EL-6l; Fri, 03 May 2024 15:13:55 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s2sjZ-00FiKN-Sr; Fri, 03 May 2024 15:13:53 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1s2sjZ-008GI0-2S; Fri, 03 May 2024 15:13:53 +0200 From: Oleksij Rempel To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Woojung Huh , Arun Ramadoss Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, David Ahern , Simon Horman , Willem de Bruijn , =?UTF-8?q?S=C3=B8ren=20Andersen?= Subject: [PATCH net-next v7 10/12] net: dsa: add support switches global DSCP priority mapping Date: Fri, 3 May 2024 15:13:49 +0200 Message-Id: <20240503131351.1969097-11-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240503131351.1969097-1-o.rempel@pengutronix.de> References: <20240503131351.1969097-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Some switches like Microchip KSZ variants do not support per port DSCP priority configuration. Instead there is a global DSCP mapping table. To handle it, we will accept set/del request to any of user ports to make global configuration and update dcb app entries for all other ports. Signed-off-by: Oleksij Rempel --- include/net/dsa.h | 9 ++++++ net/dsa/user.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 40c127a301878..b60e7e410aba7 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -433,6 +433,11 @@ struct dsa_switch { */ u32 fdb_isolation:1; + /* Drivers that have global DSCP mapping settings must set this to + * true to automatically apply the settings to all ports. + */ + u32 dscp_prio_mapping_is_global:1; + /* Listener for switch fabric events */ struct notifier_block nb; @@ -586,6 +591,10 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) dsa_switch_for_each_port((_dp), (_ds)) \ if (dsa_port_is_user((_dp))) +#define dsa_switch_for_each_user_port_continue_reverse(_dp, _ds) \ + dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \ + if (dsa_port_is_user((_dp))) + #define dsa_switch_for_each_cpu_port(_dp, _ds) \ dsa_switch_for_each_port((_dp), (_ds)) \ if (dsa_port_is_cpu((_dp))) diff --git a/net/dsa/user.c b/net/dsa/user.c index f4ac82e8a39e8..b9dd508f1fd9e 100644 --- a/net/dsa/user.c +++ b/net/dsa/user.c @@ -2189,6 +2189,58 @@ dsa_user_dcbnl_set_default_prio(struct net_device *dev, struct dcb_app *app) return 0; } +/* Update the DSCP prio entries on all user ports of the switch in case + * the switch supports global DSCP prio instead of per port DSCP prios. + */ +static int dsa_user_dcbnl_ieee_global_dscp_setdel(struct net_device *dev, + struct dcb_app *app, bool del) +{ + int (*setdel)(struct net_device *dev, struct dcb_app *app); + struct dsa_port *dp = dsa_user_to_port(dev); + struct dsa_switch *ds = dp->ds; + struct dsa_port *other_dp; + int err, restore_err; + + if (del) + setdel = dcb_ieee_delapp; + else + setdel = dcb_ieee_setapp; + + dsa_switch_for_each_user_port(other_dp, ds) { + struct net_device *user = other_dp->user; + + if (!user || user == dev) + continue; + + err = setdel(user, app); + if (err) + goto err_try_to_restore; + } + + return 0; + +err_try_to_restore: + + /* Revert logic to restore previous state of app entries */ + if (!del) + setdel = dcb_ieee_delapp; + else + setdel = dcb_ieee_setapp; + + dsa_switch_for_each_user_port_continue_reverse(other_dp, ds) { + struct net_device *user = other_dp->user; + + if (!user || user == dev) + continue; + + restore_err = setdel(user, app); + if (restore_err) + netdev_err(user, "Failed to restore DSCP prio entry configuration\n"); + } + + return err; +} + static int __maybe_unused dsa_user_dcbnl_add_dscp_prio(struct net_device *dev, struct dcb_app *app) { @@ -2220,6 +2272,17 @@ dsa_user_dcbnl_add_dscp_prio(struct net_device *dev, struct dcb_app *app) return err; } + if (!ds->dscp_prio_mapping_is_global) + return 0; + + err = dsa_user_dcbnl_ieee_global_dscp_setdel(dev, app, false); + if (err) { + if (ds->ops->port_del_dscp_prio) + ds->ops->port_del_dscp_prio(ds, port, dscp, new_prio); + dcb_ieee_delapp(dev, app); + return err; + } + return 0; } @@ -2290,6 +2353,18 @@ dsa_user_dcbnl_del_dscp_prio(struct net_device *dev, struct dcb_app *app) return err; } + if (!ds->dscp_prio_mapping_is_global) + return 0; + + err = dsa_user_dcbnl_ieee_global_dscp_setdel(dev, app, true); + if (err) { + if (ds->ops->port_add_dscp_prio) + ds->ops->port_add_dscp_prio(ds, port, dscp, + app->priority); + dcb_ieee_setapp(dev, app); + return err; + } + return 0; } -- 2.39.2