Skip to content

Commit abd9875

Browse files
horiagherbertx
authored andcommitted
crypto: caam - Move debugfs fops into standalone file
Currently the debugfs fops are defined in caam/intern.h. This causes problems because it creates identical static functions and variables in multiple files. It also creates warnings when those files don't use the fops. This patch moves them into a standalone file, debugfs.c. It also removes unnecessary uses of ifdefs on CONFIG_DEBUG_FS. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> [Moved most of debugfs-related operations into debugfs.c.] Signed-off-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent c0f6eeb commit abd9875

6 files changed

Lines changed: 136 additions & 102 deletions

File tree

‎drivers/crypto/caam/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ ifneq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI),)
2727
ccflags-y += -DCONFIG_CAAM_QI
2828
endif
2929

30+
caam-$(CONFIG_DEBUG_FS) += debugfs.o
31+
3032
obj-$(CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM) += dpaa2_caam.o
3133

3234
dpaa2_caam-y := caamalg_qi2.o dpseci.o

‎drivers/crypto/caam/ctrl.c‎

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/fsl/mc.h>
1414

1515
#include "compat.h"
16+
#include "debugfs.h"
1617
#include "regs.h"
1718
#include "intern.h"
1819
#include "jr.h"
@@ -582,12 +583,10 @@ static int init_clocks(struct device *dev, const struct caam_imx_data *data)
582583
return devm_add_action_or_reset(dev, disable_clocks, ctrlpriv);
583584
}
584585

585-
#ifdef CONFIG_DEBUG_FS
586586
static void caam_remove_debugfs(void *root)
587587
{
588588
debugfs_remove_recursive(root);
589589
}
590-
#endif
591590

