2 * drivers/char/viotape.c
6 * Authors: Dave Boutcher <boutcher@us.ibm.com>
7 * Ryan Arnold <ryanarn@us.ibm.com>
8 * Colin Devilbiss <devilbis@us.ibm.com>
9 * Stephen Rothwell <sfr@au1.ibm.com>
11 * (C) Copyright 2000-2004 IBM Corporation
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of the
16 * License, or (at your option) anyu later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * This routine provides access to tape drives owned and managed by an OS/400
28 * partition running on the same box as this Linux partition.
30 * All tape operations are performed by sending messages back and forth to
31 * the OS/400 partition. The format of the messages is defined in
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/errno.h>
37 #include <linux/init.h>
38 #include <linux/wait.h>
39 #include <linux/spinlock.h>
40 #include <linux/mtio.h>
41 #include <linux/device.h>
42 #include <linux/dma-mapping.h>
44 #include <linux/cdev.h>
45 #include <linux/major.h>
46 #include <linux/completion.h>
47 #include <linux/proc_fs.h>
48 #include <linux/seq_file.h>
50 #include <asm/uaccess.h>
51 #include <asm/ioctls.h>
52 #include <asm/firmware.h>
54 #include <asm/iseries/vio.h>
55 #include <asm/iseries/hv_lp_event.h>
56 #include <asm/iseries/hv_call_event.h>
57 #include <asm/iseries/hv_lp_config.h>
59 #define VIOTAPE_VERSION "1.2"
60 #define VIOTAPE_MAXREQ 1
62 #define VIOTAPE_KERN_WARN KERN_WARNING "viotape: "
63 #define VIOTAPE_KERN_INFO KERN_INFO "viotape: "
65 static int viotape_numdev;
68 * The minor number follows the conventions of the SCSI tape drives. The
69 * rewind and mode are encoded in the minor #. We use this struct to break
72 struct viot_devinfo_struct {
78 #define VIOTAPOP_RESET 0
79 #define VIOTAPOP_FSF 1
80 #define VIOTAPOP_BSF 2
81 #define VIOTAPOP_FSR 3
82 #define VIOTAPOP_BSR 4
83 #define VIOTAPOP_WEOF 5
84 #define VIOTAPOP_REW 6
85 #define VIOTAPOP_NOP 7
86 #define VIOTAPOP_EOM 8
87 #define VIOTAPOP_ERASE 9
88 #define VIOTAPOP_SETBLK 10
89 #define VIOTAPOP_SETDENSITY 11
90 #define VIOTAPOP_SETPOS 12
91 #define VIOTAPOP_GETPOS 13
92 #define VIOTAPOP_SETPART 14
93 #define VIOTAPOP_UNLOAD 15
96 viotape_InvalidRange = 0x0601,
97 viotape_InvalidToken = 0x0602,
98 viotape_DMAError = 0x0603,
99 viotape_UseError = 0x0604,
100 viotape_ReleaseError = 0x0605,
101 viotape_InvalidTape = 0x0606,
102 viotape_InvalidOp = 0x0607,
103 viotape_TapeErr = 0x0608,
105 viotape_AllocTimedOut = 0x0640,
106 viotape_BOTEnc = 0x0641,
107 viotape_BlankTape = 0x0642,
108 viotape_BufferEmpty = 0x0643,
109 viotape_CleanCartFound = 0x0644,
110 viotape_CmdNotAllowed = 0x0645,
111 viotape_CmdNotSupported = 0x0646,
112 viotape_DataCheck = 0x0647,
113 viotape_DecompressErr = 0x0648,
114 viotape_DeviceTimeout = 0x0649,
115 viotape_DeviceUnavail = 0x064a,
116 viotape_DeviceBusy = 0x064b,
117 viotape_EndOfMedia = 0x064c,
118 viotape_EndOfTape = 0x064d,
119 viotape_EquipCheck = 0x064e,
120 viotape_InsufficientRs = 0x064f,
121 viotape_InvalidLogBlk = 0x0650,
122 viotape_LengthError = 0x0651,
123 viotape_LibDoorOpen = 0x0652,
124 viotape_LoadFailure = 0x0653,
125 viotape_NotCapable = 0x0654,
126 viotape_NotOperational = 0x0655,
127 viotape_NotReady = 0x0656,
128 viotape_OpCancelled = 0x0657,
129 viotape_PhyLinkErr = 0x0658,
130 viotape_RdyNotBOT = 0x0659,
131 viotape_TapeMark = 0x065a,
132 viotape_WriteProt = 0x065b
135 static const struct vio_error_entry viotape_err_table[] = {
136 { viotape_InvalidRange, EIO, "Internal error" },
137 { viotape_InvalidToken, EIO, "Internal error" },
138 { viotape_DMAError, EIO, "DMA error" },
139 { viotape_UseError, EIO, "Internal error" },
140 { viotape_ReleaseError, EIO, "Internal error" },
141 { viotape_InvalidTape, EIO, "Invalid tape device" },
142 { viotape_InvalidOp, EIO, "Invalid operation" },
143 { viotape_TapeErr, EIO, "Tape error" },
144 { viotape_AllocTimedOut, EBUSY, "Allocate timed out" },
145 { viotape_BOTEnc, EIO, "Beginning of tape encountered" },
146 { viotape_BlankTape, EIO, "Blank tape" },
147 { viotape_BufferEmpty, EIO, "Buffer empty" },
148 { viotape_CleanCartFound, ENOMEDIUM, "Cleaning cartridge found" },
149 { viotape_CmdNotAllowed, EIO, "Command not allowed" },
150 { viotape_CmdNotSupported, EIO, "Command not supported" },
151 { viotape_DataCheck, EIO, "Data check" },
152 { viotape_DecompressErr, EIO, "Decompression error" },
153 { viotape_DeviceTimeout, EBUSY, "Device timeout" },
154 { viotape_DeviceUnavail, EIO, "Device unavailable" },
155 { viotape_DeviceBusy, EBUSY, "Device busy" },
156 { viotape_EndOfMedia, ENOSPC, "End of media" },
157 { viotape_EndOfTape, ENOSPC, "End of tape" },
158 { viotape_EquipCheck, EIO, "Equipment check" },
159 { viotape_InsufficientRs, EOVERFLOW, "Insufficient tape resources" },
160 { viotape_InvalidLogBlk, EIO, "Invalid logical block location" },
161 { viotape_LengthError, EOVERFLOW, "Length error" },
162 { viotape_LibDoorOpen, EBUSY, "Door open" },
163 { viotape_LoadFailure, ENOMEDIUM, "Load failure" },
164 { viotape_NotCapable, EIO, "Not capable" },
165 { viotape_NotOperational, EIO, "Not operational" },
166 { viotape_NotReady, EIO, "Not ready" },
167 { viotape_OpCancelled, EIO, "Operation cancelled" },
168 { viotape_PhyLinkErr, EIO, "Physical link error" },
169 { viotape_RdyNotBOT, EIO, "Ready but not beginning of tape" },
170 { viotape_TapeMark, EIO, "Tape mark" },
171 { viotape_WriteProt, EROFS, "Write protection error" },
175 /* Maximum number of tapes we support */
176 #define VIOTAPE_MAX_TAPE HVMAXARCHITECTEDVIRTUALTAPES
177 #define MAX_PARTITIONS 4
179 /* defines for current tape state */
181 #define VIOT_READING 1
182 #define VIOT_WRITING 2
184 /* Our info on the tapes */
186 const char *rsrcname;
189 } viotape_unitinfo[VIOTAPE_MAX_TAPE];
191 static struct mtget viomtget[VIOTAPE_MAX_TAPE];
193 static struct class *tape_class;
195 static struct device *tape_device[VIOTAPE_MAX_TAPE];
198 * maintain the current state of each tape (and partition)
199 * so that we know when to write EOF marks.
202 unsigned char cur_part;
203 unsigned char part_stat_rwi[MAX_PARTITIONS];
204 } state[VIOTAPE_MAX_TAPE];
206 /* We single-thread */
207 static struct semaphore reqSem;
210 * When we send a request, we use this struct to get the response back
211 * from the interrupt handler
219 struct completion com;
221 struct op_struct *next;
224 static spinlock_t op_struct_list_lock;
225 static struct op_struct *op_struct_list;
227 /* forward declaration to resolve interdependence */
228 static int chg_state(int index, unsigned char new_state, struct file *file);
231 static int proc_viotape_show(struct seq_file *m, void *v)
235 seq_printf(m, "viotape driver version " VIOTAPE_VERSION "\n");
236 for (i = 0; i < viotape_numdev; i++) {
237 seq_printf(m, "viotape device %d is iSeries resource %10.10s"
238 "type %4.4s, model %3.3s\n",
239 i, viotape_unitinfo[i].rsrcname,
240 viotape_unitinfo[i].type,
241 viotape_unitinfo[i].model);
246 static int proc_viotape_open(struct inode *inode, struct file *file)
248 return single_open(file, proc_viotape_show, NULL);
251 static const struct file_operations proc_viotape_operations = {
252 .open = proc_viotape_open,
255 .release = single_release,
258 /* Decode the device minor number into its parts */
259 void get_dev_info(struct inode *ino, struct viot_devinfo_struct *devi)
261 devi->devno = iminor(ino) & 0x1F;
262 devi->mode = (iminor(ino) & 0x60) >> 5;
263 /* if bit is set in the minor, do _not_ rewind automatically */
264 devi->rewind = (iminor(ino) & 0x80) == 0;
267 /* This is called only from the exit and init paths, so no need for locking */
268 static void clear_op_struct_pool(void)
270 while (op_struct_list) {
271 struct op_struct *toFree = op_struct_list;
272 op_struct_list = op_struct_list->next;
277 /* Likewise, this is only called from the init path */
278 static int add_op_structs(int structs)
282 for (i = 0; i < structs; ++i) {
283 struct op_struct *new_struct =
284 kmalloc(sizeof(*new_struct), GFP_KERNEL);
286 clear_op_struct_pool();
289 new_struct->next = op_struct_list;
290 op_struct_list = new_struct;
295 /* Allocate an op structure from our pool */
296 static struct op_struct *get_op_struct(void)
298 struct op_struct *retval;
301 spin_lock_irqsave(&op_struct_list_lock, flags);
302 retval = op_struct_list;
304 op_struct_list = retval->next;
305 spin_unlock_irqrestore(&op_struct_list_lock, flags);
307 memset(retval, 0, sizeof(*retval));
308 init_completion(&retval->com);
314 /* Return an op structure to our pool */
315 static void free_op_struct(struct op_struct *op_struct)
319 spin_lock_irqsave(&op_struct_list_lock, flags);
320 op_struct->next = op_struct_list;
321 op_struct_list = op_struct;
322 spin_unlock_irqrestore(&op_struct_list_lock, flags);
325 /* Map our tape return codes to errno values */
326 int tape_rc_to_errno(int tape_rc, char *operation, int tapeno)
328 const struct vio_error_entry *err;
333 err = vio_lookup_rc(viotape_err_table, tape_rc);
334 printk(VIOTAPE_KERN_WARN "error(%s) 0x%04x on Device %d (%-10s): %s\n",
335 operation, tape_rc, tapeno,
336 viotape_unitinfo[tapeno].rsrcname, err->msg);
341 static ssize_t viotap_write(struct file *file, const char *buf,
342 size_t count, loff_t * ppos)
345 unsigned short flags = file->f_flags;
346 int noblock = ((flags & O_NONBLOCK) != 0);
348 struct viot_devinfo_struct devi;
349 struct op_struct *op = get_op_struct();
354 get_dev_info(file->f_path.dentry->d_inode, &devi);
357 * We need to make sure we can send a request. We use
358 * a semaphore to keep track of # requests in use. If
359 * we are non-blocking, make sure we don't block on the
363 if (down_trylock(&reqSem)) {
370 /* Allocate a DMA buffer */
371 op->dev = tape_device[devi.devno];
372 op->buffer = dma_alloc_coherent(op->dev, count, &op->dmaaddr,
375 if (op->buffer == NULL) {
376 printk(VIOTAPE_KERN_WARN
377 "error allocating dma buffer for len %ld\n",
383 /* Copy the data into the buffer */
384 if (copy_from_user(op->buffer, buf, count)) {
385 printk(VIOTAPE_KERN_WARN "tape: error on copy from user\n");
390 op->non_blocking = noblock;
391 init_completion(&op->com);
394 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
395 HvLpEvent_Type_VirtualIo,
396 viomajorsubtype_tape | viotapewrite,
397 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
398 viopath_sourceinst(viopath_hostLp),
399 viopath_targetinst(viopath_hostLp),
400 (u64)(unsigned long)op, VIOVERSION << 16,
401 ((u64)devi.devno << 48) | op->dmaaddr, count, 0, 0);
402 if (hvrc != HvLpEvent_Rc_Good) {
403 printk(VIOTAPE_KERN_WARN "hv error on op %d\n",
412 wait_for_completion(&op->com);
415 ret = tape_rc_to_errno(op->rc, "write", devi.devno);
417 chg_state(devi.devno, VIOT_WRITING, file);
422 dma_free_coherent(op->dev, count, op->buffer, op->dmaaddr);
431 static ssize_t viotap_read(struct file *file, char *buf, size_t count,
435 unsigned short flags = file->f_flags;
436 struct op_struct *op = get_op_struct();
437 int noblock = ((flags & O_NONBLOCK) != 0);
439 struct viot_devinfo_struct devi;
444 get_dev_info(file->f_path.dentry->d_inode, &devi);
447 * We need to make sure we can send a request. We use
448 * a semaphore to keep track of # requests in use. If
449 * we are non-blocking, make sure we don't block on the
453 if (down_trylock(&reqSem)) {
460 chg_state(devi.devno, VIOT_READING, file);
462 /* Allocate a DMA buffer */
463 op->dev = tape_device[devi.devno];
464 op->buffer = dma_alloc_coherent(op->dev, count, &op->dmaaddr,
466 if (op->buffer == NULL) {
472 init_completion(&op->com);
474 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
475 HvLpEvent_Type_VirtualIo,
476 viomajorsubtype_tape | viotaperead,
477 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
478 viopath_sourceinst(viopath_hostLp),
479 viopath_targetinst(viopath_hostLp),
480 (u64)(unsigned long)op, VIOVERSION << 16,
481 ((u64)devi.devno << 48) | op->dmaaddr, count, 0, 0);
482 if (hvrc != HvLpEvent_Rc_Good) {
483 printk(VIOTAPE_KERN_WARN "tape hv error on op %d\n",
489 wait_for_completion(&op->com);
492 ret = tape_rc_to_errno(op->rc, "read", devi.devno);
495 if (ret && copy_to_user(buf, op->buffer, ret)) {
496 printk(VIOTAPE_KERN_WARN "error on copy_to_user\n");
502 dma_free_coherent(op->dev, count, op->buffer, op->dmaaddr);
511 static int viotap_ioctl(struct inode *inode, struct file *file,
512 unsigned int cmd, unsigned long arg)
516 struct viot_devinfo_struct devi;
519 struct op_struct *op = get_op_struct();
524 get_dev_info(file->f_path.dentry->d_inode, &devi);
534 * inode is null if and only if we (the kernel)
538 memcpy(&mtc, (void *) arg, sizeof(struct mtop));
539 else if (copy_from_user((char *)&mtc, (char *)arg,
540 sizeof(struct mtop)))
546 myOp = VIOTAPOP_RESET;
561 myOp = VIOTAPOP_WEOF;
573 myOp = VIOTAPOP_ERASE;
576 myOp = VIOTAPOP_SETBLK;
579 myOp = VIOTAPOP_SETDENSITY;
582 myOp = VIOTAPOP_GETPOS;
585 myOp = VIOTAPOP_SETPOS;
588 myOp = VIOTAPOP_SETPART;
591 myOp = VIOTAPOP_UNLOAD;
594 printk(VIOTAPE_KERN_WARN "MTIOCTOP called "
595 "with invalid op 0x%x\n", mtc.mt_op);
600 * if we moved the head, we are no longer
611 chg_state(devi.devno, VIOT_IDLE, file);
614 init_completion(&op->com);
615 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
616 HvLpEvent_Type_VirtualIo,
617 viomajorsubtype_tape | viotapeop,
618 HvLpEvent_AckInd_DoAck,
619 HvLpEvent_AckType_ImmediateAck,
620 viopath_sourceinst(viopath_hostLp),
621 viopath_targetinst(viopath_hostLp),
622 (u64)(unsigned long)op,
624 ((u64)devi.devno << 48), 0,
625 (((u64)myOp) << 32) | mtc.mt_count, 0);
626 if (hvrc != HvLpEvent_Rc_Good) {
627 printk(VIOTAPE_KERN_WARN "hv error on op %d\n",
631 wait_for_completion(&op->com);
632 ret = tape_rc_to_errno(op->rc, "tape operation", devi.devno);
637 init_completion(&op->com);
638 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
639 HvLpEvent_Type_VirtualIo,
640 viomajorsubtype_tape | viotapegetstatus,
641 HvLpEvent_AckInd_DoAck,
642 HvLpEvent_AckType_ImmediateAck,
643 viopath_sourceinst(viopath_hostLp),
644 viopath_targetinst(viopath_hostLp),
645 (u64)(unsigned long)op, VIOVERSION << 16,
646 ((u64)devi.devno << 48), 0, 0, 0);
647 if (hvrc != HvLpEvent_Rc_Good) {
648 printk(VIOTAPE_KERN_WARN "hv error on op %d\n",
652 wait_for_completion(&op->com);
654 /* Operation is complete - grab the error code */
655 ret = tape_rc_to_errno(op->rc, "get status", devi.devno);
659 if ((ret == 0) && copy_to_user((void *)arg,
660 &viomtget[devi.devno],
661 sizeof(viomtget[0])))
665 printk(VIOTAPE_KERN_WARN "Got an (unsupported) MTIOCPOS\n");
668 printk(VIOTAPE_KERN_WARN "got an unsupported ioctl 0x%0x\n",
679 static int viotap_open(struct inode *inode, struct file *file)
682 struct viot_devinfo_struct devi;
684 struct op_struct *op = get_op_struct();
689 get_dev_info(file->f_path.dentry->d_inode, &devi);
691 /* Note: We currently only support one mode! */
692 if ((devi.devno >= viotape_numdev) || (devi.mode)) {
697 init_completion(&op->com);
699 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
700 HvLpEvent_Type_VirtualIo,
701 viomajorsubtype_tape | viotapeopen,
702 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
703 viopath_sourceinst(viopath_hostLp),
704 viopath_targetinst(viopath_hostLp),
705 (u64)(unsigned long)op, VIOVERSION << 16,
706 ((u64)devi.devno << 48), 0, 0, 0);
708 printk(VIOTAPE_KERN_WARN "bad rc on signalLpEvent %d\n",
714 wait_for_completion(&op->com);
715 ret = tape_rc_to_errno(op->rc, "open", devi.devno);
723 static int viotap_release(struct inode *inode, struct file *file)
726 struct viot_devinfo_struct devi;
728 struct op_struct *op = get_op_struct();
732 init_completion(&op->com);
734 get_dev_info(file->f_path.dentry->d_inode, &devi);
736 if (devi.devno >= viotape_numdev) {
741 chg_state(devi.devno, VIOT_IDLE, file);
744 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
745 HvLpEvent_Type_VirtualIo,
746 viomajorsubtype_tape | viotapeop,
747 HvLpEvent_AckInd_DoAck,
748 HvLpEvent_AckType_ImmediateAck,
749 viopath_sourceinst(viopath_hostLp),
750 viopath_targetinst(viopath_hostLp),
751 (u64)(unsigned long)op, VIOVERSION << 16,
752 ((u64)devi.devno << 48), 0,
753 ((u64)VIOTAPOP_REW) << 32, 0);
754 wait_for_completion(&op->com);
756 tape_rc_to_errno(op->rc, "rewind", devi.devno);
759 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
760 HvLpEvent_Type_VirtualIo,
761 viomajorsubtype_tape | viotapeclose,
762 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
763 viopath_sourceinst(viopath_hostLp),
764 viopath_targetinst(viopath_hostLp),
765 (u64)(unsigned long)op, VIOVERSION << 16,
766 ((u64)devi.devno << 48), 0, 0, 0);
768 printk(VIOTAPE_KERN_WARN "bad rc on signalLpEvent %d\n",
774 wait_for_completion(&op->com);
777 printk(VIOTAPE_KERN_WARN "close failed\n");
784 const struct file_operations viotap_fops = {
785 .owner = THIS_MODULE,
787 .write = viotap_write,
788 .ioctl = viotap_ioctl,
790 .release = viotap_release,
793 /* Handle interrupt events for tape */
794 static void vioHandleTapeEvent(struct HvLpEvent *event)
797 struct op_struct *op;
798 struct viotapelpevent *tevent = (struct viotapelpevent *)event;
801 /* Notification that a partition went away! */
802 if (!viopath_isactive(viopath_hostLp)) {
808 tapeminor = event->xSubtype & VIOMINOR_SUBTYPE_MASK;
809 op = (struct op_struct *)event->xCorrelationToken;
813 op->rc = tevent->sub_type_result;
817 op->rc = tevent->sub_type_result;
818 op->count = tevent->len;
822 if (op->non_blocking) {
823 dma_free_coherent(op->dev, op->count,
824 op->buffer, op->dmaaddr);
828 op->rc = tevent->sub_type_result;
829 op->count = tevent->len;
836 case viotapegetstatus:
838 op->count = tevent->u.op.count;
839 op->rc = tevent->sub_type_result;
840 if (!op->non_blocking)
845 printk(VIOTAPE_KERN_WARN "weird ack\n");
849 static int viotape_probe(struct vio_dev *vdev, const struct vio_device_id *id)
851 int i = vdev->unit_address;
853 struct device_node *node = vdev->dev.archdata.of_node;
855 if (i > VIOTAPE_MAX_TAPE)
860 if (i >= viotape_numdev)
861 viotape_numdev = i + 1;
863 tape_device[i] = &vdev->dev;
864 viotape_unitinfo[i].rsrcname = of_get_property(node,
865 "linux,vio_rsrcname", NULL);
866 viotape_unitinfo[i].type = of_get_property(node, "linux,vio_type",
868 viotape_unitinfo[i].model = of_get_property(node, "linux,vio_model",
871 state[i].cur_part = 0;
872 for (j = 0; j < MAX_PARTITIONS; ++j)
873 state[i].part_stat_rwi[j] = VIOT_IDLE;
874 class_device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i), NULL,
876 class_device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i | 0x80),
877 NULL, "iseries!nvt%d", i);
878 printk(VIOTAPE_KERN_INFO "tape iseries/vt%d is iSeries "
879 "resource %10.10s type %4.4s, model %3.3s\n",
880 i, viotape_unitinfo[i].rsrcname,
881 viotape_unitinfo[i].type, viotape_unitinfo[i].model);
885 static int viotape_remove(struct vio_dev *vdev)
887 int i = vdev->unit_address;
889 class_device_destroy(tape_class, MKDEV(VIOTAPE_MAJOR, i | 0x80));
890 class_device_destroy(tape_class, MKDEV(VIOTAPE_MAJOR, i));
895 * viotape_device_table: Used by vio.c to match devices that we
898 static struct vio_device_id viotape_device_table[] __devinitdata = {
899 { "byte", "IBM,iSeries-viotape" },
902 MODULE_DEVICE_TABLE(vio, viotape_device_table);
904 static struct vio_driver viotape_driver = {
905 .id_table = viotape_device_table,
906 .probe = viotape_probe,
907 .remove = viotape_remove,
910 .owner = THIS_MODULE,
915 int __init viotap_init(void)
918 struct proc_dir_entry *e;
920 if (!firmware_has_feature(FW_FEATURE_ISERIES))
923 op_struct_list = NULL;
924 if ((ret = add_op_structs(VIOTAPE_MAXREQ)) < 0) {
925 printk(VIOTAPE_KERN_WARN "couldn't allocate op structs\n");
928 spin_lock_init(&op_struct_list_lock);
930 sema_init(&reqSem, VIOTAPE_MAXREQ);
932 if (viopath_hostLp == HvLpIndexInvalid) {
934 if (viopath_hostLp == HvLpIndexInvalid) {
940 ret = viopath_open(viopath_hostLp, viomajorsubtype_tape,
943 printk(VIOTAPE_KERN_WARN
944 "error on viopath_open to hostlp %d\n", ret);
949 printk(VIOTAPE_KERN_INFO "vers " VIOTAPE_VERSION
950 ", hosting partition %d\n", viopath_hostLp);
952 vio_setHandler(viomajorsubtype_tape, vioHandleTapeEvent);
954 ret = register_chrdev(VIOTAPE_MAJOR, "viotape", &viotap_fops);
956 printk(VIOTAPE_KERN_WARN "Error registering viotape device\n");
960 tape_class = class_create(THIS_MODULE, "tape");
961 if (IS_ERR(tape_class)) {
962 printk(VIOTAPE_KERN_WARN "Unable to allocat class\n");
963 ret = PTR_ERR(tape_class);
967 ret = vio_register_driver(&viotape_driver);
971 e = create_proc_entry("iSeries/viotape", S_IFREG|S_IRUGO, NULL);
973 e->owner = THIS_MODULE;
974 e->proc_fops = &proc_viotape_operations;
980 class_destroy(tape_class);
982 unregister_chrdev(VIOTAPE_MAJOR, "viotape");
984 vio_clearHandler(viomajorsubtype_tape);
985 viopath_close(viopath_hostLp, viomajorsubtype_tape, VIOTAPE_MAXREQ + 2);
987 clear_op_struct_pool();
991 /* Give a new state to the tape object */
992 static int chg_state(int index, unsigned char new_state, struct file *file)
994 unsigned char *cur_state =
995 &state[index].part_stat_rwi[state[index].cur_part];
998 /* if the same state, don't bother */
999 if (*cur_state == new_state)
1002 /* write an EOF if changing from writing to some other state */
1003 if (*cur_state == VIOT_WRITING) {
1004 struct mtop write_eof = { MTWEOF, 1 };
1006 rc = viotap_ioctl(NULL, file, MTIOCTOP,
1007 (unsigned long)&write_eof);
1009 *cur_state = new_state;
1014 static void __exit viotap_exit(void)
1016 remove_proc_entry("iSeries/viotape", NULL);
1017 vio_unregister_driver(&viotape_driver);
1018 class_destroy(tape_class);
1019 unregister_chrdev(VIOTAPE_MAJOR, "viotape");
1020 viopath_close(viopath_hostLp, viomajorsubtype_tape, VIOTAPE_MAXREQ + 2);
1021 vio_clearHandler(viomajorsubtype_tape);
1022 clear_op_struct_pool();
1025 MODULE_LICENSE("GPL");
1026 module_init(viotap_init);
1027 module_exit(viotap_exit);