From patchwork Wed May 6 16:30:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 219765 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.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 1DFB3C4724C for ; Wed, 6 May 2020 16:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEF81208E4 for ; Wed, 6 May 2020 16:30:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="wYu2ABp7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730015AbgEFQaj (ORCPT ); Wed, 6 May 2020 12:30:39 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:58202 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729567AbgEFQai (ORCPT ); Wed, 6 May 2020 12:30:38 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 046GUYJw116942; Wed, 6 May 2020 11:30:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1588782634; bh=T7PG90KboEYVGUhRi6iQEWJpyNo3ebhImthT1MYEiqs=; h=From:To:Subject:Date:In-Reply-To:References; b=wYu2ABp7aOygtoEP1+e6dEHif/dwXyp9TBk2Vk9AFQRgo1WlmulR6DOrYwqEB9g89 0iMZTm8fP12w1qZc0fDVe6OUUassHwD7av3IutvcLAry8yxWMcizUuzHLfkVyBTRls TalCS+VsfdXPkjvL1ZBGZ82H7ppqRtfWgDbQtIiU= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 046GUYo6081648 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 May 2020 11:30:34 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 6 May 2020 11:30:34 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 6 May 2020 11:30:34 -0500 Received: from uda0868495.fios-router.home (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 046GUXDe119719; Wed, 6 May 2020 11:30:34 -0500 From: Murali Karicheri To: , , , , , , Subject: [net-next RFC PATCH 01/13] net: hsr: Re-use Kconfig option to support PRP Date: Wed, 6 May 2020 12:30:21 -0400 Message-ID: <20200506163033.3843-2-m-karicheri2@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506163033.3843-1-m-karicheri2@ti.com> References: <20200506163033.3843-1-m-karicheri2@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org PRP, Parallel Redundancy Protocol is another redundancy protocol defined by IEC62439-3 similar to HSR. PRP uses a RCT, Redundancy Control Trailer appended to the end of a Ethernet frame to implement redundancy. There are many similarities between these protocols so that existing code for HSR can be enhanced to support PRP. So as a first step, rename the existing CONFIG_HSR to CONFIG_HSR_PRP to introduce PRP. Signed-off-by: Murali Karicheri --- net/Makefile | 2 +- net/hsr/Kconfig | 38 +++++++++++++++++++++++--------------- net/hsr/Makefile | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/net/Makefile b/net/Makefile index 07ea48160874..4f1c6a44f2c3 100644 --- a/net/Makefile +++ b/net/Makefile @@ -77,7 +77,7 @@ obj-$(CONFIG_OPENVSWITCH) += openvswitch/ obj-$(CONFIG_VSOCKETS) += vmw_vsock/ obj-$(CONFIG_MPLS) += mpls/ obj-$(CONFIG_NET_NSH) += nsh/ -obj-$(CONFIG_HSR) += hsr/ +obj-$(CONFIG_HSR_PRP) += hsr/ ifneq ($(CONFIG_NET_SWITCHDEV),) obj-y += switchdev/ endif diff --git a/net/hsr/Kconfig b/net/hsr/Kconfig index 9c58f8763997..220befd8e2c3 100644 --- a/net/hsr/Kconfig +++ b/net/hsr/Kconfig @@ -1,27 +1,35 @@ # SPDX-License-Identifier: GPL-2.0-only # -# IEC 62439-3 High-availability Seamless Redundancy +# IEC 62439-3 High-availability Seamless Redundancy (HSR) / +# IEC 62439-4 Parallel Redundancy Protocol (PRP) # - -config HSR - tristate "High-availability Seamless Redundancy (HSR)" +config HSR_PRP + tristate "IEC 62439 HSR/PRP Support" ---help--- + This enables IEC 62439 defined High-availability Seamless + Redundancy (HSR) and Parallel Redundancy Protocol (PRP). If you say Y here, then your Linux box will be able to act as a - DANH ("Doubly attached node implementing HSR"). For this to work, - your Linux box needs (at least) two physical Ethernet interfaces, - and it must be connected as a node in a ring network together with - other HSR capable nodes. + DANH ("Doubly attached node implementing HSR") or DANP ("Doubly + attached node implementing PRP"). For this to work, your Linux + box needs (at least) two physical Ethernet interfaces. + + For DANH, it must be connected as a node in a ring network together + with other HSR capable nodes. All Ethernet frames sent over the hsr + device will be sent in both directions on the ring (over both slave + ports), giving a redundant, instant fail-over network. Each HSR node + in the ring acts like a bridge for HSR frames, but filters frames + that have been forwarded earlier. - All Ethernet frames sent over the hsr device will be sent in both - directions on the ring (over both slave ports), giving a redundant, - instant fail-over network. Each HSR node in the ring acts like a - bridge for HSR frames, but filters frames that have been forwarded - earlier. + For DANP, it must be connected as a node connecting to two + separate networks over the two slave interfaces. Like HSR, Ethernet + frames sent over the prp device will be sent to both networks giving + a redundant, instant fail-over network. This code is a "best effort" to comply with the HSR standard as described in IEC 62439-3:2010 (HSRv0) and IEC 62439-3:2012 (HSRv1), - but no compliancy tests have been made. Use iproute2 to select - the version you desire. + and PRP standard described in IEC 62439-4:2012 (PRP), but no + compliancy tests have been made. Use iproute2 to select the protocol + you would like to use. You need to perform any and all necessary tests yourself before relying on this code in a safety critical system! diff --git a/net/hsr/Makefile b/net/hsr/Makefile index 75df90d3b416..fd207c1a0854 100644 --- a/net/hsr/Makefile +++ b/net/hsr/Makefile @@ -3,7 +3,7 @@ # Makefile for HSR # -obj-$(CONFIG_HSR) += hsr.o +obj-$(CONFIG_HSR_PRP) += hsr.o hsr-y := hsr_main.o hsr_framereg.o hsr_device.o \ hsr_netlink.o hsr_slave.o hsr_forward.o From patchwork Wed May 6 16:30:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 219760 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.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 C000EC47257 for ; Wed, 6 May 2020 16:31:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9331420708 for ; Wed, 6 May 2020 16:31:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="pPnCnFv8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730043AbgEFQb5 (ORCPT ); Wed, 6 May 2020 12:31:57 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:42222 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729747AbgEFQal (ORCPT ); Wed, 6 May 2020 12:30:41 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 046GUZjG085528; Wed, 6 May 2020 11:30:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1588782635; bh=Cai31ZHxQi4/NU0CFxQdN7+fQQ232w1peH7dU6BgXjI=; h=From:To:Subject:Date:In-Reply-To:References; b=pPnCnFv8gH/arunhGMzsTty3UahGNwcbnd1MhojUXU0hgPQ9Q0Q+nRPCFtwop4zqt ujvF2sVuOgKC2hoYHnmETMDZrdW9ug6+OWHWU+sS3rpaknUKmsT7AHsECUuUgRqHXU V8jpTfCclkAaV2yQxRNsQaR3B1oVAiGbZEuiELYU= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 046GUZpY081674 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 May 2020 11:30:35 -0500 Received: from DLEE101.ent.ti.com (157.170.170.31) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 6 May 2020 11:30:35 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE101.ent.ti.com (157.170.170.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 6 May 2020 11:30:35 -0500 Received: from uda0868495.fios-router.home (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 046GUXDg119719; Wed, 6 May 2020 11:30:35 -0500 From: Murali Karicheri To: , , , , , , Subject: [net-next RFC PATCH 03/13] net: hsr: rename files to introduce PRP support Date: Wed, 6 May 2020 12:30:23 -0400 Message-ID: <20200506163033.3843-4-m-karicheri2@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506163033.3843-1-m-karicheri2@ti.com> References: <20200506163033.3843-1-m-karicheri2@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As PRP implementation expect to re-use code from HSR driver, rename the existing files that can be re-used with a hsr_prp prefix. Signed-off-by: Murali Karicheri --- net/hsr-prp/Makefile | 11 ++++++----- net/hsr-prp/hsr_netlink.c | 6 +++--- net/hsr-prp/{hsr_debugfs.c => hsr_prp_debugfs.c} | 6 +++--- net/hsr-prp/{hsr_device.c => hsr_prp_device.c} | 10 +++++----- net/hsr-prp/{hsr_device.h => hsr_prp_device.h} | 2 +- net/hsr-prp/{hsr_forward.c => hsr_prp_forward.c} | 6 +++--- net/hsr-prp/{hsr_forward.h => hsr_prp_forward.h} | 2 +- net/hsr-prp/{hsr_framereg.c => hsr_prp_framereg.c} | 4 ++-- net/hsr-prp/{hsr_framereg.h => hsr_prp_framereg.h} | 2 +- net/hsr-prp/{hsr_main.c => hsr_prp_main.c} | 8 ++++---- net/hsr-prp/{hsr_main.h => hsr_prp_main.h} | 0 net/hsr-prp/{hsr_slave.c => hsr_prp_slave.c} | 10 +++++----- net/hsr-prp/{hsr_slave.h => hsr_prp_slave.h} | 2 +- 13 files changed, 35 insertions(+), 34 deletions(-) rename net/hsr-prp/{hsr_debugfs.c => hsr_prp_debugfs.c} (97%) rename net/hsr-prp/{hsr_device.c => hsr_prp_device.c} (98%) rename net/hsr-prp/{hsr_device.h => hsr_prp_device.h} (96%) rename net/hsr-prp/{hsr_forward.c => hsr_prp_forward.c} (99%) rename net/hsr-prp/{hsr_forward.h => hsr_prp_forward.h} (92%) rename net/hsr-prp/{hsr_framereg.c => hsr_prp_framereg.c} (99%) rename net/hsr-prp/{hsr_framereg.h => hsr_prp_framereg.h} (98%) rename net/hsr-prp/{hsr_main.c => hsr_prp_main.c} (96%) rename net/hsr-prp/{hsr_main.h => hsr_prp_main.h} (100%) rename net/hsr-prp/{hsr_slave.c => hsr_prp_slave.c} (96%) rename net/hsr-prp/{hsr_slave.h => hsr_prp_slave.h} (97%) diff --git a/net/hsr-prp/Makefile b/net/hsr-prp/Makefile index fd207c1a0854..608045f088a4 100644 --- a/net/hsr-prp/Makefile +++ b/net/hsr-prp/Makefile @@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only # -# Makefile for HSR +# Makefile for HSR & PRP # -obj-$(CONFIG_HSR_PRP) += hsr.o +obj-$(CONFIG_HSR_PRP) += hsr-prp.o -hsr-y := hsr_main.o hsr_framereg.o hsr_device.o \ - hsr_netlink.o hsr_slave.o hsr_forward.o -hsr-$(CONFIG_DEBUG_FS) += hsr_debugfs.o +hsr-prp-y := hsr_prp_main.o hsr_prp_framereg.o \ + hsr_prp_device.o hsr_netlink.o hsr_prp_slave.o \ + hsr_prp_forward.o +hsr-prp-$(CONFIG_DEBUG_FS) += hsr_prp_debugfs.o diff --git a/net/hsr-prp/hsr_netlink.c b/net/hsr-prp/hsr_netlink.c index 1decb25f6764..9791d4d89aef 100644 --- a/net/hsr-prp/hsr_netlink.c +++ b/net/hsr-prp/hsr_netlink.c @@ -11,9 +11,9 @@ #include #include #include -#include "hsr_main.h" -#include "hsr_device.h" -#include "hsr_framereg.h" +#include "hsr_prp_main.h" +#include "hsr_prp_device.h" +#include "hsr_prp_framereg.h" static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = { [IFLA_HSR_SLAVE1] = { .type = NLA_U32 }, diff --git a/net/hsr-prp/hsr_debugfs.c b/net/hsr-prp/hsr_prp_debugfs.c similarity index 97% rename from net/hsr-prp/hsr_debugfs.c rename to net/hsr-prp/hsr_prp_debugfs.c index 9787ef11ca71..d37b44082e92 100644 --- a/net/hsr-prp/hsr_debugfs.c +++ b/net/hsr-prp/hsr_prp_debugfs.c @@ -1,5 +1,5 @@ /* - * hsr_debugfs code + * hsr_prp_debugfs code * Copyright (C) 2019 Texas Instruments Incorporated * * Author(s): @@ -17,8 +17,8 @@ #include #include #include -#include "hsr_main.h" -#include "hsr_framereg.h" +#include "hsr_prp_main.h" +#include "hsr_prp_framereg.h" static struct dentry *hsr_debugfs_root_dir; diff --git a/net/hsr-prp/hsr_device.c b/net/hsr-prp/hsr_prp_device.c similarity index 98% rename from net/hsr-prp/hsr_device.c rename to net/hsr-prp/hsr_prp_device.c index cd99f548e440..ed50022849cb 100644 --- a/net/hsr-prp/hsr_device.c +++ b/net/hsr-prp/hsr_prp_device.c @@ -13,11 +13,11 @@ #include #include #include -#include "hsr_device.h" -#include "hsr_slave.h" -#include "hsr_framereg.h" -#include "hsr_main.h" -#include "hsr_forward.h" +#include "hsr_prp_device.h" +#include "hsr_prp_slave.h" +#include "hsr_prp_framereg.h" +#include "hsr_prp_main.h" +#include "hsr_prp_forward.h" static bool is_admin_up(struct net_device *dev) { diff --git a/net/hsr-prp/hsr_device.h b/net/hsr-prp/hsr_prp_device.h similarity index 96% rename from net/hsr-prp/hsr_device.h rename to net/hsr-prp/hsr_prp_device.h index a099d7de7e79..4cf3db603174 100644 --- a/net/hsr-prp/hsr_device.h +++ b/net/hsr-prp/hsr_prp_device.h @@ -9,7 +9,7 @@ #define __HSR_DEVICE_H #include -#include "hsr_main.h" +#include "hsr_prp_main.h" void hsr_dev_setup(struct net_device *dev); int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], diff --git a/net/hsr-prp/hsr_forward.c b/net/hsr-prp/hsr_prp_forward.c similarity index 99% rename from net/hsr-prp/hsr_forward.c rename to net/hsr-prp/hsr_prp_forward.c index ddd9605bad04..5ff0efba5db5 100644 --- a/net/hsr-prp/hsr_forward.c +++ b/net/hsr-prp/hsr_prp_forward.c @@ -5,13 +5,13 @@ * 2011-2014 Arvid Brodin, arvid.brodin@alten.se */ -#include "hsr_forward.h" +#include "hsr_prp_forward.h" #include #include #include #include -#include "hsr_main.h" -#include "hsr_framereg.h" +#include "hsr_prp_main.h" +#include "hsr_prp_framereg.h" struct hsr_node; diff --git a/net/hsr-prp/hsr_forward.h b/net/hsr-prp/hsr_prp_forward.h similarity index 92% rename from net/hsr-prp/hsr_forward.h rename to net/hsr-prp/hsr_prp_forward.h index 51a69295566c..cbc0704cc14a 100644 --- a/net/hsr-prp/hsr_forward.h +++ b/net/hsr-prp/hsr_prp_forward.h @@ -9,7 +9,7 @@ #define __HSR_FORWARD_H #include -#include "hsr_main.h" +#include "hsr_prp_main.h" void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port); diff --git a/net/hsr-prp/hsr_framereg.c b/net/hsr-prp/hsr_prp_framereg.c similarity index 99% rename from net/hsr-prp/hsr_framereg.c rename to net/hsr-prp/hsr_prp_framereg.c index 03b891904314..b02a2a0ca0ff 100644 --- a/net/hsr-prp/hsr_framereg.c +++ b/net/hsr-prp/hsr_prp_framereg.c @@ -14,8 +14,8 @@ #include #include #include -#include "hsr_main.h" -#include "hsr_framereg.h" +#include "hsr_prp_main.h" +#include "hsr_prp_framereg.h" #include "hsr_netlink.h" /* TODO: use hash lists for mac addresses (linux/jhash.h)? */ diff --git a/net/hsr-prp/hsr_framereg.h b/net/hsr-prp/hsr_prp_framereg.h similarity index 98% rename from net/hsr-prp/hsr_framereg.h rename to net/hsr-prp/hsr_prp_framereg.h index 0f0fa12b4329..c7a2a975aca0 100644 --- a/net/hsr-prp/hsr_framereg.h +++ b/net/hsr-prp/hsr_prp_framereg.h @@ -8,7 +8,7 @@ #ifndef __HSR_FRAMEREG_H #define __HSR_FRAMEREG_H -#include "hsr_main.h" +#include "hsr_prp_main.h" struct hsr_node; diff --git a/net/hsr-prp/hsr_main.c b/net/hsr-prp/hsr_prp_main.c similarity index 96% rename from net/hsr-prp/hsr_main.c rename to net/hsr-prp/hsr_prp_main.c index e2564de67603..d0b7117bf5f9 100644 --- a/net/hsr-prp/hsr_main.c +++ b/net/hsr-prp/hsr_prp_main.c @@ -9,11 +9,11 @@ #include #include #include -#include "hsr_main.h" -#include "hsr_device.h" +#include "hsr_prp_main.h" +#include "hsr_prp_device.h" #include "hsr_netlink.h" -#include "hsr_framereg.h" -#include "hsr_slave.h" +#include "hsr_prp_framereg.h" +#include "hsr_prp_slave.h" static bool hsr_slave_empty(struct hsr_priv *hsr) { diff --git a/net/hsr-prp/hsr_main.h b/net/hsr-prp/hsr_prp_main.h similarity index 100% rename from net/hsr-prp/hsr_main.h rename to net/hsr-prp/hsr_prp_main.h diff --git a/net/hsr-prp/hsr_slave.c b/net/hsr-prp/hsr_prp_slave.c similarity index 96% rename from net/hsr-prp/hsr_slave.c rename to net/hsr-prp/hsr_prp_slave.c index 25b6ffba26cd..fad8fef783cc 100644 --- a/net/hsr-prp/hsr_slave.c +++ b/net/hsr-prp/hsr_prp_slave.c @@ -5,14 +5,14 @@ * 2011-2014 Arvid Brodin, arvid.brodin@alten.se */ -#include "hsr_slave.h" +#include "hsr_prp_slave.h" #include #include #include -#include "hsr_main.h" -#include "hsr_device.h" -#include "hsr_forward.h" -#include "hsr_framereg.h" +#include "hsr_prp_main.h" +#include "hsr_prp_device.h" +#include "hsr_prp_forward.h" +#include "hsr_prp_framereg.h" static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) { diff --git a/net/hsr-prp/hsr_slave.h b/net/hsr-prp/hsr_prp_slave.h similarity index 97% rename from net/hsr-prp/hsr_slave.h rename to net/hsr-prp/hsr_prp_slave.h index 8953ea279ce9..c0360b111151 100644 --- a/net/hsr-prp/hsr_slave.h +++ b/net/hsr-prp/hsr_prp_slave.h @@ -10,7 +10,7 @@ #include #include #include -#include "hsr_main.h" +#include "hsr_prp_main.h" int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, enum hsr_port_type pt, struct netlink_ext_ack *extack); From patchwork Wed May 6 16:30:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 219762 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.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 3C31BC47257 for ; Wed, 6 May 2020 16:31:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0274620708 for ; Wed, 6 May 2020 16:31:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="n3/WAlFN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730363AbgEFQb1 (ORCPT ); Wed, 6 May 2020 12:31:27 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:46334 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729980AbgEFQam (ORCPT ); Wed, 6 May 2020 12:30:42 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 046GUanM025565; Wed, 6 May 2020 11:30:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1588782636; bh=XBbAdSs+7w2F8cv39wmxyojU1UOwbXJcZeUOhLfMjE0=; h=From:To:Subject:Date:In-Reply-To:References; b=n3/WAlFNCfD6POhD/w7U8g3c7KdTiLuOc4HF3l4OIb6wnAAUd47KQKgkNMm6mXXwb fZU9ZJCdb7rpUwlDLOZG9t60hze1bDdG8t77Hn2H0Gj13uOgfhWcOl1dijEEQFBMsc R8QehELu0hAchcV+0UDJBNpKxilRtPBhNzVG9nKc= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 046GUaUn021901 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 May 2020 11:30:36 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 6 May 2020 11:30:36 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 6 May 2020 11:30:36 -0500 Received: from uda0868495.fios-router.home (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 046GUXDh119719; Wed, 6 May 2020 11:30:35 -0500 From: Murali Karicheri To: , , , , , , Subject: [net-next RFC PATCH 04/13] net: hsr: rename hsr variable inside struct hsr_port to priv Date: Wed, 6 May 2020 12:30:24 -0400 Message-ID: <20200506163033.3843-5-m-karicheri2@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506163033.3843-1-m-karicheri2@ti.com> References: <20200506163033.3843-1-m-karicheri2@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The struct hsr_port has a variable pointing to the private struct of the driver. This should have been named priv instead of hsr to be clean. This would be needed as it is planned to re-use the code for prp and then priv variable is more appropriate than hsr. So fix it by search and replace of all instances within the driver. Signed-off-by: Murali Karicheri --- net/hsr-prp/hsr_netlink.c | 36 ++++----- net/hsr-prp/hsr_prp_device.c | 144 ++++++++++++++++----------------- net/hsr-prp/hsr_prp_device.h | 4 +- net/hsr-prp/hsr_prp_forward.c | 24 +++--- net/hsr-prp/hsr_prp_framereg.c | 91 ++++++++++----------- net/hsr-prp/hsr_prp_framereg.h | 10 +-- net/hsr-prp/hsr_prp_main.c | 32 ++++---- net/hsr-prp/hsr_prp_main.h | 8 +- net/hsr-prp/hsr_prp_slave.c | 28 +++---- net/hsr-prp/hsr_prp_slave.h | 2 +- 10 files changed, 190 insertions(+), 189 deletions(-) diff --git a/net/hsr-prp/hsr_netlink.c b/net/hsr-prp/hsr_netlink.c index 9791d4d89aef..9e3f6eda69f5 100644 --- a/net/hsr-prp/hsr_netlink.c +++ b/net/hsr-prp/hsr_netlink.c @@ -85,24 +85,24 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev, static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) { - struct hsr_priv *hsr = netdev_priv(dev); + struct hsr_priv *priv = netdev_priv(dev); struct hsr_port *port; - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); + port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_A); if (port) { if (nla_put_u32(skb, IFLA_HSR_SLAVE1, port->dev->ifindex)) goto nla_put_failure; } - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); + port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_B); if (port) { if (nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex)) goto nla_put_failure; } if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN, - hsr->sup_multicast_addr) || - nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr)) + priv->sup_multicast_addr) || + nla_put_u16(skb, IFLA_HSR_SEQ_NR, priv->sequence_nr)) goto nla_put_failure; return 0; @@ -142,7 +142,7 @@ static const struct genl_multicast_group hsr_mcgrps[] = { * over one of the slave interfaces. This would indicate an open network ring * (i.e. a link has failed somewhere). */ -void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN], +void hsr_nl_ringerror(struct hsr_priv *priv, unsigned char addr[ETH_ALEN], struct hsr_port *port) { struct sk_buff *skb; @@ -177,7 +177,7 @@ void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN], fail: rcu_read_lock(); - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); netdev_warn(master->dev, "Could not send HSR ring error message\n"); rcu_read_unlock(); } @@ -185,7 +185,7 @@ void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN], /* This is called when we haven't heard from the node with MAC address addr for * some time (just before the node is removed from the node table/list). */ -void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN]) +void hsr_nl_nodedown(struct hsr_priv *priv, unsigned char addr[ETH_ALEN]) { struct sk_buff *skb; void *msg_head; @@ -214,7 +214,7 @@ void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN]) fail: rcu_read_lock(); - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); netdev_warn(master->dev, "Could not send HSR node down\n"); rcu_read_unlock(); } @@ -236,7 +236,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) /* For sending */ struct sk_buff *skb_out; void *msg_head; - struct hsr_priv *hsr; + struct hsr_priv *priv; struct hsr_port *port; unsigned char hsr_node_addr_b[ETH_ALEN]; int hsr_node_if1_age; @@ -283,8 +283,8 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) if (res < 0) goto nla_put_failure; - hsr = netdev_priv(hsr_dev); - res = hsr_get_node_data(hsr, + priv = netdev_priv(hsr_dev); + res = hsr_get_node_data(priv, (unsigned char *) nla_data(info->attrs[HSR_A_NODE_ADDR]), hsr_node_addr_b, @@ -319,7 +319,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq); if (res < 0) goto nla_put_failure; - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); + port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_A); if (port) res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX, port->dev->ifindex); @@ -332,7 +332,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq); if (res < 0) goto nla_put_failure; - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); + port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_B); if (port) res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX, port->dev->ifindex); @@ -368,7 +368,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) unsigned char addr[ETH_ALEN]; struct net_device *hsr_dev; struct sk_buff *skb_out; - struct hsr_priv *hsr; + struct hsr_priv *priv; bool restart = false; struct nlattr *na; void *pos = NULL; @@ -412,10 +412,10 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) goto nla_put_failure; } - hsr = netdev_priv(hsr_dev); + priv = netdev_priv(hsr_dev); if (!pos) - pos = hsr_get_next_node(hsr, NULL, addr); + pos = hsr_get_next_node(priv, NULL, addr); while (pos) { res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr); if (res < 0) { @@ -428,7 +428,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) } goto nla_put_failure; } - pos = hsr_get_next_node(hsr, pos, addr); + pos = hsr_get_next_node(priv, pos, addr); } rcu_read_unlock(); diff --git a/net/hsr-prp/hsr_prp_device.c b/net/hsr-prp/hsr_prp_device.c index ed50022849cb..df85b8f7f007 100644 --- a/net/hsr-prp/hsr_prp_device.c +++ b/net/hsr-prp/hsr_prp_device.c @@ -60,7 +60,7 @@ static bool hsr_check_carrier(struct hsr_port *master) ASSERT_RTNL(); - hsr_for_each_port(master->hsr, port) { + hsr_for_each_port(master->priv, port) { if (port->type != HSR_PT_MASTER && is_slave_up(port->dev)) { netif_carrier_on(master->dev); return true; @@ -75,29 +75,29 @@ static bool hsr_check_carrier(struct hsr_port *master) static void hsr_check_announce(struct net_device *hsr_dev, unsigned char old_operstate) { - struct hsr_priv *hsr; + struct hsr_priv *priv; - hsr = netdev_priv(hsr_dev); + priv = netdev_priv(hsr_dev); if (hsr_dev->operstate == IF_OPER_UP && old_operstate != IF_OPER_UP) { /* Went up */ - hsr->announce_count = 0; - mod_timer(&hsr->announce_timer, + priv->announce_count = 0; + mod_timer(&priv->announce_timer, jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL)); } if (hsr_dev->operstate != IF_OPER_UP && old_operstate == IF_OPER_UP) /* Went down */ - del_timer(&hsr->announce_timer); + del_timer(&priv->announce_timer); } -void hsr_check_carrier_and_operstate(struct hsr_priv *hsr) +void hsr_check_carrier_and_operstate(struct hsr_priv *priv) { struct hsr_port *master; unsigned char old_operstate; bool has_carrier; - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); /* netif_stacked_transfer_operstate() cannot be used here since * it doesn't set IF_OPER_LOWERLAYERDOWN (?) */ @@ -107,13 +107,13 @@ void hsr_check_carrier_and_operstate(struct hsr_priv *hsr) hsr_check_announce(master->dev, old_operstate); } -int hsr_get_max_mtu(struct hsr_priv *hsr) +int hsr_get_max_mtu(struct hsr_priv *priv) { unsigned int mtu_max; struct hsr_port *port; mtu_max = ETH_DATA_LEN; - hsr_for_each_port(hsr, port) + hsr_for_each_port(priv, port) if (port->type != HSR_PT_MASTER) mtu_max = min(port->dev->mtu, mtu_max); @@ -124,11 +124,11 @@ int hsr_get_max_mtu(struct hsr_priv *hsr) static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu) { - struct hsr_priv *hsr; + struct hsr_priv *priv; - hsr = netdev_priv(dev); + priv = netdev_priv(dev); - if (new_mtu > hsr_get_max_mtu(hsr)) { + if (new_mtu > hsr_get_max_mtu(priv)) { netdev_info(dev, "A HSR master's MTU cannot be greater than the smallest MTU of its slaves minus the HSR Tag length (%d octets).\n", HSR_HLEN); return -EINVAL; @@ -141,14 +141,14 @@ static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu) static int hsr_dev_open(struct net_device *dev) { - struct hsr_priv *hsr; + struct hsr_priv *priv; struct hsr_port *port; char designation; - hsr = netdev_priv(dev); + priv = netdev_priv(dev); designation = '\0'; - hsr_for_each_port(hsr, port) { + hsr_for_each_port(priv, port) { if (port->type == HSR_PT_MASTER) continue; switch (port->type) { @@ -178,7 +178,7 @@ static int hsr_dev_close(struct net_device *dev) return 0; } -static netdev_features_t hsr_features_recompute(struct hsr_priv *hsr, +static netdev_features_t hsr_features_recompute(struct hsr_priv *priv, netdev_features_t features) { netdev_features_t mask; @@ -194,7 +194,7 @@ static netdev_features_t hsr_features_recompute(struct hsr_priv *hsr, * may become enabled. */ features &= ~NETIF_F_ONE_FOR_ALL; - hsr_for_each_port(hsr, port) + hsr_for_each_port(priv, port) features = netdev_increment_features(features, port->dev->features, mask); @@ -205,17 +205,17 @@ static netdev_features_t hsr_features_recompute(struct hsr_priv *hsr, static netdev_features_t hsr_fix_features(struct net_device *dev, netdev_features_t features) { - struct hsr_priv *hsr = netdev_priv(dev); + struct hsr_priv *priv = netdev_priv(dev); - return hsr_features_recompute(hsr, features); + return hsr_features_recompute(priv, features); } static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev) { - struct hsr_priv *hsr = netdev_priv(dev); + struct hsr_priv *priv = netdev_priv(dev); struct hsr_port *master; - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); if (master) { skb->dev = master->dev; hsr_forward_skb(skb, master); @@ -257,7 +257,7 @@ static void send_hsr_supervision_frame(struct hsr_port *master, skb->priority = TC_PRIO_CONTROL; if (dev_hard_header(skb, skb->dev, (hsr_ver ? ETH_P_HSR : ETH_P_PRP), - master->hsr->sup_multicast_addr, + master->priv->sup_multicast_addr, skb->dev->dev_addr, skb->len) <= 0) goto out; skb_reset_mac_header(skb); @@ -275,17 +275,17 @@ static void send_hsr_supervision_frame(struct hsr_port *master, set_hsr_stag_HSR_ver(hsr_stag, hsr_ver); /* From HSRv1 on we have separate supervision sequence numbers. */ - spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags); + spin_lock_irqsave(&master->priv->seqnr_lock, irqflags); if (hsr_ver > 0) { - hsr_stag->sequence_nr = htons(master->hsr->sup_sequence_nr); - hsr_tag->sequence_nr = htons(master->hsr->sequence_nr); - master->hsr->sup_sequence_nr++; - master->hsr->sequence_nr++; + hsr_stag->sequence_nr = htons(master->priv->sup_sequence_nr); + hsr_tag->sequence_nr = htons(master->priv->sequence_nr); + master->priv->sup_sequence_nr++; + master->priv->sequence_nr++; } else { - hsr_stag->sequence_nr = htons(master->hsr->sequence_nr); - master->hsr->sequence_nr++; + hsr_stag->sequence_nr = htons(master->priv->sequence_nr); + master->priv->sequence_nr++; } - spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags); + spin_unlock_irqrestore(&master->priv->seqnr_lock, irqflags); hsr_stag->HSR_TLV_type = type; /* TODO: Why 12 in HSRv0? */ @@ -311,47 +311,47 @@ static void send_hsr_supervision_frame(struct hsr_port *master, */ static void hsr_announce(struct timer_list *t) { - struct hsr_priv *hsr; + struct hsr_priv *priv; struct hsr_port *master; unsigned long interval; - hsr = from_timer(hsr, t, announce_timer); + priv = from_timer(priv, t, announce_timer); rcu_read_lock(); - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); - if (hsr->announce_count < 3 && hsr->prot_version == 0) { + if (priv->announce_count < 3 && priv->prot_version == 0) { send_hsr_supervision_frame(master, HSR_TLV_ANNOUNCE, - hsr->prot_version); - hsr->announce_count++; + priv->prot_version); + priv->announce_count++; interval = msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL); } else { send_hsr_supervision_frame(master, HSR_TLV_LIFE_CHECK, - hsr->prot_version); + priv->prot_version); interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL); } if (is_admin_up(master->dev)) - mod_timer(&hsr->announce_timer, jiffies + interval); + mod_timer(&priv->announce_timer, jiffies + interval); rcu_read_unlock(); } -static void hsr_del_ports(struct hsr_priv *hsr) +static void hsr_del_ports(struct hsr_priv *priv) { struct hsr_port *port; - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); + port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_A); if (port) hsr_del_port(port); - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); + port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_B); if (port) hsr_del_port(port); - port = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + port = hsr_port_get_hsr(priv, HSR_PT_MASTER); if (port) hsr_del_port(port); } @@ -362,16 +362,16 @@ static void hsr_del_ports(struct hsr_priv *hsr) */ static void hsr_dev_destroy(struct net_device *hsr_dev) { - struct hsr_priv *hsr = netdev_priv(hsr_dev); + struct hsr_priv *priv = netdev_priv(hsr_dev); - hsr_debugfs_term(hsr); - hsr_del_ports(hsr); + hsr_debugfs_term(priv); + hsr_del_ports(priv); - del_timer_sync(&hsr->prune_timer); - del_timer_sync(&hsr->announce_timer); + del_timer_sync(&priv->prune_timer); + del_timer_sync(&priv->announce_timer); - hsr_del_self_node(hsr); - hsr_del_nodes(&hsr->node_db); + hsr_del_self_node(priv); + hsr_del_nodes(&priv->node_db); } static const struct net_device_ops hsr_device_ops = { @@ -434,35 +434,35 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], unsigned char multicast_spec, u8 protocol_version, struct netlink_ext_ack *extack) { - struct hsr_priv *hsr; + struct hsr_priv *priv; int res; - hsr = netdev_priv(hsr_dev); - INIT_LIST_HEAD(&hsr->ports); - INIT_LIST_HEAD(&hsr->node_db); - INIT_LIST_HEAD(&hsr->self_node_db); - spin_lock_init(&hsr->list_lock); + priv = netdev_priv(hsr_dev); + INIT_LIST_HEAD(&priv->ports); + INIT_LIST_HEAD(&priv->node_db); + INIT_LIST_HEAD(&priv->self_node_db); + spin_lock_init(&priv->list_lock); ether_addr_copy(hsr_dev->dev_addr, slave[0]->dev_addr); /* Make sure we recognize frames from ourselves in hsr_rcv() */ - res = hsr_create_self_node(hsr, hsr_dev->dev_addr, + res = hsr_create_self_node(priv, hsr_dev->dev_addr, slave[1]->dev_addr); if (res < 0) return res; - spin_lock_init(&hsr->seqnr_lock); + spin_lock_init(&priv->seqnr_lock); /* Overflow soon to find bugs easier: */ - hsr->sequence_nr = HSR_SEQNR_START; - hsr->sup_sequence_nr = HSR_SUP_SEQNR_START; + priv->sequence_nr = HSR_SEQNR_START; + priv->sup_sequence_nr = HSR_SUP_SEQNR_START; - timer_setup(&hsr->announce_timer, hsr_announce, 0); - timer_setup(&hsr->prune_timer, hsr_prune_nodes, 0); + timer_setup(&priv->announce_timer, hsr_announce, 0); + timer_setup(&priv->prune_timer, hsr_prune_nodes, 0); - ether_addr_copy(hsr->sup_multicast_addr, def_multicast_addr); - hsr->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec; + ether_addr_copy(priv->sup_multicast_addr, def_multicast_addr); + priv->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec; - hsr->prot_version = protocol_version; + priv->prot_version = protocol_version; /* FIXME: should I modify the value of these? * @@ -477,7 +477,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], /* Make sure the 1st call to netif_carrier_on() gets through */ netif_carrier_off(hsr_dev); - res = hsr_add_port(hsr, hsr_dev, HSR_PT_MASTER, extack); + res = hsr_add_port(priv, hsr_dev, HSR_PT_MASTER, extack); if (res) goto err_add_master; @@ -485,25 +485,25 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], if (res) goto err_unregister; - res = hsr_add_port(hsr, slave[0], HSR_PT_SLAVE_A, extack); + res = hsr_add_port(priv, slave[0], HSR_PT_SLAVE_A, extack); if (res) goto err_add_slaves; - res = hsr_add_port(hsr, slave[1], HSR_PT_SLAVE_B, extack); + res = hsr_add_port(priv, slave[1], HSR_PT_SLAVE_B, extack); if (res) goto err_add_slaves; - hsr_debugfs_init(hsr, hsr_dev); - mod_timer(&hsr->prune_timer, jiffies + msecs_to_jiffies(PRUNE_PERIOD)); + hsr_debugfs_init(priv, hsr_dev); + mod_timer(&priv->prune_timer, jiffies + msecs_to_jiffies(PRUNE_PERIOD)); return 0; err_add_slaves: unregister_netdevice(hsr_dev); err_unregister: - hsr_del_ports(hsr); + hsr_del_ports(priv); err_add_master: - hsr_del_self_node(hsr); + hsr_del_self_node(priv); return res; } diff --git a/net/hsr-prp/hsr_prp_device.h b/net/hsr-prp/hsr_prp_device.h index 4cf3db603174..91642845cdd2 100644 --- a/net/hsr-prp/hsr_prp_device.h +++ b/net/hsr-prp/hsr_prp_device.h @@ -15,8 +15,8 @@ void hsr_dev_setup(struct net_device *dev); int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], unsigned char multicast_spec, u8 protocol_version, struct netlink_ext_ack *extack); -void hsr_check_carrier_and_operstate(struct hsr_priv *hsr); +void hsr_check_carrier_and_operstate(struct hsr_priv *priv); bool is_hsr_master(struct net_device *dev); -int hsr_get_max_mtu(struct hsr_priv *hsr); +int hsr_get_max_mtu(struct hsr_priv *priv); #endif /* __HSR_DEVICE_H */ diff --git a/net/hsr-prp/hsr_prp_forward.c b/net/hsr-prp/hsr_prp_forward.c index 5ff0efba5db5..2b6abb09fe4b 100644 --- a/net/hsr-prp/hsr_prp_forward.c +++ b/net/hsr-prp/hsr_prp_forward.c @@ -42,7 +42,7 @@ struct hsr_frame_info { * 3) Allow different MAC addresses for the two slave interfaces, using the * MacAddressA field. */ -static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb) +static bool is_supervision_frame(struct hsr_priv *priv, struct sk_buff *skb) { struct ethhdr *eth_hdr; struct hsr_sup_tag *hsr_sup_tag; @@ -53,7 +53,7 @@ static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb) /* Correct addr? */ if (!ether_addr_equal(eth_hdr->h_dest, - hsr->sup_multicast_addr)) + priv->sup_multicast_addr)) return false; /* Correct ether type?. */ @@ -172,7 +172,7 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o, memmove(dst, src, movelen); skb_reset_mac_header(skb); - hsr_fill_tag(skb, frame, port, port->hsr->prot_version); + hsr_fill_tag(skb, frame, port, port->priv->prot_version); return skb; } @@ -244,7 +244,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame) struct hsr_port *port; struct sk_buff *skb; - hsr_for_each_port(frame->port_rcv->hsr, port) { + hsr_for_each_port(frame->port_rcv->priv, port) { /* Don't send frame back the way it came */ if (port == frame->port_rcv) continue; @@ -286,10 +286,10 @@ static void hsr_forward_do(struct hsr_frame_info *frame) } } -static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb, +static void check_local_dest(struct hsr_priv *priv, struct sk_buff *skb, struct hsr_frame_info *frame) { - if (hsr_addr_is_self(hsr, eth_hdr(skb)->h_dest)) { + if (hsr_addr_is_self(priv, eth_hdr(skb)->h_dest)) { frame->is_local_exclusive = true; skb->pkt_type = PACKET_HOST; } else { @@ -311,7 +311,7 @@ static int hsr_fill_frame_info(struct hsr_frame_info *frame, struct ethhdr *ethhdr; unsigned long irqflags; - frame->is_supervision = is_supervision_frame(port->hsr, skb); + frame->is_supervision = is_supervision_frame(port->priv, skb); frame->node_src = hsr_get_node(port, skb, frame->is_supervision); if (!frame->node_src) return -1; /* Unknown node and !is_supervision, or no mem */ @@ -332,14 +332,14 @@ static int hsr_fill_frame_info(struct hsr_frame_info *frame, frame->skb_std = skb; frame->skb_hsr = NULL; /* Sequence nr for the master node */ - spin_lock_irqsave(&port->hsr->seqnr_lock, irqflags); - frame->sequence_nr = port->hsr->sequence_nr; - port->hsr->sequence_nr++; - spin_unlock_irqrestore(&port->hsr->seqnr_lock, irqflags); + spin_lock_irqsave(&port->priv->seqnr_lock, irqflags); + frame->sequence_nr = port->priv->sequence_nr; + port->priv->sequence_nr++; + spin_unlock_irqrestore(&port->priv->seqnr_lock, irqflags); } frame->port_rcv = port; - check_local_dest(port->hsr, skb, frame); + check_local_dest(port->priv, skb, frame); return 0; } diff --git a/net/hsr-prp/hsr_prp_framereg.c b/net/hsr-prp/hsr_prp_framereg.c index b02a2a0ca0ff..854338352e93 100644 --- a/net/hsr-prp/hsr_prp_framereg.c +++ b/net/hsr-prp/hsr_prp_framereg.c @@ -37,11 +37,11 @@ static bool seq_nr_after(u16 a, u16 b) #define seq_nr_before(a, b) seq_nr_after((b), (a)) #define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) -bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr) +bool hsr_addr_is_self(struct hsr_priv *priv, unsigned char *addr) { struct hsr_node *node; - node = list_first_or_null_rcu(&hsr->self_node_db, struct hsr_node, + node = list_first_or_null_rcu(&priv->self_node_db, struct hsr_node, mac_list); if (!node) { WARN_ONCE(1, "HSR: No self node\n"); @@ -74,11 +74,11 @@ static struct hsr_node *find_node_by_addr_A(struct list_head *node_db, /* Helper for device init; the self_node_db is used in hsr_rcv() to recognize * frames from self that's been looped over the HSR ring. */ -int hsr_create_self_node(struct hsr_priv *hsr, +int hsr_create_self_node(struct hsr_priv *priv, unsigned char addr_a[ETH_ALEN], unsigned char addr_b[ETH_ALEN]) { - struct list_head *self_node_db = &hsr->self_node_db; + struct list_head *self_node_db = &priv->self_node_db; struct hsr_node *node, *oldnode; node = kmalloc(sizeof(*node), GFP_KERNEL); @@ -88,33 +88,33 @@ int hsr_create_self_node(struct hsr_priv *hsr, ether_addr_copy(node->macaddress_A, addr_a); ether_addr_copy(node->macaddress_B, addr_b); - spin_lock_bh(&hsr->list_lock); + spin_lock_bh(&priv->list_lock); oldnode = list_first_or_null_rcu(self_node_db, struct hsr_node, mac_list); if (oldnode) { list_replace_rcu(&oldnode->mac_list, &node->mac_list); - spin_unlock_bh(&hsr->list_lock); + spin_unlock_bh(&priv->list_lock); kfree_rcu(oldnode, rcu_head); } else { list_add_tail_rcu(&node->mac_list, self_node_db); - spin_unlock_bh(&hsr->list_lock); + spin_unlock_bh(&priv->list_lock); } return 0; } -void hsr_del_self_node(struct hsr_priv *hsr) +void hsr_del_self_node(struct hsr_priv *priv) { - struct list_head *self_node_db = &hsr->self_node_db; + struct list_head *self_node_db = &priv->self_node_db; struct hsr_node *node; - spin_lock_bh(&hsr->list_lock); + spin_lock_bh(&priv->list_lock); node = list_first_or_null_rcu(self_node_db, struct hsr_node, mac_list); if (node) { list_del_rcu(&node->mac_list); kfree_rcu(node, rcu_head); } - spin_unlock_bh(&hsr->list_lock); + spin_unlock_bh(&priv->list_lock); } void hsr_del_nodes(struct list_head *node_db) @@ -130,7 +130,7 @@ void hsr_del_nodes(struct list_head *node_db) * seq_out is used to initialize filtering of outgoing duplicate frames * originating from the newly added node. */ -static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, +static struct hsr_node *hsr_add_node(struct hsr_priv *priv, struct list_head *node_db, unsigned char addr[], u16 seq_out) @@ -154,19 +154,19 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, for (i = 0; i < HSR_PT_PORTS; i++) new_node->seq_out[i] = seq_out; - spin_lock_bh(&hsr->list_lock); + spin_lock_bh(&priv->list_lock); list_for_each_entry_rcu(node, node_db, mac_list, - lockdep_is_held(&hsr->list_lock)) { + lockdep_is_held(&priv->list_lock)) { if (ether_addr_equal(node->macaddress_A, addr)) goto out; if (ether_addr_equal(node->macaddress_B, addr)) goto out; } list_add_tail_rcu(&new_node->mac_list, node_db); - spin_unlock_bh(&hsr->list_lock); + spin_unlock_bh(&priv->list_lock); return new_node; out: - spin_unlock_bh(&hsr->list_lock); + spin_unlock_bh(&priv->list_lock); kfree(new_node); return node; } @@ -176,8 +176,8 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, bool is_sup) { - struct list_head *node_db = &port->hsr->node_db; - struct hsr_priv *hsr = port->hsr; + struct list_head *node_db = &port->priv->node_db; + struct hsr_priv *priv = port->priv; struct hsr_node *node; struct ethhdr *ethhdr; u16 seq_out; @@ -211,7 +211,7 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, seq_out = HSR_SEQNR_START; } - return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out); + return hsr_add_node(priv, node_db, ethhdr->h_source, seq_out); } /* Use the Supervision frame's info about an eventual macaddress_B for merging @@ -221,7 +221,7 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, struct hsr_port *port_rcv) { - struct hsr_priv *hsr = port_rcv->hsr; + struct hsr_priv *priv = port_rcv->priv; struct hsr_sup_payload *hsr_sp; struct hsr_node *node_real; struct list_head *node_db; @@ -243,11 +243,11 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, hsr_sp = (struct hsr_sup_payload *)skb->data; /* Merge node_curr (registered on macaddress_B) into node_real */ - node_db = &port_rcv->hsr->node_db; + node_db = &port_rcv->priv->node_db; node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); if (!node_real) /* No frame received from AddrA of this node yet */ - node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, + node_real = hsr_add_node(priv, node_db, hsr_sp->macaddress_A, HSR_SEQNR_START - 1); if (!node_real) goto done; /* No mem */ @@ -268,9 +268,9 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, } node_real->addr_B_port = port_rcv->type; - spin_lock_bh(&hsr->list_lock); + spin_lock_bh(&priv->list_lock); list_del_rcu(&node_curr->mac_list); - spin_unlock_bh(&hsr->list_lock); + spin_unlock_bh(&priv->list_lock); kfree_rcu(node_curr, rcu_head); done: @@ -315,7 +315,7 @@ void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb, if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) return; - node_dst = find_node_by_addr_A(&port->hsr->node_db, + node_dst = find_node_by_addr_A(&port->priv->node_db, eth_hdr(skb)->h_dest); if (!node_dst) { if (net_ratelimit()) @@ -360,22 +360,22 @@ int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, return 0; } -static struct hsr_port *get_late_port(struct hsr_priv *hsr, +static struct hsr_port *get_late_port(struct hsr_priv *priv, struct hsr_node *node) { if (node->time_in_stale[HSR_PT_SLAVE_A]) - return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); + return hsr_port_get_hsr(priv, HSR_PT_SLAVE_A); if (node->time_in_stale[HSR_PT_SLAVE_B]) - return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); + return hsr_port_get_hsr(priv, HSR_PT_SLAVE_B); if (time_after(node->time_in[HSR_PT_SLAVE_B], node->time_in[HSR_PT_SLAVE_A] + msecs_to_jiffies(MAX_SLAVE_DIFF))) - return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); + return hsr_port_get_hsr(priv, HSR_PT_SLAVE_A); if (time_after(node->time_in[HSR_PT_SLAVE_A], node->time_in[HSR_PT_SLAVE_B] + msecs_to_jiffies(MAX_SLAVE_DIFF))) - return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); + return hsr_port_get_hsr(priv, HSR_PT_SLAVE_B); return NULL; } @@ -385,21 +385,21 @@ static struct hsr_port *get_late_port(struct hsr_priv *hsr, */ void hsr_prune_nodes(struct timer_list *t) { - struct hsr_priv *hsr = from_timer(hsr, t, prune_timer); + struct hsr_priv *priv = from_timer(priv, t, prune_timer); struct hsr_node *node; struct hsr_node *tmp; struct hsr_port *port; unsigned long timestamp; unsigned long time_a, time_b; - spin_lock_bh(&hsr->list_lock); - list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { + spin_lock_bh(&priv->list_lock); + list_for_each_entry_safe(node, tmp, &priv->node_db, mac_list) { /* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A] * nor time_in[HSR_PT_SLAVE_B], will ever be updated for * the master port. Thus the master node will be repeatedly * pruned leading to packet loss. */ - if (hsr_addr_is_self(hsr, node->macaddress_A)) + if (hsr_addr_is_self(priv, node->macaddress_A)) continue; /* Shorthand */ @@ -426,35 +426,36 @@ void hsr_prune_nodes(struct timer_list *t) if (time_is_after_jiffies(timestamp + msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) { rcu_read_lock(); - port = get_late_port(hsr, node); + port = get_late_port(priv, node); if (port) - hsr_nl_ringerror(hsr, node->macaddress_A, port); + hsr_nl_ringerror(priv, + node->macaddress_A, port); rcu_read_unlock(); } /* Prune old entries */ if (time_is_before_jiffies(timestamp + msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { - hsr_nl_nodedown(hsr, node->macaddress_A); + hsr_nl_nodedown(priv, node->macaddress_A); list_del_rcu(&node->mac_list); /* Note that we need to free this entry later: */ kfree_rcu(node, rcu_head); } } - spin_unlock_bh(&hsr->list_lock); + spin_unlock_bh(&priv->list_lock); /* Restart timer */ - mod_timer(&hsr->prune_timer, + mod_timer(&priv->prune_timer, jiffies + msecs_to_jiffies(PRUNE_PERIOD)); } -void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos, +void *hsr_get_next_node(struct hsr_priv *priv, void *_pos, unsigned char addr[ETH_ALEN]) { struct hsr_node *node; if (!_pos) { - node = list_first_or_null_rcu(&hsr->node_db, + node = list_first_or_null_rcu(&priv->node_db, struct hsr_node, mac_list); if (node) ether_addr_copy(addr, node->macaddress_A); @@ -462,7 +463,7 @@ void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos, } node = _pos; - list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { + list_for_each_entry_continue_rcu(node, &priv->node_db, mac_list) { ether_addr_copy(addr, node->macaddress_A); return node; } @@ -470,7 +471,7 @@ void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos, return NULL; } -int hsr_get_node_data(struct hsr_priv *hsr, +int hsr_get_node_data(struct hsr_priv *priv, const unsigned char *addr, unsigned char addr_b[ETH_ALEN], unsigned int *addr_b_ifindex, @@ -483,7 +484,7 @@ int hsr_get_node_data(struct hsr_priv *hsr, struct hsr_port *port; unsigned long tdiff; - node = find_node_by_addr_A(&hsr->node_db, addr); + node = find_node_by_addr_A(&priv->node_db, addr); if (!node) return -ENOENT; @@ -514,7 +515,7 @@ int hsr_get_node_data(struct hsr_priv *hsr, *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; if (node->addr_B_port != HSR_PT_NONE) { - port = hsr_port_get_hsr(hsr, node->addr_B_port); + port = hsr_port_get_hsr(priv, node->addr_B_port); *addr_b_ifindex = port->dev->ifindex; } else { *addr_b_ifindex = -1; diff --git a/net/hsr-prp/hsr_prp_framereg.h b/net/hsr-prp/hsr_prp_framereg.h index c7a2a975aca0..b29b685e444a 100644 --- a/net/hsr-prp/hsr_prp_framereg.h +++ b/net/hsr-prp/hsr_prp_framereg.h @@ -12,13 +12,13 @@ struct hsr_node; -void hsr_del_self_node(struct hsr_priv *hsr); +void hsr_del_self_node(struct hsr_priv *priv); void hsr_del_nodes(struct list_head *node_db); struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, bool is_sup); void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, struct hsr_port *port); -bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr); +bool hsr_addr_is_self(struct hsr_priv *priv, unsigned char *addr); void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb); void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb, @@ -31,14 +31,14 @@ int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, void hsr_prune_nodes(struct timer_list *t); -int hsr_create_self_node(struct hsr_priv *hsr, +int hsr_create_self_node(struct hsr_priv *priv, unsigned char addr_a[ETH_ALEN], unsigned char addr_b[ETH_ALEN]); -void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos, +void *hsr_get_next_node(struct hsr_priv *priv, void *_pos, unsigned char addr[ETH_ALEN]); -int hsr_get_node_data(struct hsr_priv *hsr, +int hsr_get_node_data(struct hsr_priv *priv, const unsigned char *addr, unsigned char addr_b[ETH_ALEN], unsigned int *addr_b_ifindex, diff --git a/net/hsr-prp/hsr_prp_main.c b/net/hsr-prp/hsr_prp_main.c index d0b7117bf5f9..caa544d0af42 100644 --- a/net/hsr-prp/hsr_prp_main.c +++ b/net/hsr-prp/hsr_prp_main.c @@ -15,11 +15,11 @@ #include "hsr_prp_framereg.h" #include "hsr_prp_slave.h" -static bool hsr_slave_empty(struct hsr_priv *hsr) +static bool hsr_slave_empty(struct hsr_priv *priv) { struct hsr_port *port; - hsr_for_each_port(hsr, port) + hsr_for_each_port(priv, port) if (port->type != HSR_PT_MASTER) return false; return true; @@ -30,7 +30,7 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, { struct hsr_port *port, *master; struct net_device *dev; - struct hsr_priv *hsr; + struct hsr_priv *priv; LIST_HEAD(list_kill); int mtu_max; int res; @@ -40,21 +40,21 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, if (!port) { if (!is_hsr_master(dev)) return NOTIFY_DONE; /* Not an HSR device */ - hsr = netdev_priv(dev); - port = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + priv = netdev_priv(dev); + port = hsr_port_get_hsr(priv, HSR_PT_MASTER); if (!port) { /* Resend of notification concerning removed device? */ return NOTIFY_DONE; } } else { - hsr = port->hsr; + priv = port->priv; } switch (event) { case NETDEV_UP: /* Administrative state DOWN */ case NETDEV_DOWN: /* Administrative state UP */ case NETDEV_CHANGE: /* Link (carrier) state changes */ - hsr_check_carrier_and_operstate(hsr); + hsr_check_carrier_and_operstate(priv); break; case NETDEV_CHANGENAME: if (is_hsr_master(dev)) @@ -69,7 +69,7 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, break; } - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); if (port->type == HSR_PT_SLAVE_A) { ether_addr_copy(master->dev->dev_addr, dev->dev_addr); @@ -78,8 +78,8 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, } /* Make sure we recognize frames from ourselves in hsr_rcv() */ - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); - res = hsr_create_self_node(hsr, + port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_B); + res = hsr_create_self_node(priv, master->dev->dev_addr, port ? port->dev->dev_addr : @@ -91,15 +91,15 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, case NETDEV_CHANGEMTU: if (port->type == HSR_PT_MASTER) break; /* Handled in ndo_change_mtu() */ - mtu_max = hsr_get_max_mtu(port->hsr); - master = hsr_port_get_hsr(port->hsr, HSR_PT_MASTER); + mtu_max = hsr_get_max_mtu(port->priv); + master = hsr_port_get_hsr(port->priv, HSR_PT_MASTER); master->dev->mtu = mtu_max; break; case NETDEV_UNREGISTER: if (!is_hsr_master(dev)) { - master = hsr_port_get_hsr(port->hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(port->priv, HSR_PT_MASTER); hsr_del_port(port); - if (hsr_slave_empty(master->hsr)) { + if (hsr_slave_empty(master->priv)) { unregister_netdevice_queue(master->dev, &list_kill); unregister_netdevice_many(&list_kill); @@ -116,11 +116,11 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, return NOTIFY_DONE; } -struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt) +struct hsr_port *hsr_port_get_hsr(struct hsr_priv *priv, enum hsr_port_type pt) { struct hsr_port *port; - hsr_for_each_port(hsr, port) + hsr_for_each_port(priv, port) if (port->type == pt) return port; return NULL; diff --git a/net/hsr-prp/hsr_prp_main.h b/net/hsr-prp/hsr_prp_main.h index f74193465bf5..d11a9f0b696f 100644 --- a/net/hsr-prp/hsr_prp_main.h +++ b/net/hsr-prp/hsr_prp_main.h @@ -127,7 +127,7 @@ enum hsr_port_type { struct hsr_port { struct list_head port_list; struct net_device *dev; - struct hsr_priv *hsr; + struct hsr_priv *priv; enum hsr_port_type type; }; @@ -150,10 +150,10 @@ struct hsr_priv { #endif }; -#define hsr_for_each_port(hsr, port) \ - list_for_each_entry_rcu((port), &(hsr)->ports, port_list) +#define hsr_for_each_port(priv, port) \ + list_for_each_entry_rcu((port), &(priv)->ports, port_list) -struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt); +struct hsr_port *hsr_port_get_hsr(struct hsr_priv *priv, enum hsr_port_type pt); /* Caller must ensure skb is a valid HSR frame */ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb) diff --git a/net/hsr-prp/hsr_prp_slave.c b/net/hsr-prp/hsr_prp_slave.c index fad8fef783cc..96de8d15db00 100644 --- a/net/hsr-prp/hsr_prp_slave.c +++ b/net/hsr-prp/hsr_prp_slave.c @@ -29,7 +29,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) if (!port) goto finish_pass; - if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) { + if (hsr_addr_is_self(port->priv, eth_hdr(skb)->h_source)) { /* Directly kill frames sent by ourselves */ kfree_skb(skb); goto finish_consume; @@ -97,7 +97,7 @@ static int hsr_check_dev_ok(struct net_device *dev, } /* Setup device to be added to the HSR bridge. */ -static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, +static int hsr_portdev_setup(struct hsr_priv *priv, struct net_device *dev, struct hsr_port *port, struct netlink_ext_ack *extack) @@ -110,7 +110,7 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, if (res) return res; - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); hsr_dev = master->dev; res = netdev_upper_dev_link(dev, hsr_dev, extack); @@ -131,7 +131,7 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, return res; } -int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, +int hsr_add_port(struct hsr_priv *priv, struct net_device *dev, enum hsr_port_type type, struct netlink_ext_ack *extack) { struct hsr_port *port, *master; @@ -143,7 +143,7 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, return res; } - port = hsr_port_get_hsr(hsr, type); + port = hsr_port_get_hsr(priv, type); if (port) return -EBUSY; /* This port already exists */ @@ -151,22 +151,22 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, if (!port) return -ENOMEM; - port->hsr = hsr; + port->priv = priv; port->dev = dev; port->type = type; if (type != HSR_PT_MASTER) { - res = hsr_portdev_setup(hsr, dev, port, extack); + res = hsr_portdev_setup(priv, dev, port, extack); if (res) goto fail_dev_setup; } - list_add_tail_rcu(&port->port_list, &hsr->ports); + list_add_tail_rcu(&port->port_list, &priv->ports); synchronize_rcu(); - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); netdev_update_features(master->dev); - dev_set_mtu(master->dev, hsr_get_max_mtu(hsr)); + dev_set_mtu(master->dev, hsr_get_max_mtu(priv)); return 0; @@ -177,16 +177,16 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, void hsr_del_port(struct hsr_port *port) { - struct hsr_priv *hsr; + struct hsr_priv *priv; struct hsr_port *master; - hsr = port->hsr; - master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); + priv = port->priv; + master = hsr_port_get_hsr(priv, HSR_PT_MASTER); list_del_rcu(&port->port_list); if (port != master) { netdev_update_features(master->dev); - dev_set_mtu(master->dev, hsr_get_max_mtu(hsr)); + dev_set_mtu(master->dev, hsr_get_max_mtu(priv)); netdev_rx_handler_unregister(port->dev); dev_set_promiscuity(port->dev, -1); netdev_upper_dev_unlink(port->dev, master->dev); diff --git a/net/hsr-prp/hsr_prp_slave.h b/net/hsr-prp/hsr_prp_slave.h index c0360b111151..85f292d88845 100644 --- a/net/hsr-prp/hsr_prp_slave.h +++ b/net/hsr-prp/hsr_prp_slave.h @@ -12,7 +12,7 @@ #include #include "hsr_prp_main.h" -int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, +int hsr_add_port(struct hsr_priv *priv, struct net_device *dev, enum hsr_port_type pt, struct netlink_ext_ack *extack); void hsr_del_port(struct hsr_port *port); bool hsr_port_exists(const struct net_device *dev); From patchwork Wed May 6 16:30:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 219764 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.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 A62BDC4724C for ; Wed, 6 May 2020 16:30:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6943E20708 for ; Wed, 6 May 2020 16:30:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="U9k9VjMQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730153AbgEFQap (ORCPT ); Wed, 6 May 2020 12:30:45 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:58216 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730088AbgEFQam (ORCPT ); Wed, 6 May 2020 12:30:42 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 046GUbQr116952; Wed, 6 May 2020 11:30:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1588782637; bh=WUkEMGQJ1ceuXvJNGtjvE1feD30PJr30FrAJT23HCu0=; h=From:To:Subject:Date:In-Reply-To:References; b=U9k9VjMQAvw3ZmYjEQLwgd6OFu0yN4HKc55GxpcGNJmzuftBsPG0cYkIRiNrCPANK BHfBwoLoc+sDQJqkXnXdqO4EuG7khg+qA4ffV369XrLNepNgrzajkDe4s6B3NvynEs Et3FwRtKnbP6mlKozxG4H7PCt21qykTOcO+NKjRw= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 046GUbow021932 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 May 2020 11:30:37 -0500 Received: from DFLE115.ent.ti.com (10.64.6.36) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 6 May 2020 11:30:37 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 6 May 2020 11:30:36 -0500 Received: from uda0868495.fios-router.home (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 046GUXDj119719; Wed, 6 May 2020 11:30:36 -0500 From: Murali Karicheri To: , , , , , , Subject: [net-next RFC PATCH 06/13] net: hsr: some renaming to introduce PRP driver support Date: Wed, 6 May 2020 12:30:26 -0400 Message-ID: <20200506163033.3843-7-m-karicheri2@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506163033.3843-1-m-karicheri2@ti.com> References: <20200506163033.3843-1-m-karicheri2@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is a preparatory patch to introduce PRP device support. PRP device is very much similar to HSR in terms of device creation/removal, packet handling, etc. So this patch rename the functions that can be reused for PRP with a hsr_prp prefix. Common definitions and structure types are prefixed as well per similar reason. Similarly all constants common to HSR and PRP are prefixed with HSR_PRP. Common code that uses hsr_dev for function argument is changed to hsr_prp_dev or dev or ndev depending on the existing usage and context. Signed-off-by: Murali Karicheri --- net/hsr-prp/hsr_netlink.c | 75 ++++----- net/hsr-prp/hsr_netlink.h | 12 +- net/hsr-prp/hsr_prp_debugfs.c | 60 ++++---- net/hsr-prp/hsr_prp_device.c | 271 +++++++++++++++++---------------- net/hsr-prp/hsr_prp_device.h | 20 +-- net/hsr-prp/hsr_prp_forward.c | 122 ++++++++------- net/hsr-prp/hsr_prp_forward.h | 8 +- net/hsr-prp/hsr_prp_framereg.c | 209 +++++++++++++------------ net/hsr-prp/hsr_prp_framereg.h | 74 ++++----- net/hsr-prp/hsr_prp_main.c | 81 +++++----- net/hsr-prp/hsr_prp_main.h | 85 ++++++----- net/hsr-prp/hsr_prp_slave.c | 72 ++++----- net/hsr-prp/hsr_prp_slave.h | 30 ++-- 13 files changed, 576 insertions(+), 543 deletions(-) diff --git a/net/hsr-prp/hsr_netlink.c b/net/hsr-prp/hsr_netlink.c index 727b5dc9f31b..fbfa98aee13c 100644 --- a/net/hsr-prp/hsr_netlink.c +++ b/net/hsr-prp/hsr_netlink.c @@ -25,7 +25,7 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = { }; /* Here, it seems a netdevice has already been allocated for us, and the - * hsr_dev_setup routine has been executed. Nice! + * hsr_prp_dev_setup routine has been executed. Nice! */ static int hsr_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], @@ -80,21 +80,22 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev, } } - return hsr_dev_finalize(dev, link, multicast_spec, hsr_version, extack); + return hsr_prp_dev_finalize(dev, link, multicast_spec, hsr_version, + extack); } static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) { - struct hsr_priv *priv = netdev_priv(dev); - struct hsr_port *port; + struct hsr_prp_priv *priv = netdev_priv(dev); + struct hsr_prp_port *port; - port = hsr_prp_get_port(priv, HSR_PT_SLAVE_A); + port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A); if (port) { if (nla_put_u32(skb, IFLA_HSR_SLAVE1, port->dev->ifindex)) goto nla_put_failure; } - port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B); + port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); if (port) { if (nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex)) goto nla_put_failure; @@ -115,8 +116,8 @@ static struct rtnl_link_ops hsr_link_ops __read_mostly = { .kind = "hsr", .maxtype = IFLA_HSR_MAX, .policy = hsr_policy, - .priv_size = sizeof(struct hsr_priv), - .setup = hsr_dev_setup, + .priv_size = sizeof(struct hsr_prp_priv), + .setup = hsr_prp_dev_setup, .newlink = hsr_newlink, .fill_info = hsr_fill_info, }; @@ -142,12 +143,13 @@ static const struct genl_multicast_group hsr_mcgrps[] = { * over one of the slave interfaces. This would indicate an open network ring * (i.e. a link has failed somewhere). */ -void hsr_nl_ringerror(struct hsr_priv *priv, unsigned char addr[ETH_ALEN], - struct hsr_port *port) +void hsr_nl_ringerror(struct hsr_prp_priv *priv, + unsigned char addr[ETH_ALEN], + struct hsr_prp_port *port) { struct sk_buff *skb; void *msg_head; - struct hsr_port *master; + struct hsr_prp_port *master; int res; skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); @@ -177,7 +179,7 @@ void hsr_nl_ringerror(struct hsr_priv *priv, unsigned char addr[ETH_ALEN], fail: rcu_read_lock(); - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); netdev_warn(master->dev, "Could not send HSR ring error message\n"); rcu_read_unlock(); } @@ -185,11 +187,12 @@ void hsr_nl_ringerror(struct hsr_priv *priv, unsigned char addr[ETH_ALEN], /* This is called when we haven't heard from the node with MAC address addr for * some time (just before the node is removed from the node table/list). */ -void hsr_nl_nodedown(struct hsr_priv *priv, unsigned char addr[ETH_ALEN]) +void hsr_nl_nodedown(struct hsr_prp_priv *priv, + unsigned char addr[ETH_ALEN]) { struct sk_buff *skb; void *msg_head; - struct hsr_port *master; + struct hsr_prp_port *master; int res; skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); @@ -214,7 +217,7 @@ void hsr_nl_nodedown(struct hsr_priv *priv, unsigned char addr[ETH_ALEN]) fail: rcu_read_lock(); - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); netdev_warn(master->dev, "Could not send HSR node down\n"); rcu_read_unlock(); } @@ -236,9 +239,9 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) /* For sending */ struct sk_buff *skb_out; void *msg_head; - struct hsr_priv *priv; - struct hsr_port *port; - unsigned char hsr_node_addr_b[ETH_ALEN]; + struct hsr_prp_priv *priv; + struct hsr_prp_port *port; + unsigned char node_addr_b[ETH_ALEN]; int hsr_node_if1_age; u16 hsr_node_if1_seq; int hsr_node_if2_age; @@ -261,7 +264,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) nla_get_u32(info->attrs[HSR_A_IFINDEX])); if (!hsr_dev) goto rcu_unlock; - if (!is_hsr_master(hsr_dev)) + if (!is_hsr_prp_master(hsr_dev)) goto rcu_unlock; /* Send reply */ @@ -284,15 +287,15 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) goto nla_put_failure; priv = netdev_priv(hsr_dev); - res = hsr_get_node_data(priv, - (unsigned char *) - nla_data(info->attrs[HSR_A_NODE_ADDR]), - hsr_node_addr_b, - &addr_b_ifindex, - &hsr_node_if1_age, - &hsr_node_if1_seq, - &hsr_node_if2_age, - &hsr_node_if2_seq); + res = hsr_prp_get_node_data(priv, + (unsigned char *) + nla_data(info->attrs[HSR_A_NODE_ADDR]), + node_addr_b, + &addr_b_ifindex, + &hsr_node_if1_age, + &hsr_node_if1_seq, + &hsr_node_if2_age, + &hsr_node_if2_seq); if (res < 0) goto nla_put_failure; @@ -303,7 +306,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) if (addr_b_ifindex > -1) { res = nla_put(skb_out, HSR_A_NODE_ADDR_B, ETH_ALEN, - hsr_node_addr_b); + node_addr_b); if (res < 0) goto nla_put_failure; @@ -319,7 +322,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq); if (res < 0) goto nla_put_failure; - port = hsr_prp_get_port(priv, HSR_PT_SLAVE_A); + port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A); if (port) res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX, port->dev->ifindex); @@ -332,7 +335,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq); if (res < 0) goto nla_put_failure; - port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B); + port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); if (port) res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX, port->dev->ifindex); @@ -367,8 +370,8 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) { unsigned char addr[ETH_ALEN]; struct net_device *hsr_dev; + struct hsr_prp_priv *priv; struct sk_buff *skb_out; - struct hsr_priv *priv; bool restart = false; struct nlattr *na; void *pos = NULL; @@ -387,7 +390,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) nla_get_u32(info->attrs[HSR_A_IFINDEX])); if (!hsr_dev) goto rcu_unlock; - if (!is_hsr_master(hsr_dev)) + if (!is_hsr_prp_master(hsr_dev)) goto rcu_unlock; restart: @@ -415,7 +418,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) priv = netdev_priv(hsr_dev); if (!pos) - pos = hsr_get_next_node(priv, NULL, addr); + pos = hsr_prp_get_next_node(priv, NULL, addr); while (pos) { res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr); if (res < 0) { @@ -428,7 +431,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) } goto nla_put_failure; } - pos = hsr_get_next_node(priv, pos, addr); + pos = hsr_prp_get_next_node(priv, pos, addr); } rcu_read_unlock(); @@ -495,7 +498,7 @@ int __init hsr_netlink_init(void) if (rc) goto fail_genl_register_family; - hsr_debugfs_create_root(); + hsr_prp_debugfs_create_root(); return 0; fail_genl_register_family: diff --git a/net/hsr-prp/hsr_netlink.h b/net/hsr-prp/hsr_netlink.h index 1121bb192a18..ae7a1c0de80d 100644 --- a/net/hsr-prp/hsr_netlink.h +++ b/net/hsr-prp/hsr_netlink.h @@ -12,15 +12,17 @@ #include #include -struct hsr_priv; -struct hsr_port; +struct hsr_prp_priv; +struct hsr_prp_port; int __init hsr_netlink_init(void); void __exit hsr_netlink_exit(void); -void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN], - struct hsr_port *port); -void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN]); +void hsr_nl_ringerror(struct hsr_prp_priv *priv, + unsigned char addr[ETH_ALEN], + struct hsr_prp_port *port); +void hsr_nl_nodedown(struct hsr_prp_priv *priv, + unsigned char addr[ETH_ALEN]); void hsr_nl_framedrop(int dropcount, int dev_idx); void hsr_nl_linkdown(int dev_idx); diff --git a/net/hsr-prp/hsr_prp_debugfs.c b/net/hsr-prp/hsr_prp_debugfs.c index d37b44082e92..7d8dd5ab3afd 100644 --- a/net/hsr-prp/hsr_prp_debugfs.c +++ b/net/hsr-prp/hsr_prp_debugfs.c @@ -20,7 +20,7 @@ #include "hsr_prp_main.h" #include "hsr_prp_framereg.h" -static struct dentry *hsr_debugfs_root_dir; +static struct dentry *hsr_prp_debugfs_root_dir; static void print_mac_address(struct seq_file *sfp, unsigned char *mac) { @@ -28,12 +28,12 @@ static void print_mac_address(struct seq_file *sfp, unsigned char *mac) mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } -/* hsr_node_table_show - Formats and prints node_table entries */ +/* hsr_prp_node_table_show - Formats and prints node_table entries */ static int -hsr_node_table_show(struct seq_file *sfp, void *data) +hsr_prp_node_table_show(struct seq_file *sfp, void *data) { - struct hsr_priv *priv = (struct hsr_priv *)sfp->private; - struct hsr_node *node; + struct hsr_prp_priv *priv = (struct hsr_prp_priv *)sfp->private; + struct hsr_prp_node *node; seq_puts(sfp, "Node Table entries\n"); seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], "); @@ -41,62 +41,62 @@ hsr_node_table_show(struct seq_file *sfp, void *data) rcu_read_lock(); list_for_each_entry_rcu(node, &priv->node_db, mac_list) { /* skip self node */ - if (hsr_addr_is_self(priv, node->macaddress_A)) + if (hsr_prp_addr_is_self(priv, node->macaddress_A)) continue; print_mac_address(sfp, &node->macaddress_A[0]); seq_puts(sfp, " "); print_mac_address(sfp, &node->macaddress_B[0]); - seq_printf(sfp, "0x%lx, ", node->time_in[HSR_PT_SLAVE_A]); - seq_printf(sfp, "0x%lx ", node->time_in[HSR_PT_SLAVE_B]); + seq_printf(sfp, "0x%lx, ", node->time_in[HSR_PRP_PT_SLAVE_A]); + seq_printf(sfp, "0x%lx ", node->time_in[HSR_PRP_PT_SLAVE_B]); seq_printf(sfp, "0x%x\n", node->addr_B_port); } rcu_read_unlock(); return 0; } -/* hsr_node_table_open - Open the node_table file +/* hsr_prp_node_table_open - Open the node_table file * * Description: * This routine opens a debugfs file node_table of specific hsr device */ static int -hsr_node_table_open(struct inode *inode, struct file *filp) +hsr_prp_node_table_open(struct inode *inode, struct file *filp) { - return single_open(filp, hsr_node_table_show, inode->i_private); + return single_open(filp, hsr_prp_node_table_show, inode->i_private); } -void hsr_debugfs_rename(struct net_device *dev) +void hsr_prp_debugfs_rename(struct net_device *dev) { - struct hsr_priv *priv = netdev_priv(dev); + struct hsr_prp_priv *priv = netdev_priv(dev); struct dentry *d; - d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root, - hsr_debugfs_root_dir, dev->name); + d = debugfs_rename(hsr_prp_debugfs_root_dir, priv->node_tbl_root, + hsr_prp_debugfs_root_dir, dev->name); if (IS_ERR(d)) netdev_warn(dev, "failed to rename\n"); else priv->node_tbl_root = d; } -static const struct file_operations hsr_fops = { - .open = hsr_node_table_open, +static const struct file_operations hsr_prp_fops = { + .open = hsr_prp_node_table_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; -/* hsr_debugfs_init - create hsr node_table file for dumping +/* hsr_prp_debugfs_init - create hsr node_table file for dumping * the node table * * Description: * When debugfs is configured this routine sets up the node_table file per * hsr device for dumping the node_table entries */ -void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev) +void hsr_prp_debugfs_init(struct hsr_prp_priv *priv, struct net_device *hsr_dev) { struct dentry *de = NULL; - de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir); + de = debugfs_create_dir(hsr_dev->name, hsr_prp_debugfs_root_dir); if (IS_ERR(de)) { pr_err("Cannot create hsr debugfs directory\n"); return; @@ -106,7 +106,7 @@ void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev) de = debugfs_create_file("node_table", S_IFREG | 0444, priv->node_tbl_root, priv, - &hsr_fops); + &hsr_prp_fops); if (IS_ERR(de)) { pr_err("Cannot create hsr node_table file\n"); debugfs_remove(priv->node_tbl_root); @@ -115,30 +115,30 @@ void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev) } } -/* hsr_debugfs_term - Tear down debugfs intrastructure +/* hsr_prp_debugfs_term - Tear down debugfs intrastructure * * Description: * When Debufs is configured this routine removes debugfs file system * elements that are specific to hsr */ void -hsr_debugfs_term(struct hsr_priv *priv) +hsr_prp_debugfs_term(struct hsr_prp_priv *priv) { debugfs_remove_recursive(priv->node_tbl_root); priv->node_tbl_root = NULL; } -void hsr_debugfs_create_root(void) +void hsr_prp_debugfs_create_root(void) { - hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL); - if (IS_ERR(hsr_debugfs_root_dir)) { - pr_err("Cannot create hsr debugfs root directory\n"); - hsr_debugfs_root_dir = NULL; + hsr_prp_debugfs_root_dir = debugfs_create_dir("hsr-prp", NULL); + if (IS_ERR(hsr_prp_debugfs_root_dir)) { + pr_err("Cannot create hsr-prp debugfs root directory\n"); + hsr_prp_debugfs_root_dir = NULL; } } -void hsr_debugfs_remove_root(void) +void hsr_prp_debugfs_remove_root(void) { /* debugfs_remove() internally checks NULL and ERROR */ - debugfs_remove(hsr_debugfs_root_dir); + debugfs_remove(hsr_prp_debugfs_root_dir); } diff --git a/net/hsr-prp/hsr_prp_device.c b/net/hsr-prp/hsr_prp_device.c index d8bc9a48b6f2..43269c204445 100644 --- a/net/hsr-prp/hsr_prp_device.c +++ b/net/hsr-prp/hsr_prp_device.c @@ -29,7 +29,7 @@ static bool is_slave_up(struct net_device *dev) return dev && is_admin_up(dev) && netif_oper_up(dev); } -static void __hsr_set_operstate(struct net_device *dev, int transition) +static void __hsr_prp_set_operstate(struct net_device *dev, int transition) { write_lock_bh(&dev_base_lock); if (dev->operstate != transition) { @@ -41,27 +41,27 @@ static void __hsr_set_operstate(struct net_device *dev, int transition) } } -static void hsr_set_operstate(struct hsr_port *master, bool has_carrier) +static void hsr_prp_set_operstate(struct hsr_prp_port *master, bool has_carrier) { if (!is_admin_up(master->dev)) { - __hsr_set_operstate(master->dev, IF_OPER_DOWN); + __hsr_prp_set_operstate(master->dev, IF_OPER_DOWN); return; } if (has_carrier) - __hsr_set_operstate(master->dev, IF_OPER_UP); + __hsr_prp_set_operstate(master->dev, IF_OPER_UP); else - __hsr_set_operstate(master->dev, IF_OPER_LOWERLAYERDOWN); + __hsr_prp_set_operstate(master->dev, IF_OPER_LOWERLAYERDOWN); } -static bool hsr_check_carrier(struct hsr_port *master) +static bool hsr_prp_check_carrier(struct hsr_prp_port *master) { - struct hsr_port *port; + struct hsr_prp_port *port; ASSERT_RTNL(); - hsr_for_each_port(master->priv, port) { - if (port->type != HSR_PT_MASTER && is_slave_up(port->dev)) { + hsr_prp_for_each_port(master->priv, port) { + if (port->type != HSR_PRP_PT_MASTER && is_slave_up(port->dev)) { netif_carrier_on(master->dev); return true; } @@ -72,65 +72,66 @@ static bool hsr_check_carrier(struct hsr_port *master) return false; } -static void hsr_check_announce(struct net_device *hsr_dev, - unsigned char old_operstate) +static void hsr_prp_check_announce(struct net_device *dev, + unsigned char old_operstate) { - struct hsr_priv *priv; + struct hsr_prp_priv *priv; - priv = netdev_priv(hsr_dev); + priv = netdev_priv(dev); - if (hsr_dev->operstate == IF_OPER_UP && old_operstate != IF_OPER_UP) { + if (dev->operstate == IF_OPER_UP && old_operstate != IF_OPER_UP) { /* Went up */ priv->announce_count = 0; mod_timer(&priv->announce_timer, - jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL)); + jiffies + + msecs_to_jiffies(HSR_PRP_ANNOUNCE_INTERVAL)); } - if (hsr_dev->operstate != IF_OPER_UP && old_operstate == IF_OPER_UP) + if (dev->operstate != IF_OPER_UP && old_operstate == IF_OPER_UP) /* Went down */ del_timer(&priv->announce_timer); } -void hsr_check_carrier_and_operstate(struct hsr_priv *priv) +void hsr_prp_check_carrier_and_operstate(struct hsr_prp_priv *priv) { - struct hsr_port *master; + struct hsr_prp_port *master; unsigned char old_operstate; bool has_carrier; - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); /* netif_stacked_transfer_operstate() cannot be used here since * it doesn't set IF_OPER_LOWERLAYERDOWN (?) */ old_operstate = master->dev->operstate; - has_carrier = hsr_check_carrier(master); - hsr_set_operstate(master, has_carrier); - hsr_check_announce(master->dev, old_operstate); + has_carrier = hsr_prp_check_carrier(master); + hsr_prp_set_operstate(master, has_carrier); + hsr_prp_check_announce(master->dev, old_operstate); } -int hsr_get_max_mtu(struct hsr_priv *priv) +int hsr_prp_get_max_mtu(struct hsr_prp_priv *priv) { unsigned int mtu_max; - struct hsr_port *port; + struct hsr_prp_port *port; mtu_max = ETH_DATA_LEN; - hsr_for_each_port(priv, port) - if (port->type != HSR_PT_MASTER) + hsr_prp_for_each_port(priv, port) + if (port->type != HSR_PRP_PT_MASTER) mtu_max = min(port->dev->mtu, mtu_max); - if (mtu_max < HSR_HLEN) + if (mtu_max < HSR_PRP_HLEN) return 0; - return mtu_max - HSR_HLEN; + return mtu_max - HSR_PRP_HLEN; } -static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu) +static int hsr_prp_dev_change_mtu(struct net_device *dev, int new_mtu) { - struct hsr_priv *priv; + struct hsr_prp_priv *priv; priv = netdev_priv(dev); - if (new_mtu > hsr_get_max_mtu(priv)) { - netdev_info(dev, "A HSR master's MTU cannot be greater than the smallest MTU of its slaves minus the HSR Tag length (%d octets).\n", - HSR_HLEN); + if (new_mtu > hsr_prp_get_max_mtu(priv)) { + netdev_info(dev, "A HSR/PRP master's MTU cannot be greater than the smallest MTU of its slaves minus the HSR Tag length (%d octets).\n", + HSR_PRP_HLEN); return -EINVAL; } @@ -139,30 +140,30 @@ static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu) return 0; } -static int hsr_dev_open(struct net_device *dev) +static int hsr_prp_dev_open(struct net_device *dev) { - struct hsr_priv *priv; - struct hsr_port *port; + struct hsr_prp_priv *priv; + struct hsr_prp_port *port; char designation; priv = netdev_priv(dev); designation = '\0'; - hsr_for_each_port(priv, port) { - if (port->type == HSR_PT_MASTER) + hsr_prp_for_each_port(priv, port) { + if (port->type == HSR_PRP_PT_MASTER) continue; switch (port->type) { - case HSR_PT_SLAVE_A: + case HSR_PRP_PT_SLAVE_A: designation = 'A'; break; - case HSR_PT_SLAVE_B: + case HSR_PRP_PT_SLAVE_B: designation = 'B'; break; default: designation = '?'; } if (!is_slave_up(port->dev)) - netdev_warn(dev, "Slave %c (%s) is not up; please bring it up to get a fully working HSR network\n", + netdev_warn(dev, "Slave %c (%s) is not up; please bring it up to get a fully working HSR/PRP network\n", designation, port->dev->name); } @@ -172,17 +173,17 @@ static int hsr_dev_open(struct net_device *dev) return 0; } -static int hsr_dev_close(struct net_device *dev) +static int hsr_prp_dev_close(struct net_device *dev) { /* Nothing to do here. */ return 0; } -static netdev_features_t hsr_features_recompute(struct hsr_priv *priv, - netdev_features_t features) +static netdev_features_t hsr_prp_features_recompute(struct hsr_prp_priv *priv, + netdev_features_t features) { netdev_features_t mask; - struct hsr_port *port; + struct hsr_prp_port *port; mask = features; @@ -194,7 +195,7 @@ static netdev_features_t hsr_features_recompute(struct hsr_priv *priv, * may become enabled. */ features &= ~NETIF_F_ONE_FOR_ALL; - hsr_for_each_port(priv, port) + hsr_prp_for_each_port(priv, port) features = netdev_increment_features(features, port->dev->features, mask); @@ -202,23 +203,23 @@ static netdev_features_t hsr_features_recompute(struct hsr_priv *priv, return features; } -static netdev_features_t hsr_fix_features(struct net_device *dev, - netdev_features_t features) +static netdev_features_t hsr_prp_fix_features(struct net_device *dev, + netdev_features_t features) { - struct hsr_priv *priv = netdev_priv(dev); + struct hsr_prp_priv *priv = netdev_priv(dev); - return hsr_features_recompute(priv, features); + return hsr_prp_features_recompute(priv, features); } -static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev) +static int hsr_prp_dev_xmit(struct sk_buff *skb, struct net_device *dev) { - struct hsr_priv *priv = netdev_priv(dev); - struct hsr_port *master; + struct hsr_prp_priv *priv = netdev_priv(dev); + struct hsr_prp_port *master; - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); if (master) { skb->dev = master->dev; - hsr_forward_skb(skb, master); + hsr_prp_forward_skb(skb, master); } else { atomic_long_inc(&dev->tx_dropped); dev_kfree_skb_any(skb); @@ -226,26 +227,26 @@ static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } -static const struct header_ops hsr_header_ops = { +static const struct header_ops hsr_prp_header_ops = { .create = eth_header, .parse = eth_header_parse, }; -static void send_hsr_supervision_frame(struct hsr_port *master, - u8 type, u8 hsr_ver) +static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master, + u8 type, u8 proto_ver) { struct sk_buff *skb; int hlen, tlen; struct hsr_tag *hsr_tag; - struct hsr_sup_tag *hsr_stag; - struct hsr_sup_payload *hsr_sp; + struct hsr_prp_sup_tag *hsr_stag; + struct hsr_prp_sup_payload *hsr_sp; unsigned long irqflags; hlen = LL_RESERVED_SPACE(master->dev); tlen = master->dev->needed_tailroom; skb = dev_alloc_skb(sizeof(struct hsr_tag) + - sizeof(struct hsr_sup_tag) + - sizeof(struct hsr_sup_payload) + hlen + tlen); + sizeof(struct hsr_prp_sup_tag) + + sizeof(struct hsr_prp_sup_payload) + hlen + tlen); if (!skb) return; @@ -253,10 +254,10 @@ static void send_hsr_supervision_frame(struct hsr_port *master, skb_reserve(skb, hlen); skb->dev = master->dev; - skb->protocol = htons(hsr_ver ? ETH_P_HSR : ETH_P_PRP); + skb->protocol = htons(proto_ver ? ETH_P_HSR : ETH_P_PRP); skb->priority = TC_PRIO_CONTROL; - if (dev_hard_header(skb, skb->dev, (hsr_ver ? ETH_P_HSR : ETH_P_PRP), + if (dev_hard_header(skb, skb->dev, (proto_ver ? ETH_P_HSR : ETH_P_PRP), master->priv->sup_multicast_addr, skb->dev->dev_addr, skb->len) <= 0) goto out; @@ -264,19 +265,19 @@ static void send_hsr_supervision_frame(struct hsr_port *master, skb_reset_network_header(skb); skb_reset_transport_header(skb); - if (hsr_ver > 0) { + if (proto_ver > 0) { hsr_tag = skb_put(skb, sizeof(struct hsr_tag)); hsr_tag->encap_proto = htons(ETH_P_PRP); set_hsr_tag_LSDU_size(hsr_tag, HSR_V1_SUP_LSDUSIZE); } - hsr_stag = skb_put(skb, sizeof(struct hsr_sup_tag)); - set_hsr_stag_path(hsr_stag, (hsr_ver ? 0x0 : 0xf)); - set_hsr_stag_HSR_ver(hsr_stag, hsr_ver); + hsr_stag = skb_put(skb, sizeof(struct hsr_prp_sup_tag)); + set_hsr_stag_path(hsr_stag, (proto_ver ? 0x0 : 0xf)); + set_hsr_stag_HSR_ver(hsr_stag, proto_ver); /* From HSRv1 on we have separate supervision sequence numbers. */ spin_lock_irqsave(&master->priv->seqnr_lock, irqflags); - if (hsr_ver > 0) { + if (proto_ver > 0) { hsr_stag->sequence_nr = htons(master->priv->sup_sequence_nr); hsr_tag->sequence_nr = htons(master->priv->sequence_nr); master->priv->sup_sequence_nr++; @@ -289,17 +290,17 @@ static void send_hsr_supervision_frame(struct hsr_port *master, hsr_stag->HSR_TLV_type = type; /* TODO: Why 12 in HSRv0? */ - hsr_stag->HSR_TLV_length = - hsr_ver ? sizeof(struct hsr_sup_payload) : 12; + hsr_stag->HSR_TLV_length = proto_ver ? + sizeof(struct hsr_prp_sup_payload) : 12; /* Payload: MacAddressA */ - hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload)); + hsr_sp = skb_put(skb, sizeof(struct hsr_prp_sup_payload)); ether_addr_copy(hsr_sp->macaddress_A, master->dev->dev_addr); - if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN)) + if (skb_put_padto(skb, ETH_ZLEN + HSR_PRP_HLEN)) return; - hsr_forward_skb(skb, master); + hsr_prp_forward_skb(skb, master); return; out: @@ -309,28 +310,28 @@ static void send_hsr_supervision_frame(struct hsr_port *master, /* Announce (supervision frame) timer function */ -static void hsr_announce(struct timer_list *t) +static void hsr_prp_announce(struct timer_list *t) { - struct hsr_priv *priv; - struct hsr_port *master; + struct hsr_prp_priv *priv; + struct hsr_prp_port *master; unsigned long interval; priv = from_timer(priv, t, announce_timer); rcu_read_lock(); - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); if (priv->announce_count < 3 && priv->prot_version == 0) { - send_hsr_supervision_frame(master, HSR_TLV_ANNOUNCE, - priv->prot_version); + send_hsr_prp_supervision_frame(master, HSR_TLV_ANNOUNCE, + priv->prot_version); priv->announce_count++; - interval = msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL); + interval = msecs_to_jiffies(HSR_PRP_ANNOUNCE_INTERVAL); } else { - send_hsr_supervision_frame(master, HSR_TLV_LIFE_CHECK, - priv->prot_version); + send_hsr_prp_supervision_frame(master, HSR_TLV_LIFE_CHECK, + priv->prot_version); - interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL); + interval = msecs_to_jiffies(HSR_PRP_LIFE_CHECK_INTERVAL); } if (is_admin_up(master->dev)) @@ -339,62 +340,62 @@ static void hsr_announce(struct timer_list *t) rcu_read_unlock(); } -static void hsr_del_ports(struct hsr_priv *priv) +static void hsr_prp_del_ports(struct hsr_prp_priv *priv) { - struct hsr_port *port; + struct hsr_prp_port *port; - port = hsr_prp_get_port(priv, HSR_PT_SLAVE_A); + port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A); if (port) - hsr_del_port(port); + hsr_prp_del_port(port); - port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B); + port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); if (port) - hsr_del_port(port); + hsr_prp_del_port(port); - port = hsr_prp_get_port(priv, HSR_PT_MASTER); + port = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); if (port) - hsr_del_port(port); + hsr_prp_del_port(port); } /* This has to be called after all the readers are gone. * Otherwise we would have to check the return value of * hsr_prp_get_port(). */ -static void hsr_dev_destroy(struct net_device *hsr_dev) +static void hsr_prp_dev_destroy(struct net_device *dev) { - struct hsr_priv *priv = netdev_priv(hsr_dev); + struct hsr_prp_priv *priv = netdev_priv(dev); - hsr_debugfs_term(priv); - hsr_del_ports(priv); + hsr_prp_debugfs_term(priv); + hsr_prp_del_ports(priv); del_timer_sync(&priv->prune_timer); del_timer_sync(&priv->announce_timer); - hsr_del_self_node(priv); - hsr_del_nodes(&priv->node_db); + hsr_prp_del_self_node(priv); + hsr_prp_del_nodes(&priv->node_db); } -static const struct net_device_ops hsr_device_ops = { - .ndo_change_mtu = hsr_dev_change_mtu, - .ndo_open = hsr_dev_open, - .ndo_stop = hsr_dev_close, - .ndo_start_xmit = hsr_dev_xmit, - .ndo_fix_features = hsr_fix_features, - .ndo_uninit = hsr_dev_destroy, +static const struct net_device_ops hsr_prp_device_ops = { + .ndo_change_mtu = hsr_prp_dev_change_mtu, + .ndo_open = hsr_prp_dev_open, + .ndo_stop = hsr_prp_dev_close, + .ndo_start_xmit = hsr_prp_dev_xmit, + .ndo_fix_features = hsr_prp_fix_features, + .ndo_uninit = hsr_prp_dev_destroy, }; static struct device_type hsr_type = { .name = "hsr", }; -void hsr_dev_setup(struct net_device *dev) +void hsr_prp_dev_setup(struct net_device *dev) { eth_hw_addr_random(dev); ether_setup(dev); dev->min_mtu = 0; - dev->header_ops = &hsr_header_ops; - dev->netdev_ops = &hsr_device_ops; + dev->header_ops = &hsr_prp_header_ops; + dev->netdev_ops = &hsr_prp_device_ops; SET_NETDEV_DEVTYPE(dev, &hsr_type); dev->priv_flags |= IFF_NO_QUEUE; @@ -420,9 +421,9 @@ void hsr_dev_setup(struct net_device *dev) /* Return true if dev is a HSR master; return false otherwise. */ -inline bool is_hsr_master(struct net_device *dev) +inline bool is_hsr_prp_master(struct net_device *dev) { - return (dev->netdev_ops->ndo_start_xmit == hsr_dev_xmit); + return (dev->netdev_ops->ndo_start_xmit == hsr_prp_dev_xmit); } /* Default multicast address for HSR Supervision frames */ @@ -430,34 +431,35 @@ static const unsigned char def_multicast_addr[ETH_ALEN] __aligned(2) = { 0x01, 0x15, 0x4e, 0x00, 0x01, 0x00 }; -int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], - unsigned char multicast_spec, u8 protocol_version, - struct netlink_ext_ack *extack) +int hsr_prp_dev_finalize(struct net_device *hsr_prp_dev, + struct net_device *slave[2], + unsigned char multicast_spec, u8 protocol_version, + struct netlink_ext_ack *extack) { - struct hsr_priv *priv; + struct hsr_prp_priv *priv; int res; - priv = netdev_priv(hsr_dev); + priv = netdev_priv(hsr_prp_dev); INIT_LIST_HEAD(&priv->ports); INIT_LIST_HEAD(&priv->node_db); INIT_LIST_HEAD(&priv->self_node_db); spin_lock_init(&priv->list_lock); - ether_addr_copy(hsr_dev->dev_addr, slave[0]->dev_addr); + ether_addr_copy(hsr_prp_dev->dev_addr, slave[0]->dev_addr); /* Make sure we recognize frames from ourselves in hsr_rcv() */ - res = hsr_create_self_node(priv, hsr_dev->dev_addr, - slave[1]->dev_addr); + res = hsr_prp_create_self_node(priv, hsr_prp_dev->dev_addr, + slave[1]->dev_addr); if (res < 0) return res; spin_lock_init(&priv->seqnr_lock); /* Overflow soon to find bugs easier: */ - priv->sequence_nr = HSR_SEQNR_START; - priv->sup_sequence_nr = HSR_SUP_SEQNR_START; + priv->sequence_nr = HSR_PRP_SEQNR_START; + priv->sup_sequence_nr = HSR_PRP_SUP_SEQNR_START; - timer_setup(&priv->announce_timer, hsr_announce, 0); - timer_setup(&priv->prune_timer, hsr_prune_nodes, 0); + timer_setup(&priv->announce_timer, hsr_prp_announce, 0); + timer_setup(&priv->prune_timer, hsr_prp_prune_nodes, 0); ether_addr_copy(priv->sup_multicast_addr, def_multicast_addr); priv->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec; @@ -466,44 +468,45 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], /* FIXME: should I modify the value of these? * - * - hsr_dev->flags - i.e. + * - hsr_ptp_dev->flags - i.e. * IFF_MASTER/SLAVE? - * - hsr_dev->priv_flags - i.e. + * - hsr_prp_dev->priv_flags - i.e. * IFF_EBRIDGE? * IFF_TX_SKB_SHARING? * IFF_HSR_MASTER/SLAVE? */ /* Make sure the 1st call to netif_carrier_on() gets through */ - netif_carrier_off(hsr_dev); + netif_carrier_off(hsr_prp_dev); - res = hsr_add_port(priv, hsr_dev, HSR_PT_MASTER, extack); + res = hsr_prp_add_port(priv, hsr_prp_dev, HSR_PRP_PT_MASTER, extack); if (res) goto err_add_master; - res = register_netdevice(hsr_dev); + res = register_netdevice(hsr_prp_dev); if (res) goto err_unregister; - res = hsr_add_port(priv, slave[0], HSR_PT_SLAVE_A, extack); + res = hsr_prp_add_port(priv, slave[0], HSR_PRP_PT_SLAVE_A, extack); if (res) goto err_add_slaves; - res = hsr_add_port(priv, slave[1], HSR_PT_SLAVE_B, extack); + res = hsr_prp_add_port(priv, slave[1], HSR_PRP_PT_SLAVE_B, extack); if (res) goto err_add_slaves; - hsr_debugfs_init(priv, hsr_dev); - mod_timer(&priv->prune_timer, jiffies + msecs_to_jiffies(PRUNE_PERIOD)); + hsr_prp_debugfs_init(priv, hsr_prp_dev); + mod_timer(&priv->prune_timer, + jiffies + msecs_to_jiffies(PRUNE_PERIOD)); return 0; err_add_slaves: - unregister_netdevice(hsr_dev); + unregister_netdevice(hsr_prp_dev); err_unregister: - hsr_del_ports(priv); + hsr_prp_del_ports(priv); err_add_master: - hsr_del_self_node(priv); + hsr_prp_del_self_node(priv); return res; } diff --git a/net/hsr-prp/hsr_prp_device.h b/net/hsr-prp/hsr_prp_device.h index 91642845cdd2..4f734a36b2d6 100644 --- a/net/hsr-prp/hsr_prp_device.h +++ b/net/hsr-prp/hsr_prp_device.h @@ -5,18 +5,18 @@ * 2011-2014 Arvid Brodin, arvid.brodin@alten.se */ -#ifndef __HSR_DEVICE_H -#define __HSR_DEVICE_H +#ifndef __HSR_PRP_DEVICE_H +#define __HSR_PRP_DEVICE_H #include #include "hsr_prp_main.h" -void hsr_dev_setup(struct net_device *dev); -int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], - unsigned char multicast_spec, u8 protocol_version, - struct netlink_ext_ack *extack); -void hsr_check_carrier_and_operstate(struct hsr_priv *priv); -bool is_hsr_master(struct net_device *dev); -int hsr_get_max_mtu(struct hsr_priv *priv); +void hsr_prp_dev_setup(struct net_device *dev); +int hsr_prp_dev_finalize(struct net_device *dev, struct net_device *slave[2], + unsigned char multicast_spec, u8 protocol_version, + struct netlink_ext_ack *extack); +void hsr_prp_check_carrier_and_operstate(struct hsr_prp_priv *priv); +bool is_hsr_prp_master(struct net_device *dev); +int hsr_prp_get_max_mtu(struct hsr_prp_priv *priv); -#endif /* __HSR_DEVICE_H */ +#endif /* __HSR_PRP_DEVICE_H */ diff --git a/net/hsr-prp/hsr_prp_forward.c b/net/hsr-prp/hsr_prp_forward.c index 2b6abb09fe4b..59b33d711ea6 100644 --- a/net/hsr-prp/hsr_prp_forward.c +++ b/net/hsr-prp/hsr_prp_forward.c @@ -13,13 +13,13 @@ #include "hsr_prp_main.h" #include "hsr_prp_framereg.h" -struct hsr_node; +struct hsr_prp_node; -struct hsr_frame_info { +struct hsr_prp_frame_info { struct sk_buff *skb_std; struct sk_buff *skb_hsr; - struct hsr_port *port_rcv; - struct hsr_node *node_src; + struct hsr_prp_port *port_rcv; + struct hsr_prp_node *node_src; u16 sequence_nr; bool is_supervision; bool is_vlan; @@ -42,10 +42,10 @@ struct hsr_frame_info { * 3) Allow different MAC addresses for the two slave interfaces, using the * MacAddressA field. */ -static bool is_supervision_frame(struct hsr_priv *priv, struct sk_buff *skb) +static bool is_supervision_frame(struct hsr_prp_priv *priv, struct sk_buff *skb) { struct ethhdr *eth_hdr; - struct hsr_sup_tag *hsr_sup_tag; + struct hsr_prp_sup_tag *hsr_sup_tag; struct hsrv1_ethhdr_sp *hsr_V1_hdr; WARN_ON_ONCE(!skb_mac_header_was_set(skb)); @@ -77,29 +77,30 @@ static bool is_supervision_frame(struct hsr_priv *priv, struct sk_buff *skb) hsr_sup_tag->HSR_TLV_type != HSR_TLV_LIFE_CHECK) return false; if (hsr_sup_tag->HSR_TLV_length != 12 && - hsr_sup_tag->HSR_TLV_length != sizeof(struct hsr_sup_payload)) + hsr_sup_tag->HSR_TLV_length != sizeof(struct hsr_prp_sup_payload)) return false; return true; } static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, - struct hsr_frame_info *frame) + struct hsr_prp_frame_info *frame) { struct sk_buff *skb; int copylen; unsigned char *dst, *src; - skb_pull(skb_in, HSR_HLEN); - skb = __pskb_copy(skb_in, skb_headroom(skb_in) - HSR_HLEN, GFP_ATOMIC); - skb_push(skb_in, HSR_HLEN); + skb_pull(skb_in, HSR_PRP_HLEN); + skb = __pskb_copy(skb_in, + skb_headroom(skb_in) - HSR_PRP_HLEN, GFP_ATOMIC); + skb_push(skb_in, HSR_PRP_HLEN); if (!skb) return NULL; skb_reset_mac_header(skb); if (skb->ip_summed == CHECKSUM_PARTIAL) - skb->csum_start -= HSR_HLEN; + skb->csum_start -= HSR_PRP_HLEN; copylen = 2 * ETH_ALEN; if (frame->is_vlan) @@ -112,22 +113,22 @@ static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, return skb; } -static struct sk_buff *frame_get_stripped_skb(struct hsr_frame_info *frame, - struct hsr_port *port) +static struct sk_buff *frame_get_stripped_skb(struct hsr_prp_frame_info *frame, + struct hsr_prp_port *port) { if (!frame->skb_std) frame->skb_std = create_stripped_skb(frame->skb_hsr, frame); return skb_clone(frame->skb_std, GFP_ATOMIC); } -static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame, - struct hsr_port *port, u8 proto_version) +static void hsr_fill_tag(struct sk_buff *skb, struct hsr_prp_frame_info *frame, + struct hsr_prp_port *port, u8 proto_version) { struct hsr_ethhdr *hsr_ethhdr; int lane_id; int lsdu_size; - if (port->type == HSR_PT_SLAVE_A) + if (port->type == HSR_PRP_PT_SLAVE_A) lane_id = 0; else lane_id = 1; @@ -147,28 +148,29 @@ static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame, } static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o, - struct hsr_frame_info *frame, - struct hsr_port *port) + struct hsr_prp_frame_info *frame, + struct hsr_prp_port *port) { int movelen; unsigned char *dst, *src; struct sk_buff *skb; /* Create the new skb with enough headroom to fit the HSR tag */ - skb = __pskb_copy(skb_o, skb_headroom(skb_o) + HSR_HLEN, GFP_ATOMIC); + skb = __pskb_copy(skb_o, + skb_headroom(skb_o) + HSR_PRP_HLEN, GFP_ATOMIC); if (!skb) return NULL; skb_reset_mac_header(skb); if (skb->ip_summed == CHECKSUM_PARTIAL) - skb->csum_start += HSR_HLEN; + skb->csum_start += HSR_PRP_HLEN; movelen = ETH_HLEN; if (frame->is_vlan) movelen += VLAN_HLEN; src = skb_mac_header(skb); - dst = skb_push(skb, HSR_HLEN); + dst = skb_push(skb, HSR_PRP_HLEN); memmove(dst, src, movelen); skb_reset_mac_header(skb); @@ -180,13 +182,14 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o, /* If the original frame was an HSR tagged frame, just clone it to be sent * unchanged. Otherwise, create a private frame especially tagged for 'port'. */ -static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame, - struct hsr_port *port) +static struct sk_buff *frame_get_tagged_skb(struct hsr_prp_frame_info *frame, + struct hsr_prp_port *port) { if (frame->skb_hsr) return skb_clone(frame->skb_hsr, GFP_ATOMIC); - if (port->type != HSR_PT_SLAVE_A && port->type != HSR_PT_SLAVE_B) { + if (port->type != HSR_PRP_PT_SLAVE_A && + port->type != HSR_PRP_PT_SLAVE_B) { WARN_ONCE(1, "HSR: Bug: trying to create a tagged frame for a non-ring port"); return NULL; } @@ -194,14 +197,14 @@ static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame, return create_tagged_skb(frame->skb_std, frame, port); } -static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, - struct hsr_node *node_src) +static void hsr_prp_deliver_master(struct sk_buff *skb, struct net_device *dev, + struct hsr_prp_node *node_src) { bool was_multicast_frame; int res; was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST); - hsr_addr_subst_source(node_src, skb); + hsr_prp_addr_subst_source(node_src, skb); skb_pull(skb, ETH_HLEN); res = netif_rx(skb); if (res == NET_RX_DROP) { @@ -214,11 +217,11 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, } } -static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port, - struct hsr_frame_info *frame) +static int hsr_prp_xmit(struct sk_buff *skb, struct hsr_prp_port *port, + struct hsr_prp_frame_info *frame) { - if (frame->port_rcv->type == HSR_PT_MASTER) { - hsr_addr_subst_dest(frame->node_src, skb, port); + if (frame->port_rcv->type == HSR_PRP_PT_MASTER) { + hsr_prp_addr_subst_dest(frame->node_src, skb, port); /* Address substitution (IEC62439-3 pp 26, 50): replace mac * address of outgoing frame with that of the outgoing slave's. @@ -239,37 +242,38 @@ static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port, * tags if they're of the non-HSR type (but only after duplicate discard). The * master device always strips HSR tags. */ -static void hsr_forward_do(struct hsr_frame_info *frame) +static void hsr_prp_forward_do(struct hsr_prp_frame_info *frame) { - struct hsr_port *port; + struct hsr_prp_port *port; struct sk_buff *skb; - hsr_for_each_port(frame->port_rcv->priv, port) { + hsr_prp_for_each_port(frame->port_rcv->priv, port) { /* Don't send frame back the way it came */ if (port == frame->port_rcv) continue; /* Don't deliver locally unless we should */ - if (port->type == HSR_PT_MASTER && !frame->is_local_dest) + if (port->type == HSR_PRP_PT_MASTER && !frame->is_local_dest) continue; /* Deliver frames directly addressed to us to master only */ - if (port->type != HSR_PT_MASTER && frame->is_local_exclusive) + if (port->type != HSR_PRP_PT_MASTER && + frame->is_local_exclusive) continue; /* Don't send frame over port where it has been sent before */ - if (hsr_register_frame_out(port, frame->node_src, - frame->sequence_nr)) + if (hsr_prp_register_frame_out(port, frame->node_src, + frame->sequence_nr)) continue; - if (frame->is_supervision && port->type == HSR_PT_MASTER) { - hsr_handle_sup_frame(frame->skb_hsr, - frame->node_src, - frame->port_rcv); + if (frame->is_supervision && port->type == HSR_PRP_PT_MASTER) { + hsr_prp_handle_sup_frame(frame->skb_hsr, + frame->node_src, + frame->port_rcv); continue; } - if (port->type != HSR_PT_MASTER) + if (port->type != HSR_PRP_PT_MASTER) skb = frame_get_tagged_skb(frame, port); else skb = frame_get_stripped_skb(frame, port); @@ -279,17 +283,17 @@ static void hsr_forward_do(struct hsr_frame_info *frame) } skb->dev = port->dev; - if (port->type == HSR_PT_MASTER) - hsr_deliver_master(skb, port->dev, frame->node_src); + if (port->type == HSR_PRP_PT_MASTER) + hsr_prp_deliver_master(skb, port->dev, frame->node_src); else - hsr_xmit(skb, port, frame); + hsr_prp_xmit(skb, port, frame); } } -static void check_local_dest(struct hsr_priv *priv, struct sk_buff *skb, - struct hsr_frame_info *frame) +static void check_local_dest(struct hsr_prp_priv *priv, struct sk_buff *skb, + struct hsr_prp_frame_info *frame) { - if (hsr_addr_is_self(priv, eth_hdr(skb)->h_dest)) { + if (hsr_prp_addr_is_self(priv, eth_hdr(skb)->h_dest)) { frame->is_local_exclusive = true; skb->pkt_type = PACKET_HOST; } else { @@ -305,14 +309,14 @@ static void check_local_dest(struct hsr_priv *priv, struct sk_buff *skb, } } -static int hsr_fill_frame_info(struct hsr_frame_info *frame, - struct sk_buff *skb, struct hsr_port *port) +static int fill_frame_info(struct hsr_prp_frame_info *frame, + struct sk_buff *skb, struct hsr_prp_port *port) { struct ethhdr *ethhdr; unsigned long irqflags; frame->is_supervision = is_supervision_frame(port->priv, skb); - frame->node_src = hsr_get_node(port, skb, frame->is_supervision); + frame->node_src = hsr_prp_get_node(port, skb, frame->is_supervision); if (!frame->node_src) return -1; /* Unknown node and !is_supervision, or no mem */ @@ -345,9 +349,9 @@ static int hsr_fill_frame_info(struct hsr_frame_info *frame, } /* Must be called holding rcu read lock (because of the port parameter) */ -void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) +void hsr_prp_forward_skb(struct sk_buff *skb, struct hsr_prp_port *port) { - struct hsr_frame_info frame; + struct hsr_prp_frame_info frame; if (skb_mac_header(skb) != skb->data) { WARN_ONCE(1, "%s:%d: Malformed frame (port_src %s)\n", @@ -355,14 +359,14 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) goto out_drop; } - if (hsr_fill_frame_info(&frame, skb, port) < 0) + if (fill_frame_info(&frame, skb, port) < 0) goto out_drop; - hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); - hsr_forward_do(&frame); + hsr_prp_register_frame_in(frame.node_src, port, frame.sequence_nr); + hsr_prp_forward_do(&frame); /* Gets called for ingress frames as well as egress from master port. * So check and increment stats for master port only here. */ - if (port->type == HSR_PT_MASTER) { + if (port->type == HSR_PRP_PT_MASTER) { port->dev->stats.tx_packets++; port->dev->stats.tx_bytes += skb->len; } diff --git a/net/hsr-prp/hsr_prp_forward.h b/net/hsr-prp/hsr_prp_forward.h index cbc0704cc14a..75ac419ddaff 100644 --- a/net/hsr-prp/hsr_prp_forward.h +++ b/net/hsr-prp/hsr_prp_forward.h @@ -5,12 +5,12 @@ * 2011-2014 Arvid Brodin, arvid.brodin@alten.se */ -#ifndef __HSR_FORWARD_H -#define __HSR_FORWARD_H +#ifndef __HSR_PRP_FORWARD_H +#define __HSR_PRP_FORWARD_H #include #include "hsr_prp_main.h" -void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port); +void hsr_prp_forward_skb(struct sk_buff *skb, struct hsr_prp_port *port); -#endif /* __HSR_FORWARD_H */ +#endif /* __HSR_PRP_FORWARD_H */ diff --git a/net/hsr-prp/hsr_prp_framereg.c b/net/hsr-prp/hsr_prp_framereg.c index 102b0a85f440..d78d32d513ca 100644 --- a/net/hsr-prp/hsr_prp_framereg.c +++ b/net/hsr-prp/hsr_prp_framereg.c @@ -37,11 +37,11 @@ static bool seq_nr_after(u16 a, u16 b) #define seq_nr_before(a, b) seq_nr_after((b), (a)) #define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) -bool hsr_addr_is_self(struct hsr_priv *priv, unsigned char *addr) +bool hsr_prp_addr_is_self(struct hsr_prp_priv *priv, unsigned char *addr) { - struct hsr_node *node; + struct hsr_prp_node *node; - node = list_first_or_null_rcu(&priv->self_node_db, struct hsr_node, + node = list_first_or_null_rcu(&priv->self_node_db, struct hsr_prp_node, mac_list); if (!node) { WARN_ONCE(1, "HSR: No self node\n"); @@ -58,10 +58,11 @@ bool hsr_addr_is_self(struct hsr_priv *priv, unsigned char *addr) /* Search for mac entry. Caller must hold rcu read lock. */ -static struct hsr_node *find_node_by_addr_A(struct list_head *node_db, - const unsigned char addr[ETH_ALEN]) +static struct hsr_prp_node * +find_node_by_addr_A(struct list_head *node_db, + const unsigned char addr[ETH_ALEN]) { - struct hsr_node *node; + struct hsr_prp_node *node; list_for_each_entry_rcu(node, node_db, mac_list) { if (ether_addr_equal(node->macaddress_A, addr)) @@ -74,12 +75,12 @@ static struct hsr_node *find_node_by_addr_A(struct list_head *node_db, /* Helper for device init; the self_node_db is used in hsr_rcv() to recognize * frames from self that's been looped over the HSR ring. */ -int hsr_create_self_node(struct hsr_priv *priv, - unsigned char addr_a[ETH_ALEN], - unsigned char addr_b[ETH_ALEN]) +int hsr_prp_create_self_node(struct hsr_prp_priv *priv, + unsigned char addr_a[ETH_ALEN], + unsigned char addr_b[ETH_ALEN]) { struct list_head *self_node_db = &priv->self_node_db; - struct hsr_node *node, *oldnode; + struct hsr_prp_node *node, *oldnode; node = kmalloc(sizeof(*node), GFP_KERNEL); if (!node) @@ -90,7 +91,7 @@ int hsr_create_self_node(struct hsr_priv *priv, spin_lock_bh(&priv->list_lock); oldnode = list_first_or_null_rcu(self_node_db, - struct hsr_node, mac_list); + struct hsr_prp_node, mac_list); if (oldnode) { list_replace_rcu(&oldnode->mac_list, &node->mac_list); spin_unlock_bh(&priv->list_lock); @@ -103,13 +104,14 @@ int hsr_create_self_node(struct hsr_priv *priv, return 0; } -void hsr_del_self_node(struct hsr_priv *priv) +void hsr_prp_del_self_node(struct hsr_prp_priv *priv) { struct list_head *self_node_db = &priv->self_node_db; - struct hsr_node *node; + struct hsr_prp_node *node; spin_lock_bh(&priv->list_lock); - node = list_first_or_null_rcu(self_node_db, struct hsr_node, mac_list); + node = list_first_or_null_rcu(self_node_db, struct hsr_prp_node, + mac_list); if (node) { list_del_rcu(&node->mac_list); kfree_rcu(node, rcu_head); @@ -117,10 +119,10 @@ void hsr_del_self_node(struct hsr_priv *priv) spin_unlock_bh(&priv->list_lock); } -void hsr_del_nodes(struct list_head *node_db) +void hsr_prp_del_nodes(struct list_head *node_db) { - struct hsr_node *node; - struct hsr_node *tmp; + struct hsr_prp_node *node; + struct hsr_prp_node *tmp; list_for_each_entry_safe(node, tmp, node_db, mac_list) kfree(node); @@ -130,12 +132,12 @@ void hsr_del_nodes(struct list_head *node_db) * seq_out is used to initialize filtering of outgoing duplicate frames * originating from the newly added node. */ -static struct hsr_node *hsr_add_node(struct hsr_priv *priv, - struct list_head *node_db, - unsigned char addr[], - u16 seq_out) +static struct hsr_prp_node *hsr_prp_add_node(struct hsr_prp_priv *priv, + struct list_head *node_db, + unsigned char addr[], + u16 seq_out) { - struct hsr_node *new_node, *node; + struct hsr_prp_node *new_node, *node; unsigned long now; int i; @@ -149,9 +151,9 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *priv, * as initialization. (0 could trigger an spurious ring error warning). */ now = jiffies; - for (i = 0; i < HSR_PT_PORTS; i++) + for (i = 0; i < HSR_PRP_PT_PORTS; i++) new_node->time_in[i] = now; - for (i = 0; i < HSR_PT_PORTS; i++) + for (i = 0; i < HSR_PRP_PT_PORTS; i++) new_node->seq_out[i] = seq_out; spin_lock_bh(&priv->list_lock); @@ -173,12 +175,13 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *priv, /* Get the hsr_node from which 'skb' was sent. */ -struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, - bool is_sup) +struct hsr_prp_node *hsr_prp_get_node(struct hsr_prp_port *port, + struct sk_buff *skb, + bool is_sup) { struct list_head *node_db = &port->priv->node_db; - struct hsr_priv *priv = port->priv; - struct hsr_node *node; + struct hsr_prp_priv *priv = port->priv; + struct hsr_prp_node *node; struct ethhdr *ethhdr; u16 seq_out; @@ -206,24 +209,25 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, /* this is called also for frames from master port and * so warn only for non master ports */ - if (port->type != HSR_PT_MASTER) + if (port->type != HSR_PRP_PT_MASTER) WARN_ONCE(1, "%s: Non-HSR frame\n", __func__); - seq_out = HSR_SEQNR_START; + seq_out = HSR_PRP_SEQNR_START; } - return hsr_add_node(priv, node_db, ethhdr->h_source, seq_out); + return hsr_prp_add_node(priv, node_db, ethhdr->h_source, seq_out); } /* Use the Supervision frame's info about an eventual macaddress_B for merging * nodes that has previously had their macaddress_B registered as a separate * node. */ -void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, - struct hsr_port *port_rcv) +void hsr_prp_handle_sup_frame(struct sk_buff *skb, + struct hsr_prp_node *node_curr, + struct hsr_prp_port *port_rcv) { - struct hsr_priv *priv = port_rcv->priv; - struct hsr_sup_payload *hsr_sp; - struct hsr_node *node_real; + struct hsr_prp_priv *priv = port_rcv->priv; + struct hsr_prp_sup_payload *sp; + struct hsr_prp_node *node_real; struct list_head *node_db; struct ethhdr *ethhdr; int i; @@ -238,17 +242,17 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, skb_pull(skb, sizeof(struct hsr_tag)); /* And leave the HSR sup tag. */ - skb_pull(skb, sizeof(struct hsr_sup_tag)); + skb_pull(skb, sizeof(struct hsr_prp_sup_tag)); - hsr_sp = (struct hsr_sup_payload *)skb->data; + sp = (struct hsr_prp_sup_payload *)skb->data; /* Merge node_curr (registered on macaddress_B) into node_real */ node_db = &port_rcv->priv->node_db; - node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); + node_real = find_node_by_addr_A(node_db, sp->macaddress_A); if (!node_real) /* No frame received from AddrA of this node yet */ - node_real = hsr_add_node(priv, node_db, hsr_sp->macaddress_A, - HSR_SEQNR_START - 1); + node_real = hsr_prp_add_node(priv, node_db, sp->macaddress_A, + HSR_PRP_SEQNR_START - 1); if (!node_real) goto done; /* No mem */ if (node_real == node_curr) @@ -256,7 +260,7 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, goto done; ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); - for (i = 0; i < HSR_PT_PORTS; i++) { + for (i = 0; i < HSR_PRP_PT_PORTS; i++) { if (!node_curr->time_in_stale[i] && time_after(node_curr->time_in[i], node_real->time_in[i])) { node_real->time_in[i] = node_curr->time_in[i]; @@ -283,7 +287,7 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, * address with that node's "official" address (macaddress_A) so that upper * layers recognize where it came from. */ -void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) +void hsr_prp_addr_subst_source(struct hsr_prp_node *node, struct sk_buff *skb) { if (!skb_mac_header_was_set(skb)) { WARN_ONCE(1, "%s: Mac header not set\n", __func__); @@ -302,10 +306,10 @@ void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) * This is needed to keep the packets flowing through switches that learn on * which "side" the different interfaces are. */ -void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb, - struct hsr_port *port) +void hsr_prp_addr_subst_dest(struct hsr_prp_node *node_src, struct sk_buff *skb, + struct hsr_prp_port *port) { - struct hsr_node *node_dst; + struct hsr_prp_node *node_dst; if (!skb_mac_header_was_set(skb)) { WARN_ONCE(1, "%s: Mac header not set\n", __func__); @@ -328,8 +332,9 @@ void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb, ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); } -void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, - u16 sequence_nr) +void hsr_prp_register_frame_in(struct hsr_prp_node *node, + struct hsr_prp_port *port, + u16 sequence_nr) { /* Don't register incoming frames without a valid sequence number. This * ensures entries of restarted nodes gets pruned so that they can @@ -350,8 +355,9 @@ void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, * 0 otherwise, or * negative error code on error */ -int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, - u16 sequence_nr) +int hsr_prp_register_frame_out(struct hsr_prp_port *port, + struct hsr_prp_node *node, + u16 sequence_nr) { if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type])) return 1; @@ -360,35 +366,35 @@ int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, return 0; } -static struct hsr_port *get_late_port(struct hsr_priv *priv, - struct hsr_node *node) +static struct hsr_prp_port *get_late_port(struct hsr_prp_priv *priv, + struct hsr_prp_node *node) { - if (node->time_in_stale[HSR_PT_SLAVE_A]) - return hsr_prp_get_port(priv, HSR_PT_SLAVE_A); - if (node->time_in_stale[HSR_PT_SLAVE_B]) - return hsr_prp_get_port(priv, HSR_PT_SLAVE_B); - - if (time_after(node->time_in[HSR_PT_SLAVE_B], - node->time_in[HSR_PT_SLAVE_A] + - msecs_to_jiffies(MAX_SLAVE_DIFF))) - return hsr_prp_get_port(priv, HSR_PT_SLAVE_A); - if (time_after(node->time_in[HSR_PT_SLAVE_A], - node->time_in[HSR_PT_SLAVE_B] + - msecs_to_jiffies(MAX_SLAVE_DIFF))) - return hsr_prp_get_port(priv, HSR_PT_SLAVE_B); + if (node->time_in_stale[HSR_PRP_PT_SLAVE_A]) + return hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A); + if (node->time_in_stale[HSR_PRP_PT_SLAVE_B]) + return hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); + + if (time_after(node->time_in[HSR_PRP_PT_SLAVE_B], + node->time_in[HSR_PRP_PT_SLAVE_A] + + msecs_to_jiffies(HSR_PRP_MAX_SLAVE_DIFF))) + return hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A); + if (time_after(node->time_in[HSR_PRP_PT_SLAVE_A], + node->time_in[HSR_PRP_PT_SLAVE_B] + + msecs_to_jiffies(HSR_PRP_MAX_SLAVE_DIFF))) + return hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); return NULL; } /* Remove stale sequence_nr records. Called by timer every - * HSR_LIFE_CHECK_INTERVAL (two seconds or so). + * HSR_PRP_LIFE_CHECK_INTERVAL (two seconds or so). */ -void hsr_prune_nodes(struct timer_list *t) +void hsr_prp_prune_nodes(struct timer_list *t) { - struct hsr_priv *priv = from_timer(priv, t, prune_timer); - struct hsr_node *node; - struct hsr_node *tmp; - struct hsr_port *port; + struct hsr_prp_priv *priv = from_timer(priv, t, prune_timer); + struct hsr_prp_node *node; + struct hsr_prp_node *tmp; + struct hsr_prp_port *port; unsigned long timestamp; unsigned long time_a, time_b; @@ -399,32 +405,33 @@ void hsr_prune_nodes(struct timer_list *t) * the master port. Thus the master node will be repeatedly * pruned leading to packet loss. */ - if (hsr_addr_is_self(priv, node->macaddress_A)) + if (hsr_prp_addr_is_self(priv, node->macaddress_A)) continue; /* Shorthand */ - time_a = node->time_in[HSR_PT_SLAVE_A]; - time_b = node->time_in[HSR_PT_SLAVE_B]; + time_a = node->time_in[HSR_PRP_PT_SLAVE_A]; + time_b = node->time_in[HSR_PRP_PT_SLAVE_B]; /* Check for timestamps old enough to risk wrap-around */ if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2)) - node->time_in_stale[HSR_PT_SLAVE_A] = true; + node->time_in_stale[HSR_PRP_PT_SLAVE_A] = true; if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2)) - node->time_in_stale[HSR_PT_SLAVE_B] = true; + node->time_in_stale[HSR_PRP_PT_SLAVE_B] = true; /* Get age of newest frame from node. * At least one time_in is OK here; nodes get pruned long * before both time_ins can get stale */ timestamp = time_a; - if (node->time_in_stale[HSR_PT_SLAVE_A] || - (!node->time_in_stale[HSR_PT_SLAVE_B] && + if (node->time_in_stale[HSR_PRP_PT_SLAVE_A] || + (!node->time_in_stale[HSR_PRP_PT_SLAVE_B] && time_after(time_b, time_a))) timestamp = time_b; /* Warn of ring error only as long as we get frames at all */ if (time_is_after_jiffies(timestamp + - msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) { + msecs_to_jiffies(1.5 * + HSR_PRP_MAX_SLAVE_DIFF))) { rcu_read_lock(); port = get_late_port(priv, node); if (port) @@ -435,7 +442,7 @@ void hsr_prune_nodes(struct timer_list *t) /* Prune old entries */ if (time_is_before_jiffies(timestamp + - msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { + msecs_to_jiffies(HSR_PRP_NODE_FORGET_TIME))) { hsr_nl_nodedown(priv, node->macaddress_A); list_del_rcu(&node->mac_list); /* Note that we need to free this entry later: */ @@ -449,14 +456,14 @@ void hsr_prune_nodes(struct timer_list *t) jiffies + msecs_to_jiffies(PRUNE_PERIOD)); } -void *hsr_get_next_node(struct hsr_priv *priv, void *_pos, - unsigned char addr[ETH_ALEN]) +void *hsr_prp_get_next_node(struct hsr_prp_priv *priv, void *_pos, + unsigned char addr[ETH_ALEN]) { - struct hsr_node *node; + struct hsr_prp_node *node; if (!_pos) { node = list_first_or_null_rcu(&priv->node_db, - struct hsr_node, mac_list); + struct hsr_prp_node, mac_list); if (node) ether_addr_copy(addr, node->macaddress_A); return node; @@ -471,17 +478,17 @@ void *hsr_get_next_node(struct hsr_priv *priv, void *_pos, return NULL; } -int hsr_get_node_data(struct hsr_priv *priv, - const unsigned char *addr, - unsigned char addr_b[ETH_ALEN], - unsigned int *addr_b_ifindex, - int *if1_age, - u16 *if1_seq, - int *if2_age, - u16 *if2_seq) +int hsr_prp_get_node_data(struct hsr_prp_priv *priv, + const unsigned char *addr, + unsigned char addr_b[ETH_ALEN], + unsigned int *addr_b_ifindex, + int *if1_age, + u16 *if1_seq, + int *if2_age, + u16 *if2_seq) { - struct hsr_node *node; - struct hsr_port *port; + struct hsr_prp_node *node; + struct hsr_prp_port *port; unsigned long tdiff; node = find_node_by_addr_A(&priv->node_db, addr); @@ -490,8 +497,8 @@ int hsr_get_node_data(struct hsr_priv *priv, ether_addr_copy(addr_b, node->macaddress_B); - tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; - if (node->time_in_stale[HSR_PT_SLAVE_A]) + tdiff = jiffies - node->time_in[HSR_PRP_PT_SLAVE_A]; + if (node->time_in_stale[HSR_PRP_PT_SLAVE_A]) *if1_age = INT_MAX; #if HZ <= MSEC_PER_SEC else if (tdiff > msecs_to_jiffies(INT_MAX)) @@ -500,8 +507,8 @@ int hsr_get_node_data(struct hsr_priv *priv, else *if1_age = jiffies_to_msecs(tdiff); - tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B]; - if (node->time_in_stale[HSR_PT_SLAVE_B]) + tdiff = jiffies - node->time_in[HSR_PRP_PT_SLAVE_B]; + if (node->time_in_stale[HSR_PRP_PT_SLAVE_B]) *if2_age = INT_MAX; #if HZ <= MSEC_PER_SEC else if (tdiff > msecs_to_jiffies(INT_MAX)) @@ -511,10 +518,10 @@ int hsr_get_node_data(struct hsr_priv *priv, *if2_age = jiffies_to_msecs(tdiff); /* Present sequence numbers as if they were incoming on interface */ - *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; - *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; + *if1_seq = node->seq_out[HSR_PRP_PT_SLAVE_B]; + *if2_seq = node->seq_out[HSR_PRP_PT_SLAVE_A]; - if (node->addr_B_port != HSR_PT_NONE) { + if (node->addr_B_port != HSR_PRP_PT_NONE) { port = hsr_prp_get_port(priv, node->addr_B_port); *addr_b_ifindex = port->dev->ifindex; } else { diff --git a/net/hsr-prp/hsr_prp_framereg.h b/net/hsr-prp/hsr_prp_framereg.h index b29b685e444a..be52c55d9b6a 100644 --- a/net/hsr-prp/hsr_prp_framereg.h +++ b/net/hsr-prp/hsr_prp_framereg.h @@ -5,58 +5,58 @@ * 2011-2014 Arvid Brodin, arvid.brodin@alten.se */ -#ifndef __HSR_FRAMEREG_H -#define __HSR_FRAMEREG_H +#ifndef __HSR_PRP_FRAMEREG_H +#define __HSR_PRP_FRAMEREG_H #include "hsr_prp_main.h" -struct hsr_node; +struct hsr_prp_node; -void hsr_del_self_node(struct hsr_priv *priv); -void hsr_del_nodes(struct list_head *node_db); -struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, - bool is_sup); -void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, - struct hsr_port *port); -bool hsr_addr_is_self(struct hsr_priv *priv, unsigned char *addr); +void hsr_prp_del_self_node(struct hsr_prp_priv *priv); +void hsr_prp_del_nodes(struct list_head *node_db); +struct hsr_prp_node *hsr_prp_get_node(struct hsr_prp_port *port, + struct sk_buff *skb, bool is_sup); +void hsr_prp_handle_sup_frame(struct sk_buff *skb, + struct hsr_prp_node *node_curr, + struct hsr_prp_port *port); +bool hsr_prp_addr_is_self(struct hsr_prp_priv *priv, unsigned char *addr); -void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb); -void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb, - struct hsr_port *port); +void hsr_prp_addr_subst_source(struct hsr_prp_node *node, struct sk_buff *skb); +void hsr_prp_addr_subst_dest(struct hsr_prp_node *node_src, struct sk_buff *skb, + struct hsr_prp_port *port); -void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, - u16 sequence_nr); -int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, - u16 sequence_nr); +void hsr_prp_register_frame_in(struct hsr_prp_node *node, + struct hsr_prp_port *port, u16 sequence_nr); +int hsr_prp_register_frame_out(struct hsr_prp_port *port, + struct hsr_prp_node *node, u16 sequence_nr); -void hsr_prune_nodes(struct timer_list *t); +void hsr_prp_prune_nodes(struct timer_list *t); -int hsr_create_self_node(struct hsr_priv *priv, - unsigned char addr_a[ETH_ALEN], - unsigned char addr_b[ETH_ALEN]); +int hsr_prp_create_self_node(struct hsr_prp_priv *priv, + unsigned char addr_a[ETH_ALEN], + unsigned char addr_b[ETH_ALEN]); -void *hsr_get_next_node(struct hsr_priv *priv, void *_pos, - unsigned char addr[ETH_ALEN]); +void *hsr_prp_get_next_node(struct hsr_prp_priv *priv, void *_pos, + unsigned char addr[ETH_ALEN]); -int hsr_get_node_data(struct hsr_priv *priv, - const unsigned char *addr, - unsigned char addr_b[ETH_ALEN], - unsigned int *addr_b_ifindex, - int *if1_age, - u16 *if1_seq, - int *if2_age, - u16 *if2_seq); +int hsr_prp_get_node_data(struct hsr_prp_priv *priv, const unsigned char *addr, + unsigned char addr_b[ETH_ALEN], + unsigned int *addr_b_ifindex, + int *if1_age, + u16 *if1_seq, + int *if2_age, + u16 *if2_seq); -struct hsr_node { +struct hsr_prp_node { struct list_head mac_list; unsigned char macaddress_A[ETH_ALEN]; unsigned char macaddress_B[ETH_ALEN]; /* Local slave through which AddrB frames are received from this node */ - enum hsr_port_type addr_B_port; - unsigned long time_in[HSR_PT_PORTS]; - bool time_in_stale[HSR_PT_PORTS]; - u16 seq_out[HSR_PT_PORTS]; + enum hsr_prp_port_type addr_B_port; + unsigned long time_in[HSR_PRP_PT_PORTS]; + bool time_in_stale[HSR_PRP_PT_PORTS]; + u16 seq_out[HSR_PRP_PT_PORTS]; struct rcu_head rcu_head; }; -#endif /* __HSR_FRAMEREG_H */ +#endif /* __HSR_PRP_FRAMEREG_H */ diff --git a/net/hsr-prp/hsr_prp_main.c b/net/hsr-prp/hsr_prp_main.c index de85f42be6ee..4565744ce1a1 100644 --- a/net/hsr-prp/hsr_prp_main.c +++ b/net/hsr-prp/hsr_prp_main.c @@ -15,33 +15,33 @@ #include "hsr_prp_framereg.h" #include "hsr_prp_slave.h" -static bool hsr_slave_empty(struct hsr_priv *priv) +static bool hsr_prp_slave_empty(struct hsr_prp_priv *priv) { - struct hsr_port *port; + struct hsr_prp_port *port; - hsr_for_each_port(priv, port) - if (port->type != HSR_PT_MASTER) + hsr_prp_for_each_port(priv, port) + if (port->type != HSR_PRP_PT_MASTER) return false; return true; } -static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, - void *ptr) +static int hsr_prp_netdev_notify(struct notifier_block *nb, unsigned long event, + void *ptr) { - struct hsr_port *port, *master; + struct hsr_prp_port *port, *master; struct net_device *dev; - struct hsr_priv *priv; + struct hsr_prp_priv *priv; LIST_HEAD(list_kill); int mtu_max; int res; dev = netdev_notifier_info_to_dev(ptr); - port = hsr_port_get_rtnl(dev); + port = hsr_prp_port_get_rtnl(dev); if (!port) { - if (!is_hsr_master(dev)) + if (!is_hsr_prp_master(dev)) return NOTIFY_DONE; /* Not an HSR device */ priv = netdev_priv(dev); - port = hsr_prp_get_port(priv, HSR_PT_MASTER); + port = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); if (!port) { /* Resend of notification concerning removed device? */ return NOTIFY_DONE; @@ -54,14 +54,14 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, case NETDEV_UP: /* Administrative state DOWN */ case NETDEV_DOWN: /* Administrative state UP */ case NETDEV_CHANGE: /* Link (carrier) state changes */ - hsr_check_carrier_and_operstate(priv); + hsr_prp_check_carrier_and_operstate(priv); break; case NETDEV_CHANGENAME: - if (is_hsr_master(dev)) - hsr_debugfs_rename(dev); + if (is_hsr_prp_master(dev)) + hsr_prp_debugfs_rename(dev); break; case NETDEV_CHANGEADDR: - if (port->type == HSR_PT_MASTER) { + if (port->type == HSR_PRP_PT_MASTER) { /* This should not happen since there's no * ndo_set_mac_address() for HSR devices - i.e. not * supported. @@ -69,37 +69,37 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, break; } - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); - if (port->type == HSR_PT_SLAVE_A) { + if (port->type == HSR_PRP_PT_SLAVE_A) { ether_addr_copy(master->dev->dev_addr, dev->dev_addr); call_netdevice_notifiers(NETDEV_CHANGEADDR, master->dev); } /* Make sure we recognize frames from ourselves in hsr_rcv() */ - port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B); - res = hsr_create_self_node(priv, - master->dev->dev_addr, - port ? - port->dev->dev_addr : - master->dev->dev_addr); + port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); + res = hsr_prp_create_self_node(priv, + master->dev->dev_addr, + port ? port->dev->dev_addr : + master->dev->dev_addr); if (res) netdev_warn(master->dev, "Could not update HSR node address.\n"); break; case NETDEV_CHANGEMTU: - if (port->type == HSR_PT_MASTER) + if (port->type == HSR_PRP_PT_MASTER) break; /* Handled in ndo_change_mtu() */ - mtu_max = hsr_get_max_mtu(port->priv); - master = hsr_prp_get_port(port->priv, HSR_PT_MASTER); + mtu_max = hsr_prp_get_max_mtu(port->priv); + master = hsr_prp_get_port(port->priv, HSR_PRP_PT_MASTER); master->dev->mtu = mtu_max; break; case NETDEV_UNREGISTER: - if (!is_hsr_master(dev)) { - master = hsr_prp_get_port(port->priv, HSR_PT_MASTER); - hsr_del_port(port); - if (hsr_slave_empty(master->priv)) { + if (!is_hsr_prp_master(dev)) { + master = hsr_prp_get_port(port->priv, + HSR_PRP_PT_MASTER); + hsr_prp_del_port(port); + if (hsr_prp_slave_empty(master->priv)) { unregister_netdevice_queue(master->dev, &list_kill); unregister_netdevice_many(&list_kill); @@ -116,25 +116,26 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, return NOTIFY_DONE; } -struct hsr_port *hsr_prp_get_port(struct hsr_priv *priv, enum hsr_port_type pt) +struct hsr_prp_port *hsr_prp_get_port(struct hsr_prp_priv *priv, + enum hsr_prp_port_type pt) { - struct hsr_port *port; + struct hsr_prp_port *port; - hsr_for_each_port(priv, port) + hsr_prp_for_each_port(priv, port) if (port->type == pt) return port; return NULL; } static struct notifier_block hsr_nb = { - .notifier_call = hsr_netdev_notify, /* Slave event notifications */ + .notifier_call = hsr_prp_netdev_notify, /* Slave event notifications */ }; -static int __init hsr_init(void) +static int __init hsr_prp_init(void) { int res; - BUILD_BUG_ON(sizeof(struct hsr_tag) != HSR_HLEN); + BUILD_BUG_ON(sizeof(struct hsr_tag) != HSR_PRP_HLEN); register_netdevice_notifier(&hsr_nb); res = hsr_netlink_init(); @@ -142,13 +143,13 @@ static int __init hsr_init(void) return res; } -static void __exit hsr_exit(void) +static void __exit hsr_prp_exit(void) { unregister_netdevice_notifier(&hsr_nb); hsr_netlink_exit(); - hsr_debugfs_remove_root(); + hsr_prp_debugfs_remove_root(); } -module_init(hsr_init); -module_exit(hsr_exit); +module_init(hsr_prp_init); +module_exit(hsr_prp_exit); MODULE_LICENSE("GPL"); diff --git a/net/hsr-prp/hsr_prp_main.h b/net/hsr-prp/hsr_prp_main.h index 5a99d0b12c66..7d9a3e009a2d 100644 --- a/net/hsr-prp/hsr_prp_main.h +++ b/net/hsr-prp/hsr_prp_main.h @@ -5,8 +5,8 @@ * 2011-2014 Arvid Brodin, arvid.brodin@alten.se */ -#ifndef __HSR_PRIVATE_H -#define __HSR_PRIVATE_H +#ifndef __HSR_PRP_MAIN_H +#define __HSR_PRP_MAIN_H #include #include @@ -15,19 +15,19 @@ * Table 8. * All values in milliseconds. */ -#define HSR_LIFE_CHECK_INTERVAL 2000 /* ms */ -#define HSR_NODE_FORGET_TIME 60000 /* ms */ -#define HSR_ANNOUNCE_INTERVAL 100 /* ms */ +#define HSR_PRP_LIFE_CHECK_INTERVAL 2000 /* ms */ +#define HSR_PRP_NODE_FORGET_TIME 60000 /* ms */ +#define HSR_PRP_ANNOUNCE_INTERVAL 100 /* ms */ /* By how much may slave1 and slave2 timestamps of latest received frame from * each node differ before we notify of communication problem? */ -#define MAX_SLAVE_DIFF 3000 /* ms */ -#define HSR_SEQNR_START (USHRT_MAX - 1024) -#define HSR_SUP_SEQNR_START (HSR_SEQNR_START / 2) +#define HSR_PRP_MAX_SLAVE_DIFF 3000 /* ms */ +#define HSR_PRP_SEQNR_START (USHRT_MAX - 1024) +#define HSR_PRP_SUP_SEQNR_START (HSR_PRP_SEQNR_START / 2) /* How often shall we check for broken ring and remove node entries older than - * HSR_NODE_FORGET_TIME? + * HSR_PRP_NODE_FORGET_TIME? */ #define PRUNE_PERIOD 3000 /* ms */ @@ -48,7 +48,7 @@ struct hsr_tag { __be16 encap_proto; } __packed; -#define HSR_HLEN 6 +#define HSR_PRP_HLEN 6 #define HSR_V1_SUP_LSDUSIZE 52 @@ -83,55 +83,56 @@ struct hsr_ethhdr { /* HSR Supervision Frame data types. * Field names as defined in the IEC:2010 standard for HSR. */ -struct hsr_sup_tag { +struct hsr_prp_sup_tag { __be16 path_and_HSR_ver; __be16 sequence_nr; __u8 HSR_TLV_type; __u8 HSR_TLV_length; } __packed; -struct hsr_sup_payload { +struct hsr_prp_sup_payload { unsigned char macaddress_A[ETH_ALEN]; } __packed; -static inline void set_hsr_stag_path(struct hsr_sup_tag *hst, u16 path) +static inline void set_hsr_stag_path(struct hsr_prp_sup_tag *hst, u16 path) { set_hsr_tag_path((struct hsr_tag *)hst, path); } -static inline void set_hsr_stag_HSR_ver(struct hsr_sup_tag *hst, u16 HSR_ver) +static inline void set_hsr_stag_HSR_ver(struct hsr_prp_sup_tag *hst, + u16 HSR_ver) { set_hsr_tag_LSDU_size((struct hsr_tag *)hst, HSR_ver); } struct hsrv0_ethhdr_sp { struct ethhdr ethhdr; - struct hsr_sup_tag hsr_sup; + struct hsr_prp_sup_tag hsr_sup; } __packed; struct hsrv1_ethhdr_sp { struct ethhdr ethhdr; struct hsr_tag hsr; - struct hsr_sup_tag hsr_sup; + struct hsr_prp_sup_tag hsr_sup; } __packed; -enum hsr_port_type { - HSR_PT_NONE = 0, /* Must be 0, used by framereg */ - HSR_PT_SLAVE_A, - HSR_PT_SLAVE_B, - HSR_PT_INTERLINK, - HSR_PT_MASTER, - HSR_PT_PORTS, /* This must be the last item in the enum */ +enum hsr_prp_port_type { + HSR_PRP_PT_NONE = 0, /* Must be 0, used by framereg */ + HSR_PRP_PT_SLAVE_A, + HSR_PRP_PT_SLAVE_B, + HSR_PRP_PT_INTERLINK, + HSR_PRP_PT_MASTER, + HSR_PRP_PT_PORTS, /* This must be the last item in the enum */ }; -struct hsr_port { +struct hsr_prp_port { struct list_head port_list; struct net_device *dev; - struct hsr_priv *priv; - enum hsr_port_type type; + struct hsr_prp_priv *priv; + enum hsr_prp_port_type type; }; -struct hsr_priv { +struct hsr_prp_priv { struct rcu_head rcu_head; struct list_head ports; struct list_head node_db; /* Known HSR nodes */ @@ -150,10 +151,11 @@ struct hsr_priv { #endif }; -#define hsr_for_each_port(priv, port) \ +#define hsr_prp_for_each_port(priv, port) \ list_for_each_entry_rcu((port), &(priv)->ports, port_list) -struct hsr_port *hsr_prp_get_port(struct hsr_priv *priv, enum hsr_port_type pt); +struct hsr_prp_port *hsr_prp_get_port(struct hsr_prp_priv *priv, + enum hsr_prp_port_type pt); /* Caller must ensure skb is a valid HSR frame */ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb) @@ -165,24 +167,29 @@ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb) } #if IS_ENABLED(CONFIG_DEBUG_FS) -void hsr_debugfs_rename(struct net_device *dev); -void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev); -void hsr_debugfs_term(struct hsr_priv *priv); -void hsr_debugfs_create_root(void); -void hsr_debugfs_remove_root(void); +void hsr_prp_debugfs_rename(struct net_device *dev); +void hsr_prp_debugfs_init(struct hsr_prp_priv *priv, struct net_device *ndev); +void hsr_prp_debugfs_term(struct hsr_prp_priv *priv); +void hsr_prp_debugfs_create_root(void); +void hsr_prp_debugfs_remove_root(void); #else -static inline void hsr_debugfs_rename(struct net_device *dev) +static inline void hsr_prp_debugfs_rename(struct net_device *dev) { } -static inline void hsr_debugfs_init(struct hsr_priv *priv, - struct net_device *hsr_dev) + +static inline void hsr_prp_debugfs_init(struct hsr_prp_priv *priv, + struct net_device *ndev) {} -static inline void hsr_debugfs_term(struct hsr_priv *priv) + +static inline void hsr_prp_debugfs_term(struct hsr_prp_priv *priv) {} + static inline void hsr_debugfs_create_root(void) {} + static inline void hsr_debugfs_remove_root(void) {} + #endif -#endif /* __HSR_PRIVATE_H */ +#endif /* __HSR_PRP_MAIN_H */ diff --git a/net/hsr-prp/hsr_prp_slave.c b/net/hsr-prp/hsr_prp_slave.c index 2c8832bf7a5f..63a8dafa1f68 100644 --- a/net/hsr-prp/hsr_prp_slave.c +++ b/net/hsr-prp/hsr_prp_slave.c @@ -14,10 +14,10 @@ #include "hsr_prp_forward.h" #include "hsr_prp_framereg.h" -static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) +static rx_handler_result_t hsr_prp_handle_frame(struct sk_buff **pskb) { struct sk_buff *skb = *pskb; - struct hsr_port *port; + struct hsr_prp_port *port; __be16 protocol; if (!skb_mac_header_was_set(skb)) { @@ -25,11 +25,11 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) return RX_HANDLER_PASS; } - port = hsr_port_get_rcu(skb->dev); + port = hsr_prp_port_get_rcu(skb->dev); if (!port) goto finish_pass; - if (hsr_addr_is_self(port->priv, eth_hdr(skb)->h_source)) { + if (hsr_prp_addr_is_self(port->priv, eth_hdr(skb)->h_source)) { /* Directly kill frames sent by ourselves */ kfree_skb(skb); goto finish_consume; @@ -41,7 +41,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) skb_push(skb, ETH_HLEN); - hsr_forward_skb(skb, port); + hsr_prp_forward_skb(skb, port); finish_consume: return RX_HANDLER_CONSUMED; @@ -50,13 +50,13 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) return RX_HANDLER_PASS; } -bool hsr_port_exists(const struct net_device *dev) +bool hsr_prp_port_exists(const struct net_device *dev) { - return rcu_access_pointer(dev->rx_handler) == hsr_handle_frame; + return rcu_access_pointer(dev->rx_handler) == hsr_prp_handle_frame; } -static int hsr_check_dev_ok(struct net_device *dev, - struct netlink_ext_ack *extack) +static int hsr_prp_check_dev_ok(struct net_device *dev, + struct netlink_ext_ack *extack) { /* Don't allow HSR on non-ethernet like devices */ if ((dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER || @@ -66,13 +66,13 @@ static int hsr_check_dev_ok(struct net_device *dev, } /* Don't allow enslaving hsr devices */ - if (is_hsr_master(dev)) { + if (is_hsr_prp_master(dev)) { NL_SET_ERR_MSG_MOD(extack, "Cannot create trees of HSR devices."); return -EINVAL; } - if (hsr_port_exists(dev)) { + if (hsr_prp_port_exists(dev)) { NL_SET_ERR_MSG_MOD(extack, "This device is already a HSR slave."); return -EINVAL; @@ -97,27 +97,28 @@ static int hsr_check_dev_ok(struct net_device *dev, } /* Setup device to be added to the HSR bridge. */ -static int hsr_portdev_setup(struct hsr_priv *priv, struct net_device *dev, - struct hsr_port *port, - struct netlink_ext_ack *extack) +static int hsr_prp_portdev_setup(struct hsr_prp_priv *priv, + struct net_device *dev, + struct hsr_prp_port *port, + struct netlink_ext_ack *extack) { - struct net_device *hsr_dev; - struct hsr_port *master; + struct net_device *hsr_prp_dev; + struct hsr_prp_port *master; int res; res = dev_set_promiscuity(dev, 1); if (res) return res; - master = hsr_prp_get_port(priv, HSR_PT_MASTER); - hsr_dev = master->dev; + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); + hsr_prp_dev = master->dev; - res = netdev_upper_dev_link(dev, hsr_dev, extack); + res = netdev_upper_dev_link(dev, hsr_prp_dev, extack); if (res) goto fail_upper_dev_link; - res = netdev_rx_handler_register(dev, hsr_handle_frame, port); + res = netdev_rx_handler_register(dev, hsr_prp_handle_frame, port); if (res) goto fail_rx_handler; dev_disable_lro(dev); @@ -125,20 +126,21 @@ static int hsr_portdev_setup(struct hsr_priv *priv, struct net_device *dev, return 0; fail_rx_handler: - netdev_upper_dev_unlink(dev, hsr_dev); + netdev_upper_dev_unlink(dev, hsr_prp_dev); fail_upper_dev_link: dev_set_promiscuity(dev, -1); return res; } -int hsr_add_port(struct hsr_priv *priv, struct net_device *dev, - enum hsr_port_type type, struct netlink_ext_ack *extack) +int hsr_prp_add_port(struct hsr_prp_priv *priv, struct net_device *dev, + enum hsr_prp_port_type type, + struct netlink_ext_ack *extack) { - struct hsr_port *port, *master; + struct hsr_prp_port *port, *master; int res; - if (type != HSR_PT_MASTER) { - res = hsr_check_dev_ok(dev, extack); + if (type != HSR_PRP_PT_MASTER) { + res = hsr_prp_check_dev_ok(dev, extack); if (res) return res; } @@ -155,8 +157,8 @@ int hsr_add_port(struct hsr_priv *priv, struct net_device *dev, port->dev = dev; port->type = type; - if (type != HSR_PT_MASTER) { - res = hsr_portdev_setup(priv, dev, port, extack); + if (type != HSR_PRP_PT_MASTER) { + res = hsr_prp_portdev_setup(priv, dev, port, extack); if (res) goto fail_dev_setup; } @@ -164,9 +166,9 @@ int hsr_add_port(struct hsr_priv *priv, struct net_device *dev, list_add_tail_rcu(&port->port_list, &priv->ports); synchronize_rcu(); - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); netdev_update_features(master->dev); - dev_set_mtu(master->dev, hsr_get_max_mtu(priv)); + dev_set_mtu(master->dev, hsr_prp_get_max_mtu(priv)); return 0; @@ -175,18 +177,18 @@ int hsr_add_port(struct hsr_priv *priv, struct net_device *dev, return res; } -void hsr_del_port(struct hsr_port *port) +void hsr_prp_del_port(struct hsr_prp_port *port) { - struct hsr_priv *priv; - struct hsr_port *master; + struct hsr_prp_priv *priv; + struct hsr_prp_port *master; priv = port->priv; - master = hsr_prp_get_port(priv, HSR_PT_MASTER); + master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER); list_del_rcu(&port->port_list); if (port != master) { netdev_update_features(master->dev); - dev_set_mtu(master->dev, hsr_get_max_mtu(priv)); + dev_set_mtu(master->dev, hsr_prp_get_max_mtu(priv)); netdev_rx_handler_unregister(port->dev); dev_set_promiscuity(port->dev, -1); netdev_upper_dev_unlink(port->dev, master->dev); diff --git a/net/hsr-prp/hsr_prp_slave.h b/net/hsr-prp/hsr_prp_slave.h index 85f292d88845..e12f3224ef16 100644 --- a/net/hsr-prp/hsr_prp_slave.h +++ b/net/hsr-prp/hsr_prp_slave.h @@ -4,30 +4,34 @@ * 2011-2014 Arvid Brodin, arvid.brodin@alten.se */ -#ifndef __HSR_SLAVE_H -#define __HSR_SLAVE_H +#ifndef __HSR_PRP_SLAVE_H +#define __HSR_PRP_SLAVE_H #include #include #include #include "hsr_prp_main.h" -int hsr_add_port(struct hsr_priv *priv, struct net_device *dev, - enum hsr_port_type pt, struct netlink_ext_ack *extack); -void hsr_del_port(struct hsr_port *port); -bool hsr_port_exists(const struct net_device *dev); +int hsr_prp_add_port(struct hsr_prp_priv *hsr, struct net_device *dev, + enum hsr_prp_port_type pt, struct netlink_ext_ack *extack); +void hsr_prp_del_port(struct hsr_prp_port *port); +bool hsr_prp_port_exists(const struct net_device *dev); -static inline struct hsr_port *hsr_port_get_rtnl(const struct net_device *dev) +static inline +struct hsr_prp_port *hsr_prp_port_get_rtnl(const struct net_device *dev) { ASSERT_RTNL(); - return hsr_port_exists(dev) ? - rtnl_dereference(dev->rx_handler_data) : NULL; + return hsr_prp_port_exists(dev) ? + rtnl_dereference(dev->rx_handler_data) : + NULL; } -static inline struct hsr_port *hsr_port_get_rcu(const struct net_device *dev) +static inline +struct hsr_prp_port *hsr_prp_port_get_rcu(const struct net_device *dev) { - return hsr_port_exists(dev) ? - rcu_dereference(dev->rx_handler_data) : NULL; + return hsr_prp_port_exists(dev) ? + rcu_dereference(dev->rx_handler_data) : + NULL; } -#endif /* __HSR_SLAVE_H */ +#endif /* __HSR_PRP_SLAVE_H */ From patchwork Wed May 6 16:30:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 219761 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.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 A4D04C4724C for ; Wed, 6 May 2020 16:31:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C8F120708 for ; Wed, 6 May 2020 16:31:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="nuexToJ2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730347AbgEFQb0 (ORCPT ); Wed, 6 May 2020 12:31:26 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:46342 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730086AbgEFQan (ORCPT ); Wed, 6 May 2020 12:30:43 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 046GUcWm025583; Wed, 6 May 2020 11:30:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1588782638; bh=GWTcLpmIfKng0++C9JAIQL/vXaEPy4dOdqqqfM/HKT0=; h=From:To:Subject:Date:In-Reply-To:References; b=nuexToJ2k0gFVoeHEfh1J/XyPfnJgKZU7eoWR0ikozGSh7c6WTwbf4zMIJTCNT6A4 1HGgKjL2pp2tqV+XlBMg2Bk2I28J27nWT5xo4lwZiW1mf1mnC9eKuTddzWDnoLjbXY LotC5TZCq+8Qn+kCe+6LcswZ19hKyl2NBzb/4KqQ= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 046GUcLB063303 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 May 2020 11:30:38 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 6 May 2020 11:30:38 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 6 May 2020 11:30:38 -0500 Received: from uda0868495.fios-router.home (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 046GUXDl119719; Wed, 6 May 2020 11:30:37 -0500 From: Murali Karicheri To: , , , , , , Subject: [net-next RFC PATCH 08/13] net: hsr: migrate HSR netlink socket code to use new common API Date: Wed, 6 May 2020 12:30:28 -0400 Message-ID: <20200506163033.3843-9-m-karicheri2@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506163033.3843-1-m-karicheri2@ti.com> References: <20200506163033.3843-1-m-karicheri2@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Migrate the existing netlink socket code to the use the new common API. Signed-off-by: Murali Karicheri --- net/hsr-prp/hsr_netlink.c | 123 +++++++++++++++++++------------------- net/hsr-prp/hsr_netlink.h | 2 +- 2 files changed, 64 insertions(+), 61 deletions(-) diff --git a/net/hsr-prp/hsr_netlink.c b/net/hsr-prp/hsr_netlink.c index fbfa98aee13c..1f7c3be8d96e 100644 --- a/net/hsr-prp/hsr_netlink.c +++ b/net/hsr-prp/hsr_netlink.c @@ -15,13 +15,13 @@ #include "hsr_prp_device.h" #include "hsr_prp_framereg.h" -static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = { - [IFLA_HSR_SLAVE1] = { .type = NLA_U32 }, - [IFLA_HSR_SLAVE2] = { .type = NLA_U32 }, - [IFLA_HSR_MULTICAST_SPEC] = { .type = NLA_U8 }, - [IFLA_HSR_VERSION] = { .type = NLA_U8 }, - [IFLA_HSR_SUPERVISION_ADDR] = { .len = ETH_ALEN }, - [IFLA_HSR_SEQ_NR] = { .type = NLA_U16 }, +static const struct nla_policy hsr_policy[IFLA_HSR_PRP_MAX + 1] = { + [IFLA_HSR_PRP_SLAVE1] = { .type = NLA_U32 }, + [IFLA_HSR_PRP_SLAVE2] = { .type = NLA_U32 }, + [IFLA_HSR_PRP_SF_MC_ADDR_LSB] = { .type = NLA_U8 }, + [IFLA_HSR_PRP_VERSION] = { .type = NLA_U8 }, + [IFLA_HSR_PRP_SF_MC_ADDR] = { .len = ETH_ALEN }, + [IFLA_HSR_PRP_SEQ_NR] = { .type = NLA_U16 }, }; /* Here, it seems a netdevice has already been allocated for us, and the @@ -38,22 +38,22 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev, NL_SET_ERR_MSG_MOD(extack, "No slave devices specified"); return -EINVAL; } - if (!data[IFLA_HSR_SLAVE1]) { + if (!data[IFLA_HSR_PRP_SLAVE1]) { NL_SET_ERR_MSG_MOD(extack, "Slave1 device not specified"); return -EINVAL; } link[0] = __dev_get_by_index(src_net, - nla_get_u32(data[IFLA_HSR_SLAVE1])); + nla_get_u32(data[IFLA_HSR_PRP_SLAVE1])); if (!link[0]) { NL_SET_ERR_MSG_MOD(extack, "Slave1 does not exist"); return -EINVAL; } - if (!data[IFLA_HSR_SLAVE2]) { + if (!data[IFLA_HSR_PRP_SLAVE2]) { NL_SET_ERR_MSG_MOD(extack, "Slave2 device not specified"); return -EINVAL; } link[1] = __dev_get_by_index(src_net, - nla_get_u32(data[IFLA_HSR_SLAVE2])); + nla_get_u32(data[IFLA_HSR_PRP_SLAVE2])); if (!link[1]) { NL_SET_ERR_MSG_MOD(extack, "Slave2 does not exist"); return -EINVAL; @@ -64,15 +64,15 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev, return -EINVAL; } - if (!data[IFLA_HSR_MULTICAST_SPEC]) + if (!data[IFLA_HSR_PRP_SF_MC_ADDR_LSB]) multicast_spec = 0; else - multicast_spec = nla_get_u8(data[IFLA_HSR_MULTICAST_SPEC]); + multicast_spec = nla_get_u8(data[IFLA_HSR_PRP_SF_MC_ADDR_LSB]); - if (!data[IFLA_HSR_VERSION]) { + if (!data[IFLA_HSR_PRP_VERSION]) { hsr_version = 0; } else { - hsr_version = nla_get_u8(data[IFLA_HSR_VERSION]); + hsr_version = nla_get_u8(data[IFLA_HSR_PRP_VERSION]); if (hsr_version > 1) { NL_SET_ERR_MSG_MOD(extack, "Only versions 0..1 are supported"); @@ -91,19 +91,19 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A); if (port) { - if (nla_put_u32(skb, IFLA_HSR_SLAVE1, port->dev->ifindex)) + if (nla_put_u32(skb, IFLA_HSR_PRP_SLAVE1, port->dev->ifindex)) goto nla_put_failure; } port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); if (port) { - if (nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex)) + if (nla_put_u32(skb, IFLA_HSR_PRP_SLAVE2, port->dev->ifindex)) goto nla_put_failure; } - if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN, + if (nla_put(skb, IFLA_HSR_PRP_SF_MC_ADDR, ETH_ALEN, priv->sup_multicast_addr) || - nla_put_u16(skb, IFLA_HSR_SEQ_NR, priv->sequence_nr)) + nla_put_u16(skb, IFLA_HSR_PRP_SEQ_NR, priv->sequence_nr)) goto nla_put_failure; return 0; @@ -114,7 +114,7 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) static struct rtnl_link_ops hsr_link_ops __read_mostly = { .kind = "hsr", - .maxtype = IFLA_HSR_MAX, + .maxtype = IFLA_HSR_PRP_MAX, .policy = hsr_policy, .priv_size = sizeof(struct hsr_prp_priv), .setup = hsr_prp_dev_setup, @@ -123,14 +123,14 @@ static struct rtnl_link_ops hsr_link_ops __read_mostly = { }; /* attribute policy */ -static const struct nla_policy hsr_genl_policy[HSR_A_MAX + 1] = { - [HSR_A_NODE_ADDR] = { .len = ETH_ALEN }, - [HSR_A_NODE_ADDR_B] = { .len = ETH_ALEN }, - [HSR_A_IFINDEX] = { .type = NLA_U32 }, - [HSR_A_IF1_AGE] = { .type = NLA_U32 }, - [HSR_A_IF2_AGE] = { .type = NLA_U32 }, - [HSR_A_IF1_SEQ] = { .type = NLA_U16 }, - [HSR_A_IF2_SEQ] = { .type = NLA_U16 }, +static const struct nla_policy hsr_genl_policy[HSR_PRP_A_MAX + 1] = { + [HSR_PRP_A_NODE_ADDR] = { .len = ETH_ALEN }, + [HSR_PRP_A_NODE_ADDR_B] = { .len = ETH_ALEN }, + [HSR_PRP_A_IFINDEX] = { .type = NLA_U32 }, + [HSR_PRP_A_IF1_AGE] = { .type = NLA_U32 }, + [HSR_PRP_A_IF2_AGE] = { .type = NLA_U32 }, + [HSR_PRP_A_IF1_SEQ] = { .type = NLA_U16 }, + [HSR_PRP_A_IF2_SEQ] = { .type = NLA_U16 }, }; static struct genl_family hsr_genl_family; @@ -157,15 +157,15 @@ void hsr_nl_ringerror(struct hsr_prp_priv *priv, goto fail; msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, - HSR_C_RING_ERROR); + HSR_PRP_C_RING_ERROR); if (!msg_head) goto nla_put_failure; - res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr); + res = nla_put(skb, HSR_PRP_A_NODE_ADDR, ETH_ALEN, addr); if (res < 0) goto nla_put_failure; - res = nla_put_u32(skb, HSR_A_IFINDEX, port->dev->ifindex); + res = nla_put_u32(skb, HSR_PRP_A_IFINDEX, port->dev->ifindex); if (res < 0) goto nla_put_failure; @@ -199,11 +199,12 @@ void hsr_nl_nodedown(struct hsr_prp_priv *priv, if (!skb) goto fail; - msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, HSR_C_NODE_DOWN); + msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, + HSR_PRP_C_NODE_DOWN); if (!msg_head) goto nla_put_failure; - res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr); + res = nla_put(skb, HSR_PRP_A_NODE_ADDR, ETH_ALEN, addr); if (res < 0) goto nla_put_failure; @@ -222,7 +223,7 @@ void hsr_nl_nodedown(struct hsr_prp_priv *priv, rcu_read_unlock(); } -/* HSR_C_GET_NODE_STATUS lets userspace query the internal HSR node table +/* HSR_PRP_C_GET_NODE_STATUS lets userspace query the internal HSR node table * about the status of a specific node in the network, defined by its MAC * address. * @@ -252,16 +253,17 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) if (!info) goto invalid; - na = info->attrs[HSR_A_IFINDEX]; + na = info->attrs[HSR_PRP_A_IFINDEX]; if (!na) goto invalid; - na = info->attrs[HSR_A_NODE_ADDR]; + na = info->attrs[HSR_PRP_A_NODE_ADDR]; if (!na) goto invalid; rcu_read_lock(); - hsr_dev = dev_get_by_index_rcu(genl_info_net(info), - nla_get_u32(info->attrs[HSR_A_IFINDEX])); + hsr_dev = + dev_get_by_index_rcu(genl_info_net(info), + nla_get_u32(info->attrs[HSR_PRP_A_IFINDEX])); if (!hsr_dev) goto rcu_unlock; if (!is_hsr_prp_master(hsr_dev)) @@ -276,20 +278,20 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid, info->snd_seq, &hsr_genl_family, 0, - HSR_C_SET_NODE_STATUS); + HSR_PRP_C_SET_NODE_STATUS); if (!msg_head) { res = -ENOMEM; goto nla_put_failure; } - res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex); + res = nla_put_u32(skb_out, HSR_PRP_A_IFINDEX, hsr_dev->ifindex); if (res < 0) goto nla_put_failure; priv = netdev_priv(hsr_dev); res = hsr_prp_get_node_data(priv, (unsigned char *) - nla_data(info->attrs[HSR_A_NODE_ADDR]), + nla_data(info->attrs[HSR_PRP_A_NODE_ADDR]), node_addr_b, &addr_b_ifindex, &hsr_node_if1_age, @@ -299,45 +301,45 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) if (res < 0) goto nla_put_failure; - res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, - nla_data(info->attrs[HSR_A_NODE_ADDR])); + res = nla_put(skb_out, HSR_PRP_A_NODE_ADDR, ETH_ALEN, + nla_data(info->attrs[HSR_PRP_A_NODE_ADDR])); if (res < 0) goto nla_put_failure; if (addr_b_ifindex > -1) { - res = nla_put(skb_out, HSR_A_NODE_ADDR_B, ETH_ALEN, + res = nla_put(skb_out, HSR_PRP_A_NODE_ADDR_B, ETH_ALEN, node_addr_b); if (res < 0) goto nla_put_failure; - res = nla_put_u32(skb_out, HSR_A_ADDR_B_IFINDEX, + res = nla_put_u32(skb_out, HSR_PRP_A_ADDR_B_IFINDEX, addr_b_ifindex); if (res < 0) goto nla_put_failure; } - res = nla_put_u32(skb_out, HSR_A_IF1_AGE, hsr_node_if1_age); + res = nla_put_u32(skb_out, HSR_PRP_A_IF1_AGE, hsr_node_if1_age); if (res < 0) goto nla_put_failure; - res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq); + res = nla_put_u16(skb_out, HSR_PRP_A_IF1_SEQ, hsr_node_if1_seq); if (res < 0) goto nla_put_failure; port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A); if (port) - res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX, + res = nla_put_u32(skb_out, HSR_PRP_A_IF1_IFINDEX, port->dev->ifindex); if (res < 0) goto nla_put_failure; - res = nla_put_u32(skb_out, HSR_A_IF2_AGE, hsr_node_if2_age); + res = nla_put_u32(skb_out, HSR_PRP_A_IF2_AGE, hsr_node_if2_age); if (res < 0) goto nla_put_failure; - res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq); + res = nla_put_u16(skb_out, HSR_PRP_A_IF2_SEQ, hsr_node_if2_seq); if (res < 0) goto nla_put_failure; port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B); if (port) - res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX, + res = nla_put_u32(skb_out, HSR_PRP_A_IF2_IFINDEX, port->dev->ifindex); if (res < 0) goto nla_put_failure; @@ -381,13 +383,14 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) if (!info) goto invalid; - na = info->attrs[HSR_A_IFINDEX]; + na = info->attrs[HSR_PRP_A_IFINDEX]; if (!na) goto invalid; rcu_read_lock(); - hsr_dev = dev_get_by_index_rcu(genl_info_net(info), - nla_get_u32(info->attrs[HSR_A_IFINDEX])); + hsr_dev = + dev_get_by_index_rcu(genl_info_net(info), + nla_get_u32(info->attrs[HSR_PRP_A_IFINDEX])); if (!hsr_dev) goto rcu_unlock; if (!is_hsr_prp_master(hsr_dev)) @@ -403,14 +406,14 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid, info->snd_seq, &hsr_genl_family, 0, - HSR_C_SET_NODE_LIST); + HSR_PRP_C_SET_NODE_LIST); if (!msg_head) { res = -ENOMEM; goto nla_put_failure; } if (!restart) { - res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex); + res = nla_put_u32(skb_out, HSR_PRP_A_IFINDEX, hsr_dev->ifindex); if (res < 0) goto nla_put_failure; } @@ -420,7 +423,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) if (!pos) pos = hsr_prp_get_next_node(priv, NULL, addr); while (pos) { - res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr); + res = nla_put(skb_out, HSR_PRP_A_NODE_ADDR, ETH_ALEN, addr); if (res < 0) { if (res == -EMSGSIZE) { genlmsg_end(skb_out, msg_head); @@ -457,14 +460,14 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) static const struct genl_ops hsr_ops[] = { { - .cmd = HSR_C_GET_NODE_STATUS, + .cmd = HSR_PRP_C_GET_NODE_STATUS, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .flags = 0, .doit = hsr_get_node_status, .dumpit = NULL, }, { - .cmd = HSR_C_GET_NODE_LIST, + .cmd = HSR_PRP_C_GET_NODE_LIST, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .flags = 0, .doit = hsr_get_node_list, @@ -476,7 +479,7 @@ static struct genl_family hsr_genl_family __ro_after_init = { .hdrsize = 0, .name = "HSR", .version = 1, - .maxattr = HSR_A_MAX, + .maxattr = HSR_PRP_A_MAX, .policy = hsr_genl_policy, .netnsok = true, .module = THIS_MODULE, diff --git a/net/hsr-prp/hsr_netlink.h b/net/hsr-prp/hsr_netlink.h index ae7a1c0de80d..df3d1acb08e0 100644 --- a/net/hsr-prp/hsr_netlink.h +++ b/net/hsr-prp/hsr_netlink.h @@ -10,7 +10,7 @@ #include #include -#include +#include struct hsr_prp_priv; struct hsr_prp_port; From patchwork Wed May 6 16:30:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 219763 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.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 0A305C28CBC for ; Wed, 6 May 2020 16:31:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C999620CC7 for ; Wed, 6 May 2020 16:31:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Slf/XJ9S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730239AbgEFQa7 (ORCPT ); Wed, 6 May 2020 12:30:59 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:51748 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730013AbgEFQaq (ORCPT ); Wed, 6 May 2020 12:30:46 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 046GUeIo087477; Wed, 6 May 2020 11:30:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1588782640; bh=cNCMPLTurvB38rEd2WObrxZ4bD8NhoZ6vGZvOSig6GQ=; h=From:To:Subject:Date:In-Reply-To:References; b=Slf/XJ9S5m6w9aeYjv6Dq0yXu2rzNy0z/vUBabh4myAZkD0gdkWY/Xv2j6XPXxrai aJTdrX0rAjc2caSXEzMd1QC8YucOhKWt4+fHGsJO3sRBhBqnN9wWQy6qkjh9iIlo+a LUCxgm/3+viZC1gj6yUkclWQql3w8FGk6RIGjxz4= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 046GUeo9104803; Wed, 6 May 2020 11:30:40 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 6 May 2020 11:30:40 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 6 May 2020 11:30:40 -0500 Received: from uda0868495.fios-router.home (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 046GUXDp119719; Wed, 6 May 2020 11:30:39 -0500 From: Murali Karicheri To: , , , , , , Subject: [net-next RFC PATCH 12/13] net: prp: add packet handling support Date: Wed, 6 May 2020 12:30:32 -0400 Message-ID: <20200506163033.3843-13-m-karicheri2@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506163033.3843-1-m-karicheri2@ti.com> References: <20200506163033.3843-1-m-karicheri2@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org DAN-P (Dual Attached Nodes PRP) nodes are expected to receive traditional IP packets as well as PRP (Parallel Redundancy Protocol) tagged (trailer) packets. This is because PRP network can have traditional devices such as bridges/swiches or PC attached to it and should be able to communicate. This patch adds logic to format L2 frames from network stack to add a trailer and send it as duplicates over the slave interfaces as per IEC 62439-3. At the ingress, it strips the trailer, do duplicate detection and rejection and forward a stripped frame up the network stack. As PRP device should accept frames from Singly Attached Nodes (SAN) and mark the link where the frame came from in the node table. As Supervisor frame LSDU size is same for HSR and PRP, rename the constant for the same. Signed-off-by: Murali Karicheri --- net/hsr-prp/hsr_prp_device.c | 16 ++- net/hsr-prp/hsr_prp_forward.c | 235 ++++++++++++++++++++++++++++----- net/hsr-prp/hsr_prp_framereg.c | 65 ++++++--- net/hsr-prp/hsr_prp_framereg.h | 8 +- net/hsr-prp/hsr_prp_main.h | 73 +++++++++- net/hsr-prp/hsr_prp_slave.c | 38 ++++-- 6 files changed, 371 insertions(+), 64 deletions(-) diff --git a/net/hsr-prp/hsr_prp_device.c b/net/hsr-prp/hsr_prp_device.c index 3c463e185f64..4c6a7bb95e31 100644 --- a/net/hsr-prp/hsr_prp_device.c +++ b/net/hsr-prp/hsr_prp_device.c @@ -278,7 +278,7 @@ static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master, if (proto_ver == HSR_V1) { hsr_tag = skb_put(skb, sizeof(struct hsr_tag)); hsr_tag->encap_proto = htons(ETH_P_PRP); - set_hsr_tag_LSDU_size(hsr_tag, HSR_V1_SUP_LSDUSIZE); + set_hsr_tag_LSDU_size(hsr_tag, HSR_PRP_V1_SUP_LSDUSIZE); } hsr_stag = skb_put(skb, sizeof(struct hsr_prp_sup_tag)); @@ -319,7 +319,7 @@ static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master, tail = skb_tail_pointer(skb) - HSR_PRP_HLEN; rct = (struct prp_rct *)tail; rct->PRP_suffix = htons(ETH_P_PRP); - set_prp_LSDU_size(rct, HSR_V1_SUP_LSDUSIZE); + set_prp_LSDU_size(rct, HSR_PRP_V1_SUP_LSDUSIZE); rct->sequence_nr = htons(master->priv->sequence_nr); master->priv->sequence_nr++; } @@ -483,10 +483,6 @@ int hsr_prp_dev_finalize(struct net_device *hsr_prp_dev, struct hsr_prp_priv *priv; int res; - /* PRP not supported yet */ - if (protocol_version == PRP_V1) - return -EPROTONOSUPPORT; - priv = netdev_priv(hsr_prp_dev); INIT_LIST_HEAD(&priv->ports); INIT_LIST_HEAD(&priv->node_db); @@ -501,6 +497,14 @@ int hsr_prp_dev_finalize(struct net_device *hsr_prp_dev, if (res < 0) return res; + priv->prot_version = protocol_version; + if (priv->prot_version == PRP_V1) { + /* For PRP, lan_id has most significant 3 bits holding + * the net_id of PRP_LAN_ID + */ + priv->net_id = PRP_LAN_ID << 1; + } + spin_lock_init(&priv->seqnr_lock); /* Overflow soon to find bugs easier: */ priv->sequence_nr = HSR_PRP_SEQNR_START; diff --git a/net/hsr-prp/hsr_prp_forward.c b/net/hsr-prp/hsr_prp_forward.c index d7e975919322..3305f0b8ac11 100644 --- a/net/hsr-prp/hsr_prp_forward.c +++ b/net/hsr-prp/hsr_prp_forward.c @@ -18,6 +18,7 @@ struct hsr_prp_node; struct hsr_prp_frame_info { struct sk_buff *skb_std; struct sk_buff *skb_hsr; + struct sk_buff *skb_prp; struct hsr_prp_port *port_rcv; struct hsr_prp_node *node_src; u16 sequence_nr; @@ -25,6 +26,7 @@ struct hsr_prp_frame_info { bool is_vlan; bool is_local_dest; bool is_local_exclusive; + bool is_from_san; }; /* The uses I can see for these HSR supervision frames are: @@ -85,8 +87,8 @@ static bool is_supervision_frame(struct hsr_prp_priv *priv, struct sk_buff *skb) return true; } -static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, - struct hsr_prp_frame_info *frame) +static struct sk_buff *create_stripped_skb_hsr(struct sk_buff *skb_in, + struct hsr_prp_frame_info *frame) { struct sk_buff *skb; int copylen; @@ -118,22 +120,91 @@ static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, static struct sk_buff *frame_get_stripped_skb(struct hsr_prp_frame_info *frame, struct hsr_prp_port *port) { - if (!frame->skb_std) - frame->skb_std = create_stripped_skb(frame->skb_hsr, frame); + if (!frame->skb_std) { + if (frame->skb_hsr) { + frame->skb_std = + create_stripped_skb_hsr(frame->skb_hsr, frame); + } else if (frame->skb_prp) { + /* trim the skb by len - HSR_PRP_HLEN to exclude + * RCT + */ + skb_trim(frame->skb_prp, + frame->skb_prp->len - HSR_PRP_HLEN); + frame->skb_std = + __pskb_copy(frame->skb_prp, + skb_headroom(frame->skb_prp), + GFP_ATOMIC); + + } else { + /* Unexpected */ + WARN_ONCE(1, "%s:%d: Unexpected frame received (port_src %s)\n", + __FILE__, __LINE__, port->dev->name); + return NULL; + } + } + return skb_clone(frame->skb_std, GFP_ATOMIC); } -static void hsr_fill_tag(struct sk_buff *skb, struct hsr_prp_frame_info *frame, - struct hsr_prp_port *port, u8 proto_version) +static void prp_set_lan_id(struct prp_rct *trailor, + struct hsr_prp_port *port) { - struct hsr_ethhdr *hsr_ethhdr; int lane_id; - int lsdu_size; if (port->type == HSR_PRP_PT_SLAVE_A) lane_id = 0; else lane_id = 1; + /* Add net_id in the upper 3 bits of lane_id */ + lane_id |= port->priv->net_id; + + set_prp_lan_id(trailor, lane_id); +} + +/* Tailroom for PRP rct should have been created before calling this */ +static void prp_fill_rct(struct sk_buff *skb, + struct hsr_prp_frame_info *frame, + struct hsr_prp_port *port) +{ + struct prp_rct *trailor; + int lsdu_size; + + if (!skb) + return; + + if (frame->is_vlan) + skb_put_padto(skb, VLAN_ETH_ZLEN); + else + skb_put_padto(skb, ETH_ZLEN); + + trailor = (struct prp_rct *)skb_put(skb, HSR_PRP_HLEN); + lsdu_size = skb->len - 14; + if (frame->is_vlan) + lsdu_size -= 4; + prp_set_lan_id(trailor, port); + set_prp_LSDU_size(trailor, lsdu_size); + trailor->sequence_nr = htons(frame->sequence_nr); + trailor->PRP_suffix = htons(ETH_P_PRP); +} + +static void hsr_set_path_id(struct hsr_ethhdr *hsr_ethhdr, + struct hsr_prp_port *port) +{ + int path_id; + + if (port->type == HSR_PRP_PT_SLAVE_A) + path_id = 0; + else + path_id = 1; + + set_hsr_tag_path(&hsr_ethhdr->hsr_tag, path_id); +} + +static void hsr_fill_tag(struct sk_buff *skb, struct hsr_prp_frame_info *frame, + struct hsr_prp_port *port, u8 proto_version) +{ + struct hsr_ethhdr *hsr_ethhdr; + int lsdu_size; lsdu_size = skb->len - 14; if (frame->is_vlan) @@ -141,7 +212,7 @@ static void hsr_fill_tag(struct sk_buff *skb, struct hsr_prp_frame_info *frame, hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb); - set_hsr_tag_path(&hsr_ethhdr->hsr_tag, lane_id); + hsr_set_path_id(hsr_ethhdr, port); set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size); hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr); hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto; @@ -157,6 +228,14 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o, unsigned char *dst, *src; struct sk_buff *skb; + if (port->priv->prot_version > HSR_V1) { + skb = skb_copy_expand(skb_o, 0, + skb_tailroom(skb_o) + HSR_PRP_HLEN, + GFP_ATOMIC); + prp_fill_rct(skb, frame, port); + return skb; + } + /* Create the new skb with enough headroom to fit the HSR tag */ skb = __pskb_copy(skb_o, skb_headroom(skb_o) + HSR_PRP_HLEN, GFP_ATOMIC); @@ -187,8 +266,26 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o, static struct sk_buff *frame_get_tagged_skb(struct hsr_prp_frame_info *frame, struct hsr_prp_port *port) { - if (frame->skb_hsr) + if (frame->skb_hsr) { + struct hsr_ethhdr *hsr_ethhdr = + (struct hsr_ethhdr *)skb_mac_header(frame->skb_hsr); + + /* set the lane id properly */ + hsr_set_path_id(hsr_ethhdr, port); return skb_clone(frame->skb_hsr, GFP_ATOMIC); + } + + if (frame->skb_prp) { + struct prp_rct *trailor = skb_get_PRP_rct(frame->skb_prp); + + if (trailor) { + prp_set_lan_id(trailor, port); + } else { + WARN_ONCE(!trailor, "errored PRP skb"); + return NULL; + } + return skb_clone(frame->skb_prp, GFP_ATOMIC); + } if (port->type != HSR_PRP_PT_SLAVE_A && port->type != HSR_PRP_PT_SLAVE_B) { @@ -236,6 +333,7 @@ static int hsr_prp_xmit(struct sk_buff *skb, struct hsr_prp_port *port, /* Forward the frame through all devices except: * - Back through the receiving device * - If it's a HSR frame: through a device where it has passed before + * - if it's a PRP frame: through another PRP slave device (no bridge) * - To the local HSR master only if the frame is directly addressed to it, or * a non-supervision multicast or broadcast frame. * @@ -247,7 +345,7 @@ static int hsr_prp_xmit(struct sk_buff *skb, struct hsr_prp_port *port, static void hsr_prp_forward_do(struct hsr_prp_frame_info *frame) { struct hsr_prp_port *port; - struct sk_buff *skb; + struct sk_buff *skb = NULL; hsr_prp_for_each_port(frame->port_rcv->priv, port) { /* Don't send frame back the way it came */ @@ -263,24 +361,46 @@ static void hsr_prp_forward_do(struct hsr_prp_frame_info *frame) frame->is_local_exclusive) continue; - /* Don't send frame over port where it has been sent before */ - if (hsr_prp_register_frame_out(port, frame->node_src, + /* Don't send frame over port where it has been sent before. + * Also fro SAN, this shouldn't be done. + */ + if (!frame->is_from_san && + hsr_prp_register_frame_out(port, frame->node_src, frame->sequence_nr)) continue; if (frame->is_supervision && port->type == HSR_PRP_PT_MASTER) { - hsr_prp_handle_sup_frame(frame->skb_hsr, - frame->node_src, - frame->port_rcv); + if (frame->skb_hsr) + skb = frame->skb_hsr; + else if (frame->skb_prp) + skb = frame->skb_prp; + + if (skb) + hsr_prp_handle_sup_frame(skb, + frame->node_src, + frame->port_rcv); continue; } + if (port->priv->prot_version == PRP_V1 && + ((frame->port_rcv->type == HSR_PRP_PT_SLAVE_A && + port->type == HSR_PRP_PT_SLAVE_B) || + (frame->port_rcv->type == HSR_PRP_PT_SLAVE_B && + port->type == HSR_PRP_PT_SLAVE_A))) + continue; + if (port->type != HSR_PRP_PT_MASTER) skb = frame_get_tagged_skb(frame, port); else skb = frame_get_stripped_skb(frame, port); + if (!skb) { - /* FIXME: Record the dropped frame? */ + if (frame->port_rcv->type == HSR_PRP_PT_MASTER) { + struct net_device *master_dev = + hsr_prp_get_port(port->priv, + HSR_PRP_PT_MASTER)->dev; + master_dev->stats.rx_dropped++; + } continue; } @@ -314,34 +434,79 @@ static void check_local_dest(struct hsr_prp_priv *priv, struct sk_buff *skb, static int fill_frame_info(struct hsr_prp_frame_info *frame, struct sk_buff *skb, struct hsr_prp_port *port) { + struct hsr_prp_priv *priv = port->priv; struct ethhdr *ethhdr; + struct hsr_vlan_ethhdr *vlan_hdr; unsigned long irqflags; + __be16 proto; + memset(frame, 0, sizeof(*frame)); frame->is_supervision = is_supervision_frame(port->priv, skb); - frame->node_src = hsr_prp_get_node(port, skb, frame->is_supervision); + frame->node_src = hsr_prp_get_node(port, &priv->node_db, skb, + frame->is_supervision, + port->type); if (!frame->node_src) return -1; /* Unknown node and !is_supervision, or no mem */ ethhdr = (struct ethhdr *)skb_mac_header(skb); frame->is_vlan = false; - if (ethhdr->h_proto == htons(ETH_P_8021Q)) { + proto = ethhdr->h_proto; + + if (proto == htons(ETH_P_8021Q)) { frame->is_vlan = true; /* FIXME: */ WARN_ONCE(1, "HSR: VLAN not yet supported"); } - if (ethhdr->h_proto == htons(ETH_P_PRP) || - ethhdr->h_proto == htons(ETH_P_HSR)) { - frame->skb_std = NULL; - frame->skb_hsr = skb; - frame->sequence_nr = hsr_get_skb_sequence_nr(skb); + + if (frame->is_vlan) { + vlan_hdr = (struct hsr_vlan_ethhdr *)ethhdr; + proto = vlan_hdr->vlanhdr.h_vlan_encapsulated_proto; + } + + frame->is_from_san = false; + if (proto == htons(ETH_P_PRP) || proto == htons(ETH_P_HSR)) { + struct prp_rct *rct = skb_get_PRP_rct(skb); + + if (rct && + prp_check_lsdu_size(skb, rct, frame->is_supervision)) { + frame->skb_hsr = NULL; + frame->skb_std = NULL; + frame->skb_prp = skb; + frame->sequence_nr = prp_get_skb_sequence_nr(rct); + } else { + frame->skb_std = NULL; + frame->skb_prp = NULL; + frame->skb_hsr = skb; + frame->sequence_nr = hsr_get_skb_sequence_nr(skb); + } } else { - frame->skb_std = skb; - frame->skb_hsr = NULL; - /* Sequence nr for the master node */ - spin_lock_irqsave(&port->priv->seqnr_lock, irqflags); - frame->sequence_nr = port->priv->sequence_nr; - port->priv->sequence_nr++; - spin_unlock_irqrestore(&port->priv->seqnr_lock, irqflags); + struct prp_rct *rct = skb_get_PRP_rct(skb); + + if (rct && + prp_check_lsdu_size(skb, rct, frame->is_supervision) && + port->priv->prot_version == PRP_V1) { + frame->skb_hsr = NULL; + frame->skb_std = NULL; + frame->skb_prp = skb; + frame->sequence_nr = prp_get_skb_sequence_nr(rct); + frame->is_from_san = false; + } else { + frame->skb_hsr = NULL; + frame->skb_prp = NULL; + frame->skb_std = skb; + + if (port->type != HSR_PRP_PT_MASTER) { + frame->is_from_san = true; + } else { + /* Sequence nr for the master node */ + spin_lock_irqsave(&port->priv->seqnr_lock, + irqflags); + frame->sequence_nr = port->priv->sequence_nr; + port->priv->sequence_nr++; + spin_unlock_irqrestore(&port->priv->seqnr_lock, + irqflags); + } + } } frame->port_rcv = port; @@ -363,6 +528,12 @@ void hsr_prp_forward_skb(struct sk_buff *skb, struct hsr_prp_port *port) if (fill_frame_info(&frame, skb, port) < 0) goto out_drop; + + /* Only accept packets for the protocol we have been configured */ + if ((frame.skb_hsr && port->priv->prot_version == PRP_V1) || + (frame.skb_prp && port->priv->prot_version <= HSR_V1)) + goto out_drop; + hsr_prp_register_frame_in(frame.node_src, port, frame.sequence_nr); hsr_prp_forward_do(&frame); /* Gets called for ingress frames as well as egress from master port. @@ -375,6 +546,8 @@ void hsr_prp_forward_skb(struct sk_buff *skb, struct hsr_prp_port *port) if (frame.skb_hsr) kfree_skb(frame.skb_hsr); + if (frame.skb_prp) + kfree_skb(frame.skb_prp); if (frame.skb_std) kfree_skb(frame.skb_std); return; diff --git a/net/hsr-prp/hsr_prp_framereg.c b/net/hsr-prp/hsr_prp_framereg.c index 42c673befe2c..ae12cd99868c 100644 --- a/net/hsr-prp/hsr_prp_framereg.c +++ b/net/hsr-prp/hsr_prp_framereg.c @@ -136,7 +136,8 @@ void hsr_prp_del_nodes(struct list_head *node_db) static struct hsr_prp_node *hsr_prp_add_node(struct hsr_prp_priv *priv, struct list_head *node_db, unsigned char addr[], - u16 seq_out) + u16 seq_out, bool san, + enum hsr_prp_port_type rx_port) { struct hsr_prp_node *new_node, *node; unsigned long now; @@ -156,6 +157,13 @@ static struct hsr_prp_node *hsr_prp_add_node(struct hsr_prp_priv *priv, new_node->time_in[i] = now; for (i = 0; i < HSR_PRP_PT_PORTS; i++) new_node->seq_out[i] = seq_out; + if (san) { + /* Mark if the SAN node is over LAN_A or LAN_B */ + if (rx_port == HSR_PRP_PT_SLAVE_A) + new_node->san_a = true; + else if (rx_port == HSR_PRP_PT_SLAVE_B) + new_node->san_b = true; + } spin_lock_bh(&priv->list_lock); list_for_each_entry_rcu(node, node_db, mac_list, @@ -174,16 +182,28 @@ static struct hsr_prp_node *hsr_prp_add_node(struct hsr_prp_priv *priv, return node; } +static void hsr_prp_reset_san_flags(struct hsr_prp_node *node, bool is_sup) +{ + if (!is_sup) + return; + + node->san_a = false; + node->san_b = false; +} + /* Get the hsr_node from which 'skb' was sent. */ struct hsr_prp_node *hsr_prp_get_node(struct hsr_prp_port *port, + struct list_head *node_db, struct sk_buff *skb, - bool is_sup) + bool is_sup, + enum hsr_prp_port_type rx_port) { - struct list_head *node_db = &port->priv->node_db; struct hsr_prp_priv *priv = port->priv; struct hsr_prp_node *node; struct ethhdr *ethhdr; + struct prp_rct *rct; + bool san = false; u16 seq_out; if (!skb_mac_header_was_set(skb)) @@ -192,14 +212,25 @@ struct hsr_prp_node *hsr_prp_get_node(struct hsr_prp_port *port, ethhdr = (struct ethhdr *)skb_mac_header(skb); list_for_each_entry_rcu(node, node_db, mac_list) { - if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) + if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { + /* reset the san_a/san_b if got a sv frame from + * the node. + */ + hsr_prp_reset_san_flags(node, is_sup); return node; - if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) + } + if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { + /* reset the san_a/san_b if got a sv frame from + * the node. + */ + hsr_prp_reset_san_flags(node, is_sup); return node; + } } - /* Everyone may create a node entry, connected node to a HSR device. */ - + /* Everyone may create a node entry, connected node to a HSR/PRP + * device. + */ if (ethhdr->h_proto == htons(ETH_P_PRP) || ethhdr->h_proto == htons(ETH_P_HSR)) { /* Use the existing sequence_nr from the tag as starting point @@ -207,15 +238,18 @@ struct hsr_prp_node *hsr_prp_get_node(struct hsr_prp_port *port, */ seq_out = hsr_get_skb_sequence_nr(skb) - 1; } else { - /* this is called also for frames from master port and - * so warn only for non master ports - */ - if (port->type != HSR_PRP_PT_MASTER) - WARN_ONCE(1, "%s: Non-HSR frame\n", __func__); - seq_out = HSR_PRP_SEQNR_START; + rct = skb_get_PRP_rct(skb); + if (rct && prp_check_lsdu_size(skb, rct, is_sup)) { + seq_out = prp_get_skb_sequence_nr(rct); + } else { + if (rx_port != HSR_PRP_PT_MASTER) + san = true; + seq_out = HSR_PRP_SEQNR_START; + } } - return hsr_prp_add_node(priv, node_db, ethhdr->h_source, seq_out); + return hsr_prp_add_node(priv, node_db, ethhdr->h_source, seq_out, + san, rx_port); } /* Use the Supervision frame's info about an eventual macaddress_B for merging @@ -253,7 +287,8 @@ void hsr_prp_handle_sup_frame(struct sk_buff *skb, if (!node_real) /* No frame received from AddrA of this node yet */ node_real = hsr_prp_add_node(priv, node_db, sp->macaddress_A, - HSR_PRP_SEQNR_START - 1); + HSR_PRP_SEQNR_START - 1, true, + port_rcv->type); if (!node_real) goto done; /* No mem */ if (node_real == node_curr) diff --git a/net/hsr-prp/hsr_prp_framereg.h b/net/hsr-prp/hsr_prp_framereg.h index be52c55d9b6a..488823e8fecc 100644 --- a/net/hsr-prp/hsr_prp_framereg.h +++ b/net/hsr-prp/hsr_prp_framereg.h @@ -15,7 +15,10 @@ struct hsr_prp_node; void hsr_prp_del_self_node(struct hsr_prp_priv *priv); void hsr_prp_del_nodes(struct list_head *node_db); struct hsr_prp_node *hsr_prp_get_node(struct hsr_prp_port *port, - struct sk_buff *skb, bool is_sup); + struct list_head *node_db, + struct sk_buff *skb, + bool is_sup, + enum hsr_prp_port_type rx_port); void hsr_prp_handle_sup_frame(struct sk_buff *skb, struct hsr_prp_node *node_curr, struct hsr_prp_port *port); @@ -55,6 +58,9 @@ struct hsr_prp_node { enum hsr_prp_port_type addr_B_port; unsigned long time_in[HSR_PRP_PT_PORTS]; bool time_in_stale[HSR_PRP_PT_PORTS]; + /* if the node is a SAN */ + bool san_a; + bool san_b; u16 seq_out[HSR_PRP_PT_PORTS]; struct rcu_head rcu_head; }; diff --git a/net/hsr-prp/hsr_prp_main.h b/net/hsr-prp/hsr_prp_main.h index 17049d040226..0101c2669846 100644 --- a/net/hsr-prp/hsr_prp_main.h +++ b/net/hsr-prp/hsr_prp_main.h @@ -10,6 +10,7 @@ #include #include +#include /* Time constants as specified in the HSR specification (IEC-62439-3 2010) * Table 8. @@ -54,7 +55,7 @@ struct hsr_tag { #define HSR_PRP_HLEN 6 -#define HSR_V1_SUP_LSDUSIZE 52 +#define HSR_PRP_V1_SUP_LSDUSIZE 52 /* The helper functions below assumes that 'path' occupies the 4 most * significant bits of the 16-bit field shared by 'path' and 'LSDU_size' (or @@ -84,8 +85,13 @@ struct hsr_ethhdr { struct hsr_tag hsr_tag; } __packed; -/* HSR Supervision Frame data types. - * Field names as defined in the IEC:2010 standard for HSR. +struct hsr_vlan_ethhdr { + struct vlan_ethhdr vlanhdr; + struct hsr_tag hsr_tag; +} __packed; + +/* HSR/PRP Supervision Frame data types. + * Field names as defined in the IEC:2012 standard for HSR. */ struct hsr_prp_sup_tag { __be16 path_and_HSR_ver; @@ -141,6 +147,16 @@ struct prp_rct { __be16 PRP_suffix; } __packed; +static inline u16 get_prp_LSDU_size(struct prp_rct *rct) +{ + return ntohs(rct->lan_id_and_LSDU_size) & 0x0FFF; +} + +static inline void set_prp_lan_id(struct prp_rct *rct, u16 lan_id) +{ + rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) & + 0x0FFF) | (lan_id << 12)); +} static inline void set_prp_LSDU_size(struct prp_rct *rct, u16 LSDU_size) { rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) & @@ -172,6 +188,12 @@ struct hsr_prp_priv { #define HSR_V0 0 #define HSR_V1 1 #define PRP_V1 2 +#define PRP_LAN_ID 0x5 /* 0x1010 for A and 0x1011 for B. Bit 0 is set + * based on SLAVE_A or SLAVE_B + */ + u8 net_id; /* for PRP, it occupies most significant 3 bits + * of lan_id + */ unsigned char sup_multicast_addr[ETH_ALEN]; #ifdef CONFIG_DEBUG_FS struct dentry *node_tbl_root; @@ -189,10 +211,55 @@ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb) { struct hsr_ethhdr *hsr_ethhdr; + /* TODO will not work when vlan hdr is present */ hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb); + return ntohs(hsr_ethhdr->hsr_tag.sequence_nr); } +static inline struct prp_rct *skb_get_PRP_rct(struct sk_buff *skb) +{ + unsigned char *tail = skb_tail_pointer(skb) - HSR_PRP_HLEN; + + struct prp_rct *rct = (struct prp_rct *)tail; + + if (rct->PRP_suffix == htons(ETH_P_PRP)) + return rct; + + return NULL; +} + +/* Assume caller has confirmed this skb is PRP suffixed */ +static inline u16 prp_get_skb_sequence_nr(struct prp_rct *rct) +{ + return ntohs(rct->sequence_nr); +} + +static inline u16 get_prp_lan_id(struct prp_rct *rct) +{ + return ntohs(rct->lan_id_and_LSDU_size) >> 12; +} + +/* assume there is a valid rct */ +static inline bool prp_check_lsdu_size(struct sk_buff *skb, + struct prp_rct *rct, + bool is_sup) +{ + struct ethhdr *ethhdr; + int expected_lsdu_size; + + if (is_sup) { + expected_lsdu_size = HSR_PRP_V1_SUP_LSDUSIZE; + } else { + ethhdr = (struct ethhdr *)skb_mac_header(skb); + expected_lsdu_size = skb->len - 14; + if (ethhdr->h_proto == htons(ETH_P_8021Q)) + expected_lsdu_size -= 4; + } + + return (expected_lsdu_size == get_prp_LSDU_size(rct)); +} + #if IS_ENABLED(CONFIG_DEBUG_FS) void hsr_prp_debugfs_rename(struct net_device *dev); void hsr_prp_debugfs_init(struct hsr_prp_priv *priv, struct net_device *ndev); diff --git a/net/hsr-prp/hsr_prp_slave.c b/net/hsr-prp/hsr_prp_slave.c index 63a8dafa1f68..7c7559cd15ee 100644 --- a/net/hsr-prp/hsr_prp_slave.c +++ b/net/hsr-prp/hsr_prp_slave.c @@ -18,28 +18,50 @@ static rx_handler_result_t hsr_prp_handle_frame(struct sk_buff **pskb) { struct sk_buff *skb = *pskb; struct hsr_prp_port *port; + struct hsr_prp_priv *priv; __be16 protocol; - if (!skb_mac_header_was_set(skb)) { - WARN_ONCE(1, "%s: skb invalid", __func__); - return RX_HANDLER_PASS; - } - port = hsr_prp_port_get_rcu(skb->dev); if (!port) goto finish_pass; + priv = port->priv; - if (hsr_prp_addr_is_self(port->priv, eth_hdr(skb)->h_source)) { + if (!skb_mac_header_was_set(skb)) { + WARN_ONCE(1, "%s: skb invalid", __func__); + goto finish_pass; + } + + if (hsr_prp_addr_is_self(priv, eth_hdr(skb)->h_source)) { /* Directly kill frames sent by ourselves */ kfree_skb(skb); goto finish_consume; } + /* For HSR, non tagged frames are expected, but for PRP + * there could be non tagged frames as well. + */ protocol = eth_hdr(skb)->h_proto; - if (protocol != htons(ETH_P_PRP) && protocol != htons(ETH_P_HSR)) + if (protocol != htons(ETH_P_PRP) && + protocol != htons(ETH_P_HSR) && + port->priv->prot_version <= HSR_V1) goto finish_pass; - skb_push(skb, ETH_HLEN); + /* Frame is a HSR or PRP frame or frame form a SAN. For + * PRP, only supervisor frame will have a PRP protocol. + */ + if (protocol == htons(ETH_P_HSR) || protocol == htons(ETH_P_PRP)) + skb_push(skb, ETH_HLEN); + + /* Not sure why we have to do this as some frames + * don't have the skb->data pointing to mac header for PRP case + */ + if (skb_mac_header(skb) != skb->data) { + skb_push(skb, ETH_HLEN); + + /* do one more check and bail out */ + if (skb_mac_header(skb) != skb->data) + goto finish_consume; + } hsr_prp_forward_skb(skb, port);