]> Pileus Git - ~andy/linux/blob - net/tipc/bearer.h
[TIPC] License header update
[~andy/linux] / net / tipc / bearer.h
1 /*
2  * net/tipc/bearer.h: Include file for TIPC bearer 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
38 #ifndef _TIPC_BEARER_H
39 #define _TIPC_BEARER_H
40
41 #include <net/tipc/tipc_bearer.h>
42 #include "bcast.h"
43
44 #define MAX_BEARERS 8
45 #define MAX_MEDIA 4
46
47
48 /**
49  * struct media - TIPC media information available to internal users
50  * @send_msg: routine which handles buffer transmission
51  * @enable_bearer: routine which enables a bearer
52  * @disable_bearer: routine which disables a bearer
53  * @addr2str: routine which converts bearer's address to string form
54  * @bcast_addr: media address used in broadcasting
55  * @bcast: non-zero if media supports broadcasting [currently mandatory]
56  * @priority: default link (and bearer) priority
57  * @tolerance: default time (in ms) before declaring link failure
58  * @window: default window (in packets) before declaring link congestion
59  * @type_id: TIPC media identifier [defined in tipc_bearer.h]
60  * @name: media name
61  */
62  
63 struct media {
64         int (*send_msg)(struct sk_buff *buf, 
65                         struct tipc_bearer *b_ptr,
66                         struct tipc_media_addr *dest);
67         int (*enable_bearer)(struct tipc_bearer *b_ptr);
68         void (*disable_bearer)(struct tipc_bearer *b_ptr);
69         char *(*addr2str)(struct tipc_media_addr *a, 
70                           char *str_buf, int str_size);
71         struct tipc_media_addr bcast_addr;
72         int bcast;
73         u32 priority;
74         u32 tolerance;
75         u32 window;
76         u32 type_id;
77         char name[TIPC_MAX_MEDIA_NAME];
78 };
79
80 /**
81  * struct bearer - TIPC bearer information available to internal users
82  * @publ: bearer information available to privileged users
83  * @media: ptr to media structure associated with bearer
84  * @priority: default link priority for bearer
85  * @detect_scope: network address mask used during automatic link creation
86  * @identity: array index of this bearer within TIPC bearer array
87  * @link_req: ptr to (optional) structure making periodic link setup requests
88  * @links: list of non-congested links associated with bearer
89  * @cong_links: list of congested links associated with bearer
90  * @continue_count: # of times bearer has resumed after congestion or blocking
91  * @active: non-zero if bearer structure is represents a bearer
92  * @net_plane: network plane ('A' through 'H') currently associated with bearer
93  * @nodes: indicates which nodes in cluster can be reached through bearer
94  */
95  
96 struct bearer {
97         struct tipc_bearer publ;
98         struct media *media;
99         u32 priority;
100         u32 detect_scope;
101         u32 identity;
102         struct link_req *link_req;
103         struct list_head links;
104         struct list_head cong_links;
105         u32 continue_count;
106         int active;
107         char net_plane;
108         struct node_map nodes;
109 };
110
111 struct bearer_name {
112         char media_name[TIPC_MAX_MEDIA_NAME];
113         char if_name[TIPC_MAX_IF_NAME];
114 };
115
116 struct link;
117
118 extern struct bearer *bearers;
119
120 void media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a);
121 struct sk_buff *media_get_names(void);
122
123 struct sk_buff *bearer_get_names(void);
124 void bearer_add_dest(struct bearer *b_ptr, u32 dest);
125 void bearer_remove_dest(struct bearer *b_ptr, u32 dest);
126 void bearer_schedule(struct bearer *b_ptr, struct link *l_ptr);
127 struct bearer *bearer_find_interface(const char *if_name);
128 int bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr);
129 int bearer_init(void);
130 void bearer_stop(void);
131 int bearer_broadcast(struct sk_buff *buf, struct tipc_bearer *b_ptr,
132                      struct tipc_media_addr *dest);
133 void bearer_lock_push(struct bearer *b_ptr);
134
135
136 /**
137  * bearer_send- sends buffer to destination over bearer 
138  * 
139  * Returns true (1) if successful, or false (0) if unable to send
140  * 
141  * IMPORTANT:
142  * The media send routine must not alter the buffer being passed in
143  * as it may be needed for later retransmission!
144  * 
145  * If the media send routine returns a non-zero value (indicating that 
146  * it was unable to send the buffer), it must:
147  *   1) mark the bearer as blocked,
148  *   2) call tipc_continue() once the bearer is able to send again.
149  * Media types that are unable to meet these two critera must ensure their
150  * send routine always returns success -- even if the buffer was not sent --
151  * and let TIPC's link code deal with the undelivered message. 
152  */
153
154 static inline int bearer_send(struct bearer *b_ptr, struct sk_buff *buf,
155                               struct tipc_media_addr *dest)
156 {
157         return !b_ptr->media->send_msg(buf, &b_ptr->publ, dest);
158 }
159
160 /**
161  * bearer_congested - determines if bearer is currently congested
162  */
163
164 static inline int bearer_congested(struct bearer *b_ptr, struct link *l_ptr)
165 {
166         if (unlikely(b_ptr->publ.blocked))
167                 return 1;
168         if (likely(list_empty(&b_ptr->cong_links)))
169                 return 0;
170         return !bearer_resolve_congestion(b_ptr, l_ptr);
171 }
172
173 #endif