All of lore.kernel.org
 help / color / mirror / Atom feed
* [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
@ 2020-05-06 16:30 Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 01/13] net: hsr: Re-use Kconfig option to support PRP Murali Karicheri
                   ` (14 more replies)
  0 siblings, 15 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

This RFC series add support for Parallel Redundancy Protocol (PRP)
as defined in IEC-62439-3 in the kernel networking subsystem. PRP 
Uses a Redundancy Control Trailer (RCT) the format of which is
similar to HSR Tag. This is used for implementing redundancy.
RCT consists of 6 bytes similar to HSR tag and contain following
fields:-

- 16-bit sequence number (SeqNr);
- 4-bit LAN identifier (LanId);
- 12 bit frame size (LSDUsize);
- 16-bit suffix (PRPsuffix). 

The PRPsuffix identifies PRP frames and distinguishes PRP frames
from other protocols that also append a trailer to their useful
data. The LSDUsize field allows the receiver to distinguish PRP
frames from random, nonredundant frames as an additional check.
LSDUsize is the size of the Ethernet payload inclusive of the
RCT. Sequence number along with LanId is used for duplicate
detection and discard.

PRP node is also known as Dual Attached Node (DAN-P) since it
is typically attached to two different LAN for redundancy.
DAN-P duplicates each of L2 frames and send it over the two
Ethernet links. Each outgoing frame is appended with RCT.
Unlike HSR, these are added to the end of L2 frame and may be
treated as padding by bridges and therefore would be work with
traditional bridges or switches, where as HSR wouldn't as Tag
is prefixed to the Ethenet frame. At the remote end, these are
received and the duplicate frame is discarded before the stripped
frame is send up the networking stack. Like HSR, PRP also sends
periodic Supervision frames to the network. These frames are
received and MAC address from the SV frames are populated in a
database called Node Table. The above functions are grouped into
a block called Link Redundancy Entity (LRE) in the IEC spec.

As there are many similarities between HSR and PRP protocols,
this patch re-use the code from HSR driver to implement PRP
driver. As many part of the code can be re-used, this patch
introduces a new common API definitions for both protocols and
propose to obsolete the existing HSR defines in
include/uapi/linux/if_link.h. New definitions are prefixed 
with a HSR_PRP prefix. Similarly include/uapi/linux/hsr_netlink.h
is proposed to be replaced with include/uapi/linux/hsr_prp_netlink.h
which also uses the HSR_PRP prefix. The netlink socket interface
code is migrated (as well as the iproute2 being sent as a follow up
patch) to use the new API definitions. To re-use the code,
following are done as a preparatory patch before adding the PRP
functionality:-

  - prefix all common code with hsr_prp
  - net/hsr -> renamed to net/hsr-prp
  - All common struct types, constants, functions renamed with
    hsr{HSR}_prp{PRP} prefix.

Please review this and provide me feedback so that I can work to
incorporate them and send a formal patch series for this. As this
series impacts user space, I am not sure if this is the right
approach to introduce a new definitions and obsolete the old
API definitions for HSR. The current approach is choosen
to avoid redundant code in iproute2 and in the netlink driver
code (hsr_netlink.c). Other approach we discussed internally was
to Keep the HSR prefix in the user space and kernel code, but
live with the redundant code in the iproute2 and hsr netlink
code. Would like to hear from you what is the best way to add
this feature to networking core. If there is any other
alternative approach possible, I would like to hear about the
same.

The patch was tested using two TI AM57x IDK boards which are
connected back to back over two CPSW ports. 

Script used for creating the hsr/prp interface is given below
and uses the ip link command. Also provided logs from the tests
I have executed for your reference. 

iproute2 related patches will follow soon....

Murali Karicheri
Texas Instruments

============ setup.sh =================================================
#!/bin/sh
if [ $# -lt 4 ]
then
       echo "setup-cpsw.sh <hsr/prp> <MAC-Address of slave-A>"
       echo "  <ip address for hsr/prp interface>"
       echo "  <if_name of hsr/prp interface>"
       exit
fi

if [ "$1" != "hsr" ] && [ "$1" != "prp" ]
then
       echo "use hsr or prp as first argument"
       exit
fi

if_a=eth2
if_b=eth3
if_name=$4

ifconfig $if_a down
ifconfig $if_b down
ifconfig $if_a hw ether $2
ifconfig $if_b hw ether $2
ifconfig $if_a up
ifconfig $if_b up

echo "Setting up $if_name with MAC address $2 for slaves and IP address $3"
echo "          using $if_a and $if_b"

if [ "$1" = "hsr" ]; then
       options="version 1"
else
       options=""
fi

ip link add name $if_name type $1 slave1 $if_a slave2 $if_b supervision 0 $options
ifconfig $if_name $3 up
==================================================================================
PRP Logs:

DUT-1 : https://pastebin.ubuntu.com/p/hhsRjTQpcr/
DUT-2 : https://pastebin.ubuntu.com/p/snPFKhnpk4/

HSR Logs:

DUT-1 : https://pastebin.ubuntu.com/p/FZPNc6Nwdm/
DUT-2 : https://pastebin.ubuntu.com/p/CtV4ZVS3Yd/

Murali Karicheri (13):
  net: hsr: Re-use Kconfig option to support PRP
  net: hsr: rename hsr directory to hsr-prp to introduce PRP
  net: hsr: rename files to introduce PRP support
  net: hsr: rename hsr variable inside struct hsr_port to priv
  net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port()
  net: hsr: some renaming to introduce PRP driver support
  net: hsr: introduce common uapi include/definitions for HSR and PRP
  net: hsr: migrate HSR netlink socket code to use new common API
  net: hsr: move re-usable code for PRP to hsr_prp_netlink.c
  net: hsr: add netlink socket interface for PRP
  net: prp: add supervision frame generation and handling support
  net: prp: add packet handling support
  net: prp: enhance debugfs to display PRP specific info in node table

 MAINTAINERS                                   |   2 +-
 include/uapi/linux/hsr_netlink.h              |   3 +
 include/uapi/linux/hsr_prp_netlink.h          |  50 ++
 include/uapi/linux/if_link.h                  |  19 +
 net/Kconfig                                   |   2 +-
 net/Makefile                                  |   2 +-
 net/hsr-prp/Kconfig                           |  37 ++
 net/hsr-prp/Makefile                          |  11 +
 net/hsr-prp/hsr_netlink.c                     | 202 +++++++
 net/{hsr => hsr-prp}/hsr_netlink.h            |  15 +-
 .../hsr_prp_debugfs.c}                        |  82 +--
 net/hsr-prp/hsr_prp_device.c                  | 562 ++++++++++++++++++
 net/hsr-prp/hsr_prp_device.h                  |  23 +
 net/hsr-prp/hsr_prp_forward.c                 | 558 +++++++++++++++++
 .../hsr_prp_forward.h}                        |  10 +-
 .../hsr_prp_framereg.c}                       | 323 +++++-----
 net/hsr-prp/hsr_prp_framereg.h                |  68 +++
 net/hsr-prp/hsr_prp_main.c                    | 194 ++++++
 net/hsr-prp/hsr_prp_main.h                    | 289 +++++++++
 net/hsr-prp/hsr_prp_netlink.c                 | 365 ++++++++++++
 net/hsr-prp/hsr_prp_netlink.h                 |  28 +
 net/hsr-prp/hsr_prp_slave.c                   | 222 +++++++
 net/hsr-prp/hsr_prp_slave.h                   |  37 ++
 net/hsr-prp/prp_netlink.c                     | 141 +++++
 net/hsr-prp/prp_netlink.h                     |  27 +
 net/hsr/Kconfig                               |  29 -
 net/hsr/Makefile                              |  10 -
 net/hsr/hsr_device.c                          | 509 ----------------
 net/hsr/hsr_device.h                          |  22 -
 net/hsr/hsr_forward.c                         | 379 ------------
 net/hsr/hsr_framereg.h                        |  62 --
 net/hsr/hsr_main.c                            | 154 -----
 net/hsr/hsr_main.h                            | 188 ------
 net/hsr/hsr_netlink.c                         | 514 ----------------
 net/hsr/hsr_slave.c                           | 198 ------
 net/hsr/hsr_slave.h                           |  33 -
 36 files changed, 3084 insertions(+), 2286 deletions(-)
 create mode 100644 include/uapi/linux/hsr_prp_netlink.h
 create mode 100644 net/hsr-prp/Kconfig
 create mode 100644 net/hsr-prp/Makefile
 create mode 100644 net/hsr-prp/hsr_netlink.c
 rename net/{hsr => hsr-prp}/hsr_netlink.h (58%)
 rename net/{hsr/hsr_debugfs.c => hsr-prp/hsr_prp_debugfs.c} (52%)
 create mode 100644 net/hsr-prp/hsr_prp_device.c
 create mode 100644 net/hsr-prp/hsr_prp_device.h
 create mode 100644 net/hsr-prp/hsr_prp_forward.c
 rename net/{hsr/hsr_forward.h => hsr-prp/hsr_prp_forward.h} (50%)
 rename net/{hsr/hsr_framereg.c => hsr-prp/hsr_prp_framereg.c} (56%)
 create mode 100644 net/hsr-prp/hsr_prp_framereg.h
 create mode 100644 net/hsr-prp/hsr_prp_main.c
 create mode 100644 net/hsr-prp/hsr_prp_main.h
 create mode 100644 net/hsr-prp/hsr_prp_netlink.c
 create mode 100644 net/hsr-prp/hsr_prp_netlink.h
 create mode 100644 net/hsr-prp/hsr_prp_slave.c
 create mode 100644 net/hsr-prp/hsr_prp_slave.h
 create mode 100644 net/hsr-prp/prp_netlink.c
 create mode 100644 net/hsr-prp/prp_netlink.h
 delete mode 100644 net/hsr/Kconfig
 delete mode 100644 net/hsr/Makefile
 delete mode 100644 net/hsr/hsr_device.c
 delete mode 100644 net/hsr/hsr_device.h
 delete mode 100644 net/hsr/hsr_forward.c
 delete mode 100644 net/hsr/hsr_framereg.h
 delete mode 100644 net/hsr/hsr_main.c
 delete mode 100644 net/hsr/hsr_main.h
 delete mode 100644 net/hsr/hsr_netlink.c
 delete mode 100644 net/hsr/hsr_slave.c
 delete mode 100644 net/hsr/hsr_slave.h

-- 
2.17.1


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 01/13] net: hsr: Re-use Kconfig option to support PRP
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 02/13] net: hsr: rename hsr directory to hsr-prp to introduce PRP Murali Karicheri
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

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 <m-karicheri2@ti.com>
---
 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
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 02/13] net: hsr: rename hsr directory to hsr-prp to introduce PRP
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 01/13] net: hsr: Re-use Kconfig option to support PRP Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 03/13] net: hsr: rename files to introduce PRP support Murali Karicheri
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

As prp driver is expected to re-use code from HSR driver,
rename the directory to net/hsr-prp as a preparatory step.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 MAINTAINERS                         | 2 +-
 net/Kconfig                         | 2 +-
 net/Makefile                        | 2 +-
 net/{hsr => hsr-prp}/Kconfig        | 0
 net/{hsr => hsr-prp}/Makefile       | 0
 net/{hsr => hsr-prp}/hsr_debugfs.c  | 0
 net/{hsr => hsr-prp}/hsr_device.c   | 0
 net/{hsr => hsr-prp}/hsr_device.h   | 0
 net/{hsr => hsr-prp}/hsr_forward.c  | 0
 net/{hsr => hsr-prp}/hsr_forward.h  | 0
 net/{hsr => hsr-prp}/hsr_framereg.c | 0
 net/{hsr => hsr-prp}/hsr_framereg.h | 0
 net/{hsr => hsr-prp}/hsr_main.c     | 0
 net/{hsr => hsr-prp}/hsr_main.h     | 0
 net/{hsr => hsr-prp}/hsr_netlink.c  | 0
 net/{hsr => hsr-prp}/hsr_netlink.h  | 0
 net/{hsr => hsr-prp}/hsr_slave.c    | 0
 net/{hsr => hsr-prp}/hsr_slave.h    | 0
 18 files changed, 3 insertions(+), 3 deletions(-)
 rename net/{hsr => hsr-prp}/Kconfig (100%)
 rename net/{hsr => hsr-prp}/Makefile (100%)
 rename net/{hsr => hsr-prp}/hsr_debugfs.c (100%)
 rename net/{hsr => hsr-prp}/hsr_device.c (100%)
 rename net/{hsr => hsr-prp}/hsr_device.h (100%)
 rename net/{hsr => hsr-prp}/hsr_forward.c (100%)
 rename net/{hsr => hsr-prp}/hsr_forward.h (100%)
 rename net/{hsr => hsr-prp}/hsr_framereg.c (100%)
 rename net/{hsr => hsr-prp}/hsr_framereg.h (100%)
 rename net/{hsr => hsr-prp}/hsr_main.c (100%)
 rename net/{hsr => hsr-prp}/hsr_main.h (100%)
 rename net/{hsr => hsr-prp}/hsr_netlink.c (100%)
 rename net/{hsr => hsr-prp}/hsr_netlink.h (100%)
 rename net/{hsr => hsr-prp}/hsr_slave.c (100%)
 rename net/{hsr => hsr-prp}/hsr_slave.h (100%)

diff --git a/MAINTAINERS b/MAINTAINERS
index db7a6d462dff..94d357145f81 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7789,7 +7789,7 @@ F:	drivers/net/usb/hso.c
 HSR NETWORK PROTOCOL
 L:	netdev@vger.kernel.org
 S:	Orphan
-F:	net/hsr/
+F:	net/hsr-prp/
 
 HT16K33 LED CONTROLLER DRIVER
 M:	Robin van der Gracht <robin@protonic.nl>
diff --git a/net/Kconfig b/net/Kconfig
index c5ba2d180c43..20216973d25f 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -239,7 +239,7 @@ source "net/vmw_vsock/Kconfig"
 source "net/netlink/Kconfig"
 source "net/mpls/Kconfig"
 source "net/nsh/Kconfig"
-source "net/hsr/Kconfig"
+source "net/hsr-prp/Kconfig"
 source "net/switchdev/Kconfig"
 source "net/l3mdev/Kconfig"
 source "net/qrtr/Kconfig"
diff --git a/net/Makefile b/net/Makefile
index 4f1c6a44f2c3..cab7e4071f42 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_PRP)		+= hsr/
+obj-$(CONFIG_HSR_PRP)		+= hsr-prp/
 ifneq ($(CONFIG_NET_SWITCHDEV),)
 obj-y				+= switchdev/
 endif
diff --git a/net/hsr/Kconfig b/net/hsr-prp/Kconfig
similarity index 100%
rename from net/hsr/Kconfig
rename to net/hsr-prp/Kconfig
diff --git a/net/hsr/Makefile b/net/hsr-prp/Makefile
similarity index 100%
rename from net/hsr/Makefile
rename to net/hsr-prp/Makefile
diff --git a/net/hsr/hsr_debugfs.c b/net/hsr-prp/hsr_debugfs.c
similarity index 100%
rename from net/hsr/hsr_debugfs.c
rename to net/hsr-prp/hsr_debugfs.c
diff --git a/net/hsr/hsr_device.c b/net/hsr-prp/hsr_device.c
similarity index 100%
rename from net/hsr/hsr_device.c
rename to net/hsr-prp/hsr_device.c
diff --git a/net/hsr/hsr_device.h b/net/hsr-prp/hsr_device.h
similarity index 100%
rename from net/hsr/hsr_device.h
rename to net/hsr-prp/hsr_device.h
diff --git a/net/hsr/hsr_forward.c b/net/hsr-prp/hsr_forward.c
similarity index 100%
rename from net/hsr/hsr_forward.c
rename to net/hsr-prp/hsr_forward.c
diff --git a/net/hsr/hsr_forward.h b/net/hsr-prp/hsr_forward.h
similarity index 100%
rename from net/hsr/hsr_forward.h
rename to net/hsr-prp/hsr_forward.h
diff --git a/net/hsr/hsr_framereg.c b/net/hsr-prp/hsr_framereg.c
similarity index 100%
rename from net/hsr/hsr_framereg.c
rename to net/hsr-prp/hsr_framereg.c
diff --git a/net/hsr/hsr_framereg.h b/net/hsr-prp/hsr_framereg.h
similarity index 100%
rename from net/hsr/hsr_framereg.h
rename to net/hsr-prp/hsr_framereg.h
diff --git a/net/hsr/hsr_main.c b/net/hsr-prp/hsr_main.c
similarity index 100%
rename from net/hsr/hsr_main.c
rename to net/hsr-prp/hsr_main.c
diff --git a/net/hsr/hsr_main.h b/net/hsr-prp/hsr_main.h
similarity index 100%
rename from net/hsr/hsr_main.h
rename to net/hsr-prp/hsr_main.h
diff --git a/net/hsr/hsr_netlink.c b/net/hsr-prp/hsr_netlink.c
similarity index 100%
rename from net/hsr/hsr_netlink.c
rename to net/hsr-prp/hsr_netlink.c
diff --git a/net/hsr/hsr_netlink.h b/net/hsr-prp/hsr_netlink.h
similarity index 100%
rename from net/hsr/hsr_netlink.h
rename to net/hsr-prp/hsr_netlink.h
diff --git a/net/hsr/hsr_slave.c b/net/hsr-prp/hsr_slave.c
similarity index 100%
rename from net/hsr/hsr_slave.c
rename to net/hsr-prp/hsr_slave.c
diff --git a/net/hsr/hsr_slave.h b/net/hsr-prp/hsr_slave.h
similarity index 100%
rename from net/hsr/hsr_slave.h
rename to net/hsr-prp/hsr_slave.h
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 03/13] net: hsr: rename files to introduce PRP support
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 01/13] net: hsr: Re-use Kconfig option to support PRP Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 02/13] net: hsr: rename hsr directory to hsr-prp to introduce PRP Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 04/13] net: hsr: rename hsr variable inside struct hsr_port to priv Murali Karicheri
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

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 <m-karicheri2@ti.com>
---
 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 <linux/kernel.h>
 #include <net/rtnetlink.h>
 #include <net/genetlink.h>
-#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 <linux/module.h>
 #include <linux/errno.h>
 #include <linux/debugfs.h>
-#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 <linux/etherdevice.h>
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
-#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 <linux/netdevice.h>
-#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 <linux/types.h>
 #include <linux/skbuff.h>
 #include <linux/etherdevice.h>
 #include <linux/if_vlan.h>
-#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 <linux/netdevice.h>
-#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 <linux/etherdevice.h>
 #include <linux/slab.h>
 #include <linux/rculist.h>
-#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 <linux/rculist.h>
 #include <linux/timer.h>
 #include <linux/etherdevice.h>
-#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 <linux/etherdevice.h>
 #include <linux/if_arp.h>
 #include <linux/if_vlan.h>
-#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 <linux/skbuff.h>
 #include <linux/netdevice.h>
 #include <linux/rtnetlink.h>
-#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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 04/13] net: hsr: rename hsr variable inside struct hsr_port to priv
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (2 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 03/13] net: hsr: rename files to introduce PRP support Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 05/13] net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port() Murali Karicheri
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

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 <m-karicheri2@ti.com>
---
 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 <linux/rtnetlink.h>
 #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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 05/13] net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port()
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (3 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 04/13] net: hsr: rename hsr variable inside struct hsr_port to priv Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 06/13] net: hsr: some renaming to introduce PRP driver support Murali Karicheri
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

hsr_port_get_hsr() actually gets port struct ptr from the priv. So
rename it to reflect the same. hsr_prp prefix is chosen as this
can be re-used for PRP driver as well.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 net/hsr-prp/hsr_netlink.c      | 12 ++++++------
 net/hsr-prp/hsr_prp_device.c   | 14 +++++++-------
 net/hsr-prp/hsr_prp_framereg.c | 10 +++++-----
 net/hsr-prp/hsr_prp_main.c     | 12 ++++++------
 net/hsr-prp/hsr_prp_main.h     |  2 +-
 net/hsr-prp/hsr_prp_slave.c    |  8 ++++----
 6 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/net/hsr-prp/hsr_netlink.c b/net/hsr-prp/hsr_netlink.c
index 9e3f6eda69f5..727b5dc9f31b 100644
--- a/net/hsr-prp/hsr_netlink.c
+++ b/net/hsr-prp/hsr_netlink.c
@@ -88,13 +88,13 @@ 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;
 
-	port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_A);
+	port = hsr_prp_get_port(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(priv, HSR_PT_SLAVE_B);
+	port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B);
 	if (port) {
 		if (nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex))
 			goto nla_put_failure;
@@ -177,7 +177,7 @@ void hsr_nl_ringerror(struct hsr_priv *priv, unsigned char addr[ETH_ALEN],
 
 fail:
 	rcu_read_lock();
-	master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	netdev_warn(master->dev, "Could not send HSR ring error message\n");
 	rcu_read_unlock();
 }
@@ -214,7 +214,7 @@ void hsr_nl_nodedown(struct hsr_priv *priv, unsigned char addr[ETH_ALEN])
 
 fail:
 	rcu_read_lock();
-	master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	netdev_warn(master->dev, "Could not send HSR node down\n");
 	rcu_read_unlock();
 }
@@ -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(priv, HSR_PT_SLAVE_A);
+	port = hsr_prp_get_port(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(priv, HSR_PT_SLAVE_B);
+	port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B);
 	if (port)
 		res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX,
 				  port->dev->ifindex);
diff --git a/net/hsr-prp/hsr_prp_device.c b/net/hsr-prp/hsr_prp_device.c
index df85b8f7f007..d8bc9a48b6f2 100644
--- a/net/hsr-prp/hsr_prp_device.c
+++ b/net/hsr-prp/hsr_prp_device.c
@@ -97,7 +97,7 @@ void hsr_check_carrier_and_operstate(struct hsr_priv *priv)
 	unsigned char old_operstate;
 	bool has_carrier;
 
-	master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	/* netif_stacked_transfer_operstate() cannot be used here since
 	 * it doesn't set IF_OPER_LOWERLAYERDOWN (?)
 	 */
@@ -215,7 +215,7 @@ static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 	struct hsr_priv *priv = netdev_priv(dev);
 	struct hsr_port *master;
 
-	master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	if (master) {
 		skb->dev = master->dev;
 		hsr_forward_skb(skb, master);
@@ -318,7 +318,7 @@ static void hsr_announce(struct timer_list *t)
 	priv = from_timer(priv, t, announce_timer);
 
 	rcu_read_lock();
-	master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 
 	if (priv->announce_count < 3 && priv->prot_version == 0) {
 		send_hsr_supervision_frame(master, HSR_TLV_ANNOUNCE,
@@ -343,22 +343,22 @@ static void hsr_del_ports(struct hsr_priv *priv)
 {
 	struct hsr_port *port;
 
-	port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_A);
+	port = hsr_prp_get_port(priv, HSR_PT_SLAVE_A);
 	if (port)
 		hsr_del_port(port);
 
-	port = hsr_port_get_hsr(priv, HSR_PT_SLAVE_B);
+	port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B);
 	if (port)
 		hsr_del_port(port);
 
-	port = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	port = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	if (port)
 		hsr_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_port_get_hsr().
+ * hsr_prp_get_port().
  */
 static void hsr_dev_destroy(struct net_device *hsr_dev)
 {
diff --git a/net/hsr-prp/hsr_prp_framereg.c b/net/hsr-prp/hsr_prp_framereg.c
index 854338352e93..102b0a85f440 100644
--- a/net/hsr-prp/hsr_prp_framereg.c
+++ b/net/hsr-prp/hsr_prp_framereg.c
@@ -364,18 +364,18 @@ 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(priv, 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_port_get_hsr(priv, 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_port_get_hsr(priv, HSR_PT_SLAVE_A);
+		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_port_get_hsr(priv, HSR_PT_SLAVE_B);
+		return hsr_prp_get_port(priv, HSR_PT_SLAVE_B);
 
 	return NULL;
 }
@@ -515,7 +515,7 @@ int hsr_get_node_data(struct hsr_priv *priv,
 	*if2_seq = node->seq_out[HSR_PT_SLAVE_A];
 
 	if (node->addr_B_port != HSR_PT_NONE) {
-		port = hsr_port_get_hsr(priv, node->addr_B_port);
+		port = hsr_prp_get_port(priv, node->addr_B_port);
 		*addr_b_ifindex = port->dev->ifindex;
 	} else {
 		*addr_b_ifindex = -1;
diff --git a/net/hsr-prp/hsr_prp_main.c b/net/hsr-prp/hsr_prp_main.c
index caa544d0af42..de85f42be6ee 100644
--- a/net/hsr-prp/hsr_prp_main.c
+++ b/net/hsr-prp/hsr_prp_main.c
@@ -41,7 +41,7 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
 		if (!is_hsr_master(dev))
 			return NOTIFY_DONE;	/* Not an HSR device */
 		priv = netdev_priv(dev);
-		port = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+		port = hsr_prp_get_port(priv, HSR_PT_MASTER);
 		if (!port) {
 			/* Resend of notification concerning removed device? */
 			return NOTIFY_DONE;
@@ -69,7 +69,7 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
 			break;
 		}
 
-		master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+		master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 
 		if (port->type == HSR_PT_SLAVE_A) {
 			ether_addr_copy(master->dev->dev_addr, dev->dev_addr);
@@ -78,7 +78,7 @@ 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(priv, HSR_PT_SLAVE_B);
+		port = hsr_prp_get_port(priv, HSR_PT_SLAVE_B);
 		res = hsr_create_self_node(priv,
 					   master->dev->dev_addr,
 					   port ?
@@ -92,12 +92,12 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
 		if (port->type == HSR_PT_MASTER)
 			break; /* Handled in ndo_change_mtu() */
 		mtu_max = hsr_get_max_mtu(port->priv);
-		master = hsr_port_get_hsr(port->priv, HSR_PT_MASTER);
+		master = hsr_prp_get_port(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->priv, HSR_PT_MASTER);
+			master = hsr_prp_get_port(port->priv, HSR_PT_MASTER);
 			hsr_del_port(port);
 			if (hsr_slave_empty(master->priv)) {
 				unregister_netdevice_queue(master->dev,
@@ -116,7 +116,7 @@ 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 *priv, enum hsr_port_type pt)
+struct hsr_port *hsr_prp_get_port(struct hsr_priv *priv, enum hsr_port_type pt)
 {
 	struct hsr_port *port;
 
diff --git a/net/hsr-prp/hsr_prp_main.h b/net/hsr-prp/hsr_prp_main.h
index d11a9f0b696f..5a99d0b12c66 100644
--- a/net/hsr-prp/hsr_prp_main.h
+++ b/net/hsr-prp/hsr_prp_main.h
@@ -153,7 +153,7 @@ struct hsr_priv {
 #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 *priv, enum hsr_port_type pt);
+struct hsr_port *hsr_prp_get_port(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 96de8d15db00..2c8832bf7a5f 100644
--- a/net/hsr-prp/hsr_prp_slave.c
+++ b/net/hsr-prp/hsr_prp_slave.c
@@ -110,7 +110,7 @@ static int hsr_portdev_setup(struct hsr_priv *priv, struct net_device *dev,
 	if (res)
 		return res;
 
-	master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	hsr_dev = master->dev;
 
 	res = netdev_upper_dev_link(dev, hsr_dev, extack);
@@ -143,7 +143,7 @@ int hsr_add_port(struct hsr_priv *priv, struct net_device *dev,
 			return res;
 	}
 
-	port = hsr_port_get_hsr(priv, type);
+	port = hsr_prp_get_port(priv, type);
 	if (port)
 		return -EBUSY;	/* This port already exists */
 
@@ -164,7 +164,7 @@ 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_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	netdev_update_features(master->dev);
 	dev_set_mtu(master->dev, hsr_get_max_mtu(priv));
 
@@ -181,7 +181,7 @@ void hsr_del_port(struct hsr_port *port)
 	struct hsr_port *master;
 
 	priv = port->priv;
-	master = hsr_port_get_hsr(priv, HSR_PT_MASTER);
+	master = hsr_prp_get_port(priv, HSR_PT_MASTER);
 	list_del_rcu(&port->port_list);
 
 	if (port != master) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 06/13] net: hsr: some renaming to introduce PRP driver support
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (4 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 05/13] net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port() Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 07/13] net: hsr: introduce common uapi include/definitions for HSR and PRP Murali Karicheri
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

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 <m-karicheri2@ti.com>
---
 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 <linux/module.h>
 #include <uapi/linux/hsr_netlink.h>
 
-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 <linux/netdevice.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],
-		     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 <linux/netdevice.h>
 #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 <linux/netdevice.h>
 #include <linux/list.h>
@@ -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 <linux/skbuff.h>
 #include <linux/netdevice.h>
 #include <linux/rtnetlink.h>
 #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 */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 07/13] net: hsr: introduce common uapi include/definitions for HSR and PRP
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (5 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 06/13] net: hsr: some renaming to introduce PRP driver support Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 08/13] net: hsr: migrate HSR netlink socket code to use new common API Murali Karicheri
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

There are many commonalities between HSR and PRP protocols except for
the fact that HSR uses Tag as a prefix vs RCT (Redundancy Control Trail)
as a trailer for PRP. Few of the commonalities to name are:- both uses
a pair of Ethernet interfaces, can be set up the same way from user
space using ip link command, Same Multicast MAC address for Supervision
frames, similar mechanism for redundancy, duplicate and discard using
tag/rct etc. So this patch introduces a common user space API in
if_link.h with a HSR_PRP prefix and common hsr_prp_netlink.h for
protocol specific interface configuration.  It is assumed that the old
definitions and include file for HSR may be obsoleted at some time
future (TBD) once all applications migrate to the new API.
IFLA_HSR_PRP_SUPERVISION_ADDR is the MC address for Supervision Frames
(SF), so use the name IFLA_HSR_PRP_SF_MC_ADDR instead to make it shorter
and also change IFLA_HSR_PRP_MULTICAST_SPEC to
IFLA_HSR_PRP_SF_MC_ADDR_LSB as it is the last byte of the MC address
used by Supervision frames.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 include/uapi/linux/hsr_netlink.h     |  3 ++
 include/uapi/linux/hsr_prp_netlink.h | 50 ++++++++++++++++++++++++++++
 include/uapi/linux/if_link.h         | 19 +++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 include/uapi/linux/hsr_prp_netlink.h

diff --git a/include/uapi/linux/hsr_netlink.h b/include/uapi/linux/hsr_netlink.h
index c218ef9c35dd..54650ffca2be 100644
--- a/include/uapi/linux/hsr_netlink.h
+++ b/include/uapi/linux/hsr_netlink.h
@@ -14,6 +14,9 @@
 #ifndef __UAPI_HSR_NETLINK_H
 #define __UAPI_HSR_NETLINK_H
 
+/* This file will become obsolete soon!!! Start using hsr_prp_netlink.h
+ * instead
+ */
 /* Generic Netlink HSR family definition
  */
 
diff --git a/include/uapi/linux/hsr_prp_netlink.h b/include/uapi/linux/hsr_prp_netlink.h
new file mode 100644
index 000000000000..17865cf14432
--- /dev/null
+++ b/include/uapi/linux/hsr_prp_netlink.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* prp_prp_netlink.h: This is based on hsr_netlink.h from Arvid Brodin,
+ * arvid.brodin@alten.se
+ *
+ * Copyright 2011-2014 Autronica Fire and Security AS
+ * Copyright (C) 2020 Texas Instruments Incorporated
+ *
+ * Author(s):
+ *	2011-2014 Arvid Brodin, arvid.brodin@alten.se
+ *	2020 Murali Karicheri <m-karicheri2@ti.com>
+ */
+
+#ifndef __UAPI_HSR_PRP_NETLINK_H
+#define __UAPI_HSR_PRP_NETLINK_H
+
+/* Generic Netlink HSR/PRP family definition
+ */
+
+/* attributes */
+enum {
+	HSR_PRP_A_UNSPEC,
+	HSR_PRP_A_NODE_ADDR,
+	HSR_PRP_A_IFINDEX,
+	HSR_PRP_A_IF1_AGE,
+	HSR_PRP_A_IF2_AGE,
+	HSR_PRP_A_NODE_ADDR_B,
+	HSR_PRP_A_IF1_SEQ,
+	HSR_PRP_A_IF2_SEQ,
+	HSR_PRP_A_IF1_IFINDEX,
+	HSR_PRP_A_IF2_IFINDEX,
+	HSR_PRP_A_ADDR_B_IFINDEX,
+	__HSR_PRP_A_MAX,
+};
+#define HSR_PRP_A_MAX (__HSR_PRP_A_MAX - 1)
+
+
+/* commands */
+enum {
+	HSR_PRP_C_UNSPEC,
+	HSR_PRP_C_RING_ERROR, /* only for HSR for now */
+	HSR_PRP_C_NODE_DOWN,
+	HSR_PRP_C_GET_NODE_STATUS,
+	HSR_PRP_C_SET_NODE_STATUS,
+	HSR_PRP_C_GET_NODE_LIST,
+	HSR_PRP_C_SET_NODE_LIST,
+	__HSR_PRP_C_MAX,
+};
+#define HSR_PRP_C_MAX (__HSR_PRP_C_MAX - 1)
+
+#endif /* __UAPI_HSR_PRP_NETLINK_H */
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index a009365ad67b..520537f35dcb 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -906,6 +906,8 @@ enum {
 #define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1)
 
 
+/* Will become obsolete soon!!!  Replaced with IFLA_HSR_PRP* prefix below */
+
 /* HSR section */
 
 enum {
@@ -1055,4 +1057,21 @@ struct ifla_rmnet_flags {
 	__u32	mask;
 };
 
+/* New definitions below to replace the HSR_ prefixed ones for HSR and PRP.
+ * It is expected to migrate all applications to this and obsolete the
+ * HSR specific definitions used currently.
+ */
+enum {
+	IFLA_HSR_PRP_UNSPEC,
+	IFLA_HSR_PRP_SLAVE1,
+	IFLA_HSR_PRP_SLAVE2,
+	IFLA_HSR_PRP_SF_MC_ADDR_LSB,  /* Last byte of supervision addr */
+	IFLA_HSR_PRP_SF_MC_ADDR,      /* Supervision frame multicast addr */
+	IFLA_HSR_PRP_SEQ_NR,
+	IFLA_HSR_PRP_VERSION,		/* HSR version */
+	__IFLA_HSR_PRP_MAX,
+};
+
+#define IFLA_HSR_PRP_MAX (__IFLA_HSR_PRP_MAX - 1)
+
 #endif /* _UAPI_LINUX_IF_LINK_H */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 08/13] net: hsr: migrate HSR netlink socket code to use new common API
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (6 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 07/13] net: hsr: introduce common uapi include/definitions for HSR and PRP Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 09/13] net: hsr: move re-usable code for PRP to hsr_prp_netlink.c Murali Karicheri
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

Migrate the existing netlink socket code to the use the new common API.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 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 <linux/if_ether.h>
 #include <linux/module.h>
-#include <uapi/linux/hsr_netlink.h>
+#include <uapi/linux/hsr_prp_netlink.h>
 
 struct hsr_prp_priv;
 struct hsr_prp_port;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 09/13] net: hsr: move re-usable code for PRP to hsr_prp_netlink.c
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (7 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 08/13] net: hsr: migrate HSR netlink socket code to use new common API Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 10/13] net: hsr: add netlink socket interface for PRP Murali Karicheri
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

Before introducing PRP netlink code, move the re-usable code to a
common hsr_prp_netlink.c.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 net/hsr-prp/Makefile          |   2 +-
 net/hsr-prp/hsr_netlink.c     | 337 +------------------------------
 net/hsr-prp/hsr_prp_netlink.c | 367 ++++++++++++++++++++++++++++++++++
 net/hsr-prp/hsr_prp_netlink.h |  27 +++
 4 files changed, 402 insertions(+), 331 deletions(-)
 create mode 100644 net/hsr-prp/hsr_prp_netlink.c
 create mode 100644 net/hsr-prp/hsr_prp_netlink.h

diff --git a/net/hsr-prp/Makefile b/net/hsr-prp/Makefile
index 608045f088a4..76f266cd1976 100644
--- a/net/hsr-prp/Makefile
+++ b/net/hsr-prp/Makefile
@@ -7,5 +7,5 @@ obj-$(CONFIG_HSR_PRP)	+= hsr-prp.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_forward.o hsr_prp_netlink.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 1f7c3be8d96e..6bdb369ced36 100644
--- a/net/hsr-prp/hsr_netlink.c
+++ b/net/hsr-prp/hsr_netlink.c
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <net/rtnetlink.h>
 #include <net/genetlink.h>
+#include "hsr_prp_netlink.h"
 #include "hsr_prp_main.h"
 #include "hsr_prp_device.h"
 #include "hsr_prp_framereg.h"
@@ -31,85 +32,7 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
 		       struct nlattr *tb[], struct nlattr *data[],
 		       struct netlink_ext_ack *extack)
 {
-	struct net_device *link[2];
-	unsigned char multicast_spec, hsr_version;
-
-	if (!data) {
-		NL_SET_ERR_MSG_MOD(extack, "No slave devices specified");
-		return -EINVAL;
-	}
-	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_PRP_SLAVE1]));
-	if (!link[0]) {
-		NL_SET_ERR_MSG_MOD(extack, "Slave1 does not exist");
-		return -EINVAL;
-	}
-	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_PRP_SLAVE2]));
-	if (!link[1]) {
-		NL_SET_ERR_MSG_MOD(extack, "Slave2 does not exist");
-		return -EINVAL;
-	}
-
-	if (link[0] == link[1]) {
-		NL_SET_ERR_MSG_MOD(extack, "Slave1 and Slave2 are same");
-		return -EINVAL;
-	}
-
-	if (!data[IFLA_HSR_PRP_SF_MC_ADDR_LSB])
-		multicast_spec = 0;
-	else
-		multicast_spec = nla_get_u8(data[IFLA_HSR_PRP_SF_MC_ADDR_LSB]);
-
-	if (!data[IFLA_HSR_PRP_VERSION]) {
-		hsr_version = 0;
-	} else {
-		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");
-			return -EINVAL;
-		}
-	}
-
-	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_prp_priv *priv = netdev_priv(dev);
-	struct hsr_prp_port *port;
-
-	port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A);
-	if (port) {
-		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_PRP_SLAVE2, port->dev->ifindex))
-			goto nla_put_failure;
-	}
-
-	if (nla_put(skb, IFLA_HSR_PRP_SF_MC_ADDR, ETH_ALEN,
-		    priv->sup_multicast_addr) ||
-	    nla_put_u16(skb, IFLA_HSR_PRP_SEQ_NR, priv->sequence_nr))
-		goto nla_put_failure;
-
-	return 0;
-
-nla_put_failure:
-	return -EMSGSIZE;
+	return hsr_prp_newlink(src_net, dev, tb, data, extack);
 }
 
 static struct rtnl_link_ops hsr_link_ops __read_mostly = {
@@ -119,7 +42,7 @@ static struct rtnl_link_ops hsr_link_ops __read_mostly = {
 	.priv_size	= sizeof(struct hsr_prp_priv),
 	.setup		= hsr_prp_dev_setup,
 	.newlink	= hsr_newlink,
-	.fill_info	= hsr_fill_info,
+	.fill_info	= hsr_prp_fill_info,
 };
 
 /* attribute policy */
@@ -187,40 +110,9 @@ void hsr_nl_ringerror(struct hsr_prp_priv *priv,
 /* 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_prp_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_prp_port *master;
-	int res;
-
-	skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
-	if (!skb)
-		goto fail;
-
-	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_PRP_A_NODE_ADDR, ETH_ALEN, addr);
-	if (res < 0)
-		goto nla_put_failure;
-
-	genlmsg_end(skb, msg_head);
-	genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
-
-	return;
-
-nla_put_failure:
-	kfree_skb(skb);
-
-fail:
-	rcu_read_lock();
-	master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER);
-	netdev_warn(master->dev, "Could not send HSR node down\n");
-	rcu_read_unlock();
+	hsr_prp_nl_nodedown(priv, &hsr_genl_family, addr);
 }
 
 /* HSR_PRP_C_GET_NODE_STATUS lets userspace query the internal HSR node table
@@ -233,229 +125,14 @@ void hsr_nl_nodedown(struct hsr_prp_priv *priv,
  */
 static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
 {
-	/* For receiving */
-	struct nlattr *na;
-	struct net_device *hsr_dev;
-
-	/* For sending */
-	struct sk_buff *skb_out;
-	void *msg_head;
-	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;
-	u16 hsr_node_if2_seq;
-	int addr_b_ifindex;
-	int res;
-
-	if (!info)
-		goto invalid;
-
-	na = info->attrs[HSR_PRP_A_IFINDEX];
-	if (!na)
-		goto invalid;
-	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_PRP_A_IFINDEX]));
-	if (!hsr_dev)
-		goto rcu_unlock;
-	if (!is_hsr_prp_master(hsr_dev))
-		goto rcu_unlock;
-
-	/* Send reply */
-	skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
-	if (!skb_out) {
-		res = -ENOMEM;
-		goto fail;
-	}
-
-	msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
-			       info->snd_seq, &hsr_genl_family, 0,
-			       HSR_PRP_C_SET_NODE_STATUS);
-	if (!msg_head) {
-		res = -ENOMEM;
-		goto nla_put_failure;
-	}
-
-	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_PRP_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;
-
-	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_PRP_A_NODE_ADDR_B, ETH_ALEN,
-			      node_addr_b);
-		if (res < 0)
-			goto nla_put_failure;
-
-		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_PRP_A_IF1_AGE, hsr_node_if1_age);
-	if (res < 0)
-		goto nla_put_failure;
-	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_PRP_A_IF1_IFINDEX,
-				  port->dev->ifindex);
-	if (res < 0)
-		goto nla_put_failure;
-
-	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_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_PRP_A_IF2_IFINDEX,
-				  port->dev->ifindex);
-	if (res < 0)
-		goto nla_put_failure;
-
-	rcu_read_unlock();
-
-	genlmsg_end(skb_out, msg_head);
-	genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
-
-	return 0;
-
-rcu_unlock:
-	rcu_read_unlock();
-invalid:
-	netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL, NULL);
-	return 0;
-
-nla_put_failure:
-	kfree_skb(skb_out);
-	/* Fall through */
-
-fail:
-	rcu_read_unlock();
-	return res;
+	return hsr_prp_get_node_status(&hsr_genl_family, skb_in, info);
 }
 
 /* Get a list of MacAddressA of all nodes known to this node (including self).
  */
 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;
-	bool restart = false;
-	struct nlattr *na;
-	void *pos = NULL;
-	void *msg_head;
-	int res;
-
-	if (!info)
-		goto invalid;
-
-	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_PRP_A_IFINDEX]));
-	if (!hsr_dev)
-		goto rcu_unlock;
-	if (!is_hsr_prp_master(hsr_dev))
-		goto rcu_unlock;
-
-restart:
-	/* Send reply */
-	skb_out = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
-	if (!skb_out) {
-		res = -ENOMEM;
-		goto fail;
-	}
-
-	msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
-			       info->snd_seq, &hsr_genl_family, 0,
-			       HSR_PRP_C_SET_NODE_LIST);
-	if (!msg_head) {
-		res = -ENOMEM;
-		goto nla_put_failure;
-	}
-
-	if (!restart) {
-		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);
-
-	if (!pos)
-		pos = hsr_prp_get_next_node(priv, NULL, addr);
-	while (pos) {
-		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);
-				genlmsg_unicast(genl_info_net(info), skb_out,
-						info->snd_portid);
-				restart = true;
-				goto restart;
-			}
-			goto nla_put_failure;
-		}
-		pos = hsr_prp_get_next_node(priv, pos, addr);
-	}
-	rcu_read_unlock();
-
-	genlmsg_end(skb_out, msg_head);
-	genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
-
-	return 0;
-
-rcu_unlock:
-	rcu_read_unlock();
-invalid:
-	netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL, NULL);
-	return 0;
-
-nla_put_failure:
-	nlmsg_free(skb_out);
-	/* Fall through */
-
-fail:
-	rcu_read_unlock();
-	return res;
+	return hsr_prp_get_node_list(&hsr_genl_family, skb_in, info);
 }
 
 static const struct genl_ops hsr_ops[] = {
diff --git a/net/hsr-prp/hsr_prp_netlink.c b/net/hsr-prp/hsr_prp_netlink.c
new file mode 100644
index 000000000000..04d51cd97496
--- /dev/null
+++ b/net/hsr-prp/hsr_prp_netlink.c
@@ -0,0 +1,367 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright 2011-2014 Autronica Fire and Security AS
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Based on Code by Arvid Brodin, arvid.brodin@alten.se
+ *
+ * Common routines for handling Netlink messages for HSR and PRP
+ */
+
+#include "hsr_prp_netlink.h"
+#include "hsr_prp_main.h"
+#include "hsr_prp_device.h"
+#include "hsr_prp_framereg.h"
+
+int hsr_prp_newlink(struct net *src_net, struct net_device *dev,
+		    struct nlattr *tb[], struct nlattr *data[],
+		    struct netlink_ext_ack *extack)
+{
+	struct net_device *link[2];
+	unsigned char multicast_spec, hsr_version;
+
+	if (!data) {
+		NL_SET_ERR_MSG_MOD(extack, "No slave devices specified");
+		return -EINVAL;
+	}
+	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_PRP_SLAVE1]));
+	if (!link[0]) {
+		NL_SET_ERR_MSG_MOD(extack, "Slave1 does not exist");
+		return -EINVAL;
+	}
+	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_PRP_SLAVE2]));
+	if (!link[1]) {
+		NL_SET_ERR_MSG_MOD(extack, "Slave2 does not exist");
+		return -EINVAL;
+	}
+
+	if (link[0] == link[1]) {
+		NL_SET_ERR_MSG_MOD(extack, "Slave1 and Slave2 are same");
+		return -EINVAL;
+	}
+
+	if (!data[IFLA_HSR_PRP_SF_MC_ADDR_LSB])
+		multicast_spec = 0;
+	else
+		multicast_spec = nla_get_u8(data[IFLA_HSR_PRP_SF_MC_ADDR_LSB]);
+
+	if (!data[IFLA_HSR_PRP_VERSION]) {
+		hsr_version = 0;
+	} else {
+		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");
+			return -EINVAL;
+		}
+	}
+
+	return hsr_prp_dev_finalize(dev, link, multicast_spec, hsr_version,
+				    extack);
+}
+
+int hsr_prp_fill_info(struct sk_buff *skb, const struct net_device *dev)
+{
+	struct hsr_prp_priv *priv = netdev_priv(dev);
+	struct hsr_prp_port *port;
+
+	port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A);
+	if (port) {
+		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_PRP_SLAVE2, port->dev->ifindex))
+			goto nla_put_failure;
+	}
+
+	if (nla_put(skb, IFLA_HSR_PRP_SF_MC_ADDR, ETH_ALEN,
+		    priv->sup_multicast_addr) ||
+	    nla_put_u16(skb, IFLA_HSR_PRP_SEQ_NR, priv->sequence_nr))
+		goto nla_put_failure;
+
+	return 0;
+
+nla_put_failure:
+	return -EMSGSIZE;
+}
+
+/* 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_prp_nl_nodedown(struct hsr_prp_priv *priv,
+			 struct genl_family *genl_family,
+			 unsigned char addr[ETH_ALEN])
+{
+	struct sk_buff *skb;
+	void *msg_head;
+	struct hsr_prp_port *master;
+	int res;
+
+	skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
+	if (!skb)
+		goto fail;
+
+	msg_head = genlmsg_put(skb, 0, 0, genl_family, 0,
+			       HSR_PRP_C_NODE_DOWN);
+	if (!msg_head)
+		goto nla_put_failure;
+
+	res = nla_put(skb, HSR_PRP_A_NODE_ADDR, ETH_ALEN, addr);
+	if (res < 0)
+		goto nla_put_failure;
+
+	genlmsg_end(skb, msg_head);
+	genlmsg_multicast(genl_family, skb, 0, 0, GFP_ATOMIC);
+
+	return;
+
+nla_put_failure:
+	kfree_skb(skb);
+
+fail:
+	rcu_read_lock();
+	master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER);
+	netdev_warn(master->dev, "Could not send HSR node down\n");
+	rcu_read_unlock();
+}
+
+int hsr_prp_get_node_status(struct genl_family *genl_family,
+			    struct sk_buff *skb_in, struct genl_info *info)
+{
+	/* For receiving */
+	struct nlattr *na;
+	struct net_device *hsr_dev;
+
+	/* For sending */
+	struct sk_buff *skb_out;
+	void *msg_head;
+	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;
+	u16 hsr_node_if2_seq;
+	int addr_b_ifindex;
+	int res;
+
+	if (!info)
+		goto invalid;
+
+	na = info->attrs[HSR_PRP_A_IFINDEX];
+	if (!na)
+		goto invalid;
+	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_PRP_A_IFINDEX]));
+	if (!hsr_dev)
+		goto rcu_unlock;
+	if (!is_hsr_prp_master(hsr_dev))
+		goto rcu_unlock;
+
+	/* Send reply */
+	skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
+	if (!skb_out) {
+		res = -ENOMEM;
+		goto fail;
+	}
+
+	msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
+			       info->snd_seq, genl_family, 0,
+			       HSR_PRP_C_SET_NODE_STATUS);
+	if (!msg_head) {
+		res = -ENOMEM;
+		goto nla_put_failure;
+	}
+
+	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_PRP_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;
+
+	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_PRP_A_NODE_ADDR_B, ETH_ALEN,
+			      node_addr_b);
+		if (res < 0)
+			goto nla_put_failure;
+
+		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_PRP_A_IF1_AGE, hsr_node_if1_age);
+	if (res < 0)
+		goto nla_put_failure;
+	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_PRP_A_IF1_IFINDEX,
+				  port->dev->ifindex);
+	if (res < 0)
+		goto nla_put_failure;
+
+	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_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_PRP_A_IF2_IFINDEX,
+				  port->dev->ifindex);
+	if (res < 0)
+		goto nla_put_failure;
+
+	rcu_read_unlock();
+
+	genlmsg_end(skb_out, msg_head);
+	genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
+
+	return 0;
+
+rcu_unlock:
+	rcu_read_unlock();
+invalid:
+	netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL, NULL);
+	return 0;
+
+nla_put_failure:
+	kfree_skb(skb_out);
+	/* Fall through */
+
+fail:
+	rcu_read_unlock();
+	return res;
+}
+
+/* Get a list of MacAddressA of all nodes known to this node (including self).
+ */
+int hsr_prp_get_node_list(struct genl_family *genl_family,
+			  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;
+	bool restart = false;
+	struct nlattr *na;
+	void *pos = NULL;
+	void *msg_head;
+	int res;
+
+	if (!info)
+		goto invalid;
+
+	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_PRP_A_IFINDEX]));
+	if (!hsr_dev)
+		goto rcu_unlock;
+	if (!is_hsr_prp_master(hsr_dev))
+		goto rcu_unlock;
+
+restart:
+	/* Send reply */
+	skb_out = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
+	if (!skb_out) {
+		res = -ENOMEM;
+		goto fail;
+	}
+
+	msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
+			       info->snd_seq, genl_family, 0,
+			       HSR_PRP_C_SET_NODE_LIST);
+	if (!msg_head) {
+		res = -ENOMEM;
+		goto nla_put_failure;
+	}
+
+	if (!restart) {
+		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);
+
+	if (!pos)
+		pos = hsr_prp_get_next_node(priv, NULL, addr);
+	while (pos) {
+		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);
+				genlmsg_unicast(genl_info_net(info), skb_out,
+						info->snd_portid);
+				restart = true;
+				goto restart;
+			}
+			goto nla_put_failure;
+		}
+		pos = hsr_prp_get_next_node(priv, pos, addr);
+	}
+	rcu_read_unlock();
+
+	genlmsg_end(skb_out, msg_head);
+	genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
+
+	return 0;
+
+rcu_unlock:
+	rcu_read_unlock();
+invalid:
+	netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL, NULL);
+	return 0;
+
+nla_put_failure:
+	nlmsg_free(skb_out);
+	/* Fall through */
+
+fail:
+	rcu_read_unlock();
+	return res;
+}
diff --git a/net/hsr-prp/hsr_prp_netlink.h b/net/hsr-prp/hsr_prp_netlink.h
new file mode 100644
index 000000000000..a3a4e6252e45
--- /dev/null
+++ b/net/hsr-prp/hsr_prp_netlink.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright 2011-2014 Autronica Fire and Security AS
+ *
+ * Author(s):
+ *	2011-2014 Arvid Brodin, arvid.brodin@alten.se
+ */
+
+#ifndef __HSR_PRP_NETLINK_H
+#define __HSR_PRP_NETLINK_H
+
+#include <uapi/linux/hsr_prp_netlink.h>
+#include <net/genetlink.h>
+
+#include "hsr_prp_main.h"
+
+int hsr_prp_newlink(struct net *src_net, struct net_device *dev,
+		    struct nlattr *tb[], struct nlattr *data[],
+		    struct netlink_ext_ack *extack);
+int hsr_prp_fill_info(struct sk_buff *skb, const struct net_device *dev);
+void hsr_prp_nl_nodedown(struct hsr_prp_priv *priv,
+			 struct genl_family *genl_family,
+			 unsigned char addr[ETH_ALEN]);
+int hsr_prp_get_node_status(struct genl_family *genl_family,
+			    struct sk_buff *skb_in, struct genl_info *info);
+int hsr_prp_get_node_list(struct genl_family *genl_family,
+			  struct sk_buff *skb_in, struct genl_info *info);
+#endif /* __HSR_PRP_NETLINK_H */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 10/13] net: hsr: add netlink socket interface for PRP
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (8 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 09/13] net: hsr: move re-usable code for PRP to hsr_prp_netlink.c Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 11/13] net: prp: add supervision frame generation and handling support Murali Karicheri
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

Similar to HSR, add a netlink socket interface code re-using the
common functions from hsr_prp_netlink.c. Use wrapper functions
for hsr_dev_setup() and prp_dev_setup() to setup HSR/PRP interface
by calling common hsr_prp_dev_setup().

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 net/hsr-prp/Makefile           |   2 +-
 net/hsr-prp/hsr_netlink.c      |  11 ++-
 net/hsr-prp/hsr_netlink.h      |   1 +
 net/hsr-prp/hsr_prp_device.c   |  34 +++++---
 net/hsr-prp/hsr_prp_device.h   |   3 +-
 net/hsr-prp/hsr_prp_framereg.c |   6 +-
 net/hsr-prp/hsr_prp_main.c     |  51 ++++++++++--
 net/hsr-prp/hsr_prp_main.h     |   5 ++
 net/hsr-prp/hsr_prp_netlink.c  |  80 +++++++++----------
 net/hsr-prp/hsr_prp_netlink.h  |   5 +-
 net/hsr-prp/prp_netlink.c      | 141 +++++++++++++++++++++++++++++++++
 net/hsr-prp/prp_netlink.h      |  27 +++++++
 12 files changed, 302 insertions(+), 64 deletions(-)
 create mode 100644 net/hsr-prp/prp_netlink.c
 create mode 100644 net/hsr-prp/prp_netlink.h

diff --git a/net/hsr-prp/Makefile b/net/hsr-prp/Makefile
index 76f266cd1976..9b84b0d813c2 100644
--- a/net/hsr-prp/Makefile
+++ b/net/hsr-prp/Makefile
@@ -7,5 +7,5 @@ obj-$(CONFIG_HSR_PRP)	+= hsr-prp.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_netlink.o
+			   hsr_prp_forward.o hsr_prp_netlink.o prp_netlink.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 6bdb369ced36..f14ed521dcb2 100644
--- a/net/hsr-prp/hsr_netlink.c
+++ b/net/hsr-prp/hsr_netlink.c
@@ -32,7 +32,7 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
 		       struct nlattr *tb[], struct nlattr *data[],
 		       struct netlink_ext_ack *extack)
 {
-	return hsr_prp_newlink(src_net, dev, tb, data, extack);
+	return hsr_prp_newlink(HSR, src_net, dev, tb, data, extack);
 }
 
 static struct rtnl_link_ops hsr_link_ops __read_mostly = {
@@ -40,7 +40,7 @@ static struct rtnl_link_ops hsr_link_ops __read_mostly = {
 	.maxtype	= IFLA_HSR_PRP_MAX,
 	.policy		= hsr_policy,
 	.priv_size	= sizeof(struct hsr_prp_priv),
-	.setup		= hsr_prp_dev_setup,
+	.setup		= hsr_dev_setup,
 	.newlink	= hsr_newlink,
 	.fill_info	= hsr_prp_fill_info,
 };
@@ -188,10 +188,15 @@ int __init hsr_netlink_init(void)
 	return rc;
 }
 
-void __exit hsr_netlink_exit(void)
+void hsr_nl_cleanup(void)
 {
 	genl_unregister_family(&hsr_genl_family);
 	rtnl_link_unregister(&hsr_link_ops);
 }
 
+void __exit hsr_netlink_exit(void)
+{
+	hsr_nl_cleanup();
+}
+
 MODULE_ALIAS_RTNL_LINK("hsr");
diff --git a/net/hsr-prp/hsr_netlink.h b/net/hsr-prp/hsr_netlink.h
index df3d1acb08e0..b0e96193b09f 100644
--- a/net/hsr-prp/hsr_netlink.h
+++ b/net/hsr-prp/hsr_netlink.h
@@ -18,6 +18,7 @@ struct hsr_prp_port;
 int __init hsr_netlink_init(void);
 void __exit hsr_netlink_exit(void);
 
+void hsr_nl_cleanup(void);
 void hsr_nl_ringerror(struct hsr_prp_priv *priv,
 		      unsigned char addr[ETH_ALEN],
 		      struct hsr_prp_port *port);
diff --git a/net/hsr-prp/hsr_prp_device.c b/net/hsr-prp/hsr_prp_device.c
index 43269c204445..501de23a97f5 100644
--- a/net/hsr-prp/hsr_prp_device.c
+++ b/net/hsr-prp/hsr_prp_device.c
@@ -321,7 +321,7 @@ static void hsr_prp_announce(struct timer_list *t)
 	rcu_read_lock();
 	master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER);
 
-	if (priv->announce_count < 3 && priv->prot_version == 0) {
+	if (priv->announce_count < 3 && priv->prot_version == HSR_V0) {
 		send_hsr_prp_supervision_frame(master, HSR_TLV_ANNOUNCE,
 					       priv->prot_version);
 		priv->announce_count++;
@@ -384,11 +384,7 @@ static const struct net_device_ops hsr_prp_device_ops = {
 	.ndo_uninit = hsr_prp_dev_destroy,
 };
 
-static struct device_type hsr_type = {
-	.name = "hsr",
-};
-
-void hsr_prp_dev_setup(struct net_device *dev)
+static void hsr_prp_dev_setup(struct net_device *dev, struct device_type *type)
 {
 	eth_hw_addr_random(dev);
 
@@ -396,7 +392,7 @@ void hsr_prp_dev_setup(struct net_device *dev)
 	dev->min_mtu = 0;
 	dev->header_ops = &hsr_prp_header_ops;
 	dev->netdev_ops = &hsr_prp_device_ops;
-	SET_NETDEV_DEVTYPE(dev, &hsr_type);
+	SET_NETDEV_DEVTYPE(dev, type);
 	dev->priv_flags |= IFF_NO_QUEUE;
 
 	dev->needs_free_netdev = true;
@@ -419,6 +415,24 @@ void hsr_prp_dev_setup(struct net_device *dev)
 	dev->features |= NETIF_F_NETNS_LOCAL;
 }
 
+static struct device_type hsr_type = {
+	.name = "hsr",
+};
+
+void hsr_dev_setup(struct net_device *dev)
+{
+	hsr_prp_dev_setup(dev, &hsr_type);
+}
+
+static struct device_type prp_type = {
+	.name = "prp",
+};
+
+void prp_dev_setup(struct net_device *dev)
+{
+	hsr_prp_dev_setup(dev, &prp_type);
+}
+
 /* Return true if dev is a HSR master; return false otherwise.
  */
 inline bool is_hsr_prp_master(struct net_device *dev)
@@ -439,6 +453,10 @@ 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);
@@ -464,8 +482,6 @@ int hsr_prp_dev_finalize(struct net_device *hsr_prp_dev,
 	ether_addr_copy(priv->sup_multicast_addr, def_multicast_addr);
 	priv->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec;
 
-	priv->prot_version = protocol_version;
-
 	/* FIXME: should I modify the value of these?
 	 *
 	 * - hsr_ptp_dev->flags - i.e.
diff --git a/net/hsr-prp/hsr_prp_device.h b/net/hsr-prp/hsr_prp_device.h
index 4f734a36b2d6..107f1c498442 100644
--- a/net/hsr-prp/hsr_prp_device.h
+++ b/net/hsr-prp/hsr_prp_device.h
@@ -11,7 +11,8 @@
 #include <linux/netdevice.h>
 #include "hsr_prp_main.h"
 
-void hsr_prp_dev_setup(struct net_device *dev);
+void hsr_dev_setup(struct net_device *dev);
+void 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);
diff --git a/net/hsr-prp/hsr_prp_framereg.c b/net/hsr-prp/hsr_prp_framereg.c
index d78d32d513ca..42c673befe2c 100644
--- a/net/hsr-prp/hsr_prp_framereg.c
+++ b/net/hsr-prp/hsr_prp_framereg.c
@@ -17,6 +17,7 @@
 #include "hsr_prp_main.h"
 #include "hsr_prp_framereg.h"
 #include "hsr_netlink.h"
+#include "prp_netlink.h"
 
 /*	TODO: use hash lists for mac addresses (linux/jhash.h)?    */
 
@@ -443,7 +444,10 @@ void hsr_prp_prune_nodes(struct timer_list *t)
 		/* Prune old entries */
 		if (time_is_before_jiffies(timestamp +
 				msecs_to_jiffies(HSR_PRP_NODE_FORGET_TIME))) {
-			hsr_nl_nodedown(priv, node->macaddress_A);
+			if (priv->prot_version <= HSR_V1)
+				hsr_nl_nodedown(priv, node->macaddress_A);
+			else
+				prp_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);
diff --git a/net/hsr-prp/hsr_prp_main.c b/net/hsr-prp/hsr_prp_main.c
index 4565744ce1a1..e7e5ca537456 100644
--- a/net/hsr-prp/hsr_prp_main.c
+++ b/net/hsr-prp/hsr_prp_main.c
@@ -12,6 +12,7 @@
 #include "hsr_prp_main.h"
 #include "hsr_prp_device.h"
 #include "hsr_netlink.h"
+#include "prp_netlink.h"
 #include "hsr_prp_framereg.h"
 #include "hsr_prp_slave.h"
 
@@ -25,6 +26,17 @@ static bool hsr_prp_slave_empty(struct hsr_prp_priv *priv)
 	return true;
 }
 
+static int hsr_prp_netdev_notify(struct notifier_block *nb, unsigned long event,
+				 void *ptr);
+
+static struct notifier_block hsr_nb = {
+	.notifier_call = hsr_prp_netdev_notify,	/* Slave event notifications */
+};
+
+static struct notifier_block prp_nb = {
+	.notifier_call = hsr_prp_netdev_notify,	/* Slave event notifications */
+};
+
 static int hsr_prp_netdev_notify(struct notifier_block *nb, unsigned long event,
 				 void *ptr)
 {
@@ -50,6 +62,11 @@ static int hsr_prp_netdev_notify(struct notifier_block *nb, unsigned long event,
 		priv = port->priv;
 	}
 
+	if (priv->prot_version <= HSR_V1 && nb != &hsr_nb)
+		return NOTIFY_DONE;
+	else if (priv->prot_version == PRP_V1 && nb != &prp_nb)
+		return NOTIFY_DONE;
+
 	switch (event) {
 	case NETDEV_UP:		/* Administrative state DOWN */
 	case NETDEV_DOWN:	/* Administrative state UP */
@@ -127,18 +144,38 @@ struct hsr_prp_port *hsr_prp_get_port(struct hsr_prp_priv *priv,
 	return NULL;
 }
 
-static struct notifier_block hsr_nb = {
-	.notifier_call = hsr_prp_netdev_notify,	/* Slave event notifications */
-};
-
 static int __init hsr_prp_init(void)
 {
 	int res;
 
 	BUILD_BUG_ON(sizeof(struct hsr_tag) != HSR_PRP_HLEN);
 
-	register_netdevice_notifier(&hsr_nb);
-	res = hsr_netlink_init();
+	res = register_netdevice_notifier(&hsr_nb);
+	if (!res)
+		res = hsr_netlink_init();
+	else
+		return res;
+
+	if (res)
+		goto cleanup_hsr_notify;
+
+	res = register_netdevice_notifier(&prp_nb);
+	if (!res)
+		res = prp_netlink_init();
+	else
+		goto cleanup_hsr_link;
+
+	if (res)
+		goto cleanup_prp_notify;
+
+	return res;
+
+cleanup_prp_notify:
+	unregister_netdevice_notifier(&prp_nb);
+cleanup_hsr_link:
+	hsr_nl_cleanup();
+cleanup_hsr_notify:
+	unregister_netdevice_notifier(&hsr_nb);
 
 	return res;
 }
@@ -146,7 +183,9 @@ static int __init hsr_prp_init(void)
 static void __exit hsr_prp_exit(void)
 {
 	unregister_netdevice_notifier(&hsr_nb);
+	unregister_netdevice_notifier(&prp_nb);
 	hsr_netlink_exit();
+	prp_netlink_exit();
 	hsr_prp_debugfs_remove_root();
 }
 
diff --git a/net/hsr-prp/hsr_prp_main.h b/net/hsr-prp/hsr_prp_main.h
index 7d9a3e009a2d..00c312e5189f 100644
--- a/net/hsr-prp/hsr_prp_main.h
+++ b/net/hsr-prp/hsr_prp_main.h
@@ -132,6 +132,8 @@ struct hsr_prp_port {
 	enum hsr_prp_port_type	type;
 };
 
+#define HSR	0
+#define PRP	1
 struct hsr_prp_priv {
 	struct rcu_head		rcu_head;
 	struct list_head	ports;
@@ -145,6 +147,9 @@ struct hsr_prp_priv {
 	u8 prot_version;	/* Indicate if HSRv0 or HSRv1. */
 	spinlock_t seqnr_lock;	/* locking for sequence_nr */
 	spinlock_t list_lock;	/* locking for node list */
+#define HSR_V0	0
+#define HSR_V1	1
+#define PRP_V1	2
 	unsigned char		sup_multicast_addr[ETH_ALEN];
 #ifdef	CONFIG_DEBUG_FS
 	struct dentry *node_tbl_root;
diff --git a/net/hsr-prp/hsr_prp_netlink.c b/net/hsr-prp/hsr_prp_netlink.c
index 04d51cd97496..865df1dbe621 100644
--- a/net/hsr-prp/hsr_prp_netlink.c
+++ b/net/hsr-prp/hsr_prp_netlink.c
@@ -12,12 +12,13 @@
 #include "hsr_prp_device.h"
 #include "hsr_prp_framereg.h"
 
-int hsr_prp_newlink(struct net *src_net, struct net_device *dev,
-		    struct nlattr *tb[], struct nlattr *data[],
+int hsr_prp_newlink(int proto, struct net *src_net,
+		    struct net_device *dev, struct nlattr *tb[],
+		    struct nlattr *data[],
 		    struct netlink_ext_ack *extack)
 {
 	struct net_device *link[2];
-	unsigned char multicast_spec, hsr_version;
+	unsigned char mc_lsb, version = 0;
 
 	if (!data) {
 		NL_SET_ERR_MSG_MOD(extack, "No slave devices specified");
@@ -50,23 +51,22 @@ int hsr_prp_newlink(struct net *src_net, struct net_device *dev,
 	}
 
 	if (!data[IFLA_HSR_PRP_SF_MC_ADDR_LSB])
-		multicast_spec = 0;
+		mc_lsb = 0;
 	else
-		multicast_spec = nla_get_u8(data[IFLA_HSR_PRP_SF_MC_ADDR_LSB]);
+		mc_lsb = nla_get_u8(data[IFLA_HSR_PRP_SF_MC_ADDR_LSB]);
 
-	if (!data[IFLA_HSR_PRP_VERSION]) {
-		hsr_version = 0;
+	if (proto == PRP) {
+		version = PRP_V1;
 	} else {
-		hsr_version = nla_get_u8(data[IFLA_HSR_PRP_VERSION]);
-		if (hsr_version > 1) {
+		version = nla_get_u8(data[IFLA_HSR_PRP_VERSION]);
+		if (version > 1) {
 			NL_SET_ERR_MSG_MOD(extack,
 					   "Only versions 0..1 are supported");
 			return -EINVAL;
 		}
 	}
 
-	return hsr_prp_dev_finalize(dev, link, multicast_spec, hsr_version,
-				    extack);
+	return hsr_prp_dev_finalize(dev, link, mc_lsb, version, extack);
 }
 
 int hsr_prp_fill_info(struct sk_buff *skb, const struct net_device *dev)
@@ -133,7 +133,7 @@ void hsr_prp_nl_nodedown(struct hsr_prp_priv *priv,
 fail:
 	rcu_read_lock();
 	master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER);
-	netdev_warn(master->dev, "Could not send HSR node down\n");
+	netdev_warn(master->dev, "Could not send HSR/PRP node down\n");
 	rcu_read_unlock();
 }
 
@@ -142,7 +142,7 @@ int hsr_prp_get_node_status(struct genl_family *genl_family,
 {
 	/* For receiving */
 	struct nlattr *na;
-	struct net_device *hsr_dev;
+	struct net_device *ndev;
 
 	/* For sending */
 	struct sk_buff *skb_out;
@@ -150,10 +150,10 @@ int hsr_prp_get_node_status(struct genl_family *genl_family,
 	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;
-	u16 hsr_node_if2_seq;
+	int node_if1_age;
+	u16 node_if1_seq;
+	int node_if2_age;
+	u16 node_if2_seq;
 	int addr_b_ifindex;
 	int res;
 
@@ -168,12 +168,11 @@ int hsr_prp_get_node_status(struct genl_family *genl_family,
 		goto invalid;
 
 	rcu_read_lock();
-	hsr_dev =
-	dev_get_by_index_rcu(genl_info_net(info),
-			     nla_get_u32(info->attrs[HSR_PRP_A_IFINDEX]));
-	if (!hsr_dev)
+	ndev = __dev_get_by_index(genl_info_net(info),
+				  nla_get_u32(info->attrs[HSR_PRP_A_IFINDEX]));
+	if (!ndev)
 		goto rcu_unlock;
-	if (!is_hsr_prp_master(hsr_dev))
+	if (!is_hsr_prp_master(ndev))
 		goto rcu_unlock;
 
 	/* Send reply */
@@ -191,20 +190,20 @@ int hsr_prp_get_node_status(struct genl_family *genl_family,
 		goto nla_put_failure;
 	}
 
-	res = nla_put_u32(skb_out, HSR_PRP_A_IFINDEX, hsr_dev->ifindex);
+	res = nla_put_u32(skb_out, HSR_PRP_A_IFINDEX, ndev->ifindex);
 	if (res < 0)
 		goto nla_put_failure;
 
-	priv = netdev_priv(hsr_dev);
+	priv = netdev_priv(ndev);
 	res = hsr_prp_get_node_data(priv,
 				    (unsigned char *)
 				    nla_data(info->attrs[HSR_PRP_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);
+					     &node_if1_age,
+					     &node_if1_seq,
+					     &node_if2_age,
+					     &node_if2_seq);
 	if (res < 0)
 		goto nla_put_failure;
 
@@ -225,10 +224,10 @@ int hsr_prp_get_node_status(struct genl_family *genl_family,
 			goto nla_put_failure;
 	}
 
-	res = nla_put_u32(skb_out, HSR_PRP_A_IF1_AGE, hsr_node_if1_age);
+	res = nla_put_u32(skb_out, HSR_PRP_A_IF1_AGE, node_if1_age);
 	if (res < 0)
 		goto nla_put_failure;
-	res = nla_put_u16(skb_out, HSR_PRP_A_IF1_SEQ, hsr_node_if1_seq);
+	res = nla_put_u16(skb_out, HSR_PRP_A_IF1_SEQ, node_if1_seq);
 	if (res < 0)
 		goto nla_put_failure;
 	port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_A);
@@ -238,10 +237,10 @@ int hsr_prp_get_node_status(struct genl_family *genl_family,
 	if (res < 0)
 		goto nla_put_failure;
 
-	res = nla_put_u32(skb_out, HSR_PRP_A_IF2_AGE, hsr_node_if2_age);
+	res = nla_put_u32(skb_out, HSR_PRP_A_IF2_AGE, node_if2_age);
 	if (res < 0)
 		goto nla_put_failure;
-	res = nla_put_u16(skb_out, HSR_PRP_A_IF2_SEQ, hsr_node_if2_seq);
+	res = nla_put_u16(skb_out, HSR_PRP_A_IF2_SEQ, node_if2_seq);
 	if (res < 0)
 		goto nla_put_failure;
 	port = hsr_prp_get_port(priv, HSR_PRP_PT_SLAVE_B);
@@ -273,14 +272,14 @@ int hsr_prp_get_node_status(struct genl_family *genl_family,
 	return res;
 }
 
-/* Get a list of MacAddressA of all nodes known to this node (including self).
+/* Get a list of mac_address_a of all nodes known to this node (including self).
  */
 int hsr_prp_get_node_list(struct genl_family *genl_family,
 			  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 net_device *ndev;
 	struct sk_buff *skb_out;
 	bool restart = false;
 	struct nlattr *na;
@@ -296,12 +295,11 @@ int hsr_prp_get_node_list(struct genl_family *genl_family,
 		goto invalid;
 
 	rcu_read_lock();
-	hsr_dev =
-	dev_get_by_index_rcu(genl_info_net(info),
-			     nla_get_u32(info->attrs[HSR_PRP_A_IFINDEX]));
-	if (!hsr_dev)
+	ndev = __dev_get_by_index(genl_info_net(info),
+				  nla_get_u32(info->attrs[HSR_PRP_A_IFINDEX]));
+	if (!ndev)
 		goto rcu_unlock;
-	if (!is_hsr_prp_master(hsr_dev))
+	if (!is_hsr_prp_master(ndev))
 		goto rcu_unlock;
 
 restart:
@@ -321,12 +319,12 @@ int hsr_prp_get_node_list(struct genl_family *genl_family,
 	}
 
 	if (!restart) {
-		res = nla_put_u32(skb_out, HSR_PRP_A_IFINDEX, hsr_dev->ifindex);
+		res = nla_put_u32(skb_out, HSR_PRP_A_IFINDEX, ndev->ifindex);
 		if (res < 0)
 			goto nla_put_failure;
 	}
 
-	priv = netdev_priv(hsr_dev);
+	priv = netdev_priv(ndev);
 
 	if (!pos)
 		pos = hsr_prp_get_next_node(priv, NULL, addr);
diff --git a/net/hsr-prp/hsr_prp_netlink.h b/net/hsr-prp/hsr_prp_netlink.h
index a3a4e6252e45..5bd0f8cf2644 100644
--- a/net/hsr-prp/hsr_prp_netlink.h
+++ b/net/hsr-prp/hsr_prp_netlink.h
@@ -13,8 +13,9 @@
 
 #include "hsr_prp_main.h"
 
-int hsr_prp_newlink(struct net *src_net, struct net_device *dev,
-		    struct nlattr *tb[], struct nlattr *data[],
+int hsr_prp_newlink(int proto, struct net *src_net,
+		    struct net_device *dev, struct nlattr *tb[],
+		    struct nlattr *data[],
 		    struct netlink_ext_ack *extack);
 int hsr_prp_fill_info(struct sk_buff *skb, const struct net_device *dev);
 void hsr_prp_nl_nodedown(struct hsr_prp_priv *priv,
diff --git a/net/hsr-prp/prp_netlink.c b/net/hsr-prp/prp_netlink.c
new file mode 100644
index 000000000000..d6c0a64e0a84
--- /dev/null
+++ b/net/hsr-prp/prp_netlink.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0
+/* This is based on hsr_netlink.c from Arvid Brodin, arvid.brodin@alten.se
+ *
+ * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author(s):
+ *	Murali Karicheri <m-karicheri2@ti.com>
+ *	Routines for handling Netlink messages for PRP
+ */
+
+#include <linux/kernel.h>
+#include <net/genetlink.h>
+#include <net/rtnetlink.h>
+
+#include "prp_netlink.h"
+#include "hsr_prp_netlink.h"
+#include "hsr_prp_main.h"
+#include "hsr_prp_device.h"
+#include "hsr_prp_framereg.h"
+
+static const struct nla_policy prp_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_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
+ * hsr_prp_dev_setup routine has been executed. Nice!
+ */
+static int prp_newlink(struct net *src_net, struct net_device *dev,
+		       struct nlattr *tb[], struct nlattr *data[],
+		       struct netlink_ext_ack *extack)
+{
+	return hsr_prp_newlink(PRP, src_net, dev, tb, data, extack);
+}
+
+static struct rtnl_link_ops prp_link_ops __read_mostly = {
+	.kind		= "prp",
+	.maxtype	= IFLA_HSR_PRP_MAX,
+	.policy		= prp_policy,
+	.priv_size	= sizeof(struct hsr_prp_priv),
+	.setup		= prp_dev_setup,
+	.newlink	= prp_newlink,
+	.fill_info	= hsr_prp_fill_info,
+};
+
+/* NLA_BINARY missing in libnl; use NLA_UNSPEC in userspace instead. */
+static const struct nla_policy prp_genl_policy[HSR_PRP_A_MAX + 1] = {
+	[HSR_PRP_A_NODE_ADDR] = { .type = NLA_BINARY, .len = ETH_ALEN },
+	[HSR_PRP_A_NODE_ADDR_B] = { .type = NLA_BINARY, .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 prp_genl_family;
+
+static const struct genl_multicast_group prp_mcgrps[] = {
+	{ .name = "prp-network", },
+};
+
+/* 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 prp_nl_nodedown(struct hsr_prp_priv *priv, unsigned char addr[ETH_ALEN])
+{
+	hsr_prp_nl_nodedown(priv, &prp_genl_family, addr);
+}
+
+static int prp_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
+{
+	return hsr_prp_get_node_status(&prp_genl_family, skb_in, info);
+}
+
+static int prp_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
+{
+	return hsr_prp_get_node_list(&prp_genl_family, skb_in, info);
+}
+
+static const struct genl_ops prp_ops[] = {
+	{
+		.cmd = HSR_PRP_C_GET_NODE_STATUS,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.flags = 0,
+		.doit = prp_get_node_status,
+		.dumpit = NULL,
+	},
+	{
+		.cmd = HSR_PRP_C_GET_NODE_LIST,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.flags = 0,
+		.doit = prp_get_node_list,
+		.dumpit = NULL,
+	},
+};
+
+static struct genl_family prp_genl_family __ro_after_init = {
+	.hdrsize = 0,
+	.name = "PRP",
+	.version = 1,
+	.maxattr = HSR_PRP_A_MAX,
+	.policy = prp_genl_policy,
+	.module = THIS_MODULE,
+	.ops = prp_ops,
+	.n_ops = ARRAY_SIZE(prp_ops),
+	.mcgrps = prp_mcgrps,
+	.n_mcgrps = ARRAY_SIZE(prp_mcgrps),
+};
+
+int __init prp_netlink_init(void)
+{
+	int rc;
+
+	rc = rtnl_link_register(&prp_link_ops);
+	if (rc)
+		goto fail_rtnl_link_register;
+
+	rc = genl_register_family(&prp_genl_family);
+	if (rc)
+		goto fail_genl_register_family;
+
+	return 0;
+
+fail_genl_register_family:
+	rtnl_link_unregister(&prp_link_ops);
+fail_rtnl_link_register:
+
+	return rc;
+}
+
+void __exit prp_netlink_exit(void)
+{
+	genl_unregister_family(&prp_genl_family);
+	rtnl_link_unregister(&prp_link_ops);
+}
+
+MODULE_ALIAS_RTNL_LINK("prp");
diff --git a/net/hsr-prp/prp_netlink.h b/net/hsr-prp/prp_netlink.h
new file mode 100644
index 000000000000..ad43b33b5bfb
--- /dev/null
+++ b/net/hsr-prp/prp_netlink.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* prp_netlink.h:
+ * This is based on hsr_netlink.h from Arvid Brodin, arvid.brodin@alten.se
+ *
+ * Copyright (C) 2017-2020 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author(s):
+ *	Murali Karicheri <m-karicheri2@ti.com>
+ */
+
+#ifndef __PRP_NETLINK_H
+#define __PRP_NETLINK_H
+
+#include <linux/if_ether.h>
+#include <linux/module.h>
+
+#include <uapi/linux/hsr_prp_netlink.h>
+
+struct hsr_prp_priv;
+struct hsr_prp_port;
+
+int __init prp_netlink_init(void);
+void __exit prp_netlink_exit(void);
+
+void prp_nl_nodedown(struct hsr_prp_priv *priv, unsigned char addr[ETH_ALEN]);
+
+#endif /* __PRP_NETLINK_H */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 11/13] net: prp: add supervision frame generation and handling support
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (9 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 10/13] net: hsr: add netlink socket interface for PRP Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 12/13] net: prp: add packet " Murali Karicheri
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

Add support for sending and handling supervision frames. For PRP,
supervision frame format is similar to HSR version 0, but have a
PRP Redunancy Control Trailor (RCT) added.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 net/hsr-prp/hsr_prp_device.c  | 50 ++++++++++++++++++++++++++++-------
 net/hsr-prp/hsr_prp_forward.c |  4 ++-
 net/hsr-prp/hsr_prp_main.h    | 22 +++++++++++++++
 3 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/net/hsr-prp/hsr_prp_device.c b/net/hsr-prp/hsr_prp_device.c
index 501de23a97f5..3c463e185f64 100644
--- a/net/hsr-prp/hsr_prp_device.c
+++ b/net/hsr-prp/hsr_prp_device.c
@@ -237,13 +237,20 @@ static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master,
 {
 	struct sk_buff *skb;
 	int hlen, tlen;
-	struct hsr_tag *hsr_tag;
+	struct hsr_tag *hsr_tag = NULL;
+	struct prp_rct *rct;
 	struct hsr_prp_sup_tag *hsr_stag;
 	struct hsr_prp_sup_payload *hsr_sp;
 	unsigned long irqflags;
+	u16 proto;
+	u8 *tail;
 
 	hlen = LL_RESERVED_SPACE(master->dev);
 	tlen = master->dev->needed_tailroom;
+	/* skb size is same for PRP/HSR frames, only difference
+	 * being for PRP, it is a trailor and for HSR it is a
+	 * header
+	 */
 	skb = dev_alloc_skb(sizeof(struct hsr_tag) +
 			    sizeof(struct hsr_prp_sup_tag) +
 			    sizeof(struct hsr_prp_sup_payload) + hlen + tlen);
@@ -252,12 +259,15 @@ static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master,
 		return;
 
 	skb_reserve(skb, hlen);
-
+	if (!proto_ver)
+		proto = ETH_P_PRP;
+	else
+		proto = (proto_ver == HSR_V1) ? ETH_P_HSR : ETH_P_PRP;
 	skb->dev = master->dev;
-	skb->protocol = htons(proto_ver ? ETH_P_HSR : ETH_P_PRP);
+	skb->protocol = htons(proto);
 	skb->priority = TC_PRIO_CONTROL;
 
-	if (dev_hard_header(skb, skb->dev, (proto_ver ? ETH_P_HSR : ETH_P_PRP),
+	if (dev_hard_header(skb, skb->dev, proto,
 			    master->priv->sup_multicast_addr,
 			    skb->dev->dev_addr, skb->len) <= 0)
 		goto out;
@@ -265,7 +275,7 @@ static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master,
 	skb_reset_network_header(skb);
 	skb_reset_transport_header(skb);
 
-	if (proto_ver > 0) {
+	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);
@@ -273,15 +283,19 @@ static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master,
 
 	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);
+	set_hsr_stag_HSR_ver(hsr_stag, proto_ver ? 0x1 : 0x0);
 
 	/* From HSRv1 on we have separate supervision sequence numbers. */
 	spin_lock_irqsave(&master->priv->seqnr_lock, irqflags);
 	if (proto_ver > 0) {
 		hsr_stag->sequence_nr = htons(master->priv->sup_sequence_nr);
-		hsr_tag->sequence_nr = htons(master->priv->sequence_nr);
+		if (hsr_tag)
+			hsr_tag->sequence_nr = htons(master->priv->sequence_nr);
 		master->priv->sup_sequence_nr++;
-		master->priv->sequence_nr++;
+		if (proto_ver == HSR_V1) {
+			hsr_tag->sequence_nr = htons(master->priv->sequence_nr);
+			master->priv->sequence_nr++;
+		}
 	} else {
 		hsr_stag->sequence_nr = htons(master->priv->sequence_nr);
 		master->priv->sequence_nr++;
@@ -300,6 +314,16 @@ static void send_hsr_prp_supervision_frame(struct hsr_prp_port *master,
 	if (skb_put_padto(skb, ETH_ZLEN + HSR_PRP_HLEN))
 		return;
 
+	spin_lock_irqsave(&master->priv->seqnr_lock, irqflags);
+	if (proto_ver == PRP_V1) {
+		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);
+		rct->sequence_nr = htons(master->priv->sequence_nr);
+		master->priv->sequence_nr++;
+	}
+	spin_unlock_irqrestore(&master->priv->seqnr_lock, irqflags);
 	hsr_prp_forward_skb(skb, master);
 	return;
 
@@ -328,8 +352,14 @@ static void hsr_prp_announce(struct timer_list *t)
 
 		interval = msecs_to_jiffies(HSR_PRP_ANNOUNCE_INTERVAL);
 	} else {
-		send_hsr_prp_supervision_frame(master, HSR_TLV_LIFE_CHECK,
-					       priv->prot_version);
+		if (priv->prot_version <= HSR_V1)
+			send_hsr_prp_supervision_frame(master,
+						       HSR_TLV_LIFE_CHECK,
+						       priv->prot_version);
+		else /* PRP */
+			send_hsr_prp_supervision_frame(master,
+						       PRP_TLV_LIFE_CHECK_DD,
+						       priv->prot_version);
 
 		interval = msecs_to_jiffies(HSR_PRP_LIFE_CHECK_INTERVAL);
 	}
diff --git a/net/hsr-prp/hsr_prp_forward.c b/net/hsr-prp/hsr_prp_forward.c
index 59b33d711ea6..d7e975919322 100644
--- a/net/hsr-prp/hsr_prp_forward.c
+++ b/net/hsr-prp/hsr_prp_forward.c
@@ -74,7 +74,9 @@ static bool is_supervision_frame(struct hsr_prp_priv *priv, struct sk_buff *skb)
 	}
 
 	if (hsr_sup_tag->HSR_TLV_type != HSR_TLV_ANNOUNCE &&
-	    hsr_sup_tag->HSR_TLV_type != HSR_TLV_LIFE_CHECK)
+	    hsr_sup_tag->HSR_TLV_type != HSR_TLV_LIFE_CHECK &&
+	    hsr_sup_tag->HSR_TLV_type != PRP_TLV_LIFE_CHECK_DD &&
+	    hsr_sup_tag->HSR_TLV_type != PRP_TLV_LIFE_CHECK_DA)
 		return false;
 	if (hsr_sup_tag->HSR_TLV_length != 12 &&
 	    hsr_sup_tag->HSR_TLV_length != sizeof(struct hsr_prp_sup_payload))
diff --git a/net/hsr-prp/hsr_prp_main.h b/net/hsr-prp/hsr_prp_main.h
index 00c312e5189f..17049d040226 100644
--- a/net/hsr-prp/hsr_prp_main.h
+++ b/net/hsr-prp/hsr_prp_main.h
@@ -33,6 +33,10 @@
 
 #define HSR_TLV_ANNOUNCE		   22
 #define HSR_TLV_LIFE_CHECK		   23
+/* PRP V1 life check for Duplicate discard */
+#define PRP_TLV_LIFE_CHECK_DD		   20
+/* PRP V1 life check for Duplicate Accept */
+#define PRP_TLV_LIFE_CHECK_DA		   21
 
 /* HSR Tag.
  * As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB,
@@ -125,6 +129,24 @@ enum hsr_prp_port_type {
 	HSR_PRP_PT_PORTS,	/* This must be the last item in the enum */
 };
 
+/* PRP Redunancy Control Trailor (RCT).
+ * As defined in IEC-62439-4:2012, the PRP RCT is really { sequence Nr,
+ * Lan indentifier (LanId), LSDU_size and PRP_suffix = 0x88FB }.
+ *
+ * Field names as defined in the IEC:2012 standard for PRP.
+ */
+struct prp_rct {
+	__be16		sequence_nr;
+	__be16		lan_id_and_LSDU_size;
+	__be16		PRP_suffix;
+} __packed;
+
+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) &
+					  0xF000) | (LSDU_size & 0x0FFF));
+}
+
 struct hsr_prp_port {
 	struct list_head	port_list;
 	struct net_device	*dev;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 12/13] net: prp: add packet handling support
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (10 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 11/13] net: prp: add supervision frame generation and handling support Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-06 16:30 ` [net-next RFC PATCH 13/13] net: prp: enhance debugfs to display PRP specific info in node table Murali Karicheri
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

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 <m-karicheri2@ti.com>
---
 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 <linux/netdevice.h>
 #include <linux/list.h>
