^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Copyright 2011-2014 Autronica Fire and Security AS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author(s):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * include file for HSR and PRP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef __HSR_PRIVATE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define __HSR_PRIVATE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* Time constants as specified in the HSR specification (IEC-62439-3 2010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Table 8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * All values in milliseconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define HSR_LIFE_CHECK_INTERVAL 2000 /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define HSR_NODE_FORGET_TIME 60000 /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define HSR_ANNOUNCE_INTERVAL 100 /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define HSR_ENTRY_FORGET_TIME 400 /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* By how much may slave1 and slave2 timestamps of latest received frame from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * each node differ before we notify of communication problem?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define MAX_SLAVE_DIFF 3000 /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define HSR_SEQNR_START (USHRT_MAX - 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define HSR_SUP_SEQNR_START (HSR_SEQNR_START / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* How often shall we check for broken ring and remove node entries older than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * HSR_NODE_FORGET_TIME?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define PRUNE_PERIOD 3000 /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define HSR_TLV_ANNOUNCE 22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define HSR_TLV_LIFE_CHECK 23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* PRP V1 life check for Duplicate discard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define PRP_TLV_LIFE_CHECK_DD 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* PRP V1 life check for Duplicate Accept */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define PRP_TLV_LIFE_CHECK_DA 21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* HSR Tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * h_source, h_proto = 0x88FB }, and add { path, LSDU_size, sequence Nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * encapsulated protocol } instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Field names as defined in the IEC:2010 standard for HSR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct hsr_tag {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) __be16 path_and_LSDU_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) __be16 sequence_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) __be16 encap_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define HSR_HLEN 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define HSR_V1_SUP_LSDUSIZE 52
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* The helper functions below assumes that 'path' occupies the 4 most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * significant bits of the 16-bit field shared by 'path' and 'LSDU_size' (or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * equivalently, the 4 most significant bits of HSR tag byte 14).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * This is unclear in the IEC specification; its definition of MAC addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * indicates the spec is written with the least significant bit first (to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * left). This, however, would mean that the LSDU field would be split in two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * with the path field in-between, which seems strange. I'm guessing the MAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * address definition is in error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static inline void set_hsr_tag_path(struct hsr_tag *ht, u16 path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ht->path_and_LSDU_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) htons((ntohs(ht->path_and_LSDU_size) & 0x0FFF) | (path << 12));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static inline void set_hsr_tag_LSDU_size(struct hsr_tag *ht, u16 LSDU_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ht->path_and_LSDU_size = htons((ntohs(ht->path_and_LSDU_size) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 0xF000) | (LSDU_size & 0x0FFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct hsr_ethhdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct ethhdr ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct hsr_tag hsr_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct hsr_vlan_ethhdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct vlan_ethhdr vlanhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct hsr_tag hsr_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* HSR/PRP Supervision Frame data types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Field names as defined in the IEC:2010 standard for HSR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct hsr_sup_tag {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __be16 path_and_HSR_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) __be16 sequence_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) __u8 HSR_TLV_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) __u8 HSR_TLV_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct hsr_sup_payload {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned char macaddress_A[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline void set_hsr_stag_path(struct hsr_sup_tag *hst, u16 path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) set_hsr_tag_path((struct hsr_tag *)hst, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static inline void set_hsr_stag_HSR_ver(struct hsr_sup_tag *hst, u16 HSR_ver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) set_hsr_tag_LSDU_size((struct hsr_tag *)hst, HSR_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct hsrv0_ethhdr_sp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct ethhdr ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct hsr_sup_tag hsr_sup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct hsrv1_ethhdr_sp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct ethhdr ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct hsr_tag hsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct hsr_sup_tag hsr_sup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) enum hsr_port_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) HSR_PT_NONE = 0, /* Must be 0, used by framereg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) HSR_PT_SLAVE_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) HSR_PT_SLAVE_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) HSR_PT_INTERLINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) HSR_PT_MASTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) HSR_PT_PORTS, /* This must be the last item in the enum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* PRP Redunancy Control Trailor (RCT).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * As defined in IEC-62439-4:2012, the PRP RCT is really { sequence Nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * Lan indentifier (LanId), LSDU_size and PRP_suffix = 0x88FB }.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * Field names as defined in the IEC:2012 standard for PRP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct prp_rct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) __be16 sequence_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) __be16 lan_id_and_LSDU_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __be16 PRP_suffix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static inline u16 get_prp_LSDU_size(struct prp_rct *rct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return ntohs(rct->lan_id_and_LSDU_size) & 0x0FFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline void set_prp_lan_id(struct prp_rct *rct, u16 lan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 0x0FFF) | (lan_id << 12));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline void set_prp_LSDU_size(struct prp_rct *rct, u16 LSDU_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 0xF000) | (LSDU_size & 0x0FFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct hsr_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct list_head port_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct hsr_priv *hsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) enum hsr_port_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* used by driver internally to differentiate various protocols */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) enum hsr_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) HSR_V0 = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) HSR_V1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) PRP_V1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct hsr_frame_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct hsr_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct hsr_proto_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* format and send supervision frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) void (*send_sv_frame)(struct hsr_port *port, unsigned long *interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) void (*handle_san_frame)(bool san, enum hsr_port_type port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct hsr_node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) bool (*drop_frame)(struct hsr_frame_info *frame, struct hsr_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct sk_buff * (*get_untagged_frame)(struct hsr_frame_info *frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct hsr_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct sk_buff * (*create_tagged_frame)(struct hsr_frame_info *frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct hsr_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int (*fill_frame_info)(__be16 proto, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct hsr_frame_info *frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) bool (*invalid_dan_ingress_frame)(__be16 protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) void (*update_san_info)(struct hsr_node *node, bool is_sup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct hsr_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct list_head ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct list_head node_db; /* Known HSR nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct list_head self_node_db; /* MACs of slaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct timer_list announce_timer; /* Supervision frame dispatch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct timer_list prune_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int announce_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u16 sequence_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u16 sup_sequence_nr; /* For HSRv1 separate seq_nr for supervision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) enum hsr_version prot_version; /* Indicate if HSRv0, HSRv1 or PRPv1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) spinlock_t seqnr_lock; /* locking for sequence_nr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) spinlock_t list_lock; /* locking for node list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct hsr_proto_ops *proto_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define PRP_LAN_ID 0x5 /* 0x1010 for A and 0x1011 for B. Bit 0 is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * based on SLAVE_A or SLAVE_B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) u8 net_id; /* for PRP, it occupies most significant 3 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * of lan_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) unsigned char sup_multicast_addr[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct dentry *node_tbl_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #define hsr_for_each_port(hsr, port) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) list_for_each_entry_rcu((port), &(hsr)->ports, port_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* Caller must ensure skb is a valid HSR frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct hsr_ethhdr *hsr_ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return ntohs(hsr_ethhdr->hsr_tag.sequence_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static inline struct prp_rct *skb_get_PRP_rct(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unsigned char *tail = skb_tail_pointer(skb) - HSR_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct prp_rct *rct = (struct prp_rct *)tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (rct->PRP_suffix == htons(ETH_P_PRP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return rct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* Assume caller has confirmed this skb is PRP suffixed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline u16 prp_get_skb_sequence_nr(struct prp_rct *rct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return ntohs(rct->sequence_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static inline u16 get_prp_lan_id(struct prp_rct *rct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return ntohs(rct->lan_id_and_LSDU_size) >> 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* assume there is a valid rct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static inline bool prp_check_lsdu_size(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct prp_rct *rct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) bool is_sup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct ethhdr *ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) int expected_lsdu_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (is_sup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) expected_lsdu_size = HSR_V1_SUP_LSDUSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ethhdr = (struct ethhdr *)skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) expected_lsdu_size = skb->len - 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (ethhdr->h_proto == htons(ETH_P_8021Q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) expected_lsdu_size -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return (expected_lsdu_size == get_prp_LSDU_size(rct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #if IS_ENABLED(CONFIG_DEBUG_FS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) void hsr_debugfs_rename(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) void hsr_debugfs_term(struct hsr_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) void hsr_debugfs_create_root(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) void hsr_debugfs_remove_root(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static inline void hsr_debugfs_rename(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static inline void hsr_debugfs_init(struct hsr_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct net_device *hsr_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static inline void hsr_debugfs_term(struct hsr_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline void hsr_debugfs_create_root(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static inline void hsr_debugfs_remove_root(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #endif /* __HSR_PRIVATE_H */