pktcdvd.h
上传用户:szlgq88
上传日期:2009-04-28
资源大小:48287k
文件大小:7k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

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