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 <linux/delay.h>
29 #include <asm/uaccess.h>
33 #define MODULE_VERS "1.0"
34 #define MODULE_NAME "scanlog"
36 /* Status returns from ibm,scan-log-dump */
37 #define SCANLOG_COMPLETE 0
38 #define SCANLOG_HWERROR -1
39 #define SCANLOG_CONTINUE 1
41 #define DEBUG(A...) do { if (scanlog_debug) printk(KERN_ERR "scanlog: " A); } while (0)
43 static int scanlog_debug;
44 static unsigned int ibm_scan_log_dump; /* RTAS token */
45 static struct proc_dir_entry *proc_ppc64_scan_log_dump; /* The proc file */
47 static ssize_t scanlog_read(struct file *file, char __user *buf,
48 size_t count, loff_t *ppos)
50 struct inode * inode = file->f_dentry->d_inode;
51 struct proc_dir_entry *dp;
54 unsigned long len, off;
55 unsigned int wait_time;
58 data = (unsigned int *)dp->data;
61 printk(KERN_ERR "scanlog: read failed no data\n");
65 if (count > RTAS_DATA_BUF_SIZE)
66 count = RTAS_DATA_BUF_SIZE;
69 /* This is the min supported by this RTAS call. Rather
70 * than do all the buffering we insist the user code handle
71 * larger reads. As long as cp works... :)
73 printk(KERN_ERR "scanlog: cannot perform a small read (%ld)\n", count);
77 if (!access_ok(VERIFY_WRITE, buf, count))
81 wait_time = 500; /* default wait if no data */
82 spin_lock(&rtas_data_buf_lock);
83 memcpy(rtas_data_buf, data, RTAS_DATA_BUF_SIZE);
84 status = rtas_call(ibm_scan_log_dump, 2, 1, NULL,
85 (u32) __pa(rtas_data_buf), (u32) count);
86 memcpy(data, rtas_data_buf, RTAS_DATA_BUF_SIZE);
87 spin_unlock(&rtas_data_buf_lock);
89 DEBUG("status=%d, data[0]=%x, data[1]=%x, data[2]=%x\n",
90 status, data[0], data[1], data[2]);
92 case SCANLOG_COMPLETE:
96 DEBUG("hardware error reading scan log data\n");
98 case SCANLOG_CONTINUE:
99 /* We may or may not have data yet */
103 if (copy_to_user(buf, ((char *)data)+off, len))
107 /* Break to sleep default time */
110 /* Assume extended busy */
111 wait_time = rtas_busy_delay_time(status);
113 printk(KERN_ERR "scanlog: unknown error from rtas: %d\n", status);
117 /* Apparently no data yet. Wait and try again. */
118 msleep_interruptible(wait_time);
123 static ssize_t scanlog_write(struct file * file, const char __user * buf,
124 size_t count, loff_t *ppos)
129 if (count > 19) count = 19;
130 if (copy_from_user (stkbuf, buf, count)) {
136 if (strncmp(stkbuf, "reset", 5) == 0) {
137 DEBUG("reset scanlog\n");
138 status = rtas_call(ibm_scan_log_dump, 2, 1, NULL, 0, 0);
139 DEBUG("rtas returns %d\n", status);
140 } else if (strncmp(stkbuf, "debugon", 7) == 0) {
141 printk(KERN_ERR "scanlog: debug on\n");
143 } else if (strncmp(stkbuf, "debugoff", 8) == 0) {
144 printk(KERN_ERR "scanlog: debug off\n");
151 static int scanlog_open(struct inode * inode, struct file * file)
153 struct proc_dir_entry *dp = PDE(inode);
154 unsigned int *data = (unsigned int *)dp->data;
157 printk(KERN_ERR "scanlog: open failed no data\n");
162 /* This imperfect test stops a second copy of the
163 * data (or a reset while data is being copied)
168 data[0] = 0; /* re-init so we restart the scan */
173 static int scanlog_release(struct inode * inode, struct file * file)
175 struct proc_dir_entry *dp = PDE(inode);
176 unsigned int *data = (unsigned int *)dp->data;
179 printk(KERN_ERR "scanlog: release failed no data\n");
187 struct file_operations scanlog_fops = {
188 .owner = THIS_MODULE,
189 .read = scanlog_read,
190 .write = scanlog_write,
191 .open = scanlog_open,
192 .release = scanlog_release,
195 static int __init scanlog_init(void)
197 struct proc_dir_entry *ent;
199 ibm_scan_log_dump = rtas_token("ibm,scan-log-dump");
200 if (ibm_scan_log_dump == RTAS_UNKNOWN_SERVICE) {
201 printk(KERN_ERR "scan-log-dump not implemented on this system\n");
205 ent = create_proc_entry("ppc64/rtas/scan-log-dump", S_IRUSR, NULL);
207 ent->proc_fops = &scanlog_fops;
208 /* Ideally we could allocate a buffer < 4G */
209 ent->data = kmalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
211 printk(KERN_ERR "Failed to allocate a buffer\n");
212 remove_proc_entry("scan-log-dump", ent->parent);
215 ((unsigned int *)ent->data)[0] = 0;
217 printk(KERN_ERR "Failed to create ppc64/scan-log-dump proc entry\n");
220 proc_ppc64_scan_log_dump = ent;
225 static void __exit scanlog_cleanup(void)
227 if (proc_ppc64_scan_log_dump) {
228 kfree(proc_ppc64_scan_log_dump->data);
229 remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent);
233 module_init(scanlog_init);
234 module_exit(scanlog_cleanup);
235 MODULE_LICENSE("GPL");