bcast.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * net/tipc/bcast.h: Include file for TIPC broadcast code
  3. *
  4. * Copyright (c) 2003-2005, Ericsson Research Canada
  5. * Copyright (c) 2005, Wind River Systems
  6. * Copyright (c) 2005-2006, Ericsson AB
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef _TIPC_BCAST_H
  34. #define _TIPC_BCAST_H
  35. #define MAX_NODES 4096
  36. #define WSIZE 32
  37. /**
  38. * struct node_map - set of node identifiers
  39. * @count: # of nodes in set
  40. * @map: bitmap of node identifiers that are in the set
  41. */
  42. struct node_map {
  43. u32 count;
  44. u32 map[MAX_NODES / WSIZE];
  45. };
  46. #define PLSIZE 32
  47. /**
  48. * struct port_list - set of node local destination ports
  49. * @count: # of ports in set (only valid for first entry in list)
  50. * @next: pointer to next entry in list
  51. * @ports: array of port references
  52. */
  53. struct port_list {
  54. int count;
  55. struct port_list *next;
  56. u32 ports[PLSIZE];
  57. };
  58. struct node;
  59. extern char bc_link_name[];
  60. /**
  61. * nmap_get - determine if node exists in a node map
  62. */
  63. static inline int nmap_get(struct node_map *nm_ptr, u32 node)
  64. {
  65. int n = tipc_node(node);
  66. int w = n / WSIZE;
  67. int b = n % WSIZE;
  68. return nm_ptr->map[w] & (1 << b);
  69. }
  70. /**
  71. * nmap_add - add a node to a node map
  72. */
  73. static inline void nmap_add(struct node_map *nm_ptr, u32 node)
  74. {
  75. int n = tipc_node(node);
  76. int w = n / WSIZE;
  77. u32 mask = (1 << (n % WSIZE));
  78. if ((nm_ptr->map[w] & mask) == 0) {
  79. nm_ptr->count++;
  80. nm_ptr->map[w] |= mask;
  81. }
  82. }
  83. /**
  84. * nmap_remove - remove a node from a node map
  85. */
  86. static inline void nmap_remove(struct node_map *nm_ptr, u32 node)
  87. {
  88. int n = tipc_node(node);
  89. int w = n / WSIZE;
  90. u32 mask = (1 << (n % WSIZE));
  91. if ((nm_ptr->map[w] & mask) != 0) {
  92. nm_ptr->map[w] &= ~mask;
  93. nm_ptr->count--;
  94. }
  95. }
  96. /**
  97. * nmap_equal - test for equality of node maps
  98. */
  99. static inline int nmap_equal(struct node_map *nm_a, struct node_map *nm_b)
  100. {
  101. return !memcmp(nm_a, nm_b, sizeof(*nm_a));
  102. }
  103. /**
  104. * nmap_diff - find differences between node maps
  105. * @nm_a: input node map A
  106. * @nm_b: input node map B
  107. * @nm_diff: output node map A-B (i.e. nodes of A that are not in B)
  108. */
  109. static inline void nmap_diff(struct node_map *nm_a, struct node_map *nm_b,
  110. struct node_map *nm_diff)
  111. {
  112. int stop = sizeof(nm_a->map) / sizeof(u32);
  113. int w;
  114. int b;
  115. u32 map;
  116. memset(nm_diff, 0, sizeof(*nm_diff));
  117. for (w = 0; w < stop; w++) {
  118. map = nm_a->map[w] ^ (nm_a->map[w] & nm_b->map[w]);
  119. nm_diff->map[w] = map;
  120. if (map != 0) {
  121. for (b = 0 ; b < WSIZE; b++) {
  122. if (map & (1 << b))
  123. nm_diff->count++;
  124. }
  125. }
  126. }
  127. }
  128. /**
  129. * port_list_add - add a port to a port list, ensuring no duplicates
  130. */
  131. static inline void port_list_add(struct port_list *pl_ptr, u32 port)
  132. {
  133. struct port_list *item = pl_ptr;
  134. int i;
  135. int item_sz = PLSIZE;
  136. int cnt = pl_ptr->count;
  137. for (; ; cnt -= item_sz, item = item->next) {
  138. if (cnt < PLSIZE)
  139. item_sz = cnt;
  140. for (i = 0; i < item_sz; i++)
  141. if (item->ports[i] == port)
  142. return;
  143. if (i < PLSIZE) {
  144. item->ports[i] = port;
  145. pl_ptr->count++;
  146. return;
  147. }
  148. if (!item->next) {
  149. item->next = kmalloc(sizeof(*item), GFP_ATOMIC);
  150. if (!item->next) {
  151. warn("Memory squeeze: multicast destination port list is incomplete\n");
  152. return;
  153. }
  154. item->next->next = NULL;
  155. }
  156. }
  157. }
  158. /**
  159. * port_list_free - free dynamically created entries in port_list chain
  160. *
  161. * Note: First item is on stack, so it doesn't need to be released
  162. */
  163. static inline void port_list_free(struct port_list *pl_ptr)
  164. {
  165. struct port_list *item;
  166. struct port_list *next;
  167. for (item = pl_ptr->next; item; item = next) {
  168. next = item->next;
  169. kfree(item);
  170. }
  171. }
  172. int bclink_init(void);
  173. void bclink_stop(void);
  174. void bclink_acknowledge(struct node *n_ptr, u32 acked);
  175. int bclink_send_msg(struct sk_buff *buf);
  176. void bclink_recv_pkt(struct sk_buff *buf);
  177. u32 bclink_get_last_sent(void);
  178. u32 bclink_acks_missing(struct node *n_ptr);
  179. void bclink_check_gap(struct node *n_ptr, u32 seqno);
  180. int bclink_stats(char *stats_buf, const u32 buf_size);
  181. int bclink_reset_stats(void);
  182. int bclink_set_queue_limits(u32 limit);
  183. void bcbearer_sort(void);
  184. void bcbearer_push(void);
  185. #endif