2 * c 2001 PPC 64 Team, IBM Corp
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * scan-log-data driver for PPC64 Todd Inglett <tinglett@vnet.ibm.com>
11 * When ppc64 hardware fails the service processor dumps internal state
12 * of the system. After a reboot the operating system can access a dump
13 * of this data using this driver. A dump exists if the device-tree
14 * /chosen/ibm,scan-log-data property exists.
16 * This driver exports /proc/ppc64/scan-log-dump which can be read.
17 * The driver supports only sequential reads.
19 * The driver looks at a write to the driver for the single word "reset".
20 * If given, the driver will reset the scanlog so the platform can free it.
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/errno.h>
26 #include <linux/proc_fs.h>
27 #include <linux/init.h>
28 #include <asm/uaccess.h>
32 #define MODULE_VERSION "1.0"
33 #define MODULE_NAME "scanlog"
35 /* Status returns from ibm,scan-log-dump */
36 #define SCANLOG_COMPLETE 0
37 #define SCANLOG_HWERROR -1
38 #define SCANLOG_CONTINUE 1
40 #define DEBUG(A...) do { if (scanlog_debug) printk(KERN_ERR "scanlog: " A); } while (0)
42 static int scanlog_debug;
43 static unsigned int ibm_scan_log_dump; /* RTAS token */
44 static struct proc_dir_entry *proc_ppc64_scan_log_dump; /* The proc file */
47 static ssize_t scanlog_read(struct file *file, char *buf,
48 size_t count, loff_t *ppos)
50 struct proc_dir_entry *dp = file->f_dentry->d_inode->u.generic_ip;
51 unsigned int *data = (unsigned int *)dp->data;
53 unsigned long len, off;
54 unsigned int wait_time;
57 printk(KERN_ERR "scanlog: read failed no data\n");
61 if (count > RTAS_DATA_BUF_SIZE)
62 count = RTAS_DATA_BUF_SIZE;
65 /* This is the min supported by this RTAS call. Rather
66 * than do all the buffering we insist the user code handle
67 * larger reads. As long as cp works... :)
69 printk(KERN_ERR "scanlog: cannot perform a small read (%ld)\n", count);
73 if (verify_area(VERIFY_WRITE, buf, count))
77 wait_time = HZ/2; /* default wait if no data */
78 spin_lock(&rtas_data_buf_lock);
79 memcpy(rtas_data_buf, data, RTAS_DATA_BUF_SIZE);
80 status = rtas_call(ibm_scan_log_dump, 2, 1, NULL,
81 __pa(rtas_data_buf), count);
82 memcpy(data, rtas_data_buf, RTAS_DATA_BUF_SIZE);
83 spin_unlock(&rtas_data_buf_lock);
85 DEBUG("status=%ld, data[0]=%x, data[1]=%x, data[2]=%x\n",
86 status, data[0], data[1], data[2]);
88 case SCANLOG_COMPLETE:
92 DEBUG("hardware error reading scan log data\n");
94 case SCANLOG_CONTINUE:
95 /* We may or may not have data yet */
99 if (copy_to_user(buf, ((char *)data)+off, len))
103 /* Break to sleep default time */
106 if (status > 9900 && status <= 9905) {
107 /* No data. RTAS is hinting at a delay required
108 * between 1-100000 milliseconds
111 for (; status > 9900; status--)
113 /* Use microseconds for reasonable accuracy */
115 wait_time = ms / (1000000/HZ); /* round down is fine */
116 /* Fall through to sleep */
118 printk(KERN_ERR "scanlog: unknown error from rtas: %ld\n", status);
122 /* Apparently no data yet. Wait and try again. */
123 set_current_state(TASK_INTERRUPTIBLE);
124 schedule_timeout(wait_time);
129 static ssize_t scanlog_write(struct file * file, const char * buf,
130 size_t count, loff_t *ppos)
132 unsigned long status;
135 if (strncmp(buf, "reset", 5) == 0) {
136 DEBUG("reset scanlog\n");
137 status = rtas_call(ibm_scan_log_dump, 2, 1, NULL, NULL, 0);
138 DEBUG("rtas returns %ld\n", status);
139 } else if (strncmp(buf, "debugon", 7) == 0) {
140 printk(KERN_ERR "scanlog: debug on\n");
142 } else if (strncmp(buf, "debugoff", 8) == 0) {
143 printk(KERN_ERR "scanlog: debug off\n");
150 static int scanlog_open(struct inode * inode, struct file * file)
152 struct proc_dir_entry *dp = file->f_dentry->d_inode->u.generic_ip;
153 unsigned int *data = (unsigned int *)dp->data;
156 printk(KERN_ERR "scanlog: open failed no data\n");
160 /* This imperfect test stops a second copy of the
161 * data (or a reset while data is being copied)
166 data[0] = 0; /* re-init so we restart the scan */
171 static int scanlog_release(struct inode * inode, struct file * file)
173 struct proc_dir_entry *dp = file->f_dentry->d_inode->u.generic_ip;
174 unsigned int *data = (unsigned int *)dp->data;
177 printk(KERN_ERR "scanlog: release failed no data\n");
185 struct file_operations scanlog_fops = {
188 write: scanlog_write,
190 release: scanlog_release,
193 int __init scanlog_init(void)
195 struct proc_dir_entry *ent;
197 ibm_scan_log_dump = rtas_token("ibm,scan-log-dump");
198 if (ibm_scan_log_dump == RTAS_UNKNOWN_SERVICE) {
199 printk(KERN_ERR "scan-log-dump not implemented on this system\n");
203 ent = create_proc_entry("ppc64/scan-log-dump", S_IRUSR, NULL);
205 ent->proc_fops = &scanlog_fops;
206 /* Ideally we could allocate a buffer < 4G */
207 ent->data = kmalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
209 printk(KERN_ERR "Failed to allocate a buffer\n");
210 remove_proc_entry("scan-log-dump", ent->parent);
213 ((unsigned int *)ent->data)[0] = 0;
215 printk(KERN_ERR "Failed to create ppc64/scan-log-dump proc entry\n");
218 proc_ppc64_scan_log_dump = ent;
223 void __exit scanlog_cleanup(void)
225 if (proc_ppc64_scan_log_dump) {
226 if (proc_ppc64_scan_log_dump->data)
227 kfree(proc_ppc64_scan_log_dump->data);
228 remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent);
232 module_init(scanlog_init);
233 module_exit(scanlog_cleanup);
234 MODULE_LICENSE("GPL");