1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2023 Hisilicon Limited.
*/
#include <linux/cleanup.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/pci.h>
#include "hns_roce_device.h"
#include "hns_roce_hw_v2.h"
static struct dentry *hns_roce_dbgfs_root;
static int hns_debugfs_seqfile_open(struct inode *inode, struct file *f)
{
struct hns_debugfs_seqfile *seqfile = inode->i_private;
return single_open(f, seqfile->read, seqfile->data);
}
static ssize_t hns_debugfs_seqfile_write(struct file *file,
const char __user *buffer,
size_t count, loff_t *ppos)
{
struct hns_debugfs_seqfile *seqfile = file_inode(file)->i_private;
char buf[16] = {};
if (!seqfile->write)
return -EOPNOTSUPP;
if (count >= sizeof(buf))
return -EINVAL;
if (copy_from_user(buf, buffer, count))
return -EFAULT;
return seqfile->write(buf, count, seqfile->data);
}
static const struct file_operations hns_debugfs_seqfile_fops = {
.owner = THIS_MODULE,
.open = hns_debugfs_seqfile_open,
.release = single_release,
.read = seq_read,
.write = hns_debugfs_seqfile_write,
.llseek = seq_lseek
};
static const char * const sw_stat_info[] = {
[HNS_ROCE_DFX_AEQE_CNT] = "aeqe",
[HNS_ROCE_DFX_CEQE_CNT] = "ceqe",
[HNS_ROCE_DFX_CMDS_CNT] = "cmds",
[HNS_ROCE_DFX_CMDS_ERR_CNT] = "cmds_err",
[HNS_ROCE_DFX_MBX_POSTED_CNT] = "posted_mbx",
[HNS_ROCE_DFX_MBX_POLLED_CNT] = "polled_mbx",
[HNS_ROCE_DFX_MBX_EVENT_CNT] = "mbx_event",
[HNS_ROCE_DFX_QP_CREATE_ERR_CNT] = "qp_create_err",
[HNS_ROCE_DFX_QP_MODIFY_ERR_CNT] = "qp_modify_err",
[HNS_ROCE_DFX_CQ_CREATE_ERR_CNT] = "cq_create_err",
[HNS_ROCE_DFX_CQ_MODIFY_ERR_CNT] = "cq_modify_err",
[HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT] = "srq_create_err",
[HNS_ROCE_DFX_SRQ_MODIFY_ERR_CNT] = "srq_modify_err",
[HNS_ROCE_DFX_XRCD_ALLOC_ERR_CNT] = "xrcd_alloc_err",
[HNS_ROCE_DFX_MR_REG_ERR_CNT] = "mr_reg_err",
[HNS_ROCE_DFX_MR_REREG_ERR_CNT] = "mr_rereg_err",
[HNS_ROCE_DFX_AH_CREATE_ERR_CNT] = "ah_create_err",
[HNS_ROCE_DFX_MMAP_ERR_CNT] = "mmap_err",
[HNS_ROCE_DFX_UCTX_ALLOC_ERR_CNT] = "uctx_alloc_err",
};
static int sw_stat_debugfs_show(struct seq_file *file, void *offset)
{
struct hns_roce_dev *hr_dev = file->private;
int i;
for (i = 0; i < HNS_ROCE_DFX_CNT_TOTAL; i++)
seq_printf(file, "%-20s --- %lld\n", sw_stat_info[i],
atomic64_read(&hr_dev->dfx_cnt[i]));
return 0;
}
static void create_sw_stat_debugfs(struct hns_roce_dev *hr_dev,
struct dentry *parent)
{
struct hns_sw_stat_debugfs *dbgfs = &hr_dev->dbgfs.sw_stat_root;
dbgfs->sw_stat.read = sw_stat_debugfs_show;
dbgfs->sw_stat.data = hr_dev;
dbgfs->root = debugfs_create_dir("sw_stat", parent);
debugfs_create_file("sw_stat", 0400, dbgfs->root, &dbgfs->sw_stat,
&hns_debugfs_seqfile_fops);
}
#define __HNS_SCC_ATTR(_name, _type, _offset, _size, _min, _max) { \
.name = _name, \
.algo_type = _type, \
.offset = _offset, \
.size = _size, \
.min = _min, \
.max = _max, \
}
#define HNS_DCQCN_CC_ATTR_RW(_name, NAME) \
__HNS_SCC_ATTR(_name, HNS_ROCE_SCC_ALGO_DCQCN, \
HNS_ROCE_DCQCN_##NAME##_OFS, \
HNS_ROCE_DCQCN_##NAME##_SZ, \
0, HNS_ROCE_DCQCN_##NAME##_MAX)
#define HNS_LDCP_CC_ATTR_RW(_name, NAME) \
__HNS_SCC_ATTR(_name, HNS_ROCE_SCC_ALGO_LDCP, \
HNS_ROCE_LDCP_##NAME##_OFS, \
HNS_ROCE_LDCP_##NAME##_SZ, \
0, HNS_ROCE_LDCP_##NAME##_MAX)
#define HNS_HC3_CC_ATTR_RW(_name, NAME) \
__HNS_SCC_ATTR(_name, HNS_ROCE_SCC_ALGO_HC3, \
HNS_ROCE_HC3_##NAME##_OFS, \
HNS_ROCE_HC3_##NAME##_SZ, \
HNS_ROCE_HC3_##NAME##_MIN, \
HNS_ROCE_HC3_##NAME##_MAX)
#define HNS_DIP_CC_ATTR_RW(_name, NAME) \
__HNS_SCC_ATTR(_name, HNS_ROCE_SCC_ALGO_DIP, \
HNS_ROCE_DIP_##NAME##_OFS, \
HNS_ROCE_DIP_##NAME##_SZ, \
0, HNS_ROCE_DIP_##NAME##_MAX)
static const struct hns_roce_cong_attr {
enum hns_roce_cong_type cong_type;
const char *name;
struct hns_roce_cc_param_attr params[HNS_ROCE_CC_PARAM_MAX_NUM];
} cong_attrs[] = {
{ CONG_TYPE_DCQCN, "dcqcn_cc_param",
{
HNS_DCQCN_CC_ATTR_RW("ai", AI),
HNS_DCQCN_CC_ATTR_RW("f", F),
HNS_DCQCN_CC_ATTR_RW("tkp", TKP),
HNS_DCQCN_CC_ATTR_RW("tmp", TMP),
HNS_DCQCN_CC_ATTR_RW("alp", ALP),
HNS_DCQCN_CC_ATTR_RW("max_speed", MAX_SPEED),
HNS_DCQCN_CC_ATTR_RW("g", G),
HNS_DCQCN_CC_ATTR_RW("al", AL),
HNS_DCQCN_CC_ATTR_RW("cnp_time", CNP_TIME),
HNS_DCQCN_CC_ATTR_RW("ashift", ASHIFT),
}
},
{ CONG_TYPE_LDCP, "ldcp_cc_param",
{
HNS_LDCP_CC_ATTR_RW("cwd0", CWD0),
HNS_LDCP_CC_ATTR_RW("alpha", ALPHA),
HNS_LDCP_CC_ATTR_RW("gamma", GAMMA),
HNS_LDCP_CC_ATTR_RW("beta", BETA),
HNS_LDCP_CC_ATTR_RW("eta", ETA),
}
},
{ CONG_TYPE_HC3, "hc3_cc_param",
{
HNS_HC3_CC_ATTR_RW("initial_window", INITIAL_WINDOW),
HNS_HC3_CC_ATTR_RW("bandwidth", BANDWIDTH),
HNS_HC3_CC_ATTR_RW("qlen_shift", QLEN_SHIFT),
HNS_HC3_CC_ATTR_RW("port_usage_shift", PORT_USAGE_SHIFT),
HNS_HC3_CC_ATTR_RW("over_period", OVER_PERIOD),
HNS_HC3_CC_ATTR_RW("max_stage", MAX_STAGE),
HNS_HC3_CC_ATTR_RW("gamma_shift", GAMMA_SHIFT),
}
},
{ CONG_TYPE_DIP, "dip_cc_param",
{
HNS_DIP_CC_ATTR_RW("ai", AI),
HNS_DIP_CC_ATTR_RW("f", F),
HNS_DIP_CC_ATTR_RW("tkp", TKP),
HNS_DIP_CC_ATTR_RW("tmp", TMP),
HNS_DIP_CC_ATTR_RW("alp", ALP),
HNS_DIP_CC_ATTR_RW("max_speed", MAX_SPEED),
HNS_DIP_CC_ATTR_RW("g", G),
HNS_DIP_CC_ATTR_RW("al", AL),
HNS_DIP_CC_ATTR_RW("cnp_time", CNP_TIME),
HNS_DIP_CC_ATTR_RW("ashift", ASHIFT),
}
}
};
static int cc_param_debugfs_show(struct seq_file *file, void *offset)
{
struct hns_cc_param_seqfile *param_seqfile = file->private;
const struct hns_roce_cc_param_attr *param_attr = param_seqfile->param_attr;
int algo_type = param_attr->algo_type;
int index = param_seqfile->index;
struct hns_roce_dev *hr_dev =
container_of(param_seqfile, struct hns_roce_dev,
dbgfs.cc_param_root[algo_type].params[index]);
struct hns_roce_scc_param *scc_param;
__le32 val = 0;
scc_param = &hr_dev->scc_param[algo_type];
scoped_guard(mutex, &scc_param->scc_mutex) {
memcpy(&val,
(void *)scc_param->param + param_attr->offset,
param_attr->size);
}
seq_printf(file, "%u\n", le32_to_cpu(val));
return 0;
}
static ssize_t cc_param_debugfs_store(char *buf, size_t count, void *data)
{
struct hns_cc_param_seqfile *param_seqfile = data;
const struct hns_roce_cc_param_attr *param_attr = param_seqfile->param_attr;
int algo_type = param_attr->algo_type;
int index = param_seqfile->index;
struct hns_roce_dev *hr_dev =
container_of(param_seqfile, struct hns_roce_dev,
dbgfs.cc_param_root[algo_type].params[index]);
struct hns_roce_scc_param *scc_param;
__le32 attr_val, old_val = 0;
u32 val;
int ret;
if (kstrtou32(buf, 0, &val))
return -EINVAL;
if (val > param_attr->max || val < param_attr->min)
return -EINVAL;
attr_val = cpu_to_le32(val);
scc_param = &hr_dev->scc_param[algo_type];
guard(mutex)(&scc_param->scc_mutex);
memcpy(&old_val, (void *)scc_param->param + param_attr->offset,
param_attr->size);
memcpy((void *)scc_param->param + param_attr->offset, &attr_val,
param_attr->size);
ret = hr_dev->hw->config_scc_param(hr_dev, algo_type);
if (ret) {
memcpy((void *)scc_param->param + param_attr->offset, &old_val,
param_attr->size);
return ret;
}
return count;
}
static void get_default_scc_param(struct hns_roce_dev *hr_dev)
{
int ret;
int i;
for (i = 0; i < HNS_ROCE_SCC_ALGO_TOTAL; i++) {
ret = hr_dev->hw->query_scc_param(hr_dev, i);
if (ret && ret != -EOPNOTSUPP)
ibdev_warn_ratelimited(&hr_dev->ib_dev,
"failed to get default parameters of scc algo %d, ret = %d.\n",
i, ret);
}
}
static int hns_roce_alloc_scc_param(struct hns_roce_dev *hr_dev)
{
struct hns_roce_scc_param *scc_param;
int i;
scc_param = kvzalloc_objs(*scc_param, HNS_ROCE_SCC_ALGO_TOTAL);
if (!scc_param)
return -ENOMEM;
for (i = 0; i < HNS_ROCE_SCC_ALGO_TOTAL; i++) {
scc_param[i].algo_type = i;
scc_param[i].hr_dev = hr_dev;
mutex_init(&scc_param[i].scc_mutex);
}
hr_dev->scc_param = scc_param;
get_default_scc_param(hr_dev);
return 0;
}
static void hns_roce_dealloc_scc_param(struct hns_roce_dev *hr_dev)
{
int i;
if (!hr_dev->scc_param)
return;
for (i = 0; i < HNS_ROCE_SCC_ALGO_TOTAL; i++)
mutex_destroy(&hr_dev->scc_param[i].scc_mutex);
kvfree(hr_dev->scc_param);
}
static void create_cc_param_debugfs(struct hns_roce_dev *hr_dev,
struct dentry *parent)
{
const struct hns_roce_cong_attr *cong_attr;
struct hns_cc_param_debugfs *dbgfs;
int i, j;
int ret;
if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 ||
!(hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL) ||
hr_dev->is_vf)
return;
ret = hns_roce_alloc_scc_param(hr_dev);
if (ret)
return;
for (i = 0; i < CONG_TYPE_MAX_NUM; i++) {
cong_attr = &cong_attrs[i];
if (!test_bit(cong_attr->cong_type,
(unsigned long *)&hr_dev->caps.cong_cap))
continue;
dbgfs = &hr_dev->dbgfs.cc_param_root[i];
dbgfs->root = debugfs_create_dir(cong_attr->name, parent);
for (j = 0; j < HNS_ROCE_CC_PARAM_MAX_NUM; j++) {
if (!cong_attr->params[j].name)
break;
dbgfs->params[j].param_attr = &cong_attr->params[j];
dbgfs->params[j].index = j;
dbgfs->params[j].seqfile.read = cc_param_debugfs_show;
dbgfs->params[j].seqfile.write = cc_param_debugfs_store;
dbgfs->params[j].seqfile.data = &dbgfs->params[j];
debugfs_create_file(cong_attr->params[j].name, 0600,
dbgfs->root,
&dbgfs->params[j].seqfile,
&hns_debugfs_seqfile_fops);
}
}
}
/* debugfs for device */
void hns_roce_register_debugfs(struct hns_roce_dev *hr_dev)
{
struct hns_roce_dev_debugfs *dbgfs = &hr_dev->dbgfs;
dbgfs->root = debugfs_create_dir(pci_name(hr_dev->pci_dev),
hns_roce_dbgfs_root);
create_sw_stat_debugfs(hr_dev, dbgfs->root);
create_cc_param_debugfs(hr_dev, dbgfs->root);
}
void hns_roce_unregister_debugfs(struct hns_roce_dev *hr_dev)
{
debugfs_remove_recursive(hr_dev->dbgfs.root);
hns_roce_dealloc_scc_param(hr_dev);
}
/* debugfs for hns module */
void hns_roce_init_debugfs(void)
{
hns_roce_dbgfs_root = debugfs_create_dir("hns_roce", NULL);
}
void hns_roce_cleanup_debugfs(void)
{
debugfs_remove_recursive(hns_roce_dbgfs_root);
hns_roce_dbgfs_root = NULL;
}
|