Mark Zhang | 7ade1ff | 2019-07-02 13:02:31 +0300 | [diff] [blame] | 1 | /* 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 Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 9 | #include <linux/mutex.h> |
Mark Zhang | 99fa331 | 2019-07-02 13:02:35 +0300 | [diff] [blame] | 10 | #include <linux/pid_namespace.h> |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 11 | |
Mark Zhang | 7ade1ff | 2019-07-02 13:02:31 +0300 | [diff] [blame] | 12 | #include <rdma/restrack.h> |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 13 | #include <rdma/rdma_netlink.h> |
| 14 | |
Jason Gunthorpe | 390d577 | 2019-07-09 09:44:47 -0300 | [diff] [blame] | 15 | struct ib_device; |
Mark Zhang | 99fa331 | 2019-07-02 13:02:35 +0300 | [diff] [blame] | 16 | struct ib_qp; |
| 17 | |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 18 | struct auto_mode_param { |
| 19 | int qp_type; |
| 20 | }; |
| 21 | |
| 22 | struct 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 | |
| 28 | struct rdma_port_counter { |
| 29 | struct rdma_counter_mode mode; |
Mark Zhang | f34a55e | 2019-07-02 13:02:42 +0300 | [diff] [blame] | 30 | struct rdma_hw_stats *hstats; |
Mark Zhang | 1bd8e0a | 2019-07-02 13:02:43 +0300 | [diff] [blame] | 31 | unsigned int num_counters; |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 32 | struct mutex lock; |
| 33 | }; |
Mark Zhang | 7ade1ff | 2019-07-02 13:02:31 +0300 | [diff] [blame] | 34 | |
| 35 | struct rdma_counter { |
| 36 | struct rdma_restrack_entry res; |
| 37 | struct ib_device *device; |
| 38 | uint32_t id; |
Mark Zhang | 99fa331 | 2019-07-02 13:02:35 +0300 | [diff] [blame] | 39 | struct kref kref; |
| 40 | struct rdma_counter_mode mode; |
| 41 | struct mutex lock; |
Mark Zhang | c4ffee7 | 2019-07-02 13:02:40 +0300 | [diff] [blame] | 42 | struct rdma_hw_stats *stats; |
Mark Zhang | 7ade1ff | 2019-07-02 13:02:31 +0300 | [diff] [blame] | 43 | u8 port; |
| 44 | }; |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 45 | |
| 46 | void rdma_counter_init(struct ib_device *dev); |
| 47 | void rdma_counter_release(struct ib_device *dev); |
| 48 | int rdma_counter_set_auto_mode(struct ib_device *dev, u8 port, |
| 49 | bool on, enum rdma_nl_counter_mask mask); |
Mark Zhang | 99fa331 | 2019-07-02 13:02:35 +0300 | [diff] [blame] | 50 | int rdma_counter_bind_qp_auto(struct ib_qp *qp, u8 port); |
| 51 | int rdma_counter_unbind_qp(struct ib_qp *qp, bool force); |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 52 | |
Mark Zhang | c4ffee7 | 2019-07-02 13:02:40 +0300 | [diff] [blame] | 53 | int rdma_counter_query_stats(struct rdma_counter *counter); |
Mark Zhang | f34a55e | 2019-07-02 13:02:42 +0300 | [diff] [blame] | 54 | u64 rdma_counter_get_hwstat_value(struct ib_device *dev, u8 port, u32 index); |
Mark Zhang | 1bd8e0a | 2019-07-02 13:02:43 +0300 | [diff] [blame] | 55 | int rdma_counter_bind_qpn(struct ib_device *dev, u8 port, |
| 56 | u32 qp_num, u32 counter_id); |
| 57 | int rdma_counter_bind_qpn_alloc(struct ib_device *dev, u8 port, |
| 58 | u32 qp_num, u32 *counter_id); |
| 59 | int rdma_counter_unbind_qpn(struct ib_device *dev, u8 port, |
| 60 | u32 qp_num, u32 counter_id); |
Mark Zhang | b389327 | 2019-07-02 13:02:44 +0300 | [diff] [blame] | 61 | int 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 Zhang | c4ffee7 | 2019-07-02 13:02:40 +0300 | [diff] [blame] | 64 | |
Mark Zhang | 7ade1ff | 2019-07-02 13:02:31 +0300 | [diff] [blame] | 65 | #endif /* _RDMA_COUNTER_H_ */ |