162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2005 Network Appliance, Inc. All rights reserved.
462306a36Sopenharmony_ci * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef IW_CM_H
862306a36Sopenharmony_ci#define IW_CM_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/in.h>
1162306a36Sopenharmony_ci#include <rdma/ib_cm.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct iw_cm_id;
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cienum iw_cm_event_type {
1662306a36Sopenharmony_ci	IW_CM_EVENT_CONNECT_REQUEST = 1, /* connect request received */
1762306a36Sopenharmony_ci	IW_CM_EVENT_CONNECT_REPLY,	 /* reply from active connect request */
1862306a36Sopenharmony_ci	IW_CM_EVENT_ESTABLISHED,	 /* passive side accept successful */
1962306a36Sopenharmony_ci	IW_CM_EVENT_DISCONNECT,		 /* orderly shutdown */
2062306a36Sopenharmony_ci	IW_CM_EVENT_CLOSE		 /* close complete */
2162306a36Sopenharmony_ci};
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_cistruct iw_cm_event {
2462306a36Sopenharmony_ci	enum iw_cm_event_type event;
2562306a36Sopenharmony_ci	int			 status;
2662306a36Sopenharmony_ci	struct sockaddr_storage local_addr;
2762306a36Sopenharmony_ci	struct sockaddr_storage remote_addr;
2862306a36Sopenharmony_ci	void *private_data;
2962306a36Sopenharmony_ci	void *provider_data;
3062306a36Sopenharmony_ci	u8 private_data_len;
3162306a36Sopenharmony_ci	u8 ord;
3262306a36Sopenharmony_ci	u8 ird;
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/**
3662306a36Sopenharmony_ci * iw_cm_handler - Function to be called by the IW CM when delivering events
3762306a36Sopenharmony_ci * to the client.
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci * @cm_id: The IW CM identifier associated with the event.
4062306a36Sopenharmony_ci * @event: Pointer to the event structure.
4162306a36Sopenharmony_ci */
4262306a36Sopenharmony_citypedef int (*iw_cm_handler)(struct iw_cm_id *cm_id,
4362306a36Sopenharmony_ci			     struct iw_cm_event *event);
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/**
4662306a36Sopenharmony_ci * iw_event_handler - Function called by the provider when delivering provider
4762306a36Sopenharmony_ci * events to the IW CM.  Returns either 0 indicating the event was processed
4862306a36Sopenharmony_ci * or -errno if the event could not be processed.
4962306a36Sopenharmony_ci *
5062306a36Sopenharmony_ci * @cm_id: The IW CM identifier associated with the event.
5162306a36Sopenharmony_ci * @event: Pointer to the event structure.
5262306a36Sopenharmony_ci */
5362306a36Sopenharmony_citypedef int (*iw_event_handler)(struct iw_cm_id *cm_id,
5462306a36Sopenharmony_ci				 struct iw_cm_event *event);
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_cistruct iw_cm_id {
5762306a36Sopenharmony_ci	iw_cm_handler		cm_handler;      /* client callback function */
5862306a36Sopenharmony_ci	void		        *context;	 /* client cb context */
5962306a36Sopenharmony_ci	struct ib_device	*device;
6062306a36Sopenharmony_ci	struct sockaddr_storage local_addr;      /* local addr */
6162306a36Sopenharmony_ci	struct sockaddr_storage	remote_addr;
6262306a36Sopenharmony_ci	struct sockaddr_storage m_local_addr;	 /* nmapped local addr */
6362306a36Sopenharmony_ci	struct sockaddr_storage	m_remote_addr;	 /* nmapped rem addr */
6462306a36Sopenharmony_ci	void			*provider_data;	 /* provider private data */
6562306a36Sopenharmony_ci	iw_event_handler        event_handler;   /* cb for provider
6662306a36Sopenharmony_ci						    events */
6762306a36Sopenharmony_ci	/* Used by provider to add and remove refs on IW cm_id */
6862306a36Sopenharmony_ci	void (*add_ref)(struct iw_cm_id *);
6962306a36Sopenharmony_ci	void (*rem_ref)(struct iw_cm_id *);
7062306a36Sopenharmony_ci	u8  tos;
7162306a36Sopenharmony_ci	bool tos_set:1;
7262306a36Sopenharmony_ci	bool mapped:1;
7362306a36Sopenharmony_ci	bool afonly:1;
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cistruct iw_cm_conn_param {
7762306a36Sopenharmony_ci	const void *private_data;
7862306a36Sopenharmony_ci	u16 private_data_len;
7962306a36Sopenharmony_ci	u32 ord;
8062306a36Sopenharmony_ci	u32 ird;
8162306a36Sopenharmony_ci	u32 qpn;
8262306a36Sopenharmony_ci};
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cienum iw_flags {
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci	/*
8762306a36Sopenharmony_ci	 * This flag allows the iwcm and iwpmd to still advertise
8862306a36Sopenharmony_ci	 * mappings but the real and mapped port numbers are the
8962306a36Sopenharmony_ci	 * same.  Further, iwpmd will not bind any user socket to
9062306a36Sopenharmony_ci	 * reserve the port.  This is required for soft iwarp
9162306a36Sopenharmony_ci	 * to play in the port mapped iwarp space.
9262306a36Sopenharmony_ci	 */
9362306a36Sopenharmony_ci	IW_F_NO_PORT_MAP = (1 << 0),
9462306a36Sopenharmony_ci};
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/**
9762306a36Sopenharmony_ci * iw_create_cm_id - Create an IW CM identifier.
9862306a36Sopenharmony_ci *
9962306a36Sopenharmony_ci * @device: The IB device on which to create the IW CM identier.
10062306a36Sopenharmony_ci * @event_handler: User callback invoked to report events associated with the
10162306a36Sopenharmony_ci *   returned IW CM identifier.
10262306a36Sopenharmony_ci * @context: User specified context associated with the id.
10362306a36Sopenharmony_ci */
10462306a36Sopenharmony_cistruct iw_cm_id *iw_create_cm_id(struct ib_device *device,
10562306a36Sopenharmony_ci				 iw_cm_handler cm_handler, void *context);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/**
10862306a36Sopenharmony_ci * iw_destroy_cm_id - Destroy an IW CM identifier.
10962306a36Sopenharmony_ci *
11062306a36Sopenharmony_ci * @cm_id: The previously created IW CM identifier to destroy.
11162306a36Sopenharmony_ci *
11262306a36Sopenharmony_ci * The client can assume that no events will be delivered for the CM ID after
11362306a36Sopenharmony_ci * this function returns.
11462306a36Sopenharmony_ci */
11562306a36Sopenharmony_civoid iw_destroy_cm_id(struct iw_cm_id *cm_id);
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/**
11862306a36Sopenharmony_ci * iw_cm_listen - Listen for incoming connection requests on the
11962306a36Sopenharmony_ci * specified IW CM id.
12062306a36Sopenharmony_ci *
12162306a36Sopenharmony_ci * @cm_id: The IW CM identifier.
12262306a36Sopenharmony_ci * @backlog: The maximum number of outstanding un-accepted inbound listen
12362306a36Sopenharmony_ci *   requests to queue.
12462306a36Sopenharmony_ci *
12562306a36Sopenharmony_ci * The source address and port number are specified in the IW CM identifier
12662306a36Sopenharmony_ci * structure.
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_ciint iw_cm_listen(struct iw_cm_id *cm_id, int backlog);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci/**
13162306a36Sopenharmony_ci * iw_cm_accept - Called to accept an incoming connect request.
13262306a36Sopenharmony_ci *
13362306a36Sopenharmony_ci * @cm_id: The IW CM identifier associated with the connection request.
13462306a36Sopenharmony_ci * @iw_param: Pointer to a structure containing connection establishment
13562306a36Sopenharmony_ci *   parameters.
13662306a36Sopenharmony_ci *
13762306a36Sopenharmony_ci * The specified cm_id will have been provided in the event data for a
13862306a36Sopenharmony_ci * CONNECT_REQUEST event. Subsequent events related to this connection will be
13962306a36Sopenharmony_ci * delivered to the specified IW CM identifier prior and may occur prior to
14062306a36Sopenharmony_ci * the return of this function. If this function returns a non-zero value, the
14162306a36Sopenharmony_ci * client can assume that no events will be delivered to the specified IW CM
14262306a36Sopenharmony_ci * identifier.
14362306a36Sopenharmony_ci */
14462306a36Sopenharmony_ciint iw_cm_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci/**
14762306a36Sopenharmony_ci * iw_cm_reject - Reject an incoming connection request.
14862306a36Sopenharmony_ci *
14962306a36Sopenharmony_ci * @cm_id: Connection identifier associated with the request.
15062306a36Sopenharmony_ci * @private_daa: Pointer to data to deliver to the remote peer as part of the
15162306a36Sopenharmony_ci *   reject message.
15262306a36Sopenharmony_ci * @private_data_len: The number of bytes in the private_data parameter.
15362306a36Sopenharmony_ci *
15462306a36Sopenharmony_ci * The client can assume that no events will be delivered to the specified IW
15562306a36Sopenharmony_ci * CM identifier following the return of this function. The private_data
15662306a36Sopenharmony_ci * buffer is available for reuse when this function returns.
15762306a36Sopenharmony_ci */
15862306a36Sopenharmony_ciint iw_cm_reject(struct iw_cm_id *cm_id, const void *private_data,
15962306a36Sopenharmony_ci		 u8 private_data_len);
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/**
16262306a36Sopenharmony_ci * iw_cm_connect - Called to request a connection to a remote peer.
16362306a36Sopenharmony_ci *
16462306a36Sopenharmony_ci * @cm_id: The IW CM identifier for the connection.
16562306a36Sopenharmony_ci * @iw_param: Pointer to a structure containing connection  establishment
16662306a36Sopenharmony_ci *   parameters.
16762306a36Sopenharmony_ci *
16862306a36Sopenharmony_ci * Events may be delivered to the specified IW CM identifier prior to the
16962306a36Sopenharmony_ci * return of this function. If this function returns a non-zero value, the
17062306a36Sopenharmony_ci * client can assume that no events will be delivered to the specified IW CM
17162306a36Sopenharmony_ci * identifier.
17262306a36Sopenharmony_ci */
17362306a36Sopenharmony_ciint iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param);
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci/**
17662306a36Sopenharmony_ci * iw_cm_disconnect - Close the specified connection.
17762306a36Sopenharmony_ci *
17862306a36Sopenharmony_ci * @cm_id: The IW CM identifier to close.
17962306a36Sopenharmony_ci * @abrupt: If 0, the connection will be closed gracefully, otherwise, the
18062306a36Sopenharmony_ci *   connection will be reset.
18162306a36Sopenharmony_ci *
18262306a36Sopenharmony_ci * The IW CM identifier is still active until the IW_CM_EVENT_CLOSE event is
18362306a36Sopenharmony_ci * delivered.
18462306a36Sopenharmony_ci */
18562306a36Sopenharmony_ciint iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt);
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci/**
18862306a36Sopenharmony_ci * iw_cm_init_qp_attr - Called to initialize the attributes of the QP
18962306a36Sopenharmony_ci * associated with a IW CM identifier.
19062306a36Sopenharmony_ci *
19162306a36Sopenharmony_ci * @cm_id: The IW CM identifier associated with the QP
19262306a36Sopenharmony_ci * @qp_attr: Pointer to the QP attributes structure.
19362306a36Sopenharmony_ci * @qp_attr_mask: Pointer to a bit vector specifying which QP attributes are
19462306a36Sopenharmony_ci *   valid.
19562306a36Sopenharmony_ci */
19662306a36Sopenharmony_ciint iw_cm_init_qp_attr(struct iw_cm_id *cm_id, struct ib_qp_attr *qp_attr,
19762306a36Sopenharmony_ci		       int *qp_attr_mask);
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci/**
20062306a36Sopenharmony_ci * iwcm_reject_msg - return a pointer to a reject message string.
20162306a36Sopenharmony_ci * @reason: Value returned in the REJECT event status field.
20262306a36Sopenharmony_ci */
20362306a36Sopenharmony_ciconst char *__attribute_const__ iwcm_reject_msg(int reason);
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci#endif /* IW_CM_H */
206