1219820Sjeff/* 2219820Sjeff * Copyright (c) 2005 Network Appliance, Inc. All rights reserved. 3219820Sjeff * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved. 4219820Sjeff * 5219820Sjeff * This software is available to you under a choice of one of two 6219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 7219820Sjeff * General Public License (GPL) Version 2, available from the file 8219820Sjeff * COPYING in the main directory of this source tree, or the 9219820Sjeff * OpenIB.org BSD license below: 10219820Sjeff * 11219820Sjeff * Redistribution and use in source and binary forms, with or 12219820Sjeff * without modification, are permitted provided that the following 13219820Sjeff * conditions are met: 14219820Sjeff * 15219820Sjeff * - Redistributions of source code must retain the above 16219820Sjeff * copyright notice, this list of conditions and the following 17219820Sjeff * disclaimer. 18219820Sjeff * 19219820Sjeff * - Redistributions in binary form must reproduce the above 20219820Sjeff * copyright notice, this list of conditions and the following 21219820Sjeff * disclaimer in the documentation and/or other materials 22219820Sjeff * provided with the distribution. 23219820Sjeff * 24219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31219820Sjeff * SOFTWARE. 32219820Sjeff */ 33219820Sjeff#ifndef IW_CM_H 34219820Sjeff#define IW_CM_H 35219820Sjeff 36219820Sjeff#include <linux/in.h> 37219820Sjeff#include <rdma/ib_cm.h> 38219820Sjeff 39219820Sjeffstruct iw_cm_id; 40219820Sjeff 41219820Sjeffenum iw_cm_event_type { 42219820Sjeff IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */ 43219820Sjeff IW_CM_EVENT_CONNECT_REPLY, /* reply from active connect request */ 44219820Sjeff IW_CM_EVENT_ESTABLISHED, /* passive side accept successful */ 45219820Sjeff IW_CM_EVENT_DISCONNECT, /* orderly shutdown */ 46219820Sjeff IW_CM_EVENT_CLOSE /* close complete */ 47219820Sjeff}; 48219820Sjeff 49219820Sjeffenum iw_cm_event_status { 50219820Sjeff IW_CM_EVENT_STATUS_OK = 0, /* request successful */ 51219820Sjeff IW_CM_EVENT_STATUS_ACCEPTED = 0, /* connect request accepted */ 52219820Sjeff IW_CM_EVENT_STATUS_REJECTED, /* connect request rejected */ 53219820Sjeff IW_CM_EVENT_STATUS_TIMEOUT, /* the operation timed out */ 54219820Sjeff IW_CM_EVENT_STATUS_RESET, /* reset from remote peer */ 55219820Sjeff IW_CM_EVENT_STATUS_EINVAL, /* asynchronous failure for bad parm */ 56219820Sjeff}; 57219820Sjeff 58219820Sjeffstruct iw_cm_event { 59219820Sjeff enum iw_cm_event_type event; 60219820Sjeff enum iw_cm_event_status status; 61219820Sjeff struct sockaddr_in local_addr; 62219820Sjeff struct sockaddr_in remote_addr; 63219820Sjeff void *private_data; 64219820Sjeff u8 private_data_len; 65219820Sjeff void *provider_data; 66237263Snp struct socket *so; 67219820Sjeff}; 68219820Sjeff 69219820Sjeff/** 70219820Sjeff * iw_cm_handler - Function to be called by the IW CM when delivering events 71219820Sjeff * to the client. 72219820Sjeff * 73219820Sjeff * @cm_id: The IW CM identifier associated with the event. 74219820Sjeff * @event: Pointer to the event structure. 75219820Sjeff */ 76219820Sjefftypedef int (*iw_cm_handler)(struct iw_cm_id *cm_id, 77219820Sjeff struct iw_cm_event *event); 78219820Sjeff 79219820Sjeff/** 80219820Sjeff * iw_event_handler - Function called by the provider when delivering provider 81219820Sjeff * events to the IW CM. Returns either 0 indicating the event was processed 82219820Sjeff * or -errno if the event could not be processed. 83219820Sjeff * 84219820Sjeff * @cm_id: The IW CM identifier associated with the event. 85219820Sjeff * @event: Pointer to the event structure. 86219820Sjeff */ 87219820Sjefftypedef int (*iw_event_handler)(struct iw_cm_id *cm_id, 88219820Sjeff struct iw_cm_event *event); 89219820Sjeff 90219820Sjeffstruct iw_cm_id { 91219820Sjeff iw_cm_handler cm_handler; /* client callback function */ 92219820Sjeff void *context; /* client cb context */ 93219820Sjeff struct ib_device *device; 94219820Sjeff struct sockaddr_in local_addr; 95219820Sjeff struct sockaddr_in remote_addr; 96219820Sjeff void *provider_data; /* provider private data */ 97219820Sjeff iw_event_handler event_handler; /* cb for provider 98219820Sjeff events */ 99219820Sjeff /* Used by provider to add and remove refs on IW cm_id */ 100219820Sjeff void (*add_ref)(struct iw_cm_id *); 101219820Sjeff void (*rem_ref)(struct iw_cm_id *); 102237263Snp struct socket *so; 103219820Sjeff}; 104219820Sjeff 105219820Sjeffstruct iw_cm_conn_param { 106219820Sjeff const void *private_data; 107219820Sjeff u16 private_data_len; 108219820Sjeff u32 ord; 109219820Sjeff u32 ird; 110219820Sjeff u32 qpn; 111219820Sjeff}; 112219820Sjeff 113219820Sjeffstruct iw_cm_verbs { 114219820Sjeff void (*add_ref)(struct ib_qp *qp); 115219820Sjeff 116219820Sjeff void (*rem_ref)(struct ib_qp *qp); 117219820Sjeff 118219820Sjeff struct ib_qp * (*get_qp)(struct ib_device *device, 119219820Sjeff int qpn); 120219820Sjeff 121219820Sjeff int (*connect)(struct iw_cm_id *cm_id, 122219820Sjeff struct iw_cm_conn_param *conn_param); 123219820Sjeff 124219820Sjeff int (*accept)(struct iw_cm_id *cm_id, 125219820Sjeff struct iw_cm_conn_param *conn_param); 126219820Sjeff 127219820Sjeff int (*reject)(struct iw_cm_id *cm_id, 128219820Sjeff const void *pdata, u8 pdata_len); 129219820Sjeff 130219820Sjeff int (*create_listen)(struct iw_cm_id *cm_id, 131219820Sjeff int backlog); 132219820Sjeff 133219820Sjeff int (*destroy_listen)(struct iw_cm_id *cm_id); 134219820Sjeff}; 135219820Sjeff 136219820Sjeff/** 137219820Sjeff * iw_create_cm_id - Create an IW CM identifier. 138219820Sjeff * 139219820Sjeff * @device: The IB device on which to create the IW CM identier. 140219820Sjeff * @event_handler: User callback invoked to report events associated with the 141219820Sjeff * returned IW CM identifier. 142219820Sjeff * @context: User specified context associated with the id. 143219820Sjeff */ 144237263Snpstruct iw_cm_id *iw_create_cm_id(struct ib_device *device, struct socket *so, 145219820Sjeff iw_cm_handler cm_handler, void *context); 146219820Sjeff 147219820Sjeff/** 148219820Sjeff * iw_destroy_cm_id - Destroy an IW CM identifier. 149219820Sjeff * 150219820Sjeff * @cm_id: The previously created IW CM identifier to destroy. 151219820Sjeff * 152219820Sjeff * The client can assume that no events will be delivered for the CM ID after 153219820Sjeff * this function returns. 154219820Sjeff */ 155219820Sjeffvoid iw_destroy_cm_id(struct iw_cm_id *cm_id); 156219820Sjeff 157219820Sjeff/** 158219820Sjeff * iw_cm_bind_qp - Unbind the specified IW CM identifier and QP 159219820Sjeff * 160219820Sjeff * @cm_id: The IW CM idenfier to unbind from the QP. 161219820Sjeff * @qp: The QP 162219820Sjeff * 163219820Sjeff * This is called by the provider when destroying the QP to ensure 164219820Sjeff * that any references held by the IWCM are released. It may also 165219820Sjeff * be called by the IWCM when destroying a CM_ID to that any 166219820Sjeff * references held by the provider are released. 167219820Sjeff */ 168219820Sjeffvoid iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp); 169219820Sjeff 170219820Sjeff/** 171219820Sjeff * iw_cm_get_qp - Return the ib_qp associated with a QPN 172219820Sjeff * 173219820Sjeff * @ib_device: The IB device 174219820Sjeff * @qpn: The queue pair number 175219820Sjeff */ 176219820Sjeffstruct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn); 177219820Sjeff 178219820Sjeff/** 179219820Sjeff * iw_cm_listen - Listen for incoming connection requests on the 180219820Sjeff * specified IW CM id. 181219820Sjeff * 182219820Sjeff * @cm_id: The IW CM identifier. 183219820Sjeff * @backlog: The maximum number of outstanding un-accepted inbound listen 184219820Sjeff * requests to queue. 185219820Sjeff * 186219820Sjeff * The source address and port number are specified in the IW CM identifier 187219820Sjeff * structure. 188219820Sjeff */ 189219820Sjeffint iw_cm_listen(struct iw_cm_id *cm_id, int backlog); 190219820Sjeff 191219820Sjeff/** 192219820Sjeff * iw_cm_accept - Called to accept an incoming connect request. 193219820Sjeff * 194219820Sjeff * @cm_id: The IW CM identifier associated with the connection request. 195219820Sjeff * @iw_param: Pointer to a structure containing connection establishment 196219820Sjeff * parameters. 197219820Sjeff * 198219820Sjeff * The specified cm_id will have been provided in the event data for a 199219820Sjeff * CONNECT_REQUEST event. Subsequent events related to this connection will be 200219820Sjeff * delivered to the specified IW CM identifier prior and may occur prior to 201219820Sjeff * the return of this function. If this function returns a non-zero value, the 202219820Sjeff * client can assume that no events will be delivered to the specified IW CM 203219820Sjeff * identifier. 204219820Sjeff */ 205219820Sjeffint iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); 206219820Sjeff 207219820Sjeff/** 208219820Sjeff * iw_cm_reject - Reject an incoming connection request. 209219820Sjeff * 210219820Sjeff * @cm_id: Connection identifier associated with the request. 211219820Sjeff * @private_daa: Pointer to data to deliver to the remote peer as part of the 212219820Sjeff * reject message. 213219820Sjeff * @private_data_len: The number of bytes in the private_data parameter. 214219820Sjeff * 215219820Sjeff * The client can assume that no events will be delivered to the specified IW 216219820Sjeff * CM identifier following the return of this function. The private_data 217219820Sjeff * buffer is available for reuse when this function returns. 218219820Sjeff */ 219219820Sjeffint iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data, 220219820Sjeff u8 private_data_len); 221219820Sjeff 222219820Sjeff/** 223219820Sjeff * iw_cm_connect - Called to request a connection to a remote peer. 224219820Sjeff * 225219820Sjeff * @cm_id: The IW CM identifier for the connection. 226219820Sjeff * @iw_param: Pointer to a structure containing connection establishment 227219820Sjeff * parameters. 228219820Sjeff * 229219820Sjeff * Events may be delivered to the specified IW CM identifier prior to the 230219820Sjeff * return of this function. If this function returns a non-zero value, the 231219820Sjeff * client can assume that no events will be delivered to the specified IW CM 232219820Sjeff * identifier. 233219820Sjeff */ 234219820Sjeffint iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); 235219820Sjeff 236219820Sjeff/** 237219820Sjeff * iw_cm_disconnect - Close the specified connection. 238219820Sjeff * 239219820Sjeff * @cm_id: The IW CM identifier to close. 240219820Sjeff * @abrupt: If 0, the connection will be closed gracefully, otherwise, the 241219820Sjeff * connection will be reset. 242219820Sjeff * 243219820Sjeff * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is 244219820Sjeff * delivered. 245219820Sjeff */ 246219820Sjeffint iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt); 247219820Sjeff 248219820Sjeff/** 249219820Sjeff * iw_cm_init_qp_attr - Called to initialize the attributes of the QP 250219820Sjeff * associated with a IW CM identifier. 251219820Sjeff * 252219820Sjeff * @cm_id: The IW CM identifier associated with the QP 253219820Sjeff * @qp_attr: Pointer to the QP attributes structure. 254219820Sjeff * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are 255219820Sjeff * valid. 256219820Sjeff */ 257219820Sjeffint iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr, 258219820Sjeff int *qp_attr_mask); 259219820Sjeff 260219820Sjeff#endif /* IW_CM_H */ 261