Skip to content

Commit 64a6301

Browse files
Hui Tangherbertx
authored andcommitted
crypto: hisilicon/hpre - add debugfs for Hisilicon HPRE
Add debugfs to provides IO operation debug information and add BD processing timeout count function Signed-off-by: Hui Tang <[email protected]> Signed-off-by: Longfang Liu <[email protected]> Signed-off-by: Shukun Tan <[email protected]> Reviewed-by: Zaibo Xu <[email protected]> Reviewed-by: Zhou Wang <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 8213a1a commit 64a6301

File tree

4 files changed

+202
-15
lines changed

4 files changed

+202
-15
lines changed

Documentation/ABI/testing/debugfs-hisi-hpre

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,48 @@ Contact: [email protected]
9393
Description: Dump the status of the QM.
9494
Four states: initiated, started, stopped and closed.
9595
Available for both PF and VF, and take no other effect on HPRE.
96+
97+
What: /sys/kernel/debug/hisi_hpre/<bdf>/hpre_dfx/send_cnt
98+
Date: Apr 2020
99+
100+
Description: Dump the total number of sent requests.
101+
Available for both PF and VF, and take no other effect on HPRE.
102+
103+
What: /sys/kernel/debug/hisi_hpre/<bdf>/hpre_dfx/recv_cnt
104+
Date: Apr 2020
105+
106+
Description: Dump the total number of received requests.
107+
Available for both PF and VF, and take no other effect on HPRE.
108+
109+
What: /sys/kernel/debug/hisi_hpre/<bdf>/hpre_dfx/send_busy_cnt
110+
Date: Apr 2020
111+
112+
Description: Dump the total number of requests sent
113+
with returning busy.
114+
Available for both PF and VF, and take no other effect on HPRE.
115+
116+
What: /sys/kernel/debug/hisi_hpre/<bdf>/hpre_dfx/send_fail_cnt
117+
Date: Apr 2020
118+
119+
Description: Dump the total number of completed but error requests.
120+
Available for both PF and VF, and take no other effect on HPRE.
121+
122+
What: /sys/kernel/debug/hisi_hpre/<bdf>/hpre_dfx/invalid_req_cnt
123+
Date: Apr 2020
124+
125+
Description: Dump the total number of invalid requests being received.
126+
Available for both PF and VF, and take no other effect on HPRE.
127+
128+
What: /sys/kernel/debug/hisi_hpre/<bdf>/hpre_dfx/overtime_thrhld
129+
Date: Apr 2020
130+
131+
Description: Set the threshold time for counting the request which is
132+
processed longer than the threshold.
133+
0: disable(default), 1: 1 microsecond.
134+
Available for both PF and VF, and take no other effect on HPRE.
135+
136+
What: /sys/kernel/debug/hisi_hpre/<bdf>/hpre_dfx/over_thrhld_cnt
137+
Date: Apr 2020
138+
139+
Description: Dump the total number of time out requests.
140+
Available for both PF and VF, and take no other effect on HPRE.

drivers/crypto/hisilicon/hpre/hpre.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ enum hpre_ctrl_dbgfs_file {
2525
HPRE_DEBUG_FILE_NUM,
2626
};
2727

28+
enum hpre_dfx_dbgfs_file {
29+
HPRE_SEND_CNT,
30+
HPRE_RECV_CNT,
31+
HPRE_SEND_FAIL_CNT,
32+
HPRE_SEND_BUSY_CNT,
33+
HPRE_OVER_THRHLD_CNT,
34+
HPRE_OVERTIME_THRHLD,
35+
HPRE_INVALID_REQ_CNT,
36+
HPRE_DFX_FILE_NUM
37+
};
38+
2839
#define HPRE_DEBUGFS_FILE_NUM (HPRE_DEBUG_FILE_NUM + HPRE_CLUSTERS_NUM - 1)
2940

