fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / char / viotape.c
index a5915c1..9438512 100644 (file)
  *
  * All tape operations are performed by sending messages back and forth to
  * the OS/400 partition.  The format of the messages is defined in
- * iSeries/vio.h
+ * iseries/vio.h
  */
-#include <linux/config.h>
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -44,7 +42,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/fs.h>
 #include <linux/cdev.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/major.h>
 #include <linux/completion.h>
 #include <linux/proc_fs.h>
 
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
-
-#include <asm/iSeries/vio.h>
-#include <asm/iSeries/HvLpEvent.h>
-#include <asm/iSeries/HvCallEvent.h>
-#include <asm/iSeries/HvLpConfig.h>
+#include <asm/firmware.h>
+#include <asm/vio.h>
+#include <asm/iseries/vio.h>
+#include <asm/iseries/hv_lp_event.h>
+#include <asm/iseries/hv_call_event.h>
+#include <asm/iseries/hv_lp_config.h>
 
 #define VIOTAPE_VERSION                "1.2"
 #define VIOTAPE_MAXREQ         1
@@ -216,7 +214,7 @@ static const struct vio_error_entry viotape_err_table[] = {
 };
 
 /* Maximum number of tapes we support */
-#define VIOTAPE_MAX_TAPE       8
+#define VIOTAPE_MAX_TAPE       HVMAXARCHITECTEDVIRTUALTAPES
 #define MAX_PARTITIONS         4
 
 /* defines for current tape state */
@@ -236,7 +234,9 @@ static dma_addr_t viotape_unitinfo_token;
 
 static struct mtget viomtget[VIOTAPE_MAX_TAPE];
 
-static struct class_simple *tape_class;
+static struct class *tape_class;
+
+static struct device *tape_device[VIOTAPE_MAX_TAPE];
 
 /*
  * maintain the current state of each tape (and partition)
@@ -244,7 +244,6 @@ static struct class_simple *tape_class;
  */
 static struct {
        unsigned char   cur_part;
-       int             dev_handle;
        unsigned char   part_stat_rwi[MAX_PARTITIONS];
 } state[VIOTAPE_MAX_TAPE];
 
@@ -262,6 +261,7 @@ struct op_struct {
        int                     rc;
        int                     non_blocking;
        struct completion       com;
+       struct device           *dev;
        struct op_struct        *next;
 };
 
@@ -292,7 +292,7 @@ static int proc_viotape_open(struct inode *inode, struct file *file)
        return single_open(file, proc_viotape_show, NULL);
 }
 
