scsi-lowlevel.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef CCAN_ISCSI_SCSI_LOWLEVEL_H
  15. #define CCAN_ISCSI_SCSI_LOWLEVEL_H
  16. #define SCSI_CDB_MAX_SIZE 16
  17. enum scsi_opcode {SCSI_OPCODE_TESTUNITREADY=0x00,
  18. SCSI_OPCODE_INQUIRY=0x12,
  19. SCSI_OPCODE_MODESENSE6=0x1a,
  20. SCSI_OPCODE_READCAPACITY10=0x25,
  21. SCSI_OPCODE_READ10=0x28,
  22. SCSI_OPCODE_WRITE10=0x2A,
  23. SCSI_OPCODE_REPORTLUNS=0xA0};
  24. /* sense keys */
  25. #define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
  26. #define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
  27. /* ascq */
  28. #define SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB 0x2400
  29. #define SCSI_SENSE_ASCQ_BUS_RESET 0x2900
  30. enum scsi_xfer_dir {SCSI_XFER_NONE=0,
  31. SCSI_XFER_READ=1,
  32. SCSI_XFER_WRITE=2};
  33. struct scsi_reportluns_params {
  34. int report_type;
  35. };
  36. struct scsi_readcapacity10_params {
  37. int lba;
  38. int pmi;
  39. };
  40. struct scsi_inquiry_params {
  41. int evpd;
  42. int page_code;
  43. };
  44. struct scsi_modesense6_params {
  45. int dbd;
  46. int pc;
  47. int page_code;
  48. int sub_page_code;
  49. };
  50. struct scsi_sense {
  51. unsigned char error_type;
  52. unsigned char key;
  53. int ascq;
  54. };
  55. struct scsi_data {
  56. int size;
  57. unsigned char *data;
  58. };
  59. struct scsi_allocated_memory {
  60. struct scsi_allocated_memory *prev, *next;
  61. void *ptr;
  62. };
  63. struct scsi_task {
  64. int cdb_size;
  65. int xfer_dir;
  66. int expxferlen;
  67. unsigned char cdb[SCSI_CDB_MAX_SIZE];
  68. union {
  69. struct scsi_readcapacity10_params readcapacity10;
  70. struct scsi_reportluns_params reportluns;
  71. struct scsi_inquiry_params inquiry;
  72. struct scsi_modesense6_params modesense6;
  73. } params;
  74. struct scsi_sense sense;
  75. struct scsi_data datain;
  76. struct scsi_allocated_memory *mem;
  77. };
  78. void scsi_free_scsi_task(struct scsi_task *task);
  79. /*
  80. * TESTUNITREADY
  81. */
  82. struct scsi_task *scsi_cdb_testunitready(void);
  83. /*
  84. * REPORTLUNS
  85. */
  86. #define SCSI_REPORTLUNS_REPORT_ALL_LUNS 0x00
  87. #define SCSI_REPORTLUNS_REPORT_WELL_KNOWN_ONLY 0x01
  88. #define SCSI_REPORTLUNS_REPORT_AVAILABLE_LUNS_ONLY 0x02
  89. struct scsi_reportluns_list {
  90. uint32_t num;
  91. uint16_t luns[0];
  92. };
  93. struct scsi_task *scsi_reportluns_cdb(int report_type, int alloc_len);
  94. /*
  95. * READCAPACITY10
  96. */
  97. struct scsi_readcapacity10 {
  98. uint32_t lba;
  99. uint32_t block_size;
  100. };
  101. struct scsi_task *scsi_cdb_readcapacity10(int lba, int pmi);
  102. /*
  103. * INQUIRY
  104. */
  105. enum scsi_inquiry_peripheral_qualifier {SCSI_INQUIRY_PERIPHERAL_QUALIFIER_CONNECTED=0x00,
  106. SCSI_INQUIRY_PERIPHERAL_QUALIFIER_DISCONNECTED=0x01,
  107. SCSI_INQUIRY_PERIPHERAL_QUALIFIER_NOT_SUPPORTED=0x03};
  108. enum scsi_inquiry_peripheral_device_type {SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS=0x00,
  109. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_SEQUENTIAL_ACCESS=0x01,
  110. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_PRINTER=0x02,
  111. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_PROCESSOR=0x03,
  112. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_WRITE_ONCE=0x04,
  113. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_MMC=0x05,
  114. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_SCANNER=0x06,
  115. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_OPTICAL_MEMORY=0x07,
  116. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_MEDIA_CHANGER=0x08,
  117. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_COMMUNICATIONS=0x09,
  118. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_STORAGE_ARRAY_CONTROLLER=0x0c,
  119. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_ENCLOSURE_SERVICES=0x0d,
  120. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_SIMPLIFIED_DIRECT_ACCESS=0x0e,
  121. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_OPTICAL_CARD_READER=0x0f,
  122. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_BRIDGE_CONTROLLER=0x10,
  123. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_OSD=0x11,
  124. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_AUTOMATION=0x12,
  125. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_SEQURITY_MANAGER=0x13,
  126. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_WELL_KNOWN_LUN=0x1e,
  127. SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_UNKNOWN=0x1f};
  128. struct scsi_inquiry_standard {
  129. enum scsi_inquiry_peripheral_qualifier periperal_qualifier;
  130. enum scsi_inquiry_peripheral_device_type periperal_device_type;
  131. int rmb;
  132. int version;
  133. int normaca;
  134. int hisup;
  135. int response_data_format;
  136. char vendor_identification[8+1];
  137. char product_identification[16+1];
  138. char product_revision_level[4+1];
  139. };
  140. struct scsi_task *scsi_cdb_inquiry(int evpd, int page_code, int alloc_len);
  141. /*
  142. * MODESENSE6
  143. */
  144. enum scsi_modesense_page_control {SCSI_MODESENSE_PC_CURRENT=0x00,
  145. SCSI_MODESENSE_PC_CHANGEABLE=0x01,
  146. SCSI_MODESENSE_PC_DEFAULT=0x02,
  147. SCSI_MODESENSE_PC_SAVED=0x03};
  148. enum scsi_modesense_page_code {SCSI_MODESENSE_PAGECODE_RETURN_ALL_PAGES=0x3f};
  149. struct scsi_task *scsi_cdb_modesense6(int dbd, enum scsi_modesense_page_control pc, enum scsi_modesense_page_code page_code, int sub_page_code, unsigned char alloc_len);
  150. int scsi_datain_getfullsize(struct scsi_task *task);
  151. void *scsi_datain_unmarshall(struct scsi_task *task);
  152. struct scsi_task *scsi_cdb_read10(int lba, int xferlen, int blocksize);
  153. struct scsi_task *scsi_cdb_write10(int lba, int xferlen, int fua, int fuanv, int blocksize);
  154. #endif /* CCAN_ISCSI_SCSI_LOWLEVEL_H */