Skip to content

Commit 8213a1a

Browse files
yekai123123herbertx
authored andcommitted
crypto: hisilicon/sec2 - add debugfs for Hisilicon SEC
Hisilicon SEC engine driver uses debugfs to provides IO operation debug information Signed-off-by: Kai Ye <[email protected]> Signed-off-by: Longfang Liu <[email protected]> Signed-off-by: Shukun Tan <[email protected]> Reviewed-by: Zhou Wang <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 0a3a396 commit 8213a1a

File tree

4 files changed

+95
-21
lines changed

4 files changed

+95
-21
lines changed

Documentation/ABI/testing/debugfs-hisi-sec

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
What: /sys/kernel/debug/hisi_sec/<bdf>/sec_dfx
2-
Date: Oct 2019
3-
4-
Description: Dump the debug registers of SEC cores.
5-
Only available for PF.
6-
7-
What: /sys/kernel/debug/hisi_sec/<bdf>/clear_enable
1+
What: /sys/kernel/debug/hisi_sec2/<bdf>/clear_enable
82
Date: Oct 2019
93
104
Description: Enabling/disabling of clear action after reading
115
the SEC debug registers.
126
0: disable, 1: enable.
137
Only available for PF, and take no other effect on SEC.
148

15-
What: /sys/kernel/debug/hisi_sec/<bdf>/current_qm
9+
What: /sys/kernel/debug/hisi_sec2/<bdf>/current_qm
1610
Date: Oct 2019
1711
1812
Description: One SEC controller has one PF and multiple VFs, each function
1913
has a QM. This file can be used to select the QM which below
2014
qm refers to.
2115
Only available for PF.
2216

23-
What: /sys/kernel/debug/hisi_sec/<bdf>/qm/qm_regs
17+
What: /sys/kernel/debug/hisi_sec2/<bdf>/qm/qm_regs
2418
Date: Oct 2019
2519
2620
Description: Dump of QM related debug registers.
2721
Available for PF and VF in host. VF in guest currently only
2822
has one debug register.
2923

30-
What: /sys/kernel/debug/hisi_sec/<bdf>/qm/current_q
24+
What: /sys/kernel/debug/hisi_sec2/<bdf>/qm/current_q
3125
Date: Oct 2019
3226
3327
Description: One QM of SEC may contain multiple queues. Select specific
3428
queue to show its debug registers in above 'qm_regs'.
3529
Only available for PF.
3630

37-
What: /sys/kernel/debug/hisi_sec/<bdf>/qm/clear_enable
31+
What: /sys/kernel/debug/hisi_sec2/<bdf>/qm/clear_enable
3832
Date: Oct 2019
3933
4034
Description: Enabling/disabling of clear action after reading
@@ -79,3 +73,41 @@ Contact: [email protected]
7973
Description: Dump the status of the QM.
8074
Four states: initiated, started, stopped and closed.
8175
Available for both PF and VF, and take no other effect on SEC.
76+
77+
What: /sys/kernel/debug/hisi_sec2/<bdf>/sec_dfx/send_cnt
78+
Date: Apr 2020
79+
80+
Description: Dump the total number of sent requests.
81+
Available for both PF and VF, and take no other effect on SEC.
82+
83+
What: /sys/kernel/debug/hisi_sec2/<bdf>/sec_dfx/recv_cnt
84+
Date: Apr 2020
85+
86+
Description: Dump the total number of received requests.
87+
Available for both PF and VF, and take no other effect on SEC.
88+
89+
What: /sys/kernel/debug/hisi_sec2/<bdf>/sec_dfx/send_busy_cnt
90+
Date: Apr 2020
91+
92+
Description: Dump the total number of requests sent with returning busy.
93+
Available for both PF and VF, and take no other effect on SEC.
94+
95+
What: /sys/kernel/debug/hisi_sec2/<bdf>/sec_dfx/err_bd_cnt
96+
Date: Apr 2020
97+
98+
Description: Dump the total number of BD type error requests
99+
to be received.
100+
Available for both PF and VF, and take no other effect on SEC.
101+
102+
What: /sys/kernel/debug/hisi_sec2/<bdf>/sec_dfx/invalid_req_cnt
103+
Date: Apr 2020
104+
105+
Description: Dump the total number of invalid requests being received.
106+
Available for both PF and VF, and take no other effect on SEC.
107+
108+
What: /sys/kernel/debug/hisi_sec2/<bdf>/sec_dfx/done_flag_cnt
109+
Date: Apr 2020
110+
111+
Description: Dump the total number of completed but marked error requests
112+
to be received.
113+
Available for both PF and VF, and take no other effect on SEC.

