Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2/*
  3 * Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved.
  4 */
  5
  6#ifndef _RDMA_RESTRACK_H_
  7#define _RDMA_RESTRACK_H_
  8
  9#include <linux/typecheck.h>
 10#include <linux/sched.h>
 11#include <linux/kref.h>
 12#include <linux/completion.h>
 13#include <linux/sched/task.h>
 14#include <uapi/rdma/rdma_netlink.h>
 15#include <linux/xarray.h>
 16
 
 
 
 17struct ib_device;
 18struct sk_buff;
 19
 20/**
 21 * enum rdma_restrack_type - HW objects to track
 22 */
 23enum rdma_restrack_type {
 24	/**
 25	 * @RDMA_RESTRACK_PD: Protection domain (PD)
 26	 */
 27	RDMA_RESTRACK_PD,
 28	/**
 29	 * @RDMA_RESTRACK_CQ: Completion queue (CQ)
 30	 */
 31	RDMA_RESTRACK_CQ,
 32	/**
 33	 * @RDMA_RESTRACK_QP: Queue pair (QP)
 34	 */
 35	RDMA_RESTRACK_QP,
 36	/**
 37	 * @RDMA_RESTRACK_CM_ID: Connection Manager ID (CM_ID)
 38	 */
 39	RDMA_RESTRACK_CM_ID,
 40	/**
 41	 * @RDMA_RESTRACK_MR: Memory Region (MR)
 42	 */
 43	RDMA_RESTRACK_MR,
 44	/**
 45	 * @RDMA_RESTRACK_CTX: Verbs contexts (CTX)
 46	 */
 47	RDMA_RESTRACK_CTX,
 48	/**
 49	 * @RDMA_RESTRACK_COUNTER: Statistic Counter
 50	 */
 51	RDMA_RESTRACK_COUNTER,
 52	/**
 53	 * @RDMA_RESTRACK_SRQ: Shared receive queue (SRQ)
 54	 */
 55	RDMA_RESTRACK_SRQ,
 56	/**
 57	 * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations
 58	 */
 59	RDMA_RESTRACK_MAX
 60};
 61
 62/**
 63 * struct rdma_restrack_entry - metadata per-entry
 64 */
 65struct rdma_restrack_entry {
 66	/**
 67	 * @valid: validity indicator
 68	 *
 69	 * The entries are filled during rdma_restrack_add,
 70	 * can be attempted to be free during rdma_restrack_del.
 71	 *
 72	 * As an example for that, see mlx5 QPs with type MLX5_IB_QPT_HW_GSI
 73	 */
 74	bool			valid;
 75	/**
 76	 * @no_track: don't add this entry to restrack DB
 77	 *
 78	 * This field is used to mark an entry that doesn't need to be added to
 79	 * internal restrack DB and presented later to the users at the nldev
 80	 * query stage.
 81	 */
 82	u8			no_track : 1;
 83	/*
 84	 * @kref: Protect destroy of the resource
 85	 */
 86	struct kref		kref;
 87	/*
 88	 * @comp: Signal that all consumers of resource are completed their work
 89	 */
 90	struct completion	comp;
 91	/**
 92	 * @task: owner of resource tracking entity
 93	 *
 94	 * There are two types of entities: created by user and created
 95	 * by kernel.
 96	 *
 97	 * This is relevant for the entities created by users.
 98	 * For the entities created by kernel, this pointer will be NULL.
 99	 */
100	struct task_struct	*task;
101	/**
102	 * @kern_name: name of owner for the kernel created entities.
103	 */
104	const char		*kern_name;
105	/**
106	 * @type: various objects in restrack database
107	 */
108	enum rdma_restrack_type	type;
109	/**
110	 * @user: user resource
111	 */
112	bool			user;
113	/**
114	 * @id: ID to expose to users
115	 */
116	u32 id;
117};
118
119int rdma_restrack_count(struct ib_device *dev,
120			enum rdma_restrack_type type);
121/**
122 * rdma_is_kernel_res() - check the owner of resource
123 * @res:  resource entry
124 */
125static inline bool rdma_is_kernel_res(const struct rdma_restrack_entry *res)
126{
127	return !res->user;
128}
129
130/**
131 * rdma_restrack_get() - grab to protect resource from release
132 * @res:  resource entry
133 */
134int __must_check rdma_restrack_get(struct rdma_restrack_entry *res);
135
136/**
137 * rdma_restrack_put() - release resource
138 * @res:  resource entry
139 */
140int rdma_restrack_put(struct rdma_restrack_entry *res);
141
142/*
143 * Helper functions for rdma drivers when filling out
144 * nldev driver attributes.
145 */
146int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value);
147int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name,
148			       u32 value);
149int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value);
150int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name,
151			       u64 value);
152int rdma_nl_put_driver_string(struct sk_buff *msg, const char *name,
153			      const char *str);
154int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name,
155				 u64 value);
156
157struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev,
158						   enum rdma_restrack_type type,
159						   u32 id);
160
161/**
162 * rdma_restrack_no_track() - don't add resource to the DB
163 * @res: resource entry
164 *
165 * Every user of this API should be cross examined.
166 * Probably you don't need to use this function.
167 */
168static inline void rdma_restrack_no_track(struct rdma_restrack_entry *res)
169{
170	res->no_track = true;
171}
172static inline bool rdma_restrack_is_tracked(struct rdma_restrack_entry *res)
173{
174	return !res->no_track;
175}
176#endif /* _RDMA_RESTRACK_H_ */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2/*
  3 * Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved.
  4 */
  5
  6#ifndef _RDMA_RESTRACK_H_
  7#define _RDMA_RESTRACK_H_
  8
  9#include <linux/typecheck.h>
 10#include <linux/sched.h>
 11#include <linux/kref.h>
 12#include <linux/completion.h>
 13#include <linux/sched/task.h>
 14#include <uapi/rdma/rdma_netlink.h>
 15#include <linux/xarray.h>
 16
 17/* Mark entry as containing driver specific details, it is used to provide QP subtype for now */
 18#define RESTRACK_DD XA_MARK_1
 19
 20struct ib_device;
 21struct sk_buff;
 22
 23/**
 24 * enum rdma_restrack_type - HW objects to track
 25 */
 26enum rdma_restrack_type {
 27	/**
 28	 * @RDMA_RESTRACK_PD: Protection domain (PD)
 29	 */
 30	RDMA_RESTRACK_PD,
 31	/**
 32	 * @RDMA_RESTRACK_CQ: Completion queue (CQ)
 33	 */
 34	RDMA_RESTRACK_CQ,
 35	/**
 36	 * @RDMA_RESTRACK_QP: Queue pair (QP)
 37	 */
 38	RDMA_RESTRACK_QP,
 39	/**
 40	 * @RDMA_RESTRACK_CM_ID: Connection Manager ID (CM_ID)
 41	 */
 42	RDMA_RESTRACK_CM_ID,
 43	/**
 44	 * @RDMA_RESTRACK_MR: Memory Region (MR)
 45	 */
 46	RDMA_RESTRACK_MR,
 47	/**
 48	 * @RDMA_RESTRACK_CTX: Verbs contexts (CTX)
 49	 */
 50	RDMA_RESTRACK_CTX,
 51	/**
 52	 * @RDMA_RESTRACK_COUNTER: Statistic Counter
 53	 */
 54	RDMA_RESTRACK_COUNTER,
 55	/**
 56	 * @RDMA_RESTRACK_SRQ: Shared receive queue (SRQ)
 57	 */
 58	RDMA_RESTRACK_SRQ,
 59	/**
 60	 * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations
 61	 */
 62	RDMA_RESTRACK_MAX
 63};
 64
 65/**
 66 * struct rdma_restrack_entry - metadata per-entry
 67 */
 68struct rdma_restrack_entry {
 69	/**
 70	 * @valid: validity indicator
 71	 *
 72	 * The entries are filled during rdma_restrack_add,
 73	 * can be attempted to be free during rdma_restrack_del.
 74	 *
 75	 * As an example for that, see mlx5 QPs with type MLX5_IB_QPT_HW_GSI
 76	 */
 77	bool			valid;
 78	/**
 79	 * @no_track: don't add this entry to restrack DB
 80	 *
 81	 * This field is used to mark an entry that doesn't need to be added to
 82	 * internal restrack DB and presented later to the users at the nldev
 83	 * query stage.
 84	 */
 85	u8			no_track : 1;
 86	/*
 87	 * @kref: Protect destroy of the resource
 88	 */
 89	struct kref		kref;
 90	/*
 91	 * @comp: Signal that all consumers of resource are completed their work
 92	 */
 93	struct completion	comp;
 94	/**
 95	 * @task: owner of resource tracking entity
 96	 *
 97	 * There are two types of entities: created by user and created
 98	 * by kernel.
 99	 *
100	 * This is relevant for the entities created by users.
101	 * For the entities created by kernel, this pointer will be NULL.
102	 */
103	struct task_struct	*task;
104	/**
105	 * @kern_name: name of owner for the kernel created entities.
106	 */
107	const char		*kern_name;
108	/**
109	 * @type: various objects in restrack database
110	 */
111	enum rdma_restrack_type	type;
112	/**
113	 * @user: user resource
114	 */
115	bool			user;
116	/**
117	 * @id: ID to expose to users
118	 */
119	u32 id;
120};
121
122int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type,
123			bool show_details);
124/**
125 * rdma_is_kernel_res() - check the owner of resource
126 * @res:  resource entry
127 */
128static inline bool rdma_is_kernel_res(const struct rdma_restrack_entry *res)
129{
130	return !res->user;
131}
132
133/**
134 * rdma_restrack_get() - grab to protect resource from release
135 * @res:  resource entry
136 */
137int __must_check rdma_restrack_get(struct rdma_restrack_entry *res);
138
139/**
140 * rdma_restrack_put() - release resource
141 * @res:  resource entry
142 */
143int rdma_restrack_put(struct rdma_restrack_entry *res);
144
145/*
146 * Helper functions for rdma drivers when filling out
147 * nldev driver attributes.
148 */
149int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value);
150int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name,
151			       u32 value);
152int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value);
153int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name,
154			       u64 value);
155int rdma_nl_put_driver_string(struct sk_buff *msg, const char *name,
156			      const char *str);
157int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name,
158				 u64 value);
159
160struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev,
161						   enum rdma_restrack_type type,
162						   u32 id);
163
164/**
165 * rdma_restrack_no_track() - don't add resource to the DB
166 * @res: resource entry
167 *
168 * Every user of this API should be cross examined.
169 * Probably you don't need to use this function.
170 */
171static inline void rdma_restrack_no_track(struct rdma_restrack_entry *res)
172{
173	res->no_track = true;
174}
175static inline bool rdma_restrack_is_tracked(struct rdma_restrack_entry *res)
176{
177	return !res->no_track;
178}
179#endif /* _RDMA_RESTRACK_H_ */