Browse Source

iSCSI writes seem to be working (at least, the ethereal trace shows no

errors; still need to verify data integrity).

SCSI response PDUs are handled: status and sense data (if available) are
returned via the scsi_command structure.

Updated iSCSI session parameter usage.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
a280587cde
3 changed files with 304 additions and 54 deletions
  1. 106
    32
      src/include/gpxe/iscsi.h
  2. 10
    0
      src/include/gpxe/scsi.h
  3. 188
    22
      src/net/tcp/iscsi.c

+ 106
- 32
src/include/gpxe/iscsi.h View File

81
 /** Final PDU of a sequence */
81
 /** Final PDU of a sequence */
82
 #define ISCSI_FLAG_FINAL 0x80
82
 #define ISCSI_FLAG_FINAL 0x80
83
 
83
 
84
-/**
85
- * iSCSI basic header segment common request fields
86
- *
87
- */
88
-struct iscsi_bhs_common_request {
89
-	/** Opcode */
90
-	uint8_t opcode;
91
-	/** Flags */
92
-	uint8_t flags;
93
-	/** Fields specific to the PDU type */
94
-	uint8_t other_a[2];
95
-	/** Segment lengths */
96
-	union iscsi_segment_lengths lengths;
97
-	/** Fields specific to the PDU type */
98
-	uint8_t other_b[8];
99
-	/** Initiator Task Tag */
100
-	uint32_t itt;
101
-	/** Fields specific to the PDU type */
102
-	uint8_t other_c[4];
103
-	/** Command sequence number */
104
-	uint32_t cmdsn;
105
-	/** Expected status sequence number */
106
-	uint32_t expstatsn;
107
-	/** Fields specific to the PDU type */
108
-	uint8_t other_d[16];
109
-};
110
-
111
 /**
84
 /**
112
  * iSCSI basic header segment common request fields
85
  * iSCSI basic header segment common request fields
113
  *
86
  *
328
 /** SCSI target failure */
301
 /** SCSI target failure */
329
 #define ISCSI_RESPONSE_TARGET_FAILURE 0x01
302
 #define ISCSI_RESPONSE_TARGET_FAILURE 0x01
330
 
303
 
304
+/** SCSI sense response code offset
305
+ *
306
+ * The SCSI response may contain unsolicited sense data in the data
307
+ * segment.  If it does, this is the offset to the sense response code
308
+ * byte, which is the only byte we care about.
309
+ */
310
+#define ISCSI_SENSE_RESPONSE_CODE_OFFSET 2
311
+
331
 /**
312
 /**
332
- * iSCSI data in basic header segment
313
+ * iSCSI data-in basic header segment
333
  *
314
  *
334
  */
315
  */
335
 struct iscsi_bhs_data_in {
316
 struct iscsi_bhs_data_in {
363
 	uint32_t residual_count;
344
 	uint32_t residual_count;
364
 };
345
 };
365
 
346
 
366
-/** Data in opcode */
347
+/** Data-in opcode */
367
 #define ISCSI_OPCODE_DATA_IN 0x25
348
 #define ISCSI_OPCODE_DATA_IN 0x25
368
 
349
 
369
 /** Data requires acknowledgement */
350
 /** Data requires acknowledgement */
375
 /** Data underflow occurred */
356
 /** Data underflow occurred */
376
 #define ISCSI_DATA_FLAG_UNDERFLOW 0x02
357
 #define ISCSI_DATA_FLAG_UNDERFLOW 0x02
377
 
358
 
378
-/** SCSI status code and verflow/underflow flags are valid */
359
+/** SCSI status code and overflow/underflow flags are valid */
379
 #define ISCSI_DATA_FLAG_STATUS 0x01
360
 #define ISCSI_DATA_FLAG_STATUS 0x01
380
 
361
 
