1 /* $Id: tpqic02.c,v 0.4.1.5 1994/10/29 02:46:13 root Exp root $ 2 * 3 * Driver for tape drive support for Linux-i386 1.1.58 4 * 5 * Copyright (c) 1992, 1993, 1994 by H. H. Bergman. All rights reserved. 6 * Current e-mail address: hennus@sky.ow.org [This is a UUCP link.] 7 * [If you are unable to reach me directly, try the TAPE mailing list 8 * channel on linux-activists@niksula.hut.fi using "X-Mn-Key: TAPE" as 9 * the first line in your message.] 10 * 11 * Distribution of this program in executable form is only allowed if 12 * all of the corresponding source files are made available through the same 13 * medium at no extra cost. 14 * 15 * I will not accept any responsibility for damage caused directly or 16 * indirectly by this program, or code derived from this program. 17 * 18 * Use this code at your own risk. Don't blame me if it destroys your data! 19 * Make sure you have a backup before you try this code. 20 * 21 * If you make changes to my code and redistribute it in source or binary 22 * form you must make it clear to even casual users of your code that you 23 * have modified my code, clearly point out what the changes exactly are 24 * (preferably in the form of a context diff file), how to undo your changes, 25 * where the original can be obtained, and that complaints/requests about the 26 * modified code should be directed to you instead of me. 27 * 28 * This driver was partially inspired by the 'wt' driver in the 386BSD 29 * source distribution, which carries the following copyright notice: 30 * 31 * Copyright (c) 1991 The Regents of the University of California. 32 * All rights reserved. 33 * 34 * You are not allowed to change this line nor the text above. 35 * 36 * $Log: tpqic02.c,v $ 37 * Revision 0.4.1.5 1994/10/29 02:46:13 root 38 * Minor cleanups. 39 * 40 * Revision 0.4.1.4 1994/07/21 02:15:45 root 41 * ifdef'd DDI. Exception masks. 42 * 43 * Revision 0.4.1.3 1994/05/03 01:49:09 root 44 * Initial attempt at Mountain support for the Mountain 7150. 45 * Based on patches provided by Erik Jacobson. 46 * 47 * Revision 0.4.1.2 1994/03/18 21:16:50 root 48 * Many driver messages can now be turned off (runtime selectable). 49 * 50 * Revision 0.4.1.1 1994/02/16 19:47:22 root 51 * First stab at runtime debug-variable. 52 * 53 * Revision 0.4 1994/02/15 01:53:16 root 54 * DYNCONF mark II. 55 * Minor cleanups. 56 * 57 * Revision 0.3 1994/02/07 01:23:16 root 58 * More improved DYNCONF. 59 * Archive changes & some cleanups by Eddy Olk. 60 * Removed status_open, more cleanups, misc other. 61 * 62 * Revision 0.2.1.25 1994/01/24 02:01:33 root 63 * Changed tape_qic02 to QIC02_TAPE. 64 * Changes to prepare for DYNCONF. 65 * 66 * Revision 0.2.1.24 1994/01/23 07:27:18 root 67 * Attempt to remove compilation warnings, G++ bug, 68 * Linus changed TAPE_QIC02 to QIC02_TAPE. 69 * 70 * Revision 0.2.1.23 1994/01/20 23:49:28 root 71 * Changed some exception decoding stuff. 72 * TP_HAVE_SEEK, TP_HAVE_DENS. byte_swap_w() on arg, not global. 73 * Attempt to fix cartridge-changed-problem for 2150L. 74 * Release irq and dma reservations if initial reset fails. 75 * 76 * Revision 0.2.1.22 1994/01/19 20:56:55 root 77 * Speed measuring stuff moved from aperf.h to delay.h. 78 * BogoMips (tm) introduced by Linus. 79 * 80 * Revision 0.2.1.21 1993/06/18 19:04:33 root 81 * minor fixes for 0.99.10. 82 * 83 * Revision 0.2.1.20 1993/06/11 21:38:51 root 84 * Added exception code for status 0x8000 (Cypher weirdness). 85 * 86 * Revision 0.2.1.19 1993/04/19 23:13:59 root 87 * Cleanups. Changed to 0.99.8. 88 * 89 * Revision 0.2.1.18 1993/03/22 17:39:47 root 90 * Moved to 0.99.7. Added Archive MTSEEK and MTTELL support. 91 * 92 * Revision 0.2.1.17 1993/03/08 18:51:59 root 93 * Tried to `fix' write-once bug in previous release. 94 * 95 * Revision 0.2.1.16 1993/03/01 00:06:16 root 96 * Use register_chrdev() for 0.99.6. 97 * 98 * Revision 0.2.1.15 1993/02/25 00:14:25 root 99 * minor cleanups. 100 * 101 * Revision 0.2.1.14 1993/01/25 00:06:14 root 102 * Kernel udelay. Eof fixups. 103 * Removed report_ read/write dummies; have strace(1) now. 104 * 105 * Revision 0.2.1.13 1993/01/10 02:24:43 root 106 * Rewrote wait_for_ready() to use newer schedule() features. 107 * This improves performance for rewinds etc. 108 * 109 * Revision 0.2.1.12 1993/01/05 18:44:09 root 110 * Changes for 0.99.1. Fixed `restartable reads'. 111 * 112 * Revision 0.2.1.11 1992/11/28 01:19:10 root 113 * Changes to exception handling (significant). 114 * Changed returned error codes. Hopefully they're correct now. 115 * Changed declarations to please gcc-2.3.1. 116 * Patch to deal with bogus interrupts for Archive cards. 117 * 118 * Revision 0.2.1.10 1992/10/28 00:50:44 root 119 * underrun/error counter needed byte swapping. 120 * 121 * Revision 0.2.1.9 1992/10/15 17:06:01 root 122 * Removed online() stuff. Changed EOF handling. 123 * 124 * Revision 0.2.1.8 1992/10/02 22:25:48 root 125 * Removed `no_sleep' parameters (got usleep() now), 126 * cleaned up some comments. 127 * 128 * Revision 0.2.1.7 1992/09/27 01:41:55 root 129 * Changed write() to do entire user buffer in one go, rather than just 130 * a kernel-buffer sized portion each time. 131 * 132 * Revision 0.2.1.6 1992/09/21 02:15:30 root 133 * Introduced udelay() function for microsecond-delays. 134 * Trying to use get_dma_residue rather than TC flags. 135 * Patch to fill entire user buffer on reads before 136 * returning. 137 * 138 * Revision 0.2.1.5 1992/09/19 02:31:28 root 139 * Some changes based on patches by Eddy Olk to 140 * support Archive SC402/SC499R controller cards. 141 * 142 * Revision 0.2.1.4 1992/09/07 01:37:37 root 143 * Minor changes 144 * 145 * Revision 0.2.1.3 1992/08/13 00:11:02 root 146 * Added some support for Archive SC402 and SC499 cards. 147 * (Untested.) 148 * 149 * Revision 0.2.1.2 1992/08/10 02:02:36 root 150 * Changed from linux/system.h macros to asm/dma.h inline functions. 151 * 152 * Revision 0.2.1.1 1992/08/08 01:12:39 root 153 * cleaned up a bit. added stuff for selftesting. 154 * preparing for asm/dma.h instead of linux/system.h 155 * 156 * Revision 0.2 1992/08/03 20:11:30 root 157 * Changed to use new IRQ allocation. Padding now done at runtime, pads to 158 * 512 bytes. Because of this the page regs must be re-programmed every 159 * block! Added hooks for selftest commands. 160 * Moved to linux-0.97. 161 * 162 * Revision 0.1.0.5 1992/06/22 22:20:30 root 163 * moved to Linux 0.96b 164 * 165 * Revision 0.1.0.4 1992/06/18 02:00:04 root 166 * Use minor bit-7 to enable/disable printing of extra debugging info 167 * when do tape access. 168 * Added semop stuff for DMA/IRQ allocation checking. Don't think this 169 * is the right way to do it though. 170 * 171 * Revision 0.1.0.3 1992/06/01 01:57:34 root 172 * changed DRQ to DMA. added TDEBUG ifdefs to reduce output. 173 * 174 * Revision 0.1.0.2 1992/05/31 14:02:38 root 175 * changed SET_DMA_PAGE handling slightly. 176 * 177 * Revision 0.1.0.1 1992/05/27 12:12:03 root 178 * Can now use multiple files on tape (sort of). 179 * First release. 180 * 181 * Revision 0.1 1992/05/26 01:16:31 root 182 * Initial version. Copyright H. H. Bergman 1992 183 * 184 */ 185
186 /* After the legalese, now the important bits: 187 * 188 * This is a driver for the Wangtek 5150 tape drive with 189 * a QIC-02 controller for ISA-PC type computers. 190 * Hopefully it will work with other QIC-02 tape drives as well. 191 * 192 * Make sure your setup matches the configuration parameters. 193 * Also, be careful to avoid IO conflicts with other devices! 194 */ 195
196 #include <linux/autoconf.h>
197
198
199 /* 200 #define TDEBUG 201 */ 202
203 #defineREALLY_SLOW_IO/* it sure is ... */ 204
205 #include <linux/sched.h>
206 #include <linux/timer.h>
207 #include <linux/fs.h>
208 #include <linux/kernel.h>
209 #include <linux/major.h>
210 #include <linux/errno.h>
211 #include <linux/mtio.h>
212 #include <linux/fcntl.h>
213 #include <linux/delay.h>
214 #include <linux/tpqic02.h>
215 #include <linux/config.h>
216
217 #include <asm/dma.h>
218 #include <asm/system.h>
219 #include <asm/io.h>
220 #include <asm/segment.h>
221
222 /* check existence of required configuration parameters */ 223 #if !defined(QIC02_CMD_PORT) || \
224 !defined(QIC02_TAPE_IRQ) || \
225 !defined(QIC02_TAPE_DMA)
226 #error qic02_tape configuration error
227 #endif 228
229
230 #defineTPQIC02_NAME "tpqic02"
231
232 /* Linux outb() commands have (value,port) as parameters. 233 * One might expect (port,value) instead, so beware! 234 */ 235
236 #ifdefCONFIG_QIC02_DYNCONF 237 /* This holds the dynamic configuration info for the interface 238 * card+drive info if runtime configuration has been selected. 239 */ 240 structmtconfiginfoqic02_tape_dynconf = { 0, }; /* user settable */ 241 structqic02_ccbqic02_tape_ccb = { 0, }; /* private stuff */ 242
243 #else 244
245 unsignedlongqic02_tape_debug;
246
247 # if ((QIC02_TAPE_IFC!=WANGTEK) && (QIC02_TAPE_IFC!=ARCHIVE) && (QIC02_TAPE_IFC!=MOUNTAIN))
248 # error No valid interface card specified
249 # endif 250 #endif 251
252 staticvolatileintctlbits = 0; /* control reg bits for tape interface */ 253
254 staticstructwait_queue *qic02_tape_transfer = NULL; /* sync rw with interrupts */ 255
256 staticvolatilestructmtgetioctl_status; /* current generic status */ 257
258 staticvolatilestructtpstatustperror; /* last drive status */ 259
260 staticcharrcs_revision[] = "$Revision: 0.4.1.5 $";
261 staticcharrcs_date[] = "$Date: 1994/10/29 02:46:13 $";
262
263 /* Flag bits for status and outstanding requests. 264 * (Could all be put in one bit-field-struct.) 265 * Some variables need `volatile' because they may be modified 266 * by an interrupt. 267 */ 268 staticvolatileflagstatus_dead = YES; /* device is legally dead until proven alive */ 269 staticflagstatus_zombie = YES; /* it's `zombie' until irq/dma allocated */ 270
271 staticvolatileflagstatus_bytes_wr = NO; /* write FM at close or not */ 272 staticvolatileflagstatus_bytes_rd = NO; /* (rd|wr) used for rewinding */ 273
274 staticvolatileunsignedlongstatus_cmd_pending = 0; /* cmd in progress */ 275 staticvolatileflagstatus_expect_int = NO; /* ready for interrupts */ 276 staticvolatileflagstatus_timer_on = NO; /* using time-out */ 277 staticvolatileintstatus_error = 0; /* int handler may detect error */ 278 staticvolatileflagstatus_eof_detected = NO; /* end of file */ 279 staticvolatileflagstatus_eom_detected = NO; /* end of recorded media */ 280 staticvolatileflagstatus_eot_detected = NO; /* end of tape */ 281 staticvolatileflagdoing_read = NO;
282 staticvolatileflagdoing_write = NO;
283
284 staticvolatileunsignedlongdma_bytes_todo;
285 staticvolatileunsignedlongdma_bytes_done;
286 staticvolatileunsigneddma_mode = 0; /* !=0 also means DMA in use */ 287 staticflagneed_rewind = YES;
288
289 staticdev_tcurrent_tape_dev = MKDEV(QIC02_TAPE_MAJOR, 0);
290 staticintextra_blocks_left = BLOCKS_BEYOND_EW;
291
292
293 /* return_*_eof: 294 * NO: not at EOF, 295 * YES: tell app EOF was reached (return 0). 296 * 297 * return_*_eof==YES && reported_*_eof==NO ==> 298 * return current buffer, next time(s) return EOF. 299 * 300 * return_*_eof==YES && reported_*_eof==YES ==> 301 * at EOF and application knows it, so we can 302 * move on to the next file. 303 * 304 */ 305 staticflagreturn_read_eof = NO; /* set to signal app EOF was reached */ 306 staticflagreturn_write_eof = NO;
307 staticflagreported_read_eof = NO; /* set when we've done that */ 308 staticflagreported_write_eof = NO;
309
310
311 /* This is for doing `mt seek <blocknr>' */ 312 staticcharseek_addr_buf[AR_SEEK_BUF_SIZE];
313
314
315 /* In write mode, we have to write a File Mark after the last block written, 316 * when the tape device is closed. Tape repositioning and reading in write 317 * mode is allowed as long as no actual writing has been done. After writing 318 * the File Mark, repositioning and reading are allowed again. 319 */ 320 staticintmode_access; /* access mode: READ or WRITE */ 321
322
323 /* This is the actual kernel buffer where the interrupt routines read 324 * from/write to. It is needed because the DMA channels 1 and 3 cannot 325 * always access the user buffers. [The kernel buffer must reside in the 326 * lower 16MBytes of system memory because of the DMA controller.] 327 * The user must ensure that a large enough buffer is passed to the 328 * kernel, in order to reduce tape repositioning. 329 * 330 * The buffer is 512 bytes larger than expected, because I want to align it 331 * at 512 bytes, to prevent problems with 64k boundaries. 332 */ 333
334 staticvolatilecharqic02_tape_buf[TPQBUF_SIZE+TAPE_BLKSIZE];
335 /* A really good compiler would be able to align this at 512 bytes... :-( */ 336
337 staticunsignedlongbuffaddr; /* aligned physical address of buffer */ 338
339
340 /* This translates minor numbers to the corresponding recording format: */ 341 staticchar *format_names[] = { 342 "not set", /* for dumb drives unable to handle format selection */ 343 "11", /* extinct */ 344 "24",
345 "120",
346 "150",
347 "300", /* untested. */ 348 "600" /* untested. */ 349 };
350
351
352 /* `exception_list' is needed for exception status reporting. 353 * Exceptions 1..14 are defined by QIC-02 rev F. 354 * The drive status is matched sequentially to each entry, 355 * ignoring irrelevant bits, until a match is found. If no 356 * match is found, exception number 0 is used. (That should of 357 * course never happen...) The original table was based on the 358 * "Exception Status Summary" in QIC-02 rev F, but some changes 359 * were required to make it work with real-world drives. 360 * 361 * Exception 2 (CNI) is changed to also cover status 0x00e0 (mask USL), 362 * Exception 4 (EOM) is changed to also cover status 0x8288 (mask EOR), 363 * Exception 11 (FIL) is changed to also cover status 0x0089 (mask EOM). 364 * Exception 15 (EOR) is added for seek-to-end-of-data (catch EOR), 365 * Exception 16 (BOM) is added for beginning-of-media (catch BOM). 366 * 367 * Had to swap EXC_NDRV and EXC_NCART to ensure that extended EXC_NCART 368 * (because of the incorrect Wangtek status code) doesn't catch the 369 * EXC_NDRV first. 370 */ 371 staticstructexception_list_type{ 372 unsignedshortmask, code;
373 char *msg;
374 /* EXC_nr attribute should match with tpqic02.h */ 375 }exception_list[] = { 376 {0, 0,
377 "Unknown exception status code", /* extra: 0 */},
378 {~(0), TP_ST0|TP_CNI|TP_USL|TP_WRP,
379 "Drive not online" /* 1 */},
380 /* Drive presence goes before cartridge presence. */ 381 {~(TP_WRP|TP_USL), TP_ST0|TP_CNI,
382 /* My Wangtek 5150EQ sometimes reports a status code 383 * of 0x00e0, which is not a valid exception code, but 384 * I think it should be recognized as "NO CARTRIDGE". 385 */ 386 "Cartridge not in place" /* 2 */},
387 {(unsignedshort) ~(TP_ST1|TP_BOM), (TP_ST0|TP_WRP),
388 "Write protected cartridge" /* 3 */},
389 {(unsignedshort) ~(TP_ST1|TP_EOR), (TP_ST0|TP_EOM),
390 "End of media" /* 4 */},
391 {~TP_WRP, TP_ST0|TP_UDA| TP_ST1|TP_BOM,
392 "Read or Write abort. Rewind tape." /* 5 */},
393 {~TP_WRP, TP_ST0|TP_UDA,
394 "Read error. Bad block transferred." /* 6 */},
395 {~TP_WRP, TP_ST0|TP_UDA|TP_BNL,
396 "Read error. Filler block transferred." /* 7 */},
397 {~TP_WRP, TP_ST0|TP_UDA|TP_BNL |TP_ST1|TP_NDT,
398 "Read error. No data detected." /* 8 */},
399 {~TP_WRP, TP_ST0|TP_EOM|TP_UDA|TP_BNL |TP_ST1|TP_NDT,
400 "Read error. No data detected. EOM." /* 9 */},
401 {~(TP_WRP|TP_MBD|TP_PAR|TP_EOR), TP_ST0|TP_UDA|TP_BNL |TP_ST1|TP_NDT|TP_BOM,
402 "Read error. No data detected. BOM." /* 10 */},
403 {~(TP_WRP|TP_EOM), TP_ST0|TP_FIL,
404 /* Status 0x0089 (EOM & FM) is viewed as an FM, 405 * because it can only happen during a read. 406 * EOM is checked separately for an FM condition. 407 */ 408 "File mark detected" /* 11 */},
409 {~(TP_ST0|TP_CNI|TP_USL|TP_WRP|TP_BOM), TP_ST1|TP_ILL,
410 "Illegal command" /* 12 */},
411 {~(TP_ST0|TP_CNI|TP_USL|TP_WRP|TP_BOM), TP_ST1|TP_POR,
412 "Reset occurred" /* 13 */},
413 {~TP_WRP, TP_ST0|TP_FIL|TP_MBD, /* NOTE: ST1 not set! */ 414 "Marginal block detected" /* 14 */},
415 {~(TP_ST0|TP_WRP|TP_EOM|TP_UDA|TP_BNL|TP_FIL |TP_NDT), TP_ST1|TP_EOR,
416 /********** Is the extra TP_NDT really needed Eddy? **********/ 417 "End of recorded media" /* extra: 15 */},
418 /* 15 is returned when SEEKEOD completes successfully */ 419 {~(TP_WRP|TP_ST0), TP_ST1|TP_BOM,
420 "Beginning of media" /* extra: 16 */} 421 };
422 #defineNR_OF_EXC (sizeof(exception_list)/sizeof(structexception_list_type))
423
424
425
426 staticvoidtpqputs(unsignedlongflags, char *s)
427 { 428 if ((flags & TPQD_ALWAYS) || (flags & QIC02_TAPE_DEBUG))
429 printk(TPQIC02_NAME ": %s\n", s);
430 }/* tpqputs */ 431
432
433
434
435 /* Perform byte order swapping for a 16-bit word. 436 * 437 * [FIXME] This should probably be in include/asm/ 438 * ([FIXME] i486 can do this faster) 439 */ 440 staticinlinevoidbyte_swap_w(volatileunsignedshort * w)
/* */ 441 { 442 intt = *w;
443
444 *w = (t>>8) | ((t & 0xff)<<8);
445 } 446
447
448
449 /* Init control register bits on interface card. 450 * For Archive, interrupts must be enabled explicitly. 451 * Wangtek interface card requires ONLINE to be set, Archive SC402/SC499R 452 * cards keep it active all the time. 453 */ 454 staticvoidifc_init(void)
/* */ 455 { 456 if (QIC02_TAPE_IFC == WANGTEK) /* || (QIC02_TAPE_IFC == EVEREX) */{ 457 ctlbits = WT_CTL_ONLINE; /* online */ 458 outb_p(ctlbits, QIC02_CTL_PORT);
459
460 }elseif (QIC02_TAPE_IFC == ARCHIVE) { 461 ctlbits = 0; /* no interrupts yet */ 462 outb_p(ctlbits, QIC02_CTL_PORT);
463 outb_p(0, AR_RESET_DMA_PORT); /* dummy write to reset DMA */ 464
465 }else/* MOUNTAIN */{ 466 ctlbits = MTN_CTL_ONLINE; /* online, and logic enabled */ 467 outb_p(ctlbits, QIC02_CTL_PORT);
468 } 469 }/* ifc_init */ 470
471
472 staticvoidreport_exception(unsignedn)
/* */ 473 { 474 if (n >= NR_OF_EXC) {tpqputs(TPQD_ALWAYS, "Oops -- report_exception"); n = 0; } 475 if (TPQDBG(SENSE_TEXT) || n==0)
476 printk(TPQIC02_NAME ": sense: %s\n", exception_list[n].msg);
477 }/* report_exception */ 478
479
480 /* Try to map the drive-exception bits `s' to a predefined "exception number", 481 * by comparing the significant exception bits for each entry in the 482 * exception table (`exception_list[]'). 483 * It is assumed that s!=0. 484 */ 485 staticintdecode_exception_nr(unsigneds)
/* */ 486 { 487 inti;
488
489 for (i=1; i<NR_OF_EXC; i++) { 490 if ((s & exception_list[i].mask)==exception_list[i].code)
491 returni;
492 } 493 printk(TPQIC02_NAME ": decode_exception_nr: exception(%x) not recognized\n", s);
494 return 0;
495 }/* decode_exception_nr */ 496
497
498 #ifdefOBSOLETE 499 /* There are exactly 14 possible exceptions, as defined in QIC-02 rev F. 500 * Some are FATAL, some aren't. Currently all exceptions are treated as fatal. 501 * Especially 6 and 14 should not abort the transfer. RSN... 502 * Should probably let sense() figure out the exception number using the code 503 * below, and just report the error based on the number here, returning a code 504 * for FATAL/CONTINUABLE. 505 */ 506 staticvoid report_error(ints)
/* */ 507 { 508 shortn = -1;
509
510 if (s & TP_ST1) { 511 if (s & TP_ILL) /* 12: Illegal command. FATAL */ 512 n = 12;
513 if (s & TP_POR) /* 13: Reset occurred. FATAL */ 514 n = 13;
515 } 516 elseif (s & TP_ST0) { 517 if (s & TP_EOR) {/* extra: 15: End of Recorded Media. CONTINUABLE */ 518 n = 15;
519 /********** should set flag here **********/ 520 } 521 elseif (s & TP_EOM) /* 4: End Of Media. CONTINUABLE */ 522 n = 4;
523 elseif (s & TP_USL) /* 2: Drive not online. FATAL */ 524 n = 2;
525 elseif (s & TP_CNI) {/* 1: Cartridge not in place. FATAL */ 526 n = 1;
527 need_rewind = YES;
528 status_eof_detected = NO;
529 status_eom_detected = NO;
530 } 531 elseif (s & TP_UDA) { 532 if (s & TP_BNL) { 533 if (s & TP_NDT) { 534 if (s & TP_BOM) /* 9: Read error. No data detected & EOM. CONTINUABLE */ 535 n = 9;
536 elseif (s & TP_EOM) /* 10: Read error. No data detected & BOM. CONTINUABLE */ 537 n = 10;
538 else/* 8: Read error. No data detected. CONTINUABLE */ 539 n = 8;
540 }else{/* 7: Read error. Cannot recover block, filler substituted. CONTINUABLE */ 541 tpqputs(TPQD_ALWAYS, "[Bad block -- filler data transferred.]");
542 n = 7;
543 } 544 } 545 else{ 546 if (s & TP_EOM) /* 5: Read or Write error. Rewind tape. FATAL */ 547 n = 5;
548 else{/* 6: Read error. Bad block transferred. CONTINUABLE */ 549 /* block is bad, but transfer may continue. 550 * This is why some people prefer not to 551 * use compression on backups... 552 */ 553 tpqputs(TPQD_ALWAYS, "[CRC failed!]");
554 n = 6;
555 } 556 } 557 } 558 elseif (s & TP_FIL) { 559 if (s & TP_MBD) {/* 14: Marginal block detected. CONTINUABLE */ 560 tpqputs(TPQD_ALWAYS, "[Marginal block]");
561 n = 14;
562 }else/* 11: File mark detected. CONTINUABLE */ 563 n = 11;
564 } 565 elseif (s & TP_WRP) /* 3: Write protected cartridge. FATAL */ 566 n = 3;
567 } 568 if (n >= 0)
569 sensemsg(n);
570 }/* report_error */ 571 #endif 572
573
574 /* Perform appropriate action for certain exceptions. 575 * should return a value to indicate stop/continue (in case of bad blocks) 576 */ 577 staticvoidhandle_exception(intexnr, int exbits)
/* */ 578 { 579 if (exnr==EXC_NCART) { 580 /* Cartridge was changed. Redo sense(). 581 * EXC_NCART should be handled in open(). 582 * It is not permitted to remove the tape while 583 * the tape driver has open files. 584 */ 585 need_rewind = YES;
586 status_eof_detected = NO;
587 status_eom_detected = NO;
588 } 589 elseif (exnr==EXC_XFILLER)
590 tpqputs(TPQD_ALWAYS, "[Bad block -- filler data transferred.]");
591 elseif (exnr==EXC_XBAD)
592 tpqputs(TPQD_ALWAYS, "[CRC failed!]");
593 elseif (exnr==EXC_MARGINAL) { 594 /* A marginal block behaves much like a FM. 595 * User may continue reading, if desired. 596 */ 597 tpqputs(TPQD_ALWAYS, "[Marginal block]");
598 doing_read = NO;
599 }elseif (exnr==EXC_FM)
600 doing_read = NO;
601 }/* handle_exception */ 602
603
604 staticinlineintis_exception(void)
/* */ 605 { 606 return (inb(QIC02_STAT_PORT) & QIC02_STAT_EXCEPTION) == 0;
607 }/* is_exception */ 608
609
610 /* Reset the tape drive and controller. 611 * When reset fails, it marks the drive as dead and all 612 * requests (except reset) are to be ignored (ENXIO). 613 */ 614 staticinttape_reset(intverbose)
/* */ 615 { 616 ifc_init(); /* reset interface card */ 617
618 /* assert reset */ 619 if (QIC02_TAPE_IFC == MOUNTAIN)
620 outb_p(ctlbits & ~MTN_QIC02_CTL_RESET_NOT, QIC02_CTL_PORT);
621 else/* WANGTEK, ARCHIVE */ 622 outb_p(ctlbits | QIC02_CTL_RESET, QIC02_CTL_PORT);
623
624 /* Next, we need to wait >=25 usec. */ 625 udelay(30);
626
627 /* after reset, we will be at BOT (modulo an automatic rewind) */ 628 status_eof_detected = NO;
629 status_eom_detected = NO;
630 status_cmd_pending = 0;
631 need_rewind = YES;
632 doing_read = doing_write = NO;
633 ioctl_status.mt_fileno = ioctl_status.mt_blkno = 0;
634
635 /* de-assert reset */ 636 if (QIC02_TAPE_IFC == MOUNTAIN)
637 outb_p(ctlbits | MTN_QIC02_CTL_RESET_NOT, QIC02_CTL_PORT);
638 else 639 outb_p(ctlbits & ~QIC02_CTL_RESET, QIC02_CTL_PORT);
640
641 /* KLUDGE FOR G++ BUG */ 642 {intstat = inb_p(QIC02_STAT_PORT);
643 status_dead = ((stat & QIC02_STAT_RESETMASK) != QIC02_STAT_RESETVAL); } 644 /* if successful, inb(STAT) returned RESETVAL */ 645 if (status_dead == YES)
646 printk(TPQIC02_NAME ": reset failed!\n");
647 elseif (verbose)
648 printk(TPQIC02_NAME ": reset successful\n");
649
650 return (status_dead == YES)? TE_DEAD : TE_OK;
651 }/* tape_reset */ 652
653
654
655 /* Notify tape drive of a new command. It only waits for the 656 * command to be accepted, not for the actual command to complete. 657 * 658 * Before calling this routine, QIC02_CMD_PORT must have been loaded 659 * with the command to be executed. 660 * After this routine, the exception bit must be checked. 661 * This routine is also used by rdstatus(), so in that case, any exception 662 * must be ignored (`ignore_ex' flag). 663 */ 664 staticintnotify_cmd(charcmd, shortignore_ex)
/* */ 665 { 666 inti;
667
668 outb_p(cmd, QIC02_CMD_PORT); /* output the command */ 669
670 /* wait 1 usec before asserting /REQUEST */ 671 udelay(1);
672
673 if ((!ignore_ex) && is_exception()) { 674 tpqputs(TPQD_ALWAYS, "*** exception detected in notify_cmd");
675 /** force a reset here **/ 676 if (tape_reset(1)==TE_DEAD)
677 returnTE_DEAD;
678 if (is_exception()) { 679 tpqputs(TPQD_ALWAYS, "exception persists after reset.");
680 tpqputs(TPQD_ALWAYS, " ^ exception ignored.");
681 } 682 } 683
684 outb_p(ctlbits | QIC02_CTL_REQUEST, QIC02_CTL_PORT); /* set request bit */ 685 i = TAPE_NOTIFY_TIMEOUT;
686 /* The specs say this takes about 500 usec, but there is no upper limit! 687 * If the drive were busy retensioning or something like that, 688 * it could be *much* longer! 689 */ 690 while ((inb_p(QIC02_STAT_PORT) & QIC02_STAT_READY) && (--i>0))
691 /*skip*/; /* wait for ready */ 692 if (i==0) { 693 tpqputs(TPQD_ALWAYS, "timed out waiting for ready in notify_cmd");
694 status_dead = YES;
695 returnTE_TIM;
696 } 697
698 outb_p(ctlbits & ~QIC02_CTL_REQUEST, QIC02_CTL_PORT); /* reset request bit */ 699 i = TAPE_NOTIFY_TIMEOUT;
700 /* according to the specs this one should never time-out */ 701 while (((inb_p(QIC02_STAT_PORT) & QIC02_STAT_READY) == 0) && (--i>0))
702 /*skip*/; /* wait for not ready */ 703 if (i==0) { 704 tpqputs(TPQD_ALWAYS, "timed out waiting for !ready in notify_cmd");
705 status_dead = YES;
706 returnTE_TIM;
707 } 708 /* command accepted */ 709 returnTE_OK;
710 }/* notify_cmd */ 711
712
713
714 /* Wait for a command to complete, with timeout */ 715 staticintwait_for_ready(time_ttimeout)
/* */ 716 { 717 intstat;
718 time_tspin_t;
719
720 /* Wait for ready or exception, without driving the loadavg up too much. 721 * In most cases, the tape drive already has READY asserted, 722 * so optimize for that case. 723 * 724 * First, busy wait a few usec: 725 */ 726 spin_t = 50;
727 while (((stat = inb_p(QIC02_STAT_PORT) & QIC02_STAT_MASK) == QIC02_STAT_MASK) && (--spin_t>0))
728 /*SKIP*/;
729 if ((stat & QIC02_STAT_READY) == 0)
730 returnTE_OK; /* covers 99.99% of all calls */ 731
732 /* Then use schedule() a few times */ 733 spin_t = 3; /* max 0.03 sec busy waiting */ 734 if (spin_t > timeout)
735 spin_t = timeout;
736 timeout -= spin_t;
737 spin_t += jiffies;
738
739 while (((stat = inb_p(QIC02_STAT_PORT) & QIC02_STAT_MASK) == QIC02_STAT_MASK) && (jiffies<spin_t))
740 schedule(); /* don't waste all the CPU time */ 741 if ((stat & QIC02_STAT_READY) == 0)
742 returnTE_OK;
743
744 /* If we reach this point, we probably need to wait much longer, or 745 * an exception occurred. Either case is not very time-critical. 746 * Check the status port only a few times every second. 747 * A interval of less than 0.10 sec will not be noticed by the user, 748 * more than 0.40 sec may give noticeable delays. 749 */ 750 spin_t += timeout;
751 TPQDEB({printk("wait_for_ready: additional timeout: %d\n", spin_t);})
752
753 /* not ready and no exception && timeout not expired yet */ 754 while (((stat = inb_p(QIC02_STAT_PORT) & QIC02_STAT_MASK) == QIC02_STAT_MASK) && (jiffies<spin_t)) { 755 /* be `nice` to other processes on long operations... */ 756 current->timeout = jiffies + 30; /* nap 0.30 sec between checks, */ 757 current->state = TASK_INTERRUPTIBLE;
758 schedule(); /* but could be woken up earlier by signals... */ 759 } 760
761 /* don't use jiffies for this test because it may have changed by now */ 762 if ((stat & QIC02_STAT_MASK) == QIC02_STAT_MASK) { 763 tpqputs(TPQD_ALWAYS, "wait_for_ready() timed out");
764 returnTE_TIM;
765 } 766
767 if ((stat & QIC02_STAT_EXCEPTION) == 0) { 768 tpqputs(TPQD_ALWAYS, "exception detected after waiting_for_ready");
769 returnTE_EX;
770 }else{ 771 returnTE_OK;
772 } 773 }/* wait_for_ready */ 774
775
776
777 /* Send some data to the drive */ 778 staticintsend_qic02_data(charsb[], unsignedsize, intignore_ex)
/* */ 779 { 780 inti, stat;
781
782 for (i=0; i<size; i++) { 783
784 stat = wait_for_ready(TIM_S);
785 if (stat != TE_OK)
786 returnstat;
787
788 stat = notify_cmd(sb[i], ignore_ex);
789 if (stat != TE_OK)
790 returnstat;
791 } 792 returnTE_OK;
793
794 }/* send_qic02_data */ 795
796
797 /* Send a QIC-02 command (`cmd') to the tape drive, with 798 * a time-out (`timeout'). 799 * This one is also used by tp_sense(), so we must have 800 * a flag to disable exception checking (`ignore_ex'). 801 * 802 * On entry, the controller is supposed to be READY. 803 */ 804 staticintsend_qic02_cmd(intcmd, time_ttimeout, intignore_ex)
/* */ 805 { 806 intstat;
807
808 stat = inb_p(QIC02_STAT_PORT);
809 if ((stat & QIC02_STAT_EXCEPTION) == 0) {/* if exception */ 810 tpqputs(TPQD_ALWAYS, "send_qic02_cmd: Exception!");
811 returnTE_EX;
812 } 813 if (stat & QIC02_STAT_READY) {/* if not ready */ 814 tpqputs(TPQD_ALWAYS, "send_qic02_cmd: not Ready!");
815 returnTE_ERR;
816 } 817
818 /* assert(ready & !exception) */ 819
820 /* Remember current command for later re-use with dma transfers. 821 * (For reading/writing multiple blocks.) 822 */ 823 status_cmd_pending = cmd;
824
825 stat = notify_cmd(cmd, ignore_ex); /* tell drive new command was loaded, */ 826 /* inherit exception check. */ 827 if (TP_HAVE_SEEK && (cmd == AR_QCMDV_SEEK_BLK)) { 828 /* This one needs to send 3 more bytes, MSB first */ 829 stat = send_qic02_data(seek_addr_buf, sizeof(seek_addr_buf), ignore_ex);
830 } 831
832 if (stat != TE_OK) { 833 tpqputs(TPQD_ALWAYS, "send_qic02_cmd failed");
834 } 835 returnstat;
836 }/* send_qic02_cmd */ 837
838
839
840 /* Get drive status. Assume drive is ready or has exception set. 841 * (or will be in <1000 usec.) 842 * Extra parameters added because of 'Read Extended Status 3' command. 843 */ 844 staticintrdstatus(char *stp, unsignedsize, charqcmd)
/* */ 845 { 846 ints, n;
847 char *q = stp;
848
849 /* Try to busy-wait a few (700) usec, after that de-schedule. 850 * 851 * The problem is, if we don't de-schedule, performance will 852 * drop to zero when the drive is not responding and if we 853 * de-schedule immediately, we waste a lot of time because a 854 * task switch is much longer than we usually have to wait here. 855 */ 856 n = 1000; /* 500 is not enough on a 486/33 */ 857 while ((n>0) && ((inb_p(QIC02_STAT_PORT) & QIC02_STAT_MASK) == QIC02_STAT_MASK))
858 n--; /* wait for ready or exception or timeout */ 859 if (n==0) { 860 /* n (above) should be chosen such that on your machine 861 * you rarely ever see the message below, and it should 862 * be small enough to give reasonable response time.] 863 */ 864 tpqputs(TPQD_ALWAYS, "waiting looong in rdstatus() -- drive dead?");
865 while ((inb_p(QIC02_STAT_PORT) & QIC02_STAT_MASK) == QIC02_STAT_MASK)
866 schedule();
867 tpqputs(TPQD_ALWAYS, "finished waiting in rdstatus()");
868 } 869
870 (void) notify_cmd(qcmd, 1); /* send read status command */ 871 /* ignore return code -- should always be ok, STAT may contain 872 * exception flag from previous exception which we are trying to clear. 873 */ 874
875 if (TP_DIAGS(current_tape_dev))
876 printk(TPQIC02_NAME ": reading status bytes: ");
877
878 for (q=stp; q<stp+size; q++)
879 { 880 dos = inb_p(QIC02_STAT_PORT);
881 while ((s & QIC02_STAT_MASK) == QIC02_STAT_MASK); /* wait for ready or exception */ 882
883 if ((s & QIC02_STAT_EXCEPTION) == 0) {/* if exception */ 884 tpqputs(TPQD_ALWAYS, "rdstatus: exception error");
885 ioctl_status.mt_erreg = 0; /* dunno... */ 886 returnTE_NS; /* error, shouldn't happen... */ 887 } 888
889 *q = inb_p(QIC02_DATA_PORT); /* read status byte */ 890
891 if (TP_DIAGS(current_tape_dev))
892 printk("[%1d]=0x%x ", q-stp, (unsigned) (*q) & 0xff);
893
894 outb_p(ctlbits | QIC02_CTL_REQUEST, QIC02_CTL_PORT); /* set request */ 895
896 while ((inb_p(QIC02_STAT_PORT) & QIC02_STAT_READY) == 0); /* wait for not ready */ 897
898 udelay(22); /* delay >20 usec */ 899
900 outb_p(ctlbits & ~QIC02_CTL_REQUEST, QIC02_CTL_PORT); /* un-set request */ 901
902 } 903
904 /* Specs say we should wait for READY here. 905 * My drive doesn't seem to need it here yet, but others do? 906 */ 907 while (inb_p(QIC02_STAT_PORT) & QIC02_STAT_READY)
908 /*skip*/; /* wait for ready */ 909
910 if (TP_DIAGS(current_tape_dev))
911 printk("\n");
912
913 returnTE_OK;
914 }/* rdstatus */ 915
916
917
918 /* Get standard status (6 bytes). 919 * The `.dec' and `.urc' fields are in MSB-first byte-order, 920 * so they have to be swapped first. 921 */ 922 staticintget_status(volatilestructtpstatus *stp)
/* */ 923 { 924 intstat = rdstatus((char *) stp, TPSTATSIZE, QCMD_RD_STAT);
925 #ifdefined(i386) || defined(i486)
926 byte_swap_w(&(stp->dec));
927 byte_swap_w(&(stp->urc));
928 #else 929 /* should probably swap status bytes #definition */ 930 #endif 931 returnstat;
932 }/* get_status */ 933
934
935 #if 0
936 /* This fails for my Wangtek drive */ 937 /* get "Extended Status Register 3" (64 bytes) 938 * 939 * If the meaning of the returned bytes were known, the MT_TYPE 940 * identifier could be used to decode them, since they are 941 * "vendor unique". :-( 942 */ 943 staticint get_ext_status3(void)
/* */ 944 { 945 charvus[64]; /* vendor unique status */ 946 intstat, i;
947
948 tpqputs(TPQD_ALWAYS, "Attempting to read Extended Status 3...");
949 stat = rdstatus(vus, sizeof(vus), QCMD_RD_STAT_X3);
950 if (stat != TE_OK)
951 returnstat;
952
953 tpqputs(TPQD_ALWAYS, "Returned status bytes:");
954 for (i=0; i<sizeof(vus); i++) { 955 if ( i % 8 == 0 )
956 printk("\n" TPQIC02_NAME ": %2d:");
957 printk(" %2x", vus[i] & 0xff);
958 } 959 printk("\n");
960
961 returnTE_OK;
962 }/* get_ext_status3 */ 963 #endif 964
965
966 /* Read drive status and set generic status too. 967 * NOTE: Once we do a tp_sense(), read/write transfers are killed. 968 */ 969 staticinttp_sense(intignore)
/* */ 970 { 971 unsignederr = 0, exnr = 0, gs = 0;
972 staticvoidfinish_rw(intcmd);
973
974 if (TPQDBG(SENSE_TEXT))
975 printk(TPQIC02_NAME ": tp_sense(ignore=0x%x) enter\n", ignore);
976
977 /* sense() is not allowed during a read or write cycle */ 978 if (doing_write == YES)
979 tpqputs(TPQD_ALWAYS, "Warning: File Mark inserted because of sense() request");
980 /* The extra test is to avoid calling finish_rw during booting */ 981 if ((doing_read!=NO) || (doing_write!=NO))
982 finish_rw(QCMD_RD_STAT);
983
984 if (get_status(&tperror) != TE_OK) { 985 tpqputs(TPQD_ALWAYS, "tp_sense: could not read tape drive status");
986 returnTE_ERR;
987 } 988
989 err = tperror.exs; /* get exception status bits */ 990 if (err & (TP_ST0|TP_ST1))
991 printk(TPQIC02_NAME ": tp_sense: status: %x, error count: %d, underruns: %d\n",
992 tperror.exs, tperror.dec, tperror.urc);
993 elseif ((tperror.dec!=0) || (tperror.urc!=0) || TPQDBG(SENSE_CNTS))
994 printk(TPQIC02_NAME ": tp_sense: no hard errors, soft error count: %d, underruns: %d\n",
995 tperror.dec, tperror.urc);
996
997 /* Set generic status. HP-UX defines these, but some extra would 998 * be useful. Problem is to remain compatible. [Do we want to be 999 * compatible??]1000 */1001 if (err & TP_ST0) {1002 if (err & TP_CNI) /* no cartridge */1003 gs |= GMT_DR_OPEN(-1);
1004 if (status_dead == NO)
1005 gs |= GMT_ONLINE(-1); /* always online */1006 if (err & TP_USL) /* not online */1007 gs &= ~GMT_ONLINE(-1);
1008 if (err & TP_WRP)
1009 gs |= GMT_WR_PROT(-1);
1010 if (err & TP_EOM) {/* end of media */1011 gs |= GMT_EOT(-1); /* not sure this is correct for writes */1012 status_eom_detected = YES;
1013 /* I don't know whether drive always reports EOF at or before EOM. */1014 status_eof_detected = YES;
1015 }1016 /** if (err & TP_UDA) "Unrecoverable data error" **/1017 /** if (err & TP_BNL) "Bad block not located" **/1018 if (err & TP_FIL) {1019 gs |= GMT_EOF(-1);
1020 status_eof_detected = YES;
1021 }1022 }1023 if (err & TP_ST1) {1024 /** if (err & TP_ILL) "Illegal command" **/1025 /** if (err & TP_NDT) "No data detected" **/1026 /** if (err & TP_MBD) "Marginal block detected" **/1027 if (err & TP_BOM)
1028 gs |= GMT_BOT(-1); /* beginning of tape */1029 }1030 ioctl_status.mt_gstat = gs;
1031 ioctl_status.mt_dsreg = tperror.exs; /* "drive status" */1032 ioctl_status.mt_erreg = tperror.dec; /* "sense key error" */1033
1034 if (err & (TP_ST0|TP_ST1)) {1035 /* My Wangtek occasionally reports `status' 1212 which should be ignored. */1036 exnr = decode_exception_nr(err);
1037 handle_exception(exnr, err); /* update driver state wrt drive status */1038 report_exception(exnr);
1039 }1040 err &= ~ignore; /* mask unwanted errors -- not the correct way, use exception nrs?? */1041 if (((err & TP_ST0) && (err & REPORT_ERR0)) ||
1042 ((err & TP_ST1) && (err & REPORT_ERR1)))
1043 returnTE_ERR;
1044 returnTE_OK;
1045 }/* tp_sense */1046
1047
1048
1049 /* Wait for a wind or rewind operation to finish or1050 * to time-out. (May take very long).1051 */1052 staticintwait_for_rewind(time_ttimeout)
/* */1053 {1054 intstat;
1055
1056 stat = inb(QIC02_STAT_PORT) & QIC02_STAT_MASK;
1057 if (TPQDBG(REWIND))
1058 printk(TPQIC02_NAME ": Waiting for (re-)wind to finish: stat=0x%x\n", stat);
1059
1060 stat = wait_for_ready(timeout);
1061
1062 if (stat != TE_OK) {1063 tpqputs(TPQD_ALWAYS, "(re-) winding failed\n");
1064 }1065 returnstat;
1066 }/* wait_for_rewind */1067
1068
1069
1070 /* Perform a full QIC02 command, and wait for completion,1071 * check status when done. Complain about exceptions.1072 *1073 * This function should return an OS error code when1074 * something goes wrong, 0 otherwise.1075 */1076 staticintll_do_qic_cmd(intcmd, time_ttimeout)
/* */1077 {1078 intstat;
1079
1080 if (status_dead == YES) {1081 tpqputs(TPQD_ALWAYS, "Drive is dead. Do a `mt reset`.");
1082 return -ENXIO; /* User should do an MTRESET. */1083 }1084
1085 stat = wait_for_ready(timeout); /* wait for ready or exception */1086 if (stat == TE_EX) {1087 if (tp_sense(TP_WRP|TP_BOM|TP_EOM|TP_FIL)!=TE_OK)
1088 return -EIO;
1089 /* else nothing to worry about, I hope */1090 stat = TE_OK;
1091 }1092 if (stat != TE_OK) {1093 printk(TPQIC02_NAME ": ll_do_qic_cmd(%x, %ld) failed\n", cmd, (long) timeout);
1094 return -EIO;
1095 }1096
1097
1098 #ifOBSOLETE1099 /* wait for ready since it may not be active immediately after reading status */1100 while ((inb_p(QIC02_STAT_PORT) & QIC02_STAT_READY) != 0);
1101 #endif1102
1103 stat = send_qic02_cmd(cmd, timeout, 0); /* (checks for exceptions) */1104
1105 if (cmd==QCMD_RD_FM) {1106 status_eof_detected = NO;
1107 ioctl_status.mt_fileno++;
1108 /* Should update block count as well, but can't.1109 * Can do a `read address' for some drives, when MTNOP is done.1110 */1111 }elseif (cmd==QCMD_WRT_FM) {1112 status_eof_detected = NO;
1113 ioctl_status.mt_fileno++;
1114 }elseif ((cmd==QCMD_REWIND) || (cmd==QCMD_ERASE) || (cmd==QCMD_RETEN)) {1115 status_eof_detected = NO;
1116 status_eom_detected = NO;
1117 status_eot_detected = NO;
1118 need_rewind = NO;
1119 ioctl_status.mt_fileno = ioctl_status.mt_blkno = 0;
1120 extra_blocks_left = BLOCKS_BEYOND_EW;
1121 return_write_eof = NO;
1122 return_read_eof = NO;
1123 reported_read_eof = NO;
1124 reported_write_eof = NO;
1125 }1126 /* sense() will set eof/eom as required */1127 if (stat==TE_EX) {1128 if (tp_sense(TP_WRP|TP_BOM|TP_EOM|TP_FIL)!=TE_OK) {1129 printk(TPQIC02_NAME ": Exception persist in ll_do_qic_cmd[1](%x, %ld)", cmd, (long) timeout);
1130 status_dead = YES;
1131 return -ENXIO;
1132 /* if rdstatus fails too, we're in trouble */1133 }1134 }1135 elseif (stat!=TE_OK) {1136 printk(TPQIC02_NAME ": ll_do_qic_cmd: send_qic02_cmd failed, stat = 0x%x\n", stat);
1137 return -EIO; /*** -EIO is probably not always appropriate */1138 }1139
1140
1141 if (timeout == TIM_R)
1142 stat = wait_for_rewind(timeout);
1143 else1144 stat = wait_for_ready(timeout);
1145
1146 if (stat==TE_EX) {1147 if (tp_sense((cmd==QCMD_SEEK_EOD ? /*****************************/1148 TP_EOR|TP_NDT|TP_UDA|TP_BNL|TP_WRP|TP_BOM|TP_EOM|TP_FIL :
1149 TP_WRP|TP_BOM|TP_EOM|TP_FIL))!=TE_OK) {1150 printk(TPQIC02_NAME ": Exception persist in ll_do_qic_cmd[2](%x, %ld)\n", cmd, (long) timeout);
1151 if (cmd!=QCMD_RD_FM)
1152 status_dead = YES;
1153 return -ENXIO;
1154 /* if rdstatus fails too, we're in trouble */1155 }1156 }1157 elseif (stat!=TE_OK) {1158 printk(TPQIC02_NAME ": ll_do_qic_cmd %x: wait failed, stat == 0x%x\n", cmd, stat);
1159 return -EIO;
1160 }1161 return 0;
1162 }/* ll_do_qic_cmd */1163
1164
1165 /* 1166 * Problem: What to do when the user cancels a read/write operation1167 * in-progress?1168 *1169 * "Deactivating ONLINE during a READ also causes the"1170 * "tape to be rewound to BOT." Ditto for WRITEs, except1171 * a FM is written first. "The host may alternatively terminate1172 * the READ/WRITE command by issuing a RFM/WFM command."1173 *1174 * For READs:1175 * Neither option will leave the tape positioned where it was.1176 * Another (better?) solution is to terminate the READ by two1177 * subsequent sense() operations, the first to stop the current1178 * READ cycle, the second to clear the `Illegal command' exception,1179 * because the QIC-02 specs didn't anticipate this. This is1180 * delayed until actually needed, so a tar listing can be aborted1181 * by the user and continued later.1182 * If anybody has a better solution, let me know! [Also, let me1183 * know if your drive (mine is a Wangtek5150EQ) does not accept1184 * this sequence for canceling the read-cycle.]1185 *1186 * For WRITEs it's simple: Just do a WRITE_FM, leaving the tape1187 * positioned after the FM.1188 */1189
1190 staticvoidterminate_read(intcmd)
/* */1191 {1192 if (doing_read == YES) {1193 doing_read = NO;
1194 if (cmd != QCMD_RD_FM) {1195 /* if the command is a RFM, there is no need to do this1196 * because a RFM will legally terminate the read-cycle.1197 */1198 tpqputs(TPQD_ALWAYS, "terminating pending read-cycle");
1199
1200 /* I'm not too sure about this part -- hhb */1201 if (QIC02_TAPE_IFC == MOUNTAIN) {1202 /* Mountain reference says can terminate by de-asserting online */1203 ctlbits &= ~MTN_QIC02_CTL_ONLINE;
1204 }1205
1206 if (tp_sense(TP_FIL|TP_EOM|TP_WRP) != TE_OK) {1207 tpqputs(TPQD_ALWAYS, "finish_rw[read1]: ignore the 2 lines above");
1208 if (is_exception()) {1209 if (tp_sense(TP_ILL|TP_FIL|TP_EOM|TP_WRP) != TE_OK)
1210 tpqputs(TPQD_ALWAYS, "finish_rw[read2]: read cycle error");
1211 }1212 }1213 }1214 }1215 }/* terminate_read */1216
1217
1218 staticvoidterminate_write(intcmd)
/* */1219 {1220 intstat;
1221
1222 if (doing_write == YES) {1223 doing_write = NO;
1224 /* Finish writing by appending a FileMark at the end. */1225 if (cmd != QCMD_WRT_FM) {1226 /* finish off write cycle */1227 stat = ll_do_qic_cmd(QCMD_WRT_FM, TIM_M);
1228 if (stat != TE_OK)
1229 tpqputs(TPQD_ALWAYS, "Couldn't finish write cycle properly");
1230 (void) tp_sense(0);
1231 }1232 /* If there is an EOF token waiting to be returned to1233 * the (writing) application, discard it now.1234 * We could be at EOT, so don't reset return_write_eof.1235 */1236 reported_write_eof=YES;
1237 }1238 }/* terminate_write */1239
1240
1241 /* terminate read or write cycle because of command `cmd' */1242 staticvoidfinish_rw(intcmd)
/* */1243 {1244 if (wait_for_ready(TIM_S) != TE_OK) {1245 tpqputs(TPQD_ALWAYS, "error: drive not ready in finish_rw() !");
1246 return;
1247 }1248 terminate_read(cmd);
1249 terminate_write(cmd);
1250 }/* finish_rw */1251
1252
1253 /* Perform a QIC command through ll_do_qic_cmd().1254 * If necessary, rewind the tape first.1255 * Return an OS error code if something goes wrong, 0 if all is well.1256 */1257 staticintdo_qic_cmd(intcmd, time_ttimeout)
/* */1258 {1259 intstat;
1260
1261
1262 finish_rw(cmd);
1263
1264 if (need_rewind) {1265 tpqputs(TPQD_REWIND, "Rewinding tape...");
1266 stat = ll_do_qic_cmd(QCMD_REWIND, TIM_R);
1267 if (stat != 0) {1268 printk(TPQIC02_NAME ": rewind failed in do_qic_cmd(). stat=0x%2x", stat);
1269 returnstat;
1270 }1271 need_rewind = NO;
1272 if (cmd==QCMD_REWIND) /* don't wind beyond BOT ;-) */1273 return 0;
1274 }1275
1276 returnll_do_qic_cmd(cmd, timeout);
1277 }/* do_qic_cmd */1278
1279
1280 /* Not all ioctls are supported for all drives. Some rely on1281 * optional QIC-02 commands. Check tpqic02.h for configuration.1282 * Some of these commands may require ONLINE to be active.1283 */1284 staticintdo_ioctl_cmd(intcmd)
/* */1285 {1286 intstat;
1287
1288 /* It is not permitted to read or wind the tape after bytes have1289 * been written. It is not permitted to write the tape while in1290 * read mode.1291 * We try to be kind and allow reading again after writing a FM...1292 */1293
1294 switch (cmd) {1295 caseMTRESET:
1296 /* reset verbose */1297 return (tape_reset(1)==TE_OK)? 0 : -EIO;
1298
1299 caseMTFSF:
1300 tpqputs(TPQD_IOCTLS, "MTFSF forward searching filemark");
1301 if ((mode_access==WRITE) && status_bytes_wr)
1302 return -EACCES;
1303 returndo_qic_cmd(QCMD_RD_FM, TIM_F);
1304
1305 caseMTBSF:
1306 if (TP_HAVE_BSF) {1307 tpqputs(TPQD_IOCTLS, "MTBSF backward searching filemark -- optional command");
1308 if ((mode_access==WRITE) && status_bytes_wr)
1309 return -EACCES;
1310 stat = do_qic_cmd(QCMD_RD_FM_BCK, TIM_F);
1311 }else{1312 stat = -ENXIO;
1313 }1314 status_eom_detected = status_eof_detected = NO;
1315 returnstat;
1316
1317 caseMTFSR:
1318 if (TP_HAVE_FSR) {/* This is an optional QIC-02 command */1319 tpqputs(TPQD_IOCTLS, "MTFSR forward space record");
1320 if ((mode_access==WRITE) && status_bytes_wr)
1321 return -EACCES;
1322 stat = do_qic_cmd(QCMD_SPACE_FWD, TIM_F);
1323 }else{1324 /**** fake it by doing a read data block command? ******/1325 tpqputs(TPQD_IOCTLS, "MTFSR not supported");
1326 stat = -ENXIO;
1327 }1328 returnstat;
1329
1330 caseMTBSR:
1331 if (TP_HAVE_BSR) {/* This is an optional QIC-02 command */1332 /* we need this for appending files with GNU tar!! */1333 tpqputs(TPQD_IOCTLS, "MTFSR backward space record");
1334 if ((mode_access==WRITE) && status_bytes_wr)
1335 return -EACCES;
1336 stat = do_qic_cmd(QCMD_SPACE_BCK, TIM_F);
1337 }else{1338 tpqputs(TPQD_IOCTLS, "MTBSR not supported");
1339 stat = -ENXIO;
1340 }1341 status_eom_detected = status_eof_detected = NO;
1342 returnstat;
1343
1344 caseMTWEOF:
1345 tpqputs(TPQD_IOCTLS, "MTWEOF write eof mark");
1346 /* Plain GNU mt(1) 2.2 uses read-only mode for writing FM. :-( */1347 if (mode_access==READ)
1348 return -EACCES;
1349
1350 /* allow tape movement after writing FM */1351 status_bytes_rd = status_bytes_wr; /* Kludge-O-Matic */1352 status_bytes_wr = NO;
1353 returndo_qic_cmd(QCMD_WRT_FM, TIM_M);
1354 /* not sure what to do with status_bytes when WFM should fail */1355
1356 caseMTREW:
1357 tpqputs(TPQD_IOCTLS, "MTREW rewinding tape");
1358 if ((mode_access==WRITE) && status_bytes_wr)
1359 return -EACCES;
1360 status_eom_detected = status_eof_detected = NO;
1361 returndo_qic_cmd(QCMD_REWIND, TIM_R);
1362
1363 caseMTOFFL:
1364 tpqputs(TPQD_IOCTLS, "MTOFFL rewinding & going offline");
1365 /* Doing a drive select will clear (unlock) the current drive.1366 * But that requires support for multiple drives and locking.1367 */1368 if ((mode_access==WRITE) && status_bytes_wr)
1369 return -EACCES;
1370 status_eom_detected = status_eof_detected = NO;
1371 /**** do rewind depending on minor bits??? ***/1372 stat = do_qic_cmd(QCMD_REWIND, TIM_R);
1373 returnstat;
1374
1375 caseMTNOP:
1376 tpqputs(TPQD_IOCTLS, "MTNOP setting status only");
1377 /********** should do `read position' for drives that support it **********/1378 return (tp_sense(-1)==TE_OK)? 0 : -EIO; /**** check return codes ****/1379
1380 caseMTRETEN:
1381 tpqputs(TPQD_IOCTLS, "MTRETEN retension tape");
1382 if ((mode_access==WRITE) && status_bytes_wr)
1383 return -EACCES;
1384 status_eom_detected = status_eof_detected = NO;
1385 returndo_qic_cmd(QCMD_RETEN, TIM_R);
1386
1387 caseMTBSFM:
1388 /* Think think is like MTBSF, except that1389 * we shouldn't skip the FM. Tricky.1390 * Maybe use RD_FM_BCK, then do a SPACE_FWD?1391 */1392 tpqputs(TPQD_IOCTLS, "MTBSFM not supported");
1393 if ((mode_access==WRITE) && status_bytes_wr)
1394 return -EACCES;
1395 return -ENXIO;
1396
1397 caseMTFSFM:
1398 /* I think this is like MTFSF, except that1399 * we shouldn't skip the FM. Tricky.1400 * Maybe use QCMD_RD_DATA until we get a TP_FIL exception?1401 * But then the FM will have been skipped...1402 * Maybe use RD_FM, then RD_FM_BCK, but not all1403 * drives will support that!1404 */1405 tpqputs(TPQD_IOCTLS, "MTFSFM not supported");
1406 if ((mode_access==WRITE) && status_bytes_wr)
1407 return -EACCES;
1408 return -ENXIO;
1409
1410 caseMTEOM:
1411 /* This should leave the tape ready for appending1412 * another file to the end, such that it would append1413 * after the last FM on tape.1414 */1415 tpqputs(TPQD_IOCTLS, "MTEOM search for End Of recorded Media");
1416 if ((mode_access==WRITE) && status_bytes_wr)
1417 return -EACCES;
1418 if (TP_HAVE_EOD) {1419 /* Use faster seeking when possible.1420 * This requires the absence of data beyond the EOM.1421 * It seems that my drive does not always perform the1422 * SEEK_EOD correctly, unless it is preceded by a1423 * rewind command.1424 */1425 # if 0
1426 status_eom_detected = status_eof_detected = NO;
1427 # endif1428 stat = do_qic_cmd(QCMD_REWIND, TIM_R);
1429 if (stat)
1430 returnstat;
1431 stat = do_qic_cmd(QCMD_SEEK_EOD, TIM_F);
1432 /* After a successful seek, TP_EOR should be returned */1433 }else{1434 /* else just seek until the drive returns exception "No Data" */1435 stat = 0;
1436 while ((stat==0) && (!status_eom_detected)) {1437 stat = do_qic_cmd(QCMD_RD_FM, TIM_F); /***** should use MTFSFM here???? ******/1438 }1439 if (tperror.exs & TP_NDT)
1440 return 0;
1441 }1442 returnstat;
1443
1444 caseMTERASE:
1445 tpqputs(TPQD_IOCTLS, "MTERASE -- ERASE TAPE !");
1446 if ((tperror.exs & TP_ST0) && (tperror.exs & TP_WRP)) {1447 tpqputs(TPQD_ALWAYS, "Cartridge is write-protected.");
1448 return -EACCES;
1449 }else{1450 time_tt = jiffies;
1451
1452 /* Plain GNU mt(1) 2.2 erases a tape in O_RDONLY. :-( */1453 if (mode_access==READ)
1454 return -EACCES;
1455
1456 /* give user a few seconds to pull out tape */1457 while (jiffies - t < 4*HZ)
1458 schedule();
1459 }1460
1461 /* don't bother writing filemark first */1462 status_eom_detected = status_eof_detected = NO;
1463 returndo_qic_cmd(QCMD_ERASE, TIM_R);
1464
1465 caseMTRAS1:
1466 if (TP_HAVE_RAS1) {1467 tpqputs(TPQD_IOCTLS, "MTRAS1: non-destructive self test");
1468 stat = do_qic_cmd(QCMD_SELF_TST1, TIM_R);
1469 if (stat != 0) {1470 tpqputs(TPQD_ALWAYS, "RAS1 failed");
1471 returnstat;
1472 }1473 return (tp_sense(0)==TE_OK)? 0 : -EIO; /* get_ext_status3(); */1474 }1475 tpqputs(TPQD_IOCTLS, "RAS1 not supported");
1476 return -ENXIO;
1477
1478 caseMTRAS2:
1479 if (TP_HAVE_RAS2) {1480 tpqputs(TPQD_IOCTLS, "MTRAS2: destructive self test");
1481 stat = do_qic_cmd(QCMD_SELF_TST2, TIM_R);
1482 if (stat != 0) {1483 tpqputs(TPQD_ALWAYS, "RAS2 failed");
1484 returnstat;
1485 }1486 return (tp_sense(0)==TE_OK)? 0 : -EIO; /* get_ext_status3(); */1487 }1488 tpqputs(TPQD_IOCTLS, "RAS2 not supported");
1489 return -ENXIO;
1490
1491 caseMTSEEK:
1492 if (TP_HAVE_SEEK && (QIC02_TAPE_IFC==ARCHIVE)) {1493 tpqputs(TPQD_IOCTLS, "MTSEEK seeking block");
1494 if ((mode_access==WRITE) && status_bytes_wr)
1495 return -EACCES;
1496 /* NOTE: address (24 bits) is in seek_addr_buf[] */1497 returndo_qic_cmd(AR_QCMDV_SEEK_BLK, TIM_F);
1498 }1499 else1500 return -ENOTTY;
1501
1502 default:
1503 return -ENOTTY;
1504 }1505 }/* do_ioctl_cmd */1506
1507
1508 /* dma_transfer(): This routine is called for every 512 bytes to be read1509 * from/written to the tape controller. Speed is important here!1510 * (There must be enough time left for the hd controller!)1511 * When other devices use DMA they must ensure they use un-interruptible1512 * double byte accesses to the DMA controller. Floppy.c is ok.1513 * Must have interrupts disabled when this function is invoked,1514 * otherwise, the double-byte transfers to the DMA controller will not1515 * be atomic. That could lead to nasty problems when they are interrupted1516 * by other DMA interrupt-routines.1517 *1518 * This routine merely does the least possible to keep1519 * the transfers going:1520 * - set the DMA count register for the next 512 bytes1521 * - adjust the DMA address and page registers1522 * - adjust the timeout1523 * - tell the tape controller to start transferring1524 * We assume the dma address and mode are, and remain, valid.1525 */1526 staticinlinevoiddma_transfer(void)
/* */1527 {1528
1529 if (QIC02_TAPE_IFC == WANGTEK) /* or EVEREX */1530 outb_p(WT_CTL_ONLINE, QIC02_CTL_PORT); /* back to normal */1531 elseif (QIC02_TAPE_IFC == ARCHIVE)
1532 outb_p(0, AR_RESET_DMA_PORT);
1533 else/* QIC02_TAPE_IFC == MOUNTAIN */1534 outb_p(ctlbits, QIC02_CTL_PORT);
1535
1536
1537 clear_dma_ff(QIC02_TAPE_DMA);
1538 set_dma_mode(QIC02_TAPE_DMA, dma_mode);
1539 set_dma_addr(QIC02_TAPE_DMA, buffaddr+dma_bytes_done); /* full address */1540 set_dma_count(QIC02_TAPE_DMA, TAPE_BLKSIZE);
1541
1542 /* start tape DMA controller */1543 if (QIC02_TAPE_IFC == WANGTEK) /* or EVEREX */1544 outb_p(WT_CTL_DMA | WT_CTL_ONLINE, QIC02_CTL_PORT); /* trigger DMA transfer */1545
1546 elseif (QIC02_TAPE_IFC == ARCHIVE) {1547 outb_p(AR_CTL_IEN | AR_CTL_DNIEN, QIC02_CTL_PORT); /* enable interrupts again */1548 outb_p(0, AR_START_DMA_PORT); /* start DMA transfer */1549 /* In dma_end() AR_RESET_DMA_PORT is written too. */1550
1551 }else/* QIC02_TAPE_IFC == MOUNTAIN */{1552 inb(MTN_R_DESELECT_DMA_PORT);
1553 outb_p(ctlbits | (MTN_CTL_EXC_IEN | MTN_CTL_DNIEN), QIC02_CTL_PORT);
1554 outb_p(0, MTN_W_SELECT_DMA_PORT); /* start DMA transfer */1555 if (dma_mode == DMA_MODE_WRITE)
1556 outb_p(0, MTN_W_DMA_WRITE_PORT); /* start DMA transfer */1557 }1558
1559 /* start computer DMA controller */1560 enable_dma(QIC02_TAPE_DMA);
1561 /* block transfer should start now, jumping to the 1562 * interrupt routine when done or an exception was detected.1563 */1564 }/* dma_transfer */1565
1566
1567 /* start_dma() sets a DMA transfer up between the tape controller and1568 * the kernel qic02_tape_buf buffer.1569 * Normally bytes_todo==dma_bytes_done at the end of a DMA transfer. If not,1570 * a filemark was read, or an attempt to write beyond the End Of Tape 1571 * was made. [Or some other bad thing happened.]1572 * Must do a sense() before returning error.1573 */1574 staticintstart_dma(shortmode, unsignedlongbytes_todo)
/* */1575 /* assume 'bytes_todo'>0 */1576 {1577 intstat;
1578
1579 tpqputs(TPQD_DEBUG, "start_dma() enter");
1580 TPQDEB({printk(TPQIC02_NAME ": doing_read==%d, doing_write==%d\n", doing_read, doing_write);})
1581
1582 dma_bytes_done = 0;
1583 dma_bytes_todo = bytes_todo;
1584 status_error = NO;
1585 /* dma_mode!=0 indicates that the dma controller is in use */1586 dma_mode = (mode == WRITE)? DMA_MODE_WRITE : DMA_MODE_READ;
1587
1588 /* Only give READ/WRITE DATA command to tape drive if we haven't1589 * done that already. Otherwise the drive will rewind to the beginning1590 * of the current file on tape. Any QIC command given other than1591 * R/W FM will break the read/write transfer cycle.1592 * do_qic_cmd() will terminate doing_{read,write}1593 */1594 if ((doing_read == NO) && (doing_write == NO)) {1595 /* First, we have to clear the status -- maybe remove TP_FIL???1596 */1597
1598 #if 0
1599 /* Next dummy get status is to make sure CNI is valid,1600 since we're only just starting a read/write it doesn't1601 matter some exceptions are cleared by reading the status;1602 we're only interested in CNI and WRP. -Eddy */1603 get_status(&tperror);
1604 #else1605 /* TP_CNI should now be handled in open(). -Hennus */1606 #endif1607
1608 stat = tp_sense(((mode == WRITE)? 0 : TP_WRP) | TP_BOM | TP_FIL);
1609 if (stat != TE_OK)
1610 returnstat;
1611
1612 #ifOBSOLETE1613 /************* not needed iff rd_status() would wait for ready!!!!!! **********/1614 if (wait_for_ready(TIM_S) != TE_OK) {/*** not sure this is needed ***/1615 tpqputs(TPQD_ALWAYS, "wait_for_ready failed in start_dma");
1616 return -EIO;
1617 }1618 #endif1619
1620 if (QIC02_TAPE_IFC == MOUNTAIN) {1621 /* Set control bits to select ONLINE during command */1622 ctlbits |= MTN_QIC02_CTL_ONLINE;
1623 }1624
1625 /* Tell the controller the data direction */1626
1627 /* r/w, timeout medium, check exceptions, sets status_cmd_pending. */1628 stat = send_qic02_cmd((mode == WRITE)? QCMD_WRT_DATA : QCMD_RD_DATA, TIM_M, 0);
1629 if (stat!=TE_OK) {1630 printk(TPQIC02_NAME ": start_dma: init %s failed\n",
1631 (mode == WRITE)? "write" : "read");
1632 (void) tp_sense(0);
1633 returnstat;
1634 }1635
1636 /* Do this last, because sense() will clear the doing_{read,write}1637 * flags, causing trouble next time around.1638 */1639 if (wait_for_ready(TIM_M) != TE_OK)
1640 return -EIO;
1641 switch (mode) {1642 caseREAD:
1643 doing_read = YES;
1644 break;
1645 caseWRITE:
1646 doing_write = YES;
1647 break;
1648 default:
1649 printk(TPQIC02_NAME ": requested unknown mode %d\n", mode);
1650 panic(TPQIC02_NAME ": invalid mode in start_dma()");
1651 }1652
1653 }elseif (is_exception()) {1654 /* This is for Archive drives, to handle reads with 0 bytes1655 * left for the last read request.1656 *1657 * ******** this also affects EOF/EOT handling! ************1658 */1659 tpqputs(TPQD_ALWAYS, "detected exception in start_dma() while transfer in progress");
1660 status_error = YES;
1661 returnTE_END;
1662 }1663
1664
1665 status_expect_int = YES;
1666
1667 /* This assumes tape is already positioned, but these1668 * semi-'intelligent' drives are unpredictable...1669 */1670 TIMERON(TIM_M*2);
1671
1672 /* initiate first data block read from/write to the tape controller */1673
1674 cli();
1675 dma_transfer();
1676 sti();
1677
1678 TPQPUTS("start_dma() end");
1679 returnTE_OK;
1680 }/* start_dma */1681
1682
1683 /* This cleans up after the dma transfer has completed1684 * (or failed). If an exception occurred, a sense()1685 * must be done. If the exception was caused by a FM,1686 * sense() will set `status_eof_detected' and1687 * `status_eom_detected', as required.1688 */1689 staticvoidend_dma(unsignedlong * bytes_done)
/* */1690 {1691 intstat = TE_OK;
1692
1693 TIMEROFF;
1694
1695 TPQPUTS("end_dma() enter");
1696
1697 disable_dma(QIC02_TAPE_DMA);
1698 clear_dma_ff(QIC02_TAPE_DMA);
1699
1700 if (QIC02_TAPE_IFC == WANGTEK) /* or EVEREX */1701 outb_p(WT_CTL_ONLINE, QIC02_CTL_PORT); /* back to normal */1702 elseif (QIC02_TAPE_IFC == ARCHIVE)
1703 outb_p(0, AR_RESET_DMA_PORT);
1704 else/* QIC02_TAPE_IFC == MOUNTAIN */{1705 /* Clear control bits, de-select ONLINE during tp_sense */1706 ctlbits &= ~MTN_QIC02_CTL_ONLINE;
1707 }1708
1709 stat = wait_for_ready(TIM_M);
1710 if (status_error || (stat!=TE_OK)) {1711 tpqputs(TPQD_DMAX, "DMA transfer exception");
1712 stat = tp_sense((dma_mode==READ)? TP_WRP : 0);
1713 /* no return here -- got to clean up first! */1714 }else/* if (QIC02_TAPE_IFC == MOUNTAIN) */{1715 outb_p(ctlbits, QIC02_CTL_PORT);
1716 }1717
1718 if (QIC02_TAPE_IFC == MOUNTAIN)
1719 inb(MTN_R_DESELECT_DMA_PORT);
1720
1721 /* take the tape controller offline */1722
1723 /* finish off DMA stuff */1724
1725
1726 dma_mode = 0;
1727 /* Note: The drive is left on-line, ready for the next1728 * data transfer.1729 * If the next command to the drive does not continue1730 * the pending cycle, it must do 2 sense()s first.1731 */1732
1733 *bytes_done = dma_bytes_done;
1734 status_expect_int = NO;
1735 ioctl_status.mt_blkno += (dma_bytes_done / TAPE_BLKSIZE);
1736
1737 TPQPUTS("end_dma() exit");
1738 /*** could return stat here ***/1739 }/* end_dma */1740
1741 /*********** Below are the (public) OS-interface procedures ***********/1742
1743
1744 /* qic02_tape_times_out() is called when a DMA transfer doesn't complete1745 * quickly enough. Usually this means there is something seriously wrong1746 * with the hardware/software, but it could just be that the controller1747 * has decided to do a long rewind, just when I didn't expect it.1748 * Just try again.1749 */1750 staticvoidqic02_tape_times_out(void)
/* */1751 {1752 printk("time-out in %s driver\n", TPQIC02_NAME);
1753 if ((status_cmd_pending>0) || dma_mode) {1754 /* takes tooo long, shut it down */1755 status_dead = YES;
1756 status_cmd_pending = 0;
1757 status_timer_on = NO;
1758 status_expect_int = NO;
1759 status_error = YES;
1760 if (dma_mode) {1761 dma_mode = 0; /* signal end to read/write routine */1762 wake_up(&qic02_tape_transfer);
1763 }1764 }1765 }/* qic02_tape_times_out */1766
1767 /*1768 * Interrupt handling:1769 *1770 * 1) Interrupt is generated iff at the end of 1771 * a 512-DMA-block transfer.1772 * 2) EXCEPTION is not raised unless something 1773 * is wrong or EOT/FM is detected.1774 * 3) FM EXCEPTION is set *after* the last byte has1775 * been transferred by DMA. By the time the interrupt1776 * is handled, the EXCEPTION may already be set.1777 *1778 * So,1779 * 1) On EXCEPTION, assume data has been transferred, so1780 * continue as usual, but set a flag to indicate the1781 * exception was detected.1782 * Do a sense status when the flag is found set.1783 * 2) Do not attempt to continue a transfer after an exception.1784 * [??? What about marginal blocks???????]1785 */1786
1787
1788 /* qic02_tape_interrupt() is called when the tape controller completes 1789 * a DMA transfer.1790 * We are not allowed to sleep here! 1791 *1792 * Check if the transfer was successful, check if we need to transfer1793 * more. If the buffer contains enough data/is empty enough, signal the1794 * read/write() thread to copy to/from user space.1795 * When we are finished, set flags to indicate end, disable timer.1796 * NOTE: This *must* be fast! 1797 */1798 staticvoidqic02_tape_interrupt(intirq, structpt_regs *regs)
/* */1799 {1800 intstat, r, i;
1801
1802 TIMEROFF;
1803
1804 if (status_expect_int) {1805 #ifdef WANT_EXTRA_FULL_DEBUGGING
1806 if (TP_DIAGS(current_tape_dev))
1807 printk("@");
1808 #endif1809 stat = inb(QIC02_STAT_PORT); /* Knock, knock */1810 if (QIC02_TAPE_IFC == ARCHIVE) {/* "Who's there?" */1811 if (((stat & (AR_STAT_DMADONE)) == 0) &&
1812 ((stat & (QIC02_STAT_EXCEPTION)) != 0)) {1813 TIMERCONT;
1814 return; /* "Linux with IRQ sharing" */1815 }1816 }1817
1818 if ((stat & QIC02_STAT_EXCEPTION) == 0) {/* exception occurred */1819 /* Possible causes for an exception during a transfer:1820 * - during a write-cycle: end of tape (EW) hole detected.1821 * - during a read-cycle: filemark or EOD detected.1822 * - something went wrong1823 * So don't continue with the next block.1824 */1825 tpqputs(TPQD_ALWAYS, "isr: exception on tape controller");
1826 printk(" status %02x\n", stat);
1827 status_error = TE_EX;
1828
1829 dma_bytes_done += TAPE_BLKSIZE;
1830
1831 dma_mode = 0; /* wake up rw() */1832 status_expect_int = NO;
1833 wake_up(&qic02_tape_transfer);
1834 return;
1835 }1836 /* return if tape controller not ready, or1837 * if dma channel hasn't finished last byte yet.1838 */1839 r = 0;
1840 /* Skip next ready check for Archive controller because1841 * it may be busy reading ahead. Weird. --hhb1842 */1843 if (QIC02_TAPE_IFC == WANGTEK) /* I think this is a drive-dependency, not IFC -- hhb */1844 if (stat & QIC02_STAT_READY) {/* not ready */1845 tpqputs(TPQD_ALWAYS, "isr: ? Tape controller not ready");
1846 r = 1;
1847 }1848
1849 if ( (i = get_dma_residue(QIC02_TAPE_DMA)) != 0 ) {1850 printk(TPQIC02_NAME ": dma_residue == %x !!!\n", i);
1851 r = 1; /* big trouble, but can't do much about it... */1852 }1853
1854 if (r)
1855 return;
1856
1857 /* finish DMA cycle */1858
1859 /* no errors detected, continue */1860 dma_bytes_done += TAPE_BLKSIZE;
1861 if (dma_bytes_done >= dma_bytes_todo) {1862 /* finished! Wakeup rw() */1863 dma_mode = 0;
1864 status_expect_int = NO;
1865 TPQPUTS("isr: dma_bytes_done");
1866 wake_up(&qic02_tape_transfer);
1867 }else{1868 /* start next transfer, account for track-switching time */1869 timer_table[QIC02_TAPE_TIMER].expires = jiffies + 6*HZ;
1870 dma_transfer();
1871 }1872 }else{1873 printk(TPQIC02_NAME ": Unexpected interrupt, stat == %x\n",
1874 inb(QIC02_STAT_PORT));
1875 }1876 }/* qic02_tape_interrupt */1877
1878
1879 staticintqic02_tape_lseek(structinode * inode, structfile * file, off_toffset, intorigin)
/* */1880 {1881 return -EINVAL; /* not supported */1882 }/* qic02_tape_lseek */1883
1884
1885 /* read/write routines:1886 * This code copies between a kernel buffer and a user buffer. The 1887 * actual data transfer is done using DMA and interrupts. Time-outs1888 * are also used.1889 *1890 * When a filemark is read, we return '0 bytes read' and continue with the1891 * next file after that.1892 * When EOM is read, we return '0 bytes read' twice.1893 * When the EOT marker is detected on writes, '0 bytes read' should be1894 * returned twice. If user program does a MTNOP after that, 2 additional1895 * blocks may be written. ------- FIXME: Implement this correctly *************************************************1896 *1897 * Only read/writes in multiples of 512 bytes are accepted.1898 * When no bytes are available, we sleep() until they are. The controller will1899 * generate an interrupt, and we (should) get a wake_up() call.1900 *1901 * Simple buffering is used. User program should ensure that a large enough1902 * buffer is used. Usually the drive does some buffering as well (something1903 * like 4k or so).1904 *1905 * Scott S. Bertilson suggested to continue filling the user buffer, rather1906 * than waste time on a context switch, when the kernel buffer fills up.1907 */1908
1909 /*1910 * Problem: tar(1) doesn't always read the entire file. Sometimes the entire file1911 * has been read, but the EOF token is never returned to tar(1), simply because1912 * tar(1) knows it has already read all of the data it needs. So we must use1913 * open/release to reset the `reported_read_eof' flag. If we don't, the next read1914 * request would return the EOF flag for the previous file.1915 */1916
1917 staticintqic02_tape_read(structinode * inode, structfile * filp, char * buf, intcount)
/* */1918 {1919 interror;
1920 dev_tdev = inode->i_rdev;
1921 unsignedshortflags = filp->f_flags;
1922 unsignedlongbytes_todo, bytes_done, total_bytes_done = 0;
1923 intstat;
1924
1925 if (status_zombie==YES) {1926 tpqputs(TPQD_ALWAYS, "configs not set");
1927 return -ENXIO;
1928 }1929
1930 if (TP_DIAGS(current_tape_dev))
1931 /* can't print a ``long long'' (for filp->f_pos), so chop it */1932 printk(TPQIC02_NAME ": request READ, minor=%x, buf=%p, count=%x, pos=%lx, flags=%x\n",
1933 MINOR(dev), buf, count, (unsignedlong) filp->f_pos, flags);
1934
1935 if (count % TAPE_BLKSIZE) {/* Only allow mod 512 bytes at a time. */1936 tpqputs(TPQD_BLKSZ, "Wrong block size");
1937 return -EINVAL;
1938 }1939
1940 /* Just assume everything is ok. Controller will scream if not. */1941
1942 if (status_bytes_wr) /* Once written, no more reads, 'till after WFM. */1943 return -EACCES;
1944
1945
1946 /* Make sure buffer is safe to write into. */1947 error = verify_area(VERIFY_WRITE, buf, count);
1948 if (error)
1949 returnerror;
1950
1951 /* This is rather ugly because it has to implement a finite state1952 * machine in order to handle the EOF situations properly.1953 */1954 while (count>=0) {1955 bytes_done = 0;
1956 /* see how much fits in the kernel buffer */1957 bytes_todo = TPQBUF_SIZE;
1958 if (bytes_todo>count)
1959 bytes_todo = count;
1960
1961 /* Must ensure that user program sees exactly one EOF token (==0) */1962 if (return_read_eof==YES) {1963 if (TPQDBG(DEBUG))
1964 printk("read: return_read_eof==%d, reported_read_eof==%d, total_bytes_done==%lu\n", return_read_eof, reported_read_eof, total_bytes_done);
1965
1966 if (reported_read_eof==NO) {1967 /* have not yet returned EOF to user program */1968 if (total_bytes_done>0) {1969 returntotal_bytes_done; /* next time return EOF */1970 }else{1971 reported_read_eof = YES; /* move on next time */1972 return 0; /* return EOF */1973 }1974 }else{1975 /* Application program has already received EOF1976 * (above), now continue with next file on tape,1977 * if possible.1978 * When the FM is reached, EXCEPTION is set,1979 * causing a sense(). Subsequent read/writes will1980 * continue after the FM.1981 */1982 /*********** ?????????? this should check for (EOD|NDT), not EOM, 'cause we can read past EW: ************/1983 if (status_eom_detected)
1984 /* If EOM, nothing left to read, so keep returning EOFs.1985 *** should probably set some flag to avoid clearing1986 *** status_eom_detected through ioctls or something1987 */1988 return 0;
1989 else{1990 /* just eof, there may be more files ahead... */1991 return_read_eof = NO;
1992 reported_read_eof = NO;
1993 status_eof_detected = NO; /* reset this too */1994 /*fall through*/1995 }1996 }1997 }1998
1999 /*****************************/2000 if (bytes_todo==0)
2001 returntotal_bytes_done;
2002
2003 if (bytes_todo>0) {2004 /* start reading data */2005 if (is_exception()) /****************************************/2006 tpqputs(TPQD_DMAX, "is_exception() before start_dma()!");
2007 /******************************************************************2008 ***** if start_dma() fails because the head is positioned 0 bytes2009 ***** before the FM, (causing EXCEPTION to be set) return_read_eof should2010 ***** be set to YES, and we should return total_bytes_done, rather than -ENXIO.2011 ***** The app should recognize this as an EOF condition.2012 ***************************************************************************/2013 stat = start_dma(READ, bytes_todo);
2014 if (stat == TE_OK) {2015 /* Wait for transfer to complete, interrupt should wake us */2016 while (dma_mode != 0) {2017 sleep_on(&qic02_tape_transfer);
2018 }2019 if (status_error)
2020 return_read_eof = YES;
2021 }elseif (stat != TE_END) {2022 /* should do sense() on error here */2023 #if 0
2024 return -ENXIO;
2025 #else2026 printk("Trouble: stat==%02x\n", stat);
2027 return_read_eof = YES;
2028 /*************** check EOF/EOT handling!!!!!! **/2029 #endif2030 }2031 end_dma(&bytes_done);
2032 if (bytes_done>bytes_todo) {2033 tpqputs(TPQD_ALWAYS, "read: Oops, read more bytes than requested");
2034 return -EIO;
2035 }2036 /* copy buffer to user-space in one go */2037 if (bytes_done>0)
2038 memcpy_tofs( (void *) buf, (void *) buffaddr, bytes_done);
2039 #if 1
2040 /* Checks Ton's patch below */2041 if ((return_read_eof == NO) && (status_eof_detected == YES)) {2042 printk(TPQIC02_NAME ": read(): return_read_eof=%d, status_eof_detected=YES. return_read_eof:=YES\n", return_read_eof);
2043 }2044 #endif2045 if ((bytes_todo != bytes_done) || (status_eof_detected == YES))
2046 /* EOF or EOM detected. return EOF next time. */2047 return_read_eof = YES;
2048 }/* else: ignore read request for 0 bytes */2049
2050 if (bytes_done>0) {2051 status_bytes_rd = YES;
2052 buf += bytes_done;
2053 filp->f_pos += bytes_done;
2054 total_bytes_done += bytes_done;
2055 count -= bytes_done;
2056 }2057 }2058 tpqputs(TPQD_ALWAYS, "read request for <0 bytes");
2059 return -EINVAL;
2060 }/* qic02_tape_read */2061
2062
2063
2064 /* The drive detects near-EOT by means of the holes in the tape.2065 * When the holes are detected, there is some space left. The drive2066 * reports this as a TP_EOM exception. After clearing the exception,2067 * the drive should accept two extra blocks.2068 *2069 * It seems there are some archiver programs that would like to use the2070 * extra space for writing a continuation marker. The driver should return2071 * end-of-file to the user program on writes, when the holes are detected.2072 * If the user-program wants to use the extra space, it should use the2073 * MTNOP ioctl() to get the generic status register and may then continue2074 * writing (max 1kB). ----------- doesn't work yet...............2075 *2076 * EOF behaviour on writes:2077 * If there is enough room, write all of the data.2078 * If there is insufficient room, write as much as will fit and2079 * return the amount written. If the requested amount differs from the2080 * written amount, the application program should recognize that as the2081 * end of file. Subsequent writes will return -ENOSPC.2082 * Unless the minor bits specify a rewind-on-close, the tape will not2083 * be rewound when it is full. The user-program should do that, if desired.2084 * If the driver were to do that automatically, a user-program could be 2085 * confused about the EOT/BOT condition after re-opening the tape device.2086 *2087 * Multiple volume support: Tar closes the tape device before prompting for2088 * the next tape. The user may then insert a new tape and tar will open the2089 * tape device again. The driver will detect an exception status in (No Cartridge)2090 * and force a rewind. After that tar may continue writing.2091 */2092 staticintqic02_tape_write(structinode * inode, structfile * filp, char * buf, intcount)
/* */2093 {2094 interror;
2095 dev_tdev = inode->i_rdev;
2096 unsignedshortflags = filp->f_flags;
2097 unsignedlongbytes_todo, bytes_done, total_bytes_done = 0;
2098
2099 if (status_zombie==YES) {2100 tpqputs(TPQD_ALWAYS, "configs not set");
2101 return -ENXIO;
2102 }2103
2104 if (TP_DIAGS(current_tape_dev))
2105 /* can't print a ``long long'' (for filp->f_pos), so chop it */2106 printk(TPQIC02_NAME ": request WRITE, minor=%x, buf=%p, count=%x, pos=%lx, flags=%x\n",
2107 MINOR(dev), buf, count, (unsignedlong) filp->f_pos, flags);
2108
2109 if (count % TAPE_BLKSIZE) {/* only allow mod 512 bytes at a time */2110 tpqputs(TPQD_BLKSZ, "Wrong block size");
2111 return -EINVAL;
2112 }2113
2114 if (mode_access==READ) {2115 tpqputs(TPQD_ALWAYS, "Not in write mode");
2116 return -EACCES;
2117 }2118
2119 /* open() does a sense() and we can assume the tape isn't changed2120 * between open() and release(), so the tperror.exs bits will still2121 * be valid.2122 */2123 if ((tperror.exs & TP_ST0) && (tperror.exs & TP_WRP)) {2124 tpqputs(TPQD_ALWAYS, "Cartridge is write-protected.");
2125 return -EACCES; /* don't even try when write protected */2126 }2127
2128 /* Make sure buffer is safe to read from. */2129 error = verify_area(VERIFY_READ, buf, count);
2130 if (error)
2131 returnerror;
2132
2133 if (doing_read == YES)
2134 terminate_read(0);
2135
2136 while (count>=0) {2137 /* see how much fits in the kernel buffer */2138 bytes_done = 0;
2139 bytes_todo = TPQBUF_SIZE;
2140 if (bytes_todo>count)
2141 bytes_todo = count;
2142
2143 if (return_write_eof == YES) {2144 /* return_write_eof should be reset on reverse tape movements. */2145
2146 if (reported_write_eof==NO) {2147 if (bytes_todo>0) {2148 tpqputs(TPQD_ALWAYS, "partial write");
2149 /* partial write signals EOF to user program */2150 }2151 reported_write_eof = YES;
2152 returntotal_bytes_done;
2153 }else{2154 return -ENOSPC; /* return error */2155 }2156 }2157
2158 /* Quit when done. */2159 if (bytes_todo==0)
2160 returntotal_bytes_done;
2161
2162
2163 /* copy from user to DMA buffer and initiate transfer. */2164 if (bytes_todo>0) {2165 memcpy_fromfs( (void *) buffaddr, (void *) buf, bytes_todo);
2166
2167 /****************** similar problem with read() at FM could happen here at EOT.2168 ******************/2169
2170 /***** if at EOT, 0 bytes can be written. start_dma() will2171 ***** fail and write() will return ENXIO error2172 *****/2173 if (start_dma(WRITE, bytes_todo) != TE_OK) {2174 tpqputs(TPQD_ALWAYS, "write: start_dma() failed");
2175 /* should do sense() on error here */2176 return -ENXIO; /*********** FIXTHIS **************/2177 }2178
2179 /* Wait for write to complete, interrupt should wake us. */2180 while ((status_error == 0) && (dma_mode != 0)) {2181 sleep_on(&qic02_tape_transfer);
2182 }2183
2184 end_dma(&bytes_done);
2185 if (bytes_done>bytes_todo) {2186 tpqputs(TPQD_ALWAYS, "write: Oops, wrote more bytes than requested");
2187 return -EIO;
2188 }2189 /* If the dma-transfer was aborted because of an exception,2190 * status_error will have been set in the interrupt handler.2191 * Then end_dma() will do a sense().2192 * If the exception was EXC_EOM, the EW-hole was encountered2193 * and two more blocks could be written. For the time being we'll2194 * just consider this to be the EOT.2195 * Otherwise, something Bad happened, such as the maximum number2196 * of block-rewrites was exceeded. [e.g. A very bad spot on tape was2197 * encountered. Normally short dropouts are compensated for by2198 * rewriting the block in error, up to 16 times. I'm not sure2199 * QIC-24 drives can do this.]2200 */2201 if (status_error) {2202 if (status_eom_detected == YES) {2203 tpqputs(TPQD_ALWAYS, "write: EW detected");
2204 return_write_eof = YES;
2205 }else{2206 /* probably EXC_RWA */2207 tpqputs(TPQD_ALWAYS, "write: dma: error in writing");
2208 return -EIO;
2209 }2210 }2211 if (bytes_todo != bytes_done)
2212 /* EOF or EOM detected. return EOT next time. */2213 return_write_eof = YES;
2214 }2215 /* else: ignore write request for 0 bytes. */2216
2217 if (bytes_done>0) {2218 status_bytes_wr = YES;
2219 buf += bytes_done;
2220 filp->f_pos += bytes_done;
2221 total_bytes_done += bytes_done;
2222 count -= bytes_done;
2223 }2224 }2225 tpqputs(TPQD_ALWAYS, "write request for <0 bytes");
2226 if (TPQDBG(DEBUG))
2227 printk(TPQIC02_NAME ": status_bytes_wr %x, buf %p, total_bytes_done %lx, count %x\n", status_bytes_wr, buf, total_bytes_done, count);
2228 return -EINVAL;
2229 }/* qic02_tape_write */2230
2231
2232
2233 /* qic02_tape_open()2234 * We allow the device to be opened, even if it is marked 'dead' because2235 * we want to be able to reset the tape device without rebooting.2236 * Only one open tape file at a time, except when minor=255.2237 * Minor 255 is only allowed for resetting and always returns <0.2238 * 2239 * The density command is only allowed when TP_BOM is set. Thus, remember2240 * the most recently used minor bits. When they are different from the2241 * remembered values, rewind the tape and set the required density.2242 * Don't rewind if the minor bits specify density 0.2243 */2244 staticintqic02_tape_open(structinode * inode, structfile * filp)
/* */2245 {2246 dev_tdev = inode->i_rdev;
2247 unsignedshortflags = filp->f_flags;
2248 unsignedshortdens = 0;
2249 ints;
2250
2251
2252 if (TP_DIAGS(dev)) {2253 printk("qic02_tape_open: dev=%x, flags=%x ", dev, flags);
2254 }2255
2256 if (MINOR(dev)==255) /* special case for resetting */2257 if (suser())
2258 return (tape_reset(1)==TE_OK) ? -EAGAIN : -ENXIO;
2259 else2260 return -EPERM;
2261
2262 if (status_dead==YES)
2263 /* Allow `mt reset' ioctl() even when already open()ed. */2264 return 0;
2265
2266 /* Only one at a time from here on... */2267 if (filp->f_count>1) {/* filp->f_count==1 for the first open() */2268 return -EBUSY;
2269 }2270
2271 if (status_zombie==YES)
2272 /* no irq/dma/port stuff allocated yet, no reset done2273 * yet, so return until MTSETCONFIG has been done.2274 */2275 return 0;
2276
2277 status_bytes_rd = NO;
2278 status_bytes_wr = NO;
2279
2280 return_read_eof = NO; /********????????????????*****/2281 return_write_eof = (status_eot_detected)? YES : NO;
2282
2283 /* Clear this in case user app close()d before reading EOF token */2284 status_eof_detected = NO;
2285
2286 reported_read_eof = NO;
2287 reported_write_eof = NO;
2288
2289
2290 switch (flags & O_ACCMODE) {2291 caseO_RDONLY:
2292 mode_access = READ;
2293 break;
2294 caseO_WRONLY: /* Fallthru... Strictly speaking this is not correct... */2295 caseO_RDWR: /* Reads are allowed as long as nothing is written */2296 mode_access = WRITE;
2297 break;
2298 }2299
2300 /* This is to avoid tape-changed problems (TP_CNI exception).2301 *2302 * Since removing the cartridge will not raise an exception,2303 * we always do a tp_sense() to make sure we have the proper2304 * CNI status, the 2150L may need an additional sense.... - Eddy2305 */2306 s = tp_sense(TP_WRP|TP_EOM|TP_BOM|TP_CNI|TP_EOR);
2307
2308 if (s == TE_OK)
2309 /* Try to clear cartridge-changed status for Archive-2150L */2310 if ((tperror.exs & TP_ST0) && (tperror.exs & TP_CNI))
2311 s = tp_sense(TP_WRP|TP_EOM|TP_BOM|TP_CNI|TP_EOR);
2312
2313 if (s != TE_OK) {2314 tpqputs(TPQD_ALWAYS, "open: sense() failed");
2315 return -EIO;
2316 }2317
2318 /* exception bits should be up-to-date now, so check for2319 * tape presence and exit if absent.2320 * Even `mt stat' will fail without a tape.2321 */2322 if ((tperror.exs & TP_ST0) && (tperror.exs & TP_CNI)) {2323 tpqputs(TPQD_ALWAYS, "No tape present.");
2324 return -EIO;
2325 }2326
2327 /* At this point we can assume that a tape is present and2328 * that it will remain present until release() is called.2329 */2330
2331 /* not allowed to do QCMD_DENS_* unless tape is rewound */2332 if ((TP_DENS(dev)!=0) && (TP_DENS(current_tape_dev) != TP_DENS(dev))) {2333 /* force rewind if minor bits have changed,2334 * i.e. user wants to use tape in different format.2335 * [assuming single drive operation]2336 */2337 if (TP_HAVE_DENS) {2338 tpqputs(TPQD_REWIND, "Density minor bits have changed. Forcing rewind.");
2339 need_rewind = YES;
2340 }2341 }else{2342 /* density bits still the same, but TP_DIAGS bit 2343 * may have changed.2344 */2345 current_tape_dev = dev;
2346 }2347
2348 if (need_rewind == YES) {/***************** CHECK THIS!!!!!!!! **********/2349 s = do_qic_cmd(QCMD_REWIND, TIM_R);
2350 if (s != 0) {2351 tpqputs(TPQD_ALWAYS, "open: rewind failed");
2352 return -EIO;
2353 }2354 }2355
2356
2357 /* Note: After a reset command, the controller will rewind the tape2358 * just before performing any tape movement operation! ************ SO SET need_rewind flag!!!!!2359 */2360 if (status_dead==YES) {2361 tpqputs(TPQD_ALWAYS, "open: tape dead, attempting reset");
2362 if (tape_reset(1)!=TE_OK) {2363 return -ENXIO;
2364 }else{2365 status_dead = NO;
2366 if (tp_sense(~(TP_ST1|TP_ILL)) != TE_OK) {2367 tpqputs(TPQD_ALWAYS, "open: tp_sense() failed\n");
2368 status_dead = YES; /* try reset next time */2369 return -EIO;
2370 }2371 }2372 }2373
2374 /* things should be ok, once we get here */2375
2376
2377 /* set density: only allowed when TP_BOM status bit is set,2378 * so we must have done a rewind by now. If not, just skip over.2379 * Only give set density command when minor bits have changed.2380 */2381 if (TP_DENS(current_tape_dev) == TP_DENS(dev) )
2382 return 0;
2383
2384 current_tape_dev = dev;
2385 need_rewind = NO;
2386 if (TP_HAVE_DENS)
2387 dens = TP_DENS(dev);
2388
2389 if (dens < sizeof(format_names)/sizeof(char *))
2390 printk(TPQIC02_NAME ": format: %s%s\n", (dens!=0)? "QIC-" : "", format_names[dens]);
2391 else2392 tpqputs(TPQD_REWIND, "Wait for retensioning...");
2393
2394 switch (TP_DENS(dev)) {2395 case 0: /* Minor 0 is for drives without set-density support */2396 s = 0;
2397 break;
2398 case 1:
2399 s = do_qic_cmd(QCMD_DENS_11, TIM_S);
2400 break;
2401 case 2:
2402 s = do_qic_cmd(QCMD_DENS_24, TIM_S);
2403 break;
2404 case 3:
2405 s = do_qic_cmd(QCMD_DENS_120, TIM_S);
2406 break;
2407 case 4:
2408 s = do_qic_cmd(QCMD_DENS_150, TIM_S);
2409 break;
2410 case 5:
2411 s = do_qic_cmd(QCMD_DENS_300, TIM_S);
2412 break;
2413 case 6:
2414 s = do_qic_cmd(QCMD_DENS_600, TIM_S);
2415 break;
2416 default: /* otherwise do a retension before anything else */2417 s = do_qic_cmd(QCMD_RETEN, TIM_R);
2418 }2419 if (s != 0) {2420 status_dead = YES; /* force reset */2421 current_tape_dev = 0xff80;
2422 return -EIO;
2423 }2424
2425 return 0;
2426 }/* qic02_tape_open */2427
2428
2429
2430 staticintqic02_tape_readdir(structinode * inode, structfile * filp, structdirent * dp, intcount)
/* */2431 {2432 return -ENOTDIR; /* not supported */2433 }/* qic02_tape_readdir */2434
2435
2436
2437 staticvoidqic02_tape_release(structinode * inode, structfile * filp)
/* */2438 {2439 dev_tdev = inode->i_rdev;
2440
2441 if (TP_DIAGS(dev))
2442 printk("qic02_tape_release: dev=%x\n", dev);
2443
2444 if (status_zombie==YES) /* don't rewind in zombie mode */2445 return;
2446
2447 /* Terminate any pending write cycle. Terminating the read-cycle2448 * is delayed until it is required to do so for a new command.2449 */2450 terminate_write(-1);
2451
2452 if (status_dead==YES)
2453 tpqputs(TPQD_ALWAYS, "release: device dead!?");
2454
2455 /* Rewind only if minor number requires it AND 2456 * read/writes have been done. ************* IS THIS CORRECT??????????2457 */2458 if ((TP_REWCLOSE(dev)) && (status_bytes_rd | status_bytes_wr)) {2459 tpqputs(TPQD_REWIND, "release: Doing rewind...");
2460 (void) do_qic_cmd(QCMD_REWIND, TIM_R);
2461 }2462
2463 return;
2464 }/* qic02_tape_release */2465
2466
2467 #ifdefCONFIG_QIC02_DYNCONF2468 /* Set masks etc. based on the interface card type. */2469 intupdate_ifc_masks(intifc)
/* */2470 {2471 QIC02_TAPE_IFC = ifc;
2472
2473 if ((QIC02_TAPE_IFC == WANGTEK) || (QIC02_TAPE_IFC == EVEREX)) {2474 QIC02_STAT_PORT = QIC02_TAPE_PORT;
2475 QIC02_CTL_PORT = QIC02_TAPE_PORT;
2476 QIC02_CMD_PORT = QIC02_TAPE_PORT+1;
2477 QIC02_DATA_PORT = QIC02_TAPE_PORT+1;
2478 QIC02_STAT_READY = WT_QIC02_STAT_READY;
2479 QIC02_STAT_EXCEPTION = WT_QIC02_STAT_EXCEPTION;
2480 QIC02_STAT_MASK = WT_QIC02_STAT_MASK;
2481
2482 QIC02_STAT_RESETMASK = WT_QIC02_STAT_RESETMASK;
2483 QIC02_STAT_RESETVAL = WT_QIC02_STAT_RESETVAL;
2484
2485 QIC02_CTL_RESET = WT_QIC02_CTL_RESET;
2486 QIC02_CTL_REQUEST = WT_QIC02_CTL_REQUEST;
2487
2488 if (QIC02_TAPE_DMA == 3)
2489 WT_CTL_DMA = WT_CTL_DMA3;
2490 elseif (QIC02_TAPE_DMA == 1)
2491 WT_CTL_DMA = WT_CTL_DMA1;
2492 else{2493 tpqputs(TPQD_ALWAYS, "Unsupported or incorrect DMA channel");
2494 return -EIO;
2495 }2496
2497 if (QIC02_TAPE_IFC == EVEREX) {2498 /* Everex is a special case for Wangtek (actually2499 * it's the other way 'round, but I saw Wangtek first)2500 */2501 if (QIC02_TAPE_DMA==3)
2502 WT_CTL_DMA = WT_CTL_DMA1;
2503 /* Fixup the kernel copy of the IFC type to that2504 * we don't have to distinguish between Wangtek and2505 * and Everex at runtime.2506 */2507 QIC02_TAPE_IFC = WANGTEK;
2508 }2509 }elseif (QIC02_TAPE_IFC == ARCHIVE) {2510 QIC02_STAT_PORT = QIC02_TAPE_PORT+1;
2511 QIC02_CTL_PORT = QIC02_TAPE_PORT+1;
2512 QIC02_CMD_PORT = QIC02_TAPE_PORT;
2513 QIC02_DATA_PORT = QIC02_TAPE_PORT;
2514 QIC02_STAT_READY = AR_QIC02_STAT_READY;
2515 QIC02_STAT_EXCEPTION = AR_QIC02_STAT_EXCEPTION;
2516 QIC02_STAT_MASK = AR_QIC02_STAT_MASK;
2517
2518 QIC02_STAT_RESETMASK = AR_QIC02_STAT_RESETMASK;
2519 QIC02_STAT_RESETVAL = AR_QIC02_STAT_RESETVAL;
2520
2521 QIC02_CTL_RESET = AR_QIC02_CTL_RESET;
2522 QIC02_CTL_REQUEST = AR_QIC02_CTL_REQUEST;
2523
2524 if (QIC02_TAPE_DMA > 3) {2525 tpqputs(TPQD_ALWAYS, "Unsupported or incorrect DMA channel");
2526 return -EIO;
2527 }2528 }elseif (QIC02_TAPE_IFC == MOUNTAIN) {2529 QIC02_STAT_PORT = QIC02_TAPE_PORT+1;
2530 QIC02_CTL_PORT = QIC02_TAPE_PORT+1;
2531 QIC02_CMD_PORT = QIC02_TAPE_PORT;
2532 QIC02_DATA_PORT = QIC02_TAPE_PORT;
2533
2534 QIC02_STAT_READY = MTN_QIC02_STAT_READY;
2535 QIC02_STAT_EXCEPTION = MTN_QIC02_STAT_EXCEPTION;
2536 QIC02_STAT_MASK = MTN_QIC02_STAT_MASK;
2537
2538 QIC02_STAT_RESETMASK = MTN_QIC02_STAT_RESETMASK;
2539 QIC02_STAT_RESETVAL = MTN_QIC02_STAT_RESETVAL;
2540
2541 QIC02_CTL_RESET = MTN_QIC02_CTL_RESET;
2542 QIC02_CTL_REQUEST = MTN_QIC02_CTL_REQUEST;
2543
2544 if (QIC02_TAPE_DMA > 3) {2545 tpqputs(TPQD_ALWAYS, "Unsupported or incorrect DMA channel");
2546 return -EIO;
2547 }2548 }else{2549 tpqputs(TPQD_ALWAYS, "Invalid interface type");
2550 return -ENXIO;
2551 }2552 return 0;
2553 }/* update_ifc-masks */2554 #endif2555
2556
2557 /* ioctl allows user programs to rewind the tape and stuff like that */2558 staticintqic02_tape_ioctl(structinode * inode, structfile * filp,
/* */2559 unsignedintiocmd, unsignedlongioarg)
2560 {2561 interror;
2562 shorti;
2563 intdev_maj = MAJOR(inode->i_rdev);
2564 intc;
2565 structmtopoperation;
2566 char *stp, *argp;
2567 unsignedcharblk_addr[6];
2568 structmtposioctl_tell;
2569
2570
2571 if (TP_DIAGS(current_tape_dev))
2572 printk(TPQIC02_NAME ": ioctl(%4x, %4x, %4lx)\n", dev_maj, iocmd, ioarg);
2573
2574 if (!inode || !ioarg)
2575 return -EINVAL;
2576
2577 /* check iocmd first */2578
2579 if (dev_maj != QIC02_TAPE_MAJOR) {2580 printk(TPQIC02_NAME ": Oops! Wrong device?\n");
2581 /* A panic() would be appropriate here */2582 return -ENODEV;
2583 }2584
2585 c = iocmd & IOCCMD_MASK;
2586
2587 #ifdefDDIOCSDBG2588 /* Check for DDI Debug Control, contributed by FvK, edited by HHB. */2589 if (c == DDIOCSDBG) {2590 if (!suser())
2591 return -EPERM;
2592 verify_area(VERIFY_READ, (int *) ioarg, sizeof(int));
2593 c = get_user_long((int *) ioarg);
2594 if (c==0) {2595 QIC02_TAPE_DEBUG = 0;
2596 return 0;
2597 }2598 if ((c>=1) && (c<=32)) {2599 QIC02_TAPE_DEBUG |= (1 << (c-1));
2600 return 0;
2601 }2602 if (c >= 128) {2603 QIC02_TAPE_DEBUG &= ~(1 << (c - 128));
2604 return 0;
2605 }2606 return -EINVAL;
2607 }2608 #endif2609
2610 #ifdefCONFIG_QIC02_DYNCONF2611 if (c == (MTIOCGETCONFIG & IOCCMD_MASK)) {2612 if (((iocmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT) != sizeof(structmtconfiginfo)) {2613 tpqputs(TPQD_ALWAYS, "sizeof(struct mtconfiginfo) does not match!");
2614 return -EFAULT;
2615 }2616
2617 /* check for valid user address */2618 error = verify_area(VERIFY_WRITE, (void *) ioarg, sizeof(qic02_tape_dynconf));
2619 if (error)
2620 returnerror;
2621 /* copy current settings to user space */2622 stp = (char *) &qic02_tape_dynconf;
2623 argp = (char *) ioarg;
2624 for (i=0; i<sizeof(qic02_tape_dynconf); i++)
2625 put_user_byte(*stp++, argp++);
2626 return 0;
2627
2628 }elseif (c == (MTIOCSETCONFIG & IOCCMD_MASK)) {2629 staticintqic02_get_resources(void), qic02_release_resources(void);
2630
2631 /* One should always do a MTIOCGETCONFIG first, then update2632 * user-settings, then write back with MTIOCSETCONFIG.2633 * Re-open() the device before actual use to make sure2634 * everything is initialized.2635 */2636 if (((iocmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT) != sizeof(structmtconfiginfo)) {2637 tpqputs(TPQD_ALWAYS, "sizeof(struct mtconfiginfo) does not match!");
2638 return -EFAULT;
2639 }2640 if (!suser())
2641 return -EPERM;
2642 if ((doing_read!=NO) || (doing_write!=NO))
2643 return -EBUSY;
2644 error = verify_area(VERIFY_READ, (char *) ioarg, sizeof(qic02_tape_dynconf));
2645 if (error)
2646 returnerror;
2647
2648 /* copy struct from user space to kernel space */2649 stp = (char *) &qic02_tape_dynconf;
2650 argp = (char *) ioarg;
2651 for (i=0; i<sizeof(qic02_tape_dynconf); i++)
2652 *stp++ = get_user_byte(argp++);
2653 if (status_zombie==NO)
2654 qic02_release_resources(); /* and go zombie */2655 if (update_ifc_masks(qic02_tape_dynconf.ifc_type))
2656 return -EIO;
2657 if (qic02_get_resources())
2658 return -ENXIO;
2659 return 0;
2660
2661 }2662 if (status_zombie==YES) {2663 tpqputs(TPQD_ALWAYS, "Configs not set");
2664 return -ENXIO;
2665 }2666 #endif2667 if (c == (MTIOCTOP & IOCCMD_MASK)) {2668
2669 /* Compare expected struct size and actual struct size. This2670 * is useful to catch programs compiled with old #includes.2671 */2672 if (((iocmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT) != sizeof(structmtop)) {2673 tpqputs(TPQD_ALWAYS, "sizeof(struct mtop) does not match!");
2674 return -EFAULT;
2675 }2676 error = verify_area(VERIFY_READ, (char *) ioarg, sizeof(operation));
2677 if (error)
2678 returnerror;
2679
2680 /* copy mtop struct from user space to kernel space */2681 stp = (char *) &operation;
2682 argp = (char *) ioarg;
2683 for (i=0; i<sizeof(operation); i++)
2684 *stp++ = get_user_byte(argp++);
2685
2686 /* ---note: mt_count is signed, negative seeks must be2687 * --- translated to seeks in opposite direction!2688 * (only needed for Sun-programs, I think.)2689 */2690 /* ---note: MTFSF with count 0 should position the2691 * --- tape at the beginning of the current file.2692 */2693
2694 if (TP_DIAGS(current_tape_dev))
2695 printk("OP op=%4x, count=%4x\n", operation.mt_op, operation.mt_count);
2696
2697 if (operation.mt_count < 0)
2698 tpqputs(TPQD_ALWAYS, "Warning: negative mt_count ignored");
2699
2700 ioctl_status.mt_resid = operation.mt_count;
2701 if (operation.mt_op == MTSEEK) {2702 if (!TP_HAVE_SEEK)
2703 return -ENOTTY;
2704 seek_addr_buf[0] = (operation.mt_count>>16)&0xff;
2705 seek_addr_buf[1] = (operation.mt_count>>8)&0xff;
2706 seek_addr_buf[2] = (operation.mt_count)&0xff;
2707 if (operation.mt_count>>24)
2708 return -EINVAL;
2709 if ((error = do_ioctl_cmd(operation.mt_op)) != 0)
2710 returnerror;
2711 ioctl_status.mt_resid = 0;
2712 }else{2713 while (operation.mt_count > 0) {2714 operation.mt_count--;
2715 if ((error = do_ioctl_cmd(operation.mt_op)) != 0)
2716 returnerror;
2717 ioctl_status.mt_resid = operation.mt_count;
2718 }2719 }2720 return 0;
2721
2722 }elseif (c == (MTIOCGET & IOCCMD_MASK)) {2723 if (TP_DIAGS(current_tape_dev))
2724 printk("GET ");
2725
2726 /* compare expected struct size and actual struct size */2727 if (((iocmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT) != sizeof(structmtget)) {2728 tpqputs(TPQD_ALWAYS, "sizeof(struct mtget) does not match!");
2729 return -EFAULT;
2730 }2731
2732 /* check for valid user address */2733 error = verify_area(VERIFY_WRITE, (void *) ioarg, sizeof(ioctl_status));
2734 if (error)
2735 returnerror;
2736
2737 /* It appears (gmt(1)) that it is normal behaviour to2738 * first set the status with MTNOP, and then to read2739 * it out with MTIOCGET2740 */2741
2742 /* copy results to user space */2743 stp = (char *) &ioctl_status;
2744 argp = (char *) ioarg;
2745 for (i=0; i<sizeof(ioctl_status); i++)
2746 put_user_byte(*stp++, argp++);
2747 return 0;
2748
2749
2750 }elseif (TP_HAVE_TELL && (c == (MTIOCPOS & IOCCMD_MASK))) {2751 if (TP_DIAGS(current_tape_dev))
2752 printk("POS ");
2753
2754 /* compare expected struct size and actual struct size */2755 if (((iocmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT) != sizeof(structmtpos)) {2756 tpqputs(TPQD_ALWAYS, "sizeof(struct mtpos) does not match!");
2757 return -EFAULT;
2758 }2759
2760 /* check for valid user address */2761 error = verify_area(VERIFY_WRITE, (void *) ioarg, sizeof(ioctl_tell));
2762 if (error)
2763 returnerror;
2764
2765 tpqputs(TPQD_IOCTLS, "MTTELL reading block address");
2766 if ((doing_read==YES) || (doing_write==YES))
2767 finish_rw(AR_QCMDV_TELL_BLK);
2768
2769 c = rdstatus((char *) blk_addr, sizeof(blk_addr), AR_QCMDV_TELL_BLK);
2770 if (c!=TE_OK)
2771 return -EIO;
2772
2773 ioctl_tell.mt_blkno = (blk_addr[3] << 16) | (blk_addr[4] << 8) | blk_addr[5];
2774
2775 /* copy results to user space */2776 stp = (char *) &ioctl_tell;
2777 argp = (char *) ioarg;
2778 for (i=0; i<sizeof(ioctl_tell); i++)
2779 put_user_byte(*stp++, argp++);
2780 return 0;
2781
2782 }else2783 return -ENOTTY; /* Other cmds not supported. */2784 }/* qic02_tape_ioctl */2785
2786
2787
2788 /* These are (most) of the interface functions: */2789 staticstructfile_operationsqic02_tape_fops = {2790 qic02_tape_lseek, /* not allowed */2791 qic02_tape_read, /* read */2792 qic02_tape_write, /* write */2793 qic02_tape_readdir, /* not allowed */2794 NULL, /* select ??? */2795 qic02_tape_ioctl, /* ioctl */2796 NULL, /* mmap not allowed */2797 qic02_tape_open, /* open */2798 qic02_tape_release, /* release */2799 NULL, /* fsync */2800 NULL, /* fasync */2801 NULL, /* check_media_change */2802 NULL/* revalidate */2803 };
2804
2805 /* align `a' at `size' bytes. `size' must be a power of 2 */2806 staticinlineunsignedlongconstalign_buffer(unsignedlonga, unsignedsize)
/* */2807 {2808 if (a & (size-1)) /* if not aligned */2809 return (a | (size-1)) + 1;
2810 else/* else is aligned */2811 returna;
2812 }2813
2814
2815
2816 staticvoidqic02_release_resources(void)
/* */2817 {2818 free_irq(QIC02_TAPE_IRQ);
2819 free_dma(QIC02_TAPE_DMA);
2820 status_zombie = YES;
2821 }/* qic02_release_resources */2822
2823
2824
2825
2826 staticintqic02_get_resources(void)
/* */2827 {2828 /* First perform some checks. If one of them fails,2829 * the tape driver will not be registered to the system.2830 */2831 if (QIC02_TAPE_IRQ>16) {2832 tpqputs(TPQD_ALWAYS, "Bogus interrupt number.");
2833 return -1;
2834 }2835
2836 /* for DYNCONF, allocating DMA & IRQ should not be done until 2837 * the config parameters have been set using MTSETCONFIG.2838 */2839
2840 /* get IRQ */2841 if (request_irq(QIC02_TAPE_IRQ, qic02_tape_interrupt, SA_INTERRUPT, "QIC-02")) {2842 printk(TPQIC02_NAME ": can't allocate IRQ%d for QIC-02 tape\n",
2843 QIC02_TAPE_IRQ);
2844 status_zombie = YES;
2845 return -1;
2846 }2847
2848 /* After IRQ, allocate DMA channel */2849 if (request_dma(QIC02_TAPE_DMA,"QIC-02")) {2850 printk(TPQIC02_NAME ": can't allocate DMA%d for QIC-02 tape\n",
2851 QIC02_TAPE_DMA);
2852 free_irq(QIC02_TAPE_IRQ);
2853 status_zombie = YES;
2854 return -1;
2855 }2856
2857 printk(TPQIC02_NAME ": Settings: IRQ %d, DMA %d, IO 0x%x, IFC %s\n",
2858 QIC02_TAPE_IRQ, QIC02_TAPE_DMA,
2859 ((QIC02_TAPE_IFC==ARCHIVE) || (QIC02_TAPE_IFC==MOUNTAIN))?
2860 QIC02_CMD_PORT : QIC02_STAT_PORT,
2861 (QIC02_TAPE_IFC==MOUNTAIN)? "Mountain" :
2862 ((QIC02_TAPE_IFC==ARCHIVE)? "Archive" : "Wangtek"));
2863
2864 if (tape_reset(0)!=TE_OK || tp_sense(TP_WRP|TP_POR|TP_CNI)!=TE_OK) {2865 /* No drive detected, so vanish */2866 tpqputs(TPQD_ALWAYS, "No drive detected -- releasing irq and dma.");
2867 status_dead = YES;
2868 qic02_release_resources();
2869 return -1;
2870 }2871
2872 /* All should be ok now */2873 status_zombie = NO;
2874 return 0;
2875 }/* qic02_get_resources */2876
2877
2878
2879 longqic02_tape_init(longkmem_start)
/* */2880 /* Shouldn't this be a caddr_t ? */2881 {2882
2883 if (TPSTATSIZE != 6) {2884 printk(TPQIC02_NAME ": internal error: tpstatus struct incorrect!\n");
2885 returnkmem_start;
2886 }2887 if ((TPQBUF_SIZE<512) || (TPQBUF_SIZE>=0x10000)) {2888 printk(TPQIC02_NAME ": internal error: DMA buffer size out of range\n");
2889 returnkmem_start;
2890 }2891
2892 QIC02_TAPE_DEBUG = TPQD_DEFAULT_FLAGS;
2893
2894 #ifndefCONFIG_QIC02_DYNCONF2895 printk(TPQIC02_NAME ": IRQ %d, DMA %d, IO 0x%x, IFC %s, %s, %s\n",
2896 QIC02_TAPE_IRQ, QIC02_TAPE_DMA,
2897 # ifQIC02_TAPE_IFC == WANGTEK2898 QIC02_STAT_PORT, "Wangtek",
2899 # elifQIC02_TAPE_IFC == ARCHIVE2900 QIC02_CMD_PORT, "Archive",
2901 # elifQIC02_TAPE_IFC == MOUNTAIN2902 QIC02_CMD_PORT, "Mountain",
2903 # else2904 # error2905 # endif2906 rcs_revision, rcs_date);
2907 if (qic02_get_resources())
2908 returnkmem_start;
2909 #else2910 printk(TPQIC02_NAME ": Runtime config, %s, %s\n",
2911 rcs_revision, rcs_date);
2912
2913 QIC02_TAPE_IRQ = BOGUS_IRQ; /* invalid value */2914 #endif2915
2916 printk(TPQIC02_NAME ": DMA buffers: %u blocks", NR_BLK_BUF);
2917
2918 /* Setup the page-address for the dma transfer.2919 * This assumes a one-to-one identity mapping between2920 * kernel addresses and physical memory.2921 */2922 buffaddr = align_buffer((unsignedlong) &qic02_tape_buf, TAPE_BLKSIZE);
2923 printk(", at address 0x%lx (0x%lx)\n", buffaddr, (unsignedlong) &qic02_tape_buf);
2924
2925 #ifndefCONFIG_MAX_16M2926 if (buffaddr+TPQBUF_SIZE>=0x1000000) {2927 printk(TPQIC02_NAME ": DMA buffer *must* be in lower 16MB\n");
2928 returnkmem_start;
2929 }2930 #endif2931
2932 /* If we got this far, install driver functions */2933 if (register_chrdev(QIC02_TAPE_MAJOR, TPQIC02_NAME, &qic02_tape_fops)) {2934 printk(TPQIC02_NAME ": Unable to get chrdev major %d\n", QIC02_TAPE_MAJOR);
2935 #ifndefCONFIG_QIC02_DYNCONF2936 free_irq(QIC02_TAPE_IRQ);
2937 free_dma(QIC02_TAPE_DMA);
2938 #endif2939 returnkmem_start;
2940 }2941
2942 /* prepare timer */2943 TIMEROFF;
2944 timer_table[QIC02_TAPE_TIMER].expires = 0;
2945 timer_table[QIC02_TAPE_TIMER].fn = qic02_tape_times_out;
2946
2947 #ifndefCONFIG_QIC02_DYNCONF2948 if (tape_reset(0)!=TE_OK || tp_sense(TP_WRP|TP_POR|TP_CNI)!=TE_OK) {2949 /* No drive detected, so vanish */2950 tpqputs(TPQD_ALWAYS, "No drive detected -- driver going on vacation...");
2951 status_dead = YES;
2952 free_irq(QIC02_TAPE_IRQ);
2953 free_dma(QIC02_TAPE_DMA);
2954 unregister_chrdev(QIC02_TAPE_MAJOR, TPQIC02_NAME);
2955 returnkmem_start;
2956 }else{2957 if (is_exception()) {2958 tpqputs(TPQD_ALWAYS, "exception detected\n");
2959 (void) tp_sense(TP_WRP|TP_POR|TP_CNI);
2960 }2961 }2962 #endif2963
2964 /* initialize generic status for ioctl requests */2965
2966 ioctl_status.mt_type = QIC02_TAPE_DRIVE; /* MT_IS* id nr */2967
2968 ioctl_status.mt_resid = 0; /* ---residual count */2969 ioctl_status.mt_gstat = 0; /* ---generic status */2970 ioctl_status.mt_erreg = 0; /* not used */2971 ioctl_status.mt_fileno = 0; /* number of current file on tape */2972 ioctl_status.mt_blkno = 0; /* number of current (logical) block */2973
2974 returnkmem_start;
2975 }/* qic02_tape_init */2976