]>
Commit | Line | Data |
---|---|---|
b97bf3fd PL |
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 | ||
34 | #ifndef _TIPC_BCAST_H | |
35 | #define _TIPC_BCAST_H | |
36 | ||
37 | #define MAX_NODES 4096 | |
38 | #define WSIZE 32 | |
39 | ||
40 | /** | |
41 | * struct node_map - set of node identifiers | |
42 | * @count: # of nodes in set | |
43 | * @map: bitmap of node identifiers that are in the set | |
44 | */ | |
45 | ||
46 | struct node_map { | |
47 | u32 count; | |
48 | u32 map[MAX_NODES / WSIZE]; | |
49 | }; | |
50 | ||
51 | ||
52 | #define PLSIZE 32 | |
53 | ||
54 | /** | |
55 | * struct port_list - set of node local destination ports | |
56 | * @count: # of ports in set (only valid for first entry in list) | |
57 | * @next: pointer to next entry in list | |
58 | * @ports: array of port references | |
59 | */ | |
60 | ||
61 | struct port_list { | |
62 | int count; | |
63 | struct port_list *next; | |
64 | u32 ports[PLSIZE]; | |
65 | }; | |
66 | ||
67 | ||
68 | struct node; | |
69 | ||
70 | extern char bc_link_name[]; | |
71 | ||
72 | ||
73 | /** | |
74 | * nmap_get - determine if node exists in a node map | |
75 | */ | |
76 | ||
77 | static inline int nmap_get(struct node_map *nm_ptr, u32 node) | |
78 | { | |
79 | int n = tipc_node(node); | |
80 | int w = n / WSIZE; | |
81 | int b = n % WSIZE; | |
82 | ||
83 | return nm_ptr->map[w] & (1 << b); | |
84 | } | |
85 | ||
86 | /** | |
87 | * nmap_add - add a node to a node map | |
88 | */ | |
89 | ||
90 | static inline void nmap_add(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 | ||
96 | if ((nm_ptr->map[w] & mask) == 0) { | |
97 | nm_ptr->count++; | |
98 | nm_ptr->map[w] |= mask; | |
99 | } | |
100 | } | |
101 | ||
102 | /** | |
103 | * nmap_remove - remove a node from a node map | |
104 | */ | |
105 | ||
106 | static inline void nmap_remove(struct node_map *nm_ptr, u32 node) | |
107 | { | |
108 | int n = tipc_node(node); | |
109 | int w = n / WSIZE; | |
110 | u32 mask = (1 << (n % WSIZE)); | |
111 | ||
112 | if ((nm_ptr->map[w] & mask) != 0) { | |
113 | nm_ptr->map[w] &= ~mask; | |
114 | nm_ptr->count--; | |
115 | } | |
116 | } | |
117 | ||
118 | /** | |
119 | * nmap_equal - test for equality of node maps | |
120 | */ | |
121 | ||
122 | static inline int nmap_equal(struct node_map *nm_a, struct node_map *nm_b) | |
123 | { | |
124 | return !memcmp(nm_a, nm_b, sizeof(*nm_a)); | |
125 | } | |
126 | ||
127 | /** | |
128 | * nmap_diff - find differences between node maps | |
129 | * @nm_a: input node map A | |
130 | * @nm_b: input node map B | |
131 | * @nm_diff: output node map A-B (i.e. nodes of A that are not in B) | |
132 | */ | |
133 | ||
134 | static inline void nmap_diff(struct node_map *nm_a, struct node_map *nm_b, | |
135 | struct node_map *nm_diff) | |
136 | { | |
137 | int stop = sizeof(nm_a->map) / sizeof(u32); | |
138 | int w; | |
139 | int b; | |
140 | u32 map; | |
141 | ||
142 | memset(nm_diff, 0, sizeof(*nm_diff)); | |
143 | for (w = 0; w < stop; w++) { | |
144 | map = nm_a->map[w] ^ (nm_a->map[w] & nm_b->map[w]); | |
145 | nm_diff->map[w] = map; | |
146 | if (map != 0) { | |
147 | for (b = 0 ; b < WSIZE; b++) { | |
148 | if (map & (1 << b)) | |
149 | nm_diff->count++; | |
150 | } | |
151 | } | |
152 | } | |
153 | } | |
154 | ||
155 | /** | |
156 | * port_list_add - add a port to a port list, ensuring no duplicates | |
157 | */ | |
158 | ||
159 | static inline void port_list_add(struct port_list *pl_ptr, u32 port) | |
160 | { | |
161 | struct port_list *item = pl_ptr; | |
162 | int i; | |
163 | int item_sz = PLSIZE; | |
164 | int cnt = pl_ptr->count; | |
165 | ||
166 | for (; ; cnt -= item_sz, item = item->next) { | |
167 | if (cnt < PLSIZE) | |
168 | item_sz = cnt; | |
169 | for (i = 0; i < item_sz; i++) | |
170 | if (item->ports[i] == port) | |
171 | return; | |
172 | if (i < PLSIZE) { | |
173 | item->ports[i] = port; | |
174 | pl_ptr->count++; | |
175 | return; | |
176 | } | |
177 | if (!item->next) { | |
178 | item->next = kmalloc(sizeof(*item), GFP_ATOMIC); | |
179 | if (!item->next) { | |
180 | warn("Memory squeeze: multicast destination port list is incomplete\n"); | |
181 | return; | |
182 | } | |
183 | item->next->next = NULL; | |
184 | } | |
185 | } | |
186 | } | |
187 | ||
188 | /** | |
189 | * port_list_free - free dynamically created entries in port_list chain | |
190 | * | |
191 | * Note: First item is on stack, so it doesn't need to be released | |
192 | */ | |
193 | ||
194 | static inline void port_list_free(struct port_list *pl_ptr) | |
195 | { | |
196 | struct port_list *item; | |
197 | struct port_list *next; | |
198 | ||
199 | for (item = pl_ptr->next; item; item = next) { | |
200 | next = item->next; | |
201 | kfree(item); | |
202 | } | |
203 | } | |
204 | ||
205 | ||
206 | int bclink_init(void); | |
207 | void bclink_stop(void); | |
208 | void bclink_acknowledge(struct node *n_ptr, u32 acked); | |
209 | int bclink_send_msg(struct sk_buff *buf); | |
210 | void bclink_recv_pkt(struct sk_buff *buf); | |
211 | u32 bclink_get_last_sent(void); | |
212 | u32 bclink_acks_missing(struct node *n_ptr); | |
213 | void bclink_check_gap(struct node *n_ptr, u32 seqno); | |
214 | int bclink_stats(char *stats_buf, const u32 buf_size); | |
215 | int bclink_reset_stats(void); | |
216 | int bclink_set_queue_limits(u32 limit); | |
217 | void bcbearer_sort(void); | |
218 | void bcbearer_push(void); | |
219 | ||
220 | #endif |