mlx4: Enforce device max FMR maps in FMR alloc
authorEli Cohen <eli@dev.mellanox.co.il>
Thu, 9 Feb 2012 16:10:06 +0000 (18:10 +0200)
committerRoland Dreier <roland@purestorage.com>
Sun, 26 Feb 2012 09:43:37 +0000 (01:43 -0800)
ConnectX devices have a limit on the number of mappings that can be
done on an FMR before having to call sync_tpt.  The current
mlx4_ib driver reports the limit correctly in max_map_per_fmr in
.query_device(), but mlx4_core doesn't check it when actually
allocating FMRs.

Add a max_fmr_maps field to struct mlx4_caps and enforce this maximum
value on FMR allocations.

Signed-off-by: Eli Cohen <eli@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/hw/mlx4/main.c
drivers/net/ethernet/mellanox/mlx4/main.c
drivers/net/ethernet/mellanox/mlx4/mr.c
include/linux/mlx4/device.h

index 7b445df6a667be9a595ae1f8ed9449e6419ce16a..e152837b75a56054742e45bcd597166645fa9fdb 100644 (file)
@@ -163,7 +163,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
        props->max_mcast_qp_attach = dev->dev->caps.num_qp_per_mgm;
        props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
                                           props->max_mcast_grp;
-       props->max_map_per_fmr = (1 << (32 - ilog2(dev->dev->caps.num_mpts))) - 1;
+       props->max_map_per_fmr = dev->dev->caps.max_fmr_maps;
 
 out:
        kfree(in_mad);
index 678558b502fc31e506633e0713805f58c8676108..3e593ae56e0072eea7a6775dbf7fbcc5bcdc771b 100644 (file)
@@ -1131,6 +1131,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
                        goto err_stop_fw;
                }
 
+               dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1;
+
                init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
                init_hca.uar_page_sz = PAGE_SHIFT - 12;
 
index 25a80d71fb2ab476df010be63a6f597f0b917319..5b7c06e0cd05b7ea549a57d37802a46c303b650b 100644 (file)
@@ -816,6 +816,9 @@ int mlx4_fmr_alloc(struct mlx4_dev *dev, u32 pd, u32 access, int max_pages,
        u64 mtt_offset;
        int err = -ENOMEM;
 
+       if (max_maps > dev->caps.max_fmr_maps)
+               return -EINVAL;
+
        if (page_shift < (ffs(dev->caps.page_size_cap) - 1) || page_shift >= 32)
                return -EINVAL;
 
index aea61905499b0e20598969cb02e63f32a3010d2d..263d2ae21ac1d63e5a7c5c9b167d726e09095913 100644 (file)
@@ -273,6 +273,7 @@ struct mlx4_caps {
        int                     num_comp_vectors;
        int                     comp_pool;
        int                     num_mpts;
+       int                     max_fmr_maps;
        int                     num_mtts;
        int                     fmr_reserved_mtts;
        int                     reserved_mtts;