Path: blob/master/arch/powerpc/platforms/pseries/scanlog.c
10818 views
/*1* c 2001 PPC 64 Team, IBM Corp2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation; either version6* 2 of the License, or (at your option) any later version.7*8* scan-log-data driver for PPC64 Todd Inglett <[email protected]>9*10* When ppc64 hardware fails the service processor dumps internal state11* of the system. After a reboot the operating system can access a dump12* of this data using this driver. A dump exists if the device-tree13* /chosen/ibm,scan-log-data property exists.14*15* This driver exports /proc/powerpc/scan-log-dump which can be read.16* The driver supports only sequential reads.17*18* The driver looks at a write to the driver for the single word "reset".19* If given, the driver will reset the scanlog so the platform can free it.20*/2122#include <linux/module.h>23#include <linux/types.h>24#include <linux/errno.h>25#include <linux/proc_fs.h>26#include <linux/init.h>27#include <linux/delay.h>28#include <linux/slab.h>29#include <asm/uaccess.h>30#include <asm/rtas.h>31#include <asm/prom.h>3233#define MODULE_VERS "1.0"34#define MODULE_NAME "scanlog"3536/* Status returns from ibm,scan-log-dump */37#define SCANLOG_COMPLETE 038#define SCANLOG_HWERROR -139#define SCANLOG_CONTINUE 1404142static unsigned int ibm_scan_log_dump; /* RTAS token */43static struct proc_dir_entry *proc_ppc64_scan_log_dump; /* The proc file */4445static ssize_t scanlog_read(struct file *file, char __user *buf,46size_t count, loff_t *ppos)47{48struct inode * inode = file->f_path.dentry->d_inode;49struct proc_dir_entry *dp;50unsigned int *data;51int status;52unsigned long len, off;53unsigned int wait_time;5455dp = PDE(inode);56data = (unsigned int *)dp->data;5758if (count > RTAS_DATA_BUF_SIZE)59count = RTAS_DATA_BUF_SIZE;6061if (count < 1024) {62/* This is the min supported by this RTAS call. Rather63* than do all the buffering we insist the user code handle64* larger reads. As long as cp works... :)65*/66printk(KERN_ERR "scanlog: cannot perform a small read (%ld)\n", count);67return -EINVAL;68}6970if (!access_ok(VERIFY_WRITE, buf, count))71return -EFAULT;7273for (;;) {74wait_time = 500; /* default wait if no data */75spin_lock(&rtas_data_buf_lock);76memcpy(rtas_data_buf, data, RTAS_DATA_BUF_SIZE);77status = rtas_call(ibm_scan_log_dump, 2, 1, NULL,78(u32) __pa(rtas_data_buf), (u32) count);79memcpy(data, rtas_data_buf, RTAS_DATA_BUF_SIZE);80spin_unlock(&rtas_data_buf_lock);8182pr_debug("scanlog: status=%d, data[0]=%x, data[1]=%x, " \83"data[2]=%x\n", status, data[0], data[1], data[2]);84switch (status) {85case SCANLOG_COMPLETE:86pr_debug("scanlog: hit eof\n");87return 0;88case SCANLOG_HWERROR:89pr_debug("scanlog: hardware error reading data\n");90return -EIO;91case SCANLOG_CONTINUE:92/* We may or may not have data yet */93len = data[1];94off = data[2];95if (len > 0) {96if (copy_to_user(buf, ((char *)data)+off, len))97return -EFAULT;98return len;99}100/* Break to sleep default time */101break;102default:103/* Assume extended busy */104wait_time = rtas_busy_delay_time(status);105if (!wait_time) {106printk(KERN_ERR "scanlog: unknown error " \107"from rtas: %d\n", status);108return -EIO;109}110}111/* Apparently no data yet. Wait and try again. */112msleep_interruptible(wait_time);113}114/*NOTREACHED*/115}116117static ssize_t scanlog_write(struct file * file, const char __user * buf,118size_t count, loff_t *ppos)119{120char stkbuf[20];121int status;122123if (count > 19) count = 19;124if (copy_from_user (stkbuf, buf, count)) {125return -EFAULT;126}127stkbuf[count] = 0;128129if (buf) {130if (strncmp(stkbuf, "reset", 5) == 0) {131pr_debug("scanlog: reset scanlog\n");132status = rtas_call(ibm_scan_log_dump, 2, 1, NULL, 0, 0);133pr_debug("scanlog: rtas returns %d\n", status);134}135}136return count;137}138139static int scanlog_open(struct inode * inode, struct file * file)140{141struct proc_dir_entry *dp = PDE(inode);142unsigned int *data = (unsigned int *)dp->data;143144if (data[0] != 0) {145/* This imperfect test stops a second copy of the146* data (or a reset while data is being copied)147*/148return -EBUSY;149}150151data[0] = 0; /* re-init so we restart the scan */152153return 0;154}155156static int scanlog_release(struct inode * inode, struct file * file)157{158struct proc_dir_entry *dp = PDE(inode);159unsigned int *data = (unsigned int *)dp->data;160161data[0] = 0;162163return 0;164}165166const struct file_operations scanlog_fops = {167.owner = THIS_MODULE,168.read = scanlog_read,169.write = scanlog_write,170.open = scanlog_open,171.release = scanlog_release,172.llseek = noop_llseek,173};174175static int __init scanlog_init(void)176{177struct proc_dir_entry *ent;178void *data;179int err = -ENOMEM;180181ibm_scan_log_dump = rtas_token("ibm,scan-log-dump");182if (ibm_scan_log_dump == RTAS_UNKNOWN_SERVICE)183return -ENODEV;184185/* Ideally we could allocate a buffer < 4G */186data = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);187if (!data)188goto err;189190ent = proc_create_data("powerpc/rtas/scan-log-dump", S_IRUSR, NULL,191&scanlog_fops, data);192if (!ent)193goto err;194195proc_ppc64_scan_log_dump = ent;196197return 0;198err:199kfree(data);200return err;201}202203static void __exit scanlog_cleanup(void)204{205if (proc_ppc64_scan_log_dump) {206kfree(proc_ppc64_scan_log_dump->data);207remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent);208}209}210211module_init(scanlog_init);212module_exit(scanlog_cleanup);213MODULE_LICENSE("GPL");214215216