362
+/**
363
+ * iSCSI data-out basic header segment
364
+ *
365
+ */
366
+struct iscsi_bhs_data_out {
367
+	/** Opcode */
368
+	uint8_t opcode;
369
+	/** Flags */
370
+	uint8_t flags;
371
+	/** Reserved */
372
+	uint16_t reserved_a;
373
+	/** Segment lengths */
374
+	union iscsi_segment_lengths lengths;
375
+	/** Logical Unit Number */
376
+	uint64_t lun;
377
+	/** Initiator Task Tag */
378
+	uint32_t itt;
379
+	/** Target Transfer Tag */
380
+	uint32_t ttt;
381
+	/** Reserved */
382
+	uint32_t reserved_b;
383
+	/** Expected status sequence number */
384
+	uint32_t expstatsn;
385
+	/** Reserved */
386
+	uint32_t reserved_c;
387
+	/** Data sequence number */
388
+	uint32_t datasn;
389
+	/** Buffer offset */
390
+	uint32_t offset;
391
+	/** Reserved */
392
+	uint32_t reserved_d;
393
+};
394
+
395
+/** Data-out opcode */
396
+#define ISCSI_OPCODE_DATA_OUT 0x05
397
+
398
+/**
399
+ * iSCSI request to transfer basic header segment
400
+ *
401
+ */
402
+struct iscsi_bhs_r2t {
403
+	/** Opcode */
404
+	uint8_t opcode;
405
+	/** Flags */
406
+	uint8_t flags;
407
+	/** Reserved */
408
+	uint16_t reserved_a;
409
+	/** Segment lengths */
410
+	union iscsi_segment_lengths lengths;
411
+	/** Logical Unit Number */
412
+	uint64_t lun;
413
+	/** Initiator Task Tag */
414
+	uint32_t itt;
415
+	/** Target Transfer Tag */
416
+	uint32_t ttt;
417
+	/** Status sequence number */
418
+	uint32_t statsn;
419
+	/** Expected command sequence number */
420
+	uint32_t expcmdsn;
421
+	/** Maximum command sequence number */
422
+	uint32_t maxcmdsn;
423
+	/** R2T sequence number */
424
+	uint32_t r2tsn;
425
+	/** Buffer offset */
426
+	uint32_t offset;
427
+	/** Desired data transfer length */
428
+	uint32_t len;
429
+};
430
+
431
+/** R2T opcode */
432
+#define ISCSI_OPCODE_R2T 0x31
433
+
381
 /**
434
 /**
382
  * An iSCSI basic header segment
435
  * An iSCSI basic header segment
383
  */
436
  */
384
 union iscsi_bhs {
437
 union iscsi_bhs {
385
 	struct iscsi_bhs_common common;
438
 	struct iscsi_bhs_common common;
386
-	struct iscsi_bhs_common_request common_request;
387
 	struct iscsi_bhs_common_response common_response;
439
 	struct iscsi_bhs_common_response common_response;
388
 	struct iscsi_bhs_login_request login_request;
440
 	struct iscsi_bhs_login_request login_request;
389
 	struct iscsi_bhs_login_response login_response;
441
 	struct iscsi_bhs_login_response login_response;
390
 	struct iscsi_bhs_scsi_command scsi_command;
442
 	struct iscsi_bhs_scsi_command scsi_command;
391
 	struct iscsi_bhs_scsi_response scsi_response;
443
 	struct iscsi_bhs_scsi_response scsi_response;
392
 	struct iscsi_bhs_data_in data_in;
444
 	struct iscsi_bhs_data_in data_in;
445
+	struct iscsi_bhs_data_out data_out;
446
+	struct iscsi_bhs_r2t r2t;
393
 	unsigned char bytes[ sizeof ( struct iscsi_bhs_common ) ];
447
 	unsigned char bytes[ sizeof ( struct iscsi_bhs_common ) ];
394
 };
448
 };
395
 
449
 
452
 	/** Initiator task tag
506
 	/** Initiator task tag
453
 	 *
507
 	 *
454
 	 * This is the tag of the current command.  It is incremented
508
 	 * This is the tag of the current command.  It is incremented
455
-	 * whenever a final response PDU is received.
509
+	 * whenever a new command is started.
456
 	 */
510
 	 */
457
 	uint32_t itt;
511
 	uint32_t itt;
