From nobody Sun Dec 14 06:20:51 2025 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (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 0F9B02ECEA1; Wed, 13 Aug 2025 07:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755068938; cv=none; b=NObkFKn5IlqJw/lfVn9eYDYcCB4iyYrcGasrgW2FPB2LJ1lKNw7t51LouBQUicX82VqaMPWHbaiTSFxJYSRzPLQZaVYDsFU3uYLekPXZXngLcOjmLQwacNvzXfVhxQ6X9MTvnqZKw3sTFZ3D6anyZ1lZPTxrgOJbYW+SRzLQhwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755068938; c=relaxed/simple; bh=QYaxlKYoCnSUSTITH74gXHhQqP4vxVMhGv1+UnHTb74=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CcslMNF4TALCBSTVrmiumMlHAox8/RPziChmewTbrQ9etslZQ3z652COKcwEalQTUw80YDHfzid5yF6+AAsmk8uW39bm1KaqW5OqM1tLPWCAMj6vnR1Ehe+W6laDWjckSk3PWRhn2yIHJaYRHgWC4SX4UaClFUrJn0mFk7CWGqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=TJ6lCE8a; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=GgP676hq; arc=none smtp.client-ip=80.241.56.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="TJ6lCE8a"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="GgP676hq" Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4c1zxg1CW4z9sxM; Wed, 13 Aug 2025 09:08:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1755068935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8jexbxzipWzrxqlmph9PiBTpETZUbRAyJQiQmfwesXA=; b=TJ6lCE8ajvCRDPp2Qm/byOLqXJnvECzLa0KhGFePXqqnZ09txZ0gVOFqCLn341Mx/Z8pvC URzNxMLXD98Qj7LgLGy+v6LMWr6n7GVuP6AA121BKSJmTlSK44z2bHjwtYb1+YcFUImV2A lYaQ0FJSb/jlz4AVdwAL5bUQKaY5LX1FhNkWjKBrI7VB6gd6xvKtWduSFyiG17A7Hpei25 BpIKn5RWWpnYkHe/knhb4GZj5lO1HHAAcctiSID5yFTnUZqrxxY9TxsQgCWvDOS2P3nSq6 aAOM1XHpvbHxMHJFpD5sCGNFn01SXCXv7inmT47zOxZSVRi3/G1vQ7dQjLbdtw== Authentication-Results: outgoing_mbo_mout; dkim=pass header.d=mailbox.org header.s=mail20150812 header.b=GgP676hq; spf=pass (outgoing_mbo_mout: domain of lukasz.majewski@mailbox.org designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=lukasz.majewski@mailbox.org From: Lukasz Majewski DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1755068933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8jexbxzipWzrxqlmph9PiBTpETZUbRAyJQiQmfwesXA=; b=GgP676hqUjQQJUCeoTiHyvGv8pUUmkKmozcJMdzLbGWRcbv01NCnk3t6sOTxB8ihjzwp6r /Jm8suMKH0AnQCE416CjX/8aFskKswhII9S2+EcuKZOqVnEnqIQi2Csjv/E/2zXP2SFruw tnQ6TXGeScf+C1DKmHJVLKb1CvLV8wjVcwIHe1uIDZaHPFdvQb1VYZfgKgOUtvsOynxd/q m/gPRs9KniIsMSfxgcNnu2cvH1BxiMRFwhmcOeB+gDeQq9S/9oN5unCR3Y8AYm5GklKZ5J di4b/+3MFDcNXSosPVHVEgz8whrz0H1CxeMwJcCrhOBWP+IR0rhizEGaEjW4kQ== To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo Cc: Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Richard Cochran , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Stefan Wahren , Simon Horman , Lukasz Majewski Subject: [net-next v18 7/7] net: mtip: Extend the L2 switch driver for imx287 with bridge operations Date: Wed, 13 Aug 2025 09:07:55 +0200 Message-Id: <20250813070755.1523898-8-lukasz.majewski@mailbox.org> In-Reply-To: <20250813070755.1523898-1-lukasz.majewski@mailbox.org> References: <20250813070755.1523898-1-lukasz.majewski@mailbox.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MBO-RS-ID: 71b44368fe03902302c X-MBO-RS-META: 4yikww5yjhzhwnbfzdtp181u6u8ig5q4 X-Rspamd-Queue-Id: 4c1zxg1CW4z9sxM Content-Type: text/plain; charset="utf-8" After this change the MTIP L2 switch can be configured as offloading device for packet switching when bridge on their interfaces is created. Signed-off-by: Lukasz Majewski --- Changes for v13: - New patch - created by excluding some code from large (i.e. v12 and earlier) MTIP driver Changes for v14 - v15: - None Changes for v16: - Enable MTIP ports to support bridge offloading Changes for v17 - v18: - None --- .../net/ethernet/freescale/mtipsw/Makefile | 2 +- .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 9 +- .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 2 + .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 132 ++++++++++++++++++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c diff --git a/drivers/net/ethernet/freescale/mtipsw/Makefile b/drivers/net/e= thernet/freescale/mtipsw/Makefile index a99aaf6ddfb2..81e2b0e03e6c 100644 --- a/drivers/net/ethernet/freescale/mtipsw/Makefile +++ b/drivers/net/ethernet/freescale/mtipsw/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 =20 obj-$(CONFIG_FEC_MTIP_L2SW) +=3D nxp-mtipl2sw.o -nxp-mtipl2sw-objs :=3D mtipl2sw.o mtipl2sw_mgnt.o +nxp-mtipl2sw-objs :=3D mtipl2sw.o mtipl2sw_mgnt.o mtipl2sw_br.o diff --git a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c b/drivers/net= /ethernet/freescale/mtipsw/mtipl2sw.c index 4c9776fc5382..a67fd1f5c807 100644 --- a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +++ b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c @@ -1887,11 +1887,15 @@ static int mtip_sw_probe(struct platform_device *pd= ev) if (ret) return dev_err_probe(&pdev->dev, ret, "Could not alloc IRQ\n"); =20 + ret =3D mtip_register_notifiers(fep); + if (ret) + return ret; + ret =3D mtip_switch_dma_init(fep); if (ret) { dev_err(&pdev->dev, "%s: ethernet switch init fail (%d)!\n", __func__, ret); - return ret; + goto unregister_notifiers; } =20 ret =3D mtip_mii_init(fep, pdev); @@ -1922,6 +1926,8 @@ static int mtip_sw_probe(struct platform_device *pdev) fep->bd_dma); fep->rx_bd_base =3D NULL; fep->tx_bd_base =3D NULL; + unregister_notifiers: + mtip_unregister_notifiers(fep); =20 return ret; } @@ -1930,6 +1936,7 @@ static void mtip_sw_remove(struct platform_device *pd= ev) { struct switch_enet_private *fep =3D platform_get_drvdata(pdev); =20 + mtip_unregister_notifiers(fep); mtip_ndev_cleanup(fep); =20 mtip_mii_remove(fep); diff --git a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h b/drivers/net= /ethernet/freescale/mtipsw/mtipl2sw.h index 7e5373823d43..3dae94048917 100644 --- a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h +++ b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h @@ -643,6 +643,8 @@ int mtip_port_learning_config(struct switch_enet_privat= e *fep, int port, int mtip_port_blocking_config(struct switch_enet_private *fep, int port, bool enable); bool mtip_is_switch_netdev_port(const struct net_device *ndev); +int mtip_register_notifiers(struct switch_enet_private *fep); +void mtip_unregister_notifiers(struct switch_enet_private *fep); int mtip_port_enable_config(struct switch_enet_private *fep, int port, bool tx_en, bool rx_en); void mtip_clear_atable(struct switch_enet_private *fep); diff --git a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c b/drivers/= net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file mode 100644 index 000000000000..f961b9cc4e6a --- /dev/null +++ b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * L2 switch Controller driver for MTIP block - bridge network interface + * + * Copyright (C) 2025 DENX Software Engineering GmbH + * Lukasz Majewski + */ + +#include +#include +#include +#include + +#include "mtipl2sw.h" + +static int mtip_ndev_port_link(struct net_device *ndev, + struct net_device *br_ndev, + struct netlink_ext_ack *extack) +{ + struct mtip_ndev_priv *priv =3D netdev_priv(ndev), *other_priv; + struct switch_enet_private *fep =3D priv->fep; + struct net_device *other_ndev; + int err; + + /* Check if one port of MTIP switch is already bridged */ + if (fep->br_members && !fep->br_offload) { + /* Get the second bridge ndev */ + other_ndev =3D fep->ndev[fep->br_members - 1]; + other_priv =3D netdev_priv(other_ndev); + if (other_priv->master_dev !=3D br_ndev) { + NL_SET_ERR_MSG_MOD(extack, + "L2 offloading only possible for the same bridge!"); + return notifier_from_errno(-EOPNOTSUPP); + } + + fep->br_offload =3D 1; + mtip_switch_dis_port_separation(fep); + mtip_clear_atable(fep); + } + + if (!priv->master_dev) + priv->master_dev =3D br_ndev; + + fep->br_members |=3D BIT(priv->portnum - 1); + + err =3D switchdev_bridge_port_offload(ndev, ndev, NULL, NULL, NULL, + false, extack); + if (err) { + dev_err(&ndev->dev, "can't offload bridge port %s [err: %d]\n", + ndev->name, err); + return err; + } + + dev_dbg(&ndev->dev, + "%s: ndev: %s br: %s fep: %p members: 0x%x offload: %d\n", + __func__, ndev->name, br_ndev->name, fep, fep->br_members, + fep->br_offload); + + return NOTIFY_DONE; +} + +static void mtip_netdevice_port_unlink(struct net_device *ndev) +{ + struct mtip_ndev_priv *priv =3D netdev_priv(ndev); + struct switch_enet_private *fep =3D priv->fep; + + dev_dbg(&ndev->dev, "%s: ndev: %s members: 0x%x\n", __func__, + ndev->name, fep->br_members); + + switchdev_bridge_port_unoffload(ndev, NULL, NULL, NULL); + + fep->br_members &=3D ~BIT(priv->portnum - 1); + priv->master_dev =3D NULL; + + if (fep->br_members && fep->br_offload) { + fep->br_offload =3D 0; + mtip_switch_en_port_separation(fep); + mtip_clear_atable(fep); + } +} + +/* netdev notifier */ +static int mtip_netdevice_event(struct notifier_block *unused, + unsigned long event, void *ptr) +{ + struct net_device *ndev =3D netdev_notifier_info_to_dev(ptr); + struct netdev_notifier_changeupper_info *info =3D ptr; + struct netlink_ext_ack *extack; + int ret =3D NOTIFY_DONE; + + if (!mtip_is_switch_netdev_port(ndev)) + return NOTIFY_DONE; + + extack =3D netdev_notifier_info_to_extack(&info->info); + + switch (event) { + case NETDEV_CHANGEUPPER: + if (!netif_is_bridge_master(info->upper_dev)) + break; + + if (info->linking) + ret =3D mtip_ndev_port_link(ndev, info->upper_dev, + extack); + else + mtip_netdevice_port_unlink(ndev); + + break; + default: + return NOTIFY_DONE; + } + + return notifier_from_errno(ret); +} + +static struct notifier_block mtip_netdevice_nb __read_mostly =3D { + .notifier_call =3D mtip_netdevice_event, +}; + +int mtip_register_notifiers(struct switch_enet_private *fep) +{ + int ret =3D register_netdevice_notifier(&mtip_netdevice_nb); + + if (ret) + dev_err(&fep->pdev->dev, "can't register netdevice notifier\n"); + + return ret; +} + +void mtip_unregister_notifiers(struct switch_enet_private *fep) +{ + unregister_netdevice_notifier(&mtip_netdevice_nb); +} --=20 2.39.5