blob: eb99856e8b30780577b645babd213aa5af4d762a [file] [log] [blame]
Mark Zhang7ade1ff2019-07-02 13:02:31 +03001/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2/*
3 * Copyright (c) 2019 Mellanox Technologies. All rights reserved.
4 */
5
6#ifndef _RDMA_COUNTER_H_
7#define _RDMA_COUNTER_H_
8
Mark Zhang413d3342019-07-02 13:02:34 +03009#include <linux/mutex.h>
Mark Zhang99fa3312019-07-02 13:02:35 +030010#include <linux/pid_namespace.h>
Mark Zhang413d3342019-07-02 13:02:34 +030011
Mark Zhang7ade1ff2019-07-02 13:02:31 +030012#include <rdma/restrack.h>
Mark Zhang413d3342019-07-02 13:02:34 +030013#include <rdma/rdma_netlink.h>
14
Jason Gunthorpe390d5772019-07-09 09:44:47 -030015struct ib_device;
Mark Zhang99fa3312019-07-02 13:02:35 +030016struct ib_qp;
17
Mark Zhang413d3342019-07-02 13:02:34 +030018struct auto_mode_param {
19 int qp_type;
20};
21
22struct rdma_counter_mode {
23 enum rdma_nl_counter_mode mode;
24 enum rdma_nl_counter_mask mask;
25 struct auto_mode_param param;
26};
27
28struct rdma_port_counter {
29 struct rdma_counter_mode mode;
Mark Zhangf34a55e2019-07-02 13:02:42 +030030 struct rdma_hw_stats *hstats;
Mark Zhang1bd8e0a2019-07-02 13:02:43 +030031 unsigned int num_counters;
Mark Zhang413d3342019-07-02 13:02:34 +030032 struct mutex lock;
33};
Mark Zhang7ade1ff2019-07-02 13:02:31 +030034
35struct rdma_counter {
36 struct rdma_restrack_entry res;
37 struct ib_device *device;
38 uint32_t id;
Mark Zhang99fa3312019-07-02 13:02:35 +030039 struct kref kref;
40 struct rdma_counter_mode mode;
41 struct mutex lock;
Mark Zhangc4ffee72019-07-02 13:02:40 +030042 struct rdma_hw_stats *stats;
Mark Zhang7ade1ff2019-07-02 13:02:31 +030043 u8 port;
44};
Mark Zhang413d3342019-07-02 13:02:34 +030045
46void rdma_counter_init(struct ib_device *dev);
47void rdma_counter_release(struct ib_device *dev);
48int rdma_counter_set_auto_mode(struct ib_device *dev, u8 port,
49 bool on, enum rdma_nl_counter_mask mask);
Mark Zhang99fa3312019-07-02 13:02:35 +030050int rdma_counter_bind_qp_auto(struct ib_qp *qp, u8 port);
51int rdma_counter_unbind_qp(struct ib_qp *qp, bool force);
Mark Zhang413d3342019-07-02 13:02:34 +030052
Mark Zhangc4ffee72019-07-02 13:02:40 +030053int rdma_counter_query_stats(struct rdma_counter *counter);
Mark Zhangf34a55e2019-07-02 13:02:42 +030054u64 rdma_counter_get_hwstat_value(struct ib_device *dev, u8 port, u32 index);
Mark Zhang1bd8e0a2019-07-02 13:02:43 +030055int rdma_counter_bind_qpn(struct ib_device *dev, u8 port,
56 u32 qp_num, u32 counter_id);
57int rdma_counter_bind_qpn_alloc(struct ib_device *dev, u8 port,
58 u32 qp_num, u32 *counter_id);
59int rdma_counter_unbind_qpn(struct ib_device *dev, u8 port,
60 u32 qp_num, u32 counter_id);
Mark Zhangb3893272019-07-02 13:02:44 +030061int rdma_counter_get_mode(struct ib_device *dev, u8 port,
62 enum rdma_nl_counter_mode *mode,
63 enum rdma_nl_counter_mask *mask);
Mark Zhangc4ffee72019-07-02 13:02:40 +030064
Mark Zhang7ade1ff2019-07-02 13:02:31 +030065#endif /* _RDMA_COUNTER_H_ */