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