+#include <linux/if_vlan.h>
 
 /* 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);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [net-next RFC PATCH 13/13] net: prp: enhance debugfs to display PRP specific info in node table
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (11 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 12/13] net: prp: add packet " Murali Karicheri
@ 2020-05-06 16:30 ` Murali Karicheri
  2020-05-13 12:27 ` [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
  2020-05-21 17:31 ` Vinicius Costa Gomes
  14 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-06 16:30 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

Print PRP specific information from node table as part of debugfs
node table display

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 net/hsr-prp/hsr_prp_debugfs.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/net/hsr-prp/hsr_prp_debugfs.c b/net/hsr-prp/hsr_prp_debugfs.c
index 7d8dd5ab3afd..28580de4de44 100644
--- a/net/hsr-prp/hsr_prp_debugfs.c
+++ b/net/hsr-prp/hsr_prp_debugfs.c
@@ -37,7 +37,11 @@ hsr_prp_node_table_show(struct seq_file *sfp, void *data)
 
 	seq_puts(sfp, "Node Table entries\n");
 	seq_puts(sfp, "MAC-Address-A,   MAC-Address-B, time_in[A], ");
-	seq_puts(sfp, "time_in[B], Address-B port\n");
+	seq_puts(sfp, "time_in[B], Address-B port");
+	if (priv->prot_version == PRP_V1)
+		seq_puts(sfp, ", san_a, san_b\n");
+	else
+		seq_puts(sfp, "\n");
 	rcu_read_lock();
 	list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
 		/* skip self node */
