port.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * net/tipc/port.h: Include file for TIPC port code
  3. *
  4. * Copyright (c) 1994-2007, Ericsson AB
  5. * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #ifndef _TIPC_PORT_H
  37. #define _TIPC_PORT_H
  38. #include "ref.h"
  39. #include "net.h"
  40. #include "msg.h"
  41. #include "node_subscr.h"
  42. #define TIPC_FLOW_CONTROL_WIN 512
  43. #define CONN_OVERLOAD_LIMIT ((TIPC_FLOW_CONTROL_WIN * 2 + 1) * \
  44. SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE))
  45. /**
  46. * struct user_port - TIPC user port (used with native API)
  47. * @usr_handle: user-specified field
  48. * @ref: object reference to associated TIPC port
  49. *
  50. * <various callback routines>
  51. */
  52. struct user_port {
  53. void *usr_handle;
  54. u32 ref;
  55. };
  56. /**
  57. * struct tipc_port - TIPC port structure
  58. * @usr_handle: pointer to additional user-defined information about port
  59. * @lock: pointer to spinlock for controlling access to port
  60. * @connected: non-zero if port is currently connected to a peer port
  61. * @conn_type: TIPC type used when connection was established
  62. * @conn_instance: TIPC instance used when connection was established
  63. * @conn_unacked: number of unacknowledged messages received from peer port
  64. * @published: non-zero if port has one or more associated names
  65. * @congested: non-zero if cannot send because of link or port congestion
  66. * @max_pkt: maximum packet size "hint" used when building messages sent by port
  67. * @ref: unique reference to port in TIPC object registry
  68. * @phdr: preformatted message header used when sending messages
  69. * @port_list: adjacent ports in TIPC's global list of ports
  70. * @dispatcher: ptr to routine which handles received messages
  71. * @wakeup: ptr to routine to call when port is no longer congested
  72. * @user_port: ptr to user port associated with port (if any)
  73. * @wait_list: adjacent ports in list of ports waiting on link congestion
  74. * @waiting_pkts:
  75. * @sent: # of non-empty messages sent by port
  76. * @acked: # of non-empty message acknowledgements from connected port's peer
  77. * @publications: list of publications for port
  78. * @pub_count: total # of publications port has made during its lifetime
  79. * @probing_state:
  80. * @probing_interval:
  81. * @timer_ref:
  82. * @subscription: "node down" subscription used to terminate failed connections
  83. */
  84. struct tipc_port {
  85. void *usr_handle;
  86. spinlock_t *lock;
  87. int connected;
  88. u32 conn_type;
  89. u32 conn_instance;
  90. u32 conn_unacked;
  91. int published;
  92. u32 congested;
  93. u32 max_pkt;
  94. u32 ref;
  95. struct tipc_msg phdr;
  96. struct list_head port_list;
  97. u32 (*dispatcher)(struct tipc_port *, struct sk_buff *);
  98. void (*wakeup)(struct tipc_port *);
  99. struct user_port *user_port;
  100. struct list_head wait_list;
  101. u32 waiting_pkts;
  102. u32 sent;
  103. u32 acked;
  104. struct list_head publications;
  105. u32 pub_count;
  106. u32 probing_state;
  107. u32 probing_interval;
  108. struct timer_list timer;
  109. struct tipc_node_subscr subscription;
  110. };
  111. extern spinlock_t tipc_port_list_lock;
  112. struct tipc_port_list;
  113. /*
  114. * TIPC port manipulation routines
  115. */
  116. struct tipc_port *tipc_createport_raw(void *usr_handle,
  117. u32 (*dispatcher)(struct tipc_port *, struct sk_buff *),
  118. void (*wakeup)(struct tipc_port *), const u32 importance);
  119. int tipc_reject_msg(struct sk_buff *buf, u32 err);
  120. void tipc_acknowledge(u32 port_ref, u32 ack);
  121. int tipc_deleteport(u32 portref);
  122. int tipc_portimportance(u32 portref, unsigned int *importance);
  123. int tipc_set_portimportance(u32 portref, unsigned int importance);
  124. int tipc_portunreliable(u32 portref, unsigned int *isunreliable);
  125. int tipc_set_portunreliable(u32 portref, unsigned int isunreliable);
  126. int tipc_portunreturnable(u32 portref, unsigned int *isunreturnable);
  127. int tipc_set_portunreturnable(u32 portref, unsigned int isunreturnable);
  128. int tipc_publish(u32 portref, unsigned int scope,
  129. struct tipc_name_seq const *name_seq);
  130. int tipc_withdraw(u32 portref, unsigned int scope,
  131. struct tipc_name_seq const *name_seq);
  132. int tipc_connect(u32 portref, struct tipc_portid const *port);
  133. int tipc_disconnect(u32 portref);
  134. int tipc_shutdown(u32 ref);
  135. /*
  136. * The following routines require that the port be locked on entry
  137. */
  138. int __tipc_disconnect(struct tipc_port *tp_ptr);
  139. int __tipc_connect(u32 ref, struct tipc_port *p_ptr,
  140. struct tipc_portid const *peer);
  141. int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg);
  142. /*
  143. * TIPC messaging routines
  144. */
  145. int tipc_port_recv_msg(struct sk_buff *buf);
  146. int tipc_send(u32 portref, unsigned int num_sect, struct iovec const *msg_sect,
  147. unsigned int total_len);
  148. int tipc_send2name(u32 portref, struct tipc_name const *name, u32 domain,
  149. unsigned int num_sect, struct iovec const *msg_sect,
  150. unsigned int total_len);
  151. int tipc_send2port(u32 portref, struct tipc_portid const *dest,
  152. unsigned int num_sect, struct iovec const *msg_sect,
  153. unsigned int total_len);
  154. int tipc_multicast(u32 portref, struct tipc_name_seq const *seq,
  155. unsigned int section_count, struct iovec const *msg,
  156. unsigned int total_len);
  157. int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr,
  158. struct iovec const *msg_sect, u32 num_sect,
  159. unsigned int total_len, int err);
  160. struct sk_buff *tipc_port_get_ports(void);
  161. void tipc_port_recv_proto_msg(struct sk_buff *buf);
  162. void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp);
  163. void tipc_port_reinit(void);
  164. /**
  165. * tipc_port_lock - lock port instance referred to and return its pointer
  166. */
  167. static inline struct tipc_port *tipc_port_lock(u32 ref)
  168. {
  169. return (struct tipc_port *)tipc_ref_lock(ref);
  170. }
  171. /**
  172. * tipc_port_unlock - unlock a port instance
  173. *
  174. * Can use pointer instead of tipc_ref_unlock() since port is already locked.
  175. */
  176. static inline void tipc_port_unlock(struct tipc_port *p_ptr)
  177. {
  178. spin_unlock_bh(p_ptr->lock);
  179. }
  180. static inline struct tipc_port *tipc_port_deref(u32 ref)
  181. {
  182. return (struct tipc_port *)tipc_ref_deref(ref);
  183. }
  184. static inline int tipc_port_congested(struct tipc_port *p_ptr)
  185. {
  186. return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2);
  187. }
  188. #endif