512
+	/** Target transfer tag
513
+	 *
514
+	 * This is the tag attached to a sequence of data-out PDUs in
515
+	 * response to an R2T.
516
+	 */
517
+	uint32_t ttt;
518
+	/**
519
+	 * Transfer offset
520
+	 *
521
+	 * This is the offset for an in-progress sequence of data-out
522
+	 * PDUs in response to an R2T.
523
+	 */
524
+	uint32_t transfer_offset;
525
+	/**
526
+	 * Transfer length
527
+	 *
528
+	 * This is the length for an in-progress sequence of data-out
529
+	 * PDUs in response to an R2T.
530
+	 */
531
+	uint32_t transfer_len;
458
 	/** Command sequence number
532
 	/** Command sequence number
459
 	 *
533
 	 *
460
 	 * This is the sequence number of the current command, used to
534
 	 * This is the sequence number of the current command, used to

+ 10
- 0
src/include/gpxe/scsi.h View File

136
 	 * Must be zero if @c data_in is NULL
136
 	 * Must be zero if @c data_in is NULL
137
 	 */
137
 	 */
138
 	size_t data_in_len;
138
 	size_t data_in_len;
139
+	/** SCSI statua code */
140
+	uint8_t status;
141
+	/** SCSI sense response code */
142
+	uint8_t sense_response;
139
 };
143
 };
140
 
144
 
141
 /** A SCSI device */
145
 /** A SCSI device */
154
 	 * @v scsi		SCSI device
158
 	 * @v scsi		SCSI device
155
 	 * @v command		SCSI command
159
 	 * @v command		SCSI command
156
 	 * @ret rc		Return status code
160
 	 * @ret rc		Return status code
161
+	 *
162
+	 * Note that a successful return status code indicates only
163
+	 * that the SCSI command completed.  The caller must check the
164
+	 * status field in the command structure to see if, for
165
+	 * example, the device returned CHECK CONDITION or some other
166
+	 * non-success status code.
157
 	 */
167
 	 */
158
 	int ( * command ) ( struct scsi_device *scsi,
168
 	int ( * command ) ( struct scsi_device *scsi,
159
 			    struct scsi_command *command );
169
 			    struct scsi_command *command );

+ 188
- 22
src/net/tcp/iscsi.c View File

33
  */
33
  */
34
 
34
 
35
 static void iscsi_start_tx ( struct iscsi_session *iscsi );
35
 static void iscsi_start_tx ( struct iscsi_session *iscsi );
36
+static void iscsi_start_data_out ( struct iscsi_session *iscsi,
37
+				   unsigned int datasn );
36
 
38
 
37
 /****************************************************************************
39
 /****************************************************************************
38
  *
40
  *
44
  * Build iSCSI SCSI command BHS
46
  * Build iSCSI SCSI command BHS
45
  *
47
  *
46
  * @v iscsi		iSCSI session
48
  * @v iscsi		iSCSI session
49
+ *
50
+ * We don't currently support bidirectional commands (i.e. with both
51
+ * Data-In and Data-Out segments); these would require providing code
52
+ * to generate an AHS, and there doesn't seem to be any need for it at
53
+ * the moment.
47
  */
54
  */
48
 static void iscsi_start_command ( struct iscsi_session *iscsi ) {
55
 static void iscsi_start_command ( struct iscsi_session *iscsi ) {
49
 	struct iscsi_bhs_scsi_command *command = &iscsi->tx_bhs.scsi_command;
56
 	struct iscsi_bhs_scsi_command *command = &iscsi->tx_bhs.scsi_command;
59
 		command->flags |= ISCSI_COMMAND_FLAG_READ;
66
 		command->flags |= ISCSI_COMMAND_FLAG_READ;
60
 	if ( iscsi->command->data_out )
67
 	if ( iscsi->command->data_out )
61
 		command->flags |= ISCSI_COMMAND_FLAG_WRITE;
68
 		command->flags |= ISCSI_COMMAND_FLAG_WRITE;
62
-	ISCSI_SET_LENGTHS ( command->lengths, 0, iscsi->command->data_out_len);
69
+	/* lengths left as zero */
63
 	command->lun = iscsi->lun;
70
 	command->lun = iscsi->lun;
64
-	command->itt = htonl ( iscsi->itt );
65
-	command->exp_len = htonl ( iscsi->command->data_in_len );
71
+	command->itt = htonl ( ++iscsi->itt );
72
+	command->exp_len = htonl ( iscsi->command->data_in_len |
73
+				   iscsi->command->data_out_len );
74
+	command->cmdsn = htonl ( iscsi->cmdsn );
75
+	command->expstatsn = htonl ( iscsi->statsn + 1 );
66
 	memcpy ( &command->cdb, &iscsi->command->cdb, sizeof ( command->cdb ));
76
 	memcpy ( &command->cdb, &iscsi->command->cdb, sizeof ( command->cdb ));
67
 }
77
 }
