[openib-general][PATCH][RFC]: CMA header

Guy German guyg at voltaire.com
Mon Sep 19 07:55:30 PDT 2005


/*
 * Copyright (c) 2005 Voltaire Inc.  All rights reserved.
 *
 * This Software is licensed under one of the following licenses:
 *
 * 1) under the terms of the "Common Public License 1.0" a copy of which is
 *    available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/cpl.php.
 *
 * 2) under the terms of the "The BSD License" a copy of which is
 *    available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/bsd-license.php.
 *
 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
 *    copy of which is available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/gpl-license.php.
 *
 * Licensee has the right to choose one of the above licenses.
 *
 * Redistributions of source code must retain the above copyright
 * notice and one of the license notices.
 *
 * Redistributions in binary form must reproduce both the above copyright
 * notice, one of the license notices in the documentation
 * and/or other materials provided with the distribution.
 *
 */

/*
 *  - for calling accept/reject or disconnect on the passive side you need to 
 *    use the cma handle accepted in ib_cma_listen cb.
 *  - cma_id is created when calling connect or listen and destroyed when 
 *    accepting disconnected/rejected/unreachable events on either active
 *    side (connect cb) or passive side (accept cb)
 */

#ifndef IB_CMA_H
#define IB_CMA_H

#include <linux/socket.h>
#include <linux/in.h>
#include <rdma/ib_verbs.h>

enum ib_cma_event {
	IB_CMA_EVENT_ESTABLISHED = 1,
	IB_CMA_EVENT_REJECTED,
	IB_CMA_EVENT_NON_PEER_REJECTED,
	IB_CMA_EVENT_DISCONNECTED,
	IB_CMA_EVENT_UNREACHABLE
};

enum ib_qos {
	IB_QOS_BEST_EFFORT = 0,
	IB_QOS_HIGH_THROUGHPUT = (1 << 0),
	IB_QOS_LOW_LATENCY = (1 << 1),
	IB_QOS_ECONOMY = (1 << 2),
	IB_QOS_PREMIUM = (1 << 3)
};

enum ib_connect_flags {
	IB_CONNECT_DEFAULT_FLAG = 0x00,
	IB_CONNECT_MULTIPATH_FLAG = 0x01
};

typedef void (*ib_cma_addr_handler)(struct sockaddr *src_ip, void *context);
typedef void (*ib_cma_ac_handler)(enum ib_cma_event event, void *context);
typedef void (*ib_cma_event_handler)(enum ib_cma_event event, void *context,
				     const void *private_data);
typedef void (*ib_cma_listen_handler)(void *cma_id, struct ib_device *device,
				      void *private_data, void *context);

struct ib_cma_conn {
	struct ib_qp *qp;
	struct ib_qp_attr *qp_attr;
	struct sockaddr *dst_ip;
	__be64 service_id;
	struct ib_device *device;
	void *context;
	ib_cma_event_handler cma_event_handler;
	const void *private_data;
	u8 private_data_len;
	enum ib_qos qos;
	enum ib_connect_flags connect_flags;
};

/**
 * ib_cma_get_device - Returns the device and port to be used according 
 *   to the destination ip address (this can be detemined according 
 *   to the local routing table). Call this function before 
 *   creating the qp. If using link-local IPv6 addresses
 *   there is no need to call this function.
 * @remote_address - The destination address for connection
 * @qos - desired quality of service
 * @device - The device to use (output)
 * @port - port to use (output)
 *
 */
int ib_cma_get_device(struct sockaddr *remote_address,
		      enum ib_qos qos, struct ib_device **device, u8 *port);


/**
 * ib_cma_create_qp - creates and returns a qp for a specified pd and port
 *   and modifies it to be in the init state.
 * @pd - The protection domain associated with the QP, created on the device
 *   retreived by ib_cma_get_device
 * @port - The port to use in modify to init operation
 * @qp - The qp created (out)
 * @init_attr - attributes for qp creation
 */
