Add PRP driver and bug fixes
Subsystems (4)
v2 cover Add PRP driver and bug fixes
Hello,
This series adds support for Parallel Redundancy Protocol (PRP) in the Linux HSR driver as defined in IEC-62439-3. 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 will be treated as pad 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-uses the code from HSR driver to implement PRP driver. As per feedback from the RFC series, the implementation uses the existing HSR Netlink socket interface to create the PRP interface by adding a new proto parameter to the ip link command to identify the PRP protocol. iproute2 is enhanced to implement this new parameter. The hsr_netlink.c is enhanced to handle the new proto parameter. As suggested during the RFC review, the driver introduced a proto_ops structure to hold protocol specfic functions to handle HSR and PRP specific function pointers and use them in the code based on the protocol to handle protocol specific part differently in the driver.
Please review this and provide me feedback so that I can work to incorporate them and spin the next version if needed.
The patch was tested using two TI AM57x IDK boards for PRP which are connected back to back over two CPSW Ethernet ports.
PRP Test setup
---------------
--------eth0 eth0 --------
|AM572x|----------------------|AM572x| | |----------------------| | --------eth1 eth1 --------
To build, enable CONFIG_HSR=y or m
make omap2plus_defconfig
make zImage; make modules; make dtbs
Copy the zImage and dtb files to the file system on SD card and power on the AM572x boards.
This can be tested on any platforms with 2 Ethernet interfaces. So will appreciate if you can give it a try and provide your Tested-by.
Command to create PRP interface
-------------------------------
ifconfig eth0 0.0.0.0 down
ifconfig eth1 0.0.0.0 down
ifconfig eth0 hw ether 70:FF:76:1C:0E:8C
ifconfig eth1 hw ether 70:FF:76:1C:0E:8C
ifconfig eth0 up
ifconfig eth1 up
ip link add name prp0 type hsr slave1 eth0 slave2 eth1 supervision 45 proto 1 ifconfig prp0 192.168.2.10
ifconfig eth0 0.0.0.0 down
ifconfig eth1 0.0.0.0 down
ifconfig eth0 hw ether 70:FF:76:1C:0E:8D
ifconfig eth1 hw ether 70:FF:76:1C:0E:8D
ifconfig eth0 up
ifconfig eth1 up
ip link add name prp0 type hsr slave1 eth0 slave2 eth1 supervision 45 proto 1 ifconfig prp0 192.168.2.20
command to show node table
----------------------------
Ping the peer board after the prp0 interface is up.
The remote node (DAN-P) will be shown in the node table as below.
root@am57xx-evm:~# cat /sys/kernel/debug/hsr/prp0/node_table Node Table entries for (PRP) device MAC-Address-A, MAC-Address-B, time_in[A], time_in[B], Address-B port, SAN-A, SAN-B, DAN-P 70:ff:76:1c:0e:8c 00:00:00:00:00:00 ffffe83f, ffffe83f, 0, 0, 0, 1
Try to capture the raw PRP frames at the eth0 interface as tcpdump -i eth0 -xxx
Sample Supervision frames and ARP frames shown below.
==================================================================================
Successive Supervision frames captured with tcpdump (with RCT at the end):
03:43:29.500999 70:ff:76:1c:0e:8d (oui Unknown) > 01:15:4e:00:01:2d (oui Unknown), ethertype Unknown (0x88f
0x0000: 0115 4e00 012d 70ff 761c 0e8d 88fb 0001
0x0010: 7e0a 1406 70ff 761c 0e8d 0000 0000 0000
0x0020: 0000 0000 0000 0000 0000 0000 0000 0000
0x0030: 0000 0000 0000 0000 0000 0000 fc2b a034
0x0040: 88fb 03:43:31.581025 70:ff:76:1c:0e:8d (oui Unknown) > 01:15:4e:00:01:2d (oui Unknown), ethertype Unknown (0x88f
0x0000: 0115 4e00 012d 70ff 761c 0e8d 88fb 0001
0x0010: 7e0b 1406 70ff 761c 0e8d 0000 0000 0000
0x0020: 0000 0000 0000 0000 0000 0000 0000 0000
0x0030: 0000 0000 0000 0000 0000 0000 fc2c a034
0x0040: 88fb ICMP Echo request frame with RCT
03:43:33.805354 IP 192.168.2.20 > 192.168.2.10: ICMP echo request, id 63748, seq 1, length 64
0x0000: 70ff 761c 0e8c 70ff 761c 0e8d 0800 4500
0x0010: 0054 26a4 4000 4001 8e96 c0a8 0214 c0a8
0x0020: 020a 0800 c28e f904 0001 202e 1c3d 0000
0x0030: 0000 0000 0000 0000 0000 0000 0000 0000
0x0040: 0000 0000 0000 0000 0000 0000 0000 0000
0x0050: 0000 0000 0000 0000 0000 0000 0000 0000
0x0060: 0000 fc31 a05a 88fb ==================================================================================
The iperf3 traffic test logs can be accessed at the links below.
DUT-1: https://pastebin.ubuntu.com/p/8SkQzWJMn8/
DUT-2: https://pastebin.ubuntu.com/p/j2BZvvs7p4/
Other tests done.
- Connect a SAN (eth0 and eth1 without prp interface) and do ping test from eth0 (192.168.2.40) to prp0 (192.168.2.10) verify the SAN node shows at the correct link A and B as shown in the node table dump
- Regress HSR interface using 3 nodes connected in a ring topology. create hsr link version 0. Do iperf3 test between all nodes create hsr link version 1. Do iperf3 test between all nodes.
--------eth0 eth1 --------eth0 eth1-------|
|AM572x|----------------------|AM572x|--------------|AM572x|
| | | | ------| |
--------eth1---| ------- | eth0 -------
|-------------------------------command used for HSR interface
HSR V0
ifconfig eth0 0.0.0.0 down
ifconfig eth1 0.0.0.0 down
ifconfig eth0 hw ether 70:FF:76:1C:0E:8C
ifconfig eth1 hw ether 70:FF:76:1C:0E:8C
ifconfig eth0 up
ifconfig eth1 up
ip link add name hsr0 type hsr slave1 eth0 slave2 eth1 supervision 45 version 0 ifconfig hsr0 192.168.2.10
HSR V1
ifconfig eth0 0.0.0.0 down
ifconfig eth1 0.0.0.0 down
ifconfig eth0 hw ether 70:FF:76:1C:0E:8C
ifconfig eth1 hw ether 70:FF:76:1C:0E:8C
ifconfig eth0 up
ifconfig eth1 up
ip link add name hsr0 type hsr slave1 eth0 slave2 eth1 supervision 45 version 1 ifconfig hsr0 192.168.2.10
Logs at
DUT-1 : https://pastebin.ubuntu.com/p/6PSJbZwQ6y/
DUT-2 : https://pastebin.ubuntu.com/p/T8TqJsPRHc/
DUT-3 : https://pastebin.ubuntu.com/p/VNzpv6HzKj/
- Build tests :-
Build with CONFIG_HSR=m
allmodconfig build
build with CONFIG_HSR=y and rebuild with sparse checker make C=1 zImage; make modules
Version history:
v2 : updated comments on RFC. Following are the main changes:-
- Removed the hsr_prp prefix
- Added PRP information in header files to indicate the support for PRP explicitely
- Re-use netlink socket interface with an added parameter proto for identifying PRP.
- Use function pointers using a proto_ops struct to do things differently for PRP vs HSR.
RFC: initial version posted and discussed at
https://www.spinics.net/lists/netdev/msg656229.html
Murali Karicheri (9):
net: hsr: fix incorrect lsdu size in the tag of HSR frames for small
frames
net: hsr/prp: validate address B before copying to skb
hsr: enhance netlink socket interface to support PRP
net: hsr: introduce common code for skb initialization
net: hsr: introduce protocol specific function pointers
net: prp: add supervision frame generation utility function
net: hsr: define and use proto_ops ptrs to handle hsr specific frames
net: prp: add packet handling support
net: prp: enhance debugfs to display PRP info
include/uapi/linux/hsr_netlink.h | 2 +- include/uapi/linux/if_link.h | 12 +- net/hsr/Kconfig | 37 ++-- net/hsr/hsr_debugfs.c | 33 +++- net/hsr/hsr_device.c | 181 ++++++++++++++---- net/hsr/hsr_device.h | 2 + net/hsr/hsr_forward.c | 308 ++++++++++++++++++++++++------- net/hsr/hsr_forward.h | 16 +- net/hsr/hsr_framereg.c | 100 ++++++++-- net/hsr/hsr_framereg.h | 31 +++- net/hsr/hsr_main.c | 2 + net/hsr/hsr_main.h | 120 +++++++++++- net/hsr/hsr_netlink.c | 38 +++- net/hsr/hsr_netlink.h | 2 + net/hsr/hsr_slave.c | 26 ++- net/hsr/hsr_slave.h | 4 + 16 files changed, 745 insertions(+), 169 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/9 net: hsr: fix incorrect lsdu size in the tag of HSR frames for small frames
For small Ethernet frames with size less than minimum size 66 for HSR vs 60 for regular Ethernet frames, hsr driver currently doesn't pad the frame to make it minimum size. This results in incorrect LSDU size being populated in the HSR tag for these frames. Fix this by padding the frame to the minimum size applicable for HSR.
--- net/hsr/hsr_forward.c | 3 +++ 1 file changed, 3 insertions(+)
net/hsr/hsr_forward.c +3 -0
@@ -127,6 +127,9 @@ static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame,int lane_id;int lsdu_size; +/* pad to minimum packet size which is 60 + 6 (HSR tag) */ +skb_put_padto (skb,ETH_ZLEN +HSR_HLEN ); +if (port->type ==HSR_PT_SLAVE_A ) lane_id =0 ;else
Signature · 1 line
2.17.1
PATCH v2 2/9 net: hsr/prp: validate address B before copying to skb
In reply to Murali KaricheriValidate MAC address before copying the same to outgoing frame skb destination address.
--- net/hsr/hsr_framereg.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/hsr/hsr_framereg.c +4 -1
@@ -325,7 +325,10 @@ void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,if (port->type != node_dst->addr_B_port)return ; -ether_addr_copy (eth_hdr (skb)->h_dest, node_dst->macaddress_B); +if (is_valid_ether_addr (node_dst->macaddress_B)) +ether_addr_copy (eth_hdr (skb)->h_dest, node_dst->macaddress_B); +else +WARN_ONCE (1 ,"%s: mac address B not valid\n" , __func__); } void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,
Signature · 1 line
2.17.1
PATCH v2 3/9 hsr: enhance netlink socket interface to support PRP
In reply to Murali KaricheriParallel Redundancy Protocol (PRP) is another redundancy protocol introduced by IEC 63439 standard. It is similar to HSR in many aspects:-
- Use a pair of Ethernet interfaces to created the PRP device
- Use a 6 byte redundancy protocol part (RCT, Redundancy Check Trailer) similar to HSR Tag.
- Has Link Redundancy Entity (LRE) that works with RCT to implement redundancy.
Key difference is that the protocol unit is a trailer instead of a prefix as in HSR. That makes it inter-operable with tradition network components such as bridges/switches which treat it as pad bytes, whereas HSR nodes requires some kind of translators (Called redbox) to talk to regular network devices. This features allows regular linux box to be converted to a DAN-P box. DAN-P stands for Dual Attached Node - PRP similar to DAN-H (Dual Attached Node - HSR).
Add a comment at the header/source code to explicitly state that the driver files also handles PRP protocol as well.
--- include/uapi/linux/hsr_netlink.h | 2 +- include/uapi/linux/if_link.h | 12 +++++++++- net/hsr/Kconfig | 37 ++++++++++++++++++++----------- net/hsr/hsr_debugfs.c | 2 +- net/hsr/hsr_device.c | 7 ++++-- net/hsr/hsr_device.h | 2 ++ net/hsr/hsr_forward.c | 2 ++ net/hsr/hsr_forward.h | 2 ++ net/hsr/hsr_framereg.c | 1 + net/hsr/hsr_framereg.h | 2 ++ net/hsr/hsr_main.c | 2 ++ net/hsr/hsr_main.h | 11 ++++++++- net/hsr/hsr_netlink.c | 38 ++++++++++++++++++++++++++------ net/hsr/hsr_netlink.h | 2 ++ net/hsr/hsr_slave.c | 2 ++ net/hsr/hsr_slave.h | 2 ++ 16 files changed, 100 insertions(+), 26 deletions(-)
include/uapi/linux/hsr_netlink.h +1 -1
@@ -17,7 +17,7 @@/* Generic Netlink HSR family definition */ -/* attributes */ +/* attributes for HSR or PRP node */ enum {HSR_A_UNSPEC ,HSR_A_NODE_ADDR ,
include/uapi/linux/if_link.h +11 -1
@@ -906,7 +906,14 @@ enum {#define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1) -/* HSR section */ +/* HSR/PRP section, both uses same interface */ + +/* Different redundancy protocols for hsr device */ +enum { +HSR_PROTOCOL_HSR , +HSR_PROTOCOL_PRP , +HSR_PROTOCOL_MAX , +};enum {IFLA_HSR_UNSPEC ,
@@ -916,6 +923,9 @@ enum {IFLA_HSR_SUPERVISION_ADDR ,/* Supervision frame multicast addr */ IFLA_HSR_SEQ_NR ,IFLA_HSR_VERSION ,/* HSR version */ +IFLA_HSR_PROTOCOL ,/* Indicate different protocol than +* HSR. For example PRP. +*/ __IFLA_HSR_MAX, };
net/hsr/Kconfig +24 -13
@@ -4,24 +4,35 @@ # config HSR - tristate "High-availability Seamless Redundancy (HSR)" - help + tristate "High-availability Seamless Redundancy (HSR & PRP)" + ---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. Unlike HSR, PRP networks + can have Singly Attached Nodes (SAN) such as PC, printer, bridges + etc and will be able to communicate with DANP nodes. 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!
net/hsr/hsr_debugfs.c +1 -1
@@ -1,5 +1,5 @@/* -* hsr_debugfs code +* debugfs code for HSR & PRP * Copyright (C) 2019 Texas Instruments Incorporated * * Author(s):
net/hsr/hsr_device.c +5 -2
@@ -3,9 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] -* * This file contains device methods for creating, using and destroying -* virtual HSR devices. +* virtual HSR or PRP devices. */ #include <linux/netdevice.h>
@@ -427,6 +426,10 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],ether_addr_copy (hsr_dev->dev_addr, slave[0 ]->dev_addr); +/* currently PRP is not supported */ +if (protocol_version ==PRP_V1 ) +return -EPROTONOSUPPORT ; +/* Make sure we recognize frames from ourselves in hsr_rcv() */ res =hsr_create_self_node (hsr, hsr_dev->dev_addr, slave[1 ]->dev_addr);
net/hsr/hsr_device.h +2 -0
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* include file for HSR and PRP. */ #ifndef __HSR_DEVICE_H
net/hsr/hsr_forward.c +2 -0
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* Frame router for HSR and PRP. */ #include "hsr_forward.h"
net/hsr/hsr_forward.h +2 -0
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* include file for HSR and PRP. */ #ifndef __HSR_FORWARD_H
net/hsr/hsr_framereg.c +1 -0
@@ -8,6 +8,7 @@* interface. A frame is identified by its source MAC address and its HSR * sequence number. This code keeps track of senders and their sequence numbers * to allow filtering of duplicate frames, and to detect HSR ring errors. +* Same code handles filtering of duplicates for PRP as well. */ #include <linux/if_ether.h>
net/hsr/hsr_framereg.h +2 -0
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* include file for HSR and PRP. */ #ifndef __HSR_FRAMEREG_H
net/hsr/hsr_main.c +2 -0
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* Event handling for HSR and PRP devices. */ #include <linux/netdevice.h>
net/hsr/hsr_main.h +10 -1
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* include file for HSR and PRP. */ #ifndef __HSR_PRIVATE_H
@@ -131,6 +133,13 @@ struct hsr_port {enum hsr_port_type type; }; +/* used by driver internally to differentiate various protocols */ +enum hsr_version { +HSR_V0 =0 , +HSR_V1 , +PRP_V1 , +}; +struct hsr_priv {struct rcu_head rcu_head;struct list_head ports;
@@ -141,7 +150,7 @@ struct hsr_priv {int announce_count;u16 sequence_nr;u16 sup_sequence_nr;/* For HSRv1 separate seq_nr for supervision */ -u8 prot_version;/* Indicate if HSRv0 or HSRv1. */ +enum hsr_version prot_version;/* Indicate if HSRv0, HSRv1 or PRPv1 */ spinlock_t seqnr_lock;/* locking for sequence_nr */ spinlock_t list_lock;/* locking for node list */ unsigned char sup_multicast_addr[ETH_ALEN ];
net/hsr/hsr_netlink.c +31 -7
@@ -4,7 +4,7 @@* Author(s): * 2011-2014 Arvid Brodin, [email protected] * -* Routines for handling Netlink messages for HSR. +* Routines for handling Netlink messages for HSR and PRP. */ #include "hsr_netlink.h"
@@ -22,6 +22,7 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = { [IFLA_HSR_VERSION] = { .type = NLA_U8 }, [IFLA_HSR_SUPERVISION_ADDR] = { .len = ETH_ALEN }, [IFLA_HSR_SEQ_NR] = { .type = NLA_U16 }, + [IFLA_HSR_PROTOCOL] = { .type = NLA_U8 }, };/* Here, it seems a netdevice has already been allocated for us, and the
@@ -32,7 +33,9 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev, struct netlink_ext_ack *extack) {struct net_device *link[2 ]; -unsigned char multicast_spec, hsr_version; +unsigned char multicast_spec; +enum hsr_version proto_version; +u8 proto =HSR_PROTOCOL_HSR ;if (!data) {NL_SET_ERR_MSG_MOD (extack,"No slave devices specified" );
@@ -69,18 +72,34 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,else multicast_spec =nla_get_u8 (data[IFLA_HSR_MULTICAST_SPEC ]); +if (data[IFLA_HSR_PROTOCOL ]) + proto =nla_get_u8 (data[IFLA_HSR_PROTOCOL ]); + +if (proto >=HSR_PROTOCOL_MAX ) { +NL_SET_ERR_MSG_MOD (extack,"Unsupported protocol\n" ); +return -EINVAL ; + } +if (!data[IFLA_HSR_VERSION ]) { - hsr_version =0 ; + proto_version =HSR_V0 ; }else { - hsr_version =nla_get_u8 (data[IFLA_HSR_VERSION ]); -if (hsr_version >1 ) { +if (proto ==HSR_PROTOCOL_PRP ) { +NL_SET_ERR_MSG_MOD (extack,"PRP version unsupported\n" ); +return -EINVAL ; + } + + proto_version =nla_get_u8 (data[IFLA_HSR_VERSION ]); +if (proto_version >HSR_V1 ) {NL_SET_ERR_MSG_MOD (extack, -"Only versions 0..1 are supported" ); +"Only HSR version 0/1 supported\n" );return -EINVAL ; } } -return hsr_dev_finalize (dev, link, multicast_spec, hsr_version, extack); +if (proto ==HSR_PROTOCOL_PRP ) + proto_version =PRP_V1 ; + +return hsr_dev_finalize (dev, link, multicast_spec, proto_version, extack); }static void hsr_dellink (struct net_device *dev,struct list_head *head)
@@ -102,6 +121,7 @@ static void hsr_dellink(struct net_device *dev, struct list_head *head)static int hsr_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct hsr_priv *hsr =netdev_priv (dev); +u8 proto =HSR_PROTOCOL_HSR ;struct hsr_port *port; port =hsr_port_get_hsr (hsr,HSR_PT_SLAVE_A );
@@ -120,6 +140,10 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) hsr->sup_multicast_addr) || nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr)) goto nla_put_failure; +if (hsr->prot_version ==PRP_V1 ) + proto =HSR_PROTOCOL_PRP ; +if (nla_put_u8 (skb,IFLA_HSR_PROTOCOL , proto)) + goto nla_put_failure;return 0 ;
net/hsr/hsr_netlink.h +2 -0
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* include file for HSR and PRP. */ #ifndef __HSR_NETLINK_H
net/hsr/hsr_slave.c +2 -0
@@ -3,6 +3,8 @@* * Author(s): * 2011-2014 Arvid Brodin, [email protected] +* +* Frame handler other utility functions for HSR and PRP. */ #include "hsr_slave.h"
net/hsr/hsr_slave.h +2 -0
@@ -2,6 +2,8 @@/* Copyright 2011-2014 Autronica Fire and Security AS * * 2011-2014 Arvid Brodin, [email protected] +* +* include file for HSR and PRP. */ #ifndef __HSR_SLAVE_H
Signature · 1 line
2.17.1
PATCH v2 4/9 net: hsr: introduce common code for skb initialization
In reply to Murali KaricheriAs a preparatory patch to introduce PRP protocol support in the driver, refactor the skb init code to a separate function.
--- net/hsr/hsr_device.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)
net/hsr/hsr_device.c +28 -13
@@ -230,15 +230,11 @@ static const struct header_ops hsr_header_ops = { .parse = eth_header_parse, }; -static void send_hsr_supervision_frame (struct hsr_port *master, -u8 type,u8 hsr_ver) +static struct sk_buff *hsr_init_skb (struct hsr_port *master,u8 hsr_ver) { +struct hsr_priv *hsr = master->hsr;struct sk_buff *skb;int hlen, tlen; -struct hsr_tag *hsr_tag; -struct hsr_sup_tag *hsr_stag; -struct hsr_sup_payload *hsr_sp; -unsigned long irqflags; hlen =LL_RESERVED_SPACE (master->dev); tlen = master->dev->needed_tailroom;
@@ -247,22 +243,44 @@ static void send_hsr_supervision_frame(struct hsr_port *master, sizeof(struct hsr_sup_payload) + hlen + tlen);if (!skb) -return ; +return skb;skb_reserve (skb, hlen); - skb->dev = master->dev; skb->protocol =htons (hsr_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 ), - master->hsr->sup_multicast_addr, + hsr->sup_multicast_addr, skb->dev->dev_addr, skb->len) <=0 ) goto out; +skb_reset_mac_header (skb);skb_reset_network_header (skb);skb_reset_transport_header (skb); +return skb; +out: +kfree_skb (skb); + +return NULL ; +} + +static void send_hsr_supervision_frame (struct hsr_port *master, +u8 type,u8 hsr_ver) +{ +struct sk_buff *skb; +struct hsr_tag *hsr_tag; +struct hsr_sup_tag *hsr_stag; +struct hsr_sup_payload *hsr_sp; +unsigned long irqflags; + + skb =hsr_init_skb (master, hsr_ver); +if (!skb) { +WARN_ONCE (1 ,"HSR: Could not send supervision frame\n" ); +return ; + } +if (hsr_ver >0 ) { hsr_tag =skb_put (skb,sizeof (struct hsr_tag )); hsr_tag->encap_proto =htons (ETH_P_PRP );
@@ -299,11 +317,8 @@ static void send_hsr_supervision_frame(struct hsr_port *master,return ;hsr_forward_skb (skb, master); -return ; -out: -WARN_ONCE (1 ,"HSR: Could not send supervision frame\n" ); -kfree_skb (skb); +return ; }/* Announce (supervision frame) timer function
Signature · 1 line
2.17.1
PATCH v2 5/9 net: hsr: introduce protocol specific function pointers
In reply to Murali KaricheriAs a preparatory patch to introduce support for PRP protocol, add a protocol ops ptr in the private hsr structure to hold function pointers as some of the functions at protocol level packet handling is different for HSR vs PRP. It is expected that PRP will add its of set of functions for protocol handling. Modify existing hsr_announce() function to call proto_ops->send_sv_frame() to send supervision frame for HSR. This is expected to be different for PRP. So introduce a ops function ptr, send_sv_frame() for the same and initialize it to send_hsr_supervsion_frame(). Modify hsr_announce() to call proto_ops->send_sv_frame().
--- net/hsr/hsr_device.c | 74 ++++++++++++++++++++++++-------------------- net/hsr/hsr_main.h | 6 ++++ 2 files changed, 47 insertions(+), 33 deletions(-)
net/hsr/hsr_device.c +41 -33
@@ -230,7 +230,7 @@ static const struct header_ops hsr_header_ops = { .parse = eth_header_parse, }; -static struct sk_buff *hsr_init_skb (struct hsr_port *master,u8 hsr_ver) +static struct sk_buff *hsr_init_skb (struct hsr_port *master,u16 proto) {struct hsr_priv *hsr = master->hsr;struct sk_buff *skb;
@@ -247,10 +247,10 @@ static struct sk_buff *hsr_init_skb(struct hsr_port *master, u8 hsr_ver)skb_reserve (skb, hlen); skb->dev = master->dev; - skb->protocol =htons (hsr_ver ?ETH_P_HSR :ETH_P_PRP ); + skb->protocol =htons (proto); 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, hsr->sup_multicast_addr, skb->dev->dev_addr, skb->len) <=0 ) goto out;
@@ -267,47 +267,62 @@ static struct sk_buff *hsr_init_skb(struct hsr_port *master, u8 hsr_ver) }static void send_hsr_supervision_frame (struct hsr_port *master, -u8 type,u8 hsr_ver) +unsigned long *interval) { -struct sk_buff *skb; -struct hsr_tag *hsr_tag; -struct hsr_sup_tag *hsr_stag; +struct hsr_priv *hsr = master->hsr; +__u8 type =HSR_TLV_LIFE_CHECK ; +struct hsr_tag *hsr_tag =NULL ;struct hsr_sup_payload *hsr_sp; +struct hsr_sup_tag *hsr_stag;unsigned long irqflags; +struct sk_buff *skb; +u16 proto; + + *interval =msecs_to_jiffies (HSR_LIFE_CHECK_INTERVAL ); +if (hsr->announce_count <3 && hsr->prot_version ==0 ) { + type =HSR_TLV_ANNOUNCE ; + *interval =msecs_to_jiffies (HSR_ANNOUNCE_INTERVAL ); + hsr->announce_count++; + } + +if (!hsr->prot_version) + proto =ETH_P_PRP ; +else + proto =ETH_P_HSR ; - skb =hsr_init_skb (master, hsr_ver); + skb =hsr_init_skb (master, proto);if (!skb) {WARN_ONCE (1 ,"HSR: Could not send supervision frame\n" );return ; } -if (hsr_ver >0 ) { +if (hsr->prot_version >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); +set_hsr_stag_path (hsr_stag, (hsr->prot_version ?0x0 :0xf )); +set_hsr_stag_HSR_ver (hsr_stag, hsr->prot_version);/* From HSRv1 on we have separate supervision sequence numbers. */ spin_lock_irqsave (&master->hsr->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++; +if (hsr->prot_version >0 ) { + hsr_stag->sequence_nr =htons (hsr->sup_sequence_nr); + hsr->sup_sequence_nr++; + hsr_tag->sequence_nr =htons (hsr->sequence_nr); + hsr->sequence_nr++; }else { - hsr_stag->sequence_nr =htons (master->hsr->sequence_nr); - master->hsr->sequence_nr++; + hsr_stag->sequence_nr =htons (hsr->sequence_nr); + hsr->sequence_nr++; }spin_unlock_irqrestore (&master->hsr->seqnr_lock, irqflags); 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 = hsr->prot_version ? +sizeof (struct hsr_sup_payload ) :12 ;/* Payload: MacAddressA */ hsr_sp =skb_put (skb,sizeof (struct hsr_sup_payload ));
@@ -333,19 +348,7 @@ static void hsr_announce(struct timer_list *t)rcu_read_lock (); master =hsr_port_get_hsr (hsr,HSR_PT_MASTER ); - -if (hsr->announce_count <3 && hsr->prot_version ==0 ) { -send_hsr_supervision_frame (master,HSR_TLV_ANNOUNCE , - hsr->prot_version); - hsr->announce_count++; - - interval =msecs_to_jiffies (HSR_ANNOUNCE_INTERVAL ); - }else { -send_hsr_supervision_frame (master,HSR_TLV_LIFE_CHECK , - hsr->prot_version); - - interval =msecs_to_jiffies (HSR_LIFE_CHECK_INTERVAL ); - } + hsr->proto_ops->send_sv_frame (master, &interval);if (is_admin_up (master->dev))mod_timer (&hsr->announce_timer, jiffies + interval);
@@ -382,6 +385,10 @@ static struct device_type hsr_type = { .name = "hsr", }; +static struct hsr_proto_ops hsr_ops = { + .send_sv_frame = send_hsr_supervision_frame, +}; +void hsr_dev_setup (struct net_device *dev) {eth_hw_addr_random (dev);
@@ -445,6 +452,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],if (protocol_version ==PRP_V1 )return -EPROTONOSUPPORT ; + hsr->proto_ops = &hsr_ops;/* Make sure we recognize frames from ourselves in hsr_rcv() */ res =hsr_create_self_node (hsr, hsr_dev->dev_addr, slave[1 ]->dev_addr);
net/hsr/hsr_main.h +6 -0
@@ -140,6 +140,11 @@ enum hsr_version { PRP_V1, }; +struct hsr_proto_ops { +/* format and send supervision frame */ +void (*send_sv_frame)(struct hsr_port *port,unsigned long *interval); +}; +struct hsr_priv {struct rcu_head rcu_head;struct list_head ports;
@@ -153,6 +158,7 @@ struct hsr_priv {enum hsr_version prot_version;/* Indicate if HSRv0, HSRv1 or PRPv1 */ spinlock_t seqnr_lock;/* locking for sequence_nr */ spinlock_t list_lock;/* locking for node list */ +struct hsr_proto_ops *proto_ops;unsigned char sup_multicast_addr[ETH_ALEN ];#ifdef CONFIG_DEBUG_FS struct dentry *node_tbl_root;
Signature · 1 line
2.17.1
PATCH v2 1/2 iplink: hsr: add support for creating PRP device similar to HSR
In reply to Murali KaricheriThis patch enhances the iplink command to add a proto parameters to create PRP device/interface similar to HSR. Both protocols are quite similar and requires a pair of Ethernet interfaces. So re-use the existing HSR iplink command to create PRP device/interface as well. Use proto parameter to differentiate the two protocols.
--- include/uapi/linux/if_link.h | 12 +++++++++++- ip/iplink_hsr.c | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-)
include/uapi/linux/if_link.h +11 -1
@@ -904,7 +904,14 @@ enum {#define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1) -/* HSR section */ +/* HSR/PRP section, both uses same interface */ + +/* Different redundancy protocols for hsr device */ +enum { +HSR_PROTOCOL_HSR , +HSR_PROTOCOL_PRP , +HSR_PROTOCOL_MAX , +};enum {IFLA_HSR_UNSPEC ,
@@ -914,6 +921,9 @@ enum {IFLA_HSR_SUPERVISION_ADDR ,/* Supervision frame multicast addr */ IFLA_HSR_SEQ_NR ,IFLA_HSR_VERSION ,/* HSR version */ +IFLA_HSR_PROTOCOL ,/* Indicate different protocol than +* HSR. For example PRP. +*/ __IFLA_HSR_MAX, };
ip/iplink_hsr.c +17 -2
@@ -25,7 +25,7 @@ static void print_usage(FILE *f) {fprintf (f,"Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n" -"\t[ supervision ADDR-BYTE ] [version VERSION]\n" +"\t[ supervision ADDR-BYTE ] [version VERSION] [proto PROTOCOL]\n" "\n" "NAME\n" " name of new hsr device (e.g. hsr0)\n"
@@ -35,7 +35,9 @@ static void print_usage(FILE *f)" 0-255; the last byte of the multicast address used for HSR supervision\n" " frames (default = 0)\n" "VERSION\n" - " 0,1; the protocol version to be used. (default = 0)\n"); +" 0,1; the protocol version to be used. (default = 0)\n" +"PROTOCOL\n" + " 0 - HSR, 1 - PRP. (default = 0 - HSR)\n"); }static void usage (void )
@@ -49,6 +51,7 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,int ifindex;unsigned char multicast_spec;unsigned char protocol_version; +unsigned char protocol =HSR_PROTOCOL_HSR ;while (argc >0 ) {if (matches (*argv,"supervision" ) ==0 ) {
@@ -64,6 +67,13 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,invarg ("version is invalid" , *argv);addattr_l (n,1024 ,IFLA_HSR_VERSION , &protocol_version,1 ); + }else if (matches (*argv,"proto" ) ==0 ) { +NEXT_ARG (); +if (!(get_u8 (&protocol, *argv,0 ) ==HSR_PROTOCOL_HSR || +get_u8 (&protocol, *argv,0 ) ==HSR_PROTOCOL_PRP )) +invarg ("protocol is invalid" , *argv); +addattr_l (n,1024 ,IFLA_HSR_PROTOCOL , + &protocol,1 ); }else if (matches (*argv,"slave1" ) ==0 ) {NEXT_ARG (); ifindex =ll_name_to_index (*argv);
@@ -140,6 +150,11 @@ static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])RTA_PAYLOAD (tb[IFLA_HSR_SUPERVISION_ADDR ]),ARPHRD_VOID , b1, sizeof(b1))); +if (tb[IFLA_HSR_PROTOCOL ]) +print_int (PRINT_ANY , +"proto" , +"proto %d " , +rta_getattr_u8 (tb[IFLA_HSR_PROTOCOL ])); } static void hsr_print_help(struct link_util *lu, int argc, char **argv,
Signature · 1 line
2.17.1
PATCH v2 2/2 ip: iplink: prp: update man page for new parameter
In reply to Murali KaricheriPRP support requires a proto parameter which is 0 for hsr and 1 for prp. Default is hsr and is backward compatible.
--- man/man8/ip-link.8.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
man/man8/ip-link.8.in +8 -1
@@ -1360,7 +1360,8 @@ the following additional arguments are supported: .BI slave1 " SLAVE1-IF " slave2 " SLAVE2-IF " .RB [ " supervision" .IR ADDR-BYTE " ] [" -.BR version " { " 0 " | " 1 " } ]" +.BR version " { " 0 " | " 1 " } [" +.BR proto " { " 0 " | " 1 " } ]" .in +8 .sp
@@ -1381,6 +1382,12 @@ Default option is "0", possible values 0-255. - Selects the protocol version of the interface. Default option is "0", which corresponds to the 2010 version of the HSR standard. Option "1" activates the 2012 version. + +.BR proto " { " 0 " | " 1 " }" +- Selects the protocol at the interface. Default option is "0", which +corresponds to the HSR standard. Option "1" activates the Parallel +Redundancy Protocol (PRP). +. .in -8 .TP
Signature · 1 line
2.17.1
PATCH v2 6/9 net: prp: add supervision frame generation utility function
In reply to Murali KaricheriAdd support for generation of PRP supervision frames. For PRP, supervision frame format is similar to HSR version 0, but have a PRP Redundancy Control Trailer (RCT) added and uses a different message type, PRP_TLV_LIFE_CHECK_DD. Also update is_supervision_frame() to include the new message type used for PRP supervision frame.
--- net/hsr/hsr_device.c | 64 ++++++++++++++++++++++++++++++++++++++++++- net/hsr/hsr_forward.c | 4 ++- net/hsr/hsr_main.h | 22 +++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-)
net/hsr/hsr_device.c +63 -1
@@ -238,6 +238,10 @@ static struct sk_buff *hsr_init_skb(struct hsr_port *master, u16 proto) 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 trailer and for HSR it is a +* header +*/ skb =dev_alloc_skb (sizeof (struct hsr_tag ) +sizeof (struct hsr_sup_tag ) +sizeof (struct hsr_sup_payload ) + hlen + tlen);
@@ -336,6 +340,55 @@ static void send_hsr_supervision_frame(struct hsr_port *master,return ; } +static void send_prp_supervision_frame (struct hsr_port *master, +unsigned long *interval) +{ +struct hsr_priv *hsr = master->hsr; +struct hsr_sup_payload *hsr_sp; +struct hsr_sup_tag *hsr_stag; +unsigned long irqflags; +struct sk_buff *skb; +struct prp_rct *rct; +u8 *tail; + + skb =hsr_init_skb (master,ETH_P_PRP ); +if (!skb) { +WARN_ONCE (1 ,"PRP: Could not send supervision frame\n" ); +return ; + } + + *interval =msecs_to_jiffies (HSR_LIFE_CHECK_INTERVAL ); + hsr_stag =skb_put (skb,sizeof (struct hsr_sup_tag )); +set_hsr_stag_path (hsr_stag, (hsr->prot_version ?0x0 :0xf )); +set_hsr_stag_HSR_ver (hsr_stag, (hsr->prot_version ?1 :0 )); + +/* From HSRv1 on we have separate supervision sequence numbers. */ +spin_lock_irqsave (&master->hsr->seqnr_lock, irqflags); + hsr_stag->sequence_nr =htons (hsr->sup_sequence_nr); + hsr->sup_sequence_nr++; + hsr_stag->HSR_TLV_type =PRP_TLV_LIFE_CHECK_DD ; + hsr_stag->HSR_TLV_length =sizeof (struct hsr_sup_payload ); + +/* Payload: MacAddressA */ + hsr_sp =skb_put (skb,sizeof (struct hsr_sup_payload )); +ether_addr_copy (hsr_sp->macaddress_A, master->dev->dev_addr); + +if (skb_put_padto (skb,ETH_ZLEN +HSR_HLEN )) { +spin_unlock_irqrestore (&master->hsr->seqnr_lock, irqflags); +return ; + } + + tail =skb_tail_pointer (skb) -HSR_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 (hsr->sequence_nr); + hsr->sequence_nr++; +spin_unlock_irqrestore (&master->hsr->seqnr_lock, irqflags); + +hsr_forward_skb (skb, master); +} +/* Announce (supervision frame) timer function */ static void hsr_announce (struct timer_list *t)
@@ -389,6 +442,10 @@ static struct hsr_proto_ops hsr_ops = { .send_sv_frame = send_hsr_supervision_frame, }; +struct hsr_proto_ops prp_ops = { + .send_sv_frame = send_prp_supervision_frame, +}; +void hsr_dev_setup (struct net_device *dev) {eth_hw_addr_random (dev);
@@ -452,7 +509,12 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],if (protocol_version ==PRP_V1 )return -EPROTONOSUPPORT ; - hsr->proto_ops = &hsr_ops; +/* initialize protocol specific functions */ +if (protocol_version ==PRP_V1 ) + hsr->proto_ops = &prp_ops; +else + hsr->proto_ops = &hsr_ops; +/* Make sure we recognize frames from ourselves in hsr_rcv() */ res =hsr_create_self_node (hsr, hsr_dev->dev_addr, slave[1 ]->dev_addr);
net/hsr/hsr_forward.c +3 -1
@@ -76,7 +76,9 @@ static bool is_supervision_frame(struct hsr_priv *hsr, 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_sup_payload ))
net/hsr/hsr_main.h +22 -0
@@ -35,6 +35,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,
@@ -126,6 +130,24 @@ enum hsr_port_type { HSR_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_port {struct list_head port_list;struct net_device *dev;
Signature · 1 line
2.17.1
PATCH v2 7/9 net: hsr: define and use proto_ops ptrs to handle hsr specific frames
In reply to Murali KaricheriAs a preparatory patch to introduce PRP, refactor the code specific to handling HSR frames into separate functions and call them through proto_ops function pointers.
--- net/hsr/hsr_device.c | 5 +++- net/hsr/hsr_forward.c | 63 +++++++++++++++++++++++++------------------ net/hsr/hsr_forward.h | 7 ++++- net/hsr/hsr_main.h | 8 ++++++ 4 files changed, 55 insertions(+), 28 deletions(-)
net/hsr/hsr_device.c +4 -1
@@ -440,9 +440,12 @@ static struct device_type hsr_type = {static struct hsr_proto_ops hsr_ops = { .send_sv_frame = send_hsr_supervision_frame, + .create_tagged_frame = hsr_create_tagged_frame, + .get_untagged_frame = hsr_get_untagged_frame, + .fill_frame_info = hsr_fill_frame_info, }; -struct hsr_proto_ops prp_ops = { +static struct hsr_proto_ops prp_ops = { .send_sv_frame = send_prp_supervision_frame, };
net/hsr/hsr_forward.c +37 -26
110 lines not on this page · raw message
net/hsr/hsr_forward.h +6 -1
@@ -14,5 +14,10 @@#include "hsr_main.h" void hsr_forward_skb (struct sk_buff *skb,struct hsr_port *port); - +struct sk_buff *hsr_create_tagged_frame (struct hsr_frame_info *frame, +struct hsr_port *port); +struct sk_buff *hsr_get_untagged_frame (struct hsr_frame_info *frame, +struct hsr_port *port); +void hsr_fill_frame_info (__be16 proto,struct sk_buff *skb, +struct hsr_frame_info *frame);#endif /* __HSR_FORWARD_H */
net/hsr/hsr_main.h +8 -0
@@ -162,9 +162,17 @@ enum hsr_version { PRP_V1, }; +struct hsr_frame_info ; +struct hsr_proto_ops {/* format and send supervision frame */ void (*send_sv_frame)(struct hsr_port *port,unsigned long *interval); +struct sk_buff * (*get_untagged_frame)(struct hsr_frame_info *frame, +struct hsr_port *port); +struct sk_buff * (*create_tagged_frame)(struct hsr_frame_info *frame, +struct hsr_port *port); +void (*fill_frame_info)(__be16 proto,struct sk_buff *skb, +struct hsr_frame_info *frame); };struct hsr_priv {
Signature · 1 line
2.17.1
PATCH v2 8/9 net: prp: add packet handling support
In reply to Murali KaricheriDAN-P (Dual Attached Nodes PRP) nodes are expected to receive traditional IP packets as well as PRP (Parallel Redundancy Protocol) tagged (trailer) packets. PRP trailer is 6 bytes of PRP protocol unit called RCT, Redundancy Control Trailer (RCT) similar to HSR tag. PRP network can have traditional devices such as bridges/switches or PC attached to it and should be able to communicate. Regular Ethernet devices treat the RCT as pads. This patch adds logic to format L2 frames from network stack to add a trailer (RCT) and send it as duplicates over the slave interfaces when the protocol is PRP 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. PRP device should accept frames from Singly Attached Nodes (SAN) and thus the driver mark the link where the frame came from in the node table.
--- net/hsr/hsr_device.c | 20 ++- net/hsr/hsr_forward.c | 268 ++++++++++++++++++++++++++++++++--------- net/hsr/hsr_forward.h | 7 ++ net/hsr/hsr_framereg.c | 94 ++++++++++++--- net/hsr/hsr_framereg.h | 29 ++++- net/hsr/hsr_main.h | 73 ++++++++++- net/hsr/hsr_slave.c | 24 +++- net/hsr/hsr_slave.h | 2 + 8 files changed, 429 insertions(+), 88 deletions(-)
net/hsr/hsr_device.c +14 -6
@@ -443,10 +443,17 @@ static struct hsr_proto_ops hsr_ops = { .create_tagged_frame = hsr_create_tagged_frame, .get_untagged_frame = hsr_get_untagged_frame, .fill_frame_info = hsr_fill_frame_info, + .invalid_dan_ingress_frame = hsr_invalid_dan_ingress_frame, };static struct hsr_proto_ops prp_ops = { .send_sv_frame = send_prp_supervision_frame, + .create_tagged_frame = prp_create_tagged_frame, + .get_untagged_frame = prp_get_untagged_frame, + .drop_frame = prp_drop_frame, + .fill_frame_info = prp_fill_frame_info, + .handle_san_frame = prp_handle_san_frame, + .update_san_info = prp_update_san_info, };void hsr_dev_setup (struct net_device *dev)
@@ -508,15 +515,16 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],ether_addr_copy (hsr_dev->dev_addr, slave[0 ]->dev_addr); -/* currently PRP is not supported */ -if (protocol_version ==PRP_V1 ) -return -EPROTONOSUPPORT ; -/* initialize protocol specific functions */ -if (protocol_version ==PRP_V1 ) +if (protocol_version ==PRP_V1 ) { +/* For PRP, lan_id has most significant 3 bits holding +* the net_id of PRP_LAN_ID +*/ + hsr->net_id =PRP_LAN_ID <<1 ; hsr->proto_ops = &prp_ops; -else + }else { hsr->proto_ops = &hsr_ops; + }/* Make sure we recognize frames from ourselves in hsr_rcv() */ res = hsr_create_self_node(hsr, hsr_dev->dev_addr,
net/hsr/hsr_forward.c +211 -57
401 lines not on this page · raw message
net/hsr/hsr_forward.h +7 -0
@@ -14,10 +14,17 @@#include "hsr_main.h" void hsr_forward_skb (struct sk_buff *skb,struct hsr_port *port); +struct sk_buff *prp_create_tagged_frame (struct hsr_frame_info *frame, +struct hsr_port *port);struct sk_buff *hsr_create_tagged_frame (struct hsr_frame_info *frame,struct hsr_port *port);struct sk_buff *hsr_get_untagged_frame (struct hsr_frame_info *frame,struct hsr_port *port); +struct sk_buff *prp_get_untagged_frame (struct hsr_frame_info *frame, +struct hsr_port *port); +bool prp_drop_frame (struct hsr_frame_info *frame,struct hsr_port *port); +void prp_fill_frame_info (__be16 proto,struct sk_buff *skb, +struct hsr_frame_info *frame);void hsr_fill_frame_info (__be16 proto,struct sk_buff *skb,struct hsr_frame_info *frame);#endif /* __HSR_FORWARD_H */
net/hsr/hsr_framereg.c +75 -19
168 lines not on this page · raw message
net/hsr/hsr_framereg.h +25 -4
@@ -14,12 +14,26 @@struct hsr_node ; +struct hsr_frame_info { +struct sk_buff *skb_std; +struct sk_buff *skb_hsr; +struct sk_buff *skb_prp; +struct hsr_port *port_rcv; +struct hsr_node *node_src; +u16 sequence_nr; +bool is_supervision; +bool is_vlan; +bool is_local_dest; +bool is_local_exclusive; +bool is_from_san; +}; +void hsr_del_self_node (struct hsr_priv *hsr);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); +struct hsr_node *hsr_get_node (struct hsr_port *port,struct list_head *node_db, +struct sk_buff *skb,bool is_sup, +enum hsr_port_type rx_port); +void hsr_handle_sup_frame (struct hsr_frame_info *frame);bool hsr_addr_is_self (struct hsr_priv *hsr,unsigned char *addr);void hsr_addr_subst_source (struct hsr_node *node,struct sk_buff *skb);
@@ -49,6 +63,10 @@ int hsr_get_node_data(struct hsr_priv *hsr,int *if2_age, u16 *if2_seq); +void prp_handle_san_frame (bool san,enum hsr_port_type port, +struct hsr_node *node); +void prp_update_san_info (struct hsr_node *node,bool is_sup); +struct hsr_node {struct list_head mac_list;unsigned char macaddress_A[ETH_ALEN ];
@@ -57,6 +75,9 @@ struct hsr_node {enum hsr_port_type addr_B_port;unsigned long time_in[HSR_PT_PORTS ];bool time_in_stale[HSR_PT_PORTS ]; +/* if the node is a SAN */ +bool san_a; +bool san_b;u16 seq_out[HSR_PT_PORTS ];struct rcu_head rcu_head; };
net/hsr/hsr_main.h +72 -1
119 lines not on this page · raw message
net/hsr/hsr_slave.c +23 -1
@@ -16,12 +16,22 @@#include "hsr_forward.h" #include "hsr_framereg.h" +bool hsr_invalid_dan_ingress_frame (__be16 protocol) +{ +return (protocol !=htons (ETH_P_PRP ) && protocol !=htons (ETH_P_HSR )); +} +static rx_handler_result_t hsr_handle_frame (struct sk_buff **pskb) {struct sk_buff *skb = *pskb;struct hsr_port *port; +struct hsr_priv *hsr;__be16 protocol; +/* Packets from dev_loopback_xmit() do not have L2 header, bail out */ +if (unlikely (skb->pkt_type ==PACKET_LOOPBACK )) +return RX_HANDLER_PASS ; +if (!skb_mac_header_was_set (skb)) {WARN_ONCE (1 ,"%s: skb invalid" , __func__);return RX_HANDLER_PASS ;
@@ -30,6 +40,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) port =hsr_port_get_rcu (skb->dev);if (!port) goto finish_pass; + hsr = port->hsr;if (hsr_addr_is_self (port->hsr,eth_hdr (skb)->h_source)) {/* Directly kill frames sent by ourselves */
@@ -37,12 +48,23 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) goto finish_consume; } +/* For HSR, only tagged frames are expected, but for PRP +* there could be non tagged frames as well from Single +* attached nodes (SANs). +*/ protocol =eth_hdr (skb)->h_proto; -if (protocol !=htons (ETH_P_PRP ) && protocol !=htons (ETH_P_HSR )) +if (hsr->proto_ops->invalid_dan_ingress_frame && + hsr->proto_ops->invalid_dan_ingress_frame (protocol)) goto finish_pass;skb_push (skb,ETH_HLEN ); +if (skb_mac_header (skb) != skb->data) { +WARN_ONCE (1 ,"%s:%d: Malformed frame at source port %s)\n" , + __func__, __LINE__, port->dev->name); + goto finish_consume; + } +hsr_forward_skb (skb, port); finish_consume:
net/hsr/hsr_slave.h +2 -0
@@ -32,4 +32,6 @@ static inline struct hsr_port *hsr_port_get_rcu(const struct net_device *dev) rcu_dereference(dev->rx_handler_data) : NULL; } +bool hsr_invalid_dan_ingress_frame (__be16 protocol); +#endif /* __HSR_SLAVE_H */
Signature · 1 line
2.17.1
PATCH v2 9/9 net: prp: enhance debugfs to display PRP info
In reply to Murali KaricheriPrint PRP specific information from node table as part of debugfs node table display. Also display the node as DAN-H or DAN-P depending on the info from node table.
--- net/hsr/hsr_debugfs.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
net/hsr/hsr_debugfs.c +22 -9
@@ -24,7 +24,7 @@ static struct dentry *hsr_debugfs_root_dir;static void print_mac_address (struct seq_file *sfp,unsigned char *mac) { -seq_printf (sfp,"%02x:%02x:%02x:%02x:%02x:%02x:" , +seq_printf (sfp,"%02x:%02x:%02x:%02x:%02x:%02x " , mac[0 ], mac[1 ], mac[2 ], mac[3 ], mac[4 ], mac[5 ]); }
@@ -35,20 +35,32 @@ hsr_node_table_show(struct seq_file *sfp, void *data)struct hsr_priv *priv = (struct hsr_priv *)sfp->private;struct hsr_node *node; -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_printf (sfp,"Node Table entries for (%s) device\n" , + (priv->prot_version ==PRP_V1 ?"PRP" :"HSR" )); +seq_puts (sfp,"MAC-Address-A, MAC-Address-B, time_in[A], " ); +seq_puts (sfp,"time_in[B], Address-B port, " ); +if (priv->prot_version ==PRP_V1 ) +seq_puts (sfp,"SAN-A, SAN-B, DAN-P\n" ); +else +seq_puts (sfp,"DAN-H\n" ); +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))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%x\n" , node->addr_B_port); +seq_printf (sfp,"%10lx, " , node->time_in[HSR_PT_SLAVE_A ]); +seq_printf (sfp,"%10lx, " , node->time_in[HSR_PT_SLAVE_B ]); +seq_printf (sfp,"%14x, " , node->addr_B_port); + +if (priv->prot_version ==PRP_V1 ) +seq_printf (sfp,"%5x, %5x, %5x\n" , + node->san_a, node->san_b, + (node->san_a ==0 && node->san_b ==0 )); +else +seq_printf (sfp,"%5x\n" ,1 ); }rcu_read_unlock ();return 0 ;
@@ -57,7 +69,8 @@ hsr_node_table_show(struct seq_file *sfp, void *data)/* hsr_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_node_table_open (struct inode *inode,struct file *filp)
Signature · 1 line
2.17.1
Jakub Kicinski
maintainerHi Murali,
thanks for the patches.
It seems like at least the first patch addresses a problem which exist in Linus's tree, i.e. Linux 5.8-rc.
Could you please separate bug fixes like that out to a new series addressed to the net tree, and add appropriate Fixes tags?
Hello, Jakub,
Quoted 10 lines · Jakub Kicinski
Hi Murali,
thanks for the patches.
It seems like at least the first patch addresses a problem which exist in Linus's tree, i.e. Linux 5.8-rc.
Could you please separate bug fixes like that out to a new series addressed to the net tree, and add appropriate Fixes tags?
Sure thing. I will send out the first two so that it gets merged. Spin v3 without it so that it can go to net/next.
Wondering if you would be able to test PRP?
Any other volunteers?
Thanks.
Signature · 2 lines
Murali Karicheri Texas Instruments