1 /* 2 * Copyright (c) 2005 Network Appliance, Inc. All rights reserved. 3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved. 4 * 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: 10 * 11 * Redistribution and use in source and binary forms, with or 12 * without modification, are permitted provided that the following 13 * conditions are met: 14 * 15 * - Redistributions of source code must retain the above 16 * copyright notice, this list of conditions and the following 17 * disclaimer. 18 * 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. 23 * 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 31 * SOFTWARE. 32 */ 33 #ifndef IW_CM_H 34 #define IW_CM_H 35 36 #include <linux/in.h> 37 #include <rdma/ib_cm.h> 38 39 struct iw_cm_id; 40 41 enum iw_cm_event_type { 42 IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */ 43 IW_CM_EVENT_CONNECT_REPLY, /* reply from active connect request */ 44 IW_CM_EVENT_ESTABLISHED, /* passive side accept successful */ 45 IW_CM_EVENT_DISCONNECT, /* orderly shutdown */ 46 IW_CM_EVENT_CLOSE /* close complete */ 47 }; 48 49 struct iw_cm_event { 50 enum iw_cm_event_type event; 51 int status; 52 struct sockaddr_in local_addr; 53 struct sockaddr_in remote_addr; 54 void *private_data; 55 void *provider_data; 56 u8 private_data_len; 57 struct socket *so; 58 u8 ord; 59 u8 ird; 60 }; 61 62 /** 63 * iw_cm_handler - Function to be called by the IW CM when delivering events 64 * to the client. 65 * 66 * @cm_id: The IW CM identifier associated with the event. 67 * @event: Pointer to the event structure. 68 */ 69 typedef int (*iw_cm_handler)(struct iw_cm_id *cm_id, 70 struct iw_cm_event *event); 71 72 /** 73 * iw_event_handler - Function called by the provider when delivering provider 74 * events to the IW CM. Returns either 0 indicating the event was processed 75 * or -errno if the event could not be processed. 76 * 77 * @cm_id: The IW CM identifier associated with the event. 78 * @event: Pointer to the event structure. 79 */ 80 typedef int (*iw_event_handler)(struct iw_cm_id *cm_id, 81 struct iw_cm_event *event); 82 83 struct iw_cm_id { 84 iw_cm_handler cm_handler; /* client callback function */ 85 void *context; /* client cb context */ 86 struct ib_device *device; 87 struct sockaddr_in local_addr; 88 struct sockaddr_in remote_addr; 89 void *provider_data; /* provider private data */ 90 iw_event_handler event_handler; /* cb for provider 91 events */ 92 /* Used by provider to add and remove refs on IW cm_id */ 93 void (*add_ref)(struct iw_cm_id *); 94 void (*rem_ref)(struct iw_cm_id *); 95 struct socket *so; 96 }; 97 98 struct iw_cm_conn_param { 99 const void *private_data; 100 u16 private_data_len; 101 u32 ord; 102 u32 ird; 103 u32 qpn; 104 }; 105 106 struct iw_cm_verbs { 107 void (*add_ref)(struct ib_qp *qp); 108 109 void (*rem_ref)(struct ib_qp *qp); 110 111 struct ib_qp * (*get_qp)(struct ib_device *device, 112 int qpn); 113 114 int (*connect)(struct iw_cm_id *cm_id, 115 struct iw_cm_conn_param *conn_param); 116 117 int (*accept)(struct iw_cm_id *cm_id, 118 struct iw_cm_conn_param *conn_param); 119 120 int (*reject)(struct iw_cm_id *cm_id, 121 const void *pdata, u8 pdata_len); 122 123 int (*create_listen)(struct iw_cm_id *cm_id, 124 int backlog); 125 126 int (*destroy_listen)(struct iw_cm_id *cm_id); 127 }; 128 129 /** 130 * iw_create_cm_id - Create an IW CM identifier. 131 * 132 * @device: The IB device on which to create the IW CM identier. 133 * @event_handler: User callback invoked to report events associated with the 134 * returned IW CM identifier. 135 * @context: User specified context associated with the id. 136 */ 137 struct iw_cm_id *iw_create_cm_id(struct ib_device *device, struct socket *so, 138 iw_cm_handler cm_handler, void *context); 139 140 /** 141 * iw_destroy_cm_id - Destroy an IW CM identifier. 142 * 143 * @cm_id: The previously created IW CM identifier to destroy. 144 * 145 * The client can assume that no events will be delivered for the CM ID after 146 * this function returns. 147 */ 148 void iw_destroy_cm_id(struct iw_cm_id *cm_id); 149 150 /** 151 * iw_cm_bind_qp - Unbind the specified IW CM identifier and QP 152 * 153 * @cm_id: The IW CM idenfier to unbind from the QP. 154 * @qp: The QP 155 * 156 * This is called by the provider when destroying the QP to ensure 157 * that any references held by the IWCM are released. It may also 158 * be called by the IWCM when destroying a CM_ID to that any 159 * references held by the provider are released. 160 */ 161 void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp); 162 163 /** 164 * iw_cm_get_qp - Return the ib_qp associated with a QPN 165 * 166 * @ib_device: The IB device 167 * @qpn: The queue pair number 168 */ 169 struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn); 170 171 /** 172 * iw_cm_listen - Listen for incoming connection requests on the 173 * specified IW CM id. 174 * 175 * @cm_id: The IW CM identifier. 176 * @backlog: The maximum number of outstanding un-accepted inbound listen 177 * requests to queue. 178 * 179 * The source address and port number are specified in the IW CM identifier 180 * structure. 181 */ 182 int iw_cm_listen(struct iw_cm_id *cm_id, int backlog); 183 184 /** 185 * iw_cm_accept - Called to accept an incoming connect request. 186 * 187 * @cm_id: The IW CM identifier associated with the connection request. 188 * @iw_param: Pointer to a structure containing connection establishment 189 * parameters. 190 * 191 * The specified cm_id will have been provided in the event data for a 192 * CONNECT_REQUEST event. Subsequent events related to this connection will be 193 * delivered to the specified IW CM identifier prior and may occur prior to 194 * the return of this function. If this function returns a non-zero value, the 195 * client can assume that no events will be delivered to the specified IW CM 196 * identifier. 197 */ 198 int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); 199 200 /** 201 * iw_cm_reject - Reject an incoming connection request. 202 * 203 * @cm_id: Connection identifier associated with the request. 204 * @private_daa: Pointer to data to deliver to the remote peer as part of the 205 * reject message. 206 * @private_data_len: The number of bytes in the private_data parameter. 207 * 208 * The client can assume that no events will be delivered to the specified IW 209 * CM identifier following the return of this function. The private_data 210 * buffer is available for reuse when this function returns. 211 */ 212 int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data, 213 u8 private_data_len); 214 215 /** 216 * iw_cm_connect - Called to request a connection to a remote peer. 217 * 218 * @cm_id: The IW CM identifier for the connection. 219 * @iw_param: Pointer to a structure containing connection establishment 220 * parameters. 221 * 222 * Events may be delivered to the specified IW CM identifier prior to the 223 * return of this function. If this function returns a non-zero value, the 224 * client can assume that no events will be delivered to the specified IW CM 225 * identifier. 226 */ 227 int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); 228 229 /** 230 * iw_cm_disconnect - Close the specified connection. 231 * 232 * @cm_id: The IW CM identifier to close. 233 * @abrupt: If 0, the connection will be closed gracefully, otherwise, the 234 * connection will be reset. 235 * 236 * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is 237 * delivered. 238 */ 239 int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt); 240 241 /** 242 * iw_cm_init_qp_attr - Called to initialize the attributes of the QP 243 * associated with a IW CM identifier. 244 * 245 * @cm_id: The IW CM identifier associated with the QP 246 * @qp_attr: Pointer to the QP attributes structure. 247 * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are 248 * valid. 249 */ 250 int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr, 251 int *qp_attr_mask); 252 253 #endif /* IW_CM_H */ 254