1 /* $Id: tpqic02.h,v 0.16 1993/04/19 23:15:39 root Exp root $ 2 * 3 * Include file for QIC-02 driver for Linux. 4 * 5 * Copyright (c) 1992 by H. H. Bergman. All rights reserved. 6 * 7 * ******* USER CONFIG SECTION BELOW ******* 8 */ 9 10 #ifndef _LINUX_TPQIC02_H 11 #define _LINUX_TPQIC02_H 12 13 #include <linux/config.h> 14 15 #if CONFIG_TAPE_QIC02 16 17 /* need to have TAPE_QIC02_DRIVE and TAPE_QIC02_IFC expand to something */ 18 #include <linux/mtio.h> 19 20 21 /* make TAPE_QIC02_IFC expand to something */ 22 #define WANGTEK 1 /* don't know about Wangtek QIC-36 */ 23 #define EVEREX WANGTEK /* I heard *some* of these are identical */ 24 #define EVEREX_811V EVEREX /* With TEAC MT 2ST 45D */ 25 #define EVEREX_831V EVEREX 26 #define ARCHIVE 3 27 #define ARCHIVE_SC400 ARCHIVE /* rumoured to be from the pre-SMD-age */ 28 #define ARCHIVE_SC402 ARCHIVE /* don't know much about SC400 */ 29 #define ARCHIVE_SC499 ARCHIVE /* SC402 and SC499R should be identical */ 30 31 32 /*********** START OF USER CONFIGURABLE SECTION ************/ 33 34 /* Tape configuration: 35 * 36 * Tape drive configuration: (MT_IS* constants are defined in sys/mtio.h) 37 * 38 * TAPE_QIC02_DRIVE = MT_ISWT5150 39 * - Wangtek 5150, format: up to QIC-150. 40 * TAPE_QIC02_DRIVE = MT_ISQIC02_ALL_FEATURES 41 * - Enables some optional QIC commands that some drives may lack. 42 * It is provided so you can check which are supported by your drive. 43 * Refer to tpqic02.h for others. 44 * 45 * Supported interface cards: TAPE_QIC02_IFC = 46 * WANGTEK, 47 * ARCHIVE_SC402, ARCHIVE_SC499. (both same programming interface) 48 * 49 * Make sure you have the I/O ports/DMA channels 50 * and IRQ stuff configured properly! 51 * NOTE: There may be other device drivers using the same major 52 * number. This must be avoided. Check for timer.h conflicts too. 53 */ 54 55 #define TAPE_QIC02_DRIVE MT_ISQIC02_ALL_FEATURES /* drive type */ 56 /* #define TAPE_QIC02_DRIVE MT_ISWT5150 */ 57 #define TAPE_QIC02_IFC WANGTEK /* interface card type */ 58 /* #define TAPE_QIC02_IFC ARCHIVE */ 59 #define TAPE_QIC02_MAJOR 12 /* major device number. /dev/loop seems to use 12 as well :-( */ 60 #define TAPE_QIC02_PORT 0x300 /* controller port adress */ 61 #define TAPE_QIC02_IRQ 5 /* Muhammad, please don't use 2 here. -- Hennus */ 62 #define TAPE_QIC02_DMA 1 /* either 1 or 3, because 2 is used by the floppy */ 63 64 65 /************ END OF USER CONFIGURABLE SECTION *************/ 66 67 68 /* NOTE: TP_HAVE_DENS should distinguish between available densities 69 * NOTE: Drive select is not implemented -- I have only one tape streamer, 70 * so I'm unable and unmotivated to test and implement that. ;-) ;-) 71 */ 72 #if TAPE_QIC02_DRIVE == MT_ISWT5150 73 #define TP_HAVE_DENS 74 #define TP_HAVE_BSF /* nope */ 75 #define TP_HAVE_FSR /* nope */ 76 #define TP_HAVE_BSR /* nope */ 77 #define TP_HAVE_EOD /* most of the time */ 78 #define TP_HAVE_RAS1 79 #define TP_HAVE_RAS2 80 81 #elif TAPE_QIC02_DRIVE == MT_ISARCHIVESC499 /* Archive SC-499 QIC-36 controller */ 82 #define TP_HAVE_DENS /* can do set density (QIC-11 / QIC-24) */ 83 #define TP_HAVE_FSR /* can skip one block forwards */ 84 #define TP_HAVE_BSR /* can skip one block backwards */ 85 #define TP_HAVE_EOD /* can seek to end of recorded data */ 86 #define TP_HAVE_RAS1 /* can run selftest 1 */ 87 #define TP_HAVE_RAS2 /* can run selftest 2 */ 88 /* These last two selftests shouldn't be used yet! */ 89 90 #elif (TAPE_QIC02_DRIVE == MT_ISARCHIVE_2060L) || (TAPE_QIC02_DRIVE == MT_ISARCHIVE_2150L) 91 #define TP_HAVE_DENS /* can do set density (QIC-24 / QIC-120 / QIC-150) */ 92 #define TP_HAVE_FSR /* can skip one block forwards */ 93 #define TP_HAVE_BSR /* can skip one block backwards */ 94 #define TP_HAVE_EOD /* can seek to end of recorded data */ 95 #define TP_HAVE_TELL /* can read current block address */ 96 #define TP_HAVE_SEEK /* can seek to block */ 97 #define TP_HAVE_RAS1 /* can run selftest 1 */ 98 #define TP_HAVE_RAS2 /* can run selftest 2 */ 99 /* These last two selftests shouldn't be used yet! */ 100 101 #elif TAPE_QIC02_DRIVE == MT_ISQIC02_ALL_FEATURES 102 #define TP_HAVE_DENS /* can do set density */ 103 #define TP_HAVE_BSF /* can search filemark backwards */ 104 #define TP_HAVE_FSR /* can skip one block forwards */ 105 #define TP_HAVE_BSR /* can skip one block backwards */ 106 #define TP_HAVE_EOD /* can seek to end of recorded data */ 107 #define TP_HAVE_SEEK /* seek to block address */ 108 #define TP_HAVE_TELL /* tell current block address */ 109 #define TP_HAVE_RAS1 /* can run selftest 1 */ 110 #define TP_HAVE_RAS2 /* can run selftest 2 */ 111 /* These last two selftests shouldn't be used yet! */ 112 113 114 #else 115 #error No QIC-02 tape drive type defined! 116 /* If your drive is not listed above, first try the 'ALL_FEATURES', 117 * to see what commands are supported, then create your own entry in 118 * the list above. You may want to mail it to me, so that I can include 119 * it in the next release. 120 */ 121 #endif 122 123 124 /* NR_BLK_BUF is a `tuneable parameter'. If you're really low on 125 * kernel space, you could decrease it to 1, or if you got a very 126 * slow machine, you could increase it up to 128 blocks. Less kernel 127 * buffer blocks result in more context-switching. 128 */ 129 #define NR_BLK_BUF 20 /* max 128 blocks */ 130 #define TAPE_BLKSIZE 512 /* streamer tape block size (fixed) */ 131 #define TPQBUF_SIZE (TAPE_BLKSIZE*NR_BLK_BUF) /* buffer size */ 132 133 134 #define BLOCKS_BEYOND_EW 2 /* nr of blocks after Early Warning hole */ 135 136 #if TAPE_QIC02_IFC == WANGTEK 137 /* Wangtek interface card port locations */ 138 # define QIC_STAT_PORT TAPE_QIC02_PORT 139 # define QIC_CTL_PORT TAPE_QIC02_PORT 140 # define QIC_CMD_PORT (TAPE_QIC02_PORT+1) 141 # define QIC_DATA_PORT (TAPE_QIC02_PORT+1) 142 143 /* status register bits (Active LOW!) */ 144 # define QIC_STAT_READY 0x01 145 # define QIC_STAT_EXCEPTION 0x02 146 # define QIC_STAT_MASK (QIC_STAT_READY|QIC_STAT_EXCEPTION) 147 148 # define QIC_STAT_RESETMASK 0x07 149 # define QIC_STAT_RESETVAL (QIC_STAT_RESETMASK & ~QIC_STAT_EXCEPTION) 150 151 /* controller register (QIC_CTL_PORT) bits */ 152 # define WT_CTL_ONLINE 0x01 153 # define QIC_CTL_RESET 0x02 154 # define QIC_CTL_REQUEST 0x04 155 # define WT_CTL_CMDOFF 0xC0 156 # if TAPE_QIC02_DMA == 3 /* dip-switches alone don't seem to cut it */ 157 # define WT_CTL_DMA 0x10 /* enable dma chan3 */ 158 # elif TAPE_QIC02_DMA == 1 159 # define WT_CTL_DMA 0x08 /* enable dma chan1 or chan2 */ 160 # else 161 # error Unsupported or incorrect DMA configuration. 162 # endif 163 164 #elif TAPE_QIC02_IFC == ARCHIVE 165 /* Archive interface card port locations */ 166 # define QIC_STAT_PORT (TAPE_QIC02_PORT+1) 167 # define QIC_CTL_PORT (TAPE_QIC02_PORT+1) 168 # define QIC_CMD_PORT (TAPE_QIC02_PORT) 169 # define QIC_DATA_PORT (TAPE_QIC02_PORT) 170 # define AR_START_DMA_PORT (TAPE_QIC02_PORT+2) 171 # define AR_RESET_DMA_PORT (TAPE_QIC02_PORT+3) 172 173 /* STAT port bits */ 174 # define AR_STAT_IRQF 0x80 /* active high, interrupt request flag */ 175 # define QIC_STAT_READY 0x40 /* active low */ 176 # define QIC_STAT_EXCEPTION 0x20 /* active low */ 177 # define QIC_STAT_MASK (QIC_STAT_READY|QIC_STAT_EXCEPTION) 178 # define AR_STAT_DMADONE 0x10 /* active high, DMA done */ 179 # define AR_STAT_DIRC 0x08 /* active high, direction */ 180 181 # define QIC_STAT_RESETMASK 0x70 /* check RDY,EXC,DMADONE */ 182 # define QIC_STAT_RESETVAL ((QIC_STAT_RESETMASK & ~AR_STAT_IRQF & ~QIC_STAT_EXCEPTION) | AR_STAT_DMADONE) 183 184 /* CTL port bits */ 185 # define QIC_CTL_RESET 0x80 /* drive reset */ 186 # define QIC_CTL_REQUEST 0x40 /* notify of new command */ 187 # define AR_CTL_IEN 0x20 /* interrupt enable */ 188 # define AR_CTL_DNIEN 0x10 /* done-interrupt enable */ 189 /* Note: All of these bits are cleared automatically when writing to 190 * AR_RESET_DMA_PORT. So AR_CTL_IEN and AR_CTL_DNIEN must be 191 * reprogrammed before the write to AR_START_DMA_PORT. 192 */ 193 194 # if TAPE_QIC02_DMA > 3 /* channel 2 is used by the floppy driver */ 195 # error DMA channels other than 1 and 3 are not supported. 196 # endif 197 198 #else 199 # error No valid interface card specified! 200 #endif /* TAPE_QIC02_IFC */ 201 202 /* Standard QIC-02 commands -- rev F. All QIC-02 drives must support these */ 203 #define QCMD_SEL_1 0x01 /* select drive 1 */ 204 #define QCMD_SEL_2 0x02 /* select drive 2 */ 205 #define QCMD_SEL_3 0x04 /* select drive 3 */ 206 #define QCMD_SEL_4 0x08 /* select drive 4 */ 207 #define QCMD_REWIND 0x21 /* rewind tape*/ 208 #define QCMD_ERASE 0x22 /* erase tape */ 209 #define QCMD_RETEN 0x24 /* retension tape */ 210 #define QCMD_WRT_DATA 0x40 /* write data */ 211 #define QCMD_WRT_FM 0x60 /* write file mark */ 212 #define QCMD_RD_DATA 0x80 /* read data */ 213 #define QCMD_RD_FM 0xA0 /* read file mark (forward direction) */ 214 #define QCMD_RD_STAT 0xC0 /* read status */ 215 216 /* Other (optional/vendor unique) commands */ 217 /* Density commands are only valid when TP_BOM is set! */ 218 #define QCMD_DENS_11 0x26 /* QIC-11 */ 219 #define QCMD_DENS_24 0x27 /* QIC-24: 9 track 60MB */ 220 #define QCMD_DENS_120 0x28 /* QIC-120: 15 track 120MB */ 221 #define QCMD_DENS_150 0x29 /* QIC-150: 18 track 150MB */ 222 #define QCMD_DENS_300 0x2A /* QIC-300/QIC-2100 */ 223 #define QCMD_DENS_600 0x2B /* QIC-600/QIC-2200 */ 224 /* don't know about QIC-1000 and QIC-1350 */ 225 226 #define QCMD_WRTNU_DATA 0x40 /* write data, no underruns, insert filler. */ 227 #define QCMD_SPACE_FWD 0x81 /* skip next block */ 228 #define QCMD_SPACE_BCK 0x89 /* move tape head one block back -- very useful! */ 229 #define QCMD_RD_FM_BCK 0xA8 /* read filemark (backwards) */ 230 #define QCMD_SEEK_EOD 0xA3 /* skip to EOD */ 231 #define QCMD_RD_STAT_X1 0xC1 /* read extended status 1 */ 232 #define QCMD_RD_STAT_X2 0xC4 /* read extended status 2 */ 233 #define QCMD_RD_STAT_X3 0xE0 /* read extended status 3 */ 234 #define QCMD_SELF_TST1 0xC2 /* run self test 1 (nondestructive) */ 235 #define QCMD_SELF_TST2 0xCA /* run self test 2 (destructive) */ 236 237 238 239 /* "Vendor Unique" codes */ 240 #if defined(MT_ISARCHIVESC499) || defined(MT_ISARCHIVE_2150L) 241 # define QCMDV_TELL_BLK 0xAE /* read current block address */ 242 # define QCMDV_SEEK_BLK 0xAD /* seek to specific block */ 243 # define SEEK_BUF_SIZE 3 /* address is 3 bytes */ 244 #endif 245 246 247 /* Optional, QFA (Quick File Access) commands. 248 * Not all drives support this, but those that do could use these commands 249 * to implement semi-non-sequential access. `mt fsf` would benefit from this. 250 * QFA divides the tape into 2 partitions, a data and a directory partition, 251 * causing some incompatibility problems wrt std QIC-02 data exchange. 252 * It would be useful to cache the directory info, but that might be tricky 253 * to do in kernel-space. [Size constraints.] 254 * Refer to QIC-02, appendix A for more information. 255 * I have no idea how other *nix variants implement QFA. 256 * I have no idea which drives support QFA and which don't. 257 */ 258 #define QFA_ENABLE 0x2D /* enter QFA mode, give @ BOT only */ 259 #define QFA_DATA 0x20 /* select data partition */ 260 #define QFA_DIR 0x23 /* select directory partition */ 261 #define QFA_RD_POS 0xCF /* read position+status bytes */ 262 #define QFA_SEEK_EOD 0xA1 /* seek EOD within current partition */ 263 #define QFA_SEEK_BLK 0xAF /* seek to a block within current partition */ 264 265 266 267 /* Minor device codes for tapes: 268 * |7|6|5|4|3|2|1|0| 269 * | \ | / \ | / |_____ 1=rewind on close, 0=no rewind on close 270 * | \|/ |_________ Density: 000=none, 001=QIC-11, 010=24, 011=120, 271 * | | 100=QIC-150, 101..111 reserved. 272 * | |_______________ Reserved for unit numbers. 273 * |___________________ Reserved for diagnostics during debugging. 274 */ 275 276 #define TP_REWCLOSE(d) ((MINOR(d)&0x01) == 1) /* rewind bit */ 277 /* rewind is only done if data has been transfered */ 278 #define TP_DENS(dev) ((MINOR(dev) >> 1) & 0x07) /* tape density */ 279 #define TP_UNIT(dev) ((MINOR(dev) >> 4) & 0x07) /* unit number */ 280 #define TP_DIAGS(dev) (MINOR(dev) & 0x80) /* print excessive diagnostics */ 281 282 283 /* status codes returned by a WTS_RDSTAT call */ 284 struct tpstatus { /* sizeof(short)==2), LSB first */ 285 unsigned short exs; /* Drive exception flags */ 286 unsigned short dec; /* data error count: nr of blocks rewritten/soft read errors */ 287 unsigned short urc; /* underrun count: nr of times streaming was interrupted */ 288 }; 289 #define TPSTATSIZE sizeof(struct tpstatus) 290 291 292 /* defines for tpstatus.exs -- taken from 386BSD wt driver */ 293 #define TP_POR 0x100 /* Power on or reset occurred */ 294 #define TP_EOR 0x200 /* REServed for end of RECORDED media */ 295 #define TP_PAR 0x400 /* REServed for bus parity */ 296 #define TP_BOM 0x800 /* Beginning of media */ 297 #define TP_MBD 0x1000 /* Marginal block detected */ 298 #define TP_NDT 0x2000 /* No data detected */ 299 #define TP_ILL 0x4000 /* Illegal command */ 300 #define TP_ST1 0x8000 /* Status byte 1 flag */ 301 #define TP_FIL 0x01 /* File mark detected */ 302 #define TP_BNL 0x02 /* Bad block not located */ 303 #define TP_UDA 0x04 /* Unrecoverable data error */ 304 #define TP_EOM 0x08 /* End of media */ 305 #define TP_WRP 0x10 /* Write protected cartridge */ 306 #define TP_USL 0x20 /* Unselected drive */ 307 #define TP_CNI 0x40 /* Cartridge not in place */ 308 #define TP_ST0 0x80 /* Status byte 0 flag */ 309 310 #define REPORT_ERR0 (TP_CNI|TP_USL|TP_WRP|TP_EOM|TP_UDA|TP_BNL|TP_FIL) 311 #define REPORT_ERR1 (TP_ILL|TP_NDT|TP_MBD|TP_PAR) 312 313 314 #define EXC_UNKNOWN 0 /* (extra) Unknown exception code */ 315 #define EXC_NCART 1 /* No cartridge */ 316 #define EXC_NDRV 2 /* No drive */ 317 #define EXC_WP 3 /* Write protected */ 318 #define EXC_EOM 4 /* EOM */ 319 #define EXC_RWA 5 /* read/write abort */ 320 #define EXC_XBAD 6 /* read error, bad block transfered */ 321 #define EXC_XFILLER 7 /* read error, filler block transfered */ 322 #define EXC_NDT 8 /* read error, no data */ 323 #define EXC_NDTEOM 9 /* read error, no data & EOM */ 324 #define EXC_NDTBOM 10 /* read error, no data & BOM */ 325 #define EXC_FM 11 /* Read a filemark */ 326 #define EXC_ILL 12 /* Illegal command */ 327 #define EXC_POR 13 /* Power on/reset */ 328 #define EXC_MARGINAL 14 /* Marginal block detected */ 329 #define EXC_EOR 15 /* (extra, for SEEKEOD) End Of Recorded data reached */ 330 #define EXC_BOM 16 /* (extra) BOM reached */ 331 332 333 #define TAPE_NOTIFY_TIMEOUT 1000000 334 335 /* internal function return codes */ 336 #define TE_OK 0 /* everything is fine */ 337 #define TE_EX 1 /* exception detected */ 338 #define TE_ERR 2 /* some error */ 339 #define TE_NS 3 /* can't read status */ 340 #define TE_TIM 4 /* timed out */ 341 #define TE_DEAD 5 /* tape drive doesn't respond */ 342 #define TE_END 6 /******** Archive hack *****/ 343 344 /* timeout timer values -- check these! */ 345 #define TIM_S (4*HZ) /* 4 seconds (normal cmds) */ 346 #define TIM_M (30*HZ) /* 30 seconds (write FM) */ 347 #define TIM_R (8*60*HZ) /* 8 minutes (retensioning) */ 348 #define TIM_F (2*3600*HZ) /* est. 1.2hr for full tape read/write+2 retens */ 349 350 #define TIMERON(t) timer_table[TAPE_QIC02_TIMER].expires = jiffies + (t); \ 351 timer_active |= (1<<TAPE_QIC02_TIMER) 352 #define TIMEROFF timer_active &= ~(1<<TAPE_QIC02_TIMER) 353 #define TIMERCONT timer_active |= (1<<TAPE_QIC02_TIMER) 354 355 356 typedef char flag; 357 #define NO 0 /* NO must be 0 */ 358 #define YES 1 /* YES must be != 0 */ 359 360 361 #ifdef TDEBUG 362 # define TPQDEB(s) s 363 # define TPQPUTS(s) tpqputs(s) 364 #else 365 # define TPQDEB(s) 366 # define TPQPUTS(s) 367 #endif 368 369 370 371 extern long tape_qic02_init(long); /* for kernel/mem.c */ 372 373 374 #endif /* CONFIG_TAPE_QIC02 */ 375 376 #endif /* _LINUX_TPQIC02_H */