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>
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>
49 #include <linux/smp_lock.h>
50 #include <linux/slab.h>
52 #include <asm/uaccess.h>
53 #include <asm/ioctls.h>
54 #include <asm/firmware.h>
56 #include <asm/iseries/vio.h>
57 #include <asm/iseries/hv_lp_event.h>
58 #include <asm/iseries/hv_call_event.h>
59 #include <asm/iseries/hv_lp_config.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
98 viotape_InvalidRange
= 0x0601,
99 viotape_InvalidToken
= 0x0602,
100 viotape_DMAError
= 0x0603,
101 viotape_UseError
= 0x0604,
102 viotape_ReleaseError
= 0x0605,
103 viotape_InvalidTape
= 0x0606,
104 viotape_InvalidOp
= 0x0607,
105 viotape_TapeErr
= 0x0608,
107 viotape_AllocTimedOut
= 0x0640,
108 viotape_BOTEnc
= 0x0641,
109 viotape_BlankTape
= 0x0642,
110 viotape_BufferEmpty
= 0x0643,
111 viotape_CleanCartFound
= 0x0644,
112 viotape_CmdNotAllowed
= 0x0645,
113 viotape_CmdNotSupported
= 0x0646,
114 viotape_DataCheck
= 0x0647,
115 viotape_DecompressErr
= 0x0648,
116 viotape_DeviceTimeout
= 0x0649,
117 viotape_DeviceUnavail
= 0x064a,
118 viotape_DeviceBusy
= 0x064b,
119 viotape_EndOfMedia
= 0x064c,
120 viotape_EndOfTape
= 0x064d,
121 viotape_EquipCheck
= 0x064e,
122 viotape_InsufficientRs
= 0x064f,
123 viotape_InvalidLogBlk
= 0x0650,
124 viotape_LengthError
= 0x0651,
125 viotape_LibDoorOpen
= 0x0652,
126 viotape_LoadFailure
= 0x0653,
127 viotape_NotCapable
= 0x0654,
128 viotape_NotOperational
= 0x0655,
129 viotape_NotReady
= 0x0656,
130 viotape_OpCancelled
= 0x0657,
131 viotape_PhyLinkErr
= 0x0658,
132 viotape_RdyNotBOT
= 0x0659,
133 viotape_TapeMark
= 0x065a,
134 viotape_WriteProt
= 0x065b
137 static const struct vio_error_entry viotape_err_table
[] = {
138 { viotape_InvalidRange
, EIO
, "Internal error" },
139 { viotape_InvalidToken
, EIO
, "Internal error" },
140 { viotape_DMAError
, EIO
, "DMA error" },
141 { viotape_UseError
, EIO
, "Internal error" },
142 { viotape_ReleaseError
, EIO
, "Internal error" },
143 { viotape_InvalidTape
, EIO
, "Invalid tape device" },
144 { viotape_InvalidOp
, EIO
, "Invalid operation" },
145 { viotape_TapeErr
, EIO
, "Tape error" },
146 { viotape_AllocTimedOut
, EBUSY
, "Allocate timed out" },
147 { viotape_BOTEnc
, EIO
, "Beginning of tape encountered" },
148 { viotape_BlankTape
, EIO
, "Blank tape" },
149 { viotape_BufferEmpty
, EIO
, "Buffer empty" },
150 { viotape_CleanCartFound
, ENOMEDIUM
, "Cleaning cartridge found" },
151 { viotape_CmdNotAllowed
, EIO
, "Command not allowed" },
152 { viotape_CmdNotSupported
, EIO
, "Command not supported" },
153 { viotape_DataCheck
, EIO
, "Data check" },
154 { viotape_DecompressErr
, EIO
, "Decompression error" },
155 { viotape_DeviceTimeout
, EBUSY
, "Device timeout" },
156 { viotape_DeviceUnavail
, EIO
, "Device unavailable" },
157 { viotape_DeviceBusy
, EBUSY
, "Device busy" },
158 { viotape_EndOfMedia
, ENOSPC
, "End of media" },
159 { viotape_EndOfTape
, ENOSPC
, "End of tape" },
160 { viotape_EquipCheck
, EIO
, "Equipment check" },
161 { viotape_InsufficientRs
, EOVERFLOW
, "Insufficient tape resources" },
162 { viotape_InvalidLogBlk
, EIO
, "Invalid logical block location" },
163 { viotape_LengthError
, EOVERFLOW
, "Length error" },
164 { viotape_LibDoorOpen
, EBUSY
, "Door open" },
165 { viotape_LoadFailure
, ENOMEDIUM
, "Load failure" },
166 { viotape_NotCapable
, EIO
, "Not capable" },
167 { viotape_NotOperational
, EIO
, "Not operational" },
168 { viotape_NotReady
, EIO
, "Not ready" },
169 { viotape_OpCancelled
, EIO
, "Operation cancelled" },
170 { viotape_PhyLinkErr
, EIO
, "Physical link error" },
171 { viotape_RdyNotBOT
, EIO
, "Ready but not beginning of tape" },
172 { viotape_TapeMark
, EIO
, "Tape mark" },
173 { viotape_WriteProt
, EROFS
, "Write protection error" },
177 /* Maximum number of tapes we support */
178 #define VIOTAPE_MAX_TAPE HVMAXARCHITECTEDVIRTUALTAPES
179 #define MAX_PARTITIONS 4
181 /* defines for current tape state */
183 #define VIOT_READING 1
184 #define VIOT_WRITING 2
186 /* Our info on the tapes */
188 const char *rsrcname
;
191 } viotape_unitinfo
[VIOTAPE_MAX_TAPE
];
193 static struct mtget viomtget
[VIOTAPE_MAX_TAPE
];
195 static struct class *tape_class
;
197 static struct device
*tape_device
[VIOTAPE_MAX_TAPE
];
200 * maintain the current state of each tape (and partition)
201 * so that we know when to write EOF marks.
204 unsigned char cur_part
;
205 unsigned char part_stat_rwi
[MAX_PARTITIONS
];
206 } state
[VIOTAPE_MAX_TAPE
];
208 /* We single-thread */
209 static struct semaphore reqSem
;
212 * When we send a request, we use this struct to get the response back
213 * from the interrupt handler
221 struct completion com
;
223 struct op_struct
*next
;
226 static spinlock_t op_struct_list_lock
;
227 static struct op_struct
*op_struct_list
;
229 /* forward declaration to resolve interdependence */
230 static int chg_state(int index
, unsigned char new_state
, struct file
*file
);
233 static int proc_viotape_show(struct seq_file
*m
, void *v
)
237 seq_printf(m
, "viotape driver version " VIOTAPE_VERSION
"\n");
238 for (i
= 0; i
< viotape_numdev
; i
++) {
239 seq_printf(m
, "viotape device %d is iSeries resource %10.10s"
240 "type %4.4s, model %3.3s\n",
241 i
, viotape_unitinfo
[i
].rsrcname
,
242 viotape_unitinfo
[i
].type
,
243 viotape_unitinfo
[i
].model
);
248 static int proc_viotape_open(struct inode
*inode
, struct file
*file
)
250 return single_open(file
, proc_viotape_show
, NULL
);
253 static const struct file_operations proc_viotape_operations
= {
254 .owner
= THIS_MODULE
,
255 .open
= proc_viotape_open
,
258 .release
= single_release
,
261 /* Decode the device minor number into its parts */
262 void get_dev_info(struct inode
*ino
, struct viot_devinfo_struct
*devi
)
264 devi
->devno
= iminor(ino
) & 0x1F;
265 devi
->mode
= (iminor(ino
) & 0x60) >> 5;
266 /* if bit is set in the minor, do _not_ rewind automatically */
267 devi
->rewind
= (iminor(ino
) & 0x80) == 0;
270 /* This is called only from the exit and init paths, so no need for locking */
271 static void clear_op_struct_pool(void)
273 while (op_struct_list
) {
274 struct op_struct
*toFree
= op_struct_list
;
275 op_struct_list
= op_struct_list
->next
;
280 /* Likewise, this is only called from the init path */
281 static int add_op_structs(int structs
)
285 for (i
= 0; i
< structs
; ++i
) {
286 struct op_struct
*new_struct
=
287 kmalloc(sizeof(*new_struct
), GFP_KERNEL
);
289 clear_op_struct_pool();
292 new_struct
->next
= op_struct_list
;
293 op_struct_list
= new_struct
;
298 /* Allocate an op structure from our pool */
299 static struct op_struct
*get_op_struct(void)
301 struct op_struct
*retval
;
304 spin_lock_irqsave(&op_struct_list_lock
, flags
);
305 retval
= op_struct_list
;
307 op_struct_list
= retval
->next
;
308 spin_unlock_irqrestore(&op_struct_list_lock
, flags
);
310 memset(retval
, 0, sizeof(*retval
));
311 init_completion(&retval
->com
);
317 /* Return an op structure to our pool */
318 static void free_op_struct(struct op_struct
*op_struct
)
322 spin_lock_irqsave(&op_struct_list_lock
, flags
);
323 op_struct
->next
= op_struct_list
;
324 op_struct_list
= op_struct
;
325 spin_unlock_irqrestore(&op_struct_list_lock
, flags
);
328 /* Map our tape return codes to errno values */
329 int tape_rc_to_errno(int tape_rc
, char *operation
, int tapeno
)
331 const struct vio_error_entry
*err
;
336 err
= vio_lookup_rc(viotape_err_table
, tape_rc
);
337 printk(VIOTAPE_KERN_WARN
"error(%s) 0x%04x on Device %d (%-10s): %s\n",
338 operation
, tape_rc
, tapeno
,
339 viotape_unitinfo
[tapeno
].rsrcname
, err
->msg
);
344 static ssize_t
viotap_write(struct file
*file
, const char *buf
,
345 size_t count
, loff_t
* ppos
)
348 unsigned short flags
= file
->f_flags
;
349 int noblock
= ((flags
& O_NONBLOCK
) != 0);
351 struct viot_devinfo_struct devi
;
352 struct op_struct
*op
= get_op_struct();
357 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
360 * We need to make sure we can send a request. We use
361 * a semaphore to keep track of # requests in use. If
362 * we are non-blocking, make sure we don't block on the
366 if (down_trylock(&reqSem
)) {
373 /* Allocate a DMA buffer */
374 op
->dev
= tape_device
[devi
.devno
];
375 op
->buffer
= dma_alloc_coherent(op
->dev
, count
, &op
->dmaaddr
,
378 if (op
->buffer
== NULL
) {
379 printk(VIOTAPE_KERN_WARN
380 "error allocating dma buffer for len %ld\n",
386 /* Copy the data into the buffer */
387 if (copy_from_user(op
->buffer
, buf
, count
)) {
388 printk(VIOTAPE_KERN_WARN
"tape: error on copy from user\n");
393 op
->non_blocking
= noblock
;
394 init_completion(&op
->com
);
397 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
398 HvLpEvent_Type_VirtualIo
,
399 viomajorsubtype_tape
| viotapewrite
,
400 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
401 viopath_sourceinst(viopath_hostLp
),
402 viopath_targetinst(viopath_hostLp
),
403 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
404 ((u64
)devi
.devno
<< 48) | op
->dmaaddr
, count
, 0, 0);
405 if (hvrc
!= HvLpEvent_Rc_Good
) {
406 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
415 wait_for_completion(&op
->com
);
418 ret
= tape_rc_to_errno(op
->rc
, "write", devi
.devno
);
420 chg_state(devi
.devno
, VIOT_WRITING
, file
);
425 dma_free_coherent(op
->dev
, count
, op
->buffer
, op
->dmaaddr
);
434 static ssize_t
viotap_read(struct file
*file
, char *buf
, size_t count
,
438 unsigned short flags
= file
->f_flags
;
439 struct op_struct
*op
= get_op_struct();
440 int noblock
= ((flags
& O_NONBLOCK
) != 0);
442 struct viot_devinfo_struct devi
;
447 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
450 * We need to make sure we can send a request. We use
451 * a semaphore to keep track of # requests in use. If
452 * we are non-blocking, make sure we don't block on the
456 if (down_trylock(&reqSem
)) {
463 chg_state(devi
.devno
, VIOT_READING
, file
);
465 /* Allocate a DMA buffer */
466 op
->dev
= tape_device
[devi
.devno
];
467 op
->buffer
= dma_alloc_coherent(op
->dev
, count
, &op
->dmaaddr
,
469 if (op
->buffer
== NULL
) {
475 init_completion(&op
->com
);
477 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
478 HvLpEvent_Type_VirtualIo
,
479 viomajorsubtype_tape
| viotaperead
,
480 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
481 viopath_sourceinst(viopath_hostLp
),
482 viopath_targetinst(viopath_hostLp
),
483 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
484 ((u64
)devi
.devno
<< 48) | op
->dmaaddr
, count
, 0, 0);
485 if (hvrc
!= HvLpEvent_Rc_Good
) {
486 printk(VIOTAPE_KERN_WARN
"tape hv error on op %d\n",
492 wait_for_completion(&op
->com
);
495 ret
= tape_rc_to_errno(op
->rc
, "read", devi
.devno
);
498 if (ret
&& copy_to_user(buf
, op
->buffer
, ret
)) {
499 printk(VIOTAPE_KERN_WARN
"error on copy_to_user\n");
505 dma_free_coherent(op
->dev
, count
, op
->buffer
, op
->dmaaddr
);
514 static int viotap_ioctl(struct inode
*inode
, struct file
*file
,
515 unsigned int cmd
, unsigned long arg
)
519 struct viot_devinfo_struct devi
;
522 struct op_struct
*op
= get_op_struct();
527 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
537 * inode is null if and only if we (the kernel)
541 memcpy(&mtc
, (void *) arg
, sizeof(struct mtop
));
542 else if (copy_from_user((char *)&mtc
, (char *)arg
,
543 sizeof(struct mtop
)))
549 myOp
= VIOTAPOP_RESET
;
564 myOp
= VIOTAPOP_WEOF
;
576 myOp
= VIOTAPOP_ERASE
;
579 myOp
= VIOTAPOP_SETBLK
;
582 myOp
= VIOTAPOP_SETDENSITY
;
585 myOp
= VIOTAPOP_GETPOS
;
588 myOp
= VIOTAPOP_SETPOS
;
591 myOp
= VIOTAPOP_SETPART
;
594 myOp
= VIOTAPOP_UNLOAD
;
597 printk(VIOTAPE_KERN_WARN
"MTIOCTOP called "
598 "with invalid op 0x%x\n", mtc
.mt_op
);
603 * if we moved the head, we are no longer
614 chg_state(devi
.devno
, VIOT_IDLE
, file
);
617 init_completion(&op
->com
);
618 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
619 HvLpEvent_Type_VirtualIo
,
620 viomajorsubtype_tape
| viotapeop
,
621 HvLpEvent_AckInd_DoAck
,
622 HvLpEvent_AckType_ImmediateAck
,
623 viopath_sourceinst(viopath_hostLp
),
624 viopath_targetinst(viopath_hostLp
),
625 (u64
)(unsigned long)op
,
627 ((u64
)devi
.devno
<< 48), 0,
628 (((u64
)myOp
) << 32) | mtc
.mt_count
, 0);
629 if (hvrc
!= HvLpEvent_Rc_Good
) {
630 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
634 wait_for_completion(&op
->com
);
635 ret
= tape_rc_to_errno(op
->rc
, "tape operation", devi
.devno
);
640 init_completion(&op
->com
);
641 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
642 HvLpEvent_Type_VirtualIo
,
643 viomajorsubtype_tape
| viotapegetstatus
,
644 HvLpEvent_AckInd_DoAck
,
645 HvLpEvent_AckType_ImmediateAck
,
646 viopath_sourceinst(viopath_hostLp
),
647 viopath_targetinst(viopath_hostLp
),
648 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
649 ((u64
)devi
.devno
<< 48), 0, 0, 0);
650 if (hvrc
!= HvLpEvent_Rc_Good
) {
651 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
655 wait_for_completion(&op
->com
);
657 /* Operation is complete - grab the error code */
658 ret
= tape_rc_to_errno(op
->rc
, "get status", devi
.devno
);
662 if ((ret
== 0) && copy_to_user((void *)arg
,
663 &viomtget
[devi
.devno
],
664 sizeof(viomtget
[0])))
668 printk(VIOTAPE_KERN_WARN
"Got an (unsupported) MTIOCPOS\n");
671 printk(VIOTAPE_KERN_WARN
"got an unsupported ioctl 0x%0x\n",
682 static long viotap_unlocked_ioctl(struct file
*file
,
683 unsigned int cmd
, unsigned long arg
)
688 rc
= viotap_ioctl(file
->f_path
.dentry
->d_inode
, file
, cmd
, arg
);
693 static int viotap_open(struct inode
*inode
, struct file
*file
)
696 struct viot_devinfo_struct devi
;
698 struct op_struct
*op
= get_op_struct();
704 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
706 /* Note: We currently only support one mode! */
707 if ((devi
.devno
>= viotape_numdev
) || (devi
.mode
)) {
712 init_completion(&op
->com
);
714 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
715 HvLpEvent_Type_VirtualIo
,
716 viomajorsubtype_tape
| viotapeopen
,
717 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
718 viopath_sourceinst(viopath_hostLp
),
719 viopath_targetinst(viopath_hostLp
),
720 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
721 ((u64
)devi
.devno
<< 48), 0, 0, 0);
723 printk(VIOTAPE_KERN_WARN
"bad rc on signalLpEvent %d\n",
729 wait_for_completion(&op
->com
);
730 ret
= tape_rc_to_errno(op
->rc
, "open", devi
.devno
);
739 static int viotap_release(struct inode
*inode
, struct file
*file
)
742 struct viot_devinfo_struct devi
;
744 struct op_struct
*op
= get_op_struct();
748 init_completion(&op
->com
);
750 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
752 if (devi
.devno
>= viotape_numdev
) {
757 chg_state(devi
.devno
, VIOT_IDLE
, file
);
760 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
761 HvLpEvent_Type_VirtualIo
,
762 viomajorsubtype_tape
| viotapeop
,
763 HvLpEvent_AckInd_DoAck
,
764 HvLpEvent_AckType_ImmediateAck
,
765 viopath_sourceinst(viopath_hostLp
),
766 viopath_targetinst(viopath_hostLp
),
767 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
768 ((u64
)devi
.devno
<< 48), 0,
769 ((u64
)VIOTAPOP_REW
) << 32, 0);
770 wait_for_completion(&op
->com
);
772 tape_rc_to_errno(op
->rc
, "rewind", devi
.devno
);
775 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
776 HvLpEvent_Type_VirtualIo
,
777 viomajorsubtype_tape
| viotapeclose
,
778 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
779 viopath_sourceinst(viopath_hostLp
),
780 viopath_targetinst(viopath_hostLp
),
781 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
782 ((u64
)devi
.devno
<< 48), 0, 0, 0);
784 printk(VIOTAPE_KERN_WARN
"bad rc on signalLpEvent %d\n",
790 wait_for_completion(&op
->com
);
793 printk(VIOTAPE_KERN_WARN
"close failed\n");
800 const struct file_operations viotap_fops
= {
801 .owner
= THIS_MODULE
,
803 .write
= viotap_write
,
804 .unlocked_ioctl
= viotap_unlocked_ioctl
,
806 .release
= viotap_release
,
809 /* Handle interrupt events for tape */
810 static void vioHandleTapeEvent(struct HvLpEvent
*event
)
813 struct op_struct
*op
;
814 struct viotapelpevent
*tevent
= (struct viotapelpevent
*)event
;
817 /* Notification that a partition went away! */
818 if (!viopath_isactive(viopath_hostLp
)) {
824 tapeminor
= event
->xSubtype
& VIOMINOR_SUBTYPE_MASK
;
825 op
= (struct op_struct
*)event
->xCorrelationToken
;
829 op
->rc
= tevent
->sub_type_result
;
833 op
->rc
= tevent
->sub_type_result
;
834 op
->count
= tevent
->len
;
838 if (op
->non_blocking
) {
839 dma_free_coherent(op
->dev
, op
->count
,
840 op
->buffer
, op
->dmaaddr
);
844 op
->rc
= tevent
->sub_type_result
;
845 op
->count
= tevent
->len
;
852 case viotapegetstatus
:
854 op
->count
= tevent
->u
.op
.count
;
855 op
->rc
= tevent
->sub_type_result
;
856 if (!op
->non_blocking
)
861 printk(VIOTAPE_KERN_WARN
"weird ack\n");
865 static int viotape_probe(struct vio_dev
*vdev
, const struct vio_device_id
*id
)
867 int i
= vdev
->unit_address
;
869 struct device_node
*node
= vdev
->dev
.of_node
;
871 if (i
>= VIOTAPE_MAX_TAPE
)
876 if (i
>= viotape_numdev
)
877 viotape_numdev
= i
+ 1;
879 tape_device
[i
] = &vdev
->dev
;
880 viotape_unitinfo
[i
].rsrcname
= of_get_property(node
,
881 "linux,vio_rsrcname", NULL
);
882 viotape_unitinfo
[i
].type
= of_get_property(node
, "linux,vio_type",
884 viotape_unitinfo
[i
].model
= of_get_property(node
, "linux,vio_model",
887 state
[i
].cur_part
= 0;
888 for (j
= 0; j
< MAX_PARTITIONS
; ++j
)
889 state
[i
].part_stat_rwi
[j
] = VIOT_IDLE
;
890 device_create(tape_class
, NULL
, MKDEV(VIOTAPE_MAJOR
, i
), NULL
,
892 device_create(tape_class
, NULL
, MKDEV(VIOTAPE_MAJOR
, i
| 0x80), NULL
,
894 printk(VIOTAPE_KERN_INFO
"tape iseries/vt%d is iSeries "
895 "resource %10.10s type %4.4s, model %3.3s\n",
896 i
, viotape_unitinfo
[i
].rsrcname
,
897 viotape_unitinfo
[i
].type
, viotape_unitinfo
[i
].model
);
901 static int viotape_remove(struct vio_dev
*vdev
)
903 int i
= vdev
->unit_address
;
905 device_destroy(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
| 0x80));
906 device_destroy(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
));
911 * viotape_device_table: Used by vio.c to match devices that we
914 static struct vio_device_id viotape_device_table
[] __devinitdata
= {
915 { "byte", "IBM,iSeries-viotape" },
918 MODULE_DEVICE_TABLE(vio
, viotape_device_table
);
920 static struct vio_driver viotape_driver
= {
921 .id_table
= viotape_device_table
,
922 .probe
= viotape_probe
,
923 .remove
= viotape_remove
,
926 .owner
= THIS_MODULE
,
931 int __init
viotap_init(void)
935 if (!firmware_has_feature(FW_FEATURE_ISERIES
))
938 op_struct_list
= NULL
;
939 if ((ret
= add_op_structs(VIOTAPE_MAXREQ
)) < 0) {
940 printk(VIOTAPE_KERN_WARN
"couldn't allocate op structs\n");
943 spin_lock_init(&op_struct_list_lock
);
945 sema_init(&reqSem
, VIOTAPE_MAXREQ
);
947 if (viopath_hostLp
== HvLpIndexInvalid
) {
949 if (viopath_hostLp
== HvLpIndexInvalid
) {
955 ret
= viopath_open(viopath_hostLp
, viomajorsubtype_tape
,
958 printk(VIOTAPE_KERN_WARN
959 "error on viopath_open to hostlp %d\n", ret
);
964 printk(VIOTAPE_KERN_INFO
"vers " VIOTAPE_VERSION
965 ", hosting partition %d\n", viopath_hostLp
);
967 vio_setHandler(viomajorsubtype_tape
, vioHandleTapeEvent
);
969 ret
= register_chrdev(VIOTAPE_MAJOR
, "viotape", &viotap_fops
);
971 printk(VIOTAPE_KERN_WARN
"Error registering viotape device\n");
975 tape_class
= class_create(THIS_MODULE
, "tape");
976 if (IS_ERR(tape_class
)) {
977 printk(VIOTAPE_KERN_WARN
"Unable to allocat class\n");
978 ret
= PTR_ERR(tape_class
);
982 ret
= vio_register_driver(&viotape_driver
);
986 proc_create("iSeries/viotape", S_IFREG
|S_IRUGO
, NULL
,
987 &proc_viotape_operations
);
992 class_destroy(tape_class
);
994 unregister_chrdev(VIOTAPE_MAJOR
, "viotape");
996 vio_clearHandler(viomajorsubtype_tape
);
997 viopath_close(viopath_hostLp
, viomajorsubtype_tape
, VIOTAPE_MAXREQ
+ 2);
999 clear_op_struct_pool();
1003 /* Give a new state to the tape object */
1004 static int chg_state(int index
, unsigned char new_state
, struct file
*file
)
1006 unsigned char *cur_state
=
1007 &state
[index
].part_stat_rwi
[state
[index
].cur_part
];
1010 /* if the same state, don't bother */
1011 if (*cur_state
== new_state
)
1014 /* write an EOF if changing from writing to some other state */
1015 if (*cur_state
== VIOT_WRITING
) {
1016 struct mtop write_eof
= { MTWEOF
, 1 };
1018 rc
= viotap_ioctl(NULL
, file
, MTIOCTOP
,
1019 (unsigned long)&write_eof
);
1021 *cur_state
= new_state
;
1026 static void __exit
viotap_exit(void)
1028 remove_proc_entry("iSeries/viotape", NULL
);
1029 vio_unregister_driver(&viotape_driver
);
1030 class_destroy(tape_class
);
1031 unregister_chrdev(VIOTAPE_MAJOR
, "viotape");
1032 viopath_close(viopath_hostLp
, viomajorsubtype_tape
, VIOTAPE_MAXREQ
+ 2);
1033 vio_clearHandler(viomajorsubtype_tape
);
1034 clear_op_struct_pool();
1037 MODULE_LICENSE("GPL");
1038 module_init(viotap_init
);
1039 module_exit(viotap_exit
);