hsr_framereg.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright 2011-2014 Autronica Fire and Security AS
  3. *
  4. * Author(s):
  5. * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
  6. *
  7. * include file for HSR and PRP.
  8. */
  9. #ifndef __HSR_FRAMEREG_H
  10. #define __HSR_FRAMEREG_H
  11. #include "hsr_main.h"
  12. struct hsr_node;
  13. struct hsr_frame_info {
  14. struct sk_buff *skb_std;
  15. struct sk_buff *skb_hsr;
  16. struct sk_buff *skb_prp;
  17. struct hsr_port *port_rcv;
  18. struct hsr_node *node_src;
  19. u16 sequence_nr;
  20. bool is_supervision;
  21. bool is_proxy_supervision;
  22. bool is_vlan;
  23. bool is_local_dest;
  24. bool is_local_exclusive;
  25. bool is_from_san;
  26. };
  27. void hsr_del_self_node(struct hsr_priv *hsr);
  28. void hsr_del_nodes(struct list_head *node_db);
  29. struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,
  30. struct sk_buff *skb, bool is_sup,
  31. enum hsr_port_type rx_port);
  32. void hsr_handle_sup_frame(struct hsr_frame_info *frame);
  33. bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr);
  34. bool hsr_addr_is_redbox(struct hsr_priv *hsr, unsigned char *addr);
  35. void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb);
  36. void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,
  37. struct hsr_port *port);
  38. void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,
  39. u16 sequence_nr);
  40. int hsr_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame);
  41. void hsr_prune_nodes(struct timer_list *t);
  42. void hsr_prune_proxy_nodes(struct timer_list *t);
  43. int hsr_create_self_node(struct hsr_priv *hsr,
  44. const unsigned char addr_a[ETH_ALEN],
  45. const unsigned char addr_b[ETH_ALEN]);
  46. void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
  47. unsigned char addr[ETH_ALEN]);
  48. int hsr_get_node_data(struct hsr_priv *hsr,
  49. const unsigned char *addr,
  50. unsigned char addr_b[ETH_ALEN],
  51. unsigned int *addr_b_ifindex,
  52. int *if1_age,
  53. u16 *if1_seq,
  54. int *if2_age,
  55. u16 *if2_seq);
  56. void prp_handle_san_frame(bool san, enum hsr_port_type port,
  57. struct hsr_node *node);
  58. void prp_update_san_info(struct hsr_node *node, bool is_sup);
  59. bool hsr_is_node_in_db(struct list_head *node_db,
  60. const unsigned char addr[ETH_ALEN]);
  61. int prp_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame);
  62. #if IS_ENABLED(CONFIG_KUNIT)
  63. struct hsr_seq_block *hsr_get_seq_block(struct hsr_node *node, u16 block_idx);
  64. #endif
  65. #define HSR_SEQ_BLOCK_SHIFT 7 /* 128 bits */
  66. #define HSR_SEQ_BLOCK_SIZE (1 << HSR_SEQ_BLOCK_SHIFT)
  67. #define HSR_SEQ_BLOCK_MASK (HSR_SEQ_BLOCK_SIZE - 1)
  68. #define HSR_MAX_SEQ_BLOCKS 64
  69. #define hsr_seq_block_index(sequence_nr) ((sequence_nr) >> HSR_SEQ_BLOCK_SHIFT)
  70. #define hsr_seq_block_bit(sequence_nr) ((sequence_nr) & HSR_SEQ_BLOCK_MASK)
  71. struct hsr_seq_block {
  72. unsigned long time;
  73. u16 block_idx;
  74. /* Should be a flexible array member of what DECLARE_BITMAP() would
  75. * produce.
  76. */
  77. unsigned long seq_nrs[][BITS_TO_LONGS(HSR_SEQ_BLOCK_SIZE)];
  78. };
  79. struct hsr_node {
  80. struct list_head mac_list;
  81. /* Protect R/W access seq_blocks */
  82. spinlock_t seq_out_lock;
  83. unsigned char macaddress_A[ETH_ALEN];
  84. unsigned char macaddress_B[ETH_ALEN];
  85. /* Local slave through which AddrB frames are received from this node */
  86. enum hsr_port_type addr_B_port;
  87. unsigned long time_in[HSR_PT_PORTS];
  88. bool time_in_stale[HSR_PT_PORTS];
  89. /* if the node is a SAN */
  90. bool san_a;
  91. bool san_b;
  92. bool removed;
  93. /* Duplicate detection */
  94. struct xarray seq_blocks;
  95. void *block_buf;
  96. unsigned int next_block;
  97. unsigned int seq_port_cnt;
  98. struct rcu_head rcu_head;
  99. };
  100. static inline size_t hsr_seq_block_size(struct hsr_node *node)
  101. {
  102. WARN_ON_ONCE(node->seq_port_cnt == 0);
  103. return struct_size_t(struct hsr_seq_block, seq_nrs, node->seq_port_cnt);
  104. }
  105. #endif /* __HSR_FRAMEREG_H */