@@ -48,7 +52,12 @@ hsr_prp_node_table_show(struct seq_file *sfp, void *data)
 		print_mac_address(sfp, &node->macaddress_B[0]);
 		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);
+		seq_printf(sfp, "0x%x", node->addr_B_port);
+
+		if (priv->prot_version == PRP_V1)
+			seq_printf(sfp, ", %x, %x\n", node->san_a, node->san_b);
+		else
+			seq_puts(sfp, "\n");
 	}
 	rcu_read_unlock();
 	return 0;
@@ -57,7 +66,8 @@ hsr_prp_node_table_show(struct seq_file *sfp, void *data)
 /* hsr_prp_node_table_open - Open the node_table file
  *
  * Description:
- * This routine opens a debugfs file node_table of specific hsr device
+ * This routine opens a debugfs file node_table of specific hsr
+ * or prp device
  */
 static int
 hsr_prp_node_table_open(struct inode *inode, struct file *filp)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (12 preceding siblings ...)
  2020-05-06 16:30 ` [net-next RFC PATCH 13/13] net: prp: enhance debugfs to display PRP specific info in node table Murali Karicheri
@ 2020-05-13 12:27 ` Murali Karicheri
  2020-05-21 12:34   ` Murali Karicheri
  2020-05-21 17:31 ` Vinicius Costa Gomes
  14 siblings, 1 reply; 25+ messages in thread