592591
#ifdef CONFIG_FSL_MC_BUS
593592
static bool check_version(struct fsl_mc_version *mc_version, u32 major,
@@ -619,10 +618,7 @@ static int caam_probe(struct platform_device *pdev)
619618
struct device_node *nprop, *np;
620619
struct caam_ctrl __iomem *ctrl;
621620
struct caam_drv_private *ctrlpriv;
622-
#ifdef CONFIG_DEBUG_FS
623-
struct caam_perfmon *perfmon;
624621
struct dentry *dfs_root;
625-
#endif
626622
u32 scfgr, comp_params;
627623
u8 rng_vid;
628624
int pg_size;
@@ -777,21 +773,15 @@ static int caam_probe(struct platform_device *pdev)
777773
ctrlpriv->era = caam_get_era(ctrl);
778774
ctrlpriv->domain = iommu_get_domain_for_dev(dev);
779775

780-
#ifdef CONFIG_DEBUG_FS
781-
/*
782-
* FIXME: needs better naming distinction, as some amalgamation of
783-
* "caam" and nprop->full_name. The OF name isn't distinctive,
784-
* but does separate instances
785-
*/
786-
perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
787-
788776
dfs_root = debugfs_create_dir(dev_name(dev), NULL);
789-
ret = devm_add_action_or_reset(dev, caam_remove_debugfs, dfs_root);
790-
if (ret)
791-
return ret;
777+
if (IS_ENABLED(CONFIG_DEBUG_FS)) {
778+
ret = devm_add_action_or_reset(dev, caam_remove_debugfs,
779+
dfs_root);
780+
if (ret)
781+
return ret;
782+
}
792783

793-
ctrlpriv->ctl = debugfs_create_dir("ctl", dfs_root);
794-
#endif
784+
caam_debugfs_init(ctrlpriv, dfs_root);
795785

796786
/* Check to see if (DPAA 1.x) QI present. If so, enable */
797787
if (ctrlpriv->qi_present && !caam_dpaa2) {
@@ -912,57 +902,6 @@ static int caam_probe(struct platform_device *pdev)
912902
dev_info(dev, "job rings = %d, qi = %d\n",
913903
ctrlpriv->total_jobrs, ctrlpriv->qi_present);
914904

915-
#ifdef CONFIG_DEBUG_FS
916-
debugfs_create_file("rq_dequeued", S_IRUSR | S_IRGRP | S_IROTH,
917-
ctrlpriv->ctl, &perfmon->req_dequeued,
918-
&caam_fops_u64_ro);
919-
debugfs_create_file("ob_rq_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
920-
ctrlpriv->ctl, &perfmon->ob_enc_req,
921-
&caam_fops_u64_ro);
922-
debugfs_create_file("ib_rq_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
923-
ctrlpriv->ctl, &perfmon->ib_dec_req,
924-
&caam_fops_u64_ro);
925-
debugfs_create_file("ob_bytes_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
926-
ctrlpriv->ctl, &perfmon->ob_enc_bytes,
927-
&caam_fops_u64_ro);
928-
debugfs_create_file("ob_bytes_protected", S_IRUSR | S_IRGRP | S_IROTH,
929-
ctrlpriv->ctl, &perfmon->ob_prot_bytes,
930-
&caam_fops_u64_ro);
931-
debugfs_create_file("ib_bytes_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
932-
ctrlpriv->ctl, &perfmon->ib_dec_bytes,
933-
&caam_fops_u64_ro);
934-
debugfs_create_file("ib_bytes_validated", S_IRUSR | S_IRGRP | S_IROTH,
935-
ctrlpriv->ctl, &perfmon->ib_valid_bytes,
936-
&caam_fops_u64_ro);
937-
938-
/* Controller level - global status values */
939-
debugfs_create_file("fault_addr", S_IRUSR | S_IRGRP | S_IROTH,
940-
ctrlpriv->ctl, &perfmon->faultaddr,
941-
&caam_fops_u32_ro);
942-
debugfs_create_file("fault_detail", S_IRUSR | S_IRGRP | S_IROTH,
943-
ctrlpriv->ctl, &perfmon->faultdetail,
944-
&caam_fops_u32_ro);
945-
debugfs_create_file("fault_status", S_IRUSR | S_IRGRP | S_IROTH,
946-
ctrlpriv->ctl, &perfmon->status,
947-
&caam_fops_u32_ro);
948-
949-
/* Internal covering keys (useful in non-secure mode only) */
950-
ctrlpriv->ctl_kek_wrap.data = (__force void *)&ctrlpriv->ctrl->kek[0];
951-
ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
952-
debugfs_create_blob("kek", S_IRUSR | S_IRGRP | S_IROTH, ctrlpriv->ctl,
953-
&ctrlpriv->ctl_kek_wrap);
954-
955-
ctrlpriv->ctl_tkek_wrap.data = (__force void *)&ctrlpriv->ctrl->tkek[0];
956-
ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
957-
debugfs_create_blob("tkek", S_IRUSR | S_IRGRP | S_IROTH, ctrlpriv->ctl,
958-
&ctrlpriv->ctl_tkek_wrap);
959-
960-
ctrlpriv->ctl_tdsk_wrap.data = (__force void *)&ctrlpriv->ctrl->tdsk[0];
961-
ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
962-
debugfs_create_blob("tdsk", S_IRUSR | S_IRGRP | S_IROTH, ctrlpriv->ctl,
963-
&ctrlpriv->ctl_tdsk_wrap);
964-
#endif
965-
966905
ret = devm_of_platform_populate(dev);
967906
if (ret)
968907
dev_err(dev, "JR platform devices creation error\n");

‎drivers/crypto/caam/debugfs.c‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2+
/* Copyright 2019 NXP */
3+
4+
#include <linux/debugfs.h>
5+
#include "compat.h"
6+
#include "debugfs.h"
7+
#include "regs.h"
8+
#include "intern.h"
9+
10+
static int caam_debugfs_u64_get(void *data, u64 *val)
11+
{
12+
*val = caam64_to_cpu(*(u64 *)data);
13+
return 0;
14+
}
15+
16+
static int caam_debugfs_u32_get(void *data, u64 *val)
17+
{
18+
*val = caam32_to_cpu(*(u32 *)data);
19+
return 0;
20+
}
21+
22+
DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u32_ro, caam_debugfs_u32_get, NULL, "%llu\n");
23+
DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u64_ro, caam_debugfs_u64_get, NULL, "%llu\n");
24+
25+
#ifdef CONFIG_CAAM_QI
26+
/*
27+
* This is a counter for the number of times the congestion group (where all
28+
* the request and response queueus are) reached congestion. Incremented
29+
* each time the congestion callback is called with congested == true.
30+
*/
31+
static u64 times_congested;
32+
33+
void caam_debugfs_qi_congested(void)
34+
{
35+
times_congested++;
36+
}
37+
38+
void caam_debugfs_qi_init(struct caam_drv_private *ctrlpriv)
39+
{
40+
debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
41+
&times_congested, &caam_fops_u64_ro);
42+
}
43+
#endif
44+
45+
void caam_debugfs_init(struct caam_drv_private *ctrlpriv, struct dentry *root)
46+
{
47+
struct caam_perfmon *perfmon;
48+
49+
/*
50+
* FIXME: needs better naming distinction, as some amalgamation of
51+
* "caam" and nprop->full_name. The OF name isn't distinctive,
52+
* but does separate instances
53+
*/
54+
perfmon = (struct caam_perfmon __force *)&ctrlpriv->ctrl->perfmon;
55+
56+
ctrlpriv->ctl = debugfs_create_dir("ctl", root);
57+
58+
debugfs_create_file("rq_dequeued", 0444, ctrlpriv->ctl,
59+
&perfmon->req_dequeued, &caam_fops_u64_ro);
60+
debugfs_create_file("ob_rq_encrypted", 0444, ctrlpriv->ctl,
61+
&perfmon->ob_enc_req, &caam_fops_u64_ro);
62+
debugfs_create_file("ib_rq_decrypted", 0444, ctrlpriv->ctl,
63+
&perfmon->ib_dec_req, &caam_fops_u64_ro);
64+
debugfs_create_file("ob_bytes_encrypted", 0444, ctrlpriv->ctl,
65+
&perfmon->ob_enc_bytes, &caam_fops_u64_ro);
66+
debugfs_create_file("ob_bytes_protected", 0444, ctrlpriv->ctl,
67+
&perfmon->ob_prot_bytes, &caam_fops_u64_ro);
68+
debugfs_create_file("ib_bytes_decrypted", 0444, ctrlpriv->ctl,
69+
&perfmon->ib_dec_bytes, &caam_fops_u64_ro);
70+
debugfs_create_file("ib_bytes_validated", 0444, ctrlpriv->ctl,
71+
&perfmon->ib_valid_bytes, &caam_fops_u64_ro);
72+
73+
/* Controller level - global status values */
74+
debugfs_create_file("fault_addr", 0444, ctrlpriv->ctl,
75+
&perfmon->faultaddr, &caam_fops_u32_ro);
76+
debugfs_create_file("fault_detail", 0444, ctrlpriv->ctl,
77+
&perfmon->faultdetail, &caam_fops_u32_ro);
78+
debugfs_create_file("fault_status", 0444, ctrlpriv->ctl,
79+
&perfmon->status, &caam_fops_u32_ro);
80+
81+
/* Internal covering keys (useful in non-secure mode only) */
82+
ctrlpriv->ctl_kek_wrap.data = (__force void *)&ctrlpriv->ctrl->kek[0];
83+
ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
84+
debugfs_create_blob("kek", 0444, ctrlpriv->ctl,
85+
&ctrlpriv->ctl_kek_wrap);
86+
87+
ctrlpriv->ctl_tkek_wrap.data = (__force void *)&ctrlpriv->ctrl->tkek[0];
88+
ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
89+
debugfs_create_blob("tkek", 0444, ctrlpriv->ctl,
90+
&ctrlpriv->ctl_tkek_wrap);
91+
92+
ctrlpriv->ctl_tdsk_wrap.data = (__force void *)&ctrlpriv->ctrl->tdsk[0];
93+
ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
94+
debugfs_create_blob("tdsk", 0444, ctrlpriv->ctl,
95+
&ctrlpriv->ctl_tdsk_wrap);
96+
}

