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