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