Commit 65ccbbda authored by David S. Miller's avatar David S. Miller

Merge branch 'Add-PRP-driver'

Murali Karicheri says:

====================
Add PRP driver

This series is dependent on the following patches sent out to
netdev list. All (1-3) are already merged to net/master as of
sending this, but not on the net-next master branch. So need
to apply them to net-next before applying this series. v3 of
the iproute2 patches can be merged to work with this series
as there are no updates since then.

[1] https://marc.info/?l=linux-netdev&m=159526378131542&w=2
[2] https://marc.info/?l=linux-netdev&m=159499772225350&w=2
[3] https://marc.info/?l=linux-netdev&m=159499772425352&w=2

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:
  v5 : Fixed comments about Kconfig changes on Patch 1/7 against v4
       Rebased to netnext/master branch.

  v4 : fixed following vs v3
       reverse xmas tree for local variables
       check for return type in call to skb_put_padto()

  v3 : Separated bug fixes from this series and send them for immediate merge
       But for that this is same as v2.

  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
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 1775da47 795ec4f5
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
/* Generic Netlink HSR family definition /* Generic Netlink HSR family definition
*/ */
/* attributes */ /* attributes for HSR or PRP node */
enum { enum {
HSR_A_UNSPEC, HSR_A_UNSPEC,
HSR_A_NODE_ADDR, HSR_A_NODE_ADDR,
......
...@@ -907,7 +907,14 @@ enum { ...@@ -907,7 +907,14 @@ enum {
#define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1) #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 { enum {
IFLA_HSR_UNSPEC, IFLA_HSR_UNSPEC,
...@@ -917,6 +924,9 @@ enum { ...@@ -917,6 +924,9 @@ enum {
IFLA_HSR_SUPERVISION_ADDR, /* Supervision frame multicast addr */ IFLA_HSR_SUPERVISION_ADDR, /* Supervision frame multicast addr */
IFLA_HSR_SEQ_NR, IFLA_HSR_SEQ_NR,
IFLA_HSR_VERSION, /* HSR version */ IFLA_HSR_VERSION, /* HSR version */
IFLA_HSR_PROTOCOL, /* Indicate different protocol than
* HSR. For example PRP.
*/
__IFLA_HSR_MAX, __IFLA_HSR_MAX,
}; };
......
...@@ -4,24 +4,35 @@ ...@@ -4,24 +4,35 @@
# #
config HSR config HSR
tristate "High-availability Seamless Redundancy (HSR)" tristate "High-availability Seamless Redundancy (HSR & PRP)"
help 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 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, DANH ("Doubly attached node implementing HSR") or DANP ("Doubly
your Linux box needs (at least) two physical Ethernet interfaces, attached node implementing PRP"). For this to work, your Linux box
and it must be connected as a node in a ring network together with needs (at least) two physical Ethernet interfaces.
other HSR capable nodes.
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 For DANP, it must be connected as a node connecting to two
directions on the ring (over both slave ports), giving a redundant, separate networks over the two slave interfaces. Like HSR, Ethernet
instant fail-over network. Each HSR node in the ring acts like a frames sent over the PRP device will be sent to both networks giving
bridge for HSR frames, but filters frames that have been forwarded a redundant, instant fail-over network. Unlike HSR, PRP networks
earlier. 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 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), described in IEC 62439-3:2010 (HSRv0) and IEC 62439-3:2012 (HSRv1),
but no compliancy tests have been made. Use iproute2 to select and PRP standard described in IEC 62439-4:2012 (PRP), but no
the version you desire. 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 You need to perform any and all necessary tests yourself before
relying on this code in a safety critical system! relying on this code in a safety critical system!
......
/* /*
* hsr_debugfs code * debugfs code for HSR & PRP
* Copyright (C) 2019 Texas Instruments Incorporated * Copyright (C) 2019 Texas Instruments Incorporated
* *
* Author(s): * Author(s):
...@@ -24,7 +24,7 @@ static struct dentry *hsr_debugfs_root_dir; ...@@ -24,7 +24,7 @@ static struct dentry *hsr_debugfs_root_dir;
static void print_mac_address(struct seq_file *sfp, unsigned char *mac) 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]); 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) ...@@ -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_priv *priv = (struct hsr_priv *)sfp->private;
struct hsr_node *node; struct hsr_node *node;
seq_puts(sfp, "Node Table entries\n"); seq_printf(sfp, "Node Table entries for (%s) device\n",
seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], "); (priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
seq_puts(sfp, "time_in[B], Address-B port\n"); 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(); rcu_read_lock();
list_for_each_entry_rcu(node, &priv->node_db, mac_list) { list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
/* skip self node */ /* skip self node */
if (hsr_addr_is_self(priv, node->macaddress_A)) if (hsr_addr_is_self(priv, node->macaddress_A))
continue; continue;
print_mac_address(sfp, &node->macaddress_A[0]); print_mac_address(sfp, &node->macaddress_A[0]);
seq_puts(sfp, " ");
print_mac_address(sfp, &node->macaddress_B[0]); print_mac_address(sfp, &node->macaddress_B[0]);
seq_printf(sfp, "0x%lx, ", node->time_in[HSR_PT_SLAVE_A]); seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_A]);
seq_printf(sfp, "0x%lx ", node->time_in[HSR_PT_SLAVE_B]); seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_B]);
seq_printf(sfp, "0x%x\n", node->addr_B_port); 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(); rcu_read_unlock();
return 0; return 0;
...@@ -57,7 +69,8 @@ hsr_node_table_show(struct seq_file *sfp, void *data) ...@@ -57,7 +69,8 @@ hsr_node_table_show(struct seq_file *sfp, void *data)
/* hsr_node_table_open - Open the node_table file /* hsr_node_table_open - Open the node_table file
* *
* Description: * 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 static int
hsr_node_table_open(struct inode *inode, struct file *filp) hsr_node_table_open(struct inode *inode, struct file *filp)
......
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* This file contains device methods for creating, using and destroying * This file contains device methods for creating, using and destroying
* virtual HSR devices. * virtual HSR or PRP devices.
*/ */
#include <linux/netdevice.h> #include <linux/netdevice.h>
...@@ -231,66 +230,103 @@ static const struct header_ops hsr_header_ops = { ...@@ -231,66 +230,103 @@ static const struct header_ops hsr_header_ops = {
.parse = eth_header_parse, .parse = eth_header_parse,
}; };
static void send_hsr_supervision_frame(struct hsr_port *master, static struct sk_buff *hsr_init_skb(struct hsr_port *master, u16 proto)
u8 type, u8 hsr_ver)
{ {
struct hsr_priv *hsr = master->hsr;
struct sk_buff *skb; struct sk_buff *skb;
int hlen, tlen; 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); hlen = LL_RESERVED_SPACE(master->dev);
tlen = master->dev->needed_tailroom; 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) + skb = dev_alloc_skb(sizeof(struct hsr_tag) +
sizeof(struct hsr_sup_tag) + sizeof(struct hsr_sup_tag) +
sizeof(struct hsr_sup_payload) + hlen + tlen); sizeof(struct hsr_sup_payload) + hlen + tlen);
if (!skb) if (!skb)
return; return skb;
skb_reserve(skb, hlen); skb_reserve(skb, hlen);
skb->dev = master->dev; skb->dev = master->dev;
skb->protocol = htons(hsr_ver ? ETH_P_HSR : ETH_P_PRP); skb->protocol = htons(proto);
skb->priority = TC_PRIO_CONTROL; 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,
master->hsr->sup_multicast_addr, hsr->sup_multicast_addr,
skb->dev->dev_addr, skb->len) <= 0) skb->dev->dev_addr, skb->len) <= 0)
goto out; goto out;
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
skb_reset_network_header(skb); skb_reset_network_header(skb);
skb_reset_transport_header(skb); skb_reset_transport_header(skb);
if (hsr_ver > 0) { return skb;
out:
kfree_skb(skb);
return NULL;
}
static void send_hsr_supervision_frame(struct hsr_port *master,
unsigned long *interval)
{
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, proto);
if (!skb) {
WARN_ONCE(1, "HSR: Could not send supervision frame\n");
return;
}
if (hsr->prot_version > 0) {
hsr_tag = skb_put(skb, sizeof(struct hsr_tag)); hsr_tag = skb_put(skb, sizeof(struct hsr_tag));
hsr_tag->encap_proto = htons(ETH_P_PRP); 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_V1_SUP_LSDUSIZE);
} }
hsr_stag = skb_put(skb, sizeof(struct hsr_sup_tag)); hsr_stag = skb_put(skb, sizeof(struct hsr_sup_tag));
set_hsr_stag_path(hsr_stag, (hsr_ver ? 0x0 : 0xf)); set_hsr_stag_path(hsr_stag, (hsr->prot_version ? 0x0 : 0xf));
set_hsr_stag_HSR_ver(hsr_stag, hsr_ver); set_hsr_stag_HSR_ver(hsr_stag, hsr->prot_version);
/* From HSRv1 on we have separate supervision sequence numbers. */ /* From HSRv1 on we have separate supervision sequence numbers. */
spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags); spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags);
if (hsr_ver > 0) { if (hsr->prot_version > 0) {
hsr_stag->sequence_nr = htons(master->hsr->sup_sequence_nr); hsr_stag->sequence_nr = htons(hsr->sup_sequence_nr);
hsr_tag->sequence_nr = htons(master->hsr->sequence_nr); hsr->sup_sequence_nr++;
master->hsr->sup_sequence_nr++; hsr_tag->sequence_nr = htons(hsr->sequence_nr);
master->hsr->sequence_nr++; hsr->sequence_nr++;
} else { } else {
hsr_stag->sequence_nr = htons(master->hsr->sequence_nr); hsr_stag->sequence_nr = htons(hsr->sequence_nr);
master->hsr->sequence_nr++; hsr->sequence_nr++;
} }
spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags); spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
hsr_stag->HSR_TLV_type = type; hsr_stag->HSR_TLV_type = type;
/* TODO: Why 12 in HSRv0? */ /* TODO: Why 12 in HSRv0? */
hsr_stag->HSR_TLV_length = hsr_stag->HSR_TLV_length = hsr->prot_version ?
hsr_ver ? sizeof(struct hsr_sup_payload) : 12; sizeof(struct hsr_sup_payload) : 12;
/* Payload: MacAddressA */ /* Payload: MacAddressA */
hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload)); hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload));
...@@ -300,11 +336,57 @@ static void send_hsr_supervision_frame(struct hsr_port *master, ...@@ -300,11 +336,57 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
return; return;
hsr_forward_skb(skb, master); hsr_forward_skb(skb, master);
return; return;
}
out: static void send_prp_supervision_frame(struct hsr_port *master,
WARN_ONCE(1, "HSR: Could not send supervision frame\n"); unsigned long *interval)
kfree_skb(skb); {
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 /* Announce (supervision frame) timer function
...@@ -319,19 +401,7 @@ static void hsr_announce(struct timer_list *t) ...@@ -319,19 +401,7 @@ static void hsr_announce(struct timer_list *t)
rcu_read_lock(); rcu_read_lock();
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
hsr->proto_ops->send_sv_frame(master, &interval);
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);
}
if (is_admin_up(master->dev)) if (is_admin_up(master->dev))
mod_timer(&hsr->announce_timer, jiffies + interval); mod_timer(&hsr->announce_timer, jiffies + interval);
...@@ -368,6 +438,24 @@ static struct device_type hsr_type = { ...@@ -368,6 +438,24 @@ static struct device_type hsr_type = {
.name = "hsr", .name = "hsr",
}; };
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,
.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) void hsr_dev_setup(struct net_device *dev)
{ {
eth_hw_addr_random(dev); eth_hw_addr_random(dev);
...@@ -427,6 +515,17 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], ...@@ -427,6 +515,17 @@ 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); ether_addr_copy(hsr_dev->dev_addr, slave[0]->dev_addr);
/* initialize protocol specific functions */
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 {
hsr->proto_ops = &hsr_ops;
}
/* Make sure we recognize frames from ourselves in hsr_rcv() */ /* 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(hsr, hsr_dev->dev_addr,
slave[1]->dev_addr); slave[1]->dev_addr);
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* include file for HSR and PRP.
*/ */
#ifndef __HSR_DEVICE_H #ifndef __HSR_DEVICE_H
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* Frame router for HSR and PRP.
*/ */
#include "hsr_forward.h" #include "hsr_forward.h"
...@@ -15,18 +17,6 @@ ...@@ -15,18 +17,6 @@
struct hsr_node; struct hsr_node;
struct hsr_frame_info {
struct sk_buff *skb_std;
struct sk_buff *skb_hsr;
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;
};
/* The uses I can see for these HSR supervision frames are: /* The uses I can see for these HSR supervision frames are:
* 1) Use the frames that are sent after node initialization ("HSR_TLV.Type = * 1) Use the frames that are sent after node initialization ("HSR_TLV.Type =
* 22") to reset any sequence_nr counters belonging to that node. Useful if * 22") to reset any sequence_nr counters belonging to that node. Useful if
...@@ -74,7 +64,9 @@ static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb) ...@@ -74,7 +64,9 @@ static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb)
} }
if (hsr_sup_tag->HSR_TLV_type != HSR_TLV_ANNOUNCE && 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; return false;
if (hsr_sup_tag->HSR_TLV_length != 12 && 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_sup_payload))
...@@ -83,8 +75,8 @@ static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb) ...@@ -83,8 +75,8 @@ static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb)
return true; return true;
} }
static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, static struct sk_buff *create_stripped_skb_hsr(struct sk_buff *skb_in,
struct hsr_frame_info *frame) struct hsr_frame_info *frame)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int copylen; int copylen;
...@@ -112,38 +104,123 @@ static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, ...@@ -112,38 +104,123 @@ static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in,
return skb; return skb;
} }
static struct sk_buff *frame_get_stripped_skb(struct hsr_frame_info *frame, struct sk_buff *hsr_get_untagged_frame(struct hsr_frame_info *frame,
struct hsr_port *port) struct hsr_port *port)
{ {
if (!frame->skb_std) if (!frame->skb_std) {
frame->skb_std = create_stripped_skb(frame->skb_hsr, frame); if (frame->skb_hsr) {
frame->skb_std =
create_stripped_skb_hsr(frame->skb_hsr, frame);
} 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); return skb_clone(frame->skb_std, GFP_ATOMIC);
} }
struct sk_buff *prp_get_untagged_frame(struct hsr_frame_info *frame,
struct hsr_port *port)
{
if (!frame->skb_std) {
if (frame->skb_prp) {
/* trim the skb by len - HSR_HLEN to exclude RCT */
skb_trim(frame->skb_prp,
frame->skb_prp->len - HSR_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 prp_set_lan_id(struct prp_rct *trailer,
struct hsr_port *port)
{
int lane_id;
if (port->type == HSR_PT_SLAVE_A)
lane_id = 0;
else
lane_id = 1;
/* Add net_id in the upper 3 bits of lane_id */
lane_id |= port->hsr->net_id;
set_prp_lan_id(trailer, lane_id);
}
/* Tailroom for PRP rct should have been created before calling this */
static struct sk_buff *prp_fill_rct(struct sk_buff *skb,
struct hsr_frame_info *frame,
struct hsr_port *port)
{
struct prp_rct *trailer;
int min_size = ETH_ZLEN;
int lsdu_size;
if (!skb)
return skb;
if (frame->is_vlan)
min_size = VLAN_ETH_ZLEN;
if (skb_put_padto(skb, min_size))
return NULL;
trailer = (struct prp_rct *)skb_put(skb, HSR_HLEN);
lsdu_size = skb->len - 14;
if (frame->is_vlan)
lsdu_size -= 4;
prp_set_lan_id(trailer, port);
set_prp_LSDU_size(trailer, lsdu_size);
trailer->sequence_nr = htons(frame->sequence_nr);
trailer->PRP_suffix = htons(ETH_P_PRP);
return skb;
}
static void hsr_set_path_id(struct hsr_ethhdr *hsr_ethhdr,
struct hsr_port *port)
{
int path_id;
if (port->type == HSR_PT_SLAVE_A)
path_id = 0;
else
path_id = 1;
set_hsr_tag_path(&hsr_ethhdr->hsr_tag, path_id);
}
static struct sk_buff *hsr_fill_tag(struct sk_buff *skb, static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
struct hsr_frame_info *frame, struct hsr_frame_info *frame,
struct hsr_port *port, u8 proto_version) struct hsr_port *port, u8 proto_version)
{ {
struct hsr_ethhdr *hsr_ethhdr; struct hsr_ethhdr *hsr_ethhdr;
int lane_id;
int lsdu_size; int lsdu_size;
/* pad to minimum packet size which is 60 + 6 (HSR tag) */ /* pad to minimum packet size which is 60 + 6 (HSR tag) */
if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN)) if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN))
return NULL; return NULL;
if (port->type == HSR_PT_SLAVE_A)
lane_id = 0;
else
lane_id = 1;
lsdu_size = skb->len - 14; lsdu_size = skb->len - 14;
if (frame->is_vlan) if (frame->is_vlan)
lsdu_size -= 4; lsdu_size -= 4;
hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb); 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); 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.sequence_nr = htons(frame->sequence_nr);
hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto; hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto;
...@@ -153,16 +230,28 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb, ...@@ -153,16 +230,28 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
return skb; return skb;
} }
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
struct hsr_frame_info *frame, * unchanged. Otherwise, create a private frame especially tagged for 'port'.
struct hsr_port *port) */
struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
struct hsr_port *port)
{ {
int movelen;
unsigned char *dst, *src; unsigned char *dst, *src;
struct sk_buff *skb; struct sk_buff *skb;
int movelen;
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);
}
/* Create the new skb with enough headroom to fit the HSR tag */ /* 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(frame->skb_std,
skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC);
if (!skb) if (!skb)
return NULL; return NULL;
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
...@@ -185,21 +274,29 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o, ...@@ -185,21 +274,29 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o,
return hsr_fill_tag(skb, frame, port, port->hsr->prot_version); return hsr_fill_tag(skb, frame, port, port->hsr->prot_version);
} }
/* If the original frame was an HSR tagged frame, just clone it to be sent struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
* unchanged. Otherwise, create a private frame especially tagged for 'port'. struct hsr_port *port)
*/
static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame,
struct hsr_port *port)
{ {
if (frame->skb_hsr) struct sk_buff *skb;
return skb_clone(frame->skb_hsr, GFP_ATOMIC);
if (port->type != HSR_PT_SLAVE_A && port->type != HSR_PT_SLAVE_B) { if (frame->skb_prp) {
WARN_ONCE(1, "HSR: Bug: trying to create a tagged frame for a non-ring port"); struct prp_rct *trailer = skb_get_PRP_rct(frame->skb_prp);
return NULL;
if (trailer) {
prp_set_lan_id(trailer, port);
} else {
WARN_ONCE(!trailer, "errored PRP skb");
return NULL;
}
return skb_clone(frame->skb_prp, GFP_ATOMIC);
} }
return create_tagged_skb(frame->skb_std, frame, port); skb = skb_copy_expand(frame->skb_std, 0,
skb_tailroom(frame->skb_std) + HSR_HLEN,
GFP_ATOMIC);
prp_fill_rct(skb, frame, port);
return skb;
} }
static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
...@@ -236,9 +333,18 @@ static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port, ...@@ -236,9 +333,18 @@ static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
return dev_queue_xmit(skb); return dev_queue_xmit(skb);
} }
bool prp_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port)
{
return ((frame->port_rcv->type == HSR_PT_SLAVE_A &&
port->type == HSR_PT_SLAVE_B) ||
(frame->port_rcv->type == HSR_PT_SLAVE_B &&
port->type == HSR_PT_SLAVE_A));
}
/* Forward the frame through all devices except: /* Forward the frame through all devices except:
* - Back through the receiving device * - Back through the receiving device
* - If it's a HSR frame: through a device where it has passed before * - 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 * - To the local HSR master only if the frame is directly addressed to it, or
* a non-supervision multicast or broadcast frame. * a non-supervision multicast or broadcast frame.
* *
...@@ -253,6 +359,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame) ...@@ -253,6 +359,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
struct sk_buff *skb; struct sk_buff *skb;
hsr_for_each_port(frame->port_rcv->hsr, port) { hsr_for_each_port(frame->port_rcv->hsr, port) {
struct hsr_priv *hsr = port->hsr;
/* Don't send frame back the way it came */ /* Don't send frame back the way it came */
if (port == frame->port_rcv) if (port == frame->port_rcv)
continue; continue;
...@@ -265,24 +372,33 @@ static void hsr_forward_do(struct hsr_frame_info *frame) ...@@ -265,24 +372,33 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
if (port->type != HSR_PT_MASTER && frame->is_local_exclusive) if (port->type != HSR_PT_MASTER && frame->is_local_exclusive)
continue; continue;
/* Don't send frame over port where it has been sent before */ /* Don't send frame over port where it has been sent before.
if (hsr_register_frame_out(port, frame->node_src, * Also fro SAN, this shouldn't be done.
*/
if (!frame->is_from_san &&
hsr_register_frame_out(port, frame->node_src,
frame->sequence_nr)) frame->sequence_nr))
continue; continue;
if (frame->is_supervision && port->type == HSR_PT_MASTER) { if (frame->is_supervision && port->type == HSR_PT_MASTER) {
hsr_handle_sup_frame(frame->skb_hsr, hsr_handle_sup_frame(frame);
frame->node_src,
frame->port_rcv);
continue; continue;
} }
/* Check if frame is to be dropped. Eg. for PRP no forward
* between ports.
*/
if (hsr->proto_ops->drop_frame &&
hsr->proto_ops->drop_frame(frame, port))
continue;
if (port->type != HSR_PT_MASTER) if (port->type != HSR_PT_MASTER)
skb = frame_get_tagged_skb(frame, port); skb = hsr->proto_ops->create_tagged_frame(frame, port);
else else
skb = frame_get_stripped_skb(frame, port); skb = hsr->proto_ops->get_untagged_frame(frame, port);
if (!skb) { if (!skb) {
/* FIXME: Record the dropped frame? */ frame->port_rcv->dev->stats.rx_dropped++;
continue; continue;
} }
...@@ -313,40 +429,95 @@ static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb, ...@@ -313,40 +429,95 @@ static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb,
} }
} }
static int hsr_fill_frame_info(struct hsr_frame_info *frame, static void handle_std_frame(struct sk_buff *skb,
struct sk_buff *skb, struct hsr_port *port) struct hsr_frame_info *frame)
{ {
struct ethhdr *ethhdr; struct hsr_port *port = frame->port_rcv;
struct hsr_priv *hsr = port->hsr;
unsigned long irqflags; unsigned long irqflags;
frame->skb_hsr = NULL;
frame->skb_prp = NULL;
frame->skb_std = skb;
if (port->type != HSR_PT_MASTER) {
frame->is_from_san = true;
} else {
/* Sequence nr for the master node */
spin_lock_irqsave(&hsr->seqnr_lock, irqflags);
frame->sequence_nr = hsr->sequence_nr;
hsr->sequence_nr++;
spin_unlock_irqrestore(&hsr->seqnr_lock, irqflags);
}
}
void hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
struct hsr_frame_info *frame)
{
if (proto == htons(ETH_P_PRP) ||
proto == htons(ETH_P_HSR)) {
/* HSR tagged frame :- Data or Supervision */
frame->skb_std = NULL;
frame->skb_prp = NULL;
frame->skb_hsr = skb;
frame->sequence_nr = hsr_get_skb_sequence_nr(skb);
return;
}
/* Standard frame or PRP from master port */
handle_std_frame(skb, frame);
}
void prp_fill_frame_info(__be16 proto, struct sk_buff *skb,
struct hsr_frame_info *frame)
{
/* Supervision frame */
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);
return;
}
handle_std_frame(skb, frame);
}
static int fill_frame_info(struct hsr_frame_info *frame,
struct sk_buff *skb, struct hsr_port *port)
{
struct hsr_priv *hsr = port->hsr;
struct hsr_vlan_ethhdr *vlan_hdr;
struct ethhdr *ethhdr;
__be16 proto;
memset(frame, 0, sizeof(*frame));
frame->is_supervision = is_supervision_frame(port->hsr, skb); frame->is_supervision = is_supervision_frame(port->hsr, skb);
frame->node_src = hsr_get_node(port, skb, frame->is_supervision); frame->node_src = hsr_get_node(port, &hsr->node_db, skb,
frame->is_supervision,
port->type);
if (!frame->node_src) if (!frame->node_src)
return -1; /* Unknown node and !is_supervision, or no mem */ return -1; /* Unknown node and !is_supervision, or no mem */
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = (struct ethhdr *)skb_mac_header(skb);
frame->is_vlan = false; 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; frame->is_vlan = true;
if (frame->is_vlan) {
vlan_hdr = (struct hsr_vlan_ethhdr *)ethhdr;
proto = vlan_hdr->vlanhdr.h_vlan_encapsulated_proto;
/* FIXME: */ /* FIXME: */
netdev_warn_once(skb->dev, "VLAN not yet supported"); netdev_warn_once(skb->dev, "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);
} else {
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);
}
frame->is_from_san = false;
frame->port_rcv = port; frame->port_rcv = port;
hsr->proto_ops->fill_frame_info(proto, skb, frame);
check_local_dest(port->hsr, skb, frame); check_local_dest(port->hsr, skb, frame);
return 0; return 0;
...@@ -363,8 +534,9 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) ...@@ -363,8 +534,9 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
goto out_drop; goto out_drop;
} }
if (hsr_fill_frame_info(&frame, skb, port) < 0) if (fill_frame_info(&frame, skb, port) < 0)
goto out_drop; goto out_drop;
hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
hsr_forward_do(&frame); hsr_forward_do(&frame);
/* Gets called for ingress frames as well as egress from master port. /* Gets called for ingress frames as well as egress from master port.
...@@ -376,6 +548,7 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) ...@@ -376,6 +548,7 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
} }
kfree_skb(frame.skb_hsr); kfree_skb(frame.skb_hsr);
kfree_skb(frame.skb_prp);
kfree_skb(frame.skb_std); kfree_skb(frame.skb_std);
return; return;
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* include file for HSR and PRP.
*/ */
#ifndef __HSR_FORWARD_H #ifndef __HSR_FORWARD_H
...@@ -12,5 +14,17 @@ ...@@ -12,5 +14,17 @@
#include "hsr_main.h" #include "hsr_main.h"
void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port); 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 */ #endif /* __HSR_FORWARD_H */
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* interface. A frame is identified by its source MAC address and its HSR * 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 * sequence number. This code keeps track of senders and their sequence numbers
* to allow filtering of duplicate frames, and to detect HSR ring errors. * 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> #include <linux/if_ether.h>
...@@ -126,6 +127,19 @@ void hsr_del_nodes(struct list_head *node_db) ...@@ -126,6 +127,19 @@ void hsr_del_nodes(struct list_head *node_db)
kfree(node); kfree(node);
} }
void prp_handle_san_frame(bool san, enum hsr_port_type port,
struct hsr_node *node)
{
/* Mark if the SAN node is over LAN_A or LAN_B */
if (port == HSR_PT_SLAVE_A) {
node->san_a = true;
return;
}
if (port == HSR_PT_SLAVE_B)
node->san_b = true;
}
/* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A; /* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A;
* seq_out is used to initialize filtering of outgoing duplicate frames * seq_out is used to initialize filtering of outgoing duplicate frames
* originating from the newly added node. * originating from the newly added node.
...@@ -133,7 +147,8 @@ void hsr_del_nodes(struct list_head *node_db) ...@@ -133,7 +147,8 @@ void hsr_del_nodes(struct list_head *node_db)
static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,
struct list_head *node_db, struct list_head *node_db,
unsigned char addr[], unsigned char addr[],
u16 seq_out) u16 seq_out, bool san,
enum hsr_port_type rx_port)
{ {
struct hsr_node *new_node, *node; struct hsr_node *new_node, *node;
unsigned long now; unsigned long now;
...@@ -154,6 +169,9 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, ...@@ -154,6 +169,9 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,
for (i = 0; i < HSR_PT_PORTS; i++) for (i = 0; i < HSR_PT_PORTS; i++)
new_node->seq_out[i] = seq_out; new_node->seq_out[i] = seq_out;
if (san && hsr->proto_ops->handle_san_frame)
hsr->proto_ops->handle_san_frame(san, rx_port, new_node);
spin_lock_bh(&hsr->list_lock); spin_lock_bh(&hsr->list_lock);
list_for_each_entry_rcu(node, node_db, mac_list, list_for_each_entry_rcu(node, node_db, mac_list,
lockdep_is_held(&hsr->list_lock)) { lockdep_is_held(&hsr->list_lock)) {
...@@ -171,15 +189,26 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, ...@@ -171,15 +189,26 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,
return node; return node;
} }
void prp_update_san_info(struct hsr_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. /* Get the hsr_node from which 'skb' was sent.
*/ */
struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,
bool is_sup) struct sk_buff *skb, bool is_sup,
enum hsr_port_type rx_port)
{ {
struct list_head *node_db = &port->hsr->node_db;
struct hsr_priv *hsr = port->hsr; struct hsr_priv *hsr = port->hsr;
struct hsr_node *node; struct hsr_node *node;
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
struct prp_rct *rct;
bool san = false;
u16 seq_out; u16 seq_out;
if (!skb_mac_header_was_set(skb)) if (!skb_mac_header_was_set(skb))
...@@ -188,14 +217,21 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, ...@@ -188,14 +217,21 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb,
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = (struct ethhdr *)skb_mac_header(skb);
list_for_each_entry_rcu(node, node_db, mac_list) { 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)) {
if (hsr->proto_ops->update_san_info)
hsr->proto_ops->update_san_info(node, is_sup);
return node; return node;
if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) }
if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) {
if (hsr->proto_ops->update_san_info)
hsr->proto_ops->update_san_info(node, is_sup);
return node; 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) || if (ethhdr->h_proto == htons(ETH_P_PRP) ||
ethhdr->h_proto == htons(ETH_P_HSR)) { ethhdr->h_proto == htons(ETH_P_HSR)) {
/* Use the existing sequence_nr from the tag as starting point /* Use the existing sequence_nr from the tag as starting point
...@@ -203,31 +239,47 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, ...@@ -203,31 +239,47 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb,
*/ */
seq_out = hsr_get_skb_sequence_nr(skb) - 1; seq_out = hsr_get_skb_sequence_nr(skb) - 1;
} else { } else {
/* this is called also for frames from master port and rct = skb_get_PRP_rct(skb);
* so warn only for non master ports if (rct && prp_check_lsdu_size(skb, rct, is_sup)) {
*/ seq_out = prp_get_skb_sequence_nr(rct);
if (port->type != HSR_PT_MASTER) } else {
WARN_ONCE(1, "%s: Non-HSR frame\n", __func__); if (rx_port != HSR_PT_MASTER)
seq_out = HSR_SEQNR_START; san = true;
seq_out = HSR_SEQNR_START;
}
} }
return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out); return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out,
san, rx_port);
} }
/* Use the Supervision frame's info about an eventual macaddress_B for merging /* 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 * nodes that has previously had their macaddress_B registered as a separate
* node. * node.
*/ */
void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, void hsr_handle_sup_frame(struct hsr_frame_info *frame)
struct hsr_port *port_rcv)
{ {
struct hsr_node *node_curr = frame->node_src;
struct hsr_port *port_rcv = frame->port_rcv;
struct hsr_priv *hsr = port_rcv->hsr; struct hsr_priv *hsr = port_rcv->hsr;
struct hsr_sup_payload *hsr_sp; struct hsr_sup_payload *hsr_sp;
struct hsr_node *node_real; struct hsr_node *node_real;
struct sk_buff *skb = NULL;
struct list_head *node_db; struct list_head *node_db;
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
int i; int i;
/* Here either frame->skb_hsr or frame->skb_prp should be
* valid as supervision frame always will have protocol
* header info.
*/
if (frame->skb_hsr)
skb = frame->skb_hsr;
else if (frame->skb_prp)
skb = frame->skb_prp;
if (!skb)
return;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = (struct ethhdr *)skb_mac_header(skb);
/* Leave the ethernet header. */ /* Leave the ethernet header. */
...@@ -248,7 +300,8 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, ...@@ -248,7 +300,8 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
if (!node_real) if (!node_real)
/* No frame received from AddrA of this node yet */ /* 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(hsr, node_db, hsr_sp->macaddress_A,
HSR_SEQNR_START - 1); HSR_SEQNR_START - 1, true,
port_rcv->type);
if (!node_real) if (!node_real)
goto done; /* No mem */ goto done; /* No mem */
if (node_real == node_curr) if (node_real == node_curr)
...@@ -274,7 +327,11 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, ...@@ -274,7 +327,11 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
kfree_rcu(node_curr, rcu_head); kfree_rcu(node_curr, rcu_head);
done: done:
skb_push(skb, sizeof(struct hsrv1_ethhdr_sp)); /* PRP uses v0 header */
if (ethhdr->h_proto == htons(ETH_P_HSR))
skb_push(skb, sizeof(struct hsrv1_ethhdr_sp));
else
skb_push(skb, sizeof(struct hsrv0_ethhdr_sp));
} }
/* 'skb' is a frame meant for this host, that is to be passed to upper layers. /* 'skb' is a frame meant for this host, that is to be passed to upper layers.
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* include file for HSR and PRP.
*/ */
#ifndef __HSR_FRAMEREG_H #ifndef __HSR_FRAMEREG_H
...@@ -12,12 +14,26 @@ ...@@ -12,12 +14,26 @@
struct hsr_node; 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_self_node(struct hsr_priv *hsr);
void hsr_del_nodes(struct list_head *node_db); void hsr_del_nodes(struct list_head *node_db);
struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,
bool is_sup); struct sk_buff *skb, bool is_sup,
void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, enum hsr_port_type rx_port);
struct hsr_port *port); void hsr_handle_sup_frame(struct hsr_frame_info *frame);
bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr); 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); void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb);
...@@ -47,6 +63,10 @@ int hsr_get_node_data(struct hsr_priv *hsr, ...@@ -47,6 +63,10 @@ int hsr_get_node_data(struct hsr_priv *hsr,
int *if2_age, int *if2_age,
u16 *if2_seq); 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 hsr_node {
struct list_head mac_list; struct list_head mac_list;
unsigned char macaddress_A[ETH_ALEN]; unsigned char macaddress_A[ETH_ALEN];
...@@ -55,6 +75,9 @@ struct hsr_node { ...@@ -55,6 +75,9 @@ struct hsr_node {
enum hsr_port_type addr_B_port; enum hsr_port_type addr_B_port;
unsigned long time_in[HSR_PT_PORTS]; unsigned long time_in[HSR_PT_PORTS];
bool time_in_stale[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]; u16 seq_out[HSR_PT_PORTS];
struct rcu_head rcu_head; struct rcu_head rcu_head;
}; };
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* Event handling for HSR and PRP devices.
*/ */
#include <linux/netdevice.h> #include <linux/netdevice.h>
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* include file for HSR and PRP.
*/ */
#ifndef __HSR_PRIVATE_H #ifndef __HSR_PRIVATE_H
...@@ -10,6 +12,7 @@ ...@@ -10,6 +12,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/if_vlan.h>
/* Time constants as specified in the HSR specification (IEC-62439-3 2010) /* Time constants as specified in the HSR specification (IEC-62439-3 2010)
* Table 8. * Table 8.
...@@ -33,6 +36,10 @@ ...@@ -33,6 +36,10 @@
#define HSR_TLV_ANNOUNCE 22 #define HSR_TLV_ANNOUNCE 22
#define HSR_TLV_LIFE_CHECK 23 #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. /* HSR Tag.
* As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB, * As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB,
...@@ -80,7 +87,12 @@ struct hsr_ethhdr { ...@@ -80,7 +87,12 @@ struct hsr_ethhdr {
struct hsr_tag hsr_tag; struct hsr_tag hsr_tag;
} __packed; } __packed;
/* HSR Supervision Frame data types. 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:2010 standard for HSR. * Field names as defined in the IEC:2010 standard for HSR.
*/ */
struct hsr_sup_tag { struct hsr_sup_tag {
...@@ -124,6 +136,34 @@ enum hsr_port_type { ...@@ -124,6 +136,34 @@ enum hsr_port_type {
HSR_PT_PORTS, /* This must be the last item in the enum */ 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 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) &
0xF000) | (LSDU_size & 0x0FFF));
}
struct hsr_port { struct hsr_port {
struct list_head port_list; struct list_head port_list;
struct net_device *dev; struct net_device *dev;
...@@ -131,6 +171,32 @@ struct hsr_port { ...@@ -131,6 +171,32 @@ struct hsr_port {
enum hsr_port_type type; 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_frame_info;
struct hsr_node;
struct hsr_proto_ops {
/* format and send supervision frame */
void (*send_sv_frame)(struct hsr_port *port, unsigned long *interval);
void (*handle_san_frame)(bool san, enum hsr_port_type port,
struct hsr_node *node);
bool (*drop_frame)(struct hsr_frame_info *frame, struct hsr_port *port);
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);
bool (*invalid_dan_ingress_frame)(__be16 protocol);
void (*update_san_info)(struct hsr_node *node, bool is_sup);
};
struct hsr_priv { struct hsr_priv {
struct rcu_head rcu_head; struct rcu_head rcu_head;
struct list_head ports; struct list_head ports;
...@@ -141,9 +207,16 @@ struct hsr_priv { ...@@ -141,9 +207,16 @@ struct hsr_priv {
int announce_count; int announce_count;
u16 sequence_nr; u16 sequence_nr;
u16 sup_sequence_nr; /* For HSRv1 separate seq_nr for supervision */ 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 seqnr_lock; /* locking for sequence_nr */
spinlock_t list_lock; /* locking for node list */ spinlock_t list_lock; /* locking for node list */
struct hsr_proto_ops *proto_ops;
#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]; unsigned char sup_multicast_addr[ETH_ALEN];
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
struct dentry *node_tbl_root; struct dentry *node_tbl_root;
...@@ -164,6 +237,49 @@ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb) ...@@ -164,6 +237,49 @@ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb)
return ntohs(hsr_ethhdr->hsr_tag.sequence_nr); 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_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_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) #if IS_ENABLED(CONFIG_DEBUG_FS)
void hsr_debugfs_rename(struct net_device *dev); void hsr_debugfs_rename(struct net_device *dev);
void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev); void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
* *
* Routines for handling Netlink messages for HSR. * Routines for handling Netlink messages for HSR and PRP.
*/ */
#include "hsr_netlink.h" #include "hsr_netlink.h"
...@@ -22,6 +22,7 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = { ...@@ -22,6 +22,7 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = {
[IFLA_HSR_VERSION] = { .type = NLA_U8 }, [IFLA_HSR_VERSION] = { .type = NLA_U8 },
[IFLA_HSR_SUPERVISION_ADDR] = { .len = ETH_ALEN }, [IFLA_HSR_SUPERVISION_ADDR] = { .len = ETH_ALEN },
[IFLA_HSR_SEQ_NR] = { .type = NLA_U16 }, [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 /* Here, it seems a netdevice has already been allocated for us, and the
...@@ -31,8 +32,10 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev, ...@@ -31,8 +32,10 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[], struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
enum hsr_version proto_version;
unsigned char multicast_spec;
u8 proto = HSR_PROTOCOL_HSR;
struct net_device *link[2]; struct net_device *link[2];
unsigned char multicast_spec, hsr_version;
if (!data) { if (!data) {
NL_SET_ERR_MSG_MOD(extack, "No slave devices specified"); 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, ...@@ -69,18 +72,34 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
else else
multicast_spec = nla_get_u8(data[IFLA_HSR_MULTICAST_SPEC]); 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]) { if (!data[IFLA_HSR_VERSION]) {
hsr_version = 0; proto_version = HSR_V0;
} else { } else {
hsr_version = nla_get_u8(data[IFLA_HSR_VERSION]); if (proto == HSR_PROTOCOL_PRP) {
if (hsr_version > 1) { 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, NL_SET_ERR_MSG_MOD(extack,
"Only versions 0..1 are supported"); "Only HSR version 0/1 supported\n");
return -EINVAL; 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) 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) ...@@ -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) static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
{ {
struct hsr_priv *hsr = netdev_priv(dev); struct hsr_priv *hsr = netdev_priv(dev);
u8 proto = HSR_PROTOCOL_HSR;
struct hsr_port *port; struct hsr_port *port;
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); 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) ...@@ -120,6 +140,10 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
hsr->sup_multicast_addr) || hsr->sup_multicast_addr) ||
nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr)) nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr))
goto nla_put_failure; 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; return 0;
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* include file for HSR and PRP.
*/ */
#ifndef __HSR_NETLINK_H #ifndef __HSR_NETLINK_H
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Author(s): * Author(s):
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* Frame handler other utility functions for HSR and PRP.
*/ */
#include "hsr_slave.h" #include "hsr_slave.h"
...@@ -14,12 +16,22 @@ ...@@ -14,12 +16,22 @@
#include "hsr_forward.h" #include "hsr_forward.h"
#include "hsr_framereg.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) static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
{ {
struct sk_buff *skb = *pskb; struct sk_buff *skb = *pskb;
struct hsr_port *port; struct hsr_port *port;
struct hsr_priv *hsr;
__be16 protocol; __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)) { if (!skb_mac_header_was_set(skb)) {
WARN_ONCE(1, "%s: skb invalid", __func__); WARN_ONCE(1, "%s: skb invalid", __func__);
return RX_HANDLER_PASS; return RX_HANDLER_PASS;
...@@ -28,6 +40,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) ...@@ -28,6 +40,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
port = hsr_port_get_rcu(skb->dev); port = hsr_port_get_rcu(skb->dev);
if (!port) if (!port)
goto finish_pass; goto finish_pass;
hsr = port->hsr;
if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) { if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) {
/* Directly kill frames sent by ourselves */ /* Directly kill frames sent by ourselves */
...@@ -35,12 +48,23 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) ...@@ -35,12 +48,23 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
goto finish_consume; 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; 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; goto finish_pass;
skb_push(skb, ETH_HLEN); 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); hsr_forward_skb(skb, port);
finish_consume: finish_consume:
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
/* Copyright 2011-2014 Autronica Fire and Security AS /* Copyright 2011-2014 Autronica Fire and Security AS
* *
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
*
* include file for HSR and PRP.
*/ */
#ifndef __HSR_SLAVE_H #ifndef __HSR_SLAVE_H
...@@ -30,4 +32,6 @@ static inline struct hsr_port *hsr_port_get_rcu(const struct net_device *dev) ...@@ -30,4 +32,6 @@ static inline struct hsr_port *hsr_port_get_rcu(const struct net_device *dev)
rcu_dereference(dev->rx_handler_data) : NULL; rcu_dereference(dev->rx_handler_data) : NULL;
} }
bool hsr_invalid_dan_ingress_frame(__be16 protocol);
#endif /* __HSR_SLAVE_H */ #endif /* __HSR_SLAVE_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment