Skip to content

Commit 8b93582

Browse files
qzhuo2aegl
authored andcommitted
EDAC/{skx_common,skx,i10nm}: Move the common debug code to skx_common
Commit afdb82fd763c ("EDAC, i10nm: make skx_common.o a separate module") made skx_common.o a separate module. With skx_common.o now a separate module, move the common debug code setup_{skx,i10nm}_debug() and teardown_{skx,i10nm}_debug() in {skx,i10nm}_base.c to skx_common.c to reduce code duplication. Additionally, prefix these function names with 'skx' to maintain consistency with other names in the file. Signed-off-by: Qiuxu Zhuo <[email protected]> Signed-off-by: Tony Luck <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 0ad875f commit 8b93582

File tree

4 files changed

+59
-100
lines changed

4 files changed

+59
-100
lines changed

drivers/edac/i10nm_base.c

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,54 +1013,6 @@ static struct notifier_block i10nm_mce_dec = {
10131013
.priority = MCE_PRIO_EDAC,
10141014
};
10151015

1016-
#ifdef CONFIG_EDAC_DEBUG
1017-
/*
1018-
* Debug feature.
1019-
* Exercise the address decode logic by writing an address to
1020-
* /sys/kernel/debug/edac/i10nm_test/addr.
1021-
*/
1022-
static struct dentry *i10nm_test;
1023-
1024-
static int debugfs_u64_set(void *data, u64 val)
1025-
{
1026-
struct mce m;
1027-
1028-
pr_warn_once("Fake error to 0x%llx injected via debugfs\n", val);
1029-
1030-
memset(&m, 0, sizeof(m));
1031-
/* ADDRV + MemRd + Unknown channel */
1032-
m.status = MCI_STATUS_ADDRV + 0x90;
1033-
/* One corrected error */
1034-
m.status |= BIT_ULL(MCI_STATUS_CEC_SHIFT);
1035-
m.addr = val;
1036-
skx_mce_check_error(NULL, 0, &m);
1037-
1038-
return 0;
1039-
}
1040-
DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");
1041-
1042-
static void setup_i10nm_debug(void)
1043-
{
1044-
i10nm_test = edac_debugfs_create_dir("i10nm_test");
1045-
if (!i10nm_test)
1046-
return;
1047-
1048-
if (!edac_debugfs_create_file("addr", 0200, i10nm_test,
1049-
NULL, &fops_u64_wo)) {
1050-
debugfs_remove(i10nm_test);
1051-
i10nm_test = NULL;
1052-
}
1053-
}
1054-
1055-
static void teardown_i10nm_debug(void)
1056-
{
1057-
debugfs_remove_recursive(i10nm_test);
1058-
}
1059-
#else
1060-
static inline void setup_i10nm_debug(void) {}
1061-
static inline void teardown_i10nm_debug(void) {}
1062-
#endif /*CONFIG_EDAC_DEBUG*/
1063-
10641016
static int __init i10nm_init(void)
10651017
{
10661018
u8 mc = 0, src_id = 0, node_id = 0;
@@ -1159,7 +1111,7 @@ static int __init i10nm_init(void)
11591111

11601112
opstate_init();
11611113
mce_register_decode_chain(&i10nm_mce_dec);
1162-
setup_i10nm_debug();
1114+
skx_setup_debug("i10nm_test");
11631115

11641116
if (retry_rd_err_log && res_cfg->offsets_scrub && res_cfg->offsets_demand) {
11651117
skx_set_decode(i10nm_mc_decode, show_retry_rd_err_log);
@@ -1187,7 +1139,7 @@ static void __exit i10nm_exit(void)
11871139
enable_retry_rd_err_log(false);
11881140
}
11891141

1190-
teardown_i10nm_debug();
1142+
skx_teardown_debug();
11911143
mce_unregister_decode_chain(&i10nm_mce_dec);
11921144
skx_adxl_put();
11931145
skx_remove();

drivers/edac/skx_base.c

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -587,54 +587,6 @@ static struct notifier_block skx_mce_dec = {
587587
.priority = MCE_PRIO_EDAC,
588588
};
589589

590-
#ifdef CONFIG_EDAC_DEBUG
591-
/*
592-
* Debug feature.
593-
* Exercise the address decode logic by writing an address to
594-
* /sys/kernel/debug/edac/skx_test/addr.
595-
*/
596-
static struct dentry *skx_test;
597-
598-
static int debugfs_u64_set(void *data, u64 val)
599-
{
600-
struct mce m;
601-
602-
pr_warn_once("Fake error to 0x%llx injected via debugfs\n", val);
603-
604-
memset(&m, 0, sizeof(m));
605-
/* ADDRV + MemRd + Unknown channel */
606-
m.status = MCI_STATUS_ADDRV + 0x90;
607-
/* One corrected error */
608-
m.status |= BIT_ULL(MCI_STATUS_CEC_SHIFT);
609-
m.addr = val;
610-
skx_mce_check_error(NULL, 0, &m);
611-
612-
return 0;
613-
}
614-
DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");
615-
616-
static void setup_skx_debug(void)
617-
{
618-
skx_test = edac_debugfs_create_dir("skx_test");
619-
if (!skx_test)
620-
return;
621-
622-
if (!edac_debugfs_create_file("addr", 0200, skx_test,
623-
NULL, &fops_u64_wo)) {
624-
debugfs_remove(skx_test);
625-
skx_test = NULL;
626-
}
627-
}
628-
629-
static void teardown_skx_debug(void)
630-
{
631-
debugfs_remove_recursive(skx_test);
632-
}
633-
#else
634-
static inline void setup_skx_debug(void) {}
635-
static inline void teardown_skx_debug(void) {}
636-
#endif /*CONFIG_EDAC_DEBUG*/
637-
638590
/*
639591
* skx_init:
640592
* make sure we are running on the correct cpu model
@@ -728,7 +680,7 @@ static int __init skx_init(void)
728680
/* Ensure that the OPSTATE is set correctly for POLL or NMI */
729681
opstate_init();
730682

731-
setup_skx_debug();
683+
skx_setup_debug("skx_test");
732684

733685
mce_register_decode_chain(&skx_mce_dec);
734686

@@ -742,7 +694,7 @@ static void __exit skx_exit(void)
742694
{
743695
edac_dbg(2, "\n");
744696
mce_unregister_decode_chain(&skx_mce_dec);
745-
teardown_skx_debug();
697+
skx_teardown_debug();
746698
if (nvdimm_count)
747699
skx_adxl_put();
748700
skx_remove();

drivers/edac/skx_common.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,53 @@ void skx_remove(void)
739739
}
740740
EXPORT_SYMBOL_GPL(skx_remove);
741741

742+
#ifdef CONFIG_EDAC_DEBUG
743+
/*
744+
* Debug feature.
745+
* Exercise the address decode logic by writing an address to
746+
* /sys/kernel/debug/edac/{skx,i10nm}_test/addr.
747+
*/
748+
static struct dentry *skx_test;
749+
750+
static int debugfs_u64_set(void *data, u64 val)
751+
{
752+
struct mce m;
753+
754+
pr_warn_once("Fake error to 0x%llx injected via debugfs\n", val);
755+
756+
memset(&m, 0, sizeof(m));
757+
/* ADDRV + MemRd + Unknown channel */
758+
m.status = MCI_STATUS_ADDRV + 0x90;
759+
/* One corrected error */
760+
m.status |= BIT_ULL(MCI_STATUS_CEC_SHIFT);
761+
m.addr = val;
762+
skx_mce_check_error(NULL, 0, &m);
763+
764+
return 0;
765+
}
766+
DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");
767+
768+
void skx_setup_debug(const char *name)
769+
{
770+
skx_test = edac_debugfs_create_dir(name);
771+
if (!skx_test)
772+
return;
773+
774+
if (!edac_debugfs_create_file("addr", 0200, skx_test,
775+
NULL, &fops_u64_wo)) {
776+
debugfs_remove(skx_test);
777+
skx_test = NULL;
778+
}
779+
}
780+
EXPORT_SYMBOL_GPL(skx_setup_debug);
781+
782+
void skx_teardown_debug(void)
783+
{
784+
debugfs_remove_recursive(skx_test);
785+
}
786+
EXPORT_SYMBOL_GPL(skx_teardown_debug);
787+
#endif /*CONFIG_EDAC_DEBUG*/
788+
742789
MODULE_LICENSE("GPL v2");
743790
MODULE_AUTHOR("Tony Luck");
744791
MODULE_DESCRIPTION("MC Driver for Intel server processors");

drivers/edac/skx_common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,12 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
260260

261261
void skx_remove(void);
262262

263+
#ifdef CONFIG_EDAC_DEBUG
264+
void skx_setup_debug(const char *name);
265+
void skx_teardown_debug(void);
266+
#else
267+
static inline void skx_setup_debug(const char *name) {}
268+
static inline void skx_teardown_debug(void) {}
269+
#endif
270+
263271
#endif /* _SKX_COMM_EDAC_H */

0 commit comments

Comments
 (0)