pktcdvd.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/blkdev.h>
  15. #include <linux/completion.h>
  16. #include <linux/cdrom.h>
  17. #include <linux/kobject.h>
  18. #include <linux/sysfs.h>
  19. #include <linux/mempool.h>
  20. #include <uapi/linux/pktcdvd.h>
  21. /* default bio write queue congestion marks */
  22. #define PKT_WRITE_CONGESTION_ON 10000
  23. #define PKT_WRITE_CONGESTION_OFF 9000
  24. struct packet_settings
  25. {
  26. __u32 size; /* packet size in (512 byte) sectors */
  27. __u8 fp; /* fixed packets */
  28. __u8 link_loss; /* the rest is specified
  29. * as per Mt Fuji */
  30. __u8 write_type;
  31. __u8 track_mode;
  32. __u8 block_mode;
  33. };
  34. /*
  35. * Very crude stats for now
  36. */
  37. struct packet_stats
  38. {
  39. unsigned long pkt_started;
  40. unsigned long pkt_ended;
  41. unsigned long secs_w;
  42. unsigned long secs_rg;
  43. unsigned long secs_r;
  44. };
  45. struct packet_cdrw
  46. {
  47. struct list_head pkt_free_list;
  48. struct list_head pkt_active_list;
  49. spinlock_t active_list_lock; /* Serialize access to pkt_active_list */
  50. struct task_struct *thread;
  51. atomic_t pending_bios;
  52. };
  53. /*
  54. * Switch to high speed reading after reading this many kilobytes
  55. * with no interspersed writes.
  56. */
  57. #define HI_SPEED_SWITCH 512
  58. struct packet_iosched
  59. {
  60. atomic_t attention; /* Set to non-zero when queue processing is needed */
  61. int writing; /* Non-zero when writing, zero when reading */
  62. spinlock_t lock; /* Protecting read/write queue manipulations */
  63. struct bio_list read_queue;
  64. struct bio_list write_queue;
  65. sector_t last_write; /* The sector where the last write ended */
  66. int successive_reads;
  67. };
  68. /*
  69. * 32 buffers of 2048 bytes
  70. */
  71. #if (PAGE_SIZE % CD_FRAMESIZE) != 0
  72. #error "PAGE_SIZE must be a multiple of CD_FRAMESIZE"
  73. #endif
  74. #define PACKET_MAX_SIZE 128
  75. #define FRAMES_PER_PAGE (PAGE_SIZE / CD_FRAMESIZE)
  76. #define PACKET_MAX_SECTORS (PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
  77. enum packet_data_state {
  78. PACKET_IDLE_STATE, /* Not used at the moment */
  79. PACKET_WAITING_STATE, /* Waiting for more bios to arrive, so */
  80. /* we don't have to do as much */
  81. /* data gathering */
  82. PACKET_READ_WAIT_STATE, /* Waiting for reads to fill in holes */
  83. PACKET_WRITE_WAIT_STATE, /* Waiting for the write to complete */
  84. PACKET_RECOVERY_STATE, /* Recover after read/write errors */
  85. PACKET_FINISHED_STATE, /* After write has finished */
  86. PACKET_NUM_STATES /* Number of possible states */
  87. };
  88. /*
  89. * Information needed for writing a single packet
  90. */
  91. struct pktcdvd_device;
  92. struct packet_data
  93. {
  94. struct list_head list;
  95. spinlock_t lock; /* Lock protecting state transitions and */
  96. /* orig_bios list */
  97. struct bio_list orig_bios; /* Original bios passed to pkt_make_request */
  98. /* that will be handled by this packet */
  99. int write_size; /* Total size of all bios in the orig_bios */
  100. /* list, measured in number of frames */
  101. struct bio *w_bio; /* The bio we will send to the real CD */
  102. /* device once we have all data for the */
  103. /* packet we are going to write */
  104. sector_t sector; /* First sector in this packet */
  105. int frames; /* Number of frames in this packet */
  106. enum packet_data_state state; /* Current state */
  107. atomic_t run_sm; /* Incremented whenever the state */
  108. /* machine needs to be run */
  109. long sleep_time; /* Set this to non-zero to make the state */
  110. /* machine run after this many jiffies. */
  111. atomic_t io_wait; /* Number of pending IO operations */
  112. atomic_t io_errors; /* Number of read/write errors during IO */
  113. struct bio *r_bios[PACKET_MAX_SIZE]; /* bios to use during data gathering */
  114. struct page *pages[PACKET_MAX_SIZE / FRAMES_PER_PAGE];
  115. int cache_valid; /* If non-zero, the data for the zone defined */
  116. /* by the sector variable is completely cached */
  117. /* in the pages[] vector. */
  118. int id; /* ID number for debugging */
  119. struct pktcdvd_device *pd;
  120. };
  121. struct pkt_rb_node {
  122. struct rb_node rb_node;
  123. struct bio *bio;
  124. };
  125. struct packet_stacked_data
  126. {
  127. struct bio *bio; /* Original read request bio */
  128. struct pktcdvd_device *pd;
  129. };
  130. #define PSD_POOL_SIZE 64
  131. struct pktcdvd_kobj
  132. {
  133. struct kobject kobj;
  134. struct pktcdvd_device *pd;
  135. };
  136. #define to_pktcdvdkobj(_k) \
  137. ((struct pktcdvd_kobj*)container_of(_k,struct pktcdvd_kobj,kobj))
  138. struct pktcdvd_device
  139. {
  140. struct block_device *bdev; /* dev attached */
  141. dev_t pkt_dev; /* our dev */
  142. char name[20];
  143. struct packet_settings settings;
  144. struct packet_stats stats;
  145. int refcnt; /* Open count */
  146. int write_speed; /* current write speed, kB/s */
  147. int read_speed; /* current read speed, kB/s */
  148. unsigned long offset; /* start offset */
  149. __u8 mode_offset; /* 0 / 8 */
  150. __u8 type;
  151. unsigned long flags;
  152. __u16 mmc3_profile;
  153. __u32 nwa; /* next writable address */
  154. __u32 lra; /* last recorded address */
  155. struct packet_cdrw cdrw;
  156. wait_queue_head_t wqueue;
  157. spinlock_t lock; /* Serialize access to bio_queue */
  158. struct rb_root bio_queue; /* Work queue of bios we need to handle */
  159. int bio_queue_size; /* Number of nodes in bio_queue */
  160. sector_t current_sector; /* Keep track of where the elevator is */
  161. atomic_t scan_queue; /* Set to non-zero when pkt_handle_queue */
  162. /* needs to be run. */
  163. mempool_t rb_pool; /* mempool for pkt_rb_node allocations */
  164. struct packet_iosched iosched;
  165. struct gendisk *disk;
  166. int write_congestion_off;
  167. int write_congestion_on;
  168. struct device *dev; /* sysfs pktcdvd[0-7] dev */
  169. struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */
  170. struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */
  171. struct dentry *dfs_d_root; /* debugfs: devname directory */
  172. struct dentry *dfs_f_info; /* debugfs: info file */
  173. };
  174. #endif /* __PKTCDVD_H */