QNAP-TS419p system daemon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
5.4 KiB

  1. /* prototypes and stuff for ATA command ioctls */
  2. #include <linux/types.h>
  3. enum {
  4. ATA_OP_READ_PIO = 0x20,
  5. ATA_OP_READ_PIO_ONCE = 0x21,
  6. ATA_OP_READ_LONG = 0x22,
  7. ATA_OP_READ_LONG_ONCE = 0x23,
  8. ATA_OP_READ_PIO_EXT = 0x24,
  9. ATA_OP_READ_DMA_EXT = 0x25,
  10. ATA_OP_READ_FPDMA = 0x60, // NCQ
  11. ATA_OP_WRITE_PIO = 0x30,
  12. ATA_OP_WRITE_LONG = 0x32,
  13. ATA_OP_WRITE_LONG_ONCE = 0x33,
  14. ATA_OP_WRITE_PIO_EXT = 0x34,
  15. ATA_OP_WRITE_DMA_EXT = 0x35,
  16. ATA_OP_WRITE_FPDMA = 0x61, // NCQ
  17. ATA_OP_READ_VERIFY = 0x40,
  18. ATA_OP_READ_VERIFY_ONCE = 0x41,
  19. ATA_OP_READ_VERIFY_EXT = 0x42,
  20. ATA_OP_WRITE_UNC_EXT = 0x45, // lba48, no data, uses feat reg
  21. ATA_OP_FORMAT_TRACK = 0x50,
  22. ATA_OP_DOWNLOAD_MICROCODE = 0x92,
  23. ATA_OP_STANDBYNOW2 = 0x94,
  24. ATA_OP_CHECKPOWERMODE2 = 0x98,
  25. ATA_OP_SLEEPNOW2 = 0x99,
  26. ATA_OP_PIDENTIFY = 0xa1,
  27. ATA_OP_READ_NATIVE_MAX = 0xf8,
  28. ATA_OP_READ_NATIVE_MAX_EXT = 0x27,
  29. ATA_OP_SMART = 0xb0,
  30. ATA_OP_DCO = 0xb1,
  31. ATA_OP_ERASE_SECTORS = 0xc0,
  32. ATA_OP_READ_DMA = 0xc8,
  33. ATA_OP_WRITE_DMA = 0xca,
  34. ATA_OP_DOORLOCK = 0xde,
  35. ATA_OP_DOORUNLOCK = 0xdf,
  36. ATA_OP_STANDBYNOW1 = 0xe0,
  37. ATA_OP_IDLEIMMEDIATE = 0xe1,
  38. ATA_OP_SETIDLE = 0xe3,
  39. ATA_OP_SET_MAX = 0xf9,
  40. ATA_OP_SET_MAX_EXT = 0x37,
  41. ATA_OP_SET_MULTIPLE = 0xc6,
  42. ATA_OP_CHECKPOWERMODE1 = 0xe5,
  43. ATA_OP_SLEEPNOW1 = 0xe6,
  44. ATA_OP_FLUSHCACHE = 0xe7,
  45. ATA_OP_FLUSHCACHE_EXT = 0xea,
  46. ATA_OP_IDENTIFY = 0xec,
  47. ATA_OP_SETFEATURES = 0xef,
  48. ATA_OP_SECURITY_SET_PASS = 0xf1,
  49. ATA_OP_SECURITY_UNLOCK = 0xf2,
  50. ATA_OP_SECURITY_ERASE_PREPARE = 0xf3,
  51. ATA_OP_SECURITY_ERASE_UNIT = 0xf4,
  52. ATA_OP_SECURITY_FREEZE_LOCK = 0xf5,
  53. ATA_OP_SECURITY_DISABLE = 0xf6,
  54. };
  55. /*
  56. * Some useful ATA register bits
  57. */
  58. enum {
  59. ATA_USING_LBA = (1 << 6),
  60. ATA_STAT_DRQ = (1 << 3),
  61. ATA_STAT_ERR = (1 << 0),
  62. };
  63. /*
  64. * Useful parameters for init_hdio_taskfile():
  65. */
  66. enum { RW_READ = 0,
  67. RW_WRITE = 1,
  68. LBA28_OK = 0,
  69. LBA48_FORCE = 1,
  70. };
  71. /*
  72. * Definitions and structures for use with SG_IO + ATA_16:
  73. */
  74. struct ata_lba_regs {
  75. __u8 feat;
  76. __u8 nsect;
  77. __u8 lbal;
  78. __u8 lbam;
  79. __u8 lbah;
  80. };
  81. struct ata_tf {
  82. __u8 dev;
  83. __u8 command;
  84. __u8 error;
  85. __u8 status;
  86. __u8 is_lba48;
  87. struct ata_lba_regs lob;
  88. struct ata_lba_regs hob;
  89. };
  90. /*
  91. * Definitions and structures for use with HDIO_DRIVE_TASKFILE:
  92. */
  93. enum {
  94. /*
  95. * These (redundantly) specify the category of the request
  96. */
  97. TASKFILE_CMD_REQ_NODATA = 0, /* ide: IDE_DRIVE_TASK_NO_DATA */
  98. TASKFILE_CMD_REQ_IN = 2, /* ide: IDE_DRIVE_TASK_IN */
  99. TASKFILE_CMD_REQ_OUT = 3, /* ide: IDE_DRIVE_TASK_OUT */
  100. TASKFILE_CMD_REQ_RAW_OUT= 4, /* ide: IDE_DRIVE_TASK_RAW_WRITE */
  101. /*
  102. * These specify the method of transfer (pio, dma, multi, ..)
  103. */
  104. TASKFILE_DPHASE_NONE = 0, /* ide: TASKFILE_IN */
  105. TASKFILE_DPHASE_PIO_IN = 1, /* ide: TASKFILE_IN */
  106. TASKFILE_DPHASE_PIO_OUT = 4, /* ide: TASKFILE_OUT */
  107. };
  108. struct reg_flags {
  109. union {
  110. unsigned lob_all : 8;
  111. struct {
  112. unsigned data : 1;
  113. unsigned feat : 1;
  114. unsigned lbal : 1;
  115. unsigned nsect : 1;
  116. unsigned lbam : 1;
  117. unsigned lbah : 1;
  118. unsigned dev : 1;
  119. unsigned command : 1;
  120. } lob;
  121. };
  122. union {
  123. unsigned hob_all : 8;
  124. struct {
  125. unsigned data : 1;
  126. unsigned feat : 1;
  127. unsigned lbal : 1;
  128. unsigned nsect : 1;
  129. unsigned lbam : 1;
  130. unsigned lbah : 1;
  131. unsigned dev : 1;
  132. unsigned command : 1;
  133. } hob;
  134. };
  135. };
  136. struct taskfile_regs {
  137. __u8 data;
  138. __u8 feat;
  139. __u8 nsect;
  140. __u8 lbal;
  141. __u8 lbam;
  142. __u8 lbah;
  143. __u8 dev;
  144. __u8 command;
  145. };
  146. struct hdio_taskfile {
  147. struct taskfile_regs lob;
  148. struct taskfile_regs hob;
  149. struct reg_flags oflags;
  150. struct reg_flags iflags;
  151. int dphase;
  152. int cmd_req; /* IDE command_type */
  153. unsigned long obytes;
  154. unsigned long ibytes;
  155. __u16 data[0];
  156. };
  157. struct scsi_sg_io_hdr {
  158. int interface_id;
  159. int dxfer_direction;
  160. unsigned char cmd_len;
  161. unsigned char mx_sb_len;
  162. unsigned short iovec_count;
  163. unsigned int dxfer_len;
  164. void * dxferp;
  165. unsigned char * cmdp;
  166. void * sbp;
  167. unsigned int timeout;
  168. unsigned int flags;
  169. int pack_id;
  170. void * usr_ptr;
  171. unsigned char status;
  172. unsigned char masked_status;
  173. unsigned char msg_status;
  174. unsigned char sb_len_wr;
  175. unsigned short host_status;
  176. unsigned short driver_status;
  177. int resid;
  178. unsigned int duration;
  179. unsigned int info;
  180. };
  181. #ifndef SG_DXFER_NONE
  182. #define SG_DXFER_NONE -1
  183. #define SG_DXFER_TO_DEV -2
  184. #define SG_DXFER_FROM_DEV -3
  185. #define SG_DXFER_TO_FROM_DEV -4
  186. #endif
  187. #define SG_READ 0
  188. #define SG_WRITE 1
  189. #define SG_PIO 0
  190. #define SG_DMA 1
  191. #define SG_CHECK_CONDITION 0x02
  192. #define SG_DRIVER_SENSE 0x08
  193. #define SG_ATA_16 0x85
  194. #define SG_ATA_16_LEN 16
  195. #define SG_ATA_12 0xa1
  196. #define SG_ATA_12_LEN 12
  197. #define SG_ATA_LBA48 1
  198. #define SG_ATA_PROTO_NON_DATA ( 3 << 1)
  199. #define SG_ATA_PROTO_PIO_IN ( 4 << 1)
  200. #define SG_ATA_PROTO_PIO_OUT ( 5 << 1)
  201. #define SG_ATA_PROTO_DMA ( 6 << 1)
  202. #define SG_ATA_PROTO_UDMA_IN (11 << 1) /* not yet supported in libata */
  203. #define SG_ATA_PROTO_UDMA_OUT (12 << 1) /* not yet supported in libata */
  204. void tf_init (struct ata_tf *tf, __u8 ata_op, __u64 lba, unsigned int nsect);
  205. __u64 tf_to_lba (struct ata_tf *tf);
  206. int sg16 (int fd, int rw, int dma, struct ata_tf *tf, void *data, unsigned int data_bytes, unsigned int timeout_secs);
  207. int do_drive_cmd (int fd, unsigned char *args);
  208. int do_taskfile_cmd (int fd, struct hdio_taskfile *r, unsigned int timeout_secs);
  209. int dev_has_sgio (int fd);
  210. void init_hdio_taskfile (struct hdio_taskfile *r, __u8 ata_op, int rw, int force_lba48,
  211. __u64 lba, unsigned int nsect, int data_bytes);