Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Borislav Petkov | 5ce78af | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 2 | * IDE ATAPI streaming tape driver. |
| 3 | * |
Bartlomiej Zolnierkiewicz | 59bca8c | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 4 | * Copyright (C) 1995-1999 Gadi Oxman <gadio@netvision.net.il> |
| 5 | * Copyright (C) 2003-2005 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * This driver was constructed as a student project in the software laboratory |
| 8 | * of the faculty of electrical engineering in the Technion - Israel's |
| 9 | * Institute Of Technology, with the guide of Avner Lottem and Dr. Ilana David. |
| 10 | * |
| 11 | * It is hereby placed under the terms of the GNU general public license. |
| 12 | * (See linux/COPYING). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Borislav Petkov | 5ce78af | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 14 | * For a historical changelog see |
| 15 | * Documentation/ide/ChangeLog.ide-tape.1995-2002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Borislav Petkov | dfe7993 | 2008-02-06 02:57:55 +0100 | [diff] [blame] | 18 | #define IDETAPE_VERSION "1.20" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/timer.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/interrupt.h> |
Marcelo Feitoza Parisi | 9bae1ff | 2006-03-28 01:56:46 -0800 | [diff] [blame] | 28 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/major.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/errno.h> |
| 31 | #include <linux/genhd.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/ide.h> |
| 35 | #include <linux/smp_lock.h> |
| 36 | #include <linux/completion.h> |
| 37 | #include <linux/bitops.h> |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 38 | #include <linux/mutex.h> |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 39 | #include <scsi/scsi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | #include <asm/byteorder.h> |
Borislav Petkov | c837cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 42 | #include <linux/irq.h> |
| 43 | #include <linux/uaccess.h> |
| 44 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/mtio.h> |
| 47 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 48 | enum { |
| 49 | /* output errors only */ |
| 50 | DBG_ERR = (1 << 0), |
| 51 | /* output all sense key/asc */ |
| 52 | DBG_SENSE = (1 << 1), |
| 53 | /* info regarding all chrdev-related procedures */ |
| 54 | DBG_CHRDEV = (1 << 2), |
| 55 | /* all remaining procedures */ |
| 56 | DBG_PROCS = (1 << 3), |
| 57 | /* buffer alloc info (pc_stack & rq_stack) */ |
| 58 | DBG_PCRQ_STACK = (1 << 4), |
| 59 | }; |
| 60 | |
| 61 | /* define to see debug info */ |
| 62 | #define IDETAPE_DEBUG_LOG 0 |
| 63 | |
| 64 | #if IDETAPE_DEBUG_LOG |
| 65 | #define debug_log(lvl, fmt, args...) \ |
| 66 | { \ |
| 67 | if (tape->debug_mask & lvl) \ |
| 68 | printk(KERN_INFO "ide-tape: " fmt, ## args); \ |
| 69 | } |
| 70 | #else |
| 71 | #define debug_log(lvl, fmt, args...) do {} while (0) |
| 72 | #endif |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /**************************** Tunable parameters *****************************/ |
| 75 | |
| 76 | |
| 77 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 78 | * Pipelined mode parameters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 80 | * We try to use the minimum number of stages which is enough to keep the tape |
| 81 | * constantly streaming. To accomplish that, we implement a feedback loop around |
| 82 | * the maximum number of stages: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 84 | * We start from MIN maximum stages (we will not even use MIN stages if we don't |
| 85 | * need them), increment it by RATE*(MAX-MIN) whenever we sense that the |
| 86 | * pipeline is empty, until we reach the optimum value or until we reach MAX. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 88 | * Setting the following parameter to 0 is illegal: the pipelined mode cannot be |
| 89 | * disabled (idetape_calculate_speeds() divides by tape->max_stages.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | */ |
| 91 | #define IDETAPE_MIN_PIPELINE_STAGES 1 |
| 92 | #define IDETAPE_MAX_PIPELINE_STAGES 400 |
| 93 | #define IDETAPE_INCREASE_STAGES_RATE 20 |
| 94 | |
| 95 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 96 | * After each failed packet command we issue a request sense command and retry |
| 97 | * the packet command IDETAPE_MAX_PC_RETRIES times. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 99 | * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | */ |
| 101 | #define IDETAPE_MAX_PC_RETRIES 3 |
| 102 | |
| 103 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 104 | * With each packet command, we allocate a buffer of IDETAPE_PC_BUFFER_SIZE |
| 105 | * bytes. This is used for several packet commands (Not for READ/WRITE commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | */ |
| 107 | #define IDETAPE_PC_BUFFER_SIZE 256 |
| 108 | |
| 109 | /* |
| 110 | * In various places in the driver, we need to allocate storage |
| 111 | * for packet commands and requests, which will remain valid while |
| 112 | * we leave the driver to wait for an interrupt or a timeout event. |
| 113 | */ |
| 114 | #define IDETAPE_PC_STACK (10 + IDETAPE_MAX_PC_RETRIES) |
| 115 | |
| 116 | /* |
| 117 | * Some drives (for example, Seagate STT3401A Travan) require a very long |
| 118 | * timeout, because they don't return an interrupt or clear their busy bit |
| 119 | * until after the command completes (even retension commands). |
| 120 | */ |
| 121 | #define IDETAPE_WAIT_CMD (900*HZ) |
| 122 | |
| 123 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 124 | * The following parameter is used to select the point in the internal tape fifo |
| 125 | * in which we will start to refill the buffer. Decreasing the following |
| 126 | * parameter will improve the system's latency and interactive response, while |
| 127 | * using a high value might improve system throughput. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | */ |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 129 | #define IDETAPE_FIFO_THRESHOLD 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 132 | * DSC polling parameters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 134 | * Polling for DSC (a single bit in the status register) is a very important |
| 135 | * function in ide-tape. There are two cases in which we poll for DSC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 137 | * 1. Before a read/write packet command, to ensure that we can transfer data |
| 138 | * from/to the tape's data buffers, without causing an actual media access. |
| 139 | * In case the tape is not ready yet, we take out our request from the device |
| 140 | * request queue, so that ide.c could service requests from the other device |
| 141 | * on the same interface in the meantime. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 143 | * 2. After the successful initialization of a "media access packet command", |
| 144 | * which is a command that can take a long time to complete (the interval can |
| 145 | * range from several seconds to even an hour). Again, we postpone our request |
| 146 | * in the middle to free the bus for the other device. The polling frequency |
| 147 | * here should be lower than the read/write frequency since those media access |
| 148 | * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST |
| 149 | * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD |
| 150 | * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 152 | * We also set a timeout for the timer, in case something goes wrong. The |
| 153 | * timeout should be longer then the maximum execution time of a tape operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | */ |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 155 | |
| 156 | /* DSC timings. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */ |
| 158 | #define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */ |
| 159 | #define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */ |
| 160 | #define IDETAPE_DSC_MA_FAST 2*HZ /* 2 seconds */ |
| 161 | #define IDETAPE_DSC_MA_THRESHOLD 5*60*HZ /* 5 minutes */ |
| 162 | #define IDETAPE_DSC_MA_SLOW 30*HZ /* 30 seconds */ |
| 163 | #define IDETAPE_DSC_MA_TIMEOUT 2*60*60*HZ /* 2 hours */ |
| 164 | |
| 165 | /*************************** End of tunable parameters ***********************/ |
| 166 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 167 | /* Read/Write error simulation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | #define SIMULATE_ERRORS 0 |
| 169 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 170 | /* tape directions */ |
| 171 | enum { |
| 172 | IDETAPE_DIR_NONE = (1 << 0), |
| 173 | IDETAPE_DIR_READ = (1 << 1), |
| 174 | IDETAPE_DIR_WRITE = (1 << 2), |
| 175 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | struct idetape_bh { |
Stephen Rothwell | ab05796 | 2007-08-01 23:46:44 +0200 | [diff] [blame] | 178 | u32 b_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | atomic_t b_count; |
| 180 | struct idetape_bh *b_reqnext; |
| 181 | char *b_data; |
| 182 | }; |
| 183 | |
Borislav Petkov | 03056b9 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 184 | /* Tape door status */ |
| 185 | #define DOOR_UNLOCKED 0 |
| 186 | #define DOOR_LOCKED 1 |
| 187 | #define DOOR_EXPLICITLY_LOCKED 2 |
| 188 | |
| 189 | /* Some defines for the SPACE command */ |
| 190 | #define IDETAPE_SPACE_OVER_FILEMARK 1 |
| 191 | #define IDETAPE_SPACE_TO_EOD 3 |
| 192 | |
| 193 | /* Some defines for the LOAD UNLOAD command */ |
| 194 | #define IDETAPE_LU_LOAD_MASK 1 |
| 195 | #define IDETAPE_LU_RETENSION_MASK 2 |
| 196 | #define IDETAPE_LU_EOT_MASK 4 |
| 197 | |
| 198 | /* |
| 199 | * Special requests for our block device strategy routine. |
| 200 | * |
| 201 | * In order to service a character device command, we add special requests to |
| 202 | * the tail of our block device request queue and wait for their completion. |
| 203 | */ |
| 204 | |
| 205 | enum { |
| 206 | REQ_IDETAPE_PC1 = (1 << 0), /* packet command (first stage) */ |
| 207 | REQ_IDETAPE_PC2 = (1 << 1), /* packet command (second stage) */ |
| 208 | REQ_IDETAPE_READ = (1 << 2), |
| 209 | REQ_IDETAPE_WRITE = (1 << 3), |
| 210 | }; |
| 211 | |
| 212 | /* Error codes returned in rq->errors to the higher part of the driver. */ |
| 213 | #define IDETAPE_ERROR_GENERAL 101 |
| 214 | #define IDETAPE_ERROR_FILEMARK 102 |
| 215 | #define IDETAPE_ERROR_EOD 103 |
| 216 | |
| 217 | /* Structures related to the SELECT SENSE / MODE SENSE packet commands. */ |
| 218 | #define IDETAPE_BLOCK_DESCRIPTOR 0 |
| 219 | #define IDETAPE_CAPABILITIES_PAGE 0x2a |
| 220 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 221 | /* Tape flag bits values. */ |
| 222 | enum { |
| 223 | IDETAPE_FLAG_IGNORE_DSC = (1 << 0), |
| 224 | /* 0 When the tape position is unknown */ |
| 225 | IDETAPE_FLAG_ADDRESS_VALID = (1 << 1), |
| 226 | /* Device already opened */ |
| 227 | IDETAPE_FLAG_BUSY = (1 << 2), |
| 228 | /* Error detected in a pipeline stage */ |
| 229 | IDETAPE_FLAG_PIPELINE_ERR = (1 << 3), |
| 230 | /* Attempt to auto-detect the current user block size */ |
| 231 | IDETAPE_FLAG_DETECT_BS = (1 << 4), |
| 232 | /* Currently on a filemark */ |
| 233 | IDETAPE_FLAG_FILEMARK = (1 << 5), |
| 234 | /* DRQ interrupt device */ |
| 235 | IDETAPE_FLAG_DRQ_INTERRUPT = (1 << 6), |
| 236 | /* pipeline active */ |
| 237 | IDETAPE_FLAG_PIPELINE_ACTIVE = (1 << 7), |
| 238 | /* 0 = no tape is loaded, so we don't rewind after ejecting */ |
| 239 | IDETAPE_FLAG_MEDIUM_PRESENT = (1 << 8), |
| 240 | }; |
| 241 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 242 | /* A pipeline stage. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | typedef struct idetape_stage_s { |
| 244 | struct request rq; /* The corresponding request */ |
| 245 | struct idetape_bh *bh; /* The data buffers */ |
| 246 | struct idetape_stage_s *next; /* Pointer to the next stage */ |
| 247 | } idetape_stage_t; |
| 248 | |
| 249 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 250 | * Most of our global data which we need to save even as we leave the driver due |
| 251 | * to an interrupt or a timer event is stored in the struct defined below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | */ |
| 253 | typedef struct ide_tape_obj { |
| 254 | ide_drive_t *drive; |
| 255 | ide_driver_t *driver; |
| 256 | struct gendisk *disk; |
| 257 | struct kref kref; |
| 258 | |
| 259 | /* |
| 260 | * Since a typical character device operation requires more |
| 261 | * than one packet command, we provide here enough memory |
| 262 | * for the maximum of interconnected packet commands. |
| 263 | * The packet commands are stored in the circular array pc_stack. |
| 264 | * pc_stack_index points to the last used entry, and warps around |
| 265 | * to the start when we get to the last array entry. |
| 266 | * |
| 267 | * pc points to the current processed packet command. |
| 268 | * |
| 269 | * failed_pc points to the last failed packet command, or contains |
| 270 | * NULL if we do not need to retry any packet command. This is |
| 271 | * required since an additional packet command is needed before the |
| 272 | * retry, to get detailed information on what went wrong. |
| 273 | */ |
| 274 | /* Current packet command */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 275 | struct ide_atapi_pc *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* Last failed packet command */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 277 | struct ide_atapi_pc *failed_pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | /* Packet command stack */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 279 | struct ide_atapi_pc pc_stack[IDETAPE_PC_STACK]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /* Next free packet command storage space */ |
| 281 | int pc_stack_index; |
| 282 | struct request rq_stack[IDETAPE_PC_STACK]; |
| 283 | /* We implement a circular array */ |
| 284 | int rq_stack_index; |
| 285 | |
| 286 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 287 | * DSC polling variables. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 289 | * While polling for DSC we use postponed_rq to postpone the current |
| 290 | * request so that ide.c will be able to service pending requests on the |
| 291 | * other device. Note that at most we will have only one DSC (usually |
| 292 | * data transfer) request in the device request queue. Additional |
| 293 | * requests can be queued in our internal pipeline, but they will be |
| 294 | * visible to ide.c only one at a time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | */ |
| 296 | struct request *postponed_rq; |
| 297 | /* The time in which we started polling for DSC */ |
| 298 | unsigned long dsc_polling_start; |
| 299 | /* Timer used to poll for dsc */ |
| 300 | struct timer_list dsc_timer; |
| 301 | /* Read/Write dsc polling frequency */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 302 | unsigned long best_dsc_rw_freq; |
| 303 | unsigned long dsc_poll_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | unsigned long dsc_timeout; |
| 305 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 306 | /* Read position information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | u8 partition; |
| 308 | /* Current block */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 309 | unsigned int first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 311 | /* Last error information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | u8 sense_key, asc, ascq; |
| 313 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 314 | /* Character device operation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | unsigned int minor; |
| 316 | /* device name */ |
| 317 | char name[4]; |
| 318 | /* Current character device data transfer direction */ |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 319 | u8 chrdev_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 321 | /* tape block size, usually 512 or 1024 bytes */ |
| 322 | unsigned short blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | int user_bs_factor; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | /* Copy of the tape's Capabilities and Mechanical Page */ |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 326 | u8 caps[20]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 329 | * Active data transfer request parameters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 331 | * At most, there is only one ide-tape originated data transfer request |
| 332 | * in the device request queue. This allows ide.c to easily service |
| 333 | * requests from the other device when we postpone our active request. |
| 334 | * In the pipelined operation mode, we use our internal pipeline |
| 335 | * structure to hold more data requests. The data buffer size is chosen |
| 336 | * based on the tape's recommendation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | */ |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 338 | /* ptr to the request which is waiting in the device request queue */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 339 | struct request *active_data_rq; |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 340 | /* Data buffer size chosen based on the tape's recommendation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int stage_size; |
| 342 | idetape_stage_t *merge_stage; |
| 343 | int merge_stage_size; |
| 344 | struct idetape_bh *bh; |
| 345 | char *b_data; |
| 346 | int b_count; |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 349 | * Pipeline parameters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 351 | * To accomplish non-pipelined mode, we simply set the following |
| 352 | * variables to zero (or NULL, where appropriate). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | */ |
| 354 | /* Number of currently used stages */ |
| 355 | int nr_stages; |
| 356 | /* Number of pending stages */ |
| 357 | int nr_pending_stages; |
| 358 | /* We will not allocate more than this number of stages */ |
| 359 | int max_stages, min_pipeline, max_pipeline; |
| 360 | /* The first stage which will be removed from the pipeline */ |
| 361 | idetape_stage_t *first_stage; |
| 362 | /* The currently active stage */ |
| 363 | idetape_stage_t *active_stage; |
| 364 | /* Will be serviced after the currently active request */ |
| 365 | idetape_stage_t *next_stage; |
| 366 | /* New requests will be added to the pipeline here */ |
| 367 | idetape_stage_t *last_stage; |
| 368 | /* Optional free stage which we can use */ |
| 369 | idetape_stage_t *cache_stage; |
| 370 | int pages_per_stage; |
| 371 | /* Wasted space in each stage */ |
| 372 | int excess_bh_size; |
| 373 | |
| 374 | /* Status/Action flags: long for set_bit */ |
| 375 | unsigned long flags; |
| 376 | /* protects the ide-tape queue */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 377 | spinlock_t lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 379 | /* Measures average tape speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | unsigned long avg_time; |
| 381 | int avg_size; |
| 382 | int avg_speed; |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | /* the door is currently locked */ |
| 385 | int door_locked; |
| 386 | /* the tape hardware is write protected */ |
| 387 | char drv_write_prot; |
| 388 | /* the tape is write protected (hardware or opened as read-only) */ |
| 389 | char write_prot; |
| 390 | |
| 391 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 392 | * Limit the number of times a request can be postponed, to avoid an |
| 393 | * infinite postpone deadlock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | int postpone_cnt; |
| 396 | |
| 397 | /* |
| 398 | * Measures number of frames: |
| 399 | * |
| 400 | * 1. written/read to/from the driver pipeline (pipeline_head). |
| 401 | * 2. written/read to/from the tape buffers (idetape_bh). |
| 402 | * 3. written/read by the tape to/from the media (tape_head). |
| 403 | */ |
| 404 | int pipeline_head; |
| 405 | int buffer_head; |
| 406 | int tape_head; |
| 407 | int last_tape_head; |
| 408 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 409 | /* Speed control at the tape buffers input/output */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | unsigned long insert_time; |
| 411 | int insert_size; |
| 412 | int insert_speed; |
| 413 | int max_insert_speed; |
| 414 | int measure_insert_time; |
| 415 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 416 | /* Speed regulation negative feedback loop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | int speed_control; |
| 418 | int pipeline_head_speed; |
| 419 | int controlled_pipeline_head_speed; |
| 420 | int uncontrolled_pipeline_head_speed; |
| 421 | int controlled_last_pipeline_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | unsigned long uncontrolled_pipeline_head_time; |
| 423 | unsigned long controlled_pipeline_head_time; |
| 424 | int controlled_previous_pipeline_head; |
| 425 | int uncontrolled_previous_pipeline_head; |
| 426 | unsigned long controlled_previous_head_time; |
| 427 | unsigned long uncontrolled_previous_head_time; |
| 428 | int restart_speed_control_req; |
| 429 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 430 | u32 debug_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } idetape_tape_t; |
| 432 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 433 | static DEFINE_MUTEX(idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 435 | static struct class *idetape_sysfs_class; |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | #define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref) |
| 438 | |
| 439 | #define ide_tape_g(disk) \ |
| 440 | container_of((disk)->private_data, struct ide_tape_obj, driver) |
| 441 | |
| 442 | static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) |
| 443 | { |
| 444 | struct ide_tape_obj *tape = NULL; |
| 445 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 446 | mutex_lock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | tape = ide_tape_g(disk); |
| 448 | if (tape) |
| 449 | kref_get(&tape->kref); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 450 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return tape; |
| 452 | } |
| 453 | |
| 454 | static void ide_tape_release(struct kref *); |
| 455 | |
| 456 | static void ide_tape_put(struct ide_tape_obj *tape) |
| 457 | { |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 458 | mutex_lock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | kref_put(&tape->kref, ide_tape_release); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 460 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 464 | * The variables below are used for the character device interface. Additional |
| 465 | * state variables are defined in our ide_drive_t structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 467 | static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
| 469 | #define ide_tape_f(file) ((file)->private_data) |
| 470 | |
| 471 | static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i) |
| 472 | { |
| 473 | struct ide_tape_obj *tape = NULL; |
| 474 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 475 | mutex_lock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | tape = idetape_devs[i]; |
| 477 | if (tape) |
| 478 | kref_get(&tape->kref); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 479 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | return tape; |
| 481 | } |
| 482 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 483 | static void idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 484 | unsigned int bcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
| 486 | struct idetape_bh *bh = pc->bh; |
| 487 | int count; |
| 488 | |
| 489 | while (bcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (bh == NULL) { |
| 491 | printk(KERN_ERR "ide-tape: bh == NULL in " |
| 492 | "idetape_input_buffers\n"); |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 493 | ide_atapi_discard_data(drive, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | return; |
| 495 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 496 | count = min( |
| 497 | (unsigned int)(bh->b_size - atomic_read(&bh->b_count)), |
| 498 | bcount); |
| 499 | HWIF(drive)->atapi_input_bytes(drive, bh->b_data + |
| 500 | atomic_read(&bh->b_count), count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | bcount -= count; |
| 502 | atomic_add(count, &bh->b_count); |
| 503 | if (atomic_read(&bh->b_count) == bh->b_size) { |
| 504 | bh = bh->b_reqnext; |
| 505 | if (bh) |
| 506 | atomic_set(&bh->b_count, 0); |
| 507 | } |
| 508 | } |
| 509 | pc->bh = bh; |
| 510 | } |
| 511 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 512 | static void idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 513 | unsigned int bcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | { |
| 515 | struct idetape_bh *bh = pc->bh; |
| 516 | int count; |
| 517 | |
| 518 | while (bcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (bh == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 520 | printk(KERN_ERR "ide-tape: bh == NULL in %s\n", |
| 521 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | return; |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | count = min((unsigned int)pc->b_count, (unsigned int)bcount); |
| 525 | HWIF(drive)->atapi_output_bytes(drive, pc->b_data, count); |
| 526 | bcount -= count; |
| 527 | pc->b_data += count; |
| 528 | pc->b_count -= count; |
| 529 | if (!pc->b_count) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 530 | bh = bh->b_reqnext; |
| 531 | pc->bh = bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if (bh) { |
| 533 | pc->b_data = bh->b_data; |
| 534 | pc->b_count = atomic_read(&bh->b_count); |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 540 | static void idetape_update_buffers(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | { |
| 542 | struct idetape_bh *bh = pc->bh; |
| 543 | int count; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 544 | unsigned int bcount = pc->xferred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 546 | if (pc->flags & PC_FLAG_WRITING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | return; |
| 548 | while (bcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (bh == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 550 | printk(KERN_ERR "ide-tape: bh == NULL in %s\n", |
| 551 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | return; |
| 553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | count = min((unsigned int)bh->b_size, (unsigned int)bcount); |
| 555 | atomic_set(&bh->b_count, count); |
| 556 | if (atomic_read(&bh->b_count) == bh->b_size) |
| 557 | bh = bh->b_reqnext; |
| 558 | bcount -= count; |
| 559 | } |
| 560 | pc->bh = bh; |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * idetape_next_pc_storage returns a pointer to a place in which we can |
| 565 | * safely store a packet command, even though we intend to leave the |
| 566 | * driver. A storage space for a maximum of IDETAPE_PC_STACK packet |
| 567 | * commands is allocated at initialization time. |
| 568 | */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 569 | static struct ide_atapi_pc *idetape_next_pc_storage(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
| 571 | idetape_tape_t *tape = drive->driver_data; |
| 572 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 573 | debug_log(DBG_PCRQ_STACK, "pc_stack_index=%d\n", tape->pc_stack_index); |
| 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | if (tape->pc_stack_index == IDETAPE_PC_STACK) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 576 | tape->pc_stack_index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return (&tape->pc_stack[tape->pc_stack_index++]); |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * idetape_next_rq_storage is used along with idetape_next_pc_storage. |
| 582 | * Since we queue packet commands in the request queue, we need to |
| 583 | * allocate a request, along with the allocation of a packet command. |
| 584 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | /************************************************************** |
| 587 | * * |
| 588 | * This should get fixed to use kmalloc(.., GFP_ATOMIC) * |
| 589 | * followed later on by kfree(). -ml * |
| 590 | * * |
| 591 | **************************************************************/ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 592 | |
| 593 | static struct request *idetape_next_rq_storage(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
| 595 | idetape_tape_t *tape = drive->driver_data; |
| 596 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 597 | debug_log(DBG_PCRQ_STACK, "rq_stack_index=%d\n", tape->rq_stack_index); |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | if (tape->rq_stack_index == IDETAPE_PC_STACK) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 600 | tape->rq_stack_index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return (&tape->rq_stack[tape->rq_stack_index++]); |
| 602 | } |
| 603 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 604 | static void idetape_init_pc(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
| 606 | memset(pc->c, 0, 12); |
| 607 | pc->retries = 0; |
| 608 | pc->flags = 0; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 609 | pc->req_xfer = 0; |
| 610 | pc->buf = pc->pc_buf; |
| 611 | pc->buf_size = IDETAPE_PC_BUFFER_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | pc->bh = NULL; |
| 613 | pc->b_data = NULL; |
| 614 | } |
| 615 | |
| 616 | /* |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 617 | * called on each failed packet command retry to analyze the request sense. We |
| 618 | * currently do not utilize this information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | */ |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 620 | static void idetape_analyze_error(ide_drive_t *drive, u8 *sense) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { |
| 622 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 623 | struct ide_atapi_pc *pc = tape->failed_pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 625 | tape->sense_key = sense[2] & 0xF; |
| 626 | tape->asc = sense[12]; |
| 627 | tape->ascq = sense[13]; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 628 | |
| 629 | debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n", |
| 630 | pc->c[0], tape->sense_key, tape->asc, tape->ascq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 632 | /* Correct pc->xferred by asking the tape. */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 633 | if (pc->flags & PC_FLAG_DMA_ERROR) { |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 634 | pc->xferred = pc->req_xfer - |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 635 | tape->blk_size * |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 636 | be32_to_cpu(get_unaligned((u32 *)&sense[3])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | idetape_update_buffers(pc); |
| 638 | } |
| 639 | |
| 640 | /* |
| 641 | * If error was the result of a zero-length read or write command, |
| 642 | * with sense key=5, asc=0x22, ascq=0, let it slide. Some drives |
| 643 | * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes. |
| 644 | */ |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 645 | if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6) |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 646 | /* length == 0 */ |
| 647 | && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) { |
| 648 | if (tape->sense_key == 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | /* don't report an error, everything's ok */ |
| 650 | pc->error = 0; |
| 651 | /* don't retry read/write */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 652 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 655 | if (pc->c[0] == READ_6 && (sense[2] & 0x80)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | pc->error = IDETAPE_ERROR_FILEMARK; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 657 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 659 | if (pc->c[0] == WRITE_6) { |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 660 | if ((sense[2] & 0x40) || (tape->sense_key == 0xd |
| 661 | && tape->asc == 0x0 && tape->ascq == 0x2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | pc->error = IDETAPE_ERROR_EOD; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 663 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 666 | if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 667 | if (tape->sense_key == 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | pc->error = IDETAPE_ERROR_EOD; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 669 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 671 | if (!(pc->flags & PC_FLAG_ABORT) && |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 672 | pc->xferred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | pc->retries = IDETAPE_MAX_PC_RETRIES + 1; |
| 674 | } |
| 675 | } |
| 676 | |
Borislav Petkov | 419d474 | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 677 | static void idetape_activate_next_stage(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
| 679 | idetape_tape_t *tape = drive->driver_data; |
| 680 | idetape_stage_t *stage = tape->next_stage; |
| 681 | struct request *rq = &stage->rq; |
| 682 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 683 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
| 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | if (stage == NULL) { |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 686 | printk(KERN_ERR "ide-tape: bug: Trying to activate a non" |
| 687 | " existing stage\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return; |
| 689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
| 691 | rq->rq_disk = tape->disk; |
| 692 | rq->buffer = NULL; |
| 693 | rq->special = (void *)stage->bh; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 694 | tape->active_data_rq = rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | tape->active_stage = stage; |
| 696 | tape->next_stage = stage->next; |
| 697 | } |
| 698 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 699 | /* Free a stage along with its related buffers completely. */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 700 | static void __idetape_kfree_stage(idetape_stage_t *stage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | { |
| 702 | struct idetape_bh *prev_bh, *bh = stage->bh; |
| 703 | int size; |
| 704 | |
| 705 | while (bh != NULL) { |
| 706 | if (bh->b_data != NULL) { |
| 707 | size = (int) bh->b_size; |
| 708 | while (size > 0) { |
| 709 | free_page((unsigned long) bh->b_data); |
| 710 | size -= PAGE_SIZE; |
| 711 | bh->b_data += PAGE_SIZE; |
| 712 | } |
| 713 | } |
| 714 | prev_bh = bh; |
| 715 | bh = bh->b_reqnext; |
| 716 | kfree(prev_bh); |
| 717 | } |
| 718 | kfree(stage); |
| 719 | } |
| 720 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 721 | static void idetape_kfree_stage(idetape_tape_t *tape, idetape_stage_t *stage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
| 723 | __idetape_kfree_stage(stage); |
| 724 | } |
| 725 | |
| 726 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 727 | * Remove tape->first_stage from the pipeline. The caller should avoid race |
| 728 | * conditions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 730 | static void idetape_remove_stage_head(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { |
| 732 | idetape_tape_t *tape = drive->driver_data; |
| 733 | idetape_stage_t *stage; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 734 | |
| 735 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
| 736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | if (tape->first_stage == NULL) { |
| 738 | printk(KERN_ERR "ide-tape: bug: tape->first_stage is NULL\n"); |
Borislav Petkov | 55a5d29 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 739 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | if (tape->active_stage == tape->first_stage) { |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 742 | printk(KERN_ERR "ide-tape: bug: Trying to free our active " |
| 743 | "pipeline stage\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | return; |
| 745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | stage = tape->first_stage; |
| 747 | tape->first_stage = stage->next; |
| 748 | idetape_kfree_stage(tape, stage); |
| 749 | tape->nr_stages--; |
| 750 | if (tape->first_stage == NULL) { |
| 751 | tape->last_stage = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | if (tape->next_stage != NULL) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 753 | printk(KERN_ERR "ide-tape: bug: tape->next_stage !=" |
| 754 | " NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if (tape->nr_stages) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 756 | printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 " |
| 757 | "now\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * This will free all the pipeline stages starting from new_last_stage->next |
| 763 | * to the end of the list, and point tape->last_stage to new_last_stage. |
| 764 | */ |
| 765 | static void idetape_abort_pipeline(ide_drive_t *drive, |
| 766 | idetape_stage_t *new_last_stage) |
| 767 | { |
| 768 | idetape_tape_t *tape = drive->driver_data; |
| 769 | idetape_stage_t *stage = new_last_stage->next; |
| 770 | idetape_stage_t *nstage; |
| 771 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 772 | debug_log(DBG_PROCS, "%s: Enter %s\n", tape->name, __func__); |
| 773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | while (stage) { |
| 775 | nstage = stage->next; |
| 776 | idetape_kfree_stage(tape, stage); |
| 777 | --tape->nr_stages; |
| 778 | --tape->nr_pending_stages; |
| 779 | stage = nstage; |
| 780 | } |
| 781 | if (new_last_stage) |
| 782 | new_last_stage->next = NULL; |
| 783 | tape->last_stage = new_last_stage; |
| 784 | tape->next_stage = NULL; |
| 785 | } |
| 786 | |
| 787 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 788 | * Finish servicing a request and insert a pending pipeline request into the |
| 789 | * main device queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | */ |
| 791 | static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) |
| 792 | { |
| 793 | struct request *rq = HWGROUP(drive)->rq; |
| 794 | idetape_tape_t *tape = drive->driver_data; |
| 795 | unsigned long flags; |
| 796 | int error; |
| 797 | int remove_stage = 0; |
| 798 | idetape_stage_t *active_stage; |
| 799 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 800 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | switch (uptodate) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 803 | case 0: error = IDETAPE_ERROR_GENERAL; break; |
| 804 | case 1: error = 0; break; |
| 805 | default: error = uptodate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | rq->errors = error; |
| 808 | if (error) |
| 809 | tape->failed_pc = NULL; |
| 810 | |
Bartlomiej Zolnierkiewicz | 3687221 | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 811 | if (!blk_special_request(rq)) { |
| 812 | ide_end_request(drive, uptodate, nr_sects); |
| 813 | return 0; |
| 814 | } |
| 815 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 816 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | /* The request was a pipelined data transfer request */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 819 | if (tape->active_data_rq == rq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | active_stage = tape->active_stage; |
| 821 | tape->active_stage = NULL; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 822 | tape->active_data_rq = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | tape->nr_pending_stages--; |
| 824 | if (rq->cmd[0] & REQ_IDETAPE_WRITE) { |
| 825 | remove_stage = 1; |
| 826 | if (error) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 827 | set_bit(IDETAPE_FLAG_PIPELINE_ERR, |
| 828 | &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | if (error == IDETAPE_ERROR_EOD) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 830 | idetape_abort_pipeline(drive, |
| 831 | active_stage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
| 833 | } else if (rq->cmd[0] & REQ_IDETAPE_READ) { |
| 834 | if (error == IDETAPE_ERROR_EOD) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 835 | set_bit(IDETAPE_FLAG_PIPELINE_ERR, |
| 836 | &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | idetape_abort_pipeline(drive, active_stage); |
| 838 | } |
| 839 | } |
| 840 | if (tape->next_stage != NULL) { |
Borislav Petkov | 419d474 | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 841 | idetape_activate_next_stage(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 843 | /* Insert the next request into the request queue. */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 844 | (void)ide_do_drive_cmd(drive, tape->active_data_rq, |
| 845 | ide_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } else if (!error) { |
Borislav Petkov | 9721985 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 847 | /* |
| 848 | * This is a part of the feedback loop which tries to |
| 849 | * find the optimum number of stages. We are starting |
| 850 | * from a minimum maximum number of stages, and if we |
| 851 | * sense that the pipeline is empty, we try to increase |
| 852 | * it, until we reach the user compile time memory |
| 853 | * limit. |
| 854 | */ |
| 855 | int i = (tape->max_pipeline - tape->min_pipeline) / 10; |
| 856 | |
| 857 | tape->max_stages += max(i, 1); |
| 858 | tape->max_stages = max(tape->max_stages, |
| 859 | tape->min_pipeline); |
| 860 | tape->max_stages = min(tape->max_stages, |
| 861 | tape->max_pipeline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | ide_end_drive_cmd(drive, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | if (remove_stage) |
| 867 | idetape_remove_stage_head(drive); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 868 | if (tape->active_data_rq == NULL) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 869 | clear_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 870 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 874 | static ide_startstop_t idetape_request_sense_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
| 876 | idetape_tape_t *tape = drive->driver_data; |
| 877 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 878 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
| 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | if (!tape->pc->error) { |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 881 | idetape_analyze_error(drive, tape->pc->buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | idetape_end_request(drive, 1, 0); |
| 883 | } else { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 884 | printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - " |
| 885 | "Aborting request!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | idetape_end_request(drive, 0, 0); |
| 887 | } |
| 888 | return ide_stopped; |
| 889 | } |
| 890 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 891 | static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 893 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 894 | pc->c[0] = REQUEST_SENSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | pc->c[4] = 20; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 896 | pc->req_xfer = 20; |
| 897 | pc->idetape_callback = &idetape_request_sense_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | static void idetape_init_rq(struct request *rq, u8 cmd) |
| 901 | { |
| 902 | memset(rq, 0, sizeof(*rq)); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 903 | rq->cmd_type = REQ_TYPE_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | rq->cmd[0] = cmd; |
| 905 | } |
| 906 | |
| 907 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 908 | * Generate a new packet command request in front of the request queue, before |
| 909 | * the current request, so that it will be processed immediately, on the next |
| 910 | * pass through the driver. The function below is called from the request |
| 911 | * handling part of the driver (the "bottom" part). Safe storage for the request |
| 912 | * should be allocated with ide_tape_next_{pc,rq}_storage() prior to that. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 914 | * Memory for those requests is pre-allocated at initialization time, and is |
| 915 | * limited to IDETAPE_PC_STACK requests. We assume that we have enough space for |
| 916 | * the maximum possible number of inter-dependent packet commands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 918 | * The higher level of the driver - The ioctl handler and the character device |
| 919 | * handling functions should queue request to the lower level part and wait for |
| 920 | * their completion using idetape_queue_pc_tail or idetape_queue_rw_tail. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 922 | static void idetape_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 923 | struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
| 925 | struct ide_tape_obj *tape = drive->driver_data; |
| 926 | |
| 927 | idetape_init_rq(rq, REQ_IDETAPE_PC1); |
| 928 | rq->buffer = (char *) pc; |
| 929 | rq->rq_disk = tape->disk; |
| 930 | (void) ide_do_drive_cmd(drive, rq, ide_preempt); |
| 931 | } |
| 932 | |
| 933 | /* |
| 934 | * idetape_retry_pc is called when an error was detected during the |
| 935 | * last packet command. We queue a request sense packet command in |
| 936 | * the head of the request list. |
| 937 | */ |
| 938 | static ide_startstop_t idetape_retry_pc (ide_drive_t *drive) |
| 939 | { |
| 940 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 941 | struct ide_atapi_pc *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | struct request *rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 944 | (void)ide_read_error(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | pc = idetape_next_pc_storage(drive); |
| 946 | rq = idetape_next_rq_storage(drive); |
| 947 | idetape_create_request_sense_cmd(pc); |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 948 | set_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | idetape_queue_pc_head(drive, pc, rq); |
| 950 | return ide_stopped; |
| 951 | } |
| 952 | |
| 953 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 954 | * Postpone the current request so that ide.c will be able to service requests |
| 955 | * from another device on the same hwgroup while we are polling for DSC. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 957 | static void idetape_postpone_request(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | { |
| 959 | idetape_tape_t *tape = drive->driver_data; |
| 960 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 961 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
| 962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | tape->postponed_rq = HWGROUP(drive)->rq; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 964 | ide_stall_queue(drive, tape->dsc_poll_freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 967 | typedef void idetape_io_buf(ide_drive_t *, struct ide_atapi_pc *, unsigned int); |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | /* |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 970 | * This is the usual interrupt handler which will be called during a packet |
| 971 | * command. We will transfer some of the data (as requested by the drive) and |
| 972 | * will re-point interrupt handler to us. When data transfer is finished, we |
| 973 | * will act according to the algorithm described before |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 974 | * idetape_issue_pc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | */ |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 976 | static ide_startstop_t idetape_pc_intr(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | { |
| 978 | ide_hwif_t *hwif = drive->hwif; |
| 979 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 980 | struct ide_atapi_pc *pc = tape->pc; |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 981 | xfer_func_t *xferfunc; |
| 982 | idetape_io_buf *iobuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | unsigned int temp; |
| 984 | #if SIMULATE_ERRORS |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 985 | static int error_sim_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | #endif |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 987 | u16 bcount; |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 988 | u8 stat, ireason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 990 | debug_log(DBG_PROCS, "Enter %s - interrupt handler\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
| 992 | /* Clear the interrupt */ |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 993 | stat = ide_read_status(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 995 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 996 | if (hwif->ide_dma_end(drive) || (stat & ERR_STAT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | /* |
| 998 | * A DMA error is sometimes expected. For example, |
| 999 | * if the tape is crossing a filemark during a |
| 1000 | * READ command, it will issue an irq and position |
| 1001 | * itself before the filemark, so that only a partial |
| 1002 | * data transfer will occur (which causes the DMA |
| 1003 | * error). In that case, we will later ask the tape |
| 1004 | * how much bytes of the original request were |
| 1005 | * actually transferred (we can't receive that |
| 1006 | * information from the DMA engine on most chipsets). |
| 1007 | */ |
| 1008 | |
| 1009 | /* |
| 1010 | * On the contrary, a DMA error is never expected; |
| 1011 | * it usually indicates a hardware error or abort. |
| 1012 | * If the tape crosses a filemark during a READ |
| 1013 | * command, it will issue an irq and position itself |
| 1014 | * after the filemark (not before). Only a partial |
| 1015 | * data transfer will occur, but no DMA error. |
| 1016 | * (AS, 19 Apr 2001) |
| 1017 | */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1018 | pc->flags |= PC_FLAG_DMA_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | } else { |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1020 | pc->xferred = pc->req_xfer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | idetape_update_buffers(pc); |
| 1022 | } |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1023 | debug_log(DBG_PROCS, "DMA finished\n"); |
| 1024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* No more interrupts */ |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1028 | if ((stat & DRQ_STAT) == 0) { |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1029 | debug_log(DBG_SENSE, "Packet command completed, %d bytes" |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1030 | " transferred\n", pc->xferred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1032 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | local_irq_enable(); |
| 1034 | |
| 1035 | #if SIMULATE_ERRORS |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1036 | if ((pc->c[0] == WRITE_6 || pc->c[0] == READ_6) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | (++error_sim_count % 100) == 0) { |
| 1038 | printk(KERN_INFO "ide-tape: %s: simulating error\n", |
| 1039 | tape->name); |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1040 | stat |= ERR_STAT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
| 1042 | #endif |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1043 | if ((stat & ERR_STAT) && pc->c[0] == REQUEST_SENSE) |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1044 | stat &= ~ERR_STAT; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1045 | if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) { |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1046 | /* Error detected */ |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1047 | debug_log(DBG_ERR, "%s: I/O error\n", tape->name); |
| 1048 | |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1049 | if (pc->c[0] == REQUEST_SENSE) { |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1050 | printk(KERN_ERR "ide-tape: I/O error in request" |
| 1051 | " sense command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | return ide_do_reset(drive); |
| 1053 | } |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1054 | debug_log(DBG_ERR, "[cmd %x]: check condition\n", |
| 1055 | pc->c[0]); |
| 1056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | /* Retry operation */ |
| 1058 | return idetape_retry_pc(drive); |
| 1059 | } |
| 1060 | pc->error = 0; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1061 | if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1062 | (stat & SEEK_STAT) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | /* Media access command */ |
| 1064 | tape->dsc_polling_start = jiffies; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1065 | tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT; |
| 1067 | /* Allow ide.c to handle other requests */ |
| 1068 | idetape_postpone_request(drive); |
| 1069 | return ide_stopped; |
| 1070 | } |
| 1071 | if (tape->failed_pc == pc) |
| 1072 | tape->failed_pc = NULL; |
| 1073 | /* Command finished - Call the callback function */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1074 | return pc->idetape_callback(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1076 | |
| 1077 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { |
| 1078 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | printk(KERN_ERR "ide-tape: The tape wants to issue more " |
| 1080 | "interrupts in DMA mode\n"); |
| 1081 | printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n"); |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 1082 | ide_dma_off(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | return ide_do_reset(drive); |
| 1084 | } |
| 1085 | /* Get the number of bytes to transfer on this interrupt. */ |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1086 | bcount = (hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]) << 8) | |
| 1087 | hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1089 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1091 | if (ireason & CD) { |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1092 | printk(KERN_ERR "ide-tape: CoD != 0 in %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | return ide_do_reset(drive); |
| 1094 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1095 | if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | /* Hopefully, we will never get here */ |
| 1097 | printk(KERN_ERR "ide-tape: We wanted to %s, ", |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1098 | (ireason & IO) ? "Write" : "Read"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | printk(KERN_ERR "ide-tape: but the tape wants us to %s !\n", |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1100 | (ireason & IO) ? "Read" : "Write"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | return ide_do_reset(drive); |
| 1102 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1103 | if (!(pc->flags & PC_FLAG_WRITING)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | /* Reading - Check that we have enough space */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1105 | temp = pc->xferred + bcount; |
| 1106 | if (temp > pc->req_xfer) { |
| 1107 | if (temp > pc->buf_size) { |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1108 | printk(KERN_ERR "ide-tape: The tape wants to " |
| 1109 | "send us more data than expected " |
| 1110 | "- discarding data\n"); |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1111 | ide_atapi_discard_data(drive, bcount); |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1112 | ide_set_handler(drive, &idetape_pc_intr, |
| 1113 | IDETAPE_WAIT_CMD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | return ide_started; |
| 1115 | } |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1116 | debug_log(DBG_SENSE, "The tape wants to send us more " |
| 1117 | "data than expected - allowing transfer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | } |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1119 | iobuf = &idetape_input_buffers; |
| 1120 | xferfunc = hwif->atapi_input_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } else { |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1122 | iobuf = &idetape_output_buffers; |
| 1123 | xferfunc = hwif->atapi_output_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1125 | |
| 1126 | if (pc->bh) |
| 1127 | iobuf(drive, pc, bcount); |
| 1128 | else |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1129 | xferfunc(drive, pc->cur_pos, bcount); |
Borislav Petkov | a1efc85 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | /* Update the current position */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1132 | pc->xferred += bcount; |
| 1133 | pc->cur_pos += bcount; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1134 | |
| 1135 | debug_log(DBG_SENSE, "[cmd %x] transferred %d bytes on that intr.\n", |
| 1136 | pc->c[0], bcount); |
| 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | /* And set the interrupt handler again */ |
| 1139 | ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL); |
| 1140 | return ide_started; |
| 1141 | } |
| 1142 | |
| 1143 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1144 | * Packet Command Interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1146 | * The current Packet Command is available in tape->pc, and will not change |
| 1147 | * until we finish handling it. Each packet command is associated with a |
| 1148 | * callback function that will be called when the command is finished. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1150 | * The handling will be done in three stages: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1152 | * 1. idetape_issue_pc will send the packet command to the drive, and will set |
| 1153 | * the interrupt handler to idetape_pc_intr. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1155 | * 2. On each interrupt, idetape_pc_intr will be called. This step will be |
| 1156 | * repeated until the device signals us that no more interrupts will be issued. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1158 | * 3. ATAPI Tape media access commands have immediate status with a delayed |
| 1159 | * process. In case of a successful initiation of a media access packet command, |
| 1160 | * the DSC bit will be set when the actual execution of the command is finished. |
| 1161 | * Since the tape drive will not issue an interrupt, we have to poll for this |
| 1162 | * event. In this case, we define the request as "low priority request" by |
| 1163 | * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and |
| 1164 | * exit the driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1166 | * ide.c will then give higher priority to requests which originate from the |
| 1167 | * other device, until will change rq_status to RQ_ACTIVE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1169 | * 4. When the packet command is finished, it will be checked for errors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1171 | * 5. In case an error was found, we queue a request sense packet command in |
| 1172 | * front of the request queue and retry the operation up to |
| 1173 | * IDETAPE_MAX_PC_RETRIES times. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1175 | * 6. In case no error was found, or we decided to give up and not to retry |
| 1176 | * again, the callback function will be called and then we will handle the next |
| 1177 | * request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | */ |
| 1179 | static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive) |
| 1180 | { |
| 1181 | ide_hwif_t *hwif = drive->hwif; |
| 1182 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1183 | struct ide_atapi_pc *pc = tape->pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | int retries = 100; |
| 1185 | ide_startstop_t startstop; |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1186 | u8 ireason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1188 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { |
| 1189 | printk(KERN_ERR "ide-tape: Strange, packet command initiated " |
| 1190 | "yet DRQ isn't asserted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | return startstop; |
| 1192 | } |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1193 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1194 | while (retries-- && ((ireason & CD) == 0 || (ireason & IO))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while issuing " |
| 1196 | "a packet command, retrying\n"); |
| 1197 | udelay(100); |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1198 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | if (retries == 0) { |
| 1200 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while " |
| 1201 | "issuing a packet command, ignoring\n"); |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1202 | ireason |= CD; |
| 1203 | ireason &= ~IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | } |
| 1205 | } |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1206 | if ((ireason & CD) == 0 || (ireason & IO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | printk(KERN_ERR "ide-tape: (IO,CoD) != (0,1) while issuing " |
| 1208 | "a packet command\n"); |
| 1209 | return ide_do_reset(drive); |
| 1210 | } |
| 1211 | /* Set the interrupt routine */ |
| 1212 | ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL); |
| 1213 | #ifdef CONFIG_BLK_DEV_IDEDMA |
| 1214 | /* Begin DMA, if necessary */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1215 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | hwif->dma_start(drive); |
| 1217 | #endif |
| 1218 | /* Send the actual packet */ |
| 1219 | HWIF(drive)->atapi_output_bytes(drive, pc->c, 12); |
| 1220 | return ide_started; |
| 1221 | } |
| 1222 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1223 | static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, |
| 1224 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | { |
| 1226 | ide_hwif_t *hwif = drive->hwif; |
| 1227 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | int dma_ok = 0; |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 1229 | u16 bcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1231 | if (tape->pc->c[0] == REQUEST_SENSE && |
| 1232 | pc->c[0] == REQUEST_SENSE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | printk(KERN_ERR "ide-tape: possible ide-tape.c bug - " |
| 1234 | "Two request sense in serial were issued\n"); |
| 1235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1237 | if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | tape->failed_pc = pc; |
| 1239 | /* Set the current packet command */ |
| 1240 | tape->pc = pc; |
| 1241 | |
| 1242 | if (pc->retries > IDETAPE_MAX_PC_RETRIES || |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1243 | (pc->flags & PC_FLAG_ABORT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1245 | * We will "abort" retrying a packet command in case legitimate |
| 1246 | * error code was received (crossing a filemark, or end of the |
| 1247 | * media, for example). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1249 | if (!(pc->flags & PC_FLAG_ABORT)) { |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1250 | if (!(pc->c[0] == TEST_UNIT_READY && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | tape->sense_key == 2 && tape->asc == 4 && |
| 1252 | (tape->ascq == 1 || tape->ascq == 8))) { |
| 1253 | printk(KERN_ERR "ide-tape: %s: I/O error, " |
| 1254 | "pc = %2x, key = %2x, " |
| 1255 | "asc = %2x, ascq = %2x\n", |
| 1256 | tape->name, pc->c[0], |
| 1257 | tape->sense_key, tape->asc, |
| 1258 | tape->ascq); |
| 1259 | } |
| 1260 | /* Giving up */ |
| 1261 | pc->error = IDETAPE_ERROR_GENERAL; |
| 1262 | } |
| 1263 | tape->failed_pc = NULL; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1264 | return pc->idetape_callback(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1266 | debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
| 1268 | pc->retries++; |
| 1269 | /* We haven't transferred any data yet */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1270 | pc->xferred = 0; |
| 1271 | pc->cur_pos = pc->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | /* Request to transfer the entire buffer at once */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1273 | bcount = pc->req_xfer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1275 | if (pc->flags & PC_FLAG_DMA_ERROR) { |
| 1276 | pc->flags &= ~PC_FLAG_DMA_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | printk(KERN_WARNING "ide-tape: DMA disabled, " |
| 1278 | "reverting to PIO\n"); |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 1279 | ide_dma_off(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1281 | if ((pc->flags & PC_FLAG_DMA_RECOMMENDED) && drive->using_dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | dma_ok = !hwif->dma_setup(drive); |
| 1283 | |
Bartlomiej Zolnierkiewicz | 2fc5738 | 2008-01-25 22:17:13 +0100 | [diff] [blame] | 1284 | ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK | |
| 1285 | IDE_TFLAG_OUT_DEVICE, bcount, dma_ok); |
| 1286 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1287 | if (dma_ok) |
| 1288 | /* Will begin DMA later */ |
| 1289 | pc->flags |= PC_FLAG_DMA_IN_PROGRESS; |
| 1290 | if (test_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags)) { |
Bartlomiej Zolnierkiewicz | c1c9dbc | 2008-02-02 19:56:44 +0100 | [diff] [blame] | 1291 | ide_execute_command(drive, WIN_PACKETCMD, &idetape_transfer_pc, |
| 1292 | IDETAPE_WAIT_CMD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | return ide_started; |
| 1294 | } else { |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1295 | hwif->OUTB(WIN_PACKETCMD, hwif->io_ports[IDE_COMMAND_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | return idetape_transfer_pc(drive); |
| 1297 | } |
| 1298 | } |
| 1299 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1300 | static ide_startstop_t idetape_pc_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | { |
| 1302 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1303 | |
| 1304 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
| 1306 | idetape_end_request(drive, tape->pc->error ? 0 : 1, 0); |
| 1307 | return ide_stopped; |
| 1308 | } |
| 1309 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1310 | /* A mode sense command is used to "sense" tape parameters. */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1311 | static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | { |
| 1313 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1314 | pc->c[0] = MODE_SENSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | if (page_code != IDETAPE_BLOCK_DESCRIPTOR) |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1316 | /* DBD = 1 - Don't return block descriptors */ |
| 1317 | pc->c[1] = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | pc->c[2] = page_code; |
| 1319 | /* |
| 1320 | * Changed pc->c[3] to 0 (255 will at best return unused info). |
| 1321 | * |
| 1322 | * For SCSI this byte is defined as subpage instead of high byte |
| 1323 | * of length and some IDE drives seem to interpret it this way |
| 1324 | * and return an error when 255 is used. |
| 1325 | */ |
| 1326 | pc->c[3] = 0; |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1327 | /* We will just discard data in that case */ |
| 1328 | pc->c[4] = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | if (page_code == IDETAPE_BLOCK_DESCRIPTOR) |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1330 | pc->req_xfer = 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | else if (page_code == IDETAPE_CAPABILITIES_PAGE) |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1332 | pc->req_xfer = 24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | else |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1334 | pc->req_xfer = 50; |
| 1335 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Borislav Petkov | 37016ba | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1338 | static void idetape_calculate_speeds(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | { |
| 1340 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1342 | if (time_after(jiffies, |
| 1343 | tape->controlled_pipeline_head_time + 120 * HZ)) { |
| 1344 | tape->controlled_previous_pipeline_head = |
| 1345 | tape->controlled_last_pipeline_head; |
| 1346 | tape->controlled_previous_head_time = |
| 1347 | tape->controlled_pipeline_head_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | tape->controlled_last_pipeline_head = tape->pipeline_head; |
| 1349 | tape->controlled_pipeline_head_time = jiffies; |
| 1350 | } |
| 1351 | if (time_after(jiffies, tape->controlled_pipeline_head_time + 60 * HZ)) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1352 | tape->controlled_pipeline_head_speed = (tape->pipeline_head - |
| 1353 | tape->controlled_last_pipeline_head) * 32 * HZ / |
| 1354 | (jiffies - tape->controlled_pipeline_head_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | else if (time_after(jiffies, tape->controlled_previous_head_time)) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1356 | tape->controlled_pipeline_head_speed = (tape->pipeline_head - |
| 1357 | tape->controlled_previous_pipeline_head) * 32 * |
| 1358 | HZ / (jiffies - tape->controlled_previous_head_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1360 | if (tape->nr_pending_stages < tape->max_stages/*- 1 */) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | /* -1 for read mode error recovery */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1362 | if (time_after(jiffies, tape->uncontrolled_previous_head_time + |
| 1363 | 10 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | tape->uncontrolled_pipeline_head_time = jiffies; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1365 | tape->uncontrolled_pipeline_head_speed = |
| 1366 | (tape->pipeline_head - |
| 1367 | tape->uncontrolled_previous_pipeline_head) * |
| 1368 | 32 * HZ / (jiffies - |
| 1369 | tape->uncontrolled_previous_head_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | } |
| 1371 | } else { |
| 1372 | tape->uncontrolled_previous_head_time = jiffies; |
| 1373 | tape->uncontrolled_previous_pipeline_head = tape->pipeline_head; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1374 | if (time_after(jiffies, tape->uncontrolled_pipeline_head_time + |
| 1375 | 30 * HZ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | tape->uncontrolled_pipeline_head_time = jiffies; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1379 | tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed, |
| 1380 | tape->controlled_pipeline_head_speed); |
Borislav Petkov | 37016ba | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1381 | |
| 1382 | if (tape->speed_control == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | if (tape->nr_pending_stages >= tape->max_stages / 2) |
| 1384 | tape->max_insert_speed = tape->pipeline_head_speed + |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1385 | (1100 - tape->pipeline_head_speed) * 2 * |
| 1386 | (tape->nr_pending_stages - tape->max_stages / 2) |
| 1387 | / tape->max_stages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | else |
| 1389 | tape->max_insert_speed = 500 + |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1390 | (tape->pipeline_head_speed - 500) * 2 * |
| 1391 | tape->nr_pending_stages / tape->max_stages; |
Borislav Petkov | 37016ba | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | if (tape->nr_pending_stages >= tape->max_stages * 99 / 100) |
| 1394 | tape->max_insert_speed = 5000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } else |
| 1396 | tape->max_insert_speed = tape->speed_control; |
Borislav Petkov | 37016ba | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | tape->max_insert_speed = max(tape->max_insert_speed, 500); |
| 1399 | } |
| 1400 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1401 | static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
| 1403 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1404 | struct ide_atapi_pc *pc = tape->pc; |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1405 | u8 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1407 | stat = ide_read_status(drive); |
| 1408 | |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1409 | if (stat & SEEK_STAT) { |
| 1410 | if (stat & ERR_STAT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | /* Error detected */ |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1412 | if (pc->c[0] != TEST_UNIT_READY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | printk(KERN_ERR "ide-tape: %s: I/O error, ", |
| 1414 | tape->name); |
| 1415 | /* Retry operation */ |
| 1416 | return idetape_retry_pc(drive); |
| 1417 | } |
| 1418 | pc->error = 0; |
| 1419 | if (tape->failed_pc == pc) |
| 1420 | tape->failed_pc = NULL; |
| 1421 | } else { |
| 1422 | pc->error = IDETAPE_ERROR_GENERAL; |
| 1423 | tape->failed_pc = NULL; |
| 1424 | } |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1425 | return pc->idetape_callback(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1428 | static ide_startstop_t idetape_rw_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | { |
| 1430 | idetape_tape_t *tape = drive->driver_data; |
| 1431 | struct request *rq = HWGROUP(drive)->rq; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1432 | int blocks = tape->pc->xferred / tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1434 | tape->avg_size += blocks * tape->blk_size; |
| 1435 | tape->insert_size += blocks * tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | if (tape->insert_size > 1024 * 1024) |
| 1437 | tape->measure_insert_time = 1; |
| 1438 | if (tape->measure_insert_time) { |
| 1439 | tape->measure_insert_time = 0; |
| 1440 | tape->insert_time = jiffies; |
| 1441 | tape->insert_size = 0; |
| 1442 | } |
| 1443 | if (time_after(jiffies, tape->insert_time)) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1444 | tape->insert_speed = tape->insert_size / 1024 * HZ / |
| 1445 | (jiffies - tape->insert_time); |
Marcelo Feitoza Parisi | 9bae1ff | 2006-03-28 01:56:46 -0800 | [diff] [blame] | 1446 | if (time_after_eq(jiffies, tape->avg_time + HZ)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1447 | tape->avg_speed = tape->avg_size * HZ / |
| 1448 | (jiffies - tape->avg_time) / 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | tape->avg_size = 0; |
| 1450 | tape->avg_time = jiffies; |
| 1451 | } |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1452 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1454 | tape->first_frame += blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | rq->current_nr_sectors -= blocks; |
| 1456 | |
| 1457 | if (!tape->pc->error) |
| 1458 | idetape_end_request(drive, 1, 0); |
| 1459 | else |
| 1460 | idetape_end_request(drive, tape->pc->error, 0); |
| 1461 | return ide_stopped; |
| 1462 | } |
| 1463 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1464 | static void idetape_create_read_cmd(idetape_tape_t *tape, |
| 1465 | struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1466 | unsigned int length, struct idetape_bh *bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | { |
| 1468 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1469 | pc->c[0] = READ_6; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1470 | put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | pc->c[1] = 1; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1472 | pc->idetape_callback = &idetape_rw_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | pc->bh = bh; |
| 1474 | atomic_set(&bh->b_count, 0); |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1475 | pc->buf = NULL; |
| 1476 | pc->buf_size = length * tape->blk_size; |
| 1477 | pc->req_xfer = pc->buf_size; |
| 1478 | if (pc->req_xfer == tape->stage_size) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1479 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1482 | static void idetape_create_write_cmd(idetape_tape_t *tape, |
| 1483 | struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1484 | unsigned int length, struct idetape_bh *bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | { |
| 1486 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1487 | pc->c[0] = WRITE_6; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1488 | put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | pc->c[1] = 1; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1490 | pc->idetape_callback = &idetape_rw_callback; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1491 | pc->flags |= PC_FLAG_WRITING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | pc->bh = bh; |
| 1493 | pc->b_data = bh->b_data; |
| 1494 | pc->b_count = atomic_read(&bh->b_count); |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1495 | pc->buf = NULL; |
| 1496 | pc->buf_size = length * tape->blk_size; |
| 1497 | pc->req_xfer = pc->buf_size; |
| 1498 | if (pc->req_xfer == tape->stage_size) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1499 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | static ide_startstop_t idetape_do_request(ide_drive_t *drive, |
| 1503 | struct request *rq, sector_t block) |
| 1504 | { |
| 1505 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1506 | struct ide_atapi_pc *pc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | struct request *postponed_rq = tape->postponed_rq; |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1508 | u8 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1510 | debug_log(DBG_SENSE, "sector: %ld, nr_sectors: %ld," |
| 1511 | " current_nr_sectors: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | rq->sector, rq->nr_sectors, rq->current_nr_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 1514 | if (!blk_special_request(rq)) { |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1515 | /* We do not support buffer cache originated requests. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 1517 | "request queue (%d)\n", drive->name, rq->cmd_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | ide_end_request(drive, 0, 0); |
| 1519 | return ide_stopped; |
| 1520 | } |
| 1521 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1522 | /* Retry a failed packet command */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1523 | if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE) |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1524 | return idetape_issue_pc(drive, tape->failed_pc); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | if (postponed_rq != NULL) |
| 1527 | if (rq != postponed_rq) { |
| 1528 | printk(KERN_ERR "ide-tape: ide-tape.c bug - " |
| 1529 | "Two DSC requests were queued\n"); |
| 1530 | idetape_end_request(drive, 0, 0); |
| 1531 | return ide_stopped; |
| 1532 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | |
| 1534 | tape->postponed_rq = NULL; |
| 1535 | |
| 1536 | /* |
| 1537 | * If the tape is still busy, postpone our request and service |
| 1538 | * the other device meanwhile. |
| 1539 | */ |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1540 | stat = ide_read_status(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
| 1542 | if (!drive->dsc_overlap && !(rq->cmd[0] & REQ_IDETAPE_PC2)) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1543 | set_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | |
| 1545 | if (drive->post_reset == 1) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1546 | set_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | drive->post_reset = 0; |
| 1548 | } |
| 1549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | if (time_after(jiffies, tape->insert_time)) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1551 | tape->insert_speed = tape->insert_size / 1024 * HZ / |
| 1552 | (jiffies - tape->insert_time); |
Borislav Petkov | 37016ba | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1553 | idetape_calculate_speeds(drive); |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1554 | if (!test_and_clear_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags) && |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1555 | (stat & SEEK_STAT) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | if (postponed_rq == NULL) { |
| 1557 | tape->dsc_polling_start = jiffies; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1558 | tape->dsc_poll_freq = tape->best_dsc_rw_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT; |
| 1560 | } else if (time_after(jiffies, tape->dsc_timeout)) { |
| 1561 | printk(KERN_ERR "ide-tape: %s: DSC timeout\n", |
| 1562 | tape->name); |
| 1563 | if (rq->cmd[0] & REQ_IDETAPE_PC2) { |
| 1564 | idetape_media_access_finished(drive); |
| 1565 | return ide_stopped; |
| 1566 | } else { |
| 1567 | return ide_do_reset(drive); |
| 1568 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1569 | } else if (time_after(jiffies, |
| 1570 | tape->dsc_polling_start + |
| 1571 | IDETAPE_DSC_MA_THRESHOLD)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1572 | tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | idetape_postpone_request(drive); |
| 1574 | return ide_stopped; |
| 1575 | } |
| 1576 | if (rq->cmd[0] & REQ_IDETAPE_READ) { |
| 1577 | tape->buffer_head++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | tape->postpone_cnt = 0; |
| 1579 | pc = idetape_next_pc_storage(drive); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1580 | idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, |
| 1581 | (struct idetape_bh *)rq->special); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | goto out; |
| 1583 | } |
| 1584 | if (rq->cmd[0] & REQ_IDETAPE_WRITE) { |
| 1585 | tape->buffer_head++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | tape->postpone_cnt = 0; |
| 1587 | pc = idetape_next_pc_storage(drive); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1588 | idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, |
| 1589 | (struct idetape_bh *)rq->special); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | goto out; |
| 1591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | if (rq->cmd[0] & REQ_IDETAPE_PC1) { |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1593 | pc = (struct ide_atapi_pc *) rq->buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | rq->cmd[0] &= ~(REQ_IDETAPE_PC1); |
| 1595 | rq->cmd[0] |= REQ_IDETAPE_PC2; |
| 1596 | goto out; |
| 1597 | } |
| 1598 | if (rq->cmd[0] & REQ_IDETAPE_PC2) { |
| 1599 | idetape_media_access_finished(drive); |
| 1600 | return ide_stopped; |
| 1601 | } |
| 1602 | BUG(); |
| 1603 | out: |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1604 | return idetape_issue_pc(drive, pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1607 | /* Pipeline related functions */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1608 | static inline int idetape_pipeline_active(idetape_tape_t *tape) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | { |
| 1610 | int rc1, rc2; |
| 1611 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1612 | rc1 = test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1613 | rc2 = (tape->active_data_rq != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | return rc1; |
| 1615 | } |
| 1616 | |
| 1617 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1618 | * The function below uses __get_free_page to allocate a pipeline stage, along |
| 1619 | * with all the necessary small buffers which together make a buffer of size |
| 1620 | * tape->stage_size (or a bit more). We attempt to combine sequential pages as |
| 1621 | * much as possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1623 | * It returns a pointer to the new allocated stage, or NULL if we can't (or |
| 1624 | * don't want to) allocate a stage. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1626 | * Pipeline stages are optional and are used to increase performance. If we |
| 1627 | * can't allocate them, we'll manage without them. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1629 | static idetape_stage_t *__idetape_kmalloc_stage(idetape_tape_t *tape, int full, |
| 1630 | int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | { |
| 1632 | idetape_stage_t *stage; |
| 1633 | struct idetape_bh *prev_bh, *bh; |
| 1634 | int pages = tape->pages_per_stage; |
| 1635 | char *b_data = NULL; |
| 1636 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1637 | stage = kmalloc(sizeof(idetape_stage_t), GFP_KERNEL); |
| 1638 | if (!stage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | return NULL; |
| 1640 | stage->next = NULL; |
| 1641 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1642 | stage->bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); |
| 1643 | bh = stage->bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | if (bh == NULL) |
| 1645 | goto abort; |
| 1646 | bh->b_reqnext = NULL; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1647 | bh->b_data = (char *) __get_free_page(GFP_KERNEL); |
| 1648 | if (!bh->b_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | goto abort; |
| 1650 | if (clear) |
| 1651 | memset(bh->b_data, 0, PAGE_SIZE); |
| 1652 | bh->b_size = PAGE_SIZE; |
| 1653 | atomic_set(&bh->b_count, full ? bh->b_size : 0); |
| 1654 | |
| 1655 | while (--pages) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1656 | b_data = (char *) __get_free_page(GFP_KERNEL); |
| 1657 | if (!b_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | goto abort; |
| 1659 | if (clear) |
| 1660 | memset(b_data, 0, PAGE_SIZE); |
| 1661 | if (bh->b_data == b_data + PAGE_SIZE) { |
| 1662 | bh->b_size += PAGE_SIZE; |
| 1663 | bh->b_data -= PAGE_SIZE; |
| 1664 | if (full) |
| 1665 | atomic_add(PAGE_SIZE, &bh->b_count); |
| 1666 | continue; |
| 1667 | } |
| 1668 | if (b_data == bh->b_data + bh->b_size) { |
| 1669 | bh->b_size += PAGE_SIZE; |
| 1670 | if (full) |
| 1671 | atomic_add(PAGE_SIZE, &bh->b_count); |
| 1672 | continue; |
| 1673 | } |
| 1674 | prev_bh = bh; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1675 | bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); |
| 1676 | if (!bh) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | free_page((unsigned long) b_data); |
| 1678 | goto abort; |
| 1679 | } |
| 1680 | bh->b_reqnext = NULL; |
| 1681 | bh->b_data = b_data; |
| 1682 | bh->b_size = PAGE_SIZE; |
| 1683 | atomic_set(&bh->b_count, full ? bh->b_size : 0); |
| 1684 | prev_bh->b_reqnext = bh; |
| 1685 | } |
| 1686 | bh->b_size -= tape->excess_bh_size; |
| 1687 | if (full) |
| 1688 | atomic_sub(tape->excess_bh_size, &bh->b_count); |
| 1689 | return stage; |
| 1690 | abort: |
| 1691 | __idetape_kfree_stage(stage); |
| 1692 | return NULL; |
| 1693 | } |
| 1694 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1695 | static idetape_stage_t *idetape_kmalloc_stage(idetape_tape_t *tape) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | { |
| 1697 | idetape_stage_t *cache_stage = tape->cache_stage; |
| 1698 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1699 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | |
| 1701 | if (tape->nr_stages >= tape->max_stages) |
| 1702 | return NULL; |
| 1703 | if (cache_stage != NULL) { |
| 1704 | tape->cache_stage = NULL; |
| 1705 | return cache_stage; |
| 1706 | } |
| 1707 | return __idetape_kmalloc_stage(tape, 0, 0); |
| 1708 | } |
| 1709 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1710 | static int idetape_copy_stage_from_user(idetape_tape_t *tape, |
| 1711 | idetape_stage_t *stage, const char __user *buf, int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | { |
| 1713 | struct idetape_bh *bh = tape->bh; |
| 1714 | int count; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1715 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
| 1717 | while (n) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | if (bh == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1719 | printk(KERN_ERR "ide-tape: bh == NULL in %s\n", |
| 1720 | __func__); |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1721 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1723 | count = min((unsigned int) |
| 1724 | (bh->b_size - atomic_read(&bh->b_count)), |
| 1725 | (unsigned int)n); |
| 1726 | if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf, |
| 1727 | count)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1728 | ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | n -= count; |
| 1730 | atomic_add(count, &bh->b_count); |
| 1731 | buf += count; |
| 1732 | if (atomic_read(&bh->b_count) == bh->b_size) { |
| 1733 | bh = bh->b_reqnext; |
| 1734 | if (bh) |
| 1735 | atomic_set(&bh->b_count, 0); |
| 1736 | } |
| 1737 | } |
| 1738 | tape->bh = bh; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1739 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1742 | static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf, |
| 1743 | idetape_stage_t *stage, int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | { |
| 1745 | struct idetape_bh *bh = tape->bh; |
| 1746 | int count; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1747 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | |
| 1749 | while (n) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | if (bh == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1751 | printk(KERN_ERR "ide-tape: bh == NULL in %s\n", |
| 1752 | __func__); |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1753 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | count = min(tape->b_count, n); |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1756 | if (copy_to_user(buf, tape->b_data, count)) |
| 1757 | ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | n -= count; |
| 1759 | tape->b_data += count; |
| 1760 | tape->b_count -= count; |
| 1761 | buf += count; |
| 1762 | if (!tape->b_count) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1763 | bh = bh->b_reqnext; |
| 1764 | tape->bh = bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | if (bh) { |
| 1766 | tape->b_data = bh->b_data; |
| 1767 | tape->b_count = atomic_read(&bh->b_count); |
| 1768 | } |
| 1769 | } |
| 1770 | } |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1771 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1774 | static void idetape_init_merge_stage(idetape_tape_t *tape) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | { |
| 1776 | struct idetape_bh *bh = tape->merge_stage->bh; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | tape->bh = bh; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1779 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | atomic_set(&bh->b_count, 0); |
| 1781 | else { |
| 1782 | tape->b_data = bh->b_data; |
| 1783 | tape->b_count = atomic_read(&bh->b_count); |
| 1784 | } |
| 1785 | } |
| 1786 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1787 | static void idetape_switch_buffers(idetape_tape_t *tape, idetape_stage_t *stage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | { |
| 1789 | struct idetape_bh *tmp; |
| 1790 | |
| 1791 | tmp = stage->bh; |
| 1792 | stage->bh = tape->merge_stage->bh; |
| 1793 | tape->merge_stage->bh = tmp; |
| 1794 | idetape_init_merge_stage(tape); |
| 1795 | } |
| 1796 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1797 | /* Add a new stage at the end of the pipeline. */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1798 | static void idetape_add_stage_tail(ide_drive_t *drive, idetape_stage_t *stage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | { |
| 1800 | idetape_tape_t *tape = drive->driver_data; |
| 1801 | unsigned long flags; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1802 | |
| 1803 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
| 1804 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1805 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | stage->next = NULL; |
| 1807 | if (tape->last_stage != NULL) |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1808 | tape->last_stage->next = stage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | else |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1810 | tape->first_stage = stage; |
| 1811 | tape->next_stage = stage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | tape->last_stage = stage; |
| 1813 | if (tape->next_stage == NULL) |
| 1814 | tape->next_stage = tape->last_stage; |
| 1815 | tape->nr_stages++; |
| 1816 | tape->nr_pending_stages++; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1817 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1820 | /* Install a completion in a pending request and sleep until it is serviced. The |
| 1821 | * caller should ensure that the request will not be serviced before we install |
| 1822 | * the completion (usually by disabling interrupts). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1824 | static void idetape_wait_for_request(ide_drive_t *drive, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | { |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 1826 | DECLARE_COMPLETION_ONSTACK(wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | idetape_tape_t *tape = drive->driver_data; |
| 1828 | |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 1829 | if (rq == NULL || !blk_special_request(rq)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1830 | printk(KERN_ERR "ide-tape: bug: Trying to sleep on non-valid" |
| 1831 | " request\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | return; |
| 1833 | } |
Jens Axboe | c00895a | 2006-09-30 20:29:12 +0200 | [diff] [blame] | 1834 | rq->end_io_data = &wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | rq->end_io = blk_end_sync_rq; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1836 | spin_unlock_irq(&tape->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | wait_for_completion(&wait); |
| 1838 | /* The stage and its struct request have been deallocated */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1839 | spin_lock_irq(&tape->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Borislav Petkov | a2f5b7f | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1842 | static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | { |
| 1844 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1845 | u8 *readpos = tape->pc->buf; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1846 | |
| 1847 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | |
| 1849 | if (!tape->pc->error) { |
Borislav Petkov | a2f5b7f | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1850 | debug_log(DBG_SENSE, "BOP - %s\n", |
| 1851 | (readpos[0] & 0x80) ? "Yes" : "No"); |
| 1852 | debug_log(DBG_SENSE, "EOP - %s\n", |
| 1853 | (readpos[0] & 0x40) ? "Yes" : "No"); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1854 | |
Borislav Petkov | a2f5b7f | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1855 | if (readpos[0] & 0x4) { |
| 1856 | printk(KERN_INFO "ide-tape: Block location is unknown" |
| 1857 | "to the tape\n"); |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1858 | clear_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | idetape_end_request(drive, 0, 0); |
| 1860 | } else { |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1861 | debug_log(DBG_SENSE, "Block Location - %u\n", |
Borislav Petkov | a2f5b7f | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1862 | be32_to_cpu(*(u32 *)&readpos[4])); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1863 | |
Borislav Petkov | a2f5b7f | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1864 | tape->partition = readpos[1]; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1865 | tape->first_frame = |
Borislav Petkov | a2f5b7f | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1866 | be32_to_cpu(*(u32 *)&readpos[4]); |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1867 | set_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | idetape_end_request(drive, 1, 0); |
| 1869 | } |
| 1870 | } else { |
| 1871 | idetape_end_request(drive, 0, 0); |
| 1872 | } |
| 1873 | return ide_stopped; |
| 1874 | } |
| 1875 | |
| 1876 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1877 | * Write a filemark if write_filemark=1. Flush the device buffers without |
| 1878 | * writing a filemark otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1880 | static void idetape_create_write_filemark_cmd(ide_drive_t *drive, |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1881 | struct ide_atapi_pc *pc, int write_filemark) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | { |
| 1883 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1884 | pc->c[0] = WRITE_FILEMARKS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | pc->c[4] = write_filemark; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1886 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1887 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1890 | static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | { |
| 1892 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1893 | pc->c[0] = TEST_UNIT_READY; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1894 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1898 | * We add a special packet command request to the tail of the request queue, and |
| 1899 | * wait for it to be serviced. This is not to be called from within the request |
| 1900 | * handling part of the driver! We allocate here data on the stack and it is |
| 1901 | * valid until the request is finished. This is not the case for the bottom part |
| 1902 | * of the driver, where we are always leaving the functions to wait for an |
| 1903 | * interrupt or a timer event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1905 | * From the bottom part of the driver, we should allocate safe memory using |
| 1906 | * idetape_next_pc_storage() and ide_tape_next_rq_storage(), and add the request |
| 1907 | * to the request list without waiting for it to be serviced! In that case, we |
| 1908 | * usually use idetape_queue_pc_head(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1910 | static int __idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | { |
| 1912 | struct ide_tape_obj *tape = drive->driver_data; |
| 1913 | struct request rq; |
| 1914 | |
| 1915 | idetape_init_rq(&rq, REQ_IDETAPE_PC1); |
| 1916 | rq.buffer = (char *) pc; |
| 1917 | rq.rq_disk = tape->disk; |
| 1918 | return ide_do_drive_cmd(drive, &rq, ide_wait); |
| 1919 | } |
| 1920 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1921 | static void idetape_create_load_unload_cmd(ide_drive_t *drive, |
| 1922 | struct ide_atapi_pc *pc, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | { |
| 1924 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1925 | pc->c[0] = START_STOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | pc->c[4] = cmd; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1927 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1928 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) |
| 1932 | { |
| 1933 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1934 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | int load_attempted = 0; |
| 1936 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1937 | /* Wait for the tape to become ready */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 1938 | set_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | timeout += jiffies; |
| 1940 | while (time_before(jiffies, timeout)) { |
| 1941 | idetape_create_test_unit_ready_cmd(&pc); |
| 1942 | if (!__idetape_queue_pc_tail(drive, &pc)) |
| 1943 | return 0; |
| 1944 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1945 | || (tape->asc == 0x3A)) { |
| 1946 | /* no media */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | if (load_attempted) |
| 1948 | return -ENOMEDIUM; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1949 | idetape_create_load_unload_cmd(drive, &pc, |
| 1950 | IDETAPE_LU_LOAD_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | __idetape_queue_pc_tail(drive, &pc); |
| 1952 | load_attempted = 1; |
| 1953 | /* not about to be ready */ |
| 1954 | } else if (!(tape->sense_key == 2 && tape->asc == 4 && |
| 1955 | (tape->ascq == 1 || tape->ascq == 8))) |
| 1956 | return -EIO; |
Nishanth Aravamudan | 80ce45f | 2005-09-10 00:27:08 -0700 | [diff] [blame] | 1957 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | } |
| 1959 | return -EIO; |
| 1960 | } |
| 1961 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1962 | static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | { |
| 1964 | return __idetape_queue_pc_tail(drive, pc); |
| 1965 | } |
| 1966 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1967 | static int idetape_flush_tape_buffers(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | { |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1969 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | int rc; |
| 1971 | |
| 1972 | idetape_create_write_filemark_cmd(drive, &pc, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1973 | rc = idetape_queue_pc_tail(drive, &pc); |
| 1974 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | return rc; |
| 1976 | idetape_wait_ready(drive, 60 * 5 * HZ); |
| 1977 | return 0; |
| 1978 | } |
| 1979 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1980 | static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | { |
| 1982 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1983 | pc->c[0] = READ_POSITION; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1984 | pc->req_xfer = 20; |
| 1985 | pc->idetape_callback = &idetape_read_position_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1988 | static int idetape_read_position(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | { |
| 1990 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1991 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | int position; |
| 1993 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1994 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
| 1996 | idetape_create_read_position_cmd(&pc); |
| 1997 | if (idetape_queue_pc_tail(drive, &pc)) |
| 1998 | return -1; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1999 | position = tape->first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | return position; |
| 2001 | } |
| 2002 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2003 | static void idetape_create_locate_cmd(ide_drive_t *drive, |
| 2004 | struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2005 | unsigned int block, u8 partition, int skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | { |
| 2007 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2008 | pc->c[0] = POSITION_TO_ELEMENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | pc->c[1] = 2; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2010 | put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | pc->c[8] = partition; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2012 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2013 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2016 | static int idetape_create_prevent_cmd(ide_drive_t *drive, |
| 2017 | struct ide_atapi_pc *pc, int prevent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | { |
| 2019 | idetape_tape_t *tape = drive->driver_data; |
| 2020 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2021 | /* device supports locking according to capabilities page */ |
| 2022 | if (!(tape->caps[6] & 0x01)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | return 0; |
| 2024 | |
| 2025 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2026 | pc->c[0] = ALLOW_MEDIUM_REMOVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | pc->c[4] = prevent; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2028 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | return 1; |
| 2030 | } |
| 2031 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2032 | static int __idetape_discard_read_pipeline(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | { |
| 2034 | idetape_tape_t *tape = drive->driver_data; |
| 2035 | unsigned long flags; |
| 2036 | int cnt; |
| 2037 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2038 | if (tape->chrdev_dir != IDETAPE_DIR_READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | return 0; |
| 2040 | |
| 2041 | /* Remove merge stage. */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2042 | cnt = tape->merge_stage_size / tape->blk_size; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2043 | if (test_and_clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | ++cnt; /* Filemarks count as 1 sector */ |
| 2045 | tape->merge_stage_size = 0; |
| 2046 | if (tape->merge_stage != NULL) { |
| 2047 | __idetape_kfree_stage(tape->merge_stage); |
| 2048 | tape->merge_stage = NULL; |
| 2049 | } |
| 2050 | |
| 2051 | /* Clear pipeline flags. */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2052 | clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags); |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2053 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | |
| 2055 | /* Remove pipeline stages. */ |
| 2056 | if (tape->first_stage == NULL) |
| 2057 | return 0; |
| 2058 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2059 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | tape->next_stage = NULL; |
| 2061 | if (idetape_pipeline_active(tape)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2062 | idetape_wait_for_request(drive, tape->active_data_rq); |
| 2063 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | |
| 2065 | while (tape->first_stage != NULL) { |
| 2066 | struct request *rq_ptr = &tape->first_stage->rq; |
| 2067 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2068 | cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) |
| 2070 | ++cnt; |
| 2071 | idetape_remove_stage_head(drive); |
| 2072 | } |
| 2073 | tape->nr_pending_stages = 0; |
| 2074 | tape->max_stages = tape->min_pipeline; |
| 2075 | return cnt; |
| 2076 | } |
| 2077 | |
| 2078 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2079 | * Position the tape to the requested block using the LOCATE packet command. |
| 2080 | * A READ POSITION command is then issued to check where we are positioned. Like |
| 2081 | * all higher level operations, we queue the commands at the tail of the request |
| 2082 | * queue and wait for their completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2084 | static int idetape_position_tape(ide_drive_t *drive, unsigned int block, |
| 2085 | u8 partition, int skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | { |
| 2087 | idetape_tape_t *tape = drive->driver_data; |
| 2088 | int retval; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2089 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2091 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | __idetape_discard_read_pipeline(drive); |
| 2093 | idetape_wait_ready(drive, 60 * 5 * HZ); |
| 2094 | idetape_create_locate_cmd(drive, &pc, block, partition, skip); |
| 2095 | retval = idetape_queue_pc_tail(drive, &pc); |
| 2096 | if (retval) |
| 2097 | return (retval); |
| 2098 | |
| 2099 | idetape_create_read_position_cmd(&pc); |
| 2100 | return (idetape_queue_pc_tail(drive, &pc)); |
| 2101 | } |
| 2102 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2103 | static void idetape_discard_read_pipeline(ide_drive_t *drive, |
| 2104 | int restore_position) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | { |
| 2106 | idetape_tape_t *tape = drive->driver_data; |
| 2107 | int cnt; |
| 2108 | int seek, position; |
| 2109 | |
| 2110 | cnt = __idetape_discard_read_pipeline(drive); |
| 2111 | if (restore_position) { |
| 2112 | position = idetape_read_position(drive); |
| 2113 | seek = position > cnt ? position - cnt : 0; |
| 2114 | if (idetape_position_tape(drive, seek, 0, 0)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2115 | printk(KERN_INFO "ide-tape: %s: position_tape failed in" |
| 2116 | " discard_pipeline()\n", tape->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | return; |
| 2118 | } |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2123 | * Generate a read/write request for the block device interface and wait for it |
| 2124 | * to be serviced. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2126 | static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, |
| 2127 | struct idetape_bh *bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | { |
| 2129 | idetape_tape_t *tape = drive->driver_data; |
| 2130 | struct request rq; |
| 2131 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2132 | debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); |
| 2133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | if (idetape_pipeline_active(tape)) { |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2135 | printk(KERN_ERR "ide-tape: bug: the pipeline is active in %s\n", |
| 2136 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | return (0); |
| 2138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | |
| 2140 | idetape_init_rq(&rq, cmd); |
| 2141 | rq.rq_disk = tape->disk; |
| 2142 | rq.special = (void *)bh; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2143 | rq.sector = tape->first_frame; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2144 | rq.nr_sectors = blocks; |
| 2145 | rq.current_nr_sectors = blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | (void) ide_do_drive_cmd(drive, &rq, ide_wait); |
| 2147 | |
| 2148 | if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) |
| 2149 | return 0; |
| 2150 | |
| 2151 | if (tape->merge_stage) |
| 2152 | idetape_init_merge_stage(tape); |
| 2153 | if (rq.errors == IDETAPE_ERROR_GENERAL) |
| 2154 | return -EIO; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2155 | return (tape->blk_size * (blocks-rq.current_nr_sectors)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2158 | /* start servicing the pipeline stages, starting from tape->next_stage. */ |
| 2159 | static void idetape_plug_pipeline(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | { |
| 2161 | idetape_tape_t *tape = drive->driver_data; |
| 2162 | |
| 2163 | if (tape->next_stage == NULL) |
| 2164 | return; |
| 2165 | if (!idetape_pipeline_active(tape)) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2166 | set_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags); |
Borislav Petkov | 419d474 | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 2167 | idetape_activate_next_stage(drive); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2168 | (void) ide_do_drive_cmd(drive, tape->active_data_rq, ide_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | } |
| 2170 | } |
| 2171 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2172 | static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | { |
| 2174 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2175 | pc->c[0] = INQUIRY; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2176 | pc->c[4] = 254; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2177 | pc->req_xfer = 254; |
| 2178 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2181 | static void idetape_create_rewind_cmd(ide_drive_t *drive, |
| 2182 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | { |
| 2184 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2185 | pc->c[0] = REZERO_UNIT; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2186 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2187 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2190 | static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | { |
| 2192 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2193 | pc->c[0] = ERASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | pc->c[1] = 1; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2195 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2196 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2199 | static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | { |
| 2201 | idetape_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2202 | pc->c[0] = SPACE; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 2203 | put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | pc->c[1] = cmd; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2205 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2206 | pc->idetape_callback = &idetape_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2209 | static void idetape_wait_first_stage(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | { |
| 2211 | idetape_tape_t *tape = drive->driver_data; |
| 2212 | unsigned long flags; |
| 2213 | |
| 2214 | if (tape->first_stage == NULL) |
| 2215 | return; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2216 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | if (tape->active_stage == tape->first_stage) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2218 | idetape_wait_for_request(drive, tape->active_data_rq); |
| 2219 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2223 | * Try to add a character device originated write request to our pipeline. In |
| 2224 | * case we don't succeed, we revert to non-pipelined operation mode for this |
| 2225 | * request. In order to accomplish that, we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2227 | * 1. Try to allocate a new pipeline stage. |
| 2228 | * 2. If we can't, wait for more and more requests to be serviced and try again |
| 2229 | * each time. |
| 2230 | * 3. If we still can't allocate a stage, fallback to non-pipelined operation |
| 2231 | * mode for this request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2233 | static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | { |
| 2235 | idetape_tape_t *tape = drive->driver_data; |
| 2236 | idetape_stage_t *new_stage; |
| 2237 | unsigned long flags; |
| 2238 | struct request *rq; |
| 2239 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2240 | debug_log(DBG_CHRDEV, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2242 | /* Attempt to allocate a new stage. Beware possible race conditions. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2244 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | if (idetape_pipeline_active(tape)) { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2246 | idetape_wait_for_request(drive, tape->active_data_rq); |
| 2247 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | } else { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2249 | spin_unlock_irqrestore(&tape->lock, flags); |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2250 | idetape_plug_pipeline(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | if (idetape_pipeline_active(tape)) |
| 2252 | continue; |
| 2253 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2254 | * The machine is short on memory. Fallback to non- |
| 2255 | * pipelined operation mode for this request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2257 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, |
| 2258 | blocks, tape->merge_stage->bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | } |
| 2260 | } |
| 2261 | rq = &new_stage->rq; |
| 2262 | idetape_init_rq(rq, REQ_IDETAPE_WRITE); |
| 2263 | /* Doesn't actually matter - We always assume sequential access */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2264 | rq->sector = tape->first_frame; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2265 | rq->current_nr_sectors = blocks; |
| 2266 | rq->nr_sectors = blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | |
| 2268 | idetape_switch_buffers(tape, new_stage); |
| 2269 | idetape_add_stage_tail(drive, new_stage); |
| 2270 | tape->pipeline_head++; |
Borislav Petkov | 37016ba | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2271 | idetape_calculate_speeds(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
| 2273 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2274 | * Estimate whether the tape has stopped writing by checking if our |
| 2275 | * write pipeline is currently empty. If we are not writing anymore, |
| 2276 | * wait for the pipeline to be almost completely full (90%) before |
| 2277 | * starting to service requests, so that we will be able to keep up with |
| 2278 | * the higher speeds of the tape. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | */ |
| 2280 | if (!idetape_pipeline_active(tape)) { |
| 2281 | if (tape->nr_stages >= tape->max_stages * 9 / 10 || |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2282 | tape->nr_stages >= tape->max_stages - |
| 2283 | tape->uncontrolled_pipeline_head_speed * 3 * 1024 / |
| 2284 | tape->blk_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | tape->measure_insert_time = 1; |
| 2286 | tape->insert_time = jiffies; |
| 2287 | tape->insert_size = 0; |
| 2288 | tape->insert_speed = 0; |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2289 | idetape_plug_pipeline(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | } |
| 2291 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2292 | if (test_and_clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | /* Return a deferred error */ |
| 2294 | return -EIO; |
| 2295 | return blocks; |
| 2296 | } |
| 2297 | |
| 2298 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2299 | * Wait until all pending pipeline requests are serviced. Typically called on |
| 2300 | * device close. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2302 | static void idetape_wait_for_pipeline(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | { |
| 2304 | idetape_tape_t *tape = drive->driver_data; |
| 2305 | unsigned long flags; |
| 2306 | |
| 2307 | while (tape->next_stage || idetape_pipeline_active(tape)) { |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2308 | idetape_plug_pipeline(drive); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2309 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | if (idetape_pipeline_active(tape)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2311 | idetape_wait_for_request(drive, tape->active_data_rq); |
| 2312 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | } |
| 2314 | } |
| 2315 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2316 | static void idetape_empty_write_pipeline(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | { |
| 2318 | idetape_tape_t *tape = drive->driver_data; |
| 2319 | int blocks, min; |
| 2320 | struct idetape_bh *bh; |
Borislav Petkov | 55a5d29 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2321 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2322 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2323 | printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline," |
| 2324 | " but we are not writing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | return; |
| 2326 | } |
| 2327 | if (tape->merge_stage_size > tape->stage_size) { |
| 2328 | printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n"); |
| 2329 | tape->merge_stage_size = tape->stage_size; |
| 2330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | if (tape->merge_stage_size) { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2332 | blocks = tape->merge_stage_size / tape->blk_size; |
| 2333 | if (tape->merge_stage_size % tape->blk_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | unsigned int i; |
| 2335 | |
| 2336 | blocks++; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2337 | i = tape->blk_size - tape->merge_stage_size % |
| 2338 | tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | bh = tape->bh->b_reqnext; |
| 2340 | while (bh) { |
| 2341 | atomic_set(&bh->b_count, 0); |
| 2342 | bh = bh->b_reqnext; |
| 2343 | } |
| 2344 | bh = tape->bh; |
| 2345 | while (i) { |
| 2346 | if (bh == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2347 | printk(KERN_INFO "ide-tape: bug," |
| 2348 | " bh NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | break; |
| 2350 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2351 | min = min(i, (unsigned int)(bh->b_size - |
| 2352 | atomic_read(&bh->b_count))); |
| 2353 | memset(bh->b_data + atomic_read(&bh->b_count), |
| 2354 | 0, min); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | atomic_add(min, &bh->b_count); |
| 2356 | i -= min; |
| 2357 | bh = bh->b_reqnext; |
| 2358 | } |
| 2359 | } |
| 2360 | (void) idetape_add_chrdev_write_request(drive, blocks); |
| 2361 | tape->merge_stage_size = 0; |
| 2362 | } |
| 2363 | idetape_wait_for_pipeline(drive); |
| 2364 | if (tape->merge_stage != NULL) { |
| 2365 | __idetape_kfree_stage(tape->merge_stage); |
| 2366 | tape->merge_stage = NULL; |
| 2367 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2368 | clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags); |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2369 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | |
| 2371 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2372 | * On the next backup, perform the feedback loop again. (I don't want to |
| 2373 | * keep sense information between backups, as some systems are |
| 2374 | * constantly on, and the system load can be totally different on the |
| 2375 | * next backup). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | */ |
| 2377 | tape->max_stages = tape->min_pipeline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | if (tape->first_stage != NULL || |
| 2379 | tape->next_stage != NULL || |
| 2380 | tape->last_stage != NULL || |
| 2381 | tape->nr_stages != 0) { |
| 2382 | printk(KERN_ERR "ide-tape: ide-tape pipeline bug, " |
| 2383 | "first_stage %p, next_stage %p, " |
| 2384 | "last_stage %p, nr_stages %d\n", |
| 2385 | tape->first_stage, tape->next_stage, |
| 2386 | tape->last_stage, tape->nr_stages); |
| 2387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2390 | static void idetape_restart_speed_control(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | { |
| 2392 | idetape_tape_t *tape = drive->driver_data; |
| 2393 | |
| 2394 | tape->restart_speed_control_req = 0; |
| 2395 | tape->pipeline_head = 0; |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2396 | tape->controlled_last_pipeline_head = 0; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2397 | tape->controlled_previous_pipeline_head = 0; |
| 2398 | tape->uncontrolled_previous_pipeline_head = 0; |
| 2399 | tape->controlled_pipeline_head_speed = 5000; |
| 2400 | tape->pipeline_head_speed = 5000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | tape->uncontrolled_pipeline_head_speed = 0; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2402 | tape->controlled_pipeline_head_time = |
| 2403 | tape->uncontrolled_pipeline_head_time = jiffies; |
| 2404 | tape->controlled_previous_head_time = |
| 2405 | tape->uncontrolled_previous_head_time = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2408 | static int idetape_init_read(ide_drive_t *drive, int max_stages) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | { |
| 2410 | idetape_tape_t *tape = drive->driver_data; |
| 2411 | idetape_stage_t *new_stage; |
| 2412 | struct request rq; |
| 2413 | int bytes_read; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2414 | u16 blocks = *(u16 *)&tape->caps[12]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | |
| 2416 | /* Initialize read operation */ |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2417 | if (tape->chrdev_dir != IDETAPE_DIR_READ) { |
| 2418 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | idetape_empty_write_pipeline(drive); |
| 2420 | idetape_flush_tape_buffers(drive); |
| 2421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | if (tape->merge_stage || tape->merge_stage_size) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2423 | printk(KERN_ERR "ide-tape: merge_stage_size should be" |
| 2424 | " 0 now\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | tape->merge_stage_size = 0; |
| 2426 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2427 | tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0); |
| 2428 | if (!tape->merge_stage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | return -ENOMEM; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2430 | tape->chrdev_dir = IDETAPE_DIR_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | |
| 2432 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2433 | * Issue a read 0 command to ensure that DSC handshake is |
| 2434 | * switched from completion mode to buffer available mode. |
| 2435 | * No point in issuing this if DSC overlap isn't supported, some |
| 2436 | * drives (Seagate STT3401A) will return an error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | */ |
| 2438 | if (drive->dsc_overlap) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2439 | bytes_read = idetape_queue_rw_tail(drive, |
| 2440 | REQ_IDETAPE_READ, 0, |
| 2441 | tape->merge_stage->bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | if (bytes_read < 0) { |
| 2443 | __idetape_kfree_stage(tape->merge_stage); |
| 2444 | tape->merge_stage = NULL; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2445 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | return bytes_read; |
| 2447 | } |
| 2448 | } |
| 2449 | } |
| 2450 | if (tape->restart_speed_control_req) |
| 2451 | idetape_restart_speed_control(drive); |
| 2452 | idetape_init_rq(&rq, REQ_IDETAPE_READ); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2453 | rq.sector = tape->first_frame; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2454 | rq.nr_sectors = blocks; |
| 2455 | rq.current_nr_sectors = blocks; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2456 | if (!test_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | tape->nr_stages < max_stages) { |
| 2458 | new_stage = idetape_kmalloc_stage(tape); |
| 2459 | while (new_stage != NULL) { |
| 2460 | new_stage->rq = rq; |
| 2461 | idetape_add_stage_tail(drive, new_stage); |
| 2462 | if (tape->nr_stages >= max_stages) |
| 2463 | break; |
| 2464 | new_stage = idetape_kmalloc_stage(tape); |
| 2465 | } |
| 2466 | } |
| 2467 | if (!idetape_pipeline_active(tape)) { |
| 2468 | if (tape->nr_pending_stages >= 3 * max_stages / 4) { |
| 2469 | tape->measure_insert_time = 1; |
| 2470 | tape->insert_time = jiffies; |
| 2471 | tape->insert_size = 0; |
| 2472 | tape->insert_speed = 0; |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2473 | idetape_plug_pipeline(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | return 0; |
| 2477 | } |
| 2478 | |
| 2479 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2480 | * Called from idetape_chrdev_read() to service a character device read request |
| 2481 | * and add read-ahead requests to our pipeline. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2483 | static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | { |
| 2485 | idetape_tape_t *tape = drive->driver_data; |
| 2486 | unsigned long flags; |
| 2487 | struct request *rq_ptr; |
| 2488 | int bytes_read; |
| 2489 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2490 | debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2492 | /* If we are at a filemark, return a read length of 0 */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2493 | if (test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | return 0; |
| 2495 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2496 | /* Wait for the next block to reach the head of the pipeline. */ |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2497 | idetape_init_read(drive, tape->max_stages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | if (tape->first_stage == NULL) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2499 | if (test_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | return 0; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2501 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, |
| 2502 | tape->merge_stage->bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | } |
| 2504 | idetape_wait_first_stage(drive); |
| 2505 | rq_ptr = &tape->first_stage->rq; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2506 | bytes_read = tape->blk_size * (rq_ptr->nr_sectors - |
| 2507 | rq_ptr->current_nr_sectors); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2508 | rq_ptr->nr_sectors = 0; |
| 2509 | rq_ptr->current_nr_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | |
| 2511 | if (rq_ptr->errors == IDETAPE_ERROR_EOD) |
| 2512 | return 0; |
| 2513 | else { |
| 2514 | idetape_switch_buffers(tape, tape->first_stage); |
| 2515 | if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2516 | set_bit(IDETAPE_FLAG_FILEMARK, &tape->flags); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2517 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | idetape_remove_stage_head(drive); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2519 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | tape->pipeline_head++; |
Borislav Petkov | 37016ba | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2521 | idetape_calculate_speeds(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | } |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2523 | if (bytes_read > blocks * tape->blk_size) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2524 | printk(KERN_ERR "ide-tape: bug: trying to return more bytes" |
| 2525 | " than requested\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2526 | bytes_read = blocks * tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | return (bytes_read); |
| 2529 | } |
| 2530 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2531 | static void idetape_pad_zeros(ide_drive_t *drive, int bcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | { |
| 2533 | idetape_tape_t *tape = drive->driver_data; |
| 2534 | struct idetape_bh *bh; |
| 2535 | int blocks; |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | while (bcount) { |
| 2538 | unsigned int count; |
| 2539 | |
| 2540 | bh = tape->merge_stage->bh; |
| 2541 | count = min(tape->stage_size, bcount); |
| 2542 | bcount -= count; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2543 | blocks = count / tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | while (count) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2545 | atomic_set(&bh->b_count, |
| 2546 | min(count, (unsigned int)bh->b_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | memset(bh->b_data, 0, atomic_read(&bh->b_count)); |
| 2548 | count -= atomic_read(&bh->b_count); |
| 2549 | bh = bh->b_reqnext; |
| 2550 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2551 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, |
| 2552 | tape->merge_stage->bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2556 | static int idetape_pipeline_size(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | { |
| 2558 | idetape_tape_t *tape = drive->driver_data; |
| 2559 | idetape_stage_t *stage; |
| 2560 | struct request *rq; |
| 2561 | int size = 0; |
| 2562 | |
| 2563 | idetape_wait_for_pipeline(drive); |
| 2564 | stage = tape->first_stage; |
| 2565 | while (stage != NULL) { |
| 2566 | rq = &stage->rq; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2567 | size += tape->blk_size * (rq->nr_sectors - |
| 2568 | rq->current_nr_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | if (rq->errors == IDETAPE_ERROR_FILEMARK) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2570 | size += tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | stage = stage->next; |
| 2572 | } |
| 2573 | size += tape->merge_stage_size; |
| 2574 | return size; |
| 2575 | } |
| 2576 | |
| 2577 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2578 | * Rewinds the tape to the Beginning Of the current Partition (BOP). We |
| 2579 | * currently support only one partition. |
| 2580 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2581 | static int idetape_rewind_tape(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | { |
| 2583 | int retval; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2584 | struct ide_atapi_pc pc; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2585 | idetape_tape_t *tape; |
| 2586 | tape = drive->driver_data; |
| 2587 | |
| 2588 | debug_log(DBG_SENSE, "Enter %s\n", __func__); |
| 2589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | idetape_create_rewind_cmd(drive, &pc); |
| 2591 | retval = idetape_queue_pc_tail(drive, &pc); |
| 2592 | if (retval) |
| 2593 | return retval; |
| 2594 | |
| 2595 | idetape_create_read_position_cmd(&pc); |
| 2596 | retval = idetape_queue_pc_tail(drive, &pc); |
| 2597 | if (retval) |
| 2598 | return retval; |
| 2599 | return 0; |
| 2600 | } |
| 2601 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2602 | /* mtio.h compatible commands should be issued to the chrdev interface. */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2603 | static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, |
| 2604 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | { |
| 2606 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | void __user *argp = (void __user *)arg; |
| 2608 | |
Borislav Petkov | d59823f | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 2609 | struct idetape_config { |
| 2610 | int dsc_rw_frequency; |
| 2611 | int dsc_media_access_frequency; |
| 2612 | int nr_stages; |
| 2613 | } config; |
| 2614 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2615 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
| 2616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | switch (cmd) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2618 | case 0x0340: |
| 2619 | if (copy_from_user(&config, argp, sizeof(config))) |
| 2620 | return -EFAULT; |
| 2621 | tape->best_dsc_rw_freq = config.dsc_rw_frequency; |
| 2622 | tape->max_stages = config.nr_stages; |
| 2623 | break; |
| 2624 | case 0x0350: |
| 2625 | config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq; |
| 2626 | config.nr_stages = tape->max_stages; |
| 2627 | if (copy_to_user(argp, &config, sizeof(config))) |
| 2628 | return -EFAULT; |
| 2629 | break; |
| 2630 | default: |
| 2631 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | } |
| 2633 | return 0; |
| 2634 | } |
| 2635 | |
| 2636 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2637 | * The function below is now a bit more complicated than just passing the |
| 2638 | * command to the tape since we may have crossed some filemarks during our |
| 2639 | * pipelined read-ahead mode. As a minor side effect, the pipeline enables us to |
| 2640 | * support MTFSFM when the filemark is in our internal pipeline even if the tape |
| 2641 | * doesn't support spacing over filemarks in the reverse direction. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2643 | static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op, |
| 2644 | int mt_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | { |
| 2646 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2647 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | unsigned long flags; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2649 | int retval, count = 0; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2650 | int sprev = !!(tape->caps[4] & 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | |
| 2652 | if (mt_count == 0) |
| 2653 | return 0; |
| 2654 | if (MTBSF == mt_op || MTBSFM == mt_op) { |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2655 | if (!sprev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | return -EIO; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2657 | mt_count = -mt_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2660 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2661 | /* its a read-ahead buffer, scan it for crossed filemarks. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | tape->merge_stage_size = 0; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2663 | if (test_and_clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | ++count; |
| 2665 | while (tape->first_stage != NULL) { |
| 2666 | if (count == mt_count) { |
| 2667 | if (mt_op == MTFSFM) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2668 | set_bit(IDETAPE_FLAG_FILEMARK, |
| 2669 | &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | return 0; |
| 2671 | } |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2672 | spin_lock_irqsave(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | if (tape->first_stage == tape->active_stage) { |
| 2674 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2675 | * We have reached the active stage in the read |
| 2676 | * pipeline. There is no point in allowing the |
| 2677 | * drive to continue reading any farther, so we |
| 2678 | * stop the pipeline. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2680 | * This section should be moved to a separate |
| 2681 | * subroutine because similar operations are |
| 2682 | * done in __idetape_discard_read_pipeline(), |
| 2683 | * for example. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | */ |
| 2685 | tape->next_stage = NULL; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2686 | spin_unlock_irqrestore(&tape->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | idetape_wait_first_stage(drive); |
| 2688 | tape->next_stage = tape->first_stage->next; |
| 2689 | } else |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2690 | spin_unlock_irqrestore(&tape->lock, flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2691 | if (tape->first_stage->rq.errors == |
| 2692 | IDETAPE_ERROR_FILEMARK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | ++count; |
| 2694 | idetape_remove_stage_head(drive); |
| 2695 | } |
| 2696 | idetape_discard_read_pipeline(drive, 0); |
| 2697 | } |
| 2698 | |
| 2699 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2700 | * The filemark was not found in our internal pipeline; now we can issue |
| 2701 | * the space command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | */ |
| 2703 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2704 | case MTFSF: |
| 2705 | case MTBSF: |
| 2706 | idetape_create_space_cmd(&pc, mt_count - count, |
| 2707 | IDETAPE_SPACE_OVER_FILEMARK); |
| 2708 | return idetape_queue_pc_tail(drive, &pc); |
| 2709 | case MTFSFM: |
| 2710 | case MTBSFM: |
| 2711 | if (!sprev) |
| 2712 | return -EIO; |
| 2713 | retval = idetape_space_over_filemarks(drive, MTFSF, |
| 2714 | mt_count - count); |
| 2715 | if (retval) |
| 2716 | return retval; |
| 2717 | count = (MTBSFM == mt_op ? 1 : -1); |
| 2718 | return idetape_space_over_filemarks(drive, MTFSF, count); |
| 2719 | default: |
| 2720 | printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", |
| 2721 | mt_op); |
| 2722 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | } |
| 2724 | } |
| 2725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2727 | * Our character device read / write functions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2729 | * The tape is optimized to maximize throughput when it is transferring an |
| 2730 | * integral number of the "continuous transfer limit", which is a parameter of |
| 2731 | * the specific tape (26kB on my particular tape, 32kB for Onstream). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2733 | * As of version 1.3 of the driver, the character device provides an abstract |
| 2734 | * continuous view of the media - any mix of block sizes (even 1 byte) on the |
| 2735 | * same backup/restore procedure is supported. The driver will internally |
| 2736 | * convert the requests to the recommended transfer unit, so that an unmatch |
| 2737 | * between the user's block size to the recommended size will only result in a |
| 2738 | * (slightly) increased driver overhead, but will no longer hit performance. |
| 2739 | * This is not applicable to Onstream. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2741 | static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, |
| 2742 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | { |
| 2744 | struct ide_tape_obj *tape = ide_tape_f(file); |
| 2745 | ide_drive_t *drive = tape->drive; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2746 | ssize_t bytes_read, temp, actually_read = 0, rc; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2747 | ssize_t ret = 0; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2748 | u16 ctl = *(u16 *)&tape->caps[12]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2750 | debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2752 | if (tape->chrdev_dir != IDETAPE_DIR_READ) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2753 | if (test_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2754 | if (count > tape->blk_size && |
| 2755 | (count % tape->blk_size) == 0) |
| 2756 | tape->user_bs_factor = count / tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | } |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2758 | rc = idetape_init_read(drive, tape->max_stages); |
| 2759 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | return rc; |
| 2761 | if (count == 0) |
| 2762 | return (0); |
| 2763 | if (tape->merge_stage_size) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2764 | actually_read = min((unsigned int)(tape->merge_stage_size), |
| 2765 | (unsigned int)count); |
| 2766 | if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, |
| 2767 | actually_read)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2768 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | buf += actually_read; |
| 2770 | tape->merge_stage_size -= actually_read; |
| 2771 | count -= actually_read; |
| 2772 | } |
| 2773 | while (count >= tape->stage_size) { |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2774 | bytes_read = idetape_add_chrdev_read_request(drive, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | if (bytes_read <= 0) |
| 2776 | goto finish; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2777 | if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, |
| 2778 | bytes_read)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2779 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | buf += bytes_read; |
| 2781 | count -= bytes_read; |
| 2782 | actually_read += bytes_read; |
| 2783 | } |
| 2784 | if (count) { |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2785 | bytes_read = idetape_add_chrdev_read_request(drive, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | if (bytes_read <= 0) |
| 2787 | goto finish; |
| 2788 | temp = min((unsigned long)count, (unsigned long)bytes_read); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2789 | if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, |
| 2790 | temp)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2791 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | actually_read += temp; |
| 2793 | tape->merge_stage_size = bytes_read-temp; |
| 2794 | } |
| 2795 | finish: |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2796 | if (!actually_read && test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) { |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2797 | debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name); |
| 2798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | idetape_space_over_filemarks(drive, MTFSF, 1); |
| 2800 | return 0; |
| 2801 | } |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2802 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2803 | return ret ? ret : actually_read; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | } |
| 2805 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2806 | static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | size_t count, loff_t *ppos) |
| 2808 | { |
| 2809 | struct ide_tape_obj *tape = ide_tape_f(file); |
| 2810 | ide_drive_t *drive = tape->drive; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2811 | ssize_t actually_written = 0; |
| 2812 | ssize_t ret = 0; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2813 | u16 ctl = *(u16 *)&tape->caps[12]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | |
| 2815 | /* The drive is write protected. */ |
| 2816 | if (tape->write_prot) |
| 2817 | return -EACCES; |
| 2818 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2819 | debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
| 2821 | /* Initialize write operation */ |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2822 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { |
| 2823 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | idetape_discard_read_pipeline(drive, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | if (tape->merge_stage || tape->merge_stage_size) { |
| 2826 | printk(KERN_ERR "ide-tape: merge_stage_size " |
| 2827 | "should be 0 now\n"); |
| 2828 | tape->merge_stage_size = 0; |
| 2829 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2830 | tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0); |
| 2831 | if (!tape->merge_stage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | return -ENOMEM; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2833 | tape->chrdev_dir = IDETAPE_DIR_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | idetape_init_merge_stage(tape); |
| 2835 | |
| 2836 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2837 | * Issue a write 0 command to ensure that DSC handshake is |
| 2838 | * switched from completion mode to buffer available mode. No |
| 2839 | * point in issuing this if DSC overlap isn't supported, some |
| 2840 | * drives (Seagate STT3401A) will return an error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | */ |
| 2842 | if (drive->dsc_overlap) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2843 | ssize_t retval = idetape_queue_rw_tail(drive, |
| 2844 | REQ_IDETAPE_WRITE, 0, |
| 2845 | tape->merge_stage->bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | if (retval < 0) { |
| 2847 | __idetape_kfree_stage(tape->merge_stage); |
| 2848 | tape->merge_stage = NULL; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 2849 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | return retval; |
| 2851 | } |
| 2852 | } |
| 2853 | } |
| 2854 | if (count == 0) |
| 2855 | return (0); |
| 2856 | if (tape->restart_speed_control_req) |
| 2857 | idetape_restart_speed_control(drive); |
| 2858 | if (tape->merge_stage_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | if (tape->merge_stage_size >= tape->stage_size) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2860 | printk(KERN_ERR "ide-tape: bug: merge buf too big\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | tape->merge_stage_size = 0; |
| 2862 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2863 | actually_written = min((unsigned int) |
| 2864 | (tape->stage_size - tape->merge_stage_size), |
| 2865 | (unsigned int)count); |
| 2866 | if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, |
| 2867 | actually_written)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2868 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | buf += actually_written; |
| 2870 | tape->merge_stage_size += actually_written; |
| 2871 | count -= actually_written; |
| 2872 | |
| 2873 | if (tape->merge_stage_size == tape->stage_size) { |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2874 | ssize_t retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | tape->merge_stage_size = 0; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2876 | retval = idetape_add_chrdev_write_request(drive, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | if (retval <= 0) |
| 2878 | return (retval); |
| 2879 | } |
| 2880 | } |
| 2881 | while (count >= tape->stage_size) { |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2882 | ssize_t retval; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2883 | if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, |
| 2884 | tape->stage_size)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2885 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | buf += tape->stage_size; |
| 2887 | count -= tape->stage_size; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 2888 | retval = idetape_add_chrdev_write_request(drive, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | actually_written += tape->stage_size; |
| 2890 | if (retval <= 0) |
| 2891 | return (retval); |
| 2892 | } |
| 2893 | if (count) { |
| 2894 | actually_written += count; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2895 | if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, |
| 2896 | count)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 2897 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | tape->merge_stage_size += count; |
| 2899 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2900 | return ret ? ret : actually_written; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2903 | static int idetape_write_filemark(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | { |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2905 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | |
| 2907 | /* Write a filemark */ |
| 2908 | idetape_create_write_filemark_cmd(drive, &pc, 1); |
| 2909 | if (idetape_queue_pc_tail(drive, &pc)) { |
| 2910 | printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); |
| 2911 | return -EIO; |
| 2912 | } |
| 2913 | return 0; |
| 2914 | } |
| 2915 | |
| 2916 | /* |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 2917 | * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is |
| 2918 | * requested. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 2920 | * Note: MTBSF and MTBSFM are not supported when the tape doesn't support |
| 2921 | * spacing over filemarks in the reverse direction. In this case, MTFSFM is also |
| 2922 | * usually not supported (it is supported in the rare case in which we crossed |
| 2923 | * the filemark during our read-ahead pipelined operation mode). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 2925 | * The following commands are currently not supported: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 2927 | * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS, |
| 2928 | * MT_ST_WRITE_THRESHOLD. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | */ |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 2930 | static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | { |
| 2932 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 2933 | struct ide_atapi_pc pc; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2934 | int i, retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 2936 | debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n", |
| 2937 | mt_op, mt_count); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2938 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 2939 | /* Commands which need our pipelined read-ahead stages. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2941 | case MTFSF: |
| 2942 | case MTFSFM: |
| 2943 | case MTBSF: |
| 2944 | case MTBSFM: |
| 2945 | if (!mt_count) |
| 2946 | return 0; |
| 2947 | return idetape_space_over_filemarks(drive, mt_op, mt_count); |
| 2948 | default: |
| 2949 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2953 | case MTWEOF: |
| 2954 | if (tape->write_prot) |
| 2955 | return -EACCES; |
| 2956 | idetape_discard_read_pipeline(drive, 1); |
| 2957 | for (i = 0; i < mt_count; i++) { |
| 2958 | retval = idetape_write_filemark(drive); |
| 2959 | if (retval) |
| 2960 | return retval; |
| 2961 | } |
| 2962 | return 0; |
| 2963 | case MTREW: |
| 2964 | idetape_discard_read_pipeline(drive, 0); |
| 2965 | if (idetape_rewind_tape(drive)) |
| 2966 | return -EIO; |
| 2967 | return 0; |
| 2968 | case MTLOAD: |
| 2969 | idetape_discard_read_pipeline(drive, 0); |
| 2970 | idetape_create_load_unload_cmd(drive, &pc, |
| 2971 | IDETAPE_LU_LOAD_MASK); |
| 2972 | return idetape_queue_pc_tail(drive, &pc); |
| 2973 | case MTUNLOAD: |
| 2974 | case MTOFFL: |
| 2975 | /* |
| 2976 | * If door is locked, attempt to unlock before |
| 2977 | * attempting to eject. |
| 2978 | */ |
| 2979 | if (tape->door_locked) { |
| 2980 | if (idetape_create_prevent_cmd(drive, &pc, 0)) |
| 2981 | if (!idetape_queue_pc_tail(drive, &pc)) |
| 2982 | tape->door_locked = DOOR_UNLOCKED; |
| 2983 | } |
| 2984 | idetape_discard_read_pipeline(drive, 0); |
| 2985 | idetape_create_load_unload_cmd(drive, &pc, |
| 2986 | !IDETAPE_LU_LOAD_MASK); |
| 2987 | retval = idetape_queue_pc_tail(drive, &pc); |
| 2988 | if (!retval) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 2989 | clear_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2990 | return retval; |
| 2991 | case MTNOP: |
| 2992 | idetape_discard_read_pipeline(drive, 0); |
| 2993 | return idetape_flush_tape_buffers(drive); |
| 2994 | case MTRETEN: |
| 2995 | idetape_discard_read_pipeline(drive, 0); |
| 2996 | idetape_create_load_unload_cmd(drive, &pc, |
| 2997 | IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); |
| 2998 | return idetape_queue_pc_tail(drive, &pc); |
| 2999 | case MTEOM: |
| 3000 | idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD); |
| 3001 | return idetape_queue_pc_tail(drive, &pc); |
| 3002 | case MTERASE: |
| 3003 | (void)idetape_rewind_tape(drive); |
| 3004 | idetape_create_erase_cmd(&pc); |
| 3005 | return idetape_queue_pc_tail(drive, &pc); |
| 3006 | case MTSETBLK: |
| 3007 | if (mt_count) { |
| 3008 | if (mt_count < tape->blk_size || |
| 3009 | mt_count % tape->blk_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | return -EIO; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3011 | tape->user_bs_factor = mt_count / tape->blk_size; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3012 | clear_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3013 | } else |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3014 | set_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3015 | return 0; |
| 3016 | case MTSEEK: |
| 3017 | idetape_discard_read_pipeline(drive, 0); |
| 3018 | return idetape_position_tape(drive, |
| 3019 | mt_count * tape->user_bs_factor, tape->partition, 0); |
| 3020 | case MTSETPART: |
| 3021 | idetape_discard_read_pipeline(drive, 0); |
| 3022 | return idetape_position_tape(drive, 0, mt_count, 0); |
| 3023 | case MTFSR: |
| 3024 | case MTBSR: |
| 3025 | case MTLOCK: |
| 3026 | if (!idetape_create_prevent_cmd(drive, &pc, 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | return 0; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3028 | retval = idetape_queue_pc_tail(drive, &pc); |
| 3029 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | return retval; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3031 | tape->door_locked = DOOR_EXPLICITLY_LOCKED; |
| 3032 | return 0; |
| 3033 | case MTUNLOCK: |
| 3034 | if (!idetape_create_prevent_cmd(drive, &pc, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | return 0; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3036 | retval = idetape_queue_pc_tail(drive, &pc); |
| 3037 | if (retval) |
| 3038 | return retval; |
| 3039 | tape->door_locked = DOOR_UNLOCKED; |
| 3040 | return 0; |
| 3041 | default: |
| 3042 | printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", |
| 3043 | mt_op); |
| 3044 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | /* |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 3049 | * Our character device ioctls. General mtio.h magnetic io commands are |
| 3050 | * supported here, and not in the corresponding block interface. Our own |
| 3051 | * ide-tape ioctls are supported on both interfaces. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | */ |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 3053 | static int idetape_chrdev_ioctl(struct inode *inode, struct file *file, |
| 3054 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | { |
| 3056 | struct ide_tape_obj *tape = ide_tape_f(file); |
| 3057 | ide_drive_t *drive = tape->drive; |
| 3058 | struct mtop mtop; |
| 3059 | struct mtget mtget; |
| 3060 | struct mtpos mtpos; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3061 | int block_offset = 0, position = tape->first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | void __user *argp = (void __user *)arg; |
| 3063 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 3064 | debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | |
| 3066 | tape->restart_speed_control_req = 1; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3067 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | idetape_empty_write_pipeline(drive); |
| 3069 | idetape_flush_tape_buffers(drive); |
| 3070 | } |
| 3071 | if (cmd == MTIOCGET || cmd == MTIOCPOS) { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3072 | block_offset = idetape_pipeline_size(drive) / |
| 3073 | (tape->blk_size * tape->user_bs_factor); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3074 | position = idetape_read_position(drive); |
| 3075 | if (position < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | return -EIO; |
| 3077 | } |
| 3078 | switch (cmd) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3079 | case MTIOCTOP: |
| 3080 | if (copy_from_user(&mtop, argp, sizeof(struct mtop))) |
| 3081 | return -EFAULT; |
| 3082 | return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count); |
| 3083 | case MTIOCGET: |
| 3084 | memset(&mtget, 0, sizeof(struct mtget)); |
| 3085 | mtget.mt_type = MT_ISSCSI2; |
| 3086 | mtget.mt_blkno = position / tape->user_bs_factor - block_offset; |
| 3087 | mtget.mt_dsreg = |
| 3088 | ((tape->blk_size * tape->user_bs_factor) |
| 3089 | << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3090 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3091 | if (tape->drv_write_prot) |
| 3092 | mtget.mt_gstat |= GMT_WR_PROT(0xffffffff); |
| 3093 | |
| 3094 | if (copy_to_user(argp, &mtget, sizeof(struct mtget))) |
| 3095 | return -EFAULT; |
| 3096 | return 0; |
| 3097 | case MTIOCPOS: |
| 3098 | mtpos.mt_blkno = position / tape->user_bs_factor - block_offset; |
| 3099 | if (copy_to_user(argp, &mtpos, sizeof(struct mtpos))) |
| 3100 | return -EFAULT; |
| 3101 | return 0; |
| 3102 | default: |
| 3103 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
| 3104 | idetape_discard_read_pipeline(drive, 1); |
| 3105 | return idetape_blkdev_ioctl(drive, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | } |
| 3107 | } |
| 3108 | |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 3109 | /* |
| 3110 | * Do a mode sense page 0 with block descriptor and if it succeeds set the tape |
| 3111 | * block size with the reported value. |
| 3112 | */ |
| 3113 | static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive) |
| 3114 | { |
| 3115 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3116 | struct ide_atapi_pc pc; |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 3117 | |
| 3118 | idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); |
| 3119 | if (idetape_queue_pc_tail(drive, &pc)) { |
| 3120 | printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3121 | if (tape->blk_size == 0) { |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 3122 | printk(KERN_WARNING "ide-tape: Cannot deal with zero " |
| 3123 | "block size, assuming 32k\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3124 | tape->blk_size = 32768; |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 3125 | } |
| 3126 | return; |
| 3127 | } |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3128 | tape->blk_size = (pc.buf[4 + 5] << 16) + |
| 3129 | (pc.buf[4 + 6] << 8) + |
| 3130 | pc.buf[4 + 7]; |
| 3131 | tape->drv_write_prot = (pc.buf[2] & 0x80) >> 7; |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 3132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3134 | static int idetape_chrdev_open(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | { |
| 3136 | unsigned int minor = iminor(inode), i = minor & ~0xc0; |
| 3137 | ide_drive_t *drive; |
| 3138 | idetape_tape_t *tape; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3139 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | int retval; |
| 3141 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 3142 | if (i >= MAX_HWIFS * MAX_DRIVES) |
| 3143 | return -ENXIO; |
| 3144 | |
| 3145 | tape = ide_tape_chrdev_get(i); |
| 3146 | if (!tape) |
| 3147 | return -ENXIO; |
| 3148 | |
| 3149 | debug_log(DBG_CHRDEV, "Enter %s\n", __func__); |
| 3150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | /* |
| 3152 | * We really want to do nonseekable_open(inode, filp); here, but some |
| 3153 | * versions of tar incorrectly call lseek on tapes and bail out if that |
| 3154 | * fails. So we disallow pread() and pwrite(), but permit lseeks. |
| 3155 | */ |
| 3156 | filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); |
| 3157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | drive = tape->drive; |
| 3159 | |
| 3160 | filp->private_data = tape; |
| 3161 | |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3162 | if (test_and_set_bit(IDETAPE_FLAG_BUSY, &tape->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | retval = -EBUSY; |
| 3164 | goto out_put_tape; |
| 3165 | } |
| 3166 | |
| 3167 | retval = idetape_wait_ready(drive, 60 * HZ); |
| 3168 | if (retval) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3169 | clear_bit(IDETAPE_FLAG_BUSY, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name); |
| 3171 | goto out_put_tape; |
| 3172 | } |
| 3173 | |
| 3174 | idetape_read_position(drive); |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3175 | if (!test_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | (void)idetape_rewind_tape(drive); |
| 3177 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3178 | if (tape->chrdev_dir != IDETAPE_DIR_READ) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3179 | clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | |
| 3181 | /* Read block size and write protect status from drive. */ |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 3182 | ide_tape_get_bsize_from_bdesc(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | |
| 3184 | /* Set write protect flag if device is opened as read-only. */ |
| 3185 | if ((filp->f_flags & O_ACCMODE) == O_RDONLY) |
| 3186 | tape->write_prot = 1; |
| 3187 | else |
| 3188 | tape->write_prot = tape->drv_write_prot; |
| 3189 | |
| 3190 | /* Make sure drive isn't write protected if user wants to write. */ |
| 3191 | if (tape->write_prot) { |
| 3192 | if ((filp->f_flags & O_ACCMODE) == O_WRONLY || |
| 3193 | (filp->f_flags & O_ACCMODE) == O_RDWR) { |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3194 | clear_bit(IDETAPE_FLAG_BUSY, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | retval = -EROFS; |
| 3196 | goto out_put_tape; |
| 3197 | } |
| 3198 | } |
| 3199 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3200 | /* Lock the tape drive door so user can't eject. */ |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3201 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | if (idetape_create_prevent_cmd(drive, &pc, 1)) { |
| 3203 | if (!idetape_queue_pc_tail(drive, &pc)) { |
| 3204 | if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) |
| 3205 | tape->door_locked = DOOR_LOCKED; |
| 3206 | } |
| 3207 | } |
| 3208 | } |
| 3209 | idetape_restart_speed_control(drive); |
| 3210 | tape->restart_speed_control_req = 0; |
| 3211 | return 0; |
| 3212 | |
| 3213 | out_put_tape: |
| 3214 | ide_tape_put(tape); |
| 3215 | return retval; |
| 3216 | } |
| 3217 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3218 | static void idetape_write_release(ide_drive_t *drive, unsigned int minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | { |
| 3220 | idetape_tape_t *tape = drive->driver_data; |
| 3221 | |
| 3222 | idetape_empty_write_pipeline(drive); |
| 3223 | tape->merge_stage = __idetape_kmalloc_stage(tape, 1, 0); |
| 3224 | if (tape->merge_stage != NULL) { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3225 | idetape_pad_zeros(drive, tape->blk_size * |
| 3226 | (tape->user_bs_factor - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | __idetape_kfree_stage(tape->merge_stage); |
| 3228 | tape->merge_stage = NULL; |
| 3229 | } |
| 3230 | idetape_write_filemark(drive); |
| 3231 | idetape_flush_tape_buffers(drive); |
| 3232 | idetape_flush_tape_buffers(drive); |
| 3233 | } |
| 3234 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3235 | static int idetape_chrdev_release(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | { |
| 3237 | struct ide_tape_obj *tape = ide_tape_f(filp); |
| 3238 | ide_drive_t *drive = tape->drive; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3239 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | unsigned int minor = iminor(inode); |
| 3241 | |
| 3242 | lock_kernel(); |
| 3243 | tape = drive->driver_data; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 3244 | |
| 3245 | debug_log(DBG_CHRDEV, "Enter %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3247 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | idetape_write_release(drive, minor); |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3249 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | if (minor < 128) |
| 3251 | idetape_discard_read_pipeline(drive, 1); |
| 3252 | else |
| 3253 | idetape_wait_for_pipeline(drive); |
| 3254 | } |
| 3255 | if (tape->cache_stage != NULL) { |
| 3256 | __idetape_kfree_stage(tape->cache_stage); |
| 3257 | tape->cache_stage = NULL; |
| 3258 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3259 | if (minor < 128 && test_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | (void) idetape_rewind_tape(drive); |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3261 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | if (tape->door_locked == DOOR_LOCKED) { |
| 3263 | if (idetape_create_prevent_cmd(drive, &pc, 0)) { |
| 3264 | if (!idetape_queue_pc_tail(drive, &pc)) |
| 3265 | tape->door_locked = DOOR_UNLOCKED; |
| 3266 | } |
| 3267 | } |
| 3268 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3269 | clear_bit(IDETAPE_FLAG_BUSY, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | ide_tape_put(tape); |
| 3271 | unlock_kernel(); |
| 3272 | return 0; |
| 3273 | } |
| 3274 | |
| 3275 | /* |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3276 | * check the contents of the ATAPI IDENTIFY command results. We return: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | * |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3278 | * 1 - If the tape can be supported by us, based on the information we have so |
| 3279 | * far. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | * |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3281 | * 0 - If this tape driver is not currently supported by us. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | */ |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3283 | static int idetape_identify_device(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | { |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3285 | u8 gcw[2], protocol, device_type, removable, packet_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | |
| 3287 | if (drive->id_read == 0) |
| 3288 | return 1; |
| 3289 | |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3290 | *((unsigned short *) &gcw) = drive->id->config; |
| 3291 | |
| 3292 | protocol = (gcw[1] & 0xC0) >> 6; |
| 3293 | device_type = gcw[1] & 0x1F; |
| 3294 | removable = !!(gcw[0] & 0x80); |
| 3295 | packet_size = gcw[0] & 0x3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | /* Check that we can support this device */ |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3298 | if (protocol != 2) |
Bartlomiej Zolnierkiewicz | 16422de3 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 3299 | printk(KERN_ERR "ide-tape: Protocol (0x%02x) is not ATAPI\n", |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3300 | protocol); |
| 3301 | else if (device_type != 1) |
Bartlomiej Zolnierkiewicz | 16422de3 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 3302 | printk(KERN_ERR "ide-tape: Device type (0x%02x) is not set " |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3303 | "to tape\n", device_type); |
| 3304 | else if (!removable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | printk(KERN_ERR "ide-tape: The removable flag is not set\n"); |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3306 | else if (packet_size != 0) { |
Borislav Petkov | 24d57f8 | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3307 | printk(KERN_ERR "ide-tape: Packet size (0x%02x) is not 12" |
| 3308 | " bytes\n", packet_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | } else |
| 3310 | return 1; |
| 3311 | return 0; |
| 3312 | } |
| 3313 | |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3314 | static void idetape_get_inquiry_results(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3317 | struct ide_atapi_pc pc; |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3318 | char fw_rev[6], vendor_id[10], product_id[18]; |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | idetape_create_inquiry_cmd(&pc); |
| 3321 | if (idetape_queue_pc_tail(drive, &pc)) { |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3322 | printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", |
| 3323 | tape->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | return; |
| 3325 | } |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3326 | memcpy(vendor_id, &pc.buf[8], 8); |
| 3327 | memcpy(product_id, &pc.buf[16], 16); |
| 3328 | memcpy(fw_rev, &pc.buf[32], 4); |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3329 | |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3330 | ide_fixstring(vendor_id, 10, 0); |
| 3331 | ide_fixstring(product_id, 18, 0); |
| 3332 | ide_fixstring(fw_rev, 6, 0); |
| 3333 | |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3334 | printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n", |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3335 | drive->name, tape->name, vendor_id, product_id, fw_rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | /* |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3339 | * Ask the tape about its various parameters. In particular, we will adjust our |
| 3340 | * data transfer buffer size to the recommended value as returned by the tape. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3342 | static void idetape_get_mode_sense_results(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | { |
| 3344 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3345 | struct ide_atapi_pc pc; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3346 | u8 *caps; |
| 3347 | u8 speed, max_speed; |
Borislav Petkov | 47314fa | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 3348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); |
| 3350 | if (idetape_queue_pc_tail(drive, &pc)) { |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3351 | printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" |
| 3352 | " some default values\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3353 | tape->blk_size = 512; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3354 | put_unaligned(52, (u16 *)&tape->caps[12]); |
| 3355 | put_unaligned(540, (u16 *)&tape->caps[14]); |
| 3356 | put_unaligned(6*52, (u16 *)&tape->caps[16]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | return; |
| 3358 | } |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 3359 | caps = pc.buf + 4 + pc.buf[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3361 | /* convert to host order and save for later use */ |
| 3362 | speed = be16_to_cpu(*(u16 *)&caps[14]); |
| 3363 | max_speed = be16_to_cpu(*(u16 *)&caps[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3365 | put_unaligned(max_speed, (u16 *)&caps[8]); |
| 3366 | put_unaligned(be16_to_cpu(*(u16 *)&caps[12]), (u16 *)&caps[12]); |
| 3367 | put_unaligned(speed, (u16 *)&caps[14]); |
| 3368 | put_unaligned(be16_to_cpu(*(u16 *)&caps[16]), (u16 *)&caps[16]); |
| 3369 | |
| 3370 | if (!speed) { |
| 3371 | printk(KERN_INFO "ide-tape: %s: invalid tape speed " |
| 3372 | "(assuming 650KB/sec)\n", drive->name); |
| 3373 | put_unaligned(650, (u16 *)&caps[14]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | } |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3375 | if (!max_speed) { |
| 3376 | printk(KERN_INFO "ide-tape: %s: invalid max_speed " |
| 3377 | "(assuming 650KB/sec)\n", drive->name); |
| 3378 | put_unaligned(650, (u16 *)&caps[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3381 | memcpy(&tape->caps, caps, 20); |
| 3382 | if (caps[7] & 0x02) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3383 | tape->blk_size = 512; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3384 | else if (caps[7] & 0x04) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3385 | tape->blk_size = 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | } |
| 3387 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 3388 | #ifdef CONFIG_IDE_PROC_FS |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3389 | static void idetape_add_settings(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | { |
| 3391 | idetape_tape_t *tape = drive->driver_data; |
| 3392 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3393 | ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, |
| 3394 | 1, 2, (u16 *)&tape->caps[16], NULL); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3395 | ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, |
| 3396 | tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); |
| 3397 | ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff, |
| 3398 | tape->stage_size / 1024, 1, &tape->max_stages, NULL); |
| 3399 | ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff, |
| 3400 | tape->stage_size / 1024, 1, &tape->max_pipeline, NULL); |
| 3401 | ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0, |
| 3402 | 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, |
| 3403 | NULL); |
| 3404 | ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0, |
| 3405 | 0xffff, tape->stage_size / 1024, 1, |
| 3406 | &tape->nr_pending_stages, NULL); |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3407 | ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, |
| 3408 | 1, 1, (u16 *)&tape->caps[14], NULL); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3409 | ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, |
| 3410 | 1024, &tape->stage_size, NULL); |
| 3411 | ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, |
| 3412 | IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_freq, |
| 3413 | NULL); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3414 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, |
| 3415 | 1, &drive->dsc_overlap, NULL); |
| 3416 | ide_add_setting(drive, "pipeline_head_speed_c", SETTING_READ, TYPE_INT, |
| 3417 | 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed, |
| 3418 | NULL); |
| 3419 | ide_add_setting(drive, "pipeline_head_speed_u", SETTING_READ, TYPE_INT, |
| 3420 | 0, 0xffff, 1, 1, |
| 3421 | &tape->uncontrolled_pipeline_head_speed, NULL); |
| 3422 | ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, |
| 3423 | 1, 1, &tape->avg_speed, NULL); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 3424 | ide_add_setting(drive, "debug_mask", SETTING_RW, TYPE_INT, 0, 0xffff, 1, |
| 3425 | 1, &tape->debug_mask, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | } |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 3427 | #else |
| 3428 | static inline void idetape_add_settings(ide_drive_t *drive) { ; } |
| 3429 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | |
| 3431 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3432 | * The function below is called to: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3434 | * 1. Initialize our various state variables. |
| 3435 | * 2. Ask the tape for its capabilities. |
| 3436 | * 3. Allocate a buffer which will be used for data transfer. The buffer size |
| 3437 | * is chosen based on the recommendation which we received in step 2. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3439 | * Note that at this point ide.c already assigned us an irq, so that we can |
| 3440 | * queue requests here and wait for their completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3442 | static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | { |
| 3444 | unsigned long t1, tmid, tn, t; |
| 3445 | int speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | int stage_size; |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3447 | u8 gcw[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | struct sysinfo si; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3449 | u16 *ctl = (u16 *)&tape->caps[12]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3451 | spin_lock_init(&tape->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | drive->dsc_overlap = 1; |
Bartlomiej Zolnierkiewicz | 4166c19 | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 3453 | if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { |
| 3454 | printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", |
| 3455 | tape->name); |
| 3456 | drive->dsc_overlap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | /* Seagate Travan drives do not support DSC overlap. */ |
| 3459 | if (strstr(drive->id->model, "Seagate STT3401")) |
| 3460 | drive->dsc_overlap = 0; |
| 3461 | tape->minor = minor; |
| 3462 | tape->name[0] = 'h'; |
| 3463 | tape->name[1] = 't'; |
| 3464 | tape->name[2] = '0' + minor; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3465 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | tape->pc = tape->pc_stack; |
| 3467 | tape->max_insert_speed = 10000; |
| 3468 | tape->speed_control = 1; |
| 3469 | *((unsigned short *) &gcw) = drive->id->config; |
Borislav Petkov | 71071b8 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3470 | |
| 3471 | /* Command packet DRQ type */ |
| 3472 | if (((gcw[0] & 0x60) >> 5) == 1) |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 3473 | set_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3475 | tape->min_pipeline = 10; |
| 3476 | tape->max_pipeline = 10; |
| 3477 | tape->max_stages = 10; |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | idetape_get_inquiry_results(drive); |
| 3480 | idetape_get_mode_sense_results(drive); |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 3481 | ide_tape_get_bsize_from_bdesc(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | tape->user_bs_factor = 1; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3483 | tape->stage_size = *ctl * tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | while (tape->stage_size > 0xffff) { |
| 3485 | printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3486 | *ctl /= 2; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3487 | tape->stage_size = *ctl * tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | } |
| 3489 | stage_size = tape->stage_size; |
| 3490 | tape->pages_per_stage = stage_size / PAGE_SIZE; |
| 3491 | if (stage_size % PAGE_SIZE) { |
| 3492 | tape->pages_per_stage++; |
| 3493 | tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE; |
| 3494 | } |
| 3495 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3496 | /* Select the "best" DSC read/write polling freq and pipeline size. */ |
| 3497 | speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | |
| 3499 | tape->max_stages = speed * 1000 * 10 / tape->stage_size; |
| 3500 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3501 | /* Limit memory use for pipeline to 10% of physical memory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | si_meminfo(&si); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3503 | if (tape->max_stages * tape->stage_size > |
| 3504 | si.totalram * si.mem_unit / 10) |
| 3505 | tape->max_stages = |
| 3506 | si.totalram * si.mem_unit / (10 * tape->stage_size); |
| 3507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | tape->max_stages = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES); |
| 3509 | tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3510 | tape->max_pipeline = |
| 3511 | min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES); |
| 3512 | if (tape->max_stages == 0) { |
| 3513 | tape->max_stages = 1; |
| 3514 | tape->min_pipeline = 1; |
| 3515 | tape->max_pipeline = 1; |
| 3516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | |
| 3518 | t1 = (tape->stage_size * HZ) / (speed * 1000); |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3519 | tmid = (*(u16 *)&tape->caps[16] * 32 * HZ) / (speed * 125); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000); |
| 3521 | |
| 3522 | if (tape->max_stages) |
| 3523 | t = tn; |
| 3524 | else |
| 3525 | t = t1; |
| 3526 | |
| 3527 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3528 | * Ensure that the number we got makes sense; limit it within |
| 3529 | * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3531 | tape->best_dsc_rw_freq = max_t(unsigned long, |
| 3532 | min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), |
| 3533 | IDETAPE_DSC_RW_MIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " |
| 3535 | "%dkB pipeline, %lums tDSC%s\n", |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 3536 | drive->name, tape->name, *(u16 *)&tape->caps[14], |
| 3537 | (*(u16 *)&tape->caps[16] * 512) / tape->stage_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | tape->stage_size / 1024, |
| 3539 | tape->max_stages * tape->stage_size / 1024, |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 3540 | tape->best_dsc_rw_freq * 1000 / HZ, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | drive->using_dma ? ", DMA":""); |
| 3542 | |
| 3543 | idetape_add_settings(drive); |
| 3544 | } |
| 3545 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 3546 | static void ide_tape_remove(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | { |
| 3548 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 3550 | ide_proc_unregister_driver(drive, tape->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | |
| 3552 | ide_unregister_region(tape->disk); |
| 3553 | |
| 3554 | ide_tape_put(tape); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
| 3557 | static void ide_tape_release(struct kref *kref) |
| 3558 | { |
| 3559 | struct ide_tape_obj *tape = to_ide_tape(kref); |
| 3560 | ide_drive_t *drive = tape->drive; |
| 3561 | struct gendisk *g = tape->disk; |
| 3562 | |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 3563 | BUG_ON(tape->first_stage != NULL || tape->merge_stage_size); |
| 3564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | drive->dsc_overlap = 0; |
| 3566 | drive->driver_data = NULL; |
Tony Jones | dbc1272 | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 3567 | device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3568 | device_destroy(idetape_sysfs_class, |
| 3569 | MKDEV(IDETAPE_MAJOR, tape->minor + 128)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | idetape_devs[tape->minor] = NULL; |
| 3571 | g->private_data = NULL; |
| 3572 | put_disk(g); |
| 3573 | kfree(tape); |
| 3574 | } |
| 3575 | |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 3576 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | static int proc_idetape_read_name |
| 3578 | (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 3579 | { |
| 3580 | ide_drive_t *drive = (ide_drive_t *) data; |
| 3581 | idetape_tape_t *tape = drive->driver_data; |
| 3582 | char *out = page; |
| 3583 | int len; |
| 3584 | |
| 3585 | len = sprintf(out, "%s\n", tape->name); |
| 3586 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
| 3587 | } |
| 3588 | |
| 3589 | static ide_proc_entry_t idetape_proc[] = { |
| 3590 | { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL }, |
| 3591 | { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL }, |
| 3592 | { NULL, 0, NULL, NULL } |
| 3593 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | #endif |
| 3595 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 3596 | static int ide_tape_probe(ide_drive_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | static ide_driver_t idetape_driver = { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 3599 | .gen_driver = { |
Laurent Riffard | 4ef3b8f | 2005-11-18 22:15:40 +0100 | [diff] [blame] | 3600 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 3601 | .name = "ide-tape", |
| 3602 | .bus = &ide_bus_type, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 3603 | }, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 3604 | .probe = ide_tape_probe, |
| 3605 | .remove = ide_tape_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | .version = IDETAPE_VERSION, |
| 3607 | .media = ide_tape, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | .supports_dsc_overlap = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | .do_request = idetape_do_request, |
| 3610 | .end_request = idetape_end_request, |
| 3611 | .error = __ide_error, |
| 3612 | .abort = __ide_abort, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 3613 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | .proc = idetape_proc, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 3615 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | }; |
| 3617 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 3618 | /* Our character device supporting functions, passed to register_chrdev. */ |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 3619 | static const struct file_operations idetape_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | .owner = THIS_MODULE, |
| 3621 | .read = idetape_chrdev_read, |
| 3622 | .write = idetape_chrdev_write, |
| 3623 | .ioctl = idetape_chrdev_ioctl, |
| 3624 | .open = idetape_chrdev_open, |
| 3625 | .release = idetape_chrdev_release, |
| 3626 | }; |
| 3627 | |
| 3628 | static int idetape_open(struct inode *inode, struct file *filp) |
| 3629 | { |
| 3630 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 3631 | struct ide_tape_obj *tape; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3633 | tape = ide_tape_get(disk); |
| 3634 | if (!tape) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | return -ENXIO; |
| 3636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | return 0; |
| 3638 | } |
| 3639 | |
| 3640 | static int idetape_release(struct inode *inode, struct file *filp) |
| 3641 | { |
| 3642 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 3643 | struct ide_tape_obj *tape = ide_tape_g(disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | |
| 3645 | ide_tape_put(tape); |
| 3646 | |
| 3647 | return 0; |
| 3648 | } |
| 3649 | |
| 3650 | static int idetape_ioctl(struct inode *inode, struct file *file, |
| 3651 | unsigned int cmd, unsigned long arg) |
| 3652 | { |
| 3653 | struct block_device *bdev = inode->i_bdev; |
| 3654 | struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk); |
| 3655 | ide_drive_t *drive = tape->drive; |
| 3656 | int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); |
| 3657 | if (err == -EINVAL) |
| 3658 | err = idetape_blkdev_ioctl(drive, cmd, arg); |
| 3659 | return err; |
| 3660 | } |
| 3661 | |
| 3662 | static struct block_device_operations idetape_block_ops = { |
| 3663 | .owner = THIS_MODULE, |
| 3664 | .open = idetape_open, |
| 3665 | .release = idetape_release, |
| 3666 | .ioctl = idetape_ioctl, |
| 3667 | }; |
| 3668 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 3669 | static int ide_tape_probe(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | { |
| 3671 | idetape_tape_t *tape; |
| 3672 | struct gendisk *g; |
| 3673 | int minor; |
| 3674 | |
| 3675 | if (!strstr("ide-tape", drive->driver_req)) |
| 3676 | goto failed; |
| 3677 | if (!drive->present) |
| 3678 | goto failed; |
| 3679 | if (drive->media != ide_tape) |
| 3680 | goto failed; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3681 | if (!idetape_identify_device(drive)) { |
| 3682 | printk(KERN_ERR "ide-tape: %s: not supported by this version of" |
| 3683 | " the driver\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | goto failed; |
| 3685 | } |
| 3686 | if (drive->scsi) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3687 | printk(KERN_INFO "ide-tape: passing drive %s to ide-scsi" |
| 3688 | " emulation.\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | goto failed; |
| 3690 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3691 | tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | if (tape == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3693 | printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n", |
| 3694 | drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | goto failed; |
| 3696 | } |
| 3697 | |
| 3698 | g = alloc_disk(1 << PARTN_BITS); |
| 3699 | if (!g) |
| 3700 | goto out_free_tape; |
| 3701 | |
| 3702 | ide_init_disk(g, drive); |
| 3703 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 3704 | ide_proc_register_driver(drive, &idetape_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | kref_init(&tape->kref); |
| 3707 | |
| 3708 | tape->drive = drive; |
| 3709 | tape->driver = &idetape_driver; |
| 3710 | tape->disk = g; |
| 3711 | |
| 3712 | g->private_data = &tape->driver; |
| 3713 | |
| 3714 | drive->driver_data = tape; |
| 3715 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 3716 | mutex_lock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | for (minor = 0; idetape_devs[minor]; minor++) |
| 3718 | ; |
| 3719 | idetape_devs[minor] = tape; |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 3720 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | |
| 3722 | idetape_setup(drive, tape, minor); |
| 3723 | |
Tony Jones | dbc1272 | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 3724 | device_create(idetape_sysfs_class, &drive->gendev, |
| 3725 | MKDEV(IDETAPE_MAJOR, minor), "%s", tape->name); |
| 3726 | device_create(idetape_sysfs_class, &drive->gendev, |
| 3727 | MKDEV(IDETAPE_MAJOR, minor + 128), "n%s", tape->name); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 3728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | g->fops = &idetape_block_ops; |
| 3730 | ide_register_region(g); |
| 3731 | |
| 3732 | return 0; |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 3733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | out_free_tape: |
| 3735 | kfree(tape); |
| 3736 | failed: |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 3737 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | } |
| 3739 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3740 | static void __exit idetape_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 3742 | driver_unregister(&idetape_driver.gen_driver); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 3743 | class_destroy(idetape_sysfs_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | unregister_chrdev(IDETAPE_MAJOR, "ht"); |
| 3745 | } |
| 3746 | |
Bartlomiej Zolnierkiewicz | 17514e8 | 2005-11-19 22:24:35 +0100 | [diff] [blame] | 3747 | static int __init idetape_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | { |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 3749 | int error = 1; |
| 3750 | idetape_sysfs_class = class_create(THIS_MODULE, "ide_tape"); |
| 3751 | if (IS_ERR(idetape_sysfs_class)) { |
| 3752 | idetape_sysfs_class = NULL; |
| 3753 | printk(KERN_ERR "Unable to create sysfs class for ide tapes\n"); |
| 3754 | error = -EBUSY; |
| 3755 | goto out; |
| 3756 | } |
| 3757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3759 | printk(KERN_ERR "ide-tape: Failed to register chrdev" |
| 3760 | " interface\n"); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 3761 | error = -EBUSY; |
| 3762 | goto out_free_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | } |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 3764 | |
| 3765 | error = driver_register(&idetape_driver.gen_driver); |
| 3766 | if (error) |
| 3767 | goto out_free_driver; |
| 3768 | |
| 3769 | return 0; |
| 3770 | |
| 3771 | out_free_driver: |
| 3772 | driver_unregister(&idetape_driver.gen_driver); |
| 3773 | out_free_class: |
| 3774 | class_destroy(idetape_sysfs_class); |
| 3775 | out: |
| 3776 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 3779 | MODULE_ALIAS("ide:*m-tape*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | module_init(idetape_init); |
| 3781 | module_exit(idetape_exit); |
| 3782 | MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR); |
Borislav Petkov | 9c14576 | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 3783 | MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver"); |
| 3784 | MODULE_LICENSE("GPL"); |