mlx4_core: Don't read reserved fields in mlx4_QUERY_ADAPTER()
[linux-block.git] / drivers / infiniband / hw / mlx4 / main.c
index 6b9870a50bea828296f43a6d059a5a30c0004a79..d2f50b62fcb6ff7a44786967dc5758ae956285fd 100644 (file)
@@ -468,6 +468,7 @@ static int init_node_data(struct mlx4_ib_dev *dev)
        if (err)
                goto out;
 
+       dev->dev->rev_id = be32_to_cpup((__be32 *) (out_mad->data + 32));
        memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
 
 out:
@@ -476,9 +477,48 @@ out:
        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);
+       return sprintf(buf, "MT%d\n", dev->dev->pdev->device);
+}
+
+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) {
@@ -529,6 +569,7 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
                (1ull << IB_USER_VERBS_CMD_DETACH_MCAST)        |
                (1ull << IB_USER_VERBS_CMD_CREATE_SRQ)          |
                (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ)          |
+               (1ull << IB_USER_VERBS_CMD_QUERY_SRQ)           |
                (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
 
        ibdev->ib_dev.query_device      = mlx4_ib_query_device;
@@ -547,6 +588,7 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
        ibdev->ib_dev.destroy_ah        = mlx4_ib_destroy_ah;
        ibdev->ib_dev.create_srq        = mlx4_ib_create_srq;
        ibdev->ib_dev.modify_srq        = mlx4_ib_modify_srq;
+       ibdev->ib_dev.query_srq         = mlx4_ib_query_srq;
        ibdev->ib_dev.destroy_srq       = mlx4_ib_destroy_srq;
        ibdev->ib_dev.post_srq_recv     = mlx4_ib_post_srq_recv;
        ibdev->ib_dev.create_qp         = mlx4_ib_create_qp;
@@ -566,6 +608,11 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
        ibdev->ib_dev.detach_mcast      = mlx4_ib_mcg_detach;
        ibdev->ib_dev.process_mad       = mlx4_ib_process_mad;
 
+       ibdev->ib_dev.alloc_fmr         = mlx4_ib_fmr_alloc;
+       ibdev->ib_dev.map_phys_fmr      = mlx4_ib_map_phys_fmr;
+       ibdev->ib_dev.unmap_fmr         = mlx4_ib_unmap_fmr;
+       ibdev->ib_dev.dealloc_fmr       = mlx4_ib_fmr_dealloc;
+
        if (init_node_data(ibdev))
                goto err_map;
 
@@ -578,6 +625,12 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
        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: