0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __HSR_PRIVATE_H
0011 #define __HSR_PRIVATE_H
0012
0013 #include <linux/netdevice.h>
0014 #include <linux/list.h>
0015 #include <linux/if_vlan.h>
0016 #include <linux/if_hsr.h>
0017
0018
0019
0020
0021
0022 #define HSR_LIFE_CHECK_INTERVAL 2000
0023 #define HSR_NODE_FORGET_TIME 60000
0024 #define HSR_ANNOUNCE_INTERVAL 100
0025 #define HSR_ENTRY_FORGET_TIME 400
0026
0027
0028
0029
0030 #define MAX_SLAVE_DIFF 3000
0031 #define HSR_SEQNR_START (USHRT_MAX - 1024)
0032 #define HSR_SUP_SEQNR_START (HSR_SEQNR_START / 2)
0033
0034
0035
0036
0037 #define PRUNE_PERIOD 3000
0038 #define HSR_TLV_EOT 0
0039 #define HSR_TLV_ANNOUNCE 22
0040 #define HSR_TLV_LIFE_CHECK 23
0041
0042 #define PRP_TLV_LIFE_CHECK_DD 20
0043
0044 #define PRP_TLV_LIFE_CHECK_DA 21
0045
0046 #define PRP_TLV_REDBOX_MAC 30
0047
0048 #define HSR_V1_SUP_LSDUSIZE 52
0049
0050 #define HSR_HSIZE_SHIFT 8
0051 #define HSR_HSIZE BIT(HSR_HSIZE_SHIFT)
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 static inline void set_hsr_tag_path(struct hsr_tag *ht, u16 path)
0065 {
0066 ht->path_and_LSDU_size =
0067 htons((ntohs(ht->path_and_LSDU_size) & 0x0FFF) | (path << 12));
0068 }
0069
0070 static inline void set_hsr_tag_LSDU_size(struct hsr_tag *ht, u16 LSDU_size)
0071 {
0072 ht->path_and_LSDU_size = htons((ntohs(ht->path_and_LSDU_size) &
0073 0xF000) | (LSDU_size & 0x0FFF));
0074 }
0075
0076 struct hsr_ethhdr {
0077 struct ethhdr ethhdr;
0078 struct hsr_tag hsr_tag;
0079 } __packed;
0080
0081 struct hsr_vlan_ethhdr {
0082 struct vlan_ethhdr vlanhdr;
0083 struct hsr_tag hsr_tag;
0084 } __packed;
0085
0086 struct hsr_sup_tlv {
0087 u8 HSR_TLV_type;
0088 u8 HSR_TLV_length;
0089 };
0090
0091
0092
0093
0094 struct hsr_sup_tag {
0095 __be16 path_and_HSR_ver;
0096 __be16 sequence_nr;
0097 struct hsr_sup_tlv tlv;
0098 } __packed;
0099
0100 struct hsr_sup_payload {
0101 unsigned char macaddress_A[ETH_ALEN];
0102 } __packed;
0103
0104 static inline void set_hsr_stag_path(struct hsr_sup_tag *hst, u16 path)
0105 {
0106 set_hsr_tag_path((struct hsr_tag *)hst, path);
0107 }
0108
0109 static inline void set_hsr_stag_HSR_ver(struct hsr_sup_tag *hst, u16 HSR_ver)
0110 {
0111 set_hsr_tag_LSDU_size((struct hsr_tag *)hst, HSR_ver);
0112 }
0113
0114 struct hsrv0_ethhdr_sp {
0115 struct ethhdr ethhdr;
0116 struct hsr_sup_tag hsr_sup;
0117 } __packed;
0118
0119 struct hsrv1_ethhdr_sp {
0120 struct ethhdr ethhdr;
0121 struct hsr_tag hsr;
0122 struct hsr_sup_tag hsr_sup;
0123 } __packed;
0124
0125 enum hsr_port_type {
0126 HSR_PT_NONE = 0,
0127 HSR_PT_SLAVE_A,
0128 HSR_PT_SLAVE_B,
0129 HSR_PT_INTERLINK,
0130 HSR_PT_MASTER,
0131 HSR_PT_PORTS,
0132 };
0133
0134
0135
0136
0137
0138
0139
0140 struct prp_rct {
0141 __be16 sequence_nr;
0142 __be16 lan_id_and_LSDU_size;
0143 __be16 PRP_suffix;
0144 } __packed;
0145
0146 static inline u16 get_prp_LSDU_size(struct prp_rct *rct)
0147 {
0148 return ntohs(rct->lan_id_and_LSDU_size) & 0x0FFF;
0149 }
0150
0151 static inline void set_prp_lan_id(struct prp_rct *rct, u16 lan_id)
0152 {
0153 rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) &
0154 0x0FFF) | (lan_id << 12));
0155 }
0156 static inline void set_prp_LSDU_size(struct prp_rct *rct, u16 LSDU_size)
0157 {
0158 rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) &
0159 0xF000) | (LSDU_size & 0x0FFF));
0160 }
0161
0162 struct hsr_port {
0163 struct list_head port_list;
0164 struct net_device *dev;
0165 struct hsr_priv *hsr;
0166 enum hsr_port_type type;
0167 };
0168
0169 struct hsr_frame_info;
0170 struct hsr_node;
0171
0172 struct hsr_proto_ops {
0173
0174 void (*send_sv_frame)(struct hsr_port *port, unsigned long *interval);
0175 void (*handle_san_frame)(bool san, enum hsr_port_type port,
0176 struct hsr_node *node);
0177 bool (*drop_frame)(struct hsr_frame_info *frame, struct hsr_port *port);
0178 struct sk_buff * (*get_untagged_frame)(struct hsr_frame_info *frame,
0179 struct hsr_port *port);
0180 struct sk_buff * (*create_tagged_frame)(struct hsr_frame_info *frame,
0181 struct hsr_port *port);
0182 int (*fill_frame_info)(__be16 proto, struct sk_buff *skb,
0183 struct hsr_frame_info *frame);
0184 bool (*invalid_dan_ingress_frame)(__be16 protocol);
0185 void (*update_san_info)(struct hsr_node *node, bool is_sup);
0186 };
0187
0188 struct hsr_priv {
0189 struct rcu_head rcu_head;
0190 struct list_head ports;
0191 struct hlist_head node_db[HSR_HSIZE];
0192 struct hlist_head self_node_db;
0193 struct timer_list announce_timer;
0194 struct timer_list prune_timer;
0195 int announce_count;
0196 u16 sequence_nr;
0197 u16 sup_sequence_nr;
0198 enum hsr_version prot_version;
0199 spinlock_t seqnr_lock;
0200 spinlock_t list_lock;
0201 struct hsr_proto_ops *proto_ops;
0202 u32 hash_buckets;
0203 u32 hash_seed;
0204 #define PRP_LAN_ID 0x5
0205
0206
0207 u8 net_id;
0208
0209
0210 unsigned char sup_multicast_addr[ETH_ALEN] __aligned(sizeof(u16));
0211
0212
0213
0214 #ifdef CONFIG_DEBUG_FS
0215 struct dentry *node_tbl_root;
0216 #endif
0217 };
0218
0219 #define hsr_for_each_port(hsr, port) \
0220 list_for_each_entry_rcu((port), &(hsr)->ports, port_list)
0221
0222 struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt);
0223
0224
0225 static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb)
0226 {
0227 struct hsr_ethhdr *hsr_ethhdr;
0228
0229 hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
0230 return ntohs(hsr_ethhdr->hsr_tag.sequence_nr);
0231 }
0232
0233 static inline struct prp_rct *skb_get_PRP_rct(struct sk_buff *skb)
0234 {
0235 unsigned char *tail = skb_tail_pointer(skb) - HSR_HLEN;
0236
0237 struct prp_rct *rct = (struct prp_rct *)tail;
0238
0239 if (rct->PRP_suffix == htons(ETH_P_PRP))
0240 return rct;
0241
0242 return NULL;
0243 }
0244
0245
0246 static inline u16 prp_get_skb_sequence_nr(struct prp_rct *rct)
0247 {
0248 return ntohs(rct->sequence_nr);
0249 }
0250
0251
0252 static inline bool prp_check_lsdu_size(struct sk_buff *skb,
0253 struct prp_rct *rct,
0254 bool is_sup)
0255 {
0256 struct ethhdr *ethhdr;
0257 int expected_lsdu_size;
0258
0259 if (is_sup) {
0260 expected_lsdu_size = HSR_V1_SUP_LSDUSIZE;
0261 } else {
0262 ethhdr = (struct ethhdr *)skb_mac_header(skb);
0263 expected_lsdu_size = skb->len - 14;
0264 if (ethhdr->h_proto == htons(ETH_P_8021Q))
0265 expected_lsdu_size -= 4;
0266 }
0267
0268 return (expected_lsdu_size == get_prp_LSDU_size(rct));
0269 }
0270
0271 #if IS_ENABLED(CONFIG_DEBUG_FS)
0272 void hsr_debugfs_rename(struct net_device *dev);
0273 void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev);
0274 void hsr_debugfs_term(struct hsr_priv *priv);
0275 void hsr_debugfs_create_root(void);
0276 void hsr_debugfs_remove_root(void);
0277 #else
0278 static inline void hsr_debugfs_rename(struct net_device *dev)
0279 {
0280 }
0281 static inline void hsr_debugfs_init(struct hsr_priv *priv,
0282 struct net_device *hsr_dev)
0283 {}
0284 static inline void hsr_debugfs_term(struct hsr_priv *priv)
0285 {}
0286 static inline void hsr_debugfs_create_root(void)
0287 {}
0288 static inline void hsr_debugfs_remove_root(void)
0289 {}
0290 #endif
0291
0292 #endif