forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
....@@ -36,6 +36,7 @@
3636 #include <linux/mlx5/cq.h>
3737 #include <linux/mlx5/driver.h>
3838 #include "mlx5_core.h"
39
+#include "lib/eq.h"
3940
4041 enum {
4142 QP_PID,
....@@ -91,8 +92,6 @@
9192 void mlx5_register_debugfs(void)
9293 {
9394 mlx5_debugfs_root = debugfs_create_dir("mlx5", NULL);
94
- if (IS_ERR_OR_NULL(mlx5_debugfs_root))
95
- mlx5_debugfs_root = NULL;
9695 }
9796
9897 void mlx5_unregister_debugfs(void)
....@@ -100,45 +99,25 @@
10099 debugfs_remove(mlx5_debugfs_root);
101100 }
102101
103
-int mlx5_qp_debugfs_init(struct mlx5_core_dev *dev)
102
+void mlx5_qp_debugfs_init(struct mlx5_core_dev *dev)
104103 {
105
- if (!mlx5_debugfs_root)
106
- return 0;
107
-
108
- atomic_set(&dev->num_qps, 0);
109
-
110104 dev->priv.qp_debugfs = debugfs_create_dir("QPs", dev->priv.dbg_root);
111
- if (!dev->priv.qp_debugfs)
112
- return -ENOMEM;
113
-
114
- return 0;
115105 }
106
+EXPORT_SYMBOL(mlx5_qp_debugfs_init);
116107
117108 void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev)
118109 {
119
- if (!mlx5_debugfs_root)
120
- return;
121
-
122110 debugfs_remove_recursive(dev->priv.qp_debugfs);
123111 }
112
+EXPORT_SYMBOL(mlx5_qp_debugfs_cleanup);
124113
125
-int mlx5_eq_debugfs_init(struct mlx5_core_dev *dev)
114
+void mlx5_eq_debugfs_init(struct mlx5_core_dev *dev)
126115 {
127
- if (!mlx5_debugfs_root)
128
- return 0;
129
-
130116 dev->priv.eq_debugfs = debugfs_create_dir("EQs", dev->priv.dbg_root);
131
- if (!dev->priv.eq_debugfs)
132
- return -ENOMEM;
133
-
134
- return 0;
135117 }
136118
137119 void mlx5_eq_debugfs_cleanup(struct mlx5_core_dev *dev)
138120 {
139
- if (!mlx5_debugfs_root)
140
- return;
141
-
142121 debugfs_remove_recursive(dev->priv.eq_debugfs);
143122 }
144123
....@@ -182,85 +161,41 @@
182161 .write = average_write,
183162 };
184163
185
-int mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev)
164
+void mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev)
186165 {
187166 struct mlx5_cmd_stats *stats;
188167 struct dentry **cmd;
189168 const char *namep;
190
- int err;
191169 int i;
192
-
193
- if (!mlx5_debugfs_root)
194
- return 0;
195170
196171 cmd = &dev->priv.cmdif_debugfs;
197172 *cmd = debugfs_create_dir("commands", dev->priv.dbg_root);
198
- if (!*cmd)
199
- return -ENOMEM;
200173
201
- for (i = 0; i < ARRAY_SIZE(dev->cmd.stats); i++) {
174
+ for (i = 0; i < MLX5_CMD_OP_MAX; i++) {
202175 stats = &dev->cmd.stats[i];
203176 namep = mlx5_command_str(i);
204177 if (strcmp(namep, "unknown command opcode")) {
205178 stats->root = debugfs_create_dir(namep, *cmd);
206
- if (!stats->root) {
207
- mlx5_core_warn(dev, "failed adding command %d\n",
208
- i);
209
- err = -ENOMEM;
210
- goto out;
211
- }
212179
213
- stats->avg = debugfs_create_file("average", 0400,
214
- stats->root, stats,
215
- &stats_fops);
216
- if (!stats->avg) {
217
- mlx5_core_warn(dev, "failed creating debugfs file\n");
218
- err = -ENOMEM;
219
- goto out;
220
- }
221
-
222
- stats->count = debugfs_create_u64("n", 0400,
223
- stats->root,
224
- &stats->n);
225
- if (!stats->count) {
226
- mlx5_core_warn(dev, "failed creating debugfs file\n");
227
- err = -ENOMEM;
228
- goto out;
229
- }
180
+ debugfs_create_file("average", 0400, stats->root, stats,
181
+ &stats_fops);
182
+ debugfs_create_u64("n", 0400, stats->root, &stats->n);
230183 }
231184 }
232
-
233
- return 0;
234
-out:
235
- debugfs_remove_recursive(dev->priv.cmdif_debugfs);
236
- return err;
237185 }
238186
239187 void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev)
240188 {
241
- if (!mlx5_debugfs_root)
242
- return;
243
-
244189 debugfs_remove_recursive(dev->priv.cmdif_debugfs);
245190 }
246191
247
-int mlx5_cq_debugfs_init(struct mlx5_core_dev *dev)
192
+void mlx5_cq_debugfs_init(struct mlx5_core_dev *dev)
248193 {
249
- if (!mlx5_debugfs_root)
250
- return 0;
251
-
252194 dev->priv.cq_debugfs = debugfs_create_dir("CQs", dev->priv.dbg_root);
253
- if (!dev->priv.cq_debugfs)
254
- return -ENOMEM;
255
-
256
- return 0;
257195 }
258196
259197 void mlx5_cq_debugfs_cleanup(struct mlx5_core_dev *dev)
260198 {
261
- if (!mlx5_debugfs_root)
262
- return;
263
-
264199 debugfs_remove_recursive(dev->priv.cq_debugfs);
265200 }
266201
....@@ -268,41 +203,41 @@
268203 int index, int *is_str)
269204 {
270205 int outlen = MLX5_ST_SZ_BYTES(query_qp_out);
271
- struct mlx5_qp_context *ctx;
206
+ u32 in[MLX5_ST_SZ_DW(query_qp_in)] = {};
272207 u64 param = 0;
273208 u32 *out;
209
+ int state;
210
+ u32 *qpc;
274211 int err;
275
- int no_sq;
276212
277213 out = kzalloc(outlen, GFP_KERNEL);
278214 if (!out)
279
- return param;
215
+ return 0;
280216
281
- err = mlx5_core_qp_query(dev, qp, out, outlen);
282
- if (err) {
283
- mlx5_core_warn(dev, "failed to query qp err=%d\n", err);
217
+ MLX5_SET(query_qp_in, in, opcode, MLX5_CMD_OP_QUERY_QP);
218
+ MLX5_SET(query_qp_in, in, qpn, qp->qpn);
219
+ err = mlx5_cmd_exec_inout(dev, query_qp, in, out);
220
+ if (err)
284221 goto out;
285
- }
286222
287223 *is_str = 0;
288224
289
- /* FIXME: use MLX5_GET rather than mlx5_qp_context manual struct */
290
- ctx = (struct mlx5_qp_context *)MLX5_ADDR_OF(query_qp_out, out, qpc);
291
-
225
+ qpc = MLX5_ADDR_OF(query_qp_out, out, qpc);
292226 switch (index) {
293227 case QP_PID:
294228 param = qp->pid;
295229 break;
296230 case QP_STATE:
297
- param = (unsigned long)mlx5_qp_state_str(be32_to_cpu(ctx->flags) >> 28);
231
+ state = MLX5_GET(qpc, qpc, state);
232
+ param = (unsigned long)mlx5_qp_state_str(state);
298233 *is_str = 1;
299234 break;
300235 case QP_XPORT:
301
- param = (unsigned long)mlx5_qp_type_str((be32_to_cpu(ctx->flags) >> 16) & 0xff);
236
+ param = (unsigned long)mlx5_qp_type_str(MLX5_GET(qpc, qpc, st));
302237 *is_str = 1;
303238 break;
304239 case QP_MTU:
305
- switch (ctx->mtu_msgmax >> 5) {
240
+ switch (MLX5_GET(qpc, qpc, mtu)) {
306241 case IB_MTU_256:
307242 param = 256;
308243 break;
....@@ -323,27 +258,22 @@
323258 }
324259 break;
325260 case QP_N_RECV:
326
- param = 1 << ((ctx->rq_size_stride >> 3) & 0xf);
261
+ param = 1 << MLX5_GET(qpc, qpc, log_rq_size);
327262 break;
328263 case QP_RECV_SZ:
329
- param = 1 << ((ctx->rq_size_stride & 7) + 4);
264
+ param = 1 << (MLX5_GET(qpc, qpc, log_rq_stride) + 4);
330265 break;
331266 case QP_N_SEND:
332
- no_sq = be16_to_cpu(ctx->sq_crq_size) >> 15;
333
- if (!no_sq)
334
- param = 1 << (be16_to_cpu(ctx->sq_crq_size) >> 11);
335
- else
336
- param = 0;
267
+ if (!MLX5_GET(qpc, qpc, no_sq))
268
+ param = 1 << MLX5_GET(qpc, qpc, log_sq_size);
337269 break;
338270 case QP_LOG_PG_SZ:
339
- param = (be32_to_cpu(ctx->log_pg_sz_remote_qpn) >> 24) & 0x1f;
340
- param += 12;
271
+ param = MLX5_GET(qpc, qpc, log_page_size) + 12;
341272 break;
342273 case QP_RQPN:
343
- param = be32_to_cpu(ctx->log_pg_sz_remote_qpn) & 0xffffff;
274
+ param = MLX5_GET(qpc, qpc, remote_qpn);
344275 break;
345276 }
346
-
347277 out:
348278 kfree(out);
349279 return param;
....@@ -353,6 +283,7 @@
353283 int index)
354284 {
355285 int outlen = MLX5_ST_SZ_BYTES(query_eq_out);
286
+ u32 in[MLX5_ST_SZ_DW(query_eq_in)] = {};
356287 u64 param = 0;
357288 void *ctx;
358289 u32 *out;
....@@ -362,7 +293,9 @@
362293 if (!out)
363294 return param;
364295
365
- err = mlx5_core_eq_query(dev, eq, out, outlen);
296
+ MLX5_SET(query_eq_in, in, opcode, MLX5_CMD_OP_QUERY_EQ);
297
+ MLX5_SET(query_eq_in, in, eq_number, eq->eqn);
298
+ err = mlx5_cmd_exec_inout(dev, query_eq, in, out);
366299 if (err) {
367300 mlx5_core_warn(dev, "failed to query eq\n");
368301 goto out;
....@@ -399,7 +332,7 @@
399332 if (!out)
400333 return param;
401334
402
- err = mlx5_core_query_cq(dev, cq, out, outlen);
335
+ err = mlx5_core_query_cq(dev, cq, out);
403336 if (err) {
404337 mlx5_core_warn(dev, "failed to query cq\n");
405338 goto out;
....@@ -473,7 +406,6 @@
473406 {
474407 struct mlx5_rsc_debug *d;
475408 char resn[32];
476
- int err;
477409 int i;
478410
479411 d = kzalloc(struct_size(d, fields, nfile), GFP_KERNEL);
....@@ -485,30 +417,15 @@
485417 d->type = type;
486418 sprintf(resn, "0x%x", rsn);
487419 d->root = debugfs_create_dir(resn, root);
488
- if (!d->root) {
489
- err = -ENOMEM;
490
- goto out_free;
491
- }
492420
493421 for (i = 0; i < nfile; i++) {
494422 d->fields[i].i = i;
495
- d->fields[i].dent = debugfs_create_file(field[i], 0400,
496
- d->root, &d->fields[i],
497
- &fops);
498
- if (!d->fields[i].dent) {
499
- err = -ENOMEM;
500
- goto out_rem;
501
- }
423
+ debugfs_create_file(field[i], 0400, d->root, &d->fields[i],
424
+ &fops);
502425 }
503426 *dbg = d;
504427
505428 return 0;
506
-out_rem:
507
- debugfs_remove_recursive(d->root);
508
-
509
-out_free:
510
- kfree(d);
511
- return err;
512429 }
513430
514431 static void rem_res_tree(struct mlx5_rsc_debug *d)
....@@ -532,6 +449,7 @@
532449
533450 return err;
534451 }
452
+EXPORT_SYMBOL(mlx5_debug_qp_add);
535453
536454 void mlx5_debug_qp_remove(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp)
537455 {
....@@ -541,6 +459,7 @@
541459 if (qp->dbg)
542460 rem_res_tree(qp->dbg);
543461 }
462
+EXPORT_SYMBOL(mlx5_debug_qp_remove);
544463
545464 int mlx5_debug_eq_add(struct mlx5_core_dev *dev, struct mlx5_eq *eq)
546465 {
....@@ -588,6 +507,8 @@
588507 if (!mlx5_debugfs_root)
589508 return;
590509
591
- if (cq->dbg)
510
+ if (cq->dbg) {
592511 rem_res_tree(cq->dbg);
512
+ cq->dbg = NULL;
513
+ }
593514 }