blob: 93d142ad152815c7aafefa00ddd6cf2e1ab77a31 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2000 Jens Axboe <axboe@suse.de>
3 * Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com>
4 *
5 * May be copied or modified under the terms of the GNU General Public
6 * License. See linux/COPYING for more information.
7 *
8 * Packet writing layer for ATAPI and SCSI CD-R, CD-RW, DVD-R, and
9 * DVD-RW devices.
10 *
11 */
12#ifndef __PKTCDVD_H
13#define __PKTCDVD_H
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/blkdev.h>
16#include <linux/completion.h>
17#include <linux/cdrom.h>
Thomas Maier32694852006-12-08 02:36:12 -080018#include <linux/kobject.h>
19#include <linux/sysfs.h>
Alexander Beregalov097102c2009-04-21 09:33:14 +020020#include <linux/mempool.h>
David Howells607ca462012-10-13 10:46:48 +010021#include <uapi/linux/pktcdvd.h>
Thomas Maier0a0fc962006-12-08 02:36:11 -080022
23/* default bio write queue congestion marks */
24#define PKT_WRITE_CONGESTION_ON 10000
25#define PKT_WRITE_CONGESTION_OFF 9000
26
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028struct packet_settings
29{
Phillip Susia460ad62006-02-04 23:27:44 -080030 __u32 size; /* packet size in (512 byte) sectors */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 __u8 fp; /* fixed packets */
32 __u8 link_loss; /* the rest is specified
33 * as per Mt Fuji */
34 __u8 write_type;
35 __u8 track_mode;
36 __u8 block_mode;
37};
38
39/*
40 * Very crude stats for now
41 */
42struct packet_stats
43{
44 unsigned long pkt_started;
45 unsigned long pkt_ended;
46 unsigned long secs_w;
47 unsigned long secs_rg;
48 unsigned long secs_r;
49};
50
51struct packet_cdrw
52{
53 struct list_head pkt_free_list;
54 struct list_head pkt_active_list;
55 spinlock_t active_list_lock; /* Serialize access to pkt_active_list */
56 struct task_struct *thread;
57 atomic_t pending_bios;
58};
59
60/*
61 * Switch to high speed reading after reading this many kilobytes
62 * with no interspersed writes.
63 */
64#define HI_SPEED_SWITCH 512
65
66struct packet_iosched
67{
68 atomic_t attention; /* Set to non-zero when queue processing is needed */
69 int writing; /* Non-zero when writing, zero when reading */
70 spinlock_t lock; /* Protecting read/write queue manipulations */
Akinobu Mitac5ecc482010-02-24 08:30:08 +010071 struct bio_list read_queue;
72 struct bio_list write_queue;
Peter Osterlund46c271b2005-06-23 00:10:02 -070073 sector_t last_write; /* The sector where the last write ended */
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 int successive_reads;
75};
76
77/*
78 * 32 buffers of 2048 bytes
79 */
Peter Osterlund610827d2005-09-13 01:25:29 -070080#if (PAGE_SIZE % CD_FRAMESIZE) != 0
81#error "PAGE_SIZE must be a multiple of CD_FRAMESIZE"
82#endif
Phillip Susi5c55ac92006-02-04 23:27:48 -080083#define PACKET_MAX_SIZE 128
Peter Osterlunde1bc89b2006-02-04 23:27:47 -080084#define FRAMES_PER_PAGE (PAGE_SIZE / CD_FRAMESIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define PACKET_MAX_SECTORS (PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
86
87enum packet_data_state {
88 PACKET_IDLE_STATE, /* Not used at the moment */
89 PACKET_WAITING_STATE, /* Waiting for more bios to arrive, so */
90 /* we don't have to do as much */
91 /* data gathering */
92 PACKET_READ_WAIT_STATE, /* Waiting for reads to fill in holes */
93 PACKET_WRITE_WAIT_STATE, /* Waiting for the write to complete */
94 PACKET_RECOVERY_STATE, /* Recover after read/write errors */
95 PACKET_FINISHED_STATE, /* After write has finished */
96
97 PACKET_NUM_STATES /* Number of possible states */
98};
99
100/*
101 * Information needed for writing a single packet
102 */
103struct pktcdvd_device;
104
105struct packet_data
106{
107 struct list_head list;
108
109 spinlock_t lock; /* Lock protecting state transitions and */
110 /* orig_bios list */
111
Akinobu Mitac5ecc482010-02-24 08:30:08 +0100112 struct bio_list orig_bios; /* Original bios passed to pkt_make_request */
113 /* that will be handled by this packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 int write_size; /* Total size of all bios in the orig_bios */
115 /* list, measured in number of frames */
116
117 struct bio *w_bio; /* The bio we will send to the real CD */
118 /* device once we have all data for the */
119 /* packet we are going to write */
120 sector_t sector; /* First sector in this packet */
121 int frames; /* Number of frames in this packet */
122
123 enum packet_data_state state; /* Current state */
124 atomic_t run_sm; /* Incremented whenever the state */
125 /* machine needs to be run */
126 long sleep_time; /* Set this to non-zero to make the state */
127 /* machine run after this many jiffies. */
128
129 atomic_t io_wait; /* Number of pending IO operations */
130 atomic_t io_errors; /* Number of read/write errors during IO */
131
132 struct bio *r_bios[PACKET_MAX_SIZE]; /* bios to use during data gathering */
Peter Osterlunde1bc89b2006-02-04 23:27:47 -0800133 struct page *pages[PACKET_MAX_SIZE / FRAMES_PER_PAGE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 int cache_valid; /* If non-zero, the data for the zone defined */
136 /* by the sector variable is completely cached */
137 /* in the pages[] vector. */
138
139 int id; /* ID number for debugging */
140 struct pktcdvd_device *pd;
141};
142
143struct pkt_rb_node {
144 struct rb_node rb_node;
145 struct bio *bio;
146};
147
148struct packet_stacked_data
149{
150 struct bio *bio; /* Original read request bio */
151 struct pktcdvd_device *pd;
152};
153#define PSD_POOL_SIZE 64
154
Thomas Maier32694852006-12-08 02:36:12 -0800155struct pktcdvd_kobj
156{
157 struct kobject kobj;
158 struct pktcdvd_device *pd;
159};
160#define to_pktcdvdkobj(_k) \
161 ((struct pktcdvd_kobj*)container_of(_k,struct pktcdvd_kobj,kobj))
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163struct pktcdvd_device
164{
165 struct block_device *bdev; /* dev attached */
166 dev_t pkt_dev; /* our dev */
167 char name[20];
168 struct packet_settings settings;
169 struct packet_stats stats;
170 int refcnt; /* Open count */
171 int write_speed; /* current write speed, kB/s */
172 int read_speed; /* current read speed, kB/s */
173 unsigned long offset; /* start offset */
174 __u8 mode_offset; /* 0 / 8 */
175 __u8 type;
176 unsigned long flags;
177 __u16 mmc3_profile;
178 __u32 nwa; /* next writable address */
179 __u32 lra; /* last recorded address */
180 struct packet_cdrw cdrw;
181 wait_queue_head_t wqueue;
182
183 spinlock_t lock; /* Serialize access to bio_queue */
184 struct rb_root bio_queue; /* Work queue of bios we need to handle */
185 int bio_queue_size; /* Number of nodes in bio_queue */
186 sector_t current_sector; /* Keep track of where the elevator is */
187 atomic_t scan_queue; /* Set to non-zero when pkt_handle_queue */
188 /* needs to be run. */
189 mempool_t *rb_pool; /* mempool for pkt_rb_node allocations */
190
191 struct packet_iosched iosched;
192 struct gendisk *disk;
Thomas Maier0a0fc962006-12-08 02:36:11 -0800193
194 int write_congestion_off;
195 int write_congestion_on;
Thomas Maier32694852006-12-08 02:36:12 -0800196
Tony Jones6013c122007-09-25 02:03:03 +0200197 struct device *dev; /* sysfs pktcdvd[0-7] dev */
Thomas Maier32694852006-12-08 02:36:12 -0800198 struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */
199 struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */
200
201 struct dentry *dfs_d_root; /* debugfs: devname directory */
202 struct dentry *dfs_f_info; /* debugfs: info file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203};
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#endif /* __PKTCDVD_H */