‎drivers/crypto/caam/debugfs.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2+
/* Copyright 2019 NXP */
3+
4+
#ifndef CAAM_DEBUGFS_H
5+
#define CAAM_DEBUGFS_H
6+
7+
struct dentry;
8+
struct caam_drv_private;
9+
10+
#ifdef CONFIG_DEBUG_FS
11+
void caam_debugfs_init(struct caam_drv_private *ctrlpriv, struct dentry *root);
12+
#else
13+
static inline void caam_debugfs_init(struct caam_drv_private *ctrlpriv,
14+
struct dentry *root)
15+
{}
16+
#endif
17+
18+
#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_CAAM_QI)
19+
void caam_debugfs_qi_congested(void);
20+
void caam_debugfs_qi_init(struct caam_drv_private *ctrlpriv);
21+
#else
22+
static inline void caam_debugfs_qi_congested(void) {}
23+
static inline void caam_debugfs_qi_init(struct caam_drv_private *ctrlpriv) {}
24+
#endif
25+
26+
#endif /* CAAM_DEBUGFS_H */

‎drivers/crypto/caam/intern.h‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,6 @@ static inline void caam_qi_algapi_exit(void)
195195

196196
#endif /* CONFIG_CAAM_QI */
197197

198-
#ifdef CONFIG_DEBUG_FS
199-
static int caam_debugfs_u64_get(void *data, u64 *val)
200-
{
201-
*val = caam64_to_cpu(*(u64 *)data);
202-
return 0;
203-
}
204-
205-
static int caam_debugfs_u32_get(void *data, u64 *val)
206-
{
207-
*val = caam32_to_cpu(*(u32 *)data);
208-
return 0;
209-
}
210-
211-
DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u32_ro, caam_debugfs_u32_get, NULL, "%llu\n");
212-
DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u64_ro, caam_debugfs_u64_get, NULL, "%llu\n");
213-
#endif
214-
215198
static inline u64 caam_get_dma_mask(struct device *dev)
216199
{
217200
struct device_node *nprop = dev->of_node;

‎drivers/crypto/caam/qi.c‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/kthread.h>
1212
#include <soc/fsl/qman.h>
1313

14+
#include "debugfs.h"
1415
#include "regs.h"
1516
#include "qi.h"
1617
#include "desc.h"
@@ -73,15 +74,6 @@ static struct caam_qi_priv qipriv ____cacheline_aligned;
7374
bool caam_congested __read_mostly;
7475
EXPORT_SYMBOL(caam_congested);
7576

76-
#ifdef CONFIG_DEBUG_FS
77-
/*
78-
* This is a counter for the number of times the congestion group (where all
79-
* the request and response queueus are) reached congestion. Incremented
80-
* each time the congestion callback is called with congested == true.
81-
*/
82-
static u64 times_congested;
83-
#endif
84-
8577
/*
8678
* This is a a cache of buffers, from which the users of CAAM QI driver
8779
* can allocate short (CAAM_QI_MEMCACHE_SIZE) buffers. It's faster than
@@ -544,9 +536,8 @@ static void cgr_cb(struct qman_portal *qm, struct qman_cgr *cgr, int congested)
544536
caam_congested = congested;
545537

546538
if (congested) {
547-
#ifdef CONFIG_DEBUG_FS
548-
times_congested++;
549-
#endif
539+
caam_debugfs_qi_congested();
540+
550541
pr_debug_ratelimited("CAAM entered congestion\n");
551542

552543
} else {
@@ -775,10 +766,7 @@ int caam_qi_init(struct platform_device *caam_pdev)
775766
return -ENOMEM;
776767
}
777768

778-
#ifdef CONFIG_DEBUG_FS
779-
debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
780-
&times_congested, &caam_fops_u64_ro);
781-
#endif
769+
caam_debugfs_qi_init(ctrlpriv);
782770

783771
err = devm_add_action_or_reset(qidev, caam_qi_shutdown, ctrlpriv);
784772
if (err)

0 commit comments

Comments
 (0)