[ofa-general] [PATCH] mlx4: display misc device information via sysfs under /sys/class/infiniband/mlx4_x, for ibstat and ibv_devinfo

Jack Morgenstein jackm at dev.mellanox.co.il
Tue Sep 18 00:14:18 PDT 2007


display the following device information via sysfs:
board_id, fw_ver, hw_rev, hca_type.

The info is displayed under directory /sys/class/infiniband/mlx4_x, where x is
the pci bus sequence number (starting from zero).

This patch makes information available to ibstat and ibv_devinfo under the
same directory as is used for tavor/arbel/sinai -- thus requiring no userspace
modifications.

Signed-off-by: Jack Morgenstein <jackm at dev.mellanox.co.il>

Index: connectx_kernel/drivers/infiniband/hw/mlx4/main.c
===================================================================
--- connectx_kernel.orig/drivers/infiniband/hw/mlx4/main.c	2007-08-02 13:58:37.000000000 +0300
+++ connectx_kernel/drivers/infiniband/hw/mlx4/main.c	2007-08-02 14:04:28.000000000 +0300
@@ -477,9 +477,61 @@
 	return err;
 }
 
+static ssize_t show_hca(struct class_device *cdev, char *buf)
+{
+	struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
+	switch (dev->dev->pdev->device) {
+	case 0x6340:
+		return sprintf(buf, "MT25408\n");
+	case 0x634a:
+		return sprintf(buf, "MT25418\n");
+	case 0x6354:
+		return sprintf(buf, "MT25428\n");
+	case 0x6732:
+		return sprintf(buf, "MT26418\n");
+	case 0x673c:
+		return sprintf(buf, "MT26428\n");
+	default:
+		return sprintf(buf, "unknown\n");
+	}
+}
+
+static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
+{
+	struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
+	return sprintf(buf, "%d.%d.%d\n", (int) (dev->dev->caps.fw_ver >> 32),
+		       (int) (dev->dev->caps.fw_ver >> 16) & 0xffff,
+		       (int) dev->dev->caps.fw_ver & 0xffff);
+}
+
+static ssize_t show_rev(struct class_device *cdev, char *buf)
+{
+	struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
+	return sprintf(buf, "%x\n", dev->dev->rev_id);
+}
+
+static ssize_t show_board(struct class_device *cdev, char *buf)
+{
+	struct mlx4_ib_dev *dev = container_of(cdev, struct mlx4_ib_dev, ib_dev.class_dev);
+	return sprintf(buf, "%.*s\n", MLX4_BOARD_ID_LEN, dev->dev->board_id);
+}
+
+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 CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board,  NULL);
+
+static struct class_device_attribute *mlx4_class_attributes[] = {
+	&class_device_attr_hw_rev,
+	&class_device_attr_fw_ver,
+	&class_device_attr_hca_type,
+	&class_device_attr_board_id
+};
+
 static void *mlx4_ib_add(struct mlx4_dev *dev)
 {
 	struct mlx4_ib_dev *ibdev;
+	int i;
 
 	ibdev = (struct mlx4_ib_dev *) ib_alloc_device(sizeof *ibdev);
 	if (!ibdev) {
@@ -586,6 +642,12 @@
 	if (mlx4_ib_mad_init(ibdev))
 		goto err_reg;
 
+	for (i = 0; i < ARRAY_SIZE(mlx4_class_attributes); ++i) {
+		if (class_device_create_file(&ibdev->ib_dev.class_dev,
+					       mlx4_class_attributes[i]))
+			goto err_reg;
+	}
+
 	return ibdev;
 
 err_reg:
Index: connectx_kernel/include/linux/mlx4/device.h
===================================================================
--- connectx_kernel.orig/include/linux/mlx4/device.h	2007-08-02 13:58:37.000000000 +0300
+++ connectx_kernel/include/linux/mlx4/device.h	2007-08-02 14:04:28.000000000 +0300
@@ -49,6 +49,10 @@
 };
 
 enum {
+	MLX4_BOARD_ID_LEN = 64
+};
+
+enum {
 	MLX4_DEV_CAP_FLAG_RC		= 1 <<  0,
 	MLX4_DEV_CAP_FLAG_UC		= 1 <<  1,
 	MLX4_DEV_CAP_FLAG_UD		= 1 <<  2,
@@ -283,6 +287,8 @@
 	unsigned long		flags;
 	struct mlx4_caps	caps;
 	struct radix_tree_root	qp_table_tree;
+	u32			rev_id;
+	char			board_id[MLX4_BOARD_ID_LEN];
 };
 
 struct mlx4_init_port_param {
Index: connectx_kernel/drivers/net/mlx4/main.c
===================================================================
--- connectx_kernel.orig/drivers/net/mlx4/main.c	2007-08-02 13:58:37.000000000 +0300
+++ connectx_kernel/drivers/net/mlx4/main.c	2007-08-02 14:04:28.000000000 +0300
@@ -536,8 +536,8 @@
 	}
 
 	priv->eq_table.inta_pin = adapter.inta_pin;
-	priv->rev_id		= adapter.revision_id;
-	memcpy(priv->board_id, adapter.board_id, sizeof priv->board_id);
+	priv->dev.rev_id	= adapter.revision_id;
+	memcpy(priv->dev.board_id, adapter.board_id, sizeof priv->dev.board_id);
 
 	return 0;
 
Index: connectx_kernel/drivers/net/mlx4/mlx4.h
===================================================================
--- connectx_kernel.orig/drivers/net/mlx4/mlx4.h	2007-08-02 13:58:37.000000000 +0300
+++ connectx_kernel/drivers/net/mlx4/mlx4.h	2007-08-02 14:04:28.000000000 +0300
@@ -56,10 +56,6 @@
 };
 
 enum {
-	MLX4_BOARD_ID_LEN	= 64
-};
-
-enum {
 	MLX4_MGM_ENTRY_SIZE	=  0x100,
 	MLX4_QP_PER_MGM		= 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
 	MLX4_MTT_ENTRY_PER_SEG	= 8
@@ -279,9 +275,6 @@
 
 	struct mlx4_uar		driver_uar;
 	void __iomem	       *kar;
-
-	u32			rev_id;
-	char			board_id[MLX4_BOARD_ID_LEN];
 };
 
 static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)



More information about the general mailing list