pktcdvd.h 8.1 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 sucessfully 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. /* default bio write queue congestion marks */
  99. #define PKT_WRITE_CONGESTION_ON 10000
  100. #define PKT_WRITE_CONGESTION_OFF 9000
  101. struct packet_settings
  102. {
  103. __u32 size; /* packet size in (512 byte) sectors */
  104. __u8 fp; /* fixed packets */
  105. __u8 link_loss; /* the rest is specified
  106. * as per Mt Fuji */
  107. __u8 write_type;
  108. __u8 track_mode;
  109. __u8 block_mode;
  110. };
  111. /*
  112. * Very crude stats for now
  113. */
  114. struct packet_stats
  115. {
  116. unsigned long pkt_started;
  117. unsigned long pkt_ended;
  118. unsigned long secs_w;
  119. unsigned long secs_rg;
  120. unsigned long secs_r;
  121. };
  122. struct packet_cdrw
  123. {
  124. struct list_head pkt_free_list;
  125. struct list_head pkt_active_list;
  126. spinlock_t active_list_lock; /* Serialize access to pkt_active_list */
  127. struct task_struct *thread;
  128. atomic_t pending_bios;
  129. };
  130. /*
  131. * Switch to high speed reading after reading this many kilobytes
  132. * with no interspersed writes.
  133. */
  134. #define HI_SPEED_SWITCH 512
  135. struct packet_iosched
  136. {
  137. atomic_t attention; /* Set to non-zero when queue processing is needed */
  138. int writing; /* Non-zero when writing, zero when reading */
  139. spinlock_t lock; /* Protecting read/write queue manipulations */
  140. struct bio *read_queue;
  141. struct bio *read_queue_tail;
  142. struct bio *write_queue;
  143. struct bio *write_queue_tail;
  144. sector_t last_write; /* The sector where the last write ended */
  145. int successive_reads;
  146. };
  147. /*
  148. * 32 buffers of 2048 bytes
  149. */
  150. #if (PAGE_SIZE % CD_FRAMESIZE) != 0
  151. #error "PAGE_SIZE must be a multiple of CD_FRAMESIZE"
  152. #endif
  153. #define PACKET_MAX_SIZE 128
  154. #define FRAMES_PER_PAGE (PAGE_SIZE / CD_FRAMESIZE)
  155. #define PACKET_MAX_SECTORS (PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
  156. enum packet_data_state {
  157. PACKET_IDLE_STATE, /* Not used at the moment */
  158. PACKET_WAITING_STATE, /* Waiting for more bios to arrive, so */
  159. /* we don't have to do as much */
  160. /* data gathering */
  161. PACKET_READ_WAIT_STATE, /* Waiting for reads to fill in holes */
  162. PACKET_WRITE_WAIT_STATE, /* Waiting for the write to complete */
  163. PACKET_RECOVERY_STATE, /* Recover after read/write errors */
  164. PACKET_FINISHED_STATE, /* After write has finished */
  165. PACKET_NUM_STATES /* Number of possible states */
  166. };
  167. /*
  168. * Information needed for writing a single packet
  169. */
  170. struct pktcdvd_device;
  171. struct packet_data
  172. {
  173. struct list_head list;
  174. spinlock_t lock; /* Lock protecting state transitions and */
  175. /* orig_bios list */
  176. struct bio *orig_bios; /* Original bios passed to pkt_make_request */
  177. struct bio *orig_bios_tail;/* that will be handled by this packet */
  178. int write_size; /* Total size of all bios in the orig_bios */
  179. /* list, measured in number of frames */
  180. struct bio *w_bio; /* The bio we will send to the real CD */
  181. /* device once we have all data for the */
  182. /* packet we are going to write */
  183. sector_t sector; /* First sector in this packet */
  184. int frames; /* Number of frames in this packet */
  185. enum packet_data_state state; /* Current state */
  186. atomic_t run_sm; /* Incremented whenever the state */
  187. /* machine needs to be run */
  188. long sleep_time; /* Set this to non-zero to make the state */
  189. /* machine run after this many jiffies. */
  190. atomic_t io_wait; /* Number of pending IO operations */
  191. atomic_t io_errors; /* Number of read/write errors during IO */
  192. struct bio *r_bios[PACKET_MAX_SIZE]; /* bios to use during data gathering */
  193. struct page *pages[PACKET_MAX_SIZE / FRAMES_PER_PAGE];
  194. int cache_valid; /* If non-zero, the data for the zone defined */
  195. /* by the sector variable is completely cached */
  196. /* in the pages[] vector. */
  197. int id; /* ID number for debugging */
  198. struct pktcdvd_device *pd;
  199. };
  200. struct pkt_rb_node {
  201. struct rb_node rb_node;
  202. struct bio *bio;
  203. };
  204. struct packet_stacked_data
  205. {
  206. struct bio *bio; /* Original read request bio */
  207. struct pktcdvd_device *pd;
  208. };
  209. #define PSD_POOL_SIZE 64
  210. struct pktcdvd_kobj
  211. {
  212. struct kobject kobj;
  213. struct pktcdvd_device *pd;
  214. };
  215. #define to_pktcdvdkobj(_k) \
  216. ((struct pktcdvd_kobj*)container_of(_k,struct pktcdvd_kobj,kobj))
  217. struct pktcdvd_device
  218. {
  219. struct block_device *bdev; /* dev attached */
  220. dev_t pkt_dev; /* our dev */
  221. char name[20];
  222. struct packet_settings settings;
  223. struct packet_stats stats;
  224. int refcnt; /* Open count */
  225. int write_speed; /* current write speed, kB/s */
  226. int read_speed; /* current read speed, kB/s */
  227. unsigned long offset; /* start offset */
  228. __u8 mode_offset; /* 0 / 8 */
  229. __u8 type;
  230. unsigned long flags;
  231. __u16 mmc3_profile;
  232. __u32 nwa; /* next writable address */
  233. __u32 lra; /* last recorded address */
  234. struct packet_cdrw cdrw;
  235. wait_queue_head_t wqueue;
  236. spinlock_t lock; /* Serialize access to bio_queue */
  237. struct rb_root bio_queue; /* Work queue of bios we need to handle */
  238. int bio_queue_size; /* Number of nodes in bio_queue */
  239. sector_t current_sector; /* Keep track of where the elevator is */
  240. atomic_t scan_queue; /* Set to non-zero when pkt_handle_queue */
  241. /* needs to be run. */
  242. mempool_t *rb_pool; /* mempool for pkt_rb_node allocations */
  243. struct packet_iosched iosched;
  244. struct gendisk *disk;
  245. int write_congestion_off;
  246. int write_congestion_on;
  247. struct class_device *clsdev; /* sysfs pktcdvd[0-7] class dev */
  248. struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */
  249. struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */
  250. struct dentry *dfs_d_root; /* debugfs: devname directory */
  251. struct dentry *dfs_f_info; /* debugfs: info file */
  252. };
  253. #endif /* __KERNEL__ */
  254. #endif /* __PKTCDVD_H */