/*1* Copyright (c) 2005 Network Appliance, Inc. All rights reserved.2* Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/32#ifndef IW_CM_H33#define IW_CM_H3435#include <linux/in.h>36#include <rdma/ib_cm.h>3738struct iw_cm_id;3940enum iw_cm_event_type {41IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */42IW_CM_EVENT_CONNECT_REPLY, /* reply from active connect request */43IW_CM_EVENT_ESTABLISHED, /* passive side accept successful */44IW_CM_EVENT_DISCONNECT, /* orderly shutdown */45IW_CM_EVENT_CLOSE /* close complete */46};4748struct iw_cm_event {49enum iw_cm_event_type event;50int status;51struct sockaddr_in local_addr;52struct sockaddr_in remote_addr;53void *private_data;54u8 private_data_len;55void *provider_data;56};5758/**59* iw_cm_handler - Function to be called by the IW CM when delivering events60* to the client.61*62* @cm_id: The IW CM identifier associated with the event.63* @event: Pointer to the event structure.64*/65typedef int (*iw_cm_handler)(struct iw_cm_id *cm_id,66struct iw_cm_event *event);6768/**69* iw_event_handler - Function called by the provider when delivering provider70* events to the IW CM. Returns either 0 indicating the event was processed71* or -errno if the event could not be processed.72*73* @cm_id: The IW CM identifier associated with the event.74* @event: Pointer to the event structure.75*/76typedef int (*iw_event_handler)(struct iw_cm_id *cm_id,77struct iw_cm_event *event);7879struct iw_cm_id {80iw_cm_handler cm_handler; /* client callback function */81void *context; /* client cb context */82struct ib_device *device;83struct sockaddr_in local_addr;84struct sockaddr_in remote_addr;85void *provider_data; /* provider private data */86iw_event_handler event_handler; /* cb for provider87events */88/* Used by provider to add and remove refs on IW cm_id */89void (*add_ref)(struct iw_cm_id *);90void (*rem_ref)(struct iw_cm_id *);91};9293struct iw_cm_conn_param {94const void *private_data;95u16 private_data_len;96u32 ord;97u32 ird;98u32 qpn;99};100101struct iw_cm_verbs {102void (*add_ref)(struct ib_qp *qp);103104void (*rem_ref)(struct ib_qp *qp);105106struct ib_qp * (*get_qp)(struct ib_device *device,107int qpn);108109int (*connect)(struct iw_cm_id *cm_id,110struct iw_cm_conn_param *conn_param);111112int (*accept)(struct iw_cm_id *cm_id,113struct iw_cm_conn_param *conn_param);114115int (*reject)(struct iw_cm_id *cm_id,116const void *pdata, u8 pdata_len);117118int (*create_listen)(struct iw_cm_id *cm_id,119int backlog);120121int (*destroy_listen)(struct iw_cm_id *cm_id);122};123124/**125* iw_create_cm_id - Create an IW CM identifier.126*127* @device: The IB device on which to create the IW CM identier.128* @event_handler: User callback invoked to report events associated with the129* returned IW CM identifier.130* @context: User specified context associated with the id.131*/132struct iw_cm_id *iw_create_cm_id(struct ib_device *device,133iw_cm_handler cm_handler, void *context);134135/**136* iw_destroy_cm_id - Destroy an IW CM identifier.137*138* @cm_id: The previously created IW CM identifier to destroy.139*140* The client can assume that no events will be delivered for the CM ID after141* this function returns.142*/143void iw_destroy_cm_id(struct iw_cm_id *cm_id);144145/**146* iw_cm_bind_qp - Unbind the specified IW CM identifier and QP147*148* @cm_id: The IW CM idenfier to unbind from the QP.149* @qp: The QP150*151* This is called by the provider when destroying the QP to ensure152* that any references held by the IWCM are released. It may also153* be called by the IWCM when destroying a CM_ID to that any154* references held by the provider are released.155*/156void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp);157158/**159* iw_cm_get_qp - Return the ib_qp associated with a QPN160*161* @ib_device: The IB device162* @qpn: The queue pair number163*/164struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn);165166/**167* iw_cm_listen - Listen for incoming connection requests on the168* specified IW CM id.169*170* @cm_id: The IW CM identifier.171* @backlog: The maximum number of outstanding un-accepted inbound listen172* requests to queue.173*174* The source address and port number are specified in the IW CM identifier175* structure.176*/177int iw_cm_listen(struct iw_cm_id *cm_id, int backlog);178179/**180* iw_cm_accept - Called to accept an incoming connect request.181*182* @cm_id: The IW CM identifier associated with the connection request.183* @iw_param: Pointer to a structure containing connection establishment184* parameters.185*186* The specified cm_id will have been provided in the event data for a187* CONNECT_REQUEST event. Subsequent events related to this connection will be188* delivered to the specified IW CM identifier prior and may occur prior to189* the return of this function. If this function returns a non-zero value, the190* client can assume that no events will be delivered to the specified IW CM191* identifier.192*/193int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);194195/**196* iw_cm_reject - Reject an incoming connection request.197*198* @cm_id: Connection identifier associated with the request.199* @private_daa: Pointer to data to deliver to the remote peer as part of the200* reject message.201* @private_data_len: The number of bytes in the private_data parameter.202*203* The client can assume that no events will be delivered to the specified IW204* CM identifier following the return of this function. The private_data205* buffer is available for reuse when this function returns.206*/207int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data,208u8 private_data_len);209210/**211* iw_cm_connect - Called to request a connection to a remote peer.212*213* @cm_id: The IW CM identifier for the connection.214* @iw_param: Pointer to a structure containing connection establishment215* parameters.216*217* Events may be delivered to the specified IW CM identifier prior to the218* return of this function. If this function returns a non-zero value, the219* client can assume that no events will be delivered to the specified IW CM220* identifier.221*/222int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);223224/**225* iw_cm_disconnect - Close the specified connection.226*227* @cm_id: The IW CM identifier to close.228* @abrupt: If 0, the connection will be closed gracefully, otherwise, the229* connection will be reset.230*231* The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is232* delivered.233*/234int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt);235236/**237* iw_cm_init_qp_attr - Called to initialize the attributes of the QP238* associated with a IW CM identifier.239*240* @cm_id: The IW CM identifier associated with the QP241* @qp_attr: Pointer to the QP attributes structure.242* @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are243* valid.244*/245int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr,246int *qp_attr_mask);247248#endif /* IW_CM_H */249250251