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/config.h>
35 #include <linux/version.h>
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/errno.h>
39 #include <linux/init.h>
40 #include <linux/wait.h>
41 #include <linux/spinlock.h>
42 #include <linux/mtio.h>
43 #include <linux/device.h>
44 #include <linux/dma-mapping.h>
46 #include <linux/cdev.h>
47 #include <linux/devfs_fs_kernel.h>
48 #include <linux/major.h>
49 #include <linux/completion.h>
50 #include <linux/proc_fs.h>
51 #include <linux/seq_file.h>
53 #include <asm/uaccess.h>
54 #include <asm/ioctls.h>
56 #include <asm/iSeries/vio.h>
57 #include <asm/iSeries/HvLpEvent.h>
58 #include <asm/iSeries/HvCallEvent.h>
59 #include <asm/iSeries/HvLpConfig.h>
61 #define VIOTAPE_VERSION "1.2"
62 #define VIOTAPE_MAXREQ 1
64 #define VIOTAPE_KERN_WARN KERN_WARNING "viotape: "
65 #define VIOTAPE_KERN_INFO KERN_INFO "viotape: "
67 static int viotape_numdev;
70 * The minor number follows the conventions of the SCSI tape drives. The
71 * rewind and mode are encoded in the minor #. We use this struct to break
74 struct viot_devinfo_struct {
80 #define VIOTAPOP_RESET 0
81 #define VIOTAPOP_FSF 1
82 #define VIOTAPOP_BSF 2
83 #define VIOTAPOP_FSR 3
84 #define VIOTAPOP_BSR 4
85 #define VIOTAPOP_WEOF 5
86 #define VIOTAPOP_REW 6
87 #define VIOTAPOP_NOP 7
88 #define VIOTAPOP_EOM 8
89 #define VIOTAPOP_ERASE 9
90 #define VIOTAPOP_SETBLK 10
91 #define VIOTAPOP_SETDENSITY 11
92 #define VIOTAPOP_SETPOS 12
93 #define VIOTAPOP_GETPOS 13
94 #define VIOTAPOP_SETPART 14
95 #define VIOTAPOP_UNLOAD 15
97 struct viotapelpevent {
98 struct HvLpEvent event;
126 enum viotapesubtype {
127 viotapeopen = 0x0001,
128 viotapeclose = 0x0002,
129 viotaperead = 0x0003,
130 viotapewrite = 0x0004,
131 viotapegetinfo = 0x0005,
133 viotapegetpos = 0x0007,
134 viotapesetpos = 0x0008,
135 viotapegetstatus = 0x0009
139 viotape_InvalidRange = 0x0601,
140 viotape_InvalidToken = 0x0602,
141 viotape_DMAError = 0x0603,
142 viotape_UseError = 0x0604,
143 viotape_ReleaseError = 0x0605,
144 viotape_InvalidTape = 0x0606,
145 viotape_InvalidOp = 0x0607,
146 viotape_TapeErr = 0x0608,
148 viotape_AllocTimedOut = 0x0640,
149 viotape_BOTEnc = 0x0641,
150 viotape_BlankTape = 0x0642,
151 viotape_BufferEmpty = 0x0643,
152 viotape_CleanCartFound = 0x0644,
153 viotape_CmdNotAllowed = 0x0645,
154 viotape_CmdNotSupported = 0x0646,
155 viotape_DataCheck = 0x0647,
156 viotape_DecompressErr = 0x0648,
157 viotape_DeviceTimeout = 0x0649,
158 viotape_DeviceUnavail = 0x064a,
159 viotape_DeviceBusy = 0x064b,
160 viotape_EndOfMedia = 0x064c,
161 viotape_EndOfTape = 0x064d,
162 viotape_EquipCheck = 0x064e,
163 viotape_InsufficientRs = 0x064f,
164 viotape_InvalidLogBlk = 0x0650,
165 viotape_LengthError = 0x0651,
166 viotape_LibDoorOpen = 0x0652,
167 viotape_LoadFailure = 0x0653,
168 viotape_NotCapable = 0x0654,
169 viotape_NotOperational = 0x0655,
170 viotape_NotReady = 0x0656,
171 viotape_OpCancelled = 0x0657,
172 viotape_PhyLinkErr = 0x0658,
173 viotape_RdyNotBOT = 0x0659,
174 viotape_TapeMark = 0x065a,
175 viotape_WriteProt = 0x065b
178 static const struct vio_error_entry viotape_err_table[] = {
179 { viotape_InvalidRange, EIO, "Internal error" },
180 { viotape_InvalidToken, EIO, "Internal error" },
181 { viotape_DMAError, EIO, "DMA error" },
182 { viotape_UseError, EIO, "Internal error" },
183 { viotape_ReleaseError, EIO, "Internal error" },
184 { viotape_InvalidTape, EIO, "Invalid tape device" },
185 { viotape_InvalidOp, EIO, "Invalid operation" },
186 { viotape_TapeErr, EIO, "Tape error" },
187 { viotape_AllocTimedOut, EBUSY, "Allocate timed out" },
188 { viotape_BOTEnc, EIO, "Beginning of tape encountered" },
189 { viotape_BlankTape, EIO, "Blank tape" },
190 { viotape_BufferEmpty, EIO, "Buffer empty" },
191 { viotape_CleanCartFound, ENOMEDIUM, "Cleaning cartridge found" },
192 { viotape_CmdNotAllowed, EIO, "Command not allowed" },
193 { viotape_CmdNotSupported, EIO, "Command not supported" },
194 { viotape_DataCheck, EIO, "Data check" },
195 { viotape_DecompressErr, EIO, "Decompression error" },
196 { viotape_DeviceTimeout, EBUSY, "Device timeout" },
197 { viotape_DeviceUnavail, EIO, "Device unavailable" },
198 { viotape_DeviceBusy, EBUSY, "Device busy" },
199 { viotape_EndOfMedia, ENOSPC, "End of media" },
200 { viotape_EndOfTape, ENOSPC, "End of tape" },
201 { viotape_EquipCheck, EIO, "Equipment check" },
202 { viotape_InsufficientRs, EOVERFLOW, "Insufficient tape resources" },
203 { viotape_InvalidLogBlk, EIO, "Invalid logical block location" },
204 { viotape_LengthError, EOVERFLOW, "Length error" },
205 { viotape_LibDoorOpen, EBUSY, "Door open" },
206 { viotape_LoadFailure, ENOMEDIUM, "Load failure" },
207 { viotape_NotCapable, EIO, "Not capable" },
208 { viotape_NotOperational, EIO, "Not operational" },
209 { viotape_NotReady, EIO, "Not ready" },
210 { viotape_OpCancelled, EIO, "Operation cancelled" },
211 { viotape_PhyLinkErr, EIO, "Physical link error" },
212 { viotape_RdyNotBOT, EIO, "Ready but not beginning of tape" },
213 { viotape_TapeMark, EIO, "Tape mark" },
214 { viotape_WriteProt, EROFS, "Write protection error" },
218 /* Maximum number of tapes we support */
219 #define VIOTAPE_MAX_TAPE 8
220 #define MAX_PARTITIONS 4
222 /* defines for current tape state */
224 #define VIOT_READING 1
225 #define VIOT_WRITING 2
227 /* Our info on the tapes */
234 static struct tape_descr *viotape_unitinfo;
235 static dma_addr_t viotape_unitinfo_token;
237 static struct mtget viomtget[VIOTAPE_MAX_TAPE];
239 static struct class_simple *tape_class;
242 * maintain the current state of each tape (and partition)
243 * so that we know when to write EOF marks.
246 unsigned char cur_part;
248 unsigned char part_stat_rwi[MAX_PARTITIONS];
249 } state[VIOTAPE_MAX_TAPE];
251 /* We single-thread */
252 static struct semaphore reqSem;
255 * When we send a request, we use this struct to get the response back
256 * from the interrupt handler
264 struct completion com;
265 struct op_struct *next;
268 static spinlock_t op_struct_list_lock;
269 static struct op_struct *op_struct_list;
271 /* forward declaration to resolve interdependence */
272 static int chg_state(int index, unsigned char new_state, struct file *file);
275 static int proc_viotape_show(struct seq_file *m, void *v)
279 seq_printf(m, "viotape driver version " VIOTAPE_VERSION "\n");
280 for (i = 0; i < viotape_numdev; i++) {
281 seq_printf(m, "viotape device %d is iSeries resource %10.10s"
282 "type %4.4s, model %3.3s\n",
283 i, viotape_unitinfo[i].rsrcname,
284 viotape_unitinfo[i].type,
285 viotape_unitinfo[i].model);
290 static int proc_viotape_open(struct inode *inode, struct file *file)
292 return single_open(file, proc_viotape_show, NULL);
295 static struct file_operations proc_viotape_operations = {
296 .open = proc_viotape_open,
299 .release = single_release,
302 /* Decode the device minor number into its parts */
303 void get_dev_info(struct inode *ino, struct viot_devinfo_struct *devi)
305 devi->devno = iminor(ino) & 0x1F;
306 devi->mode = (iminor(ino) & 0x60) >> 5;
307 /* if bit is set in the minor, do _not_ rewind automatically */
308 devi->rewind = (iminor(ino) & 0x80) == 0;
311 /* This is called only from the exit and init paths, so no need for locking */
312 static void clear_op_struct_pool(void)
314 while (op_struct_list) {
315 struct op_struct *toFree = op_struct_list;
316 op_struct_list = op_struct_list->next;
321 /* Likewise, this is only called from the init path */
322 static int add_op_structs(int structs)
326 for (i = 0; i < structs; ++i) {
327 struct op_struct *new_struct =
328 kmalloc(sizeof(*new_struct), GFP_KERNEL);
330 clear_op_struct_pool();
333 new_struct->next = op_struct_list;
334 op_struct_list = new_struct;
339 /* Allocate an op structure from our pool */
340 static struct op_struct *get_op_struct(void)
342 struct op_struct *retval;
345 spin_lock_irqsave(&op_struct_list_lock, flags);
346 retval = op_struct_list;
348 op_struct_list = retval->next;
349 spin_unlock_irqrestore(&op_struct_list_lock, flags);
351 memset(retval, 0, sizeof(*retval));
352 init_completion(&retval->com);
358 /* Return an op structure to our pool */
359 static void free_op_struct(struct op_struct *op_struct)
363 spin_lock_irqsave(&op_struct_list_lock, flags);
364 op_struct->next = op_struct_list;
365 op_struct_list = op_struct;
366 spin_unlock_irqrestore(&op_struct_list_lock, flags);
369 /* Map our tape return codes to errno values */
370 int tape_rc_to_errno(int tape_rc, char *operation, int tapeno)
372 const struct vio_error_entry *err;
377 err = vio_lookup_rc(viotape_err_table, tape_rc);
378 printk(VIOTAPE_KERN_WARN "error(%s) 0x%04x on Device %d (%-10s): %s\n",
379 operation, tape_rc, tapeno,
380 viotape_unitinfo[tapeno].rsrcname, err->msg);
384 /* Get info on all tapes from OS/400 */
385 static int get_viotape_info(void)
389 size_t len = sizeof(*viotape_unitinfo) * VIOTAPE_MAX_TAPE;
390 struct op_struct *op = get_op_struct();
395 viotape_unitinfo = dma_alloc_coherent(iSeries_vio_dev, len,
396 &viotape_unitinfo_token, GFP_ATOMIC);
397 if (viotape_unitinfo == NULL) {
402 memset(viotape_unitinfo, 0, len);
404 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
405 HvLpEvent_Type_VirtualIo,
406 viomajorsubtype_tape | viotapegetinfo,
407 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
408 viopath_sourceinst(viopath_hostLp),
409 viopath_targetinst(viopath_hostLp),
410 (u64) (unsigned long) op, VIOVERSION << 16,
411 viotape_unitinfo_token, len, 0, 0);
412 if (hvrc != HvLpEvent_Rc_Good) {
413 printk(VIOTAPE_KERN_WARN "hv error on op %d\n",
419 wait_for_completion(&op->com);
424 ((i < VIOTAPE_MAX_TAPE) && (viotape_unitinfo[i].rsrcname[0]));
432 static ssize_t viotap_write(struct file *file, const char *buf,
433 size_t count, loff_t * ppos)
436 unsigned short flags = file->f_flags;
437 int noblock = ((flags & O_NONBLOCK) != 0);
439 struct viot_devinfo_struct devi;
440 struct op_struct *op = get_op_struct();
445 get_dev_info(file->f_dentry->d_inode, &devi);
448 * We need to make sure we can send a request. We use
449 * a semaphore to keep track of # requests in use. If
450 * we are non-blocking, make sure we don't block on the
454 if (down_trylock(&reqSem)) {
461 /* Allocate a DMA buffer */
462 op->buffer = dma_alloc_coherent(iSeries_vio_dev, count, &op->dmaaddr,
465 if (op->buffer == NULL) {
466 printk(VIOTAPE_KERN_WARN
467 "error allocating dma buffer for len %ld\n",
473 /* Copy the data into the buffer */
474 if (copy_from_user(op->buffer, buf, count)) {
475 printk(VIOTAPE_KERN_WARN "tape: error on copy from user\n");
480 op->non_blocking = noblock;
481 init_completion(&op->com);
484 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
485 HvLpEvent_Type_VirtualIo,
486 viomajorsubtype_tape | viotapewrite,
487 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
488 viopath_sourceinst(viopath_hostLp),
489 viopath_targetinst(viopath_hostLp),
490 (u64)(unsigned long)op, VIOVERSION << 16,
491 ((u64)devi.devno << 48) | op->dmaaddr, count, 0, 0);
492 if (hvrc != HvLpEvent_Rc_Good) {
493 printk(VIOTAPE_KERN_WARN "hv error on op %d\n",
502 wait_for_completion(&op->com);
505 ret = tape_rc_to_errno(op->rc, "write", devi.devno);
507 chg_state(devi.devno, VIOT_WRITING, file);
512 dma_free_coherent(iSeries_vio_dev, count, op->buffer, op->dmaaddr);
521 static ssize_t viotap_read(struct file *file, char *buf, size_t count,
525 unsigned short flags = file->f_flags;
526 struct op_struct *op = get_op_struct();
527 int noblock = ((flags & O_NONBLOCK) != 0);
529 struct viot_devinfo_struct devi;
534 get_dev_info(file->f_dentry->d_inode, &devi);
537 * We need to make sure we can send a request. We use
538 * a semaphore to keep track of # requests in use. If
539 * we are non-blocking, make sure we don't block on the
543 if (down_trylock(&reqSem)) {
550 chg_state(devi.devno, VIOT_READING, file);
552 /* Allocate a DMA buffer */
553 op->buffer = dma_alloc_coherent(iSeries_vio_dev, count, &op->dmaaddr,
555 if (op->buffer == NULL) {
561 init_completion(&op->com);
563 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
564 HvLpEvent_Type_VirtualIo,
565 viomajorsubtype_tape | viotaperead,
566 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
567 viopath_sourceinst(viopath_hostLp),
568 viopath_targetinst(viopath_hostLp),
569 (u64)(unsigned long)op, VIOVERSION << 16,
570 ((u64)devi.devno << 48) | op->dmaaddr, count, 0, 0);
571 if (hvrc != HvLpEvent_Rc_Good) {
572 printk(VIOTAPE_KERN_WARN "tape hv error on op %d\n",
578 wait_for_completion(&op->com);
581 ret = tape_rc_to_errno(op->rc, "read", devi.devno);
584 if (ret && copy_to_user(buf, op->buffer, ret)) {
585 printk(VIOTAPE_KERN_WARN "error on copy_to_user\n");
591 dma_free_coherent(iSeries_vio_dev, count, op->buffer, op->dmaaddr);
600 static int viotap_ioctl(struct inode *inode, struct file *file,
601 unsigned int cmd, unsigned long arg)
605 struct viot_devinfo_struct devi;
608 struct op_struct *op = get_op_struct();
613 get_dev_info(file->f_dentry->d_inode, &devi);
623 * inode is null if and only if we (the kernel)
627 memcpy(&mtc, (void *) arg, sizeof(struct mtop));
628 else if (copy_from_user((char *)&mtc, (char *)arg,
629 sizeof(struct mtop)))
635 myOp = VIOTAPOP_RESET;
650 myOp = VIOTAPOP_WEOF;
662 myOp = VIOTAPOP_ERASE;
665 myOp = VIOTAPOP_SETBLK;
668 myOp = VIOTAPOP_SETDENSITY;
671 myOp = VIOTAPOP_GETPOS;
674 myOp = VIOTAPOP_SETPOS;
677 myOp = VIOTAPOP_SETPART;
680 myOp = VIOTAPOP_UNLOAD;
683 printk(VIOTAPE_KERN_WARN "MTIOCTOP called "
684 "with invalid op 0x%x\n", mtc.mt_op);
689 * if we moved the head, we are no longer
700 chg_state(devi.devno, VIOT_IDLE, file);
703 init_completion(&op->com);
704 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
705 HvLpEvent_Type_VirtualIo,
706 viomajorsubtype_tape | viotapeop,
707 HvLpEvent_AckInd_DoAck,
708 HvLpEvent_AckType_ImmediateAck,
709 viopath_sourceinst(viopath_hostLp),
710 viopath_targetinst(viopath_hostLp),
711 (u64)(unsigned long)op,
713 ((u64)devi.devno << 48), 0,
714 (((u64)myOp) << 32) | mtc.mt_count, 0);
715 if (hvrc != HvLpEvent_Rc_Good) {
716 printk(VIOTAPE_KERN_WARN "hv error on op %d\n",
720 wait_for_completion(&op->com);
721 ret = tape_rc_to_errno(op->rc, "tape operation", devi.devno);
726 init_completion(&op->com);
727 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
728 HvLpEvent_Type_VirtualIo,
729 viomajorsubtype_tape | viotapegetstatus,
730 HvLpEvent_AckInd_DoAck,
731 HvLpEvent_AckType_ImmediateAck,
732 viopath_sourceinst(viopath_hostLp),
733 viopath_targetinst(viopath_hostLp),
734 (u64)(unsigned long)op, VIOVERSION << 16,
735 ((u64)devi.devno << 48), 0, 0, 0);
736 if (hvrc != HvLpEvent_Rc_Good) {
737 printk(VIOTAPE_KERN_WARN "hv error on op %d\n",
741 wait_for_completion(&op->com);
743 /* Operation is complete - grab the error code */
744 ret = tape_rc_to_errno(op->rc, "get status", devi.devno);
748 if ((ret == 0) && copy_to_user((void *)arg,
749 &viomtget[devi.devno],
750 sizeof(viomtget[0])))
754 printk(VIOTAPE_KERN_WARN "Got an (unsupported) MTIOCPOS\n");
757 printk(VIOTAPE_KERN_WARN "got an unsupported ioctl 0x%0x\n",
768 static int viotap_open(struct inode *inode, struct file *file)
771 struct viot_devinfo_struct devi;
773 struct op_struct *op = get_op_struct();
778 get_dev_info(file->f_dentry->d_inode, &devi);
780 /* Note: We currently only support one mode! */
781 if ((devi.devno >= viotape_numdev) || (devi.mode)) {
786 init_completion(&op->com);
788 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
789 HvLpEvent_Type_VirtualIo,
790 viomajorsubtype_tape | viotapeopen,
791 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
792 viopath_sourceinst(viopath_hostLp),
793 viopath_targetinst(viopath_hostLp),
794 (u64)(unsigned long)op, VIOVERSION << 16,
795 ((u64)devi.devno << 48), 0, 0, 0);
797 printk(VIOTAPE_KERN_WARN "bad rc on signalLpEvent %d\n",
803 wait_for_completion(&op->com);
804 ret = tape_rc_to_errno(op->rc, "open", devi.devno);
812 static int viotap_release(struct inode *inode, struct file *file)
815 struct viot_devinfo_struct devi;
817 struct op_struct *op = get_op_struct();
821 init_completion(&op->com);
823 get_dev_info(file->f_dentry->d_inode, &devi);
825 if (devi.devno >= viotape_numdev) {
830 chg_state(devi.devno, VIOT_IDLE, file);
833 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
834 HvLpEvent_Type_VirtualIo,
835 viomajorsubtype_tape | viotapeop,
836 HvLpEvent_AckInd_DoAck,
837 HvLpEvent_AckType_ImmediateAck,
838 viopath_sourceinst(viopath_hostLp),
839 viopath_targetinst(viopath_hostLp),
840 (u64)(unsigned long)op, VIOVERSION << 16,
841 ((u64)devi.devno << 48), 0,
842 ((u64)VIOTAPOP_REW) << 32, 0);
843 wait_for_completion(&op->com);
845 tape_rc_to_errno(op->rc, "rewind", devi.devno);
848 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
849 HvLpEvent_Type_VirtualIo,
850 viomajorsubtype_tape | viotapeclose,
851 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
852 viopath_sourceinst(viopath_hostLp),
853 viopath_targetinst(viopath_hostLp),
854 (u64)(unsigned long)op, VIOVERSION << 16,
855 ((u64)devi.devno << 48), 0, 0, 0);
857 printk(VIOTAPE_KERN_WARN "bad rc on signalLpEvent %d\n",
863 wait_for_completion(&op->com);
866 printk(VIOTAPE_KERN_WARN "close failed\n");
873 struct file_operations viotap_fops = {
879 release: viotap_release,
882 /* Handle interrupt events for tape */
883 static void vioHandleTapeEvent(struct HvLpEvent *event)
886 struct op_struct *op;
887 struct viotapelpevent *tevent = (struct viotapelpevent *)event;
890 /* Notification that a partition went away! */
891 if (!viopath_isactive(viopath_hostLp)) {
897 tapeminor = event->xSubtype & VIOMINOR_SUBTYPE_MASK;
898 op = (struct op_struct *)event->xCorrelationToken;
903 op->rc = tevent->sub_type_result;
907 op->rc = tevent->sub_type_result;
908 op->count = tevent->len;
912 if (op->non_blocking) {
913 dma_free_coherent(iSeries_vio_dev, op->count,
914 op->buffer, op->dmaaddr);
918 op->rc = tevent->sub_type_result;
919 op->count = tevent->len;
926 case viotapegetstatus:
928 op->count = tevent->u.op.count;
929 op->rc = tevent->sub_type_result;
930 if (!op->non_blocking)
935 printk(VIOTAPE_KERN_WARN "wierd ack\n");
940 int __init viotap_init(void)
945 struct proc_dir_entry *e;
947 op_struct_list = NULL;
948 if ((ret = add_op_structs(VIOTAPE_MAXREQ)) < 0) {
949 printk(VIOTAPE_KERN_WARN "couldn't allocate op structs\n");
952 spin_lock_init(&op_struct_list_lock);
954 sema_init(&reqSem, VIOTAPE_MAXREQ);
956 if (viopath_hostLp == HvLpIndexInvalid) {
958 if (viopath_hostLp == HvLpIndexInvalid) {
964 ret = viopath_open(viopath_hostLp, viomajorsubtype_tape,
967 printk(VIOTAPE_KERN_WARN
968 "error on viopath_open to hostlp %d\n", ret);
973 printk(VIOTAPE_KERN_INFO "vers " VIOTAPE_VERSION
974 ", hosting partition %d\n", viopath_hostLp);
976 vio_setHandler(viomajorsubtype_tape, vioHandleTapeEvent);
978 ret = register_chrdev(VIOTAPE_MAJOR, "viotape", &viotap_fops);
980 printk(VIOTAPE_KERN_WARN "Error registering viotape device\n");
984 tape_class = class_simple_create(THIS_MODULE, "tape");
985 if (IS_ERR(tape_class)) {
986 printk(VIOTAPE_KERN_WARN "Unable to allocat class\n");
987 ret = PTR_ERR(tape_class);
991 if ((ret = get_viotape_info()) < 0) {
992 printk(VIOTAPE_KERN_WARN "Unable to obtain virtual device information");
996 for (i = 0; i < viotape_numdev; i++) {
999 state[i].cur_part = 0;
1000 for (j = 0; j < MAX_PARTITIONS; ++j)
1001 state[i].part_stat_rwi[j] = VIOT_IDLE;
1002 class_simple_device_add(tape_class, MKDEV(VIOTAPE_MAJOR, i),
1003 NULL, "iseries!vt%d", i);
1004 class_simple_device_add(tape_class,
1005 MKDEV(VIOTAPE_MAJOR, i | 0x80),
1006 NULL, "iseries!nvt%d", i);
1007 devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR, i),
1008 S_IFCHR | S_IRUSR | S_IWUSR,
1010 devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR, i | 0x80),
1011 S_IFCHR | S_IRUSR | S_IWUSR,
1012 "iseries/nvt%d", i);
1013 sprintf(tapename, "iseries/vt%d", i);
1014 state[i].dev_handle = devfs_register_tape(tapename);
1015 printk(VIOTAPE_KERN_INFO "tape %s is iSeries "
1016 "resource %10.10s type %4.4s, model %3.3s\n",
1017 tapename, viotape_unitinfo[i].rsrcname,
1018 viotape_unitinfo[i].type,
1019 viotape_unitinfo[i].model);
1022 e = create_proc_entry("iSeries/viotape", S_IFREG|S_IRUGO, NULL);
1024 e->owner = THIS_MODULE;
1025 e->proc_fops = &proc_viotape_operations;
1031 class_simple_destroy(tape_class);
1033 unregister_chrdev(VIOTAPE_MAJOR, "viotape");
1035 vio_clearHandler(viomajorsubtype_tape);
1036 viopath_close(viopath_hostLp, viomajorsubtype_tape, VIOTAPE_MAXREQ + 2);
1038 clear_op_struct_pool();
1042 /* Give a new state to the tape object */
1043 static int chg_state(int index, unsigned char new_state, struct file *file)
1045 unsigned char *cur_state =
1046 &state[index].part_stat_rwi[state[index].cur_part];
1049 /* if the same state, don't bother */
1050 if (*cur_state == new_state)
1053 /* write an EOF if changing from writing to some other state */
1054 if (*cur_state == VIOT_WRITING) {
1055 struct mtop write_eof = { MTWEOF, 1 };
1057 rc = viotap_ioctl(NULL, file, MTIOCTOP,
1058 (unsigned long)&write_eof);
1060 *cur_state = new_state;
1065 static void __exit viotap_exit(void)
1069 remove_proc_entry("iSeries/viotape", NULL);
1071 for (i = 0; i < viotape_numdev; ++i) {
1072 devfs_remove("iseries/nvt%d", i);
1073 devfs_remove("iseries/vt%d", i);
1074 devfs_unregister_tape(state[i].dev_handle);
1075 class_simple_device_remove(MKDEV(VIOTAPE_MAJOR, i | 0x80));
1076 class_simple_device_remove(MKDEV(VIOTAPE_MAJOR, i));
1078 class_simple_destroy(tape_class);
1079 ret = unregister_chrdev(VIOTAPE_MAJOR, "viotape");
1081 printk(VIOTAPE_KERN_WARN "Error unregistering device: %d\n",
1083 if (viotape_unitinfo)
1084 dma_free_coherent(iSeries_vio_dev,
1085 sizeof(viotape_unitinfo[0]) * VIOTAPE_MAX_TAPE,
1086 viotape_unitinfo, viotape_unitinfo_token);
1087 viopath_close(viopath_hostLp, viomajorsubtype_tape, VIOTAPE_MAXREQ + 2);
1088 vio_clearHandler(viomajorsubtype_tape);
1089 clear_op_struct_pool();
1092 MODULE_LICENSE("GPL");
1093 module_init(viotap_init);
1094 module_exit(viotap_exit);