3041
struct hpre_debugfs_file {
@@ -34,13 +45,19 @@ struct hpre_debugfs_file {
3445
struct hpre_debug *debug;
3546
};
3647

48+
struct hpre_dfx {
49+
atomic64_t value;
50+
enum hpre_dfx_dbgfs_file type;
51+
};
52+
3753
/*
3854
* One HPRE controller has one PF and multiple VFs, some global configurations
3955
* which PF has need this structure.
4056
* Just relevant for PF.
4157
*/
4258
struct hpre_debug {
4359
struct dentry *debug_root;
60+
struct hpre_dfx dfx[HPRE_DFX_FILE_NUM];
4461
struct hpre_debugfs_file files[HPRE_DEBUGFS_FILE_NUM];
4562
};
4663

drivers/crypto/hisilicon/hpre/hpre_crypto.c

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/dma-mapping.h>
1111
#include <linux/fips.h>
1212
#include <linux/module.h>
13+
#include <linux/time.h>
1314
#include "hpre.h"
1415

1516
struct hpre_ctx;
@@ -32,6 +33,9 @@ struct hpre_ctx;
3233
#define HPRE_SQE_DONE_SHIFT 30
3334
#define HPRE_DH_MAX_P_SZ 512
3435

36+
#define HPRE_DFX_SEC_TO_US 1000000
37+
#define HPRE_DFX_US_TO_NS 1000
38+
3539
typedef void (*hpre_cb)(struct hpre_ctx *ctx, void *sqe);
3640

3741
struct hpre_rsa_ctx {
@@ -68,6 +72,7 @@ struct hpre_dh_ctx {
6872
struct hpre_ctx {
6973
struct hisi_qp *qp;
7074
struct hpre_asym_request **req_list;
75+
struct hpre *hpre;
7176
spinlock_t req_lock;
7277
unsigned int key_sz;
7378
bool crt_g2_mode;
@@ -90,6 +95,7 @@ struct hpre_asym_request {
9095
int err;
9196
int req_id;
9297
hpre_cb cb;
98+
struct timespec64 req_time;
9399
};
94100

95101
static DEFINE_MUTEX(hpre_alg_lock);
@@ -119,6 +125,7 @@ static void hpre_free_req_id(struct hpre_ctx *ctx, int req_id)
119125
static int hpre_add_req_to_ctx(struct hpre_asym_request *hpre_req)
120126
{
121127
struct hpre_ctx *ctx;
128+
struct hpre_dfx *dfx;
122129
int id;
123130

124131
ctx = hpre_req->ctx;
@@ -129,6 +136,10 @@ static int hpre_add_req_to_ctx(struct hpre_asym_request *hpre_req)
129136
ctx->req_list[id] = hpre_req;
130137
hpre_req->req_id = id;
131138

139+
dfx = ctx->hpre->debug.dfx;
140+
if (atomic64_read(&dfx[HPRE_OVERTIME_THRHLD].value))
141+
ktime_get_ts64(&hpre_req->req_time);
142+
132143
return id;
133144
}
134145

@@ -309,12 +320,16 @@ static int hpre_alg_res_post_hf(struct hpre_ctx *ctx, struct hpre_sqe *sqe,
309320

310321
static int hpre_ctx_set(struct hpre_ctx *ctx, struct hisi_qp *qp, int qlen)
311322
{
323+
struct hpre *hpre;
324+
312325
if (!ctx || !qp || qlen < 0)
313326
return -EINVAL;
314327

315328
spin_lock_init(&ctx->req_lock);
316329
ctx->qp = qp;
317330

331+
hpre = container_of(ctx->qp->qm, struct hpre, qm);
332+
ctx->hpre = hpre;
318333
ctx->req_list = kcalloc(qlen, sizeof(void *), GFP_KERNEL);
319334
if (!ctx->req_list)
320335
return -ENOMEM;
@@ -337,38 +352,80 @@ static void hpre_ctx_clear(struct hpre_ctx *ctx, bool is_clear_all)
337352
ctx->key_sz = 0;
338353
}
339354

355+
static bool hpre_is_bd_timeout(struct hpre_asym_request *req,
356+
u64 overtime_thrhld)
357+
{
358+
struct timespec64 reply_time;
359+
u64 time_use_us;
360+
361+
ktime_get_ts64(&reply_time);
362+
time_use_us = (reply_time.tv_sec - req->req_time.tv_sec) *
363+
HPRE_DFX_SEC_TO_US +
364+
(reply_time.tv_nsec - req->req_time.tv_nsec) /
365+
HPRE_DFX_US_TO_NS;
366+
367+
if (time_use_us <= overtime_thrhld)
368+
return false;
369+
370+
return true;
371+
}
372+
340373
static void hpre_dh_cb(struct hpre_ctx *ctx, void *resp)
341374
{
375+
struct hpre_dfx *dfx = ctx->hpre->debug.dfx;
342376
struct hpre_asym_request *req;
343377
struct kpp_request *areq;
378+
u64 overtime_thrhld;
344379
int ret;
345380

346381
ret = hpre_alg_res_post_hf(ctx, resp, (void **)&req);
347382
areq = req->areq.dh;
348383
areq->dst_len = ctx->key_sz;
384+
385+
overtime_thrhld = atomic64_read(&dfx[HPRE_OVERTIME_THRHLD].value);
386+
if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld))
387+
atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value);
388+
349389
hpre_hw_data_clr_all(ctx, req, areq->dst, areq->src);
350390
kpp_request_complete(areq, ret);
391+
atomic64_inc(&dfx[HPRE_RECV_CNT].value);
351392
}
352393

353394
static void hpre_rsa_cb(struct hpre_ctx *ctx, void *resp)
354395
{
396+
struct hpre_dfx *dfx = ctx->hpre->debug.dfx;
355397
struct hpre_asym_request *req;
356398
struct akcipher_request *areq;
399+
u64 overtime_thrhld;
357400
int ret;
358401

359402
ret = hpre_alg_res_post_hf(ctx, resp, (void **)&req);
403+
404+
overtime_thrhld = atomic64_read(&dfx[HPRE_OVERTIME_THRHLD].value);
405+
if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld))
406+
atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value);
407+
360408
areq = req->areq.rsa;
361409
areq->dst_len = ctx->key_sz;
362410
hpre_hw_data_clr_all(ctx, req, areq->dst, areq->src);
363411
akcipher_request_complete(areq, ret);
412+
atomic64_inc(&dfx[HPRE_RECV_CNT].value);
364413
}
365414

