OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [before_ORP/] [uclinux/] [uClinux-2.0.x/] [drivers/] [block/] [ide-tape.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * linux/drivers/block/ide-tape.h       Version 1.9 - ALPHA     Nov   5, 1996
3
 *
4
 * Copyright (C) 1995, 1996 Gadi Oxman <gadio@netvision.net.il>
5
 */
6
 
7
/*
8
 * Include file for the IDE ATAPI streaming tape driver.
9
 *
10
 * This file contains various ide-tape related structures and function
11
 * prototypes which are already used in ide.h.
12
 *
13
 * The various compile time options are described below.
14
 */
15
 
16
#ifndef IDETAPE_H
17
#define IDETAPE_H 
18
 
19
/**************************** Tunable parameters *****************************/
20
 
21
/*
22
 *      This is probably the most important configuration option.
23
 *
24
 *      Pipelined operation mode has the potential to maximize the
25
 *      performance of the driver and thus to saturate the throughput
26
 *      to the maximum value supported by the tape.
27
 *
28
 *      In pipelined mode we are servicing requests without blocking the
29
 *      user backup program. For example, on a write request, we will add it
30
 *      to the pipeline and return without waiting for it to complete. The
31
 *      user program will then have enough time to prepare the next blocks
32
 *      while the tape is still busy working on the previous requests.
33
 *
34
 *      Pipelined operation mode is enabled by default, but since it has a
35
 *      few downfalls as well, you may wish to disable it.
36
 *      Further explanation of pipelined mode is available in ide-tape.c .
37
 */
38
 
39
#define IDETAPE_PIPELINE        1
40
 
41
/*
42
 *      Pipelined mode parameters.
43
 *
44
 *      We try to use the minimum number of stages which is enough to
45
 *      keep the tape constantly streaming. To accomplish that, we implement
46
 *      a feedback loop around the maximum number of stages:
47
 *
48
 *      We start from MIN maximum stages (we will not even use MIN stages
49
 *      if we don't need them), increment it by RATE*(MAX-MIN)
50
 *      whenever we sense that the pipeline is empty, until we reach
51
 *      the optimum value or until we reach MAX.
52
 */
53
 
54
#define IDETAPE_MIN_PIPELINE_STAGES             100
55
#define IDETAPE_MAX_PIPELINE_STAGES             200
56
#define IDETAPE_INCREASE_STAGES_RATE            20
57
 
58
/*
59
 *      Assuming the tape shares an interface with another device, the default
60
 *      behavior is to service our pending pipeline requests as soon as
61
 *      possible, but to gracefully postpone them in favor of the other device
62
 *      when the tape is busy. This has the potential to maximize our
63
 *      throughput and in the same time, to make efficient use of the IDE bus.
64
 *
65
 *      Note that when we transfer data to / from the tape, we co-operate with
66
 *      the relatively fast tape buffers and the tape will perform the
67
 *      actual media access in the background, without blocking the IDE
68
 *      bus. This means that as long as the maximum IDE bus throughput is much
69
 *      higher than the sum of our maximum throughput and the maximum
70
 *      throughput of the other device, we should probably leave the default
71
 *      behavior.
72
 *
73
 *      However, if it is still desired to give the other device a share even
74
 *      in our own (small) bus bandwidth, you can set IDETAPE_LOW_TAPE_PRIORITY
75
 *      to 1. This will let the other device finish *all* its pending requests
76
 *      before we even check if we can service our next pending request.
77
 */
78
 
79
#define IDETAPE_LOW_TAPE_PRIORITY               0
80
 
81
/*
82
 *      It seems that dynamically allocating buffers of about 32KB
83
 *      each is doomed to fail, unless we are in or very near the
84
 *      initialization stage. Take care when changing this value, as it
85
 *      is now optimized with the design of kmalloc, so that we will not
86
 *      allocate parts of a page. Setting the size to 512 bytes, for example,
87
 *      would cause kmalloc to allocate for us 1024 bytes, and to
88
 *      unnecessarily waste double amount of memory.
89
 */
90
 
91
#if PAGE_SIZE == 4096
92
        #define IDETAPE_ALLOCATION_BLOCK                500
93
#elif PAGE_SIZE == 8192
94
        #define IDETAPE_ALLOCATION_BLOCK                496
95
#else /* ??? Not defined by linux/mm/kmalloc.c */
96
        #define IDETAPE_ALLOCATION_BLOCK                512
97
#endif
98
 
99
/*
100
 *      ide-tape currently uses two continuous buffers, each of the size of
101
 *      one stage. By default, those buffers are allocated at initialization
102
 *      time and never released, since dynamic allocation of pages bigger
103
 *      than PAGE_SIZE may fail as memory becomes fragmented.
104
 *
105
 *      This results in about 100 KB memory usage when the tape is idle.
106
 *      Setting IDETAPE_MINIMIZE_IDLE_MEMORY_USAGE to 1 will let ide-tape
107
 *      to dynamically allocate those buffers, resulting in about 20 KB idle
108
 *      memory usage.
109
 */
110
 
111
#define IDETAPE_MINIMIZE_IDLE_MEMORY_USAGE      0
112
 
113
/*
114
 *      The following are used to debug the driver:
115
 *
116
 *      Setting IDETAPE_DEBUG_LOG to 1 will log driver flow control.
117
 *      Setting IDETAPE_DEBUG_BUGS to 1 will enable self-sanity checks in
118
 *      some places.
119
 *
120
 *      Setting them to 0 will restore normal operation mode:
121
 *
122
 *              1.      Disable logging normal successful operations.
123
 *              2.      Disable self-sanity checks.
124
 *              3.      Errors will still be logged, of course.
125
 *
126
 *      All the #if DEBUG code will be removed some day, when the driver
127
 *      is verified to be stable enough. This will make it much more
128
 *      esthetic.
129
 */
130
 
131
#define IDETAPE_DEBUG_LOG               0
132
#define IDETAPE_DEBUG_BUGS              1
133
 
134
/*
135
 *      After each failed packet command we issue a request sense command
136
 *      and retry the packet command IDETAPE_MAX_PC_RETRIES times.
137
 *
138
 *      Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
139
 */
140
 
141
#define IDETAPE_MAX_PC_RETRIES  3
142
 
143
/*
144
 *      With each packet command, we allocate a buffer of
145
 *      IDETAPE_TEMP_BUFFER_SIZE bytes. This is used for several packet
146
 *      commands (Not for READ/WRITE commands).
147
 *
148
 *      The default below is too high - We should be using around 100 bytes
149
 *      typically, but I didn't check all the cases, so I rather be on the
150
 *      safe size.
151
 */
152
 
153
#define IDETAPE_TEMP_BUFFER_SIZE 256
154
 
155
/*
156
 *      In various places in the driver, we need to allocate storage
157
 *      for packet commands and requests, which will remain valid while
158
 *      we leave the driver to wait for an interrupt or a timeout event.
159
 *
160
 *      In the corresponding ide_drive_t structure, we pre-allocate storage
161
 *      for IDETAPE_PC_STACK packet commands and requests. This storage is
162
 *      used as a circular array - Each time we reach the last entry, we
163
 *      warp around to the first.
164
 *
165
 *      It is crucial that we have enough entries for the maximum number
166
 *      of packet commands / sub-requests which we need to allocate during
167
 *      the handling of a specific request.
168
 *
169
 *      Follows a worse case calculation of the required storage, with a
170
 *      large safety margin.
171
 */
172
 
173
#define IDETAPE_PC_STACK        20+IDETAPE_MAX_PC_RETRIES
174
 
175
/*
176
 *      DSC polling parameters.
177
 *
178
 *      Polling for DSC (a single bit in the status register) is a very
179
 *      important function in ide-tape. There are two cases in which we
180
 *      poll for DSC:
181
 *
182
 *      1.      Before a read/write packet command, to ensure that we
183
 *              can transfer data from/to the tape's data buffers, without
184
 *              causing an actual media access. In case the tape is not
185
 *              ready yet, we take out our request from the device
186
 *              request queue, so that ide.c will service requests from
187
 *              the other device on the same interface meanwhile.
188
 *
189
 *              We can now automatically select the "best" polling frequency.
190
 *              Have a look at IDETAPE_ANTICIPATE_READ_WRITE_DSC below.
191
 *
192
 *              In case you don't want to use the automatic selection,
193
 *              choose it to be relatively fast. The default fallback
194
 *              frequency is 1/50 msec.
195
 *
196
 *      2.      After the successful initialization of a "media access
197
 *              packet command", which is a command which can take a long
198
 *              time to complete (it can be several seconds or even an hour).
199
 *
200
 *              Again, we postpone our request in the middle to free the bus
201
 *              for the other device. The polling frequency here should be
202
 *              lower than the read/write frequency since those media access
203
 *              commands are slow. We start from a "fast" frequency -
204
 *              IDETAPE_DSC_FAST_MEDIA_ACCESS_FREQUENCY (one second), and
205
 *              if we don't receive DSC after IDETAPE_FAST_SLOW_THRESHOLD
206
 *              (5 minutes), we switch it to a lower frequency -
207
 *              IDETAPE_DSC_SLOW_MEDIA_ACCESS_FREQUENCY (1 minute).
208
 *
209
 *      We also set a timeout for the timer, in case something goes wrong.
210
 *      The timeout should be longer then the maximum execution time of a
211
 *      tape operation. I still have to measure exactly how much time does
212
 *      it take to space over a far filemark, etc. It seemed that 15 minutes
213
 *      was way too low, so I am meanwhile setting it to a rather large
214
 *      timeout - 2 Hours ...
215
 *
216
 */
217
 
218
/*
219
 *      Setting IDETAPE_ANTICIPATE_READ_WRITE_DSC to 1 will allow ide-tape
220
 *      to cleverly select the lowest possible frequency which will
221
 *      not affect performance, based on the tape parameters and our operation
222
 *      mode. This has potential to dramatically decrease our polling load
223
 *      on Linux.
224
 *
225
 *      However, for the cases in which our calculation fails, setting
226
 *      the following option to 0 will force the use of the "fallback"
227
 *      polling period defined below (defaults to 50 msec).
228
 *
229
 *      In any case, the frequency will be between the "lowest" value
230
 *      to the "fallback" value, to ensure that our selected "best" frequency
231
 *      is reasonable.
232
 */
233
 
234
#define IDETAPE_ANTICIPATE_READ_WRITE_DSC       1
235
 
236
/*
237
 *      The following parameter is used to select the point in the internal
238
 *      tape fifo in which we will start to refill the buffer. Decreasing
239
 *      the following parameter will improve the system's latency and
240
 *      interactive response, while using a high value might improve sytem
241
 *      throughput.
242
 */
243
#define IDETAPE_FIFO_THRESHOLD                  2
244
 
245
/*
246
 *      DSC timings.
247
 */
248
 
249
#define IDETAPE_DSC_READ_WRITE_FALLBACK_FREQUENCY   5*HZ/100    /* 50 msec */
250
#define IDETAPE_DSC_READ_WRITE_LOWEST_FREQUENCY 40*HZ/100       /* 400 msec */
251
#define IDETAPE_DSC_FAST_MEDIA_ACCESS_FREQUENCY 1*HZ            /* 1 second */
252
#define IDETAPE_FAST_SLOW_THRESHOLD             5*60*HZ         /* 5 minutes */
253
#define IDETAPE_DSC_SLOW_MEDIA_ACCESS_FREQUENCY 60*HZ           /* 1 minute */
254
#define IDETAPE_DSC_TIMEOUT                     2*60*60*HZ      /* 2 hours */
255
 
256
/*************************** End of tunable parameters ***********************/
257
 
258
/*
259
 *      Definitions which are already needed in ide.h
260
 */
261
 
262
/*
263
 *      Current character device data transfer direction.
264
 */
265
 
266
typedef enum {idetape_direction_none,idetape_direction_read,idetape_direction_write} chrdev_direction_t;
267
 
268
struct ide_drive_s;                             /* Forward declaration - Will be defined later in ide.h */
269
typedef void (idetape_pc_completed_t)(struct ide_drive_s *);
270
 
271
/*
272
 *      Our view of a packet command.
273
 */
274
 
275
typedef struct idetape_packet_command_s {
276
        byte c [12];                            /* Actual packet bytes */
277
 
278
        byte retries;                           /* On each retry, we increment retries */
279
        byte error;                             /* Error code */
280
        byte abort;                             /* Set when an error is considered normal - We won't retry */
281
        byte wait_for_dsc;                      /* 1 When polling for DSC on a media access command */
282
        byte dma_recommended;                   /* 1 when we prefer to use DMA if possible */
283
        byte dma_in_progress;                   /* 1 while DMA in progress */
284
        byte dma_error;                         /* 1 when encountered problem during DMA */
285
        unsigned long request_transfer;         /* Bytes to transfer */
286
        unsigned long actually_transferred;     /* Bytes actually transferred */
287
        unsigned long buffer_size;              /* Size of our data buffer */
288
        byte *buffer;                           /* Data buffer */
289
        byte *current_position;                 /* Pointer into the above buffer */
290
        byte writing;                           /* Data direction */
291
        idetape_pc_completed_t *callback;       /* Called when this packet command is completed */
292
        byte temp_buffer [IDETAPE_TEMP_BUFFER_SIZE];    /* Temporary buffer */
293
} idetape_packet_command_t;
294
 
295
/*
296
 *      Capabilities and Mechanical Status Page
297
 */
298
 
299
typedef struct {
300
        unsigned page_code      :6;     /* Page code - Should be 0x2a */
301
        unsigned reserved1_67   :2;
302
        byte page_length;               /* Page Length - Should be 0x12 */
303
        byte reserved2;
304
        byte reserved3;
305
        unsigned ro             :1;     /* Read Only Mode */
306
        unsigned reserved4_1234 :4;
307
        unsigned sprev          :1;     /* Supports SPACE in the reverse direction */
308
        unsigned reserved4_67   :2;
309
        unsigned reserved5_012  :3;
310
        unsigned efmt           :1;     /* Supports ERASE command initiated formatting */
311
        unsigned reserved5_4    :1;
312
        unsigned qfa            :1;     /* Supports the QFA two partition formats */
313
        unsigned reserved5_67   :2;
314
        unsigned lock           :1;     /* Supports locking the volume */
315
        unsigned locked         :1;     /* The volume is locked */
316
        unsigned prevent        :1;     /* The device defaults in the prevent state after power up */
317
        unsigned eject          :1;     /* The device can eject the volume */
318
        unsigned reserved6_45   :2;     /* Reserved */
319
        unsigned ecc            :1;     /* Supports error correction */
320
        unsigned cmprs          :1;     /* Supports data compression */
321
        unsigned reserved7_0    :1;
322
        unsigned blk512         :1;     /* Supports 512 bytes block size */
323
        unsigned blk1024        :1;     /* Supports 1024 bytes block size */
324
        unsigned reserved7_3_6  :4;
325
        unsigned slowb          :1;     /* The device restricts the byte count for PIO */
326
                                        /* transfers for slow buffer memory ??? */
327
        unsigned short max_speed;       /* Maximum speed supported in KBps */
328
        byte reserved10;
329
        byte reserved11;
330
        unsigned short ctl;             /* Continuous Transfer Limit in blocks */
331
        unsigned short speed;           /* Current Speed, in KBps */
332
        unsigned short buffer_size;     /* Buffer Size, in 512 bytes */
333
        byte reserved18;
334
        byte reserved19;
335
} idetape_capabilities_page_t;
336
 
337
/*
338
 *      A pipeline stage contains several small buffers of type
339
 *      idetape_buffer_head_t. This is necessary since dynamical allocation
340
 *      of large (32 KB or so) continuous memory blocks will usually fail.
341
 */
342
 
343
typedef struct idetape_buffer_head_s {
344
        char *data;                                     /* Pointer to data (512 bytes by default) */
345
        struct idetape_buffer_head_s *next;
346
} idetape_buffer_head_t;
347
 
348
/*
349
 *      A pipeline stage.
350
 *
351
 *      In a pipeline stage we have a request, pointer to a list of small
352
 *      buffers, and pointers to the near stages.
353
 */
354
 
355
typedef struct idetape_pipeline_stage_s {
356
        struct request rq;                              /* The corresponding request */
357
        idetape_buffer_head_t *bh;                      /* The data buffers */
358
        struct idetape_pipeline_stage_s *next,*prev;    /* Pointers to the next and previous stages */
359
} idetape_pipeline_stage_t;
360
 
361
/*
362
 *      Most of our global data which we need to save even as we leave the
363
 *      driver due to an interrupt or a timer event is stored in a variable
364
 *      of type tape_info, defined below.
365
 *
366
 *      Additional global variables which provide the link between the
367
 *      character device interface to this structure are defined in
368
 *      ide-tape.c
369
 */
370
 
371
typedef struct {
372
 
373
        /*
374
         *      Since a typical character device operation requires more
375
         *      than one packet command, we provide here enough memory
376
         *      for the maximum of interconnected packet commands.
377
         *      The packet commands are stored in the circular array pc_stack.
378
         *      pc_stack_index points to the last used entry, and warps around
379
         *      to the start when we get to the last array entry.
380
         *
381
         *      pc points to the current processed packet command.
382
         *
383
         *      failed_pc points to the last failed packet command, or contains
384
         *      NULL if we do not need to retry any packet command. This is
385
         *      required since an additional packet command is needed before the
386
         *      retry, to get detailed information on what went wrong.
387
         */
388
 
389
        idetape_packet_command_t *pc;           /* Current packet command */
390
        idetape_packet_command_t *failed_pc;    /* Last failed packet command */
391
        idetape_packet_command_t pc_stack [IDETAPE_PC_STACK]; /* Packet command stack */
392
        byte pc_stack_index;                    /* Next free packet command storage space */
393
 
394
        /*
395
         *      The Linux ide driver basically traverses the request lists
396
         *      of the ide block devices, finds the next request, completes
397
         *      it, and passes to the next one. This is done in ide_do_request.
398
         *
399
         *      In this regard, ide-tape.c is fully compatible with the rest of
400
         *      the ide driver - From the point of view of ide.c, we are just
401
         *      another ide block device which receives requests and completes
402
         *      them.
403
         *
404
         *      However, our requests don't originate in the buffer cache but
405
         *      rather in ide-tape.c itself. Here we provide safe storage for
406
         *      such requests.
407
         */
408
 
409
        struct request rq_stack [IDETAPE_PC_STACK];
410
        byte rq_stack_index;                    /* We implement a circular array */
411
 
412
        /*
413
         *      While polling for DSC we use postponed_rq to postpone the
414
         *      current request so that ide.c will be able to service
415
         *      pending requests on the other device. Note that at most
416
         *      we will have only one DSC (usually data transfer) request
417
         *      in the device request queue. Additional request can be
418
         *      queued in our internal pipeline, but they will be visible
419
         *      to ide.c only one at a time.
420
         */
421
 
422
        struct request *postponed_rq;
423
 
424
        /*
425
         *      DSC polling variables.
426
         */
427
 
428
        byte dsc_count;                         /* We received DSC dsc_count times in a row */
429
        unsigned long dsc_polling_start;        /* The time in which we started polling for DSC */
430
        struct timer_list dsc_timer;            /* Timer used to poll for dsc */
431
 
432
        /*
433
         *      We can now be much more clever in our selection of the
434
         *      read/write polling frequency. This is used along with
435
         *      the compile time option IDETAPE_ANTICIPATE_DSC.
436
         */
437
 
438
        unsigned long best_dsc_rw_frequency;    /* Read/Write dsc polling frequency */
439
 
440
        unsigned long dsc_polling_frequency;    /* The current polling frequency */
441
        unsigned long dsc_timeout;              /* Maximum waiting time */
442
        byte dsc_received;                      /* Set when we receive DSC */
443
 
444
        byte request_status;
445
        byte last_status;                       /* Contents of the tape status register */
446
                                                /* before the current request (saved for us */
447
                                                /* by ide.c) */
448
        /*
449
         *      After an ATAPI software reset, the status register will be
450
         *      locked, and thus we need to ignore it when checking DSC for
451
         *      the first time.
452
         */
453
 
454
        byte reset_issued;
455
 
456
        /* Position information */
457
 
458
        byte partition_num;                     /* Currently not used */
459
        unsigned long block_address;            /* Current block */
460
        byte block_address_valid;               /* 0 When the tape position is unknown */
461
                                                /* (To the tape or to us) */
462
        /* Last error information */
463
 
464
        byte sense_key,asc,ascq;
465
 
466
        /* Character device operation */
467
 
468
        chrdev_direction_t chrdev_direction;    /* Current character device data transfer direction */
469
        int filemark;                           /* Currently on a filemark */
470
        byte busy;                              /* Device already opened */
471
 
472
        /* Device information */
473
 
474
        unsigned short tape_block_size;                 /* Usually 512 or 1024 bytes */
475
        idetape_capabilities_page_t capabilities;       /* Copy of the tape's Capabilities and Mechanical Page */
476
 
477
        /*
478
         *      Active data transfer request parameters.
479
         *
480
         *      At most, there is only one ide-tape originated data transfer
481
         *      request in the device request queue. This allows ide.c to
482
         *      easily service requests from the other device when we
483
         *      postpone our active request. In the pipelined operation
484
         *      mode, we use our internal pipeline structure to hold
485
         *      more data requests.
486
         *
487
         *      The data buffer size is chosen based on the tape's
488
         *      recommendation.
489
         */
490
 
491
        struct request *active_data_request;    /* Pointer to the request which is waiting in the device request queue */
492
        char *data_buffer;                      /* The corresponding data buffer (for read/write requests) */
493
        int data_buffer_size;                   /* Data buffer size (chosen based on the tape's recommendation */
494
 
495
        char *merge_buffer;                     /* Temporary buffer for user <-> kernel space data transfer */
496
        int merge_buffer_offset;
497
        int merge_buffer_size;
498
 
499
        /*
500
         *      Pipeline parameters.
501
         *
502
         *      To accomplish non-pipelined mode, we simply set the following
503
         *      variables to zero (or NULL, where appropriate).
504
         */
505
 
506
        int current_number_of_stages;           /* Number of currently used stages */
507
        int max_number_of_stages;               /* We will not allocate more than this number of stages */
508
        idetape_pipeline_stage_t *first_stage;  /* The first stage which will be removed from the pipeline */
509
        idetape_pipeline_stage_t *active_stage; /* The currently active stage */
510
        idetape_pipeline_stage_t *next_stage;   /* Will be serviced after the currently active request */
511
        idetape_pipeline_stage_t *last_stage;   /* New requests will be added to the pipeline here */
512
        int error_in_pipeline_stage;            /* Set when an error was detected in one of the pipeline stages */
513
 
514
        int drq_interrupt;
515
 
516
} idetape_tape_t;
517
 
518
/*
519
 *      The following is used to have a quick look at the tape's status
520
 *      register between requests of the other device.
521
 */
522
 
523
#define POLL_HWIF_TAPE_DRIVE                                                    \
524
        if (hwif->tape_drive != NULL) {                                         \
525
                if (hwif->tape_drive->tape.request_status) {                    \
526
                        SELECT_DRIVE(hwif,hwif->tape_drive);                    \
527
                        hwif->tape_drive->tape.last_status=GET_STAT();          \
528
                        hwif->tape_drive->tape.request_status=0;         \
529
                }                                                               \
530
        }
531
 
532
#endif /* IDETAPE_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.