From: Murali Karicheri @ 2020-05-13 12:27 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

Hello netdev experts,

On 5/6/20 12:30 PM, Murali Karicheri wrote:
> This RFC series add support for Parallel Redundancy Protocol (PRP)
> as defined in IEC-62439-3 in the kernel networking subsystem. PRP
> Uses a Redundancy Control Trailer (RCT) the format of which is
> similar to HSR Tag. This is used for implementing redundancy.
> RCT consists of 6 bytes similar to HSR tag and contain following
> fields:-
> 
> - 16-bit sequence number (SeqNr);
> - 4-bit LAN identifier (LanId);
> - 12 bit frame size (LSDUsize);
> - 16-bit suffix (PRPsuffix).
> 
> The PRPsuffix identifies PRP frames and distinguishes PRP frames
> from other protocols that also append a trailer to their useful
> data. The LSDUsize field allows the receiver to distinguish PRP
> frames from random, nonredundant frames as an additional check.
> LSDUsize is the size of the Ethernet payload inclusive of the
> RCT. Sequence number along with LanId is used for duplicate
> detection and discard.
> 
> PRP node is also known as Dual Attached Node (DAN-P) since it
> is typically attached to two different LAN for redundancy.
> DAN-P duplicates each of L2 frames and send it over the two
> Ethernet links. Each outgoing frame is appended with RCT.
> Unlike HSR, these are added to the end of L2 frame and may be
> treated as padding by bridges and therefore would be work with
> traditional bridges or switches, where as HSR wouldn't as Tag
> is prefixed to the Ethenet frame. At the remote end, these are
> received and the duplicate frame is discarded before the stripped
> frame is send up the networking stack. Like HSR, PRP also sends
> periodic Supervision frames to the network. These frames are
> received and MAC address from the SV frames are populated in a
> database called Node Table. The above functions are grouped into
> a block called Link Redundancy Entity (LRE) in the IEC spec.
> 
> As there are many similarities between HSR and PRP protocols,
> this patch re-use the code from HSR driver to implement PRP
> driver. As many part of the code can be re-used, this patch
> introduces a new common API definitions for both protocols and
> propose to obsolete the existing HSR defines in
> include/uapi/linux/if_link.h. New definitions are prefixed
> with a HSR_PRP prefix. Similarly include/uapi/linux/hsr_netlink.h
> is proposed to be replaced with include/uapi/linux/hsr_prp_netlink.h
> which also uses the HSR_PRP prefix. The netlink socket interface
> code is migrated (as well as the iproute2 being sent as a follow up
> patch) to use the new API definitions. To re-use the code,
> following are done as a preparatory patch before adding the PRP
> functionality:-
> 
>    - prefix all common code with hsr_prp
>    - net/hsr -> renamed to net/hsr-prp
>    - All common struct types, constants, functions renamed with
>      hsr{HSR}_prp{PRP} prefix.
> 
> Please review this and provide me feedback so that I can work to
> incorporate them and send a formal patch series for this. As this
> series impacts user space, I am not sure if this is the right
> approach to introduce a new definitions and obsolete the old
> API definitions for HSR. The current approach is choosen
> to avoid redundant code in iproute2 and in the netlink driver
> code (hsr_netlink.c). Other approach we discussed internally was
> to Keep the HSR prefix in the user space and kernel code, but
> live with the redundant code in the iproute2 and hsr netlink
> code. Would like to hear from you what is the best way to add
> this feature to networking core. If there is any other
> alternative approach possible, I would like to hear about the
> same.
> 
> The patch was tested using two TI AM57x IDK boards which are
> connected back to back over two CPSW ports.
> 
> Script used for creating the hsr/prp interface is given below
> and uses the ip link command. Also provided logs from the tests
> I have executed for your reference.
> 
> iproute2 related patches will follow soon....
Could someone please review this and provide some feedback to take
this forward?