68
 
78
 
69
 /**
79
 /**
70
- * Send iSCSI SCSI command data
80
+ * Receive data segment of an iSCSI SCSI response PDU
71
  *
81
  *
72
  * @v iscsi		iSCSI session
82
  * @v iscsi		iSCSI session
83
+ * @v data		Received data
84
+ * @v len		Length of received data
85
+ * @v remaining		Data remaining after this data
86
+ * 
73
  */
87
  */
74
-static void iscsi_tx_command ( struct iscsi_session *iscsi ) {
75
-	tcp_send ( &iscsi->tcp, iscsi->command->data_out + iscsi->tx_offset,
76
-		   iscsi->command->data_out_len - iscsi->tx_offset );
88
+static void iscsi_rx_scsi_response ( struct iscsi_session *iscsi, void *data,
89
+				     size_t len, size_t remaining ) {
90
+	struct iscsi_bhs_scsi_response *response
91
+		= &iscsi->rx_bhs.scsi_response;
92
+	int sense_offset;
93
+
94
+	/* Capture the sense response code as it floats past, if present */
95
+	sense_offset = ISCSI_SENSE_RESPONSE_CODE_OFFSET - iscsi->rx_offset;
96
+	if ( ( sense_offset >= 0 ) && len ) {
97
+		iscsi->command->sense_response =
98
+			* ( ( char * ) data + sense_offset );
99
+	}
100
+
101
+	/* Wait for whole SCSI response to arrive */
102
+	if ( remaining )
103
+		return;
104
+	
105
+	/* Record SCSI status code */
106
+	iscsi->command->status = response->status;
107
+
108
+	/* Mark as completed, with error if applicable */
109
+	iscsi->status |= ISCSI_STATUS_DONE;
110
+	if ( response->response != ISCSI_RESPONSE_COMMAND_COMPLETE )
111
+		iscsi->status |= ISCSI_STATUS_ERR;
77
 }
112
 }
78
 
113
 
79
 /**
114
 /**
86
  * 
121
  * 
87
  */
122
  */
