/*-1* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.02*3* Copyright (c) 2005 Network Appliance, Inc. All rights reserved.4* Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.5*6* This software is available to you under a choice of one of two7* licenses. You may choose to be licensed under the terms of the GNU8* General Public License (GPL) Version 2, available from the file9* COPYING in the main directory of this source tree, or the10* OpenIB.org BSD license below:11*12* Redistribution and use in source and binary forms, with or13* without modification, are permitted provided that the following14* conditions are met:15*16* - Redistributions of source code must retain the above17* copyright notice, this list of conditions and the following18* disclaimer.19*20* - Redistributions in binary form must reproduce the above21* copyright notice, this list of conditions and the following22* disclaimer in the documentation and/or other materials23* 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 OF27* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND28* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS29* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN30* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN31* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE32* SOFTWARE.33*/3435#ifndef IW_CM_H36#define IW_CM_H3738#include <linux/in.h>39#include <rdma/ib_cm.h>4041struct iw_cm_id;4243enum iw_cm_event_type {44IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */45IW_CM_EVENT_CONNECT_REPLY, /* reply from active connect request */46IW_CM_EVENT_ESTABLISHED, /* passive side accept successful */47IW_CM_EVENT_DISCONNECT, /* orderly shutdown */48IW_CM_EVENT_CLOSE /* close complete */49};5051struct iw_cm_event {52enum iw_cm_event_type event;53int status;54struct sockaddr_storage local_addr;55struct sockaddr_storage remote_addr;56void *private_data;57void *provider_data;58u8 private_data_len;59u8 ord;60u8 ird;61};6263/**64* iw_cm_handler - Function to be called by the IW CM when delivering events65* to the client.66*67* @cm_id: The IW CM identifier associated with the event.68* @event: Pointer to the event structure.69*/70typedef int (*iw_cm_handler)(struct iw_cm_id *cm_id,71struct iw_cm_event *event);7273/**74* iw_event_handler - Function called by the provider when delivering provider75* events to the IW CM. Returns either 0 indicating the event was processed76* or -errno if the event could not be processed.77*78* @cm_id: The IW CM identifier associated with the event.79* @event: Pointer to the event structure.80*/81typedef int (*iw_event_handler)(struct iw_cm_id *cm_id,82struct iw_cm_event *event);8384struct iw_cm_id {85iw_cm_handler cm_handler; /* client callback function */86void *context; /* client cb context */87struct ib_device *device;88struct sockaddr_storage local_addr; /* local addr */89struct sockaddr_storage remote_addr;90struct sockaddr_storage m_local_addr; /* nmapped local addr */91struct sockaddr_storage m_remote_addr; /* nmapped rem addr */92void *provider_data; /* provider private data */93iw_event_handler event_handler; /* cb for provider94events */95/* Used by provider to add and remove refs on IW cm_id */96void (*add_ref)(struct iw_cm_id *);97void (*rem_ref)(struct iw_cm_id *);98u8 tos;99};100101struct iw_cm_conn_param {102const void *private_data;103u16 private_data_len;104u32 ord;105u32 ird;106u32 qpn;107};108109struct iw_cm_verbs {110void (*add_ref)(struct ib_qp *qp);111112void (*rem_ref)(struct ib_qp *qp);113114struct ib_qp * (*get_qp)(struct ib_device *device,115int qpn);116117int (*connect)(struct iw_cm_id *cm_id,118struct iw_cm_conn_param *conn_param);119120int (*accept)(struct iw_cm_id *cm_id,121struct iw_cm_conn_param *conn_param);122123int (*reject)(struct iw_cm_id *cm_id,124const void *pdata, u8 pdata_len);125126int (*create_listen)(struct iw_cm_id *cm_id,127int backlog);128129int (*destroy_listen)(struct iw_cm_id *cm_id);130char ifname[IFNAMSIZ];131};132133/**134* iw_create_cm_id - Create an IW CM identifier.135*136* @device: The IB device on which to create the IW CM identier.137* @event_handler: User callback invoked to report events associated with the138* returned IW CM identifier.139* @context: User specified context associated with the id.140*/141struct iw_cm_id *iw_create_cm_id(struct ib_device *device,142iw_cm_handler cm_handler, void *context);143144/**145* iw_destroy_cm_id - Destroy an IW CM identifier.146*147* @cm_id: The previously created IW CM identifier to destroy.148*149* The client can assume that no events will be delivered for the CM ID after150* this function returns.151*/152void iw_destroy_cm_id(struct iw_cm_id *cm_id);153154/**155* iw_cm_bind_qp - Unbind the specified IW CM identifier and QP156*157* @cm_id: The IW CM idenfier to unbind from the QP.158* @qp: The QP159*160* This is called by the provider when destroying the QP to ensure161* that any references held by the IWCM are released. It may also162* be called by the IWCM when destroying a CM_ID to that any163* references held by the provider are released.164*/165void iw_cm_unbind_qp(struct iw_cm_id *cm_id, struct ib_qp *qp);166167/**168* iw_cm_get_qp - Return the ib_qp associated with a QPN169*170* @ib_device: The IB device171* @qpn: The queue pair number172*/173struct ib_qp *iw_cm_get_qp(struct ib_device *device, int qpn);174175/**176* iw_cm_listen - Listen for incoming connection requests on the177* specified IW CM id.178*179* @cm_id: The IW CM identifier.180* @backlog: The maximum number of outstanding un-accepted inbound listen181* requests to queue.182*183* The source address and port number are specified in the IW CM identifier184* structure.185*/186int iw_cm_listen(struct iw_cm_id *cm_id, int backlog);187188/**189* iw_cm_accept - Called to accept an incoming connect request.190*191* @cm_id: The IW CM identifier associated with the connection request.192* @iw_param: Pointer to a structure containing connection establishment193* parameters.194*195* The specified cm_id will have been provided in the event data for a196* CONNECT_REQUEST event. Subsequent events related to this connection will be197* delivered to the specified IW CM identifier prior and may occur prior to198* the return of this function. If this function returns a non-zero value, the199* client can assume that no events will be delivered to the specified IW CM200* identifier.201*/202int iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);203204/**205* iw_cm_reject - Reject an incoming connection request.206*207* @cm_id: Connection identifier associated with the request.208* @private_daa: Pointer to data to deliver to the remote peer as part of the209* reject message.210* @private_data_len: The number of bytes in the private_data parameter.211*212* The client can assume that no events will be delivered to the specified IW213* CM identifier following the return of this function. The private_data214* buffer is available for reuse when this function returns.215*/216int iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data,217u8 private_data_len);218219/**220* iw_cm_connect - Called to request a connection to a remote peer.221*222* @cm_id: The IW CM identifier for the connection.223* @iw_param: Pointer to a structure containing connection establishment224* parameters.225*226* Events may be delivered to the specified IW CM identifier prior to the227* return of this function. If this function returns a non-zero value, the228* client can assume that no events will be delivered to the specified IW CM229* identifier.230*/231int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);232233/**234* iw_cm_disconnect - Close the specified connection.235*236* @cm_id: The IW CM identifier to close.237* @abrupt: If 0, the connection will be closed gracefully, otherwise, the238* connection will be reset.239*240* The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is241* delivered.242*/243int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt);244245/**246* iw_cm_init_qp_attr - Called to initialize the attributes of the QP247* associated with a IW CM identifier.248*249* @cm_id: The IW CM identifier associated with the QP250* @qp_attr: Pointer to the QP attributes structure.251* @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are252* valid.253*/254int iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr,255int *qp_attr_mask);256257/**258* iwcm_reject_msg - return a pointer to a reject message string.259* @reason: Value returned in the REJECT event status field.260*/261const char *__attribute_const__ iwcm_reject_msg(int reason);262263#endif /* IW_CM_H */264265266