Thanks and regards,
> 
> Murali Karicheri
> Texas Instruments


-Cut-------------------------

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-13 12:27 ` [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
@ 2020-05-21 12:34   ` Murali Karicheri
  0 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-21 12:34 UTC (permalink / raw)
  To: davem, kuba, netdev, linux-kernel, linux-api, nsekhar, grygorii.strashko

Hi David, et all,

On 5/13/20 8:27 AM, Murali Karicheri wrote:
> Hello netdev experts,
> 
> On 5/6/20 12:30 PM, Murali Karicheri wrote:
>> This RFC series add support for Parallel Redundancy Protocol (PRP)
>> as defined in IEC-62439-3 in the kernel networking subsystem. PRP
>> Uses a Redundancy Control Trailer (RCT) the format of which is
>> similar to HSR Tag. This is used for implementing redundancy.
>> RCT consists of 6 bytes similar to HSR tag and contain following
>> fields:-
>>
>> - 16-bit sequence number (SeqNr);
>> - 4-bit LAN identifier (LanId);
>> - 12 bit frame size (LSDUsize);
>> - 16-bit suffix (PRPsuffix).
>>
>> The PRPsuffix identifies PRP frames and distinguishes PRP frames
>> from other protocols that also append a trailer to their useful
>> data. The LSDUsize field allows the receiver to distinguish PRP
>> frames from random, nonredundant frames as an additional check.
>> LSDUsize is the size of the Ethernet payload inclusive of the
>> RCT. Sequence number along with LanId is used for duplicate
>> detection and discard.
>>
>> PRP node is also known as Dual Attached Node (DAN-P) since it
>> is typically attached to two different LAN for redundancy.
>> DAN-P duplicates each of L2 frames and send it over the two
>> Ethernet links. Each outgoing frame is appended with RCT.
>> Unlike HSR, these are added to the end of L2 frame and may be
>> treated as padding by bridges and therefore would be work with
>> traditional bridges or switches, where as HSR wouldn't as Tag
>> is prefixed to the Ethenet frame. At the remote end, these are
>> received and the duplicate frame is discarded before the stripped
>> frame is send up the networking stack. Like HSR, PRP also sends
>> periodic Supervision frames to the network. These frames are
>> received and MAC address from the SV frames are populated in a
>> database called Node Table. The above functions are grouped into
>> a block called Link Redundancy Entity (LRE) in the IEC spec.
>>
>> As there are many similarities between HSR and PRP protocols,
>> this patch re-use the code from HSR driver to implement PRP
>> driver. As many part of the code can be re-used, this patch
>> introduces a new common API definitions for both protocols and
>> propose to obsolete the existing HSR defines in
>> include/uapi/linux/if_link.h. New definitions are prefixed
>> with a HSR_PRP prefix. Similarly include/uapi/linux/hsr_netlink.h
>> is proposed to be replaced with include/uapi/linux/hsr_prp_netlink.h
>> which also uses the HSR_PRP prefix. The netlink socket interface
>> code is migrated (as well as the iproute2 being sent as a follow up
>> patch) to use the new API definitions. To re-use the code,
>> following are done as a preparatory patch before adding the PRP
>> functionality:-
>>
>>    - prefix all common code with hsr_prp
>>    - net/hsr -> renamed to net/hsr-prp
>>    - All common struct types, constants, functions renamed with
>>      hsr{HSR}_prp{PRP} prefix.
>>
>> Please review this and provide me feedback so that I can work to
>> incorporate them and send a formal patch series for this. As this
>> series impacts user space, I am not sure if this is the right
>> approach to introduce a new definitions and obsolete the old
>> API definitions for HSR. The current approach is choosen
>> to avoid redundant code in iproute2 and in the netlink driver
>> code (hsr_netlink.c). Other approach we discussed internally was
>> to Keep the HSR prefix in the user space and kernel code, but
>> live with the redundant code in the iproute2 and hsr netlink
>> code. Would like to hear from you what is the best way to add
>> this feature to networking core. If there is any other
>> alternative approach possible, I would like to hear about the
>> same.
>>
>> The patch was tested using two TI AM57x IDK boards which are
>> connected back to back over two CPSW ports.
>>
>> Script used for creating the hsr/prp interface is given below
>> and uses the ip link command. Also provided logs from the tests
>> I have executed for your reference.
>>
>> iproute2 related patches will follow soon....
> Could someone please review this and provide some feedback to take
> this forward?
> 
> Thanks and regards,
>>
>> Murali Karicheri
>> Texas Instruments
> 
> 
> -Cut-------------------------

