bcast.h 5.6 KB

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