1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
/*
* osd_protocol.h - OSD T10 standard C definitions.
*
* Copyright (C) 2008 Panasas Inc. All rights reserved.
*
* Authors:
* Boaz Harrosh <ooo@electrozaur.com>
* Benny Halevy <bhalevy@panasas.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
*
* This file contains types and constants that are defined by the protocol
* Note: All names and symbols are taken from the OSD standard's text.
*/
#ifndef __OSD_PROTOCOL_H__
#define __OSD_PROTOCOL_H__
#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/unaligned.h>
#include <scsi/scsi.h>
enum {
OSDv1_ADDITIONAL_CDB_LENGTH = 192,
OSDv1_TOTAL_CDB_LEN = OSDv1_ADDITIONAL_CDB_LENGTH + 8,
OSDv1_CAP_LEN = 80,
/* Latest supported version */
OSDv2_ADDITIONAL_CDB_LENGTH = 228,
OSD_ADDITIONAL_CDB_LENGTH =
OSDv2_ADDITIONAL_CDB_LENGTH,
OSD_TOTAL_CDB_LEN = OSD_ADDITIONAL_CDB_LENGTH + 8,
OSD_CAP_LEN = 104,
OSD_SYSTEMID_LEN = 20,
OSDv1_CRYPTO_KEYID_SIZE = 20,
OSDv2_CRYPTO_KEYID_SIZE = 32,
OSD_CRYPTO_KEYID_SIZE = OSDv2_CRYPTO_KEYID_SIZE,
OSD_CRYPTO_SEED_SIZE = 4,
OSD_CRYPTO_NONCE_SIZE = 12,
OSD_MAX_SENSE_LEN = 252, /* from SPC-3 */
OSD_PARTITION_FIRST_ID = 0x10000,
OSD_OBJECT_FIRST_ID = 0x10000,
};
/* (osd-r10 5.2.4)
* osd2r03: 5.2.3 Caching control bits
*/
enum osd_options_byte {
OSD_CDB_FUA = 0x08, /* Force Unit Access */
OSD_CDB_DPO = 0x10, /* Disable Page Out */
};
/*
* osd2r03: 5.2.5 Isolation.
* First 3 bits, V2-only.
* Also for attr 110h "default isolation method" at Root Information page
*/
enum osd_options_byte_isolation {
OSD_ISOLATION_DEFAULT = 0,
OSD_ISOLATION_NONE = 1,
OSD_ISOLATION_STRICT = 2,
OSD_ISOLATION_RANGE = 4,
OSD_ISOLATION_FUNCTIONAL = 5,
OSD_ISOLATION_VENDOR = 7,
};
/* (osd-r10: 6.7)
* osd2r03: 6.8 FLUSH, FLUSH COLLECTION, FLUSH OSD, FLUSH PARTITION
*/
enum osd_options_flush_scope_values {
OSD_CDB_FLUSH_ALL = 0,
OSD_CDB_FLUSH_ATTR_ONLY = 1,
OSD_CDB_FLUSH_ALL_RECURSIVE = 2,
/* V2-only */
OSD_CDB_FLUSH_ALL_RANGE = 2,
};
/* osd2r03: 5.2.10 Timestamps control */
enum {
OSD_CDB_NORMAL_TIMESTAMPS = 0,
OSD_CDB_BYPASS_TIMESTAMPS = 0x7f,
};
/* (osd-r10: 5.2.2.1)
* osd2r03: 5.2.4.1 Get and set attributes CDB format selection
* 2 bits at second nibble of command_specific_options byte
*/
enum osd_attributes_mode {
/* V2-only */
OSD_CDB_SET_ONE_ATTR = 0x10,
OSD_CDB_GET_ATTR_PAGE_SET_ONE = 0x20,
OSD_CDB_GET_SET_ATTR_LISTS = 0x30,
OSD_CDB_GET_SET_ATTR_MASK = 0x30,
};
/* (osd-r10: 4.12.5)
* osd2r03: 4.14.5 Data-In and Data-Out buffer offsets
* byte offset = mantissa * (2^(exponent+8))
* struct {
* unsigned mantissa: 28;
* int exponent: 04;
* }
*/
typedef __be32 osd_cdb_offset;
enum {
OSD_OFFSET_UNUSED = 0xFFFFFFFF,
OSD_OFFSET_MAX_BITS = 28,
OSDv1_OFFSET_MIN_SHIFT = 8,
OSD_OFFSET_MIN_SHIFT = 3,
OSD_OFFSET_MAX_SHIFT = 16,
};
/* Return the smallest allowed encoded offset that contains @offset.
*
* The actual encoded offset returned is @offset + *padding.
* (up to max_shift, non-inclusive)
*/
osd_cdb_offset __osd_encode_offset(u64 offset, unsigned *padding,
int min_shift, int max_shift);
/* Minimum alignment is 256 bytes
* Note: Seems from std v1 that exponent can be from 0+8 to 0xE+8 (inclusive)
* which is 8 to 23 but IBM code restricts it to 16, so be it.
*/
static inline osd_cdb_offset osd_encode_offset_v1(u64 offset, unsigned *padding)
{
return __osd_encode_offset(offset, padding,
OSDv1_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
}
/* Minimum 8 bytes alignment
* Same as v1 but since exponent can be signed than a less than
* 256 alignment can be reached with small offsets (<2GB)
*/
static inline osd_cdb_offset osd_encode_offset_v2(u64 offset, unsigned *padding)
{
return __osd_encode_offset(offset, padding,
OSD_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
}
/* osd2r03: 5.2.1 Overview */
struct osd_cdb_head {
struct scsi_varlen_cdb_hdr varlen_cdb;
/*10*/ u8 options;
u8 command_specific_options;
u8 timestamp_control;
/*13*/ u8 reserved1[3];
/*16*/ __be64 partition;
/*24*/ __be64 object;
/*32*/ union { /* V1 vs V2 alignment differences */
struct __osdv1_cdb_addr_len {
/*32*/ __be32 list_identifier;/* Rarely used */
/*36*/ __be64 length;
/*44*/ __be64 start_address;
} __packed v1;
struct __osdv2_cdb_addr_len {
/* called allocation_length in some commands */
/*32*/ __be64 length;
/*40*/ __be64 start_address;
union {
/*48*/ __be32 list_identifier;/* Rarely used */
/* OSD2r05 5.2.5 CDB continuation length */
/*48*/ __be32 cdb_continuation_length;
};
} __packed v2;
};
/*52*/ union { /* selected attributes mode Page/List/Single */
struct osd_attributes_page_mode {
/*52*/ __be32 get_attr_page;
/*56*/ __be32 get_attr_alloc_length;
/*60*/ osd_cdb_offset get_attr_offset;
/*64*/ __be32 set_attr_page;
/*68*/ __be32 set_attr_id;
/*72*/ __be32 set_attr_length;
/*76*/ osd_cdb_offset set_attr_offset;
/*80*/ } __packed attrs_page;
struct osd_attributes_list_mode {
/*52*/ __be32 get_attr_desc_bytes;
/*56*/ osd_cdb_offset get_attr_desc_offset;
/*60*/ __be32 get_attr_alloc_length;
/*64*/ osd_cdb_offset get_attr_offset;
/*68*/ __be32 set_attr_bytes;
/*72*/ osd_cdb_offset set_attr_offset;
__be32 not_used;
/*80*/ } __packed attrs_list;
/* osd2r03:5.2.4.2 Set one attribute value using CDB fields */
struct osd_attributes_cdb_mode {
/*52*/ __be32 set_attr_page;
/*56*/ __be32 set_attr_id;
/*60*/ __be16 set_attr_len;
/*62*/ u8 set_attr_val[18];
/*80*/ } __packed attrs_cdb;
/*52*/ u8 get_set_attributes_parameters[28];
};
} __packed;
/*80*/
/*160 v1*/
struct osdv1_security_parameters {
/*160*/u8 integrity_check_value[OSDv1_CRYPTO_KEYID_SIZE];
/*180*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE];
/*192*/osd_cdb_offset data_in_integrity_check_offset;
/*196*/osd_cdb_offset data_out_integrity_check_offset;
} __packed;
/*200 v1*/
/*184 v2*/
struct osdv2_security_parameters {
/*184*/u8 integrity_check_value[OSDv2_CRYPTO_KEYID_SIZE];
/*216*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE];
/*228*/osd_cdb_offset data_in_integrity_check_offset;
/*232*/osd_cdb_offset data_out_integrity_check_offset;
} __packed;
/*236 v2*/
struct osd_security_parameters {
union {
struct osdv1_security_parameters v1;
struct osdv2_security_parameters v2;
};
};
struct osdv1_cdb {
struct osd_cdb_head h;
u8 caps[OSDv1_CAP_LEN];
struct osdv1_security_parameters sec_params;
} __packed;
struct osdv2_cdb {
struct osd_cdb_head h;
u8 caps[OSD_CAP_LEN];
struct osdv2_security_parameters sec_params;
} __packed;
struct osd_cdb {
union {
struct osdv1_cdb v1;
struct osdv2_cdb v2;
u8 buff[OSD_TOTAL_CDB_LEN];
};
} __packed;
static inline struct osd_cdb_head *osd_cdb_head(struct osd_cdb *ocdb)
{
return (struct osd_cdb_head *)ocdb->buff;
}
/* define both version actions
* Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD
*/
#define OSD_ACT___(Name, Num) \
OSD_ACT_##Name = cpu_to_be16(0x8880 + Num), \
OSDv1_ACT_##Name = cpu_to_be16(0x8800 + Num),
/* V2 only actions */
#define OSD_ACT_V2(Name, Num) \
OSD_ACT_##Name = cpu_to_be16(0x8880 + Num),
#define OSD_ACT_V1_V2(Name, Num1, Num2) \
OSD_ACT_##Name = cpu_to_be16(Num2), \
OSDv1_ACT_##Name = cpu_to_be16(Num1),
enum osd_service_actions {
OSD_ACT_V2(OBJECT_STRUCTURE_CHECK, 0x00)
OSD_ACT___(FORMAT_OSD, 0x01)
OSD_ACT___(CREATE, 0x02)
OSD_ACT___(LIST, 0x03)
OSD_ACT_V2(PUNCH, 0x04)
OSD_ACT___(READ, 0x05)
OSD_ACT___(WRITE, 0x06)
OSD_ACT___(APPEND, 0x07)
OSD_ACT___(FLUSH, 0x08)
OSD_ACT_V2(CLEAR, 0x09)
OSD_ACT_
|