Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
/*	$NetBSD: iscsi_pdu.h,v 1.4 2017/12/03 19:07:10 christos Exp $	*/

/*-
 * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Wasabi Systems, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef _ISCSI_PDU_H
#define _ISCSI_PDU_H

#define BHS_SIZE           48	/* Basic Header Segment (without digest) */
#define PDU_HEADER_SIZE    52	/* PDU Header with Digest */

#define OP_IMMEDIATE       0x40	/* Bit 1 in Opcode field: immediate delivery */
#define OPCODE_MASK        0x3f	/* Mask for opcode */

/* PDU Flags field */

#define FLAG_FINAL         0x80	/* Bit 0: Final PDU in sequence */
#define FLAG_TRANSIT       0x80	/* Bit 0: Transit to next login phase */
#define FLAG_CONTINUE      0x40	/* Bit 1: Continue PDU */
#define FLAG_ACK           0x40	/* Bit 1: Acknowledge */
#define FLAG_READ          0x40	/* Bit 1: Read Data */
#define FLAG_WRITE         0x20	/* Bit 2: Write Data */
#define FLAG_BIDI_OFLO     0x10	/* Bit 3: Bidirectional Read Residual Oflow */
#define FLAG_BIDI_UFLOW    0x08	/* Bit 4: Bidirectional Read Residual Uflow */
#define FLAG_OVERFLOW      0x04	/* Bit 5: Residual Overflow */
#define FLAG_UNDERFLOW     0x02	/* Bit 6: Residual Underflow */
#define FLAG_STATUS        0x01	/* Bit 7: Command Status is valid */

/* CSG/NSG flag field codes */

#define SG_SECURITY_NEGOTIATION           0
#define SG_LOGIN_OPERATIONAL_NEGOTIATION  1
#define SG_FULL_FEATURE_PHASE             3

#define CSG_SHIFT          2	/* shift factor for CSG field */
#define SG_MASK            3	/* mask for CSG (after shift) and NSG */

#define NEXT_PHASE(ph)  ((!ph) ? 1 : 3)	/* no phase 2 */

/* Task Management Function Codes (in Flags byte) */

#define ABORT_TASK            1
#define ABORT_TASK_SET        2
#define CLEAR_ACA             3
#define CLEAR_TASK_SET        4
#define LOGICAL_UNIT_RESET    5
#define TARGET_WARM_RESET     6
#define TARGET_COLD_RESET     7
#define TASK_REASSIGN         8

/* ISID T-Field (first byte) */

#define T_FORMAT_OUI    0x00
#define T_FORMAT_EN     0x40
#define T_FORMAT_RANDOM 0x80


/* Task Attributes */

#define ATTR_UNTAGGED         0
#define ATTR_SIMPLE           1
#define ATTR_ORDERED          2
#define ATTR_HEAD_OF_QUEUE    3
#define ATTR_ACA              4

/* Initiator Opcodes */

#define IOP_NOP_Out              0x00
#define IOP_SCSI_Command         0x01
#define IOP_SCSI_Task_Management 0x02
#define IOP_Login_Request        0x03
#define IOP_Text_Request         0x04
#define IOP_SCSI_Data_out        0x05
#define IOP_Logout_Request       0x06
#define IOP_SNACK_Request        0x10

/* Target Opcodes */

#define TOP_NOP_In               0x20
#define TOP_SCSI_Response        0x21
#define TOP_SCSI_Task_Management 0x22
#define TOP_Login_Response       0x23
#define TOP_Text_Response        0x24
#define TOP_SCSI_Data_in         0x25
#define TOP_Logout_Response      0x26
#define TOP_R2T                  0x31
#define TOP_Asynchronous_Message 0x32
#define TOP_Reject               0x3f

/*
 * The Opcode-dependent fields of the BHS, defined per PDU
 */

/* Command + Response */

struct scsi_command_pdu_s
{
	uint32_t ExpectedDataTransferLength;
	uint32_t CmdSN;
	uint32_t ExpStatSN;
	uint8_t SCSI_CDB[16];
} __packed;

typedef struct scsi_command_pdu_s scsi_command_pdu_t;

struct scsi_response_pdu_s
{
	uint32_t SNACKTag;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint32_t ExpDataSN;
	uint32_t ReadResidualCount;
	uint32_t ResidualCount;
} __packed;

typedef struct scsi_response_pdu_s scsi_response_pdu_t;


/* Task Management */

struct task_management_req_pdu_s
{
	uint32_t ReferencedTaskTag;
	uint32_t CmdSN;
	uint32_t ExpStatSN;
	uint32_t RefCmdSN;
	uint32_t ExpDataSN;
	uint8_t reserved[8];
} __packed;

typedef struct task_management_req_pdu_s task_management_req_pdu_t;


struct task_management_rsp_pdu_s
{
	uint32_t reserved1;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint8_t reserved2[12];
} __packed;

typedef struct task_management_rsp_pdu_s task_management_rsp_pdu_t;


/* Data Out & In, R2T */

struct data_out_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t reserved1;
	uint32_t ExpStatSN;
	uint32_t reserved2;
	uint32_t DataSN;
	uint32_t BufferOffset;
	uint32_t reserved3;
} __packed;

typedef struct data_out_pdu_s data_out_pdu_t;


struct data_in_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint32_t DataSN;
	uint32_t BufferOffset;
	uint32_t ResidualCount;
} __packed;

typedef struct data_in_pdu_s data_in_pdu_t;


