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>
57 #include <asm/iSeries/vio.h>
58 #include <asm/iSeries/HvLpEvent.h>
59 #include <asm/iSeries/HvCallEvent.h>
60 #include <asm/iSeries/HvLpConfig.h>
62 #define VIOTAPE_VERSION "1.2"
63 #define VIOTAPE_MAXREQ 1
65 #define VIOTAPE_KERN_WARN KERN_WARNING "viotape: "
66 #define VIOTAPE_KERN_INFO KERN_INFO "viotape: "
68 static int viotape_numdev
;
71 * The minor number follows the conventions of the SCSI tape drives. The
72 * rewind and mode are encoded in the minor #. We use this struct to break
75 struct viot_devinfo_struct
{
81 #define VIOTAPOP_RESET 0
82 #define VIOTAPOP_FSF 1
83 #define VIOTAPOP_BSF 2
84 #define VIOTAPOP_FSR 3
85 #define VIOTAPOP_BSR 4
86 #define VIOTAPOP_WEOF 5
87 #define VIOTAPOP_REW 6
88 #define VIOTAPOP_NOP 7
89 #define VIOTAPOP_EOM 8
90 #define VIOTAPOP_ERASE 9
91 #define VIOTAPOP_SETBLK 10
92 #define VIOTAPOP_SETDENSITY 11
93 #define VIOTAPOP_SETPOS 12
94 #define VIOTAPOP_GETPOS 13
95 #define VIOTAPOP_SETPART 14
96 #define VIOTAPOP_UNLOAD 15
98 struct viotapelpevent
{
99 struct HvLpEvent event
;
127 enum viotapesubtype
{
128 viotapeopen
= 0x0001,
129 viotapeclose
= 0x0002,
130 viotaperead
= 0x0003,
131 viotapewrite
= 0x0004,
132 viotapegetinfo
= 0x0005,
134 viotapegetpos
= 0x0007,
135 viotapesetpos
= 0x0008,
136 viotapegetstatus
= 0x0009
140 viotape_InvalidRange
= 0x0601,
141 viotape_InvalidToken
= 0x0602,
142 viotape_DMAError
= 0x0603,
143 viotape_UseError
= 0x0604,
144 viotape_ReleaseError
= 0x0605,
145 viotape_InvalidTape
= 0x0606,
146 viotape_InvalidOp
= 0x0607,
147 viotape_TapeErr
= 0x0608,
149 viotape_AllocTimedOut
= 0x0640,
150 viotape_BOTEnc
= 0x0641,
151 viotape_BlankTape
= 0x0642,
152 viotape_BufferEmpty
= 0x0643,
153 viotape_CleanCartFound
= 0x0644,
154 viotape_CmdNotAllowed
= 0x0645,
155 viotape_CmdNotSupported
= 0x0646,
156 viotape_DataCheck
= 0x0647,
157 viotape_DecompressErr
= 0x0648,
158 viotape_DeviceTimeout
= 0x0649,
159 viotape_DeviceUnavail
= 0x064a,
160 viotape_DeviceBusy
= 0x064b,
161 viotape_EndOfMedia
= 0x064c,
162 viotape_EndOfTape
= 0x064d,
163 viotape_EquipCheck
= 0x064e,
164 viotape_InsufficientRs
= 0x064f,
165 viotape_InvalidLogBlk
= 0x0650,
166 viotape_LengthError
= 0x0651,
167 viotape_LibDoorOpen
= 0x0652,
168 viotape_LoadFailure
= 0x0653,
169 viotape_NotCapable
= 0x0654,
170 viotape_NotOperational
= 0x0655,
171 viotape_NotReady
= 0x0656,
172 viotape_OpCancelled
= 0x0657,
173 viotape_PhyLinkErr
= 0x0658,
174 viotape_RdyNotBOT
= 0x0659,
175 viotape_TapeMark
= 0x065a,
176 viotape_WriteProt
= 0x065b
179 static const struct vio_error_entry viotape_err_table
[] = {
180 { viotape_InvalidRange
, EIO
, "Internal error" },
181 { viotape_InvalidToken
, EIO
, "Internal error" },
182 { viotape_DMAError
, EIO
, "DMA error" },
183 { viotape_UseError
, EIO
, "Internal error" },
184 { viotape_ReleaseError
, EIO
, "Internal error" },
185 { viotape_InvalidTape
, EIO
, "Invalid tape device" },
186 { viotape_InvalidOp
, EIO
, "Invalid operation" },
187 { viotape_TapeErr
, EIO
, "Tape error" },
188 { viotape_AllocTimedOut
, EBUSY
, "Allocate timed out" },
189 { viotape_BOTEnc
, EIO
, "Beginning of tape encountered" },
190 { viotape_BlankTape
, EIO
, "Blank tape" },
191 { viotape_BufferEmpty
, EIO
, "Buffer empty" },
192 { viotape_CleanCartFound
, ENOMEDIUM
, "Cleaning cartridge found" },
193 { viotape_CmdNotAllowed
, EIO
, "Command not allowed" },
194 { viotape_CmdNotSupported
, EIO
, "Command not supported" },
195 { viotape_DataCheck
, EIO
, "Data check" },
196 { viotape_DecompressErr
, EIO
, "Decompression error" },
197 { viotape_DeviceTimeout
, EBUSY
, "Device timeout" },
198 { viotape_DeviceUnavail
, EIO
, "Device unavailable" },
199 { viotape_DeviceBusy
, EBUSY
, "Device busy" },
200 { viotape_EndOfMedia
, ENOSPC
, "End of media" },
201 { viotape_EndOfTape
, ENOSPC
, "End of tape" },
202 { viotape_EquipCheck
, EIO
, "Equipment check" },
203 { viotape_InsufficientRs
, EOVERFLOW
, "Insufficient tape resources" },
204 { viotape_InvalidLogBlk
, EIO
, "Invalid logical block location" },
205 { viotape_LengthError
, EOVERFLOW
, "Length error" },
206 { viotape_LibDoorOpen
, EBUSY
, "Door open" },
207 { viotape_LoadFailure
, ENOMEDIUM
, "Load failure" },
208 { viotape_NotCapable
, EIO
, "Not capable" },
209 { viotape_NotOperational
, EIO
, "Not operational" },
210 { viotape_NotReady
, EIO
, "Not ready" },
211 { viotape_OpCancelled
, EIO
, "Operation cancelled" },
212 { viotape_PhyLinkErr
, EIO
, "Physical link error" },
213 { viotape_RdyNotBOT
, EIO
, "Ready but not beginning of tape" },
214 { viotape_TapeMark
, EIO
, "Tape mark" },
215 { viotape_WriteProt
, EROFS
, "Write protection error" },
219 /* Maximum number of tapes we support */
220 #define VIOTAPE_MAX_TAPE HVMAXARCHITECTEDVIRTUALTAPES
221 #define MAX_PARTITIONS 4
223 /* defines for current tape state */
225 #define VIOT_READING 1
226 #define VIOT_WRITING 2
228 /* Our info on the tapes */
235 static struct tape_descr
*viotape_unitinfo
;
236 static dma_addr_t viotape_unitinfo_token
;
238 static struct mtget viomtget
[VIOTAPE_MAX_TAPE
];
240 static struct class *tape_class
;
242 static struct device
*tape_device
[VIOTAPE_MAX_TAPE
];
245 * maintain the current state of each tape (and partition)
246 * so that we know when to write EOF marks.
249 unsigned char cur_part
;
251 unsigned char part_stat_rwi
[MAX_PARTITIONS
];
252 } state
[VIOTAPE_MAX_TAPE
];
254 /* We single-thread */
255 static struct semaphore reqSem
;
258 * When we send a request, we use this struct to get the response back
259 * from the interrupt handler
267 struct completion com
;
269 struct op_struct
*next
;
272 static spinlock_t op_struct_list_lock
;
273 static struct op_struct
*op_struct_list
;
275 /* forward declaration to resolve interdependence */
276 static int chg_state(int index
, unsigned char new_state
, struct file
*file
);
279 static int proc_viotape_show(struct seq_file
*m
, void *v
)
283 seq_printf(m
, "viotape driver version " VIOTAPE_VERSION
"\n");
284 for (i
= 0; i
< viotape_numdev
; i
++) {
285 seq_printf(m
, "viotape device %d is iSeries resource %10.10s"
286 "type %4.4s, model %3.3s\n",
287 i
, viotape_unitinfo
[i
].rsrcname
,
288 viotape_unitinfo
[i
].type
,
289 viotape_unitinfo
[i
].model
);
294 static int proc_viotape_open(struct inode
*inode
, struct file
*file
)
296 return single_open(file
, proc_viotape_show
, NULL
);
299 static struct file_operations proc_viotape_operations
= {
300 .open
= proc_viotape_open
,
303 .release
= single_release
,
306 /* Decode the device minor number into its parts */
307 void get_dev_info(struct inode
*ino
, struct viot_devinfo_struct
*devi
)
309 devi
->devno
= iminor(ino
) & 0x1F;
310 devi
->mode
= (iminor(ino
) & 0x60) >> 5;
311 /* if bit is set in the minor, do _not_ rewind automatically */
312 devi
->rewind
= (iminor(ino
) & 0x80) == 0;
315 /* This is called only from the exit and init paths, so no need for locking */
316 static void clear_op_struct_pool(void)
318 while (op_struct_list
) {
319 struct op_struct
*toFree
= op_struct_list
;
320 op_struct_list
= op_struct_list
->next
;
325 /* Likewise, this is only called from the init path */
326 static int add_op_structs(int structs
)
330 for (i
= 0; i
< structs
; ++i
) {
331 struct op_struct
*new_struct
=
332 kmalloc(sizeof(*new_struct
), GFP_KERNEL
);
334 clear_op_struct_pool();
337 new_struct
->next
= op_struct_list
;
338 op_struct_list
= new_struct
;
343 /* Allocate an op structure from our pool */
344 static struct op_struct
*get_op_struct(void)
346 struct op_struct
*retval
;
349 spin_lock_irqsave(&op_struct_list_lock
, flags
);
350 retval
= op_struct_list
;
352 op_struct_list
= retval
->next
;
353 spin_unlock_irqrestore(&op_struct_list_lock
, flags
);
355 memset(retval
, 0, sizeof(*retval
));
356 init_completion(&retval
->com
);
362 /* Return an op structure to our pool */
363 static void free_op_struct(struct op_struct
*op_struct
)
367 spin_lock_irqsave(&op_struct_list_lock
, flags
);
368 op_struct
->next
= op_struct_list
;
369 op_struct_list
= op_struct
;
370 spin_unlock_irqrestore(&op_struct_list_lock
, flags
);
373 /* Map our tape return codes to errno values */
374 int tape_rc_to_errno(int tape_rc
, char *operation
, int tapeno
)
376 const struct vio_error_entry
*err
;
381 err
= vio_lookup_rc(viotape_err_table
, tape_rc
);
382 printk(VIOTAPE_KERN_WARN
"error(%s) 0x%04x on Device %d (%-10s): %s\n",
383 operation
, tape_rc
, tapeno
,
384 viotape_unitinfo
[tapeno
].rsrcname
, err
->msg
);
388 /* Get info on all tapes from OS/400 */
389 static int get_viotape_info(void)
393 size_t len
= sizeof(*viotape_unitinfo
) * VIOTAPE_MAX_TAPE
;
394 struct op_struct
*op
= get_op_struct();
399 viotape_unitinfo
= dma_alloc_coherent(iSeries_vio_dev
, len
,
400 &viotape_unitinfo_token
, GFP_ATOMIC
);
401 if (viotape_unitinfo
== NULL
) {
406 memset(viotape_unitinfo
, 0, len
);
408 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
409 HvLpEvent_Type_VirtualIo
,
410 viomajorsubtype_tape
| viotapegetinfo
,
411 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
412 viopath_sourceinst(viopath_hostLp
),
413 viopath_targetinst(viopath_hostLp
),
414 (u64
) (unsigned long) op
, VIOVERSION
<< 16,
415 viotape_unitinfo_token
, len
, 0, 0);
416 if (hvrc
!= HvLpEvent_Rc_Good
) {
417 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
423 wait_for_completion(&op
->com
);
428 ((i
< VIOTAPE_MAX_TAPE
) && (viotape_unitinfo
[i
].rsrcname
[0]));
436 static ssize_t
viotap_write(struct file
*file
, const char *buf
,
437 size_t count
, loff_t
* ppos
)
440 unsigned short flags
= file
->f_flags
;
441 int noblock
= ((flags
& O_NONBLOCK
) != 0);
443 struct viot_devinfo_struct devi
;
444 struct op_struct
*op
= get_op_struct();
449 get_dev_info(file
->f_dentry
->d_inode
, &devi
);
452 * We need to make sure we can send a request. We use
453 * a semaphore to keep track of # requests in use. If
454 * we are non-blocking, make sure we don't block on the
458 if (down_trylock(&reqSem
)) {
465 /* Allocate a DMA buffer */
466 op
->dev
= tape_device
[devi
.devno
];
467 op
->buffer
= dma_alloc_coherent(op
->dev
, count
, &op
->dmaaddr
,
470 if (op
->buffer
== NULL
) {
471 printk(VIOTAPE_KERN_WARN
472 "error allocating dma buffer for len %ld\n",
478 /* Copy the data into the buffer */
479 if (copy_from_user(op
->buffer
, buf
, count
)) {
480 printk(VIOTAPE_KERN_WARN
"tape: error on copy from user\n");
485 op
->non_blocking
= noblock
;
486 init_completion(&op
->com
);
489 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
490 HvLpEvent_Type_VirtualIo
,
491 viomajorsubtype_tape
| viotapewrite
,
492 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
493 viopath_sourceinst(viopath_hostLp
),
494 viopath_targetinst(viopath_hostLp
),
495 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
496 ((u64
)devi
.devno
<< 48) | op
->dmaaddr
, count
, 0, 0);
497 if (hvrc
!= HvLpEvent_Rc_Good
) {
498 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
507 wait_for_completion(&op
->com
);
510 ret
= tape_rc_to_errno(op
->rc
, "write", devi
.devno
);
512 chg_state(devi
.devno
, VIOT_WRITING
, file
);
517 dma_free_coherent(op
->dev
, count
, op
->buffer
, op
->dmaaddr
);
526 static ssize_t
viotap_read(struct file
*file
, char *buf
, size_t count
,
530 unsigned short flags
= file
->f_flags
;
531 struct op_struct
*op
= get_op_struct();
532 int noblock
= ((flags
& O_NONBLOCK
) != 0);
534 struct viot_devinfo_struct devi
;
539 get_dev_info(file
->f_dentry
->d_inode
, &devi
);
542 * We need to make sure we can send a request. We use
543 * a semaphore to keep track of # requests in use. If
544 * we are non-blocking, make sure we don't block on the
548 if (down_trylock(&reqSem
)) {
555 chg_state(devi
.devno
, VIOT_READING
, file
);
557 /* Allocate a DMA buffer */
558 op
->dev
= tape_device
[devi
.devno
];
559 op
->buffer
= dma_alloc_coherent(op
->dev
, count
, &op
->dmaaddr
,
561 if (op
->buffer
== NULL
) {
567 init_completion(&op
->com
);
569 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
570 HvLpEvent_Type_VirtualIo
,
571 viomajorsubtype_tape
| viotaperead
,
572 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
573 viopath_sourceinst(viopath_hostLp
),
574 viopath_targetinst(viopath_hostLp
),
575 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
576 ((u64
)devi
.devno
<< 48) | op
->dmaaddr
, count
, 0, 0);
577 if (hvrc
!= HvLpEvent_Rc_Good
) {
578 printk(VIOTAPE_KERN_WARN
"tape hv error on op %d\n",
584 wait_for_completion(&op
->com
);
587 ret
= tape_rc_to_errno(op
->rc
, "read", devi
.devno
);
590 if (ret
&& copy_to_user(buf
, op
->buffer
, ret
)) {
591 printk(VIOTAPE_KERN_WARN
"error on copy_to_user\n");
597 dma_free_coherent(op
->dev
, count
, op
->buffer
, op
->dmaaddr
);
606 static int viotap_ioctl(struct inode
*inode
, struct file
*file
,
607 unsigned int cmd
, unsigned long arg
)
611 struct viot_devinfo_struct devi
;
614 struct op_struct
*op
= get_op_struct();
619 get_dev_info(file
->f_dentry
->d_inode
, &devi
);
629 * inode is null if and only if we (the kernel)
633 memcpy(&mtc
, (void *) arg
, sizeof(struct mtop
));
634 else if (copy_from_user((char *)&mtc
, (char *)arg
,
635 sizeof(struct mtop
)))
641 myOp
= VIOTAPOP_RESET
;
656 myOp
= VIOTAPOP_WEOF
;
668 myOp
= VIOTAPOP_ERASE
;
671 myOp
= VIOTAPOP_SETBLK
;
674 myOp
= VIOTAPOP_SETDENSITY
;
677 myOp
= VIOTAPOP_GETPOS
;
680 myOp
= VIOTAPOP_SETPOS
;
683 myOp
= VIOTAPOP_SETPART
;
686 myOp
= VIOTAPOP_UNLOAD
;
689 printk(VIOTAPE_KERN_WARN
"MTIOCTOP called "
690 "with invalid op 0x%x\n", mtc
.mt_op
);
695 * if we moved the head, we are no longer
706 chg_state(devi
.devno
, VIOT_IDLE
, file
);
709 init_completion(&op
->com
);
710 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
711 HvLpEvent_Type_VirtualIo
,
712 viomajorsubtype_tape
| viotapeop
,
713 HvLpEvent_AckInd_DoAck
,
714 HvLpEvent_AckType_ImmediateAck
,
715 viopath_sourceinst(viopath_hostLp
),
716 viopath_targetinst(viopath_hostLp
),
717 (u64
)(unsigned long)op
,
719 ((u64
)devi
.devno
<< 48), 0,
720 (((u64
)myOp
) << 32) | mtc
.mt_count
, 0);
721 if (hvrc
!= HvLpEvent_Rc_Good
) {
722 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
726 wait_for_completion(&op
->com
);
727 ret
= tape_rc_to_errno(op
->rc
, "tape operation", devi
.devno
);
732 init_completion(&op
->com
);
733 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
734 HvLpEvent_Type_VirtualIo
,
735 viomajorsubtype_tape
| viotapegetstatus
,
736 HvLpEvent_AckInd_DoAck
,
737 HvLpEvent_AckType_ImmediateAck
,
738 viopath_sourceinst(viopath_hostLp
),
739 viopath_targetinst(viopath_hostLp
),
740 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
741 ((u64
)devi
.devno
<< 48), 0, 0, 0);
742 if (hvrc
!= HvLpEvent_Rc_Good
) {
743 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
747 wait_for_completion(&op
->com
);
749 /* Operation is complete - grab the error code */
750 ret
= tape_rc_to_errno(op
->rc
, "get status", devi
.devno
);
754 if ((ret
== 0) && copy_to_user((void *)arg
,
755 &viomtget
[devi
.devno
],
756 sizeof(viomtget
[0])))
760 printk(VIOTAPE_KERN_WARN
"Got an (unsupported) MTIOCPOS\n");
763 printk(VIOTAPE_KERN_WARN
"got an unsupported ioctl 0x%0x\n",
774 static int viotap_open(struct inode
*inode
, struct file
*file
)
777 struct viot_devinfo_struct devi
;
779 struct op_struct
*op
= get_op_struct();
784 get_dev_info(file
->f_dentry
->d_inode
, &devi
);
786 /* Note: We currently only support one mode! */
787 if ((devi
.devno
>= viotape_numdev
) || (devi
.mode
)) {
792 init_completion(&op
->com
);
794 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
795 HvLpEvent_Type_VirtualIo
,
796 viomajorsubtype_tape
| viotapeopen
,
797 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
798 viopath_sourceinst(viopath_hostLp
),
799 viopath_targetinst(viopath_hostLp
),
800 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
801 ((u64
)devi
.devno
<< 48), 0, 0, 0);
803 printk(VIOTAPE_KERN_WARN
"bad rc on signalLpEvent %d\n",
809 wait_for_completion(&op
->com
);
810 ret
= tape_rc_to_errno(op
->rc
, "open", devi
.devno
);
818 static int viotap_release(struct inode
*inode
, struct file
*file
)
821 struct viot_devinfo_struct devi
;
823 struct op_struct
*op
= get_op_struct();
827 init_completion(&op
->com
);
829 get_dev_info(file
->f_dentry
->d_inode
, &devi
);
831 if (devi
.devno
>= viotape_numdev
) {
836 chg_state(devi
.devno
, VIOT_IDLE
, file
);
839 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
840 HvLpEvent_Type_VirtualIo
,
841 viomajorsubtype_tape
| viotapeop
,
842 HvLpEvent_AckInd_DoAck
,
843 HvLpEvent_AckType_ImmediateAck
,
844 viopath_sourceinst(viopath_hostLp
),
845 viopath_targetinst(viopath_hostLp
),
846 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
847 ((u64
)devi
.devno
<< 48), 0,
848 ((u64
)VIOTAPOP_REW
) << 32, 0);
849 wait_for_completion(&op
->com
);
851 tape_rc_to_errno(op
->rc
, "rewind", devi
.devno
);
854 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
855 HvLpEvent_Type_VirtualIo
,
856 viomajorsubtype_tape
| viotapeclose
,
857 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
858 viopath_sourceinst(viopath_hostLp
),
859 viopath_targetinst(viopath_hostLp
),
860 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
861 ((u64
)devi
.devno
<< 48), 0, 0, 0);
863 printk(VIOTAPE_KERN_WARN
"bad rc on signalLpEvent %d\n",
869 wait_for_completion(&op
->com
);
872 printk(VIOTAPE_KERN_WARN
"close failed\n");
879 struct file_operations viotap_fops
= {
885 release
: viotap_release
,
888 /* Handle interrupt events for tape */
889 static void vioHandleTapeEvent(struct HvLpEvent
*event
)
892 struct op_struct
*op
;
893 struct viotapelpevent
*tevent
= (struct viotapelpevent
*)event
;
896 /* Notification that a partition went away! */
897 if (!viopath_isactive(viopath_hostLp
)) {
903 tapeminor
= event
->xSubtype
& VIOMINOR_SUBTYPE_MASK
;
904 op
= (struct op_struct
*)event
->xCorrelationToken
;
909 op
->rc
= tevent
->sub_type_result
;
913 op
->rc
= tevent
->sub_type_result
;
914 op
->count
= tevent
->len
;
918 if (op
->non_blocking
) {
919 dma_free_coherent(op
->dev
, op
->count
,
920 op
->buffer
, op
->dmaaddr
);
924 op
->rc
= tevent
->sub_type_result
;
925 op
->count
= tevent
->len
;
932 case viotapegetstatus
:
934 op
->count
= tevent
->u
.op
.count
;
935 op
->rc
= tevent
->sub_type_result
;
936 if (!op
->non_blocking
)
941 printk(VIOTAPE_KERN_WARN
"weird ack\n");
945 static int viotape_probe(struct vio_dev
*vdev
, const struct vio_device_id
*id
)
948 int i
= vdev
->unit_address
;
951 if (i
>= viotape_numdev
)
954 tape_device
[i
] = &vdev
->dev
;
956 state
[i
].cur_part
= 0;
957 for (j
= 0; j
< MAX_PARTITIONS
; ++j
)
958 state
[i
].part_stat_rwi
[j
] = VIOT_IDLE
;
959 class_device_create(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
), NULL
,
961 class_device_create(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
| 0x80),
962 NULL
, "iseries!nvt%d", i
);
963 devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR
, i
), S_IFCHR
| S_IRUSR
| S_IWUSR
,
965 devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR
, i
| 0x80),
966 S_IFCHR
| S_IRUSR
| S_IWUSR
, "iseries/nvt%d", i
);
967 sprintf(tapename
, "iseries/vt%d", i
);
968 state
[i
].dev_handle
= devfs_register_tape(tapename
);
969 printk(VIOTAPE_KERN_INFO
"tape %s is iSeries "
970 "resource %10.10s type %4.4s, model %3.3s\n",
971 tapename
, viotape_unitinfo
[i
].rsrcname
,
972 viotape_unitinfo
[i
].type
, viotape_unitinfo
[i
].model
);
976 static int viotape_remove(struct vio_dev
*vdev
)
978 int i
= vdev
->unit_address
;
980 devfs_remove("iseries/nvt%d", i
);
981 devfs_remove("iseries/vt%d", i
);
982 devfs_unregister_tape(state
[i
].dev_handle
);
983 class_device_destroy(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
| 0x80));
984 class_device_destroy(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
));
989 * viotape_device_table: Used by vio.c to match devices that we
992 static struct vio_device_id viotape_device_table
[] __devinitdata
= {
997 MODULE_DEVICE_TABLE(vio
, viotape_device_table
);
998 static struct vio_driver viotape_driver
= {
1000 .id_table
= viotape_device_table
,
1001 .probe
= viotape_probe
,
1002 .remove
= viotape_remove
1006 int __init
viotap_init(void)
1009 struct proc_dir_entry
*e
;
1011 op_struct_list
= NULL
;
1012 if ((ret
= add_op_structs(VIOTAPE_MAXREQ
)) < 0) {
1013 printk(VIOTAPE_KERN_WARN
"couldn't allocate op structs\n");
1016 spin_lock_init(&op_struct_list_lock
);
1018 sema_init(&reqSem
, VIOTAPE_MAXREQ
);
1020 if (viopath_hostLp
== HvLpIndexInvalid
) {
1022 if (viopath_hostLp
== HvLpIndexInvalid
) {
1028 ret
= viopath_open(viopath_hostLp
, viomajorsubtype_tape
,
1029 VIOTAPE_MAXREQ
+ 2);
1031 printk(VIOTAPE_KERN_WARN
1032 "error on viopath_open to hostlp %d\n", ret
);
1037 printk(VIOTAPE_KERN_INFO
"vers " VIOTAPE_VERSION
1038 ", hosting partition %d\n", viopath_hostLp
);
1040 vio_setHandler(viomajorsubtype_tape
, vioHandleTapeEvent
);
1042 ret
= register_chrdev(VIOTAPE_MAJOR
, "viotape", &viotap_fops
);
1044 printk(VIOTAPE_KERN_WARN
"Error registering viotape device\n");
1048 tape_class
= class_create(THIS_MODULE
, "tape");
1049 if (IS_ERR(tape_class
)) {
1050 printk(VIOTAPE_KERN_WARN
"Unable to allocat class\n");
1051 ret
= PTR_ERR(tape_class
);
1055 if ((ret
= get_viotape_info()) < 0) {
1056 printk(VIOTAPE_KERN_WARN
"Unable to obtain virtual device information");
1060 ret
= vio_register_driver(&viotape_driver
);
1064 e
= create_proc_entry("iSeries/viotape", S_IFREG
|S_IRUGO
, NULL
);
1066 e
->owner
= THIS_MODULE
;
1067 e
->proc_fops
= &proc_viotape_operations
;
1073 class_destroy(tape_class
);
1075 unregister_chrdev(VIOTAPE_MAJOR
, "viotape");
1077 vio_clearHandler(viomajorsubtype_tape
);
1078 viopath_close(viopath_hostLp
, viomajorsubtype_tape
, VIOTAPE_MAXREQ
+ 2);
1080 clear_op_struct_pool();
1084 /* Give a new state to the tape object */
1085 static int chg_state(int index
, unsigned char new_state
, struct file
*file
)
1087 unsigned char *cur_state
=
1088 &state
[index
].part_stat_rwi
[state
[index
].cur_part
];
1091 /* if the same state, don't bother */
1092 if (*cur_state
== new_state
)
1095 /* write an EOF if changing from writing to some other state */
1096 if (*cur_state
== VIOT_WRITING
) {
1097 struct mtop write_eof
= { MTWEOF
, 1 };
1099 rc
= viotap_ioctl(NULL
, file
, MTIOCTOP
,
1100 (unsigned long)&write_eof
);
1102 *cur_state
= new_state
;
1107 static void __exit
viotap_exit(void)
1111 remove_proc_entry("iSeries/viotape", NULL
);
1112 vio_unregister_driver(&viotape_driver
);
1113 class_destroy(tape_class
);
1114 ret
= unregister_chrdev(VIOTAPE_MAJOR
, "viotape");
1116 printk(VIOTAPE_KERN_WARN
"Error unregistering device: %d\n",
1118 if (viotape_unitinfo
)
1119 dma_free_coherent(iSeries_vio_dev
,
1120 sizeof(viotape_unitinfo
[0]) * VIOTAPE_MAX_TAPE
,
1121 viotape_unitinfo
, viotape_unitinfo_token
);
1122 viopath_close(viopath_hostLp
, viomajorsubtype_tape
, VIOTAPE_MAXREQ
+ 2);
1123 vio_clearHandler(viomajorsubtype_tape
);
1124 clear_op_struct_pool();
1127 MODULE_LICENSE("GPL");
1128 module_init(viotap_init
);
1129 module_exit(viotap_exit
);