-static struct file_operations proc_viotape_operations = {
+static const struct file_operations proc_viotape_operations = {
        .open           = proc_viotape_open,
        .read           = seq_read,
        .llseek         = seq_lseek,
@@ -442,7 +442,7 @@ static ssize_t viotap_write(struct file *file, const char *buf,
        if (op == NULL)
                return -ENOMEM;
 
-       get_dev_info(file->f_dentry->d_inode, &devi);
+       get_dev_info(file->f_path.dentry->d_inode, &devi);
 
        /*
         * We need to make sure we can send a request.  We use
@@ -459,7 +459,8 @@ static ssize_t viotap_write(struct file *file, const char *buf,
                down(&reqSem);
 
        /* Allocate a DMA buffer */
-       op->buffer = dma_alloc_coherent(iSeries_vio_dev, count, &op->dmaaddr,
+       op->dev = tape_device[devi.devno];
+       op->buffer = dma_alloc_coherent(op->dev, count, &op->dmaaddr,
                        GFP_ATOMIC);
 
        if (op->buffer == NULL) {
@@ -509,7 +510,7 @@ static ssize_t viotap_write(struct file *file, const char *buf,
        }
 
 free_dma:
-       dma_free_coherent(iSeries_vio_dev, count, op->buffer, op->dmaaddr);
+       dma_free_coherent(op->dev, count, op->buffer, op->dmaaddr);
 up_sem:
        up(&reqSem);
 free_op:
@@ -531,7 +532,7 @@ static ssize_t viotap_read(struct file *file, char *buf, size_t count,
        if (op == NULL)
                return -ENOMEM;
 
-       get_dev_info(file->f_dentry->d_inode, &devi);
+       get_dev_info(file->f_path.dentry->d_inode, &devi);
 
        /*
         * We need to make sure we can send a request.  We use
@@ -550,7 +551,8 @@ static ssize_t viotap_read(struct file *file, char *buf, size_t count,
        chg_state(devi.devno, VIOT_READING, file);
 
        /* Allocate a DMA buffer */
-       op->buffer = dma_alloc_coherent(iSeries_vio_dev, count, &op->dmaaddr,
+       op->dev = tape_device[devi.devno];
+       op->buffer = dma_alloc_coherent(op->dev, count, &op->dmaaddr,
                        GFP_ATOMIC);
        if (op->buffer == NULL) {
                ret = -EFAULT;
@@ -588,7 +590,7 @@ static ssize_t viotap_read(struct file *file, char *buf, size_t count,
        }
 
 free_dma:
-       dma_free_coherent(iSeries_vio_dev, count, op->buffer, op->dmaaddr);
+       dma_free_coherent(op->dev, count, op->buffer, op->dmaaddr);
 up_sem:
        up(&reqSem);
 free_op:
@@ -610,7 +612,7 @@ static int viotap_ioctl(struct inode *inode, struct file *file,
        if (op == NULL)
                return -ENOMEM;
 
-       get_dev_info(file->f_dentry->d_inode, &devi);
+       get_dev_info(file->f_path.dentry->d_inode, &devi);
 
        down(&reqSem);
 
@@ -775,7 +777,7 @@ static int viotap_open(struct inode *inode, struct file *file)
        if (op == NULL)
                return -ENOMEM;
 
-       get_dev_info(file->f_dentry->d_inode, &devi);
+       get_dev_info(file->f_path.dentry->d_inode, &devi);
 
        /* Note: We currently only support one mode! */
        if ((devi.devno >= viotape_numdev) || (devi.mode)) {
@@ -820,7 +822,7 @@ static int viotap_release(struct inode *inode, struct file *file)
                return -ENOMEM;
        init_completion(&op->com);
 
-       get_dev_info(file->f_dentry->d_inode, &devi);
+       get_dev_info(file->f_path.dentry->d_inode, &devi);
 
        if (devi.devno >= viotape_numdev) {
                ret = -ENODEV;
@@ -910,7 +912,7 @@ static void vioHandleTapeEvent(struct HvLpEvent *event)
                break;
        case viotapewrite:
                if (op->non_blocking) {
-                       dma_free_coherent(iSeries_vio_dev, op->count,
+                       dma_free_coherent(op->dev, op->count,
                                        op->buffer, op->dmaaddr);
                        free_op_struct(op);
                        up(&reqSem);
@@ -932,18 +934,72 @@ static void vioHandleTapeEvent(struct HvLpEvent *event)
                }
                break;
        default:
-               printk(VIOTAPE_KERN_WARN "wierd ack\n");
+               printk(VIOTAPE_KERN_WARN "weird ack\n");
        }
 }
 
+static int viotape_probe(struct vio_dev *vdev, const struct vio_device_id *id)
+{
+       int i = vdev->unit_address;
+       int j;
+
+       if (i >= viotape_numdev)
+               return -ENODEV;
+
+       tape_device[i] = &vdev->dev;
+
+       state[i].cur_part = 0;
+       for (j = 0; j < MAX_PARTITIONS; ++j)
+               state[i].part_stat_rwi[j] = VIOT_IDLE;
+       class_device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i), NULL,
+                       "iseries!vt%d", i);
+       class_device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i | 0x80),
+                       NULL, "iseries!nvt%d", i);
+       printk(VIOTAPE_KERN_INFO "tape iseries/vt%d is iSeries "
+                       "resource %10.10s type %4.4s, model %3.3s\n",
+                       i, viotape_unitinfo[i].rsrcname,
+                       viotape_unitinfo[i].type, viotape_unitinfo[i].model);
+       return 0;
+}
+
+static int viotape_remove(struct vio_dev *vdev)
+{
+       int i = vdev->unit_address;
+
+       class_device_destroy(tape_class, MKDEV(VIOTAPE_MAJOR, i | 0x80));
+       class_device_destroy(tape_class, MKDEV(VIOTAPE_MAJOR, i));
+       return 0;
+}
+
+/**
+ * viotape_device_table: Used by vio.c to match devices that we
+ * support.
+ */
+static struct vio_device_id viotape_device_table[] __devinitdata = {
+       { "byte", "IBM,iSeries-viotape" },
+       { "", "" }
+};
+MODULE_DEVICE_TABLE(vio, viotape_device_table);
+
+static struct vio_driver viotape_driver = {
+       .id_table = viotape_device_table,
+       .probe = viotape_probe,
+       .remove = viotape_remove,
+       .driver = {
+               .name = "viotape",
+               .owner = THIS_MODULE,
+       }
+};
+
 
 int __init viotap_init(void)
 {
        int ret;
-       char tapename[32];
-       int i;
        struct proc_dir_entry *e;
 
+       if (!firmware_has_feature(FW_FEATURE_ISERIES))
+               return -ENODEV;
+
        op_struct_list = NULL;
        if ((ret = add_op_structs(VIOTAPE_MAXREQ)) < 0) {
                printk(VIOTAPE_KERN_WARN "couldn't allocate op structs\n");
@@ -981,7 +1037,7 @@ int __init viotap_init(void)
                goto clear_handler;
        }
 
-       tape_class = class_simple_create(THIS_MODULE, "tape");
+       tape_class = class_create(THIS_MODULE, "tape");
        if (IS_ERR(tape_class)) {
                printk(VIOTAPE_KERN_WARN "Unable to allocat class\n");
                ret = PTR_ERR(tape_class);
@@ -993,31 +1049,9 @@ int __init viotap_init(void)
                goto unreg_class;
        }
 
-       for (i = 0; i < viotape_numdev; i++) {
-               int j;
-
-               state[i].cur_part = 0;
-               for (j = 0; j < MAX_PARTITIONS; ++j)
-                       state[i].part_stat_rwi[j] = VIOT_IDLE;
-               class_simple_device_add(tape_class, MKDEV(VIOTAPE_MAJOR, i),
-                               NULL, "iseries!vt%d", i);
-               class_simple_device_add(tape_class,
-                               MKDEV(VIOTAPE_MAJOR, i | 0x80),
-                               NULL, "iseries!nvt%d", i);
-               devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR, i),
-                               S_IFCHR | S_IRUSR | S_IWUSR,
-                               "iseries/vt%d", i);
-               devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR, i | 0x80),
-                               S_IFCHR | S_IRUSR | S_IWUSR,
-                               "iseries/nvt%d", i);
-               sprintf(tapename, "iseries/vt%d", i);
-               state[i].dev_handle = devfs_register_tape(tapename);
-               printk(VIOTAPE_KERN_INFO "tape %s is iSeries "
-                               "resource %10.10s type %4.4s, model %3.3s\n",
-                               tapename, viotape_unitinfo[i].rsrcname,
-                               viotape_unitinfo[i].type,
-                               viotape_unitinfo[i].model);
-       }
+       ret = vio_register_driver(&viotape_driver);
+       if (ret)
+               goto unreg_class;
 
        e = create_proc_entry("iSeries/viotape", S_IFREG|S_IRUGO, NULL);
        if (e) {
@@ -1028,7 +1062,7 @@ int __init viotap_init(void)
        return 0;
 
 unreg_class:
-       class_simple_destroy(tape_class);
+       class_destroy(tape_class);
 unreg_chrdev:
        unregister_chrdev(VIOTAPE_MAJOR, "viotape");
 clear_handler:
@@ -1064,18 +1098,11 @@ static int chg_state(int index, unsigned char new_state, struct file *file)
 /* Cleanup */
 static void __exit viotap_exit(void)
 {
-       int i, ret;
+       int ret;
 
        remove_proc_entry("iSeries/viotape", NULL);
-
-       for (i = 0; i < viotape_numdev; ++i) {
-               devfs_remove("iseries/nvt%d", i);
-               devfs_remove("iseries/vt%d", i);
-               devfs_unregister_tape(state[i].dev_handle);
-               class_simple_device_remove(MKDEV(VIOTAPE_MAJOR, i | 0x80));
-               class_simple_device_remove(MKDEV(VIOTAPE_MAJOR, i));
-       }
-       class_simple_destroy(tape_class);
+       vio_unregister_driver(&viotape_driver);
+       class_destroy(tape_class);
        ret = unregister_chrdev(VIOTAPE_MAJOR, "viotape");
        if (ret < 0)
                printk(VIOTAPE_KERN_WARN "Error unregistering device: %d\n",