diff options
author | Borislav Petkov <petkovbb@googlemail.com> | 2008-02-05 20:57:53 -0500 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-02-05 20:57:53 -0500 |
commit | 3c98bf347d95cf9c43104db2fda848d0c7decebd (patch) | |
tree | f2f5b4522c894026137cf8849465572747884414 | |
parent | 8d06bfadb44bfec067603fbc8ee2faced3b13ad9 (diff) |
ide-tape: cleanup and fix comments
Also, remove redundant ones and cleanup whitespace.
Bart:
- minor fixups
Signed-off-by: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
-rw-r--r-- | drivers/ide/ide-tape.c | 681 |
1 files changed, 271 insertions, 410 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index bdf02fcc1a25..d8b02fb0284c 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c | |||
@@ -75,37 +75,34 @@ enum { | |||
75 | 75 | ||
76 | 76 | ||
77 | /* | 77 | /* |
78 | * Pipelined mode parameters. | 78 | * Pipelined mode parameters. |
79 | * | 79 | * |
80 | * 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 |
81 | * keep the tape constantly streaming. To accomplish that, we implement | 81 | * constantly streaming. To accomplish that, we implement a feedback loop around |
82 | * a feedback loop around the maximum number of stages: | 82 | * the maximum number of stages: |
83 | * | 83 | * |
84 | * 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 |
85 | * 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 |
86 | * 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. |
87 | * the optimum value or until we reach MAX. | ||
88 | * | 87 | * |
89 | * 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 |
90 | * cannot be disabled (idetape_calculate_speeds() divides by | 89 | * disabled (idetape_calculate_speeds() divides by tape->max_stages.) |
91 | * tape->max_stages.) | ||
92 | */ | 90 | */ |
93 | #define IDETAPE_MIN_PIPELINE_STAGES 1 | 91 | #define IDETAPE_MIN_PIPELINE_STAGES 1 |
94 | #define IDETAPE_MAX_PIPELINE_STAGES 400 | 92 | #define IDETAPE_MAX_PIPELINE_STAGES 400 |
95 | #define IDETAPE_INCREASE_STAGES_RATE 20 | 93 | #define IDETAPE_INCREASE_STAGES_RATE 20 |
96 | 94 | ||
97 | /* | 95 | /* |
98 | * After each failed packet command we issue a request sense command | 96 | * After each failed packet command we issue a request sense command and retry |
99 | * and retry the packet command IDETAPE_MAX_PC_RETRIES times. | 97 | * the packet command IDETAPE_MAX_PC_RETRIES times. |
100 | * | 98 | * |
101 | * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries. | 99 | * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries. |
102 | */ | 100 | */ |
103 | #define IDETAPE_MAX_PC_RETRIES 3 | 101 | #define IDETAPE_MAX_PC_RETRIES 3 |
104 | 102 | ||
105 | /* | 103 | /* |
106 | * With each packet command, we allocate a buffer of | 104 | * With each packet command, we allocate a buffer of IDETAPE_PC_BUFFER_SIZE |
107 | * 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) |
108 | * commands (Not for READ/WRITE commands). | ||
109 | */ | 106 | */ |
110 | #define IDETAPE_PC_BUFFER_SIZE 256 | 107 | #define IDETAPE_PC_BUFFER_SIZE 256 |
111 | 108 | ||
@@ -124,48 +121,39 @@ enum { | |||
124 | #define IDETAPE_WAIT_CMD (900*HZ) | 121 | #define IDETAPE_WAIT_CMD (900*HZ) |
125 | 122 | ||
126 | /* | 123 | /* |
127 | * 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 |
128 | * 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 |
129 | * the following parameter will improve the system's latency and | 126 | * parameter will improve the system's latency and interactive response, while |
130 | * interactive response, while using a high value might improve system | 127 | * using a high value might improve system throughput. |
131 | * throughput. | ||
132 | */ | 128 | */ |
133 | #define IDETAPE_FIFO_THRESHOLD 2 | 129 | #define IDETAPE_FIFO_THRESHOLD 2 |
134 | 130 | ||
135 | /* | 131 | /* |
136 | * DSC polling parameters. | 132 | * DSC polling parameters. |
137 | * | 133 | * |
138 | * Polling for DSC (a single bit in the status register) is a very | 134 | * Polling for DSC (a single bit in the status register) is a very important |
139 | * important function in ide-tape. There are two cases in which we | 135 | * function in ide-tape. There are two cases in which we poll for DSC: |
140 | * poll for DSC: | ||
141 | * | 136 | * |
142 | * 1. Before a read/write packet command, to ensure that we | 137 | * 1. Before a read/write packet command, to ensure that we can transfer data |
143 | * can transfer data from/to the tape's data buffers, without | 138 | * from/to the tape's data buffers, without causing an actual media access. |
144 | * causing an actual media access. In case the tape is not | 139 | * In case the tape is not ready yet, we take out our request from the device |
145 | * ready yet, we take out our request from the device | 140 | * request queue, so that ide.c could service requests from the other device |
146 | * request queue, so that ide.c will service requests from | 141 | * on the same interface in the meantime. |
147 | * the other device on the same interface meanwhile. | ||
148 | * | 142 | * |
149 | * 2. After the successful initialization of a "media access | 143 | * 2. After the successful initialization of a "media access packet command", |
150 | * packet command", which is a command which can take a long | 144 | * which is a command that can take a long time to complete (the interval can |
151 | * time to complete (it can be several seconds or even an hour). | 145 | * range from several seconds to even an hour). Again, we postpone our request |
146 | * in the middle to free the bus for the other device. The polling frequency | ||
147 | * here should be lower than the read/write frequency since those media access | ||
148 | * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST | ||
149 | * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD | ||
150 | * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min). | ||
152 | * | 151 | * |
153 | * Again, we postpone our request in the middle to free the bus | 152 | * We also set a timeout for the timer, in case something goes wrong. The |
154 | * for the other device. The polling frequency here should be | 153 | * timeout should be longer then the maximum execution time of a tape operation. |
155 | * lower than the read/write frequency since those media access | ||
156 | * commands are slow. We start from a "fast" frequency - | ||
157 | * IDETAPE_DSC_MA_FAST (one second), and if we don't receive DSC | ||
158 | * after IDETAPE_DSC_MA_THRESHOLD (5 minutes), we switch it to a | ||
159 | * lower frequency - IDETAPE_DSC_MA_SLOW (1 minute). | ||
160 | * | ||
161 | * We also set a timeout for the timer, in case something goes wrong. | ||
162 | * The timeout should be longer then the maximum execution time of a | ||
163 | * tape operation. | ||
164 | */ | ||
165 | |||
166 | /* | ||
167 | * DSC timings. | ||
168 | */ | 154 | */ |
155 | |||
156 | /* DSC timings. */ | ||
169 | #define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */ | 157 | #define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */ |
170 | #define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */ | 158 | #define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */ |
171 | #define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */ | 159 | #define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */ |
@@ -176,15 +164,9 @@ enum { | |||
176 | 164 | ||
177 | /*************************** End of tunable parameters ***********************/ | 165 | /*************************** End of tunable parameters ***********************/ |
178 | 166 | ||
179 | /* | 167 | /* Read/Write error simulation */ |
180 | * Read/Write error simulation | ||
181 | */ | ||
182 | #define SIMULATE_ERRORS 0 | 168 | #define SIMULATE_ERRORS 0 |
183 | 169 | ||
184 | /* | ||
185 | * For general magnetic tape device compatibility. | ||
186 | */ | ||
187 | |||
188 | /* tape directions */ | 170 | /* tape directions */ |
189 | enum { | 171 | enum { |
190 | IDETAPE_DIR_NONE = (1 << 0), | 172 | IDETAPE_DIR_NONE = (1 << 0), |
@@ -199,24 +181,32 @@ struct idetape_bh { | |||
199 | char *b_data; | 181 | char *b_data; |
200 | }; | 182 | }; |
201 | 183 | ||
202 | /* | ||
203 | * Our view of a packet command. | ||
204 | */ | ||
205 | typedef struct idetape_packet_command_s { | 184 | typedef struct idetape_packet_command_s { |
206 | u8 c[12]; /* Actual packet bytes */ | 185 | /* Actual packet bytes */ |
207 | int retries; /* On each retry, we increment retries */ | 186 | u8 c[12]; |
208 | int error; /* Error code */ | 187 | /* On each retry, we increment retries */ |
209 | int request_transfer; /* Bytes to transfer */ | 188 | int retries; |
210 | int actually_transferred; /* Bytes actually transferred */ | 189 | /* Error code */ |
211 | 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; | ||
212 | struct idetape_bh *bh; | 197 | struct idetape_bh *bh; |
213 | char *b_data; | 198 | char *b_data; |
214 | int b_count; | 199 | int b_count; |
215 | u8 *buffer; /* Data buffer */ | 200 | /* Data buffer */ |
216 | u8 *current_position; /* Pointer into the above buffer */ | 201 | u8 *buffer; |
217 | ide_startstop_t (*callback) (ide_drive_t *); /* Called when this packet command is completed */ | 202 | /* Pointer into the above buffer */ |
218 | u8 pc_buffer[IDETAPE_PC_BUFFER_SIZE]; /* Temporary buffer */ | 203 | u8 *current_position; |
219 | 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; | ||
220 | } idetape_pc_t; | 210 | } idetape_pc_t; |
221 | 211 | ||
222 | /* | 212 | /* |
@@ -235,9 +225,7 @@ typedef struct idetape_packet_command_s { | |||
235 | /* Data direction */ | 225 | /* Data direction */ |
236 | #define PC_WRITING 5 | 226 | #define PC_WRITING 5 |
237 | 227 | ||
238 | /* | 228 | /* A pipeline stage. */ |
239 | * A pipeline stage. | ||
240 | */ | ||
241 | typedef struct idetape_stage_s { | 229 | typedef struct idetape_stage_s { |
242 | struct request rq; /* The corresponding request */ | 230 | struct request rq; /* The corresponding request */ |
243 | struct idetape_bh *bh; /* The data buffers */ | 231 | struct idetape_bh *bh; /* The data buffers */ |
@@ -245,9 +233,8 @@ typedef struct idetape_stage_s { | |||
245 | } idetape_stage_t; | 233 | } idetape_stage_t; |
246 | 234 | ||
247 | /* | 235 | /* |
248 | * 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 |
249 | * 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. |
250 | * of type idetape_tape_t, defined below. | ||
251 | */ | 238 | */ |
252 | typedef struct ide_tape_obj { | 239 | typedef struct ide_tape_obj { |
253 | ide_drive_t *drive; | 240 | ide_drive_t *drive; |
@@ -283,15 +270,14 @@ typedef struct ide_tape_obj { | |||
283 | int rq_stack_index; | 270 | int rq_stack_index; |
284 | 271 | ||
285 | /* | 272 | /* |
286 | * DSC polling variables. | 273 | * DSC polling variables. |
287 | * | 274 | * |
288 | * While polling for DSC we use postponed_rq to postpone the | 275 | * While polling for DSC we use postponed_rq to postpone the current |
289 | * 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 |
290 | * pending requests on the other device. Note that at most | 277 | * other device. Note that at most we will have only one DSC (usually |
291 | * we will have only one DSC (usually data transfer) request | 278 | * data transfer) request in the device request queue. Additional |
292 | * in the device request queue. Additional requests can be | 279 | * requests can be queued in our internal pipeline, but they will be |
293 | * queued in our internal pipeline, but they will be visible | 280 | * visible to ide.c only one at a time. |
294 | * to ide.c only one at a time. | ||
295 | */ | 281 | */ |
296 | struct request *postponed_rq; | 282 | struct request *postponed_rq; |
297 | /* The time in which we started polling for DSC */ | 283 | /* The time in which we started polling for DSC */ |
@@ -303,21 +289,15 @@ typedef struct ide_tape_obj { | |||
303 | unsigned long dsc_poll_freq; | 289 | unsigned long dsc_poll_freq; |
304 | unsigned long dsc_timeout; | 290 | unsigned long dsc_timeout; |
305 | 291 | ||
306 | /* | 292 | /* Read position information */ |
307 | * Read position information | ||
308 | */ | ||
309 | u8 partition; | 293 | u8 partition; |
310 | /* Current block */ | 294 | /* Current block */ |
311 | unsigned int first_frame; | 295 | unsigned int first_frame; |
312 | 296 | ||
313 | /* | 297 | /* Last error information */ |
314 | * Last error information | ||
315 | */ | ||
316 | u8 sense_key, asc, ascq; | 298 | u8 sense_key, asc, ascq; |
317 | 299 | ||
318 | /* | 300 | /* Character device operation */ |
319 | * Character device operation | ||
320 | */ | ||
321 | unsigned int minor; | 301 | unsigned int minor; |
322 | /* device name */ | 302 | /* device name */ |
323 | char name[4]; | 303 | char name[4]; |
@@ -332,33 +312,30 @@ typedef struct ide_tape_obj { | |||
332 | u8 caps[20]; | 312 | u8 caps[20]; |
333 | 313 | ||
334 | /* | 314 | /* |
335 | * Active data transfer request parameters. | 315 | * Active data transfer request parameters. |
336 | * | ||
337 | * At most, there is only one ide-tape originated data transfer | ||
338 | * request in the device request queue. This allows ide.c to | ||
339 | * easily service requests from the other device when we | ||
340 | * postpone our active request. In the pipelined operation | ||
341 | * mode, we use our internal pipeline structure to hold | ||
342 | * more data requests. | ||
343 | * | 316 | * |
344 | * The data buffer size is chosen based on the tape's | 317 | * At most, there is only one ide-tape originated data transfer request |
345 | * 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. | ||
346 | */ | 323 | */ |
347 | /* Ptr to the request which is waiting in the device request queue */ | 324 | /* ptr to the request which is waiting in the device request queue */ |
348 | struct request *active_data_rq; | 325 | struct request *active_data_rq; |
349 | /* Data buffer size (chosen based on the tape's recommendation */ | 326 | /* Data buffer size chosen based on the tape's recommendation */ |
350 | int stage_size; | 327 | int stage_size; |
351 | idetape_stage_t *merge_stage; | 328 | idetape_stage_t *merge_stage; |
352 | int merge_stage_size; | 329 | int merge_stage_size; |
353 | struct idetape_bh *bh; | 330 | struct idetape_bh *bh; |
354 | char *b_data; | 331 | char *b_data; |
355 | int b_count; | 332 | int b_count; |
356 | 333 | ||
357 | /* | 334 | /* |
358 | * Pipeline parameters. | 335 | * Pipeline parameters. |
359 | * | 336 | * |
360 | * To accomplish non-pipelined mode, we simply set the following | 337 | * To accomplish non-pipelined mode, we simply set the following |
361 | * variables to zero (or NULL, where appropriate). | 338 | * variables to zero (or NULL, where appropriate). |
362 | */ | 339 | */ |
363 | /* Number of currently used stages */ | 340 | /* Number of currently used stages */ |
364 | int nr_stages; | 341 | int nr_stages; |
@@ -385,9 +362,7 @@ typedef struct ide_tape_obj { | |||
385 | /* protects the ide-tape queue */ | 362 | /* protects the ide-tape queue */ |
386 | spinlock_t lock; | 363 | spinlock_t lock; |
387 | 364 | ||
388 | /* | 365 | /* Measures average tape speed */ |
389 | * Measures average tape speed | ||
390 | */ | ||
391 | unsigned long avg_time; | 366 | unsigned long avg_time; |
392 | int avg_size; | 367 | int avg_size; |
393 | int avg_speed; | 368 | int avg_speed; |
@@ -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,18 +392,14 @@ 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 | * Speed regulation negative feedback loop | ||
433 | */ | ||
434 | int speed_control; | 403 | int speed_control; |
435 | int pipeline_head_speed; | 404 | int pipeline_head_speed; |
436 | int controlled_pipeline_head_speed; | 405 | int controlled_pipeline_head_speed; |
@@ -477,9 +446,7 @@ static void ide_tape_put(struct ide_tape_obj *tape) | |||
477 | mutex_unlock(&idetape_ref_mutex); | 446 | mutex_unlock(&idetape_ref_mutex); |
478 | } | 447 | } |
479 | 448 | ||
480 | /* | 449 | /* Tape door status */ |
481 | * Tape door status | ||
482 | */ | ||
483 | #define DOOR_UNLOCKED 0 | 450 | #define DOOR_UNLOCKED 0 |
484 | #define DOOR_LOCKED 1 | 451 | #define DOOR_LOCKED 1 |
485 | #define DOOR_EXPLICITLY_LOCKED 2 | 452 | #define DOOR_EXPLICITLY_LOCKED 2 |
@@ -499,30 +466,23 @@ static void ide_tape_put(struct ide_tape_obj *tape) | |||
499 | /* 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 */ |
500 | #define IDETAPE_MEDIUM_PRESENT 9 | 467 | #define IDETAPE_MEDIUM_PRESENT 9 |
501 | 468 | ||
502 | /* | 469 | /* A define for the READ BUFFER command */ |
503 | * Some defines for the READ BUFFER command | ||
504 | */ | ||
505 | #define IDETAPE_RETRIEVE_FAULTY_BLOCK 6 | 470 | #define IDETAPE_RETRIEVE_FAULTY_BLOCK 6 |
506 | 471 | ||
507 | /* | 472 | /* Some defines for the SPACE command */ |
508 | * Some defines for the SPACE command | ||
509 | */ | ||
510 | #define IDETAPE_SPACE_OVER_FILEMARK 1 | 473 | #define IDETAPE_SPACE_OVER_FILEMARK 1 |
511 | #define IDETAPE_SPACE_TO_EOD 3 | 474 | #define IDETAPE_SPACE_TO_EOD 3 |
512 | 475 | ||
513 | /* | 476 | /* Some defines for the LOAD UNLOAD command */ |
514 | * Some defines for the LOAD UNLOAD command | ||
515 | */ | ||
516 | #define IDETAPE_LU_LOAD_MASK 1 | 477 | #define IDETAPE_LU_LOAD_MASK 1 |
517 | #define IDETAPE_LU_RETENSION_MASK 2 | 478 | #define IDETAPE_LU_RETENSION_MASK 2 |
518 | #define IDETAPE_LU_EOT_MASK 4 | 479 | #define IDETAPE_LU_EOT_MASK 4 |
519 | 480 | ||
520 | /* | 481 | /* |
521 | * Special requests for our block device strategy routine. | 482 | * Special requests for our block device strategy routine. |
522 | * | 483 | * |
523 | * 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 |
524 | * 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. |
525 | * for their completion. | ||
526 | */ | 486 | */ |
527 | 487 | ||
528 | enum { | 488 | enum { |
@@ -533,10 +493,7 @@ enum { | |||
533 | REQ_IDETAPE_READ_BUFFER = (1 << 4), | 493 | REQ_IDETAPE_READ_BUFFER = (1 << 4), |
534 | }; | 494 | }; |
535 | 495 | ||
536 | /* | 496 | /* Error codes returned in rq->errors to the higher part of the driver. */ |
537 | * Error codes which are returned in rq->errors to the higher part | ||
538 | * of the driver. | ||
539 | */ | ||
540 | #define IDETAPE_ERROR_GENERAL 101 | 497 | #define IDETAPE_ERROR_GENERAL 101 |
541 | #define IDETAPE_ERROR_FILEMARK 102 | 498 | #define IDETAPE_ERROR_FILEMARK 102 |
542 | #define IDETAPE_ERROR_EOD 103 | 499 | #define IDETAPE_ERROR_EOD 103 |
@@ -560,8 +517,8 @@ struct idetape_id_gcw { | |||
560 | #define IDETAPE_CAPABILITIES_PAGE 0x2a | 517 | #define IDETAPE_CAPABILITIES_PAGE 0x2a |
561 | 518 | ||
562 | /* | 519 | /* |
563 | * The variables below are used for the character device interface. | 520 | * The variables below are used for the character device interface. Additional |
564 | * Additional state variables are defined in our ide_drive_t structure. | 521 | * state variables are defined in our ide_drive_t structure. |
565 | */ | 522 | */ |
566 | static struct ide_tape_obj * idetape_devs[MAX_HWIFS * MAX_DRIVES]; | 523 | static struct ide_tape_obj * idetape_devs[MAX_HWIFS * MAX_DRIVES]; |
567 | 524 | ||
@@ -579,10 +536,6 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i) | |||
579 | return tape; | 536 | return tape; |
580 | } | 537 | } |
581 | 538 | ||
582 | /* | ||
583 | * Function declarations | ||
584 | * | ||
585 | */ | ||
586 | static int idetape_chrdev_release (struct inode *inode, struct file *filp); | 539 | static int idetape_chrdev_release (struct inode *inode, struct file *filp); |
587 | static void idetape_write_release (ide_drive_t *drive, unsigned int minor); | 540 | static void idetape_write_release (ide_drive_t *drive, unsigned int minor); |
588 | 541 | ||
@@ -711,9 +664,6 @@ static struct request *idetape_next_rq_storage (ide_drive_t *drive) | |||
711 | return (&tape->rq_stack[tape->rq_stack_index++]); | 664 | return (&tape->rq_stack[tape->rq_stack_index++]); |
712 | } | 665 | } |
713 | 666 | ||
714 | /* | ||
715 | * idetape_init_pc initializes a packet command. | ||
716 | */ | ||
717 | static void idetape_init_pc (idetape_pc_t *pc) | 667 | static void idetape_init_pc (idetape_pc_t *pc) |
718 | { | 668 | { |
719 | memset(pc->c, 0, 12); | 669 | memset(pc->c, 0, 12); |
@@ -809,10 +759,7 @@ static void idetape_activate_next_stage(ide_drive_t *drive) | |||
809 | tape->next_stage = stage->next; | 759 | tape->next_stage = stage->next; |
810 | } | 760 | } |
811 | 761 | ||
812 | /* | 762 | /* Free a stage along with its related buffers completely. */ |
813 | * idetape_kfree_stage calls kfree to completely free a stage, along with | ||
814 | * its related buffers. | ||
815 | */ | ||
816 | static void __idetape_kfree_stage (idetape_stage_t *stage) | 763 | static void __idetape_kfree_stage (idetape_stage_t *stage) |
817 | { | 764 | { |
818 | struct idetape_bh *prev_bh, *bh = stage->bh; | 765 | struct idetape_bh *prev_bh, *bh = stage->bh; |
@@ -840,8 +787,8 @@ static void idetape_kfree_stage (idetape_tape_t *tape, idetape_stage_t *stage) | |||
840 | } | 787 | } |
841 | 788 | ||
842 | /* | 789 | /* |
843 | * idetape_remove_stage_head removes tape->first_stage from the pipeline. | 790 | * Remove tape->first_stage from the pipeline. The caller should avoid race |
844 | * The caller should avoid race conditions. | 791 | * conditions. |
845 | */ | 792 | */ |
846 | static void idetape_remove_stage_head (ide_drive_t *drive) | 793 | static void idetape_remove_stage_head (ide_drive_t *drive) |
847 | { | 794 | { |
@@ -899,8 +846,8 @@ static void idetape_abort_pipeline(ide_drive_t *drive, | |||
899 | } | 846 | } |
900 | 847 | ||
901 | /* | 848 | /* |
902 | * idetape_end_request is used to finish servicing a request, and to | 849 | * Finish servicing a request and insert a pending pipeline request into the |
903 | * insert a pending pipeline request into the main device queue. | 850 | * main device queue. |
904 | */ | 851 | */ |
905 | static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) | 852 | static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) |
906 | { | 853 | { |
@@ -951,9 +898,7 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) | |||
951 | if (tape->next_stage != NULL) { | 898 | if (tape->next_stage != NULL) { |
952 | idetape_activate_next_stage(drive); | 899 | idetape_activate_next_stage(drive); |
953 | 900 | ||
954 | /* | 901 | /* Insert the next request into the request queue. */ |
955 | * Insert the next request into the request queue. | ||
956 | */ | ||
957 | (void)ide_do_drive_cmd(drive, tape->active_data_rq, | 902 | (void)ide_do_drive_cmd(drive, tape->active_data_rq, |
958 | ide_end); | 903 | ide_end); |
959 | } else if (!error) { | 904 | } else if (!error) { |
@@ -1020,23 +965,19 @@ static void idetape_init_rq(struct request *rq, u8 cmd) | |||
1020 | } | 965 | } |
1021 | 966 | ||
1022 | /* | 967 | /* |
1023 | * idetape_queue_pc_head generates a new packet command request in front | 968 | * Generate a new packet command request in front of the request queue, before |
1024 | * of the request queue, before the current request, so that it will be | 969 | * the current request, so that it will be processed immediately, on the next |
1025 | * processed immediately, on the next pass through the driver. | 970 | * pass through the driver. The function below is called from the request |
1026 | * | 971 | * handling part of the driver (the "bottom" part). Safe storage for the request |
1027 | * idetape_queue_pc_head is called from the request handling part of | 972 | * should be allocated with ide_tape_next_{pc,rq}_storage() prior to that. |
1028 | * the driver (the "bottom" part). Safe storage for the request should | ||
1029 | * be allocated with idetape_next_pc_storage and idetape_next_rq_storage | ||
1030 | * before calling idetape_queue_pc_head. | ||
1031 | * | 973 | * |
1032 | * Memory for those requests is pre-allocated at initialization time, and | 974 | * Memory for those requests is pre-allocated at initialization time, and is |
1033 | * is limited to IDETAPE_PC_STACK requests. We assume that we have enough | 975 | * limited to IDETAPE_PC_STACK requests. We assume that we have enough space for |
1034 | * space for the maximum possible number of inter-dependent packet commands. | 976 | * the maximum possible number of inter-dependent packet commands. |
1035 | * | 977 | * |
1036 | * The higher level of the driver - The ioctl handler and the character | 978 | * The higher level of the driver - The ioctl handler and the character device |
1037 | * device handling functions should queue request to the lower level part | 979 | * handling functions should queue request to the lower level part and wait for |
1038 | * and wait for their completion using idetape_queue_pc_tail or | 980 | * their completion using idetape_queue_pc_tail or idetape_queue_rw_tail. |
1039 | * idetape_queue_rw_tail. | ||
1040 | */ | 981 | */ |
1041 | static void idetape_queue_pc_head (ide_drive_t *drive, idetape_pc_t *pc,struct request *rq) | 982 | static void idetape_queue_pc_head (ide_drive_t *drive, idetape_pc_t *pc,struct request *rq) |
1042 | { | 983 | { |
@@ -1069,9 +1010,8 @@ static ide_startstop_t idetape_retry_pc (ide_drive_t *drive) | |||
1069 | } | 1010 | } |
1070 | 1011 | ||
1071 | /* | 1012 | /* |
1072 | * idetape_postpone_request postpones the current request so that | 1013 | * Postpone the current request so that ide.c will be able to service requests |
1073 | * ide.c will be able to service requests from another device on | 1014 | * from another device on the same hwgroup while we are polling for DSC. |
1074 | * the same hwgroup while we are polling for DSC. | ||
1075 | */ | 1015 | */ |
1076 | static void idetape_postpone_request (ide_drive_t *drive) | 1016 | static void idetape_postpone_request (ide_drive_t *drive) |
1077 | { | 1017 | { |
@@ -1258,46 +1198,40 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive) | |||
1258 | } | 1198 | } |
1259 | 1199 | ||
1260 | /* | 1200 | /* |
1261 | * Packet Command Interface | 1201 | * Packet Command Interface |
1262 | * | 1202 | * |
1263 | * The current Packet Command is available in tape->pc, and will not | 1203 | * The current Packet Command is available in tape->pc, and will not change |
1264 | * change until we finish handling it. Each packet command is associated | 1204 | * until we finish handling it. Each packet command is associated with a |
1265 | * with a callback function that will be called when the command is | 1205 | * callback function that will be called when the command is finished. |
1266 | * finished. | ||
1267 | * | 1206 | * |
1268 | * The handling will be done in three stages: | 1207 | * The handling will be done in three stages: |
1269 | * | 1208 | * |
1270 | * 1. idetape_issue_pc will send the packet command to the | 1209 | * 1. idetape_issue_pc will send the packet command to the drive, and will set |
1271 | * drive, and will set the interrupt handler to idetape_pc_intr. | 1210 | * the interrupt handler to idetape_pc_intr. |
1272 | * | 1211 | * |
1273 | * 2. On each interrupt, idetape_pc_intr will be called. This step | 1212 | * 2. On each interrupt, idetape_pc_intr will be called. This step will be |
1274 | * will be repeated until the device signals us that no more | 1213 | * repeated until the device signals us that no more interrupts will be issued. |
1275 | * interrupts will be issued. | ||
1276 | * | 1214 | * |
1277 | * 3. ATAPI Tape media access commands have immediate status with a | 1215 | * 3. ATAPI Tape media access commands have immediate status with a delayed |
1278 | * delayed process. In case of a successful initiation of a | 1216 | * process. In case of a successful initiation of a media access packet command, |
1279 | * media access packet command, the DSC bit will be set when the | 1217 | * the DSC bit will be set when the actual execution of the command is finished. |
1280 | * actual execution of the command is finished. | 1218 | * Since the tape drive will not issue an interrupt, we have to poll for this |
1281 | * Since the tape drive will not issue an interrupt, we have to | 1219 | * event. In this case, we define the request as "low priority request" by |
1282 | * poll for this event. In this case, we define the request as | 1220 | * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and |
1283 | * "low priority request" by setting rq_status to | 1221 | * exit the driver. |
1284 | * IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and exit | ||
1285 | * the driver. | ||
1286 | * | 1222 | * |
1287 | * ide.c will then give higher priority to requests which | 1223 | * ide.c will then give higher priority to requests which originate from the |
1288 | * originate from the other device, until will change rq_status | 1224 | * other device, until will change rq_status to RQ_ACTIVE. |
1289 | * to RQ_ACTIVE. | ||
1290 | * | 1225 | * |
1291 | * 4. When the packet command is finished, it will be checked for errors. | 1226 | * 4. When the packet command is finished, it will be checked for errors. |
1292 | * | 1227 | * |
1293 | * 5. In case an error was found, we queue a request sense packet | 1228 | * 5. In case an error was found, we queue a request sense packet command in |
1294 | * command in front of the request queue and retry the operation | 1229 | * front of the request queue and retry the operation up to |
1295 | * up to IDETAPE_MAX_PC_RETRIES times. | 1230 | * IDETAPE_MAX_PC_RETRIES times. |
1296 | * | ||
1297 | * 6. In case no error was found, or we decided to give up and not | ||
1298 | * to retry again, the callback function will be called and then | ||
1299 | * we will handle the next request. | ||
1300 | * | 1231 | * |
1232 | * 6. In case no error was found, or we decided to give up and not to retry | ||
1233 | * again, the callback function will be called and then we will handle the next | ||
1234 | * request. | ||
1301 | */ | 1235 | */ |
1302 | static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive) | 1236 | static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive) |
1303 | { | 1237 | { |
@@ -1363,9 +1297,9 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, idetape_pc_t *pc) | |||
1363 | if (pc->retries > IDETAPE_MAX_PC_RETRIES || | 1297 | if (pc->retries > IDETAPE_MAX_PC_RETRIES || |
1364 | test_bit(PC_ABORT, &pc->flags)) { | 1298 | test_bit(PC_ABORT, &pc->flags)) { |
1365 | /* | 1299 | /* |
1366 | * We will "abort" retrying a packet command in case | 1300 | * We will "abort" retrying a packet command in case legitimate |
1367 | * a legitimate error code was received (crossing a | 1301 | * error code was received (crossing a filemark, or end of the |
1368 | * filemark, or end of the media, for example). | 1302 | * media, for example). |
1369 | */ | 1303 | */ |
1370 | if (!test_bit(PC_ABORT, &pc->flags)) { | 1304 | if (!test_bit(PC_ABORT, &pc->flags)) { |
1371 | if (!(pc->c[0] == TEST_UNIT_READY && | 1305 | if (!(pc->c[0] == TEST_UNIT_READY && |
@@ -1416,9 +1350,6 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, idetape_pc_t *pc) | |||
1416 | } | 1350 | } |
1417 | } | 1351 | } |
1418 | 1352 | ||
1419 | /* | ||
1420 | * General packet command callback function. | ||
1421 | */ | ||
1422 | static ide_startstop_t idetape_pc_callback (ide_drive_t *drive) | 1353 | static ide_startstop_t idetape_pc_callback (ide_drive_t *drive) |
1423 | { | 1354 | { |
1424 | idetape_tape_t *tape = drive->driver_data; | 1355 | idetape_tape_t *tape = drive->driver_data; |
@@ -1429,15 +1360,14 @@ static ide_startstop_t idetape_pc_callback (ide_drive_t *drive) | |||
1429 | return ide_stopped; | 1360 | return ide_stopped; |
1430 | } | 1361 | } |
1431 | 1362 | ||
1432 | /* | 1363 | /* A mode sense command is used to "sense" tape parameters. */ |
1433 | * A mode sense command is used to "sense" tape parameters. | ||
1434 | */ | ||
1435 | static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code) | 1364 | static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code) |
1436 | { | 1365 | { |
1437 | idetape_init_pc(pc); | 1366 | idetape_init_pc(pc); |
1438 | pc->c[0] = MODE_SENSE; | 1367 | pc->c[0] = MODE_SENSE; |
1439 | if (page_code != IDETAPE_BLOCK_DESCRIPTOR) | 1368 | if (page_code != IDETAPE_BLOCK_DESCRIPTOR) |
1440 | pc->c[1] = 8; /* DBD = 1 - Don't return block descriptors */ | 1369 | /* DBD = 1 - Don't return block descriptors */ |
1370 | pc->c[1] = 8; | ||
1441 | pc->c[2] = page_code; | 1371 | pc->c[2] = page_code; |
1442 | /* | 1372 | /* |
1443 | * Changed pc->c[3] to 0 (255 will at best return unused info). | 1373 | * Changed pc->c[3] to 0 (255 will at best return unused info). |
@@ -1447,7 +1377,8 @@ static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code) | |||
1447 | * and return an error when 255 is used. | 1377 | * and return an error when 255 is used. |
1448 | */ | 1378 | */ |
1449 | pc->c[3] = 0; | 1379 | pc->c[3] = 0; |
1450 | pc->c[4] = 255; /* (We will just discard data in that case) */ | 1380 | /* We will just discard data in that case */ |
1381 | pc->c[4] = 255; | ||
1451 | if (page_code == IDETAPE_BLOCK_DESCRIPTOR) | 1382 | if (page_code == IDETAPE_BLOCK_DESCRIPTOR) |
1452 | pc->request_transfer = 12; | 1383 | pc->request_transfer = 12; |
1453 | else if (page_code == IDETAPE_CAPABILITIES_PAGE) | 1384 | else if (page_code == IDETAPE_CAPABILITIES_PAGE) |
@@ -1619,9 +1550,6 @@ static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, uns | |||
1619 | set_bit(PC_DMA_RECOMMENDED, &pc->flags); | 1550 | set_bit(PC_DMA_RECOMMENDED, &pc->flags); |
1620 | } | 1551 | } |
1621 | 1552 | ||
1622 | /* | ||
1623 | * idetape_do_request is our request handling function. | ||
1624 | */ | ||
1625 | static ide_startstop_t idetape_do_request(ide_drive_t *drive, | 1553 | static ide_startstop_t idetape_do_request(ide_drive_t *drive, |
1626 | struct request *rq, sector_t block) | 1554 | struct request *rq, sector_t block) |
1627 | { | 1555 | { |
@@ -1635,18 +1563,14 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive, | |||
1635 | rq->sector, rq->nr_sectors, rq->current_nr_sectors); | 1563 | rq->sector, rq->nr_sectors, rq->current_nr_sectors); |
1636 | 1564 | ||
1637 | if (!blk_special_request(rq)) { | 1565 | if (!blk_special_request(rq)) { |
1638 | /* | 1566 | /* We do not support buffer cache originated requests. */ |
1639 | * We do not support buffer cache originated requests. | ||
1640 | */ | ||
1641 | printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " | 1567 | printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " |
1642 | "request queue (%d)\n", drive->name, rq->cmd_type); | 1568 | "request queue (%d)\n", drive->name, rq->cmd_type); |
1643 | ide_end_request(drive, 0, 0); | 1569 | ide_end_request(drive, 0, 0); |
1644 | return ide_stopped; | 1570 | return ide_stopped; |
1645 | } | 1571 | } |
1646 | 1572 | ||
1647 | /* | 1573 | /* Retry a failed packet command */ |
1648 | * Retry a failed packet command | ||
1649 | */ | ||
1650 | if (tape->failed_pc != NULL && | 1574 | if (tape->failed_pc != NULL && |
1651 | tape->pc->c[0] == REQUEST_SENSE) { | 1575 | tape->pc->c[0] == REQUEST_SENSE) { |
1652 | return idetape_issue_pc(drive, tape->failed_pc); | 1576 | return idetape_issue_pc(drive, tape->failed_pc); |
@@ -1733,9 +1657,7 @@ out: | |||
1733 | return idetape_issue_pc(drive, pc); | 1657 | return idetape_issue_pc(drive, pc); |
1734 | } | 1658 | } |
1735 | 1659 | ||
1736 | /* | 1660 | /* Pipeline related functions */ |
1737 | * Pipeline related functions | ||
1738 | */ | ||
1739 | static inline int idetape_pipeline_active (idetape_tape_t *tape) | 1661 | static inline int idetape_pipeline_active (idetape_tape_t *tape) |
1740 | { | 1662 | { |
1741 | int rc1, rc2; | 1663 | int rc1, rc2; |
@@ -1746,16 +1668,16 @@ static inline int idetape_pipeline_active (idetape_tape_t *tape) | |||
1746 | } | 1668 | } |
1747 | 1669 | ||
1748 | /* | 1670 | /* |
1749 | * idetape_kmalloc_stage uses __get_free_page to allocate a pipeline | 1671 | * The function below uses __get_free_page to allocate a pipeline stage, along |
1750 | * stage, along with all the necessary small buffers which together make | 1672 | * with all the necessary small buffers which together make a buffer of size |
1751 | * a buffer of size tape->stage_size (or a bit more). We attempt to | 1673 | * tape->stage_size (or a bit more). We attempt to combine sequential pages as |
1752 | * combine sequential pages as much as possible. | 1674 | * much as possible. |
1753 | * | 1675 | * |
1754 | * Returns a pointer to the new allocated stage, or NULL if we | 1676 | * It returns a pointer to the new allocated stage, or NULL if we can't (or |
1755 | * can't (or don't want to) allocate a stage. | 1677 | * don't want to) allocate a stage. |
1756 | * | 1678 | * |
1757 | * Pipeline stages are optional and are used to increase performance. | 1679 | * Pipeline stages are optional and are used to increase performance. If we |
1758 | * If we can't allocate them, we'll manage without them. | 1680 | * can't allocate them, we'll manage without them. |
1759 | */ | 1681 | */ |
1760 | static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, int clear) | 1682 | static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, int clear) |
1761 | { | 1683 | { |
@@ -1913,9 +1835,7 @@ static void idetape_switch_buffers (idetape_tape_t *tape, idetape_stage_t *stage | |||
1913 | idetape_init_merge_stage(tape); | 1835 | idetape_init_merge_stage(tape); |
1914 | } | 1836 | } |
1915 | 1837 | ||
1916 | /* | 1838 | /* Add a new stage at the end of the pipeline. */ |
1917 | * idetape_add_stage_tail adds a new stage at the end of the pipeline. | ||
1918 | */ | ||
1919 | static void idetape_add_stage_tail (ide_drive_t *drive,idetape_stage_t *stage) | 1839 | static void idetape_add_stage_tail (ide_drive_t *drive,idetape_stage_t *stage) |
1920 | { | 1840 | { |
1921 | idetape_tape_t *tape = drive->driver_data; | 1841 | idetape_tape_t *tape = drive->driver_data; |
@@ -1937,12 +1857,9 @@ static void idetape_add_stage_tail (ide_drive_t *drive,idetape_stage_t *stage) | |||
1937 | spin_unlock_irqrestore(&tape->lock, flags); | 1857 | spin_unlock_irqrestore(&tape->lock, flags); |
1938 | } | 1858 | } |
1939 | 1859 | ||
1940 | /* | 1860 | /* Install a completion in a pending request and sleep until it is serviced. The |
1941 | * idetape_wait_for_request installs a completion in a pending request | 1861 | * caller should ensure that the request will not be serviced before we install |
1942 | * and sleeps until it is serviced. | 1862 | * the completion (usually by disabling interrupts). |
1943 | * | ||
1944 | * The caller should ensure that the request will not be serviced | ||
1945 | * before we install the completion (usually by disabling interrupts). | ||
1946 | */ | 1863 | */ |
1947 | static void idetape_wait_for_request (ide_drive_t *drive, struct request *rq) | 1864 | static void idetape_wait_for_request (ide_drive_t *drive, struct request *rq) |
1948 | { | 1865 | { |
@@ -1996,12 +1913,8 @@ static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive) | |||
1996 | } | 1913 | } |
1997 | 1914 | ||
1998 | /* | 1915 | /* |
1999 | * idetape_create_write_filemark_cmd will: | 1916 | * Write a filemark if write_filemark=1. Flush the device buffers without |
2000 | * | 1917 | * writing a filemark otherwise. |
2001 | * 1. Write a filemark if write_filemark=1. | ||
2002 | * 2. Flush the device buffers without writing a filemark | ||
2003 | * if write_filemark=0. | ||
2004 | * | ||
2005 | */ | 1918 | */ |
2006 | static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t *pc,int write_filemark) | 1919 | static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t *pc,int write_filemark) |
2007 | { | 1920 | { |
@@ -2020,24 +1933,17 @@ static void idetape_create_test_unit_ready_cmd(idetape_pc_t *pc) | |||
2020 | } | 1933 | } |
2021 | 1934 | ||
2022 | /* | 1935 | /* |
2023 | * idetape_queue_pc_tail is based on the following functions: | 1936 | * We add a special packet command request to the tail of the request queue, and |
2024 | * | 1937 | * wait for it to be serviced. This is not to be called from within the request |
2025 | * ide_do_drive_cmd from ide.c | 1938 | * handling part of the driver! We allocate here data on the stack and it is |
2026 | * cdrom_queue_request and cdrom_queue_packet_command from ide-cd.c | 1939 | * valid until the request is finished. This is not the case for the bottom part |
2027 | * | 1940 | * of the driver, where we are always leaving the functions to wait for an |
2028 | * We add a special packet command request to the tail of the request | 1941 | * interrupt or a timer event. |
2029 | * queue, and wait for it to be serviced. | ||
2030 | * | 1942 | * |
2031 | * This is not to be called from within the request handling part | 1943 | * From the bottom part of the driver, we should allocate safe memory using |
2032 | * of the driver ! We allocate here data in the stack, and it is valid | 1944 | * idetape_next_pc_storage() and ide_tape_next_rq_storage(), and add the request |
2033 | * until the request is finished. This is not the case for the bottom | 1945 | * to the request list without waiting for it to be serviced! In that case, we |
2034 | * part of the driver, where we are always leaving the functions to wait | 1946 | * usually use idetape_queue_pc_head(). |
2035 | * for an interrupt or a timer event. | ||
2036 | * | ||
2037 | * From the bottom part of the driver, we should allocate safe memory | ||
2038 | * using idetape_next_pc_storage and idetape_next_rq_storage, and add | ||
2039 | * the request to the request list without waiting for it to be serviced ! | ||
2040 | * In that case, we usually use idetape_queue_pc_head. | ||
2041 | */ | 1947 | */ |
2042 | static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc) | 1948 | static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc) |
2043 | { | 1949 | { |
@@ -2065,9 +1971,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) | |||
2065 | idetape_pc_t pc; | 1971 | idetape_pc_t pc; |
2066 | int load_attempted = 0; | 1972 | int load_attempted = 0; |
2067 | 1973 | ||
2068 | /* | 1974 | /* Wait for the tape to become ready */ |
2069 | * Wait for the tape to become ready | ||
2070 | */ | ||
2071 | set_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags); | 1975 | set_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags); |
2072 | timeout += jiffies; | 1976 | timeout += jiffies; |
2073 | while (time_before(jiffies, timeout)) { | 1977 | while (time_before(jiffies, timeout)) { |
@@ -2075,7 +1979,8 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) | |||
2075 | if (!__idetape_queue_pc_tail(drive, &pc)) | 1979 | if (!__idetape_queue_pc_tail(drive, &pc)) |
2076 | return 0; | 1980 | return 0; |
2077 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) | 1981 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) |
2078 | || (tape->asc == 0x3A)) { /* no media */ | 1982 | || (tape->asc == 0x3A)) { |
1983 | /* no media */ | ||
2079 | if (load_attempted) | 1984 | if (load_attempted) |
2080 | return -ENOMEDIUM; | 1985 | return -ENOMEDIUM; |
2081 | idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK); | 1986 | idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK); |
@@ -2203,13 +2108,10 @@ static int __idetape_discard_read_pipeline (ide_drive_t *drive) | |||
2203 | } | 2108 | } |
2204 | 2109 | ||
2205 | /* | 2110 | /* |
2206 | * idetape_position_tape positions the tape to the requested block | 2111 | * Position the tape to the requested block using the LOCATE packet command. |
2207 | * using the LOCATE packet command. A READ POSITION command is then | 2112 | * A READ POSITION command is then issued to check where we are positioned. Like |
2208 | * issued to check where we are positioned. | 2113 | * all higher level operations, we queue the commands at the tail of the request |
2209 | * | 2114 | * queue and wait for their completion. |
2210 | * Like all higher level operations, we queue the commands at the tail | ||
2211 | * of the request queue and wait for their completion. | ||
2212 | * | ||
2213 | */ | 2115 | */ |
2214 | static int idetape_position_tape (ide_drive_t *drive, unsigned int block, u8 partition, int skip) | 2116 | static int idetape_position_tape (ide_drive_t *drive, unsigned int block, u8 partition, int skip) |
2215 | { | 2117 | { |
@@ -2247,8 +2149,8 @@ static void idetape_discard_read_pipeline (ide_drive_t *drive, int restore_posit | |||
2247 | } | 2149 | } |
2248 | 2150 | ||
2249 | /* | 2151 | /* |
2250 | * idetape_queue_rw_tail generates a read/write request for the block | 2152 | * Generate a read/write request for the block device interface and wait for it |
2251 | * device interface and wait for it to be serviced. | 2153 | * to be serviced. |
2252 | */ | 2154 | */ |
2253 | static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, struct idetape_bh *bh) | 2155 | static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, struct idetape_bh *bh) |
2254 | { | 2156 | { |
@@ -2343,15 +2245,15 @@ static void idetape_wait_first_stage (ide_drive_t *drive) | |||
2343 | } | 2245 | } |
2344 | 2246 | ||
2345 | /* | 2247 | /* |
2346 | * idetape_add_chrdev_write_request tries to add a character device | 2248 | * Try to add a character device originated write request to our pipeline. In |
2347 | * originated write request to our pipeline. In case we don't succeed, | 2249 | * case we don't succeed, we revert to non-pipelined operation mode for this |
2348 | * we revert to non-pipelined operation mode for this request. | 2250 | * request. In order to accomplish that, we |
2349 | * | 2251 | * |
2350 | * 1. Try to allocate a new pipeline stage. | 2252 | * 1. Try to allocate a new pipeline stage. |
2351 | * 2. If we can't, wait for more and more requests to be serviced | 2253 | * 2. If we can't, wait for more and more requests to be serviced and try again |
2352 | * and try again each time. | 2254 | * each time. |
2353 | * 3. If we still can't allocate a stage, fallback to | 2255 | * 3. If we still can't allocate a stage, fallback to non-pipelined operation |
2354 | * non-pipelined operation mode for this request. | 2256 | * mode for this request. |
2355 | */ | 2257 | */ |
2356 | static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) | 2258 | static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) |
2357 | { | 2259 | { |
@@ -2362,10 +2264,7 @@ static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) | |||
2362 | 2264 | ||
2363 | debug_log(DBG_CHRDEV, "Enter %s\n", __func__); | 2265 | debug_log(DBG_CHRDEV, "Enter %s\n", __func__); |
2364 | 2266 | ||
2365 | /* | 2267 | /* Attempt to allocate a new stage. Beware possible race conditions. */ |
2366 | * Attempt to allocate a new stage. | ||
2367 | * Pay special attention to possible race conditions. | ||
2368 | */ | ||
2369 | while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) { | 2268 | while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) { |
2370 | spin_lock_irqsave(&tape->lock, flags); | 2269 | spin_lock_irqsave(&tape->lock, flags); |
2371 | if (idetape_pipeline_active(tape)) { | 2270 | if (idetape_pipeline_active(tape)) { |
@@ -2377,8 +2276,8 @@ static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) | |||
2377 | if (idetape_pipeline_active(tape)) | 2276 | if (idetape_pipeline_active(tape)) |
2378 | continue; | 2277 | continue; |
2379 | /* | 2278 | /* |
2380 | * Linux is short on memory. Fallback to | 2279 | * The machine is short on memory. Fallback to non- |
2381 | * non-pipelined operation mode for this request. | 2280 | * pipelined operation mode for this request. |
2382 | */ | 2281 | */ |
2383 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh); | 2282 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh); |
2384 | } | 2283 | } |
@@ -2395,11 +2294,11 @@ static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) | |||
2395 | idetape_calculate_speeds(drive); | 2294 | idetape_calculate_speeds(drive); |
2396 | 2295 | ||
2397 | /* | 2296 | /* |
2398 | * Estimate whether the tape has stopped writing by checking | 2297 | * Estimate whether the tape has stopped writing by checking if our |
2399 | * if our write pipeline is currently empty. If we are not | 2298 | * write pipeline is currently empty. If we are not writing anymore, |
2400 | * writing anymore, wait for the pipeline to be full enough | 2299 | * wait for the pipeline to be almost completely full (90%) before |
2401 | * (90%) before starting to service requests, so that we will | 2300 | * starting to service requests, so that we will be able to keep up with |
2402 | * be able to keep up with the higher speeds of the tape. | 2301 | * the higher speeds of the tape. |
2403 | */ | 2302 | */ |
2404 | if (!idetape_pipeline_active(tape)) { | 2303 | if (!idetape_pipeline_active(tape)) { |
2405 | if (tape->nr_stages >= tape->max_stages * 9 / 10 || | 2304 | if (tape->nr_stages >= tape->max_stages * 9 / 10 || |
@@ -2420,8 +2319,8 @@ static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) | |||
2420 | } | 2319 | } |
2421 | 2320 | ||
2422 | /* | 2321 | /* |
2423 | * idetape_wait_for_pipeline will wait until all pending pipeline | 2322 | * Wait until all pending pipeline requests are serviced. Typically called on |
2424 | * requests are serviced. Typically called on device close. | 2323 | * device close. |
2425 | */ | 2324 | */ |
2426 | static void idetape_wait_for_pipeline (ide_drive_t *drive) | 2325 | static void idetape_wait_for_pipeline (ide_drive_t *drive) |
2427 | { | 2326 | { |
@@ -2490,10 +2389,10 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive) | |||
2490 | tape->chrdev_dir = IDETAPE_DIR_NONE; | 2389 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
2491 | 2390 | ||
2492 | /* | 2391 | /* |
2493 | * On the next backup, perform the feedback loop again. | 2392 | * On the next backup, perform the feedback loop again. (I don't want to |
2494 | * (I don't want to keep sense information between backups, | 2393 | * keep sense information between backups, as some systems are |
2495 | * as some systems are constantly on, and the system load | 2394 | * constantly on, and the system load can be totally different on the |
2496 | * can be totally different on the next backup). | 2395 | * next backup). |
2497 | */ | 2396 | */ |
2498 | tape->max_stages = tape->min_pipeline; | 2397 | tape->max_stages = tape->min_pipeline; |
2499 | if (tape->first_stage != NULL || | 2398 | if (tape->first_stage != NULL || |
@@ -2545,11 +2444,10 @@ static int idetape_init_read(ide_drive_t *drive, int max_stages) | |||
2545 | tape->chrdev_dir = IDETAPE_DIR_READ; | 2444 | tape->chrdev_dir = IDETAPE_DIR_READ; |
2546 | 2445 | ||
2547 | /* | 2446 | /* |
2548 | * Issue a read 0 command to ensure that DSC handshake | 2447 | * Issue a read 0 command to ensure that DSC handshake is |
2549 | * is switched from completion mode to buffer available | 2448 | * switched from completion mode to buffer available mode. |
2550 | * mode. | 2449 | * No point in issuing this if DSC overlap isn't supported, some |
2551 | * No point in issuing this if DSC overlap isn't supported, | 2450 | * drives (Seagate STT3401A) will return an error. |
2552 | * some drives (Seagate STT3401A) will return an error. | ||
2553 | */ | 2451 | */ |
2554 | if (drive->dsc_overlap) { | 2452 | if (drive->dsc_overlap) { |
2555 | bytes_read = idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, 0, tape->merge_stage->bh); | 2453 | bytes_read = idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, 0, tape->merge_stage->bh); |
@@ -2590,9 +2488,8 @@ static int idetape_init_read(ide_drive_t *drive, int max_stages) | |||
2590 | } | 2488 | } |
2591 | 2489 | ||
2592 | /* | 2490 | /* |
2593 | * idetape_add_chrdev_read_request is called from idetape_chrdev_read | 2491 | * Called from idetape_chrdev_read() to service a character device read request |
2594 | * to service a character device read request and add read-ahead | 2492 | * and add read-ahead requests to our pipeline. |
2595 | * requests to our pipeline. | ||
2596 | */ | 2493 | */ |
2597 | static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks) | 2494 | static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks) |
2598 | { | 2495 | { |
@@ -2603,16 +2500,11 @@ static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks) | |||
2603 | 2500 | ||
2604 | debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); | 2501 | debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); |
2605 | 2502 | ||
2606 | /* | 2503 | /* If we are at a filemark, return a read length of 0 */ |
2607 | * If we are at a filemark, return a read length of 0 | ||
2608 | */ | ||
2609 | if (test_bit(IDETAPE_FILEMARK, &tape->flags)) | 2504 | if (test_bit(IDETAPE_FILEMARK, &tape->flags)) |
2610 | return 0; | 2505 | return 0; |
2611 | 2506 | ||
2612 | /* | 2507 | /* Wait for the next block to reach the head of the pipeline. */ |
2613 | * Wait for the next block to be available at the head | ||
2614 | * of the pipeline | ||
2615 | */ | ||
2616 | idetape_init_read(drive, tape->max_stages); | 2508 | idetape_init_read(drive, tape->max_stages); |
2617 | if (tape->first_stage == NULL) { | 2509 | if (tape->first_stage == NULL) { |
2618 | if (test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags)) | 2510 | if (test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags)) |
@@ -2651,7 +2543,7 @@ static void idetape_pad_zeros (ide_drive_t *drive, int bcount) | |||
2651 | idetape_tape_t *tape = drive->driver_data; | 2543 | idetape_tape_t *tape = drive->driver_data; |
2652 | struct idetape_bh *bh; | 2544 | struct idetape_bh *bh; |
2653 | int blocks; | 2545 | int blocks; |
2654 | 2546 | ||
2655 | while (bcount) { | 2547 | while (bcount) { |
2656 | unsigned int count; | 2548 | unsigned int count; |
2657 | 2549 | ||
@@ -2691,10 +2583,9 @@ static int idetape_pipeline_size (ide_drive_t *drive) | |||
2691 | } | 2583 | } |
2692 | 2584 | ||
2693 | /* | 2585 | /* |
2694 | * Rewinds the tape to the Beginning Of the current Partition (BOP). | 2586 | * Rewinds the tape to the Beginning Of the current Partition (BOP). We |
2695 | * | 2587 | * currently support only one partition. |
2696 | * We currently support only one partition. | 2588 | */ |
2697 | */ | ||
2698 | static int idetape_rewind_tape (ide_drive_t *drive) | 2589 | static int idetape_rewind_tape (ide_drive_t *drive) |
2699 | { | 2590 | { |
2700 | int retval; | 2591 | int retval; |
@@ -2716,13 +2607,7 @@ static int idetape_rewind_tape (ide_drive_t *drive) | |||
2716 | return 0; | 2607 | return 0; |
2717 | } | 2608 | } |
2718 | 2609 | ||
2719 | /* | 2610 | /* mtio.h compatible commands should be issued to the chrdev interface. */ |
2720 | * Our special ide-tape ioctl's. | ||
2721 | * | ||
2722 | * Currently there aren't any ioctl's. | ||
2723 | * mtio.h compatible commands should be issued to the character device | ||
2724 | * interface. | ||
2725 | */ | ||
2726 | static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned long arg) | 2611 | static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned long arg) |
2727 | { | 2612 | { |
2728 | idetape_tape_t *tape = drive->driver_data; | 2613 | idetape_tape_t *tape = drive->driver_data; |
@@ -2756,13 +2641,11 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned l | |||
2756 | } | 2641 | } |
2757 | 2642 | ||
2758 | /* | 2643 | /* |
2759 | * idetape_space_over_filemarks is now a bit more complicated than just | 2644 | * The function below is now a bit more complicated than just passing the |
2760 | * passing the command to the tape since we may have crossed some | 2645 | * command to the tape since we may have crossed some filemarks during our |
2761 | * filemarks during our pipelined read-ahead mode. | 2646 | * pipelined read-ahead mode. As a minor side effect, the pipeline enables us to |
2762 | * | 2647 | * support MTFSFM when the filemark is in our internal pipeline even if the tape |
2763 | * As a minor side effect, the pipeline enables us to support MTFSFM when | 2648 | * doesn't support spacing over filemarks in the reverse direction. |
2764 | * the filemark is in our internal pipeline even if the tape doesn't | ||
2765 | * support spacing over filemarks in the reverse direction. | ||
2766 | */ | 2649 | */ |
2767 | static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_count) | 2650 | static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_count) |
2768 | { | 2651 | { |
@@ -2781,10 +2664,7 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c | |||
2781 | } | 2664 | } |
2782 | 2665 | ||
2783 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { | 2666 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
2784 | /* | 2667 | /* its a read-ahead buffer, scan it for crossed filemarks. */ |
2785 | * We have a read-ahead buffer. Scan it for crossed | ||
2786 | * filemarks. | ||
2787 | */ | ||
2788 | tape->merge_stage_size = 0; | 2668 | tape->merge_stage_size = 0; |
2789 | if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags)) | 2669 | if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags)) |
2790 | ++count; | 2670 | ++count; |
@@ -2797,13 +2677,15 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c | |||
2797 | spin_lock_irqsave(&tape->lock, flags); | 2677 | spin_lock_irqsave(&tape->lock, flags); |
2798 | if (tape->first_stage == tape->active_stage) { | 2678 | if (tape->first_stage == tape->active_stage) { |
2799 | /* | 2679 | /* |
2800 | * We have reached the active stage in the read pipeline. | 2680 | * We have reached the active stage in the read |
2801 | * There is no point in allowing the drive to continue | 2681 | * pipeline. There is no point in allowing the |
2802 | * reading any farther, so we stop the pipeline. | 2682 | * drive to continue reading any farther, so we |
2683 | * stop the pipeline. | ||
2803 | * | 2684 | * |
2804 | * This section should be moved to a separate subroutine, | 2685 | * This section should be moved to a separate |
2805 | * because a similar function is performed in | 2686 | * subroutine because similar operations are |
2806 | * __idetape_discard_read_pipeline(), for example. | 2687 | * done in __idetape_discard_read_pipeline(), |
2688 | * for example. | ||
2807 | */ | 2689 | */ |
2808 | tape->next_stage = NULL; | 2690 | tape->next_stage = NULL; |
2809 | spin_unlock_irqrestore(&tape->lock, flags); | 2691 | spin_unlock_irqrestore(&tape->lock, flags); |
@@ -2819,8 +2701,8 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c | |||
2819 | } | 2701 | } |
2820 | 2702 | ||
2821 | /* | 2703 | /* |
2822 | * The filemark was not found in our internal pipeline. | 2704 | * The filemark was not found in our internal pipeline; now we can issue |
2823 | * Now we can issue the space command. | 2705 | * the space command. |
2824 | */ | 2706 | */ |
2825 | switch (mt_op) { | 2707 | switch (mt_op) { |
2826 | case MTFSF: | 2708 | case MTFSF: |
@@ -2843,21 +2725,19 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c | |||
2843 | 2725 | ||
2844 | 2726 | ||
2845 | /* | 2727 | /* |
2846 | * Our character device read / write functions. | 2728 | * Our character device read / write functions. |
2847 | * | 2729 | * |
2848 | * The tape is optimized to maximize throughput when it is transferring | 2730 | * The tape is optimized to maximize throughput when it is transferring an |
2849 | * an integral number of the "continuous transfer limit", which is | 2731 | * integral number of the "continuous transfer limit", which is a parameter of |
2850 | * a parameter of the specific tape (26 KB on my particular tape). | 2732 | * the specific tape (26kB on my particular tape, 32kB for Onstream). |
2851 | * (32 kB for Onstream) | ||
2852 | * | 2733 | * |
2853 | * As of version 1.3 of the driver, the character device provides an | 2734 | * As of version 1.3 of the driver, the character device provides an abstract |
2854 | * abstract continuous view of the media - any mix of block sizes (even 1 | 2735 | * continuous view of the media - any mix of block sizes (even 1 byte) on the |
2855 | * byte) on the same backup/restore procedure is supported. The driver | 2736 | * same backup/restore procedure is supported. The driver will internally |
2856 | * will internally convert the requests to the recommended transfer unit, | 2737 | * convert the requests to the recommended transfer unit, so that an unmatch |
2857 | * so that an unmatch between the user's block size to the recommended | 2738 | * between the user's block size to the recommended size will only result in a |
2858 | * size will only result in a (slightly) increased driver overhead, but | 2739 | * (slightly) increased driver overhead, but will no longer hit performance. |
2859 | * will no longer hit performance. | 2740 | * This is not applicable to Onstream. |
2860 | * This is not applicable to Onstream. | ||
2861 | */ | 2741 | */ |
2862 | static ssize_t idetape_chrdev_read (struct file *file, char __user *buf, | 2742 | static ssize_t idetape_chrdev_read (struct file *file, char __user *buf, |
2863 | size_t count, loff_t *ppos) | 2743 | size_t count, loff_t *ppos) |
@@ -2950,11 +2830,10 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf, | |||
2950 | idetape_init_merge_stage(tape); | 2830 | idetape_init_merge_stage(tape); |
2951 | 2831 | ||
2952 | /* | 2832 | /* |
2953 | * Issue a write 0 command to ensure that DSC handshake | 2833 | * Issue a write 0 command to ensure that DSC handshake is |
2954 | * is switched from completion mode to buffer available | 2834 | * switched from completion mode to buffer available mode. No |
2955 | * mode. | 2835 | * point in issuing this if DSC overlap isn't supported, some |
2956 | * No point in issuing this if DSC overlap isn't supported, | 2836 | * drives (Seagate STT3401A) will return an error. |
2957 | * some drives (Seagate STT3401A) will return an error. | ||
2958 | */ | 2837 | */ |
2959 | if (drive->dsc_overlap) { | 2838 | if (drive->dsc_overlap) { |
2960 | ssize_t retval = idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, 0, tape->merge_stage->bh); | 2839 | ssize_t retval = idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, 0, tape->merge_stage->bh); |
@@ -3045,9 +2924,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) | |||
3045 | 2924 | ||
3046 | debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n", | 2925 | debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n", |
3047 | mt_op, mt_count); | 2926 | mt_op, mt_count); |
3048 | /* | 2927 | /* Commands which need our pipelined read-ahead stages. */ |
3049 | * Commands which need our pipelined read-ahead stages. | ||
3050 | */ | ||
3051 | switch (mt_op) { | 2928 | switch (mt_op) { |
3052 | case MTFSF: | 2929 | case MTFSF: |
3053 | case MTFSFM: | 2930 | case MTFSFM: |
@@ -3235,9 +3112,6 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive) | |||
3235 | tape->drv_write_prot = (pc.buffer[2] & 0x80) >> 7; | 3112 | tape->drv_write_prot = (pc.buffer[2] & 0x80) >> 7; |
3236 | } | 3113 | } |
3237 | 3114 | ||
3238 | /* | ||
3239 | * Our character device open function. | ||
3240 | */ | ||
3241 | static int idetape_chrdev_open (struct inode *inode, struct file *filp) | 3115 | static int idetape_chrdev_open (struct inode *inode, struct file *filp) |
3242 | { | 3116 | { |
3243 | unsigned int minor = iminor(inode), i = minor & ~0xc0; | 3117 | unsigned int minor = iminor(inode), i = minor & ~0xc0; |
@@ -3304,9 +3178,7 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp) | |||
3304 | } | 3178 | } |
3305 | } | 3179 | } |
3306 | 3180 | ||
3307 | /* | 3181 | /* Lock the tape drive door so user can't eject. */ |
3308 | * Lock the tape drive door so user can't eject. | ||
3309 | */ | ||
3310 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { | 3182 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
3311 | if (idetape_create_prevent_cmd(drive, &pc, 1)) { | 3183 | if (idetape_create_prevent_cmd(drive, &pc, 1)) { |
3312 | if (!idetape_queue_pc_tail(drive, &pc)) { | 3184 | if (!idetape_queue_pc_tail(drive, &pc)) { |
@@ -3341,9 +3213,6 @@ static void idetape_write_release (ide_drive_t *drive, unsigned int minor) | |||
3341 | idetape_flush_tape_buffers(drive); | 3213 | idetape_flush_tape_buffers(drive); |
3342 | } | 3214 | } |
3343 | 3215 | ||
3344 | /* | ||
3345 | * Our character device release function. | ||
3346 | */ | ||
3347 | static int idetape_chrdev_release (struct inode *inode, struct file *filp) | 3216 | static int idetape_chrdev_release (struct inode *inode, struct file *filp) |
3348 | { | 3217 | { |
3349 | struct ide_tape_obj *tape = ide_tape_f(filp); | 3218 | struct ide_tape_obj *tape = ide_tape_f(filp); |
@@ -3500,9 +3369,6 @@ static void idetape_add_settings (ide_drive_t *drive) | |||
3500 | { | 3369 | { |
3501 | idetape_tape_t *tape = drive->driver_data; | 3370 | idetape_tape_t *tape = drive->driver_data; |
3502 | 3371 | ||
3503 | /* | ||
3504 | * drive setting name read/write data type min max mul_factor div_factor data pointer set function | ||
3505 | */ | ||
3506 | ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, | 3372 | ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, |
3507 | 1, 2, (u16 *)&tape->caps[16], NULL); | 3373 | 1, 2, (u16 *)&tape->caps[16], NULL); |
3508 | ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); | 3374 | ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); |
@@ -3529,16 +3395,15 @@ static inline void idetape_add_settings(ide_drive_t *drive) { ; } | |||
3529 | #endif | 3395 | #endif |
3530 | 3396 | ||
3531 | /* | 3397 | /* |
3532 | * ide_setup is called to: | 3398 | * The function below is called to: |
3533 | * | 3399 | * |
3534 | * 1. Initialize our various state variables. | 3400 | * 1. Initialize our various state variables. |
3535 | * 2. Ask the tape for its capabilities. | 3401 | * 2. Ask the tape for its capabilities. |
3536 | * 3. Allocate a buffer which will be used for data | 3402 | * 3. Allocate a buffer which will be used for data transfer. The buffer size |
3537 | * transfer. The buffer size is chosen based on | 3403 | * is chosen based on the recommendation which we received in step 2. |
3538 | * the recommendation which we received in step (2). | ||
3539 | * | 3404 | * |
3540 | * Note that at this point ide.c already assigned us an irq, so that | 3405 | * Note that at this point ide.c already assigned us an irq, so that we can |
3541 | * we can queue requests here and wait for their completion. | 3406 | * queue requests here and wait for their completion. |
3542 | */ | 3407 | */ |
3543 | static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor) | 3408 | static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor) |
3544 | { | 3409 | { |
@@ -3572,7 +3437,7 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor) | |||
3572 | set_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags); | 3437 | set_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags); |
3573 | 3438 | ||
3574 | tape->min_pipeline = tape->max_pipeline = tape->max_stages = 10; | 3439 | tape->min_pipeline = tape->max_pipeline = tape->max_stages = 10; |
3575 | 3440 | ||
3576 | idetape_get_inquiry_results(drive); | 3441 | idetape_get_inquiry_results(drive); |
3577 | idetape_get_mode_sense_results(drive); | 3442 | idetape_get_mode_sense_results(drive); |
3578 | ide_tape_get_bsize_from_bdesc(drive); | 3443 | ide_tape_get_bsize_from_bdesc(drive); |
@@ -3595,9 +3460,7 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor) | |||
3595 | 3460 | ||
3596 | tape->max_stages = speed * 1000 * 10 / tape->stage_size; | 3461 | tape->max_stages = speed * 1000 * 10 / tape->stage_size; |
3597 | 3462 | ||
3598 | /* | 3463 | /* Limit memory use for pipeline to 10% of physical memory */ |
3599 | * Limit memory use for pipeline to 10% of physical memory | ||
3600 | */ | ||
3601 | si_meminfo(&si); | 3464 | si_meminfo(&si); |
3602 | if (tape->max_stages * tape->stage_size > si.totalram * si.mem_unit / 10) | 3465 | if (tape->max_stages * tape->stage_size > si.totalram * si.mem_unit / 10) |
3603 | tape->max_stages = si.totalram * si.mem_unit / (10 * tape->stage_size); | 3466 | tape->max_stages = si.totalram * si.mem_unit / (10 * tape->stage_size); |
@@ -3617,8 +3480,8 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor) | |||
3617 | t = t1; | 3480 | t = t1; |
3618 | 3481 | ||
3619 | /* | 3482 | /* |
3620 | * Ensure that the number we got makes sense; limit | 3483 | * Ensure that the number we got makes sense; limit it within |
3621 | * it within IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. | 3484 | * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. |
3622 | */ | 3485 | */ |
3623 | tape->best_dsc_rw_freq = max_t(unsigned long, | 3486 | tape->best_dsc_rw_freq = max_t(unsigned long, |
3624 | min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), | 3487 | min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), |
@@ -3706,9 +3569,7 @@ static ide_driver_t idetape_driver = { | |||
3706 | #endif | 3569 | #endif |
3707 | }; | 3570 | }; |
3708 | 3571 | ||
3709 | /* | 3572 | /* Our character device supporting functions, passed to register_chrdev. */ |
3710 | * Our character device supporting functions, passed to register_chrdev. | ||
3711 | */ | ||
3712 | static const struct file_operations idetape_fops = { | 3573 | static const struct file_operations idetape_fops = { |
3713 | .owner = THIS_MODULE, | 3574 | .owner = THIS_MODULE, |
3714 | .read = idetape_chrdev_read, | 3575 | .read = idetape_chrdev_read, |