I plan to send a formal patch early next week as we would like to move
forward with this series. So please take some high level look at this
and guide me if I am on the right track or this requires rework for
a formal patch.
-- 
Murali Karicheri
Texas Instruments

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
                   ` (13 preceding siblings ...)
  2020-05-13 12:27 ` [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
@ 2020-05-21 17:31 ` Vinicius Costa Gomes
  2020-05-25 16:49   ` Murali Karicheri
  2020-05-25 21:37   ` Vladimir Oltean
  14 siblings, 2 replies; 25+ messages in thread
From: Vinicius Costa Gomes @ 2020-05-21 17:31 UTC (permalink / raw)
  To: Murali Karicheri, davem, kuba, netdev, linux-kernel, linux-api,
	nsekhar, grygorii.strashko

Murali Karicheri <m-karicheri2@ti.com> writes:

> This RFC series add support for Parallel Redundancy Protocol (PRP)
> as defined in IEC-62439-3 in the kernel networking subsystem. PRP 
> Uses a Redundancy Control Trailer (RCT) the format of which is
> similar to HSR Tag. This is used for implementing redundancy.
> RCT consists of 6 bytes similar to HSR tag and contain following
> fields:-
>
> - 16-bit sequence number (SeqNr);
> - 4-bit LAN identifier (LanId);
> - 12 bit frame size (LSDUsize);
> - 16-bit suffix (PRPsuffix). 
>
> The PRPsuffix identifies PRP frames and distinguishes PRP frames
> from other protocols that also append a trailer to their useful
> data. The LSDUsize field allows the receiver to distinguish PRP
> frames from random, nonredundant frames as an additional check.
> LSDUsize is the size of the Ethernet payload inclusive of the
> RCT. Sequence number along with LanId is used for duplicate
> detection and discard.
>
> PRP node is also known as Dual Attached Node (DAN-P) since it
> is typically attached to two different LAN for redundancy.
> DAN-P duplicates each of L2 frames and send it over the two
> Ethernet links. Each outgoing frame is appended with RCT.
> Unlike HSR, these are added to the end of L2 frame and may be
> treated as padding by bridges and therefore would be work with
> traditional bridges or switches, where as HSR wouldn't as Tag
> is prefixed to the Ethenet frame. At the remote end, these are
> received and the duplicate frame is discarded before the stripped
> frame is send up the networking stack. Like HSR, PRP also sends
> periodic Supervision frames to the network. These frames are
> received and MAC address from the SV frames are populated in a
> database called Node Table. The above functions are grouped into
> a block called Link Redundancy Entity (LRE) in the IEC spec.
>
> As there are many similarities between HSR and PRP protocols,
> this patch re-use the code from HSR driver to implement PRP
> driver. As many part of the code can be re-used, this patch
> introduces a new common API definitions for both protocols and
> propose to obsolete the existing HSR defines in
> include/uapi/linux/if_link.h. New definitions are prefixed 
> with a HSR_PRP prefix. Similarly include/uapi/linux/hsr_netlink.h
> is proposed to be replaced with include/uapi/linux/hsr_prp_netlink.h
> which also uses the HSR_PRP prefix. The netlink socket interface
> code is migrated (as well as the iproute2 being sent as a follow up
> patch) to use the new API definitions. To re-use the code,
> following are done as a preparatory patch before adding the PRP
> functionality:-
>
>   - prefix all common code with hsr_prp
>   - net/hsr -> renamed to net/hsr-prp
>   - All common struct types, constants, functions renamed with
>     hsr{HSR}_prp{PRP} prefix.

I don't really like these prefixes, I am thinking of when support for
IEEE 802.1CB is added, do we rename this to "hsr_prp_frer"?

And it gets even more complicated, and using 802.1CB you can configure
the tagging method and the stream identification function so a system
can interoperate in a HSR or PRP network.

So, I see this as different methods of achieving the same result, which
makes me think that the different "methods/types" (HSR and PRP in your
case) should be basically different implementations of a "struct
hsr_ops" interface. With this hsr_ops something like this:

   struct hsr_ops {
          int (*handle_frame)()
          int (*add_port)()
          int (*remove_port)()
          int (*setup)()
          void (*teardown)()
   };

>
> Please review this and provide me feedback so that I can work to
> incorporate them and send a formal patch series for this. As this
> series impacts user space, I am not sure if this is the right
> approach to introduce a new definitions and obsolete the old
> API definitions for HSR. The current approach is choosen
> to avoid redundant code in iproute2 and in the netlink driver
> code (hsr_netlink.c). Other approach we discussed internally was
> to Keep the HSR prefix in the user space and kernel code, but
> live with the redundant code in the iproute2 and hsr netlink
> code. Would like to hear from you what is the best way to add
> this feature to networking core. If there is any other
> alternative approach possible, I would like to hear about the
> same.

Why redudant code is needed in the netlink parts and in iproute2 when
keeping the hsr prefix?

>
> The patch was tested using two TI AM57x IDK boards which are
> connected back to back over two CPSW ports. 
>
> Script used for creating the hsr/prp interface is given below
> and uses the ip link command. Also provided logs from the tests
> I have executed for your reference. 
>
> iproute2 related patches will follow soon....
>
> Murali Karicheri
> Texas Instruments
>
> ============ setup.sh =================================================
> #!/bin/sh
> if [ $# -lt 4 ]
> then
>        echo "setup-cpsw.sh <hsr/prp> <MAC-Address of slave-A>"
>        echo "  <ip address for hsr/prp interface>"
>        echo "  <if_name of hsr/prp interface>"
>        exit
> fi
>
> if [ "$1" != "hsr" ] && [ "$1" != "prp" ]
> then
>        echo "use hsr or prp as first argument"
>        exit
> fi
>
> if_a=eth2
> if_b=eth3
> if_name=$4
>
> ifconfig $if_a down
> ifconfig $if_b down
> ifconfig $if_a hw ether $2
> ifconfig $if_b hw ether $2
> ifconfig $if_a up
> ifconfig $if_b up
>
> echo "Setting up $if_name with MAC address $2 for slaves and IP address $3"
> echo "          using $if_a and $if_b"
>
> if [ "$1" = "hsr" ]; then
>        options="version 1"
> else
>        options=""
> fi
>
> ip link add name $if_name type $1 slave1 $if_a slave2 $if_b supervision 0 $options
> ifconfig $if_name $3 up
> ==================================================================================
> PRP Logs:
>
> DUT-1 : https://pastebin.ubuntu.com/p/hhsRjTQpcr/
> DUT-2 : https://pastebin.ubuntu.com/p/snPFKhnpk4/
>
> HSR Logs:
>
> DUT-1 : https://pastebin.ubuntu.com/p/FZPNc6Nwdm/
> DUT-2 : https://pastebin.ubuntu.com/p/CtV4ZVS3Yd/
>
> Murali Karicheri (13):
>   net: hsr: Re-use Kconfig option to support PRP
>   net: hsr: rename hsr directory to hsr-prp to introduce PRP
>   net: hsr: rename files to introduce PRP support
>   net: hsr: rename hsr variable inside struct hsr_port to priv
>   net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port()
>   net: hsr: some renaming to introduce PRP driver support
>   net: hsr: introduce common uapi include/definitions for HSR and PRP
>   net: hsr: migrate HSR netlink socket code to use new common API
>   net: hsr: move re-usable code for PRP to hsr_prp_netlink.c
>   net: hsr: add netlink socket interface for PRP
>   net: prp: add supervision frame generation and handling support
>   net: prp: add packet handling support
>   net: prp: enhance debugfs to display PRP specific info in node table
>
>  MAINTAINERS                                   |   2 +-
>  include/uapi/linux/hsr_netlink.h              |   3 +
>  include/uapi/linux/hsr_prp_netlink.h          |  50 ++
>  include/uapi/linux/if_link.h                  |  19 +
>  net/Kconfig                                   |   2 +-
>  net/Makefile                                  |   2 +-
>  net/hsr-prp/Kconfig                           |  37 ++
>  net/hsr-prp/Makefile                          |  11 +
>  net/hsr-prp/hsr_netlink.c                     | 202 +++++++
>  net/{hsr => hsr-prp}/hsr_netlink.h            |  15 +-
>  .../hsr_prp_debugfs.c}                        |  82 +--
>  net/hsr-prp/hsr_prp_device.c                  | 562 ++++++++++++++++++
>  net/hsr-prp/hsr_prp_device.h                  |  23 +
>  net/hsr-prp/hsr_prp_forward.c                 | 558 +++++++++++++++++
>  .../hsr_prp_forward.h}                        |  10 +-
>  .../hsr_prp_framereg.c}                       | 323 +++++-----
>  net/hsr-prp/hsr_prp_framereg.h                |  68 +++
>  net/hsr-prp/hsr_prp_main.c                    | 194 ++++++
>  net/hsr-prp/hsr_prp_main.h                    | 289 +++++++++
>  net/hsr-prp/hsr_prp_netlink.c                 | 365 ++++++++++++
>  net/hsr-prp/hsr_prp_netlink.h                 |  28 +
>  net/hsr-prp/hsr_prp_slave.c                   | 222 +++++++
>  net/hsr-prp/hsr_prp_slave.h                   |  37 ++
>  net/hsr-prp/prp_netlink.c                     | 141 +++++
>  net/hsr-prp/prp_netlink.h                     |  27 +
>  net/hsr/Kconfig                               |  29 -
>  net/hsr/Makefile                              |  10 -
>  net/hsr/hsr_device.c                          | 509 ----------------
>  net/hsr/hsr_device.h                          |  22 -
>  net/hsr/hsr_forward.c                         | 379 ------------
>  net/hsr/hsr_framereg.h                        |  62 --
>  net/hsr/hsr_main.c                            | 154 -----
>  net/hsr/hsr_main.h                            | 188 ------
>  net/hsr/hsr_netlink.c                         | 514 ----------------
>  net/hsr/hsr_slave.c                           | 198 ------
>  net/hsr/hsr_slave.h                           |  33 -
>  36 files changed, 3084 insertions(+), 2286 deletions(-)
>  create mode 100644 include/uapi/linux/hsr_prp_netlink.h
>  create mode 100644 net/hsr-prp/Kconfig
>  create mode 100644 net/hsr-prp/Makefile
>  create mode 100644 net/hsr-prp/hsr_netlink.c
>  rename net/{hsr => hsr-prp}/hsr_netlink.h (58%)
>  rename net/{hsr/hsr_debugfs.c => hsr-prp/hsr_prp_debugfs.c} (52%)
>  create mode 100644 net/hsr-prp/hsr_prp_device.c
>  create mode 100644 net/hsr-prp/hsr_prp_device.h
>  create mode 100644 net/hsr-prp/hsr_prp_forward.c
>  rename net/{hsr/hsr_forward.h => hsr-prp/hsr_prp_forward.h} (50%)
>  rename net/{hsr/hsr_framereg.c => hsr-prp/hsr_prp_framereg.c} (56%)
>  create mode 100644 net/hsr-prp/hsr_prp_framereg.h
>  create mode 100644 net/hsr-prp/hsr_prp_main.c
>  create mode 100644 net/hsr-prp/hsr_prp_main.h
>  create mode 100644 net/hsr-prp/hsr_prp_netlink.c
>  create mode 100644 net/hsr-prp/hsr_prp_netlink.h
>  create mode 100644 net/hsr-prp/hsr_prp_slave.c
>  create mode 100644 net/hsr-prp/hsr_prp_slave.h
>  create mode 100644 net/hsr-prp/prp_netlink.c
>  create mode 100644 net/hsr-prp/prp_netlink.h
>  delete mode 100644 net/hsr/Kconfig
>  delete mode 100644 net/hsr/Makefile
>  delete mode 100644 net/hsr/hsr_device.c
>  delete mode 100644 net/hsr/hsr_device.h
>  delete mode 100644 net/hsr/hsr_forward.c
>  delete mode 100644 net/hsr/hsr_framereg.h
>  delete mode 100644 net/hsr/hsr_main.c
>  delete mode 100644 net/hsr/hsr_main.h
>  delete mode 100644 net/hsr/hsr_netlink.c
>  delete mode 100644 net/hsr/hsr_slave.c
>  delete mode 100644 net/hsr/hsr_slave.h
>
> -- 
> 2.17.1
>

-- 
Vinicius

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-21 17:31 ` Vinicius Costa Gomes
@ 2020-05-25 16:49   ` Murali Karicheri
  2020-05-26 18:56     ` Vinicius Costa Gomes
  2020-05-25 21:37   ` Vladimir Oltean
  1 sibling, 1 reply; 25+ messages in thread
From: Murali Karicheri @ 2020-05-25 16:49 UTC (permalink / raw)
  To: Vinicius Costa Gomes, davem, kuba, netdev, linux-kernel,
	linux-api, nsekhar, grygorii.strashko

Hi Vinicius,

On 5/21/20 1:31 PM, Vinicius Costa Gomes wrote:
> Murali Karicheri <m-karicheri2@ti.com> writes:
> 
------------ Snip-------------

>>    - prefix all common code with hsr_prp
>>    - net/hsr -> renamed to net/hsr-prp
>>    - All common struct types, constants, functions renamed with
>>      hsr{HSR}_prp{PRP} prefix.
> 
> I don't really like these prefixes, I am thinking of when support for
> IEEE 802.1CB is added, do we rename this to "hsr_prp_frer"?
> 
> And it gets even more complicated, and using 802.1CB you can configure
> the tagging method and the stream identification function so a system
> can interoperate in a HSR or PRP network.
> 
> So, I see this as different methods of achieving the same result, which
> makes me think that the different "methods/types" (HSR and PRP in your
> case) should be basically different implementations of a "struct
> hsr_ops" interface. With this hsr_ops something like this:
> 
>     struct hsr_ops {
>            int (*handle_frame)()
>            int (*add_port)()
>            int (*remove_port)()
>            int (*setup)()
>            void (*teardown)()
>     };
> 

Thanks for your response!

I agree with you that the prefix renaming is ugly. However I wasn't
sure if it is okay to use a hsr prefixed code to handle PRP as
well as it may not be intuitive to anyone investigating the code. For
the same reason, handling 802.1CB specifc functions using the hsr_
prefixed code. If that is okay, then patch 1-6 are unnecessary. We could
also add some documentation at the top of the file to indicate that
both hsr and prp are implemented in the code or something like that.
BTW, I need to investigate more into 802.1CB and this was not known
when I developed this code few years ago.

Main difference between HSR and PRP is how they handle the protocol tag
or rct and create or handle the protocol specific part in the frame.
For that part, we should be able to define ops() like you have
suggested, instead of doing if check throughout the code. Hope that
is what you meant by hsr_ops() for this. Again shouldn't we use some 
generic name like proto_ops or red_ops instead of hsr_ops() and assign
protocol specific implementaion to them? i.e hsr_ or prp_
or 802.1CB specific functions assigned to the function pointers. For
now I see handle_frame(), handle_sv_frame, create_frame(), 
create_sv_frame() etc implemented differently (This is currently part of
patch 11 & 12). So something like

    struct proto_ops {
	int (*handle_frame)();
	int (*create_frame)();
	int (*handle_sv_frame)();
	int (*create_sv_frame)();
    };

and call dev->proto_ops->handle_frame() to process a frame from the
main hook. proto_ops gets initialized to of the set if implementation
at device or interface creation in hsr_dev_finalize().

>>
>> Please review this and provide me feedback so that I can work to
>> incorporate them and send a formal patch series for this. As this
>> series impacts user space, I am not sure if this is the right
>> approach to introduce a new definitions and obsolete the old
>> API definitions for HSR. The current approach is choosen
>> to avoid redundant code in iproute2 and in the netlink driver
>> code (hsr_netlink.c). Other approach we discussed internally was
>> to Keep the HSR prefix in the user space and kernel code, but
>> live with the redundant code in the iproute2 and hsr netlink
>> code. Would like to hear from you what is the best way to add
>> this feature to networking core. If there is any other
>> alternative approach possible, I would like to hear about the
>> same.
> 
> Why redudant code is needed in the netlink parts and in iproute2 when
> keeping the hsr prefix?

May be this is due to the specific implementation that I chose.
Currently I have separate netlink socket for HSR and PRP which may
be an overkill since bith are similar protocol.

Currently hsr inteface is created as

ip link add name hsr0 type hsr slave1 eth0 slave2 eth1 supervision 0

So I have implemented similar command for prp

ip link add name prp0 type prp slave1 eth0 slave2 eth1 supervision 0

In patch 7/13 I renamed existing HSR netlink socket attributes that
defines the hsr interface with the assumption that we can obsolete
the old definitions in favor of new common definitions with the
HSR_PRP prefix. Then I have separate code for creating prp
interface and related functions, even though they are similar.
So using common definitions, I re-use the code in netlink and
iproute2 (see patch 8 and 9 to re-use the code). PRP netlink
socket code in patch 10 which register prp_genl_family similar
to HSR.

+static struct genl_family prp_genl_family __ro_after_init = {
+	.hdrsize = 0,
+	.name = "PRP",
+	.version = 1,
+	.maxattr = HSR_PRP_A_MAX,
+	.policy = prp_genl_policy,
+	.module = THIS_MODULE,
+	.ops = prp_ops,
+	.n_ops = ARRAY_SIZE(prp_ops),
+	.mcgrps = prp_mcgrps,
+	.n_mcgrps = ARRAY_SIZE(prp_mcgrps),
+};
+
+int __init prp_netlink_init(void)
+{
+	int rc;
+
+	rc = rtnl_link_register(&prp_link_ops);
+	if (rc)
+		goto fail_rtnl_link_register;
+
+	rc = genl_register_family(&prp_genl_family);
+	if (rc)
+		goto fail_genl_register_family;


If we choose to re-use the existing HSR_ uapi defines, then should we
re-use the hsr netlink socket interface for PRP as well and
add additional attribute for differentiating the protocol specific
part?

i.e introduce protocol attribute to existing HSR uapi defines for
netlink socket to handle creation of prp interface.

enum {
	HSR_A_UNSPEC,
	HSR_A_NODE_ADDR,
	HSR_A_IFINDEX,
	HSR_A_IF1_AGE,
	HSR_A_IF2_AGE,
	HSR_A_NODE_ADDR_B,
	HSR_A_IF1_SEQ,
	HSR_A_IF2_SEQ,
	HSR_A_IF1_IFINDEX,
	HSR_A_IF2_IFINDEX,
	HSR_A_ADDR_B_IFINDEX,
+       HSR_A_PROTOCOL  <====if missing it is HSR (backward 	
			     compatibility)
                              defines HSR or PRP or 802.1CB in future.
	__HSR_A_MAX,
};

So if ip link command is

ip link add name <if name> type <proto> slave1 eth0 slave2 eth1 
supervision 0

Add HSR_A_PROTOCOL attribute with HSR/PRP specific value.

This way, the iprout2 code mostly remain the same as hsr, but will
change a bit to introduced this new attribute if user choose proto as
'prp' vs 'hsr'

BTW, I have posted the existing iproute2 code also to the mailing list
with title 'iproute2: Add PRP support'.

If re-using hsr code with existing prefix is fine for PRP or any future
protocol such as 801.1B, then I will drop patch 1-6 that are essentially
doing some renaming and re-use existing hsr netlink code for PRP with
added attribute to differentiate the protocol at the driver as described
above along with proto_ops and re-spin the series.

Let me know.

Regards,

Murali
> 
>>
>> The patch was tested using two TI AM57x IDK boards which are
>> connected back to back over two CPSW ports.
>>
>> Script used for creating the hsr/prp interface is given below
>> and uses the ip link command. Also provided logs from the tests
>> I have executed for your reference.
>>
>> iproute2 related patches will follow soon....
>>
>> Murali Karicheri
>> Texas Instruments
>>
>> ============ setup.sh =================================================
>> #!/bin/sh
>> if [ $# -lt 4 ]
>> then
>>         echo "setup-cpsw.sh <hsr/prp> <MAC-Address of slave-A>"
>>         echo "  <ip address for hsr/prp interface>"
>>         echo "  <if_name of hsr/prp interface>"
>>         exit
>> fi
>>
>> if [ "$1" != "hsr" ] && [ "$1" != "prp" ]
>> then
>>         echo "use hsr or prp as first argument"
>>         exit
>> fi
>>
>> if_a=eth2
>> if_b=eth3
>> if_name=$4
>>
>> ifconfig $if_a down
>> ifconfig $if_b down
>> ifconfig $if_a hw ether $2
>> ifconfig $if_b hw ether $2
>> ifconfig $if_a up
>> ifconfig $if_b up
>>
>> echo "Setting up $if_name with MAC address $2 for slaves and IP address $3"
>> echo "          using $if_a and $if_b"
>>
>> if [ "$1" = "hsr" ]; then
>>         options="version 1"
>> else
>>         options=""
>> fi
>>
>> ip link add name $if_name type $1 slave1 $if_a slave2 $if_b supervision 0 $options
>> ifconfig $if_name $3 up
>> ==================================================================================
>> PRP Logs:
>>
>> DUT-1 : https://pastebin.ubuntu.com/p/hhsRjTQpcr/
>> DUT-2 : https://pastebin.ubuntu.com/p/snPFKhnpk4/
>>
>> HSR Logs:
>>
>> DUT-1 : https://pastebin.ubuntu.com/p/FZPNc6Nwdm/
>> DUT-2 : https://pastebin.ubuntu.com/p/CtV4ZVS3Yd/
>>
>> Murali Karicheri (13):
>>    net: hsr: Re-use Kconfig option to support PRP
>>    net: hsr: rename hsr directory to hsr-prp to introduce PRP
>>    net: hsr: rename files to introduce PRP support
>>    net: hsr: rename hsr variable inside struct hsr_port to priv
>>    net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port()
>>    net: hsr: some renaming to introduce PRP driver support
>>    net: hsr: introduce common uapi include/definitions for HSR and PRP
>>    net: hsr: migrate HSR netlink socket code to use new common API
>>    net: hsr: move re-usable code for PRP to hsr_prp_netlink.c
>>    net: hsr: add netlink socket interface for PRP
>>    net: prp: add supervision frame generation and handling support
>>    net: prp: add packet handling support
>>    net: prp: enhance debugfs to display PRP specific info in node table
>>
>>   MAINTAINERS                                   |   2 +-
>>   include/uapi/linux/hsr_netlink.h              |   3 +
>>   include/uapi/linux/hsr_prp_netlink.h          |  50 ++
>>   include/uapi/linux/if_link.h                  |  19 +
>>   net/Kconfig                                   |   2 +-
>>   net/Makefile                                  |   2 +-
>>   net/hsr-prp/Kconfig                           |  37 ++
>>   net/hsr-prp/Makefile                          |  11 +
>>   net/hsr-prp/hsr_netlink.c                     | 202 +++++++
>>   net/{hsr => hsr-prp}/hsr_netlink.h            |  15 +-
>>   .../hsr_prp_debugfs.c}                        |  82 +--
>>   net/hsr-prp/hsr_prp_device.c                  | 562 ++++++++++++++++++
>>   net/hsr-prp/hsr_prp_device.h                  |  23 +
>>   net/hsr-prp/hsr_prp_forward.c                 | 558 +++++++++++++++++
>>   .../hsr_prp_forward.h}                        |  10 +-
>>   .../hsr_prp_framereg.c}                       | 323 +++++-----
>>   net/hsr-prp/hsr_prp_framereg.h                |  68 +++
>>   net/hsr-prp/hsr_prp_main.c                    | 194 ++++++
>>   net/hsr-prp/hsr_prp_main.h                    | 289 +++++++++
>>   net/hsr-prp/hsr_prp_netlink.c                 | 365 ++++++++++++
>>   net/hsr-prp/hsr_prp_netlink.h                 |  28 +
>>   net/hsr-prp/hsr_prp_slave.c                   | 222 +++++++
>>   net/hsr-prp/hsr_prp_slave.h                   |  37 ++
>>   net/hsr-prp/prp_netlink.c                     | 141 +++++
>>   net/hsr-prp/prp_netlink.h                     |  27 +
>>   net/hsr/Kconfig                               |  29 -
>>   net/hsr/Makefile                              |  10 -
>>   net/hsr/hsr_device.c                          | 509 ----------------
>>   net/hsr/hsr_device.h                          |  22 -
>>   net/hsr/hsr_forward.c                         | 379 ------------
>>   net/hsr/hsr_framereg.h                        |  62 --
>>   net/hsr/hsr_main.c                            | 154 -----
>>   net/hsr/hsr_main.h                            | 188 ------
>>   net/hsr/hsr_netlink.c                         | 514 ----------------
>>   net/hsr/hsr_slave.c                           | 198 ------
>>   net/hsr/hsr_slave.h                           |  33 -
>>   36 files changed, 3084 insertions(+), 2286 deletions(-)
>>   create mode 100644 include/uapi/linux/hsr_prp_netlink.h
>>   create mode 100644 net/hsr-prp/Kconfig
>>   create mode 100644 net/hsr-prp/Makefile
>>   create mode 100644 net/hsr-prp/hsr_netlink.c
>>   rename net/{hsr => hsr-prp}/hsr_netlink.h (58%)
>>   rename net/{hsr/hsr_debugfs.c => hsr-prp/hsr_prp_debugfs.c} (52%)
>>   create mode 100644 net/hsr-prp/hsr_prp_device.c
>>   create mode 100644 net/hsr-prp/hsr_prp_device.h
>>   create mode 100644 net/hsr-prp/hsr_prp_forward.c
>>   rename net/{hsr/hsr_forward.h => hsr-prp/hsr_prp_forward.h} (50%)
>>   rename net/{hsr/hsr_framereg.c => hsr-prp/hsr_prp_framereg.c} (56%)
>>   create mode 100644 net/hsr-prp/hsr_prp_framereg.h
>>   create mode 100644 net/hsr-prp/hsr_prp_main.c
>>   create mode 100644 net/hsr-prp/hsr_prp_main.h
>>   create mode 100644 net/hsr-prp/hsr_prp_netlink.c
>>   create mode 100644 net/hsr-prp/hsr_prp_netlink.h
>>   create mode 100644 net/hsr-prp/hsr_prp_slave.c
>>   create mode 100644 net/hsr-prp/hsr_prp_slave.h
>>   create mode 100644 net/hsr-prp/prp_netlink.c
>>   create mode 100644 net/hsr-prp/prp_netlink.h
>>   delete mode 100644 net/hsr/Kconfig
>>   delete mode 100644 net/hsr/Makefile
>>   delete mode 100644 net/hsr/hsr_device.c
>>   delete mode 100644 net/hsr/hsr_device.h
>>   delete mode 100644 net/hsr/hsr_forward.c
>>   delete mode 100644 net/hsr/hsr_framereg.h
>>   delete mode 100644 net/hsr/hsr_main.c
>>   delete mode 100644 net/hsr/hsr_main.h
>>   delete mode 100644 net/hsr/hsr_netlink.c
>>   delete mode 100644 net/hsr/hsr_slave.c
>>   delete mode 100644 net/hsr/hsr_slave.h
>>
>> -- 
>> 2.17.1
>>
> 

-- 
Murali Karicheri
Texas Instruments

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-21 17:31 ` Vinicius Costa Gomes
  2020-05-25 16:49   ` Murali Karicheri
@ 2020-05-25 21:37   ` Vladimir Oltean
  2020-05-26 14:12     ` Murali Karicheri
  2020-05-26 18:09     ` Vinicius Costa Gomes
  1 sibling, 2 replies; 25+ messages in thread
From: Vladimir Oltean @ 2020-05-25 21:37 UTC (permalink / raw)
  To: Vinicius Costa Gomes
  Cc: Murali Karicheri, David S. Miller, Jakub Kicinski, netdev, lkml,
	linux-api, Sekhar Nori, Grygorii Strashko

Hi Vinicius,

On Thu, 21 May 2020 at 20:33, Vinicius Costa Gomes
<vinicius.gomes@intel.com> wrote:
>
> Murali Karicheri <m-karicheri2@ti.com> writes:
>
> > This RFC series add support for Parallel Redundancy Protocol (PRP)
> > as defined in IEC-62439-3 in the kernel networking subsystem. PRP
> > Uses a Redundancy Control Trailer (RCT) the format of which is
> > similar to HSR Tag. This is used for implementing redundancy.
> > RCT consists of 6 bytes similar to HSR tag and contain following
> > fields:-
> >
> > - 16-bit sequence number (SeqNr);
> > - 4-bit LAN identifier (LanId);
> > - 12 bit frame size (LSDUsize);
> > - 16-bit suffix (PRPsuffix).
> >
> > The PRPsuffix identifies PRP frames and distinguishes PRP frames
> > from other protocols that also append a trailer to their useful
> > data. The LSDUsize field allows the receiver to distinguish PRP
> > frames from random, nonredundant frames as an additional check.
> > LSDUsize is the size of the Ethernet payload inclusive of the
> > RCT. Sequence number along with LanId is used for duplicate
> > detection and discard.
> >
> > PRP node is also known as Dual Attached Node (DAN-P) since it
> > is typically attached to two different LAN for redundancy.
> > DAN-P duplicates each of L2 frames and send it over the two
> > Ethernet links. Each outgoing frame is appended with RCT.
> > Unlike HSR, these are added to the end of L2 frame and may be
> > treated as padding by bridges and therefore would be work with
> > traditional bridges or switches, where as HSR wouldn't as Tag
> > is prefixed to the Ethenet frame. At the remote end, these are
> > received and the duplicate frame is discarded before the stripped
> > frame is send up the networking stack. Like HSR, PRP also sends
> > periodic Supervision frames to the network. These frames are
> > received and MAC address from the SV frames are populated in a
> > database called Node Table. The above functions are grouped into
> > a block called Link Redundancy Entity (LRE) in the IEC spec.
> >
> > As there are many similarities between HSR and PRP protocols,
> > this patch re-use the code from HSR driver to implement PRP
> > driver. As many part of the code can be re-used, this patch
> > introduces a new common API definitions for both protocols and
> > propose to obsolete the existing HSR defines in
> > include/uapi/linux/if_link.h. New definitions are prefixed
> > with a HSR_PRP prefix. Similarly include/uapi/linux/hsr_netlink.h
> > is proposed to be replaced with include/uapi/linux/hsr_prp_netlink.h
> > which also uses the HSR_PRP prefix. The netlink socket interface
> > code is migrated (as well as the iproute2 being sent as a follow up
> > patch) to use the new API definitions. To re-use the code,
> > following are done as a preparatory patch before adding the PRP
> > functionality:-
> >
> >   - prefix all common code with hsr_prp
> >   - net/hsr -> renamed to net/hsr-prp
> >   - All common struct types, constants, functions renamed with
> >     hsr{HSR}_prp{PRP} prefix.
>
> I don't really like these prefixes, I am thinking of when support for
> IEEE 802.1CB is added, do we rename this to "hsr_prp_frer"?
>
> And it gets even more complicated, and using 802.1CB you can configure
> the tagging method and the stream identification function so a system
> can interoperate in a HSR or PRP network.
>

Is it a given that 802.1CB in Linux should be implemented using an hsr
upper device?
802.1CB is _much_ more flexible than both HSR and PRP. You can have
more than 2 ports, you can have per-stream rules (each stream has its
own sequence number), and those rules can identify the source, the
destination, or both the source and the destination.

> So, I see this as different methods of achieving the same result, which
> makes me think that the different "methods/types" (HSR and PRP in your
> case) should be basically different implementations of a "struct
> hsr_ops" interface. With this hsr_ops something like this:
>
>    struct hsr_ops {
>           int (*handle_frame)()
>           int (*add_port)()
>           int (*remove_port)()
>           int (*setup)()
>           void (*teardown)()
>    };
>
> >
> > Please review this and provide me feedback so that I can work to
> > incorporate them and send a formal patch series for this. As this
> > series impacts user space, I am not sure if this is the right
> > approach to introduce a new definitions and obsolete the old
> > API definitions for HSR. The current approach is choosen
> > to avoid redundant code in iproute2 and in the netlink driver
> > code (hsr_netlink.c). Other approach we discussed internally was
> > to Keep the HSR prefix in the user space and kernel code, but
> > live with the redundant code in the iproute2 and hsr netlink
> > code. Would like to hear from you what is the best way to add
> > this feature to networking core. If there is any other
> > alternative approach possible, I would like to hear about the
> > same.
>
> Why redudant code is needed in the netlink parts and in iproute2 when
> keeping the hsr prefix?
>
> >
> > The patch was tested using two TI AM57x IDK boards which are
> > connected back to back over two CPSW ports.
> >
> > Script used for creating the hsr/prp interface is given below
> > and uses the ip link command. Also provided logs from the tests
> > I have executed for your reference.
> >
> > iproute2 related patches will follow soon....
> >
> > Murali Karicheri
> > Texas Instruments
> >
> > ============ setup.sh =================================================
> > #!/bin/sh
> > if [ $# -lt 4 ]
> > then
> >        echo "setup-cpsw.sh <hsr/prp> <MAC-Address of slave-A>"
> >        echo "  <ip address for hsr/prp interface>"
> >        echo "  <if_name of hsr/prp interface>"
> >        exit
> > fi
> >
> > if [ "$1" != "hsr" ] && [ "$1" != "prp" ]
> > then
> >        echo "use hsr or prp as first argument"
> >        exit
> > fi
> >
> > if_a=eth2
> > if_b=eth3
> > if_name=$4
> >
> > ifconfig $if_a down
> > ifconfig $if_b down
> > ifconfig $if_a hw ether $2
> > ifconfig $if_b hw ether $2
> > ifconfig $if_a up
> > ifconfig $if_b up
> >
> > echo "Setting up $if_name with MAC address $2 for slaves and IP address $3"
> > echo "          using $if_a and $if_b"
> >
> > if [ "$1" = "hsr" ]; then
> >        options="version 1"
> > else
> >        options=""
> > fi
> >
> > ip link add name $if_name type $1 slave1 $if_a slave2 $if_b supervision 0 $options
> > ifconfig $if_name $3 up
> > ==================================================================================
> > PRP Logs:
> >
> > DUT-1 : https://pastebin.ubuntu.com/p/hhsRjTQpcr/
> > DUT-2 : https://pastebin.ubuntu.com/p/snPFKhnpk4/
> >
> > HSR Logs:
> >
> > DUT-1 : https://pastebin.ubuntu.com/p/FZPNc6Nwdm/
> > DUT-2 : https://pastebin.ubuntu.com/p/CtV4ZVS3Yd/
> >
> > Murali Karicheri (13):
> >   net: hsr: Re-use Kconfig option to support PRP
> >   net: hsr: rename hsr directory to hsr-prp to introduce PRP
> >   net: hsr: rename files to introduce PRP support
> >   net: hsr: rename hsr variable inside struct hsr_port to priv
> >   net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port()
> >   net: hsr: some renaming to introduce PRP driver support
> >   net: hsr: introduce common uapi include/definitions for HSR and PRP
> >   net: hsr: migrate HSR netlink socket code to use new common API
> >   net: hsr: move re-usable code for PRP to hsr_prp_netlink.c
> >   net: hsr: add netlink socket interface for PRP
> >   net: prp: add supervision frame generation and handling support
> >   net: prp: add packet handling support
> >   net: prp: enhance debugfs to display PRP specific info in node table
> >
> >  MAINTAINERS                                   |   2 +-
> >  include/uapi/linux/hsr_netlink.h              |   3 +
> >  include/uapi/linux/hsr_prp_netlink.h          |  50 ++
> >  include/uapi/linux/if_link.h                  |  19 +
> >  net/Kconfig                                   |   2 +-
> >  net/Makefile                                  |   2 +-
> >  net/hsr-prp/Kconfig                           |  37 ++
> >  net/hsr-prp/Makefile                          |  11 +
> >  net/hsr-prp/hsr_netlink.c                     | 202 +++++++
> >  net/{hsr => hsr-prp}/hsr_netlink.h            |  15 +-
> >  .../hsr_prp_debugfs.c}                        |  82 +--
> >  net/hsr-prp/hsr_prp_device.c                  | 562 ++++++++++++++++++
> >  net/hsr-prp/hsr_prp_device.h                  |  23 +
> >  net/hsr-prp/hsr_prp_forward.c                 | 558 +++++++++++++++++
> >  .../hsr_prp_forward.h}                        |  10 +-
> >  .../hsr_prp_framereg.c}                       | 323 +++++-----
> >  net/hsr-prp/hsr_prp_framereg.h                |  68 +++
> >  net/hsr-prp/hsr_prp_main.c                    | 194 ++++++
> >  net/hsr-prp/hsr_prp_main.h                    | 289 +++++++++
> >  net/hsr-prp/hsr_prp_netlink.c                 | 365 ++++++++++++
> >  net/hsr-prp/hsr_prp_netlink.h                 |  28 +
> >  net/hsr-prp/hsr_prp_slave.c                   | 222 +++++++
> >  net/hsr-prp/hsr_prp_slave.h                   |  37 ++
> >  net/hsr-prp/prp_netlink.c                     | 141 +++++
> >  net/hsr-prp/prp_netlink.h                     |  27 +
> >  net/hsr/Kconfig                               |  29 -
> >  net/hsr/Makefile                              |  10 -
> >  net/hsr/hsr_device.c                          | 509 ----------------
> >  net/hsr/hsr_device.h                          |  22 -
> >  net/hsr/hsr_forward.c                         | 379 ------------
> >  net/hsr/hsr_framereg.h                        |  62 --
> >  net/hsr/hsr_main.c                            | 154 -----
> >  net/hsr/hsr_main.h                            | 188 ------
> >  net/hsr/hsr_netlink.c                         | 514 ----------------
> >  net/hsr/hsr_slave.c                           | 198 ------
> >  net/hsr/hsr_slave.h                           |  33 -
> >  36 files changed, 3084 insertions(+), 2286 deletions(-)
> >  create mode 100644 include/uapi/linux/hsr_prp_netlink.h
> >  create mode 100644 net/hsr-prp/Kconfig
> >  create mode 100644 net/hsr-prp/Makefile
> >  create mode 100644 net/hsr-prp/hsr_netlink.c
> >  rename net/{hsr => hsr-prp}/hsr_netlink.h (58%)
> >  rename net/{hsr/hsr_debugfs.c => hsr-prp/hsr_prp_debugfs.c} (52%)
> >  create mode 100644 net/hsr-prp/hsr_prp_device.c
> >  create mode 100644 net/hsr-prp/hsr_prp_device.h
> >  create mode 100644 net/hsr-prp/hsr_prp_forward.c
> >  rename net/{hsr/hsr_forward.h => hsr-prp/hsr_prp_forward.h} (50%)
> >  rename net/{hsr/hsr_framereg.c => hsr-prp/hsr_prp_framereg.c} (56%)
> >  create mode 100644 net/hsr-prp/hsr_prp_framereg.h
> >  create mode 100644 net/hsr-prp/hsr_prp_main.c
> >  create mode 100644 net/hsr-prp/hsr_prp_main.h
> >  create mode 100644 net/hsr-prp/hsr_prp_netlink.c
> >  create mode 100644 net/hsr-prp/hsr_prp_netlink.h
> >  create mode 100644 net/hsr-prp/hsr_prp_slave.c
> >  create mode 100644 net/hsr-prp/hsr_prp_slave.h
> >  create mode 100644 net/hsr-prp/prp_netlink.c
> >  create mode 100644 net/hsr-prp/prp_netlink.h
> >  delete mode 100644 net/hsr/Kconfig
> >  delete mode 100644 net/hsr/Makefile
> >  delete mode 100644 net/hsr/hsr_device.c
> >  delete mode 100644 net/hsr/hsr_device.h
> >  delete mode 100644 net/hsr/hsr_forward.c
> >  delete mode 100644 net/hsr/hsr_framereg.h
> >  delete mode 100644 net/hsr/hsr_main.c
> >  delete mode 100644 net/hsr/hsr_main.h
> >  delete mode 100644 net/hsr/hsr_netlink.c
> >  delete mode 100644 net/hsr/hsr_slave.c
> >  delete mode 100644 net/hsr/hsr_slave.h
> >
> > --
> > 2.17.1
> >
>
> --
> Vinicius