366415
static void hpre_alg_cb(struct hisi_qp *qp, void *resp)
367416
{
368417
struct hpre_ctx *ctx = qp->qp_ctx;
418+
struct hpre_dfx *dfx = ctx->hpre->debug.dfx;
369419
struct hpre_sqe *sqe = resp;
420+
struct hpre_asym_request *req = ctx->req_list[le16_to_cpu(sqe->tag)];
370421

371-
ctx->req_list[le16_to_cpu(sqe->tag)]->cb(ctx, resp);
422+
423+
if (unlikely(!req)) {
424+
atomic64_inc(&dfx[HPRE_INVALID_REQ_CNT].value);
425+
return;
426+
}
427+
428+
req->cb(ctx, resp);
372429
}
373430

374431
static int hpre_ctx_init(struct hpre_ctx *ctx)
@@ -436,6 +493,29 @@ static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa)
436493
return 0;
437494
}
438495

496+
static int hpre_send(struct hpre_ctx *ctx, struct hpre_sqe *msg)
497+
{
498+
struct hpre_dfx *dfx = ctx->hpre->debug.dfx;
499+
int ctr = 0;
500+
int ret;
501+
502+
do {
503+
atomic64_inc(&dfx[HPRE_SEND_CNT].value);
504+
ret = hisi_qp_send(ctx->qp, msg);
505+
if (ret != -EBUSY)
506+
break;
507+
atomic64_inc(&dfx[HPRE_SEND_BUSY_CNT].value);
508+
} while (ctr++ < HPRE_TRY_SEND_TIMES);
509+
510+
if (likely(!ret))
511+
return ret;
512+
513+
if (ret != -EBUSY)
514+
atomic64_inc(&dfx[HPRE_SEND_FAIL_CNT].value);
515+
516+
return ret;
517+
}
518+
439519
#ifdef CONFIG_CRYPTO_DH
440520
static int hpre_dh_compute_value(struct kpp_request *req)
441521
{
@@ -444,7 +524,6 @@ static int hpre_dh_compute_value(struct kpp_request *req)
444524
void *tmp = kpp_request_ctx(req);
445525
struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
446526
struct hpre_sqe *msg = &hpre_req->req;
447-
int ctr = 0;
448527
int ret;
449528

450529
ret = hpre_msg_request_set(ctx, req, false);
@@ -465,11 +544,9 @@ static int hpre_dh_compute_value(struct kpp_request *req)
465544
msg->dw0 = cpu_to_le32(le32_to_cpu(msg->dw0) | HPRE_ALG_DH_G2);
466545
else
467546
msg->dw0 = cpu_to_le32(le32_to_cpu(msg->dw0) | HPRE_ALG_DH);
468-
do {
469-
ret = hisi_qp_send(ctx->qp, msg);
470-
} while (ret == -EBUSY && ctr++ < HPRE_TRY_SEND_TIMES);
471547

472548
/* success */
549+
ret = hpre_send(ctx, msg);
473550
if (likely(!ret))
474551
return -EINPROGRESS;
475552

@@ -647,7 +724,6 @@ static int hpre_rsa_enc(struct akcipher_request *req)
647724
void *tmp = akcipher_request_ctx(req);
648725
struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
649726
struct hpre_sqe *msg = &hpre_req->req;
650-
int ctr = 0;
651727
int ret;
652728

653729
/* For 512 and 1536 bits key size, use soft tfm instead */
@@ -677,11 +753,8 @@ static int hpre_rsa_enc(struct akcipher_request *req)
677753
if (unlikely(ret))
678754
goto clear_all;
679755

680-
do {
681-
ret = hisi_qp_send(ctx->qp, msg);
682-
} while (ret == -EBUSY && ctr++ < HPRE_TRY_SEND_TIMES);
683-
684756
/* success */
757+
ret = hpre_send(ctx, msg);
685758
if (likely(!ret))
686759
return -EINPROGRESS;
687760

@@ -699,7 +772,6 @@ static int hpre_rsa_dec(struct akcipher_request *req)
699772
void *tmp = akcipher_request_ctx(req);
700773
struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
701774
struct hpre_sqe *msg = &hpre_req->req;
702-
int ctr = 0;
703775
int ret;
704776

705777
/* For 512 and 1536 bits key size, use soft tfm instead */
@@ -736,11 +808,8 @@ static int hpre_rsa_dec(struct akcipher_request *req)
736808
if (unlikely(ret))
737809
goto clear_all;
738810

739-
do {
740-
ret = hisi_qp_send(ctx->qp, msg);
741-
} while (ret == -EBUSY && ctr++ < HPRE_TRY_SEND_TIMES);
742-
743811
/* success */
812+
ret = hpre_send(ctx, msg);
744813
if (likely(!ret))
745814
return -EINPROGRESS;
746815

0 commit comments

Comments
 (0)