2007-07-19 10:49:52 +02:00
|
|
|
/*
|
|
|
|
* edac_module.c
|
|
|
|
*
|
2007-07-19 10:50:30 +02:00
|
|
|
* (C) 2007 www.softwarebitmaker.com
|
|
|
|
*
|
2007-07-19 10:49:52 +02:00
|
|
|
* This file is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2. This program is licensed "as is" without any
|
|
|
|
* warranty of any kind, whether express or implied.
|
|
|
|
*
|
2007-07-19 10:50:30 +02:00
|
|
|
* Author: Doug Thompson <dougthompson@xmission.com>
|
2007-07-19 10:49:52 +02:00
|
|
|
*
|
|
|
|
*/
|
2007-07-19 10:49:46 +02:00
|
|
|
#include <linux/edac.h>
|
2007-07-19 10:49:33 +02:00
|
|
|
|
2007-07-19 10:49:47 +02:00
|
|
|
#include "edac_core.h"
|
2007-07-19 10:49:33 +02:00
|
|
|
#include "edac_module.h"
|
|
|
|
|
2007-07-19 10:50:30 +02:00
|
|
|
#define EDAC_VERSION "Ver: 2.1.0 " __DATE__
|
2007-07-19 10:49:33 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_EDAC_DEBUG
|
|
|
|
/* Values of 0 to 4 will generate output */
|
2007-07-19 10:50:27 +02:00
|
|
|
int edac_debug_level = 2;
|
2007-07-19 10:49:33 +02:00
|
|
|
EXPORT_SYMBOL_GPL(edac_debug_level);
|
|
|
|
#endif
|
|
|
|
|
2007-07-19 10:49:36 +02:00
|
|
|
/* scope is to module level only */
|
|
|
|
struct workqueue_struct *edac_workqueue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sysfs object: /sys/devices/system/edac
|
|
|
|
* need to export to other files in this modules
|
|
|
|
*/
|
|
|
|
static struct sysdev_class edac_class = {
|
|
|
|
set_kset_name("edac"),
|
|
|
|
};
|
2007-07-19 10:50:19 +02:00
|
|
|
static int edac_class_valid;
|
2007-07-19 10:49:36 +02:00
|
|
|
|
2007-07-19 10:49:52 +02:00
|
|
|
/*
|
2007-07-19 10:50:21 +02:00
|
|
|
* edac_op_state_to_string()
|
2007-07-19 10:49:52 +02:00
|
|
|
*/
|
2007-07-19 10:50:21 +02:00
|
|
|
char *edac_op_state_to_string(int opstate)
|
2007-07-19 10:49:52 +02:00
|
|
|
{
|
|
|
|
if (opstate == OP_RUNNING_POLL)
|
|
|
|
return "POLLED";
|
|
|
|
else if (opstate == OP_RUNNING_INTERRUPT)
|
|
|
|
return "INTERRUPT";
|
|
|
|
else if (opstate == OP_RUNNING_POLL_INTR)
|
|
|
|
return "POLL-INTR";
|
|
|
|
else if (opstate == OP_ALLOC)
|
|
|
|
return "ALLOC";
|
|
|
|
else if (opstate == OP_OFFLINE)
|
|
|
|
return "OFFLINE";
|
|
|
|
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:49:36 +02:00
|
|
|
/*
|
|
|
|
* edac_get_edac_class()
|
|
|
|
*
|
|
|
|
* return pointer to the edac class of 'edac'
|
|
|
|
*/
|
|
|
|
struct sysdev_class *edac_get_edac_class(void)
|
|
|
|
{
|
2007-07-19 10:49:58 +02:00
|
|
|
struct sysdev_class *classptr = NULL;
|
2007-07-19 10:49:36 +02:00
|
|
|
|
|
|
|
if (edac_class_valid)
|
|
|
|
classptr = &edac_class;
|
|
|
|
|
|
|
|
return classptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* edac_register_sysfs_edac_name()
|
|
|
|
*
|
|
|
|
* register the 'edac' into /sys/devices/system
|
|
|
|
*
|
|
|
|
* return:
|
|
|
|
* 0 success
|
|
|
|
* !0 error
|
|
|
|
*/
|
|
|
|
static int edac_register_sysfs_edac_name(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* create the /sys/devices/system/edac directory */
|
|
|
|
err = sysdev_class_register(&edac_class);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
debugf1("%s() error=%d\n", __func__, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
edac_class_valid = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sysdev_class_unregister()
|
|
|
|
*
|
|
|
|
* unregister the 'edac' from /sys/devices/system
|
|
|
|
*/
|
|
|
|
static void edac_unregister_sysfs_edac_name(void)
|
|
|
|
{
|
|
|
|
/* only if currently registered, then unregister it */
|
|
|
|
if (edac_class_valid)
|
|
|
|
sysdev_class_unregister(&edac_class);
|
|
|
|
|
|
|
|
edac_class_valid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* edac_workqueue_setup
|
|
|
|
* initialize the edac work queue for polling operations
|
|
|
|
*/
|
|
|
|
static int edac_workqueue_setup(void)
|
|
|
|
{
|
|
|
|
edac_workqueue = create_singlethread_workqueue("edac-poller");
|
|
|
|
if (edac_workqueue == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* edac_workqueue_teardown
|
|
|
|
* teardown the edac workqueue
|
|
|
|
*/
|
|
|
|
static void edac_workqueue_teardown(void)
|
|
|
|
{
|
|
|
|
if (edac_workqueue) {
|
|
|
|
flush_workqueue(edac_workqueue);
|
|
|
|
destroy_workqueue(edac_workqueue);
|
|
|
|
edac_workqueue = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:49:33 +02:00
|
|
|
/*
|
|
|
|
* edac_init
|
|
|
|
* module initialization entry point
|
|
|
|
*/
|
|
|
|
static int __init edac_init(void)
|
|
|
|
{
|
2007-07-19 10:49:36 +02:00
|
|
|
int err = 0;
|
|
|
|
|
2007-07-19 10:50:30 +02:00
|
|
|
edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
|
2007-07-19 10:49:33 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Harvest and clear any boot/initialization PCI parity errors
|
|
|
|
*
|
|
|
|
* FIXME: This only clears errors logged by devices present at time of
|
2007-07-19 10:49:58 +02:00
|
|
|
* module initialization. We should also do an initial clear
|
|
|
|
* of each newly hotplugged device.
|
2007-07-19 10:49:33 +02:00
|
|
|
*/
|
|
|
|
edac_pci_clear_parity_errors();
|
|
|
|
|
2007-07-19 10:49:36 +02:00
|
|
|
/*
|
2007-07-19 10:50:27 +02:00
|
|
|
* perform the registration of the /sys/devices/system/edac class object
|
2007-07-19 10:49:36 +02:00
|
|
|
*/
|
|
|
|
if (edac_register_sysfs_edac_name()) {
|
|
|
|
edac_printk(KERN_ERR, EDAC_MC,
|
2007-07-19 10:50:13 +02:00
|
|
|
"Error initializing 'edac' kobject\n");
|
2007-07-19 10:49:36 +02:00
|
|
|
err = -ENODEV;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:50:27 +02:00
|
|
|
/*
|
|
|
|
* now set up the mc_kset under the edac class object
|
2007-07-19 10:49:36 +02:00
|
|
|
*/
|
2007-07-19 10:50:27 +02:00
|
|
|
err = edac_sysfs_setup_mc_kset();
|
|
|
|
if (err)
|
|
|
|
goto sysfs_setup_fail;
|
2007-07-19 10:49:33 +02:00
|
|
|
|
2007-07-19 10:50:27 +02:00
|
|
|
/* Setup/Initialize the workq for this core */
|
2007-07-19 10:49:36 +02:00
|
|
|
err = edac_workqueue_setup();
|
|
|
|
if (err) {
|
|
|
|
edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
|
2007-07-19 10:50:27 +02:00
|
|
|
goto workq_fail;
|
2007-07-19 10:49:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-07-19 10:49:36 +02:00
|
|
|
|
|
|
|
/* Error teardown stack */
|
2007-07-19 10:50:27 +02:00
|
|
|
workq_fail:
|
|
|
|
edac_sysfs_teardown_mc_kset();
|
|
|
|
|
|
|
|
sysfs_setup_fail:
|
2007-07-19 10:49:36 +02:00
|
|
|
edac_unregister_sysfs_edac_name();
|
2007-07-19 10:50:27 +02:00
|
|
|
|
2007-07-19 10:50:13 +02:00
|
|
|
error:
|
2007-07-19 10:49:36 +02:00
|
|
|
return err;
|
2007-07-19 10:49:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* edac_exit()
|
|
|
|
* module exit/termination function
|
|
|
|
*/
|
|
|
|
static void __exit edac_exit(void)
|
|
|
|
{
|
|
|
|
debugf0("%s()\n", __func__);
|
|
|
|
|
2007-07-19 10:49:58 +02:00
|
|
|
/* tear down the various subsystems */
|
2007-07-19 10:49:36 +02:00
|
|
|
edac_workqueue_teardown();
|
2007-07-19 10:50:27 +02:00
|
|
|
edac_sysfs_teardown_mc_kset();
|
2007-07-19 10:49:36 +02:00
|
|
|
edac_unregister_sysfs_edac_name();
|
2007-07-19 10:49:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inform the kernel of our entry and exit points
|
|
|
|
*/
|
|
|
|
module_init(edac_init);
|
|
|
|
module_exit(edac_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
|
|
|
|
MODULE_DESCRIPTION("Core library routines for EDAC reporting");
|
|
|
|
|
|
|
|
/* refer to *_sysfs.c files for parameters that are exported via sysfs */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EDAC_DEBUG
|
|
|
|
module_param(edac_debug_level, int, 0644);
|
|
|
|
MODULE_PARM_DESC(edac_debug_level, "Debug level");
|
|
|
|
#endif
|