Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[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 # define PTL_USE_SLAB_CACHE
16 # include <linux/uio.h>
17 # include <linux/smp_lock.h>
18 # include <linux/types.h>
19 #else
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 /* Each of these structs should start with an odd number of
58  * __u32, or the compiler could add its own padding and confuse
59  * everyone.
60  *
61  * Also, "length" needs to be at offset 28 of each struct.
62  */
63 typedef struct ptl_ack {
64         ptl_size_t mlength;
65         ptl_handle_wire_t dst_wmd;
66         ptl_match_bits_t match_bits;
67         ptl_size_t length;                      /* common length (0 for acks) moving out RSN */
68 } WIRE_ATTR ptl_ack_t;
69
70 typedef struct ptl_put {
71         ptl_pt_index_t ptl_index;
72         ptl_handle_wire_t ack_wmd;
73         ptl_match_bits_t match_bits;
74         ptl_size_t length;                      /* common length moving out RSN */
75         ptl_size_t offset;
76         ptl_hdr_data_t hdr_data;
77 } WIRE_ATTR ptl_put_t;
78
79 typedef struct ptl_get {
80         ptl_pt_index_t ptl_index;
81         ptl_handle_wire_t return_wmd;
82         ptl_match_bits_t match_bits;
83         ptl_size_t length;                      /* common length (0 for gets) moving out RSN */
84         ptl_size_t src_offset;
85         ptl_size_t return_offset;               /* unused: going RSN */
86         ptl_size_t sink_length;
87 } WIRE_ATTR ptl_get_t;
88
89 typedef struct ptl_reply {
90         __u32 unused1;                          /* unused fields going RSN */
91         ptl_handle_wire_t dst_wmd;
92         ptl_size_t dst_offset;                  /* unused: going RSN */
93         __u32 unused2;
94         ptl_size_t length;                      /* common length moving out RSN */
95 } WIRE_ATTR ptl_reply_t;
96
97 typedef struct {
98         ptl_nid_t dest_nid;
99         ptl_nid_t src_nid;
100         ptl_pid_t dest_pid;
101         ptl_pid_t src_pid;
102         __u32 type; /* ptl_msg_type_t */
103         union {
104                 ptl_ack_t ack;
105                 ptl_put_t put;
106                 ptl_get_t get;
107                 ptl_reply_t reply;
108         } msg;
109 } WIRE_ATTR ptl_hdr_t;
110
111 /* All length fields in individual unions at same offset */
112 /* LASSERT for same in lib-move.c */
113 #define PTL_HDR_LENGTH(h) ((h)->msg.ack.length)
114
115 /* A HELLO message contains the portals magic number and protocol version
116  * code in the header's dest_nid, the peer's NID in the src_nid, and
117  * PTL_MSG_HELLO in the type field.  All other fields are zero (including
118  * PTL_HDR_LENGTH; i.e. no payload).
119  * This is for use by byte-stream NALs (e.g. TCP/IP) to check the peer is
120  * running the same protocol and to find out its NID, so that hosts with
121  * multiple IP interfaces can have a single NID. These NALs should exchange
122  * HELLO messages when a connection is first established. */
123 typedef struct {
124         __u32   magic;                          /* PORTALS_PROTO_MAGIC */
125         __u16   version_major;                  /* increment on incompatible change */
126         __u16   version_minor;                  /* increment on compatible change */
127 } WIRE_ATTR ptl_magicversion_t;
128
129 #define PORTALS_PROTO_MAGIC                0xeebc0ded
130
131 #define PORTALS_PROTO_VERSION_MAJOR        0
132 #define PORTALS_PROTO_VERSION_MINOR        1
133
134 typedef struct {
135         long recv_count, recv_length, send_count, send_length, drop_count,
136             drop_length, msgs_alloc, msgs_max;
137 } lib_counters_t;
138
139 /* temporary expedient: limit number of entries in discontiguous MDs */
140 #if PTL_LARGE_MTU
141 # define PTL_MD_MAX_IOV 64
142 #else
143 # define PTL_MD_MAX_IOV 16
144 #endif
145
146 struct lib_msg_t {
147         struct list_head  msg_list;
148         int               send_ack;
149         lib_md_t         *md;
150         ptl_nid_t         nid;
151         ptl_pid_t         pid;
152         ptl_event_t       ev;
153         ptl_handle_wire_t ack_wmd;
154         union {
155                 struct iovec  iov[PTL_MD_MAX_IOV];
156                 ptl_kiov_t    kiov[PTL_MD_MAX_IOV];
157         } msg_iov;
158 };
159
160 struct lib_ptl_t {
161         ptl_pt_index_t size;
162         struct list_head *tbl;
163 };
164
165 struct lib_ac_t {
166         int next_free;
167 };
168
169 typedef struct {
170         struct list_head  lh_hash_chain;
171         __u64             lh_cookie;
172 } lib_handle_t;
173
174 #define lh_entry(ptr, type, member) \
175         ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
176
177 struct lib_eq_t {
178         struct list_head  eq_list;
179         lib_handle_t      eq_lh;
180         ptl_seq_t         sequence;
181         ptl_size_t        size;
182         ptl_event_t      *base;
183         int               eq_refcount;
184         int (*event_callback) (ptl_event_t * event);
185         void             *eq_addrkey;
186 };
187
188 struct lib_me_t {
189         struct list_head  me_list;
190         lib_handle_t      me_lh;
191         ptl_process_id_t  match_id;
192         ptl_match_bits_t  match_bits, ignore_bits;
193         ptl_unlink_t      unlink;
194         lib_md_t         *md;
195 };
196
197 struct lib_md_t {
198         struct list_head  md_list;
199         lib_handle_t      md_lh;
200         lib_me_t         *me;
201         user_ptr          start;
202         ptl_size_t        offset;
203         ptl_size_t        length;
204         ptl_size_t        max_size;
205         int               threshold;
206         int               pending;
207         ptl_unlink_t      unlink;
208         unsigned int      options;
209         unsigned int      md_flags;
210         void             *user_ptr;
211         lib_eq_t         *eq;
212         void             *md_addrkey;
213         unsigned int      md_niov;                /* # frags */
214         union {
215                 struct iovec  iov[PTL_MD_MAX_IOV];
216                 ptl_kiov_t    kiov[PTL_MD_MAX_IOV];
217         } md_iov;
218 };
219
220 #define PTL_MD_FLAG_UNLINK            (1 << 0)
221 #define PTL_MD_FLAG_AUTO_UNLINKED     (1 << 1)
222
223 #ifndef PTL_USE_SLAB_CACHE
224 typedef struct
225 {
226         void              *fl_objs;             /* single contiguous array of objects */
227         int                fl_nobjs;            /* the number of them */
228         int                fl_objsize;          /* the size (including overhead) of each of them */
229         struct list_head   fl_list;             /* where they are enqueued */
230 } lib_freelist_t;
231
232 typedef struct
233 {
234         struct list_head   fo_list;             /* enqueue on fl_list */
235         void              *fo_contents;         /* aligned contents */
236 } lib_freeobj_t;
237 #endif
238
239 typedef struct {
240         /* info about peers we are trying to fail */
241         struct list_head  tp_list;             /* stash in ni.ni_test_peers */
242         ptl_nid_t         tp_nid;              /* matching nid */
243         unsigned int      tp_threshold;        /* # failures to simulate */
244 } lib_test_peer_t;
245
246 #define PTL_COOKIE_TYPE_MD    1
247 #define PTL_COOKIE_TYPE_ME    2
248 #define PTL_COOKIE_TYPE_EQ    3
249 #define PTL_COOKIE_TYPES      4
250 /* PTL_COOKIE_TYPES must be a power of 2, so the cookie type can be
251  * extracted by masking with (PTL_COOKIE_TYPES - 1) */
252
253 typedef struct {
254         int up;
255         int refcnt;
256         ptl_nid_t nid;
257         ptl_pid_t pid;
258         int num_nodes;
259         unsigned int debug;
260         lib_ptl_t tbl;
261         lib_ac_t ac;
262         lib_counters_t counters;
263
264         int               ni_lh_hash_size;      /* size of lib handle hash table */
265         struct list_head *ni_lh_hash_table;     /* all extant lib handles, this interface */
266         __u64             ni_next_object_cookie; /* cookie generator */
267         __u64             ni_interface_cookie;  /* uniquely identifies this ni in this epoch */
268         
269         struct list_head ni_test_peers;
270         
271 #ifndef PTL_USE_SLAB_CACHE
272         lib_freelist_t   ni_free_mes;
273         lib_freelist_t   ni_free_msgs;
274         lib_freelist_t   ni_free_mds;
275         lib_freelist_t   ni_free_eqs;
276 #endif
277         struct list_head ni_active_msgs;
278         struct list_head ni_active_mds;
279         struct list_head ni_active_eqs;
280 } lib_ni_t;
281
282 #endif