int ib_cma_create_qp(struct ib_pd *pd, u8 port, struct ib_qp **qp,
		     struct ib_qp_init_attr *init_attr);


/**
 * ib_cma_connect - this is the connect request function, called by 
 *   the active side. The consumer registers an upcall that will be 
 *   initiated by the cma with an appropriate connection event 
 *   notification (established/rejected/disconnected etc)
 * @cma_conn: This structure contains the following connection parameters:
 *   @qp: qp for establishing the connection
 *   @qp_attr: only relevant attributes are used
 *   @dst_ip: destination ip address
 *   @service_id: destination service id (port)
 *   @context: context to be returned in the callback
 *   @cma_event_handler: the upcall function for the active side
 *   @private_data: private data to be received at the listener upcall
 *   @private_data_len: private data length (max 255)
 *   @qos: Quality os service for the rc
 *   @connect_flags: default or multipath connection
 * @cma_id: This returned handle is a void* (different in ib and iwarp)
 *   in ib - it is pointer to struct cma_context.
 */
int ib_cma_connect(struct ib_cma_conn *cma_conn, void **cma_id);


/**
 * ib_cma_disconnect - this function disconnects the rc. It can be 
 *   called, by either the passive or active side
 * @qp: the connected qp to disconnect
 * @cma_id: On the active side- this handle is the one returned 
 *   when ib_cma_connect was called.
 *   On the passive side- this handle was accepted in cma_listen callback
 */
int ib_cma_disconnect(struct ib_qp *qp, void *cma_id);


/**
 * ib_cma_listen - this function is called by the passive side. It is
 *   listening on a the specified port (ib service id) for incomming 
 *   connection requests
 * @device:
 * @address:
 * @service_id: service id (port) to listen on
 * @context: user context to be returned in the callback
 * @cm_listen_handler: the listen callback 
 * @cma_id: cma handle for the passive side
 */
int ib_cma_listen(struct ib_device *device, struct sockaddr *address,
		  __be64 service_id, void *context,
		  ib_cma_listen_handler cm_listen_handler,
		  void **cma_id);


/**
 * ib_cma_destroy - this functionis is called on the passive side, to 
 *   stop listenning on a certain sevice id
 * @cma_id: the same cma handle received when ib_cma_sid_listen was called
 */
int ib_cma_destroy(void *cma_id);


/**
 * ib_cma_accept - call on the passive side to accept a connection request
 *   note that if the function returned with error - a reject message was
 *   sent to the remote side and the cma_id was destroyed
 * @cma_id: pass the handle that was returned in cma_listen callback for
 *   this connection
 * @qp: the connection's qp
 * @private_data: private data to send back to the initiator
 * @private_data_len: private data length
 * @context: user context to be returned in the callback
 * @cm_accept_handler: the cma accept callback - triggered when RTU ack
 *   received
 */
int ib_cma_accept(void *cma_id, struct ib_qp *qp, 
		  const void *private_data, u8 private_data_len,
		  void *context, ib_cma_ac_handler cm_accept_handler);

/**
 * ib_cma_reject - call on the passive side to reject a connection request.
 *   This call destroys the cma_id, hence when the active side accepts
 *   the reject the cma_id is already destroyed.
 * @cma_id: this handle was accepted in cma_listen callback
 * @private_data: private data to send back to the initiator
 * @private_data_len: private data length
 */
int ib_cma_reject(void *cma_id, const void *private_data,
		  u8 private_data_len);


/**
 * ib_cma_get_src_ip - this function asynchronicly finds
 *   src ip from cma_id
 * @cma_id: the cma_id will have to include the path data received 
 *   in the request handler
 * @src_ip: source ip of the initiator
 */
int ib_cma_get_src_ip(void *cma_id, ib_cma_addr_handler addr_handler,
		      void *context);

#endif /* IB_CMA_H */

5~



More information about the general mailing list