From patchwork Tue Apr 14 11:26:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 221210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 223F7C2BA19 for ; Tue, 14 Apr 2020 11:31:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC5A9206D5 for ; Tue, 14 Apr 2020 11:31:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="2AwyDrd7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439253AbgDNLbt (ORCPT ); Tue, 14 Apr 2020 07:31:49 -0400 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:18260 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438988AbgDNL1S (ORCPT ); Tue, 14 Apr 2020 07:27:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1586863637; x=1618399637; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=bgal25Q2GLlB11cf7TVsL0b4pEAKBlQgQ2+f0ocKzAw=; b=2AwyDrd7zSLDlCq/kpl2L+PU4PdOgAw9MwikaDSOyMyOtl/+EOiyP9qg 7WdHs2WA+NcEOse26b0qe27IWDXEjRq+Sat5UcTRPcB6yFuzQ/URBV+z/ pafcnLHsgbCKe8BRUcW/RRFILbMVJnuyRxdzJyS6YI8N0idBAKUGfbYJr wvKyu6+LhD4rqajLD7tTIhxULsyGHnjdhshydYwrLA8AFPcGLZbq5sERS CnoTP93wV2vKicR4/Elfq5HeKuPkgNiyzDgQz6qRGilWSoC11unrZ/mE6 +FQjkcDKfHn6q5xb1mE6JVD/gK+e9DootCTuxmX+i/tMYP8QB6UMmZnSk A==; IronPort-SDR: FyX6K0vNEkVdhwRsCL9eiSdv7aItkODXd3Lk3HnNjfVx3Ql4HoDErhwnrIzoJgVV1nvzILIPgW lctKj78CbMqvGjgZ7laVmI2I7CJMlp9K5RCRs+JG3GaHAhgPhkO6EHYGBLj5Ae5kDYYPYaZI8E JiZgZsh35IhX4FoiXCPmXs60xvosDQtlKDmsApiJIEgV2zFPoNrEMPrxriL264luDHtMuqHzP2 5tBkAcj36BSXuwYUASUXAYRV3WOpKFVmkDGwVvwP/Qg8c6B3FhX1fLX/AxiH94EDel/ldcgAL8 vyc= X-IronPort-AV: E=Sophos;i="5.72,382,1580799600"; d="scan'208";a="75809061" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Apr 2020 04:27:16 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 14 Apr 2020 04:27:03 -0700 Received: from soft-dev3.microsemi.net (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 Apr 2020 04:27:14 -0700 From: Horatiu Vultur To: , , , , , , , , , , , CC: Horatiu Vultur Subject: [RFC net-next v5 2/9] bridge: mrp: Update Kconfig and Makefile Date: Tue, 14 Apr 2020 13:26:11 +0200 Message-ID: <20200414112618.3644-3-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414112618.3644-1-horatiu.vultur@microchip.com> References: <20200414112618.3644-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add the option BRIDGE_MRP to allow to build in or not MRP support. The default value is N. Signed-off-by: Horatiu Vultur --- net/bridge/Kconfig | 12 ++++++++++++ net/bridge/Makefile | 2 ++ 2 files changed, 14 insertions(+) diff --git a/net/bridge/Kconfig b/net/bridge/Kconfig index e4fb050e2078..51a6414145d2 100644 --- a/net/bridge/Kconfig +++ b/net/bridge/Kconfig @@ -61,3 +61,15 @@ config BRIDGE_VLAN_FILTERING Say N to exclude this support and reduce the binary size. If unsure, say Y. + +config BRIDGE_MRP + bool "MRP protocol" + depends on BRIDGE + default n + help + If you say Y here, then the Ethernet bridge will be able to run MRP + protocol to detect loops + + Say N to exclude this support and reduce the binary size. + + If unsure, say N. diff --git a/net/bridge/Makefile b/net/bridge/Makefile index 49da7ae6f077..9bf3e1be3328 100644 --- a/net/bridge/Makefile +++ b/net/bridge/Makefile @@ -25,3 +25,5 @@ bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o br_vlan_tunnel.o br_vlan_opt bridge-$(CONFIG_NET_SWITCHDEV) += br_switchdev.o obj-$(CONFIG_NETFILTER) += netfilter/ + +bridge-$(CONFIG_BRIDGE_MRP) += br_mrp.o br_mrp_netlink.o br_mrp_switchdev.o From patchwork Tue Apr 14 11:26:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 221213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47A70C2BA19 for ; Tue, 14 Apr 2020 11:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21FB020732 for ; Tue, 14 Apr 2020 11:27:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="tyCIgc+G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439073AbgDNL1j (ORCPT ); Tue, 14 Apr 2020 07:27:39 -0400 Received: from esa6.microchip.iphmx.com ([216.71.154.253]:34470 "EHLO esa6.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439060AbgDNL11 (ORCPT ); Tue, 14 Apr 2020 07:27:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1586863646; x=1618399646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Wk5W6JOrVyShu0Bu566DjA/nJMtV0L8hDnh56QYpSOM=; b=tyCIgc+GlkAGy2SvX8CQDvqdenComncHwn4KJvlErPaG4vLFv3O7mk4f LBfxsNhgH6cY6Hy2OjZ1W4NLNiWtU4zmOOC0COngm5i+whvgV3j6V3xyY xMFjZpEsbV1EfSqHSjQs/R/G5DrTFKfsxe1TGgNFbZIBzGkQnwLFUm3PC 1NDC0JPBUHyjjIGSfYZ3EHvcbT2ibjqEr/mmJjG9RkX/BMCiDn9gqHLxK uIT0ib05uXly5u3VFQ0JnKSA4iXTfoUxP47Y26sFnQaP1C5v1YGpN+reC eoQ2n8V2L5+uVFyw+Fc5S8L+7VZW4Pw7qxghbPqItleyiyvymomQI6xvH g==; IronPort-SDR: /F8BP7LwDCcPgcvjIrvHkla1gFwZo+sHQeC/OkwDcaNdpQM2GEamktJMbud1adCGKchoWuhh8/ G1oW/cVAQhCG447aaLtLUfD4rH2x28jWBoJci+esRyZTJhf1PCDmVUM8ext67Dtvk4vL7k0uaY /9BX36aWPpBiaApElq11NWbXm+kaQBtumtNFMD0Zl+s9jZKpowC8dKYVJG+BKz/cn9TfePoO7X s5EUIPECi/EvAP+lmB5yRo2MafQfg1E7ZXr3p21L8/24NFFBHrP/Hjf/nGAueV3OIXXDY49bSB 4t0= X-IronPort-AV: E=Sophos;i="5.72,382,1580799600"; d="scan'208";a="9066832" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Apr 2020 04:27:26 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 14 Apr 2020 04:27:12 -0700 Received: from soft-dev3.microsemi.net (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 Apr 2020 04:27:23 -0700 From: Horatiu Vultur To: , , , , , , , , , , , CC: Horatiu Vultur Subject: [RFC net-next v5 5/9] switchdev: mrp: Extend switchdev API to offload MRP Date: Tue, 14 Apr 2020 13:26:14 +0200 Message-ID: <20200414112618.3644-6-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414112618.3644-1-horatiu.vultur@microchip.com> References: <20200414112618.3644-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Extend switchdev API to add support for MRP. The HW is notified in following cases: SWITCHDEV_OBJ_ID_MRP: This is used when a MRP instance is added/removed from the MRP ring. SWITCHDEV_OBJ_ID_RING_ROLE_MRP: This is used when the role of the node changes. The current supported roles are MRM and MRC. SWITCHDEV_OBJ_ID_RING_TEST_MRP: This is used when to start/stop sending MRP_Test frames on the mrp ring ports. This is called only on nodes that have the role MRM. In case this fails then the SW will generate the frames. SWITCHDEV_OBJ_ID_RING_STATE_STATE: This is used when the ring changes it states to open or closed. This is required to notify HW because the MRP_Test frame contains the field MRP_InState which contains this information. SWITCHDEV_ATTR_ID_MRP_PORT_STATE: This is used when the port's state is changed. It can be in blocking/forwarding mode. SWITCHDEV_ATTR_ID_MRP_PORT_ROLE: This is used when port's role changes. The roles of the port can be primary/secondary. This is required to notify HW because the MRP_Test frame contains the field MRP_PortRole that contains this information. Signed-off-by: Horatiu Vultur --- include/net/switchdev.h | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/include/net/switchdev.h b/include/net/switchdev.h index aee86a189432..ae7aeb0d1f9c 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -40,6 +40,10 @@ enum switchdev_attr_id { SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING, SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED, SWITCHDEV_ATTR_ID_BRIDGE_MROUTER, +#if IS_ENABLED(CONFIG_BRIDGE_MRP) + SWITCHDEV_ATTR_ID_MRP_PORT_STATE, + SWITCHDEV_ATTR_ID_MRP_PORT_ROLE, +#endif }; struct switchdev_attr { @@ -55,6 +59,11 @@ struct switchdev_attr { clock_t ageing_time; /* BRIDGE_AGEING_TIME */ bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */ bool mc_disabled; /* MC_DISABLED */ +#if IS_ENABLED(CONFIG_BRIDGE_MRP) + u8 mrp_port_state; /* MRP_PORT_STATE */ + u8 mrp_port_role; /* MRP_PORT_ROLE */ + u8 mrp_ring_state; /* MRP_RING_STATE */ +#endif } u; }; @@ -63,6 +72,12 @@ enum switchdev_obj_id { SWITCHDEV_OBJ_ID_PORT_VLAN, SWITCHDEV_OBJ_ID_PORT_MDB, SWITCHDEV_OBJ_ID_HOST_MDB, +#if IS_ENABLED(CONFIG_BRIDGE_MRP) + SWITCHDEV_OBJ_ID_MRP, + SWITCHDEV_OBJ_ID_RING_TEST_MRP, + SWITCHDEV_OBJ_ID_RING_ROLE_MRP, + SWITCHDEV_OBJ_ID_RING_STATE_MRP, +#endif }; struct switchdev_obj { @@ -94,6 +109,53 @@ struct switchdev_obj_port_mdb { #define SWITCHDEV_OBJ_PORT_MDB(OBJ) \ container_of((OBJ), struct switchdev_obj_port_mdb, obj) + +#if IS_ENABLED(CONFIG_BRIDGE_MRP) +/* SWITCHDEV_OBJ_ID_MRP */ +struct switchdev_obj_mrp { + struct switchdev_obj obj; + struct net_device *p_port; + struct net_device *s_port; + u32 ring_id; +}; + +#define SWITCHDEV_OBJ_MRP(OBJ) \ + container_of((OBJ), struct switchdev_obj_mrp, obj) + +/* SWITCHDEV_OBJ_ID_RING_TEST_MRP */ +struct switchdev_obj_ring_test_mrp { + struct switchdev_obj obj; + /* The value is in us and a value of 0 represents to stop */ + u32 interval; + u8 max_miss; + u32 ring_id; + u32 period; +}; + +#define SWITCHDEV_OBJ_RING_TEST_MRP(OBJ) \ + container_of((OBJ), struct switchdev_obj_ring_test_mrp, obj) + +/* SWICHDEV_OBJ_ID_RING_ROLE_MRP */ +struct switchdev_obj_ring_role_mrp { + struct switchdev_obj obj; + u8 ring_role; + u32 ring_id; +}; + +#define SWITCHDEV_OBJ_RING_ROLE_MRP(OBJ) \ + container_of((OBJ), struct switchdev_obj_ring_role_mrp, obj) + +struct switchdev_obj_ring_state_mrp { + struct switchdev_obj obj; + u8 ring_state; + u32 ring_id; +}; + +#define SWITCHDEV_OBJ_RING_STATE_MRP(OBJ) \ + container_of((OBJ), struct switchdev_obj_ring_state_mrp, obj) + +#endif + typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj); enum switchdev_notifier_type { From patchwork Tue Apr 14 11:26:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 221211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22FEEC2BA19 for ; Tue, 14 Apr 2020 11:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA6D620775 for ; Tue, 14 Apr 2020 11:31:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="QL4+TepN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439095AbgDNL2I (ORCPT ); Tue, 14 Apr 2020 07:28:08 -0400 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:17753 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439070AbgDNL1m (ORCPT ); Tue, 14 Apr 2020 07:27:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1586863661; x=1618399661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=DWPs3xrMyxo3okz3VMWs5x6ia6WwSmMa/+orZa96r/I=; b=QL4+TepN/8jtKQ9ey3+iAPBUi2JpQDJsdULoNJoXJS90qrK3nBMo7sOn BiChiksEir/FpWO6tTMzq6mtNJ2V4UCksuhtIDPsw4Cl8sJ2vR+82prw3 nxcsa/Nb9UVKQLZlnu40OLrB5KAnmwrDRQL5jwVuIOnrsw1ztq41Vc6WB R8vdh8sQuS6mOHsTEPECJFpMJjKWokSOJQTpVEMH39RQdYAl6ERqRQF1O lzSsE4M0GBaWPw8JvLBvYNSWX9SwzRFnYy7H++g2pGy/7S3/gKdRgBPUH orpC/kxIcTeG71AFhcMXDu6HJt9B7z2tLSMDD8D3aLvhbfQx2XuA/z5iU Q==; IronPort-SDR: WCInP7Qr5Sy1ud/Ldk3QOFTP183MTspilSHsloYl3SfCsQrszxOMezTOUjEYA9NEQFPbYIfdNx Y5eInCCoWl0X6w7puunL9bjBIcGC9TWIBYFoXS1XbLBzQgQf7vV/P1yyXGXz7fn1p1ZC2mrHZl fz2fjviciTPyLYy9t0GuOeEd4AFLHy7A4Fi+B3Y7J0xdW3XYmnqp5YgJ803cq+LyGqKHTr2/dT tTCLhBQBWD2fjDf4k7VWoWDz9C9ZDLE6sxXHhOerjl7WDTFZiPwCHFdUJy8IEmkD1c5POVdBnP Zgk= X-IronPort-AV: E=Sophos;i="5.72,382,1580799600"; d="scan'208";a="70264391" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Apr 2020 04:27:35 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 14 Apr 2020 04:27:34 -0700 Received: from soft-dev3.microsemi.net (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 Apr 2020 04:27:31 -0700 From: Horatiu Vultur To: , , , , , , , , , , , CC: Horatiu Vultur Subject: [RFC net-next v5 8/9] bridge: mrp: Implement netlink interface to configure MRP Date: Tue, 14 Apr 2020 13:26:17 +0200 Message-ID: <20200414112618.3644-9-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414112618.3644-1-horatiu.vultur@microchip.com> References: <20200414112618.3644-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Implement netlink interface to configure MRP. The implementation will do sanity checks over the attributes and then eventually call the MRP interface. Signed-off-by: Horatiu Vultur --- net/bridge/br_mrp_netlink.c | 164 ++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 net/bridge/br_mrp_netlink.c diff --git a/net/bridge/br_mrp_netlink.c b/net/bridge/br_mrp_netlink.c new file mode 100644 index 000000000000..0d8253311595 --- /dev/null +++ b/net/bridge/br_mrp_netlink.c @@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +#include +#include "br_private.h" +#include "br_private_mrp.h" + +static const struct nla_policy br_mrp_policy[IFLA_BRIDGE_MRP_MAX + 1] = { + [IFLA_BRIDGE_MRP_UNSPEC] = { .type = NLA_REJECT }, + [IFLA_BRIDGE_MRP_INSTANCE] = { .type = NLA_EXACT_LEN, + .len = sizeof(struct br_mrp_instance)}, + [IFLA_BRIDGE_MRP_PORT_STATE] = { .type = NLA_U32 }, + [IFLA_BRIDGE_MRP_PORT_ROLE] = { .type = NLA_EXACT_LEN, + .len = sizeof(struct br_mrp_port_role)}, + [IFLA_BRIDGE_MRP_RING_STATE] = { .type = NLA_EXACT_LEN, + .len = sizeof(struct br_mrp_ring_state)}, + [IFLA_BRIDGE_MRP_RING_ROLE] = { .type = NLA_EXACT_LEN, + .len = sizeof(struct br_mrp_ring_role)}, + [IFLA_BRIDGE_MRP_START_TEST] = { .type = NLA_EXACT_LEN, + .len = sizeof(struct br_mrp_start_test)}, +}; + +int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, + struct nlattr *attr, int cmd, struct netlink_ext_ack *extack) +{ + struct nlattr *tb[IFLA_BRIDGE_MRP_MAX + 1]; + int err; + + if (br->stp_enabled != BR_NO_STP) { + br_warn(br, "MRP can't be enabled if STP is already enabled\n"); + return -EINVAL; + } + + err = nla_parse_nested(tb, IFLA_BRIDGE_MRP_MAX, attr, + NULL, extack); + if (err) + return err; + + if (tb[IFLA_BRIDGE_MRP_INSTANCE]) { + struct br_mrp_instance *instance = + nla_data(tb[IFLA_BRIDGE_MRP_INSTANCE]); + + if (cmd == RTM_SETLINK) + err = br_mrp_add(br, instance); + else + err = br_mrp_del(br, instance); + if (err) + return err; + } + + if (tb[IFLA_BRIDGE_MRP_PORT_STATE]) { + enum br_mrp_port_state_type state = + nla_get_u32(tb[IFLA_BRIDGE_MRP_PORT_STATE]); + + err = br_mrp_set_port_state(p, state); + if (err) + return err; + } + + if (tb[IFLA_BRIDGE_MRP_PORT_ROLE]) { + struct br_mrp_port_role *role = + nla_data(tb[IFLA_BRIDGE_MRP_PORT_ROLE]); + + err = br_mrp_set_port_role(p, role); + if (err) + return err; + } + + if (tb[IFLA_BRIDGE_MRP_RING_STATE]) { + struct br_mrp_ring_state *state = + nla_data(tb[IFLA_BRIDGE_MRP_RING_STATE]); + + err = br_mrp_set_ring_state(br, state); + if (err) + return err; + } + + if (tb[IFLA_BRIDGE_MRP_RING_ROLE]) { + struct br_mrp_ring_role *role = + nla_data(tb[IFLA_BRIDGE_MRP_RING_ROLE]); + + err = br_mrp_set_ring_role(br, role); + if (err) + return err; + } + + if (tb[IFLA_BRIDGE_MRP_START_TEST]) { + struct br_mrp_start_test *test = + nla_data(tb[IFLA_BRIDGE_MRP_START_TEST]); + + err = br_mrp_start_test(br, test); + if (err) + return err; + } + + return 0; +} + +static inline size_t br_mrp_nlmsg_size(void) +{ + return NLMSG_ALIGN(sizeof(struct ifinfomsg)) + + nla_total_size(4); /* IFLA_BRIDGE_MRP_RING_OPEN */ +} + +int br_mrp_port_open(struct net_device *dev, u8 loc) +{ + struct nlattr *af, *mrp; + struct ifinfomsg *hdr; + struct nlmsghdr *nlh; + struct sk_buff *skb; + int err = -ENOBUFS; + struct net *net; + + net = dev_net(dev); + + skb = nlmsg_new(br_mrp_nlmsg_size(), GFP_ATOMIC); + if (!skb) + goto errout; + + nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*hdr), 0); + if (!nlh) + goto errout; + + hdr = nlmsg_data(nlh); + hdr->ifi_family = AF_BRIDGE; + hdr->__ifi_pad = 0; + hdr->ifi_type = dev->type; + hdr->ifi_index = dev->ifindex; + hdr->ifi_flags = dev_get_flags(dev); + hdr->ifi_change = 0; + + af = nla_nest_start_noflag(skb, IFLA_AF_SPEC); + if (!af) { + err = -EMSGSIZE; + goto nla_put_failure; + } + + mrp = nla_nest_start_noflag(skb, IFLA_BRIDGE_MRP); + if (!mrp) { + err = -EMSGSIZE; + goto nla_put_failure; + } + + err = nla_put_u32(skb, IFLA_BRIDGE_MRP_RING_OPEN, loc); + if (err) + goto nla_put_failure; + + nla_nest_end(skb, mrp); + nla_nest_end(skb, af); + nlmsg_end(skb, nlh); + + rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC); + return 0; + +nla_put_failure: + nlmsg_cancel(skb, nlh); + kfree_skb(skb); + +errout: + rtnl_set_sk_err(net, RTNLGRP_LINK, err); + return err; +} +EXPORT_SYMBOL(br_mrp_port_open); From patchwork Tue Apr 14 11:26:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 221212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90889C2BA19 for ; Tue, 14 Apr 2020 11:28:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 613C5206B6 for ; Tue, 14 Apr 2020 11:28:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="YXVQIEeN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728782AbgDNL2Z (ORCPT ); Tue, 14 Apr 2020 07:28:25 -0400 Received: from esa3.microchip.iphmx.com ([68.232.153.233]:39025 "EHLO esa3.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439072AbgDNL1m (ORCPT ); Tue, 14 Apr 2020 07:27:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1586863661; x=1618399661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=AAktRsGo1nOyB9XwgW0b2ZZuoEurSDp9VgnnFBebWBg=; b=YXVQIEeN2NdSqtID5m5YqfXYvzrRMniXmfYkgcpvu6HIuiaQnpFJFkAm zhNnwBktN5T1hKBptFH0v8fquA/MkoBIEf9LGmnmzrZKMOCq18nit2iwp M3p3P77kCOMic1NqPe+MRlXkqQT+miYZdzGztJe1sXFUZn7f0e5QGvapp fnZHUUFkY6z8nIBTi6mCAb/rUZsvezBJrM2weH+g9tSAofj+fgM9UfG4r qnD9wzFbkkQr2EFtT5YeISR8BSg7BUaLjiaPsr3P/FAOW3plw6P7N8Wf6 NUx/aqQglcU8/ONsjLTpUSpn0R7sYG8MQlHJkci1AnxszL70dEQ/cuXf0 A==; IronPort-SDR: 4ZjutON7erWUO1fBoDa8Dw4AA+M7jD3fRYVVhUn1HFlhZ6PdqcWiTrgkJspnN7EGOAmjADoP/r KyIhTqWK81jH36LJoWh68rl98fHOfykMbScijLYIRGm+K0s7u2K7uJ2qKSLjptj16ZTxcF6RIp sweq2LurWviTiQG6cTA40psnLYXXQmTBjby8BD3qkuVke1zBIJVJ+IqP6qUMuw0xounYGljrRZ LIjgRbjVbFr2yl5bVdj5F5YEL11OU1+gr+EbrV43L7azSyBOTZBvzzh/puKCCXqNJUdTjTjjSx xjU= X-IronPort-AV: E=Sophos;i="5.72,382,1580799600"; d="scan'208";a="73265533" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Apr 2020 04:27:37 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 14 Apr 2020 04:27:37 -0700 Received: from soft-dev3.microsemi.net (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 Apr 2020 04:27:34 -0700 From: Horatiu Vultur To: , , , , , , , , , , , CC: Horatiu Vultur Subject: [RFC net-next v5 9/9] bridge: mrp: Integrate MRP into the bridge Date: Tue, 14 Apr 2020 13:26:18 +0200 Message-ID: <20200414112618.3644-10-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414112618.3644-1-horatiu.vultur@microchip.com> References: <20200414112618.3644-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To integrate MRP into the bridge, the bridge needs to do the following: - add new flag(BR_MPP_AWARE) to the net bridge ports, this bit will be set when the port is added to an MRP instance. In this way it knows if the frame was received on MRP ring port - detect if the MRP frame was received on MRP ring port in that case it would be processed otherwise just forward it as usual. - enable parsing of MRP - before whenever the bridge was set up, it would set all the ports in forwarding state. Add an extra check to not set ports in forwarding state if the port is an MRP ring port. The reason of this change is that if the MRP instance initially sets the port in blocked state by setting the bridge up it would overwrite this setting. Signed-off-by: Horatiu Vultur --- include/linux/if_bridge.h | 1 + net/bridge/br_device.c | 3 +++ net/bridge/br_if.c | 2 ++ net/bridge/br_input.c | 3 +++ net/bridge/br_netlink.c | 5 +++++ net/bridge/br_private.h | 35 +++++++++++++++++++++++++++++++++++ net/bridge/br_stp.c | 6 ++++++ net/bridge/br_stp_if.c | 5 +++++ 8 files changed, 60 insertions(+) diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index 9e57c4411734..10baa9efdae8 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -47,6 +47,7 @@ struct br_ip_list { #define BR_BCAST_FLOOD BIT(14) #define BR_NEIGH_SUPPRESS BIT(15) #define BR_ISOLATED BIT(16) +#define BR_MRP_AWARE BIT(17) #define BR_DEFAULT_AGEING_TIME (300 * HZ) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index 0e3dbc5f3c34..8ec1362588af 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -463,6 +463,9 @@ void br_dev_setup(struct net_device *dev) spin_lock_init(&br->lock); INIT_LIST_HEAD(&br->port_list); INIT_HLIST_HEAD(&br->fdb_list); +#if IS_ENABLED(CONFIG_BRIDGE_MRP) + INIT_LIST_HEAD(&br->mrp_list); +#endif spin_lock_init(&br->hash_lock); br->bridge_id.prio[0] = 0x80; diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index 4fe30b182ee7..ca685c0cdf95 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -333,6 +333,8 @@ static void del_nbp(struct net_bridge_port *p) br_stp_disable_port(p); spin_unlock_bh(&br->lock); + br_mrp_port_del(br, p); + br_ifinfo_notify(RTM_DELLINK, NULL, p); list_del_rcu(&p->list); diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index fcc260840028..d5c34f36f0f4 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -342,6 +342,9 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb) } } + if (unlikely(br_mrp_process(p, skb))) + return RX_HANDLER_PASS; + forward: switch (p->state) { case BR_STATE_FORWARDING: diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 43dab4066f91..8826fcd1eb76 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -669,6 +669,11 @@ static int br_afspec(struct net_bridge *br, if (err) return err; break; + case IFLA_BRIDGE_MRP: + err = br_mrp_parse(br, p, attr, cmd, extack); + if (err) + return err; + break; } } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 1f97703a52ff..5835828320b6 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -428,6 +428,10 @@ struct net_bridge { int offload_fwd_mark; #endif struct hlist_head fdb_list; + +#if IS_ENABLED(CONFIG_BRIDGE_MRP) + struct list_head __rcu mrp_list; +#endif }; struct br_input_skb_cb { @@ -1304,6 +1308,37 @@ unsigned long br_timer_value(const struct timer_list *timer); extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr); #endif +/* br_mrp.c */ +#if IS_ENABLED(CONFIG_BRIDGE_MRP) +int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, + struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); +int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb); +bool br_mrp_enabled(struct net_bridge *br); +void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p); +#else +static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, + struct nlattr *attr, int cmd, + struct netlink_ext_ack *extack) +{ + return -EOPNOTSUPP; +} + +static inline int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb) +{ + return 0; +} + +static inline bool br_mrp_enabled(struct net_bridge *br) +{ + return 0; +} + +static inline void br_mrp_port_del(struct net_bridge *br, + struct net_bridge_port *p) +{ +} +#endif + /* br_netlink.c */ extern struct rtnl_link_ops br_link_ops; int br_netlink_init(void); diff --git a/net/bridge/br_stp.c b/net/bridge/br_stp.c index 1f14b8455345..3e88be7aa269 100644 --- a/net/bridge/br_stp.c +++ b/net/bridge/br_stp.c @@ -36,6 +36,12 @@ void br_set_state(struct net_bridge_port *p, unsigned int state) }; int err; + /* Don't change the state of the ports if they are driven by a different + * protocol. + */ + if (p->flags & BR_MRP_AWARE) + return; + p->state = state; err = switchdev_port_attr_set(p->dev, &attr); if (err && err != -EOPNOTSUPP) diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c index d174d3a566aa..542b212d5033 100644 --- a/net/bridge/br_stp_if.c +++ b/net/bridge/br_stp_if.c @@ -200,6 +200,11 @@ void br_stp_set_enabled(struct net_bridge *br, unsigned long val) { ASSERT_RTNL(); + if (br_mrp_enabled(br)) { + br_warn(br, "STP can't be enabled if MRP is already enabled\n"); + return; + } + if (val) { if (br->stp_enabled == BR_NO_STP) br_stp_start(br);