drivers/crypto/hisilicon/sec2/sec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ struct sec_debug_file {
160160
struct sec_dfx {
161161
atomic64_t send_cnt;
162162
atomic64_t recv_cnt;
163+
atomic64_t send_busy_cnt;
164+
atomic64_t err_bd_cnt;
165+
atomic64_t invalid_req_cnt;
166+
atomic64_t done_flag_cnt;
163167
};
164168

165169
struct sec_debug {

drivers/crypto/hisilicon/sec2/sec_crypto.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static int sec_aead_verify(struct sec_req *req)
148148
static void sec_req_cb(struct hisi_qp *qp, void *resp)
149149
{
150150
struct sec_qp_ctx *qp_ctx = qp->qp_ctx;
151+
struct sec_dfx *dfx = &qp_ctx->ctx->sec->debug.dfx;
151152
struct sec_sqe *bd = resp;
152153
struct sec_ctx *ctx;
153154
struct sec_req *req;
@@ -157,11 +158,16 @@ static void sec_req_cb(struct hisi_qp *qp, void *resp)
157158

158159
type = bd->type_cipher_auth & SEC_TYPE_MASK;
159160
if (unlikely(type != SEC_BD_TYPE2)) {
161+
atomic64_inc(&dfx->err_bd_cnt);
160162
pr_err("err bd type [%d]\n", type);
161163
return;
162164
}
163165

164166
req = qp_ctx->req_list[le16_to_cpu(bd->type2.tag)];
167+
if (unlikely(!req)) {
168+
atomic64_inc(&dfx->invalid_req_cnt);
169+
return;
170+
}
165171
req->err_type = bd->type2.error_type;
166172
ctx = req->ctx;
167173
done = le16_to_cpu(bd->type2.done_flag) & SEC_DONE_MASK;
@@ -174,12 +180,13 @@ static void sec_req_cb(struct hisi_qp *qp, void *resp)
174180
"err_type[%d],done[%d],flag[%d]\n",
175181
req->err_type, done, flag);
176182
err = -EIO;
183+
atomic64_inc(&dfx->done_flag_cnt);
177184
}
178185

179186
if (ctx->alg_type == SEC_AEAD && !req->c_req.encrypt)
180187
err = sec_aead_verify(req);
181188

182-
atomic64_inc(&ctx->sec->debug.dfx.recv_cnt);
189+
atomic64_inc(&dfx->recv_cnt);
183190

184191
ctx->req_op->buf_unmap(ctx, req);
185192

@@ -200,10 +207,12 @@ static int sec_bd_send(struct sec_ctx *ctx, struct sec_req *req)
200207
return -ENOBUFS;
201208

202209
if (!ret) {
203-
if (req->fake_busy)
210+
if (req->fake_busy) {
211+
atomic64_inc(&ctx->sec->debug.dfx.send_busy_cnt);
204212
ret = -EBUSY;
205-
else
213+
} else {
206214
ret = -EINPROGRESS;
215+
}
207216
}
208217

209218
return ret;

drivers/crypto/hisilicon/sec2/sec_main.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ struct sec_hw_error {
8888
const char *msg;
8989
};
9090

91+
struct sec_dfx_item {
92+
const char *name;
93+
u32 offset;
94+
};
95+
9196
static const char sec_name[] = "hisi_sec2";
9297
static struct dentry *sec_debugfs_root;
9398
static struct hisi_qm_list sec_devices;
@@ -110,6 +115,15 @@ static const char * const sec_dbg_file_name[] = {
110115
[SEC_CLEAR_ENABLE] = "clear_enable",
111116
};
112117

118+
static struct sec_dfx_item sec_dfx_labels[] = {
119+
{"send_cnt", offsetof(struct sec_dfx, send_cnt)},
120+
{"recv_cnt", offsetof(struct sec_dfx, recv_cnt)},
121+
{"send_busy_cnt", offsetof(struct sec_dfx, send_busy_cnt)},
122+
{"err_bd_cnt", offsetof(struct sec_dfx, err_bd_cnt)},
123+
{"invalid_req_cnt", offsetof(struct sec_dfx, invalid_req_cnt)},
124+
{"done_flag_cnt", offsetof(struct sec_dfx, done_flag_cnt)},
125+
};
126+
113127
static const struct debugfs_reg32 sec_dfx_regs[] = {
114128
{"SEC_PF_ABNORMAL_INT_SOURCE ", 0x301010},
115129
{"SEC_SAA_EN ", 0x301270},
@@ -543,10 +557,22 @@ static const struct file_operations sec_dbg_fops = {
543557
static int sec_debugfs_atomic64_get(void *data, u64 *val)
544558
{
545559
*val = atomic64_read((atomic64_t *)data);
560+
561+
return 0;
562+
}
563+
564+
static int sec_debugfs_atomic64_set(void *data, u64 val)
565+
{
566+
if (val)
567+
return -EINVAL;
568+
569+
atomic64_set((atomic64_t *)data, 0);
570+
546571
return 0;
547572
}
573+
548574
DEFINE_DEBUGFS_ATTRIBUTE(sec_atomic64_ops, sec_debugfs_atomic64_get,
549-
NULL, "%lld\n");
575+
sec_debugfs_atomic64_set, "%lld\n");
550576

551577
static int sec_core_debug_init(struct sec_dev *sec)
552578
{
@@ -555,6 +581,7 @@ static int sec_core_debug_init(struct sec_dev *sec)
555581
struct sec_dfx *dfx = &sec->debug.dfx;
556582
struct debugfs_regset32 *regset;
557583
struct dentry *tmp_d;
584+
int i;
558585

559586
tmp_d = debugfs_create_dir("sec_dfx", sec->qm.debug.debug_root);
560587

@@ -566,13 +593,15 @@ static int sec_core_debug_init(struct sec_dev *sec)
566593
regset->nregs = ARRAY_SIZE(sec_dfx_regs);
567594
regset->base = qm->io_base;
568595

569-
debugfs_create_regset32("regs", 0444, tmp_d, regset);
596+
if (qm->pdev->device == SEC_PF_PCI_DEVICE_ID)
597+
debugfs_create_regset32("regs", 0444, tmp_d, regset);
570598

571-
debugfs_create_file("send_cnt", 0444, tmp_d,
572-
&dfx->send_cnt, &sec_atomic64_ops);
573-
574-
debugfs_create_file("recv_cnt", 0444, tmp_d,
575-
&dfx->recv_cnt, &sec_atomic64_ops);
599+
for (i = 0; i < ARRAY_SIZE(sec_dfx_labels); i++) {
600+
atomic64_t *data = (atomic64_t *)((uintptr_t)dfx +
601+
sec_dfx_labels[i].offset);
602+
debugfs_create_file(sec_dfx_labels[i].name, 0644,
603+
tmp_d, data, &sec_atomic64_ops);
604+
}
576605

577606
return 0;
578607
}

0 commit comments

Comments
 (0)