0001
0002
0003
0004
0005
0006 #ifndef _RDMA_RESTRACK_H_
0007 #define _RDMA_RESTRACK_H_
0008
0009 #include <linux/typecheck.h>
0010 #include <linux/sched.h>
0011 #include <linux/kref.h>
0012 #include <linux/completion.h>
0013 #include <linux/sched/task.h>
0014 #include <uapi/rdma/rdma_netlink.h>
0015 #include <linux/xarray.h>
0016
0017 struct ib_device;
0018 struct sk_buff;
0019
0020
0021
0022
0023 enum rdma_restrack_type {
0024
0025
0026
0027 RDMA_RESTRACK_PD,
0028
0029
0030
0031 RDMA_RESTRACK_CQ,
0032
0033
0034
0035 RDMA_RESTRACK_QP,
0036
0037
0038
0039 RDMA_RESTRACK_CM_ID,
0040
0041
0042
0043 RDMA_RESTRACK_MR,
0044
0045
0046
0047 RDMA_RESTRACK_CTX,
0048
0049
0050
0051 RDMA_RESTRACK_COUNTER,
0052
0053
0054
0055 RDMA_RESTRACK_SRQ,
0056
0057
0058
0059 RDMA_RESTRACK_MAX
0060 };
0061
0062
0063
0064
0065 struct rdma_restrack_entry {
0066
0067
0068
0069
0070
0071
0072
0073
0074 bool valid;
0075
0076
0077
0078
0079
0080
0081
0082 u8 no_track : 1;
0083
0084
0085
0086 struct kref kref;
0087
0088
0089
0090 struct completion comp;
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 struct task_struct *task;
0101
0102
0103
0104 const char *kern_name;
0105
0106
0107
0108 enum rdma_restrack_type type;
0109
0110
0111
0112 bool user;
0113
0114
0115
0116 u32 id;
0117 };
0118
0119 int rdma_restrack_count(struct ib_device *dev,
0120 enum rdma_restrack_type type);
0121
0122
0123
0124
0125 static inline bool rdma_is_kernel_res(const struct rdma_restrack_entry *res)
0126 {
0127 return !res->user;
0128 }
0129
0130
0131
0132
0133
0134 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res);
0135
0136
0137
0138
0139
0140 int rdma_restrack_put(struct rdma_restrack_entry *res);
0141
0142
0143
0144
0145
0146 int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value);
0147 int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name,
0148 u32 value);
0149 int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value);
0150 int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name,
0151 u64 value);
0152 int rdma_nl_put_driver_string(struct sk_buff *msg, const char *name,
0153 const char *str);
0154 int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name,
0155 u64 value);
0156
0157 struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev,
0158 enum rdma_restrack_type type,
0159 u32 id);
0160
0161
0162
0163
0164
0165
0166
0167
0168 static inline void rdma_restrack_no_track(struct rdma_restrack_entry *res)
0169 {
0170 res->no_track = true;
0171 }
0172 static inline bool rdma_restrack_is_tracked(struct rdma_restrack_entry *res)
0173 {
0174 return !res->no_track;
0175 }
0176 #endif