2 * Copyright (c) 2010-2014 Intel Corporation. All rights reserved.
4 * This software is available to you under the OpenIB.org BSD license
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * - Redistributions of source code must retain the above
12 * copyright notice, this list of conditions and the following
15 * - Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 #include <rdma/rdma_cma.h>
39 #include <rdma/rdma_verbs.h>
41 static const char *server = "127.0.0.1";
42 static char port[6] = "7471";
44 static struct rdma_cm_id *id;
45 static struct ibv_mr *mr;
46 static struct rdma_addrinfo hints;
48 static uint8_t send_msg[16];
51 static int post_send(void)
53 struct ibv_send_wr wr, *bad;
57 sge.addr = (uint64_t) (uintptr_t) send_msg;
58 sge.length = (uint32_t) sizeof send_msg;
60 wr.wr_id = (uintptr_t) NULL;
64 wr.opcode = IBV_WR_SEND;
65 wr.send_flags = IBV_SEND_INLINE;
66 if (hints.ai_qp_type == IBV_QPT_XRC_SEND)
67 wr.qp_type.xrc.remote_srqn = srqn;
69 ret = ibv_post_send(id->qp, &wr, &bad);
71 perror("rdma_post_send");
78 struct rdma_addrinfo *res;
79 struct ibv_qp_init_attr attr;
83 ret = rdma_getaddrinfo(server, port, &hints, &res);
85 printf("rdma_getaddrinfo: %s\n", gai_strerror(ret));
89 memset(&attr, 0, sizeof attr);
90 attr.cap.max_send_wr = attr.cap.max_recv_wr = 1;
91 attr.cap.max_send_sge = attr.cap.max_recv_sge = 1;
93 ret = rdma_create_ep(&id, res, NULL, &attr);
94 rdma_freeaddrinfo(res);
96 perror("rdma_create_ep");
100 mr = rdma_reg_msgs(id, send_msg, sizeof send_msg);
102 perror("rdma_reg_msgs");
106 ret = rdma_connect(id, NULL);
108 perror("rdma_connect");
112 if (hints.ai_qp_type == IBV_QPT_XRC_SEND)
113 srqn = be32toh(*(__be32 *) id->event->param.conn.private_data);
121 ret = rdma_get_send_comp(id, &wc);
123 perror("rdma_get_recv_comp");
133 int main(int argc, char **argv)
137 hints.ai_port_space = RDMA_PS_TCP;
138 hints.ai_qp_type = IBV_QPT_RC;
140 while ((op = getopt(argc, argv, "s:p:c:")) != -1) {
146 strncpy(port, optarg, sizeof port - 1);
149 switch (tolower(optarg[0])) {
153 hints.ai_port_space = RDMA_PS_IB;
154 hints.ai_qp_type = IBV_QPT_XRC_SEND;
165 printf("%s: start\n", argv[0]);
167 printf("%s: end %d\n", argv[0], ret);
171 printf("usage: %s\n", argv[0]);
172 printf("\t[-s server]\n");
173 printf("\t[-p port_number]\n");
174 printf("\t[-c communication type]\n");
175 printf("\t r - RC: reliable-connected (default)\n");
176 printf("\t x - XRC: extended-reliable-connected\n");