Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[linux-2.6.git] / drivers / infiniband / core / sysfs.c
index 000c086..4d10421 100644 (file)
@@ -30,8 +30,6 @@
  * 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.
- *
- * $Id: sysfs.c 1349 2004-12-16 21:09:43Z roland $
  */
 
 #include "core_priv.h"
@@ -311,7 +309,7 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
                return sprintf(buf, "N/A (no PMA)\n");
 
        in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
-       out_mad = kmalloc(sizeof *in_mad, GFP_KERNEL);
+       out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
        if (!in_mad || !out_mad) {
                ret = -ENOMEM;
                goto out;
@@ -427,28 +425,25 @@ static struct kobj_type port_type = {
        .default_attrs = port_default_attrs
 };
 
-static void ib_device_release(struct class_device *cdev)
+static void ib_device_release(struct device *device)
 {
-       struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
 
        kfree(dev);
 }
 
-static int ib_device_uevent(struct class_device *cdev, char **envp,
-                           int num_envp, char *buf, int size)
+static int ib_device_uevent(struct device *device,
+                           struct kobj_uevent_env *env)
 {
-       struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
-       int i = 0, len = 0;
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
 
-       if (add_uevent_var(envp, num_envp, &i, buf, size, &len,
-                          "NAME=%s", dev->name))
+       if (add_uevent_var(env, "NAME=%s", dev->name))
                return -ENOMEM;
 
        /*
         * It would be nice to pass the node GUID with the event...
         */
 
-       envp[i] = NULL;
        return 0;
 }
 
@@ -479,7 +474,6 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *,
 
                element->attr.attr.name  = element->name;
                element->attr.attr.mode  = S_IRUGO;
-               element->attr.attr.owner = THIS_MODULE;
                element->attr.show       = show;
                element->index           = i;
 
@@ -512,19 +506,10 @@ static int add_port(struct ib_device *device, int port_num)
 
        p->ibdev      = device;
        p->port_num   = port_num;
-       p->kobj.ktype = &port_type;
 
-       p->kobj.parent = kobject_get(&device->ports_parent);
-       if (!p->kobj.parent) {
-               ret = -EBUSY;
-               goto err;
-       }
-
-       ret = kobject_set_name(&p->kobj, "%d", port_num);
-       if (ret)
-               goto err_put;
-
-       ret = kobject_register(&p->kobj);
+       ret = kobject_init_and_add(&p->kobj, &port_type,
+                                  kobject_get(device->ports_parent),
+                                  "%d", port_num);
        if (ret)
                goto err_put;
 
@@ -553,6 +538,7 @@ static int add_port(struct ib_device *device, int port_num)
 
        list_add_tail(&p->kobj.entry, &device->port_list);
 
+       kobject_uevent(&p->kobj, KOBJ_ADD);
        return 0;
 
 err_free_pkey:
@@ -574,16 +560,15 @@ err_remove_pma:
        sysfs_remove_group(&p->kobj, &pma_group);
 
 err_put:
-       kobject_put(&device->ports_parent);
-
-err:
+       kobject_put(device->ports_parent);
        kfree(p);
        return ret;
 }
 
-static ssize_t show_node_type(struct class_device *cdev, char *buf)
+static ssize_t show_node_type(struct device *device,
+                             struct device_attribute *attr, char *buf)
 {
-       struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
 
        if (!ibdev_is_alive(dev))
                return -ENODEV;
@@ -597,9 +582,10 @@ static ssize_t show_node_type(struct class_device *cdev, char *buf)
        }
 }
 
-static ssize_t show_sys_image_guid(struct class_device *cdev, char *buf)
+static ssize_t show_sys_image_guid(struct device *device,
+                                  struct device_attribute *dev_attr, char *buf)
 {
-       struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
        struct ib_device_attr attr;
        ssize_t ret;
 
@@ -617,9 +603,10 @@ static ssize_t show_sys_image_guid(struct class_device *cdev, char *buf)
                       be16_to_cpu(((__be16 *) &attr.sys_image_guid)[3]));
 }
 
-static ssize_t show_node_guid(struct class_device *cdev, char *buf)
+static ssize_t show_node_guid(struct device *device,
+                             struct device_attribute *attr, char *buf)
 {
-       struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
 
        if (!ibdev_is_alive(dev))
                return -ENODEV;
@@ -631,17 +618,19 @@ static ssize_t show_node_guid(struct class_device *cdev, char *buf)
                       be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
 }
 
-static ssize_t show_node_desc(struct class_device *cdev, char *buf)
+static ssize_t show_node_desc(struct device *device,
+                             struct device_attribute *attr, char *buf)
 {
-       struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
 
        return sprintf(buf, "%.64s\n", dev->node_desc);
 }
 
-static ssize_t set_node_desc(struct class_device *cdev, const char *buf,
-                             size_t count)
+static ssize_t set_node_desc(struct device *device,
+                            struct device_attribute *attr,
+                            const char *buf, size_t count)
 {
-       struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
        struct ib_device_modify desc = {};
        int ret;
 
@@ -656,58 +645,167 @@ static ssize_t set_node_desc(struct class_device *cdev, const char *buf,
        return count;
 }
 
-static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
-static CLASS_DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
-static CLASS_DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
-static CLASS_DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc,
-                        set_node_desc);
-
-static struct class_device_attribute *ib_class_attributes[] = {
-       &class_device_attr_node_type,
-       &class_device_attr_sys_image_guid,
-       &class_device_attr_node_guid,
-       &class_device_attr_node_desc
+static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
+static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
+static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
+static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc);
+
+static struct device_attribute *ib_class_attributes[] = {
+       &dev_attr_node_type,
+       &dev_attr_sys_image_guid,
+       &dev_attr_node_guid,
+       &dev_attr_node_desc
 };
 
 static struct class ib_class = {
        .name    = "infiniband",
-       .release = ib_device_release,
-       .uevent = ib_device_uevent,
+       .dev_release = ib_device_release,
+       .dev_uevent = ib_device_uevent,
+};
+
+/* Show a given an attribute in the statistics group */
+static ssize_t show_protocol_stat(const struct device *device,
+                           struct device_attribute *attr, char *buf,
+                           unsigned offset)
+{
+       struct ib_device *dev = container_of(device, struct ib_device, dev);
+       union rdma_protocol_stats stats;
+       ssize_t ret;
+
+       ret = dev->get_protocol_stats(dev, &stats);
+       if (ret)
+               return ret;
+
+       return sprintf(buf, "%llu\n",
+                      (unsigned long long) ((u64 *) &stats)[offset]);
+}
+
+/* generate a read-only iwarp statistics attribute */
+#define IW_STATS_ENTRY(name)                                           \
+static ssize_t show_##name(struct device *device,                      \
+                          struct device_attribute *attr, char *buf)    \
+{                                                                      \
+       return show_protocol_stat(device, attr, buf,                    \
+                                 offsetof(struct iw_protocol_stats, name) / \
+                                 sizeof (u64));                        \
+}                                                                      \
+static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
+
+IW_STATS_ENTRY(ipInReceives);
+IW_STATS_ENTRY(ipInHdrErrors);
+IW_STATS_ENTRY(ipInTooBigErrors);
+IW_STATS_ENTRY(ipInNoRoutes);
+IW_STATS_ENTRY(ipInAddrErrors);
+IW_STATS_ENTRY(ipInUnknownProtos);
+IW_STATS_ENTRY(ipInTruncatedPkts);
+IW_STATS_ENTRY(ipInDiscards);
+IW_STATS_ENTRY(ipInDelivers);
+IW_STATS_ENTRY(ipOutForwDatagrams);
+IW_STATS_ENTRY(ipOutRequests);
+IW_STATS_ENTRY(ipOutDiscards);
+IW_STATS_ENTRY(ipOutNoRoutes);
+IW_STATS_ENTRY(ipReasmTimeout);
+IW_STATS_ENTRY(ipReasmReqds);
+IW_STATS_ENTRY(ipReasmOKs);
+IW_STATS_ENTRY(ipReasmFails);
+IW_STATS_ENTRY(ipFragOKs);
+IW_STATS_ENTRY(ipFragFails);
+IW_STATS_ENTRY(ipFragCreates);
+IW_STATS_ENTRY(ipInMcastPkts);
+IW_STATS_ENTRY(ipOutMcastPkts);
+IW_STATS_ENTRY(ipInBcastPkts);
+IW_STATS_ENTRY(ipOutBcastPkts);
+IW_STATS_ENTRY(tcpRtoAlgorithm);
+IW_STATS_ENTRY(tcpRtoMin);
+IW_STATS_ENTRY(tcpRtoMax);
+IW_STATS_ENTRY(tcpMaxConn);
+IW_STATS_ENTRY(tcpActiveOpens);
+IW_STATS_ENTRY(tcpPassiveOpens);
+IW_STATS_ENTRY(tcpAttemptFails);
+IW_STATS_ENTRY(tcpEstabResets);
+IW_STATS_ENTRY(tcpCurrEstab);
+IW_STATS_ENTRY(tcpInSegs);
+IW_STATS_ENTRY(tcpOutSegs);
+IW_STATS_ENTRY(tcpRetransSegs);
+IW_STATS_ENTRY(tcpInErrs);
+IW_STATS_ENTRY(tcpOutRsts);
+
+static struct attribute *iw_proto_stats_attrs[] = {
+       &dev_attr_ipInReceives.attr,
+       &dev_attr_ipInHdrErrors.attr,
+       &dev_attr_ipInTooBigErrors.attr,
+       &dev_attr_ipInNoRoutes.attr,
+       &dev_attr_ipInAddrErrors.attr,
+       &dev_attr_ipInUnknownProtos.attr,
+       &dev_attr_ipInTruncatedPkts.attr,
+       &dev_attr_ipInDiscards.attr,
+       &dev_attr_ipInDelivers.attr,
+       &dev_attr_ipOutForwDatagrams.attr,
+       &dev_attr_ipOutRequests.attr,
+       &dev_attr_ipOutDiscards.attr,
+       &dev_attr_ipOutNoRoutes.attr,
+       &dev_attr_ipReasmTimeout.attr,
+       &dev_attr_ipReasmReqds.attr,
+       &dev_attr_ipReasmOKs.attr,
+       &dev_attr_ipReasmFails.attr,
+       &dev_attr_ipFragOKs.attr,
+       &dev_attr_ipFragFails.attr,
+       &dev_attr_ipFragCreates.attr,
+       &dev_attr_ipInMcastPkts.attr,
+       &dev_attr_ipOutMcastPkts.attr,
+       &dev_attr_ipInBcastPkts.attr,
+       &dev_attr_ipOutBcastPkts.attr,
+       &dev_attr_tcpRtoAlgorithm.attr,
+       &dev_attr_tcpRtoMin.attr,
+       &dev_attr_tcpRtoMax.attr,
+       &dev_attr_tcpMaxConn.attr,
+       &dev_attr_tcpActiveOpens.attr,
+       &dev_attr_tcpPassiveOpens.attr,
+       &dev_attr_tcpAttemptFails.attr,
+       &dev_attr_tcpEstabResets.attr,
+       &dev_attr_tcpCurrEstab.attr,
+       &dev_attr_tcpInSegs.attr,
+       &dev_attr_tcpOutSegs.attr,
+       &dev_attr_tcpRetransSegs.attr,
+       &dev_attr_tcpInErrs.attr,
+       &dev_attr_tcpOutRsts.attr,
+       NULL
+};
+
+static struct attribute_group iw_stats_group = {
+       .name   = "proto_stats",
+       .attrs  = iw_proto_stats_attrs,
 };
 
 int ib_device_register_sysfs(struct ib_device *device)
 {
-       struct class_device *class_dev = &device->class_dev;
+       struct device *class_dev = &device->dev;
        int ret;
        int i;
 
        class_dev->class      = &ib_class;
-       class_dev->class_data = device;
-       strlcpy(class_dev->class_id, device->name, BUS_ID_SIZE);
+       class_dev->driver_data = device;
+       class_dev->parent     = device->dma_device;
+       strlcpy(class_dev->bus_id, device->name, BUS_ID_SIZE);
 
        INIT_LIST_HEAD(&device->port_list);
 
-       ret = class_device_register(class_dev);
+       ret = device_register(class_dev);
        if (ret)
                goto err;
 
        for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
-               ret = class_device_create_file(class_dev, ib_class_attributes[i]);
+               ret = device_create_file(class_dev, ib_class_attributes[i]);
                if (ret)
                        goto err_unregister;
        }
 