88
 static void iscsi_rx_data_in ( struct iscsi_session *iscsi, void *data,
123
 static void iscsi_rx_data_in ( struct iscsi_session *iscsi, void *data,
89
-			       size_t len, size_t remaining ) {
124
+			       size_t len, size_t remaining __unused ) {
90
 	struct iscsi_bhs_data_in *data_in = &iscsi->rx_bhs.data_in;
125
 	struct iscsi_bhs_data_in *data_in = &iscsi->rx_bhs.data_in;
91
 	unsigned long offset;
126
 	unsigned long offset;
92
 
127
 
97
 	assert ( ( offset + len ) <= iscsi->command->data_in_len );
132
 	assert ( ( offset + len ) <= iscsi->command->data_in_len );
98
 	memcpy ( ( iscsi->command->data_in + offset ), data, len );
133
 	memcpy ( ( iscsi->command->data_in + offset ), data, len );
99
 
134
 
135
+	/* Record SCSI status, if present */
136
+	if ( data_in->flags & ISCSI_DATA_FLAG_STATUS )
137
+		iscsi->command->status = data_in->status;
138
+
100
 	/* If this is the end, flag as complete */
139
 	/* If this is the end, flag as complete */
101
-	if ( ( data_in->flags & ISCSI_FLAG_FINAL ) && ( remaining == 0 ) )
140
+	if ( ( offset + len ) == iscsi->command->data_in_len ) {
141
+		assert ( data_in->flags & ISCSI_FLAG_FINAL );
142
+		assert ( remaining == 0 );
102
 		iscsi->status |= ISCSI_STATUS_DONE;
143
 		iscsi->status |= ISCSI_STATUS_DONE;
144
+	}
145
+}
146
+
147
+/**
148
+ * Receive data segment of an iSCSI R2T PDU
149
+ *
150
+ * @v iscsi		iSCSI session
151
+ * @v data		Received data
152
+ * @v len		Length of received data
153
+ * @v remaining		Data remaining after this data
154
+ * 
155
+ */
156
+static void iscsi_rx_r2t ( struct iscsi_session *iscsi, void *data __unused,
157
+			   size_t len __unused, size_t remaining __unused ) {
158
+	struct iscsi_bhs_r2t *r2t = &iscsi->rx_bhs.r2t;
159
+
160
+	/* Record transfer parameters and trigger first data-out */
161
+	iscsi->ttt = ntohl ( r2t->ttt );
162
+	iscsi->transfer_offset = ntohl ( r2t->offset );
163
+	iscsi->transfer_len = ntohl ( r2t->len );
164
+	iscsi_start_data_out ( iscsi, 0 );
165
+}
166
+
167
+/**
168
+ * Build iSCSI data-out BHS
169
+ *
170
+ * @v iscsi		iSCSI session
171
+ * @v datasn		Data sequence number within the transfer
172
+ *
173
+ */
174
+static void iscsi_start_data_out ( struct iscsi_session *iscsi,
175
+				   unsigned int datasn ) {
176
+	struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
177
+	unsigned long offset;
178
+	unsigned long remaining;
179
+	unsigned long len;
180
+
181
+	/* We always send 512-byte Data-Out PDUs; this removes the
182
+	 * need to worry about the target's MaxRecvDataSegmentLength.
183
+	 */
184
+	offset = datasn * 512;
185
+	remaining = iscsi->transfer_len - offset;
186
+	len = remaining;
187
+	if ( len > 512 )
188
+		len = 512;
189
+
190
+	/* Construct BHS and initiate transmission */
191
+	iscsi_start_tx ( iscsi );
192
+	data_out->opcode = ISCSI_OPCODE_DATA_OUT;
193
+	if ( len == remaining )
194
+		data_out->flags = ( ISCSI_FLAG_FINAL );
195
+	ISCSI_SET_LENGTHS ( data_out->lengths, 0, len );
196
+	data_out->lun = iscsi->lun;
197
+	data_out->itt = htonl ( iscsi->itt );
198
+	data_out->ttt = htonl ( iscsi->ttt );
199
+	data_out->expstatsn = htonl ( iscsi->statsn + 1 );
200
+	data_out->datasn = htonl ( datasn );
201
+	data_out->offset = htonl ( iscsi->transfer_offset + offset );
202
+}
203
+
204
+/**
205
+ * Complete iSCSI data-out PDU transmission
206
+ *
207
+ * @v iscsi		iSCSI session
208
+ *
209
+ */
210
+static void iscsi_data_out_done ( struct iscsi_session *iscsi ) {
211
+	struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
212
+
213
+	/* If we haven't reached the end of the sequence, start
214
+	 * sending the next data-out PDU.
215
+	 */
216
+	if ( ! ( data_out->flags & ISCSI_FLAG_FINAL ) )
217
+		iscsi_start_data_out ( iscsi, ntohl ( data_out->datasn ) + 1 );
218
+}
219
+
220
+/**
221
+ * Send iSCSI data-out data segment
222
+ *
223
+ * @v iscsi		iSCSI session
224
+ */
225
+static void iscsi_tx_data_out ( struct iscsi_session *iscsi ) {
226
+	struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
227
+	unsigned long offset;
228
+	unsigned long len;
229
+
230
+	offset = ( iscsi->transfer_offset + ntohl ( data_out->offset ) +
231
+		   iscsi->tx_offset );
232
+	len = ( ISCSI_DATA_LEN ( data_out->lengths ) - iscsi->tx_offset );
233
+	assert ( iscsi->command != NULL );
234
+	assert ( iscsi->command->data_out != NULL );
235
+	assert ( ( offset + len ) <= iscsi->command->data_out_len );
236
+	
237
+	tcp_send ( &iscsi->tcp, iscsi->command->data_out + offset, len );
103
 }
238
 }
104
 
