net/mlx4_core: Add helper to query counters
[cascardo/linux.git] / drivers / infiniband / hw / mlx4 / mad.c
index bc698b1..bc09b4e 100644 (file)
@@ -64,14 +64,6 @@ enum {
 #define GUID_TBL_BLK_NUM_ENTRIES 8
 #define GUID_TBL_BLK_SIZE (GUID_TBL_ENTRY_SIZE * GUID_TBL_BLK_NUM_ENTRIES)
 
-/* Counters should be saturate once they reach their maximum value */
-#define ASSIGN_32BIT_COUNTER(counter, value) do {\
-       if ((value) > U32_MAX)                   \
-               counter = cpu_to_be32(U32_MAX); \
-       else                                     \
-               counter = cpu_to_be32(value);    \
-} while (0)
-
 struct mlx4_mad_rcv_buf {
        struct ib_grh grh;
        u8 payload[256];
@@ -828,31 +820,25 @@ static int iboe_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
                        struct ib_wc *in_wc, struct ib_grh *in_grh,
                        struct ib_mad *in_mad, struct ib_mad *out_mad)
 {
-       struct mlx4_cmd_mailbox *mailbox;
+       struct mlx4_counter counter_stats;
        struct mlx4_ib_dev *dev = to_mdev(ibdev);
        int err;
-       u32 inmod = dev->counters[port_num - 1].index & 0xffff;
-       u8 mode;
 
        if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_PERF_MGMT)
                return -EINVAL;
 
-       mailbox = mlx4_alloc_cmd_mailbox(dev->dev);
-       if (IS_ERR(mailbox))
-               return IB_MAD_RESULT_FAILURE;
-
-       err = mlx4_cmd_box(dev->dev, 0, mailbox->dma, inmod, 0,
-                          MLX4_CMD_QUERY_IF_STAT, MLX4_CMD_TIME_CLASS_C,
-                          MLX4_CMD_WRAPPED);
+       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 {
                memset(out_mad->data, 0, sizeof out_mad->data);
-               mode = ((struct mlx4_counter *)mailbox->buf)->counter_mode;
-               switch (mode & 0xf) {
+               switch (counter_stats.counter_mode & 0xf) {
                case 0:
-                       edit_counter(mailbox->buf,
-                                               (void *)(out_mad->data + 40));
+                       edit_counter(&counter_stats,
+                                    (void *)(out_mad->data + 40));
                        err = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
                        break;
                default:
@@ -860,8 +846,6 @@ static int iboe_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
                }
        }
 
-       mlx4_free_cmd_mailbox(dev->dev, mailbox);
-
        return err;
 }