-       device->ports_parent.parent = kobject_get(&class_dev->kobj);
-       if (!device->ports_parent.parent) {
-               ret = -EBUSY;
-               goto err_unregister;
-       }
-       ret = kobject_set_name(&device->ports_parent, "ports");
-       if (ret)
-               goto err_put;
-       ret = kobject_register(&device->ports_parent);
-       if (ret)
+       device->ports_parent = kobject_create_and_add("ports",
+                                       kobject_get(&class_dev->kobj));
+       if (!device->ports_parent) {
+               ret = -ENOMEM;
                goto err_put;
+       }
 
        if (device->node_type == RDMA_NODE_IB_SWITCH) {
                ret = add_port(device, 0);
@@ -721,6 +819,12 @@ int ib_device_register_sysfs(struct ib_device *device)
                }
        }
 
+       if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) {
+               ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group);
+               if (ret)
+                       goto err_put;
+       }
+
        return 0;
 
 err_put:
@@ -734,14 +838,14 @@ err_put:
                        sysfs_remove_group(p, &pma_group);
                        sysfs_remove_group(p, &port->pkey_group);
                        sysfs_remove_group(p, &port->gid_group);
-                       kobject_unregister(p);
+                       kobject_put(p);
                }
        }
 
        kobject_put(&class_dev->kobj);
 
 err_unregister:
-       class_device_unregister(class_dev);
+       device_unregister(class_dev);
 
 err:
        return ret;
@@ -758,11 +862,11 @@ void ib_device_unregister_sysfs(struct ib_device *device)
                sysfs_remove_group(p, &pma_group);
                sysfs_remove_group(p, &port->pkey_group);
                sysfs_remove_group(p, &port->gid_group);
-               kobject_unregister(p);
+               kobject_put(p);
        }
 
-       kobject_unregister(&device->ports_parent);
-       class_device_unregister(&device->class_dev);
+       kobject_put(device->ports_parent);
+       device_unregister(&device->dev);
 }
 
 int ib_sysfs_setup(void)