fixed prev. ibwrapper_test options
[vlendec/samba-autobuild/.git] / ctdb / ib / ibwrapper_internal.h
1 /*
2  * Unix SMB/CIFS implementation.
3  * Wrap Infiniband calls.
4  *
5  * Copyright (C) Sven Oehme <oehmes@de.ibm.com> 2006
6  *
7  * Major code contributions by Peter Somogyi <psomogyi@gamax.hu>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 struct ibw_opts {
25         uint32_t        max_send_wr;
26         uint32_t        max_recv_wr;
27         uint32_t        recv_bufsize;
28         uint32_t        recv_threshold;
29 };
30
31 struct ibw_wr {
32         char    *buf; /* initialized in ibw_init_memory once per connection */
33         int     wr_id; /* position in wr_index list; also used as wr id */
34
35         char    *buf_large; /* allocated specially for "large" message */
36         struct ibv_mr *mr_large;
37         int     ref_cnt; /* reference count for ibw_wc_send to know when to release */
38
39         char    *queued_msg; /* set at ibw_send - can be different than above */
40         int     queued_ref_cnt; /* instead of adding the same to the queue again */
41         uint32_t        queued_rlen; /* last wins when queued_ref_cnt>0; or simple msg size */
42
43         struct ibw_wr *next, *prev; /* in wr_list_avail or wr_list_used */
44                                 /* or extra_sent or extra_avail */
45         struct ibw_wr *qnext, *qprev; /* in queue */
46 };
47
48 struct ibw_ctx_priv {
49         struct event_context *ectx;
50
51         struct ibw_opts opts;
52
53         struct rdma_cm_id       *cm_id; /* server cm id */
54
55         struct rdma_event_channel *cm_channel;
56         struct fd_event *cm_channel_event;
57
58         ibw_connstate_fn_t connstate_func; /* see ibw_init */
59         ibw_receive_fn_t receive_func; /* see ibw_init */
60
61         long    pagesize; /* sysconf result for memalign */
62 };
63
64 struct ibw_part {
65         char *buf; /* talloced memory buffer */
66         uint32_t bufsize; /* allocated size of buf - always grows */
67         uint32_t len; /* message part length */
68         uint32_t to_read; /* 4 or *((uint32_t)buf) if len>=sizeof(uint32_t) */
69 };
70
71 struct ibw_conn_priv {
72         struct ibv_comp_channel *verbs_channel;
73         struct fd_event *verbs_channel_event;
74
75         struct rdma_cm_id *cm_id; /* client's cm id */
76         struct ibv_pd   *pd;
77         int     is_accepted;
78
79         struct ibv_cq   *cq; /* qp is in cm_id */
80
81         char *buf_send; /* max_send_wr * avg_send_size */
82         struct ibv_mr *mr_send;
83         struct ibw_wr *wr_list_avail;
84         struct ibw_wr *wr_list_used;
85         struct ibw_wr **wr_index; /* array[0..(qsize-1)] of (ibw_wr *) */
86         int     wr_sent; /* # of send wrs in the CQ */
87
88         struct ibw_wr *extra_sent;
89         struct ibw_wr *extra_avail;
90         int     extra_max; /* max wr_id in the queue */
91
92         struct ibw_wr *queue;
93
94         /* buf_recv is a ring buffer */
95         char *buf_recv; /* max_recv_wr * avg_recv_size */
96         struct ibv_mr *mr_recv;
97         int recv_index; /* index of the next recv buffer when refilling */
98         struct ibw_part part;
99 };
100
101 /* remove an element from a list - element doesn't have to be in list. */
102 #define DLIST_REMOVE2(list, p, prev, next) \
103 do { \
104         if ((p) == (list)) { \
105                 (list) = (p)->next; \
106                 if (list) (list)->prev = NULL; \
107         } else { \
108                 if ((p)->prev) (p)->prev->next = (p)->next; \
109                 if ((p)->next) (p)->next->prev = (p)->prev; \
110         } \
111         if ((p) != (list)) (p)->next = (p)->prev = NULL; \
112 } while (0)
113
114 /* hook into the end of the list - needs a tmp pointer */
115 #define DLIST_ADD_END2(list, p, type, prev, next) \
116 do { \
117                 if (!(list)) { \
118                         (list) = (p); \
119                         (p)->next = (p)->prev = NULL; \
120                 } else { \
121                         type tmp; \
122                         for (tmp = (list); tmp->next; tmp = tmp->next) ; \
123                         tmp->next = (p); \
124                         (p)->next = NULL; \
125                         (p)->prev = tmp; \
126                 } \
127 } while (0)