2 * drivers/s390/char/tape_std.c
3 * standard tape device functions for ibm tapes.
5 * S390 and zSeries version
6 * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Michael Holzheu <holzheu@de.ibm.com>
9 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
10 * Martin Schwidefsky <schwidefsky@de.ibm.com>
11 * Stefan Bader <shbader@de.ibm.com>
14 #include <linux/config.h>
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/bio.h>
18 #include <linux/timer.h>
20 #include <asm/types.h>
21 #include <asm/idals.h>
22 #include <asm/ebcdic.h>
23 #include <asm/tape390.h>
25 #define TAPE_DBF_AREA tape_core_dbf
30 #define PRINTK_HEADER "TAPE_STD: "
36 tape_std_assign_timeout(unsigned long data
)
38 struct tape_request
* request
;
39 struct tape_device
* device
;
41 request
= (struct tape_request
*) data
;
42 if ((device
= request
->device
) == NULL
)
45 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
46 if (request
->callback
!= NULL
) {
47 DBF_EVENT(3, "%08x: Assignment timeout. Device busy.\n",
49 PRINT_ERR("%s: Assignment timeout. Device busy.\n",
50 device
->cdev
->dev
.bus_id
);
51 ccw_device_clear(device
->cdev
, (long) request
);
53 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
57 tape_std_assign(struct tape_device
*device
)
60 struct timer_list timeout
;
61 struct tape_request
*request
;
63 request
= tape_alloc_request(2, 11);
65 return PTR_ERR(request
);
67 request
->op
= TO_ASSIGN
;
68 tape_ccw_cc(request
->cpaddr
, ASSIGN
, 11, request
->cpdata
);
69 tape_ccw_end(request
->cpaddr
+ 1, NOP
, 0, NULL
);
72 * The assign command sometimes blocks if the device is assigned
73 * to another host (actually this shouldn't happen but it does).
74 * So we set up a timeout for this call.
77 timeout
.function
= tape_std_assign_timeout
;
78 timeout
.data
= (unsigned long) request
;
79 timeout
.expires
= jiffies
+ 2 * HZ
;
82 rc
= tape_do_io_interruptible(device
, request
);
87 PRINT_WARN("%s: assign failed - device might be busy\n",
88 device
->cdev
->dev
.bus_id
);
89 DBF_EVENT(3, "%08x: assign failed - device might be busy\n",
92 DBF_EVENT(3, "%08x: Tape assigned\n", device
->cdev_id
);
94 tape_free_request(request
);
102 tape_std_unassign (struct tape_device
*device
)
105 struct tape_request
*request
;
107 if (device
->tape_state
== TS_NOT_OPER
) {
108 DBF_EVENT(3, "(%08x): Can't unassign device\n",
110 PRINT_WARN("(%s): Can't unassign device - device gone\n",
111 device
->cdev
->dev
.bus_id
);
115 request
= tape_alloc_request(2, 11);
117 return PTR_ERR(request
);
119 request
->op
= TO_UNASSIGN
;
120 tape_ccw_cc(request
->cpaddr
, UNASSIGN
, 11, request
->cpdata
);
121 tape_ccw_end(request
->cpaddr
+ 1, NOP
, 0, NULL
);
123 if ((rc
= tape_do_io(device
, request
)) != 0) {
124 DBF_EVENT(3, "%08x: Unassign failed\n", device
->cdev_id
);
125 PRINT_WARN("%s: Unassign failed\n", device
->cdev
->dev
.bus_id
);
127 DBF_EVENT(3, "%08x: Tape unassigned\n", device
->cdev_id
);
129 tape_free_request(request
);
134 * TAPE390_DISPLAY: Show a string on the tape display.
137 tape_std_display(struct tape_device
*device
, struct display_struct
*disp
)
139 struct tape_request
*request
;
142 request
= tape_alloc_request(2, 17);
143 if (IS_ERR(request
)) {
144 DBF_EVENT(3, "TAPE: load display failed\n");
145 return PTR_ERR(request
);
147 request
->op
= TO_DIS
;
149 *(unsigned char *) request
->cpdata
= disp
->cntrl
;
150 DBF_EVENT(5, "TAPE: display cntrl=%04x\n", disp
->cntrl
);
151 memcpy(((unsigned char *) request
->cpdata
) + 1, disp
->message1
, 8);
152 memcpy(((unsigned char *) request
->cpdata
) + 9, disp
->message2
, 8);
153 ASCEBC(((unsigned char*) request
->cpdata
) + 1, 16);
155 tape_ccw_cc(request
->cpaddr
, LOAD_DISPLAY
, 17, request
->cpdata
);
156 tape_ccw_end(request
->cpaddr
+ 1, NOP
, 0, NULL
);
158 rc
= tape_do_io_interruptible(device
, request
);
159 tape_free_request(request
);
167 tape_std_read_block_id(struct tape_device
*device
, __u64
*id
)
169 struct tape_request
*request
;
172 request
= tape_alloc_request(3, 8);
174 return PTR_ERR(request
);
175 request
->op
= TO_RBI
;
177 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
178 tape_ccw_cc(request
->cpaddr
+ 1, READ_BLOCK_ID
, 8, request
->cpdata
);
179 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
181 rc
= tape_do_io(device
, request
);
183 /* Get result from read buffer. */
184 *id
= *(__u64
*) request
->cpdata
;
185 tape_free_request(request
);
190 tape_std_terminate_write(struct tape_device
*device
)
194 if(device
->required_tapemarks
== 0)
197 DBF_LH(5, "tape%d: terminate write %dxEOF\n", device
->first_minor
,
198 device
->required_tapemarks
);
200 rc
= tape_mtop(device
, MTWEOF
, device
->required_tapemarks
);
204 device
->required_tapemarks
= 0;
205 return tape_mtop(device
, MTBSR
, 1);
209 * MTLOAD: Loads the tape.
210 * The default implementation just wait until the tape medium state changes
214 tape_std_mtload(struct tape_device
*device
, int count
)
216 return wait_event_interruptible(device
->state_change_wq
,
217 (device
->medium_state
== MS_LOADED
));
221 * MTSETBLK: Set block size.
224 tape_std_mtsetblk(struct tape_device
*device
, int count
)
226 struct idal_buffer
*new;
228 DBF_LH(6, "tape_std_mtsetblk(%d)\n", count
);
231 * Just set block_size to 0. tapechar_read/tapechar_write
232 * will realloc the idal buffer if a bigger one than the
235 device
->char_data
.block_size
= 0;
238 if (device
->char_data
.idal_buf
!= NULL
&&
239 device
->char_data
.idal_buf
->size
== count
)
240 /* We already have a idal buffer of that size. */
243 if (count
> MAX_BLOCKSIZE
) {
244 DBF_EVENT(3, "Invalid block size (%d > %d) given.\n",
245 count
, MAX_BLOCKSIZE
);
246 PRINT_ERR("Invalid block size (%d > %d) given.\n",
247 count
, MAX_BLOCKSIZE
);
251 /* Allocate a new idal buffer. */
252 new = idal_buffer_alloc(count
, 0);
255 if (device
->char_data
.idal_buf
!= NULL
)
256 idal_buffer_free(device
->char_data
.idal_buf
);
257 device
->char_data
.idal_buf
= new;
258 device
->char_data
.block_size
= count
;
260 DBF_LH(6, "new blocksize is %d\n", device
->char_data
.block_size
);
266 * MTRESET: Set block size to 0.
269 tape_std_mtreset(struct tape_device
*device
, int count
)
271 DBF_EVENT(6, "TCHAR:devreset:\n");
272 device
->char_data
.block_size
= 0;
277 * MTFSF: Forward space over 'count' file marks. The tape is positioned
278 * at the EOT (End of Tape) side of the file mark.
281 tape_std_mtfsf(struct tape_device
*device
, int mt_count
)
283 struct tape_request
*request
;
286 request
= tape_alloc_request(mt_count
+ 2, 0);
288 return PTR_ERR(request
);
289 request
->op
= TO_FSF
;
291 ccw
= tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
292 device
->modeset_byte
);
293 ccw
= tape_ccw_repeat(ccw
, FORSPACEFILE
, mt_count
);
294 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
297 return tape_do_io_free(device
, request
);
301 * MTFSR: Forward space over 'count' tape blocks (blocksize is set
305 tape_std_mtfsr(struct tape_device
*device
, int mt_count
)
307 struct tape_request
*request
;
311 request
= tape_alloc_request(mt_count
+ 2, 0);
313 return PTR_ERR(request
);
314 request
->op
= TO_FSB
;
316 ccw
= tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
317 device
->modeset_byte
);
318 ccw
= tape_ccw_repeat(ccw
, FORSPACEBLOCK
, mt_count
);
319 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
322 rc
= tape_do_io(device
, request
);
323 if (rc
== 0 && request
->rescnt
> 0) {
324 DBF_LH(3, "FSR over tapemark\n");
327 tape_free_request(request
);
333 * MTBSR: Backward space over 'count' tape blocks.
334 * (blocksize is set via MTSETBLK.
337 tape_std_mtbsr(struct tape_device
*device
, int mt_count
)
339 struct tape_request
*request
;
343 request
= tape_alloc_request(mt_count
+ 2, 0);
345 return PTR_ERR(request
);
346 request
->op
= TO_BSB
;
348 ccw
= tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
349 device
->modeset_byte
);
350 ccw
= tape_ccw_repeat(ccw
, BACKSPACEBLOCK
, mt_count
);
351 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
354 rc
= tape_do_io(device
, request
);
355 if (rc
== 0 && request
->rescnt
> 0) {
356 DBF_LH(3, "BSR over tapemark\n");
359 tape_free_request(request
);
365 * MTWEOF: Write 'count' file marks at the current position.
368 tape_std_mtweof(struct tape_device
*device
, int mt_count
)
370 struct tape_request
*request
;
373 request
= tape_alloc_request(mt_count
+ 2, 0);
375 return PTR_ERR(request
);
376 request
->op
= TO_WTM
;
378 ccw
= tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
379 device
->modeset_byte
);
380 ccw
= tape_ccw_repeat(ccw
, WRITETAPEMARK
, mt_count
);
381 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
384 return tape_do_io_free(device
, request
);
388 * MTBSFM: Backward space over 'count' file marks.
389 * The tape is positioned at the BOT (Begin Of Tape) side of the
390 * last skipped file mark.
393 tape_std_mtbsfm(struct tape_device
*device
, int mt_count
)
395 struct tape_request
*request
;
398 request
= tape_alloc_request(mt_count
+ 2, 0);
400 return PTR_ERR(request
);
401 request
->op
= TO_BSF
;
403 ccw
= tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
404 device
->modeset_byte
);
405 ccw
= tape_ccw_repeat(ccw
, BACKSPACEFILE
, mt_count
);
406 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
409 return tape_do_io_free(device
, request
);
413 * MTBSF: Backward space over 'count' file marks. The tape is positioned at
414 * the EOT (End of Tape) side of the last skipped file mark.
417 tape_std_mtbsf(struct tape_device
*device
, int mt_count
)
419 struct tape_request
*request
;
423 request
= tape_alloc_request(mt_count
+ 2, 0);
425 return PTR_ERR(request
);
426 request
->op
= TO_BSF
;
428 ccw
= tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
429 device
->modeset_byte
);
430 ccw
= tape_ccw_repeat(ccw
, BACKSPACEFILE
, mt_count
);
431 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
433 rc
= tape_do_io_free(device
, request
);
435 rc
= tape_mtop(device
, MTFSR
, 1);
443 * MTFSFM: Forward space over 'count' file marks.
444 * The tape is positioned at the BOT (Begin Of Tape) side
445 * of the last skipped file mark.
448 tape_std_mtfsfm(struct tape_device
*device
, int mt_count
)
450 struct tape_request
*request
;
454 request
= tape_alloc_request(mt_count
+ 2, 0);
456 return PTR_ERR(request
);
457 request
->op
= TO_FSF
;
459 ccw
= tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
460 device
->modeset_byte
);
461 ccw
= tape_ccw_repeat(ccw
, FORSPACEFILE
, mt_count
);
462 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
464 rc
= tape_do_io_free(device
, request
);
466 rc
= tape_mtop(device
, MTBSR
, 1);
475 * MTREW: Rewind the tape.
478 tape_std_mtrew(struct tape_device
*device
, int mt_count
)
480 struct tape_request
*request
;
482 request
= tape_alloc_request(3, 0);
484 return PTR_ERR(request
);
485 request
->op
= TO_REW
;
487 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1,
488 device
->modeset_byte
);
489 tape_ccw_cc(request
->cpaddr
+ 1, REWIND
, 0, NULL
);
490 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
493 return tape_do_io_free(device
, request
);
497 * MTOFFL: Rewind the tape and put the drive off-line.
498 * Implement 'rewind unload'
501 tape_std_mtoffl(struct tape_device
*device
, int mt_count
)
503 struct tape_request
*request
;
505 request
= tape_alloc_request(3, 0);
507 return PTR_ERR(request
);
508 request
->op
= TO_RUN
;
510 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
511 tape_ccw_cc(request
->cpaddr
+ 1, REWIND_UNLOAD
, 0, NULL
);
512 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
515 return tape_do_io_free(device
, request
);
519 * MTNOP: 'No operation'.
522 tape_std_mtnop(struct tape_device
*device
, int mt_count
)
524 struct tape_request
*request
;
526 request
= tape_alloc_request(2, 0);
528 return PTR_ERR(request
);
529 request
->op
= TO_NOP
;
531 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
532 tape_ccw_end(request
->cpaddr
+ 1, NOP
, 0, NULL
);
534 return tape_do_io_free(device
, request
);
538 * MTEOM: positions at the end of the portion of the tape already used
539 * for recordind data. MTEOM positions after the last file mark, ready for
540 * appending another file.
543 tape_std_mteom(struct tape_device
*device
, int mt_count
)
548 * Seek from the beginning of tape (rewind).
550 if ((rc
= tape_mtop(device
, MTREW
, 1)) < 0)
554 * The logical end of volume is given by two sewuential tapemarks.
555 * Look for this by skipping to the next file (over one tapemark)
556 * and then test for another one (fsr returns 1 if a tapemark was
560 if ((rc
= tape_mtop(device
, MTFSF
, 1)) < 0)
562 if ((rc
= tape_mtop(device
, MTFSR
, 1)) < 0)
566 return tape_mtop(device
, MTBSR
, 1);
570 * MTRETEN: Retension the tape, i.e. forward space to end of tape and rewind.
573 tape_std_mtreten(struct tape_device
*device
, int mt_count
)
575 struct tape_request
*request
;
578 request
= tape_alloc_request(4, 0);
580 return PTR_ERR(request
);
581 request
->op
= TO_FSF
;
583 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
584 tape_ccw_cc(request
->cpaddr
+ 1,FORSPACEFILE
, 0, NULL
);
585 tape_ccw_cc(request
->cpaddr
+ 2, NOP
, 0, NULL
);
586 tape_ccw_end(request
->cpaddr
+ 3, CCW_CMD_TIC
, 0, request
->cpaddr
);
587 /* execute it, MTRETEN rc gets ignored */
588 rc
= tape_do_io_interruptible(device
, request
);
589 tape_free_request(request
);
590 return tape_mtop(device
, MTREW
, 1);
594 * MTERASE: erases the tape.
597 tape_std_mterase(struct tape_device
*device
, int mt_count
)
599 struct tape_request
*request
;
601 request
= tape_alloc_request(6, 0);
603 return PTR_ERR(request
);
604 request
->op
= TO_DSE
;
606 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
607 tape_ccw_cc(request
->cpaddr
+ 1, REWIND
, 0, NULL
);
608 tape_ccw_cc(request
->cpaddr
+ 2, ERASE_GAP
, 0, NULL
);
609 tape_ccw_cc(request
->cpaddr
+ 3, DATA_SEC_ERASE
, 0, NULL
);
610 tape_ccw_cc(request
->cpaddr
+ 4, REWIND
, 0, NULL
);
611 tape_ccw_end(request
->cpaddr
+ 5, NOP
, 0, NULL
);
614 return tape_do_io_free(device
, request
);
618 * MTUNLOAD: Rewind the tape and unload it.
621 tape_std_mtunload(struct tape_device
*device
, int mt_count
)
623 return tape_mtop(device
, MTOFFL
, mt_count
);
627 * MTCOMPRESSION: used to enable compression.
628 * Sets the IDRC on/off.
631 tape_std_mtcompression(struct tape_device
*device
, int mt_count
)
633 struct tape_request
*request
;
635 if (mt_count
< 0 || mt_count
> 1) {
636 DBF_EXCEPTION(6, "xcom parm\n");
637 if (*device
->modeset_byte
& 0x08)
638 PRINT_INFO("(%s) Compression is currently on\n",
639 device
->cdev
->dev
.bus_id
);
641 PRINT_INFO("(%s) Compression is currently off\n",
642 device
->cdev
->dev
.bus_id
);
643 PRINT_INFO("Use 1 to switch compression on, 0 to "
647 request
= tape_alloc_request(2, 0);
649 return PTR_ERR(request
);
650 request
->op
= TO_NOP
;
652 *device
->modeset_byte
= (mt_count
== 0) ? 0x00 : 0x08;
653 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
654 tape_ccw_end(request
->cpaddr
+ 1, NOP
, 0, NULL
);
656 return tape_do_io_free(device
, request
);
662 struct tape_request
*
663 tape_std_read_block(struct tape_device
*device
, size_t count
)
665 struct tape_request
*request
;
668 * We have to alloc 4 ccws in order to be able to transform request
669 * into a read backward request in error case.
671 request
= tape_alloc_request(4, 0);
672 if (IS_ERR(request
)) {
673 DBF_EXCEPTION(6, "xrbl fail");
676 request
->op
= TO_RFO
;
677 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
678 tape_ccw_end_idal(request
->cpaddr
+ 1, READ_FORWARD
,
679 device
->char_data
.idal_buf
);
680 DBF_EVENT(6, "xrbl ccwg\n");
685 * Read Block backward transformation function.
688 tape_std_read_backward(struct tape_device
*device
, struct tape_request
*request
)
691 * We have allocated 4 ccws in tape_std_read, so we can now
692 * transform the request to a read backward, followed by a
693 * forward space block.
695 request
->op
= TO_RBA
;
696 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
697 tape_ccw_cc_idal(request
->cpaddr
+ 1, READ_BACKWARD
,
698 device
->char_data
.idal_buf
);
699 tape_ccw_cc(request
->cpaddr
+ 2, FORSPACEBLOCK
, 0, NULL
);
700 tape_ccw_end(request
->cpaddr
+ 3, NOP
, 0, NULL
);
701 DBF_EVENT(6, "xrop ccwg");}
706 struct tape_request
*
707 tape_std_write_block(struct tape_device
*device
, size_t count
)
709 struct tape_request
*request
;
711 request
= tape_alloc_request(2, 0);
712 if (IS_ERR(request
)) {
713 DBF_EXCEPTION(6, "xwbl fail\n");
716 request
->op
= TO_WRI
;
717 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
718 tape_ccw_end_idal(request
->cpaddr
+ 1, WRITE_CMD
,
719 device
->char_data
.idal_buf
);
720 DBF_EVENT(6, "xwbl ccwg\n");
725 * This routine is called by frontend after an ENOSP on write
728 tape_std_process_eov(struct tape_device
*device
)
731 * End of volume: We have to backspace the last written record, then
732 * we TRY to write a tapemark and then backspace over the written TM
734 if (tape_mtop(device
, MTBSR
, 1) == 0 &&
735 tape_mtop(device
, MTWEOF
, 1) == 0) {
736 tape_mtop(device
, MTBSR
, 1);
740 EXPORT_SYMBOL(tape_std_assign
);
741 EXPORT_SYMBOL(tape_std_unassign
);
742 EXPORT_SYMBOL(tape_std_display
);
743 EXPORT_SYMBOL(tape_std_read_block_id
);
744 EXPORT_SYMBOL(tape_std_mtload
);
745 EXPORT_SYMBOL(tape_std_mtsetblk
);
746 EXPORT_SYMBOL(tape_std_mtreset
);
747 EXPORT_SYMBOL(tape_std_mtfsf
);
748 EXPORT_SYMBOL(tape_std_mtfsr
);
749 EXPORT_SYMBOL(tape_std_mtbsr
);
750 EXPORT_SYMBOL(tape_std_mtweof
);
751 EXPORT_SYMBOL(tape_std_mtbsfm
);
752 EXPORT_SYMBOL(tape_std_mtbsf
);
753 EXPORT_SYMBOL(tape_std_mtfsfm
);
754 EXPORT_SYMBOL(tape_std_mtrew
);
755 EXPORT_SYMBOL(tape_std_mtoffl
);
756 EXPORT_SYMBOL(tape_std_mtnop
);
757 EXPORT_SYMBOL(tape_std_mteom
);
758 EXPORT_SYMBOL(tape_std_mtreten
);
759 EXPORT_SYMBOL(tape_std_mterase
);
760 EXPORT_SYMBOL(tape_std_mtunload
);
761 EXPORT_SYMBOL(tape_std_mtcompression
);
762 EXPORT_SYMBOL(tape_std_read_block
);
763 EXPORT_SYMBOL(tape_std_read_backward
);
764 EXPORT_SYMBOL(tape_std_write_block
);
765 EXPORT_SYMBOL(tape_std_process_eov
);