pktcdvd.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  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. #include <linux/types.h>
  15. /*
  16. * 1 for normal debug messages, 2 is very verbose. 0 to turn it off.
  17. */
  18. #define PACKET_DEBUG 1
  19. #define MAX_WRITERS 8
  20. #define PKT_RB_POOL_SIZE 512
  21. /*
  22. * How long we should hold a non-full packet before starting data gathering.
  23. */
  24. #define PACKET_WAIT_TIME (HZ * 5 / 1000)
  25. /*
  26. * use drive write caching -- we need deferred error handling to be
  27. * able to successfully recover with this option (drive will return good
  28. * status as soon as the cdb is validated).
  29. */
  30. #if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
  31. #define USE_WCACHING 1
  32. #else
  33. #define USE_WCACHING 0
  34. #endif
  35. /*
  36. * No user-servicable parts beyond this point ->
  37. */
  38. /*
  39. * device types
  40. */
  41. #define PACKET_CDR 1
  42. #define PACKET_CDRW 2
  43. #define PACKET_DVDR 3
  44. #define PACKET_DVDRW 4
  45. /*
  46. * flags
  47. */
  48. #define PACKET_WRITABLE 1 /* pd is writable */
  49. #define PACKET_NWA_VALID 2 /* next writable address valid */
  50. #define PACKET_LRA_VALID 3 /* last recorded address valid */
  51. #define PACKET_MERGE_SEGS 4 /* perform segment merging to keep */
  52. /* underlying cdrom device happy */
  53. /*
  54. * Disc status -- from READ_DISC_INFO
  55. */
  56. #define PACKET_DISC_EMPTY 0
  57. #define PACKET_DISC_INCOMPLETE 1
  58. #define PACKET_DISC_COMPLETE 2
  59. #define PACKET_DISC_OTHER 3
  60. /*
  61. * write type, and corresponding data block type
  62. */
  63. #define PACKET_MODE1 1
  64. #define PACKET_MODE2 2
  65. #define PACKET_BLOCK_MODE1 8
  66. #define PACKET_BLOCK_MODE2 10
  67. /*
  68. * Last session/border status
  69. */
  70. #define PACKET_SESSION_EMPTY 0
  71. #define PACKET_SESSION_INCOMPLETE 1
  72. #define PACKET_SESSION_RESERVED 2
  73. #define PACKET_SESSION_COMPLETE 3
  74. #define PACKET_MCN "4a656e734178626f65323030300000"
  75. #undef PACKET_USE_LS
  76. #define PKT_CTRL_CMD_SETUP 0
  77. #define PKT_CTRL_CMD_TEARDOWN 1
  78. #define PKT_CTRL_CMD_STATUS 2
  79. struct pkt_ctrl_command {
  80. __u32 command; /* in: Setup, teardown, status */
  81. __u32 dev_index; /* in/out: Device index */
  82. __u32 dev; /* in/out: Device nr for cdrw device */
  83. __u32 pkt_dev; /* in/out: Device nr for packet device */
  84. __u32 num_devices; /* out: Largest device index + 1 */
  85. __u32 padding; /* Not used */
  86. };
  87. /*
  88. * packet ioctls
  89. */
  90. #define PACKET_IOCTL_MAGIC ('X')
  91. #define PACKET_CTRL_CMD _IOWR(PACKET_IOCTL_MAGIC, 1, struct pkt_ctrl_command)
  92. #ifdef __KERNEL__
  93. #include <linux/blkdev.h>
  94. #include <linux/completion.h>
  95. #include <linux/cdrom.h>
  96. #include <linux/kobject.h>
  97. #include <linux/sysfs.h>
  98. #include <linux/mempool.h>
  99. /* default bio write queue congestion marks */
  100. #define PKT_WRITE_CONGESTION_ON 10000
  101. #define PKT_WRITE_CONGESTION_OFF 9000
  102. struct packet_settings
  103. {
  104. __u32 size; /* packet size in (512 byte) sectors */
  105. __u8 fp; /* fixed packets */
  106. __u8 link_loss; /* the rest is specified
  107. * as per Mt Fuji */
  108. __u8 write_type;
  109. __u8 track_mode;
  110. __u8 block_mode;
  111. };
  112. /*
  113. * Very crude stats for now
  114. */
  115. struct packet_stats
  116. {
  117. unsigned long pkt_started;
  118. unsigned long pkt_ended;
  119. unsigned long secs_w;
  120. unsigned long secs_rg;
  121. unsigned long secs_r;
  122. };
  123. struct packet_cdrw
  124. {
  125. struct list_head pkt_free_list;
  126. struct list_head pkt_active_list;
  127. spinlock_t active_list_lock; /* Serialize access to pkt_active_list */
  128. struct task_struct *thread;
  129. atomic_t pending_bios;
  130. };
  131. /*
  132. * Switch to high speed reading after reading this many kilobytes
  133. * with no interspersed writes.
  134. */
  135. #define HI_SPEED_SWITCH 512
  136. struct packet_iosched
  137. {
  138. atomic_t attention; /* Set to non-zero when queue processing is needed */
  139. int writing; /* Non-zero when writing, zero when reading */
  140. spinlock_t lock; /* Protecting read/write queue manipulations */
  141. struct bio_list read_queue;
  142. struct bio_list write_queue;
  143. sector_t last_write; /* The sector where the last write ended */
  144. int successive_reads;
  145. };
  146. /*
  147. * 32 buffers of 2048 bytes
  148. */
  149. #if (PAGE_SIZE % CD_FRAMESIZE) != 0
  150. #error "PAGE_SIZE must be a multiple of CD_FRAMESIZE"
  151. #endif
  152. #define PACKET_MAX_SIZE 128
  153. #define FRAMES_PER_PAGE (PAGE_SIZE / CD_FRAMESIZE)
  154. #define PACKET_MAX_SECTORS (PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
  155. enum packet_data_state {
  156. PACKET_IDLE_STATE, /* Not used at the moment */
  157. PACKET_WAITING_STATE, /* Waiting for more bios to arrive, so */
  158. /* we don't have to do as much */
  159. /* data gathering */
  160. PACKET_READ_WAIT_STATE, /* Waiting for reads to fill in holes */
  161. PACKET_WRITE_WAIT_STATE, /* Waiting for the write to complete */
  162. PACKET_RECOVERY_STATE, /* Recover after read/write errors */
  163. PACKET_FINISHED_STATE, /* After write has finished */
  164. PACKET_NUM_STATES /* Number of possible states */
  165. };
  166. /*
  167. * Information needed for writing a single packet
  168. */
  169. struct pktcdvd_device;
  170. struct packet_data
  171. {
  172. struct list_head list;
  173. spinlock_t lock; /* Lock protecting state transitions and */
  174. /* orig_bios list */
  175. struct bio_list orig_bios; /* Original bios passed to pkt_make_request */
  176. /* that will be handled by this packet */
  177. int write_size; /* Total size of all bios in the orig_bios */
  178. /* list, measured in number of frames */
  179. struct bio *w_bio; /* The bio we will send to the real CD */
  180. /* device once we have all data for the */
  181. /* packet we are going to write */
  182. sector_t sector; /* First sector in this packet */
  183. int frames; /* Number of frames in this packet */
  184. enum packet_data_state state; /* Current state */
  185. atomic_t run_sm; /* Incremented whenever the state */
  186. /* machine needs to be run */
  187. long sleep_time; /* Set this to non-zero to make the state */
  188. /* machine run after this many jiffies. */
  189. atomic_t io_wait; /* Number of pending IO operations */
  190. atomic_t io_errors; /* Number of read/write errors during IO */
  191. struct bio *r_bios[PACKET_MAX_SIZE]; /* bios to use during data gathering */
  192. struct page *pages[PACKET_MAX_SIZE / FRAMES_PER_PAGE];
  193. int cache_valid; /* If non-zero, the data for the zone defined */
  194. /* by the sector variable is completely cached */
  195. /* in the pages[] vector. */
  196. int id; /* ID number for debugging */
  197. struct pktcdvd_device *pd;
  198. };
  199. struct pkt_rb_node {
  200. struct rb_node rb_node;
  201. struct bio *bio;
  202. };
  203. struct packet_stacked_data
  204. {
  205. struct bio *bio; /* Original read request bio */
  206. struct pktcdvd_device *pd;
  207. };
  208. #define PSD_POOL_SIZE 64
  209. struct pktcdvd_kobj
  210. {
  211. struct kobject kobj;
  212. struct pktcdvd_device *pd;
  213. };
  214. #define to_pktcdvdkobj(_k) \
  215. ((struct pktcdvd_kobj*)container_of(_k,struct pktcdvd_kobj,kobj))
  216. struct pktcdvd_device
  217. {
  218. struct block_device *bdev; /* dev attached */
  219. dev_t pkt_dev; /* our dev */
  220. char name[20];
  221. struct packet_settings settings;
  222. struct packet_stats stats;
  223. int refcnt; /* Open count */
  224. int write_speed; /* current write speed, kB/s */
  225. int read_speed; /* current read speed, kB/s */
  226. unsigned long offset; /* start offset */
  227. __u8 mode_offset; /* 0 / 8 */
  228. __u8 type;
  229. unsigned long flags;
  230. __u16 mmc3_profile;
  231. __u32 nwa; /* next writable address */
  232. __u32 lra; /* last recorded address */
  233. struct packet_cdrw cdrw;
  234. wait_queue_head_t wqueue;
  235. spinlock_t lock; /* Serialize access to bio_queue */
  236. struct rb_root bio_queue; /* Work queue of bios we need to handle */
  237. int bio_queue_size; /* Number of nodes in bio_queue */
  238. sector_t current_sector; /* Keep track of where the elevator is */
  239. atomic_t scan_queue; /* Set to non-zero when pkt_handle_queue */
  240. /* needs to be run. */
  241. mempool_t *rb_pool; /* mempool for pkt_rb_node allocations */
  242. struct packet_iosched iosched;
  243. struct gendisk *disk;
  244. int write_congestion_off;
  245. int write_congestion_on;
  246. struct device *dev; /* sysfs pktcdvd[0-7] dev */
  247. struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */
  248. struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */
  249. struct dentry *dfs_d_root; /* debugfs: devname directory */
  250. struct dentry *dfs_f_info; /* debugfs: info file */
  251. };
  252. #endif /* __KERNEL__ */
  253. #endif /* __PKTCDVD_H */