2 * Copyright (c) 2005-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 *port = "7471";
43 static struct rdma_cm_id *listen_id, *id;
44 static struct ibv_mr *mr;
45 static struct rdma_addrinfo hints;
47 static uint8_t recv_msg[16];
50 static int create_srq(void)
52 struct ibv_srq_init_attr attr;
57 attr.attr.max_sge = 1;
58 attr.attr.srq_limit = 0;
59 attr.srq_context = id;
61 ret = rdma_create_srq(id, NULL, &attr);
63 perror("rdma_create_srq:");
66 ibv_get_srq_num(id->srq, &tmp_srqn);
67 srqn = htobe32(tmp_srqn);
74 struct rdma_addrinfo *res;
75 struct ibv_qp_init_attr attr;
76 struct rdma_conn_param param;
80 ret = rdma_getaddrinfo(NULL, port, &hints, &res);
82 printf("rdma_getaddrinfo: %s\n", gai_strerror(ret));
86 memset(&attr, 0, sizeof attr);
87 attr.cap.max_send_wr = attr.cap.max_recv_wr = 1;
88 attr.cap.max_send_sge = attr.cap.max_recv_sge = 1;
89 ret = rdma_create_ep(&listen_id, res, NULL, &attr);
90 rdma_freeaddrinfo(res);
92 perror("rdma_create_ep");
96 ret = rdma_listen(listen_id, 0);
98 perror("rdma_listen");
102 ret = rdma_get_request(listen_id, &id);
104 perror("rdma_get_request");
108 if (hints.ai_qp_type == IBV_QPT_XRC_RECV) {
114 mr = rdma_reg_msgs(id, recv_msg, sizeof recv_msg);
116 perror("rdma_reg_msgs");
120 ret = rdma_post_recv(id, NULL, recv_msg, sizeof recv_msg, mr);
122 perror("rdma_post_recv");
126 memset(¶m, 0, sizeof param);
127 param.private_data = &srqn;
128 param.private_data_len = sizeof srqn;
129 ret = rdma_accept(id, ¶m);
131 perror("rdma_accept");
135 ret = rdma_get_recv_comp(id, &wc);
137 perror("rdma_get_recv_comp");
144 rdma_destroy_ep(listen_id);
148 int main(int argc, char **argv)
152 hints.ai_flags = RAI_PASSIVE;
153 hints.ai_port_space = RDMA_PS_TCP;
154 hints.ai_qp_type = IBV_QPT_RC;
156 while ((op = getopt(argc, argv, "p:c:")) != -1) {
162 switch (tolower(optarg[0])) {
166 hints.ai_port_space = RDMA_PS_IB;
167 hints.ai_qp_type = IBV_QPT_XRC_RECV;
178 printf("%s: start\n", argv[0]);
180 printf("%s: end %d\n", argv[0], ret);
184 printf("usage: %s\n", argv[0]);
185 printf("\t[-p port_number]\n");
186 printf("\t[-c communication type]\n");
187 printf("\t r - RC: reliable-connected (default)\n");
188 printf("\t x - XRC: extended-reliable-connected\n");