IB/mlx4: Add IB counters table
[cascardo/linux.git] / drivers / infiniband / hw / mlx4 / mad.c
index 1cd75ff..68f2567 100644 (file)
@@ -824,18 +824,29 @@ static int iboe_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
 {
        struct mlx4_counter counter_stats;
        struct mlx4_ib_dev *dev = to_mdev(ibdev);
-       int err;
+       struct counter_index *tmp_counter;
+       int err = IB_MAD_RESULT_FAILURE, stats_avail = 0;
 
        if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_PERF_MGMT)
                return -EINVAL;
 
        memset(&counter_stats, 0, sizeof(counter_stats));
-       err = mlx4_get_counter_stats(dev->dev,
-                                    dev->counters[port_num - 1].index,
-                                    &counter_stats, 0);
-       if (err)
-               err = IB_MAD_RESULT_FAILURE;
-       else {
+       mutex_lock(&dev->counters_table[port_num - 1].mutex);
+       list_for_each_entry(tmp_counter,
+                           &dev->counters_table[port_num - 1].counters_list,
+                           list) {
+               err = mlx4_get_counter_stats(dev->dev,
+                                            tmp_counter->index,
+                                            &counter_stats, 0);
+               if (err) {
+                       err = IB_MAD_RESULT_FAILURE;
+                       stats_avail = 0;
+                       break;
+               }
+               stats_avail = 1;
+       }
+       mutex_unlock(&dev->counters_table[port_num - 1].mutex);
+       if (stats_avail) {
                memset(out_mad->data, 0, sizeof out_mad->data);
                switch (counter_stats.counter_mode & 0xf) {
                case 0: