[openib-general] [PATCH] initial CM module
Sean Hefty
mshefty at ichips.intel.com
Thu Dec 16 11:55:56 PST 2004
This patch adds in the initial CM API and module code. The module loads,
unloads, and allocates/deallocates connection structures, but that's about it.
This patch does not include changes needed to Kconfig or the Makefile, since I'm
not sure that it makes sense to change these yet.
I will commit this unless there are any objections.
- Sean
Index: include/ib_cm.h
===================================================================
--- include/ib_cm.h (revision 0)
+++ include/ib_cm.h (revision 0)
@@ -0,0 +1,387 @@
+/*
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available at
+ * <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
+ * license, available in the LICENSE.TXT file accompanying this
+ * software. These details are also available at
+ * <http://openib.org/license.html>.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Copyright (c) 2004 Intel Corporation. All rights reserved.
+ * Copyright (c) 2004 Topspin Corporation. All rights reserved.
+ * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
+ *
+ * $Id$
+ */
+#if !defined(IB_CM_H)
+#define IB_CM_H
+
+#include <ib_mad.h>
+#include <ib_sa.h>
+
+enum ib_cm_state {
+ IB_CM_IDLE,
+ IB_CM_LISTEN,
+ IB_CM_REQ_SENT,
+ IB_CM_REQ_RCVD,
+ IB_CM_MRA_REQ_SENT,
+ IB_CM_MRA_REQ_RCVD,
+ IB_CM_REP_SENT,
+ IB_CM_REP_RCVD,
+ IB_CM_MRA_REP_SENT,
+ IB_CM_MRA_REP_RCVD,
+ IB_CM_ESTABLISHED,
+ IB_CM_LAP_SENT,
+ IB_CM_LAP_RCVD,
+ IB_CM_MRA_LAP_SENT,
+ IB_CM_MRA_LAP_RCVD,
+ IB_CM_DREQ_SENT,
+ IB_CM_DREQ_RCVD,
+ IB_CM_TIMEWAIT,
+ IB_CM_SIDR_REQ_SENT,
+ IB_CM_SIDR_REQ_RCVD
+};
+
+enum ib_cm_event_type {
+ IB_CM_REQ_TIMEOUT,
+ IB_CM_REQ_RECEIVED,
+ IB_CM_REP_TIMEOUT,
+ IB_CM_REP_RECEIVED,
+ IB_CM_RTU_RECEIVED,
+ IB_CM_DREQ_TIMEOUT,
+ IB_CM_DREQ_RECEIVED,
+ IB_CM_DREP_RECEIVED,
+ IB_CM_MRA_RECEIVED,
+ IB_CM_LAP_TIMEOUT,
+ IB_CM_LAP_RECEIVED,
+ IB_CM_APR_RECEIVED
+};
+
+struct ib_cm_event {
+ /* a whole lot more stuff goes here */
+ void *private_data;
+ u8 private_data_len;
+ enum ib_cm_event_type event;
+};
+
+struct ib_cm_id;
+
+typedef void (*ib_cm_handler)(struct ib_cm_id *cm_id,
+ struct ib_cm_event *event);
+
+struct ib_cm_id {
+ ib_cm_handler cm_handler;
+ void *context;
+ u64 service_id;
+ enum ib_cm_state state;
+};
+
+/**
+ * ib_create_cm_id - Allocate a connection identifier.
+ * @cm_handler: Callback invoked to notify the user of CM events.
+ * @context: User specified context associated with the connection
+ * identifier.
+ *
+ * Connection identifiers are used to track connection states and
+ * listen requests.
+ */
+struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler,
+ void *context);
+
+/**
+ * ib_destroy_cm_id - Destroy a connection identifier.
+ * @cm_id: Connection identifier to destroy.
+ *
+ * This call blocks until the connection identifier is destroyed.
+ */
+int ib_destroy_cm_id(struct ib_cm_id *cm_id);
+//*** TBD : add flags to allow calling routine from CM callback...
+
+/**
+ * ib_cm_listen - Initiates listening on the specified service ID for
+ * connection and service ID resolution requests.
+ * @cm_id: Connection identifier associated with the listen request.
+ * @service_id: Service identifier matched against incoming connection
+ * and service ID resolution requests.
+ * @service_mask: Mask applied to service ID used to listen across a
+ * range of service IDs.
+ */
+int ib_cm_listen(struct ib_cm_id *cm_id,
+ u64 service_id,
+ u64 service_mask);
+
+struct ib_cm_req_param {
+ struct ib_qp *qp;
+ struct ib_path_record *primary_path;
+ struct ib_path_record *alternate_path;
+ u64 service_id;
+ int timeout_ms;
+ void *private_data;
+ u8 private_data_len;
+ u8 responder_resources;
+ u8 initiator_depth;
+ u8 remote_cm_response_timeout;
+ u8 flow_control;
+ u8 local_cm_response_timeout;
+ u8 retry_count;
+ u8 rnr_retry_count;
+ u8 max_cm_retries;
+};
+
+/**
+ * ib_send_cm_req - Sends a connection request to the remote node.
+ * @cm_id: Connection identifier that will be associated with the
+ * connection request.
+ * @param: Connection request information needed to establish the
+ * connection.
+ */
+int ib_send_cm_req(struct ib_cm_id *cm_id,
+ struct ib_cm_req_param *param);
+
+struct ib_cm_rep_param {
+ struct ib_qp *qp;
+ void *private_data;
+ u8 reply_private_data_len;
+ u8 responder_resources;
+ u8 initiator_depth;
+ u8 target_ack_delay;
+ u8 failover_accepted;
+ u8 flow_control;
+ u8 rnr_retry_count;
+};
+
+/**
+ * ib_send_cm_rep - Sends a connection reply in response to a connection
+ * request.
+ * @cm_id: Connection identifier that will be associated with the
+ * connection request.
+ * @param: Connection reply information needed to establish the
+ * connection.
+ */
+int ib_send_cm_rep(struct ib_cm_id *cm_id,
+ struct ib_cm_req_param *param);
+
+/**
+ * ib_send_cm_rtu - Sends a connection ready to use message in response
+ * to a connection reply message.
+ * @cm_id: Connection identifier associated with the connection request.
+ * @private_data: Optional user-defined private data sent with the
+ * ready to use message.
+ * @private_data_len: Size of the private data buffer, in bytes.
+ */
+int ib_send_cm_rtu(struct ib_cm_id *cm_id,
+ void *private_data,
+ u8 private_data_len);
+
+/**
+ * ib_send_cm_dreq - Sends a disconnection request for an existing
+ * connection.
+ * @cm_id: Connection identifier associated with the connection being
+ * released.
+ * @private_data: Optional user-defined private data sent with the
+ * disconnection request message.
+ * @private_data_len: Size of the private data buffer, in bytes.
+ */
+int ib_send_cm_dreq(struct ib_cm_id *cm_id,
+ void *private_data,
+ u8 private_data_len);
+
+/**
+ * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
+ * @cm_id: Connection identifier associated with the connection being
+ * released.
+ * @private_data: Optional user-defined private data sent with the
+ * disconnection reply message.
+ * @private_data_len: Size of the private data buffer, in bytes.
+ */
+int ib_send_cm_drep(struct ib_cm_id *cm_id,
+ void *private_data,
+ u8 private_data_len);
+
+/**
+ * ib_cm_establish - Forces a connection state to established.
+ * @cm_id: Connection identifier to transition to established.
+ *
+ * This routine should be invoked by users who receive messages on a
+ * connected QP before an RTU has been received.
+ */
+int ib_cm_establish(struct ib_cm_id *id);
+
+enum ib_cm_rej_reason {
+ IB_CM_REJ_NO_QP = __constant_htons(1),
+ IB_CM_REJ_NO_EEC = __constant_htons(2),
+ IB_CM_REJ_NO_RESOURCES = __constant_htons(3),
+ IB_CM_REJ_TIMEOUT = __constant_htons(4),
+ IB_CM_REJ_UNSUPPORTED = __constant_htons(5),
+ IB_CM_REJ_INVALID_COMM_ID = __constant_htons(6),
+ IB_CM_REJ_INVALID_COMM_INSTANCE = __constant_htons(7),
+ IB_CM_REJ_INVALID_SERVICE_ID = __constant_htons(8),
+ IB_CM_REJ_INVALID_TRANSPORT_TYPE = __constant_htons(9),
+ IB_CM_REJ_STALE_CONN = __constant_htons(10),
+ IB_CM_REJ_RDC_NOT_EXIST = __constant_htons(11),
+ IB_CM_REJ_INVALID_GID = __constant_htons(12),
+ IB_CM_REJ_INVALID_LID = __constant_htons(13),
+ IB_CM_REJ_INVALID_SL = __constant_htons(14),
+ IB_CM_REJ_INVALID_TRAFFIC_CLASS = __constant_htons(15),
+ IB_CM_REJ_INVALID_HOP_LIMIT = __constant_htons(16),
+ IB_CM_REJ_INVALID_PACKET_RATE = __constant_htons(17),
+ IB_CM_REJ_INVALID_ALT_GID = __constant_htons(18),
+ IB_CM_REJ_INVALID_ALT_LID = __constant_htons(19),
+ IB_CM_REJ_INVALID_ALT_SL = __constant_htons(20),
+ IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = __constant_htons(21),
+ IB_CM_REJ_INVALID_ALT_HOP_LIMIT = __constant_htons(22),
+ IB_CM_REJ_INVALID_ALT_PACKET_RATE = __constant_htons(23),
+ IB_CM_REJ_PORT_REDIRECT = __constant_htons(24),
+ IB_CM_REJ_INVALID_MTU = __constant_htons(26),
+ IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = __constant_htons(27),
+ IB_CM_REJ_CONSUMER_DEFINED = __constant_htons(28),
+ IB_CM_REJ_INVALID_RNR_RETRY = __constant_htons(29),
+ IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = __constant_htons(30),
+ IB_CM_REJ_INVALID_CLASS_VERSION = __constant_htons(31),
+ IB_CM_REJ_INVALID_FLOW_LABEL = __constant_htons(32),
+ IB_CM_REJ_INVALID_ALT_FLOW_LABEL = __constant_htons(33)
+};
+
+/**
+ * ib_send_cm_rej - Sends a connection rejection message to the
+ * remote node.
+ * @cm_id: Connection identifier associated with the connection being
+ * rejected.
+ * @reason: Reason for the connection request rejection.
+ * @ari: Optional additional rejection information.
+ * @ari_length: Size of the additional rejection information, in bytes.
+ * @private_data: Optional user-defined private data sent with the
+ * rejection message.
+ * @private_data_len: Size of the private data buffer, in bytes.
+ */
+int ib_send_cm_rej(struct ib_cm_id *cm_id,
+ enum ib_cm_rej_reason reason,
+ void *ari,
+ u8 ari_length,
+ void *private_data,
+ u8 private_data_len);
+
+/**
+ * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
+ * message.
+ * @cm_id: Connection identifier associated with the connection message.
+ * @service_timeout: The maximum time required for the sender to reply to
+ * to the connection message.
+ * @private_data: Optional user-defined private data sent with the
+ * message receipt acknowledgement.
+ * @private_data_len: Size of the private data buffer, in bytes.
+ */
+int ib_send_cm_mra(struct ib_cm_id *cm_id,
+ u8 service_timeout,
+ void *private_data,
+ u8 private_data_len);
+
+/**
+ * ib_send_cm_lap - Sends a load alternate path request.
+ * @cm_id: Connection identifier associated with the load alternate path
+ * message.
+ * @alternate_path: A path record that identifies the alternate path to
+ * load.
+ * @private_data: Optional user-defined private data sent with the
+ * load alternate path message.
+ * @private_data_len: Size of the private data buffer, in bytes.
+ */
+int ib_send_cm_lap(struct ib_cm_id *cm_id,
+ struct ib_path_record *alternate_path,
+ void *private_data,
+ u8 private_data_len);
+
+enum ib_cm_apr_status {
+ IB_CM_APR_SUCCESS,
+ IB_CM_APR_INVALID_COMM_ID,
+ IB_CM_APR_UNSUPPORTED,
+ IB_CM_APR_REJECT,
+ IB_CM_APR_REDIRECT,
+ IB_CM_APR_IS_CURRENT,
+ IB_CM_APR_INVALID_QPN_EECN,
+ IB_CM_APR_INVALID_LID,
+ IB_CM_APR_INVALID_GID,
+ IB_CM_APR_INVALID_FLOW_LABEL,
+ IB_CM_APR_INVALID_TCLASS,
+ IB_CM_APR_INVALID_HOP_LIMIT,
+ IB_CM_APR_INVALID_PACKET_RATE,
+ IB_CM_APR_INVALID_SL
+};
+
+/**
+ * ib_send_cm_apr - Sends an alternate path response message in response to
+ * a load alternate path request.
+ * @cm_id: Connection identifier associated with the alternate path response.
+ * @status: Reply status sent with the alternate path response.
+ * @info: Optional additional information sent with the alternate path
+ * response.
+ * @info_length: Size of the additional information, in bytes.
+ * @private_data: Optional user-defined private data sent with the
+ * alternate path response message.
+ * @private_data_len: Size of the private data buffer, in bytes.
+ */
+int ib_send_cm_apr(struct ib_cm_id *cm_id,
+ enum ib_cm_apr_status status,
+ void *info,
+ u8 info_length,
+ void *private_data,
+ u8 private_data_len);
+
+struct ib_cm_sidr_req_param {
+ struct ib_path_record *path;
+ u64 service_id;
+ int timeout_ms;
+ void *private_data;
+ u8 private_data_len;
+ u16 pkey;
+};
+
+/**
+ * ib_send_cm_sidr_req - Sends a service ID resolution request to the
+ * remote node.
+ * @cm_id: Communication identifier that will be associated with the
+ * service ID resolution request.
+ * @param: Service ID resolution request information.
+ */
+int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
+ struct ib_cm_sidr_req_param *param);
+
+enum ib_cm_sidr_status {
+ IB_SIDR_SUCCESS,
+ IB_SIDR_UNSUPPORTED,
+ IB_SIDR_REJECT,
+ IB_SIDR_NO_QP,
+ IB_SIDR_REDIRECT,
+ IB_SIDR_UNSUPPORTED_VERSION
+};
+
+struct ib_cm_sidr_rep_param {
+ u32 qp_num;
+ u32 qkey;
+ enum ib_cm_sidr_status status;
+ void *info;
+ u8 info_length;
+ void *private_data;
+ u8 private_data_len;
+};
+
+/**
+ * ib_send_cm_sidr_rep - Sends a service ID resolution request to the
+ * remote node.
+ * @cm_id: Communication identifier associated with the received service ID
+ * resolution request.
+ * @param: Service ID resolution reply information.
+ */
+int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
+ struct ib_cm_sidr_rep_param *param);
+
+#endif /* IB_CM_H */
Index: core/cm.c
===================================================================
--- core/cm.c (revision 0)
+++ core/cm.c (revision 0)
@@ -0,0 +1,292 @@
+/*
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available at
+ * <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
+ * license, available in the LICENSE.TXT file accompanying this
+ * software. These details are also available at
+ * <http://openib.org/license.html>.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Copyright (c) 2004 Intel Corporation. All rights reserved.
+ * Copyright (c) 2004 Topspin Corporation. All rights reserved.
+ * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
+ *
+ * $Id$
+ */
+#include <linux/err.h>
+#include <linux/spinlock.h>
+
+#include <ib_cm.h>
+
+MODULE_AUTHOR("Sean Hefty");
+MODULE_DESCRIPTION("InfiniBand CM");
+MODULE_LICENSE("Dual BSD/GPL");
+
+static void cm_add_one(struct ib_device *device);
+static void cm_remove_one(struct ib_device *device);
+
+static struct ib_client cm_client = {
+ .name = "cm",
+ .add = cm_add_one,
+ .remove = cm_remove_one
+};
+
+struct cm_port {
+ struct ib_mad_agent *mad_agent;
+};
+
+struct ib_cm_id_private {
+ struct ib_cm_id id;
+
+ spinlock_t lock;
+ wait_queue_head_t wait;
+ atomic_t refcount;
+};
+
+struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler,
+ void *context)
+{
+ struct ib_cm_id_private *cm_id_priv;
+
+ cm_id_priv = kmalloc(sizeof *cm_id_priv, GFP_KERNEL);
+ if (!cm_id_priv)
+ return ERR_PTR(-ENOMEM);
+
+ cm_id_priv->id.service_id = 0;
+ cm_id_priv->id.state = IB_CM_IDLE;
+ cm_id_priv->id.cm_handler = cm_handler;
+ cm_id_priv->id.context = context;
+
+ spin_lock_init(&cm_id_priv->lock);
+ init_waitqueue_head(&cm_id_priv->wait);
+ atomic_set(&cm_id_priv->refcount, 1);
+
+ return &cm_id_priv->id;
+}
+EXPORT_SYMBOL(ib_create_cm_id);
+
+static void reset_cm_state(struct ib_cm_id_private *cm_id_priv)
+{
+ /* reject connections if establishing */
+ /* disconnect established connections */
+ /* update timewait info */
+}
+
+int ib_destroy_cm_id(struct ib_cm_id *cm_id)
+{
+ struct ib_cm_id_private *cm_id_priv;
+ unsigned long flags;
+
+ cm_id_priv = container_of(cm_id, struct ib_cm_id_private, id);
+
+ spin_lock_irqsave(&cm_id_priv->lock, flags);
+ switch(cm_id->state) {
+ case IB_CM_IDLE:
+ case IB_CM_LISTEN:
+ case IB_CM_TIMEWAIT:
+ break; /* Connection is ready to be destroyed. */
+ default:
+ reset_cm_state(cm_id_priv);
+ break;
+ }
+ cm_id->state = IB_CM_IDLE;
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+ atomic_dec(&cm_id_priv->refcount);
+ wait_event(cm_id_priv->wait,
+ !atomic_read(&cm_id_priv->refcount));
+ kfree(cm_id_priv);
+ return 0;
+}
+EXPORT_SYMBOL(ib_destroy_cm_id);
+
+int ib_cm_listen(struct ib_cm_id *cm_id,
+ u64 service_id,
+ u64 service_mask)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_cm_listen);
+
+int ib_send_cm_req(struct ib_cm_id *cm_id,
+ struct ib_cm_req_param *param)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_req);
+
+int ib_send_cm_rep(struct ib_cm_id *cm_id,
+ struct ib_cm_req_param *param)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_rep);
+
+int ib_send_cm_rtu(struct ib_cm_id *cm_id,
+ void *private_data,
+ u8 private_data_len)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_rtu);
+
+int ib_send_cm_dreq(struct ib_cm_id *cm_id,
+ void *private_data,
+ u8 private_data_len)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_dreq);
+
+int ib_send_cm_drep(struct ib_cm_id *cm_id,
+ void *private_data,
+ u8 private_data_len)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_drep);
+
+int ib_cm_establish(struct ib_cm_id *id)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_cm_establish);
+
+int ib_send_cm_rej(struct ib_cm_id *cm_id,
+ enum ib_cm_rej_reason reason,
+ void *ari,
+ u8 ari_length,
+ void *private_data,
+ u8 private_data_len)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_rej);
+
+int ib_send_cm_mra(struct ib_cm_id *cm_id,
+ u8 service_timeout,
+ void *private_data,
+ u8 private_data_len)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_mra);
+
+int ib_send_cm_lap(struct ib_cm_id *cm_id,
+ struct ib_path_record *alternate_path,
+ void *private_data,
+ u8 private_data_len)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_lap);
+
+int ib_send_cm_apr(struct ib_cm_id *cm_id,
+ enum ib_cm_apr_status status,
+ void *info,
+ u8 info_length,
+ void *private_data,
+ u8 private_data_len)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_apr);
+
+int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
+ struct ib_cm_sidr_req_param *param)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_sidr_req);
+
+int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
+ struct ib_cm_sidr_rep_param *param)
+{
+ return -EINVAL;
+}
+EXPORT_SYMBOL(ib_send_cm_sidr_rep);
+
+static void send_handler(struct ib_mad_agent *mad_agent,
+ struct ib_mad_send_wc *mad_send_wc)
+{
+ struct cm_port *port;
+
+ port = (struct cm_port *)mad_agent->context;
+}
+
+static void recv_handler(struct ib_mad_agent *mad_agent,
+ struct ib_mad_recv_wc *mad_recv_wc)
+{
+ struct cm_port *port;
+
+ port = (struct cm_port *)mad_agent->context;
+}
+
+static void cm_add_one(struct ib_device *device)
+{
+ struct cm_port *port;
+ struct ib_mad_reg_req reg_req;
+ u8 i;
+
+ port = kmalloc(sizeof *port * device->phys_port_cnt, GFP_KERNEL);
+ if (!port)
+ goto out;
+
+ memset(®_req, 0, sizeof reg_req);
+ reg_req.mgmt_class = IB_MGMT_CLASS_CM;
+ reg_req.mgmt_class_version = 1;
+ set_bit(IB_MGMT_METHOD_GET, reg_req.method_mask);
+ set_bit(IB_MGMT_METHOD_SET, reg_req.method_mask);
+ set_bit(IB_MGMT_METHOD_GET_RESP, reg_req.method_mask);
+ set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask);
+ for (i = 1; i <= device->phys_port_cnt; i++) {
+ port[i].mad_agent = ib_register_mad_agent(device, i,
+ IB_QPT_GSI,
+ ®_req,
+ 0,
+ send_handler,
+ recv_handler,
+ &port[i]);
+ }
+
+out:
+ ib_set_client_data(device, &cm_client, port);
+}
+
+static void cm_remove_one(struct ib_device *device)
+{
+ struct cm_port *port;
+ int i;
+
+ port = (struct cm_port *)ib_get_client_data(device, &cm_client);
+ if (!port)
+ return;
+
+ for (i = 1; i <= device->phys_port_cnt; i++) {
+ if (!IS_ERR(port[i].mad_agent))
+ ib_unregister_mad_agent(port[i].mad_agent);
+ }
+ kfree(port);
+}
+
+static int __init ib_cm_init(void)
+{
+ return ib_register_client(&cm_client);
+}
+
+static void __exit ib_cm_cleanup(void)
+{
+ ib_unregister_client(&cm_client);
+}
+
+module_init(ib_cm_init);
+module_exit(ib_cm_cleanup);
More information about the general
mailing list