2 * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #include <rdma/iw_cm.h>
39 int c2_llp_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*iw_param
)
41 struct c2_dev
*c2dev
= to_c2dev(cm_id
->device
);
44 struct c2wr_qp_connect_req
*wr
; /* variable size needs a malloc. */
45 struct c2_vq_req
*vq_req
;
48 ibqp
= c2_get_qp(cm_id
->device
, iw_param
->qpn
);
53 /* Associate QP <--> CM_ID */
54 cm_id
->provider_data
= qp
;
55 cm_id
->add_ref(cm_id
);
59 * only support the max private_data length
61 if (iw_param
->private_data_len
> C2_MAX_PRIVATE_DATA_SIZE
) {
66 * Set the rdma read limits
68 err
= c2_qp_set_read_limits(c2dev
, qp
, iw_param
->ord
, iw_param
->ird
);
73 * Create and send a WR_QP_CONNECT...
75 wr
= kmalloc(c2dev
->req_vq
.msg_size
, GFP_KERNEL
);
81 vq_req
= vq_req_alloc(c2dev
);
87 c2_wr_set_id(wr
, CCWR_QP_CONNECT
);
89 wr
->rnic_handle
= c2dev
->adapter_handle
;
90 wr
->qp_handle
= qp
->adapter_handle
;
92 wr
->remote_addr
= cm_id
->remote_addr
.sin_addr
.s_addr
;
93 wr
->remote_port
= cm_id
->remote_addr
.sin_port
;
96 * Move any private data from the callers's buf into
99 if (iw_param
->private_data
) {
100 wr
->private_data_length
=
101 cpu_to_be32(iw_param
->private_data_len
);
102 memcpy(&wr
->private_data
[0], iw_param
->private_data
,
103 iw_param
->private_data_len
);
105 wr
->private_data_length
= 0;
108 * Send WR to adapter. NOTE: There is no synch reply from
111 err
= vq_send_wr(c2dev
, (union c2wr
*) wr
);
112 vq_req_free(c2dev
, vq_req
);
119 * If we fail, release reference on QP and
120 * disassociate QP from CM_ID
122 cm_id
->provider_data
= NULL
;
124 cm_id
->rem_ref(cm_id
);
129 int c2_llp_service_create(struct iw_cm_id
*cm_id
, int backlog
)
131 struct c2_dev
*c2dev
;
132 struct c2wr_ep_listen_create_req wr
;
133 struct c2wr_ep_listen_create_rep
*reply
;
134 struct c2_vq_req
*vq_req
;
137 c2dev
= to_c2dev(cm_id
->device
);
142 * Allocate verbs request.
144 vq_req
= vq_req_alloc(c2dev
);
151 c2_wr_set_id(&wr
, CCWR_EP_LISTEN_CREATE
);
152 wr
.hdr
.context
= (u64
) (unsigned long) vq_req
;
153 wr
.rnic_handle
= c2dev
->adapter_handle
;
154 wr
.local_addr
= cm_id
->local_addr
.sin_addr
.s_addr
;
155 wr
.local_port
= cm_id
->local_addr
.sin_port
;
156 wr
.backlog
= cpu_to_be32(backlog
);
157 wr
.user_context
= (u64
) (unsigned long) cm_id
;
160 * Reference the request struct. Dereferenced in the int handler.
162 vq_req_get(c2dev
, vq_req
);
167 err
= vq_send_wr(c2dev
, (union c2wr
*) & wr
);
169 vq_req_put(c2dev
, vq_req
);
174 * Wait for reply from adapter
176 err
= vq_wait_for_reply(c2dev
, vq_req
);
184 (struct c2wr_ep_listen_create_rep
*) (unsigned long) vq_req
->reply_msg
;
190 if ((err
= c2_errno(reply
)) != 0)
194 * Keep the adapter handle. Used in subsequent destroy
196 cm_id
->provider_data
= (void*)(unsigned long) reply
->ep_handle
;
201 vq_repbuf_free(c2dev
, reply
);
202 vq_req_free(c2dev
, vq_req
);
207 vq_repbuf_free(c2dev
, reply
);
209 vq_req_free(c2dev
, vq_req
);
214 int c2_llp_service_destroy(struct iw_cm_id
*cm_id
)
217 struct c2_dev
*c2dev
;
218 struct c2wr_ep_listen_destroy_req wr
;
219 struct c2wr_ep_listen_destroy_rep
*reply
;
220 struct c2_vq_req
*vq_req
;
223 c2dev
= to_c2dev(cm_id
->device
);
228 * Allocate verbs request.
230 vq_req
= vq_req_alloc(c2dev
);
237 c2_wr_set_id(&wr
, CCWR_EP_LISTEN_DESTROY
);
238 wr
.hdr
.context
= (unsigned long) vq_req
;
239 wr
.rnic_handle
= c2dev
->adapter_handle
;
240 wr
.ep_handle
= (u32
)(unsigned long)cm_id
->provider_data
;
243 * reference the request struct. dereferenced in the int handler.
245 vq_req_get(c2dev
, vq_req
);
250 err
= vq_send_wr(c2dev
, (union c2wr
*) & wr
);
252 vq_req_put(c2dev
, vq_req
);
257 * Wait for reply from adapter
259 err
= vq_wait_for_reply(c2dev
, vq_req
);
266 reply
=(struct c2wr_ep_listen_destroy_rep
*)(unsigned long)vq_req
->reply_msg
;
271 if ((err
= c2_errno(reply
)) != 0)
275 vq_repbuf_free(c2dev
, reply
);
277 vq_req_free(c2dev
, vq_req
);
281 int c2_llp_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*iw_param
)
283 struct c2_dev
*c2dev
= to_c2dev(cm_id
->device
);
286 struct c2wr_cr_accept_req
*wr
; /* variable length WR */
287 struct c2_vq_req
*vq_req
;
288 struct c2wr_cr_accept_rep
*reply
; /* VQ Reply msg ptr. */
291 ibqp
= c2_get_qp(cm_id
->device
, iw_param
->qpn
);
296 /* Set the RDMA read limits */
297 err
= c2_qp_set_read_limits(c2dev
, qp
, iw_param
->ord
, iw_param
->ird
);
301 /* Allocate verbs request. */
302 vq_req
= vq_req_alloc(c2dev
);
308 vq_req
->cm_id
= cm_id
;
309 vq_req
->event
= IW_CM_EVENT_ESTABLISHED
;
311 wr
= kmalloc(c2dev
->req_vq
.msg_size
, GFP_KERNEL
);
318 c2_wr_set_id(wr
, CCWR_CR_ACCEPT
);
319 wr
->hdr
.context
= (unsigned long) vq_req
;
320 wr
->rnic_handle
= c2dev
->adapter_handle
;
321 wr
->ep_handle
= (u32
) (unsigned long) cm_id
->provider_data
;
322 wr
->qp_handle
= qp
->adapter_handle
;
324 /* Replace the cr_handle with the QP after accept */
325 cm_id
->provider_data
= qp
;
326 cm_id
->add_ref(cm_id
);
329 cm_id
->provider_data
= qp
;
331 /* Validate private_data length */
332 if (iw_param
->private_data_len
> C2_MAX_PRIVATE_DATA_SIZE
) {
337 if (iw_param
->private_data
) {
338 wr
->private_data_length
= cpu_to_be32(iw_param
->private_data_len
);
339 memcpy(&wr
->private_data
[0],
340 iw_param
->private_data
, iw_param
->private_data_len
);
342 wr
->private_data_length
= 0;
344 /* Reference the request struct. Dereferenced in the int handler. */
345 vq_req_get(c2dev
, vq_req
);
347 /* Send WR to adapter */
348 err
= vq_send_wr(c2dev
, (union c2wr
*) wr
);
350 vq_req_put(c2dev
, vq_req
);
354 /* Wait for reply from adapter */
355 err
= vq_wait_for_reply(c2dev
, vq_req
);
359 /* Check that reply is present */
360 reply
= (struct c2wr_cr_accept_rep
*) (unsigned long) vq_req
->reply_msg
;
366 err
= c2_errno(reply
);
367 vq_repbuf_free(c2dev
, reply
);
370 c2_set_qp_state(qp
, C2_QP_STATE_RTS
);
373 vq_req_free(c2dev
, vq_req
);
377 * If we fail, release reference on QP and
378 * disassociate QP from CM_ID
380 cm_id
->provider_data
= NULL
;
382 cm_id
->rem_ref(cm_id
);
387 int c2_llp_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
389 struct c2_dev
*c2dev
;
390 struct c2wr_cr_reject_req wr
;
391 struct c2_vq_req
*vq_req
;
392 struct c2wr_cr_reject_rep
*reply
;
395 c2dev
= to_c2dev(cm_id
->device
);
398 * Allocate verbs request.
400 vq_req
= vq_req_alloc(c2dev
);
407 c2_wr_set_id(&wr
, CCWR_CR_REJECT
);
408 wr
.hdr
.context
= (unsigned long) vq_req
;
409 wr
.rnic_handle
= c2dev
->adapter_handle
;
410 wr
.ep_handle
= (u32
) (unsigned long) cm_id
->provider_data
;
413 * reference the request struct. dereferenced in the int handler.
415 vq_req_get(c2dev
, vq_req
);
420 err
= vq_send_wr(c2dev
, (union c2wr
*) & wr
);
422 vq_req_put(c2dev
, vq_req
);
427 * Wait for reply from adapter
429 err
= vq_wait_for_reply(c2dev
, vq_req
);
436 reply
= (struct c2wr_cr_reject_rep
*) (unsigned long)
442 err
= c2_errno(reply
);
446 vq_repbuf_free(c2dev
, reply
);
449 vq_req_free(c2dev
, vq_req
);