239
 
105
 /****************************************************************************
240
 /****************************************************************************
121
 	return snprintf ( data, len,
256
 	return snprintf ( data, len,
122
 			  "InitiatorName=%s%c"
257
 			  "InitiatorName=%s%c"
123
 			  "TargetName=%s%c"
258
 			  "TargetName=%s%c"
124
-			  "MaxRecvDataSegmentLength=512%c"
125
 			  "SessionType=Normal%c"
259
 			  "SessionType=Normal%c"
126
 			  "DataDigest=None%c"
260
 			  "DataDigest=None%c"
127
 			  "HeaderDigest=None%c"
261
 			  "HeaderDigest=None%c"
128
-			  "ErrorRecoveryLevel=0%c",
262
+			  "DefaultTime2Wait=0%c"
263
+			  "DefaultTime2Retain=0%c",
129
 			  iscsi->initiator, 0, iscsi->target, 0,
264
 			  iscsi->initiator, 0, iscsi->target, 0,
130
 			  0, 0, 0, 0, 0 );
265
 			  0, 0, 0, 0, 0 );
131
 }
266
 }
134
  * Build iSCSI login request BHS
269
  * Build iSCSI login request BHS
135
  *
270
  *
136
  * @v iscsi		iSCSI session
271
  * @v iscsi		iSCSI session
137
- * @v first		Login request is the first request of a session
272
+ * @v first		Login request is the first in a sequence
138
  */
273
  */
139
 static void iscsi_start_login ( struct iscsi_session *iscsi, int first ) {
274
 static void iscsi_start_login ( struct iscsi_session *iscsi, int first ) {
140
 	struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
275
 	struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
156
 					IANA_EN_FEN_SYSTEMS );
291
 					IANA_EN_FEN_SYSTEMS );
157
 	/* isid_iana_qual left as zero */
292
 	/* isid_iana_qual left as zero */
158
 	request->tsih = htons ( iscsi->tsih );
293
 	request->tsih = htons ( iscsi->tsih );
159
-	/* itt left as zero */
294
+	if ( first )
295
+		iscsi->itt++;
296
+	request->itt = htonl ( iscsi->itt );
160
 	/* cid left as zero */
297
 	/* cid left as zero */
298
+	request->cmdsn = htonl ( iscsi->cmdsn );
299
+	request->expstatsn = htonl ( iscsi->statsn + 1 );
161
 }
300
 }
162
 
301
 
163
 /**
302
 /**
240
 	
379
 	
241
 	/* Initialise TX BHS */
380
 	/* Initialise TX BHS */
242
 	memset ( &iscsi->tx_bhs, 0, sizeof ( iscsi->tx_bhs ) );
381
 	memset ( &iscsi->tx_bhs, 0, sizeof ( iscsi->tx_bhs ) );
243
-	iscsi->tx_bhs.common_request.cmdsn = htonl ( iscsi->cmdsn );
244
-	iscsi->tx_bhs.common_request.expstatsn = htonl ( iscsi->statsn + 1 );
245
 
382
 
246
 	/* Flag TX engine to start transmitting */
383
 	/* Flag TX engine to start transmitting */
247
 	iscsi->tx_state = ISCSI_TX_BHS;
384
 	iscsi->tx_state = ISCSI_TX_BHS;
260
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
397
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
261
 
398
 
262
 	switch ( common->opcode & ISCSI_OPCODE_MASK ) {
399
 	switch ( common->opcode & ISCSI_OPCODE_MASK ) {
263
-	case ISCSI_OPCODE_SCSI_COMMAND:
264
-		iscsi_tx_command ( iscsi );
400
+	case ISCSI_OPCODE_DATA_OUT:
401
+		iscsi_tx_data_out ( iscsi );
265
 		break;
402
 		break;
266
 	case ISCSI_OPCODE_LOGIN_REQUEST:
403
 	case ISCSI_OPCODE_LOGIN_REQUEST:
267
 		iscsi_tx_login_request ( iscsi );
404
 		iscsi_tx_login_request ( iscsi );
272
 	}
409
 	}
273
 }
410
 }
274
 
411
 
