Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2000 Jens Axboe <axboe@suse.de>
0003  * Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com>
0004  *
0005  * May be copied or modified under the terms of the GNU General Public
0006  * License.  See linux/COPYING for more information.
0007  *
0008  * Packet writing layer for ATAPI and SCSI CD-R, CD-RW, DVD-R, and
0009  * DVD-RW devices.
0010  *
0011  */
0012 #ifndef __PKTCDVD_H
0013 #define __PKTCDVD_H
0014 
0015 #include <linux/blkdev.h>
0016 #include <linux/completion.h>
0017 #include <linux/cdrom.h>
0018 #include <linux/kobject.h>
0019 #include <linux/sysfs.h>
0020 #include <linux/mempool.h>
0021 #include <uapi/linux/pktcdvd.h>
0022 
0023 /* default bio write queue congestion marks */
0024 #define PKT_WRITE_CONGESTION_ON    10000
0025 #define PKT_WRITE_CONGESTION_OFF   9000
0026 
0027 
0028 struct packet_settings
0029 {
0030     __u32           size;       /* packet size in (512 byte) sectors */
0031     __u8            fp;     /* fixed packets */
0032     __u8            link_loss;  /* the rest is specified
0033                          * as per Mt Fuji */
0034     __u8            write_type;
0035     __u8            track_mode;
0036     __u8            block_mode;
0037 };
0038 
0039 /*
0040  * Very crude stats for now
0041  */
0042 struct packet_stats
0043 {
0044     unsigned long       pkt_started;
0045     unsigned long       pkt_ended;
0046     unsigned long       secs_w;
0047     unsigned long       secs_rg;
0048     unsigned long       secs_r;
0049 };
0050 
0051 struct packet_cdrw
0052 {
0053     struct list_head    pkt_free_list;
0054     struct list_head    pkt_active_list;
0055     spinlock_t      active_list_lock; /* Serialize access to pkt_active_list */
0056     struct task_struct  *thread;
0057     atomic_t        pending_bios;
0058 };
0059 
0060 /*
0061  * Switch to high speed reading after reading this many kilobytes
0062  * with no interspersed writes.
0063  */
0064 #define HI_SPEED_SWITCH 512
0065 
0066 struct packet_iosched
0067 {
0068     atomic_t        attention;  /* Set to non-zero when queue processing is needed */
0069     int         writing;    /* Non-zero when writing, zero when reading */
0070     spinlock_t      lock;       /* Protecting read/write queue manipulations */
0071     struct bio_list     read_queue;
0072     struct bio_list     write_queue;
0073     sector_t        last_write; /* The sector where the last write ended */
0074     int         successive_reads;
0075 };
0076 
0077 /*
0078  * 32 buffers of 2048 bytes
0079  */
0080 #if (PAGE_SIZE % CD_FRAMESIZE) != 0
0081 #error "PAGE_SIZE must be a multiple of CD_FRAMESIZE"
0082 #endif
0083 #define PACKET_MAX_SIZE     128
0084 #define FRAMES_PER_PAGE     (PAGE_SIZE / CD_FRAMESIZE)
0085 #define PACKET_MAX_SECTORS  (PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
0086 
0087 enum packet_data_state {
0088     PACKET_IDLE_STATE,          /* Not used at the moment */
0089     PACKET_WAITING_STATE,           /* Waiting for more bios to arrive, so */
0090                         /* we don't have to do as much */
0091                         /* data gathering */
0092     PACKET_READ_WAIT_STATE,         /* Waiting for reads to fill in holes */
0093     PACKET_WRITE_WAIT_STATE,        /* Waiting for the write to complete */
0094     PACKET_RECOVERY_STATE,          /* Recover after read/write errors */
0095     PACKET_FINISHED_STATE,          /* After write has finished */
0096 
0097     PACKET_NUM_STATES           /* Number of possible states */
0098 };
0099 
0100 /*
0101  * Information needed for writing a single packet
0102  */
0103 struct pktcdvd_device;
0104 
0105 struct packet_data
0106 {
0107     struct list_head    list;
0108 
0109     spinlock_t      lock;       /* Lock protecting state transitions and */
0110                         /* orig_bios list */
0111 
0112     struct bio_list     orig_bios;  /* Original bios passed to pkt_make_request */
0113                         /* that will be handled by this packet */
0114     int         write_size; /* Total size of all bios in the orig_bios */
0115                         /* list, measured in number of frames */
0116 
0117     struct bio      *w_bio;     /* The bio we will send to the real CD */
0118                         /* device once we have all data for the */
0119                         /* packet we are going to write */
0120     sector_t        sector;     /* First sector in this packet */
0121     int         frames;     /* Number of frames in this packet */
0122 
0123     enum packet_data_state  state;      /* Current state */
0124     atomic_t        run_sm;     /* Incremented whenever the state */
0125                         /* machine needs to be run */
0126     long            sleep_time; /* Set this to non-zero to make the state */
0127                         /* machine run after this many jiffies. */
0128 
0129     atomic_t        io_wait;    /* Number of pending IO operations */
0130     atomic_t        io_errors;  /* Number of read/write errors during IO */
0131 
0132     struct bio      *r_bios[PACKET_MAX_SIZE]; /* bios to use during data gathering */
0133     struct page     *pages[PACKET_MAX_SIZE / FRAMES_PER_PAGE];
0134 
0135     int         cache_valid;    /* If non-zero, the data for the zone defined */
0136                         /* by the sector variable is completely cached */
0137                         /* in the pages[] vector. */
0138 
0139     int         id;     /* ID number for debugging */
0140     struct pktcdvd_device   *pd;
0141 };
0142 
0143 struct pkt_rb_node {
0144     struct rb_node      rb_node;
0145     struct bio      *bio;
0146 };
0147 
0148 struct packet_stacked_data
0149 {
0150     struct bio      *bio;       /* Original read request bio */
0151     struct pktcdvd_device   *pd;
0152 };
0153 #define PSD_POOL_SIZE       64
0154 
0155 struct pktcdvd_device
0156 {
0157     struct block_device *bdev;      /* dev attached */
0158     dev_t           pkt_dev;    /* our dev */
0159     char            name[20];
0160     struct packet_settings  settings;
0161     struct packet_stats stats;
0162     int         refcnt;     /* Open count */
0163     int         write_speed;    /* current write speed, kB/s */
0164     int         read_speed; /* current read speed, kB/s */
0165     unsigned long       offset;     /* start offset */
0166     __u8            mode_offset;    /* 0 / 8 */
0167     __u8            type;
0168     unsigned long       flags;
0169     __u16           mmc3_profile;
0170     __u32           nwa;        /* next writable address */
0171     __u32           lra;        /* last recorded address */
0172     struct packet_cdrw  cdrw;
0173     wait_queue_head_t   wqueue;
0174 
0175     spinlock_t      lock;       /* Serialize access to bio_queue */
0176     struct rb_root      bio_queue;  /* Work queue of bios we need to handle */
0177     int         bio_queue_size; /* Number of nodes in bio_queue */
0178     bool            congested;  /* Someone is waiting for bio_queue_size
0179                          * to drop. */
0180     sector_t        current_sector; /* Keep track of where the elevator is */
0181     atomic_t        scan_queue; /* Set to non-zero when pkt_handle_queue */
0182                         /* needs to be run. */
0183     mempool_t       rb_pool;    /* mempool for pkt_rb_node allocations */
0184 
0185     struct packet_iosched   iosched;
0186     struct gendisk      *disk;
0187 
0188     int         write_congestion_off;
0189     int         write_congestion_on;
0190 
0191     struct device       *dev;       /* sysfs pktcdvd[0-7] dev */
0192 
0193     struct dentry       *dfs_d_root;    /* debugfs: devname directory */
0194     struct dentry       *dfs_f_info;    /* debugfs: info file */
0195 };
0196 
0197 #endif /* __PKTCDVD_H */