1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef __OSD_INITIATOR_H__
15#define __OSD_INITIATOR_H__
16
17#include "osd_protocol.h"
18#include "osd_types.h"
19
20#include <linux/blkdev.h>
21#include <scsi/scsi_device.h>
22
23
24
25
26
27
28
29
30
31
32
33
34#define OSD_VER1_SUPPORT y
35
36enum osd_std_version {
37 OSD_VER_NONE = 0,
38 OSD_VER1 = 1,
39 OSD_VER2 = 2,
40};
41
42
43
44
45
46
47
48
49struct osd_dev {
50 struct scsi_device *scsi_device;
51 unsigned def_timeout;
52
53#ifdef OSD_VER1_SUPPORT
54 enum osd_std_version version;
55#endif
56};
57
58
59struct osd_dev_info {
60 unsigned systemid_len;
61 u8 systemid[OSD_SYSTEMID_LEN];
62 unsigned osdname_len;
63 u8 *osdname;
64};
65
66
67
68
69struct osd_dev *osduld_path_lookup(const char *dev_name);
70struct osd_dev *osduld_info_lookup(const struct osd_dev_info *odi);
71void osduld_put_device(struct osd_dev *od);
72
73const struct osd_dev_info *osduld_device_info(struct osd_dev *od);
74bool osduld_device_same(struct osd_dev *od, const struct osd_dev_info *odi);
75
76
77typedef int (do_test_fn)(struct osd_dev *od, unsigned cmd, unsigned long arg);
78int osduld_register_test(unsigned ioctl, do_test_fn *do_test);
79void osduld_unregister_test(unsigned ioctl);
80
81
82void osd_dev_init(struct osd_dev *od, struct scsi_device *scsi_device);
83void osd_dev_fini(struct osd_dev *od);
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100int osd_auto_detect_ver(struct osd_dev *od,
101 void *caps, struct osd_dev_info *odi);
102
103static inline struct request_queue *osd_request_queue(struct osd_dev *od)
104{
105 return od->scsi_device->request_queue;
106}
107
108
109static inline void osd_dev_set_ver(struct osd_dev *od, enum osd_std_version v)
110{
111#ifdef OSD_VER1_SUPPORT
112 od->version = v;
113#endif
114}
115
116static inline bool osd_dev_is_ver1(struct osd_dev *od)
117{
118#ifdef OSD_VER1_SUPPORT
119 return od->version == OSD_VER1;
120#else
121 return false;
122#endif
123}
124
125struct osd_request;
126typedef void (osd_req_done_fn)(struct osd_request *or, void *private);
127
128struct osd_request {
129 struct osd_cdb cdb;
130 struct osd_data_out_integrity_info out_data_integ;
131 struct osd_data_in_integrity_info in_data_integ;
132
133 struct osd_dev *osd_dev;
134 struct request *request;
135
136 struct _osd_req_data_segment {
137 void *buff;
138 unsigned alloc_size;
139 unsigned total_bytes;
140 } cdb_cont, set_attr, enc_get_attr, get_attr;
141
142 struct _osd_io_info {
143 struct bio *bio;
144 u64 total_bytes;
145 u64 residual;
146 struct request *req;
147 struct _osd_req_data_segment *last_seg;
148 u8 *pad_buff;
149 } out, in;
150
151 gfp_t alloc_flags;
152 unsigned timeout;
153 unsigned retries;
154 unsigned sense_len;
155 u8 sense[OSD_MAX_SENSE_LEN];
156 enum osd_attributes_mode attributes_mode;
157
158 osd_req_done_fn *async_done;
159 void *async_private;
160 int async_error;
161 int req_errors;
162};
163
164static inline bool osd_req_is_ver1(struct osd_request *or)
165{
166 return osd_dev_is_ver1(or->osd_dev);
167}
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212struct osd_request *osd_start_request(struct osd_dev *od, gfp_t gfp);
213
214enum osd_req_options {
215 OSD_REQ_FUA = 0x08,
216 OSD_REQ_DPO = 0x10,
217
218 OSD_REQ_BYPASS_TIMESTAMPS = 0x80,
219};
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235int osd_finalize_request(struct osd_request *or,
236 u8 options, const void *cap, const u8 *cap_key);
237
238
239
240
241
242
243
244
245int osd_execute_request(struct osd_request *or);
246
247
248
249
250
251
252
253
254
255
256
257
258int osd_execute_request_async(struct osd_request *or,
259 osd_req_done_fn *done, void *private);
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289enum osd_err_priority {
290 OSD_ERR_PRI_NO_ERROR = 0,
291
292 OSD_ERR_PRI_CLEAR_PAGES = 1,
293 OSD_ERR_PRI_RESOURCE = 2,
294 OSD_ERR_PRI_BAD_CRED = 3,
295 OSD_ERR_PRI_NO_ACCESS = 4,
296 OSD_ERR_PRI_UNREACHABLE = 5,
297 OSD_ERR_PRI_NOT_FOUND = 6,
298 OSD_ERR_PRI_NO_SPACE = 7,
299 OSD_ERR_PRI_EIO = 8,
300};
301
302struct osd_sense_info {
303 enum osd_err_priority osd_err_pri;
304
305 int key;
306 int additional_code ;
307 union {
308 u16 sense_info;
309 u16 cdb_field_offset;
310 };
311 union {
312 u64 command_info;
313 };
314
315 u32 not_initiated_command_functions;
316 u32 completed_command_functions;
317 struct osd_obj_id obj;
318 struct osd_attr attr;
319};
320
321int osd_req_decode_sense_full(struct osd_request *or,
322 struct osd_sense_info *osi, bool silent,
323 struct osd_obj_id *bad_obj_list, int max_obj,
324 struct osd_attr *bad_attr_list, int max_attr);
325
326static inline int osd_req_decode_sense(struct osd_request *or,
327 struct osd_sense_info *osi)
328{
329 return osd_req_decode_sense_full(or, osi, false, NULL, 0, NULL, 0);
330}
331
332
333
334
335
336
337
338
339void osd_end_request(struct osd_request *or);
340
341
342
343
344
345
346
347
348
349
350void osd_req_set_master_seed_xchg(struct osd_request *or, ...);
351void osd_req_set_master_key(struct osd_request *or, ...);
352
353void osd_req_format(struct osd_request *or, u64 tot_capacity);
354
355
356
357
358
359
360int osd_req_list_dev_partitions(struct osd_request *or,
361 osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem);
362
363void osd_req_flush_obsd(struct osd_request *or,
364 enum osd_options_flush_scope_values);
365
366void osd_req_perform_scsi_command(struct osd_request *or,
367 const u8 *cdb, ...);
368void osd_req_task_management(struct osd_request *or, ...);
369
370
371
372
373void osd_req_create_partition(struct osd_request *or, osd_id partition);
374void osd_req_remove_partition(struct osd_request *or, osd_id partition);
375
376void osd_req_set_partition_key(struct osd_request *or,
377 osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
378 u8 seed[OSD_CRYPTO_SEED_SIZE]);
379
380
381
382
383
384
385int osd_req_list_partition_collections(struct osd_request *or,
386 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
387 unsigned nelem);
388
389
390
391
392
393
394int osd_req_list_partition_objects(struct osd_request *or,
395 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
396 unsigned nelem);
397
398void osd_req_flush_partition(struct osd_request *or,
399 osd_id partition, enum osd_options_flush_scope_values);
400
401
402
403
404void osd_req_create_collection(struct osd_request *or,
405 const struct osd_obj_id *);
406void osd_req_remove_collection(struct osd_request *or,
407 const struct osd_obj_id *);
408
409
410int osd_req_list_collection_objects(struct osd_request *or,
411 const struct osd_obj_id *, osd_id initial_id,
412 struct osd_obj_id_list *list, unsigned nelem);
413
414
415void osd_req_query(struct osd_request *or, ...);
416
417void osd_req_flush_collection(struct osd_request *or,
418 const struct osd_obj_id *, enum osd_options_flush_scope_values);
419
420void osd_req_get_member_attrs(struct osd_request *or, ...);
421void osd_req_set_member_attrs(struct osd_request *or, ...);
422
423
424
425
426void osd_req_create_object(struct osd_request *or, struct osd_obj_id *);
427void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *);
428
429void osd_req_write(struct osd_request *or,
430 const struct osd_obj_id *obj, u64 offset, struct bio *bio, u64 len);
431int osd_req_write_kern(struct osd_request *or,
432 const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
433void osd_req_append(struct osd_request *or,
434 const struct osd_obj_id *, struct bio *data_out);
435void osd_req_create_write(struct osd_request *or,
436 const struct osd_obj_id *, struct bio *data_out, u64 offset);
437void osd_req_clear(struct osd_request *or,
438 const struct osd_obj_id *, u64 offset, u64 len);
439void osd_req_punch(struct osd_request *or,
440 const struct osd_obj_id *, u64 offset, u64 len);
441
442void osd_req_flush_object(struct osd_request *or,
443 const struct osd_obj_id *, enum osd_options_flush_scope_values,
444 u64 offset, u64 len);
445
446void osd_req_read(struct osd_request *or,
447 const struct osd_obj_id *obj, u64 offset, struct bio *bio, u64 len);
448int osd_req_read_kern(struct osd_request *or,
449 const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
450
451
452int osd_req_write_sg(struct osd_request *or,
453 const struct osd_obj_id *obj, struct bio *bio,
454 const struct osd_sg_entry *sglist, unsigned numentries);
455int osd_req_read_sg(struct osd_request *or,
456 const struct osd_obj_id *obj, struct bio *bio,
457 const struct osd_sg_entry *sglist, unsigned numentries);
458int osd_req_write_sg_kern(struct osd_request *or,
459 const struct osd_obj_id *obj, void **buff,
460 const struct osd_sg_entry *sglist, unsigned numentries);
461int osd_req_read_sg_kern(struct osd_request *or,
462 const struct osd_obj_id *obj, void **buff,
463 const struct osd_sg_entry *sglist, unsigned numentries);
464
465
466
467
468
469
470void osd_req_get_attributes(struct osd_request *or, const struct osd_obj_id *);
471
472
473void osd_req_set_attributes(struct osd_request *or, const struct osd_obj_id *);
474
475
476
477
478
479
480
481
482
483
484
485
486int osd_req_add_set_attr_list(struct osd_request *or,
487 const struct osd_attr *, unsigned nelem);
488
489
490int osd_req_add_get_attr_list(struct osd_request *or,
491 const struct osd_attr *, unsigned nelem);
492
493
494
495
496
497
498
499int osd_req_decode_get_attr_list(struct osd_request *or,
500 struct osd_attr *, int *nelem, void **iterator);
501
502
503
504
505
506
507
508
509
510
511int osd_req_add_get_attr_page(struct osd_request *or,
512 u32 page_id, void *attr_page_data, unsigned max_page_len,
513 const struct osd_attr *set_one);
514
515#endif
516