struct r2t_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint32_t R2TSN;
	uint32_t BufferOffset;
	uint32_t DesiredDataTransferLength;
} __packed;

typedef struct r2t_pdu_s r2t_pdu_t;


/* Asynch message */

struct asynch_pdu_s
{
	uint32_t reserved1;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint8_t AsyncEvent;
	uint8_t AsyncVCode;
	uint16_t Parameter1;
	uint16_t Parameter2;
	uint16_t Parameter3;
	uint32_t reserved2;
} __packed;

typedef struct asynch_pdu_s asynch_pdu_t;


/* Text request / response */

struct text_req_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t CmdSN;
	uint32_t ExpStatSN;
	uint8_t reserved[16];
} __packed;

typedef struct text_req_pdu_s text_req_pdu_t;


struct text_rsp_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint8_t reserved[12];
} __packed;

typedef struct text_rsp_pdu_s text_rsp_pdu_t;


/* Login request / response */

struct login_req_pdu_s
{
	uint16_t CID;
	uint16_t reserved1;
	uint32_t CmdSN;
	uint32_t ExpStatSN;
	uint8_t reserved2[16];
} __packed;

typedef struct login_req_pdu_s login_req_pdu_t;

/* Overlays LUN field in login request and response */
struct login_isid_s
{
	uint8_t ISID_A;
	uint16_t ISID_B;
	uint8_t ISID_C;
	uint16_t ISID_D;
	uint16_t TSIH;
} __packed;

typedef struct login_isid_s login_isid_t;

struct login_rsp_pdu_s
{
	uint32_t reserved1;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint8_t StatusClass;
	uint8_t StatusDetail;
	uint8_t reserved2[10];
} __packed;

typedef struct login_rsp_pdu_s login_rsp_pdu_t;


/* Logout request / response */

struct logout_req_pdu_s
{
	uint16_t CID;
	uint16_t reserved2;
	uint32_t CmdSN;
	uint32_t ExpStatSN;
	uint8_t reserved3[16];
} __packed;

typedef struct logout_req_pdu_s logout_req_pdu_t;


struct logout_rsp_pdu_s
{
	uint32_t reserved2;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint32_t reserved3;
	uint16_t Time2Wait;
	uint16_t Time2Retain;
	uint32_t reserved4;
} __packed;

typedef struct logout_rsp_pdu_s logout_rsp_pdu_t;


/* SNACK request */

/* SNACK Types (in Flags field) */

#define SNACK_DATA_NAK     0
#define SNACK_STATUS_NAK   1
#define SNACK_DATA_ACK     2
#define SNACK_RDATA_NAK    3

struct snack_req_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t reserved1;
	uint32_t ExpStatSN;
	uint8_t reserved2[8];
	uint32_t BegRun;
	uint32_t RunLength;
} __packed;

typedef struct snack_req_pdu_s snack_req_pdu_t;


/* Reject */

#define REJECT_DIGEST_ERROR         2
#define REJECT_SNACK                3
#define REJECT_PROTOCOL_ERROR       4
#define REJECT_CMD_NOT_SUPPORTED    5
#define REJECT_IMMED_COMMAND        6
#define REJECT_TASK_IN_PROGRESS     7
#define REJECT_INVALID_DATA_ACK     8
#define REJECT_INVALID_PDU_FIELD    9
#define REJECT_LONG_OPERATION       10
#define REJECT_NEGOTIATION_RESET    11
#define REJECT_WAITING_FOR_LOGOUT   12


struct reject_pdu_s
{
	uint32_t reserved2;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint8_t DataSN;
	uint8_t reserved[8];
} __packed;

typedef struct reject_pdu_s reject_pdu_t;


/* NOP Out & In */

struct nop_out_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t CmdSN;
	uint32_t ExpStatSN;
	uint8_t reserved[16];
} __packed;

typedef struct nop_out_pdu_s nop_out_pdu_t;


struct nop_in_pdu_s
{
	uint32_t TargetTransferTag;
	uint32_t StatSN;
	uint32_t ExpCmdSN;
	uint32_t MaxCmdSN;
	uint8_t reserved3[12];
} __packed;

typedef struct nop_in_pdu_s nop_in_pdu_t;


/*
 * The complete PDU Header.
 */

struct pdu_header_s
{
	uint8_t pduh_Opcode;
	uint8_t pduh_Flags;
	uint8_t pduh_OpcodeSpecific[2];
	uint8_t pduh_TotalAHSLength;
	uint8_t pduh_DataSegmentLength[3];
	uint64_t pduh_LUN;
	uint32_t pduh_InitiatorTaskTag;
	union
	{
		scsi_command_pdu_t command;
		scsi_response_pdu_t response;
		task_management_req_pdu_t task_req;
		task_management_rsp_pdu_t task_rsp;
		data_out_pdu_t data_out;
		data_in_pdu_t data_in;
		r2t_pdu_t r2t;
		asynch_pdu_t asynch;
		text_req_pdu_t text_req;
		text_rsp_pdu_t text_rsp;
		login_req_pdu_t login_req;
		login_rsp_pdu_t login_rsp;
		logout_req_pdu_t logout_req;
		logout_rsp_pdu_t logout_rsp;
		snack_req_pdu_t snack;
		reject_pdu_t reject;
		nop_out_pdu_t nop_out;
		nop_in_pdu_t nop_in;
	} pduh_p;
	uint32_t pduh_HeaderDigest;
} __packed;

typedef struct pdu_header_s pdu_header_t;

#endif /* !_ISCSI_PDU_H */