1/* 2 * Copyright (c) 2005 Network Appliance, Inc. All rights reserved. 3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved. 4 * Copyright (c) 2016 Chelsio Communications. All rights reserved. 5 * 6 * This software is available to you under a choice of one of two 7 * licenses. You may choose to be licensed under the terms of the GNU 8 * General Public License (GPL) Version 2, available from the file 9 * COPYING in the main directory of this source tree, or the 10 * OpenIB.org BSD license below: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * - Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34#ifndef IW_CM_H 35#define IW_CM_H 36 37#include <linux/in.h> 38#include <rdma/ib_cm.h> 39 40struct iw_cm_id; 41 42enum iw_cm_event_type { 43 IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */ 44 IW_CM_EVENT_CONNECT_REPLY, /* reply from active connect request */ 45 IW_CM_EVENT_ESTABLISHED, /* passive side accept successful */ 46 IW_CM_EVENT_DISCONNECT, /* orderly shutdown */ 47 IW_CM_EVENT_CLOSE /* close complete */ 48}; 49 50enum iw_cm_event_status { 51 IW_CM_EVENT_STATUS_OK = 0, /* request successful */ 52 IW_CM_EVENT_STATUS_ACCEPTED = 0, /* connect request accepted */ 53 IW_CM_EVENT_STATUS_REJECTED, /* connect request rejected */ 54 IW_CM_EVENT_STATUS_TIMEOUT, /* the operation timed out */ 55 IW_CM_EVENT_STATUS_RESET, /* reset from remote peer */ 56 IW_CM_EVENT_STATUS_EINVAL, /* asynchronous failure for bad parm */ 57}; 58 59struct iw_cm_event { 60 enum iw_cm_event_type event; 61 enum iw_cm_event_status status; 62 struct sockaddr_in local_addr; 63 struct sockaddr_in remote_addr; 64 void *private_data; 65 u8 private_data_len; 66 void *provider_data; 67 struct socket *so; 68 u8 ord; 69 u8 ird; 70}; 71 72/** 73 * iw_cm_handler - Function to be called by the IW CM when delivering events 74 * to the client. 75 * 76 * @cm_id: The IW CM identifier associated with the event. 77 * @event: Pointer to the event structure. 78 */ 79typedef int (*iw_cm_handler)(struct iw_cm_id *cm_id, 80 struct iw_cm_event *event); 81 82/** 83 * iw_event_handler - Function called by the provider when delivering provider 84 * events to the IW CM. Returns either 0 indicating the event was processed 85 * or -errno if the event could not be processed. 86 * 87 * @cm_id: The IW CM identifier associated with the event. 88 * @event: Pointer to the event structure. 89 */ 90typedef int (*iw_event_handler)(struct iw_cm_id *cm_id, 91 struct iw_cm_event *event); 92 93struct iw_cm_id { 94 iw_cm_handler cm_handler; /* client callback function */ 95 void *context; /* client cb context */ 96 struct ib_device *device; 97 struct sockaddr_in local_addr; 98 struct sockaddr_in remote_addr; 99 void *provider_data; /* provider private data */ 100 iw_event_handler event_handler; /* cb for provider 101 events */ 102 /* Used by provider to add and remove refs on IW cm_id */ 103 void (*add_ref)(struct iw_cm_id *); 104 void (*rem_ref)(struct iw_cm_id *); 105 struct socket *so; 106}; 107 108struct iw_cm_conn_param { 109 const void *private_data; 110 u16 private_data_len; 111 u32 ord; 112 u32 ird; 113 u32 qpn; 114}; 115 116struct iw_cm_verbs { 117 void (*add_ref)(struct ib_qp *qp); 118 119 void (*rem_ref)(struct ib_qp *qp); 120 121 struct ib_qp * (*get_qp)(struct ib_device *device, 122 int qpn); 123 124 int (*connect)(struct iw_cm_id *cm_id, 125 struct iw_cm_conn_param *conn_param); 126 127 int (*accept)(struct iw_cm_id *cm_id, 128 struct iw_cm_conn_param *conn_param); 129 130 int (*reject)(struct iw_cm_id *cm_id, 131 const void *pdata, u8 pdata_len); 132 133 int (*create_listen_ep)(struct iw_cm_id *cm_id, 134 int backlog); 135 136 void (*destroy_listen_ep)(struct iw_cm_id *cm_id); 137 138 void (*newconn)(struct iw_cm_id *parent_cm_id, 139 struct socket *so); 140}; 141 142/** 143 * iw_create_cm_id - Create an IW CM identifier. 144 * 145 * @device: The IB device on which to create the IW CM identier. 146 * @event_handler: User callback invoked to report events associated with the 147 * returned IW CM identifier. 148 * @context: User specified context associated with the id. 149 */ 150struct iw_cm_id *iw_create_cm_id(struct ib_device *device, struct socket *so, 151 iw_cm_handler cm_handler, void *context); 152 153/** 154 * iw_destroy_cm_id - Destroy an IW CM identifier. 155 * 156 * @cm_id: The previously created IW CM identifier to destroy. 157 * 158 * The client can assume that no events will be delivered for the CM ID after 159 * this function returns. 160 */ 161void iw_destroy_cm_id(struct iw_cm_id *cm_id); 162 163/** 164 * iw_cm_bind_qp - Unbind the specified IW CM identifier and QP 165 * 166 * @cm_id: The IW CM idenfier to unbind from the QP. 167 * @qp: The QP 168 * 169 * This is called by the provider when destroying the QP to ensure 170 * that any references held by the IWCM are released. It may also 171 * be called by the IWCM when destroying a CM_ID to that any 172 * references held by the provider are released. 173 */ 174void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp); 175 176/** 177 * iw_cm_get_qp - Return the ib_qp associated with a QPN 178 * 179 * @ib_device: The IB device 180 * @qpn: The queue pair number 181 */ 182struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn); 183 184/** 185 * iw_cm_listen - Listen for incoming connection requests on the 186 * specified IW CM id. 187 * 188 * @cm_id: The IW CM identifier. 189 * @backlog: The maximum number of outstanding un-accepted inbound listen 190 * requests to queue. 191 * 192 * The source address and port number are specified in the IW CM identifier 193 * structure. 194 */ 195int iw_cm_listen(struct iw_cm_id *cm_id, int backlog); 196 197/** 198 * iw_cm_accept - Called to accept an incoming connect request. 199 * 200 * @cm_id: The IW CM identifier associated with the connection request. 201 * @iw_param: Pointer to a structure containing connection establishment 202 * parameters. 203 * 204 * The specified cm_id will have been provided in the event data for a 205 * CONNECT_REQUEST event. Subsequent events related to this connection will be 206 * delivered to the specified IW CM identifier prior and may occur prior to 207 * the return of this function. If this function returns a non-zero value, the 208 * client can assume that no events will be delivered to the specified IW CM 209 * identifier. 210 */ 211int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); 212 213/** 214 * iw_cm_reject - Reject an incoming connection request. 215 * 216 * @cm_id: Connection identifier associated with the request. 217 * @private_daa: Pointer to data to deliver to the remote peer as part of the 218 * reject message. 219 * @private_data_len: The number of bytes in the private_data parameter. 220 * 221 * The client can assume that no events will be delivered to the specified IW 222 * CM identifier following the return of this function. The private_data 223 * buffer is available for reuse when this function returns. 224 */ 225int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data, 226 u8 private_data_len); 227 228/** 229 * iw_cm_connect - Called to request a connection to a remote peer. 230 * 231 * @cm_id: The IW CM identifier for the connection. 232 * @iw_param: Pointer to a structure containing connection establishment 233 * parameters. 234 * 235 * Events may be delivered to the specified IW CM identifier prior to the 236 * return of this function. If this function returns a non-zero value, the 237 * client can assume that no events will be delivered to the specified IW CM 238 * identifier. 239 */ 240int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); 241 242/** 243 * iw_cm_disconnect - Close the specified connection. 244 * 245 * @cm_id: The IW CM identifier to close. 246 * @abrupt: If 0, the connection will be closed gracefully, otherwise, the 247 * connection will be reset. 248 * 249 * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is 250 * delivered. 251 */ 252int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt); 253 254/** 255 * iw_cm_init_qp_attr - Called to initialize the attributes of the QP 256 * associated with a IW CM identifier. 257 * 258 * @cm_id: The IW CM identifier associated with the QP 259 * @qp_attr: Pointer to the QP attributes structure. 260 * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are 261 * valid. 262 */ 263int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr, 264 int *qp_attr_mask); 265 266#endif /* IW_CM_H */ 267