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
34 #include <linux/slab.h>
39 #include <rdma/iw_cm.h>
41 int c2_llp_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*iw_param
)
43 struct c2_dev
*c2dev
= to_c2dev(cm_id
->device
);
46 struct c2wr_qp_connect_req
*wr
; /* variable size needs a malloc. */
47 struct c2_vq_req
*vq_req
;
49 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&cm_id
->remote_addr
;
51 if (cm_id
->remote_addr
.ss_family
!= AF_INET
)
54 ibqp
= c2_get_qp(cm_id
->device
, iw_param
->qpn
);
59 /* Associate QP <--> CM_ID */
60 cm_id
->provider_data
= qp
;
61 cm_id
->add_ref(cm_id
);
65 * only support the max private_data length
67 if (iw_param
->private_data_len
> C2_MAX_PRIVATE_DATA_SIZE
) {
72 * Set the rdma read limits
74 err
= c2_qp_set_read_limits(c2dev
, qp
, iw_param
->ord
, iw_param
->ird
);
79 * Create and send a WR_QP_CONNECT...
81 wr
= kmalloc(c2dev
->req_vq
.msg_size
, GFP_KERNEL
);
87 vq_req
= vq_req_alloc(c2dev
);
93 c2_wr_set_id(wr
, CCWR_QP_CONNECT
);
95 wr
->rnic_handle
= c2dev
->adapter_handle
;
96 wr
->qp_handle
= qp
->adapter_handle
;
98 wr
->remote_addr
= raddr
->sin_addr
.s_addr
;
99 wr
->remote_port
= raddr
->sin_port
;
102 * Move any private data from the callers's buf into
105 if (iw_param
->private_data
) {
106 wr
->private_data_length
=
107 cpu_to_be32(iw_param
->private_data_len
);
108 memcpy(&wr
->private_data
[0], iw_param
->private_data
,
109 iw_param
->private_data_len
);
111 wr
->private_data_length
= 0;
114 * Send WR to adapter. NOTE: There is no synch reply from
117 err
= vq_send_wr(c2dev
, (union c2wr
*) wr
);
118 vq_req_free(c2dev
, vq_req
);
125 * If we fail, release reference on QP and
126 * disassociate QP from CM_ID
128 cm_id
->provider_data
= NULL
;
130 cm_id
->rem_ref(cm_id
);
135 int c2_llp_service_create(struct iw_cm_id
*cm_id
, int backlog
)
137 struct c2_dev
*c2dev
;
138 struct c2wr_ep_listen_create_req wr
;
139 struct c2wr_ep_listen_create_rep
*reply
;
140 struct c2_vq_req
*vq_req
;
142 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->local_addr
;
144 if (cm_id
->local_addr
.ss_family
!= AF_INET
)
147 c2dev
= to_c2dev(cm_id
->device
);
152 * Allocate verbs request.
154 vq_req
= vq_req_alloc(c2dev
);
161 c2_wr_set_id(&wr
, CCWR_EP_LISTEN_CREATE
);
162 wr
.hdr
.context
= (u64
) (unsigned long) vq_req
;
163 wr
.rnic_handle
= c2dev
->adapter_handle
;
164 wr
.local_addr
= laddr
->sin_addr
.s_addr
;
165 wr
.local_port
= laddr
->sin_port
;
166 wr
.backlog
= cpu_to_be32(backlog
);
167 wr
.user_context
= (u64
) (unsigned long) cm_id
;
170 * Reference the request struct. Dereferenced in the int handler.
172 vq_req_get(c2dev
, vq_req
);
177 err
= vq_send_wr(c2dev
, (union c2wr
*) & wr
);
179 vq_req_put(c2dev
, vq_req
);
184 * Wait for reply from adapter
186 err
= vq_wait_for_reply(c2dev
, vq_req
);
194 (struct c2wr_ep_listen_create_rep
*) (unsigned long) vq_req
->reply_msg
;
200 if ((err
= c2_errno(reply
)) != 0)
204 * Keep the adapter handle. Used in subsequent destroy
206 cm_id
->provider_data
= (void*)(unsigned long) reply
->ep_handle
;
211 vq_repbuf_free(c2dev
, reply
);
212 vq_req_free(c2dev
, vq_req
);
217 vq_repbuf_free(c2dev
, reply
);
219 vq_req_free(c2dev
, vq_req
);
224 int c2_llp_service_destroy(struct iw_cm_id
*cm_id
)
227 struct c2_dev
*c2dev
;
228 struct c2wr_ep_listen_destroy_req wr
;
229 struct c2wr_ep_listen_destroy_rep
*reply
;
230 struct c2_vq_req
*vq_req
;
233 c2dev
= to_c2dev(cm_id
->device
);
238 * Allocate verbs request.
240 vq_req
= vq_req_alloc(c2dev
);
247 c2_wr_set_id(&wr
, CCWR_EP_LISTEN_DESTROY
);
248 wr
.hdr
.context
= (unsigned long) vq_req
;
249 wr
.rnic_handle
= c2dev
->adapter_handle
;
250 wr
.ep_handle
= (u32
)(unsigned long)cm_id
->provider_data
;
253 * reference the request struct. dereferenced in the int handler.
255 vq_req_get(c2dev
, vq_req
);
260 err
= vq_send_wr(c2dev
, (union c2wr
*) & wr
);
262 vq_req_put(c2dev
, vq_req
);
267 * Wait for reply from adapter
269 err
= vq_wait_for_reply(c2dev
, vq_req
);
276 reply
=(struct c2wr_ep_listen_destroy_rep
*)(unsigned long)vq_req
->reply_msg
;
281 if ((err
= c2_errno(reply
)) != 0)
285 vq_repbuf_free(c2dev
, reply
);
287 vq_req_free(c2dev
, vq_req
);
291 int c2_llp_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*iw_param
)
293 struct c2_dev
*c2dev
= to_c2dev(cm_id
->device
);
296 struct c2wr_cr_accept_req
*wr
; /* variable length WR */
297 struct c2_vq_req
*vq_req
;
298 struct c2wr_cr_accept_rep
*reply
; /* VQ Reply msg ptr. */
301 ibqp
= c2_get_qp(cm_id
->device
, iw_param
->qpn
);
306 /* Set the RDMA read limits */
307 err
= c2_qp_set_read_limits(c2dev
, qp
, iw_param
->ord
, iw_param
->ird
);
311 /* Allocate verbs request. */
312 vq_req
= vq_req_alloc(c2dev
);
318 vq_req
->cm_id
= cm_id
;
319 vq_req
->event
= IW_CM_EVENT_ESTABLISHED
;
321 wr
= kmalloc(c2dev
->req_vq
.msg_size
, GFP_KERNEL
);
328 c2_wr_set_id(wr
, CCWR_CR_ACCEPT
);
329 wr
->hdr
.context
= (unsigned long) vq_req
;
330 wr
->rnic_handle
= c2dev
->adapter_handle
;
331 wr
->ep_handle
= (u32
) (unsigned long) cm_id
->provider_data
;
332 wr
->qp_handle
= qp
->adapter_handle
;
334 /* Replace the cr_handle with the QP after accept */
335 cm_id
->provider_data
= qp
;
336 cm_id
->add_ref(cm_id
);
339 cm_id
->provider_data
= qp
;
341 /* Validate private_data length */
342 if (iw_param
->private_data_len
> C2_MAX_PRIVATE_DATA_SIZE
) {
347 if (iw_param
->private_data
) {
348 wr
->private_data_length
= cpu_to_be32(iw_param
->private_data_len
);
349 memcpy(&wr
->private_data
[0],
350 iw_param
->private_data
, iw_param
->private_data_len
);
352 wr
->private_data_length
= 0;
354 /* Reference the request struct. Dereferenced in the int handler. */
355 vq_req_get(c2dev
, vq_req
);
357 /* Send WR to adapter */
358 err
= vq_send_wr(c2dev
, (union c2wr
*) wr
);
360 vq_req_put(c2dev
, vq_req
);
364 /* Wait for reply from adapter */
365 err
= vq_wait_for_reply(c2dev
, vq_req
);
369 /* Check that reply is present */
370 reply
= (struct c2wr_cr_accept_rep
*) (unsigned long) vq_req
->reply_msg
;
376 err
= c2_errno(reply
);
377 vq_repbuf_free(c2dev
, reply
);
380 c2_set_qp_state(qp
, C2_QP_STATE_RTS
);
383 vq_req_free(c2dev
, vq_req
);
387 * If we fail, release reference on QP and
388 * disassociate QP from CM_ID
390 cm_id
->provider_data
= NULL
;
392 cm_id
->rem_ref(cm_id
);
397 int c2_llp_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
399 struct c2_dev
*c2dev
;
400 struct c2wr_cr_reject_req wr
;
401 struct c2_vq_req
*vq_req
;
402 struct c2wr_cr_reject_rep
*reply
;
405 c2dev
= to_c2dev(cm_id
->device
);
408 * Allocate verbs request.
410 vq_req
= vq_req_alloc(c2dev
);
417 c2_wr_set_id(&wr
, CCWR_CR_REJECT
);
418 wr
.hdr
.context
= (unsigned long) vq_req
;
419 wr
.rnic_handle
= c2dev
->adapter_handle
;
420 wr
.ep_handle
= (u32
) (unsigned long) cm_id
->provider_data
;
423 * reference the request struct. dereferenced in the int handler.
425 vq_req_get(c2dev
, vq_req
);
430 err
= vq_send_wr(c2dev
, (union c2wr
*) & wr
);
432 vq_req_put(c2dev
, vq_req
);
437 * Wait for reply from adapter
439 err
= vq_wait_for_reply(c2dev
, vq_req
);
446 reply
= (struct c2wr_cr_reject_rep
*) (unsigned long)
452 err
= c2_errno(reply
);
456 vq_repbuf_free(c2dev
, reply
);
459 vq_req_free(c2dev
, vq_req
);