Thanks,
-Vladimir

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-25 21:37   ` Vladimir Oltean
@ 2020-05-26 14:12     ` Murali Karicheri
  2020-05-26 18:25       ` Vladimir Oltean
  2020-05-26 18:09     ` Vinicius Costa Gomes
  1 sibling, 1 reply; 25+ messages in thread
From: Murali Karicheri @ 2020-05-26 14:12 UTC (permalink / raw)
  To: Vladimir Oltean, Vinicius Costa Gomes
  Cc: David S. Miller, Jakub Kicinski, netdev, lkml, linux-api,
	Sekhar Nori, Grygorii Strashko

Hi Vladimir,

On 5/25/20 5:37 PM, Vladimir Oltean wrote:
> Hi Vinicius,
> 
> On Thu, 21 May 2020 at 20:33, Vinicius Costa Gomes
> <vinicius.gomes@intel.com> wrote:
>>
>> Murali Karicheri <m-karicheri2@ti.com> writes:
>>
>>> This RFC series add support for Parallel Redundancy Protocol (PRP)
>>> as defined in IEC-62439-3 in the kernel networking subsystem. PRP
>>> Uses a Redundancy Control Trailer (RCT) the format of which is
>>> similar to HSR Tag. This is used for implementing redundancy.
>>> RCT consists of 6 bytes similar to HSR tag and contain following
>>> fields:-
>>>
>>> - 16-bit sequence number (SeqNr);
>>> - 4-bit LAN identifier (LanId);
>>> - 12 bit frame size (LSDUsize);
>>> - 16-bit suffix (PRPsuffix).
>>>
>>> The PRPsuffix identifies PRP frames and distinguishes PRP frames
>>> from other protocols that also append a trailer to their useful
>>> data. The LSDUsize field allows the receiver to distinguish PRP
>>> frames from random, nonredundant frames as an additional check.
>>> LSDUsize is the size of the Ethernet payload inclusive of the
>>> RCT. Sequence number along with LanId is used for duplicate
>>> detection and discard.
>>>
>>> PRP node is also known as Dual Attached Node (DAN-P) since it
>>> is typically attached to two different LAN for redundancy.
>>> DAN-P duplicates each of L2 frames and send it over the two
>>> Ethernet links. Each outgoing frame is appended with RCT.
>>> Unlike HSR, these are added to the end of L2 frame and may be
>>> treated as padding by bridges and therefore would be work with
>>> traditional bridges or switches, where as HSR wouldn't as Tag
>>> is prefixed to the Ethenet frame. At the remote end, these are
>>> received and the duplicate frame is discarded before the stripped
>>> frame is send up the networking stack. Like HSR, PRP also sends
>>> periodic Supervision frames to the network. These frames are
>>> received and MAC address from the SV frames are populated in a
>>> database called Node Table. The above functions are grouped into
>>> a block called Link Redundancy Entity (LRE) in the IEC spec.
>>>
>>> As there are many similarities between HSR and PRP protocols,
>>> this patch re-use the code from HSR driver to implement PRP
>>> driver. As many part of the code can be re-used, this patch
>>> introduces a new common API definitions for both protocols and
>>> propose to obsolete the existing HSR defines in
>>> include/uapi/linux/if_link.h. New definitions are prefixed
>>> with a HSR_PRP prefix. Similarly include/uapi/linux/hsr_netlink.h
>>> is proposed to be replaced with include/uapi/linux/hsr_prp_netlink.h
>>> which also uses the HSR_PRP prefix. The netlink socket interface
>>> code is migrated (as well as the iproute2 being sent as a follow up
>>> patch) to use the new API definitions. To re-use the code,
>>> following are done as a preparatory patch before adding the PRP
>>> functionality:-
>>>
>>>    - prefix all common code with hsr_prp
>>>    - net/hsr -> renamed to net/hsr-prp
>>>    - All common struct types, constants, functions renamed with
>>>      hsr{HSR}_prp{PRP} prefix.
>>
>> I don't really like these prefixes, I am thinking of when support for
>> IEEE 802.1CB is added, do we rename this to "hsr_prp_frer"?
>>
>> And it gets even more complicated, and using 802.1CB you can configure
>> the tagging method and the stream identification function so a system
>> can interoperate in a HSR or PRP network.
>>
> 
> Is it a given that 802.1CB in Linux should be implemented using an hsr
> upper device?
> 802.1CB is _much_ more flexible than both HSR and PRP. You can have
> more than 2 ports, you can have per-stream rules (each stream has its
> own sequence number), and those rules can identify the source, the
> destination, or both the source and the destination.
> 
I haven't looked the spec for 802.1CB. If they re-use HSR/PRP Tag in the
L2 protocol it make sense to enhance the driver. Else I don't see any
re-use possibility. Do you know the above?

Thanks

Murali
>> So, I see this as different methods of achieving the same result, which
>> makes me think that the different "methods/types" (HSR and PRP in your
>> case) should be basically different implementations of a "struct
>> hsr_ops" interface. With this hsr_ops something like this:
>>
>>     struct hsr_ops {
>>            int (*handle_frame)()
>>            int (*add_port)()
>>            int (*remove_port)()
>>            int (*setup)()
>>            void (*teardown)()
>>     };
>>
>>>
>>> Please review this and provide me feedback so that I can work to
>>> incorporate them and send a formal patch series for this. As this
>>> series impacts user space, I am not sure if this is the right
>>> approach to introduce a new definitions and obsolete the old
>>> API definitions for HSR. The current approach is choosen
>>> to avoid redundant code in iproute2 and in the netlink driver
>>> code (hsr_netlink.c). Other approach we discussed internally was
>>> to Keep the HSR prefix in the user space and kernel code, but
>>> live with the redundant code in the iproute2 and hsr netlink
>>> code. Would like to hear from you what is the best way to add
>>> this feature to networking core. If there is any other
>>> alternative approach possible, I would like to hear about the
>>> same.
>>
>> Why redudant code is needed in the netlink parts and in iproute2 when
>> keeping the hsr prefix?
>>
>>>
>>> The patch was tested using two TI AM57x IDK boards which are
>>> connected back to back over two CPSW ports.
>>>
>>> Script used for creating the hsr/prp interface is given below
>>> and uses the ip link command. Also provided logs from the tests
>>> I have executed for your reference.
>>>
>>> iproute2 related patches will follow soon....
>>>
>>> Murali Karicheri
>>> Texas Instruments
>>>
>>> ============ setup.sh =================================================
>>> #!/bin/sh
>>> if [ $# -lt 4 ]
>>> then
>>>         echo "setup-cpsw.sh <hsr/prp> <MAC-Address of slave-A>"
>>>         echo "  <ip address for hsr/prp interface>"
>>>         echo "  <if_name of hsr/prp interface>"
>>>         exit
>>> fi
>>>
>>> if [ "$1" != "hsr" ] && [ "$1" != "prp" ]
>>> then
>>>         echo "use hsr or prp as first argument"
>>>         exit
>>> fi
>>>
>>> if_a=eth2
>>> if_b=eth3
>>> if_name=$4
>>>
>>> ifconfig $if_a down
>>> ifconfig $if_b down
>>> ifconfig $if_a hw ether $2
>>> ifconfig $if_b hw ether $2
>>> ifconfig $if_a up
>>> ifconfig $if_b up
>>>
>>> echo "Setting up $if_name with MAC address $2 for slaves and IP address $3"
>>> echo "          using $if_a and $if_b"
>>>
>>> if [ "$1" = "hsr" ]; then
>>>         options="version 1"
>>> else
>>>         options=""
>>> fi
>>>
>>> ip link add name $if_name type $1 slave1 $if_a slave2 $if_b supervision 0 $options
>>> ifconfig $if_name $3 up
>>> ==================================================================================
>>> PRP Logs:
>>>
>>> DUT-1 : https://pastebin.ubuntu.com/p/hhsRjTQpcr/
>>> DUT-2 : https://pastebin.ubuntu.com/p/snPFKhnpk4/
>>>
>>> HSR Logs:
>>>
>>> DUT-1 : https://pastebin.ubuntu.com/p/FZPNc6Nwdm/
>>> DUT-2 : https://pastebin.ubuntu.com/p/CtV4ZVS3Yd/
>>>
>>> Murali Karicheri (13):
>>>    net: hsr: Re-use Kconfig option to support PRP
>>>    net: hsr: rename hsr directory to hsr-prp to introduce PRP
>>>    net: hsr: rename files to introduce PRP support
>>>    net: hsr: rename hsr variable inside struct hsr_port to priv
>>>    net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port()
>>>    net: hsr: some renaming to introduce PRP driver support
>>>    net: hsr: introduce common uapi include/definitions for HSR and PRP
>>>    net: hsr: migrate HSR netlink socket code to use new common API
>>>    net: hsr: move re-usable code for PRP to hsr_prp_netlink.c
>>>    net: hsr: add netlink socket interface for PRP
>>>    net: prp: add supervision frame generation and handling support
>>>    net: prp: add packet handling support
>>>    net: prp: enhance debugfs to display PRP specific info in node table
>>>
>>>   MAINTAINERS                                   |   2 +-
>>>   include/uapi/linux/hsr_netlink.h              |   3 +
>>>   include/uapi/linux/hsr_prp_netlink.h          |  50 ++
>>>   include/uapi/linux/if_link.h                  |  19 +
>>>   net/Kconfig                                   |   2 +-
>>>   net/Makefile                                  |   2 +-
>>>   net/hsr-prp/Kconfig                           |  37 ++
>>>   net/hsr-prp/Makefile                          |  11 +
>>>   net/hsr-prp/hsr_netlink.c                     | 202 +++++++
>>>   net/{hsr => hsr-prp}/hsr_netlink.h            |  15 +-
>>>   .../hsr_prp_debugfs.c}                        |  82 +--
>>>   net/hsr-prp/hsr_prp_device.c                  | 562 ++++++++++++++++++
>>>   net/hsr-prp/hsr_prp_device.h                  |  23 +
>>>   net/hsr-prp/hsr_prp_forward.c                 | 558 +++++++++++++++++
>>>   .../hsr_prp_forward.h}                        |  10 +-
>>>   .../hsr_prp_framereg.c}                       | 323 +++++-----
>>>   net/hsr-prp/hsr_prp_framereg.h                |  68 +++
>>>   net/hsr-prp/hsr_prp_main.c                    | 194 ++++++
>>>   net/hsr-prp/hsr_prp_main.h                    | 289 +++++++++
>>>   net/hsr-prp/hsr_prp_netlink.c                 | 365 ++++++++++++
>>>   net/hsr-prp/hsr_prp_netlink.h                 |  28 +
>>>   net/hsr-prp/hsr_prp_slave.c                   | 222 +++++++
>>>   net/hsr-prp/hsr_prp_slave.h                   |  37 ++
>>>   net/hsr-prp/prp_netlink.c                     | 141 +++++
>>>   net/hsr-prp/prp_netlink.h                     |  27 +
>>>   net/hsr/Kconfig                               |  29 -
>>>   net/hsr/Makefile                              |  10 -
>>>   net/hsr/hsr_device.c                          | 509 ----------------
>>>   net/hsr/hsr_device.h                          |  22 -
>>>   net/hsr/hsr_forward.c                         | 379 ------------
>>>   net/hsr/hsr_framereg.h                        |  62 --
>>>   net/hsr/hsr_main.c                            | 154 -----
>>>   net/hsr/hsr_main.h                            | 188 ------
>>>   net/hsr/hsr_netlink.c                         | 514 ----------------
>>>   net/hsr/hsr_slave.c                           | 198 ------
>>>   net/hsr/hsr_slave.h                           |  33 -
>>>   36 files changed, 3084 insertions(+), 2286 deletions(-)
>>>   create mode 100644 include/uapi/linux/hsr_prp_netlink.h
>>>   create mode 100644 net/hsr-prp/Kconfig
>>>   create mode 100644 net/hsr-prp/Makefile
>>>   create mode 100644 net/hsr-prp/hsr_netlink.c
>>>   rename net/{hsr => hsr-prp}/hsr_netlink.h (58%)
>>>   rename net/{hsr/hsr_debugfs.c => hsr-prp/hsr_prp_debugfs.c} (52%)
>>>   create mode 100644 net/hsr-prp/hsr_prp_device.c
>>>   create mode 100644 net/hsr-prp/hsr_prp_device.h
>>>   create mode 100644 net/hsr-prp/hsr_prp_forward.c
>>>   rename net/{hsr/hsr_forward.h => hsr-prp/hsr_prp_forward.h} (50%)
>>>   rename net/{hsr/hsr_framereg.c => hsr-prp/hsr_prp_framereg.c} (56%)
>>>   create mode 100644 net/hsr-prp/hsr_prp_framereg.h
>>>   create mode 100644 net/hsr-prp/hsr_prp_main.c
>>>   create mode 100644 net/hsr-prp/hsr_prp_main.h
>>>   create mode 100644 net/hsr-prp/hsr_prp_netlink.c
>>>   create mode 100644 net/hsr-prp/hsr_prp_netlink.h
>>>   create mode 100644 net/hsr-prp/hsr_prp_slave.c
>>>   create mode 100644 net/hsr-prp/hsr_prp_slave.h
>>>   create mode 100644 net/hsr-prp/prp_netlink.c
>>>   create mode 100644 net/hsr-prp/prp_netlink.h
>>>   delete mode 100644 net/hsr/Kconfig
>>>   delete mode 100644 net/hsr/Makefile
>>>   delete mode 100644 net/hsr/hsr_device.c
>>>   delete mode 100644 net/hsr/hsr_device.h
>>>   delete mode 100644 net/hsr/hsr_forward.c
>>>   delete mode 100644 net/hsr/hsr_framereg.h
>>>   delete mode 100644 net/hsr/hsr_main.c
>>>   delete mode 100644 net/hsr/hsr_main.h
>>>   delete mode 100644 net/hsr/hsr_netlink.c
>>>   delete mode 100644 net/hsr/hsr_slave.c
>>>   delete mode 100644 net/hsr/hsr_slave.h
>>>
>>> --
>>> 2.17.1
>>>
>>
>> --
>> Vinicius
> 
> Thanks,
> -Vladimir
> 

-- 
Murali Karicheri
Texas Instruments

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-25 21:37   ` Vladimir Oltean
  2020-05-26 14:12     ` Murali Karicheri
@ 2020-05-26 18:09     ` Vinicius Costa Gomes
  1 sibling, 0 replies; 25+ messages in thread
From: Vinicius Costa Gomes @ 2020-05-26 18:09 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Murali Karicheri, David S. Miller, Jakub Kicinski, netdev, lkml,
	linux-api, Sekhar Nori, Grygorii Strashko

Hi Vladimir,

Vladimir Oltean <olteanv@gmail.com> writes:
>>
>> I don't really like these prefixes, I am thinking of when support for
>> IEEE 802.1CB is added, do we rename this to "hsr_prp_frer"?
>>
>> And it gets even more complicated, and using 802.1CB you can configure
>> the tagging method and the stream identification function so a system
>> can interoperate in a HSR or PRP network.
>>
>
> Is it a given that 802.1CB in Linux should be implemented using an hsr
> upper device?

What I was trying to express is the idea of using "hsr" as the directory
name/prefix for all the features that deal with frame replication for
reliability, including 802.1CB. At least until we find a better name.

> 802.1CB is _much_ more flexible than both HSR and PRP. You can have
> more than 2 ports, you can have per-stream rules (each stream has its
> own sequence number), and those rules can identify the source, the
> destination, or both the source and the destination.

Same understanding here.


Cheers,
-- 
Vinicius

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-26 14:12     ` Murali Karicheri
@ 2020-05-26 18:25       ` Vladimir Oltean
  2020-05-26 21:33         ` Murali Karicheri
  0 siblings, 1 reply; 25+ messages in thread
From: Vladimir Oltean @ 2020-05-26 18:25 UTC (permalink / raw)
  To: Murali Karicheri
  Cc: Vinicius Costa Gomes, David S. Miller, Jakub Kicinski, netdev,
	lkml, linux-api, Sekhar Nori, Grygorii Strashko

Hi Murali,

