[ofa-general] [PATCHv2] IB/core/user_mad.c: Add support for issmdisabled

Hal Rosenstock halr at voltaire.com
Mon Apr 2 12:49:58 PDT 2007


IB/core/user_mad.c: Add support for issmdisabled

(v2 combines the ib_umad_smcap_open/close routines for issm and
issmdisabled)

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index c069ebe..a689c5c 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
- * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2005-2007 Voltaire, Inc. All rights reserved. 
  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
@@ -31,7 +31,6 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: user_mad.c 5596 2006-03-03 01:00:07Z sean.hefty $
  */
 
 #include <linux/module.h>
@@ -92,6 +91,8 @@ struct ib_umad_port {
 
 	struct cdev           *sm_dev;
 	struct class_device   *sm_class_dev;
+	struct cdev           *smdis_dev;
+	struct class_device   *smdis_class_dev;   
 	struct semaphore       sm_sem;
 
 	struct rw_semaphore    mutex;
@@ -782,16 +783,14 @@ static const struct file_operations umad
 	.release 	= ib_umad_close
 };
 
-static int ib_umad_sm_open(struct inode *inode, struct file *filp)
+static int ib_umad_smcap_open(struct file *filp, unsigned portnum,
+			      struct ib_port_modify *props)
 {
 	struct ib_umad_port *port;
-	struct ib_port_modify props = {
-		.set_port_cap_mask = IB_PORT_SM
-	};
 	int ret;
 
 	spin_lock(&port_lock);
-	port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE - IB_UMAD_MAX_PORTS];
+	port = umad_port[portnum];
 	if (port)
 		kref_get(&port->umad_dev->ref);
 	spin_unlock(&port_lock);
@@ -811,7 +810,7 @@ static int ib_umad_sm_open(struct inode
 		}
 	}
 
-	ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props);
+	ret = ib_modify_port(port->ib_dev, port->port_num, 0, props);
 	if (ret) {
 		up(&port->sm_sem);
 		goto fail;
@@ -826,17 +825,14 @@ fail:
 	return ret;
 }
 
-static int ib_umad_sm_close(struct inode *inode, struct file *filp)
+static int ib_umad_smcap_close(struct ib_umad_port *port,
+			       struct ib_port_modify *props)
 {
-	struct ib_umad_port *port = filp->private_data;
-	struct ib_port_modify props = {
-		.clr_port_cap_mask = IB_PORT_SM
-	};
 	int ret = 0;
 
 	down_write(&port->mutex);
 	if (port->ib_dev)
-		ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props);
+		ret = ib_modify_port(port->ib_dev, port->port_num, 0, props);
 	up_write(&port->mutex);
 
 	up(&port->sm_sem);
@@ -846,12 +842,56 @@ static int ib_umad_sm_close(struct inode
 	return ret;
 }
 
+static int ib_umad_sm_open(struct inode *inode, struct file *filp)
+{
+	struct ib_port_modify props = {
+		.set_port_cap_mask = IB_PORT_SM
+	};
+
+	return ib_umad_smcap_open(filp, iminor(inode) - IB_UMAD_MINOR_BASE - IB_UMAD_MAX_PORTS, &props);
+}
+
+static int ib_umad_sm_close(struct inode *inode, struct file *filp)
+{
+	struct ib_umad_port *port = filp->private_data;
+	struct ib_port_modify props = {
+		.clr_port_cap_mask = IB_PORT_SM
+	};
+
+	return ib_umad_smcap_close(port, &props);
+}
+
 static const struct file_operations umad_sm_fops = {
 	.owner 	 = THIS_MODULE,
 	.open 	 = ib_umad_sm_open,
 	.release = ib_umad_sm_close
 };
 
+static int ib_umad_smdis_open(struct inode *inode, struct file *filp)
+{
+	struct ib_port_modify props = {
+		.set_port_cap_mask = IB_PORT_SM_DISABLED
+	};
+
+	return ib_umad_smcap_open(filp, iminor(inode) - IB_UMAD_MINOR_BASE - 2*IB_UMAD_MAX_PORTS, &props);
+}
+
+static int ib_umad_smdis_close(struct inode *inode, struct file *filp)
+{
+	struct ib_umad_port *port = filp->private_data;
+	struct ib_port_modify props = {
+		.clr_port_cap_mask = IB_PORT_SM_DISABLED
+	};
+
+	return ib_umad_smcap_close(port, &props);
+}
+
+static const struct file_operations umad_smdis_fops = {
+	.owner	 = THIS_MODULE,
+	.open	 = ib_umad_smdis_open,
+	.release = ib_umad_smdis_close
+};
+
 static struct ib_client umad_client = {
 	.name   = "umad",
 	.add    = ib_umad_add_one,
@@ -947,12 +987,41 @@ static int ib_umad_init_port(struct ib_d
 	if (class_device_create_file(port->sm_class_dev, &class_device_attr_port))
 		goto err_sm_class;
 
+	port->smdis_dev = cdev_alloc();
+	if (!port->smdis_dev)
+		goto err_sm_class;
+	port->smdis_dev->owner = THIS_MODULE;
+	port->smdis_dev->ops   = &umad_smdis_fops;
+	kobject_set_name(&port->smdis_dev->kobj, "issmdisabled%d", port->dev_num);
+	if (cdev_add(port->smdis_dev, base_dev + port->dev_num + 2*IB_UMAD_MAX_PORTS, 1))
+		goto err_smdis_cdev;
+
+	port->smdis_class_dev = class_device_create(umad_class, NULL, port->smdis_dev->dev,
+						    device->dma_device,
+						    "issmdisabled%d",
+						    port->dev_num);
+	if (IS_ERR(port->smdis_class_dev))
+                goto err_smdis_cdev;
+
+	class_set_devdata(port->smdis_class_dev, port);
+
+	if (class_device_create_file(port->smdis_class_dev, &class_device_attr_ibdev))
+		goto err_smdis_class;
+	if (class_device_create_file(port->smdis_class_dev, &class_device_attr_port))
+		goto err_smdis_class;
+
 	spin_lock(&port_lock);
 	umad_port[port->dev_num] = port;
 	spin_unlock(&port_lock);
 
 	return 0;
 
+err_smdis_class:
+	class_device_destroy(umad_class, port->smdis_dev->dev);
+
+err_smdis_cdev:
+	cdev_del(port->smdis_dev);
+
 err_sm_class:
 	class_device_destroy(umad_class, port->sm_dev->dev);
 
@@ -979,9 +1048,11 @@ static void ib_umad_kill_port(struct ib_
 
 	class_device_destroy(umad_class, port->dev->dev);
 	class_device_destroy(umad_class, port->sm_dev->dev);
+	class_device_destroy(umad_class, port->smdis_dev->dev);
 
 	cdev_del(port->dev);
 	cdev_del(port->sm_dev);
+	cdev_del(port->smdis_dev);
 
 	spin_lock(&port_lock);
 	umad_port[port->dev_num] = NULL;






More information about the general mailing list