412
+/**
413
+ * Complete iSCSI PDU transmission
414
+ *
415
+ * @v iscsi		iSCSI session
416
+ *
417
+ * Called when a PDU has been completely transmitted and the TX state
418
+ * machine is about to enter the idle state.  iscsi::tx_bhs will be
419
+ * valid for the just-completed PDU when this is called.
420
+ */
421
+static void iscsi_tx_done ( struct iscsi_session *iscsi ) {
422
+	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
423
+
424
+	switch ( common->opcode & ISCSI_OPCODE_MASK ) {
425
+	case ISCSI_OPCODE_DATA_OUT:
426
+		iscsi_data_out_done ( iscsi );
427
+	default:
428
+		/* No action */
429
+		break;
430
+	}
431
+}
432
+
275
 /**
433
 /**
276
  * Handle TCP ACKs
434
  * Handle TCP ACKs
277
  *
435
  *
318
 		 */
476
 		 */
319
 		if ( iscsi->tx_offset != max_tx_offset )
477
 		if ( iscsi->tx_offset != max_tx_offset )
320
 			return;
478
 			return;
321
-		
479
+
480
+		/* Move to next state.  Call iscsi_tx_done() when PDU
481
+		 * transmission is complete.
482
+		 */
322
 		iscsi->tx_state = next_state;
483
 		iscsi->tx_state = next_state;
323
 		iscsi->tx_offset = 0;
484
 		iscsi->tx_offset = 0;
485
+		if ( next_state == ISCSI_TX_IDLE )
486
+			iscsi_tx_done ( iscsi );
324
 	}
487
 	}
325
 }
488
 }
326
 
489
 
381
 	iscsi->cmdsn = ntohl ( response->expcmdsn );
544
 	iscsi->cmdsn = ntohl ( response->expcmdsn );
382
 	iscsi->statsn = ntohl ( response->statsn );
545
 	iscsi->statsn = ntohl ( response->statsn );
383
 
546
 
384
-	/* Increment itt when we receive a final response */
385
-	if ( response->flags & ISCSI_FLAG_FINAL )
386
-		iscsi->itt++;
387
-
388
 	switch ( response->opcode & ISCSI_OPCODE_MASK ) {
547
 	switch ( response->opcode & ISCSI_OPCODE_MASK ) {
389
 	case ISCSI_OPCODE_LOGIN_RESPONSE:
548
 	case ISCSI_OPCODE_LOGIN_RESPONSE:
390
 		iscsi_rx_login_response ( iscsi, data, len, remaining );
549
 		iscsi_rx_login_response ( iscsi, data, len, remaining );
391
 		break;
550
 		break;
551
+	case ISCSI_OPCODE_SCSI_RESPONSE:
552
+		iscsi_rx_scsi_response ( iscsi, data, len, remaining );
553
+		break;
392
 	case ISCSI_OPCODE_DATA_IN:
554
 	case ISCSI_OPCODE_DATA_IN:
393
 		iscsi_rx_data_in ( iscsi, data, len, remaining );
555
 		iscsi_rx_data_in ( iscsi, data, len, remaining );
394
 		break;
556
 		break;
557
+	case ISCSI_OPCODE_R2T:
558
+		iscsi_rx_r2t ( iscsi, data, len, remaining );
559
+		break;
395
 	default:
560
 	default:
396
 		printf ( "Unknown iSCSI opcode %02x\n", response->opcode );
561
 		printf ( "Unknown iSCSI opcode %02x\n", response->opcode );
397
 		iscsi->status |= ( ISCSI_STATUS_DONE | ISCSI_STATUS_ERR );
562
 		iscsi->status |= ( ISCSI_STATUS_DONE | ISCSI_STATUS_ERR );
521
 	if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
686
 	if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
522
 		tcp_connect ( conn );
687
 		tcp_connect ( conn );
523
 	} else {
688
 	} else {
689
+		printf ( "iSCSI retry count exceeded\n" );
524
 		iscsi->status |= ( ISCSI_STATUS_DONE | ISCSI_STATUS_ERR );
690
 		iscsi->status |= ( ISCSI_STATUS_DONE | ISCSI_STATUS_ERR );
525
 	}
691
 	}
526
 }
692
 }

Loading…
Cancel
Save