On Tue, 26 May 2020 at 17:12, Murali Karicheri <m-karicheri2@ti.com> wrote:
>
> Hi Vladimir,
>

> I haven't looked the spec for 802.1CB. If they re-use HSR/PRP Tag in the
> L2 protocol it make sense to enhance the driver. Else I don't see any
> re-use possibility. Do you know the above?
>
> Thanks
>
> Murali

IEEE 802.1CB redundancy tag sits between Source MAC address and
Ethertype or any VLAN tag, is 6 bytes in length, of which:
- first 2 bytes are the 0xf1c1 EtherType
- next 2 bytes are reserved
- last 2 bytes are the sequence number
There is also a pre-standard version of the IEEE 802.1CB redundancy
tag, which is only 4 bytes in length. I assume vendors of pre-standard
equipment will want to have support for this 4-byte tag as well, as
well as a mechanism of converting between HSR/PRP/pre-standard 802.1CB
tag on one set of ports, and 802.1CB on another set of ports.

>
> --
> Murali Karicheri
> Texas Instruments

Thanks,
-Vladimir

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-25 16:49   ` Murali Karicheri
@ 2020-05-26 18:56     ` Vinicius Costa Gomes
  2020-05-26 21:51       ` Murali Karicheri
  0 siblings, 1 reply; 25+ messages in thread
From: Vinicius Costa Gomes @ 2020-05-26 18:56 UTC (permalink / raw)
  To: Murali Karicheri, davem, kuba, netdev, linux-kernel, linux-api,
	nsekhar, grygorii.strashko

Murali Karicheri <m-karicheri2@ti.com> writes:

> Hi Vinicius,
>
> On 5/21/20 1:31 PM, Vinicius Costa Gomes wrote:
>> Murali Karicheri <m-karicheri2@ti.com> writes:
>> 
> ------------ Snip-------------
>
>>>    - prefix all common code with hsr_prp
>>>    - net/hsr -> renamed to net/hsr-prp
>>>    - All common struct types, constants, functions renamed with
>>>      hsr{HSR}_prp{PRP} prefix.
>> 
>> I don't really like these prefixes, I am thinking of when support for
>> IEEE 802.1CB is added, do we rename this to "hsr_prp_frer"?
>> 
>> And it gets even more complicated, and using 802.1CB you can configure
>> the tagging method and the stream identification function so a system
>> can interoperate in a HSR or PRP network.
>> 
>> So, I see this as different methods of achieving the same result, which
>> makes me think that the different "methods/types" (HSR and PRP in your
>> case) should be basically different implementations of a "struct
>> hsr_ops" interface. With this hsr_ops something like this:
>> 
>>     struct hsr_ops {
>>            int (*handle_frame)()
>>            int (*add_port)()
>>            int (*remove_port)()
>>            int (*setup)()
>>            void (*teardown)()
>>     };
>> 
>
> Thanks for your response!
>
> I agree with you that the prefix renaming is ugly. However I wasn't
> sure if it is okay to use a hsr prefixed code to handle PRP as
> well as it may not be intuitive to anyone investigating the code. For
> the same reason, handling 802.1CB specifc functions using the hsr_
> prefixed code. If that is okay, then patch 1-6 are unnecessary. We could
> also add some documentation at the top of the file to indicate that
> both hsr and prp are implemented in the code or something like that.
> BTW, I need to investigate more into 802.1CB and this was not known
> when I developed this code few years ago.

I think for now it's better to make it clear how similar PRP and HSR
are.

As for the renaming, I am afraid that this boat has sailed, as the
netlink API already uses HSR_ and it's better to reuse that than create
a new family for, at least conceptually, the same thing (PRP and
802.1CB). And this is important bit, the userspace API.

And even for 802.1CB using name "High-availability Seamless Redudancy"
is as good as any, if very pompous.

>
> Main difference between HSR and PRP is how they handle the protocol tag
> or rct and create or handle the protocol specific part in the frame.
> For that part, we should be able to define ops() like you have
> suggested, instead of doing if check throughout the code. Hope that
> is what you meant by hsr_ops() for this. Again shouldn't we use some 
> generic name like proto_ops or red_ops instead of hsr_ops() and assign
> protocol specific implementaion to them? i.e hsr_ or prp_
> or 802.1CB specific functions assigned to the function pointers. For
> now I see handle_frame(), handle_sv_frame, create_frame(), 
> create_sv_frame() etc implemented differently (This is currently part of
> patch 11 & 12). So something like
>
>     struct proto_ops {
> 	int (*handle_frame)();
> 	int (*create_frame)();
> 	int (*handle_sv_frame)();
> 	int (*create_sv_frame)();
>     };

That's it. That was the idea I was trying to communicate :-)

>
> and call dev->proto_ops->handle_frame() to process a frame from the
> main hook. proto_ops gets initialized to of the set if implementation
> at device or interface creation in hsr_dev_finalize().
>
>>>
>>> Please review this and provide me feedback so that I can work to
>>> incorporate them and send a formal patch series for this. As this
>>> series impacts user space, I am not sure if this is the right
>>> approach to introduce a new definitions and obsolete the old
>>> API definitions for HSR. The current approach is choosen
>>> to avoid redundant code in iproute2 and in the netlink driver
>>> code (hsr_netlink.c). Other approach we discussed internally was
>>> to Keep the HSR prefix in the user space and kernel code, but
>>> live with the redundant code in the iproute2 and hsr netlink
>>> code. Would like to hear from you what is the best way to add
>>> this feature to networking core. If there is any other
>>> alternative approach possible, I would like to hear about the
>>> same.
>> 
>> Why redudant code is needed in the netlink parts and in iproute2 when
>> keeping the hsr prefix?
>
> May be this is due to the specific implementation that I chose.
> Currently I have separate netlink socket for HSR and PRP which may
> be an overkill since bith are similar protocol.
>
> Currently hsr inteface is created as
>
> ip link add name hsr0 type hsr slave1 eth0 slave2 eth1 supervision 0
>
> So I have implemented similar command for prp
>
> ip link add name prp0 type prp slave1 eth0 slave2 eth1 supervision 0
>
> In patch 7/13 I renamed existing HSR netlink socket attributes that
> defines the hsr interface with the assumption that we can obsolete
> the old definitions in favor of new common definitions with the
> HSR_PRP prefix. Then I have separate code for creating prp
> interface and related functions, even though they are similar.
> So using common definitions, I re-use the code in netlink and
> iproute2 (see patch 8 and 9 to re-use the code). PRP netlink
> socket code in patch 10 which register prp_genl_family similar
> to HSR.

Deprecating an userspace API is hard and takes a long time. So let's
avoid that if it makes sense.

>
> +static struct genl_family prp_genl_family __ro_after_init = {
> +	.hdrsize = 0,
> +	.name = "PRP",
> +	.version = 1,
> +	.maxattr = HSR_PRP_A_MAX,
> +	.policy = prp_genl_policy,
> +	.module = THIS_MODULE,
> +	.ops = prp_ops,
> +	.n_ops = ARRAY_SIZE(prp_ops),
> +	.mcgrps = prp_mcgrps,
> +	.n_mcgrps = ARRAY_SIZE(prp_mcgrps),
> +};
> +
> +int __init prp_netlink_init(void)
> +{
> +	int rc;
> +
> +	rc = rtnl_link_register(&prp_link_ops);
> +	if (rc)
> +		goto fail_rtnl_link_register;
> +
> +	rc = genl_register_family(&prp_genl_family);
> +	if (rc)
> +		goto fail_genl_register_family;
>
>
> If we choose to re-use the existing HSR_ uapi defines, then should we
> re-use the hsr netlink socket interface for PRP as well and
> add additional attribute for differentiating the protocol specific
> part?

Yes, that seems the way to go.

>
> i.e introduce protocol attribute to existing HSR uapi defines for
> netlink socket to handle creation of prp interface.
>
> enum {
> 	HSR_A_UNSPEC,
> 	HSR_A_NODE_ADDR,
> 	HSR_A_IFINDEX,
> 	HSR_A_IF1_AGE,
> 	HSR_A_IF2_AGE,
> 	HSR_A_NODE_ADDR_B,
> 	HSR_A_IF1_SEQ,
> 	HSR_A_IF2_SEQ,
> 	HSR_A_IF1_IFINDEX,
> 	HSR_A_IF2_IFINDEX,
> 	HSR_A_ADDR_B_IFINDEX,
> +       HSR_A_PROTOCOL  <====if missing it is HSR (backward 	
> 			     compatibility)
>                               defines HSR or PRP or 802.1CB in future.
> 	__HSR_A_MAX,
> };
>
> So if ip link command is
>
> ip link add name <if name> type <proto> slave1 eth0 slave2 eth1 
> supervision 0
>
> Add HSR_A_PROTOCOL attribute with HSR/PRP specific value.
>
> This way, the iprout2 code mostly remain the same as hsr, but will
> change a bit to introduced this new attribute if user choose proto as
> 'prp' vs 'hsr'

Sounds good, I think.

>
> BTW, I have posted the existing iproute2 code also to the mailing list
> with title 'iproute2: Add PRP support'.
>
> If re-using hsr code with existing prefix is fine for PRP or any future
> protocol such as 801.1B, then I will drop patch 1-6 that are essentially
> doing some renaming and re-use existing hsr netlink code for PRP with
> added attribute to differentiate the protocol at the driver as described
> above along with proto_ops and re-spin the series.

If I forget that HSR is also the name of a protocol, what the acronym
means makes sense for 802.1CB, so it's not too bad, I think.

>
> Let me know.
>
> Regards,
>
> Murali


Cheers,
-- 
Vinicius

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-26 18:25       ` Vladimir Oltean
@ 2020-05-26 21:33         ` Murali Karicheri
  0 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-26 21:33 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Vinicius Costa Gomes, David S. Miller, Jakub Kicinski, netdev,
	lkml, linux-api, Sekhar Nori, Grygorii Strashko

Hi Vladimir

On 5/26/20 2:25 PM, Vladimir Oltean wrote:
> Hi Murali,
> 
> On Tue, 26 May 2020 at 17:12, Murali Karicheri <m-karicheri2@ti.com> wrote:
>>
>> Hi Vladimir,
>>
> 
>> I haven't looked the spec for 802.1CB. If they re-use HSR/PRP Tag in the
>> L2 protocol it make sense to enhance the driver. Else I don't see any
>> re-use possibility. Do you know the above?
>>
>> Thanks
>>
>> Murali
> 
> IEEE 802.1CB redundancy tag sits between Source MAC address and
> Ethertype or any VLAN tag, is 6 bytes in length, of which:
> - first 2 bytes are the 0xf1c1 EtherType
> - next 2 bytes are reserved
> - last 2 bytes are the sequence number
> There is also a pre-standard version of the IEEE 802.1CB redundancy
> tag, which is only 4 bytes in length. I assume vendors of pre-standard
> equipment will want to have support for this 4-byte tag as well, as
> well as a mechanism of converting between HSR/PRP/pre-standard 802.1CB
> tag on one set of ports, and 802.1CB on another set of ports.
> 
Thanks for sharing the details. I also took a quick glance at the
802.1CB spec today. It answered also my above question
1) In addition to FRER tag, it also includes HSR tag and PRP trailer
that can be provisioned through management objects.
2) Now I think I get what Vinicius refers to the interoperability. there
can be HSR tag received on ingress port and PRP on the egress port of
a relay function.

Essentially tag usage is configurable on a stream basis. Since both
HSR and PRP functions for frame formatting and decoding would be
re-usable. In addition driver could be enhanced for FRER functions.

Regards,

Murali
>>
>> --
>> Murali Karicheri
>> Texas Instruments
> 
> Thanks,
> -Vladimir
> 

-- 
Murali Karicheri
Texas Instruments

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [net-next RFC PATCH 00/13] net: hsr: Add PRP driver
  2020-05-26 18:56     ` Vinicius Costa Gomes
@ 2020-05-26 21:51       ` Murali Karicheri
  0 siblings, 0 replies; 25+ messages in thread
From: Murali Karicheri @ 2020-05-26 21:51 UTC (permalink / raw)
  To: Vinicius Costa Gomes, davem, kuba, netdev, linux-kernel,
	linux-api, nsekhar, grygorii.strashko

Hi Vinicius,

On 5/26/20 2:56 PM, Vinicius Costa Gomes wrote:
> Murali Karicheri <m-karicheri2@ti.com> writes:
> 
>> Hi Vinicius,
>>
>> On 5/21/20 1:31 PM, Vinicius Costa Gomes wrote:
>>> Murali Karicheri <m-karicheri2@ti.com> writes:
>>>
>> ------------ Snip-------------

>>> So, I see this as different methods of achieving the same result, which
>>> makes me think that the different "methods/types" (HSR and PRP in your
>>> case) should be basically different implementations of a "struct
>>> hsr_ops" interface. With this hsr_ops something like this:
>>>
>>>      struct hsr_ops {
>>>             int (*handle_frame)()
>>>             int (*add_port)()
>>>             int (*remove_port)()
>>>             int (*setup)()
>>>             void (*teardown)()
>>>      };
>>>
>>
>> Thanks for your response!
>>
>> I agree with you that the prefix renaming is ugly. However I wasn't
>> sure if it is okay to use a hsr prefixed code to handle PRP as
>> well as it may not be intuitive to anyone investigating the code. For
>> the same reason, handling 802.1CB specifc functions using the hsr_
>> prefixed code. If that is okay, then patch 1-6 are unnecessary. We could
>> also add some documentation at the top of the file to indicate that
>> both hsr and prp are implemented in the code or something like that.
>> BTW, I need to investigate more into 802.1CB and this was not known
>> when I developed this code few years ago.
> 
> I think for now it's better to make it clear how similar PRP and HSR
> are.
> 
> As for the renaming, I am afraid that this boat has sailed, as the
> netlink API already uses HSR_ and it's better to reuse that than create
> a new family for, at least conceptually, the same thing (PRP and
> 802.1CB). And this is important bit, the userspace API.
> 
> And even for 802.1CB using name "High-availability Seamless Redudancy"
> is as good as any, if very pompous.
> I have reviewed the 802.1CB at a high level. The idea of 802.1CB is
also high availability and redundancy similar to HSR and PRP but at
stream level. So now I feel more comfortable to re-use the hsr prefix
until we find a better name. I can document this in all file headers to
make this explicit when I spin the formal patch for this. I will wait
for a couple of weeks before start the work on a formal patch
series so that others have a chance to respond as well.

>>
>> Main difference between HSR and PRP is how they handle the protocol tag
>> or rct and create or handle the protocol specific part in the frame.
>> For that part, we should be able to define ops() like you have
>> suggested, instead of doing if check throughout the code. Hope that
>> is what you meant by hsr_ops() for this. Again shouldn't we use some
>> generic name like proto_ops or red_ops instead of hsr_ops() and assign
>> protocol specific implementaion to them? i.e hsr_ or prp_
>> or 802.1CB specific functions assigned to the function pointers. For
>> now I see handle_frame(), handle_sv_frame, create_frame(),
>> create_sv_frame() etc implemented differently (This is currently part of
>> patch 11 & 12). So something like
>>
>>      struct proto_ops {
>> 	int (*handle_frame)();
>> 	int (*create_frame)();
>> 	int (*handle_sv_frame)();
>> 	int (*create_sv_frame)();
>>      };
> 
> That's it. That was the idea I was trying to communicate :-)
> 
Ok
>>
>> and call dev->proto_ops->handle_frame() to process a frame from the
>> main hook. proto_ops gets initialized to of the set if implementation
>> at device or interface creation in hsr_dev_finalize().
>>
>>>>
>>>> Please review this and provide me feedback so that I can work to
>>>> incorporate them and send a formal patch series for this. As this
>>>> series impacts user space, I am not sure if this is the right
>>>> approach to introduce a new definitions and obsolete the old
>>>> API definitions for HSR. The current approach is choosen
>>>> to avoid redundant code in iproute2 and in the netlink driver
>>>> code (hsr_netlink.c). Other approach we discussed internally was
>>>> to Keep the HSR prefix in the user space and kernel code, but
>>>> live with the redundant code in the iproute2 and hsr netlink
>>>> code. Would like to hear from you what is the best way to add
>>>> this feature to networking core. If there is any other
>>>> alternative approach possible, I would like to hear about the
>>>> same.
>>>
>>> Why redudant code is needed in the netlink parts and in iproute2 when
>>> keeping the hsr prefix?
>>
>> May be this is due to the specific implementation that I chose.
>> Currently I have separate netlink socket for HSR and PRP which may
>> be an overkill since bith are similar protocol.
>>
>> Currently hsr inteface is created as
>>
>> ip link add name hsr0 type hsr slave1 eth0 slave2 eth1 supervision 0
>>
>> So I have implemented similar command for prp
>>
>> ip link add name prp0 type prp slave1 eth0 slave2 eth1 supervision 0
>>
>> In patch 7/13 I renamed existing HSR netlink socket attributes that
>> defines the hsr interface with the assumption that we can obsolete
>> the old definitions in favor of new common definitions with the
>> HSR_PRP prefix. Then I have separate code for creating prp
>> interface and related functions, even though they are similar.
>> So using common definitions, I re-use the code in netlink and
>> iproute2 (see patch 8 and 9 to re-use the code). PRP netlink
>> socket code in patch 10 which register prp_genl_family similar
>> to HSR.
> 
> Deprecating an userspace API is hard and takes a long time. So let's
> avoid that if it makes sense.
> 

Ok, make sense.

>>
>> +static struct genl_family prp_genl_family __ro_after_init = {
>> +	.hdrsize = 0,
>> +	.name = "PRP",
>> +	.version = 1,
>> +	.maxattr = HSR_PRP_A_MAX,
>> +	.policy = prp_genl_policy,
>> +	.module = THIS_MODULE,
>> +	.ops = prp_ops,
>> +	.n_ops = ARRAY_SIZE(prp_ops),
>> +	.mcgrps = prp_mcgrps,
>> +	.n_mcgrps = ARRAY_SIZE(prp_mcgrps),
>> +};
>> +
>> +int __init prp_netlink_init(void)
>> +{
>> +	int rc;
>> +
>> +	rc = rtnl_link_register(&prp_link_ops);
>> +	if (rc)
>> +		goto fail_rtnl_link_register;
>> +
>> +	rc = genl_register_family(&prp_genl_family);
>> +	if (rc)
>> +		goto fail_genl_register_family;
>>
>>
>> If we choose to re-use the existing HSR_ uapi defines, then should we
>> re-use the hsr netlink socket interface for PRP as well and
>> add additional attribute for differentiating the protocol specific
>> part?
> 
> Yes, that seems the way to go.
> 
Ok.

>>
>> i.e introduce protocol attribute to existing HSR uapi defines for
>> netlink socket to handle creation of prp interface.
>>
>> enum {
>> 	HSR_A_UNSPEC,
>> 	HSR_A_NODE_ADDR,
>> 	HSR_A_IFINDEX,
>> 	HSR_A_IF1_AGE,
>> 	HSR_A_IF2_AGE,
>> 	HSR_A_NODE_ADDR_B,
>> 	HSR_A_IF1_SEQ,
>> 	HSR_A_IF2_SEQ,
>> 	HSR_A_IF1_IFINDEX,
>> 	HSR_A_IF2_IFINDEX,
>> 	HSR_A_ADDR_B_IFINDEX,
>> +       HSR_A_PROTOCOL  <====if missing it is HSR (backward 	
>> 			     compatibility)
>>                                defines HSR or PRP or 802.1CB in future.
>> 	__HSR_A_MAX,
>> };
>>
>> So if ip link command is
>>
>> ip link add name <if name> type <proto> slave1 eth0 slave2 eth1
>> supervision 0
>>
>> Add HSR_A_PROTOCOL attribute with HSR/PRP specific value.
>>
>> This way, the iprout2 code mostly remain the same as hsr, but will
>> change a bit to introduced this new attribute if user choose proto as
>> 'prp' vs 'hsr'
> 
> Sounds good, I think.

Ok. If we want to add 802.1CB later, specific value used can be
extended to use 802.1CB.

> 
>>
>> BTW, I have posted the existing iproute2 code also to the mailing list
>> with title 'iproute2: Add PRP support'.
>>
>> If re-using hsr code with existing prefix is fine for PRP or any future
>> protocol such as 801.1B, then I will drop patch 1-6 that are essentially
>> doing some renaming and re-use existing hsr netlink code for PRP with
>> added attribute to differentiate the protocol at the driver as described
>> above along with proto_ops and re-spin the series.
> 
> If I forget that HSR is also the name of a protocol, what the acronym
> means makes sense for 802.1CB, so it's not too bad, I think.
> 

Agree.

>>
>> Let me know.
>>
>> Regards,
>>
>> Murali
> 
> 
> Cheers,
> 

-- 
Murali Karicheri
Texas Instruments

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2020-05-26 21:51 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 16:30 [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 01/13] net: hsr: Re-use Kconfig option to support PRP Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 02/13] net: hsr: rename hsr directory to hsr-prp to introduce PRP Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 03/13] net: hsr: rename files to introduce PRP support Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 04/13] net: hsr: rename hsr variable inside struct hsr_port to priv Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 05/13] net: hsr: rename hsr_port_get_hsr() to hsr_prp_get_port() Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 06/13] net: hsr: some renaming to introduce PRP driver support Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 07/13] net: hsr: introduce common uapi include/definitions for HSR and PRP Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 08/13] net: hsr: migrate HSR netlink socket code to use new common API Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 09/13] net: hsr: move re-usable code for PRP to hsr_prp_netlink.c Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 10/13] net: hsr: add netlink socket interface for PRP Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 11/13] net: prp: add supervision frame generation and handling support Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 12/13] net: prp: add packet " Murali Karicheri
2020-05-06 16:30 ` [net-next RFC PATCH 13/13] net: prp: enhance debugfs to display PRP specific info in node table Murali Karicheri
2020-05-13 12:27 ` [net-next RFC PATCH 00/13] net: hsr: Add PRP driver Murali Karicheri
2020-05-21 12:34   ` Murali Karicheri
2020-05-21 17:31 ` Vinicius Costa Gomes
2020-05-25 16:49   ` Murali Karicheri
2020-05-26 18:56     ` Vinicius Costa Gomes
2020-05-26 21:51       ` Murali Karicheri
2020-05-25 21:37   ` Vladimir Oltean
2020-05-26 14:12     ` Murali Karicheri
2020-05-26 18:25       ` Vladimir Oltean
2020-05-26 21:33         ` Murali Karicheri
2020-05-26 18:09     ` Vinicius Costa Gomes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.