Whamcloud - gitweb
land b_eq on HEAD
[fs/lustre-release.git] / lnet / include / lnet / lib-types.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * p30/lib-types.h
5  *
6  * Types used by the library side routines that do not need to be
7  * exposed to the user application
8  */
9
10 #ifndef _LIB_TYPES_H_
11 #define _LIB_TYPES_H_
12
13 #include <portals/types.h>
14 #ifdef __KERNEL__
15 # include <linux/uio.h>
16 # include <linux/smp_lock.h>
17 # include <linux/types.h>
18 #else
19 # define PTL_USE_LIB_FREELIST
20 # include <sys/types.h>
21 #endif
22
23 /* struct nal_cb_t is defined in lib-nal.h */
24 typedef struct nal_cb_t nal_cb_t;
25
26 typedef char *user_ptr;
27 typedef struct lib_msg_t lib_msg_t;
28 typedef struct lib_ptl_t lib_ptl_t;
29 typedef struct lib_ac_t lib_ac_t;
30 typedef struct lib_me_t lib_me_t;
31 typedef struct lib_md_t lib_md_t;
32 typedef struct lib_eq_t lib_eq_t;
33
34 #define WIRE_ATTR       __attribute__((packed))
35
36 /* The wire handle's interface cookie only matches one network interface in
37  * one epoch (i.e. new cookie when the interface restarts or the node
38  * reboots).  The object cookie only matches one object on that interface
39  * during that object's lifetime (i.e. no cookie re-use). */
40 typedef struct {
41         __u64 wh_interface_cookie;
42         __u64 wh_object_cookie;
43 } WIRE_ATTR ptl_handle_wire_t;
44
45 /* byte-flip insensitive! */
46 #define PTL_WIRE_HANDLE_NONE \
47 ((const ptl_handle_wire_t) {.wh_interface_cookie = -1, .wh_object_cookie = -1})
48
49 typedef enum {
50         PTL_MSG_ACK = 0,
51         PTL_MSG_PUT,
52         PTL_MSG_GET,
53         PTL_MSG_REPLY,
54         PTL_MSG_HELLO,
55 } ptl_msg_type_t;
56
57 /* The variant fields of the portals message header are aligned on an 8
58  * byte boundary in the message header.  Note that all types used in these
59  * wire structs MUST be fixed size and the smaller types are placed at the
60  * end. */
61 typedef struct ptl_ack {
62         ptl_handle_wire_t  dst_wmd;
63         ptl_match_bits_t   match_bits;
64         ptl_size_t         mlength;
65 } WIRE_ATTR ptl_ack_t;
66
67 typedef struct ptl_put {
68         ptl_handle_wire_t  ack_wmd;
69         ptl_match_bits_t   match_bits;
70         ptl_hdr_data_t     hdr_data;
71         ptl_pt_index_t     ptl_index;
72         ptl_size_t         offset;
73 } WIRE_ATTR ptl_put_t;
74
75 typedef struct ptl_get {
76         ptl_handle_wire_t  return_wmd;
77         ptl_match_bits_t   match_bits;
78         ptl_pt_index_t     ptl_index;
79         ptl_size_t         src_offset;
80         ptl_size_t         sink_length;
81 } WIRE_ATTR ptl_get_t;
82
83 typedef struct ptl_reply {
84         ptl_handle_wire_t  dst_wmd;
85 } WIRE_ATTR ptl_reply_t;
86
87 typedef struct ptl_hello {
88         __u64              incarnation;
89         __u32              type;
90 } WIRE_ATTR ptl_hello_t;
91
92 typedef struct {
93         ptl_nid_t           dest_nid;
94         ptl_nid_t           src_nid;
95         ptl_pid_t           dest_pid;
96         ptl_pid_t           src_pid;
97         __u32               type;               /* ptl_msg_type_t */
98         __u32               payload_length;     /* payload data to follow */
99         /*<------__u64 aligned------->*/
100         union {
101                 ptl_ack_t   ack;
102                 ptl_put_t   put;
103                 ptl_get_t   get;
104                 ptl_reply_t reply;
105                 ptl_hello_t hello;
106         } msg;
107 } WIRE_ATTR ptl_hdr_t;
108
109 /* A HELLO message contains the portals magic number and protocol version
110  * code in the header's dest_nid, the peer's NID in the src_nid, and
111  * PTL_MSG_HELLO in the type field.  All other common fields are zero
112  * (including payload_size; i.e. no payload).  
113  * This is for use by byte-stream NALs (e.g. TCP/IP) to check the peer is
114  * running the same protocol and to find out its NID, so that hosts with
115  * multiple IP interfaces can have a single NID. These NALs should exchange
116  * HELLO messages when a connection is first established. 
117  * Individual NALs can put whatever else they fancy in ptl_hdr_t::msg. 
118  */
119 typedef struct {
120         __u32   magic;                          /* PORTALS_PROTO_MAGIC */
121         __u16   version_major;                  /* increment on incompatible change */
122         __u16   version_minor;                  /* increment on compatible change */
123 } WIRE_ATTR ptl_magicversion_t;
124
125 #define PORTALS_PROTO_MAGIC                0xeebc0ded
126
127 #define PORTALS_PROTO_VERSION_MAJOR        0
128 #define PORTALS_PROTO_VERSION_MINOR        3
129
130 typedef struct {
131         long recv_count, recv_length, send_count, send_length, drop_count,
132             drop_length, msgs_alloc, msgs_max;
133 } lib_counters_t;
134
135 /* temporary expedient: limit number of entries in discontiguous MDs */
136 # define PTL_MTU        (512<<10)
137 # define PTL_MD_MAX_IOV 128
138 # define PTL_MD_MAX_PAGES min_t(int, PTL_MD_MAX_IOV, PTL_MTU / PAGE_SIZE)
139
140 struct lib_msg_t {
141         struct list_head  msg_list;
142         lib_md_t         *md;
143         ptl_handle_wire_t ack_wmd;
144         ptl_event_t       ev;
145 };
146
147 struct lib_ptl_t {
148         ptl_pt_index_t size;
149         struct list_head *tbl;
150 };
151
152 struct lib_ac_t {
153         int next_free;
154 };
155
156 typedef struct {
157         struct list_head  lh_hash_chain;
158         __u64             lh_cookie;
159 } lib_handle_t;
160
161 #define lh_entry(ptr, type, member) \
162         ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
163
164 struct lib_eq_t {
165         struct list_head  eq_list;
166         lib_handle_t      eq_lh;
167         ptl_seq_t         sequence;
168         ptl_size_t        size;
169         ptl_event_t      *base;
170         int               eq_refcount;
171         int (*event_callback) (ptl_event_t * event);
172         void             *eq_addrkey;
173 };
174
175 struct lib_me_t {
176         struct list_head  me_list;
177         lib_handle_t      me_lh;
178         ptl_process_id_t  match_id;
179         ptl_match_bits_t  match_bits, ignore_bits;
180         ptl_unlink_t      unlink;
181         lib_md_t         *md;
182 };
183
184 struct lib_md_t {
185         struct list_head  md_list;
186         lib_handle_t      md_lh;
187         lib_me_t         *me;
188         user_ptr          start;
189         ptl_size_t        offset;
190         ptl_size_t        length;
191         ptl_size_t        max_size;
192         int               threshold;
193         int               pending;
194         ptl_unlink_t      unlink;
195         unsigned int      options;
196         unsigned int      md_flags;
197         void             *user_ptr;
198         lib_eq_t         *eq;
199         void             *md_addrkey;
200         unsigned int      md_niov;                /* # frags */
201         union {
202                 struct iovec  iov[PTL_MD_MAX_IOV];
203                 ptl_kiov_t    kiov[PTL_MD_MAX_IOV];
204         } md_iov;
205 };
206
207 #define PTL_MD_FLAG_UNLINK            (1 << 0)
208
209 #ifdef PTL_USE_LIB_FREELIST
210 typedef struct
211 {
212         void              *fl_objs;             /* single contiguous array of objects */
213         int                fl_nobjs;            /* the number of them */
214         int                fl_objsize;          /* the size (including overhead) of each of them */
215         struct list_head   fl_list;             /* where they are enqueued */
216 } lib_freelist_t;
217
218 typedef struct
219 {
220         struct list_head   fo_list;             /* enqueue on fl_list */
221         void              *fo_contents;         /* aligned contents */
222 } lib_freeobj_t;
223 #endif
224
225 typedef struct {
226         /* info about peers we are trying to fail */
227         struct list_head  tp_list;             /* stash in ni.ni_test_peers */
228         ptl_nid_t         tp_nid;              /* matching nid */
229         unsigned int      tp_threshold;        /* # failures to simulate */
230 } lib_test_peer_t;
231
232 #define PTL_COOKIE_TYPE_MD    1
233 #define PTL_COOKIE_TYPE_ME    2
234 #define PTL_COOKIE_TYPE_EQ    3
235 #define PTL_COOKIE_TYPES      4
236 /* PTL_COOKIE_TYPES must be a power of 2, so the cookie type can be
237  * extracted by masking with (PTL_COOKIE_TYPES - 1) */
238
239 typedef struct {
240         int up;
241         int refcnt;
242         ptl_nid_t nid;
243         ptl_pid_t pid;
244         int num_nodes;
245         unsigned int debug;
246         lib_ptl_t tbl;
247         lib_ac_t ac;
248         lib_counters_t counters;
249
250         int               ni_lh_hash_size;      /* size of lib handle hash table */
251         struct list_head *ni_lh_hash_table;     /* all extant lib handles, this interface */
252         __u64             ni_next_object_cookie; /* cookie generator */
253         __u64             ni_interface_cookie;  /* uniquely identifies this ni in this epoch */
254         
255         struct list_head ni_test_peers;
256         
257 #ifdef PTL_USE_LIB_FREELIST
258         lib_freelist_t   ni_free_mes;
259         lib_freelist_t   ni_free_msgs;
260         lib_freelist_t   ni_free_mds;
261         lib_freelist_t   ni_free_eqs;
262 #endif
263         struct list_head ni_active_msgs;
264         struct list_head ni_active_mds;
265         struct list_head ni_active_eqs;
266 } lib_ni_t;
267
268 #endif