162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright 2011-2014 Autronica Fire and Security AS
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Author(s):
562306a36Sopenharmony_ci *	2011-2014 Arvid Brodin, arvid.brodin@alten.se
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * include file for HSR and PRP.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef __HSR_FRAMEREG_H
1162306a36Sopenharmony_ci#define __HSR_FRAMEREG_H
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include "hsr_main.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cistruct hsr_node;
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cistruct hsr_frame_info {
1862306a36Sopenharmony_ci	struct sk_buff *skb_std;
1962306a36Sopenharmony_ci	struct sk_buff *skb_hsr;
2062306a36Sopenharmony_ci	struct sk_buff *skb_prp;
2162306a36Sopenharmony_ci	struct hsr_port *port_rcv;
2262306a36Sopenharmony_ci	struct hsr_node *node_src;
2362306a36Sopenharmony_ci	u16 sequence_nr;
2462306a36Sopenharmony_ci	bool is_supervision;
2562306a36Sopenharmony_ci	bool is_vlan;
2662306a36Sopenharmony_ci	bool is_local_dest;
2762306a36Sopenharmony_ci	bool is_local_exclusive;
2862306a36Sopenharmony_ci	bool is_from_san;
2962306a36Sopenharmony_ci};
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_civoid hsr_del_self_node(struct hsr_priv *hsr);
3262306a36Sopenharmony_civoid hsr_del_nodes(struct list_head *node_db);
3362306a36Sopenharmony_cistruct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,
3462306a36Sopenharmony_ci			      struct sk_buff *skb, bool is_sup,
3562306a36Sopenharmony_ci			      enum hsr_port_type rx_port);
3662306a36Sopenharmony_civoid hsr_handle_sup_frame(struct hsr_frame_info *frame);
3762306a36Sopenharmony_cibool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr);
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_civoid hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb);
4062306a36Sopenharmony_civoid hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,
4162306a36Sopenharmony_ci			 struct hsr_port *port);
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_civoid hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,
4462306a36Sopenharmony_ci			   u16 sequence_nr);
4562306a36Sopenharmony_ciint hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node,
4662306a36Sopenharmony_ci			   u16 sequence_nr);
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_civoid hsr_prune_nodes(struct timer_list *t);
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ciint hsr_create_self_node(struct hsr_priv *hsr,
5162306a36Sopenharmony_ci			 const unsigned char addr_a[ETH_ALEN],
5262306a36Sopenharmony_ci			 const unsigned char addr_b[ETH_ALEN]);
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_civoid *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
5562306a36Sopenharmony_ci			unsigned char addr[ETH_ALEN]);
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciint hsr_get_node_data(struct hsr_priv *hsr,
5862306a36Sopenharmony_ci		      const unsigned char *addr,
5962306a36Sopenharmony_ci		      unsigned char addr_b[ETH_ALEN],
6062306a36Sopenharmony_ci		      unsigned int *addr_b_ifindex,
6162306a36Sopenharmony_ci		      int *if1_age,
6262306a36Sopenharmony_ci		      u16 *if1_seq,
6362306a36Sopenharmony_ci		      int *if2_age,
6462306a36Sopenharmony_ci		      u16 *if2_seq);
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_civoid prp_handle_san_frame(bool san, enum hsr_port_type port,
6762306a36Sopenharmony_ci			  struct hsr_node *node);
6862306a36Sopenharmony_civoid prp_update_san_info(struct hsr_node *node, bool is_sup);
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistruct hsr_node {
7162306a36Sopenharmony_ci	struct list_head	mac_list;
7262306a36Sopenharmony_ci	/* Protect R/W access to seq_out */
7362306a36Sopenharmony_ci	spinlock_t		seq_out_lock;
7462306a36Sopenharmony_ci	unsigned char		macaddress_A[ETH_ALEN];
7562306a36Sopenharmony_ci	unsigned char		macaddress_B[ETH_ALEN];
7662306a36Sopenharmony_ci	/* Local slave through which AddrB frames are received from this node */
7762306a36Sopenharmony_ci	enum hsr_port_type	addr_B_port;
7862306a36Sopenharmony_ci	unsigned long		time_in[HSR_PT_PORTS];
7962306a36Sopenharmony_ci	bool			time_in_stale[HSR_PT_PORTS];
8062306a36Sopenharmony_ci	unsigned long		time_out[HSR_PT_PORTS];
8162306a36Sopenharmony_ci	/* if the node is a SAN */
8262306a36Sopenharmony_ci	bool			san_a;
8362306a36Sopenharmony_ci	bool			san_b;
8462306a36Sopenharmony_ci	u16			seq_out[HSR_PT_PORTS];
8562306a36Sopenharmony_ci	bool			removed;
8662306a36Sopenharmony_ci	struct rcu_head		rcu_head;
8762306a36Sopenharmony_ci};
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#endif /* __HSR_FRAMEREG_H */
90