[openib-general] [PATCH] mthca-specific sysfs attributes

Roland Dreier roland at topspin.com
Mon Sep 6 15:39:21 PDT 2004


This adds some extra fields to sysfs that the low-level driver knows
how to format: FW version and HW revision.

 - R.

Index: infiniband/hw/mthca/mthca_provider.c
===================================================================
--- infiniband/hw/mthca/mthca_provider.c	(revision 737)
+++ infiniband/hw/mthca/mthca_provider.c	(working copy)
@@ -71,7 +71,8 @@
 		0xffffff;
 	props->vendor_part_id = be16_to_cpup((u16 *) (out_mad->payload + 70));
 	props->hw_ver         = be16_to_cpup((u16 *) (out_mad->payload + 72));
-	memcpy(&props->node_guid, out_mad->payload + 52, 8);
+	memcpy(&props->sys_image_guid, out_mad->payload + 44, 8);
+	memcpy(&props->node_guid,      out_mad->payload + 52, 8);
 
 	err = 0;
  out:
@@ -514,8 +515,46 @@
 	return 0;
 }
 
+static ssize_t show_rev(struct class_device *cdev, char *buf)
+{
+	struct mthca_dev *dev = container_of(cdev, struct mthca_dev, ib_dev.class_dev);
+	return sprintf(buf, "%x\n", dev->rev_id);
+}
+
+static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
+{
+	struct mthca_dev *dev = container_of(cdev, struct mthca_dev, ib_dev.class_dev);
+	return sprintf(buf, "%x.%x.%x\n", (int) (dev->fw_ver >> 32),
+		       (int) (dev->fw_ver >> 16) & 0xffff,
+		       (int) dev->fw_ver & 0xffff);
+}
+
+static ssize_t show_hca(struct class_device *cdev, char *buf)
+{
+	struct mthca_dev *dev = container_of(cdev, struct mthca_dev, ib_dev.class_dev);
+	switch (dev->hca_type) {
+	case TAVOR:        return sprintf(buf, "MT23108\n");
+	case ARBEL_COMPAT: return sprintf(buf, "MT25208 (MT23108 compat mode)\n");
+	case ARBEL_NATIVE: return sprintf(buf, "MT25208\n");
+	default:           return sprintf(buf, "unknown\n");
+	}
+}
+
+static CLASS_DEVICE_ATTR(hw_rev,   S_IRUGO, show_rev,    NULL);
+static CLASS_DEVICE_ATTR(fw_ver,   S_IRUGO, show_fw_ver, NULL);
+static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca,    NULL);
+
+static struct class_device_attribute *mthca_class_attributes[] = {
+	&class_device_attr_hw_rev,
+	&class_device_attr_fw_ver,
+	&class_device_attr_hca_type
+};
+
 int mthca_register_device(struct mthca_dev *dev)
 {
+	int ret;
+	int i;
+
 	strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX);
 	dev->ib_dev.node_type            = IB_NODE_CA;
 	dev->ib_dev.owner                = THIS_MODULE;
@@ -546,7 +585,20 @@
 	dev->ib_dev.detach_mcast         = mthca_multicast_detach;
 	dev->ib_dev.mad_process          = mthca_process_mad;
 
-	return ib_register_device(&dev->ib_dev);
+	ret = ib_register_device(&dev->ib_dev);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < ARRAY_SIZE(mthca_class_attributes); ++i) {
+		ret = class_device_create_file(&dev->ib_dev.class_dev,
+					       mthca_class_attributes[i]);
+		if (ret) {
+			ib_deregister_device(&dev->ib_dev);
+			return ret;
+		}
+	}
+
+	return 0;
 }
 
 void mthca_deregister_device(struct mthca_dev *dev)
Index: infiniband/hw/mthca/ChangeLog
===================================================================
--- infiniband/hw/mthca/ChangeLog	(revision 736)
+++ infiniband/hw/mthca/ChangeLog	(working copy)
@@ -51,6 +51,7 @@
 	- Fix mapping of HCA memory on JS20 (don't trust what the HCA
 	  tells us about PCI addresses).
         - Don't request SRQ events if FW doesn't support SRQ.
+        - Add firmware version and revision ID to sysfs.
 
 Local Variables:
 mode: text



More information about the general mailing list