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/mutex.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 DEFINE_MUTEX(proc_viotape_mutex
);
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
99 viotape_InvalidRange
= 0x0601,
100 viotape_InvalidToken
= 0x0602,
101 viotape_DMAError
= 0x0603,
102 viotape_UseError
= 0x0604,
103 viotape_ReleaseError
= 0x0605,
104 viotape_InvalidTape
= 0x0606,
105 viotape_InvalidOp
= 0x0607,
106 viotape_TapeErr
= 0x0608,
108 viotape_AllocTimedOut
= 0x0640,
109 viotape_BOTEnc
= 0x0641,
110 viotape_BlankTape
= 0x0642,
111 viotape_BufferEmpty
= 0x0643,
112 viotape_CleanCartFound
= 0x0644,
113 viotape_CmdNotAllowed
= 0x0645,
114 viotape_CmdNotSupported
= 0x0646,
115 viotape_DataCheck
= 0x0647,
116 viotape_DecompressErr
= 0x0648,
117 viotape_DeviceTimeout
= 0x0649,
118 viotape_DeviceUnavail
= 0x064a,
119 viotape_DeviceBusy
= 0x064b,
120 viotape_EndOfMedia
= 0x064c,
121 viotape_EndOfTape
= 0x064d,
122 viotape_EquipCheck
= 0x064e,
123 viotape_InsufficientRs
= 0x064f,
124 viotape_InvalidLogBlk
= 0x0650,
125 viotape_LengthError
= 0x0651,
126 viotape_LibDoorOpen
= 0x0652,
127 viotape_LoadFailure
= 0x0653,
128 viotape_NotCapable
= 0x0654,
129 viotape_NotOperational
= 0x0655,
130 viotape_NotReady
= 0x0656,
131 viotape_OpCancelled
= 0x0657,
132 viotape_PhyLinkErr
= 0x0658,
133 viotape_RdyNotBOT
= 0x0659,
134 viotape_TapeMark
= 0x065a,
135 viotape_WriteProt
= 0x065b
138 static const struct vio_error_entry viotape_err_table
[] = {
139 { viotape_InvalidRange
, EIO
, "Internal error" },
140 { viotape_InvalidToken
, EIO
, "Internal error" },
141 { viotape_DMAError
, EIO
, "DMA error" },
142 { viotape_UseError
, EIO
, "Internal error" },
143 { viotape_ReleaseError
, EIO
, "Internal error" },
144 { viotape_InvalidTape
, EIO
, "Invalid tape device" },
145 { viotape_InvalidOp
, EIO
, "Invalid operation" },
146 { viotape_TapeErr
, EIO
, "Tape error" },
147 { viotape_AllocTimedOut
, EBUSY
, "Allocate timed out" },
148 { viotape_BOTEnc
, EIO
, "Beginning of tape encountered" },
149 { viotape_BlankTape
, EIO
, "Blank tape" },
150 { viotape_BufferEmpty
, EIO
, "Buffer empty" },
151 { viotape_CleanCartFound
, ENOMEDIUM
, "Cleaning cartridge found" },
152 { viotape_CmdNotAllowed
, EIO
, "Command not allowed" },
153 { viotape_CmdNotSupported
, EIO
, "Command not supported" },
154 { viotape_DataCheck
, EIO
, "Data check" },
155 { viotape_DecompressErr
, EIO
, "Decompression error" },
156 { viotape_DeviceTimeout
, EBUSY
, "Device timeout" },
157 { viotape_DeviceUnavail
, EIO
, "Device unavailable" },
158 { viotape_DeviceBusy
, EBUSY
, "Device busy" },
159 { viotape_EndOfMedia
, ENOSPC
, "End of media" },
160 { viotape_EndOfTape
, ENOSPC
, "End of tape" },
161 { viotape_EquipCheck
, EIO
, "Equipment check" },
162 { viotape_InsufficientRs
, EOVERFLOW
, "Insufficient tape resources" },
163 { viotape_InvalidLogBlk
, EIO
, "Invalid logical block location" },
164 { viotape_LengthError
, EOVERFLOW
, "Length error" },
165 { viotape_LibDoorOpen
, EBUSY
, "Door open" },
166 { viotape_LoadFailure
, ENOMEDIUM
, "Load failure" },
167 { viotape_NotCapable
, EIO
, "Not capable" },
168 { viotape_NotOperational
, EIO
, "Not operational" },
169 { viotape_NotReady
, EIO
, "Not ready" },
170 { viotape_OpCancelled
, EIO
, "Operation cancelled" },
171 { viotape_PhyLinkErr
, EIO
, "Physical link error" },
172 { viotape_RdyNotBOT
, EIO
, "Ready but not beginning of tape" },
173 { viotape_TapeMark
, EIO
, "Tape mark" },
174 { viotape_WriteProt
, EROFS
, "Write protection error" },
178 /* Maximum number of tapes we support */
179 #define VIOTAPE_MAX_TAPE HVMAXARCHITECTEDVIRTUALTAPES
180 #define MAX_PARTITIONS 4
182 /* defines for current tape state */
184 #define VIOT_READING 1
185 #define VIOT_WRITING 2
187 /* Our info on the tapes */
189 const char *rsrcname
;
192 } viotape_unitinfo
[VIOTAPE_MAX_TAPE
];
194 static struct mtget viomtget
[VIOTAPE_MAX_TAPE
];
196 static struct class *tape_class
;
198 static struct device
*tape_device
[VIOTAPE_MAX_TAPE
];
201 * maintain the current state of each tape (and partition)
202 * so that we know when to write EOF marks.
205 unsigned char cur_part
;
206 unsigned char part_stat_rwi
[MAX_PARTITIONS
];
207 } state
[VIOTAPE_MAX_TAPE
];
209 /* We single-thread */
210 static struct semaphore reqSem
;
213 * When we send a request, we use this struct to get the response back
214 * from the interrupt handler
222 struct completion com
;
224 struct op_struct
*next
;
227 static spinlock_t op_struct_list_lock
;
228 static struct op_struct
*op_struct_list
;
230 /* forward declaration to resolve interdependence */
231 static int chg_state(int index
, unsigned char new_state
, struct file
*file
);
234 static int proc_viotape_show(struct seq_file
*m
, void *v
)
238 seq_printf(m
, "viotape driver version " VIOTAPE_VERSION
"\n");
239 for (i
= 0; i
< viotape_numdev
; i
++) {
240 seq_printf(m
, "viotape device %d is iSeries resource %10.10s"
241 "type %4.4s, model %3.3s\n",
242 i
, viotape_unitinfo
[i
].rsrcname
,
243 viotape_unitinfo
[i
].type
,
244 viotape_unitinfo
[i
].model
);
249 static int proc_viotape_open(struct inode
*inode
, struct file
*file
)
251 return single_open(file
, proc_viotape_show
, NULL
);
254 static const struct file_operations proc_viotape_operations
= {
255 .owner
= THIS_MODULE
,
256 .open
= proc_viotape_open
,
259 .release
= single_release
,
262 /* Decode the device minor number into its parts */
263 void get_dev_info(struct inode
*ino
, struct viot_devinfo_struct
*devi
)
265 devi
->devno
= iminor(ino
) & 0x1F;
266 devi
->mode
= (iminor(ino
) & 0x60) >> 5;
267 /* if bit is set in the minor, do _not_ rewind automatically */
268 devi
->rewind
= (iminor(ino
) & 0x80) == 0;
271 /* This is called only from the exit and init paths, so no need for locking */
272 static void clear_op_struct_pool(void)
274 while (op_struct_list
) {
275 struct op_struct
*toFree
= op_struct_list
;
276 op_struct_list
= op_struct_list
->next
;
281 /* Likewise, this is only called from the init path */
282 static int add_op_structs(int structs
)
286 for (i
= 0; i
< structs
; ++i
) {
287 struct op_struct
*new_struct
=
288 kmalloc(sizeof(*new_struct
), GFP_KERNEL
);
290 clear_op_struct_pool();
293 new_struct
->next
= op_struct_list
;
294 op_struct_list
= new_struct
;
299 /* Allocate an op structure from our pool */
300 static struct op_struct
*get_op_struct(void)
302 struct op_struct
*retval
;
305 spin_lock_irqsave(&op_struct_list_lock
, flags
);
306 retval
= op_struct_list
;
308 op_struct_list
= retval
->next
;
309 spin_unlock_irqrestore(&op_struct_list_lock
, flags
);
311 memset(retval
, 0, sizeof(*retval
));
312 init_completion(&retval
->com
);
318 /* Return an op structure to our pool */
319 static void free_op_struct(struct op_struct
*op_struct
)
323 spin_lock_irqsave(&op_struct_list_lock
, flags
);
324 op_struct
->next
= op_struct_list
;
325 op_struct_list
= op_struct
;
326 spin_unlock_irqrestore(&op_struct_list_lock
, flags
);
329 /* Map our tape return codes to errno values */
330 int tape_rc_to_errno(int tape_rc
, char *operation
, int tapeno
)
332 const struct vio_error_entry
*err
;
337 err
= vio_lookup_rc(viotape_err_table
, tape_rc
);
338 printk(VIOTAPE_KERN_WARN
"error(%s) 0x%04x on Device %d (%-10s): %s\n",
339 operation
, tape_rc
, tapeno
,
340 viotape_unitinfo
[tapeno
].rsrcname
, err
->msg
);
345 static ssize_t
viotap_write(struct file
*file
, const char *buf
,
346 size_t count
, loff_t
* ppos
)
349 unsigned short flags
= file
->f_flags
;
350 int noblock
= ((flags
& O_NONBLOCK
) != 0);
352 struct viot_devinfo_struct devi
;
353 struct op_struct
*op
= get_op_struct();
358 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
361 * We need to make sure we can send a request. We use
362 * a semaphore to keep track of # requests in use. If
363 * we are non-blocking, make sure we don't block on the
367 if (down_trylock(&reqSem
)) {
374 /* Allocate a DMA buffer */
375 op
->dev
= tape_device
[devi
.devno
];
376 op
->buffer
= dma_alloc_coherent(op
->dev
, count
, &op
->dmaaddr
,
379 if (op
->buffer
== NULL
) {
380 printk(VIOTAPE_KERN_WARN
381 "error allocating dma buffer for len %ld\n",
387 /* Copy the data into the buffer */
388 if (copy_from_user(op
->buffer
, buf
, count
)) {
389 printk(VIOTAPE_KERN_WARN
"tape: error on copy from user\n");
394 op
->non_blocking
= noblock
;
395 init_completion(&op
->com
);
398 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
399 HvLpEvent_Type_VirtualIo
,
400 viomajorsubtype_tape
| viotapewrite
,
401 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
402 viopath_sourceinst(viopath_hostLp
),
403 viopath_targetinst(viopath_hostLp
),
404 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
405 ((u64
)devi
.devno
<< 48) | op
->dmaaddr
, count
, 0, 0);
406 if (hvrc
!= HvLpEvent_Rc_Good
) {
407 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
416 wait_for_completion(&op
->com
);
419 ret
= tape_rc_to_errno(op
->rc
, "write", devi
.devno
);
421 chg_state(devi
.devno
, VIOT_WRITING
, file
);
426 dma_free_coherent(op
->dev
, count
, op
->buffer
, op
->dmaaddr
);
435 static ssize_t
viotap_read(struct file
*file
, char *buf
, size_t count
,
439 unsigned short flags
= file
->f_flags
;
440 struct op_struct
*op
= get_op_struct();
441 int noblock
= ((flags
& O_NONBLOCK
) != 0);
443 struct viot_devinfo_struct devi
;
448 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
451 * We need to make sure we can send a request. We use
452 * a semaphore to keep track of # requests in use. If
453 * we are non-blocking, make sure we don't block on the
457 if (down_trylock(&reqSem
)) {
464 chg_state(devi
.devno
, VIOT_READING
, file
);
466 /* Allocate a DMA buffer */
467 op
->dev
= tape_device
[devi
.devno
];
468 op
->buffer
= dma_alloc_coherent(op
->dev
, count
, &op
->dmaaddr
,
470 if (op
->buffer
== NULL
) {
476 init_completion(&op
->com
);
478 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
479 HvLpEvent_Type_VirtualIo
,
480 viomajorsubtype_tape
| viotaperead
,
481 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
482 viopath_sourceinst(viopath_hostLp
),
483 viopath_targetinst(viopath_hostLp
),
484 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
485 ((u64
)devi
.devno
<< 48) | op
->dmaaddr
, count
, 0, 0);
486 if (hvrc
!= HvLpEvent_Rc_Good
) {
487 printk(VIOTAPE_KERN_WARN
"tape hv error on op %d\n",
493 wait_for_completion(&op
->com
);
496 ret
= tape_rc_to_errno(op
->rc
, "read", devi
.devno
);
499 if (ret
&& copy_to_user(buf
, op
->buffer
, ret
)) {
500 printk(VIOTAPE_KERN_WARN
"error on copy_to_user\n");
506 dma_free_coherent(op
->dev
, count
, op
->buffer
, op
->dmaaddr
);
515 static int viotap_ioctl(struct inode
*inode
, struct file
*file
,
516 unsigned int cmd
, unsigned long arg
)
520 struct viot_devinfo_struct devi
;
523 struct op_struct
*op
= get_op_struct();
528 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
538 * inode is null if and only if we (the kernel)
542 memcpy(&mtc
, (void *) arg
, sizeof(struct mtop
));
543 else if (copy_from_user((char *)&mtc
, (char *)arg
,
544 sizeof(struct mtop
)))
550 myOp
= VIOTAPOP_RESET
;
565 myOp
= VIOTAPOP_WEOF
;
577 myOp
= VIOTAPOP_ERASE
;
580 myOp
= VIOTAPOP_SETBLK
;
583 myOp
= VIOTAPOP_SETDENSITY
;
586 myOp
= VIOTAPOP_GETPOS
;
589 myOp
= VIOTAPOP_SETPOS
;
592 myOp
= VIOTAPOP_SETPART
;
595 myOp
= VIOTAPOP_UNLOAD
;
598 printk(VIOTAPE_KERN_WARN
"MTIOCTOP called "
599 "with invalid op 0x%x\n", mtc
.mt_op
);
604 * if we moved the head, we are no longer
615 chg_state(devi
.devno
, VIOT_IDLE
, file
);
618 init_completion(&op
->com
);
619 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
620 HvLpEvent_Type_VirtualIo
,
621 viomajorsubtype_tape
| viotapeop
,
622 HvLpEvent_AckInd_DoAck
,
623 HvLpEvent_AckType_ImmediateAck
,
624 viopath_sourceinst(viopath_hostLp
),
625 viopath_targetinst(viopath_hostLp
),
626 (u64
)(unsigned long)op
,
628 ((u64
)devi
.devno
<< 48), 0,
629 (((u64
)myOp
) << 32) | mtc
.mt_count
, 0);
630 if (hvrc
!= HvLpEvent_Rc_Good
) {
631 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
635 wait_for_completion(&op
->com
);
636 ret
= tape_rc_to_errno(op
->rc
, "tape operation", devi
.devno
);
641 init_completion(&op
->com
);
642 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
643 HvLpEvent_Type_VirtualIo
,
644 viomajorsubtype_tape
| viotapegetstatus
,
645 HvLpEvent_AckInd_DoAck
,
646 HvLpEvent_AckType_ImmediateAck
,
647 viopath_sourceinst(viopath_hostLp
),
648 viopath_targetinst(viopath_hostLp
),
649 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
650 ((u64
)devi
.devno
<< 48), 0, 0, 0);
651 if (hvrc
!= HvLpEvent_Rc_Good
) {
652 printk(VIOTAPE_KERN_WARN
"hv error on op %d\n",
656 wait_for_completion(&op
->com
);
658 /* Operation is complete - grab the error code */
659 ret
= tape_rc_to_errno(op
->rc
, "get status", devi
.devno
);
663 if ((ret
== 0) && copy_to_user((void *)arg
,
664 &viomtget
[devi
.devno
],
665 sizeof(viomtget
[0])))
669 printk(VIOTAPE_KERN_WARN
"Got an (unsupported) MTIOCPOS\n");
672 printk(VIOTAPE_KERN_WARN
"got an unsupported ioctl 0x%0x\n",
683 static long viotap_unlocked_ioctl(struct file
*file
,
684 unsigned int cmd
, unsigned long arg
)
688 mutex_lock(&proc_viotape_mutex
);
689 rc
= viotap_ioctl(file
->f_path
.dentry
->d_inode
, file
, cmd
, arg
);
690 mutex_unlock(&proc_viotape_mutex
);
694 static int viotap_open(struct inode
*inode
, struct file
*file
)
697 struct viot_devinfo_struct devi
;
699 struct op_struct
*op
= get_op_struct();
704 mutex_lock(&proc_viotape_mutex
);
705 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
707 /* Note: We currently only support one mode! */
708 if ((devi
.devno
>= viotape_numdev
) || (devi
.mode
)) {
713 init_completion(&op
->com
);
715 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
716 HvLpEvent_Type_VirtualIo
,
717 viomajorsubtype_tape
| viotapeopen
,
718 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
719 viopath_sourceinst(viopath_hostLp
),
720 viopath_targetinst(viopath_hostLp
),
721 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
722 ((u64
)devi
.devno
<< 48), 0, 0, 0);
724 printk(VIOTAPE_KERN_WARN
"bad rc on signalLpEvent %d\n",
730 wait_for_completion(&op
->com
);
731 ret
= tape_rc_to_errno(op
->rc
, "open", devi
.devno
);
735 mutex_unlock(&proc_viotape_mutex
);
740 static int viotap_release(struct inode
*inode
, struct file
*file
)
743 struct viot_devinfo_struct devi
;
745 struct op_struct
*op
= get_op_struct();
749 init_completion(&op
->com
);
751 get_dev_info(file
->f_path
.dentry
->d_inode
, &devi
);
753 if (devi
.devno
>= viotape_numdev
) {
758 chg_state(devi
.devno
, VIOT_IDLE
, file
);
761 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
762 HvLpEvent_Type_VirtualIo
,
763 viomajorsubtype_tape
| viotapeop
,
764 HvLpEvent_AckInd_DoAck
,
765 HvLpEvent_AckType_ImmediateAck
,
766 viopath_sourceinst(viopath_hostLp
),
767 viopath_targetinst(viopath_hostLp
),
768 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
769 ((u64
)devi
.devno
<< 48), 0,
770 ((u64
)VIOTAPOP_REW
) << 32, 0);
771 wait_for_completion(&op
->com
);
773 tape_rc_to_errno(op
->rc
, "rewind", devi
.devno
);
776 hvrc
= HvCallEvent_signalLpEventFast(viopath_hostLp
,
777 HvLpEvent_Type_VirtualIo
,
778 viomajorsubtype_tape
| viotapeclose
,
779 HvLpEvent_AckInd_DoAck
, HvLpEvent_AckType_ImmediateAck
,
780 viopath_sourceinst(viopath_hostLp
),
781 viopath_targetinst(viopath_hostLp
),
782 (u64
)(unsigned long)op
, VIOVERSION
<< 16,
783 ((u64
)devi
.devno
<< 48), 0, 0, 0);
785 printk(VIOTAPE_KERN_WARN
"bad rc on signalLpEvent %d\n",
791 wait_for_completion(&op
->com
);
794 printk(VIOTAPE_KERN_WARN
"close failed\n");
801 const struct file_operations viotap_fops
= {
802 .owner
= THIS_MODULE
,
804 .write
= viotap_write
,
805 .unlocked_ioctl
= viotap_unlocked_ioctl
,
807 .release
= viotap_release
,
808 .llseek
= noop_llseek
,
811 /* Handle interrupt events for tape */
812 static void vioHandleTapeEvent(struct HvLpEvent
*event
)
815 struct op_struct
*op
;
816 struct viotapelpevent
*tevent
= (struct viotapelpevent
*)event
;
819 /* Notification that a partition went away! */
820 if (!viopath_isactive(viopath_hostLp
)) {
826 tapeminor
= event
->xSubtype
& VIOMINOR_SUBTYPE_MASK
;
827 op
= (struct op_struct
*)event
->xCorrelationToken
;
831 op
->rc
= tevent
->sub_type_result
;
835 op
->rc
= tevent
->sub_type_result
;
836 op
->count
= tevent
->len
;
840 if (op
->non_blocking
) {
841 dma_free_coherent(op
->dev
, op
->count
,
842 op
->buffer
, op
->dmaaddr
);
846 op
->rc
= tevent
->sub_type_result
;
847 op
->count
= tevent
->len
;
854 case viotapegetstatus
:
856 op
->count
= tevent
->u
.op
.count
;
857 op
->rc
= tevent
->sub_type_result
;
858 if (!op
->non_blocking
)
863 printk(VIOTAPE_KERN_WARN
"weird ack\n");
867 static int viotape_probe(struct vio_dev
*vdev
, const struct vio_device_id
*id
)
869 int i
= vdev
->unit_address
;
871 struct device_node
*node
= vdev
->dev
.of_node
;
873 if (i
>= VIOTAPE_MAX_TAPE
)
878 if (i
>= viotape_numdev
)
879 viotape_numdev
= i
+ 1;
881 tape_device
[i
] = &vdev
->dev
;
882 viotape_unitinfo
[i
].rsrcname
= of_get_property(node
,
883 "linux,vio_rsrcname", NULL
);
884 viotape_unitinfo
[i
].type
= of_get_property(node
, "linux,vio_type",
886 viotape_unitinfo
[i
].model
= of_get_property(node
, "linux,vio_model",
889 state
[i
].cur_part
= 0;
890 for (j
= 0; j
< MAX_PARTITIONS
; ++j
)
891 state
[i
].part_stat_rwi
[j
] = VIOT_IDLE
;
892 device_create(tape_class
, NULL
, MKDEV(VIOTAPE_MAJOR
, i
), NULL
,
894 device_create(tape_class
, NULL
, MKDEV(VIOTAPE_MAJOR
, i
| 0x80), NULL
,
896 printk(VIOTAPE_KERN_INFO
"tape iseries/vt%d is iSeries "
897 "resource %10.10s type %4.4s, model %3.3s\n",
898 i
, viotape_unitinfo
[i
].rsrcname
,
899 viotape_unitinfo
[i
].type
, viotape_unitinfo
[i
].model
);
903 static int viotape_remove(struct vio_dev
*vdev
)
905 int i
= vdev
->unit_address
;
907 device_destroy(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
| 0x80));
908 device_destroy(tape_class
, MKDEV(VIOTAPE_MAJOR
, i
));
913 * viotape_device_table: Used by vio.c to match devices that we
916 static struct vio_device_id viotape_device_table
[] __devinitdata
= {
917 { "byte", "IBM,iSeries-viotape" },
920 MODULE_DEVICE_TABLE(vio
, viotape_device_table
);
922 static struct vio_driver viotape_driver
= {
923 .id_table
= viotape_device_table
,
924 .probe
= viotape_probe
,
925 .remove
= viotape_remove
,
928 .owner
= THIS_MODULE
,
933 int __init
viotap_init(void)
937 if (!firmware_has_feature(FW_FEATURE_ISERIES
))
940 op_struct_list
= NULL
;
941 if ((ret
= add_op_structs(VIOTAPE_MAXREQ
)) < 0) {
942 printk(VIOTAPE_KERN_WARN
"couldn't allocate op structs\n");
945 spin_lock_init(&op_struct_list_lock
);
947 sema_init(&reqSem
, VIOTAPE_MAXREQ
);
949 if (viopath_hostLp
== HvLpIndexInvalid
) {
951 if (viopath_hostLp
== HvLpIndexInvalid
) {
957 ret
= viopath_open(viopath_hostLp
, viomajorsubtype_tape
,
960 printk(VIOTAPE_KERN_WARN
961 "error on viopath_open to hostlp %d\n", ret
);
966 printk(VIOTAPE_KERN_INFO
"vers " VIOTAPE_VERSION
967 ", hosting partition %d\n", viopath_hostLp
);
969 vio_setHandler(viomajorsubtype_tape
, vioHandleTapeEvent
);
971 ret
= register_chrdev(VIOTAPE_MAJOR
, "viotape", &viotap_fops
);
973 printk(VIOTAPE_KERN_WARN
"Error registering viotape device\n");
977 tape_class
= class_create(THIS_MODULE
, "tape");
978 if (IS_ERR(tape_class
)) {
979 printk(VIOTAPE_KERN_WARN
"Unable to allocat class\n");
980 ret
= PTR_ERR(tape_class
);
984 ret
= vio_register_driver(&viotape_driver
);
988 proc_create("iSeries/viotape", S_IFREG
|S_IRUGO
, NULL
,
989 &proc_viotape_operations
);
994 class_destroy(tape_class
);
996 unregister_chrdev(VIOTAPE_MAJOR
, "viotape");
998 vio_clearHandler(viomajorsubtype_tape
);
999 viopath_close(viopath_hostLp
, viomajorsubtype_tape
, VIOTAPE_MAXREQ
+ 2);
1001 clear_op_struct_pool();
1005 /* Give a new state to the tape object */
1006 static int chg_state(int index
, unsigned char new_state
, struct file
*file
)
1008 unsigned char *cur_state
=
1009 &state
[index
].part_stat_rwi
[state
[index
].cur_part
];
1012 /* if the same state, don't bother */
1013 if (*cur_state
== new_state
)
1016 /* write an EOF if changing from writing to some other state */
1017 if (*cur_state
== VIOT_WRITING
) {
1018 struct mtop write_eof
= { MTWEOF
, 1 };
1020 rc
= viotap_ioctl(NULL
, file
, MTIOCTOP
,
1021 (unsigned long)&write_eof
);
1023 *cur_state
= new_state
;
1028 static void __exit
viotap_exit(void)
1030 remove_proc_entry("iSeries/viotape", NULL
);
1031 vio_unregister_driver(&viotape_driver
);
1032 class_destroy(tape_class
);
1033 unregister_chrdev(VIOTAPE_MAJOR
, "viotape");
1034 viopath_close(viopath_hostLp
, viomajorsubtype_tape
, VIOTAPE_MAXREQ
+ 2);
1035 vio_clearHandler(viomajorsubtype_tape
);
1036 clear_op_struct_pool();
1039 MODULE_LICENSE("GPL");
1040 module_init(viotap_init
);
1041 module_exit(viotap_exit
);