2 * Unix SMB/CIFS implementation.
3 * Wrap Infiniband calls.
5 * Copyright (C) Sven Oehme <oehmes@de.ibm.com> 2006
7 * Major code contributions by Peter Somogyi <psomogyi@gamax.hu>
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.
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.
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.
24 #include "ibwrapper.h"
30 #include <sys/types.h>
31 #include <netinet/in.h>
32 #include <sys/socket.h>
34 #include <arpa/inet.h>
36 #include <rdma/rdma_cma.h>
37 #include "lib/events/events.h"
39 #include "ibwrapper_internal.h"
42 #define IBW_LASTERR_BUFSIZE 512
43 static char ibw_lasterr[IBW_LASTERR_BUFSIZE];
45 static ibw_mr *ibw_alloc_mr(ibw_ctx_priv *pctx)
49 static int ibwctx_destruct(void *ptr)
51 ibw_ctx *pctx = talloc_get_type(ptr, ibw_ctx);
54 /* free memory regions */
59 int ibw_process_event(ibw_ctx *ctx, int fd_index);
61 static void ibw_process_cm_event(struct event_context *ev,
62 struct fd_event *fde, uint16_t flags, void *private_data)
67 static int ibw_process_init_attrs(ibw_initattr *attr, int nattr, ibw_opts *opts)
72 for(i=0; i<nattr; i++) {
74 value = attr[i].value;
76 assert(name!=NULL && value!=NULL);
77 if (strcmp(name, "dev_name")==0)
78 opts->opts.dev_name = talloc_strdup(ctx, value);
79 else if (strcmp(name, "rx_depth")==0)
80 opts->rx_depth = atoi(value);
81 else if (strcmp(name, "mtu")==0)
82 opts->mtu = atoi(value);
84 sprintf(ibw_lasterr, "ibw_init: unknown name %s\n", name);
91 ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
93 ibw_connstate_fn_t ibw_connstate,
94 ibw_receive_fn_t ibw_receive)
96 ibw_ctx *ctx = talloc_zero(NULL, ibw_ctx);
99 ibw_event_ud *event_priv;
101 memset(ibw_lasterr, 0, IBW_LASTERR_BUFSIZE);
104 ibw_lasterr[0] = '\0';
105 talloc_set_destructor(ctx, ibwctx_destruct);
106 ctx->userdata = userdata;
108 pctx = talloc_zero(ctx, ibw_ctx_priv);
109 ctx->internal = (void *)pctx;
112 pctx->connstate_func = ibw_connstate;
113 pctx->receive_func = ibw_receive;
115 assert((pctx->ectx = event_context_init(ctx))!=NULL);
117 /* process attributes */
118 if (ibw_process_init_attrs(attr, nattr, pctx->opts))
121 /* initialize CM stuff */
122 pctx->cm_channel = rdma_create_event_channel();
123 if (!pctx->cm_channel) {
125 sprintf(ibw_lasterr, "rdma_create_event_channel error %d\n", ret);
129 event_priv = talloc_zero(ctx, ibw_event_ud);
130 event_priv->ctx = ctx;
131 event_priv->id = IBWET_CM;
133 pctx->cm_channel_event = event_add_fd(pctx->ectx, pctx,
134 pctx->cm_channel->fd, EVENT_FD_READ, ibw_process_cm_event, event_priv);
136 rc = rdma_create_id(pctx->cm_channel, &pctx->cm_id, cb, RDMA_PS_TCP);
139 sprintf(ibw_lasterr, "rdma_create_id error %d\n", rc);
142 DEBUG(10, "created cm_id %p\n", pctx->cm_id);
144 /* allocate ib memory regions */
155 int ibw_stop(ibw_ctx *ctx)
157 ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
161 int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr)
163 ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
166 int ibw_listen(ibw_ctx *ctx, int backlog)
168 ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
171 int ibw_accept(ibw_ctx *ctx, void *conn_userdata)
173 ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
176 int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata)
178 ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
181 void ibw_disconnect(ibw_conn *conn)
183 ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
186 int ibw_process_event(ibw_ctx *ctx, ...)
188 ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
191 int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key, int n)
195 int ibw_send(ibw_conn *conn, void *buf, void *key, int n)
199 const char *ibw_getLastError()